package com.engine.salary.entity.siaccount.bo; import com.alibaba.fastjson.JSON; import com.engine.salary.entity.salaryacct.po.ExcelAcctResultPO; import com.engine.salary.entity.salaryacct.po.SalaryAcctResultPO; import com.engine.salary.entity.salarysob.dto.SalarySobEmpFieldDTO; import com.engine.salary.entity.sicategory.po.ICategoryPO; import com.engine.salary.entity.siexport.po.AccountExportPO; import com.engine.salary.entity.siexport.po.ExcelAccountExportPO; import com.engine.salary.entity.taxagent.po.TaxAgentPO; import com.engine.salary.enums.salaryitem.SalaryDataTypeEnum; import com.engine.salary.mapper.sicategory.ICategoryMapper; import com.engine.salary.mapper.taxagent.TaxAgentMapper; import com.engine.salary.util.SalaryEntityUtil; import com.engine.salary.util.SalaryI18nUtil; import com.engine.salary.util.db.MapperProxyFactory; import com.engine.salary.util.page.Column; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; import static com.engine.salary.enums.UserStatusEnum.getDefaultLabelByValue; /** * @Author: sy * @Description: 福利核算线上线下对比结果 * @Date: 2022/9/28 **/ public class InsuranceComparisonResultBO { /** * 数据类型的后缀标识 * 为了展示千分位,福利核算结果列表、线上线下对比结果列表需要返回给前端列表字段的数据类型,字段索引+后缀标识 */ private static final String DATA_TYPE_SUFFIX = "_type"; /** * 构建福利核算结果列表的表头(线下对比) * */ public static List buildTableColumns4ComparisonResult(Set insuranceBaseSet, Set insurancePerPaySet, Set insuranceComPaySet) { List listAll = MapperProxyFactory.getProxy(ICategoryMapper.class).listAll(); List socialWelfareList = listAll.stream().filter(e -> e.getWelfareType() == 1 && e.getIsUse() == 1 && insuranceBaseSet.contains(e.getId())).collect(Collectors.toList()); List fundWelfareList = listAll.stream().filter(e -> e.getWelfareType() == 2 && e.getIsUse() == 1 && insuranceBaseSet.contains(e.getId())).collect(Collectors.toList()); List otherWelfareList = listAll.stream().filter(e -> e.getWelfareType() == 3 && e.getIsUse() == 1 && insuranceBaseSet.contains(e.getId())).collect(Collectors.toList()); List socialWelPerList = listAll.stream().filter(e -> e.getWelfareType() == 1 && e.getIsUse() == 1 && insurancePerPaySet.contains(e.getId())).collect(Collectors.toList()); List fundWelPerList = listAll.stream().filter(e -> e.getWelfareType() == 2 && e.getIsUse() == 1 && insurancePerPaySet.contains(e.getId())).collect(Collectors.toList()); List otherWelPerList = listAll.stream().filter(e -> e.getWelfareType() == 3 && e.getIsUse() == 1 && insurancePerPaySet.contains(e.getId())).collect(Collectors.toList()); List socialWelComList = listAll.stream().filter(e -> e.getWelfareType() == 1 && e.getIsUse() == 1 && insuranceComPaySet.contains(e.getId())).collect(Collectors.toList()); List fundWelComList = listAll.stream().filter(e -> e.getWelfareType() == 2 && e.getIsUse() == 1 && insuranceComPaySet.contains(e.getId())).collect(Collectors.toList()); List otherWelComList = listAll.stream().filter(e -> e.getWelfareType() == 3 && e.getIsUse() == 1 && insuranceComPaySet.contains(e.getId())).collect(Collectors.toList()); List columns = Lists.newArrayList(); // 员工信息字段 columns.add(new Column("姓名", "userName", "userName")); columns.add(new Column("部门", "department", "department")); columns.add(new Column("手机号", "mobile", "mobile")); columns.add(new Column("工号", "workcode", "workcode")); columns.add(new Column("员工状态", "employeeStatus", "employeeStatus")); columns.add(new Column("数据来源", "sourceFrom", "sourceFrom")); columns.add(new Column("个税扣缴义务人", "socialPayOrg", "socialPayOrg")); columns.add(new Column("社保账号", "socialAccount", "socialAccount")); columns.add(new Column("社保方案名称", "socialSchemeName", "socialSchemeName")); //组装社保基数 for (ICategoryPO po : socialWelfareList) { columns.add(new Column(po.getInsuranceName() + "申报基数", po.getId() + "socialBase", po.getId() + "socialBase")); } columns.add(new Column("公积金账号", "fundAccount", "fundAccount")); columns.add(new Column("公积金方案名称", "fundSchemeName", "fundSchemeName")); //组装公积金基数 for (ICategoryPO po : fundWelfareList) { columns.add(new Column(po.getInsuranceName() + "申报基数", po.getId() + "fundBase", po.getId() + "fundBase")); } columns.add(new Column("补充公积金账号", "supplementFundAccount", "supplementFundAccount")); columns.add(new Column("其他福利方案名称", "otherSchemeName", "otherSchemeName")); //组装其他福利基数 for (ICategoryPO po : otherWelfareList) { columns.add(new Column(po.getInsuranceName() + "申报基数", po.getId() + "otherBase", po.getId() + "otherBase")); } //社保个人(生育保险个人、工伤保险个人、失业保险个人、养老保险个人、医疗保险个人) for (ICategoryPO po : socialWelPerList) { columns.add(new Column(po.getInsuranceName() + "个人", po.getId() + "socialPer", po.getId() + "socialPer")); } columns.add(new Column("社保个人合计", "socialPerSum", "socialPerSum")); //住房公积金个人、补充住房公积金个人 for (ICategoryPO po : fundWelPerList) { columns.add(new Column(po.getInsuranceName() + "个人", po.getId() + "fundPer", po.getId() + "fundPer")); } columns.add(new Column("公积金个人合计", "fundPerSum", "fundPerSum")); //其他个人(比如企业年金个人) for (ICategoryPO po : otherWelPerList) { columns.add(new Column(po.getInsuranceName() + "个人", po.getId() + "otherPer", po.getId() + "otherPer")); } columns.add(new Column("其他福利个人合计", "otherPerSum", "otherPerSum")); columns.add(new Column("个人合计", "perSum", "perSum")); //社保单位(生育保险单位、工伤保险单位、失业保险单位、养老保险单位、医疗保险单位) for (ICategoryPO po : socialWelComList) { columns.add(new Column(po.getInsuranceName() + "单位", po.getId() + "socialCom", po.getId() + "socialCom")); } columns.add(new Column("社保单位合计", "socialComSum", "socialComSum")); //住房公积金单位、补充住房公积金单位 for (ICategoryPO po : fundWelComList) { columns.add(new Column(po.getInsuranceName() + "单位", po.getId() + "fundCom", po.getId() + "fundCom")); } columns.add(new Column("公积金单位合计", "fundComSum", "fundComSum")); //其他单位(比如企业年金单位) for (ICategoryPO po : otherWelComList) { columns.add(new Column(po.getInsuranceName() + "单位", po.getId() + "otherCom", po.getId() + "otherCom")); } columns.add(new Column("其他福利单位合计", "otherComSum", "otherComSum")); columns.add(new Column("单位合计", "comSum", "comSum")); columns.add(new Column("社保合计", "socialSum", "socialSum")); columns.add(new Column("公积金合计", "fundSum", "fundSum")); columns.add(new Column("其他福利合计", "otherSum", "otherSum")); columns.add(new Column("合计", "total", "total")); return columns; } /** * 构建福利核算线下对比结果 * */ public static List> buildComparisonTableData(List accountExportPOS, List excelAccountExportPOS, Map schemeIdNameMap) { Map> excelResultMap = SalaryEntityUtil.group2Map(excelAccountExportPOS, ExcelAccountExportPO::getWorkcode); // Map> acctResultMap = SalaryEntityUtil.group2Map(accountExportPOS, AccountExportPO::getWorkcode); List paymentList = MapperProxyFactory.getProxy(TaxAgentMapper.class).listAll(); Map paymentMap = paymentList.stream().collect(Collectors.toMap(TaxAgentPO::getId, Function.identity())); List> resultList = Lists.newArrayListWithExpectedSize(accountExportPOS.size()); //遍历线上数据 for (AccountExportPO accountExportPO : accountExportPOS) { Map map = Maps.newHashMap(); // 记录线下值和系统值之间是否存在差异 map.put("different", "false"); //设置基本字段信息和类型 map.put("userName", accountExportPO.getUserName()); map.put("userName" + DATA_TYPE_SUFFIX, SalaryDataTypeEnum.STRING.getValue()); map.put("department", accountExportPO.getDepartmentName()); map.put("department" + DATA_TYPE_SUFFIX, SalaryDataTypeEnum.STRING.getValue()); map.put("mobile", accountExportPO.getTelephone()); map.put("mobile" + DATA_TYPE_SUFFIX, SalaryDataTypeEnum.STRING.getValue()); map.put("workcode", accountExportPO.getWorkcode()); map.put("workcode" + DATA_TYPE_SUFFIX, SalaryDataTypeEnum.STRING.getValue()); map.put("employeeStatus", accountExportPO.getUserStatus() == null ? "" : getDefaultLabelByValue(accountExportPO.getUserStatus())); map.put("employeeStatus" + DATA_TYPE_SUFFIX, SalaryDataTypeEnum.STRING.getValue()); map.put("socialPayOrg", paymentMap.get(accountExportPO.getSocialPayOrg()) == null ? "" : paymentMap.get(accountExportPO.getSocialPayOrg()).getName()); map.put("socialPayOrg" + DATA_TYPE_SUFFIX, SalaryDataTypeEnum.STRING.getValue()); //社保账号、公积金账号、补充公积金账号 map.put("fundAccount", accountExportPO.getFundAccount()); map.put("fundAccount" + DATA_TYPE_SUFFIX, SalaryDataTypeEnum.STRING.getValue()); map.put("socialAccount", accountExportPO.getSocialAccount()); map.put("socialAccount" + DATA_TYPE_SUFFIX, SalaryDataTypeEnum.STRING.getValue()); map.put("supplementFundAccount", accountExportPO.getSupplementFundAccount()); map.put("supplementFundAccount" + DATA_TYPE_SUFFIX, SalaryDataTypeEnum.STRING.getValue()); //福利方案名称 map.put("socialSchemeName", schemeIdNameMap.get(accountExportPO.getSocialSchemeId())); map.put("fundSchemeName", schemeIdNameMap.get(accountExportPO.getFundSchemeId())); map.put("otherSchemeName", schemeIdNameMap.get(accountExportPO.getOtherSchemeId())); //线下值 List excelResultValueList = excelResultMap.get(accountExportPO.getWorkcode()); ExcelAccountExportPO excelAccountExportPO = new ExcelAccountExportPO(); if (excelResultValueList != null && excelResultValueList.size() == 1) { excelAccountExportPO = excelResultValueList.get(0); } //社保基数,socialPaymentBaseString welfareElementCompare(map, accountExportPO.getSocialPaymentBaseString(), excelAccountExportPO.getSocialPaymentBaseString(), "Base", 1); //公积金基数,fundPaymentBaseString welfareElementCompare(map, accountExportPO.getFundPaymentBaseString(), excelAccountExportPO.getFundPaymentBaseString(), "Base", 2); //其他福利基数,otherPaymentBaseString welfareElementCompare(map, accountExportPO.getOtherPaymentBaseString(), excelAccountExportPO.getOtherPaymentBaseString(), "Base", 3); //社保个人socialPerJson welfareElementCompare(map, accountExportPO.getSocialPerJson(), excelAccountExportPO.getSocialPerJson(), "Per", 1); //公积金个人fundPerJson welfareElementCompare(map, accountExportPO.getFundPerJson(), excelAccountExportPO.getFundPerJson(), "Per", 2); //其他个人otherPerJson welfareElementCompare(map, accountExportPO.getOtherPerJson(), excelAccountExportPO.getOtherPerJson(), "Per", 3); //社保单位socialComJson welfareElementCompare(map, accountExportPO.getSocialComJson(), excelAccountExportPO.getSocialComJson(), "Com", 1); //公积金单位fundComJson welfareElementCompare(map, accountExportPO.getFundComJson(), excelAccountExportPO.getFundComJson(), "Com", 2); //其他单位otherComJson welfareElementCompare(map, accountExportPO.getOtherComJson(), excelAccountExportPO.getOtherComJson(), "Com", 3); //各种合计 welfareSumCompare(map, accountExportPO, excelAccountExportPO); resultList.add(map); } return resultList; } private static Map welfareElementCompare(Map map, String accountJson, String excelAccountJson, String welfareStand, Integer welfareType) { List listAll = MapperProxyFactory.getProxy(ICategoryMapper.class).listAll(); List accountWelfareList = listAll.stream().filter(e -> e.getWelfareType().equals(welfareType)).collect(Collectors.toList()); String baseTypeInfo = welfareType.equals(1) ? "social" : (welfareType.equals(2) ? "fund" : "other"); Map accountMap = JSON.parseObject(accountJson, HashMap.class); Map excelAccountMap = JSON.parseObject(excelAccountJson, HashMap.class); for (ICategoryPO welfare : accountWelfareList) { Map temp = Maps.newHashMap(); if (accountMap != null && accountMap.get(welfare.getId().toString()) != null) { temp.put("acctResultValue", dealNull(accountMap.get(welfare.getId().toString()))); } else { temp.put("acctResultValue", ""); } if (excelAccountMap != null && excelAccountMap.get(welfare.getId().toString()) != null) { temp.put("excelResultValue", dealNull(excelAccountMap.get(welfare.getId().toString()))); }else { temp.put("excelResultValue", ""); } map.put(welfare.getId() + baseTypeInfo + welfareStand, temp); // 薪资项目字段的字段类型 map.put(welfare.getId() + baseTypeInfo + welfareStand + DATA_TYPE_SUFFIX, SalaryDataTypeEnum.STRING.getValue()); if (map.get("different").equals("false") && !temp.get("acctResultValue").equals(temp.get("excelResultValue"))) { map.put("different", "true"); } } return map; } private static Map welfareSumCompare(Map map, AccountExportPO accountExportPO, ExcelAccountExportPO excelAccountExportPO) { //社保个人合计、公积金个人合计、其他福利个人合计、个人合计 Map socialPerSumTemp = Maps.newHashMap(); socialPerSumTemp.put("acctResultValue", dealNull(accountExportPO.getSocialPerSum())); socialPerSumTemp.put("excelResultValue", dealNull(excelAccountExportPO.getSocialPerSum())); map.put("socialPerSum", socialPerSumTemp); map.put("socialPerSum" + DATA_TYPE_SUFFIX, SalaryDataTypeEnum.STRING.getValue()); if (map.get("different").equals("false") && !socialPerSumTemp.get("acctResultValue").equals(socialPerSumTemp.get("excelResultValue"))) { map.put("different", "true"); } Map fundPerSumTemp = Maps.newHashMap(); fundPerSumTemp.put("acctResultValue", dealNull(accountExportPO.getFundPerSum())); fundPerSumTemp.put("excelResultValue", dealNull(excelAccountExportPO.getFundPerSum())); map.put("fundPerSum", fundPerSumTemp); map.put("fundPerSum" + DATA_TYPE_SUFFIX, SalaryDataTypeEnum.STRING.getValue()); if (map.get("different").equals("false") && !fundPerSumTemp.get("acctResultValue").equals(fundPerSumTemp.get("excelResultValue"))) { map.put("different", "true"); } Map otherPerSumTemp = Maps.newHashMap(); otherPerSumTemp.put("acctResultValue", dealNull(accountExportPO.getOtherPerSum())); otherPerSumTemp.put("excelResultValue", dealNull(excelAccountExportPO.getOtherPerSum())); map.put("otherPerSum", otherPerSumTemp); map.put("otherPerSum" + DATA_TYPE_SUFFIX, SalaryDataTypeEnum.STRING.getValue()); if (map.get("different").equals("false") && !otherPerSumTemp.get("acctResultValue").equals(otherPerSumTemp.get("excelResultValue"))) { map.put("different", "true"); } Map perSumTemp = Maps.newHashMap(); perSumTemp.put("acctResultValue", dealNull(accountExportPO.getPerSum())); perSumTemp.put("excelResultValue", dealNull(excelAccountExportPO.getPerSum())); map.put("perSum", perSumTemp); map.put("perSum" + DATA_TYPE_SUFFIX, SalaryDataTypeEnum.STRING.getValue()); if (map.get("different").equals("false") && !perSumTemp.get("acctResultValue").equals(perSumTemp.get("excelResultValue"))) { map.put("different", "true"); } //社保单位合计、公积金单位合计、其他福利单位合计、单位合计 Map socialComSumTemp = Maps.newHashMap(); socialComSumTemp.put("acctResultValue", dealNull(accountExportPO.getSocialComSum())); socialComSumTemp.put("excelResultValue", dealNull(excelAccountExportPO.getSocialComSum())); map.put("socialComSum", socialComSumTemp); map.put("socialComSum" + DATA_TYPE_SUFFIX, SalaryDataTypeEnum.STRING.getValue()); if (map.get("different").equals("false") && !socialComSumTemp.get("acctResultValue").equals(socialComSumTemp.get("excelResultValue"))) { map.put("different", "true"); } Map fundComSumTemp = Maps.newHashMap(); fundComSumTemp.put("acctResultValue", dealNull(accountExportPO.getFundComSum())); fundComSumTemp.put("excelResultValue", dealNull(excelAccountExportPO.getFundComSum())); map.put("fundComSum", fundComSumTemp); map.put("fundComSum" + DATA_TYPE_SUFFIX, SalaryDataTypeEnum.STRING.getValue()); if (map.get("different").equals("false") && !fundComSumTemp.get("acctResultValue").equals(fundComSumTemp.get("excelResultValue"))) { map.put("different", "true"); } Map otherComSumTemp = Maps.newHashMap(); otherComSumTemp.put("acctResultValue", dealNull(accountExportPO.getOtherComSum())); otherComSumTemp.put("excelResultValue", dealNull(excelAccountExportPO.getOtherComSum())); map.put("otherComSum", otherComSumTemp); map.put("otherComSum" + DATA_TYPE_SUFFIX, SalaryDataTypeEnum.STRING.getValue()); if (map.get("different").equals("false") && !otherComSumTemp.get("acctResultValue").equals(otherComSumTemp.get("excelResultValue"))) { map.put("different", "true"); } Map perComTemp = Maps.newHashMap(); perComTemp.put("acctResultValue", dealNull(accountExportPO.getComSum())); perComTemp.put("excelResultValue", dealNull(excelAccountExportPO.getComSum())); map.put("comSum", perComTemp); map.put("comSum" + DATA_TYPE_SUFFIX, SalaryDataTypeEnum.STRING.getValue()); if (map.get("different").equals("false") && !perComTemp.get("acctResultValue").equals(perComTemp.get("excelResultValue"))) { map.put("different", "true"); } //社保合计、公积金合计、其他福利合计、合计 Map socialSumTemp = Maps.newHashMap(); socialSumTemp.put("acctResultValue", dealNull(accountExportPO.getSocialSum())); socialSumTemp.put("excelResultValue", dealNull(excelAccountExportPO.getSocialSum())); map.put("socialSum", socialSumTemp); map.put("socialSum" + DATA_TYPE_SUFFIX, SalaryDataTypeEnum.STRING.getValue()); if (map.get("different").equals("false") && !socialSumTemp.get("acctResultValue").equals(socialSumTemp.get("excelResultValue"))) { map.put("different", "true"); } Map fundSumTemp = Maps.newHashMap(); fundSumTemp.put("acctResultValue", dealNull(accountExportPO.getFundSum())); fundSumTemp.put("excelResultValue", dealNull(excelAccountExportPO.getFundSum())); map.put("fundSum", fundSumTemp); map.put("fundSum" + DATA_TYPE_SUFFIX, SalaryDataTypeEnum.STRING.getValue()); if (map.get("different").equals("false") && !fundSumTemp.get("acctResultValue").equals(fundSumTemp.get("excelResultValue"))) { map.put("different", "true"); } Map otherSumTemp = Maps.newHashMap(); otherSumTemp.put("acctResultValue", dealNull(accountExportPO.getOtherSum())); otherSumTemp.put("excelResultValue", dealNull(excelAccountExportPO.getOtherSum())); map.put("otherSum", otherSumTemp); map.put("otherSum" + DATA_TYPE_SUFFIX, SalaryDataTypeEnum.STRING.getValue()); if (map.get("different").equals("false") && !otherSumTemp.get("acctResultValue").equals(otherSumTemp.get("excelResultValue"))) { map.put("different", "true"); } Map totalTemp = Maps.newHashMap(); totalTemp.put("acctResultValue", dealNull(accountExportPO.getTotal())); totalTemp.put("excelResultValue", dealNull(excelAccountExportPO.getTotal())); map.put("total", totalTemp); map.put("total" + DATA_TYPE_SUFFIX, SalaryDataTypeEnum.STRING.getValue()); if (map.get("different").equals("false") && !totalTemp.get("acctResultValue").equals(totalTemp.get("excelResultValue"))) { map.put("different", "true"); } return map; } private static String dealNull(String data) { if (data == null || "0".equals(data) || "0.00".equals(data)) { return ""; } return data; } }