| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long generateSalesNoticeFromSaleOrder(Long saleOrderId) { |
| | | // 1. 获取销售订单信息 |
| | | // 1. 校验是否已生成过发货通知单(防止重复生成) |
| | | MesWmSalesNoticeDO existNotice = salesNoticeMapper.selectBySaleOrderId(saleOrderId); |
| | | if (existNotice != null) { |
| | | throw exception(WM_SALES_NOTICE_ALREADY_EXISTS); |
| | | } |
| | | |
| | | // 2. 获取销售订单信息 |
| | | ErpSaleOrderRespDTO saleOrder = saleOrderApi.getSaleOrder(saleOrderId).getCheckedData(); |
| | | if (saleOrder == null) { |
| | | throw exception(WM_SALES_NOTICE_SALE_ORDER_NOT_EXISTS); |
| | | } |
| | | |
| | | // 2. 获取销售订单明细 |
| | | // 3. 获取销售订单明细 |
| | | List<ErpSaleOrderItemRespDTO> saleOrderItems = saleOrderApi.getSaleOrderItemList(saleOrderId).getCheckedData(); |
| | | if (CollUtil.isEmpty(saleOrderItems)) { |
| | | throw exception(WM_SALES_NOTICE_SALE_ORDER_ITEM_EMPTY); |
| | | } |
| | | |
| | | // 3. 生成发货通知单编码 |
| | | // 4. 生成发货通知单编码 |
| | | String code = autoCodeRecordService.generateAutoCode("SALESNOTICE_CODE", null); |
| | | |
| | | // 4. 创建发货通知单主表 |
| | | // 5. 创建发货通知单主表 |
| | | MesWmSalesNoticeDO notice = new MesWmSalesNoticeDO(); |
| | | notice.setCode(code); |
| | | notice.setName("销售订单[" + saleOrder.getNo() + "]发货通知"); |
| | |
| | | notice.setStatus(PREPARE.getStatus()); |
| | | salesNoticeMapper.insert(notice); |
| | | |
| | | // 5. 遍历明细创建发货通知单行 |
| | | // 6. 遍历明细创建发货通知单行 |
| | | for (ErpSaleOrderItemRespDTO saleOrderItem : saleOrderItems) { |
| | | MesWmSalesNoticeLineDO line = new MesWmSalesNoticeLineDO(); |
| | | line.setNoticeId(notice.getId()); |
| | |
| | | throw exception(WM_SALES_NOTICE_STATUS_NOT_APPROVED); |
| | | } |
| | | |
| | | // 2. 获取发货通知单行 |
| | | // 2. 校验是否已生成过销售出库单(防止重复生成) |
| | | if (productSalesMapper.selectByNoticeId(noticeId) != null) { |
| | | throw exception(WM_PRODUCT_SALES_ALREADY_EXISTS); |
| | | } |
| | | |
| | | // 3. 获取发货通知单行 |
| | | List<MesWmSalesNoticeLineDO> noticeLines = salesNoticeLineService.getSalesNoticeLineListByNoticeId(noticeId); |
| | | if (CollUtil.isEmpty(noticeLines)) { |
| | | throw exception(WM_SALES_NOTICE_LINE_EMPTY); |
| | | } |
| | | |
| | | // 3. 生成销售出库单编码 |
| | | // 4. 生成销售出库单编码 |
| | | String code = autoCodeRecordService.generateAutoCode("WM_PRODUCT_SALES_CODE", null); |
| | | |
| | | // 4. 创建销售出库单主表 |
| | | // 5. 创建销售出库单主表 |
| | | MesWmProductSalesDO productSales = new MesWmProductSalesDO(); |
| | | productSales.setCode(code); |
| | | productSales.setName("发货通知单[" + notice.getCode() + "]出库"); |
| | |
| | | productSales.setStatus(MesWmProductSalesStatusEnum.PREPARE.getStatus()); |
| | | productSalesMapper.insert(productSales); |
| | | |
| | | // 5. 遍历发货通知单行创建销售出库单行 |
| | | // 6. 遍历发货通知单行创建销售出库单行 |
| | | for (MesWmSalesNoticeLineDO noticeLine : noticeLines) { |
| | | MesWmProductSalesLineDO salesLine = new MesWmProductSalesLineDO(); |
| | | salesLine.setSalesId(productSales.getId()); |