package com.engine.salary.biz; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.TypeReference; import com.api.formmode.mybatis.util.SqlProxyHandle; import com.engine.common.util.ServiceUtil; import com.engine.core.impl.Service; import com.engine.salary.cache.SalaryCacheKey; import com.engine.salary.constant.SalaryDefaultTenantConstant; import com.engine.salary.encrypt.AESEncryptUtil; import com.engine.salary.encrypt.EncryptUtil; import com.engine.salary.entity.datacollection.DataCollectionEmployee; import com.engine.salary.entity.salaryacct.dto.SalaryAcctProgressDTO; import com.engine.salary.entity.siaccount.dto.InsuranceAccountViewListDTO; import com.engine.salary.entity.siaccount.dto.SIAccountUtilDTO; import com.engine.salary.entity.siaccount.param.*; import com.engine.salary.entity.siaccount.po.*; import com.engine.salary.entity.siarchives.po.*; import com.engine.salary.entity.sicategory.po.ICategoryPO; import com.engine.salary.entity.sischeme.po.InsuranceSchemeDetailPO; import com.engine.salary.entity.taxagent.po.TaxAgentPO; import com.engine.salary.enums.siaccount.*; import com.engine.salary.enums.sicategory.*; import com.engine.salary.exception.SalaryRunTimeException; import com.engine.salary.mapper.datacollection.EmployMapper; import com.engine.salary.mapper.siaccount.*; import com.engine.salary.mapper.siarchives.InsuranceBaseInfoMapper; import com.engine.salary.mapper.sicategory.ICategoryMapper; import com.engine.salary.mapper.sischeme.InsuranceSchemeDetailMapper; import com.engine.salary.mapper.taxagent.TaxAgentMapper; import com.engine.salary.service.SalaryAcctProgressService; import com.engine.salary.service.SalaryEmployeeService; import com.engine.salary.service.TaxAgentService; import com.engine.salary.service.impl.SalaryAcctProgressServiceImpl; import com.engine.salary.service.impl.SalaryEmployeeServiceImpl; import com.engine.salary.service.impl.TaxAgentServiceImpl; import com.engine.salary.sys.entity.vo.OrderRuleVO; import com.engine.salary.sys.service.SalarySysConfService; import com.engine.salary.sys.service.impl.SalarySysConfServiceImpl; import com.engine.salary.util.SalaryAssert; import com.engine.salary.util.SalaryDateUtil; 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.PageInfo; import com.engine.salary.util.page.SalaryPageUtil; import com.engine.salary.util.valid.ValidUtil; import com.google.common.collect.Lists; import com.wbi.util.StringUtil; import dm.jdbc.util.IdGenerator; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import weaver.hrm.User; import java.math.BigDecimal; import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.function.Function; import java.util.regex.Pattern; import java.util.stream.Collectors; /** * @Author weaver_cl * @Description: * @Date 2022/4/11 * @Version V1.0 **/ @Slf4j public class SIAccountBiz extends Service { private SIArchivesBiz siArchivesBiz = new SIArchivesBiz(); private EncryptUtil encryptUtil = new EncryptUtil(); private TaxAgentService getTaxAgentService() { return ServiceUtil.getService(TaxAgentServiceImpl.class, user); } private SalaryEmployeeService getSalaryEmployeeService() { return ServiceUtil.getService(SalaryEmployeeServiceImpl.class, user); } private InsuranceAccountBatchMapper getInsuranceAccountBatchMapper() { return SqlProxyHandle.getProxy(InsuranceAccountBatchMapper.class); } private InsuranceAccountDetailMapper getInsuranceAccountDetailMapper() { return SqlProxyHandle.getProxy(InsuranceAccountDetailMapper.class); } private SIAccountUtilMapper getSIAccountUtilMapper() { return MapperProxyFactory.getProxy(SIAccountUtilMapper.class); } private InsuranceAccountInspectMapper getInsuranceAccountInspectMapper() { return MapperProxyFactory.getProxy(InsuranceAccountInspectMapper.class); } private InsuranceBaseInfoMapper getInsuranceBaseInfoMapper() { return MapperProxyFactory.getProxy(InsuranceBaseInfoMapper.class); } private SalarySysConfService getSalarySysConfService(User user) { return ServiceUtil.getService(SalarySysConfServiceImpl.class, user); } private InsuranceCompensationMapper getInsuranceCompensationMapper() { return MapperProxyFactory.getProxy(InsuranceCompensationMapper.class); } private SalaryAcctProgressService getSalaryAcctProgressService(User user) { return (SalaryAcctProgressService) ServiceUtil.getService(SalaryAcctProgressServiceImpl.class, user); } public PageInfo listPage(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 listCommonPage(InsuranceAccountDetailParam queryParam) { queryParam.setPaymentStatus(PaymentStatusEnum.COMMON.getValue()); //过滤出需要核算的人员,即福利档案基础信息表中runStatus为正在缴纳和待减员的人员 List baseInfoPOList = getInsuranceBaseInfoMapper().listAll(); List canAccountIds = baseInfoPOList.stream() .filter(f->f.getPaymentOrganization().toString().equals(queryParam.getPaymentOrganization()) && (f.getRunStatus().equals(EmployeeStatusEnum.PAYING.getValue()) || f.getRunStatus().equals(EmployeeStatusEnum.STAY_DEL.getValue()))) .map(InsuranceArchivesBaseInfoPO::getEmployeeId) .collect(Collectors.toList()); queryParam.setEmployeeIds(canAccountIds); //排序配置 OrderRuleVO orderRule = getSalarySysConfService(user).orderRule(); queryParam.setOrderRule(orderRule); List list = getInsuranceAccountDetailMapper().list(queryParam); PageInfo pageInfo = SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(), list, InsuranceAccountDetailPO.class); encryptUtil.decryptList(pageInfo.getList(), InsuranceAccountDetailPO.class); return pageInfo; } public String save(boolean flag, AccountParam param, Long employeeId, String currentUserName) { if (flag) { InsuranceAccountBatchPO insuranceAccountBatchPO = getInsuranceAccountBatchMapper().getByBillMonth(param.getBillMonth(), param.getPaymentOrganization()); insuranceAccountBatchPO = encryptUtil.decrypt(insuranceAccountBatchPO, InsuranceAccountBatchPO.class); SalaryAssert.isNull(insuranceAccountBatchPO, SalaryI18nUtil.getI18nLabel(100461, "所属月份存在核算数据")); InsuranceAccountBatchPO build = InsuranceAccountBatchPO.builder() .paymentOrganization(param.getPaymentOrganization()) .accountant(currentUserName) .billMonth(param.getBillMonth()) .billStatus(BillStatusEnum.NOT_ARCHIVED.getValue()) .remarks(param.getRemarks()) .creator(employeeId) .tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY) .createTime(new Date()) .updateTime(new Date()) .deleteType(DeleteTypeEnum.NOT_DELETED.getValue()) .paymentOrganization(param.getPaymentOrganization()) .socialPay("0") .fundPay("0") .otherPay("0") .build(); encryptUtil.encrypt(build, InsuranceAccountBatchPO.class); getInsuranceAccountBatchMapper().insert(build); // LoggerContext insuranceSchemeContext = new LoggerContext(); // insuranceSchemeContext.setTargetId(String.valueOf(build.getId())); // insuranceSchemeContext.setTargetName(build.getBillMonth()); // insuranceSchemeContext.setOperateType(OperateTypeEnum.ADD.getValue()); // insuranceSchemeContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100462, "新增台账")); // insuranceSchemeContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100462, "新增台账")); // insuranceSchemeContext.setNewValues(build); // siAccountLoggerTemplate.write(insuranceSchemeContext); } try { account(param, employeeId, SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY, currentUserName); } catch (Exception e) { // 回滚 List list = Lists.newArrayList(getInsuranceAccountBatchMapper().getByBillMonth(param.getBillMonth(), param.getPaymentOrganization())); list = encryptUtil.decryptList(list, InsuranceAccountBatchPO.class); if (CollectionUtils.isNotEmpty(list)) { list.stream().forEach(f -> { getInsuranceAccountBatchMapper().deleteById(f.getId()); }); } throw new SalaryRunTimeException(e.getMessage()); } return employeeId.toString(); } public void account(AccountParam param, Long employeeId, String tenantKey, String currentUserName) { // Collection employeeIdsInTaxAgent = getTaxAgentService().listEmployeeIdsInTaxAgent(param.getPaymentOrganization()); Long paymentOrganization = param.getPaymentOrganization(); // List employeeIds = getInsuranceAccountDetailMapper().selectAccountIds(SalaryDateUtil.getMonthBegin(param.getBillMonth()), paymentOrganization); List employeeIds = getInsuranceAccountDetailMapper().selectEmpByPaymentOrg(paymentOrganization); // employeeIds = employeeIds.stream().filter(employeeIdsInTaxAgent::contains).collect(Collectors.toList()); if (CollectionUtils.isEmpty(employeeIds)) { List list = Lists.newArrayList(getInsuranceAccountBatchMapper().getByBillMonth(param.getBillMonth(), paymentOrganization)); encryptUtil.decryptList(list, InsuranceAccountBatchPO.class); if (CollectionUtils.isNotEmpty(list)) { list.stream().forEach(f -> { getInsuranceAccountDetailMapper().deleteById(f.getId()); }); } } SalaryAssert.notEmpty(employeeIds, "没有需要核算的人员"); AccountParam selectParam = new AccountParam(); selectParam.setBillMonth(param.getBillMonth()); selectParam.setPaymentOrganization(paymentOrganization); ExecutorService taskExecutor = Executors.newCachedThreadPool(); taskExecutor.execute(() -> { try { DSTenantKeyThreadVar.tenantKey.set(tenantKey); accounting(selectParam, employeeId, tenantKey, currentUserName); } finally { DSTenantKeyThreadVar.tenantKey.remove(); } }); } public void accounting(AccountParam param, Long employeeId, String tenantKey, String currentUserName) { //薪资核算进度暂未实现 SalaryAcctProgressDTO salaryAcctProgressDTO = getSalaryAcctProgressService(user).getProgress(SalaryCacheKey.ACCT_PROGRESS + param.getBillMonth()); if (salaryAcctProgressDTO != null && salaryAcctProgressDTO.getProgress().compareTo(BigDecimal.ONE) < 0) { return; } // 初始化进度 SalaryAcctProgressDTO initProgress = new SalaryAcctProgressDTO() .setTitle(SalaryI18nUtil.getI18nLabel(97515, "核算中")) .setTitleLabelId(97515L) .setTotalQuantity(NumberUtils.INTEGER_ONE) .setCalculatedQuantity(NumberUtils.INTEGER_ZERO) .setProgress(BigDecimal.ZERO) .setStatus(true) .setMessage(StringUtils.EMPTY); getSalaryAcctProgressService(user).initProgress(SalaryCacheKey.ACCT_PROGRESS + param.getBillMonth(), initProgress); doAccounting(param, employeeId, tenantKey, currentUserName); } public void doAccounting(AccountParam param, Long employeeId, String tenantKey, String currentUserName) { log.info("核算时间:{}, 核算月份:{}, 个税扣缴义务人:{}, 是否首次核算:{}", new Date(), param.getBillMonth(), param.getPaymentOrganization(), param.isFlag()); try { List ids; List validIds = new ArrayList<>(); if (CollectionUtils.isEmpty(param.getIds())) { // 需要分权的情况 // if(getTaxAgentService().isOpenDevolution()) { List empIds = getInsuranceAccountDetailMapper().selectEmpByPaymentOrg(param.getPaymentOrganization()); //过滤出需要核算的人员,即福利档案基础信息表中runStatus为正在缴纳和待减员的人员 List baseInfoPOList = getInsuranceBaseInfoMapper().listAll(); List canAccountIds = baseInfoPOList.stream() .filter(f->f.getPaymentOrganization().equals(param.getPaymentOrganization()) && (f.getRunStatus().equals(EmployeeStatusEnum.PAYING.getValue()) || f.getRunStatus().equals(EmployeeStatusEnum.STAY_DEL.getValue()))) .map(InsuranceArchivesBaseInfoPO::getEmployeeId) .collect(Collectors.toList()); empIds = empIds.stream().filter(f->canAccountIds.contains(f)).collect(Collectors.toList()); //过滤不在扣缴义务人下的数据 // Collection employeeIdsInTaxAgent = getTaxAgentService().listEmployeeIdsInTaxAgent(param.getPaymentOrganization()); // empIds = empIds.stream().filter(employeeIdsInTaxAgent::contains).collect(Collectors.toList()); List socials = siArchivesBiz.getSocialByEmployeeIds(empIds); //过滤出目标个税扣缴义务人相关信息 socials = socials.stream().filter(f -> f.getPaymentOrganization().equals(param.getPaymentOrganization())).collect(Collectors.toList()); List emp1 = socials.stream() .filter(s -> StringUtils.isBlank(s.getSocialEndTime()) || (SalaryDateUtil.stringToDate(s.getSocialEndTime() + "-01") != null && !SalaryDateUtil.stringToDate(param.getBillMonth() + "-01").after(SalaryDateUtil.stringToDate(s.getSocialEndTime() + "-01")))) .map(InsuranceArchivesSocialSchemePO::getEmployeeId) .collect(Collectors.toList()); List funds = siArchivesBiz.getFundByEmployeeIds(empIds); //过滤出目标个税扣缴义务人相关信息 funds = funds.stream().filter(f -> f.getPaymentOrganization().equals(param.getPaymentOrganization())).collect(Collectors.toList()); List emp2 = funds.stream() .filter(s -> StringUtils.isBlank(s.getFundEndTime()) || (SalaryDateUtil.stringToDate(s.getFundEndTime() + "-01") != null && !SalaryDateUtil.stringToDate(param.getBillMonth() + "-01").after(SalaryDateUtil.stringToDate(s.getFundEndTime() + "-01")))) .map(InsuranceArchivesFundSchemePO::getEmployeeId) .collect(Collectors.toList()); List others = siArchivesBiz.getOtherByEmployeeIds(empIds); //过滤出目标个税扣缴义务人相关信息 others = others.stream().filter(f -> f.getPaymentOrganization().equals(param.getPaymentOrganization())).collect(Collectors.toList()); List emp3 = others.stream() .filter(s -> StringUtils.isBlank(s.getOtherEndTime()) || (SalaryDateUtil.stringToDate(s.getOtherEndTime() + "-01") != null && !SalaryDateUtil.stringToDate(param.getBillMonth() + "-01").after(SalaryDateUtil.stringToDate(s.getOtherEndTime() + "-01")))) .map(InsuranceArchivesOtherSchemePO::getEmployeeId) .collect(Collectors.toList()); validIds.addAll(emp1); validIds.addAll(emp2); validIds.addAll(emp3); List finalValidIds = validIds.stream().distinct().collect(Collectors.toList()); ids = empIds.stream().filter(finalValidIds::contains).collect(Collectors.toList()); // } else { // ids = getInsuranceAccountDetailMapper().selectAccountIds(SalaryDateUtil.getMonthBegin(param.getBillMonth()), null); // } } else { ids = param.getIds(); } if (CollectionUtils.isEmpty(ids)) { getSalaryAcctProgressService(user).finish(SalaryCacheKey.ACCT_PROGRESS + param.getBillMonth(), true); // getSalaryAcctProgressService(user).fail(SalaryCacheKey.ACCT_PROGRESS + param.getBillMonth(), SalaryI18nUtil.getI18nLabel( 100468, "无需要核算的人员")); return; } // SalaryAcctProgressDTO salaryAcctProgressDTO = new SalaryAcctProgressDTO(SalaryI18nUtil.getI18nLabel(97515, "核算中"), 97515L, ids.size(), 0, // BigDecimal.ZERO, true, "", true); //salaryAcctProgressService.initProgress(tenantKey + param.getBillMonth(), salaryAcctProgressDTO, employeeId, tenantKey); // 初始化进度 SalaryAcctProgressDTO initProgress = new SalaryAcctProgressDTO() .setTitle(SalaryI18nUtil.getI18nLabel(97515, "核算中")) .setTitleLabelId(97515L) .setTotalQuantity(ids.size()) .setCalculatedQuantity(NumberUtils.INTEGER_ZERO) .setProgress(BigDecimal.ZERO) .setStatus(true) .setMessage(StringUtils.EMPTY); getSalaryAcctProgressService(user).initProgress(SalaryCacheKey.ACCT_PROGRESS + param.getBillMonth(), initProgress); /* List> partition = Lists.partition(ids, 100); CountDownLatch countDownLatch = new CountDownLatch(partition.size()); BlockingDeque results = new LinkedBlockingDeque<>(partition.size());*/ commonAccount(/*countDownLatch, results, */param.getBillMonth(), ids, employeeId, tenantKey, param.getPaymentOrganization()); /* for (List batchIds : partition) { taskExecutor.execute(() -> { commonAccount(countDownLatch, results, param.getBillMonth(), batchIds, simpleEmployee); }); } countDownLatch.await(); boolean allSuccess = results.stream().allMatch(Boolean::booleanValue);*/ /* if (allSuccess) {*/ handleData(ids, param, employeeId, tenantKey, currentUserName); /*}*/ List> partition = Lists.partition((List) ids, 100); partition.forEach(part -> { MapperProxyFactory.getProxy(SIAccountDetailTempMapper.class).batchDelByEmpIdsAndMonthAndPayOrg(part, param.getBillMonth(), param.getPaymentOrganization()); }); getSalaryAcctProgressService(user).finish(SalaryCacheKey.ACCT_PROGRESS + param.getBillMonth(), true); } catch (Exception e) { log.error("account run fail", e); List list = Lists.newArrayList(getInsuranceAccountBatchMapper().getByBillMonth(param.getBillMonth(), param.getPaymentOrganization())); list = encryptUtil.decryptList(list, InsuranceAccountBatchPO.class); if (CollectionUtils.isNotEmpty(list)) { list.stream().forEach(f -> { getInsuranceAccountBatchMapper().deleteById(f.getId()); }); } //薪资核算进度暂未实现 //salaryAcctProgressService.del(tenantKey + param.getBillMonth(), employeeId, tenantKey); //logger.error("welfare account error:{}", e.getMessage(), e); getSalaryAcctProgressService(user).fail(SalaryCacheKey.ACCT_PROGRESS + param.getBillMonth(), e.getMessage()); } } public void commonAccount(/*CountDownLatch countDownLatch, BlockingDeque results,*/ String billMonth, List ids, Long employeeId, String tenantKey, Long paymentOrganization) { /* try {*/ SIArchivesBiz siArchivesBiz = new SIArchivesBiz(); Map insuranceArchivesAccountPOS = siArchivesBiz.buildBatchAccount(ids, paymentOrganization); List list = new ArrayList<>(); int count = 0; for (Map.Entry entry : insuranceArchivesAccountPOS.entrySet()) { Long k = entry.getKey(); InsuranceArchivesAccountPO v = entry.getValue(); InsuranceAccountDetailPO insuranceAccountDetailPO = new InsuranceAccountDetailPO(); insuranceAccountDetailPO.setBillMonth(billMonth); insuranceAccountDetailPO.setBillStatus(BillStatusEnum.NOT_ARCHIVED.getValue()); insuranceAccountDetailPO.setCreator(employeeId); insuranceAccountDetailPO.setCreateTime(new Date()); insuranceAccountDetailPO.setDeleteType(DeleteTypeEnum.NOT_DELETED.getValue()); insuranceAccountDetailPO.setEmployeeId(k); insuranceAccountDetailPO.setUpdateTime(new Date()); insuranceAccountDetailPO.setPaymentStatus(PaymentStatusEnum.COMMON.getValue()); insuranceAccountDetailPO.setResourceFrom(ResourceFromEnum.SYSTEM.getValue()); insuranceAccountDetailPO.setTenantKey(tenantKey); insuranceAccountDetailPO.setPaymentOrganization(paymentOrganization); //核算社保 accountSocial(insuranceAccountDetailPO, v, billMonth, tenantKey); //核算公积金 accountFund(insuranceAccountDetailPO, v, billMonth, tenantKey); //核算其他福利 accountOther(insuranceAccountDetailPO, v, billMonth, tenantKey); //计算合计 account(insuranceAccountDetailPO); //临时表PO InsuranceAccountDetailTempPO insuranceAccountDetailTempPO = new InsuranceAccountDetailTempPO(); BeanUtils.copyProperties(insuranceAccountDetailPO, insuranceAccountDetailTempPO); list.add(insuranceAccountDetailTempPO); count++; if (count % 50 == 0 || count >= ids.size()) { //salaryAcctProgressService.getAndAddCalculatedQty(tenantKey + billMonth, count >= ids.size() ? count % 50 : 50); getSalaryAcctProgressService(user).getAndAddCalculatedQty(SalaryCacheKey.ACCT_PROGRESS + billMonth, count >= ids.size() ? count % 50 : 50); if (count == ids.size()) { getSalaryAcctProgressService(user).updateProgress(SalaryCacheKey.ACCT_PROGRESS + billMonth, BigDecimal.valueOf(0.99), false); } else { getSalaryAcctProgressService(user).updateProgress(SalaryCacheKey.ACCT_PROGRESS + billMonth, BigDecimal.valueOf(count/ids.size()).setScale(2, BigDecimal.ROUND_HALF_UP), false); } } } //临时表入库前先对(可能存在的)历史数据进行删除 List> partition = Lists.partition((List) ids, 100); partition.forEach(part -> { MapperProxyFactory.getProxy(SIAccountDetailTempMapper.class).batchDelByEmpIdsAndMonthAndPayOrg(part, billMonth, paymentOrganization); }); //临时表数据入库 if (CollectionUtils.isNotEmpty(list)) { encryptUtil.encryptList(list, InsuranceAccountDetailTempPO.class); List> lists = splitList(list, 40); lists.forEach(subList -> { MapperProxyFactory.getProxy(SIAccountDetailTempMapper.class).batchSaveAccountTempDetails(subList); }); } /* } catch (Exception e) { logger.error("福利核算失败:{}", e.getMessage(), e); results.add(false); } finally { countDownLatch.countDown(); }*/ } private List> splitList(List list, int groupSize) { int length = list.size(); // 计算可以分成多少组 int num = (length + groupSize - 1) / groupSize; List> newList = new ArrayList<>(num); for (int i = 0; i < num; i++) { // 开始位置 int fromIndex = i * groupSize; // 结束位置 int toIndex = (i + 1) * groupSize < length ? (i + 1) * groupSize : length; newList.add(list.subList(fromIndex, toIndex)); } return newList; } private void handleData(List ids, AccountParam param, Long employeeId, String tenantKey, String currentUserName) { //事务后续处理 //TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition()); String billMonth = param.getBillMonth(); try { List list = MapperProxyFactory.getProxy(SIAccountDetailTempMapper.class).getListByEmployeeIdsAndBillMonth(ids, billMonth, param.getPaymentOrganization()); encryptUtil.decryptList(list, InsuranceAccountDetailTempPO.class); Integer paymentStatus = 0; log.info("核算明细临时表 hrsa_bill_detail_temp待处理数量:{}", list.size()); List> partitionIds = Lists.partition((List) ids, 100); log.info("bill_detail入库前删除数据数量:{}", ids.size()); for (List part : partitionIds) { getInsuranceAccountDetailMapper().batchDelAccountDetails(part, billMonth, param.getPaymentOrganization(), paymentStatus); //删除账单月份+个税扣缴义务人+人员id下的调差数据 getInsuranceCompensationMapper().deleteByBillMonthPayOrgEmpIds(InsuranceCompensationPO.builder() .billMonth(billMonth) .paymentOrganization(param.getPaymentOrganization()) .employeeIds(part) .build()); } //生成bill_detail入库数据 List collect = list.stream().map(item -> { InsuranceAccountDetailPO insuranceAccountDetailPO = new InsuranceAccountDetailPO(); BeanUtils.copyProperties(item, insuranceAccountDetailPO); return insuranceAccountDetailPO; }).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(collect)) { log.info("bill_detail入库数据数量:{}", collect.size()); batchSaveAccountInspectDetail(collect, billMonth, tenantKey); encryptUtil.encryptList(collect, InsuranceAccountDetailPO.class); List> lists = splitDetailList(collect, 20); lists.forEach(subList -> { getInsuranceAccountDetailMapper().batchSaveAccountDetails(subList); }); updateBatchAccount(param, employeeId, tenantKey, currentUserName); } //transactionManager.commit(status); } catch (Exception e) { //transactionManager.rollback(status); throw e; } } public InsuranceAccountDetailPO account(InsuranceAccountDetailPO insuranceAccountDetailPO) { //个人合计 BigDecimal socialPerson = StringUtils.isBlank(insuranceAccountDetailPO.getSocialPerSum()) ? new BigDecimal("0") : new BigDecimal(insuranceAccountDetailPO.getSocialPerSum()); BigDecimal fundPerson = StringUtils.isBlank(insuranceAccountDetailPO.getFundPerSum()) ? new BigDecimal("0") : new BigDecimal(insuranceAccountDetailPO.getFundPerSum()); BigDecimal otherPerson = StringUtils.isBlank(insuranceAccountDetailPO.getOtherPerSum()) ? new BigDecimal("0") : new BigDecimal(insuranceAccountDetailPO.getOtherPerSum()); BigDecimal perSum = socialPerson.add(fundPerson).add(otherPerson); insuranceAccountDetailPO.setPerSum(perSum.toPlainString()); //单位合计 BigDecimal socialCom = StringUtils.isBlank(insuranceAccountDetailPO.getSocialComSum()) ? new BigDecimal("0") : new BigDecimal(insuranceAccountDetailPO.getSocialComSum()); BigDecimal fundCom = StringUtils.isBlank(insuranceAccountDetailPO.getFundComSum()) ? new BigDecimal("0") : new BigDecimal(insuranceAccountDetailPO.getFundComSum()); BigDecimal otherCom = StringUtils.isBlank(insuranceAccountDetailPO.getOtherComSum()) ? new BigDecimal("0") : new BigDecimal(insuranceAccountDetailPO.getOtherComSum()); BigDecimal comSum = socialCom.add(fundCom).add(otherCom); insuranceAccountDetailPO.setComSum(comSum.toPlainString()); //社保合计 insuranceAccountDetailPO.setSocialSum(socialPerson.add(socialCom).toPlainString()); //公积金合计 insuranceAccountDetailPO.setFundSum(fundPerson.add(fundCom).toPlainString()); //其他福利合计 insuranceAccountDetailPO.setOtherSum(otherPerson.add(otherCom).toPlainString()); //合计 insuranceAccountDetailPO.setTotal(perSum.add(comSum).toPlainString()); return insuranceAccountDetailPO; } public InsuranceAccountDetailPO accountOther(InsuranceAccountDetailPO insuranceAccountDetailPO, InsuranceArchivesAccountPO accountPO, String billMonth, String tenantKey) { if (accountPO.getOther() != null) { InsuranceArchivesOtherSchemePO otherPO = accountPO.getOther(); insuranceAccountDetailPO.setOtherPayOrg(otherPO.getPaymentOrganization()); insuranceAccountDetailPO.setOtherSchemeId(otherPO.getOtherSchemeId()); insuranceAccountDetailPO.setOtherPaymentBaseString(otherPO.getOtherPaymentBaseString()); //判断是否在起始缴纳月和最后缴纳月之间 Boolean inDataRange = SalaryDateUtil.monthInRange(insuranceAccountDetailPO.getBillMonth(), otherPO.getOtherStartTime(), otherPO.getOtherEndTime()); if ((Objects.equals(NonPaymentEnum.YES.getValue(), otherPO.getNonPayment()) || otherPO.getNonPayment() == null) && otherPO.getOtherSchemeId() != null && inDataRange) { List detailPOS = MapperProxyFactory.getProxy(InsuranceSchemeDetailMapper.class).queryListBySchemeId(otherPO.getOtherSchemeId()); encryptUtil.decryptList(detailPOS, InsuranceSchemeDetailPO.class); //方案中包含的需要缴纳其他的个人福利 int monthIndex = Integer.parseInt(billMonth.split("-")[1]) - 1; Map otherPerson = 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(otherPO.getOtherPaymentBaseString(), new HashMap().getClass()); //需要核算其他的福利id 个人 List needArchivesPerson = new ArrayList<>(); if (archivesPerson != null) { archivesPerson.forEach((id, value) -> { if (otherPerson.containsKey(Long.valueOf(id))) { needArchivesPerson.add(Long.valueOf(id)); } }); } //判断核算周期、核算月、福利起始缴纳月的关系 checkCycleSettingWithStartMonth(otherPerson, billMonth, otherPO.getOtherStartTime()); List otherPer = new ArrayList<>(); Map otherPerJsonMap = new HashMap<>(); needArchivesPerson.stream().forEach(e -> { InsuranceSchemeDetailPO po = otherPerson.get(e); BigDecimal paymentProportion = new BigDecimal(StringUtils.isBlank(po.getPaymentProportion()) ? "0" : po.getPaymentProportion()).divide(new BigDecimal("100")); BigDecimal paymentNum = new BigDecimal(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 = SalaryEntityUtil.carryRule(newScale, po.getRententionRule(), paymentNum.multiply(paymentProportion).add(fixedCost)); BigDecimal result = new BigDecimal("0"); if (po.getPaymentCycle() != null && 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)); } otherPerJsonMap.put(String.valueOf(e), result.toPlainString()); otherPer.add(result); }); insuranceAccountDetailPO.setOtherPerJson(JSON.toJSONString(otherPerJsonMap)); BigDecimal otherPerSum = new BigDecimal("0"); for (BigDecimal bigDecimal : otherPer) { otherPerSum = otherPerSum.add(bigDecimal); } insuranceAccountDetailPO.setOtherPerSum(otherPerSum.toPlainString()); //方案中包含的需要缴纳公积金的单位福利 Map otherCom = 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(otherPO.getOtherPaymentBaseString(), new HashMap().getClass()); //需要核算其他的福利id 单位 List needArchivesCom = new ArrayList<>(); if (archivesCom != null) { archivesCom.forEach((id, value) -> { if (otherCom.containsKey(Long.valueOf(id))) { needArchivesCom.add(Long.valueOf(id)); } }); } //判断核算周期、核算月、福利起始缴纳月的关系 checkCycleSettingWithStartMonth(otherCom, billMonth, otherPO.getOtherStartTime()); List otherComList = new ArrayList<>(); Map otherComJsonMap = new HashMap<>(); needArchivesCom.stream().forEach(e -> { InsuranceSchemeDetailPO po = otherCom.get(e); BigDecimal paymentProportion = new BigDecimal(StringUtils.isBlank(po.getPaymentProportion()) ? "0" : po.getPaymentProportion()).divide(new BigDecimal("100")); BigDecimal paymentNum = new BigDecimal(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 = SalaryEntityUtil.carryRule(newScale, po.getRententionRule(), paymentNum.multiply(paymentProportion).add(fixedCost)); 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)); } otherComJsonMap.put(String.valueOf(e), result.toPlainString()); otherComList.add(result); }); insuranceAccountDetailPO.setOtherComJson(JSON.toJSONString(otherComJsonMap)); BigDecimal otherComSum = new BigDecimal("0"); for (BigDecimal bigDecimal : otherComList) { otherComSum = otherComSum.add(bigDecimal); } insuranceAccountDetailPO.setOtherComSum(otherComSum.toPlainString()); } } return insuranceAccountDetailPO; } public InsuranceAccountDetailPO accountFund(InsuranceAccountDetailPO insuranceAccountDetailPO, InsuranceArchivesAccountPO accountPO, String billMonth, String tenantKey) { if (accountPO.getFund() != null) { InsuranceArchivesFundSchemePO fundPO = accountPO.getFund(); insuranceAccountDetailPO.setFundPayOrg(fundPO.getPaymentOrganization()); insuranceAccountDetailPO.setFundAccount(fundPO.getFundAccount()); insuranceAccountDetailPO.setSupplementFundAccount(fundPO.getSupplementFundAccount()); insuranceAccountDetailPO.setFundSchemeId(fundPO.getFundSchemeId()); insuranceAccountDetailPO.setFundPaymentBaseString(fundPO.getFundPaymentBaseString()); //判断是否在起始缴纳月和最后缴纳月之间 Boolean inDataRange = SalaryDateUtil.monthInRange(insuranceAccountDetailPO.getBillMonth(), fundPO.getFundStartTime(), fundPO.getFundEndTime()); if ((NonPaymentEnum.YES.getValue() == fundPO.getNonPayment() || fundPO.getNonPayment() == null) && fundPO.getFundSchemeId() != null && inDataRange) { List detailPOS = MapperProxyFactory.getProxy(InsuranceSchemeDetailMapper.class).queryListBySchemeId(fundPO.getFundSchemeId()); encryptUtil.decryptList(detailPOS, InsuranceSchemeDetailPO.class); //方案中包含的需要缴纳社保的个人福利 int monthIndex = Integer.parseInt(billMonth.split("-")[1]) - 1; Map fundperson = 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(fundPO.getFundPaymentBaseString(), new HashMap().getClass()); //需要核算公积金的福利id 个人 List needArchivesPerson = new ArrayList<>(); if (archivesPerson != null) { archivesPerson.forEach((id, value) -> { if (fundperson.containsKey(Long.valueOf(id))) { needArchivesPerson.add(Long.valueOf(id)); } }); } //判断核算周期、核算月、福利起始缴纳月的关系 checkCycleSettingWithStartMonth(fundperson, billMonth, fundPO.getFundStartTime()); List fundPer = new ArrayList<>(); Map fundPerJsonMap = new HashMap<>(); needArchivesPerson.stream().forEach(e -> { InsuranceSchemeDetailPO po = fundperson.get(e); BigDecimal paymentProportion = new BigDecimal(StringUtils.isBlank(po.getPaymentProportion()) ? "0" : po.getPaymentProportion()).divide(new BigDecimal("100")); BigDecimal paymentNum = new BigDecimal(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 = SalaryEntityUtil.carryRule(newScale, po.getRententionRule(), paymentNum.multiply(paymentProportion).add(fixedCost)); 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)); } fundPerJsonMap.put(String.valueOf(e), result.toPlainString()); fundPer.add(result); }); insuranceAccountDetailPO.setFundPerJson(JSON.toJSONString(fundPerJsonMap)); BigDecimal funPerSum = new BigDecimal("0"); for (BigDecimal bigDecimal : fundPer) { funPerSum = funPerSum.add(bigDecimal); } insuranceAccountDetailPO.setFundPerSum(funPerSum.toPlainString()); //方案中包含的需要缴纳公积金的单位福利 Map fundCom = 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(fundPO.getFundPaymentBaseString(), new HashMap().getClass()); //需要核算公积金的福利id 单位 List needArchivesCom = new ArrayList<>(); if (archivesCom != null) { archivesCom.forEach((id, value) -> { if (fundCom.containsKey(Long.valueOf(id))) { needArchivesCom.add(Long.valueOf(id)); } }); } //判断核算周期、核算月、福利起始缴纳月的关系 checkCycleSettingWithStartMonth(fundCom, billMonth, fundPO.getFundStartTime()); List fundComList = new ArrayList<>(); Map fundComJsonMap = new HashMap<>(); needArchivesCom.stream().forEach(e -> { InsuranceSchemeDetailPO po = fundCom.get(e); BigDecimal paymentProportion = new BigDecimal(StringUtils.isBlank(po.getPaymentProportion()) ? "0" : po.getPaymentProportion()).divide(new BigDecimal("100")); BigDecimal paymentNum = new BigDecimal(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 = SalaryEntityUtil.carryRule(newScale, po.getRententionRule(), paymentNum.multiply(paymentProportion).add(fixedCost)); 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)); } fundComJsonMap.put(String.valueOf(e), result.toPlainString()); fundComList.add(result); }); insuranceAccountDetailPO.setFundComJson(JSON.toJSONString(fundComJsonMap)); BigDecimal fundComSum = new BigDecimal("0"); for (BigDecimal bigDecimal : fundComList) { fundComSum = fundComSum.add(bigDecimal); } insuranceAccountDetailPO.setFundComSum(fundComSum.toPlainString()); } } return insuranceAccountDetailPO; } public InsuranceAccountDetailPO accountSocial(InsuranceAccountDetailPO insuranceAccountDetailPO, InsuranceArchivesAccountPO accountPO, String billMonth, String tenantKey) { if (accountPO.getSocial() != null) { InsuranceArchivesSocialSchemePO socialPO = accountPO.getSocial(); insuranceAccountDetailPO.setSocialPayOrg(socialPO.getPaymentOrganization()); insuranceAccountDetailPO.setSocialAccount(socialPO.getSocialAccount()); insuranceAccountDetailPO.setSocialSchemeId(socialPO.getSocialSchemeId()); insuranceAccountDetailPO.setSocialPaymentBaseString(socialPO.getSocialPaymentBaseString()); //判断是否在起始缴纳月和最后缴纳月之间 Boolean inDataRange = SalaryDateUtil.monthInRange(insuranceAccountDetailPO.getBillMonth(), socialPO.getSocialStartTime(), socialPO.getSocialEndTime()); if ((NonPaymentEnum.YES.getValue().equals(socialPO.getNonPayment()) || socialPO.getNonPayment() == null) && socialPO.getSocialSchemeId() != null && inDataRange) { List detailPOS = MapperProxyFactory.getProxy(InsuranceSchemeDetailMapper.class).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) { archivesPerson.forEach((id, value) -> { if (schemeperson.containsKey(Long.valueOf(id))) { needArchivesPerson.add(Long.valueOf(id)); } }); } //判断核算周期、核算月、福利起始缴纳月的关系 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(StringUtils.isBlank(po.getPaymentProportion()) ? "0" : po.getPaymentProportion()).divide(new BigDecimal("100")); BigDecimal paymentNum = new BigDecimal(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 = SalaryEntityUtil.carryRule(newScale, po.getRententionRule(), paymentNum.multiply(paymentProportion).add(fixedCost)); 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) { archivesCom.forEach((id, value) -> { if (schemeCom.containsKey(Long.valueOf(id))) { needArchivesCom.add(Long.valueOf(id)); } }); } //判断核算周期、核算月、福利起始缴纳月的关系 checkCycleSettingWithStartMonth(schemeCom, billMonth, socialPO.getSocialStartTime()); List socialCom = new ArrayList<>(); Map sociaComJsonMap = new HashMap<>(); needArchivesCom.stream().forEach(e -> { InsuranceSchemeDetailPO po = schemeCom.get(e); BigDecimal paymentProportion = new BigDecimal(StringUtils.isBlank(po.getPaymentProportion()) ? "0" : po.getPaymentProportion()).divide(new BigDecimal("100")); BigDecimal paymentNum = new BigDecimal(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 = SalaryEntityUtil.carryRule(newScale, po.getRententionRule(), paymentNum.multiply(paymentProportion).add(fixedCost)); 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; } /** * 对于核算月和福利起始缴纳月处于同年时,要避免根据周期缴纳福利费用时,可能出现的多余费用缴纳情况 * @param schemeDetail 福利方案明细 * @param billMonth 核算月 * @param startMonth 福利起始缴纳月 * @return */ public Map checkCycleSettingWithStartMonth(Map schemeDetail, String billMonth, String startMonth) { String billYear = billMonth.substring(0,4); if (StringUtils.isNotBlank(startMonth) && billYear.equals(startMonth.substring(0,4))) { int startMonthIndex = Integer.parseInt(startMonth.split("-")[1]) - 1; schemeDetail.forEach((k, v) -> { if (v.getPaymentCycle() != null && v.getPaymentCycle().equals(1) && startMonthIndex != 0) { StringBuilder newCycleSetting = new StringBuilder(v.getCycleSetting()); newCycleSetting.setCharAt(startMonthIndex - 1, '1'); v.setCycleSetting(newCycleSetting.toString()); } }); } return schemeDetail; } public void batchSaveAccountInspectDetail(List list, String billMonth, String tenantKey) { List insuranceAccountInspectAllPOS = accountInspect(list, true); batchDelInspectDetail(insuranceAccountInspectAllPOS); List insuranceAccountInspectPOS = accountInspect(list, false); if (CollectionUtils.isNotEmpty(insuranceAccountInspectPOS)) { batchSaveInspectDetail(insuranceAccountInspectPOS); } } public List accountInspect(List list, boolean isAll) { List insuranceAccountInspectPOS = new ArrayList<>(); for (InsuranceAccountDetailPO e : list) { if (isAll || detailCheck(e.getSocialPerJson()) || detailCheck(e.getSocialComJson()) || detailCheck(e.getFundPerJson()) || detailCheck(e.getFundComJson()) || detailCheck(e.getOtherPerJson()) || detailCheck(e.getOtherComJson())) { InsuranceAccountInspectPO insuranceAccountInspectPO = InsuranceAccountInspectPO.builder().build(); insuranceAccountInspectPO.setSupplementaryProjects(e.getSupplementaryProjects()); insuranceAccountInspectPO.setInspectStatus(InspectStatusEnum.IGNORE.getValue()); insuranceAccountInspectPO.setBillMonth(e.getBillMonth()); insuranceAccountInspectPO.setCreator(e.getCreator()); insuranceAccountInspectPO.setCreateTime(new Date()); insuranceAccountInspectPO.setDeleteType(DeleteTypeEnum.NOT_DELETED.getValue()); insuranceAccountInspectPO.setEmployeeId(e.getEmployeeId()); insuranceAccountInspectPO.setPaymentStatus(e.getPaymentStatus()); insuranceAccountInspectPO.setSupplementaryMonth(e.getSupplementaryMonth()); insuranceAccountInspectPO.setTenantKey(e.getTenantKey()); insuranceAccountInspectPO.setUpdateTime(new Date()); insuranceAccountInspectPOS.add(insuranceAccountInspectPO); } } return insuranceAccountInspectPOS; } public boolean detailCheck(String baseString) { if (StringUtils.isEmpty(baseString)) { return false; } Map baseStringMap = JSON.parseObject(baseString, new TypeReference>() { }); if (baseStringMap == null || baseStringMap.size() == 0) { return false; } return baseStringMap.values().stream().anyMatch(item -> StringUtils.isEmpty(item) || Pattern.matches("^([0].?[0]*)$", item)); } public void batchDelInspectDetail(List list) { List> lists = Lists.partition(list, 100); lists.forEach(getInsuranceAccountInspectMapper()::batchDelInspectDetails); } public void batchSaveInspectDetail(List list) { List> lists = Lists.partition(list, 100); lists.forEach(getInsuranceAccountInspectMapper()::batchSaveInspectDetails); } /** * 跟新台账接口 * * @param tenantKey 租户key */ public void updateBatchAccount(AccountParam param, Long employeeId, String tenantKey, String currentUserName) { String billMonth = param.getBillMonth(); List insuranceAccountDetailPOS = getInsuranceAccountDetailMapper().selectList(billMonth, param.getPaymentOrganization()); Map> map = insuranceAccountDetailPOS.stream().filter(item -> item.getEmployeeId() != null) .collect(Collectors.groupingBy(InsuranceAccountDetailPO::getEmployeeId)); int socialAccountPerson = 0; int funcAccountPerson = 0; int otherAccountPerson = 0; BigDecimal socialSum = new BigDecimal("0"); BigDecimal fundSum = new BigDecimal("0"); BigDecimal otherSum = new BigDecimal("0"); for (Map.Entry> entry : map.entrySet()) { List v = entry.getValue(); BigDecimal socialTemp = new BigDecimal("0"); BigDecimal fundTemp = new BigDecimal("0"); BigDecimal otherTemp = new BigDecimal("0"); encryptUtil.decryptList(v, InsuranceAccountDetailPO.class); boolean socialPersonFlag = false; boolean fundPersonFlag = false; boolean otherPersonFlag = false; for (InsuranceAccountDetailPO item : v) { // 判断社保是否为0 socialPersonFlag = (StringUtils.isBlank(item.getSocialSum()) || SalaryEntityUtil.StringEqZERO(item.getSocialSum())); BigDecimal socialPerson = socialPersonFlag ? new BigDecimal("0") : new BigDecimal(item.getSocialSum()); fundPersonFlag = (StringUtils.isBlank(item.getFundSum()) || SalaryEntityUtil.StringEqZERO(item.getFundSum())); BigDecimal fundPerson = fundPersonFlag ? new BigDecimal("0") : new BigDecimal(item.getFundSum()); otherPersonFlag = (StringUtils.isBlank(item.getOtherSum()) || SalaryEntityUtil.StringEqZERO(item.getOtherSum())); BigDecimal otherPerson = otherPersonFlag ? new BigDecimal("0") : new BigDecimal(item.getOtherSum()); socialTemp = socialTemp.add(socialPerson); fundTemp = fundTemp.add(fundPerson); otherTemp = otherTemp.add(otherPerson); if (!socialPersonFlag && !item.getPaymentStatus().equals(PaymentStatusEnum.BALANCE.getValue())) { socialAccountPerson += 1; } if (!fundPersonFlag && !item.getPaymentStatus().equals(PaymentStatusEnum.BALANCE.getValue())) { funcAccountPerson += 1; } if (!otherPersonFlag && !item.getPaymentStatus().equals(PaymentStatusEnum.BALANCE.getValue())) { otherAccountPerson += 1; } } // if (!socialPersonFlag) { // socialSum = socialSum.add(socialTemp); // } // if (!fundPersonFlag) { // fundSum = fundSum.add(fundTemp); // } // if (!otherPersonFlag) { // otherSum = otherSum.add(otherTemp); // } if (!"0".equals(socialTemp.toPlainString())) { socialSum = socialSum.add(socialTemp); } if (!"0".equals(fundTemp.toPlainString())) { fundSum = fundSum.add(fundTemp); } if (!"0".equals(otherTemp.toPlainString())) { otherSum = otherSum.add(otherTemp); } } InsuranceAccountBatchPO insuranceAccountBatchPO = getInsuranceAccountBatchMapper().getByBillMonth(billMonth, param.getPaymentOrganization()); encryptUtil.decrypt(insuranceAccountBatchPO, InsuranceAccountBatchPO.class); DataCollectionEmployee simpleEmployee = MapperProxyFactory.getProxy(EmployMapper.class).getEmployeeById(employeeId); insuranceAccountBatchPO.setAccountant(currentUserName); insuranceAccountBatchPO.setUpdateTime(new Date()); insuranceAccountBatchPO.setSocialPay(socialSum.toPlainString()); insuranceAccountBatchPO.setSocialNum(socialAccountPerson); insuranceAccountBatchPO.setFundNum(funcAccountPerson); insuranceAccountBatchPO.setFundPay(fundSum.toPlainString()); insuranceAccountBatchPO.setOtherNum(otherAccountPerson); insuranceAccountBatchPO.setOtherPay(otherSum.toPlainString()); encryptUtil.encrypt(insuranceAccountBatchPO, InsuranceAccountBatchPO.class); getInsuranceAccountBatchMapper().updateById(insuranceAccountBatchPO); // LoggerContext insuranceSchemeContext = new LoggerContext(); // insuranceSchemeContext.setTargetId(String.valueOf(insuranceAccountBatchPO.getId())); // insuranceSchemeContext.setTargetName(insuranceAccountBatchPO.getBillMonth()); // insuranceSchemeContext.setOperateType(OperateTypeEnum.UPDATE.getValue()); // insuranceSchemeContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100491, "更新台账")); // insuranceSchemeContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100491, "更新台账")); // insuranceSchemeContext.setNewValues(insuranceAccountBatchPO); // siAccountLoggerTemplate.write(insuranceSchemeContext); } public void saveCommonAccount(SaveCommonAccountParam param, Long employeeId, String currentUserName) { List collect; SalaryAssert.notEmpty(param.getIncludes(), SalaryI18nUtil.getI18nLabel(100466, "参数为空")); SalaryAssert.notNull(param.getBillMonth(), SalaryI18nUtil.getI18nLabel(100467, "账单月为空")); if (CollectionUtils.isNotEmpty(param.getExcludes())) { collect = param.getIncludes().stream().filter(item -> !param.getExcludes().contains(item)).collect(Collectors.toList()); } else { collect = param.getIncludes(); } SalaryAssert.notEmpty(collect, SalaryI18nUtil.getI18nLabel(99920, "无核算人员")); AccountParam accountParam = new AccountParam(); accountParam.setBillMonth(param.getBillMonth()); accountParam.setIds(collect); accounting(accountParam, employeeId, SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY, currentUserName); } public void delete(AccountParam param, Long employeeId) { InsuranceAccountBatchPO insuranceAccountBatchPO = getInsuranceAccountBatchMapper().getByBillMonth(param.getBillMonth(), param.getPaymentOrganization()); encryptUtil.decrypt(insuranceAccountBatchPO, InsuranceAccountBatchPO.class); SalaryAssert.notNull(insuranceAccountBatchPO, SalaryI18nUtil.getI18nLabel(84026, "参数错误")); // 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 saveSupplementaryAccount(SaveSupplementaryAccountParam param, Long employeeId, String currentUserName) { if (StringUtils.isBlank(param.getBillMonth()) || CollectionUtils.isEmpty(param.getBillMonthList()) || CollectionUtils.isEmpty(param.getProjects()) || CollectionUtils.isEmpty(param.getIncludes())) { throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "参数错误")); } //需要补缴的月份 if (param.getBillMonthList().contains(param.getBillMonth())) { throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100481, "当前月走正常缴纳")); } //需要补缴的员工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, "补缴人员中存在未设置福利档案人员或相关人员不在福利在缴人员中,不可新建补缴信息!")); } SalaryAssert.notEmpty(employeeIds, SalaryI18nUtil.getI18nLabel(99920, "无核算人员")); 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.getBillMonth(), employeeId, param.getPaymentOrganization()); updateBatchAccount(AccountParam.builder().billMonth(param.getBillMonth()).paymentOrganization(param.getPaymentOrganization()).build(), employeeId, SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY, currentUserName); } /** * @param baseList 员工id-账单月份-补缴月份(单挑)-补缴项 集合 * @param employeeIds 需要补缴的员工id * @return */ public String accountSupplement(List baseList, List employeeIds, String billMonth, Long employeeId, 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()), employeeId); pos.add(insuranceAccountDetailPO); }); batchSaveSupplementAccount(pos, billMonth, SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY); return SalaryI18nUtil.getI18nLabel(100492, "核算完成,数据保存成功"); } public InsuranceAccountDetailPO accountSingleEmployeeBill(SupplementAccountBaseParam baseParam, InsuranceArchivesAccountPO accountPO, Long employeeId) { InsuranceAccountDetailPO insuranceAccountDetailPO = new InsuranceAccountDetailPO(); List projects = baseParam.getProjects(); insuranceAccountDetailPO.setBillMonth(baseParam.getBillMonth()); insuranceAccountDetailPO.setBillStatus(BillStatusEnum.NOT_ARCHIVED.getValue()); insuranceAccountDetailPO.setCreator(employeeId); 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())) { accountSocialByData(insuranceAccountDetailPO, baseParam); accountFundByData(insuranceAccountDetailPO, baseParam); accountOtherByData(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())) { accountSocialByData(insuranceAccountDetailPO, baseParam); } else { accountSocial(insuranceAccountDetailPO, accountPO, baseParam.getSupplementaryMonth()); } } if (!projects.contains(ProjectTypeEnum.SOCIAL.getValue())) { List ids = new ArrayList<>(); List list = MapperProxyFactory.getProxy(ICategoryMapper.class).listByDataType(DataTypeEnum.SYSTEM.getValue()); if (projects.contains(ProjectTypeEnum.ENDOWMENT_INSURANCE.getValue())) { ICategoryPO insuranceCategoryPO = list.stream().filter(item -> SalaryI18nUtil.getI18nLabel(93113, "养老保险").equals(item.getInsuranceName())).findFirst() .get(); ids.add(insuranceCategoryPO.getId()); } if (projects.contains(ProjectTypeEnum.MEDICAL_INSURANCE.getValue())) { ICategoryPO insuranceCategoryPO = list.stream().filter(item -> SalaryI18nUtil.getI18nLabel(93114, "医疗保险").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())) { accountEndowmentInsuranceByData(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())) { accountFundByData(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())) { accountOtherByData(insuranceAccountDetailPO, baseParam); } else { accountOther(insuranceAccountDetailPO, accountPO, baseParam.getSupplementaryMonth()); } } return account(insuranceAccountDetailPO); } public InsuranceAccountDetailPO accountOther(InsuranceAccountDetailPO insuranceAccountDetailPO, InsuranceArchivesAccountPO accountPO, String billMonth) { if (accountPO.getOther() != null) { InsuranceArchivesOtherSchemePO otherPO = accountPO.getOther(); insuranceAccountDetailPO.setOtherPayOrg(otherPO.getPaymentOrganization()); insuranceAccountDetailPO.setOtherSchemeId(otherPO.getOtherSchemeId()); insuranceAccountDetailPO.setOtherPaymentBaseString(otherPO.getOtherPaymentBaseString()); //判断是否在起始缴纳月和最后缴纳月之间 Boolean inDataRange = SalaryDateUtil.monthInRange(billMonth, otherPO.getOtherStartTime(), otherPO.getOtherEndTime()); if ((Objects.equals(NonPaymentEnum.YES.getValue(), otherPO.getNonPayment()) || otherPO.getNonPayment() == null) && otherPO.getOtherSchemeId() != null && inDataRange) { List detailPOS = MapperProxyFactory.getProxy(InsuranceSchemeDetailMapper.class).queryListBySchemeId(otherPO.getOtherSchemeId()); encryptUtil.decryptList(detailPOS, InsuranceSchemeDetailPO.class); //方案中包含的需要缴纳其他的个人福利 int monthIndex = Integer.parseInt(billMonth.split("-")[1]) - 1; Map otherPerson = 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(otherPO.getOtherPaymentBaseString(), new HashMap().getClass()); //需要核算其他的福利id 个人 List needArchivesPerson = new ArrayList<>(); if (archivesPerson != null) { archivesPerson.forEach((id, value) -> { if (otherPerson.containsKey(Long.valueOf(id))) { needArchivesPerson.add(Long.valueOf(id)); } }); } //判断核算周期、核算月、福利起始缴纳月的关系 checkCycleSettingWithStartMonth(otherPerson, billMonth, otherPO.getOtherStartTime()); List otherPer = new ArrayList<>(); Map otherPerJsonMap = new HashMap<>(); needArchivesPerson.stream().forEach(e -> { InsuranceSchemeDetailPO po = otherPerson.get(e); BigDecimal paymentProportion = new BigDecimal(StringUtils.isBlank(po.getPaymentProportion()) ? "0" : po.getPaymentProportion()).divide(new BigDecimal("100")); BigDecimal paymentNum = new BigDecimal(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 = SalaryEntityUtil.carryRule(newScale, po.getRententionRule(), paymentNum.multiply(paymentProportion).add(fixedCost)); BigDecimal result = new BigDecimal("0"); if (po.getPaymentCycle() != null && 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)); } otherPerJsonMap.put(String.valueOf(e), result.toPlainString()); otherPer.add(result); }); insuranceAccountDetailPO.setOtherPerJson(JSON.toJSONString(otherPerJsonMap)); BigDecimal otherPerSum = new BigDecimal("0"); for (BigDecimal bigDecimal : otherPer) { otherPerSum = otherPerSum.add(bigDecimal); } insuranceAccountDetailPO.setOtherPerSum(otherPerSum.toPlainString()); //方案中包含的需要缴纳公积金的单位福利 Map otherCom = 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(otherPO.getOtherPaymentBaseString(), new HashMap().getClass()); //需要核算其他的福利id 单位 List needArchivesCom = new ArrayList<>(); if (archivesCom != null) { archivesCom.forEach((id, value) -> { if (otherCom.containsKey(Long.valueOf(id))) { needArchivesCom.add(Long.valueOf(id)); } }); } //判断核算周期、核算月、福利起始缴纳月的关系 checkCycleSettingWithStartMonth(otherCom, billMonth, otherPO.getOtherStartTime()); List otherComList = new ArrayList<>(); Map otherComJsonMap = new HashMap<>(); needArchivesCom.stream().forEach(e -> { InsuranceSchemeDetailPO po = otherCom.get(e); BigDecimal paymentProportion = new BigDecimal(StringUtils.isBlank(po.getPaymentProportion()) ? "0" : po.getPaymentProportion()).divide(new BigDecimal("100")); BigDecimal paymentNum = new BigDecimal(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 = SalaryEntityUtil.carryRule(newScale, po.getRententionRule(), paymentNum.multiply(paymentProportion).add(fixedCost)); 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)); } otherComJsonMap.put(String.valueOf(e), result.toPlainString()); otherComList.add(result); }); insuranceAccountDetailPO.setOtherComJson(JSON.toJSONString(otherComJsonMap)); BigDecimal otherComSum = new BigDecimal("0"); for (BigDecimal bigDecimal : otherComList) { otherComSum = otherComSum.add(bigDecimal); } insuranceAccountDetailPO.setOtherComSum(otherComSum.toPlainString()); } } return insuranceAccountDetailPO; } public InsuranceAccountDetailPO accountFund(InsuranceAccountDetailPO insuranceAccountDetailPO, InsuranceArchivesAccountPO accountPO, String billMonth) { if (accountPO.getFund() != null) { InsuranceArchivesFundSchemePO fundPO = accountPO.getFund(); insuranceAccountDetailPO.setFundPayOrg(fundPO.getPaymentOrganization()); insuranceAccountDetailPO.setFundAccount(fundPO.getFundAccount()); insuranceAccountDetailPO.setSupplementFundAccount(fundPO.getSupplementFundAccount()); insuranceAccountDetailPO.setFundSchemeId(fundPO.getFundSchemeId()); insuranceAccountDetailPO.setFundPaymentBaseString(fundPO.getFundPaymentBaseString()); //判断是否在起始缴纳月和最后缴纳月之间 Boolean inDataRange = SalaryDateUtil.monthInRange(billMonth, fundPO.getFundStartTime(), fundPO.getFundEndTime()); if ((Objects.equals(NonPaymentEnum.YES.getValue(), fundPO.getNonPayment()) || fundPO.getNonPayment() == null) && fundPO.getFundSchemeId() != null && inDataRange) { List detailPOS = MapperProxyFactory.getProxy(InsuranceSchemeDetailMapper.class).queryListBySchemeId(fundPO.getFundSchemeId()); encryptUtil.decryptList(detailPOS, InsuranceSchemeDetailPO.class); //方案中包含的需要缴纳社保的个人福利 int monthIndex = Integer.parseInt(billMonth.split("-")[1]) - 1; Map fundperson = 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(fundPO.getFundPaymentBaseString(), new HashMap().getClass()); //需要核算公积金的福利id 个人 List needArchivesPerson = new ArrayList<>(); if (archivesPerson != null) { archivesPerson.forEach((id, value) -> { if (fundperson.containsKey(Long.valueOf(id))) { needArchivesPerson.add(Long.valueOf(id)); } }); } //判断核算周期、核算月、福利起始缴纳月的关系 checkCycleSettingWithStartMonth(fundperson, billMonth, fundPO.getFundStartTime()); List fundPer = new ArrayList<>(); Map fundPerJsonMap = new HashMap<>(); needArchivesPerson.stream().forEach(e -> { InsuranceSchemeDetailPO po = fundperson.get(e); BigDecimal paymentProportion = new BigDecimal(StringUtils.isBlank(po.getPaymentProportion()) ? "0" : po.getPaymentProportion()).divide(new BigDecimal("100")); BigDecimal paymentNum = new BigDecimal(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 = SalaryEntityUtil.carryRule(newScale, po.getRententionRule(), paymentNum.multiply(paymentProportion).add(fixedCost)); 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)); } fundPerJsonMap.put(String.valueOf(e), result.toPlainString()); fundPer.add(result); }); insuranceAccountDetailPO.setFundPerJson(JSON.toJSONString(fundPerJsonMap)); BigDecimal funPerSum = new BigDecimal("0"); for (BigDecimal bigDecimal : fundPer) { funPerSum = funPerSum.add(bigDecimal); } insuranceAccountDetailPO.setFundPerSum(funPerSum.toPlainString()); //方案中包含的需要缴纳公积金的单位福利 Map fundCom = 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(fundPO.getFundPaymentBaseString(), new HashMap().getClass()); //需要核算公积金的福利id 单位 List needArchivesCom = new ArrayList<>(); if (archivesCom != null) { archivesCom.forEach((id, value) -> { if (fundCom.containsKey(Long.valueOf(id))) { needArchivesCom.add(Long.valueOf(id)); } }); } //判断核算周期、核算月、福利起始缴纳月的关系 checkCycleSettingWithStartMonth(fundCom, billMonth, fundPO.getFundStartTime()); List fundComList = new ArrayList<>(); Map fundComJsonMap = new HashMap<>(); needArchivesCom.stream().forEach(e -> { InsuranceSchemeDetailPO po = fundCom.get(e); BigDecimal paymentProportion = new BigDecimal(StringUtils.isBlank(po.getPaymentProportion()) ? "0" : po.getPaymentProportion()).divide(new BigDecimal("100")); BigDecimal paymentNum = new BigDecimal(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 = SalaryEntityUtil.carryRule(newScale, po.getRententionRule(), paymentNum.multiply(paymentProportion).add(fixedCost)); 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)); } fundComJsonMap.put(String.valueOf(e), result.toPlainString()); fundComList.add(result); }); insuranceAccountDetailPO.setFundComJson(JSON.toJSONString(fundComJsonMap)); BigDecimal fundComSum = new BigDecimal("0"); for (BigDecimal bigDecimal : fundComList) { fundComSum = fundComSum.add(bigDecimal); } insuranceAccountDetailPO.setFundComSum(fundComSum.toPlainString()); } } return insuranceAccountDetailPO; } public InsuranceAccountDetailPO accountSocial(InsuranceAccountDetailPO insuranceAccountDetailPO, InsuranceArchivesAccountPO accountPO, 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()); //判断是否在起始缴纳月和最后缴纳月之间 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 = MapperProxyFactory.getProxy(InsuranceSchemeDetailMapper.class).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) { archivesPerson.forEach((id, value) -> { if (schemeperson.containsKey(Long.valueOf(id))) { needArchivesPerson.add(Long.valueOf(id)); } }); } //判断核算周期、核算月、福利起始缴纳月的关系 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(StringUtils.isBlank(po.getPaymentProportion()) ? "0" : po.getPaymentProportion()).divide(new BigDecimal("100")); BigDecimal paymentNum = new BigDecimal(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 = SalaryEntityUtil.carryRule(newScale, po.getRententionRule(), paymentNum.multiply(paymentProportion).add(fixedCost)); 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) { archivesCom.forEach((id, value) -> { if (schemeCom.containsKey(Long.valueOf(id))) { needArchivesCom.add(Long.valueOf(id)); } }); } //判断核算周期、核算月、福利起始缴纳月的关系 checkCycleSettingWithStartMonth(schemeCom, billMonth, socialPO.getSocialStartTime()); List socialCom = new ArrayList<>(); Map sociaComJsonMap = new HashMap<>(); needArchivesCom.stream().forEach(e -> { InsuranceSchemeDetailPO po = schemeCom.get(e); BigDecimal paymentProportion = new BigDecimal(StringUtils.isBlank(po.getPaymentProportion()) ? "0" : po.getPaymentProportion()).divide(new BigDecimal("100")); BigDecimal paymentNum = new BigDecimal(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 = SalaryEntityUtil.carryRule(newScale, po.getRententionRule(), paymentNum.multiply(paymentProportion).add(fixedCost)); 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 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()); //判断是否在起始缴纳月和最后缴纳月之间 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 = MapperProxyFactory.getProxy(InsuranceSchemeDetailMapper.class).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(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 = SalaryEntityUtil.carryRule(newScale, po.getRententionRule(), paymentNum.multiply(paymentProportion).add(fixedCost)); 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()); // archivesCom.forEach((id, value) -> { // if (schemeCom.containsKey(Long.valueOf(id))) { // needArchivesCom.add(Long.valueOf(id)); // } // }); } 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 = SalaryEntityUtil.string2BigDecimalDefault0(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 = SalaryEntityUtil.carryRule(newScale, po.getRententionRule(), paymentNum.multiply(paymentProportion).add(fixedCost)); 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; } private List> splitDetailList(List list, int groupSize) { int length = list.size(); // 计算可以分成多少组 int num = (length + groupSize - 1) / groupSize; List> newList = new ArrayList<>(num); for (int i = 0; i < num; i++) { // 开始位置 int fromIndex = i * groupSize; // 结束位置 int toIndex = (i + 1) * groupSize < length ? (i + 1) * groupSize : length; newList.add(list.subList(fromIndex, toIndex)); } return newList; } public void batchSaveSupplementAccount(List pos, String billMonth, String tenantKey) { if (CollectionUtils.isEmpty(pos)) { return; } batchSaveAccountInspectDetail(pos, billMonth, tenantKey); 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 deleteCommonAccount(SaveCommonAccountParam param, Long employeeId, String currentUserName) { ValidUtil.doValidator(param); SalaryAssert.notEmpty(param.getIncludes(), SalaryI18nUtil.getI18nLabel(84026, "参数错误")); //根据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(), employeeId, SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY, currentUserName); } public void deleteSupplementaryAccount(List param, Long employeeId, String currentUserName) { SalaryAssert.notEmpty(param, SalaryI18nUtil.getI18nLabel(84026, "参数错误")); boolean valid = param.stream().anyMatch(item -> item.getEmployeeId() == null || StringUtils.isBlank(item.getSupplementaryMonth()) || StringUtils.isBlank(item.getBillMonth())); if (valid) { throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "参数错误")); } 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(), employeeId, SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY, currentUserName); } public void file(String billMonth, Long employeeId, Long paymentOrganization) { // 归档前检查是否有核算异常 // List insuranceAccountInspectPOS = MapperProxyFactory.getProxy(InsuranceAccountInspectMapper.class).getByInspectStatusAndBillMonth(InspectStatusEnum.IGNORE.getValue(),billMonth); // SalaryAssert.isEmpty(insuranceAccountInspectPOS, SalaryI18nUtil.getI18nLabel( 100500, "当前核算月存在核算异常数据")); //开始归档数据 InsuranceAccountBatchPO insuranceAccountBatchPO = getInsuranceAccountBatchMapper().getByBillStatus(billMonth, BillStatusEnum.NOT_ARCHIVED.getValue(), paymentOrganization); encryptUtil.decrypt(insuranceAccountBatchPO, InsuranceAccountBatchPO.class); SalaryAssert.notNull(insuranceAccountBatchPO, SalaryI18nUtil.getI18nLabel(100503, "月份账单不存在")); SalaryAssert.isFalse(Objects.equals(insuranceAccountBatchPO.getBillStatus(), BillStatusEnum.ARCHIVED.getValue()), SalaryI18nUtil.getI18nLabel(100504, "月份账单已归档")); insuranceAccountBatchPO.setBillStatus(BillStatusEnum.ARCHIVED.getValue()); encryptUtil.encrypt(insuranceAccountBatchPO, InsuranceAccountBatchPO.class); getInsuranceAccountBatchMapper().updateById(insuranceAccountBatchPO); //日志记录 // LoggerContext insuranceSchemeContext = new LoggerContext(); // insuranceSchemeContext.setTargetId(String.valueOf(insuranceAccountBatchPO.getId())); // insuranceSchemeContext.setTargetName(insuranceAccountBatchPO.getBillMonth()); // insuranceSchemeContext.setOperateType(OperateTypeEnum.UPDATE.getValue()); // insuranceSchemeContext.setOperateTypeName(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100506, "台账归档")); // insuranceSchemeContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100506, "台账归档")); // insuranceSchemeContext.setNewValues(insuranceAccountBatchPO); // siAccountLoggerTemplate.write(insuranceSchemeContext); } public void accountInspect(Collection ids, String billMonth, Long employeeId, String currentUserName, Long paymentOrganization) { List insuranceAccountInspectPOS = allInspects(ids, billMonth); SalaryAssert.notEmpty(insuranceAccountInspectPOS, SalaryI18nUtil.getI18nLabel(100515, "无核算数据")); 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())); saveCommonAccount(param, employeeId, currentUserName); } //核算补缴 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()), billMonth, employeeId, paymentOrganization); } } public List allInspects(Collection ids, String billMonth) { List list = MapperProxyFactory.getProxy(InsuranceAccountInspectMapper.class).getList(billMonth, InspectStatusEnum.IGNORE.getValue(), ids); if (CollectionUtils.isNotEmpty(list)) { return list; } return Collections.emptyList(); } public PageInfo overView(InsuranceAccountDetailParam queryParam) { // SalaryPageUtil.start(queryParam.getCurrent(),queryParam.getPageSize()); List insuranceAccountDetailPOS = getInsuranceAccountDetailMapper().selectList(queryParam.getBillMonth(), StringUtil.isBlank(queryParam.getPaymentOrganization()) ? null : Long.valueOf(queryParam.getPaymentOrganization())); encryptUtil.decryptList(insuranceAccountDetailPOS, InsuranceAccountDetailPO.class); //获取扣缴义务人信息 List paymentList = MapperProxyFactory.getProxy(TaxAgentMapper.class).listAll(); SalaryAssert.notEmpty(paymentList, SalaryI18nUtil.getI18nLabel(100341, "该租户无扣缴义务人")); Map paymentMap = paymentList.stream().collect(Collectors.toMap(TaxAgentPO::getId, Function.identity())); List insuranceAccountViewListDTOS = buildRecords(insuranceAccountDetailPOS, paymentMap); // List iCategoryPOS = MapperProxyFactory.getProxy(ICategoryMapper.class).listAll(); // Page page = FormatManager.getTablePage(); // Page insuranceAccountViewListDTOPage = new Page<>(page.getCurrent(), insuranceAccountViewListDTOS.size(), insuranceAccountViewListDTOS.size(), // page.isSearchCount()); PageInfo insuranceAccountViewListDTOPage = new PageInfo<>(insuranceAccountViewListDTOS, InsuranceAccountViewListDTO.class); insuranceAccountViewListDTOPage.setTotal(insuranceAccountViewListDTOS.size()); return insuranceAccountViewListDTOPage; } 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(93278, "合计")); 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()); } private List encryptSchemeDetail(List source) { source.forEach(item -> { item.setUpperLimit(AESEncryptUtil.encrypt(item.getUpperLimit())); item.setFixedCost(AESEncryptUtil.encrypt(item.getFixedCost())); item.setLowerLimit(AESEncryptUtil.encrypt(item.getLowerLimit())); }); return source; } private List decryptSchemeDetail(List encryptList) { encryptList.forEach(item -> { item.setUpperLimit(AESEncryptUtil.decrypt(item.getUpperLimit())); item.setFixedCost(AESEncryptUtil.decrypt(item.getFixedCost())); item.setLowerLimit(AESEncryptUtil.decrypt(item.getLowerLimit())); }); return encryptList; } /** * 查询台账id是否已经薪资核算核算过 * * @param param * @return */ public int checkIfBusinessaccounting(InsuranceAccountBatchPO param) { List list = getSIAccountUtilMapper().checkIfBusinessaccounting(param.getId()); return (int) list.stream().filter(e -> e.getBillmonth().equals(e.getTaxcycle().substring(0, 7))).count(); } /** * 更新薪资台账 * * @param param * @return */ public void updateById(InsuranceAccountBatchPO param) { getInsuranceAccountBatchMapper().updateById(param); } /** * 更新福利台账 */ public void updateByEmployeeIdAndBillMonth(InsuranceAccountDetailPO insuranceAccountDetailPO) { getInsuranceAccountDetailMapper().updateByEmployeeIdAndBillMonth(insuranceAccountDetailPO); } public void accountFundByData(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 accountOtherByData(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 accountSocialByData(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 void accountEndowmentInsuranceByData(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()); } } }