package com.easyproject.system.service.member.impl;

import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.easyproject.common.constant.HttpStatus;
import com.easyproject.common.core.domain.entity.ClientMember;
import com.easyproject.common.core.page.TableDataInfo;
import com.easyproject.common.utils.DateUtils;
import com.easyproject.service.mapper.member.MemberInviteMapper;
import com.easyproject.service.mapper.member.ClientMemberMapper;
import com.easyproject.system.domain.vo.ClientMemberVo;
import com.easyproject.system.service.member.IClientMemberService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 用户列表Service业务层处理
 *
 * @author easyproject
 * @date 2024-05-23
 */
@Service
public class ClientMemberServiceImpl implements IClientMemberService {
    @Autowired
    private ClientMemberMapper clientMemberMapper;
    @Resource
    private MemberInviteMapper memberInviteMapper;

    /**
     * 查询用户列表
     *
     * @param id 用户列表主键
     * @return 用户列表
     */
    @Override
    public ClientMember selectClientMemberById(Long id) {
        return clientMemberMapper.selectClientMemberById(id);
    }

    /**
     * 查询用户列表列表
     *
     * @param clientMember 用户列表
     * @return 用户列表
     */
    @Override
    public TableDataInfo selectClientMemberList(ClientMember clientMember) {
        List<ClientMember> clientMemberList = clientMemberMapper.selectClientMemberList(clientMember);
        List<ClientMemberVo> clientMemberVoList = null;
        if (ObjectUtil.isNotEmpty(clientMemberList)) {
            clientMemberVoList = BeanUtil.copyToList(clientMemberList, ClientMemberVo.class);
        }
        //自定也分页信息
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(clientMemberVoList);
        rspData.setTotal(new PageInfo(clientMemberList).getTotal());
        return rspData;
    }

    public List<ClientMemberVo> selectClientMemberExportList(ClientMember clientMember) {
        List<ClientMember> clientMemberList = clientMemberMapper.selectClientMemberList(clientMember);
        List<ClientMemberVo> clientMemberVoList = null;
        if (ObjectUtil.isNotEmpty(clientMemberList)) {
            clientMemberVoList = BeanUtil.copyToList(clientMemberList, ClientMemberVo.class);
        }
        return clientMemberVoList;
    }

    /**
     * 修改用户列表
     *
     * @param clientMember 用户列表
     * @return 结果
     */
    @Override
    public int updateClientMember(ClientMember clientMember) {
        ClientMember newClientMember = new ClientMember();
        newClientMember.setId(clientMember.getId());
        newClientMember.setStatus(clientMember.getStatus());
        newClientMember.setRemark(clientMember.getRemark());
        newClientMember.setUpdateTime(DateUtils.getNowDate());
        return clientMemberMapper.updateClientMember(newClientMember);
    }

}
