diff --git a/src/main/java/com/qs/serve/modules/seeyon/entity/CtpAffair.java b/src/main/java/com/qs/serve/modules/seeyon/entity/CtpAffair.java index 13050dc5..fdc82b97 100644 --- a/src/main/java/com/qs/serve/modules/seeyon/entity/CtpAffair.java +++ b/src/main/java/com/qs/serve/modules/seeyon/entity/CtpAffair.java @@ -19,7 +19,7 @@ public class CtpAffair { private String memberId; - /** 1.代发;2已发;3待办;4已办;5取消;6回退;7取回;8竞争执行;15中止 */ + /** 1.代发;2已发(前端:发起);3待办(前端:待办);4已办(前端:同意);5取消;6回退;7取回;8竞争执行;15中止(前端:拒绝) */ private Integer state; private String templateId; diff --git a/src/main/java/com/qs/serve/modules/tbs/common/TbsActivityState.java b/src/main/java/com/qs/serve/modules/tbs/common/TbsActivityState.java index 639499e1..c69267a3 100644 --- a/src/main/java/com/qs/serve/modules/tbs/common/TbsActivityState.java +++ b/src/main/java/com/qs/serve/modules/tbs/common/TbsActivityState.java @@ -13,5 +13,6 @@ public interface TbsActivityState { Integer STATE_1_Checking = 1; Integer STATE_1_Finished = 2; Integer STATE_1_Baning = 3; + Integer STATE_4_Release = 4; } diff --git a/src/main/java/com/qs/serve/modules/tbs/controller/TbsCostApplyController.java b/src/main/java/com/qs/serve/modules/tbs/controller/TbsCostApplyController.java index fc6a28c4..a561c339 100644 --- a/src/main/java/com/qs/serve/modules/tbs/controller/TbsCostApplyController.java +++ b/src/main/java/com/qs/serve/modules/tbs/controller/TbsCostApplyController.java @@ -256,6 +256,9 @@ public class TbsCostApplyController { return R.error("当前账号未绑定致远用户信息"); } TbsCostApply costApplyParam = tbsCostApplyService.getById(costApplyId); + if(costApplyParam.getSyFormId()==null){ + return R.ok(); + } CtpAffairQo param = new CtpAffairQo(); param.setFormMainId(costApplyParam.getSyFormId()); param.setTemplateCodes(Arrays.asList(TbsSeeYonConst.COST_APPLY_FORM)); diff --git a/src/main/java/com/qs/serve/modules/tbs/entity/TbsActivity.java b/src/main/java/com/qs/serve/modules/tbs/entity/TbsActivity.java index 1e230d32..6a728b74 100644 --- a/src/main/java/com/qs/serve/modules/tbs/entity/TbsActivity.java +++ b/src/main/java/com/qs/serve/modules/tbs/entity/TbsActivity.java @@ -35,7 +35,7 @@ public class TbsActivity implements Serializable { /** 编码 */ private String activityCode; - /** 活动状态:0-待核销;1-审批中;2-完成;3-冻结 */ + /** 活动状态:0-待核销;1-审批中;2-完成;3-冻结;4-已释放 */ private Integer activityState; /** 费用申请id */ diff --git a/src/main/java/com/qs/serve/modules/vtb/controller/VtbVerificationController.java b/src/main/java/com/qs/serve/modules/vtb/controller/VtbVerificationController.java index b5c51cb1..6ab4aa81 100644 --- a/src/main/java/com/qs/serve/modules/vtb/controller/VtbVerificationController.java +++ b/src/main/java/com/qs/serve/modules/vtb/controller/VtbVerificationController.java @@ -6,6 +6,7 @@ import com.qs.serve.common.model.dto.PageVo; import com.qs.serve.common.model.dto.R; import com.qs.serve.common.model.enums.BizType; import com.qs.serve.common.model.enums.SystemModule; +import com.qs.serve.common.util.CollectionUtil; import com.qs.serve.common.util.PageUtil; import com.qs.serve.common.util.CopierUtil; import com.qs.serve.common.util.StringUtils; @@ -56,21 +57,6 @@ public class VtbVerificationController { return R.ok(); } - /** - * 列表 - * @param param - * @return - */ - //@GetMapping("/list") - @PreAuthorize("hasRole('vtb:verification:query')") - public R> getList(VtbVerificationSo param){ - VtbVerification entity = CopierUtil.copy(param,new VtbVerification()); - LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(entity); - PageUtil.startPage(); - List list = vtbVerificationService.list(lqw); - return R.ok(list); - } - /** * 翻页 * @param param @@ -96,8 +82,8 @@ public class VtbVerificationController { @PreAuthorize("hasRole('vtb:verification:query')") public R getById(@PathVariable("id") String id){ VtbVerification vtbVerification = vtbVerificationService.getById(id); - List attachIds = Arrays.asList(vtbVerification.getAttachIds()); - if(attachIds.size()>0){ + if(CollectionUtil.isNotEmpty(vtbVerification.getAttachIds())){ + List attachIds = Arrays.asList(vtbVerification.getAttachIds()); List attachList = attachService.listByIds(attachIds); vtbVerification.setAttachList(attachList); } @@ -131,33 +117,6 @@ public class VtbVerificationController { return R.ok(); } - /** - * 新增 - * @param param - * @return - */ - //@PostMapping("/save") - @SysLog(module = SystemModule.Verification, title = "核销", biz = BizType.INSERT) - @PreAuthorize("hasRole('vtb:verification:insert')") - public R save(@RequestBody @Valid VtbVerificationBo param){ - VtbVerification entity = CopierUtil.copy(param,new VtbVerification()); - boolean result = vtbVerificationService.save(entity); - return R.isTrue(result); - } - - /** - * 删除 - * @param ids - * @return - */ - //@DeleteMapping("/deleteById/{ids}") - @SysLog(module = SystemModule.Verification, title = "核销", biz = BizType.DELETE) - @PreAuthorize("hasRole('vtb:verification:delete')") - public R deleteById(@PathVariable("ids") String ids){ - List idsLong = StringUtils.splitIdLong(ids); - boolean result = vtbVerificationService.removeByIds(idsLong); - return R.isTrue(result); - } } diff --git a/src/main/java/com/qs/serve/modules/vtb/entity/VtbFundFlow.java b/src/main/java/com/qs/serve/modules/vtb/entity/VtbFundFlow.java index f41efa16..d81df277 100644 --- a/src/main/java/com/qs/serve/modules/vtb/entity/VtbFundFlow.java +++ b/src/main/java/com/qs/serve/modules/vtb/entity/VtbFundFlow.java @@ -138,6 +138,9 @@ public class VtbFundFlow implements Serializable { @JsonProperty private String delFlag; + /** TbsActivityCenterGoods的id */ + private Long centerGoodItemId; + /** 临时金额,统计该项可传入金额 */ @TableField(exist = false) private BigDecimal tempBalance; diff --git a/src/main/java/com/qs/serve/modules/vtb/entity/VtbVerification.java b/src/main/java/com/qs/serve/modules/vtb/entity/VtbVerification.java index a93a8d09..29aa808a 100644 --- a/src/main/java/com/qs/serve/modules/vtb/entity/VtbVerification.java +++ b/src/main/java/com/qs/serve/modules/vtb/entity/VtbVerification.java @@ -45,6 +45,9 @@ public class VtbVerification implements Serializable { /** 核销状态 */ private Integer verificationState; + /** 金额 */ + private BigDecimal amount; + /** 备注 */ @Length(max = 255,message = "备注长度不能超过255字") private String remark; 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 81cf03b7..fbd7fa51 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 @@ -61,22 +61,43 @@ public class VtbFundFlowServiceImpl extends ServiceImpl allFunFlow = this.listByActivity(activityId); - List activitySubjectList = activitySubjectService.listByActivityId(activityId); - List activityCenterList = activityCenterService.listByActivity(activityId); - List activityCenterGoodsList = activityCenterGoodsService.listByActivityId(activityId); + List allFunFlow = this.listByActivity(activityId,VtbFundFlowType.Verification); //总使用额 BigDecimal activityUsedAmount = BigDecimal.ZERO; for (VtbFundFlow fundFlow : allFunFlow) { activityUsedAmount = activityUsedAmount.add(fundFlow.getUsedAmount()); } + //构建更新列表 + List activitySubject4Update = new ArrayList<>(); + List centerParam4Update = new ArrayList<>(); + List allUpdateCenterGoodsList = new ArrayList<>(); + this.buildActivityResUpdateList(activityId,allFunFlow, activitySubject4Update, centerParam4Update, allUpdateCenterGoodsList); + //更新活动相关数据 + this.activitySubjectService.updateBatchById(activitySubject4Update); + this.activityCenterService.updateBatchById(centerParam4Update); + this.activityCenterGoodsService.updateBatchById(allUpdateCenterGoodsList); + //更新活动 TbsActivity activity = new TbsActivity(); activity.setId(activityId); activity.setUsedAmount(activityUsedAmount); - boolean finished = orgActivity.getUsedAmount().compareTo(activityUsedAmount)==0; - log.info("活动完成状态:{},ActId:{}",finished,activityId); + boolean finished = orgActivity.getTotalAmount().compareTo(activityUsedAmount)==0; + log.info("活动信息:{},ActId:{}",finished?"已完成":"未完成",activityId); activity.setFinishedFlag(finished?1:0); activityService.updateById(activity); + } + + /** + * 构建活动更新列表 + * @param activityId + * @param allFunFlow + * @param activitySubject4Update + * @param centerParam4Update + * @param allUpdateCenterGoodsList + */ + private void buildActivityResUpdateList(Long activityId,List allFunFlow, List activitySubject4Update, List centerParam4Update, List allUpdateCenterGoodsList) { + List activitySubjectList = activitySubjectService.listByActivityId(activityId); + List activityCenterList = activityCenterService.listByActivity(activityId); + List activityCenterGoodsList = activityCenterGoodsService.listByActivityId(activityId); //更新其它明细 Map> fundFlowMapBySubject = allFunFlow.stream().collect(Collectors.groupingBy(VtbFundFlow::getSubjectId)); for (Long subjectId : fundFlowMapBySubject.keySet()) { @@ -96,11 +117,11 @@ public class VtbFundFlowServiceImpl extends ServiceImpl> fundFlowMapByCenter = fundFlowList.stream().collect(Collectors.groupingBy(VtbFundFlow::getCenterId)); - for (String centerId : fundFlowMapByCenter.keySet()) { - List centerFundFlowList = fundFlowMapByCenter.get(centerId); + Map> fundFlowMapByCenter = fundFlowList.stream().collect(Collectors.groupingBy(obj->obj.getCenterType()+":"+obj.getCenterId())); + for (String centerKey : fundFlowMapByCenter.keySet()) { + List centerFundFlowList = fundFlowMapByCenter.get(centerKey); if(centerFundFlowList==null){ continue; } @@ -109,11 +130,12 @@ public class VtbFundFlowServiceImpl extends ServiceImpl channelBoList = verificationBo.getChannelList(); List pointBoList = verificationBo.getPointList(); + List vtbVerificationChannelList = new ArrayList<>(); + List verificationChannelPointList = new ArrayList<>(); if(CollectionUtil.isNotEmpty(channelBoList)){ - List vtbVerificationChannelList = new ArrayList<>(); for (VtbVerificationChannelBo channelBo : channelBoList) { BmsChannel channel = channelService.getById(channelBo.getChannelId()); VtbVerificationChannel verificationChannel = new VtbVerificationChannel(); @@ -163,9 +166,7 @@ public class VtbVerificationServiceImpl extends ServiceImpl activityChannelPointList = new ArrayList<>(); for (VtbVerificationChannelPointBo channelPointBo : pointBoList) { BmsChannelPoint channelPoint = channelPointService.getById(channelPointBo.getPointId()); BmsChannel channel = channelService.getById(channelPoint.getChannelId()); @@ -180,11 +181,16 @@ public class VtbVerificationServiceImpl extends ServiceImpl verificationSubjects = validCreateVeriSubject(verificationBo, activity, costApply); + //设置总金额 + BigDecimal totalAmount = BigDecimal.ZERO; + for (VtbVerificationSubject verificationSubject : verificationSubjects) { + totalAmount = totalAmount.add(verificationSubject.getUsedAmount()); + } + verification.setAmount(totalAmount); //保存 this.saveOrUpdate(verification); //移除历史提交记录 @@ -193,6 +199,14 @@ public class VtbVerificationServiceImpl extends ServiceImplobj.setVerificationId(verification.getId())); + verificationChannelService.saveBatch(vtbVerificationChannelList); + } + if(CollectionUtil.isNotEmpty(verificationChannelPointList)){ + verificationChannelPointList.forEach(obj->obj.setVerificationId(verification.getId())); + verificationChannelPointService.saveBatch(verificationChannelPointList); + } //保存科目费用 verificationSubjects.forEach(obj->obj.setVerificationId(verification.getId())); verificationSubjectService.saveBatch(verificationSubjects); @@ -200,13 +214,14 @@ public class VtbVerificationServiceImpl extends ServiceImpl lqw = new LambdaQueryWrapper<>(); + lqw.eq(VtbFundFlow::getVerificationId,verificationId); + fundFlowService.remove(lqw); List verificationSubjects = verificationSubjectService.listByVerificationId(verification.getId()); List activityCenterGoodsAllList = activityCenterGoodsService.listByActivityId(verification.getActivityId()); - List addFundFlowList = new ArrayList<>(); + List activityCenterList = activityCenterService.listByActivity(verification.getActivityId()); //生成费用流水记录 Map> centerGoodsMapBySubject = activityCenterGoodsAllList.stream() .collect(Collectors.groupingBy(TbsActivityCenterGoods::getSubjectId)); + Map> centerMapBySubject = activityCenterList.stream() + .collect(Collectors.groupingBy(TbsActivityCenter::getSubjectId)); + List addFundFlowList = new ArrayList<>(); for (VtbVerificationSubject verificationSubject : verificationSubjects) { - List addFundFlowListOfSubject = new ArrayList<>(); Long subjectId = verificationSubject.getSubjectId(); BigDecimal usedAmount = verificationSubject.getUsedAmount(); List activityCenterGoodsOfSubject = centerGoodsMapBySubject.get(subjectId); - //统计前面项合计金额 - BigDecimal totalPrefixAmount = BigDecimal.ZERO; - //统计不匹配金额 - BigDecimal unMatchAmount = BigDecimal.ZERO; - for (int i = 0; i < activityCenterGoodsOfSubject.size(); i++) { - TbsActivityCenterGoods centerGoods = activityCenterGoodsOfSubject.get(i); - BigDecimal currentTimeAmount; - if(i==activityCenterGoodsOfSubject.size()-1){ - currentTimeAmount = usedAmount.subtract(totalPrefixAmount); - }else { - currentTimeAmount = usedAmount.multiply(centerGoods.getCenterGoodsRate()) - .multiply(centerGoods.getCenterRate()) - //四舍五入保留两位小数 - .divide(new BigDecimal(10000), RoundingMode.HALF_UP); - //防止费率为0情况 - if(currentTimeAmount.compareTo(BigDecimal.ZERO)==0){ - continue; - } - } - //可用金额 - BigDecimal allowBalance = centerGoods.getCenterGoodsAmount().subtract(centerGoods.getUsedAmount()); - if(allowBalance.compareTo(BigDecimal.ZERO)==0){ - log.debug("统计不匹配金额allowBalance:{},currentTimeAmount:{}",allowBalance.doubleValue(),currentTimeAmount.doubleValue()); - unMatchAmount.add(currentTimeAmount); - continue; - } - BigDecimal tempBalance = BigDecimal.ZERO; - //如果不够减 - if(allowBalance.compareTo(currentTimeAmount)<1){ - //统计不匹配金额 - unMatchAmount = unMatchAmount.add(currentTimeAmount.subtract(allowBalance)); - log.debug("统计不匹配金额allowBalance:{},currentTimeAmount:{}",allowBalance.doubleValue(),currentTimeAmount.doubleValue()); - currentTimeAmount = allowBalance; - }else { - tempBalance = allowBalance.subtract(currentTimeAmount); - } - VtbFundFlow fundFlow = CopierUtil.copy(centerGoods,new VtbFundFlow()); - fundFlow.setId(null); - fundFlow.setUsedAmount(currentTimeAmount); - fundFlow.setFundType(VtbFundFlowType.Release); - fundFlow.setVerificationId(verificationId); - fundFlow.setTempBalance(tempBalance); - addFundFlowListOfSubject.add(fundFlow); - } - //todo 1400元 44次 33行 - //打乱顺序,保存前平摊费用 - Collections.shuffle(addFundFlowListOfSubject); - for (VtbFundFlow fundFlow : addFundFlowListOfSubject) { - if(unMatchAmount.compareTo(BigDecimal.ZERO)>0){ - BigDecimal tmpBalance = fundFlow.getTempBalance(); - if(tmpBalance.compareTo(BigDecimal.ZERO)>0){ - if(tmpBalance.compareTo(unMatchAmount)>0){ - BigDecimal resultBalance = fundFlow.getUsedAmount().add(unMatchAmount); - fundFlow.setUsedAmount(resultBalance); - break; - }else { - unMatchAmount = unMatchAmount.subtract(fundFlow.getTempBalance()); - BigDecimal resultBalance = fundFlow.getUsedAmount().add(tmpBalance); - fundFlow.setUsedAmount(resultBalance); - } - } + Map> activityGoodsOfSubjectCenter = activityCenterGoodsOfSubject.stream() + .collect(Collectors.groupingBy(obj->obj.getCenterType()+":"+obj.getCenterId())); + + List activityCenters = centerMapBySubject.get(subjectId); + //统计最后一项为减法 + BigDecimal preCenterAmount = BigDecimal.ZERO; + for (int i = 0; i < activityCenters.size(); i++) { + TbsActivityCenter activityCenter = activityCenters.get(i); + String subjectCenterKey = activityCenter.getCenterType()+":"+activityCenter.getCenterId(); + List activityGoodsListOfSubjectCenter = activityGoodsOfSubjectCenter.get(subjectCenterKey); + //当前成本中心分配金额 + BigDecimal currentCenterAmount; + if(i == activityCenters.size()-1){ + currentCenterAmount = usedAmount.subtract(preCenterAmount); }else { - break; + 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); } - if(unMatchAmount.compareTo(BigDecimal.ZERO)>0){ - log.error("异常数据,费用核销[{}]超额:{}",verificationId,unMatchAmount.doubleValue()); - } - addFundFlowList.addAll(addFundFlowListOfSubject); } fundFlowService.saveBatch(addFundFlowList); //更新已用费用记录 @@ -388,6 +362,92 @@ public class VtbVerificationServiceImpl extends ServiceImpl addFundFlowList, + List activityCenterGoodsOfSubject, + BigDecimal usedAmount) { + List addFundFlowListOfSubject = new ArrayList<>(); + //统计不匹配金额 + BigDecimal unMatchAmount = BigDecimal.ZERO; + for (int i = 0; i < activityCenterGoodsOfSubject.size(); i++) { + TbsActivityCenterGoods centerGoods = activityCenterGoodsOfSubject.get(i); + BigDecimal currentTimeAmount; + if(i==activityCenterGoodsOfSubject.size()-1){ + BigDecimal totalPrefixAmount = BigDecimal.ZERO; + for (VtbFundFlow fundFlow : addFundFlowListOfSubject) { + totalPrefixAmount = totalPrefixAmount.add(fundFlow.getUsedAmount()); + } + currentTimeAmount = usedAmount.subtract(totalPrefixAmount); + }else { + currentTimeAmount = usedAmount.multiply(centerGoods.getCenterGoodsRate()) + .multiply(centerGoods.getCenterRate()) + //四舍五入保留两位小数 + .divide(new BigDecimal("10000"), RoundingMode.HALF_DOWN) + .setScale(2, RoundingMode.DOWN);; + } + //可用金额 + BigDecimal allowBalance = centerGoods.getCenterGoodsAmount().subtract(centerGoods.getUsedAmount()); + if(allowBalance.compareTo(BigDecimal.ZERO)==0){ + log.debug("统计不匹配金额allowBalance:{},currentTimeAmount:{}",allowBalance.doubleValue(),currentTimeAmount.doubleValue()); + unMatchAmount.add(currentTimeAmount); + continue; + } + BigDecimal tempBalance = BigDecimal.ZERO; + //如果不够减 + if(allowBalance.compareTo(currentTimeAmount)<1){ + //统计不匹配金额 + unMatchAmount = unMatchAmount.add(currentTimeAmount.subtract(allowBalance)); + log.debug("统计不匹配金额allowBalance:{},currentTimeAmount:{}",allowBalance.doubleValue(),currentTimeAmount.doubleValue()); + currentTimeAmount = allowBalance; + }else { + tempBalance = allowBalance.subtract(currentTimeAmount); + } + VtbFundFlow fundFlow = CopierUtil.copy(centerGoods,new VtbFundFlow()); + fundFlow.setId(null); + fundFlow.setUsedAmount(currentTimeAmount); + fundFlow.setFundType(VtbFundFlowType.Verification); + fundFlow.setVerificationId(verificationId); + fundFlow.setTempBalance(tempBalance); + fundFlow.setCenterGoodItemId(centerGoods.getId()); + addFundFlowListOfSubject.add(fundFlow); + } + //打乱顺序,保存前平摊费用 + Collections.shuffle(addFundFlowListOfSubject); + for (VtbFundFlow fundFlow : addFundFlowListOfSubject) { + fundFlow.setCreateTime(null); + fundFlow.setUpdateTime(null); + fundFlow.setCreateBy(null); + fundFlow.setUpdateBy(null); + if(unMatchAmount.compareTo(BigDecimal.ZERO)>0){ + BigDecimal tmpBalance = fundFlow.getTempBalance(); + if(tmpBalance.compareTo(BigDecimal.ZERO)>0){ + if(tmpBalance.compareTo(unMatchAmount)>0){ + BigDecimal resultBalance = fundFlow.getUsedAmount().add(unMatchAmount); + fundFlow.setUsedAmount(resultBalance); + break; + }else { + unMatchAmount = unMatchAmount.subtract(fundFlow.getTempBalance()); + BigDecimal resultBalance = fundFlow.getUsedAmount().add(tmpBalance); + fundFlow.setUsedAmount(resultBalance); + } + } + }else { + break; + } + } + if(unMatchAmount.compareTo(BigDecimal.ZERO)>0){ + log.error("异常数据,费用核销[{}]超额:{}", verificationId,unMatchAmount.doubleValue()); + } + addFundFlowList.addAll(addFundFlowListOfSubject); + } + @Override public boolean checkCommitting(Long activityId) {