package com.mall.member.service.impl;

import com.mall.member.mapper.IntegrationChangeHistoryMapper;
import com.mall.member.service.IntegrationChangeHistoryService;
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.IntegrationChangeHistoryService;
import com.mall.member.domain.dto.IntegrationChangeHistoryDto;
import com.mall.member.domain.entity.IntegrationChangeHistory;
import com.mall.member.domain.vo.IntegrationChangeHistoryVo;
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 IntegrationChangeHistoryServiceImpl extends ServiceImpl<IntegrationChangeHistoryMapper, IntegrationChangeHistory> implements IntegrationChangeHistoryService {

    /**
     * * 积分变化历史记录 服务实现类
     *
     * @param pageParams 积分变化历史记录分页查询page对象
     * @param dto        积分变化历史记录分页查询对象
     * @return 查询分页积分变化历史记录返回对象
     */
    @Override
    public PageResult<IntegrationChangeHistoryVo> getIntegrationChangeHistoryPage(Page<IntegrationChangeHistory> pageParams, IntegrationChangeHistoryDto dto) {
        IPage<IntegrationChangeHistoryVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 添加积分变化历史记录
     *
     * @param dto 积分变化历史记录添加
     */
    @Override
    public void addIntegrationChangeHistory(IntegrationChangeHistoryDto dto) {
        IntegrationChangeHistory integrationChangeHistory =new IntegrationChangeHistory();
        BeanUtils.copyProperties(dto, integrationChangeHistory);
        save(integrationChangeHistory);
    }

    /**
     * 更新积分变化历史记录
     *
     * @param dto 积分变化历史记录更新
     */
    @Override
    public void updateIntegrationChangeHistory(IntegrationChangeHistoryDto dto) {
        IntegrationChangeHistory integrationChangeHistory =new IntegrationChangeHistory();
        BeanUtils.copyProperties(dto, integrationChangeHistory);
        updateById(integrationChangeHistory);
    }

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