|
@ -1,18 +1,128 @@ |
|
|
package com.qs.serve.modules.tbs.service; |
|
|
package com.qs.serve.modules.tbs.service; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
|
import com.qs.serve.common.model.enums.BudgetLogOptFlag; |
|
|
|
|
|
import com.qs.serve.common.util.CollectionUtil; |
|
|
|
|
|
import com.qs.serve.modules.sys.entity.SysUser; |
|
|
|
|
|
import com.qs.serve.modules.tbs.common.util.TbsBudgetLogBuildUtil; |
|
|
|
|
|
import com.qs.serve.modules.tbs.entity.*; |
|
|
|
|
|
import com.qs.serve.modules.vtb.common.VtbFundFlowType; |
|
|
|
|
|
import com.qs.serve.modules.vtb.entity.VtbFundFlow; |
|
|
|
|
|
import com.qs.serve.modules.vtb.mapper.VtbFundFlowMapper; |
|
|
|
|
|
import com.qs.serve.modules.vtb.service.VtbFundFlowService; |
|
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @author YenHex |
|
|
* @author YenHex |
|
|
* @since 2024/5/28 |
|
|
* @since 2024/5/28 |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
@Slf4j |
|
|
|
|
|
@Service |
|
|
|
|
|
@AllArgsConstructor |
|
|
public class TbsBudgetReleaseApplicationService { |
|
|
public class TbsBudgetReleaseApplicationService { |
|
|
|
|
|
|
|
|
|
|
|
private final VtbFundFlowService fundFlowService; |
|
|
|
|
|
private final VtbFundFlowMapper vtbFundFlowMapper; |
|
|
|
|
|
private final TbsBudgetService budgetService; |
|
|
|
|
|
private final TbsBudgetLogService budgetLogService; |
|
|
|
|
|
private final TbsBudgetCostItemService budgetCostItemService; |
|
|
|
|
|
private final TbsActivityService activityService; |
|
|
|
|
|
private final TbsActivityCenterGoodsService activityCenterGoodsService; |
|
|
|
|
|
private final TbsCostApplyService costApplyService; |
|
|
|
|
|
private final TbsActivityPayConditionService activityPayConditionService; |
|
|
|
|
|
|
|
|
public void check(){ |
|
|
public void check(){ |
|
|
//校验活动的核销金额是否匹配,不匹配则中断
|
|
|
//校验活动的核销金额是否匹配,不匹配则中断
|
|
|
//查询需要补偿释放的活动ID
|
|
|
//查询需要补偿释放的活动ID
|
|
|
List<Long> activitIds = new ArrayList<>(); |
|
|
List<Long> activityIds = vtbFundFlowMapper.listMissReleaseActivityId(); |
|
|
|
|
|
for (Long activityId : activityIds) { |
|
|
|
|
|
TbsActivity activity = activityService.getById(activityId); |
|
|
|
|
|
TbsCostApply costApply = costApplyService.getById(activity.getCostApplyId()); |
|
|
|
|
|
|
|
|
|
|
|
//保存预算日志
|
|
|
|
|
|
List<TbsActivityCenterGoods> centerGoodsList = activityCenterGoodsService.listByActivityId(activityId); |
|
|
|
|
|
LambdaQueryWrapper<TbsBudgetCostItem> itemLqw = new LambdaQueryWrapper<>(); |
|
|
|
|
|
itemLqw.eq(TbsBudgetCostItem::getActivityId,activityId); |
|
|
|
|
|
List<TbsBudgetCostItem> budgetCostItemList = budgetCostItemService.list(itemLqw); |
|
|
|
|
|
List<Long> budgetIds = budgetCostItemList.stream().map(TbsBudgetCostItem::getBudgetId).collect(Collectors.toList()); |
|
|
|
|
|
if(CollUtil.isEmpty(budgetIds)){ |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
List<TbsBudget> budgetLIst = budgetService.listByIds(budgetIds); |
|
|
|
|
|
List<TbsBudgetLog> budgetLogList = new ArrayList<>(); |
|
|
|
|
|
for (TbsActivityCenterGoods centerGoods : centerGoodsList) { |
|
|
|
|
|
if(centerGoods.getCenterGoodsAmount().compareTo(centerGoods.getUsedAmount())<1){ |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
TbsBudgetCostItem currCostItem = null; |
|
|
|
|
|
TbsBudget currentBudget = null; |
|
|
|
|
|
for (TbsBudgetCostItem costItem : budgetCostItemList) { |
|
|
|
|
|
if(centerGoods.getId().equals(costItem.getCenterGoodItemId())){ |
|
|
|
|
|
currCostItem = costItem; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
for (TbsBudget budget : budgetLIst) { |
|
|
|
|
|
if (currCostItem.getBudgetId().equals(budget.getId())){ |
|
|
|
|
|
currentBudget = budget; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
BigDecimal amount = centerGoods.getCenterGoodsAmount().subtract(centerGoods.getUsedAmount()); |
|
|
|
|
|
SysUser sysUser = new SysUser(); |
|
|
|
|
|
sysUser.setId("0"); |
|
|
|
|
|
sysUser.setName("系统执行"); |
|
|
|
|
|
sysUser.setCode("0"); |
|
|
|
|
|
TbsBudgetLog budgetLog = TbsBudgetLogBuildUtil.buildTbsBudgetLog(BudgetLogOptFlag.State_4,sysUser,costApply,currCostItem,currentBudget,amount,activity); |
|
|
|
|
|
budgetLogList.add(budgetLog); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//移除历史记录
|
|
|
|
|
|
fundFlowService.remove( |
|
|
|
|
|
new LambdaQueryWrapper<VtbFundFlow>() |
|
|
|
|
|
.eq(VtbFundFlow::getFundType, VtbFundFlowType.Release) |
|
|
|
|
|
.eq(VtbFundFlow::getCostApplyId,activity.getCostApplyId()) |
|
|
|
|
|
.eq(VtbFundFlow::getActivityId,activity.getId()) |
|
|
|
|
|
); |
|
|
|
|
|
VtbFundFlow fundFlow = new VtbFundFlow(); |
|
|
|
|
|
fundFlow.setFundType(VtbFundFlowType.Release); |
|
|
|
|
|
fundFlow.setVerificationId(0L); |
|
|
|
|
|
fundFlow.setCenterGoodsCode(activity.getActivityCode()+"_00"); |
|
|
|
|
|
fundFlow.setCostApplyId(activity.getCostApplyId()); |
|
|
|
|
|
fundFlow.setActivityId(activity.getId()); |
|
|
|
|
|
fundFlow.setUsedAmount(activity.getReleaseAmount()); |
|
|
|
|
|
fundFlow.setSupplierId(activity.getSupplierId()); |
|
|
|
|
|
fundFlow.setSupplierCode(activity.getSupplierCode()); |
|
|
|
|
|
fundFlow.setSupplierName(activity.getSupplierName()); |
|
|
|
|
|
fundFlowService.save(fundFlow); |
|
|
|
|
|
|
|
|
|
|
|
//移除历史记录
|
|
|
|
|
|
budgetLogService.remove(new LambdaQueryWrapper<TbsBudgetLog>() |
|
|
|
|
|
.eq(TbsBudgetLog::getCostApplyId,activity.getCostApplyId()) |
|
|
|
|
|
.eq(TbsBudgetLog::getOptType, BudgetLogOptFlag.State_4.getCode()) |
|
|
|
|
|
.eq(TbsBudgetLog::getActivityId,activity.getId())); |
|
|
|
|
|
|
|
|
|
|
|
//更新付款条件状态
|
|
|
|
|
|
LambdaQueryWrapper<TbsActivityPayCondition> updLqw = new LambdaQueryWrapper<>(); |
|
|
|
|
|
updLqw.eq(TbsActivityPayCondition::getActivityId,activityId); |
|
|
|
|
|
TbsActivityPayCondition payCondition = new TbsActivityPayCondition(); |
|
|
|
|
|
payCondition.setFinishedFlag(1); |
|
|
|
|
|
activityPayConditionService.update(payCondition,updLqw); |
|
|
|
|
|
|
|
|
|
|
|
//重新保存
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(budgetLogList)){ |
|
|
|
|
|
budgetLogService.saveBatch(budgetLogList); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|