6 changed files with 145 additions and 1 deletions
@ -0,0 +1,103 @@ |
|||||
|
package com.qs.serve.modules.tbs.service.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
|
import com.qs.serve.common.util.JsonUtil; |
||||
|
import com.qs.serve.modules.sys.entity.SysSyncLog; |
||||
|
import com.qs.serve.modules.sys.mapper.SysSyncLogMapper; |
||||
|
import com.qs.serve.modules.tbs.entity.TbsActivityCenterGoods; |
||||
|
import com.qs.serve.modules.tbs.entity.TbsBudgetCostItem; |
||||
|
import com.qs.serve.modules.tbs.entity.TbsBudgetLog; |
||||
|
import com.qs.serve.modules.tbs.entity.TbsCostApply; |
||||
|
import com.qs.serve.modules.tbs.mapper.TbsActivityCenterGoodsMapper; |
||||
|
import com.qs.serve.modules.tbs.mapper.TbsBudgetCostItemMapper; |
||||
|
import com.qs.serve.modules.tbs.mapper.TbsBudgetLogMapper; |
||||
|
import com.qs.serve.modules.third.entity.ProcessCreateCostApplyBo; |
||||
|
import com.qs.serve.modules.third.entity.ProcessGoodsItem; |
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* 处理特殊错误的场景 |
||||
|
* @author YenHex |
||||
|
* @since 2023/12/6 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@Service |
||||
|
@AllArgsConstructor |
||||
|
public class TbsDealErrorApplication { |
||||
|
|
||||
|
private final TbsBudgetLogMapper tbsBudgetLogMapper; |
||||
|
private final SysSyncLogMapper sysSyncLogMapper; |
||||
|
private final TbsActivityCenterGoodsMapper activityCenterGoodsMapper; |
||||
|
private final TbsBudgetCostItemMapper budgetCostItemMapper; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 处理第三方核销错误数据 |
||||
|
*/ |
||||
|
public void dealThirtyBuildCost(){ |
||||
|
List<TbsCostApply> costApplyList =tbsBudgetLogMapper.selectErrorThirtyCostId(); |
||||
|
for (TbsCostApply costApply : costApplyList) { |
||||
|
SysSyncLog syncLog = sysSyncLogMapper.selectThirtyLogByCostCode(costApply.getCode()); |
||||
|
if(syncLog==null){ |
||||
|
continue; |
||||
|
} |
||||
|
ProcessCreateCostApplyBo costApplyBo = JsonUtil.jsonToPojo(syncLog.getRequestJson(),ProcessCreateCostApplyBo.class); |
||||
|
List<ProcessGoodsItem> goodsList = costApplyBo.getGoodsList(); |
||||
|
Map<String, BigDecimal> goodsAmountMap = new HashMap<>(); |
||||
|
for (ProcessGoodsItem goodsItem : goodsList) { |
||||
|
BigDecimal amt = goodsAmountMap.get(goodsItem.getInventoryCode()); |
||||
|
if(amt==null){ |
||||
|
amt = BigDecimal.ZERO; |
||||
|
} |
||||
|
amt = amt.add(goodsItem.getAmount()); |
||||
|
goodsAmountMap.put(goodsItem.getInventoryCode(),amt); |
||||
|
} |
||||
|
//更新表 tbs_budget_log,tbs_act_center_goods,tbs_cost_item_budget
|
||||
|
LambdaQueryWrapper<TbsBudgetLog> budgetLogLqw = new LambdaQueryWrapper<>(); |
||||
|
budgetLogLqw.eq(TbsBudgetLog::getCostApplyId,costApply.getId()); |
||||
|
List<TbsBudgetLog> budgetLogList = tbsBudgetLogMapper.selectList(budgetLogLqw); |
||||
|
for (TbsBudgetLog budgetLog : budgetLogList) { |
||||
|
String goodCode = budgetLog.getTargetCode(); |
||||
|
BigDecimal amt = goodsAmountMap.get(goodCode).negate(); |
||||
|
if(budgetLog.getAmount().compareTo(amt)!=0){ |
||||
|
budgetLog.setAmount(amt); |
||||
|
tbsBudgetLogMapper.updateById(budgetLog); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
LambdaQueryWrapper<TbsActivityCenterGoods> goodsLqw = new LambdaQueryWrapper<>(); |
||||
|
goodsLqw.eq(TbsActivityCenterGoods::getCostApplyId,costApply.getId()); |
||||
|
List<TbsActivityCenterGoods> activityCenterGoodsList = activityCenterGoodsMapper.selectList(goodsLqw); |
||||
|
for (TbsActivityCenterGoods centerGoods : activityCenterGoodsList) { |
||||
|
String goodCode = centerGoods.getTargetCode(); |
||||
|
BigDecimal amt = goodsAmountMap.get(goodCode); |
||||
|
if(centerGoods.getUsedAmount().compareTo(amt)!=0){ |
||||
|
centerGoods.setCenterGoodsAmount(amt); |
||||
|
centerGoods.setUsedAmount(amt); |
||||
|
activityCenterGoodsMapper.updateById(centerGoods); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
LambdaQueryWrapper<TbsBudgetCostItem> budgetCostItemLQW = new LambdaQueryWrapper<>(); |
||||
|
budgetCostItemLQW.eq(TbsBudgetCostItem::getCostApplyId,costApply.getId()); |
||||
|
List<TbsBudgetCostItem> budgetCostItemList = budgetCostItemMapper.selectList(budgetCostItemLQW); |
||||
|
for (TbsBudgetCostItem costItem : budgetCostItemList) { |
||||
|
String goodCode = costItem.getTargetCode(); |
||||
|
BigDecimal amt = goodsAmountMap.get(goodCode); |
||||
|
if(costItem.getCenterGoodsAmount().compareTo(amt)!=0){ |
||||
|
costItem.setCenterGoodsAmount(amt); |
||||
|
budgetCostItemMapper.updateById(costItem); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue