Browse Source

新增套系1.2(判断套系名称是否重复)

sjx 2 years ago
parent
commit
1d6e2dfdc5

+ 6 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/PostCollectionsSystemController.java

@@ -92,6 +92,12 @@ public class PostCollectionsSystemController extends BaseController
         if (postCollectionsSystem.getEndTime().before(DateUtils.getNowDate())){
             return warn("请设置正确的套系时间");
         }
+
+        //判断套系名称是否重复
+        if (postCollectionsSystemService.selectPostCollectionsSystemByName(postCollectionsSystem) > 0){
+            return warn("该套系名称已存在");
+        }
+
         return toAjax(postCollectionsSystemService.insertPostCollectionsSystem(postCollectionsSystem));
     }
 

+ 2 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/PostCollectionsSystemMapper.java

@@ -67,4 +67,6 @@ public interface PostCollectionsSystemMapper
                                                             @Param("timeRight") Date timeRight);
 
     Integer getCopiesById(Long id);
+    // 查询该套系名 数量
+    int selectPostCollectionsSystemByName(PostCollectionsSystem postCollectionsSystem);
 }

+ 6 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/IPostCollectionsSystemService.java

@@ -70,4 +70,10 @@ public interface IPostCollectionsSystemService
      * @return 该套系下藏品数量
      */
     public Integer getCopies(Long id);
+
+    /**
+     *  用套系名称进行查询
+     * @param postCollectionsSystem
+     */
+    int selectPostCollectionsSystemByName(PostCollectionsSystem postCollectionsSystem);
 }

+ 6 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PostCollectionsSystemServiceImpl.java

@@ -166,4 +166,10 @@ public class PostCollectionsSystemServiceImpl implements IPostCollectionsSystemS
     public Integer getCopies(Long id) {
         return postCollectionsSystemMapper.getCopiesById(id);
     }
+
+
+    @Override
+    public int selectPostCollectionsSystemByName(PostCollectionsSystem postCollectionsSystem) {
+        return postCollectionsSystemMapper.selectPostCollectionsSystemByName(postCollectionsSystem);
+    }
 }

+ 5 - 0
ruoyi-system/src/main/resources/mapper/system/PostCollectionsSystemMapper.xml

@@ -117,7 +117,12 @@
         </where>
     </select>
 
+    <!--获取藏品数量-->
     <select id="getCopiesById" parameterType="Long" resultType="Integer">
        SELECT SUM(collections_number) FROM post_collections where system_id = #{id}
     </select>
+    <!--用藏品名称进行查询数量-->
+    <select id="selectPostCollectionsSystemByName" parameterType="PostCollectionsSystem" resultType="int">
+        SELECT COUNT(name) FROM post_collections_system where name =  #{name} and del_flag = '0'
+    </select>
 </mapper>