Compare commits

...

112 Commits

Author SHA1 Message Date
YangPeng 0f0502f224 fix():删除cars类 2024-10-10 19:57:41 +08:00
王鑫 07288fe6b1 fix():修复VX命名错误问题 2024-10-10 14:11:33 +08:00
王鑫 d5483cae0a fix():修复VX命名错误问题 2024-10-10 14:10:47 +08:00
王鑫 223d2c5a21 fix():修复admin账号为空的问题 2024-10-10 14:05:26 +08:00
ruyaxie 37a42ccd3c Merge remote-tracking branch 'origin/dev' into dev 2024-10-10 10:30:21 +08:00
ruyaxie 214962ff9a feat():修复yml配置名称 2024-10-10 10:29:42 +08:00
王鑫 5d1500f4f6 Merge remote-tracking branch 'origin/dev' into dev
# Conflicts:
#	cloud-modules/cloud-modules-file/src/main/java/com/muyu/file/utils/FileUploadUtils.java
2024-10-10 10:00:57 +08:00
王鑫 ead12857c5 fix():修复admin账号为空的问题 2024-10-10 10:00:25 +08:00
ruyaxie 08fc9623bc feat():修复车辆网关报错 2024-10-09 17:02:51 +08:00
ruyaxie ee6da76129 Merge remote-tracking branch 'origin/dev' into dev
# Conflicts:
#	cloud-modules/cloud-modules-enterprise/enterpise-cache/pom.xml
#	cloud-modules/cloud-modules-enterprise/enterpise-common/pom.xml
#	cloud-modules/cloud-modules-enterprise/enterpise-service/pom.xml
#	cloud-modules/cloud-modules-parse/pom.xml
#	cloud-modules/cloud-modules-parse/src/main/resources/bootstrap.yml
#	cloud-modules/cloud-modules-vehicle-gateway/src/main/resources/bootstrap.yml
#	pom.xml
2024-10-09 16:55:09 +08:00
ruyaxie 89c2fc33fa Merge branch 'dev.parse' into dev
# Conflicts:
#	pom.xml
2024-10-09 16:54:48 +08:00
ruyaxie 1e86779560 feat():修复车辆网关报错 2024-10-09 16:53:09 +08:00
王鑫 5c4e0cde3e fix():修改saas结构 2024-10-09 16:33:33 +08:00
ruyaxie 4f0fa2e95c Merge branch 'dev.parse' into dev
# Conflicts:
#	cloud-modules/cloud-modules-enterprise/enterpise-cache/pom.xml
#	cloud-modules/cloud-modules-enterprise/enterpise-common/pom.xml
#	cloud-modules/cloud-modules-enterprise/enterpise-service/pom.xml
#	cloud-modules/cloud-modules-vehicle-gateway/src/main/resources/bootstrap.yml
#	pom.xml
2024-10-08 19:51:47 +08:00
ruyaxie b13931317c feat():parse多余的依赖,车辆管理的启动报错,以及XXLJob依赖问题 2024-10-08 19:48:57 +08:00
DongZeLiang dcd9ce68df fix(): 修复包名等格式规范问题 2024-10-08 19:12:42 +08:00
王鑫 65d7fb3de1 fix():重新构建结构 2024-10-08 19:12:42 +08:00
王鑫 a993b30e6e fix():重新构建结构 2024-10-08 19:12:39 +08:00
YangPeng 92c2d7b11b feat():添加剩余注释 2024-10-08 19:12:19 +08:00
YangPeng 75b6097fed feat():添加缓存注释 2024-10-08 19:12:19 +08:00
YangPeng c86f2732b0 fix():bootstrap.yml其他名字改成yp启动,防止端口占用 2024-10-08 19:12:13 +08:00
王鑫 553d5933ed fix():重新构建结构 2024-10-08 19:10:32 +08:00
YangPeng ff98f1cc1b fix():添加车辆全部缓存 2024-10-08 19:10:32 +08:00
YangPeng 1468206f1d Merge branch 'dev' of https://gitea.qinmian.online/wuzudaniu/cloud-plus-server into dev.saas.yp 2024-10-08 16:34:34 +08:00
DongZeLiang 47222f5f68 fix(): 修复包名等格式规范问题 2024-10-08 16:25:15 +08:00
王鑫 0c8a13439f fix():重新构建结构 2024-10-08 16:17:38 +08:00
YangPeng 492be37314 feat():添加剩余注释 2024-10-08 16:08:45 +08:00
王鑫 5a0f5e28d2 fix():重新构建结构 2024-10-08 16:05:18 +08:00
YangPeng e1d45db36e Merge branch 'dev.saas.yp' into dev
# Conflicts:
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/resources/bootstrap.yml
#	cloud-modules/cloud-modules-parse/src/main/resources/bootstrap.yml
#	cloud-modules/cloud-modules-vehicle-gateway/src/main/resources/bootstrap.yml
2024-10-08 16:02:04 +08:00
YangPeng e50219f9fb feat():添加缓存注释 2024-10-08 15:58:28 +08:00
王鑫 54d216b144 fix():重新构建结构 2024-10-08 15:58:18 +08:00
王鑫 293cb42bcf Merge remote-tracking branch 'origin/dev' into dev 2024-10-08 15:56:00 +08:00
王鑫 9ba5f8e14a fix():重新构建结构 2024-10-08 15:54:50 +08:00
YangPeng 83756518ad fix():bootstrap.yml其他名字改成yp启动,防止端口占用 2024-10-07 22:37:39 +08:00
YangPeng 44ec3e9eed Merge branch 'dev.saas.yp' into dev 2024-10-07 22:10:46 +08:00
YangPeng 45cb6b2a17 fix():添加车辆全部缓存 2024-10-07 22:05:38 +08:00
王鑫 6dde202353 fix():重新构建数据处理结构 2024-10-07 20:26:11 +08:00
王鑫 3b2e16a39e Merge branch 'dev' of https://gitea.qinmian.online/wuzudaniu/cloud-plus-server into dev
# Conflicts:
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/enterpise/service/impl/CarFenceServiceMybaitsImpl.java
2024-10-07 20:20:23 +08:00
YangPeng 39432a1270 fix():修复enterpise-cache的pom名称冲突问题 2024-10-07 20:16:21 +08:00
YangPeng c7c51c2305 fix():修复enterpise-cache的pom名称冲突问题 2024-10-07 20:05:18 +08:00
YangPeng 11ab968c8d Merge branch 'dev.saas.yp' into dev 2024-10-07 19:53:37 +08:00
YangPeng 4e3dce703d fix():修复合并bug 2024-10-07 19:52:57 +08:00
王鑫 b29b1f18db Merge branch 'dev.parse' into dev
# Conflicts:
#	cloud-common/cloud-common-saas/pom.xml
#	cloud-modules/cloud-modules-data-process/cloud-modules-data-process-common/pom.xml
#	cloud-modules/cloud-modules-enterprise/enterpise-cache/src/main/java/com/muyu/enterpise/cache/WarnStrategyCacjeService.java
#	cloud-modules/cloud-modules-enterprise/enterpise-cache/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
#	cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/req/FenceGroupUpdateReq.java
#	cloud-modules/cloud-modules-enterprise/enterpise-service/pom.xml
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/enterpise/controller/CarAndFenceGroupMiddleController.java
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/enterpise/controller/CarFenceUpdateController.java
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/enterpise/mapper/CarAndFenceGroupMiddleMapper.java
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/enterpise/mapper/CarFenceUpdateMapper.java
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/enterpise/service/CarAndFenceGroupMiddleService.java
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/enterpise/service/CarFenceUpdateService.java
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/enterpise/service/impl/CarAndFenceGroupMiddleServiceImpl.java
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/enterpise/service/impl/CarFenceServiceMybaitsImpl.java
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/enterpise/service/impl/CarFenceUpdateServiceImpl.java
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/resources/bootstrap.yml
#	cloud-modules/cloud-modules-parse/pom.xml
#	cloud-modules/cloud-modules-parse/src/main/java/com/muyu/parse/process/ProcessData.java
2024-10-07 18:57:20 +08:00
ruyaxie 226c427255 feat():添加协议解析模块描述 2024-10-07 18:36:59 +08:00
王鑫 5ac1ef17a3 fix():重新构建数据处理结构 2024-10-07 18:36:05 +08:00
ruyaxie 04450b84e6 feat():提取公共依赖在最大的pom 2024-10-07 15:43:26 +08:00
王鑫 dfdcbdbd86 Merge remote-tracking branch 'origin/dev' into dev
# Conflicts:
#	cloud-common/cloud-common-saas/pom.xml
#	cloud-modules/cloud-modules-enterprise/enterpise-cache/pom.xml
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/enterpise/controller/MiddleController.java
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/enterpise/service/impl/CarFenceServiceMybaitsImpl.java
#	cloud-modules/cloud-modules-enterprise/enterprise-cache/src/main/java/com/muyu/enterpise/cache/VehicleCacheService.java
2024-10-07 14:07:19 +08:00
王鑫 536c40a8e2 fix():重新构建数据处理结构 2024-10-07 14:05:20 +08:00
ruyaxie 761fd61725 feat():修复数据处理 2024-10-07 09:12:10 +08:00
ruyaxie c5f79db964 feat():修复缓存Redis-five 2024-10-06 21:40:40 +08:00
ruyaxie bfb3b98684 feat():修复缓存Redis-four 2024-10-04 21:00:36 +08:00
ruyaxie c37e762dd6 Merge remote-tracking branch 'origin/dev' into dev 2024-10-04 20:49:08 +08:00
ruyaxie cd4a07e637 feat():修复缓存Redis-four 2024-10-04 20:47:02 +08:00
YangPeng a138c0dacd feat():优化 2024-10-04 16:05:15 +08:00
YangPeng eea7db374d feat():优化 2024-10-04 16:05:15 +08:00
YangPeng 4396e30dfd feat():修改JDK版本问题 2024-10-04 16:05:12 +08:00
王鑫 d6167ebfed fix():添加rabbitmq工具类,添加数据处理基础类,添加缓存 2024-10-04 16:04:56 +08:00
ruyaxie e9e32c2ad0 feat():修复缓存3 2024-10-02 16:45:36 +08:00
wangxin1 d7f31e3482 revert a88e91c139
revert fix():修复缓存模块命名冲突问题
2024-09-30 19:25:45 +08:00
王鑫 a88e91c139 fix():修复缓存模块命名冲突问题 2024-10-01 19:20:43 +08:00
ruyaxie 06a35cd645 feat():修复缓存Bug2 2024-09-30 19:06:56 +08:00
ruyaxie 6fbff659c5 feat():修复缓存Bug 2024-09-30 18:17:25 +08:00
ruyaxie 443350c8f4 Merge branch 'dev.parse' into dev 2024-09-30 18:09:42 +08:00
ruyaxie 19f99ac116 feat():修复kafka生产者 2024-09-30 16:50:07 +08:00
YangPeng e5b5222c39 Merge branch 'dev.saas' into dev 2024-09-30 16:41:54 +08:00
YangPeng d24110090c Merge branch 'dev.saas.yp' into dev
# Conflicts:
#	cloud-modules/cloud-modules-data-process/cloud-modules-data-process-common/src/main/java/com/muyu/data/basics/EventQueueConfig.java
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/enterpise/controller/CarAndFenceGroupMiddleController.java
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/enterpise/controller/CarFenceUpdateController.java
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/enterpise/controller/MiddleController.java
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/enterpise/mapper/CarAndFenceGroupMiddleMapper.java
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/enterpise/mapper/CarFenceUpdateMapper.java
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/enterpise/service/CarAndFenceGroupMiddleService.java
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/enterpise/service/CarFenceUpdateService.java
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/enterpise/service/impl/CarAndFenceGroupMiddleServiceImpl.java
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/enterpise/service/impl/CarFenceServiceMybaitsImpl.java
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/java/com/muyu/enterpise/service/impl/CarFenceUpdateServiceImpl.java
#	cloud-modules/cloud-modules-enterprise/enterprise-cache/pom.xml
2024-09-30 16:38:41 +08:00
王鑫 14cc2afd35 Merge remote-tracking branch 'origin/dev' into dev
# Conflicts:
#	cloud-modules/cloud-modules-enterprise/enterpise-service/src/main/resources/bootstrap.yml
#	cloud-modules/cloud-modules-enterprise/pom.xml
2024-09-30 16:30:20 +08:00
王鑫 afdc7b3421 fix():添加rabbitmq工具类,添加数据处理基础类,添加缓存 2024-09-30 16:28:08 +08:00
yangpeng 535eae941e Merge pull request 'feat():优化' (#29) from dev.saas.yp into dev.saas
Reviewed-on: #29
2024-09-30 14:44:23 +08:00
YangPeng bd2865ebc5 feat():优化 2024-09-30 14:43:22 +08:00
yangpeng eef2467a61 Merge pull request 'feat():优化' (#27) from dev.saas.yp into dev.saas
Reviewed-on: #27
2024-09-30 14:36:40 +08:00
YangPeng a66329500c feat():优化 2024-09-30 14:34:49 +08:00
ruyaxie f98c11e825 feat():修复Redis缓存 2024-09-30 12:27:32 +08:00
yangpeng c241897dfe Merge pull request 'dev.saas.yp' (#22) from dev.saas.yp into dev.saas
Reviewed-on: #22
2024-09-30 12:02:43 +08:00
YangPeng 6f9079ec5f feat():修改JDK版本问题 2024-09-30 12:01:29 +08:00
xieyaru070903 eff427473f Merge pull request 'feat():修复Redis' (#19) from dev.parse into dev
Reviewed-on: #19
2024-09-30 10:41:50 +08:00
ruyaxie c87bf8a2fa feat():修复Redis 2024-09-30 10:41:15 +08:00
xieyaru070903 0bb5a912f7 Merge pull request 'dev.parse' (#17) from dev.parse into dev
Reviewed-on: #17
2024-09-30 09:14:38 +08:00
ruyaxie 1d43fa7888 feat():修复cloud-common冲突 2024-09-30 09:13:45 +08:00
ruyaxie 61dc7f9277 Merge remote-tracking branch 'origin/dev.parse' into dev.parse
# Conflicts:
#	cloud-common/cloud-common-kafka/pom.xml
#	cloud-common/pom.xml
#	cloud-modules/cloud-modules-data-process/cloud-modules-data-process-server/pom.xml
#	cloud-modules/cloud-modules-data-process/cloud-modules-data-process-server/src/main/resources/bootstrap.yml
#	cloud-modules/cloud-modules-data-process/cloud-modules-data-process-server/src/main/resources/logback/dev.xml
#	cloud-modules/cloud-modules-data-process/cloud-modules-data-process-server/src/main/resources/logback/prod.xml
#	cloud-modules/cloud-modules-data-process/cloud-modules-data-process-server/src/main/resources/logback/test.xml
2024-09-30 09:12:02 +08:00
ruyaxie 6eff930c84 feat():修复代码缓存框架 2024-09-30 08:59:19 +08:00
ruyaxie ecf81cc79e feat():修复代码缓存框架 2024-09-30 01:22:53 +08:00
ruyaxie 63ebaee731 feat():修复代码缓存框架 2024-09-30 01:13:22 +08:00
王鑫 dd94f2e39e fix():修复框架bug 2024-09-29 22:45:06 +08:00
王鑫 2084013449 Merge branch 'dev.data.process' into dev
# Conflicts:
#	pom.xml
2024-09-29 20:04:28 +08:00
王鑫 3ac5b84ef6 Merge remote-tracking branch 'origin/dev.data.process' into dev.data.process
# Conflicts:
#	pom.xml
2024-09-29 17:59:23 +08:00
xieyaru070903 5f391234e2 Merge pull request 'dev.saas' (#12) from dev.saas into dev
Reviewed-on: #12
2024-09-29 17:44:19 +08:00
xieyaru070903 127c941d1c Merge pull request 'dev.saas.yp' (#11) from dev.saas.yp into dev.saas
Reviewed-on: #11
2024-09-29 17:43:23 +08:00
xieyaru070903 f3428404a2 Merge pull request 'fix():增添协议解析的YML' (#10) from dev.parse into dev
Reviewed-on: #10
2024-09-29 17:31:24 +08:00
ruyaxie 491ecec44a fix():增添协议解析的YML 2024-09-29 17:30:09 +08:00
YangPeng efd7a46c68 feat():添加缓存模块封装方法 2024-09-29 17:06:22 +08:00
王鑫 1e19d99748 fix():提交数据处理模块的kafka工具类, 2024-09-29 16:58:58 +08:00
xieyaru070903 93f78cdc3e Merge pull request 'fix():修复框架bug' (#9) from dev.parse into dev
Reviewed-on: #9
2024-09-29 12:28:07 +08:00
ruyaxie 3953642310 fix():修复框架bug 2024-09-29 12:26:51 +08:00
ruyaxie 29f08cbb46 Merge remote-tracking branch 'origin/dev' into dev.parse
# Conflicts:
#	cloud-modules/cloud-modules-enterprise/enterpise-common/pom.xml
2024-09-29 12:26:21 +08:00
ruyaxie 05e6ecb947 fix():修复框架bug 2024-09-29 12:20:14 +08:00
LiHD 1f98e4ea26 Merge pull request 'dev.gateway' (#7) from dev.gateway into dev
Reviewed-on: #7
2024-09-29 10:54:34 +08:00
Li HD 6eb46f53ae Merge remote-tracking branch 'origin/dev.gateway' into dev.gateway
# Conflicts:
#	cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/MessageTemplate.java
#	cloud-modules/cloud-modules-enterprise/enterpise-common/src/main/java/com/muyu/domain/SysCarType.java
2024-09-29 10:51:11 +08:00
Li HD db16c57199 fix():跟新代码 2024-09-29 10:50:18 +08:00
Li HD 90195a9226 fix():初始化 2024-09-29 10:40:08 +08:00
yanchouchou 70ee6d0628 Merge pull request 'dev.saas' (#5) from dev.saas into dev
Reviewed-on: #5
2024-09-29 10:33:30 +08:00
yanchouchou 7971b67277 Merge pull request 'fix():更新模块cloud-modules-enterprise' (#4) from dev.saas.yp into dev.saas
Reviewed-on: #4
2024-09-29 10:32:45 +08:00
YangPeng 49a7e0df4d fix():更新模块cloud-modules-enterprise 2024-09-29 10:31:52 +08:00
Li HD e491c7de89 fix():初始化 2024-09-29 10:29:43 +08:00
yanchouchou 0303b4fe72 Merge pull request 'dev.saas' (#2) from dev.saas into dev
Reviewed-on: #2
2024-09-29 09:40:01 +08:00
yanchouchou 1b982ed5a2 Merge pull request 'dev.saas.yp' (#1) from dev.saas.yp into dev.saas
Reviewed-on: #1
2024-09-29 09:39:30 +08:00
YangPeng 244ceb5b46 fix():添加实现FaultCode添加字段 2024-09-29 00:07:21 +08:00
YangPeng 0ae1ddbbca fix():添加实现cloud-vx pom文件 2024-09-28 18:26:46 +08:00
YangPeng 5994bf1550 fix():修改接口文档,添加注解 controller 和 service 和 domain 2024-09-28 18:21:09 +08:00
YangPeng aa39403714 fix():CarInformation添加实体类 修改其他类的注解 2024-09-30 12:48:15 +08:00
YangPeng 7ae5082c3d feat():message添加注解 2024-09-30 12:18:55 +08:00
YangPeng 40e3a1ceb7 feat():service controller mapper domain 添加注解 2024-09-28 15:11:42 +08:00
753 changed files with 10604 additions and 24374 deletions

View File

@ -34,7 +34,7 @@ public class TokenController {
@PostMapping("login")
public Result<?> login (@RequestBody LoginBody form) {
// 用户登录
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword());
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword(), form.getFirmId());
// 获取登录token
return Result.success(tokenService.createToken(userInfo));
}

View File

@ -1,10 +1,20 @@
package com.muyu.auth.form;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
*
*
* @author muyu
*/
@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
public class LoginBody {
/**
*
@ -16,19 +26,9 @@ public class LoginBody {
*/
private String password;
public String getUsername () {
return username;
}
/**
* id
*/
private Long firmId;
public void setUsername (String username) {
this.username = username;
}
public String getPassword () {
return password;
}
public void setPassword (String password) {
this.password = password;
}
}

View File

@ -40,9 +40,9 @@ public class SysLoginService {
/**
*
*/
public LoginUser login (String username, String password) {
public LoginUser login(String username, String password, Long firmId) {
// 用户名或密码为空 错误
if (StringUtils.isAnyBlank(username, password)) {
if (StringUtils.isAnyBlank(username, password, String.valueOf(firmId))) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户/密码必须填写");
throw new ServiceException("用户/密码必须填写");
}
@ -65,7 +65,9 @@ public class SysLoginService {
throw new ServiceException("很遗憾访问IP已被列入系统黑名单");
}
// 查询用户信息
Result<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
Result<LoginUser> userResult = null;
// 查询用户信息
userResult = remoteUserService.getUserInfo(username, firmId, SecurityConstants.INNER);
if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) {
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在");
@ -91,14 +93,14 @@ public class SysLoginService {
return userInfo;
}
public void logout (String loginName) {
public void logout(String loginName) {
recordLogService.recordLogininfor(loginName, Constants.LOGOUT, "退出成功");
}
/**
*
*/
public void register (String username, String password) {
public void register(String username, String password) {
// 用户名或密码为空 错误
if (StringUtils.isAnyBlank(username, password)) {
throw new ServiceException("用户/密码必须填写");

View File

@ -1,13 +1,13 @@
# Tomcat
server:
port: 9500
port: 19500
# nacos线上地址
nacos:
addr: 123.57.152.124:8848
user-name: nacos
password: nacos
namespace: yan1
namespace: wx
# Spring
spring:
application:

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>cloud-common</artifactId>
<version>3.6.3</version>
</parent>
<description>
cloud-common-cache 缓存基准
</description>
<artifactId>cloud-common-cache</artifactId>
<properties>
<maven.compiler.source>23</maven.compiler.source>
<maven.compiler.target>23</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- redis 缓存模块-->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-redis</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,62 @@
package com.muyu.common.cache;
import com.muyu.common.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.concurrent.TimeUnit;
/**
*
* * @className: CacheAbsBasic
* * @author: Yang 🦅
* * @date: 2024/9/29 16:08
* * @Version: 1.0
* * @description:
*/
public abstract class CacheAbsBasic <K, V> implements CacheBasic<K, V>{
@Autowired
private RedisService redisService;
@Override
public void put(K key, V value) {
try {
redisService.setCacheObject(encode(key), value);
} catch (Exception e) {
throw new RuntimeException("运行时异常,异常信息为:{}"+e.getMessage());
}
}
@Override
public V get(K key) {
try {
return redisService.getCacheObject(encode(key));
} catch (Exception e) {
throw new RuntimeException("运行时异常,异常信息为:{}"+e.getMessage());
}
}
@Override
public void remove(K key) {
try {
redisService.deleteObject(encode(key));
} catch (Exception e) {
throw new RuntimeException("运行时异常,异常信息为:{}"+e.getMessage());
}
}
@Override
public boolean hashKey(K key){
Boolean b = false;
try {
b = redisService.hasKey(encode(key));
} catch (Exception e) {
throw new RuntimeException("运行时异常,异常信息为:{}"+e.getMessage());
}
return b;
}
}

View File

@ -0,0 +1,24 @@
package com.muyu.common.cache;
import org.springframework.data.redis.core.TimeoutUtils;
import java.util.Date;
import java.util.concurrent.TimeUnit;
/**
*
* * @className: CacheBasic
* * @author: Yang 🦅
* * @date: 2024/9/29 16:08
* * @Version: 1.0
* * @description:
*/
public interface CacheBasic<K, V> extends PrimaryKeyBasic<K> {
void put(K key, V value);
V get(K key);
void remove(K key);
boolean hashKey(K key);
}

View File

@ -0,0 +1,40 @@
package com.muyu.common.cache;
/**
*
* * @className: PrimaryKeyBasic
* * @author: Yang 🦅
* * @date: 2024/9/29 16:08
* * @Version: 1.0
* * @description:
*/
public interface PrimaryKeyBasic<K> {
/**
*
*
* @return
*/
public String keyPre();
/**
*
*
* @param key
* @return
*/
public default String encode(K key) {
return key.toString() + keyPre();
}
/**
*
*
* @param key
* @return
*/
public default K decode(String key) {
return (K) key.substring(0, key.lastIndexOf(keyPre()));
}
}

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>cloud-common</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>cloud-common-caffeine</artifactId>
<description>
cloud-common-caffeine 本地缓存服务
</description>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-redis</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,44 @@
package com.muyu.common.caffeine.bean;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.muyu.common.caffeine.enums.CacheNameEnums;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.CacheManager;
import org.springframework.cache.caffeine.CaffeineCache;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* Caffeine
* @Author: WangXin
* @Name: CaffeineCacheConfig
* @Description: Caffeine
*/
@Slf4j
@Component
public class CaffeineManager {
/**
*
* @return
*/
@Bean
public CacheManager cacheManager() {
SimpleCacheManager cacheManager = new SimpleCacheManager();
List<String> cacheNames = CacheNameEnums.getCodes();
cacheManager.setCaches(cacheNames.stream()
.map(name -> new CaffeineCache(
name,
Caffeine.newBuilder()
.recordStats()
.build()))
.toList());
log.info("缓存管理器初始化完成,缓存分区:{}", cacheNames);
return cacheManager;
}
}

View File

@ -0,0 +1,15 @@
package com.muyu.common.caffeine.constents;
/**
* Caffeine
* @Author: WangXin
* @Name: CaffeineContent
* @Description: Caffeine
*/
public class CaffeineContent {
public static final String CAR_VIN_KEY = "car:vin";
public static final String VIN = "vin";
}

View File

@ -0,0 +1,66 @@
package com.muyu.common.caffeine.enums;
import lombok.Getter;
import java.util.Arrays;
import java.util.List;
/**
*
*
* @Author: WangXin
* @Name: CacheNameEnums
* @Description:
*/
@Getter
public enum CacheNameEnums {
STORAGE("storage", "持久化"),
FAULT("fault", "故障"),
FENCE("fence", "围栏"),
WARMING("warming", "预警"),
REALTIME("realTime", "实时信息");
private final String code;
private final String info;
CacheNameEnums(String code, String info) {
this.code = code;
this.info = info;
}
/**
*
*
* @param code
* @return turn, false
*/
public static boolean isCode(String code) {
return Arrays.stream(values())
.map(CacheNameEnums::getCode)
.anyMatch(c -> c.equals(code));
}
/**
* Value
* @param code
* @return Value
*/
public static String getInfo(String code) {
return Arrays.stream(values())
.filter(c -> c.getCode().equals(code))
.map(CacheNameEnums::getInfo)
.findFirst()
.orElse("");
}
/**
* code
* @return code
*/
public static List<String> getCodes() {
return Arrays.stream(values())
.map(CacheNameEnums::getCode)
.toList();
}
}

View File

@ -0,0 +1,89 @@
package com.muyu.common.caffeine.utils;
import com.muyu.common.caffeine.enums.CacheNameEnums;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.cache.CacheManager;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
/**
* Caffeine
* @Author: WangXin
* @Name: CaffeineUtils
* @Description:
* @CreatedDate: 2024/9/26 2:53
* @FilePath: com.muyu.common.caffeine
*/
@Slf4j
@Component
public class CaffeineCacheUtils {
@Resource
private CacheManager cacheManager;
@Resource
private RedisTemplate<String, String> redisTemplate;
/**
* 线 -
*/
public void addCarCache(String vin) {
// 从Redis中获取缓存信息
for (String name : CacheNameEnums.getCodes()) {
String value = redisTemplate.opsForValue().get(name+":"+vin);
cacheManager.getCache(name).put(vin, value);
log.info("存储缓存, 缓存分区:[{}], 车辆编码:[{}], 存储值:[{}]", name, vin, value);
}
log.info("车辆编码:{},本地缓存完成...",vin);
}
/**
* 线 -
*/
public void deleteCarCache(String cacheName) {
if (!hasCarVinCache(cacheName,null)) {
log.warn("车辆编码:{},本地缓存不存在该车辆信息...", cacheName);
return;
}
cacheManager.getCache(cacheName).invalidate();
log.info("车辆编码:{},本地缓存删除完成...", cacheName);
}
/**
*
*/
public Object getCarCache(String cacheName, String key) {
if (!hasCarVinCache(cacheName, key)){
log.warn("车辆编码:{},本地缓存不存在该车辆信息...",cacheName);
return null;
}
return cacheManager.getCache(cacheName).get(key).get();
}
/**
*
*/
public <T> T getCarCache(String cacheName, String key, Class<T> type) {
if (!hasCarVinCache(cacheName,key)){
log.warn("车辆编码:{},本地缓存不存在该车辆信息...",cacheName);
return null;
}
return cacheManager.getCache(cacheName).get(key, type);
}
/**
*
*/
public Boolean hasCarVinCache(String cacheName,String key) {
boolean notEmpty = ObjectUtils.isNotEmpty(cacheManager.getCache(cacheName));
if (notEmpty && StringUtils.isNotEmpty(key)){
return ObjectUtils.isNotEmpty(cacheManager.getCache(cacheName).get(key).get());
}
return notEmpty;
}
}

View File

@ -0,0 +1,2 @@
com.muyu.common.caffeine.utils.CaffeineCacheUtils
com.muyu.common.caffeine.bean.CaffeineManager

View File

@ -9,12 +9,12 @@ public class CacheConstants {
/**
* 720
*/
public final static long EXPIRATION = 720;
public final static Long EXPIRATION = 720L;
/**
* 120
*/
public final static long REFRESH_TIME = 120;
public final static Long REFRESH_TIME = 120L;
/**
*
@ -24,7 +24,7 @@ public class CacheConstants {
/**
* 10
*/
public final static long PASSWORD_LOCK_TIME = 10;
public final static Long PASSWORD_LOCK_TIME = 10L;
/**
*

View File

@ -109,7 +109,7 @@ public class Constants {
/**
*
*/
public static final long CAPTCHA_EXPIRATION = 2;
public static final Long CAPTCHA_EXPIRATION = 2L;
/**
*

View File

@ -54,7 +54,7 @@ public class GenConstants {
/**
*
*/
public static final String[] COLUMNTYPE_TEXT = {"tinytext", "text", "mediumtext", "longtext"};
public static final String[] COLUMNTYPE_TEXT = {"tinytext", "text", "mediumtext", "Longtext"};
/**
*

View File

@ -45,4 +45,13 @@ public class SecurityConstants {
*
*/
public static final String ROLE_PERMISSION = "role_permission";
/**
* key
*/
public static final String FIRM_KEY = "firm_key";
/**
* Id
*/
public static final String FIRM_ID = "firm_id";
}

View File

@ -20,4 +20,10 @@ public class ServiceNameConstants {
* serviceid
*/
public static final String FILE_SERVICE = "cloud-file";
/**
* serviceid
*/
public static final String ENTERPRISE_SERVICE = "cloud-saas";
}

View File

@ -19,6 +19,6 @@ public class TokenConstants {
/**
*
*/
public final static String SECRET = "abcdefghijklmnsalieopadfaqawefwerstuvwxyz";
public final static String SECRET = "abcdefghijklmnsalieopadfaqawefwerstuvxyryz";
}

View File

@ -3,9 +3,9 @@ package com.muyu.common.core.domain;
import com.muyu.common.core.constant.Constants;
import com.muyu.common.core.constant.HttpStatus;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.io.Serializable;
@ -15,7 +15,7 @@ import java.io.Serializable;
* @author muyu
*/
@Data
@Builder
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {
@ -32,7 +32,8 @@ public class Result<T> implements Serializable {
*/
public static final int WARN = HttpStatus.WARN;
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
private int code;
private String msg;
@ -96,8 +97,8 @@ public class Result<T> implements Serializable {
private static <T> Result<T> restResult (T data, int code, String msg) {
return Result.<T>builder()
.code(code)
.data(data)
.msg(msg)
.data(data)
.build();
}

View File

@ -6,7 +6,7 @@ package com.muyu.common.core.exception;
* @author muyu
*/
public class CaptchaException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
public CaptchaException (String msg) {
super(msg);

View File

@ -6,7 +6,7 @@ package com.muyu.common.core.exception;
* @author muyu
*/
public class CheckedException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
public CheckedException (String message) {
super(message);

View File

@ -6,7 +6,7 @@ package com.muyu.common.core.exception;
* @author muyu
*/
public class DemoModeException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
public DemoModeException () {
}

View File

@ -6,7 +6,7 @@ package com.muyu.common.core.exception;
* @author muyu
*/
public class GlobalException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
/**
*

View File

@ -6,7 +6,7 @@ package com.muyu.common.core.exception;
* @author muyu
*/
public class InnerAuthException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
public InnerAuthException (String message) {
super(message);

View File

@ -6,7 +6,7 @@ package com.muyu.common.core.exception;
* @author muyu
*/
public class PreAuthorizeException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
public PreAuthorizeException () {
}

View File

@ -5,8 +5,8 @@ package com.muyu.common.core.exception;
*
* @author muyu
*/
public final class ServiceException extends RuntimeException {
private static final long serialVersionUID = 1L;
public class ServiceException extends RuntimeException {
private static final Long serialVersionUID = 1L;
/**
*
@ -21,7 +21,7 @@ public final class ServiceException extends RuntimeException {
/**
*
* <p>
* {@link CommonResult#getDetailMessage()}
* {@link #()}
*/
private String detailMessage;

View File

@ -6,7 +6,7 @@ package com.muyu.common.core.exception;
* @author muyu
*/
public class UtilException extends RuntimeException {
private static final long serialVersionUID = 8247610319171014183L;
private static final Long serialVersionUID = 8247610319171014183L;
public UtilException (Throwable e) {
super(e.getMessage(), e);

View File

@ -6,7 +6,7 @@ package com.muyu.common.core.exception.auth;
* @author muyu
*/
public class NotLoginException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
public NotLoginException (String message) {
super(message);

View File

@ -8,7 +8,7 @@ import org.apache.commons.lang3.StringUtils;
* @author muyu
*/
public class NotPermissionException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
public NotPermissionException (String permission) {
super(permission);

View File

@ -8,7 +8,7 @@ import org.apache.commons.lang3.StringUtils;
* @author muyu
*/
public class NotRoleException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
public NotRoleException (String role) {
super(role);

View File

@ -6,7 +6,7 @@ package com.muyu.common.core.exception.base;
* @author muyu
*/
public class BaseException extends RuntimeException {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
/**
*

View File

@ -8,7 +8,7 @@ import com.muyu.common.core.exception.base.BaseException;
* @author muyu
*/
public class FileException extends BaseException {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
public FileException (String code, Object[] args, String msg) {
super("file", code, args, msg);

View File

@ -6,9 +6,9 @@ package com.muyu.common.core.exception.file;
* @author muyu
*/
public class FileNameLengthLimitExceededException extends FileException {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
public FileNameLengthLimitExceededException (int defaultFileNameLength) {
super("upload.filename.exceed.length", new Object[]{defaultFileNameLength}, "the filename is too long");
super("upload.filename.exceed.length", new Object[]{defaultFileNameLength}, "the filename is too Long");
}
}

View File

@ -6,9 +6,9 @@ package com.muyu.common.core.exception.file;
* @author muyu
*/
public class FileSizeLimitExceededException extends FileException {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
public FileSizeLimitExceededException (long defaultMaxSize) {
public FileSizeLimitExceededException (Long defaultMaxSize) {
super("upload.exceed.maxSize", new Object[]{defaultMaxSize}, "the filesize is too large");
}
}

View File

@ -10,7 +10,7 @@ import java.io.PrintWriter;
*/
public class FileUploadException extends Exception {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
private final Throwable cause;

View File

@ -8,7 +8,7 @@ import java.util.Arrays;
* @author muyu
*/
public class InvalidExtensionException extends FileUploadException {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
private String[] allowedExtension;
private String extension;
@ -34,7 +34,7 @@ public class InvalidExtensionException extends FileUploadException {
}
public static class InvalidImageExtensionException extends InvalidExtensionException {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
public InvalidImageExtensionException (String[] allowedExtension, String extension, String filename) {
super(allowedExtension, extension, filename);
@ -42,7 +42,7 @@ public class InvalidExtensionException extends FileUploadException {
}
public static class InvalidFlashExtensionException extends InvalidExtensionException {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
public InvalidFlashExtensionException (String[] allowedExtension, String extension, String filename) {
super(allowedExtension, extension, filename);
@ -50,7 +50,7 @@ public class InvalidExtensionException extends FileUploadException {
}
public static class InvalidMediaExtensionException extends InvalidExtensionException {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
public InvalidMediaExtensionException (String[] allowedExtension, String extension, String filename) {
super(allowedExtension, extension, filename);
@ -58,7 +58,7 @@ public class InvalidExtensionException extends FileUploadException {
}
public static class InvalidVideoExtensionException extends InvalidExtensionException {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
public InvalidVideoExtensionException (String[] allowedExtension, String extension, String filename) {
super(allowedExtension, extension, filename);

View File

@ -6,7 +6,7 @@ package com.muyu.common.core.exception.job;
* @author muyu
*/
public class TaskException extends Exception {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
private Code code;

View File

@ -6,7 +6,7 @@ package com.muyu.common.core.exception.user;
* @author muyu
*/
public class CaptchaExpireException extends UserException {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
public CaptchaExpireException () {
super("user.jcaptcha.expire", null);

View File

@ -8,7 +8,7 @@ import com.muyu.common.core.exception.base.BaseException;
* @author muyu
*/
public class UserException extends BaseException {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
public UserException (String code, Object[] args) {
super("user", code, args, null);

View File

@ -6,7 +6,7 @@ package com.muyu.common.core.exception.user;
* @author muyu
*/
public class UserPasswordNotMatchException extends UserException {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
public UserPasswordNotMatchException () {
super("user.password.not.match", null);

View File

@ -313,12 +313,12 @@ public class Convert {
return new Long[]{};
}
String[] arr = str.split(split);
final Long[] longs = new Long[arr.length];
final Long[] Longs = new Long[arr.length];
for (int i = 0 ; i < arr.length ; i++) {
final Long v = toLong(arr[i], null);
longs[i] = v;
Longs[i] = v;
}
return longs;
return Longs;
}
/**
@ -345,7 +345,7 @@ public class Convert {
}
/**
* long<br>
* Long<br>
* <br>
*
*
@ -377,7 +377,7 @@ public class Convert {
}
/**
* long<br>
* Long<br>
* <code>null</code><code>null</code><br>
*
*

View File

@ -109,7 +109,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
*
*/
public static Date getServerStartDate () {
long time = ManagementFactory.getRuntimeMXBean().getStartTime();
Long time = ManagementFactory.getRuntimeMXBean().getStartTime();
return new Date(time);
}
@ -122,20 +122,20 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
* @return //
*/
public static String timeDistance (Date endDate, Date startTime) {
long nd = 1000 * 24 * 60 * 60;
long nh = 1000 * 60 * 60;
long nm = 1000 * 60;
// long ns = 1000;
Long nd = 1000 * 24 * 60 * 60L;
Long nh = 1000 * 60 * 60L;
Long nm = 1000 * 60L;
// Long ns = 1000;
// 获得两个时间的毫秒时间差异
long diff = endDate.getTime() - startTime.getTime();
Long diff = endDate.getTime() - startTime.getTime();
// 计算差多少天
long day = diff / nd;
Long day = diff / nd;
// 计算差多少小时
long hour = diff % nd / nh;
Long hour = diff % nd / nh;
// 计算差多少分钟
long min = diff % nd % nh / nm;
Long min = diff % nd % nh / nm;
// 计算差多少秒//输出结果
// long sec = diff % nd % nh % nm / ns;
// Long sec = diff % nd % nh % nm / ns;
return day + "天" + hour + "小时" + min + "分钟";
}

View File

@ -162,4 +162,21 @@ public class JwtUtils {
public static String getValue (Claims claims, String key) {
return Convert.toStr(claims.get(key), "");
}
/**
*
* @param claims
* @return
*/
public static String getFirmKey(Claims claims) {
return getValue(claims, SecurityConstants.FIRM_KEY);
}
/**
*
* @param claims
* @return
*/
public static String getFirmId(Claims claims) {
return getValue(claims, SecurityConstants.FIRM_ID);
}
}

View File

@ -45,7 +45,7 @@ public final class HTMLFilter {
private static final ConcurrentMap<String, Pattern> P_REMOVE_SELF_BLANKS = new ConcurrentHashMap<>();
/**
* set of allowed html elements, along with allowed attributes for each element
* set of allowed html elements, aLong with allowed attributes for each element
**/
private final Map<String, List<String>> vAllowed;
/**

View File

@ -127,7 +127,7 @@ public class IpUtils {
byte[] bytes = new byte[4];
String[] elements = text.split("\\.", -1);
try {
long l;
Long l;
int i;
switch (elements.length) {
case 1:
@ -141,12 +141,12 @@ public class IpUtils {
bytes[3] = (byte) (int) (l & 0xFF);
break;
case 2:
l = Integer.parseInt(elements[0]);
l = (long) Integer.parseInt(elements[0]);
if ((l < 0L) || (l > 255L)) {
return null;
}
bytes[0] = (byte) (int) (l & 0xFF);
l = Integer.parseInt(elements[1]);
l = (long) Integer.parseInt(elements[1]);
if ((l < 0L) || (l > 16777215L)) {
return null;
}
@ -156,13 +156,13 @@ public class IpUtils {
break;
case 3:
for (i = 0; i < 2 ; ++i) {
l = Integer.parseInt(elements[i]);
l = (long) Integer.parseInt(elements[i]);
if ((l < 0L) || (l > 255L)) {
return null;
}
bytes[i] = (byte) (int) (l & 0xFF);
}
l = Integer.parseInt(elements[2]);
l = (long) Integer.parseInt(elements[2]);
if ((l < 0L) || (l > 65535L)) {
return null;
}
@ -171,7 +171,7 @@ public class IpUtils {
break;
case 4:
for (i = 0; i < 4 ; ++i) {
l = Integer.parseInt(elements[i]);
l = (long) Integer.parseInt(elements[i]);
if ((l < 0L) || (l > 255L)) {
return null;
}
@ -290,14 +290,14 @@ public class IpUtils {
String[] sips = iparea.substring(0, idx).split("\\.");
String[] sipe = iparea.substring(idx + 1).split("\\.");
String[] sipt = ip.split("\\.");
long ips = 0L, ipe = 0L, ipt = 0L;
Long ips = 0L, ipe = 0L, ipt = 0L;
for (int i = 0 ; i < 4 ; ++i) {
ips = ips << 8 | Integer.parseInt(sips[i]);
ipe = ipe << 8 | Integer.parseInt(sipe[i]);
ipt = ipt << 8 | Integer.parseInt(sipt[i]);
}
if (ips > ipe) {
long t = ips;
Long t = ips;
ips = ipe;
ipe = t;
}

View File

@ -30,8 +30,8 @@ public final class UUID implements java.io.Serializable, Comparable<UUID> {
* @param data
*/
private UUID (byte[] data) {
long msb = 0;
long lsb = 0;
long msb = 0L;
long lsb = 0L;
assert data.length == 16 : "data must be 16 bytes in length";
for (int i = 0 ; i < 8 ; i++) {
msb = (msb << 8) | (data[i] & 0xff);
@ -131,15 +131,15 @@ public final class UUID implements java.io.Serializable, Comparable<UUID> {
components[i] = "0x" + components[i];
}
long mostSigBits = Long.decode(components[0]).longValue();
long mostSigBits = Long.decode(components[0]);
mostSigBits <<= 16;
mostSigBits |= Long.decode(components[1]).longValue();
mostSigBits |= Long.decode(components[1]);
mostSigBits <<= 16;
mostSigBits |= Long.decode(components[2]).longValue();
mostSigBits |= Long.decode(components[2]);
long leastSigBits = Long.decode(components[3]).longValue();
long leastSigBits = Long.decode(components[3]);
leastSigBits <<= 48;
leastSigBits |= Long.decode(components[4]).longValue();
leastSigBits |= Long.decode(components[4]);
return new UUID(mostSigBits, leastSigBits);
}

View File

@ -1,9 +1,11 @@
package com.muyu.common.core.web.controller;
import com.github.pagehelper.PageInfo;
import com.muyu.common.core.utils.DateUtils;
import com.muyu.common.core.utils.PageUtils;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.common.core.web.page.TableDataInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -19,7 +21,7 @@ import java.util.List;
*
* @author muyu
*/
public class BaseController {
public class BaseController<M extends BaseEntity> {
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
/**

View File

@ -24,7 +24,7 @@ import java.util.Map;
@NoArgsConstructor
@AllArgsConstructor
public class BaseEntity implements Serializable {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
/**
*

View File

@ -17,7 +17,7 @@ import java.util.List;
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class TreeEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
/**
*

View File

@ -20,7 +20,7 @@ import java.util.List;
@NoArgsConstructor
@AllArgsConstructor
public class TableDataInfo<T> implements Serializable {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
/**
*

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>cloud-common</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>cloud-common-iotdb</artifactId>
<description>
cloud-common-iotdb 时序性数据存储服务
</description>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-session</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,180 @@
package com.muyu.common.iotdb.config;
import com.alibaba.fastjson2.JSONObject;
import lombok.extern.log4j.Log4j2;
import org.apache.iotdb.isession.SessionDataSet;
import org.apache.iotdb.isession.pool.SessionDataSetWrapper;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.session.pool.SessionPool;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.read.common.Field;
import org.apache.iotdb.tsfile.read.common.RowRecord;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.muyu.common.iotdb.constant.IotdbConstant.ROOT_DATA_DATAJSON;
import static com.muyu.common.iotdb.constant.IotdbConstant.SELECT_ROOT_DATA_DATAJSON_DATASOURCE;
/**
* @Author WangXin
* @Data 2024/9/30
* @Description IotDBSessionConfig
* @Version 1.0.0
*/
@Log4j2
@Component
@Configuration
public class IotDBSessionConfig {
@Value("${spring.iotdb.username:root}")
private String username;
@Value("${spring.iotdb.password:root}")
private String password;
@Value("${spring.iotdb.ip:127.0.0.1}")
private String ip;
@Value("${spring.iotdb.port:6667}")
private int port;
@Value("${spring.iotdb.maxSize:10}")
private int maxSize;
private static SessionPool sessionPool;
/**
* IotDBSession
* @return iotDBSession
*/
public SessionPool getSessionPool() {
if (sessionPool == null) {
sessionPool = new SessionPool(ip, port, username, password, maxSize);
}
return sessionPool;
}
/**
*
* @param deviceId
* @param time
* @param measurements
* @param value
*/
public void insertRecord(SessionPool sessionPool,String deviceId,
Long time, List<String> measurements,List<TSDataType> dataTypeList, JSONObject value) {
try {
log.info("iotdb数据入库device_id:[{}], measurements:[{}], values:[{}]", deviceId, measurements, value);
sessionPool.insertRecord(deviceId, time, measurements,dataTypeList,new Object[]{value.toJSONString()});
} catch (Exception e) {
log.error("IotDBSession insertRecord失败: deviceId={}, time={}, measurements={}, values={}, error={}",
deviceId, time, measurements, value, e.getMessage());
}
}
public void JSONObject(JSONObject value){
}
/**
* sql
* @param sessionPool
* @param sql
* @return
*/
public SessionDataSet selectRecord(SessionPool sessionPool,String sql) {
log.info("iotdb数据查询sql:[{}]",sql);
SessionDataSetWrapper sessionDataSetWrapper = null;
try {
log.info("iotdb SQL查询sql:[{}]", sql);
sessionDataSetWrapper = sessionPool.executeQueryStatement(sql);
return sessionDataSetWrapper.getSessionDataSet();
} catch (Exception e) {
log.error("IotDBSession executeQueryStatement失败:sql:[{}],error={}", sql, e.getMessage());
throw new RuntimeException(e);
}
}
public JSONObject getJsonFindByTime(SessionPool sessionPool,String fieldName,String deviceId,Long timestamp) {
String sql = String.format("SELECT %s FROM %s WHERE time = %d", fieldName, deviceId, timestamp);
SessionDataSet sessionDataSet = selectRecord(sessionPool, sql);
try {
while (sessionDataSet.hasNext()){
RowRecord next = sessionDataSet.next();
for (Field field : next.getFields()) {
String stringValue = field.getStringValue();
}
}
} catch (StatementExecutionException e) {
throw new RuntimeException(e);
} catch (IoTDBConnectionException e) {
throw new RuntimeException(e);
}
return null;
}
public static void main(String[] args) {
SessionPool sessionPool = new SessionPool("127.0.0.1", 6667, "root", "root", 10);
String jsonValue = """
{
"name": "张三",
"age": 28,
"email": "zhangsan@example.com",
"isStudent": false,
"hobbies": ["阅读", "旅行", "编程"],
"address": {
"street": "长安街100号",
"city": "北京",
"postalCode": "100000"
}
}
""";
JSONObject value = JSONObject.parseObject(jsonValue);
IotDBSessionConfig iotDBSessionConfig = new IotDBSessionConfig();
List<String> measurements = List.of("datasource");
List<TSDataType> datatypeList = List.of(TSDataType.TEXT);
iotDBSessionConfig.insertRecord(sessionPool,ROOT_DATA_DATAJSON,System.currentTimeMillis(),measurements,datatypeList,value);
SessionDataSet sessionDataSet = iotDBSessionConfig.selectRecord(sessionPool,SELECT_ROOT_DATA_DATAJSON_DATASOURCE);
HashMap<Long, Map<String, String>> LongMapHashMap = new HashMap<>();
try {
while (sessionDataSet.hasNext()){
RowRecord next = sessionDataSet.next();
Long timestamp = next.getTimestamp();
Map<String, String> fieldMap = new HashMap<>();
for (Field field : next.getFields()) {
TSDataType dataType = field.getDataType();
String stringValue = field.getStringValue();
fieldMap.put(dataType.name(), stringValue);
}
LongMapHashMap.put(timestamp, fieldMap);
}
} catch (StatementExecutionException e) {
throw new RuntimeException(e);
} catch (IoTDBConnectionException e) {
throw new RuntimeException(e);
}
log.info("数据为:{}", JSONObject.toJSONString(LongMapHashMap));
}
}

View File

@ -0,0 +1,14 @@
package com.muyu.common.iotdb.constant;
/**
* @Author WangXin
* @Data 2024/9/30
* @Description iotdb
* @Version 1.0.0
*/
public interface IotdbConstant {
String ROOT_DATA_DATAJSON = "root.car.data.datajson";
String SELECT_ROOT_DATA_DATAJSON_DATASOURCE = "select * from root.car.data.datajson";
}

View File

@ -0,0 +1,40 @@
package com.muyu.common.iotdb.domain;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.List;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class InsertDataDTO {
private Float temperature;
private String hardware;
private Boolean status;
public InsertDataDTO buildOne() {
InsertDataDTO insertDataDTO = new InsertDataDTO();
insertDataDTO.setHardware("ss");
insertDataDTO.setStatus(true);
insertDataDTO.setTemperature(12.0F);
return insertDataDTO;
}
public List<InsertDataDTO> buildList() {
List<InsertDataDTO> insertDataDTOS = new ArrayList<>();
int buildNum = 10;
for (int i = 0; i < buildNum; i++) {
InsertDataDTO insertDataDTO = new InsertDataDTO();
insertDataDTO.setHardware(i % 2 == 0 ? "pp" + i : null);
insertDataDTO.setStatus(i % 2 == 0);
insertDataDTO.setTemperature(12.0F + i);
insertDataDTOS.add(insertDataDTO);
}
return insertDataDTOS;
}
}

View File

@ -0,0 +1,14 @@
package com.muyu.common.iotdb.domain.dto;
import lombok.Data;
/**
* @Author WangXin
* @Data 2024/9/30
* @Description IotDBServiceImpl
* @Version 1.0.0
*/
@Data
public class IotDbRecordAble {
}

View File

@ -0,0 +1,23 @@
package com.muyu.common.iotdb.domain.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
import java.util.List;
@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
public class MeasurementSchemaValuesDTO {
private List<MeasurementSchema> schemaList;
private List<Object> values;
private List<Integer> valueIsNullIndex;
}

View File

@ -0,0 +1,105 @@
package com.muyu.common.iotdb.service;
import com.muyu.common.iotdb.domain.dto.IotDbRecordAble;
import com.muyu.common.iotdb.domain.dto.MeasurementSchemaValuesDTO;
import org.apache.iotdb.common.rpc.thrift.TAggregationType;
import org.apache.iotdb.isession.SessionDataSet;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.write.record.Tablet;
import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
import java.util.List;
import java.util.Map;
/**
* @Author WangXin
* @Data 2024/9/28
* @Description IotDBServiceImpl
* @Version 1.0.0
*/
public interface IotDBService {
void insertTablet(Tablet tablet);
void insertTablets(Map<String, Tablet> tablets);
void insertStringRecord(String deviceId, Long time, List<String> measurements, List<String> values);
void insertRecord(String deviceId, Long time, List<String> measurements, List<TSDataType> types, List<Object> values);
void insertStringRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<String>> valuesList);
void insertRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList);
void insertStringRecordsOfOneDevice(String deviceId, List<Long> times, List<List<String>> measurementsList, List<List<String>> valuesList);
void insertRecordsOfOneDevice(String deviceId, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList);
void deleteData(String path, Long endTime);
void deleteData(List<String> paths, Long endTime);
SessionDataSet executeRawDataQuery(List<String> paths, Long startTime, Long endTime, Long timeOut);
<T> List<T> executeRawDataQuery(List<String> paths, Long startTime, Long endTime, Long timeOut, Class<? extends IotDbRecordAble> clazz);
SessionDataSet executeLastDataQuery(List<String> paths, Long lastTime);
<T> List<T> executeLastDataQuery(List<String> paths, Long lastTime, Class<? extends IotDbRecordAble> clazz);
SessionDataSet executeLastDataQueryForOneDevice(String db, String device, List<String> sensors, boolean isLegalPathNodes);
<T> List<T> executeLastDataQueryForOneDevice(String db, String device, List<String> sensors, boolean isLegalPathNodes, Class<? extends IotDbRecordAble> clazz);
SessionDataSet executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations);
SessionDataSet executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations, Long startTime, Long endTime);
SessionDataSet executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations, Long startTime, Long endTime, Long interval);
SessionDataSet executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations, Long startTime, Long endTime, Long interval, Long slidingStep);
SessionDataSet executeQueryStatement(String sql);
/**
* SQL
*
* @param sql
*/
void executeNonQueryStatement(String sql);
/**
*
*
* @param sessionDataSet
* @param titleList
*/
List<Map<String, Object>> packagingMapData(SessionDataSet sessionDataSet, List<String> columnNames);
/**
*
*
* @param sessionDataSet
* @param titleList
* @param clazz
* @param <T>
* @return
*/
<T> List<T> packagingObjectData(SessionDataSet sessionDataSet, List<String> titleList, Class<? extends IotDbRecordAble> clazz);
/**
* MeasurementSchemas
*
* @param object
* @return
*/
List<MeasurementSchema> buildMeasurementSchemas(Object object);
/**
* MeasurementSchemaValuesDTO
*
* @param object
* @return
*/
MeasurementSchemaValuesDTO buildMeasurementSchemasAndValues(Object object);
}

View File

@ -0,0 +1,711 @@
package com.muyu.common.iotdb.service.impl;
import com.alibaba.fastjson2.JSON;
import com.muyu.common.iotdb.config.IotDBSessionConfig;
import com.muyu.common.iotdb.domain.dto.IotDbRecordAble;
import com.muyu.common.iotdb.domain.dto.MeasurementSchemaValuesDTO;
import com.muyu.common.iotdb.service.IotDBService;
import jakarta.annotation.Resource;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.iotdb.common.rpc.thrift.TAggregationType;
import org.apache.iotdb.isession.SessionDataSet;
import org.apache.iotdb.isession.pool.SessionDataSetWrapper;
import org.apache.iotdb.session.pool.SessionPool;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.read.common.Field;
import org.apache.iotdb.tsfile.read.common.RowRecord;
import org.apache.iotdb.tsfile.write.record.Tablet;
import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
import org.springframework.stereotype.Service;
import java.lang.reflect.Type;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Author WangXin
* @Data 2024/9/28
* @Description IotDBServiceImpl
* @Version 1.0.0
*/
@Service
@Slf4j
public class IotDBServiceImpl implements IotDBService {
@Resource
private IotDBSessionConfig iotDBSessionConfig;
/**
*
*
* @param tablet
*/
@Override
public void insertTablet(Tablet tablet) {
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
try {
log.info("iotdb数据入库tablet:[{}]", tablet);
sessionPool.insertTablet(tablet);
} catch (Exception e) {
log.error("IotDBSession insertTablet失败: tablet={}, error={}", tablet, e.getMessage());
}
}
/**
*
*
* @param tablets
*/
@Override
public void insertTablets(Map<String, Tablet> tablets) {
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
try {
log.info("iotdb数据入库tablets:[{}]", tablets);
sessionPool.insertTablets(tablets);
} catch (Exception e) {
log.error("IotDBSession insertTablets失败: tablets={}, error={}", tablets, e.getMessage());
}
}
/**
* string
*
* @param deviceId root.ln.wf01.wt01
* @param time
* @param measurements
* @param values
*/
@Override
public void insertStringRecord(String deviceId, Long time, List<String> measurements, List<String> values) {
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
try {
log.info("iotdb数据入库device_id:[{}], measurements:[{}], values:[{}]", deviceId, measurements, values);
sessionPool.insertRecord(deviceId, time, measurements, values);
} catch (Exception e) {
log.error("IotDBSession insertRecord失败: deviceId={}, time={}, measurements={}, values={}, error={}",
deviceId, time, measurements, values, e.getMessage());
}
}
/**
*
*
* @param deviceId root.ln.wf01.wt01
* @param time
* @param measurements
* @param types
* @param values
*/
@Override
public void insertRecord(String deviceId, Long time, List<String> measurements, List<TSDataType> types, List<Object> values) {
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
try {
log.info("iotdb数据入库device_id:[{}], measurements:[{}], types:[{}], values:[{}]", deviceId, measurements, types, values);
sessionPool.insertRecord(deviceId, time, measurements, types, values);
} catch (Exception e) {
log.error("IotDBSession insertRecordHasTypes失败: deviceId={}, time={}, measurements={},types={}, values={}, error={}",
deviceId, time, measurements, types, values, e.getMessage());
}
}
/**
* string
*
* @param deviceIds root.ln.wf01.wt01
* @param times
* @param measurementsList
* @param valuesList
*/
@Override
public void insertStringRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<String>> valuesList) {
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
try {
log.info("iotdb数据入库deviceIds:[{}], measurementsList:[{}], valuesList:[{}]", deviceIds, measurementsList, valuesList);
sessionPool.insertRecords(deviceIds, times, measurementsList, valuesList);
} catch (Exception e) {
log.error("IotDBSession insertRecords失败: deviceIds={}, times={}, measurementsList={}, valuesList={}, error={}",
deviceIds, times, measurementsList, valuesList, e.getMessage());
}
}
/**
*
*
* @param deviceIds root.ln.wf01.wt01
* @param times
* @param measurementsList
* @param typesList
* @param valuesList
*/
@Override
public void insertRecords(List<String> deviceIds, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList) {
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
try {
log.info("iotdb数据入库deviceIds:[{}], measurementsList:[{}], typesList[{}], valuesList:[{}]", deviceIds, measurementsList, typesList, valuesList);
sessionPool.insertRecords(deviceIds, times, measurementsList, typesList, valuesList);
} catch (Exception e) {
log.error("IotDBSession insertRecords失败: deviceIds={}, times={}, measurementsList={}, typesList=[],valuesList={}, error={}",
deviceIds, times, measurementsList, typesList, valuesList, e.getMessage());
}
}
/**
* string
*
* @param deviceId root.ln.wf01.wt01
* @param times
* @param measurementsList
* @param valuesList
*/
@Override
public void insertStringRecordsOfOneDevice(String deviceId, List<Long> times, List<List<String>> measurementsList, List<List<String>> valuesList) {
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
try {
log.info("iotdb数据入库deviceId:[{}], measurementsList:[{}], valuesList:[{}]", deviceId, measurementsList, valuesList);
sessionPool.insertStringRecordsOfOneDevice(deviceId, times, measurementsList, valuesList);
} catch (Exception e) {
log.error("IotDBSession insertStringRecordsOfOneDevice失败: deviceId={}, times={}, measurementsList={}, valuesList={}, error={}",
deviceId, times, measurementsList, valuesList, e.getMessage());
}
}
/**
*
*
* @param deviceId root.ln.wf01.wt01
* @param times
* @param measurementsList
* @param typesList
* @param valuesList
*/
@Override
public void insertRecordsOfOneDevice(String deviceId, List<Long> times, List<List<String>> measurementsList, List<List<TSDataType>> typesList, List<List<Object>> valuesList) {
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
try {
log.info("iotdb数据入库deviceId:[{}], measurementsList:[{}], typesList[{}], valuesList:[{}]", deviceId, measurementsList, typesList, valuesList);
sessionPool.insertRecordsOfOneDevice(deviceId, times, measurementsList, typesList, valuesList);
} catch (Exception e) {
log.error("IotDBSession insertRecordsOfOneDevice失败: deviceId={}, times={}, measurementsList={}, typesList=[],valuesList={}, error={}", deviceId, times, measurementsList, typesList, valuesList, e.getMessage());
}
}
/**
*
*
* @param path root.ln.wf01.wt01.temperature
* @param endTime
*/
@Override
public void deleteData(String path, Long endTime) {
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
try {
log.info("iotdb数据删除path:[{}], endTime:[{}]", path, endTime);
sessionPool.deleteData(path, endTime);
} catch (Exception e) {
log.error("IotDBSession deleteData失败: deviceId={}, times={},error={}", path, endTime, e.getMessage());
}
}
/**
*
*
* @param paths root.ln.wf01.wt01.temperature
* @param endTime
*/
@Override
public void deleteData(List<String> paths, Long endTime) {
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
try {
log.info("iotdb数据删除paths:[{}], endTime:[{}]", paths, endTime);
sessionPool.deleteData(paths, endTime);
} catch (Exception e) {
log.error("IotDBSession deleteData失败: paths={}, times={},error={}", paths, endTime, e.getMessage());
}
}
/**
*
*
* @param paths root.ln.wf01.wt01.temperature
* @param startTime
* @param endTime
* @param outTime
* @return SessionDataSet (Time,paths)
*/
@Override
public SessionDataSet executeRawDataQuery(List<String> paths, Long startTime, Long endTime, Long outTime) {
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
SessionDataSetWrapper sessionDataSetWrapper = null;
try {
log.info("iotdb数据查询paths:[{}], startTime[{}], endTime:[{}],outTime:[{}]", paths, startTime, endTime, outTime);
sessionDataSetWrapper = sessionPool.executeRawDataQuery(paths, startTime, endTime, outTime);
return sessionDataSetWrapper.getSessionDataSet();
} catch (Exception e) {
log.error("IotDBSession executeRawDataQuery失败: paths={}, startTime[{}], endTime:[{}],outTime:[{}],error={}", paths, startTime, endTime, outTime, e.getMessage());
} finally {
sessionPool.closeResultSet(sessionDataSetWrapper);
}
return null;
}
/**
*
*
* @param paths root.ln.wf01.wt01.temperature
* @param startTime
* @param endTime
* @param outTime
* @param clazz
* @param <T>
* @return
*/
@Override
public <T> List<T> executeRawDataQuery(List<String> paths, Long startTime, Long endTime, Long outTime, Class<? extends IotDbRecordAble> clazz) {
SessionDataSet sessionDataSet = executeRawDataQuery(paths, startTime, endTime, outTime);
List<String> columnNames = sessionDataSet.getColumnNames();
List<T> resultEntities = null;
try {
resultEntities = packagingObjectData(sessionDataSet, columnNames, clazz);
} catch (Exception e) {
log.error("IotDBSession executeRawDataQuery失败: paths={}, startTime[{}], endTime:[{}],outTime:[{}],error={}", paths, startTime, endTime, outTime, e.getMessage());
}
return resultEntities;
}
/**
* ()
*
* @param paths root.ln.wf01.wt01.temperature
* @param lastTime
* @return SessionDataSet
*/
@Override
public SessionDataSet executeLastDataQuery(List<String> paths, Long lastTime) {
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
SessionDataSetWrapper sessionDataSetWrapper = null;
try {
log.info("iotdb数据查询paths:[{}], lastTime:[{}]", paths, lastTime);
sessionDataSetWrapper = sessionPool.executeLastDataQuery(paths, lastTime);
return sessionDataSetWrapper.getSessionDataSet();
} catch (Exception e) {
log.error("IotDBSession executeLastDataQuery失败: paths={}, lastTime[{}], error={}", paths, lastTime, e.getMessage());
} finally {
sessionPool.closeResultSet(sessionDataSetWrapper);
}
return null;
}
/**
* ()
*
* @param <T>
* @param paths root.ln.wf01.wt01.temperature
* @param lastTime
* @param clazz
* @return
*/
@Override
public <T> List<T> executeLastDataQuery(List<String> paths, Long lastTime, Class<? extends IotDbRecordAble> clazz) {
SessionDataSet sessionDataSet = executeLastDataQuery(paths, lastTime);
List<String> columnNames = sessionDataSet.getColumnNames();
List<T> resultEntities = null;
try {
resultEntities = packagingObjectData(sessionDataSet, columnNames, clazz);
} catch (Exception e) {
log.error("IotDBSession executeLastDataQuery失败: paths={}, lastTime[{}], error={}", paths, lastTime, e.getMessage());
}
return resultEntities;
}
/**
*
*
* @param db root.ln.wf01
* @param device root.ln.wf01.wt01
* @param sensors temperaturestatus()
* @param isLegalPathNodes true()
* @return SessionDataSet
*/
@Override
public SessionDataSet executeLastDataQueryForOneDevice(String db, String device, List<String> sensors, boolean isLegalPathNodes) {
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
SessionDataSetWrapper sessionDataSetWrapper = null;
try {
log.info("iotdb数据查询db:[{}], device:[{}],sensors:[{}], isLegalPathNodes:[{}]", db, device, sensors, isLegalPathNodes);
sessionDataSetWrapper = sessionPool.executeLastDataQueryForOneDevice(db, device, sensors, isLegalPathNodes);
return sessionDataSetWrapper.getSessionDataSet();
} catch (Exception e) {
log.error("IotDBSession executeLastDataQueryForOneDevice失败: db:[{}], device:[{}],sensors:[{}], isLegalPathNodes:[{}], error={}", db, device, sensors, isLegalPathNodes, e.getMessage());
} finally {
sessionPool.closeResultSet(sessionDataSetWrapper);
}
return null;
}
/**
* @param db root.ln.wf01
* @param device root.ln.wf01.wt01
* @param sensors temperaturestatus()
* @param isLegalPathNodes true()
* @param clazz
* @param <T>
* @return
*/
@Override
public <T> List<T> executeLastDataQueryForOneDevice(String db, String device, List<String> sensors, boolean isLegalPathNodes, Class<? extends IotDbRecordAble> clazz) {
SessionDataSet sessionDataSet = executeLastDataQueryForOneDevice(db, device, sensors, isLegalPathNodes);
List<String> columnNames = sessionDataSet.getColumnNames();
List<T> resultEntities = null;
try {
resultEntities = packagingObjectData(sessionDataSet, columnNames, clazz);
} catch (Exception e) {
log.error("IotDBSession executeLastDataQueryForOneDevice失败: db:[{}], device:[{}],sensors:[{}], isLegalPathNodes:[{}], error={}", db, device, sensors, isLegalPathNodes, e.getMessage());
}
return resultEntities;
}
/**
*
*
* @param paths root.ln.wf01.wt01.temperature
* @param aggregations TAggregationType.SUM,TAggregationType.COUNT
* @return SessionDataSet
*/
@Override
public SessionDataSet executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations) {
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
SessionDataSetWrapper sessionDataSetWrapper = null;
try {
log.info("iotdb聚合查询paths:[{}], aggregations[{}]", paths, aggregations);
sessionDataSetWrapper = sessionPool.executeAggregationQuery(paths, aggregations);
return sessionDataSetWrapper.getSessionDataSet();
} catch (Exception e) {
log.error("IotDBSession executeAggregationQuery失败: paths:[{}], aggregations[{}] ,error={}", paths, aggregations, e.getMessage());
} finally {
sessionPool.closeResultSet(sessionDataSetWrapper);
}
return null;
}
/**
* ()
*
* @param paths root.ln.wf01.wt01.temperature
* @param aggregations TAggregationType.SUM,TAggregationType.COUNT
* @param startTime ()
* @param endTime
* @return SessionDataSet
*/
@Override
public SessionDataSet executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations, Long startTime, Long endTime) {
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
SessionDataSetWrapper sessionDataSetWrapper = null;
try {
log.info("iotdb聚合查询paths:[{}], aggregations[{}],startTime[{}], endTime:[{}]", paths, aggregations, startTime, endTime);
sessionDataSetWrapper = sessionPool.executeAggregationQuery(paths, aggregations, startTime, endTime);
return sessionDataSetWrapper.getSessionDataSet();
} catch (Exception e) {
log.error("IotDBSession executeAggregationQuery失败: paths:[{}], aggregations[{}] ,startTime[{}], endTime:[{}],error={}", paths, aggregations, startTime, endTime, e.getMessage());
} finally {
sessionPool.closeResultSet(sessionDataSetWrapper);
}
return null;
}
/**
* ()
*
* @param paths root.ln.wf01.wt01.temperature
* @param aggregations TAggregationType.SUM,TAggregationType.COUNT
* @param startTime ()
* @param endTime
* @param interval
* @return SessionDataSet
*/
@Override
public SessionDataSet executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations, Long startTime, Long endTime, Long interval) {
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
SessionDataSetWrapper sessionDataSetWrapper = null;
try {
log.info("iotdb聚合查询paths:[{}], aggregations[{}],startTime[{}], endTime:[{}] ,interval:[{}]", paths, aggregations, startTime, endTime, interval);
sessionDataSetWrapper = sessionPool.executeAggregationQuery(paths, aggregations, startTime, endTime, interval);
return sessionDataSetWrapper.getSessionDataSet();
} catch (Exception e) {
log.error("IotDBSession executeAggregationQuery失败: paths:[{}], aggregations[{}] ,startTime[{}], endTime:[{}], interval:[{}], error={}", paths, aggregations, startTime, endTime, interval, e.getMessage());
} finally {
sessionPool.closeResultSet(sessionDataSetWrapper);
}
return null;
}
/**
* ()
*
* @param paths root.ln.wf01.wt01.temperature
* @param aggregations TAggregationType.SUM,TAggregationType.COUNT
* @param startTime ()
* @param endTime
* @param interval
* @param slidingStep
* @return SessionDataSet
*/
@Override
public SessionDataSet executeAggregationQuery(List<String> paths, List<TAggregationType> aggregations, Long startTime, Long endTime, Long interval, Long slidingStep) {
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
SessionDataSetWrapper sessionDataSetWrapper = null;
try {
log.info("iotdb聚合查询paths:[{}], aggregations[{}],startTime[{}], endTime:[{}] ,interval:[{}], slidingStep:[{}]", paths, aggregations, startTime, endTime, interval, slidingStep);
sessionDataSetWrapper = sessionPool.executeAggregationQuery(paths, aggregations, startTime, endTime, interval, slidingStep);
return sessionDataSetWrapper.getSessionDataSet();
} catch (Exception e) {
log.error("IotDBSession executeAggregationQuery失败: paths:[{}], aggregations[{}] ,startTime[{}], endTime:[{}], interval:[{}], slidingStep:[{}] ,error={}", paths, aggregations, startTime, endTime, interval, slidingStep, e.getMessage());
} finally {
sessionPool.closeResultSet(sessionDataSetWrapper);
}
return null;
}
/**
* SQL
*
* @param sql
* @return
*/
@Override
public SessionDataSet executeQueryStatement(String sql) {
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
SessionDataSetWrapper sessionDataSetWrapper = null;
try {
log.info("iotdb SQL查询sql:[{}]", sql);
sessionDataSetWrapper = sessionPool.executeQueryStatement(sql);
return sessionDataSetWrapper.getSessionDataSet();
} catch (Exception e) {
log.error("IotDBSession executeQueryStatement失败:sql:[{}],error={}", sql, e.getMessage());
} finally {
sessionPool.closeResultSet(sessionDataSetWrapper);
}
return null;
}
/**
* SQL
*
* @param sql
*/
@Override
public void executeNonQueryStatement(String sql) {
SessionPool sessionPool = iotDBSessionConfig.getSessionPool();
try {
log.info("iotdb SQL无查询sql:[{}]", sql);
sessionPool.executeNonQueryStatement(sql);
} catch (Exception e) {
log.error("IotDBSession executeNonQueryStatement失败:sql:[{}],error={}", sql, e.getMessage());
}
}
/**
*
*
* @param sessionDataSet
* @param titleList
*/
@SneakyThrows
@Override
public List<Map<String, Object>> packagingMapData(SessionDataSet sessionDataSet, List<String> titleList) {
int fetchSize = sessionDataSet.getFetchSize();
List<Map<String, Object>> resultList = new ArrayList<>();
titleList.remove("Time");
if (fetchSize > 0) {
while (sessionDataSet.hasNext()) {
Map<String, Object> resultMap = new HashMap<>();
RowRecord next = sessionDataSet.next();
List<Field> fields = next.getFields();
String timeString = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(next.getTimestamp());
resultMap.put("time", timeString);
for (int i = 0; i < fields.size(); i++) {
Field field = fields.get(i);
if (field.getDataType() == null || field.getObjectValue(field.getDataType()) == null) {
resultMap.put(splitString(titleList.get(i)), null);
} else {
resultMap.put(splitString(titleList.get(i)), field.getObjectValue(field.getDataType()).toString());
}
}
resultList.add(resultMap);
}
}
return resultList;
}
/**
*
*
* @param sessionDataSet
* @param titleList
* @param clazz
* @param <T>
* @return
*/
@SneakyThrows
@Override
public <T> List<T> packagingObjectData(SessionDataSet sessionDataSet, List<String> titleList, Class<? extends IotDbRecordAble> clazz) {
int fetchSize = sessionDataSet.getFetchSize();
List<T> resultList = new ArrayList<>();
titleList.remove("Time");
if (fetchSize > 0) {
while (sessionDataSet.hasNext()) {
Map<String, Object> resultMap = new HashMap<>();
RowRecord next = sessionDataSet.next();
List<Field> fields = next.getFields();
String timeString = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(next.getTimestamp());
resultMap.put("time", timeString);
if (titleList.stream().anyMatch(str -> str.contains("."))) {
for (int i = 0; i < fields.size(); i++) {
Field field = fields.get(i);
String title = titleList.get(i);
if (field.getDataType() == null || field.getObjectValue(field.getDataType()) == null) {
resultMap.put(splitString(title), null);
} else {
resultMap.put(splitString(title), field.getObjectValue(field.getDataType()).toString());
}
}
} else {
Field fieldName = fields.get(0);
Field fieldValue = fields.get(1);
Field fieldDataType = fields.get(2);
if (fieldName.getDataType() != null && fieldName.getObjectValue(fieldName.getDataType()) != null) {
String mapKey = fieldName.getObjectValue(fieldName.getDataType()).toString();
Object mapValue = convertStringToType(fieldValue.getObjectValue(fieldValue.getDataType()).toString(), fieldDataType.getObjectValue(fieldDataType.getDataType()).toString());
resultMap.put(splitString(mapKey), mapValue);
}
}
String jsonString = JSON.toJSONString(resultMap);
resultList.add(JSON.parseObject(jsonString, (Type) clazz));
}
}
return resultList;
}
/**
*
*
* @param str
* @return
*/
public static String splitString(String str) {
String[] parts = str.split("\\.");
if (parts.length <= 0) {
return str;
} else {
return parts[parts.length - 1];
}
}
/**
*
*
* @param value
* @param typeName
* @return
*/
public static Object convertStringToType(String value, String typeName) {
String type = typeName.toLowerCase();
if (type.isEmpty()) {
return value;
}
if ("boolean".equals(type)) {
return Boolean.parseBoolean(value);
} else if ("double".equals(type)) {
return Double.parseDouble(value);
} else if ("int32".equals(type)) {
return Integer.parseInt(value);
} else if ("int64".equals(type)) {
return Long.parseLong(value);
} else if ("float".equals(type)) {
return Float.parseFloat(value);
} else if ("text".equals(type)) {
return value;
} else {
return value;
}
}
/**
* TSDataType
*
* @param type
* @return TSDataType
*/
public static TSDataType getTsDataTypeByString(String type) {
String typeName = splitString(type).toLowerCase();
if ("boolean".equals(typeName)) {
return TSDataType.BOOLEAN;
} else if ("double".equals(typeName)) {
return TSDataType.DOUBLE;
} else if ("int".equals(typeName) || "integer".equals(typeName)) {
return TSDataType.INT32;
} else if ("Long".equals(typeName)) {
return TSDataType.INT64;
} else if ("float".equals(typeName)) {
return TSDataType.FLOAT;
} else if ("text".equals(typeName)) {
return TSDataType.TEXT;
} else if ("string".equals(typeName)) {
return TSDataType.TEXT;
} else {
return TSDataType.UNKNOWN;
}
}
/**
* MeasurementSchemas
*
* @param obj
* @return
*/
@Override
public List<MeasurementSchema> buildMeasurementSchemas(Object obj) {
java.lang.reflect.Field[] fields = obj.getClass().getDeclaredFields();
List<MeasurementSchema> schemaList = Arrays.stream(fields).map(field ->
new MeasurementSchema(field.getName(),
getTsDataTypeByString(
field.getType().getName()
))).
collect(Collectors.toList());
return schemaList;
}
/**
* MeasurementSchemaValuesDTO
*
* @param obj
* @return
*/
@SneakyThrows
@Override
public MeasurementSchemaValuesDTO buildMeasurementSchemasAndValues(Object obj) {
MeasurementSchemaValuesDTO measurementSchemaValuesDTO = new MeasurementSchemaValuesDTO();
java.lang.reflect.Field[] fields = obj.getClass().getDeclaredFields();
List<MeasurementSchema> schemaList = new ArrayList<>();
List<Object> values = new ArrayList<>();
List<Integer> valuesIsNullIndex = new ArrayList<>();
int valueIndex = 0;
for (java.lang.reflect.Field field : fields) {
MeasurementSchema measurementSchema = new MeasurementSchema(field.getName(), getTsDataTypeByString(field.getType().getName()));
schemaList.add(measurementSchema);
Object value = field.get(obj);
if (value == null) {
valuesIsNullIndex.add(valueIndex);
}
values.add(value);
valueIndex++;
}
measurementSchemaValuesDTO.setSchemaList(schemaList);
measurementSchemaValuesDTO.setValues(values);
return measurementSchemaValuesDTO;
}
}

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>cloud-common</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>cloud-common-kafka</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<description>
cloud-common-kafka kafka公共模块
</description>
<dependencies>
<!-- 项目公共核心模块 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-core</artifactId>
</dependency>
<!-- kafka客户端 -->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,102 @@
package com.muyu.common.kafka.config;
import com.muyu.common.core.text.StrFormatter;
import com.muyu.common.kafka.constant.KafkaConfigConstants;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.common.serialization.Deserializer;
import org.apache.kafka.common.serialization.StringDeserializer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
/**
* @Author: wangXin
* @Date 2024/9/28 20:32
* @Description Kafka
*/
@Configuration
public class KafkaConsumerConfig {
/**
* IP
*/
@Value("${kafka.consumer.bootstrap-servers-ip}")
private String bootstrapServersIP;
/**
*
*/
@Value("${kafka.consumer.bootstrap-servers-port}")
private String bootstrapServersPort;
/**
*
*/
@Value("${kafka.consumer.enable-auto-commit}")
private Boolean enableAutoCommit;
/**
*
*/
@Value("${kafka.consumer.auto-commit-interval}")
private Integer autoCommitInterval;
/**
*
*/
@Value("${kafka.consumer.auto-offset-reset}")
private String autoOffsetReset;
/**
*
*/
@Value("${kafka.consumer.fetch-max-wait}")
private Integer fetchMaxWait;
/**
*
*/
@Value("${kafka.consumer.fetch-min-size}")
private Integer fetchMinSize;
/**
*
*/
@Value("${kafka.consumer.heartbeat-interval}")
private Integer heartbeatInterval;
/**
* poll
*/
@Value("${kafka.consumer.max-poll-records}")
private Integer maxPollRecords;
/**
*
*/
@Value("${kafka.consumer.group-id}")
private String groupId;
/**
* Kafka
* @return Kafka
*/
@Bean
public KafkaConsumer<String, String> kafkaConsumer() {
HashMap<String, Object> configs = new HashMap<>();
configs.put(KafkaConfigConstants.BOOTSTRAP_SERVERS,
StrFormatter.format("{}:{}", bootstrapServersIP, bootstrapServersPort));
configs.put(KafkaConfigConstants.ENABLE_AUTO_COMMIT, enableAutoCommit);
configs.put(KafkaConfigConstants.AUTO_COMMIT_INTERVAL, autoCommitInterval);
configs.put(KafkaConfigConstants.AUTO_OFFSET_RESET, autoOffsetReset);
configs.put(KafkaConfigConstants.FETCH_MAX_WAIT, fetchMaxWait);
configs.put(KafkaConfigConstants.FETCH_MIN_SIZE, fetchMinSize);
configs.put(KafkaConfigConstants.HEARTBEAT_INTERVAL, heartbeatInterval);
configs.put(KafkaConfigConstants.MAX_POLL_RECORDS, maxPollRecords);
configs.put(KafkaConfigConstants.GROUP_ID, groupId);
Deserializer<String> keyDeserializer = new StringDeserializer();
Deserializer<String> valueDeserializer = new StringDeserializer();
return new KafkaConsumer<>(configs, keyDeserializer, valueDeserializer);
}
}

View File

@ -0,0 +1,74 @@
package com.muyu.common.kafka.config;
import com.muyu.common.core.text.StrFormatter;
import com.muyu.common.kafka.constant.KafkaConfigConstants;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.common.serialization.Serializer;
import org.apache.kafka.common.serialization.StringSerializer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
/**
* @Author: wangXin
* @Date 2024/9/28 16:35
* @Description Kafka
*/
@Configuration
public class KafkaProducerConfig {
/**
* IP
*/
@Value("${kafka.producer.bootstrap-servers-ip}")
private String bootstrapServersIP;
/**
*
*/
@Value("${kafka.producer.bootstrap-servers-port}")
private String bootstrapServersPort;
/**
*
*/
@Value("${kafka.producer.retries}")
private Integer retries;
/**
*
*/
@Value("${kafka.producer.batch-size}")
private Integer batchSize;
/**
*
*/
@Value("${kafka.producer.buffer-memory}")
private Integer bufferMemory;
/**
*
*/
@Value("${kafka.producer.acks}")
private String acks;
/**
* Kafka
* @return kafka
*/
@Bean
public KafkaProducer<String, String> kafkaProducer() {
HashMap<String, Object> configs = new HashMap<>();
configs.put(KafkaConfigConstants.BOOTSTRAP_SERVERS,
StrFormatter.format("{}:{}", bootstrapServersIP, bootstrapServersPort));
configs.put(KafkaConfigConstants.RETRIES, retries);
configs.put(KafkaConfigConstants.BATCH_SIZE, batchSize);
configs.put(KafkaConfigConstants.BUFFER_MEMORY, bufferMemory);
configs.put(KafkaConfigConstants.ACKS, acks);
Serializer<String> keySerializer = new StringSerializer();
Serializer<String> valueSerializer = new StringSerializer();
return new KafkaProducer<>(configs, keySerializer, valueSerializer);
}
}

View File

@ -0,0 +1,74 @@
package com.muyu.common.kafka.constant;
/**
* @Author: wangXin
* @Date 2024/9/28 20:07
* @Description Kafka
*/
public class KafkaConfigConstants {
/**
* ip+
*/
public static final String BOOTSTRAP_SERVERS = "bootstrap.servers";
/**
*
*/
public static final String RETRIES = "retries";
/**
*
*/
public static final String BATCH_SIZE = "batch.size";
/**
*
*/
public static final String BUFFER_MEMORY = "buffer-memory";
/**
*
*/
public static final String ACKS = "acks";
/**
*
*/
public static final String ENABLE_AUTO_COMMIT = "enable.auto.commit";
/**
*
*/
public static final String AUTO_COMMIT_INTERVAL = "auto.commit.interval";
/**
*
*/
public static final String AUTO_OFFSET_RESET = "auto.offset.reset";
/**
*
*/
public static final String FETCH_MAX_WAIT = "fetch.max.wait";
/**
*
*/
public static final String FETCH_MIN_SIZE = "fetch.min.size";
/**
*
*/
public static final String HEARTBEAT_INTERVAL = "heartbeat-interval";
/**
* poll
*/
public static final String MAX_POLL_RECORDS = "max.poll.records";
/**
*
*/
public static final String GROUP_ID = "group.id";
}

View File

@ -0,0 +1,14 @@
package com.muyu.common.kafka.constant;
/**
* @Author: WangXin
* @date: 2024/7/10
* @Description: kafka
* @Version 1.0.0
*/
public class KafkaConstants {
public final static String KafkaTopic = "kafka_topic";
public final static String KafkaGrop = "kafka_grop";
}

View File

@ -0,0 +1,2 @@
com.muyu.common.kafka.config.KafkaProducerConfig
com.muyu.common.kafka.config.KafkaConsumerConfig

View File

@ -17,6 +17,10 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<description>
cloud-common-rabbit 消息队列服务
</description>
<dependencies>
<!-- rabbitMq 消息队列 -->
@ -28,7 +32,7 @@
<!-- 项目公共核心 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-core</artifactId>
<artifactId>cloud-common-redis</artifactId>
</dependency>
</dependencies>

View File

@ -0,0 +1,48 @@
package com.muyu.common.rabbit.config;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
/**
*
*
*/
@Component
@Log4j2
public class ConfirmCallbackConfig implements RabbitTemplate.ConfirmCallback {
@Autowired
private RabbitTemplate rabbitTemplate;
/**
* @PostContructspringspring
*/
@PostConstruct
public void init() {
rabbitTemplate.setConfirmCallback(this);
}
/**
*
*
* @param correlationData
* @param ack
* @param cause
*/
@Override
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
if (!ack) {
String exchange = correlationData.getReturned().getExchange();
String message = correlationData.getReturned().getMessage().getBody().toString();
// 发送异常
log.error("消息:{},发送到交换机:{}失败,原因是:{}", message, exchange, cause);
// TODO 可以把异常信息 以及 消息的内容直接添加到 MYSQL
}
}
}

View File

@ -1,13 +1,14 @@
package com.muyu.common.rabbit;
package com.muyu.common.rabbit.config;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistrar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.converter.MappingJackson2MessageConverter;
import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory;
import javax.annotation.Resource;
@Configuration
public class RabbitListenerConfigurer implements org.springframework.amqp.rabbit.annotation.RabbitListenerConfigurer {
@ -16,7 +17,7 @@ public class RabbitListenerConfigurer implements org.springframework.amqp.rabbit
}
//以下配置RabbitMQ消息服务
@Autowired
@Resource
public ConnectionFactory connectionFactory;

View File

@ -0,0 +1,41 @@
package com.muyu.common.rabbit.config;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
/**
*
*/
@Component
@Log4j2
public class ReturnCallbackConfig implements RabbitTemplate.ReturnsCallback {
@Autowired
private RabbitTemplate rabbitTemplate;
/**
* @PostContructspringspring
*/
@PostConstruct
public void init() {
rabbitTemplate.setReturnsCallback(this);
}
/**
*
*
* @param returnedMessage the returned message and metadata.
*/
@Override
public void returnedMessage(ReturnedMessage returnedMessage) {
log.error("消息:{},被交换机:{} 回退!退回原因为:{}",
returnedMessage.getMessage().toString(), returnedMessage.getExchange(), returnedMessage.getReplyText());
// TODO 回退了所有的信息,可做补偿机制
}
}

View File

@ -0,0 +1,23 @@
package com.muyu.common.rabbit.constants;
/**
* rabbit
* @Author: WangXin
* @date: 2024/7/10
* @Description: rabbit
* @Version 1.0.0
*/
public interface RabbitConstants {
/**
* 线
*/
String GO_ONLINE_QUEUE= "GoOnline";
/**
* 线
*/
String DOWN_LINE_QUEUE= "DownLine";
/**
*
*/
String ONLINE_EXCHANGE = "online_exchange";
}

View File

@ -1 +1,3 @@
com.muyu.common.rabbit.RabbitListenerConfigurer
com.muyu.common.rabbit.config.RabbitListenerConfigurer
com.muyu.common.rabbit.config.ConfirmCallbackConfig
com.muyu.common.rabbit.config.ReturnCallbackConfig

View File

@ -53,7 +53,7 @@ public class RedisService {
*
* @return true=false=
*/
public boolean expire (final String key, final long timeout) {
public boolean expire (final String key, final Long timeout) {
return expire(key, timeout, TimeUnit.SECONDS);
}
@ -66,7 +66,7 @@ public class RedisService {
*
* @return true=false=
*/
public boolean expire (final String key, final long timeout, final TimeUnit unit) {
public boolean expire (final String key, final Long timeout, final TimeUnit unit) {
return redisTemplate.expire(key, timeout, unit);
}
@ -77,7 +77,7 @@ public class RedisService {
*
* @return
*/
public long getExpire (final String key) {
public Long getExpire (final String key) {
return redisTemplate.getExpire(key);
}
@ -132,7 +132,7 @@ public class RedisService {
*
* @return
*/
public <T> long setCacheList (final String key, final List<T> dataList) {
public <T> Long setCacheList (final String key, final List<T> dataList) {
Long count = redisTemplate.opsForList().rightPushAll(key, dataList);
return count == null ? 0 : count;
}

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>cloud-common</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>cloud-common-saas</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<description>
cloud-common-saas saas公共模块
</description>
<dependencies>
<!-- 多数据源依赖 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-datasource</artifactId>
</dependency>
<!-- 鉴权依赖 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-security</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,107 @@
package com.muyu.cloud.common.many.datasource;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
import com.muyu.cloud.common.many.datasource.domain.model.DataSourceInfo;
import com.muyu.cloud.common.many.datasource.factory.DruidDataSourceFactory;
import com.muyu.cloud.common.many.datasource.role.DynamicDataSource;
import com.muyu.cloud.common.saas.domain.model.EntInfo;
import com.muyu.cloud.common.saas.exception.SaaSException;
import com.muyu.common.core.constant.SecurityConstants;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.SpringUtils;
import com.muyu.common.system.domain.SysFirmDatasource;
import com.muyu.common.system.remote.RemoteUserService;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.*;
/**
* @Author: DongZeLiang
* @date: 2024/6/3
* @Description:
* @Version: 1.0
*/
@Log4j2
@Configuration
@AutoConfiguration(before = MybatisPlusAutoConfiguration.class)
public class ManyDataSource implements ApplicationRunner {
private List<EntInfo> dataSourceInfoList(){
RemoteUserService RemoteUserService = SpringUtils.getBean(RemoteUserService.class);
Result<List<SysFirmDatasource>> listResult = RemoteUserService.selectFirmDatabaseList(SecurityConstants.INNER);
if (listResult==null){
throw new SaaSException("saas远调数据源错误");
}
List<SysFirmDatasource> data = listResult.getData();
if (listResult.getCode() ==Result.SUCCESS && data !=null){
List<EntInfo> list = new ArrayList<>();
for (SysFirmDatasource row : data) {
list.add(
EntInfo.builder()
.entCode(row.getDatabaseName())
.ip(row.getIp())
.port(row.getPort())
.userName(row.getUsername())
.password(row.getPassword())
.build()
);
}
return list;
}else {
log.error("远调数据源错误,远调数据为:{}", JSON.toJSONString(data));
throw new RuntimeException("远调数据源错误,远调--》 firmList ");
}
}
@Bean
public DynamicDataSource dynamicDataSource() {
// 企业列表 企业CODE端口IP
Map<Object, Object> dataSourceMap = new HashMap<>();
dataSourceInfoList()
.stream()
.map(entInfo -> DataSourceInfo.hostAndPortBuild(
entInfo.getEntCode(),
entInfo.getIp(),
entInfo.getPort(),
entInfo.getUserName(),
entInfo.getPassword()))
.map(DruidDataSourceFactory::create)
.filter(Objects::nonNull)
.forEach(druidDataSource -> {
dataSourceMap.put(druidDataSource.getName(), druidDataSource);
});
//设置动态数据源
DynamicDataSource dynamicDataSource = new DynamicDataSource();
// dynamicDataSource.setDefaultTargetDataSource(masterDataSource());
dynamicDataSource.setTargetDataSources(dataSourceMap);
//将数据源信息备份在defineTargetDataSources中
dynamicDataSource.setDefineTargetDataSources(dataSourceMap);
return dynamicDataSource;
}
@Override
public void run(ApplicationArguments args) throws Exception {
DynamicDataSource dynamicDataSource = SpringUtils.getBean(DynamicDataSource.class);
dataSourceInfoList()
.stream()
.map(entInfo -> DataSourceInfo.hostAndPortBuild(
entInfo.getEntCode(),
entInfo.getIp(),
entInfo.getPort(),
entInfo.getUserName(),
entInfo.getPassword()))
.map(DruidDataSourceFactory::create)
.filter(Objects::nonNull)
.forEach(druidDataSource -> {
dynamicDataSource.put(druidDataSource.getName(), druidDataSource);
});
}
}

View File

@ -0,0 +1,12 @@
package com.muyu.cloud.common.many.datasource.constents;
/**
* @author DongZl
* @description:
* @Date 2023-8-1 11:02
*/
public class DatasourceContent {
public final static String DATASOURCE_URL = "jdbc:mysql://{}:{}/{}?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8";
}

View File

@ -0,0 +1,50 @@
package com.muyu.cloud.common.many.datasource.domain.model;
import com.muyu.cloud.common.many.datasource.constents.DatasourceContent;
import com.muyu.common.core.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author DongZl
* @description:
* @Date 2023-8-1 11:15
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DataSourceInfo {
/**
*
*/
private String key;
/**
*
*/
private String url;
/**
*
*/
private String userName;
/**
*
*/
private String password;
public static DataSourceInfo hostAndPortBuild(String key, String host, Integer port,String userName,String password) {
return DataSourceInfo.builder()
.key(key)
.url(StringUtils.format(DatasourceContent.DATASOURCE_URL, host, port, key))
.password(password)
.userName(userName)
.build();
}
}

View File

@ -0,0 +1,40 @@
package com.muyu.cloud.common.many.datasource.factory;
import com.alibaba.druid.pool.DruidDataSource;
import com.muyu.cloud.common.many.datasource.domain.model.DataSourceInfo;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;
import java.sql.SQLException;
/**
* @Author: DongZeLiang
* @date: 2024/6/3
* @Description: Druid
* @Version: 1.0
*/
@Log4j2
@Component
public class DruidDataSourceFactory {
/**
* @Description:
*/
public static DruidDataSource create(DataSourceInfo dataSourceInfo) {
DruidDataSource druidDataSource = new DruidDataSource();
druidDataSource.setName(dataSourceInfo.getKey());
druidDataSource.setUrl(dataSourceInfo.getUrl());
druidDataSource.setUsername(dataSourceInfo.getUserName());
druidDataSource.setPassword(dataSourceInfo.getPassword());
druidDataSource.setBreakAfterAcquireFailure(true);
druidDataSource.setConnectionErrorRetryAttempts(0);
try {
druidDataSource.getConnection(2000);
log.info("{} -> 数据源连接成功", dataSourceInfo.getKey());
return druidDataSource;
} catch (SQLException throwables) {
log.error("数据源 {} 连接失败,用户名:{},密码 {}",dataSourceInfo.getUrl(),dataSourceInfo.getUserName(),dataSourceInfo.getPassword());
return null;
}
}
}

View File

@ -0,0 +1,42 @@
package com.muyu.cloud.common.many.datasource.holder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;
/**
*
*
* @author Dongzl
*/
@Slf4j
public class DynamicDataSourceHolder {
/**
*
*/
private static final ThreadLocal<String> DYNAMIC_DATASOURCE_KEY = new ThreadLocal<>();
/**
* /线使
*/
public static void setDynamicDataSourceKey(String key){
log.info("数据源切换为:{}",key);
DYNAMIC_DATASOURCE_KEY.set(key);
}
/**
* 使mater
*/
public static String getDynamicDataSourceKey(){
String key = DYNAMIC_DATASOURCE_KEY.get();
Assert.notNull(key, "请携带数据标识");
return key;
}
/**
*
*/
public static void removeDynamicDataSourceKey(){
log.info("移除数据源:{}",DYNAMIC_DATASOURCE_KEY.get());
DYNAMIC_DATASOURCE_KEY.remove();
}
}

View File

@ -0,0 +1,55 @@
package com.muyu.cloud.common.many.datasource.role;
import com.alibaba.druid.pool.DruidDataSource;
import com.muyu.cloud.common.many.datasource.holder.DynamicDataSourceHolder;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
import java.util.Map;
/**
*
* AddDefineDataSourceaddDefineDynamicDataSourcetargetdatasourcesmapmaptargetdatasourcesmap
* 使@DataSource(value = "数据源名称")DynamicDataSourceContextHolder.setContextKey("数据源名称")
* @author Dongzl
*/
@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DynamicDataSource extends AbstractRoutingDataSource {
/**
*
*/
private Map<Object, Object> defineTargetDataSources;
/**
*
* @param key
* @return true false
*/
public boolean hashKey(String key){
return defineTargetDataSources.containsKey(key);
}
/**
*
* @param key
* @param value
*/
public void put(String key, DruidDataSource value) {
defineTargetDataSources.put(key, value);
this.afterPropertiesSet();
}
/**
* 线使
*/
@Override
protected Object determineCurrentLookupKey() {
return DynamicDataSourceHolder.getDynamicDataSourceKey();
}
}

View File

@ -0,0 +1,12 @@
package com.muyu.cloud.common.saas.contents;
/**
* @Author: DongZeLiang
* @date: 2024/6/3
* @Description: SAAS
* @Version: 1.0
*/
public class SaaSConstant {
public final static String SAAS_KEY = "ent-code";
}

View File

@ -0,0 +1,29 @@
package com.muyu.cloud.common.saas.domain.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author: DongZeLiang
* @date: 2024/6/3
* @Description:
* @Version: 1.0
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class EntInfo {
private String entCode;
private String ip;
private Integer port;
private String userName;
private String password;
}

View File

@ -0,0 +1,28 @@
package com.muyu.cloud.common.saas.exception;
import com.muyu.common.core.exception.ServiceException;
/**
* @Author: DongZeLiang
* @date: 2024/6/3
* @Description: SaaS
* @Version: 1.0
*/
public class SaaSException extends ServiceException {
public SaaSException (String message, Integer code) {
super(message, code);
}
public SaaSException (String message) {
super(message);
}
/**
*
*/
public SaaSException () {
super();
}
}

View File

@ -0,0 +1,67 @@
package com.muyu.cloud.common.saas.interceptor;
import com.alibaba.fastjson2.JSONObject;
import com.muyu.cloud.common.saas.contents.SaaSConstant;
import com.muyu.cloud.common.many.datasource.holder.DynamicDataSourceHolder;
import com.muyu.cloud.common.saas.exception.SaaSException;
import com.muyu.cloud.common.many.datasource.role.DynamicDataSource;
import com.muyu.common.core.constant.SecurityConstants;
import com.muyu.common.core.utils.ServletUtils;
import com.muyu.common.core.utils.SpringUtils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.AsyncHandlerInterceptor;
/**
* @Author: DongZeLiang
* @date: 2024/6/3
* @Description: SAAS
* @Version: 1.0
*/
@Log4j2
public class SaaSInterceptor implements AsyncHandlerInterceptor {
private Boolean flag = false;
/**
*
*/
@Override
public boolean preHandle (HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (!(handler instanceof HandlerMethod)) {
return true;
}
String SaaSKey = ServletUtils.getHeader(request, SecurityConstants.FIRM_KEY);
if (SaaSKey == null) {
throw new SaaSException("SaaS非法访问");
}
if (SaaSKey.equals("1")){
log.info("使用 [ nacos ] 配置数据库 ");
flag = true;
return true;
}
DynamicDataSource dynamicDataSource = SpringUtils.getBean(DynamicDataSource.class);
if (!dynamicDataSource.hashKey(SaaSKey)){
throw new SaaSException("SaaS非法访问");
}
DynamicDataSourceHolder.setDynamicDataSourceKey(SaaSKey);
return true;
}
/**
*
*/
@Override
public void afterConcurrentHandlingStarted (HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
if (flag){
DynamicDataSourceHolder.removeDynamicDataSourceKey();
flag = false;
}
}
}

View File

@ -0,0 +1,31 @@
package com.muyu.cloud.common.saas.interceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
*
*
* @author muyu
*/
public class WebMvcSaaSConfig implements WebMvcConfigurer {
/**
*
*/
public static final String[] excludeUrls = {"/login", "/logout", "/refresh"};
@Override
public void addInterceptors (InterceptorRegistry registry) {
registry.addInterceptor(getHeaderInterceptor())
.addPathPatterns("/**")
.excludePathPatterns(excludeUrls)
.order(-10);
}
/**
*
*/
public SaaSInterceptor getHeaderInterceptor () {
return new SaaSInterceptor();
}
}

View File

@ -0,0 +1,3 @@
com.muyu.cloud.common.saas.interceptor.WebMvcSaaSConfig
com.muyu.cloud.common.many.datasource.ManyDataSource
com.muyu.cloud.common.many.datasource.factory.DruidDataSourceFactory

View File

@ -27,11 +27,11 @@ import java.util.concurrent.TimeUnit;
*/
@Component
public class TokenService {
protected static final long MILLIS_SECOND = 1000;
protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND;
protected static final Long MILLIS_SECOND = 1000L;
protected static final Long MILLIS_MINUTE = 60 * MILLIS_SECOND;
private final static Long MILLIS_MINUTE_TEN = CacheConstants.REFRESH_TIME * MILLIS_MINUTE;
private static final Logger log = LoggerFactory.getLogger(TokenService.class);
private final static long expireTime = CacheConstants.EXPIRATION;
private final static Long expireTime = CacheConstants.EXPIRATION;
private final static String ACCESS_TOKEN = CacheConstants.LOGIN_TOKEN_KEY;
@Autowired
@ -43,6 +43,7 @@ public class TokenService {
public Map<String, Object> createToken (LoginUser loginUser) {
String token = IdUtils.fastUUID();
Long userId = loginUser.getSysUser().getUserId();
Long firmId = loginUser.getSysUser().getFirmId();
String userName = loginUser.getSysUser().getUserName();
loginUser.setToken(token);
loginUser.setUserid(userId);
@ -55,7 +56,8 @@ public class TokenService {
claimsMap.put(SecurityConstants.USER_KEY, token);
claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId);
claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName);
claimsMap.put(SecurityConstants.FIRM_KEY, loginUser.getSysUser().getDatabaseName());
claimsMap.put(SecurityConstants.FIRM_ID, loginUser.getSysUser().getFirmId());
// 接口返回信息
Map<String, Object> rspMap = new HashMap<String, Object>();
rspMap.put("access_token", JwtUtils.createToken(claimsMap));
@ -127,8 +129,8 @@ public class TokenService {
* @param loginUser
*/
public void verifyToken (LoginUser loginUser) {
long expireTime = loginUser.getExpireTime();
long currentTime = System.currentTimeMillis();
Long expireTime = loginUser.getExpireTime();
Long currentTime = System.currentTimeMillis();
if (expireTime - currentTime <= MILLIS_MINUTE_TEN) {
refreshToken(loginUser);
}

View File

@ -25,5 +25,9 @@
<groupId>com.muyu</groupId>
<artifactId>cloud-common-core</artifactId>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations-jakarta</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -16,7 +16,7 @@ import java.util.Set;
@NoArgsConstructor
@AllArgsConstructor
public class LoginUser implements Serializable {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
/**
*

View File

@ -22,7 +22,7 @@ import java.util.List;
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class SysDept extends BaseEntity {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
/**
* ID
@ -79,6 +79,11 @@ public class SysDept extends BaseEntity {
*/
private String parentName;
/**
* Id
*/
private Long firmId;
/**
*
*/

View File

@ -21,7 +21,7 @@ import jakarta.validation.constraints.Size;
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class SysDictData extends BaseEntity {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
/**
*

View File

@ -21,7 +21,7 @@ import jakarta.validation.constraints.Size;
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class SysDictType extends BaseEntity {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
/**
*

View File

@ -0,0 +1,60 @@
package com.muyu.common.system.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
*
*
* @Author WangXin
* @Data 2024/10/9
* @Version 1.0.0
*/
@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@Tag(name = "公司信息")
@TableName("sys_firm")
public class SysFirm {
/**
* Id
*/
@TableId(type = IdType.AUTO)
@Schema(name = "公司Id")
private Long id;
/**
*
*/
@Schema(name = "公司名称")
private String name;
/**
*
*/
@Schema(name = "公司数据源")
private Long did;
/**
* logo
*/
@Schema(name = "公司logo")
private String logo;
/**
*
*/
@Schema(name = "唯一标识")
private String sole;
/**
*
*/
@Schema(name = "车辆状态")
private String status;
}

View File

@ -0,0 +1,64 @@
package com.muyu.common.system.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* @Author WangXin
* @Data 2024/10/2
* @Description
* @Version 1.0.0
*/
@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@Tag(name = "数据源信息")
@TableName("sys_firm_datasource")
public class SysFirmDatasource {
/**
* Id
*/
@Schema(name = "数据源Id")
@TableId(type = IdType.AUTO)
private Long id;
/**
* url
*/
@Schema(name = "数据源url")
private String datasourceUrl;
/**
*
*/
@Schema(name = "数据源用户名")
private String username;
/**
*
*/
@Schema(name = "数据源密码")
private String password;
/**
* IP
*/
@Schema(name = "数据源IP")
private String ip;
/**
*
*/
@Schema(name = "数据源端口号")
private Integer port;
/**
*
*/
@Schema(name = "数据源库名")
private String databaseName;
}

View File

@ -23,7 +23,7 @@ import java.util.Date;
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class SysLogininfor extends BaseEntity {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
/**
* ID

View File

@ -23,7 +23,7 @@ import java.util.Date;
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class SysOperLog extends BaseEntity {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
/**
*

View File

@ -22,7 +22,7 @@ import java.util.Set;
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class SysRole extends BaseEntity {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
/**
* ID

View File

@ -29,7 +29,7 @@ import java.util.List;
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class SysUser extends BaseEntity {
private static final long serialVersionUID = 1L;
private static final Long serialVersionUID = 1L;
/**
* ID
@ -134,6 +134,15 @@ public class SysUser extends BaseEntity {
* ID
*/
private Long roleId;
/**
* Id
*/
private Long firmId;
/**
*
*/
private String databaseName;
public SysUser (Long userId) {
this.userId = userId;

View File

@ -0,0 +1,36 @@
package com.muyu.common.system.domain.resp;
import com.muyu.common.system.domain.SysFirm;
import com.muyu.common.system.domain.SysFirmDatasource;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
*
*
* @Author WangXin
* @Data 2024/10/9
* @Version 1.0.0
*/
@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@Tag(name = "公司信息响应对象")
public class SysFirmResp {
/**
*
*/
@Schema(name = "公司信息")
private SysFirm firm;
/**
*
*/
@Schema(name = "公司数据源信息")
private SysFirmDatasource firmDatasource;
}

Some files were not shown because too many files have changed in this diff Show More