diff --git a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/config/RabbitMQConfig.java b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/config/RabbitMQConfig.java
index 32976d5..341d052 100644
--- a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/config/RabbitMQConfig.java
+++ b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/config/RabbitMQConfig.java
@@ -33,7 +33,7 @@ public class RabbitMQConfig implements RabbitTemplate.ConfirmCallback, RabbitTem
public String exchangeName;
//路由键
- @Value(("${mq.routingKey}"))
+ @Value("${mq.routingKey}")
public String routingKey;
private RabbitTemplate rabbitTemplate;
@@ -69,7 +69,7 @@ public class RabbitMQConfig implements RabbitTemplate.ConfirmCallback, RabbitTem
* @Param: []
* @Return: 返回一个配置好的DirectExchange实例。
**/
- @Bean("exchange")
+ @Bean
public DirectExchange directExchange() {
return new DirectExchange(exchangeName);
}
diff --git a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/controller/MqController.java b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/controller/MqController.java
index 7188a91..057ac32 100644
--- a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/controller/MqController.java
+++ b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/controller/MqController.java
@@ -1,15 +1,13 @@
package com.couplet.mq.controller;
import com.couplet.common.core.utils.uuid.IdUtils;
-import com.couplet.mq.config.RabbitMQConfig;
+import com.couplet.mq.domain.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.*;
/**
* @ProjectName: five-groups-couplet
@@ -21,17 +19,37 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/mq")
@Slf4j
public class MqController {
+ // 通过注入的方式获取队列名、交换机名和路由键
+ //队列名
+ @Value("${mq.queueName}")
+ public String queueName;
+
+ //交换机
+ @Value("${mq.exchangeName}")
+ public String exchangeName;
+
+ //路由键
+ @Value("${mq.routingKey}")
+ public String routingKey;
+
@Autowired
private RabbitTemplate rabbitTemplate;
- @GetMapping("/receive/{data}")
- public void receive(@PathVariable("data") String data) {
- //创建配置类对象,用于获取配置值
- RabbitMQConfig config = new RabbitMQConfig();
+ /*
+ * @Author: LiuYunHu
+ * @Date: 2024/4/1 19:58
+ * @Description: 消息发送者
+ * @Param: [data]
+ * @Return: void
+ **/
+ @PostMapping("/sout")
+ //接收json字符串
+ public void sout(@RequestBody User param) {
+ rabbitTemplate.convertAndSend(exchangeName, routingKey, param, message -> {
+ message.getMessageProperties().setMessageId(IdUtils.randomUUID());
+ return message;
+ }, new CorrelationData(IdUtils.randomUUID())
+ );
- rabbitTemplate.convertAndSend(config.exchangeName, config.routingKey, data , message -> {
- message.getMessageProperties().setMessageId(IdUtils.randomUUID());
- return message;
- }, new CorrelationData(IdUtils.randomUUID()));
}
}
diff --git a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/domain/Test.java b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/domain/Test.java
deleted file mode 100644
index 618d7ec..0000000
--- a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/domain/Test.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.couplet.mq.domain;
-
-import java.io.Serializable;
-
-/**
- * @ProjectName: five-groups-couplet
- * @Author: LiuYunHu
- * @CreateTime: 2024/3/29
- * @Description: 测试 参数类
- */
-
-public class Test implements Serializable {
- public String data;
-}
diff --git a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/domain/User.java b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/domain/User.java
new file mode 100644
index 0000000..77451e1
--- /dev/null
+++ b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/domain/User.java
@@ -0,0 +1,22 @@
+package com.couplet.mq.domain;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+/**
+ * @ProjectName: five-groups-couplet
+ * @Author: LiuYunHu
+ * @CreateTime: 2024/4/1
+ * @Description:
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@ToString
+public class User {
+ private String name;
+ private Integer age;
+ private String sex;
+}
diff --git a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/service/Consumer.java b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/service/Consumer.java
index 5d27eec..a01fcac 100644
--- a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/service/Consumer.java
+++ b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/service/Consumer.java
@@ -1,5 +1,6 @@
package com.couplet.mq.service;
+import com.couplet.mq.domain.User;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
@@ -18,53 +19,146 @@ import java.util.concurrent.TimeUnit;
* @CreateTime: 2024/3/28
* @Description: MQ消费者类
*/
-@RabbitListener(queues = "${mq.queueName}")
+
@Component
@Slf4j
+@SuppressWarnings("all")
+@RabbitListener(queues = "${mq.queueName}")
public class Consumer {
@Autowired
- private StringRedisTemplate redisTemplate;
+ private StringRedisTemplate redis;
+ /* 线程池执行
+
+ //创建一个定长线程池
+ private final Executor executor = Executors.newFixedThreadPool(5);
+
+ @Async
@RabbitHandler
- public void receive(String data, Channel channel, Message message) throws IOException {
- log.info("消费者接受到数据:{}", data);
+ public void process(User param, Channel channel, Message message) {
+ executor.execute(() -> {
+ try {
+ handleMessage(param, channel, message);
+ } catch (IOException e) {
+ log.error("处理消息失败:{}", e);
+ }
+ });
+ }
+
+ //处理信息的方法
+ private void handleMessage(User param, Channel channel, Message message) throws IOException {
+ log.info("消费者收到消息为:{},{}" + param, message.getMessageProperties().getDeliveryTag());
- //获取信息的标记
long deliveryTag = message.getMessageProperties().getDeliveryTag();
-
- //获取到消息的id
String messageId = message.getMessageProperties().getMessageId();
- Long add = redisTemplate.opsForSet().add("set:" + messageId, "set:" + messageId);
-
- if (!redisTemplate.hasKey("value:" + messageId)) {
- redisTemplate.opsForValue().set("value:" + messageId, String.valueOf(deliveryTag), 10, TimeUnit.MINUTES);
+ if (!redis.hasKey("value:" + messageId)) {
+ redis.opsForValue().set("value:" + messageId, "" + deliveryTag, 5, TimeUnit.MINUTES);
}
+ // 1 添加成功新数据 0已有重复值,不允许再添加
+ Long add = redis.opsForSet().add("set:" + messageId, "set:" + messageId);
+ //过期时间
+ redis.expire("set:" + messageId, 5, TimeUnit.MINUTES);
+
+
try {
if (add == 1) {
- log.info("---------------消费者开始消费---------------");
+ //第一次 消费
+ System.out.println("*****************************");
+ System.out.println("消费者收到消息:" + param);
+ System.out.println("*****************************");
+ log.info("消费结束");
- System.out.println(data);
+ channel.basicAck(deliveryTag, false);
- log.info("---------------消费者结束消费---------------");
- }else {
- log.error("重复消费!");
+ } else {
+ //重复消费
+ log.error("重复消费");
channel.basicReject(deliveryTag, false);
+
+ //删除缓存
+ redis.opsForSet().remove("set:" + messageId, "set:" + messageId);
}
- } catch (IOException e) {
-// throw new RuntimeException(e);
- String s = redisTemplate.opsForValue().get("value:" + messageId);
+
+
+ } catch (Exception e) {
+ log.error("消息没有成功消费!");
+
+ String s = redis.opsForValue().get("value:" + messageId);
+
long oldTag = Long.parseLong(s);
- if ((oldTag + 2) != deliveryTag) {
- log.info("重新入队!");
- channel.basicNack(deliveryTag, false, true);
- }else {
- log.error("三次无法消费,不再入队!");
+ if (deliveryTag == (oldTag + 2)) {
+ log.error("确实消费不了,不入队了!");
channel.basicNack(deliveryTag, false, false);
+ } else {
+ log.info("消息消费失败,重新入队");
+ channel.basicNack(deliveryTag, false, true);
+ }
+ }
+
+ }
+
+**/
+
+ @RabbitHandler
+ public void process(User param, Channel channel, Message message) throws IOException {
+ log.info("消费者收到消息为:{},{}" + param, message.getMessageProperties().getDeliveryTag());
+
+ long deliveryTag = message.getMessageProperties().getDeliveryTag();
+ String messageId = message.getMessageProperties().getMessageId();
+
+ if (!redis.hasKey("value:" + messageId)) {
+ redis.opsForValue().set("value:" + messageId, "" + deliveryTag, 5, TimeUnit.MINUTES);
+ }
+
+ // 1 添加成功新数据 0已有重复值,不允许再添加
+ Long add = redis.opsForSet().add("set:" + messageId, "set:" + messageId);
+ //过期时间
+ redis.expire("set:" + messageId, 5, TimeUnit.MINUTES);
+
+
+ try {
+ if (add == 1) {
+ //第一次 消费
+ System.out.println("*****************************");
+ System.out.println("消费者收到消息:" + param);
+ System.out.println("*****************************");
+ log.info("消费结束");
+
+ //确认消费
+ channel.basicAck(deliveryTag, false);
+
+ } else {
+ //重复消费
+ log.error("重复消费");
+ //拒绝消费
+ channel.basicReject(deliveryTag, false);
+
+ //删除缓存
+ redis.opsForSet().remove("set:" + messageId, "set:" + messageId);
}
+
+ } catch (Exception e) {
+ log.error("消息没有成功消费!");
+
+ String s = redis.opsForValue().get("value:" + messageId);
+
+ long oldTag = Long.parseLong(s);
+
+ if (deliveryTag == (oldTag + 2)) {
+ log.error("确实消费不了,不入队了!");
+
+
+ //拒绝消费
+ channel.basicNack(deliveryTag, false, false);
+ } else {
+ log.info("消息消费失败,重新入队");
+ //重新入队
+ channel.basicNack(deliveryTag, false, true);
+ }
}
}
}
diff --git a/couplet-modules/couplet-modules-mq/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/couplet-modules/couplet-modules-mq/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
new file mode 100644
index 0000000..84477af
--- /dev/null
+++ b/couplet-modules/couplet-modules-mq/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -0,0 +1 @@
+com.couplet.mq.config.RabbitMQConfig
diff --git a/couplet-modules/couplet-modules-mq/src/main/resources/bootstrap.yml b/couplet-modules/couplet-modules-mq/src/main/resources/bootstrap.yml
index 61d454f..efb4cd6 100644
--- a/couplet-modules/couplet-modules-mq/src/main/resources/bootstrap.yml
+++ b/couplet-modules/couplet-modules-mq/src/main/resources/bootstrap.yml
@@ -31,16 +31,6 @@ logging:
level:
com.couplet.system.mapper: DEBUG
-# 订阅端配置
-mqtt:
- server:
- broker: tcp://115.159.47.13:1883
- username:
- password:
- clientid: mqttx
- qos: 0
- topic: test
-
# RabbitMQ配置
mq:
queueName: queue
diff --git a/couplet-modules/couplet-modules-onLine/pom.xml b/couplet-modules/couplet-modules-onLine/pom.xml
new file mode 100644
index 0000000..74327db
--- /dev/null
+++ b/couplet-modules/couplet-modules-onLine/pom.xml
@@ -0,0 +1,121 @@
+
+
+
+ com.couplet
+ couplet-modules
+ 3.6.3
+
+ 4.0.0
+
+ couplet-modules-online
+
+
+
+
+
+
+
+
+ couplet-modules-online车辆上线的模块
+
+
+
+
+
+
+ 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
+
+
+
+
+ io.springfox
+ springfox-swagger-ui
+ ${swagger.fox.version}
+
+
+
+
+ com.mysql
+ mysql-connector-j
+
+
+
+
+ com.couplet
+ couplet-common-datasource
+
+
+
+
+ com.couplet
+ couplet-common-datascope
+
+
+
+
+ com.couplet
+ couplet-common-log
+
+
+
+
+ com.couplet
+ couplet-common-swagger
+
+
+
+
+ org.eclipse.paho
+ org.eclipse.paho.client.mqttv3
+ 1.2.5
+
+
+
+
+
+ ${project.artifactId}
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ repackage
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-deploy-plugin
+
+ true
+
+
+
+
+
+
diff --git a/couplet-modules/couplet-modules-onLine/src/main/java/com/couplet/online/OnlineApplication.java b/couplet-modules/couplet-modules-onLine/src/main/java/com/couplet/online/OnlineApplication.java
new file mode 100644
index 0000000..d1b4a04
--- /dev/null
+++ b/couplet-modules/couplet-modules-onLine/src/main/java/com/couplet/online/OnlineApplication.java
@@ -0,0 +1,25 @@
+package com.couplet.online;
+
+import com.couplet.common.security.annotation.EnableCustomConfig;
+import com.couplet.common.security.annotation.EnableMyFeignClients;
+import com.couplet.common.swagger.annotation.EnableCustomSwagger2;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ * @ProjectName: Default (Template) Project
+ * @Author: LiuYunHu
+ * @CreateTime: 2024/4/1
+ * @Description: 车辆上线的模块启动类
+ */
+
+@EnableCustomConfig
+@EnableCustomSwagger2
+@EnableMyFeignClients
+@SpringBootApplication
+public class OnlineApplication {
+ public static void main(String[] args) {
+ SpringApplication.run(OnlineApplication.class);
+ System.out.println("车辆上线模块启动成功");
+ }
+}
diff --git a/couplet-modules/couplet-modules-onLine/src/main/java/com/couplet/online/controller/OnlineController.java b/couplet-modules/couplet-modules-onLine/src/main/java/com/couplet/online/controller/OnlineController.java
new file mode 100644
index 0000000..3c028a9
--- /dev/null
+++ b/couplet-modules/couplet-modules-onLine/src/main/java/com/couplet/online/controller/OnlineController.java
@@ -0,0 +1,16 @@
+package com.couplet.online.controller;
+
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @ProjectName: five-groups-couplet
+ * @Author: LiuYunHu
+ * @CreateTime: 2024/4/1
+ * @Description: 车辆上线控制器
+ */
+
+@RestController
+@RequestMapping("/online")
+public class OnlineController {
+}
diff --git a/couplet-modules/couplet-modules-onLine/src/main/java/com/couplet/online/mapper/OnlineMapper.java b/couplet-modules/couplet-modules-onLine/src/main/java/com/couplet/online/mapper/OnlineMapper.java
new file mode 100644
index 0000000..08848d2
--- /dev/null
+++ b/couplet-modules/couplet-modules-onLine/src/main/java/com/couplet/online/mapper/OnlineMapper.java
@@ -0,0 +1,16 @@
+package com.couplet.online.mapper;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.springframework.stereotype.Component;
+
+/**
+ * @ProjectName: five-groups-couplet
+ * @Author: LiuYunHu
+ * @CreateTime: 2024/4/1
+ * @Description: 车辆上线mapper
+ */
+
+@Mapper
+@Component
+public interface OnlineMapper {
+}
diff --git a/couplet-modules/couplet-modules-onLine/src/main/java/com/couplet/online/service/OnlineService.java b/couplet-modules/couplet-modules-onLine/src/main/java/com/couplet/online/service/OnlineService.java
new file mode 100644
index 0000000..4b40842
--- /dev/null
+++ b/couplet-modules/couplet-modules-onLine/src/main/java/com/couplet/online/service/OnlineService.java
@@ -0,0 +1,11 @@
+package com.couplet.online.service;
+
+/**
+ * @ProjectName: five-groups-couplet
+ * @Author: LiuYunHu
+ * @CreateTime: 2024/4/1
+ * @Description:
+ */
+
+public interface OnlineService {
+}
diff --git a/couplet-modules/couplet-modules-onLine/src/main/java/com/couplet/online/service/impl/OnlineServiceImpl.java b/couplet-modules/couplet-modules-onLine/src/main/java/com/couplet/online/service/impl/OnlineServiceImpl.java
new file mode 100644
index 0000000..d735045
--- /dev/null
+++ b/couplet-modules/couplet-modules-onLine/src/main/java/com/couplet/online/service/impl/OnlineServiceImpl.java
@@ -0,0 +1,16 @@
+package com.couplet.online.service.impl;
+
+import com.couplet.online.service.OnlineService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+/**
+ * @ProjectName: five-groups-couplet
+ * @Author: LiuYunHu
+ * @CreateTime: 2024/4/1
+ * @Description: 车辆上线service层
+ */
+@Service
+@Slf4j
+public class OnlineServiceImpl implements OnlineService {
+}
diff --git a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/service/MqttListen.java b/couplet-modules/couplet-modules-onLine/src/main/java/com/couplet/online/utils/MqttMonitor.java
similarity index 52%
rename from couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/service/MqttListen.java
rename to couplet-modules/couplet-modules-onLine/src/main/java/com/couplet/online/utils/MqttMonitor.java
index 8b914e9..b3b85b3 100644
--- a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/service/MqttListen.java
+++ b/couplet-modules/couplet-modules-onLine/src/main/java/com/couplet/online/utils/MqttMonitor.java
@@ -1,4 +1,4 @@
-package com.couplet.mq.service;
+package com.couplet.online.utils;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.*;
@@ -11,98 +11,101 @@ import javax.annotation.PostConstruct;
/**
* @ProjectName: five-groups-couplet
* @Author: LiuYunHu
- * @CreateTime: 2024/3/28
- * @Description: mqtt客户端
+ * @CreateTime: 2024/4/1
+ * @Description: mqtt监听者
*/
+
@Component
@Slf4j
-public class MqttListen {
+public class MqttMonitor {
/*
* 路径
* */
@Value("${mqtt.server.broker}")
- private String BROKER;
+ private String broker;
/*
* 主题
* */
@Value("${mqtt.server.topic}")
- private String TOPIC;
+ private String topic;
/*
* 客户端id
* */
- @Value("${mqtt.server.clientid}")
- private String CLIENTID;
+ @Value("${mqtt.server.clientId}")
+ private String clientId;
/*
* 用户名
* */
@Value("${mqtt.server.username}")
- private String USERNAME;
+ private String userName;
/*
* 密码
* */
@Value("${mqtt.server.password}")
- private String PASSWORD;
+ private String password;
/*
- * qos
+ * 遗嘱消息qos
* */
@Value("${mqtt.server.qos}")
- private Integer QOS;
-
+ private Integer qos;
+ //随项目启动而执行这个方法
@PostConstruct
public void connect() {
- System.out.println("监听者启动");
+ log.info("mqtt监听者启动");
try {
+ MqttClient client = new MqttClient(broker, clientId, new MemoryPersistence());
- MqttClient client = new MqttClient(BROKER, CLIENTID, new MemoryPersistence());
MqttConnectOptions options = new MqttConnectOptions();
- options.setUserName(USERNAME);
- options.setPassword(PASSWORD.toCharArray());
+ options.setUserName(userName);
+ options.setPassword(password.toCharArray());
//连接超时
- options.setConnectionTimeout(60);
+ options.setConnectionTimeout(10);
- //心跳
+ //心跳时间
options.setKeepAliveInterval(60);
- log.info("连接到:"+BROKER);
+ log.info("mqtt监听者启动成功,连接到:{}", broker);
client.connect(options);
- log.info("连接成功");
+ log.info("连接成功!");
//设置回调
client.setCallback(new MqttCallback() {
@Override
public void connectionLost(Throwable throwable) {
- log.error("连接断开:" + throwable.getMessage());
+ log.error("连接丢失:{}", throwable.getMessage());
}
@Override
- public void messageArrived(String topic, MqttMessage message) {
- log.info("消息到达");
- log.info("接收消息主题:" + topic);
- log.info("接收消息Qos:" + message.getQos());
- log.info("接收消息内容:" + new String(message.getPayload()));
+ public void messageArrived(String topic, MqttMessage mqttMessage) {
+ log.info("消息已送达");
+ log.info("接收消息主题:{}",topic);
+ log.info("接收消息qos:{}", mqttMessage.getQos());
+ log.info("接收消息内容:{}", new String(mqttMessage.getPayload()));
}
@Override
- public void deliveryComplete(IMqttDeliveryToken token) {
- log.info("消息发送成功----------" + token.isComplete());
+ public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
+ log.info("消息发送成功!");
}
});
- client.subscribe(TOPIC, QOS);
+
+ client.subscribe(topic, qos);
} catch (MqttException e) {
+ log.error("mqtt监听者启动失败,{}", e.getMessage());
throw new RuntimeException(e);
}
-
}
+
}
diff --git a/couplet-modules/couplet-modules-onLine/src/main/resources/banner.txt b/couplet-modules/couplet-modules-onLine/src/main/resources/banner.txt
new file mode 100644
index 0000000..a126421
--- /dev/null
+++ b/couplet-modules/couplet-modules-onLine/src/main/resources/banner.txt
@@ -0,0 +1,10 @@
+Spring Boot Version: ${spring-boot.version}
+Spring Application Name: ${spring.application.name}
+ _______ _ _ _________ _ _______
+( ___ )( ( /|( \ \__ __/( ( /|( ____ \
+| ( ) || \ ( || ( ) ( | \ ( || ( \/
+| | | || \ | || | | | | \ | || (__
+| | | || (\ \) || | | | | (\ \) || __)
+| | | || | \ || | | | | | \ || (
+| (___) || ) \ || (____/\___) (___| ) \ || (____/\
+(_______)|/ )_)(_______/\_______/|/ )_)(_______/
diff --git a/couplet-modules/couplet-modules-onLine/src/main/resources/bootstrap.yml b/couplet-modules/couplet-modules-onLine/src/main/resources/bootstrap.yml
new file mode 100644
index 0000000..f690aa8
--- /dev/null
+++ b/couplet-modules/couplet-modules-onLine/src/main/resources/bootstrap.yml
@@ -0,0 +1,43 @@
+# Tomcat
+server:
+ port: 9616
+
+# Spring
+spring:
+ application:
+ # 应用名称
+ name: couplet-online
+ profiles:
+ # 环境配置
+ active: dev
+ cloud:
+ nacos:
+ discovery:
+ # 服务注册地址
+ server-addr: 121.89.211.230:8848
+ namespace: 172469
+ config:
+ # 配置中心地址
+ server-addr: 121.89.211.230:8848
+ namespace: 172469
+ # 配置文件格式
+ file-extension: yml
+ # 共享配置
+ shared-configs:
+ - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
+ main:
+ allow-bean-definition-overriding: true
+logging:
+ level:
+ com.couplet.system.mapper: DEBUG
+
+# 订阅端配置
+mqtt:
+ server:
+ broker: tcp://115.159.47.13:1883
+ username:
+ password:
+ clientId: lyh
+ qos: 0
+ topic: test
+
diff --git a/couplet-modules/couplet-modules-onLine/src/main/resources/logback.xml b/couplet-modules/couplet-modules-onLine/src/main/resources/logback.xml
new file mode 100644
index 0000000..4940ee0
--- /dev/null
+++ b/couplet-modules/couplet-modules-onLine/src/main/resources/logback.xml
@@ -0,0 +1,74 @@
+
+
+
+
+
+
+
+
+
+
+ ${log.pattern}
+
+
+
+
+
+ ${log.path}/info.log
+
+
+
+ ${log.path}/info.%d{yyyy-MM-dd}.log
+
+ 60
+
+
+ ${log.pattern}
+
+
+
+ INFO
+
+ ACCEPT
+
+ DENY
+
+
+
+
+ ${log.path}/error.log
+
+
+
+ ${log.path}/error.%d{yyyy-MM-dd}.log
+
+ 60
+
+
+ ${log.pattern}
+
+
+
+ ERROR
+
+ ACCEPT
+
+ DENY
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/couplet-modules/couplet-modules-onLine/src/main/resources/mapper/online/OnlineMapper.xml b/couplet-modules/couplet-modules-onLine/src/main/resources/mapper/online/OnlineMapper.xml
new file mode 100644
index 0000000..c3ae648
--- /dev/null
+++ b/couplet-modules/couplet-modules-onLine/src/main/resources/mapper/online/OnlineMapper.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
diff --git a/couplet-modules/couplet-modules-vehicle/src/main/java/com/couplet/vehicle/service/impl/VehicleServiceImpl.java b/couplet-modules/couplet-modules-vehicle/src/main/java/com/couplet/vehicle/service/impl/VehicleServiceImpl.java
index 1a4d5f8..12e7591 100644
--- a/couplet-modules/couplet-modules-vehicle/src/main/java/com/couplet/vehicle/service/impl/VehicleServiceImpl.java
+++ b/couplet-modules/couplet-modules-vehicle/src/main/java/com/couplet/vehicle/service/impl/VehicleServiceImpl.java
@@ -190,7 +190,11 @@ public class VehicleServiceImpl extends ServiceImpl impl
//雪花算法生成随机数
SnowflakeIdGenerator idGenerator = new SnowflakeIdGenerator(1, 1);
long randomId = idGenerator.nextId();
- String vin = "VIN" + randomId;
+ //转成字符串,便于切割
+ String vin = "" + randomId;
+
+ //切割,只留后17位
+ vin = vin.substring(vin.length() - 17);
//创建入参对象
diff --git a/couplet-modules/couplet-modules-vehicle/src/test/java/IdTest.java b/couplet-modules/couplet-modules-vehicle/src/test/java/IdTest.java
index 8a754b4..6cfd8e3 100644
--- a/couplet-modules/couplet-modules-vehicle/src/test/java/IdTest.java
+++ b/couplet-modules/couplet-modules-vehicle/src/test/java/IdTest.java
@@ -14,7 +14,20 @@ public class IdTest {
SnowflakeIdGenerator idGenerator = new SnowflakeIdGenerator(1, 1);
long l = idGenerator.nextId();
+ String s = "VIN" + l;
System.out.println(l);
+ System.out.println(s);
+ System.out.println("剪切前长度:" + s.length());
+
+ String last17 = s.substring(s.length() - 17);
+ System.out.println("剪切后:"+last17+" 长度:"+last17.length());
+
+
+ System.out.println("----------------------");
+
+ String s1 = "1224069209961664512";
+ String substring = s1.substring(s1.length() - 17);
+ System.out.println(substring);
}
}