sjx 2 лет назад
Родитель
Сommit
7ff29e6ba2

+ 7 - 38
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/PostNoticeController.java

@@ -10,14 +10,7 @@ import io.swagger.annotations.ApiOperation;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
@@ -53,42 +46,16 @@ public class PostNoticeController extends BaseController
         List<PostNotice> list = postNoticeService.selectPostNoticeList(postNotice);
         return getDataTable(list);
     }
-    /*@ApiOperation("搜索公告")
-    @PreAuthorize("@ss.hasPermi('system:notice:queryNotice')")
-    @GetMapping("/queryNotice")
-    public AjaxResult queryByTitleOrTime(String noticeTitle, Date noticeTimeLeft,Date noticeTimeRight){
-        if(noticeTitle!=null){
-            if(noticeTimeLeft!=null&&noticeTimeRight!=null) {
-                List<PostNotice> list = postNoticeService.selectPostNoticeListByTitleOrNoticeTime(noticeTitle, noticeTimeLeft,noticeTimeRight);
-                return success(list);
-            }
-            return error("请输入完整时间范围");
-        }
-        return error("未找到相应数据");
-    }*/
 
     @ApiOperation("搜索公告列表")
     @PreAuthorize("@ss.hasPermi('system:notice:queryNotice')")
     @GetMapping("/queryNotice")
-    public TableDataInfo list(PostNotice postNotice, String title, Date noticeTimeLeft, Date noticeTimeRight)
+    public TableDataInfo list(@RequestParam(value="title",required = false)String title,
+                              @RequestParam(value="noticeTimeLeft",required = false) Date noticeTimeLeft,
+                              @RequestParam(value="noticeTimeRight",required = false) Date noticeTimeRight)
     {
         startPage();
-        List<PostNotice> list=null;
-        if(title!=null){
-            //标题不为空则判断时间
-            if(noticeTimeLeft!=null&&noticeTimeRight!=null&&noticeTimeLeft.before(noticeTimeRight)) {
-                //时间不为空
-                list = postNoticeService.selectPostNoticeListByTitleOrNoticeTime(title, noticeTimeLeft,noticeTimeRight);
-            }
-        }else{
-            //标题为空
-            if(noticeTimeLeft!=null&&noticeTimeRight!=null&&noticeTimeLeft.before(noticeTimeRight)) {
-                //时间不为空
-                //list = postNoticeService.selectPostNoticeListOnlyByTitleOrNoticeTime(noticeTimeLeft,noticeTimeRight);
-            }else {
-                list = postNoticeService.selectPostNoticeList(postNotice);
-            }
-        }
+        List<PostNotice> list= postNoticeService.selectList(title,noticeTimeLeft,noticeTimeRight);
         return getDataTable(list);
     }
 
@@ -163,4 +130,6 @@ public class PostNoticeController extends BaseController
     {
         return toAjax(postNoticeService.deletePostNoticeByNoticeIds(noticeIds));
     }
+
+
 }

+ 4 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/PostNoticeMapper.java

@@ -71,4 +71,8 @@ public interface PostNoticeMapper
     public int deletePostNoticeByNoticeIds(Long[] noticeIds);
 
     public List<PostNotice> selectPostNoticeListByTitleOrNoticeTime(@Param("noticeTitle")String noticeTitle, @Param("noticeTimeLeft")Date noticeTimeLeft, @Param("noticeTimeRight")Date noticeTimeRight);
+
+    public List<PostNotice> selectPostNoticeListOnlyByTitleOrNoticeTime( @Param("noticeTimeLeft")Date noticeTimeLeft, @Param("noticeTimeRight")Date noticeTimeRight);
+
+    List<PostNotice> selectPostNoticeListByTitle(@Param("noticeTitle")String title);
 }

+ 2 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/IPostNoticeService.java

@@ -69,6 +69,7 @@ public interface IPostNoticeService
      */
     public String selectDetailByNoticeId(Long noticeId);
 
+    public List<PostNotice> selectList(String title, Date noticeTimeLeft, Date noticeTimeRight);
+
 
-    public List<PostNotice> selectPostNoticeListByTitleOrNoticeTime(String noticeTitle, Date noticeTimeLeft,Date noticeTimeRight);
 }

+ 35 - 9
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PostNoticeServiceImpl.java

@@ -54,18 +54,44 @@ public class PostNoticeServiceImpl implements IPostNoticeService
     }
 
 
-    /**
-     * 搜素
-     * @param noticeTitle
-     * @param noticeTimeLeft
-     * @param noticeTimeRight
-     * @return
-     */
+//    /**
+//     * 搜素
+//     * @param title
+//     * @param noticeTimeLeft
+//     * @param noticeTimeRight
+//     * @return
+//     */
+//    @Override
+//    public List<PostNotice> selectPostNoticeListByTitleOrNoticeTime(String title, Date noticeTimeLeft, Date noticeTimeRight) {
+//        return postNoticeMapper.selectPostNoticeListByTitleOrNoticeTime(title,noticeTimeLeft,noticeTimeRight);
+//    }
+
     @Override
-    public List<PostNotice> selectPostNoticeListByTitleOrNoticeTime(String noticeTitle, Date noticeTimeLeft, Date noticeTimeRight) {
-        return postNoticeMapper.selectPostNoticeListByTitleOrNoticeTime(noticeTitle,noticeTimeLeft,noticeTimeRight);
+    public List<PostNotice> selectList(String title, Date noticeTimeLeft, Date noticeTimeRight) {
+        if (title != null) {
+            //标题不为空则判断时间
+            if (noticeTimeLeft != null && noticeTimeRight != null) {
+                //时间不为空 ,且左时间在右时间之前
+                if( noticeTimeLeft.before(noticeTimeRight)) {
+                    return postNoticeMapper.selectPostNoticeListByTitleOrNoticeTime(title, noticeTimeLeft, noticeTimeRight);
+                }else {
+                    return null;
+                }
+            }else {
+                //时间为空
+                return postNoticeMapper.selectPostNoticeListByTitle(title);
+            }
+        } else {
+            //标题为空
+            if (noticeTimeLeft != null && noticeTimeRight != null && noticeTimeLeft.before(noticeTimeRight)) {
+                //时间不为空
+                return postNoticeMapper.selectPostNoticeListOnlyByTitleOrNoticeTime(noticeTimeLeft, noticeTimeRight);
+            }
+        }
+        return null;
     }
 
+
     /**
      * 新增公告
      *

+ 16 - 3
ruoyi-system/src/main/resources/mapper/system/PostNoticeMapper.xml

@@ -23,7 +23,6 @@
         <include refid="selectPostNoticeVo"/>
         <where>
             <if test="noticeTitle != null  and noticeTitle != ''"> and notice_title = #{noticeTitle}</if>
-            <if test="noticeTime != null "> and notice_time like "%str%"</if>
             <if test="detailDetail != null  and detailDetail != ''"> and detail_detail = #{detailDetail}</if>
         </where>
     </select>
@@ -31,8 +30,22 @@
     <select id="selectPostNoticeListByTitleOrNoticeTime" resultType="PostNotice" resultMap="PostNoticeResult">
         <include refid="selectPostNoticeVo"/>
         <where>
-            <if test="noticeTitle != null  and noticeTitle != ''"> and notice_title = #{title}</if>
-            <if test="noticeTime != null "> and notice_time between #{noticeTimeLeft} AND #{noticeTimeRight}</if>
+            <if test="noticeTitle != null  and noticeTitle != ''"> and notice_title LIKE '%${noticeTitle}%'</if>
+            <if test="noticeTimeLeft != null and noticeTimeRight != null "> and notice_time between #{noticeTimeLeft} AND #{noticeTimeRight}</if>
+        </where>
+    </select>
+
+    <select id="selectPostNoticeListOnlyByTitleOrNoticeTime" resultType="PostNotice" resultMap="PostNoticeResult">
+        <include refid="selectPostNoticeVo"/>
+        <where>
+            <if test="noticeTimeLeft != null and noticeTimeRight != null "> and notice_time between #{noticeTimeLeft} AND #{noticeTimeRight}</if>
+        </where>
+    </select>
+
+    <select id="selectPostNoticeListByTitle" resultType="PostNotice" resultMap="PostNoticeResult">
+        <include refid="selectPostNoticeVo"/>
+        <where>
+            <if test="noticeTitle != null  and noticeTitle != ''"> and notice_title LIKE '%${noticeTitle}%'</if>
         </where>
     </select>