From ea1b8aca5ac53ec65f102494329acd7d95707bbe Mon Sep 17 00:00:00 2001 From: Yen Date: Mon, 30 Jan 2023 11:24:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=E6=97=B6=E9=A2=84=E7=AE=97?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E9=94=99=E8=AF=AF=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/tbs/entity/TbsBudgetLog.java | 4 +- .../service/impl/TbsCostApplyServiceImpl.java | 60 +++++++++++++++++-- .../controller/VtbVerificationController.java | 10 ++-- 3 files changed, 62 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/qs/serve/modules/tbs/entity/TbsBudgetLog.java b/src/main/java/com/qs/serve/modules/tbs/entity/TbsBudgetLog.java index e788f33e..9b1c3708 100644 --- a/src/main/java/com/qs/serve/modules/tbs/entity/TbsBudgetLog.java +++ b/src/main/java/com/qs/serve/modules/tbs/entity/TbsBudgetLog.java @@ -40,8 +40,8 @@ public class TbsBudgetLog implements Serializable { @Length(max = 30,message = "预算编码长度不能超过30字") private String budgetCode; - /** 类型:0-预算新增;1-费用申请;2-预算调增;3-预算调减;4-费用释放 */ - @NotNull(message = "类型:0-预算新增;1-费用申请;2-预算调增;3-预算调减;4-费用释放不能为空") + /** 类型:0-预算新增;1-费用申请;2-预算调增;3-预算调减;4-费用释放;5-费用申请调增;6-费用申请调减 */ + @NotNull(message = "类型不能为空") private Integer optType; /** 操作人id */ diff --git a/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyServiceImpl.java b/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyServiceImpl.java index abb2b3d5..6d973c1f 100644 --- a/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyServiceImpl.java +++ b/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyServiceImpl.java @@ -24,6 +24,7 @@ import org.springframework.stereotype.Service; import com.qs.serve.modules.tbs.mapper.TbsCostApplyMapper; import org.springframework.transaction.annotation.Transactional; +import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashMap; @@ -109,7 +110,58 @@ public class TbsCostApplyServiceImpl extends ServiceImpl budgetLogList = saveBudgetLog(result, sysUser, costApply, result.getBudgetMatchList(),result.getActivityList()); + if(CollectionUtil.isNotEmpty(budgetLogList)){ + budgetLogService.saveBatch(budgetLogList); + } + }else { + //排除历史记录 + List budgetLogList = saveBudgetLog(result, sysUser, costApply, result.getBudgetMatchList(),result.getActivityList()); + LambdaQueryWrapper logLqw = new LambdaQueryWrapper<>(); + logLqw.eq(TbsBudgetLog::getCostApplyId,costApply.getId()); + List oldLogList = budgetLogService.list(logLqw); + Map> oldLogMap = oldLogList.stream().collect(Collectors.groupingBy(a->a.getScheduleItemId()+"_"+a.getTargetId())); + List insertList = new ArrayList<>(); + for (TbsBudgetLog budgetLog : budgetLogList) { + String key = budgetLog.getScheduleItemId()+"_"+budgetLog.getTargetId(); + List subOldList = oldLogMap.get(key); + if(CollectionUtil.isNotEmpty(subOldList)){ + BigDecimal totalOldLogAmount = BigDecimal.ZERO; + for (TbsBudgetLog oldListItem : subOldList) { + totalOldLogAmount = totalOldLogAmount.add(oldListItem.getAmount()); + } + BigDecimal diffAmount = budgetLog.getAmount().subtract(totalOldLogAmount); + if(diffAmount.compareTo(BigDecimal.ZERO)>0){ + budgetLog.setOptType(5); + budgetLog.setAmount(diffAmount); + insertList.add(budgetLog); + }else if (diffAmount.compareTo(BigDecimal.ZERO)<0){ + budgetLog.setOptType(6); + budgetLog.setAmount(diffAmount); + insertList.add(budgetLog); + } + oldLogMap.remove(key); + }else { + insertList.add(budgetLog); + } + } + //调节未包含在budgetLogList的oldLogList的项 + if(CollectionUtil.isNotEmpty(oldLogMap)){ + for (String key : oldLogMap.keySet()) { + List subOldList = oldLogMap.get(key); + for (TbsBudgetLog budgetLog : subOldList) { + budgetLog.setOptType(5); + budgetLog.setAmount(budgetLog.getAmount().negate()); + budgetLog.setId(null); + insertList.add(budgetLog); + } + } + } + if(CollectionUtil.isNotEmpty(insertList)){ + budgetLogService.saveBatch(insertList); + } + } //创建流程后回调 BaseCreateCallbackBo callbackBo = new BaseCreateCallbackBo(TbsSeeYonConst.COST_APPLY_CODE,tbsCostApply.getId()+""); seeYonService.createCallbackStatus(callbackBo); @@ -122,7 +174,7 @@ public class TbsCostApplyServiceImpl extends ServiceImpl allBudgetItem, List activityList) { + private List saveBudgetLog(TbsBudgetCostResult result, SysUser sysUser, TbsCostApply costApply, List allBudgetItem, List activityList) { List budgetLogList = new ArrayList<>(); List budgetList = result.getBudgetList(); for (TbsBudgetCostItem item : allBudgetItem) { @@ -149,9 +201,7 @@ public class TbsCostApplyServiceImpl extends ServiceImpl