Blame view

MemberServiceImpl.java 10.6 KB
涂亚平 committed
1 2
package com.subsidy.service.impl;

涂亚平 committed
3 4 5 6 7 8 9 10 11 12 13 14
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.common.exception.HttpException;
import com.subsidy.dto.administer.DownloadFailMembersDTO;
import com.subsidy.dto.administer.ImportMemberVO;
import com.subsidy.dto.member.AddMemberDTO;
import com.subsidy.dto.member.ImportMemberDTO;
import com.subsidy.dto.member.QueryMembersDTO;
import com.subsidy.mapper.GroupMemberMappingMapper;
import com.subsidy.mapper.LaborGroupDictMapper;
涂亚平 committed
15
import com.subsidy.mapper.MemberMapper;
涂亚平 committed
16 17 18 19 20
import com.subsidy.mapper.ProjectMemberMappingMapper;
import com.subsidy.model.GroupMemberMappingDO;
import com.subsidy.model.LaborGroupDictDO;
import com.subsidy.model.MemberDO;
import com.subsidy.model.ProjectMemberMappingDO;
涂亚平 committed
21
import com.subsidy.service.MemberService;
涂亚平 committed
22 23 24 25 26 27 28
import com.subsidy.util.excel.ExcelUtil;
import com.subsidy.vo.member.DetailVO;
import com.subsidy.vo.member.ImportMemberResultVO;
import com.subsidy.vo.member.QueryMembersVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
涂亚平 committed
29
import org.springframework.stereotype.Service;
涂亚平 committed
30 31 32 33 34 35 36
import org.springframework.web.multipart.MultipartFile;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
涂亚平 committed
37 38 39

/**
 * <p>
涂亚平 committed
40
 * 服务实现类
涂亚平 committed
41 42 43 44 45 46 47 48
 * </p>
 *
 * @author Tuyp
 * @since 2024-07-18
 */
@Service
public class MemberServiceImpl extends ServiceImpl<MemberMapper, MemberDO> implements MemberService {

涂亚平 committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
    @Autowired
    private ProjectMemberMappingMapper projectMemberMappingMapper;

    @Autowired
    private MemberMapper memberMapper;

    @Autowired
    private GroupMemberMappingMapper groupMemberMappingMapper;

    @Autowired
    private LaborGroupDictMapper laborGroupDictMapper;

    public void addMember(AddMemberDTO addMemberDTO) {

        //查看手机号是否存在
        int count = this.baseMapper.selectCount(new QueryWrapper<MemberDO>()
                .lambda()
                .eq(MemberDO::getTelephone, addMemberDTO.getTelephone())
                .eq(MemberDO::getMemberType, 3));

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

        //查看身份证号是否存在
        int count1 = this.baseMapper.selectCount(new QueryWrapper<MemberDO>()
                .lambda()
                .eq(MemberDO::getIdCard, addMemberDTO.getIdCard())
                .eq(MemberDO::getMemberType, 3));
        if (count1 > 0) {
            throw new HttpException(20002);
        }
        MemberDO memberDO = new MemberDO();
        BeanUtils.copyProperties(addMemberDTO, memberDO);
        memberDO.setMemberType(3);
        this.baseMapper.insert(memberDO);

        GroupMemberMappingDO groupMemberMappingDO = new GroupMemberMappingDO();
        groupMemberMappingDO.setGroupId(addMemberDTO.getGroupId());
        groupMemberMappingDO.setMemberId(memberDO.getId());
        groupMemberMappingMapper.insert(groupMemberMappingDO);
    }

    public void updateMember(AddMemberDTO addMemberDTO) {

        //查看手机号是否存在
        int count = this.baseMapper.selectCount(new QueryWrapper<MemberDO>()
                .lambda()
                .eq(MemberDO::getTelephone, addMemberDTO.getTelephone())
                .ne(MemberDO::getId, addMemberDTO.getId())
                .eq(MemberDO::getMemberType, 3));

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

        //查看身份证号是否存在
        int count1 = this.baseMapper.selectCount(new QueryWrapper<MemberDO>()
                .lambda()
                .eq(MemberDO::getIdCard, addMemberDTO.getIdCard())
                .ne(MemberDO::getId, addMemberDTO.getId())
                .eq(MemberDO::getMemberType, 3));
        if (count1 > 0) {
            throw new HttpException(20002);
        }
        MemberDO memberDO = new MemberDO();
        BeanUtils.copyProperties(addMemberDTO, memberDO);
        this.baseMapper.updateById(memberDO);

    }

    public void deleteMember(MemberDO memberDO) {
        this.baseMapper.deleteById(memberDO.getId());
    }

    public IPage<QueryMembersVO> queryMembers(QueryMembersDTO queryMembersDTO) {

        LaborGroupDictDO laborGroupDictDO = laborGroupDictMapper.selectById(queryMembersDTO.getGroupId());

        Page page = new Page(queryMembersDTO.getPageNum(), queryMembersDTO.getPageSize());

        IPage<QueryMembersVO> queryMembers = this.baseMapper.queryMembers(page, queryMembersDTO.getGroupId(), queryMembersDTO.getUserInfo());

        List<QueryMembersVO> queryMembersVOS = queryMembers.getRecords();
        for (QueryMembersVO queryMembersVO : queryMembersVOS) {
            //入职状态
            List<ProjectMemberMappingDO> memberMappingDOS = projectMemberMappingMapper.selectList(new QueryWrapper<ProjectMemberMappingDO>()
                    .lambda()
                    .eq(ProjectMemberMappingDO::getMemberId, queryMembersVO.getId())
                    .orderByDesc(ProjectMemberMappingDO::getId));

            if (memberMappingDOS.size() > 0) {
                if (1 == memberMappingDOS.get(0).getStatus()) {
                    queryMembersVO.setFireStatus("入职");
                } else {
                    queryMembersVO.setFireStatus("离职");
                }
            } else {
                queryMembersVO.setFireStatus("离职");
            }
        }
        return queryMembers;
    }

    public List<DetailVO> detail(GroupMemberMappingDO groupMemberMappingDO) {
        return projectMemberMappingMapper.detail(groupMemberMappingDO.getMemberId());
    }

    //    @Transactional(rollbackFor = Exception.class)
    public ImportMemberResultVO importMember(Long groupId, MultipartFile multipartFile) throws Exception {

        ImportMemberResultVO importMemberResultVO = new ImportMemberResultVO();

        List<ImportMemberVO> failMembers = new ArrayList<>();

        int successCount = 0;
        int failCount = 0;
        List<ImportMemberDTO> importMemberDTOS = ExcelUtil.readExcelWithoutTitle(null, ImportMemberDTO.class, multipartFile);
        for (ImportMemberDTO s : importMemberDTOS) {
            try {

                MemberDO memberDel = memberMapper.selectOne(new QueryWrapper<MemberDO>()
                        .lambda()
                        .eq(MemberDO::getTelephone, s.getTelephone())
                        .eq(MemberDO::getMemberType, 3));

                MemberDO memberIdCard = memberMapper.selectOne(new QueryWrapper<MemberDO>()
                        .lambda()
                        .eq(MemberDO::getIdCard, s.getIdCard())
                        .eq(MemberDO::getMemberType, 3));

                //日期格式
                SimpleDateFormat d = null;
                Date date = null;

                if (StringUtils.isEmpty(s.getUserName()) || StringUtils.isEmpty(s.getTelephone()) || StringUtils.isEmpty(s.getGender()) || StringUtils.isEmpty(s.getIdCard()) || StringUtils.isEmpty(s.getPayrollAccount())) {
                    ImportMemberVO importMemberVO = new ImportMemberVO();
                    BeanUtils.copyProperties(s, importMemberVO);
                    importMemberVO.setReason("必填字段");
                    failMembers.add(importMemberVO);
                    failCount++;
                } else if (null != s.getIdCard() && s.getIdCard().length() != 18) {
                    ImportMemberVO importMemberVO = new ImportMemberVO();
                    BeanUtils.copyProperties(s, importMemberVO);
                    importMemberVO.setReason("身份证位数不正确");
                    failMembers.add(importMemberVO);
                    failCount++;
                } else if (null != s.getTelephone() && s.getTelephone().length() != 11) {
                    ImportMemberVO importMemberVO = new ImportMemberVO();
                    BeanUtils.copyProperties(s, importMemberVO);
                    importMemberVO.setReason("手机号位数不正确");
                    failMembers.add(importMemberVO);
                    failCount++;
                } else if (null != memberDel) {
                    ImportMemberVO importMemberVO = new ImportMemberVO();
                    BeanUtils.copyProperties(s, importMemberVO);
                    importMemberVO.setReason("手机号重复");
                    failMembers.add(importMemberVO);
                    failCount++;
                } else if (null != memberIdCard) {
                    ImportMemberVO importMemberVO = new ImportMemberVO();
                    BeanUtils.copyProperties(s, importMemberVO);
                    importMemberVO.setReason("身份证重复");
                    failMembers.add(importMemberVO);
                    failCount++;
                } else {
                    MemberDO memberDO1 = new MemberDO();
                    memberDO1.setUserName(s.getUserName());
                    memberDO1.setGender(s.getGender());
                    memberDO1.setFirstLogin(0);
                    memberDO1.setTelephone(s.getTelephone());
                    memberDO1.setIdCard(s.getIdCard().toUpperCase());
                    memberDO1.setStatus("启用");
                    memberDO1.setPayrollAccount(s.getPayrollAccount());
                    memberDO1.setBank(s.getBank());
                    memberDO1.setMemberType(3);
                    memberMapper.insert(memberDO1);

                    //人和群组的映射
                    GroupMemberMappingDO groupMemberMappingDO = new GroupMemberMappingDO();
                    groupMemberMappingDO.setMemberId(memberDO1.getId());
                    groupMemberMappingDO.setGroupId(groupId);
                    groupMemberMappingMapper.insert(groupMemberMappingDO);
                    successCount++;

                }
            } catch (Exception e) {
                ImportMemberVO importMemberVO = new ImportMemberVO();
                BeanUtils.copyProperties(s, importMemberVO);
                importMemberVO.setReason("其他原因");
                failCount++;
                failMembers.add(importMemberVO);
            }
        }
        importMemberResultVO.setImportMemberVOS(failMembers);
        importMemberResultVO.setSuccessCount(successCount);
        importMemberResultVO.setFailCount(failCount);
        return importMemberResultVO;
    }

    public void downloadFailMembers(DownloadFailMembersDTO downloadFailMembersDTO) {
        List<ImportMemberVO> importMemberVOS = downloadFailMembersDTO.getImportMemberVOS();
        ExcelUtil.writeExcel(importMemberVOS, ImportMemberVO.class);
    }


涂亚平 committed
255
}