|
|
@ -11,6 +11,8 @@ import com.qs.serve.modules.tbs.mapper.TbsCostApplyMapper; |
|
|
|
import com.qs.serve.modules.tbs.service.*; |
|
|
|
import com.qs.serve.modules.vtb.common.VtbFundFlowType; |
|
|
|
import com.qs.serve.modules.vtb.entity.VtbVerificationSubject; |
|
|
|
import com.qs.serve.modules.vtb.entity.VtbVerificationSubjectCenter; |
|
|
|
import com.qs.serve.modules.vtb.service.VtbVerificationSubjectCenterService; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
@ -42,14 +44,25 @@ public class VtbFundFlowServiceImpl extends ServiceImpl<VtbFundFlowMapper,VtbFun |
|
|
|
private final TbsActivitySubjectService activitySubjectService; |
|
|
|
private final TbsActivityCenterService activityCenterService; |
|
|
|
private final TbsActivityCenterGoodsService activityCenterGoodsService; |
|
|
|
private final VtbVerificationSubjectCenterService verificationSubjectCenterService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<VtbFundFlow> listByActivity(Long activityId,String... fundTypes) { |
|
|
|
return this.listByActivity(null,activityId,fundTypes); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<VtbFundFlow> listByActivity(List<Long> notInVerificationIds, Long activityId, String... fundTypes) { |
|
|
|
LambdaQueryWrapper<VtbFundFlow> lqw = new LambdaQueryWrapper<>(); |
|
|
|
lqw.eq(VtbFundFlow::getActivityId,activityId); |
|
|
|
if(CollectionUtil.isNotEmpty(fundTypes)){ |
|
|
|
lqw.in(VtbFundFlow::getFundType, Arrays.asList(fundTypes)); |
|
|
|
} |
|
|
|
if(notInVerificationIds!=null){ |
|
|
|
//防止空in查询
|
|
|
|
notInVerificationIds.add(0L); |
|
|
|
lqw.notIn(VtbFundFlow::getVerificationId,notInVerificationIds); |
|
|
|
} |
|
|
|
return this.list(lqw); |
|
|
|
} |
|
|
|
|
|
|
@ -63,9 +76,18 @@ public class VtbFundFlowServiceImpl extends ServiceImpl<VtbFundFlowMapper,VtbFun |
|
|
|
|
|
|
|
@Override |
|
|
|
public void flushActivityAmount(Long activityId) { |
|
|
|
//活动自定义提交记录
|
|
|
|
List<VtbVerificationSubjectCenter> subjectCenterList = verificationSubjectCenterService.listEffectiveByActivityId(activityId); |
|
|
|
boolean centerCommitFlag = subjectCenterList.size()>0; |
|
|
|
//旧流程按比例分配,新流程按比例分配后,进行再分配
|
|
|
|
log.info("刷新活动金额,ActId:{}",activityId); |
|
|
|
TbsActivity orgActivity = activityService.getById(activityId); |
|
|
|
List<VtbFundFlow> allFunFlow = this.listByActivity(activityId,VtbFundFlowType.Verification); |
|
|
|
List<VtbFundFlow> notCenterCommitFunFlow = allFunFlow; |
|
|
|
if(centerCommitFlag){ |
|
|
|
List<Long> verificationIds = subjectCenterList.stream().map(VtbVerificationSubjectCenter::getVerificationId).collect(Collectors.toList()); |
|
|
|
notCenterCommitFunFlow = this.listByActivity(verificationIds,activityId,VtbFundFlowType.Verification); |
|
|
|
} |
|
|
|
//总使用额
|
|
|
|
BigDecimal activityUsedAmount = BigDecimal.ZERO; |
|
|
|
for (VtbFundFlow fundFlow : allFunFlow) { |
|
|
@ -75,7 +97,43 @@ public class VtbFundFlowServiceImpl extends ServiceImpl<VtbFundFlowMapper,VtbFun |
|
|
|
List<TbsActivitySubject> activitySubject4Update = new ArrayList<>(); |
|
|
|
List<TbsActivityCenter> centerParam4Update = new ArrayList<>(); |
|
|
|
List<TbsActivityCenterGoods> allUpdateCenterGoodsList = new ArrayList<>(); |
|
|
|
this.buildActivityResUpdateList(activityId,allFunFlow, activitySubject4Update, centerParam4Update, allUpdateCenterGoodsList); |
|
|
|
this.buildActivityResUpdateList(activityId,notCenterCommitFunFlow, activitySubject4Update, centerParam4Update, allUpdateCenterGoodsList); |
|
|
|
//二次分配
|
|
|
|
if(centerCommitFlag){ |
|
|
|
for (VtbVerificationSubjectCenter verCenter : subjectCenterList) { |
|
|
|
//成本中心提交金额
|
|
|
|
BigDecimal centerAmount = verCenter.getUsedAmount(); |
|
|
|
if(centerAmount.compareTo(BigDecimal.ZERO)<=0){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
//统计科目的金额
|
|
|
|
for (TbsActivitySubject activitySubject : activitySubject4Update) { |
|
|
|
if(activitySubject.getSubjectId().equals(verCenter.getSubjectId())){ |
|
|
|
BigDecimal activitySubjectAmt = activitySubject.getUsedAmount().add(centerAmount); |
|
|
|
activitySubject.setUsedAmount(activitySubjectAmt); |
|
|
|
} |
|
|
|
} |
|
|
|
//统计成本中心的金额
|
|
|
|
for (TbsActivityCenter activityCenter : centerParam4Update) { |
|
|
|
if(activityCenter.getId().equals(verCenter.getActivityCenterId())){ |
|
|
|
BigDecimal activityCenterAmt = activityCenter.getUsedAmount().add(centerAmount); |
|
|
|
activityCenter.setUsedAmount(activityCenterAmt); |
|
|
|
//分配到商品明细
|
|
|
|
String subjectCenterKey = verCenter.getSubjectId()+":"+verCenter.getCenterType()+"_"+verCenter.getCenterId(); |
|
|
|
for (TbsActivityCenterGoods centerGoods : allUpdateCenterGoodsList) { |
|
|
|
if(centerGoods.getSubjectCenterKey().equals(subjectCenterKey)){ |
|
|
|
BigDecimal goodAmt = activityCenterAmt |
|
|
|
.multiply(centerGoods.getCenterGoodsRate()) |
|
|
|
.divide(new BigDecimal("100"),2,BigDecimal.ROUND_DOWN); |
|
|
|
BigDecimal totalGoodAmt = centerGoods.getUsedAmount().add(goodAmt); |
|
|
|
centerGoods.setUsedAmount(totalGoodAmt); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//更新活动相关数据
|
|
|
|
this.activitySubjectService.updateBatchById(activitySubject4Update); |
|
|
|
this.activityCenterService.updateBatchById(centerParam4Update); |
|
|
@ -179,6 +237,9 @@ public class VtbFundFlowServiceImpl extends ServiceImpl<VtbFundFlowMapper,VtbFun |
|
|
|
TbsActivityCenterGoods centerGoodsParam = new TbsActivityCenterGoods(); |
|
|
|
centerGoodsParam.setId(centerGoods.getId()); |
|
|
|
centerGoodsParam.setUsedAmount(goodsAmount); |
|
|
|
centerGoodsParam.setCenterGoodsRate(centerGoods.getCenterGoodsRate()); |
|
|
|
String subjectCenterKey = centerGoods.getSubjectId()+":"+centerGoods.getCenterType()+"_"+centerGoods.getCenterId(); |
|
|
|
centerGoodsParam.setSubjectCenterKey(subjectCenterKey); |
|
|
|
updateCenterGoodsList.add(centerGoodsParam); |
|
|
|
} |
|
|
|
} |
|
|
|