package com.engine.salary.biz; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.TypeReference; import com.engine.salary.constant.SalaryDefaultTenantConstant; 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.param.*; import com.engine.salary.entity.siaccount.po.InsuranceAccountBatchPO; import com.engine.salary.entity.siaccount.po.InsuranceAccountDetailPO; import com.engine.salary.entity.siaccount.po.InsuranceAccountDetailTempPO; import com.engine.salary.entity.siaccount.po.InsuranceAccountInspectPO; 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.taxrate.TaxAgent; import com.engine.salary.enums.siaccount.*; import com.engine.salary.enums.sicategory.*; import com.engine.salary.exception.SalaryRunTimeException; import com.engine.salary.mapper.TaxAgentMapper; import com.engine.salary.mapper.datacollection.EmployMapper; import com.engine.salary.mapper.siaccount.InsuranceAccountBatchMapper; import com.engine.salary.mapper.siaccount.InsuranceAccountDetailMapper; import com.engine.salary.mapper.siaccount.InsuranceAccountInspectMapper; import com.engine.salary.mapper.siaccount.SIAccountDetailTempMapper; import com.engine.salary.mapper.sicategory.ICategoryMapper; import com.engine.salary.mapper.sischeme.InsuranceSchemeDetailMapper; import com.engine.salary.service.SIAccountService; import com.engine.salary.service.impl.SIAccountServiceImpl; 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.PageUtil; import com.google.common.collect.Lists; import dm.jdbc.util.IdGenerator; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.session.SqlSession; import org.springframework.beans.BeanUtils; import org.springframework.transaction.annotation.Transactional; import weaver.conn.mybatis.MyBatisFactory; 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; import com.engine.core.impl.Service; /** * @Author weaver_cl * @Description: TODO * @Date 2022/4/11 * @Version V1.0 **/ public class SIAccountBiz extends Service{ private SIArchivesBiz siArchivesBiz = new SIArchivesBiz(); public PageInfo listPage(InsuranceAccountBatchParam queryParam, Long employeeId) { SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); try { InsuranceAccountBatchMapper insuranceAccountBatchMapper = sqlSession.getMapper(InsuranceAccountBatchMapper.class); PageUtil.start(queryParam.getCurrent(), queryParam.getPageSize()); List list = insuranceAccountBatchMapper.list(queryParam); PageInfo pageInfo = new PageInfo<>(list,InsuranceAccountBatchPO.class); return pageInfo; }finally { sqlSession.close(); } } public PageInfo listCommonPage(InsuranceAccountDetailParam queryParam) { SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); try { InsuranceAccountDetailMapper insuranceAccountDetailMapper = sqlSession.getMapper(InsuranceAccountDetailMapper.class); PageUtil.start(queryParam.getCurrent(), queryParam.getPageSize()); queryParam.setPaymentStatus(PaymentStatusEnum.COMMON.getValue()); List list = insuranceAccountDetailMapper.list(queryParam); PageInfo pageInfo = new PageInfo<>(list,InsuranceAccountDetailPO.class); return pageInfo; }finally { sqlSession.close(); } } public void save(boolean flag, AccountParam param,Long employeeId,String currentUserName) { if (flag) { InsuranceAccountBatchPO insuranceAccountBatchPO = MapperProxyFactory.getProxy(InsuranceAccountBatchMapper.class).getByBillMonth(param.getBillMonth()); SalaryAssert.isNull(insuranceAccountBatchPO, SalaryI18nUtil.getI18nLabel( 100461, "所属月份存在核算数据")); InsuranceAccountBatchPO build = InsuranceAccountBatchPO.builder() //.id(IdGenerator.generate()) .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()) .build(); MapperProxyFactory.getProxy(InsuranceAccountBatchMapper.class).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); } account(param.getBillMonth(), employeeId, SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY,currentUserName); } public void account(String billMonth, Long employeeId, String tenantKey,String currentUserName) { List employeeIds = MapperProxyFactory.getProxy(InsuranceAccountDetailMapper.class).selectAccountIds(SalaryDateUtil.getMonthBegin(billMonth)); if (CollectionUtils.isEmpty(employeeIds)) { List list = Lists.newArrayList(MapperProxyFactory.getProxy(InsuranceAccountBatchMapper.class).getByBillMonth(billMonth)); if (CollectionUtils.isNotEmpty(list)) { list.stream().forEach(f -> { MapperProxyFactory.getProxy(InsuranceAccountDetailMapper.class).deleteById(f.getId()); }); } } SalaryAssert.notEmpty(employeeIds, "no account data"); AccountParam param = new AccountParam(); param.setBillMonth(billMonth); ExecutorService taskExecutor = Executors.newCachedThreadPool(); taskExecutor.execute(() -> { try { DSTenantKeyThreadVar.tenantKey.set(tenantKey); accounting(param, employeeId, tenantKey,currentUserName); } finally { DSTenantKeyThreadVar.tenantKey.remove(); } }); } public void accounting(AccountParam param, Long employeeId, String tenantKey,String currentUserName) { //薪资核算进度暂未实现 // SalaryAcctProgressDTO salaryAcctProgressDTO = salaryAcctProgressService.getProgress(tenantKey + param.getBillMonth(), employeeId, tenantKey); // if (salaryAcctProgressDTO != null && salaryAcctProgressDTO.getProgress().compareTo(BigDecimal.ONE) < 0) { // return; // } doAccounting(param, employeeId, tenantKey,currentUserName); } //@Transactional(propagation = Propagation.NEVER, rollbackFor = Exception.class) public void doAccounting(AccountParam param, Long employeeId, String tenantKey,String currentUserName) { try { List ids; if (CollectionUtils.isEmpty(param.getIds())) { ids = MapperProxyFactory.getProxy(InsuranceAccountDetailMapper.class).selectAccountIds(SalaryDateUtil.getMonthBegin(param.getBillMonth())); } else { ids = param.getIds(); } if (CollectionUtils.isEmpty(ids)) { //salaryAcctProgressService.fail(tenantKey + 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); /* 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); /* 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.getBillMonth(), employeeId, tenantKey,currentUserName); /*}*/ MapperProxyFactory.getProxy(SIAccountDetailTempMapper.class).batchDelAccountTempDetails(ids, param.getBillMonth()); } catch (Exception e) { List list = Lists.newArrayList(MapperProxyFactory.getProxy(InsuranceAccountBatchMapper.class).getByBillMonth(param.getBillMonth())); if (CollectionUtils.isNotEmpty(list)) { list.stream().forEach(f -> { MapperProxyFactory.getProxy(InsuranceAccountBatchMapper.class).deleteById(f.getId()); }); } //薪资核算进度暂未实现 //salaryAcctProgressService.del(tenantKey + param.getBillMonth(), employeeId, tenantKey); //logger.error("welfare account error:{}", e.getMessage(), e); } } public void commonAccount(/*CountDownLatch countDownLatch, BlockingDeque results,*/ String billMonth, List ids, Long employeeId, String tenantKey) { /* try {*/ SIArchivesBiz siArchivesBiz = new SIArchivesBiz(); Map insuranceArchivesAccountPOS = siArchivesBiz.buildBatchAccount(ids, tenantKey); 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.setId(IdGenerator.generate()); insuranceAccountDetailPO.setEmployeeId(k); insuranceAccountDetailPO.setUpdateTime(new Date()); insuranceAccountDetailPO.setPaymentStatus(PaymentStatusEnum.COMMON.getValue()); insuranceAccountDetailPO.setResourceFrom(ResourceFromEnum.SYSTEM.getValue()); insuranceAccountDetailPO.setTenantKey(tenantKey); //核算社保 accountSocial(insuranceAccountDetailPO, v, tenantKey); //核算公积金 accountFund(insuranceAccountDetailPO, v, tenantKey); //核算其他福利 accountOther(insuranceAccountDetailPO, v, 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); } } if (CollectionUtils.isNotEmpty(list)) { MapperProxyFactory.getProxy(SIAccountDetailTempMapper.class).batchSaveAccountTempDetails(list); } /* } catch (Exception e) { logger.error("福利核算失败:{}", e.getMessage(), e); results.add(false); } finally { countDownLatch.countDown(); }*/ } private void handleData(List ids, String billMonth, Long employeeId, String tenantKey,String currentUserName) { //事务后续处理 //TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition()); try { List list = MapperProxyFactory.getProxy(SIAccountDetailTempMapper.class).getListByEmployeeIdsAndBillMonth(ids,billMonth); MapperProxyFactory.getProxy(InsuranceAccountDetailMapper.class).batchDelAccountDetails(ids, billMonth); List collect = list.stream().map(item -> { InsuranceAccountDetailPO insuranceAccountDetailPO = new InsuranceAccountDetailPO(); BeanUtils.copyProperties(item, insuranceAccountDetailPO); return insuranceAccountDetailPO; }).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(collect)) { batchSaveAccountInspectDetail(collect, billMonth, tenantKey); MapperProxyFactory.getProxy(InsuranceAccountDetailMapper.class).batchSaveAccountDetails(collect); updateBatchAccount(billMonth, 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 tenantKey) { if (accountPO.getOther() != null) { InsuranceArchivesOtherSchemePO otherPO = accountPO.getOther(); insuranceAccountDetailPO.setOtherPayOrg(otherPO.getPaymentOrganization()); insuranceAccountDetailPO.setOtherSchemeId(otherPO.getOtherSchemeId()); insuranceAccountDetailPO.setOtherPaymentBaseString(otherPO.getOtherPaymentBaseString()); if ((Objects.equals(NonPaymentEnum.YES.getValue(), otherPO.getNonPayment()) || otherPO.getNonPayment() == null) && otherPO.getOtherSchemeId() != null) { List detailPOS = MapperProxyFactory.getProxy(InsuranceSchemeDetailMapper.class).queryListBySchemeId(otherPO.getOtherSchemeId()); //方案中包含的需要缴纳其他的个人福利 Map otherPerson = detailPOS.stream() .filter(item -> Objects.equals(IsPaymentEnum.YES.getValue(), item.getIsPayment()) && item.getPaymentScope() == PaymentScopeEnum.SCOPE_PERSON.getValue()) .collect( Collectors.toMap(InsuranceSchemeDetailPO::getInsuranceId, Function.identity())); //档案中包含的基数信息 HashMap archivesPerson = JSON.parseObject(otherPO.getOtherPaymentBaseString(), new HashMap().getClass()); //需要核算其他的福利id 个人 List needArchivesPerson = new ArrayList<>(); archivesPerson.forEach((id, value) -> { if (otherPerson.containsKey(Long.valueOf(id))) { needArchivesPerson.add(Long.valueOf(id)); } }); 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)); ; 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()) && item.getPaymentScope() == PaymentScopeEnum.SCOPE_COMPANY.getValue()) .collect( Collectors.toMap(InsuranceSchemeDetailPO::getInsuranceId, Function.identity())); //档案中包含的基数信息 HashMap archivesCom = JSON.parseObject(otherPO.getOtherPaymentBaseString(), new HashMap().getClass()); //需要核算其他的福利id 单位 List needArchivesCom = new ArrayList<>(); archivesCom.forEach((id, value) -> { if (otherCom.containsKey(Long.valueOf(id))) { needArchivesCom.add(Long.valueOf(id)); } }); 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)); 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 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()); if ((NonPaymentEnum.YES.getValue() == fundPO.getNonPayment() || fundPO.getNonPayment() == null) && fundPO.getFundSchemeId() != null) { List detailPOS = MapperProxyFactory.getProxy(InsuranceSchemeDetailMapper.class).queryListBySchemeId(fundPO.getFundSchemeId()); //方案中包含的需要缴纳社保的个人福利 Map fundperson = detailPOS.stream() .filter(item -> IsPaymentEnum.YES.getValue() == item.getIsPayment() && item.getPaymentScope() == PaymentScopeEnum.SCOPE_PERSON.getValue()) .collect( Collectors.toMap(InsuranceSchemeDetailPO::getInsuranceId, Function.identity())); //档案中包含的基数信息 HashMap archivesPerson = JSON.parseObject(fundPO.getFundPaymentBaseString(), new HashMap().getClass()); //需要核算公积金的福利id 个人 List needArchivesPerson = new ArrayList<>(); archivesPerson.forEach((id, value) -> { if (fundperson.containsKey(Long.valueOf(id))) { needArchivesPerson.add(Long.valueOf(id)); } }); 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)); ; 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 -> IsPaymentEnum.YES.getValue() == item.getIsPayment() && item.getPaymentScope() == PaymentScopeEnum.SCOPE_COMPANY.getValue()) .collect( Collectors.toMap(InsuranceSchemeDetailPO::getInsuranceId, Function.identity())); //档案中包含的基数信息 HashMap archivesCom = JSON.parseObject(fundPO.getFundPaymentBaseString(), new HashMap().getClass()); //需要核算公积金的福利id 单位 List needArchivesCom = new ArrayList<>(); archivesCom.forEach((id, value) -> { if (fundCom.containsKey(Long.valueOf(id))) { needArchivesCom.add(Long.valueOf(id)); } }); 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)); ; 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 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()); if ((NonPaymentEnum.YES.getValue() == socialPO.getNonPayment() || socialPO.getNonPayment() == null) && socialPO.getSocialSchemeId() != null) { List detailPOS = MapperProxyFactory.getProxy(InsuranceSchemeDetailMapper.class).queryListBySchemeId(socialPO.getSocialSchemeId()); //方案中包含的需要缴纳社保的个人福利 Map schemeperson = detailPOS.stream() .filter(item -> IsPaymentEnum.YES.getValue() == item.getIsPayment() && item.getPaymentScope() == PaymentScopeEnum.SCOPE_PERSON.getValue()) .collect( Collectors.toMap(InsuranceSchemeDetailPO::getInsuranceId, Function.identity())); //档案中包含的基数信息 HashMap archivesPerson = JSON.parseObject(socialPO.getSocialPaymentBaseString(), new HashMap().getClass()); //需要核算社保的福利id 个人 List needArchivesPerson = new ArrayList<>(); archivesPerson.forEach((id, value) -> { if (schemeperson.containsKey(Long.valueOf(id))) { needArchivesPerson.add(Long.valueOf(id)); } }); List socialPer = new ArrayList<>(); Map socialPerJsonMap = new HashMap<>(); needArchivesPerson.stream().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)); ; 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 -> IsPaymentEnum.YES.getValue() == item.getIsPayment() && item.getPaymentScope() == PaymentScopeEnum.SCOPE_COMPANY.getValue()) .collect( Collectors.toMap(InsuranceSchemeDetailPO::getInsuranceId, Function.identity())); //档案中包含的基数信息 HashMap archivesCom = JSON.parseObject(socialPO.getSocialPaymentBaseString(), new HashMap().getClass()); //需要核算社保的福利id 单位 List needArchivesCom = new ArrayList<>(); archivesCom.forEach((id, value) -> { if (schemeCom.containsKey(Long.valueOf(id))) { needArchivesCom.add(Long.valueOf(id)); } }); 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)); sociaComJsonMap.put(String.valueOf(e), result.toPlainString()); socialCom.add(result); }); insuranceAccountDetailPO.setSocialComJson(JSON.toJSONString(sociaComJsonMap)); BigDecimal socialComSum = new BigDecimal("0"); for (BigDecimal decimal : socialCom) { socialComSum = socialComSum.add(decimal); } insuranceAccountDetailPO.setSocialComSum(socialComSum.toPlainString()); } } return insuranceAccountDetailPO; } public void 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.setId(IdGenerator.generate()); 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) { MapperProxyFactory.getProxy(InsuranceAccountInspectMapper.class).batchDelInspectDetails(list); //上报删除日志 // list.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(100445, "删除核算异常记录")); // insuranceSchemeContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(100445, "删除核算异常记录")); // insuranceSchemeContext.setNewValues(item); // siAccountLoggerTemplate.write(insuranceSchemeContext); // }); } public void batchSaveInspectDetail(List list) { MapperProxyFactory.getProxy(InsuranceAccountInspectMapper.class).batchSaveInspectDetails(list); //上报新增日志 // list.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(100447, "新建核算异常记录")); // insuranceSchemeContext.setOperatedesc(SalaryI18nUtil.getI18nLabel(100447, "新建核算异常记录")); // insuranceSchemeContext.setNewValues(item); // siAccountLoggerTemplate.write(insuranceSchemeContext); // }); } /** * 跟新台账接口 * * @param billMonth 账单月份 * @param tenantKey 租户key */ public void updateBatchAccount(String billMonth, Long employeeId, String tenantKey,String currentUserName) { List insuranceAccountDetailPOS = MapperProxyFactory.getProxy(InsuranceAccountDetailMapper.class).selectList(billMonth); 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"); for (InsuranceAccountDetailPO item : v) { BigDecimal socialPerson = StringUtils.isBlank(item.getSocialSum()) ? new BigDecimal("0") : new BigDecimal(item.getSocialSum()); BigDecimal fundPerson = StringUtils.isBlank(item.getFundSum()) ? new BigDecimal("0") : new BigDecimal(item.getFundSum()); BigDecimal otherPerson = StringUtils.isBlank(item.getOtherSum()) ? new BigDecimal("0") : new BigDecimal(item.getOtherSum()); socialTemp = socialTemp.add(socialPerson); fundTemp = fundTemp.add(fundPerson); otherTemp = otherTemp.add(otherPerson); } if (!"0".equals(socialTemp.toPlainString())) { socialSum = socialSum.add(socialTemp); socialAccountPerson += 1; } if (!"0".equals(fundTemp.toPlainString())) { fundSum = fundSum.add(fundTemp); funcAccountPerson += 1; } if (!"0".equals(otherTemp.toPlainString())) { otherSum = otherSum.add(otherTemp); otherAccountPerson += 1; } } InsuranceAccountBatchPO insuranceAccountBatchPO = MapperProxyFactory.getProxy(InsuranceAccountBatchMapper.class).getByBillMonth(billMonth); 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()); MapperProxyFactory.getProxy(InsuranceAccountBatchMapper.class).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 = MapperProxyFactory.getProxy(InsuranceAccountBatchMapper.class).getByBillMonth(param.getBillMonth()); SalaryAssert.notNull(insuranceAccountBatchPO, SalaryI18nUtil.getI18nLabel( 84026, "参数错误")); MapperProxyFactory.getProxy(InsuranceAccountBatchMapper.class).deleteById(insuranceAccountBatchPO.getId()); MapperProxyFactory.getProxy(InsuranceAccountDetailMapper.class).batchDeleteNotFile(param.getBillMonth()); // 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()); } 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) .projects(param.getProjects()) .billMonth(param.getBillMonth()) .build(); baseList.add(supplementAccountBaseParam); }); }); //核算开始 accountSupplement(baseList, employeeIds, param.getBillMonth(),employeeId); updateBatchAccount(param.getBillMonth(), employeeId,SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY,currentUserName); } /** * @param baseList 员工id-账单月份-补缴月份(单挑)-补缴项 集合 * @param employeeIds 需要补缴的员工id * @return */ public String accountSupplement(List baseList, List employeeIds, String billMonth,Long employeeId) { //(k,v) k-员工id v-员工对应的福利档案数据 Map longInsuranceArchivesAccountPOMap = siArchivesBiz.buildBatchAccount(employeeIds,SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY); //核算结果集 List pos = new ArrayList<>(); baseList.forEach(baseParam -> { 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.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()); if (projects.contains(ProjectTypeEnum.ALL.getValue())) { accountSocial(insuranceAccountDetailPO, accountPO); accountFund(insuranceAccountDetailPO, accountPO); accountOther(insuranceAccountDetailPO, accountPO); return account(insuranceAccountDetailPO); } if (projects.contains(ProjectTypeEnum.SOCIAL.getValue())) { accountSocial(insuranceAccountDetailPO, accountPO); } 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()); } accountEndowmentInsurance(insuranceAccountDetailPO, accountPO, ids); } if (projects.contains(ProjectTypeEnum.FUND.getValue())) { accountFund(insuranceAccountDetailPO, accountPO); } if (projects.contains(ProjectTypeEnum.OTHER.getValue())) { accountOther(insuranceAccountDetailPO, accountPO); } return account(insuranceAccountDetailPO); } public InsuranceAccountDetailPO accountOther(InsuranceAccountDetailPO insuranceAccountDetailPO, InsuranceArchivesAccountPO accountPO) { if (accountPO.getOther() != null) { InsuranceArchivesOtherSchemePO otherPO = accountPO.getOther(); insuranceAccountDetailPO.setOtherPayOrg(otherPO.getPaymentOrganization()); insuranceAccountDetailPO.setOtherSchemeId(otherPO.getOtherSchemeId()); insuranceAccountDetailPO.setOtherPaymentBaseString(otherPO.getOtherPaymentBaseString()); if ((Objects.equals(NonPaymentEnum.YES.getValue(), otherPO.getNonPayment()) || otherPO.getNonPayment() == null) && otherPO.getOtherSchemeId() != null) { List detailPOS = MapperProxyFactory.getProxy(InsuranceSchemeDetailMapper.class).queryListBySchemeId(otherPO.getOtherSchemeId()); //方案中包含的需要缴纳其他的个人福利 Map otherPerson = detailPOS.stream() .filter(item -> Objects.equals(IsPaymentEnum.YES.getValue(), item.getIsPayment()) && item.getPaymentScope() == PaymentScopeEnum.SCOPE_PERSON.getValue()) .collect( Collectors.toMap(InsuranceSchemeDetailPO::getInsuranceId, Function.identity())); //档案中包含的基数信息 HashMap archivesPerson = JSON.parseObject(otherPO.getOtherPaymentBaseString(), new HashMap().getClass()); //需要核算其他的福利id 个人 List needArchivesPerson = new ArrayList<>(); archivesPerson.forEach((id, value) -> { if (otherPerson.containsKey(Long.valueOf(id))) { needArchivesPerson.add(Long.valueOf(id)); } }); 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)); ; 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()) && item.getPaymentScope() == PaymentScopeEnum.SCOPE_COMPANY.getValue()) .collect( Collectors.toMap(InsuranceSchemeDetailPO::getInsuranceId, Function.identity())); //档案中包含的基数信息 HashMap archivesCom = JSON.parseObject(otherPO.getOtherPaymentBaseString(), new HashMap().getClass()); //需要核算其他的福利id 单位 List needArchivesCom = new ArrayList<>(); archivesCom.forEach((id, value) -> { if (otherCom.containsKey(Long.valueOf(id))) { needArchivesCom.add(Long.valueOf(id)); } }); 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)); ; 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) { 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()); if ((NonPaymentEnum.YES.getValue() == fundPO.getNonPayment() || fundPO.getNonPayment() == null) && fundPO.getFundSchemeId() != null) { List detailPOS = MapperProxyFactory.getProxy(InsuranceSchemeDetailMapper.class).queryListBySchemeId(fundPO.getFundSchemeId()); //方案中包含的需要缴纳社保的个人福利 Map fundperson = detailPOS.stream() .filter(item -> IsPaymentEnum.YES.getValue() == item.getIsPayment() && item.getPaymentScope() == PaymentScopeEnum.SCOPE_PERSON.getValue()) .collect( Collectors.toMap(InsuranceSchemeDetailPO::getInsuranceId, Function.identity())); //档案中包含的基数信息 HashMap archivesPerson = JSON.parseObject(fundPO.getFundPaymentBaseString(), new HashMap().getClass()); //需要核算公积金的福利id 个人 List needArchivesPerson = new ArrayList<>(); archivesPerson.forEach((id, value) -> { if (fundperson.containsKey(Long.valueOf(id))) { needArchivesPerson.add(Long.valueOf(id)); } }); 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)); ; 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 -> IsPaymentEnum.YES.getValue() == item.getIsPayment() && item.getPaymentScope() == PaymentScopeEnum.SCOPE_COMPANY.getValue()) .collect( Collectors.toMap(InsuranceSchemeDetailPO::getInsuranceId, Function.identity())); //档案中包含的基数信息 HashMap archivesCom = JSON.parseObject(fundPO.getFundPaymentBaseString(), new HashMap().getClass()); //需要核算公积金的福利id 单位 List needArchivesCom = new ArrayList<>(); archivesCom.forEach((id, value) -> { if (fundCom.containsKey(Long.valueOf(id))) { needArchivesCom.add(Long.valueOf(id)); } }); 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)); ; 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) { if (accountPO.getSocial() != null) { InsuranceArchivesSocialSchemePO socialPO = accountPO.getSocial(); insuranceAccountDetailPO.setSocialPayOrg(socialPO.getPaymentOrganization()); insuranceAccountDetailPO.setSocialAccount(socialPO.getSocialAccount()); insuranceAccountDetailPO.setSocialSchemeId(socialPO.getSocialSchemeId()); insuranceAccountDetailPO.setSocialPaymentBaseString(socialPO.getSocialPaymentBaseString()); if ((NonPaymentEnum.YES.getValue() == socialPO.getNonPayment() || socialPO.getNonPayment() == null) && socialPO.getSocialSchemeId() != null) { List detailPOS = MapperProxyFactory.getProxy(InsuranceSchemeDetailMapper.class).queryListBySchemeId(socialPO.getSocialSchemeId()); //方案中包含的需要缴纳社保的个人福利 Map schemeperson = detailPOS.stream() .filter(item -> IsPaymentEnum.YES.getValue() == item.getIsPayment() && item.getPaymentScope() == PaymentScopeEnum.SCOPE_PERSON.getValue()) .collect( Collectors.toMap(InsuranceSchemeDetailPO::getInsuranceId, Function.identity())); //档案中包含的基数信息 HashMap archivesPerson = JSON.parseObject(socialPO.getSocialPaymentBaseString(), new HashMap().getClass()); //需要核算社保的福利id 个人 List needArchivesPerson = new ArrayList<>(); archivesPerson.forEach((id, value) -> { if (schemeperson.containsKey(Long.valueOf(id))) { needArchivesPerson.add(Long.valueOf(id)); } }); List socialPer = new ArrayList<>(); Map socialPerJsonMap = new HashMap<>(); needArchivesPerson.stream().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)); 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 -> IsPaymentEnum.YES.getValue() == item.getIsPayment() && item.getPaymentScope() == PaymentScopeEnum.SCOPE_COMPANY.getValue()) .collect( Collectors.toMap(InsuranceSchemeDetailPO::getInsuranceId, Function.identity())); //档案中包含的基数信息 HashMap archivesCom = JSON.parseObject(socialPO.getSocialPaymentBaseString(), new HashMap().getClass()); //需要核算社保的福利id 单位 List needArchivesCom = new ArrayList<>(); archivesCom.forEach((id, value) -> { if (schemeCom.containsKey(Long.valueOf(id))) { needArchivesCom.add(Long.valueOf(id)); } }); 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)); 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) { if (accountPO.getSocial() != null) { InsuranceArchivesSocialSchemePO socialPO = accountPO.getSocial(); insuranceAccountDetailPO.setSocialPayOrg(socialPO.getPaymentOrganization()); insuranceAccountDetailPO.setSocialAccount(socialPO.getSocialAccount()); insuranceAccountDetailPO.setSocialSchemeId(socialPO.getSocialSchemeId()); insuranceAccountDetailPO.setSocialPaymentBaseString(socialPO.getSocialPaymentBaseString()); if ((NonPaymentEnum.YES.getValue() == socialPO.getNonPayment() || socialPO.getNonPayment() == null) && socialPO.getSocialSchemeId() != null) { List detailPOS = MapperProxyFactory.getProxy(InsuranceSchemeDetailMapper.class).queryListBySchemeId(socialPO.getSocialSchemeId()); //方案中包含的需要缴纳社保的个人福利 Map schemeperson = detailPOS.stream() .filter(item -> IsPaymentEnum.YES.getValue() == item.getIsPayment() && item.getPaymentScope() == PaymentScopeEnum.SCOPE_PERSON.getValue()) .collect( Collectors.toMap(InsuranceSchemeDetailPO::getInsuranceId, Function.identity())); //档案中包含的基数信息 HashMap archivesPerson = JSON.parseObject(socialPO.getSocialPaymentBaseString(), new HashMap().getClass()); //需要核算社保的福利id 个人 List needArchivesPerson = new ArrayList<>(); categoryIds.forEach(item -> { if (archivesPerson.containsKey(String.valueOf(item)) && schemeperson.containsKey(item)) { needArchivesPerson.add(item); } }); List socialPer = new ArrayList<>(); Map socialPerJsonMap = new HashMap<>(); needArchivesPerson.stream().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)); ; 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 -> IsPaymentEnum.YES.getValue() == item.getIsPayment() && item.getPaymentScope() == PaymentScopeEnum.SCOPE_COMPANY.getValue()) .collect( Collectors.toMap(InsuranceSchemeDetailPO::getInsuranceId, Function.identity())); //档案中包含的基数信息 HashMap archivesCom = JSON.parseObject(socialPO.getSocialPaymentBaseString(), new HashMap().getClass()); //需要核算社保的福利id 单位 List needArchivesCom = new ArrayList<>(); archivesCom.forEach((id, value) -> { if (schemeCom.containsKey(Long.valueOf(id))) { needArchivesCom.add(Long.valueOf(id)); } }); List socialCom = new ArrayList<>(); Map sociaComJsonMap = new HashMap<>(); needArchivesCom.stream().forEach(e -> { InsuranceSchemeDetailPO po = schemeCom.get(e); BigDecimal paymentProportion = new BigDecimal(po.getPaymentProportion()).divide(new BigDecimal("100")); BigDecimal paymentNum = new BigDecimal(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)); ; 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; } @Transactional public void batchSaveSupplementAccount(List pos, String billMonth, String tenantKey) { if (CollectionUtils.isEmpty(pos)) { return; } batchSaveAccountInspectDetail(pos, billMonth, tenantKey); MapperProxyFactory.getProxy(InsuranceAccountDetailMapper.class).batchDelSupplementAccountDetails(pos); MapperProxyFactory.getProxy(InsuranceAccountDetailMapper.class).batchSaveAccountDetails(pos); //删除日志 // 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) { SalaryAssert.notBlank(param.getBillMonth(), SalaryI18nUtil.getI18nLabel( 84026, "参数错误")); SalaryAssert.notEmpty(param.getIncludes(), SalaryI18nUtil.getI18nLabel( 84026, "参数错误")); MapperProxyFactory.getProxy(InsuranceAccountDetailMapper.class).batchDelAccountDetails(param.getIncludes(), param.getBillMonth()); //记录日志 // 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(param.getBillMonth(), 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, "参数错误")); } MapperProxyFactory.getProxy(InsuranceAccountDetailMapper.class).batchDelSupplementDetailsByIds(param); // param.stream().forEach(item -> { // LoggerContext insuranceSchemeContext = new LoggerContext(); // insuranceSchemeContext.setTargetId(String.valueOf(IdGenerator.generate())); // 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(param.get(0).getBillMonth(), employeeId, SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY,currentUserName); } public void file(String billMonth, Long employeeId) { //归档前检查是否有核算异常 List insuranceAccountInspectPOS = MapperProxyFactory.getProxy(InsuranceAccountInspectMapper.class).getByInspectStatusAndBillMonth(InspectStatusEnum.IGNORE.getValue(),billMonth); SalaryAssert.isEmpty(insuranceAccountInspectPOS, SalaryI18nUtil.getI18nLabel( 100500, "当前核算月存在核算异常数据")); //开始归档数据 InsuranceAccountBatchPO insuranceAccountBatchPO = MapperProxyFactory.getProxy(InsuranceAccountBatchMapper.class).getByBillStatus(billMonth,BillStatusEnum.NOT_ARCHIVED.getValue()); SalaryAssert.notNull(insuranceAccountBatchPO, SalaryI18nUtil.getI18nLabel( 100503, "月份账单不存在")); SalaryAssert.isFalse(insuranceAccountBatchPO.getBillStatus() == BillStatusEnum.ARCHIVED.getValue(), SalaryI18nUtil.getI18nLabel( 100504, "月份账单已归档")); insuranceAccountBatchPO.setBillStatus(BillStatusEnum.ARCHIVED.getValue()); MapperProxyFactory.getProxy(InsuranceAccountBatchMapper.class).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) { 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); } } 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) { PageUtil.start(queryParam.getCurrent(),queryParam.getPageSize()); List insuranceAccountDetailPOS = MapperProxyFactory.getProxy(InsuranceAccountDetailMapper.class).selectList(queryParam.getBillMonth()); //获取扣缴义务人信息 List paymentList = MapperProxyFactory.getProxy(TaxAgentMapper.class).listAll(); SalaryAssert.notEmpty(paymentList, SalaryI18nUtil.getI18nLabel( 100341, "该租户无扣缴义务人")); Map paymentMap = paymentList.stream().collect(Collectors.toMap(TaxAgent::getId, Function.identity())); List insuranceAccountViewListDTOS = 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.getFundPayOrg() != null) .collect(Collectors.groupingBy(InsuranceAccountDetailPO::getFundPayOrg)); 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.getOtherPayOrg() != null) .collect(Collectors.groupingBy(InsuranceAccountDetailPO::getOtherPayOrg)); 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())) { 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())) { 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())) { socialNum += 1; socialPaySum = socialPaySum.add(new BigDecimal(item.getSocialSum())); } } dto.setSocialNum(socialNum); dto.setSocialPaySum(socialPaySum.toPlainString()); } }