From 5dc6d9b7fbf97cf9d34716f8dd13dcf5123d84b6 Mon Sep 17 00:00:00 2001 From: "15989082884@163.com" <15989082884@163.com> Date: Wed, 15 Nov 2023 12:03:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E7=AB=99=E5=BC=8F=E6=94=BF=E7=AD=96?= =?UTF-8?q?=E6=A0=B8=E9=94=80=EF=BC=8C=E5=88=9B=E5=BB=BA=E8=B4=B9=E7=94=A8?= =?UTF-8?q?=EF=BC=8C=E8=B4=B9=E7=94=A8=E9=A2=84=E7=AE=97=E5=8D=A0=E7=94=A8?= =?UTF-8?q?=EF=BC=8C=E6=A0=B8=E9=94=80=EF=BC=8C=E6=94=BF=E7=AD=96=E9=A2=84?= =?UTF-8?q?=E7=AE=97=E8=B0=83=E5=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/third/PortalOfCostController.java | 28 ++- .../service/PortalOfCostApplication.java | 183 +++++++++--------- 2 files changed, 115 insertions(+), 96 deletions(-) diff --git a/src/main/java/com/qs/serve/modules/third/PortalOfCostController.java b/src/main/java/com/qs/serve/modules/third/PortalOfCostController.java index 78caf4ac..6adb119d 100644 --- a/src/main/java/com/qs/serve/modules/third/PortalOfCostController.java +++ b/src/main/java/com/qs/serve/modules/third/PortalOfCostController.java @@ -81,7 +81,33 @@ public class PortalOfCostController { - + /** + * 一站式创建费用(费用申请,根据东哥的数据关联政策生成) + * @param createBo + * @return + */ + @PostMapping("createCostApplyByPolicy") + public R createCostProcessByPolicy(@Valid @RequestBody ProcessCreatePolicyCostBo createBo,HttpServletRequest request){ + SysSyncLog syncLog = new SysSyncLog(); + syncLog.setFromPlat("一站式费用ByDong"); + syncLog.setUrl(request.getRequestURI()); + syncLog.setRequestJson(JsonUtil.objectToJson(createBo)); + syncLog.setEntityClass(ProcessCreateCostApplyBo.class.getName()); + try { + ThirdTokenUtil.checkToken(request); + portalOfCostApplication.createCostProcessByPolicy(createBo); + syncLog.setSuccessStatus(1); + } catch (Exception e) { + log.error("站式创建费用(费用申请)===>{}", JsonUtil.objectToJson(createBo)); + syncLog.setFailReason(e.getMessage()); + return R.error(e.getMessage()); + } + sysSyncLogService.save(syncLog); + if(syncLog.getSuccessStatus()!=null&&syncLog.getSuccessStatus().equals(1)){ + return R.ok(); + } + return R.error("支付异常"); + } } diff --git a/src/main/java/com/qs/serve/modules/third/service/PortalOfCostApplication.java b/src/main/java/com/qs/serve/modules/third/service/PortalOfCostApplication.java index adb5008e..7b911e94 100644 --- a/src/main/java/com/qs/serve/modules/third/service/PortalOfCostApplication.java +++ b/src/main/java/com/qs/serve/modules/third/service/PortalOfCostApplication.java @@ -37,6 +37,7 @@ import com.qs.serve.modules.tbs.common.TbsCostApplyState; import com.qs.serve.modules.tbs.common.util.TbsBudgetLogBuildUtil; import com.qs.serve.modules.tbs.entity.*; import com.qs.serve.modules.tbs.entity.dto.TbsBudgetCostResult; +import com.qs.serve.modules.tbs.mapper.TbsBudgetMapper; import com.qs.serve.modules.tbs.service.*; import com.qs.serve.modules.third.entity.*; import com.qs.serve.modules.third.util.ThirtyVerificationUtil; @@ -93,8 +94,11 @@ public class PortalOfCostApplication { private TbsCostApplyService costApplyService; private TbsCostUnItemService costUnItemService; + private TbsBudgetCostItemService costItemService; private TbsBudgetLogService budgetLogService; private TbsBudgetApplicationService budgetApplicationService; + private TbsBudgetMapper tbsBudgetMapper; + private GoodsSkuService goodsSkuService; private GoodsSpuService goodsSpuService; @@ -234,24 +238,15 @@ public class PortalOfCostApplication { if(!policyItem.getPolicyItemStatus().equals(TzPolicyItemStatus.Status_2_SyncSuccess)){ Assert.throwEx("政策项状态异常或未完成同步"); } + if(CollectionUtil.isEmpty(createBo.getGoodsList()) || createBo.getGoodsList().size()==0){ + Assert.throwEx("商品数据不能为空"); + } BmsSupplier supplier = supplierService.getById(policyItem.getSupplierId()); BmsSubject subject = subjectService.getById(policyItem.getSubjectId()); //发票号 String billNumber = createBo.getBillNumber(); - //拦截是否已保存 - LambdaQueryWrapper payLqw = new LambdaQueryWrapper<>(); - payLqw.eq(PayPayment::getBillNumber,billNumber); - long countPay = paymentService.count(payLqw); - if(countPay>0){Assert.throwEx("发票号已存在,请勿重复提交");} //校验商品信息 List skuCodes = createBo.getGoodsList().stream().map(a->a.getInventoryCode()).collect(Collectors.toList()); - LambdaQueryWrapper goodsSyncLambdaQueryWrapper = new LambdaQueryWrapper<>(); - goodsSyncLambdaQueryWrapper.eq(TzcPolicyGoodsSync::getPolicyItemCode,policyItem.getPolicyItemCode()); - goodsSyncLambdaQueryWrapper.in(TzcPolicyGoodsSync::getSkuCode,skuCodes); - long countSku = tzcPolicyGoodsSyncService.count(goodsSyncLambdaQueryWrapper); - if(countSku < skuCodes.size()){ - Assert.throwEx("部分商品不在政策范围内"); - } //初始化sku列表 List processGoodsItems = createBo.getGoodsList(); List invCodes = new ArrayList<>(); @@ -272,11 +267,12 @@ public class PortalOfCostApplication { BigDecimal totalAmount = createBo.getTotalAmount(); String costTheme = createBo.getCostTheme(); String random = String.format("%03d",new Random().nextInt(999)); - String activityCode = "G"+ StringUtils.genShortId() + random; - String activityTitle = "由核销API生成的活动"; + String costApplyCode = "CA"+CodeGenUtil.generate(CodeGenUtil.SourceKey.CostApply); + String activityCode = costApplyCode + "_1"; + String activityTitle = "由政策"+policyItem.getPolicyItemCode()+"核销一站式API生成的活动"; //构建费用申请 TbsCostApply costApply = new TbsCostApply(); - costApply.setCode("CA"+IdUtil.timeStampId()); + costApply.setCode(costApplyCode); costApply.setChargeTheme(costTheme); costApply.setChargeState(TbsCostApplyState.State_3_finished.getCode()); costApply.setSupplierId(supplierId); @@ -322,10 +318,12 @@ public class PortalOfCostApplication { activityCenter.setSubjectId(subject.getId()); activityCenter.setCenterAmount(totalAmount); activityCenter.setCenterRate(OneHundred); - activityCenter.setCenterType(CENTER_TYPE); - activityCenter.setCenterId(supplier.getId()); - activityCenter.setCenterName(supplier.getName()); - activityCenter.setCenterCode(supplier.getCode()); + + + activityCenter.setCenterType(policyItem.getCenterType()); + activityCenter.setCenterId(policyItem.getCenterId()); + activityCenter.setCenterName(policyItem.getCenterName()); + activityCenter.setCenterCode(policyItem.getCenterCode()); activityCenter.setUsedAmount(totalAmount); //活动-商品 @@ -355,10 +353,10 @@ public class PortalOfCostApplication { centerGoods.setSupplierCode(supplier.getCode()); centerGoods.setSupplierName(supplier.getName()); //设置成本中心 - centerGoods.setCenterType(CENTER_TYPE); - centerGoods.setCenterId(supplier.getId()); - centerGoods.setCenterCode(supplier.getCode()); - centerGoods.setCenterName(supplier.getName()); + centerGoods.setCenterType(policyItem.getCenterType()); + centerGoods.setCenterId(policyItem.getCenterId()); + centerGoods.setCenterName(policyItem.getCenterName()); + centerGoods.setCenterCode(policyItem.getCenterCode()); centerGoods.setCenterRate(OneHundred); centerGoods.setCenterAmount(totalAmount); //设置科目 @@ -412,8 +410,42 @@ public class PortalOfCostApplication { }); activityCenterGoodsService.saveBatch(activityCenterGoodsList); - // 因为政策申请已扣除预算,这里旧不需要再进行保存 - // budgetLogService.saveBatch(budgetLogList); +// 活动申请扣除预算,这里需要进行保存 + + LambdaQueryWrapper tbsLogLqw = new LambdaQueryWrapper<>(); + tbsLogLqw.eq(TbsBudgetLog::getPolicyItemId,policyItem.getId()); + tbsLogLqw.eq(TbsBudgetLog::getOptType,BudgetLogOptFlag.State_11.getCode()); + tbsLogLqw.isNull(TbsBudgetLog::getCostApplyId); + TbsBudgetLog oriPolicyBudgetLog = budgetLogService.getOne(tbsLogLqw); + + TbsBudgetLog dropPolicyBudgetLog = new TbsBudgetLog(); + CopierUtil.copy(oriPolicyBudgetLog,dropPolicyBudgetLog); + dropPolicyBudgetLog.setId(null); + dropPolicyBudgetLog.setOptType(BudgetLogOptFlag.State_13.getCode()); + dropPolicyBudgetLog.setAmount(totalAmount); + + + List budgetLogList = new ArrayList<>(); + List costItemList = new ArrayList<>(); + + + for (TbsActivityCenterGoods centerGoodItem : activityCenterGoodsList) { + TbsBudgetCostItem costItem = centerGoodItem.toBudgetCostItem(); + costItem.setBudgetId(dropPolicyBudgetLog.getBudgetId()); + costItem.setScheduleId(dropPolicyBudgetLog.getScheduleId()); + costItem.setScheduleItemId(dropPolicyBudgetLog.getScheduleItemId()); + costItem.setScheduleItemBudgetId(dropPolicyBudgetLog.getScheduleItemBudgetId()); + costItem.setScheduleItemName(dropPolicyBudgetLog.getItemName()); + TbsBudget currBudget = tbsBudgetMapper.selectById(dropPolicyBudgetLog.getBudgetId()); + + TbsBudgetLog budgetLog = TbsBudgetLogBuildUtil.buildTbsBudgetLog(BudgetLogOptFlag.State_1,user, costApply, costItem, currBudget,centerGoodItem.getCenterGoodsAmount(),activity); + budgetLogList.add(budgetLog); + costItemList.add(costItem); + } + + budgetLogService.save(dropPolicyBudgetLog); + budgetLogService.saveBatch(budgetLogList); + costItemService.saveBatch(costItemList); //修改预算日志,记录政策使用情况 TzcPolicyItemLog policyItemLog = TzcPolicyItemLog.toNewObject(policyItem,totalAmount); @@ -440,44 +472,9 @@ public class PortalOfCostApplication { verification.setUserName(user.getName()); verification.setAmount(totalAmount); verification.setAmountRecord(totalAmount); - verification.setPaymentState(ResultFlag.OK); + verification.setPaymentState(ResultFlag.NOT); verificationService.save(verification); - if(createBo.getToSaveCostCheckFlag()!=null&&createBo.getToSaveCostCheckFlag().equals(1)){ - //保存支付信息 - String COST_TO_PAY_API = projectApisProperties.getCostToPay(); - String json = ThirtyVerificationUtil.buildJson(supplier, subject, verification.getAmount() - , activity.getActTitle(),activity.getActStartDate().atStartOfDay(),activity.getActEndDate().atTime(23,59,59), verification); - SysSyncLog syncLog = ThirtyVerificationUtil.requestToPayment("to支付请求",verification.getVerificationCode(), COST_TO_PAY_API, json); - syncLog.setTodoState(0); - sysSyncLogService.save(syncLog); -// //发送请求到中间服务 -// XltApticlaim apticlaim = new XltApticlaim(); -// apticlaim.setVerificationCode(verification.getVerificationCode()); -// apticlaim.setCostCode(costApply.getCode()); -// apticlaim.setCostCode2(activity.getActivityCode()); -// apticlaim.setCusCode(verification.getSupplierCode()); -// apticlaim.setAmount(totalAmount); -// apticlaim.setSubjectCode(subject.getSubjectCode()); -// apticlaim.setSubjectName(subject.getSubjectName()); -// apticlaim.setExpType("TI"); -// apticlaim.setApplyType("01"); -// apticlaim.setEffDate(nowDate_); -// apticlaim.setInvoiced("2"); -// apticlaim.setCreateTime(nowDate_); -// apticlaim.setStatus("00"); -// apticlaim.setDealTime(nowDate_); -// apticlaim.setTopic(costApply.getChargeTheme()); -// try { -// //todo 如果失败做补偿处理 -// xiaoLuTonService.saveApticlaim(apticlaim); -// log.info("发送对象(apticlaim)到OA服务成功"); -// } catch (Exception e) { -// e.printStackTrace(); -// log.error("发送对象到OA服务失败,数据内容如下:{}", JsonUtil.objectToJson(apticlaim)); -// } - } - //保存核销费用结果 VtbVerificationSubject verificationSubject = new VtbVerificationSubject(); verificationSubject.setVerificationId(verification.getId()); @@ -498,41 +495,36 @@ public class PortalOfCostApplication { verificationSubjectService.save(verificationSubject); //保存支付 - PayPayment payPayment = new PayPayment(); - payPayment.setPayType(PaymentType.PAYMENT); - payPayment.setPayCode("PM"+ StringUtils.genShortId()); - payPayment.setSupplierId(supplierId); - payPayment.setSupplierCode(supplier.getCode()); - payPayment.setSupplierName(supplier.getName()); - payPayment.setPayAmount(totalAmount); - payPayment.setUserId(user.getId()); - payPayment.setUserCode(user.getCode()); - payPayment.setUserName(user.getName()); - payPayment.setPayTime(nowTime); - payPayment.setErpCode(erpCode); - payPayment.setBillNumber(billNumber); - paymentService.save(payPayment); +// PayPayment payPayment = new PayPayment(); +// payPayment.setPayType(PaymentType.PAYMENT); +// payPayment.setPayCode("PM"+ StringUtils.genShortId()); +// payPayment.setSupplierId(supplierId); +// payPayment.setSupplierCode(supplier.getCode()); +// payPayment.setSupplierName(supplier.getName()); +// payPayment.setPayAmount(totalAmount); +// payPayment.setUserId(user.getId()); +// payPayment.setUserCode(user.getCode()); +// payPayment.setUserName(user.getName()); +// payPayment.setPayTime(nowTime); +// payPayment.setErpCode(erpCode); +// payPayment.setBillNumber(billNumber); +// paymentService.save(payPayment); +// +// PayPaymentItem paymentItem = new PayPaymentItem(); +// paymentItem.setPaymentId(payPayment.getId()); +// paymentItem.setPayType(PaymentType.PAYMENT); +// paymentItem.setSupplierId(supplierId); +// paymentItem.setItemPayAmount(totalAmount); +// paymentItem.setVerificationId(verification.getId()); +// paymentItem.setVerificationSubjectId(verificationSubject.getId()); +// paymentItem.setCostApplyId(costApply.getId()); +// paymentItem.setActivityId(activity.getId()); +// paymentItem.setActivityCode(activity.getActivityCode()); +// paymentItem.setSubjectId(subject.getId()); +// paymentItem.setSubjectCode(subject.getSubjectCode()); +// paymentItem.setSubjectName(subject.getSubjectName()); +// paymentItemService.save(paymentItem); - PayPaymentItem paymentItem = new PayPaymentItem(); - paymentItem.setPaymentId(payPayment.getId()); - paymentItem.setPayType(PaymentType.PAYMENT); - paymentItem.setSupplierId(supplierId); - paymentItem.setItemPayAmount(totalAmount); - paymentItem.setVerificationId(verification.getId()); - paymentItem.setVerificationSubjectId(verificationSubject.getId()); - paymentItem.setCostApplyId(costApply.getId()); - paymentItem.setActivityId(activity.getId()); - paymentItem.setActivityCode(activity.getActivityCode()); - paymentItem.setSubjectId(subject.getId()); - paymentItem.setSubjectCode(subject.getSubjectCode()); - paymentItem.setSubjectName(subject.getSubjectName()); - paymentItemService.save(paymentItem); - - if(createBo.getToSavePaymentFlag()!=null&&createBo.getToSavePaymentFlag().equals(1)){ - //TODO 保存支付记录 - XltPaymentRecord paymentRecord = new XltPaymentRecord(); - xiaoLuTonService.savePaymentRecord(paymentRecord); - } } @@ -806,6 +798,7 @@ public class PortalOfCostApplication { budgetLogList.add(budgetLog); } } + costItemService.saveBatch(matchBudgetItem); budgetLogService.saveBatch(budgetLogList); //保存核销申请