Showing
18 changed files
with
1210 additions
and
23 deletions
... | ... | @@ -30,6 +30,11 @@ |
30 | 30 | <artifactId>spring-boot-starter-data-jpa</artifactId> |
31 | 31 | </dependency> |
32 | 32 | |
33 | + <dependency> | |
34 | + <groupId>org.springframework.boot</groupId> | |
35 | + <artifactId>spring-boot-starter-data-redis</artifactId> | |
36 | + </dependency> | |
37 | + | |
33 | 38 | <!-- MySQL Connector --> |
34 | 39 | <dependency> |
35 | 40 | <groupId>mysql</groupId> | ... | ... |
1 | +package com.ash.Filter; | |
2 | + | |
3 | +import com.ash.util.AshConstant; | |
4 | +import com.ash.util.RedisUtil; | |
5 | +import lombok.extern.slf4j.Slf4j; | |
6 | +import org.springframework.beans.factory.annotation.Value; | |
7 | +import org.springframework.core.annotation.Order; | |
8 | +import org.springframework.http.HttpStatus; | |
9 | +import org.springframework.http.server.reactive.ServerHttpResponse; | |
10 | +import org.springframework.stereotype.Component; | |
11 | + | |
12 | +import javax.annotation.Resource; | |
13 | +import javax.servlet.*; | |
14 | +import javax.servlet.http.HttpServletRequest; | |
15 | +import javax.servlet.http.HttpServletResponse; | |
16 | +import java.io.IOException; | |
17 | +import java.util.List; | |
18 | + | |
19 | +@Component | |
20 | +@Slf4j | |
21 | +@Order(1) | |
22 | +public class LoginFilter implements Filter { | |
23 | + | |
24 | + @Resource | |
25 | + RedisUtil redisUtil; | |
26 | + | |
27 | + @Value("#{'${auth.white.list}'.split(',')}") | |
28 | + private List<String> white_List; | |
29 | + | |
30 | + @Value("${auth.enable}") | |
31 | + private Boolean authEnable; | |
32 | + | |
33 | + | |
34 | + @Override | |
35 | + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { | |
36 | + HttpServletRequest request = (HttpServletRequest) servletRequest; | |
37 | + | |
38 | + if (authEnable == null || !authEnable) { | |
39 | + chain.doFilter(request, servletResponse); | |
40 | + return; | |
41 | + } | |
42 | + | |
43 | + // url白名单 | |
44 | + String path = request.getRequestURI(); | |
45 | + boolean isWhiteUrl = white_List.stream().anyMatch(path::endsWith); | |
46 | + | |
47 | + if (!isWhiteUrl) { | |
48 | + String sid = request.getHeader(AshConstant.AUTHORIZATION); | |
49 | + | |
50 | + String sessionKey = AshConstant.UC_LOGIN_SESSION + AshConstant.REDIS_DIVISION + sid; | |
51 | + String data = redisUtil.get(sessionKey); | |
52 | + | |
53 | + if (data == null) { | |
54 | + HttpServletResponse response = (HttpServletResponse) servletResponse; | |
55 | + response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); | |
56 | + return; | |
57 | + } | |
58 | + } | |
59 | + | |
60 | + chain.doFilter(request, servletResponse); | |
61 | + } | |
62 | +} | ... | ... |
1 | +package com.ash.Filter; | |
2 | + | |
3 | + | |
4 | +import com.alibaba.fastjson.JSONObject; | |
5 | +import com.ash.base.ExecutionContext; | |
6 | +import com.ash.util.AshConstant; | |
7 | +import com.ash.util.RedisUtil; | |
8 | +import lombok.extern.slf4j.Slf4j; | |
9 | +import org.apache.commons.lang3.StringUtils; | |
10 | +import org.springframework.core.annotation.Order; | |
11 | +import org.springframework.stereotype.Component; | |
12 | + | |
13 | +import javax.annotation.Resource; | |
14 | +import javax.servlet.*; | |
15 | +import javax.servlet.http.HttpServletRequest; | |
16 | +import java.io.IOException; | |
17 | +import java.lang.reflect.Type; | |
18 | +import java.util.Map; | |
19 | + | |
20 | +@Slf4j | |
21 | +@Order(2) | |
22 | +@Component | |
23 | +public class TransmitExecutionFilter implements Filter { | |
24 | + | |
25 | + @Resource | |
26 | + RedisUtil redisUtil; | |
27 | + | |
28 | + @Override | |
29 | + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | |
30 | + this.initCpmtext((HttpServletRequest) request); | |
31 | + chain.doFilter(request, response); | |
32 | + } | |
33 | + | |
34 | + private void initCpmtext(HttpServletRequest request) { | |
35 | + try { | |
36 | + String sid = request.getHeader(AshConstant.AUTHORIZATION); | |
37 | + log.info("接收sid信息:" + sid); | |
38 | + String sessionKey = AshConstant.UC_LOGIN_SESSION + AshConstant.REDIS_DIVISION + sid; | |
39 | + String data = redisUtil.get(sessionKey); | |
40 | + if (StringUtils.isNotBlank(data)) { | |
41 | + Map<String, Object> userMap = JSONObject.parseObject(data, (Type) Map.class); | |
42 | + String userId = userMap.get("id") + ""; | |
43 | + ExecutionContext.setUserId(userId); | |
44 | + ExecutionContext.setSid(sid); | |
45 | + } else { | |
46 | + String remoteHost = getRemoteHost(request); | |
47 | + log.error("================= init sid empty! ip:" + remoteHost); | |
48 | + } | |
49 | + | |
50 | + } catch (Exception e) { | |
51 | + log.error("init sid error", e); | |
52 | + } | |
53 | + | |
54 | + } | |
55 | + | |
56 | + public String getRemoteHost(HttpServletRequest request) { | |
57 | + String ip = request.getHeader("x-forwarded-for"); | |
58 | + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { | |
59 | + ip = request.getHeader("Proxy-Client-IP"); | |
60 | + } | |
61 | + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { | |
62 | + ip = request.getHeader("WL-Proxy-Client-IP"); | |
63 | + } | |
64 | + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { | |
65 | + ip = request.getRemoteAddr(); | |
66 | + } | |
67 | + return ip.equals("0:0:0:0:0:0:0:1") ? "127.0.0.1" : ip; | |
68 | + } | |
69 | +} | ... | ... |
... | ... | @@ -6,6 +6,10 @@ public enum AshErrorCode { |
6 | 6 | DATA_NOT_EXIST("数据不存在"), |
7 | 7 | INVOKE_SERVICE_FAILED("远程服务调用失败"), |
8 | 8 | SYSTEM_ERROR("系统异常"), |
9 | + USER_NOT_EXIST("用户不存在"), | |
10 | + LOGINNAME_PWD_NOT_MATCH("用户名密码不正确"), | |
11 | + USER_FORBIDDEN("用户名冻结"), | |
12 | + LOGINNAME_OR_PWD_EMPTY("用户名密码为空"), | |
9 | 13 | ; |
10 | 14 | |
11 | 15 | private final String text; | ... | ... |
1 | +package com.ash.base; | |
2 | + | |
3 | +import java.util.HashMap; | |
4 | +import java.util.Map; | |
5 | + | |
6 | +public class ExecutionContext { | |
7 | + private static ThreadLocal<Map<String, String>> threadLocal = new ThreadLocal<>(); | |
8 | + | |
9 | + /** | |
10 | + * 用户id 键 | |
11 | + */ | |
12 | + public static final String USER_ID = "user_id"; | |
13 | + public static final String SID = "sid"; | |
14 | + public static final String IS_SUPER_ADMIN = "is_super_admin"; | |
15 | + | |
16 | + /** | |
17 | + * 构造函数 | |
18 | + */ | |
19 | + public ExecutionContext() { | |
20 | + // For Spring initialization. | |
21 | + } | |
22 | + | |
23 | + /** | |
24 | + * 从 ThreadLocal中获取名值Map(不包含appCode) | |
25 | + * | |
26 | + * @return 名值Map | |
27 | + */ | |
28 | + public static Map<String, String> getContextMap() { | |
29 | + return threadLocal.get(); | |
30 | + } | |
31 | + | |
32 | + /** | |
33 | + * 从 ThreadLocal 获取名值Map | |
34 | + * | |
35 | + * @param contextMap 名值Map | |
36 | + */ | |
37 | + public static void setContextMap(Map<String, String> contextMap) { | |
38 | + threadLocal.set(contextMap); | |
39 | + } | |
40 | + | |
41 | + /** | |
42 | + * (获取键下的值.如果不存在,返回null;如果名值Map未初始化,也返回null) Get the value of key. Would | |
43 | + * return null if context map hasn't been initialized. | |
44 | + * | |
45 | + * @param key 键 | |
46 | + * @return 键下的值 | |
47 | + */ | |
48 | + public static String get(String key) { | |
49 | + Map<String, String> contextMap = getContextMap(); | |
50 | + if (contextMap == null) { | |
51 | + return null; | |
52 | + } | |
53 | + | |
54 | + return contextMap.get(key); | |
55 | + } | |
56 | + | |
57 | + /** | |
58 | + * (设置名值对。如果Map之前为null,则会被初始化) Put the key-value into the context map; | |
59 | + * <p> | |
60 | + * Initialize the map if the it doesn't exist. | |
61 | + * | |
62 | + * @param key 键 | |
63 | + * @param value 值 | |
64 | + * @return 之前的值 | |
65 | + */ | |
66 | + public static String put(String key, String value) { | |
67 | + Map<String, String> contextMap = getContextMap(); | |
68 | + if (contextMap == null) { | |
69 | + contextMap = new HashMap<>(); | |
70 | + setContextMap(contextMap); | |
71 | + } | |
72 | + | |
73 | + return contextMap.put(key, value); | |
74 | + } | |
75 | + | |
76 | + public static String getUserId() { | |
77 | + return get(USER_ID); | |
78 | + } | |
79 | + | |
80 | + public static void setUserId(String userId) { | |
81 | + put(USER_ID, userId); | |
82 | + } | |
83 | + | |
84 | + public static String getSid() { | |
85 | + return get(SID); | |
86 | + } | |
87 | + | |
88 | + public static void setSid(String sid) { | |
89 | + put(SID, sid); | |
90 | + } | |
91 | + | |
92 | + public static boolean isSuperAdmin(){ | |
93 | + String isSuperAdmin = get(IS_SUPER_ADMIN); | |
94 | + return "true".equals(isSuperAdmin); | |
95 | + } | |
96 | + | |
97 | + public static void setIsSuperAdmin(Boolean isSuperAdmin){ | |
98 | + put(IS_SUPER_ADMIN, isSuperAdmin+""); | |
99 | + } | |
100 | + | |
101 | +} | ... | ... |
1 | 1 | package com.ash.config; |
2 | 2 | |
3 | +import com.ash.base.ExecutionContext; | |
3 | 4 | import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; |
4 | 5 | import lombok.extern.slf4j.Slf4j; |
5 | 6 | import org.apache.ibatis.reflection.MetaObject; |
... | ... | @@ -14,19 +15,19 @@ public class MyMetaObjectHandler implements MetaObjectHandler { |
14 | 15 | @Override |
15 | 16 | public void insertFill(MetaObject metaObject) { |
16 | 17 | Date now=new Date(); |
17 | -// String userId = ExecutionContext.getUserId(); | |
18 | + String userId = ExecutionContext.getUserId(); | |
18 | 19 | this.strictInsertFill(metaObject, "createTime", Date.class, now); |
19 | 20 | this.strictUpdateFill(metaObject, "lastModifyTime", Date.class, now); |
20 | -// this.strictInsertFill(metaObject, "createBy", String.class, userId); | |
21 | -// this.strictUpdateFill(metaObject, "lastModifyBy", String.class, userId); | |
21 | + this.strictInsertFill(metaObject, "createBy", String.class, userId); | |
22 | + this.strictUpdateFill(metaObject, "lastModifyBy", String.class, userId); | |
22 | 23 | } |
23 | 24 | |
24 | 25 | @Override |
25 | 26 | public void updateFill(MetaObject metaObject) { |
26 | 27 | Date now=new Date(); |
27 | -// String userId = ExecutionContext.getUserId(); | |
28 | + String userId = ExecutionContext.getUserId(); | |
28 | 29 | this.strictUpdateFill(metaObject, "lastModifyTime", Date.class, now); |
29 | -// this.strictUpdateFill(metaObject, "lastModifyBy", String.class, userId); | |
30 | + this.strictUpdateFill(metaObject, "lastModifyBy", String.class, userId); | |
30 | 31 | } |
31 | 32 | } |
32 | 33 | ... | ... |
1 | +package com.ash.controller; | |
2 | + | |
3 | +import com.ash.base.BaseController; | |
4 | +import com.ash.base.ExecutionContext; | |
5 | +import com.ash.base.JsonResult; | |
6 | +import com.ash.base.OptionStatus; | |
7 | +import com.ash.entity.UserInfo; | |
8 | +import com.ash.service.UserService; | |
9 | +import lombok.extern.slf4j.Slf4j; | |
10 | +import org.springframework.web.bind.annotation.RequestBody; | |
11 | +import org.springframework.web.bind.annotation.RequestMapping; | |
12 | +import org.springframework.web.bind.annotation.RequestMethod; | |
13 | +import org.springframework.web.bind.annotation.RestController; | |
14 | + | |
15 | +import javax.annotation.Resource; | |
16 | + | |
17 | +@RestController | |
18 | +@RequestMapping("/login") | |
19 | +@Slf4j | |
20 | +public class LoginController extends BaseController { | |
21 | + @Resource | |
22 | + private UserService userService; | |
23 | + | |
24 | + @RequestMapping(value = "/login", method = RequestMethod.POST) | |
25 | + public JsonResult login(@RequestBody UserInfo userInfo) { | |
26 | + JsonResult loginResult = null; | |
27 | + try { | |
28 | + loginResult = userService.login(userInfo); | |
29 | + } catch (Exception ex) { | |
30 | + ex.printStackTrace(); | |
31 | + log.error(ex.getMessage()); | |
32 | + return JsonResult.error(OptionStatus.OPT_ERROR.getName()); | |
33 | + } | |
34 | + | |
35 | + return loginResult; | |
36 | + } | |
37 | + | |
38 | + @RequestMapping(value = "/logout", method = RequestMethod.POST) | |
39 | + public JsonResult logout() { | |
40 | + JsonResult loginResult = null; | |
41 | + try { | |
42 | + String userId = ExecutionContext.getUserId(); | |
43 | + loginResult = userService.logout(userId); | |
44 | + } catch (Exception ex) { | |
45 | + ex.printStackTrace(); | |
46 | + log.error(ex.getMessage()); | |
47 | + return JsonResult.error(OptionStatus.OPT_ERROR.getName()); | |
48 | + } | |
49 | + | |
50 | + return loginResult; | |
51 | + } | |
52 | +} | ... | ... |
1 | +package com.ash.controller; | |
2 | + | |
3 | + | |
4 | +import com.ash.base.BaseController; | |
5 | +import com.ash.base.JsonResult; | |
6 | +import com.ash.base.OptionStatus; | |
7 | +import com.ash.entity.UserInfo; | |
8 | +import com.ash.service.UserService; | |
9 | +import lombok.extern.slf4j.Slf4j; | |
10 | +import org.springframework.web.bind.annotation.PostMapping; | |
11 | +import org.springframework.web.bind.annotation.RequestBody; | |
12 | +import org.springframework.web.bind.annotation.RequestMapping; | |
13 | +import org.springframework.web.bind.annotation.RestController; | |
14 | + | |
15 | +import javax.annotation.Resource; | |
16 | + | |
17 | +@RestController | |
18 | +@RequestMapping("/user") | |
19 | +@Slf4j | |
20 | +public class UserServiceController extends BaseController { | |
21 | + | |
22 | + @Resource | |
23 | + private UserService userService; | |
24 | + | |
25 | + @PostMapping("/save") | |
26 | + public JsonResult saveUser(@RequestBody UserInfo userInfo) { | |
27 | + try { | |
28 | + boolean success = userService.save(userInfo); | |
29 | + return new JsonResult(success, OptionStatus.OPT_SUCCESS.getName(), null); | |
30 | + } catch (Exception ex) { | |
31 | + ex.printStackTrace(); | |
32 | + log.error(ex.getMessage()); | |
33 | + return JsonResult.error(OptionStatus.OPT_ERROR.getName()); | |
34 | + } | |
35 | + } | |
36 | +} | ... | ... |
src/main/java/com/ash/entity/UserInfo.java
0 → 100644
1 | +package com.ash.entity; | |
2 | + | |
3 | +import com.ash.base.BaseModel; | |
4 | +import com.ash.enums.UserStatusEnum; | |
5 | +import com.baomidou.mybatisplus.annotation.TableField; | |
6 | +import com.baomidou.mybatisplus.annotation.TableId; | |
7 | +import com.baomidou.mybatisplus.annotation.TableName; | |
8 | +import lombok.Data; | |
9 | + | |
10 | +@Data | |
11 | +@TableName(value = "t_ash_user") | |
12 | +public class UserInfo extends BaseModel { | |
13 | + @TableId(value = "id") | |
14 | + private String id; | |
15 | + | |
16 | + /** | |
17 | + * 工号 | |
18 | + */ | |
19 | + @TableField(value = "employee_code") | |
20 | + private String employeeCode; | |
21 | + | |
22 | + /** | |
23 | + * 姓名 | |
24 | + */ | |
25 | + @TableField(value = "user_name") | |
26 | + private String userName; | |
27 | + | |
28 | + /** | |
29 | + * 登录名 | |
30 | + */ | |
31 | + @TableField(value = "login_name") | |
32 | + private String loginName; | |
33 | + | |
34 | + /** | |
35 | + * 密码 | |
36 | + */ | |
37 | + @TableField(value = "password") | |
38 | + private String password; | |
39 | + | |
40 | + /** | |
41 | + * 状态(ENABLE 激活 FORBIDDEN冻结)" | |
42 | + */ | |
43 | + @TableField(value = "status") | |
44 | + private UserStatusEnum status; | |
45 | + | |
46 | + /** | |
47 | + * 性别(性别 0女 1男) | |
48 | + */ | |
49 | + @TableField(value = "sex") | |
50 | + private int sex; | |
51 | + | |
52 | + /** | |
53 | + * 手机号码 | |
54 | + */ | |
55 | + @TableField(value = "mobile") | |
56 | + private String mobile; | |
57 | + | |
58 | +} | ... | ... |
1 | +package com.ash.entity.dao; | |
2 | + | |
3 | +import com.ash.entity.UserInfo; | |
4 | +import com.github.yulichang.base.MPJBaseMapper; | |
5 | +import org.apache.ibatis.annotations.Mapper; | |
6 | +import org.springframework.stereotype.Repository; | |
7 | + | |
8 | +@Mapper | |
9 | +@Repository | |
10 | +public interface UserMapper extends CommonBaseMapper<UserInfo>, MPJBaseMapper<UserInfo> { | |
11 | +} | ... | ... |
1 | +package com.ash.service; | |
2 | + | |
3 | +import com.alibaba.fastjson.JSONObject; | |
4 | +import com.ash.base.AshErrorCode; | |
5 | +import com.ash.base.AshException; | |
6 | +import com.ash.base.JsonResult; | |
7 | +import com.ash.entity.UserInfo; | |
8 | +import com.ash.entity.dao.UserMapper; | |
9 | +import com.ash.enums.UserStatusEnum; | |
10 | +import com.ash.util.*; | |
11 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |
12 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
13 | +import lombok.extern.slf4j.Slf4j; | |
14 | +import org.apache.commons.lang3.StringUtils; | |
15 | +import org.springframework.stereotype.Service; | |
16 | +import org.springframework.util.CollectionUtils; | |
17 | + | |
18 | +import javax.annotation.Resource; | |
19 | +import java.util.List; | |
20 | +import java.util.concurrent.TimeUnit; | |
21 | + | |
22 | +@Slf4j | |
23 | +@Service | |
24 | +public class UserService { | |
25 | + | |
26 | + @Resource | |
27 | + private UserMapper userMapper; | |
28 | + | |
29 | + @Resource | |
30 | + RedisUtil redisUtil; | |
31 | + | |
32 | + public Boolean save(UserInfo userInfo) { | |
33 | + String uuid = UUIDGenerator.uuid(); | |
34 | + userInfo.setId(uuid); | |
35 | + String pwd = MD5Generator.getHexMD5(userInfo.getPassword()); | |
36 | + userInfo.setPassword(pwd); | |
37 | + if (userInfo.getStatus()==null) { | |
38 | + userInfo.setStatus(UserStatusEnum.ENABLE); | |
39 | + } | |
40 | + | |
41 | + int result = userMapper.insert(userInfo); | |
42 | + return result > 0; | |
43 | + } | |
44 | + | |
45 | + public Boolean saveAll(List<UserInfo> userInfoList) { | |
46 | + if (CollectionUtils.isEmpty(userInfoList)) { | |
47 | + throw new AshException(AshErrorCode.ILLEGAL_PARAM, "userInfoList is empty!"); | |
48 | + } | |
49 | + | |
50 | + int pageSize = 100; | |
51 | + int pages = (userInfoList.size() + pageSize - 1) / pageSize; | |
52 | + int count = 0; | |
53 | + int fromIndex = 0; | |
54 | + int toIndex = pageSize; | |
55 | + List<UserInfo> sub; | |
56 | + for (int i = 0; i < pages; i++) { | |
57 | + if (toIndex > userInfoList.size()) { | |
58 | + toIndex = userInfoList.size(); | |
59 | + } | |
60 | + log.info("from " + fromIndex + " to " + toIndex + "...."); | |
61 | + sub = userInfoList.subList(fromIndex, toIndex); | |
62 | + sub.forEach(t -> { | |
63 | + String uuid = UUIDGenerator.uuid(); | |
64 | + t.setId(uuid); | |
65 | + }); | |
66 | + try { | |
67 | + Integer result = userMapper.insertBatchSomeColumn(sub); | |
68 | + count += result; | |
69 | + } catch (Exception e) { | |
70 | + e.printStackTrace(); | |
71 | + } | |
72 | + fromIndex = toIndex; | |
73 | + toIndex = toIndex + pageSize; | |
74 | + } | |
75 | + | |
76 | + return count > 0; | |
77 | + } | |
78 | + | |
79 | + public JsonResult login(UserInfo loginUser) { | |
80 | + JsonResult result = new JsonResult(); | |
81 | + result.setSuccess(true); | |
82 | + if (StringUtils.isBlank(loginUser.getLoginName()) || StringUtils.isBlank(loginUser.getPassword())) { | |
83 | + result.setSuccess(false); | |
84 | + result.setMsg(AshErrorCode.LOGINNAME_OR_PWD_EMPTY.getText()); | |
85 | + return result; | |
86 | + } | |
87 | + | |
88 | + String password = loginUser.getPassword(); | |
89 | + password = AesUtils.aesDecrypt(password); | |
90 | + loginUser.setPassword(password); | |
91 | + | |
92 | + String loginPwd = MD5Generator.getHexMD5(loginUser.getPassword()); | |
93 | + UserInfo userInfo = getUserByLoginName(loginUser.getLoginName()); | |
94 | + | |
95 | + if (userInfo == null) { | |
96 | + result.setSuccess(false); | |
97 | + result.setMsg(AshErrorCode.USER_NOT_EXIST.getText()); | |
98 | + return result; | |
99 | + } | |
100 | + | |
101 | + if (!userInfo.getPassword().equals(loginPwd)) { | |
102 | + result.setSuccess(false); | |
103 | + result.setMsg(AshErrorCode.LOGINNAME_PWD_NOT_MATCH.getText()); | |
104 | + return result; | |
105 | + } | |
106 | + | |
107 | + if (UserStatusEnum.ENABLE != userInfo.getStatus()) { | |
108 | + result.setSuccess(false); | |
109 | + result.setMsg(AshErrorCode.USER_FORBIDDEN.getText()); | |
110 | + return result; | |
111 | + } | |
112 | + | |
113 | + String sessionId = storeSession(userInfo); | |
114 | + result.setData(sessionId); | |
115 | + return result; | |
116 | + } | |
117 | + | |
118 | + public JsonResult logout(String userId) { | |
119 | + JsonResult result = new JsonResult(); | |
120 | + try { | |
121 | + String loginKey = AshConstant.UC_ALREADY_LOGIN + AshConstant.REDIS_DIVISION + userId; | |
122 | + String loginSessionId = redisUtil.get(loginKey); | |
123 | + String loginSessionKey = AshConstant.UC_LOGIN_SESSION + AshConstant.REDIS_DIVISION + loginSessionId; | |
124 | + redisUtil.delete(loginSessionKey); | |
125 | + redisUtil.delete(loginKey); | |
126 | + | |
127 | + result.setSuccess(true); | |
128 | + } catch (Exception ex) { | |
129 | + ex.printStackTrace(); | |
130 | + log.error(ex.getMessage()); | |
131 | + result.setSuccess(false); | |
132 | + result.setMsg(AshErrorCode.SYSTEM_ERROR.getText()); | |
133 | + } | |
134 | + | |
135 | + return result; | |
136 | + } | |
137 | + | |
138 | + protected String storeSession(UserInfo userInfo) { | |
139 | + String sessionId = UUIDGenerator.uuid(); | |
140 | + try { | |
141 | + String loginKey = AshConstant.UC_ALREADY_LOGIN + AshConstant.REDIS_DIVISION + userInfo.getId(); | |
142 | + Boolean result = redisUtil.setNx(loginKey, sessionId); | |
143 | + //互踢 | |
144 | + if (!result) { | |
145 | + String loginSessionId = redisUtil.get(loginKey); | |
146 | + String loginSessionKey = AshConstant.UC_LOGIN_SESSION + AshConstant.REDIS_DIVISION + loginSessionId; | |
147 | + log.info("==========" + userInfo.getLoginName() + " already session id :{" + loginSessionId + "}"); | |
148 | + redisUtil.delete(loginSessionKey); | |
149 | + redisUtil.set(loginKey, sessionId); | |
150 | + } | |
151 | + | |
152 | + String sessionKey = AshConstant.UC_LOGIN_SESSION + AshConstant.REDIS_DIVISION + sessionId; | |
153 | + redisUtil.setEx(sessionKey, JSONObject.toJSONString(userInfo), AshConstant.sessionExprie, TimeUnit.MINUTES); | |
154 | + redisUtil.expire(loginKey, AshConstant.sessionExprie, TimeUnit.MINUTES); | |
155 | + | |
156 | + | |
157 | + } catch (Exception ex) { | |
158 | + ex.printStackTrace(); | |
159 | + log.error(ex.getMessage()); | |
160 | + } | |
161 | + return sessionId; | |
162 | + | |
163 | + } | |
164 | + | |
165 | + public UserInfo getUserByLoginName(String loginName) { | |
166 | + UserInfo userInfo = new UserInfo(); | |
167 | + userInfo.setLoginName(loginName); | |
168 | + List<UserInfo> userInfoList = listByCondition(userInfo); | |
169 | + if (CollectionUtils.isEmpty(userInfoList)) { | |
170 | + return null; | |
171 | + } | |
172 | + return userInfoList.get(0); | |
173 | + } | |
174 | + | |
175 | + public List<UserInfo> listByCondition(UserInfo userInfo) { | |
176 | + QueryWrapper<UserInfo> queryWrapper = getQwCondition(userInfo); | |
177 | + return userMapper.selectList(queryWrapper); | |
178 | + } | |
179 | + | |
180 | + private QueryWrapper<UserInfo> getQwCondition(UserInfo userInfo) { | |
181 | + if (userInfo == null) | |
182 | + return null; | |
183 | + QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<UserInfo>(); | |
184 | + LambdaQueryWrapper<UserInfo> lambda = queryWrapper.lambda(); | |
185 | + if (StringUtils.isNotBlank(userInfo.getUserName())) { | |
186 | + lambda.like(UserInfo::getUserName, userInfo.getUserName()); | |
187 | + } | |
188 | + | |
189 | + if (StringUtils.isNotBlank(userInfo.getLoginName())) { | |
190 | + lambda.eq(UserInfo::getLoginName, userInfo.getLoginName()); | |
191 | + } | |
192 | + | |
193 | + return queryWrapper; | |
194 | + } | |
195 | +} | ... | ... |
src/main/java/com/ash/util/AesUtils.java
0 → 100644
1 | +package com.ash.util; | |
2 | + | |
3 | + | |
4 | + | |
5 | +import org.apache.commons.lang3.StringUtils; | |
6 | +import org.slf4j.Logger; | |
7 | +import org.slf4j.LoggerFactory; | |
8 | + | |
9 | +import javax.crypto.Cipher; | |
10 | +import javax.crypto.KeyGenerator; | |
11 | +import javax.crypto.spec.SecretKeySpec; | |
12 | +import java.math.BigInteger; | |
13 | +import java.nio.charset.StandardCharsets; | |
14 | +import java.util.Base64; | |
15 | + | |
16 | + | |
17 | + | |
18 | +public class AesUtils { | |
19 | + //密钥 (需要前端和后端保持一致) | |
20 | + private static final String KEY = "MIGfMA0GCSqGSIb3"; | |
21 | + //算法 | |
22 | + private static final String ALGORITHMSTR = "AES/ECB/PKCS5Padding"; | |
23 | + | |
24 | + private static final Logger LOGGER = LoggerFactory.getLogger(AesUtils.class); | |
25 | + | |
26 | + public static String aesDecrypt(String encrypt) { | |
27 | + try { | |
28 | + return aesDecrypt(encrypt, KEY); | |
29 | + } catch (Exception e) { | |
30 | + LOGGER.error(e.getMessage(), e); | |
31 | + return ""; | |
32 | + } | |
33 | + } | |
34 | + | |
35 | + | |
36 | + public static String aesEncrypt(String content) { | |
37 | + try { | |
38 | + return aesEncrypt(content, KEY); | |
39 | + } catch (Exception e) { | |
40 | + LOGGER.error(e.getMessage(), e); | |
41 | + return ""; | |
42 | + } | |
43 | + } | |
44 | + | |
45 | + public static String binary(byte[] bytes, int radix){ | |
46 | + return new BigInteger(1, bytes).toString(radix);// 这里的1代表正数 | |
47 | + } | |
48 | + | |
49 | + public static String base64Encode(byte[] bytes){ | |
50 | + return Base64.getEncoder().encodeToString(bytes); | |
51 | + } | |
52 | + | |
53 | + public static byte[] base64Decode(String base64Code) throws Exception{ | |
54 | + return StringUtils.isEmpty(base64Code) ? null : Base64.getDecoder().decode(base64Code); | |
55 | + } | |
56 | + | |
57 | + | |
58 | + public static byte[] aesEncryptToBytes(String content, String encryptKey) throws Exception { | |
59 | + KeyGenerator kgen = KeyGenerator.getInstance("AES"); | |
60 | + kgen.init(128); | |
61 | + Cipher cipher = Cipher.getInstance(ALGORITHMSTR); | |
62 | + cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(encryptKey.getBytes(), "AES")); | |
63 | + | |
64 | + return cipher.doFinal(content.getBytes(StandardCharsets.UTF_8)); | |
65 | + } | |
66 | + | |
67 | + | |
68 | + public static String aesEncrypt(String content, String encryptKey) throws Exception { | |
69 | + return base64Encode(aesEncryptToBytes(content, encryptKey)); | |
70 | + } | |
71 | + | |
72 | + | |
73 | + public static String aesDecryptByBytes(byte[] encryptBytes, String decryptKey) throws Exception { | |
74 | + KeyGenerator kgen = KeyGenerator.getInstance("AES"); | |
75 | + kgen.init(128); | |
76 | + | |
77 | + Cipher cipher = Cipher.getInstance(ALGORITHMSTR); | |
78 | + cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(decryptKey.getBytes(), "AES")); | |
79 | + byte[] decryptBytes = cipher.doFinal(encryptBytes); | |
80 | + return new String(decryptBytes); | |
81 | + } | |
82 | + | |
83 | + | |
84 | + | |
85 | + public static String aesDecrypt(String encryptStr, String decryptKey) throws Exception { | |
86 | + return StringUtils.isEmpty(encryptStr) ? null : aesDecryptByBytes(base64Decode(encryptStr), decryptKey); | |
87 | + } | |
88 | + | |
89 | + /** | |
90 | + * 测试 | |
91 | + */ | |
92 | + public static void main(String[] args) { | |
93 | + String content = "123456"; | |
94 | + System.out.println("加密前:" + content); | |
95 | + System.out.println("加密密钥和解密密钥:" + KEY); | |
96 | + String encrypt = aesEncrypt(content); | |
97 | + System.out.println("加密后:" + encrypt); | |
98 | + String decrypt = aesDecrypt(encrypt); | |
99 | + System.out.println("解密后:" + decrypt); | |
100 | + } | |
101 | +} | ... | ... |
src/main/java/com/ash/util/AshConstant.java
0 → 100644
1 | +package com.ash.util; | |
2 | + | |
3 | +public interface AshConstant { | |
4 | + | |
5 | + String AUTHORIZATION = "SID"; | |
6 | + | |
7 | + String REDIS_DIVISION = "_"; | |
8 | + | |
9 | + Integer sessionExprie=1440; | |
10 | + | |
11 | + String UC_ALREADY_LOGIN = "ASH" + REDIS_DIVISION | |
12 | + + "ALREADY" + REDIS_DIVISION + "LOGIN"; | |
13 | + | |
14 | + | |
15 | + String UC_LOGIN_SESSION = "ASH" + REDIS_DIVISION | |
16 | + + "LOGIN" + REDIS_DIVISION + "SESSION"; | |
17 | + | |
18 | + | |
19 | +} | ... | ... |
src/main/java/com/ash/util/MD5Generator.java
0 → 100644
1 | +package com.ash.util; | |
2 | + | |
3 | + | |
4 | + | |
5 | +import java.security.MessageDigest; | |
6 | +import java.security.NoSuchAlgorithmException; | |
7 | + | |
8 | + | |
9 | +public final class MD5Generator { | |
10 | + | |
11 | + private static final String CHARSET = "UTF-8"; | |
12 | + private static final String MD5 = "MD5"; | |
13 | + private static final char[] HEX_DIGITS = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; | |
14 | + private MessageDigest digest; | |
15 | + | |
16 | + public MD5Generator() { | |
17 | + try { | |
18 | + this.digest = MessageDigest.getInstance("MD5"); | |
19 | + } catch (NoSuchAlgorithmException var2) { | |
20 | + var2.printStackTrace(); | |
21 | + } | |
22 | + | |
23 | + } | |
24 | + | |
25 | + public void update(byte[] data, int offset, int len) { | |
26 | + if (this.digest != null && data != null) { | |
27 | + this.digest.update(data, offset, len); | |
28 | + } | |
29 | + } | |
30 | + | |
31 | + public void update(byte[] data) { | |
32 | + if (data != null) { | |
33 | + this.update(data, 0, data.length); | |
34 | + } | |
35 | + } | |
36 | + | |
37 | + public String getHexMD5() { | |
38 | + byte[] digestData = this.digest.digest(); | |
39 | + return hexDigest(digestData); | |
40 | + } | |
41 | + | |
42 | + public byte[] getMD5() { | |
43 | + return this.digest.digest(); | |
44 | + } | |
45 | + | |
46 | + public static String getHexMD5(String data) { | |
47 | + try { | |
48 | + MessageDigest e = MessageDigest.getInstance("MD5"); | |
49 | + byte[] bytes = data.getBytes("UTF-8"); | |
50 | + e.update(bytes); | |
51 | + byte[] byteDigest = e.digest(); | |
52 | + return hexDigest(byteDigest).toLowerCase(); | |
53 | + } catch (Exception ex) { | |
54 | + ex.printStackTrace(); | |
55 | + return null; | |
56 | + } | |
57 | + } | |
58 | + | |
59 | + public static String hexDigest(byte[] byteDigest) { | |
60 | + char[] chars = new char[byteDigest.length * 2]; | |
61 | + | |
62 | + for (int i = 0; i < byteDigest.length; ++i) { | |
63 | + chars[i * 2] = HEX_DIGITS[byteDigest[i] >> 4 & 15]; | |
64 | + chars[i * 2 + 1] = HEX_DIGITS[byteDigest[i] & 15]; | |
65 | + } | |
66 | + | |
67 | + return new String(chars); | |
68 | + } | |
69 | + | |
70 | + public static void main(String[] args) { | |
71 | + String hexMD5 = MD5Generator.getHexMD5("Ahyj2023!@#"); | |
72 | + System.out.println(hexMD5); | |
73 | + } | |
74 | +} | ... | ... |
src/main/java/com/ash/util/RedisUtil.java
0 → 100644
1 | +package com.ash.util; | |
2 | + | |
3 | +import org.springframework.data.redis.core.RedisTemplate; | |
4 | +import org.springframework.stereotype.Component; | |
5 | + | |
6 | +import javax.annotation.Resource; | |
7 | +import java.util.List; | |
8 | +import java.util.Set; | |
9 | +import java.util.concurrent.TimeUnit; | |
10 | + | |
11 | +@Component | |
12 | +public class RedisUtil { | |
13 | + | |
14 | + | |
15 | + @Resource | |
16 | + private RedisTemplate redisTemplate; | |
17 | + | |
18 | + @SuppressWarnings("unchecked") | |
19 | + public void set(String key, Object value) { | |
20 | + redisTemplate.opsForValue().set(key, value); | |
21 | + } | |
22 | + | |
23 | + @SuppressWarnings("unchecked") | |
24 | + public void set(String key, Object value, long timeout, TimeUnit unit) { | |
25 | + redisTemplate.opsForValue().set(key, value, timeout, unit); | |
26 | + } | |
27 | + | |
28 | + @SuppressWarnings("unchecked") | |
29 | + public boolean setIfAbsent(String key, Object value, long timeout, TimeUnit unit) { | |
30 | + return Boolean.TRUE.equals(redisTemplate.opsForValue().setIfAbsent(key, value, timeout, unit)); | |
31 | + } | |
32 | + | |
33 | + @SuppressWarnings("unchecked") | |
34 | + public <T> T get(String key, Class<?> T) { | |
35 | + return (T) redisTemplate | |
36 | + .opsForValue().get(key); | |
37 | + } | |
38 | + | |
39 | + @SuppressWarnings("unchecked") | |
40 | + public void delete(String key) { | |
41 | + redisTemplate.delete(key); | |
42 | + } | |
43 | + | |
44 | + public String get(String key) { | |
45 | + return (String) redisTemplate | |
46 | + .opsForValue().get(key); | |
47 | + } | |
48 | + | |
49 | + @SuppressWarnings("unchecked") | |
50 | + public Long decr(String key) { | |
51 | + return redisTemplate | |
52 | + .opsForValue().decrement(key); | |
53 | + } | |
54 | + | |
55 | + @SuppressWarnings("unchecked") | |
56 | + public Long decr(String key, long delta) { | |
57 | + return redisTemplate | |
58 | + .opsForValue().decrement(key, delta); | |
59 | + } | |
60 | + | |
61 | + @SuppressWarnings("unchecked") | |
62 | + public Long incr(String key) { | |
63 | + return redisTemplate | |
64 | + .opsForValue().increment(key); | |
65 | + } | |
66 | + | |
67 | + @SuppressWarnings("unchecked") | |
68 | + public Long incr(String key, long delta) { | |
69 | + return redisTemplate | |
70 | + .opsForValue().increment(key, delta); | |
71 | + } | |
72 | + | |
73 | + @SuppressWarnings("unchecked") | |
74 | + public void expire(String key, long time, TimeUnit unit) { | |
75 | + redisTemplate.expire(key, time, unit); | |
76 | + } | |
77 | + | |
78 | + @SuppressWarnings("unchecked") | |
79 | + public Boolean setNx(String key, Object value) { | |
80 | + return redisTemplate.opsForValue().setIfAbsent(key, value); | |
81 | + } | |
82 | + | |
83 | + @SuppressWarnings("unchecked") | |
84 | + public void setEx(String key, String value, long timeout, TimeUnit unit) { | |
85 | + redisTemplate.opsForValue().set(key, value, timeout, unit); | |
86 | + } | |
87 | + | |
88 | + // ============================set============================= | |
89 | + | |
90 | + /** | |
91 | + * 根据key获取Set中的所有值 | |
92 | + * | |
93 | + * @param key 键 | |
94 | + */ | |
95 | + @SuppressWarnings("unchecked") | |
96 | + public Set<Object> sGet(String key) { | |
97 | + try { | |
98 | + return redisTemplate.opsForSet().members(key); | |
99 | + } catch (Exception e) { | |
100 | + e.printStackTrace(); | |
101 | + return null; | |
102 | + } | |
103 | + } | |
104 | + | |
105 | + | |
106 | + /** | |
107 | + * 根据value从一个set中查询,是否存在 | |
108 | + * | |
109 | + * @param key 键 | |
110 | + * @param value 值 | |
111 | + * @return true 存在 false不存在 | |
112 | + */ | |
113 | + @SuppressWarnings("unchecked") | |
114 | + public boolean sHasKey(String key, Object value) { | |
115 | + try { | |
116 | + return Boolean.TRUE.equals(redisTemplate.opsForSet().isMember(key, value)); | |
117 | + } catch (Exception e) { | |
118 | + e.printStackTrace(); | |
119 | + return false; | |
120 | + } | |
121 | + } | |
122 | + | |
123 | + | |
124 | + /** | |
125 | + * 将数据放入set缓存 | |
126 | + * | |
127 | + * @param key 键 | |
128 | + * @param values 值 可以是多个 | |
129 | + * @return 成功个数 | |
130 | + */ | |
131 | + public long sSet(String key, Object... values) { | |
132 | + try { | |
133 | + return redisTemplate.opsForSet().add(key, values); | |
134 | + } catch (Exception e) { | |
135 | + e.printStackTrace(); | |
136 | + return 0; | |
137 | + } | |
138 | + } | |
139 | + | |
140 | + | |
141 | + /** | |
142 | + * 将set数据放入缓存 | |
143 | + * | |
144 | + * @param key 键 | |
145 | + * @param time 时间(秒) | |
146 | + * @param values 值 可以是多个 | |
147 | + * @return 成功个数 | |
148 | + */ | |
149 | + @SuppressWarnings("unchecked") | |
150 | + public long sSetAndTime(String key, long time, TimeUnit timeUnit, Object... values) { | |
151 | + try { | |
152 | + Long count = redisTemplate.opsForSet().add(key, values); | |
153 | + if (time > 0) | |
154 | + expire(key, time, timeUnit); | |
155 | + return count; | |
156 | + } catch (Exception e) { | |
157 | + e.printStackTrace(); | |
158 | + return 0; | |
159 | + } | |
160 | + } | |
161 | + | |
162 | + | |
163 | + | |
164 | + /** | |
165 | + * 移除值为value的 | |
166 | + * | |
167 | + * @param key 键 | |
168 | + * @param values 值 可以是多个 | |
169 | + * @return 移除的个数 | |
170 | + */ | |
171 | + @SuppressWarnings("unchecked") | |
172 | + public long setRemove(String key, Object... values) { | |
173 | + try { | |
174 | + return redisTemplate.opsForSet().remove(key, values); | |
175 | + } catch (Exception e) { | |
176 | + e.printStackTrace(); | |
177 | + return 0; | |
178 | + } | |
179 | + } | |
180 | + | |
181 | + // ===============================list================================= | |
182 | + | |
183 | + /** | |
184 | + * 获取list缓存的内容 | |
185 | + * | |
186 | + * @param key 键 | |
187 | + * @param start 开始 | |
188 | + * @param end 结束 0 到 -1代表所有值 | |
189 | + */ | |
190 | + @SuppressWarnings("unchecked") | |
191 | + public List<Object> lGet(String key, long start, long end) { | |
192 | + try { | |
193 | + return redisTemplate.opsForList().range(key, start, end); | |
194 | + } catch (Exception e) { | |
195 | + e.printStackTrace(); | |
196 | + return null; | |
197 | + } | |
198 | + } | |
199 | + | |
200 | + | |
201 | + /** | |
202 | + * 获取list缓存的长度 | |
203 | + * | |
204 | + * @param key 键 | |
205 | + */ | |
206 | + @SuppressWarnings("unchecked") | |
207 | + public long lGetListSize(String key) { | |
208 | + try { | |
209 | + return redisTemplate.opsForList().size(key); | |
210 | + } catch (Exception e) { | |
211 | + e.printStackTrace(); | |
212 | + return 0; | |
213 | + } | |
214 | + } | |
215 | + | |
216 | + | |
217 | + /** | |
218 | + * 通过索引 获取list中的值 | |
219 | + * | |
220 | + * @param key 键 | |
221 | + * @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推 | |
222 | + */ | |
223 | + @SuppressWarnings("unchecked") | |
224 | + public Object lGetIndex(String key, long index) { | |
225 | + try { | |
226 | + return redisTemplate.opsForList().index(key, index); | |
227 | + } catch (Exception e) { | |
228 | + e.printStackTrace(); | |
229 | + return null; | |
230 | + } | |
231 | + } | |
232 | + | |
233 | + | |
234 | + /** | |
235 | + * 将list放入缓存 | |
236 | + * | |
237 | + * @param key 键 | |
238 | + * @param value 值 | |
239 | + */ | |
240 | + @SuppressWarnings("unchecked") | |
241 | + public boolean lSet(String key, Object value) { | |
242 | + try { | |
243 | + redisTemplate.opsForList().rightPush(key, value); | |
244 | + return true; | |
245 | + } catch (Exception e) { | |
246 | + e.printStackTrace(); | |
247 | + return false; | |
248 | + } | |
249 | + } | |
250 | + | |
251 | + | |
252 | + /** | |
253 | + * 将list放入缓存 | |
254 | + * | |
255 | + * @param key 键 | |
256 | + * @param value 值 | |
257 | + * @param time 时间(秒) | |
258 | + */ | |
259 | + @SuppressWarnings("unchecked") | |
260 | + public boolean lSet(String key, Object value, long time) { | |
261 | + try { | |
262 | + redisTemplate.opsForList().rightPush(key, value); | |
263 | + if (time > 0) | |
264 | + expire(key, time, TimeUnit.SECONDS); | |
265 | + return true; | |
266 | + } catch (Exception e) { | |
267 | + e.printStackTrace(); | |
268 | + return false; | |
269 | + } | |
270 | + | |
271 | + } | |
272 | + | |
273 | + | |
274 | + /** | |
275 | + * 将list放入缓存 | |
276 | + * | |
277 | + * @param key 键 | |
278 | + * @param value 值 | |
279 | + * @return | |
280 | + */ | |
281 | + @SuppressWarnings("unchecked") | |
282 | + public boolean lSet(String key, List<Object> value) { | |
283 | + try { | |
284 | + redisTemplate.opsForList().rightPushAll(key, value); | |
285 | + return true; | |
286 | + } catch (Exception e) { | |
287 | + e.printStackTrace(); | |
288 | + return false; | |
289 | + } | |
290 | + | |
291 | + } | |
292 | + | |
293 | + | |
294 | + /** | |
295 | + * 将list放入缓存 | |
296 | + * | |
297 | + * @param key 键 | |
298 | + * @param value 值 | |
299 | + * @param time 时间(秒) | |
300 | + * @return | |
301 | + */ | |
302 | + @SuppressWarnings("unchecked") | |
303 | + public boolean lSet(String key, List<Object> value, long time) { | |
304 | + try { | |
305 | + redisTemplate.opsForList().rightPushAll(key, value); | |
306 | + if (time > 0) | |
307 | + expire(key, time, TimeUnit.SECONDS); | |
308 | + return true; | |
309 | + } catch (Exception e) { | |
310 | + e.printStackTrace(); | |
311 | + return false; | |
312 | + } | |
313 | + } | |
314 | + | |
315 | + /** | |
316 | + * 根据索引修改list中的某条数据 | |
317 | + * | |
318 | + * @param key 键 | |
319 | + * @param index 索引 | |
320 | + * @param value 值 | |
321 | + * @return | |
322 | + */ | |
323 | + @SuppressWarnings("unchecked") | |
324 | + public boolean lUpdateIndex(String key, long index, Object value) { | |
325 | + try { | |
326 | + redisTemplate.opsForList().set(key, index, value); | |
327 | + return true; | |
328 | + } catch (Exception e) { | |
329 | + e.printStackTrace(); | |
330 | + return false; | |
331 | + } | |
332 | + } | |
333 | + | |
334 | + /** | |
335 | + * 移除N个值为value | |
336 | + * | |
337 | + * @param key 键 | |
338 | + * @param count 移除多少个 | |
339 | + * @param value 值 | |
340 | + * @return 移除的个数 | |
341 | + */ | |
342 | + @SuppressWarnings("unchecked") | |
343 | + public long lRemove(String key, long count, Object value) { | |
344 | + try { | |
345 | + return redisTemplate.opsForList().remove(key, count, value); | |
346 | + } catch (Exception e) { | |
347 | + e.printStackTrace(); | |
348 | + return 0; | |
349 | + } | |
350 | + | |
351 | + } | |
352 | + | |
353 | +} | ... | ... |
... | ... | @@ -24,6 +24,11 @@ spring: |
24 | 24 | test-on-borrow: true |
25 | 25 | test-on-return: true |
26 | 26 | test-while-idle: true |
27 | + redis: | |
28 | + cluster: | |
29 | + nodes: 10.9.1.252:16380 | |
30 | + password: qixiao@123.com | |
31 | + timeout: 3000 | |
27 | 32 | servlet: |
28 | 33 | multipart: |
29 | 34 | max-file-size: 100MB |
... | ... | @@ -34,5 +39,9 @@ logging: |
34 | 39 | file: |
35 | 40 | name: logs/ash.log |
36 | 41 | ash: |
37 | - # errorFilePath: D:/data/errorData | |
42 | + # errorFilePath: D:/data/errorData | |
38 | 43 | errorFilePath: /web/errorData |
44 | +auth: | |
45 | + enable: false | |
46 | + white: | |
47 | + list: /login | ... | ... |
... | ... | @@ -31,23 +31,23 @@ create table `t_ash_warning_instance` |
31 | 31 | |
32 | 32 | create table `t_ash_warning_instance_analysis` |
33 | 33 | ( |
34 | - id varchar(32) not null, | |
35 | - wi_id varchar(32), | |
36 | - area varchar(50), | |
37 | - amount double, | |
38 | - sex varchar(50), | |
39 | - career varchar(50), | |
40 | - rainage_method varchar(50), | |
41 | - pay_method varchar(50), | |
42 | - conform_status varchar(50) DEFAULT 'UNCONFIRMED', | |
43 | - create_time timestamp null, | |
44 | - create_by varchar(32), | |
45 | - last_modify_time timestamp null, | |
46 | - last_modify_by varchar(32), | |
34 | + id varchar(32) not null, | |
35 | + wi_id varchar(32), | |
36 | + area varchar(50), | |
37 | + amount double, | |
38 | + sex varchar(50), | |
39 | + career varchar(50), | |
40 | + rainage_method varchar(50), | |
41 | + pay_method varchar(50), | |
42 | + conform_status varchar(50) DEFAULT 'UNCONFIRMED', | |
43 | + create_time timestamp null, | |
44 | + create_by varchar(32), | |
45 | + last_modify_time timestamp null, | |
46 | + last_modify_by varchar(32), | |
47 | 47 | primary key (id) |
48 | 48 | ) comment = '警情分析结果' ENGINE = InnoDB; |
49 | 49 | |
50 | -create index i_wia_wi on t_ash_warning_instance_analysis(wi_id); | |
50 | +create index i_wia_wi on t_ash_warning_instance_analysis (wi_id); | |
51 | 51 | |
52 | 52 | create table `t_ash_case` |
53 | 53 | ( |
... | ... | @@ -58,7 +58,7 @@ create table `t_ash_case` |
58 | 58 | case_detail varchar(5000), |
59 | 59 | alarm_date timestamp null, |
60 | 60 | filing_date timestamp null, |
61 | - filing_unit varchar(200), | |
61 | + filing_unit varchar(200), | |
62 | 62 | analysis_status varchar(50) DEFAULT 'unanalysis', |
63 | 63 | review_status varchar(50) DEFAULT 'UNAUDITED', |
64 | 64 | area varchar(50), |
... | ... | @@ -96,7 +96,7 @@ create table `t_ash_case_analysis` |
96 | 96 | rainage_method varchar(50), |
97 | 97 | rainage_detail varchar(500), |
98 | 98 | pay_method varchar(50), |
99 | - conform_status varchar(50) DEFAULT 'UNCONFIRMED', | |
99 | + conform_status varchar(50) DEFAULT 'UNCONFIRMED', | |
100 | 100 | create_time timestamp null, |
101 | 101 | create_by varchar(32), |
102 | 102 | last_modify_time timestamp null, |
... | ... | @@ -104,7 +104,7 @@ create table `t_ash_case_analysis` |
104 | 104 | primary key (id) |
105 | 105 | ) comment = '案件分析结果' ENGINE = InnoDB; |
106 | 106 | |
107 | -create index i_case_ci on t_ash_case_analysis(case_id); | |
107 | +create index i_case_ci on t_ash_case_analysis (case_id); | |
108 | 108 | |
109 | 109 | create table `t_ash_file_data` |
110 | 110 | ( |
... | ... | @@ -118,3 +118,22 @@ create table `t_ash_file_data` |
118 | 118 | primary key (id) |
119 | 119 | ) comment = '文件数据' ENGINE = InnoDB; |
120 | 120 | |
121 | +create table `t_ash_user` | |
122 | +( | |
123 | + id varchar(32) not null, | |
124 | + employee_code varchar(50), | |
125 | + user_name varchar(50), | |
126 | + login_name varchar(50), | |
127 | + password varchar(50), | |
128 | + status varchar(50), | |
129 | + mobile varchar(50), | |
130 | + sex int, | |
131 | + create_time timestamp null, | |
132 | + create_by varchar(32), | |
133 | + last_modify_time timestamp null, | |
134 | + last_modify_by varchar(32), | |
135 | + primary key (id) | |
136 | +) comment = '用户表' ENGINE = InnoDB; | |
137 | + | |
138 | +create index i_user_l on t_ash_user(login_name); | |
139 | +create unique index u_user_login_name on t_ash_user (login_name); | |
\ No newline at end of file | ... | ... |