CompanyMemberMappingServiceImpl.java 4.03 KB
package com.subsidy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.subsidy.common.exception.HttpException;
import com.subsidy.dto.company.AttendMembersDTO;
import com.subsidy.dto.company.GetCompanyMembersDTO;
import com.subsidy.dto.company.InviteMemberDTO;
import com.subsidy.dto.member.CancerMemberDTO;
import com.subsidy.dto.member.DepartMembersDTO;
import com.subsidy.mapper.MemberDepartmentMappingMapper;
import com.subsidy.mapper.MemberMapper;
import com.subsidy.model.CompanyMemberMappingDO;
import com.subsidy.mapper.CompanyMemberMappingMapper;
import com.subsidy.model.MemberDO;
import com.subsidy.model.MemberDepartmentMappingDO;
import com.subsidy.service.CompanyMemberMappingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import com.subsidy.util.excel.ExcelUtil;
import com.subsidy.vo.company.GetCompanyMembersVO;
import com.subsidy.vo.company.MemberCompanyVO;
import com.subsidy.vo.member.AttendMembersVO;
import com.subsidy.vo.member.DepartMembersVO;
import com.subsidy.vo.member.MemberAttendInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 公司人员映射表 服务实现类
 * </p>
 *
 * @author Tuyp
 * @since 2024-01-11
 */
@Service
public class CompanyMemberMappingServiceImpl extends ServiceImpl<CompanyMemberMappingMapper, CompanyMemberMappingDO> implements CompanyMemberMappingService {

    @Autowired
    private MemberDepartmentMappingMapper memberDepartmentMappingMapper;

    @Autowired
    private MemberMapper memberMapper;

    public String inviteMember(InviteMemberDTO inviteMemberDTO) {

        MemberDO memberDO = memberMapper.selectOne(new QueryWrapper<MemberDO>()
                .lambda()
                .eq(MemberDO::getUserName, inviteMemberDTO.getUserName())
                .eq(MemberDO::getIdCard, inviteMemberDTO.getIdCard()));

        if (null == memberDO) {
            throw new HttpException(10011);
        }

        Integer count = this.baseMapper.selectCount(new QueryWrapper<CompanyMemberMappingDO>()
                .lambda()
                .eq(CompanyMemberMappingDO::getMemberId, memberDO.getId())
                .eq(CompanyMemberMappingDO::getMemberStatus, 1));

        if (count > 0) {
            throw new HttpException(10028);
        }

        CompanyMemberMappingDO companyMemberMappingDO = new CompanyMemberMappingDO();
        companyMemberMappingDO.setCompanyId(inviteMemberDTO.getCompanyId());
        companyMemberMappingDO.setMemberId(memberDO.getId());
        companyMemberMappingDO.setMemberStatus(1);
        this.baseMapper.insert(companyMemberMappingDO);

        MemberDepartmentMappingDO memberDepartmentMappingDO = new MemberDepartmentMappingDO();
        memberDepartmentMappingDO.setDepartmentId(inviteMemberDTO.getDepartmentId());
        memberDepartmentMappingDO.setMemberId(memberDO.getId());
        memberDepartmentMappingDO.setMemberStatus(1);
        memberDepartmentMappingMapper.insert(memberDepartmentMappingDO);


        return ConstantUtils.ADD_SUCCESS;
    }

    public String cancerMember(CancerMemberDTO cancerMemberDTO) {

        List<Long> members = cancerMemberDTO.getMemberIds();

        for (Long memberId : members) {
            CompanyMemberMappingDO companyMemberMappingDO1 = this.baseMapper.selectOne(new QueryWrapper<CompanyMemberMappingDO>()
                    .lambda()
                    .eq(CompanyMemberMappingDO::getCompanyId, cancerMemberDTO.getCompanyId())
                    .eq(CompanyMemberMappingDO::getMemberId, memberId)
                    .eq(CompanyMemberMappingDO::getMemberStatus, 1));

            companyMemberMappingDO1.setMemberStatus(0);
            this.baseMapper.updateById(companyMemberMappingDO1);
            memberDepartmentMappingMapper.cancelMember(memberId);
        }
        return ConstantUtils.DELETE_SUCCESS;
    }


}