package com.engine.salary.service.impl; import com.cloudstore.eccom.pc.table.WeaTableColumn; import com.engine.common.util.ServiceUtil; import com.engine.core.impl.Service; import com.engine.salary.biz.SIArchivesBiz; import com.engine.salary.cmd.siarchives.SIArchivesTipsCmd; import com.engine.salary.entity.siarchives.bo.InsuranceArchivesBaseInfoBO; import com.engine.salary.entity.siarchives.param.InsuranceArchivesListParam; import com.engine.salary.entity.siarchives.param.InsuranceArchivesSaveParam; import com.engine.salary.entity.siarchives.po.*; import com.engine.salary.entity.taxagent.dto.TaxAgentEmployeeDTO; import com.engine.salary.entity.taxagent.dto.TaxAgentManageRangeEmployeeDTO; import com.engine.salary.entity.taxagent.po.TaxAgentEmpChangePO; import com.engine.salary.entity.taxagent.po.TaxAgentPO; import com.engine.salary.enums.siaccount.EmployeeStatusEnum; import com.engine.salary.enums.sicategory.DeleteTypeEnum; import com.engine.salary.enums.sicategory.NonPaymentEnum; import com.engine.salary.enums.sicategory.WelfareTypeEnum; import com.engine.salary.enums.taxagent.TaxAgentEmpChangeModuleEnum; import com.engine.salary.mapper.siarchives.FundSchemeMapper; import com.engine.salary.mapper.siarchives.InsuranceBaseInfoMapper; import com.engine.salary.mapper.siarchives.OtherSchemeMapper; import com.engine.salary.mapper.siarchives.SocialSchemeMapper; import com.engine.salary.service.SIArchivesService; import com.engine.salary.service.TaxAgentEmpChangeService; import com.engine.salary.service.TaxAgentService; import com.engine.salary.sys.entity.vo.OrderRuleVO; import com.engine.salary.sys.service.SalarySysConfService; import com.engine.salary.sys.service.impl.SalarySysConfServiceImpl; import com.engine.salary.util.SalaryEntityUtil; import com.engine.salary.util.SalaryI18nUtil; import com.engine.salary.util.db.MapperProxyFactory; import com.engine.salary.util.excel.ExcelUtil; import com.google.common.collect.Lists; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.transaction.annotation.Transactional; import weaver.general.Util; import weaver.hrm.User; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; /** * @Author weaver_cl * @Description: * @Date 2022/3/11 * @Version V1.0 **/ public class SIArchivesServiceImpl extends Service implements SIArchivesService { private SIArchivesBiz siArchivesBiz = new SIArchivesBiz(); private TaxAgentService getTaxAgentService(User user) { return ServiceUtil.getService(TaxAgentServiceImpl.class, user); } private SalarySysConfService getSalarySysConfService(User user) { return ServiceUtil.getService(SalarySysConfServiceImpl.class, user); } private InsuranceBaseInfoMapper getInsuranceBaseInfoMapper() { return MapperProxyFactory.getProxy(InsuranceBaseInfoMapper.class); } private TaxAgentEmpChangeService getTaxAgentEmpChangeService(User user) { return ServiceUtil.getService(TaxAgentEmpChangeServiceImpl.class, user); } private SocialSchemeMapper getSocialSchemeMapper() { return MapperProxyFactory.getProxy(SocialSchemeMapper.class); } private FundSchemeMapper getFundSchemeMapper() { return MapperProxyFactory.getProxy(FundSchemeMapper.class); } private OtherSchemeMapper getOtherSchemeMapper() { return MapperProxyFactory.getProxy(OtherSchemeMapper.class); } @Override public Map getTips(Map params) { return commandExecutor.execute(new SIArchivesTipsCmd(params, user)); } @Override public Map getBaseForm(Map params) { long currentEmployeeId = user.getUID(); Boolean needAuth = getTaxAgentService(user).isNeedAuth(currentEmployeeId); Collection taxAgentPOS = getTaxAgentService(user).listAllTaxAgentsAsAdmin(currentEmployeeId); Map apidatas = new HashMap<>(16); SIArchivesBiz siArchivesBiz = new SIArchivesBiz(); siArchivesBiz.setNeedAuth(needAuth); siArchivesBiz.setTaxAgentPOS(taxAgentPOS); WelfareTypeEnum welfareTypeEnum = (WelfareTypeEnum) params.get("welfareTypeEnum"); Long employeeId = Long.valueOf(Util.null2String(params.get("employeeId"))); apidatas = siArchivesBiz.getBaseForm(welfareTypeEnum, employeeId, (long) user.getUID(), user); return apidatas; } @Override public Map getPaymentForm(Map params) { Map apidatas = new HashMap<>(16); SIArchivesBiz siArchivesBiz = new SIArchivesBiz(); WelfareTypeEnum welfareTypeEnum = (WelfareTypeEnum) params.get("welfareTypeEnum"); Long employeeId = Long.valueOf(Util.null2String(params.get("employeeId"))); String schemeIdStr = Util.null2String(params.get("schemeId")); Long schemeId = null; if (StringUtils.isNotBlank(schemeIdStr)) { schemeId = Long.valueOf(schemeIdStr); } apidatas = siArchivesBiz.getPaymentForm(user, welfareTypeEnum, employeeId, (long) user.getUID(), schemeId); return apidatas; } @Override public String insert(InsuranceArchivesSaveParam param) { SIArchivesBiz siArchivesBiz = new SIArchivesBiz(); siArchivesBiz.insert(param, (long) user.getUID()); return null; } @Override public Map listPage(InsuranceArchivesListParam param) { long currentEmployeeId = user.getUID(); // 2.待减员自动处理 handleStayDelData(currentEmployeeId); // 3.增量数据处理 handleChangeData(currentEmployeeId); //排序配置 OrderRuleVO orderRule = getSalarySysConfService(user).orderRule(); param.setOrderRule(orderRule); Boolean needAuth = getTaxAgentService(user).isNeedAuth(currentEmployeeId); param.setNeedAuth(needAuth); if (needAuth) { List taxAgentEmployeeDTOS = getTaxAgentService(user).listTaxAgentAndEmployee(currentEmployeeId); Set employeeIds = SalaryEntityUtil.properties(taxAgentEmployeeDTOS, TaxAgentEmployeeDTO::getEmployeeId); Set taxAgentIds = SalaryEntityUtil.properties(taxAgentEmployeeDTOS, TaxAgentEmployeeDTO::getTaxAgentId); param.setTaxAgentEmployeeIds(employeeIds); param.setTaxAgentIds(taxAgentIds); } Map apidatas = new HashMap<>(16); SIArchivesBiz siArchivesBiz = new SIArchivesBiz(); apidatas = siArchivesBiz.listPage(param, (long) user.getUID()); return apidatas; } /** * 福利档案中待减员数据自动处理 * @param currentEmployeeId */ @Transactional(rollbackFor = Exception.class) private void handleStayDelData(long currentEmployeeId) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM"); String today = simpleDateFormat.format(new Date()); //part1,员工维护了社保/公积金/其他福利最后缴纳日,且任一类信息大于今天的,自动将待减员状态置为正在缴纳状态 List rePayList = getInsuranceBaseInfoMapper().getRePayList(today); updateInsuranceBaseInfoRunStatus(rePayList, EmployeeStatusEnum.PAYING.getValue()); //part2,员工维护了社保/公积金/其他福利最后缴纳日,且三类信息都小于今天的,自动置为待减员状态 List reStayDelList = getInsuranceBaseInfoMapper().getReStayDelList(today); updateInsuranceBaseInfoRunStatus(reStayDelList, EmployeeStatusEnum.STAY_DEL.getValue()); //part3,非在职员工且处于正常缴纳的福利档案置为待减员状态 //定义非在职的人事状态 List personnelStatuses = new ArrayList() {{ add("5"); add("6"); add("7"); }}; if (CollectionUtils.isNotEmpty(personnelStatuses)) { //获取非在职员工的福利档案基础信息 InsuranceArchivesListParam insuranceArchivesListParam = new InsuranceArchivesListParam(); insuranceArchivesListParam.setPersonnelStatuses(personnelStatuses); insuranceArchivesListParam.setRunStatuses(Collections.singletonList(EmployeeStatusEnum.PAYING.getValue())); List noNormalList = getInsuranceBaseInfoMapper().getAbnormalList(insuranceArchivesListParam); updateInsuranceBaseInfoRunStatus(noNormalList, EmployeeStatusEnum.STAY_DEL.getValue()); } } /** * 福利档案中增量数据处理 * @param currentEmployeeId */ @Transactional(rollbackFor = Exception.class) private void handleChangeData(long currentEmployeeId) { // 所有增量人员列表 List taxAgentEmpChangeList = getTaxAgentEmpChangeService(user).listAllByModule(TaxAgentEmpChangeModuleEnum.INSURANCE_ARCHIVE); if (CollectionUtils.isEmpty(taxAgentEmpChangeList)) { return; } // 当前可以管辖的人员 Collection taxAgentList = getTaxAgentService(user).listAllTaxAgents(currentEmployeeId); taxAgentEmpChangeList = taxAgentEmpChangeList.stream().filter(f -> taxAgentList.stream().anyMatch(e -> e.getId().equals(f.getTaxAgentId()))).collect(Collectors.toList()); if (CollectionUtils.isEmpty(taxAgentEmpChangeList)) { return; } // 所有福利档案基础信息数据 List baseInfoPOList = getInsuranceBaseInfoMapper().listAll(); InsuranceArchivesBaseInfoBO.ChangeData changeData = InsuranceArchivesBaseInfoBO.buildChangeData(taxAgentEmpChangeList, baseInfoPOList, currentEmployeeId); // 批量修改福利档案 if (CollectionUtils.isNotEmpty(changeData.getBaseInfoUpdateTodoList())) { //对于即将调整为“待减员”的数据,更新社保、公积金、其他福利档案的停止缴纳时间 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM"); String today = simpleDateFormat.format(new Date()); List toStayDelList = changeData.getBaseInfoUpdateTodoList().stream() .filter(f -> f.getRunStatus().equals(EmployeeStatusEnum.STAY_DEL.getValue())) .collect(Collectors.toList()); if (toStayDelList.size() > 0) { List> partitionUpdateEndTime = Lists.partition(toStayDelList, 100); partitionUpdateEndTime.forEach(part->{ List socialIds = part.stream().map(InsuranceArchivesBaseInfoPO::getSocialArchivesId).collect(Collectors.toList()); List fundIds = part.stream().map(InsuranceArchivesBaseInfoPO::getFundArchivesId).collect(Collectors.toList()); List otherIds = part.stream().map(InsuranceArchivesBaseInfoPO::getOtherArchivesId).collect(Collectors.toList()); getSocialSchemeMapper().batchUpdateEndTime(socialIds, today); getFundSchemeMapper().batchUpdateEndTime(fundIds, today); getOtherSchemeMapper().batchUpdateEndTime(otherIds, today); }); } //修改福利档案基础信息 List> partitionUpdateBase = Lists.partition(changeData.getBaseInfoUpdateTodoList(), 100); partitionUpdateBase.forEach(part-> getInsuranceBaseInfoMapper().batchUpdate(part)); } // 批量新增福利档案 if (CollectionUtils.isNotEmpty(changeData.getBaseInfoAddTodoList())) { //新增社保、公积金、其他福利档案、福利档案基础信息 addNewInsuranceBaseInfo(changeData.getBaseInfoAddTodoList(), currentEmployeeId); } // 删除增量数据 if (CollectionUtils.isNotEmpty(changeData.getChangeIds())) { getTaxAgentEmpChangeService(user).deleleByIds(changeData.getChangeIds()); } } //新增社保、公积金、其他福利档案、福利档案基础信息 private List addNewInsuranceBaseInfo(List baseInfoPOList, Long currentEmployeeId) { List socialList = new ArrayList<>(); List fundList = new ArrayList<>(); List otherList = new ArrayList<>(); for (InsuranceArchivesBaseInfoPO baseInfoPO : baseInfoPOList) { InsuranceArchivesSocialSchemePO insuranceArchivesSocialSchemePO = new InsuranceArchivesSocialSchemePO(); insuranceArchivesSocialSchemePO.setTenantKey(""); insuranceArchivesSocialSchemePO.setWelfareType(WelfareTypeEnum.SOCIAL_SECURITY.getValue()); insuranceArchivesSocialSchemePO.setPaymentOrganization(baseInfoPO.getPaymentOrganization()); insuranceArchivesSocialSchemePO.setNonPayment(NonPaymentEnum.YES.getValue()); insuranceArchivesSocialSchemePO.setCreator(currentEmployeeId); insuranceArchivesSocialSchemePO.setCreateTime(new Date()); insuranceArchivesSocialSchemePO.setUpdateTime(new Date()); insuranceArchivesSocialSchemePO.setDeleteType(DeleteTypeEnum.NOT_DELETED.getValue()); insuranceArchivesSocialSchemePO.setEmployeeId(baseInfoPO.getEmployeeId()); socialList.add(insuranceArchivesSocialSchemePO); InsuranceArchivesFundSchemePO insuranceArchivesFundSchemePO = new InsuranceArchivesFundSchemePO(); insuranceArchivesFundSchemePO.setTenantKey(""); insuranceArchivesFundSchemePO.setWelfareType(WelfareTypeEnum.ACCUMULATION_FUND.getValue()); insuranceArchivesFundSchemePO.setPaymentOrganization(baseInfoPO.getPaymentOrganization()); insuranceArchivesFundSchemePO.setNonPayment(NonPaymentEnum.YES.getValue()); insuranceArchivesFundSchemePO.setCreator(currentEmployeeId); insuranceArchivesFundSchemePO.setCreateTime(new Date()); insuranceArchivesFundSchemePO.setUpdateTime(new Date()); insuranceArchivesFundSchemePO.setDeleteType(DeleteTypeEnum.NOT_DELETED.getValue()); insuranceArchivesFundSchemePO.setEmployeeId(baseInfoPO.getEmployeeId()); fundList.add(insuranceArchivesFundSchemePO); InsuranceArchivesOtherSchemePO insuranceArchivesOtherSchemePO = new InsuranceArchivesOtherSchemePO(); insuranceArchivesOtherSchemePO.setTenantKey(""); insuranceArchivesOtherSchemePO.setWelfareType(WelfareTypeEnum.OTHER.getValue()); insuranceArchivesOtherSchemePO.setPaymentOrganization(baseInfoPO.getPaymentOrganization()); insuranceArchivesOtherSchemePO.setNonPayment(NonPaymentEnum.YES.getValue()); insuranceArchivesOtherSchemePO.setCreator(currentEmployeeId); insuranceArchivesOtherSchemePO.setCreateTime(new Date()); insuranceArchivesOtherSchemePO.setUpdateTime(new Date()); insuranceArchivesOtherSchemePO.setDeleteType(DeleteTypeEnum.NOT_DELETED.getValue()); insuranceArchivesOtherSchemePO.setEmployeeId(baseInfoPO.getEmployeeId()); otherList.add(insuranceArchivesOtherSchemePO); } //导入社保档案 if (CollectionUtils.isNotEmpty(socialList)) { socialList = socialList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(InsuranceArchivesSocialSchemePO::getEmployeeId))), ArrayList::new)); List socialEmployeeIds = socialList.stream().map(InsuranceArchivesSocialSchemePO::getEmployeeId).collect(Collectors.toList()); List> socialEmployeeIdPartition = Lists.partition(socialEmployeeIds, 100); socialEmployeeIdPartition.forEach(getSocialSchemeMapper()::batchDeleteByEmployeeIds); List> partition = Lists.partition(socialList, 100); partition.forEach(getSocialSchemeMapper()::batchSave); } //导入公积金档案 if (CollectionUtils.isNotEmpty(fundList)) { fundList = fundList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(InsuranceArchivesFundSchemePO::getEmployeeId))), ArrayList::new)); List fundEmployeeIds = fundList.stream().map(InsuranceArchivesFundSchemePO::getEmployeeId).collect(Collectors.toList()); List> fundEmployeeIdsPartition = Lists.partition(fundEmployeeIds, 100); fundEmployeeIdsPartition.forEach(getFundSchemeMapper()::batchDeleteByEmployeeIds); List> partition = Lists.partition(fundList, 100); partition.forEach(getFundSchemeMapper()::batchSave); } //导入其他福利档案 if (CollectionUtils.isNotEmpty(otherList)) { otherList = otherList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(InsuranceArchivesOtherSchemePO::getEmployeeId))), ArrayList::new)); List otherEmployeeIds = otherList.stream().map(InsuranceArchivesOtherSchemePO::getEmployeeId).collect(Collectors.toList()); List> otherEmployeeIdsPartition = Lists.partition(otherEmployeeIds, 100); otherEmployeeIdsPartition.forEach(getOtherSchemeMapper()::batchDeleteByEmployeeIds); List> partition = Lists.partition(otherList, 100); partition.forEach(getOtherSchemeMapper()::batchSave); } //导入福利档案基础信息 if (CollectionUtils.isNotEmpty(baseInfoPOList)) { baseInfoPOList = baseInfoPOList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(InsuranceArchivesBaseInfoPO::getEmployeeId))), ArrayList::new)); //分批批量删除 List baseInfoEmployeeIds = baseInfoPOList.stream().map(InsuranceArchivesBaseInfoPO::getEmployeeId).collect(Collectors.toList()); List> employeeIdPartition = Lists.partition(baseInfoEmployeeIds, 100); employeeIdPartition.forEach(getInsuranceBaseInfoMapper()::batchDeleteByEmployeeIds); //查询目标人员的剩余的福利档案基础信息(社保、公积金、其他福利档案id) List moreBaseInfoPOS = getInsuranceBaseInfoMapper().getInsuranceBaseInfoListByInsuranceDetail(baseInfoEmployeeIds); List newInsuranceArchivesBaseInfoList = new ArrayList<>(); //设置社保、公积金、其他福利档案id for (InsuranceArchivesBaseInfoPO po : baseInfoPOList) { InsuranceArchivesBaseInfoPO moreBaseInfo = moreBaseInfoPOS.stream().filter(s -> Objects.equals(s.getEmployeeId(), po.getEmployeeId())).findFirst().orElse(null); po.setSocialArchivesId(moreBaseInfo.getSocialArchivesId()); po.setFundArchivesId(moreBaseInfo.getFundArchivesId()); po.setOtherArchivesId(moreBaseInfo.getOtherArchivesId()); newInsuranceArchivesBaseInfoList.add(po); } //分批批量入库 List> partition = Lists.partition(newInsuranceArchivesBaseInfoList, 100); partition.forEach(getInsuranceBaseInfoMapper()::batchSave); } return baseInfoPOList; } /** * 分批更新福利档案基础信息的runStatus * @param baseInfoPOList * @param runStatus */ private void updateInsuranceBaseInfoRunStatus(List baseInfoPOList, String runStatus) { if (CollectionUtils.isNotEmpty(baseInfoPOList)) { List idList = baseInfoPOList.stream().map(InsuranceArchivesBaseInfoPO::getId).collect(Collectors.toList()); List> partition = Lists.partition(idList, 999); partition.forEach( part -> { InsuranceArchivesBaseInfoPO baseInfoPO = new InsuranceArchivesBaseInfoPO(); baseInfoPO.setIds(part); baseInfoPO.setRunStatus(runStatus); getInsuranceBaseInfoMapper().updateRunStatusByIds(baseInfoPO); } ); } } @Override public Map getSearchCondition(Map param) { Map apidatas = new HashMap<>(16); SIArchivesBiz siArchivesBiz = new SIArchivesBiz(); apidatas = siArchivesBiz.getSearchCondition(user); return apidatas; } @Override public XSSFWorkbook export(InsuranceArchivesListParam param) { InsuranceArchivesListParam request = InsuranceArchivesListParam.builder().build(); if (param.getHireDate() != null && param.getHireDate().length == 2) { param.setHiredateStart(param.getHireDate()[0]); param.setHiredateEnd(param.getHireDate()[1]); } if (param.getDimissionDate() != null && param.getDimissionDate().length == 2) { param.setDimissionDateStart(param.getDimissionDate()[0]); param.setDimissionDateEnd(param.getDimissionDate()[1]); } if (Objects.equals("fromQuickSearch", param.getDataSource())) { request.setStatuses(param.getStatuses()); request.setKeyword(param.getUserName()); } else { request = param; } request.setPageSize(null); request.setStartNum(null); List insuranceArchivesEmployeePOS = listPageEmployeePOS(request); if (insuranceArchivesEmployeePOS == null) { insuranceArchivesEmployeePOS = new ArrayList<>(); } List> records = siArchivesBiz.buildTableData(insuranceArchivesEmployeePOS); List columns = siArchivesBiz.buildWeaTableColumns(insuranceArchivesEmployeePOS, user.getUID()); //工作簿list List> excelSheetData = new ArrayList<>(); //工作簿名称 String sheetName = SalaryI18nUtil.getI18nLabel(85368, "社保福利档案"); //表头 //表头 excelSheetData.add(Arrays.asList(columns.stream().map(WeaTableColumn::getText).toArray(String[]::new))); //工作簿数据 List> rows = new LinkedList<>(); for (Map recordData : records) { List row = new LinkedList<>(); for (WeaTableColumn column : columns) { row.add(recordData.get(column.getColumn())); } rows.add(row); } excelSheetData.addAll(rows); return ExcelUtil.genWorkbookV2(excelSheetData, sheetName); } @Override public List listPageEmployeePOS(InsuranceArchivesListParam param) { long currentEmployeeId = user.getUID(); Boolean needAuth = getTaxAgentService(user).isNeedAuth(currentEmployeeId); if (needAuth) { List taxAgentEmployeeDTOS = getTaxAgentService(user).listTaxAgentAndEmployee(currentEmployeeId); Set employeeIds = SalaryEntityUtil.properties(taxAgentEmployeeDTOS, TaxAgentEmployeeDTO::getEmployeeId); List list = MapperProxyFactory.getProxy(SocialSchemeMapper.class).queryEmployeeList(param); return list.stream().filter(f -> employeeIds.contains(f.getEmployeeId())).collect(Collectors.toList()); } return MapperProxyFactory.getProxy(SocialSchemeMapper.class).queryEmployeeList(param); } /** * 获取福利档案各tab总人数 */ @Override public Map queryInsuranceTabTotal() { long currentEmployeeId = user.getUID(); // tab页签数量 Map result = new HashMap<>(); Boolean needAuth = getTaxAgentService(user).isNeedAuth(currentEmployeeId); //获取管理的人员范围 List taxAgentEmployeeDTOS = getTaxAgentService(user).listTaxAgentAndEmployeeTree(currentEmployeeId); Map> taxAgentEmployeesMap = SalaryEntityUtil.convert2Map(taxAgentEmployeeDTOS, TaxAgentManageRangeEmployeeDTO::getTaxAgentId, TaxAgentManageRangeEmployeeDTO::getEmployeeList); List list = null; if (needAuth) { // 获取作为管理员的所有个税扣缴义务人列表 Collection taxAgentPOS = getTaxAgentService(user).listAllTaxAgentsAsAdmin(currentEmployeeId); Set taxAgentIds = SalaryEntityUtil.properties(taxAgentPOS, TaxAgentPO::getId); //获取所有福利档案基础信息 List archiveListDTOS = getInsuranceBaseInfoMapper().listAll(); list = archiveListDTOS.stream().filter(dto -> taxAgentIds.contains(dto.getPaymentOrganization())).collect(Collectors.toList()); Boolean adminEnable = getTaxAgentService(user).isAdminEnable(currentEmployeeId); //不是管理员看不到数据,返回空 if (!adminEnable) { list = new ArrayList<>(); } } else { list = getInsuranceBaseInfoMapper().listAll(); } long stayAddTotal = 0L; long payTotal = 0L; long stayDelTotal = 0L; long stopTotal = 0L; for (InsuranceArchivesBaseInfoPO baseInfoPO : list) { if (baseInfoPO.getRunStatus().equals(EmployeeStatusEnum.STAY_ADD.getValue())) { stayAddTotal += 1; } else if (baseInfoPO.getRunStatus().equals(EmployeeStatusEnum.PAYING.getValue()) || baseInfoPO.getRunStatus().equals(EmployeeStatusEnum.STAY_DEL.getValue())) { payTotal += 1; if (baseInfoPO.getRunStatus().equals(EmployeeStatusEnum.STAY_DEL.getValue())) { stayDelTotal += 1; } } else if (baseInfoPO.getRunStatus().equals(EmployeeStatusEnum.STOP_PAYMENT_FROM_ADD.getValue()) || baseInfoPO.getRunStatus().equals(EmployeeStatusEnum.STOP_PAYMENT_FROM_DEL.getValue())) { stopTotal += 1; } } result.put("stayAdd", stayAddTotal); result.put("paying", payTotal); result.put("stayDel", stayDelTotal); result.put("stopPay", stopTotal); return result; } /** * 批量变更档案列表的runStatus */ @Override public void updateRunStatus(InsuranceArchivesBaseInfoPO po) { getInsuranceBaseInfoMapper().updateRunStatusByIds(po); } @Override public void cancelStopPayment(List pos) { List stayAddIds = new ArrayList<>(); List stayDelIds = new ArrayList<>(); for(InsuranceArchivesBaseInfoPO po : pos) { if (po.getRunStatus().equals(EmployeeStatusEnum.STOP_PAYMENT_FROM_ADD.getValue())) { //来自待增员的停缴->待增员 stayAddIds.add(po.getId()); } else if (po.getRunStatus().equals(EmployeeStatusEnum.STOP_PAYMENT_FROM_DEL.getValue())) { //来自待减员的停缴->待减员 stayDelIds.add(po.getId()); } } //更新调整为待增员的数据 InsuranceArchivesBaseInfoPO stayAddPO = InsuranceArchivesBaseInfoPO.builder().ids(stayAddIds).runStatus(EmployeeStatusEnum.STAY_ADD.getValue()).build(); getInsuranceBaseInfoMapper().updateRunStatusByIds(stayAddPO); //更新调整为待减员的数据 InsuranceArchivesBaseInfoPO stayDelPO = InsuranceArchivesBaseInfoPO.builder().ids(stayDelIds).runStatus(EmployeeStatusEnum.STAY_DEL.getValue()).build(); getInsuranceBaseInfoMapper().updateRunStatusByIds(stayDelPO); } /** * 批量减员 */ @Override public String stayDelToStop(List baseInfoPOList) { //分别新建福利档案基础信息相关的社保、公积金、其他福利档案列表 List socialList = new ArrayList<>(); List fundList = new ArrayList<>(); List otherList = new ArrayList<>(); //分别新建福利档案基础信息相关的社保、公积金、其他福利档案可以进行减员的人员列表 List toStopSocialEmployeeIdList = new ArrayList<>(); List toStopFundEmployeeIdList = new ArrayList<>(); List toStopOtherEmployeeIdList = new ArrayList<>(); //分别新建福利档案基础信息相关的社保、公积金、其他福利档案不可以进行减员的人员列表 List noStopSocialEmployeeIdList = new ArrayList<>(); List noStopFundEmployeeIdList = new ArrayList<>(); List noStopOtherEmployeeIdList = new ArrayList<>(); //新建最终可以进行减员的人员列表 List toStopEmployeeIdList = new ArrayList<>(); //新建最终不可以进行减员的人员列表 List noStopEmployeeIds = new ArrayList<>(); //获取待处理的员工id列表 List employeeIds = baseInfoPOList.stream().map(InsuranceArchivesBaseInfoPO::getEmployeeId).collect(Collectors.toList()); //设置最后缴纳月的比较月份 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM"); String todayMonth = simpleDateFormat.format(new Date()); //分别获取福利档案基础信息相关的社保、公积金、其他福利档案id列表 List socialIds = baseInfoPOList.stream().map(InsuranceArchivesBaseInfoPO::getSocialArchivesId).collect(Collectors.toList()); List fundIds = baseInfoPOList.stream().map(InsuranceArchivesBaseInfoPO::getFundArchivesId).collect(Collectors.toList()); List otherIds = baseInfoPOList.stream().map(InsuranceArchivesBaseInfoPO::getOtherArchivesId).collect(Collectors.toList()); //获取可进行减员的社保档案相关人员数据 if (socialIds.size() > 0) { //获取社保档案 socialList = getSocialSchemeMapper().getSocialById(socialIds); //筛选可减员的社保档案相关人员信息 toStopSocialEmployeeIdList = socialList.stream().filter(f->f.getSocialEndTime() != null && f.getSocialEndTime().length() > 0 && (f.getSocialEndTime().compareTo(todayMonth)) <= 0) .map(InsuranceArchivesSocialSchemePO::getEmployeeId).collect(Collectors.toList()); //获取不可减员的社保档案相关人员信息 if (toStopSocialEmployeeIdList.size() != baseInfoPOList.size()) { noStopSocialEmployeeIdList = (List) CollectionUtils.subtract(employeeIds, toStopSocialEmployeeIdList); } } if (fundIds.size() > 0) { fundList = getFundSchemeMapper().getFundById(fundIds); toStopFundEmployeeIdList = fundList.stream().filter(f->f.getFundEndTime() != null && f.getFundEndTime().length() > 0 && (f.getFundEndTime().compareTo(todayMonth)) <= 0) .map(InsuranceArchivesFundSchemePO::getEmployeeId).collect(Collectors.toList()); if (toStopFundEmployeeIdList.size() != baseInfoPOList.size()) { noStopFundEmployeeIdList = (List) CollectionUtils.subtract(employeeIds, toStopFundEmployeeIdList); } } if (otherIds.size() > 0) { otherList = getOtherSchemeMapper().getOtherById(otherIds); toStopOtherEmployeeIdList = otherList.stream().filter(f->f.getOtherEndTime() != null && f.getOtherEndTime().length() > 0 && (f.getOtherEndTime().compareTo(todayMonth)) <= 0) .map(InsuranceArchivesOtherSchemePO::getEmployeeId).collect(Collectors.toList()); if (toStopOtherEmployeeIdList.size() != baseInfoPOList.size()) { noStopOtherEmployeeIdList = (List) CollectionUtils.subtract(employeeIds, toStopOtherEmployeeIdList); } } //获取最终基础信息表中的可减员数据 if (noStopSocialEmployeeIdList.size() == 0 && noStopFundEmployeeIdList.size() == 0 && noStopOtherEmployeeIdList.size() ==0) { //社保、公积金、其他福利档案的可减员的人员信息与入参中的人员信息一致时 toStopEmployeeIdList = employeeIds; } else { //社保、公积金、其他福利档案的可减员的人员信息与入参中的人员信息不一致时,取三类档案不可减员的人员并集,作为最终不可减员的人员信息 noStopEmployeeIds = (List) CollectionUtils.union(CollectionUtils.union(noStopSocialEmployeeIdList, noStopFundEmployeeIdList), noStopOtherEmployeeIdList); //入参人员信息和最终不可减员的人员信息做差集,获得最终可减员的人员信息 toStopEmployeeIdList = (List) CollectionUtils.subtract(employeeIds, noStopEmployeeIds); } //进行减员操作 if (toStopEmployeeIdList.size() > 0) { getInsuranceBaseInfoMapper().updateRunStatusByEmployeeIds(InsuranceArchivesBaseInfoPO.builder() .employeeIds(toStopEmployeeIdList).runStatus(EmployeeStatusEnum.STOP_PAYMENT_FROM_DEL.getValue()).build()); } //输出结果,此处需区分单一减员和批量减员 if (baseInfoPOList.size() == toStopEmployeeIdList.size()) { //减员成功 if (baseInfoPOList.size() == 1) { return "减员成功"; } else { return "批量减员成功"; } } else { //减员失败 if (baseInfoPOList.size() == 1) { return "减员失败,失败原因:数据未正常维护"; } else { return "部分或全部失败:【共提交减员数据" + employeeIds.size() +"条,成功" + toStopEmployeeIdList.size() +"条,失败" + noStopEmployeeIds.size() +"条,失败原因:数据未正常维护】"; } } } /** * 全量减员 */ @Override public String allStayDelToStop() { List allBaseInfoList = getInsuranceBaseInfoMapper().listAll(); if (allBaseInfoList.size() > 0) { List stayDelList = allBaseInfoList.stream().filter(f->f.getRunStatus().equals(EmployeeStatusEnum.STAY_DEL.getValue())).collect(Collectors.toList()); if (stayDelList.size() > 0) { return stayDelToStop(stayDelList); } else { return "当前无待减员数据"; } } else { return "当前无待减员数据"; } } /** * 批量增员 */ @Override public String stayAddToPay(List baseInfoPOList) { //分别新建福利档案基础信息相关的社保、公积金、其他福利档案列表 List socialList = new ArrayList<>(); List fundList = new ArrayList<>(); List otherList = new ArrayList<>(); //分别新建福利档案基础信息相关的社保、公积金、其他福利档案可以进行增员的人员列表 List toPaySocialEmployeeIdList = new ArrayList<>(); List toPayFundEmployeeIdList = new ArrayList<>(); List toPayOtherEmployeeIdList = new ArrayList<>(); //分别新建福利档案基础信息相关的社保、公积金、其他福利档案不可以进行增员的人员列表 List noPaySocialEmployeeIdList = new ArrayList<>(); List noPayFundEmployeeIdList = new ArrayList<>(); List noPayOtherEmployeeIdList = new ArrayList<>(); //新建最终可以进行增员的人员列表 List toPayEmployeeIdList = new ArrayList<>(); //新建最终不可以进行增员的人员列表 List noPayEmployeeIds = new ArrayList<>(); //获取待处理的员工id列表 List employeeIds = baseInfoPOList.stream().map(InsuranceArchivesBaseInfoPO::getEmployeeId).collect(Collectors.toList()); //设置最后缴纳月的比较月份 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM"); String todayMonth = simpleDateFormat.format(new Date()); //分别获取福利档案基础信息相关的社保、公积金、其他福利档案id列表 List socialIds = baseInfoPOList.stream().map(InsuranceArchivesBaseInfoPO::getSocialArchivesId).collect(Collectors.toList()); List fundIds = baseInfoPOList.stream().map(InsuranceArchivesBaseInfoPO::getFundArchivesId).collect(Collectors.toList()); List otherIds = baseInfoPOList.stream().map(InsuranceArchivesBaseInfoPO::getOtherArchivesId).collect(Collectors.toList()); //获取可进行增员的社保档案相关人员数据 if (socialIds.size() > 0) { //获取社保档案 socialList = getSocialSchemeMapper().getSocialById(socialIds); //筛选可增员的社保档案相关人员信息 toPaySocialEmployeeIdList = socialList.stream().filter(f-> { boolean flag = true; if (f.getSocialStartTime() == null || f.getSocialStartTime().length() == 0 || f.getSocialSchemeId() == null) { flag = false; } if (f.getSocialEndTime() != null && f.getSocialEndTime().length() > 0 && (f.getSocialEndTime().compareTo(todayMonth)) <= 0) { flag = false; } return flag; }) .map(InsuranceArchivesSocialSchemePO::getEmployeeId).collect(Collectors.toList()); //获取不可增员的社保档案相关人员信息 if (toPaySocialEmployeeIdList.size() != baseInfoPOList.size()) { noPaySocialEmployeeIdList = (List) CollectionUtils.subtract(employeeIds, toPaySocialEmployeeIdList); } } if (fundIds.size() > 0) { fundList = getFundSchemeMapper().getFundById(fundIds); toPayFundEmployeeIdList = fundList.stream().filter(f-> { boolean flag = true; if (f.getFundStartTime() == null || f.getFundStartTime().length() == 0 || f.getFundSchemeId() == null) { flag = false; } if (f.getFundEndTime() != null && f.getFundEndTime().length() > 0 && (f.getFundEndTime().compareTo(todayMonth)) <= 0) { flag = false; } return flag; }) .map(InsuranceArchivesFundSchemePO::getEmployeeId).collect(Collectors.toList()); if (toPayFundEmployeeIdList.size() != baseInfoPOList.size()) { noPayFundEmployeeIdList = (List) CollectionUtils.subtract(employeeIds, toPayFundEmployeeIdList); } } if (otherIds.size() > 0) { otherList = getOtherSchemeMapper().getOtherById(otherIds); toPayOtherEmployeeIdList = otherList.stream().filter(f-> { boolean flag = true; if (f.getOtherStartTime() == null || f.getOtherStartTime().length() == 0 || f.getOtherSchemeId() == null) { flag = false; } if (f.getOtherEndTime() != null && f.getOtherEndTime().length() > 0 && (f.getOtherEndTime().compareTo(todayMonth)) <= 0) { flag = false; } return flag; }) .map(InsuranceArchivesOtherSchemePO::getEmployeeId).collect(Collectors.toList()); if (toPayOtherEmployeeIdList.size() != baseInfoPOList.size()) { noPayOtherEmployeeIdList = (List) CollectionUtils.subtract(employeeIds, toPayOtherEmployeeIdList); } } //获取最终基础信息表中的可增员数据 if (noPaySocialEmployeeIdList.size() == 0 && noPayFundEmployeeIdList.size() == 0 && noPayOtherEmployeeIdList.size() ==0) { //社保、公积金、其他福利档案的可增员的人员信息与入参中的人员信息一致时 toPayEmployeeIdList = employeeIds; } else { //社保、公积金、其他福利档案的可增员的人员信息与入参中的人员信息不一致时,取三类档案可增员的人员并集,作为最终可增员的人员信息 toPayEmployeeIdList = (List) CollectionUtils.union(CollectionUtils.union(toPaySocialEmployeeIdList, toPayFundEmployeeIdList), toPayOtherEmployeeIdList); //入参人员信息和最终可增员的人员信息做差集,获得最终不可增员的人员信息 noPayEmployeeIds = (List) CollectionUtils.subtract(employeeIds, toPayEmployeeIdList); } //其他的个税扣缴义务人下的在缴员工中存在该员工,在缴员工未进入停缴员工时,不可进行增员 //进行增员操作 if (toPayEmployeeIdList.size() > 0) { getInsuranceBaseInfoMapper().updateRunStatusByEmployeeIds(InsuranceArchivesBaseInfoPO.builder() .employeeIds(toPayEmployeeIdList).runStatus(EmployeeStatusEnum.PAYING.getValue()).build()); } //输出结果,此处需区分单一增员和批量增员 if (baseInfoPOList.size() == toPayEmployeeIdList.size()) { //增员成功 if (baseInfoPOList.size() == 1) { return "增员成功"; } else { return "批量增员成功"; } } else { //增员失败 if (baseInfoPOList.size() == 1) { return "增员失败,失败原因:数据未正常维护"; } else { return "部分或全部失败:【共提交增员数据" + employeeIds.size() +"条,成功" + toPayEmployeeIdList.size() +"条,失败" + noPayEmployeeIds.size() +"条,失败原因:数据未正常维护】"; } } } /** * 全量增员 */ @Override public String allStayAddToPay() { List allBaseInfoList = getInsuranceBaseInfoMapper().listAll(); if (allBaseInfoList.size() > 0) { List stayAddList = allBaseInfoList.stream().filter(f->f.getRunStatus().equals(EmployeeStatusEnum.STAY_ADD.getValue())).collect(Collectors.toList()); if (stayAddList.size() > 0) { return stayAddToPay(stayAddList); } else { return "当前无待增员数据"; } } else { return "当前无待增员数据"; } } }