ソースを参照

第二版 客户端新增上传图片功能

刘一凡 3 年 前
コミット
633eadd5e9

+ 3 - 0
src/main/java/com/chuanghai/h3c_reporting/common/exception/BizCodeEnume.java

@@ -15,6 +15,9 @@ public enum BizCodeEnume {
     INVALID_PARAM(11001,"参数格式校验失败"),
     BODY_IS_EMPTY(11002, "body为空"),
     PARAMETER_ERROR(11003, "参数异常"),
+    FILE_IS_NULL(11004, "文件为空"),
+    FILE_NOT(11005, "存在不支持的文件后缀名"),
+    FILE_UPDOWN_FAIL(11006, "文件上传失败"),
     DATA_IS_EXIST(16000, "数据已存在"),
     DATA_NOT_EXIST(16000, "数据不存在"),
     WX_EXCEPTION(17000, "微信相关异常");

+ 67 - 0
src/main/java/com/chuanghai/h3c_reporting/controller/FileController.java

@@ -0,0 +1,67 @@
+package com.chuanghai.h3c_reporting.controller;
+
+import com.chuanghai.h3c_reporting.common.exception.BizCodeEnume;
+import com.chuanghai.h3c_reporting.common.exception.RRException;
+import com.chuanghai.h3c_reporting.common.utils.CommonResult;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.beans.factory.annotation.Value;
+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 java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * @author 27951
+ * @version 1.0
+ * @description: TODO 文件处理
+ * @date 2022/7/27 14:30
+ */
+@RestController
+@RequestMapping("/file")
+public class FileController {
+
+    @Value("${file.imgPath}")
+    private String imgPath;
+
+    @Value("${file.imgPathDown}")
+    private String imgPathDown;
+
+    /**
+     * 获取文件路径链接
+     */
+    @PostMapping("/fileUpDown")
+    public CommonResult<String> fileUpDown(@Param("file") MultipartFile file[]) {
+
+        List<MultipartFile> fileList = Arrays.asList(file);
+        List<String> files = new ArrayList<>();
+        fileList.forEach(file1 -> {
+            try {
+                //获取文件名
+                String fileName = file1.getOriginalFilename();
+                //获取文件后缀名。
+                assert fileName != null;
+                String suffixName = fileName.substring(fileName.lastIndexOf("."));
+                //为了避免发生文件替换,这里使用了文件名重新生成
+                fileName = UUID.randomUUID() + suffixName;
+                // 判断文件后缀名,不符合要求的不保存
+                if (suffixName.equals(".jpg") || suffixName.equals(".jpeg") || suffixName.equals(".png")) {
+                    file1.transferTo(new File(imgPath, fileName));
+                    files.add(imgPathDown + fileName);
+                } else {
+                    throw new RRException(BizCodeEnume.FILE_NOT);
+                }
+            } catch (IOException e) {
+                throw new RRException(BizCodeEnume.FILE_UPDOWN_FAIL);
+            }
+        });
+
+        return CommonResult.ok().setResult(files);
+    }
+}

+ 5 - 1
src/main/java/com/chuanghai/h3c_reporting/controller/InformationReportingController.java

@@ -47,10 +47,14 @@ public class InformationReportingController {
     @PostMapping("/add")
     public CommonResult<String> add(@Valid @RequestBody InformationReportingVO staffEntity) {
 
-//        staffEntity.setProduct(JSONObject.toJSONString(staffEntity.getBProduct()));
         String product = StringUtils.join(Arrays.asList(staffEntity.getBProduct()), ',');
         staffEntity.setProduct(product);
 
+        if (staffEntity.getBFile().length != 0){
+            String file = StringUtils.join(Arrays.asList(staffEntity.getBFile()), ',');
+            staffEntity.setFile(file);
+        }
+
         InformationReporting reporting = new InformationReporting();
         BeanUtils.copyProperties(staffEntity, reporting);
         LocalDateTime localDateTime = LocalDateTime.now();

+ 8 - 1
src/main/java/com/chuanghai/h3c_reporting/entity/InformationReporting.java

@@ -106,12 +106,19 @@ public class InformationReporting implements Serializable {
     @ColumnWidth(20)
     private String product;
 
+    /**
+     * 附件材料
+     */
+    @ExcelProperty(value = "附件材料", index = 11)
+    @ColumnWidth(20)
+    private String file;
+
 
     /**
      * 提交时间
      */
     @ColumnWidth(20)
-    @ExcelProperty(value = "提交时间", converter = LocalDateTimeConverter.class, index = 11)
+    @ExcelProperty(value = "提交时间", converter = LocalDateTimeConverter.class, index = 12)
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private LocalDateTime reportingTime;
 

+ 8 - 0
src/main/java/com/chuanghai/h3c_reporting/vo/InformationReportingVO.java

@@ -88,4 +88,12 @@ public class InformationReportingVO {
     @TableField(exist = false)
     @JsonProperty(value ="bProduct")
     private String[] bProduct;
+
+    /**
+     * 附件材料
+     */
+    @JsonProperty(value ="bFile")
+    private String[] bFile;
+
+    private String file;
 }

+ 7 - 0
src/main/resources/application.yml

@@ -1,5 +1,6 @@
 server:
   port: 8888
+#  port: 9999
   servlet:
     context-path: /reporting
 
@@ -39,3 +40,9 @@ my-security:
 wx:
   app_id: wx2fc3f45732fae5d3
   secret: 7eee4a49a4470a77f9222995e8511547
+
+file:
+  # 存
+  imgPath: /home/reporting/reportImg/
+  # 取
+  imgPathDown: https://chtech.ncjti.edu.cn/gradiate-school/reportImg/

ファイルの差分が大きいため隠しています
+ 97 - 88
src/main/resources/static/doc/index.html


+ 27 - 16
src/main/resources/static/doc/search.js

@@ -1,76 +1,87 @@
 let api = [];
 api.push({
-    alias: 'InformationReportingController',
+    alias: 'FileController',
+    order: '1',
+    link: '',
+    desc: '',
+    list: []
+})
+api[0].list.push({
     order: '1',
+    desc: '获取文件路径链接',
+});
+api.push({
+    alias: 'InformationReportingController',
+    order: '2',
     link: '报备模块',
     desc: '报备模块',
     list: []
 })
-api[0].list.push({
+api[1].list.push({
     order: '1',
     desc: '信息上传',
 });
-api[0].list.push({
+api[1].list.push({
     order: '2',
     desc: '删除信息',
 });
-api[0].list.push({
+api[1].list.push({
     order: '3',
     desc: '关闭项目',
 });
-api[0].list.push({
+api[1].list.push({
     order: '4',
     desc: '项目列表',
 });
-api[0].list.push({
+api[1].list.push({
     order: '5',
     desc: '信息导出',
 });
 api.push({
     alias: 'UserController',
-    order: '2',
+    order: '3',
     link: '账户管理模块',
     desc: '账户管理模块',
     list: []
 })
-api[1].list.push({
+api[2].list.push({
     order: '1',
     desc: '管理员登录',
 });
-api[1].list.push({
+api[2].list.push({
     order: '2',
     desc: '添加管理员',
 });
-api[1].list.push({
+api[2].list.push({
     order: '3',
     desc: '删除管理员',
 });
-api[1].list.push({
+api[2].list.push({
     order: '4',
     desc: '修改管理员信息',
 });
-api[1].list.push({
+api[2].list.push({
     order: '5',
     desc: '修改本人密码',
 });
-api[1].list.push({
+api[2].list.push({
     order: '6',
     desc: '管理员列表',
 });
 api.push({
     alias: 'WxController',
-    order: '3',
+    order: '4',
     link: '获取微信绑定手机号',
     desc: '获取微信绑定手机号',
     list: []
 })
-api[2].list.push({
+api[3].list.push({
     order: '1',
     desc: '通过code换取用户手机号',
 });
 api.push({
     alias: 'dict',
-    order: '4',
+    order: '5',
     link: 'dict_list',
     desc: '数据字典',
     list: []