Jelajahi Sumber

BOM资料检验编号+version

zhoudw 7 tahun lalu
induk
melakukan
b936c7c25c

+ 4 - 1
applications/document/document-server/src/main/java/com/usoftchina/saas/document/mapper/BomMapper.java

@@ -19,7 +19,10 @@ public interface BomMapper extends CommonBaseMapper<Bom> {
 
     int updateByPrimaryKey(Bom record);
 
-    int validCodeAndVersion(@Param("code") String code, @Param("version") String version, @Param("companyId") Long companyId);
+    int validCodeAndVersionWhenInsert(@Param("code") String code, @Param("version") String version, @Param("companyId") Long companyId);
+
+    int validCodeAndVersionWhenUpdate(@Param("code") String code, @Param("id") Long id, @Param("version") String version, @Param("companyId") Long companyId);
+
 
     int validateCodeWhenInsert(@Param("code") String code, @Param("companyId") Long companyId);
 

+ 7 - 3
applications/document/document-server/src/main/java/com/usoftchina/saas/document/service/impl/BomServiceImpl.java

@@ -51,9 +51,10 @@ public class BomServiceImpl extends CommonBaseServiceImpl<BomMapper, Bom> implem
         DocBaseDTO docBaseDTO = null;
         if(id == 0){
             //校验编号和版本 是否已存在
-            int count = getMapper().validCodeAndVersion(bom.getBo_mothercode(), bom.getBo_version(), companyId);
+            int count = getMapper().validCodeAndVersionWhenInsert(bom.getBo_mothercode(), bom.getBo_version(), companyId);
             if(count == 0){
-                String code = pushMaxnubmer(bom.getBo_mothercode(), bom.getId());
+//                String code = pushMaxnubmer(bom.getBo_mothercode(), bom.getId());
+                String code = bom.getBo_mothercode();
                 bom.setBo_mothercode(code);
                 bom.setCompanyId(companyId);
                 //保存BOM
@@ -79,8 +80,11 @@ public class BomServiceImpl extends CommonBaseServiceImpl<BomMapper, Bom> implem
             }
         }else{
             //校验编号和版本 是否已存在
-            int count = getMapper().validCodeAndVersion(bom.getBo_mothercode(), bom.getBo_version(), companyId);
+            int count = getMapper().validCodeAndVersionWhenUpdate(bom.getBo_mothercode(),bom.getId(),bom.getBo_version(),companyId);
             //更新主表
+            if (count != 0) {
+                throw new BizException(BizExceptionCode.BOM_SAVE);
+            }
             getMapper().updateByPrimaryKeySelective(bom);
             if (bomDetailList.size() > 0) {
                 List<BomDetail> insertItems = new ArrayList<BomDetail>();

+ 7 - 1
applications/document/document-server/src/main/resources/mapper/BomMapper.xml

@@ -271,9 +271,15 @@
   <select id="validateCodeWhenUpdate" resultType="int" >
     select count(*) from BOM where BO_MOTHERCODE = #{code} and BO_ID != #{id} and companyId =#{companyId}
   </select>
-  <select id="validCodeAndVersion" resultType="int">
+  <select id="validCodeAndVersionWhenInsert" resultType="int">
       SELECT COUNT(*) FROM BOM WHERE BO_MOTHERCODE = #{code} and BO_VERSION=#{version} and COMPANYID=#{companyId}
   </select>
+
+  <select id="validCodeAndVersionWhenUpdate" resultType="int">
+    SELECT COUNT(*) FROM BOM WHERE BO_MOTHERCODE = #{code} and BO_ID != #{id} and BO_VERSION=#{version} and COMPANYID=#{companyId}
+  </select>
+
+
   <select id="getCodeById" resultType="string">
       SELECT BO_MOTHERCODE FROM BOM WHERE BO_ID = #{id} and COMPANYID = #{companyId}
   </select>