diff --git a/src/main/java/com/qs/serve/modules/tbs/entity/TbsActivityCenterGoods.java b/src/main/java/com/qs/serve/modules/tbs/entity/TbsActivityCenterGoods.java index bb37cc3a..ad16903d 100644 --- a/src/main/java/com/qs/serve/modules/tbs/entity/TbsActivityCenterGoods.java +++ b/src/main/java/com/qs/serve/modules/tbs/entity/TbsActivityCenterGoods.java @@ -265,11 +265,14 @@ public class TbsActivityCenterGoods implements Serializable { @TableField(exist = false) private List queryGoodsGroups; - /** */ @JsonIgnore @TableField(exist = false) private List match2ScheduleItemBudgetList ; + @JsonIgnore + @TableField(exist = false) + private String subjectCenterKey ; + public TbsBudgetCostItem toBudgetCostItem(){ TbsBudgetCostItem budgetCostItem = CopierUtil.copy(this,new TbsBudgetCostItem()); budgetCostItem.setId(null); diff --git a/src/main/java/com/qs/serve/modules/vtb/service/VtbFundFlowService.java b/src/main/java/com/qs/serve/modules/vtb/service/VtbFundFlowService.java index c19ee0b8..16e3b26a 100644 --- a/src/main/java/com/qs/serve/modules/vtb/service/VtbFundFlowService.java +++ b/src/main/java/com/qs/serve/modules/vtb/service/VtbFundFlowService.java @@ -20,6 +20,15 @@ public interface VtbFundFlowService extends IService { */ List listByActivity(Long activityId,String... fundTypes); + /** + * 获取相关活动列表 + * @param notInVerificationIds 不包含当前核销的id + * @param activityId 不能空 + * @param fundTypes 可空 + * @return + */ + List listByActivity(List notInVerificationIds ,Long activityId,String... fundTypes); + /** * 判断释放 * @param activityId diff --git a/src/main/java/com/qs/serve/modules/vtb/service/VtbVerificationSubjectCenterService.java b/src/main/java/com/qs/serve/modules/vtb/service/VtbVerificationSubjectCenterService.java index 4f2ab9f4..2375f67a 100644 --- a/src/main/java/com/qs/serve/modules/vtb/service/VtbVerificationSubjectCenterService.java +++ b/src/main/java/com/qs/serve/modules/vtb/service/VtbVerificationSubjectCenterService.java @@ -15,5 +15,14 @@ public interface VtbVerificationSubjectCenterService extends IService listByVerificationId(Long id); + List listByActivityId(Long id); + + /** + * 获取生效的 + * @param id + * @return + */ + List listEffectiveByActivityId(Long id); + } diff --git a/src/main/java/com/qs/serve/modules/vtb/service/impl/VtbFundFlowServiceImpl.java b/src/main/java/com/qs/serve/modules/vtb/service/impl/VtbFundFlowServiceImpl.java index 1f3cb215..71aafc2b 100644 --- a/src/main/java/com/qs/serve/modules/vtb/service/impl/VtbFundFlowServiceImpl.java +++ b/src/main/java/com/qs/serve/modules/vtb/service/impl/VtbFundFlowServiceImpl.java @@ -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 listByActivity(Long activityId,String... fundTypes) { + return this.listByActivity(null,activityId,fundTypes); + } + + @Override + public List listByActivity(List notInVerificationIds, Long activityId, String... fundTypes) { LambdaQueryWrapper 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 subjectCenterList = verificationSubjectCenterService.listEffectiveByActivityId(activityId); + boolean centerCommitFlag = subjectCenterList.size()>0; + //旧流程按比例分配,新流程按比例分配后,进行再分配 log.info("刷新活动金额,ActId:{}",activityId); TbsActivity orgActivity = activityService.getById(activityId); List allFunFlow = this.listByActivity(activityId,VtbFundFlowType.Verification); + List notCenterCommitFunFlow = allFunFlow; + if(centerCommitFlag){ + List 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 activitySubject4Update = new ArrayList<>(); List centerParam4Update = new ArrayList<>(); List 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 addFundFlowList = new ArrayList<>(); + //协议类支持自动分配 buildFundFlows(verification.getId(), addFundFlowList, activityCenterGoods4Update,currentSubjectAmt); if(CollectionUtil.isNotEmpty(addFundFlowList)){ fundFlowService.saveBatch(addFundFlowList); @@ -1164,9 +1165,19 @@ public class VtbVerificationServiceImpl extends ServiceImpl subjectCenterList = vtbVerificationSubjectCenterService.listByVerificationId(verificationId); + boolean isCenterCommit = subjectCenterList.size()>0; //0元核销只改变状态 if(checkZero){ - fundFlowService.flushActivityAmount(verification.getActivityId()); + //自定义成本中心提交后,无法再自动分配刷新金额 + if(isCenterCommit){ + //TODO 刷洗自定义金额 + + }else { + //自动分配刷新金额 + fundFlowService.flushActivityAmount(verification.getActivityId()); + } verification = new VtbVerification(); verification.setId(verificationId); verification.setVerificationState(VtbVerificationState.Finished.getCode()); @@ -1191,6 +1202,7 @@ public class VtbVerificationServiceImpl extends ServiceImpl addFundFlowList = new ArrayList<>(); LocalDateTime now = LocalDateTime.now(); Date now2 = Date.from(now.atZone(ZoneId.systemDefault()).toInstant()); + for (VtbVerificationSubject verificationSubject : verificationSubjects) { Long subjectId = verificationSubject.getSubjectId(); BigDecimal usedAmount = verificationSubject.getUsedAmount(); @@ -1206,18 +1218,31 @@ public class VtbVerificationServiceImpl extends ServiceImpl activityGoodsListOfSubjectCenter = activityGoodsOfSubjectCenter.get(subjectCenterKey); //当前成本中心分配金额 - BigDecimal currentCenterAmount; - if(i == activityCenters.size()-1){ - currentCenterAmount = usedAmount.subtract(preCenterAmount); + BigDecimal currentCenterAmount = BigDecimal.ZERO; + if(isCenterCommit){ + //刷洗自定义成本中心金额 + for (VtbVerificationSubjectCenter subjectCenter : subjectCenterList) { + if(subjectCenter.getActivityCenterId().equals(activityCenter.getId())){ + currentCenterAmount = subjectCenter.getUsedAmount(); + } + } + buildFundFlows(verificationId, addFundFlowList, activityGoodsListOfSubjectCenter,currentCenterAmount); }else { - currentCenterAmount = usedAmount.multiply(activityCenter.getCenterRate()) - .divide(new BigDecimal("100"), RoundingMode.HALF_DOWN) - .setScale(2, RoundingMode.DOWN); - preCenterAmount = preCenterAmount.add(currentCenterAmount); + //按比例分配 + if(i == activityCenters.size()-1){ + currentCenterAmount = usedAmount.subtract(preCenterAmount); + }else { + currentCenterAmount = usedAmount.multiply(activityCenter.getCenterRate()) + .divide(new BigDecimal("100"), RoundingMode.HALF_DOWN) + .setScale(2, RoundingMode.DOWN); + preCenterAmount = preCenterAmount.add(currentCenterAmount); + } + buildFundFlows(verificationId, addFundFlowList, activityGoodsListOfSubjectCenter,currentCenterAmount); } - buildFundFlows(verificationId, addFundFlowList, activityGoodsListOfSubjectCenter,currentCenterAmount); + } + //调用支付接口 BmsSubject subject = new BmsSubject(); subject.setSubjectCode(verificationSubject.getSubjectCode()); subject.setSubjectName(verificationSubject.getSubjectName()); @@ -1267,6 +1292,9 @@ public class VtbVerificationServiceImpl extends ServiceImpl addFundFlowList, @@ -1343,9 +1372,9 @@ public class VtbVerificationServiceImpl extends ServiceImpl listByActivityId(Long id) { + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.eq(VtbVerificationSubjectCenter::getActivityId,id); + return this.list(lqw); + } + + @Override + public List listEffectiveByActivityId(Long id) { + LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); + lqw.eq(VtbVerificationSubjectCenter::getActivityId,id); + lqw.eq(VtbVerificationSubjectCenter::getEffectiveFlag,1); + return this.list(lqw); + } }