Skip to content

Commit 904cde9

Browse files
committed
feat: base core constant
1 parent 3c93f92 commit 904cde9

File tree

5 files changed

+346
-0
lines changed

5 files changed

+346
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package com.starimmortal.core.constant;
2+
3+
/**
4+
* 缓存常量
5+
*
6+
* @author william@StarImmortal
7+
* @date 2021/11/5
8+
*/
9+
public class CacheConstant {
10+
/**
11+
* 验证码 Redis Key
12+
*/
13+
public static final String CAPTCHA_CODE_KEY = "captcha:%s:string";
14+
15+
/**
16+
* 登录/注册短信验证码 Redis Key
17+
*/
18+
public static final String SMS_CODE_KEY = "sms:user:%s:string";
19+
20+
/**
21+
* 登录用户 Redis Key
22+
*/
23+
public static final String LOGIN_TOKEN_KEY = "login:user:token:%s:string";
24+
25+
/**
26+
* 令牌黑名单 Redis Key
27+
*/
28+
public static final String TOKEN_BLACKLIST_KEY = "token:black:%s:string";
29+
30+
/**
31+
* 防重提交 Redis Key
32+
*/
33+
public static final String REPEAT_SUBMIT_KEY = "repeat:submit:";
34+
35+
/**
36+
* 限流 Redis Key
37+
*/
38+
public static final String RATE_LIMIT_KEY = "rate:limit:";
39+
40+
/**
41+
* 登录账户密码错误次数 Redis Key
42+
*/
43+
public static final String PASSWORD_ERROR_COUNT_KEY = "password:error.count:";
44+
45+
/**
46+
* 手机号登录验证码错误次数 Redis Key
47+
*/
48+
public static final String PHONE_SMS_ERROR_COUNT_KEY = "sms:error.count:%s:string";
49+
50+
/**
51+
* Shiro权限缓存 Redis Key
52+
*/
53+
public static final String SHIRO_CACHE_KEY = "shiro:cache:com.starimmortal.shiro.shiro.ShiroRealm.authorizationCache:";
54+
55+
/**
56+
* 参数管理 Redis Key
57+
*/
58+
public static final String SYS_CONFIG_KEY = "system:config:";
59+
60+
/**
61+
* 字典管理 Redis Key
62+
*/
63+
public static final String SYS_DICT_KEY = "system:dict:";
64+
65+
/**
66+
* 用户获赞总数
67+
*/
68+
public static final String USER_TOTAL_LIKES = "user:likes:%s:long";
69+
70+
/**
71+
* 用户关注总数
72+
*/
73+
public static final String USER_TOTAL_FOLLOWERS = "user:followers:%s:long";
74+
75+
/**
76+
* 用户粉丝总数
77+
*/
78+
public static final String USER_TOTAL_FANS = "user:fans:%s:long";
79+
80+
/**
81+
* 用户关系:用于判断他们之间是否互粉
82+
*/
83+
public static final String USER_RELATIONSHIP = "user:relationship:%s:%s:long";
84+
85+
/**
86+
* 笔记获赞总数
87+
*/
88+
public static final String NOTE_TOTAL_LIKES = "note:likes:%s:long";
89+
90+
/**
91+
* 笔记评论总数
92+
*/
93+
public static final String NOTE_TOTAL_COMMENTS = "note:comment:count:%s:long";
94+
95+
/**
96+
* 笔记评论点赞总数
97+
*/
98+
public static final String NOTE_TOTAL_COMMENT_LIKES = "note:comment:likes:%s:long";
99+
100+
/**
101+
* 用户点赞笔记
102+
*/
103+
public static final String USER_LIKE_NOTE = "user:like:note:%s:%s:long";
104+
105+
/**
106+
* 用户点赞笔记评论
107+
*/
108+
public static final String USER_LIKE_NOTE_COMMENT = "user:like:note:comment:%s:long";
109+
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
package com.starimmortal.core.constant;
2+
3+
/**
4+
* 通用常量
5+
*
6+
* @author william@StarImmortal
7+
* @date 2021/11/05
8+
*/
9+
public class Constant {
10+
/**
11+
* UTF-8 字符集
12+
*/
13+
public static final String UTF8 = "UTF-8";
14+
15+
/**
16+
* GBK 字符集
17+
*/
18+
public static final String GBK = "GBK";
19+
20+
/**
21+
* http请求
22+
*/
23+
public static final String HTTP = "http://";
24+
25+
/**
26+
* https请求
27+
*/
28+
public static final String HTTPS = "https://";
29+
30+
/**
31+
* 通用成功标识
32+
*/
33+
public static final String SUCCESS = "0";
34+
35+
/**
36+
* 通用失败标识
37+
*/
38+
public static final String FAIL = "1";
39+
40+
/**
41+
* 登录成功
42+
*/
43+
public static final String LOGIN_SUCCESS = "Success";
44+
45+
/**
46+
* 注销
47+
*/
48+
public static final String LOGOUT = "Logout";
49+
50+
/**
51+
* 注册
52+
*/
53+
public static final String REGISTER = "Register";
54+
55+
/**
56+
* 登录失败
57+
*/
58+
public static final String LOGIN_FAIL = "Error";
59+
60+
/**
61+
* 验证码有效期(分钟)
62+
*/
63+
public static final Integer CAPTCHA_EXPIRATION_MINUTES = 2;
64+
65+
/**
66+
* 验证码有效期(秒)
67+
*/
68+
public static final Integer CAPTCHA_EXPIRATION_SECONDS = 300;
69+
70+
/**
71+
* 请求头
72+
*/
73+
public static final String HEADER = "header";
74+
75+
/**
76+
* 令牌
77+
*/
78+
public static final String TOKEN = "token";
79+
80+
/**
81+
* 认证头
82+
*/
83+
public static final String AUTHORIZATION_HEADER = "Authorization";
84+
85+
/**
86+
* 令牌前缀
87+
*/
88+
public static final String TOKEN_PREFIX = "Bearer ";
89+
90+
/**
91+
* 用户ID
92+
*/
93+
public static final String JWT_USER_ID = "uid";
94+
95+
/**
96+
* 用户名
97+
*/
98+
public static final String JWT_USERNAME = "username";
99+
100+
/**
101+
* 用户权限
102+
*/
103+
public static final String JWT_USER_AUTHORITIES = "authorities";
104+
105+
/**
106+
* 令牌颁布时间
107+
*/
108+
public static final String JWT_ISSUED = "issued";
109+
110+
/**
111+
* 令牌过期时间
112+
*/
113+
public static final String JWT_EXPIRES = "expires";
114+
115+
/**
116+
* 用户头像上传路径
117+
*/
118+
public static final String USER_AVATAR_PATH = "avatar";
119+
120+
/**
121+
* 省
122+
*/
123+
public static final String PROVINCE = "province";
124+
125+
/**
126+
* 市
127+
*/
128+
public static final String CITY = "city";
129+
130+
/**
131+
* 区
132+
*/
133+
public static final String COUNTY = "county";
134+
135+
/**
136+
* 城镇
137+
*/
138+
public static final String TOWN = "town";
139+
140+
/**
141+
* 乡村
142+
*/
143+
public static final String VILLAGE = "village";
144+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.starimmortal.core.constant;
2+
3+
/**
4+
* 身份认证常量
5+
*
6+
* @author pedro@TaleLin
7+
*/
8+
public class IdentityConstant {
9+
/**
10+
* 表示通过用户名和密码来进行身份认证
11+
*/
12+
public static final String USERNAME_PASSWORD_IDENTITY = "USERNAME_PASSWORD";
13+
14+
/**
15+
* 表示通过手机号和密码来进行身份认证
16+
*/
17+
public static final String PHONE_PASSWORD_IDENTITY = "PHONE_PASSWORD";
18+
19+
/**
20+
* 表示通过手机号和验证码来进行身份认证
21+
*/
22+
public static final String PHONE_CAPTCHA_IDENTITY = "PHONE_CAPTCHA";
23+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.starimmortal.core.constant;
2+
3+
import java.util.regex.Pattern;
4+
5+
/**
6+
* 常用正则表达式常量
7+
*
8+
* @author william@StarImmortal
9+
* @date 2022/09/08
10+
*/
11+
public class PatternConstant {
12+
/**
13+
* 手机号正则表达式
14+
*/
15+
public final static Pattern TELEPHONE_PATTERN = Pattern.compile("^(13\\d|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18\\d|19[0-35-9])\\d{8}$");
16+
17+
/**
18+
* 常规自动日期格式识别正则表达式
19+
*/
20+
public final static Pattern DATE_PATTERN = Pattern.compile("^[-+]?\\d*$");
21+
22+
/**
23+
* 驼峰转下划线正则表达式
24+
*/
25+
public final static Pattern UNDERLINE_PATTERN = Pattern.compile("_(\\w)");
26+
27+
/**
28+
* 令牌前缀正则表达式
29+
*/
30+
public final static String BEARER_PATTERN = "^Bearer$";
31+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.starimmortal.core.constant;
2+
3+
/**
4+
* 字符串常量
5+
*
6+
* @author william@StarImmortal
7+
* @date 2022/05/08
8+
*/
9+
public class StringConstant {
10+
/**
11+
* 空字符串
12+
*/
13+
public static final String EMPTY = "";
14+
15+
/**
16+
* 空格字符串
17+
*/
18+
public static final String SPACE = " ";
19+
20+
/**
21+
* 斜杠分隔符
22+
*/
23+
public static final String SEPARATOR = "/";
24+
25+
/**
26+
* 横线分隔符
27+
*/
28+
public static final String LINE_SEPARATOR = "-";
29+
30+
/**
31+
* 下划线分隔符
32+
*/
33+
public static final String SNAKE_SEPARATOR = "_";
34+
35+
/**
36+
* 冒号分隔符
37+
*/
38+
public static final String COLON_SEPARATOR = ":";
39+
}

0 commit comments

Comments
 (0)