Compare commits

..

124 Commits

Author SHA1 Message Date
袁子龙 24b8fe4085 Merge remote-tracking branch 'origin/dev.business' into dev
# Conflicts:
#	cloud-modules/saas/saas-server/src/main/java/com/muyu/server/controller/EnterpriseController.java
#	cloud-modules/saas/saas-server/src/main/java/com/muyu/server/service/impl/EnterpriseServiceImpl.java
2024-10-10 22:25:22 +08:00
袁子龙 13a67257fc Merge branch 'dev' of https://gitea.qinmian.online/group-four/cloud-car into dev 2024-10-10 22:24:42 +08:00
袁子龙 b04f697547 text:()修改企业入入驻 2024-10-10 22:24:30 +08:00
袁子龙 585656aa46 text:()修改企业入入驻 2024-10-10 22:24:27 +08:00
袁子龙 55ed020ac7 test:()去除无用的对象 2024-10-10 22:24:21 +08:00
袁子龙 cedad4d7b9 test:()去除重复的企业对象 2024-10-10 22:24:21 +08:00
袁子龙 c8f912393d test:()修改企业对象 2024-10-10 22:24:21 +08:00
袁子龙 0be030416f test:()修改故障 2024-10-10 22:24:21 +08:00
袁子龙 40fccdbc56 test:()修改企业添加 2024-10-10 22:24:18 +08:00
袁子龙 b8a7658ce5 text:()修改企业入入驻 2024-10-10 22:21:48 +08:00
袁子龙 a8cdd55797 text:()修改企业入入驻 2024-10-10 22:21:06 +08:00
Number7 1960d9dd90 Merge remote-tracking branch 'refs/remotes/origin/dev.template' into dev 2024-10-10 19:54:59 +08:00
Number7 2308d974be fix():数据预警编写修改 2024-10-10 19:53:34 +08:00
SuiXxx b26bb59183 Merge branch 'dev' of https://gitea.qinmian.online/group-four/cloud-car into dev 2024-10-10 19:52:57 +08:00
SuiXxx 1a62dd6f96 feat():轮询 2024-10-10 17:20:16 +08:00
袁子龙 6779e2120e text:()修改企业入入驻 2024-10-10 14:01:21 +08:00
袁子龙 b9ce76ca15 text:()修改企业入入驻 2024-10-10 11:45:55 +08:00
Number7 2e940349ef Merge remote-tracking branch 'refs/remotes/origin/dev.template' into dev
# Conflicts:
#	cloud-auth/src/main/resources/bootstrap.yml
#	cloud-gateway/src/main/resources/bootstrap.yml
#	cloud-modules/cloud-event/src/main/java/com/muyu/event/consumer/MessageConsumer.java
#	cloud-modules/cloud-modules-system/src/main/resources/bootstrap.yml
#	cloud-modules/cloud-modules-vehiclegateway/src/main/resources/bootstrap.yml
#	cloud-modules/saas/saas-server/src/main/java/com/muyu/server/SaasApplication.java
#	cloud-modules/saas/saas-server/src/main/resources/bootstrap.yml
2024-10-10 09:28:44 +08:00
Number7 cf286d48f9 feat():新增数据预警 2024-10-10 09:26:52 +08:00
袁子龙 ec57579533 test:()去除无用的对象 2024-10-09 17:18:04 +08:00
袁子龙 4cbfb65109 test:()去除重复的企业对象 2024-10-09 17:16:17 +08:00
袁子龙 acd7ad9fb4 test:()修改企业对象 2024-10-09 17:13:08 +08:00
袁子龙 b266460a0a test:()修改故障 2024-10-09 17:08:19 +08:00
袁子龙 d7fa72be80 Merge remote-tracking branch 'origin/dev' into dev.business
# Conflicts:
#	cloud-modules/saas/saas-server/src/main/java/com/muyu/server/controller/EnterpriseController.java
#	cloud-modules/saas/saas-server/src/main/resources/bootstrap.yml
2024-10-09 16:50:46 +08:00
Number7 88fdcfcbab Merge remote-tracking branch 'refs/remotes/origin/dev.template' into dev 2024-10-08 20:02:50 +08:00
Number7 79f9309c0f fix():完善数据预警方法 2024-10-08 20:02:00 +08:00
Number7 0aa33b36a0 Merge remote-tracking branch 'refs/remotes/origin/dev.template' into dev 2024-10-08 17:12:00 +08:00
Number7 d5d17321ff fix():修复协议解析 2024-10-08 17:11:03 +08:00
Number7 6e5e07af85 Merge remote-tracking branch 'origin/dev' into dev 2024-10-08 11:56:49 +08:00
Number7 d0e51b14b1 Merge remote-tracking branch 'refs/remotes/origin/dev.template' into dev 2024-10-08 11:56:30 +08:00
Number7 4548e2c781 fix():删除冗余代码 2024-10-08 11:55:04 +08:00
袁子龙 59c16de298 test:()修改企业入驻 2024-10-08 11:46:04 +08:00
袁子龙 efa6861d2f test:()修改企业添加 2024-10-08 11:31:17 +08:00
刘武 0ebf046e25 fix(): 代码合并 2024-10-08 10:05:09 +08:00
袁子龙 2773a13270 test:()修改企业添加 2024-10-08 09:15:15 +08:00
刘武 2a0bd1178e Merge remote-tracking branch 'origin/dev.vehiclegateway' into dev 2024-10-08 09:03:44 +08:00
刘武 97994a0452 fix(): 代码合并 2024-10-07 22:38:09 +08:00
SuiXxx cd5e46b650 feat():项目启动创建交换机 2024-10-07 21:51:04 +08:00
SuiXxx f6baa83c94 Merge remote-tracking branch 'origin/dev' into dev.vehiclegateway 2024-10-07 21:39:34 +08:00
SuiXxx 2235097f05 feat():账号密码存入数据库 2024-10-07 21:39:01 +08:00
刘武 9e94cf5674 Merge branch 'dev' of https://gitea.qinmian.online/group-four/cloud-car into dev 2024-10-07 21:35:45 +08:00
刘武 ca505dc2c4 fix(): 代码合并 2024-10-07 21:35:30 +08:00
刘武 c90845d508 Merge remote-tracking branch 'origin/dev.event' into dev
# Conflicts:
#	cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/producer/RabbitMQProducerUtil.java
#	cloud-common/cloud-common-rabbit/src/main/java/com/muyu/rabbitmq/consumer/RabbitMQConsumerUtil.java
#	cloud-modules/saas/saas-server/src/main/java/com/muyu/server/controller/TemplateController.java
2024-10-07 21:31:48 +08:00
刘武 c1f24c8d03 Merge remote-tracking branch 'origin/dev.business' into dev
# Conflicts:
#	cloud-common/cloud-common-kafka/pom.xml
#	cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/config/MqttConfigure.java
#	cloud-modules/saas/saas-server/src/main/java/com/muyu/server/controller/SysCarController.java
2024-10-07 20:52:29 +08:00
刘武 f45e6865d9 Merge remote-tracking branch 'origin/dev.template' into dev 2024-10-07 20:39:38 +08:00
袁子龙 abf186e99c test:()修改企业添加 2024-10-07 19:41:03 +08:00
Number7 2186c58122 Merge remote-tracking branch 'refs/remotes/origin/dev.template' into dev 2024-10-07 14:31:00 +08:00
Number7 b395a24329 fix():优化协议解析中的集合遍历方法 2024-10-07 14:30:30 +08:00
Number7 e2897c4bb7 Merge remote-tracking branch 'origin/dev' into dev 2024-10-07 14:09:36 +08:00
Number7 c539a55f1e fix():将协议解析中的取值换成Redis缓存 2024-10-07 14:07:32 +08:00
刘武 9499d9738e fix(): 事件基础 2024-10-07 12:06:18 +08:00
袁子龙 ae7294da6f fix:()修改为Mybatis-Plus方法 2024-10-06 20:39:40 +08:00
袁子龙 fe3ce0e291 fix:()修改为Mybatis-Plus方法 2024-10-06 20:34:13 +08:00
袁子龙 bd0214ccd9 fix:()修改为Mybatis-Plus方法 2024-10-06 20:32:33 +08:00
SuiXxx d01a3d5ce1 Merge branch 'dev' of https://gitea.qinmian.online/group-four/cloud-car into dev
# Conflicts:
#	cloud-modules/cloud-modules-vehiclegateway/src/main/resources/bootstrap.yml
2024-10-06 20:10:17 +08:00
SuiXxx 705414778c feat():账号密码存入数据库 2024-10-06 20:04:08 +08:00
袁子龙 dd319599b6 fix:()补全swagger接口文档 2024-10-06 16:20:17 +08:00
袁子龙 875391757f fix:()补全swagger接口文档 2024-10-06 16:17:34 +08:00
袁子龙 b9c4334cb5 style:()删除无用的测试类 2024-10-06 14:35:47 +08:00
刘武 87d104cf9b fix(): 事件基础修改 2024-10-06 10:39:59 +08:00
袁子龙 a63bde6c84 fix:()kafka读取不到的问题 2024-10-06 10:09:48 +08:00
袁子龙 c5f0d52aa6 fix:()修复方法引入但未依赖的问题 2024-10-06 09:11:41 +08:00
袁子龙 e2fc097b14 test():企业入驻时创库创表修改 2024-10-04 20:59:21 +08:00
Number7 30782882c3 Merge remote-tracking branch 'refs/remotes/origin/dev.template' into dev 2024-10-04 16:58:38 +08:00
Number7 8c90364eaa feat():修改协议解析方法 2024-10-04 16:57:45 +08:00
袁子龙 dc26138929 Merge remote-tracking branch 'origin/dev.business' into dev 2024-10-04 16:55:24 +08:00
袁子龙 4399609c9e test():企业入驻时创库创表修改 2024-10-04 16:54:37 +08:00
袁子龙 a769d4da40 text:企业用户修改加入表的创建 2024-10-04 09:31:04 +08:00
Number7 a3613176f3 Merge remote-tracking branch 'refs/remotes/origin/dev.template' into dev 2024-10-02 16:49:07 +08:00
Number7 d82ae07d37 feat():删除车辆管理中不必要的注入 2024-10-02 16:48:33 +08:00
86191 89825669dc Merge remote-tracking branch 'origin/dev.operation' into dev 2024-10-02 16:44:44 +08:00
86191 f56a0e8b7f fix():把saas缓存对象换成缓存列表 2024-10-02 16:44:00 +08:00
Number7 9846c72b3b Merge remote-tracking branch 'refs/remotes/origin/dev.template' into dev 2024-10-02 16:39:56 +08:00
Number7 53ff3d70c9 fix():完善kafka的报错 2024-10-02 16:38:11 +08:00
袁子龙 709878fbab Merge branch 'dev.business' into dev 2024-10-02 16:33:16 +08:00
86191 6dd3d73f62 fix():把saas缓存对象换成缓存列表 2024-10-02 16:23:41 +08:00
86191 2623669eb0 fix():把saas缓存对象换成缓存列表 2024-10-02 16:22:39 +08:00
86191 3a8b35b710 fix():把saas缓存对象换成缓存列表 2024-10-02 16:21:58 +08:00
袁子龙 cb8867d0ee chore:修改企业管理字段 2024-10-02 15:14:50 +08:00
袁子龙 ba8009fd8d chore:修改企业管理字段 2024-10-02 14:49:25 +08:00
袁子龙 954a8939c6 feat:新增企业管理添加 2024-10-02 14:39:19 +08:00
袁子龙 3393804735 fix:修复企业入驻接口调用失败问题 2024-10-02 14:12:47 +08:00
Number7 59050208a0 Merge remote-tracking branch 'refs/remotes/origin/dev.template' into dev 2024-10-02 11:03:52 +08:00
Number7 008efdde25 fix():修改协议解析方法 2024-10-02 11:03:21 +08:00
86191 217af96abc feat():缓存各个模块对象 2024-10-02 10:57:46 +08:00
86191 b5a2687491 Merge remote-tracking branch 'origin/dev.operation' into dev
# Conflicts:
#	cloud-auth/src/main/resources/bootstrap.yml
#	cloud-gateway/src/main/resources/bootstrap.yml
#	cloud-modules/cloud-event/src/main/resources/bootstrap.yml
#	cloud-modules/cloud-modules-file/src/main/resources/bootstrap.yml
#	cloud-modules/cloud-modules-gen/src/main/resources/bootstrap.yml
#	cloud-modules/cloud-modules-system/src/main/resources/bootstrap.yml
#	cloud-modules/saas/saas-server/src/main/java/com/muyu/server/service/impl/SysCarServiceImpl.java
#	cloud-modules/saas/saas-server/src/main/java/com/muyu/server/service/impl/TemplateServiceImpl.java
#	cloud-modules/saas/saas-server/src/main/resources/bootstrap.yml
2024-10-02 10:35:35 +08:00
86191 370a91773e feat():缓存各个模块对象 2024-10-02 10:33:14 +08:00
袁子龙 5589803de6 feat:新增企业入驻新增数据库 2024-10-02 10:29:40 +08:00
Number7 708214b86e Merge remote-tracking branch 'refs/remotes/origin/dev.template' into dev 2024-10-02 10:05:02 +08:00
Number7 c79a39f54e fix():修改协议解析方法 2024-10-02 10:03:36 +08:00
86191 476d6ae0b7 feat():围栏和故障的缓存 2024-09-30 18:45:08 +08:00
袁子龙 4adb06459e feat:新增kafka模块依赖 2024-09-30 18:09:05 +08:00
Number7 a13ba8199a fix():修改协议解析方法 2024-09-30 17:00:05 +08:00
袁子龙 fe90a341ff Merge remote-tracking branch 'origin/dev.business' into dev 2024-09-30 16:48:27 +08:00
袁子龙 d99edc16d1 feat:新增企业入驻 2024-09-30 16:47:31 +08:00
袁子龙 50a655d888 feat:新增企业入驻 2024-09-30 16:46:34 +08:00
Number7 e8bc92c658 Merge remote-tracking branch 'refs/remotes/origin/dev.template' into dev 2024-09-30 16:38:01 +08:00
Number7 76440e1c98 feat():增加协议解析模块 2024-09-30 16:37:24 +08:00
袁子龙 b879a1768d feat:新增企业入驻 2024-09-30 16:36:35 +08:00
刘武 370fdd9fd5 Merge branch 'dev' of https://gitea.qinmian.online/group-four/cloud-car into dev
# Conflicts:
#	cloud-common/pom.xml
2024-09-30 16:35:35 +08:00
刘武 f46db057b5 fix(): 事件基础修改,kafka注入 2024-09-30 16:34:37 +08:00
Number7 82ec79ccaf fix():修改报文基础类型方法 2024-09-30 15:47:20 +08:00
Number7 551f5f5496 Merge remote-tracking branch 'refs/remotes/origin/dev.template' into dev
# Conflicts:
#	cloud-modules/saas/saas-server/src/main/java/com/muyu/server/service/impl/TemplateServiceImpl.java
2024-09-30 15:28:30 +08:00
Number7 8e0e492555 fix():修改报文基础类型方法 2024-09-30 15:27:28 +08:00
Number7 6545fc79ef feat():增加添加报文模版功能 2024-09-30 14:40:07 +08:00
袁子龙 78747b7d03 feat:新增企业入驻接口 2024-09-30 12:23:56 +08:00
袁子龙 d6ff8ad340 feat:新增企业入驻服务校验 2024-09-30 12:19:21 +08:00
袁子龙 8bc54f4662 feat:新增企业对象 2024-09-30 12:12:52 +08:00
袁子龙 e6639bc7f9 feat:新增长度限制 2024-09-30 11:37:41 +08:00
袁子龙 a0ddc45e67 feat:企业入驻 2024-09-30 11:31:52 +08:00
袁子龙 051fe490d6 feat:企业入驻 2024-09-30 11:31:41 +08:00
袁子龙 31df6d32db feat:企业入驻 2024-09-30 11:31:07 +08:00
袁子龙 798f509dec feat:企业登录 2024-09-30 11:17:20 +08:00
袁子龙 f93af8b4a6 Merge remote-tracking branch 'origin/dev.business' into dev
# Conflicts:
#	cloud-modules/saas/saas-common/src/main/java/com/muyu/common/domain/CarType.java
#	cloud-modules/saas/saas-common/src/main/java/com/muyu/common/domain/DataType.java
#	cloud-modules/saas/saas-common/src/main/java/com/muyu/common/domain/MessageTemplate.java
#	cloud-modules/saas/saas-common/src/main/java/com/muyu/common/domain/MessageTemplateType.java
#	cloud-modules/saas/saas-common/src/main/java/com/muyu/common/domain/SysCar.java
#	cloud-modules/saas/saas-common/src/main/java/com/muyu/common/domain/SysCarLog.java
#	cloud-modules/saas/saas-common/src/main/java/com/muyu/common/domain/Template.java
#	cloud-modules/saas/saas-server/src/main/java/com/muyu/server/config/MqttConfigure.java
#	cloud-modules/saas/saas-server/src/main/java/com/muyu/server/service/impl/SysCarServiceImpl.java
2024-09-30 11:00:49 +08:00
袁子龙 1272d0e0b7 refactor:修改注释 2024-09-30 10:59:09 +08:00
86191 7149ea8f1c Merge remote-tracking branch 'origin/dev' into dev.operation 2024-09-30 10:32:54 +08:00
Number7 1f072d4ca2 fix():修改报文接口字段问题 2024-09-30 10:29:58 +08:00
86191 a6521e46c9 feat():围栏和故障的缓存 2024-09-30 09:26:57 +08:00
刘武 cc99d65102 fix(): 事件基础修改,kafka注入 2024-09-30 09:17:02 +08:00
袁子龙 29cb1ffadb refactor:修改注释 2024-09-29 22:03:51 +08:00
袁子龙 2488248967 refactor:修改注释 2024-09-29 16:12:34 +08:00
袁子龙 dea0f07c90 refactor:修改注释 2024-09-29 16:03:17 +08:00
袁子龙 688154709d refactor:修改注释 2024-09-29 14:51:02 +08:00
袁子龙 3f9a930c95 refactor:修改yml的nacos命名空间 2024-09-29 12:28:21 +08:00
244 changed files with 5345 additions and 1831 deletions

View File

@ -16,6 +16,13 @@
<dependencies>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.5</version>
</dependency>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
@ -34,6 +41,8 @@
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- SpringBoot Web -->
<dependency>
<groupId>org.springframework.boot</groupId>
@ -57,6 +66,19 @@
<groupId>com.muyu</groupId>
<artifactId>cloud-common-api-doc</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-saas</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
</dependency>
</dependencies>

View File

@ -1,8 +1,13 @@
package com.muyu.auth.controller;
import com.muyu.auth.form.EnterpriseSettlement;
import com.muyu.auth.form.Firm;
import com.muyu.auth.form.LoginBody;
import com.muyu.auth.form.RegisterBody;
import com.muyu.auth.service.SysFirmService;
import com.muyu.auth.service.SysLoginService;
import com.muyu.cloud.common.many.datasource.constents.DatasourceContent;
import com.muyu.common.core.constant.SecurityConstants;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.JwtUtils;
import com.muyu.common.core.utils.StringUtils;
@ -10,7 +15,15 @@ import com.muyu.common.security.auth.AuthUtil;
import com.muyu.common.security.service.TokenService;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.common.system.domain.SysUser;
import com.muyu.common.system.remote.RemoteUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.jdbc.datasource.init.ScriptUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -18,12 +31,20 @@ import org.springframework.web.bind.annotation.RestController;
import jakarta.servlet.http.HttpServletRequest;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
/**
* token
*
* @author muyu
*/
@Log4j2
@RestController
@Tag(name = "auth",description = "auth")
public class TokenController {
@Autowired
private TokenService tokenService;
@ -31,8 +52,20 @@ public class TokenController {
@Autowired
private SysLoginService sysLoginService;
@Autowired
private SysFirmService sysFirmService;
@Autowired
private RemoteUserService remoteUserService;
@PostMapping("login")
@Operation(summary = "登录", description = "登录")
public Result<?> login (@RequestBody LoginBody form) {
//查询企业是否存在
Firm firm = sysFirmService.findFirmByName(form.getFirmName());
if (firm.getDatabaseName() == null){
return Result.error(null,"企业不存在");
}
// 用户登录
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword());
// 获取登录token
@ -40,6 +73,7 @@ public class TokenController {
}
@DeleteMapping("logout")
@Operation(summary = "退出", description = "退出")
public Result<?> logout (HttpServletRequest request) {
String token = SecurityUtils.getToken(request);
if (StringUtils.isNotEmpty(token)) {
@ -53,6 +87,7 @@ public class TokenController {
}
@PostMapping("refresh")
@Operation(summary = "刷新token", description = "刷新token")
public Result<?> refresh (HttpServletRequest request) {
LoginUser loginUser = tokenService.getLoginUser(request);
if (StringUtils.isNotNull(loginUser)) {
@ -64,9 +99,65 @@ public class TokenController {
}
@PostMapping("register")
@Operation(summary = "注册用户", description = "注册用户")
public Result<?> register (@RequestBody RegisterBody registerBody) {
// 用户注册
sysLoginService.register(registerBody.getUsername(), registerBody.getPassword());
return Result.success();
}
/**
*
* @param settlement
* @return
*/
@PostMapping("/enterprise")
@Operation(summary = "企业入驻", description = "企业入驻")
public Result<?> enterprise( @RequestBody EnterpriseSettlement settlement){
String createDatabaseUrl="jdbc:mysql://"+ DatasourceContent.IP+":"+DatasourceContent.PORT+"?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8";
String createDatabaseSql = "CREATE DATABASE IF NOT EXISTS " + settlement.getDatabaseName() + ";";
try (Connection adminConn = DriverManager.getConnection(createDatabaseUrl, DatasourceContent.USER_NAME, DatasourceContent.PASSWORD);
Statement stmt = adminConn.createStatement()) {
boolean success = stmt.execute(createDatabaseSql);
if (success) {
log.info("数据库 {} 创建失败", settlement.getDatabaseName());
} else {
log.warn("数据库 {} 创建成功", settlement.getDatabaseName());
SysUser sysUser = new SysUser();
sysUser.setCreateTime(new Date());
sysUser.setUserName(settlement.getFirmName());
sysUser.setDatabaseName(settlement.getDatabaseName());
remoteUserService.addUser(sysUser, SecurityConstants.INNER);
// 切换到新的数据库连接
Connection connection = null;
try {
String url = "jdbc:mysql://47.101.53.251:3306/" + settlement.getDatabaseName() + "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8";
String user = "root";
String pwd = "Lw030106";
String driverClassName = "com.mysql.cj.jdbc.Driver";
Class.forName(driverClassName);
connection = DriverManager.getConnection(url, user, pwd);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
ClassPathResource rc = new ClassPathResource("init-file/saas.sql");
EncodedResource er = new EncodedResource(rc, "utf-8");
ScriptUtils.executeSqlScript(connection, er);
}
} catch (SQLException e) {
e.printStackTrace();
log.error("连接数据库时发生错误或创建数据库失败", e);
}
//企业入驻
sysLoginService.enterprise(settlement.getDatabaseName(),settlement.getFirmName());
return Result.success();
}
}

View File

@ -0,0 +1,23 @@
package com.muyu.auth.form;
import lombok.Data;
/**
*
* @author
* @package com.muyu.auth.form
* @name EnterpriseSettlement
* @date 2024/9/30 11:25
*/
@Data
public class EnterpriseSettlement {
/**
*
*/
private String firmName;
/**
*
*/
private String databaseName;
}

View File

@ -0,0 +1,28 @@
package com.muyu.auth.form;
import lombok.Data;
/**
*
* @author
* @package com.muyu.auth.form
* @name Enterprise
* @date 2024/9/30 10:30
*/
@Data
public class Firm {
/**
* id
*/
private Integer id;
/**
*
*/
private String firmName;
/**
*
*/
private String databaseName;
}

View File

@ -1,10 +1,14 @@
package com.muyu.auth.form;
import lombok.Data;
/**
*
*
* @author muyu
*/
@Data
public class LoginBody {
/**
*
@ -16,20 +20,11 @@ public class LoginBody {
*/
private String password;
/**
*
*/
private String firmName;
public String getUsername () {
return username;
}
public void setUsername (String username) {
this.username = username;
}
public String getPassword () {
return password;
}
public void setPassword (String password) {
this.password = password;
}
}

View File

@ -0,0 +1,57 @@
package com.muyu.auth.service;
import com.muyu.auth.form.Firm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.data.redis.core.RedisTemplate;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
/**
*
* @author
* @package com.muyu.auth.service
* @name SysFirmService
* @date 2024/9/30 11:05
*/
@Component
public class SysFirmService {
//数据库账号
static final String USER="root";
//数据库密码
static final String PASSWORD="Lw030106";
@Autowired
private RedisTemplate redisTemplate;
public Firm findFirmByName(String firmName){
Firm firm = new Firm();
try {
DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
Connection connection= DriverManager.getConnection("jdbc:mysql://47.101.53.251:3306/datasource?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT&useSSL=false",USER,PASSWORD);
String sql="select * from `datasource` where firm_name = '"+firmName+"'";
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()){
firm.setId(rs.getInt("id"));
firm.setFirmName(rs.getString("firm_name"));
firm.setDatabaseName(rs.getString("database_name"));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
//数据源不为空
if (firm!=null){
redisTemplate.opsForValue().set("datasource",firm.getDatabaseName());
}
return firm;
};
}

View File

@ -1,5 +1,7 @@
package com.muyu.auth.service;
import com.muyu.cloud.common.many.datasource.ManyDataSource;
import com.muyu.common.core.constant.CacheConstants;
import com.muyu.common.core.constant.Constants;
import com.muyu.common.core.constant.SecurityConstants;
@ -12,7 +14,10 @@ import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.core.utils.ip.IpUtils;
import com.muyu.common.redis.service.RedisService;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.remote.RemoteUserService;
import com.muyu.common.system.domain.Business;
import com.muyu.common.system.domain.SysUser;
import com.muyu.common.system.domain.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
@ -37,6 +42,8 @@ public class SysLoginService {
@Autowired
private RedisService redisService;
/**
*
*/
@ -88,6 +95,8 @@ public class SysLoginService {
}
passwordService.validate(user, password);
recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
return userInfo;
}
@ -124,4 +133,29 @@ public class SysLoginService {
}
recordLogService.recordLogininfor(username, Constants.REGISTER, "注册成功");
}
/**
*
* @param databaseName
* @param fileName
*/
public void enterprise (String databaseName,String fileName) {
// 参数校验 数据库名或企业名称不能为空
if (StringUtils.isAnyBlank(databaseName, fileName)) {
throw new ServiceException("数据库名或企业名称不能为空");
}
if (databaseName.length() < UserConstants.PASSWORD_MIN_LENGTH || databaseName.length() > UserConstants.PASSWORD_MAX_LENGTH) {
throw new ServiceException("数据库名长度必须在5到20个字符之间");
}
if (fileName.length() < UserConstants.Firm_NAME_MIN_LENGTH || fileName.length() > UserConstants.Firm_NAME_MAX_LENGTH) {
throw new ServiceException("企业名称长度必须在2到20个字符之间");
}
Business settlement = new Business();
settlement.setDatabaseName(databaseName);
settlement.setFirmName(fileName);
remoteUserService.settlementEnterpriseInfo(settlement, SecurityConstants.INNER);
}
}

View File

@ -0,0 +1,374 @@
/*
Navicat Premium Data Transfer
Source Server :
Source Server Type : MySQL
Source Server Version : 80401
Source Host : 47.101.53.251:3306
Source Schema : saas
Target Server Type : MySQL
Target Server Version : 80401
File Encoding : 65001
Date: 04/10/2024 16:01:07
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for car_type
-- ----------------------------
DROP TABLE IF EXISTS `car_type`;
CREATE TABLE `car_type` (
`id` int NOT NULL AUTO_INCREMENT COMMENT '车辆类型Id',
`type_name` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '车辆类型',
`template_id` int NULL DEFAULT NULL COMMENT '报文模版Id',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '车辆类型' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for data_type
-- ----------------------------
DROP TABLE IF EXISTS `data_type`;
CREATE TABLE `data_type` (
`data_type_id` int NOT NULL AUTO_INCREMENT COMMENT '报文数据类型Id',
`data_type_name` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '报文数据类型',
PRIMARY KEY (`data_type_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '报文数据类型' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for electronic_fence
-- ----------------------------
DROP TABLE IF EXISTS `electronic_fence`;
CREATE TABLE `electronic_fence` (
`id` int NOT NULL AUTO_INCREMENT COMMENT '围栏主键',
`name` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '围栏名称',
`fence_type` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '围栏类型(驶入,驶出)',
`longitude_latitude` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL COMMENT '经纬度信息',
`status` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '电子围栏状态(正常,停用)',
`fence_desc` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '描述信息',
`create_by` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '创建人',
`create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '更新人',
`update_time` datetime NULL DEFAULT NULL COMMENT '更新时间',
`remark` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '备注',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 11 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin COMMENT = '电子围栏' ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Table structure for electronic_fence_group
-- ----------------------------
DROP TABLE IF EXISTS `electronic_fence_group`;
CREATE TABLE `electronic_fence_group` (
`id` int NOT NULL AUTO_INCREMENT COMMENT '自增主键',
`group_name` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '围栏组名称',
`group_type` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '围栏组类型',
`priority` int NULL DEFAULT NULL COMMENT '围栏组优先级(0-99)',
`status` varchar(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '启用状态',
`create_by` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '创建人',
`create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '更新人',
`update_time` datetime NULL DEFAULT NULL COMMENT '更新时间',
`remark` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '备注',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 11 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin COMMENT = '围栏组' ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Table structure for fence_group_mid
-- ----------------------------
DROP TABLE IF EXISTS `fence_group_mid`;
CREATE TABLE `fence_group_mid` (
`id` int NOT NULL AUTO_INCREMENT,
`group_id` int NULL DEFAULT NULL COMMENT '围栏组外键',
`fence_id` int NULL DEFAULT NULL COMMENT '电子围栏外键',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 23 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '电子围栏-围栏组(中间表)' ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Table structure for message_template
-- ----------------------------
DROP TABLE IF EXISTS `message_template`;
CREATE TABLE `message_template` (
`message_id` int(10) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT,
`vin_code` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'VIN 码',
`time_stamp` datetime NULL DEFAULT NULL COMMENT '时间戳',
`long_itude` double NULL DEFAULT NULL COMMENT '经度',
`latitude` double NULL DEFAULT NULL COMMENT '纬度',
`speed_vehicle` double NULL DEFAULT NULL COMMENT '车速',
`total_mileage` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '总里程',
`total_voltage` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '总电压',
`combined_current` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '总电流',
`insulation_resistance` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '绝缘电阻',
`gear_position` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '档位',
`accelerator_pedal_travel_value` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '加速踏板行程值',
`brake_pedal_travel_value` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '制动踏板行程值',
`specific_fuel_consumption` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '燃料消耗率',
`motor_controller_temperature` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '电机控制器温度',
`motor_speed` double NULL DEFAULT NULL COMMENT '电机转速',
`motor_torque` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '电机转矩',
`motor_temperature` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '电机温度',
`motor_voltage` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '电机电压',
`motor_current` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '电机电流',
`power_battery_remaining_soc` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '剩余电池电量',
`maximum_feedback_power` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最大反馈功率',
`maximum_discharge_power` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最大放电功率',
`bms_self_check_counter` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'BMS自检计数器',
`power_battery` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '动力电池',
`total_voltage_load_side` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '总电压负载侧',
`maximum_voltage` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最大电压',
`minimum_voltage` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最小电压',
`maximum_temperature` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最高温度',
`minimum_temperature` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最低温度',
`available_capacity` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '可用功率',
`vehicle_status` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '车辆状态',
`charging_state` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '充电状态',
`operational_status` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '行驶状态',
`soc` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '单芯片系统',
`energy_storage_devices` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '能源存储设备',
`drive_motor_condition` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '驱动电机转态',
`whether_works` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '是否有效',
`eas` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '电子防窃系统',
`ptc` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '正常温度系数',
`eps` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '蓄电池',
`abs` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '防抱死制动系统',
`mcu` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '单片机',
`heating_state` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '加热状态',
`power_battery_status` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '电源电池状态',
`state_battery_insulation` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '状态电池绝缘',
`dcdc` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '直流直流变换器',
`chg` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '变化',
`check_digit` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '校验数位',
`cutoff_bit` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '截止点',
PRIMARY KEY (`message_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '报文模版' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for message_template_type
-- ----------------------------
DROP TABLE IF EXISTS `message_template_type`;
CREATE TABLE `message_template_type` (
`message_template_type_id` int NOT NULL AUTO_INCREMENT,
`message_code` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '编码',
`message_field` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '标签',
`start_index` int NULL DEFAULT NULL COMMENT '起始位',
`end_index` int NULL DEFAULT NULL COMMENT '终值位',
`data_type_id` int NULL DEFAULT NULL COMMENT '报文数据类型Id',
`data_type_name` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '报文数据类型名称',
`fixed_value` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最小值',
`range_value` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最大值',
`template_id` int NULL DEFAULT NULL COMMENT '模版Id',
`message_class` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '报文类别',
PRIMARY KEY (`message_template_type_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 76 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '报文模版类型' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for message_value
-- ----------------------------
DROP TABLE IF EXISTS `message_value`;
CREATE TABLE `message_value` (
`message_id` bigint NOT NULL AUTO_INCREMENT COMMENT '报文主键',
`template_id` bigint NULL DEFAULT NULL COMMENT '模版外键',
`message_code` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '报文编码',
`message_label` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '报文标签',
`message_start_index` int NULL DEFAULT NULL COMMENT '起始位',
`message_end_index` int NULL DEFAULT NULL COMMENT '终止位',
`create_by` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '创建人',
`create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '更新人',
`update_time` datetime NULL DEFAULT NULL COMMENT '更新时间',
`remark` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '备注',
`message_class` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`message_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 61 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '报文' ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Table structure for sys_car
-- ----------------------------
DROP TABLE IF EXISTS `sys_car`;
CREATE TABLE `sys_car` (
`id` int NOT NULL AUTO_INCREMENT,
`car_vin` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'VIN码',
`car_type_id` int NULL DEFAULT NULL COMMENT '车辆类型Id',
`state` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '状态',
`fence_id` int NULL DEFAULT NULL COMMENT '电子围栏',
`car_motor_manufacturer` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '车辆电机厂商',
`car_motor_model` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '电机型号',
`car_battery_manufacturer` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '车辆电池厂商',
`car_battery_model` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '电池型号',
`strategy_id` int NULL DEFAULT NULL COMMENT '策略ID',
`group_id` int NULL DEFAULT NULL COMMENT '围栏组ID',
`create_by` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '创建人',
`create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '修改人',
`update_time` datetime NULL DEFAULT NULL COMMENT '修改时间',
`remark` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注',
`template_id` int NULL DEFAULT NULL COMMENT '报文模版ID',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '车辆基础信息表' ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Table structure for sys_car_enterprise
-- ----------------------------
DROP TABLE IF EXISTS `sys_car_enterprise`;
CREATE TABLE `sys_car_enterprise` (
`id` int NOT NULL AUTO_INCREMENT,
`enterprise_name` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '企业名称',
`name` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '用户姓名',
`position` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '用户职位',
`province` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '公司所在省',
`city` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '公司所在市',
`county` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '公司所在县/区',
`address` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '公司详细地址',
`credit_code` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '统一社会信用代码',
`business_license` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '营业执照',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '企业' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for sys_car_fault
-- ----------------------------
DROP TABLE IF EXISTS `sys_car_fault`;
CREATE TABLE `sys_car_fault` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '参数主键',
`fault_code` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '故障码编码',
`fault_name` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '故障名',
`type_id` int NULL DEFAULT NULL COMMENT '故障类型',
`fault_label` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '故障标签',
`fault_bit` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '故障位',
`fault_value` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '故障值',
`fault_rank` int NULL DEFAULT NULL COMMENT '故障级别 (0.低 1.中 2.高)',
`fault_desc` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '故障描述信息',
`fault_min_threshold` int NULL DEFAULT NULL COMMENT '故障最小阈值',
`fault_max_threshold` int NULL DEFAULT NULL COMMENT '故障最大阈值',
`status` int NULL DEFAULT 1 COMMENT '启用状态(1.待处理 2.处理中 3.已处理 4.忽略)',
`warn_status` int NULL DEFAULT 0 COMMENT '是否警告(0.开启 1.禁止)',
`remark` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注',
`create_by` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '创建者',
`create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_by` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '更新者',
`update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`car_type_id` int NULL DEFAULT NULL COMMENT '车辆类型',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 17 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '故障码' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for sys_car_fault_log
-- ----------------------------
DROP TABLE IF EXISTS `sys_car_fault_log`;
CREATE TABLE `sys_car_fault_log` (
`id` int NOT NULL AUTO_INCREMENT,
`sys_car_fault_id` int NOT NULL COMMENT '故障码编号',
`create_by` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '创建人',
`create_time` datetime NULL DEFAULT NULL COMMENT '开始时间',
`update_by` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '修改人',
`update_time` datetime NULL DEFAULT NULL COMMENT '结束时间',
`vin` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'VIN码',
`remark` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '内容',
`status` int NULL DEFAULT 2 COMMENT '1- 解决 2- 处理中 3-忽略',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '故障日志表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for sys_car_fault_message
-- ----------------------------
DROP TABLE IF EXISTS `sys_car_fault_message`;
CREATE TABLE `sys_car_fault_message` (
`id` int NOT NULL AUTO_INCREMENT,
`content` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '内容',
`status` int NULL DEFAULT NULL COMMENT '1-已读 2-未读',
`create_by` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '创建人',
`create_time` datetime NULL DEFAULT NULL COMMENT '开始时间',
`update_by` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '修改人',
`update_time` datetime NULL DEFAULT NULL COMMENT '结束时间',
`remark` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '站内信' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for sys_car_log
-- ----------------------------
DROP TABLE IF EXISTS `sys_car_log`;
CREATE TABLE `sys_car_log` (
`id` int NOT NULL AUTO_INCREMENT,
`car_vin` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'VIN码',
`start_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
`end_time` datetime NULL DEFAULT NULL COMMENT '结束时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '车辆日志表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for t_template
-- ----------------------------
DROP TABLE IF EXISTS `t_template`;
CREATE TABLE `t_template` (
`template_id` int NOT NULL AUTO_INCREMENT,
`house_id` int NULL DEFAULT NULL,
`template_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '报文模版名称',
`template_describe` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '报文模版描述',
`create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`template_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '报文模版表' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for tb_enterprise
-- ----------------------------
DROP TABLE IF EXISTS `tb_enterprise`;
CREATE TABLE `tb_enterprise` (
`enterprise_id` int NOT NULL AUTO_INCREMENT COMMENT '企业编号',
`enterprise_name` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '企业名称',
`enterprise_car_count` int NULL DEFAULT 0 COMMENT '企业车辆数量',
`enterprise_fence_count` int NULL DEFAULT 0 COMMENT '企业电子围栏数量',
`enterprise_database_name` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '企业数据库',
PRIMARY KEY (`enterprise_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 18 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '企业运营' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for warn_logs
-- ----------------------------
DROP TABLE IF EXISTS `warn_logs`;
CREATE TABLE `warn_logs` (
`id` int NOT NULL AUTO_INCREMENT COMMENT '预警日志id',
`vin` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '车辆vin码',
`warn_rule_id` int NULL DEFAULT NULL COMMENT '规则id',
`start_time` datetime NULL DEFAULT NULL COMMENT '开始时间',
`end_time` datetime NULL DEFAULT NULL COMMENT '结束时间',
`max_value` int NULL DEFAULT NULL COMMENT '最大值',
`min_value` int NULL DEFAULT NULL COMMENT '最小值',
`avg_value` int NULL DEFAULT NULL COMMENT '平均值',
`median_value` int NULL DEFAULT NULL COMMENT '中位数',
`status` int NULL DEFAULT NULL COMMENT '是否发送预警',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '车辆预警记录表' ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Table structure for warn_rule
-- ----------------------------
DROP TABLE IF EXISTS `warn_rule`;
CREATE TABLE `warn_rule` (
`id` int NOT NULL AUTO_INCREMENT COMMENT '规则id',
`rule_name` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '规则名称',
`strategy_id` int NULL DEFAULT NULL COMMENT '策略id',
`msg_type_id` int NULL DEFAULT NULL COMMENT '报文数据类型id',
`slide_time` int NULL DEFAULT NULL COMMENT '滑窗时间',
`slide_frequency` int NULL DEFAULT NULL COMMENT '滑窗频率',
`growth_rate` int NULL DEFAULT NULL COMMENT '增长率',
`volatility_rate` int NULL DEFAULT NULL COMMENT '波动率',
`decrease_rate` int NULL DEFAULT NULL COMMENT '下降率',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '车辆预警规则表' ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Table structure for warn_strategy
-- ----------------------------
DROP TABLE IF EXISTS `warn_strategy`;
CREATE TABLE `warn_strategy` (
`id` int NOT NULL AUTO_INCREMENT COMMENT '策略id',
`car_type_id` int NULL DEFAULT NULL COMMENT '车辆类型id',
`strategy_name` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '策略名称',
`template_id` int NULL DEFAULT NULL COMMENT '报文模版id',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 8 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '车辆预警策略表' ROW_FORMAT = DYNAMIC;
SET FOREIGN_KEY_CHECKS = 1;

View File

@ -8,6 +8,10 @@ package com.muyu.cache;/**
import com.muyu.common.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import static cn.hutool.core.lang.ansi.AnsiEncoder.encode;
/**
@ -23,7 +27,7 @@ public abstract class CacheAbsBasic<K,V> implements CacheBasic<K,V>{
@Override
public void put(K key, V value) {
redisService.setCacheObject(encodeKey(key), value); // 编码 --> 缓存基础的对象 Integer String 实体类等
redisService.setCacheObject(encodeKey(key), value,24L, TimeUnit.HOURS); // 编码 --> 缓存基础的对象 Integer String 实体类等
}
@Override

View File

@ -1,5 +1,7 @@
package com.muyu.cache;
import java.util.List;
/**
* @author yuping
* @package com.muyu.cache

View File

@ -0,0 +1,49 @@
package com.muyu.common.core.constant;
/**
* kafka
* @program: cloud-server
* @author: cuiyongxing
* @create: 2024-09-28 12:18
**/
public class KafkaConstant {
public static final String BOOTSTRAP_SERVERS = "bootstrap.servers";
public static final String RETRIES = "retries";
public static final String ACKS = "acks";
public static final String BATCH_SIZE = "batch.size";
public static final String BUFFER_MEMORY = "buffer-memory";
public static final String KEY_SERIALIZER = "key.serializer";
public static final String VALUE_SERIALIZER = "value.serializer";
public static final String ENABLE_AUTO_COMMIT = "enable.auto.commit";
public static final String AUTO_COMMIT_INTERVAL = "auto.commit.interval.ms";
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";
public static final String MAX_POLL_RECORDS = "max.poll.records";
public static final String KEY_DESERIALIZER = "key.deserializer";
public static final String VALUE_DESERIALIZER = "value.deserializer";
public static final String TOPIC = "topic";
public static final String GROUP_ID = "group.id";
}

View File

@ -110,4 +110,16 @@ public class UserConstants {
public static final int PASSWORD_MIN_LENGTH = 5;
public static final int PASSWORD_MAX_LENGTH = 20;
/**
*
*/
public static final int Firm_NAME_MIN_LENGTH = 2;
public static final int Firm_NAME_MAX_LENGTH = 20;
/**
*
*/
public static final int DATABASE_NAME_MIN_LENGTH = 2;
public static final int DATABASE_NAME_MAX_LENGTH = 20;
}

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-kafka</artifactId>
<description>
cloud-common-kafka消息队列
</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.kafka</groupId>-->
<!-- <artifactId>kafka-clients</artifactId>-->
<!-- <version>3.0.0</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-core</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,94 @@
package com.muyu.common.kafka.config;
import com.muyu.common.core.constant.KafkaConstant;
import org.apache.kafka.clients.consumer.KafkaConsumer;
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;
import java.util.Map;
/**
* kafka
* @program: cloud-server
* @author: cuiyongxing
* @create: 2024-09-28 14:28
**/
@Configuration
public class KafkaConsumerConfig {
/**
* id+
*/
@Value("${spring.kafka.consumer.bootstrap-servers}")
private String bootstrapServers;
/**
*
*/
@Value("${spring.kafka.consumer.enable-auto-commit}")
private Boolean enableAutoCommit;
/**
*
*/
@Value("${spring.kafka.consumer.auto-commit-interval}")
private Integer autoCommitInterval;
/**
*
*/
@Value("${spring.kafka.consumer.auto-offset-reset}")
private String autoOffsetReset;
/**
*
*/
@Value("${spring.kafka.consumer.fetch-max-wait}")
private Integer fetchMaxWait;
/**
*
*/
@Value("${spring.kafka.consumer.fetch-min-size}")
private Integer fetchMinSize;
/**
*
*/
@Value("${spring.kafka.consumer.heartbeat-interval}")
private Integer heartbeatInterval;
/**
*
*/
@Value("${spring.kafka.consumer.max-poll-records}")
private Integer maxPollRecords;
/**
*
*/
@Value("${spring.kafka.consumer.group-id}")
private String groupId;
@Bean
public KafkaConsumer kafkaConsumer(){
Map<String,Object> configs = new HashMap<>();
configs.put(KafkaConstant.BOOTSTRAP_SERVERS, bootstrapServers);
configs.put(KafkaConstant.ENABLE_AUTO_COMMIT, enableAutoCommit);
configs.put(KafkaConstant.AUTO_COMMIT_INTERVAL, autoCommitInterval);
configs.put(KafkaConstant.AUTO_OFFSET_RESET, autoOffsetReset);
configs.put(KafkaConstant.FETCH_MAX_WAIT, fetchMaxWait);
configs.put(KafkaConstant.FETCH_MIN_SIZE, fetchMinSize);
configs.put(KafkaConstant.HEARTBEAT_INTERVAL, heartbeatInterval);
configs.put(KafkaConstant.MAX_POLL_RECORDS, maxPollRecords);
configs.put(KafkaConstant.GROUP_ID, groupId);
StringDeserializer keyDeserializer = new StringDeserializer();
StringDeserializer valueDeserializer = new StringDeserializer();
return new KafkaConsumer(configs, keyDeserializer, valueDeserializer);
}
}

View File

@ -0,0 +1,66 @@
package com.muyu.common.kafka.config;
import com.muyu.common.core.constant.KafkaConstant;
import org.apache.kafka.clients.producer.KafkaProducer;
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;
import java.util.Map;
/**
* kafka
* @program: cloud-server
* @author: cuiyongxing
* @create: 2024-09-28 12:03
**/
@Configuration
public class KafkaProducerConfig {
/**
* ip+
*/
@Value("${spring.kafka.producer.bootstrap-servers}")
private String bootstrapServers;
/**
*
*/
@Value("${spring.kafka.producer.retries}")
private Integer retries;
/**
*
*/
@Value("${spring.kafka.producer.batch-size}")
private Integer batchSize;
/**
*
*/
@Value("${spring.kafka.producer.buffer-memory}")
private Integer bufferMemory;
/**
*
*/
@Value("${spring.kafka.producer.acks}")
private String acks;
@Bean
public KafkaProducer kafkaProducer() {
Map<String, Object> configs = new HashMap<>();
configs.put(KafkaConstant.BOOTSTRAP_SERVERS, bootstrapServers);
configs.put(KafkaConstant.RETRIES, retries);
configs.put(KafkaConstant.BATCH_SIZE, batchSize);
configs.put(KafkaConstant.BUFFER_MEMORY, bufferMemory);
configs.put(KafkaConstant.ACKS, acks);
StringSerializer keySerializer = new StringSerializer();
StringSerializer valueSerializer = new StringSerializer();
KafkaProducer kafkaProducer = new KafkaProducer<>(configs, keySerializer, valueSerializer);
return kafkaProducer;
}
}

View File

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

View File

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

View File

@ -1,41 +0,0 @@
package com.muyu.common.rabbit;
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;
@Configuration
public class RabbitListenerConfigurer implements org.springframework.amqp.rabbit.annotation.RabbitListenerConfigurer {
static {
System.setProperty("spring.amqp.deserialization.trust.all", "true");
}
//以下配置RabbitMQ消息服务
@Autowired
public ConnectionFactory connectionFactory;
/**
*
* @return
*/
@Bean
public DefaultMessageHandlerMethodFactory handlerMethodFactory() {
DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();
// 这里的转换器设置实现了 通过 @Payload 注解 自动反序列化message body
factory.setMessageConverter(new MappingJackson2MessageConverter());
return factory;
}
@Override
public void configureRabbitListeners(RabbitListenerEndpointRegistrar rabbitListenerEndpointRegistrar) {
rabbitListenerEndpointRegistrar.setMessageHandlerMethodFactory(handlerMethodFactory());
}
}

View File

@ -0,0 +1,47 @@
package com.muyu.rabbitmq.config;
import lombok.AllArgsConstructor;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
/**
* @ClassName:
* @Description:
*/
@Component
@AllArgsConstructor
public class MyConfirmCallback implements RabbitTemplate.ConfirmCallback {
private RabbitTemplate rabbitTemplate;
// public MyConfirmCallback(RabbitTemplate rabbitTemplate) {
// this.rabbitTemplate = rabbitTemplate;
// // 设置 消息发送到交换机成功 的回调
// this.rabbitTemplate.setConfirmCallback(this);
// }
@PostConstruct
public void init() {
this.rabbitTemplate.setConfirmCallback(this);
}
/**
*
*
* @param correlationData correlation data for the callback.
* @param ack true for ack, false for nack
* @param cause An optional cause, for nack, when available, otherwise null.
*/
@Override
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
if (ack) {
System.out.println("消息发送到交换机成功~");
} else {
System.out.println("消息发送到交换机失败,失败的原因:" + cause);
}
}
}

View File

@ -0,0 +1,49 @@
package com.muyu.rabbitmq.config;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @ClassName: RabbitAdminConfig
* @Description: RabbitAdmin
*/
@Configuration
public class RabbitAdminConfig {
@Value("${spring.rabbitmq.host}")
private String host;
@Value("${spring.rabbitmq.username}")
private String username;
@Value("${spring.rabbitmq.password}")
private String password;
@Value("${spring.rabbitmq.port}")
private Integer port;
@Bean
public ConnectionFactory connectionFactory() {
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
cachingConnectionFactory.setHost(host);
cachingConnectionFactory.setPort(port);
cachingConnectionFactory.setUsername(username);
cachingConnectionFactory.setPassword(password);
return cachingConnectionFactory;
}
@Bean
public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
rabbitAdmin.setAutoStartup(true);
return rabbitAdmin;
}
}

View File

@ -0,0 +1,20 @@
package com.muyu.rabbitmq.config;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* JSON json
*/
@Configuration
public class RabbitmqConfig {
// 消息转换配置
@Bean
public MessageConverter jsonMessageConverter() {
return new Jackson2JsonMessageConverter();
}
}

View File

@ -0,0 +1,37 @@
package com.muyu.rabbitmq.config;
import lombok.AllArgsConstructor;
import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
/**
*
*/
@Component
@AllArgsConstructor
public class ReturnCallbackConfig implements RabbitTemplate.ReturnsCallback {
private final RabbitTemplate rabbitTemplate;
@PostConstruct // @PostContruct是spring框架的注解在⽅法上加该注解会在项⽬启动的时候执⾏该⽅法也可以理解为在spring容器初始化的时候执
public void init() {
rabbitTemplate.setReturnsCallback(this);
}
/**
*
*
* @param returnedMessage the returned message and metadata.
*/
@Override
public void returnedMessage(ReturnedMessage returnedMessage) {
System.out.println("消息" + returnedMessage.getMessage().toString() +
"被交换机" + returnedMessage.getExchange() + "回退!"
+ "退回原因为:" + returnedMessage.getReplyText());
// 回退了所有的信息,可做补偿机制 记录发送的日志
}
}

View File

@ -0,0 +1,35 @@
package com.muyu.rabbitmq.constants;
/**
*
* @author:
* @date: 2024/7/10
* @Description: rabbitmq
* @Version 1.0.0
*/
public interface RabbitmqConstants {
//普通队列
String BASIC_QUEUE_NAME = "BASIC_QUEUE_NAME";
String lOG_QUEUE_NAME = "LOG_QUEUE_NAME";
//延迟队列
//队列名称
String DELAYED_QUEUE_NAME = "delayed_queue";
//交换机名称
String DELAYED_EXCHANGE_NAME = "DELAYED_EXCHANGE";
//交换机
String DELAYED_ROUTING_KEY = "delayed";
/**
* 线
*/
String TOP_BOTTOM_STITCHING = "top_bottom_stitching";
/**
* 线
*/
String TOP_RULE = "car.top.data";
/**
* 线
*/
String BOTTOM_RULE = "car.bottom.data";
}

View File

@ -0,0 +1,150 @@
package com.muyu.rabbitmq.consumer;
import com.alibaba.fastjson2.JSONObject;
import com.muyu.common.redis.service.RedisService;
//import com.muyu.rabbitmq.util.CacheUtil;
import com.rabbitmq.client.Channel;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.Date;
/**
* @ClassName: RabbitMQConsumerUtil
* @Description: rabbitmq
*/
@Component
@Log4j2
@AllArgsConstructor
public class RabbitMQConsumerUtil {
private final RedisService redisService;
// @Autowired
// private CacheUtil cacheUtil;
/**
*
* @param data
* @param message
* @param channel
*/
// @RabbitListener(queuesToDeclare = @Queue(name = "basic"))
public void rabbitMQBasicConsumer(String data ,Message message , Channel channel) {
log.info("当前时间:{} RabbitMQConsumerUtil : {}", new Date(), message);
try {
// 获取到消息 开始消费
log.info("消息消费者接收到消息,消息内容:{}", JSONObject.toJSONString(data));
Long add = redisService.redisTemplate.opsForSet().add(data, message.getMessageProperties().getMessageId());
if (add != 1) {
return;
}
/**
* ---------------------------------------------------------------
*/
String carList = (String) redisService.redisTemplate.opsForValue().get("carList");
/**
* ------------------------------------------------------------------------------
*/
// 消费消息成功之后需要确认
// long deliveryTag 消息投递序号 自增的数字 在整个队列中唯一 拿到这个序号就相当于拿到这条消息
// boolean multiple 是否批量确认 true 批量 确认小于等于当前投递序号的消息 false 单个确认
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
log.info("xxx消费者接收到消息消息内容{},消费成功...", message);
} catch (Exception e) {
log.error("xxx消费者接收到消息消息内容{},消费消息异常,异常信息:{}", message, e);
// 消息回退 拒绝消费消息
// long deliveryTag 消息投递序号 自增的数字 在整个队列中唯一 拿到这个序号就相当于拿到这条消息
// boolean requeue 是否回到原来的队列
try {
channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
// channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true);
} catch (IOException ex) {
log.error("xxx消费者接收到消息消息内容{},回退消息异常,异常信息:{}", message, ex);
}
}finally {
try {
channel.close();
} catch (Exception e) {
log.error("xxx消费者关闭Channel异常消息内容{},异常信息:{}", message, e);
}
}
}
/**
*
* @param data
* @param message
* @param channel
*/
public void carUpConsumer(String data,Message message , Channel channel) {
log.info("当前时间:{} RabbitMQConsumerUtil : {}", new Date(), message);
try {
// 获取到消息 开始消费
log.info("消息消费者接收到消息,消息内容:{}", JSONObject.toJSONString(data));
Long add = redisService.redisTemplate.opsForSet().add(data, message.getMessageProperties().getMessageId());
if (add != 1) {
return;
}
/**
* ---------------------------------------------------------------
*/
log.info("[ 根据vin拿到缓存 ] vin为 --》 {}",data);
log.info("[ 存入本地缓存 ] 数据为 --》 {}",data);
log.info("[ 存入本地缓存 ] 数据为 --》 {}",data);
/**
* ------------------------------------------------------------------------------
*/
// 消费消息成功之后需要确认
// long deliveryTag 消息投递序号 自增的数字 在整个队列中唯一 拿到这个序号就相当于拿到这条消息
// boolean multiple 是否批量确认 true 批量 确认小于等于当前投递序号的消息 false 单个确认
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
log.info("xxx消费者接收到消息消息内容{},消费成功...", message);
} catch (Exception e) {
log.error("xxx消费者接收到消息消息内容{},消费消息异常,异常信息:{}", message, e);
// 消息回退 拒绝消费消息
// long deliveryTag 消息投递序号 自增的数字 在整个队列中唯一 拿到这个序号就相当于拿到这条消息
// boolean requeue 是否回到原来的队列
try {
channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
// channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true);
} catch (IOException ex) {
log.error("xxx消费者接收到消息消息内容{},回退消息异常,异常信息:{}", message, ex);
}
}finally {
try {
channel.close();
} catch (Exception e) {
log.error("xxx消费者关闭Channel异常消息内容{},异常信息:{}", message, e);
}
}
}
}

View File

@ -0,0 +1,174 @@
package com.muyu.rabbitmq.producer;
import com.muyu.common.core.domain.Result;
import com.muyu.rabbitmq.constants.RabbitmqConstants;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;
import java.util.UUID;
/**
* @ClassName: RabbitMQProducer
* @Description: rabbitmq
*/
@Component
@AllArgsConstructor
@Log4j2
public class RabbitMQProducerUtil {
//redis工具类对象
//rabbit
private final RabbitTemplate rabbitTemplate;
/**
*
*
* @param param
* @return
*
*/
public void basicSendMessage(String queueName, String param) {
log.info("【简单模型mq】 : method: 【 basicSendMessage 】 - ages: 【 String : {}, Object : {}】 ---> 【 消息发送中。。。 】", RabbitmqConstants.BASIC_QUEUE_NAME, param);
// 发送简单模型消息
// 第一个参数: 绑定规则 相当于 队列名称
// 第二个参数:消息内容
rabbitTemplate.convertAndSend(queueName, param, message -> {
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
return message;
} );
log.info("【简单模型mq】 : method: 【 basicSendMessage 】- queue: 【 {} 】 ---> 【 消息发送成功 】", RabbitmqConstants.BASIC_QUEUE_NAME);
}
// /**
// * Work queue 工作模型
// *
// * @param obj 传递的消息 (如果是对象需要序列化)
// * @return 结果集
// * 多个消费者,你一个我一个分配消费消息,有预取机制,默认公平消费,可配置 能者多劳模式(),谁完成的快,谁多做一点
// */
// public Result<?> workSendMessage(String queueName, Object obj, String msg) {
//
// log.info("【工作模型mq】 : method: 【 workSendMessage 】 - ages: 【 String : {}, Object : {}, String : {} 】 ---> 【 消息发送中。。。 】", queueName, obj, msg);
// // 发送简单模型消息
// // 第一个参数: 绑定规则 相当于 队列名称
// // 第二个参数:消息内容
// rabbitTemplate.convertAndSend(queueName, obj, message -> {
// message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
// return message;
// } );
//
// log.info("【工作模型mq】 : method: 【 workSendMessage 】- queue: 【 {} 】 ---> 【 消息发送成功 】", queueName);
//
// return Result.success("消息发送成功");
// }
//
// /**
// * Publish/Subscribe 发布订阅者模型
// * 多个消费者,多个消费者可以同时接收到消息 有交换机 类型 fanout
// *
// * @param exchange 交换机名称
// * @param obj 发送的消息Object
// * @param msg 响应的内容
// * @return 结果集
// */
// public Result<?> publishSubscribeSendMessage(String exchange, Object obj, String msg) {
//
// log.info("【订阅模型mq】 : method: 【 workSendMessage 】 - ages: 【 String : {}, Object : {}, String : {} 】 ---> 【 消息发送中。。。 】", exchange, obj, msg);
// // 发送简单模型消息
// // 第一个参数: exchange 交换机的名称
// // 第二个参数: 绑定规则 发布订阅者模型 不写 默认 "" 只要绑定就行 不需要规则
// // 第三个参数:消息内容
// rabbitTemplate.convertAndSend(exchange, "", obj, message -> {
// message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
// return message;
// } );
//
// log.info("【订阅模型mq】 : method: 【 workSendMessage 】- exchange: 【 {} 】 ---> 【 消息发送成功 】", exchange);
//
// return Result.success("消息发送成功");
// }
//
// /**
// * Routing路由模型
// * 使用的是 Direct 类型的交换机,会将接收到的消息根据 规则 路由到指定的Queue(队列),因此称为路由模式
// *
// * @param exchange 交换机名称
// * @param rule 绑定规则 一个字符串即可
// * @param obj 发送的消息Object
// * @param msg 响应的内容
// * @return 结果集
// */
// public Result<?> routingSendMessage(String exchange, String rule, Object obj, String msg) {
//
// log.info("【路由模型mq】 : method: 【 workSendMessage 】 - ages: 【 String : {}, Object : {}, String : {} 】 ---> 【 消息发送中。。。 】", exchange, obj, msg);
// // 发送简单模型消息
// // 第一个参数: 绑定规则 相当于 队列名称
// // 第二个参数:消息内容
// rabbitTemplate.convertAndSend(exchange, rule, obj, message -> {
// message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
// return message;
// } );
//
// log.info("【路由模型mq】 : method: 【 workSendMessage 】- exchange: 【 {} 】 ---> 【 消息发送成功 】", exchange);
//
// return Result.success("消息发送成功");
// }
//
//
// /**
// * Topic主题模型模型
// * 使用的是 topic 类型的交换机
// *
// * @param exchange 交换机名称
// * @param rule 绑定规则 可以绑定多个单词以 . 拼接 也可以使用 #(匹配 零个 一个 或 多个 单词) 或 *(匹配 一个 单词) 通配符例如name.msg, *.msg, age.#
// * @param obj 发送的消息Object
// * @param msg 响应的内容
// * @return 结果集
// */
// public Result<?> topicSendMessage(String exchange, String rule, Object obj) {
//
// log.info("【主题模型mq】 : method: 【 workSendMessage 】 - ages: 【 String : {}, Object : {} 】 ---> 【 消息发送中。。。 】", exchange, obj);
// // 发送简单模型消息
// // 第一个参数: 绑定规则 相当于 队列名称
// // 第二个参数:消息内容
// rabbitTemplate.convertAndSend(exchange, rule, obj, message -> {
// message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
// return message;
// } );
//
// log.info("【主题模型mq】 : method: 【 workSendMessage 】- exchange: 【 {} 】 ---> 【 消息发送成功 】", exchange);
//
// return Result.success(obj,"消息发送成功");
// }
/**
*
* @param param
* @param delayTime
* @return
*/
// public Result<?> delayedSendMessage(Long delayTime, Object param) {
// log.info("【延迟队列模型】 : method: 【 delayedSendMessage 】 消息内容:{}---> 【 消息发送中。。。 】",param);
//
// rabbitTemplate.convertAndSend(RabbitmqConstants.DELAYED_EXCHANGE_NAME, RabbitmqConstants.DELAYED_ROUTING_KEY,param, message -> {
// MessageProperties messageProperties = message.getMessageProperties();
// messageProperties.setMessageId(UUID.randomUUID().toString());
// messageProperties.setDelayLong(delayTime);
// return message;
// });
// log.info("【延迟队列模型】 : method: 【 delayedSendMessage 】 消息内容:{}---> 【 消息发送成功 】",param);
//
// return Result.success(param,"消息发送成功");
//
// }
}

View File

@ -1 +1,6 @@
com.muyu.common.rabbit.RabbitListenerConfigurer
com.muyu.rabbitmq.producer.RabbitMQProducerUtil
com.muyu.rabbitmq.consumer.RabbitMQConsumerUtil
com.muyu.rabbitmq.config.RabbitmqConfig
com.muyu.rabbitmq.config.MyConfirmCallback
com.muyu.rabbitmq.config.RabbitAdminConfig
com.muyu.rabbitmq.config.ReturnCallbackConfig

View File

@ -11,6 +11,10 @@
<artifactId>cloud-common-saas</artifactId>
<description>
cloud-common-saas 模块
</description>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
@ -29,8 +33,10 @@
<groupId>com.muyu</groupId>
<artifactId>cloud-common-security</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
</dependencies>

View File

@ -1,33 +1,30 @@
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.constents.DatasourceContent;
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.init.InitDataSource;
import com.muyu.cloud.common.many.datasource.role.DynamicDataSource;
import com.muyu.cloud.common.saas.domain.Datasource;
import com.muyu.cloud.common.saas.domain.model.EntInfo;
import com.muyu.cloud.common.saas.exception.SaaSException;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.SpringUtils;
import com.muyu.common.system.domain.Datasource;
import com.muyu.common.system.domain.SysUser;
import com.muyu.common.system.remote.RemoteSaaSService;
import com.muyu.common.system.remote.RemoteUserService;
import lombok.extern.log4j.Log4j2;
import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
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.stereotype.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Author: DongZeLiang
* @date: 2024/6/3
@ -38,9 +35,14 @@ import java.util.Map;
@Component
@AutoConfiguration(before = {MybatisPlusAutoConfiguration.class, MybatisAutoConfiguration.class})
public class ManyDataSource implements ApplicationRunner{
private List<EntInfo> dataSourceInfoList(){
@Autowired
private InitDataSource initDataSource;
public List<EntInfo> dataSourceInfoList(){
RemoteSaaSService remoteSaaSService = SpringUtils.getBean(RemoteSaaSService.class);
Result<List<Datasource>> tableDataInfoResult = remoteSaaSService.findDatabaseList();
Result<List<Datasource>> tableDataInfoResult = initDataSource.initDatasource();
if (tableDataInfoResult==null){
throw new SaaSException("saas远调数据源错误");
}
@ -62,7 +64,6 @@ Result<List<Datasource>> tableDataInfoResult = remoteSaaSService.findDatabaseLis
return null;
}
}
// private List<EntInfo> dataPrimarySourceInfoList(){
// List<EntInfo> list = new ArrayList<>();
// list.add(
@ -74,7 +75,6 @@ Result<List<Datasource>> tableDataInfoResult = remoteSaaSService.findDatabaseLis
// );
// return list;
// }
@Bean
public DynamicDataSource dynamicDataSource(DruidDataSourceFactory druidDataSourceFactory) {
// 企业列表 企业CODE端口IP
@ -93,7 +93,6 @@ Result<List<Datasource>> tableDataInfoResult = remoteSaaSService.findDatabaseLis
dynamicDataSource.setDefineTargetDataSources(dataSourceMap);
return dynamicDataSource;
}
@Override
public void run(ApplicationArguments args) {
DruidDataSourceFactory druidDataSourceFactory = SpringUtils.getBean(DruidDataSourceFactory.class);

View File

@ -0,0 +1,58 @@
package com.muyu.cloud.common.many.datasource.init;
import com.muyu.cloud.common.saas.domain.Datasource;
import com.muyu.common.core.domain.Result;
import lombok.extern.log4j.Log4j2;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
@Component
@Log4j2
public class InitDataSource {
public static final String USER="root";
public static final String PASSWORD="Lw030106";
@Bean
@Primary
public Result<List<Datasource>> initDatasource(){
ArrayList<Datasource> list = new ArrayList<>();
try {
DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
Connection connection= DriverManager.getConnection("jdbc:mysql://47.101.53.251:3306/datasource?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT&useSSL=false",USER,PASSWORD);
String sql="select * from `datasource` ";
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()){
Datasource datasource = new Datasource();
datasource.setId(rs.getInt("id"));
datasource.setFirmName(rs.getString("firm_name"));
datasource.setDatabaseName(rs.getString("database_name"));
list.add(datasource);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
return Result.success(list);
};
}

View File

@ -1,10 +1,9 @@
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.cloud.common.saas.contents.SaaSConstant;
import com.muyu.cloud.common.saas.exception.SaaSException;
import com.muyu.common.core.utils.ServletUtils;
import com.muyu.common.core.utils.SpringUtils;
import jakarta.servlet.http.HttpServletRequest;

View File

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

View File

@ -1,23 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
<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>
<modelVersion>4.0.0</modelVersion>
<groupId>com.bwie</groupId>
<artifactId>cloud-common-swagger</artifactId>
<description>
cloud-common-swagger swagger2文档聚合
cloud-common-swagger系统接口
</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>
<!-- SpringBoot Web -->
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -1,10 +1,21 @@
package com.muyu.common.swagger.annotation;
import com.muyu.common.swagger.config.SwaggerAutoConfiguration;
import org.springframework.context.annotation.Import;
import java.lang.annotation.*;
/**
* @author
* @packagecom.muyu.common.swagger.annotation
* @nameEnableCustomSwagger2
* @date2024/9/29 10:01
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Import({SwaggerAutoConfiguration.class})
public @interface EnableCustomSwagger2 {
}

View File

@ -12,6 +12,7 @@ import java.util.List;
import java.util.stream.Collectors;
/**
* springboot 2.6.x
* @author
* @packagecom.muyu.common.swagger.config
* @nameSwaggerBeanPostProcessor

View File

@ -300,4 +300,3 @@ public class SwaggerProperties {
}
}
}

View File

@ -0,0 +1,40 @@
package com.muyu.common.system.domain;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.annotation.Excel.ColumnType;
import com.muyu.common.core.web.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
*
* @author
* @package com.muyu.common.system.domain
* @name Enterprise
* @date 2024/9/30 12:05
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class Business {
/**
* Id
*/
@Excel(name = "企业序号",cellType = ColumnType.NUMERIC, prompt = "企业编号")
private Integer id;
/**
*
*/
@Excel(name = "企业名称")
private String firmName;
/**
*
*/
@Excel(name = "数据库名称")
private String databaseName;
}

View File

@ -1,26 +0,0 @@
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 lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "datasource", autoResultMap = true)
public class Datasource {
@TableId(value = "id",type = IdType.AUTO)
private Integer id;
public String firmName;
public String databaseName;
}

View File

@ -1,25 +0,0 @@
package com.muyu.common.system.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* @Author WangXin
* @Data 2024/9/18
* @Description
* @Version 1.0.0
*/
@EqualsAndHashCode(callSuper = true)
@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
public class SysFirmUser extends SysUser {
/**
*
*/
private String databaseName;
}

View File

@ -1,13 +1,10 @@
package com.muyu.common.system.remote;
import com.muyu.common.core.constant.SecurityConstants;
import com.muyu.common.core.constant.ServiceNameConstants;
import com.muyu.common.core.domain.Result;
import com.muyu.common.system.domain.Datasource;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.common.system.domain.SysUser;
import com.muyu.common.system.domain.Business;
import com.muyu.common.system.remote.factory.RemoteSaaSFallbackFactory;
import com.muyu.common.system.remote.factory.RemoteUserFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
@ -22,7 +19,7 @@ import java.util.List;
public interface RemoteSaaSService {
@GetMapping("/saas/findDatabaseList")
Result<List<Datasource>> findDatabaseList();
Result<List<Business>> findDatabaseList();

View File

@ -3,12 +3,12 @@ package com.muyu.common.system.remote;
import com.muyu.common.core.constant.SecurityConstants;
import com.muyu.common.core.constant.ServiceNameConstants;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.system.domain.SysFirmUser;
import com.muyu.common.system.domain.Business;
import com.muyu.common.system.domain.SysUser;
import com.muyu.common.system.remote.factory.RemoteUserFallbackFactory;
import com.muyu.common.system.domain.LoginUser;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -44,4 +44,21 @@ public interface RemoteUserService {
@GetMapping("/user/companyList")
Result<List<SysUser>> companyList();
/**
*
* @param enterprise
* @param source
* @return
*/
@PostMapping("/user/enterprise")
Result<Boolean>settlementEnterpriseInfo(@RequestBody Business enterprise, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/**
*
* @param sysUser
* @return
*/
@PostMapping("/user/addUser")
public Result<Integer> addUser(@RequestBody SysUser sysUser,@RequestHeader(SecurityConstants.FROM_SOURCE)String source);
}

View File

@ -1,13 +1,8 @@
package com.muyu.common.system.remote.factory;
import com.muyu.common.core.domain.Result;
import com.muyu.common.system.domain.Datasource;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.common.system.domain.SysUser;
import com.muyu.common.system.domain.Business;
import com.muyu.common.system.remote.RemoteSaaSService;
import com.muyu.common.system.remote.RemoteUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
@ -25,7 +20,7 @@ public class RemoteSaaSFallbackFactory implements FallbackFactory<RemoteSaaSServ
public RemoteSaaSService create(Throwable cause) {
return new RemoteSaaSService() {
@Override
public Result<List<Datasource>> findDatabaseList() {
public Result<List<Business>> findDatabaseList() {
return Result.error("查询数据库失败:" + cause.getMessage());
}
};

View File

@ -1,8 +1,7 @@
package com.muyu.common.system.remote.factory;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.system.domain.SysFirmUser;
import com.muyu.common.system.domain.Business;
import com.muyu.common.system.remote.RemoteUserService;
import com.muyu.common.system.domain.SysUser;
import com.muyu.common.system.domain.LoginUser;
@ -41,6 +40,17 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
return Result.error("获取企业列表失败:" + throwable.getMessage());
}
@Override
public Result<Boolean> settlementEnterpriseInfo(Business enterprise, String source) {
return Result.error("入驻企业失败");
}
@Override
public Result<Integer> addUser(SysUser sysUser, String source) {
return Result.error("用户添加失败");
}
};
}
}

View File

@ -23,6 +23,7 @@
<module>cloud-common-saas</module>
<module>cloud-common-swagger</module>
<module>cloud-common-cache</module>
<module>cloud-common-kafka</module>
</modules>
<artifactId>cloud-common</artifactId>
@ -32,4 +33,5 @@
cloud-common通用模块
</description>
</project>

View File

@ -54,13 +54,6 @@
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<!-- Mysql Connector -->
<dependency>
<groupId>com.mysql</groupId>
@ -110,11 +103,35 @@
<artifactId>node-commons</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-kafka</artifactId>
<version>3.6.3</version>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-rabbit</artifactId>
</dependency>
<dependency>
<groupId>com.muyu.common</groupId>
<artifactId>saas-common</artifactId>
<version>3.6.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>saas-cache</artifactId>
<version>3.6.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>saas-cache</artifactId>
<version>3.6.3</version>
</dependency>
</dependencies>

View File

@ -0,0 +1,26 @@
package com.muyu.event.basic;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.context.ApplicationEvent;
/**
*
* @author
* @packagecom.muyu.event.Basic
* @nameEventCustom
* @date2024/9/29 21:17
*/
public class EventCustom extends ApplicationEvent {
private JSONObject data;
public EventCustom(Object source,JSONObject data) {
super(source);
this.data=data;
}
public JSONObject getData(){
return data;
}
}

View File

@ -0,0 +1,17 @@
package com.muyu.event.basic;
import org.springframework.context.ApplicationListener;
/**
*
* @author
* @packagecom.muyu.event.basic
* @nameEventListener
* @date2024/9/29 21:21
*/
public interface EventListener extends ApplicationListener<EventCustom> {
void onEvent(EventCustom event);
}

View File

@ -0,0 +1,31 @@
package com.muyu.event.basic;
import com.alibaba.fastjson2.JSONB;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;
/**
*
* @author
* @packagecom.muyu.event.basic
* @nameEventPublisher
* @date2024/9/29 22:01
*/
@Component
public class EventPublisher implements ApplicationEventPublisherAware {
private ApplicationEventPublisher publisher;
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
this.publisher=applicationEventPublisher;
}
public void publishEvent(JSONObject jsonObject){
EventCustom event = new EventCustom(this, jsonObject);
publisher.publishEvent(event);
}
}

View File

@ -1,25 +0,0 @@
package com.muyu.event.basics;
/**
* @author
* @package
* @nameEventHandler
* @date2024/9/29
*/
public class EventHandler {
private static final ThreadLocal<EventQueueConfig> EVENT_THREAD = new ThreadLocal<>();
public static void set(final EventQueueConfig handler) {
EVENT_THREAD.set(handler);
}
public static EventQueueConfig get() {
return EVENT_THREAD.get();
}
public static void remove(){
EVENT_THREAD.remove();
}
}

View File

@ -1,25 +0,0 @@
package com.muyu.event.basics;
public abstract class EventProcessBasics {
/**
*
*/
protected EventProcessBasics nextEvent;
/**
*
* @param nextHandler
*/
public void setNextHandler(EventProcessBasics nextHandler) {
this.nextEvent = nextHandler;
}
/**
*
* @param eventKey key
*/
public abstract void handleEvent(String eventKey);
}

View File

@ -1,35 +0,0 @@
package com.muyu.event.basics;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.concurrent.LinkedBlockingDeque;
/**
* @author
* @package
* @nameEventQueueConfig
* @date2024/9/29
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class EventQueueConfig {
private LinkedBlockingDeque<EventProcessBasics> taskNodeQueue = new LinkedBlockingDeque<>();
public void addEvent(EventProcessBasics obj){
this.taskNodeQueue.add(obj);
}
public boolean hashEventNext(){
return !taskNodeQueue.isEmpty();
}
private EventProcessBasics nextTaskNode(){
return taskNodeQueue.poll();
}
}

View File

@ -1,28 +0,0 @@
package com.muyu.event.basics;
import com.muyu.event.domian.EventActuate;
import org.springframework.context.ApplicationEvent;
import java.util.List;
/**
* @author
* @package
* @nameStartEvent
* @date2024/9/29
*/
public class StartEvent extends ApplicationEvent {
private EventActuate eventActuate;
public StartEvent(EventActuate source) {
super(source);
this.eventActuate = source;
}
public EventActuate getEventActuate() {
return eventActuate;
}
}

View File

@ -0,0 +1,23 @@
package com.muyu.event.config;
import com.muyu.event.listener.AddDatabaseListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author
* @packagecom.muyu.event.config
* @nameEventConfig
* @date2024/9/29 21:13
*/
@Configuration
public class EventConfig {
@Bean
public AddDatabaseListener addDatabaseListener() {
return new AddDatabaseListener();
}
}

View File

@ -66,9 +66,7 @@ public class IoTDBConfig {
measurements.add("car_vin");
measurements.add("information");
session.insertRecord(TABLENAME,System.currentTimeMillis(),measurements,list);
//关闭连接
session.close();
} catch (IoTDBConnectionException e) {

View File

@ -1,129 +0,0 @@
package com.muyu.event.config;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
import org.springframework.kafka.config.KafkaListenerContainerFactory;
import org.springframework.kafka.core.ConsumerFactory;
import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
import org.springframework.kafka.listener.ConcurrentMessageListenerContainer;
import org.springframework.kafka.listener.ContainerProperties;
import org.springframework.kafka.support.serializer.JsonDeserializer;
import java.util.HashMap;
import java.util.Map;
/**
* @author
* @date 2022/10/31 18:05
* kafkaymlyml
*/
@SpringBootConfiguration
public class KafkaConsumerConfig {
/**
* Kafka
*/
@Value("${spring.kafka.consumer.bootstrap-servers}")
private String bootstrapServers;
/**
*
*/
@Value("${spring.kafka.consumer.group-id}")
private String groupId;
/**
*
*/
@Value("${spring.kafka.consumer.enable-auto-commit}")
private boolean enableAutoCommit;
/**
* Kafka
*/
@Value("${spring.kafka.properties.session.timeout.ms}")
private String sessionTimeout;
/**
* poll5reBalance
*/
@Value("${spring.kafka.properties.max.poll.interval.ms}")
private String maxPollIntervalTime;
@Value("${spring.kafka.consumer.max-poll-records}")
private String maxPollRecords;
@Value("${spring.kafka.consumer.auto-offset-reset}")
private String autoOffsetReset;
@Value("${spring.kafka.listener.concurrency}")
private Integer concurrency;
@Value("${spring.kafka.listener.missing-topics-fatal}")
private boolean missingTopicsFatal;
@Value("${spring.kafka.listener.poll-timeout}")
private long pollTimeout;
@Bean
public Map<String, Object> consumerConfigs() {
Map<String, Object> propsMap = new HashMap<>(16);
propsMap.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
propsMap.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
//是否自动提交偏移量默认值是true为了避免出现重复数据和数据丢失可以把它设置为false然后手动提交偏移量
propsMap.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, enableAutoCommit);
//自动提交的时间间隔,自动提交开启时生效
propsMap.put(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG, "2000");
//该属性指定了消费者在读取一个没有偏移量的分区或者偏移量无效的情况下该作何处理:
//earliest当各分区下有已提交的offset时从提交的offset开始消费无提交的offset时从头开始消费分区的记录
//latest当各分区下有已提交的offset时从提交的offset开始消费无提交的offset时消费新产生的该分区下的数据在消费者启动之后生成的记录
//none当各分区都存在已提交的offset时从提交的offset开始消费只要有一个分区不存在已提交的offset则抛出异常
propsMap.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, autoOffsetReset);
//两次poll之间的最大间隔默认值为5分钟。如果超过这个间隔会触发reBalance
propsMap.put(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG, maxPollIntervalTime);
//这个参数定义了poll方法最多可以拉取多少条消息默认值为500。如果在拉取消息的时候新消息不足500条那有多少返回多少如果超过500条每次只返回500。
//这个默认值在有些场景下太大有些场景很难保证能够在5min内处理完500条消息
//如果消费者无法在5分钟内处理完500条消息的话就会触发reBalance,
//然后这批消息会被分配到另一个消费者中,还是会处理不完,这样这批消息就永远也处理不完。
//要避免出现上述问题提前评估好处理一条消息最长需要多少时间然后覆盖默认的max.poll.records参数
//注需要开启BatchListener批量监听才会生效如果不开启BatchListener则不会出现reBalance情况
propsMap.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, maxPollRecords);
//当broker多久没有收到consumer的心跳请求后就触发reBalance默认值是10s
propsMap.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, sessionTimeout);
//序列化建议使用Json这种序列化方式可以无需额外配置传输实体类
propsMap.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, JsonDeserializer.class);
propsMap.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, JsonDeserializer.class);
return propsMap;
}
@Bean
public ConsumerFactory<Object, Object> consumerFactory() {
// 配置消费者的 Json 反序列化的可信赖包,反序列化实体类需要
try (JsonDeserializer<Object> deserializer = new JsonDeserializer<>()) {
deserializer.trustedPackages("*");
return new DefaultKafkaConsumerFactory<>(consumerConfigs(), new JsonDeserializer<>(), deserializer);
}
}
/**
* kafka Kafka
* @return
*/
@Bean
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<Object, Object>> kafkaListenerContainerFactory() {
ConcurrentKafkaListenerContainerFactory<Object, Object> factory = new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory());
//在侦听器容器中运行的线程数,一般设置为 机器数*分区数
factory.setConcurrency(concurrency);
// 消费监听接口监听的主题不存在时默认会报错所以设置为false忽略错误
factory.setMissingTopicsFatal(missingTopicsFatal);
// 自动提交关闭,需要设置手动消息确认
factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL_IMMEDIATE);
factory.getContainerProperties().setPollTimeout(pollTimeout);
// 设置为批量监听需要用List接收
// factory.setBatchListener(true);
return factory;
}
}

View File

@ -1,127 +0,0 @@
package com.muyu.event.config;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.core.ProducerFactory;
import org.springframework.kafka.transaction.KafkaTransactionManager;
import java.util.HashMap;
import java.util.Map;
/**
*
*/
@Configuration
public class KafkaProviderConfig {
/**
* kafka
*/
@Value("${spring.kafka.producer.bootstrap-servers}")
private String bootstrapServers;
/**
* Kafka
*/
@Value("${spring.kafka.producer.transaction-id-prefix}")
private String transactionIdPrefix;
/**
*
*/
@Value("${spring.kafka.producer.acks}")
private String acks;
/**
*
*/
@Value("${spring.kafka.producer.retries}")
private String retries;
/**
*
*/
@Value("${spring.kafka.producer.batch-size}")
private String batchSize;
/**
*
*/
@Value("${spring.kafka.producer.buffer-memory}")
private String bufferMemory;
/**
*
*/
@Value("${spring.kafka.producer.key-serializer}")
private String keySerializer;
/**
*
*/
@Value("${spring.kafka.producer.value-serializer}")
private String valueSerializer;
/**
* map
* @return
*/
@Bean
public Map<String, Object> producerConfigs() {
Map<String, Object> props = new HashMap<>(16);
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
//acks=0 生产者在成功写入消息之前不会等待任何来自服务器的响应。
//acks=1 只要集群的首领节点收到消息,生产者就会收到一个来自服务器成功响应。
//acks=all :只有当所有参与复制的节点全部收到消息时,生产者才会收到一个来自服务器的成功响应。
//开启事务必须设为all
props.put(ProducerConfig.ACKS_CONFIG, acks);
//发生错误后消息重发的次数开启事务必须大于0
props.put(ProducerConfig.RETRIES_CONFIG, retries);
//当多个消息发送到相同分区时,生产者会将消息打包到一起,以减少请求交互. 而不是一条条发送
//批次的大小可以通过batch.size 参数设置.默认是16KB
//较小的批次大小有可能降低吞吐量批次大小为0则完全禁用批处理
//比如说kafka里的消息5秒钟Batch才凑满了16KB才能发送出去。那这些消息的延迟就是5秒钟
//实测batchSize这个参数没有用
props.put(ProducerConfig.BATCH_SIZE_CONFIG, batchSize);
//有的时刻消息比较少,过了很久,比如5min也没有凑够16KB,这样延时就很大,所以需要一个参数. 再设置一个时间,到了这个时间,
//即使数据没达到16KB,也将这个批次发送出去
props.put(ProducerConfig.LINGER_MS_CONFIG, "5000");
//生产者内存缓冲区的大小
props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, bufferMemory);
//反序列化,和生产者的序列化方式对应
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, keySerializer);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, valueSerializer);
return props;
}
/**
*
* @return
*/
@Bean
public ProducerFactory<Object, Object> producerFactory() {
DefaultKafkaProducerFactory<Object, Object> factory = new DefaultKafkaProducerFactory<>(producerConfigs());
//开启事务,会导致 LINGER_MS_CONFIG 配置失效
factory.setTransactionIdPrefix(transactionIdPrefix);
return factory;
}
/**
* Kafka
* @param producerFactory
* @return
*/
@Bean
public KafkaTransactionManager<Object, Object> kafkaTransactionManager(ProducerFactory<Object, Object> producerFactory) {
return new KafkaTransactionManager<>(producerFactory);
}
/**
* KafkaTemplate
* @return
*/
@Bean
public KafkaTemplate<Object, Object> kafkaTemplate() {
return new KafkaTemplate<>(producerFactory());
}
}

View File

@ -1,65 +0,0 @@
package com.muyu.event.config;
import jakarta.annotation.Nullable;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.support.ProducerListener;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@Component
public class KafkaSendResultHandler implements ProducerListener<Object,Object> {
@Autowired
private KafkaTemplate<Object,Object> kafkaTemplate;
/**
* bean
*/
@PostConstruct
public void init(){
this.kafkaTemplate.setProducerListener(this);
}
/**
* Kafka
* @param producerRecord
* @param recordMetadata
*/
@Override
public void onSuccess(ProducerRecord producerRecord, RecordMetadata recordMetadata){
System.out.println("信息发送成功:"+ producerRecord.toString());
}
/**
* Kafka
* @param producerRecord the failed record
* @param recordMetadata The metadata for the record that was sent (i.e. the partition
* and offset). If an error occurred, metadata will contain only valid topic and maybe
* the partition. If the partition is not provided in the ProducerRecord and an error
* occurs before partition is assigned, then the partition will be set to
* RecordMetadata.UNKNOWN_PARTITION.
* @param exception the exception thrown
*/
@Override
public void onError(ProducerRecord producerRecord, @Nullable RecordMetadata recordMetadata,
Exception exception){
System.out.println("消息发送失败: "+ producerRecord.toString());
}
}

View File

@ -1,34 +0,0 @@
package com.muyu.event.config;
import lombok.NonNull;
import org.apache.kafka.clients.consumer.Consumer;
import org.springframework.kafka.listener.KafkaListenerErrorHandler;
import org.springframework.kafka.listener.ListenerExecutionFailedException;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;
@Component
public class MyKafkaListenerErrorHandler implements KafkaListenerErrorHandler {
@Override
@NonNull
public Object handleError(@NonNull Message<?> message,
ListenerExecutionFailedException exception) {
return new Object();
}
@Override
@NonNull
public Object handleError(@NonNull Message<?> message,
@NonNull ListenerExecutionFailedException exception,
Consumer<?, ?> consumer) {
System.out.println("消息详情:"+ message);
System.out.println("异常信息:"+ exception);
System.out.println("消费者详情:" +consumer.groupMetadata());
System.out.println("监听主题:"+ consumer.listTopics());
return KafkaListenerErrorHandler.super.handleError(message, exception, consumer);
}
}

View File

@ -1,15 +0,0 @@
package com.muyu.event.constant;
/**
*
* @author
* @packagecom.muyu.event.constant
* @nameEventConstant
* @date2024/9/28 19:25
*/
public interface EventConstant {
String STORAGE_EVENT = "storageEvent";
}

View File

@ -1,31 +0,0 @@
package com.muyu.event.consumer;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
/**
* kafka
* @author
* @packagecom.muyu.event.consumer
* @nameKafkaConsumer
* @date2024/9/28 23:34
*/
public class KafkaConsumer {
@KafkaListener(topics = "data")
public void dataKafkaConsumer(ConsumerRecord<Object,Object> consumerRecord, Acknowledgment acknowledgment){
Object key = consumerRecord.key();
Object value = consumerRecord.value();
//事件调用
//消息确认消费
acknowledgment.acknowledge();
}
}

View File

@ -0,0 +1,57 @@
package com.muyu.event.consumer;
import com.alibaba.fastjson2.JSONObject;
import com.muyu.event.basic.EventPublisher;
import com.muyu.event.service.IncidentService;
import lombok.extern.log4j.Log4j2;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import java.time.Duration;
import java.util.Collections;
import java.util.List;
import static org.bouncycastle.asn1.x500.style.RFC4519Style.l;
/**
* kafka
* @author
* @packagecom.muyu.event.consumer
* @nameKafkaConsumer
* @date2024/9/28 23:34
*/
@Component
@Log4j2
public class MessageConsumer implements ApplicationRunner {
@Autowired
public KafkaConsumer consumer;
private EventPublisher eventPublisher;
private final String topic="kafka-topic";
@Autowired
private IncidentService incidentService;
@Override
public void run(ApplicationArguments args) throws Exception {
List<String> list = Collections.singletonList(topic);
consumer.subscribe(list);
while (true){
ConsumerRecords<String,String> consumerRecords = consumer.poll(Duration.ofMillis(100));
consumerRecords.forEach(record -> {
String value = record.value();
JSONObject jsonObject = JSONObject.parseObject(value);
log.info("value:{}",value);
eventPublisher.publishEvent(jsonObject);
try {
incidentService.warnEventProcess(jsonObject);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
}
}

View File

@ -0,0 +1,90 @@
package com.muyu.event.consumer;
import com.alibaba.fastjson2.JSONObject;
import com.muyu.cache.ElectronicFenceGroupCacheService;
import com.muyu.cache.SysCarCacheService;
import com.muyu.common.domain.database.ElectronicFenceGroup;
import com.muyu.common.domain.resp.SysCarVo;
import com.muyu.common.redis.service.RedisService;
import com.muyu.rabbitmq.consumer.RabbitMQConsumerUtil;
import com.rabbitmq.client.Channel;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.Date;
import java.util.List;
/**
* rabbitmq
* @author
* @packagecom.muyu.event.consumer
* @nameMqConsumer
* @date2024/10/2 14:17
*/
@Component
@Log4j2
public class MqConsumer {
@Autowired
private RedisService redisService;
@Autowired
private SysCarCacheService sysCarCacheService;
@Autowired
private ElectronicFenceGroupCacheService electronicFenceGroupCacheService;
@RabbitListener(queuesToDeclare = @Queue(name = "basic"))
public void rabbitMQBasicConsumer(String data , Message message , Channel channel) {
log.info("当前时间:{} RabbitMQConsumerUtil : {}", new Date(), message);
try {
// 获取到消息 开始消费
log.info("消息消费者接收到消息,消息内容:{}", JSONObject.toJSONString(data));
Long add = redisService.redisTemplate.opsForSet().add(data, message.getMessageProperties().getMessageId());
if (add != 1) {
return;
}
/**
* ---------------------------------------------------------------
*/
/**
* ------------------------------------------------------------------------------
*/
// 消费消息成功之后需要确认
// long deliveryTag 消息投递序号 自增的数字 在整个队列中唯一 拿到这个序号就相当于拿到这条消息
// boolean multiple 是否批量确认 true 批量 确认小于等于当前投递序号的消息 false 单个确认
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
log.info("xxx消费者接收到消息消息内容{},消费成功...", message);
} catch (Exception e) {
log.error("xxx消费者接收到消息消息内容{},消费消息异常,异常信息:{}", message, e);
// 消息回退 拒绝消费消息
// long deliveryTag 消息投递序号 自增的数字 在整个队列中唯一 拿到这个序号就相当于拿到这条消息
// boolean requeue 是否回到原来的队列
try {
channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
// channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true);
} catch (IOException ex) {
log.error("xxx消费者接收到消息消息内容{},回退消息异常,异常信息:{}", message, ex);
}
}finally {
try {
channel.close();
} catch (Exception e) {
log.error("xxx消费者关闭Channel异常消息内容{},异常信息:{}", message, e);
}
}
}
}

View File

@ -0,0 +1,23 @@
package com.muyu.event.consumer;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;
/**
* 线
* @author
* @packagecom.muyu.event.consumer
* @nameOnlineConsumer
* @date2024/9/30 11:40
*/
@Component
@Log4j2
public class OnlineConsumer {
}

View File

@ -0,0 +1,21 @@
package com.muyu.event.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
*
* @author
* @packagecom.muyu.event.controller
* @nameDataController
* @date2024/9/29 20:16
*/
@RestController
@RequestMapping("data")
public class DataController {
}

View File

@ -19,13 +19,12 @@ import java.util.List;
* @nameItodbController
* @date2024/9/28 19:17
*/
@RestController()
@RestController
public class IoTDBController {
@Autowired
private IoTDBService tdbService;
/**
*
* @return list
@ -47,7 +46,6 @@ public class IoTDBController {
return Result.success(carInformation);
};
/**
*
* @param addCarInformation
@ -59,16 +57,4 @@ public class IoTDBController {
return Result.success("添加成功");
};
}

View File

@ -0,0 +1,68 @@
package com.muyu.event.controller;
import com.alibaba.fastjson2.JSONObject;
import com.muyu.rabbitmq.producer.RabbitMQProducerUtil;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
*
* @author
* @packagecom.muyu.event.controller
* @nameTestController
* @date2024/9/29 20:58
*/
@RestController("test")
public class TestController {
@Resource
private KafkaProducer kafkaProducer;
@Resource
private RabbitMQProducerUtil rabbitMQProducerUtil;
private static final String topic="four_car";
@GetMapping("sendKafka")
public String sendKafka(){
String message="发送一条信息";
JSONObject jsonObject = new JSONObject();
jsonObject.put("cj","hh");
ProducerRecord<String, String> producerRecord = new ProducerRecord<String, String>(topic,jsonObject.toString());
kafkaProducer.send(producerRecord);
return "success";
}
@GetMapping("sendMq")
public String sendMq(){
String message="发送一条信息-mq";
rabbitMQProducerUtil.basicSendMessage("basic",message);
return "success-mq";
};
}

View File

@ -13,7 +13,13 @@ import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
*
* @author
* @packagecom.muyu.event.domain
* @nameEvent
* @date2024/9/28 23:10
*/
@Data
@AllArgsConstructor
@NoArgsConstructor

View File

@ -1,28 +0,0 @@
package com.muyu.event.domian;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import java.util.List;
/**
*
* @Author
* @Data 2024/9/29
*/
@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
public class EventActuate {
/**
* json
*/
private String jsonData;
/**
* key
*/
private List<String> eventKeys;
}

View File

@ -1,25 +0,0 @@
package com.muyu.event.eventDispose;
import com.muyu.event.basics.StartEvent;
import com.muyu.event.domian.EventActuate;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
/**
* @author
* @package
* @nameAutoStartupEventListener
* @date2024/9/29
*/
@Component
public class AutoStartupEventListener implements ApplicationListener<StartEvent> {
@Override
public void onApplicationEvent(StartEvent event) {
EventActuate eventActuate = event.getEventActuate();
}
}

View File

@ -1,37 +0,0 @@
package com.muyu.event.eventDispose;
import com.muyu.event.basics.EventProcessBasics;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.log4j.Log4j2;
/**
* @author
* @package
* @nameStorageEvent
* @date2024/9/29
*/
@EqualsAndHashCode(callSuper = true)
@Log4j2
@Data
@AllArgsConstructor
public class StorageEvent extends EventProcessBasics {
/**
*
*/
private String eventName;
@Override
public void handleEvent(String eventKey) {
if (eventKey.equals(eventName)){
log.info("开始执行 [{}] 事件", eventKey);
}else if (nextEvent != null){
nextEvent.handleEvent(eventKey);
}else {
log.info("处理结束,最后处理的事件为 [{}]", eventKey);
}
}
}

View File

@ -0,0 +1,34 @@
package com.muyu.event.listener;
import com.alibaba.fastjson2.JSONObject;
import com.muyu.event.basic.EventCustom;
import com.muyu.event.basic.EventListener;
import java.util.ArrayList;
import java.util.List;
/**
*
* @program: cloud-server
* @author: cuiyongxing
* @create: 2024-09-29 17:34
**/
public class AddDatabaseListener implements EventListener {
@Override
public void onEvent(EventCustom event) {
JSONObject jsonObject = event.getData();
List<String> keys = new ArrayList<>();
List<String> values = new ArrayList<>();
jsonObject.forEach((key, value) -> {
keys.add(key);
values.add((String) value);
});
}
@Override
public void onApplicationEvent(EventCustom event) {
onEvent(event);
}
}

View File

@ -0,0 +1,19 @@
package com.muyu.event.service;
/**
* @author
* @packagecom.muyu.event.service.impl
* @nameDataService
* @date2024/9/29 20:23
*/
public interface DataService {
void warnData(String data);
}

View File

@ -0,0 +1,17 @@
package com.muyu.event.service;
import com.alibaba.fastjson2.JSONObject;
/**
* @author liuxinyue
* @Packagecom.muyu.event.service
* @nameIncidentService
* @Date2024/10/9 15:02
*/
public interface IncidentService {
void warnEventProcess(JSONObject jsonObject) throws Exception;
void eventAlarmProcessing(JSONObject jsonObject) throws Exception;
}

View File

@ -0,0 +1,10 @@
package com.muyu.event.service;
/**
* @author
* @packagecom.muyu.event.service
* @nameTestService
* @date2024/9/29 20:59
*/
public interface TestService {
}

View File

@ -0,0 +1,26 @@
package com.muyu.event.service.impl;
import com.muyu.event.service.DataService;
import org.springframework.stereotype.Service;
/**
* @author
* @packagecom.muyu.event.service.impl
* @nameDataServiceImpl
* @date2024/9/29 20:24
*/
@Service
public class DataServiceImpl implements DataService {
@Override
public void warnData(String data) {
}
}

View File

@ -0,0 +1,178 @@
package com.muyu.event.service.impl;
import com.alibaba.fastjson2.JSONObject;
import com.muyu.cache.*;
import com.muyu.common.domain.MessageTemplateType;
import com.muyu.common.domain.SysCar;
import com.muyu.common.domain.SysCarFault;
import com.muyu.common.domain.resp.SysCarVo;
import com.muyu.common.domain.resp.WarnRuleResp;
import com.muyu.common.domain.resp.WarnStrategyResp;
import com.muyu.event.consumer.MessageConsumer;
import com.muyu.event.service.IncidentService;
import lombok.extern.log4j.Log4j2;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @author liuxinyue
* @Packagecom.muyu.event.service.impl
* @nameIncidentServiceImpl
* @Date2024/10/9 15:02
*/
@Log4j2
@Service
public class IncidentServiceImpl implements IncidentService {
private static int DURATION_SECONDS = 5;
private static List<JSONObject> receivedStrings = new ArrayList<>();
private static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
private static int elapsedSeconds = 0;
private static String file="elapsed";
private static List<MessageTemplateType> messageTemplateTypes=null;
private static Long msgTypeId=null;
//滑窗时间
private static Long slideTime=null;
//增长率
private static Long slideFrequency=null;
//预警策略
@Resource
private WarnStrategyCacheService warnStrategyCacheService;
//车辆
@Resource
private SysCarCacheService sysCarCacheService;
//预警规则
@Resource
private WarnRuleCacheService warnRuleCacheService;
//报文模版
@Resource
private MessageTemplateTypeCacheService messageTemplateTypeCacheService;
//kafka的主题名称
private final String topic="kafka-topic";
@Autowired
private SysCarFaultCacheService sysCarFaultCacheService;
@Override
public void warnEventProcess(JSONObject jsonObject) throws Exception {
receivedStrings.add(jsonObject);
//协议解析:每秒穿过来一个JSONObject jsonObject; 添加进receivedStrings
//根据这个车辆VIN查询出他对应的车辆类型
String carVin=null;
//报文模版的ID
Integer templateId=null;
//取出这辆车的carVin
for (JSONObject receivedString : receivedStrings) {
carVin = (String) receivedString.get("carVin");
}
//这辆车的信息
SysCar carByVin = null;
List<SysCarVo> carVoList = sysCarCacheService.get(sysCarCacheService.keyPre());
Map<String, SysCarVo> carMap = carVoList.stream()
.collect(Collectors.toMap(SysCarVo::getCarVin, Function.identity()));
//获取到了这个车辆的信息
carByVin = carMap.get(carVin);
//获取到这辆车绑定的报文模版
templateId=carByVin.getTemplateId();
//这个是这辆车对应的所有策略
List<WarnStrategyResp> carWithWarnStrategyList=null;
List<WarnStrategyResp> warnStrategyResps = warnStrategyCacheService.get(warnStrategyCacheService.keyPre());
for (WarnStrategyResp warnStrategyResp : warnStrategyResps) {
//策略中有绑定的车辆ID
if(warnStrategyResp.getCarTypeId()==carByVin.getCarTypeId()){
carWithWarnStrategyList.add(warnStrategyResp);
}
}
//该车对应的所有预警规则
List<WarnRuleResp> warnRuleResp=null;
List<WarnRuleResp> warnRuleResps = warnRuleCacheService.get(warnRuleCacheService.keyPre());
for (WarnStrategyResp warnStrategyResp : carWithWarnStrategyList) {
for (WarnRuleResp ruleResp : warnRuleResps) {
if(warnStrategyResp.getId().equals(ruleResp.getStrategyId())){
warnRuleResp.add(ruleResp);
}
}
}
//报文模版
messageTemplateTypes = messageTemplateTypeCacheService.get(messageTemplateTypeCacheService.keyPre());
for (WarnRuleResp ruleResp : warnRuleResp) {
//每一个规则他绑定了报文模版里面对应的一个配置 比如:电池,或者车速
msgTypeId = ruleResp.getMsgTypeId();
//将规则中对应的滑窗时间赋值为DURATION_SECONDS
DURATION_SECONDS = Math.toIntExact(ruleResp.getSlideTime());
slideFrequency = ruleResp.getSlideFrequency();
}
// 定义一个任务,每秒执行一次
Runnable task = new Runnable() {
@Override
public void run() {
// 清理超过的数据
cleanUpOldStrings();
// 检查超速条件
checkForSpeeding();
}
};
// 每隔1秒执行一次任务
scheduler.scheduleAtFixedRate(task, 0, 1, TimeUnit.SECONDS);
}
// 清理超过60秒的数据
private static void cleanUpOldStrings() {
long currentTime = System.currentTimeMillis();
receivedStrings.removeIf(jsonObject ->
currentTime - jsonObject.getLong("time") > TimeUnit.SECONDS.toMillis(DURATION_SECONDS)
);
}
// 检查是否有超速情况
private static void checkForSpeeding() {
if (receivedStrings.size() < 2) return; // 如果数据不足,直接返回
for (int i = 0; i < receivedStrings.size(); i++) {
JSONObject current = receivedStrings.get(i);
JSONObject next = receivedStrings.get(i + 1);
for (MessageTemplateType messageTemplateType : messageTemplateTypes) {
if(messageTemplateType.getMessageTemplateTypeId().equals(msgTypeId)){
Short currentElapsed = current.getShort(messageTemplateType.getMessageField());
Short nextElapsed = next.getShort(messageTemplateType.getMessageField());
if (nextElapsed > currentElapsed + slideFrequency) {
log.info("出错啦,出错啦,您的"+messageTemplateType.getMessageField()+"不正常,请检查!!!");
}
}
}
}
}
@Override
public void eventAlarmProcessing(JSONObject jsonObject) throws Exception {
String carVin = (String) jsonObject.get("carVin");
//车辆缓存配置
List<SysCarVo> carVoList = sysCarCacheService.get(sysCarCacheService.keyPre());
//这辆车的信息
SysCar carByVin = null;
Map<String, SysCarVo> carMap = carVoList.stream()
.collect(Collectors.toMap(SysCarVo::getCarVin, Function.identity()));
//获取到了这个车辆的信息
carByVin = carMap.get(carVin);
Long carTypeId = carByVin.getCarTypeId();
//车辆绑定的报警规则
List<SysCarFault> sysCarFaults = sysCarFaultCacheService.get(sysCarFaultCacheService.keyPre());
//车辆的所有报警规则都重新存储在sysCarFaultList里面
List<SysCarFault> sysCarFaultList=null;
SysCar finalCarByVin = carByVin;
sysCarFaults.forEach(sysCarFault -> {
if(sysCarFault.getCarTypeId().equals(carTypeId)){
sysCarFaultList.add(sysCarFault);
}
});
//报文模版
}
}

View File

@ -0,0 +1,20 @@
package com.muyu.event.service.impl;
import com.muyu.event.service.TestService;
import org.springframework.stereotype.Service;
/**
* @author
* @packagecom.muyu.event.service.impl
* @nameTestServiceImpl
* @date2024/9/29 21:00
*/
@Service
public class TestServiceImpl implements TestService {
}

View File

@ -0,0 +1,37 @@
package com.muyu.event.util;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.stereotype.Component;
/**
*
*
* @program: cloud-server
* @author:
* @create: 2024-09-30 10:08
**/
@Component
public class CacheUtil<T> {
private final Cache<String, T> cache;
public CacheUtil() {
this.cache = Caffeine.newBuilder()
.maximumSize(500L)
.build();
}
public T get(String key) {
return cache.getIfPresent(key);
}
public void put(String key, T value) {
cache.put(key, value);
}
public void remove(String key) {
cache.invalidate(key);
}
}

View File

@ -1,14 +1,16 @@
# Tomcat
server:
port: 10009
# nacos线上地址
nacos:
addr: 47.101.53.251:8848
user-name: nacos
password: nacos
namespace: four
namespace: lxy
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
# Spring
spring:
amqp:
deserialization:
trust:
@ -51,9 +53,8 @@ nacos:
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
# xxl-job 配置文件
- application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
# rabbit 配置文件
- application-rabbit-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
logging:
level:
com.muyu.fence.mapper: DEBUG
com.muyu.system.mapper: DEBUG

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.53.251:8848
user-name: nacos
password: nacos
namespace: four
namespace: lxy
# Spring
spring:

View File

@ -9,7 +9,7 @@ import org.springframework.stereotype.Service;
import java.util.List;
/**
*
*
*
* @author ruoyi
*/

View File

@ -40,7 +40,7 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
*
*
*
* @author ruoyi
*/

View File

@ -7,7 +7,7 @@ nacos:
addr: 47.101.53.251:8848
user-name: nacos
password: nacos
namespace: four
namespace: lxy
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
# Spring
spring:

View File

@ -78,6 +78,7 @@
<artifactId>cloud-common-xxl</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -10,10 +10,7 @@ import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.InnerAuth;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.SysDept;
import com.muyu.common.system.domain.SysRole;
import com.muyu.common.system.domain.SysUser;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.common.system.domain.*;
import com.muyu.system.domain.resp.AuthRoleResp;
import com.muyu.system.domain.resp.UserDetailInfoResp;
import com.muyu.system.domain.resp.UserInfoResp;
@ -136,6 +133,15 @@ public class SysUserController extends BaseController {
return Result.success(userService.registerUser(sysUser));
}
/**
*
*/
@InnerAuth
@PostMapping("/enterprise")
public Result<Boolean> enterprise (@RequestBody Business enterprise){
return Result.success(userService.enterprise(enterprise));
}
/**
*
*
@ -296,4 +302,11 @@ public class SysUserController extends BaseController {
public Result deptTree (SysDept dept) {
return success(deptService.selectDeptTreeList(dept));
}
@PostMapping("/addUser")
public Result<Integer> addUser(@RequestBody SysUser sysUser){
Integer i = userService.addUser(sysUser);
return Result.success(i);
}
}

View File

@ -1,6 +1,7 @@
package com.muyu.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.common.system.domain.Business;
import com.muyu.common.system.domain.SysUser;
import org.apache.ibatis.annotations.Param;
@ -66,6 +67,20 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
*/
int insertUser(SysUser user);
/**
*
* @param enterprise
* @return
*/
int enterprise(Business enterprise);
/**
*
* @param enterprise
* @return
*/
int enterPriseAdd(Business enterprise);
/**
*
*
@ -142,4 +157,9 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
List<SysUser> selectCompanyList();
Integer addUser(SysUser sysUser);
}

View File

@ -6,6 +6,7 @@ import com.muyu.system.domain.SysConfig;
import java.util.List;
/**
* plus
* @author DongZl
* @description: plus
* @Date 2023-11-13 10:06

View File

@ -7,7 +7,7 @@ import com.muyu.system.domain.vo.TreeSelect;
import java.util.List;
/**
*
*
*
* @author muyu
*/

View File

@ -1,6 +1,7 @@
package com.muyu.system.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.common.system.domain.Business;
import com.muyu.common.system.domain.SysUser;
import java.util.List;
@ -133,6 +134,7 @@ public interface SysUserService extends IService<SysUser> {
*/
boolean registerUser(SysUser user);
boolean enterprise(Business enterprise);
/**
*
*
@ -228,4 +230,6 @@ public interface SysUserService extends IService<SysUser> {
List<SysUser> selectCompanyList();
Integer addUser(SysUser sysUser);
}

View File

@ -18,6 +18,7 @@ import java.util.List;
import java.util.Objects;
/**
* plus
* @author DongZl
* @description: plus
* @Date 2023-11-13 10:06

View File

@ -8,6 +8,7 @@ import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.core.utils.bean.BeanValidators;
import com.muyu.common.datascope.annotation.DataScope;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.Business;
import com.muyu.common.system.domain.SysRole;
import com.muyu.common.system.domain.SysUser;
import com.muyu.system.domain.SysPost;
@ -257,6 +258,17 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
return userMapper.insertUser(user) > 0;
}
/**
*
* @param enterprise
* @return
*/
@Override
public boolean enterprise(Business enterprise){
userMapper.enterPriseAdd(enterprise);
return userMapper.enterprise(enterprise) > 0;
}
/**
*
*
@ -506,4 +518,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
return userMapper.selectCompanyList();
}
@Override
public Integer addUser(SysUser sysUser) {
return userMapper.addUser(sysUser);
}
}

View File

@ -24,6 +24,7 @@
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="remark" column="remark"/>
<result property="databaseName" column="database_name"/>
<association property="dept" javaType="com.muyu.common.system.domain.SysDept" resultMap="deptResult"/>
<collection property="roles" javaType="java.util.List" resultMap="RoleResult"/>
</resultMap>
@ -204,6 +205,7 @@
<if test="status != null and status != ''">status,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="databaseName !=null and databaseName!=''">database_name,</if>
create_time
)values(
<if test="userId != null and userId != ''">#{userId},</if>
@ -218,9 +220,22 @@
<if test="status != null and status != ''">#{status},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="databaseName!=null and databaseName!=''">#{databaseName}</if>
sysdate()
)
</insert>
<insert id="enterprise">
INSERT INTO `datasource`.`datasource` (`id`, `firm_name`, `database_name`) VALUES (NULL, #{firmName}, #{databaseName});
</insert>
<insert id="enterPriseAdd">
INSERT INTO `saas`.`tb_enterprise` (`enterprise_id`, `enterprise_name`, `enterprise_car_count`, `enterprise_fence_count`, `enterprise_database_name`)
VALUES (NULL, #{firmName}, 0, 0, #{databaseName});
</insert>
<insert id="addUser">
INSERT INTO `four`.`sys_user`
(`dept_id`, `user_name`, `nick_name`, `user_type`, `email`, `phonenumber`, `sex`, `avatar`, `password`, `status`, `del_flag`, `login_ip`, `login_date`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`, `database_name`)
VALUES ( 105, #{userName}, '若依', '00', 'ry@qq.com', '15666666666', '1', '', '$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2', '0', '0', '47.101.53.251', '2024-05-23 15:08:18', 'admin', #{createTime}, '', NULL, '测试员', #{databaseName});
</insert>
<update id="updateUser" parameterType="com.muyu.common.system.domain.SysUser">
update sys_user

View File

@ -0,0 +1,109 @@
<?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-modules</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>cloud-modules-template</artifactId>
<description>
cloud-modules-template 协议解析模块
</description>
<dependencies>
<!-- <dependency>-->
<!-- <groupId>com.muyu</groupId>-->
<!-- <artifactId>cloud-common-kafka</artifactId>-->
<!-- <version>3.6.3</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.muyu.server</groupId>
<artifactId>saas-server</artifactId>
<version>3.6.3</version>
</dependency>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos Config -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- SpringCloud Alibaba Sentinel -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- SpringBoot Actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Mysql Connector -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<!-- MuYu Common DataSource -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-datasource</artifactId>
</dependency>
<!-- MuYu Common DataScope -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-datascope</artifactId>
</dependency>
<!-- MuYu Common Log -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-log</artifactId>
</dependency>
<!-- 接口模块 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-api-doc</artifactId>
</dependency>
<!-- XllJob定时任务 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-xxl</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId> <!-- or lettuce -->
</dependency>
</dependencies>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -0,0 +1,19 @@
package com.muyu.template;
import com.muyu.common.security.annotation.EnableCustomConfig;
import com.muyu.common.security.annotation.EnableMyFeignClients;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author liuxinyue
* @Packagecom.muyu.template
* @nameCloudTemplateApplication
* @Date2024/9/30 10:36
*/
@EnableCustomConfig
@EnableMyFeignClients
@SpringBootApplication
public class CloudTemplateApplication {
public static void main(String[] args) {
SpringApplication.run(CloudTemplateApplication.class, args);
}
}

View File

@ -0,0 +1,170 @@
package com.muyu.template.config;
import cn.hutool.json.JSONObject;
import com.alibaba.fastjson2.JSON;
import com.muyu.cache.MessageTemplateCacheService;
import com.muyu.cache.MessageTemplateTypeCacheService;
import com.muyu.cache.SysCarCacheService;
import com.muyu.cache.TemplateCacheService;
import com.muyu.common.domain.MessageTemplate;
import com.muyu.common.domain.MessageTemplateType;
import com.muyu.common.domain.SysCar;
import com.muyu.common.domain.Template;
import com.muyu.common.domain.resp.SysCarVo;
import com.muyu.common.redis.service.RedisService;
import lombok.extern.log4j.Log4j2;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.eclipse.paho.client.mqttv3.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author liuxinyue
* @Packagecom.muyu.mqtt.configure
* @Projectcloud-server
* @nameMqttConfigure
* @Date2024/9/28 16:10
*/
@Log4j2
@Component
public class MqttConfigure {
@Autowired
private RedisService redisService;
@Autowired
private SysCarCacheService service;
@Autowired
private MessageTemplateCacheService messageTemplateCacheService;
@Autowired
private MessageTemplateTypeCacheService messageTemplateTypeCacheService;
@Autowired
private KafkaProducer kafkaProducer;
@PostConstruct
public void MQTTMonitoring(){
String topic = "car";
int qos = 2;
String broker = "tcp://47.101.53.251:1883";
String clientId = "lxy";
try {
MqttClient sampleClient = new MqttClient(broker, clientId);
MqttConnectOptions connOpts = new MqttConnectOptions();
//是否清空session
connOpts.setCleanSession(false);
log.info("Connecting to broker: " + broker);
//连接
sampleClient.connect(connOpts);
sampleClient.subscribe(topic,0);
sampleClient.setCallback(new MqttCallback() {
//连接丢失(报错)
@Override
public void connectionLost(Throwable throwable) {
log.error("error:"+throwable.getMessage());
}
//消息已经接收到
@Override
public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
// 将MQTT消息转换为字符串
String messageContent = new String(mqttMessage.getPayload());
// 解析JSON字符串
JSONObject jsonObject = new JSONObject(messageContent);
// 从JSON对象中获取"msg"字段的值
String msgValue = jsonObject.getStr("msg");
log.info("接收到的报文为:"+msgValue);
messageParsing(msgValue);
}
//交付完成
@Override
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
}
});
} catch(MqttException me) {
System.out.println("reason "+me.getReasonCode());
System.out.println("msg "+me.getMessage());
System.out.println("loc "+me.getLocalizedMessage());
System.out.println("cause "+me.getCause());
System.out.println("excep "+me);
me.printStackTrace();
}
}
public JSONObject messageParsing(String templateMessage) {
//给一个JSON对象
JSONObject jsonObject = new JSONObject();
//先截取出VIN码 然后根据VIN码查询这个车属于什么类型
if (templateMessage.length() < 18) {
throw new RuntimeException("The vehicle message is incorrect");
}
//将 templateMessage 按空格切割成多个字符串,得到一个字符串数组 hexArray。接着
// 将每个十六进制字符串转换成十进制整数,然后再转换为字符,最后将所有字符拼接成一个完整的字符串 result。
String[] hexArray = templateMessage.split(" ");
StringBuilder result = new StringBuilder();
for (String hex : hexArray) {
int decimal = Integer.parseInt(hex, 16);
result.append((char) decimal);
}
//取出VIN码
String carVin = result.substring(1, 18 );
log.info("carVin码为:" + carVin);
//根据VIN码获取车辆信息
SysCar carByVin = null;
List<SysCarVo> carList = service.get("carList");
if(carList==null){
throw new RuntimeException("Redis未获取到车辆数据!!!");
}else{
// 使用 HashMap 存储车信息,以 VIN 作为键
Map<String, SysCarVo> carMap = carList.stream()
.collect(Collectors.toMap(SysCarVo::getCarVin, Function.identity()));
carByVin = carMap.get(carVin);
}
log.info("车辆信息为:" + carByVin);
//对应车辆所对应的报文模版
Integer templateId = carByVin.getTemplateId();
List<MessageTemplateType> messageTemplateTypes=null;
String redisKey = "messageTemplateTypeList";
//key存在
Boolean b = redisService.hasKey(redisKey);
if (b) {
messageTemplateTypes = messageTemplateTypeCacheService.get(redisKey);
}else{
throw new RuntimeException("请先将配置存入Redis!!!");
}
//将模版里面有的配置进行循环
for (MessageTemplateType messageTemplateType : messageTemplateTypes) {
//开始位置
Integer startIndex = messageTemplateType.getStartIndex() - 1;
//结束位置
Integer endIndex = messageTemplateType.getEndIndex();
//将每个解析后的字段都存入到JSON对象中
jsonObject.put(messageTemplateType.getMessageField(), result.substring(startIndex, endIndex));
}
log.info("解析后的报文是:" + jsonObject);
sendKafka(jsonObject);
log.info("发送kafka成功");
return jsonObject;
}
//kafka发送消息
public void sendKafka(JSONObject jsonObject){
ProducerRecord<String, String> stringStringProducerRecord = new ProducerRecord<>("four_car", jsonObject.toString());
kafkaProducer.send(stringStringProducerRecord);
log.info("kafka发送成功");
}
}

View File

@ -0,0 +1,135 @@
package com.muyu.template;
import cn.hutool.json.JSONObject;
import com.muyu.cache.MessageTemplateTypeCacheService;
import com.muyu.cache.SysCarCacheService;
import com.muyu.cache.WarnRuleCacheService;
import com.muyu.cache.WarnStrategyCacheService;
import com.muyu.common.domain.MessageTemplateType;
import com.muyu.common.domain.SysCar;
import com.muyu.common.domain.resp.SysCarVo;
import com.muyu.common.domain.resp.WarnRuleResp;
import com.muyu.common.domain.resp.WarnStrategyResp;
import lombok.extern.log4j.Log4j2;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @author liuxinyue
* @Packagecom.muyu.template
* @nametest2
* @Date2024/10/6 10:34
*/
@Log4j2
public class test {
private static int DURATION_SECONDS = 5;
private static List<JSONObject> receivedStrings = new ArrayList<>();
private static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
private static int elapsedSeconds = 0;
private static String file="elapsed";
private static List<MessageTemplateType> messageTemplateTypes=null;
private static Long msgTypeId=null;
//滑窗时间
private static Long slideTime=null;
//增长率
private static Long slideFrequency=null;
//预警策略
@Resource
private WarnStrategyCacheService warnStrategyCacheService;
//车辆
@Resource
private SysCarCacheService sysCarCacheService;
//预警规则
@Resource
private WarnRuleCacheService warnRuleCacheService;
//报文模版
@Resource
private MessageTemplateTypeCacheService messageTemplateTypeCacheService;
public void main(String[] args) {
//协议解析:每秒穿过来一个JSONObject jsonObject; 添加进receivedStrings
//根据这个车辆VIN查询出他对应的车辆类型
String carVin=null;
//报文模版的ID
Integer templateId=null;
for (JSONObject receivedString : receivedStrings) {
carVin = receivedString.getStr("carVin");
}
SysCar carByVin = null;
List<SysCarVo> carVoList = sysCarCacheService.get(sysCarCacheService.keyPre());
Map<String, SysCarVo> carMap = carVoList.stream()
.collect(Collectors.toMap(SysCarVo::getCarVin, Function.identity()));
//获取到了这个车辆的信息
carByVin = carMap.get(carVin);
//获取到这辆车绑定的报文模版
templateId=carByVin.getTemplateId();
//这个是这辆车对应的所有策略
List<WarnStrategyResp> carWithWarnStrategyList=null;
List<WarnStrategyResp> warnStrategyResps = warnStrategyCacheService.get(warnStrategyCacheService.keyPre());
for (WarnStrategyResp warnStrategyResp : warnStrategyResps) {
if(warnStrategyResp.getCarTypeId()==carByVin.getCarTypeId()){
carWithWarnStrategyList.add(warnStrategyResp);
}
}
//该车对应的所有预警规则
List<WarnRuleResp> warnRuleResp=null;
List<WarnRuleResp> warnRuleResps = warnRuleCacheService.get(warnRuleCacheService.keyPre());
for (WarnStrategyResp warnStrategyResp : carWithWarnStrategyList) {
for (WarnRuleResp ruleResp : warnRuleResps) {
if(warnStrategyResp.getId().equals(ruleResp.getStrategyId())){
warnRuleResp.add(ruleResp);
}
}
}
//报文模版
messageTemplateTypes = messageTemplateTypeCacheService.get(messageTemplateTypeCacheService.keyPre());
for (WarnRuleResp ruleResp : warnRuleResp) {
//每一个规则他绑定了报文模版里面对应的一个配置 比如:电池,或者车速
msgTypeId = ruleResp.getMsgTypeId();
//将规则中对应的滑窗时间赋值为DURATION_SECONDS
DURATION_SECONDS = Math.toIntExact(ruleResp.getSlideTime());
slideFrequency = ruleResp.getSlideFrequency();
}
// 定义一个任务,每秒执行一次
Runnable task = new Runnable() {
@Override
public void run() {
// 清理超过的数据
cleanUpOldStrings();
// 检查超速条件
checkForSpeeding();
}
};
// 每隔1秒执行一次任务
scheduler.scheduleAtFixedRate(task, 0, 1, TimeUnit.SECONDS);
}
// 清理超过60秒的数据
private static void cleanUpOldStrings() {
long currentTime = System.currentTimeMillis();
receivedStrings.removeIf(jsonObject ->
currentTime - jsonObject.getLong("time") > TimeUnit.SECONDS.toMillis(DURATION_SECONDS)
);
}
// 检查是否有超速情况
private static void checkForSpeeding() {
if (receivedStrings.size() < 2) return; // 如果数据不足,直接返回
for (int i = 0; i < receivedStrings.size(); i++) {
JSONObject current = receivedStrings.get(i);
JSONObject next = receivedStrings.get(i + 1);
for (MessageTemplateType messageTemplateType : messageTemplateTypes) {
if(messageTemplateType.getMessageTemplateTypeId().equals(msgTypeId)){
Short currentElapsed = current.getShort(messageTemplateType.getMessageField());
Short nextElapsed = next.getShort(messageTemplateType.getMessageField());
if (nextElapsed > currentElapsed + slideFrequency) {
log.info("出错啦,出错啦,您的"+messageTemplateType.getMessageField()+"不正常,请检查!!!");
}
}
}
}
}
}

View File

@ -0,0 +1,2 @@
Spring Boot Version: ${spring-boot.version}
Spring Application Name: ${spring.application.name}

View File

@ -0,0 +1,62 @@
# Tomcat
server:
port: 15277
# nacos线上地址
nacos:
addr: 47.101.53.251:8848
user-name: nacos
password: nacos
namespace: lxy
# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
# Spring
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
amqp:
deserialization:
trust:
all: true
main:
allow-bean-definition-overriding: true
application:
# 应用名称
name: cloud-template
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: ${nacos.addr}
# nacos用户名
username: ${nacos.user-name}
# nacos密码
password: ${nacos.password}
# 命名空间
namespace: ${nacos.namespace}
config:
# 服务注册地址
server-addr: ${nacos.addr}
# nacos用户名
username: ${nacos.user-name}
# nacos密码
password: ${nacos.password}
# 命名空间
namespace: ${nacos.namespace}
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
# 系统共享配置
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
# 系统环境Config共享配置
- application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
# xxl-job 配置文件
- application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
logging:
level:
com.muyu.system.mapper: DEBUG

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!-- 日志存放路径 -->
<property name="log.path" value="logs/cloud-saas"/>
<!-- 日志输出格式 -->
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
<!-- 控制台输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
</appender>
<!-- 系统日志输出 -->
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/info.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>INFO</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/error.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>ERROR</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 系统模块日志级别控制 -->
<logger name="com.muyu" level="info"/>
<!-- Spring日志级别控制 -->
<logger name="org.springframework" level="warn"/>
<root level="info">
<appender-ref ref="console"/>
</root>
<!--系统操作日志-->
<root level="info">
<appender-ref ref="file_info"/>
<appender-ref ref="file_error"/>
</root>
</configuration>

View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!-- 日志存放路径 -->
<property name="log.path" value="logs/cloud-saas"/>
<!-- 日志输出格式 -->
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
<!-- 控制台输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.sky.pattern}</pattern>
</encoder>
</appender>
<!-- 系统日志输出 -->
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/info.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>INFO</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/error.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>ERROR</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 使用gRpc将日志发送到skywalking服务端 -->
<appender name="GRPC_LOG" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
<Pattern>${log.sky.pattern}</Pattern>
</layout>
</encoder>
</appender>
<!-- 系统模块日志级别控制 -->
<logger name="com.muyu" level="info"/>
<!-- Spring日志级别控制 -->
<logger name="org.springframework" level="warn"/>
<root level="info">
<appender-ref ref="GRPC_LOG"/>
<appender-ref ref="console"/>
</root>
<!--系统操作日志-->
<root level="info">
<appender-ref ref="file_info"/>
<appender-ref ref="file_error"/>
</root>
</configuration>

View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<!-- 日志存放路径 -->
<property name="log.path" value="logs/cloud-saas"/>
<!-- 日志输出格式 -->
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
<property name="log.sky.pattern" value="%d{HH:mm:ss.SSS} %yellow([%tid]) [%thread] %-5level %logger{20} - [%method,%line] - %msg%n"/>
<!-- 控制台输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.sky.pattern}</pattern>
</encoder>
</appender>
<!-- 系统日志输出 -->
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/info.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/info.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>INFO</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/error.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/error.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>ERROR</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 使用gRpc将日志发送到skywalking服务端 -->
<appender name="GRPC_LOG" class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.log.GRPCLogClientAppender">
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
<Pattern>${log.sky.pattern}</Pattern>
</layout>
</encoder>
</appender>
<!-- 系统模块日志级别控制 -->
<logger name="com.muyu" level="info"/>
<!-- Spring日志级别控制 -->
<logger name="org.springframework" level="warn"/>
<root level="info">
<appender-ref ref="GRPC_LOG"/>
<appender-ref ref="console"/>
</root>
<!--系统操作日志-->
<root level="info">
<appender-ref ref="file_info"/>
<appender-ref ref="file_error"/>
</root>
</configuration>

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