package com.mall.member.service.impl;

import com.mall.member.mapper.MemberMapper;
import com.mall.member.service.MemberService;
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.MemberService;
import com.mall.member.domain.dto.MemberDto;
import com.mall.member.domain.entity.Member;
import com.mall.member.domain.vo.MemberVo;
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 MemberServiceImpl extends ServiceImpl<MemberMapper, Member> implements MemberService {

    /**
     * * 会员 服务实现类
     *
     * @param pageParams 会员分页查询page对象
     * @param dto        会员分页查询对象
     * @return 查询分页会员返回对象
     */
    @Override
    public PageResult<MemberVo> getMemberPage(Page<Member> pageParams, MemberDto dto) {
        IPage<MemberVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 添加会员
     *
     * @param dto 会员添加
     */
    @Override
    public void addMember(MemberDto dto) {
        Member member =new Member();
        BeanUtils.copyProperties(dto, member);
        save(member);
    }

    /**
     * 更新会员
     *
     * @param dto 会员更新
     */
    @Override
    public void updateMember(MemberDto dto) {
        Member member =new Member();
        BeanUtils.copyProperties(dto, member);
        updateById(member);
    }

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