Browse Source

Merge branch 'dev_openapi' into dev_temp

# Conflicts:
#	epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java
master
wxz 4 years ago
parent
commit
af4e5489b4
  1. 15
      epmet-commons/epmet-commons-openapi/pom.xml
  2. 8
      epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/AuthTypes.java
  3. 10
      epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/InClusterHeaderKeys.java
  4. 14
      epmet-commons/epmet-commons-openapi/src/main/java/com/epmet/openapi/constant/RequestParamKeys.java
  5. 26
      epmet-commons/epmet-commons-security/pom.xml
  6. 131
      epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/jwt/JwtUtils.java
  7. 109
      epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java
  8. 2
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aspect/BaseRequestLogAspect.java
  9. 11
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java
  10. 40
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java
  11. 40
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/ConvertUtils.java
  12. 2
      epmet-commons/pom.xml
  13. 24
      epmet-gateway/pom.xml
  14. 91
      epmet-gateway/src/main/java/com/epmet/auth/ExtAppTakeTokenAuthProcessor.java
  15. 58
      epmet-gateway/src/main/java/com/epmet/auth/ExternalAuthProcessor.java
  16. 8
      epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java
  17. 5
      epmet-gateway/src/main/java/com/epmet/filter/CpProperty.java
  18. 19
      epmet-gateway/src/main/java/com/epmet/utils/ServerHttpRequestUtils.java
  19. 9
      epmet-gateway/src/main/resources/bootstrap.yml
  20. 2
      epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/feign/EpmetCommonServiceOpenFeignClient.java
  21. 5
      epmet-module/epmet-common-service/common-service-server/src/main/java/com/epmet/service/impl/AreaCodeServiceImpl.java
  22. 15
      epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/openapi/GetOrgDetailFormDTO.java
  23. 31
      epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/form/openapi/OpenApiBaseFormDTO.java
  24. 12
      epmet-module/epmet-ext/epmet-ext-client/src/main/java/com/epmet/dto/result/openapi/GetAccessTokenResultDTO.java
  25. 15
      epmet-module/epmet-ext/epmet-ext-server/pom.xml
  26. 13
      epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/annotation/OpenApiCheckSign.java
  27. 218
      epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java
  28. 15
      epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/config/OpenApiConfig.java
  29. 60
      epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiAccessTokenController.java
  30. 27
      epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/controller/OpenApiOrgController.java
  31. 17
      epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/OpenApiAccessTokenService.java
  32. 45
      epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/service/impl/OpenApiAccessTokenServiceImpl.java
  33. 5
      epmet-module/epmet-ext/epmet-ext-server/src/main/resources/bootstrap.yml
  34. 57
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/ThirdPlatformDTO.java
  35. 18
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/CustomerFormDTO.java
  36. 15
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/PlatformNameFormDTO.java
  37. 29
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/PlatformRegisterFormDTO.java
  38. 27
      epmet-module/epmet-third/epmet-third-client/src/main/java/com/epmet/dto/form/PlatformUnregisterFormDTO.java
  39. 118
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/controller/ThirdPlatformController.java
  40. 26
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ThirdplatformCustomerRegisterDao.java
  41. 47
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/dao/ThirdplatformDao.java
  42. 80
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/ThirdPlatformService.java
  43. 65
      epmet-module/epmet-third/epmet-third-server/src/main/java/com/epmet/service/impl/ThirdPlatformServiceImpl.java
  44. 42
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ThirdplatformCustomerRegisterDao.xml
  45. 67
      epmet-module/epmet-third/epmet-third-server/src/main/resources/mapper/ThirdplatformDao.xml
  46. 2
      pom.xml

15
epmet-commons/epmet-commons-openapi/pom.xml

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>epmet-commons</artifactId>
<groupId>com.epmet</groupId>
<version>2.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>epmet-commons-openapi</artifactId>
</project>

8
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";
}

10
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";
}

14
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";
}

26
epmet-commons/epmet-commons-security/pom.xml

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>epmet-commons</artifactId>
<groupId>com.epmet</groupId>
<version>2.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>epmet-commons-security</artifactId>
<dependencies>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-commons-tools</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.7.0</version>
</dependency>
</dependencies>
</project>

131
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.
* <p>
* https://www.renren.io
* <p>
* 版权所有侵权必究
*/
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<String, Object> 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<String, Object> 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<String, Object> 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"));
}
}

109
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<String, String> 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<String, String> 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<String, String> map) {
Set<String> 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<String, String> 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<String, String> 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);
}
}

2
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));

11
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;

40
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);
}
}

40
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<String, String> entityToMap(Object bean) throws IntrospectionException, InvocationTargetException, IllegalAccessException {
Class<?> type = bean.getClass();
Map<String, String> 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;
}
}

2
epmet-commons/pom.xml

@ -25,6 +25,8 @@
<module>epmet-commons-extapp-auth</module>
<module>epmet-commons-thirdplat</module>
<module>epmet-commons-rocketmq</module>
<module>epmet-commons-security</module>
<module>epmet-commons-openapi</module>
</modules>
</project>

24
epmet-gateway/pom.xml

@ -13,6 +13,11 @@
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-commons-security</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-commons-tools</artifactId>
@ -65,6 +70,17 @@
<artifactId>common-service-client</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-commons-openapi</artifactId>
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-commons-openapi</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
<build>
@ -298,8 +314,8 @@
<!-- <gateway.routes.gov-project-server.uri>http://localhost:8102</gateway.routes.gov-project-server.uri>-->
<gateway.routes.gov-project-server.uri>lb://gov-project-server</gateway.routes.gov-project-server.uri>
<!-- 24、公共服务 -->
<gateway.routes.common-service-server.uri>lb://common-service-server</gateway.routes.common-service-server.uri>
<!-- <gateway.routes.common-service-server.uri>http://localhost:8103</gateway.routes.common-service-server.uri>-->
<!--<gateway.routes.common-service-server.uri>lb://common-service-server</gateway.routes.common-service-server.uri>-->
<gateway.routes.common-service-server.uri>http://localhost:8103</gateway.routes.common-service-server.uri>
<!-- 25、党建园地 -->
<gateway.routes.resi-home-server.uri>lb://resi-home-server</gateway.routes.resi-home-server.uri>
<!-- <gateway.routes.resi-home-server.uri>http://localhost:8104</gateway.routes.resi-home-server.uri>-->
@ -329,8 +345,8 @@
<gateway.routes.epmet-point-server.url>lb://epmet-point-server</gateway.routes.epmet-point-server.url>
<!-- <gateway.routes.epmet-point-server.url>http://127.0.0.1:8112</gateway.routes.epmet-point-server.url>-->
<!-- 34、 开放接口服务 -->
<gateway.routes.epmet-ext-server.url>lb://epmet-ext-server</gateway.routes.epmet-ext-server.url>
<!-- <gateway.routes.epmet-ext-server.url>http://127.0.0.1:8113</gateway.routes.epmet-ext-server.url>-->
<!--<gateway.routes.epmet-ext-server.url>lb://epmet-ext-server</gateway.routes.epmet-ext-server.url>-->
<gateway.routes.epmet-ext-server.url>http://127.0.0.1:8113</gateway.routes.epmet-ext-server.url>
<!-- 35、多数据源服务 -->
<gateway.routes.data-aggregator-server.url>lb://data-aggregator-server</gateway.routes.data-aggregator-server.url>

91
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<String> 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;
}
}

58
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;
}
}

8
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<CpA
// }
//}
String authType = ServerHttpRequestUtils.getRequestParam(request, RequestParamKeys.AUTH_TYPE);
if (StringUtils.isNotBlank(authType) && AuthTypes.TAKE_TOKEN.equals(authType)) {
return AuthTypeConstant.AUTH_TYPE_EXTERNAL;
}
boolean needExternal = StringUtils.isNotBlank(request.getHeaders().getFirst(TokenHeaderKeyConstant.ACCESS_TOKEN_HEADER_KEY));
boolean needInternal = StringUtils.isNotBlank(request.getHeaders().getFirst(TokenHeaderKeyConstant.AUTHORIZATION_TOKEN_HEADER_KEY));

5
epmet-gateway/src/main/java/com/epmet/filter/CpProperty.java

@ -32,6 +32,11 @@ public class CpProperty {
*/
private List<String> externalOpenUrls;
/**
* 对外开放url白名单
*/
private List<String> externalAuthUrlsWhiteList;
/**
* 不处理token直接通过
*/

19
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<String, String> queryParams = request.getQueryParams();
return queryParams.getFirst(paramName);
}
}

9
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:

2
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

5
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<AreaCodeDao, AreaCodeEn
throw new RenException("目前只允许添加街道或社区");
}
if (StringUtils.isNotBlank(formDTO.getCode())) {
//修改地区编码名称
AreaCodeChildDTO areaCodeChildDTO = childDao.selectByCode(formDTO.getCode().trim());
if (null == areaCodeChildDTO) {
throw new RenException("code不存在");
@ -601,15 +602,17 @@ public class AreaCodeServiceImpl extends BaseServiceImpl<AreaCodeDao, AreaCodeEn
areaCodeChildService.update(areaCodeChildDTO);
return areaCodeChildDTO.getCode();
}
//查询area_code_child 判断当前父级,是街道还是社区?
AreaCodeChildDTO parent = childDao.selectByCode(formDTO.getParentAreaCode().trim());
if (null == parent) {
//街道、社区没找到,查询是否是 区县
AreaCodeDTO areaCodeDTOP = baseDao.selectByCountyCode(formDTO.getParentAreaCode().trim());
if (null == areaCodeDTOP) {
throw new RenException("parentAreaCode不存在");
}
}
//同一级不允许重名
//地区编码 同一级不允许重名
List<AreaCodeChildDTO> list = childDao.selectByPCodeAndName(formDTO.getParentAreaCode().trim(), formDTO.getName().trim());
if (CollUtil.isNotEmpty(list)) {
throw new RenException("name已存在");

15
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;
}

31
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;
}

12
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;
}

15
epmet-module/epmet-ext/epmet-ext-server/pom.xml

@ -21,6 +21,21 @@
</properties>
<dependencies>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-commons-openapi</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>common-service-client</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-commons-security</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.epmet</groupId>
<artifactId>epmet-ext-client</artifactId>

13
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 {
}

218
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<String, String> 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<String, String> 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<String, String> argMap, HttpServletRequest request, String paramName) {
String paramValue = request.getParameter(paramName);
if (StringUtils.isNotBlank(paramName)) {
argMap.put(paramName, paramValue);
}
}
/**
* 检查请求重放
* @param argMap
*/
void checkRepeatRequest(Map<String, String> 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<String> 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());
}
}

15
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;
}

60
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<GetAccessTokenResultDTO> getAccessToken(@RequestParam("app_id") String appId) {
// 1.取secret
String secret = (String)redisUtils.get(RedisKeys.getExternalAppSecretKey(appId));
if (StringUtils.isBlank(secret)) {
Result<String> 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<GetAccessTokenResultDTO>().ok(content);
}
}

27
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");
}
}

17
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);
}

45
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<String, Object> 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;
}
}

5
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

57
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;
}

18
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;
}

15
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;
}

29
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<String> platformIdList;
}

27
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;
}

118
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<java.util.List<com.epmet.dto.ThirdPlatformDTO>>
* @Author zhangyong
* @Date 17:13 2021-04-08
**/
@PostMapping("list-platforms")
public Result<List<ThirdPlatformDTO>> listPlatforms(@RequestBody PlatformNameFormDTO formsDTO) {
ValidatorUtils.validateEntity(formsDTO);
return new Result<List<ThirdPlatformDTO>>().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<com.epmet.dto.ThirdPlatformDTO>
* @Author zhangyong
* @Date 17:31 2021-04-08
**/
@PostMapping("add-platform")
public Result<ThirdPlatformDTO> addPlatform(@RequestBody ThirdPlatformDTO formDTO) {
ValidatorUtils.validateEntity(formDTO);
return new Result<ThirdPlatformDTO>().ok(thirdPlatformService.addPlatform(formDTO));
}
/**
* 第三方平台-客户可接入的平台列表
* 该客户还没有注册的平台列表从thirdplatform表中找该客户没注册的不在thirdplatform_customer_register中或者在其中但是del_flag为1的返回
*
* @param formDTO
* @return com.epmet.commons.tools.utils.Result<java.util.List<com.epmet.dto.ThirdPlatformDTO>>
* @Author zhangyong
* @Date 09:46 2021-04-09
**/
@PostMapping("customer/registrable-platform-list")
public Result<List<ThirdPlatformDTO>> registrablePlatformList(@RequestBody CustomerFormDTO formDTO) {
ValidatorUtils.validateEntity(formDTO);
return new Result<List<ThirdPlatformDTO>>().ok(thirdPlatformService.listRegistrablePlatform(formDTO));
}
/**
* 第三方平台-客户已经接入的平台列表
* 在thirdplatform_customer_register中的记录
*
* @param formDTO
* @return com.epmet.commons.tools.utils.Result<java.util.List<com.epmet.dto.ThirdPlatformDTO>>
* @Author zhangyong
* @Date 09:46 2021-04-09
**/
@PostMapping("customer/registered-platform-list")
public Result<List<ThirdPlatformDTO>> registeredPlatformList(@RequestBody CustomerFormDTO formDTO) {
ValidatorUtils.validateEntity(formDTO);
return new Result<List<ThirdPlatformDTO>>().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();
}
}

26
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> {
ThirdplatformCustomerRegisterEntity getByCustomerIdAndPlatformId(@Param("customerId") String customerId, @Param("platformId") String platformId);
}
/**
* 批量新增
* @param list
* @return int
* @Author zhangyong
* @Date 11:05 2021-04-09
**/
int batchInsertThirdplatformCustomerRegister(@Param("list") List<ThirdplatformCustomerRegisterEntity> list);
/**
* 第三方平台-解除客户接入的平台
* 单个解除.thirdplatform_customer_register表del_flag状态置为1
*
* @param formDTO
* @return void
* @Author zhangyong
* @Date 10:15 2021-04-09
**/
void unregisterPlatformCustomer(PlatformUnregisterFormDTO formDTO);
}

47
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<ThirdplatformEntity> {
List<ThirdplatformResultDTO> listAvailablePlatformsByCustomerAndAction(@Param("customerId") String customerId, @Param("actionKey") String actionKey);
List<ThirdplatformResultDTO> listSelectableByCustomerAndActionGroup(@Param("customerId") String customerId, @Param("actionKey") String actionKey);
}
/**
* 第三方平台-平台列表模糊查询
*
* @param platformName 平台名称用于模糊搜索
* @return java.util.List<com.epmet.dto.ThirdPlatformDTO>
* @Author zhangyong
* @Date 17:14 2021-04-08
**/
List<ThirdPlatformDTO> selectListPlatforms(@Param("platformName") String platformName);
/**
* 第三方平台-客户可接入的平台列表
* 该客户还没有注册的平台列表从thirdplatform表中找该客户没注册的不在thirdplatform_customer_register中或者在其中但是del_flag为1的返回
*
* @param customerId
* @return java.util.List<com.epmet.dto.ThirdPlatformDTO>
* @Author zhangyong
* @Date 09:47 2021-04-09
**/
List<ThirdPlatformDTO> selectListRegistrablePlatform(@Param("customerId") String customerId);
/**
* 第三方平台-客户已经接入的平台列表
* 在thirdplatform_customer_register中的记录
*
* @param customerId
* @return java.util.List<com.epmet.dto.ThirdPlatformDTO>
* @Author zhangyong
* @Date 09:47 2021-04-09
**/
List<ThirdPlatformDTO> selectListRegisteredPlatform(@Param("customerId") String customerId);
/**
* 查询第三方平台
*
* @param platformIds
* @return java.util.List<com.epmet.dto.ThirdPlatformDTO>
* @Author zhangyong
* @Date 10:51 2021-04-09
**/
List<ThirdPlatformDTO> selectListThirdPlatform(@Param("platformIds") List<String> platformIds);
}

80
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<ThirdPlatformFormDTO> platforms);
}
/**
* 第三方平台-平台列表模糊查询
*
* @param platformName 平台名称用于模糊搜索
* @return java.util.List<com.epmet.dto.ThirdPlatformDTO>
* @Author zhangyong
* @Date 17:14 2021-04-08
**/
List<ThirdPlatformDTO> 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<com.epmet.dto.ThirdPlatformDTO>
* @Author zhangyong
* @Date 09:47 2021-04-09
**/
List<ThirdPlatformDTO> listRegistrablePlatform(CustomerFormDTO formDTO);
/**
* 第三方平台-客户已经接入的平台列表
* 在thirdplatform_customer_register中的记录
*
* @param formDTO
* @return java.util.List<com.epmet.dto.ThirdPlatformDTO>
* @Author zhangyong
* @Date 09:47 2021-04-09
**/
List<ThirdPlatformDTO> 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);
}

65
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<ThirdPlatformDTO> 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<ThirdPlatformDTO> listRegistrablePlatform(CustomerFormDTO formDTO) {
return thirdplatformDao.selectListRegistrablePlatform(formDTO.getCustomerId());
}
@Override
public List<ThirdPlatformDTO> listRegisteredPlatform(CustomerFormDTO formDTO) {
return thirdplatformDao.selectListRegisteredPlatform(formDTO.getCustomerId());
}
@Override
public void unregisterPlatformCustomer(PlatformUnregisterFormDTO formDTO) {
thirdplatformCustomerRegisterDao.unregisterPlatformCustomer(formDTO);
}
@Override
public void registerThirdPlatformCustomer(PlatformRegisterFormDTO formDTO) {
List<ThirdplatformCustomerRegisterEntity> entityList = new ArrayList<>();
List<ThirdPlatformDTO> 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);
}
}
}

42
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
</select>
</mapper>
<insert id="batchInsertThirdplatformCustomerRegister" parameterType="map">
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
<foreach collection="list" item="item" index="index" separator=",">
(
(SELECT REPLACE(UUID(), '-', '') AS id),
#{item.customerId},
#{item.platformId},
#{item.customizedPlatformName},
#{item.customizedPlatformIcon},
'0',
0,
'APP_USER',
now(),
'APP_USER',
now()
)
</foreach>
</insert>
<update id="unregisterPlatformCustomer">
UPDATE thirdplatform_customer_register
SET DEL_FLAG = '1'
WHERE
DEL_FLAG = '0'
AND CUSTOMER_ID = #{customerId} AND PLATFORM_ID = #{platformId}
</update>
</mapper>

67
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
</select>
</mapper>
<select id="selectListPlatforms" resultType="com.epmet.dto.ThirdPlatformDTO">
SELECT
ID,
PLATFORM_NAME,
PLATFORM_KEY,
PLATFORM_SECRET,
ICON,
API_SERVICE,
BASE_URL
FROM `thirdplatform`
WHERE DEL_FLAG = '0'
AND PLATFORM_NAME LIKE concat('%', #{platformName}, '%')
</select>
<select id="selectListRegistrablePlatform" resultType="com.epmet.dto.ThirdPlatformDTO">
SELECT
ID,
PLATFORM_NAME,
PLATFORM_KEY,
PLATFORM_SECRET,
ICON,
API_SERVICE,
BASE_URL
FROM thirdplatform
WHERE DEL_FLAG = '0'
AND ID NOT IN (
SELECT PLATFORM_ID FROM thirdplatform_customer_register WHERE DEL_FLAG = '0' AND CUSTOMER_ID = #{customerId}
)
</select>
<select id="selectListRegisteredPlatform" resultType="com.epmet.dto.ThirdPlatformDTO">
SELECT
ID,
PLATFORM_NAME,
PLATFORM_KEY,
PLATFORM_SECRET,
ICON,
API_SERVICE,
BASE_URL
FROM thirdplatform
WHERE DEL_FLAG = '0'
AND ID IN (
SELECT PLATFORM_ID FROM thirdplatform_customer_register WHERE DEL_FLAG = '0' AND CUSTOMER_ID = #{customerId}
)
</select>
<select id="selectListThirdPlatform" resultType="com.epmet.dto.ThirdPlatformDTO">
SELECT
ID,
PLATFORM_NAME,
PLATFORM_KEY,
PLATFORM_SECRET,
ICON,
API_SERVICE,
BASE_URL
FROM thirdplatform
WHERE DEL_FLAG = '0'
<if test="platformIds != null and platformIds.size() != 0">
AND ID IN
<foreach collection="platformIds" item="platformId" open="(" close=")" separator=",">
#{platformId}
</foreach>
</if>
</select>
</mapper>

2
pom.xml

@ -29,7 +29,7 @@
<module>epmet-module</module>
<module>epmet-user</module>
<module>epmet-openapi</module>
</modules>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

Loading…
Cancel
Save