登录拦截器

EAC公共拦截器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
import cn.mysteel.util.StringUtils;
import com.alibaba.dubbo.common.utils.CollectionUtils;
import com.alibaba.fastjson.JSONObject;
import com.banksteel.openerp.authentication.constant.LoginConstants;
import com.banksteel.openerp.commons.auth.TokenManager;
import com.banksteel.openerp.commons.constants.AuthorizationConstants;
import com.banksteel.openerp.commons.constants.MemberStatusConstants;
import com.banksteel.openerp.commons.enums.ResponseResultEnum;
import com.banksteel.openerp.commons.filter.SaasParameter;
import com.banksteel.openerp.commons.filter.ThreadContext;
import com.banksteel.openerp.commons.framework.entiy.ResponseEntity;
import com.banksteel.openerp.commons.permission.PermissionContext;
import com.banksteel.openerp.commons.permission.PermissionLevel;
import com.banksteel.openerp.commons.permission.PermissionRequest;
import com.banksteel.openerp.commons.permission.RequestType;
import com.banksteel.openerp.entity.AdminMemberVO;
import com.banksteel.openerp.system.vo.UserVO;
import com.banksteel.openerp.user.AuthUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
* EAC公共拦截器
*/
public class BaseEACAuthenticationInterceptor extends HandlerInterceptorAdapter {
private static final String NO_PERMISSIONS = "您的公司未分配此权限给您,请联系您公司主账号的管理员";
private static final String VERSION_EXCEPTION = "您暂无权限使用此功能,请升级您的会员版本!";
private static final String LOGINER = ",登录人=";
private static final String INTERCEPTOR_REQUEST = "Interceptor-请求命令:";
private static final String RESULT_MSG = ",执行结果:阻止。理由:会员账户";
private static final String ACCOUNT_MSG="您的会员账户";

static Logger logger = LoggerFactory.getLogger(BaseEACAuthenticationInterceptor.class);

/**
* redis缓存
*/
@Resource
private StringRedisTemplate eacRedisTemplate;
@Autowired
private TokenManager<AuthUser> tokenManager;

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
/**
* swagger接口不进行拦截
*/
if (request.getRequestURI().contains("swagger") || request.getRequestURI().contains("csrf") || request.getRequestURI().contains("error")
|| request.getRequestURI().contains("api-docs") || request.getRequestURI().contains("webjars") || request.getRequestURI().contains("doc.html") || request.getRequestURI().contains("webap") || request.getRequestURI().contains("swagger-resources")) {
return true;
}
// 封装请求url
PermissionRequest permissionRequest = PermissionContext.getPermissionRequest(request);
if (permissionRequest == null) {
return false;
}

// 初始化用户信息
AdminMemberVO adminMemberVO = null;
try {
adminMemberVO = initUserToSaasParameter(request, response, permissionRequest);
} catch (Exception e) {
logger.error("====登录信息校异常");
throw new Exception(e);
}

// 判断是否不过滤的请求
if (Objects.equals(PermissionLevel.ALL, permissionRequest.getLevel())
|| Objects.equals(PermissionLevel.OUT_INTERFACE, permissionRequest.getLevel())
) {
return true;
}

// 从线程中获取用户信息
UserVO userVO = SaasParameter.<UserVO>getCurrentThreadContext().getUserInfo();

String command = permissionRequest.getCommand();
request.setCharacterEncoding("UTF-8");
if (userVO == null) {
// 如果没有用户信息直接返回,重新登陆
setResponse(response, command, 401, "您还未登录,请先登录");
return false;
}
if (Objects.equals(permissionRequest.getRequestType(), RequestType.URL)) {
return true;
}

if (Objects.equals(PermissionLevel.INNER_USER, permissionRequest.getLevel())) {
return true;
}

if(adminMemberVO == null) {
setResponse(response, command, 408, "会员信息过期,请重新登录");
return false;
}

// 检查会员的状态
String message = checkMemberStatus(adminMemberVO);
if (StringUtils.isNotEmpty(message)) {
setResponse(response, command, 408, ACCOUNT_MSG + message);
logger.info(INTERCEPTOR_REQUEST + command + LOGINER + userVO.getLoginUName() + RESULT_MSG + message);
return false;
}

// 判断是否是管理员 或者 是否是通用放行命令
if (Objects.equals(PermissionLevel.COMMAND_NORMAL_MEMBER, permissionRequest.getLevel())) {
return true;
}
// 校验权限访问级别
String commonds = eacRedisTemplate.opsForValue().get(AuthorizationConstants.MEMBER_COMMONDS_CACHE + userVO.getMemberId());
if(StringUtils.isEmpty(commonds)) {
setResponse(response, command, 403, VERSION_EXCEPTION);
logger.info(VERSION_EXCEPTION);
logger.info("会员的commond集合为空,会员id:{},请求命令commond:{}", userVO.getMemberId(), command);
return false;
}
List<String> operssionIds = JSONObject.parseArray(commonds, String.class);
if(!operssionIds.contains(command)) {
setResponse(response, command, 403, VERSION_EXCEPTION);
logger.info(VERSION_EXCEPTION);
logger.info("当前登录用户名:{},手机号:{},会员id:{},请求命令commond:{}", userVO.getUserName(), userVO.getMobile(), userVO.getMemberId(), command);
return false;
}
// 会员----权限关系记录
if (userVO.isMaster()) {
return true;
}
// 不是管理员 也不是放行命令 则查询其命令是否具有该权限
String roleIds = eacRedisTemplate.opsForValue().get(AuthorizationConstants.ROLE_USER_CACHE + userVO.getId() + ":" + userVO.getMemberId());
if(StringUtils.isEmpty(roleIds)) {
setResponse(response, command, 403, NO_PERMISSIONS);
logger.info("您的公司未分配此权限给您,请联系您公司主账号的管理员!");
logger.info("当前用户在会员下未分配任何角色,用户名:{},手机号:{},会员id:{}", userVO.getUserName(), userVO.getMobile(), userVO.getMemberId());
return false;
}
List<Long> roleIdList = JSONObject.parseArray(roleIds, Long.class);
Set<String> userUrl = new HashSet<>();
roleIdList.stream().forEach(roleId -> {
Set<String> roleUrls = eacRedisTemplate.opsForSet().members(AuthorizationConstants.EAC_ROLE_OPERATION + roleId);
userUrl.addAll(roleUrls);
});
if(CollectionUtils.isEmpty(userUrl) || !userUrl.contains(command)) {
setResponse(response, command, 403, NO_PERMISSIONS);
logger.info(NO_PERMISSIONS);
logger.info("登录用户名:{},手机号:{},会员id:{},请求命令commond:{}", userVO.getUserName(), userVO.getMobile(), userVO.getMemberId(), command);
return false;
}
return true;
}

private String checkMemberStatus(AdminMemberVO adminMemberVO){
String message = "";
if (Objects.equals(MemberStatusConstants.REGULAR,adminMemberVO.getMemberStatus())){
return message;
}else if (Objects.equals(MemberStatusConstants.LOCKING,adminMemberVO.getMemberStatus())){
message = "已经被锁定";
}else {
message = "会员状态:" + adminMemberVO.getMemberStatus();
}
return message;
}

/**
* 设置返回头和返回实体
*/
protected ResponseEntity setResponse(HttpServletResponse response, String command, int code, String mess)
throws IOException {
ResponseEntity responseEntity = new ResponseEntity();
responseEntity.setTimeStamp(System.currentTimeMillis());
responseEntity.setResult(ResponseResultEnum.FAIL.getValue());
responseEntity.setData("");
responseEntity.setCode(code);
responseEntity.setMess(mess);
response.setStatus(200);
response.setHeader("Content-type", "application/json;charset=UTF-8");
response.getWriter().write(JSONObject.toJSONString(responseEntity));
return responseEntity;
}

/**
* 初始化用户信息
*/
private AdminMemberVO initUserToSaasParameter(HttpServletRequest request, HttpServletResponse response, PermissionRequest permissionRequest) {
ThreadContext<UserVO> threadContext = SaasParameter.getCurrentThreadContext();
threadContext.setUserInfo(null);
SaasParameter.setMemberId(null);
SaasParameter.setUserId(null);
UserVO user = getSsoUserVO();
// 如果没有用户信息直接返回,重新登陆
if (user == null) {
// 删除无用用户信息
tokenManager.loginOff();
SaasParameter.setMemberId("-1");
SaasParameter.setUserId(-1L);
} else {
request.setAttribute(LoginConstants.SESSION_USER, user);
SaasParameter.setMemberId(user.getMemberId() + "");
SaasParameter.setUserId(user.getUserId());
MDC.put("username", user.getLoginUName()); // 保存用户名到线程中,日志使用
MDC.put("memberId", user.getMemberId() + ""); // 保存会员ID到线程中,日志使用
MDC.put("ipaddress", getIp(request));// 保存访问IP地址到线程中,日志使用

threadContext.setUserInfo(user);
threadContext.setIp(getIp(request));

String reqCommand = StringUtils.isNotEmpty(permissionRequest.getCommand()) ?
permissionRequest.getCommand() :
permissionRequest.getRelativePath();
threadContext.setCommand(reqCommand);

// 该信息在登录时放到缓存中,可以从缓存中取
String memberVO = eacRedisTemplate.opsForValue().get(AuthorizationConstants.LOGIN_USER_MEMBER_CACHE + user.getMemberId());
if(StringUtils.isEmpty(memberVO)) {
return null;
}
AdminMemberVO adminMemberVO = JSONObject.parseObject(memberVO, AdminMemberVO.class);
SaasParameter.setUserId(user.getUserId());
user.setMemberName(adminMemberVO.getMemberName());
return adminMemberVO;
}

return null;
}

private UserVO getSsoUserVO() {
AuthUser authUser = tokenManager.getAndExtendUserByToken(AuthUser.class);
UserVO userVO = null;
if (authUser != null) {
//1、从redis缓存中获取用户下面信息,这就要求再用户登录的时候把上述信息保存到缓存中
// 登录信息缓存中用户信息不存在
String userInfo = eacRedisTemplate.opsForValue().get(AuthorizationConstants.LOGIN_USER_CACHE + authUser.getUserId() + ":" + authUser.getMemberId());
if(StringUtils.isEmpty(userInfo)) {
return userVO;
}
userVO = JSONObject.parseObject(userInfo, UserVO.class);
userVO.setMemberOwerId(authUser.getMemberOwerId());
userVO.setUserDepartments(authUser.getUserDepartments());
}

return userVO;
}

/**
* 获取客户端的IP
*
* @param request
* @return
*/
public String getIp(HttpServletRequest request) {
String ip = request.getHeader("X-Forwarded-For");
if (StringUtils.isNotEmpty(ip) && !"unKnown".equalsIgnoreCase(ip)) {
// 多次反向代理后会有多个ip值,第一个ip才是真实ip
int index = ip.indexOf(",");
if (index != -1) {
return ip.substring(0, index);
} else {
return ip;
}
}
ip = request.getHeader("X-Real-IP");
if (StringUtils.isNotEmpty(ip) && !"unKnown".equalsIgnoreCase(ip)) {
return ip;
}
return request.getRemoteAddr();
}

public StringRedisTemplate getEacRedisTemplate() {
return this.eacRedisTemplate;
}

public void setEacRedisTemplate(StringRedisTemplate eacRedisTemplate) {
this.eacRedisTemplate = eacRedisTemplate;
}
}

校验用户处理器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import cn.mysteel.data.redis.service.AbstractRedisCache;
import com.alibaba.fastjson.JSONObject;
import com.banksteel.openerp.commons.auth.RedisTokenManagerConfig;
import com.banksteel.openerp.commons.auth.TokenUserLoginHandler;
import com.banksteel.openerp.commons.constants.AuthorizationConstants;
import com.banksteel.openerp.commons.utils.StringConvertUtils;
import com.banksteel.openerp.user.AuthUser;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;


/**
* 2020/3/19 16:36<br>
* Description:
*/
@Slf4j
public class DuplicateCheckUserLoginHandler implements TokenUserLoginHandler<AuthUser> {
private AbstractRedisCache redisUtils;
private RedisTokenManagerConfig tokenManagerConfig;
private final String userTokenRedisKeyTemplate = "openerp:logincheck:";
private final String appUserTokenRedisKeyTemplate = "openerp:app:logincheck:";
private int expires = 60 * 60 ;

public DuplicateCheckUserLoginHandler(AbstractRedisCache redisUtils, RedisTokenManagerConfig tokenManagerConfig) {
this.redisUtils = redisUtils;
this.tokenManagerConfig = tokenManagerConfig;
}

@Override
public String loginAndCreateToken(AuthUser loginUser) {
String loginKey = getRedisKey(loginUser.getUserId(), loginUser.isApp());
String token = redisUtils.get(loginKey,"");
log.info("当前环境是否允许多地在线:{}", loginUser.isEnvAllowMultiOnline());
if (StringUtils.isNotBlank(token) && !loginUser.isEnvAllowMultiOnline()){
redisUtils.del(createTokenKey(token));
log.info(String.format("用户%s对应的token[%s]被强制登出",loginUser.getUserName(),token));
}
String newToken = StringConvertUtils.shortUuid();
if (loginUser.isApp()){
newToken = AuthorizationConstants.IS_APP_KEY + newToken;
}
Integer loginExpireSeconds = getLoginExpireSeconds(loginUser.getMemberId());
redisUtils.set(loginKey,newToken,getExpires(loginKey, loginExpireSeconds));
return newToken;
}

@Override
public int extend(AuthUser loginUser) {
String loginKey = getRedisKey(loginUser.getUserId());
Integer loginExpireSeconds = getLoginExpireSeconds(loginUser.getMemberId());
if (redisUtils.exists(loginKey)) {
redisUtils.expire(loginKey, getExpires(loginKey, loginExpireSeconds));
}
return loginUser.isApp() ? tokenManagerConfig.getExpires() * 24 * 7 : loginExpireSeconds;
}

@Override
public void loginOff(AuthUser loginUser) {
String loginKey = getRedisKey(loginUser.getUserId());
redisUtils.del(loginKey);
}

private String getRedisKey(long userId){
return this.getRedisKey(userId, false);
}

private String getRedisKey(long userId, boolean isApp){
if (isApp) {
return appUserTokenRedisKeyTemplate + userId;
} else {
return userTokenRedisKeyTemplate + userId;
}
}

private String createTokenKey(String token) {
return tokenManagerConfig.getKeyPrefix() + token;
}

private int getExpires(String key, Integer loginExpireSeconds){
return key.contains("app") ? tokenManagerConfig.getExpires() * 24 * 7 : loginExpireSeconds;
}

private Integer getLoginExpireSeconds(Long memberId) {
// token过期时间
String memberVO = redisUtils.get(AuthorizationConstants.LOGIN_USER_MEMBER_CACHE + memberId, "");
if(StringUtils.isEmpty(memberVO)) {
return expires;
}
JSONObject jsonObject = JSONObject.parseObject(memberVO);
Integer expireSeconds = jsonObject.getInteger("loginExpireSeconds");
return expireSeconds == null ? expires : expireSeconds;
}
}

用户登录常量

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* 用户登录常量
*
* @description:
* @projectName:openerp-webapp
* @className:LoginConstants.java
* @author:商家进销存项目组 xuxp
* @createTime:2016年8月8日 上午9:46:51
* @version 1.0
*/
public class LoginConstants {
// 用户登录状态cookie
public static final String SSO_LOGIN_TOKEN = "_sso_login_token";
//用户登录的ID号码
public static final String LOGIN_UID = "_login_uid";
// 登录url
public static final String LOGIN_URL = "login.banksteel.com";
// 返回登录url名称
public static final String LOGIN_URL_NAME = "login_url";

public static final String SESSION_USER = "userVO";
// 顶级域名
public static final String PARENT_DOMIAN = ".banksteel.com";
//用户会员idcookie
public static final String LOGIN_MEMBER = "_login_member";
//cookie存在时间
public static final int EXPIRE_SECONDS = 60 * 60 * 2;
}

token管理器统一入口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* 〈一句话功能简述〉<br>
* Description: token管理器统一入口
*
* @author hillchen
* @create 2019/4/30 13:23
*/
public interface TokenManager<U> {
/**
* 创建token并保存到redis和cookie中
* @param userInfo
* @return
*/
String createAndSaveToken(U userInfo, Long memberId);

/**
* 延长用户token的有效时间
*/
void extendUserToken();

/**
* 用户退出登陆
*/
void loginOff();

/**
* 获取用户信息
* @return
*/
U getUserByToken(Class<U> clazz);

/**
* @author:hillchen
* @serialData: 2020/3/19 15:43 <br>
*
* Description: 通过http上下文cookies中的token获取当前登录用户信息,如果存在登录用户,则延迟登录用户登录状态的有效时间,并返回,否则返回空
*
*/
default U getAndExtendUserByToken(Class<U> clazz){
U currentUser = getUserByToken(clazz);
saveCurrentLoginUser(currentUser);
extendUserToken();
return currentUser;
}

/**
* @author:hillchen
* @serialData: 2020/3/19 15:36 <br>
*
* Description: 保存当前登录用户人信息
*
*/
void saveCurrentLoginUser(U currentUser);

/**
* 获取token
* @Description:
* @return
* @author:Aoxin Liang
* @date: 2021年4月29日 下午2:34:05
*/
String getToken();
}

常量类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
public class AuthorizationConstants {

//http的请求常量
public static final String REQUEST_COMMAND = "request_command";

//cookie:用户的常量
public static final String COOKIE_LOGIN_USERID = "_login_uid";

//cookie:会员的常量
public static final String COOKIE_LOGIN_MEMBERID = "_login_memberId";

//cookie:登录token的常量
public static final String COOKIE_LOGIN_TOKEN = "_sso_login_token";

//Redis缓存:会员信息
public static final String MEMBERVO_CACHE = "openerp:memberVO_";
//Redis缓存:用户信息
public static final String USERVO_CACHE = "openerp:userVO_";
//Redis缓存:用户的会员集合
public static final String MEMBER_LIST_CACHE = "openerp:simpleMemberListVO_";
//Redis缓存:会员主账户
public static final String ADMIN_MEMBERVO_CACHE = "openerp:adminMemberVO_";
//Redis缓存:用户的会员集合信息
public static final String SYS_MEMBERVO_LIST_CACHE = "openerp:sysMemberVOList_";

public static final String COOKIE_LOGIN_DOMAIN = ".banksteel.com";

public static final String COOKIE_LOGIN_DOMAIN_DEMO = ".demo.openerp.banksteel.com";

// openerp接口访问域名
public static final String OPENERP_REQUEST_URL = "https://openerp.banksteel.com/%s/api";

//EAC公共组件抽取:登录用户信息
public static final String LOGIN_USER_CACHE = "openerp:loginUserVO:";
//EAC公共组件抽取:登录用户-会员信息
public static final String LOGIN_USER_MEMBER_CACHE = "openerp:loginUserMemberVO:";
//EAC公共组件抽取:角色用户信息
public static final String ROLE_USER_CACHE = "openerp:roleUserList:";
//EAC公共组件抽取:会员操作信息
public static final String MEMBER_COMMONDS_CACHE = "openerp:memberCommondsList:";
//用户登录密码错误安全保护
public static final String LOGIN_PWS_ERROR_COUNT = "openerp:loginPwsErrorCount:";
//忘记密码验证码错误安全保护
public static final String RESET_PWS_ERROR_COUNT = "openerp:resetPwsErrorCount:";

//注册手机号缓存
public static final String MOBILE_CHECKCODE_CACHE = "openerp:mobileCheckCode_";

//注册
public static final String REGISTER = "注册";

//加密的key
public static final String DEC_PUBLIC_KEY = "mysteelerp";

//APP
public static final String IS_APP_KEY = "app:";

/**
* 角色对应的操作key
*/
public static final String EAC_ROLE_OPERATION = "banksteel-min-eac-service:role_operation_";

//tokenKey前缀
public static final String TOKEN_PREFIX = "openerp:token:";

/**
* 准备上线提示
*/
public static final String PREPARE_UPGRADE_MSG = "openerp:prepare_upgrade_msg";
/**
* 开始上线提示
*/
public static final String START_UPGRADE_MSG = "openerp:start_upgrade_msg";

/**
* redis图片验证码缓存前缀
*/
public static final String IMG_VCODE_KEY_PREFIX = "openerp:imgVcode:";

public static final String USER_TOKEN_REDISKEY = "openerp:logincheck:";
public static final String APP_USER_TOKEN_REDISKEY = "openerp:app:logincheck:";

// 登录安全配置
public static final String LOGIN_EXPIRE_MINUTE = "login_expire_minute";

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/**
* @description:会员状态
* @projectName:openerp-commons
* @className:MemberStatusConstants.java
* @author:商家进销存项目组 衷文涛
* @createTime:2017年5月3日 下午3:42:15
* @version 1.0
*/
public class MemberStatusConstants {
public static final String NORMAL = "通过";
public static final String APPLIED = "待审";
public static final String LOCKING = "锁定";
public static final String UNINITIALIZED = "未初始化";
public static final String INITIALIZATION_FAILED = "初始化失败";
public static final String REJECTED = "驳回";
public static final String REGULAR = "正常";
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
* @description:
* @projectName:openerp-commons
* @className:ResponseResultEnum.java
* @author:商家进销存项目组 xuxp
* @createTime:2016年7月19日 下午5:35:00
* @version 1.0
*/
public enum ResponseResultEnum
{
SUCCESS("success"), FAIL("fail"), EXCEPTION("exception"),REPEAT("repeat");
private String value;

ResponseResultEnum(String value)
{
this.value = value;
}

public String getValue()
{
return value;
}

}

线程上下文信息类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* 〈一句话功能简述〉<br>
* Description: 线程上下文信息类
*
* @author hillchen
* @create 2019/5/22 17:29
*/
public class ThreadContext<T extends UserInfo> {
//当前登录用户信息
private T userInfo;
// 当前系统信息
private String appName;
// 当前请求源ip地址
private String ip;
// 当前请求源command
private String command;

public Long getMemberId() {
return userInfo == null ? null : userInfo.getMemberId();
}


public Long getUserId() {
return userInfo == null ? null : userInfo.getUserId();
}

public String getAppName() {
return appName;
}

public void setAppName(String appName) {
this.appName = appName;
}

public String getIp() {
return ip;
}

public void setIp(String ip) {
this.ip = ip;
}

public String getCommand() {
return command;
}

public void setCommand(String command) {
this.command = command;
}

public String getUserName() {
return userInfo == null ? null : userInfo.getUserName();
}

public T getUserInfo() {
return userInfo;
}

public void setUserInfo(T userInfo) {
this.userInfo = userInfo;
}

public Long getMemberOwerId(){
return userInfo.getMemberOwerId();
}
}

返回通用实体类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* @description: 返回通用实体类
* @projectName:openerp-commons
* @className:Response.java
* @author:xuxiepeg@banksteel
* @createTime:2016年6月30日 上午9:41:24
* @version 1.0
*/
public class ResponseEntity<T> implements Serializable
{
private static final long serialVersionUID = -1354109520823131322L;
private int code;
private long timeStamp;
private String result;
private String mess;
private T data;

public ResponseEntity()
{
super();
}

public ResponseEntity(int code, long timeStamp, String result, String mess, T data)
{
super();
this.code = code;
this.timeStamp = timeStamp;
this.result = result;
this.mess = mess;
this.data = data;
}

public int getCode()
{
return code;
}

public void setCode(int code)
{
this.code = code;
}

public long getTimeStamp()
{
return timeStamp;
}

public void setTimeStamp(long timeStamp)
{
this.timeStamp = timeStamp;
}

public String getResult()
{
return result;
}

public void setResult(String result)
{
this.result = result;
}

public String getMess()
{
return mess;
}

public void setMess(String mess)
{
this.mess = mess;
}

public T getData()
{
return data;
}

public void setData(T data)
{
this.data = data;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import cn.mysteel.util.DateUtils;

import java.io.Serializable;

@Data
public class AdminMemberVO implements Serializable {
private Long id;
private Long memberId; // 会员ID
private String memberName; // 会员名
private Long masterId; // 主账户ID
private String masterName;// 主账户名称
private String masterMobilephone; // 主账户联系方式
private Boolean inited; // 是否初始化
private String initedTime; // 初始化时间
private String appliedTime; // 申请时间
private String approvedTime; // 审批时间
private Boolean saleBlocked; // 是否一键封库
private String memberStatus; // 会员状态([待审、正常、锁定、未初始化、初始化失败...])
private String approveStatus; // 开通审批状态(待审、驳回、通过)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import com.alibaba.fastjson.annotation.JSONField;
import com.banksteel.openerp.commons.dto.user.DepartmentDTO;
import com.banksteel.openerp.commons.filter.UserInfo;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Data
public class UserVO implements UserInfo,Serializable {
private static final long serialVersionUID = 1L;

private long id; // 用户id
@Deprecated
@JSONField(serialize=false)
private String loginName; // 登录用户名
private String loginUName; // 用户姓名
private long loginTime = 0; // 登录时间
private String loginIpAddr = ""; // 登录ip
private String userSex = "";
private long memberId = 0; // 会员ID
private String memberName; // 会员名称
private Long memberOwerId; // 会员对应的获取人id
private boolean isMaster = false; //是否为主用户
private String companyName = "";
private String mobile = "";
private String departName = ""; //部门
private String adminName = ""; //管理员名称
private String adminPhone = ""; //管理员电话

private String passwd ; //密码
private String email = ""; //邮箱地址
private String portraitUrl = ""; //头像图片地址
private String passwordLevel ; //密码等级
private Set<String> mappingApps;
/**
* appId 和映射id(mapping_member_id)的map
*/
private Map<String, Long> mappingAppMap;

/**
* 用户所在有效部门信息,
* 登录后赋值,组织架构调整后需重新登录
*/
private List<DepartmentDTO> userDepartments;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import com.banksteel.openerp.commons.dto.user.DepartmentDTO;
import lombok.Data;

import java.util.List;

/**
* 〈一句话功能简述〉<br>
* Description: 登陆用户信息
*
* @author hillchen
* @create 2019/4/30 14:54
*/
@Data
public class AuthUser {
private Long memberOwerId;

private Long userId;

private Long memberId;

private String userName;

private boolean isApp;

List<DepartmentDTO> userDepartments;

private boolean envAllowMultiOnline;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
import java.util.List;
import java.util.Map;
import java.util.Set;

public interface AbstractRedisCache
{

/**
* 设置一个key的过期时间(单位:秒)
*
* @param key
* key值
* @param seconds
* 多少秒后过期
* @return 1:设置了过期时间 0:没有设置过期时间/不能设置过期时间
*/
long expire(String key, int seconds);

/**
* 设置一个key在某个时间点过期
*
* @param key
* key值
* @param unixTimestamp
* unix时间戳,从1970-01-01 00:00:00开始到现在的秒数
* @return 1:设置了过期时间 0:没有设置过期时间/不能设置过期时间
*/
long expireAt(String key, int unixTimestamp);

/**
* 截断一个List
*
* @param key
* 列表key
* @param start
* 开始位置 从0开始
* @param end
* 结束位置
* @return 状态码
*/
public String trimList(String key, long start, long end);

/**
* 检查Set长度
*
* @param key
* @return
*/
public long countSet(String key);

/**
* 添加到Set中(同时设置过期时间)
*
* @param key
* key值
* @param seconds
* 过期时间 单位s
* @param value
* @return
*/
public boolean addSet(String key, int seconds, String... value);

/**
* 添加到Set中
*
* @param key
* @param value
* @return
*/
public boolean addSet(String key, String... value);

/**
* @param key
* @param value
* @return 判断值是否包含在set中
*/
public boolean containsInSet(String key, String value);

/**
* 获取Set
*
* @param key
* @return
*/
public Set<String> getSet(String key);

/**
* 从set中删除value
*
* @param key
* @return
*/
public boolean removeSetValue(String key, String... value);

/**
* 从list中删除value 默认count 1
*
* @param key
* @param values
* 值list
* @return
*/
public int removeListValue(String key, List<String> values);

/**
* 从list中删除value
*
* @param key
* @param count
* @param values
* 值list
* @return
*/
public int removeListValue(String key, long count, List<String> values);

/**
* 从list中删除value
*
* @param key
* @param count
* 要删除个数
* @param value
* @return
*/
public boolean removeListValue(String key, long count, String value);

/**
* 截取List
*
* @param key
* @param start
* 起始位置
* @param end
* 结束位置
* @return
*/
public List<String> rangeList(String key, long start, long end);

/**
* 检查List长度
*
* @param key
* @return
*/
public long countList(String key);

/**
* 添加到List中(同时设置过期时间)
*
* @param key
* key值
* @param seconds
* 过期时间 单位s
* @param value
* @return
*/
public boolean addList(String key, int seconds, String... value);

/**
* 添加到List
*
* @param key
* @param value
* @return
*/
public boolean addList(String key, String... value);

/**
* 添加到List(只新增)
*
* @param key
* @param value
* @return
*/
public boolean addList(String key, List<String> list);

/**
* 获取List
*
* @param key
* @return
*/
public List<String> getList(String key);

/**
* 设置HashSet对象
*
* @param domain
* 域名
* @param key
* 键值
* @param value
* Json String or String value
* @return
*/
public boolean setHSet(String domain, String key, String value);

/**
* 获得HashSet对象
*
* @param domain
* 域名
* @param key
* 键值
* @return Json String or String value
*/
public String getHSet(String domain, String key);

/**
* 删除HashSet对象
*
* @param domain
* 域名
* @param key
* 键值
* @return 删除的记录数
*/
public long delHSet(String domain, String key);

/**
* 删除HashSet对象
*
* @param domain
* 域名
* @param key
* 键值
* @return 删除的记录数
*/
public long delHSet(String domain, String... key);

/**
* 判断key是否存在
*
* @param domain
* 域名
* @param key
* 键值
* @return
*/
public boolean existsHSet(String domain, String key);

/**
* 全局扫描hset
*
* @param match
* field匹配模式
* @return
*/
public List<Map.Entry<String, String>> scanHSet(String domain, String match);

/**
* 返回 domain 指定的哈希集中所有字段的value值
*
* @param domain
* @return
*/

public List<String> hvals(String domain);

/**
* 返回 domain 指定的哈希集中所有字段的key值
*
* @param domain
* @return
*/

public Set<String> hkeys(String domain);

/**
* 返回 domain 指定的哈希key值总数
*
* @param domain
* @return
*/
public long lenHset(String domain);

/**
* 设置排序集合
*
* @param key
* @param score
* @param value
* @return
*/
public boolean setSortedSet(String key, long score, String value);

/**
* 获得排序集合
*
* @param key
* @param startScore
* @param endScore
* @param orderByDesc
* @return
*/
public Set<String> getSoredSet(String key, long startScore, long endScore,
boolean orderByDesc);

/**
* 计算排序长度
*
* @param key
* @param startScore
* @param endScore
* @return
*/
public long countSoredSet(String key, long startScore, long endScore);

/**
* 删除排序集合
*
* @param key
* @param value
* @return
*/
public boolean delSortedSet(String key, String value);

/**
* 获得排序集合
*
* @param key
* @param startRange
* @param endRange
* @param orderByDesc
* @return
*/
public Set<String> getSoredSetByRange(String key, int startRange,
int endRange, boolean orderByDesc);

/**
* 获得排序打分
*
* @param key
* @return
*/
public Double getScore(String key, String member);

public boolean set(String key, String value, int second);

public boolean set(String key, String value);

public String get(String key, String defaultValue);

public boolean del(String key);

public long incr(String key);

public long decr(String key);

public boolean exists(String key);

}