From 809eb8fe8d7878aa9d6742c9052139603dbaba9b Mon Sep 17 00:00:00 2001 From: liuchuang Date: Sun, 8 Sep 2019 18:37:29 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E7=AB=AF=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=8E=A5=E5=8F=A3=20init?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epdc-api/epdc-api-client/pom.xml | 6 ++--- .../epdc/controller/ApiIssueController.java | 14 +++++++++++ .../elink/esua/epdc/feign/OssFeignClient.java | 23 +++++++++++++++++++ .../fallback/OssFeignClientFallback.java | 23 +++++++++++++++++++ .../elink/esua/epdc/service/IssueService.java | 11 +++++++++ .../epdc/service/impl/IssueServiceImpl.java | 11 +++++++++ 6 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/feign/OssFeignClient.java create mode 100644 esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/feign/fallback/OssFeignClientFallback.java diff --git a/esua-epdc/epdc-module/epdc-api/epdc-api-client/pom.xml b/esua-epdc/epdc-module/epdc-api/epdc-api-client/pom.xml index 7416667dc..43d64f905 100644 --- a/esua-epdc/epdc-module/epdc-api/epdc-api-client/pom.xml +++ b/esua-epdc/epdc-module/epdc-api/epdc-api-client/pom.xml @@ -45,17 +45,17 @@ com.esua.epdc - epdc-events-client + epdc-services-client 1.0.0 com.esua.epdc - epdc-services-client + epdc-user-client 1.0.0 com.esua.epdc - epdc-user-client + epdc-oss-client 1.0.0 diff --git a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/controller/ApiIssueController.java b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/controller/ApiIssueController.java index 396e740c1..8a4cf679e 100644 --- a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/controller/ApiIssueController.java +++ b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/controller/ApiIssueController.java @@ -3,12 +3,14 @@ package com.elink.esua.epdc.controller; import com.elink.esua.epdc.common.token.dto.TokenDto; import com.elink.esua.epdc.commons.tools.annotation.LoginUser; import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.dto.UploadDTO; import com.elink.esua.epdc.dto.events.form.EpdcEventSubmitFormDTO; import com.elink.esua.epdc.dto.issue.form.IssueFormDTO; import com.elink.esua.epdc.dto.issue.result.IssueResultDTO; import com.elink.esua.epdc.service.IssueService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -48,4 +50,16 @@ public class ApiIssueController { return issueService.listIssues(userDetail, formDto); } + /** + * 文件上传 + * @Params: [file] + * @Return: com.elink.esua.epdc.commons.tools.utils.Result + * @Author: liuchuang + * @Date: 2019/9/8 18:34 + */ + @PostMapping("upload") + public Result upload(@RequestParam("file") MultipartFile file) { + return issueService.upload(file); + } + } diff --git a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/feign/OssFeignClient.java b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/feign/OssFeignClient.java new file mode 100644 index 000000000..ec8294bf0 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/feign/OssFeignClient.java @@ -0,0 +1,23 @@ +package com.elink.esua.epdc.feign; + +import com.elink.esua.epdc.commons.tools.constant.ServiceConstant; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.dto.UploadDTO; +import com.elink.esua.epdc.feign.fallback.OssFeignClientFallback; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.multipart.MultipartFile; + +/** + * 文件对象模块 + * @Author LC + * @Date 2019/9/8 18:24 + */ +@FeignClient(name = ServiceConstant.EPDC_OSS_SERVER, fallback = OssFeignClientFallback.class) +public interface OssFeignClient { + + @PostMapping(value = "oss/file/upload", produces = MediaType.APPLICATION_JSON_UTF8_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + Result upload(@RequestPart("file") MultipartFile file); +} diff --git a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/feign/fallback/OssFeignClientFallback.java b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/feign/fallback/OssFeignClientFallback.java new file mode 100644 index 000000000..c9dc436a8 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/feign/fallback/OssFeignClientFallback.java @@ -0,0 +1,23 @@ +package com.elink.esua.epdc.feign.fallback; + +import com.elink.esua.epdc.commons.tools.constant.ServiceConstant; +import com.elink.esua.epdc.commons.tools.utils.ModuleUtils; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.dto.UploadDTO; +import com.elink.esua.epdc.feign.OssFeignClient; +import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; + +/** + * 文件对象模块 + * @Author LC + * @Date 2019/9/8 18:25 + */ +@Component +public class OssFeignClientFallback implements OssFeignClient { + + @Override + public Result upload(MultipartFile file) { + return ModuleUtils.feignConError(ServiceConstant.EPDC_OSS_SERVER, "upload", file.getOriginalFilename()); + } +} diff --git a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/service/IssueService.java b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/service/IssueService.java index 759519915..c529bb090 100644 --- a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/service/IssueService.java +++ b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/service/IssueService.java @@ -2,9 +2,11 @@ package com.elink.esua.epdc.service; import com.elink.esua.epdc.common.token.dto.TokenDto; import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.dto.UploadDTO; import com.elink.esua.epdc.dto.events.form.EpdcEventSubmitFormDTO; import com.elink.esua.epdc.dto.issue.form.IssueFormDTO; import com.elink.esua.epdc.dto.issue.result.IssueResultDTO; +import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -32,4 +34,13 @@ public interface IssueService { * @Date: 2019/9/7 11:26 */ Result> listIssues(TokenDto userDetail, IssueFormDTO formDto); + + /** + * 文件上传 + * @Params: [file] + * @Return: com.elink.esua.epdc.commons.tools.utils.Result + * @Author: liuchuang + * @Date: 2019/9/8 18:34 + */ + Result upload(MultipartFile file); } diff --git a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/service/impl/IssueServiceImpl.java b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/service/impl/IssueServiceImpl.java index b64e982fe..468676da7 100644 --- a/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/service/impl/IssueServiceImpl.java +++ b/esua-epdc/epdc-module/epdc-api/epdc-api-server/src/main/java/com/elink/esua/epdc/service/impl/IssueServiceImpl.java @@ -3,14 +3,17 @@ package com.elink.esua.epdc.service.impl; import com.elink.esua.epdc.common.token.dto.TokenDto; import com.elink.esua.epdc.commons.tools.utils.Result; import com.elink.esua.epdc.dto.CompleteDeptDTO; +import com.elink.esua.epdc.dto.UploadDTO; import com.elink.esua.epdc.dto.events.form.EpdcEventSubmitFormDTO; import com.elink.esua.epdc.dto.issue.form.IssueFormDTO; import com.elink.esua.epdc.dto.issue.result.IssueResultDTO; import com.elink.esua.epdc.feign.IssueFeignClient; +import com.elink.esua.epdc.feign.OssFeignClient; import com.elink.esua.epdc.feign.SysDeptFeignClient; import com.elink.esua.epdc.service.IssueService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -28,6 +31,9 @@ public class IssueServiceImpl implements IssueService { @Autowired private SysDeptFeignClient sysDeptFeignClient; + @Autowired + private OssFeignClient ossFeignClient; + @Override public Result saveEvent(TokenDto userDetail, EpdcEventSubmitFormDTO formDto) { // 获取该网格所有上级机构 @@ -55,4 +61,9 @@ public class IssueServiceImpl implements IssueService { formDto.setDeptId(userDetail.getGridId()); return issueFeignClient.listIssues(formDto); } + + @Override + public Result upload(MultipartFile file) { + return ossFeignClient.upload(file); + } }