Browse Source

搜索函数完善

sjx 2 years ago
parent
commit
42f9c2c9cc

+ 0 - 2
ruoyi-system/src/main/java/com/ruoyi/system/domain/PostNotice.java

@@ -27,8 +27,6 @@ public class PostNotice extends BaseEntity
     /** 公告标题 */
     @Excel(name = "公告标题")
     @Xss(message = "公告标题不能包含脚本字符")
-    @NotBlank(message = "公告标题不能为空")
-    @Size(min = 0, max = 20, message = "公告标题不能超过20个字符")
     private String noticeTitle;
 
     /** 发布时间 */

+ 8 - 12
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PostNoticeServiceImpl.java

@@ -54,18 +54,6 @@ public class PostNoticeServiceImpl implements IPostNoticeService
     }
 
 
-//    /**
-//     * 搜素
-//     * @param title
-//     * @param noticeTimeLeft
-//     * @param noticeTimeRight
-//     * @return
-//     */
-//    @Override
-//    public List<PostNotice> selectPostNoticeListByTitleOrNoticeTime(String title, Date noticeTimeLeft, Date noticeTimeRight) {
-//        return postNoticeMapper.selectPostNoticeListByTitleOrNoticeTime(title,noticeTimeLeft,noticeTimeRight);
-//    }
-
     /**
      * 搜索公告列表
      * @param title
@@ -79,6 +67,10 @@ public class PostNoticeServiceImpl implements IPostNoticeService
             //标题不为空则判断时间
             if (noticeTimeLeft != null && noticeTimeRight != null) {
                 //时间不为空 ,且左时间在右时间之前
+                //确保查询到的公告为已发布的公告
+                if (DateUtils.getNowDate().before(noticeTimeRight)){
+                    noticeTimeRight = DateUtils.getNowDate();
+                }
                 if( noticeTimeLeft.before(noticeTimeRight)) {
                     return postNoticeMapper.selectPostNoticeListByTitleOrNoticeTime(title, noticeTimeLeft, noticeTimeRight);
                 }else {
@@ -91,6 +83,10 @@ public class PostNoticeServiceImpl implements IPostNoticeService
             }
         } else {
             //标题为空
+            //确保查询到的公告为已发布的公告
+            if (DateUtils.getNowDate().before(noticeTimeRight)){
+                noticeTimeRight = DateUtils.getNowDate();
+            }
             if (noticeTimeLeft != null && noticeTimeRight != null) {
                 //时间不为空 ,且左时间在右时间之前
                 if( noticeTimeLeft.before(noticeTimeRight)) {

+ 1 - 0
ruoyi-system/src/main/resources/mapper/system/PostNoticeMapper.xml

@@ -24,6 +24,7 @@
         <where>
             <if test="noticeTitle != null  and noticeTitle != ''"> and notice_title = #{noticeTitle}</if>
             <if test="noticeContent != null and noticeContent != ''">and notice_content = #{noticeContent} </if>
+            and notice_time &lt; now()
         </where>
     </select>