Browse Source

搜索完善

chenzhengming 2 years ago
parent
commit
62077f1152

+ 166 - 166
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java

@@ -1,166 +1,166 @@
-package com.ruoyi.web.controller.common;
-
-import java.util.ArrayList;
-import java.util.List;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.MediaType;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.multipart.MultipartFile;
-import com.ruoyi.common.config.RuoYiConfig;
-import com.ruoyi.common.constant.Constants;
-import com.ruoyi.common.core.domain.AjaxResult;
-import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.common.utils.file.FileUploadUtils;
-import com.ruoyi.common.utils.file.FileUtils;
-import com.ruoyi.framework.config.ServerConfig;
-
-/**
- * 通用请求处理
- * 
- * @author ruoyi
- */
-@RestController
-@RequestMapping("/common")
-public class CommonController
-{
-    private static final Logger log = LoggerFactory.getLogger(CommonController.class);
-
-    @Autowired
-    private ServerConfig serverConfig;
-
-    private static final String FILE_DELIMETER = ",";
-
-    /**
-     * 通用下载请求
-     * 
-     * @param fileName 文件名称
-     * @param delete 是否删除
-     */
-    @GetMapping("/download")
-    public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
-    {
-        try
-        {
-            if (!FileUtils.checkAllowDownload(fileName))
-            {
-                throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
-            }
-            String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
-            String filePath = RuoYiConfig.getDownloadPath() + fileName;
-
-            response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
-            FileUtils.setAttachmentResponseHeader(response, realFileName);
-            FileUtils.writeBytes(filePath, response.getOutputStream());
-            if (delete)
-            {
-                FileUtils.deleteFile(filePath);
-            }
-        }
-        catch (Exception e)
-        {
-            log.error("下载文件失败", e);
-        }
-    }
-
-    /**
-     * 通用上传请求(单个)
-     */
-    @PostMapping("/upload")
-    public AjaxResult uploadFile(MultipartFile file) throws Exception
-    {
-        try
-        {
-            // 上传文件路径
-            String filePath = RuoYiConfig.getUploadPath();
-            // 上传并返回新文件名称
-            String fileName = FileUploadUtils.upload(filePath, file);
-            String url = serverConfig.getUrl() + fileName;
-            AjaxResult ajax = AjaxResult.success();
-            ajax.put("url", url);
-            ajax.put("fileName", fileName);
-            ajax.put("newFileName", FileUtils.getName(fileName));
-            ajax.put("originalFilename", file.getOriginalFilename());
-            return ajax;
-        }
-        catch (Exception e)
-        {
-            return AjaxResult.error(e.getMessage());
-        }
-    }
-
-    /**
-     * 通用上传请求(多个)
-     */
-    @PostMapping("/uploads")
-    public AjaxResult uploadFiles(List<MultipartFile> files) throws Exception
-    {
-        try
-        {
-            // 上传文件路径
-            String filePath = RuoYiConfig.getUploadPath();
-            List<String> urls = new ArrayList<String>();
-            List<String> fileNames = new ArrayList<String>();
-            List<String> newFileNames = new ArrayList<String>();
-            List<String> originalFilenames = new ArrayList<String>();
-            for (MultipartFile file : files)
-            {
-                // 上传并返回新文件名称
-                String fileName = FileUploadUtils.upload(filePath, file);
-                String url = serverConfig.getUrl() + fileName;
-                urls.add(url);
-                fileNames.add(fileName);
-                newFileNames.add(FileUtils.getName(fileName));
-                originalFilenames.add(file.getOriginalFilename());
-            }
-            AjaxResult ajax = AjaxResult.success();
-            ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER));
-            ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER));
-            ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER));
-            ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));
-            return ajax;
-        }
-        catch (Exception e)
-        {
-            return AjaxResult.error(e.getMessage());
-        }
-    }
-
-    /**
-     * 本地资源通用下载
-     */
-    @GetMapping("/download/resource")
-    public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response)
-            throws Exception
-    {
-        try
-        {
-            if (!FileUtils.checkAllowDownload(resource))
-            {
-                throw new Exception(StringUtils.format("资源文件({})非法,不允许下载。 ", resource));
-            }
-            // 本地资源路径
-            String localPath = RuoYiConfig.getProfile();
-            // 数据库资源地址
-            String downloadPath = localPath + StringUtils.substringAfter(resource, Constants.RESOURCE_PREFIX);
-            // 下载名称
-            String downloadName = StringUtils.substringAfterLast(downloadPath, "/");
-            response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
-            FileUtils.setAttachmentResponseHeader(response, downloadName);
-            FileUtils.writeBytes(downloadPath, response.getOutputStream());
-        }
-        catch (Exception e)
-        {
-            log.error("下载文件失败", e);
-        }
-    }
-}
+package com.ruoyi.web.controller.common;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+import com.ruoyi.common.config.RuoYiConfig;
+import com.ruoyi.common.constant.Constants;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.file.FileUploadUtils;
+import com.ruoyi.common.utils.file.FileUtils;
+import com.ruoyi.framework.config.ServerConfig;
+
+/**
+ * 通用请求处理
+ * 
+ * @author ruoyi
+ */
+@RestController
+@RequestMapping("/common")
+public class CommonController
+{
+    private static final Logger log = LoggerFactory.getLogger(CommonController.class);
+
+    @Autowired
+    private ServerConfig serverConfig;
+
+    private static final String FILE_DELIMETER = ",";
+
+    /**
+     * 通用下载请求
+     * 
+     * @param fileName 文件名称
+     * @param delete 是否删除
+     */
+    @GetMapping("/download")
+    public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
+    {
+        try
+        {
+            if (!FileUtils.checkAllowDownload(fileName))
+            {
+                throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
+            }
+            String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
+            String filePath = RuoYiConfig.getDownloadPath() + fileName;
+
+            response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
+            FileUtils.setAttachmentResponseHeader(response, realFileName);
+            FileUtils.writeBytes(filePath, response.getOutputStream());
+            if (delete)
+            {
+                FileUtils.deleteFile(filePath);
+            }
+        }
+        catch (Exception e)
+        {
+            log.error("下载文件失败", e);
+        }
+    }
+
+    /**
+     * 通用上传请求(单个)
+     */
+    @PostMapping("/upload")
+    public AjaxResult uploadFile(MultipartFile file) throws Exception
+    {
+        try
+        {
+            // 上传文件路径
+            String filePath = RuoYiConfig.getUploadPath();
+            // 上传并返回新文件名称
+            String fileName = FileUploadUtils.upload(filePath, file);
+            String url = serverConfig.getUrl() + fileName;
+            AjaxResult ajax = AjaxResult.success();
+            ajax.put("url", url);
+            ajax.put("fileName", fileName);
+            ajax.put("newFileName", FileUtils.getName(fileName));
+            ajax.put("originalFilename", file.getOriginalFilename());
+            return ajax;
+        }
+        catch (Exception e)
+        {
+            return AjaxResult.error(e.getMessage());
+        }
+    }
+
+    /**
+     * 通用上传请求(多个)
+     */
+    @PostMapping("/uploads")
+    public AjaxResult uploadFiles(List<MultipartFile> files) throws Exception
+    {
+        try
+        {
+            // 上传文件路径
+            String filePath = RuoYiConfig.getUploadPath();
+            List<String> urls = new ArrayList<String>();
+            List<String> fileNames = new ArrayList<String>();
+            List<String> newFileNames = new ArrayList<String>();
+            List<String> originalFilenames = new ArrayList<String>();
+            for (MultipartFile file : files)
+            {
+                // 上传并返回新文件名称
+                String fileName = FileUploadUtils.upload(filePath, file);
+                String url = serverConfig.getUrl() + fileName;
+                urls.add(url);
+                fileNames.add(fileName);
+                newFileNames.add(FileUtils.getName(fileName));
+                originalFilenames.add(file.getOriginalFilename());
+            }
+            AjaxResult ajax = AjaxResult.success();
+            ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER));
+            ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER));
+            ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER));
+            ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));
+            return ajax;
+        }
+        catch (Exception e)
+        {
+            return AjaxResult.error(e.getMessage());
+        }
+    }
+
+    /**
+     * 本地资源通用下载
+     */
+    @GetMapping("/download/resource")
+    public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response)
+            throws Exception
+    {
+        try
+        {
+            if (!FileUtils.checkAllowDownload(resource))
+            {
+                throw new Exception(StringUtils.format("资源文件({})非法,不允许下载。 ", resource));
+            }
+            // 本地资源路径
+            String localPath = RuoYiConfig.getProfile();
+            // 数据库资源地址
+            String downloadPath = localPath + StringUtils.substringAfter(resource, Constants.RESOURCE_PREFIX);
+            // 下载名称
+            String downloadName = StringUtils.substringAfterLast(downloadPath, "/");
+            response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
+            FileUtils.setAttachmentResponseHeader(response, downloadName);
+            FileUtils.writeBytes(downloadPath, response.getOutputStream());
+        }
+        catch (Exception e)
+        {
+            log.error("下载文件失败", e);
+        }
+    }
+}

+ 19 - 8
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/LcdInfoController.java

@@ -1,6 +1,7 @@
 package com.ruoyi.web.controller.system;
 
 
+import java.util.Date;
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
 
@@ -8,14 +9,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 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;
@@ -112,4 +106,21 @@ public class LcdInfoController extends BaseController
     {
         return toAjax(lcdInfoService.deleteLcdInfoByIds(ids));
     }
+    /**
+     * 搜索消息列表.
+     * @param title
+     * @param lcdTimeLeft
+     * @param lcdTimeRight
+     * @return
+     */
+    @ApiOperation("搜索消息列表")
+    @PreAuthorize("@ss.hasPermi('system:lcd:querylcd')")
+    @GetMapping("/queryLcd")
+    public AjaxResult list(@RequestParam(value="title",required = false)String title,
+                              @RequestParam(value="lcdTimeLeft",required = false) Date lcdTimeLeft,
+                              @RequestParam(value="lcdTimeRight",required = false) Date lcdTimeRight)
+    {
+        List<LcdInfo> list= lcdInfoService.selectList(title,lcdTimeLeft,lcdTimeRight);
+        return success(list);
+    }
 }

+ 3 - 1
ruoyi-admin/src/main/resources/application-druid.yml

@@ -54,4 +54,6 @@ spring:
                     merge-sql: true
                 wall:
                     config:
-                        multi-statement-allow: true
+                        multi-statement-allow: true
+post:
+    path: D:\img\

+ 6 - 0
ruoyi-system/pom.xml

@@ -22,6 +22,12 @@
             <groupId>com.ruoyi</groupId>
             <artifactId>ruoyi-common</artifactId>
         </dependency>
+        <dependency>
+            <groupId>io.swagger</groupId>
+            <artifactId>swagger-annotations</artifactId>
+            <version>1.6.2</version>
+            <scope>compile</scope>
+        </dependency>
 
     </dependencies>
 

+ 13 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/LcdInfoMapper.java

@@ -1,7 +1,9 @@
 package com.ruoyi.system.mapper;
 
+import java.util.Date;
 import java.util.List;
 import com.ruoyi.system.domain.LcdInfo;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * 消息Mapper接口
@@ -58,4 +60,15 @@ public interface LcdInfoMapper
      * @return 结果
      */
     public int deleteLcdInfoByIds(Long[] ids);
+
+    /**
+     * 搜索消息列表.
+     * @param title
+     * @param lcdTimeLeft
+     * @param lcdTimeRight
+     * @return
+     */
+    List<LcdInfo> selectLcdListByTitleOrlcdTime(@Param("title")String title,
+                                                  @Param("lcdTimeLeft")Date lcdTimeLeft,
+                                                  @Param("lcdTimeRight")Date lcdTimeRight);
 }

+ 9 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/ILcdInfoService.java

@@ -1,5 +1,6 @@
 package com.ruoyi.system.service;
 
+import java.util.Date;
 import java.util.List;
 import com.ruoyi.system.domain.LcdInfo;
 
@@ -58,4 +59,12 @@ public interface ILcdInfoService
      * @return 结果
      */
     public int deleteLcdInfoById(Long id);
+    /**
+     * 搜索消息列表.
+     * @param title
+     * @param lcdTimeLeft
+     * @param lcdTimeRight
+     * @return 结果
+     */
+    List<LcdInfo> selectList(String title, Date lcdTimeLeft, Date lcdTimeRight);
 }

+ 45 - 14
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/LcdInfoServiceImpl.java

@@ -1,5 +1,7 @@
 package com.ruoyi.system.service.impl;
 
+import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import com.ruoyi.common.utils.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -15,8 +17,7 @@ import com.ruoyi.system.service.ILcdInfoService;
  * @date 2023-01-14
  */
 @Service
-public class LcdInfoServiceImpl implements ILcdInfoService
-{
+public class LcdInfoServiceImpl implements ILcdInfoService {
     @Autowired
     private LcdInfoMapper lcdInfoMapper;
 
@@ -27,8 +28,7 @@ public class LcdInfoServiceImpl implements ILcdInfoService
      * @return 消息
      */
     @Override
-    public LcdInfo selectLcdInfoById(Long id)
-    {
+    public LcdInfo selectLcdInfoById(Long id) {
         return lcdInfoMapper.selectLcdInfoById(id);
     }
 
@@ -39,8 +39,7 @@ public class LcdInfoServiceImpl implements ILcdInfoService
      * @return 消息
      */
     @Override
-    public List<LcdInfo> selectLcdInfoList(LcdInfo lcdInfo)
-    {
+    public List<LcdInfo> selectLcdInfoList(LcdInfo lcdInfo) {
         return lcdInfoMapper.selectLcdInfoList(lcdInfo);
     }
 
@@ -51,8 +50,7 @@ public class LcdInfoServiceImpl implements ILcdInfoService
      * @return 结果
      */
     @Override
-    public int insertLcdInfo(LcdInfo lcdInfo)
-    {
+    public int insertLcdInfo(LcdInfo lcdInfo) {
         lcdInfo.setCreateTime(DateUtils.getNowDate());
         return lcdInfoMapper.insertLcdInfo(lcdInfo);
     }
@@ -64,8 +62,7 @@ public class LcdInfoServiceImpl implements ILcdInfoService
      * @return 结果
      */
     @Override
-    public int updateLcdInfo(LcdInfo lcdInfo)
-    {
+    public int updateLcdInfo(LcdInfo lcdInfo) {
         lcdInfo.setUpdateTime(DateUtils.getNowDate());
         return lcdInfoMapper.updateLcdInfo(lcdInfo);
     }
@@ -77,8 +74,7 @@ public class LcdInfoServiceImpl implements ILcdInfoService
      * @return 结果
      */
     @Override
-    public int deleteLcdInfoByIds(Long[] ids)
-    {
+    public int deleteLcdInfoByIds(Long[] ids) {
         return lcdInfoMapper.deleteLcdInfoByIds(ids);
     }
 
@@ -89,8 +85,43 @@ public class LcdInfoServiceImpl implements ILcdInfoService
      * @return 结果
      */
     @Override
-    public int deleteLcdInfoById(Long id)
-    {
+    public int deleteLcdInfoById(Long id) {
         return lcdInfoMapper.deleteLcdInfoById(id);
     }
+
+    /**
+     * 搜索消息列表.
+     *
+     * @param title
+     * @param lcdTimeLeft
+     * @param lcdTimeRight
+     * @return 结果
+     */
+    @Override
+    public List<LcdInfo> selectList(String title, Date lcdTimeLeft, Date lcdTimeRight) {
+        if (title != null) {
+            //标题不为空则判断时间
+            if (lcdTimeLeft != null && lcdTimeRight != null) {
+                //时间不为空 ,且左时间在右时间之前
+                if (lcdTimeLeft.before(lcdTimeRight)) {
+                    return lcdInfoMapper.selectLcdListByTitleOrlcdTime(title, lcdTimeLeft, lcdTimeRight);
+                } else {
+                    List list = new ArrayList<>();
+                    list.add("时间顺序错误");
+                    return list;
+                }
+            } else {
+                //时间为空
+                return lcdInfoMapper.selectLcdListByTitleOrlcdTime(title, null, null);
+            }
+        } else {
+            //标题为空
+            if (lcdTimeLeft != null && lcdTimeRight != null && lcdTimeLeft.before(lcdTimeRight)) {
+                //时间不为空
+                return lcdInfoMapper.selectLcdListByTitleOrlcdTime(null, lcdTimeLeft, lcdTimeRight);
+            }
+        }
+        LcdInfo lcdInfo = new LcdInfo();
+        return lcdInfoMapper.selectLcdInfoList(lcdInfo);
+    }
 }

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

@@ -95,7 +95,8 @@ public class PostNoticeServiceImpl implements IPostNoticeService
                 return postNoticeMapper.selectPostNoticeListOnlyByTitleOrNoticeTime(noticeTimeLeft, noticeTimeRight);
             }
         }
-        return null;
+        PostNotice postNotice = new PostNotice();
+        return postNoticeMapper.selectPostNoticeList(postNotice);
     }
 
 

+ 19 - 0
ruoyi-system/src/main/resources/mapper/system/LcdInfoMapper.xml

@@ -18,6 +18,23 @@
     <sql id="selectLcdInfoVo">
         select id, title, send_time, detail, create_by, create_time, update_by, update_time from lcd_info
     </sql>
+    <!--搜索消息列表,xml中>,
+    <不能被正确解析,需要XML转义字符
+     &gt;是大于
+     &lt;是小于-->
+    <select id="selectLcdListByTitleOrlcdTime" resultType="LcdInfo" resultMap="LcdInfoResult">
+        <include refid="selectLcdInfoVo"/>
+        <where>
+            <if test="title != null  and title != ''"> and title LIKE CONCAT(CONCAT('%',#{title},'%'))</if>
+            <if test="lcdTimeLeft !=null">
+                and send_time &gt;=#{lcdTimeLeft}
+            </if>
+            <if test="lcdTimeRight != null">
+                and send_time &lt;=#{lcdTimeRight}
+            </if>
+
+        </where>
+    </select>
 
     <select id="selectLcdInfoList" parameterType="LcdInfo" resultMap="LcdInfoResult">
         <include refid="selectLcdInfoVo"/>
@@ -81,4 +98,6 @@
             #{id}
         </foreach>
     </delete>
+
+
 </mapper>