|
@@ -118,65 +118,56 @@ public class PurchaseFlowServiceImpl implements PurchaseFlowService {
|
|
|
/**
|
|
|
* 发起
|
|
|
*
|
|
|
- * @param entity
|
|
|
+ * @param purchase
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional(rollbackFor = {Exception.class})
|
|
|
@Override
|
|
|
- public void start(Purchase entity) {
|
|
|
- List<ApplyPurchase> goodsList = entity.getGoodsList();
|
|
|
+ public void start(Purchase purchase) {
|
|
|
+ List<ApplyPurchase> goodsList = purchase.getGoodsList();
|
|
|
Assert.notEmpty(goodsList, "采购物品不能为空");
|
|
|
|
|
|
if (!redisLockClient.lockFair(REDIS_LOCK_CACHE_KEY, () -> {
|
|
|
- if (Func.isEmpty(entity.getId())) {
|
|
|
- entity.setId(IdWorker.getId());
|
|
|
+ if (Func.isEmpty(purchase.getId())) {
|
|
|
+ purchase.setId(IdWorker.getId());
|
|
|
}
|
|
|
|
|
|
- if (Func.isBlank(entity.getCode())) {
|
|
|
+ if (Func.isBlank(purchase.getCode())) {
|
|
|
// 获取编码
|
|
|
- entity.setCode(CodeEnum.APPLY_PURCHASE.getCode());
|
|
|
+ purchase.setCode(CodeEnum.PURCHASE.getCode());
|
|
|
// 查询编码是否已存在
|
|
|
- if (!checkCodeIsExist(null, entity.getCode())) {
|
|
|
- throw new ServiceException("后台自增编码存在重复,请重试或联系管理员!编码:" + entity.getCode());
|
|
|
+ if (!checkCodeIsExist(null, purchase.getCode())) {
|
|
|
+ throw new ServiceException("后台自增编码存在重复,请重试或联系管理员!编码:" + purchase.getCode());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //流程标题
|
|
|
- String title = AuthUtil.getUserName() + " 在" + LocalDate.now() + "日发起了 采购审批流程(单号:" + entity.getCode() + ")";
|
|
|
+ purchase.setStatus(PurchaseStatusEnum.STATUS_10.getKey());
|
|
|
+ // 采购金额
|
|
|
+ BigDecimal price = new BigDecimal(BigDecimal.ZERO.intValue());
|
|
|
+
|
|
|
+ for (ApplyPurchase goods : goodsList) {
|
|
|
+ goods.setPurchaseId(purchase.getId());
|
|
|
+ goods.setPurchaseCode(purchase.getCode());
|
|
|
+ goods.setStatus(ApplyPurchaseStatusEnum.STATUS_40.getKey());
|
|
|
+ price = price.add(BigDecimalUtil.multiply(goods.getQuantity(), goods.getUnitPrice(), 2));
|
|
|
+ }
|
|
|
+ purchase.setPrice(price);
|
|
|
+ purchaseService.saveOrUpdate(purchase);
|
|
|
+ applyPurchaseService.saveOrUpdateBatch(goodsList);
|
|
|
|
|
|
- ExampleResult exampleResult;
|
|
|
- if (Func.isEmpty(entity.getFlowId())) {
|
|
|
- //启动流程
|
|
|
- exampleResult = flowConstructor().create(entity.getId(), title, entity.getFlowRemark(), entity.getId());
|
|
|
+ // 流程标题
|
|
|
+ String title = AuthUtil.getUserName() + " 在" + LocalDate.now() + "日发起了 采购审批流程(单号:" + purchase.getCode() + ")";
|
|
|
+
|
|
|
+ if (Func.isEmpty(purchase.getFlowId())) {
|
|
|
+ // 启动流程
|
|
|
+ flowConstructor().create(purchase.getId(), title, purchase.getFlowRemark(), purchase.getId());
|
|
|
} else {
|
|
|
- //获取当前节点对应的按钮ID
|
|
|
- Long buttonId = iFlowClient.getButtonIdByExampleInfoId(entity.getFlowId());
|
|
|
- //审批操作(用于驳回后重新提交)
|
|
|
- exampleResult = flowConstructor().jump(entity.getId(), buttonId, entity.getFlowRemark(), entity.getId());
|
|
|
+ // 获取当前节点对应的按钮ID
|
|
|
+ Long buttonId = iFlowClient.getButtonIdByExampleInfoId(purchase.getFlowId());
|
|
|
+ // 审批操作(用于驳回后重新提交)
|
|
|
+ flowConstructor().jump(purchase.getId(), buttonId, purchase.getFlowRemark(), purchase.getId());
|
|
|
}
|
|
|
|
|
|
- ExampleResult finalExampleResult = exampleResult;
|
|
|
- exampleResult.after(() -> {
|
|
|
- //处理下一节点处理人信息
|
|
|
- JSONObject nextNodeHandleUserInfo = new JSONObject();
|
|
|
- FlowUserUtil.getNextNodeHandleUserInfo(finalExampleResult, nextNodeHandleUserInfo);
|
|
|
- entity.setFlowId(nextNodeHandleUserInfo.getLong("flowId"));
|
|
|
- entity.setFlowApproverId(nextNodeHandleUserInfo.getLong("flowApproverId"));
|
|
|
- entity.setFlowApproverName(nextNodeHandleUserInfo.getString("flowApproverName"));
|
|
|
- entity.setStatus(PurchaseStatusEnum.STATUS_10.getKey());
|
|
|
- //采购金额
|
|
|
- BigDecimal price = new BigDecimal(BigDecimal.ZERO.intValue());
|
|
|
-
|
|
|
- for (ApplyPurchase goods : goodsList) {
|
|
|
- goods.setPurchaseId(entity.getId());
|
|
|
- goods.setPurchaseCode(entity.getCode());
|
|
|
- goods.setStatus(ApplyPurchaseStatusEnum.STATUS_40.getKey());
|
|
|
- price = price.add(BigDecimalUtil.multiply(goods.getQuantity(), goods.getUnitPrice(), 2));
|
|
|
- }
|
|
|
- entity.setPrice(price);
|
|
|
- purchaseService.saveOrUpdate(entity);
|
|
|
- applyPurchaseService.saveOrUpdateBatch(goodsList);
|
|
|
- });
|
|
|
return true;
|
|
|
})) {
|
|
|
throw new ServiceException("当前系统繁忙,请稍后重试!");
|