yz
2021-03-07 9ec124ecb9239091d537c71fe907f9a1bb3e135f
febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/service/impl/EmpBaseInfoServiceImpl.java
@@ -1,11 +1,9 @@
package cc.mrbird.febs.server.hr.service.impl;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.*;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import cc.mrbird.febs.common.core.entity.constant.StringConstant;
import cc.mrbird.febs.common.core.entity.system.SysConfig;
@@ -13,15 +11,17 @@
import cc.mrbird.febs.common.core.utils.MyUtil;
import cc.mrbird.febs.server.hr.entity.EmpDimissionLog;
import cc.mrbird.febs.server.hr.entity.EmpJobChange;
import cc.mrbird.febs.server.hr.feign.IRemoteDicItemService;
import cc.mrbird.febs.server.hr.feign.IRemoteUserService;
import cc.mrbird.febs.server.hr.mapper.*;
import cc.mrbird.febs.server.hr.properties.FebsServerHrProperties;
import cc.mrbird.febs.server.hr.service.IEmpContractInfoService;
import cc.mrbird.febs.server.hr.service.IEmpDimissionLogService;
import cc.mrbird.febs.server.hr.service.IEmpJobChangeService;
import cc.mrbird.febs.server.hr.service.*;
import cc.mrbird.febs.server.hr.util.PoiExportExcel;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cc.mrbird.febs.server.hr.entity.*;
import cn.hutool.core.util.StrUtil;
import io.prometheus.client.Collector;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
@@ -44,10 +44,9 @@
import cc.mrbird.febs.common.redis.service.RedisService;
import cc.mrbird.febs.server.hr.entity.EmpBaseInfo;
import cc.mrbird.febs.server.hr.feign.IRemoteDeptService;
import cc.mrbird.febs.server.hr.mapper.EmpBaseInfoMapper;
import cc.mrbird.febs.server.hr.service.IEmpBaseInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.util.FileSystemUtils;
import org.springframework.validation.annotation.Validated;
import javax.servlet.http.HttpServletResponse;
@@ -69,12 +68,23 @@
    private final EmpBaseInfoMapper empBaseInfoMapper;
    private final IEmpDimissionLogService dimissionLogService;
    private final IEmpJobChangeService jobChangeService;
    private final IEmpContractInfoService empContractInfoService;
    private final EmpContractInfoMapper empContractInfoMapper;
    private final FebsServerHrProperties properties;
    private final IRemoteDeptService remoteDeptService;
    private final String operatorId = Optional.ofNullable(FebsUtil.getCurrentUser())
            .map(u -> u.getUserId().toString())
            .orElse("1");
    private final EmpWorkExperienceMapper empWorkExperienceMapper;
    private final EmpPhysicalExamMapper empPhysicalExamMapper;
    private final EmpJobChangeMapper empJobChangeMapper;
    private final EmpLeaveInfoMapper empLeaveInfoMapper;
    private final EmpUnemploymentMapper empUnemploymentMapper;
    private final EmpDimissionAttendMapper empDimissionAttendMapper;
    private final EmpInsuranceMapper empInsuranceMapper;
    private final EmpAccidentCasesMapper empAccidentCasesMapper;
    private final EmpLaborTroubleMapper empLaborTroubleMapper;
    private final EmpBadRecordMapper empBadRecordMapper;
    private final EmpRemarkInfoMapper empRemarkInfoMapper;
    private final IRemoteDicItemService remoteDicItemService;
    private final String operatorId = Optional.of(FebsUtil.getUserId()).orElse("1");
    @Override
    public IPage<EmpBaseInfo> findEmpBaseInfos(QueryRequest request, EmpBaseInfo empBaseInfo) {
@@ -104,7 +114,7 @@
                    .filter(k -> DicCode.EMPTYPE.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getEmpType()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("汉族"));
                    .orElse("正式工"));
            // 设置民族
            p.setNationName(dicItems.stream()
                    .filter(k -> DicCode.NATION.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getNation()))
@@ -237,7 +247,12 @@
    @Override
    public boolean verifyEmpNumb(EmpBaseInfo empBaseInfo) {
        QueryWrapper<EmpBaseInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EmpBaseInfo::getEmpNumb, empBaseInfo.getEmpNumb()).ne(EmpBaseInfo::getDelFlag, 1);
        queryWrapper.lambda().eq(EmpBaseInfo::getEmpNumb, empBaseInfo.getEmpNumb())
                .ne(EmpBaseInfo::getDelFlag, 1);
        if (empBaseInfo.getEmpId()!=null) {
            queryWrapper.lambda().ne(EmpBaseInfo::getEmpId, empBaseInfo.getEmpId());
        }
        if (this.count(queryWrapper) <= 0) {
            return false;
        }
@@ -300,14 +315,15 @@
            switch (flag) {
                case 1:
                    //解除合同
                    empContractInfoService.terminateContract(empDimissionLog.getEmpIds(), operatorId);
                    empContractInfoMapper.terminateContract(new ArrayList<>(Arrays.asList(empDimissionLog.getEmpIds().split(StringConstant.COMMA))), operatorId);
                    break;
                case 2:
                    //禁用账户
                    iRemoteUserService.updateStatus(empDimissionLog.getCertificateNumb());
                    break;
                case 3:
                    empContractInfoService.terminateContract(empDimissionLog.getEmpIds(), operatorId);
                    empContractInfoMapper.terminateContract(new ArrayList<>(Arrays.asList(empDimissionLog.getEmpIds().split(StringConstant.COMMA))), operatorId);
                    iRemoteUserService.updateStatus(empDimissionLog.getCertificateNumb());
                    break;
            }
@@ -369,13 +385,13 @@
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void importEmpBaseInfo(List<List<Object>> listObject,List<String>  returnList) {
    public void importEmpBaseInfo(List<List<Object>> listObject, List<String> returnList) {
        for (List<Object> list : listObject) {
            if (list.size()==0){
            if (list.size() == 0) {
                continue;
            }
            if (this.count(new LambdaQueryWrapper<EmpBaseInfo>().eq(EmpBaseInfo::getEmpNumb,list.get(1).toString()).ne(EmpBaseInfo::getDelFlag,1))>0){
                returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}员工编号重复",listObject.indexOf(list),list.get(1).toString()));
            if (this.count(new LambdaQueryWrapper<EmpBaseInfo>().eq(EmpBaseInfo::getEmpNumb, list.get(1).toString()).ne(EmpBaseInfo::getDelFlag, 1)) > 0) {
                returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}员工编号重复", listObject.indexOf(list) + 1, list.get(1).toString()));
                continue;
            }
            EmpBaseInfo empBaseInfo = new EmpBaseInfo();
@@ -387,7 +403,7 @@
            empBaseInfo.setDeptName(list.get(3).toString());
            Dept dept = depts.stream().filter(d -> d.getDeptName().equals(list.get(3).toString())).findFirst().orElse(null);
            if (null == dept) {
                returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}部门不存在",listObject.indexOf(list),list.get(3).toString()));
                returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}部门不存在", listObject.indexOf(list) + 1, list.get(3).toString()));
                continue;
            }
            empBaseInfo.setDeptId(dept.getDeptId());
@@ -826,7 +842,7 @@
    }
    private QueryWrapper<EmpBaseInfo> createQueryWrapper(EmpBaseInfo empBaseInfo) {
       QueryWrapper<EmpBaseInfo> queryWrapper = new QueryWrapper<>();
        QueryWrapper<EmpBaseInfo> queryWrapper = new QueryWrapper<>();
        //记录的状态,0-正常 1-删除 2-暂存
        if (StringUtils.isNotBlank(empBaseInfo.getDelFlag().toString())) {
            queryWrapper.eq("a.DelFlag", empBaseInfo.getDelFlag());
@@ -838,6 +854,12 @@
            queryWrapper.in("a.EmpStatus", empBaseInfo.getEmpStatus().split(","));
        } else {
            queryWrapper.in("a.EmpStatus", 0);
        }
        if (StringUtils.isNotBlank(empBaseInfo.getEmpCardStatus())) {
            queryWrapper.in("a.empCardStatus", empBaseInfo.getEmpCardStatus().split(","));
        }
        if (StringUtils.isNotBlank(empBaseInfo.getHandbookStatus())) {
            queryWrapper.in("a.handBookStatus", empBaseInfo.getHandbookStatus().split(","));
        }
        // 下面的条件就是人员的属性条件,条件之间是或的关系
        if (this.checkQueryCondition(empBaseInfo)) {
@@ -855,10 +877,10 @@
                    p.or().like("a.CertificateNumb", empBaseInfo.getCertificateNumb());
                }
                if (StringUtils.isNotBlank(empBaseInfo.getEntryDateStr())) {
                    p.or().between("a.EntryDate", empBaseInfo.getEntryDateStr().split(",")[0], empBaseInfo.getEntryDateStr().split(",")[1]);
                    p.between("a.EntryDate", empBaseInfo.getEntryDateStr().split(",")[0], empBaseInfo.getEntryDateStr().split(",")[1]);
                }
                if (StringUtils.isNotBlank(empBaseInfo.getDimissionDateStr())) {
                    p.or().between("a.DimissionDate", empBaseInfo.getDimissionDateStr().split(",")[0], empBaseInfo.getDimissionDateStr().split(",")[1]);
                    p.between("a.DimissionDate", empBaseInfo.getDimissionDateStr().split(",")[0], empBaseInfo.getDimissionDateStr().split(",")[1]);
                }
                if (StringUtils.isNotBlank(empBaseInfo.getSex())) {
                    p.or().in("a.Sex", empBaseInfo.getSex().split(","));
@@ -893,6 +915,9 @@
                if (StringUtils.isNotBlank(empBaseInfo.getEmpCardStatus())) {
                    p.or().in("a.EmpCardStatus", empBaseInfo.getEmpCardStatus().split(","));
                }
                if (StringUtils.isNotBlank(empBaseInfo.getEmpType())) {
                    p.or().in("a.empType", empBaseInfo.getEmpType().split(","));
                }
            });
        }
        queryWrapper.in("c.dept_Id", remoteDeptService.userRightDepts().split(StringConstant.COMMA));
@@ -909,4 +934,145 @@
            return dbEmpInfo;
        }
    }
    @Override
    public Long getEmpIdByEmpNumb(String empNumb) {
        try {
            return this.getOne(new LambdaQueryWrapper<EmpBaseInfo>().eq(EmpBaseInfo::getEmpNumb, empNumb).ne(EmpBaseInfo::getDelFlag, 1)).getEmpId();
        } catch (Exception e) {
            return null;
        }
    }
    @Override
    public EmpBaseInfo getEmpBaseInfoByEmpNumb(String empNumb) {
        try {
            return this.getOne(new LambdaQueryWrapper<EmpBaseInfo>().eq(EmpBaseInfo::getEmpNumb,empNumb).ne(EmpBaseInfo::getDelFlag,1));
        }catch (Exception e){
            return  null;
        }
    }
    @Override
    public void exportEmpAll(HttpServletResponse response, EmpBaseInfo empBaseinfo) throws IOException {
        //获取字典
        List<DicItem> dicItemList = remoteDicItemService.getAllDicitemsAll();
        Map<String, Object> map = new HashMap<>();
        List<Long> itemCode = dicItemList.stream().map(i->i.getDicId()).distinct().collect(Collectors.toList());
        itemCode.stream().forEach(i->{
           List<DicItem> dicItems =  dicItemList.stream().filter(j->j.getDicId().equals(i)).collect(Collectors.toList());
            Map<String, Object> itemMap = new HashMap<>();
            dicItems.stream().forEach(dicItem -> itemMap.put(dicItem.getDicItemCode(),dicItem.getDicItemName()));
            map.put(dicItems.get(0).getDicCode().toLowerCase(),itemMap);
        });
        //基本信息
        QueryRequest request = new QueryRequest();
        request.setPageSize(25535);
        request.setPageNum(1);
        List<EmpBaseInfo> exportList = this.findZsEmpBaseInfos(request, empBaseinfo).getRecords();
        List<Map<String, Object>> listMapDicItem = new ArrayList();
        listMapDicItem.add(map);
        String exportField = FebsUtil. reflectAnnotation(EmpBaseInfo.class);
        List<Map<String, Object>> allList = PoiExportExcel.getDataList(exportField, exportList, listMapDicItem);
        Page<EmpBaseInfo> page = new Page<>(request.getPageNum(), request.getPageSize());
        List<Long> empIds = exportList.stream().map(i->i.getEmpId()).collect(Collectors.toList());
        //工作经历
        IPage<EmpWorkExperience> workExperienceIPage = empWorkExperienceMapper.selectPageVo(page,new QueryWrapper<EmpWorkExperience>().in("a.empId",empIds).ne("a.delFlag",1));
        exportField = FebsUtil. reflectAnnotation(EmpWorkExperience.class);
        List<Map<String, Object>> allListEmpWork = PoiExportExcel.getDataList(exportField, workExperienceIPage.getRecords(), listMapDicItem);
        allList.add(allListEmpWork.get(0));
        //体检信息
        IPage<EmpPhysicalExam> empPhysicalExamIPage = empPhysicalExamMapper.selectPageVo(page,new QueryWrapper<EmpPhysicalExam>().in("a.empId",empIds).ne("a.delFlag",1));
        exportField = FebsUtil. reflectAnnotation(EmpWorkExperience.class);
        List<Map<String, Object>> allListEmpPhysical = PoiExportExcel.getDataList(exportField, empPhysicalExamIPage.getRecords(), listMapDicItem);
        allList.add(allListEmpPhysical.get(0));
        //调岗记录
        IPage<EmpJobChange> jobChangeIPage = empJobChangeMapper.selectPageVoBean(page,new QueryWrapper<EmpJobChange>().in("a.empId",empIds).ne("a.delFlag",1));
        exportField = FebsUtil. reflectAnnotation(EmpJobChange.class);
        List<Map<String, Object>> allListjobChangeI = PoiExportExcel.getDataList(exportField, jobChangeIPage.getRecords(), listMapDicItem);
        allList.add(allListjobChangeI.get(0));
        //合同信息
        IPage<EmpContractInfo> empContractInfoIPage = empContractInfoMapper.selectPageVo(page,new QueryWrapper<EmpContractInfo>().in("a.empId",empIds).ne("a.delFlag",1));
        exportField = FebsUtil. reflectAnnotation(EmpContractInfo.class);
        List<Map<String, Object>> allListEmpContractInfo = PoiExportExcel.getDataList(exportField, empContractInfoIPage.getRecords(), listMapDicItem);
        allList.add(allListEmpContractInfo.get(0));
        //入离职记录
        IPage<EmpDimissionAttend> empDimissionAttendIPage = empDimissionAttendMapper.selectPageVo(page,new QueryWrapper<EmpDimissionAttend>().in("a.empId",empIds).ne("a.delFlag",1));
        exportField = FebsUtil. reflectAnnotation(EmpDimissionAttend.class);
        List<Map<String, Object>> allListEmpDimissionAtt = PoiExportExcel.getDataList(exportField, empDimissionAttendIPage.getRecords(), listMapDicItem);
        allList.add(allListEmpDimissionAtt.get(0));
        //请假记录
        IPage<EmpLeaveInfo> empLeaveInfoIPage = empLeaveInfoMapper.selectPageVo(page,new QueryWrapper<EmpLeaveInfo>().in("a.empId",empIds).ne("a.delFlag",1));
        exportField = FebsUtil. reflectAnnotation(EmpLeaveInfo.class);
        List<Map<String, Object>> allListEmpLoeaveInfo = PoiExportExcel.getDataList(exportField, empLeaveInfoIPage.getRecords(), listMapDicItem);
        allList.add(allListEmpLoeaveInfo.get(0));
        //失业金领取
        IPage<EmpUnemployment> empUnemploymentIPage = empUnemploymentMapper.selectPageVo(page,new QueryWrapper<EmpUnemployment>().in("a.empId",empIds).ne("a.delFlag",1));
        exportField = FebsUtil. reflectAnnotation(EmpUnemployment.class);
        List<Map<String, Object>> allListEmpUnemployment = PoiExportExcel.getDataList(exportField, empUnemploymentIPage.getRecords(), listMapDicItem);
        allList.add(allListEmpUnemployment.get(0));
        //社保申请
        IPage<EmpInsurance> empInsuranceIPage = empInsuranceMapper.selectPageVo(page,new QueryWrapper<EmpInsurance>().in("a.empId",empIds).ne("a.delFlag",1));
        exportField = FebsUtil. reflectAnnotation(EmpInsurance.class);
        List<Map<String, Object>> allListEmpInsurance = PoiExportExcel.getDataList(exportField, empInsuranceIPage.getRecords(), listMapDicItem);
        allList.add(allListEmpInsurance.get(0));
        //意外险案件
        IPage<EmpAccidentCases> empAccidentCasesIPage = empAccidentCasesMapper.selectPageVo(page,new QueryWrapper<EmpInsurance>().in("a.empId",empIds).ne("a.delFlag",1));
        exportField = FebsUtil. reflectAnnotation(EmpAccidentCases.class);
        List<Map<String, Object>> allListEmpAccidentCases = PoiExportExcel.getDataList(exportField, empAccidentCasesIPage.getRecords(), listMapDicItem);
        allList.add(allListEmpAccidentCases.get(0));
        //劳资案件
        IPage<EmpLaborTrouble> empLaborTroubleIPage = empLaborTroubleMapper.selectPageVo(page,new QueryWrapper<EmpInsurance>().in("a.empId",empIds).ne("a.delFlag",1));
        exportField = FebsUtil. reflectAnnotation(EmpLaborTrouble.class);
        List<Map<String, Object>> allListEmpLaborTrouble = PoiExportExcel.getDataList(exportField, empLaborTroubleIPage.getRecords(), listMapDicItem);
        allList.add(allListEmpLaborTrouble.get(0));
        //不良记录
        IPage<EmpBadRecord> empBadRecordIPage = empBadRecordMapper.selectPageVo(page,new QueryWrapper<EmpInsurance>().in("a.empId",empIds).ne("a.delFlag",1));
        exportField = FebsUtil. reflectAnnotation(EmpBadRecord.class);
        List<Map<String, Object>> allListEmpBadRecord = PoiExportExcel.getDataList(exportField, empBadRecordIPage.getRecords(), listMapDicItem);
        allList.add(allListEmpBadRecord.get(0));
        //备注信息
        IPage<EmpRemarkInfo> empRemarkInfoIPage = empRemarkInfoMapper.selectPageVo(page,new QueryWrapper<EmpRemarkInfo>().in("a.empId",empIds).ne("a.delFlag",1));
        exportField = FebsUtil. reflectAnnotation(EmpRemarkInfo.class);
        List<Map<String, Object>> allListEmpRemarkInfo = PoiExportExcel.getDataList(exportField, empRemarkInfoIPage.getRecords(), listMapDicItem);
        allList.add(allListEmpRemarkInfo.get(0));
        List<String> sheetNames = new ArrayList<>();
        sheetNames.add("基本信息");
        sheetNames.add("工作经历");
        sheetNames.add("体检信息");
        sheetNames.add("调岗记录");
        sheetNames.add("合同信息");
        sheetNames.add("入离职记录");
        sheetNames.add("请假记录");
        sheetNames.add("失业金领取");
        sheetNames.add("社保申请");
        sheetNames.add("意外险案件");
        sheetNames.add("工商案件");
        sheetNames.add("劳资案件");
        sheetNames.add("不良记录");
        sheetNames.add("备注信息");
        boolean result = PoiExportExcel.exportCommonExcelMultiSheet(response, "在职员工列表",allList,sheetNames);
    }
}