package com.engine.salary.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.TypeReference; import com.engine.common.util.ServiceUtil; import com.engine.core.impl.Service; import com.engine.salary.entity.siarchives.param.InsuranceArchivesListParam; import com.engine.salary.entity.siarchives.po.InsuranceArchivesEmployeePO; import com.engine.salary.entity.siarchives.po.InsuranceArchivesFundSchemePO; import com.engine.salary.entity.siarchives.po.InsuranceArchivesOtherSchemePO; import com.engine.salary.entity.siarchives.po.InsuranceArchivesSocialSchemePO; import com.engine.salary.entity.sicategory.po.ICategoryPO; import com.engine.salary.entity.sischeme.po.InsuranceSchemePO; import com.engine.salary.entity.taxrate.TaxAgent; import com.engine.salary.enums.sicategory.WelfareTypeEnum; import com.engine.salary.mapper.TaxAgentMapper; import com.engine.salary.mapper.siarchives.FundSchemeMapper; import com.engine.salary.mapper.siarchives.OtherSchemeMapper; import com.engine.salary.mapper.siarchives.SocialSchemeMapper; import com.engine.salary.mapper.sicategory.ICategoryMapper; import com.engine.salary.mapper.sischeme.InsuranceSchemeMapper; import com.engine.salary.service.SIArchivesService; import com.engine.salary.service.SIImportService; import com.engine.salary.util.SalaryI18nUtil; import com.engine.salary.util.db.MapperProxyFactory; import com.engine.salary.util.excel.ExcelUtil; import org.apache.commons.collections4.CollectionUtils; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import weaver.hrm.User; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; /** * @Author weaver_cl * @Description: TODO * @Date 2022/4/20 * @Version V1.0 **/ public class SIImportServiceImpl extends Service implements SIImportService { public SIArchivesService getSIArchivesService(User user) { return ServiceUtil.getService(SIArchivesServiceImpl.class,user); } @Override public XSSFWorkbook exportTemplate(InsuranceArchivesListParam param) { //工作簿list List> excelSheetData = new ArrayList<>(); //工作簿名称 String sheetName = SalaryI18nUtil.getI18nLabel(85368, "社保福利档案"); //表头 List headers = buildHeader(); 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()); request.setStartNum(param.getStartNum()); request.setPageSize(param.getPageSize()); } else { request = param; } // request.setPageSize(null); // request.setStartNum(null); // List insuranceArchivesEmployeePOS = getSIArchivesService(user).listPageEmployeePOS(request); // if (insuranceArchivesEmployeePOS == null) { // insuranceArchivesEmployeePOS = new ArrayList<>(); // } // List> datas = buildTableData(insuranceArchivesEmployeePOS); //表头 excelSheetData.add(Arrays.asList(headers.toArray(new String[0]))); //工作簿数据 // List> rows = new LinkedList<>(); // for (int i = 1; i <= datas.size(); i++) { // List row = new ArrayList<>(); // for (int j = 0; j < 4; j++) { // Object cellValue = datas.get(i - 1).get(headers.get(j)); // row.add(cellValue); // } // rows.add(row); // } // //根据是否导出数据开关设置已存在的档案数据 // for (int i = 1; i <= datas.size(); i++) { // List row = rows.get(i - 1); // for (int j = 4; j < headers.size(); j++) { // if (param.getExportData() != null && param.getExportData()) { // Object cellValue = datas.get(i - 1).get(headers.get(j)); // row.add(cellValue); // } else { // row.add(""); // } // } // } // excelSheetData.addAll(rows); return ExcelUtil.genWorkbookV2(excelSheetData, sheetName); } /** * 构建档案excel的表头 * * @return */ public List buildHeader() { List result = new ArrayList<>(); result.add(SalaryI18nUtil.getI18nLabel( 85429, "姓名")); result.add(SalaryI18nUtil.getI18nLabel( 86185, "部门")); result.add(SalaryI18nUtil.getI18nLabel( 86186, "手机号")); result.add(SalaryI18nUtil.getI18nLabel( 86187, "员工状态")); result.add(SalaryI18nUtil.getI18nLabel( 91323, "社保方案名称")); result.add(SalaryI18nUtil.getI18nLabel( 91325, "社保缴纳组织")); //社保福利基数 Map socialMap = welfareNameIdMap( WelfareTypeEnum.SOCIAL_SECURITY); socialMap.forEach((k, v) -> result.add(k + SalaryI18nUtil.getI18nLabel( 100293, "申报基数"))); result.add(SalaryI18nUtil.getI18nLabel( 91324, "社保账号")); result.add(SalaryI18nUtil.getI18nLabel( 91319, "社保起始缴纳月")); result.add(SalaryI18nUtil.getI18nLabel( 91320, "社保最后缴纳月")); result.add(SalaryI18nUtil.getI18nLabel( 91485, "公积金方案名称")); result.add(SalaryI18nUtil.getI18nLabel( 91488, "公积金缴纳组织")); result.add(SalaryI18nUtil.getI18nLabel( 91486, "公积金账号")); //公积金福利基数 Map fundMap = welfareNameIdMap( WelfareTypeEnum.ACCUMULATION_FUND); fundMap.forEach((k, v) -> result.add(k + SalaryI18nUtil.getI18nLabel( 100293, "申报基数"))); result.add(SalaryI18nUtil.getI18nLabel( 91487, "补充公积金账号")); result.add(SalaryI18nUtil.getI18nLabel( 91483, "公积金起始缴纳月")); result.add(SalaryI18nUtil.getI18nLabel( 91484, "公积金最后缴纳月")); result.add(SalaryI18nUtil.getI18nLabel( 91496, "其他福利方案名称")); result.add(SalaryI18nUtil.getI18nLabel( 91497, "其他福利缴纳组织")); //其他福利基数 Map otherMap = welfareNameIdMap( WelfareTypeEnum.OTHER); otherMap.forEach((k, v) -> result.add(k + SalaryI18nUtil.getI18nLabel( 100293, "申报基数"))); result.add(SalaryI18nUtil.getI18nLabel( 91490, "其他福利起始缴纳月")); result.add(SalaryI18nUtil.getI18nLabel( 91494, "其他福利最后缴纳月")); return result; } /** * 获取福利类型名称-id的map * * @param welfareTypeEnum * @return */ public Map welfareNameIdMap(WelfareTypeEnum welfareTypeEnum) { return MapperProxyFactory.getProxy(ICategoryMapper.class).listByWelfareType(welfareTypeEnum.getValue(),null).stream().collect(Collectors.toMap(ICategoryPO::getInsuranceName, ICategoryPO::getId)); } public Map welfareMap() { return MapperProxyFactory.getProxy(ICategoryMapper.class).listAll().stream().collect(Collectors.toMap(ICategoryPO::getId, ICategoryPO::getInsuranceName)); } /** * 获取缴纳组织id-名称集合 * * @return */ public Map paymentOrganizationIdNameMap() { List list = MapperProxyFactory.getProxy(TaxAgentMapper.class).listAll(); if (CollectionUtils.isEmpty(list)) { return new HashMap<>(); } return list.stream().collect(Collectors.toMap(TaxAgent::getId, TaxAgent::getName)); } public List> buildTableData(List insuranceArchivesEmployeePOS) { List> records = new ArrayList<>(); //获取id,福利名称的map,用于下面组装福利数据 Map welfareMap = welfareMap(); //获取缴纳组织id-name集合 Map paymentMap = paymentOrganizationIdNameMap(); //获取id,方案名称的map,用于下面组装福利数据 Map schemeMap = new HashMap<>(); List schemeList = MapperProxyFactory.getProxy(InsuranceSchemeMapper.class).listAll(); if (CollectionUtils.isNotEmpty(schemeList)) { schemeMap = schemeList.stream().collect(Collectors.toMap(InsuranceSchemePO::getId, InsuranceSchemePO::getSchemeName)); } List employeeIds = insuranceArchivesEmployeePOS.stream().map(InsuranceArchivesEmployeePO::getEmployeeId).collect(Collectors.toList()); Map socialSchemePOMap = new HashMap<>(); List socialSchemePOList = MapperProxyFactory.getProxy(SocialSchemeMapper.class).getSocialByEmployeeId(employeeIds); if (CollectionUtils.isNotEmpty(socialSchemePOList)) { socialSchemePOMap = socialSchemePOList.stream().collect(Collectors.toMap(InsuranceArchivesSocialSchemePO::getEmployeeId, Function.identity())); } List fundSchemePOList = MapperProxyFactory.getProxy(FundSchemeMapper.class).getFundByEmployeeId(employeeIds); Map fundSchemePOMap = new HashMap<>(); if (CollectionUtils.isNotEmpty(fundSchemePOList)) { fundSchemePOMap = fundSchemePOList.stream().collect(Collectors.toMap(InsuranceArchivesFundSchemePO::getEmployeeId, Function.identity())); } Map otherSchemePOMap = new HashMap<>(); List otherSchemePOList = MapperProxyFactory.getProxy(OtherSchemeMapper.class).getOtherByEmployeeId(employeeIds); if (CollectionUtils.isNotEmpty(otherSchemePOList)) { otherSchemePOMap = otherSchemePOList.stream().collect(Collectors.toMap(InsuranceArchivesOtherSchemePO::getEmployeeId, Function.identity())); } for (InsuranceArchivesEmployeePO item : insuranceArchivesEmployeePOS) { InsuranceArchivesSocialSchemePO socialItem = socialSchemePOMap.get(item.getEmployeeId()); InsuranceArchivesFundSchemePO fundItem = fundSchemePOMap.get(item.getEmployeeId()); InsuranceArchivesOtherSchemePO otherItem = otherSchemePOMap.get(item.getEmployeeId()); Map map = new HashMap<>(); map.put(SalaryI18nUtil.getI18nLabel( 85429, "姓名"), item.getUserName()); map.put(SalaryI18nUtil.getI18nLabel( 86185, "部门"), item.getDepartmentName()); map.put(SalaryI18nUtil.getI18nLabel( 86186, "手机号"), item.getTelephone()); map.put(SalaryI18nUtil.getI18nLabel( 86187, "员工状态"), item.getUserStatusEnum() == null ? "" : item.getUserStatusEnum().getDescription()); if (socialItem != null) { map.put(SalaryI18nUtil.getI18nLabel( 91323, "社保方案名称"), schemeMap.get(socialItem.getSocialSchemeId())); map.put(SalaryI18nUtil.getI18nLabel( 91325, "社保缴纳组织"), paymentMap.get(socialItem.getPaymentOrganization())); Map socialJson = JSON.parseObject(socialItem.getSocialPaymentBaseString(), new TypeReference>() { }); if (socialJson != null) { socialJson.forEach((k, v) -> map.put(welfareMap.get(Long.valueOf(k)) + SalaryI18nUtil.getI18nLabel( 100293, "申报基数"), v)); } map.put(SalaryI18nUtil.getI18nLabel( 91324, "社保账号"), socialItem.getSocialAccount()); map.put(SalaryI18nUtil.getI18nLabel( 91319, "社保起始缴纳月"), socialItem.getSocialStartTime()); map.put(SalaryI18nUtil.getI18nLabel( 91320, "社保最后缴纳月"), socialItem.getSocialEndTime()); } if (fundItem != null) { map.put(SalaryI18nUtil.getI18nLabel( 91485, "公积金方案名称"), schemeMap.get(fundItem.getFundSchemeId())); map.put(SalaryI18nUtil.getI18nLabel( 91488, "公积金缴纳组织"), paymentMap.get(fundItem.getPaymentOrganization())); map.put(SalaryI18nUtil.getI18nLabel( 91486, "公积金账号"), fundItem.getFundAccount()); Map fundJson = JSON.parseObject(fundItem.getFundPaymentBaseString(), new TypeReference>() { }); if (fundJson != null) { fundJson.forEach((k, v) -> map.put(welfareMap.get(Long.valueOf(k)) + SalaryI18nUtil.getI18nLabel( 100293, "申报基数"), v)); } map.put(SalaryI18nUtil.getI18nLabel( 91487, "补充公积金账号"), fundItem.getSupplementFundAccount()); map.put(SalaryI18nUtil.getI18nLabel( 91483, "公积金起始缴纳月"), fundItem.getFundStartTime()); map.put(SalaryI18nUtil.getI18nLabel( 91484, "公积金最后缴纳月"), fundItem.getFundEndTime()); } if (otherItem != null) { map.put(SalaryI18nUtil.getI18nLabel( 91496, "其他福利方案名称"), schemeMap.get(otherItem.getOtherSchemeId())); map.put(SalaryI18nUtil.getI18nLabel( 91497, "其他福利缴纳组织"), paymentMap.get(otherItem.getPaymentOrganization())); Map otherJson = JSON.parseObject(otherItem.getOtherPaymentBaseString(), new TypeReference>() { }); if (otherJson != null) { otherJson.forEach((k, v) -> map.put(welfareMap.get(Long.valueOf(k)) + SalaryI18nUtil.getI18nLabel( 100293, "申报基数"), v)); } map.put(SalaryI18nUtil.getI18nLabel( 91490, "其他福利起始缴纳月"), otherItem.getOtherStartTime()); map.put(SalaryI18nUtil.getI18nLabel( 91494, "其他福利最后缴纳月"), otherItem.getOtherEndTime()); } records.add(map); } return records; } }