diff --git a/library/skyeye-dev/.DS_Store b/library/skyeye-dev/.DS_Store new file mode 100644 index 0000000..aa55b83 Binary files /dev/null and b/library/skyeye-dev/.DS_Store differ diff --git a/library/skyeye-dev/.idea/compiler.xml b/library/skyeye-dev/.idea/compiler.xml new file mode 100644 index 0000000..2c3cf5a --- /dev/null +++ b/library/skyeye-dev/.idea/compiler.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/library/skyeye-dev/.idea/encodings.xml b/library/skyeye-dev/.idea/encodings.xml new file mode 100644 index 0000000..58ba318 --- /dev/null +++ b/library/skyeye-dev/.idea/encodings.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/library/skyeye-dev/.idea/jarRepositories.xml b/library/skyeye-dev/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/library/skyeye-dev/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/library/skyeye-dev/.idea/misc.xml b/library/skyeye-dev/.idea/misc.xml new file mode 100644 index 0000000..63019e7 --- /dev/null +++ b/library/skyeye-dev/.idea/misc.xml @@ -0,0 +1,15 @@ + + + + + + + + \ No newline at end of file diff --git a/library/skyeye-dev/.idea/workspace.xml b/library/skyeye-dev/.idea/workspace.xml new file mode 100644 index 0000000..e8b58fa --- /dev/null +++ b/library/skyeye-dev/.idea/workspace.xml @@ -0,0 +1,109 @@ + + + + + + + + + + { + "associatedIndex": 8 +} + + + + + + + + + + + + + + + + + + + + + + + 1767609517374 + + + + + + \ No newline at end of file diff --git a/library/skyeye-dev/README.md b/library/skyeye-dev/README.md new file mode 100644 index 0000000..ab162cd --- /dev/null +++ b/library/skyeye-dev/README.md @@ -0,0 +1,20 @@ +# SpaceDT Java开发库 + +## 目录结构 + +```java +dt-dev + |-- dt-dev-common:通用依赖及接口标准封装 + |-- dt-dev-db:数据库集成类库封装 + |-- dt-dev-email:邮件类库封装 + |-- dt-dev-generator:代码生成模块封装 + |-- dt-dev-knife4j:在线API集成封装 + |-- dt-dev-quartz:定时任务集成封装 + |-- dt-dev-redis:Redis集成封装 + |-- dt-dev-tx:分布式事务封装 + |-- dt-dev-util:常用工具类库封装 + |-- dt-dev-websocket:websocket集成封装 + |-- pom.xml:Maven配置文件 + +``` + diff --git a/library/skyeye-dev/pom.xml b/library/skyeye-dev/pom.xml new file mode 100644 index 0000000..d0385eb --- /dev/null +++ b/library/skyeye-dev/pom.xml @@ -0,0 +1,37 @@ + + + + + skyeye + com.zhangy + 1.0.0.RELEASE + + 4.0.0 + + com.zhangy + skyeye-dev + 1.0.0.RELEASE + pom + skyeye library + + + skyeye-common + skyeye-db + skyeye-generator + skyeye-job + skyeye-knife4j + skyeye-quartz + skyeye-redis + skyeye-websocket + skyeye-util + + + + \ No newline at end of file diff --git a/library/skyeye-dev/skyeye-common/.DS_Store b/library/skyeye-dev/skyeye-common/.DS_Store new file mode 100644 index 0000000..6330a99 Binary files /dev/null and b/library/skyeye-dev/skyeye-common/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-common/pom.xml b/library/skyeye-dev/skyeye-common/pom.xml new file mode 100644 index 0000000..826f644 --- /dev/null +++ b/library/skyeye-dev/skyeye-common/pom.xml @@ -0,0 +1,50 @@ + + + + + skyeye-dev + com.zhangy + 1.0.0.RELEASE + + 4.0.0 + + skyeye-common + + + + + + org.projectlombok + lombok + + + + + com.auth0 + java-jwt + + + + + org.springframework.boot + spring-boot-starter + + + + + javax.servlet + javax.servlet-api + + + + + org.springframework + spring-webmvc + provided + + + + + \ No newline at end of file diff --git a/library/skyeye-dev/skyeye-common/src/.DS_Store b/library/skyeye-dev/skyeye-common/src/.DS_Store new file mode 100644 index 0000000..7ebb4f9 Binary files /dev/null and b/library/skyeye-dev/skyeye-common/src/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-common/src/main/.DS_Store b/library/skyeye-dev/skyeye-common/src/main/.DS_Store new file mode 100644 index 0000000..a46babd Binary files /dev/null and b/library/skyeye-dev/skyeye-common/src/main/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-common/src/main/java/.DS_Store b/library/skyeye-dev/skyeye-common/src/main/java/.DS_Store new file mode 100644 index 0000000..508308f Binary files /dev/null and b/library/skyeye-dev/skyeye-common/src/main/java/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-common/src/main/java/com/.DS_Store b/library/skyeye-dev/skyeye-common/src/main/java/com/.DS_Store new file mode 100644 index 0000000..0cbd6fb Binary files /dev/null and b/library/skyeye-dev/skyeye-common/src/main/java/com/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/pojo/CommonConstant.java b/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/pojo/CommonConstant.java new file mode 100644 index 0000000..e328116 --- /dev/null +++ b/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/pojo/CommonConstant.java @@ -0,0 +1,14 @@ +package com.zhangy.skyeye.common.pojo; + +/** + * 通用常量 + */ +public interface CommonConstant { + + /** + * true and false + */ + Integer FALSE = 0; + Integer TRUE = 1; + +} diff --git a/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/pojo/SecurityConstants.java b/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/pojo/SecurityConstants.java new file mode 100644 index 0000000..38d4ca9 --- /dev/null +++ b/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/pojo/SecurityConstants.java @@ -0,0 +1,103 @@ +package com.zhangy.skyeye.common.pojo; + +public interface SecurityConstants { + + + /** + * 用户token header + */ + String AUTHORIZATION = "Authorization"; + + /** + * 呕 + */ + String BEARER = "Bearer "; + + /** + * 用户信息 + */ + String DETAILS_USER = "user_info"; + + /** + * 客户端模式 + */ + String CLIENT_CREDENTIALS = "client_credentials"; + + /** + * 客户端ID + */ + String CLIENT_ID = "clientId"; + + /** + * 手机号登录 + */ + String APP = "mobile"; + + /** + * 协议字段 + */ + String DETAILS_LICENSE = "license"; + + /** + * 角色前缀 + */ + String ROLE = "ROLE_"; + + /** + * {bcrypt} 加密的特征码 + */ + String BCRYPT = "{bcrypt}"; + + /** + * sys_oauth_client_details 表的字段,不包括client_id、client_secret + */ + String CLIENT_FIELDS = "client_id, CONCAT('{noop}',client_secret) as client_secret, resource_ids, scope, " + + "authorized_grant_types, web_server_redirect_uri, authorities, access_token_validity, " + + "refresh_token_validity, additional_information, autoapprove"; + + /** + * JdbcClientDetailsService 查询语句 + */ + String BASE_FIND_STATEMENT = "select " + CLIENT_FIELDS + " from sys_oauth_client_details"; + + /** + * 按条件client_id 查询 + */ + String DEFAULT_SELECT_STATEMENT = BASE_FIND_STATEMENT + " where client_id = ? and del_flag = 0"; + + /** + * 默认的查询语句 + */ + String DEFAULT_FIND_STATEMENT = BASE_FIND_STATEMENT + " order by client_id"; + + + /** + * 删除 + */ + String STATUS_DEL = "1"; + + /** + * 正常 + */ + String STATUS_NORMAL = "0"; + + /** + * 锁定 + */ + String STATUS_LOCK = "9"; + + /*** + * 资源服务器默认bean名称 + */ + String RESOURCE_SERVER_CONFIGURER = "resourceServerConfigurerAdapter"; + + /** + * 内部val + */ + String SECRET_VALUE = "Y"; + + /** + * 标志头 + */ + String SECRET_KEY = "secret"; +} diff --git a/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/pojo/param/IdParam.java b/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/pojo/param/IdParam.java new file mode 100644 index 0000000..fb87142 --- /dev/null +++ b/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/pojo/param/IdParam.java @@ -0,0 +1,18 @@ +package com.zhangy.skyeye.common.pojo.param; + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * Controller接口,ID方法参数封装 + */ +@Data +public class IdParam implements Serializable { + + private static final long serialVersionUID = 1L; + + private T id; + private List ids; +} diff --git a/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/pojo/result/Result.java b/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/pojo/result/Result.java new file mode 100644 index 0000000..d6c65cb --- /dev/null +++ b/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/pojo/result/Result.java @@ -0,0 +1,159 @@ +package com.zhangy.skyeye.common.pojo.result; + +import lombok.Data; + +import java.io.Serializable; + +/** + * 统一接口返回数据格式 + */ +@Data +public class Result implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 返回代码 + */ + private Integer code; + + /** + * 返回处理消息 + */ + private String message; + + /** + * 返回数据对象 data + */ + private T data; + + public Result() { } + + /** + * 成功 + * @return Result对象 + */ + public static Result success() { + Result r = new Result(); + r.setCode(ResultConstant.SUCCESS_200); + r.setMessage("操作成功"); + return r; + } + + /** + * 成功 + * @param message 消息 + * @return Result对象 + */ + public static Result success(String message) { + Result r = new Result(); + r.setCode(ResultConstant.SUCCESS_200); + r.setMessage(message); + return r; + } + + /** + * 成功 + * @param data data数据 + * @return Result对象 + */ + public static Result successData(Object data) { + Result r = new Result(); + r.setCode(ResultConstant.SUCCESS_200); + r.setData(data); + return r; + } + + /** + * 成功 + * @param msg 消息 + * @param data data数据 + * @return Result对象 + */ + public static Result successData(String msg, Object data) { + Result r = new Result(); + r.setCode(ResultConstant.SUCCESS_200); + r.setMessage(msg); + r.setData(data); + return r; + } + + /** + * 失败 + * @return Result对象 + */ + public static Result error() { + return error(ResultConstant.SERVER_ERROR_500, "操作失败,请重试!"); + } + + /** + * 失败 + * @param msg 消息 + * @return Result对象 + */ + public static Result error(String msg) { + return error(ResultConstant.SERVER_ERROR_500, msg); + } + + /** + * 失败 + * @param code 自定义code + * @param msg 消息 + * @return Result对象 + */ + public static Result error(int code, String msg) { + Result r = new Result(); + r.setCode(code); + r.setMessage(msg); + return r; + } + + /** + * 失败 + * @param msg 消息 + * @param data data数据 + * @return Result对象 + */ + public static Result errorData(String msg, Object data) { + Result r = new Result(); + r.setCode(ResultConstant.SERVER_ERROR_500); + r.setMessage(msg); + r.setData(data); + return r; + } + + /** + * 无权限访问返回结果 + * @param msg 消息 + * @return 无权限访问返回结果 + */ + public static Result unAuth(String msg) { + return error(ResultConstant.NO_AUTH_401, msg); + } + +// /** +// * 增加返回数据对象 +// * @param k +// * @param v +// * @return +// */ +// public Result addData(String k, Object v) { +// if(this.data == null){ +// this.data = new HashMap<>(); +// } +// +// ((Map)this.data).put(k, v); +// return this; +// } + + /** + * 返回成功或失败 + * @param flag 成功失败状态值 + * @return Result对象 + */ + public static Result status(boolean flag){ + return flag ? success() : error(); + } + + +} \ No newline at end of file diff --git a/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/pojo/result/ResultConstant.java b/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/pojo/result/ResultConstant.java new file mode 100644 index 0000000..4698848 --- /dev/null +++ b/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/pojo/result/ResultConstant.java @@ -0,0 +1,23 @@ +package com.zhangy.skyeye.common.pojo.result; + +/** + * 返回状态码枚举类 + */ +public interface ResultConstant { + + /** + * 成功 + */ + Integer SUCCESS_200 = 200; + + /** + * 权限不足 + */ + Integer NO_AUTH_401 = 401; + + /** + * 失败 + */ + Integer SERVER_ERROR_500 = 500; + +} diff --git a/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/pojo/tree/TreeNode.java b/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/pojo/tree/TreeNode.java new file mode 100644 index 0000000..85aee61 --- /dev/null +++ b/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/pojo/tree/TreeNode.java @@ -0,0 +1,43 @@ +package com.zhangy.skyeye.common.pojo.tree; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.List; + +/** + * 树状结构节点封装 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TreeNode implements Serializable { + + private static final long serialVersionUID = 1L; + + private T id; + private String label; + private List children; + private Object data; + private Integer order; + private Object type; + + public TreeNode(T id, String label, List children, Object data) { + this.id = id; + this.label = label; + this.children = children; + this.data = data; + this.order = 0; + } + + public TreeNode(T id, String label, List children, Object data, Object type) { + this.id = id; + this.label = label; + this.children = children; + this.data = data; + this.order = 0; + this.type = type; + } +} diff --git a/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/utils/CommonUtil.java b/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/utils/CommonUtil.java new file mode 100644 index 0000000..5a56a16 --- /dev/null +++ b/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/utils/CommonUtil.java @@ -0,0 +1,198 @@ +package com.zhangy.skyeye.common.utils; + +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * 通用工具类 + */ +public class CommonUtil { + + /** + * ids字符串转Long list,逗号分隔 + * @param ids + * @return + */ + public static List toList(String ids){ + if(ids == null || ids.isEmpty()){ + return new ArrayList<>(); + } + + String[] strArr = ids.split(","); + Long[] longArr = new Long[strArr.length]; + for (int i = 0; i < strArr.length; i++) { + Long v = Long.valueOf(strArr[i]); + longArr[i] = v; + } + return Arrays.asList(longArr); + } + + /** + * Long list转ids字符串,逗号分隔 + * @param list + * @return + */ + public static String toStr(List list){ + if(list == null || list.isEmpty()){ + return ""; + } + + Iterator it = list.iterator(); + + //使用StringJoiner方式实现 + StringJoiner sj = new StringJoiner(","); + while (it.hasNext()){ + sj.add(String.valueOf(it.next())); + } + return sj.toString(); + + //使用StringBuilder方式实现 + /*StringBuilder sb = new StringBuilder(); + while (it.hasNext()){ + sb.append(it.next()); + if(it.hasNext()){ + sb.append(","); + } + } + return sb.toString();*/ + } + + /** + * java去除字符串中的空格、回车、换行符、制表符 + * + * @param str + * @return + */ + public static String replaceBlank(String str) { + String dest = ""; + if (str != null) { + Pattern p = Pattern.compile("\\s*|\t|\r|\n"); + Matcher m = p.matcher(str); + dest = m.replaceAll(""); + } + return dest; + + } + + /** + * 将下划线大写方式命名的字符串转换为驼峰式。 + * 如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。
+ * 例如:hello_world->helloWorld + * + * @param name + * 转换前的下划线大写方式命名的字符串 + * @return 转换后的驼峰式命名的字符串 + */ + public static String camelName(String name) { + StringBuilder result = new StringBuilder(); + // 快速检查 + if (name == null || name.isEmpty()) { + // 没必要转换 + return ""; + } else if (!name.contains("_")) { + // 不含下划线,仅将首字母小写 + //update-begin--Author:zhoujf Date:20180503 for:TASK #2500 【代码生成器】代码生成器开发一通用模板生成功能 + //update-begin--Author:zhoujf Date:20180503 for:TASK #2500 【代码生成器】代码生成器开发一通用模板生成功能 + return name.substring(0, 1).toLowerCase() + name.substring(1).toLowerCase(); + //update-end--Author:zhoujf Date:20180503 for:TASK #2500 【代码生成器】代码生成器开发一通用模板生成功能 + } + // 用下划线将原始字符串分割 + String camels[] = name.split("_"); + for (String camel : camels) { + // 跳过原始字符串中开头、结尾的下换线或双重下划线 + if (camel.isEmpty()) { + continue; + } + // 处理真正的驼峰片段 + if (result.length() == 0) { + // 第一个驼峰片段,全部字母都小写 + result.append(camel.toLowerCase()); + } else { + // 其他的驼峰片段,首字母大写 + result.append(camel.substring(0, 1).toUpperCase()); + result.append(camel.substring(1).toLowerCase()); + } + } + return result.toString(); + } + + /** + * 将下划线大写方式命名的字符串转换为驼峰式。 + * 如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。
+ * 例如:hello_world,test_id->helloWorld,testId + * + * @param names + * 转换前的下划线大写方式命名的字符串 + * @return 转换后的驼峰式命名的字符串 + */ + public static String camelNames(String names) { + if(names==null||names.equals("")){ + return null; + } + StringBuffer sf = new StringBuffer(); + String[] fs = names.split(","); + for (String field : fs) { + field = camelName(field); + sf.append(field + ","); + } + String result = sf.toString(); + return result.substring(0, result.length() - 1); + } + + //update-begin--Author:zhoujf Date:20180503 for:TASK #2500 【代码生成器】代码生成器开发一通用模板生成功能 + /** + * 将下划线大写方式命名的字符串转换为驼峰式。(首字母写) + * 如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。
+ * 例如:hello_world->HelloWorld + * + * @param name + * 转换前的下划线大写方式命名的字符串 + * @return 转换后的驼峰式命名的字符串 + */ + public static String camelNameCapFirst(String name) { + StringBuilder result = new StringBuilder(); + // 快速检查 + if (name == null || name.isEmpty()) { + // 没必要转换 + return ""; + } else if (!name.contains("_")) { + // 不含下划线,仅将首字母小写 + return name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase(); + } + // 用下划线将原始字符串分割 + String camels[] = name.split("_"); + for (String camel : camels) { + // 跳过原始字符串中开头、结尾的下换线或双重下划线 + if (camel.isEmpty()) { + continue; + } + // 其他的驼峰片段,首字母大写 + result.append(camel.substring(0, 1).toUpperCase()); + result.append(camel.substring(1).toLowerCase()); + } + return result.toString(); + } + + /** + * 将驼峰命名转化成下划线 + * @param para + * @return + */ + public static String camelToUnderline(String para){ + if(para.length()<3){ + return para.toLowerCase(); + } + StringBuilder sb=new StringBuilder(para); + int temp=0;//定位 + //从第三个字符开始 避免命名不规范 + for(int i=2;i netInterfaces = NetworkInterface.getNetworkInterfaces(); + InetAddress ip = null; + boolean finded = false;// 是否找到外网IP + while (netInterfaces.hasMoreElements() && !finded) { + NetworkInterface ni = netInterfaces.nextElement(); + Enumeration address = ni.getInetAddresses(); + while (address.hasMoreElements()) { + ip = address.nextElement(); + if (!ip.isSiteLocalAddress() && !ip.isLoopbackAddress() && ip.getHostAddress().indexOf(":") == -1) {// 外网IP + netip = ip.getHostAddress(); + finded = true; + break; + } else if (ip.isSiteLocalAddress() && !ip.isLoopbackAddress() && ip.getHostAddress().indexOf(":") == -1) {// 内网IP + localip = ip.getHostAddress(); + } + } + } + + if (netip != null && !"".equals(netip)) { + return netip; + } else { + return localip; + } + } + +} diff --git a/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/utils/JwtUtil.java b/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/utils/JwtUtil.java new file mode 100644 index 0000000..c42c4a0 --- /dev/null +++ b/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/utils/JwtUtil.java @@ -0,0 +1,84 @@ +package com.zhangy.skyeye.common.utils; + +import com.auth0.jwt.JWT; +import com.auth0.jwt.JWTVerifier; +import com.auth0.jwt.algorithms.Algorithm; +import com.auth0.jwt.exceptions.JWTDecodeException; +import com.auth0.jwt.interfaces.DecodedJWT; + +import java.util.Date; + +/** + * JWT工具类 + **/ +public class JwtUtil { + + // Token过期时间30分钟 + public static final long EXPIRE_TIME = 4 * 60 * 60 * 1000; + + // Reuqest Header中token的key + public static final String AUTH_TOKEN_KEY = "X-Access-Token"; + + /** + * 校验token是否正确 + * + * @param token 密钥 + * @param username 用户名 + * @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; + } + } + + /** + * 生成签名,5min后过期 + * + * @param username 用户名 + * @param secret 用户的密码 + * @return 加密的token + */ + public static String sign(String username, String secret) { + Date date = new Date(System.currentTimeMillis() + EXPIRE_TIME); + Algorithm algorithm = Algorithm.HMAC256(secret); + // 附带username信息 + return JWT.create().withClaim("username", username).withExpiresAt(date).sign(algorithm); + + } + + /** + * 根据token获取用户账号 + * + * @param accessToken + * @return username + */ + public static String getUserName(String accessToken) { + try { + DecodedJWT jwt = JWT.decode(accessToken); + return jwt.getClaim("username").asString(); + } catch (JWTDecodeException e) { + return null; + } + } + + /** + * 判断token是否已过期 + * + * @param accessToken + * @return true-过期,false-没过期 + */ + public static Boolean isTokenExpired(String accessToken) { + DecodedJWT jwt = JWT.decode(accessToken); + return jwt.getExpiresAt().getTime() < new Date(System.currentTimeMillis()).getTime(); + } + +} diff --git a/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/utils/SpringUtil.java b/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/utils/SpringUtil.java new file mode 100644 index 0000000..6447dd3 --- /dev/null +++ b/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/utils/SpringUtil.java @@ -0,0 +1,58 @@ +package com.zhangy.skyeye.common.utils; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +@Component +public class SpringUtil implements ApplicationContextAware { + + private static ApplicationContext applicationContext; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + if(SpringUtil.applicationContext == null) { + SpringUtil.applicationContext = applicationContext; + } + } + + /** + * 获取applicationContext + * @return ApplicationContext + */ + public static ApplicationContext getApplicationContext() { + return applicationContext; + } + + /** + * 通过name获取 Bean. + * @param name name + * @return Bean对象 + */ + public static Object getBean(String name){ + return getApplicationContext().getBean(name); + } + + /** + * 通过class获取Bean + * @param clazz class + * @param + * @return Bean对象 + */ + public static T getBean(Class clazz){ + return getApplicationContext().getBean(clazz); + } + + /** + * 通过name,以及Clazz返回指定的Bean + * @param name name + * @param clazz class + * @param + * @return Bean对象 + */ + public static T getBean(String name,Class clazz){ + return getApplicationContext().getBean(name, clazz); + } + +} \ No newline at end of file diff --git a/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/utils/WebUtil.java b/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/utils/WebUtil.java new file mode 100644 index 0000000..f58021e --- /dev/null +++ b/library/skyeye-dev/skyeye-common/src/main/java/com/zhangy/skyeye/common/utils/WebUtil.java @@ -0,0 +1,78 @@ +package com.zhangy.skyeye.common.utils; + +import lombok.experimental.UtilityClass; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * web工具类 + */ +@UtilityClass +public class WebUtil { + + private final String UNKNOWN = "unknown"; + + /** + * 获取 HttpServletRequest + * + * @return HttpServletRequest + */ + public HttpServletRequest getRequest() { + try { + RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes(); + return ((ServletRequestAttributes) requestAttributes).getRequest(); + } catch (IllegalStateException e) { + return null; + } + } + + /** + * 获取 HttpServletResponse + * + * @return HttpServletResponse + */ + public HttpServletResponse getResponse() { + return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse(); + } + +// /** +// * 获取ip +// * @return +// */ +// public String getIP() { +// return getIP(getRequest()); +// } +// +// /** +// * 获取ip +// * @param request +// * @return +// */ +// public String getIP(HttpServletRequest request) { +// Assert.notNull(request, "HttpServletRequest is null"); +// String ip = request.getHeader("X-Requested-For"); +// if (StrUtil.isBlank(ip) || UNKNOWN.equalsIgnoreCase(ip)) { +// ip = request.getHeader("X-Forwarded-For"); +// } +// if (StrUtil.isBlank(ip) || UNKNOWN.equalsIgnoreCase(ip)) { +// ip = request.getHeader("Proxy-Client-IP"); +// } +// if (StrUtil.isBlank(ip) || UNKNOWN.equalsIgnoreCase(ip)) { +// ip = request.getHeader("WL-Proxy-Client-IP"); +// } +// if (StrUtil.isBlank(ip) || UNKNOWN.equalsIgnoreCase(ip)) { +// ip = request.getHeader("HTTP_CLIENT_IP"); +// } +// if (StrUtil.isBlank(ip) || UNKNOWN.equalsIgnoreCase(ip)) { +// ip = request.getHeader("HTTP_X_FORWARDED_FOR"); +// } +// if (StrUtil.isBlank(ip) || UNKNOWN.equalsIgnoreCase(ip)) { +// ip = request.getRemoteAddr(); +// } +// return StrUtil.isBlank(ip) ? null : ip.split(",")[0]; +// } +} diff --git a/library/skyeye-dev/skyeye-common/src/main/resources/META-INF/spring.factories b/library/skyeye-dev/skyeye-common/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..bcb56e9 --- /dev/null +++ b/library/skyeye-dev/skyeye-common/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.zhangy.skyeye.common.utils.SpringUtil diff --git a/library/skyeye-dev/skyeye-common/src/main/resources/banner.txt b/library/skyeye-dev/skyeye-common/src/main/resources/banner.txt new file mode 100644 index 0000000..f73ac5b --- /dev/null +++ b/library/skyeye-dev/skyeye-common/src/main/resources/banner.txt @@ -0,0 +1,12 @@ +${AnsiColor.BRIGHT_BLUE} + _____ _ _ ____ ____ _____ + |_ _(_) / \ _ __ ___ ___ / ___| _ __ __ _ ___ ___ | _ \_ _| + | | | | / _ \ | '_ ` _ \ / _ \ \___ \| '_ \ / _` |/ __/ _ \_____| | | || | + | | | |/ ___ \| | | | | | (_) | ___) | |_) | (_| | (_| __/_____| |_| || | + |_| |_/_/ \_\_| |_| |_|\___/ |____/| .__/ \__,_|\___\___| |____/ |_| + |_| +${AnsiColor.BRIGHT_GREEN} +Spring Boot Version: ${spring-boot.version} +Spring Cloud Version: Hoxton.SR9 +Spring Cloud Alibaba Version: 2.2.2.RELEASE +${AnsiColor.BLACK} \ No newline at end of file diff --git a/library/skyeye-dev/skyeye-common/src/main/resources/logback-spring.xml b/library/skyeye-dev/skyeye-common/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..7770c61 --- /dev/null +++ b/library/skyeye-dev/skyeye-common/src/main/resources/logback-spring.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + ${CONSOLE_LOG_PATTERN} + + + + + + ${log.path}/java/${spring.application.name}/syslogTodayDebug.log + + ${log.path}/%d{yyyy-MM-dd}/java/${spring.application.name}/syslogYesterdayDebug.%i.log + 50MB + 30 + + + %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n + + + + + + ${log.path}/java/${spring.application.name}/syslogTodayError.log + + ${log.path}/%d{yyyy-MM-dd}/java/${spring.application.name}/syslogYesterdayError.%i.log + 50MB + 30 + + + %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n + + + ERROR + + + + + + + + + + + + + + + diff --git a/library/skyeye-dev/skyeye-common/target/classes/META-INF/spring.factories b/library/skyeye-dev/skyeye-common/target/classes/META-INF/spring.factories new file mode 100644 index 0000000..bcb56e9 --- /dev/null +++ b/library/skyeye-dev/skyeye-common/target/classes/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.zhangy.skyeye.common.utils.SpringUtil diff --git a/library/skyeye-dev/skyeye-common/target/classes/banner.txt b/library/skyeye-dev/skyeye-common/target/classes/banner.txt new file mode 100644 index 0000000..f73ac5b --- /dev/null +++ b/library/skyeye-dev/skyeye-common/target/classes/banner.txt @@ -0,0 +1,12 @@ +${AnsiColor.BRIGHT_BLUE} + _____ _ _ ____ ____ _____ + |_ _(_) / \ _ __ ___ ___ / ___| _ __ __ _ ___ ___ | _ \_ _| + | | | | / _ \ | '_ ` _ \ / _ \ \___ \| '_ \ / _` |/ __/ _ \_____| | | || | + | | | |/ ___ \| | | | | | (_) | ___) | |_) | (_| | (_| __/_____| |_| || | + |_| |_/_/ \_\_| |_| |_|\___/ |____/| .__/ \__,_|\___\___| |____/ |_| + |_| +${AnsiColor.BRIGHT_GREEN} +Spring Boot Version: ${spring-boot.version} +Spring Cloud Version: Hoxton.SR9 +Spring Cloud Alibaba Version: 2.2.2.RELEASE +${AnsiColor.BLACK} \ No newline at end of file diff --git a/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/pojo/CommonConstant.class b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/pojo/CommonConstant.class new file mode 100644 index 0000000..6a0e8f6 Binary files /dev/null and b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/pojo/CommonConstant.class differ diff --git a/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/pojo/SecurityConstants.class b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/pojo/SecurityConstants.class new file mode 100644 index 0000000..d3adbd0 Binary files /dev/null and b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/pojo/SecurityConstants.class differ diff --git a/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/pojo/param/IdParam.class b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/pojo/param/IdParam.class new file mode 100644 index 0000000..f72bb79 Binary files /dev/null and b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/pojo/param/IdParam.class differ diff --git a/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/pojo/result/Result.class b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/pojo/result/Result.class new file mode 100644 index 0000000..2101bbb Binary files /dev/null and b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/pojo/result/Result.class differ diff --git a/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/pojo/result/ResultConstant.class b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/pojo/result/ResultConstant.class new file mode 100644 index 0000000..068d654 Binary files /dev/null and b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/pojo/result/ResultConstant.class differ diff --git a/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/pojo/tree/TreeNode.class b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/pojo/tree/TreeNode.class new file mode 100644 index 0000000..896ea2d Binary files /dev/null and b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/pojo/tree/TreeNode.class differ diff --git a/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/utils/CommonUtil.class b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/utils/CommonUtil.class new file mode 100644 index 0000000..ab20f78 Binary files /dev/null and b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/utils/CommonUtil.class differ diff --git a/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/utils/CookieUtil.class b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/utils/CookieUtil.class new file mode 100644 index 0000000..a926a27 Binary files /dev/null and b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/utils/CookieUtil.class differ diff --git a/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/utils/IPUtil.class b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/utils/IPUtil.class new file mode 100644 index 0000000..67c9ef0 Binary files /dev/null and b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/utils/IPUtil.class differ diff --git a/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/utils/JwtUtil.class b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/utils/JwtUtil.class new file mode 100644 index 0000000..9e95795 Binary files /dev/null and b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/utils/JwtUtil.class differ diff --git a/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/utils/SpringUtil.class b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/utils/SpringUtil.class new file mode 100644 index 0000000..17709f8 Binary files /dev/null and b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/utils/SpringUtil.class differ diff --git a/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/utils/WebUtil.class b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/utils/WebUtil.class new file mode 100644 index 0000000..5b68e8f Binary files /dev/null and b/library/skyeye-dev/skyeye-common/target/classes/com/zhangy/skyeye/common/utils/WebUtil.class differ diff --git a/library/skyeye-dev/skyeye-common/target/classes/logback-spring.xml b/library/skyeye-dev/skyeye-common/target/classes/logback-spring.xml new file mode 100644 index 0000000..7770c61 --- /dev/null +++ b/library/skyeye-dev/skyeye-common/target/classes/logback-spring.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + ${CONSOLE_LOG_PATTERN} + + + + + + ${log.path}/java/${spring.application.name}/syslogTodayDebug.log + + ${log.path}/%d{yyyy-MM-dd}/java/${spring.application.name}/syslogYesterdayDebug.%i.log + 50MB + 30 + + + %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n + + + + + + ${log.path}/java/${spring.application.name}/syslogTodayError.log + + ${log.path}/%d{yyyy-MM-dd}/java/${spring.application.name}/syslogYesterdayError.%i.log + 50MB + 30 + + + %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n + + + ERROR + + + + + + + + + + + + + + + diff --git a/library/skyeye-dev/skyeye-common/target/maven-archiver/pom.properties b/library/skyeye-dev/skyeye-common/target/maven-archiver/pom.properties new file mode 100644 index 0000000..6ac9d09 --- /dev/null +++ b/library/skyeye-dev/skyeye-common/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=skyeye-common +groupId=com.zhangy +version=1.0.0.RELEASE diff --git a/library/skyeye-dev/skyeye-common/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/library/skyeye-dev/skyeye-common/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..1bacb4a --- /dev/null +++ b/library/skyeye-dev/skyeye-common/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,12 @@ +com\zhangy\skyeye\common\utils\SpringUtil.class +com\zhangy\skyeye\common\utils\IPUtil.class +com\zhangy\skyeye\common\pojo\result\ResultConstant.class +com\zhangy\skyeye\common\pojo\tree\TreeNode.class +com\zhangy\skyeye\common\pojo\param\IdParam.class +com\zhangy\skyeye\common\pojo\result\Result.class +com\zhangy\skyeye\common\utils\WebUtil.class +com\zhangy\skyeye\common\utils\CommonUtil.class +com\zhangy\skyeye\common\utils\JwtUtil.class +com\zhangy\skyeye\common\pojo\SecurityConstants.class +com\zhangy\skyeye\common\pojo\CommonConstant.class +com\zhangy\skyeye\common\utils\CookieUtil.class diff --git a/library/skyeye-dev/skyeye-common/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/library/skyeye-dev/skyeye-common/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..11f828d --- /dev/null +++ b/library/skyeye-dev/skyeye-common/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,12 @@ +D:\logisen\ddd\skyeye-dev\skyeye-common\src\main\java\com\zhangy\skyeye\common\pojo\CommonConstant.java +D:\logisen\ddd\skyeye-dev\skyeye-common\src\main\java\com\zhangy\skyeye\common\pojo\param\IdParam.java +D:\logisen\ddd\skyeye-dev\skyeye-common\src\main\java\com\zhangy\skyeye\common\pojo\SecurityConstants.java +D:\logisen\ddd\skyeye-dev\skyeye-common\src\main\java\com\zhangy\skyeye\common\utils\CookieUtil.java +D:\logisen\ddd\skyeye-dev\skyeye-common\src\main\java\com\zhangy\skyeye\common\utils\SpringUtil.java +D:\logisen\ddd\skyeye-dev\skyeye-common\src\main\java\com\zhangy\skyeye\common\pojo\result\ResultConstant.java +D:\logisen\ddd\skyeye-dev\skyeye-common\src\main\java\com\zhangy\skyeye\common\pojo\tree\TreeNode.java +D:\logisen\ddd\skyeye-dev\skyeye-common\src\main\java\com\zhangy\skyeye\common\utils\WebUtil.java +D:\logisen\ddd\skyeye-dev\skyeye-common\src\main\java\com\zhangy\skyeye\common\pojo\result\Result.java +D:\logisen\ddd\skyeye-dev\skyeye-common\src\main\java\com\zhangy\skyeye\common\utils\CommonUtil.java +D:\logisen\ddd\skyeye-dev\skyeye-common\src\main\java\com\zhangy\skyeye\common\utils\JwtUtil.java +D:\logisen\ddd\skyeye-dev\skyeye-common\src\main\java\com\zhangy\skyeye\common\utils\IPUtil.java diff --git a/library/skyeye-dev/skyeye-common/target/skyeye-common-1.0.0.RELEASE.jar b/library/skyeye-dev/skyeye-common/target/skyeye-common-1.0.0.RELEASE.jar new file mode 100644 index 0000000..122c117 Binary files /dev/null and b/library/skyeye-dev/skyeye-common/target/skyeye-common-1.0.0.RELEASE.jar differ diff --git a/library/skyeye-dev/skyeye-db/pom.xml b/library/skyeye-dev/skyeye-db/pom.xml new file mode 100644 index 0000000..61d23d8 --- /dev/null +++ b/library/skyeye-dev/skyeye-db/pom.xml @@ -0,0 +1,53 @@ + + + + + skyeye-dev + com.zhangy + 1.0.0.RELEASE + + 4.0.0 + + skyeye-db + jar + skyeye db library + + + + + + org.springframework.boot + spring-boot-starter-web + + + + + com.baomidou + mybatis-plus-boot-starter + + + + + com.alibaba + druid-spring-boot-starter + + + + + com.zhangy + skyeye-common + ${skyeye.version} + + + + + com.github.xiaoymin + knife4j-micro-spring-boot-starter + + + + + + \ No newline at end of file diff --git a/library/skyeye-dev/skyeye-db/src/main/java/com/zhangy/skyeye/.DS_Store b/library/skyeye-dev/skyeye-db/src/main/java/com/zhangy/skyeye/.DS_Store new file mode 100644 index 0000000..285bd77 Binary files /dev/null and b/library/skyeye-dev/skyeye-db/src/main/java/com/zhangy/skyeye/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-db/src/main/java/com/zhangy/skyeye/db/config/DTDruidConfig.java b/library/skyeye-dev/skyeye-db/src/main/java/com/zhangy/skyeye/db/config/DTDruidConfig.java new file mode 100644 index 0000000..9b47295 --- /dev/null +++ b/library/skyeye-dev/skyeye-db/src/main/java/com/zhangy/skyeye/db/config/DTDruidConfig.java @@ -0,0 +1,39 @@ +package com.zhangy.skyeye.db.config; + +import com.alibaba.druid.support.http.StatViewServlet; +import com.alibaba.druid.support.http.WebStatFilter; +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class DTDruidConfig { + + @Bean + public ServletRegistrationBean statViewServletRegistrationBean() { + ServletRegistrationBean registrationBean = new ServletRegistrationBean(); + registrationBean.setServlet(new StatViewServlet()); + registrationBean.addUrlMappings(new String[] { "/druid/*" }); + registrationBean.addInitParameter("loginUsername", "admin"); + registrationBean.addInitParameter("loginPassword", "123456"); + registrationBean.addInitParameter("resetEnable", "false"); + return registrationBean; + } + + @Bean + public FilterRegistrationBean webStatFilterRegistrationBean() { + FilterRegistrationBean registrationBean = new FilterRegistrationBean(); + WebStatFilter filter = new WebStatFilter(); + registrationBean.setFilter(filter); + registrationBean.addUrlPatterns(new String[] { "/*" }); + registrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"); + registrationBean.addInitParameter("sessionStatEnable", "false"); + registrationBean.addInitParameter("sessionStatMaxCount", "1000"); + registrationBean.addInitParameter("principalSessionName", ""); + registrationBean.addInitParameter("principalCookieName", ""); + registrationBean.addInitParameter("profileEnable", "true"); + return registrationBean; + } + +} diff --git a/library/skyeye-dev/skyeye-db/src/main/java/com/zhangy/skyeye/db/config/DTMybatisPlusConfig.java b/library/skyeye-dev/skyeye-db/src/main/java/com/zhangy/skyeye/db/config/DTMybatisPlusConfig.java new file mode 100644 index 0000000..0161abc --- /dev/null +++ b/library/skyeye-dev/skyeye-db/src/main/java/com/zhangy/skyeye/db/config/DTMybatisPlusConfig.java @@ -0,0 +1,47 @@ +package com.zhangy.skyeye.db.config; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.handler.TableNameHandler; +import com.baomidou.mybatisplus.extension.plugins.inner.DynamicTableNameInnerInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.HashMap; + +@MapperScan("com.tiamo.dt.**.mapper") +@Configuration +public class DTMybatisPlusConfig { + + /** + * 分页插件 + */ + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + + //分页插件 + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); + + //动态表名插件 + DynamicTableNameInnerInterceptor dynamicTableNameInnerInterceptor = new DynamicTableNameInnerInterceptor(); + HashMap map = new HashMap<>(); + map.put("res_pos_vel", (sql, tableName) -> tableName + "_" + DynamicTableNameHelper.getTableNameSuffix()); + map.put("env_sat_risk", (sql, tableName) -> getTableName(tableName, DynamicTableNameHelper.getTableNameSuffix())); + map.put("env_goes_proton", (sql, tableName) -> getTableName(tableName, DynamicTableNameHelper.getTableNameSuffix())); + map.put("env_goes_electron", (sql, tableName) -> getTableName(tableName, DynamicTableNameHelper.getTableNameSuffix())); + map.put("env_goes_xray", (sql, tableName) -> getTableName(tableName, DynamicTableNameHelper.getTableNameSuffix())); + map.put("env_goes_geomagnetic", (sql, tableName) -> getTableName(tableName, DynamicTableNameHelper.getTableNameSuffix())); + map.put("env_poes_data", (sql, tableName) -> getTableName(tableName, DynamicTableNameHelper.getTableNameSuffix())); + dynamicTableNameInnerInterceptor.setTableNameHandlerMap(map); + interceptor.addInnerInterceptor(dynamicTableNameInnerInterceptor); + + return interceptor; + } + + private String getTableName(String tableName, String suffix) { + return suffix != null ? tableName + suffix : tableName; + } +} diff --git a/library/skyeye-dev/skyeye-db/src/main/java/com/zhangy/skyeye/db/config/DynamicTableNameHelper.java b/library/skyeye-dev/skyeye-db/src/main/java/com/zhangy/skyeye/db/config/DynamicTableNameHelper.java new file mode 100644 index 0000000..cfe4b95 --- /dev/null +++ b/library/skyeye-dev/skyeye-db/src/main/java/com/zhangy/skyeye/db/config/DynamicTableNameHelper.java @@ -0,0 +1,20 @@ +package com.zhangy.skyeye.db.config; + +/** + * 动态表名参数类 + */ +public class DynamicTableNameHelper { + + /** + * 动态表名参数保存 + */ + private static final ThreadLocal TABLE_NAME_SUFFIX = new ThreadLocal<>(); + + public static void setTableNameSuffix(String tableNameSuffix){ + TABLE_NAME_SUFFIX.set(tableNameSuffix); + } + + public static String getTableNameSuffix() { + return TABLE_NAME_SUFFIX.get(); + } +} diff --git a/library/skyeye-dev/skyeye-db/src/main/java/com/zhangy/skyeye/db/pojo/page/PageParam.java b/library/skyeye-dev/skyeye-db/src/main/java/com/zhangy/skyeye/db/pojo/page/PageParam.java new file mode 100644 index 0000000..3738b49 --- /dev/null +++ b/library/skyeye-dev/skyeye-db/src/main/java/com/zhangy/skyeye/db/pojo/page/PageParam.java @@ -0,0 +1,26 @@ +package com.zhangy.skyeye.db.pojo.page; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * 分页参数 + */ +@Data +@ApiModel(value="PageParam对象", description="分页参数") +public class PageParam { + + @ApiModelProperty(value = "当前页", position = 1) + private Integer pageCurrent = 1; + + @ApiModelProperty(value = "每页数量", position = 2) + private Integer pageSize = 10; + + @ApiModelProperty(value = "排序字段", position = 3) + private String orderBy; + + @ApiModelProperty(value = "正序or倒序", position = 4) + private Boolean isAsc = true; + +} diff --git a/library/skyeye-dev/skyeye-db/src/main/java/com/zhangy/skyeye/db/pojo/props/Knife4jProperties.java b/library/skyeye-dev/skyeye-db/src/main/java/com/zhangy/skyeye/db/pojo/props/Knife4jProperties.java new file mode 100644 index 0000000..37b716d --- /dev/null +++ b/library/skyeye-dev/skyeye-db/src/main/java/com/zhangy/skyeye/db/pojo/props/Knife4jProperties.java @@ -0,0 +1,22 @@ +package com.zhangy.skyeye.db.pojo.props; + +import lombok.Data; + +/** + * knife4j配置配置信息 + */ +@Data +public class Knife4jProperties { + + /** + * Controller包根路径 + */ + private String basePackage; + + private String title; + + private String description; + + private String version; + +} diff --git a/library/skyeye-dev/skyeye-db/src/main/java/com/zhangy/skyeye/db/utils/MPUtil.java b/library/skyeye-dev/skyeye-db/src/main/java/com/zhangy/skyeye/db/utils/MPUtil.java new file mode 100644 index 0000000..37a61cf --- /dev/null +++ b/library/skyeye-dev/skyeye-db/src/main/java/com/zhangy/skyeye/db/utils/MPUtil.java @@ -0,0 +1,81 @@ +package com.zhangy.skyeye.db.config; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.OrderItem; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.zhangy.skyeye.common.utils.CommonUtil; +import com.zhangy.skyeye.db.pojo.page.PageParam; + +/** + * MybatisPlus工具类 + */ +public class MPUtil { + + /** + * 通过PageParam获取分页对象 + * @param pageParam + * @return + */ + public static Page getPage(PageParam pageParam){ + if(pageParam == null){ + pageParam = new PageParam(); + } + + Page page = new Page(pageParam.getPageCurrent(), pageParam.getPageSize()); + if(pageParam.getOrderBy() != null && !pageParam.getOrderBy().isEmpty()){ + String[] orderColumnArr = pageParam.getOrderBy().split(","); + + //驼峰转下划线,数据库中字段为下划线 + for (int i = 0; i < orderColumnArr.length; i++) { + orderColumnArr[i] = CommonUtil.camelToUnderline(orderColumnArr[i]); + } + + if(pageParam.getIsAsc()){ + page.addOrder(OrderItem.ascs(orderColumnArr)); + }else{ + page.addOrder(OrderItem.descs(orderColumnArr)); + } + } + return page; + } + + /** + * 获取QueryWrapper + * @return + */ + public static QueryWrapper getQueryWrapper(){ + return new QueryWrapper<>(); + } + + /** + * 获取QueryWrapper + * @param pageParam + * @return + */ + public static QueryWrapper getQueryWrapper(PageParam pageParam){ + if(pageParam == null){ + return new QueryWrapper<>(); + } + + QueryWrapper queryWrapper = new QueryWrapper<>(); + + if(pageParam.getOrderBy() != null && !pageParam.getOrderBy().isEmpty()){ + String[] orderColumnArr = pageParam.getOrderBy().split(","); + + //驼峰转下划线,数据库中字段为下划线 + for (int i = 0; i < orderColumnArr.length; i++) { + orderColumnArr[i] = CommonUtil.camelToUnderline(orderColumnArr[i]); + } + + if(pageParam.getIsAsc()){ + queryWrapper.orderByAsc(orderColumnArr); + }else{ + queryWrapper.orderByDesc(orderColumnArr); + } + } + + + return queryWrapper; + } + +} diff --git a/library/skyeye-dev/skyeye-db/src/main/resources/META-INF/spring.factories b/library/skyeye-dev/skyeye-db/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..f0e7ff3 --- /dev/null +++ b/library/skyeye-dev/skyeye-db/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.tiamo.dt.dev.db.config.DTDruidConfig,\ + com.tiamo.dt.dev.db.config.DTMybatisPlusConfig diff --git a/library/skyeye-dev/skyeye-db/target/classes/META-INF/spring.factories b/library/skyeye-dev/skyeye-db/target/classes/META-INF/spring.factories new file mode 100644 index 0000000..f0e7ff3 --- /dev/null +++ b/library/skyeye-dev/skyeye-db/target/classes/META-INF/spring.factories @@ -0,0 +1,3 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.tiamo.dt.dev.db.config.DTDruidConfig,\ + com.tiamo.dt.dev.db.config.DTMybatisPlusConfig diff --git a/library/skyeye-dev/skyeye-db/target/classes/com/zhangy/skyeye/db/config/DTDruidConfig.class b/library/skyeye-dev/skyeye-db/target/classes/com/zhangy/skyeye/db/config/DTDruidConfig.class new file mode 100644 index 0000000..7110b3a Binary files /dev/null and b/library/skyeye-dev/skyeye-db/target/classes/com/zhangy/skyeye/db/config/DTDruidConfig.class differ diff --git a/library/skyeye-dev/skyeye-db/target/classes/com/zhangy/skyeye/db/config/DTMybatisPlusConfig.class b/library/skyeye-dev/skyeye-db/target/classes/com/zhangy/skyeye/db/config/DTMybatisPlusConfig.class new file mode 100644 index 0000000..451ec70 Binary files /dev/null and b/library/skyeye-dev/skyeye-db/target/classes/com/zhangy/skyeye/db/config/DTMybatisPlusConfig.class differ diff --git a/library/skyeye-dev/skyeye-db/target/classes/com/zhangy/skyeye/db/config/DynamicTableNameHelper.class b/library/skyeye-dev/skyeye-db/target/classes/com/zhangy/skyeye/db/config/DynamicTableNameHelper.class new file mode 100644 index 0000000..626f6d8 Binary files /dev/null and b/library/skyeye-dev/skyeye-db/target/classes/com/zhangy/skyeye/db/config/DynamicTableNameHelper.class differ diff --git a/library/skyeye-dev/skyeye-db/target/classes/com/zhangy/skyeye/db/config/MPUtil.class b/library/skyeye-dev/skyeye-db/target/classes/com/zhangy/skyeye/db/config/MPUtil.class new file mode 100644 index 0000000..c50e163 Binary files /dev/null and b/library/skyeye-dev/skyeye-db/target/classes/com/zhangy/skyeye/db/config/MPUtil.class differ diff --git a/library/skyeye-dev/skyeye-db/target/classes/com/zhangy/skyeye/db/pojo/page/PageParam.class b/library/skyeye-dev/skyeye-db/target/classes/com/zhangy/skyeye/db/pojo/page/PageParam.class new file mode 100644 index 0000000..6a84c4d Binary files /dev/null and b/library/skyeye-dev/skyeye-db/target/classes/com/zhangy/skyeye/db/pojo/page/PageParam.class differ diff --git a/library/skyeye-dev/skyeye-db/target/classes/com/zhangy/skyeye/db/pojo/props/Knife4jProperties.class b/library/skyeye-dev/skyeye-db/target/classes/com/zhangy/skyeye/db/pojo/props/Knife4jProperties.class new file mode 100644 index 0000000..8f4ac6a Binary files /dev/null and b/library/skyeye-dev/skyeye-db/target/classes/com/zhangy/skyeye/db/pojo/props/Knife4jProperties.class differ diff --git a/library/skyeye-dev/skyeye-db/target/maven-archiver/pom.properties b/library/skyeye-dev/skyeye-db/target/maven-archiver/pom.properties new file mode 100644 index 0000000..bc96b8f --- /dev/null +++ b/library/skyeye-dev/skyeye-db/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=skyeye-db +groupId=com.zhangy +version=1.0.0.RELEASE diff --git a/library/skyeye-dev/skyeye-db/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/library/skyeye-dev/skyeye-db/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..2d96a96 --- /dev/null +++ b/library/skyeye-dev/skyeye-db/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,6 @@ +com\zhangy\skyeye\db\config\DTDruidConfig.class +com\zhangy\skyeye\db\config\DTMybatisPlusConfig.class +com\zhangy\skyeye\db\pojo\page\PageParam.class +com\zhangy\skyeye\db\config\DynamicTableNameHelper.class +com\zhangy\skyeye\db\config\MPUtil.class +com\zhangy\skyeye\db\pojo\props\Knife4jProperties.class diff --git a/library/skyeye-dev/skyeye-db/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/library/skyeye-dev/skyeye-db/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..5e4d5ef --- /dev/null +++ b/library/skyeye-dev/skyeye-db/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,6 @@ +D:\logisen\ddd\skyeye-dev\skyeye-db\src\main\java\com\zhangy\skyeye\db\utils\MPUtil.java +D:\logisen\ddd\skyeye-dev\skyeye-db\src\main\java\com\zhangy\skyeye\db\config\DynamicTableNameHelper.java +D:\logisen\ddd\skyeye-dev\skyeye-db\src\main\java\com\zhangy\skyeye\db\config\DTDruidConfig.java +D:\logisen\ddd\skyeye-dev\skyeye-db\src\main\java\com\zhangy\skyeye\db\pojo\props\Knife4jProperties.java +D:\logisen\ddd\skyeye-dev\skyeye-db\src\main\java\com\zhangy\skyeye\db\pojo\page\PageParam.java +D:\logisen\ddd\skyeye-dev\skyeye-db\src\main\java\com\zhangy\skyeye\db\config\DTMybatisPlusConfig.java diff --git a/library/skyeye-dev/skyeye-db/target/skyeye-db-1.0.0.RELEASE.jar b/library/skyeye-dev/skyeye-db/target/skyeye-db-1.0.0.RELEASE.jar new file mode 100644 index 0000000..11138af Binary files /dev/null and b/library/skyeye-dev/skyeye-db/target/skyeye-db-1.0.0.RELEASE.jar differ diff --git a/library/skyeye-dev/skyeye-generator/.DS_Store b/library/skyeye-dev/skyeye-generator/.DS_Store new file mode 100644 index 0000000..fb82c56 Binary files /dev/null and b/library/skyeye-dev/skyeye-generator/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-generator/pom.xml b/library/skyeye-dev/skyeye-generator/pom.xml new file mode 100644 index 0000000..234953b --- /dev/null +++ b/library/skyeye-dev/skyeye-generator/pom.xml @@ -0,0 +1,45 @@ + + + + + skyeye-dev + com.zhangy + 1.0.0.RELEASE + + 4.0.0 + + skyeye-generator + skyeye code generator lib + + + + + + com.baomidou + mybatis-plus-generator + + + + + org.springframework.boot + spring-boot-starter-logging + + + + + org.apache.velocity + velocity + 1.7 + + + + + org.projectlombok + lombok + + + + + \ No newline at end of file diff --git a/library/skyeye-dev/skyeye-generator/src/.DS_Store b/library/skyeye-dev/skyeye-generator/src/.DS_Store new file mode 100644 index 0000000..ad10f0b Binary files /dev/null and b/library/skyeye-dev/skyeye-generator/src/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-generator/src/main/.DS_Store b/library/skyeye-dev/skyeye-generator/src/main/.DS_Store new file mode 100644 index 0000000..0f81f65 Binary files /dev/null and b/library/skyeye-dev/skyeye-generator/src/main/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-generator/src/main/java/com/zhangy/skyeye/generator/GeneratorApi.java b/library/skyeye-dev/skyeye-generator/src/main/java/com/zhangy/skyeye/generator/GeneratorApi.java new file mode 100644 index 0000000..216271c --- /dev/null +++ b/library/skyeye-dev/skyeye-generator/src/main/java/com/zhangy/skyeye/generator/GeneratorApi.java @@ -0,0 +1,194 @@ +package com.zhangy.skyeye.generator; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.core.toolkit.StringPool; +import com.baomidou.mybatisplus.generator.AutoGenerator; +import com.baomidou.mybatisplus.generator.InjectionConfig; +import com.baomidou.mybatisplus.generator.config.*; +import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert; +import com.baomidou.mybatisplus.generator.config.converts.OracleTypeConvert; +import com.baomidou.mybatisplus.generator.config.converts.PostgreSqlTypeConvert; +import com.baomidou.mybatisplus.generator.config.converts.SqlServerTypeConvert; +import com.baomidou.mybatisplus.generator.config.po.TableInfo; +import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +/** + * 代码生成器配置类 + */ +@Data +public class GeneratorApi { + /** + * 数据库驱动名 + */ + private String driverName; + /** + * 数据库链接地址 + */ + private String url; + /** + * 数据库用户名 + */ + private String username; + /** + * 数据库密码 + */ + private String password; + /** + * 输出文件目录 + */ + private String outputDir; + /** + * 作者 + */ + private String author = "Tiamo"; + /** + * 代码生成的包名 + */ + private String packageName; + /** + * 需要生成的表名(两者只能取其一) + */ + private String[] includeTables; + /** + * 需要排除的表名(两者只能取其一) + */ + private String[] excludeTables; + /** + * 是否启用swagger + */ + private Boolean isSwagger2 = Boolean.TRUE; + + public void run() { + AutoGenerator mpg = new AutoGenerator(); + + //全局配置 + GlobalConfig gc = new GlobalConfig(); + //代码输出目录 + gc.setOutputDir(outputDir + "/src/main/java"); + //开发人员 + gc.setAuthor(author); + + gc.setFileOverride(true); + //是否打开输出目录 + gc.setOpen(false); + gc.setActiveRecord(false); + gc.setEnableCache(false); + //Mybatis Mapping.xml中增加BaseResult和BaseColumn + gc.setBaseResultMap(true); + gc.setBaseColumnList(true); + /*gc.setMapperName("%sMapper"); + gc.setXmlName("%sMapping"); + gc.setServiceName("I%sService"); + gc.setServiceImplName("%sServiceImpl"); + gc.setControllerName("%sController");*/ + gc.setSwagger2(isSwagger2); + mpg.setGlobalConfig(gc); + + //数据源配置 + DataSourceConfig dsc = new DataSourceConfig(); + dsc.setDriverName(this.driverName); + dsc.setUrl(this.url); + dsc.setUsername(this.username); + dsc.setPassword(this.password); + if (this.driverName.contains(DbType.MYSQL.getDb())) { + dsc.setDbType(DbType.MYSQL); + dsc.setTypeConvert(new MySqlTypeConvert()); + } else if (this.driverName.contains(DbType.POSTGRE_SQL.getDb())) { + dsc.setDbType(DbType.POSTGRE_SQL); + dsc.setTypeConvert(new PostgreSqlTypeConvert()); + } else if (this.driverName.contains(DbType.SQL_SERVER.getDb())) { + dsc.setDbType(DbType.SQL_SERVER); + dsc.setTypeConvert(new SqlServerTypeConvert()); + } else if (this.driverName.contains(DbType.ORACLE.getDb())) { + dsc.setDbType(DbType.ORACLE); + dsc.setTypeConvert(new OracleTypeConvert()); + } else { + System.out.println("数据库类型异常,代码生成失败!"); + return; + } + mpg.setDataSource(dsc); + + // 策略配置 + StrategyConfig strategy = new StrategyConfig(); + // strategy.setCapitalMode(true);// 全局大写命名 + // strategy.setDbColumnUnderline(true);//全局下划线命名 + strategy.setNaming(NamingStrategy.underline_to_camel); + strategy.setColumnNaming(NamingStrategy.underline_to_camel); +// strategy.setTablePrefix(tablePrefix); + if (includeTables.length > 0) { + strategy.setInclude(includeTables); + } + if (excludeTables.length > 0) { + strategy.setExclude(excludeTables); + } + + // 自定义 controller 父类 +// strategy.setSuperControllerClass("com.tiamo.dev.db.controller.BaseController"); + strategy.setEntityBuilderModel(false); + strategy.setEntityLombokModel(true); + strategy.setRestControllerStyle(true); + strategy.setControllerMappingHyphenStyle(true); + mpg.setStrategy(strategy); + + // 包配置 + PackageConfig pc = new PackageConfig(); + // 控制台扫描 + pc.setModuleName(null); + //父包名 + pc.setParent(packageName); + //controller包名 + pc.setController("controller"); + //entity包名 + pc.setEntity("entity"); + //mapping包名 + pc.setXml("mapping"); + mpg.setPackageInfo(pc); + + //自定义配置 + InjectionConfig injectionConfig = new InjectionConfig() { + @Override + public void initMap() { + + } + }; + + //如果模板引擎是 freemarker + //String templatePath = "/templates/mapping.xml.ftl"; + // 如果模板引擎是 velocity + String templatePath = "/templates/mapping.xml.vm"; + + // 自定义输出配置 + List focList = new ArrayList<>(); + // 自定义配置会被优先输出 + focList.add(new FileOutConfig(templatePath) { + @Override + public String outputFile(TableInfo tableInfo) { + // 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!! + return outputDir + "/src/main/resources/mapping/" + + tableInfo.getEntityName() + "Mapping" + StringPool.DOT_XML; + } + }); + + injectionConfig.setFileOutConfigList(focList); + mpg.setCfg(injectionConfig); + + // 配置模板 + TemplateConfig templateConfig = new TemplateConfig(); + + // 配置自定义输出模板 + //指定自定义模板路径,注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别 + // templateConfig.setEntity("templates/entity2.java"); + // templateConfig.setService(); + // templateConfig.setController(); + + templateConfig.setXml(null); + mpg.setTemplate(templateConfig); + + mpg.execute(); + } + +} diff --git a/library/skyeye-dev/skyeye-generator/src/main/resources/templates/controller.java.vm b/library/skyeye-dev/skyeye-generator/src/main/resources/templates/controller.java.vm new file mode 100644 index 0000000..63bcbe9 --- /dev/null +++ b/library/skyeye-dev/skyeye-generator/src/main/resources/templates/controller.java.vm @@ -0,0 +1,134 @@ +package ${package.Controller}; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import org.springframework.web.bind.annotation.*; +#if(${restControllerStyle}) +#else +import org.springframework.stereotype.Controller; +#end + +#if(${superControllerClassPackage}) +import ${superControllerClassPackage}; +#end +#if(${swagger2}) +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +#end +#if(${entityLombokModel}) +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +#end + +import $!{package.Entity}.$!{entity}; +import $!{package.Service}.$!{table.serviceName}; +import result.pojo.com.zhangy.skyeye.common.Result; +import param.pojo.com.zhangy.skyeye.common.IdParam; +import com.tiamo.dt.dev.db.utils.MPUtil; +import com.tiamo.dt.dev.db.pojo.page.PageParam; + +import java.util.List; + +/** + * $!{table.comment} 前端控制器 + * + * @author ${author} + * @since ${date} + */ +#if(${restControllerStyle}) +@RestController +#else +@Controller +#end +@AllArgsConstructor +@Slf4j +@Api(value = "$!{table.comment}", tags = "$!{table.comment}接口") +@RequestMapping("#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end") +#if(${superControllerClass}) +public class ${table.controllerName} extends ${superControllerClass} { +#else +public class ${table.controllerName} { +#end + + private $!{table.serviceName} $!{table.entityPath}Service; + + /** + * 新增 + */ + @PostMapping("/save") + @ApiOperationSupport(order = 1) + @ApiOperation(value = "新增", notes = "传入$!{table.entityPath}") + public Result save(@RequestBody $!{entity} $!{table.entityPath}) { + if($!{table.entityPath} == null){ + return Result.error("参数异常"); + } + return Result.status($!{table.entityPath}Service.save($!{table.entityPath})); + } + + /** + * 修改 $!{table.comment} + */ + @PostMapping("/update") + @ApiOperationSupport(order = 2) + @ApiOperation(value = "修改", notes = "传入$!{table.entityPath}") + public Result update(@RequestBody $!{entity} $!{table.entityPath}) { + if($!{table.entityPath} == null){ + return Result.error("参数异常"); + } + return Result.status($!{table.entityPath}Service.updateById($!{table.entityPath})); + } + + /** + * 删除 $!{table.comment} + */ + @PostMapping("/remove") + @ApiOperationSupport(order = 3) + @ApiOperation(value = "删除", notes = "传入ids") + public Result remove(@RequestBody IdParam idParam) { + if(idParam == null){ + return Result.error("参数异常!"); + } + + return Result.status($!{table.entityPath}Service.removeByIds(idParam.getIds())); + } + + /** + * 详情 + */ + @GetMapping("/detail") + @ApiOperationSupport(order = 4) + @ApiOperation(value = "详情", notes = "传入id") + public Result<$!{entity}> detail(Long id) { + if(id == null){ + return Result.error("参数异常"); + } + $!{entity} detail = $!{table.entityPath}Service.getById(id); + return Result.successData(detail); + } + + /** + * 查询 $!{table.comment} + */ + @GetMapping("/list") + @ApiOperationSupport(order = 5) + @ApiOperation(value = "查询", notes = "传入$!{table.entityPath}") + public Result> list(PageParam pageParam, $!{entity} $!{table.entityPath}) { + List<$!{entity}> list = $!{table.entityPath}Service.list($!{table.entityPath}Service.getQueryWrapper(pageParam, $!{table.entityPath})); + return Result.successData(list); + } + + /** + * 分页 $!{table.comment} + */ + @GetMapping("/page") + @ApiOperationSupport(order = 6) + @ApiOperation(value = "分页", notes = "传入$!{table.entityPath}") + public Result> page(PageParam pageParam, $!{entity} $!{table.entityPath}) { + IPage<$!{entity}> pages = $!{table.entityPath}Service.page( + MPUtil.getPage(pageParam), + $!{table.entityPath}Service.getQueryWrapper(null, $!{table.entityPath}) + ); + return Result.successData(pages); + } + +} diff --git a/library/skyeye-dev/skyeye-generator/src/main/resources/templates/entity.java.vm b/library/skyeye-dev/skyeye-generator/src/main/resources/templates/entity.java.vm new file mode 100644 index 0000000..9031ae0 --- /dev/null +++ b/library/skyeye-dev/skyeye-generator/src/main/resources/templates/entity.java.vm @@ -0,0 +1,158 @@ +package ${package.Entity}; + +#foreach($pkg in ${table.importPackages}) +import ${pkg}; +#end +#if(${swagger2}) +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +#end +#if(${entityLombokModel}) +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +#if(${chainModel}) +import lombok.experimental.Accessors; +#end +#end + +/** + * $!{table.comment} + * + * @author ${author} + * @since ${date} + */ +#if(${entityLombokModel}) +@Data +@AllArgsConstructor +@NoArgsConstructor +#if(${superEntityClass}) +@EqualsAndHashCode(callSuper = true) +#else +@EqualsAndHashCode(callSuper = false) +#end +#if(${chainModel}) +@Accessors(chain = true) +#end +#end +#if(${table.convert}) +@TableName("${table.name}") +#end +#if(${swagger2}) +@ApiModel(value="${entity}对象", description="$!{table.comment}") +#end +#if(${superEntityClass}) +public class ${entity} extends ${superEntityClass}#if(${activeRecord})<${entity}>#end { +#elseif(${activeRecord}) +public class ${entity} extends Model<${entity}> { +#else +public class ${entity} implements Serializable { +#end + +#if(${entitySerialVersionUID}) + private static final long serialVersionUID = 1L; +#end +## ---------- BEGIN 字段循环遍历 ---------- +#foreach($field in ${table.fields}) + +#if(${field.keyFlag}) +#set($keyPropertyName=${field.propertyName}) +#end +#if("$!field.comment" != "") +#if(${swagger2}) + @ApiModelProperty(value = "${field.comment}", position = ${foreach.index}) +#else + /** + * ${field.comment} + */ +#end +#end +#if(${field.keyFlag}) +## 主键 +#if(${field.keyIdentityFlag}) + @TableId(value = "${field.annotationColumnName}", type = IdType.AUTO) +#elseif(!$null.isNull(${idType}) && "$!idType" != "") + @TableId(value = "${field.annotationColumnName}", type = IdType.${idType}) +#elseif(${field.convert}) + @TableId("${field.annotationColumnName}") +#end +## 普通字段 +#elseif(${field.fill}) +## ----- 存在字段填充设置 ----- +#if(${field.convert}) + @TableField(value = "${field.annotationColumnName}", fill = FieldFill.${field.fill}) +#else + @TableField(fill = FieldFill.${field.fill}) +#end +#elseif(${field.convert}) + @TableField("${field.annotationColumnName}") +#end +## 乐观锁注解 +#if(${versionFieldName}==${field.name}) + @Version +#end +## 逻辑删除注解 +#if(${logicDeleteFieldName}==${field.name}) + @TableLogic +#end + private ${field.propertyType} ${field.propertyName}; +#end +## ---------- END 字段循环遍历 ---------- +#if(!${entityLombokModel}) +#foreach($field in ${table.fields}) +#if(${field.propertyType.equals("boolean")}) +#set($getprefix="is") +#else +#set($getprefix="get") +#end + public ${field.propertyType} ${getprefix}${field.capitalName}() { + return ${field.propertyName}; + } +#if(${chainModel}) + public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) { +#else + public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) { +#end + this.${field.propertyName} = ${field.propertyName}; +#if(${chainModel}) + return this; +#end + } +#end +## --foreach end--- +#end +## --end of #if(!${entityLombokModel})-- +#if(${entityColumnConstant}) +#foreach($field in ${table.fields}) + public static final String ${field.name.toUpperCase()} = "${field.name}"; + +#end +#end +#if(${activeRecord}) + @Override + protected Serializable pkVal() { +#if(${keyPropertyName}) + return this.${keyPropertyName}; +#else + return null; +#end + } + +#end +#if(!${entityLombokModel}) + @Override + public String toString() { + return "${entity}{" + +#foreach($field in ${table.fields}) +#if($!{foreach.index}==0) + "${field.propertyName}=" + ${field.propertyName} + +#else + ", ${field.propertyName}=" + ${field.propertyName} + +#end +#end + "}"; + } +#end + +} diff --git a/library/skyeye-dev/skyeye-generator/src/main/resources/templates/mapper.java.vm b/library/skyeye-dev/skyeye-generator/src/main/resources/templates/mapper.java.vm new file mode 100644 index 0000000..101e157 --- /dev/null +++ b/library/skyeye-dev/skyeye-generator/src/main/resources/templates/mapper.java.vm @@ -0,0 +1,14 @@ +package ${package.Mapper}; + +import ${package.Entity}.${entity}; +import ${superMapperClassPackage}; + +/** + * $!{table.comment} Mapper 接口 + * + * @author ${author} + * @since ${date} + */ +public interface ${table.mapperName} extends ${superMapperClass}<${entity}> { + +} diff --git a/library/skyeye-dev/skyeye-generator/src/main/resources/templates/mapping.xml.vm b/library/skyeye-dev/skyeye-generator/src/main/resources/templates/mapping.xml.vm new file mode 100644 index 0000000..7a8e48d --- /dev/null +++ b/library/skyeye-dev/skyeye-generator/src/main/resources/templates/mapping.xml.vm @@ -0,0 +1,38 @@ + + + +#if(${enableCache}) + + +#end + +#if(${baseResultMap}) + + +#foreach($field in ${table.fields}) +#if(${field.keyFlag})##生成主键排在第一位 + +#end +#end +#foreach($field in ${table.commonFields})##生成公共字段 + +#end +#foreach($field in ${table.fields}) +#if(!${field.keyFlag})##生成普通字段 + +#end +#end + + +#end +#if(${baseColumnList}) + + +#foreach($field in ${table.commonFields}) + ${field.columnName}, +#end + ${table.fieldNames} + + +#end + diff --git a/library/skyeye-dev/skyeye-generator/src/main/resources/templates/service.java.vm b/library/skyeye-dev/skyeye-generator/src/main/resources/templates/service.java.vm new file mode 100644 index 0000000..818903a --- /dev/null +++ b/library/skyeye-dev/skyeye-generator/src/main/resources/templates/service.java.vm @@ -0,0 +1,24 @@ +package ${package.Service}; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.tiamo.dt.dev.db.pojo.page.PageParam; +import ${package.Entity}.${entity}; +import ${superServiceClassPackage}; + +/** + * $!{table.comment} 服务类 + * + * @author ${author} + * @since ${date} + */ +public interface ${table.serviceName} extends ${superServiceClass}<${entity}> { + + /** + * 通过实体类获取QueryWrapper + * @param pageParam 分页参数 + * @param $!{table.entityPath} 实体信息 + * @return + */ + QueryWrapper<$!{entity}> getQueryWrapper(PageParam pageParam, $!{entity} $!{table.entityPath}); + +} diff --git a/library/skyeye-dev/skyeye-generator/src/main/resources/templates/serviceImpl.java.vm b/library/skyeye-dev/skyeye-generator/src/main/resources/templates/serviceImpl.java.vm new file mode 100644 index 0000000..ddb67cb --- /dev/null +++ b/library/skyeye-dev/skyeye-generator/src/main/resources/templates/serviceImpl.java.vm @@ -0,0 +1,60 @@ +package ${package.ServiceImpl}; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.tiamo.dt.dev.db.pojo.page.PageParam; +import com.tiamo.dt.dev.db.utils.MPUtil; +import ${package.Entity}.${entity}; +import ${package.Mapper}.${table.mapperName}; +import ${package.Service}.${table.serviceName}; +import ${superServiceImplClassPackage}; +import org.springframework.stereotype.Service; + +/** + * $!{table.comment} 服务实现类 + * + * @author ${author} + * @since ${date} + */ +@Service +public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} { + + /** + * 通过实体类获取QueryWrapper + * @param pageParam 分页参数 + * @param $!{table.entityPath} 实体信息 + * @return + */ + @Override + public QueryWrapper<$!{entity}> getQueryWrapper(PageParam pageParam, $!{entity} $!{table.entityPath}){ + QueryWrapper<$!{entity}> queryWrapper = MPUtil.getQueryWrapper(pageParam); + + if($!{table.entityPath} == null){ + return queryWrapper; + } + +#foreach($field in ${table.fields}) +## 主键 +#if(${field.keyIdentityFlag}) + //主键 + if($!{table.entityPath}.get${field.capitalName}() != null){ + queryWrapper.lambda() + .eq($!{entity}::get${field.capitalName}, $!{table.entityPath}.get${field.capitalName}()); + return queryWrapper; + } +#end +#end + + //TODO 此处可以根据各字段查询需求修改查询条件,eq、like、ge、gt、le、lt、ne...等等等 + queryWrapper.lambda() +#foreach($field in ${table.fields}) +#if(!${field.keyIdentityFlag}) +#if($!{foreach.last}) + .eq($!{table.entityPath}.get${field.capitalName}() != null, $!{entity}::get${field.capitalName}, $!{table.entityPath}.get${field.capitalName}()); +#else + .eq($!{table.entityPath}.get${field.capitalName}() != null, $!{entity}::get${field.capitalName}, $!{table.entityPath}.get${field.capitalName}()) +#end +#end +#end + return queryWrapper; + } +} diff --git a/library/skyeye-dev/skyeye-generator/target/classes/com/zhangy/skyeye/generator/GeneratorApi$1.class b/library/skyeye-dev/skyeye-generator/target/classes/com/zhangy/skyeye/generator/GeneratorApi$1.class new file mode 100644 index 0000000..02457be Binary files /dev/null and b/library/skyeye-dev/skyeye-generator/target/classes/com/zhangy/skyeye/generator/GeneratorApi$1.class differ diff --git a/library/skyeye-dev/skyeye-generator/target/classes/com/zhangy/skyeye/generator/GeneratorApi$2.class b/library/skyeye-dev/skyeye-generator/target/classes/com/zhangy/skyeye/generator/GeneratorApi$2.class new file mode 100644 index 0000000..7e51bfd Binary files /dev/null and b/library/skyeye-dev/skyeye-generator/target/classes/com/zhangy/skyeye/generator/GeneratorApi$2.class differ diff --git a/library/skyeye-dev/skyeye-generator/target/classes/com/zhangy/skyeye/generator/GeneratorApi.class b/library/skyeye-dev/skyeye-generator/target/classes/com/zhangy/skyeye/generator/GeneratorApi.class new file mode 100644 index 0000000..16b501c Binary files /dev/null and b/library/skyeye-dev/skyeye-generator/target/classes/com/zhangy/skyeye/generator/GeneratorApi.class differ diff --git a/library/skyeye-dev/skyeye-generator/target/classes/templates/controller.java.vm b/library/skyeye-dev/skyeye-generator/target/classes/templates/controller.java.vm new file mode 100644 index 0000000..63bcbe9 --- /dev/null +++ b/library/skyeye-dev/skyeye-generator/target/classes/templates/controller.java.vm @@ -0,0 +1,134 @@ +package ${package.Controller}; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import org.springframework.web.bind.annotation.*; +#if(${restControllerStyle}) +#else +import org.springframework.stereotype.Controller; +#end + +#if(${superControllerClassPackage}) +import ${superControllerClassPackage}; +#end +#if(${swagger2}) +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +#end +#if(${entityLombokModel}) +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +#end + +import $!{package.Entity}.$!{entity}; +import $!{package.Service}.$!{table.serviceName}; +import result.pojo.com.zhangy.skyeye.common.Result; +import param.pojo.com.zhangy.skyeye.common.IdParam; +import com.tiamo.dt.dev.db.utils.MPUtil; +import com.tiamo.dt.dev.db.pojo.page.PageParam; + +import java.util.List; + +/** + * $!{table.comment} 前端控制器 + * + * @author ${author} + * @since ${date} + */ +#if(${restControllerStyle}) +@RestController +#else +@Controller +#end +@AllArgsConstructor +@Slf4j +@Api(value = "$!{table.comment}", tags = "$!{table.comment}接口") +@RequestMapping("#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end") +#if(${superControllerClass}) +public class ${table.controllerName} extends ${superControllerClass} { +#else +public class ${table.controllerName} { +#end + + private $!{table.serviceName} $!{table.entityPath}Service; + + /** + * 新增 + */ + @PostMapping("/save") + @ApiOperationSupport(order = 1) + @ApiOperation(value = "新增", notes = "传入$!{table.entityPath}") + public Result save(@RequestBody $!{entity} $!{table.entityPath}) { + if($!{table.entityPath} == null){ + return Result.error("参数异常"); + } + return Result.status($!{table.entityPath}Service.save($!{table.entityPath})); + } + + /** + * 修改 $!{table.comment} + */ + @PostMapping("/update") + @ApiOperationSupport(order = 2) + @ApiOperation(value = "修改", notes = "传入$!{table.entityPath}") + public Result update(@RequestBody $!{entity} $!{table.entityPath}) { + if($!{table.entityPath} == null){ + return Result.error("参数异常"); + } + return Result.status($!{table.entityPath}Service.updateById($!{table.entityPath})); + } + + /** + * 删除 $!{table.comment} + */ + @PostMapping("/remove") + @ApiOperationSupport(order = 3) + @ApiOperation(value = "删除", notes = "传入ids") + public Result remove(@RequestBody IdParam idParam) { + if(idParam == null){ + return Result.error("参数异常!"); + } + + return Result.status($!{table.entityPath}Service.removeByIds(idParam.getIds())); + } + + /** + * 详情 + */ + @GetMapping("/detail") + @ApiOperationSupport(order = 4) + @ApiOperation(value = "详情", notes = "传入id") + public Result<$!{entity}> detail(Long id) { + if(id == null){ + return Result.error("参数异常"); + } + $!{entity} detail = $!{table.entityPath}Service.getById(id); + return Result.successData(detail); + } + + /** + * 查询 $!{table.comment} + */ + @GetMapping("/list") + @ApiOperationSupport(order = 5) + @ApiOperation(value = "查询", notes = "传入$!{table.entityPath}") + public Result> list(PageParam pageParam, $!{entity} $!{table.entityPath}) { + List<$!{entity}> list = $!{table.entityPath}Service.list($!{table.entityPath}Service.getQueryWrapper(pageParam, $!{table.entityPath})); + return Result.successData(list); + } + + /** + * 分页 $!{table.comment} + */ + @GetMapping("/page") + @ApiOperationSupport(order = 6) + @ApiOperation(value = "分页", notes = "传入$!{table.entityPath}") + public Result> page(PageParam pageParam, $!{entity} $!{table.entityPath}) { + IPage<$!{entity}> pages = $!{table.entityPath}Service.page( + MPUtil.getPage(pageParam), + $!{table.entityPath}Service.getQueryWrapper(null, $!{table.entityPath}) + ); + return Result.successData(pages); + } + +} diff --git a/library/skyeye-dev/skyeye-generator/target/classes/templates/entity.java.vm b/library/skyeye-dev/skyeye-generator/target/classes/templates/entity.java.vm new file mode 100644 index 0000000..9031ae0 --- /dev/null +++ b/library/skyeye-dev/skyeye-generator/target/classes/templates/entity.java.vm @@ -0,0 +1,158 @@ +package ${package.Entity}; + +#foreach($pkg in ${table.importPackages}) +import ${pkg}; +#end +#if(${swagger2}) +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +#end +#if(${entityLombokModel}) +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +#if(${chainModel}) +import lombok.experimental.Accessors; +#end +#end + +/** + * $!{table.comment} + * + * @author ${author} + * @since ${date} + */ +#if(${entityLombokModel}) +@Data +@AllArgsConstructor +@NoArgsConstructor +#if(${superEntityClass}) +@EqualsAndHashCode(callSuper = true) +#else +@EqualsAndHashCode(callSuper = false) +#end +#if(${chainModel}) +@Accessors(chain = true) +#end +#end +#if(${table.convert}) +@TableName("${table.name}") +#end +#if(${swagger2}) +@ApiModel(value="${entity}对象", description="$!{table.comment}") +#end +#if(${superEntityClass}) +public class ${entity} extends ${superEntityClass}#if(${activeRecord})<${entity}>#end { +#elseif(${activeRecord}) +public class ${entity} extends Model<${entity}> { +#else +public class ${entity} implements Serializable { +#end + +#if(${entitySerialVersionUID}) + private static final long serialVersionUID = 1L; +#end +## ---------- BEGIN 字段循环遍历 ---------- +#foreach($field in ${table.fields}) + +#if(${field.keyFlag}) +#set($keyPropertyName=${field.propertyName}) +#end +#if("$!field.comment" != "") +#if(${swagger2}) + @ApiModelProperty(value = "${field.comment}", position = ${foreach.index}) +#else + /** + * ${field.comment} + */ +#end +#end +#if(${field.keyFlag}) +## 主键 +#if(${field.keyIdentityFlag}) + @TableId(value = "${field.annotationColumnName}", type = IdType.AUTO) +#elseif(!$null.isNull(${idType}) && "$!idType" != "") + @TableId(value = "${field.annotationColumnName}", type = IdType.${idType}) +#elseif(${field.convert}) + @TableId("${field.annotationColumnName}") +#end +## 普通字段 +#elseif(${field.fill}) +## ----- 存在字段填充设置 ----- +#if(${field.convert}) + @TableField(value = "${field.annotationColumnName}", fill = FieldFill.${field.fill}) +#else + @TableField(fill = FieldFill.${field.fill}) +#end +#elseif(${field.convert}) + @TableField("${field.annotationColumnName}") +#end +## 乐观锁注解 +#if(${versionFieldName}==${field.name}) + @Version +#end +## 逻辑删除注解 +#if(${logicDeleteFieldName}==${field.name}) + @TableLogic +#end + private ${field.propertyType} ${field.propertyName}; +#end +## ---------- END 字段循环遍历 ---------- +#if(!${entityLombokModel}) +#foreach($field in ${table.fields}) +#if(${field.propertyType.equals("boolean")}) +#set($getprefix="is") +#else +#set($getprefix="get") +#end + public ${field.propertyType} ${getprefix}${field.capitalName}() { + return ${field.propertyName}; + } +#if(${chainModel}) + public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) { +#else + public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) { +#end + this.${field.propertyName} = ${field.propertyName}; +#if(${chainModel}) + return this; +#end + } +#end +## --foreach end--- +#end +## --end of #if(!${entityLombokModel})-- +#if(${entityColumnConstant}) +#foreach($field in ${table.fields}) + public static final String ${field.name.toUpperCase()} = "${field.name}"; + +#end +#end +#if(${activeRecord}) + @Override + protected Serializable pkVal() { +#if(${keyPropertyName}) + return this.${keyPropertyName}; +#else + return null; +#end + } + +#end +#if(!${entityLombokModel}) + @Override + public String toString() { + return "${entity}{" + +#foreach($field in ${table.fields}) +#if($!{foreach.index}==0) + "${field.propertyName}=" + ${field.propertyName} + +#else + ", ${field.propertyName}=" + ${field.propertyName} + +#end +#end + "}"; + } +#end + +} diff --git a/library/skyeye-dev/skyeye-generator/target/classes/templates/mapper.java.vm b/library/skyeye-dev/skyeye-generator/target/classes/templates/mapper.java.vm new file mode 100644 index 0000000..101e157 --- /dev/null +++ b/library/skyeye-dev/skyeye-generator/target/classes/templates/mapper.java.vm @@ -0,0 +1,14 @@ +package ${package.Mapper}; + +import ${package.Entity}.${entity}; +import ${superMapperClassPackage}; + +/** + * $!{table.comment} Mapper 接口 + * + * @author ${author} + * @since ${date} + */ +public interface ${table.mapperName} extends ${superMapperClass}<${entity}> { + +} diff --git a/library/skyeye-dev/skyeye-generator/target/classes/templates/mapping.xml.vm b/library/skyeye-dev/skyeye-generator/target/classes/templates/mapping.xml.vm new file mode 100644 index 0000000..7a8e48d --- /dev/null +++ b/library/skyeye-dev/skyeye-generator/target/classes/templates/mapping.xml.vm @@ -0,0 +1,38 @@ + + + +#if(${enableCache}) + + +#end + +#if(${baseResultMap}) + + +#foreach($field in ${table.fields}) +#if(${field.keyFlag})##生成主键排在第一位 + +#end +#end +#foreach($field in ${table.commonFields})##生成公共字段 + +#end +#foreach($field in ${table.fields}) +#if(!${field.keyFlag})##生成普通字段 + +#end +#end + + +#end +#if(${baseColumnList}) + + +#foreach($field in ${table.commonFields}) + ${field.columnName}, +#end + ${table.fieldNames} + + +#end + diff --git a/library/skyeye-dev/skyeye-generator/target/classes/templates/service.java.vm b/library/skyeye-dev/skyeye-generator/target/classes/templates/service.java.vm new file mode 100644 index 0000000..818903a --- /dev/null +++ b/library/skyeye-dev/skyeye-generator/target/classes/templates/service.java.vm @@ -0,0 +1,24 @@ +package ${package.Service}; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.tiamo.dt.dev.db.pojo.page.PageParam; +import ${package.Entity}.${entity}; +import ${superServiceClassPackage}; + +/** + * $!{table.comment} 服务类 + * + * @author ${author} + * @since ${date} + */ +public interface ${table.serviceName} extends ${superServiceClass}<${entity}> { + + /** + * 通过实体类获取QueryWrapper + * @param pageParam 分页参数 + * @param $!{table.entityPath} 实体信息 + * @return + */ + QueryWrapper<$!{entity}> getQueryWrapper(PageParam pageParam, $!{entity} $!{table.entityPath}); + +} diff --git a/library/skyeye-dev/skyeye-generator/target/classes/templates/serviceImpl.java.vm b/library/skyeye-dev/skyeye-generator/target/classes/templates/serviceImpl.java.vm new file mode 100644 index 0000000..ddb67cb --- /dev/null +++ b/library/skyeye-dev/skyeye-generator/target/classes/templates/serviceImpl.java.vm @@ -0,0 +1,60 @@ +package ${package.ServiceImpl}; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.tiamo.dt.dev.db.pojo.page.PageParam; +import com.tiamo.dt.dev.db.utils.MPUtil; +import ${package.Entity}.${entity}; +import ${package.Mapper}.${table.mapperName}; +import ${package.Service}.${table.serviceName}; +import ${superServiceImplClassPackage}; +import org.springframework.stereotype.Service; + +/** + * $!{table.comment} 服务实现类 + * + * @author ${author} + * @since ${date} + */ +@Service +public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} { + + /** + * 通过实体类获取QueryWrapper + * @param pageParam 分页参数 + * @param $!{table.entityPath} 实体信息 + * @return + */ + @Override + public QueryWrapper<$!{entity}> getQueryWrapper(PageParam pageParam, $!{entity} $!{table.entityPath}){ + QueryWrapper<$!{entity}> queryWrapper = MPUtil.getQueryWrapper(pageParam); + + if($!{table.entityPath} == null){ + return queryWrapper; + } + +#foreach($field in ${table.fields}) +## 主键 +#if(${field.keyIdentityFlag}) + //主键 + if($!{table.entityPath}.get${field.capitalName}() != null){ + queryWrapper.lambda() + .eq($!{entity}::get${field.capitalName}, $!{table.entityPath}.get${field.capitalName}()); + return queryWrapper; + } +#end +#end + + //TODO 此处可以根据各字段查询需求修改查询条件,eq、like、ge、gt、le、lt、ne...等等等 + queryWrapper.lambda() +#foreach($field in ${table.fields}) +#if(!${field.keyIdentityFlag}) +#if($!{foreach.last}) + .eq($!{table.entityPath}.get${field.capitalName}() != null, $!{entity}::get${field.capitalName}, $!{table.entityPath}.get${field.capitalName}()); +#else + .eq($!{table.entityPath}.get${field.capitalName}() != null, $!{entity}::get${field.capitalName}, $!{table.entityPath}.get${field.capitalName}()) +#end +#end +#end + return queryWrapper; + } +} diff --git a/library/skyeye-dev/skyeye-generator/target/maven-archiver/pom.properties b/library/skyeye-dev/skyeye-generator/target/maven-archiver/pom.properties new file mode 100644 index 0000000..68fd68e --- /dev/null +++ b/library/skyeye-dev/skyeye-generator/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=skyeye-generator +groupId=com.zhangy +version=1.0.0.RELEASE diff --git a/library/skyeye-dev/skyeye-generator/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/library/skyeye-dev/skyeye-generator/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..1755832 --- /dev/null +++ b/library/skyeye-dev/skyeye-generator/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,3 @@ +com\zhangy\skyeye\generator\GeneratorApi.class +com\zhangy\skyeye\generator\GeneratorApi$2.class +com\zhangy\skyeye\generator\GeneratorApi$1.class diff --git a/library/skyeye-dev/skyeye-generator/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/library/skyeye-dev/skyeye-generator/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..24e52dc --- /dev/null +++ b/library/skyeye-dev/skyeye-generator/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1 @@ +D:\logisen\ddd\skyeye-dev\skyeye-generator\src\main\java\com\zhangy\skyeye\generator\GeneratorApi.java diff --git a/library/skyeye-dev/skyeye-generator/target/skyeye-generator-1.0.0.RELEASE.jar b/library/skyeye-dev/skyeye-generator/target/skyeye-generator-1.0.0.RELEASE.jar new file mode 100644 index 0000000..291eaab Binary files /dev/null and b/library/skyeye-dev/skyeye-generator/target/skyeye-generator-1.0.0.RELEASE.jar differ diff --git a/library/skyeye-dev/skyeye-job/pom.xml b/library/skyeye-dev/skyeye-job/pom.xml new file mode 100644 index 0000000..a04d7eb --- /dev/null +++ b/library/skyeye-dev/skyeye-job/pom.xml @@ -0,0 +1,42 @@ + + + + skyeye-dev + com.zhangy + 1.0.0.RELEASE + + 4.0.0 + + skyeye-job + + + + + + org.projectlombok + lombok + + + + + org.springframework.boot + spring-boot-starter + + + + + com.xuxueli + xxl-job-core + 2.3.1 + + + + + org.springframework.cloud + spring-cloud-commons + + + + \ No newline at end of file diff --git a/library/skyeye-dev/skyeye-job/src/main/java/com/zhangy/skyeye/job/XxlJobAutoConfiguration.java b/library/skyeye-dev/skyeye-job/src/main/java/com/zhangy/skyeye/job/XxlJobAutoConfiguration.java new file mode 100644 index 0000000..28e4e11 --- /dev/null +++ b/library/skyeye-dev/skyeye-job/src/main/java/com/zhangy/skyeye/job/XxlJobAutoConfiguration.java @@ -0,0 +1,68 @@ +package com.zhangy.skyeye.job; + +import com.zhangy.skyeye.job.properties.XxlExecutorProperties; +import com.zhangy.skyeye.job.properties.XxlJobProperties; +import com.xxl.job.core.executor.impl.XxlJobSpringExecutor; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cloud.client.discovery.DiscoveryClient; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; +import org.springframework.util.StringUtils; + +import java.util.stream.Collectors; + +/** + * xxl-job自动装配 + */ +@Configuration(proxyBeanMethods = false) +@EnableAutoConfiguration +@EnableConfigurationProperties(XxlJobProperties.class) +public class XxlJobAutoConfiguration { + + /** + * 服务名称 包含 XXL_JOB_ADMIN 则说明是 Admin + */ + private static final String XXL_JOB_ADMIN = "xxl-job-admin"; + + /** + * 配置xxl-job 执行器,提供自动发现 xxl-job-admin 能力 + * + * @param xxlJobProperties xxl 配置 + * @param environment 环境变量 + * @param discoveryClient 注册发现客户端 + * @return + */ + @Bean + public XxlJobSpringExecutor xxlJobSpringExecutor(XxlJobProperties xxlJobProperties, Environment environment, + DiscoveryClient discoveryClient) { + XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor(); + XxlExecutorProperties executor = xxlJobProperties.getExecutor(); + // 应用名默认为服务名 + String appName = executor.getAppname(); + if (!StringUtils.hasText(appName)) { + appName = environment.getProperty("spring.application.name"); + } + xxlJobSpringExecutor.setAppname(appName); + xxlJobSpringExecutor.setAddress(executor.getAddress()); + xxlJobSpringExecutor.setIp(executor.getIp()); + xxlJobSpringExecutor.setPort(executor.getPort()); + xxlJobSpringExecutor.setAccessToken(executor.getAccessToken()); + xxlJobSpringExecutor.setLogPath(executor.getLogPath()); + xxlJobSpringExecutor.setLogRetentionDays(executor.getLogRetentionDays()); + + if (!StringUtils.hasText(xxlJobProperties.getAdmin().getAddresses())) { + String serverList = discoveryClient.getServices().stream().filter(s -> s.contains(XXL_JOB_ADMIN)) + .flatMap(s -> discoveryClient.getInstances(s).stream()).map(instance -> String + .format("http://%s:%s/%s", instance.getHost(), instance.getPort(), XXL_JOB_ADMIN)) + .collect(Collectors.joining(",")); + xxlJobSpringExecutor.setAdminAddresses(serverList); + } else { + xxlJobSpringExecutor.setAdminAddresses(xxlJobProperties.getAdmin().getAddresses()); + } + + return xxlJobSpringExecutor; + } + +} diff --git a/library/skyeye-dev/skyeye-job/src/main/java/com/zhangy/skyeye/job/annotation/EnableDtXxlJob.java b/library/skyeye-dev/skyeye-job/src/main/java/com/zhangy/skyeye/job/annotation/EnableDtXxlJob.java new file mode 100644 index 0000000..2d55427 --- /dev/null +++ b/library/skyeye-dev/skyeye-job/src/main/java/com/zhangy/skyeye/job/annotation/EnableDtXxlJob.java @@ -0,0 +1,15 @@ +package com.zhangy.skyeye.job.annotation; + +import com.zhangy.skyeye.job.XxlJobAutoConfiguration; +import org.springframework.context.annotation.Import; + +import java.lang.annotation.*; + +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@Import({XxlJobAutoConfiguration.class}) +public @interface EnableDtXxlJob { + +} diff --git a/library/skyeye-dev/skyeye-job/src/main/java/com/zhangy/skyeye/job/properties/XxlAdminProperties.java b/library/skyeye-dev/skyeye-job/src/main/java/com/zhangy/skyeye/job/properties/XxlAdminProperties.java new file mode 100644 index 0000000..63a7e47 --- /dev/null +++ b/library/skyeye-dev/skyeye-job/src/main/java/com/zhangy/skyeye/job/properties/XxlAdminProperties.java @@ -0,0 +1,16 @@ +package com.zhangy.skyeye.job.properties; + +import lombok.Data; + +/** + * xxl-job管理平台配置 + */ +@Data +public class XxlAdminProperties { + + /** + * 调度中心部署跟地址 [选填]:如调度中心集群部署存在多个地址则用逗号分隔。 执行器将会使用该地址进行"执行器心跳注册"和"任务结果回调";为空则关闭自动注册; + */ + private String addresses; + +} diff --git a/library/skyeye-dev/skyeye-job/src/main/java/com/zhangy/skyeye/job/properties/XxlExecutorProperties.java b/library/skyeye-dev/skyeye-job/src/main/java/com/zhangy/skyeye/job/properties/XxlExecutorProperties.java new file mode 100644 index 0000000..8fc207c --- /dev/null +++ b/library/skyeye-dev/skyeye-job/src/main/java/com/zhangy/skyeye/job/properties/XxlExecutorProperties.java @@ -0,0 +1,47 @@ +package com.zhangy.skyeye.job.properties; + +import lombok.Data; + +/** + * xxl-job执行器配置 + */ +@Data +public class XxlExecutorProperties { + + /** + * 执行器AppName [选填]:执行器心跳注册分组依据;为空则关闭自动注册 + */ + private String appname; + + /** + * 服务注册地址,优先使用该配置作为注册地址 为空时使用内嵌服务 ”IP:PORT“ 作为注册地址 从而更灵活的支持容器类型执行器动态IP和动态映射端口问题 + */ + private String address; + + /** + * 执行器IP [选填]:默认为空表示自动获取IP,多网卡时可手动设置指定IP ,该IP不会绑定Host仅作为通讯实用;地址信息用于 "执行器注册" 和 + * "调度中心请求并触发任务" + */ + private String ip; + + /** + * 执行器端口号 [选填]:小于等于0则自动获取;默认端口为9099,单机部署多个执行器时,注意要配置不同执行器端口; + */ + private Integer port = 9099; + + /** + * 执行器通讯TOKEN [选填]:非空时启用; + */ + private String accessToken; + + /** + * 执行器运行日志文件存储磁盘路径 [选填] :需要对该路径拥有读写权限;为空则使用默认路径; + */ + private String logPath = "logs/applogs/xxl-job/jobhandler"; + + /** + * 执行器日志保存天数 [选填] :值大于3时生效,启用执行器Log文件定期清理功能,否则不生效; + */ + private Integer logRetentionDays = 30; + +} diff --git a/library/skyeye-dev/skyeye-job/src/main/java/com/zhangy/skyeye/job/properties/XxlJobProperties.java b/library/skyeye-dev/skyeye-job/src/main/java/com/zhangy/skyeye/job/properties/XxlJobProperties.java new file mode 100644 index 0000000..84c325b --- /dev/null +++ b/library/skyeye-dev/skyeye-job/src/main/java/com/zhangy/skyeye/job/properties/XxlJobProperties.java @@ -0,0 +1,20 @@ +package com.zhangy.skyeye.job.properties; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.NestedConfigurationProperty; + +/** + * xxl-job配置 + */ +@Data +@ConfigurationProperties(prefix = "xxl.job") +public class XxlJobProperties { + + @NestedConfigurationProperty + private XxlAdminProperties admin = new XxlAdminProperties(); + + @NestedConfigurationProperty + private XxlExecutorProperties executor = new XxlExecutorProperties(); + +} diff --git a/library/skyeye-dev/skyeye-job/target/classes/com/zhangy/skyeye/job/XxlJobAutoConfiguration.class b/library/skyeye-dev/skyeye-job/target/classes/com/zhangy/skyeye/job/XxlJobAutoConfiguration.class new file mode 100644 index 0000000..bc812a6 Binary files /dev/null and b/library/skyeye-dev/skyeye-job/target/classes/com/zhangy/skyeye/job/XxlJobAutoConfiguration.class differ diff --git a/library/skyeye-dev/skyeye-job/target/classes/com/zhangy/skyeye/job/annotation/EnableDtXxlJob.class b/library/skyeye-dev/skyeye-job/target/classes/com/zhangy/skyeye/job/annotation/EnableDtXxlJob.class new file mode 100644 index 0000000..437b9f1 Binary files /dev/null and b/library/skyeye-dev/skyeye-job/target/classes/com/zhangy/skyeye/job/annotation/EnableDtXxlJob.class differ diff --git a/library/skyeye-dev/skyeye-job/target/classes/com/zhangy/skyeye/job/properties/XxlAdminProperties.class b/library/skyeye-dev/skyeye-job/target/classes/com/zhangy/skyeye/job/properties/XxlAdminProperties.class new file mode 100644 index 0000000..6801e23 Binary files /dev/null and b/library/skyeye-dev/skyeye-job/target/classes/com/zhangy/skyeye/job/properties/XxlAdminProperties.class differ diff --git a/library/skyeye-dev/skyeye-job/target/classes/com/zhangy/skyeye/job/properties/XxlExecutorProperties.class b/library/skyeye-dev/skyeye-job/target/classes/com/zhangy/skyeye/job/properties/XxlExecutorProperties.class new file mode 100644 index 0000000..3129b50 Binary files /dev/null and b/library/skyeye-dev/skyeye-job/target/classes/com/zhangy/skyeye/job/properties/XxlExecutorProperties.class differ diff --git a/library/skyeye-dev/skyeye-job/target/classes/com/zhangy/skyeye/job/properties/XxlJobProperties.class b/library/skyeye-dev/skyeye-job/target/classes/com/zhangy/skyeye/job/properties/XxlJobProperties.class new file mode 100644 index 0000000..8ca0c14 Binary files /dev/null and b/library/skyeye-dev/skyeye-job/target/classes/com/zhangy/skyeye/job/properties/XxlJobProperties.class differ diff --git a/library/skyeye-dev/skyeye-job/target/maven-archiver/pom.properties b/library/skyeye-dev/skyeye-job/target/maven-archiver/pom.properties new file mode 100644 index 0000000..b34cda6 --- /dev/null +++ b/library/skyeye-dev/skyeye-job/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=skyeye-job +groupId=com.zhangy +version=1.0.0.RELEASE diff --git a/library/skyeye-dev/skyeye-job/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/library/skyeye-dev/skyeye-job/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..f830209 --- /dev/null +++ b/library/skyeye-dev/skyeye-job/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,5 @@ +com\zhangy\skyeye\job\properties\XxlAdminProperties.class +com\zhangy\skyeye\job\annotation\EnableDtXxlJob.class +com\zhangy\skyeye\job\properties\XxlJobProperties.class +com\zhangy\skyeye\job\properties\XxlExecutorProperties.class +com\zhangy\skyeye\job\XxlJobAutoConfiguration.class diff --git a/library/skyeye-dev/skyeye-job/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/library/skyeye-dev/skyeye-job/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..7e277d5 --- /dev/null +++ b/library/skyeye-dev/skyeye-job/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,5 @@ +D:\logisen\ddd\skyeye-dev\skyeye-job\src\main\java\com\zhangy\skyeye\job\properties\XxlExecutorProperties.java +D:\logisen\ddd\skyeye-dev\skyeye-job\src\main\java\com\zhangy\skyeye\job\properties\XxlAdminProperties.java +D:\logisen\ddd\skyeye-dev\skyeye-job\src\main\java\com\zhangy\skyeye\job\XxlJobAutoConfiguration.java +D:\logisen\ddd\skyeye-dev\skyeye-job\src\main\java\com\zhangy\skyeye\job\properties\XxlJobProperties.java +D:\logisen\ddd\skyeye-dev\skyeye-job\src\main\java\com\zhangy\skyeye\job\annotation\EnableDtXxlJob.java diff --git a/library/skyeye-dev/skyeye-job/target/skyeye-job-1.0.0.RELEASE.jar b/library/skyeye-dev/skyeye-job/target/skyeye-job-1.0.0.RELEASE.jar new file mode 100644 index 0000000..ba2707a Binary files /dev/null and b/library/skyeye-dev/skyeye-job/target/skyeye-job-1.0.0.RELEASE.jar differ diff --git a/library/skyeye-dev/skyeye-knife4j/pom.xml b/library/skyeye-dev/skyeye-knife4j/pom.xml new file mode 100644 index 0000000..5d9a0ce --- /dev/null +++ b/library/skyeye-dev/skyeye-knife4j/pom.xml @@ -0,0 +1,38 @@ + + + + + skyeye-dev + com.zhangy + 1.0.0.RELEASE + + 4.0.0 + + skyeye-knife4j + skyeye knife4j lib + + + + + + org.springframework.boot + spring-boot-starter + + + + + com.github.xiaoymin + knife4j-micro-spring-boot-starter + + + + + org.projectlombok + lombok + + + + + \ No newline at end of file diff --git a/library/skyeye-dev/skyeye-knife4j/src/main/java/com/zhangy/skyeye/knife4j/config/DTKnife4jConfig.java b/library/skyeye-dev/skyeye-knife4j/src/main/java/com/zhangy/skyeye/knife4j/config/DTKnife4jConfig.java new file mode 100644 index 0000000..487f45d --- /dev/null +++ b/library/skyeye-dev/skyeye-knife4j/src/main/java/com/zhangy/skyeye/knife4j/config/DTKnife4jConfig.java @@ -0,0 +1,93 @@ +package com.zhangy.skyeye.knife4j.config; + +import com.zhangy.skyeye.knife4j.props.Knife4jProperties; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.core.annotation.Order; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; + +@Configuration +@Import(DTKnife4jPropertiesAutoConfig.class) +@EnableSwagger2WebMvc +public class DTKnife4jConfig { + + @Autowired + Knife4jProperties knife4jProperties; + + @Bean(value = "restApi") + @Order(value = 1) + public Docket groupRestApi() { + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(groupApiInfo()) + .host(knife4jProperties.getHost()) + .select() + .apis(RequestHandlerSelectors.basePackage(knife4jProperties.getBasePackage())) + .paths(PathSelectors.any()) + .build(); + } + + private ApiInfo groupApiInfo(){ + return new ApiInfoBuilder() + .title(knife4jProperties.getTitle()) + .description(knife4jProperties.getDescription()) + .termsOfServiceUrl("www.tiamotech.com") + .version(knife4jProperties.getVersion()) + .contact(new Contact("tiamo", "www.tiamotech.com", "tiamo@tiamotech.com")) + .build(); + } + + // /** +// * 解决springboot升级到2.6.x之后,与spring-boot-starter-actuator同时使用时,knife4j报错问题 +// * +// * @param webEndpointsSupplier the web endpoints supplier +// * @param servletEndpointsSupplier the servlet endpoints supplier +// * @param controllerEndpointsSupplier the controller endpoints supplier +// * @param endpointMediaTypes the endpoint media types +// * @param corsProperties the cors properties +// * @param webEndpointProperties the web endpoint properties +// * @param environment the environment +// * @return the web mvc endpoint handler mapping +// */ +// @Bean +// public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping( +// WebEndpointsSupplier webEndpointsSupplier, ServletEndpointsSupplier servletEndpointsSupplier, +// ControllerEndpointsSupplier controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes, +// CorsEndpointProperties corsProperties, WebEndpointProperties webEndpointProperties, +// Environment environment) { +// List> allEndpoints = new ArrayList<>(); +// Collection webEndpoints = webEndpointsSupplier.getEndpoints(); +// allEndpoints.addAll(webEndpoints); +// allEndpoints.addAll(servletEndpointsSupplier.getEndpoints()); +// allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints()); +// String basePath = webEndpointProperties.getBasePath(); +// EndpointMapping endpointMapping = new EndpointMapping(basePath); +// boolean shouldRegisterLinksMapping = shouldRegisterLinksMapping(webEndpointProperties, +// environment, basePath); +// return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes, +// corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath), +// shouldRegisterLinksMapping, null); +// } +// +// /** +// * shouldRegisterLinksMapping +// * +// * @param webEndpointProperties webEndpointProperties +// * @param environment environment +// * @param basePath / +// * @return boolean +// */ +// private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, +// Environment environment, String basePath) { +// return webEndpointProperties.getDiscovery().isEnabled() && (StringUtils.hasText(basePath) +// || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT)); +// } +} diff --git a/library/skyeye-dev/skyeye-knife4j/src/main/java/com/zhangy/skyeye/knife4j/config/DTKnife4jPropertiesAutoConfig.java b/library/skyeye-dev/skyeye-knife4j/src/main/java/com/zhangy/skyeye/knife4j/config/DTKnife4jPropertiesAutoConfig.java new file mode 100644 index 0000000..6b275c0 --- /dev/null +++ b/library/skyeye-dev/skyeye-knife4j/src/main/java/com/zhangy/skyeye/knife4j/config/DTKnife4jPropertiesAutoConfig.java @@ -0,0 +1,27 @@ +package com.zhangy.skyeye.knife4j.config; + +import com.zhangy.skyeye.knife4j.props.Knife4jProperties; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * 数据库连接和DAO框架的配置 + */ +@Configuration +@AutoConfigureBefore(Knife4jProperties.class) +public class DTKnife4jPropertiesAutoConfig { + + /** + * Knife4j + */ + @Bean + @ConfigurationProperties(prefix = "tiamo.knife4j") + @ConditionalOnMissingBean(Knife4jProperties.class) + public Knife4jProperties druidProperties() { + return new Knife4jProperties(); + } + +} diff --git a/library/skyeye-dev/skyeye-knife4j/src/main/java/com/zhangy/skyeye/knife4j/props/Knife4jProperties.java b/library/skyeye-dev/skyeye-knife4j/src/main/java/com/zhangy/skyeye/knife4j/props/Knife4jProperties.java new file mode 100644 index 0000000..0961191 --- /dev/null +++ b/library/skyeye-dev/skyeye-knife4j/src/main/java/com/zhangy/skyeye/knife4j/props/Knife4jProperties.java @@ -0,0 +1,24 @@ +package com.zhangy.skyeye.knife4j.props; + +import lombok.Data; + +/** + * knife4j配置配置信息 + */ +@Data +public class Knife4jProperties { + + /** + * Controller包根路径 + */ + private String basePackage; + + private String title; + + private String description; + + private String version; + + private String host; + +} diff --git a/library/skyeye-dev/skyeye-knife4j/src/main/resources/META-INF/spring.factories b/library/skyeye-dev/skyeye-knife4j/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..f0452cf --- /dev/null +++ b/library/skyeye-dev/skyeye-knife4j/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.tiamo.dt.dev.knife4j.config.DTKnife4jPropertiesAutoConfig,\ + com.tiamo.dt.dev.knife4j.config.DTKnife4jConfig diff --git a/library/skyeye-dev/skyeye-knife4j/src/main/resources/bootstrap.yml b/library/skyeye-dev/skyeye-knife4j/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..1b64ce0 --- /dev/null +++ b/library/skyeye-dev/skyeye-knife4j/src/main/resources/bootstrap.yml @@ -0,0 +1,2 @@ +knife4j: + enable: true \ No newline at end of file diff --git a/library/skyeye-dev/skyeye-knife4j/target/classes/META-INF/spring.factories b/library/skyeye-dev/skyeye-knife4j/target/classes/META-INF/spring.factories new file mode 100644 index 0000000..f0452cf --- /dev/null +++ b/library/skyeye-dev/skyeye-knife4j/target/classes/META-INF/spring.factories @@ -0,0 +1,3 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.tiamo.dt.dev.knife4j.config.DTKnife4jPropertiesAutoConfig,\ + com.tiamo.dt.dev.knife4j.config.DTKnife4jConfig diff --git a/library/skyeye-dev/skyeye-knife4j/target/classes/bootstrap.yml b/library/skyeye-dev/skyeye-knife4j/target/classes/bootstrap.yml new file mode 100644 index 0000000..1b64ce0 --- /dev/null +++ b/library/skyeye-dev/skyeye-knife4j/target/classes/bootstrap.yml @@ -0,0 +1,2 @@ +knife4j: + enable: true \ No newline at end of file diff --git a/library/skyeye-dev/skyeye-knife4j/target/classes/com/zhangy/skyeye/knife4j/config/DTKnife4jConfig.class b/library/skyeye-dev/skyeye-knife4j/target/classes/com/zhangy/skyeye/knife4j/config/DTKnife4jConfig.class new file mode 100644 index 0000000..9076076 Binary files /dev/null and b/library/skyeye-dev/skyeye-knife4j/target/classes/com/zhangy/skyeye/knife4j/config/DTKnife4jConfig.class differ diff --git a/library/skyeye-dev/skyeye-knife4j/target/classes/com/zhangy/skyeye/knife4j/config/DTKnife4jPropertiesAutoConfig.class b/library/skyeye-dev/skyeye-knife4j/target/classes/com/zhangy/skyeye/knife4j/config/DTKnife4jPropertiesAutoConfig.class new file mode 100644 index 0000000..779de2e Binary files /dev/null and b/library/skyeye-dev/skyeye-knife4j/target/classes/com/zhangy/skyeye/knife4j/config/DTKnife4jPropertiesAutoConfig.class differ diff --git a/library/skyeye-dev/skyeye-knife4j/target/classes/com/zhangy/skyeye/knife4j/props/Knife4jProperties.class b/library/skyeye-dev/skyeye-knife4j/target/classes/com/zhangy/skyeye/knife4j/props/Knife4jProperties.class new file mode 100644 index 0000000..5040e24 Binary files /dev/null and b/library/skyeye-dev/skyeye-knife4j/target/classes/com/zhangy/skyeye/knife4j/props/Knife4jProperties.class differ diff --git a/library/skyeye-dev/skyeye-knife4j/target/maven-archiver/pom.properties b/library/skyeye-dev/skyeye-knife4j/target/maven-archiver/pom.properties new file mode 100644 index 0000000..652427c --- /dev/null +++ b/library/skyeye-dev/skyeye-knife4j/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=skyeye-knife4j +groupId=com.zhangy +version=1.0.0.RELEASE diff --git a/library/skyeye-dev/skyeye-knife4j/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/library/skyeye-dev/skyeye-knife4j/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..51fa8bc --- /dev/null +++ b/library/skyeye-dev/skyeye-knife4j/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,3 @@ +com\zhangy\skyeye\knife4j\config\DTKnife4jPropertiesAutoConfig.class +com\zhangy\skyeye\knife4j\props\Knife4jProperties.class +com\zhangy\skyeye\knife4j\config\DTKnife4jConfig.class diff --git a/library/skyeye-dev/skyeye-knife4j/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/library/skyeye-dev/skyeye-knife4j/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..16eb8d3 --- /dev/null +++ b/library/skyeye-dev/skyeye-knife4j/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,3 @@ +D:\logisen\ddd\skyeye-dev\skyeye-knife4j\src\main\java\com\zhangy\skyeye\knife4j\config\DTKnife4jPropertiesAutoConfig.java +D:\logisen\ddd\skyeye-dev\skyeye-knife4j\src\main\java\com\zhangy\skyeye\knife4j\config\DTKnife4jConfig.java +D:\logisen\ddd\skyeye-dev\skyeye-knife4j\src\main\java\com\zhangy\skyeye\knife4j\props\Knife4jProperties.java diff --git a/library/skyeye-dev/skyeye-knife4j/target/skyeye-knife4j-1.0.0.RELEASE.jar b/library/skyeye-dev/skyeye-knife4j/target/skyeye-knife4j-1.0.0.RELEASE.jar new file mode 100644 index 0000000..bf74c54 Binary files /dev/null and b/library/skyeye-dev/skyeye-knife4j/target/skyeye-knife4j-1.0.0.RELEASE.jar differ diff --git a/library/skyeye-dev/skyeye-quartz/pom.xml b/library/skyeye-dev/skyeye-quartz/pom.xml new file mode 100644 index 0000000..311f7e2 --- /dev/null +++ b/library/skyeye-dev/skyeye-quartz/pom.xml @@ -0,0 +1,50 @@ + + + + skyeye-dev + com.zhangy + 1.0.0.RELEASE + + 4.0.0 + + skyeye-quartz + skyeye Quartz lib + + + + + + + + + + + + + + + org.springframework.boot + spring-boot-starter-quartz + + + + + + org.projectlombok + lombok + + + + \ No newline at end of file diff --git a/library/skyeye-dev/skyeye-quartz/src/main/java/com/zhangy/skyeye/quartz/config/QuartzConfig.java b/library/skyeye-dev/skyeye-quartz/src/main/java/com/zhangy/skyeye/quartz/config/QuartzConfig.java new file mode 100644 index 0000000..4bee559 --- /dev/null +++ b/library/skyeye-dev/skyeye-quartz/src/main/java/com/zhangy/skyeye/quartz/config/QuartzConfig.java @@ -0,0 +1,98 @@ +package com.zhangy.skyeye.quartz.config; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.quartz.QuartzProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.quartz.SchedulerFactoryBean; + +import javax.sql.DataSource; +import java.util.Map; +import java.util.Properties; + +/** + * 定时任务配置 + */ +@Configuration +@Slf4j +public class QuartzConfig { + + @Value("${spring.application.name}") + private String applicationName; + + @Value("${spring.quartz.overwrite-existing-jobs:true}") + private boolean overwriteExistingJobs; + + @Value("${spring.quartz.auto-startup:true}") + private boolean autoStartup; + + @Bean + public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource, QuartzProperties properties) { + log.info("init quartz properties start...."); + /*log.info("startup:{},{},{}", properties.getStartupDelay(), properties.getStartupDelay().isNegative(), properties.getStartupDelay().isZero());*/ + SchedulerFactoryBean factory = new SchedulerFactoryBean(); + factory.setDataSource(dataSource); + + // quartz参数 + Properties prop = initQuartzProperties(properties.getProperties()); + factory.setQuartzProperties(prop); + + if (properties.getSchedulerName() == null) { + properties.setSchedulerName("DTScheduler(" + applicationName + ")"); + } + + // 可选,QuartzScheduler + // 启ob,这样动时更新己存在的J就不用每次修改targetObject后删除qrtz_job_details表对应记录了 + factory.setOverwriteExistingJobs(overwriteExistingJobs); + // 设置自动启动,默认为true + factory.setAutoStartup(autoStartup); +/* + factory.setSchedulerName("DTScheduler(" + applicationName + ")"); + // 延时启动 + factory.setStartupDelay(1); + factory.setApplicationContextSchedulerContextKey("applicationContextKey"); + // 可选,QuartzScheduler + // 启ob,这样动时更新己存在的J就不用每次修改targetObject后删除qrtz_job_details表对应记录了 + factory.setOverwriteExistingJobs(true); + // 设置自动启动,默认为true + factory.setAutoStartup(true); +*/ + return factory; + } + + private Properties initQuartzProperties(Map properties) { + Properties initProp = new Properties(); + initProp.put("org.quartz.scheduler.instanceName", "DTScheduler(" + applicationName + ")"); + initProp.put("org.quartz.scheduler.instanceId", "AUTO"); + // 线程池配置 + initProp.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool"); + initProp.put("org.quartz.threadPool.threadCount", "20"); + initProp.put("org.quartz.threadPool.threadPriority", "5"); + //initProp.put("org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread:", "true"); + // JobStore配置 +// initProp.put("org.quartz.jobStore.class", "org.quartz.impl.jdbcjobstore.JobStoreTX"); + // 集群配置 + initProp.put("org.quartz.jobStore.isClustered", "true"); + initProp.put("org.quartz.jobStore.clusterCheckinInterval", "15000"); + initProp.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1"); + initProp.put("org.quartz.jobStore.txIsolationLevelSerializable", "true"); + + // sqlserver 启用 + // initProp.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?"); + initProp.put("org.quartz.jobStore.misfireThreshold", "12000"); + initProp.put("org.quartz.jobStore.tablePrefix", "QRTZ_"); + //判断其他属性 + if (properties.isEmpty()) { + return initProp; + } + //如果本地或nacos配置文件上有值,覆盖原有值 + initProp.forEach((k, v) -> { + if (properties.containsKey(k)) { + //log.info("该key:{},有值:{}",k,properties.get(k)); + initProp.put(k, properties.get(k)); + } + }); + return initProp; + } +} diff --git a/library/skyeye-dev/skyeye-quartz/src/main/java/com/zhangy/skyeye/quartz/util/CronUtils.java b/library/skyeye-dev/skyeye-quartz/src/main/java/com/zhangy/skyeye/quartz/util/CronUtils.java new file mode 100644 index 0000000..9c0ceff --- /dev/null +++ b/library/skyeye-dev/skyeye-quartz/src/main/java/com/zhangy/skyeye/quartz/util/CronUtils.java @@ -0,0 +1,73 @@ +package com.zhangy.skyeye.quartz.util; + +import org.quartz.CronExpression; +import org.quartz.TriggerUtils; +import org.quartz.impl.triggers.CronTriggerImpl; + +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * cron表达式工具类 + */ +public class CronUtils { + /** + * 返回一个布尔值代表一个给定的Cron表达式的有效性 + * + * @param cronExpression Cron表达式 + * @return boolean 表达式是否有效 + */ + public static boolean isValid(String cronExpression) { + return CronExpression.isValidExpression(cronExpression); + } + + /** + * 返回一个字符串值,表示该消息无效Cron表达式给出有效性 + * + * @param cronExpression Cron表达式 + * @return String 无效时返回表达式错误描述,如果有效返回null + */ + public static String getInvalidMessage(String cronExpression) { + try { + new CronExpression(cronExpression); + return null; + } catch (ParseException pe) { + return pe.getMessage(); + } + } + + /** + * 返回下一个执行时间根据给定的Cron表达式 + * + * @param cronExpression Cron表达式 + * @return Date 下次Cron表达式执行时间 + */ + public static Date getNextExecution(String cronExpression) { + try { + CronExpression cron = new CronExpression(cronExpression); + return cron.getNextValidTimeAfter(new Date(System.currentTimeMillis())); + } catch (ParseException e) { + throw new IllegalArgumentException(e.getMessage()); + } + } + + /** + * 通过表达式获取近10次的执行时间 + * + * @param cron 表达式 + * @return 时间列表 + */ + public static List getRecentTriggerTime(String cron) { + List list = new ArrayList<>(); + try { + CronTriggerImpl cronTriggerImpl = new CronTriggerImpl(); + cronTriggerImpl.setCronExpression(cron); + List dates = TriggerUtils.computeFireTimes(cronTriggerImpl, null, 10); + } catch (ParseException e) { + return null; + } + return list; + } +} diff --git a/library/skyeye-dev/skyeye-quartz/src/main/java/com/zhangy/skyeye/quartz/util/ScheduleUtils.java b/library/skyeye-dev/skyeye-quartz/src/main/java/com/zhangy/skyeye/quartz/util/ScheduleUtils.java new file mode 100644 index 0000000..fb487c1 --- /dev/null +++ b/library/skyeye-dev/skyeye-quartz/src/main/java/com/zhangy/skyeye/quartz/util/ScheduleUtils.java @@ -0,0 +1,173 @@ +package com.zhangy.skyeye.quartz.util; + +import org.quartz.*; + +import java.util.Date; +import java.util.Map; + +/** + * 定时任务工具类 + */ +public class ScheduleUtils { + + private static final String TASK_CLASS_NAME = "DT_TASK_"; + + /** + * 构建任务触发对象 + */ + public static TriggerKey getTriggerKey(String jobId, String jobGroup) { + return TriggerKey.triggerKey(TASK_CLASS_NAME + jobId, jobGroup); + } + + /** + * 构建任务键对象 + */ + public static JobKey getJobKey(String jobId, String jobGroup) { + return JobKey.jobKey(TASK_CLASS_NAME + jobId, jobGroup); + } + + /** + * 创建定时任务 + * @param scheduler scheduler对象 + * @param jobClass job class + * @param jobId jobId + * @param jobGroup job组 + * @param cronExpression cron表达式 + * @throws SchedulerException + */ + public static void createScheduleJob(Scheduler scheduler, Class jobClass, String jobId, String jobGroup, String cronExpression) throws SchedulerException { + // 构建job信息 + JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(getJobKey(jobId, jobGroup)).build(); + + // 表达式调度构建器 + CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression); + + // 按新的cronExpression表达式构建一个新的trigger + CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(jobId, jobGroup)) + .withSchedule(cronScheduleBuilder).build(); + + // 放入参数,运行时的方法可以获取 + /*jobDetail.getJobDataMap().put(ScheduleConstants.TASK_PROPERTIES, job);*/ + + // 判断是否存在 + if (scheduler.checkExists(getJobKey(jobId, jobGroup))) { + // 防止创建时存在数据问题 先移除,然后在执行创建操作 + scheduler.deleteJob(getJobKey(jobId, jobGroup)); + } + + scheduler.scheduleJob(jobDetail, trigger); + + } + + /** + * 创建定时任务 + * @param scheduler scheduler对象 + * @param jobClass job class + * @param jobId jobId + * @param jobGroup job组 + * @param startDate 开始执行时间,为null时立即执行 + * @param intervalSeconds 间隔时间,单位秒,为null时只执行一次 + * @param repeatCount 重复次数,为null时一直重复 + * @param dataMap 参数map + * @throws SchedulerException + */ + public static void createScheduleJob(Scheduler scheduler, Class jobClass, String jobId, String jobGroup, Date startDate, Integer intervalSeconds, Integer repeatCount, Map dataMap) throws SchedulerException { + // 构建job信息 + JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(getJobKey(jobId, jobGroup)).build(); + + SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule(); + //每隔多少秒执行一次 + simpleScheduleBuilder.withIntervalInSeconds(intervalSeconds); + + if(repeatCount != null){ + //重复固定次数 + simpleScheduleBuilder.withRepeatCount(repeatCount); + }else{ + //一直重复 + simpleScheduleBuilder.repeatForever(); + } + + Trigger trigger = TriggerBuilder.newTrigger() + .withIdentity(getTriggerKey(jobId, jobGroup)) + .startAt(startDate == null ? new Date() : startDate) //开始执行时间,为空时立即触发 + .withSchedule(simpleScheduleBuilder) + .build(); + + + // 放入参数,运行时的方法可以获取 + if(dataMap != null) { + jobDetail.getJobDataMap().putAll(dataMap); + } + + // 判断是否存在 + if (scheduler.checkExists(getJobKey(jobId, jobGroup))) { + // 防止创建时存在数据问题 先移除,然后在执行创建操作 + scheduler.deleteJob(getJobKey(jobId, jobGroup)); + } + + scheduler.scheduleJob(jobDetail, trigger); + } + + /** + * 删除定时任务 + * @param scheduler scheduler对象 + * @param jobId jobId + * @param jobGroup job组 + * @throws SchedulerException + */ + public static void deleteScheduleJob(Scheduler scheduler, String jobId, String jobGroup) throws SchedulerException { + // 判断是否存在 + if (scheduler.checkExists(getJobKey(jobId, jobGroup))) { + // 防止创建时存在数据问题 先移除,然后在执行创建操作 + scheduler.deleteJob(getJobKey(jobId, jobGroup)); + } + } + + /** + * 暂停定时任务 + * @param scheduler scheduler对象 + * @param jobId jobId + * @param jobGroup job组 + * @throws SchedulerException + */ + public static void pauseScheduleJob(Scheduler scheduler, String jobId, String jobGroup) throws SchedulerException { + // 判断是否存在 + if (scheduler.checkExists(getJobKey(jobId, jobGroup))) { + // 防止创建时存在数据问题 先移除,然后在执行创建操作 + scheduler.pauseJob(getJobKey(jobId, jobGroup)); + } + } + + /** + * 继续定时任务 + * @param scheduler scheduler对象 + * @param jobId jobId + * @param jobGroup job组 + * @throws SchedulerException + */ + public static void resumeScheduleJob(Scheduler scheduler, String jobId, String jobGroup) throws SchedulerException { + // 判断是否存在 + if (scheduler.checkExists(getJobKey(jobId, jobGroup))) { + // 防止创建时存在数据问题 先移除,然后在执行创建操作 + scheduler.resumeJob(getJobKey(jobId, jobGroup)); + } + } + + /** + * 更新jobDetail中的参数Map + * @param scheduler scheduler对象 + * @param jobId jobId + * @param jobGroup job组 + * @throws SchedulerException + */ + public static void putDataMap(Scheduler scheduler, String jobId, String jobGroup, String key, Object value) throws SchedulerException { + // 判断是否存在 + JobDetail jobDetail = scheduler.getJobDetail(getJobKey(jobId, jobGroup)); + + if(jobDetail != null){ + jobDetail.getJobDataMap().put(key, value); + scheduler.addJob(jobDetail, true, true); + } + } + +} \ No newline at end of file diff --git a/library/skyeye-dev/skyeye-quartz/src/main/resources/META-INF/spring.factories b/library/skyeye-dev/skyeye-quartz/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..c1b8b3f --- /dev/null +++ b/library/skyeye-dev/skyeye-quartz/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.tiamo.dt.dev.quartz.config.QuartzConfig diff --git a/library/skyeye-dev/skyeye-quartz/target/classes/META-INF/spring.factories b/library/skyeye-dev/skyeye-quartz/target/classes/META-INF/spring.factories new file mode 100644 index 0000000..c1b8b3f --- /dev/null +++ b/library/skyeye-dev/skyeye-quartz/target/classes/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.tiamo.dt.dev.quartz.config.QuartzConfig diff --git a/library/skyeye-dev/skyeye-quartz/target/classes/com/zhangy/skyeye/quartz/config/QuartzConfig.class b/library/skyeye-dev/skyeye-quartz/target/classes/com/zhangy/skyeye/quartz/config/QuartzConfig.class new file mode 100644 index 0000000..87c3bdd Binary files /dev/null and b/library/skyeye-dev/skyeye-quartz/target/classes/com/zhangy/skyeye/quartz/config/QuartzConfig.class differ diff --git a/library/skyeye-dev/skyeye-quartz/target/classes/com/zhangy/skyeye/quartz/util/CronUtils.class b/library/skyeye-dev/skyeye-quartz/target/classes/com/zhangy/skyeye/quartz/util/CronUtils.class new file mode 100644 index 0000000..cae26d8 Binary files /dev/null and b/library/skyeye-dev/skyeye-quartz/target/classes/com/zhangy/skyeye/quartz/util/CronUtils.class differ diff --git a/library/skyeye-dev/skyeye-quartz/target/classes/com/zhangy/skyeye/quartz/util/ScheduleUtils.class b/library/skyeye-dev/skyeye-quartz/target/classes/com/zhangy/skyeye/quartz/util/ScheduleUtils.class new file mode 100644 index 0000000..c067d4b Binary files /dev/null and b/library/skyeye-dev/skyeye-quartz/target/classes/com/zhangy/skyeye/quartz/util/ScheduleUtils.class differ diff --git a/library/skyeye-dev/skyeye-quartz/target/maven-archiver/pom.properties b/library/skyeye-dev/skyeye-quartz/target/maven-archiver/pom.properties new file mode 100644 index 0000000..c7bd980 --- /dev/null +++ b/library/skyeye-dev/skyeye-quartz/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=skyeye-quartz +groupId=com.zhangy +version=1.0.0.RELEASE diff --git a/library/skyeye-dev/skyeye-quartz/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/library/skyeye-dev/skyeye-quartz/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..967ffe0 --- /dev/null +++ b/library/skyeye-dev/skyeye-quartz/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,3 @@ +com\zhangy\skyeye\quartz\util\ScheduleUtils.class +com\zhangy\skyeye\quartz\util\CronUtils.class +com\zhangy\skyeye\quartz\config\QuartzConfig.class diff --git a/library/skyeye-dev/skyeye-quartz/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/library/skyeye-dev/skyeye-quartz/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..93c2952 --- /dev/null +++ b/library/skyeye-dev/skyeye-quartz/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,3 @@ +D:\logisen\ddd\skyeye-dev\skyeye-quartz\src\main\java\com\zhangy\skyeye\quartz\config\QuartzConfig.java +D:\logisen\ddd\skyeye-dev\skyeye-quartz\src\main\java\com\zhangy\skyeye\quartz\util\ScheduleUtils.java +D:\logisen\ddd\skyeye-dev\skyeye-quartz\src\main\java\com\zhangy\skyeye\quartz\util\CronUtils.java diff --git a/library/skyeye-dev/skyeye-quartz/target/skyeye-quartz-1.0.0.RELEASE.jar b/library/skyeye-dev/skyeye-quartz/target/skyeye-quartz-1.0.0.RELEASE.jar new file mode 100644 index 0000000..161ce73 Binary files /dev/null and b/library/skyeye-dev/skyeye-quartz/target/skyeye-quartz-1.0.0.RELEASE.jar differ diff --git a/library/skyeye-dev/skyeye-redis/.DS_Store b/library/skyeye-dev/skyeye-redis/.DS_Store new file mode 100644 index 0000000..6330a99 Binary files /dev/null and b/library/skyeye-dev/skyeye-redis/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-redis/pom.xml b/library/skyeye-dev/skyeye-redis/pom.xml new file mode 100644 index 0000000..a9afeb2 --- /dev/null +++ b/library/skyeye-dev/skyeye-redis/pom.xml @@ -0,0 +1,32 @@ + + + + + skyeye-dev + com.zhangy + 1.0.0.RELEASE + + 4.0.0 + + skyeye-redis + skyeye Redis lib + + + + + + org.projectlombok + lombok + + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + + \ No newline at end of file diff --git a/library/skyeye-dev/skyeye-redis/src/.DS_Store b/library/skyeye-dev/skyeye-redis/src/.DS_Store new file mode 100644 index 0000000..7ebb4f9 Binary files /dev/null and b/library/skyeye-dev/skyeye-redis/src/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-redis/src/main/.DS_Store b/library/skyeye-dev/skyeye-redis/src/main/.DS_Store new file mode 100644 index 0000000..a46babd Binary files /dev/null and b/library/skyeye-dev/skyeye-redis/src/main/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-redis/src/main/java/.DS_Store b/library/skyeye-dev/skyeye-redis/src/main/java/.DS_Store new file mode 100644 index 0000000..508308f Binary files /dev/null and b/library/skyeye-dev/skyeye-redis/src/main/java/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-redis/src/main/java/com/.DS_Store b/library/skyeye-dev/skyeye-redis/src/main/java/com/.DS_Store new file mode 100644 index 0000000..0cbd6fb Binary files /dev/null and b/library/skyeye-dev/skyeye-redis/src/main/java/com/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-redis/src/main/java/com/zhangy/.DS_Store b/library/skyeye-dev/skyeye-redis/src/main/java/com/zhangy/.DS_Store new file mode 100644 index 0000000..172f3ca Binary files /dev/null and b/library/skyeye-dev/skyeye-redis/src/main/java/com/zhangy/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-redis/src/main/java/com/zhangy/skyeye/.DS_Store b/library/skyeye-dev/skyeye-redis/src/main/java/com/zhangy/skyeye/.DS_Store new file mode 100644 index 0000000..93ea907 Binary files /dev/null and b/library/skyeye-dev/skyeye-redis/src/main/java/com/zhangy/skyeye/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-redis/src/main/java/com/zhangy/skyeye/redis/.DS_Store b/library/skyeye-dev/skyeye-redis/src/main/java/com/zhangy/skyeye/redis/.DS_Store new file mode 100644 index 0000000..b277365 Binary files /dev/null and b/library/skyeye-dev/skyeye-redis/src/main/java/com/zhangy/skyeye/redis/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-redis/src/main/java/com/zhangy/skyeye/redis/config/DTRedisTemplateConfiguration.java b/library/skyeye-dev/skyeye-redis/src/main/java/com/zhangy/skyeye/redis/config/DTRedisTemplateConfiguration.java new file mode 100644 index 0000000..f54c567 --- /dev/null +++ b/library/skyeye-dev/skyeye-redis/src/main/java/com/zhangy/skyeye/redis/config/DTRedisTemplateConfiguration.java @@ -0,0 +1,70 @@ +package com.zhangy.skyeye.redis.config; + +import com.zhangy.skyeye.redis.utils.RedisUtil; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; +import org.springframework.cache.CacheManager; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.cache.RedisCacheConfiguration; +import org.springframework.data.redis.cache.RedisCacheManager; +import org.springframework.data.redis.cache.RedisCacheWriter; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; +import org.springframework.data.redis.serializer.RedisSerializer; + +import java.time.Duration; + +/** + * Redis 配置 + */ +@EnableCaching +@Configuration(proxyBeanMethods = false) +@AutoConfigureBefore(RedisAutoConfiguration.class) +public class DTRedisTemplateConfiguration { + + /** + * value 值 序列化 + * @return RedisSerializer + */ + @Bean + @ConditionalOnMissingBean(RedisSerializer.class) + public RedisSerializer redisSerializer() { + return new JdkSerializationRedisSerializer(); + } + + @Bean(name = "redisTemplate") + @ConditionalOnMissingBean(RedisTemplate.class) + public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory, RedisSerializer redisSerializer) { + RedisTemplate redisTemplate = new RedisTemplate<>(); + RedisKeySerializer redisKeySerializer = new RedisKeySerializer(); + // key 序列化 + redisTemplate.setKeySerializer(redisKeySerializer); + redisTemplate.setHashKeySerializer(redisKeySerializer); + // value 序列化 + redisTemplate.setValueSerializer(redisSerializer); + redisTemplate.setHashValueSerializer(redisSerializer); + redisTemplate.setConnectionFactory(redisConnectionFactory); + return redisTemplate; + } + + @Bean + public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) { + RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig() + .entryTtl(Duration.ofHours(1)); + return RedisCacheManager + .builder(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory)) + .cacheDefaults(redisCacheConfiguration).build(); + } + + @Bean(name = "redisUtil") + @ConditionalOnBean(RedisTemplate.class) + public RedisUtil redisUtils(RedisTemplate redisTemplate) { + return new RedisUtil(redisTemplate); + } + +} diff --git a/library/skyeye-dev/skyeye-redis/src/main/java/com/zhangy/skyeye/redis/config/RedisKeySerializer.java b/library/skyeye-dev/skyeye-redis/src/main/java/com/zhangy/skyeye/redis/config/RedisKeySerializer.java new file mode 100644 index 0000000..34dc23e --- /dev/null +++ b/library/skyeye-dev/skyeye-redis/src/main/java/com/zhangy/skyeye/redis/config/RedisKeySerializer.java @@ -0,0 +1,55 @@ +package com.zhangy.skyeye.redis.config; + +import org.springframework.cache.interceptor.SimpleKey; +import org.springframework.core.convert.ConversionService; +import org.springframework.core.convert.support.DefaultConversionService; +import org.springframework.data.redis.serializer.RedisSerializer; +import org.springframework.lang.Nullable; + +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.util.Objects; + +/** + * 将redis key序列化为字符串 + * spring cache中的简单基本类型直接使用 StringRedisSerializer 会有问题 + */ +public class RedisKeySerializer implements RedisSerializer { + private final Charset charset; + private final ConversionService converter; + + public RedisKeySerializer() { + this(StandardCharsets.UTF_8); + } + + public RedisKeySerializer(Charset charset) { + Objects.requireNonNull(charset, "Charset must not be null"); + this.charset = charset; + this.converter = DefaultConversionService.getSharedInstance(); + } + + @Override + public Object deserialize(byte[] bytes) { + // redis keys 会用到反序列化 + if (bytes == null) { + return null; + } + return new String(bytes, charset); + } + + @Override + @Nullable + public byte[] serialize(Object object) { + Objects.requireNonNull(object, "redis key is null"); + String key; + if (object instanceof SimpleKey) { + key = ""; + } else if (object instanceof String) { + key = (String) object; + } else { + key = converter.convert(object, String.class); + } + return key.getBytes(this.charset); + } + +} diff --git a/library/skyeye-dev/skyeye-redis/src/main/java/com/zhangy/skyeye/redis/utils/RedisUtil.java b/library/skyeye-dev/skyeye-redis/src/main/java/com/zhangy/skyeye/redis/utils/RedisUtil.java new file mode 100644 index 0000000..4ada03d --- /dev/null +++ b/library/skyeye-dev/skyeye-redis/src/main/java/com/zhangy/skyeye/redis/utils/RedisUtil.java @@ -0,0 +1,600 @@ +package com.zhangy.skyeye.redis.utils; + +import lombok.AllArgsConstructor; +import org.springframework.data.redis.core.RedisTemplate; + +import java.util.*; +import java.util.concurrent.TimeUnit; + +/** + * Redis工具类 + */ +@AllArgsConstructor +public class RedisUtil { + + private RedisTemplate redisTemplate; + + //=============================common============================ + + /** + * 指定缓存失效时间 + * + * @param key 键 + * @param time 时间(秒) + * @return boolean + */ + public boolean expire(String key, long time) { + try { + if (time > 0) { + redisTemplate.expire(key, time, TimeUnit.SECONDS); + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 根据key 获取过期时间 + * + * @param key 键 不能为null + * @return 时间(秒) 返回0代表为永久有效 + */ + public long getExpire(String key) { + return redisTemplate.getExpire(key, TimeUnit.SECONDS); + } + + /** + * 判断key是否存在 + * + * @param key 键 + * @return true 存在 false不存在 + */ + public boolean hasKey(String key) { + try { + return redisTemplate.hasKey(key); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 删除缓存 + * + * @param key 可以传一个值 或多个 + */ + public void del(String... key) { + if (key != null && key.length > 0) { + if (key.length == 1) { + redisTemplate.delete(key[0]); + } else { + redisTemplate.delete(Arrays.asList(key)); + } + } + } + + //============================String============================= + + /** + * 普通缓存获取 + * + * @param key 键 + * @return 值 + */ + public Object get(String key) { + return key == null ? null : redisTemplate.opsForValue().get(key); + } + + /** + * 普通缓存放入 + * + * @param key 键 + * @param value 值 + * @return true成功 false失败 + */ + public boolean set(String key, Object value) { + try { + redisTemplate.opsForValue().set(key, value); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + + } + + /** + * 普通缓存放入并设置时间 + * + * @param key 键 + * @param value 值 + * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期 + * @return true成功 false 失败 + */ + public boolean set(String key, Object value, long time) { + try { + if (time > 0) { + redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS); + } else { + set(key, value); + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 普通缓存放入并设置时间 + * + * @param key 键 + * @param value 值 + * @param time 时间 + * @param timeUnit 时间单位 + * @return true成功 false 失败 + */ + public boolean set(String key, Object value, long time, TimeUnit timeUnit) { + try { + if (time > 0) { + redisTemplate.opsForValue().set(key, value, time, timeUnit); + } else { + set(key, value); + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 递增 + * + * @param key 键 + * @param delta 要增加几(大于0) + * @return long + */ + public long incr(String key, long delta) { + if (delta < 0) { + throw new RuntimeException("递增因子必须大于0"); + } + return redisTemplate.opsForValue().increment(key, delta); + } + + /** + * 递减 + * + * @param key 键 + * @param delta 要减少几(小于0) + * @return long + */ + public long decr(String key, long delta) { + if (delta < 0) { + throw new RuntimeException("递减因子必须大于0"); + } + return redisTemplate.opsForValue().increment(key, -delta); + } + + //================================Map================================= + + /** + * HashGet + * + * @param key 键 不能为null + * @param item 项 不能为null + * @return 值 + */ + public Object hget(String key, String item) { + return redisTemplate.opsForHash().get(key, item); + } + + /** + * 获取hashKey对应的所有键值 + * + * @param key 键 + * @return 对应的多个键值 + */ + public Map hmget(String key) { + return redisTemplate.opsForHash().entries(key); + } + + /** + * 获取hashKey对应的所有键值 + * + * @param key 键 + * @return 对应的多个键值 + */ + public List hmget(String key, List hk) { + return redisTemplate.opsForHash().multiGet(key, hk); + } + + /** + * HashSet + * + * @param key 键 + * @param map 对应多个键值 + * @return true 成功 false 失败 + */ + public boolean hmset(String key, Map map) { + try { + redisTemplate.opsForHash().putAll(key, map); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * HashSet 并设置时间 + * + * @param key 键 + * @param map 对应多个键值 + * @param time 时间(秒) + * @return true成功 false失败 + */ + public boolean hmset(String key, Map map, long time) { + try { + redisTemplate.opsForHash().putAll(key, map); + if (time > 0) { + expire(key, time); + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 向一张hash表中放入数据,如果不存在将创建 + * + * @param key 键 + * @param item 项 + * @param value 值 + * @return true 成功 false失败 + */ + public boolean hset(String key, String item, Object value) { + try { + redisTemplate.opsForHash().put(key, item, value); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 向一张hash表中放入数据,如果不存在将创建 + * + * @param key 键 + * @param item 项 + * @param value 值 + * @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间 + * @return true 成功 false失败 + */ + public boolean hset(String key, String item, Object value, long time) { + try { + redisTemplate.opsForHash().put(key, item, value); + if (time > 0) { + expire(key, time); + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 删除hash表中的值 + * + * @param key 键 不能为null + * @param item 项 可以使多个 不能为null + */ + public void hdel(String key, Object... item) { + redisTemplate.opsForHash().delete(key, item); + } + + /** + * 判断hash表中是否有该项的值 + * + * @param key 键 不能为null + * @param item 项 不能为null + * @return true 存在 false不存在 + */ + public boolean hHasKey(String key, String item) { + return redisTemplate.opsForHash().hasKey(key, item); + } + + /** + * hash递增 如果不存在,就会创建一个 并把新增后的值返回 + * + * @param key 键 + * @param item 项 + * @param by 要增加几(大于0) + * @return double + */ + public double hincr(String key, String item, double by) { + return redisTemplate.opsForHash().increment(key, item, by); + } + + /** + * hash递减 + * + * @param key 键 + * @param item 项 + * @param by 要减少记(小于0) + * @return double + */ + public double hdecr(String key, String item, double by) { + return redisTemplate.opsForHash().increment(key, item, -by); + } + + //============================set============================= + + /** + * 根据key获取Set中的所有值 + * + * @param key 键 + * @return Set + */ + public Set sGet(String key) { + try { + return redisTemplate.opsForSet().members(key); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * 根据value从一个set中查询,是否存在 + * + * @param key 键 + * @param value 值 + * @return true 存在 false不存在 + */ + public boolean sHasKey(String key, Object value) { + try { + return redisTemplate.opsForSet().isMember(key, value); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 将数据放入set缓存 + * + * @param key 键 + * @param values 值 可以是多个 + * @return 成功个数 + */ + public long sSet(String key, Object... values) { + try { + return redisTemplate.opsForSet().add(key, values); + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + } + + /** + * 将set数据放入缓存 + * + * @param key 键 + * @param time 时间(秒) + * @param values 值 可以是多个 + * @return 成功个数 + */ + public long sSetAndTime(String key, long time, Object... values) { + try { + Long count = redisTemplate.opsForSet().add(key, values); + if (time > 0) { + expire(key, time); + } + return count; + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + } + + /** + * 获取set缓存的长度 + * + * @param key 键 + * @return long + */ + public long sGetSetSize(String key) { + try { + return redisTemplate.opsForSet().size(key); + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + } + + /** + * 移除值为value的 + * + * @param key 键 + * @param values 值 可以是多个 + * @return 移除的个数 + */ + public long setRemove(String key, Object... values) { + try { + Long count = redisTemplate.opsForSet().remove(key, values); + return count; + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + } + //===============================list================================= + + /** + * 获取list缓存的内容 + * + * @param key 键 + * @param start 开始 + * @param end 结束 0 到 -1代表所有值 + * @return List + */ + public List lGet(String key, long start, long end) { + try { + return redisTemplate.opsForList().range(key, start, end); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * 获取list缓存的长度 + * + * @param key 键 + * @return long + */ + public long lGetListSize(String key) { + try { + return redisTemplate.opsForList().size(key); + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + } + + /** + * 通过索引 获取list中的值 + * + * @param key 键 + * @param index 索引 + * @return Object + */ + public Object lGetIndex(String key, long index) { + try { + return redisTemplate.opsForList().index(key, index); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * 将list放入缓存 + * + * @param key 键 + * @param value 值 + * @return boolean + */ + public boolean lSet(String key, Object value) { + try { + redisTemplate.opsForList().rightPush(key, value); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 将list放入缓存 + * + * @param key 键 + * @param value 值 + * @param time 时间(秒) + * @return boolean + */ + public boolean lSet(String key, Object value, long time) { + try { + redisTemplate.opsForList().rightPush(key, value); + if (time > 0) { + expire(key, time); + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 将list放入缓存 + * + * @param key 键 + * @param value 值 + * @return boolean + */ + public boolean lSet(String key, List value) { + try { + redisTemplate.opsForList().rightPushAll(key, value); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 将list放入缓存 + * + * @param key 键 + * @param value 值 + * @param time 时间(秒) + * @return boolean + */ + public boolean lSet(String key, List value, long time) { + try { + redisTemplate.opsForList().rightPushAll(key, value); + if (time > 0) { + expire(key, time); + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 根据索引修改list中的某条数据 + * + * @param key 键 + * @param index 索引 + * @param value 值 + * @return boolean + */ + public boolean lUpdateIndex(String key, long index, Object value) { + try { + redisTemplate.opsForList().set(key, index, value); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 移除N个值为value + * + * @param key 键 + * @param count 移除多少个 + * @param value 值 + * @return 移除的个数 + */ + public long lRemove(String key, long count, Object value) { + try { + Long remove = redisTemplate.opsForList().remove(key, count, value); + return remove; + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + } + +} diff --git a/library/skyeye-dev/skyeye-redis/src/main/resources/META-INF/spring.factories b/library/skyeye-dev/skyeye-redis/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..3ba0428 --- /dev/null +++ b/library/skyeye-dev/skyeye-redis/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.tiamo.dt.dev.redis.config.DTRedisTemplateConfiguration diff --git a/library/skyeye-dev/skyeye-redis/target/classes/META-INF/spring.factories b/library/skyeye-dev/skyeye-redis/target/classes/META-INF/spring.factories new file mode 100644 index 0000000..3ba0428 --- /dev/null +++ b/library/skyeye-dev/skyeye-redis/target/classes/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.tiamo.dt.dev.redis.config.DTRedisTemplateConfiguration diff --git a/library/skyeye-dev/skyeye-redis/target/classes/com/zhangy/skyeye/redis/config/DTRedisTemplateConfiguration.class b/library/skyeye-dev/skyeye-redis/target/classes/com/zhangy/skyeye/redis/config/DTRedisTemplateConfiguration.class new file mode 100644 index 0000000..678a60f Binary files /dev/null and b/library/skyeye-dev/skyeye-redis/target/classes/com/zhangy/skyeye/redis/config/DTRedisTemplateConfiguration.class differ diff --git a/library/skyeye-dev/skyeye-redis/target/classes/com/zhangy/skyeye/redis/config/RedisKeySerializer.class b/library/skyeye-dev/skyeye-redis/target/classes/com/zhangy/skyeye/redis/config/RedisKeySerializer.class new file mode 100644 index 0000000..9fb5ef9 Binary files /dev/null and b/library/skyeye-dev/skyeye-redis/target/classes/com/zhangy/skyeye/redis/config/RedisKeySerializer.class differ diff --git a/library/skyeye-dev/skyeye-redis/target/classes/com/zhangy/skyeye/redis/utils/RedisUtil.class b/library/skyeye-dev/skyeye-redis/target/classes/com/zhangy/skyeye/redis/utils/RedisUtil.class new file mode 100644 index 0000000..d0cd85e Binary files /dev/null and b/library/skyeye-dev/skyeye-redis/target/classes/com/zhangy/skyeye/redis/utils/RedisUtil.class differ diff --git a/library/skyeye-dev/skyeye-redis/target/maven-archiver/pom.properties b/library/skyeye-dev/skyeye-redis/target/maven-archiver/pom.properties new file mode 100644 index 0000000..8647f30 --- /dev/null +++ b/library/skyeye-dev/skyeye-redis/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=skyeye-redis +groupId=com.zhangy +version=1.0.0.RELEASE diff --git a/library/skyeye-dev/skyeye-redis/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/library/skyeye-dev/skyeye-redis/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..711ee24 --- /dev/null +++ b/library/skyeye-dev/skyeye-redis/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,3 @@ +com\zhangy\skyeye\redis\config\RedisKeySerializer.class +com\zhangy\skyeye\redis\utils\RedisUtil.class +com\zhangy\skyeye\redis\config\DTRedisTemplateConfiguration.class diff --git a/library/skyeye-dev/skyeye-redis/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/library/skyeye-dev/skyeye-redis/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..8d3f76a --- /dev/null +++ b/library/skyeye-dev/skyeye-redis/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,3 @@ +D:\logisen\ddd\skyeye-dev\skyeye-redis\src\main\java\com\zhangy\skyeye\redis\config\RedisKeySerializer.java +D:\logisen\ddd\skyeye-dev\skyeye-redis\src\main\java\com\zhangy\skyeye\redis\utils\RedisUtil.java +D:\logisen\ddd\skyeye-dev\skyeye-redis\src\main\java\com\zhangy\skyeye\redis\config\DTRedisTemplateConfiguration.java diff --git a/library/skyeye-dev/skyeye-redis/target/skyeye-redis-1.0.0.RELEASE.jar b/library/skyeye-dev/skyeye-redis/target/skyeye-redis-1.0.0.RELEASE.jar new file mode 100644 index 0000000..eb0b90e Binary files /dev/null and b/library/skyeye-dev/skyeye-redis/target/skyeye-redis-1.0.0.RELEASE.jar differ diff --git a/library/skyeye-dev/skyeye-util/.DS_Store b/library/skyeye-dev/skyeye-util/.DS_Store new file mode 100644 index 0000000..fb82c56 Binary files /dev/null and b/library/skyeye-dev/skyeye-util/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-util/pom.xml b/library/skyeye-dev/skyeye-util/pom.xml new file mode 100644 index 0000000..a4e48ff --- /dev/null +++ b/library/skyeye-dev/skyeye-util/pom.xml @@ -0,0 +1,34 @@ + + + + skyeye-dev + com.zhangy + 1.0.0.RELEASE + + 4.0.0 + + skyeye-util + + + + + org.projectlombok + lombok + + + + cn.hutool + hutool-all + + + + com.belerweb + pinyin4j + 2.5.1 + + + + + \ No newline at end of file diff --git a/library/skyeye-dev/skyeye-util/src/.DS_Store b/library/skyeye-dev/skyeye-util/src/.DS_Store new file mode 100644 index 0000000..ad10f0b Binary files /dev/null and b/library/skyeye-dev/skyeye-util/src/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-util/src/main/.DS_Store b/library/skyeye-dev/skyeye-util/src/main/.DS_Store new file mode 100644 index 0000000..7900701 Binary files /dev/null and b/library/skyeye-dev/skyeye-util/src/main/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-util/src/main/java/.DS_Store b/library/skyeye-dev/skyeye-util/src/main/java/.DS_Store new file mode 100644 index 0000000..186214a Binary files /dev/null and b/library/skyeye-dev/skyeye-util/src/main/java/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-util/src/main/java/com/.DS_Store b/library/skyeye-dev/skyeye-util/src/main/java/com/.DS_Store new file mode 100644 index 0000000..615813f Binary files /dev/null and b/library/skyeye-dev/skyeye-util/src/main/java/com/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/.DS_Store b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/.DS_Store new file mode 100644 index 0000000..fbfd8c2 Binary files /dev/null and b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/.DS_Store b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/.DS_Store new file mode 100644 index 0000000..ff683de Binary files /dev/null and b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/.DS_Store b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/.DS_Store new file mode 100644 index 0000000..d084456 Binary files /dev/null and b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/.DS_Store differ diff --git a/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/other/TemporalAccessorUtil.java b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/other/TemporalAccessorUtil.java new file mode 100644 index 0000000..452fda9 --- /dev/null +++ b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/other/TemporalAccessorUtil.java @@ -0,0 +1,158 @@ +package com.zhangy.skyeye.util.other; + +import cn.hutool.core.util.StrUtil; +import com.zhangy.skyeye.util.utils.LdtUtil; + +import java.time.*; +import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAccessor; +import java.time.temporal.TemporalField; +import java.time.temporal.UnsupportedTemporalTypeException; + +public class TemporalAccessorUtil { + /** + * 安全获取时间的某个属性,属性不存在返回最小值,一般为0
+ * 注意请谨慎使用此方法,某些{@link TemporalAccessor#isSupported(TemporalField)}为{@code false}的方法返回最小值 + * + * @param temporalAccessor 需要获取的时间对象 + * @param field 需要获取的属性 + * @return 时间的值,如果无法获取则获取最小值,一般为0 + */ + public static int get(TemporalAccessor temporalAccessor, TemporalField field) { + if (temporalAccessor.isSupported(field)) { + return temporalAccessor.get(field); + } + + return (int) field.range().getMinimum(); + } + + /** + * 格式化日期时间为指定格式
+ * 如果为{@link Month},调用{@link Month#toString()} + * + * @param time {@link TemporalAccessor} + * @param formatter 日期格式化器,预定义的格式见:{@link DateTimeFormatter} + * @return 格式化后的字符串 + */ + public static String format(TemporalAccessor time, DateTimeFormatter formatter) { + if (null == time) { + return null; + } + + if (time instanceof Month) { + return time.toString(); + } + + if (null == formatter) { + formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME; + } + + try { + return formatter.format(time); + } catch (UnsupportedTemporalTypeException e) { + if (time instanceof LocalDate && e.getMessage().contains("HourOfDay")) { + // 用户传入LocalDate,但是要求格式化带有时间部分,转换为LocalDateTime重试 + return formatter.format(((LocalDate) time).atStartOfDay()); + } else if (time instanceof LocalTime && e.getMessage().contains("YearOfEra")) { + // 用户传入LocalTime,但是要求格式化带有日期部分,转换为LocalDateTime重试 + return formatter.format(((LocalTime) time).atDate(LocalDate.now())); + } else if (time instanceof Instant) { + // 时间戳没有时区信息,赋予默认时区 + return formatter.format(((Instant) time).atZone(ZoneId.systemDefault())); + } + throw e; + } + } + + /** + * 格式化日期时间为指定格式
+ * 如果为{@link Month},调用{@link Month#toString()} + * + * @param time {@link TemporalAccessor} + * @param format 日期格式 + * @return 格式化后的字符串 + */ + public static String format(TemporalAccessor time, String format) { + if (null == time) { + return null; + } + + if (time instanceof Month) { + return time.toString(); + } + + final DateTimeFormatter formatter = StrUtil.isBlank(format) + ? null : DateTimeFormatter.ofPattern(format); + + return format(time, formatter); + } + + /** + * {@link TemporalAccessor}转换为 时间戳(从1970-01-01T00:00:00Z开始的毫秒数)
+ * 如果为{@link Month},调用{@link Month#getValue()} + * + * @param temporalAccessor Date对象 + * @return {@link Instant}对象 + */ + public static long toEpochMilli(TemporalAccessor temporalAccessor) { + if (temporalAccessor instanceof Month) { + return ((Month) temporalAccessor).getValue(); + } + return toInstant(temporalAccessor).toEpochMilli(); + } + + /** + * {@link TemporalAccessor}转换为 {@link Instant}对象 + * + * @param temporalAccessor Date对象 + * @return {@link Instant}对象 + */ + public static Instant toInstant(TemporalAccessor temporalAccessor) { + if (null == temporalAccessor) { + return null; + } + + Instant result; + if (temporalAccessor instanceof Instant) { + result = (Instant) temporalAccessor; + } else if (temporalAccessor instanceof LocalDateTime) { + result = ((LocalDateTime) temporalAccessor).atZone(ZoneId.systemDefault()).toInstant(); + } else if (temporalAccessor instanceof ZonedDateTime) { + result = ((ZonedDateTime) temporalAccessor).toInstant(); + } else if (temporalAccessor instanceof OffsetDateTime) { + result = ((OffsetDateTime) temporalAccessor).toInstant(); + } else if (temporalAccessor instanceof LocalDate) { + result = ((LocalDate) temporalAccessor).atStartOfDay(ZoneId.systemDefault()).toInstant(); + } else if (temporalAccessor instanceof LocalTime) { + // 指定本地时间转换 为Instant,取当天日期 + result = ((LocalTime) temporalAccessor).atDate(LocalDate.now()).atZone(ZoneId.systemDefault()).toInstant(); + } else if (temporalAccessor instanceof OffsetTime) { + // 指定本地时间转换 为Instant,取当天日期 + result = ((OffsetTime) temporalAccessor).atDate(LocalDate.now()).toInstant(); + } else { + // issue#1891@Github + // Instant.from不能完成日期转换 + //result = Instant.from(temporalAccessor); + result = toInstant(LdtUtil.of(temporalAccessor)); + } + + return result; + } + + /** + * 当前日期是否在日期指定范围内
+ * 起始日期和结束日期可以互换 + * + * @param date 被检查的日期 + * @param beginDate 起始日期(包含) + * @param endDate 结束日期(包含) + * @return 是否在范围内 + */ + public static boolean isIn(TemporalAccessor date, TemporalAccessor beginDate, TemporalAccessor endDate) { + final long thisMills = toEpochMilli(date); + final long beginMills = toEpochMilli(beginDate); + final long endMills = toEpochMilli(endDate); + + return thisMills >= Math.min(beginMills, endMills) && thisMills <= Math.max(beginMills, endMills); + } +} diff --git a/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/other/TemporalUtil.java b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/other/TemporalUtil.java new file mode 100644 index 0000000..f7f03b3 --- /dev/null +++ b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/other/TemporalUtil.java @@ -0,0 +1,140 @@ +package com.zhangy.skyeye.util.other; + +import java.time.DayOfWeek; +import java.time.Duration; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.time.temporal.Temporal; +import java.time.temporal.TemporalAdjusters; +import java.time.temporal.TemporalUnit; +import java.util.concurrent.TimeUnit; + +public class TemporalUtil { + + public static void main(String[] args) { + LocalDateTime of = LocalDateTime.of(2022, 2, 28, 15, 55, 0); + LocalDateTime localDateTime = of.plusMonths(1); + System.out.println(localDateTime); + System.out.println(localDateTime.with(TemporalAdjusters.lastDayOfMonth())); + } + + /** + * 获取两个日期的差,如果结束时间早于开始时间,获取结果为负。 + *

+ * 返回结果为{@link Duration}对象,通过调用toXXX方法返回相差单位 + * + * @param startTimeInclude 开始时间(包含) + * @param endTimeExclude 结束时间(不包含) + * @return 时间差 {@link Duration}对象 + */ + public static Duration between(Temporal startTimeInclude, Temporal endTimeExclude) { + return Duration.between(startTimeInclude, endTimeExclude); + } + + /** + * 获取两个日期的差,如果结束时间早于开始时间,获取结果为负。 + *

+ * 返回结果为时间差的long值 + * + * @param startTimeInclude 开始时间(包括) + * @param endTimeExclude 结束时间(不包括) + * @param unit 时间差单位 + * @return 时间差 + */ + public static long between(Temporal startTimeInclude, Temporal endTimeExclude, ChronoUnit unit) { + return unit.between(startTimeInclude, endTimeExclude); + } + + /** + * 将 {@link TimeUnit} 转换为 {@link ChronoUnit}. + * + * @param unit 被转换的{@link TimeUnit}单位,如果为{@code null}返回{@code null} + * @return {@link ChronoUnit} + */ + public static ChronoUnit toChronoUnit(TimeUnit unit) throws IllegalArgumentException { + if (null == unit) { + return null; + } + switch (unit) { + case NANOSECONDS: + return ChronoUnit.NANOS; + case MICROSECONDS: + return ChronoUnit.MICROS; + case MILLISECONDS: + return ChronoUnit.MILLIS; + case SECONDS: + return ChronoUnit.SECONDS; + case MINUTES: + return ChronoUnit.MINUTES; + case HOURS: + return ChronoUnit.HOURS; + case DAYS: + return ChronoUnit.DAYS; + default: + throw new IllegalArgumentException("Unknown TimeUnit constant"); + } + } + + /** + * 转换 {@link ChronoUnit} 到 {@link TimeUnit}. + * + * @param unit {@link ChronoUnit},如果为{@code null}返回{@code null} + * @return {@link TimeUnit} + * @throws IllegalArgumentException 如果{@link TimeUnit}没有对应单位抛出 + */ + public static TimeUnit toTimeUnit(ChronoUnit unit) throws IllegalArgumentException { + if (null == unit) { + return null; + } + switch (unit) { + case NANOS: + return TimeUnit.NANOSECONDS; + case MICROS: + return TimeUnit.MICROSECONDS; + case MILLIS: + return TimeUnit.MILLISECONDS; + case SECONDS: + return TimeUnit.SECONDS; + case MINUTES: + return TimeUnit.MINUTES; + case HOURS: + return TimeUnit.HOURS; + case DAYS: + return TimeUnit.DAYS; + default: + throw new IllegalArgumentException("ChronoUnit cannot be converted to TimeUnit: " + unit); + } + } + + /** + * 日期偏移,根据field不同加不同值(偏移会修改传入的对象) + * + * @param 日期类型,如LocalDate或LocalDateTime + * @param time {@link Temporal} + * @param number 偏移量,正数为向后偏移,负数为向前偏移 + * @param field 偏移单位,见{@link ChronoUnit},不能为null + * @return 偏移后的日期时间 + */ + @SuppressWarnings("unchecked") + public static T offset(T time, long number, TemporalUnit field) { + if (null == time) { + return null; + } + + return (T) time.plus(number, field); + } + + /** + * 偏移到指定的周几 + * + * @param temporal 日期或者日期时间 + * @param dayOfWeek 周几 + * @param 日期类型,如LocalDate或LocalDateTime + * @param isPrevious 是否向前偏移,{@code true}向前偏移,{@code false}向后偏移。 + * @return 偏移后的日期 + */ + @SuppressWarnings("unchecked") + public T offset(T temporal, DayOfWeek dayOfWeek, boolean isPrevious) { + return (T) temporal.with(isPrevious ? TemporalAdjusters.previous(dayOfWeek) : TemporalAdjusters.next(dayOfWeek)); + } +} diff --git a/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/utils/Base64Util.java b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/utils/Base64Util.java new file mode 100644 index 0000000..ae2a3c6 --- /dev/null +++ b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/utils/Base64Util.java @@ -0,0 +1,91 @@ +package com.zhangy.skyeye.util.utils; + +import lombok.experimental.UtilityClass; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.Base64; + +/** + * base64与文件转换工具类 + */ +@UtilityClass +public class Base64Util { + + /** + * 根据远程文件url转换base64字符串 + * @param path 远程文件url + * @return base64字符串 + * @throws IOException + */ + public String getBase64ByUrl(String path) throws IOException { + URL url = new URL(path); + HttpURLConnection httpUrl = (HttpURLConnection) url.openConnection(); + httpUrl.connect(); + httpUrl.getInputStream(); + InputStream is = httpUrl.getInputStream(); + + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + //创建一个Buffer字符串 + byte[] buffer = new byte[1024]; + //每次读取的字符串长度,如果为-1,代表全部读取完毕 + int len = 0; + //使用一个输入流从buffer里把数据读取出来 + while ((len = is.read(buffer)) != -1) { + //用输出流往buffer里写入数据,中间参数代表从哪个位置开始读,len代表读取的长度 + outStream.write(buffer, 0, len); + } + // 对字节数组Base64编码 + return Base64.getEncoder().encodeToString(outStream.toByteArray()); + } + + /** + * base64字符串解码成文件并保存 + * @param base64 base64字符串 + * @param filePath 保存路径 + * @return 文件路径 + */ + public String decryptByBase64(String base64, String filePath) { + if (base64 == null && filePath == null) { + return null; + } + try { + Files.write(Paths.get(filePath), Base64.getDecoder().decode(base64), StandardOpenOption.CREATE); + } catch (IOException e) { + e.printStackTrace(); + } + return filePath; + } + + /** + * 本地文件转base64 + * @param filePath 文件路径 + * @return base64字符串 + */ + public String encryptToBase64(String filePath) { + if (filePath == null) { + return null; + } + try { + byte[] b = Files.readAllBytes(Paths.get(filePath)); + return Base64.getEncoder().encodeToString(b); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + public static void main(String[] args) { + try { + String base64Str = Base64Util.getBase64ByUrl("http://127.0.0.1:13000/1.png"); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/utils/BigDecimalUtil.java b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/utils/BigDecimalUtil.java new file mode 100644 index 0000000..e10040d --- /dev/null +++ b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/utils/BigDecimalUtil.java @@ -0,0 +1,178 @@ +package com.zhangy.skyeye.util.utils; + +import lombok.experimental.UtilityClass; + +import java.math.BigDecimal; + +/** + * 加减乘除计算 + */ +@UtilityClass +public class BigDecimalUtil { + private BigDecimal bigDecimal; + + /** + * 加法,默认四舍五入 + * + * @param val1 值1 + * @param val2 值2 + * @param scale 保留位数 + * @return 计算后值 + */ + public double add(double val1, double val2, int scale) { + return add(val1, val2, scale, BigDecimal.ROUND_HALF_UP); + } + + /** + * 加法 + * + * @param val1 值1 + * @param val2 值2 + * @param scale 保留位数 + * @param type BigDecimal 进位方式 + * @return 计算后值 + */ + public double add(double val1, double val2, int scale, int type) { + return new BigDecimal(val1 + "").add(new BigDecimal(val2 + "")).setScale(scale, type).doubleValue(); + } + + + /** + * 减法,默认四舍五入 + * + * @param val1 值1 + * @param val2 值2 + * @param scale 保留位数 + * @return 计算后值 + */ + public double subtract(double val1, double val2, int scale) { + return subtract(val1, val2, scale, BigDecimal.ROUND_HALF_UP); + } + + /** + * 减法 + * + * @param val1 值1 + * @param val2 值2 + * @param scale 保留位数 + * @param type BigDecimal 进位方式 + * @return 计算后值 + */ + public double subtract(double val1, double val2, int scale, int type) { + return new BigDecimal(val1 + "").subtract(new BigDecimal(val2 + "")).setScale(scale, type).doubleValue(); + } + + /** + * 乘法,默认四舍五入 + * + * @param val1 值1 + * @param val2 值2 + * @param scale 保留位数 + * @return 计算后值 + */ + public double multiply(double val1, double val2, int scale) { + return multiply(val1, val2, scale, BigDecimal.ROUND_HALF_UP); + } + + /** + * 乘法 + * + * @param val1 值1 + * @param val2 值2 + * @param scale 保留位数 + * @param type BigDecimal 进位方式 + * @return 计算后值 + */ + public double multiply(double val1, double val2, int scale, int type) { + return new BigDecimal(val1 + "").multiply(new BigDecimal(val2 + "")).setScale(scale, type).doubleValue(); + } + + /** + * 除法,默认四舍五入 + * + * @param val1 值1 + * @param val2 值2 + * @param scale 保留位数 + * @return 计算后值 + */ + public double divide(double val1, double val2, int scale) { + return divide(val1, val2, scale, BigDecimal.ROUND_HALF_UP); + } + + /** + * 除法 + * + * @param val1 值1 + * @param val2 值2 + * @param scale 保留位数 + * @param type BigDecimal 进位方式 + * @return 计算后值 + */ + public double divide(double val1, double val2, int scale, int type) { + return new BigDecimal(val1 + "").divide(new BigDecimal(val2 + ""), scale, type).doubleValue(); + } + + /** + * 格式化,默认四舍五入 + * + * @param val1 值 + * @param scale 保留位数 + * @return 格式化后值 + */ + public double format(double val1, int scale) { + return format(val1, scale, BigDecimal.ROUND_HALF_UP); + } + + /** + * 格式化 + * + * @param val1 值 + * @param scale 保留位数 + * @param type BigDecimal 进位方式 + * @return 格式化后值 + */ + public double format(double val1, int scale, int type) { + return new BigDecimal(val1 + "").setScale(scale, type).doubleValue(); + } + + + /** + * 格式化 科学计数法 + * + * @param v + * @param scale + * @param type + * @return + */ + public double formatScientific(double v, int scale, int type) { + String val = new String(v + ""); + if (val.indexOf('-') != -1) { + String[] split = val.split("-"); + int i = Integer.parseInt(split[split.length-1]); + return BigDecimalUtil.format(v, i + scale, type); + } + + if (v >= 1 / Math.pow(10, scale)) { + return BigDecimalUtil.format(v, scale, type); + } + + return v; + } + + public static void main(String[] args) { + System.out.println(BigDecimalUtil.add(1.3331, 2.313, 2)); + System.out.println(BigDecimalUtil.add(1.3331, 2.313, 2, BigDecimal.ROUND_DOWN)); + System.out.println(BigDecimalUtil.subtract(1.3331, 2.313, 2)); + System.out.println(BigDecimalUtil.multiply(1.3331, 2.313, 2)); + System.out.println(BigDecimalUtil.divide(1, 3, 2)); + System.out.println(BigDecimalUtil.format(2.315, 2)); + System.out.println(BigDecimalUtil.format(2.315, 2, BigDecimal.ROUND_DOWN)); + System.out.println(BigDecimalUtil.formatScientific(0.000128932142533, 1, BigDecimal.ROUND_DOWN)); + System.out.println(BigDecimalUtil.formatScientific(-7.957747154594768E-5, 4, BigDecimal.ROUND_DOWN)); + } + + /*public double add(double val1, double val2, int scale, int type) { + return new BigDecimal(val1 + "").add(new BigDecimal(val2 + "")).setScale(scale, type).doubleValue(); + }*/ + +} diff --git a/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/utils/GeoUtil.java b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/utils/GeoUtil.java new file mode 100644 index 0000000..01df784 --- /dev/null +++ b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/utils/GeoUtil.java @@ -0,0 +1,142 @@ +package com.zhangy.skyeye.util.utils; + +import lombok.experimental.UtilityClass; + +import java.util.*; + +@UtilityClass +public class GeoUtil { + + + public static void main(String[] args) { + + List idList = new ArrayList<>(); + List pointList = new ArrayList<>(); + + //初始化id跟点位数据 + idList.add("a1"); + idList.add("a2"); + idList.add("a3"); + idList.add("a4"); + idList.add("a5"); + idList.add("a6"); + idList.add("a7"); + idList.add("a8"); + idList.add("a9"); + idList.add("a10"); + idList.add("a11"); + idList.add("a12"); + idList.add("a13"); + + pointList.add(new Double[]{1.1, 3.1}); + pointList.add(new Double[]{2.1, 1.1}); + pointList.add(new Double[]{2.1, 4.1}); + pointList.add(new Double[]{3.1, 2.1}); + pointList.add(new Double[]{4.1, 1.1}); + pointList.add(new Double[]{5.1, 7.1}); + pointList.add(new Double[]{6.1, 2.1}); + pointList.add(new Double[]{7.1, 5.1}); + pointList.add(new Double[]{8.1, 1.1}); + pointList.add(new Double[]{9.1, 1.1}); + pointList.add(new Double[]{10.1, 55.1}); + pointList.add(new Double[]{11.1, 2.1}); + pointList.add(new Double[]{12.1, 4.1}); + + Map pointMap = new HashMap<>(); + for (int i = 0; i < idList.size(); i++) { + Object o = idList.get(i); + pointMap.put(o, pointList.get(i)); + } + + //调用方法返回聚集集合 + List> gatherIdList = GeoUtil.getGatherIds(idList, pointList, 5, 1); + for (Set set1 : gatherIdList) { + System.out.println("================"); + System.out.println(set1.size()); + for (Object next : set1) { + Double[] doubles = pointMap.get(next); + System.out.println(next + "|" + doubles[0] + "," + doubles[1]); + } + System.out.println("================"); + } + System.out.println(pointList.size()); + } + + /** + * 根据传入的点位算出对应ID的聚集信息 返回的 Set 就是某一地点的聚集人员id集合 + * + * @param idList 坐标对应的实体ID集合 + * @param pointList 坐标集合 + * @param checkDistance 聚集计算距离 + * @param scale 1坐标对应米数 + * @return 聚集人员id集合 + */ + public static List> getGatherIds(List idList, List pointList, int checkDistance, int scale) { + Map disMap = new HashMap<>(); //item与所属cluster中心点的距离 + Map> itemToCluster = new HashMap<>(); //item所属的cluster + Set noSvisitedCandidate = new HashSet<>(); //保存还没处理过的item + for (int i = 0; i < idList.size(); i++) { + noSvisitedCandidate.add(i); + } + + List> resList = new ArrayList<>(); + + //判断是否已全部数据都遍历过 + while (!noSvisitedCandidate.isEmpty()) { + + Set cluster = new HashSet<>(); //保存遍历并属于一组的item + resList.add(cluster); + + Integer centerIndex = noSvisitedCandidate.iterator().next(); + //初始化一个中心点 + cluster.add(idList.get(centerIndex)); + + Double[] centerPoint = pointList.get(centerIndex); + noSvisitedCandidate.remove(centerIndex); + + //遍历开始 + for (int nowIndex = 0; nowIndex < pointList.size(); nowIndex++) { + if (nowIndex == centerIndex) { + continue; + } + Double[] nowPoint = pointList.get(nowIndex); + //计算距离 + double distance = getDistance(centerPoint, nowPoint, scale); + + if (distance < checkDistance * scale) { + //如果遍历中点位已被其他包含,就判断他跟现在中心点的距离是否比它所属的中心点距离小,如果小就把这个点放到新的cluster中 + if (itemToCluster.containsKey(idList.get(nowIndex))) { + Double existingDistance = disMap.get(idList.get(nowIndex)); //原来的中心点距离 + if (distance < existingDistance) { + //删除原来的item与cluster关联 + itemToCluster.get(idList.get(nowIndex)).remove(idList.get(nowIndex)); + } else { + continue; + } + } + + //加入新关系,新距离 + disMap.put(idList.get(nowIndex), distance); + itemToCluster.put(idList.get(nowIndex), cluster); + cluster.add(idList.get(nowIndex)); + + //标记为已处理,删除掉,下次不作为中心点处理 + noSvisitedCandidate.remove(nowIndex); + } + } + + } + return resList; + } + + /** + * 判断两点之间距离 + * + * @param size 1x等于多少米 + * @return + */ + public double getDistance(Double[] x, Double[] y, double size) { + double juli = Math.sqrt(Math.pow(Math.abs(x[0] - y[0]), 2) + Math.pow(Math.abs(x[1] - y[1]), 2)); + return juli * size; + } +} diff --git a/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/utils/IMGUtil.java b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/utils/IMGUtil.java new file mode 100644 index 0000000..34ea005 --- /dev/null +++ b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/utils/IMGUtil.java @@ -0,0 +1,466 @@ +package com.zhangy.skyeye.util.utils; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.util.List; + +/** + * 图片工具类 + */ +public class IMGUtil { + + public static int[][] makeRGBARangeV3() { + int[][] rgbaRange = new int[5][3]; + rgbaRange[0] = new int[]{0, 119, 255}; + rgbaRange[1] = new int[]{0, 255, 17}; + rgbaRange[2] = new int[]{255, 211, 0}; + rgbaRange[3] = new int[]{255, 123, 0}; + rgbaRange[4] = new int[]{255, 0, 0}; + return rgbaRange; + } + + public static int[] getRGBAV3(int[][] rgbaRange, double value) { + return rgbaRange[(int) Math.ceil(value)]; + } + + + /** + * 生成色棒 + * + * @return 色棒数组 + */ + public static int[][] makeRGBARange() { + int[][] rgbaRange = new int[5 * 255][3]; + int index = 0; + + // 1-2 + // {0, 0, 255}蓝色 - {0, 255, 255}天蓝色 + for (int i = 0; i < 255; i++, index++) { + rgbaRange[index] = new int[]{0, i, 255}; + } + + // 2-3 + // {0, 255, 255}天蓝色 - {0, 255, 0}绿色 + for (int i = 255; i > 0; i--, index++) { + rgbaRange[index] = new int[]{0, 255, i}; + } + + // 3-4 + // {0, 255, 0}绿色 - {255, 255, 0}黄色 + for (int i = 0; i < 255; i++, index++) { + rgbaRange[index] = new int[]{i, 255, 0}; + } + + // 4-5 + // {255, 255, 0}黄色 - {255, 0, 0}红色 + for (int i = 255; i > 0; i--, index++) { + rgbaRange[index] = new int[]{255, i, 0}; + } + + return rgbaRange; + } + + /** + * 生成色棒 有0-1维度 + * + * @return 色棒数组 + */ + public static int[][] makeRGBARangeV2() { + int[][] rgbaRange = new int[5 * 255][3]; + int index = 0; + + // 0-1 + // {0, 0, 255}蓝色 + for (int i = 0; i < 255; i++, index++) { + rgbaRange[index] = new int[]{0, 0, 255}; + } + + // 1-2 + // {0, 0, 255}蓝色 - {0, 255, 255}天蓝色 + for (int i = 0; i < 255; i++, index++) { + rgbaRange[index] = new int[]{0, i, 255}; + } + + // 2-3 + // {0, 255, 255}天蓝色 - {0, 255, 0}绿色 + for (int i = 255; i > 0; i--, index++) { + rgbaRange[index] = new int[]{0, 255, i}; + } + + // 3-4 + // {0, 255, 0}绿色 - {255, 255, 0}黄色 + for (int i = 0; i < 255; i++, index++) { + rgbaRange[index] = new int[]{i, 255, 0}; + } + + // 4-5 + // {255, 255, 0}黄色 - {255, 0, 0}红色 + for (int i = 255; i > 0; i--, index++) { + rgbaRange[index] = new int[]{255, i, 0}; + } + + return rgbaRange; + } + + /** + * 生成色棒 绿-天蓝-蓝-黄-红 + * + * @return + */ + public static int[][] makeRGBARangeV4() { + int[][] rgbaRange = new int[5 * 255][3]; + int index = 0; + + // 0-1 + // {0, 255, 0}绿色 + for (int i = 0; i < 255; i++, index++) { + rgbaRange[index] = new int[]{0, 255, 0}; + } + + // 1-2 + // {0, 255, 0}绿色 - {0, 255, 255}天蓝色 + for (int i = 0; i < 255; i++, index++) { + rgbaRange[index] = new int[]{0, 255, i}; + } + + // 2-3 + // {0, 255, 255}天蓝色 - {0, 0, 255}蓝色 + for (int i = 255; i > 0; i--, index++) { + rgbaRange[index] = new int[]{0, i, 255}; + } + + // 3-4 + // {0, 0, 255}蓝色 - {255, 255, 0}黄色 + for (int i = 0; i < 255; i++, index++) { + rgbaRange[index] = new int[]{i, i, 255 - i}; + } + + // 4-5 + // {255, 255, 0}黄色 - {255, 0, 0}红色 + for (int i = 255; i > 0; i--, index++) { + rgbaRange[index] = new int[]{255, i, 0}; + } + + return rgbaRange; + } + + /** + * 生成色棒 绿蓝黄橙红 + * + * @return + */ + public static int[][] makeRGBARangeV5() { + int[][] rgbaRange = new int[5 * 255][3]; + int index = 0; + + // 0-1 + // {0, 255, 0}绿色 + for (int i = 0; i < 255; i++, index++) { + rgbaRange[index] = new int[]{0, 255, 0}; + } + + // 1-2 + // {0, 255, 0}绿色 - {0, 0, 255}蓝色 + for (int i = 0; i < 255; i++, index++) { + rgbaRange[index] = new int[]{0, 255 - i, i}; + } + + // 2-3 + // {0, 0, 255}蓝色 - {255, 255, 0}黄色 + for (int i = 255; i > 0; i--, index++) { + rgbaRange[index] = new int[]{255 - i, 255 - i, i}; + } + + // 3-4 + // {255, 255, 0}黄色 - {255, 127, 0}橙色 + for (int i = 0; i < 255; i++, index++) { + rgbaRange[index] = new int[]{255, 255 - (int) Math.round(i / 2 + 0.5), 0}; + } + + // 4-5 + // {255, 127, 0}橙色 - {255, 0, 0}红色 + for (int i = 0; i < 255; i++, index++) { + rgbaRange[index] = new int[]{255, 128 - (int) Math.round(i / 2 + 0.5), 0}; + } + + return rgbaRange; + } + + /** + * 生成色棒 绿蓝黄橙红,1-2蓝色无渐变 + * + * @return + */ + public static int[][] makeRGBARangeV6() { + int[][] rgbaRange = new int[5 * 255][3]; + int index = 0; + + // 0-1 + // {0, 255, 0}绿色 + for (int i = 0; i < 255; i++, index++) { + rgbaRange[index] = new int[]{0, 255, 0}; + } + + // 1-2 + // {0, 0, 255}蓝色 + for (int i = 0; i < 255; i++, index++) { + rgbaRange[index] = new int[]{0, 0, 255}; + } + + // 2-3 + // {0, 0, 255}蓝色 - {255, 255, 0}黄色 + for (int i = 255; i > 0; i--, index++) { + rgbaRange[index] = new int[]{255 - i, 255 - i, i}; + } + + // 3-4 + // {255, 255, 0}黄色 - {255, 127, 0}橙色 + for (int i = 0; i < 255; i++, index++) { + rgbaRange[index] = new int[]{255, 255 - (int) Math.round(i / 2 + 0.5), 0}; + } + + // 4-5 + // {255, 127, 0}橙色 - {255, 0, 0}红色 + for (int i = 0; i < 255; i++, index++) { + rgbaRange[index] = new int[]{255, 128 - (int) Math.round(i / 2 + 0.5), 0}; + } + + return rgbaRange; + } + + public static int[] getRGBA(int[][] rgbaRange, double value, double maxValue, double minValue) { + double rate = (value - minValue) / (maxValue - minValue); + int index = new Double(rgbaRange.length * rate).intValue(); + return rgbaRange[index >= rgbaRange.length ? rgbaRange.length - 1 : index]; + } + + public static void outFile(BufferedImage image, String filePath) { + File fileFolder = new File(filePath).getParentFile(); + if (!fileFolder.exists()) { + fileFolder.mkdir(); + } + + File file = new File(filePath); + try { + ImageIO.write(image, "png", file); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static String getRiskPicFileName(String type, String orbitType, long time) { + return type + "-" + orbitType + ".png"; + } + + /** + * 生成风险球壳图片 + * + * @param scale 图片放大倍数 + * @param filePath 保存图片目录 + * @param valArr 环境风险等级值数组 double[360][180] + * @param minVal 风险等级最小值 + * @param maxVal 风险等级最大值 + */ + public static void generatePNG(Integer scale, String filePath, double[][] valArr, double minVal, double maxVal) { + generatePNG(scale, filePath, valArr, minVal, maxVal, 10); + } + + + public static void generatePNG(Integer scale, String filePath, double[][] valArr, double minVal, double maxVal, int alpha) { + generatePNG(scale, filePath, valArr, minVal, maxVal, alpha, IMGUtil.makeRGBARange()); + } + + public static void generatePNG(Integer scale, String filePath, double[][] valArr, double minVal, double maxVal, int alpha, int[][] rgbaRanGE) { + generatePNG(scale, filePath, valArr, minVal, maxVal, alpha, rgbaRanGE, null); + } + + /** + * 生成风险球壳图片 + * + * @param scale 图片放大倍数 + * @param filePath 保存图片目录 + * @param valArr 环境风险等级值数组 double[360][180] + * @param minVal 风险等级最小值 + * @param maxVal 风险等级最大值 + * @param alpha 图片透明度 + */ + public static void generatePNG(Integer scale, String filePath, double[][] valArr, double minVal, double maxVal, int alpha, int[][] rgbaRanGE, Double minLevel) { + BufferedImage image = new BufferedImage(360 * scale, 180 * scale, BufferedImage.TYPE_INT_ARGB); + Graphics2D g = image.createGraphics(); + image = g.getDeviceConfiguration().createCompatibleImage(360 * scale, 180 * scale, Transparency.TRANSLUCENT); + g.dispose(); + g = image.createGraphics(); + +// int[][] rgbaRanGE = IMGUtil.makeRGBARange(); + for (int y1 = 0; y1 < 180; ++y1) { + for (int x1 = 0; x1 < 360; ++x1) { + double val = valArr[y1][x1]; + if (minLevel != null && val <= minLevel.doubleValue()) { + continue; + } + int[] rgba = IMGUtil.getRGBA(rgbaRanGE, val, maxVal, minVal); + Color color = new Color(rgba[0], rgba[1], rgba[2], alpha); + g.setColor(color); + /*for (int i = 0; i < scale; i++) { + int tmpX = (x1 * scale) + i; + int tmpY = (180 * scale) - y1 * scale - 1; + for (int j = 0; j < scale; j++) { + g.drawRect(tmpX, tmpY - j, 1, 1); + } + }*/ + //图片下标从-1开始 + for (int i = 0; i < scale; ++i) { + int tmpX = (x1 * scale) + i; + int tmpY = (180 * scale) - (y1 * scale) - 1; + + for (int j = 0; j < scale; ++j) { + g.drawRect(tmpX, tmpY - j, 1, 1); + } + } + } + } + + //补边,先横轴,从-1,-1开始 + int y1 = -1; + for (int x1 = 0; x1 < 360; ++x1) { + + double val = valArr[y1 + 1][x1]; + if (minLevel != null && val <= minLevel.doubleValue()) { + continue; + } + int[] rgba = IMGUtil.getRGBA(rgbaRanGE, val, maxVal, minVal); + Color color = new Color(rgba[0], rgba[1], rgba[2], alpha); + g.setColor(color); + + for (int i = 0; i < scale; ++i) { + int tmpX = (x1 * scale) + i - 1; + int tmpY = y1; + + for (int j = 0; j < scale; ++j) { + g.drawRect(tmpX, tmpY - j, 1, 1); + } + } + } + + //再补纵轴 + int x1 = -1; + for (y1 = 0; y1 < 180; ++y1) { + + double val = valArr[y1][x1 + 1]; + if (minLevel != null && val <= minLevel.doubleValue()) { + continue; + } + int[] rgba = IMGUtil.getRGBA(rgbaRanGE, val, maxVal, minVal); + Color color = new Color(rgba[0], rgba[1], rgba[2], alpha); + g.setColor(color); + + for (int i = 0; i < scale; ++i) { + int tmpX = x1; + int tmpY = (180 * scale) - (y1 * scale) - 1 - i; + + for (int j = 0; j < scale; ++j) { + g.drawRect(tmpX + j, tmpY, 1, 1); + } + } + } + + IMGUtil.outFile(image, filePath); + } + + public static void main(String[] args) { + double val = 3; + double[][] colorArr = new double[180][360]; + + for (int i = 0; i < colorArr.length; i++) { + double[] doubles = colorArr[i]; + for (int j = 0; j < doubles.length; j++) { + doubles[j] = val; + } + } + + generatePNG(1, "D:\\zhangzhe\\files\\upload-files\\env-img\\2.png", colorArr, 0, 5, 60); + System.out.println("完成"); + } + + /** + * 根据数组长度动态生成图片 + * @param scale + * @param filePath + * @param valArr + * @param minVal + * @param maxVal + * @param alpha + * @param rgbaRanGE + */ + public static void generatePNGDynamicSize(Integer scale, String filePath, double[][] valArr, double minVal, double maxVal, int alpha, int[][] rgbaRanGE) { + int width = valArr[0].length; + int height = valArr.length; + BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); + Graphics2D g = image.createGraphics(); + image = g.getDeviceConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT); + g.dispose(); + g = image.createGraphics(); + + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + double val = valArr[y][x]; + if (val == -999999) { + //异常值透明处理 + continue; + } + + if (val < minVal) { + val = minVal; + } + + int[] rgba = IMGUtil.getRGBA(rgbaRanGE, val, maxVal, minVal); + Color color = new Color(rgba[0], rgba[1], rgba[2], alpha); + g.setColor(color); + //width为1,height为0时,只会在xy上绘制一个像素点 + g.drawRect(x, y, 1, 0); + } + } + + IMGUtil.outFile(image, filePath); + } + + /** + * 渐变色棒 + * + * @param colList + * @return + */ + public static int[][] makeRGBARange(List colList) { + int size = colList.size()-1; + int[][] rgbaRange = new int[size * 255][3]; + + int index = 0; + + for (int j = 0; j < size ; j++) { + + Integer[] col = colList.get(j); + Integer[] col2 = colList.get(j + 1); + + for (int i = 0; i < 255; i++, index++) { + Integer a1 = col[0]; + Integer a2 = col[1]; + Integer a3 = col[2]; + + Integer b1 = col2[0]; + Integer b2 = col2[1]; + Integer b3 = col2[2]; + + int i1 = i * (b1 - a1) / 255; + int i2 = i * (b2 - a2) / 255; + int i3 = i * (b3 - a3) / 255; + + rgbaRange[index] = new int[]{a1 + i1, a2 + i2, a3 + i3}; + } + } + + return rgbaRange; + } +} diff --git a/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/utils/LdtUtil.java b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/utils/LdtUtil.java new file mode 100644 index 0000000..e446fa4 --- /dev/null +++ b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/utils/LdtUtil.java @@ -0,0 +1,480 @@ +package com.zhangy.skyeye.util.utils; + +import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.StrUtil; +import com.zhangy.skyeye.util.other.TemporalAccessorUtil; +import com.zhangy.skyeye.util.other.TemporalUtil; + +import java.time.*; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoField; +import java.time.temporal.ChronoUnit; +import java.time.temporal.TemporalAccessor; +import java.time.temporal.TemporalUnit; +import java.util.List; + +/** + * LocalDateTime时间工具类 + */ +public class LdtUtil { + + public static void main(String[] args) { + //转换UTC时间字符串 + String timeStr = "2021-10-01T16:00:00Z"; + LdtUtil ldtUtil = new LdtUtil(); + LocalDateTime parse = ldtUtil.parseUTC(timeStr); + System.out.println(parse); + + //转换中文格式时间字符串 + String timeStr1 = "2021年10月01日"; + LocalDate localDate = ldtUtil.parseDate(timeStr1, LdtUtil.CHINESE_DATE_PATTERN); + System.out.println(localDate); + + //转换斜线格式时间字符串 + String timeStr2 = "2021/10/1"; + String normalize = ldtUtil.normalize(timeStr2); + LocalDate localDate2 = ldtUtil.parseDate(normalize); + System.out.println(localDate2); + + //转换.格式时间字符串 + String timeStr3 = "2021.10.1"; + System.out.println(ldtUtil.normalize(timeStr3)); + + //格式化成时间字符串 + LocalDateTime localDateTime = LocalDateTime.now(); + String format = ldtUtil.format(localDateTime, LdtUtil.UTC_PATTERN); + System.out.println(format); + + //计算时间间隔 + LocalDateTime time1 = LocalDateTime.of(2021, 10, 1, 0, 0, 0); + LocalDateTime time2 = LocalDateTime.of(2021, 10, 2, 0, 0, 0); + + Duration between = ldtUtil.between(time1, time2); + System.out.println(between.toDays()); + + //根据传入的单位返回间隔 + long between1 = ldtUtil.between(time1, time2, ChronoUnit.DAYS); + System.out.println(between1); + + //判断时间是否在指定的时间范围内 + LocalDateTime time3 = LocalDateTime.of(2021, 10, 2, 0, 0, 0); + boolean in = TemporalAccessorUtil.isIn(time3, time1.toLocalDate(), time2.toLocalDate()); + System.out.println(in); + + //获取中文星期 + DayOfWeek dayOfWeek = LocalDateTime.now().getDayOfWeek(); + String weekStr = ldtUtil.toChineseWeek(dayOfWeek); + System.out.println(weekStr); + + LocalDateTime now = LocalDateTime.now(); + now = ldtUtil.offset(now, 2, ChronoUnit.DAYS); + System.out.println(now); + now = ldtUtil.offset(now, 50, ChronoUnit.SECONDS); + System.out.println(now); + + System.out.println(LocalDate.of(2022,5,10).toString()); + System.out.println(LdtUtil.format(LocalDate.now(), LdtUtil.NORM_DATE_PATTERN)); + + System.out.println(LocalTime.now().toString()); + System.out.println(LdtUtil.format(LocalTime.now(),LdtUtil.NORM_TIME_PATTERN)); + } + + /** + * 转换成LocalDateTime + * + * @param dateStr 日期字符串 + * @return {@link LocalDateTime} + */ + public static LocalDateTime parse(CharSequence dateStr) { + return parse(dateStr, NORM_DATETIME_PATTERN); + } + + /** + * 转换成LocalDateTime + * + * @param dateStr 日期字符串 + * @param format 格式 + * @return {@link LocalDateTime} + */ + public static LocalDateTime parse(CharSequence dateStr, String format) { + DateTimeFormatter df = DateTimeFormatter.ofPattern(format); + return LocalDateTime.parse(dateStr, df); + } + + /** + * utc格式转换成LocalDateTime + * + * @param dateStr 日期字符串 + * @return {@link LocalDateTime} + */ + public static LocalDateTime parseUTC(CharSequence dateStr) { + return parse(dateStr, UTC_PATTERN); + } + + /** + * 转换成LocalDate + * + * @param dateStr 日期字符串 + * @return {@link LocalDate} + */ + public static LocalDate parseDate(CharSequence dateStr) { + return LocalDate.parse(normalize(dateStr)); + } + + /** + * 转换成LocalDate + * + * @param dateStr 日期字符串 + * @param format 格式 + * @return {@link LocalDate} + */ + public static LocalDate parseDate(CharSequence dateStr, String format) { + DateTimeFormatter df = DateTimeFormatter.ofPattern(format); + return LocalDate.parse(dateStr, df); + } + + /** + * 转换成LocalTime + * + * @param dateStr 日期字符串 + * @return {@link LocalTime} + */ + public static LocalTime parseTime(CharSequence dateStr) { + return LocalTime.parse(normalize(dateStr)); + } + + /** + * 转换成LocalTime + * + * @param dateStr 日期字符串 + * @param format 格式 + * @return {@link LocalTime} + */ + public static LocalTime parseTime(CharSequence dateStr, String format) { + DateTimeFormatter df = DateTimeFormatter.ofPattern(format); + return LocalTime.parse(dateStr, df); + } + + /** + * 格式化时间 + * + * @param time 时间 + * @param format 格式 + * @return {@link String} + */ + public static String format(LocalDateTime time, String format) { + return TemporalAccessorUtil.format(time, format); + } + + /** + * 格式化时间 + * + * @param time 时间 + * @param format 格式 + * @return {@link String} + */ + public static String format(LocalDate time, String format) { + return TemporalAccessorUtil.format(time, format); + } + + /** + * 格式化时间 + * + * @param time 时间 + * @param format 格式 + * @return {@link String} + */ + public static String format(LocalTime time, String format) { + return TemporalAccessorUtil.format(time, format); + } + + /** + * 获取两个日期的差,如果结束时间早于开始时间,获取结果为负。 + * 返回结果为{@link Duration}对象,通过调用toXXX方法返回相差单位 + * + * @param startTimeInclude 开始时间(包含) + * @param endTimeExclude 结束时间(不包含) + * @return 时间差 {@link Duration}对象 + */ + public static Duration between(LocalDateTime startTimeInclude, LocalDateTime endTimeExclude) { + return TemporalUtil.between(startTimeInclude, endTimeExclude); + } + + /** + * 获取两个日期的差,如果结束时间早于开始时间,获取结果为负。 + * 返回结果为时间差的long值 + * + * @param startTimeInclude 开始时间(包括) + * @param endTimeExclude 结束时间(不包括) + * @param unit 时间差单位 + * @return 时间差 + */ + public static long between(LocalDateTime startTimeInclude, LocalDateTime endTimeExclude, ChronoUnit unit) { + return TemporalUtil.between(startTimeInclude, endTimeExclude, unit); + } + + /** + * 当前日期是否在日期指定范围内
+ * 起始日期和结束日期可以互换 + * + * @param date 被检查的日期 + * @param beginDate 起始日期(包含) + * @param endDate 结束日期(包含) + * @return 是否在范围内 + */ + public static boolean isIn(TemporalAccessor date, TemporalAccessor beginDate, TemporalAccessor endDate) { + return TemporalAccessorUtil.isIn(date, beginDate, endDate); + } + + /** + * 返回中文星期 + * + * @param dayOfWeek 星期对象 + * @return 星期 + */ + public static String toChineseWeek(DayOfWeek dayOfWeek) { + return toChineseWeek(dayOfWeek, "星期"); + } + + /** + * 返回中文星期,可自定义设置前缀 + * + * @param dayOfWeek 星期对象 + * @param weekNamePre 前缀名 + * @return 星期 + */ + public static String toChineseWeek(DayOfWeek dayOfWeek, String weekNamePre) { + String name = dayOfWeek.name(); + switch (name) { + case "SUNDAY": + return weekNamePre + "日"; + case "MONDAY": + return weekNamePre + "一"; + case "TUESDAY": + return weekNamePre + "二"; + case "WEDNESDAY": + return weekNamePre + "三"; + case "THURSDAY": + return weekNamePre + "四"; + case "FRIDAY": + return weekNamePre + "五"; + case "SATURDAY": + return weekNamePre + "六"; + default: + return null; + } + } + + /** + * 日期偏移,根据field不同加不同值(偏移会修改传入的对象) + * + * @param time {@link LocalDateTime} + * @param number 偏移量,正数为向后偏移,负数为向前偏移 + * @param field 偏移单位,见{@link ChronoUnit},不能为null + * @return 偏移后的日期时间 + */ + public static LocalDateTime offset(LocalDateTime time, long number, TemporalUnit field) { + return TemporalUtil.offset(time, number, field); + } + + /** + * 选择单位 + * + * @param period 单位名 + * @return {@link ChronoUnit} + */ + public static ChronoUnit choiceUnit(String period) { + switch (period) { + case "year": + return ChronoUnit.YEARS; + case "month": + return ChronoUnit.MONTHS; + case "day": + return ChronoUnit.DAYS; + case "hour": + return ChronoUnit.HOURS; + case "minute": + return ChronoUnit.MINUTES; + case "second": + return ChronoUnit.SECONDS; + default: + break; + } + return null; + } + + /** + * 规范化字符串 会对一些不规范的日期格式进行格式化, + * 年月日转为`-`分割,时分秒转为`:`分割, + * 并进行补零,如2022-10-1会输出2022-10-01 + * + * @param dateStr 日期字符串 支持格式:2022年10月12日 10时10分10秒,2022/10/2,2022.10.1, + * @return 规范后日期字符串 + */ + public static String normalize(CharSequence dateStr) { + if (StrUtil.isBlank(dateStr)) { + return StrUtil.str(dateStr); + } else { + List dateAndTime = StrUtil.splitTrim(dateStr, ' '); + int size = dateAndTime.size(); + if (size >= 1 && size <= 2) { + StringBuilder builder = StrUtil.builder(); + String datePart = ((String) dateAndTime.get(0)).replaceAll("[/.年月]", "-"); + datePart = StrUtil.removeSuffix(datePart, "日"); + datePart = zeroFill(datePart); + builder.append(datePart); + if (size == 2) { + builder.append(' '); + String timePart = ((String) dateAndTime.get(1)).replaceAll("[时分秒]", ":"); + timePart = StrUtil.removeSuffix(timePart, ":"); + timePart = timePart.replace(',', '.'); + timePart = zeroFill(timePart); + builder.append(timePart); + } + + return builder.toString(); + } else { + return StrUtil.str(dateStr); + } + } + } + + + /** + * 补零,如2022-10-1会输出2022-10-01 + * + * @param dateStr 日期字符串 + * @return 日期字符串 + */ + public static String zeroFill(String dateStr) { + String[] split = dateStr.split("-"); + for (int i = 0; i < split.length; i++) { + if (split[i].length() < 2) { + split[i] = "0" + split[i]; + } + } + return ArrayUtil.join(split, "-"); + } + + + /** + * {@link TemporalAccessor}转{@link LocalDateTime},使用默认时区 + * + * @param temporalAccessor {@link TemporalAccessor} + * @return {@link LocalDateTime} + */ + public static LocalDateTime of(TemporalAccessor temporalAccessor) { + if (null == temporalAccessor) { + return null; + } + + if (temporalAccessor instanceof LocalDate) { + return ((LocalDate) temporalAccessor).atStartOfDay(); + } else if (temporalAccessor instanceof Instant) { + return LocalDateTime.ofInstant((Instant) temporalAccessor, ZoneId.systemDefault()); + } else if (temporalAccessor instanceof ZonedDateTime) { + return ((ZonedDateTime) temporalAccessor).toLocalDateTime(); + } + + return LocalDateTime.of( + TemporalAccessorUtil.get(temporalAccessor, ChronoField.YEAR), + TemporalAccessorUtil.get(temporalAccessor, ChronoField.MONTH_OF_YEAR), + TemporalAccessorUtil.get(temporalAccessor, ChronoField.DAY_OF_MONTH), + TemporalAccessorUtil.get(temporalAccessor, ChronoField.HOUR_OF_DAY), + TemporalAccessorUtil.get(temporalAccessor, ChronoField.MINUTE_OF_HOUR), + TemporalAccessorUtil.get(temporalAccessor, ChronoField.SECOND_OF_MINUTE), + TemporalAccessorUtil.get(temporalAccessor, ChronoField.NANO_OF_SECOND) + ); + } + + /** + * 毫秒转{@link LocalDateTime},使用默认时区 + * + *

注意:此方法使用默认时区,如果非UTC,会产生时间偏移

+ * + * @param epochMilli 从1970-01-01T00:00:00Z开始计数的毫秒数 + * @return {@link LocalDateTime} + */ + public static LocalDateTime of(long epochMilli) { + return of(Instant.ofEpochMilli(epochMilli)); + } + + /** + * yyyy-MM-dd + */ + public static final String NORM_DATE_PATTERN = "yyyy-MM-dd"; + /** + * HH:mm:ss + */ + public static final String NORM_TIME_PATTERN = "HH:mm:ss"; + /** + * yyyy-MM-dd HH:mm + */ + public static final String NORM_DATETIME_MINUTE_PATTERN = "yyyy-MM-dd HH:mm"; + /** + * yyyy-MM-dd HH:mm:ss + */ + public static final String NORM_DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss"; + /** + * yyyy-MM-dd HH:mm:ss.SSS + */ + public static final String NORM_DATETIME_MS_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS"; + /** + * yyyy-MM-dd HH:mm:ss,SSS + */ + public static final String ISO8601_PATTERN = "yyyy-MM-dd HH:mm:ss,SSS"; + /** + * yyyy年MM月dd日 + */ + public static final String CHINESE_DATE_PATTERN = "yyyy年MM月dd日"; + /** + * yyyyMMdd + */ + public static final String PURE_DATE_PATTERN = "yyyyMMdd"; + /** + * HHmmss + */ + public static final String PURE_TIME_PATTERN = "HHmmss"; + /** + * yyyyMMddHHmmss + */ + public static final String PURE_DATETIME_PATTERN = "yyyyMMddHHmmss"; + /** + * yyyyMMddHHmmssSSS + */ + public static final String PURE_DATETIME_MS_PATTERN = "yyyyMMddHHmmssSSS"; + + /** + * yyyyMMddHH + */ + public static final String PURE_DATETIME_HH_PATTERN = "yyyyMMddHH"; + + /** + * EEE, dd MMM yyyy HH:mm:ss z + */ + public static final String HTTP_DATETIME_PATTERN = "EEE, dd MMM yyyy HH:mm:ss z"; + /** + * EEE MMM dd HH:mm:ss zzz yyyy + */ + public static final String JDK_DATETIME_PATTERN = "EEE MMM dd HH:mm:ss zzz yyyy"; + /** + * yyyy-MM-dd'T'HH:mm:ss'Z' + */ + public static final String UTC_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'"; + /** + * yyyy-MM-dd'T'HH:mm:ssZ + */ + public static final String UTC_WITH_ZONE_OFFSET_PATTERN = "yyyy-MM-dd'T'HH:mm:ssZ"; + /** + * yyyy-MM-dd'T'HH:mm:ss.SSS'Z' + */ + public static final String UTC_MS_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; + /** + * yyyy-MM-dd'T'HH:mm:ss.SSSZ + */ + public static final String UTC_MS_WITH_ZONE_OFFSET_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; + /** + * yyyy/MM/dd + */ + public static final String DIAGONAL_DATE_PATTERN = "yyyy/MM/dd"; +} diff --git a/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/utils/NoticeUtil.java b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/utils/NoticeUtil.java new file mode 100644 index 0000000..d906c08 --- /dev/null +++ b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/utils/NoticeUtil.java @@ -0,0 +1,48 @@ +package com.zhangy.skyeye.util.utils; + +import cn.hutool.core.util.IdUtil; +import cn.hutool.http.HttpUtil; +import cn.hutool.json.JSONObject; +import lombok.experimental.UtilityClass; + +@UtilityClass +public class NoticeUtil { + + public void sendDingTalkEventNotice(String url, String typeName, Integer level, String time) { + if (level == 0) { + return; + } + String[] levelArr = new String[]{"蓝色", "黄色", "橙色", "红色"}; + String content = String.format("[空间天气事件预警]:%s发布\n%s【%s】预警", time, typeName, levelArr[level - 1]); + String msgStr = "{\"at\":{\"atMobiles\":[\"\"],\"atUserIds\":[\"\"],\"isAtAll\":true},\"text\":{\"content\":\"" + content + "\"},\"msgtype\":\"text\"}"; + HttpUtil.post(url, msgStr); + } + + public void sendDingTalkEventNoticeV2(String url, String content) { + String msgStr = "{\"at\":{\"atMobiles\":[\"\"],\"atUserIds\":[\"\"],\"isAtAll\":true},\"text\":{\"content\":\"" + content + "\"},\"msgtype\":\"text\"}"; + HttpUtil.post(url, msgStr); + } + + /** + * 飞书机器人 + * + * @param url + * @param content + */ + public void sendFeishuEventNotice(String url, String content) { + JSONObject json = new JSONObject(); + json.put("receive_id", IdUtil.simpleUUID()); + json.put("msg_type", "text"); + JSONObject contJson = new JSONObject(); + contJson.put("text", content + "所有人"); + json.put("content", contJson.toString()); + String res = HttpUtil.post(url, json.toString()); + + } + + /*public static void main(String[] args) { + String content = "[空间天气事件预警]\n" + + "北京时2023年3月15日1时50分,太阳质子事件达到蓝色告警级别,10MeV质子积分通量质子达到10.0。"; + sendFeishuEventNotice("https://open.feishu.cn/open-apis/bot/v2/hook/1db0ec9b-b74a-492a-8a94-398291f67d5c", content); + }*/ +} diff --git a/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/utils/PinYinUtil.java b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/utils/PinYinUtil.java new file mode 100644 index 0000000..ecf3f8b --- /dev/null +++ b/library/skyeye-dev/skyeye-util/src/main/java/com/zhangy/skyeye/util/utils/PinYinUtil.java @@ -0,0 +1,47 @@ +package com.zhangy.skyeye.util.utils; + +import cn.hutool.extra.pinyin.PinyinUtil; +import lombok.experimental.UtilityClass; + +/** + * 姓名拼音筛选工具类 + */ +@UtilityClass +public class PinYinUtil { + + public static void main(String[] args) { + boolean result1 = PinYinUtil.validPinYin("张三", "zs"); + boolean result2 = PinYinUtil.validPinYin("张三","zha"); + boolean result3 = PinYinUtil.validPinYin("张三","zjs"); + System.out.println("result1:"+result1); + System.out.println("result2:"+result2); + System.out.println("result3:"+result3); + } + + /** + * 根据传入的名称和拼音判断是否通过验证 + * @param str 名称 + * @param searchStr 传入的拼音 + * @return 验证结果 + */ + public boolean validPinYin(String str,String searchStr){ + //全拼 + if (PinyinUtil.getPinyin(str).contains(searchStr)) return true; + //拼音首字母 + if (getPinYinGetFirstLetter(str).contains(searchStr)) return true; + return false; + } + + /** + * 获取拼音首字母 + * @param name + * @return 拼音首字母 + */ + private String getPinYinGetFirstLetter(String name){ + String firstStr = ""; + for (int i = 0; i < name.length(); i++) { + firstStr += PinyinUtil.getFirstLetter(name.charAt(i)); + } + return firstStr; + } +} diff --git a/library/skyeye-dev/skyeye-util/src/main/resources/META-INF/spring.factories b/library/skyeye-dev/skyeye-util/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..ab43764 --- /dev/null +++ b/library/skyeye-dev/skyeye-util/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration= diff --git a/library/skyeye-dev/skyeye-util/target/classes/META-INF/spring.factories b/library/skyeye-dev/skyeye-util/target/classes/META-INF/spring.factories new file mode 100644 index 0000000..ab43764 --- /dev/null +++ b/library/skyeye-dev/skyeye-util/target/classes/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration= diff --git a/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/other/TemporalAccessorUtil.class b/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/other/TemporalAccessorUtil.class new file mode 100644 index 0000000..acd70ab Binary files /dev/null and b/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/other/TemporalAccessorUtil.class differ diff --git a/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/other/TemporalUtil$1.class b/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/other/TemporalUtil$1.class new file mode 100644 index 0000000..6ad96ba Binary files /dev/null and b/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/other/TemporalUtil$1.class differ diff --git a/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/other/TemporalUtil.class b/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/other/TemporalUtil.class new file mode 100644 index 0000000..f87be92 Binary files /dev/null and b/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/other/TemporalUtil.class differ diff --git a/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/utils/Base64Util.class b/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/utils/Base64Util.class new file mode 100644 index 0000000..ca27c11 Binary files /dev/null and b/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/utils/Base64Util.class differ diff --git a/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/utils/BigDecimalUtil.class b/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/utils/BigDecimalUtil.class new file mode 100644 index 0000000..82b1f81 Binary files /dev/null and b/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/utils/BigDecimalUtil.class differ diff --git a/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/utils/GeoUtil.class b/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/utils/GeoUtil.class new file mode 100644 index 0000000..4aa871a Binary files /dev/null and b/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/utils/GeoUtil.class differ diff --git a/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/utils/IMGUtil.class b/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/utils/IMGUtil.class new file mode 100644 index 0000000..f4b0df0 Binary files /dev/null and b/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/utils/IMGUtil.class differ diff --git a/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/utils/LdtUtil.class b/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/utils/LdtUtil.class new file mode 100644 index 0000000..538dea2 Binary files /dev/null and b/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/utils/LdtUtil.class differ diff --git a/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/utils/NoticeUtil.class b/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/utils/NoticeUtil.class new file mode 100644 index 0000000..fb9f32c Binary files /dev/null and b/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/utils/NoticeUtil.class differ diff --git a/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/utils/PinYinUtil.class b/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/utils/PinYinUtil.class new file mode 100644 index 0000000..ec68d61 Binary files /dev/null and b/library/skyeye-dev/skyeye-util/target/classes/com/zhangy/skyeye/util/utils/PinYinUtil.class differ diff --git a/library/skyeye-dev/skyeye-util/target/maven-archiver/pom.properties b/library/skyeye-dev/skyeye-util/target/maven-archiver/pom.properties new file mode 100644 index 0000000..18f82f6 --- /dev/null +++ b/library/skyeye-dev/skyeye-util/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=skyeye-util +groupId=com.zhangy +version=1.0.0.RELEASE diff --git a/library/skyeye-dev/skyeye-util/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/library/skyeye-dev/skyeye-util/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..0b5f2a5 --- /dev/null +++ b/library/skyeye-dev/skyeye-util/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,10 @@ +com\zhangy\skyeye\util\utils\NoticeUtil.class +com\zhangy\skyeye\util\other\TemporalUtil.class +com\zhangy\skyeye\util\utils\LdtUtil.class +com\zhangy\skyeye\util\utils\BigDecimalUtil.class +com\zhangy\skyeye\util\other\TemporalUtil$1.class +com\zhangy\skyeye\util\utils\PinYinUtil.class +com\zhangy\skyeye\util\utils\GeoUtil.class +com\zhangy\skyeye\util\utils\Base64Util.class +com\zhangy\skyeye\util\utils\IMGUtil.class +com\zhangy\skyeye\util\other\TemporalAccessorUtil.class diff --git a/library/skyeye-dev/skyeye-util/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/library/skyeye-dev/skyeye-util/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..e3c31fe --- /dev/null +++ b/library/skyeye-dev/skyeye-util/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,9 @@ +D:\logisen\ddd\skyeye-dev\skyeye-util\src\main\java\com\zhangy\skyeye\util\utils\NoticeUtil.java +D:\logisen\ddd\skyeye-dev\skyeye-util\src\main\java\com\zhangy\skyeye\util\utils\PinYinUtil.java +D:\logisen\ddd\skyeye-dev\skyeye-util\src\main\java\com\zhangy\skyeye\util\utils\BigDecimalUtil.java +D:\logisen\ddd\skyeye-dev\skyeye-util\src\main\java\com\zhangy\skyeye\util\other\TemporalUtil.java +D:\logisen\ddd\skyeye-dev\skyeye-util\src\main\java\com\zhangy\skyeye\util\utils\GeoUtil.java +D:\logisen\ddd\skyeye-dev\skyeye-util\src\main\java\com\zhangy\skyeye\util\utils\LdtUtil.java +D:\logisen\ddd\skyeye-dev\skyeye-util\src\main\java\com\zhangy\skyeye\util\utils\IMGUtil.java +D:\logisen\ddd\skyeye-dev\skyeye-util\src\main\java\com\zhangy\skyeye\util\utils\Base64Util.java +D:\logisen\ddd\skyeye-dev\skyeye-util\src\main\java\com\zhangy\skyeye\util\other\TemporalAccessorUtil.java diff --git a/library/skyeye-dev/skyeye-util/target/skyeye-util-1.0.0.RELEASE.jar b/library/skyeye-dev/skyeye-util/target/skyeye-util-1.0.0.RELEASE.jar new file mode 100644 index 0000000..600ce37 Binary files /dev/null and b/library/skyeye-dev/skyeye-util/target/skyeye-util-1.0.0.RELEASE.jar differ diff --git a/library/skyeye-dev/skyeye-websocket/pom.xml b/library/skyeye-dev/skyeye-websocket/pom.xml new file mode 100644 index 0000000..64e31de --- /dev/null +++ b/library/skyeye-dev/skyeye-websocket/pom.xml @@ -0,0 +1,24 @@ + + + + skyeye-dev + com.zhangy + 1.0.0.RELEASE + + 4.0.0 + + skyeye-websocket + + + + + + org.springframework.boot + spring-boot-starter-websocket + + + + + \ No newline at end of file diff --git a/library/skyeye-dev/skyeye-websocket/src/main/java/com/zhangy/skyeye/service/DtWebsocketConfig.java b/library/skyeye-dev/skyeye-websocket/src/main/java/com/zhangy/skyeye/service/DtWebsocketConfig.java new file mode 100644 index 0000000..7053c4f --- /dev/null +++ b/library/skyeye-dev/skyeye-websocket/src/main/java/com/zhangy/skyeye/service/DtWebsocketConfig.java @@ -0,0 +1,18 @@ +package com.zhangy.skyeye.service; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.config.annotation.EnableWebSocket; +import org.springframework.web.socket.server.standard.ServerEndpointExporter; + +@ConditionalOnProperty(name = "tiamo.dev.websocket.tomcat", havingValue = "false", matchIfMissing = true) +@Configuration +@EnableWebSocket +public class DtWebsocketConfig { + + @Bean + public ServerEndpointExporter serverEndpoint() { + return new ServerEndpointExporter(); + } +} diff --git a/library/skyeye-dev/skyeye-websocket/src/main/java/com/zhangy/skyeye/websocket/config/DTStompWebSocketConfig.java b/library/skyeye-dev/skyeye-websocket/src/main/java/com/zhangy/skyeye/websocket/config/DTStompWebSocketConfig.java new file mode 100644 index 0000000..eac6d95 --- /dev/null +++ b/library/skyeye-dev/skyeye-websocket/src/main/java/com/zhangy/skyeye/websocket/config/DTStompWebSocketConfig.java @@ -0,0 +1,201 @@ +package com.zhangy.skyeye.websocket.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.messaging.simp.config.ChannelRegistration; +import org.springframework.messaging.simp.config.MessageBrokerRegistry; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; +import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; +import org.springframework.web.socket.config.annotation.StompEndpointRegistry; +import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; +import org.springframework.web.socket.config.annotation.WebSocketTransportRegistration; + +/** + * <配置基于STOMP的websocket> + **/ +@Configuration +@EnableWebSocketMessageBroker +public class DTStompWebSocketConfig implements WebSocketMessageBrokerConfigurer { + + /** + * 将"/stomp/ws"路径注册为STOMP端点,这个路径与发送和接收消息的目的路径有所不同,这是一个端点,客户端在订阅或发布消息到目的地址前,要连接该端点, + * 即用户发送请求url="/applicationName/stomp/ws"与STOMP server进行连接。之后再转发到订阅url; + * PS:端点的作用——客户端在订阅或发布消息到目的地址前,要连接该端点。 + * + * @param stompEndpointRegistry + */ + @Override + public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) { + + //支持原生websocket连接方式 + stompEndpointRegistry.addEndpoint("/ws") + .setAllowedOriginPatterns("*");//跨域 + + /* + * 1. 将 /serviceName/stomp/ws路径注册为STOMP的端点, + * 用户连接了这个端点后就可以进行websocket通讯,支持socketJs + * 2. setAllowedOrigins("*")表示可以跨域 + * 3. withSockJS()表示支持socktJS访问 + * 4. addInterceptors 添加自定义拦截器,这个拦截器是上一个demo自己定义的获取httpsession的拦截器 + * 5. addInterceptors 添加拦截处理,这里MyPrincipalHandshakeHandler 封装的认证用户信息 + */ + stompEndpointRegistry.addEndpoint("/stomp/ws") + .setAllowedOriginPatterns("*") + //.addInterceptors(new SessionAuthHandshakeInterceptor()) + //.setHandshakeHandler(new MyPrincipalHandshakeHandler()) + .withSockJS(); + } + + /** + * 配置消息代理 + * + * @param registry + */ + @Override + public void configureMessageBroker(MessageBrokerRegistry registry) { + /* + * enableStompBrokerRelay 配置外部的STOMP服务,需要安装额外的支持 比如rabbitmq或activemq + * 1. 配置代理域,可以配置多个,此段代码配置代理目的地的前缀为 /topicTest 或者 /userTest + * 我们就可以在配置的域上向客户端推送消息 + * 3. 可以通过 setRelayHost 配置代理监听的host,默认为localhost + * 4. 可以通过 setRelayPort 配置代理监听的端口,默认为61613 + * 5. 可以通过 setClientLogin 和 setClientPasscode 配置账号和密码 + * 6. setxxx这种设置方法是可选的,根据业务需要自行配置,也可以使用默认配置 + */ + /*registry.enableStompBrokerRelay("/topicTest","/userTest") + .setRelayHost("rabbit.someotherserver") + .setRelayPort(62623); + .setClientLogin("userName") + .setClientPasscode("password");*/ + + // 自定义调度器,用于控制心跳线程 + ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); + // 线程池线程数,心跳连接开线程 + taskScheduler.setPoolSize(1); + // 线程名前缀 + taskScheduler.setThreadNamePrefix("websocket-heartbeat-thread-"); + // 初始化 + taskScheduler.initialize(); + + /* + * spring 内置broker对象 + * 1. 配置代理域,可以配置多个,此段代码配置代理目的地的前缀为 /topicTest 或者 /userTest + * 我们就可以在配置的域上向客户端推送消息 + * 2,进行心跳设置,第一值表示server最小能保证发的心跳间隔毫秒数, 第二个值代码server希望client发的心跳间隔毫秒数 + * 3. 可以配置心跳线程调度器 setHeartbeatValue这个不能单独设置,不然不起作用,要配合setTaskScheduler才可以生效 + * 调度器我们可以自己写一个,也可以自己使用默认的调度器 new DefaultManagedTaskScheduler() + */ + registry.enableSimpleBroker("/topic", "/user") + .setHeartbeatValue(new long[]{10000, 10000}) + .setTaskScheduler(taskScheduler); + /* + * "/app" 为配置应用服务器的地址前缀,表示所有以/app 开头的客户端消息或请求 + * 都会路由到带有@MessageMapping 注解的方法中 + */ + registry.setApplicationDestinationPrefixes("/app"); + + /* + * 1. 配置一对一消息前缀, 客户端接收一对一消息需要配置的前缀 如“'/user/'+userid + '/message'”, + * 是客户端订阅一对一消息的地址 stompClient.subscribe js方法调用的地址 + * 2. 使用@SendToUser发送私信的规则不是这个参数设定,在框架内部是用UserDestinationMessageHandler处理, + * 而不是而不是 AnnotationMethodMessageHandler 或 SimpleBrokerMessageHandler + * or StompBrokerRelayMessageHandler,是在@SendToUser的URL前加“user+sessionId"组成 + */ + registry.setUserDestinationPrefix("/user"); + + /* + * 自定义路径分割符 + * 注释掉的这段代码添加的分割符为. 分割是类级别的@messageMapping和方法级别的@messageMapping的路径 + * 例如类注解路径为 “topic”,方法注解路径为“hello”,那么客户端JS stompClient.send 方法调用的路径为“/app/topic.hello” + * 注释掉此段代码后,类注解路径“/topic”,方法注解路径“/hello”,JS调用的路径为“/app/topic/hello” + */ + //registry.setPathMatcher(new AntPathMatcher(".")); + + } + + /** + * 配置发送与接收的消息参数,可以指定消息字节大小,缓存大小,发送超时时间 + * + * @param registration + */ + @Override + public void configureWebSocketTransport(WebSocketTransportRegistration registration) { + /* + * 1. setMessageSizeLimit 设置消息缓存的字节数大小 字节 + * 2. setSendBufferSizeLimit 设置websocket会话时,缓存的大小 字节 + * 3. setSendTimeLimit 设置消息发送会话超时时间,毫秒 + */ + registration.setMessageSizeLimit(502400) + .setSendBufferSizeLimit(502400) + .setSendTimeLimit(10000); + } + + /** + * 设置输入消息通道的线程数,默认线程为1,可以自己自定义线程数,最大线程数,线程存活时间 + * + * @param registration + */ + @Override + public void configureClientInboundChannel(ChannelRegistration registration) { + + /* + * 配置消息线程池 + * 1. corePoolSize 配置核心线程池,当线程数小于此配置时,不管线程中有无空闲的线程,都会产生新线程处理任务 + * 2. maxPoolSize 配置线程池最大数,当线程池数等于此配置时,不会产生新线程 + * 3. keepAliveSeconds 线程池维护线程所允许的空闲时间,单位秒 + */ + registration.taskExecutor().corePoolSize(10) + .maxPoolSize(20) + .keepAliveSeconds(60); + /* + * 添加stomp自定义拦截器,可以根据业务做一些处理 + * springframework 4.3.12 之后版本此方法废弃,代替方法 interceptors(ChannelInterceptor... interceptors) + * 消息拦截器,实现ChannelInterceptor接口 + */ +// registration.interceptors(webSocketChannelInterceptor()); + } + + /** + * 设置输出消息通道的线程数,默认线程为1,可以自己自定义线程数,最大线程数,线程存活时间 + * + * @param registration + */ + @Override + public void configureClientOutboundChannel(ChannelRegistration registration) { + registration.taskExecutor().corePoolSize(10) + .maxPoolSize(20) + .keepAliveSeconds(60); + //registration.interceptors(new WebSocketChannelInterceptor()); + } + + /** + * 添加自定义的消息转换器,spring 提供多种默认的消息转换器, + * 返回false,不会添加消息转换器,返回true,会添加默认的消息转换器,当然也可以把自己写的消息转换器添加到转换链中 + * + * @param list + * @return + */ + /*@Override + public boolean configureMessageConverters(List list) { + return true; + }*/ + + /** + * 自定义控制器方法的参数类型,有兴趣可以百度google HandlerMethodArgumentResolver这个的用法 + * @param list + */ + /*@Override + public void addArgumentResolvers(List list) { + + }*/ + + /** + * 自定义控制器方法返回值类型,有兴趣可以百度google HandlerMethodReturnValueHandler这个的用法 + * @param list + */ + /*@Override + public void addReturnValueHandlers(List list) { + + }*/ + + +} \ No newline at end of file diff --git a/library/skyeye-dev/skyeye-websocket/src/main/resources/META-INF/spring.factories b/library/skyeye-dev/skyeye-websocket/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..cd050d7 --- /dev/null +++ b/library/skyeye-dev/skyeye-websocket/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.zhangy.skyeye.websocket.config.DTStompWebSocketConfig diff --git a/library/skyeye-dev/skyeye-websocket/target/classes/META-INF/spring.factories b/library/skyeye-dev/skyeye-websocket/target/classes/META-INF/spring.factories new file mode 100644 index 0000000..cd050d7 --- /dev/null +++ b/library/skyeye-dev/skyeye-websocket/target/classes/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.zhangy.skyeye.websocket.config.DTStompWebSocketConfig diff --git a/library/skyeye-dev/skyeye-websocket/target/classes/com/zhangy/skyeye/service/DtWebsocketConfig.class b/library/skyeye-dev/skyeye-websocket/target/classes/com/zhangy/skyeye/service/DtWebsocketConfig.class new file mode 100644 index 0000000..1a33362 Binary files /dev/null and b/library/skyeye-dev/skyeye-websocket/target/classes/com/zhangy/skyeye/service/DtWebsocketConfig.class differ diff --git a/library/skyeye-dev/skyeye-websocket/target/classes/com/zhangy/skyeye/websocket/config/DTStompWebSocketConfig.class b/library/skyeye-dev/skyeye-websocket/target/classes/com/zhangy/skyeye/websocket/config/DTStompWebSocketConfig.class new file mode 100644 index 0000000..854d436 Binary files /dev/null and b/library/skyeye-dev/skyeye-websocket/target/classes/com/zhangy/skyeye/websocket/config/DTStompWebSocketConfig.class differ diff --git a/library/skyeye-dev/skyeye-websocket/target/maven-archiver/pom.properties b/library/skyeye-dev/skyeye-websocket/target/maven-archiver/pom.properties new file mode 100644 index 0000000..b2b4128 --- /dev/null +++ b/library/skyeye-dev/skyeye-websocket/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=skyeye-websocket +groupId=com.zhangy +version=1.0.0.RELEASE diff --git a/library/skyeye-dev/skyeye-websocket/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/library/skyeye-dev/skyeye-websocket/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..85dd24a --- /dev/null +++ b/library/skyeye-dev/skyeye-websocket/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,2 @@ +com\zhangy\skyeye\service\DtWebsocketConfig.class +com\zhangy\skyeye\websocket\config\DTStompWebSocketConfig.class diff --git a/library/skyeye-dev/skyeye-websocket/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/library/skyeye-dev/skyeye-websocket/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..d7f8515 --- /dev/null +++ b/library/skyeye-dev/skyeye-websocket/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,2 @@ +D:\logisen\ddd\skyeye-dev\skyeye-websocket\src\main\java\com\zhangy\skyeye\websocket\config\DTStompWebSocketConfig.java +D:\logisen\ddd\skyeye-dev\skyeye-websocket\src\main\java\com\zhangy\skyeye\service\DtWebsocketConfig.java diff --git a/library/skyeye-dev/skyeye-websocket/target/skyeye-websocket-1.0.0.RELEASE.jar b/library/skyeye-dev/skyeye-websocket/target/skyeye-websocket-1.0.0.RELEASE.jar new file mode 100644 index 0000000..f2626c1 Binary files /dev/null and b/library/skyeye-dev/skyeye-websocket/target/skyeye-websocket-1.0.0.RELEASE.jar differ diff --git a/library/skyeye/1.0.0.RELEASE/skyeye-1.0.0.RELEASE.pom b/library/skyeye/1.0.0.RELEASE/skyeye-1.0.0.RELEASE.pom new file mode 100644 index 0000000..54c7172 --- /dev/null +++ b/library/skyeye/1.0.0.RELEASE/skyeye-1.0.0.RELEASE.pom @@ -0,0 +1,257 @@ + + + + 4.0.0 + + com.zhangy + skyeye + 1.0.0.RELEASE + pom + Skyeye parent project + + + org.springframework.boot + spring-boot-starter-parent + 2.7.8 + + + + 1.0.0.RELEASE + 1.8 + UTF-8 + 2.7.8 + 2021.0.5 + + 1.2.75 + 2.0.8 + 8.0.21 + 5.3.8 + 3.4.1 + 1.1.22 + 1.18.16 + + 2.2.0 + + + + 3.11.0 + 3.2.0 + 3.13.6 + 1.9.4 + 29.0-jre + 2.6 + + + 1.7.1 + 3.1.0 + 1.3.3 + + + 1.3.4 + + + + + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + + + + + + + org.redisson + redisson + ${redisson.version} + + + + + + + + cn.hutool + hutool-all + ${hutool-all.version} + + + + + commons-beanutils + commons-beanutils + ${commons-beanutils.version} + + + + + commons-fileupload + commons-fileupload + 1.4 + + + commons-io + commons-io + + + + + + + com.auth0 + java-jwt + ${java-jwt.version} + + + + + + + + com.github.xiaoymin + knife4j-spring-boot-starter + ${knife4j.version} + + + + + com.github.xiaoymin + knife4j-micro-spring-boot-starter + ${knife4j.version} + + + + + com.baomidou + mybatis-plus-boot-starter + ${mybatis-plus.version} + + + + + com.baomidou + mybatis-plus-generator + ${mybatis-plus.version} + + + + + com.alibaba + druid-spring-boot-starter + ${druid.version} + + + + + mysql + mysql-connector-java + ${mysql-connector-java.version} + runtime + + + + + com.alibaba + fastjson + ${fastjson.version} + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + UTF-8 + + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + + + src/main/resources + true + + + src/main/java + + **/*.xml + **/*.json + **/*.ftl + + + + + + + + + releases + Nexue Release Repository + http://127.0.0.1:8081/repository/maven-releases/ + + + + snapshots + Nexue Snapshot Repository + http://127.0.0.1:8081/repository/maven-snapshots/ + + + + + \ No newline at end of file diff --git a/library/skyeye/1.0.0.RELEASE/skyeye-1.0.0.RELEASE.pom.lastUpdated b/library/skyeye/1.0.0.RELEASE/skyeye-1.0.0.RELEASE.pom.lastUpdated new file mode 100644 index 0000000..09e7ce1 --- /dev/null +++ b/library/skyeye/1.0.0.RELEASE/skyeye-1.0.0.RELEASE.pom.lastUpdated @@ -0,0 +1,4 @@ +#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice. +#Mon Jan 12 18:02:06 CST 2026 +https\://repo.maven.apache.org/maven2/.lastUpdated=1768212126438 +https\://repo.maven.apache.org/maven2/.error=