|
|
@ -2,6 +2,7 @@ package com.qs.serve.modules.tbs.service.impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.qs.serve.common.model.consts.BudgetLogRollbackFlag; |
|
|
|
import com.qs.serve.common.model.dto.R; |
|
|
|
import com.qs.serve.common.util.*; |
|
|
|
import com.qs.serve.common.util.model.DateFormatString; |
|
|
@ -120,47 +121,27 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC |
|
|
|
List<TbsBudgetLog> budgetLogList = saveBudgetLog(result, sysUser, costApply, result.getBudgetMatchList(),result.getActivityList()); |
|
|
|
LambdaQueryWrapper<TbsBudgetLog> logLqw = new LambdaQueryWrapper<>(); |
|
|
|
logLqw.eq(TbsBudgetLog::getCostApplyId,costApply.getId()); |
|
|
|
logLqw.eq(TbsBudgetLog::getRollbackFlag, BudgetLogRollbackFlag.State_1); |
|
|
|
List<TbsBudgetLog> oldLogList = budgetLogService.list(logLqw); |
|
|
|
Map<String,List<TbsBudgetLog>> oldLogMap = oldLogList.stream().collect(Collectors.groupingBy(a->a.getScheduleItemId()+"_"+a.getTargetId())); |
|
|
|
List<TbsBudgetLog> insertList = new ArrayList<>(); |
|
|
|
for (TbsBudgetLog budgetLog : budgetLogList) { |
|
|
|
String key = budgetLog.getScheduleItemId()+"_"+budgetLog.getTargetId(); |
|
|
|
List<TbsBudgetLog> 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<TbsBudgetLog> 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); |
|
|
|
List<TbsBudgetLog> oldLogList4Upd = oldLogList.stream().map(a->{ |
|
|
|
TbsBudgetLog budgetLog = new TbsBudgetLog(); |
|
|
|
budgetLog.setId(a.getId()); |
|
|
|
budgetLog.setRollbackFlag(BudgetLogRollbackFlag.State_2); |
|
|
|
return budgetLog; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
budgetLogService.updateBatchById(oldLogList4Upd); |
|
|
|
for (TbsBudgetLog budgetLog : oldLogList) { |
|
|
|
budgetLog.setCreateBy(null); |
|
|
|
budgetLog.setCreateTime(null); |
|
|
|
budgetLog.setUpdateBy(null); |
|
|
|
budgetLog.setUpdateTime(null); |
|
|
|
budgetLog.setId(null); |
|
|
|
budgetLog.setAmount(budgetLog.getAmount().negate()); |
|
|
|
budgetLog.setOptType(5); |
|
|
|
} |
|
|
|
budgetLogService.saveBatch(oldLogList); |
|
|
|
budgetLogList.forEach(a->a.setOptType(6)); |
|
|
|
budgetLogService.saveBatch(budgetLogList); |
|
|
|
} |
|
|
|
//创建流程后回调
|
|
|
|
BaseCreateCallbackBo callbackBo = new BaseCreateCallbackBo(TbsSeeYonConst.COST_APPLY_CODE,tbsCostApply.getId()+""); |
|
|
|