From d03f448d6888f406fe273658c8c0a5c19eff7f94 Mon Sep 17 00:00:00 2001
From: yinzuomei <57602893@qq.com>
Date: Wed, 18 Mar 2020 15:48:50 +0800
Subject: [PATCH] =?UTF-8?q?feign=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../tools/constant/ServiceConstant.java | 5 +++
.../epmet-demo/epmet-demo-server/pom.xml | 6 +++
.../com/epmet/controller/DemoController.java | 13 +++++-
.../com/epmet/feign/AdminFeignClient.java | 41 +++++++++++++++++++
.../com/epmet/feign/EpmetUserFeignClient.java | 14 +++++++
.../com/epmet/feign/GovOrgFeignClient.java | 20 +++++++++
.../com/epmet/feign/OperCrmFeignClient.java | 2 +-
.../fallback/AdminFeignClientFallback.java | 34 +++++++++++++++
.../EpmetUserFeignClientFallback.java | 15 +++++++
.../fallback/GovOrgFeignClientFallBack.java | 21 ++++++++++
.../OperCrmFeignClientFallBack.java | 2 +-
.../java/com/epmet/service/DemoService.java | 6 +++
.../epmet/service/impl/DemoServiceImpl.java | 18 +++++++-
.../java/com/epmet/GovOrgApplication.java | 4 ++
.../controller/CustomerGridController.java | 11 +++--
15 files changed, 205 insertions(+), 7 deletions(-)
create mode 100644 epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/AdminFeignClient.java
create mode 100644 epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java
create mode 100644 epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/GovOrgFeignClient.java
create mode 100644 epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/fallback/AdminFeignClientFallback.java
create mode 100644 epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallback.java
create mode 100644 epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/fallback/GovOrgFeignClientFallBack.java
rename epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/{impl => fallback}/OperCrmFeignClientFallBack.java (96%)
diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/ServiceConstant.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/ServiceConstant.java
index 2329a246b6..232c92ac97 100644
--- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/ServiceConstant.java
+++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/ServiceConstant.java
@@ -48,4 +48,9 @@ public interface ServiceConstant {
* 陌生人导览
*/
String RESI_GUIDE_SERVER = "resi-guide-server";
+
+ /**
+ * 政府机构组织管理
+ */
+ String GOV_ORG_SERVER = "gov-org-server";
}
diff --git a/epmet-module/epmet-demo/epmet-demo-server/pom.xml b/epmet-module/epmet-demo/epmet-demo-server/pom.xml
index f3d4c712f7..957a3d250d 100644
--- a/epmet-module/epmet-demo/epmet-demo-server/pom.xml
+++ b/epmet-module/epmet-demo/epmet-demo-server/pom.xml
@@ -55,6 +55,12 @@
2.0.0
compile
+
+ com.epmet
+ gov-org-client
+ 2.0.0
+ compile
+
io.github.openfeign
diff --git a/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/controller/DemoController.java b/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/controller/DemoController.java
index e3d1f43721..799c768701 100644
--- a/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/controller/DemoController.java
+++ b/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/controller/DemoController.java
@@ -18,6 +18,7 @@
package com.epmet.controller;
import com.epmet.commons.tools.page.PageData;
+import com.epmet.commons.tools.security.user.UserDetail;
import com.epmet.commons.tools.utils.ExcelUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.AssertUtils;
@@ -26,13 +27,13 @@ import com.epmet.commons.tools.validator.group.AddGroup;
import com.epmet.commons.tools.validator.group.UpdateGroup;
import com.epmet.commons.tools.validator.group.DefaultGroup;
import com.epmet.dto.CustomerDTO;
+import com.epmet.dto.CustomerGridDTO;
import com.epmet.dto.DemoDTO;
import com.epmet.dto.form.SaveCustomerFormDTO;
import com.epmet.dto.result.ValidCustomerResultDTO;
import com.epmet.excel.DemoExcel;
import com.epmet.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
@@ -115,4 +116,14 @@ public class DemoController {
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
return demoService.saveCustomerInfo(dto);
}
+
+ @GetMapping("/getcustomergrid/{id}")
+ public Result getcustomergrid(@PathVariable("id") String id){
+ return demoService.getcustomergrid(id);
+ }
+
+ @GetMapping("getSysUserInfoById")
+ public Result getSysUserInfoById(@RequestParam("id") Long id){
+ return demoService.getSysUserInfoById(id);
+ }
}
diff --git a/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/AdminFeignClient.java b/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/AdminFeignClient.java
new file mode 100644
index 0000000000..b8c41f35e8
--- /dev/null
+++ b/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/AdminFeignClient.java
@@ -0,0 +1,41 @@
+/**
+ * Copyright (c) 2018 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.epmet.feign;
+
+import com.epmet.commons.tools.constant.ServiceConstant;
+import com.epmet.commons.tools.security.user.UserDetail;
+import com.epmet.commons.tools.utils.Result;
+import com.epmet.feign.fallback.AdminFeignClientFallback;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+/**
+ * 用户接口
+ *
+ * @author Mark sunlightcs@gmail.com
+ * @since 1.0.0
+ */
+@FeignClient(name = ServiceConstant.EPMET_ADMIN_SERVER, fallback = AdminFeignClientFallback.class)
+public interface AdminFeignClient {
+
+ /**
+ * 根据用户ID,获取用户信息
+ */
+ @GetMapping("sys/user/getById")
+ Result getById(@RequestParam("id") Long id);
+
+ /**
+ * 根据用户名,获取用户信息
+ * @param username 用户名
+ */
+ @GetMapping("sys/user/getByUsername")
+ Result getByUsername(@RequestParam("username") String username);
+
+}
diff --git a/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java b/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java
new file mode 100644
index 0000000000..52562d655b
--- /dev/null
+++ b/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/EpmetUserFeignClient.java
@@ -0,0 +1,14 @@
+package com.epmet.feign;
+
+import com.epmet.commons.tools.constant.ServiceConstant;
+import com.epmet.feign.fallback.EpmetUserFeignClientFallback;
+import org.springframework.cloud.openfeign.FeignClient;
+
+/**
+ * @Description
+ * @Author yinzuomei
+ * @Date 2020/3/16 14:48
+ */
+@FeignClient(name = ServiceConstant.EPMET_USER_SERVER, fallback = EpmetUserFeignClientFallback.class)
+public interface EpmetUserFeignClient {
+}
diff --git a/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/GovOrgFeignClient.java b/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/GovOrgFeignClient.java
new file mode 100644
index 0000000000..e2d1a6ac26
--- /dev/null
+++ b/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/GovOrgFeignClient.java
@@ -0,0 +1,20 @@
+package com.epmet.feign;
+
+import com.epmet.commons.tools.constant.ServiceConstant;
+import com.epmet.commons.tools.utils.Result;
+import com.epmet.dto.CustomerGridDTO;
+import com.epmet.feign.fallback.GovOrgFeignClientFallBack;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+
+/**
+ * @Description
+ * @Author yinzuomei
+ * @Date 2020/3/18 11:11
+ */
+@FeignClient(name = ServiceConstant.GOV_ORG_SERVER, fallback = GovOrgFeignClientFallBack.class)
+public interface GovOrgFeignClient {
+ @GetMapping("gov/org/customergrid/getcustomergrid/{id}")
+ Result getcustomergrid(@PathVariable("id") String id);
+}
diff --git a/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/OperCrmFeignClient.java b/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/OperCrmFeignClient.java
index e446a0df2c..e2c52f4039 100644
--- a/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/OperCrmFeignClient.java
+++ b/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/OperCrmFeignClient.java
@@ -4,7 +4,7 @@ import com.epmet.commons.tools.constant.ServiceConstant;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.CustomerDTO;
import com.epmet.dto.result.ValidCustomerResultDTO;
-import com.epmet.feign.impl.OperCrmFeignClientFallBack;
+import com.epmet.feign.fallback.OperCrmFeignClientFallBack;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
diff --git a/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/fallback/AdminFeignClientFallback.java b/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/fallback/AdminFeignClientFallback.java
new file mode 100644
index 0000000000..1339aa4265
--- /dev/null
+++ b/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/fallback/AdminFeignClientFallback.java
@@ -0,0 +1,34 @@
+/**
+ * Copyright (c) 2018 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.epmet.feign.fallback;
+
+import com.epmet.commons.tools.security.user.UserDetail;
+import com.epmet.commons.tools.utils.Result;
+import com.epmet.feign.AdminFeignClient;
+import org.springframework.stereotype.Component;
+
+/**
+ * 用户接口 Fallback
+ *
+ * @author Mark sunlightcs@gmail.com
+ * @since 1.0.0
+ */
+@Component
+public class AdminFeignClientFallback implements AdminFeignClient {
+
+ @Override
+ public Result getById(Long id) {
+ return new Result<>();
+ }
+
+ @Override
+ public Result getByUsername(String username) {
+ return new Result<>();
+ }
+}
diff --git a/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallback.java b/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallback.java
new file mode 100644
index 0000000000..68ae3f7db1
--- /dev/null
+++ b/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/fallback/EpmetUserFeignClientFallback.java
@@ -0,0 +1,15 @@
+package com.epmet.feign.fallback;
+
+import com.epmet.feign.EpmetUserFeignClient;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Description
+ * @Author yinzuomei
+ * @Date 2020/3/16 14:53
+ */
+@Component
+public class EpmetUserFeignClientFallback implements EpmetUserFeignClient {
+
+
+}
diff --git a/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/fallback/GovOrgFeignClientFallBack.java b/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/fallback/GovOrgFeignClientFallBack.java
new file mode 100644
index 0000000000..f1540af47a
--- /dev/null
+++ b/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/fallback/GovOrgFeignClientFallBack.java
@@ -0,0 +1,21 @@
+package com.epmet.feign.fallback;
+
+import com.epmet.commons.tools.constant.ServiceConstant;
+import com.epmet.commons.tools.utils.ModuleUtils;
+import com.epmet.commons.tools.utils.Result;
+import com.epmet.dto.CustomerGridDTO;
+import com.epmet.feign.GovOrgFeignClient;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Description
+ * @Author yinzuomei
+ * @Date 2020/3/18 11:13
+ */
+@Component
+public class GovOrgFeignClientFallBack implements GovOrgFeignClient {
+ @Override
+ public Result getcustomergrid(String id) {
+ return ModuleUtils.feignConError(ServiceConstant.GOV_ORG_SERVER, "getcustomergrid",id);
+ }
+}
diff --git a/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/impl/OperCrmFeignClientFallBack.java b/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/fallback/OperCrmFeignClientFallBack.java
similarity index 96%
rename from epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/impl/OperCrmFeignClientFallBack.java
rename to epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/fallback/OperCrmFeignClientFallBack.java
index 52215b48d4..55374aa025 100644
--- a/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/impl/OperCrmFeignClientFallBack.java
+++ b/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/feign/fallback/OperCrmFeignClientFallBack.java
@@ -1,4 +1,4 @@
-package com.epmet.feign.impl;
+package com.epmet.feign.fallback;
import com.epmet.commons.tools.constant.ServiceConstant;
import com.epmet.commons.tools.utils.ModuleUtils;
diff --git a/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/service/DemoService.java b/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/service/DemoService.java
index ab5a997da0..2a69c04bd5 100644
--- a/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/service/DemoService.java
+++ b/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/service/DemoService.java
@@ -19,8 +19,10 @@ package com.epmet.service;
import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.commons.tools.page.PageData;
+import com.epmet.commons.tools.security.user.UserDetail;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.CustomerDTO;
+import com.epmet.dto.CustomerGridDTO;
import com.epmet.dto.DemoDTO;
import com.epmet.dto.form.SaveCustomerFormDTO;
import com.epmet.dto.result.ValidCustomerResultDTO;
@@ -104,4 +106,8 @@ public interface DemoService extends BaseService {
Result queryCustomerInfo(String customerId);
Result saveCustomerInfo(SaveCustomerFormDTO dto);
+
+ Result getcustomergrid(String id);
+
+ Result getSysUserInfoById(Long id);
}
diff --git a/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/service/impl/DemoServiceImpl.java b/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/service/impl/DemoServiceImpl.java
index 9299b20ddd..cbe78d61ca 100644
--- a/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/service/impl/DemoServiceImpl.java
+++ b/epmet-module/epmet-demo/epmet-demo-server/src/main/java/com/epmet/service/impl/DemoServiceImpl.java
@@ -22,14 +22,18 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.page.PageData;
+import com.epmet.commons.tools.security.user.UserDetail;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dao.DemoDao;
import com.epmet.dto.CustomerDTO;
+import com.epmet.dto.CustomerGridDTO;
import com.epmet.dto.DemoDTO;
import com.epmet.dto.form.SaveCustomerFormDTO;
import com.epmet.dto.result.ValidCustomerResultDTO;
import com.epmet.entity.DemoEntity;
+import com.epmet.feign.AdminFeignClient;
+import com.epmet.feign.GovOrgFeignClient;
import com.epmet.feign.OperCrmFeignClient;
import com.epmet.redis.DemoRedis;
import com.epmet.service.DemoService;
@@ -41,7 +45,6 @@ import org.springframework.transaction.annotation.Transactional;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
-import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -58,6 +61,10 @@ public class DemoServiceImpl extends BaseServiceImpl implem
private DemoRedis demoRedis;
@Autowired
private OperCrmFeignClient operCrmFeignClient;
+ @Autowired
+ private GovOrgFeignClient govOrgFeignClient;
+ @Autowired
+ private AdminFeignClient adminFeignClient;
@Override
public PageData page(Map params) {
IPage page = baseDao.selectPage(
@@ -147,4 +154,13 @@ public class DemoServiceImpl extends BaseServiceImpl implem
return operCrmFeignClient.saveCustomerInfo(dto);
}
+ @Override
+ public Result getcustomergrid(String id) {
+ return govOrgFeignClient.getcustomergrid(id);
+ }
+
+ @Override
+ public Result getSysUserInfoById(Long id) {
+ return adminFeignClient.getById(id);
+ }
}
diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/GovOrgApplication.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/GovOrgApplication.java
index 7f1f254652..d4cafe7020 100644
--- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/GovOrgApplication.java
+++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/GovOrgApplication.java
@@ -10,6 +10,8 @@ package com.epmet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.cloud.openfeign.EnableFeignClients;
/**
*
@@ -18,6 +20,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* @since 1.0.0
*/
@SpringBootApplication
+@EnableDiscoveryClient
+@EnableFeignClients
public class GovOrgApplication {
public static void main(String[] args) {
diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/CustomerGridController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/CustomerGridController.java
index be74383365..9e8eed6436 100644
--- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/CustomerGridController.java
+++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/CustomerGridController.java
@@ -37,7 +37,7 @@ import java.util.Map;
/**
- * 客户网格表
+ * 客户网格表
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2020-03-16
@@ -45,7 +45,7 @@ import java.util.Map;
@RestController
@RequestMapping("customergrid")
public class CustomerGridController {
-
+
@Autowired
private CustomerGridService customerGridService;
@@ -91,4 +91,9 @@ public class CustomerGridController {
ExcelUtils.exportExcelToTarget(response, null, list, CustomerGridExcel.class);
}
-}
\ No newline at end of file
+ @GetMapping("getcustomergrid/{id}")
+ public Result getcustomergrid(@PathVariable("id") String id){
+ CustomerGridDTO data = customerGridService.get(id);
+ return new Result().ok(data);
+ }
+}