package com.mall.product.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.common.domain.vo.result.PageResult;
import com.mall.product.domain.dto.SpuInfoDescDto;
import com.mall.product.domain.entity.SpuInfoDesc;
import com.mall.product.domain.vo.SpuInfoDescVo;
import com.mall.product.mapper.SpuInfoDescMapper;
import com.mall.product.service.SpuInfoDescService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * spu信息介绍 服务实现类
 * </p>
 *
 * @author Bunny
 * @since 2025-07-04 14:05:53
 */
@Service
@Transactional
public class SpuInfoDescServiceImpl extends ServiceImpl<SpuInfoDescMapper, SpuInfoDesc> implements SpuInfoDescService {

    /**
     * * spu信息介绍 服务实现类
     *
     * @param pageParams spu信息介绍分页查询page对象
     * @param dto        spu信息介绍分页查询对象
     * @return 查询分页spu信息介绍返回对象
     */
    @Override
    public PageResult<SpuInfoDescVo> getSpuInfoDescPage(Page<SpuInfoDesc> pageParams, SpuInfoDescDto dto) {
        IPage<SpuInfoDescVo> page = baseMapper.selectListByPage(pageParams, dto);

        return PageResult.<SpuInfoDescVo>builder()
                .list(page.getRecords())
                .pageNo(page.getCurrent())
                .pageSize(page.getSize())
                .total(page.getTotal())
                .build();
    }

    /**
     * 添加spu信息介绍
     *
     * @param dto spu信息介绍添加
     */
    @Override
    public void addSpuInfoDesc(SpuInfoDescDto dto) {
        SpuInfoDesc spuInfoDesc = new SpuInfoDesc();
        BeanUtils.copyProperties(dto, spuInfoDesc);
        save(spuInfoDesc);
    }

    /**
     * 更新spu信息介绍
     *
     * @param dto spu信息介绍更新
     */
    @Override
    public void updateSpuInfoDesc(SpuInfoDescDto dto) {
        SpuInfoDesc spuInfoDesc = new SpuInfoDesc();
        BeanUtils.copyProperties(dto, spuInfoDesc);
        updateById(spuInfoDesc);
    }

    /**
     * 删除|批量删除spu信息介绍
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteSpuInfoDesc(List<Long> ids) {
        removeByIds(ids);
    }
}