浏览代码

优化文件上传

zhouhao 7 年之前
父节点
当前提交
87f7b6293d

+ 1 - 2
hsweb-system/hsweb-system-file/hsweb-system-file-controller/src/main/java/org/hswebframework/web/controller/file/FileInfoController.java

@@ -4,9 +4,7 @@ import io.swagger.annotations.Api;
 import org.hswebframework.web.authorization.annotation.Authorize;
 import org.hswebframework.web.commons.entity.param.QueryParamEntity;
 import org.hswebframework.web.controller.QueryController;
-import org.hswebframework.web.controller.SimpleGenericEntityController;
 import org.hswebframework.web.entity.file.FileInfoEntity;
-import org.hswebframework.web.logging.AccessLogger;
 import org.hswebframework.web.service.file.FileInfoService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -35,4 +33,5 @@ public class FileInfoController implements QueryController<FileInfoEntity, Strin
     public FileInfoService getService() {
         return fileInfoService;
     }
+
 }

+ 6 - 131
hsweb-system/hsweb-system-file/hsweb-system-file-entity/src/main/java/org/hswebframework/web/entity/file/SimpleFileInfoEntity.java

@@ -1,5 +1,6 @@
 package org.hswebframework.web.entity.file;
 
+import lombok.*;
 import org.hswebframework.web.commons.entity.SimpleGenericEntity;
 
 /**
@@ -7,6 +8,11 @@ import org.hswebframework.web.commons.entity.SimpleGenericEntity;
  *
  * @author hsweb-generator-online
  */
+@Getter
+@Setter
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
 public class SimpleFileInfoEntity extends SimpleGenericEntity<String> implements FileInfoEntity {
     //文件名称
     private String name;
@@ -27,135 +33,4 @@ public class SimpleFileInfoEntity extends SimpleGenericEntity<String> implements
     //创建人
     private String creatorId;
 
-    /**
-     * @return 文件名称
-     */
-    @Override
-    public String getName() {
-        return this.name;
-    }
-
-    /**
-     * @param name 文件名称
-     */
-    @Override
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    @Override
-    public String getLocation() {
-        return location;
-    }
-
-    @Override
-    public void setLocation(String location) {
-        this.location = location;
-    }
-
-    /**
-     * @return 类型
-     */
-    @Override
-    public String getType() {
-        return this.type;
-    }
-
-    /**
-     * @param type 类型
-     */
-    @Override
-    public void setType(String type) {
-        this.type = type;
-    }
-
-    /**
-     * @return md5校验值
-     */
-    @Override
-    public String getMd5() {
-        return this.md5;
-    }
-
-    /**
-     * @param md5 md5校验值
-     */
-    @Override
-    public void setMd5(String md5) {
-        this.md5 = md5;
-    }
-
-    /**
-     * @return 文件大小
-     */
-    @Override
-    public Long getSize() {
-        return this.size;
-    }
-
-    /**
-     * @param size 文件大小
-     */
-    @Override
-    public void setSize(Long size) {
-        this.size = size;
-    }
-
-    /**
-     * @return 状态
-     */
-    @Override
-    public Byte getStatus() {
-        return this.status;
-    }
-
-    /**
-     * @param status 状态
-     */
-    @Override
-    public void setStatus(Byte status) {
-        this.status = status;
-    }
-
-    /**
-     * @return 分类
-     */
-    @Override
-    public String getClassified() {
-        return this.classified;
-    }
-
-    /**
-     * @param classified 分类
-     */
-    @Override
-    public void setClassified(String classified) {
-        this.classified = classified;
-    }
-
-    /**
-     * @return 创建人
-     */
-    @Override
-    public String getCreatorId() {
-        return this.creatorId;
-    }
-
-    @Override
-    public Long getCreateTime() {
-        return createTime;
-    }
-
-    @Override
-    public void setCreateTime(Long createTime) {
-        this.createTime = createTime;
-    }
-
-    /**
-     * @param creatorId 创建人
-     */
-    @Override
-    public void setCreatorId(String creatorId) {
-        this.creatorId = creatorId;
-    }
 }

+ 3 - 4
hsweb-system/hsweb-system-file/hsweb-system-file-service/hsweb-system-file-service-oauth2/src/main/java/org/hswebframework/web/service/file/oauth2/OAuth2FileService.java

@@ -37,15 +37,14 @@ public class OAuth2FileService implements FileService, OAuth2ServiceSupport {
     @Override
     public FileInfoEntity saveFile(InputStream fileStream, String fileName, String type, String creatorId) throws IOException {
         return createRequest("/upload")
-                .upload(fileName, fileStream)
-                .post().as(getEntityType());
+                .upload("file", fileStream,fileName)
+                .as(getEntityType());
     }
 
     @Override
     public String saveStaticFile(InputStream fileStream, String fileName) throws IOException {
         return createRequest("/upload-static")
-                .upload(fileName, fileStream)
-                .post()
+                .upload("file", fileStream,fileName)
                 .as(String.class);
     }
 

+ 9 - 4
hsweb-system/hsweb-system-file/hsweb-system-file-service/hsweb-system-file-service-oauth2/src/test/java/org/hswebframework/web/service/file/oauth2/MockOAuth2Request.java

@@ -13,9 +13,9 @@ import java.util.function.Function;
 @Slf4j
 public class MockOAuth2Request implements OAuth2Request {
 
-    private Function<String,OAuth2Response> responseGetter;
+    private Function<String, OAuth2Response> responseGetter;
 
-    public MockOAuth2Request(Function<String,OAuth2Response> responseGetter) {
+    public MockOAuth2Request(Function<String, OAuth2Response> responseGetter) {
         this.responseGetter = responseGetter;
     }
 
@@ -42,8 +42,13 @@ public class MockOAuth2Request implements OAuth2Request {
     }
 
     @Override
-    public OAuth2Request upload(String name, InputStream inputStream) {
-        return this;
+    public OAuth2Response upload(String name, InputStream inputStream) {
+        return responseGetter.apply("post");
+    }
+
+    @Override
+    public OAuth2Response upload(String name, InputStream inputStream, String fileName) {
+        return responseGetter.apply("post");
     }
 
     @Override