diff --git a/src/com/engine/salary/entity/ly/po/UfGjjInfo.java b/src/com/engine/salary/entity/ly/po/UfGjjInfo.java index 4ad35c11d..cda71065a 100644 --- a/src/com/engine/salary/entity/ly/po/UfGjjInfo.java +++ b/src/com/engine/salary/entity/ly/po/UfGjjInfo.java @@ -18,6 +18,8 @@ import lombok.NoArgsConstructor; public class UfGjjInfo { private Long id; + private String dyxzzq; + // 分部 private Long fb; diff --git a/src/com/engine/salary/entity/ly/po/UfSbInfo.java b/src/com/engine/salary/entity/ly/po/UfSbInfo.java index 6f4f98d82..5057d0c70 100644 --- a/src/com/engine/salary/entity/ly/po/UfSbInfo.java +++ b/src/com/engine/salary/entity/ly/po/UfSbInfo.java @@ -18,6 +18,9 @@ import lombok.NoArgsConstructor; public class UfSbInfo { private Long id; + // 对应薪资周期 + private String dyxzzq; + // 分部 private Integer fb; diff --git a/src/com/engine/salary/mapper/ly/UfSbgjjMapper.xml b/src/com/engine/salary/mapper/ly/UfSbgjjMapper.xml index 8deae532d..6b793a04a 100644 --- a/src/com/engine/salary/mapper/ly/UfSbgjjMapper.xml +++ b/src/com/engine/salary/mapper/ly/UfSbgjjMapper.xml @@ -35,6 +35,7 @@ + @@ -71,6 +72,7 @@ , t.ylbxgrjn1 , t.znxmlb , t.znxmmc + , t.dyxzzq @@ -108,6 +110,7 @@ + @@ -127,6 +130,7 @@ , t.yg , t.znxmlb , t.znxmmc + , t.dyxzzq diff --git a/src/com/engine/salary/service/impl/LySalaryReportServiceImpl.java b/src/com/engine/salary/service/impl/LySalaryReportServiceImpl.java index 882f3e9ac..4ef4a708e 100644 --- a/src/com/engine/salary/service/impl/LySalaryReportServiceImpl.java +++ b/src/com/engine/salary/service/impl/LySalaryReportServiceImpl.java @@ -492,6 +492,8 @@ public class LySalaryReportServiceImpl extends Service implements LySalaryReport } // 主键id map.put("id", e.getId()); + // 薪资所属月 + map.put("salaryMonth", SalaryDateUtil.getFormatYearMonth(e.getSalaryMonth())); //人员id map.put("employeeId", e.getEmployeeId()); map.put("userName", fieldValueMap.get("username")); @@ -532,6 +534,7 @@ public class LySalaryReportServiceImpl extends Service implements LySalaryReport itemSum.put("employeeId", CollectionUtils.isEmpty(value) ? "" : value.get(0).get("employeeId")); itemSum.put("subcompanyId", CollectionUtils.isEmpty(value) ? "" : value.get(0).get("subcompanyId") == null ? "0" : value.get(0).get("subcompanyId")); itemSum.put("departmentId", CollectionUtils.isEmpty(value) ? "" : value.get(0).get("departmentId") == null ? "0" : value.get(0).get("departmentId")); + itemSum.put("salaryMonth", CollectionUtils.isEmpty(value) ? "" : value.get(0).get("salaryMonth") == null ? " " : value.get(0).get("salaryMonth")); if (ffgsztItemId != null) { Map map = value.get(0); String rylb = map.get(ffgsztItemId.toString()) == null ? "" : map.get(ffgsztItemId.toString()).toString(); @@ -2124,8 +2127,23 @@ public class LySalaryReportServiceImpl extends Service implements LySalaryReport } // 获取当月导入社保数据 -// List ufSbInfos = getLyUfSbgjjMapper().listSbInfoByFyssq(salaryMonth); - List ufSbInfos = getLyUfSbgjjMapper().listSbInfoByDyxzzq(salaryMonth); + List ufSbInfos = getLyUfSbgjjMapper().listSbInfoByFyssq(salaryMonth); + // 根据人员id汇总 + Map> ufGroupByYg = SalaryEntityUtil.group2Map(ufSbInfos, UfSbInfo::getYg); + ufSbInfos = ufSbInfos.stream().filter(uf -> { + List list = ufGroupByYg.get(uf.getYg()); + if (CollectionUtils.isNotEmpty(list) && list.size() > 1) { + return !(uf.getSbgrjnhj() == null || uf.getSbgrjnhj().compareTo(Double.valueOf("0")) == 0); + } + return true; + }).collect(Collectors.toList()); + List dateList = ufSbInfos.stream().map(UfSbInfo::getDyxzzq) + .distinct() + .map(date -> SalaryDateUtil.dateStrToLocalYearMonth(date)) + .filter(date -> date != null).distinct() + .sorted(Comparator.comparing(Date::getTime)) + .collect(Collectors.toList()); +// List ufSbInfos = getLyUfSbgjjMapper().listSbInfoByDyxzzq(salaryMonth); ufSbInfos = ufSbInfos.stream().map(info -> { if (info.getGmgsqc() == null) { info.setGmgsqc(""); @@ -2186,28 +2204,35 @@ public class LySalaryReportServiceImpl extends Service implements LySalaryReport // 查询核算账套 List salarySobList = getSalarySobService(user).listAll(); List salarySobIds = salarySobList.stream().map(SalarySobPO::getId).collect(Collectors.toList()); - LocalDateRange dateRange = LocalDateRange.builder().fromDate(salaryMonthDate).endDate(salaryMonthDate).build(); - // 获取核算记录 - List salaryAcctRecordList = getSalaryAcctRecordService(user).listBySalarySobIdsAndSalaryMonth(salarySobIds, dateRange); - salaryAcctRecordList = salaryAcctRecordList.stream().filter(salaryAcctRecordPO -> salaryAcctRecordPO.getStatus() > SalaryAcctRecordStatusEnum.NOT_ARCHIVED.getValue()).collect(Collectors.toList()); - List salaryAcctRecordIds = salaryAcctRecordList.stream().map(SalaryAcctRecordPO::getId).collect(Collectors.toList()); - LinkedHashMap> acctSbSumByGsMap = new LinkedHashMap<>(); + // 查询所有薪资所属月下核算数据 + List salaryAcctRecordIds = new ArrayList<>(); + Map>> resultGroupByKey = new HashMap<>(); + if (CollectionUtils.isNotEmpty(dateList)) { + LocalDateRange dateRange = LocalDateRange.builder().fromDate(dateList.get(0)).endDate(dateList.get(dateList.size()-1)).build(); + // 获取核算记录 + List salaryAcctRecordList = getSalaryAcctRecordService(user).listBySalarySobIdsAndSalaryMonth(salarySobIds, dateRange); + salaryAcctRecordList = salaryAcctRecordList.stream().filter(salaryAcctRecordPO -> salaryAcctRecordPO.getStatus() > SalaryAcctRecordStatusEnum.NOT_ARCHIVED.getValue()).collect(Collectors.toList()); + salaryAcctRecordIds = salaryAcctRecordList.stream().map(SalaryAcctRecordPO::getId).collect(Collectors.toList()); + } + if (CollectionUtils.isNotEmpty(salaryAcctRecordIds)) { List salaryAcctEmpList = getSalaryAcctEmployeeService(user).listBySalaryAcctRecordIds(salaryAcctRecordIds); // 查新薪资核算结果 List acctResultPOList = getSalaryAcctResultService(user).listBySalaryAcctRecordIdsAndSalaryItemIds(salaryAcctRecordIds, salaryItemIdList); List> resultMapList = buildData4LyReport(salaryItemList, salaryAcctEmpList, new ArrayList<>(), acctResultPOList, false); - // 根据社保购买公司进行分组 - Map>> resultGroupByGmgs = SalaryEntityUtil.group2Map(resultMapList, map -> (map.get(gmgsItemId.toString()) == null ? " " : map.get(gmgsItemId.toString()).toString())); - List numberItems = salaryItemList.stream().filter(item -> item.getDataType().equals(SalaryDataTypeEnum.NUMBER.getValue())).collect(Collectors.toList()); - acctSbSumByGsMap = getSumResultByGroup(resultGroupByGmgs, Collections.emptyList(), numberItems, null ,Collections.emptyList()); + // 根据年月 社保购买公司 人员id进行分组 + resultGroupByKey = SalaryEntityUtil.group2Map(resultMapList, + map -> (map.get("salaryMonth") == null ? " " : map.get("salaryMonth") + "_split" +(map.get(gmgsItemId.toString()) == null ? " " : map.get(gmgsItemId.toString()).toString())) + "_split" +(map.get("employeeId") == null ? " " : map.get("employeeId").toString())); +// List numberItems = salaryItemList.stream().filter(item -> item.getDataType().equals(SalaryDataTypeEnum.NUMBER.getValue())).collect(Collectors.toList()); +// LinkedHashMap> acctSbSumByGsAndDateMap = getSumResultByGroup(resultGroupByGmgsAndDate, Collections.emptyList(), numberItems, null ,Collections.emptyList()); } - // 取建模、核算中购买公司合集 + + // 取建模、核算中购买公司合集(中文) Set totalGs = new HashSet<>(); - Set acctGs = acctSbSumByGsMap.keySet(); +// Set acctGs = acctSbSumByGsAndDateMap.keySet().stream().map(key -> key.split("_split")[1]).collect(Collectors.toSet()); totalGs.addAll(ufSbSumByGsMap.keySet()); - totalGs.addAll(acctGs); +// totalGs.addAll(acctGs); String currDate = String.format("'%s'", TimeUtil.getCurrentDateString()); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); @@ -2221,6 +2246,7 @@ public class LySalaryReportServiceImpl extends Service implements LySalaryReport // 插入前先删除 String deleteSql ="delete from uf_dbhzb where yf = '"+ salaryMonth + "'"; rs.execute(deleteSql); + Map>> finalResultGroupByKey = resultGroupByKey; for (List part : partition) { // 插入对比数据 // StringBuilder sbSql = new StringBuilder("insert into uf_dbhzb(formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime," + @@ -2262,14 +2288,36 @@ public class LySalaryReportServiceImpl extends Service implements LySalaryReport "yf,gmgs,sbdrrs,xcffrs,drje,gzkkje,ce) values "); for (String gmgs : part) { String gmgsId = frztNameMap.get(gmgs); - Map acctSumMap = acctSbSumByGsMap.getOrDefault(gmgs, new HashMap<>()); +// Map acctSumMap = acctSbSumByGsMap.getOrDefault(gmgs, new HashMap<>()); Map ufSumMap = ufSbSumByGsMap.getOrDefault(gmgs, new HashMap<>()); // 社保合计 - String sbAcct = SalaryEntityUtil.empty2Zero(Utils.null2String(acctSumMap.get(grjnheItemId.toString()))).toPlainString(); + BigDecimal sbAcct = new BigDecimal("0"); + // 获取该社保购买公司下建模数据 + List ufSbInfosList = ufSbInfoGroupMap.get(gmgsId); + // 核算人数 + int[] countEmp = {0}; + if (CollectionUtils.isNotEmpty(ufSbInfosList)) { + sbAcct = ufSbInfosList.stream().map(uf -> { + String key = uf.getDyxzzq() + "_split" + gmgs + "_split" + uf.getYg(); + List> maps = finalResultGroupByKey.get(key); + BigDecimal sum = new BigDecimal("0"); + if (CollectionUtils.isNotEmpty(maps)) { + countEmp[0] = countEmp[0] + 1; + List itemValue = maps.stream().filter(v -> v.get(grjnheItemId.toString()) != null).map(v -> (String) v.get(grjnheItemId.toString())).collect(Collectors.toList()); + sum = itemValue + .stream() + .filter(NumberUtils::isCreatable) + .map(BigDecimal::new) + .reduce(BigDecimal.ZERO, BigDecimal::add); + } + return sum; + }).reduce(BigDecimal.ZERO, BigDecimal::add); + } +// String sbAcct = SalaryEntityUtil.empty2Zero(Utils.null2String(acctSumMap.get(grjnheItemId.toString()))).toPlainString(); String sbUf = SalaryEntityUtil.empty2Zero(Utils.null2String(ufSumMap.get("sbgrjnhj"))).toPlainString(); - String ce = new BigDecimal(sbUf).subtract(new BigDecimal(sbAcct)).toPlainString(); + String ce = new BigDecimal(sbUf).subtract(sbAcct).toPlainString(); // 人数 - String empNumsAcct = SalaryEntityUtil.empty2Zero(Utils.null2String(acctSumMap.get("empNums"))).toPlainString(); + String empNumsAcct =String.valueOf(countEmp[0]); String empNumsUf = SalaryEntityUtil.empty2Zero(Utils.null2String(ufSumMap.get("empNums"))).toPlainString(); sbSql.append("(").append(modeId).append(",1,0,").append(currDate).append(",").append(currTime).append(",'"); sbSql.append(salaryMonth).append("','") @@ -2318,7 +2366,23 @@ public class LySalaryReportServiceImpl extends Service implements LySalaryReport } // 获取当月导入公积金数据 - List ufGjjInfos = getLyUfSbgjjMapper().listGjjInfoByDyxzzq(salaryMonth); +// List ufGjjInfos = getLyUfSbgjjMapper().listGjjInfoByDyxzzq(salaryMonth); + List ufGjjInfos = getLyUfSbgjjMapper().listGjjInfoByFyssq(salaryMonth); + // 根据人员id汇总 + Map> ufGroupByYg = SalaryEntityUtil.group2Map(ufGjjInfos, UfGjjInfo::getYg); + ufGjjInfos = ufGjjInfos.stream().filter(uf -> { + List list = ufGroupByYg.get(uf.getYg()); + if (CollectionUtils.isNotEmpty(list) && list.size() > 1) { + return !(uf.getGjjgrjn() == null || uf.getGjjgrjn().compareTo(Double.valueOf("0")) == 0); + } + return true; + }).collect(Collectors.toList()); + List dateList = ufGjjInfos.stream().map(UfGjjInfo::getDyxzzq) + .distinct() + .map(date -> SalaryDateUtil.dateStrToLocalYearMonth(date)) + .filter(date -> date != null).distinct() + .sorted(Comparator.comparing(Date::getTime)) + .collect(Collectors.toList()); // 根据公积金购买公司汇总 ufGjjInfos = ufGjjInfos.stream().map(value -> { if (value.getFycdgsqc() == null) { @@ -2352,28 +2416,31 @@ public class LySalaryReportServiceImpl extends Service implements LySalaryReport // 查询核算账套 List salarySobList = getSalarySobService(user).listAll(); List salarySobIds = salarySobList.stream().map(SalarySobPO::getId).collect(Collectors.toList()); - LocalDateRange dateRange = LocalDateRange.builder().fromDate(salaryMonthDate).endDate(salaryMonthDate).build(); - // 获取核算记录 - List salaryAcctRecordList = getSalaryAcctRecordService(user).listBySalarySobIdsAndSalaryMonth(salarySobIds, dateRange); - salaryAcctRecordList = salaryAcctRecordList.stream().filter(salaryAcctRecordPO -> salaryAcctRecordPO.getStatus() > SalaryAcctRecordStatusEnum.NOT_ARCHIVED.getValue()).collect(Collectors.toList()); - List salaryAcctRecordIds = salaryAcctRecordList.stream().map(SalaryAcctRecordPO::getId).collect(Collectors.toList()); - LinkedHashMap> acctSbSumByGsMap = new LinkedHashMap<>(); + + List salaryAcctRecordIds = new ArrayList<>(); + Map>> resultGroupByKey = new HashMap<>(); + if (CollectionUtils.isNotEmpty(dateList)) { + LocalDateRange dateRange = LocalDateRange.builder().fromDate(dateList.get(0)).endDate(dateList.get(dateList.size()-1)).build(); + // 获取核算记录 + List salaryAcctRecordList = getSalaryAcctRecordService(user).listBySalarySobIdsAndSalaryMonth(salarySobIds, dateRange); + salaryAcctRecordList = salaryAcctRecordList.stream().filter(salaryAcctRecordPO -> salaryAcctRecordPO.getStatus() > SalaryAcctRecordStatusEnum.NOT_ARCHIVED.getValue()).collect(Collectors.toList()); + salaryAcctRecordIds = salaryAcctRecordList.stream().map(SalaryAcctRecordPO::getId).collect(Collectors.toList()); + } if (CollectionUtils.isNotEmpty(salaryAcctRecordIds)) { List salaryAcctEmpList = getSalaryAcctEmployeeService(user).listBySalaryAcctRecordIds(salaryAcctRecordIds); // 查新薪资核算结果 List acctResultPOList = getSalaryAcctResultService(user).listBySalaryAcctRecordIdsAndSalaryItemIds(salaryAcctRecordIds, salaryItemIdList); List> resultMapList = buildData4LyReport(salaryItemList, salaryAcctEmpList, new ArrayList<>(), acctResultPOList, false); - // 根据公积金购买公司进行分组 - Map>> resultGroupByGmgs = SalaryEntityUtil.group2Map(resultMapList, map -> (map.get(gmgsItemId.toString()) == null ? " " : map.get(gmgsItemId.toString()).toString())); - List numberItems = salaryItemList.stream().filter(item -> item.getDataType().equals(SalaryDataTypeEnum.NUMBER.getValue())).collect(Collectors.toList()); - acctSbSumByGsMap = getSumResultByGroup(resultGroupByGmgs, Collections.emptyList(), numberItems, null ,Collections.emptyList()); + // 根据年月 公积金购买公司 人员id进行分组 + resultGroupByKey = SalaryEntityUtil.group2Map(resultMapList, + map -> (map.get("salaryMonth") == null ? " " : map.get("salaryMonth") + "_split" +(map.get(gmgsItemId.toString()) == null ? " " : map.get(gmgsItemId.toString()).toString())) + "_split" +(map.get("employeeId") == null ? " " : map.get("employeeId").toString())); } // 取建模、核算中购买公司合集 Set totalGs = new HashSet<>(); - Set acctGs = acctSbSumByGsMap.keySet(); +// Set acctGs = acctSbSumByGsMap.keySet(); totalGs.addAll(ufGjjSumByGsMap.keySet()); - totalGs.addAll(acctGs); +// totalGs.addAll(acctGs); String currDate = String.format("'%s'", TimeUtil.getCurrentDateString()); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); @@ -2387,20 +2454,44 @@ public class LySalaryReportServiceImpl extends Service implements LySalaryReport // 插入前先删除 String deleteSql ="delete from uf_dbhzbgjj where yf = '"+ salaryMonth + "'"; rs.execute(deleteSql); + Map>> finalResultGroupByKey = resultGroupByKey; for (List part : partition) { // 插入对比数据 StringBuilder sbSql = new StringBuilder("insert into uf_dbhzbgjj(formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime," + "yf,gmgs,gjjdrrs,xcffrs,gjjdrsj,gjjxcff,ce) values "); for (String gmgs : part) { String gmgsId = frztNameMap.get(gmgs); - Map acctSumMap = acctSbSumByGsMap.getOrDefault(gmgs, new HashMap<>()); +// Map acctSumMap = acctSbSumByGsMap.getOrDefault(gmgs, new HashMap<>()); Map ufSumMap = ufGjjSumByGsMap.getOrDefault(gmgs, new HashMap<>()); // 公积金 - String gjjAcct = SalaryEntityUtil.empty2Zero(Utils.null2String(acctSumMap.get(gjjItemId.toString()))).toPlainString(); + BigDecimal gjjAcct = new BigDecimal("0"); + // 获取该公积金购买公司下建模数据 + List ufGjjInfosList = ufGjjInfoGroupMap.get(gmgsId); + // 核算人数 + int[] countEmp = {0}; + if (CollectionUtils.isNotEmpty(ufGjjInfosList)) { + gjjAcct = ufGjjInfosList.stream().map(uf -> { + String key = uf.getDyxzzq() + "_split" + gmgs + "_split" + uf.getYg(); + List> maps = finalResultGroupByKey.get(key); + BigDecimal sum = new BigDecimal("0"); + if (CollectionUtils.isNotEmpty(maps)) { + countEmp[0] = countEmp[0] + 1; + List itemValue = maps.stream().filter(v -> v.get(gjjItemId.toString()) != null).map(v -> (String) v.get(gjjItemId.toString())).collect(Collectors.toList()); + sum = itemValue + .stream() + .filter(NumberUtils::isCreatable) + .map(BigDecimal::new) + .reduce(BigDecimal.ZERO, BigDecimal::add); + } + return sum; + }).reduce(BigDecimal.ZERO, BigDecimal::add); + } +// String gjjAcct = SalaryEntityUtil.empty2Zero(Utils.null2String(acctSumMap.get(gjjItemId.toString()))).toPlainString(); String gjjUf = SalaryEntityUtil.empty2Zero(Utils.null2String(ufSumMap.get("gjj"))).toPlainString(); - String ce = new BigDecimal(gjjUf).subtract(new BigDecimal(gjjAcct)).toPlainString(); + String ce = new BigDecimal(gjjUf).subtract(gjjAcct).toPlainString(); // 人数 - String empNumsAcct = SalaryEntityUtil.empty2Zero(Utils.null2String(acctSumMap.get("empNums"))).toPlainString(); +// String empNumsAcct = SalaryEntityUtil.empty2Zero(Utils.null2String(acctSumMap.get("empNums"))).toPlainString(); + String empNumsAcct =String.valueOf(countEmp[0]); String empNumsUf = SalaryEntityUtil.empty2Zero(Utils.null2String(ufSumMap.get("empNums"))).toPlainString(); sbSql.append("(").append(modeId).append(",1,0,").append(currDate).append(",").append(currTime).append(",'"); sbSql.append(salaryMonth).append("','") @@ -2449,15 +2540,33 @@ public class LySalaryReportServiceImpl extends Service implements LySalaryReport } // 获取当月导入社保数据 - List ufSbInfos = getLyUfSbgjjMapper().listSbInfoByDyxzzq(salaryMonth); +// List ufSbInfos = getLyUfSbgjjMapper().listSbInfoByDyxzzq(salaryMonth); + List ufSbInfos = getLyUfSbgjjMapper().listSbInfoByFyssq(salaryMonth); + // 根据人员id汇总 + Map> ufGroupByYg = SalaryEntityUtil.group2Map(ufSbInfos, UfSbInfo::getYg); + ufSbInfos = ufSbInfos.stream().filter(uf -> { + List list = ufGroupByYg.get(uf.getYg()); + if (CollectionUtils.isNotEmpty(list) && list.size() > 1) { + return !(uf.getSbgrjnhj() == null || uf.getSbgrjnhj().compareTo(Double.valueOf("0")) == 0); + } + return true; + }).collect(Collectors.toList()); + List dateList = ufSbInfos.stream().map(UfSbInfo::getDyxzzq) + .distinct() + .map(date -> SalaryDateUtil.dateStrToLocalYearMonth(date)) + .filter(date -> date != null).distinct() + .sorted(Comparator.comparing(Date::getTime)) + .collect(Collectors.toList()); ufSbInfos = ufSbInfos.stream().map(value -> { if (value.getGmgsqc() == null) { value.setGmgsqc(""); } return value; }).collect(Collectors.toList()); - // 根据社保购买公司汇总 + // 根据社保购买公司员工汇总 Map> ufSbInfoGroupMap = SalaryEntityUtil.group2Map(ufSbInfos, ufSbInfo -> Utils.null2String(ufSbInfo.getGmgsqc()) + "_split" + Utils.null2String(ufSbInfo.getYg())); + Map> ufSbInfoNameGroupMap = SalaryEntityUtil.group2Map(ufSbInfos, ufSbInfo -> Utils.null2String(frztMap.get(Utils.null2String(ufSbInfo.getGmgsqc()))) + "_split" + Utils.null2String(ufSbInfo.getYg())); + // 以购买公司维度求和 Map> ufSbSumByGsMap = new HashMap<>(); for (Map.Entry> entry : ufSbInfoGroupMap.entrySet()) { @@ -2511,69 +2620,61 @@ public class LySalaryReportServiceImpl extends Service implements LySalaryReport // 查询核算账套 List salarySobList = getSalarySobService(user).listAll(); List salarySobIds = salarySobList.stream().map(SalarySobPO::getId).collect(Collectors.toList()); - LocalDateRange dateRange = LocalDateRange.builder().fromDate(salaryMonthDate).endDate(salaryMonthDate).build(); - // 获取核算记录 - List salaryAcctRecordList = getSalaryAcctRecordService(user).listBySalarySobIdsAndSalaryMonth(salarySobIds, dateRange); - salaryAcctRecordList = salaryAcctRecordList.stream().filter(salaryAcctRecordPO -> salaryAcctRecordPO.getStatus() > SalaryAcctRecordStatusEnum.NOT_ARCHIVED.getValue()).collect(Collectors.toList()); - List salaryAcctRecordIds = salaryAcctRecordList.stream().map(SalaryAcctRecordPO::getId).collect(Collectors.toList()); - LinkedHashMap> acctSbSumByGsMap = new LinkedHashMap<>(); + // 查询所有薪资所属月下核算数据 + List salaryAcctRecordIds = new ArrayList<>(); + Map>> resultGroupByKey = new HashMap<>(); + if (CollectionUtils.isNotEmpty(dateList)) { + LocalDateRange dateRange = LocalDateRange.builder().fromDate(dateList.get(0)).endDate(dateList.get(dateList.size()-1)).build(); + // 获取核算记录 + List salaryAcctRecordList = getSalaryAcctRecordService(user).listBySalarySobIdsAndSalaryMonth(salarySobIds, dateRange); + salaryAcctRecordList = salaryAcctRecordList.stream().filter(salaryAcctRecordPO -> salaryAcctRecordPO.getStatus() > SalaryAcctRecordStatusEnum.NOT_ARCHIVED.getValue()).collect(Collectors.toList()); + salaryAcctRecordIds = salaryAcctRecordList.stream().map(SalaryAcctRecordPO::getId).collect(Collectors.toList()); + } + if (CollectionUtils.isNotEmpty(salaryAcctRecordIds)) { List salaryAcctEmpList = getSalaryAcctEmployeeService(user).listBySalaryAcctRecordIds(salaryAcctRecordIds); // 查新薪资核算结果 List acctResultPOList = getSalaryAcctResultService(user).listBySalaryAcctRecordIdsAndSalaryItemIds(salaryAcctRecordIds, salaryItemIdList); List> resultMapList = buildData4LyReport(salaryItemList, salaryAcctEmpList, new ArrayList<>(), acctResultPOList, false); - // 根据社保购买公司进行分组 - Map>> resultGroupByGmgsEmp = SalaryEntityUtil.group2Map(resultMapList, - map -> (map.get(gmgsItemId.toString()) == null ? " " : map.get(gmgsItemId.toString()).toString() + "_split" + Utils.null2String(map.get("employeeId")) )); - List numberItems = salaryItemList.stream().filter(item -> item.getDataType().equals(SalaryDataTypeEnum.NUMBER.getValue())).collect(Collectors.toList()); - acctSbSumByGsMap = getSumResultByGroup(resultGroupByGmgsEmp, Collections.emptyList(), numberItems, null ,Collections.emptyList()); + // 根据年月 社保购买公司 人员id进行分组 + resultGroupByKey = SalaryEntityUtil.group2Map(resultMapList, + map -> (map.get("salaryMonth") == null ? " " : map.get("salaryMonth") + "_split" +(map.get(gmgsItemId.toString()) == null ? " " : map.get(gmgsItemId.toString()).toString())) + "_split" +(map.get("employeeId") == null ? " " : map.get("employeeId").toString())); +// List numberItems = salaryItemList.stream().filter(item -> item.getDataType().equals(SalaryDataTypeEnum.NUMBER.getValue())).collect(Collectors.toList()); +// LinkedHashMap> acctSbSumByGsAndDateMap = getSumResultByGroup(resultGroupByGmgsAndDate, Collections.emptyList(), numberItems, null ,Collections.emptyList()); } // 取建模、核算中购买公司_split人员id 合集 Set totalKey = new HashSet<>(); - Set acctGs = acctSbSumByGsMap.keySet(); +// Set acctGs = acctSbSumByGsMap.keySet(); totalKey.addAll(ufSbSumByGsMap.keySet()); - totalKey.addAll(acctGs); +// totalKey.addAll(acctGs); // 对比建模、核算数据过滤出有差异的key List> diffList = new ArrayList<>(); + Map>> finalResultGroupByKey = resultGroupByKey; for (String key : totalKey) { boolean hasDiff = false; - Map acctSumMap = acctSbSumByGsMap.getOrDefault(key, new HashMap<>()); Map ufSumMap = ufSbSumByGsMap.getOrDefault(key, new HashMap<>()); -// // 养老 -// BigDecimal ylAcct = SalaryEntityUtil.empty2Zero(Utils.null2String(acctSumMap.get(ylItemId.toString()))); -// BigDecimal ylUf = SalaryEntityUtil.empty2Zero(Utils.null2String(ufSumMap.get("yl"))); -// if (ylAcct.compareTo(ylUf) != 0) { -// hasDiff = true; -// } -// // 医疗 -// BigDecimal yliaoAcct = SalaryEntityUtil.empty2Zero(Utils.null2String(acctSumMap.get(yliaoItemId.toString()))); -// BigDecimal yliaoUf = SalaryEntityUtil.empty2Zero(Utils.null2String(ufSumMap.get("yliao"))); -// if (yliaoAcct.compareTo(yliaoUf) != 0) { -// hasDiff = true; -// } -// // 生育 -// BigDecimal syAcct = SalaryEntityUtil.empty2Zero(Utils.null2String(acctSumMap.get(syItemId.toString()))); -// BigDecimal syUf = SalaryEntityUtil.empty2Zero(Utils.null2String(ufSumMap.get("sy"))); -// if (syAcct.compareTo(syUf) != 0) { -// hasDiff = true; -// } -// // 工伤 -// BigDecimal gsAcct = SalaryEntityUtil.empty2Zero(Utils.null2String(acctSumMap.get(gsItemId.toString()))); -// BigDecimal gsUf = SalaryEntityUtil.empty2Zero(Utils.null2String(ufSumMap.get("gs"))); -// if (gsAcct.compareTo(gsUf) != 0) { -// hasDiff = true; -// } -// // 失业 -// BigDecimal syeAcct = SalaryEntityUtil.empty2Zero(Utils.null2String(acctSumMap.get(syeItemId.toString()))); -// BigDecimal syeUf = SalaryEntityUtil.empty2Zero(Utils.null2String(ufSumMap.get("sye"))); -// if (syeAcct.compareTo(syeUf) != 0) { -// hasDiff = true; -// } // 社保合计 - BigDecimal sbAcct = SalaryEntityUtil.empty2Zero(Utils.null2String(acctSumMap.get(grjnheItemId.toString()))); + BigDecimal sbAcct = new BigDecimal("0"); + // 获取该社保购买公司下建模数据 + List ufSbInfosList = ufSbInfoNameGroupMap.get(key); + if (CollectionUtils.isNotEmpty(ufSbInfosList)) { + sbAcct = ufSbInfosList.stream().map(uf -> { + List> maps = finalResultGroupByKey.get(uf.getDyxzzq() + "_split" + key); + BigDecimal sum = new BigDecimal("0"); + if (CollectionUtils.isNotEmpty(maps)) { + List itemValue = maps.stream().filter(v -> v.get(grjnheItemId.toString()) != null).map(v -> (String) v.get(grjnheItemId.toString())).collect(Collectors.toList()); + sum = itemValue + .stream() + .filter(NumberUtils::isCreatable) + .map(BigDecimal::new) + .reduce(BigDecimal.ZERO, BigDecimal::add); + } + return sum; + }).reduce(BigDecimal.ZERO, BigDecimal::add); + } BigDecimal sbUf = SalaryEntityUtil.empty2Zero(Utils.null2String(ufSumMap.get("sbgrjnhj"))); if (sbAcct.compareTo(sbUf) != 0) { hasDiff = true; @@ -2584,16 +2685,6 @@ public class LySalaryReportServiceImpl extends Service implements LySalaryReport Long empId = splitKey.length > 1 && NumberUtils.isCreatable(splitKey[1]) ? Long.valueOf(splitKey[1]) : 0; if (hasDiff) { Map singleDiffMap = new HashMap<>(); -// singleDiffMap.put("ylAcct", ylAcct); -// singleDiffMap.put("ylUf", ylUf); -// singleDiffMap.put("yliaoAcct", yliaoAcct); -// singleDiffMap.put("yliaoUf", yliaoUf); -// singleDiffMap.put("syAcct", syAcct); -// singleDiffMap.put("syUf", syUf); -// singleDiffMap.put("gsAcct", gsAcct); -// singleDiffMap.put("gsUf", gsUf); -// singleDiffMap.put("syeAcct", syeAcct); -// singleDiffMap.put("syeUf", syeUf); singleDiffMap.put("sbAcct", sbAcct); singleDiffMap.put("sbUf", sbUf); singleDiffMap.put("xm", empId); @@ -2678,7 +2769,23 @@ public class LySalaryReportServiceImpl extends Service implements LySalaryReport } // 获取当月导入社保数据 - List ufGjjInfos = getLyUfSbgjjMapper().listGjjInfoByDyxzzq(salaryMonth); +// List ufGjjInfos = getLyUfSbgjjMapper().listGjjInfoByDyxzzq(salaryMonth); + List ufGjjInfos = getLyUfSbgjjMapper().listGjjInfoByFyssq(salaryMonth); + // 根据人员id汇总 + Map> ufGroupByYg = SalaryEntityUtil.group2Map(ufGjjInfos, UfGjjInfo::getYg); + ufGjjInfos = ufGjjInfos.stream().filter(uf -> { + List list = ufGroupByYg.get(uf.getYg()); + if (CollectionUtils.isNotEmpty(list) && list.size() > 1) { + return !(uf.getGjjgrjn() == null || uf.getGjjgrjn().compareTo(Double.valueOf("0")) == 0); + } + return true; + }).collect(Collectors.toList()); + List dateList = ufGjjInfos.stream().map(UfGjjInfo::getDyxzzq) + .distinct() + .map(date -> SalaryDateUtil.dateStrToLocalYearMonth(date)) + .filter(date -> date != null).distinct() + .sorted(Comparator.comparing(Date::getTime)) + .collect(Collectors.toList()); ufGjjInfos = ufGjjInfos.stream().map(value -> { if (value.getFycdgsqc() == null) { value.setFycdgsqc(""); @@ -2687,6 +2794,8 @@ public class LySalaryReportServiceImpl extends Service implements LySalaryReport }).collect(Collectors.toList()); // 根据社保购买公司汇总 Map> ufGjjInfoGroupMap = SalaryEntityUtil.group2Map(ufGjjInfos, ufGjjInfo -> Utils.null2String(ufGjjInfo.getFycdgsqc()) + "_split" + Utils.null2String(ufGjjInfo.getYg())); + Map> ufGjjInfoNameGroupMap = SalaryEntityUtil.group2Map(ufGjjInfos, ufGjjInfo -> Utils.null2String(frztMap.get(Utils.null2String(ufGjjInfo.getFycdgsqc()))) + "_split" + Utils.null2String(ufGjjInfo.getYg())); + // 以购买公司维度求和 Map> ufGjjSumByGsMap = new HashMap<>(); for (Map.Entry> entry : ufGjjInfoGroupMap.entrySet()) { @@ -2714,11 +2823,18 @@ public class LySalaryReportServiceImpl extends Service implements LySalaryReport // 查询核算账套 List salarySobList = getSalarySobService(user).listAll(); List salarySobIds = salarySobList.stream().map(SalarySobPO::getId).collect(Collectors.toList()); - LocalDateRange dateRange = LocalDateRange.builder().fromDate(salaryMonthDate).endDate(salaryMonthDate).build(); - // 获取核算记录 - List salaryAcctRecordList = getSalaryAcctRecordService(user).listBySalarySobIdsAndSalaryMonth(salarySobIds, dateRange); - salaryAcctRecordList = salaryAcctRecordList.stream().filter(salaryAcctRecordPO -> salaryAcctRecordPO.getStatus() > SalaryAcctRecordStatusEnum.NOT_ARCHIVED.getValue()).collect(Collectors.toList()); - List salaryAcctRecordIds = salaryAcctRecordList.stream().map(SalaryAcctRecordPO::getId).collect(Collectors.toList()); + + // 查询所有薪资所属月下核算数据 + List salaryAcctRecordIds = new ArrayList<>(); + Map>> resultGroupByKey = new HashMap<>(); + if (CollectionUtils.isNotEmpty(dateList)) { + LocalDateRange dateRange = LocalDateRange.builder().fromDate(dateList.get(0)).endDate(dateList.get(dateList.size()-1)).build(); + // 获取核算记录 + List salaryAcctRecordList = getSalaryAcctRecordService(user).listBySalarySobIdsAndSalaryMonth(salarySobIds, dateRange); + salaryAcctRecordList = salaryAcctRecordList.stream().filter(salaryAcctRecordPO -> salaryAcctRecordPO.getStatus() > SalaryAcctRecordStatusEnum.NOT_ARCHIVED.getValue()).collect(Collectors.toList()); + salaryAcctRecordIds = salaryAcctRecordList.stream().map(SalaryAcctRecordPO::getId).collect(Collectors.toList()); + } + LinkedHashMap> acctSbSumByGsMap = new LinkedHashMap<>(); if (CollectionUtils.isNotEmpty(salaryAcctRecordIds)) { List salaryAcctEmpList = getSalaryAcctEmployeeService(user).listBySalaryAcctRecordIds(salaryAcctRecordIds); @@ -2726,26 +2842,50 @@ public class LySalaryReportServiceImpl extends Service implements LySalaryReport List acctResultPOList = getSalaryAcctResultService(user).listBySalaryAcctRecordIdsAndSalaryItemIds(salaryAcctRecordIds, salaryItemIdList); List> resultMapList = buildData4LyReport(salaryItemList, salaryAcctEmpList, new ArrayList<>(), acctResultPOList, false); // 根据社保购买公司进行分组 - Map>> resultGroupByGmgsEmp = SalaryEntityUtil.group2Map(resultMapList, - map -> (map.get(gmgsItemId.toString()) == null ? " " : map.get(gmgsItemId.toString()).toString() + "_split" + Utils.null2String(map.get("employeeId")) )); - List numberItems = salaryItemList.stream().filter(item -> item.getDataType().equals(SalaryDataTypeEnum.NUMBER.getValue())).collect(Collectors.toList()); - acctSbSumByGsMap = getSumResultByGroup(resultGroupByGmgsEmp, Collections.emptyList(), numberItems, null ,Collections.emptyList()); +// Map>> resultGroupByGmgsEmp = SalaryEntityUtil.group2Map(resultMapList, +// map -> (map.get(gmgsItemId.toString()) == null ? " " : map.get(gmgsItemId.toString()).toString() + "_split" + Utils.null2String(map.get("employeeId")) )); +// List numberItems = salaryItemList.stream().filter(item -> item.getDataType().equals(SalaryDataTypeEnum.NUMBER.getValue())).collect(Collectors.toList()); +// acctSbSumByGsMap = getSumResultByGroup(resultGroupByGmgsEmp, Collections.emptyList(), numberItems, null ,Collections.emptyList()); + + // 根据年月 公积金购买公司 人员id进行分组 + resultGroupByKey = SalaryEntityUtil.group2Map(resultMapList, + map -> (map.get("salaryMonth") == null ? " " : map.get("salaryMonth") + "_split" +(map.get(gmgsItemId.toString()) == null ? " " : map.get(gmgsItemId.toString()).toString())) + "_split" +(map.get("employeeId") == null ? " " : map.get("employeeId").toString())); } // 取建模、核算中购买公司_split人员id 合集 Set totalKey = new HashSet<>(); - Set acctGs = acctSbSumByGsMap.keySet(); +// Set acctGs = acctSbSumByGsMap.keySet(); totalKey.addAll(ufGjjSumByGsMap.keySet()); - totalKey.addAll(acctGs); +// totalKey.addAll(acctGs); // 对比建模、核算数据过滤出有差异的key List> diffList = new ArrayList<>(); + Map>> finalResultGroupByKey = resultGroupByKey; for (String key : totalKey) { boolean hasDiff = false; - Map acctSumMap = acctSbSumByGsMap.getOrDefault(key, new HashMap<>()); +// Map acctSumMap = acctSbSumByGsMap.getOrDefault(key, new HashMap<>()); Map ufSumMap = ufGjjSumByGsMap.getOrDefault(key, new HashMap<>()); // 公积金 - BigDecimal gjjAcct = SalaryEntityUtil.empty2Zero(Utils.null2String(acctSumMap.get(gjjItemId.toString()))); + BigDecimal gjjAcct = new BigDecimal("0"); + // 获取该社保购买公司下建模数据 + List ufGjjInfosList = ufGjjInfoNameGroupMap.get(key); + if (CollectionUtils.isNotEmpty(ufGjjInfosList)) { + gjjAcct = ufGjjInfosList.stream().map(uf -> { + List> maps = finalResultGroupByKey.get(uf.getDyxzzq() + "_split" + key); + BigDecimal sum = new BigDecimal("0"); + if (CollectionUtils.isNotEmpty(maps)) { + List itemValue = maps.stream().filter(v -> v.get(gjjItemId.toString()) != null).map(v -> (String) v.get(gjjItemId.toString())).collect(Collectors.toList()); + sum = itemValue + .stream() + .filter(NumberUtils::isCreatable) + .map(BigDecimal::new) + .reduce(BigDecimal.ZERO, BigDecimal::add); + } + return sum; + }).reduce(BigDecimal.ZERO, BigDecimal::add); + } + +// BigDecimal gjjAcct = SalaryEntityUtil.empty2Zero(Utils.null2String(acctSumMap.get(gjjItemId.toString()))); BigDecimal gjjUf = SalaryEntityUtil.empty2Zero(Utils.null2String(ufSumMap.get("gjj"))); if (gjjAcct.compareTo(gjjUf) != 0) { hasDiff = true;