| | |
| | | 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) |
| | |
| | | return arrivalNoticeId; |
| | | } |
| | | |
| | | } |
| | | } |