| | |
| | | accountService.validateAccount(createReqVO.getAccountId()); |
| | | } |
| | | // 1.4 生成订单号,并校验唯一性 |
| | | String no = noRedisDAO.generate(ErpNoRedisDAO.PURCHASE_ORDER_NO_PREFIX); |
| | | if (purchaseOrderMapper.selectByNo(no) != null) { |
| | | throw exception(PURCHASE_ORDER_NO_EXISTS); |
| | | } |
| | | String no = noRedisDAO.generate(ErpNoRedisDAO.PURCHASE_ORDER_NO_PREFIX, |
| | | candidate -> purchaseOrderMapper.selectByNo(candidate) != null); |
| | | |
| | | // 2.1 插入订单(submit=false 时保存为草稿,等待业务确认后手动提交审批) |
| | | ErpPurchaseOrderDO purchaseOrder = BeanUtils.toBean(createReqVO, ErpPurchaseOrderDO.class, in -> in |
| | | .setNo(no).setStatus(submit ? ErpAuditStatus.PROCESS.getStatus() : ErpAuditStatus.DRAFT.getStatus()) |
| | | .setInCount(BigDecimal.ZERO).setInStatus(ErpPurchaseOrderInStatusEnum.NOT_IN.getStatus())); |
| | | if (purchaseOrder.getDepositPrice() == null) { |
| | | purchaseOrder.setDepositPrice(BigDecimal.ZERO); |
| | | } |
| | | calculateTotalPrice(purchaseOrder, purchaseOrderItems); |
| | | purchaseOrderMapper.insert(purchaseOrder); |
| | | // 2.2 插入订单项 |
| | |
| | | |
| | | // 2.1 更新订单 |
| | | ErpPurchaseOrderDO updateObj = BeanUtils.toBean(updateReqVO, ErpPurchaseOrderDO.class); |
| | | if (updateObj.getDepositPrice() == null) { |
| | | updateObj.setDepositPrice(BigDecimal.ZERO); |
| | | } |
| | | calculateTotalPrice(updateObj, purchaseOrderItems); |
| | | purchaseOrderMapper.updateById(updateObj); |
| | | // 2.2 更新订单项 |
| | |
| | | } |
| | | |
| | | // 3. 单号:填了就用(校验唯一),没填自动生成 |
| | | String no = StrUtil.isNotBlank(head.getNo()) ? head.getNo().trim() |
| | | : noRedisDAO.generate(ErpNoRedisDAO.PURCHASE_ORDER_NO_PREFIX); |
| | | if (purchaseOrderMapper.selectByNo(no) != null) { |
| | | throw new IllegalArgumentException("采购单编号已存在:" + no); |
| | | String no; |
| | | if (StrUtil.isNotBlank(head.getNo())) { |
| | | no = head.getNo().trim(); |
| | | if (purchaseOrderMapper.selectByNo(no) != null) { |
| | | throw new IllegalArgumentException("采购单编号已存在:" + no); |
| | | } |
| | | } else { |
| | | no = noRedisDAO.generate(ErpNoRedisDAO.PURCHASE_ORDER_NO_PREFIX, |
| | | candidate -> purchaseOrderMapper.selectByNo(candidate) != null); |
| | | } |
| | | |
| | | // 4. 组装主表:勾选“是否审核” => 已审核(20),否则未审核(10) |
| | |
| | | if (!submitable) { |
| | | throw exception(PURCHASE_ORDER_SUBMIT_FAIL_STATUS); |
| | | } |
| | | // 2. 付款日期必选:采购申请自动生成的草稿订单没有付款日期,提交前必须先编辑补齐 |
| | | if (purchaseOrder.getPaymentDate() == null) { |
| | | throw exception(PURCHASE_ORDER_PAYMENT_DATE_REQUIRED); |
| | | } |
| | | |
| | | // 2. 创建 BPM 流程实例 |
| | | // 3. 创建 BPM 流程实例 |
| | | // 全局免审批:业务校验通过后直接执行审批通过逻辑,无需流程模型。 |
| | | if (processInstanceApi.isGlobalAutoApprove()) { |
| | | purchaseOrderMapper.updateById(new ErpPurchaseOrderDO() |
| | |
| | | return arrivalNoticeId; |
| | | } |
| | | |
| | | } |
| | | } |