diff --git a/epmet-commons/epmet-commons-openapi/pom.xml b/epmet-commons/epmet-commons-openapi/pom.xml
new file mode 100644
index 0000000000..41093f03fa
--- /dev/null
+++ b/epmet-commons/epmet-commons-openapi/pom.xml
@@ -0,0 +1,15 @@
+
+
+
+ epmet-commons
+ com.epmet
+ 2.0.0
+
+ 4.0.0
+
+ epmet-commons-openapi
+
+
+
diff --git a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/AuthTypes.java b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/AuthTypes.java
new file mode 100644
index 0000000000..4f1c94af10
--- /dev/null
+++ b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/AuthTypes.java
@@ -0,0 +1,8 @@
+package com.epmet.openapi.constant;
+
+/**
+ * 认证方式
+ */
+public interface AuthTypes {
+ String TAKE_TOKEN = "take_token";
+}
diff --git a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/InClusterHeaderKeys.java b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/InClusterHeaderKeys.java
new file mode 100644
index 0000000000..e2d0b2ca18
--- /dev/null
+++ b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/InClusterHeaderKeys.java
@@ -0,0 +1,10 @@
+package com.epmet.openapi.constant;
+
+/**
+ * 集群内的Header key
+ */
+public interface InClusterHeaderKeys {
+
+ String APP_ID = "AppId";
+
+}
diff --git a/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/RequestParamKeys.java b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/RequestParamKeys.java
new file mode 100644
index 0000000000..b1d6bae806
--- /dev/null
+++ b/epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/RequestParamKeys.java
@@ -0,0 +1,14 @@
+package com.epmet.openapi.constant;
+
+/**
+ * url请求参数key
+ */
+public class RequestParamKeys {
+
+ public static String APP_ID = "app_id";
+ public static String AUTH_TYPE = "auth_type";
+ public static String TIMESTAMP = "timestamp";
+ public static String SIGN = "sign";
+ public static String NONCE = "nonce";
+
+}
diff --git a/epmet-commons/epmet-commons-security/pom.xml b/epmet-commons/epmet-commons-security/pom.xml
new file mode 100644
index 0000000000..a4bebe4c54
--- /dev/null
+++ b/epmet-commons/epmet-commons-security/pom.xml
@@ -0,0 +1,26 @@
+
+
+
+ epmet-commons
+ com.epmet
+ 2.0.0
+
+ 4.0.0
+
+ epmet-commons-security
+
+
+
+ com.epmet
+ epmet-commons-tools
+ 2.0.0
+
+
+ io.jsonwebtoken
+ jjwt
+ 0.7.0
+
+
+
\ No newline at end of file
diff --git a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/jwt/JwtUtils.java b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/jwt/JwtUtils.java
new file mode 100644
index 0000000000..8df0b6cd8f
--- /dev/null
+++ b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/jwt/JwtUtils.java
@@ -0,0 +1,131 @@
+/**
+ * Copyright (c) 2018 人人开源 All rights reserved.
+ *
+ * https://www.renren.io
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.epmet.commons.security.jwt;
+
+import io.jsonwebtoken.Claims;
+import io.jsonwebtoken.Jwts;
+import io.jsonwebtoken.SignatureAlgorithm;
+import org.joda.time.DateTime;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Jwt工具类
+ *
+ * @author Mark sunlightcs@gmail.com
+ * @since 1.0.0
+ */
+@Component
+public class JwtUtils {
+ private static final Logger logger = LoggerFactory.getLogger(JwtUtils.class);
+
+ public Claims getClaimByToken(String token, String secret) {
+ try {
+ return Jwts.parser()
+ .setSigningKey(secret)
+ .parseClaimsJws(token)
+ .getBody();
+ } catch (Exception e) {
+ logger.debug("validate is token error, token = " + token, e);
+ return null;
+ }
+ }
+
+ /**
+ * @return java.util.Date
+ * @param token
+ * @Author yinzuomei
+ * @Description 获取token的有效期截止时间
+ * @Date 2020/3/18 22:17
+ **/
+ public Date getExpiration(String token, String secret){
+ try {
+ return Jwts.parser()
+ .setSigningKey(secret)
+ .parseClaimsJws(token)
+ .getBody().getExpiration();
+ } catch (Exception e) {
+ logger.debug("validate is token error, token = " + token, e);
+ return null;
+ }
+ }
+
+ /**
+ * @return java.lang.String
+ * @Author yinzuomei
+ * @Description 根据app+client+userId生成token
+ * @Date 2020/3/18 22:29
+ **/
+ public String createToken(Map claims, int expire, String secret) {
+ return Jwts.builder()
+ .setHeaderParam("typ", "JWT")
+ .setClaims(claims)
+ .setIssuedAt(new Date())
+ .setExpiration(DateTime.now().plusSeconds(expire).toDate())
+ .signWith(SignatureAlgorithm.HS512, secret)
+ .compact();
+ }
+
+ /**
+ * @Description 创建Token
+ * @return Token
+ * @param claims 载荷信息
+ * @param expireTime 过期时间
+ * @param secret 秘钥
+ * @author wxz
+ * @date 2021.03.26 13:33
+ */
+ public String createToken(Map claims, Date expireTime, String secret) {
+ return Jwts.builder()
+ .setHeaderParam("typ", "JWT")
+ .setClaims(claims)
+ .setIssuedAt(new Date())
+ .setExpiration(expireTime)
+ .signWith(SignatureAlgorithm.HS512, secret)
+ .compact();
+ }
+
+ /**
+ * token是否过期
+ *
+ * @return true:过期
+ */
+ public boolean isTokenExpired(Date expiration) {
+ return expiration.before(new Date());
+ }
+
+ public static void main(String[] args) {
+ Map map=new HashMap<>();
+ map.put("app","gov");
+ map.put("client","wxmp");
+ map.put("userId","100526ABC");
+ String tokenStr=Jwts.builder()
+ .setHeaderParam("typ", "JWT")
+ .setClaims(map)
+ .setIssuedAt(new Date())
+ .setExpiration(DateTime.now().plusSeconds(604800).toDate())
+ .signWith(SignatureAlgorithm.HS512, "7016867071f0ebf1c46f123eaaf4b9d6[elink.epmet]")
+ .compact();
+ System.out.println(tokenStr);
+ Claims claims= Jwts.parser()
+ .setSigningKey("7016867071f0ebf1c46f123eaaf4b9d6[elink.epmet]")
+ .parseClaimsJws(tokenStr)
+ .getBody();
+ System.out.println("app="+ claims.get("app"));
+ System.out.println("client="+ claims.get("client"));
+ System.out.println("userId="+ claims.get("userId"));
+ }
+
+}
diff --git a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java
new file mode 100644
index 0000000000..1de1b04f73
--- /dev/null
+++ b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java
@@ -0,0 +1,109 @@
+package com.epmet.commons.security.sign.openapi;
+
+import com.epmet.commons.tools.utils.Md5Util;
+
+import java.util.*;
+
+/**
+ * OpenApi签名工具
+ */
+public class OpenApiSignUtils {
+
+ /**
+ * @Description 创建签名
+ * @return
+ * @author wxz
+ * @date 2021.03.22 16:47
+ */
+ public static String createSign(Map contentMap, String signKey) {
+ String str2beSigned = mapToSignStr(contentMap);
+ str2beSigned = str2beSigned.concat("&sign_key=").concat(signKey);
+ return Md5Util.md5(str2beSigned);
+ }
+
+ /**
+ * @Description 验签
+ * @return
+ * @author wxz
+ * @date 2021.03.22 16:51
+ */
+ public static boolean checkSign(Map contentMap, String signKey) {
+ String newSign = createSign(contentMap, signKey);
+ return newSign.equals(contentMap.get("sign"));
+ }
+
+ /**
+ * @Description map转化为签名明文
+ * @return
+ * @author wxz
+ * @date 2021.03.22 16:47
+ */
+ public static String mapToSignStr(Map map) {
+ Set keySet = map.keySet();
+ String[] keyArray = (String[])keySet.toArray(new String[keySet.size()]);
+ Arrays.sort(keyArray);
+ StringBuilder sb = new StringBuilder();
+
+ for(int i = 0; i < keyArray.length; ++i) {
+ String key = keyArray[i];
+ String val = (String)map.get(key);
+ if (val != null && val.trim().length() > 0 && !"sign".equals(key)) {
+ if (!sb.toString().isEmpty()) {
+ sb.append("&");
+ }
+
+ sb.append(key).append("=").append((String)map.get(key));
+ }
+ }
+
+ return sb.toString();
+ }
+
+ public static void main(String[] args) {
+ generateGetAccessTokenSign();
+ System.out.println("==============");
+ generateGetOrgDetailSign();
+ }
+
+ private static void generateGetAccessTokenSign() {
+ long now = System.currentTimeMillis();
+ System.out.println(now);
+
+ String uuid = UUID.randomUUID().toString().replace("-", "");
+
+ HashMap content = new HashMap<>();
+ content.put("app_id", "7d98b8af2d05752b4225709c4cfd4bd0");
+ content.put("timestamp", String.valueOf(now));
+ content.put("nonce", uuid);
+ content.put("auth_type", "take_token");
+
+ String secret = "3209ee9f41704482be1a1fb5873a25376f2899191ca846119d44168316bc3e44";
+
+ String sign = createSign(content, secret);
+
+ System.out.println("时间戳:" + now);
+ System.out.println("随机数:" + uuid);
+ System.out.println("签名:" + sign);
+ }
+
+ private static void generateGetOrgDetailSign() {
+ long now = System.currentTimeMillis();
+ String uuid = UUID.randomUUID().toString().replace("-", "");;
+ System.out.println("时间戳:" + now);
+ System.out.println("随机数:" + uuid);
+
+ HashMap content = new HashMap<>();
+ //content.put("orgId", "aaa");
+ //content.put("test", null);
+ content.put("gridId", "12128e0f614f1c00a058ea9a107033b2");
+ content.put("app_id", "7d98b8af2d05752b4225709c4cfd4bd0");
+ content.put("timestamp", String.valueOf(now));
+ content.put("nonce", uuid);
+ content.put("auth_type", "take_token");
+
+ String secret = "3209ee9f41704482be1a1fb5873a25376f2899191ca846119d44168316bc3e44";
+
+ String sign = createSign(content, secret);
+ System.out.println("签名:" + sign);
+ }
+}
diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aspect/BaseRequestLogAspect.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aspect/BaseRequestLogAspect.java
index bdff667e81..1df41d92ae 100644
--- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aspect/BaseRequestLogAspect.java
+++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aspect/BaseRequestLogAspect.java
@@ -84,7 +84,7 @@ public abstract class BaseRequestLogAspect {
return result;
} catch (ValidateException e) {
result = handleValidateException(e);
- resultErrorLog(transactionSerial, getExecPeriod(startTime), result, e.getMsg(), ExceptionUtils.getErrorStackTrace(e));
+ resultWarnLog(transactionSerial, getExecPeriod(startTime), result, e.getMsg(), ExceptionUtils.getErrorStackTrace(e));
} catch (DuplicateKeyException e) {
result = handlerDuplicateKeyException(e);
resultErrorLog(transactionSerial, getExecPeriod(startTime), result, e.getMessage(), ExceptionUtils.getErrorStackTrace(e));
diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java
index 210f2d3443..5673b272f1 100644
--- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java
+++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java
@@ -149,7 +149,16 @@ public enum EpmetErrorCode {
TOPIC_IS_CLOSED(9008,"该话题已关闭,无法转为议题"),
CUSTOMER_CATEGORY(9101,"分类已使用,不允许删除"),
- CATEGORY_NAME(9102,"分类名称已存在,不允许重复");
+ CATEGORY_NAME(9102,"分类名称已存在,不允许重复"),
+
+ // open api异常
+ OPEN_API_UNAUTHENTICATED(10100, "请求未认证"),
+ OPEN_API_TOKEN_EXPIRED(10102, "Token过期"),
+ OPEN_API_PARAMS_MISSING(10103, "参数不完整"),
+ OPEN_API_SIGN_ERROR(10104, "签名错误"),
+ OPEN_API_PARAMS_APPID_DIFF(10105, "app_id不一致"), // app_id在请求参数中和在token中不一致
+ OPEN_API_REQUEST_EXPIRED(10106, "请求过期"),
+ OPEN_API_REQUEST_REPEAT(10107, "请求重复");
private int code;
private String msg;
diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java
index d5fe7e02b1..3a18918430 100644
--- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java
+++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java
@@ -382,21 +382,23 @@ public class RedisKeys {
}
/**
- * 一个客户对应多个第三方平台,多个ApiService的key
- * @param customerId
+ * @Description 获取openApi的accessToken的key
* @return
- */
- public static String listCustomerApiServiceListKey(String customerId) {
- return rootPrefix.concat("customer:thirdplat:apiservicelist:").concat(customerId);
+ * @author wxz
+ * @date 2021.03.23 10:25
+ */
+ public static String getOpenApiAccessTokenKey(String appId) {
+ return rootPrefix.concat("openapi:accesstoken:").concat(appId);
}
/**
- * 查询第三方平台access token
- * @param platformId
+ * @Description 获取OpenApi请求随机数nonce
* @return
- */
- public static String getThirdPlatformAccessTokenKey(String platformId) {
- return rootPrefix.concat("thirdplatform:accesstoken:").concat(platformId);
+ * @author wxz
+ * @date 2021.03.24 17:49
+ */
+ public static String getOpenApiNonceKey(String nonce) {
+ return rootPrefix.concat("openapi:nonce:").concat(nonce);
}
/**
@@ -410,4 +412,22 @@ public class RedisKeys {
public static String getOssFileKey(String path) {
return rootPrefix.concat("oss:temp:").concat(path);
}
+
+ /**
+ * 一个客户对应多个第三方平台,多个ApiService的key
+ * @param customerId
+ * @return
+ */
+ public static String listCustomerApiServiceListKey(String customerId) {
+ return rootPrefix.concat("customer:thirdplat:apiservicelist:").concat(customerId);
+ }
+
+ /**
+ * 查询第三方平台access token
+ * @param platformId
+ * @return
+ */
+ public static String getThirdPlatformAccessTokenKey(String platformId) {
+ return rootPrefix.concat("thirdplatform:accesstoken:").concat(platformId);
+ }
}
diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ConvertUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ConvertUtils.java
index 93c653e178..6d2e509797 100644
--- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ConvertUtils.java
+++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ConvertUtils.java
@@ -12,11 +12,14 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.*;
/**
* 转换工具类
@@ -87,4 +90,33 @@ public class ConvertUtils {
}
return t;
}
+
+ /**
+ * @Description entity转map
+ * @return
+ * @author wxz
+ * @date 2021.03.22 16:38
+ */
+ public static Map entityToMap(Object bean) throws IntrospectionException, InvocationTargetException, IllegalAccessException {
+ Class> type = bean.getClass();
+ Map returnMap = new HashMap(16);
+ BeanInfo beanInfo = Introspector.getBeanInfo(type);
+ PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+
+ for(int i = 0; i < propertyDescriptors.length; ++i) {
+ PropertyDescriptor descriptor = propertyDescriptors[i];
+ String propertyName = descriptor.getName();
+ if (!"class".equals(propertyName)) {
+ Method readMethod = descriptor.getReadMethod();
+ Object result = readMethod.invoke(bean);
+ if (result != null) {
+ returnMap.put(propertyName, String.valueOf(result));
+ } else {
+ returnMap.put(propertyName, "");
+ }
+ }
+ }
+
+ return returnMap;
+ }
}
diff --git a/epmet-commons/pom.xml b/epmet-commons/pom.xml
index 636480c48f..9e0d315827 100644
--- a/epmet-commons/pom.xml
+++ b/epmet-commons/pom.xml
@@ -25,6 +25,8 @@
epmet-commons-extapp-auth
epmet-commons-thirdplat
epmet-commons-rocketmq
+ epmet-commons-security
+ epmet-commons-openapi
diff --git a/epmet-gateway/pom.xml b/epmet-gateway/pom.xml
index 08eda7167e..af02a2054c 100644
--- a/epmet-gateway/pom.xml
+++ b/epmet-gateway/pom.xml
@@ -13,6 +13,11 @@
jar
+
+ com.epmet
+ epmet-commons-security
+ 2.0.0
+
com.epmet
epmet-commons-tools
@@ -65,6 +70,17 @@
common-service-client
2.0.0
+
+ com.epmet
+ epmet-commons-openapi
+ 2.0.0
+ compile
+
+
+ com.epmet
+ epmet-commons-openapi
+ 2.0.0
+
@@ -298,8 +314,8 @@
lb://gov-project-server
- lb://common-service-server
-
+
+ http://localhost:8103
lb://resi-home-server
@@ -329,8 +345,8 @@
lb://epmet-point-server
- lb://epmet-ext-server
-
+
+ http://127.0.0.1:8113
lb://data-aggregator-server
diff --git a/epmet-gateway/src/main/java/com/epmet/auth/ExtAppTakeTokenAuthProcessor.java b/epmet-gateway/src/main/java/com/epmet/auth/ExtAppTakeTokenAuthProcessor.java
new file mode 100644
index 0000000000..6b527dc074
--- /dev/null
+++ b/epmet-gateway/src/main/java/com/epmet/auth/ExtAppTakeTokenAuthProcessor.java
@@ -0,0 +1,91 @@
+package com.epmet.auth;
+
+import com.epmet.commons.security.jwt.JwtUtils;
+import com.epmet.commons.security.sign.openapi.OpenApiSignUtils;
+import com.epmet.commons.tools.exception.EpmetErrorCode;
+import com.epmet.commons.tools.exception.RenException;
+import com.epmet.commons.tools.redis.RedisKeys;
+import com.epmet.commons.tools.redis.RedisUtils;
+import com.epmet.commons.tools.utils.Result;
+import com.epmet.commons.tools.utils.SpringContextUtils;
+import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
+import com.epmet.openapi.constant.InClusterHeaderKeys;
+import com.epmet.openapi.constant.RequestParamKeys;
+import io.jsonwebtoken.Claims;
+import io.jsonwebtoken.Jwts;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.server.reactive.ServerHttpRequest;
+import org.springframework.stereotype.Component;
+import org.springframework.web.server.ServerWebExchange;
+
+import java.util.Date;
+
+/**
+ * 外部应用认证处理器:来平台token的方式
+ */
+@Component
+public class ExtAppTakeTokenAuthProcessor extends ExtAppAuthProcessor {
+
+ @Autowired
+ private JwtUtils jwtTokenUtils;
+
+ @Autowired
+ private RedisUtils redisUtils;
+
+ @Override
+ public void auth(String appId, String token, Long ts, ServerWebExchange exchange) {
+ String secret = getSecret(appId);
+
+ // 1.过期验证
+ String accessTokenInCache = redisUtils.getString(RedisKeys.getOpenApiAccessTokenKey(appId));
+ Date expiration = jwtTokenUtils.getExpiration(token, secret);
+ if (StringUtils.isBlank(accessTokenInCache) ||
+ expiration == null ||
+ jwtTokenUtils.isTokenExpired(expiration)
+ ) {
+
+ throw new RenException(EpmetErrorCode.OPEN_API_TOKEN_EXPIRED.getCode(),
+ EpmetErrorCode.OPEN_API_TOKEN_EXPIRED.getMsg());
+ }
+
+ // 2.验签
+ // 验签暂时放到具体接口中,不放在gateway
+ //openApiSignUtils.checkSign();
+
+ // 2. 获取claims
+ Claims claims = jwtTokenUtils.getClaimByToken(token, secret);
+ String appIdInAccessToken = claims.get(RequestParamKeys.APP_ID, String.class);
+
+ if (!appId.equals(appIdInAccessToken)) {
+ // 参数列表的appId和token中封装的不一致
+ throw new RenException(EpmetErrorCode.OPEN_API_PARAMS_APPID_DIFF.getCode(),
+ EpmetErrorCode.OPEN_API_PARAMS_APPID_DIFF.getMsg());
+ }
+
+ // 3.将app_id放入header中
+ ServerHttpRequest.Builder mutate = exchange.getRequest().mutate();
+ mutate.header(InClusterHeaderKeys.APP_ID, new String[]{appId});
+ exchange.mutate().request(mutate.build()).build();
+ }
+
+ /**
+ * @return
+ * @Description 获取秘钥
+ * @author wxz
+ * @date 2021.03.23 14:12
+ */
+ private String getSecret(String appId) {
+ EpmetCommonServiceOpenFeignClient commonService = SpringContextUtils.getBean(EpmetCommonServiceOpenFeignClient.class);
+ Result result = commonService.getSecret(appId);
+ if (result == null || !result.success()) {
+ throw new RenException("fetchToken方式的外部应用认证,获取secret失败");
+ }
+ String secret = result.getData();
+ if (StringUtils.isBlank(secret)) {
+ throw new RenException("fetchToken方式的外部应用认证,获取secret失败");
+ }
+
+ return secret;
+ }
+}
diff --git a/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java b/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java
index 8af2cdd5ef..d21ec692c5 100644
--- a/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java
+++ b/epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java
@@ -4,6 +4,9 @@ import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.filter.CpProperty;
+import com.epmet.openapi.constant.AuthTypes;
+import com.epmet.openapi.constant.RequestParamKeys;
+import com.epmet.utils.ServerHttpRequestUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -13,6 +16,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher;
+import org.springframework.util.MultiValueMap;
import org.springframework.web.server.ServerWebExchange;
/**
@@ -31,17 +35,23 @@ public class ExternalAuthProcessor extends AuthProcessor {
public static final String APP_ID_CUSTOMER_ID_KEY = "CustomerId";
public static final String APP_ID_AUTY_TYPE_KEY = "AuthType";
- // 认证方式
+ /**
+ * 认证方式
+ */
+ // 调用方生成jwt
public static final String APP_AUTH_TYPE_JWT = "jwt";
+ // 调用方生成md5
public static final String APP_AUTH_TYPE_MD5 = "md5";
-
@Autowired
private ExtAppJwtAuthProcessor jwtAuthProcessor;
@Autowired
private ExtAppMD5AuthProcessor md5AuthProcessor;
+ @Autowired
+ private ExtAppTakeTokenAuthProcessor takeTokenAuthProcessor;
+
private final AntPathMatcher antPathMatcher = new AntPathMatcher();
@Autowired
@@ -58,6 +68,7 @@ public class ExternalAuthProcessor extends AuthProcessor {
for (String url : cpProperty.getExternalOpenUrls()) {
if (antPathMatcher.match(url, requestUri)) {
inPaths = true;
+ break;
}
}
@@ -65,27 +76,46 @@ public class ExternalAuthProcessor extends AuthProcessor {
throw new RenException(EpmetErrorCode.ERR401.getCode(), "所请求的url并未对外部应用开放");
}
+ // 放行白名单
+ for (String url : cpProperty.getExternalAuthUrlsWhiteList()) {
+ if (antPathMatcher.match(url, requestUri)) {
+ return exchange;
+ }
+ }
+
HttpHeaders headers = request.getHeaders();
String token = headers.getFirst(ACCESS_TOKEN_HEADER_KEY);
- String appId = headers.getFirst(APP_ID_HEADER_KEY);
String ts = headers.getFirst(APP_ID_TIMESTAMP_KEY);
String customerId = headers.getFirst(APP_ID_CUSTOMER_ID_KEY);
- String authType = headers.getFirst(APP_ID_AUTY_TYPE_KEY);
-
- if (StringUtils.isAnyBlank(token, appId)) {
- throw new RenException(EpmetErrorCode.ERR401.getCode(), "请求头中的AccessToken和AppId不能为空");
- }
+ String authType = getAuthType(headers, request);
- logger.info("外部应用请求认证拦截Aspect执行,appId:{}, token:{}, ts:{}, customerId:{}, authType:{}",
- appId, token, ts, customerId, authType);
+ logger.info("外部应用请求认证拦截Aspect执行,token:{}, ts:{}, customerId:{}, authType:{}",
+ token, ts, customerId, authType);
// 没传authType或者传的jwt都用jwtprocessor处理
try {
if (StringUtils.isBlank(authType) || APP_AUTH_TYPE_JWT.equals(authType)) {
+ String appId = headers.getFirst(APP_ID_HEADER_KEY);
+ if (StringUtils.isAnyBlank(token, appId)) {
+ throw new RenException(EpmetErrorCode.ERR401.getCode(), "请求头中的AccessToken和AppId不能为空");
+ }
jwtAuthProcessor.auth(appId, token, StringUtils.isNotBlank(ts) ? new Long(ts) : null, exchange);
} else if (APP_AUTH_TYPE_MD5.equals(authType)) {
+ String appId = headers.getFirst(APP_ID_HEADER_KEY);
+ if (StringUtils.isAnyBlank(token, appId)) {
+ throw new RenException(EpmetErrorCode.ERR401.getCode(), "请求头中的AccessToken和AppId不能为空");
+ }
md5AuthProcessor.auth(appId, token, StringUtils.isNotBlank(ts) ? new Long(ts) : null, exchange);
+ } else if (AuthTypes.TAKE_TOKEN.equals(authType)) {
+ if (StringUtils.isBlank(token)) {
+ throw new RenException(EpmetErrorCode.OPEN_API_UNAUTHENTICATED.getCode());
+ }
+ String appId = ServerHttpRequestUtils.getRequestParam(request, RequestParamKeys.APP_ID);
+ if (StringUtils.isBlank(appId)) {
+ throw new RenException(EpmetErrorCode.OPEN_API_PARAMS_MISSING.getCode(),"缺少参数:".concat(RequestParamKeys.APP_ID));
+ }
+ takeTokenAuthProcessor.auth(appId, token, StringUtils.isNotBlank(ts) ? new Long(ts) : null, exchange);
} else {
throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_AUTH_ERROR.getCode(), "未知的外部认证类型");
}
@@ -100,4 +130,12 @@ public class ExternalAuthProcessor extends AuthProcessor {
return exchange;
}
+
+ private String getAuthType(HttpHeaders headers, ServerHttpRequest request) {
+ String authType = ServerHttpRequestUtils.getRequestParam(request, RequestParamKeys.AUTH_TYPE);
+ if (StringUtils.isBlank(authType)) {
+ authType = headers.getFirst(APP_ID_AUTY_TYPE_KEY);
+ }
+ return authType;
+ }
}
diff --git a/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java b/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java
index bb97dc2be7..9e6d7ef077 100644
--- a/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java
+++ b/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java
@@ -10,6 +10,9 @@ import com.epmet.commons.tools.utils.IpUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.constant.AuthTypeConstant;
import com.epmet.constant.TokenHeaderKeyConstant;
+import com.epmet.openapi.constant.AuthTypes;
+import com.epmet.openapi.constant.RequestParamKeys;
+import com.epmet.utils.ServerHttpRequestUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -111,6 +114,11 @@ public class CpAuthGatewayFilterFactory extends AbstractGatewayFilterFactory externalOpenUrls;
+ /**
+ * 对外开放url白名单
+ */
+ private List externalAuthUrlsWhiteList;
+
/**
* 不处理token,直接通过
*/
diff --git a/epmet-gateway/src/main/java/com/epmet/utils/ServerHttpRequestUtils.java b/epmet-gateway/src/main/java/com/epmet/utils/ServerHttpRequestUtils.java
new file mode 100644
index 0000000000..334134baa1
--- /dev/null
+++ b/epmet-gateway/src/main/java/com/epmet/utils/ServerHttpRequestUtils.java
@@ -0,0 +1,19 @@
+package com.epmet.utils;
+
+import org.springframework.http.server.reactive.ServerHttpRequest;
+import org.springframework.util.MultiValueMap;
+
+public class ServerHttpRequestUtils {
+
+ /**
+ * @Description 从url中获取appId
+ * @return
+ * @author wxz
+ * @date 2021.03.25 15:13
+ */
+ public static String getRequestParam(ServerHttpRequest request, String paramName) {
+ MultiValueMap queryParams = request.getQueryParams();
+ return queryParams.getFirst(paramName);
+ }
+
+}
diff --git a/epmet-gateway/src/main/resources/bootstrap.yml b/epmet-gateway/src/main/resources/bootstrap.yml
index 973179c819..c9cdd6a23d 100644
--- a/epmet-gateway/src/main/resources/bootstrap.yml
+++ b/epmet-gateway/src/main/resources/bootstrap.yml
@@ -422,6 +422,10 @@ feign:
okhttp:
enabled: true
+#logging:
+# level:
+# com.epmet: debug
+
hystrix:
command:
default:
@@ -477,6 +481,11 @@ epmet:
- /epmetuser/customerstaff/customerlist
- /message/template/**
- /data/aggregator/project/projectdistribution
+
+ # 对外开放接口认证白名单
+ externalAuthUrlsWhiteList:
+ - /epmet/ext/open-api/get-access-token
+
swaggerUrls:
jwt:
diff --git a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/EpmetCommonServiceOpenFeignClient.java b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/EpmetCommonServiceOpenFeignClient.java
index 66a1f46ee7..296489af6e 100644
--- a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/EpmetCommonServiceOpenFeignClient.java
+++ b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/EpmetCommonServiceOpenFeignClient.java
@@ -20,7 +20,7 @@ import java.util.Map;
* @date 2020/6/4 10:28
*/
@FeignClient(name = ServiceConstant.EPMET_COMMON_SERVICE, fallback = EpmetCommonServiceOpenFeignClientFallback.class)
-// @FeignClient(name = ServiceConstant.EPMET_COMMON_SERVICE, fallback = EpmetCommonServiceOpenFeignClientFallback.class, url = "http://localhost:8103")
+ //@FeignClient(name = ServiceConstant.EPMET_COMMON_SERVICE, fallback = EpmetCommonServiceOpenFeignClientFallback.class, url = "http://192.168.1.132:8103")
public interface EpmetCommonServiceOpenFeignClient {
/**
* @param formDTO
diff --git a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/AreaCodeServiceImpl.java b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/AreaCodeServiceImpl.java
index 5e865cfc44..f34ff30605 100644
--- a/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/AreaCodeServiceImpl.java
+++ b/epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/AreaCodeServiceImpl.java
@@ -593,6 +593,7 @@ public class AreaCodeServiceImpl extends BaseServiceImpl list = childDao.selectByPCodeAndName(formDTO.getParentAreaCode().trim(), formDTO.getName().trim());
if (CollUtil.isNotEmpty(list)) {
throw new RenException("name已存在");
diff --git a/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/openapi/GetOrgDetailFormDTO.java b/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/openapi/GetOrgDetailFormDTO.java
new file mode 100644
index 0000000000..820225682a
--- /dev/null
+++ b/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/openapi/GetOrgDetailFormDTO.java
@@ -0,0 +1,15 @@
+package com.epmet.dto.form.openapi;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+
+@Data
+public class GetOrgDetailFormDTO extends OpenApiBaseFormDTO {
+
+ @NotBlank(message = "orgId不能为空")
+ private String orgId;
+
+ private String test;
+
+}
diff --git a/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/openapi/OpenApiBaseFormDTO.java b/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/openapi/OpenApiBaseFormDTO.java
new file mode 100644
index 0000000000..68f46e351b
--- /dev/null
+++ b/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/openapi/OpenApiBaseFormDTO.java
@@ -0,0 +1,31 @@
+package com.epmet.dto.form.openapi;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
+/**
+ * open api基础类
+ */
+@Data
+public class OpenApiBaseFormDTO {
+
+ public interface GetAccessTokenGroup {}
+
+ @NotBlank(message = "签名不能为空", groups = { GetAccessTokenGroup.class })
+ private String sign;
+
+ /**
+ * 时间戳,ms
+ */
+ @NotNull(message = "时间戳不能为空", groups = { GetAccessTokenGroup.class })
+ private Long timestamp;
+
+ /**
+ * 随机数,每次请求唯一
+ */
+ @NotBlank(message = "随机字段nonce不能为空", groups = { GetAccessTokenGroup.class })
+ private String nonce;
+
+}
diff --git a/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/result/openapi/GetAccessTokenResultDTO.java b/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/result/openapi/GetAccessTokenResultDTO.java
new file mode 100644
index 0000000000..a913b25945
--- /dev/null
+++ b/epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/result/openapi/GetAccessTokenResultDTO.java
@@ -0,0 +1,12 @@
+package com.epmet.dto.result.openapi;
+
+import lombok.Data;
+
+@Data
+public class GetAccessTokenResultDTO {
+
+ private String accessToken;
+
+ private Long expireTime;
+
+}
diff --git a/epmet-module/epmet-ext/epmet-ext-server/pom.xml b/epmet-module/epmet-ext/epmet-ext-server/pom.xml
index f33a428e27..9eda7325be 100644
--- a/epmet-module/epmet-ext/epmet-ext-server/pom.xml
+++ b/epmet-module/epmet-ext/epmet-ext-server/pom.xml
@@ -21,6 +21,21 @@
+
+ com.epmet
+ epmet-commons-openapi
+ 2.0.0
+
+
+ com.epmet
+ common-service-client
+ 2.0.0
+
+
+ com.epmet
+ epmet-commons-security
+ 2.0.0
+
com.epmet
epmet-ext-client
diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/annotation/OpenApiCheckSign.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/annotation/OpenApiCheckSign.java
new file mode 100644
index 0000000000..10bbcc156e
--- /dev/null
+++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/annotation/OpenApiCheckSign.java
@@ -0,0 +1,13 @@
+package com.epmet.annotation;
+
+import java.lang.annotation.*;
+
+/**
+ * OpenApi验签注解
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface OpenApiCheckSign {
+
+}
diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java
new file mode 100644
index 0000000000..c6f23cc779
--- /dev/null
+++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java
@@ -0,0 +1,218 @@
+package com.epmet.aspect;
+
+import com.epmet.commons.mybatis.aspect.DataFilterAspect;
+import com.epmet.commons.security.sign.openapi.OpenApiSignUtils;
+import com.epmet.commons.tools.exception.EpmetErrorCode;
+import com.epmet.commons.tools.exception.RenException;
+import com.epmet.commons.tools.redis.RedisKeys;
+import com.epmet.commons.tools.redis.RedisUtils;
+import com.epmet.commons.tools.utils.ConvertUtils;
+import com.epmet.commons.tools.utils.Result;
+import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
+import com.epmet.openapi.constant.RequestParamKeys;
+import org.apache.commons.lang3.StringUtils;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.context.request.RequestAttributes;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import javax.servlet.http.HttpServletRequest;
+import java.lang.reflect.Method;
+import java.lang.reflect.Parameter;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * OpenApi检查请求切面
+ * 1.验签防止参数篡改
+ * 2.timestamp+nonce防止请求重放攻击
+ */
+@Aspect
+@Component
+@Order(1)
+public class OpenApiRequestCheckAspect {
+
+ @Autowired
+ private RedisUtils redisUtils;
+
+ @Autowired
+ private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient;
+
+ //请求时差单位:s
+ long requestTimeSecDiff = 120;
+ //请求时差,单位:ms
+ long requestTimeMillSecDiff = requestTimeSecDiff * 1000;//单位:ms
+
+ private static final Logger log = LoggerFactory.getLogger(DataFilterAspect.class);
+
+ /**
+ * @Description 验签
+ * @return
+ * @author wxz
+ * @date 2021.03.24 13:39
+ */
+ @Before("execution(* com.epmet.controller.*Controller*.*(..)) && @annotation(com.epmet.annotation.OpenApiCheckSign)")
+ public void check(JoinPoint point) {
+ Object[] args = point.getArgs();
+ MethodSignature methodSignature = (MethodSignature) point.getSignature();
+ Method method = methodSignature.getMethod();
+ Parameter[] parameters = method.getParameters();
+
+ HttpServletRequest request = getRequest();
+
+ Map argMap = new HashMap<>();
+ for (int i = 0; i < parameters.length; i++) {
+ if (parameters[i].isAnnotationPresent(RequestBody.class)) {
+ try {
+ argMap = ConvertUtils.entityToMap(args[i]);
+ } catch (Exception e) {
+ throw new RenException("验签参数转化发生异常");
+ }
+
+ break;
+ }
+ }
+
+ fillRequestParamsInfoArgMap(argMap, request);
+ if (!OpenApiSignUtils.checkSign(argMap, getSecret(argMap.get(RequestParamKeys.APP_ID)))) {
+ // 验签失败
+ throw new RenException(EpmetErrorCode.OPEN_API_SIGN_ERROR.getCode());
+ }
+ checkRepeatRequest(argMap);
+ }
+
+ /**
+ * @Description 填充url请求参数到map中,用来签名
+ * @return
+ * @author wxz
+ * @date 2021.03.26 10:13
+ */
+ private void fillRequestParamsInfoArgMap(Map argMap, HttpServletRequest request) {
+ fillRequestParamsInfoArgMap(argMap, request, RequestParamKeys.APP_ID);
+ fillRequestParamsInfoArgMap(argMap, request, RequestParamKeys.AUTH_TYPE);
+ fillRequestParamsInfoArgMap(argMap, request, RequestParamKeys.NONCE);
+ fillRequestParamsInfoArgMap(argMap, request, RequestParamKeys.TIMESTAMP);
+ fillRequestParamsInfoArgMap(argMap, request, RequestParamKeys.SIGN);
+ }
+
+ private void fillRequestParamsInfoArgMap(Map argMap, HttpServletRequest request, String paramName) {
+ String paramValue = request.getParameter(paramName);
+ if (StringUtils.isNotBlank(paramName)) {
+ argMap.put(paramName, paramValue);
+ }
+ }
+
+ /**
+ * 检查请求重放
+ * @param argMap
+ */
+ void checkRepeatRequest(Map argMap) {
+ String timestampStr = argMap.get(RequestParamKeys.TIMESTAMP);
+ if (StringUtils.isBlank(timestampStr)) {
+ throw new RenException(EpmetErrorCode.OPEN_API_PARAMS_MISSING.getCode());
+ }
+ long timestamp = Long.valueOf(timestampStr).longValue();
+ long now = System.currentTimeMillis();
+
+ if (Math.abs(now - timestamp) > requestTimeMillSecDiff) {
+ // 只允许1分钟之内的请求,允许服务器之间时差为1分钟
+ throw new RenException(EpmetErrorCode.OPEN_API_REQUEST_EXPIRED.getCode(),
+ String.format("请求已过期,允许时差为%s s", requestTimeSecDiff));
+ }
+ String nonce = argMap.get(RequestParamKeys.NONCE);
+ String nonceInCache = redisUtils.getString(RedisKeys.getOpenApiNonceKey(nonce));
+ if (StringUtils.isNotBlank(nonceInCache)) {
+ throw new RenException(EpmetErrorCode.OPEN_API_REQUEST_REPEAT.getCode());
+ }
+ //将nonce缓存到redis,有效期1分钟
+ redisUtils.set(RedisKeys.getOpenApiNonceKey(nonce), System.currentTimeMillis(), requestTimeSecDiff);
+ }
+
+ /**
+ * @return
+ * @Description 取secret
+ * @author wxz
+ * @date 2021.03.24 12:49
+ */
+ private String getSecret(String appId) {
+ String secret = (String) redisUtils.get(RedisKeys.getExternalAppSecretKey(appId));
+ if (StringUtils.isBlank(secret)) {
+ Result result = commonServiceOpenFeignClient.getSecret(appId);
+ if (!result.success()) {
+ throw new RenException("调用common service查询secret失败");
+ }
+ secret = result.getData();
+ if (StringUtils.isBlank(secret)) {
+ throw new RenException(String.format("根据appId%s没有找到对应的secret", appId));
+ }
+ redisUtils.set(RedisKeys.getExternalAppSecretKey(appId), secret);
+ }
+ return secret;
+ }
+
+ /**
+ * @return
+ * @Description 获取request
+ * @author wxz
+ * @date 2021.03.24 12:52
+ */
+ public HttpServletRequest getRequest() {
+ RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
+ ServletRequestAttributes sra = (ServletRequestAttributes) requestAttributes;
+ return sra.getRequest();
+ }
+
+ /**
+ * @return
+ * @Description 获取appId
+ * @author wxz
+ * @date 2021.03.24 12:53
+ */
+ //public String getAppId(Parameter[] parameters, Object[] args) {
+ // HttpServletRequest request = getRequest();
+ // String appId = request.getHeader("AppId");
+ // if (StringUtils.isBlank(appId)) {
+ // for (int i = 0; i < parameters.length; i++) {
+ // if (parameters[i].isAnnotationPresent(RequestBody.class)) {
+ // Object arg = args[i];
+ // try {
+ // appId = getAppIdFromDTO(arg);
+ // } catch (IllegalAccessException e) {
+ // e.printStackTrace();
+ // }
+ // }
+ // }
+ // }
+ // if (StringUtils.isBlank(appId)) {
+ // throw new RenException("未携带AppId");
+ // }
+ // return appId;
+ //}
+
+ //private String getAppIdFromDTO(Object dto) throws IllegalAccessException {
+ // Field[] declaredFields = dto.getClass().getDeclaredFields();
+ // for (int i = 0; i < declaredFields.length; i++) {
+ // Field field = declaredFields[i];
+ // String fieldName = field.getName();
+ // if ("appId".equals(fieldName)) {
+ // field.setAccessible(true);
+ // String value = (String) field.get(dto);
+ // return value;
+ // }
+ // }
+ // return null;
+ //}
+
+ public static void main(String[] args) {
+ System.out.println(System.currentTimeMillis());
+ }
+}
diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/config/OpenApiConfig.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/config/OpenApiConfig.java
new file mode 100644
index 0000000000..706c01af35
--- /dev/null
+++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/config/OpenApiConfig.java
@@ -0,0 +1,15 @@
+package com.epmet.config;
+
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.stereotype.Component;
+
+@Component
+@Data
+public class OpenApiConfig {
+
+ @Value("${openApi.accessToken.expire}")
+ private int accessTokenExpire;
+
+}
diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java
new file mode 100644
index 0000000000..5f24502bfa
--- /dev/null
+++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java
@@ -0,0 +1,60 @@
+package com.epmet.controller;
+
+import com.epmet.annotation.OpenApiCheckSign;
+import com.epmet.commons.tools.exception.RenException;
+import com.epmet.commons.tools.redis.RedisKeys;
+import com.epmet.commons.tools.redis.RedisUtils;
+import com.epmet.commons.tools.utils.Result;
+import com.epmet.dto.result.openapi.GetAccessTokenResultDTO;
+import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
+import com.epmet.service.OpenApiAccessTokenService;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+@RestController
+@RequestMapping("open-api")
+public class OpenApiAccessTokenController {
+
+ @Autowired
+ private OpenApiAccessTokenService openApiAccessTokenService;
+
+ @Autowired
+ private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient;
+
+ @Autowired
+ private RedisUtils redisUtils;
+
+ private Logger logger = LoggerFactory.getLogger(OpenApiAccessTokenController.class);
+
+ /**
+ * @Description 获取AccessToken
+ * @return
+ * @author wxz
+ * @date 2021.03.23 09:52
+ */
+ @OpenApiCheckSign
+ @PostMapping("get-access-token")
+ public Result getAccessToken(@RequestParam("app_id") String appId) {
+ // 1.取secret
+ String secret = (String)redisUtils.get(RedisKeys.getExternalAppSecretKey(appId));
+ if (StringUtils.isBlank(secret)) {
+ Result result = commonServiceOpenFeignClient.getSecret(appId);
+ if (!result.success()) {
+ throw new RenException("调用common service查询secret失败");
+ }
+ secret = result.getData();
+ if (StringUtils.isBlank(secret)) {
+ throw new RenException(String.format("根据appId%s没有找到对应的secret", appId));
+ }
+ redisUtils.set(RedisKeys.getExternalAppSecretKey(appId), secret);
+ }
+
+ //2.生成token
+ GetAccessTokenResultDTO content = openApiAccessTokenService.getAccessToken(appId, secret);
+ return new Result().ok(content);
+ }
+
+}
diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiOrgController.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiOrgController.java
new file mode 100644
index 0000000000..30e97da2bf
--- /dev/null
+++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiOrgController.java
@@ -0,0 +1,27 @@
+package com.epmet.controller;
+
+import com.epmet.annotation.OpenApiCheckSign;
+import com.epmet.commons.tools.utils.Result;
+import com.epmet.dto.form.openapi.GetOrgDetailFormDTO;
+import org.springframework.web.bind.annotation.*;
+
+@RestController
+@RequestMapping("open-api")
+public class OpenApiOrgController {
+
+ /**
+ * @Description OpenApiCheckSign是验签注解,OpenApi的接口请加上该注解
+ * @return
+ * @author wxz
+ * @date 2021.03.24 12:55
+ */
+ @OpenApiCheckSign
+ @PostMapping("/get-org-detail")
+ public Result getOrgDetail(@RequestBody GetOrgDetailFormDTO input,
+ @RequestHeader("AppId") String appId) {
+ return new Result().ok("测试org");
+ }
+
+
+
+}
diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/OpenApiAccessTokenService.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/OpenApiAccessTokenService.java
new file mode 100644
index 0000000000..2b6d362636
--- /dev/null
+++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/OpenApiAccessTokenService.java
@@ -0,0 +1,17 @@
+package com.epmet.service;
+
+import com.epmet.dto.result.openapi.GetAccessTokenResultDTO;
+
+/**
+ * access token的service
+ */
+public interface OpenApiAccessTokenService {
+
+ /**
+ * @Description 获取AccessToken
+ * @return
+ * @author wxz
+ * @date 2021.03.22 22:57
+ */
+ GetAccessTokenResultDTO getAccessToken(String appId, String secret);
+}
diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java
new file mode 100644
index 0000000000..fad64083db
--- /dev/null
+++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java
@@ -0,0 +1,45 @@
+package com.epmet.service.impl;
+
+import com.epmet.commons.security.jwt.JwtUtils;
+import com.epmet.commons.tools.redis.RedisKeys;
+import com.epmet.commons.tools.redis.RedisUtils;
+import com.epmet.config.OpenApiConfig;
+import com.epmet.dto.result.openapi.GetAccessTokenResultDTO;
+import com.epmet.openapi.constant.RequestParamKeys;
+import com.epmet.service.OpenApiAccessTokenService;
+import org.joda.time.DateTime;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+import java.util.HashMap;
+
+@Service
+public class OpenApiAccessTokenServiceImpl implements OpenApiAccessTokenService {
+
+ @Autowired
+ private JwtUtils jwtTokenUtils;
+
+ @Autowired
+ private OpenApiConfig openApiConfig;
+
+ @Autowired
+ private RedisUtils redisUtils;
+
+ @Override
+ public GetAccessTokenResultDTO getAccessToken(String appId, String secret) {
+ HashMap claim = new HashMap<>();
+ claim.put(RequestParamKeys.APP_ID, appId);
+
+ Date expireTime = DateTime.now().plusSeconds(openApiConfig.getAccessTokenExpire()).toDate();
+ String token = jwtTokenUtils.createToken(claim, expireTime, secret);
+ // 缓存token
+ redisUtils.set(RedisKeys.getOpenApiAccessTokenKey(appId), token, openApiConfig.getAccessTokenExpire());
+
+ GetAccessTokenResultDTO content = new GetAccessTokenResultDTO();
+ content.setAccessToken(token);
+ content.setExpireTime(expireTime.getTime());
+
+ return content;
+ }
+}
diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/resources/bootstrap.yml b/epmet-module/epmet-ext/epmet-ext-server/src/main/resources/bootstrap.yml
index 1ed5a4306d..881881db27 100644
--- a/epmet-module/epmet-ext/epmet-ext-server/src/main/resources/bootstrap.yml
+++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/resources/bootstrap.yml
@@ -110,3 +110,8 @@ shutdown:
graceful:
enable: true #是否开启优雅停机
waitTimeSecs: 30 # 优雅停机等待时间,超过30秒,发出告警
+
+# 对外开放接口配置
+openApi:
+ accessToken:
+ expire: 7200
diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/ThirdPlatformDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/ThirdPlatformDTO.java
new file mode 100644
index 0000000000..7a8efc43cd
--- /dev/null
+++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/ThirdPlatformDTO.java
@@ -0,0 +1,57 @@
+package com.epmet.dto;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import java.io.Serializable;
+
+/**
+ * @auther: zhangyong
+ * @date: 2021-04-08 17:27
+ */
+@Data
+public class ThirdPlatformDTO implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 主键
+ */
+ private String id;
+
+ /**
+ * 平台名称
+ */
+ @NotBlank(message = "平台名称 不能为空")
+ private String platformName;
+
+ /**
+ * 平台唯一KEY
+ */
+ @NotBlank(message = "平台唯一KEY 不能为空")
+ private String platformKey;
+
+ /**
+ * 平台秘钥
+ */
+ @NotBlank(message = "平台秘钥 不能为空")
+ private String platformSecret;
+
+ /**
+ * apiservice
+ */
+ @NotBlank(message = "apiservice 不能为空")
+ private String apiService;
+
+ /**
+ * 基础url
+ */
+ @NotBlank(message = "基础url 不能为空")
+ private String baseUrl;
+
+ /**
+ * icon
+ */
+ @NotBlank(message = "icon 不能为空")
+ private String icon;
+}
diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/CustomerFormDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/CustomerFormDTO.java
new file mode 100644
index 0000000000..d2defb259d
--- /dev/null
+++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/CustomerFormDTO.java
@@ -0,0 +1,18 @@
+package com.epmet.dto.form;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+
+/**
+ * 客户 共用入参
+ **/
+@Data
+public class CustomerFormDTO {
+
+ /**
+ * 客户id
+ **/
+ @NotBlank(message = "客户id 不能为空")
+ private String customerId;
+}
diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/PlatformNameFormDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/PlatformNameFormDTO.java
new file mode 100644
index 0000000000..2fe4f8ed45
--- /dev/null
+++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/PlatformNameFormDTO.java
@@ -0,0 +1,15 @@
+package com.epmet.dto.form;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+
+@Data
+public class PlatformNameFormDTO {
+
+ /**
+ * 平台名称,用于模糊搜索
+ **/
+ @NotBlank(message = "平台名称 不能为空")
+ private String platformName;
+}
diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/PlatformRegisterFormDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/PlatformRegisterFormDTO.java
new file mode 100644
index 0000000000..9f7afda3ae
--- /dev/null
+++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/PlatformRegisterFormDTO.java
@@ -0,0 +1,29 @@
+package com.epmet.dto.form;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+/**
+ * 第三方平台-新增客户接入的第三方平台
+ *
+ * @auther: zhangyong
+ * @date: 2021-04-08 17:27
+ */
+@Data
+public class PlatformRegisterFormDTO {
+
+ /**
+ * 客户id
+ */
+ @NotBlank(message = "客户id 不能为空")
+ private String customerId;
+
+ /**
+ * 平台id列表
+ */
+ @NotNull(message = "平台id列表 不能为空")
+ private List platformIdList;
+}
diff --git a/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/PlatformUnregisterFormDTO.java b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/PlatformUnregisterFormDTO.java
new file mode 100644
index 0000000000..04cc64ae77
--- /dev/null
+++ b/epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/PlatformUnregisterFormDTO.java
@@ -0,0 +1,27 @@
+package com.epmet.dto.form;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+
+/**
+ * 解除客户接入的平台
+ *
+ * @auther: zhangyong
+ * @date: 2021-04-08 17:27
+ */
+@Data
+public class PlatformUnregisterFormDTO {
+
+ /**
+ * 客户id
+ */
+ @NotBlank(message = "客户id 不能为空")
+ private String customerId;
+
+ /**
+ * 平台ID
+ */
+ @NotBlank(message = "平台ID 不能为空")
+ private String platformId;
+}
diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/ThirdPlatformController.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/ThirdPlatformController.java
index de315e253e..54c7cc7ca3 100644
--- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/ThirdPlatformController.java
+++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/ThirdPlatformController.java
@@ -1,11 +1,14 @@
package com.epmet.controller;
+import com.epmet.commons.tools.constant.NumConstant;
+import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
-import com.epmet.dto.form.SaveOrUpdateCustSelPlatformFormDTO;
-import com.epmet.dto.form.ThirdPlatformFormDTO;
+import com.epmet.dto.ThirdPlatformDTO;
+import com.epmet.dto.form.*;
import com.epmet.dto.result.ThirdplatformResultDTO;
import com.epmet.service.ThirdPlatformService;
+import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@@ -89,4 +92,115 @@ public class ThirdPlatformController {
thirdPlatformService.saveOrUpdateSelectedPlatformInfo(input.getCustomerId(), input.getActionKey(), input.getPlatforms());
return new Result();
}
+
+ /**
+ * 第三方平台-平台列表模糊查询
+ *
+ * @param formsDTO
+ * @return com.epmet.commons.tools.utils.Result>
+ * @Author zhangyong
+ * @Date 17:13 2021-04-08
+ **/
+ @PostMapping("list-platforms")
+ public Result> listPlatforms(@RequestBody PlatformNameFormDTO formsDTO) {
+ ValidatorUtils.validateEntity(formsDTO);
+ return new Result>().ok(thirdPlatformService.listPlatforms(formsDTO.getPlatformName()));
+ }
+
+ /**
+ * 第三方平台-修改平台
+ *
+ * @param formDTO
+ * @return com.epmet.commons.tools.utils.Result
+ * @Author zhangyong
+ * @Date 17:31 2021-04-08
+ **/
+ @PostMapping("update-platform")
+ public Result updatePlatform(@RequestBody ThirdPlatformDTO formDTO) {
+ ValidatorUtils.validateEntity(formDTO);
+ if (StringUtils.isBlank(formDTO.getId())) {
+ throw new RenException("主键不能为空");
+ }
+ thirdPlatformService.updatePlatform(formDTO);
+ return new Result();
+ }
+
+ /**
+ * 第三方平台-新增平台
+ *
+ * @param formDTO
+ * @return com.epmet.commons.tools.utils.Result
+ * @Author zhangyong
+ * @Date 17:31 2021-04-08
+ **/
+ @PostMapping("add-platform")
+ public Result addPlatform(@RequestBody ThirdPlatformDTO formDTO) {
+ ValidatorUtils.validateEntity(formDTO);
+ return new Result().ok(thirdPlatformService.addPlatform(formDTO));
+ }
+
+ /**
+ * 第三方平台-客户可接入的平台列表
+ * 注:该客户还没有注册的平台列表。从thirdplatform表中找该客户没注册的(不在thirdplatform_customer_register中,或者在其中,但是del_flag为1的)返回
+ *
+ * @param formDTO
+ * @return com.epmet.commons.tools.utils.Result>
+ * @Author zhangyong
+ * @Date 09:46 2021-04-09
+ **/
+ @PostMapping("customer/registrable-platform-list")
+ public Result> registrablePlatformList(@RequestBody CustomerFormDTO formDTO) {
+ ValidatorUtils.validateEntity(formDTO);
+ return new Result>().ok(thirdPlatformService.listRegistrablePlatform(formDTO));
+ }
+
+ /**
+ * 第三方平台-客户已经接入的平台列表
+ * 注:在thirdplatform_customer_register中的记录
+ *
+ * @param formDTO
+ * @return com.epmet.commons.tools.utils.Result>
+ * @Author zhangyong
+ * @Date 09:46 2021-04-09
+ **/
+ @PostMapping("customer/registered-platform-list")
+ public Result> registeredPlatformList(@RequestBody CustomerFormDTO formDTO) {
+ ValidatorUtils.validateEntity(formDTO);
+ return new Result>().ok(thirdPlatformService.listRegisteredPlatform(formDTO));
+ }
+
+ /**
+ * 第三方平台-解除客户接入的平台
+ * 注:单个解除thirdplatform_customer_register表del_flag状态置为1
+ *
+ * @param formDTO
+ * @return com.epmet.commons.tools.utils.Result
+ * @Author zhangyong
+ * @Date 09:46 2021-04-09
+ **/
+ @PostMapping("customer/unregister-platform")
+ public Result unregisterPlatform(@RequestBody PlatformUnregisterFormDTO formDTO) {
+ ValidatorUtils.validateEntity(formDTO);
+ thirdPlatformService.unregisterPlatformCustomer(formDTO);
+ return new Result();
+ }
+
+ /**
+ * 第三方平台-新增客户接入的第三方平台
+ * 注:新增该客户要接入的第三方平台。thirdplatform_customer_register表新增数据。customized_xxx默认从thirdplatform表取过来
+ *
+ * @param formDTO
+ * @return com.epmet.commons.tools.utils.Result
+ * @Author zhangyong
+ * @Date 10:34 2021-04-09
+ **/
+ @PostMapping("customer/register-platform")
+ public Result registerPlatform(@RequestBody PlatformRegisterFormDTO formDTO) {
+ ValidatorUtils.validateEntity(formDTO);
+ if (formDTO.getPlatformIdList().size() == NumConstant.ZERO) {
+ throw new RenException("formDTO.getPlatformIdList().size() == 0;平台id列表不能为空");
+ }
+ thirdPlatformService.registerThirdPlatformCustomer(formDTO);
+ return new Result();
+ }
}
diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ThirdplatformCustomerRegisterDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ThirdplatformCustomerRegisterDao.java
index cbae094292..3dc3001baf 100644
--- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ThirdplatformCustomerRegisterDao.java
+++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ThirdplatformCustomerRegisterDao.java
@@ -18,7 +18,7 @@
package com.epmet.dao;
import com.epmet.commons.mybatis.dao.BaseDao;
-import com.epmet.dto.result.ThirdplatformResultDTO;
+import com.epmet.dto.form.PlatformUnregisterFormDTO;
import com.epmet.entity.ThirdplatformCustomerRegisterEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@@ -26,7 +26,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
- *
+ *
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2021-03-15
@@ -35,4 +35,24 @@ import java.util.List;
public interface ThirdplatformCustomerRegisterDao extends BaseDao {
ThirdplatformCustomerRegisterEntity getByCustomerIdAndPlatformId(@Param("customerId") String customerId, @Param("platformId") String platformId);
-}
\ No newline at end of file
+
+ /**
+ * 批量新增
+ * @param list
+ * @return int
+ * @Author zhangyong
+ * @Date 11:05 2021-04-09
+ **/
+ int batchInsertThirdplatformCustomerRegister(@Param("list") List list);
+
+ /**
+ * 第三方平台-解除客户接入的平台
+ * 注:单个解除.thirdplatform_customer_register表del_flag状态置为1
+ *
+ * @param formDTO
+ * @return void
+ * @Author zhangyong
+ * @Date 10:15 2021-04-09
+ **/
+ void unregisterPlatformCustomer(PlatformUnregisterFormDTO formDTO);
+}
diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ThirdplatformDao.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ThirdplatformDao.java
index 8b5e7840cc..74b53823b3 100644
--- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ThirdplatformDao.java
+++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ThirdplatformDao.java
@@ -18,6 +18,7 @@
package com.epmet.dao;
import com.epmet.commons.mybatis.dao.BaseDao;
+import com.epmet.dto.ThirdPlatformDTO;
import com.epmet.dto.result.ThirdplatformResultDTO;
import com.epmet.entity.ThirdplatformEntity;
import org.apache.ibatis.annotations.Mapper;
@@ -26,7 +27,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
- *
+ *
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2021-03-15
@@ -43,4 +44,46 @@ public interface ThirdplatformDao extends BaseDao {
List listAvailablePlatformsByCustomerAndAction(@Param("customerId") String customerId, @Param("actionKey") String actionKey);
List listSelectableByCustomerAndActionGroup(@Param("customerId") String customerId, @Param("actionKey") String actionKey);
-}
\ No newline at end of file
+
+ /**
+ * 第三方平台-平台列表模糊查询
+ *
+ * @param platformName 平台名称,用于模糊搜索
+ * @return java.util.List
+ * @Author zhangyong
+ * @Date 17:14 2021-04-08
+ **/
+ List selectListPlatforms(@Param("platformName") String platformName);
+
+ /**
+ * 第三方平台-客户可接入的平台列表
+ * 注:该客户还没有注册的平台列表。从thirdplatform表中找该客户没注册的(不在thirdplatform_customer_register中,或者在其中,但是del_flag为1的)返回
+ *
+ * @param customerId
+ * @return java.util.List
+ * @Author zhangyong
+ * @Date 09:47 2021-04-09
+ **/
+ List selectListRegistrablePlatform(@Param("customerId") String customerId);
+
+ /**
+ * 第三方平台-客户已经接入的平台列表
+ * 注:在thirdplatform_customer_register中的记录
+ *
+ * @param customerId
+ * @return java.util.List
+ * @Author zhangyong
+ * @Date 09:47 2021-04-09
+ **/
+ List selectListRegisteredPlatform(@Param("customerId") String customerId);
+
+ /**
+ * 查询第三方平台
+ *
+ * @param platformIds
+ * @return java.util.List
+ * @Author zhangyong
+ * @Date 10:51 2021-04-09
+ **/
+ List selectListThirdPlatform(@Param("platformIds") List platformIds);
+}
diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ThirdPlatformService.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ThirdPlatformService.java
index 9a0042f6e7..570ce04d49 100644
--- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ThirdPlatformService.java
+++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ThirdPlatformService.java
@@ -1,6 +1,10 @@
package com.epmet.service;
+import com.epmet.dto.ThirdPlatformDTO;
+import com.epmet.dto.form.CustomerFormDTO;
import com.epmet.dto.form.ThirdPlatformFormDTO;
+import com.epmet.dto.form.PlatformRegisterFormDTO;
+import com.epmet.dto.form.PlatformUnregisterFormDTO;
import com.epmet.dto.result.ThirdplatformResultDTO;
import java.util.List;
@@ -22,4 +26,78 @@ public interface ThirdPlatformService {
void updateCustomizePlatformInfo(ThirdPlatformFormDTO input);
void saveOrUpdateSelectedPlatformInfo(String customerId, String actionKey, List platforms);
-}
\ No newline at end of file
+
+ /**
+ * 第三方平台-平台列表模糊查询
+ *
+ * @param platformName 平台名称,用于模糊搜索
+ * @return java.util.List
+ * @Author zhangyong
+ * @Date 17:14 2021-04-08
+ **/
+ List listPlatforms(String platformName);
+
+ /**
+ * 第三方平台-修改平台
+ *
+ * @param formDTO
+ * @return void
+ * @Author zhangyong
+ * @Date 17:43 2021-04-08
+ **/
+ void updatePlatform(ThirdPlatformDTO formDTO);
+
+ /**
+ * 第三方平台-新增平台
+ *
+ * @param formDTO
+ * @return com.epmet.dto.ThirdPlatformDTO
+ * @Author zhangyong
+ * @Date 17:43 2021-04-08
+ **/
+ ThirdPlatformDTO addPlatform(ThirdPlatformDTO formDTO);
+
+ /**
+ * 第三方平台-客户可接入的平台列表
+ * 注:该客户还没有注册的平台列表。从thirdplatform表中找该客户没注册的(不在thirdplatform_customer_register中,或者在其中,但是del_flag为1的)返回
+ *
+ * @param formDTO
+ * @return java.util.List
+ * @Author zhangyong
+ * @Date 09:47 2021-04-09
+ **/
+ List listRegistrablePlatform(CustomerFormDTO formDTO);
+
+ /**
+ * 第三方平台-客户已经接入的平台列表
+ * 注:在thirdplatform_customer_register中的记录
+ *
+ * @param formDTO
+ * @return java.util.List
+ * @Author zhangyong
+ * @Date 09:47 2021-04-09
+ **/
+ List listRegisteredPlatform(CustomerFormDTO formDTO);
+
+ /**
+ * 第三方平台-解除客户接入的平台
+ * 注:单个解除.thirdplatform_customer_register表del_flag状态置为1
+ *
+ * @param formDTO
+ * @return void
+ * @Author zhangyong
+ * @Date 10:15 2021-04-09
+ **/
+ void unregisterPlatformCustomer(PlatformUnregisterFormDTO formDTO);
+
+ /**
+ * 第三方平台-新增客户接入的第三方平台
+ * 注:新增该客户要接入的第三方平台。thirdplatform_customer_register表新增数据。customized_xxx默认从thirdplatform表取过来
+ *
+ * @param formDTO
+ * @return void
+ * @Author zhangyong
+ * @Date 10:15 2021-04-09
+ **/
+ void registerThirdPlatformCustomer(PlatformRegisterFormDTO formDTO);
+}
diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ThirdPlatformServiceImpl.java b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ThirdPlatformServiceImpl.java
index 7e92c34223..3d6393e17e 100644
--- a/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ThirdPlatformServiceImpl.java
+++ b/epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ThirdPlatformServiceImpl.java
@@ -2,24 +2,27 @@ package com.epmet.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.epmet.commons.tools.constant.NumConstant;
+import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.dao.ThirdplatformCustomerActionDao;
import com.epmet.dao.ThirdplatformCustomerRegisterDao;
import com.epmet.dao.ThirdplatformDao;
+import com.epmet.dto.ThirdPlatformDTO;
+import com.epmet.dto.form.CustomerFormDTO;
import com.epmet.dto.form.ThirdPlatformFormDTO;
+import com.epmet.dto.form.PlatformRegisterFormDTO;
+import com.epmet.dto.form.PlatformUnregisterFormDTO;
import com.epmet.dto.result.ThirdplatformResultDTO;
-import com.epmet.entity.ThirdplatformActionEntity;
import com.epmet.entity.ThirdplatformCustomerActionEntity;
import com.epmet.entity.ThirdplatformCustomerRegisterEntity;
+import com.epmet.entity.ThirdplatformEntity;
import com.epmet.service.ThirdPlatformService;
-import jodd.util.CollectionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.CollectionUtils;
-import javax.validation.constraints.NotBlank;
+import java.util.ArrayList;
import java.util.List;
-import java.util.stream.Collectors;
@Service
public class ThirdPlatformServiceImpl implements ThirdPlatformService {
@@ -105,4 +108,56 @@ public class ThirdPlatformServiceImpl implements ThirdPlatformService {
entity.setCustomizedPlatformIcon(platformFormDTO.getIcon());
thirdplatformCustomerRegisterDao.update(entity, conditions);
}
+
+ @Override
+ public List listPlatforms(String platformName) {
+ return thirdplatformDao.selectListPlatforms(platformName);
+ }
+
+ @Override
+ public void updatePlatform(ThirdPlatformDTO formDTO) {
+ ThirdplatformEntity entity = ConvertUtils.sourceToTarget(formDTO, ThirdplatformEntity.class);
+ thirdplatformDao.updateById(entity);
+ }
+
+ @Override
+ public ThirdPlatformDTO addPlatform(ThirdPlatformDTO formDTO) {
+ ThirdplatformEntity entity = ConvertUtils.sourceToTarget(formDTO, ThirdplatformEntity.class);
+ thirdplatformDao.insert(entity);
+ formDTO.setId(entity.getId());
+ return formDTO;
+ }
+
+ @Override
+ public List listRegistrablePlatform(CustomerFormDTO formDTO) {
+ return thirdplatformDao.selectListRegistrablePlatform(formDTO.getCustomerId());
+ }
+
+ @Override
+ public List listRegisteredPlatform(CustomerFormDTO formDTO) {
+ return thirdplatformDao.selectListRegisteredPlatform(formDTO.getCustomerId());
+ }
+
+ @Override
+ public void unregisterPlatformCustomer(PlatformUnregisterFormDTO formDTO) {
+ thirdplatformCustomerRegisterDao.unregisterPlatformCustomer(formDTO);
+ }
+
+ @Override
+ public void registerThirdPlatformCustomer(PlatformRegisterFormDTO formDTO) {
+ List entityList = new ArrayList<>();
+
+ List thirdPlatforms = thirdplatformDao.selectListThirdPlatform(formDTO.getPlatformIdList());
+ for (ThirdPlatformDTO dto : thirdPlatforms) {
+ ThirdplatformCustomerRegisterEntity entity = new ThirdplatformCustomerRegisterEntity();
+ entity.setCustomerId(formDTO.getCustomerId());
+ entity.setPlatformId(dto.getId());
+ entity.setCustomizedPlatformName(dto.getPlatformName());
+ entity.setCustomizedPlatformIcon(dto.getIcon());
+ entityList.add(entity);
+ }
+ if (entityList.size() > NumConstant.ZERO) {
+ thirdplatformCustomerRegisterDao.batchInsertThirdplatformCustomerRegister(entityList);
+ }
+ }
}
diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ThirdplatformCustomerRegisterDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ThirdplatformCustomerRegisterDao.xml
index e4cdddc98d..9ab368a8bc 100644
--- a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ThirdplatformCustomerRegisterDao.xml
+++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ThirdplatformCustomerRegisterDao.xml
@@ -35,4 +35,44 @@
and PLATFORM_ID = #{platformId}
and DEL_FLAG = 0
-
\ No newline at end of file
+
+
+ insert into thirdplatform_customer_register
+ (
+ ID,
+ CUSTOMER_ID,
+ PLATFORM_ID,
+ CUSTOMIZED_PLATFORM_NAME,
+ CUSTOMIZED_PLATFORM_ICON,
+ DEL_FLAG,
+ REVISION,
+ CREATED_BY,
+ CREATED_TIME,
+ UPDATED_BY,
+ UPDATED_TIME
+ ) values
+
+ (
+ (SELECT REPLACE(UUID(), '-', '') AS id),
+ #{item.customerId},
+ #{item.platformId},
+ #{item.customizedPlatformName},
+ #{item.customizedPlatformIcon},
+ '0',
+ 0,
+ 'APP_USER',
+ now(),
+ 'APP_USER',
+ now()
+ )
+
+
+
+
+ UPDATE thirdplatform_customer_register
+ SET DEL_FLAG = '1'
+ WHERE
+ DEL_FLAG = '0'
+ AND CUSTOMER_ID = #{customerId} AND PLATFORM_ID = #{platformId}
+
+
diff --git a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ThirdplatformDao.xml b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ThirdplatformDao.xml
index beec9ed36d..e27f550f11 100644
--- a/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ThirdplatformDao.xml
+++ b/epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ThirdplatformDao.xml
@@ -87,4 +87,69 @@
and ta.ACTION_KEY = #{actionKey}
and tcr.DEL_FLAG = 0
-
\ No newline at end of file
+
+
+
+
+
+
+
+
+
diff --git a/pom.xml b/pom.xml
index b0d6621300..9420c9ff24 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,7 +29,7 @@
epmet-module
epmet-user
epmet-openapi
-
+
UTF-8