diff --git a/.gitignore b/.gitignore index 9154f4c..15cc7a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ -# ---> Java # Compiled class file *.class +*.iml +*.idea +target/ +logs/ # Log file *.log @@ -14,13 +17,34 @@ # Package Files # *.jar *.war -*.nar *.ear -*.zip *.tar.gz *.rar # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* -replay_pid* +*velocity.log* + +# Eclipse # +.classpath +.project +.settings/ + +.DS_Store + +_dockerCerts/ + +.factorypath + +node_modules/ +package-lock.json +yarn.lock + +rebel.xml + +!DmJdbcDriver18.jar +!kingbase8-8.6.0.jar +/.fastRequest/collections/Root/Default Group/directory.json +/.fastRequest/collections/Root/directory.json +/.fastRequest/config/fastRequestCurrentProjectConfig.json diff --git a/njcn-common/pom.xml b/njcn-common/pom.xml new file mode 100644 index 0000000..d724b17 --- /dev/null +++ b/njcn-common/pom.xml @@ -0,0 +1,113 @@ + + + + com.njcn + BasicDependVersion + 1.0.0 + + 4.0.0 + njcn-common + 0.0.1 + jar + 聚合所有服务模块公共信息 + + + 8 + 8 + 1.18.18 + 5.8.25 + 3.12.0 + 2.8.0 + 1.15 + 1.68 + 2.13.4.1 + 2.17.0 + 1.7.32 + 1.2.12 + + + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + ch.qos.logback + logback-classic + ${logback.version} + + + + + + + org.projectlombok + lombok + ${lombok.version} + + + + + cn.hutool + hutool-all + ${hutool.version} + + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + + commons-io + commons-io + ${commons-io.version} + + + + commons-codec + commons-codec + ${commons-codec.version} + + + + + org.bouncycastle + bcprov-jdk15on + ${bcprov-jdk15on.version} + + + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson.jsr310.version} + + + + + org.springframework.boot + spring-boot-starter-json + ${spring-boot.version} + + + ch.qos.logback + logback-classic + + + + + + \ No newline at end of file diff --git a/njcn-common/src/main/java/com/njcn/common/bean/CustomCacheUtil.java b/njcn-common/src/main/java/com/njcn/common/bean/CustomCacheUtil.java new file mode 100644 index 0000000..c6560fb --- /dev/null +++ b/njcn-common/src/main/java/com/njcn/common/bean/CustomCacheUtil.java @@ -0,0 +1,75 @@ +package com.njcn.common.bean; + +import cn.hutool.cache.CacheUtil; +import cn.hutool.cache.impl.TimedCache; +import cn.hutool.core.date.DateUnit; +import cn.hutool.extra.spring.SpringUtil; +import org.springframework.stereotype.Component; + +import java.util.Objects; + +@Component(value = "internalStorageCache") +public class CustomCacheUtil { + + public static final String CACHE_NAME = "internalStorageCache"; + + public TimedCache timedCache; + + public CustomCacheUtil() { + //初始化一个定时缓存 + this.timedCache = initTimedCache(); + //启动定时任务,每60秒清理一次过期条目 + this.timedCache.schedulePrune(60*1000); + } + + /** + * 默认缓存30分钟 + */ + public static TimedCache initTimedCache() { + return CacheUtil.newTimedCache(DateUnit.MINUTE.getMillis() * 30); + } + + /** + * 添加缓存 + * 采用默认缓存时间 + */ + public void put(String key, String value) { + if (Objects.isNull(timedCache)) { + //初始化一个定时缓存 + this.timedCache = initTimedCache(); + //启动定时任务,每60秒清理一次过期条目 + timedCache.schedulePrune(60*1000); + } + timedCache.put(key, value); + } + + /** + * 添加缓存 + * 指定缓存时间 毫秒级别 + */ + public void putWithExpireTime(String key, String value, long expireTime) { + if (Objects.isNull(timedCache)) { + //初始化一个定时缓存 + this.timedCache = initTimedCache(); + //启动定时任务,每60秒清理一次过期条目 + timedCache.schedulePrune(60*1000); + } + timedCache.put(key, value, expireTime); + } + + + /** + * 获取缓存值, + * @param key 缓存key + * @param flush 是否重置生命周期 true 重置,false 不重置 + */ + public String get(String key,boolean flush) { + if (Objects.isNull(timedCache)) { + //初始化一个定时缓存 + this.timedCache = initTimedCache(); + //启动定时任务,每60秒清理一次过期条目 + timedCache.schedulePrune(60*1000); + } + return timedCache.get(key,flush); + } +} diff --git a/njcn-common/src/main/java/com/njcn/common/pojo/annotation/OperateInfo.java b/njcn-common/src/main/java/com/njcn/common/pojo/annotation/OperateInfo.java new file mode 100644 index 0000000..48d1db8 --- /dev/null +++ b/njcn-common/src/main/java/com/njcn/common/pojo/annotation/OperateInfo.java @@ -0,0 +1,30 @@ +package com.njcn.common.pojo.annotation; + +import com.njcn.common.pojo.constant.OperateType; +import com.njcn.common.pojo.enums.common.LogEnum; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2021年07月07日 15:51 + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface OperateInfo { + + /** + * 默认为业务事件类型,严重度为普通 + */ + LogEnum info() default LogEnum.BUSINESS_COMMON; + + /** + * 默认为查询操作类型 + */ + String operateType() default OperateType.QUERY; + +} diff --git a/njcn-common/src/main/java/com/njcn/common/pojo/constant/BizParamConstant.java b/njcn-common/src/main/java/com/njcn/common/pojo/constant/BizParamConstant.java new file mode 100644 index 0000000..66f3b20 --- /dev/null +++ b/njcn-common/src/main/java/com/njcn/common/pojo/constant/BizParamConstant.java @@ -0,0 +1,20 @@ +package com.njcn.common.pojo.constant; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2022年10月10日 09:30 + */ +public interface BizParamConstant { + + /** + * 前端查询时间类型 + * 1年 2季度 3月份 4周 5日 + */ + String STAT_BIZ_YEAR = "1"; + String STAT_BIZ_QUARTER = "2"; + String STAT_BIZ_MONTH = "3"; + String STAT_BIZ_WEEK = "4"; + String STAT_BIZ_DAY = "5"; + +} diff --git a/njcn-common/src/main/java/com/njcn/common/pojo/constant/LogInfo.java b/njcn-common/src/main/java/com/njcn/common/pojo/constant/LogInfo.java new file mode 100644 index 0000000..3143e03 --- /dev/null +++ b/njcn-common/src/main/java/com/njcn/common/pojo/constant/LogInfo.java @@ -0,0 +1,24 @@ +package com.njcn.common.pojo.constant; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2021年07月07日 15:33 + */ +public interface LogInfo { + + String UNKNOWN_OPERATE = "unknown operate"; + + String UNKNOWN_USER = "unknown user"; + /*解析登陆角色jsonarray转list*/ + String UNKNOWN_ROLE = "[\"unknown role\"]"; + + String UNKNOWN_IP = "unknown IP"; + + String UNKNOWN_CLIENT = "unknown client"; + + String UNKNOWN_SERVER = "unknown sever"; + + String UNKNOWN_DEPT = "unknown department"; + +} diff --git a/njcn-common/src/main/java/com/njcn/common/pojo/constant/OperateType.java b/njcn-common/src/main/java/com/njcn/common/pojo/constant/OperateType.java new file mode 100644 index 0000000..fb55a62 --- /dev/null +++ b/njcn-common/src/main/java/com/njcn/common/pojo/constant/OperateType.java @@ -0,0 +1,31 @@ +package com.njcn.common.pojo.constant; + +/** + * 系统操作类型 + * + * @author hongawen + * @version 1.0.0 + * @date 2021年07月08日 17:56 + */ +public interface OperateType { + + String QUERY = "查询"; + + String ADD = "新增"; + + String DELETE = "删除"; + + String UPDATE = "更新"; + + String AUTHENTICATE = "认证"; + + String LOGOUT = "注销"; + + String UPLOAD = "上传"; + + String DOWNLOAD = "下载"; + + + + +} diff --git a/njcn-common/src/main/java/com/njcn/common/pojo/constant/PatternRegex.java b/njcn-common/src/main/java/com/njcn/common/pojo/constant/PatternRegex.java new file mode 100644 index 0000000..1434e57 --- /dev/null +++ b/njcn-common/src/main/java/com/njcn/common/pojo/constant/PatternRegex.java @@ -0,0 +1,256 @@ +package com.njcn.common.pojo.constant; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2021年05月19日 12:52 + */ +public interface PatternRegex { + + /** + * URL + */ + String URL_REGEX = "[a-zA-z]+://[^\\s]*"; + + /** + * 密码需要包含特殊字符字母数字,长度为8-16 + */ + String PASSWORD_REGEX = "^(?=.*[a-zA-Z])(?=.*\\d)(?=.*[\\=\\[\\]\\{\\}\\.\\,\\。\\、\\@\\#\\_\\!\\$\\%\\^\\&\\*\\(\\)\\?\\<\\>\\/\\|\\~,\\-\\+]).{8,16}$"; + + /** + * APP密码,长度为8-16 + */ + String APP_PASSWORD_REGEX = "^.{8,16}$"; + + + /** + * 手机的密码 + */ + String PASSWORD_PHONE_REGEX = "^.{6,18}$"; + + /** + * 用户名中英文,长度1-16 + */ + String USERNAME_REGEX = "^[\\u4e00-\\u9fffa-zA-Z]{1,16}$"; + + /** + * 概览配置界面名称 + */ + String HOMEPAGE_REGEX = "^[\\u4e00-\\u9fa5]{1,10}$"; + + /** + * 登录名只能输入3-16位的英文字母或数字 + */ + String LOGIN_NAME_REGEX = "^[a-zA-Z_.]{1}[a-zA-Z0-9_.]{2,15}$"; + + /** + * 手机号必须有11位,并且为数字,是正常的手机·号码开头 + */ + String PHONE_REGEX = "(?:0|86|\\+86)?1[3-9]\\d{9}"; + + /** + * 手机号码可以为空,如果输入手机号就要正则匹配 + */ + String PHONE_REGEX_OR_NULL = "^\\s{0}$|(?:0|86|\\+86)?1[3-9]\\d{9}"; + + /** + * 邮箱含有@ .在@后,以.com、.con结尾(qq,163等) + */ + String EMAIL_REGEX = "^([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+\\.(?:com|cn)$"; + + /** + * 邮箱可以为空,如果输入邮箱就要进行正则匹配,邮箱含有@ .在@后,以.com、.con结尾(qq,163等) + */ + String EMAIL_REGEX_OR_NULL = "^\\s{0}$|([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+\\.(?:com|cn)$"; + + /** + * IP v4 + */ + String IP_REGEX = "\\b((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\.((?!\\d\\d\\d)\\d+|1\\d\\d|2[0-4]\\d|25[0-5])\\b"; + + /** + * 角色名由数字、字母组成且长度为2-50 + */ + String ROLE_REGEX = "^[a-zA-Z][a-zA-Z0-9]{2,50}$"; + + /** + * 部门名称由汉字组成,长度为0-20 + */ + String DEPT_NAME_REGEX = "^[\\u4e00-\\u9fa5]{1,20}$"; + + /** + * 字典名称包括中文、数字、字母、罗马数字、括号以及点号 + */ + String DIC_REGEX = "^[\\w\\u4E00-\\u9FA5()()_/、/, /,\\- ]+\\.?[\\w\\u4E00-\\u9FA5()()I II III IV V /]{0,125}$"; + + /** + * 密码有效期(月)1-3月 + */ + String PASS_MONTH_REGEX = "^[1-3]{1}$"; + + /** + * 密码错误次数 1-10次 + */ + String PASS_ERROR_REGEX = "^([1-9]|10)$"; + + /** + * 最大并发数 1-99次 + */ + String MAX_NUM_REGEX = "^([1-9]{1}|[0-9]{2})$"; + + /** + * 闲置用户_修改密码 6-12 + */ + String PASS_UPW_REGEX = "^([6-9]{1}|10|11|12)$"; + + /** + * 临时账户休眠 1-12 + */ + String FREE_MONTH_REGEX = "^([1-9]{1}|10|11|12)$"; + + /** + * 审计存储空间 1-2G + */ + String LOG_SIZE_REGEX = "^[1-2]{1}$"; + + /** + * 用户锁定时长20-60min + */ + String USER_LOCK_REGEX = "^[2-5][0-9]|60$"; + + /** + * 台账名称 前置机名称 供电公司 变电站 + */ + String DEV_NAME_REGEX = "[\\u4E00-\\u9FA5A-Za-z0-9ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩ_\\s+\\#\\-]{1,32}$"; + + /** + * 浮点数 + */ + String FLOAT_REGEX = "[0-9]*(\\.?)[0-9]*"; + + /** + * 识别码秘钥 + */ + String SERIES_REGEX = "[^\\u4e00-\\u9fa5]{0,20}$"; + + /** + * ip分段 + */ + String SIP_REGEX = "[0-9]{1,3}$"; + + /** + * 端口号 + */ + String PORT_REGEX = "[0-9]{1,10}$"; + + /** + * 备注 + */ + String REMARK_REGEX = "[\\u4E00-\\u9FA5A-Za-z0-9_]{0,255}$"; + + /** + * 国网平台监测点号 + */ + String MONITOR_ID_REGEX = "[A-Za-z0-9]{0,255}$"; + + /** + * 变压器名称 + */ + String TRANS_NAME_REGEX = "^[0-9a-zA-Z\\u0391-\\uFFE5]{1,50}$"; + + /** + * 变压器策略名称 + */ + String TF_NAME_REGEX = "^[0-9a-zA-Z\\u0391-\\uFFE5]{1,16}$"; + + /** + * 字典类型名称 + */ + String TYPE_REGEX = "^[0-9a-zA-Z\\u0391-\\uFFE5]{1,100}$"; + + /** + * 描述64 + */ + String DES64_REGEX = "^.{0,64}$"; + + /** + * 描述200 + */ + String DES200_REGEX = "^.{0,200}$"; + + /** + * 描述500 + */ + String DES500_REGEX = "^.{0,500}$"; + + /** + * mac地址 + */ + String MAC_REGEX = "((?:[A-F0-9]{1,2}[:-]){5}[A-F0-9]{1,2})|(?:0x)(\\d{12})(?:.+ETHER)"; + + /** + * 流量套餐 + */ + String DATA_PLAN_REGEX = "[0-9]{0,6}$"; + + /** + * 十六进制颜色 + */ + String COLOR_REGEX = "^#([a-fA-F\\d]{3}|[a-fA-F\\d]{6})$"; + + /** + * 描述64 + */ + String DES10_REGEX = "^.{1,10}$"; + + /** + * 大于0的正整数 + */ + String POSITIVE = "^[0-9].*$"; + + /** + * 资源名称 + */ + String FUNCTION_NAME = "^[\\u4e00-\\u9fa5A-Za-z0-9_]+$"; + + /** + * 资源路径 + */ + String FUNCTION_URL = "^[A-Za-z0-9\\/\\-]+$"; + + /** + * 匹配数字、字母、中文 + */ + String NORMAL = "^[A-Za-z0-9\\u4e00-\\u9fa5]+$"; + + + /** + * 任意字符,长度在1-20位,常用于名称、编码等常规录入 + */ + String ALL_CHAR_1_20 = "^[-_A-Za-z0-9\\u4e00-\\u9fa5]{1,20}$"; + + /** + * uuid 32位正则,数字 、 字母 + */ + String SYSTEM_ID = "^[A-Za-z0-9]{32}$"; + + /** + * 1-32位正则,数字 、 字母 + */ + String SYSTEMS_ID = "^[A-Za-z0-9]{1,32}$"; + + /** + * decimal(10,6) 10位数字,小数点最多6位(坐标) + */ + String COORDINATE="^([0-9]{1,4})([.][0-9]{1,6})?$"; + + /** + * 时间正则(日期) + */ + String TIME_FORMAT = "^$|(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)$"; + + /** + * 时间正则(秒) + */ + String TIME_SECOND_FORMAT = "^((([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29))\\s+([0-1]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$"; +} diff --git a/njcn-common/src/main/java/com/njcn/common/pojo/constant/SecurityConstants.java b/njcn-common/src/main/java/com/njcn/common/pojo/constant/SecurityConstants.java new file mode 100644 index 0000000..ecbe190 --- /dev/null +++ b/njcn-common/src/main/java/com/njcn/common/pojo/constant/SecurityConstants.java @@ -0,0 +1,152 @@ +package com.njcn.common.pojo.constant; + +/** + * 认证业务用到的常量定义 + * + * @author hongawen + */ +public interface SecurityConstants { + + /** + * 认证请求头key + * 1. 获取token时,Authorization的内容是client:secret的base64的密文 + * 2. 已经认证后,Authorization的内容是access_token内容 + */ + String AUTHORIZATION_KEY = "Authorization"; + + /** + * JWT令牌前缀 + */ + String AUTHORIZATION_PREFIX = "bearer "; + + /** + * Basic认证前缀 + */ + String BASIC_PREFIX = "Basic "; + + /** + * JWT载体key + */ + String JWT_PAYLOAD_KEY = "payload"; + + /** + * JWT ID 唯一标识 + */ + String JWT_JTI = "jti"; + + /** + * JWT ID 超时key + */ + String JWT_EXP = "exp"; + + /** + * 认证成功后,返回信息包含的内容- + */ + String USER_INDEX_KEY = "userIndex"; + String USER_TYPE = "userType"; + String USER_NAME_KEY = "user_name"; + String USER_HEAD_KEY = "headSculpture"; + String USER_NICKNAME_KEY = "nickname"; + String CLIENT_ID_KEY = "client_id"; + String DEPT_INDEX_KEY = "deptIndex"; + + /** + * 认证方式 + */ + String AUTHENTICATION_METHOD = "authenticationMethod"; + + /** + * JWT存储权限前缀 + */ + String AUTHORITY_PREFIX = "ROLE_"; + + /** + * JWT存储权限属性 + */ + String JWT_AUTHORITIES_KEY = "authorities"; + + String GRANT_TYPE_KEY = "grant_type"; + + String REFRESH_TOKEN_KEY = "refresh_token"; + + /** + * 黑名单token前缀 + */ + String TOKEN_BLACKLIST_PREFIX = "auth:token:black:"; + + /** + * 认证后token前缀 + */ + String TOKEN_ONLINE_PREFIX = "auth:token:online:"; + + + /** + * 真实客户端IP地址 + */ + String REQUEST_HEADER_KEY_CLIENT_REAL_IP = "realClientIp"; + + + /** + * 认证需要的各项参数名 + */ + String GRANT_TYPE = "grant_type"; + String CLIENT_ID = "client_id"; + String CLIENT_SECRET = "client_secret"; + String REFRESH_TOKEN = "refresh_token"; + String USERNAME = "username"; + String PASSWORD = "password"; + String PHONE = "phone"; + String SMS_CODE = "smsCode"; + String IMAGE_CODE = "imageCode"; + String VERIFY_CODE = "verifyCode"; + + + /** + * 认证阶段保存的用户登录名 + */ + String AUTHENTICATE_USERNAME = "authenticateUserName"; + + /** + * 上游服务器模块名称 + */ + String SERVER_NAME = "serverName"; + + + /** + * 接口文档 Knife4j 测试客户端ID + */ + String TEST_CLIENT_ID = "client"; + + + /** + * 授权码模式 + */ + String GRANT_AUTHORIZATION_CODE = "authorization_code"; + + /** + * 验证码授权模式 + */ + String GRANT_CAPTCHA = "captcha"; + + /** + * 密码模式 + */ + String GRANT_PASSWORD = "password"; + + /** + * 刷新token模式 + */ + String GRANT_REFRESH_TOKEN = "refresh_token"; + + /** + * 短信模式 + */ + String GRANT_SMS_CODE = "sms_code"; + + /** + * 微信模式 + */ + String GRANT_WECHAT = "wechat"; + + +} diff --git a/njcn-common/src/main/java/com/njcn/common/pojo/constant/ServerInfo.java b/njcn-common/src/main/java/com/njcn/common/pojo/constant/ServerInfo.java new file mode 100644 index 0000000..75f4ff0 --- /dev/null +++ b/njcn-common/src/main/java/com/njcn/common/pojo/constant/ServerInfo.java @@ -0,0 +1,55 @@ +package com.njcn.common.pojo.constant; + + +/** + * @author hongawen + * @version 1.0.0 + * @date 2021年12月15日 13:39 + */ +public interface ServerInfo { + + String GATEWAY = "pqs-gateway"; + String OAUTH = "pqs-auth"; + String APP = "pqs-app"; + String SUPERVISE = "pqs-supervise"; + String COMMON = "pqs-common"; + String DEVICE = "device-boot"; + String EVENT = "event-boot"; + String SUPERVISION = "supervision-boot"; + String BPM = "bpm-boot"; + String HARMONIC = "harmonic-boot"; + String REPORT = "report-boot"; + String SYSTEM = "system-boot"; + String ENERGY = "energy-boot"; + String JOB_ADMIN = "job-admin"; + String USER = "user-boot"; + String JOB = "job-admin"; + String QUALITY = "quality-boot"; + String PROCESS = "process-boot"; + String PREPARE_BOOT = "prepare-boot"; + String ALGORITHM_BOOT = "algorithm-boot"; + + String CS_DEVICE_BOOT = "cs-device-boot"; + + String CS_SYSTEM_BOOT = "cs-system-boot"; + + String CS_WARN_BOOT = "cs-warn-boot"; + + String CS_EVENT_BOOT = "cs-event-boot"; + + String CS_HARMONIC_BOOT = "cs-harmonic-boot"; + + String CS_REPORT_BOOT = "cs-report-boot"; + + String ACCESS_BOOT = "access-boot"; + + String CS_STAT_BOOT = "stat-boot"; + + String CS_RT_BOOT = "rt-boot"; + + String CS_ZL_EVENT_BOOT = "zl-event-boot"; + + String ADVANCE_BOOT = "advance-boot"; + + +} diff --git a/njcn-common/src/main/java/com/njcn/common/pojo/dto/LogInfoDTO.java b/njcn-common/src/main/java/com/njcn/common/pojo/dto/LogInfoDTO.java new file mode 100644 index 0000000..78cba3f --- /dev/null +++ b/njcn-common/src/main/java/com/njcn/common/pojo/dto/LogInfoDTO.java @@ -0,0 +1,78 @@ +package com.njcn.common.pojo.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2021年07月08日 20:03 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class LogInfoDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 登录名 + */ + private String loginName; + + /** + * 用户已登录:用户名 + */ + private String userName; + + + private String ip; + + private String operate; + + private String operateType; + + /** + * 操作结果 0.失败 1.成功 + */ + private Integer result; + + /** + * 失败原因 + */ + private String failReason; + + /** + * 严重度 0.普通 1.中等 2.严重 + */ + private Integer level; + + /** + * 事件类型 0.业务事件 1.系统事件 + */ + private Integer type; + + private String serviceName; + + /** + * 0 未登录; 1 已登录 + */ + private String userIndex; + + /** + * 0 未登录; 1 已登录 + */ + @JsonDeserialize(using = LocalDateTimeDeserializer.class) + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime createTime; +} diff --git a/njcn-common/src/main/java/com/njcn/common/pojo/dto/SelectOption.java b/njcn-common/src/main/java/com/njcn/common/pojo/dto/SelectOption.java new file mode 100644 index 0000000..d97cfef --- /dev/null +++ b/njcn-common/src/main/java/com/njcn/common/pojo/dto/SelectOption.java @@ -0,0 +1,23 @@ +package com.njcn.common.pojo.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2023年07月25日 09:40 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class SelectOption implements Serializable { + + private String name; + + private String value; + +} diff --git a/njcn-common/src/main/java/com/njcn/common/pojo/dto/UserTokenInfo.java b/njcn-common/src/main/java/com/njcn/common/pojo/dto/UserTokenInfo.java new file mode 100644 index 0000000..4f27e71 --- /dev/null +++ b/njcn-common/src/main/java/com/njcn/common/pojo/dto/UserTokenInfo.java @@ -0,0 +1,41 @@ +package com.njcn.common.pojo.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; +import lombok.Data; + +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2022年03月11日 11:29 + */ +@Data +public class UserTokenInfo implements Serializable { + + /** + * 通行token + */ + private String accessTokenJti; + + /** + * 刷新token + */ + private String refreshToken; + + + /** + * refreshToken的生命周期结点 + */ + @JsonDeserialize(using = LocalDateTimeDeserializer.class) + @JsonSerialize(using = LocalDateTimeSerializer.class) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime refreshTokenExpire; + + +} diff --git a/njcn-common/src/main/java/com/njcn/common/pojo/enums/auth/AuthenticationMethodEnum.java b/njcn-common/src/main/java/com/njcn/common/pojo/enums/auth/AuthenticationMethodEnum.java new file mode 100644 index 0000000..82064c1 --- /dev/null +++ b/njcn-common/src/main/java/com/njcn/common/pojo/enums/auth/AuthenticationMethodEnum.java @@ -0,0 +1,39 @@ +package com.njcn.common.pojo.enums.auth; + +import lombok.Getter; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2021年12月15日 15:55 + */ +@Getter +public enum AuthenticationMethodEnum { + + /** + * 认证的方式 + */ + USERNAME("username", "用户名"), + MOBILE("mobile", "手机号"), + OPENID("openId", "开放式认证系统唯一身份标识"); + + private final String value; + + private final String label; + + AuthenticationMethodEnum(String value, String label) { + this.value = value; + this.label = label; + } + + public static AuthenticationMethodEnum getByValue(String value) { + AuthenticationMethodEnum authenticationMethodEnum = null; + for (AuthenticationMethodEnum item : values()) { + if (item.getValue().equals(value)) { + authenticationMethodEnum = item; + } + } + return authenticationMethodEnum; + } + +} diff --git a/njcn-common/src/main/java/com/njcn/common/pojo/enums/auth/ClientEnum.java b/njcn-common/src/main/java/com/njcn/common/pojo/enums/auth/ClientEnum.java new file mode 100644 index 0000000..3ceb29e --- /dev/null +++ b/njcn-common/src/main/java/com/njcn/common/pojo/enums/auth/ClientEnum.java @@ -0,0 +1,40 @@ +package com.njcn.common.pojo.enums.auth; + +import lombok.Getter; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2022年02月10日 14:50 + */ +@Getter +public enum ClientEnum { + + /** + * 客户端,目前仅分为web端、大屏端、移动端 + */ + WEB_CLIENT("njcn", "web"), + WEB_CLIENT_TEST("njcntest", "web"), + SCREEN_CLIENT("screen", "screen"), + APP_CLIENT("app", "app"), + WE_CHAT_APP_CLIENT("wx", "app"); + + private final String clientId; + + private final String clientType; + + ClientEnum(String clientId, String clientType) { + this.clientId = clientId; + this.clientType = clientType; + } + + public static String getClientType(String clientId) { + for (ClientEnum item : values()) { + if (item.getClientId().equals(clientId)) { + return item.getClientType(); + } + } + //默认为web端 + return "web"; + } +} diff --git a/njcn-common/src/main/java/com/njcn/common/pojo/enums/auth/PasswordEncoderTypeEnum.java b/njcn-common/src/main/java/com/njcn/common/pojo/enums/auth/PasswordEncoderTypeEnum.java new file mode 100644 index 0000000..a38e806 --- /dev/null +++ b/njcn-common/src/main/java/com/njcn/common/pojo/enums/auth/PasswordEncoderTypeEnum.java @@ -0,0 +1,28 @@ +package com.njcn.common.pojo.enums.auth; + +import lombok.Getter; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2021年12月15日 14:03 + */ +@Getter +public enum PasswordEncoderTypeEnum { + + /** + * 密码加密类型 + */ + BCRYPT("{bcrypt}","BCRYPT加密"), + + NOOP("{noop}","无加密明文"); + + private final String prefix; + + private final String desc; + + PasswordEncoderTypeEnum(String prefix, String desc){ + this.prefix=prefix; + this.desc = desc; + } +} diff --git a/njcn-common/src/main/java/com/njcn/common/pojo/enums/common/DataStateEnum.java b/njcn-common/src/main/java/com/njcn/common/pojo/enums/common/DataStateEnum.java new file mode 100644 index 0000000..5ec5403 --- /dev/null +++ b/njcn-common/src/main/java/com/njcn/common/pojo/enums/common/DataStateEnum.java @@ -0,0 +1,31 @@ +package com.njcn.common.pojo.enums.common; + +import lombok.Getter; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2021年12月15日 11:37 + */ +@Getter +public enum DataStateEnum { + /** + * 正常 + */ + ENABLE(1, "正常"), + + /** + * 删除 + */ + DELETED(0, "删除"); + + private final Integer code; + + private final String message; + + DataStateEnum(Integer code, String message) { + this.code = code; + this.message = message; + } + +} diff --git a/njcn-common/src/main/java/com/njcn/common/pojo/enums/common/LogEnum.java b/njcn-common/src/main/java/com/njcn/common/pojo/enums/common/LogEnum.java new file mode 100644 index 0000000..6874613 --- /dev/null +++ b/njcn-common/src/main/java/com/njcn/common/pojo/enums/common/LogEnum.java @@ -0,0 +1,36 @@ +package com.njcn.common.pojo.enums.common; + +import lombok.Getter; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2021年07月07日 15:37 + */ +@Getter +public enum LogEnum { + + /** + * 日志类型分为业务事件、系统事件 + * 严重度分为 严重 中等 普通 + */ + BUSINESS_SERIOUS("业务事件", "严重"), + BUSINESS_MEDIUM("业务事件", "中等"), + BUSINESS_COMMON("业务事件", "普通"), + + SYSTEM_SERIOUS("系统事件", "严重"), + SYSTEM_MEDIUM("系统事件", "中等"), + SYSTEM_COMMON("系统事件", "普通"); + + + private final String operateType; + + private final String operateLevel; + + LogEnum(String operateType, String operateLevel) { + this.operateType = operateType; + this.operateLevel = operateLevel; + } + + +} diff --git a/njcn-common/src/main/java/com/njcn/common/pojo/enums/common/ServerEnum.java b/njcn-common/src/main/java/com/njcn/common/pojo/enums/common/ServerEnum.java new file mode 100644 index 0000000..be37a84 --- /dev/null +++ b/njcn-common/src/main/java/com/njcn/common/pojo/enums/common/ServerEnum.java @@ -0,0 +1,40 @@ +package com.njcn.common.pojo.enums.common; + +import lombok.Getter; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2021年09月06日 14:00 + */ +@Getter +public enum ServerEnum { + + /** + * 微服务模块的枚举信息 + */ + APP("pqs-app", "APP服务模块"), + DEVICE("device-boot", "终端服务模块"), + EVENT("event-boot", "暂降服务模块"), + GATEWAY("pqs-gateway", "网关服务模块"), + HARMONIC("harmonic-boot", "谐波监测服务模块"), + OAUTH("pqs-auth", "认证服务模块"), + REPORT("report-boot", "报表服务模块"), + SUPERVISE("pqs-supervise", "技术监督管理服务模块"), + SYSTEM("system-boot", "系统配置服务模块"), + USER("user-boot", "用户服务模块"), + ENERGY("energy-boot", "用能服务模块"), + QUALITY("quality-boot", "电能质量服务模块"), + EVENT_PREPARE("event-prepare","暂态模块预处理"), + HARMONIC_PREPARE("harmonic-prepare","谐波模块预处理"), + COMMON("pqs-common", "通用服务模块"); + + private final String name; + + private final String serverInfo; + + ServerEnum(String name, String serverInfo) { + this.name = name; + this.serverInfo = serverInfo; + } +} diff --git a/njcn-common/src/main/java/com/njcn/common/pojo/enums/response/CommonResponseEnum.java b/njcn-common/src/main/java/com/njcn/common/pojo/enums/response/CommonResponseEnum.java new file mode 100644 index 0000000..44fe806 --- /dev/null +++ b/njcn-common/src/main/java/com/njcn/common/pojo/enums/response/CommonResponseEnum.java @@ -0,0 +1,123 @@ +package com.njcn.common.pojo.enums.response; + +import lombok.Getter; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2021年04月13日 10:33 + */ +@Getter +public enum CommonResponseEnum { + + /** + * A0000 ~ A0099 作用于通用业务枚举 + * 通用业务的响应枚举 + */ + SUCCESS("A0000", "成功"), + + NO_DATA("A0001", "数据为空"), + + FAIL("A0002", "失败"), + + INTERNAL_ERROR("A0003", "系统内部异常"), + + SERVICE_FALLBACK("A0004", "服务访问降级"), + + INVALID_PARAMETER("A0005", "请求参数非法"), + + INVALID_MEDIA("A0006", "请求参数媒体不支持"), + + ENUM_ERROR("A0007", "枚举解析异常"), + + NULL_POINTER_EXCEPTION("A0008", "空指针异常"), + + ARITHMETIC_EXCEPTION("A0009", "算数运算异常"), + + CLASS_CAST_EXCEPTION("A0010", "类型转换异常"), + + INDEX_OUT_OF_BOUNDS_EXCEPTION("A0011", "索引下标越界异常"), + + HTTP_MEDIA_TYPE_NOT_SUPPORTED_EXCEPTION("A0012", "请求中参数的媒体方式不支持"), + + METHOD_ARGUMENT_NOT_VALID_EXCEPTION("A0013", "参数校验异常"), + + ILLEGAL_ARGUMENT_EXCEPTION("A0014", "参数校验异常"), + + SM2_CIPHER_ERROR("A0015", "SM2获取秘钥对异常"), + + UN_DECLARE("A0016", "后台接口异常"), + + DIC_DATA("A0017", "获取字典数据失败"), + + GET_MQTT_CLIENT_FAIL("A0018", "获取MQTT客户端失败"), + + NO_MQTT_HANDLER("A0019", "MQTT中没有处理器Handler"), + + NO_MQTT_PRODUCER("A0020", "MQTT没有生产者producer"), + + JSON_CONVERT_EXCEPTION("A0021", "JSON转换异常"), + + TOKEN_EXPIRE_JWT("A0024", "token已过期"), + + PARSE_TOKEN_ERROR("A0025", "token解析异常"), + + REFLECT_METHOD_EXCEPTION("A0026", "反射方法获取属性值异常"), + + REQUEST_EMPTY("A0027", "当前请求web环境为空"), + + EXPORT_FILE_ERROR("A0051","数据完整报表下载异常"), + + PREPARE_RESPONSE_ENUM("A0089", "预处理响应枚举类型"), + + USER_RESPONSE_ENUM("A0090", "用户响应枚举类型"), + + GATEWAY_RESPONSE_ENUM("A0091", "网关响应枚举类型"), + + DEVICE_RESPONSE_ENUM("A0092", "终端响应枚举类型"), + + SYSTEM_RESPONSE_ENUM("A0093", "系统响应枚举类型"), + + DELETE_PID_EXIST("A0094", "存在子节点"), + + DELETE_PID_UNEXIST("A0095", "不存在子节点"), + + FILE_EXIST("A0096", "文件已存在"), + + FILE_SIZE_ERROR("A0096", "文件过大"), + + FILE_XLSX_ERROR("A0096", "请上传excel文件"), + + DEPT_EXIST("A0097", "部门id已存在"), + + DEPT_NOT_EXIST("A0098", "部门id不存在"), + + DEPT_BINDED("A0099", "部门id已绑定"), + + ID_NOT_EXIST("A0100", "id不存在"), + + TIME_ERROR("A0101","时间格式有误"), + CLOSE_RESOURCE_ERROR("A0102","关闭资源有误"), + MATH_ERROR("A0103","比例总和大于100%"), + CS_DEVICE_RESPONSE_ENUM("A0104", "治理终端响应枚举类型"), + + ADVANCE_RESPONSE_ENUM("A00105", "终端响应枚举类型"), + + DYNAMIC_RESPONSE_ENUM("A00002", "动态枚举内容"), + + + ; + + private final String code; + + private String message; + + public void setMessage(String message) { + this.message = message; + } + + CommonResponseEnum(String code, String message) { + this.code = code; + this.message = message; + } +} diff --git a/njcn-common/src/main/java/com/njcn/common/pojo/exception/BusinessException.java b/njcn-common/src/main/java/com/njcn/common/pojo/exception/BusinessException.java new file mode 100644 index 0000000..99d3473 --- /dev/null +++ b/njcn-common/src/main/java/com/njcn/common/pojo/exception/BusinessException.java @@ -0,0 +1,87 @@ +package com.njcn.common.pojo.exception; + +import com.njcn.common.pojo.response.HttpResult; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2021年04月20日 14:48 + */ +@Data +@Slf4j +@NoArgsConstructor +public class BusinessException extends RuntimeException { + + private static final long serialVersionUID = -1; + + public static final String GET_CODE_METHOD = "getCode"; + + public static final String GET_MESSAGE_METHOD = "getMessage"; + + /** + * 异常码 + */ + private String code; + + /** + * 异常提示信息 + */ + private String message; + + /** + * 构造器内的枚举 + */ + private Enum anEnum; + + /** + * openfeign请求,返回的非常规结果集 + */ + private HttpResult result; + + public BusinessException(Enum eEnum) { + anEnum = eEnum; + try { + Method codeMethod = eEnum.getClass().getMethod(GET_CODE_METHOD); + Method messageMethod = eEnum.getClass().getMethod(GET_MESSAGE_METHOD); + this.code = (String) codeMethod.invoke(eEnum); + this.message = (String) messageMethod.invoke(eEnum); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + } + + /** + * 针对批量操作的业务返回 + * + * @author cdf + * @date 2021/7/7 + */ + public BusinessException(Enum eEnum, String msg) { + anEnum = eEnum; + try { + Method codeMethod = eEnum.getClass().getMethod(GET_CODE_METHOD); + Method messageMethod = eEnum.getClass().getMethod(GET_MESSAGE_METHOD); + this.code = (String) codeMethod.invoke(eEnum); + this.message = (String) messageMethod.invoke(eEnum); + this.message = this.message.concat(": " + msg); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + } + + + public BusinessException(HttpResult result) { + this.result = result; + } + + public BusinessException(String message) { + super(message); + this.message = message; + } +} diff --git a/njcn-common/src/main/java/com/njcn/common/pojo/response/HttpResult.java b/njcn-common/src/main/java/com/njcn/common/pojo/response/HttpResult.java new file mode 100644 index 0000000..b9d74ac --- /dev/null +++ b/njcn-common/src/main/java/com/njcn/common/pojo/response/HttpResult.java @@ -0,0 +1,43 @@ +package com.njcn.common.pojo.response; + +import com.njcn.common.pojo.enums.response.CommonResponseEnum; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2021年03月25日 15:38 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class HttpResult implements Serializable { + + /**状态码*/ + private String code; + + /**回执信息*/ + private String message; + + /**响应数据*/ + private T data; + + public HttpResult(String code, String message) { + this.code = code; + this.message = message; + } + + public HttpResult(Integer code, String message) { + this.code = String.valueOf(code); + this.message = message; + } + + public HttpResult(T content) { + this.code = CommonResponseEnum.SUCCESS.getCode(); + this.data = content; + } +} diff --git a/njcn-db/mybatis-plus/pom.xml b/njcn-db/mybatis-plus/pom.xml new file mode 100644 index 0000000..639cc7f --- /dev/null +++ b/njcn-db/mybatis-plus/pom.xml @@ -0,0 +1,77 @@ + + + 4.0.0 + + com.njcn + njcn-db + 0.0.1 + + + mybatis-plus + 0.0.1 + + + 8 + 8 + UTF-8 + 2.1.3 + 3.4.2 + 1.5.1-RELEASE + 1.2.5 + 8.0.19 + + + + + + com.njcn + njcn-common + 0.0.1 + + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + + + + com.zaxxer + HikariCP + + + ${mybatis.version} + + + + + com.baomidou + mybatis-plus-boot-starter + ${mybatis-plus.version} + + + + + com.github.jeffreyning + mybatisplus-plus + ${jeffrey-mybatis-plus.version} + + + + + com.alibaba + druid-spring-boot-starter + ${druid.version} + + + + + mysql + mysql-connector-java + ${mysql.version} + + + + \ No newline at end of file diff --git a/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/bo/BaseEntity.java b/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/bo/BaseEntity.java new file mode 100644 index 0000000..21f5d7f --- /dev/null +++ b/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/bo/BaseEntity.java @@ -0,0 +1,55 @@ +package com.njcn.db.mybatisplus.bo; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer; +import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2021年12月13日 10:18 + */ +@Data +public class BaseEntity { + + private static final long serialVersionUID = 1L; + + /** + * 创建用户 + */ + @TableField(fill = FieldFill.INSERT) + private String createBy; + + + /** + * 创建时间 + */ + @TableField(fill = FieldFill.INSERT) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonDeserialize(using = LocalDateTimeDeserializer.class) + @JsonSerialize(using = LocalDateTimeSerializer.class) + private LocalDateTime createTime; + + /** + * 更新用户 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + private String updateBy; + + /** + * 更新时间 + */ + @TableField(fill = FieldFill.INSERT_UPDATE) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonDeserialize(using = LocalDateTimeDeserializer.class) + @JsonSerialize(using = LocalDateTimeSerializer.class) + private LocalDateTime updateTime; + +} diff --git a/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/config/MybatisConfig.java b/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/config/MybatisConfig.java new file mode 100644 index 0000000..35508ad --- /dev/null +++ b/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/config/MybatisConfig.java @@ -0,0 +1,50 @@ +package com.njcn.db.mybatisplus.config; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import com.njcn.db.mybatisplus.handler.AutoFillValueHandler; +import com.njcn.db.mybatisplus.handler.BatchInjector; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2021年12月14日 16:43 + */ +@Configuration +public class MybatisConfig { + + /** + * 分页插件 + */ + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); + return interceptor; + } + + + /** + * 自定义公共字段自动填充 + */ + @Bean + public AutoFillValueHandler autoFillValueHandler() { + return new AutoFillValueHandler(); + } + + + /*** + * 自定义注册器,处理批量插入 + * @author hongawen + * @return BatchInjector + */ + @Bean + public BatchInjector BatchInjector() { + return new BatchInjector(); + } + + +} diff --git a/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/constant/DbConstant.java b/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/constant/DbConstant.java new file mode 100644 index 0000000..9c8b062 --- /dev/null +++ b/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/constant/DbConstant.java @@ -0,0 +1,19 @@ +package com.njcn.db.mybatisplus.constant; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2021年12月20日 16:08 + */ +public interface DbConstant { + + /** + * 正序标识 + */ + String ASC = "asc"; + + /** + * 倒序标识 + */ + String DESC = "desc"; +} diff --git a/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/constant/UserConstant.java b/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/constant/UserConstant.java new file mode 100644 index 0000000..82a6bba --- /dev/null +++ b/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/constant/UserConstant.java @@ -0,0 +1,9 @@ +package com.njcn.db.mybatisplus.constant; + +public interface UserConstant { + + String USER_ID = "userId"; + + String UNKNOWN_USER_ID = "未知用户"; + +} diff --git a/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/handler/AutoFillValueHandler.java b/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/handler/AutoFillValueHandler.java new file mode 100644 index 0000000..99e2f0e --- /dev/null +++ b/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/handler/AutoFillValueHandler.java @@ -0,0 +1,62 @@ +package com.njcn.db.mybatisplus.handler; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.extra.spring.SpringUtil; +import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; +import com.njcn.common.bean.CustomCacheUtil; +import com.njcn.db.mybatisplus.constant.UserConstant; +import org.apache.ibatis.reflection.MetaObject; + +import java.time.LocalDateTime; +import java.util.function.Supplier; + +/** + * 数据自动填充处理器 + * + * @author hongawen + * @version 1.0.0 + * @date 2021年12月14日 16:36 + */ + +public class AutoFillValueHandler implements MetaObjectHandler { + + private static final String CREATE_USER = "createBy"; + + private static final String CREATE_TIME = "createTime"; + + private static final String UPDATE_USER = "updateBy"; + + private static final String UPDATE_TIME = "updateTime"; + + + /** + * 执行元数据需要插入的值添加 + */ + @Override + public void insertFill(MetaObject metaObject) { + Supplier supplierUserId = getUserIdSupplier(); + this.strictInsertFill(metaObject, CREATE_TIME, LocalDateTime::now, LocalDateTime.class); + this.strictInsertFill(metaObject, CREATE_USER, supplierUserId, String.class); + this.strictInsertFill(metaObject, UPDATE_TIME, LocalDateTime::now, LocalDateTime.class); + this.strictInsertFill(metaObject, UPDATE_USER, supplierUserId, String.class); + } + + /** + * 执行元数据需要更新的数据更新 + */ + @Override + public void updateFill(MetaObject metaObject) { + Supplier supplierUserId = getUserIdSupplier(); + this.strictInsertFill(metaObject, UPDATE_USER, supplierUserId, String.class); + this.strictUpdateFill(metaObject, UPDATE_TIME, LocalDateTime::now, LocalDateTime.class); + } + + + public Supplier getUserIdSupplier(){ + CustomCacheUtil customCacheUtil = SpringUtil.getBean(CustomCacheUtil.CACHE_NAME); + String userId = customCacheUtil.get(UserConstant.USER_ID, false); + final String actualUserId = StrUtil.isBlank(userId) ? UserConstant.UNKNOWN_USER_ID : userId; + return () -> actualUserId; + } + +} diff --git a/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/handler/BatchInjector.java b/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/handler/BatchInjector.java new file mode 100644 index 0000000..193bda3 --- /dev/null +++ b/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/handler/BatchInjector.java @@ -0,0 +1,25 @@ +package com.njcn.db.mybatisplus.handler; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.core.injector.AbstractMethod; +import com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn; +import com.github.jeffreyning.mybatisplus.base.MppSqlInjector; + +import java.util.List; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2023年05月30日 14:51 + */ +public class BatchInjector extends MppSqlInjector { + + @Override + public List getMethodList(Class mapperClass) { + List methodList = super.getMethodList(mapperClass); + //更新时自动填充的字段,不用插入值 + methodList.add(new InsertBatchSomeColumn(i -> i.getFieldFill() != FieldFill.UPDATE)); + return methodList; + } + +} diff --git a/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/mapper/BatchBaseMapper.java b/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/mapper/BatchBaseMapper.java new file mode 100644 index 0000000..63dfb39 --- /dev/null +++ b/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/mapper/BatchBaseMapper.java @@ -0,0 +1,19 @@ +package com.njcn.db.mybatisplus.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +import java.util.List; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2023年05月30日 14:54 + */ +public interface BatchBaseMapper extends BaseMapper { + + /** + * 真正的批量插入 + */ + int insertBatchSomeColumn(List entityList); + +} diff --git a/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/service/IReplenishMybatisService.java b/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/service/IReplenishMybatisService.java new file mode 100644 index 0000000..502e1a9 --- /dev/null +++ b/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/service/IReplenishMybatisService.java @@ -0,0 +1,22 @@ +package com.njcn.db.mybatisplus.service; + +import com.baomidou.mybatisplus.extension.service.IService; + +import java.util.List; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2023年06月06日 18:14 + */ +public interface IReplenishMybatisService extends IService { + + /*** + * 当批量插入数据量过大时,可以指定尺寸交给mybatis,每次插入多少条记录 + * @author hongawen + * @date 2023/6/6 9:33 + * @param data 数据集合 + * @param size 分片的尺寸 + */ + void insertBatchBySlice(List data, int size); +} diff --git a/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/service/impl/ReplenishMybatisServiceImpl.java b/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/service/impl/ReplenishMybatisServiceImpl.java new file mode 100644 index 0000000..d019b1f --- /dev/null +++ b/njcn-db/mybatis-plus/src/main/java/com/njcn/db/mybatisplus/service/impl/ReplenishMybatisServiceImpl.java @@ -0,0 +1,48 @@ +package com.njcn.db.mybatisplus.service.impl; + +import cn.hutool.core.collection.CollectionUtil; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.njcn.db.mybatisplus.mapper.BatchBaseMapper; +import com.njcn.db.mybatisplus.service.IReplenishMybatisService; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author hongawen + * @version 1.0.0 + * @date 2023年06月06日 18:16 + */ +public class ReplenishMybatisServiceImpl, T> extends ServiceImpl, T> implements IReplenishMybatisService { + + @Override + @Transactional(rollbackFor = Exception.class) + public void insertBatchBySlice(List data, int size) { + try { + int totalCount = data.size(); + int idxLimit = Math.min(size, totalCount); + List dataTemp = new ArrayList<>(data); + //保存单批提交的数据集合 + if (idxLimit == size) { + int times = totalCount / idxLimit + 1; + for (int i = 1; i <= times; i++) { + if (totalCount >= idxLimit) { + List temp = dataTemp.subList(0, idxLimit); + this.baseMapper.insertBatchSomeColumn(temp); + temp.clear(); + totalCount = totalCount - idxLimit; + } else { + if (CollectionUtil.isNotEmpty(dataTemp)) { + this.baseMapper.insertBatchSomeColumn(dataTemp); + } + } + } + } else { + this.baseMapper.insertBatchSomeColumn(dataTemp); + } + } catch (Exception e) { + throw new RuntimeException("分片批量插入数据异常,异常为:" + e); + } + } +} diff --git a/njcn-db/mybatis-plus/src/main/resources/META-INF/spring.factories b/njcn-db/mybatis-plus/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..3032b8a --- /dev/null +++ b/njcn-db/mybatis-plus/src/main/resources/META-INF/spring.factories @@ -0,0 +1,4 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.njcn.db.mybatisplus.config.MybatisConfig + + diff --git a/njcn-db/pom.xml b/njcn-db/pom.xml new file mode 100644 index 0000000..83e2617 --- /dev/null +++ b/njcn-db/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + com.njcn + BasicDependVersion + 1.0.0 + + njcn-db + 0.0.1 + pom + 数据库模块 管理多中ORM框架 + + mybatis-plus + + + + 8 + 8 + UTF-8 + + + \ No newline at end of file diff --git a/njcn-springboot/pom.xml b/njcn-springboot/pom.xml new file mode 100644 index 0000000..988924e --- /dev/null +++ b/njcn-springboot/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + + com.njcn + BasicDependVersion + 1.0.0 + + + njcn-springboot + pom + 整理springboot各大版本 + + spingboot2.3.12 + spingboot2.7.11 + + + + 8 + 8 + UTF-8 + + + \ No newline at end of file diff --git a/njcn-springboot/spingboot2.3.12/pom.xml b/njcn-springboot/spingboot2.3.12/pom.xml new file mode 100644 index 0000000..42551d7 --- /dev/null +++ b/njcn-springboot/spingboot2.3.12/pom.xml @@ -0,0 +1,80 @@ + + + 4.0.0 + + com.njcn + njcn-springboot + 1.0.0 + + spingboot2.3.12 + 2.3.12 + 整理以2.3.12为基础版本的所有相关依赖 + + 8 + 8 + UTF-8 + 3.0.2 + + + + + + com.njcn + njcn-common + 0.0.1 + + + + + org.springframework.boot + spring-boot-starter-web + ${spring-boot.version} + + + + org.springframework.boot + spring-boot-starter-actuator + ${spring-boot.version} + + + + org.springframework.boot + spring-boot-configuration-processor + true + ${spring-boot.version} + + + + org.springframework.boot + spring-boot-starter-test + ${spring-boot.version} + + + + org.springframework.boot + spring-boot-starter-validation + ${spring-boot.version} + + + + + + com.github.xiaoymin + knife4j-spring-boot-starter + ${knife4j.version} + + + com.google.guava + guava + + + + + com.github.xiaoymin + knife4j-spring-ui + ${knife4j.version} + + + \ No newline at end of file diff --git a/njcn-springboot/spingboot2.7.11/pom.xml b/njcn-springboot/spingboot2.7.11/pom.xml new file mode 100644 index 0000000..7c0ad65 --- /dev/null +++ b/njcn-springboot/spingboot2.7.11/pom.xml @@ -0,0 +1,72 @@ + + + 4.0.0 + + com.njcn + njcn-springboot + 1.0.0 + + spingboot2.7.11 + 2.7.11 + 整理以2.7.11为基础版本的所有相关依赖 + + 8 + 8 + UTF-8 + 2.7.11 + 3.0.2 + + + + + org.springframework.boot + spring-boot-starter-json + ${spring-boot.version} + + + + org.springframework.boot + spring-boot-starter-web + ${spring-boot.version} + + + + org.springframework.boot + spring-boot-starter-actuator + ${spring-boot.version} + + + + org.springframework.boot + spring-boot-configuration-processor + true + ${spring-boot.version} + + + + org.springframework.boot + spring-boot-starter-test + ${spring-boot.version} + + + + + com.github.xiaoymin + knife4j-spring-boot-starter + ${knife4j.version} + + + com.google.guava + guava + + + + + com.github.xiaoymin + knife4j-spring-ui + ${knife4j.version} + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..f1711d7 --- /dev/null +++ b/pom.xml @@ -0,0 +1,66 @@ + + + 4.0.0 + + com.njcn + BasicDependVersion + 1.0.0 + + njcn-common + njcn-springboot + njcn-db + + pom + 版本控制项目 + + + nexus-releases + Nexus Release Repository + http://192.168.1.22:8001/nexus/content/repositories/releases/ + + + nexus-snapshots + Nexus Snapshot Repository + http://192.168.1.22:8001/nexus/content/repositories/snapshots/ + + + + 2.3.12.RELEASE + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.2.2.RELEASE + + true + true + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + + + + + src/main/resources + true + + + src/main/java + + **/*.xml + + + + +