lumaojun 3 hete
szülő
commit
f48a34ccd7

+ 30 - 0
easydo-mes/src/main/java/easydo/technology/controller/ProductPlanController.java

@@ -2,6 +2,7 @@ package easydo.technology.controller;
 
 import easydo.technology.model.ProductPlan;
 import easydo.technology.service.ProductPlanService;
+import easydo.technology.utils.SecurityUtils;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -23,5 +24,34 @@ public class ProductPlanController {
         Map<String, Object> result = productPlanService.getPage(map);
         return new ResponseEntity<>(result, HttpStatus.OK);
     }
+
+    @RequestMapping(value = "/save")
+    public Object save(@RequestBody ProductPlan model) throws Exception {
+        // 校验用户登录状态
+        Long userId = SecurityUtils.getCurrentUserId();
+        if (userId == null) {
+            return new ResponseEntity<>("用户请先登录", HttpStatus.UNAUTHORIZED);
+        }
+        
+        model.setCreateId(userId);
+        return new ResponseEntity<>(productPlanService.save(model), HttpStatus.OK);
+    }
+
+    @RequestMapping(value = "/update")
+    public Object update(@RequestBody ProductPlan model) throws Exception {
+        // 校验用户登录状态
+        Long userId = SecurityUtils.getCurrentUserId();
+        if (userId == null) {
+            return new ResponseEntity<>("用户请先登录", HttpStatus.UNAUTHORIZED);
+        }
+        
+        model.setUpdateId(userId);
+        return new ResponseEntity<>(productPlanService.update(model), HttpStatus.OK);
+    }
+
+    @RequestMapping(value = "/remove")
+    public Object remove(@RequestBody ProductPlan model) throws Exception {
+        return new ResponseEntity<>(productPlanService.remove(model), HttpStatus.OK);
+    }
 }
 

+ 5 - 0
easydo-mes/src/main/java/easydo/technology/enums/MESEnum.java

@@ -96,6 +96,11 @@ public enum MESEnum {
     PURCHASE_ORDER_OF_CATEGORY_SPORADIC("sporadic", "零星采购"),
     PURCHASE_ORDER_OF_CATEGORY_BULK("bulk", "大量采购"),
     PURCHASE_ORDER_OF_CATEGORY_INTERNAL("internal", "集团内部采购"),
+
+    PLAN_PRIORITY_URGENT("urgent", "紧急"),
+    PLAN_PRIORITY_HIGH("high", "高"),
+    PLAN_PRIORITY_MEDIUM("medium", "中"),
+    PLAN_PRIORITY_LOW("low", "低"),
     ;
 
     MESEnum(String value, String comment) {

+ 1 - 0
easydo-mes/src/main/java/easydo/technology/model/OutsourcingPlan.java

@@ -24,6 +24,7 @@ public class OutsourcingPlan extends CommonModel {
     private String beginDate;
     private String endDate;
     private String type;
+    private String priority;
 
     // 非数据库字段
     @NotTableField

+ 4 - 0
easydo-mes/src/main/java/easydo/technology/model/ProductBom.java

@@ -29,6 +29,10 @@ public class ProductBom extends CommonModel{
     @NotTableField
     private String routeName;
     @NotTableField
+    private String inspectProgramId;
+    @NotTableField
+    private String inspectProgramName;
+    @NotTableField
     private ProductMaterial material;
     @NotTableField
     private List<WarehouseMaterial> warehouseMaterialList;

+ 1 - 0
easydo-mes/src/main/java/easydo/technology/model/ProductPlan.java

@@ -22,6 +22,7 @@ public class ProductPlan extends CommonModel {
     private String tenantId;
     private Long updateId;
     private String updateTime;
+    private String priority;
 
     @NotTableField
     private SaleOrder saleOrder;

+ 2 - 6
easydo-mes/src/main/java/easydo/technology/model/PurchaseOrder.java

@@ -40,15 +40,11 @@ public class PurchaseOrder extends CommonModel {
 
     // 非数据库字段,用于级联组装
     @NotTableField
-    private List<String> emptyField;
-    @NotTableField
-    private List<MinioFile> fileList;
-    @NotTableField
     private List<PurchaseOrderDetail> childrenList;
     @NotTableField
     private SaleOrder saleOrder;
-    // @NotTableField
-    // private Customer customer;
+    @NotTableField
+    private Customer customer;
     @NotTableField
     private PurchasePlan purchasePlan;
     @NotTableField

+ 8 - 0
easydo-mes/src/main/java/easydo/technology/service/ProductPlanService.java

@@ -1,8 +1,16 @@
 package easydo.technology.service;
 
+import easydo.technology.model.ProductPlan;
+
 import java.util.Map;
 
 public interface ProductPlanService {
     Map<String, Object> getPage(Map<String, Object> map) throws Exception;
+    
+    ProductPlan save(ProductPlan model) throws Exception;
+    
+    ProductPlan update(ProductPlan model) throws Exception;
+    
+    ProductPlan remove(ProductPlan model) throws Exception;
 }
 

+ 13 - 0
easydo-mes/src/main/java/easydo/technology/service/impl/ProductBomServiceImpl.java

@@ -6,6 +6,7 @@ import easydo.technology.exception.BizException;
 import easydo.technology.model.ProcessRoute;
 import easydo.technology.model.ProductBom;
 import easydo.technology.model.ProductMaterial;
+import easydo.technology.model.QualityInspectProgram;
 import easydo.technology.service.FlowNoService;
 import easydo.technology.service.ProductBomService;
 import easydo.technology.utils.SecurityUtils;
@@ -83,6 +84,18 @@ public class ProductBomServiceImpl implements ProductBomService {
             route = jdbcClient.getJdbcModelById(route, connection);
             if (route != null) {
                 model.setRouteName(route.getName());
+                
+                // 4. Backfill InspectProgramId and InspectProgramName from ProcessRoute
+                if (StringUtil.isNotEmpty(route.getInspectProgramId())) {
+                    model.setInspectProgramId(route.getInspectProgramId());
+                    
+                    QualityInspectProgram inspectProgram = new QualityInspectProgram();
+                    inspectProgram.setId(route.getInspectProgramId());
+                    inspectProgram = jdbcClient.getJdbcModelById(inspectProgram, connection);
+                    if (inspectProgram != null) {
+                        model.setInspectProgramName(inspectProgram.getName());
+                    }
+                }
             }
         }
     }

+ 197 - 2
easydo-mes/src/main/java/easydo/technology/service/impl/ProductPlanServiceImpl.java

@@ -1,8 +1,10 @@
 package easydo.technology.service.impl;
 
 import easydo.technology.components.JdbcClient;
+import easydo.technology.enums.MESEnum;
 import easydo.technology.exception.BizException;
 import easydo.technology.model.*;
+import easydo.technology.service.FlowNoService;
 import easydo.technology.service.ProductPlanService;
 import easydo.technology.system.model.SysUser;
 import org.springframework.stereotype.Service;
@@ -20,6 +22,8 @@ public class ProductPlanServiceImpl implements ProductPlanService {
     private JdbcClient jdbcClient;
     @Resource
     private DataSource dataSource;
+    @Resource
+    private FlowNoService flowNoService;
 
     @Override
     @SuppressWarnings("unchecked")
@@ -90,7 +94,16 @@ public class ProductPlanServiceImpl implements ProductPlanService {
                         if (planBom.getBomId() != null) {
                             ProductBom productBomParam = new ProductBom();
                             productBomParam.setId(planBom.getBomId());
-                            planBom.setProductBom(jdbcClient.getJdbcModelById(productBomParam, connection));
+                            ProductBom productBom = jdbcClient.getJdbcModelById(productBomParam, connection);
+                            
+                            // 4.3.1) 查询 ProductBom 的物料信息(ProductMaterial)
+                            if (productBom != null && productBom.getMaterialCode() != null) {
+                                ProductMaterial materialParam = new ProductMaterial();
+                                materialParam.setCode(productBom.getMaterialCode());
+                                productBom.setMaterial(jdbcClient.getJdbcModel(materialParam, connection));
+                            }
+                            
+                            planBom.setProductBom(productBom);
                         }
                     }
                 }
@@ -134,5 +147,187 @@ public class ProductPlanServiceImpl implements ProductPlanService {
             connection.close();
         }
     }
-}
 
+    @Override
+    public ProductPlan save(ProductPlan model) throws Exception {
+        Connection connection = dataSource.getConnection();
+        connection.setAutoCommit(false);
+        try {
+            // 1) 生成编码(支持手填校验 + 自动生成)
+            String code = flowNoService.generateProductPlanCode(model, connection);
+            model.setCode(code);
+
+            // 2) 设置初始状态为 pending
+            model.setStatus(MESEnum.PRODUCT_PLAN_OF_STATUS_PENDING.getValue());
+
+            // 3) 插入主表(会自动保存附件 fileList)
+            jdbcClient.jdbcInsert(model, connection);
+
+            // 4) 插入 BOM 列表
+            List<ProductPlanBom> bomList = model.getBomList();
+            if (bomList != null) {
+                for (ProductPlanBom bom : bomList) {
+                    bom.setPlanId(model.getId());
+
+                    // 根据 bomId 查询 product_bom 表获取工艺路线ID
+                    if (bom.getBomId() != null) {
+                        ProductBom productBomParam = new ProductBom();
+                        productBomParam.setId(bom.getBomId());
+                        ProductBom productBom = jdbcClient.getJdbcModelById(productBomParam, connection);
+                        if (productBom != null && productBom.getRouteId() != null) {
+                            bom.setRouteId(productBom.getRouteId());
+
+                            // 根据工艺路线ID查询工艺路线表获取质检方案ID
+                            ProcessRoute processRouteParam = new ProcessRoute();
+                            processRouteParam.setId(productBom.getRouteId());
+                            ProcessRoute processRoute = jdbcClient.getJdbcModelById(processRouteParam, connection);
+                            if (processRoute != null && processRoute.getInspectProgramId() != null) {
+                                bom.setInspectProgramId(processRoute.getInspectProgramId());
+                            }
+                        }
+                    }
+
+                    jdbcClient.jdbcInsert(bom, connection);
+                }
+            }
+
+            // 5) 插入设备列表
+            List<ProductPlanDevice> deviceList = model.getDeviceList();
+            if (deviceList != null) {
+                for (ProductPlanDevice device : deviceList) {
+                    device.setPlanId(model.getId());
+                    jdbcClient.jdbcInsert(device, connection);
+                }
+            }
+
+            // 6) 插入人员列表
+            List<ProductPlanUser> userList = model.getUserList();
+            if (userList != null) {
+                for (ProductPlanUser user : userList) {
+                    user.setPlanId(model.getId());
+                    jdbcClient.jdbcInsert(user, connection);
+                }
+            }
+
+            connection.commit();
+            return model;
+        } catch (Exception e) {
+            connection.rollback();
+            throw new BizException(e.getMessage());
+        } finally {
+            connection.close();
+        }
+    }
+
+    @Override
+    public ProductPlan update(ProductPlan model) throws Exception {
+        Connection connection = dataSource.getConnection();
+        connection.setAutoCommit(false);
+        try {
+            // 1) 更新主表(会自动保存附件 fileList)
+            jdbcClient.jdbcUpdateById(model, connection);
+
+            // 2) 删除旧 BOM 列表
+            ProductPlanBom bomRemoveParam = new ProductPlanBom();
+            bomRemoveParam.setPlanId(model.getId());
+            jdbcClient.jdbcRemove(bomRemoveParam, connection);
+
+            // 3) 插入新 BOM 列表
+            List<ProductPlanBom> bomList = model.getBomList();
+            if (bomList != null) {
+                for (ProductPlanBom bom : bomList) {
+                    bom.setPlanId(model.getId());
+
+                    // 根据 bomId 查询 product_bom 表获取工艺路线ID
+                    if (bom.getBomId() != null) {
+                        ProductBom productBomParam = new ProductBom();
+                        productBomParam.setId(bom.getBomId());
+                        ProductBom productBom = jdbcClient.getJdbcModelById(productBomParam, connection);
+                        if (productBom != null && productBom.getRouteId() != null) {
+                            bom.setRouteId(productBom.getRouteId());
+
+                            // 根据工艺路线ID查询工艺路线表获取质检方案ID
+                            ProcessRoute processRouteParam = new ProcessRoute();
+                            processRouteParam.setId(productBom.getRouteId());
+                            ProcessRoute processRoute = jdbcClient.getJdbcModelById(processRouteParam, connection);
+                            if (processRoute != null && processRoute.getInspectProgramId() != null) {
+                                bom.setInspectProgramId(processRoute.getInspectProgramId());
+                            }
+                        }
+                    }
+                    
+                    jdbcClient.jdbcInsert(bom, connection);
+                }
+            }
+
+            // 4) 删除旧设备列表
+            ProductPlanDevice deviceRemoveParam = new ProductPlanDevice();
+            deviceRemoveParam.setPlanId(model.getId());
+            jdbcClient.jdbcRemove(deviceRemoveParam, connection);
+
+            // 5) 插入新设备列表
+            List<ProductPlanDevice> deviceList = model.getDeviceList();
+            if (deviceList != null) {
+                for (ProductPlanDevice device : deviceList) {
+                    device.setPlanId(model.getId());
+                    jdbcClient.jdbcInsert(device, connection);
+                }
+            }
+
+            // 6) 删除旧人员列表
+            ProductPlanUser userRemoveParam = new ProductPlanUser();
+            userRemoveParam.setPlanId(model.getId());
+            jdbcClient.jdbcRemove(userRemoveParam, connection);
+
+            // 7) 插入新人员列表
+            List<ProductPlanUser> userList = model.getUserList();
+            if (userList != null) {
+                for (ProductPlanUser user : userList) {
+                    user.setPlanId(model.getId());
+                    jdbcClient.jdbcInsert(user, connection);
+                }
+            }
+
+            connection.commit();
+            return model;
+        } catch (Exception e) {
+            connection.rollback();
+            throw new BizException(e.getMessage());
+        } finally {
+            connection.close();
+        }
+    }
+
+    @Override
+    public ProductPlan remove(ProductPlan model) throws Exception {
+        Connection connection = dataSource.getConnection();
+        connection.setAutoCommit(false);
+        try {
+            // 1) 删除主表(JdbcClient 会自动删除附件)
+            jdbcClient.jdbcRemoveById(model, connection);
+
+            // 2) 删除 BOM 列表
+            ProductPlanBom bomRemoveParam = new ProductPlanBom();
+            bomRemoveParam.setPlanId(model.getId());
+            jdbcClient.jdbcRemove(bomRemoveParam, connection);
+
+            // 3) 删除设备列表
+            ProductPlanDevice deviceRemoveParam = new ProductPlanDevice();
+            deviceRemoveParam.setPlanId(model.getId());
+            jdbcClient.jdbcRemove(deviceRemoveParam, connection);
+
+            // 4) 删除人员列表
+            ProductPlanUser userRemoveParam = new ProductPlanUser();
+            userRemoveParam.setPlanId(model.getId());
+            jdbcClient.jdbcRemove(userRemoveParam, connection);
+
+            connection.commit();
+            return model;
+        } catch (Exception e) {
+            connection.rollback();
+            throw new BizException(e.getMessage());
+        } finally {
+            connection.close();
+        }
+    }
+}