Browse Source

一站式政策核销,创建费用,费用预算占用,核销,政策预算调减

v1.0
15989082884@163.com 2 years ago
parent
commit
5dc6d9b7fb
  1. 28
      src/main/java/com/qs/serve/modules/third/PortalOfCostController.java
  2. 183
      src/main/java/com/qs/serve/modules/third/service/PortalOfCostApplication.java

28
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("支付异常");
}
}

183
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<PayPayment> payLqw = new LambdaQueryWrapper<>();
payLqw.eq(PayPayment::getBillNumber,billNumber);
long countPay = paymentService.count(payLqw);
if(countPay>0){Assert.throwEx("发票号已存在,请勿重复提交");}
//校验商品信息
List<String> skuCodes = createBo.getGoodsList().stream().map(a->a.getInventoryCode()).collect(Collectors.toList());
LambdaQueryWrapper<TzcPolicyGoodsSync> 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<ProcessGoodsItem> processGoodsItems = createBo.getGoodsList();
List<String> 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<TbsBudgetLog> 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<TbsBudgetLog> budgetLogList = new ArrayList<>();
List<TbsBudgetCostItem> 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);
//保存核销申请

Loading…
Cancel
Save