153 changed files with 3927 additions and 1042 deletions
@ -0,0 +1,26 @@ |
|||
package com.epmet.auth; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import org.springframework.cloud.gateway.filter.GatewayFilterChain; |
|||
import org.springframework.core.io.buffer.DataBuffer; |
|||
import org.springframework.http.HttpStatus; |
|||
import org.springframework.http.MediaType; |
|||
import org.springframework.web.server.ServerWebExchange; |
|||
import reactor.core.publisher.Flux; |
|||
import reactor.core.publisher.Mono; |
|||
|
|||
import java.nio.charset.StandardCharsets; |
|||
|
|||
public abstract class AuthProcessor { |
|||
|
|||
abstract Mono<Void> auth(ServerWebExchange exchange, GatewayFilterChain chain); |
|||
|
|||
protected Mono<Void> response(ServerWebExchange exchange, Object object) { |
|||
String json = JSON.toJSONString(object); |
|||
DataBuffer buffer = exchange.getResponse().bufferFactory().wrap(json.getBytes(StandardCharsets.UTF_8)); |
|||
exchange.getResponse().getHeaders().setContentType(MediaType.APPLICATION_JSON_UTF8); |
|||
exchange.getResponse().setStatusCode(HttpStatus.OK); |
|||
return exchange.getResponse().writeWith(Flux.just(buffer)); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,31 @@ |
|||
package com.epmet.auth; |
|||
|
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.web.server.ServerWebExchange; |
|||
|
|||
|
|||
/** |
|||
* 外部应用认证处理器父类 |
|||
*/ |
|||
public abstract class ExtAppAuthProcessor { |
|||
|
|||
private Logger logger = LoggerFactory.getLogger(getClass()); |
|||
|
|||
private int diffMillins = 1000 * 60 * 5; |
|||
|
|||
public abstract void auth(String appId, String token, Long ts, ServerWebExchange exchange); |
|||
|
|||
/** |
|||
* 时间戳校验 |
|||
* @param timestamp |
|||
* @return |
|||
*/ |
|||
protected boolean validTimeStamp(Long timestamp) { |
|||
long now = System.currentTimeMillis(); |
|||
if (Math.abs(now - timestamp) > diffMillins) { |
|||
return false; |
|||
} |
|||
return true; |
|||
} |
|||
} |
@ -0,0 +1,92 @@ |
|||
package com.epmet.auth; |
|||
|
|||
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|||
import com.epmet.commons.tools.exception.ExceptionUtils; |
|||
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.jwt.JwtTokenUtils; |
|||
import io.jsonwebtoken.Claims; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.web.server.ServerWebExchange; |
|||
|
|||
/** |
|||
* jwt 认证处理器 |
|||
*/ |
|||
@Component |
|||
public class ExtAppJwtAuthProcessor extends ExtAppAuthProcessor { |
|||
|
|||
private static Logger logger = LoggerFactory.getLogger(ExtAppJwtAuthProcessor.class); |
|||
|
|||
@Autowired |
|||
private JwtTokenUtils jwtTokenUtils; |
|||
|
|||
@Autowired |
|||
private RedisUtils redisUtils; |
|||
|
|||
@Override |
|||
public void auth(String appId, String token, Long ts, ServerWebExchange exchange) { |
|||
String secret; |
|||
if (StringUtils.isBlank(secret = getTokenFromCache(appId))) { |
|||
throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_AUTH_ERROR.getCode(), String.format("根据AppId:【%s】没有找到对应的秘钥", appId)); |
|||
} |
|||
|
|||
Claims claim; |
|||
try { |
|||
claim = jwtTokenUtils.getClaimByToken(token, secret); |
|||
} catch (Exception e) { |
|||
String errorStackTrace = ExceptionUtils.getErrorStackTrace(e); |
|||
logger.error("解析token失败:{}", errorStackTrace); |
|||
throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_AUTH_ERROR.getCode(), "解析token失败"); |
|||
} |
|||
|
|||
String appIdIn = (String)claim.get("appId"); |
|||
String customerId = (String)claim.get("customerId"); |
|||
Long timestamp = (Long)claim.get("ts"); |
|||
|
|||
//校验时间戳,允许5分钟误差
|
|||
if (StringUtils.isAnyBlank(appIdIn, customerId) || timestamp == null) { |
|||
logger.error("access token不完整。{},{},{}", appIdIn, customerId, timestamp); |
|||
throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_AUTH_ERROR.getCode(), "AccessToken不完整"); |
|||
} |
|||
|
|||
if (!validTimeStamp(timestamp)) { |
|||
logger.error("extapp token已经超时,请求被拒绝"); |
|||
throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_AUTH_ERROR.getCode(), "AccessToken已经超时"); |
|||
} |
|||
|
|||
if (!appId.equals(appIdIn)) { |
|||
logger.error("AppId不对应,token外部的:{}, token内部解析出来的:{}", appId, appIdIn); |
|||
throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_AUTH_ERROR.getCode(), "AppId不匹配"); |
|||
} |
|||
|
|||
// 添加客户ID等到请求头
|
|||
exchange.getRequest().mutate().header("CustomerId", customerId); |
|||
} |
|||
|
|||
/** |
|||
* 通过APP ID查询对应的秘钥 |
|||
* @param appId |
|||
* @return |
|||
*/ |
|||
public String getTokenFromCache(String appId) { |
|||
String secret = (String)redisUtils.get(RedisKeys.getExternalAppSecretKey(appId)); |
|||
if (StringUtils.isBlank(secret)) { |
|||
EpmetCommonServiceOpenFeignClient commonService = SpringContextUtils.getBean(EpmetCommonServiceOpenFeignClient.class); |
|||
Result<String> result = commonService.getSecret(appId); |
|||
if (!result.success()) { |
|||
throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_AUTH_ERROR.getCode(), result.getInternalMsg()); |
|||
} |
|||
secret = result.getData(); |
|||
redisUtils.set(RedisKeys.getExternalAppSecretKey(appId), secret); |
|||
} |
|||
return secret; |
|||
} |
|||
} |
@ -0,0 +1,75 @@ |
|||
package com.epmet.auth; |
|||
|
|||
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.Md5Util; |
|||
import com.epmet.commons.tools.utils.Result; |
|||
import com.epmet.commons.tools.utils.SpringContextUtils; |
|||
import com.epmet.feign.EpmetCommonServiceOpenFeignClient; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.web.server.ServerWebExchange; |
|||
|
|||
/** |
|||
* md5 认证处理器 |
|||
*/ |
|||
@Component |
|||
public class ExtAppMD5AuthProcessor extends ExtAppAuthProcessor { |
|||
|
|||
private static Logger logger = LoggerFactory.getLogger(ExtAppMD5AuthProcessor.class); |
|||
|
|||
//@Autowired
|
|||
//private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient;
|
|||
|
|||
@Autowired |
|||
private RedisUtils redisUtils; |
|||
|
|||
@Override |
|||
public void auth(String appId, String token, Long ts, ServerWebExchange exchange) { |
|||
if (ts == null) { |
|||
throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_AUTH_ERROR.getCode(), "需要传入时间戳参数"); |
|||
} |
|||
String secret; |
|||
if (StringUtils.isBlank(secret = getTokenFromCache(appId))) { |
|||
throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_AUTH_ERROR.getCode(), String.format("根据AppId:%s没有找到对应的秘钥", appId)); |
|||
} |
|||
|
|||
String localDigest = Md5Util.md5(secret.concat(":") + ts); |
|||
if (!localDigest.equals(token)) { |
|||
// 调用方生成的摘要跟本地生成的摘要不匹配
|
|||
throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_AUTH_ERROR.getCode(), "签名不匹配,认证失败"); |
|||
} |
|||
|
|||
if (!validTimeStamp(ts)) { |
|||
logger.error("AccessToken已经超时,请求被拒绝"); |
|||
throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_AUTH_ERROR.getCode(), "AccessToken已经超时,请求被拒绝"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 通过APP ID查询对应的秘钥 |
|||
* |
|||
* @param appId |
|||
* @return |
|||
*/ |
|||
public String getTokenFromCache(String appId) { |
|||
String secret = (String) redisUtils.get(RedisKeys.getExternalAppSecretKey(appId)); |
|||
if (StringUtils.isBlank(secret)) { |
|||
EpmetCommonServiceOpenFeignClient commonService = SpringContextUtils.getBean(EpmetCommonServiceOpenFeignClient.class); |
|||
Result<String> result = commonService.getSecret(appId); |
|||
if (!result.success()) { |
|||
throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_AUTH_ERROR.getCode(), result.getInternalMsg()); |
|||
} |
|||
|
|||
secret = result.getData(); |
|||
redisUtils.set(RedisKeys.getExternalAppSecretKey(appId), secret); |
|||
} |
|||
return secret; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,79 @@ |
|||
package com.epmet.auth; |
|||
|
|||
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|||
import com.epmet.commons.tools.exception.ExceptionUtils; |
|||
import com.epmet.commons.tools.exception.RenException; |
|||
import com.epmet.commons.tools.utils.Result; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.cloud.gateway.filter.GatewayFilterChain; |
|||
import org.springframework.http.HttpHeaders; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.web.server.ServerWebExchange; |
|||
import reactor.core.publisher.Mono; |
|||
|
|||
/** |
|||
* 外部应用认证 |
|||
*/ |
|||
@Component |
|||
public class ExternalAuthProcessor extends AuthProcessor { |
|||
|
|||
private Logger logger = LoggerFactory.getLogger(getClass()); |
|||
|
|||
// 头s
|
|||
public static final String AUTHORIZATION_TOKEN_HEADER_KEY = "Authorization"; |
|||
public static final String ACCESS_TOKEN_HEADER_KEY = "AccessToken"; |
|||
public static final String APP_ID_HEADER_KEY = "appId"; |
|||
public static final String APP_ID_TIMESTAMP_KEY = "ts"; |
|||
public static final String APP_ID_CUSTOMER_ID_KEY = "CustomerId"; |
|||
public static final String APP_ID_AUTY_TYPE_KEY = "AuthType"; |
|||
|
|||
// 认证方式
|
|||
public static final String APP_AUTH_TYPE_JWT = "jwt"; |
|||
public static final String APP_AUTH_TYPE_MD5 = "md5"; |
|||
|
|||
|
|||
@Autowired |
|||
private ExtAppJwtAuthProcessor jwtAuthProcessor; |
|||
|
|||
@Autowired |
|||
private ExtAppMD5AuthProcessor md5AuthProcessor; |
|||
|
|||
@Override |
|||
public Mono<Void> auth(ServerWebExchange exchange, GatewayFilterChain chain) { |
|||
HttpHeaders headers = exchange.getRequest().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("请求头中的AccessToken和AppId不能为空"); |
|||
} |
|||
|
|||
logger.info("外部应用请求认证拦截Aspect执行,appId:{}, token:{}, ts:{}, customerId:{}, authType:{}", |
|||
appId, token, ts, customerId, authType); |
|||
|
|||
// 没传authType或者传的jwt都用jwtprocessor处理
|
|||
try { |
|||
if (StringUtils.isBlank(authType) || APP_AUTH_TYPE_JWT.equals(authType)) { |
|||
jwtAuthProcessor.auth(appId, token, StringUtils.isNotBlank(ts) ? new Long(ts) : null, exchange); |
|||
} else if (APP_AUTH_TYPE_MD5.equals(authType)) { |
|||
md5AuthProcessor.auth(appId, token, StringUtils.isNotBlank(ts) ? new Long(ts) : null, exchange); |
|||
} else { |
|||
throw new RenException(EpmetErrorCode.OPER_EXTERNAL_APP_AUTH_ERROR.getCode(), "未知的认证类型"); |
|||
} |
|||
} catch (RenException e) { |
|||
return response(exchange, new Result<>().error(e.getCode(), e.getMsg())); |
|||
} catch (Exception e) { |
|||
logger.error("外部应用请求认证发生未知错误:" + ExceptionUtils.getErrorStackTrace(e)); |
|||
return response(exchange, new Result<>().error("外部应用请求认证发生未知错误")); |
|||
} |
|||
|
|||
return chain.filter(exchange); |
|||
} |
|||
} |
@ -0,0 +1,175 @@ |
|||
package com.epmet.auth; |
|||
|
|||
import com.epmet.commons.tools.constant.AppClientConstant; |
|||
import com.epmet.commons.tools.constant.Constant; |
|||
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|||
import com.epmet.commons.tools.exception.RenException; |
|||
import com.epmet.commons.tools.security.dto.BaseTokenDto; |
|||
import com.epmet.commons.tools.security.dto.GovTokenDto; |
|||
import com.epmet.commons.tools.security.dto.TokenDto; |
|||
import com.epmet.commons.tools.utils.CpUserDetailRedis; |
|||
import com.epmet.commons.tools.utils.Result; |
|||
import com.epmet.jwt.JwtTokenUtils; |
|||
import io.jsonwebtoken.Claims; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.cloud.gateway.filter.GatewayFilterChain; |
|||
import org.springframework.http.HttpHeaders; |
|||
import org.springframework.http.server.reactive.ServerHttpRequest; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.web.server.ServerWebExchange; |
|||
import reactor.core.publisher.Mono; |
|||
|
|||
/** |
|||
* 内部认证处理器 |
|||
*/ |
|||
@Component |
|||
public class InternalAuthProcessor extends AuthProcessor { |
|||
|
|||
private Logger logger = LoggerFactory.getLogger(getClass()); |
|||
|
|||
@Autowired |
|||
private JwtTokenUtils jwtTokenUtils; |
|||
|
|||
@Autowired |
|||
private CpUserDetailRedis cpUserDetailRedis; |
|||
|
|||
@Override |
|||
public Mono<Void> auth(ServerWebExchange exchange, GatewayFilterChain chain) { |
|||
ServerHttpRequest request = exchange.getRequest(); |
|||
String requestUri = request.getPath().pathWithinApplication().value(); |
|||
|
|||
logger.info("CpAuthGatewayFilterFactory当前requestUri=[" + requestUri + "]CpAuthGatewayFilterFactory拦截成功"); |
|||
String token = getTokenFromRequest(request); |
|||
//BaseTokenDto baseTokenDto = StringUtils.isNotBlank(token) ? getBaseTokenDto(token, jwtTokenUtils) : null;
|
|||
BaseTokenDto baseTokenDto; |
|||
if(StringUtils.isNotBlank(token)){ |
|||
try{ |
|||
baseTokenDto = getBaseTokenDto(token, jwtTokenUtils); |
|||
}catch(RenException e){ |
|||
return response(exchange,new Result<>().error(e.getCode(),e.getMsg())); |
|||
} |
|||
}else{ |
|||
baseTokenDto = null; |
|||
} |
|||
|
|||
String customerId = ""; |
|||
|
|||
if (baseTokenDto != null) { |
|||
if (AppClientConstant.APP_RESI.equals(baseTokenDto.getApp())) { |
|||
// 居民端
|
|||
TokenDto resiTokenDto = getLoginUserInfoByToken(token, jwtTokenUtils, TokenDto.class); |
|||
if (resiTokenDto != null) { |
|||
customerId = resiTokenDto.getCustomerId(); |
|||
baseTokenDto = resiTokenDto; |
|||
} |
|||
} else if (AppClientConstant.APP_GOV.equals(baseTokenDto.getApp())) { |
|||
// 政府端
|
|||
GovTokenDto govTokenDto = getLoginUserInfoByToken(token, jwtTokenUtils, GovTokenDto.class); |
|||
if (govTokenDto != null) { |
|||
customerId = govTokenDto.getCustomerId(); |
|||
baseTokenDto = govTokenDto; |
|||
} |
|||
} else if(AppClientConstant.APP_OPER.equals(baseTokenDto.getApp())){ |
|||
//运营端
|
|||
TokenDto resiTokenDto = getLoginUserInfoByToken(token, jwtTokenUtils, TokenDto.class); |
|||
if (resiTokenDto != null) { |
|||
customerId = resiTokenDto.getCustomerId(); |
|||
baseTokenDto = resiTokenDto; |
|||
} |
|||
} |
|||
} |
|||
|
|||
// 校验token
|
|||
if (StringUtils.isBlank(token)) { |
|||
return response(exchange,new Result<>().error(EpmetErrorCode.ERR10005.getCode(),EpmetErrorCode.ERR10005.getMsg())); |
|||
} |
|||
try { |
|||
validateTokenDto(baseTokenDto, token); |
|||
} catch (RenException e) { |
|||
return response(exchange,new Result<>().error(e.getCode(),e.getMsg())); |
|||
} |
|||
|
|||
// 添加header
|
|||
if (baseTokenDto != null) { |
|||
String redisKey = baseTokenDto.getApp() + "-" + baseTokenDto.getClient() + "-" + baseTokenDto.getUserId(); |
|||
logger.info("redisKey=" + redisKey); |
|||
exchange.getRequest().mutate() |
|||
.header(Constant.APP_USER_KEY, redisKey) |
|||
.header(AppClientConstant.APP,baseTokenDto.getApp()) |
|||
.header(AppClientConstant.CLIENT,baseTokenDto.getClient()) |
|||
.header(AppClientConstant.USER_ID,baseTokenDto.getUserId()); |
|||
|
|||
if (StringUtils.equals(baseTokenDto.getApp(), "gov")) {//工作端
|
|||
if(StringUtils.isNotBlank(customerId)){ |
|||
exchange.getRequest().mutate().header(AppClientConstant.CUSTOMER_ID, customerId); |
|||
} |
|||
} else if (StringUtils.equals(baseTokenDto.getApp(), "public")) {//公众号端
|
|||
exchange.getRequest().mutate().header(AppClientConstant.CUSTOMER_ID, customerId); |
|||
} |
|||
ServerHttpRequest build = exchange.getRequest().mutate().build(); |
|||
return chain.filter(exchange.mutate().request(build).build()); |
|||
} |
|||
|
|||
return chain.filter(exchange); |
|||
} |
|||
|
|||
/** |
|||
* 从请求中获取token |
|||
* @param request |
|||
* @return |
|||
*/ |
|||
private String getTokenFromRequest(ServerHttpRequest request) { |
|||
HttpHeaders headers = request.getHeaders(); |
|||
String token = headers.getFirst(Constant.AUTHORIZATION_HEADER); |
|||
if (StringUtils.isBlank(token)) { |
|||
token = headers.getFirst(Constant.TOKEN_HEADER); |
|||
} |
|||
if (StringUtils.isBlank(token)) { |
|||
token = request.getQueryParams().getFirst(Constant.AUTHORIZATION_HEADER); |
|||
} |
|||
return token; |
|||
} |
|||
|
|||
private BaseTokenDto getBaseTokenDto(String token, JwtTokenUtils jwtTokenUtils) { |
|||
//是否过期
|
|||
Claims claims = jwtTokenUtils.getClaimByToken(token); |
|||
if (claims == null || jwtTokenUtils.isTokenExpired(claims.getExpiration())) { |
|||
return null; |
|||
} |
|||
//获取用户ID
|
|||
String app = (String) claims.get("app"); |
|||
String client = (String) claims.get("client"); |
|||
String userId = (String) claims.get("userId"); |
|||
return new BaseTokenDto(app, client, userId, token); |
|||
} |
|||
|
|||
private <T> T getLoginUserInfoByToken(String token, JwtTokenUtils jwtTokenUtils, Class<T> clz) { |
|||
BaseTokenDto baseTokenDto = getBaseTokenDto(token, jwtTokenUtils); |
|||
//查询Redis
|
|||
return cpUserDetailRedis.get(baseTokenDto.getApp(), baseTokenDto.getClient(), baseTokenDto.getUserId(), clz); |
|||
} |
|||
|
|||
/** |
|||
* 校验Token是否异常 |
|||
* @param tokenDto |
|||
* @param tokenStr |
|||
*/ |
|||
private void validateTokenDto(BaseTokenDto tokenDto, String tokenStr) { |
|||
if (null == tokenDto) { |
|||
//说明登录状态时效(超时)
|
|||
throw new RenException(EpmetErrorCode.ERR10006.getCode()); |
|||
}else{ |
|||
//Redis中存在数据,取出token,进行比对
|
|||
if(StringUtils.equals(tokenDto.getToken(),tokenStr)){ |
|||
//用户携带token与Redis中一致
|
|||
|
|||
}else{ |
|||
//用户携带token与Redis中不一致,说明当前用户此次会话失效,提示重新登陆
|
|||
throw new RenException(EpmetErrorCode.ERR10007.getCode()); |
|||
} |
|||
} |
|||
} |
|||
} |
@ -1,35 +0,0 @@ |
|||
package com.epmet.filter; |
|||
|
|||
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|||
import com.epmet.commons.tools.exception.RenException; |
|||
import com.epmet.commons.tools.security.dto.BaseTokenDto; |
|||
import com.epmet.commons.tools.utils.CpUserDetailRedis; |
|||
import com.epmet.jwt.JwtTokenUtils; |
|||
import io.jsonwebtoken.Claims; |
|||
|
|||
/** |
|||
* 用户token的过滤器接口,提供通用的默认方法 |
|||
*/ |
|||
public interface UserTokenFilter { |
|||
|
|||
default BaseTokenDto getBaseTokenDto(String token, JwtTokenUtils jwtTokenUtils) { |
|||
//是否过期
|
|||
Claims claims = jwtTokenUtils.getClaimByToken(token); |
|||
if (claims == null || jwtTokenUtils.isTokenExpired(claims.getExpiration())) { |
|||
// throw new RenException(EpmetErrorCode.ERR401.getCode());
|
|||
return null; |
|||
} |
|||
//获取用户ID
|
|||
String app = (String) claims.get("app"); |
|||
String client = (String) claims.get("client"); |
|||
String userId = (String) claims.get("userId"); |
|||
return new BaseTokenDto(app, client, userId, token); |
|||
} |
|||
|
|||
default <T> T getLoginUserInfoByToken(String token, JwtTokenUtils jwtTokenUtils, CpUserDetailRedis cpUserDetailRedis, Class<T> clz) { |
|||
BaseTokenDto baseTokenDto = getBaseTokenDto(token, jwtTokenUtils); |
|||
//查询Redis
|
|||
return cpUserDetailRedis.get(baseTokenDto.getApp(), baseTokenDto.getClient(), baseTokenDto.getUserId(), clz); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,34 @@ |
|||
package com.epmet.evaluationindex.screen.dto.form; |
|||
|
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.Min; |
|||
import javax.validation.constraints.NotBlank; |
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* 组织月度指数得分--接口入参 |
|||
* @Author sun |
|||
*/ |
|||
@Data |
|||
public class IndexScoreFormDTO implements Serializable { |
|||
private static final long serialVersionUID = -2880432640584616651L; |
|||
/** |
|||
* 组织或网格Id |
|||
*/ |
|||
@NotBlank(message = "组织或网格ID不能为空",groups = {IndexScoreFormDTO.AddUserInternalGroup.class}) |
|||
private String orgId; |
|||
/** |
|||
* 类型(组织:agency 网格:grid) |
|||
*/ |
|||
@NotBlank(message = "数据类型不能为空",groups = {IndexScoreFormDTO.AddUserInternalGroup.class}) |
|||
private String orgType; |
|||
/** |
|||
* 月份Id eg:202009 |
|||
*/ |
|||
@NotBlank(message = "月份Id不能为空",groups = {IndexScoreFormDTO.AddUserInternalGroup.class}) |
|||
private String monthId; |
|||
public interface AddUserInternalGroup {} |
|||
|
|||
} |
@ -0,0 +1,55 @@ |
|||
package com.epmet.evaluationindex.screen.dto.result; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.math.BigDecimal; |
|||
|
|||
/** |
|||
* 组织月度指数得分--接口返参 |
|||
* @Author sun |
|||
*/ |
|||
@Data |
|||
public class IndexScoreResultDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 3860268744336541373L; |
|||
|
|||
/** |
|||
* 年度平均指数(保留一位小数) |
|||
*/ |
|||
@JsonIgnore |
|||
private String total; |
|||
private BigDecimal totalScore; |
|||
/** |
|||
* 党建能力(保留一位小数) |
|||
*/ |
|||
@JsonIgnore |
|||
private String party; |
|||
private BigDecimal partyDevAbility; |
|||
/** |
|||
* 党建能力权重(保留一位小数) |
|||
*/ |
|||
private String partyDevAbilityWeight; |
|||
/** |
|||
* 治理能力(保留一位小数) |
|||
*/ |
|||
@JsonIgnore |
|||
private String govern; |
|||
private BigDecimal governAbility; |
|||
/** |
|||
* 治理能力权重(保留一位小数) |
|||
*/ |
|||
private String governAbilityWeight; |
|||
/** |
|||
* 服务能力(保留一位小数) |
|||
*/ |
|||
@JsonIgnore |
|||
private String service; |
|||
private BigDecimal serviceAbility; |
|||
/** |
|||
* 服务能力权重(保留一位小数) |
|||
*/ |
|||
private String serviceAbilityWeight; |
|||
|
|||
} |
@ -0,0 +1,21 @@ |
|||
package com.epmet.dto.extract.form; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* desc: 抽取大屏数据dto |
|||
* |
|||
* @author LiuJanJun |
|||
* @date 2020/9/25 2:32 下午 |
|||
*/ |
|||
@Data |
|||
public class ExtractScreenFormDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 7659170440875719461L; |
|||
private String customerId; |
|||
private String monthId; |
|||
private String dateId; |
|||
|
|||
} |
@ -0,0 +1,19 @@ |
|||
package com.epmet.dto.extract.form; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @Author zxc |
|||
* @DateTime 2020/9/25 4:17 下午 |
|||
*/ |
|||
@Data |
|||
public class ScreenExtractFormDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = -6092830982601961936L; |
|||
|
|||
private String customerId; |
|||
|
|||
private String monthId; |
|||
} |
@ -0,0 +1,97 @@ |
|||
package com.epmet.dto.extract.form; |
|||
|
|||
import com.epmet.commons.tools.constant.NumConstant; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @Author zxc |
|||
* @DateTime 2020/9/25 9:07 上午 |
|||
*/ |
|||
@Data |
|||
public class ScreenPartyBranchDataFormDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = -5521810726686859779L; |
|||
|
|||
/** |
|||
* 客户Id |
|||
*/ |
|||
private String customerId; |
|||
|
|||
/** |
|||
* 年Id |
|||
*/ |
|||
private String yearId; |
|||
|
|||
/** |
|||
* 月份Id |
|||
*/ |
|||
private String monthId; |
|||
|
|||
/** |
|||
* 数据类别 :party:支部建设; union:联合建设;党员志愿服务:voluntaryservice |
|||
*/ |
|||
private String type; |
|||
|
|||
/** |
|||
* 组织类别 agency:组织;部门:department;网格:grid |
|||
*/ |
|||
private String orgType; |
|||
|
|||
/** |
|||
* 组织Id 可以为网格,机关id |
|||
*/ |
|||
private String orgId; |
|||
|
|||
/** |
|||
* 上级组织Id |
|||
*/ |
|||
private String parentId; |
|||
|
|||
/** |
|||
* 组织名称 |
|||
*/ |
|||
private String orgName; |
|||
|
|||
/** |
|||
* 会议分类Id |
|||
*/ |
|||
private String meetCategoryId; |
|||
|
|||
/** |
|||
* 会议分类名称(三会党课、主题党日.....等等) |
|||
*/ |
|||
private String meetCategoryName; |
|||
|
|||
/** |
|||
* 组织次数 |
|||
*/ |
|||
private Integer organizeCount; |
|||
|
|||
/** |
|||
* 参加人数 |
|||
*/ |
|||
private Integer joinUserCount; |
|||
|
|||
/** |
|||
* 平均参加人数 |
|||
*/ |
|||
private Integer averageJoinUserCount; |
|||
|
|||
private String delFlag; |
|||
|
|||
private Integer revision; |
|||
|
|||
private String createdBy; |
|||
|
|||
private String updatedBy; |
|||
|
|||
public ScreenPartyBranchDataFormDTO() { |
|||
this.delFlag = NumConstant.ZERO_STR; |
|||
this.revision = NumConstant.ZERO; |
|||
this.createdBy = "APP_USER"; |
|||
this.updatedBy = "APP_USER"; |
|||
this.type = "voluntaryservice"; |
|||
} |
|||
} |
@ -0,0 +1,73 @@ |
|||
package com.epmet.dto.extract.form; |
|||
|
|||
import com.epmet.commons.tools.constant.NumConstant; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @Author zxc |
|||
* @DateTime 2020/9/24 6:03 下午 |
|||
*/ |
|||
@Data |
|||
public class ScreenPartyLinkMassesDataFormDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = -7534140815638694052L; |
|||
|
|||
/** |
|||
* 客户Id |
|||
*/ |
|||
private String customerId; |
|||
|
|||
/** |
|||
* 组织类别 agency:组织;部门:department;网格:grid |
|||
*/ |
|||
private String orgType; |
|||
|
|||
/** |
|||
* 组织Id 可以为网格,机关id |
|||
*/ |
|||
private String orgId; |
|||
|
|||
/** |
|||
* 上级组织Id |
|||
*/ |
|||
private String parentId; |
|||
|
|||
/** |
|||
* 组织名称 |
|||
*/ |
|||
private String orgName; |
|||
|
|||
/** |
|||
* 党员建群总数 |
|||
*/ |
|||
private Integer createGroupTotal; |
|||
|
|||
/** |
|||
* 群成员总数 |
|||
*/ |
|||
private Integer groupUserTotal; |
|||
|
|||
/** |
|||
* 数据更新至: yyyy|yyyyMM|yyyyMMdd(08-21新增) |
|||
*/ |
|||
private String dataEndTime; |
|||
|
|||
private String delFlag; |
|||
|
|||
private Integer revision; |
|||
|
|||
private String createdBy; |
|||
|
|||
private String updatedBy; |
|||
|
|||
public ScreenPartyLinkMassesDataFormDTO() { |
|||
this.createGroupTotal = NumConstant.ZERO; |
|||
this.groupUserTotal = NumConstant.ZERO; |
|||
this.delFlag = NumConstant.ZERO_STR; |
|||
this.revision = NumConstant.ZERO; |
|||
this.createdBy = "APP_USER"; |
|||
this.updatedBy = "APP_USER"; |
|||
} |
|||
} |
@ -0,0 +1,90 @@ |
|||
package com.epmet.dto.extract.result; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @Author zxc |
|||
* @DateTime 2020/9/25 3:38 下午 |
|||
*/ |
|||
@Data |
|||
public class ActInfoResultDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 2322961372193392320L; |
|||
|
|||
/** |
|||
* 客户ID |
|||
*/ |
|||
private String customerId; |
|||
|
|||
/** |
|||
* 组织ID【gridId或agencyId】 |
|||
*/ |
|||
private String orgId; |
|||
|
|||
/** |
|||
* 组织类型【agency,grid】 |
|||
*/ |
|||
private String orgType; |
|||
|
|||
/** |
|||
* 组织名称 |
|||
*/ |
|||
private String orgName; |
|||
|
|||
/** |
|||
* 年度ID |
|||
*/ |
|||
private String yearId; |
|||
|
|||
/** |
|||
* 月度ID |
|||
*/ |
|||
private String monthId; |
|||
|
|||
/** |
|||
* 父级ID |
|||
*/ |
|||
private String parentId; |
|||
|
|||
/** |
|||
* 组织次数 |
|||
*/ |
|||
private Integer organizeCount; |
|||
|
|||
/** |
|||
* 会议分类Id |
|||
*/ |
|||
private String meetCategoryId; |
|||
|
|||
/** |
|||
* 会议分类名称(三会党课、主题党日.....等等) |
|||
*/ |
|||
private String meetCategoryName; |
|||
|
|||
/** |
|||
* 平均参加人数 |
|||
*/ |
|||
private Integer averageJoinUserCount; |
|||
|
|||
/** |
|||
* 删除状态 |
|||
*/ |
|||
private String delFlag; |
|||
|
|||
/** |
|||
* 乐观锁 |
|||
*/ |
|||
private Integer revision; |
|||
|
|||
/** |
|||
* 创建人 |
|||
*/ |
|||
private String createdBy; |
|||
|
|||
/** |
|||
* 更新人 |
|||
*/ |
|||
private String updatedBy; |
|||
} |
@ -0,0 +1,23 @@ |
|||
package com.epmet.dto.extract.result; |
|||
|
|||
import com.epmet.dto.extract.form.ScreenPartyLinkMassesDataFormDTO; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @Author zxc |
|||
* @DateTime 2020/9/25 10:10 上午 |
|||
*/ |
|||
@Data |
|||
@AllArgsConstructor |
|||
public class GridPartyGuideDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 8986034496647129566L; |
|||
|
|||
private List<String> orgIds; |
|||
|
|||
private List<ScreenPartyLinkMassesDataFormDTO> result; |
|||
} |
@ -0,0 +1,22 @@ |
|||
package com.epmet.dto.extract.result; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @Author zxc |
|||
* @DateTime 2020/9/25 5:14 下午 |
|||
*/ |
|||
@Data |
|||
public class JoinUserCountResultDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 3961393565082322770L; |
|||
|
|||
private String orgId; |
|||
|
|||
/** |
|||
* 参与人数 |
|||
*/ |
|||
private Integer joinUserCount; |
|||
} |
@ -0,0 +1,25 @@ |
|||
package com.epmet.dao.heart; |
|||
|
|||
import com.epmet.dto.extract.result.JoinUserCountResultDTO; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
import org.apache.ibatis.annotations.Param; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @Author zxc |
|||
* @DateTime 2020/9/25 5:21 下午 |
|||
*/ |
|||
@Mapper |
|||
public interface ActUserRelationDao { |
|||
|
|||
/** |
|||
* @Description 查询参与人数 |
|||
* @Param customerId |
|||
* @Param monthId |
|||
* @author zxc |
|||
* @date 2020/9/25 5:19 下午 |
|||
*/ |
|||
List<JoinUserCountResultDTO> selectJoinUserCount(@Param("customerId") String customerId,@Param("monthId") String monthId); |
|||
|
|||
} |
@ -0,0 +1,34 @@ |
|||
package com.epmet.service.evaluationindex.extract.toscreen; |
|||
|
|||
import com.epmet.dto.extract.form.ExtractScreenFormDTO; |
|||
|
|||
/** |
|||
* @desc: 大屏 公众参与抽取服务接口 |
|||
* @Author: LiuJanJun |
|||
* @Date: 2020/9/25 10:03 上午 |
|||
* @Version: 1.0 |
|||
*/ |
|||
public interface PublicPartExtractService { |
|||
|
|||
/** |
|||
* desc: 抽取公众参与 人均议题 总次数和平均参与度 |
|||
* target:screen_user_join |
|||
* |
|||
* @param |
|||
* @return java.lang.Boolean |
|||
* @author LiuJanJun |
|||
* @date 2020/9/25 10:24 上午 |
|||
*/ |
|||
Boolean extractTotalDataMonthly(ExtractScreenFormDTO formDTO); |
|||
|
|||
/** |
|||
* desc: 抽取公众参与 各类总数 |
|||
* target:screen_public_parti_total_data |
|||
* |
|||
* @param |
|||
* @return java.lang.Boolean |
|||
* @author LiuJanJun |
|||
* @date 2020/9/25 10:24 上午 |
|||
*/ |
|||
Boolean extractPerTotalDataDaily(ExtractScreenFormDTO formDTO); |
|||
} |
@ -0,0 +1,32 @@ |
|||
package com.epmet.service.evaluationindex.extract.toscreen; |
|||
|
|||
/** |
|||
* @desc: 大屏 产品内部客户组织结构数据 |
|||
* @Author: LiuJanJun |
|||
* @Date: 2020/9/25 10:03 上午 |
|||
* @Version: 1.0 |
|||
*/ |
|||
public interface ScreenOrgService { |
|||
|
|||
/** |
|||
* desc: 抽取公众参与 人均议题 总次数和平均参与度 |
|||
* target:screen_user_join |
|||
* |
|||
* @param |
|||
* @return java.lang.Boolean |
|||
* @author LiuJanJun |
|||
* @date 2020/9/25 10:24 上午 |
|||
*/ |
|||
Boolean getInnerCustomerAgencyTree(); |
|||
|
|||
/** |
|||
* desc: 抽取公众参与 各类总数 |
|||
* target:screen_public_parti_total_data |
|||
* |
|||
* @param |
|||
* @return java.lang.Boolean |
|||
* @author LiuJanJun |
|||
* @date 2020/9/25 10:24 上午 |
|||
*/ |
|||
Boolean extractPerTotalDataDaily(); |
|||
} |
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue