> entry : strategyMap.entrySet()) {
66 | String fieldKey = entry.getKey();
67 | IEncryptResultFieldStrategy fieldEncryptStrategy = entry.getValue().newInstance();
68 | Object fieldValue = metaReturnItem.getValue(fieldKey);
69 | if (fieldValue instanceof String) {
70 | metaReturnItem.setValue(fieldKey, fieldEncryptStrategy.encrypt((String) fieldValue));
71 | }
72 | }
73 | }
74 | }
75 | }
76 | } catch (Exception e) {
77 | // ignore
78 | }
79 |
80 | }
81 | }
82 | return returnValue;
83 |
84 | }
85 |
86 | @Override
87 | public Object plugin(Object target) {
88 | return Plugin.wrap(target, this);
89 | }
90 |
91 | @Override
92 | public void setProperties(Properties properties) {
93 |
94 | }
95 |
96 | /**
97 | * 获取方法上的EncryptResultFieldAnnotation注解
98 | *
99 | * @param mappedStatement MappedStatement
100 | * @return EncryptResultFieldAnnotation注解
101 | */
102 | private EncryptResultFieldAnnotation getEncryptResultFieldAnnotation(MappedStatement mappedStatement) {
103 | EncryptResultFieldAnnotation encryptResultFieldAnnotation = null;
104 | try {
105 | String id = mappedStatement.getId();
106 | String className = id.substring(0, id.lastIndexOf("."));
107 | String methodName = id.substring(id.lastIndexOf(".") + 1);
108 | final Method[] method = Class.forName(className).getMethods();
109 | for (Method me : method) {
110 | if (me.getName().equals(methodName) && me.isAnnotationPresent(EncryptResultFieldAnnotation.class)) {
111 | encryptResultFieldAnnotation = me.getAnnotation(EncryptResultFieldAnnotation.class);
112 | break;
113 | }
114 | }
115 | } catch (Exception ex) {
116 | ex.printStackTrace();
117 | }
118 | return encryptResultFieldAnnotation;
119 | }
120 |
121 |
122 | }
123 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/java/com/tuacy/mybatis/interceptor/interceptor/encryptresultfield/IEncryptResultFieldStrategy.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.mybatis.interceptor.interceptor.encryptresultfield;
2 |
3 | /**
4 | * 加密策略
5 | */
6 | public interface IEncryptResultFieldStrategy {
7 |
8 | /**
9 | * 返回加密之后的字符
10 | *
11 | * @param source 原始字符
12 | * @return 加密之后的字符
13 | */
14 | String encrypt(String source);
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/java/com/tuacy/mybatis/interceptor/interceptor/log/LogInterceptor.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.mybatis.interceptor.interceptor.log;
2 |
3 | import org.apache.ibatis.executor.Executor;
4 | import org.apache.ibatis.mapping.BoundSql;
5 | import org.apache.ibatis.mapping.MappedStatement;
6 | import org.apache.ibatis.mapping.ParameterMapping;
7 | import org.apache.ibatis.plugin.*;
8 | import org.apache.ibatis.reflection.MetaObject;
9 | import org.apache.ibatis.session.Configuration;
10 | import org.apache.ibatis.session.ResultHandler;
11 | import org.apache.ibatis.session.RowBounds;
12 | import org.apache.ibatis.type.TypeHandlerRegistry;
13 |
14 | import java.text.DateFormat;
15 | import java.util.Date;
16 | import java.util.List;
17 | import java.util.Locale;
18 | import java.util.Properties;
19 |
20 |
21 | /**
22 | * 1. 打印mysql完整的执行语句
23 | * 2. 打印mysql语句执行时间
24 | * 这里我们拦截Executor里面的query和update方法
25 | */
26 | @Intercepts({
27 | @Signature(
28 | method = "query",
29 | type = Executor.class,
30 | args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}
31 | ),
32 | @Signature(
33 | type = Executor.class,
34 | method = "update",
35 | args = {MappedStatement.class, Object.class}
36 | )
37 | })
38 | public class LogInterceptor implements Interceptor {
39 |
40 | /**
41 | * 是否显示语句的执行时间
42 | */
43 | public static final String PROPERTIES_KEY_ENABLE_EXECUTOR_TIME = "enableExecutorTIme";
44 | public static final String ENABLE_EXECUTOR_TIME = "0"; // 显示
45 |
46 | private boolean enableExecutorTime = false;
47 |
48 | @Override
49 | public Object intercept(Invocation invocation) throws Throwable {
50 | // 获取执行方法的MappedStatement参数,不管是Executor的query方法还是update方法,第一个参数都是MappedStatement
51 | MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
52 | Object parameter = null;
53 | if (invocation.getArgs().length > 1) {
54 | parameter = invocation.getArgs()[1];
55 | }
56 | String sqlId = mappedStatement.getId();
57 | BoundSql boundSql = mappedStatement.getBoundSql(parameter);
58 | Configuration configuration = mappedStatement.getConfiguration();
59 | long sqlStartTime = System.currentTimeMillis();
60 | Object re = invocation.proceed();
61 | long sqlEndTime = System.currentTimeMillis();
62 | // 打印mysql执行语句
63 | String sql = getSql(configuration, boundSql, sqlId);
64 | System.out.println(sql);
65 | // 打印mysql执行时间
66 | if (enableExecutorTime) {
67 | String sqlTimeLog = sqlId + " 方法对应sql执行时间:" + (sqlEndTime - sqlStartTime) + " ms";
68 | System.out.println(sqlTimeLog);
69 | }
70 | return re;
71 | }
72 |
73 | /**
74 | * 通过该方法决定要返回的对象是目标对象还是对应的代理
75 | * 不要想的太复杂,一般就两种情况:
76 | *
77 | * 1. return target; 直接返回目标对象,相当于当前Interceptor没起作用,不会调用上面的intercept()方法
78 | * 2. return Plugin.wrap(target, this); 返回代理对象,会调用上面的intercept()方法
79 | *
80 | * @param target 目标对象
81 | * @return 目标对象或者代理对象
82 | */
83 | @Override
84 | public Object plugin(Object target) {
85 | return Plugin.wrap(target, this);
86 | }
87 |
88 | /**
89 | * 用于获取在Configuration初始化当前的Interceptor时时候设置的一些参数
90 | *
91 | * @param properties Properties参数
92 | */
93 | @Override
94 | public void setProperties(Properties properties) {
95 | if (properties != null) {
96 | String executorTImeValue = properties.getProperty(PROPERTIES_KEY_ENABLE_EXECUTOR_TIME);
97 | if (executorTImeValue != null) {
98 | enableExecutorTime = executorTImeValue.equals(ENABLE_EXECUTOR_TIME);
99 | }
100 | }
101 | }
102 |
103 | private static String getSql(Configuration configuration, BoundSql boundSql, String sqlId) {
104 | return sqlId + " 方法对应sql执行语句:" + assembleSql(configuration, boundSql);
105 | }
106 |
107 | /**
108 | * 转义正则特殊字符 ($()*+.[]?\^{}
109 | * \\需要第一个替换,否则replace方法替换时会有逻辑bug
110 | */
111 | private static String makeQueryStringAllRegExp(String str) {
112 | if (str != null && !str.equals("")) {
113 | return str.replace("\\", "\\\\").replace("*", "\\*")
114 | .replace("+", "\\+").replace("|", "\\|")
115 | .replace("{", "\\{").replace("}", "\\}")
116 | .replace("(", "\\(").replace(")", "\\)")
117 | .replace("^", "\\^").replace("$", "\\$")
118 | .replace("[", "\\[").replace("]", "\\]")
119 | .replace("?", "\\?").replace(",", "\\,")
120 | .replace(".", "\\.").replace("&", "\\&");
121 | }
122 | return str;
123 | }
124 |
125 | /**
126 | * 获取参数对应的string值
127 | *
128 | * @param obj 参数对应的值
129 | * @return string
130 | */
131 | private static String getParameterValue(Object obj) {
132 | String value;
133 | if (obj instanceof String) {
134 | value = "'" + obj.toString() + "'";
135 | } else if (obj instanceof Date) {
136 | DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.CHINA);
137 | value = "'" + formatter.format(new Date()) + "'";
138 | } else {
139 | if (obj != null) {
140 | value = obj.toString();
141 | } else {
142 | value = "";
143 | }
144 |
145 | }
146 | // 对特殊字符进行转义,方便之后处理替换
147 | return value != null ? makeQueryStringAllRegExp(value) : value;
148 | }
149 |
150 | /**
151 | * 组装完整的sql语句 -- 把对应的参数都代入到sql语句里面
152 | *
153 | * @param configuration Configuration
154 | * @param boundSql BoundSql
155 | * @return sql完整语句
156 | */
157 | private static String assembleSql(Configuration configuration, BoundSql boundSql) {
158 | // 获取mapper里面方法上的参数
159 | Object sqlParameter = boundSql.getParameterObject();
160 | // sql语句里面需要的参数 -- 真实需要用到的参数 因为sqlParameter里面的每个参数不一定都会用到
161 | List parameterMappings = boundSql.getParameterMappings();
162 | // sql原始语句(?还没有替换成我们具体的参数)
163 | String sql = boundSql.getSql().replaceAll("[\\s]+", " ");
164 | if (parameterMappings.size() > 0 && sqlParameter != null) {
165 | // sql语句里面的?替换成真实的参数
166 | TypeHandlerRegistry typeHandlerRegistry = configuration.getTypeHandlerRegistry();
167 | if (typeHandlerRegistry.hasTypeHandler(sqlParameter.getClass())) {
168 | sql = sql.replaceFirst("\\?", getParameterValue(sqlParameter));
169 | } else {
170 | MetaObject metaObject = configuration.newMetaObject(sqlParameter);
171 | for (ParameterMapping parameterMapping : parameterMappings) {
172 | // 一个一个把对应的值替换进去 按顺序把?替换成对应的值
173 | String propertyName = parameterMapping.getProperty();
174 | if (metaObject.hasGetter(propertyName)) {
175 | Object obj = metaObject.getValue(propertyName);
176 | sql = sql.replaceFirst("\\?", getParameterValue(obj));
177 | } else if (boundSql.hasAdditionalParameter(propertyName)) {
178 | Object obj = boundSql.getAdditionalParameter(propertyName);
179 | sql = sql.replaceFirst("\\?", getParameterValue(obj));
180 | }
181 | }
182 | }
183 | }
184 | return sql;
185 | }
186 | }
187 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/java/com/tuacy/mybatis/interceptor/interceptor/page/PageView.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.mybatis.interceptor.interceptor.page;
2 |
3 | import java.util.List;
4 |
5 | public class PageView {
6 |
7 | /**
8 | * 默认每一页的数据大小
9 | */
10 | private static final int PAGE_SIZE = 10;
11 |
12 | /**
13 | * 当前需要查询的页码 ,从0开始
14 | */
15 | private int pageNo;
16 | /**
17 | * 每页显示几条记录
18 | */
19 | private int pageSize;
20 | /**
21 | * 总记录数
22 | */
23 | private long totalCount;
24 | /**
25 | * 是否需要进行count查询,因为在有些情况,不需要每次都进行count查询
26 | */
27 | private boolean doCount;
28 | /**
29 | * 总页数
30 | */
31 | private long totalPage;
32 |
33 | /**
34 | * 最终查询出来的数据
35 | */
36 | private List lists;
37 |
38 | public PageView() {
39 | this(0);
40 | }
41 |
42 | /**
43 | * 使用构造函数,,强制必需输入 当前页
44 | *
45 | * @param pageNo 当前页
46 | */
47 | public PageView(int pageNo) {
48 | this(pageNo, PAGE_SIZE, true);
49 | }
50 |
51 | /**
52 | * @param pageSize 每一页的大小
53 | * @param pageNo 当前查询第几页,从1开始
54 | */
55 | public PageView(int pageNo, int pageSize) {
56 | this(pageNo, pageSize, true);
57 | }
58 |
59 | /**
60 | * @param pageSize 每一页的大小
61 | * @param pageNo 当前查询第几页,从1开始
62 | * @param doCount 是否需要进行count查询
63 | */
64 | public PageView(int pageNo, int pageSize, boolean doCount) {
65 | this.pageNo = pageNo;
66 | this.pageSize = pageSize;
67 | this.doCount = doCount;
68 | }
69 |
70 | /**
71 | * 查询结果方法 把 记录数 结果集合 放入到 PageView对象
72 | *
73 | * @param rowCount 总记录数
74 | * @param records 结果集合
75 | */
76 |
77 | public void setQueryResult(long rowCount, List records) {
78 | setLists(records);
79 | }
80 |
81 |
82 | public List getLists() {
83 | return lists;
84 | }
85 |
86 | public void setLists(List lists) {
87 | this.lists = lists;
88 | }
89 |
90 | public int getPageNo() {
91 | return pageNo;
92 | }
93 |
94 | public void setPageNo(int pageNo) {
95 | this.pageNo = pageNo;
96 | }
97 |
98 | public int getPageSize() {
99 | return pageSize;
100 | }
101 |
102 | public void setPageSize(int pageSize) {
103 | this.pageSize = pageSize;
104 | }
105 |
106 | public long getTotalCount() {
107 | return totalCount;
108 | }
109 |
110 | public void setTotalCount(long totalCount) {
111 | this.totalCount = totalCount;
112 | setTotalPage(this.totalCount % this.pageSize == 0 ? this.totalCount / this.pageSize : this.totalCount / this.pageSize + 1);
113 | }
114 |
115 | public long getTotalPage() {
116 | return totalPage;
117 | }
118 |
119 | public void setTotalPage(long totalPage) {
120 | this.totalPage = totalPage;
121 | }
122 |
123 | public boolean isDoCount() {
124 | return doCount;
125 | }
126 |
127 | public void setDoCount(boolean doCount) {
128 | this.doCount = doCount;
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/java/com/tuacy/mybatis/interceptor/interceptor/tableshard/DayTableShardStrategy.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.mybatis.interceptor.interceptor.tableshard;
2 |
3 | import org.apache.ibatis.mapping.BoundSql;
4 | import org.apache.ibatis.reflection.MetaObject;
5 |
6 | import java.text.SimpleDateFormat;
7 | import java.util.Date;
8 |
9 | /**
10 | * 按日分表,根据当前时间
11 | */
12 | public class DayTableShardStrategy implements ITableShardStrategy {
13 |
14 | /**
15 | * 分表策略
16 | *
17 | * @param metaStatementHandler MetaObject包装的RoutingStatementHandler对象
18 | * @param tableName 原始表名
19 | * @param shardParamKey 可以在mapper文件的方法里面传递一些参数key过来,在分表策略里面通过key获取到对应的值
20 | * @return 包装之后的sql语句
21 | */
22 | @Override
23 | public String tableShard(MetaObject metaStatementHandler, String tableName, String[] shardParamKey) {
24 | BoundSql boundSql = (BoundSql) metaStatementHandler.getValue("delegate.boundSql");
25 | String originSql = boundSql.getSql();
26 | // 当前时间
27 | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
28 | String newTableName = tableName + "_" + sdf.format(new Date());
29 | return originSql.replaceAll(tableName, newTableName);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/java/com/tuacy/mybatis/interceptor/interceptor/tableshard/ITableShardStrategy.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.mybatis.interceptor.interceptor.tableshard;
2 |
3 | import org.apache.ibatis.reflection.MetaObject;
4 |
5 | /**
6 | * 分表策略
7 | */
8 | public interface ITableShardStrategy {
9 |
10 | /**
11 | * 分表策略
12 | *
13 | * @param metaStatementHandler MetaObject包装的RoutingStatementHandler对象
14 | * @param tableName 原始表名
15 | * @param shardParamKey 可以在mapper文件的方法里面传递一些参数key过来,在分表策略里面通过key获取到对应的值
16 | * @return 包装之后的sql语句
17 | */
18 | String tableShard(MetaObject metaStatementHandler, String tableName, String[] shardParamKey) throws Exception;
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/java/com/tuacy/mybatis/interceptor/interceptor/tableshard/MonthTableShardStrategy.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.mybatis.interceptor.interceptor.tableshard;
2 |
3 | import org.apache.ibatis.mapping.BoundSql;
4 | import org.apache.ibatis.reflection.MetaObject;
5 |
6 | import java.text.SimpleDateFormat;
7 | import java.util.Date;
8 |
9 | /**
10 | * 按月分表,根据当前时间
11 | */
12 | public class MonthTableShardStrategy implements ITableShardStrategy {
13 |
14 | @Override
15 | public String tableShard(MetaObject metaStatementHandler, String tableName, String[] shardParamKey) {
16 |
17 | BoundSql boundSql = (BoundSql) metaStatementHandler.getValue("delegate.boundSql");
18 | String originSql = boundSql.getSql();
19 | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
20 | String newTableName = tableName + "_" + sdf.format(new Date());
21 | return originSql.replaceAll(tableName, newTableName);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/java/com/tuacy/mybatis/interceptor/interceptor/tableshard/TableShardAnnotation.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.mybatis.interceptor.interceptor.tableshard;
2 |
3 | import java.lang.annotation.*;
4 |
5 | /**
6 | * 分表注解
7 | */
8 | @Target({ElementType.METHOD})
9 | @Retention(RetentionPolicy.RUNTIME)
10 | @Inherited
11 | @Documented
12 | public @interface TableShardAnnotation {
13 | /**
14 | * 待分表的表名
15 | */
16 | String tableName();
17 |
18 | /**
19 | * 分表策略
20 | */
21 | Class extends ITableShardStrategy> shadeStrategy();
22 |
23 | /**
24 | * 分表条件key, 通过key去参数列表里取对应的值,作为分表条件处理
25 | */
26 | String[] shardParamKey() default {};
27 | }
28 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/java/com/tuacy/mybatis/interceptor/interceptor/tableshard/TableShardInterceptor.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.mybatis.interceptor.interceptor.tableshard;
2 |
3 | import org.apache.ibatis.executor.statement.RoutingStatementHandler;
4 | import org.apache.ibatis.executor.statement.StatementHandler;
5 | import org.apache.ibatis.mapping.BoundSql;
6 | import org.apache.ibatis.mapping.MappedStatement;
7 | import org.apache.ibatis.plugin.*;
8 | import org.apache.ibatis.reflection.DefaultReflectorFactory;
9 | import org.apache.ibatis.reflection.MetaObject;
10 | import org.apache.ibatis.reflection.ReflectorFactory;
11 | import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
12 | import org.apache.ibatis.reflection.factory.ObjectFactory;
13 | import org.apache.ibatis.reflection.wrapper.DefaultObjectWrapperFactory;
14 | import org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory;
15 | import org.springframework.util.StringUtils;
16 |
17 | import java.lang.reflect.Method;
18 | import java.sql.Connection;
19 | import java.util.Properties;
20 |
21 | /**
22 | * mybatis分表拦截器 -- 水平切分
23 | */
24 | @Intercepts({
25 | @Signature(
26 | type = StatementHandler.class,
27 | method = "prepare",
28 | args = {Connection.class, Integer.class}
29 | )
30 | })
31 | public class TableShardInterceptor implements Interceptor {
32 |
33 | private static final ObjectFactory DEFAULT_OBJECT_FACTORY = new DefaultObjectFactory();
34 | private static final ObjectWrapperFactory DEFAULT_OBJECT_WRAPPER_FACTORY = new DefaultObjectWrapperFactory();
35 | private static final ReflectorFactory REFLECTOR_FACTORY = new DefaultReflectorFactory();
36 |
37 | @Override
38 | public Object intercept(Invocation invocation) throws Throwable {
39 | if (invocation.getTarget() instanceof RoutingStatementHandler) {
40 | try {
41 | RoutingStatementHandler statementHandler = (RoutingStatementHandler) invocation.getTarget();
42 | // MetaObject是mybatis里面提供的一个工具类,类似反射的效果
43 | MetaObject metaStatementHandler = MetaObject.forObject(statementHandler, DEFAULT_OBJECT_FACTORY, DEFAULT_OBJECT_WRAPPER_FACTORY, REFLECTOR_FACTORY);
44 | BoundSql boundSql = (BoundSql) metaStatementHandler.getValue("delegate.boundSql");//获取sql语句
45 | String originSql = boundSql.getSql();
46 | if (!StringUtils.isEmpty(originSql)) {
47 | MappedStatement mappedStatement = (MappedStatement) metaStatementHandler.getValue("delegate.mappedStatement");
48 | // 判断方法上是否添加了 TableShardAnnotation 注解,因为只有添加了TableShard注解的方法我们才会去做分表处理
49 | TableShardAnnotation tableShardAnnotation = getTableShardAnnotation(mappedStatement);
50 | if (tableShardAnnotation != null) {
51 | String tableName = tableShardAnnotation.tableName();
52 | Class> strategyClazz = tableShardAnnotation.shadeStrategy();
53 | String[] shardParamKey = tableShardAnnotation.shardParamKey();
54 | ITableShardStrategy tableStrategy = (ITableShardStrategy) strategyClazz.newInstance();
55 | String newSql = tableStrategy.tableShard(metaStatementHandler, tableName, shardParamKey);
56 | // 把新语句设置回去
57 | metaStatementHandler.setValue("delegate.boundSql.sql", newSql);
58 | }
59 |
60 | }
61 | } catch (Exception e) {
62 | // ignore 任何一个地方有异常都去执行原始操作 -- invocation.proceed()
63 | }
64 |
65 | }
66 | return invocation.proceed();
67 | }
68 |
69 | @Override
70 | public Object plugin(Object target) {
71 | // 当目标类是StatementHandler类型时,才包装目标类,否者直接返回目标本身,减少目标被代理的次数
72 | return (target instanceof RoutingStatementHandler) ? Plugin.wrap(target, this) : target;
73 | }
74 |
75 | @Override
76 | public void setProperties(Properties properties) {
77 |
78 | }
79 |
80 | /**
81 | * 获取方法上的TableShardAnnotation注解
82 | *
83 | * @param mappedStatement MappedStatement
84 | * @return TableShardAnnotation注解
85 | */
86 | private TableShardAnnotation getTableShardAnnotation(MappedStatement mappedStatement) {
87 | TableShardAnnotation tableShardAnnotation = null;
88 | try {
89 | String id = mappedStatement.getId();
90 | String className = id.substring(0, id.lastIndexOf("."));
91 | String methodName = id.substring(id.lastIndexOf(".") + 1);
92 | final Method[] method = Class.forName(className).getMethods();
93 | for (Method me : method) {
94 | if (me.getName().equals(methodName) && me.isAnnotationPresent(TableShardAnnotation.class)) {
95 | tableShardAnnotation = me.getAnnotation(TableShardAnnotation.class);
96 | break;
97 | }
98 | }
99 | } catch (Exception ex) {
100 | ex.printStackTrace();
101 | }
102 | return tableShardAnnotation;
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/java/com/tuacy/mybatis/interceptor/interceptor/tableshard/YearTableShardStrategy.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.mybatis.interceptor.interceptor.tableshard;
2 |
3 | import org.apache.ibatis.mapping.BoundSql;
4 | import org.apache.ibatis.reflection.MetaObject;
5 |
6 | import java.text.SimpleDateFormat;
7 | import java.util.Date;
8 |
9 | /**
10 | * 按年分表,根据当前时间
11 | */
12 | public class YearTableShardStrategy implements ITableShardStrategy {
13 |
14 | @Override
15 | public String tableShard(MetaObject metaStatementHandler, String tableName, String[] shardParamKey) {
16 |
17 | BoundSql boundSql = (BoundSql) metaStatementHandler.getValue("delegate.boundSql");
18 | String originSql = boundSql.getSql();
19 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
20 | String newTableName = tableName + "_" + sdf.format(new Date());
21 | return originSql.replaceAll(tableName, newTableName);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/java/com/tuacy/mybatis/interceptor/interceptor/utils/ReflectHelper.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.mybatis.interceptor.interceptor.utils;
2 |
3 | import java.lang.reflect.Field;
4 |
5 | /**
6 | * 反射工具
7 | */
8 | public class ReflectHelper {
9 |
10 | /**
11 | * 获取obj对象fieldName的Field
12 | *
13 | * @param obj 对象
14 | * @param fieldName 字段名称
15 | * @return 字段
16 | */
17 | private static Field getFieldByFieldName(Object obj, String fieldName) {
18 | if (obj == null || fieldName == null) {
19 | return null;
20 | }
21 | // 遍历父类
22 | for (Class> superClass = obj.getClass(); superClass != Object.class; superClass = superClass.getSuperclass()) {
23 | try {
24 | // 获得某个类的所有声明的字段,即包括public、private和protected,但是不包括父类的申明字段
25 | return superClass.getDeclaredField(fieldName);
26 | } catch (Exception e) {
27 | // 当前对象没有该字段,继续去父类里面查找
28 | }
29 | }
30 | return null;
31 | }
32 |
33 | /**
34 | * 获取obj对象fieldName的属性值
35 | *
36 | * @param obj 对象
37 | * @param fieldName 字段名称
38 | * @return obj对象fieldName的属性值
39 | */
40 | public static Object getValueByFieldName(Object obj, String fieldName) {
41 | Object value = null;
42 | try {
43 | Field field = getFieldByFieldName(obj, fieldName);
44 | if (field != null) {
45 | // 获取字段对应的值
46 | if (field.isAccessible()) {
47 | value = field.get(obj);
48 | } else {
49 | field.setAccessible(true);
50 | value = field.get(obj);
51 | field.setAccessible(false);
52 | }
53 | }
54 | } catch (Exception e) {
55 | return null;
56 | }
57 | return value;
58 | }
59 |
60 | /**
61 | * 设置obj对象fieldName的属性值
62 | *
63 | * @param obj 对象
64 | * @param fieldName 属性名称
65 | * @param value 属性值
66 | */
67 | public static boolean setValueByFieldName(Object obj, String fieldName, Object value) {
68 | try {
69 | //java.lang.Class.getDeclaredField()方法用法实例教程 - 方法返回一个Field对象,它反映此Class对象所表示的类或接口的指定已声明字段。
70 | //此方法返回这个类中的指定字段的Field对象
71 | Field field = obj.getClass().getDeclaredField(fieldName);
72 | /**
73 | * public void setAccessible(boolean flag)
74 | * throws SecurityException将此对象的 accessible 标志设置为指示的布尔值。值为 true 则指示反射的对象在使用时应该取消 Java 语言访问检查。值为 false 则指示反射的对象应该实施 Java 语言访问检查。
75 | * 首先,如果存在安全管理器,则在 ReflectPermission("suppressAccessChecks") 权限下调用 checkPermission 方法。
76 | * 如果 flag 为 true,并且不能更改此对象的可访问性(例如,如果此元素对象是 Class 类的 Constructor 对象),则会引发 SecurityException。
77 | * 如果此对象是 java.lang.Class 类的 Constructor 对象,并且 flag 为 true,则会引发 SecurityException。
78 | * 参数:
79 | * flag - accessible 标志的新值
80 | * 抛出:
81 | * SecurityException - 如果请求被拒绝。
82 | */
83 | if (field.isAccessible()) {//获取此对象的 accessible 标志的值。
84 | field.set(obj, value);//将指定对象变量上此 Field 对象表示的字段设置为指定的新值
85 | } else {
86 | field.setAccessible(true);
87 | field.set(obj, value);
88 | field.setAccessible(false);
89 | }
90 | return true;
91 | } catch (Exception e) {
92 | e.printStackTrace();
93 | }
94 | return false;
95 | }
96 |
97 | /**
98 | * 去obj对象里面找某种类型对应的值
99 | * 比如去obj对象里面查找 String类型对应的值
100 | *
101 | * @param obj 对象
102 | * @param fieldType 属性列席
103 | * @return 属性对应值
104 | */
105 | @SuppressWarnings("unchecked")
106 | public static T getValueByFieldType(Object obj, Class fieldType) {
107 | Object value = null;
108 | for (Class> superClass = obj.getClass(); superClass != Object.class; superClass = superClass.getSuperclass()) {
109 | try {
110 | Field[] fields = superClass.getDeclaredFields();
111 | for (Field f : fields) {
112 | // 遍历每个属性,判断属性类型是否对应
113 | if (f.getType() == fieldType) {
114 | if (f.isAccessible()) {
115 | value = f.get(obj);
116 | break;
117 | } else {
118 | f.setAccessible(true);
119 | value = f.get(obj);
120 | f.setAccessible(false);
121 | break;
122 | }
123 | }
124 | }
125 | if (value != null) {
126 | // 找到
127 | break;
128 | }
129 | } catch (Exception e) {
130 | // 当前对象没有该字段,继续去父类里面查找
131 | }
132 | }
133 | return (T) value;
134 | }
135 |
136 | }
137 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/java/com/tuacy/mybatis/interceptor/mapper/AlarmManageMapper.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.mybatis.interceptor.mapper;
2 |
3 | import com.tuacy.mybatis.interceptor.entity.param.AlarmInfoInsetParam;
4 | import com.tuacy.mybatis.interceptor.interceptor.tableshard.TableShardAnnotation;
5 | import com.tuacy.mybatis.interceptor.strategy.AlarmTableShardStrategy;
6 | import org.apache.ibatis.annotations.Param;
7 | import org.springframework.stereotype.Repository;
8 |
9 | /**
10 | * 告警管理mapper
11 | */
12 | @Repository
13 | public interface AlarmManageMapper {
14 |
15 | @TableShardAnnotation(tableName = "tablealarmevent", shadeStrategy = AlarmTableShardStrategy.class, shardParamKey = "occurTime")
16 | long insertAlarm(@Param("param") AlarmInfoInsetParam param, @Param("occurTime") String occurTIme);
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/java/com/tuacy/mybatis/interceptor/mapper/UserManageMapper.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.mybatis.interceptor.mapper;
2 |
3 | import com.tuacy.mybatis.interceptor.entity.vo.UserInfoVo;
4 | import com.tuacy.mybatis.interceptor.interceptor.encryptresultfield.EncryptResultFieldAnnotation;
5 | import com.tuacy.mybatis.interceptor.interceptor.page.PageView;
6 | import com.tuacy.mybatis.interceptor.strategy.PasswordEncryptStrategy;
7 | import org.apache.ibatis.annotations.Param;
8 | import org.springframework.stereotype.Repository;
9 |
10 | import java.util.List;
11 |
12 | /**
13 | * 用户管理mapper
14 | */
15 | @Repository
16 | public interface UserManageMapper {
17 |
18 | @EncryptResultFieldAnnotation(fieldKey = "password", encryptStrategy = PasswordEncryptStrategy.class)
19 | List getAllUserList();
20 |
21 | List getAllUserListPage(@Param("pageView") PageView pageView);
22 |
23 | List getAllUserListPageManualCount(@Param("pageView") PageView pageView);
24 |
25 | /**
26 | * 和getAllUserListPageManualCount查询对应,自定义一个count查询语句
27 | */
28 | Long getAllUserListPageManualCount_COUNT(@Param("pageView") PageView pageView);
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/java/com/tuacy/mybatis/interceptor/mapper/UserMapper.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.mybatis.interceptor.mapper;
2 |
3 | import com.tuacy.mybatis.interceptor.model.User;
4 |
5 | public interface UserMapper {
6 | /**
7 | * This method was generated by MyBatis Generator.
8 | * This method corresponds to the database table user
9 | *
10 | * @mbggenerated
11 | */
12 | int deleteByPrimaryKey(Short pkid);
13 |
14 | /**
15 | * This method was generated by MyBatis Generator.
16 | * This method corresponds to the database table user
17 | *
18 | * @mbggenerated
19 | */
20 | int insert(User record);
21 |
22 | /**
23 | * This method was generated by MyBatis Generator.
24 | * This method corresponds to the database table user
25 | *
26 | * @mbggenerated
27 | */
28 | int insertSelective(User record);
29 |
30 | /**
31 | * This method was generated by MyBatis Generator.
32 | * This method corresponds to the database table user
33 | *
34 | * @mbggenerated
35 | */
36 | User selectByPrimaryKey(Short pkid);
37 |
38 | /**
39 | * This method was generated by MyBatis Generator.
40 | * This method corresponds to the database table user
41 | *
42 | * @mbggenerated
43 | */
44 | int updateByPrimaryKeySelective(User record);
45 |
46 | /**
47 | * This method was generated by MyBatis Generator.
48 | * This method corresponds to the database table user
49 | *
50 | * @mbggenerated
51 | */
52 | int updateByPrimaryKey(User record);
53 | }
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/java/com/tuacy/mybatis/interceptor/model/User.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.mybatis.interceptor.model;
2 |
3 | import java.io.Serializable;
4 |
5 | public class User implements Serializable {
6 | /**
7 | * This field was generated by MyBatis Generator.
8 | * This field corresponds to the database column user.pkid
9 | *
10 | * @mbggenerated
11 | */
12 | private Short pkid;
13 |
14 | /**
15 | * This field was generated by MyBatis Generator.
16 | * This field corresponds to the database column user.name
17 | *
18 | * @mbggenerated
19 | */
20 | private String name;
21 |
22 | /**
23 | * This field was generated by MyBatis Generator.
24 | * This field corresponds to the database column user.phone
25 | *
26 | * @mbggenerated
27 | */
28 | private String phone;
29 |
30 | /**
31 | * This field was generated by MyBatis Generator.
32 | * This field corresponds to the database column user.password
33 | *
34 | * @mbggenerated
35 | */
36 | private String password;
37 |
38 | /**
39 | * This field was generated by MyBatis Generator.
40 | * This field corresponds to the database table user
41 | *
42 | * @mbggenerated
43 | */
44 | private static final long serialVersionUID = 1L;
45 |
46 | /**
47 | * This method was generated by MyBatis Generator.
48 | * This method returns the value of the database column user.pkid
49 | *
50 | * @return the value of user.pkid
51 | *
52 | * @mbggenerated
53 | */
54 | public Short getPkid() {
55 | return pkid;
56 | }
57 |
58 | /**
59 | * This method was generated by MyBatis Generator.
60 | * This method sets the value of the database column user.pkid
61 | *
62 | * @param pkid the value for user.pkid
63 | *
64 | * @mbggenerated
65 | */
66 | public void setPkid(Short pkid) {
67 | this.pkid = pkid;
68 | }
69 |
70 | /**
71 | * This method was generated by MyBatis Generator.
72 | * This method returns the value of the database column user.name
73 | *
74 | * @return the value of user.name
75 | *
76 | * @mbggenerated
77 | */
78 | public String getName() {
79 | return name;
80 | }
81 |
82 | /**
83 | * This method was generated by MyBatis Generator.
84 | * This method sets the value of the database column user.name
85 | *
86 | * @param name the value for user.name
87 | *
88 | * @mbggenerated
89 | */
90 | public void setName(String name) {
91 | this.name = name == null ? null : name.trim();
92 | }
93 |
94 | /**
95 | * This method was generated by MyBatis Generator.
96 | * This method returns the value of the database column user.phone
97 | *
98 | * @return the value of user.phone
99 | *
100 | * @mbggenerated
101 | */
102 | public String getPhone() {
103 | return phone;
104 | }
105 |
106 | /**
107 | * This method was generated by MyBatis Generator.
108 | * This method sets the value of the database column user.phone
109 | *
110 | * @param phone the value for user.phone
111 | *
112 | * @mbggenerated
113 | */
114 | public void setPhone(String phone) {
115 | this.phone = phone == null ? null : phone.trim();
116 | }
117 |
118 | /**
119 | * This method was generated by MyBatis Generator.
120 | * This method returns the value of the database column user.password
121 | *
122 | * @return the value of user.password
123 | *
124 | * @mbggenerated
125 | */
126 | public String getPassword() {
127 | return password;
128 | }
129 |
130 | /**
131 | * This method was generated by MyBatis Generator.
132 | * This method sets the value of the database column user.password
133 | *
134 | * @param password the value for user.password
135 | *
136 | * @mbggenerated
137 | */
138 | public void setPassword(String password) {
139 | this.password = password == null ? null : password.trim();
140 | }
141 |
142 | /**
143 | * This method was generated by MyBatis Generator.
144 | * This method corresponds to the database table user
145 | *
146 | * @mbggenerated
147 | */
148 | @Override
149 | public boolean equals(Object that) {
150 | if (this == that) {
151 | return true;
152 | }
153 | if (that == null) {
154 | return false;
155 | }
156 | if (getClass() != that.getClass()) {
157 | return false;
158 | }
159 | User other = (User) that;
160 | return (this.getPkid() == null ? other.getPkid() == null : this.getPkid().equals(other.getPkid()))
161 | && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
162 | && (this.getPhone() == null ? other.getPhone() == null : this.getPhone().equals(other.getPhone()))
163 | && (this.getPassword() == null ? other.getPassword() == null : this.getPassword().equals(other.getPassword()));
164 | }
165 |
166 | /**
167 | * This method was generated by MyBatis Generator.
168 | * This method corresponds to the database table user
169 | *
170 | * @mbggenerated
171 | */
172 | @Override
173 | public int hashCode() {
174 | final int prime = 31;
175 | int result = 1;
176 | result = prime * result + ((getPkid() == null) ? 0 : getPkid().hashCode());
177 | result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
178 | result = prime * result + ((getPhone() == null) ? 0 : getPhone().hashCode());
179 | result = prime * result + ((getPassword() == null) ? 0 : getPassword().hashCode());
180 | return result;
181 | }
182 |
183 | /**
184 | * This method was generated by MyBatis Generator.
185 | * This method corresponds to the database table user
186 | *
187 | * @mbggenerated
188 | */
189 | @Override
190 | public String toString() {
191 | StringBuilder sb = new StringBuilder();
192 | sb.append(getClass().getSimpleName());
193 | sb.append(" [");
194 | sb.append("Hash = ").append(hashCode());
195 | sb.append(", pkid=").append(pkid);
196 | sb.append(", name=").append(name);
197 | sb.append(", phone=").append(phone);
198 | sb.append(", password=").append(password);
199 | sb.append(", serialVersionUID=").append(serialVersionUID);
200 | sb.append("]");
201 | return sb.toString();
202 | }
203 | }
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/java/com/tuacy/mybatis/interceptor/service/IAlarmManageService.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.mybatis.interceptor.service;
2 |
3 | import com.tuacy.mybatis.interceptor.entity.param.AlarmInfoInsetParam;
4 |
5 | public interface IAlarmManageService {
6 |
7 | /**
8 | * 插入一条告警
9 | * @param param 告警信息
10 | */
11 | void insertAlarm(AlarmInfoInsetParam param);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/java/com/tuacy/mybatis/interceptor/service/IUserManageService.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.mybatis.interceptor.service;
2 |
3 | import com.tuacy.mybatis.interceptor.entity.vo.UserInfoVo;
4 | import com.tuacy.mybatis.interceptor.interceptor.page.PageView;
5 |
6 | import java.util.List;
7 |
8 | public interface IUserManageService {
9 |
10 | /**
11 | * 获取所有的用户列表信息
12 | */
13 | List getAllUserList();
14 |
15 |
16 | /**
17 | * 分页获取所有的用户列表信息
18 | */
19 | PageView getUserListPage(PageView pageView);
20 |
21 |
22 | /**
23 | * 分页获取所有的用户列表信息 -- 自定义count查询
24 | */
25 | PageView getUserListPageManualCount(PageView pageView);
26 | }
27 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/java/com/tuacy/mybatis/interceptor/service/impl/AlarmManageServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.mybatis.interceptor.service.impl;
2 |
3 | import com.tuacy.mybatis.interceptor.entity.param.AlarmInfoInsetParam;
4 | import com.tuacy.mybatis.interceptor.mapper.AlarmManageMapper;
5 | import com.tuacy.mybatis.interceptor.service.IAlarmManageService;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Service;
8 | import org.springframework.transaction.annotation.Transactional;
9 |
10 | @Service(value = "alarm-manage")
11 | public class AlarmManageServiceImpl implements IAlarmManageService {
12 |
13 | private AlarmManageMapper alarmManageMapper;
14 |
15 | @Autowired
16 | public void setAlarmManageMapper(AlarmManageMapper alarmManageMapper) {
17 | this.alarmManageMapper = alarmManageMapper;
18 | }
19 |
20 | /**
21 | * 插入一条告警
22 | * @param param 告警信息
23 | */
24 | @Transactional(rollbackFor = Exception.class)
25 | @Override
26 | public void insertAlarm(AlarmInfoInsetParam param) {
27 | alarmManageMapper.insertAlarm(param, param.getAlarmOccurTime());
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/java/com/tuacy/mybatis/interceptor/service/impl/UserManageServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.mybatis.interceptor.service.impl;
2 |
3 | import com.tuacy.mybatis.interceptor.entity.vo.UserInfoVo;
4 | import com.tuacy.mybatis.interceptor.interceptor.page.PageView;
5 | import com.tuacy.mybatis.interceptor.mapper.UserManageMapper;
6 | import com.tuacy.mybatis.interceptor.service.IUserManageService;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Service;
9 | import org.springframework.transaction.annotation.Transactional;
10 |
11 | import java.util.List;
12 |
13 | @Service(value = "user-manage")
14 | public class UserManageServiceImpl implements IUserManageService {
15 |
16 | private UserManageMapper userManageMapper;
17 |
18 | @Autowired
19 | public void setUserManageMapper(UserManageMapper userManageMapper) {
20 | this.userManageMapper = userManageMapper;
21 | }
22 |
23 | @Transactional(rollbackFor = Exception.class, readOnly = true)
24 | @Override
25 | public List getAllUserList() {
26 | return userManageMapper.getAllUserList();
27 | }
28 |
29 | /**
30 | * 分页获取所有的用户列表信息
31 | */
32 | @Transactional(rollbackFor = Exception.class, readOnly = true)
33 | @Override
34 | public PageView getUserListPage(PageView pageView) {
35 | pageView.setLists(userManageMapper.getAllUserListPage(pageView));
36 | return pageView;
37 | }
38 |
39 |
40 | /**
41 | * 分页获取所有的用户列表信息 -- 自定义count查询
42 | */
43 | @Transactional(rollbackFor = Exception.class, readOnly = true)
44 | @Override
45 | public PageView getUserListPageManualCount(PageView pageView) {
46 | pageView.setLists(userManageMapper.getAllUserListPageManualCount(pageView));
47 | return pageView;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/java/com/tuacy/mybatis/interceptor/strategy/AlarmTableShardStrategy.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.mybatis.interceptor.strategy;
2 |
3 | import com.tuacy.mybatis.interceptor.interceptor.tableshard.ITableShardStrategy;
4 | import org.apache.ibatis.mapping.BoundSql;
5 | import org.apache.ibatis.reflection.DefaultReflectorFactory;
6 | import org.apache.ibatis.reflection.MetaObject;
7 | import org.apache.ibatis.reflection.ReflectorFactory;
8 | import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
9 | import org.apache.ibatis.reflection.factory.ObjectFactory;
10 | import org.apache.ibatis.reflection.wrapper.DefaultObjectWrapperFactory;
11 | import org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory;
12 |
13 | import java.text.SimpleDateFormat;
14 | import java.util.Date;
15 | import java.util.Map;
16 | import java.util.Set;
17 |
18 | /**
19 | * 告警表分表策略 -- 根据告警发生时间来分表,天
20 | * shardParamKey 对应时间格式 yyyy-MM-dd HH:mm:ss
21 | */
22 | public class AlarmTableShardStrategy implements ITableShardStrategy {
23 |
24 | private static final ObjectFactory DEFAULT_OBJECT_FACTORY = new DefaultObjectFactory();
25 | private static final ObjectWrapperFactory DEFAULT_OBJECT_WRAPPER_FACTORY = new DefaultObjectWrapperFactory();
26 | private static final ReflectorFactory REFLECTOR_FACTORY = new DefaultReflectorFactory();
27 |
28 | /**
29 | * 分表策略
30 | *
31 | * @param metaStatementHandler MetaObject包装的RoutingStatementHandler对象
32 | * @param tableName 原始表名
33 | * @param shardParamKey 可以在mapper文件的方法里面传递一些参数key过来,在分表策略里面通过key获取到对应的值
34 | * @return 包装之后的sql语句
35 | */
36 | @SuppressWarnings("unchecked")
37 | @Override
38 | public String tableShard(MetaObject metaStatementHandler, String tableName, String[] shardParamKey) throws Exception {
39 | BoundSql boundSql = (BoundSql) metaStatementHandler.getValue("delegate.boundSql");
40 | String originSql = boundSql.getSql();
41 | if (shardParamKey == null || shardParamKey.length == 0) {
42 | return originSql;
43 | }
44 | String alarmOccurTimeParamKey = shardParamKey[0];
45 | String alarmOccurTime = null;
46 | Object parameterObject = metaStatementHandler.getValue("delegate.boundSql.parameterObject");//获取参数
47 | if (parameterObject instanceof String) {
48 | // 参数是一个String,那我们就认为这个String就是用来分表的参数了
49 | alarmOccurTime = (String) parameterObject;
50 | } else if (parameterObject instanceof Map) {
51 | // 参数是一个Map
52 | Map map = (Map) parameterObject;
53 | Set set = map.keySet();
54 | for (String key : set) {
55 | if (key.equals(alarmOccurTimeParamKey)) {
56 | alarmOccurTime = map.get(alarmOccurTimeParamKey).toString();
57 | break;
58 | }
59 | }
60 | } else {
61 | // 参数为某个对象
62 | MetaObject metaParamObject = MetaObject.forObject(parameterObject, DEFAULT_OBJECT_FACTORY, DEFAULT_OBJECT_WRAPPER_FACTORY, REFLECTOR_FACTORY);
63 | alarmOccurTime = (String) metaParamObject.getValue(alarmOccurTimeParamKey);
64 | }
65 | // 确定表名字
66 | if (alarmOccurTime != null) {
67 | SimpleDateFormat parseSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
68 | Date occurDate = parseSdf.parse(alarmOccurTime);
69 | SimpleDateFormat formatSdf = new SimpleDateFormat("yyyyMMdd");
70 | String shardTableName = tableName + "_" + formatSdf.format(occurDate);
71 | return originSql.replaceAll(tableName, shardTableName);
72 | }
73 | return originSql;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/java/com/tuacy/mybatis/interceptor/strategy/PasswordEncryptStrategy.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.mybatis.interceptor.strategy;
2 |
3 | import com.tuacy.mybatis.interceptor.interceptor.encryptresultfield.IEncryptResultFieldStrategy;
4 | import org.springframework.util.DigestUtils;
5 |
6 | public class PasswordEncryptStrategy implements IEncryptResultFieldStrategy {
7 | @Override
8 | public String encrypt(String source) {
9 | if (source == null) {
10 | return null;
11 | }
12 | return new String(DigestUtils.md5Digest(source.getBytes()));
13 | }
14 |
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 2223
3 | spring:
4 | application:
5 | name: mybatis-interceptor
6 | datasource:
7 | url: jdbc:mysql://localhost:3306/tuacydev?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false
8 | username: root
9 | password: 123456
10 | driver-class-name: com.mysql.jdbc.Driver
11 | # 使用druid数据源
12 | type: com.alibaba.druid.pool.DruidDataSource
13 | #eureka:
14 | # client:
15 | # serviceUrl:
16 | # defaultZone: http://localhost:8761/eureka/
17 | #
18 | # instance:
19 | # instance-id: ${spring.application.name}:${spring.application.instance_id:${random.value}}
20 | # prefer-ip-address: true
21 | # leaseRenewalIntervalInSeconds: 5
22 | # leaseExpirationDurationInSeconds: 5
23 |
24 | mybatis:
25 | typeAliasesPackage: com.tuacy.mybatis.interceptor.model
26 | mapperLocations: classpath:mapper/*.xml
27 | # configuration:
28 | # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
29 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/resources/generator/generatorConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
21 |
22 |
23 |
25 |
26 |
27 |
28 |
30 |
31 |
32 |
33 |
34 |
36 |
37 |
38 |
39 |
43 |
44 |
45 |
46 |
47 |
48 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/resources/mapper/AlarmManageMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | insert into tablealarmevent (
9 | alarmeventid,
10 | alarmeventname,
11 | alarmlevel,
12 | alarmoccurtime
13 | ) values (
14 | uuid_short(),
15 | #{param.alarmEventName},
16 | #{param.alarmLevel},
17 | #{param.alarmOccurTime}
18 | )
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/resources/mapper/UserManageMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
15 |
16 |
26 |
27 |
37 |
38 |
39 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/mybatis-interceptor/src/main/resources/mapper/UserMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
19 | pkid, name, phone, password
20 |
21 |
31 |
32 |
36 | delete from user
37 | where pkid = #{pkid,jdbcType=SMALLINT}
38 |
39 |
40 |
44 | insert into user (pkid, name, phone,
45 | password)
46 | values (#{pkid,jdbcType=SMALLINT}, #{name,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR},
47 | #{password,jdbcType=VARCHAR})
48 |
49 |
50 |
54 | insert into user
55 |
56 |
57 | pkid,
58 |
59 |
60 | name,
61 |
62 |
63 | phone,
64 |
65 |
66 | password,
67 |
68 |
69 |
70 |
71 | #{pkid,jdbcType=SMALLINT},
72 |
73 |
74 | #{name,jdbcType=VARCHAR},
75 |
76 |
77 | #{phone,jdbcType=VARCHAR},
78 |
79 |
80 | #{password,jdbcType=VARCHAR},
81 |
82 |
83 |
84 |
85 |
89 | update user
90 |
91 |
92 | name = #{name,jdbcType=VARCHAR},
93 |
94 |
95 | phone = #{phone,jdbcType=VARCHAR},
96 |
97 |
98 | password = #{password,jdbcType=VARCHAR},
99 |
100 |
101 | where pkid = #{pkid,jdbcType=SMALLINT}
102 |
103 |
104 |
108 | update user
109 | set name = #{name,jdbcType=VARCHAR},
110 | phone = #{phone,jdbcType=VARCHAR},
111 | password = #{password,jdbcType=VARCHAR}
112 | where pkid = #{pkid,jdbcType=SMALLINT}
113 |
114 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | tuacy.microservice.framweork
8 | microservice-framework
9 | pom
10 | PACKT-SNAPSHOT
11 |
12 | user-manage
13 | framework-common
14 | user-manage-api
15 | quartz-manage
16 | quartz-manage-api
17 | actuator
18 | url-decoration
19 | mybatis-interceptor
20 |
21 |
22 | microservice-framwork
23 | microservice framework project for Spring Boot
24 |
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-parent
30 | 2.0.3.RELEASE
31 |
32 |
33 |
34 | UTF-8
35 | UTF-8
36 | 1.8
37 | Finchley.RELEASE
38 |
39 |
40 |
41 |
42 |
43 |
44 | org.springframework.cloud
45 | spring-cloud-dependencies
46 | ${spring-cloud.version}
47 | pom
48 | import
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | org.springframework.boot
58 | spring-boot-starter
59 |
60 |
61 |
62 | org.springframework.boot
63 | spring-boot-starter-test
64 | test
65 |
66 |
67 |
68 | org.springframework.boot
69 | spring-boot-starter-web
70 |
71 |
72 |
73 | org.springframework.cloud
74 | spring-cloud-starter-netflix-hystrix
75 |
76 |
77 |
78 | org.springframework.cloud
79 | spring-cloud-starter-netflix-eureka-client
80 |
81 |
82 |
83 | org.springframework.cloud
84 | spring-cloud-starter-openfeign
85 |
86 |
87 |
88 | org.springframework.cloud
89 | spring-cloud-config-client
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 | src/main/java
99 |
100 | **/*.xml
101 | **/*.properties
102 |
103 | false
104 |
105 |
106 | src/main/resources
107 |
108 | **/*.yml
109 | **/*.xml
110 | **/*.properties
111 |
112 | false
113 |
114 |
115 |
116 |
117 |
118 | org.springframework.boot
119 | spring-boot-maven-plugin
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 | alimaven
129 | http://maven.aliyun.com/nexus/content/repositories/central/
130 |
131 | true
132 |
133 |
134 | true
135 |
136 |
137 |
138 |
139 |
140 | spring-libs-release
141 | http://repo.spring.io/libs-release-local
142 |
143 |
144 |
145 |
146 |
147 |
148 | spring-libs-release
149 | http://repo.spring.io/libs-release-local
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
--------------------------------------------------------------------------------
/quartz-manage-api/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | microservice-framework
7 | tuacy.microservice.framweork
8 | PACKT-SNAPSHOT
9 |
10 | jar
11 | 4.0.0
12 |
13 | quartz-manage-api
14 |
15 |
16 |
17 | tuacy.microservice.framweork
18 | framework-common
19 | ${parent.version}
20 |
21 |
22 |
23 |
24 |
25 |
26 | org.springframework.boot
27 | spring-boot-maven-plugin
28 |
29 |
30 | none
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/quartz-manage-api/src/main/java/com/tuacy/microservice/framework/quartz/manage/api/IQuartzManageApi.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.microservice.framework.quartz.manage.api;
2 |
3 | import com.tuacy.microservice.framework.common.entity.response.ResponseDataEntity;
4 | import com.tuacy.microservice.framework.quartz.manage.param.QuartzJobAddParam;
5 | import com.tuacy.microservice.framework.quartz.manage.param.QuartzJobDeleteParam;
6 | import org.springframework.web.bind.annotation.RequestBody;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.RequestMethod;
9 |
10 | @RequestMapping("/quartz/")
11 | public interface IQuartzManageApi {
12 |
13 |
14 | /**
15 | * 添加一个job任务
16 | */
17 | @RequestMapping(value = "add", method = RequestMethod.POST)
18 | ResponseDataEntity addQuartzJob(@RequestBody QuartzJobAddParam param);
19 |
20 | /**
21 | * 添加一个job任务
22 | */
23 | @RequestMapping(value = "delete", method = RequestMethod.POST)
24 | ResponseDataEntity deleteQuartzJob(@RequestBody QuartzJobDeleteParam param);
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/quartz-manage-api/src/main/java/com/tuacy/microservice/framework/quartz/manage/param/QuartzJobAddParam.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.microservice.framework.quartz.manage.param;
2 |
3 | public class QuartzJobAddParam {
4 | private String keyId;
5 |
6 | public String getKeyId() {
7 | return keyId;
8 | }
9 |
10 | public void setKeyId(String keyId) {
11 | this.keyId = keyId;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/quartz-manage-api/src/main/java/com/tuacy/microservice/framework/quartz/manage/param/QuartzJobDeleteParam.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.microservice.framework.quartz.manage.param;
2 |
3 | public class QuartzJobDeleteParam {
4 | private String keyId;
5 |
6 | public String getKeyId() {
7 | return keyId;
8 | }
9 |
10 | public void setKeyId(String keyId) {
11 | this.keyId = keyId;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/quartz-manage/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | microservice-framework
7 | tuacy.microservice.framweork
8 | PACKT-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | quartz-manage
13 |
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-hateoas
19 |
20 |
21 |
22 | org.springframework.boot
23 | spring-boot-starter-actuator
24 |
25 |
26 |
27 |
28 | org.springframework.cloud
29 | spring-cloud-starter-sleuth
30 |
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-jdbc
36 |
37 |
38 |
39 |
40 | org.springframework.boot
41 | spring-boot-starter-quartz
42 |
43 |
44 |
45 |
46 | mysql
47 | mysql-connector-java
48 | 5.1.39
49 |
50 |
51 |
52 |
53 | com.alibaba
54 | druid
55 | 1.0.18
56 |
57 |
58 |
59 |
60 | org.mybatis.spring.boot
61 | mybatis-spring-boot-starter
62 | 1.3.2
63 |
64 |
65 |
66 |
67 | com.github.pagehelper
68 | pagehelper-spring-boot-starter
69 |
70 | 1.2.3
71 |
72 |
73 |
74 | tuacy.microservice.framweork
75 | framework-common
76 | ${parent.version}
77 |
78 |
79 |
80 | tuacy.microservice.framweork
81 | quartz-manage-api
82 | ${parent.version}
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 | org.springframework.boot
92 | spring-boot-maven-plugin
93 |
94 |
95 | none
96 |
97 |
98 |
99 |
100 |
101 | org.mybatis.generator
102 | mybatis-generator-maven-plugin
103 | 1.3.2
104 |
105 |
106 | mysql
107 | mysql-connector-java
108 | 5.1.35
109 |
110 |
111 |
112 | ${basedir}/src/main/resources/generator/generatorConfig.xml
113 | true
114 | true
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
--------------------------------------------------------------------------------
/quartz-manage/src/main/java/com/tuacy/microservice/framework/quartz/manage/FrameworkQuartzManageApplication.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.microservice.framework.quartz.manage;
2 |
3 | import org.mybatis.spring.annotation.MapperScan;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
7 | import org.springframework.cloud.netflix.hystrix.EnableHystrix;
8 | import org.springframework.cloud.openfeign.EnableFeignClients;
9 | import org.springframework.transaction.annotation.EnableTransactionManagement;
10 |
11 | @SpringBootApplication
12 | @EnableDiscoveryClient
13 | @EnableTransactionManagement
14 | @MapperScan(basePackages = "com.tuacy.microservice.framework.quartz.manage.mapper")
15 | @EnableFeignClients
16 | @EnableHystrix
17 | public class FrameworkQuartzManageApplication {
18 |
19 | public static void main(String[] args) {
20 | SpringApplication.run(FrameworkQuartzManageApplication.class, args);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/quartz-manage/src/main/java/com/tuacy/microservice/framework/quartz/manage/controller/IQuartzManageController.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.microservice.framework.quartz.manage.controller;
2 |
3 | import com.tuacy.microservice.framework.common.controller.BaseController;
4 | import com.tuacy.microservice.framework.common.entity.response.ResponseDataEntity;
5 | import com.tuacy.microservice.framework.quartz.manage.api.IQuartzManageApi;
6 | import com.tuacy.microservice.framework.quartz.manage.exception.QuartzException;
7 | import com.tuacy.microservice.framework.quartz.manage.job.SendEmailJob;
8 | import com.tuacy.microservice.framework.quartz.manage.param.QuartzJobAddParam;
9 | import com.tuacy.microservice.framework.quartz.manage.param.QuartzJobDeleteParam;
10 | import com.tuacy.microservice.framework.quartz.manage.service.IQuartzActionService;
11 | import org.springframework.beans.factory.annotation.Autowired;
12 | import org.springframework.web.bind.annotation.RequestBody;
13 | import org.springframework.web.bind.annotation.RestController;
14 |
15 | @RestController
16 | public class IQuartzManageController extends BaseController implements IQuartzManageApi {
17 |
18 | private static final String GROUP = "email_group";
19 |
20 | private IQuartzActionService quartzActionService;
21 |
22 | @Autowired
23 | public void setQuartzActionService(IQuartzActionService quartzActionService) {
24 | this.quartzActionService = quartzActionService;
25 | }
26 |
27 | /**
28 | * 添加一个job任务
29 | */
30 | @Override
31 | public ResponseDataEntity addQuartzJob(@RequestBody QuartzJobAddParam param) {
32 | ResponseDataEntity responseDataEntity = new ResponseDataEntity<>();
33 | if (param.getKeyId() != null && !param.getKeyId().isEmpty()) {
34 | // 模拟每隔5s执行一次
35 | try {
36 | quartzActionService.addJob(SendEmailJob.class, param.getKeyId(), GROUP, "0/5 * * * * ? ");
37 | } catch (QuartzException e) {
38 | e.printStackTrace();
39 | }
40 | }
41 | return responseDataEntity;
42 | }
43 |
44 | /**
45 | * 添加一个job任务
46 | */
47 | @Override
48 | public ResponseDataEntity deleteQuartzJob(@RequestBody QuartzJobDeleteParam param) {
49 | ResponseDataEntity responseDataEntity = new ResponseDataEntity<>();
50 | if (param.getKeyId() != null && !param.getKeyId().isEmpty()) {
51 | // 模拟每隔5s执行一次
52 | try {
53 | quartzActionService.deleteJob(param.getKeyId(), GROUP);
54 | } catch (QuartzException e) {
55 | e.printStackTrace();
56 | }
57 | }
58 | return responseDataEntity;
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/quartz-manage/src/main/java/com/tuacy/microservice/framework/quartz/manage/exception/QuartzException.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.microservice.framework.quartz.manage.exception;
2 |
3 | public class QuartzException extends Exception {
4 |
5 | public QuartzException() {
6 | }
7 |
8 | public QuartzException(String message) {
9 | super(message);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/quartz-manage/src/main/java/com/tuacy/microservice/framework/quartz/manage/job/SendEmailJob.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.microservice.framework.quartz.manage.job;
2 |
3 | import com.tuacy.microservice.framework.quartz.manage.service.impl.QuartzActionServiceImpl;
4 | import org.quartz.JobDataMap;
5 | import org.quartz.JobExecutionContext;
6 | import org.springframework.scheduling.quartz.QuartzJobBean;
7 |
8 | /**
9 | * 定时发送邮件任务 -- 只是一个模拟任务,大家根据实际情况编写
10 | */
11 | public class SendEmailJob extends QuartzJobBean {
12 | @Override
13 | protected void executeInternal(JobExecutionContext jobExecutionContext) {
14 |
15 | JobDataMap jobDataMap = jobExecutionContext.getMergedJobDataMap();
16 | if (jobDataMap != null && !jobDataMap.isEmpty()) {
17 | System.out.println("******************************");
18 | System.out.println("******************************");
19 | System.out.println("******************************");
20 | System.out.println("job name = " + jobDataMap.get(QuartzActionServiceImpl.TASK_ID_KEY));
21 | System.out.println("开始发送邮件了");
22 | }
23 |
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/quartz-manage/src/main/java/com/tuacy/microservice/framework/quartz/manage/mapper/UserMapper.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.microservice.framework.quartz.manage.mapper;
2 |
3 | import com.tuacy.microservice.framework.quartz.manage.model.User;
4 |
5 | public interface UserMapper {
6 | /**
7 | * This method was generated by MyBatis Generator.
8 | * This method corresponds to the database table user
9 | *
10 | * @mbggenerated
11 | */
12 | int deleteByPrimaryKey(Short pkid);
13 |
14 | /**
15 | * This method was generated by MyBatis Generator.
16 | * This method corresponds to the database table user
17 | *
18 | * @mbggenerated
19 | */
20 | int insert(User record);
21 |
22 | /**
23 | * This method was generated by MyBatis Generator.
24 | * This method corresponds to the database table user
25 | *
26 | * @mbggenerated
27 | */
28 | int insertSelective(User record);
29 |
30 | /**
31 | * This method was generated by MyBatis Generator.
32 | * This method corresponds to the database table user
33 | *
34 | * @mbggenerated
35 | */
36 | User selectByPrimaryKey(Short pkid);
37 |
38 | /**
39 | * This method was generated by MyBatis Generator.
40 | * This method corresponds to the database table user
41 | *
42 | * @mbggenerated
43 | */
44 | int updateByPrimaryKeySelective(User record);
45 |
46 | /**
47 | * This method was generated by MyBatis Generator.
48 | * This method corresponds to the database table user
49 | *
50 | * @mbggenerated
51 | */
52 | int updateByPrimaryKey(User record);
53 | }
--------------------------------------------------------------------------------
/quartz-manage/src/main/java/com/tuacy/microservice/framework/quartz/manage/model/User.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.microservice.framework.quartz.manage.model;
2 |
3 | import java.io.Serializable;
4 |
5 | public class User implements Serializable {
6 | /**
7 | * This field was generated by MyBatis Generator.
8 | * This field corresponds to the database column user.pkid
9 | *
10 | * @mbggenerated
11 | */
12 | private Short pkid;
13 |
14 | /**
15 | * This field was generated by MyBatis Generator.
16 | * This field corresponds to the database column user.name
17 | *
18 | * @mbggenerated
19 | */
20 | private String name;
21 |
22 | /**
23 | * This field was generated by MyBatis Generator.
24 | * This field corresponds to the database column user.phone
25 | *
26 | * @mbggenerated
27 | */
28 | private String phone;
29 |
30 | /**
31 | * This field was generated by MyBatis Generator.
32 | * This field corresponds to the database column user.password
33 | *
34 | * @mbggenerated
35 | */
36 | private String password;
37 |
38 | /**
39 | * This field was generated by MyBatis Generator.
40 | * This field corresponds to the database table user
41 | *
42 | * @mbggenerated
43 | */
44 | private static final long serialVersionUID = 1L;
45 |
46 | /**
47 | * This method was generated by MyBatis Generator.
48 | * This method returns the value of the database column user.pkid
49 | *
50 | * @return the value of user.pkid
51 | *
52 | * @mbggenerated
53 | */
54 | public Short getPkid() {
55 | return pkid;
56 | }
57 |
58 | /**
59 | * This method was generated by MyBatis Generator.
60 | * This method sets the value of the database column user.pkid
61 | *
62 | * @param pkid the value for user.pkid
63 | *
64 | * @mbggenerated
65 | */
66 | public void setPkid(Short pkid) {
67 | this.pkid = pkid;
68 | }
69 |
70 | /**
71 | * This method was generated by MyBatis Generator.
72 | * This method returns the value of the database column user.name
73 | *
74 | * @return the value of user.name
75 | *
76 | * @mbggenerated
77 | */
78 | public String getName() {
79 | return name;
80 | }
81 |
82 | /**
83 | * This method was generated by MyBatis Generator.
84 | * This method sets the value of the database column user.name
85 | *
86 | * @param name the value for user.name
87 | *
88 | * @mbggenerated
89 | */
90 | public void setName(String name) {
91 | this.name = name == null ? null : name.trim();
92 | }
93 |
94 | /**
95 | * This method was generated by MyBatis Generator.
96 | * This method returns the value of the database column user.phone
97 | *
98 | * @return the value of user.phone
99 | *
100 | * @mbggenerated
101 | */
102 | public String getPhone() {
103 | return phone;
104 | }
105 |
106 | /**
107 | * This method was generated by MyBatis Generator.
108 | * This method sets the value of the database column user.phone
109 | *
110 | * @param phone the value for user.phone
111 | *
112 | * @mbggenerated
113 | */
114 | public void setPhone(String phone) {
115 | this.phone = phone == null ? null : phone.trim();
116 | }
117 |
118 | /**
119 | * This method was generated by MyBatis Generator.
120 | * This method returns the value of the database column user.password
121 | *
122 | * @return the value of user.password
123 | *
124 | * @mbggenerated
125 | */
126 | public String getPassword() {
127 | return password;
128 | }
129 |
130 | /**
131 | * This method was generated by MyBatis Generator.
132 | * This method sets the value of the database column user.password
133 | *
134 | * @param password the value for user.password
135 | *
136 | * @mbggenerated
137 | */
138 | public void setPassword(String password) {
139 | this.password = password == null ? null : password.trim();
140 | }
141 |
142 | /**
143 | * This method was generated by MyBatis Generator.
144 | * This method corresponds to the database table user
145 | *
146 | * @mbggenerated
147 | */
148 | @Override
149 | public boolean equals(Object that) {
150 | if (this == that) {
151 | return true;
152 | }
153 | if (that == null) {
154 | return false;
155 | }
156 | if (getClass() != that.getClass()) {
157 | return false;
158 | }
159 | User other = (User) that;
160 | return (this.getPkid() == null ? other.getPkid() == null : this.getPkid().equals(other.getPkid()))
161 | && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
162 | && (this.getPhone() == null ? other.getPhone() == null : this.getPhone().equals(other.getPhone()))
163 | && (this.getPassword() == null ? other.getPassword() == null : this.getPassword().equals(other.getPassword()));
164 | }
165 |
166 | /**
167 | * This method was generated by MyBatis Generator.
168 | * This method corresponds to the database table user
169 | *
170 | * @mbggenerated
171 | */
172 | @Override
173 | public int hashCode() {
174 | final int prime = 31;
175 | int result = 1;
176 | result = prime * result + ((getPkid() == null) ? 0 : getPkid().hashCode());
177 | result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
178 | result = prime * result + ((getPhone() == null) ? 0 : getPhone().hashCode());
179 | result = prime * result + ((getPassword() == null) ? 0 : getPassword().hashCode());
180 | return result;
181 | }
182 |
183 | /**
184 | * This method was generated by MyBatis Generator.
185 | * This method corresponds to the database table user
186 | *
187 | * @mbggenerated
188 | */
189 | @Override
190 | public String toString() {
191 | StringBuilder sb = new StringBuilder();
192 | sb.append(getClass().getSimpleName());
193 | sb.append(" [");
194 | sb.append("Hash = ").append(hashCode());
195 | sb.append(", pkid=").append(pkid);
196 | sb.append(", name=").append(name);
197 | sb.append(", phone=").append(phone);
198 | sb.append(", password=").append(password);
199 | sb.append(", serialVersionUID=").append(serialVersionUID);
200 | sb.append("]");
201 | return sb.toString();
202 | }
203 | }
--------------------------------------------------------------------------------
/quartz-manage/src/main/java/com/tuacy/microservice/framework/quartz/manage/service/IQuartzActionService.java:
--------------------------------------------------------------------------------
1 | package com.tuacy.microservice.framework.quartz.manage.service;
2 |
3 | import com.tuacy.microservice.framework.quartz.manage.exception.QuartzException;
4 | import org.springframework.scheduling.quartz.QuartzJobBean;
5 |
6 | import java.util.List;
7 | import java.util.Map;
8 |
9 | public interface IQuartzActionService {
10 |
11 | /**
12 | * 增加一个job
13 | *
14 | * @param jobClass 任务实现类
15 | * @param jobName 任务名称
16 | * @param jobGroupName 任务组名
17 | * @param jobTime 这是每隔多少秒为一次任务
18 | * @param jobTimes 运行的次数 (<0:表示不限次数)
19 | */
20 | void addJob(Class extends QuartzJobBean> jobClass,
21 | String jobName,
22 | String jobGroupName,
23 | int jobTime,
24 | int jobTimes) throws QuartzException;
25 |
26 | /**
27 | * 增加一个job
28 | *
29 | * @param jobClass 任务实现类
30 | * @param jobName 任务名称
31 | * @param jobGroupName 任务组名
32 | * @param jobTime 这是每隔多少秒为一次任务
33 | * @param jobTimes 运行的次数 (<0:表示不限次数)
34 | * @param start 添加任务之后直接设置pause,resume状态
35 | */
36 | void addJob(Class extends QuartzJobBean> jobClass,
37 | String jobName,
38 | String jobGroupName,
39 | int jobTime,
40 | int jobTimes,
41 | boolean start) throws QuartzException;
42 |
43 | /**
44 | * 增加一个job
45 | *
46 | * @param jobClass 任务实现类
47 | * @param jobName 任务名称
48 | * @param jobGroupName 任务组名
49 | * @param jobTime 时间表达式 (如:0/5 * * * * ? )
50 | */
51 | void addJob(Class extends QuartzJobBean> jobClass,
52 | String jobName,
53 | String jobGroupName,
54 | String jobTime) throws QuartzException;
55 |
56 | /**
57 | * 增加一个job
58 | *
59 | * @param jobClass 任务实现类
60 | * @param jobName 任务名称
61 | * @param jobGroupName 任务组名
62 | * @param jobTime 时间表达式 (如:0/5 * * * * ? )
63 | * @param start 是否启用 true: 添加任务之后,job run,false: 添加任务之后,job pause
64 | */
65 | void addJob(Class extends QuartzJobBean> jobClass,
66 | String jobName,
67 | String jobGroupName,
68 | String jobTime,
69 | boolean start) throws QuartzException;
70 |
71 | /**
72 | * 修改 一个job的 时间表达式
73 | *
74 | * @param jobName 任务名称
75 | * @param jobGroupName 任务组
76 | * @param jobTime 任务时间表达式
77 | */
78 | void updateJob(String jobName, String jobGroupName, String jobTime) throws QuartzException;
79 |
80 | /**
81 | * 修改 一个job的 时间表达式
82 | *
83 | * @param jobName 任务名称
84 | * @param jobGroupName 任务组
85 | * @param jobTime 任务时间表达式
86 | * @param start 修改任务之后直接设置pause,resume状态
87 | */
88 | void updateJob(String jobName,
89 | String jobGroupName,
90 | String jobTime,
91 | boolean start) throws QuartzException;
92 |
93 | /**
94 | * 删除任务一个job
95 | *
96 | * @param jobName 任务名称
97 | * @param jobGroupName 任务组名
98 | */
99 | void deleteJob(String jobName, String jobGroupName) throws QuartzException;
100 |
101 | /**
102 | * 暂停一个job
103 | *
104 | * @param jobName 任务名称
105 | * @param jobGroupName 任务组名
106 | */
107 | void pauseJob(String jobName, String jobGroupName) throws QuartzException;
108 |
109 | /**
110 | * 恢复一个job
111 | *
112 | * @param jobName 任务名称
113 | * @param jobGroupName 任务组名
114 | */
115 | void resumeJob(String jobName, String jobGroupName) throws QuartzException;
116 |
117 | /**
118 | * 立即执行一个job
119 | *
120 | * @param jobName 任务名称
121 | * @param jobGroupName 任务组名
122 | */
123 | void runAJobNow(String jobName, String jobGroupName) throws QuartzException;
124 |
125 | /**
126 | * 获取所有计划中的任务列表
127 | *
128 | * @return map 列表
129 | */
130 | List