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 eabcf01c..2bf0a964 100644 --- a/src/main/java/com/qs/serve/modules/third/PortalOfCostController.java +++ b/src/main/java/com/qs/serve/modules/third/PortalOfCostController.java @@ -209,7 +209,37 @@ public class PortalOfCostController { if(syncLog.getSuccessStatus()!=null&&syncLog.getSuccessStatus().equals(1)){ return R.ok(); } - return R.error("支付异常"); + return R.error("创建异常"); + } + + /** + * 一站式删除政策费用(费用申请,根据东哥的数据关联政策生成) + * @param recId + * @return + */ + @GetMapping("deleteCostApplyByPolicy") + public R deleteCostApplyByPolicy(String recId,HttpServletRequest request){ + SysSyncLog syncLog = new SysSyncLog(); + syncLog.setFromPlat("一站式删除费用ByDong"); + syncLog.setUrl(request.getRequestURI()); + syncLog.setRequestJson(JsonUtil.objectToJson(recId)); + syncLog.setEntityClass(ProcessCreateCostApplyBo.class.getName()); + try { + ThirdTokenUtil.checkToken(request); + portalOfCostApplication.deleteCostProcessByPolicy(recId); + syncLog.setSuccessStatus(1); + } catch (Exception e) { + log.error("一站式删除政策费用(费用申请)===>{}", JsonUtil.objectToJson(recId)); + e.printStackTrace(); + syncLog.setFailReason(e.getMessage()); + sysSyncLogService.save(syncLog); + 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 2a673320..d621398a 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 @@ -133,151 +133,56 @@ public class PortalOfCostApplication { private ProjectApisProperties projectApisProperties; - + /** + * + * @param recId + */ @Transactional(rollbackFor = Exception.class) - public void syncXltPolicyItemPayment(AptPolicyPayment createBo){ - TzcPolicyItem policyItem = policyItemServiceService.getByPolicyItemCode(createBo.getPolicyItemCode()); - if(policyItem==null){ - return; - } - //发票号 - String billNumber = createBo.getBillCode(); - //拦截是否已保存 - LambdaQueryWrapper payLqw = new LambdaQueryWrapper<>(); - payLqw.eq(PayPayment::getBillNumber,billNumber); - long countPay = paymentService.count(payLqw); - if(countPay>0){ - //发票号已存在 - return; + public void deleteCostProcessByPolicy(String recId) { + List histCostApplyList = costApplyService.list(new LambdaQueryWrapper() + .eq(TbsCostApply::getRecId,recId)); + if(histCostApplyList.size()==0){ + Assert.throwEx("记录不存在,RecId:"+recId); } - BmsSupplier supplier = supplierService.getById(policyItem.getSupplierId()); - BmsSubject subject = subjectService.getById(policyItem.getSubjectId()); - //常用参数 - LocalDateTime nowTime = LocalDateTime.now(); - String erpCode = ""; - Long supplierId = Long.parseLong(supplier.getId()); - BigDecimal totalAmount = createBo.getAmount(); - - //修改预算日志,记录政策使用情况 - TzcPolicyItemLog policyItemLog = TzcPolicyItemLog.toNewObject(policyItem,totalAmount); - policyItemLogService.save(policyItemLog); - - //更新项使用情况 - TzcPolicyItem policyItemParam = new TzcPolicyItem(); - policyItemParam.setId(policyItem.getId()); - policyItemParam.setUsedAmount(policyItem.getUsedAmount().add(totalAmount)); - policyItemServiceService.updateById(policyItemParam); - - //保存核销申请 - VtbVerification verification = new VtbVerification(); - verification.setVerificationCode("HX"+ IdUtil.timeStampId()); - verification.setVerificationMainCode(verification.getVerificationCode()); - verification.setFinishedTime(nowTime); - verification.setVerificationState(VtbVerificationState.Finished.getCode()); - verification.setPolicyItemId(policyItem.getId()); - verification.setPolicyItemCode(policyItem.getPolicyItemCode()); - verification.setSupplierId(supplierId); - verification.setSupplierCode(supplier.getCode()); - verification.setSupplierName(supplier.getName()); - verification.setUserId("000"); - verification.setUserCode("000"); - verification.setUserName("ApiUser"); - verification.setAmount(totalAmount); - verification.setAmountRecord(totalAmount); - verification.setPaymentState(ResultFlag.OK); - verificationService.save(verification); - - - //保存核销费用结果 - VtbVerificationSubject verificationSubject = new VtbVerificationSubject(); - verificationSubject.setVerificationId(verification.getId()); - verificationSubject.setVerificationSubCode(verification.getVerificationCode()+"_1"); - verificationSubject.setPolicyItemId(policyItem.getId()); - verificationSubject.setPolicyItemCode(policyItem.getPolicyItemCode()); - verificationSubject.setSubjectId(subject.getId()); - verificationSubject.setSubjectCode(subject.getSubjectCode()); - verificationSubject.setSubjectName(subject.getSubjectName()); - verificationSubject.setSupplierId(Long.parseLong(supplier.getId())); - verificationSubject.setSupplierCode(supplier.getCode()); - verificationSubject.setSupplierName(supplier.getName()); - verificationSubject.setPayFinishedFlag(ResultFlag.OK); - verificationSubject.setUsedAmount(totalAmount); - verificationSubject.setUsedAmountRecord(totalAmount); - verificationSubject.setCountPerson(0); - verificationSubject.setCountSession(0); - 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("000"); - payPayment.setUserCode("000"); - payPayment.setUserName("ApiUser"); - 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.setPolicyItemId(policyItem.getId()); - paymentItem.setPolicyItemCode(policyItem.getPolicyItemCode()); - paymentItem.setSubjectId(subject.getId()); - paymentItem.setSubjectCode(subject.getSubjectCode()); - paymentItem.setSubjectName(subject.getSubjectName()); - paymentItem.setPayTime(nowTime); - - paymentItemService.save(paymentItem); + for (TbsCostApply costApply : histCostApplyList) { + costApplyService.removeById(costApply.getId()); + QueryWrapper costqw = new QueryWrapper(); + costqw.eq("cost_apply_id",costApply.getId()); + activityService.remove(costqw); + activitySubjectService.remove(costqw); + activityCenterService.remove(costqw); + activityGoodsService.remove(costqw); + activityCenterGoodsService.remove(costqw); + budgetLogService.remove(costqw); + costItemService.remove(costqw); + verificationService.remove(costqw); + verificationSubjectService.remove(costqw); + paymentService.remove(costqw); + paymentItemService.remove(costqw); - } + Long policyItemId = costApply.getPolicyItemId(); + TzcPolicyItem policyItem = policyItemServiceService.getById(policyItemId); + LambdaQueryWrapper budgetLogLambdaQueryWrapper = new LambdaQueryWrapper<>(); + budgetLogLambdaQueryWrapper.eq(TbsBudgetLog::getCreateCostId,costApply.getId()); + budgetLogLambdaQueryWrapper.eq(TbsBudgetLog::getCreatePolicyItemId,policyItemId); + budgetLogLambdaQueryWrapper.eq(TbsBudgetLog::getOptType,BudgetLogOptFlag.State_13.getCode()); + budgetLogService.remove(budgetLogLambdaQueryWrapper); - /** - * 重新构建 - */ - public void rebuildCreateCostProcessByPolicy(){ - Long[] errorCostIds = new Long[]{279525L,280099L,280383L,280384L,280385L,280386L,280387L,280390L,280393L,280395L,280396L, - 280397L,280403L,280408L,280410L,280413L,280422L,280424L,280425L,280428L,280433L,280442L,280447L,280454L, - 280456L,280458L,280460L,280466L,280488L,280494L,280503L,280504L,280508L,280510L,280513L,280530L,280536L, - 280543L,280546L,280553L,280555L,280556L,280557L,280558L,280562L,280563L,280565L,280566L,280567L,280569L, - 280570L,280573L,280579L,280583L,280587L,280600L,280610L,280623L,280624L,280626L,280650L,280652L,280653L, - 280655L,280657L,280663L,280664L,280672L,280678L,280679L,280687L,280691L,280694L,280697L,280698L,280699L, - 280700L,280701L,280720L,280721L,280723L,280736L,280741L,280743L,280745L,280748L,280749L,280750L,280757L, - 280760L,280775L,280798L,280799L,280800L,280803L,280806L,280825L,280835L,280844L,280845L,280849L,280850L, - 280851L,280852L,280856L,280859L,280869L,280871L,280872L,280873L,280874L}; - - // costApplyService.save(costApply); - // activityService.save(activity); - // activitySubjectService.save(activitySubject); - // activityCenterService.save(activityCenter); - // activityGoodsService.saveBatch(activityGoodsList); - // activityCenterGoodsService.saveBatch(activityCenterGoodsList); - - // budgetLogService.save(dropPolicyBudgetLog); - // budgetLogService.saveBatch(budgetLogList); - // costItemService.saveBatch(costItemList); - - // policyItemLogService.save(policyItemLog); - // policyItemServiceService.updateById(policyItemParam); - - // verificationService.save(verification); - // verificationSubjectService.save(verificationSubject); + //修改预算日志,记录政策使用情况 + TzcPolicyItemLog policyItemLog = TzcPolicyItemLog.toNewObject(policyItem,costApply.getTotalActivityAmount().negate()); + policyItemLogService.save(policyItemLog); + BigDecimal policyItemUsedAmt = tzcPolicyItemMapper.sumPolicyItemTranAmt(policyItem.getId()); + TzcPolicyItem policyItemParam = new TzcPolicyItem(); + policyItemParam.setId(policyItem.getId()); + policyItemParam.setUsedAmount(policyItemUsedAmt); + policyItemServiceService.updateById(policyItemParam); + } } - /** - * 已弃用,适用 syncXltPolicyItemPayment代替 + * * @param createBo */ @Transactional(rollbackFor = Exception.class) @@ -323,7 +228,7 @@ public class PortalOfCostApplication { checkLqw.eq(TbsCostApply::getBillNumber,billNumber); checkLqw.eq(TbsCostApply::getPolicyItemId,policyItem.getId()); if(costApplyService.count(checkLqw)>0L){ - Assert.throwEx("记录已存在"); + Assert.throwEx("记录已存在,相同的发票和政策ID"); } LambdaQueryWrapper tbsLogLqw = new LambdaQueryWrapper<>(); @@ -342,23 +247,26 @@ public class PortalOfCostApplication { Assert.throwEx("政策预算不足,可用余额:"+surplusAmt); } - //移除历史记录 + //历史记录 List histCostApplyList = costApplyService.list(new LambdaQueryWrapper() .eq(TbsCostApply::getRecId,createBo.getRecId())); - for (TbsCostApply costApply : histCostApplyList) { - costApplyService.removeById(costApply.getId()); - QueryWrapper costqw = new QueryWrapper(); - costqw.eq("cost_apply_id",costApply.getId()); - activityService.remove(costqw); - activitySubjectService.remove(costqw); - activityCenterService.remove(costqw); - activityGoodsService.remove(costqw); - activityCenterGoodsService.remove(costqw); - budgetLogService.remove(costqw); - costItemService.remove(costqw); - verificationService.remove(costqw); - verificationSubjectService.remove(costqw); + if(histCostApplyList.size()>0){ + Assert.throwEx("记录已存在,相同的RecId:"+createBo.getRecId()); } +// for (TbsCostApply costApply : histCostApplyList) { +// costApplyService.removeById(costApply.getId()); +// QueryWrapper costqw = new QueryWrapper(); +// costqw.eq("cost_apply_id",costApply.getId()); +// activityService.remove(costqw); +// activitySubjectService.remove(costqw); +// activityCenterService.remove(costqw); +// activityGoodsService.remove(costqw); +// activityCenterGoodsService.remove(costqw); +// budgetLogService.remove(costqw); +// costItemService.remove(costqw); +// verificationService.remove(costqw); +// verificationSubjectService.remove(costqw); +// } //构建费用申请 TbsCostApply costApply = new TbsCostApply(); @@ -1421,52 +1329,4 @@ public class PortalOfCostApplication { } - /** - * 修复数据方法,修复后可删除 - */ - public void repairCaCost(){ - //Assert.throwEx("DEV"); - LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); - lqw.eq(SysSyncLog::getFromPlat,"一站式费用ByDong"); - //只处理成功的 - lqw.eq(SysSyncLog::getSuccessStatus,1); - lqw.in(SysSyncLog::getId,13309L); - List syncLogList = sysSyncLogService.list(lqw); - for (SysSyncLog syncLog : syncLogList) { - ProcessCreatePolicyCostBo applyBo = JsonUtil.jsonToPojo(syncLog.getRequestJson(),ProcessCreatePolicyCostBo.class); - String title = applyBo.getCostTheme(); - LambdaQueryWrapper costLqw = new LambdaQueryWrapper<>(); - costLqw.eq(TbsCostApply::getChargeTheme,title); - List costApplyList = costApplyService.list(costLqw); - - SysTableTemp sysTableTemp = new SysTableTemp(); - sysTableTemp.setTableName("sys_sync_log"); - sysTableTemp.setTableId(syncLog.getId()+""); - sysTableTemp.setOptionTitle("0305修复CA数据"); - - for (int i = 0; i < costApplyList.size(); i++) { - TbsCostApply costApply = costApplyList.get(i); - costApplyService.removeById(costApply.getId()); - QueryWrapper costqw = new QueryWrapper(); - costqw.eq("cost_apply_id",costApply.getId()); - activityService.remove(costqw); - activitySubjectService.remove(costqw); - activityCenterService.remove(costqw); - activityGoodsService.remove(costqw); - activityCenterGoodsService.remove(costqw); - budgetLogService.remove(costqw); - costItemService.remove(costqw); - verificationService.remove(costqw); - verificationSubjectService.remove(costqw); - } - try { - this.createCostProcessByPolicy(applyBo); - sysTableTemp.setDealState(1); - } catch (Exception e) { - sysTableTemp.setResultMsg(e.getMessage()); - } - sysTableTempMapper.insert(sysTableTemp); - } - } - } diff --git a/src/main/java/com/qs/serve/task/TzcPolicyTask.java b/src/main/java/com/qs/serve/task/TzcPolicyTask.java index 48883514..55c392bc 100644 --- a/src/main/java/com/qs/serve/task/TzcPolicyTask.java +++ b/src/main/java/com/qs/serve/task/TzcPolicyTask.java @@ -36,22 +36,6 @@ public class TzcPolicyTask { private PortalOfCostApplication portalOfCostApplication; private XiaoLuTonService xiaoLuTonService; - /** - * 根据销路通支付数据,和本系统政策匹对,并生成本系统核销及支付信息 - */ - //@Scheduled(cron="0 0 3 * * ?") - public void syncFromXltPolicyPayment(){ - AuthContextUtils.setTenant("001"); - xiaoLuTonService.listPolicyPayments(); - Object obj = xiaoLuTonService.listPolicyPayments().getData(); - String json = obj.toString(); - List policyPaymentList = JsonUtil.jsonToList(json,AptPolicyPayment.class); - if(CollectionUtil.isNotEmpty(policyPaymentList)){ - for (AptPolicyPayment policyPayment : policyPaymentList) { - portalOfCostApplication.syncXltPolicyItemPayment(policyPayment); - } - } - } /** * 同步政策到销路通