|
|
@ -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<TbsCostApplyMapper,TbsC |
|
|
|
allBudgetItem.addAll(result.getBudgetUnMatchList()); |
|
|
|
budgetCostItemService.saveBatch(allBudgetItem); |
|
|
|
//保存预算使用日志
|
|
|
|
saveBudgetLog(result, sysUser, costApply, result.getBudgetMatchList(),result.getActivityList()); |
|
|
|
if(tbsCostApply.getChargeState().equals(TbsCostApplyState.State_0_unPublish.getCode())){ |
|
|
|
List<TbsBudgetLog> budgetLogList = saveBudgetLog(result, sysUser, costApply, result.getBudgetMatchList(),result.getActivityList()); |
|
|
|
if(CollectionUtil.isNotEmpty(budgetLogList)){ |
|
|
|
budgetLogService.saveBatch(budgetLogList); |
|
|
|
} |
|
|
|
}else { |
|
|
|
//排除历史记录
|
|
|
|
List<TbsBudgetLog> budgetLogList = saveBudgetLog(result, sysUser, costApply, result.getBudgetMatchList(),result.getActivityList()); |
|
|
|
LambdaQueryWrapper<TbsBudgetLog> logLqw = new LambdaQueryWrapper<>(); |
|
|
|
logLqw.eq(TbsBudgetLog::getCostApplyId,costApply.getId()); |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
//创建流程后回调
|
|
|
|
BaseCreateCallbackBo callbackBo = new BaseCreateCallbackBo(TbsSeeYonConst.COST_APPLY_CODE,tbsCostApply.getId()+""); |
|
|
|
seeYonService.createCallbackStatus(callbackBo); |
|
|
@ -122,7 +174,7 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC |
|
|
|
* @param costApply |
|
|
|
* @param allBudgetItem |
|
|
|
*/ |
|
|
|
private void saveBudgetLog(TbsBudgetCostResult result, SysUser sysUser, TbsCostApply costApply, List<TbsBudgetCostItem> allBudgetItem, List<TbsActivity> activityList) { |
|
|
|
private List<TbsBudgetLog> saveBudgetLog(TbsBudgetCostResult result, SysUser sysUser, TbsCostApply costApply, List<TbsBudgetCostItem> allBudgetItem, List<TbsActivity> activityList) { |
|
|
|
List<TbsBudgetLog> budgetLogList = new ArrayList<>(); |
|
|
|
List<TbsBudget> budgetList = result.getBudgetList(); |
|
|
|
for (TbsBudgetCostItem item : allBudgetItem) { |
|
|
@ -149,9 +201,7 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC |
|
|
|
TbsBudgetLog budgetLog = budgetLogService.buildTbsBudgetLog(1,sysUser, costApply, item, budget,item.getCenterGoodsAmount().negate(),currActivity); |
|
|
|
budgetLogList.add(budgetLog); |
|
|
|
} |
|
|
|
if(CollectionUtil.isNotEmpty(budgetLogList)){ |
|
|
|
budgetLogService.saveBatch(budgetLogList); |
|
|
|
} |
|
|
|
return budgetLogList; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|