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.param.InsuranceArchivesListParam; import com.engine.salary.entity.siarchives.param.InsuranceArchivesSaveParam; import com.engine.salary.entity.siarchives.po.InsuranceArchivesBaseInfoPO; import com.engine.salary.entity.siarchives.po.InsuranceArchivesEmployeePO; import com.engine.salary.entity.taxagent.dto.TaxAgentEmployeeDTO; import com.engine.salary.entity.taxagent.dto.TaxAgentManageRangeEmployeeDTO; import com.engine.salary.entity.taxagent.po.TaxAgentPO; import com.engine.salary.enums.siaccount.EmployeeStatusEnum; import com.engine.salary.enums.sicategory.WelfareTypeEnum; import com.engine.salary.mapper.siarchives.InsuranceBaseInfoMapper; import com.engine.salary.mapper.siarchives.SocialSchemeMapper; import com.engine.salary.service.SIArchivesService; 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); } @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 */ private void handleChangeData(long currentEmployeeId) { } /** * 分批更新福利档案基础信息的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.getValue())) { stopTotal += 1; } } result.put(EmployeeStatusEnum.STAY_ADD.getValue(), stayAddTotal); result.put(EmployeeStatusEnum.PAYING.getValue(), payTotal); result.put(EmployeeStatusEnum.STAY_DEL.getValue(), stayDelTotal); result.put(EmployeeStatusEnum.STOP_PAYMENT.getValue(), stopTotal); return result; } }