diff --git a/src/com/engine/salary/service/SIAccountService.java b/src/com/engine/salary/service/SIAccountService.java index 60d06ed86..6a496845b 100644 --- a/src/com/engine/salary/service/SIAccountService.java +++ b/src/com/engine/salary/service/SIAccountService.java @@ -314,5 +314,7 @@ public interface SIAccountService { boolean checkBalance(InsuranceAccountDetailPO po); boolean checkBalancePayInsurance(InsuranceAccountDetailPO po); + + List buildRecords(List list, Map paymentMap); } diff --git a/src/com/engine/salary/service/impl/SIAccountServiceImpl.java b/src/com/engine/salary/service/impl/SIAccountServiceImpl.java index 6bb0fd1f2..43168124a 100644 --- a/src/com/engine/salary/service/impl/SIAccountServiceImpl.java +++ b/src/com/engine/salary/service/impl/SIAccountServiceImpl.java @@ -18,10 +18,7 @@ import com.engine.salary.encrypt.EncryptUtil; import com.engine.salary.entity.datacollection.DataCollectionEmployee; import com.engine.salary.entity.progress.ProgressDTO; import com.engine.salary.entity.siaccount.bo.InsuranceAccountBO; -import com.engine.salary.entity.siaccount.dto.InsuranceAccountBatchListDTO; -import com.engine.salary.entity.siaccount.dto.InsuranceAccountTabDTO; -import com.engine.salary.entity.siaccount.dto.InsuranceAccountViewListDTO; -import com.engine.salary.entity.siaccount.dto.InsuranceAcctDetailImportFieldDTO; +import com.engine.salary.entity.siaccount.dto.*; import com.engine.salary.entity.siaccount.param.*; import com.engine.salary.entity.siaccount.po.*; import com.engine.salary.entity.siarchives.po.*; @@ -67,6 +64,7 @@ import com.engine.salary.util.valid.ValidUtil; import com.engine.salary.wrapper.SalaryFormulaWrapper; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.wbi.util.StringUtil; import dm.jdbc.util.IdGenerator; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; @@ -83,6 +81,7 @@ import weaver.hrm.User; import java.io.InputStream; import java.math.BigDecimal; +import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -103,7 +102,6 @@ import static com.engine.salary.util.excel.ExcelSupport.EXCEL_TYPE_XLSX; @Slf4j public class SIAccountServiceImpl extends Service implements SIAccountService { -// private SIAccountBiz siAccountBiz = new SIAccountBiz(); private SIArchivesBiz siArchivesBiz = new SIArchivesBiz(); @@ -113,9 +111,9 @@ public class SIAccountServiceImpl extends Service implements SIAccountService { return ServiceUtil.getService(RecordsBuildServiceImpl.class, user); } - public SIAccountBiz getSiAccountBiz(User user) { - return ServiceUtil.getService(SIAccountBiz.class, user); - } +// public SIAccountBiz getSiAccountBiz(User user) { +// return ServiceUtil.getService(SIAccountBiz.class, user); +// } public ColumnBuildService getColumnBuildService(User user) { return ServiceUtil.getService(ColumnBuildServiceImpl.class, user); @@ -225,6 +223,10 @@ public class SIAccountServiceImpl extends Service implements SIAccountService { return MapperProxyFactory.getProxy(InsuranceCompensationMapper.class); } + private SIAccountUtilMapper getSIAccountUtilMapper() { + return MapperProxyFactory.getProxy(SIAccountUtilMapper.class); + } + @Override public Map listPage(InsuranceAccountBatchParam queryParam) { Long employeeId = (long) user.getUID(); @@ -244,7 +246,8 @@ public class SIAccountServiceImpl extends Service implements SIAccountService { } //福利台账列表 - PageInfo pageInfo = getSiAccountBiz(user).listPage(queryParam); +// PageInfo pageInfo = getSiAccountBiz(user).listPage(queryParam); + PageInfo pageInfo = siBatchListPage(queryParam); Collection insuranceAccountBatchPOS = pageInfo.getList(); List insuranceAccountBatchListDTOS = InsuranceAccountBO.buildAccountBatchDTOList(insuranceAccountBatchPOS); @@ -313,7 +316,8 @@ public class SIAccountServiceImpl extends Service implements SIAccountService { Map datas = new HashMap<>(); //正常缴纳列表 - PageInfo pageInfo = getSiAccountBiz(user).listCommonPage(queryParam); +// PageInfo pageInfo = getSiAccountBiz(user).listCommonPage(queryParam); + PageInfo pageInfo = siBatchListCommonPage(queryParam); List insuranceAccountDetailPOS = pageInfo.getList(); //数据组装 @@ -599,7 +603,8 @@ public class SIAccountServiceImpl extends Service implements SIAccountService { @Override public void delete(AccountParam accountParam) { Long employeeId = (long) user.getUID(); - getSiAccountBiz(user).delete(accountParam, employeeId); +// getSiAccountBiz(user).delete(accountParam, employeeId); + siDelete(accountParam); } @Override @@ -635,24 +640,27 @@ public class SIAccountServiceImpl extends Service implements SIAccountService { public void saveSupplementaryAccount(SaveSupplementaryAccountParam saveSupplementaryAccountParam) { ValidUtil.doValidator(saveSupplementaryAccountParam); - Long employeeId = (long) user.getUID(); - String currentUserName = user.getLastname(); - getSiAccountBiz(user).saveSupplementaryAccount(saveSupplementaryAccountParam, employeeId, currentUserName); +// Long employeeId = (long) user.getUID(); +// String currentUserName = user.getLastname(); +// getSiAccountBiz(user).saveSupplementaryAccount(saveSupplementaryAccountParam, employeeId, currentUserName); + siSaveSupplementaryAccount(saveSupplementaryAccountParam); } @Override public void deleteCommonAccount(SaveCommonAccountParam param) { ValidUtil.doValidator(param); - Long employeeId = (long) user.getUID(); - String currentUserName = user.getLastname(); - getSiAccountBiz(user).deleteCommonAccount(param, employeeId, currentUserName); +// Long employeeId = (long) user.getUID(); +// String currentUserName = user.getLastname(); +// getSiAccountBiz(user).deleteCommonAccount(param, employeeId, currentUserName); + siDeleteCommonAccount(param); } @Override public void deleteSummplementaryAccount(List supplementAccountBaseParams) { - Long employeeId = (long) user.getUID(); - String currentUserName = user.getLastname(); - getSiAccountBiz(user).deleteSupplementaryAccount(supplementAccountBaseParams, employeeId, currentUserName); +// Long employeeId = (long) user.getUID(); +// String currentUserName = user.getLastname(); +// getSiAccountBiz(user).deleteSupplementaryAccount(supplementAccountBaseParams, employeeId, currentUserName); + siDeleteSupplementaryAccount(supplementAccountBaseParams); } @Override @@ -799,10 +807,11 @@ public class SIAccountServiceImpl extends Service implements SIAccountService { @Override public void accountInspect(InspectAccountParam param) { - Long employeeId = (long) user.getUID(); +// Long employeeId = (long) user.getUID(); ValidUtil.doValidator(param); - String currentUserName = user.getLastname(); - getSiAccountBiz(user).accountInspect(param.getIds(), param.getBillMonth(), employeeId, currentUserName, param.getPaymentOrganization()); +// String currentUserName = user.getLastname(); +// getSiAccountBiz(user).accountInspect(param.getIds(), param.getBillMonth(), employeeId, currentUserName, param.getPaymentOrganization()); + accountInspect(param.getIds(), param.getBillMonth(), param.getPaymentOrganization()); } @Override @@ -926,7 +935,8 @@ public class SIAccountServiceImpl extends Service implements SIAccountService { @Override public PageInfo overView(InsuranceAccountDetailParam queryParam) { - PageInfo pageInfos = getSiAccountBiz(user).overView(queryParam); +// PageInfo pageInfos = getSiAccountBiz(user).overView(queryParam); + PageInfo pageInfos = siOverView(queryParam); return pageInfos; } @@ -1521,13 +1531,15 @@ public class SIAccountServiceImpl extends Service implements SIAccountService { @Override public void socialSecurityBenefitsRecalculate(InsuranceAccountBatchPO param) { //fixme 重新核算的校验逻辑 1、先取台账对应扣缴义务人下的所有账套 2、取账套下所有核算记录 3、判断核算记录有没有使用对应月份的福利台账 - int num = getSiAccountBiz(user).checkIfBusinessaccounting(param); +// int num = getSiAccountBiz(user).checkIfBusinessaccounting(param); + int num = checkIfBusinessAccounting(param); //表示已经被核算过不能重新核算 if (num > 0) { throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0, "已被薪酬核算给核算过,无法重新核算!")); } param.setBillStatus(0); - getSiAccountBiz(user).updateById(param); +// getSiAccountBiz(user).updateById(param); + updateById(param); } /** @@ -1804,7 +1816,8 @@ public class SIAccountServiceImpl extends Service implements SIAccountService { encryptUtil.encryptList(updateInsuranceAccountDetailList, InsuranceAccountDetailPO.class); //更新 for(InsuranceAccountDetailPO po : updateInsuranceAccountDetailList) { - getSiAccountBiz(user).updateByEmployeeIdAndBillMonth(po); +// getSiAccountBiz(user).updateByEmployeeIdAndBillMonth(po); + updateByEmployeeIdAndBillMonth(po); } //刷新hrsa_bill_batch中数据统计信息 @@ -3667,7 +3680,8 @@ public class SIAccountServiceImpl extends Service implements SIAccountService { encryptUtil.encryptList(updateInsuranceAccountDetailList, InsuranceAccountDetailPO.class); //更新 for(InsuranceAccountDetailPO po : updateInsuranceAccountDetailList) { - getSiAccountBiz(user).updateByEmployeeIdAndBillMonth(po); +// getSiAccountBiz(user).updateByEmployeeIdAndBillMonth(po); + updateByEmployeeIdAndBillMonth(po); } } if (createInsuranceAccountDetailList.size() > 0) { @@ -3705,7 +3719,8 @@ public class SIAccountServiceImpl extends Service implements SIAccountService { // 正常缴纳列表 queryParam.setPageSize(10000000); - PageInfo pageInfo = getSiAccountBiz(user).listCommonPage(queryParam); +// PageInfo pageInfo = getSiAccountBiz(user).listCommonPage(queryParam); + PageInfo pageInfo = siBatchListCommonPage(queryParam); List insuranceAccountDetailPOS = pageInfo.getList(); // 数据组装 List> records = getService(user).buildCommonRecords(insuranceAccountDetailPOS, employeeId); @@ -4319,6 +4334,7 @@ public class SIAccountServiceImpl extends Service implements SIAccountService { insuranceAccountDetailPO.setOtherComSum(otherComSum.toPlainString()); return insuranceAccountDetailPO; } + /*****以下代码为SIAccountBiz中逻辑迁移,旨在减少Biz类的使用*****/ /** * 新建核算并归档 @@ -5352,4 +5368,865 @@ public class SIAccountServiceImpl extends Service implements SIAccountService { // insuranceSchemeContext.setNewValues(insuranceAccountBatchPO); // siAccountLoggerTemplate.write(insuranceSchemeContext); } + + + public PageInfo siBatchListPage(InsuranceAccountBatchParam queryParam) { + List list = getInsuranceAccountBatchMapper().list(queryParam); + PageInfo page = SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(), + list, InsuranceAccountBatchPO.class); + encryptUtil.decryptList(page.getList(), InsuranceAccountBatchPO.class); + return page; + } + + public PageInfo siBatchListCommonPage(InsuranceAccountDetailParam queryParam) { + queryParam.setPaymentStatus(PaymentStatusEnum.COMMON.getValue()); + //排序配置 + OrderRuleVO orderRule = getSalarySysConfService(user).orderRule(); + queryParam.setOrderRule(orderRule); + //系统人员福利台账明细 + List list = getInsuranceAccountDetailMapper().list(queryParam); + //非系统各人员台账明细 + List extList = getInsuranceAccountDetailMapper().extList(queryParam); + list.addAll(extList); + PageInfo pageInfo = SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(), + list, InsuranceAccountDetailPO.class); + encryptUtil.decryptList(pageInfo.getList(), InsuranceAccountDetailPO.class); + return pageInfo; + } + + public void siDelete(AccountParam param) { + InsuranceAccountBatchPO insuranceAccountBatchPO = getInsuranceAccountBatchMapper().getByBillMonth(param.getBillMonth(), param.getPaymentOrganization()); + encryptUtil.decrypt(insuranceAccountBatchPO, InsuranceAccountBatchPO.class); + SalaryAssert.notNull(insuranceAccountBatchPO, SalaryI18nUtil.getI18nLabel(0, "参数错误")); +// if (insuranceAccountBatchPO.getBillStatus().equals(BillStatusEnum.ARCHIVED.getValue())) { +// int num = checkIfBusinessAccounting(insuranceAccountBatchPO); +// //表示已经被核算过不能重新核算 +// if (num > 0) { +// throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0, "已被薪酬核算给核算过,无法删除!")); +// } +// } + +// if(param.getPaymentOrganization()==null){ +// throw new SalaryRunTimeException("个税扣缴义务人为空"); +// } + getInsuranceAccountBatchMapper().deleteById(insuranceAccountBatchPO.getId()); + getInsuranceAccountDetailMapper().batchDeleteNotFile(param.getBillMonth(), param.getPaymentOrganization()); + + //删除账单月份+个税扣缴义务人下的调差数据 + getInsuranceCompensationMapper().deleteByBillMonthAndPayOrg(param.getBillMonth(), param.getPaymentOrganization()); +// LoggerContext insuranceSchemeContext = new LoggerContext(); +// insuranceSchemeContext.setTargetId(String.valueOf(insuranceAccountBatchPO.getId())); +// insuranceSchemeContext.setTargetName(insuranceAccountBatchPO.getBillMonth()); +// insuranceSchemeContext.setOperateType(OperateTypeEnum.DELETE.getValue()); +// insuranceSchemeContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(tenantkey, employeeId, 100464, "删除台账")); +// insuranceSchemeContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(tenantkey, employeeId, 100464, "删除台账")); +// insuranceSchemeContext.setNewValues(insuranceAccountBatchPO); +// siAccountLoggerTemplate.write(insuranceSchemeContext); + } + + public void siSaveSupplementaryAccount(SaveSupplementaryAccountParam param) { + if (StringUtils.isBlank(param.getBillMonth()) || CollectionUtils.isEmpty(param.getBillMonthList()) || CollectionUtils.isEmpty(param.getProjects()) + || CollectionUtils.isEmpty(param.getIncludes())) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0, "参数错误")); + } + //需要补缴的月份 + if (param.getBillMonthList().contains(param.getBillMonth())) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0, "当前月走正常缴纳")); + } + //需要补缴的员工id + List employeeIds = param.getIncludes(); + if (CollectionUtils.isNotEmpty(param.getExcludes())) { + employeeIds = employeeIds.stream().filter(item -> !param.getExcludes().contains(item)).collect(Collectors.toList()); + } + //校验补缴人员是否存在福利档案基础信息,并且runStatus处于正在缴纳或者待减员 + List insuranceBaseInfoList = getInsuranceBaseInfoMapper().getSocialByPaymentOrganization(param.getPaymentOrganization()); + List finalEmployeeIds = employeeIds; + List filterList = insuranceBaseInfoList.stream().filter(e -> { + for (Long uId : finalEmployeeIds) { + if (e.getEmployeeId().equals(uId) && (e.getRunStatus().equals(EmployeeStatusEnum.STAY_DEL.getValue()) || e.getRunStatus().equals(EmployeeStatusEnum.PAYING.getValue()))) { + return true; + } + } + return false; + }).collect(Collectors.toList()); + if (filterList.size() != employeeIds.size()) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0, "补缴人员中存在未设置福利档案人员或相关人员不在福利在缴人员中,不可新建补缴信息!")); + } + //20231122逻辑优化,过滤出不在起始缴纳月和最后缴纳月区间的人员 + List empIdsInPayMonthRange = listCanPayEmpIds(param.getPaymentOrganization(), param.getBillMonth()); + employeeIds = employeeIds.stream().filter(f -> empIdsInPayMonthRange.contains(f)).collect(Collectors.toList()); + + SalaryAssert.notEmpty(employeeIds, SalaryI18nUtil.getI18nLabel(0, "无核算人员")); + List baseList = new ArrayList<>(); + employeeIds.stream().forEach(id -> { + param.getBillMonthList().stream().forEach(month -> { + SupplementAccountBaseParam supplementAccountBaseParam = SupplementAccountBaseParam.builder() + .supplementaryMonth(month) + .employeeId(id) + .paymentOrganization(param.getPaymentOrganization()) + .projects(param.getProjects()) + .billMonth(param.getBillMonth()) + .supplementType(param.getSupplementType()) + .build(); + if ("2".equals(param.getSupplementType())) { + supplementAccountBaseParam.setSocialPaymentBaseString(param.getSocialPaymentBaseString()); + supplementAccountBaseParam.setFundPaymentBaseString(param.getFundPaymentBaseString()); + supplementAccountBaseParam.setOtherPaymentBaseString(param.getOtherPaymentBaseString()); + } else if("3".equals(param.getSupplementType())) { + supplementAccountBaseParam.setSocialPaymentPerString(param.getSocialPaymentPerString()); + supplementAccountBaseParam.setSocialPaymentComString(param.getSocialPaymentComString()); + supplementAccountBaseParam.setFundPaymentPerString(param.getFundPaymentPerString()); + supplementAccountBaseParam.setFundPaymentComString(param.getFundPaymentComString()); + supplementAccountBaseParam.setOtherPaymentPerString(param.getOtherPaymentPerString()); + supplementAccountBaseParam.setOtherPaymentComString(param.getOtherPaymentComString()); + } + baseList.add(supplementAccountBaseParam); + }); + }); + //核算开始 + accountSupplement(baseList, employeeIds, param.getPaymentOrganization()); + + updateBatchAccount(AccountParam.builder().billMonth(param.getBillMonth()).paymentOrganization(param.getPaymentOrganization()).build()); + } + + /** + * @param baseList 员工id-账单月份-补缴月份(单挑)-补缴项 集合 + * @param employeeIds 需要补缴的员工id + * @return + */ + public String accountSupplement(List baseList, List employeeIds, Long paymentOrganization) { + //(k,v) k-员工id v-员工对应的福利档案数据 + Map longInsuranceArchivesAccountPOMap = siArchivesBiz.buildBatchAccount(employeeIds, paymentOrganization); + //核算结果集 + List pos = new ArrayList<>(); + baseList.forEach(baseParam -> { + //判断人员id+账单月份+补缴月份在表中的唯一性 + List supplementList = getInsuranceAccountDetailMapper().querySupplementList(baseParam.getBillMonth(), baseParam.getPaymentOrganization(), baseParam.getEmployeeId(), baseParam.getSupplementaryMonth()); + if (supplementList.size() > 0) { + throw new SalaryRunTimeException("当前人员和账单月份已存在该补缴月份的数据!无法再次创建!"); + } + InsuranceAccountDetailPO insuranceAccountDetailPO = accountSingleEmployeeBill(baseParam, longInsuranceArchivesAccountPOMap.get(baseParam.getEmployeeId())); + pos.add(insuranceAccountDetailPO); + }); + batchSaveSupplementAccount(pos); + return SalaryI18nUtil.getI18nLabel(0, "核算完成,数据保存成功"); + } + + public InsuranceAccountDetailPO accountSingleEmployeeBill(SupplementAccountBaseParam baseParam, InsuranceArchivesAccountPO accountPO) { + InsuranceAccountDetailPO insuranceAccountDetailPO = new InsuranceAccountDetailPO(); + List projects = baseParam.getProjects(); + insuranceAccountDetailPO.setBillMonth(baseParam.getBillMonth()); + insuranceAccountDetailPO.setBillStatus(BillStatusEnum.NOT_ARCHIVED.getValue()); + insuranceAccountDetailPO.setCreator((long) user.getUID()); + insuranceAccountDetailPO.setCreateTime(new Date()); + insuranceAccountDetailPO.setUpdateTime(new Date()); + insuranceAccountDetailPO.setDeleteType(DeleteTypeEnum.NOT_DELETED.getValue()); + insuranceAccountDetailPO.setId(IdGenerator.generate()); + insuranceAccountDetailPO.setEmployeeId(baseParam.getEmployeeId()); + insuranceAccountDetailPO.setPaymentStatus(PaymentStatusEnum.REPAIR.getValue()); + insuranceAccountDetailPO.setSupplementaryMonth(baseParam.getSupplementaryMonth()); + insuranceAccountDetailPO.setPaymentOrganization(baseParam.getPaymentOrganization()); + insuranceAccountDetailPO.setSupplementaryProjects( + String.join(",", + baseParam.getProjects() == null ? new ArrayList<>() : baseParam.getProjects().stream().map(String::valueOf).collect(Collectors.toList()))); + insuranceAccountDetailPO.setTenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY); + insuranceAccountDetailPO.setResourceFrom(ResourceFromEnum.SYSTEM.getValue()); + //缴纳组织=个税扣缴义务人 + insuranceAccountDetailPO.setSocialPayOrg(baseParam.getPaymentOrganization()); + if (projects.contains(ProjectTypeEnum.ALL.getValue())) { + if ("2".equals(baseParam.getSupplementType())) { + if (accountPO.getSocial() != null) { + accountPO.getSocial().setSocialPaymentBaseString(baseParam.getSocialPaymentBaseString()); + } + if (accountPO.getFund() != null) { + accountPO.getFund().setFundPaymentBaseString(baseParam.getFundPaymentBaseString()); + } + if (accountPO.getOther() != null) { + accountPO.getOther().setOtherPaymentBaseString(baseParam.getOtherPaymentBaseString()); + } + accountSocial(insuranceAccountDetailPO, accountPO, baseParam.getSupplementaryMonth()); + accountFund(insuranceAccountDetailPO, accountPO, baseParam.getSupplementaryMonth()); + accountOther(insuranceAccountDetailPO, accountPO, baseParam.getSupplementaryMonth()); + } else if ("3".equals(baseParam.getSupplementType())) { + accountSupSocialByData(insuranceAccountDetailPO, baseParam); + accountSupFundByData(insuranceAccountDetailPO, baseParam); + accountSupOtherByData(insuranceAccountDetailPO, baseParam); + } else { + accountSocial(insuranceAccountDetailPO, accountPO, baseParam.getSupplementaryMonth()); + accountFund(insuranceAccountDetailPO, accountPO, baseParam.getSupplementaryMonth()); + accountOther(insuranceAccountDetailPO, accountPO, baseParam.getSupplementaryMonth()); + } + + return account(insuranceAccountDetailPO); + } + if (projects.contains(ProjectTypeEnum.SOCIAL.getValue())) { + if ("2".equals(baseParam.getSupplementType())) { + if (accountPO.getSocial() != null) { + accountPO.getSocial().setSocialPaymentBaseString(baseParam.getSocialPaymentBaseString()); + } + accountSocial(insuranceAccountDetailPO, accountPO, baseParam.getSupplementaryMonth()); + } else if ("3".equals(baseParam.getSupplementType())) { + accountSupSocialByData(insuranceAccountDetailPO, baseParam); + } else { + accountSocial(insuranceAccountDetailPO, accountPO, baseParam.getSupplementaryMonth()); + } + + } + if (!projects.contains(ProjectTypeEnum.SOCIAL.getValue())) { + List ids = new ArrayList<>(); + List list = getICategoryMapper().listByDataType(DataTypeEnum.SYSTEM.getValue()); + + if (projects.contains(ProjectTypeEnum.ENDOWMENT_INSURANCE.getValue())) { + ICategoryPO insuranceCategoryPO = list.stream().filter(item -> SalaryI18nUtil.getI18nLabel(0, "养老保险").equals(item.getInsuranceName())).findFirst() + .get(); + ids.add(insuranceCategoryPO.getId()); + } + if (projects.contains(ProjectTypeEnum.MEDICAL_INSURANCE.getValue())) { + ICategoryPO insuranceCategoryPO = list.stream().filter(item -> SalaryI18nUtil.getI18nLabel(0, "医疗保险").equals(item.getInsuranceName())).findFirst() + .get(); + ids.add(insuranceCategoryPO.getId()); + } + if ("2".equals(baseParam.getSupplementType())) { + if (accountPO.getSocial() != null) { + accountPO.getSocial().setSocialPaymentBaseString(baseParam.getSocialPaymentBaseString()); + } + accountEndowmentInsurance(insuranceAccountDetailPO, accountPO, ids, baseParam.getSupplementaryMonth()); + } else if ("3".equals(baseParam.getSupplementType())) { + accountSupEndowmentInsuranceByData(insuranceAccountDetailPO, baseParam, ids); + } else { + accountEndowmentInsurance(insuranceAccountDetailPO, accountPO, ids, baseParam.getSupplementaryMonth()); + } + + } + if (projects.contains(ProjectTypeEnum.FUND.getValue())) { + if ("2".equals(baseParam.getSupplementType())) { + if (accountPO.getFund() != null) { + accountPO.getFund().setFundPaymentBaseString(baseParam.getFundPaymentBaseString()); + } + accountFund(insuranceAccountDetailPO, accountPO, baseParam.getSupplementaryMonth()); + } else if ("3".equals(baseParam.getSupplementType())) { + accountSupFundByData(insuranceAccountDetailPO, baseParam); + } else { + accountFund(insuranceAccountDetailPO, accountPO, baseParam.getSupplementaryMonth()); + } + } + if (projects.contains(ProjectTypeEnum.OTHER.getValue())) { + + if ("2".equals(baseParam.getSupplementType())) { + if (accountPO.getOther() != null) { + accountPO.getOther().setOtherPaymentBaseString(baseParam.getOtherPaymentBaseString()); + } + accountOther(insuranceAccountDetailPO, accountPO, baseParam.getSupplementaryMonth()); + } else if ("3".equals(baseParam.getSupplementType())) { + accountSupOtherByData(insuranceAccountDetailPO, baseParam); + } else { + accountOther(insuranceAccountDetailPO, accountPO, baseParam.getSupplementaryMonth()); + } + + } + + return account(insuranceAccountDetailPO); + } + + public void accountSupFundByData(InsuranceAccountDetailPO insuranceAccountDetailPO, SupplementAccountBaseParam baseParam) { + //公积金个人 + if (StringUtils.isNotBlank(baseParam.getFundPaymentPerString())) { + List fundPer = new ArrayList<>(); + HashMap fundPerson = JSON.parseObject(baseParam.getFundPaymentPerString(), new HashMap().getClass()); + fundPerson.forEach((k, v) -> { + BigDecimal result = new BigDecimal(v); + fundPer.add(result); + }); + insuranceAccountDetailPO.setFundPerJson(baseParam.getFundPaymentPerString()); + BigDecimal fundPerSum = new BigDecimal("0"); + for (BigDecimal bigDecimal : fundPer) { + fundPerSum = fundPerSum.add(bigDecimal); + } + insuranceAccountDetailPO.setFundPerSum(fundPerSum.toPlainString()); + } + //公积金单位 + if (StringUtils.isNotBlank(baseParam.getFundPaymentComString())) { + List fundCom = new ArrayList<>(); + HashMap fundComMap = JSON.parseObject(baseParam.getFundPaymentComString(), new HashMap().getClass()); + fundComMap.forEach((k, v) -> { + BigDecimal result = new BigDecimal(v); + fundCom.add(result); + }); + insuranceAccountDetailPO.setFundComJson(baseParam.getFundPaymentComString()); + BigDecimal fundComSum = new BigDecimal("0"); + for (BigDecimal bigDecimal : fundCom) { + fundComSum = fundComSum.add(bigDecimal); + } + insuranceAccountDetailPO.setFundComSum(fundComSum.toPlainString()); + } + } + + public void accountSupOtherByData(InsuranceAccountDetailPO insuranceAccountDetailPO, SupplementAccountBaseParam baseParam) { + //其他福利个人 + if (StringUtils.isNotBlank(baseParam.getOtherPaymentPerString())) { + List otherPer = new ArrayList<>(); + HashMap otherPerMap = JSON.parseObject(baseParam.getOtherPaymentPerString(), new HashMap().getClass()); + otherPerMap.forEach((k, v) -> { + BigDecimal result = new BigDecimal(v); + otherPer.add(result); + }); + insuranceAccountDetailPO.setOtherPerJson(baseParam.getOtherPaymentPerString()); + BigDecimal otherPerSum = new BigDecimal("0"); + for (BigDecimal bigDecimal : otherPer) { + otherPerSum = otherPerSum.add(bigDecimal); + } + insuranceAccountDetailPO.setOtherPerSum(otherPerSum.toPlainString()); + } + //其他福利单位 + if (StringUtils.isNotBlank(baseParam.getOtherPaymentComString())) { + List otherCom = new ArrayList<>(); + HashMap otherComMap = JSON.parseObject(baseParam.getOtherPaymentComString(), new HashMap().getClass()); + otherComMap.forEach((k, v) -> { + BigDecimal result = new BigDecimal(v); + otherCom.add(result); + }); + insuranceAccountDetailPO.setOtherComJson(baseParam.getOtherPaymentComString()); + BigDecimal otherComSum = new BigDecimal("0"); + for (BigDecimal bigDecimal : otherCom) { + otherComSum = otherComSum.add(bigDecimal); + } + insuranceAccountDetailPO.setOtherComSum(otherComSum.toPlainString()); + } + } + + public void accountSupSocialByData(InsuranceAccountDetailPO insuranceAccountDetailPO, SupplementAccountBaseParam baseParam) { + //社保个人 + if (StringUtils.isNotBlank(baseParam.getSocialPaymentPerString())) { + List socialPer = new ArrayList<>(); + HashMap archivesPerson = JSON.parseObject(baseParam.getSocialPaymentPerString(), new HashMap().getClass()); + archivesPerson.forEach((k, v) -> { + BigDecimal result = new BigDecimal(v); + socialPer.add(result); + }); + insuranceAccountDetailPO.setSocialPerJson(baseParam.getSocialPaymentPerString()); + BigDecimal socialPerSum = new BigDecimal("0"); + for (BigDecimal bigDecimal : socialPer) { + socialPerSum = socialPerSum.add(bigDecimal); + } + insuranceAccountDetailPO.setSocialPerSum(socialPerSum.toPlainString()); + } + //社保单位 + if (StringUtils.isNotBlank(baseParam.getSocialPaymentComString())) { + List socialCom = new ArrayList<>(); + HashMap archivesCom = JSON.parseObject(baseParam.getSocialPaymentComString(), new HashMap().getClass()); + archivesCom.forEach((k, v) -> { + BigDecimal result = new BigDecimal(v); + socialCom.add(result); + }); + insuranceAccountDetailPO.setSocialComJson(baseParam.getSocialPaymentComString()); + BigDecimal socialComSum = new BigDecimal("0"); + for (BigDecimal bigDecimal : socialCom) { + socialComSum = socialComSum.add(bigDecimal); + } + insuranceAccountDetailPO.setSocialComSum(socialComSum.toPlainString()); + } + } + + public InsuranceAccountDetailPO accountEndowmentInsurance(InsuranceAccountDetailPO insuranceAccountDetailPO, InsuranceArchivesAccountPO accountPO, List categoryIds, String billMonth) { + if (accountPO.getSocial() != null) { + InsuranceArchivesSocialSchemePO socialPO = accountPO.getSocial(); + insuranceAccountDetailPO.setSocialPayOrg(socialPO.getPaymentOrganization()); + insuranceAccountDetailPO.setSocialAccount(socialPO.getSocialAccount()); + insuranceAccountDetailPO.setSocialSchemeId(socialPO.getSocialSchemeId()); + insuranceAccountDetailPO.setSocialPaymentBaseString(socialPO.getSocialPaymentBaseString()); + insuranceAccountDetailPO.setSocialPaymentComBaseString(socialPO.getSocialPaymentComBaseString()); + //判断是否在起始缴纳月和最后缴纳月之间 + Boolean inDataRange = SalaryDateUtil.monthInRange(billMonth, socialPO.getSocialStartTime(), socialPO.getSocialEndTime()); + + if ((Objects.equals(NonPaymentEnum.YES.getValue(), socialPO.getNonPayment()) || socialPO.getNonPayment() == null) && socialPO.getSocialSchemeId() != null && inDataRange) { + List detailPOS = getInsuranceSchemeDetailMapper().queryListBySchemeId(socialPO.getSocialSchemeId()); + encryptUtil.decryptList(detailPOS, InsuranceSchemeDetailPO.class); + //方案中包含的需要缴纳社保的个人福利 + int monthIndex = Integer.parseInt(billMonth.split("-")[1]) - 1; + Map schemeperson = detailPOS.stream() + .filter(item -> Objects.equals(IsPaymentEnum.YES.getValue(), item.getIsPayment()) + && Objects.equals(item.getPaymentScope(), PaymentScopeEnum.SCOPE_PERSON.getValue()) + && (item.getPaymentCycle() == null || item.getPaymentCycle() == 0 || (item.getPaymentCycle() == 1 && String.valueOf(item.getCycleSetting().charAt(monthIndex)).equals("1")))) + .collect( + Collectors.toMap(InsuranceSchemeDetailPO::getInsuranceId, Function.identity())); + //档案中包含的基数信息 + HashMap archivesPerson = JSON.parseObject(socialPO.getSocialPaymentBaseString(), new HashMap().getClass()); + //需要核算社保的福利id 个人 + List needArchivesPerson = new ArrayList<>(); + if (archivesPerson != null) { + categoryIds.forEach(item -> { + if (archivesPerson.containsKey(String.valueOf(item)) && schemeperson.containsKey(item)) { + if (StringUtils.isNotBlank(archivesPerson.get(String.valueOf(item)))) { + needArchivesPerson.add(item); + } + } + }); + } + //判断核算周期、核算月、福利起始缴纳月的关系 + checkCycleSettingWithStartMonth(schemeperson, billMonth, socialPO.getSocialStartTime()); + + List socialPer = new ArrayList<>(); + Map socialPerJsonMap = new HashMap<>(); + needArchivesPerson.forEach(e -> { + InsuranceSchemeDetailPO po = schemeperson.get(e); + BigDecimal paymentProportion = new BigDecimal(po.getPaymentProportion()).divide(new BigDecimal("100")); + BigDecimal paymentNum = new BigDecimal((ObjectUtils.isEmpty(archivesPerson) || StringUtils.isBlank(archivesPerson.get(String.valueOf(e)))) ? "0" : archivesPerson.get(String.valueOf(e))); + BigDecimal fixedCost = StringUtils.isBlank(po.getFixedCost()) ? new BigDecimal("0") : new BigDecimal(po.getFixedCost()); + Integer newScale = po.getValidNum() == null ? 0 : po.getValidNum(); + BigDecimal result = new BigDecimal("0"); + if (Objects.equals(po.getPaymentCycle(), 1)) { + int monthValue = 1; + for (int i = monthIndex - 1; i >= 0; i--) { + String cycleValue = po.getCycleSetting().charAt(i) + ""; + if (Integer.parseInt(cycleValue) == 1) { + break; + } + monthValue++; + } + if (po.getAccountType() == 1) { + paymentNum = paymentNum.multiply(new BigDecimal(monthValue)); + fixedCost = fixedCost.multiply(new BigDecimal(monthValue)); + result = SalaryEntityUtil.carryRule(newScale, po.getRententionRule(), paymentNum.multiply(paymentProportion).add(fixedCost)); + } else { + for (int i = 0; i < monthValue; i++) { + result = result.add(SalaryEntityUtil.carryRule(newScale, po.getRententionRule(), paymentNum.multiply(paymentProportion).add(fixedCost))); + } + } + } else { + result = SalaryEntityUtil.carryRule(newScale, po.getRententionRule(), paymentNum.multiply(paymentProportion).add(fixedCost)); + } + socialPerJsonMap.put(String.valueOf(e), result.toPlainString()); + socialPer.add(result); + }); + insuranceAccountDetailPO.setSocialPerJson(JSON.toJSONString(socialPerJsonMap)); + BigDecimal socialPerSum = new BigDecimal("0"); + for (BigDecimal bigDecimal : socialPer) { + socialPerSum = socialPerSum.add(bigDecimal); + } + insuranceAccountDetailPO.setSocialPerSum(socialPerSum.toPlainString()); + //方案中包含的需要缴纳社保的单位福利 + Map schemeCom = detailPOS.stream() + .filter(item -> Objects.equals(IsPaymentEnum.YES.getValue(), item.getIsPayment()) && Objects.equals(item.getPaymentScope(), PaymentScopeEnum.SCOPE_COMPANY.getValue()) && + (item.getPaymentCycle() == null || item.getPaymentCycle() == 0 || (item.getPaymentCycle() == 1 && String.valueOf(item.getCycleSetting().charAt(monthIndex)).equals("1")))) + .collect( + Collectors.toMap(InsuranceSchemeDetailPO::getInsuranceId, Function.identity())); + //档案中包含的基数信息 + HashMap archivesCom = JSON.parseObject(socialPO.getSocialPaymentBaseString(), new HashMap().getClass()); + //需要核算社保的福利id 单位 + List needArchivesCom = new ArrayList<>(); + if (archivesCom != null) { + categoryIds.forEach(item -> { + if (archivesCom.containsKey(String.valueOf(item)) && schemeCom.containsKey(item)) { + if (StringUtils.isNotBlank(archivesCom.get(String.valueOf(item)))) { + needArchivesCom.add(item); + } + } + }); + //判断核算周期、核算月、福利起始缴纳月的关系 + checkCycleSettingWithStartMonth(schemeCom, billMonth, socialPO.getSocialStartTime()); + } + List socialCom = new ArrayList<>(); + Map sociaComJsonMap = new HashMap<>(); + needArchivesCom.forEach(e -> { + InsuranceSchemeDetailPO po = schemeCom.get(e); + BigDecimal paymentProportion = new BigDecimal(po.getPaymentProportion()).divide(new BigDecimal("100")); + BigDecimal paymentNum = new BigDecimal((ObjectUtils.isEmpty(archivesCom) || StringUtils.isBlank(archivesCom.get(String.valueOf(e)))) ? "0" : archivesCom.get(String.valueOf(e))); + BigDecimal fixedCost = StringUtils.isBlank(po.getFixedCost()) ? new BigDecimal("0") : new BigDecimal(po.getFixedCost()); + Integer newScale = po.getValidNum() == null ? 0 : po.getValidNum(); + BigDecimal result = new BigDecimal("0"); + if (Objects.equals(po.getPaymentCycle(), 1)) { + int monthValue = 1; + for (int i = monthIndex - 1; i >= 0; i--) { + String cycleValue = po.getCycleSetting().charAt(i) + ""; + if (Integer.parseInt(cycleValue) == 1) { + break; + } + monthValue++; + } + if (po.getAccountType() == 1) { + paymentNum = paymentNum.multiply(new BigDecimal(monthValue)); + fixedCost = fixedCost.multiply(new BigDecimal(monthValue)); + result = SalaryEntityUtil.carryRule(newScale, po.getRententionRule(), paymentNum.multiply(paymentProportion).add(fixedCost)); + } else { + for (int i = 0; i < monthValue; i++) { + result = result.add(SalaryEntityUtil.carryRule(newScale, po.getRententionRule(), paymentNum.multiply(paymentProportion).add(fixedCost))); + } + } + } else { + result = SalaryEntityUtil.carryRule(newScale, po.getRententionRule(), paymentNum.multiply(paymentProportion).add(fixedCost)); + } + + sociaComJsonMap.put(String.valueOf(e), result.toPlainString()); + socialCom.add(result); + + }); + insuranceAccountDetailPO.setSocialComJson(JSON.toJSONString(sociaComJsonMap)); + BigDecimal socialComSum = new BigDecimal("0"); + for (BigDecimal decimal : socialCom) { + socialComSum = socialComSum.add(decimal); + } + insuranceAccountDetailPO.setSocialComSum(socialComSum.toPlainString()); + } + } + return insuranceAccountDetailPO; + } + + public void accountSupEndowmentInsuranceByData(InsuranceAccountDetailPO insuranceAccountDetailPO, SupplementAccountBaseParam baseParam, List ids) { + //社保个人 + if (StringUtils.isNotBlank(baseParam.getSocialPaymentPerString())) { + List socialPer = new ArrayList<>(); + HashMap archivesPerson = JSON.parseObject(baseParam.getSocialPaymentPerString(), new HashMap().getClass()); + HashMap socialPerson = new HashMap<>(); + archivesPerson.forEach((k, v) -> { + if (ids.contains(Long.valueOf(k))) { + socialPerson.put(k, v); + BigDecimal result = new BigDecimal(v); + socialPer.add(result); + } + + }); + insuranceAccountDetailPO.setSocialPerJson(JSON.toJSONString(socialPerson)); + BigDecimal socialPerSum = new BigDecimal("0"); + for (BigDecimal bigDecimal : socialPer) { + socialPerSum = socialPerSum.add(bigDecimal); + } + insuranceAccountDetailPO.setSocialPerSum(socialPerSum.toPlainString()); + } + //社保单位 + if (StringUtils.isNotBlank(baseParam.getSocialPaymentComString())) { + List socialCom = new ArrayList<>(); + HashMap archivesCom = JSON.parseObject(baseParam.getSocialPaymentComString(), new HashMap().getClass()); + HashMap socialComMap = new HashMap<>(); + archivesCom.forEach((k, v) -> { + if (ids.contains(Long.valueOf(k))) { + socialComMap.put(k, v); + BigDecimal result = new BigDecimal(v); + socialCom.add(result); + } + }); + insuranceAccountDetailPO.setSocialComJson(JSON.toJSONString(socialComMap)); + BigDecimal socialComSum = new BigDecimal("0"); + for (BigDecimal bigDecimal : socialCom) { + socialComSum = socialComSum.add(bigDecimal); + } + insuranceAccountDetailPO.setSocialComSum(socialComSum.toPlainString()); + } + } + + public void batchSaveSupplementAccount(List pos) { + if (CollectionUtils.isEmpty(pos)) { + return; + } + batchSaveAccountInspectDetail(pos); + getInsuranceAccountDetailMapper().batchDelSupplementAccountDetails(pos); + encryptUtil.encryptList(pos, InsuranceAccountDetailPO.class); + List> lists = splitDetailList(pos, 20); + lists.forEach(subList -> { + getInsuranceAccountDetailMapper().batchSaveAccountDetails(subList); + }); + //删除日志 +// pos.stream().forEach(item -> { +// LoggerContext insuranceSchemeContext = new LoggerContext(); +// insuranceSchemeContext.setTargetId(String.valueOf(item.getId())); +// insuranceSchemeContext.setTargetName(String.valueOf(item.getEmployeeId())); +// insuranceSchemeContext.setOperateType(OperateTypeEnum.DELETE.getValue()); +// insuranceSchemeContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(100448, "删除核算记录")); +// insuranceSchemeContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(100448, "删除核算记录")); +// insuranceSchemeContext.setNewValues(item); +// siAccountLoggerTemplate.write(insuranceSchemeContext); +// }); + //插入日志 +// pos.stream().forEach(item -> { +// LoggerContext insuranceSchemeContext = new LoggerContext(); +// insuranceSchemeContext.setTargetId(String.valueOf(item.getId())); +// insuranceSchemeContext.setTargetName(String.valueOf(item.getEmployeeId())); +// insuranceSchemeContext.setOperateType(OperateTypeEnum.ADD.getValue()); +// insuranceSchemeContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(100494, "新建核算记录")); +// insuranceSchemeContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(100494, "新建核算记录")); +// insuranceSchemeContext.setNewValues(item); +// siAccountLoggerTemplate.write(insuranceSchemeContext); +// }); + } + + public void siDeleteCommonAccount(SaveCommonAccountParam param) { + ValidUtil.doValidator(param); + SalaryAssert.notEmpty(param.getIncludes(), SalaryI18nUtil.getI18nLabel(0, "参数错误")); + //根据id批量删除 + if (param.getIds().size() > 0) { + getInsuranceAccountDetailMapper().batchDelAccountDetailsByIds(param.getIds()); + } else { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0, "请勾选需要删除的数据项!")); + } + //记录日志 +// LoggerContext insuranceSchemeContext = new LoggerContext(); +// insuranceSchemeContext.setTargetId(String.join(",", param.getIncludes().stream().map(item -> String.valueOf(item)).collect(Collectors.toList()))); +// insuranceSchemeContext.setTargetName(param.getBillMonth()); +// insuranceSchemeContext.setOperateType(OperateTypeEnum.ADD.getValue()); +// insuranceSchemeContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100462, "新增台账")); +// insuranceSchemeContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100462, "新增台账")); +// insuranceSchemeContext.setNewValues(param); +// siAccountLoggerTemplate.write(insuranceSchemeContext); + updateBatchAccount(AccountParam.builder().billMonth(param.getBillMonth()).paymentOrganization(param.getPaymentOrganization()).build()); + } + + public void siDeleteSupplementaryAccount(List param) { + SalaryAssert.notEmpty(param, SalaryI18nUtil.getI18nLabel(0, "参数错误")); + boolean valid = param.stream().anyMatch(item -> item.getEmployeeId() == null + || StringUtils.isBlank(item.getSupplementaryMonth()) + || StringUtils.isBlank(item.getBillMonth())); + if (valid) { + throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0, "参数错误")); + } + getInsuranceAccountDetailMapper().batchDelSupplementDetailsByIds(param); +// param.stream().forEach(item -> { +// LoggerContext insuranceSchemeContext = new LoggerContext(); +// insuranceSchemeContext.setTargetName(item.getBillMonth()); +// insuranceSchemeContext.setOperateType(OperateTypeEnum.DELETE.getValue()); +// insuranceSchemeContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100490, "删除补缴核算记录")); +// insuranceSchemeContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100490, "删除补缴核算记录")); +// insuranceSchemeContext.setNewValues(item); +// siAccountLoggerTemplate.write(insuranceSchemeContext); +// }); + updateBatchAccount(AccountParam.builder().billMonth(param.get(0).getBillMonth()).paymentOrganization(param.get(0).getPaymentOrganization()).build()); + } + + public void accountInspect(Collection ids, String billMonth, Long paymentOrganization) { + List insuranceAccountInspectPOS = allInspects(ids, billMonth); + SalaryAssert.notEmpty(insuranceAccountInspectPOS, SalaryI18nUtil.getI18nLabel(0, "无核算数据")); + List commonInspects = insuranceAccountInspectPOS.stream() + .filter(e -> Objects.equals(e.getPaymentStatus(), PaymentStatusEnum.COMMON.getValue())) + .collect(Collectors.toList()); + List supplementInspects = insuranceAccountInspectPOS.stream() + .filter(e -> Objects.equals(e.getPaymentStatus(), PaymentStatusEnum.REPAIR.getValue())) + .collect(Collectors.toList()); + //核算正常缴纳 + if (CollectionUtils.isNotEmpty(commonInspects)) { + SaveCommonAccountParam param = new SaveCommonAccountParam(); + param.setBillMonth(billMonth); + param.setIncludes(commonInspects.stream().map(InsuranceAccountInspectPO::getEmployeeId).collect(Collectors.toList())); + siSaveCommonAccount(param); + } + //核算补缴 + if (CollectionUtils.isNotEmpty(supplementInspects)) { + List baseList = new ArrayList<>(); + supplementInspects.forEach(e -> { + SupplementAccountBaseParam base = new SupplementAccountBaseParam(); + base.setBillMonth(billMonth); + base.setProjects( + e.getSupplementaryProjects() == null ? null : Arrays.stream(e.getSupplementaryProjects().split(",")).map(Integer::valueOf).collect(Collectors.toList())); + base.setEmployeeId(e.getEmployeeId()); + base.setSupplementaryMonth(e.getSupplementaryMonth()); + baseList.add(base); + }); + accountSupplement(baseList, baseList.stream().map(SupplementAccountBaseParam::getEmployeeId).collect(Collectors.toList()), paymentOrganization); + } + } + + public PageInfo siOverView(InsuranceAccountDetailParam queryParam) { + + List insuranceAccountDetailPOS = getInsuranceAccountDetailMapper().selectList(queryParam.getBillMonth(), StringUtil.isBlank(queryParam.getPaymentOrganization()) ? null : Long.valueOf(queryParam.getPaymentOrganization())); + encryptUtil.decryptList(insuranceAccountDetailPOS, InsuranceAccountDetailPO.class); + //获取扣缴义务人信息 + List paymentList = getTaxAgentMapper().listAll(); + SalaryAssert.notEmpty(paymentList, SalaryI18nUtil.getI18nLabel(0, "该租户无扣缴义务人")); + Map paymentMap = paymentList.stream().collect(Collectors.toMap(TaxAgentPO::getId, Function.identity())); + List insuranceAccountViewListDTOS = buildRecords(insuranceAccountDetailPOS, paymentMap); + + PageInfo insuranceAccountViewListDTOPage = new PageInfo<>(insuranceAccountViewListDTOS, InsuranceAccountViewListDTO.class); + insuranceAccountViewListDTOPage.setTotal(insuranceAccountViewListDTOS.size()); + return insuranceAccountViewListDTOPage; + } + + @Override + public List buildRecords(List list, Map paymentMap) { + Map result = new HashMap<>(); + //根据组织分组,对社保进行统计 + Map> socialCollect = list.stream().filter(item -> item.getSocialPayOrg() != null) + .collect(Collectors.groupingBy(InsuranceAccountDetailPO::getSocialPayOrg)); + socialCollect.forEach((k, v) -> { + if (result.get(k) == null) { + InsuranceAccountViewListDTO temp = new InsuranceAccountViewListDTO(); + temp.setPayOrg(paymentMap.get(k).getName()); + result.put(k, temp); + } + InsuranceAccountViewListDTO insuranceAccountViewListDTO = result.get(k); + accountSocialView(insuranceAccountViewListDTO, v); + }); + //根据组织分组,对公积金进行统计 + Map> fundCollect = list.stream().filter(item -> item.getSocialPayOrg() != null) + .collect(Collectors.groupingBy(InsuranceAccountDetailPO::getSocialPayOrg)); + fundCollect.forEach((k, v) -> { + if (result.get(k) == null) { + InsuranceAccountViewListDTO temp = new InsuranceAccountViewListDTO(); + temp.setPayOrg(paymentMap.get(k).getName()); + result.put(k, temp); + } + InsuranceAccountViewListDTO insuranceAccountViewListDTO = result.get(k); + accountFundView(insuranceAccountViewListDTO, v); + }); + //根据组织分组,对其他福利进行统计 + Map> otherCollect = list.stream().filter(item -> item.getSocialPayOrg() != null) + .collect(Collectors.groupingBy(InsuranceAccountDetailPO::getSocialPayOrg)); + otherCollect.forEach((k, v) -> { + if (result.get(k) == null) { + InsuranceAccountViewListDTO temp = new InsuranceAccountViewListDTO(); + temp.setPayOrg(paymentMap.get(k).getName()); + result.put(k, temp); + } + InsuranceAccountViewListDTO insuranceAccountViewListDTO = result.get(k); + accountOtherView(insuranceAccountViewListDTO, v); + }); + //对各组织进行金额合计 + List viewDTOS = new ArrayList<>(); + result.forEach((k, v) -> { + BigDecimal socialPaySum = StringUtils.isBlank(v.getSocialPaySum()) ? new BigDecimal("0") : new BigDecimal(v.getSocialPaySum()); + BigDecimal fundPaySum = StringUtils.isBlank(v.getFundPaySum()) ? new BigDecimal("0") : new BigDecimal(v.getFundPaySum()); + BigDecimal otherPaySum = StringUtils.isBlank(v.getOtherPaySum()) ? new BigDecimal("0") : new BigDecimal(v.getOtherPaySum()); + v.setIndex(k); + BigDecimal sum = socialPaySum.add(fundPaySum).add(otherPaySum); + v.setSum(sum.toPlainString()); + viewDTOS.add(v); + }); + //合计 + InsuranceAccountViewListDTO insuranceAccountViewListDTO = new InsuranceAccountViewListDTO(); + int socialNum = 0; + int fundNum = 0; + int otherNum = 0; + BigDecimal socialSum = new BigDecimal("0"); + BigDecimal fundSum = new BigDecimal("0"); + BigDecimal otherSum = new BigDecimal("0"); + BigDecimal sum = new BigDecimal("0"); + for (InsuranceAccountViewListDTO item : viewDTOS) { + if (item.getSocialNum() != null) { + socialNum += item.getSocialNum(); + } + if (item.getFundNum() != null) { + fundNum += item.getFundNum(); + } + if (item.getOtherNum() != null) { + otherNum += item.getOtherNum(); + } + if (StringUtils.isNotBlank(item.getSocialPaySum())) { + socialSum = socialSum.add(new BigDecimal(item.getSocialPaySum())); + } + if (StringUtils.isNotBlank(item.getFundPaySum())) { + fundSum = fundSum.add(new BigDecimal(item.getFundPaySum())); + } + if (StringUtils.isNotBlank(item.getOtherPaySum())) { + otherSum = otherSum.add(new BigDecimal(item.getOtherPaySum())); + } + if (StringUtils.isNotBlank(item.getSum())) { + sum = sum.add(new BigDecimal(item.getSum())); + } + } + insuranceAccountViewListDTO.setSum(sum.toPlainString()); + insuranceAccountViewListDTO.setSocialPaySum(socialSum.toPlainString()); + insuranceAccountViewListDTO.setPayOrg(SalaryI18nUtil.getI18nLabel(0, "合计")); + insuranceAccountViewListDTO.setFundPaySum(fundSum.toPlainString()); + insuranceAccountViewListDTO.setOtherPaySum(otherSum.toPlainString()); + insuranceAccountViewListDTO.setSocialNum(socialNum); + insuranceAccountViewListDTO.setFundNum(fundNum); + insuranceAccountViewListDTO.setOtherNum(otherNum); + viewDTOS.add(insuranceAccountViewListDTO); + viewDTOS.forEach(e -> { + e.setSocialPaySum(StringUtils.isBlank(e.getSocialPaySum()) ? "0" : e.getSocialPaySum()); + e.setSocialNum(e.getSocialNum() == null ? 0 : e.getSocialNum()); + e.setFundNum(e.getFundNum() == null ? 0 : e.getFundNum()); + e.setFundPaySum(StringUtils.isBlank(e.getFundPaySum()) ? "0" : e.getFundPaySum()); + e.setOtherPaySum(StringUtils.isBlank(e.getOtherPaySum()) ? "0" : e.getOtherPaySum()); + e.setOtherNum(e.getOtherNum() == null ? 0 : e.getOtherNum()); + e.setSum(SalaryEntityUtil.thousandthConvert(e.getSum())); + e.setSocialPaySum(SalaryEntityUtil.thousandthConvert(e.getSocialPaySum())); + e.setOtherPaySum(SalaryEntityUtil.thousandthConvert(e.getOtherPaySum())); + e.setFundPaySum(SalaryEntityUtil.thousandthConvert(e.getFundPaySum())); + }); + return viewDTOS; + } + + public void accountOtherView(InsuranceAccountViewListDTO dto, List pos) { + int otherNum = 0; + BigDecimal otherPaySum = new BigDecimal("0"); + for (InsuranceAccountDetailPO item : pos) { + if (StringUtils.isNotBlank(item.getOtherSum()) && SalaryEntityUtil.string2DoubleDefault0(item.getOtherSum()) != 0.0) { + if (!PaymentStatusEnum.BALANCE.getValue().equals(item.getPaymentStatus())) { + otherNum += 1; + } + otherPaySum = otherPaySum.add(new BigDecimal(item.getOtherSum())); + } + } + dto.setOtherNum(otherNum); + dto.setOtherPaySum(otherPaySum.toPlainString()); + } + + public void accountFundView(InsuranceAccountViewListDTO dto, List pos) { + int fundNum = 0; + BigDecimal fundPaySum = new BigDecimal("0"); + for (InsuranceAccountDetailPO item : pos) { + if (StringUtils.isNotBlank(item.getFundSum()) && SalaryEntityUtil.string2DoubleDefault0(item.getFundSum()) != 0.0) { + if (!PaymentStatusEnum.BALANCE.getValue().equals(item.getPaymentStatus())) { + fundNum += 1; + } + fundPaySum = fundPaySum.add(new BigDecimal(item.getFundSum())); + } + } + dto.setFundNum(fundNum); + dto.setFundPaySum(fundPaySum.toPlainString()); + } + + public void accountSocialView(InsuranceAccountViewListDTO dto, List pos) { + int socialNum = 0; + BigDecimal socialPaySum = new BigDecimal("0"); + for (InsuranceAccountDetailPO item : pos) { + if (StringUtils.isNotBlank(item.getSocialSum()) && SalaryEntityUtil.string2DoubleDefault0(item.getSocialSum()) != 0.0 ) { + if (!PaymentStatusEnum.BALANCE.getValue().equals(item.getPaymentStatus())) { + socialNum += 1; + } + socialPaySum = socialPaySum.add(new BigDecimal(item.getSocialSum())); + } + } + dto.setSocialNum(socialNum); + dto.setSocialPaySum(socialPaySum.toPlainString()); + } + + /** + * 查询台账id是否已经薪资核算核算过 + * + * @param param + * @return + */ + public int checkIfBusinessAccounting(InsuranceAccountBatchPO param) { + List list = getSIAccountUtilMapper().checkIfBusinessaccounting(param.getId()); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); + return (int) list.stream().filter( f -> { + String billMonthBySob = sdf.format(convertSalaryMonthToBillMonth(f.getSalaryMonth(), f.getSocialSecurityCycleType())); + return f.getBillmonth().equals(billMonthBySob.substring(0, 7)); + }).count(); + } + + public Date convertSalaryMonthToBillMonth(Date salaryMonth, Integer socialSecurityCycleType) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(salaryMonth); + calendar.add(Calendar.MONTH, socialSecurityCycleType - 3); + return calendar.getTime(); + } + + /** + * 更新薪资台账 + * + * @param param + * @return + */ + public void updateById(InsuranceAccountBatchPO param) { + getInsuranceAccountBatchMapper().updateById(param); + } + + /** + * 更新福利台账 + */ + public void updateByEmployeeIdAndBillMonth(InsuranceAccountDetailPO insuranceAccountDetailPO) { + getInsuranceAccountDetailMapper().updateByEmployeeIdAndBillMonth(insuranceAccountDetailPO); + } + + /*****以上代码为SIAccountBiz中方法逻辑迁移,旨在减少Biz类的使用*****/ + } diff --git a/src/com/engine/salary/service/impl/SIExportServiceImpl.java b/src/com/engine/salary/service/impl/SIExportServiceImpl.java index ac3ec8488..93c929e46 100644 --- a/src/com/engine/salary/service/impl/SIExportServiceImpl.java +++ b/src/com/engine/salary/service/impl/SIExportServiceImpl.java @@ -5,7 +5,6 @@ import com.alibaba.fastjson.TypeReference; import com.cloudstore.eccom.pc.table.WeaTableColumn; import com.engine.common.util.ServiceUtil; import com.engine.core.impl.Service; -import com.engine.salary.biz.SIAccountBiz; import com.engine.salary.biz.SIArchivesBiz; import com.engine.salary.encrypt.EncryptUtil; import com.engine.salary.entity.siaccount.dto.InsuranceAccountViewListDTO; @@ -68,7 +67,7 @@ public class SIExportServiceImpl extends Service implements SIExportService { private EncryptUtil encryptUtil = new EncryptUtil(); - private SIAccountBiz siAccountBiz = new SIAccountBiz(); +// private SIAccountBiz siAccountBiz = new SIAccountBiz(); private SIArchivesBiz siArchivesBiz = new SIArchivesBiz(); @@ -117,7 +116,8 @@ public class SIExportServiceImpl extends Service implements SIExportService { List paymentList =getTaxAgentMapper().listAll(); SalaryAssert.notEmpty(paymentList, SalaryI18nUtil.getI18nLabel(100341, "该租户无扣缴义务人")); Map paymentMap = paymentList.stream().collect(Collectors.toMap(TaxAgentPO::getId, Function.identity())); - List insuranceAccountViewListDTOS = siAccountBiz.buildRecords(insuranceAccountDetailPOS, paymentMap); +// List insuranceAccountViewListDTOS = siAccountBiz.buildRecords(insuranceAccountDetailPOS, paymentMap); + List insuranceAccountViewListDTOS = getSIAccountService(user).buildRecords(insuranceAccountDetailPOS, paymentMap); List> excelSheetData = new ArrayList<>(); // 1.工作簿名称 diff --git a/src/com/engine/salary/timer/AutoSiAccountAndFileJob.java b/src/com/engine/salary/timer/AutoSiAccountAndFileJob.java index 7d1b8f757..646024f3d 100644 --- a/src/com/engine/salary/timer/AutoSiAccountAndFileJob.java +++ b/src/com/engine/salary/timer/AutoSiAccountAndFileJob.java @@ -77,7 +77,6 @@ public class AutoSiAccountAndFileJob extends BaseCronJob { user.setLastname("sysadmin"); Calendar accountTime= Calendar.getInstance(); -// prevMonth.setTimeInMillis(System.currentTimeMillis()); accountTime.set(Calendar.MONTH, accountTime.get(Calendar.MONTH) + Integer.parseInt(diffToCurrentMonth)); SimpleDateFormat s=new SimpleDateFormat("yyyy-MM"); diff --git a/src/com/engine/salary/web/SIExportController.java b/src/com/engine/salary/web/SIExportController.java index a37cd05c8..f3636c8dd 100644 --- a/src/com/engine/salary/web/SIExportController.java +++ b/src/com/engine/salary/web/SIExportController.java @@ -2,7 +2,6 @@ package com.engine.salary.web; import cn.hutool.core.util.BooleanUtil; import com.engine.common.util.ServiceUtil; -import com.engine.salary.biz.SIAccountBiz; import com.engine.salary.entity.siaccount.param.InspectAccountParam; import com.engine.salary.entity.siaccount.po.InsuranceAccountInspectPO; import com.engine.salary.entity.siarchives.param.InsuranceArchivesListParam; @@ -85,8 +84,9 @@ public class SIExportController { @QueryParam("ids")List ids,@QueryParam("billMonth") String billMonth) { InspectAccountParam param = InspectAccountParam.builder().ids(ids).billMonth(billMonth).build(); User user = HrmUserVarify.getUser(request, response); - SIAccountBiz siAccountBiz = new SIAccountBiz(); - List insuranceAccountInspectPOS = siAccountBiz.allInspects(param.getIds(), param.getBillMonth()); +// SIAccountBiz siAccountBiz = new SIAccountBiz(); +// List insuranceAccountInspectPOS = siAccountBiz.allInspects(param.getIds(), param.getBillMonth()); + List insuranceAccountInspectPOS = getService(user).allInspects(param.getIds(), param.getBillMonth()); InsuranceArchivesListParam req = new InsuranceArchivesListParam(); req.setEmployeeIds(insuranceAccountInspectPOS.stream().map(InsuranceAccountInspectPO::getEmployeeId).distinct().collect(Collectors.toList())); XSSFWorkbook workbook = getSIExportWrapper(user).export(req); @@ -236,12 +236,13 @@ public class SIExportController { @Produces(MediaType.APPLICATION_OCTET_STREAM) public Response exportTemplate(@Context HttpServletRequest request, @Context HttpServletResponse response) { InsuranceArchivesListParam param = buildParam(request); - SIAccountBiz siAccountBiz = new SIAccountBiz(); + User user = HrmUserVarify.getUser(request, response); +// SIAccountBiz siAccountBiz = new SIAccountBiz(); if (param.getInspectAll() != null && param.getInspectAll()) { - List insuranceAccountInspectPOS = siAccountBiz.allInspects(param.getIds(), param.getBillMonth()); +// List insuranceAccountInspectPOS = siAccountBiz.allInspects(param.getIds(), param.getBillMonth()); + List insuranceAccountInspectPOS = getService(user).allInspects(param.getIds(), param.getBillMonth()); param.setEmployeeIds(insuranceAccountInspectPOS.stream().map(InsuranceAccountInspectPO::getEmployeeId).distinct().collect(Collectors.toList())); } - User user = HrmUserVarify.getUser(request, response); XSSFWorkbook workbook = getSIImportWrapper(user).exportTemplate(param); String time = LocalDate.now().toString(); String fileName = "";