iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/enums/CommonConstant.java
@@ -8,554 +8,11 @@ */ public interface CommonConstant { String CJS_SYS = "system"; String HTTP_CLIENT_ID_XST = "xsteam"; String HTTP_CLIENT_ID_SD = "sd"; String HTTP_CLIENT_ID_OADP = "oadp"; String HTTP_CLIENT_ID_FXJY = "fxjy"; String HTTP_CLIENT_ID_ELELOW = "elelow"; String HTTP_RESULT_TRUE = "true"; //常量点 String CONSTANT = "CONSTANT"; //计量点 String MEASURE = "MEASURE"; //计算点 String CALCULATE = "CALCULATE"; int IS_ENABLE = 1; BigDecimal BAD_VALUE = new BigDecimal("-2"); BigDecimal ZERO_VALUE = new BigDecimal("0"); //年生产计划执行数据 String YEAR_PEI_HTTP_TAG = "yearPeiHttpTag"; //当前产量 String CURRENT_PERFORMANCE_HTTP_TAG = "currentPerformanceHttpTag"; //生产时间分布 String PRD_TIME_DIST_HTTP_TAG = "prdTimeDistHttpTag"; //当前销量 String CURRENT_SALE_HTTP_TAG = "currentSaleHttpTag"; String HTTP_API_ZXZK_IH = "ZXZK_IH"; String HTTP_API_SD_RUN_STATE = "SDRunState"; String HTTP_API_SD_HEALTH_STATE = "SDHealthState"; String HTTP_API_SD_DEVICE_LIST = "SDDeviceList"; String HTTP_API_SD_DEVICE_TEMPERATURE = "SDDeviceTemperature"; String HTTP_API_ZX_DEVICE_ELECTRIC = "ZXDeviceElectric"; String HTTP_API_PERSON_LIST = "PersonList"; String HTTP_API_JOB_LIST = "JobList"; //年 String YEAR = "year"; //月 String MONTH = "month"; //下划线 String UNDERLINE = "_"; //$符 String DOLLAR = "$"; /** * 启用 */ public static final int IS_ENABLE = 1; /** * 删除标志 */ public static final Integer BPM_FLAG_1 = 1; /** * 正常状态 */ public static final Integer STATUS_NORMAL = 0; /** * 禁用状态 */ public static final Integer STATUS_DISABLE = -1; /** * 删除标志 */ public static final Integer DEL_FLAG_1 = 1; /** * 未删除 */ public static final Integer DEL_FLAG_0 = 0; /** * 未提交 */ public static final Integer SUBMINT_STATUS_0 = 0; /** * 系统日志类型: 登录 */ public static final int LOG_TYPE_1 = 1; /** * 系统日志类型: 操作 */ public static final int LOG_TYPE_2 = 2; /** * 操作日志类型: 查询 */ public static final int OPERATE_TYPE_1 = 1; /** * 操作日志类型: 添加 */ public static final int OPERATE_TYPE_2 = 2; /** * 操作日志类型: 更新 */ public static final int OPERATE_TYPE_3 = 3; /** * 操作日志类型: 删除 */ public static final int OPERATE_TYPE_4 = 4; /** * 操作日志类型: 倒入 */ public static final int OPERATE_TYPE_5 = 5; /** * 操作日志类型: 导出 */ public static final int OPERATE_TYPE_6 = 6; /** * 提交 */ public static final int SUBMIT_FLAG_1 = 1; /** * 通过 */ public static final int SUBMIT_FLAG_2 = 2; /** * 驳回 */ public static final int SUBMIT_FLAG_3 = 3; /** * 提交 */ public static final int SUBMIT_FLAG_0 = 0; public static final int SUBMIT_FLAG_4 = 4; public static final int SUBMIT_FLAG_5 = 5; public static final int SUBMIT_FLAG_6 = 6; public static final Integer DANGER_STATUS = 1; public static final Integer DANGER_STATUS_2 = 2; /** * {@code 500 Server Error} (HTTP/1.0 - RFC 1945) */ public static final Integer SC_INTERNAL_SERVER_ERROR_500 = 500; /** * {@code 200 OK} (HTTP/1.0 - RFC 1945) */ public static final Integer SC_OK_200 = 200; /** * 访问权限认证未通过 510 */ public static final Integer SC_JEECG_NO_AUTHZ = 510; /** * 登录用户Shiro权限缓存KEY前缀 */ public static String PREFIX_USER_SHIRO_CACHE = "shiro:cache:org.jeecg.config.shiro.ShiroRealm.authorizationCache:"; /** * 登录用户Token令牌缓存KEY前缀 */ public static final String PREFIX_USER_TOKEN = "prefix_user_token_"; // /** Token缓存时间:3600秒即一小时 */ // public static final int TOKEN_EXPIRE_TIME = 3600; /** * 登录二维码 */ public static final String LOGIN_QRCODE_PRE = "QRCODELOGIN:"; public static final String LOGIN_QRCODE = "LQ:"; /** * 登录二维码token */ public static final String LOGIN_QRCODE_TOKEN = "LQT:"; /** * 0:一级菜单 */ public static final Integer MENU_TYPE_0 = 0; /** * 1:子菜单 */ public static final Integer MENU_TYPE_1 = 1; /** * 2:按钮权限 */ public static final Integer MENU_TYPE_2 = 2; /** * 通告对象类型(USER:指定用户,ALL:全体用户) */ public static final String MSG_TYPE_UESR = "USER"; public static final String MSG_TYPE_ALL = "ALL"; /** * 发布状态(0未发布,1已发布,2已撤销) */ public static final String NO_SEND = "0"; public static final String HAS_SEND = "1"; public static final String HAS_CANCLE = "2"; /** * 阅读状态(0未读,1已读) */ public static final String HAS_READ_FLAG = "1"; public static final String NO_READ_FLAG = "0"; /** * 优先级(L低,M中,H高) */ public static final String PRIORITY_L = "L"; public static final String PRIORITY_M = "M"; public static final String PRIORITY_H = "H"; /** * 短信模板方式 0 .登录模板、1.注册模板、2.忘记密码模板 */ public static final String SMS_TPL_TYPE_0 = "0"; public static final String SMS_TPL_TYPE_1 = "1"; public static final String SMS_TPL_TYPE_2 = "2"; /** * 状态(0无效1有效) */ public static final String STATUS_0 = "0"; public static final String STATUS_1 = "1"; /** * 状态(0无效1有效) */ public static final Integer INT_STATUS_0 = 0; public static final Integer INT_STATUS_1 = 1; /** * 同步工作流引擎1同步0不同步 */ public static final Integer ACT_SYNC_1 = 1; public static final Integer ACT_SYNC_0 = 0; /** * 消息类型1:通知公告2:系统消息 */ public static final String MSG_CATEGORY_1 = "1"; public static final String MSG_CATEGORY_2 = "2"; /** * 是否配置菜单的数据权限 1是0否 */ public static final Integer RULE_FLAG_0 = 0; public static final Integer RULE_FLAG_1 = 1; /** * 是否用户已被冻结 1正常(解冻) 2冻结 */ public static final Integer USER_UNFREEZE = 1; public static final Integer USER_FREEZE = 2; /** * 字典翻译文本后缀 */ public static final String DICT_TEXT_SUFFIX = "_dictText"; /** * 表单设计器主表类型 */ public static final Integer DESIGN_FORM_TYPE_MAIN = 1; /** * 表单设计器子表表类型 */ public static final Integer DESIGN_FORM_TYPE_SUB = 2; /** * 表单设计器URL授权通过 */ public static final Integer DESIGN_FORM_URL_STATUS_PASSED = 1; /** * 表单设计器URL授权未通过 */ public static final Integer DESIGN_FORM_URL_STATUS_NOT_PASSED = 2; /** * 表单设计器新增 Flag */ public static final String DESIGN_FORM_URL_TYPE_ADD = "add"; /** * 表单设计器修改 Flag */ public static final String DESIGN_FORM_URL_TYPE_EDIT = "edit"; /** * 表单设计器详情 Flag */ public static final String DESIGN_FORM_URL_TYPE_DETAIL = "detail"; /** * 表单设计器复用数据 Flag */ public static final String DESIGN_FORM_URL_TYPE_REUSE = "reuse"; /** * 表单设计器编辑 Flag (已弃用) */ public static final String DESIGN_FORM_URL_TYPE_VIEW = "view"; /** * online参数值设置(是:Y, 否:N) */ public static final String ONLINE_PARAM_VAL_IS_TURE = "Y"; public static final String ONLINE_PARAM_VAL_IS_FALSE = "N"; /** * 文件上传类型(本地:local,Minio:minio,阿里云:alioss) */ public static final String UPLOAD_TYPE_LOCAL = "local"; public static final String UPLOAD_TYPE_MINIO = "minio"; public static final String UPLOAD_TYPE_OSS = "alioss"; /** * 文档上传自定义桶名称 */ public static final String UPLOAD_CUSTOM_BUCKET = "eoafile"; /** * 文档上传自定义路径 */ public static final String UPLOAD_CUSTOM_PATH = "eoafile"; /** * 文件外链接有效天数 */ public static final Integer UPLOAD_EFFECTIVE_DAYS = 1; /** * 员工身份 (1:普通员工 2:上级) */ public static final Integer USER_IDENTITY_1 = 1; public static final Integer USER_IDENTITY_2 = 2; /** * sys_user 表 username 唯一键索引 */ public static final String SQL_INDEX_UNIQ_SYS_USER_USERNAME = "uniq_sys_user_username"; /** * sys_user 表 work_no 唯一键索引 */ public static final String SQL_INDEX_UNIQ_SYS_USER_WORK_NO = "uniq_sys_user_work_no"; /** * sys_user 表 phone 唯一键索引 */ public static final String SQL_INDEX_UNIQ_SYS_USER_PHONE = "uniq_sys_user_phone"; /** * 达梦数据库升提示。违反表[SYS_USER]唯一性约束 */ public static final String SQL_INDEX_UNIQ_SYS_USER = "唯一性约束"; /** * sys_user 表 email 唯一键索引 */ public static final String SQL_INDEX_UNIQ_SYS_USER_EMAIL = "uniq_sys_user_email"; /** * sys_quartz_job 表 job_class_name 唯一键索引 */ public static final String SQL_INDEX_UNIQ_JOB_CLASS_NAME = "uniq_job_class_name"; /** * sys_position 表 code 唯一键索引 */ public static final String SQL_INDEX_UNIQ_CODE = "uniq_code"; /** * sys_role 表 code 唯一键索引 */ public static final String SQL_INDEX_UNIQ_SYS_ROLE_CODE = "uniq_sys_role_role_code"; /** * sys_depart 表 code 唯一键索引 */ public static final String SQL_INDEX_UNIQ_DEPART_ORG_CODE = "uniq_depart_org_code"; /** * sys_category 表 code 唯一键索引 */ public static final String SQL_INDEX_UNIQ_CATEGORY_CODE = "idx_sc_code"; /** * 在线聊天 是否为默认分组 */ public static final String IM_DEFAULT_GROUP = "1"; /** * 在线聊天 图片文件保存路径 */ public static final String IM_UPLOAD_CUSTOM_PATH = "imfile"; /** * 在线聊天 用户状态 */ public static final String IM_STATUS_ONLINE = "online"; /** * 在线聊天 SOCKET消息类型 */ public static final String IM_SOCKET_TYPE = "chatMessage"; /** * 在线聊天 是否开启默认添加好友 1是 0否 */ public static final String IM_DEFAULT_ADD_FRIEND = "1"; /** * 在线聊天 用户好友缓存前缀 */ public static final String IM_PREFIX_USER_FRIEND_CACHE = "sys:cache:im:im_prefix_user_friend_"; /** * 考勤补卡业务状态 (1:同意 2:不同意) */ public static final String SIGN_PATCH_BIZ_STATUS_1 = "1"; public static final String SIGN_PATCH_BIZ_STATUS_2 = "2"; /** * 公文文档上传自定义路径 */ public static final String UPLOAD_CUSTOM_PATH_OFFICIAL = "officialdoc"; /** * 公文文档下载自定义路径 */ public static final String DOWNLOAD_CUSTOM_PATH_OFFICIAL = "officaldown"; /** * WPS存储值类别(1 code文号 2 text(WPS模板还是公文发文模板)) */ public static final String WPS_TYPE_1 = "1"; public static final String WPS_TYPE_2 = "2"; public final static String X_ACCESS_TOKEN = "X-Access-Token"; public final static String X_SIGN = "X-Sign"; public final static String X_TIMESTAMP = "X-TIMESTAMP"; public final static String TOKEN_IS_INVALID_MSG = "Token失效,请重新登录!"; /** * 多租户 请求头 */ public final static String TENANT_ID = "tenant-id"; /** * 微服务读取配置文件属性 服务地址 */ public final static String CLOUD_SERVER_KEY = "spring.cloud.nacos.discovery.server-addr"; /** * 第三方登录 验证密码/创建用户 都需要设置一个操作码 防止被恶意调用 */ public final static String THIRD_LOGIN_CODE = "third_login_code"; /** * 第三方APP同步方向:本地 --> 第三方APP */ String THIRD_SYNC_TO_APP = "SYNC_TO_APP"; /** * 第三方APP同步方向:第三方APP --> 本地 */ String THIRD_SYNC_TO_LOCAL = "SYNC_TO_LOCAL"; /** * 系统通告消息状态:0=未发布 */ String ANNOUNCEMENT_SEND_STATUS_0 = "0"; /** * 系统通告消息状态:1=已发布 */ String ANNOUNCEMENT_SEND_STATUS_1 = "1"; /** * 系统通告消息状态:2=已撤销 */ String ANNOUNCEMENT_SEND_STATUS_2 = "2"; /** * ONLINE 报表权限用 从request中获取地址栏后的参数 */ String ONL_REP_URL_PARAM_STR = "onlRepUrlParamStr"; /** * POST请求 */ String HTTP_POST = "POST"; /** * PUT请求 */ String HTTP_PUT = "PUT"; /** * PATCH请求 */ String HTTP_PATCH = "PATCH"; /** * 未知的 */ String UNKNOWN = "unknown"; /** * 字符串http */ String STR_HTTP = "http"; /** * String 类型的空值 */ String STRING_NULL = "null"; /** * java.util.Date 包 */ String JAVA_UTIL_DATE = "java.util.Date"; /** * .do */ String SPOT_DO = ".do"; /** * 前端vue版本标识 */ String VERSION = "X-Version"; /** * 前端vue版本 */ String VERSION_VUE3 = "vue3"; } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/exception/RRExceptionHandler.java
@@ -1,6 +1,6 @@ //package com.iailab.common.exception; //package com.iailab.module.data.common.exception; // //import com.iailab.common.utils.R; //import com.iailab.module.data.common.utils.R; //import org.apache.shiro.authz.AuthorizationException; //import org.slf4j.Logger; //import org.slf4j.LoggerFactory; iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/interceptor/DataFilterInterceptor.java
@@ -1,89 +1,81 @@ ///** // * Copyright (c) 2018 人人开源 All rights reserved. // * // * https://www.renren.io // * // * 版权所有,侵权必究! // */ // //package com.iailab.module.common.interceptor; // //import cn.hutool.core.util.StrUtil; //import com.baomidou.mybatisplus.core.toolkit.PluginUtils; //import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor; //import net.sf.jsqlparser.JSQLParserException; //import net.sf.jsqlparser.expression.Expression; //import net.sf.jsqlparser.expression.StringValue; //import net.sf.jsqlparser.expression.operators.conditional.AndExpression; //import net.sf.jsqlparser.parser.CCJSqlParserUtil; //import net.sf.jsqlparser.statement.select.PlainSelect; //import net.sf.jsqlparser.statement.select.Select; //import org.apache.ibatis.executor.Executor; //import org.apache.ibatis.mapping.BoundSql; //import org.apache.ibatis.mapping.MappedStatement; //import org.apache.ibatis.session.ResultHandler; //import org.apache.ibatis.session.RowBounds; // //import java.util.Map; // ///** // * 数据过滤 // * // * @author Mark sunlightcs@gmail.com // */ //public class DataFilterInterceptor implements InnerInterceptor { // // @Override // public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) { // DataScope scope = getDataScope(parameter); // // 不进行数据过滤 // if(scope == null || StrUtil.isBlank(scope.getSqlFilter())){ // return; // } // // // 拼接新SQL // String buildSql = getSelect(boundSql.getSql(), scope); // // // 重写SQL // PluginUtils.mpBoundSql(boundSql).sql(buildSql); // } // // private DataScope getDataScope(Object parameter){ // if (parameter == null){ // return null; // } // // // 判断参数里是否有DataScope对象 // if (parameter instanceof Map) { // Map<?, ?> parameterMap = (Map<?, ?>) parameter; // for (Map.Entry entry : parameterMap.entrySet()) { // if (entry.getValue() != null && entry.getValue() instanceof DataScope) { // return (DataScope) entry.getValue(); // } // } // } else if (parameter instanceof DataScope) { // return (DataScope) parameter; // } // // return null; // } // // private String getSelect(String buildSql, DataScope scope){ // try { // Select select = (Select) CCJSqlParserUtil.parse(buildSql); // PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); // // Expression expression = plainSelect.getWhere(); // if(expression == null){ // plainSelect.setWhere(new StringValue(scope.getSqlFilter())); // }else{ // AndExpression andExpression = new AndExpression(expression, new StringValue(scope.getSqlFilter())); // plainSelect.setWhere(andExpression); // } // // return select.toString().replaceAll("'", ""); // }catch (JSQLParserException e){ // return buildSql; // } // } //} package com.iailab.module.data.common.interceptor; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.toolkit.PluginUtils; import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor; import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.StringValue; import net.sf.jsqlparser.expression.operators.conditional.AndExpression; import net.sf.jsqlparser.parser.CCJSqlParserUtil; import net.sf.jsqlparser.statement.select.PlainSelect; import net.sf.jsqlparser.statement.select.Select; import org.apache.ibatis.executor.Executor; import org.apache.ibatis.mapping.BoundSql; import org.apache.ibatis.mapping.MappedStatement; import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.RowBounds; import java.util.Map; /** * 数据过滤 * * @author Mark sunlightcs@gmail.com */ public class DataFilterInterceptor implements InnerInterceptor { @Override public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) { DataScope scope = getDataScope(parameter); // 不进行数据过滤 if(scope == null || StrUtil.isBlank(scope.getSqlFilter())){ return; } // 拼接新SQL String buildSql = getSelect(boundSql.getSql(), scope); // 重写SQL PluginUtils.mpBoundSql(boundSql).sql(buildSql); } private DataScope getDataScope(Object parameter){ if (parameter == null){ return null; } // 判断参数里是否有DataScope对象 if (parameter instanceof Map) { Map<?, ?> parameterMap = (Map<?, ?>) parameter; for (Map.Entry entry : parameterMap.entrySet()) { if (entry.getValue() != null && entry.getValue() instanceof DataScope) { return (DataScope) entry.getValue(); } } } else if (parameter instanceof DataScope) { return (DataScope) parameter; } return null; } private String getSelect(String buildSql, DataScope scope){ try { Select select = (Select) CCJSqlParserUtil.parse(buildSql); PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); Expression expression = plainSelect.getWhere(); if(expression == null){ plainSelect.setWhere(new StringValue(scope.getSqlFilter())); }else{ AndExpression andExpression = new AndExpression(expression, new StringValue(scope.getSqlFilter())); plainSelect.setWhere(andExpression); } return select.toString().replaceAll("'", ""); }catch (JSQLParserException e){ return buildSql; } } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/interceptor/DataScope.java
@@ -1,36 +1,28 @@ ///** // * Copyright (c) 2018 人人开源 All rights reserved. // * // * https://www.renren.io // * // * 版权所有,侵权必究! // */ // //package com.iailab.module.common.interceptor; // ///** // * 数据范围 // * // * @author Mark sunlightcs@gmail.com // * @since 1.0.0 // */ //public class DataScope { // private String sqlFilter; // // public DataScope(String sqlFilter) { // this.sqlFilter = sqlFilter; // } // // public String getSqlFilter() { // return sqlFilter; // } // // public void setSqlFilter(String sqlFilter) { // this.sqlFilter = sqlFilter; // } // // @Override // public String toString() { // return this.sqlFilter; // } //} package com.iailab.module.data.common.interceptor; /** * 数据范围 * * @author Mark sunlightcs@gmail.com * @since 1.0.0 */ public class DataScope { private String sqlFilter; public DataScope(String sqlFilter) { this.sqlFilter = sqlFilter; } public String getSqlFilter() { return sqlFilter; } public void setSqlFilter(String sqlFilter) { this.sqlFilter = sqlFilter; } @Override public String toString() { return this.sqlFilter; } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/DateUtils.java
对比新文件 @@ -0,0 +1,196 @@ /** * Copyright (c) 2018 人人开源 All rights reserved. * * https://www.renren.io * * 版权所有,侵权必究! */ package com.iailab.module.data.common.utils; import org.apache.commons.lang3.StringUtils; import org.joda.time.DateTime; import org.joda.time.LocalDate; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; /** * 日期处理 * * @author Mark sunlightcs@gmail.com */ public class DateUtils { /** 时间格式(yyyy-MM-dd) */ public final static String DATE_PATTERN = "yyyy-MM-dd"; /** 时间格式(yyyy-MM-dd HH:mm:ss) */ public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss"; /** * 日期格式化 日期格式为:yyyy-MM-dd * @param date 日期 * @return 返回yyyy-MM-dd格式日期 */ public static String format(Date date) { return format(date, DATE_PATTERN); } /** * 日期格式化 日期格式为:yyyy-MM-dd * @param date 日期 * @param pattern 格式,如:DateUtils.DATE_TIME_PATTERN * @return 返回yyyy-MM-dd格式日期 */ public static String format(Date date, String pattern) { if(date != null){ SimpleDateFormat df = new SimpleDateFormat(pattern); return df.format(date); } return null; } /** * 日期解析 * @param date 日期 * @param pattern 格式,如:DateUtils.DATE_TIME_PATTERN * @return 返回Date */ public static Date parse(String date, String pattern) { try { return new SimpleDateFormat(pattern).parse(date); } catch (ParseException e) { e.printStackTrace(); } return null; } /** * 字符串转换成日期 * @param strDate 日期字符串 * @param pattern 日期的格式,如:DateUtils.DATE_TIME_PATTERN */ public static Date stringToDate(String strDate, String pattern) { if (StringUtils.isBlank(strDate)){ return null; } DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern); return fmt.parseLocalDateTime(strDate).toDate(); } /** * 根据周数,获取开始日期、结束日期 * @param week 周期 0本周,-1上周,-2上上周,1下周,2下下周 * @return 返回date[0]开始日期、date[1]结束日期 */ public static Date[] getWeekStartAndEnd(int week) { DateTime dateTime = new DateTime(); LocalDate date = new LocalDate(dateTime.plusWeeks(week)); date = date.dayOfWeek().withMinimumValue(); Date beginDate = date.toDate(); Date endDate = date.plusDays(6).toDate(); return new Date[]{beginDate, endDate}; } /** * 对日期的【秒】进行加/减 * * @param date 日期 * @param seconds 秒数,负数为减 * @return 加/减几秒后的日期 */ public static Date addDateSeconds(Date date, int seconds) { DateTime dateTime = new DateTime(date); return dateTime.plusSeconds(seconds).toDate(); } /** * 对日期的【分钟】进行加/减 * * @param date 日期 * @param minutes 分钟数,负数为减 * @return 加/减几分钟后的日期 */ public static Date addDateMinutes(Date date, int minutes) { DateTime dateTime = new DateTime(date); return dateTime.plusMinutes(minutes).toDate(); } /** * 对日期的【小时】进行加/减 * * @param date 日期 * @param hours 小时数,负数为减 * @return 加/减几小时后的日期 */ public static Date addDateHours(Date date, int hours) { DateTime dateTime = new DateTime(date); return dateTime.plusHours(hours).toDate(); } /** * 对日期的【天】进行加/减 * * @param date 日期 * @param days 天数,负数为减 * @return 加/减几天后的日期 */ public static Date addDateDays(Date date, int days) { DateTime dateTime = new DateTime(date); return dateTime.plusDays(days).toDate(); } /** * 对日期的【周】进行加/减 * * @param date 日期 * @param weeks 周数,负数为减 * @return 加/减几周后的日期 */ public static Date addDateWeeks(Date date, int weeks) { DateTime dateTime = new DateTime(date); return dateTime.plusWeeks(weeks).toDate(); } /** * 对日期的【月】进行加/减 * * @param date 日期 * @param months 月数,负数为减 * @return 加/减几月后的日期 */ public static Date addDateMonths(Date date, int months) { DateTime dateTime = new DateTime(date); return dateTime.plusMonths(months).toDate(); } /** * 对日期的【年】进行加/减 * * @param date 日期 * @param years 年数,负数为减 * @return 加/减几年后的日期 */ public static Date addDateYears(Date date, int years) { DateTime dateTime = new DateTime(date); return dateTime.plusYears(years).toDate(); } public static List<String> getTimeScale(Date startDate, Date endDate, int seconds) { List<String> days = new ArrayList<String>(); Calendar calendar = Calendar.getInstance(); calendar.setTime(startDate); while (calendar.getTime().compareTo(endDate) <= 0) { days.add(DateUtils.format(calendar.getTime(), DATE_TIME_PATTERN)); calendar.add(Calendar.SECOND, seconds); } return days; } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/JwtUtils.java
对比新文件 @@ -0,0 +1,104 @@ package com.iailab.module.data.common.utils; import com.auth0.jwt.JWT; import com.auth0.jwt.JWTVerifier; import com.auth0.jwt.algorithms.Algorithm; import com.auth0.jwt.interfaces.DecodedJWT; import java.util.Date; /** * @author PanZhibao * @Description * @createTime 2022年07月20日 11:47:00 */ public class JwtUtils { private static final String USER_INFO_KEY = "username"; /**Token有效期为12小时*/ public static final long EXPIRE_TIME = 60 * 60 * 1000 * 12; /** * 生成Token * @param username 用户标识(唯一) * @param secretKey 签名算法以及密匙 * @return */ public static String generateToken(String username, String secretKey) { Algorithm algorithm = Algorithm.HMAC256(secretKey); Date now = new Date(); Date expireTime = new Date(now.getTime() + EXPIRE_TIME); String token = JWT.create() .withClaim(USER_INFO_KEY, username) .withExpiresAt(expireTime) .sign(algorithm); return token; } /** * 校验token是否正确 * * @param token 密钥 * @param secret 用户的密码 * @return 是否正确 */ public static boolean verify(String token, String username, String secret) { try { // 根据密码生成JWT效验器 Algorithm algorithm = Algorithm.HMAC256(secret); JWTVerifier verifier = JWT.require(algorithm).withClaim("username", username).build(); // 效验TOKEN DecodedJWT jwt = verifier.verify(token); return true; } catch (Exception exception) { return false; } } /** * 校验token是否正确 * * @param token * @param secret * @return */ public static boolean verify(String token, String secret) { try { Algorithm algorithm = Algorithm.HMAC256(secret); JWTVerifier verifier = JWT.require(algorithm).build(); // 效验TOKEN DecodedJWT jwt = verifier.verify(token); return true; } catch (Exception exception) { exception.printStackTrace(); return false; } } /** * 从Token中提取用户信息 * @param token * @return */ public static String getUserInfo(String token) { DecodedJWT decodedJWT = JWT.decode(token); String username = decodedJWT.getClaim(USER_INFO_KEY).asString(); return username; } /** * 从Token中提取信息 * @param token * @param key * @return */ public static String getInfo(String token, String key) { DecodedJWT decodedJWT = JWT.decode(token); String username = decodedJWT.getClaim(USER_INFO_KEY).asString(); return username; } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/MessageUtils.java
对比新文件 @@ -0,0 +1,34 @@ /** * Copyright (c) 2018 人人开源 All rights reserved. * * https://www.renren.io * * 版权所有,侵权必究! */ package com.iailab.module.data.common.utils; import com.iailab.framework.common.util.spring.SpringContextUtils; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; /** * 国际化 * * @author Mark sunlightcs@gmail.com * @since 1.0.0 */ public class MessageUtils { private static MessageSource messageSource; static { messageSource = (MessageSource) SpringContextUtils.getBean("messageSource"); } public static String getMessage(int code){ return getMessage(code, new String[0]); } public static String getMessage(int code, String... params){ return messageSource.getMessage(code+"", params, LocaleContextHolder.getLocale()); } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/Result.java
对比新文件 @@ -0,0 +1,84 @@ package com.iailab.module.data.common.utils; import com.iailab.framework.common.enums.ErrorCode; import java.io.Serializable; /** * 响应数据 * * @author Mark sunlightcs@gmail.com * @since 1.0.0 */ public class Result<T> implements Serializable { private static final long serialVersionUID = 1L; /** * 编码:0表示成功,其他值表示失败 */ private int code = 0; /** * 消息内容 */ private String msg = "success"; /** * 响应数据 */ private T data; public Result<T> ok(T data) { this.setData(data); return this; } public boolean success(){ return code == 0; } public Result<T> error() { this.code = ErrorCode.INTERNAL_SERVER_ERROR; this.msg = MessageUtils.getMessage(this.code); return this; } public Result<T> error(int code) { this.code = code; this.msg = MessageUtils.getMessage(this.code); return this; } public Result<T> error(int code, String msg) { this.code = code; this.msg = msg; return this; } public Result<T> error(String msg) { this.code = ErrorCode.INTERNAL_SERVER_ERROR; this.msg = msg; return this; } public int getCode() { return code; } public void setCode(int code) { this.code = code; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public T getData() { return data; } public void setData(T data) { this.data = data; } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/package-info.java
对比新文件 @@ -0,0 +1,6 @@ /** * 属于 data 模块的 framework 封装 * * @author iailab */ package com.iailab.module.data.framework; iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/rpc/config/RpcConfiguration.java
对比新文件 @@ -0,0 +1,12 @@ package com.iailab.module.data.framework.rpc.config; import com.iailab.module.infra.api.config.ConfigApi; import com.iailab.module.infra.api.file.FileApi; import com.iailab.module.system.api.user.AdminUserApi; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.Configuration; @Configuration(proxyBeanMethods = false) @EnableFeignClients(clients = {FileApi.class, AdminUserApi.class, ConfigApi.class}) public class RpcConfiguration { } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/rpc/package-info.java
对比新文件 @@ -0,0 +1,4 @@ /** * 占位 */ package com.iailab.module.data.framework.rpc; iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/security/config/SecurityConfiguration.java
对比新文件 @@ -0,0 +1,38 @@ package com.iailab.module.data.framework.security.config; import com.iailab.framework.security.config.AuthorizeRequestsCustomizer; import com.iailab.module.system.enums.ApiConstants; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; /** * System 模块的 Security 配置 */ @Configuration(proxyBeanMethods = false, value = "systemSecurityConfiguration") public class SecurityConfiguration { @Bean("systemAuthorizeRequestsCustomizer") public AuthorizeRequestsCustomizer authorizeRequestsCustomizer() { return new AuthorizeRequestsCustomizer() { @Override public void customize(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) { // TODO iailab:这个每个项目都需要重复配置,得捉摸有没通用的方案 // Swagger 接口文档 registry.antMatchers("/v3/api-docs/**").permitAll() // 元数据 .antMatchers("/swagger-ui.html").permitAll(); // Swagger UI // Druid 监控 registry.antMatchers("/druid/**").anonymous(); // Spring Boot Actuator 的安全配置 registry.antMatchers("/actuator").anonymous() .antMatchers("/actuator/**").anonymous(); // RPC 服务的安全配置 registry.antMatchers(ApiConstants.PREFIX + "/**").permitAll(); } }; } } iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/framework/security/core/package-info.java
对比新文件 @@ -0,0 +1,4 @@ /** * 占位 */ package com.iailab.module.data.framework.security.core; iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/job/task/PointCollectTaskNet10.java
@@ -1,7 +1,6 @@ package com.iailab.module.data.job.task; import com.iailab.module.data.point.collection.PointCollector; import com.xxl.job.core.handler.annotation.XxlJob; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.annotation.Resource; @@ -28,7 +27,7 @@ private PointCollector pointCollector; @Override @XxlJob("pointCollectTaskNet10") // @XxlJob("pointCollectTaskNet10") public void run(String params){ // 0/10 * * * * ? logger.debug("PointCollectTaskNet10定时任务正在执行,参数为:{}", params);