فهرست منبع

文件上传新增app适用接口

lengfaqiang 2 سال پیش
والد
کامیت
a63173979f

+ 46 - 0
sckw-common/sckw-common-core/src/main/java/com/sckw/core/web/response/Data.java

@@ -0,0 +1,46 @@
+package com.sckw.core.web.response;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+
+/**
+ * @description: 数据封装
+ * @author: lfdc
+ * @copyright
+ * @create: 2022-01-27 09:49
+ **/
+public class Data {
+    @JsonInclude(JsonInclude.Include.NON_NULL)
+    private Object body;
+
+    public static Data getData() {
+        return new Data();
+    }
+
+    public static Data getData(Object data) {
+        Data da = new Data();
+        da.setBody(data);
+        return da;
+    }
+
+
+    public Object getBody() {
+        return this.body;
+    }
+
+
+    public void setBody(Object body) {
+        this.body = body;
+    }
+
+
+    public String toString() {
+        return "Data(body=" + this.getBody() + ")";
+    }
+
+    public Data() {
+    }
+
+    public Data(Object body) {
+        this.body = body;
+    }
+}

+ 151 - 0
sckw-common/sckw-common-core/src/main/java/com/sckw/core/web/response/Result.java

@@ -0,0 +1,151 @@
+package com.sckw.core.web.response;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+/**
+ * @description:
+ * @author: LengFaQiang
+ * @copyright 北京联众信安科技有限公司
+ * @create: 2022-01-27 10:17
+ **/
+public class Result {
+    private static final long serialVersionUID = 8295075842951977226L;
+    private int status;
+    private String msg;
+    //    @JsonProperty
+    private Object data;
+
+
+    public Result() {
+    }
+
+    public Result(Status status) {
+        this.status = status.getCode();
+        this.msg = status.getMsg();
+        this.data = Data.getData();
+    }
+
+    public Result(Status status, Object data) {
+        this.status = status.getCode();
+        this.data = data;
+    }
+
+
+    public Result(Status status, String msg) {
+        this.status = status.getCode();
+        this.msg = msg;
+//        this.data = Data.getData();
+    }
+
+    public Result(Status status, int msgCode) {
+        this.status = status.getCode();
+        this.msg = String.valueOf(msgCode);
+//        this.data = Data.getData();
+    }
+
+
+    public Result(Status status, String msg, Object data) {
+        this.status = status.getCode();
+        this.msg = msg;
+        this.data = data;
+    }
+
+    public Result(Status status, int msgCode, Object data) {
+        this.status = status.getCode();
+        this.msg = String.valueOf(msgCode);
+        this.data = data;
+    }
+
+
+    @JsonIgnore
+    public boolean isSuccess() {
+        return this.status == Status.SUCCESS.getCode();
+    }
+
+    @JsonIgnore
+    public boolean nonSuccess() {
+        return this.status != Status.SUCCESS.getCode();
+    }
+
+    public Result success() {
+        return new Result(Status.SUCCESS);
+    }
+
+    public Result illegal() {
+        return new Result(Status.BAD_REQUEST);
+    }
+
+    public Result unauthorized() {
+        return new Result(Status.UNAUTHORIZED);
+    }
+
+    public Result forbidden() {
+        return new Result(Status.FORBIDDEN);
+    }
+
+    public Result notFound() {
+        return new Result(Status.NOT_FOUND);
+    }
+
+    public Result failure() {
+        return new Result(Status.FAILURE);
+    }
+
+    public Result conflict() {
+        return new Result(Status.CONFLICT);
+    }
+
+    public int getStatus() {
+        return this.status;
+    }
+
+    public String getMsg() {
+        return this.msg;
+    }
+
+    public Object getData() {
+        return this.data;
+    }
+
+    public void setStatus(int status) {
+        this.status = status;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+
+    public void setData(Data data) {
+        this.data = data;
+    }
+
+    public String toString() {
+        return "Result(status=" + this.getStatus() + ", msg=" + this.getMsg() + ", data=" + this.getData() + ")";
+    }
+
+    public static long getSerialVersionUID() {
+        return serialVersionUID;
+    }
+
+    public void setData(Object data) {
+        this.data = data;
+    }
+
+    public Result(int status, String msg, Object data) {
+        this.status = status;
+        this.msg = msg;
+        this.data = data;
+    }
+
+    public static Result build(Status status, Object data) {
+        return new Result(status, data);
+    }
+
+    public static Result build(Status status, String msg, Object data) {
+        return new Result(status, msg, data);
+    }
+
+    public static Result build(Status status, String msg) {
+        return new Result(status, msg);
+    }
+}

+ 32 - 0
sckw-common/sckw-common-core/src/main/java/com/sckw/core/web/response/Status.java

@@ -0,0 +1,32 @@
+package com.sckw.core.web.response;
+
+/**
+ * @description: 状态枚举
+ * @author: lfdc
+ * @create: 2022-01-27 09:43
+ **/
+public enum Status {
+    SUCCESS(200, "操作成功"),
+    BAD_REQUEST(400, "操作验证失败"),
+    UNAUTHORIZED(401, "操作未授权"),
+    FORBIDDEN(403, "操作被拒绝"),
+    NOT_FOUND(404, "未知操作"),
+    CONFLICT(409, "请求发生冲突"),
+    FAILURE(500, "操作失败");
+
+    private int code;
+    private String msg;
+
+    private Status(int code, String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+
+    public int getCode() {
+        return this.code;
+    }
+
+    public String getMsg() {
+        return this.msg;
+    }
+}

+ 12 - 0
sckw-modules/sckw-file/src/main/java/com/sckw/file/controller/FileApiController.java

@@ -3,6 +3,7 @@ package com.sckw.file.controller;
 import com.sckw.core.model.file.FileInfo;
 import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.response.HttpResult;
+import com.sckw.core.web.response.Result;
 import com.sckw.file.api.dto.FileInfoDTO;
 import com.sckw.file.service.FileService;
 import com.sckw.file.service.dubbo.FileDubboApiServiceImpl;
@@ -122,6 +123,17 @@ public class FileApiController {
         return fileService.uploadFileInfo(file);
     }
 
+
+    /**
+     * app-前端调用接口上传oss
+     * @param file
+     * @return
+     */
+    @RequestMapping(value = "/appUploadFileInfo", method = RequestMethod.POST)
+    public Result appUploadFileInfo(@RequestParam("file") MultipartFile file) {
+        return fileService.appUploadFileInfo(file);
+    }
+
     /**
      * dubbo接收文件信息保存至数据库
      * @param fileInfo

+ 19 - 2
sckw-modules/sckw-file/src/main/java/com/sckw/file/service/FileService.java

@@ -13,6 +13,8 @@ import com.sckw.core.utils.StringUtils;
 import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.context.LoginUserHolder;
 import com.sckw.core.web.response.HttpResult;
+import com.sckw.core.web.response.Result;
+import com.sckw.core.web.response.Status;
 import com.sckw.file.api.dto.FileInfoDTO;
 import com.sckw.file.config.FileListConfig;
 import com.sckw.file.dao.KwsFileInfoDao;
@@ -249,19 +251,34 @@ public class FileService {
 
     public HttpResult uploadFileInfo(MultipartFile file) {
         boolean flag = checkFileFormat(file);
-        if (!flag){
+        if (!flag) {
             throw new RuntimeException("上传文件格式错误!");
         }
         FileInfo fileInfo = FileUtils.getFileDataList(file);
         fileInfo.setType(FileEnum.FILE_STORE_TYPE_OSS.getFileType());
         FileInfo returnFileInfo = FileUtils.uploadFileInfo(file, fileInfo, FileEnum.FILE_STORE_TYPE_OSS);
         FileInfoVO fileInfoVO = new FileInfoVO();
-        BeanUtils.copyProperties(returnFileInfo,fileInfoVO);
+        BeanUtils.copyProperties(returnFileInfo, fileInfoVO);
         return HttpResult.ok(fileInfoVO);
     }
 
+
+    public Result appUploadFileInfo(MultipartFile file) {
+        boolean flag = checkFileFormat(file);
+        if (!flag) {
+            return Result.build(Status.FAILURE, "上传文件格式错误!");
+        }
+        FileInfo fileInfo = FileUtils.getFileDataList(file);
+        fileInfo.setType(FileEnum.FILE_STORE_TYPE_OSS.getFileType());
+        FileInfo returnFileInfo = FileUtils.uploadFileInfo(file, fileInfo, FileEnum.FILE_STORE_TYPE_OSS);
+        FileInfoVO fileInfoVO = new FileInfoVO();
+        BeanUtils.copyProperties(returnFileInfo, fileInfoVO);
+        return Result.build(Status.SUCCESS, fileInfoVO);
+    }
+
     /**
      * 上传文件->oss文件格式校验
+     *
      * @param file
      * @return
      */