From fa64fe3454a2c9f9fea075d0b77454cb2785496b Mon Sep 17 00:00:00 2001
From: cuilei <ray_tsu1@163.com>
Date: 星期五, 22 八月 2025 10:45:48 +0800
Subject: [PATCH] 排产工单列表接口调整

---
 src/main/java/org/jeecg/modules/mes/service/impl/MesProductionWorkOrderServiceImpl.java |  113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 112 insertions(+), 1 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 407a954..e871cce 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
@@ -8,20 +8,37 @@
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 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;
 import org.jeecg.modules.base.entity.ShiftGroup;
 import org.jeecg.modules.base.service.IFactoryService;
+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.LswMaterialInventory;
+import org.jeecg.modules.lsw.service.ILswMaterialInventoryService;
+import org.jeecg.modules.lsw.vo.LswMaterialInventoryVo;
 import org.jeecg.modules.mes.dto.MesProductionWorkScheduleRequest;
+import org.jeecg.modules.mes.entity.MesKittingCompletenessCheck;
+import org.jeecg.modules.mes.entity.MesProductionOrder;
+import org.jeecg.modules.mes.enums.ProductionOrderStatus;
+import org.jeecg.modules.mes.service.IMesProductionOrderService;
 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.system.service.ISysDictService;
+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;
+import org.jeecg.modules.pms.service.IPmsProcessBillMaterialsService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.time.LocalDate;
 import java.time.ZoneId;
 import java.time.temporal.ChronoUnit;
@@ -43,6 +60,16 @@
     private IShiftGroupService shiftGroupService;
     @Autowired
     private IFactoryService factoryService;
+    @Autowired
+    private IMesProductionOrderService mesProductionOrderService;
+    @Autowired
+    private IPmsProcessBillMaterialsService pmsProcessBillMaterialsService;
+    @Autowired
+    private IPmsProcessBillMaterialsDetailService pmsProcessBillMaterialsDetailService;
+    @Autowired
+    private ILswMaterialInventoryService lswMaterialInventoryService;
+    @Autowired
+    private ILineSideWarehouseService lineSideWarehouseService;
 
     @Override
     public List<MesProductionWorkOrder> schedule(MesProductionWorkScheduleRequest request) {
@@ -52,6 +79,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>()
@@ -107,9 +137,27 @@
     @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");
@@ -127,4 +175,67 @@
         queryWrapper.orderByAsc("t1.work_order_date");
         return this.baseMapper.queryPageList(page, queryWrapper);
     }
+
+    @Override
+    public List<MesKittingCompletenessCheck> workOrderCompletenessCheck(MesProductionWorkOrder workOrder) {
+        //鏍规嵁褰撳墠鎺掍骇宸ュ崟纭畾鐢熶骇璁㈠崟
+        List<MesProductionOrder> orderList = mesProductionOrderService.list(new LambdaQueryWrapper<MesProductionOrder>()
+                .eq(MesProductionOrder::getMaterialNumber, workOrder.getMaterialNumber())
+                .eq(MesProductionOrder::getOrderStatus, ProductionOrderStatus.REL.name())
+                .eq(MesProductionOrder::getDelFlag, CommonConstant.DEL_FLAG_0)
+                .orderByAsc(MesProductionOrder::getPlanStart));
+        if (orderList.isEmpty()) {
+            throw new JeecgBootException("鏈壘鍒拌鐗╂枡鐨勫叧鑱旂敓浜ц鍗曪紒");
+        }
+        //榛樿鍙栨椂闂存渶鏃╂湭瀹屾垚鐨勮鍗曪紝涔熷氨鏄涓�椤�
+        MesProductionOrder order = orderList.get(0);
+        //鏍规嵁鐢熶骇璁㈠崟id鍜岀墿鏂欑紪鐮佹煡璇㈣鍗旴OM
+        PmsProcessBillMaterials processBillMaterials = pmsProcessBillMaterialsService.list(new LambdaQueryWrapper<PmsProcessBillMaterials>()
+                        .eq(PmsProcessBillMaterials::getOrderId, order.getId())
+                        .eq(PmsProcessBillMaterials::getMaterialNumber, workOrder.getMaterialNumber()))
+                .stream().findFirst().orElse(null);
+        if (processBillMaterials == null) {
+            throw new JeecgBootException("鏈壘鍒颁笌璇ョ墿鏂欏叧鑱旂殑璁㈠崟BOM锛�");
+        }
+        //鏌ヨ宸ュ崟鎵�灞炰骇绾垮搴旂殑绾胯竟浠�
+        LineSideWarehouse lineSideWarehouse = lineSideWarehouseService.list(new LambdaQueryWrapper<LineSideWarehouse>()
+                        .eq(LineSideWarehouse::getFactoryId, workOrder.getFactoryId())
+                        .eq(LineSideWarehouse::getDelFlag, CommonConstant.DEL_FLAG_0)
+                        .eq(LineSideWarehouse::getWarehouseStatus, CommonConstant.DEFAULT_1))
+                .stream().findFirst().orElse(null);
+        if (lineSideWarehouse == null) {
+            throw new JeecgBootException("璇ヤ骇绾挎湭閰嶇疆绾胯竟浠擄紒");
+        }
+        //璁㈠崟BOM鏄庣粏
+        List<PmsProcessBillMaterialsDetail> processBillMaterialsDetails = pmsProcessBillMaterialsDetailService.queryByMaterialId(processBillMaterials.getId());
+        //鏌ヨ璁㈠崟BOM鏄庣粏涓殑鐗╂枡鍦ㄨ浜х嚎绾胯竟浠撲腑鐨勫簱瀛�
+        List<String> bomMaterialNumberList = processBillMaterialsDetails.stream()
+                .map(PmsProcessBillMaterialsDetail::getMaterialNumber).collect(Collectors.toList());
+        Map<String, LswMaterialInventoryVo> lswMaterialInventoryMap = lswMaterialInventoryService
+                .selectLineSideMaterialInventoryByMaterialNumber(bomMaterialNumberList, lineSideWarehouse.getId()).stream()
+                .collect(Collectors.toMap(LswMaterialInventoryVo::getMaterialNumber, v1 -> v1, (v1, v2) -> v1));
+        List<MesKittingCompletenessCheck> completenessCheckResultList = CollectionUtil.newArrayList();
+        //鏍规嵁璁㈠崟BOM鏄庣粏鍒楀嚭榻愬妫�鏌ョ粨鏋�
+        for (PmsProcessBillMaterialsDetail processBillMaterialsDetail : processBillMaterialsDetails) {
+            LswMaterialInventoryVo materialInventoryVo = lswMaterialInventoryMap.get(processBillMaterialsDetail.getMaterialNumber());
+            MesKittingCompletenessCheck completenessCheckItem = new MesKittingCompletenessCheck()
+                    .setMaterialNumber(processBillMaterialsDetail.getMaterialNumber())
+                    .setMaterialName(processBillMaterialsDetail.getMaterialName())
+                    //闇�姹傛暟閲� = (bom鏄庣粏鐨勯渶姹傛暟閲� / bom璁㈠崟鐨勬暟閲�) * 鎺掍骇宸ュ崟璁″垝鐢熶骇鏁伴噺
+                    .setRequiredQuantity(processBillMaterialsDetail.getUsageQuantity()
+                            .divide(processBillMaterials.getProductionQuantity(), 2, RoundingMode.HALF_UP)
+                            .multiply(workOrder.getPlanQuantity()))
+                    .setActualQuantity(materialInventoryVo == null ? BigDecimal.ZERO : materialInventoryVo.getStockQuantity())
+                    .setProductionUnit(processBillMaterialsDetail.getProductionUnit());
+            completenessCheckResultList.add(completenessCheckItem);
+        }
+        completenessCheckResultList.forEach(item -> {
+            if (item.getRequiredQuantity().compareTo(item.getActualQuantity()) > 0) {
+                item.setCheckFlag(CommonConstant.DEFAULT_0);
+            } else {
+                item.setCheckFlag(CommonConstant.DEFAULT_1);
+            }
+        });
+        return completenessCheckResultList;
+    }
 }

--
Gitblit v1.9.3