From ffde4dbf79a70128c01c3e5193f1b40f022be39a Mon Sep 17 00:00:00 2001
From: cuilei <ray_tsu1@163.com>
Date: 星期五, 29 八月 2025 16:05:16 +0800
Subject: [PATCH] 排产工单生成排产计划接口调整

---
 src/main/java/org/jeecg/modules/mes/service/impl/MesProductionWorkOrderServiceImpl.java |   49 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/jeecg/modules/mes/service/impl/MesProductionWorkOrderServiceImpl.java b/src/main/java/org/jeecg/modules/mes/service/impl/MesProductionWorkOrderServiceImpl.java
index 2b407ff..83314ea 100644
--- a/src/main/java/org/jeecg/modules/mes/service/impl/MesProductionWorkOrderServiceImpl.java
+++ b/src/main/java/org/jeecg/modules/mes/service/impl/MesProductionWorkOrderServiceImpl.java
@@ -7,8 +7,10 @@
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.apache.commons.lang.StringUtils;
 import org.jeecg.common.constant.CommonConstant;
 import org.jeecg.common.exception.JeecgBootException;
+import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.modules.base.entity.Factory;
 import org.jeecg.modules.base.entity.LineSideWarehouse;
 import org.jeecg.modules.base.entity.Shift;
@@ -17,8 +19,11 @@
 import org.jeecg.modules.base.service.ILineSideWarehouseService;
 import org.jeecg.modules.base.service.IShiftGroupService;
 import org.jeecg.modules.base.service.IShiftService;
+import org.jeecg.modules.lsw.entity.LswMaterial;
 import org.jeecg.modules.lsw.entity.LswMaterialInventory;
+import org.jeecg.modules.lsw.enums.MaterialCategoryEnum;
 import org.jeecg.modules.lsw.service.ILswMaterialInventoryService;
+import org.jeecg.modules.lsw.service.ILswMaterialService;
 import org.jeecg.modules.lsw.vo.LswMaterialInventoryVo;
 import org.jeecg.modules.mes.dto.MesProductionWorkScheduleRequest;
 import org.jeecg.modules.mes.entity.MesKittingCompletenessCheck;
@@ -28,6 +33,7 @@
 import org.jeecg.modules.mes.service.IMesProductionWorkOrderService;
 import org.jeecg.modules.mes.entity.MesProductionWorkOrder;
 import org.jeecg.modules.mes.mapper.MesProductionWorkOrderMapper;
+import org.jeecg.modules.mes.utils.CommonUtils;
 import org.jeecg.modules.pms.entity.PmsProcessBillMaterials;
 import org.jeecg.modules.pms.entity.PmsProcessBillMaterialsDetail;
 import org.jeecg.modules.pms.service.IPmsProcessBillMaterialsDetailService;
@@ -65,6 +71,8 @@
     @Autowired
     private IPmsProcessBillMaterialsDetailService pmsProcessBillMaterialsDetailService;
     @Autowired
+    private ILswMaterialService lswMaterialService;
+    @Autowired
     private ILswMaterialInventoryService lswMaterialInventoryService;
     @Autowired
     private ILineSideWarehouseService lineSideWarehouseService;
@@ -77,6 +85,9 @@
                         .eq(ShiftGroup::getFactoryId, request.getFactoryId())
                         .eq(ShiftGroup::getDelFlag, CommonConstant.DEL_FLAG_0))
                 .stream().collect(Collectors.toMap(ShiftGroup::getShiftId, v1 -> v1, (v1, v2) -> v1));
+        if (shiftGroupMap.isEmpty()) {
+            throw new JeecgBootException("璇ヤ骇绾夸笅鏈缃彮缁勶紝鏃犳硶鎺掍骇锛�");
+        }
         Factory factory = factoryService.getById(request.getFactoryId());
         Map<String, Shift> shiftNameMap = new HashMap<>();
         List<Shift> shifts = shiftService.list(new LambdaQueryWrapper<Shift>()
@@ -90,6 +101,16 @@
                 .limit(ChronoUnit.DAYS.between(startDate, endDate) + 1)
                 .collect(Collectors.toList());
         List<MesProductionWorkOrder> newProductionWorkOrderList = CollectionUtil.newArrayList();
+        String materialNumber = request.getMaterialNumber();
+        BigDecimal planQuantity = request.getPlanQuantity();
+        if (StringUtils.isNotBlank(materialNumber)) {
+            LswMaterial material = lswMaterialService.list(new LambdaQueryWrapper<LswMaterial>()
+                            .eq(LswMaterial::getMaterialNumber, materialNumber)
+                            .eq(LswMaterial::getDelFlag, CommonConstant.DEL_FLAG_0)
+                            .eq(LswMaterial::getMaterialStatus, CommonConstant.STATUS_1))
+                    .stream().findFirst().orElse(null);
+            request.setMaterialName(Objects.requireNonNull(material).getMaterialName());
+        }
 
         for (LocalDate date : dateRange) {
             for (String shiftId : shiftGroupMap.keySet()) {
@@ -112,7 +133,10 @@
                             .setShiftName(shiftNameMap.get(shiftId).getShiftName())
                             .setGroupId(shiftGroup.getId())
                             .setGroupName(shiftGroup.getGroupName())
-                            .setWorkOrderDate(workOrderDate);
+                            .setWorkOrderDate(workOrderDate)
+                            .setMaterialNumber(StringUtils.isNotBlank(materialNumber) ? materialNumber : "")
+                            .setMaterialName(StringUtils.isNotBlank(materialNumber) ? request.getMaterialName() : "")
+                            .setPlanQuantity(Objects.nonNull(planQuantity) ? planQuantity : null);
 
                     newProductionWorkOrderList.add(mesProductionWorkOrder);
                 }
@@ -123,7 +147,10 @@
             MesProductionWorkOrder mesProductionWorkOrder = new MesProductionWorkOrder()
                     .setFactoryId(factory.getId())
                     .setFactoryCode(factory.getFactoryCode())
-                    .setFactoryName(factory.getFactoryName());
+                    .setFactoryName(factory.getFactoryName())
+                    .setMaterialNumber(StringUtils.isNotBlank(materialNumber) ? materialNumber : "")
+                    .setMaterialName(StringUtils.isNotBlank(materialNumber) ? request.getMaterialName() : "")
+                    .setPlanQuantity(Objects.nonNull(planQuantity) ? planQuantity : null);;
             newProductionWorkOrderList.add(mesProductionWorkOrder);
         }
         return newProductionWorkOrderList;
@@ -132,10 +159,28 @@
     @Override
     public IPage<MesProductionWorkOrder> queryPageList(Page<MesProductionWorkOrder> page, Map<String, String[]> parameterMap) {
         QueryWrapper<MesProductionWorkOrder> queryWrapper = Wrappers.query();
+
+        LoginUser loginUser = CommonUtils.getCurrentUser();
+        if (loginUser == null) {
+            return page;
+        }
+        queryWrapper.exists("select 1 from base_user_factory t where t.user_id = {0} and t.factory_id = t1.factory_id", loginUser.getId());
         String[] factoryIds = parameterMap.get("factoryId");
         if (factoryIds != null && factoryIds.length > 0) {
             queryWrapper.eq("t1.factory_id", factoryIds[0]);
         }
+        String[] materialNumbers = parameterMap.get("materialNumber");
+        if (materialNumbers != null && materialNumbers.length > 0) {
+            queryWrapper.like("t1.material_number", materialNumbers[0]);
+        }
+        String[] materialNames = parameterMap.get("materialName");
+        if (materialNames != null && materialNames.length > 0) {
+            queryWrapper.like("t1.material_name", materialNames[0]);
+        }
+        String[] workOrderCodes = parameterMap.get("workOrderCode");
+        if (workOrderCodes != null && workOrderCodes.length > 0) {
+            queryWrapper.like("t1.work_order_code", workOrderCodes[0]);
+        }
         String[] startDates = parameterMap.get("startDate");
         String[] endDates = parameterMap.get("endDate");
         if (startDates != null && startDates.length > 0) {

--
Gitblit v1.9.3