diff --git a/cloud-auth/pom.xml b/cloud-auth/pom.xml index 0a76aae..4cd0756 100644 --- a/cloud-auth/pom.xml +++ b/cloud-auth/pom.xml @@ -16,6 +16,8 @@ + + com.alibaba.cloud @@ -57,6 +59,19 @@ com.muyu cloud-common-api-doc + + com.mysql + mysql-connector-j + + + + com.muyu + cloud-common-saas + + + cn.hutool + hutool-all + diff --git a/cloud-auth/src/main/java/com/muyu/auth/controller/TokenController.java b/cloud-auth/src/main/java/com/muyu/auth/controller/TokenController.java index d870762..3b5b745 100644 --- a/cloud-auth/src/main/java/com/muyu/auth/controller/TokenController.java +++ b/cloud-auth/src/main/java/com/muyu/auth/controller/TokenController.java @@ -1,8 +1,12 @@ 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.domain.Result; import com.muyu.common.core.utils.JwtUtils; import com.muyu.common.core.utils.StringUtils; @@ -10,7 +14,11 @@ 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 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,11 +26,17 @@ 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; + /** * token 控制 * * @author muyu */ +@Log4j2 @RestController public class TokenController { @Autowired @@ -31,8 +45,16 @@ public class TokenController { @Autowired private SysLoginService sysLoginService; + @Autowired + private SysFirmService sysFirmService; + @PostMapping("login") 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 @@ -69,4 +91,51 @@ public class TokenController { sysLoginService.register(registerBody.getUsername(), registerBody.getPassword()); return Result.success(); } + + /** + * 企业入入驻 + * @param settlement + * @return + */ + @PostMapping("/enterprise") + 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()); + + // 切换到新的数据库连接 + 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("static/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(); + } } diff --git a/cloud-auth/src/main/java/com/muyu/auth/form/EnterpriseSettlement.java b/cloud-auth/src/main/java/com/muyu/auth/form/EnterpriseSettlement.java new file mode 100644 index 0000000..5696a6a --- /dev/null +++ b/cloud-auth/src/main/java/com/muyu/auth/form/EnterpriseSettlement.java @@ -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; + +} diff --git a/cloud-auth/src/main/java/com/muyu/auth/form/Firm.java b/cloud-auth/src/main/java/com/muyu/auth/form/Firm.java new file mode 100644 index 0000000..0ddc387 --- /dev/null +++ b/cloud-auth/src/main/java/com/muyu/auth/form/Firm.java @@ -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; + +} diff --git a/cloud-auth/src/main/java/com/muyu/auth/form/LoginBody.java b/cloud-auth/src/main/java/com/muyu/auth/form/LoginBody.java index 354122e..7701310 100644 --- a/cloud-auth/src/main/java/com/muyu/auth/form/LoginBody.java +++ b/cloud-auth/src/main/java/com/muyu/auth/form/LoginBody.java @@ -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; - } } diff --git a/cloud-auth/src/main/java/com/muyu/auth/service/SysFirmService.java b/cloud-auth/src/main/java/com/muyu/auth/service/SysFirmService.java new file mode 100644 index 0000000..8ac333c --- /dev/null +++ b/cloud-auth/src/main/java/com/muyu/auth/service/SysFirmService.java @@ -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; + }; +} diff --git a/cloud-auth/src/main/java/com/muyu/auth/service/SysLoginService.java b/cloud-auth/src/main/java/com/muyu/auth/service/SysLoginService.java index ff0af1a..7305c98 100644 --- a/cloud-auth/src/main/java/com/muyu/auth/service/SysLoginService.java +++ b/cloud-auth/src/main/java/com/muyu/auth/service/SysLoginService.java @@ -1,5 +1,6 @@ package com.muyu.auth.service; +import com.muyu.auth.form.EnterpriseSettlement; import com.muyu.common.core.constant.CacheConstants; import com.muyu.common.core.constant.Constants; import com.muyu.common.core.constant.SecurityConstants; @@ -12,6 +13,7 @@ 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.domain.Enterprise; import com.muyu.common.system.remote.RemoteUserService; import com.muyu.common.system.domain.SysUser; import com.muyu.common.system.domain.LoginUser; @@ -124,4 +126,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个字符之间"); + } + Enterprise settlement = new Enterprise(); + settlement.setDatabaseName(databaseName); + settlement.setFirmName(fileName); + + remoteUserService.settlementEnterpriseInfo(settlement, SecurityConstants.INNER); + + } } diff --git a/cloud-auth/src/main/resources/bootstrap.yml b/cloud-auth/src/main/resources/bootstrap.yml index fdf3847..57dca73 100644 --- a/cloud-auth/src/main/resources/bootstrap.yml +++ b/cloud-auth/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 47.101.53.251:8848 user-name: nacos password: nacos - namespace: four + namespace: yzl # Spring spring: application: diff --git a/cloud-auth/src/main/resources/static/saas.sql b/cloud-auth/src/main/resources/static/saas.sql new file mode 100644 index 0000000..ba9d697 --- /dev/null +++ b/cloud-auth/src/main/resources/static/saas.sql @@ -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; diff --git a/cloud-common/cloud-common-cache/src/main/java/com/muyu/cache/CacheAbsBasic.java b/cloud-common/cloud-common-cache/src/main/java/com/muyu/cache/CacheAbsBasic.java index bc3a38c..286c20e 100644 --- a/cloud-common/cloud-common-cache/src/main/java/com/muyu/cache/CacheAbsBasic.java +++ b/cloud-common/cloud-common-cache/src/main/java/com/muyu/cache/CacheAbsBasic.java @@ -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 implements CacheBasic{ @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 diff --git a/cloud-common/cloud-common-cache/src/main/java/com/muyu/cache/CacheBasic.java b/cloud-common/cloud-common-cache/src/main/java/com/muyu/cache/CacheBasic.java index 11ed9d5..4b2191c 100644 --- a/cloud-common/cloud-common-cache/src/main/java/com/muyu/cache/CacheBasic.java +++ b/cloud-common/cloud-common-cache/src/main/java/com/muyu/cache/CacheBasic.java @@ -1,5 +1,7 @@ package com.muyu.cache; +import java.util.List; + /** * @author yuping * @package com.muyu.cache diff --git a/cloud-common/cloud-common-core/pom.xml b/cloud-common/cloud-common-core/pom.xml index 7cd55ff..9d4b3c5 100644 --- a/cloud-common/cloud-common-core/pom.xml +++ b/cloud-common/cloud-common-core/pom.xml @@ -138,10 +138,10 @@ - - - - + + + + javax.annotation diff --git a/cloud-common/cloud-common-core/src/main/java/com/muyu/common/core/constant/KafkaConstant.java b/cloud-common/cloud-common-core/src/main/java/com/muyu/common/core/constant/KafkaConstant.java new file mode 100644 index 0000000..53d4c2c --- /dev/null +++ b/cloud-common/cloud-common-core/src/main/java/com/muyu/common/core/constant/KafkaConstant.java @@ -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"; + + + +} diff --git a/cloud-common/cloud-common-core/src/main/java/com/muyu/common/core/constant/UserConstants.java b/cloud-common/cloud-common-core/src/main/java/com/muyu/common/core/constant/UserConstants.java index 0df401c..9e0d6a9 100644 --- a/cloud-common/cloud-common-core/src/main/java/com/muyu/common/core/constant/UserConstants.java +++ b/cloud-common/cloud-common-core/src/main/java/com/muyu/common/core/constant/UserConstants.java @@ -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; } diff --git a/cloud-common/cloud-common-kafka/pom.xml b/cloud-common/cloud-common-kafka/pom.xml new file mode 100644 index 0000000..abe86fc --- /dev/null +++ b/cloud-common/cloud-common-kafka/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + com.muyu + cloud-common + 3.6.3 + + + cloud-common-kafka + + cloud-common-kafka消息队列 + + + 17 + 17 + UTF-8 + + + + + + + + + + org.apache.kafka + kafka-clients + + + com.muyu + cloud-common-core + + + + + + + diff --git a/cloud-common/cloud-common-kafka/src/main/java/com/muyu/common/kafka/config/KafkaConsumerConfig.java b/cloud-common/cloud-common-kafka/src/main/java/com/muyu/common/kafka/config/KafkaConsumerConfig.java new file mode 100644 index 0000000..3eba063 --- /dev/null +++ b/cloud-common/cloud-common-kafka/src/main/java/com/muyu/common/kafka/config/KafkaConsumerConfig.java @@ -0,0 +1,96 @@ +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 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); + } + +} diff --git a/cloud-common/cloud-common-kafka/src/main/java/com/muyu/common/kafka/config/KafkaProducerConfig.java b/cloud-common/cloud-common-kafka/src/main/java/com/muyu/common/kafka/config/KafkaProducerConfig.java new file mode 100644 index 0000000..becdcda --- /dev/null +++ b/cloud-common/cloud-common-kafka/src/main/java/com/muyu/common/kafka/config/KafkaProducerConfig.java @@ -0,0 +1,68 @@ +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 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; + } + +} diff --git a/cloud-common/cloud-common-kafka/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/cloud-common/cloud-common-kafka/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000..e87908e --- /dev/null +++ b/cloud-common/cloud-common-kafka/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1,2 @@ +com.muyu.common.kafka.config.KafkaConsumerConfig +com.muyu.common.kafka.config.KafkaProducerConfig diff --git a/cloud-common/cloud-common-rabbit/pom.xml b/cloud-common/cloud-common-rabbit/pom.xml index fa6d383..79f5225 100644 --- a/cloud-common/cloud-common-rabbit/pom.xml +++ b/cloud-common/cloud-common-rabbit/pom.xml @@ -17,6 +17,10 @@ UTF-8 + + cloud-common-rabbit 消息队列服务 + + @@ -28,8 +32,8 @@ com.muyu - cloud-common-core + cloud-common-redis - \ No newline at end of file + diff --git a/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/RabbitListenerConfigurer.java b/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/RabbitListenerConfigurer.java deleted file mode 100644 index 51cb359..0000000 --- a/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/RabbitListenerConfigurer.java +++ /dev/null @@ -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()); - } - -} - diff --git a/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/config/DelayedQueueConfig.java b/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/config/DelayedQueueConfig.java new file mode 100644 index 0000000..0b67d49 --- /dev/null +++ b/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/config/DelayedQueueConfig.java @@ -0,0 +1,83 @@ +package com.muyu.common.rabbit.config; + + +import com.muyu.common.rabbit.constants.RabbitmqConstants; +import org.springframework.amqp.core.*; +import org.springframework.amqp.rabbit.core.RabbitAdmin; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.annotation.Resource; +import java.util.HashMap; + +/** + * @ClassName: DelayedQueueConfig + * @Description: 延迟队列配置类 + */ +@Configuration +public class DelayedQueueConfig { + + + @Resource + private RabbitAdmin rabbitAdmin; + + /** + * 声明队列 + * @return 返回队列 + */ + @Bean + public Queue delayedQueue() { + Queue queue = new Queue(RabbitmqConstants.DELAYED_QUEUE_NAME); + rabbitAdmin.declareQueue(queue); + return queue; + } + + /** + * 声明交换机 + * @return 返回交换机 + */ + @Bean + public Exchange delayedExchange() { + HashMap arguments = new HashMap<>(3); + + arguments.put("x-delayed-type", "direct"); + + /** + * 声明自定义交换机 + * 第一个参数:交换机的名称 + * 第二个参数:交换机的类型 + * 第三个参数:是否需要持久化 + * 第四个参数:是否自动删除 + * 第五个参数:其他参数 + */ + CustomExchange customExchange = new CustomExchange( + RabbitmqConstants.DELAYED_EXCHANGE_NAME, + "x-delayed-message", + true, + false, + arguments); + rabbitAdmin.declareExchange(customExchange); + return customExchange; + } + + /** + * 绑定交换机 + * @param delayedQueue 队列对象 + * @param delayedExchange 交换机对象 + */ + @Bean + public Binding delayedQueueBindingDelayedExchange( + @Qualifier("delayedQueue") Queue delayedQueue, + @Qualifier("delayedExchange") Exchange delayedExchange) { + + Binding noargs = BindingBuilder.bind(delayedQueue) + .to(delayedExchange) + .with(RabbitmqConstants.DELAYED_ROUTING_KEY) + .noargs(); + rabbitAdmin.declareBinding(noargs); + return noargs; + } + + +} diff --git a/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/config/MyConfirmCallback.java b/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/config/MyConfirmCallback.java new file mode 100644 index 0000000..2b40812 --- /dev/null +++ b/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/config/MyConfirmCallback.java @@ -0,0 +1,47 @@ +package com.muyu.common.rabbit.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); + } + } +} diff --git a/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/config/RabbitAdminConfig.java b/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/config/RabbitAdminConfig.java new file mode 100644 index 0000000..27b24c5 --- /dev/null +++ b/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/config/RabbitAdminConfig.java @@ -0,0 +1,49 @@ +package com.muyu.common.rabbit.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.virtualhost}") + private String virtualHost; + + @Bean + public ConnectionFactory connectionFactory() { + CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(); + cachingConnectionFactory.setHost(host); + cachingConnectionFactory.setUsername(username); + cachingConnectionFactory.setPassword(password); + cachingConnectionFactory.setVirtualHost(virtualHost); + return cachingConnectionFactory; + + } + + @Bean + public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) { + RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory); + rabbitAdmin.setAutoStartup(true); + return rabbitAdmin; + } + +} + + + + diff --git a/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/config/RabbitmqConfig.java b/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/config/RabbitmqConfig.java new file mode 100644 index 0000000..9814d1b --- /dev/null +++ b/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/config/RabbitmqConfig.java @@ -0,0 +1,20 @@ +package com.muyu.common.rabbit.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(); + } +} diff --git a/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/config/ReturnCallbackConfig.java b/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/config/ReturnCallbackConfig.java new file mode 100644 index 0000000..212e2fd --- /dev/null +++ b/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/config/ReturnCallbackConfig.java @@ -0,0 +1,37 @@ +package com.muyu.common.rabbit.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()); + // 回退了所有的信息,可做补偿机制 记录发送的日志 + } +} diff --git a/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/config/TopicConfig.java b/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/config/TopicConfig.java new file mode 100644 index 0000000..58d717b --- /dev/null +++ b/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/config/TopicConfig.java @@ -0,0 +1,75 @@ +package com.muyu.common.rabbit.config; + +import org.springframework.amqp.core.*; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @Author: WangXin + * @Time: 2024/4/22 11:55 + * @Description: 主题模式配置 + */ +@Configuration +public class TopicConfig { + + /** + * 主题模式交换机 + * @return exchange + */ + @Bean(name = "topicExchange") + public Exchange getTopicExchange(){ + return ExchangeBuilder + .topicExchange("exchange_topic") + .build(); + } + + /** + * 主题队列 01 + * @return queue + */ + @Bean(name = "topicQueue01") + public Queue getTopicQueue01(){ + return QueueBuilder + .durable("queue_topic_01") + .build(); + } + + /** + * 主题队列 02 + * @return queue + */ + @Bean(name = "topicQueue02") + public Queue getTopicQueue02(){ + return QueueBuilder + .durable("queue_topic_02") + .build(); + } + + /** + * 绑定队列 01 + * @return binding + */ + @Bean + public Binding getTopicBinding01(){ + return BindingBuilder + .bind(getTopicQueue01()) + .to(getTopicExchange()) + //路由键 队列1接收debug级别的消息 + .with("front.#") + .noargs(); + } + + /** + * 绑定队列 02 + * @return binding + */ + @Bean + public Binding getTopicBinding02(){ + return BindingBuilder + .bind(getTopicQueue02()) + .to(getTopicExchange()) + // 路由键 队列2接收info级别的消息 + .with("back.order.*") + .noargs(); + } +} diff --git a/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/constants/RabbitmqConstants.java b/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/constants/RabbitmqConstants.java new file mode 100644 index 0000000..45495ab --- /dev/null +++ b/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/constants/RabbitmqConstants.java @@ -0,0 +1,35 @@ +package com.muyu.common.rabbit.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"; +} diff --git a/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/consumer/RabbitMQConsumerUtil.java b/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/consumer/RabbitMQConsumerUtil.java new file mode 100644 index 0000000..876453d --- /dev/null +++ b/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/consumer/RabbitMQConsumerUtil.java @@ -0,0 +1,128 @@ +package com.muyu.common.rabbit.consumer; + +import com.alibaba.fastjson2.JSONObject; +import com.muyu.common.redis.service.RedisService; +import com.rabbitmq.client.Channel; +import lombok.AllArgsConstructor; +import lombok.extern.log4j.Log4j2; +import org.springframework.amqp.core.Message; +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; + + + /** + * 普通消费者 + * @param data 数据类型 + * @param message + * @param channel + */ + public void rabbitMQBasicConsumer(Object 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); + } + } + } + + /** + * 普通消费者 + * @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); + } + } + } + + + + + + +} diff --git a/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/producer/RabbitMQProducerUtil.java b/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/producer/RabbitMQProducerUtil.java new file mode 100644 index 0000000..88b0187 --- /dev/null +++ b/cloud-common/cloud-common-rabbit/src/main/java/com/muyu/common/rabbit/producer/RabbitMQProducerUtil.java @@ -0,0 +1,172 @@ +package com.muyu.common.rabbit.producer; + +import com.muyu.common.core.domain.Result; +import com.muyu.common.rabbit.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 Result basicSendMessage(String queueName, Object param, String msg) { + + log.info("【简单模型mq】 : method: 【 basicSendMessage 】 - ages: 【 String : {}, Object : {}, String : {} 】 ---> 【 消息发送中。。。 】", RabbitmqConstants.BASIC_QUEUE_NAME, param, msg); + // 发送简单模型消息 + // 第一个参数: 绑定规则 相当于 队列名称 + // 第二个参数:消息内容 + rabbitTemplate.convertAndSend(queueName, param, message -> { + message.getMessageProperties().setMessageId(UUID.randomUUID().toString()); + return message; + } ); + + log.info("【简单模型mq】 : method: 【 basicSendMessage 】- queue: 【 {} 】 ---> 【 消息发送成功 】", RabbitmqConstants.BASIC_QUEUE_NAME); + + return Result.success(msg!=null?msg:"消息发送成功"); + } + + /** + * 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,"消息发送成功"); + + } + +} diff --git a/cloud-common/cloud-common-rabbit/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/cloud-common/cloud-common-rabbit/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 189ea2c..6cd925a 100644 --- a/cloud-common/cloud-common-rabbit/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/cloud-common/cloud-common-rabbit/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1 +1,7 @@ -com.muyu.common.rabbit.RabbitListenerConfigurer \ No newline at end of file +com.muyu.rabbitmq.producer.RabbitMQProducerUtil +com.muyu.rabbitmq.consumer.RabbitMQConsumerUtil +com.muyu.rabbitmq.config.RabbitmqConfig +com.muyu.rabbitmq.config.MyConfirmCallback +com.muyu.rabbitmq.config.DelayedQueueConfig +com.muyu.rabbitmq.config.RabbitAdminConfig +com.muyu.rabbitmq.config.ReturnCallbackConfig diff --git a/cloud-common/cloud-common-saas/pom.xml b/cloud-common/cloud-common-saas/pom.xml index 41b57fd..6c0d2f6 100644 --- a/cloud-common/cloud-common-saas/pom.xml +++ b/cloud-common/cloud-common-saas/pom.xml @@ -11,6 +11,10 @@ cloud-common-saas + + cloud-common-saas 模块 + + 17 17 @@ -33,6 +37,7 @@ + diff --git a/cloud-common/cloud-common-saas/src/main/java/com/muyu/cloud/common/many/datasource/ManyDataSource.java b/cloud-common/cloud-common-saas/src/main/java/com/muyu/cloud/common/many/datasource/ManyDataSource.java index 8ea974e..04bf3b3 100644 --- a/cloud-common/cloud-common-saas/src/main/java/com/muyu/cloud/common/many/datasource/ManyDataSource.java +++ b/cloud-common/cloud-common-saas/src/main/java/com/muyu/cloud/common/many/datasource/ManyDataSource.java @@ -40,7 +40,7 @@ import java.util.Map; public class ManyDataSource implements ApplicationRunner{ private List dataSourceInfoList(){ RemoteSaaSService remoteSaaSService = SpringUtils.getBean(RemoteSaaSService.class); -Result> tableDataInfoResult = remoteSaaSService.findDatabaseList(); + Result> tableDataInfoResult = remoteSaaSService.findDatabaseList(); if (tableDataInfoResult==null){ throw new SaaSException("saas远调数据源错误"); } diff --git a/cloud-common/cloud-common-saas/src/main/java/com/muyu/cloud/common/many/datasource/constents/DatasourceContent.java b/cloud-common/cloud-common-saas/src/main/java/com/muyu/cloud/common/many/datasource/constents/DatasourceContent.java index b69b858..6152cad 100644 --- a/cloud-common/cloud-common-saas/src/main/java/com/muyu/cloud/common/many/datasource/constents/DatasourceContent.java +++ b/cloud-common/cloud-common-saas/src/main/java/com/muyu/cloud/common/many/datasource/constents/DatasourceContent.java @@ -16,4 +16,8 @@ public class DatasourceContent { public final static String IP = "47.101.53.251"; public final static Integer PORT = 3306; + + public static String getDatasourceUrl(String databaseName) { + return String.format(DATASOURCE_URL,USER_NAME,PASSWORD,IP,PORT, databaseName); + } } diff --git a/cloud-common/cloud-common-swagger/pom.xml b/cloud-common/cloud-common-swagger/pom.xml index 6aa037d..5dbca7f 100644 --- a/cloud-common/cloud-common-swagger/pom.xml +++ b/cloud-common/cloud-common-swagger/pom.xml @@ -1,23 +1,26 @@ - + 4.0.0 com.muyu cloud-common 3.6.3 - 4.0.0 - + com.bwie cloud-common-swagger - - cloud-common-swagger swagger2文档聚合 + cloud-common-swagger系统接口 + + 17 + 17 + UTF-8 + - org.springframework.boot diff --git a/cloud-common/cloud-common-swagger/src/main/java/com/muyu/common/swagger/annotation/EnableCustomSwagger2.java b/cloud-common/cloud-common-swagger/src/main/java/com/muyu/common/swagger/annotation/EnableCustomSwagger2.java index 0d36ba9..c788b2e 100644 --- a/cloud-common/cloud-common-swagger/src/main/java/com/muyu/common/swagger/annotation/EnableCustomSwagger2.java +++ b/cloud-common/cloud-common-swagger/src/main/java/com/muyu/common/swagger/annotation/EnableCustomSwagger2.java @@ -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 袁子龙 * @package:com.muyu.common.swagger.annotation * @name:EnableCustomSwagger2 * @date:2024/9/29 10:01 */ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +@Import({SwaggerAutoConfiguration.class}) public @interface EnableCustomSwagger2 { + } diff --git a/cloud-common/cloud-common-swagger/src/main/java/com/muyu/common/swagger/config/SwaggerBeanPostProcessor.java b/cloud-common/cloud-common-swagger/src/main/java/com/muyu/common/swagger/config/SwaggerBeanPostProcessor.java index be3d265..04e4cf3 100644 --- a/cloud-common/cloud-common-swagger/src/main/java/com/muyu/common/swagger/config/SwaggerBeanPostProcessor.java +++ b/cloud-common/cloud-common-swagger/src/main/java/com/muyu/common/swagger/config/SwaggerBeanPostProcessor.java @@ -12,6 +12,7 @@ import java.util.List; import java.util.stream.Collectors; /** + * 在 springboot 2.6.x 不兼容问题的处理 * @author 袁子龙 * @package:com.muyu.common.swagger.config * @name:SwaggerBeanPostProcessor diff --git a/cloud-common/cloud-common-swagger/src/main/java/com/muyu/common/swagger/config/SwaggerProperties.java b/cloud-common/cloud-common-swagger/src/main/java/com/muyu/common/swagger/config/SwaggerProperties.java index 9be178f..c99b9a2 100644 --- a/cloud-common/cloud-common-swagger/src/main/java/com/muyu/common/swagger/config/SwaggerProperties.java +++ b/cloud-common/cloud-common-swagger/src/main/java/com/muyu/common/swagger/config/SwaggerProperties.java @@ -300,4 +300,3 @@ public class SwaggerProperties { } } } - diff --git a/cloud-common/cloud-common-system/src/main/java/com/muyu/common/system/domain/Enterprise.java b/cloud-common/cloud-common-system/src/main/java/com/muyu/common/system/domain/Enterprise.java new file mode 100644 index 0000000..2dcb360 --- /dev/null +++ b/cloud-common/cloud-common-system/src/main/java/com/muyu/common/system/domain/Enterprise.java @@ -0,0 +1,42 @@ +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 +@EqualsAndHashCode(callSuper = true) +public class Enterprise extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * 企业Id + */ + @Excel(name = "企业序号",cellType = ColumnType.NUMERIC, prompt = "企业编号") + private Integer id; + /** + * 企业名称 + */ + @Excel(name = "企业名称") + private String firmName; + /** + * 数据库名称 + */ + @Excel(name = "数据库名称") + private String databaseName; +} diff --git a/cloud-common/cloud-common-system/src/main/java/com/muyu/common/system/remote/RemoteUserService.java b/cloud-common/cloud-common-system/src/main/java/com/muyu/common/system/remote/RemoteUserService.java index 4bcc4ff..a558d0a 100644 --- a/cloud-common/cloud-common-system/src/main/java/com/muyu/common/system/remote/RemoteUserService.java +++ b/cloud-common/cloud-common-system/src/main/java/com/muyu/common/system/remote/RemoteUserService.java @@ -4,6 +4,7 @@ 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.Enterprise; import com.muyu.common.system.domain.SysFirmUser; import com.muyu.common.system.domain.SysUser; import com.muyu.common.system.remote.factory.RemoteUserFallbackFactory; @@ -44,4 +45,13 @@ public interface RemoteUserService { @GetMapping("/user/companyList") Result> companyList(); + + /** + * 入驻企业信息 + * @param enterprise + * @param source + * @return + */ + @PostMapping("/user/enterprise") + ResultsettlementEnterpriseInfo(@RequestBody Enterprise enterprise, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); } diff --git a/cloud-common/cloud-common-system/src/main/java/com/muyu/common/system/remote/factory/RemoteUserFallbackFactory.java b/cloud-common/cloud-common-system/src/main/java/com/muyu/common/system/remote/factory/RemoteUserFallbackFactory.java index 071490a..720d62a 100644 --- a/cloud-common/cloud-common-system/src/main/java/com/muyu/common/system/remote/factory/RemoteUserFallbackFactory.java +++ b/cloud-common/cloud-common-system/src/main/java/com/muyu/common/system/remote/factory/RemoteUserFallbackFactory.java @@ -2,6 +2,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.Enterprise; import com.muyu.common.system.domain.SysFirmUser; import com.muyu.common.system.remote.RemoteUserService; import com.muyu.common.system.domain.SysUser; @@ -41,6 +42,11 @@ public class RemoteUserFallbackFactory implements FallbackFactory settlementEnterpriseInfo(Enterprise enterprise, String source) { + return Result.error("入驻企业失败"); + } + }; } } diff --git a/cloud-common/pom.xml b/cloud-common/pom.xml index 39e986c..2ed8868 100644 --- a/cloud-common/pom.xml +++ b/cloud-common/pom.xml @@ -23,6 +23,7 @@ cloud-common-saas cloud-common-swagger cloud-common-cache + cloud-common-kafka cloud-common @@ -32,4 +33,5 @@ cloud-common通用模块 + diff --git a/cloud-gateway/src/main/resources/bootstrap.yml b/cloud-gateway/src/main/resources/bootstrap.yml index cf1cc9f..de95a70 100644 --- a/cloud-gateway/src/main/resources/bootstrap.yml +++ b/cloud-gateway/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 47.101.53.251:8848 user-name: nacos password: nacos - namespace: four + namespace: yzl # Spring spring: diff --git a/cloud-modules/cloud-event/pom.xml b/cloud-modules/cloud-event/pom.xml index eb13417..cae475e 100644 --- a/cloud-modules/cloud-event/pom.xml +++ b/cloud-modules/cloud-event/pom.xml @@ -54,13 +54,6 @@ spring-boot-starter-actuator - - - org.springframework.kafka - spring-kafka - - - com.mysql @@ -110,11 +103,17 @@ node-commons 1.3.2 + - org.springframework.kafka - spring-kafka + com.muyu + cloud-common-kafka + 3.6.3 + + com.muyu + cloud-common-rabbit + diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/basic/EventCustom.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/basic/EventCustom.java new file mode 100644 index 0000000..609c8a4 --- /dev/null +++ b/cloud-modules/cloud-event/src/main/java/com/muyu/event/basic/EventCustom.java @@ -0,0 +1,26 @@ +package com.muyu.event.basic; + +import com.alibaba.fastjson2.JSONObject; +import org.springframework.context.ApplicationEvent; + +/** + * 事件类型 + * @author 刘武 + * @package:com.muyu.event.Basic + * @name:EventCustom + * @date:2024/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; + } + +} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/basic/EventListener.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/basic/EventListener.java new file mode 100644 index 0000000..cceaeb9 --- /dev/null +++ b/cloud-modules/cloud-event/src/main/java/com/muyu/event/basic/EventListener.java @@ -0,0 +1,17 @@ +package com.muyu.event.basic; + + +import org.springframework.context.ApplicationListener; + +/** + * 事件监听接口 + * @author 刘武 + * @package:com.muyu.event.basic + * @name:EventListener + * @date:2024/9/29 21:21 + */ +public interface EventListener extends ApplicationListener { + + void onEvent(EventCustom event); + +} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/basic/EventPublisher.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/basic/EventPublisher.java new file mode 100644 index 0000000..624f7fa --- /dev/null +++ b/cloud-modules/cloud-event/src/main/java/com/muyu/event/basic/EventPublisher.java @@ -0,0 +1,33 @@ +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 刘武 + * @package:com.muyu.event.basic + * @name:EventPublisher + * @date:2024/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); + } + + + +} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/basics/EventHandler.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/basics/EventHandler.java deleted file mode 100644 index 85b3488..0000000 --- a/cloud-modules/cloud-event/src/main/java/com/muyu/event/basics/EventHandler.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.muyu.event.basics; - -/** - * @author 刘武 - * @package: - * @name:EventHandler - * @date:2024/9/29 - */ -public class EventHandler { - - private static final ThreadLocal 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(); - } - -} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/basics/EventProcessBasics.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/basics/EventProcessBasics.java deleted file mode 100644 index 98b7684..0000000 --- a/cloud-modules/cloud-event/src/main/java/com/muyu/event/basics/EventProcessBasics.java +++ /dev/null @@ -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); - -} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/basics/EventQueueConfig.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/basics/EventQueueConfig.java deleted file mode 100644 index daf4bb2..0000000 --- a/cloud-modules/cloud-event/src/main/java/com/muyu/event/basics/EventQueueConfig.java +++ /dev/null @@ -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: - * @name:EventQueueConfig - * @date:2024/9/29 - */ -@Data -@Builder -@AllArgsConstructor -@NoArgsConstructor -public class EventQueueConfig { - - private LinkedBlockingDeque taskNodeQueue = new LinkedBlockingDeque<>(); - - public void addEvent(EventProcessBasics obj){ - this.taskNodeQueue.add(obj); - } - - public boolean hashEventNext(){ - return !taskNodeQueue.isEmpty(); - } - - private EventProcessBasics nextTaskNode(){ - return taskNodeQueue.poll(); - } -} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/basics/StartEvent.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/basics/StartEvent.java deleted file mode 100644 index 74d882b..0000000 --- a/cloud-modules/cloud-event/src/main/java/com/muyu/event/basics/StartEvent.java +++ /dev/null @@ -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: - * @name:StartEvent - * @date:2024/9/29 - */ - -public class StartEvent extends ApplicationEvent { - - private EventActuate eventActuate; - - public StartEvent(EventActuate source) { - super(source); - this.eventActuate = source; - } - - public EventActuate getEventActuate() { - return eventActuate; - } -} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/config/EventConfig.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/config/EventConfig.java new file mode 100644 index 0000000..747cb86 --- /dev/null +++ b/cloud-modules/cloud-event/src/main/java/com/muyu/event/config/EventConfig.java @@ -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 刘武 + * @package:com.muyu.event.config + * @name:EventConfig + * @date:2024/9/29 21:13 + */ +@Configuration +public class EventConfig { + + @Bean + public AddDatabaseListener addDatabaseListener() { + return new AddDatabaseListener(); + } + + +} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/config/KafkaConsumerConfig.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/config/KafkaConsumerConfig.java deleted file mode 100644 index 36610d7..0000000 --- a/cloud-modules/cloud-event/src/main/java/com/muyu/event/config/KafkaConsumerConfig.java +++ /dev/null @@ -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 - * kafka配置,也可以写在yml,这个文件会覆盖yml - */ -@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; - /** - * 两次poll之间的最大间隔,默认值为5分钟。如果超过这个间隔会触发reBalance - */ - @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 consumerConfigs() { - Map 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 consumerFactory() { - // 配置消费者的 Json 反序列化的可信赖包,反序列化实体类需要 - try (JsonDeserializer deserializer = new JsonDeserializer<>()) { - deserializer.trustedPackages("*"); - return new DefaultKafkaConsumerFactory<>(consumerConfigs(), new JsonDeserializer<>(), deserializer); - } - } - - /** - * kafka监听容器工厂 负责 从 Kafka的主题中 取出消息进行消费 可以设置消费者的配置 - * @return - */ - @Bean - public KafkaListenerContainerFactory> kafkaListenerContainerFactory() { - ConcurrentKafkaListenerContainerFactory 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; - } - -} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/config/KafkaProviderConfig.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/config/KafkaProviderConfig.java deleted file mode 100644 index 1fdcf05..0000000 --- a/cloud-modules/cloud-event/src/main/java/com/muyu/event/config/KafkaProviderConfig.java +++ /dev/null @@ -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 producerConfigs() { - Map 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 producerFactory() { - DefaultKafkaProducerFactory factory = new DefaultKafkaProducerFactory<>(producerConfigs()); - //开启事务,会导致 LINGER_MS_CONFIG 配置失效 - factory.setTransactionIdPrefix(transactionIdPrefix); - return factory; - } - - /** - * 配置 Kafka的事务管理器 - * @param producerFactory - * @return - */ - @Bean - public KafkaTransactionManager kafkaTransactionManager(ProducerFactory producerFactory) { - return new KafkaTransactionManager<>(producerFactory); - } - - /** - * 构建 KafkaTemplate - * @return - */ - @Bean - public KafkaTemplate kafkaTemplate() { - return new KafkaTemplate<>(producerFactory()); - } - -} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/config/KafkaSendResultHandler.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/config/KafkaSendResultHandler.java deleted file mode 100644 index c0fa863..0000000 --- a/cloud-modules/cloud-event/src/main/java/com/muyu/event/config/KafkaSendResultHandler.java +++ /dev/null @@ -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 { - - @Autowired - private KafkaTemplate 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()); - } - - - - - - - - - - - - - -} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/config/MyKafkaListenerErrorHandler.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/config/MyKafkaListenerErrorHandler.java deleted file mode 100644 index 7c72f48..0000000 --- a/cloud-modules/cloud-event/src/main/java/com/muyu/event/config/MyKafkaListenerErrorHandler.java +++ /dev/null @@ -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); - } - - -} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/constant/EventConstant.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/constant/EventConstant.java deleted file mode 100644 index fa152ac..0000000 --- a/cloud-modules/cloud-event/src/main/java/com/muyu/event/constant/EventConstant.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.muyu.event.constant; - - -/** - * 事件常量 - * @author 刘武 - * @package:com.muyu.event.constant - * @name:EventConstant - * @date:2024/9/28 19:25 - */ - -public interface EventConstant { - - String STORAGE_EVENT = "storageEvent"; -} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/consumer/KafkaConsumer.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/consumer/KafkaConsumer.java deleted file mode 100644 index 6fe4eb6..0000000 --- a/cloud-modules/cloud-event/src/main/java/com/muyu/event/consumer/KafkaConsumer.java +++ /dev/null @@ -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 刘武 - * @package:com.muyu.event.consumer - * @name:KafkaConsumer - * @date:2024/9/28 23:34 - */ - -public class KafkaConsumer { - - - @KafkaListener(topics = "data") - public void dataKafkaConsumer(ConsumerRecord consumerRecord, Acknowledgment acknowledgment){ - Object key = consumerRecord.key(); - Object value = consumerRecord.value(); - - //事件调用 - - - //消息确认消费 - acknowledgment.acknowledge(); - } - - -} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/consumer/MessageConsumer.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/consumer/MessageConsumer.java new file mode 100644 index 0000000..3cb39c0 --- /dev/null +++ b/cloud-modules/cloud-event/src/main/java/com/muyu/event/consumer/MessageConsumer.java @@ -0,0 +1,57 @@ +package com.muyu.event.consumer; + + + +import com.alibaba.fastjson2.JSONObject; +import com.muyu.event.basic.EventPublisher; +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 刘武 + * @package:com.muyu.event.consumer + * @name:KafkaConsumer + * @date:2024/9/28 23:34 + */ +@Component +@Log4j2 +public class MessageConsumer implements ApplicationRunner { + + @Autowired + public KafkaConsumer consumer; + @Autowired + private EventPublisher eventPublisher; + + private final String topic="four_car"; + + + @Override + public void run(ApplicationArguments args) throws Exception { + List list = Collections.singletonList(topic); + consumer.subscribe(list); + + while (true){ + ConsumerRecords 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); + }); + + + } + } +} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/consumer/OnlineConsumer.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/consumer/OnlineConsumer.java new file mode 100644 index 0000000..d8871b7 --- /dev/null +++ b/cloud-modules/cloud-event/src/main/java/com/muyu/event/consumer/OnlineConsumer.java @@ -0,0 +1,21 @@ +package com.muyu.event.consumer; + +import lombok.extern.log4j.Log4j2; +import org.springframework.stereotype.Component; + +/** + * 车辆上线监听 + * @author 刘武 + * @package:com.muyu.event.consumer + * @name:OnlineConsumer + * @date:2024/9/30 11:40 + */ +@Component +@Log4j2 +public class OnlineConsumer { + + + + + +} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/controller/DataController.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/controller/DataController.java new file mode 100644 index 0000000..d1ff027 --- /dev/null +++ b/cloud-modules/cloud-event/src/main/java/com/muyu/event/controller/DataController.java @@ -0,0 +1,19 @@ +package com.muyu.event.controller; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author 刘武 + * @package:com.muyu.event.controller + * @name:DataController + * @date:2024/9/29 20:16 + */ +@RestController +@RequestMapping("data") +public class DataController { + + + + +} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/controller/TestController.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/controller/TestController.java new file mode 100644 index 0000000..fb46a2e --- /dev/null +++ b/cloud-modules/cloud-event/src/main/java/com/muyu/event/controller/TestController.java @@ -0,0 +1,63 @@ +package com.muyu.event.controller; + + +import com.alibaba.fastjson2.JSONObject; +import com.muyu.event.service.TestService; +import org.apache.kafka.clients.producer.KafkaProducer; +import org.apache.kafka.clients.producer.ProducerRecord; +import org.springframework.amqp.core.AmqpTemplate; +import org.springframework.beans.factory.annotation.Autowired; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * @author 刘武 + * @package:com.muyu.event.controller + * @name:TestController + * @date:2024/9/29 20:58 + */ +@RestController("test") +public class TestController { + + @Resource + private KafkaProducer kafkaProducer; + + + + private static final String topic="four_car"; + + @GetMapping("send") + public String sendKafka(){ + + String message="发送一条信息"; + JSONObject jsonObject = new JSONObject(); + jsonObject.put("cj","sb"); + + + ProducerRecord producerRecord = new ProducerRecord(topic,jsonObject.toJSONString()); + kafkaProducer.send(producerRecord); + + return "success"; + } + + + + + + + + + + + + + + + + +} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/domian/EventActuate.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/domian/EventActuate.java deleted file mode 100644 index 9ccd57e..0000000 --- a/cloud-modules/cloud-event/src/main/java/com/muyu/event/domian/EventActuate.java +++ /dev/null @@ -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 eventKeys; -} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/eventDispose/AutoStartupEventListener.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/eventDispose/AutoStartupEventListener.java deleted file mode 100644 index 6eec2db..0000000 --- a/cloud-modules/cloud-event/src/main/java/com/muyu/event/eventDispose/AutoStartupEventListener.java +++ /dev/null @@ -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: - * @name:AutoStartupEventListener - * @date:2024/9/29 - */ -@Component -public class AutoStartupEventListener implements ApplicationListener { - - @Override - public void onApplicationEvent(StartEvent event) { - - EventActuate eventActuate = event.getEventActuate(); - - } - -} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/eventDispose/StorageEvent.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/eventDispose/StorageEvent.java deleted file mode 100644 index 70d6e79..0000000 --- a/cloud-modules/cloud-event/src/main/java/com/muyu/event/eventDispose/StorageEvent.java +++ /dev/null @@ -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: - * @name:StorageEvent - * @date:2024/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); - } - } -} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/listener/AddDatabaseListener.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/listener/AddDatabaseListener.java new file mode 100644 index 0000000..e3fc4a7 --- /dev/null +++ b/cloud-modules/cloud-event/src/main/java/com/muyu/event/listener/AddDatabaseListener.java @@ -0,0 +1,37 @@ +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 keys = new ArrayList<>(); + List values = new ArrayList<>(); + + jsonObject.forEach((key, value) -> { + keys.add(key); + values.add((String) value); + }); + } + + @Override + public void onApplicationEvent(EventCustom event) { + onEvent(event); + } +} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/DataService.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/DataService.java new file mode 100644 index 0000000..a06f76c --- /dev/null +++ b/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/DataService.java @@ -0,0 +1,19 @@ +package com.muyu.event.service; + +/** + * @author 刘武 + * @package:com.muyu.event.service.impl + * @name:DataService + * @date:2024/9/29 20:23 + */ +public interface DataService { + + void warnData(String data); + + + + + + + +} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/TestService.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/TestService.java new file mode 100644 index 0000000..a7e2b7c --- /dev/null +++ b/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/TestService.java @@ -0,0 +1,10 @@ +package com.muyu.event.service; + +/** + * @author 刘武 + * @package:com.muyu.event.service + * @name:TestService + * @date:2024/9/29 20:59 + */ +public interface TestService { +} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/impl/DataServiceImpl.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/impl/DataServiceImpl.java new file mode 100644 index 0000000..649c0ce --- /dev/null +++ b/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/impl/DataServiceImpl.java @@ -0,0 +1,26 @@ +package com.muyu.event.service.impl; + +import com.muyu.event.service.DataService; +import org.springframework.stereotype.Service; + +/** + * @author 刘武 + * @package:com.muyu.event.service.impl + * @name:DataServiceImpl + * @date:2024/9/29 20:24 + */ +@Service +public class DataServiceImpl implements DataService { + + + + @Override + public void warnData(String data) { + + + + + + + } +} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/impl/TestServiceImpl.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/impl/TestServiceImpl.java new file mode 100644 index 0000000..79100a8 --- /dev/null +++ b/cloud-modules/cloud-event/src/main/java/com/muyu/event/service/impl/TestServiceImpl.java @@ -0,0 +1,20 @@ +package com.muyu.event.service.impl; + +import com.muyu.event.service.TestService; +import org.springframework.stereotype.Service; + +/** + * @author 刘武 + * @package:com.muyu.event.service.impl + * @name:TestServiceImpl + * @date:2024/9/29 21:00 + */ +@Service +public class TestServiceImpl implements TestService { + + + + + + +} diff --git a/cloud-modules/cloud-event/src/main/java/com/muyu/event/util/CacheUtil.java b/cloud-modules/cloud-event/src/main/java/com/muyu/event/util/CacheUtil.java new file mode 100644 index 0000000..c2de42f --- /dev/null +++ b/cloud-modules/cloud-event/src/main/java/com/muyu/event/util/CacheUtil.java @@ -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 { + + private final Cache 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); + } + +} diff --git a/cloud-modules/cloud-event/src/main/resources/bootstrap.yml b/cloud-modules/cloud-event/src/main/resources/bootstrap.yml index f0ff80f..1bc0fa4 100644 --- a/cloud-modules/cloud-event/src/main/resources/bootstrap.yml +++ b/cloud-modules/cloud-event/src/main/resources/bootstrap.yml @@ -1,14 +1,16 @@ # Tomcat server: port: 10009 + # nacos线上地址 nacos: addr: 47.101.53.251:8848 user-name: nacos password: nacos - namespace: four + namespace: yzl # 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 diff --git a/cloud-modules/cloud-modules-file/src/main/resources/bootstrap.yml b/cloud-modules/cloud-modules-file/src/main/resources/bootstrap.yml index cb7e8d5..3a1eb6a 100644 --- a/cloud-modules/cloud-modules-file/src/main/resources/bootstrap.yml +++ b/cloud-modules/cloud-modules-file/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 47.101.53.251:8848 user-name: nacos password: nacos - namespace: four + namespace: yzl # Spring spring: diff --git a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/GenTableColumnServiceImpl.java b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/GenTableColumnServiceImpl.java index 043c83b..b608eb5 100644 --- a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/GenTableColumnServiceImpl.java +++ b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/GenTableColumnServiceImpl.java @@ -9,7 +9,7 @@ import org.springframework.stereotype.Service; import java.util.List; /** - * 业务字段 服务层实现 + * 业务字段 业务逻辑层实现 * * @author ruoyi */ diff --git a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/GenTableServiceImpl.java b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/GenTableServiceImpl.java index 8cdefc5..872897c 100644 --- a/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/GenTableServiceImpl.java +++ b/cloud-modules/cloud-modules-gen/src/main/java/com/muyu/gen/service/GenTableServiceImpl.java @@ -40,7 +40,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; /** - * 业务 服务层实现 + * 业务 业务逻辑层实现 * * @author ruoyi */ diff --git a/cloud-modules/cloud-modules-gen/src/main/resources/bootstrap.yml b/cloud-modules/cloud-modules-gen/src/main/resources/bootstrap.yml index 0b7bdc1..c5e8cb9 100644 --- a/cloud-modules/cloud-modules-gen/src/main/resources/bootstrap.yml +++ b/cloud-modules/cloud-modules-gen/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 47.101.53.251:8848 user-name: nacos password: nacos - namespace: four + namespace: yzl # SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all # Spring spring: diff --git a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysUserController.java b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysUserController.java index d3aa7ca..17170ac 100644 --- a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysUserController.java +++ b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysUserController.java @@ -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 enterprise (@RequestBody Enterprise enterprise){ + + return Result.success(userService.enterprise(enterprise)); + } /** * 获取用户信息 * diff --git a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/mapper/SysUserMapper.java b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/mapper/SysUserMapper.java index 90ae439..d02260f 100644 --- a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/mapper/SysUserMapper.java +++ b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/mapper/SysUserMapper.java @@ -1,6 +1,7 @@ package com.muyu.system.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.muyu.common.system.domain.Enterprise; import com.muyu.common.system.domain.SysUser; import org.apache.ibatis.annotations.Param; @@ -66,6 +67,20 @@ public interface SysUserMapper extends BaseMapper { */ int insertUser(SysUser user); + /** + * 企业入驻 + * @param enterprise + * @return + */ + int enterprise(Enterprise enterprise); + + /** + * 企业管理添加 + * @param enterprise + * @return + */ + int enterPriseAdd(Enterprise enterprise); + /** * 修改用户信息 * @@ -142,4 +157,6 @@ public interface SysUserMapper extends BaseMapper { List selectCompanyList(); + + } diff --git a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/SysConfigService.java b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/SysConfigService.java index 4ebc241..dadf990 100644 --- a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/SysConfigService.java +++ b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/SysConfigService.java @@ -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 diff --git a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/SysDeptService.java b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/SysDeptService.java index e3d0b28..b259732 100644 --- a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/SysDeptService.java +++ b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/SysDeptService.java @@ -7,7 +7,7 @@ import com.muyu.system.domain.vo.TreeSelect; import java.util.List; /** - * 部门管理 服务层 + * 部门管理 业务逻辑层 * * @author muyu */ diff --git a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/SysUserService.java b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/SysUserService.java index a36a4f0..84c9065 100644 --- a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/SysUserService.java +++ b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/SysUserService.java @@ -1,6 +1,7 @@ package com.muyu.system.service; import com.baomidou.mybatisplus.extension.service.IService; +import com.muyu.common.system.domain.Enterprise; import com.muyu.common.system.domain.SysUser; import java.util.List; @@ -133,6 +134,7 @@ public interface SysUserService extends IService { */ boolean registerUser(SysUser user); + boolean enterprise(Enterprise enterprise); /** * 修改用户信息 * @@ -228,4 +230,5 @@ public interface SysUserService extends IService { List selectCompanyList(); + } diff --git a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/impl/SysConfigServiceImpl.java b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/impl/SysConfigServiceImpl.java index bc07cc8..a08ad64 100644 --- a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/impl/SysConfigServiceImpl.java +++ b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/impl/SysConfigServiceImpl.java @@ -18,6 +18,7 @@ import java.util.List; import java.util.Objects; /** + * 配置plus业务实现层 * @author DongZl * @description: 配置plus业务实现层 * @Date 2023-11-13 上午 10:06 diff --git a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/impl/SysUserServiceImpl.java b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/impl/SysUserServiceImpl.java index 7bba2ee..4e30574 100644 --- a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/impl/SysUserServiceImpl.java +++ b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/impl/SysUserServiceImpl.java @@ -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.Enterprise; 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 impl return userMapper.insertUser(user) > 0; } + /** + * 企业入驻 + * @param enterprise + * @return + */ + @Override + public boolean enterprise(Enterprise enterprise){ + userMapper.enterPriseAdd(enterprise); + return userMapper.enterprise(enterprise) > 0; + } + /** * 修改保存用户信息 * diff --git a/cloud-modules/cloud-modules-system/src/main/resources/bootstrap.yml b/cloud-modules/cloud-modules-system/src/main/resources/bootstrap.yml index 566c624..afe1a22 100644 --- a/cloud-modules/cloud-modules-system/src/main/resources/bootstrap.yml +++ b/cloud-modules/cloud-modules-system/src/main/resources/bootstrap.yml @@ -7,7 +7,7 @@ nacos: addr: 47.101.53.251:8848 user-name: nacos password: nacos - namespace: four + namespace: yzl # SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all # Spring spring: diff --git a/cloud-modules/cloud-modules-system/src/main/resources/mapper/system/SysUserMapper.xml b/cloud-modules/cloud-modules-system/src/main/resources/mapper/system/SysUserMapper.xml index c23843a..6023ef5 100644 --- a/cloud-modules/cloud-modules-system/src/main/resources/mapper/system/SysUserMapper.xml +++ b/cloud-modules/cloud-modules-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -221,6 +221,13 @@ sysdate() ) + + INSERT INTO `datasource`.`datasource` (`id`, `firm_name`, `database_name`) VALUES (NULL, #{firmName}, #{databaseName}); + + + INSERT INTO `saas`.`tb_enterprise` (`enterprise_id`, `enterprise_name`, `enterprise_car_count`, `enterprise_fence_count`, `enterprise_database_name`) + VALUES (NULL, #{firmName}, 0, 0, #{databaseName}); + update sys_user diff --git a/cloud-modules/cloud-modules-template/pom.xml b/cloud-modules/cloud-modules-template/pom.xml new file mode 100644 index 0000000..fa19206 --- /dev/null +++ b/cloud-modules/cloud-modules-template/pom.xml @@ -0,0 +1,100 @@ + + + 4.0.0 + + com.muyu + cloud-modules + 3.6.3 + + + cloud-modules-template + + + cloud-modules-template 协议解析模块 + + + + + + + + + + + + + com.muyu.server + saas-server + 3.6.3 + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-sentinel + + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + com.mysql + mysql-connector-j + + + + + com.muyu + cloud-common-datasource + + + + + com.muyu + cloud-common-datascope + + + + + com.muyu + cloud-common-log + + + + + com.muyu + cloud-common-api-doc + + + + + com.muyu + cloud-common-xxl + + + + + 17 + 17 + UTF-8 + + + diff --git a/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/CloudTemplateApplication.java b/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/CloudTemplateApplication.java new file mode 100644 index 0000000..80804e6 --- /dev/null +++ b/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/CloudTemplateApplication.java @@ -0,0 +1,23 @@ +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 + * @Package:com.muyu.template + * @name:CloudTemplateApplication + * @Date:2024/9/30 10:36 + */ +@EnableCustomConfig +@EnableMyFeignClients +@SpringBootApplication +public class CloudTemplateApplication { + + public static void main(String[] args) { + + SpringApplication.run(CloudTemplateApplication.class, args); + + } + +} diff --git a/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/config/MqttConfigure.java b/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/config/MqttConfigure.java new file mode 100644 index 0000000..065aa80 --- /dev/null +++ b/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/config/MqttConfigure.java @@ -0,0 +1,170 @@ +package com.muyu.template.config; +import cn.hutool.json.JSONObject; +import com.alibaba.fastjson2.JSON; +import com.muyu.common.domain.MessageTemplateType; +import com.muyu.common.domain.SysCar; +import com.muyu.common.redis.service.RedisService; + +import lombok.extern.log4j.Log4j2; +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; +/** + * + * @author liuxinyue + * @Package:com.muyu.mqtt.configure + * @Project:cloud-server + * @name:MqttConfigure + * @Date:2024/9/28 16:10 + */ +@Log4j2 +@Component +public class MqttConfigure { + + @Autowired + private RedisService redisService; + + @Autowired + private RedisTemplate redisTemplate; + +// @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"); + messageParsing(msgValue); + log.info("接收到的值为:"+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"); + } + //将报文进行切割 + 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(0, 18 - 1); + log.info("carVin码为:" + carVin); + //根据VIN码获取车辆信息 + SysCar carByVin = null; + List carList = redisService.getCacheList("carList"); + for (SysCar sysCar : carList) { + if(sysCar.getCarVin().equals(carVin)){ + carByVin=sysCar; + } + } +// SysCar carByVin = service.findCarByVin(carVin); + log.info("车辆信息为:" + carByVin); + //对应车辆所对应的报文模版 + Integer templateId = carByVin.getTemplateId(); + List templateTypeList; + //key + String redisKey = "messageTemplateType" + templateId; + //key存在 + if (redisTemplate.hasKey(redisKey)) { + + List list = redisTemplate.opsForList().range(redisKey, 0, -1); + + templateTypeList = list.stream().map(o -> JSON.parseObject(o.toString(), MessageTemplateType.class)) + .toList(); + } else { + List templateTypeList1=null; + List templateTypeList2 = redisService.getCacheList("templateTypeList"); + for (MessageTemplateType messageTemplateType : templateTypeList2) { + if(messageTemplateType.getTemplateId()==templateId){ + templateTypeList1.add(messageTemplateType); + } + } +// List templateTypeList1 = messageTemplateTypeService.findTemplateById(templateId); + templateTypeList = templateTypeList1; + templateTypeList.forEach( + templateType -> + redisTemplate.opsForList().rightPush( + redisKey, JSON.toJSONString(templateType) + ) + ); + } + //将模版里面有的配置进行循环 + for (MessageTemplateType messageTemplateType : templateTypeList) { + //开始位置 + 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 stringStringProducerRecord = new ProducerRecord<>("four_car", jsonObject.toString()); +// kafkaProducer.send(stringStringProducerRecord); +// log.info("kafka发送成功"); +// } + +} diff --git a/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/controller/KafkaController.java b/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/controller/KafkaController.java new file mode 100644 index 0000000..34e4ccd --- /dev/null +++ b/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/controller/KafkaController.java @@ -0,0 +1,10 @@ +package com.muyu.template.controller; + +/** + * @author liuxinyue + * @Package:com.muyu.template.controller + * @name:KafkaController + * @Date:2024/10/4 16:11 + */ +public class KafkaController { +} diff --git a/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/test.java b/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/test.java new file mode 100644 index 0000000..e602a8d --- /dev/null +++ b/cloud-modules/cloud-modules-template/src/main/java/com/muyu/template/test.java @@ -0,0 +1,62 @@ +package com.muyu.template; + +import com.muyu.common.domain.SysCar; +import com.muyu.common.domain.Template; +import com.muyu.common.domain.WarnRule; +import com.muyu.common.domain.WarnStrategy; +import com.muyu.common.redis.service.RedisService; +import org.springframework.beans.factory.annotation.Autowired; +import javax.annotation.Resource; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +/** + * @author liuxinyue + * @Package:com.muyu.template + * @name:test + * @Date:2024/10/4 9:42 + */ +public class test { + + @Resource + private RedisService redisService; + + public void main(String[] args) { + + //车类型 + Long carTypeId=null; + //查找车对应的类型 + List carList = redisService.getCacheList("car"); + for (SysCar sysCar : carList) { + if(sysCar.getCarVin().equals("")){ + //获取到车的类型ID + carTypeId = sysCar.getCarTypeId(); + } + } + + //查找车类型对应的策略 + List warnStrategyList = null; + //该车绑定的报文模版 + Long templateId=null; + //获取到车的类型之后 查找对应的策略 + List warnStrategy = redisService.getCacheList("warnStrategy"); + for (WarnStrategy strategy : warnStrategy) { + if(strategy.getCarTypeId().equals(carTypeId)){ + templateId=strategy.getTemplateId(); + warnStrategyList.add(strategy); + } + } + + //根据ID取出对应的报文模版 + List