Browse Source

文件file模块增加feign调用服务

lengfaqiang 2 years ago
parent
commit
9e14d9d1d7

+ 2 - 1
README.md

@@ -48,7 +48,7 @@
 | 分布式日志中心     | 采用 ELK 业界成熟解决方案 实时收集所有服务的运行日志 快速发现定位问题                                                                  |
 | 分布式搜索引擎     | 采用 ElasticSearch以 Mybatis-Plus 方式操作 ElasticSearch                                                       |
 | *分布式消息队列    | 采用 SpringCloud-Stream + RabbitMQ                                                                        |
-| 文件存储        | 采用 Minio 分布式文件存储 天生支持多机、多硬盘、多分片、多副本存储支持权限管理 安全可靠 文件可加密存储                                                |
+| *文件存储       | 采用 Minio 分布式文件存储 天生支持多机、多硬盘、多分片、多副本存储支持权限管理 安全可靠 文件可加密存储(采用的aliyun-oss)                                 |
 | *短信         | 使用 spring-cloud-alicloud-sms                                                                            |
 | 短链接         | 购买现成产品                                                                                                  |
 | 接口文档        | 援用现有接口文档系统                                                                                              |
@@ -87,6 +87,7 @@ sckw-service-platform
 │       └── sckw-xxx                            // xxxx服务 [10040]
 ├── sckw-modules-api                    // 接口模块
 │       └── sckw-system-api                     // 系统基础服务接口
+│       └── sckw-file-api                     // 系统文件服务接口
 ├── sckw-ops          				    // 运维中心
 ├── sckw-common          				// 通用模块
 │       └── sckw-common-core                    // 核心模块

+ 19 - 6
sckw-modules-api/sckw-file-api/src/main/java/com/sckw/file/api/feign/FileApiFeignService.java

@@ -2,11 +2,11 @@ package com.sckw.file.api.feign;
 
 import com.sckw.core.web.response.HttpResult;
 import org.springframework.cloud.openfeign.FeignClient;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.util.Map;
+
 /**
  * @author lfdc
  * @version 1.0
@@ -16,9 +16,9 @@ import org.springframework.web.multipart.MultipartFile;
  * @date 2023-06-06 10:06:06
  */
 //name:调⽤的服务名称,和服务提供者yml⽂件中spring.application.name保持⼀致
-//path: 定义当前FeignClient的统一前缀
+//path: 定义当前FeignClient的统一前缀 ,path = "/file",url = "http://127.0.0.1:10050"
 //url: 定义当前FeignClient调用地址
-@FeignClient(name = "sckw-file",path = "/file",url = "http://127.0.0.1:10050")
+@FeignClient(name = "sckw-file")
 public interface FileApiFeignService {
 
     /**
@@ -26,7 +26,20 @@ public interface FileApiFeignService {
      * @param file
      * @return
      */
-   @RequestMapping(value = "/fileFeignUpload",method = RequestMethod.POST)
+//   @RequestMapping(value = "/file/fileFeignUpload",method = RequestMethod.POST)
+    @PostMapping("/file/fileFeignUpload")
     public HttpResult fileFeignUpload(@RequestParam("file") MultipartFile file) ;
 
+    /**
+     * file-demo
+     * @param userName
+     * @return
+     */
+//    @RequestMapping(value = "/fileFeignUpload",method = RequestMethod.POST)
+    @GetMapping(value = "/file/fileFeignDemo")
+    public String fileFeignDemo(@RequestParam("userName") String userName) ;
+
+
+    @RequestMapping(value = "/file/fileFeignDemo1",method = RequestMethod.POST)
+    String fileFeignDemo1( Map<String, String> map);
 }

+ 31 - 3
sckw-modules/sckw-example/src/main/java/com/sckw/example/controller/FileApiController.java

@@ -5,13 +5,14 @@ import com.sckw.example.service.FileService;
 import com.sckw.file.api.dubbo.FileApiDubboService;
 import com.sckw.file.api.feign.FileApiFeignService;
 import lombok.AllArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * @author lfdc
@@ -22,7 +23,6 @@ import java.io.IOException;
  * @company sckw
  * @date 2023-06-02 16:06:43
  */
-@Slf4j
 @RestController
 @RequestMapping("/file")
 @AllArgsConstructor
@@ -73,11 +73,39 @@ public class FileApiController {
      */
     @RequestMapping (value = "/fileFeignUpload",method = RequestMethod.POST)
     public HttpResult fileFeignUpload(@RequestParam("file") MultipartFile file) {
-        //auth 服务 调用 file服务提供的feign接口
+        //example 服务 调用 file服务提供的feign接口
         HttpResult result = fileApiFeignService.fileFeignUpload(file);
         return result;
     }
 
+    /**
+     * 基于feign调用
+     *
+     * @param
+     * @return
+     */
+    @RequestMapping (value = "/fileFeignDemo",method = RequestMethod.GET)
+    //@RequestParam("file") MultipartFile file
+    public String fileFeignDemo() {
+        //example 服务 调用 file服务提供的feign接口
+        return fileApiFeignService.fileFeignDemo("userName");
+    }
+
+    /**
+     * 基于feign调用
+     *
+     * @param
+     * @return
+     */
+    @RequestMapping (value = "/fileFeignDemo1",method = RequestMethod.POST)
+    public String fileFeignDemo1() {
+       Map<String, String> map = new HashMap<>();
+        map.put("123","456");
+        map.put("asd","asd");
+        return fileApiFeignService.fileFeignDemo1(map);
+    }
+
+
     /**
      * 基于dubbo调用
      *

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

@@ -8,6 +8,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.util.Map;
+
 /**
  * @author lfdc
  * @version 1.0
@@ -82,4 +84,25 @@ public class FileApiController {
         return HttpResult.ok();
     }
 
+    /**
+     * file-feign-demo
+     * @param userName
+     * @return
+     */
+    @GetMapping(value = "/fileFeignDemo")
+    public HttpResult fileFeignDemo(@RequestParam("userName") String userName) {
+        return HttpResult.ok(userName);
+    }
+
+
+    /**
+     * file-feign-demo1
+     * @param map
+     * @return
+     */
+    @RequestMapping(value = "fileFeignDemo1",method = RequestMethod.POST)
+    public HttpResult fileFeignDemo1(@RequestBody Map<String, String> map) {
+        return HttpResult.ok(map);
+    }
+
 }