Bläddra i källkod

藏品的新增唯一判定

zhangxin 2 år sedan
förälder
incheckning
d6182ba55a

+ 12 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/post/PostCollectionController.java

@@ -2,6 +2,9 @@ package com.ruoyi.web.controller.post;
 
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
+
+import com.ruoyi.common.constant.UserConstants;
+import com.ruoyi.post.domain.PostNews;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -77,6 +80,15 @@ public class PostCollectionController extends BaseController
     @PostMapping
     public AjaxResult add(@RequestBody PostCollection postCollection)
     {
+        if(UserConstants.NOT_UNIQUE.equals(postCollectionService.checkName(postCollection)))
+        {
+            return AjaxResult.error("新增消息"+postCollection.getCollectionName()+"失败,消息标题已经存在");
+        }
+        else if(UserConstants.NOT_UNIQUE.equals(postCollectionService.checkName(postCollection)))
+        {
+            return AjaxResult.error("新增消息"+postCollection.getCollectionName()+"失败,消息内容已经存在");
+        }
+        postCollection.setCreateBy(getUsername());
         return toAjax(postCollectionService.insertPostCollection(postCollection));
     }
 

+ 8 - 0
ruoyi-post/src/main/java/com/ruoyi/post/mapper/PostCollectionMapper.java

@@ -2,6 +2,7 @@ package com.ruoyi.post.mapper;
 
 import java.util.List;
 import com.ruoyi.post.domain.PostCollection;
+import com.ruoyi.post.domain.PostNews;
 
 /**
  * 邮贝藏品信息; 
@@ -58,4 +59,11 @@ public interface PostCollectionMapper
      * @return 结果
      */
     public int deletePostCollectionByCollectionIds(Long[] collectionIds);
+
+    /**
+    * 判断是否唯一名字
+    *
+    * */
+     public PostCollection checkNameUnique(String collectionName);
+
 }

+ 8 - 0
ruoyi-post/src/main/java/com/ruoyi/post/service/IPostCollectionService.java

@@ -1,7 +1,9 @@
 package com.ruoyi.post.service;
 
+import java.util.Collection;
 import java.util.List;
 import com.ruoyi.post.domain.PostCollection;
+import com.ruoyi.post.domain.PostNews;
 
 /**
  * 邮贝藏品信息; Service接口
@@ -58,4 +60,10 @@ public interface IPostCollectionService
      * @return 结果
      */
     public int deletePostCollectionByCollectionId(Long collectionId);
+
+     /**
+      *判断邮贝藏品名字是否唯一;
+      */
+     public String checkName(PostCollection postCollection);
+
 }

+ 16 - 1
ruoyi-post/src/main/java/com/ruoyi/post/service/impl/PostCollectionServiceImpl.java

@@ -1,7 +1,12 @@
 package com.ruoyi.post.service.impl;
 
+import java.util.Collection;
 import java.util.List;
+
+import com.ruoyi.common.constant.UserConstants;
 import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.post.domain.PostNews;
 import org.springframework.stereotype.Service;
 import com.ruoyi.post.mapper.PostCollectionMapper;
 import com.ruoyi.post.domain.PostCollection;
@@ -19,7 +24,6 @@ public class PostCollectionServiceImpl implements IPostCollectionService
 {
     @Resource
     private PostCollectionMapper postCollectionMapper;
-
     /**
      * 查询邮贝藏品信息; 
      * 
@@ -93,4 +97,15 @@ public class PostCollectionServiceImpl implements IPostCollectionService
     {
         return postCollectionMapper.deletePostCollectionByCollectionId(collectionId);
     }
+
+    //检验标题是否重复
+    @Override
+    public String checkName(PostCollection postCollection) {
+        Long CollectionId = StringUtils.isNull(postCollection.getCollectionId()) ? -1l : postCollection.getCollectionId();
+        PostCollection info = postCollectionMapper.checkNameUnique(postCollection.getCollectionName());
+        if (StringUtils.isNotNull(info)&&info.getCollectionId().longValue()!= CollectionId.longValue()) {
+            return UserConstants.NOT_UNIQUE;
+        }
+        return UserConstants.UNIQUE;
+    }
 }

+ 7 - 0
ruoyi-post/src/main/resources/mapper/PostCollectionMapper.xml

@@ -136,4 +136,11 @@
             #{collectionId}
         </foreach>
     </update>
+
+
+
+    <select id="checkNameUnique" parameterType="String" resultMap="PostCollectionResult">
+        select collection_id, collection_name from post_collection where collection_name = #{collectionName} limit 1
+    </select>
+
 </mapper>