From e0ff6529b4364fdbf81d25f33e881118b147b3fa Mon Sep 17 00:00:00 2001
From: zf <1603559716@qq.com>
Date: Mon, 31 Jul 2023 13:04:41 +0800
Subject: [PATCH] bug修改
---
src/main/java/com/gk/hotwork/Controller/AttachmentController.java | 223 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 223 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/gk/hotwork/Controller/AttachmentController.java b/src/main/java/com/gk/hotwork/Controller/AttachmentController.java
new file mode 100644
index 0000000..e61c642
--- /dev/null
+++ b/src/main/java/com/gk/hotwork/Controller/AttachmentController.java
@@ -0,0 +1,223 @@
+package com.gk.hotwork.Controller;
+import com.gk.hotwork.Controller.Base.BaseController;
+import com.gk.hotwork.Domain.AttachmentInfo;
+import com.gk.hotwork.Domain.Utils.Msg;
+import com.gk.hotwork.Service.AttachmentService;
+
+import com.gk.hotwork.common.FileProjectConstants;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+
+/**
+ * @email 1603559716@qq.com
+ * @author: zf
+ * @date: 2023/5/6
+ * @time: 14:22
+ */
+@Api(tags = "附件上传接口")
+@RestController
+@RequestMapping("/attachment")
+public class AttachmentController extends BaseController {
+
+ @Autowired
+ private AttachmentService attachmentService;
+
+
+ /**
+ * 根据标识查询文件具体信息
+ * @param key
+ * @return
+ */
+ @ApiOperation(value = "根据标识查询文件具体信息",response = Msg.class)
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "key",value = "文件标识")
+ })
+ @GetMapping("/get/key/{key}")
+ public Msg findByKey(@PathVariable String key) {
+ Msg msg = new Msg();
+ msg.setCode("200");
+ msg.setMessage("查询成功");
+ AttachmentInfo byKey = attachmentService.findByKey(key);
+ msg.setResult(byKey);
+ return msg;
+ }
+
+ /**
+ * 根据id获取文件
+ * @param id
+ * @return
+ */
+ @ApiOperation(value = "根据id获取文件",response = Msg.class)
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "id",value = "文件id")
+ })
+ @GetMapping("/get/id/{id}")
+ public Msg get(@PathVariable Long id) {
+ Msg msg = new Msg();
+ msg.setCode("200");
+ msg.setMessage("查询成功");
+ AttachmentInfo byKey = attachmentService.findById(id);
+ msg.setResult(byKey);
+ return msg;
+ }
+
+ /**
+ * 删除文件数据
+ * @param id
+ * @return
+ */
+ @ApiOperation(value = "删除文件数据",response = Msg.class)
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "id",value = "文件id")
+ })
+ @GetMapping("/delete/{id}")
+ public Msg delete(@PathVariable Long id) {
+ Msg msg = new Msg();
+ msg.setCode("200");
+ msg.setMessage("删除成功");
+ attachmentService.delete(id,getUser());
+ return msg;
+
+ }
+
+ /**
+ * 单个文件上传
+ * @Description 上传文件(返回文件标识)
+ * @Param [file, module]
+ **/
+ @ApiOperation(value = "上传文件(返回文件标识)-单个文件",response = Msg.class)
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "file",value = "文件"),
+ @ApiImplicitParam(name = "module",value = "checkPath")
+ })
+ @PostMapping("/upload/key")
+ public Msg uploadReturnKey(@RequestParam("file") MultipartFile
+ file, @RequestParam("module") String module) {
+ Msg msg = new Msg();
+ msg.setCode("200");
+ msg.setMessage("上传成功");
+ Object returnStr = attachmentService.saveFileToPath(file, module, FileProjectConstants.ReturnType.KEY,getUser());
+ msg.setResult(returnStr);
+ return msg;
+ }
+
+ /**
+ * 单个文件
+ * @Description 上传文件(返回文件信息)
+ * @Param [file, module]
+ **/
+ @ApiOperation(value = "上传文件(返回文件信息)-单个文件",response = Msg.class)
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "file",value = "文件"),
+ @ApiImplicitParam(name = "module",value = "模块(checkPath)")
+ })
+ @PostMapping("/upload/detail")
+ public Msg uploadReturnDetail(@RequestParam("file") MultipartFile
+ file, @RequestParam("module") String module) {
+ Msg msg = new Msg();
+ msg.setCode("200");
+ msg.setMessage("上传成功");
+ Object detail = attachmentService.saveFileToPath(file, module, FileProjectConstants.ReturnType.DETAIL,getUser());
+ msg.setResult(detail);
+ return msg;
+ }
+ /**
+ * 单个文件
+ * @Description 上传文件(返回访问路径)
+ * @Date 2021/4/20 19:28
+ * @Param [file, module]
+ **/
+ @ApiOperation(value = "上传文件(返回访问路径)-单个文件",response = Msg.class)
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "file",value = "文件"),
+ @ApiImplicitParam(name = "module",value = "模块(checkPath)")
+ })
+ @PostMapping("/upload/url")
+ public Msg uploadReturnUrl(@RequestParam("file") MultipartFile file, @RequestParam("module") String module) {
+ Msg msg = new Msg();
+ msg.setCode("200");
+ msg.setMessage("上传成功");
+ Object returnStr = attachmentService.saveFileToPath(file, module, FileProjectConstants.ReturnType.URL,getUser());
+ msg.setResult(returnStr);
+ return msg;
+ }
+
+ /**
+ * 批量文件
+ * @Description 上传文件(返回文件信息)
+ * @Param [file, module]
+ **/
+ @ApiOperation(value = "上传文件(返回访问路径)-批量",response = Msg.class)
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "file",value = "文件"),
+ @ApiImplicitParam(name = "module",value = "模块(checkPath)")
+ })
+ @PostMapping("/upload/batch/detail")
+ public Msg uploadBatchReturnDetail(@RequestParam("file") MultipartFile[]
+ file, @RequestParam("module") String module) {
+ Msg msg = new Msg();
+ msg.setCode("200");
+ msg.setMessage("上传成功");
+ Object detail = attachmentService.saveBatchFileToPath(file, module,getUser());
+ msg.setResult(detail);
+ return msg;
+ }
+
+ /**
+ * @return org.springframework.http.ResponseEntity<byte [ ]>
+ * @Description 获取下载文件流
+ * @Param [key]
+ **/
+ @ApiOperation(value = "获取下载文件流",response = Msg.class)
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "key",value = "文件标识"),
+ })
+ @GetMapping("/downloadFile/{key}")
+ public void download(@PathVariable String key, HttpServletResponse response) {
+ attachmentService.downloadForStream(response, key);
+ }
+
+ /**
+ * @return void
+ * @Description 文件下载
+ * @Param [key, response, request]
+ **/
+ @ApiOperation(value = "文件下载",response = Msg.class)
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "id",value = "文件id"),
+ })
+ @RequestMapping(value = "/downloadFileById/{id}", method = {RequestMethod.POST, RequestMethod.GET})
+ public void downloadFileByKey(@PathVariable Long id, HttpServletResponse response, HttpServletRequest
+ request) {
+ attachmentService.downloadById(response, request, id);
+ }
+
+ /**
+ * @Description 获取下载文件路径
+ * @Param [key]
+ **/
+ @ApiOperation(value = "获取下载文件路径",response = Msg.class)
+ @ApiImplicitParams({
+ @ApiImplicitParam(name = "key",value = "文件key"),
+ })
+ @GetMapping("/downloadUrl/{key}")
+ public Msg downLoad( @PathVariable String key) {
+ Msg msg = new Msg();
+ msg.setCode("200");
+ msg.setMessage("查询成功");
+ AttachmentInfo byKey = attachmentService.findByKey(key);
+ msg.setResult(byKey);
+ return msg;
+ }
+
+
+}
--
Gitblit v1.9.2