Browse Source

新增功能以及修改功能的完善

huianan 2 years ago
parent
commit
7e47d99483

+ 24 - 7
ruoyi-admin/src/main/java/com/ruoyi/web/controller/post/PostBulletinController.java

@@ -6,11 +6,14 @@ import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.post.domain.PostBulletin;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import com.ruoyi.post.service.IPostBulletinService;
 import javax.servlet.http.HttpServletResponse;
@@ -64,17 +67,20 @@ public class PostBulletinController extends BaseController
         return success(postBulletinService.selectPostBulletinByNoticeId(noticeId));
     }
 
-    /**
-     * 新增通知公告;
-     */
     @PreAuthorize("@ss.hasPermi('system:bulletin:add')")
     @Log(title = "新增通知公告; ", businessType = BusinessType.INSERT)
     @PostMapping("/add")
-    public AjaxResult add(@RequestBody PostBulletin postBulletin)
+    public AjaxResult add(@Validated @RequestBody PostBulletin postBulletin)
     {
-//        if(UserConstants.NOT_UNIQUE.equals(postBulletinService.newsTitleAndNewsContentIsNull(postBulletin))){
-//            return AjaxResult.error("新增失败"+postBulletin.getNoticeTitle()+"消息标题及内容已经存在");
-//        }
+        if(UserConstants.NOT_UNIQUE.equals(postBulletinService.checkTitle(postBulletin)))
+        {
+            return AjaxResult.error("新增公告"+postBulletin.getNoticeTitle()+"失败,公告标题已经存在");
+        }
+        else if(UserConstants.NOT_UNIQUE.equals(postBulletinService.checkContent(postBulletin)))
+        {
+            return AjaxResult.error("新增公告"+postBulletin.getNoticeContent()+"失败,公告内容已经存在");
+        }
+        postBulletin.setCreateBy(getUsername());
         return toAjax(postBulletinService.insertPostBulletin(postBulletin));
     }
 
@@ -86,6 +92,17 @@ public class PostBulletinController extends BaseController
     @PutMapping("/edit")
     public AjaxResult edit(@RequestBody PostBulletin postBulletin)
     {
+        //判断用户数据是否存在
+
+        if(UserConstants.NOT_UNIQUE.equals(postBulletinService.checkTitle(postBulletin)))
+        {
+            return AjaxResult.error("修改公告"+postBulletin.getNoticeTitle()+"失败,公告标题已经存在");
+        }
+        else if(StringUtils.isNotEmpty(postBulletin.getNoticeContent())&&UserConstants.NOT_UNIQUE.equals(postBulletinService.checkContent(postBulletin)))
+        {
+            return AjaxResult.error("修改公告"+postBulletin.getNoticeContent()+"失败,公告内容已经存在");
+        }
+        postBulletin.setCreateBy(getUsername());
         return toAjax(postBulletinService.updatePostBulletin(postBulletin));
     }
 

+ 20 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/post/PostNewsController.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;
@@ -75,6 +76,15 @@ public class PostNewsController extends BaseController
     @PostMapping("/add")
     public AjaxResult add(@RequestBody PostNews postNews)
     {
+        if(UserConstants.NOT_UNIQUE.equals(postNewsService.checkTitle(postNews)))
+        {
+            return AjaxResult.error("新增消息"+postNews.getNewsTitle()+"失败,消息标题已经存在");
+        }
+        else if(UserConstants.NOT_UNIQUE.equals(postNewsService.checkContent(postNews)))
+        {
+            return AjaxResult.error("新增消息"+postNews.getNewsContent()+"失败,消息内容已经存在");
+        }
+        postNews.setCreateBy(getUsername());
         return toAjax(postNewsService.insertPostNews(postNews));
     }
 
@@ -86,7 +96,16 @@ public class PostNewsController extends BaseController
     @PutMapping("/edit")
     public AjaxResult edit(@RequestBody PostNews postNews)
     {
-        return toAjax(postNewsService.updatePostNews(postNews));
+        if(UserConstants.NOT_UNIQUE.equals(postNewsService.checkTitle(postNews)))
+        {
+            return AjaxResult.error("修改消息"+postNews.getNewsTitle()+"失败,消息标题已经存在");
+        }
+        else if(UserConstants.NOT_UNIQUE.equals(postNewsService.checkContent(postNews)))
+        {
+            return AjaxResult.error("修改消息"+postNews.getNewsContent()+"失败,消息内容已经存在");
+        }
+        postNews.setCreateBy(getUsername());
+        return toAjax(postNewsService.insertPostNews(postNews));
     }
 
     /**

+ 10 - 2
ruoyi-post/src/main/java/com/ruoyi/post/mapper/PostBulletinMapper.java

@@ -59,9 +59,17 @@ public interface PostBulletinMapper {
     public int deletePostBulletinByNoticeIds(Integer[] noticeIds);
 
     /**
-     * 判断内容以及标题是否存在
+     * 判断消息内容是否唯一
+     * checkContent checkTitle
+     * @return
      */
-    public String checkTitleAndContentIsExit(String title,String Content);
+    public PostBulletin checkContentUnique(String content);
+
+    /**
+     * 判断消息标题是否唯一
+     * @return
+     */
+    public PostBulletin checkTitleUnique(String Title);
 
     /**
      * 查看详情

+ 19 - 0
ruoyi-post/src/main/java/com/ruoyi/post/mapper/PostNewsMapper.java

@@ -1,6 +1,7 @@
 package com.ruoyi.post.mapper;
 
 
+import com.ruoyi.post.domain.PostNews;
 import com.ruoyi.post.domain.PostNews;
 
 import java.util.List;
@@ -58,4 +59,22 @@ public interface PostNewsMapper
      * @return 结果
      */
     public int deletePostNewsByNewsIds(Integer[] newsIds);
+
+    /**
+     * 判断消息内容是否唯一
+     * checkContent checkTitle
+     * @return
+     */
+    public PostNews checkContentUnique(String content);
+
+    /**
+     * 判断消息标题是否唯一
+     * @return
+     */
+    public PostNews checkTitleUnique(String Title);
+
+    /**
+     * 查看详情
+     */
+    public PostNews selectViewDetails(Integer newsId);
 }

+ 8 - 3
ruoyi-post/src/main/java/com/ruoyi/post/service/IPostBulletinService.java

@@ -53,12 +53,17 @@ public interface IPostBulletinService
     public int deletePostBulletinByNoticeId(Integer noticeId);
 
     /**
-     * 公告标题及内容为空判断
+     * 查看详情
+     */
+    public PostBulletin selectViewDetail(Integer noticeId);
+
+    /**
+     * 判断消息标题是否唯一
      */
-    public String newsTitleAndNewsContentIsNull(PostBulletin postBulletin);
+    public String checkTitle(PostBulletin postBulletin);
 
     /**
      * 查看详情
      */
-    public PostBulletin selectViewDetail(Integer noticeId);
+    public String checkContent(PostBulletin postBulletin);
 }

+ 16 - 0
ruoyi-post/src/main/java/com/ruoyi/post/service/IPostNewsService.java

@@ -1,5 +1,6 @@
 package com.ruoyi.post.service;
 
+import com.ruoyi.post.domain.PostNews;
 import com.ruoyi.post.domain.PostNews;
 
 import java.util.List;
@@ -58,4 +59,19 @@ public interface IPostNewsService
      * @return 结果
      */
     public int deletePostNewsByNewsId(Integer newsId);
+
+    /**
+     * 查看详情
+     */
+    public PostNews selectViewDetail(Integer newsId);
+
+    /**
+     * 判断消息标题是否唯一
+     */
+    public String checkTitle(PostNews postNews);
+
+    /**
+     * 查看详情
+     */
+    public String checkContent(PostNews postNews);
 }

+ 32 - 13
ruoyi-post/src/main/java/com/ruoyi/post/service/impl/PostBulletinServiceImpl.java

@@ -1,6 +1,7 @@
 package com.ruoyi.post.service.impl;
 
 import com.ruoyi.common.constant.UserConstants;
+import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.post.domain.PostBulletin;
@@ -92,26 +93,44 @@ public class PostBulletinServiceImpl implements IPostBulletinService {
         return postBulletinMapper.deletePostBulletinByNoticeId(noticeId);
     }
 
-    /**
-     * 公告及公告内容为空的判断
-     *
-     * @param postBulletin
-     */
+
+    @Override
+    public PostBulletin selectViewDetail(Integer noticeId) {
+        return postBulletinMapper.selectViewDetails(noticeId);
+    }
+
     @Override
-    public String newsTitleAndNewsContentIsNull(PostBulletin postBulletin) {
-        //查询内容以及标题是否存在
-        String PostNewsId = StringUtils.isNull(postBulletin.getNoticeId()) ? "标题以及内容不存在" : postBulletin.getNoticeId().toString();
-        String title = postBulletinMapper.checkTitleAndContentIsExit(postBulletin.getNoticeTitle(), postBulletin.getNoticeContent());
-        if (StringUtils.isNotNull(title) && postBulletin.getNoticeId().toString() != PostNewsId) {
+    public String checkTitle(PostBulletin postBulletin) {
+       Long noticeId=StringUtils.isNull(postBulletin.getNoticeId()) ? -1l :postBulletin.getNoticeId();
+       PostBulletin info=postBulletinMapper.checkTitleUnique(postBulletin.getNoticeTitle());
+       if(StringUtils.isNotNull(info)&&info.getNoticeId().longValue()!=noticeId.longValue())
+        {
             return UserConstants.NOT_UNIQUE;
         }
-        return UserConstants.UNIQUE;
+       return UserConstants.UNIQUE;
     }
 
     @Override
-    public PostBulletin selectViewDetail(Integer noticeId) {
-        return postBulletinMapper.selectViewDetails(noticeId);
+    public String checkContent(PostBulletin postBulletin) {
+        Long noticeId=StringUtils.isNull(postBulletin.getNoticeId()) ? -1l :postBulletin.getNoticeId();
+        PostBulletin info=postBulletinMapper.checkContentUnique(postBulletin.getNoticeContent());
+        if(StringUtils.isNotNull(info)&&info.getNoticeId().longValue()!=noticeId.longValue())
+        {
+            return UserConstants.NOT_UNIQUE;
+        }
+        return UserConstants.UNIQUE;
     }
 
 
+//    public String checkUserNameUnique(SysUser user)
+//    {
+//        Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
+//        SysUser info = userMapper.checkUserNameUnique(user.getUserName());
+//        if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue())
+//        {
+//            return UserConstants.NOT_UNIQUE;
+//        }
+//        return UserConstants.UNIQUE;
+//    }
+
 }

+ 30 - 0
ruoyi-post/src/main/java/com/ruoyi/post/service/impl/PostNewsServiceImpl.java

@@ -1,7 +1,10 @@
 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.PostNews;
 import com.ruoyi.post.mapper.PostNewsMapper;
 import com.ruoyi.post.service.IPostNewsService;
@@ -94,4 +97,31 @@ public class PostNewsServiceImpl implements IPostNewsService
     {
         return postNewsMapper.deletePostNewsByNewsId(newsId);
     }
+
+    @Override
+    public PostNews selectViewDetail(Integer newsId) {
+        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())
+        {
+            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())
+        {
+            return UserConstants.NOT_UNIQUE;
+        }
+        return UserConstants.UNIQUE;
+    }
 }

+ 22 - 4
ruoyi-post/src/main/resources/mapper/PostBulletinMapper.xml

@@ -115,12 +115,30 @@
     <select id="checkTitleAndContentIsExit" resultType="PostBulletin" resultMap="PostBulletinResult">
         <include refid="selectPostBulletinVo"></include>
         <where>
-<!--            <if test="@Ognl@isNotEmpty(noticeTitle)">and notice_title like concat('%', #{noticeTitle}, '%')</if>-->
-            <if test="noticeTitle!= null and noticeTitle!=''">and notice_title like concat('%', #{noticeTitle}, '%')</if>
-            <if test="noticeContent!= null and noticeContent!=''">and notice_content like concat('%', #{noticeContent}, '%')</if>
+            <!--            <if test="@Ognl@isNotEmpty(noticeTitle)">and notice_title like concat('%', #{noticeTitle}, '%')</if>-->
+            <if test="noticeTitle!= null and noticeTitle!=''">and notice_title like concat('%', #{noticeTitle}, '%')
+            </if>
+            <if test="noticeContent!= null and noticeContent!=''">and notice_content like concat('%', #{noticeContent},
+                '%')
+            </if>
         </where>
     </select>
+    <!--    查看详情-->
     <select id="selectViewDetails" parameterType="Integer" resultMap="PostBulletinResult">
-        select notice_title,create_time,notice_content from post_bulletin where notice_id = #{noticeId}
+        select notice_title, create_time, notice_content
+        from post_bulletin
+        where notice_id = #{noticeId}
+    </select>
+    <!--     检验内容是否唯一-->
+    <select id="checkContentUnique" parameterType="String" resultMap="PostBulletinResult">
+        select notice_id, notice_content
+        from post_bulletin
+        where notice_content = #{noticeContent} limit 1
+    </select>
+    <!--    检验标题是否唯一-->
+    <select id="checkTitleUnique" parameterType="String" resultMap="PostBulletinResult">
+        select notice_id, notice_title
+        from post_bulletin
+        where notice_title = #{noticeTitle} limit 1
     </select>
 </mapper>

+ 12 - 0
ruoyi-post/src/main/resources/mapper/PostNewsMapper.xml

@@ -99,4 +99,16 @@
             #{newsId}
         </foreach>
     </delete>
+
+    <select id="selectViewDetails" parameterType="Integer" resultMap="PostNewsResult">
+        select news_title,create_time,news_content from post_news where news_id = #{newsId}
+    </select>
+
+    <select id="checkContentUnique" parameterType="String" resultMap="PostNewsResult">
+        select news_id, news_content from post_news where news_content = #{newsContent} limit 1
+    </select>
+
+    <select id="checkTitleUnique" parameterType="String" resultMap="PostNewsResult">
+        select news_id, news_title from post_news where news_title = #{newsTitle} limit 1
+    </select>
 </mapper>