package com.mall.member.service.impl;

import com.mall.member.mapper.MemberStatisticsInfoMapper;
import com.mall.member.service.MemberStatisticsInfoService;
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.MemberStatisticsInfoService;
import com.mall.member.domain.dto.MemberStatisticsInfoDto;
import com.mall.member.domain.entity.MemberStatisticsInfo;
import com.mall.member.domain.vo.MemberStatisticsInfoVo;
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 MemberStatisticsInfoServiceImpl extends ServiceImpl<MemberStatisticsInfoMapper, MemberStatisticsInfo> implements MemberStatisticsInfoService {

    /**
     * * 会员统计信息 服务实现类
     *
     * @param pageParams 会员统计信息分页查询page对象
     * @param dto        会员统计信息分页查询对象
     * @return 查询分页会员统计信息返回对象
     */
    @Override
    public PageResult<MemberStatisticsInfoVo> getMemberStatisticsInfoPage(Page<MemberStatisticsInfo> pageParams, MemberStatisticsInfoDto dto) {
        IPage<MemberStatisticsInfoVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 添加会员统计信息
     *
     * @param dto 会员统计信息添加
     */
    @Override
    public void addMemberStatisticsInfo(MemberStatisticsInfoDto dto) {
        MemberStatisticsInfo memberStatisticsInfo =new MemberStatisticsInfo();
        BeanUtils.copyProperties(dto, memberStatisticsInfo);
        save(memberStatisticsInfo);
    }

    /**
     * 更新会员统计信息
     *
     * @param dto 会员统计信息更新
     */
    @Override
    public void updateMemberStatisticsInfo(MemberStatisticsInfoDto dto) {
        MemberStatisticsInfo memberStatisticsInfo =new MemberStatisticsInfo();
        BeanUtils.copyProperties(dto, memberStatisticsInfo);
        updateById(memberStatisticsInfo);
    }

    /**
     * 删除|批量删除会员统计信息
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteMemberStatisticsInfo(List<Long> ids) {
        removeByIds(ids);
    }
}