Forráskód Böngészése

feat:工艺管理

lumaojun 1 hónapja
szülő
commit
daf5c1f4b2

+ 17 - 219
easydo-mes/src/main/java/easydo/technology/controller/ProcessRouteController.java

@@ -1,14 +1,7 @@
 package easydo.technology.controller;
 
-import easydo.technology.components.JdbcClient;
-import easydo.technology.enums.MESEnum;
-import easydo.technology.exception.BizException;
 import easydo.technology.model.ProcessRoute;
-import easydo.technology.model.ProcessRouteDetail;
-import easydo.technology.model.ProcessStage;
-import easydo.technology.service.FlowNoService;
-import easydo.technology.utils.SecurityUtils;
-import easydo.technology.utils.StringUtil;
+import easydo.technology.service.ProcessRouteService;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -16,249 +9,54 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
-import javax.sql.DataSource;
-import java.sql.Connection;
-import java.util.*;
-import java.util.stream.Collectors;
+import java.util.Map;
 
 @RestController
 @RequestMapping("/processRoute")
 public class ProcessRouteController {
+
     @Resource
-    JdbcClient jdbcClient;
-    @Resource
-    DataSource dataSource;
-    @Resource
-    FlowNoService flowNoService;
+    ProcessRouteService processRouteService;
 
     @RequestMapping(value = "/getList")
     public Object getList(@RequestBody Map<String, Object> map) throws Exception {
-        List<ProcessRoute> list = jdbcClient.getJdbcList(map, ProcessRoute.class);
+        Object list = processRouteService.getList(map);
         return new ResponseEntity<>(list, HttpStatus.OK);
     }
 
     @RequestMapping(value = "/getPage")
     public Object getPage(@RequestBody Map<String, Object> map) throws Exception {
-        Connection connection = dataSource.getConnection();
-        try {
-            Map<String, Object> recordsPage = jdbcClient.getJdbcPage(map, ProcessRoute.class, connection);
-            List<ProcessRoute> records = (List<ProcessRoute>) recordsPage.get("records");
-            for (ProcessRoute model : records) {
-                ProcessRouteDetail routeDetail = new ProcessRouteDetail();
-                routeDetail.setRouteId(model.getId());
-                List<ProcessRouteDetail> routeDetailList = jdbcClient.getJdbcList(routeDetail, connection);
-                for (ProcessRouteDetail detail : routeDetailList) {
-                    ProcessStage stage = new ProcessStage();
-                    stage.setId(detail.getStageId());
-                    stage = jdbcClient.getJdbcModelById(stage, connection);
-                    detail.setStage(stage);
-                }
-                model.setDetailList(routeDetailList);
-
-                jdbcClient.getMinioFile(model, connection);
-
-                ProcessRoute child = new ProcessRoute();
-                child.setParentId(model.getId());
-                int count = jdbcClient.getJdbcCount(child, connection);
-                if (count > 0) {
-                    model.setIsHaveHistory(true);
-                } else {
-                    model.setIsHaveHistory(false);
-                }
-            }
-            return new ResponseEntity<>(recordsPage, HttpStatus.OK);
-        } catch (Exception e) {
-            throw new BizException(e.getMessage());
-        } finally {
-            connection.close();
-        }
+        Object page = processRouteService.getPage(map);
+        return new ResponseEntity<>(page, HttpStatus.OK);
     }
 
-
     @RequestMapping(value = "/save")
     public Object save(@RequestBody ProcessRoute model) throws Exception {
-        Connection connection = dataSource.getConnection();
-        try {
-            connection.setAutoCommit(false);
-            model.setCreateId(SecurityUtils.getCurrentUserId());
-            model.setCode(flowNoService.generateProcessRouteCode(model, connection));
-            model.setParentId("0");
-            model.setStatus(MESEnum.PROCESS_OF_STATUS_ENABLE.getValue());
-            jdbcClient.jdbcInsert(model, connection);
-
-            List<ProcessRouteDetail> detailList = model.getDetailList();
-            for (ProcessRouteDetail detail : detailList) {
-                detail.setRouteId(model.getId());
-                jdbcClient.jdbcInsert(detail, connection);
-            }
-            connection.commit();
-            return new ResponseEntity<>(model, HttpStatus.OK);
-        } catch (Exception e) {
-            connection.rollback();
-            throw new BizException(e.getMessage());
-        } finally {
-            connection.close();
-        }
+        Object result = processRouteService.save(model);
+        return new ResponseEntity<>(result, HttpStatus.OK);
     }
 
     @RequestMapping(value = "/update")
     public Object update(@RequestBody ProcessRoute model) throws Exception {
-        Connection connection = dataSource.getConnection();
-        try {
-            connection.setAutoCommit(false);
-            jdbcClient.jdbcUpdateById(model, connection);
-
-            List<ProcessRouteDetail> detailList = model.getDetailList();
-            if (null != detailList && !detailList.isEmpty()) {
-                ProcessRouteDetail routeDetail = new ProcessRouteDetail();
-                routeDetail.setRouteId(model.getId());
-                jdbcClient.jdbcRemove(routeDetail, connection);
-
-                for (ProcessRouteDetail detail : detailList) {
-                    detail.setRouteId(model.getId());
-                    jdbcClient.jdbcInsert(detail, connection);
-                }
-            }
-            connection.commit();
-            return new ResponseEntity<>(model, HttpStatus.OK);
-        } catch (Exception e) {
-            connection.rollback();
-            throw new BizException(e.getMessage());
-        } finally {
-            connection.close();
-        }
+        Object result = processRouteService.update(model);
+        return new ResponseEntity<>(result, HttpStatus.OK);
     }
 
     @RequestMapping(value = "/remove")
     public Object remove(@RequestBody ProcessRoute model) throws Exception {
-        Connection connection = dataSource.getConnection();
-        try {
-            connection.setAutoCommit(false);
-            jdbcClient.jdbcRemoveById(model, connection);
-
-            ProcessRouteDetail routeDetail = new ProcessRouteDetail();
-            routeDetail.setRouteId(model.getId());
-            jdbcClient.jdbcRemove(routeDetail, connection);
-
-            ProcessRoute history = new ProcessRoute();
-            history.setParentId(model.getId());
-            List<ProcessRoute> historyList = jdbcClient.getJdbcList(history, connection);
-            for (ProcessRoute hismodel : historyList) {
-                jdbcClient.jdbcRemoveById(hismodel, connection);
-
-                ProcessRouteDetail routeHisDetail = new ProcessRouteDetail();
-                routeHisDetail.setRouteId(hismodel.getId());
-                jdbcClient.jdbcRemove(routeHisDetail, connection);
-            }
-
-            connection.commit();
-            return new ResponseEntity<>(model, HttpStatus.OK);
-        } catch (Exception e) {
-            connection.rollback();
-            throw new BizException(e.getMessage());
-        } finally {
-            connection.close();
-        }
+        Object result = processRouteService.remove(model);
+        return new ResponseEntity<>(result, HttpStatus.OK);
     }
 
     @RequestMapping(value = "/upgrade")
     public Object upgrade(@RequestBody ProcessRoute model) throws Exception {
-        Connection connection = dataSource.getConnection();
-        try {
-            connection.setAutoCommit(false);
-            String newId = UUID.randomUUID().toString();
-
-            ProcessRoute existRoute = new ProcessRoute();
-            existRoute.setId(model.getId());
-            existRoute.setParentId(newId);
-            existRoute.setStatus(MESEnum.PROCESS_OF_STATUS_DISABLE.getValue());
-            jdbcClient.jdbcUpdateById(existRoute, connection);
-
-            ProcessRoute childrenRoute = new ProcessRoute();
-            childrenRoute.setParentId(newId);
-            Map<String, Object> paramMap = new HashMap<>();
-            paramMap.put("parentId", model.getId());
-            jdbcClient.jdbcUpdate(childrenRoute, paramMap, connection);
-
-            model.setCreateId(SecurityUtils.getCurrentUserId());
-            model.setCode(flowNoService.generateProcessRouteCode(model, connection));
-            model.setParentId("0");
-            model.setId(newId);
-            model.setStatus(MESEnum.PROCESS_OF_STATUS_ENABLE.getValue());
-            jdbcClient.jdbcInsert(model, connection);
-
-            List<ProcessRouteDetail> detailList = model.getDetailList();
-            for (ProcessRouteDetail detail : detailList) {
-                detail.setRouteId(model.getId());
-                jdbcClient.jdbcInsert(detail, connection);
-            }
-            connection.commit();
-            return new ResponseEntity<>(model, HttpStatus.OK);
-        } catch (Exception e) {
-            connection.rollback();
-            throw new BizException(e.getMessage());
-        } finally {
-            connection.close();
-        }
+        Object result = processRouteService.upgrade(model);
+        return new ResponseEntity<>(result, HttpStatus.OK);
     }
 
     @RequestMapping(value = "/regrade")
     public Object regrade(@RequestBody ProcessRoute model) throws Exception {
-        Connection connection = dataSource.getConnection();
-        try {
-            connection.setAutoCommit(false);
-            ProcessRoute children = new ProcessRoute();
-            children.setParentId(model.getId());
-            List<ProcessRoute> childrenList = jdbcClient.getJdbcList(children, connection);
-            if (!childrenList.isEmpty()) {
-                childrenList = childrenList.stream().sorted(Comparator.comparing(ProcessRoute::getCreateTime).reversed()).collect(Collectors.toList());
-                ProcessRoute child = childrenList.get(0);
-                child.setParentId("0");
-                child.setStatus(MESEnum.PROCESS_OF_STATUS_ENABLE.getValue());
-                jdbcClient.jdbcUpdateById(child, connection);
-
-                ProcessRoute childrenRoute = new ProcessRoute();
-                childrenRoute.setParentId(child.getId());
-                Map<String, Object> paramMap = new HashMap<>();
-                paramMap.put("parentId", model.getId());
-                jdbcClient.jdbcUpdate(childrenRoute, paramMap, connection);
-
-                jdbcClient.jdbcRemoveById(model, connection);
-
-                ProcessRouteDetail routeDetail = new ProcessRouteDetail();
-                routeDetail.setRouteId(model.getId());
-                jdbcClient.jdbcRemove(routeDetail, connection);
-            }
-            connection.commit();
-            return new ResponseEntity<>(model, HttpStatus.OK);
-        } catch (Exception e) {
-            connection.rollback();
-            throw new BizException(e.getMessage());
-        } finally {
-            connection.close();
-        }
+        Object result = processRouteService.regrade(model);
+        return new ResponseEntity<>(result, HttpStatus.OK);
     }
-
-    private synchronized void generateCode(ProcessRoute model, Connection connection) throws Exception {
-        if (StringUtil.isEmpty(model.getCode())) {
-            while (true) {
-                String flowNo = flowNoService.getFlowNo(MESEnum.FLOW_NO_TYPE_PROCESS_ROUTE.getValue(), connection);
-                ProcessRoute processRouteParam = new ProcessRoute();
-                processRouteParam.setCode(flowNo);
-                int count = jdbcClient.getJdbcCount(processRouteParam, connection);
-                if (count == 0) {
-                    model.setCode(flowNo);
-                    break;
-                }
-            }
-        } else {
-            ProcessRoute processRouteParam = new ProcessRoute();
-            processRouteParam.setCode(model.getCode());
-            int count = jdbcClient.getJdbcCount(processRouteParam, connection);
-            if (count > 0) {
-                throw new BizException("编号已存在,请重新填写");
-            }
-        }
-    }
-
 }

+ 14 - 71
easydo-mes/src/main/java/easydo/technology/controller/ProcessStageController.java

@@ -1,12 +1,7 @@
 package easydo.technology.controller;
 
-import easydo.technology.components.JdbcClient;
-import easydo.technology.enums.MESEnum;
-import easydo.technology.exception.BizException;
+import easydo.technology.service.ProcessStageService;
 import easydo.technology.model.ProcessStage;
-import easydo.technology.service.FlowNoService;
-import easydo.technology.utils.SecurityUtils;
-import easydo.technology.utils.StringUtil;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -14,96 +9,44 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
-import javax.sql.DataSource;
-import java.sql.Connection;
-import java.util.List;
 import java.util.Map;
 
 @RestController
-@RequestMapping("/processManage")
+@RequestMapping("/processStage")
 public class ProcessStageController {
+
     @Resource
-    JdbcClient jdbcClient;
-    @Resource
-    DataSource dataSource;
-    @Resource
-    FlowNoService flowNoService;
+    ProcessStageService processStageService;
 
     @RequestMapping(value = "/getList")
     public Object getList(@RequestBody Map<String, Object> map) throws Exception {
-        List<ProcessStage> list = jdbcClient.getJdbcList(map, ProcessStage.class);
+        Object list = processStageService.getList(map);
         return new ResponseEntity<>(list, HttpStatus.OK);
     }
 
     @RequestMapping(value = "/getPage")
     public Object getPage(@RequestBody Map<String, Object> map) throws Exception {
-        Connection connection = dataSource.getConnection();
-        try {
-            Map<String, Object> recordsPage = jdbcClient.getJdbcPage(map, ProcessStage.class, connection);
-            List<ProcessStage> records = (List<ProcessStage>) recordsPage.get("records");
-            for (ProcessStage model : records) {
-                jdbcClient.getMinioFile(model, connection);
-            }
-            return new ResponseEntity<>(recordsPage, HttpStatus.OK);
-        } catch (Exception e) {
-            throw new BizException(e.getMessage());
-        } finally {
-            connection.close();
-        }
+        Object page = processStageService.getPage(map);
+        return new ResponseEntity<>(page, HttpStatus.OK);
     }
 
 
     @RequestMapping(value = "/save")
     public Object add(@RequestBody ProcessStage model) throws Exception {
-        Connection connection = dataSource.getConnection();
-        try {
-            connection.setAutoCommit(false);
-            model.setStatus(MESEnum.PROCESS_OF_STATUS_ENABLE.getValue());
-            model.setCreateId(SecurityUtils.getCurrentUserId());
-            model.setCode(flowNoService.generateProcessStageCode(model, connection));
-            jdbcClient.jdbcInsert(model, connection);
-            connection.commit();
-            return new ResponseEntity<>(model, HttpStatus.OK);
-        } catch (Exception e) {
-            connection.rollback();
-            throw new BizException(e.getMessage());
-        } finally {
-            connection.close();
-        }
+        Object result = processStageService.save(model);
+        return new ResponseEntity<>(result, HttpStatus.OK);
     }
 
 
     @RequestMapping(value = "/update")
     public Object update(@RequestBody ProcessStage model) throws Exception {
-        jdbcClient.jdbcUpdateById(model);
-        return new ResponseEntity<>(HttpStatus.OK);
+        Object result = processStageService.update(model);
+        return new ResponseEntity<>(result, HttpStatus.OK);
     }
 
     @RequestMapping(value = "/remove")
-    public Object deleteProgram(@RequestBody ProcessStage model) throws Exception {
-        jdbcClient.jdbcRemoveById(model);
-        return new ResponseEntity<>(HttpStatus.OK);
-    }
-
-    private synchronized void generateCode(ProcessStage model, Connection connection) throws Exception {
-        if (StringUtil.isEmpty(model.getCode())) {
-            while (true) {
-                String flowNo = flowNoService.getFlowNo(MESEnum.FLOW_NO_TYPE_PROCESS_STAGE.getValue(), connection);
-                ProcessStage processStageParam = new ProcessStage();
-                processStageParam.setCode(flowNo);
-                int count = jdbcClient.getJdbcCount(processStageParam, connection);
-                if (count == 0) {
-                    model.setCode(flowNo);
-                    break;
-                }
-            }
-        } else {
-            ProcessStage processStageParam = new ProcessStage();
-            processStageParam.setCode(model.getCode());
-            int count = jdbcClient.getJdbcCount(processStageParam, connection);
-            if (count > 0) {
-                throw new BizException("编号已存在,请重新填写");
-            }
-        }
+    public Object remove(@RequestBody ProcessStage model) throws Exception {
+        Object result = processStageService.remove(model);
+        return new ResponseEntity<>(result, HttpStatus.OK);
     }
 }

+ 3 - 0
easydo-mes/src/main/java/easydo/technology/model/ProcessRoute.java

@@ -18,6 +18,7 @@ public class ProcessRoute extends CommonModel {
     private String timeUnit;
     private String createTime;
     private Long createId;
+    private Long updateId;
     private String status;
     private String remark;
     private String version;
@@ -28,4 +29,6 @@ public class ProcessRoute extends CommonModel {
     private List<ProcessRouteDetail> detailList;
     @NotTableField
     private Boolean isHaveHistory;
+    @NotTableField
+    private QualityInspectProgram inspectProgram;
 }

+ 5 - 1
easydo-mes/src/main/java/easydo/technology/model/ProcessRouteDetail.java

@@ -1,10 +1,10 @@
 package easydo.technology.model;
 
-import easydo.technology.annotation.Minio;
 import easydo.technology.annotation.NotTableField;
 import lombok.Data;
 
 import java.math.BigDecimal;
+import java.util.List;
 
 @Data
 public class ProcessRouteDetail {
@@ -21,7 +21,11 @@ public class ProcessRouteDetail {
     private Boolean isReport;
     private Boolean isRound;
     private String remark;
+    private String deviceList;
 
     @NotTableField
     private ProcessStage stage;
+
+    @NotTableField
+    private List<String> deviceNameList;
 }

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

@@ -20,6 +20,7 @@ public class ProcessStage extends CommonModel {
     private String remark;
     private String createTime;
     private Long createId;
+    private Long updateId;
     private String status;
     private String tenantId;
 }

+ 23 - 0
easydo-mes/src/main/java/easydo/technology/service/ProcessRouteService.java

@@ -0,0 +1,23 @@
+package easydo.technology.service;
+
+import easydo.technology.model.ProcessRoute;
+
+import java.util.Map;
+
+public interface ProcessRouteService {
+
+    Object getList(Map<String, Object> map) throws Exception;
+
+    Object getPage(Map<String, Object> map) throws Exception;
+
+    Object save(ProcessRoute model) throws Exception;
+
+    Object update(ProcessRoute model) throws Exception;
+
+    Object remove(ProcessRoute model) throws Exception;
+
+    Object upgrade(ProcessRoute model) throws Exception;
+
+    Object regrade(ProcessRoute model) throws Exception;
+}
+

+ 19 - 0
easydo-mes/src/main/java/easydo/technology/service/ProcessStageService.java

@@ -0,0 +1,19 @@
+package easydo.technology.service;
+
+import easydo.technology.model.ProcessStage;
+
+import java.util.Map;
+
+public interface ProcessStageService {
+
+    Object getList(Map<String, Object> map) throws Exception;
+
+    Object getPage(Map<String, Object> map) throws Exception;
+
+    Object save(ProcessStage model) throws Exception;
+
+    Object update(ProcessStage model) throws Exception;
+
+    Object remove(ProcessStage model) throws Exception;
+}
+

+ 287 - 0
easydo-mes/src/main/java/easydo/technology/service/impl/ProcessRouteServiceImpl.java

@@ -0,0 +1,287 @@
+package easydo.technology.service.impl;
+
+import easydo.technology.components.JdbcClient;
+import easydo.technology.enums.MESEnum;
+import easydo.technology.model.*;
+import easydo.technology.service.FlowNoService;
+import easydo.technology.service.ProcessRouteService;
+import easydo.technology.utils.SecurityUtils;
+import easydo.technology.utils.StringUtil;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.core.type.TypeReference;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.util.*;
+import java.util.stream.Collectors;
+
+@Service
+public class ProcessRouteServiceImpl implements ProcessRouteService {
+
+    @Resource
+    JdbcClient jdbcClient;
+    @Resource
+    DataSource dataSource;
+    @Resource
+    FlowNoService flowNoService;
+
+    private static final ObjectMapper objectMapper = new ObjectMapper();
+
+    @Override
+    public Object getList(Map<String, Object> map) throws Exception {
+        List<ProcessRoute> list = jdbcClient.getJdbcList(map, ProcessRoute.class);
+        Connection connection = dataSource.getConnection();
+        try {
+            for (ProcessRoute model : list) {
+                fillRouteDetails(model, connection);
+            }
+        } finally {
+            connection.close();
+        }
+        return list;
+    }
+
+    @Override
+    public Object getPage(Map<String, Object> map) throws Exception {
+        Connection connection = dataSource.getConnection();
+        try {
+            Map<String, Object> recordsPage = jdbcClient.getJdbcPage(map, ProcessRoute.class, connection);
+            List<ProcessRoute> records = (List<ProcessRoute>) recordsPage.get("records");
+            for (ProcessRoute model : records) {
+                fillRouteDetails(model, connection);
+            }
+            return recordsPage;
+        } finally {
+            connection.close();
+        }
+    }
+
+    private void fillRouteDetails(ProcessRoute model, Connection connection) throws Exception {
+        // 1. 回填明细与工序
+        ProcessRouteDetail routeDetail = new ProcessRouteDetail();
+        routeDetail.setRouteId(model.getId());
+        List<ProcessRouteDetail> routeDetailList = jdbcClient.getJdbcList(routeDetail, connection);
+        for (ProcessRouteDetail detail : routeDetailList) {
+            ProcessStage stage = new ProcessStage();
+            stage.setId(detail.getStageId());
+            stage = jdbcClient.getJdbcModelById(stage, connection);
+            detail.setStage(stage);
+
+            // 补齐逻辑:解析 device_list 并回显名称数组
+            if (StringUtil.isNotEmpty(detail.getDeviceList())) {
+                try {
+                    List<String> deviceIds = objectMapper.readValue(detail.getDeviceList(), new TypeReference<List<String>>() {});
+                    List<String> deviceNames = new ArrayList<>();
+                    for (String deviceId : deviceIds) {
+                        Device device = new Device();
+                        device.setId(deviceId);
+                        device = jdbcClient.getJdbcModelById(device, connection);
+                        deviceNames.add(device != null ? device.getName() : "未知设备");
+                    }
+                    detail.setDeviceNameList(deviceNames);
+                } catch (Exception e) {
+                    // 忽略解析异常
+                }
+            }
+        }
+        model.setDetailList(routeDetailList);
+
+        // 2. 回填附件
+        jdbcClient.getMinioFile(model, connection);
+
+        // 3. 回填历史标记
+        ProcessRoute child = new ProcessRoute();
+        child.setParentId(model.getId());
+        int count = jdbcClient.getJdbcCount(child, connection);
+        model.setIsHaveHistory(count > 0);
+
+        // 4. 回填检验方案对象
+        if (StringUtil.isNotEmpty(model.getInspectProgramId())) {
+            QualityInspectProgram inspectProgram = new QualityInspectProgram();
+            inspectProgram.setId(model.getInspectProgramId());
+            model.setInspectProgram(jdbcClient.getJdbcModelById(inspectProgram, connection));
+        }
+    }
+
+    @Override
+    public Object save(ProcessRoute model) throws Exception {
+        Connection connection = dataSource.getConnection();
+        try {
+            connection.setAutoCommit(false);
+            model.setCreateId(SecurityUtils.getCurrentUserId());
+            model.setCode(flowNoService.generateProcessRouteCode(model, connection));
+            model.setParentId("0");
+            model.setStatus(MESEnum.PROCESS_OF_STATUS_ENABLE.getValue());
+            jdbcClient.jdbcInsert(model, connection);
+
+            List<ProcessRouteDetail> detailList = model.getDetailList();
+            if (detailList != null) {
+                for (ProcessRouteDetail detail : detailList) {
+                    detail.setRouteId(model.getId());
+                    jdbcClient.jdbcInsert(detail, connection);
+                }
+            }
+            connection.commit();
+            return model;
+        } catch (Exception e) {
+            connection.rollback();
+            throw e;
+        } finally {
+            connection.close();
+        }
+    }
+
+    @Override
+    public Object update(ProcessRoute model) throws Exception {
+        Connection connection = dataSource.getConnection();
+        try {
+            connection.setAutoCommit(false);
+            model.setUpdateId(SecurityUtils.getCurrentUserId());
+            jdbcClient.jdbcUpdateById(model, connection);
+
+            ProcessRouteDetail routeDetail = new ProcessRouteDetail();
+            routeDetail.setRouteId(model.getId());
+            jdbcClient.jdbcRemove(routeDetail, connection);
+
+            List<ProcessRouteDetail> detailList = model.getDetailList();
+            if (detailList != null) {
+                for (ProcessRouteDetail detail : detailList) {
+                    detail.setRouteId(model.getId());
+                    jdbcClient.jdbcInsert(detail, connection);
+                }
+            }
+            connection.commit();
+            return model;
+        } catch (Exception e) {
+            connection.rollback();
+            throw e;
+        } finally {
+            connection.close();
+        }
+    }
+
+    @Override
+    public Object remove(ProcessRoute model) throws Exception {
+        Connection connection = dataSource.getConnection();
+        try {
+            connection.setAutoCommit(false);
+            jdbcClient.jdbcRemoveById(model, connection);
+
+            ProcessRouteDetail routeDetail = new ProcessRouteDetail();
+            routeDetail.setRouteId(model.getId());
+            jdbcClient.jdbcRemove(routeDetail, connection);
+
+            ProcessRoute history = new ProcessRoute();
+            history.setParentId(model.getId());
+            List<ProcessRoute> historyList = jdbcClient.getJdbcList(history, connection);
+            for (ProcessRoute hismodel : historyList) {
+                jdbcClient.jdbcRemoveById(hismodel, connection);
+                ProcessRouteDetail routeHisDetail = new ProcessRouteDetail();
+                routeHisDetail.setRouteId(hismodel.getId());
+                jdbcClient.jdbcRemove(routeHisDetail, connection);
+            }
+
+            connection.commit();
+            return model;
+        } catch (Exception e) {
+            connection.rollback();
+            throw e;
+        } finally {
+            connection.close();
+        }
+    }
+
+    @Override
+    public Object upgrade(ProcessRoute model) throws Exception {
+        Connection connection = dataSource.getConnection();
+        try {
+            connection.setAutoCommit(false);
+            Long userId = SecurityUtils.getCurrentUserId();
+
+            // 对齐 Go 执行顺序:先插入新版本,再归档旧版本,再迁移历史链
+            String oldId = model.getId();
+
+            model.setCreateId(userId);
+            model.setCode(flowNoService.generateProcessRouteCode(model, connection));
+            model.setParentId("0");
+            model.setId(UUID.randomUUID().toString());
+            model.setStatus(MESEnum.PROCESS_OF_STATUS_ENABLE.getValue());
+            jdbcClient.jdbcInsert(model, connection);
+
+            ProcessRoute existRoute = new ProcessRoute();
+            existRoute.setId(oldId);
+            existRoute.setParentId(model.getId());
+            existRoute.setStatus(MESEnum.PROCESS_OF_STATUS_DISABLE.getValue());
+            existRoute.setUpdateId(userId);
+            jdbcClient.jdbcUpdateById(existRoute, connection);
+
+            ProcessRoute childrenRoute = new ProcessRoute();
+            childrenRoute.setParentId(model.getId());
+            childrenRoute.setUpdateId(userId);
+            Map<String, Object> paramMap = new HashMap<>();
+            paramMap.put("parentId", oldId);
+            jdbcClient.jdbcUpdate(childrenRoute, paramMap, connection);
+
+            List<ProcessRouteDetail> detailList = model.getDetailList();
+            if (detailList != null) {
+                for (ProcessRouteDetail detail : detailList) {
+                    detail.setRouteId(model.getId());
+                    jdbcClient.jdbcInsert(detail, connection);
+                }
+            }
+            connection.commit();
+            return model;
+        } catch (Exception e) {
+            connection.rollback();
+            throw e;
+        } finally {
+            connection.close();
+        }
+    }
+
+    @Override
+    public Object regrade(ProcessRoute model) throws Exception {
+        Connection connection = dataSource.getConnection();
+        try {
+            connection.setAutoCommit(false);
+            Long userId = SecurityUtils.getCurrentUserId();
+            ProcessRoute children = new ProcessRoute();
+            children.setParentId(model.getId());
+            List<ProcessRoute> childrenList = jdbcClient.getJdbcList(children, connection);
+            
+            if (!childrenList.isEmpty()) {
+                childrenList = childrenList.stream()
+                    .sorted(Comparator.comparing(ProcessRoute::getCreateTime).reversed())
+                    .collect(Collectors.toList());
+                
+                ProcessRoute child = childrenList.get(0);
+                child.setParentId("0");
+                child.setStatus(MESEnum.PROCESS_OF_STATUS_ENABLE.getValue());
+                child.setUpdateId(userId);
+                jdbcClient.jdbcUpdateById(child, connection);
+
+                ProcessRoute childrenRoute = new ProcessRoute();
+                childrenRoute.setParentId(child.getId());
+                childrenRoute.setUpdateId(userId);
+                Map<String, Object> paramMap = new HashMap<>();
+                paramMap.put("parentId", model.getId());
+                jdbcClient.jdbcUpdate(childrenRoute, paramMap, connection);
+
+                jdbcClient.jdbcRemoveById(model, connection);
+
+                ProcessRouteDetail routeDetail = new ProcessRouteDetail();
+                routeDetail.setRouteId(model.getId());
+                jdbcClient.jdbcRemove(routeDetail, connection);
+            }
+            connection.commit();
+            return model;
+        } catch (Exception e) {
+            connection.rollback();
+            throw e;
+        } finally {
+            connection.close();
+        }
+    }
+}

+ 114 - 0
easydo-mes/src/main/java/easydo/technology/service/impl/ProcessStageServiceImpl.java

@@ -0,0 +1,114 @@
+package easydo.technology.service.impl;
+
+import easydo.technology.components.JdbcClient;
+import easydo.technology.enums.MESEnum;
+import easydo.technology.exception.BizException;
+import easydo.technology.model.MinioFile;
+import easydo.technology.model.ProcessRouteDetail;
+import easydo.technology.model.ProcessStage;
+import easydo.technology.service.FlowNoService;
+import easydo.technology.service.ProcessStageService;
+import easydo.technology.utils.SecurityUtils;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class ProcessStageServiceImpl implements ProcessStageService {
+
+    @Resource
+    JdbcClient jdbcClient;
+    @Resource
+    DataSource dataSource;
+    @Resource
+    FlowNoService flowNoService;
+
+    @Override
+    public Object getList(Map<String, Object> map) throws Exception {
+        List<ProcessStage> list = jdbcClient.getJdbcList(map, ProcessStage.class);
+        return list;
+    }
+
+    @Override
+    public Object getPage(Map<String, Object> map) throws Exception {
+        Connection connection = dataSource.getConnection();
+        try {
+            Map<String, Object> recordsPage = jdbcClient.getJdbcPage(map, ProcessStage.class, connection);
+            List<ProcessStage> records = (List<ProcessStage>) recordsPage.get("records");
+            for (ProcessStage model : records) {
+                jdbcClient.getMinioFile(model, connection);
+            }
+            return recordsPage;
+        } catch (Exception e) {
+            throw e;
+        } finally {
+            connection.close();
+        }
+    }
+
+    @Override
+    public Object save(ProcessStage model) throws Exception {
+        Connection connection = dataSource.getConnection();
+        try {
+            connection.setAutoCommit(false);
+            model.setStatus(MESEnum.PROCESS_OF_STATUS_ENABLE.getValue());
+            model.setCreateId(SecurityUtils.getCurrentUserId());
+            model.setCode(flowNoService.generateProcessStageCode(model, connection));
+            jdbcClient.jdbcInsert(model, connection);
+            connection.commit();
+            return model;
+        } catch (Exception e) {
+            connection.rollback();
+            throw e;
+        } finally {
+            connection.close();
+        }
+    }
+
+    @Override
+    public Object update(ProcessStage model) throws Exception {
+        Connection connection = dataSource.getConnection();
+        try {
+            connection.setAutoCommit(false);
+            model.setUpdateId(SecurityUtils.getCurrentUserId());
+            jdbcClient.jdbcUpdateById(model, connection);
+            connection.commit();
+            return model;
+        } catch (Exception e) {
+            connection.rollback();
+            throw e;
+        } finally {
+            connection.close();
+        }
+    }
+
+    @Override
+    public Object remove(ProcessStage model) throws Exception {
+        Connection connection = dataSource.getConnection();
+        try {
+            connection.setAutoCommit(false);
+
+            ProcessRouteDetail routeDetail = new ProcessRouteDetail();
+            routeDetail.setStageId(model.getId());
+            int count = jdbcClient.getJdbcCount(routeDetail, connection);
+            if (count > 0) {
+                throw new BizException("当前工序已被绑定到工艺路线,请勿删除");
+            }
+
+            jdbcClient.jdbcRemoveById(model, connection);
+
+            connection.commit();
+            return model;
+        } catch (Exception e) {
+            connection.rollback();
+            throw e;
+        } finally {
+            connection.close();
+        }
+    }
+}
+