فهرست منبع

文件上传下载

zhangyang 2 سال پیش
والد
کامیت
8048c62b5f

+ 51 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/UploadAndDownloadController.java

@@ -0,0 +1,51 @@
+package com.ruoyi.web.controller.system;
+
+import com.ruoyi.common.config.RuoYiConfig;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.file.FileUploadUtils;
+import com.ruoyi.framework.config.ServerConfig;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestPart;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+@RestController
+@RequestMapping("/file")
+public class UploadAndDownloadController {
+    @Autowired
+    private ServerConfig serverConfig;
+
+    /**
+     * 上传文件
+     */
+    /**
+     * 文件上传接口
+     */
+    @ApiOperation(value = "上传文件", notes = "上传文件接口")
+    @RequestMapping(value = "/upload", method = RequestMethod.POST, headers = "content-type=multipart/form-data")
+    public AjaxResult uploadFile(@RequestPart("file") MultipartFile file) throws Exception
+    {
+        try {
+            // 上传文件路径
+            String filePath = RuoYiConfig.getUploadPath();
+            if (filePath == null){
+                throw new RuntimeException("文件路径不存在");
+            }
+            //上传并返回文件名
+            String filename = FileUploadUtils.upload(filePath, file);
+            if (filename == null){
+                throw new RuntimeException("文件名称不存在");
+            }
+            String url = serverConfig.getUrl()+filename;
+            AjaxResult ajax = AjaxResult.success();
+            ajax.put("fileName",filename);
+            ajax.put("url",url);
+            return ajax;
+        }catch (Exception e){
+            return AjaxResult.error(e.getMessage());
+        }
+    }
+}

+ 3 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/core/config/SwaggerConfig.java

@@ -58,8 +58,9 @@ public class SwaggerConfig
                 // 扫描所有有注解的api,用这种方式更灵活
                 .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                 // 扫描指定包中的swagger注解
-                // .apis(RequestHandlerSelectors.basePackage("com.ruoyi.project.tool.swagger"))
-                // 扫描所有 .apis(RequestHandlerSelectors.any())
+                .apis(RequestHandlerSelectors.basePackage("com.ruoyi.web.controller"))
+                // 扫描所有
+                .apis(RequestHandlerSelectors.any())
                 .paths(PathSelectors.any())
                 .build()
                 /* 设置安全模式,swagger可以设置访问token */

+ 3 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PoNewsServiceImpl.java

@@ -149,6 +149,9 @@ public class PoNewsServiceImpl implements IPoNewsService {
             //标题不为空且开始时间和结束时间都不为空
             if (newsTimeStart != null && newsTimeEnd != null) {
 
+                if (DateUtils.getNowDate().before(newsTimeEnd)){
+                    newsTimeEnd = DateUtils.getNowDate();
+                }
                 if (newsTimeStart.before(newsTimeEnd)) {
                     return poNewsMapper.selectPoNewsListByTitleAndNewsTimeStartAndNewsTimeEnd(title, newsTimeStart, newsTimeEnd);
                 } else if ((newsTimeStart != null && newsTimeEnd == null) || (newsTimeStart == null && newsTimeEnd != null)) {

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

@@ -40,6 +40,7 @@
             <if test="image != null and image != ''">and image = #{image}</if>
             <if test="newsTime != null ">and news_time = #{newsTime}</if>
             <if test="phonenumber != null ">and phonenumber = #{phonenumber}</if>
+            where news_time &lt; now()
         </where>
     </select>