Merge remote-tracking branch 'origin/server_five_liuyunhu' into server_five_xiaoyao
# Conflicts: # couplet-common/couplet-common-system/src/main/java/com/couplet/common/system/domain/SysDept.java # pom.xmlserver_five_liuyunhu
commit
3303cfd0b3
|
@ -62,6 +62,7 @@ public class BaseEntity implements Serializable {
|
|||
/**
|
||||
* 备注
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
|
|
|
@ -83,14 +83,13 @@ public class SysDept extends BaseEntity {
|
|||
/**
|
||||
* 父部门名称
|
||||
*/
|
||||
|
||||
@TableField(exist = false)
|
||||
private String parentName;
|
||||
|
||||
@TableField(exist = false)
|
||||
/**
|
||||
* 子部门
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private List<SysDept> children = new ArrayList<SysDept>();
|
||||
|
||||
public Long getDeptId () {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>couplet-modules-mqtt</artifactId>
|
||||
<artifactId>couplet-modules-mq</artifactId>
|
||||
|
||||
<!-- <properties>-->
|
||||
<!-- <maven.compiler.source>17</maven.compiler.source>-->
|
||||
|
@ -18,7 +18,7 @@
|
|||
<!-- </properties>-->
|
||||
|
||||
<description>
|
||||
couplet-modules-mqttx获取报文模块
|
||||
couplet-modules-mq MQ模块
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
|
@ -91,6 +91,11 @@
|
|||
<version>1.2.5</version>
|
||||
</dependency>
|
||||
|
||||
<!-- RabbitMQ依赖-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
|
@ -1,4 +1,4 @@
|
|||
package com.couplet.mqtt;
|
||||
package com.couplet.mq;
|
||||
|
||||
import com.couplet.common.security.annotation.EnableCustomConfig;
|
||||
import com.couplet.common.security.annotation.EnableMyFeignClients;
|
||||
|
@ -10,15 +10,15 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
* @ProjectName: Default (Template) Project
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/3/28
|
||||
* @Description: 获取报文模块启动类
|
||||
* @Description: rabbitMq模块启动类
|
||||
*/
|
||||
@EnableCustomConfig
|
||||
@EnableCustomSwagger2
|
||||
@EnableMyFeignClients
|
||||
@SpringBootApplication
|
||||
public class CoupletMqttxApplatcaion {
|
||||
public class CoupletMqApplatcaion {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CoupletMqttxApplatcaion.class, args);
|
||||
System.out.println("获取报文模块启动成功");
|
||||
SpringApplication.run(CoupletMqApplatcaion.class, args);
|
||||
System.out.println("获取报文、RabbitMQ模块启动成功");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
package com.couplet.mq.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||
import org.springframework.amqp.support.converter.MessageConverter;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
|
||||
/**
|
||||
* @ProjectName: five-groups-couplet
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/3/29
|
||||
* @Description: rabbitMQ配置类
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class RabbitMQConfig implements RabbitTemplate.ConfirmCallback, RabbitTemplate.ReturnsCallback {
|
||||
// 通过注入的方式获取队列名、交换机名和路由键
|
||||
//队列名
|
||||
@Value("${mq.queueName}")
|
||||
public String queueName;
|
||||
|
||||
//交换机
|
||||
@Value("${mq.exchangeName}")
|
||||
public String exchangeName;
|
||||
|
||||
//路由键
|
||||
@Value(("${mq.routingKey}"))
|
||||
public String routingKey;
|
||||
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
/*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/3/29 21:25
|
||||
* @Description: 创建并返回一个消息转换器,用于转换消息体。
|
||||
* @Param: []
|
||||
* @Return: 返回一个Jackson2JsonMessageConverter实例,用于JSON格式的消息转换。
|
||||
**/
|
||||
@Bean
|
||||
public MessageConverter messageConverter() {
|
||||
return new Jackson2JsonMessageConverter();
|
||||
}
|
||||
|
||||
/*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/3/29 21:26
|
||||
* @Description: 创建并返回一个持久化的队列。
|
||||
* @Param: []
|
||||
* @Return: 返回一个配置好的Queue实例。
|
||||
**/
|
||||
@Bean
|
||||
public Queue queue() {
|
||||
return new Queue(queueName, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/3/29 21:26
|
||||
* @Description: 创建并返回一个直连交换机。
|
||||
* @Param: []
|
||||
* @Return: 返回一个配置好的DirectExchange实例。
|
||||
**/
|
||||
@Bean("exchange")
|
||||
public DirectExchange directExchange() {
|
||||
return new DirectExchange(exchangeName);
|
||||
}
|
||||
|
||||
/*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/3/29 21:27
|
||||
* @Description: 配置并返回RabbitTemplate实例,用于发送消息。
|
||||
* @Param: connectionFactory RabbitMQ连接工厂。
|
||||
* @Return: 配置好的RabbitTemplate实例。
|
||||
**/
|
||||
@Primary
|
||||
@Bean
|
||||
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
|
||||
RabbitTemplate rabbitTempalte = new RabbitTemplate(connectionFactory);
|
||||
this.rabbitTemplate = rabbitTempalte;
|
||||
rabbitTempalte.setMessageConverter(messageConverter());
|
||||
rabbitTempalte();
|
||||
|
||||
return rabbitTempalte;
|
||||
}
|
||||
|
||||
/*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/3/29 21:27
|
||||
* @Description: 配置RabbitTemplate的回调函数。
|
||||
* @Param: []
|
||||
* @Return: void
|
||||
**/
|
||||
public void rabbitTempalte() {
|
||||
rabbitTemplate.setConfirmCallback(this);
|
||||
rabbitTemplate.setReturnsCallback(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/3/29 21:27
|
||||
* @Description: 创建并返回一个绑定,将队列与交换机绑定,并指定路由键
|
||||
* @Param: []
|
||||
* @Return: 返回一个配置好的Binding实例
|
||||
**/
|
||||
@Bean
|
||||
public Binding binding() {
|
||||
return BindingBuilder.bind(queue()).to(directExchange()).with(routingKey);
|
||||
}
|
||||
|
||||
/*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/3/29 21:28
|
||||
* @Description: 消息确认回调函数。
|
||||
* 当消息被交换机成功处理后调用,或当消息未能被正确处理时调用。
|
||||
* @Param: correlationData 关联数据,用于追踪消息
|
||||
* @Param: ack 消息是否被成功处理
|
||||
* @Param: s 附加信息
|
||||
**/
|
||||
@Override
|
||||
public void confirm(CorrelationData correlationData, boolean ack, String s) {
|
||||
if (ack) {
|
||||
log.info("{}消息到达交换机", correlationData.getId());
|
||||
} else {
|
||||
log.error("{}消息丢失", correlationData.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @Author: LiuYunHu
|
||||
* @Date: 2024/3/29 21:29
|
||||
* @Description: 消息返回回调函数。
|
||||
* 当消息未能被正确路由到队列时调用
|
||||
* @Param: returnedMessage 被返回的消息
|
||||
* @Return: void
|
||||
**/
|
||||
@Override
|
||||
public void returnedMessage(ReturnedMessage returnedMessage) {
|
||||
log.error("{}消息未到达队列", returnedMessage.getMessage().getMessageProperties().getMessageId());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.couplet.mq.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.couplet.common.core.utils.uuid.IdUtils;
|
||||
import com.couplet.mq.config.RabbitMQConfig;
|
||||
import com.couplet.mq.domain.Test;
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* @ProjectName: five-groups-couplet
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/3/29
|
||||
* @Description: MQController类
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/mq")
|
||||
@Slf4j
|
||||
public class MqController {
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@PostMapping("/receive")
|
||||
public void receive(@RequestBody Test data) {
|
||||
//创建配置类对象,用于获取配置值
|
||||
RabbitMQConfig config = new RabbitMQConfig();
|
||||
|
||||
rabbitTemplate.convertAndSend(config.exchangeName, config.routingKey, JSON.toJSONString(data) , message -> {
|
||||
message.getMessageProperties().setMessageId(IdUtils.randomUUID());
|
||||
return message;
|
||||
}, new CorrelationData(IdUtils.randomUUID()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
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;
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package com.couplet.mq.service;
|
||||
|
||||
import com.couplet.mq.config.RabbitMQConfig;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @ProjectName: five-groups-couplet
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/3/28
|
||||
* @Description: MQ消费者类
|
||||
*/
|
||||
@RabbitListener(queues = "${mq.queueName}")
|
||||
@Component
|
||||
@Slf4j
|
||||
public class Consumer {
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
@RabbitHandler
|
||||
public void receive(String data, Channel channel, Message message) throws IOException {
|
||||
log.info("消费者接受到数据:{}", data);
|
||||
|
||||
//获取信息的标记
|
||||
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);
|
||||
}
|
||||
|
||||
try {
|
||||
if (add == 1) {
|
||||
log.info("---------------消费者开始消费---------------");
|
||||
|
||||
System.out.println(data);
|
||||
|
||||
log.info("---------------消费者结束消费---------------");
|
||||
}else {
|
||||
log.error("重复消费!");
|
||||
channel.basicReject(deliveryTag, false);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// throw new RuntimeException(e);
|
||||
String s = redisTemplate.opsForValue().get("value:" + messageId);
|
||||
long oldTag = Long.parseLong(s);
|
||||
|
||||
if ((oldTag + 2) != deliveryTag) {
|
||||
log.info("重新入队!");
|
||||
channel.basicNack(deliveryTag, false, true);
|
||||
}else {
|
||||
log.error("三次无法消费,不再入队!");
|
||||
channel.basicNack(deliveryTag, false, false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.couplet.mqtt.service.impl;
|
||||
package com.couplet.mq.service;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
|
@ -6,7 +6,7 @@ server:
|
|||
spring:
|
||||
application:
|
||||
# 应用名称
|
||||
name: couplet-mqtt
|
||||
name: couplet-mq
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
|
@ -40,3 +40,9 @@ mqtt:
|
|||
clientid: mqttx
|
||||
qos: 0
|
||||
topic: test
|
||||
|
||||
# RabbitMQ配置
|
||||
mq:
|
||||
queueName: queue
|
||||
exchangeName: exchange
|
||||
routingKey: routingKey
|
|
@ -1,15 +0,0 @@
|
|||
package com.couplet.mqtt.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @ProjectName: five-groups-couplet
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/3/28
|
||||
* @Description:
|
||||
*/
|
||||
@Component
|
||||
@Mapper
|
||||
public interface MqttMapper {
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package com.couplet.mqtt.service;
|
||||
|
||||
/**
|
||||
* @ProjectName: five-groups-couplet
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/3/28
|
||||
* @Description: MQTT服务接口
|
||||
*/
|
||||
|
||||
public interface MqttService {
|
||||
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package com.couplet.mqtt.service.impl;
|
||||
|
||||
import com.couplet.mqtt.service.MqttService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @ProjectName: five-groups-couplet
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/3/28
|
||||
* @Description: MQTT服务实现类
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class MqttServiceImpl implements MqttService {
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.couplet.mqtt.mapper.MqttMapper">
|
||||
|
||||
|
||||
</mapper>
|
|
@ -5,6 +5,9 @@ import lombok.Data;
|
|||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
|
||||
/**
|
||||
* @ProjectName: five-groups-couplet
|
||||
* @Author: LiuYunHu
|
||||
|
@ -20,11 +23,13 @@ public class VehicleEditParams {
|
|||
/*
|
||||
*车辆id
|
||||
* */
|
||||
@NotNull(message = "车辆id不能为空")
|
||||
private Long vehicleId;
|
||||
|
||||
/*
|
||||
*车辆类型
|
||||
* */
|
||||
@NotNull(message="车辆类型不能为空")
|
||||
private Integer vehicleType;
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package com.couplet.vehicle.exception;
|
||||
|
||||
/**
|
||||
* @ProjectName: five-groups-couplet
|
||||
* @Author: LiuYunHu
|
||||
* @CreateTime: 2024/3/29
|
||||
* @Description: 车辆异常响应
|
||||
*/
|
||||
|
||||
public class VehicleException extends RuntimeException {
|
||||
private int code;
|
||||
private String message;
|
||||
|
||||
public VehicleException(int code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public VehicleException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public VehicleException() {
|
||||
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ import com.couplet.vehicle.domain.LyhVehicle;
|
|||
import com.couplet.vehicle.domain.req.VehicleEditParams;
|
||||
import com.couplet.vehicle.domain.req.VehicleInsertParams;
|
||||
import com.couplet.vehicle.domain.req.VehicleListParams;
|
||||
import com.couplet.vehicle.exception.VehicleException;
|
||||
import com.couplet.vehicle.mapper.VehicleMapper;
|
||||
import com.couplet.vehicle.service.VehicleService;
|
||||
import com.couplet.vehicle.utils.SnowflakeIdGenerator;
|
||||
|
@ -79,7 +80,7 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, LyhVehicle> i
|
|||
|
||||
if (!update) {
|
||||
result = "删除失败";
|
||||
throw new RuntimeException(result);
|
||||
throw new VehicleException(result);
|
||||
}
|
||||
|
||||
result = "删除成功!";
|
||||
|
@ -124,7 +125,7 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, LyhVehicle> i
|
|||
|
||||
if (!update) {
|
||||
result = "编辑失败";
|
||||
throw new RuntimeException(result);
|
||||
throw new VehicleException(result);
|
||||
}
|
||||
|
||||
result = "编辑成功!";
|
||||
|
@ -153,7 +154,7 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, LyhVehicle> i
|
|||
|
||||
if (insert == 0) {
|
||||
result = "新增失败";
|
||||
throw new RuntimeException(result);
|
||||
throw new VehicleException(result);
|
||||
}
|
||||
|
||||
result = "新增成功!";
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<module>couplet-trouble</module>
|
||||
<module>couplet-electronic-fence</module>
|
||||
<module>couplet-modules-vehicle</module>
|
||||
<module>couplet-modules-mqtt</module>
|
||||
<module>couplet-modules-mq</module>
|
||||
<module>couplet-enterprisemanagement</module>
|
||||
</modules>
|
||||
|
||||
|
|
15
pom.xml
15
pom.xml
|
@ -245,6 +245,21 @@
|
|||
<artifactId>couplet-enterprisemanagement-remote</artifactId>
|
||||
<version>${couplet.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 车辆管理模块 -->
|
||||
<dependency>
|
||||
<groupId>com.couplet</groupId>
|
||||
<artifactId>couplet-modules-vehicle</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<!-- RabbitMq模块 -->
|
||||
<dependency>
|
||||
<groupId>com.couplet</groupId>
|
||||
<artifactId>couplet-modules-mq</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
|
Loading…
Reference in New Issue