Selaa lähdekoodia

fix:解决客户附件查询不到的问题

lumaojun 1 kuukausi sitten
vanhempi
commit
b4b7c48bc1

+ 13 - 87
easydo-mes/src/main/java/easydo/technology/controller/CustomerController.java

@@ -1,11 +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.Customer;
-import easydo.technology.service.FlowNoService;
-import easydo.technology.utils.StringUtil;
+import easydo.technology.service.CustomerService;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -13,112 +9,42 @@ 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.HashMap;
-import java.util.List;
 import java.util.Map;
 
 @RestController
 @RequestMapping("/customer")
 public class CustomerController {
+
     @Resource
-    JdbcClient jdbcClient;
-    @Resource
-    DataSource dataSource;
-    @Resource
-    FlowNoService flowNoService;
+    CustomerService customerService;
 
     @RequestMapping(value = "/getList")
     public Object getList(@RequestBody Map<String, Object> map) throws Exception {
-        List<Customer> list = jdbcClient.getJdbcList(map, Customer.class);
+        Object list = customerService.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, Customer.class, connection);
-            return new ResponseEntity<>(recordsPage, HttpStatus.OK);
-        } catch (Exception e) {
-            throw new BizException(e.getMessage());
-        } finally {
-            connection.close();
-        }
+        Object page = customerService.getPage(map);
+        return new ResponseEntity<>(page, HttpStatus.OK);
     }
 
     @RequestMapping(value = "/save")
     public Object save(@RequestBody Customer model) throws Exception {
-        Connection connection = dataSource.getConnection();
-        try {
-            connection.setAutoCommit(false);
-            model.setStatus(MESEnum.PROCESS_OF_STATUS_ENABLE.getValue());
-            generateCode(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 = customerService.save(model);
+        return new ResponseEntity<>(result, HttpStatus.OK);
     }
 
     @RequestMapping(value = "/update")
     public Object update(@RequestBody Customer model) throws Exception {
-        Connection connection = dataSource.getConnection();
-        try {
-            connection.setAutoCommit(false);
-
-            jdbcClient.jdbcUpdateById(model, connection);
-
-            connection.commit();
-            return new ResponseEntity<>(HttpStatus.OK);
-        } catch (Exception e) {
-            connection.rollback();
-            throw new BizException(e.getMessage());
-        } finally {
-            connection.close();
-        }
+        Object result = customerService.update(model);
+        return new ResponseEntity<>(result, HttpStatus.OK);
     }
 
     @RequestMapping(value = "/remove")
-    public Object deleteProgram(@RequestBody Customer model) throws Exception {
-        Connection connection = dataSource.getConnection();
-        try {
-            jdbcClient.jdbcRemoveById(model, connection);
-
-            return new ResponseEntity<>(HttpStatus.OK);
-        } catch (Exception e) {
-            throw new BizException(e.getMessage());
-        } finally {
-            connection.close();
-        }
+    public Object remove(@RequestBody Customer model) throws Exception {
+        Object result = customerService.remove(model);
+        return new ResponseEntity<>(result, HttpStatus.OK);
     }
-
-    private synchronized void generateCode(Customer model, Connection connection) throws Exception {
-        if (StringUtil.isEmpty(model.getCode())) {
-            while (true) {
-                String flowNo = flowNoService.getFlowNo(MESEnum.FLOW_NO_TYPE_CUSTOMER.getValue(), connection);
-                Customer param = new Customer();
-                param.setCode(flowNo);
-                int count = jdbcClient.getJdbcCount(param, connection);
-                if (count == 0) {
-                    model.setCode(flowNo);
-                    break;
-                }
-            }
-        } else {
-            Customer param = new Customer();
-            param.setCode(model.getCode());
-            int count = jdbcClient.getJdbcCount(param, connection);
-            if (count > 0) {
-                throw new BizException("编号已存在,请重新填写");
-            }
-        }
-    }
-
 }

+ 8 - 2
easydo-mes/src/main/java/easydo/technology/model/Customer.java

@@ -1,9 +1,13 @@
 package easydo.technology.model;
 
+import easydo.technology.annotation.Minio;
 import lombok.Data;
+import lombok.EqualsAndHashCode;
 
 @Data
-public class Customer {
+@Minio
+@EqualsAndHashCode(callSuper = true)
+public class Customer extends CommonModel {
     private String id;
     private String name;
     private String code;
@@ -19,5 +23,7 @@ public class Customer {
     private String email;
     private String creditLevel;
     private String valueLevel;
-
+    private String tenantId;
+    private Long createId;
+    private Long updateId;
 }

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

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

+ 56 - 0
easydo-mes/src/main/java/easydo/technology/service/FlowNoService.java

@@ -30,6 +30,7 @@ public class FlowNoService {
     private final Object processStageLock = new Object();
     private final Object processRouteLock = new Object();
     private final Object productMaterialLock = new Object();
+    private final Object customerLock = new Object();
 
 
     /**
@@ -307,6 +308,61 @@ public class FlowNoService {
         }
     }
 
+    /**
+     * 生成客户编码 (Customer) - 独立解耦实现
+     */
+    public String generateCustomerCode(Customer model, Connection connection) throws Exception {
+        synchronized (customerLock) {
+            String manualCode = model.getCode();
+            String tenantId = model.getTenantId();
+            if (StringUtil.isNotEmpty(manualCode)) {
+                Map<String, Object> checkMap = new HashMap<>();
+                checkMap.put("code", manualCode);
+                checkMap.put("tenantId", tenantId);
+                int count = (int) jdbcClient.getJdbcCountByMap(checkMap, Customer.class, connection);
+                if (count > 0) {
+                    throw new BizException("客户编号已存在: " + manualCode);
+                }
+                return manualCode;
+            }
+            while (true) {
+                FlowNo flowNo = new FlowNo();
+                flowNo.setType("customer");
+                flowNo.setTenantId(tenantId);
+                flowNo = jdbcClient.getJdbcModel(flowNo, connection);
+                if (flowNo == null) throw new BizException("未配置客户流水号规则");
+
+                String currDate = DFY_MD.format(LocalDateTime.now());
+                String currDate2 = DFY_MD_2.format(LocalDateTime.now());
+                if (StringUtil.isEmpty(flowNo.getCurrDate()) || !flowNo.getCurrDate().equals(currDate)) {
+                    flowNo.setCurrDate(currDate);
+                    flowNo.setCurrSeq(1);
+                } else {
+                    flowNo.setCurrSeq(flowNo.getCurrSeq() + 1);
+                }
+
+                String no;
+                if (StringUtil.isEmpty(flowNo.getCurrDate())) {
+                    no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + String.format("%06d", flowNo.getCurrSeq());
+                } else {
+                    no = (flowNo.getPrefix() != null ? flowNo.getPrefix() : "") + currDate2 + String.format("%05d", flowNo.getCurrSeq());
+                }
+                flowNo.setCurrNo(no);
+
+                Map<String, Object> updateMap = new HashMap<>();
+                updateMap.put("type", "customer");
+                updateMap.put("tenantId", tenantId);
+                jdbcClient.jdbcUpdate(flowNo, updateMap, connection);
+
+                Map<String, Object> checkMap = new HashMap<>();
+                checkMap.put("code", no);
+                checkMap.put("tenantId", tenantId);
+                int count = (int) jdbcClient.getJdbcCountByMap(checkMap, Customer.class, connection);
+                if (count == 0) return no;
+            }
+        }
+    }
+
     /**
      * 原始流水号生成方法
      */

+ 108 - 0
easydo-mes/src/main/java/easydo/technology/service/impl/CustomerServiceImpl.java

@@ -0,0 +1,108 @@
+package easydo.technology.service.impl;
+
+import easydo.technology.components.JdbcClient;
+import easydo.technology.enums.MESEnum;
+import easydo.technology.model.Customer;
+import easydo.technology.service.CustomerService;
+import easydo.technology.service.FlowNoService;
+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 CustomerServiceImpl implements CustomerService {
+
+    @Resource
+    JdbcClient jdbcClient;
+    @Resource
+    DataSource dataSource;
+    @Resource
+    FlowNoService flowNoService;
+
+    @Override
+    public Object getList(Map<String, Object> map) throws Exception {
+        List<Customer> list = jdbcClient.getJdbcList(map, Customer.class);
+        Connection connection = dataSource.getConnection();
+        try {
+            for (Customer model : list) {
+                jdbcClient.getMinioFile(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, Customer.class, connection);
+            List<Customer> records = (List<Customer>) recordsPage.get("records");
+            for (Customer model : records) {
+                jdbcClient.getMinioFile(model, connection);
+            }
+            return recordsPage;
+        } finally {
+            connection.close();
+        }
+    }
+
+    @Override
+    public Object save(Customer 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.generateCustomerCode(model, connection));
+            jdbcClient.jdbcInsert(model, connection);
+            connection.commit();
+            return model;
+        } catch (Exception e) {
+            connection.rollback();
+            throw e;
+        } finally {
+            connection.close();
+        }
+    }
+
+    @Override
+    public Object update(Customer 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(Customer model) throws Exception {
+        Connection connection = dataSource.getConnection();
+        try {
+            connection.setAutoCommit(false);
+            jdbcClient.jdbcRemoveById(model, connection);
+            connection.commit();
+            return model;
+        } catch (Exception e) {
+            connection.rollback();
+            throw e;
+        } finally {
+            connection.close();
+        }
+    }
+}
+