ソースを参照

修改客户资料保存,更新校验

zhoudw 7 年 前
コミット
b2cab4c6c6

+ 1 - 1
applications/commons/commons-server/src/main/resources/application.yml

@@ -53,7 +53,7 @@ eureka:
   client:
     registryFetchIntervalSeconds: 5
     serviceUrl:
-      defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@192.168.0.181:8510/eureka/
+      defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@127.0.0.1:8500/eureka/
 server:
   port: 8920
   tomcat:

+ 5 - 0
applications/document/document-server/src/main/java/com/usoftchina/saas/document/mapper/CustomerMapper.java

@@ -21,4 +21,9 @@ public interface CustomerMapper extends CommonBaseMapper<Customer> {
 
     Integer validateCodeWhenUpdate(@Param("code") String code, @Param("id") Long id,
                                    @Param("companyId") Long companyId);
+
+    int validNameAndCodeWhenInsert(Customer record);
+
+    int validNameAndCodeWhenUpdate(Customer record);
+
 }

+ 12 - 1
applications/document/document-server/src/main/java/com/usoftchina/saas/document/service/impl/CustomerServiceImpl.java

@@ -133,6 +133,11 @@ public class CustomerServiceImpl extends CommonBaseServiceImpl<CustomerMapper, C
         //单号赋值
         customer.setCu_code(cu_code);
         if (StringUtils.isEmpty(cu_id) || "0".equals(cu_id.toString())) {
+            //检查名称和编号
+            int count = getMapper().validNameAndCodeWhenInsert(customer);
+            if (count>0) {
+                throw new BizException(500, "客户名称或编号重复");
+            }
             //插入操作
             getMapper().insertSelective(customer);
             cu_id = customer.getId();
@@ -167,6 +172,12 @@ public class CustomerServiceImpl extends CommonBaseServiceImpl<CustomerMapper, C
             messageLogService.save(baseDTO);
             return baseDTO;
         }
+        //检查名称和编号
+        int count = getMapper().validNameAndCodeWhenUpdate(customer);
+        if (count>0) {
+            throw new BizException(500, "客户名称或编号重复");
+        }
+
         //更新操作
         getMapper().updateByPrimaryKeySelective(customer);
         //添加从表传输对象
@@ -216,7 +227,7 @@ public class CustomerServiceImpl extends CommonBaseServiceImpl<CustomerMapper, C
 
         baseDTO = getBaseDTOById(cu_id);
         //日志记录
-            messageLogService.save(baseDTO);
+        messageLogService.save(baseDTO);
         return baseDTO;
     }
 

+ 10 - 0
applications/document/document-server/src/main/resources/mapper/CustomerMapper.xml

@@ -359,6 +359,16 @@
     select count(1) from customer where cu_code = #{code} and cu_id != #{id} and companyId =#{companyId}
   </select>
 
+  <select id="validNameAndCodeWhenInsert" parameterType="com.usoftchina.saas.document.entities.Customer" resultType="int">
+    select count(1) from customer where cu_code = #{cu_code,jdbcType=VARCHAR} or cu_name = #{cu_name,jdbcType=VARCHAR}
+  </select>
+
+  <select id="validNameAndCodeWhenUpdate" parameterType="com.usoftchina.saas.document.entities.Customer" resultType="int">
+    select count(1) from customer where cu_code = #{cu_code,jdbcType=VARCHAR} or cu_name = #{cu_name,jdbcType=VARCHAR}
+    and cu_id != #{id}
+  </select>
+
+
   <select id="selectCodeById" parameterType="java.lang.Long" resultType="string">
     select
     cu_code