From e4766cef5227aec46d573b7b1265a2ddf0264cad Mon Sep 17 00:00:00 2001 From: Kelvin Date: Sun, 5 Jan 2025 20:31:04 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=87=BA=E5=BA=93=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E8=AE=A2=E5=8D=95=E7=94=9F=E6=88=90=E5=87=BA?= =?UTF-8?q?=E5=BA=93=E8=AE=A1=E5=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../md/controller/WmsOutPlanController.java | 75 ++++++++++++++++++- .../md/domain/dto/WmsOutboundOrderDto.java | 27 +++++++ 2 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 ktg-mes/src/main/java/com/ktg/mes/md/domain/dto/WmsOutboundOrderDto.java diff --git a/ktg-mes/src/main/java/com/ktg/mes/md/controller/WmsOutPlanController.java b/ktg-mes/src/main/java/com/ktg/mes/md/controller/WmsOutPlanController.java index aa97bf0..8655651 100644 --- a/ktg-mes/src/main/java/com/ktg/mes/md/controller/WmsOutPlanController.java +++ b/ktg-mes/src/main/java/com/ktg/mes/md/controller/WmsOutPlanController.java @@ -8,14 +8,19 @@ import com.ktg.common.core.page.TableDataInfo; import com.ktg.common.enums.BusinessType; import com.ktg.common.utils.poi.ExcelUtil; import com.ktg.generator.util.MultiModuleCodeGenerator; -import com.ktg.mes.md.domain.WmsOutPlan; -import com.ktg.mes.md.domain.WmsOutPlanDetailEntity; +import com.ktg.mes.md.domain.*; +import com.ktg.mes.md.domain.dto.WmsOutboundOrderDto; +import com.ktg.mes.md.service.IMdItemService; +import com.ktg.mes.md.service.IWmsBusinessTypeService; import com.ktg.mes.md.service.IWmsOutPlanService; +import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -27,9 +32,11 @@ import java.util.List; */ @RestController @RequestMapping("/md/PLAN") +@RequiredArgsConstructor public class WmsOutPlanController extends BaseController { - @Autowired - private IWmsOutPlanService wmsOutPlanService; + private final IWmsOutPlanService wmsOutPlanService; + private final IWmsBusinessTypeService wmsBusinessTypeService; + private final IMdItemService mdItemService; /** * 查询出库计划管理列表 @@ -50,6 +57,66 @@ public class WmsOutPlanController extends BaseController { return toAjax(wmsOutPlanService.insertWmsOutPlanAndRun(wmsOutPlan)); } + + /** + * 订单生成出库计划 + * @param wmsOutboundOrderDto + * @return + */ + @PostMapping("/open/order/add") + public AjaxResult openOrderAdd(@RequestBody @Valid WmsOutboundOrderDto wmsOutboundOrderDto) { + // 查询业务类型 + WmsBusinessType wmsBusinessType = wmsBusinessTypeService.selectWmsBusinessTypeByCode(wmsOutboundOrderDto.getTypeCode()); + if (wmsBusinessType == null) { + return AjaxResult.error("出库类型编码错误:" + wmsOutboundOrderDto.getTypeCode()); + } + + // 查询物料信息 + MdItem mdItem = mdItemService.selectMdItemByCode(wmsOutboundOrderDto.getMaterialCode()); + if (mdItem == null) { + return AjaxResult.error("物料编码错误:" + wmsOutboundOrderDto.getMaterialCode()); + } + + // 创建出库计划 + WmsOutPlan wmsOutPlan = new WmsOutPlan(); + wmsOutPlan.setPlanCode(MultiModuleCodeGenerator.generateTaskCode("CKP")); + wmsOutPlan.setWmsBusinessTypeId(wmsBusinessType.getTypeId()); + wmsOutPlan.setWmsBusinessType(wmsBusinessType); + wmsOutPlan.setPlanType("SGLR"); + wmsOutPlan.setPlanState("0"); + wmsOutPlan.setRemark("订单号: " + wmsOutboundOrderDto.getOrderId()); + // 创建出库计划明细 + ArrayList wmsOutPlanDetails = getWmsOutPlanDetails(wmsOutboundOrderDto, mdItem); + wmsOutPlan.setWmsOutPlanDetailList(wmsOutPlanDetails); + + // 插入出库计划并执行 + try { + int i = wmsOutPlanService.insertWmsOutPlanAndRun(wmsOutPlan); + if (i > 0) { + return AjaxResult.success("出库任务创建成功"); + } else { + return AjaxResult.error("出库任务创建失败,原因:数据库插入失败"); + } + } catch (Exception e) { + return AjaxResult.error("出库任务创建失败,原因:" + e.getMessage()); + } + } + + private static ArrayList getWmsOutPlanDetails(WmsOutboundOrderDto wmsOutboundOrderDto, MdItem mdItem) { + WmsOutPlanDetail wmsOutPlanDetail = new WmsOutPlanDetail(); + wmsOutPlanDetail.setMdItemId(mdItem.getItemId()); + wmsOutPlanDetail.setMdItemName(mdItem.getItemName()); + wmsOutPlanDetail.setMdItemCode(mdItem.getItemCode()); + wmsOutPlanDetail.setMdItemUnit(mdItem.getUnitName()); + wmsOutPlanDetail.setPlannedQuantity(wmsOutboundOrderDto.getQuantity()); + wmsOutPlanDetail.setRealQuantity(wmsOutboundOrderDto.getQuantity()); + wmsOutPlanDetail.setDetailBatchNum(wmsOutboundOrderDto.getOrderId()); + wmsOutPlanDetail.setDetailState("0"); + ArrayList wmsOutPlanDetails = new ArrayList<>(); + wmsOutPlanDetails.add(wmsOutPlanDetail); + return wmsOutPlanDetails; + } + /** * 查询出库计划管理列表 */ diff --git a/ktg-mes/src/main/java/com/ktg/mes/md/domain/dto/WmsOutboundOrderDto.java b/ktg-mes/src/main/java/com/ktg/mes/md/domain/dto/WmsOutboundOrderDto.java new file mode 100644 index 0000000..b1a7a47 --- /dev/null +++ b/ktg-mes/src/main/java/com/ktg/mes/md/domain/dto/WmsOutboundOrderDto.java @@ -0,0 +1,27 @@ +package com.ktg.mes.md.domain.dto; + +import lombok.Getter; +import lombok.Setter; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +// 根据订单出库 +@Getter +@Setter +public class WmsOutboundOrderDto { + // 订单号 + @NotBlank(message = "订单号不能为空") + private String orderId; + // 物料编码 + @NotBlank(message = "物料编码不能为空") + private String materialCode; + // 出库类型编码 + @NotBlank(message = "出库类型编码不能为空") + private String typeCode; + // 出库数量 + @NotNull(message = "出库数量不能为空") + @Min(value = 1, message = "数量必须大于等于 1") + private int quantity; +}