Browse Source

发行方名称头像的唯一检验

huianan 2 years ago
parent
commit
134874d00c

+ 19 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/post/PostPublisherController.java

@@ -1,6 +1,7 @@
 package com.ruoyi.web.controller.post;
 
 import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.constant.UserConstants;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.page.TableDataInfo;
@@ -69,6 +70,15 @@ public class PostPublisherController extends BaseController
     @PostMapping
     public AjaxResult add(@RequestBody PostPublisher postPublisher)
     {
+        if(UserConstants.NOT_UNIQUE.equals(postPublisherService.checkPublisherName(postPublisher)))
+        {
+            return AjaxResult.error("新增发行方"+postPublisher.getPublisherName()+"失败,发行方标题已经存在");
+        }
+        else if(UserConstants.NOT_UNIQUE.equals(postPublisherService.checkImage(postPublisher)))
+        {
+            return AjaxResult.error("新增发行方"+postPublisher.getPublisherImage()+"失败,发行方内容已经存在");
+        }
+        postPublisher.setCreateBy(getUsername());
         return toAjax(postPublisherService.insertPostPublisher(postPublisher));
     }
 
@@ -80,6 +90,15 @@ public class PostPublisherController extends BaseController
     @PutMapping
     public AjaxResult edit(@RequestBody PostPublisher postPublisher)
     {
+        if(UserConstants.NOT_UNIQUE.equals(postPublisherService.checkPublisherName(postPublisher)))
+        {
+            return AjaxResult.error("新增发行方"+postPublisher.getPublisherName()+"失败,发行方标题已经存在");
+        }
+        else if(UserConstants.NOT_UNIQUE.equals(postPublisherService.checkImage(postPublisher)))
+        {
+            return AjaxResult.error("新增发行方"+postPublisher.getPublisherImage()+"失败,发行方内容已经存在");
+        }
+        postPublisher.setCreateBy(getUsername());
         return toAjax(postPublisherService.updatePostPublisher(postPublisher));
     }
 

+ 12 - 0
ruoyi-post/src/main/java/com/ruoyi/post/mapper/PostPublisherMapper.java

@@ -1,5 +1,6 @@
 package com.ruoyi.post.mapper;
 
+import com.ruoyi.post.domain.PostNews;
 import com.ruoyi.post.domain.PostPublisher;
 
 import java.util.List;
@@ -59,5 +60,16 @@ public interface PostPublisherMapper
      */
     public int deletePostPublisherByPublisherIds(Long[] publisherIds);
 
+    /**
+     * 判断账号是否唯一
+     * checkContent checkTitle
+     * @return
+     */
+    public PostNews checkPublisherNameUnique(String publisherName);
 
+    /**
+     * 判断头像是否唯一
+     * @return
+     */
+    public PostNews checkImageUnique(String image);
 }

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

@@ -59,5 +59,13 @@ public interface IPostPublisherService
      */
     public int deletePostPublisherByPublisherId(Long publisherId);
 
+    /**
+     * 检验发行方名称是否重复
+     */
+    public String checkPublisherName(PostPublisher postPublisher);
 
+    /**
+     * 检验发行方图像是否重复
+     */
+    public String checkImage(PostPublisher postPublisher);
 }

+ 29 - 34
ruoyi-post/src/main/java/com/ruoyi/post/service/impl/PostNewsServiceImpl.java

@@ -25,8 +25,7 @@ import java.util.List;
  * @Exegesis:
  */
 @Service
-public class PostNewsServiceImpl implements IPostNewsService
-{
+public class PostNewsServiceImpl implements IPostNewsService {
     @Resource
     private PostNewsMapper postNewsMapper;
 
@@ -35,6 +34,7 @@ public class PostNewsServiceImpl implements IPostNewsService
 
     @Resource
     protected Validator validator;
+
     /**
      * 查询通知消息管理;
      *
@@ -42,8 +42,7 @@ public class PostNewsServiceImpl implements IPostNewsService
      * @return 通知消息管理;
      */
     @Override
-    public PostNews selectPostNewsByNewsId(Integer newsId)
-    {
+    public PostNews selectPostNewsByNewsId(Integer newsId) {
         return postNewsMapper.selectPostNewsByNewsId(newsId);
     }
 
@@ -54,8 +53,7 @@ public class PostNewsServiceImpl implements IPostNewsService
      * @return 通知消息管理;
      */
     @Override
-    public List<PostNews> selectPostNewsList(PostNews postNews)
-    {
+    public List<PostNews> selectPostNewsList(PostNews postNews) {
         return postNewsMapper.selectPostNewsList(postNews);
     }
 
@@ -66,8 +64,7 @@ public class PostNewsServiceImpl implements IPostNewsService
      * @return 结果
      */
     @Override
-    public int insertPostNews(PostNews postNews)
-    {
+    public int insertPostNews(PostNews postNews) {
         postNews.setCreateTime(DateUtils.getNowDate());
         return postNewsMapper.insertPostNews(postNews);
     }
@@ -79,8 +76,7 @@ public class PostNewsServiceImpl implements IPostNewsService
      * @return 结果
      */
     @Override
-    public int updatePostNews(PostNews postNews)
-    {
+    public int updatePostNews(PostNews postNews) {
         postNews.setUpdateTime(DateUtils.getNowDate());
         return postNewsMapper.updatePostNews(postNews);
     }
@@ -92,8 +88,7 @@ public class PostNewsServiceImpl implements IPostNewsService
      * @return 结果
      */
     @Override
-    public int deletePostNewsByNewsIds(Integer[] newsIds)
-    {
+    public int deletePostNewsByNewsIds(Integer[] newsIds) {
         return postNewsMapper.deletePostNewsByNewsIds(newsIds);
     }
 
@@ -104,8 +99,7 @@ public class PostNewsServiceImpl implements IPostNewsService
      * @return 结果
      */
     @Override
-    public int deletePostNewsByNewsId(Integer newsId)
-    {
+    public int deletePostNewsByNewsId(Integer newsId) {
         return postNewsMapper.deletePostNewsByNewsId(newsId);
     }
 
@@ -114,37 +108,38 @@ public class PostNewsServiceImpl implements IPostNewsService
         return postNewsMapper.selectViewDetails(newsId);
     }
 
+    //检验标题是否重复
     @Override
     public String checkTitle(PostNews postNews) {
-        Long NewsId= StringUtils.isNull(postNews.getNewsId()) ? -1l :postNews.getNewsId();
-        PostNews info=postNewsMapper.checkTitleUnique(postNews.getNewsTitle());
-        if(StringUtils.isNotNull(info)&&info.getNewsId().longValue()!=NewsId.longValue())
-        {
+        Long NewsId = StringUtils.isNull(postNews.getNewsId()) ? -1l : postNews.getNewsId();
+        PostNews info = postNewsMapper.checkTitleUnique(postNews.getNewsTitle());
+        if (StringUtils.isNotNull(info) && info.getNewsId().longValue() != NewsId.longValue()) {
             return UserConstants.NOT_UNIQUE;
         }
         return UserConstants.UNIQUE;
     }
 
+    //检验内容是否重复
     @Override
     public String checkContent(PostNews postNews) {
-        Long NewsId= StringUtils.isNull(postNews.getNewsId()) ? -1l :postNews.getNewsId();
-        PostNews info=postNewsMapper.checkContentUnique(postNews.getNewsContent());
-        if(StringUtils.isNotNull(info)&&info.getNewsId().longValue()!=NewsId.longValue())
-        {
+        Long NewsId = StringUtils.isNull(postNews.getNewsId()) ? -1l : postNews.getNewsId();
+        PostNews info = postNewsMapper.checkContentUnique(postNews.getNewsContent());
+        if (StringUtils.isNotNull(info) && info.getNewsId().longValue() != NewsId.longValue()) {
             return UserConstants.NOT_UNIQUE;
         }
         return UserConstants.UNIQUE;
     }
+
     /**
      * 导入用户数据
      *
-     * @param phoneList 手机号数据列表
+     * @param phoneList       手机号数据列表
      * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
-     * @param operName 操作用户
+     * @param operName        操作用户
      * @return 结果
      */
     @Override
-    public String importPhone(List<PostNews> phoneList, Boolean isUpdateSupport, String operName,PostNews postNews) {
+    public String importPhone(List<PostNews> phoneList, Boolean isUpdateSupport, String operName, PostNews postNews) {
         if (StringUtils.isNull(phoneList) || phoneList.size() == 0) {
             throw new ServiceException("导入用户电话数据不能为空!");
         }
@@ -163,16 +158,17 @@ public class PostNewsServiceImpl implements IPostNewsService
                     this.insertBulletin(postNews);
                     successNum++;
                     successMsg.append("<br/>" + successNum + "电话号 " + postNews.getUserPhone() + " 导入成功");
-                }}catch(Exception e)
-                {
-                    failureNum++;
-                    String msg = "<br/>" + failureNum + "电话号 " +postNews.getUserPhone()+ " 导入失败:";
-                    failureMsg.append(msg + e.getMessage());
                 }
+            } catch (Exception e) {
+                failureNum++;
+                String msg = "<br/>" + failureNum + "电话号 " + postNews.getUserPhone() + " 导入失败:";
+                failureMsg.append(msg + e.getMessage());
             }
-
-            return successMsg.toString();
         }
+
+        return successMsg.toString();
+    }
+
     /**
      * 新增保存用户电话信息
      *
@@ -181,8 +177,7 @@ public class PostNewsServiceImpl implements IPostNewsService
      */
     @Override
     @Transactional
-    public int insertBulletin(PostNews postNews)
-    {
+    public int insertBulletin(PostNews postNews) {
         // 新增用户电话信息
         int rows = postNewsMapper.insertPostNews(postNews);
         return rows;

+ 25 - 0
ruoyi-post/src/main/java/com/ruoyi/post/service/impl/PostPublisherServiceImpl.java

@@ -1,6 +1,9 @@
 package com.ruoyi.post.service.impl;
 
+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 com.ruoyi.post.domain.PostPublisher;
 import com.ruoyi.post.mapper.PostPublisherMapper;
 import com.ruoyi.post.service.IPostPublisherService;
@@ -93,4 +96,26 @@ public class PostPublisherServiceImpl implements IPostPublisherService
     {
         return postPublisherMapper.deletePostPublisherByPublisherId(publisherId);
     }
+
+    //检验发行方账号是否重复
+    @Override
+    public String checkPublisherName(PostPublisher postPublisher) {
+        Long NewsId = StringUtils.isNull(postPublisher.getPublisherId()) ? -1l : postPublisher.getPublisherId();
+        PostNews info = postPublisherMapper.checkPublisherNameUnique(postPublisher.getPublisherName());
+        if (StringUtils.isNotNull(info) && info.getNewsId().longValue() != NewsId.longValue()) {
+            return UserConstants.NOT_UNIQUE;
+        }
+        return UserConstants.UNIQUE;
+    }
+
+    //检验发行方头像是否重复
+    @Override
+    public String checkImage(PostPublisher postPublisher) {
+        Long NewsId = StringUtils.isNull(postPublisher.getPublisherId()) ? -1l : postPublisher.getPublisherId();
+        PostNews info = postPublisherMapper.checkImageUnique(postPublisher.getPublisherImage());
+        if (StringUtils.isNotNull(info) && info.getNewsId().longValue() != NewsId.longValue()) {
+            return UserConstants.NOT_UNIQUE;
+        }
+        return UserConstants.UNIQUE;
+    }
 }

+ 8 - 0
ruoyi-post/src/main/resources/mapper/PostPublisherMapper.xml

@@ -129,4 +129,12 @@
             #{publisherId}
         </foreach>
     </delete>
+<!--    账号是否重复-->
+    <select id="checkPublisherNameUnique" parameterType="String" resultMap="PostPublisherResult">
+        select publisher_id,publisher_name from post_publisher where publisher_name = #{publisherName} limit 1
+    </select>
+<!--    头像是否重复-->
+    <select id="checkImageUnique" parameterType="String" resultMap="PostPublisherResult">
+        select publisher_id, publisher_image from post_publisher where publisher_image = #{publisherImage} limit 1
+    </select>
 </mapper>