|
@@ -1,15 +1,19 @@
|
|
|
package com.gree.mall.manager.logic.settle.repair;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.gree.mall.manager.bean.admin.AdminUserCom;
|
|
|
+import com.gree.mall.manager.bean.settle.repair.DailyImportSummaryItemVO;
|
|
|
import com.gree.mall.manager.bean.settle.repair.DailyImportSummaryVO;
|
|
|
import com.gree.mall.manager.bean.settle.repair.DailyTotalCostBean;
|
|
|
import com.gree.mall.manager.commonmapper.CommonMapper;
|
|
|
import com.gree.mall.manager.commonmapper.DailyMapper;
|
|
|
+import com.gree.mall.manager.constant.Constant;
|
|
|
import com.gree.mall.manager.constant.DailyConstant;
|
|
|
import com.gree.mall.manager.constant.SysDictConstant;
|
|
|
+import com.gree.mall.manager.enums.repair.settle.DictCodeEnum;
|
|
|
import com.gree.mall.manager.exception.RemoteServiceException;
|
|
|
import com.gree.mall.manager.logic.common.CommonLogic;
|
|
|
import com.gree.mall.manager.plus.entity.*;
|
|
@@ -48,6 +52,8 @@ public class DailyImportSummaryLogic {
|
|
|
private final SettleDailyIssueSummaryRecordService settleDailyIssueSummaryRecordService;
|
|
|
private final SysDictCompanyService sysDictCompanyService;
|
|
|
private final SettleDailyWithholdService settleDailyWithholdService;
|
|
|
+ private final SettleDailyResidualInsuranceService settleDailyResidualInsuranceService;
|
|
|
+ private final SettleDailyRemaineBuckleService settleDailyRemaineBuckleService;
|
|
|
|
|
|
|
|
|
public IPage<DailyImportSummaryVO> page(ZfireParamBean zfireParamBean) {
|
|
@@ -380,9 +386,9 @@ public class DailyImportSummaryLogic {
|
|
|
}
|
|
|
//处理本月要扣的工伤残保金,扣不完则留到历史费用
|
|
|
//2.扣工伤残保,并产生新的待扣记录
|
|
|
-// issue = this.deductGscb(opName, nowMonth, summaryBatchNo, issue, cost, withholds);
|
|
|
+ issue = this.deductGscb(opName, nowMonth, summaryBatchNo, issue, cost, withholds, adminUser);
|
|
|
//3.处理历史待扣
|
|
|
-// issue = this.historyAmount(issue, summaryBatchNo, opName);
|
|
|
+ issue = this.historyAmount(issue, summaryBatchNo, opName, adminUser);
|
|
|
}
|
|
|
issueList.add(issue);
|
|
|
}
|
|
@@ -404,4 +410,325 @@ public class DailyImportSummaryLogic {
|
|
|
}
|
|
|
settleDailyImportSummaryItemService.updateBatchById(updateList, 500);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 扣本月的工伤残保
|
|
|
+ */
|
|
|
+ public SettleDailyIssueSummaryRecord deductGscb(String opName, String nowMonth, String summaryBatchNo, SettleDailyIssueSummaryRecord issue, DailyTotalCostBean cost, List<SettleDailyWithhold> withholds, AdminUserCom adminUser) {
|
|
|
+
|
|
|
+ BigDecimal issueCost = issue.getIssueCost();
|
|
|
+ //查询本月是否有扣除记录
|
|
|
+ Integer count = settleDailyResidualInsuranceService.lambdaQuery()
|
|
|
+ .eq(SettleDailyResidualInsurance::getCompanyWechatId, adminUser.getAdminCompanyWechat().getCompanyWechatId())
|
|
|
+ .eq(SettleDailyResidualInsurance::getSendMonth, nowMonth)
|
|
|
+ .eq(SettleDailyResidualInsurance::getIdcard, cost.getIdCard())
|
|
|
+// .eq(DailyResidualInsurance::getMobile,cost.getMobile())
|
|
|
+ .eq(SettleDailyResidualInsurance::getName, cost.getRepairWorkerName())
|
|
|
+ .count();
|
|
|
+ if (count == 0) {
|
|
|
+ //残保金月份扣除记录表
|
|
|
+ SettleDailyResidualInsurance insurance = new SettleDailyResidualInsurance();
|
|
|
+ insurance.setServiceNumber(cost.getWorkerNumber());
|
|
|
+ insurance.setMobile(cost.getMobile());
|
|
|
+ insurance.setIdcard(cost.getIdCard());
|
|
|
+ insurance.setName(cost.getRepairWorkerName());
|
|
|
+ insurance.setSendMonth(nowMonth);
|
|
|
+ insurance.setCreateTime(new Date());
|
|
|
+ insurance.setCreateBy(opName);
|
|
|
+ insurance.setSummaryBatchNo(summaryBatchNo);
|
|
|
+ insurance.insert();
|
|
|
+
|
|
|
+ for (SettleDailyWithhold withhold : withholds) {
|
|
|
+ BigDecimal withholdAmount = withhold.getAmount();
|
|
|
+ //减掉本次要扣的钱之后的钱
|
|
|
+ BigDecimal subAmount = issueCost.subtract(withholdAmount);
|
|
|
+ //处理工伤
|
|
|
+ if (DictCodeEnum.EMP_RESIDUAL_DAILY.getName().equals(withhold.getName())) {
|
|
|
+ issue.setShouldEmpInsuranceCost(withholdAmount);
|
|
|
+
|
|
|
+ if (subAmount.doubleValue() < 0) {
|
|
|
+ //本次扣的工伤(所有钱)
|
|
|
+ issue.setEmpInsuranceCost(issueCost);
|
|
|
+ //不够扣,应发金额为0
|
|
|
+ issueCost = BigDecimal.valueOf(0);
|
|
|
+ //记录下次要扣的钱
|
|
|
+ SettleDailyRemaineBuckle dailyRemaineBuckle = supplyRemaineBuckle(subAmount, DictCodeEnum.EMP_RESIDUAL_DAILY.toString(), cost.getWorkerNumber(),
|
|
|
+ Constant.DAILY_PREFIX + summaryBatchNo, cost.getWebsitName(), cost.getWebsitNumber(), opName, cost.getIdCard());
|
|
|
+
|
|
|
+ log.info("【产生历史待扣费用11】:{}", JSONObject.toJSONString(dailyRemaineBuckle));
|
|
|
+
|
|
|
+ dailyRemaineBuckle.insert();
|
|
|
+ } else {
|
|
|
+ // 应发金额 = 应发金额 - 扣掉该扣的钱
|
|
|
+ issueCost = subAmount;
|
|
|
+ // 已扣完工伤
|
|
|
+ issue.setEmpInsuranceCost(withholdAmount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //处理残保金
|
|
|
+ if (DictCodeEnum.INSURANCE_DAILY.getName().equals(withhold.getName())) {
|
|
|
+ issue.setShouldResidualInsuranceCost(withhold.getAmount());
|
|
|
+ issue.setResidualInsuranceCost(new BigDecimal(0));
|
|
|
+
|
|
|
+ if (subAmount.doubleValue() < 0) {
|
|
|
+ //本次已扣残保金
|
|
|
+ issue.setResidualInsuranceCost(issueCost);
|
|
|
+ //不够扣,应发金额为0
|
|
|
+ issueCost = BigDecimal.valueOf(0);
|
|
|
+ //记录下次要扣的钱
|
|
|
+ SettleDailyRemaineBuckle dailyRemaineBuckle = this.supplyRemaineBuckle(subAmount, DictCodeEnum.INSURANCE_DAILY.toString(), cost.getWorkerNumber(),
|
|
|
+ Constant.DAILY_PREFIX + summaryBatchNo, cost.getWebsitName(), cost.getWebsitNumber(), opName, cost.getIdCard());
|
|
|
+
|
|
|
+ log.info("【产生历史待扣费用12】:{}", JSONObject.toJSONString(dailyRemaineBuckle));
|
|
|
+
|
|
|
+ dailyRemaineBuckle.insert();
|
|
|
+ } else {
|
|
|
+ // 应发金额 = 应发金额 - 扣掉该扣的钱
|
|
|
+ issueCost = subAmount;
|
|
|
+ // 已扣完残保金
|
|
|
+ issue.setResidualInsuranceCost(withholdAmount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ issue.setIssueCost(issueCost);
|
|
|
+ return issue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理历史费用
|
|
|
+ *
|
|
|
+ * @param issue 汇总数据
|
|
|
+ * @param adminUser
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public SettleDailyIssueSummaryRecord historyAmount(SettleDailyIssueSummaryRecord issue, String summaryBatchNo, String opName, AdminUserCom adminUser) {
|
|
|
+ if (issue.getIssueCost().doubleValue() == 0) {
|
|
|
+ return issue;
|
|
|
+ }
|
|
|
+ List<SettleDailyRemaineBuckle> buckles = settleDailyRemaineBuckleService.lambdaQuery()
|
|
|
+ //.eq(DailyRemaineBuckle::getWorkerNumber,issue.getServiceNumber())
|
|
|
+ .eq(SettleDailyRemaineBuckle::getCompanyWechatId, adminUser.getAdminCompanyWechat().getCompanyWechatId())
|
|
|
+ .eq(SettleDailyRemaineBuckle::getIdcard, issue.getIdCard())
|
|
|
+ //.eq(DailyRemaineBuckle::getSummaryNumber,issue.getSummaryNumber())
|
|
|
+ .eq(SettleDailyRemaineBuckle::getIsBuckle, false)
|
|
|
+ .list();
|
|
|
+ if (CollectionUtils.isEmpty(buckles)) {
|
|
|
+ return issue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //将所有未处理的历史数据都标记为本次已处理,后续逻辑将会产生新的历史待扣记录
|
|
|
+ List<String> buckleIds = buckles.stream().map(SettleDailyRemaineBuckle::getId).collect(Collectors.toList());
|
|
|
+ settleDailyRemaineBuckleService.lambdaUpdate()
|
|
|
+ .set(SettleDailyRemaineBuckle::getSummaryBatchNo, summaryBatchNo)
|
|
|
+ .set(SettleDailyRemaineBuckle::getIsBuckle, true)
|
|
|
+ .set(SettleDailyRemaineBuckle::getUpdateTime, new Date())
|
|
|
+ .set(SettleDailyRemaineBuckle::getUpdateBy, opName)
|
|
|
+ .in(SettleDailyRemaineBuckle::getId, buckleIds).update();
|
|
|
+
|
|
|
+ String summaryBatchNoTmp = Constant.DAILY_PREFIX + summaryBatchNo;
|
|
|
+
|
|
|
+ //增减费用
|
|
|
+ for (SettleDailyRemaineBuckle remaine : buckles) {
|
|
|
+ //历史费用
|
|
|
+ BigDecimal amount = remaine.getBuckleAmount();
|
|
|
+ if (DictCodeEnum.INCR_DECR_DAILY.toString().equals(remaine.getCostType())) {
|
|
|
+
|
|
|
+ BigDecimal sum = issue.getIssueCost().add(amount);
|
|
|
+ if (sum.doubleValue() > 0) {
|
|
|
+ //记录增减费用
|
|
|
+ issue.setIncrDecrCost(issue.getIncrDecrCost().add(amount));
|
|
|
+ //还剩多少钱
|
|
|
+ issue.setIssueCost(sum);
|
|
|
+ } else {
|
|
|
+ issue.setIncrDecrCost(issue.getIncrDecrCost().add(issue.getIssueCost()));
|
|
|
+ issue.setIssueCost(BigDecimal.valueOf(0));
|
|
|
+ //产生历史费用
|
|
|
+ //记录下次要扣的钱(这里不需要生成临时的批次号,驳回的时候也依据这个临时的批次号删除)
|
|
|
+ SettleDailyRemaineBuckle dailyRemaineBuckle = this.supplyRemaineBuckle(sum, remaine.getCostType(), remaine.getWorkerNumber(),
|
|
|
+ summaryBatchNoTmp, remaine.getWebsitName(), remaine.getWebsitNumber(), opName, remaine.getIdcard());
|
|
|
+ dailyRemaineBuckle.insert();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (issue.getIssueCost().doubleValue() == 0) {
|
|
|
+ return issue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理扣回费用
|
|
|
+ for (SettleDailyRemaineBuckle remaine : buckles) {
|
|
|
+ //历史费用
|
|
|
+ BigDecimal amount = remaine.getBuckleAmount();
|
|
|
+ if (DictCodeEnum.REDUCE_DAILY.toString().equals(remaine.getCostType())) {
|
|
|
+ if (amount.doubleValue() > 0) {
|
|
|
+ amount = BigDecimal.valueOf(0).subtract(amount);
|
|
|
+ }
|
|
|
+ BigDecimal sum = issue.getIssueCost().add(amount);
|
|
|
+ if (sum.doubleValue() > 0) {
|
|
|
+ //应扣回费用
|
|
|
+ issue.setShouldReduceCost(issue.getShouldReduceCost().add(amount.doubleValue() < 0 ? BigDecimal.valueOf(0).subtract(amount) : amount));
|
|
|
+ //实际已扣回费用
|
|
|
+ issue.setReduceCost(issue.getReduceCost().add(amount.doubleValue() < 0 ? BigDecimal.valueOf(0).subtract(amount) : amount));
|
|
|
+
|
|
|
+ issue.setIssueCost(sum);
|
|
|
+ } else {
|
|
|
+ issue.setReduceCost(issue.getReduceCost().add(issue.getIssueCost()));
|
|
|
+ issue.setIssueCost(BigDecimal.valueOf(0));
|
|
|
+ //产生历史费用
|
|
|
+ //记录下次要扣的钱(这里不需要生成临时的批次号,驳回的时候也依据这个临时的批次号删除)
|
|
|
+ SettleDailyRemaineBuckle dailyRemaineBuckle = this.supplyRemaineBuckle(sum, remaine.getCostType(), remaine.getWorkerNumber(),
|
|
|
+ summaryBatchNoTmp, remaine.getWebsitName(), remaine.getWebsitNumber(), opName, remaine.getIdcard());
|
|
|
+ dailyRemaineBuckle.insert();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (issue.getIssueCost().doubleValue() == 0) {
|
|
|
+ return issue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理历史的工伤残保金
|
|
|
+ for (SettleDailyRemaineBuckle remaine : buckles) {
|
|
|
+ //历史费用
|
|
|
+ BigDecimal amount = remaine.getBuckleAmount();
|
|
|
+
|
|
|
+ BigDecimal sum = issue.getIssueCost().add(amount);
|
|
|
+ if (DictCodeEnum.INSURANCE_DAILY.toString().equals(remaine.getCostType())
|
|
|
+ || DictCodeEnum.EMP_RESIDUAL_DAILY.toString().equals(remaine.getCostType())) {
|
|
|
+
|
|
|
+ if (sum.doubleValue() > 0) {
|
|
|
+ if (DictCodeEnum.INSURANCE_DAILY.toString().equals(remaine.getCostType())) {
|
|
|
+ //残保金应扣
|
|
|
+ issue.setShouldResidualInsuranceCost(issue.getShouldResidualInsuranceCost()
|
|
|
+ .add(amount.doubleValue() < 0 ? BigDecimal.valueOf(0).subtract(amount) : amount));
|
|
|
+ //残保金已扣
|
|
|
+ issue.setResidualInsuranceCost(issue.getResidualInsuranceCost()
|
|
|
+ .add(amount.doubleValue() < 0 ? BigDecimal.valueOf(0).subtract(amount) : amount));
|
|
|
+
|
|
|
+ } else {
|
|
|
+ //工伤保险应扣
|
|
|
+ issue.setShouldEmpInsuranceCost(issue.getShouldEmpInsuranceCost()
|
|
|
+ .add(amount.doubleValue() < 0 ? BigDecimal.valueOf(0).subtract(amount) : amount));
|
|
|
+ //工伤保险已扣
|
|
|
+ issue.setEmpInsuranceCost(issue.getEmpInsuranceCost()
|
|
|
+ .add(amount.doubleValue() < 0 ? BigDecimal.valueOf(0).subtract(amount) : amount));
|
|
|
+ }
|
|
|
+ issue.setIssueCost(sum);
|
|
|
+ } else {
|
|
|
+ //不够扣
|
|
|
+ if (DictCodeEnum.INSURANCE_DAILY.toString().equals(remaine.getCostType())) {
|
|
|
+ //残保金应扣
|
|
|
+ issue.setShouldResidualInsuranceCost(issue.getShouldResidualInsuranceCost()
|
|
|
+ .add(amount.doubleValue() < 0 ? BigDecimal.valueOf(0).subtract(amount) : amount));
|
|
|
+ //残保金已扣
|
|
|
+ issue.setResidualInsuranceCost(issue.getResidualInsuranceCost()
|
|
|
+ .add(issue.getIssueCost()));
|
|
|
+ } else {
|
|
|
+ //工伤保险应扣
|
|
|
+ issue.setShouldEmpInsuranceCost(issue.getShouldEmpInsuranceCost()
|
|
|
+ .add(amount.doubleValue() < 0 ? BigDecimal.valueOf(0).subtract(amount) : amount));
|
|
|
+ //工伤保险已扣
|
|
|
+ issue.setEmpInsuranceCost(issue.getEmpInsuranceCost().add(issue.getIssueCost()));
|
|
|
+ }
|
|
|
+ issue.setIssueCost(BigDecimal.valueOf(0));
|
|
|
+ //产生历史费用
|
|
|
+ //记录下次要扣的钱(这里不需要生成临时的批次号,驳回的时候也依据这个临时的批次号删除)
|
|
|
+ SettleDailyRemaineBuckle dailyRemaineBuckle = this.supplyRemaineBuckle(sum, remaine.getCostType(), remaine.getWorkerNumber(),
|
|
|
+ summaryBatchNoTmp, remaine.getWebsitName(), remaine.getWebsitNumber(), opName, remaine.getIdcard());
|
|
|
+
|
|
|
+ log.info("【产生历史待扣费用2】:{}", JSONObject.toJSONString(dailyRemaineBuckle));
|
|
|
+
|
|
|
+ dailyRemaineBuckle.insert();
|
|
|
+ }
|
|
|
+
|
|
|
+ remaine.setSummaryBatchNo(summaryBatchNo);
|
|
|
+ remaine.setIsBuckle(true);
|
|
|
+ remaine.setUpdateTime(new Date());
|
|
|
+ remaine.updateById();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return issue;
|
|
|
+ }
|
|
|
+
|
|
|
+ public SettleDailyRemaineBuckle supplyRemaineBuckle(BigDecimal buckle, String type, String workerNumber,
|
|
|
+ String summaryBatchNo, String websiteName, String websiteNumber, String opName, String idcard) {
|
|
|
+ SettleDailyRemaineBuckle bean = new SettleDailyRemaineBuckle();
|
|
|
+ bean.setCostType(type);
|
|
|
+ bean.setBuckleAmount(buckle);
|
|
|
+ bean.setIsBuckle(false);
|
|
|
+ bean.setWorkerNumber(workerNumber);
|
|
|
+ bean.setSummaryBatchNo(summaryBatchNo);
|
|
|
+ bean.setCreateBy(opName);
|
|
|
+ bean.setCreateTime(new Date());
|
|
|
+ bean.setWebsitName(websiteName);
|
|
|
+ bean.setIdcard(idcard);
|
|
|
+ bean.setWebsitNumber(websiteNumber);
|
|
|
+ //bean.insert();
|
|
|
+ return bean;
|
|
|
+ }
|
|
|
+
|
|
|
+ public IPage<DailyImportSummaryItemVO> repairDetailList(ZfireParamBean zfireParamBean) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ FieldUtils.supplyParam(zfireParamBean, DailyImportSummaryItemVO.class, adminUser);
|
|
|
+
|
|
|
+ return commonMapper.repairDetailList(new Page(zfireParamBean.getPageNum(), zfireParamBean.getPageSize()), zfireParamBean);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除结算导入明细
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public void repairItemDelete(List<Integer> ids) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+
|
|
|
+ if (adminUser.getType() == 2) {
|
|
|
+ throw new RemoteServiceException("平台账号禁止操作");
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer count = settleDailyImportSummaryItemService.lambdaQuery()
|
|
|
+ .eq(SettleDailyImportSummaryItem::getCompanyWechatId, adminUser.getCompanyWechatId())
|
|
|
+ .in(SettleDailyImportSummaryItem::getId,ids)
|
|
|
+ .eq(SettleDailyImportSummaryItem::getSummaryStatus,DailyConstant.SUMMARY_STATUS_HAS)
|
|
|
+ .count();
|
|
|
+ if(count > 0){
|
|
|
+ throw new RemoteServiceException("存在已汇总的数据,无法删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ settleDailyImportSummaryItemService.lambdaUpdate()
|
|
|
+ .eq(SettleDailyImportSummaryItem::getCompanyWechatId, adminUser.getCompanyWechatId())
|
|
|
+ .in(SettleDailyImportSummaryItem::getId,ids)
|
|
|
+ .in(SettleDailyImportSummaryItem::getSummaryStatus,DailyConstant.SUMMARY_STATUS_CAN_DEL)
|
|
|
+ .remove();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void batchWaitSummary(List<Integer> ids) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+
|
|
|
+ if (adminUser.getType() == 2) {
|
|
|
+ throw new RemoteServiceException("平台账号禁止操作");
|
|
|
+ }
|
|
|
+
|
|
|
+ settleDailyImportSummaryItemService.lambdaUpdate()
|
|
|
+ .set(SettleDailyImportSummaryItem::getSummaryStatus,DailyConstant.SUMMARY_STATUS_WAIT)
|
|
|
+ .in(SettleDailyImportSummaryItem::getSummaryStatus,DailyConstant.SUMMARY_STATUS_CAN_DO)
|
|
|
+ .in(SettleDailyImportSummaryItem::getId,ids)
|
|
|
+ .update();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void batchSummary(List<Integer> ids) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+
|
|
|
+ if (adminUser.getType() == 2) {
|
|
|
+ throw new RemoteServiceException("平台账号禁止操作");
|
|
|
+ }
|
|
|
+
|
|
|
+ settleDailyImportSummaryItemService.lambdaUpdate()
|
|
|
+ .set(SettleDailyImportSummaryItem::getSummaryStatus,DailyConstant.SUMMARY_STATUS_NOT)
|
|
|
+ .eq(SettleDailyImportSummaryItem::getSummaryStatus,DailyConstant.SUMMARY_STATUS_WAIT)
|
|
|
+ .in(SettleDailyImportSummaryItem::getId,ids)
|
|
|
+ .update();
|
|
|
+ }
|
|
|
}
|