package com.mall.member.service.impl;

import com.mall.member.mapper.GrowthChangeHistoryMapper;
import com.mall.member.service.GrowthChangeHistoryService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.mall.member.service.GrowthChangeHistoryService;
import com.mall.member.domain.dto.GrowthChangeHistoryDto;
import com.mall.member.domain.entity.GrowthChangeHistory;
import com.mall.member.domain.vo.GrowthChangeHistoryVo;
import com.mall.common.domain.vo.result.PageResult;
import com.mall.common.domain.vo.result.Result;
import com.mall.common.domain.vo.result.ResultCodeEnum;

import java.util.List;

/**
 * <p>
 * 成长值变化历史记录 服务实现类
 * </p>
 *
 * @author Bunny
 * @since 2025-07-05 19:30:06
 */
@Service
@Transactional
public class GrowthChangeHistoryServiceImpl extends ServiceImpl<GrowthChangeHistoryMapper, GrowthChangeHistory> implements GrowthChangeHistoryService {

    /**
     * * 成长值变化历史记录 服务实现类
     *
     * @param pageParams 成长值变化历史记录分页查询page对象
     * @param dto        成长值变化历史记录分页查询对象
     * @return 查询分页成长值变化历史记录返回对象
     */
    @Override
    public PageResult<GrowthChangeHistoryVo> getGrowthChangeHistoryPage(Page<GrowthChangeHistory> pageParams, GrowthChangeHistoryDto dto) {
        IPage<GrowthChangeHistoryVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 添加成长值变化历史记录
     *
     * @param dto 成长值变化历史记录添加
     */
    @Override
    public void addGrowthChangeHistory(GrowthChangeHistoryDto dto) {
        GrowthChangeHistory growthChangeHistory =new GrowthChangeHistory();
        BeanUtils.copyProperties(dto, growthChangeHistory);
        save(growthChangeHistory);
    }

    /**
     * 更新成长值变化历史记录
     *
     * @param dto 成长值变化历史记录更新
     */
    @Override
    public void updateGrowthChangeHistory(GrowthChangeHistoryDto dto) {
        GrowthChangeHistory growthChangeHistory =new GrowthChangeHistory();
        BeanUtils.copyProperties(dto, growthChangeHistory);
        updateById(growthChangeHistory);
    }

    /**
     * 删除|批量删除成长值变化历史记录
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteGrowthChangeHistory(List<Long> ids) {
        removeByIds(ids);
    }
}