package com.engine.salary.service.impl; import com.alibaba.fastjson.JSON; import com.cloudstore.eccom.pc.table.WeaTableColumn; import com.engine.core.impl.Service; import com.engine.salary.biz.SIAccountBiz; import com.engine.salary.encrypt.siaccount.InsuranceAccountDetailPOEncrypt; import com.engine.salary.encrypt.siexport.AccountExportPOEncrypt; import com.engine.salary.entity.siaccount.dto.InsuranceAccountViewListDTO; import com.engine.salary.entity.siaccount.po.InsuranceAccountDetailPO; import com.engine.salary.entity.sicategory.po.ICategoryPO; import com.engine.salary.entity.siexport.param.InsuranceExportParam; import com.engine.salary.entity.siexport.po.AccountExportPO; import com.engine.salary.entity.taxrate.TaxAgent; import com.engine.salary.enums.siaccount.BillStatusEnum; import com.engine.salary.enums.siaccount.PaymentStatusEnum; import com.engine.salary.enums.siaccount.ResourceFromEnum; import com.engine.salary.enums.sicategory.DataTypeEnum; import com.engine.salary.enums.sicategory.WelfareTypeEnum; import com.engine.salary.mapper.InsuranceExportMapper; import com.engine.salary.mapper.TaxAgentMapper; import com.engine.salary.mapper.siaccount.InsuranceAccountDetailMapper; import com.engine.salary.mapper.sicategory.ICategoryMapper; import com.engine.salary.service.SIExportService; import com.engine.salary.service.SISchemeService; import com.engine.salary.util.SalaryAssert; import com.engine.salary.util.SalaryEnumUtil; 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.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import weaver.hrm.User; import com.engine.common.util.ServiceUtil; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; import static com.engine.salary.enums.UserStatusEnum.getDefaultLabelByValue; /** * @Author weaver_cl * @Description: 该条数据不在个税扣缴义务人人员范围内,不可导入 * @Date 2022/4/18 * @Version V1.0 **/ public class SIExportServiceImpl extends Service implements SIExportService { private SIAccountBiz siAccountBiz = new SIAccountBiz(); private SISchemeService getSISchemeService(User user) { return ServiceUtil.getService(SISchemeServiceImpl.class,user); } @Override public XSSFWorkbook exportOverView(InsuranceExportParam queryParam) { List insuranceAccountDetailPOS = MapperProxyFactory.getProxy(InsuranceAccountDetailMapper.class).selectList(queryParam.getBillMonth(), StringUtils.isBlank(queryParam.getPaymentOrganization()) ? null : Long.valueOf(queryParam.getPaymentOrganization())); InsuranceAccountDetailPOEncrypt.decryptInsuranceAccountDetailPOList(insuranceAccountDetailPOS); //获取扣缴义务人信息 List paymentList = MapperProxyFactory.getProxy(TaxAgentMapper.class).listAll(); SalaryAssert.notEmpty(paymentList, SalaryI18nUtil.getI18nLabel( 100341, "该租户无扣缴义务人")); Map paymentMap = paymentList.stream().collect(Collectors.toMap(TaxAgent::getId, Function.identity())); List insuranceAccountViewListDTOS = siAccountBiz.buildRecords(insuranceAccountDetailPOS, paymentMap); List> excelSheetData = new ArrayList<>(); // 1.工作簿名称 String sheetName = SalaryI18nUtil.getI18nLabel(85368, "社保福利档案"); // 2.表头 String[] header = { SalaryI18nUtil.getI18nLabel( 93270, "缴纳组织"), SalaryI18nUtil.getI18nLabel( 93272, "社保人数"), SalaryI18nUtil.getI18nLabel( 93273, "公积金人数"), SalaryI18nUtil.getI18nLabel( 93274, "其他福利人数"), SalaryI18nUtil.getI18nLabel( 93275, "社保缴费合计"), SalaryI18nUtil.getI18nLabel( 93276, "公积金缴费合计"), SalaryI18nUtil.getI18nLabel( 93277, "其他福利缴费合计"), SalaryI18nUtil.getI18nLabel( 93278, "合计")}; excelSheetData.add(Arrays.asList(header)); //工作簿数据 List> rows = new LinkedList<>(); for (InsuranceAccountViewListDTO dto : insuranceAccountViewListDTOS) { List row = new LinkedList<>(); row.add(dto.getPayOrg()); row.add(dto.getSocialNum()); row.add(dto.getFundNum()); row.add(dto.getOtherNum()); row.add(dto.getSocialPaySum()); row.add(dto.getFundPaySum()); row.add(dto.getOtherPaySum()); row.add(dto.getSum()); rows.add(row); } excelSheetData.addAll(rows); return ExcelUtil.genWorkbookV2(excelSheetData, sheetName); } @Override public XSSFWorkbook exportAccount(Integer paymentStatus, InsuranceExportParam param) { List accountExportPOS = MapperProxyFactory.getProxy(InsuranceExportMapper.class).exportAccount(paymentStatus, param.getBillMonth()); AccountExportPOEncrypt.decryptAccountExportPOList(accountExportPOS); List columns = new ArrayList<>(); List> records = new ArrayList<>(); if (PaymentStatusEnum.COMMON.getValue() == paymentStatus) { columns = buildCommonColumns(accountExportPOS, false); } if (PaymentStatusEnum.REPAIR.getValue() == paymentStatus) { columns = buildCommonColumns(accountExportPOS, true); } records = buildCommonRecords(accountExportPOS); 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); } private List> buildCommonRecords(List list) { List> result = new ArrayList<>(); List paymentList = MapperProxyFactory.getProxy(TaxAgentMapper.class).listAll(); SalaryAssert.notEmpty(paymentList, SalaryI18nUtil.getI18nLabel( 100341, "该租户无扣缴义务人")); Map schemeIdNameMap = getSISchemeService(user).getSchemeIdNameMap(); Map paymentMap = paymentList.stream().collect(Collectors.toMap(TaxAgent::getId, Function.identity())); list.forEach(item -> { Map record = new HashMap<>(); record.put("billMonth", item.getBillMonth()); record.put("billStatus", SalaryEnumUtil.enumMatchByValue(item.getBillStatus(), BillStatusEnum.values(), BillStatusEnum.class)); record.put("userName", item.getUserName()); record.put("department", item.getDepartmentName()); record.put("supplementaryMonth", item.getSupplementaryMonth()); record.put("mobile", item.getTelephone()); record.put("employeeStatus", item.getUserStatus() == null ? "" : getDefaultLabelByValue(item.getUserStatus())); ResourceFromEnum from = SalaryEnumUtil.enumMatchByValue(item.getResourceFrom(), ResourceFromEnum.values(), ResourceFromEnum.class); record.put("sourceFrom", SalaryI18nUtil.getI18nLabel( from.getLabelId(), from.getDefaultLabel())); record.put("socialPayOrg", paymentMap.get(item.getSocialPayOrg()) == null ? "" : paymentMap.get(item.getSocialPayOrg()).getName()); record.put("socialAccount", item.getSocialAccount()); record.put("socialSchemeName", schemeIdNameMap.get(item.getSocialSchemeId())); if (StringUtils.isNotEmpty(item.getSocialPaymentBaseString())) { Map socialJson = JSON.parseObject(item.getSocialPaymentBaseString(), new HashMap().getClass()); socialJson.forEach((k, v) -> { record.put(k + "socialBase", v); }); } record.put("fundPayOrg", paymentMap.get(item.getSocialPayOrg()) == null ? "" : paymentMap.get(item.getSocialPayOrg()).getName()); record.put("fundAccount", item.getFundAccount()); record.put("fundSchemeName", schemeIdNameMap.get(item.getFundSchemeId())); record.put("supplementFundAccount", item.getSupplementFundAccount()); if (StringUtils.isNotEmpty(item.getFundPaymentBaseString())) { Map socialJson = JSON.parseObject(item.getFundPaymentBaseString(), new HashMap().getClass()); socialJson.forEach((k, v) -> { record.put(k + "fundBase", v); }); } record.put("otherPayOrg", paymentMap.get(item.getOtherPayOrg()) == null ? "" : paymentMap.get(item.getOtherPayOrg()).getName()); record.put("otherSchemeName", schemeIdNameMap.get(item.getOtherSchemeId())); if (StringUtils.isNotEmpty(item.getOtherPaymentBaseString())) { Map socialJson = JSON.parseObject(item.getOtherPaymentBaseString(), new HashMap().getClass()); socialJson.forEach((k, v) -> { record.put(k + "otherBase", v); }); } if (StringUtils.isNotEmpty(item.getSocialPerJson())) { Map socialJson = JSON.parseObject(item.getSocialPerJson(), new HashMap().getClass()); socialJson.forEach((k, v) -> { record.put(k + "socialPer", v); }); } record.put("socialPerSum", item.getSocialPerSum()); if (StringUtils.isNotEmpty(item.getFundPerJson())) { Map fundPerJson = JSON.parseObject(item.getFundPerJson(), new HashMap().getClass()); fundPerJson.forEach((k, v) -> { record.put(k + "fundPer", v); }); } record.put("fundPerSum", item.getFundPerSum()); if (StringUtils.isNotEmpty(item.getOtherPerJson())) { Map fundPerJson = JSON.parseObject(item.getOtherPerJson(), new HashMap().getClass()); fundPerJson.forEach((k, v) -> { record.put(k + "otherPer", v); }); } record.put("otherPerSum", item.getOtherPerSum()); record.put("perSum", item.getPerSum()); if (StringUtils.isNotEmpty(item.getSocialComJson())) { Map fundPerJson = JSON.parseObject(item.getSocialComJson(), new HashMap().getClass()); fundPerJson.forEach((k, v) -> { record.put(k + "socialCom", v); }); } record.put("socialComSum", item.getSocialComSum()); if (StringUtils.isNotEmpty(item.getFundComJson())) { Map fundPerJson = JSON.parseObject(item.getFundComJson(), new HashMap().getClass()); fundPerJson.forEach((k, v) -> { record.put(k + "fundCom", v); }); } record.put("fundComSum", item.getFundComSum()); if (StringUtils.isNotEmpty(item.getOtherPerJson())) { Map fundPerJson = JSON.parseObject(item.getOtherPerJson(), new HashMap().getClass()); fundPerJson.forEach((k, v) -> { record.put(k + "otherCom", v); }); } record.put("otherComSum", item.getOtherComSum()); record.put("comSum", item.getComSum()); record.put("socialSum", item.getSocialSum()); record.put("fundSum", item.getFundSum()); record.put("otherSum", item.getOtherSum()); record.put("total", item.getTotal()); result.add(record); }); return result; } private Map> buildComTitle(List pos, Map categoryIdNameMap) { Set socailIds = new HashSet<>(); Set fundIds = new HashSet<>(); Set otherIds = new HashSet<>(); Map> result = new HashMap<>(); pos.stream().forEach(item -> { if (StringUtils.isNotBlank(item.getSocialComJson())) { Map socialJson = JSON.parseObject(item.getSocialComJson(), new HashMap().getClass()); socialJson.forEach((k, v) -> { socailIds.add(k); }); } if (StringUtils.isNotBlank(item.getFundComJson())) { Map fundJson = JSON.parseObject(item.getFundComJson(), new HashMap().getClass()); fundJson.forEach((k, v) -> { fundIds.add(k); }); } if (StringUtils.isNotBlank(item.getOtherComJson())) { Map otherJson = JSON.parseObject(item.getOtherComJson(), new HashMap().getClass()); otherJson.forEach((k, v) -> { otherIds.add(k); }); } }); Map socialColumns = new HashMap<>(); Map fundColumns = new HashMap<>(); Map otherColumns = new HashMap<>(); socailIds.stream().forEach(social -> { if (categoryIdNameMap.containsKey(social)) { socialColumns.put( categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel( 100289, "单位"), social + "socialCom"); } }); fundIds.stream().forEach(social -> { if (categoryIdNameMap.containsKey(social)) { fundColumns.put(categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel( 100289, "单位"), social + "fundCom"); } }); otherIds.stream().forEach(social -> { if (categoryIdNameMap.containsKey(social)) { otherColumns.put(categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel( 100289, "单位"), social + "otherCom"); } }); result.put(WelfareTypeEnum.SOCIAL_SECURITY.getValue(), socialColumns); result.put(WelfareTypeEnum.ACCUMULATION_FUND.getValue(), fundColumns); result.put(WelfareTypeEnum.OTHER.getValue(), otherColumns); return result; } private Map> buildPersonalTitle(List pos, Map categoryIdNameMap) { Set socailIds = new HashSet<>(); Set fundIds = new HashSet<>(); Set otherIds = new HashSet<>(); Map> result = new HashMap<>(); pos.stream().forEach(item -> { if (StringUtils.isNotBlank(item.getSocialPerJson())) { Map socialJson = JSON.parseObject(item.getSocialPerJson(), new HashMap().getClass()); socialJson.forEach((k, v) -> { socailIds.add(k); }); } if (StringUtils.isNotBlank(item.getFundPerJson())) { Map fundJson = JSON.parseObject(item.getFundPerJson(), new HashMap().getClass()); fundJson.forEach((k, v) -> { fundIds.add(k); }); } if (StringUtils.isNotBlank(item.getOtherPerJson())) { Map otherJson = JSON.parseObject(item.getOtherPerJson(), new HashMap().getClass()); otherJson.forEach((k, v) -> { otherIds.add(k); }); } }); Map socialColumns = new HashMap<>(); Map fundColumns = new HashMap<>(); Map otherColumns = new HashMap<>(); socailIds.stream().forEach(social -> { if (categoryIdNameMap.containsKey(social)) { socialColumns.put(categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel( 87159, "个人"), social + "socialPer"); } }); fundIds.stream().forEach(social -> { if (categoryIdNameMap.containsKey(social)) { fundColumns.put(categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel( 87159, "个人"), social + "fundPer"); } }); otherIds.stream().forEach(social -> { if (categoryIdNameMap.containsKey(social)) { otherColumns.put(categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel( 87159, "个人"), social + "otherPer"); } }); result.put(WelfareTypeEnum.SOCIAL_SECURITY.getValue(), socialColumns); result.put(WelfareTypeEnum.ACCUMULATION_FUND.getValue(), fundColumns); result.put(WelfareTypeEnum.OTHER.getValue(), otherColumns); return result; } private List buildCommonColumns(List pos, boolean flag) { List list = new ArrayList<>(); Map categoryIdNameMap = categoryIdNameMap(); Map> columns = buildPaymentTitle(pos, categoryIdNameMap); Map> personColumns = buildPersonalTitle(pos, categoryIdNameMap); Map> comColumns = buildComTitle(pos, categoryIdNameMap); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 85429, "姓名"), "userName")); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 86185, "部门"), "department")); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 86186, "手机号"), "mobile")); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 86187, "员工状态"), "employeeStatus")); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 100377, "数据来源"), "sourceFrom")); if (flag) { list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 100379, "补缴月份"), "supplementaryMonth")); } list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 91325, "社保缴纳组织"), "socialPayOrg")); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 91324, "社保账号"), "socialAccount")); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 91323, "社保方案名称"), "socialSchemeName")); //组装社保基数 columns.get(WelfareTypeEnum.SOCIAL_SECURITY.getValue()).forEach((k, v) -> { list.add(new WeaTableColumn("150px",k, v)); }); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 91488, "公积金缴纳组织"), "fundPayOrg")); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 91486, "公积金账号"), "fundAccount")); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 91485, "公积金方案名称"), "fundSchemeName")); //组装公积金基数 columns.get(WelfareTypeEnum.ACCUMULATION_FUND.getValue()).forEach((k, v) -> { list.add(new WeaTableColumn("150px",k, v)); }); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 91487, "补充公积金账号"), "supplementFundAccount")); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 91497, "其他福利缴纳组织"), "otherPayOrg")); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 91496, "其他福利方案名称"), "otherSchemeName")); columns.get(WelfareTypeEnum.OTHER.getValue()).forEach((k, v) -> { list.add(new WeaTableColumn("150px",k, v)); }); personColumns.get(WelfareTypeEnum.SOCIAL_SECURITY.getValue()).forEach((k, v) -> { list.add(new WeaTableColumn("150px",k, v)); }); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 100388, "社保个人合计"), "socialPerSum")); personColumns.get(WelfareTypeEnum.ACCUMULATION_FUND.getValue()).forEach((k, v) -> { list.add(new WeaTableColumn("150px",k, v)); }); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 100390, "公积金个人合计"), "fundPerSum")); personColumns.get(WelfareTypeEnum.OTHER.getValue()).forEach((k, v) -> { list.add(new WeaTableColumn("150px",k, v)); }); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 100392, "其他福利个人合计"), "otherPerSum")); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 100393, "个人合计"), "perSum")); comColumns.get(WelfareTypeEnum.SOCIAL_SECURITY.getValue()).forEach((k, v) -> { list.add(new WeaTableColumn("150px",k, v)); }); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 100394, "社保单位合计"), "socialComSum")); comColumns.get(WelfareTypeEnum.ACCUMULATION_FUND.getValue()).forEach((k, v) -> { list.add(new WeaTableColumn("150px",k, v)); }); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 100395, "公积金单位合计"), "fundComSum")); comColumns.get(WelfareTypeEnum.OTHER.getValue()).forEach((k, v) -> { list.add(new WeaTableColumn("150px",k, v)); }); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 100396, "其他福利单位合计"), "fundComSum")); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 100397, "单位合计"), "comSum")); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 100398, "社保合计"), "socialSum")); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 100399, "公积金合计"), "fundSum")); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 100400, "其他福利合计"), "otherSum")); list.add(new WeaTableColumn("150px",SalaryI18nUtil.getI18nLabel( 93278, "合计"), "total")); return list; } private Map categoryIdNameMap() { //系统福利类型 Map systemMap = MapperProxyFactory.getProxy(ICategoryMapper.class).listByDataType(DataTypeEnum.SYSTEM.getValue()).stream() .collect(Collectors.toMap(ICategoryPO::getId, ICategoryPO::getInsuranceName)); Map customMap = MapperProxyFactory.getProxy(ICategoryMapper.class).listAll() .stream().collect(Collectors.toMap(ICategoryPO::getId, ICategoryPO::getInsuranceName)); HashMap total = new HashMap<>(); if (MapUtils.isNotEmpty(systemMap)) { total.putAll(systemMap); } if (MapUtils.isNotEmpty(customMap)) { total.putAll(customMap); } HashMap result = new HashMap<>(); total.forEach((k, v) -> { result.put(String.valueOf(k), v); }); return result; } private Map> buildPaymentTitle(List pos, Map categoryIdNameMap) { Set socailIds = new HashSet<>(); Set fundIds = new HashSet<>(); Set otherIds = new HashSet<>(); Map> result = new HashMap<>(); pos.stream().forEach(item -> { if (StringUtils.isNotBlank(item.getSocialPaymentBaseString())) { Map socialJson = JSON.parseObject(item.getSocialPaymentBaseString(), new HashMap().getClass()); socialJson.forEach((k, v) -> { socailIds.add(k); }); } if (StringUtils.isNotBlank(item.getFundPaymentBaseString())) { Map fundJson = JSON.parseObject(item.getFundPaymentBaseString(), new HashMap().getClass()); fundJson.forEach((k, v) -> { fundIds.add(k); }); } if (StringUtils.isNotBlank(item.getOtherPaymentBaseString())) { Map otherJson = JSON.parseObject(item.getOtherPaymentBaseString(), new HashMap().getClass()); otherJson.forEach((k, v) -> { otherIds.add(k); }); } }); Map socialColumns = new HashMap<>(); Map fundColumns = new HashMap<>(); Map otherColumns = new HashMap<>(); socailIds.stream().forEach(social -> { if (categoryIdNameMap.containsKey(social)) { socialColumns.put(categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel( 100293, "申报基数"), social + "socialBase"); } }); fundIds.stream().forEach(social -> { if (categoryIdNameMap.containsKey(social)) { fundColumns.put(categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel( 100293, "申报基数"), social + "fundBase"); } }); otherIds.stream().forEach(social -> { if (categoryIdNameMap.containsKey(social)) { otherColumns.put(categoryIdNameMap.get(social) + SalaryI18nUtil.getI18nLabel( 100293, "申报基数"), social + "otherBase"); } }); result.put(WelfareTypeEnum.SOCIAL_SECURITY.getValue(), socialColumns); result.put(WelfareTypeEnum.ACCUMULATION_FUND.getValue(), fundColumns); result.put(WelfareTypeEnum.OTHER.getValue(), otherColumns); return result; } }