Merge branch 'server_five' of https://gitea.qinmian.online/five-groups/five-groups-couplet into server_five_fufanrui
# Conflicts: # couplet-modules/couplet-business/pom.xml # couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/VehicleDetectionServiceImpl.java # couplet-modules/couplet-business/src/main/resources/bootstrap.yml # couplet-visual/couplet-monitor/src/main/resources/bootstrap.ymlserver_five_liuyunhu
commit
31e78c3c3c
|
@ -8,7 +8,6 @@ import org.springframework.stereotype.Component;
|
||||||
* @Date: 2024/4/7
|
* @Date: 2024/4/7
|
||||||
* @Description: 事件内容
|
* @Description: 事件内容
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface AnalyzeEventContents {
|
public interface AnalyzeEventContents {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,14 +17,14 @@ public interface AnalyzeEventContents {
|
||||||
/**
|
/**
|
||||||
* 电子围栏
|
* 电子围栏
|
||||||
*/
|
*/
|
||||||
static final String ELECTRONIC_FENCE = "electronic-fence";
|
static final String ELECTRONIC_FENCE = "electronic_fence";
|
||||||
/**
|
/**
|
||||||
* 实时数据
|
* 实时数据
|
||||||
*/
|
*/
|
||||||
static final String REAL_TIME_DATA = "real-time-data";
|
static final String REAL_TIME_DATA = "real_time_data";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 存储
|
* 存储
|
||||||
*/
|
*/
|
||||||
static final String STORED_EVENT = "stored-event";
|
static final String STORED_EVENT = "stored_event";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package com.couplet.analyze.common.event;
|
package com.couplet.analyze.common.event;
|
||||||
|
|
||||||
|
import com.couplet.common.domain.request.RealTimeDataRequest;
|
||||||
import com.couplet.common.redis.service.RedisService;
|
import com.couplet.common.redis.service.RedisService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -11,6 +13,7 @@ import java.util.Set;
|
||||||
* @Description:
|
* @Description:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@Component
|
||||||
public class AnalyzeEventCache {
|
public class AnalyzeEventCache {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -38,6 +41,12 @@ public class AnalyzeEventCache {
|
||||||
public void removeEvent(String vin,String eventName){
|
public void removeEvent(String vin,String eventName){
|
||||||
redisService.deleteSet(encode(vin), eventName);
|
redisService.deleteSet(encode(vin), eventName);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 查询事件
|
||||||
|
*/
|
||||||
|
public void queryEvent(String vin, final RealTimeDataRequest eventName){
|
||||||
|
redisService.setCacheObject(encode(vin), eventName);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 获取事件集合
|
* 获取事件集合
|
||||||
*
|
*
|
||||||
|
@ -47,4 +56,5 @@ public class AnalyzeEventCache {
|
||||||
return redisService.getCacheSet(encode(vin));
|
return redisService.getCacheSet(encode(vin));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,6 @@
|
||||||
<artifactId>couplet-common-event</artifactId>
|
<artifactId>couplet-common-event</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.kafka</groupId>
|
<groupId>org.springframework.kafka</groupId>
|
||||||
<artifactId>spring-kafka</artifactId>
|
<artifactId>spring-kafka</artifactId>
|
||||||
|
|
|
@ -1,203 +1,203 @@
|
||||||
package com.couplet.analyze.msg.consumer;
|
//package com.couplet.analyze.msg.consumer;
|
||||||
|
//
|
||||||
import com.alibaba.fastjson.JSONObject;
|
//import com.alibaba.fastjson.JSONObject;
|
||||||
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
//import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
import com.couplet.analyze.msg.utils.MsgUtils;
|
//import com.couplet.analyze.msg.utils.MsgUtils;
|
||||||
import com.couplet.common.domain.CoupletTroubleCode;
|
//import com.couplet.common.domain.CoupletTroubleCode;
|
||||||
import com.couplet.common.redis.service.RedisService;
|
//import com.couplet.common.redis.service.RedisService;
|
||||||
import com.couplet.remote.RemoteTroubleService;
|
//import com.couplet.remote.RemoteTroubleService;
|
||||||
import com.rabbitmq.client.Channel;
|
//import com.rabbitmq.client.Channel;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
//import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
//import org.springframework.amqp.rabbit.annotation.Queue;
|
||||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
//import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.amqp.core.Message;
|
//import org.springframework.amqp.core.Message;
|
||||||
import org.springframework.stereotype.Component;
|
//import org.springframework.stereotype.Component;
|
||||||
|
//
|
||||||
import java.util.Date;
|
//import java.util.Date;
|
||||||
import java.util.concurrent.CompletableFuture;
|
//import java.util.concurrent.CompletableFuture;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* @author DongXiaoDong
|
// * @author DongXiaoDong
|
||||||
* @version 1.0
|
// * @version 1.0
|
||||||
* @date 2024/4/6 15:37
|
// * @date 2024/4/6 15:37
|
||||||
* @description
|
// * @description
|
||||||
*/
|
// */
|
||||||
@Component
|
//@Component
|
||||||
@Slf4j
|
//@Slf4j
|
||||||
public class CodeConsumer {
|
//public class CodeConsumer {
|
||||||
|
//// @Autowired
|
||||||
|
//// private RedisTemplate<String, String> redisTemplate;
|
||||||
|
//
|
||||||
// @Autowired
|
// @Autowired
|
||||||
// private RedisTemplate<String, String> redisTemplate;
|
// private RedisService redisService;
|
||||||
|
// @Autowired
|
||||||
@Autowired
|
// private RemoteTroubleService remoteTroubleService;
|
||||||
private RedisService redisService;
|
//
|
||||||
@Autowired
|
// @RabbitListener(queuesToDeclare = {@Queue("couplet-code-queue")})
|
||||||
private RemoteTroubleService remoteTroubleService;
|
// public void sendLogQueueConsumer(Message message, CoupletMsgData msgData, Channel channel) {
|
||||||
|
// log.info("日志队列:{},接收到的消息:{},开始消费...","couplet-code-queue", JSONObject.toJSONString(msgData));
|
||||||
@RabbitListener(queuesToDeclare = {@Queue("couplet-code-queue")})
|
// long start = System.currentTimeMillis();
|
||||||
public void sendLogQueueConsumer(Message message, CoupletMsgData msgData, Channel channel) {
|
//
|
||||||
log.info("日志队列:{},接收到的消息:{},开始消费...","couplet-code-queue", JSONObject.toJSONString(msgData));
|
// String messageId = message.getMessageProperties().getMessageId();
|
||||||
long start = System.currentTimeMillis();
|
//
|
||||||
|
// try {
|
||||||
String messageId = message.getMessageProperties().getMessageId();
|
// boolean addToSetIfNotExists = redisService.addToSetIfNotExists("couplet-code-queue", messageId);
|
||||||
|
// if (addToSetIfNotExists) {
|
||||||
try {
|
// //异步保存记录
|
||||||
boolean addToSetIfNotExists = redisService.addToSetIfNotExists("couplet-code-queue", messageId);
|
// CompletableFuture.runAsync(() -> {
|
||||||
if (addToSetIfNotExists) {
|
// CoupletTroubleCode troubleCode = new CoupletTroubleCode();
|
||||||
//异步保存记录
|
// troubleCode.setTroubleStartTime(new Date());
|
||||||
CompletableFuture.runAsync(() -> {
|
// troubleCode.setTroubleVin(msgData.getVin());
|
||||||
CoupletTroubleCode troubleCode = new CoupletTroubleCode();
|
// // 随机生成故障码
|
||||||
troubleCode.setTroubleStartTime(new Date());
|
// String faultCode = MsgUtils.generateGTA();
|
||||||
troubleCode.setTroubleVin(msgData.getVin());
|
// troubleCode.setTroubleCode(faultCode);
|
||||||
// 随机生成故障码
|
//
|
||||||
String faultCode = MsgUtils.generateGTA();
|
// switch (msgData.getVehicleStatus()) {
|
||||||
troubleCode.setTroubleCode(faultCode);
|
// case 0:
|
||||||
|
// troubleCode.setTroublePosition("190");
|
||||||
switch (msgData.getVehicleStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("190");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getChargingStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("191");
|
||||||
switch (msgData.getChargingStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("191");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getOperatingStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("192");
|
||||||
switch (msgData.getOperatingStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("192");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getSocStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("193");
|
||||||
switch (msgData.getSocStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("193");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getChargingEnergyStorageStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("194");
|
||||||
switch (msgData.getChargingEnergyStorageStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("194");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getDriveMotorStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("195");
|
||||||
switch (msgData.getDriveMotorStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("195");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getPositionStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("196");
|
||||||
switch (msgData.getPositionStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("196");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getEasStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("197");
|
||||||
switch (msgData.getEasStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("197");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getPtcStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("198");
|
||||||
switch (msgData.getPtcStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("198");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getEpsStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("199");
|
||||||
switch (msgData.getEpsStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("199");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getAbsStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("200");
|
||||||
switch (msgData.getAbsStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("200");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getMcuStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("201");
|
||||||
switch (msgData.getMcuStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("201");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getHeatingStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("202");
|
||||||
switch (msgData.getHeatingStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("202");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getBatteryStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("203");
|
||||||
switch (msgData.getBatteryStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("203");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getBatteryInsulationStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("204");
|
||||||
switch (msgData.getBatteryInsulationStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("204");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getDcdcStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("205");
|
||||||
switch (msgData.getDcdcStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("205");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// switch (msgData.getChgStatus()) {
|
||||||
break;
|
// case 0:
|
||||||
default:
|
// troubleCode.setTroublePosition("206");
|
||||||
switch (msgData.getChgStatus()) {
|
// troubleCode.setProcessingState(0);
|
||||||
case 0:
|
// break;
|
||||||
troubleCode.setTroublePosition("206");
|
// default:
|
||||||
troubleCode.setProcessingState(0);
|
// // do nothing
|
||||||
break;
|
// break;
|
||||||
default:
|
// }
|
||||||
// do nothing
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// break;
|
||||||
break;
|
// }
|
||||||
}
|
// remoteTroubleService.newFaultData(troubleCode);
|
||||||
break;
|
// });
|
||||||
}
|
// }
|
||||||
remoteTroubleService.newFaultData(troubleCode);
|
// long end = System.currentTimeMillis();
|
||||||
});
|
// log.info("日志队列:{},接收到的消息:{},消费完成,耗时:{}毫秒","couplet-code-queue", JSONObject.toJSONString(msgData), (end-start));
|
||||||
}
|
// } catch (Exception e) {
|
||||||
long end = System.currentTimeMillis();
|
// throw new RuntimeException(e);
|
||||||
log.info("日志队列:{},接收到的消息:{},消费完成,耗时:{}毫秒","couplet-code-queue", JSONObject.toJSONString(msgData), (end-start));
|
// }
|
||||||
} catch (Exception e) {
|
// }
|
||||||
throw new RuntimeException(e);
|
//}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,8 +4,6 @@ import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: LiJiaYao
|
* @Author: LiJiaYao
|
||||||
* @Date: 2024/4/2
|
* @Date: 2024/4/2
|
||||||
|
@ -23,6 +21,6 @@ public interface IncidentMapper {
|
||||||
* 查询是否存在该vin
|
* 查询是否存在该vin
|
||||||
*/
|
*/
|
||||||
// CoupletMsgData queryByIncident(RealTimeDataRequest realTimeDataRequest);
|
// CoupletMsgData queryByIncident(RealTimeDataRequest realTimeDataRequest);
|
||||||
CoupletMsgData queryByIncident(@Param("vin") String vin, @Param("createTime") Date createTime);
|
CoupletMsgData queryByIncident(String vin);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,14 +9,18 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.kafka.clients.consumer.ConsumerConfig;
|
import org.apache.kafka.clients.consumer.ConsumerConfig;
|
||||||
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
||||||
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.*;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
import static com.couplet.analyze.msg.utils.MsgUtils.hexToString;
|
import static com.couplet.analyze.msg.utils.MsgUtils.hexToString;
|
||||||
import static com.couplet.analyze.msg.utils.MsgUtils.sendMsg;
|
import static com.couplet.analyze.msg.utils.MsgUtils.sendMsg;
|
||||||
|
@ -35,29 +39,52 @@ public class ModelsKafkaMessage {
|
||||||
private static final String TOPIC_NAME = "online";
|
private static final String TOPIC_NAME = "online";
|
||||||
private static final String BOOTSTRAP_SERVERS = "39.103.133.136:9092";
|
private static final String BOOTSTRAP_SERVERS = "39.103.133.136:9092";
|
||||||
|
|
||||||
|
|
||||||
|
//线程池,用于异步处理消息到来时的业务逻辑
|
||||||
|
private ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
|
//kafka消费者实例化为类成员变量
|
||||||
|
KafkaConsumer<String, String> consumer;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AnalyzeEventCache analyzeEventCache;
|
private AnalyzeEventCache analyzeEventCache;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//kafka消费者初始化
|
||||||
|
@PostConstruct
|
||||||
|
public void initKafkaConsumer() {
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS);
|
||||||
|
// props.put(ConsumerConfig.GROUP_ID_CONFIG, "my-consumer-group");
|
||||||
|
props.put(ConsumerConfig.GROUP_ID_CONFIG, "ddd");
|
||||||
|
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
|
||||||
|
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
|
||||||
|
|
||||||
|
//消费者
|
||||||
|
consumer = new KafkaConsumer<>(props);
|
||||||
|
//订阅主题
|
||||||
|
consumer.subscribe(Collections.singletonList(TOPIC_NAME));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消费者配置
|
* 消费者配置
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Scheduled(fixedDelay = 50)
|
// @Scheduled(fixedDelay = 50)
|
||||||
|
@PostConstruct
|
||||||
public void consumerMessages() {
|
public void consumerMessages() {
|
||||||
Properties props = new Properties();
|
executorService.execute(this::consumer);
|
||||||
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS);
|
}
|
||||||
props.put(ConsumerConfig.GROUP_ID_CONFIG, "my-consumer-group");
|
|
||||||
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
|
|
||||||
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
|
|
||||||
|
|
||||||
//创建消费者
|
|
||||||
KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
|
|
||||||
|
|
||||||
|
public void consumer() {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
//订阅主题
|
|
||||||
consumer.subscribe(Collections.singletonList(TOPIC_NAME));
|
|
||||||
//持续消费消息
|
//持续消费消息
|
||||||
while (true) {
|
while (true) {
|
||||||
ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100));
|
ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100));
|
||||||
|
@ -77,19 +104,12 @@ public class ModelsKafkaMessage {
|
||||||
// message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
// message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||||
// return message;
|
// return message;
|
||||||
// });
|
// });
|
||||||
|
|
||||||
try {
|
|
||||||
sleep(100);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new VehicleException("睡眠失败" + e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error(e.getMessage());
|
||||||
} finally {
|
|
||||||
consumer.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.couplet.analyze.msg.service.impl;
|
package com.couplet.analyze.msg.service.impl;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.couplet.analyze.common.contents.AnalyzeEventContents;
|
||||||
import com.couplet.analyze.msg.contents.StateConstant;
|
import com.couplet.analyze.msg.contents.StateConstant;
|
||||||
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
import com.couplet.analyze.msg.service.IncidentService;
|
import com.couplet.analyze.msg.service.IncidentService;
|
||||||
|
@ -26,7 +27,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
* @Date: 2024/4/2
|
* @Date: 2024/4/2
|
||||||
* @Description: 故障事件
|
* @Description: 故障事件
|
||||||
*/
|
*/
|
||||||
@Service("breakdown")
|
@Service(AnalyzeEventContents.BREAKDOWN)
|
||||||
public class BreakdownServiceImpl extends KeyExpirationEventMessageListener implements IncidentService {
|
public class BreakdownServiceImpl extends KeyExpirationEventMessageListener implements IncidentService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -93,7 +94,7 @@ public class BreakdownServiceImpl extends KeyExpirationEventMessageListener impl
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "breakdown";
|
return AnalyzeEventContents.BREAKDOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scheduledRedis() {
|
public void scheduledRedis() {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.couplet.analyze.msg.service.impl;
|
package com.couplet.analyze.msg.service.impl;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.couplet.analyze.common.contents.AnalyzeEventContents;
|
||||||
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
import com.couplet.analyze.msg.service.IncidentService;
|
import com.couplet.analyze.msg.service.IncidentService;
|
||||||
import com.couplet.common.core.text.Convert;
|
import com.couplet.common.core.text.Convert;
|
||||||
|
@ -13,14 +14,16 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: LiJiaYao
|
* @Author: LiJiaYao
|
||||||
* @Date: 2024/4/2
|
* @Date: 2024/4/2
|
||||||
* @Description: 电子围栏事件服务实现类
|
* @Description: 电子围栏事件服务实现类
|
||||||
*/
|
*/
|
||||||
@Service("electronic-fence")
|
@Service(AnalyzeEventContents.ELECTRONIC_FENCE)
|
||||||
@Log4j2
|
@Log4j2
|
||||||
public class ElectronicFenceServiceImpl implements IncidentService {
|
public class ElectronicFenceServiceImpl implements IncidentService {
|
||||||
|
|
||||||
|
@ -39,56 +42,44 @@ public class ElectronicFenceServiceImpl implements IncidentService {
|
||||||
|
|
||||||
log.info("电子围栏事件开始.......");
|
log.info("电子围栏事件开始.......");
|
||||||
|
|
||||||
String fenceKey="fence";
|
String fenceKey = "车辆vin和电子围栏:" + coupletMsgData.getVin();
|
||||||
|
|
||||||
// redisService.getCacheSet()
|
|
||||||
ArrayList<Fence> fences = new ArrayList<>();
|
|
||||||
if (redisService.hasKey(fenceKey)) {
|
if (redisService.hasKey(fenceKey)) {
|
||||||
|
Set<Fence> cacheSet = redisService.getCacheSet(fenceKey);
|
||||||
log.info("电子围栏事件redis存在.......");
|
log.info("电子围栏事件redis存在.......");
|
||||||
// redisService.getCacheObject();
|
|
||||||
// for (String s : fence) {
|
|
||||||
// Fence parseObject = JSON.parseObject(s, Fence.class);
|
|
||||||
// fences.add(parseObject);
|
|
||||||
// }
|
|
||||||
// jingdu;
|
// jingdu;
|
||||||
// longitude;
|
// longitude;
|
||||||
// weidu;
|
// weidu;
|
||||||
// latitude;
|
// latitude;
|
||||||
for (Fence data : fences) {
|
for (Fence fence : cacheSet) {
|
||||||
|
String fenceLongitudeLatitude = fence.getFenceLongitudeLatitude();
|
||||||
String fenceLongitudeLatitude = data.getFenceLongitudeLatitude();
|
|
||||||
/**
|
/**
|
||||||
* 先通过;号切割
|
* 先通过;后切割
|
||||||
*/
|
*/
|
||||||
String[] split = fenceLongitudeLatitude.split(";");
|
String[] split = fenceLongitudeLatitude.split(";");
|
||||||
for (String s : split) {
|
for (String s : split) {
|
||||||
|
|
||||||
String[] strings = s.split(",");
|
String[] strings = s.split(",");
|
||||||
if (strings.length == 2){
|
if (strings.length == 2) {
|
||||||
// 经度
|
// 经度
|
||||||
Double trim = Double.valueOf(strings[0].trim());
|
Double trim = Double.valueOf(strings[0].trim());
|
||||||
// 纬度
|
// 纬度
|
||||||
Double trim1 = Double.valueOf(strings[1].trim());
|
Double trim1 = Double.valueOf(strings[1].trim());
|
||||||
boolean a = trim <= Double.valueOf(coupletMsgData.getLongitude());
|
boolean a = trim <= Double.valueOf(coupletMsgData.getLongitude());
|
||||||
boolean b = trim1 <= Double.valueOf(coupletMsgData.getLatitude());
|
boolean b = trim1 <= Double.valueOf(coupletMsgData.getLatitude());
|
||||||
if (a && b){
|
if (a && b) {
|
||||||
log.info("电子围栏报警啦!!!!您的车驶出范围啦!!!");
|
log.info("电子围栏报警啦!!!!您的车驶出范围啦!!!");
|
||||||
}else {
|
} else {
|
||||||
log.info("电子围栏报警啦!!!!正常啦!!!");
|
log.info("电子围栏报警啦!!!!正常啦!!!");
|
||||||
}
|
}
|
||||||
log.info("经度是:"+trim);
|
log.info("经度是:" + trim);
|
||||||
log.info("纬度是:"+trim1);
|
log.info("纬度是:" + trim1);
|
||||||
}else {
|
} else {
|
||||||
throw new RuntimeException("电子围栏经纬度格式错误"+strings);
|
throw new RuntimeException("电子围栏经纬度格式错误" + strings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// log.info("更改的电子围栏内容是:"+fence);
|
|
||||||
log.info("电子围栏事件结束.......");
|
log.info("电子围栏事件结束.......");
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("电子围栏事件结束.......");
|
log.info("电子围栏事件结束.......");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,7 +87,7 @@ public class ElectronicFenceServiceImpl implements IncidentService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "electronic-fence";
|
return AnalyzeEventContents.ELECTRONIC_FENCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,26 +1,25 @@
|
||||||
package com.couplet.analyze.msg.service.impl;
|
package com.couplet.analyze.msg.service.impl;
|
||||||
|
|
||||||
|
import com.couplet.analyze.common.contents.AnalyzeEventContents;
|
||||||
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
import com.couplet.analyze.msg.mapper.IncidentMapper;
|
import com.couplet.analyze.msg.mapper.IncidentMapper;
|
||||||
import com.couplet.analyze.msg.service.IncidentService;
|
import com.couplet.analyze.msg.service.IncidentService;
|
||||||
import com.couplet.analyze.msg.service.impl.realTimeData.RealTimeJudge;
|
import com.couplet.analyze.msg.service.impl.realTimeData.RealTimeJudge;
|
||||||
import com.couplet.common.core.utils.StringUtils;
|
|
||||||
import com.couplet.common.domain.request.RealTimeDataRequest;
|
import com.couplet.common.domain.request.RealTimeDataRequest;
|
||||||
import com.couplet.common.redis.service.RedisService;
|
import com.couplet.common.redis.service.RedisService;
|
||||||
import com.couplet.remote.RemoteRealTimeService;
|
import com.couplet.remote.RemoteRealTimeService;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: LiJiaYao
|
* @Author: LiJiaYao
|
||||||
* @Date: 2024/4/2
|
* @Date: 2024/4/2
|
||||||
* @Description: 实时数据事件
|
* @Description: 实时数据事件
|
||||||
*/
|
*/
|
||||||
@Service("real-time-data")
|
@Service(AnalyzeEventContents.REAL_TIME_DATA)
|
||||||
@Log4j2
|
@Log4j2
|
||||||
public class RealTimeDataServiceImpl implements IncidentService {
|
public class RealTimeDataServiceImpl implements IncidentService {
|
||||||
|
|
||||||
|
@ -32,8 +31,6 @@ public class RealTimeDataServiceImpl implements IncidentService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
@Autowired
|
|
||||||
private RemoteRealTimeService remoteRealTimeService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 实时数据事件
|
* 实时数据事件
|
||||||
|
@ -42,21 +39,22 @@ public class RealTimeDataServiceImpl implements IncidentService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void incident(CoupletMsgData coupletMsgData) {
|
public void incident(CoupletMsgData coupletMsgData) {
|
||||||
|
|
||||||
log.info("实时数据事件开始.....");
|
log.info("实时数据事件开始.....");
|
||||||
|
|
||||||
RealTimeDataRequest cacheObject = redisService.getCacheObject("vin:" + coupletMsgData.getVin());
|
RealTimeDataRequest cacheObject = redisService.getCacheObject("vin:" + coupletMsgData.getVin());
|
||||||
|
//判断是否有缓存数据
|
||||||
if (RealTimeJudge.addRealTime(cacheObject)) {
|
|
||||||
log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据一致,开始传输实时数据", coupletMsgData.getVin(), cacheObject);
|
|
||||||
CoupletMsgData query = incidentMapper.queryByIncident(coupletMsgData.getVin(), new Date());
|
|
||||||
redisService.setCacheObject("vin:" + cacheObject.getVin(), query);
|
|
||||||
} else {
|
|
||||||
log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据不一致,开始传输实时数据", coupletMsgData.getVin(), cacheObject);
|
|
||||||
}
|
|
||||||
if (RealTimeJudge.isJudge(coupletMsgData.getVin())) {
|
if (RealTimeJudge.isJudge(coupletMsgData.getVin())) {
|
||||||
log.info("有实时数据,值为:[{}]开始传输实时数据", coupletMsgData.getVin());
|
log.info("有实时数据,值为:[{}]开始传输实时数据", coupletMsgData.getVin());
|
||||||
|
//判断数据是否一致,
|
||||||
|
// if (RealTimeJudge.addRealTime(cacheObject)) {
|
||||||
|
log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据一致,开始传输实时数据", coupletMsgData.getVin(), cacheObject);
|
||||||
|
CoupletMsgData query = incidentMapper.queryByIncident(coupletMsgData.getVin());
|
||||||
|
redisService.setCacheObject("vin:query:" + cacheObject.getVin(), query);
|
||||||
|
redisService.expire("vin:"+cacheObject.getVin(),10, TimeUnit.MINUTES);
|
||||||
|
// } else {
|
||||||
|
// log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据不一致,开始传输实时数据", coupletMsgData.getVin(), cacheObject);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("[{}]开始传输实时数据", coupletMsgData.getVin());
|
log.info("[{}]开始传输实时数据", coupletMsgData.getVin());
|
||||||
|
|
||||||
log.info("实时数据事件结束.....");
|
log.info("实时数据事件结束.....");
|
||||||
|
@ -70,6 +68,6 @@ public class RealTimeDataServiceImpl implements IncidentService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "real-time-data";
|
return AnalyzeEventContents.REAL_TIME_DATA;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.couplet.analyze.msg.service.impl;
|
package com.couplet.analyze.msg.service.impl;
|
||||||
|
|
||||||
|
import com.couplet.analyze.common.contents.AnalyzeEventContents;
|
||||||
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
import com.couplet.analyze.msg.mapper.IncidentMapper;
|
import com.couplet.analyze.msg.mapper.IncidentMapper;
|
||||||
import com.couplet.analyze.msg.service.IncidentService;
|
import com.couplet.analyze.msg.service.IncidentService;
|
||||||
|
@ -12,7 +13,7 @@ import org.springframework.stereotype.Service;
|
||||||
* @Date: 2024/4/2
|
* @Date: 2024/4/2
|
||||||
* @Description: 事件存储服务
|
* @Description: 事件存储服务
|
||||||
*/
|
*/
|
||||||
@Service("stored-event")
|
@Service(AnalyzeEventContents.STORED_EVENT)
|
||||||
@Log4j2
|
@Log4j2
|
||||||
public class StoredEventServiceImpl implements IncidentService {
|
public class StoredEventServiceImpl implements IncidentService {
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -36,6 +37,6 @@ public class StoredEventServiceImpl implements IncidentService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "stored-event";
|
return AnalyzeEventContents.STORED_EVENT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,11 @@
|
||||||
</insert>
|
</insert>
|
||||||
<select id="queryByIncident" resultType="com.couplet.analyze.msg.domain.CoupletMsgData"
|
<select id="queryByIncident" resultType="com.couplet.analyze.msg.domain.CoupletMsgData"
|
||||||
parameterType="com.couplet.common.domain.request.RealTimeDataRequest">
|
parameterType="com.couplet.common.domain.request.RealTimeDataRequest">
|
||||||
SELECT * FROM couplet_msg_data WHERE vin=#{vin} and create_time = #{createTime}
|
SELECT *
|
||||||
|
FROM couplet_msg_data
|
||||||
|
WHERE vin = #{vin}
|
||||||
|
ORDER BY create_time DESC
|
||||||
|
LIMIT 1;
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,11 @@
|
||||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.couplet</groupId>
|
||||||
|
<artifactId>couplet-common-event</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- RabbitMQ依赖-->
|
<!-- RabbitMQ依赖-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
@ -101,6 +106,10 @@
|
||||||
<groupId>com.couplet</groupId>
|
<groupId>com.couplet</groupId>
|
||||||
<artifactId>couplet-modules-mq</artifactId>
|
<artifactId>couplet-modules-mq</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.couplet</groupId>
|
||||||
|
<artifactId>couplet-common-event</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.couplet</groupId>
|
<groupId>com.couplet</groupId>
|
||||||
<artifactId>couplet-analyze-msg</artifactId>
|
<artifactId>couplet-analyze-msg</artifactId>
|
||||||
|
|
|
@ -93,4 +93,13 @@ public class SysTroubleController extends BaseController {
|
||||||
troubleService.newFaultData(code);
|
troubleService.newFaultData(code);
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询故障的状态并处理
|
||||||
|
*/
|
||||||
|
@PostMapping("/getUpdState")
|
||||||
|
public Result<?> getUpdState(@RequestBody CoupletTroubleCode code) {
|
||||||
|
int updateState = troubleService.updateState(code);
|
||||||
|
return Result.success(updateState);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,4 +28,6 @@ public interface FenAndLogoMapper extends BaseMapper<Fence> {
|
||||||
* @param aLong
|
* @param aLong
|
||||||
*/
|
*/
|
||||||
List<Fence> queryByFenceAndLogoIds(FenceAndLogeRequest aLong);
|
List<Fence> queryByFenceAndLogoIds(FenceAndLogeRequest aLong);
|
||||||
|
|
||||||
|
List<Fence> findFencesByLogoId(@Param("logoId") Long logoId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,4 +29,6 @@ public interface SysTroubleMapper extends BaseMapper<CoupletTroubleCode> {
|
||||||
void newFaultData(CoupletTroubleCode code);
|
void newFaultData(CoupletTroubleCode code);
|
||||||
|
|
||||||
void cleanTroubleCode();
|
void cleanTroubleCode();
|
||||||
|
|
||||||
|
int updateState(CoupletTroubleCode code);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,4 +28,9 @@ public interface FenAndLogoService extends IService<Fence> {
|
||||||
*/
|
*/
|
||||||
List<Fence> queryByFenceAndLogoIds(FenceAndLogeRequest request);
|
List<Fence> queryByFenceAndLogoIds(FenceAndLogeRequest request);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 通过标识id查询围栏id
|
||||||
|
* */
|
||||||
|
List<Fence> findFencesByLogoId(Long logoId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,4 +26,6 @@ public interface SysTroubleService extends IService<CoupletTroubleCode> {
|
||||||
void newFaultData(CoupletTroubleCode code);
|
void newFaultData(CoupletTroubleCode code);
|
||||||
|
|
||||||
void cleanTroubleCode();
|
void cleanTroubleCode();
|
||||||
|
|
||||||
|
int updateState(CoupletTroubleCode code);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,4 +47,14 @@ public class FenAndLogoServiceImpl extends ServiceImpl<FenAndLogoMapper, Fence>
|
||||||
|
|
||||||
return fenAndLogoMapper.queryByFenceAndLogoIds(request);
|
return fenAndLogoMapper.queryByFenceAndLogoIds(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 通过标识id查询围栏信息
|
||||||
|
* */
|
||||||
|
@Override
|
||||||
|
public List<Fence> findFencesByLogoId(Long logoId) {
|
||||||
|
|
||||||
|
|
||||||
|
return fenAndLogoMapper.findFencesByLogoId(logoId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import com.couplet.common.domain.request.FenceRequest;
|
||||||
import com.couplet.common.domain.request.FenceUpdateRequest;
|
import com.couplet.common.domain.request.FenceUpdateRequest;
|
||||||
import com.couplet.common.redis.service.RedisService;
|
import com.couplet.common.redis.service.RedisService;
|
||||||
import com.couplet.common.security.utils.SecurityUtils;
|
import com.couplet.common.security.utils.SecurityUtils;
|
||||||
import com.couplet.mq.remote.RemoteFenceService;
|
//import com.couplet.mq.remote.RemoteFenceService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -47,8 +47,8 @@ public class FenceServiceImpl extends ServiceImpl<FenceMapper, Fence> implements
|
||||||
/**
|
/**
|
||||||
* 远程调用队列服务
|
* 远程调用队列服务
|
||||||
*/
|
*/
|
||||||
@Autowired
|
// @Autowired
|
||||||
private RemoteFenceService remoteFenceService;
|
// private RemoteFenceService remoteFenceService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Fence> pageQuery(FenceConfig fenceConfig) {
|
public List<Fence> pageQuery(FenceConfig fenceConfig) {
|
||||||
|
@ -67,7 +67,7 @@ public class FenceServiceImpl extends ServiceImpl<FenceMapper, Fence> implements
|
||||||
*/
|
*/
|
||||||
redisTemplate.opsForValue().set("changeFenceStatus", JSON.toJSONString(fenceUpdateRequest), 10, TimeUnit.MINUTES);
|
redisTemplate.opsForValue().set("changeFenceStatus", JSON.toJSONString(fenceUpdateRequest), 10, TimeUnit.MINUTES);
|
||||||
|
|
||||||
remoteFenceService.fenceQueue(fenceUpdateRequest);
|
// remoteFenceService.fenceQueue(fenceUpdateRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -58,4 +58,14 @@ public class SysTroubleServiceImpl extends ServiceImpl<SysTroubleMapper, Couplet
|
||||||
sysTroubleMapper.cleanTroubleCode();
|
sysTroubleMapper.cleanTroubleCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取故障状态
|
||||||
|
* @param code
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int updateState(CoupletTroubleCode code) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package com.couplet.business.server.service.impl;
|
package com.couplet.business.server.service.impl;
|
||||||
|
|
||||||
|
import afu.org.checkerframework.checker.units.qual.A;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
|
import com.couplet.analyze.common.event.AnalyzeEventCache;
|
||||||
import com.couplet.business.server.mapper.VehicleDetectionMapper;
|
import com.couplet.business.server.mapper.VehicleDetectionMapper;
|
||||||
import com.couplet.business.server.service.VehicleDetectionService;
|
import com.couplet.business.server.service.VehicleDetectionService;
|
||||||
import com.couplet.business.server.service.VehicleManageService;
|
import com.couplet.business.server.service.VehicleManageService;
|
||||||
|
@ -21,6 +23,7 @@ import springfox.documentation.spring.web.json.Json;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author fufanrui
|
* @author fufanrui
|
||||||
|
@ -36,10 +39,14 @@ public class VehicleDetectionServiceImpl implements VehicleDetectionService{
|
||||||
private VehicleDetectionMapper vehicleDetectionMapper;
|
private VehicleDetectionMapper vehicleDetectionMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
@Autowired
|
||||||
|
private AnalyzeEventCache analyzeEventCache;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Vehicle> detectionList() {
|
public List<Vehicle> detectionList() {
|
||||||
return vehicleDetectionMapper.detectionList();
|
List<Vehicle> vehicles = vehicleDetectionMapper.detectionList();
|
||||||
|
|
||||||
|
return vehicles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -58,6 +65,8 @@ public class VehicleDetectionServiceImpl implements VehicleDetectionService{
|
||||||
Long userId = SecurityUtils.getUserId();
|
Long userId = SecurityUtils.getUserId();
|
||||||
realTimeDataRequest.setVin(vin);
|
realTimeDataRequest.setVin(vin);
|
||||||
realTimeDataRequest.setUserId(userId);
|
realTimeDataRequest.setUserId(userId);
|
||||||
|
// analyzeEventCache.queryEvent("查询实时数据"+vin,realTimeDataRequest);
|
||||||
|
// redisService.expire("查询实时数据"+vin,4,TimeUnit.MINUTES);
|
||||||
redisService.setVinAndUserId(realTimeDataRequest);
|
redisService.setVinAndUserId(realTimeDataRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,18 @@ package com.couplet.business.server.service.impl;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.couplet.analyze.common.contents.AnalyzeEventContents;
|
||||||
|
import com.couplet.analyze.common.event.AnalyzeEventCache;
|
||||||
import com.couplet.business.server.mapper.VehicleMapper;
|
import com.couplet.business.server.mapper.VehicleMapper;
|
||||||
|
import com.couplet.business.server.service.FenAndLogoService;
|
||||||
import com.couplet.business.server.service.VehicleAndLogoService;
|
import com.couplet.business.server.service.VehicleAndLogoService;
|
||||||
import com.couplet.business.server.service.VehicleService;
|
import com.couplet.business.server.service.VehicleService;
|
||||||
import com.couplet.business.server.service.VehicleTypeService;
|
import com.couplet.business.server.service.VehicleTypeService;
|
||||||
import com.couplet.common.core.domain.Result;
|
import com.couplet.common.core.domain.Result;
|
||||||
import com.couplet.common.core.utils.StringUtils;
|
import com.couplet.common.core.utils.StringUtils;
|
||||||
import com.couplet.common.core.utils.uuid.UUID;
|
import com.couplet.common.core.utils.uuid.UUID;
|
||||||
|
import com.couplet.common.domain.Fence;
|
||||||
import com.couplet.common.domain.Vehicle;
|
import com.couplet.common.domain.Vehicle;
|
||||||
import com.couplet.common.domain.VehicleMiddle;
|
|
||||||
import com.couplet.common.domain.VehicleType;
|
import com.couplet.common.domain.VehicleType;
|
||||||
import com.couplet.common.domain.request.VehicleEditParams;
|
import com.couplet.common.domain.request.VehicleEditParams;
|
||||||
import com.couplet.common.domain.request.VehicleInsertParams;
|
import com.couplet.common.domain.request.VehicleInsertParams;
|
||||||
|
@ -21,8 +24,12 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ProjectName: five-groups-couplet
|
* @ProjectName: five-groups-couplet
|
||||||
|
@ -52,6 +59,12 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
|
||||||
@Autowired
|
@Autowired
|
||||||
private VehicleAndLogoService vehicleAndLogoService;
|
private VehicleAndLogoService vehicleAndLogoService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FenAndLogoService fenAndLogoService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AnalyzeEventCache eventCache;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @Author: LiuYunHu
|
* @Author: LiuYunHu
|
||||||
* @Date: 2024/3/26 22:11
|
* @Date: 2024/3/26 22:11
|
||||||
|
@ -119,6 +132,9 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
|
||||||
Result.error(result);
|
Result.error(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//刷新set缓存
|
||||||
|
reCache();
|
||||||
|
|
||||||
result = "删除成功!";
|
result = "删除成功!";
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -132,6 +148,7 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
|
||||||
* @Return: java.lang.String
|
* @Return: java.lang.String
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public String editById(VehicleEditParams editParams) {
|
public String editById(VehicleEditParams editParams) {
|
||||||
String result = "";
|
String result = "";
|
||||||
|
|
||||||
|
@ -175,16 +192,8 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
|
||||||
vehicleAndLogoService.vehicleBindLogo(editParams.getVehicleId(), editParams.getLogoIds());
|
vehicleAndLogoService.vehicleBindLogo(editParams.getVehicleId(), editParams.getLogoIds());
|
||||||
|
|
||||||
|
|
||||||
// //mq
|
//刷新set缓存
|
||||||
// List<Long> logoList = getBindLogoById(editParams.getVehicleId());
|
reCache();
|
||||||
// if (0 != logoList.size()) {
|
|
||||||
// String ids = "";
|
|
||||||
// for (Long l : logoList) {
|
|
||||||
// ids = "," + l;
|
|
||||||
// }
|
|
||||||
// ids = ids.substring(1);
|
|
||||||
// remoteFenceService.vehicleQueue(editParams.getVehicleId() + "-" + ids);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
result = "编辑成功!";
|
result = "编辑成功!";
|
||||||
|
@ -200,6 +209,7 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
|
||||||
* @Return: java.lang.String
|
* @Return: java.lang.String
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public String insert(VehicleInsertParams insertParams) {
|
public String insert(VehicleInsertParams insertParams) {
|
||||||
String result = "";
|
String result = "";
|
||||||
|
|
||||||
|
@ -250,20 +260,17 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
|
||||||
Result.error(result);
|
Result.error(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//获取新增的车辆id值
|
//获取新增的车辆id值
|
||||||
//执行添加电子围栏
|
//执行添加电子围栏
|
||||||
int i = vehicleAndLogoService.vehicleBindLogo(vehicle.getVehicleId(), insertParams.getLogoIds());
|
int i = vehicleAndLogoService.vehicleBindLogo(vehicle.getVehicleId(), insertParams.getLogoIds());
|
||||||
|
|
||||||
//
|
|
||||||
// List<Long> logoList = getBindLogoById(vehicle.getVehicleId());
|
//刷新set缓存
|
||||||
// if (0 != logoList.size()) {
|
reCache();
|
||||||
// String ids = "";
|
|
||||||
// for (Long l : logoList) {
|
//加入事件缓存
|
||||||
// ids = "," + l;
|
reEvent();
|
||||||
// }
|
|
||||||
// ids = ids.substring(1);
|
|
||||||
// remoteFenceService.vehicleQueue(vehicle.getVehicleId() + "-" + ids);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
result = "新增成功!";
|
result = "新增成功!";
|
||||||
|
@ -304,14 +311,19 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Vehicle> vehicleAll() {
|
public List<Vehicle> vehicleAll() {
|
||||||
return vehicleMapper.vehicleAll();
|
return vehicleMapper.vehicleAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//通过vin修改车辆上下线的状态
|
/*
|
||||||
|
* @Author: LiuYunHu
|
||||||
|
* @Date: 2024/4/8 14:11
|
||||||
|
* @Description: 通过vin修改车辆上下线的状态
|
||||||
|
* @Param: [vin, status]
|
||||||
|
* @Return: java.lang.Integer
|
||||||
|
**/
|
||||||
@Override
|
@Override
|
||||||
public Integer onOrOutLineByVIN(String vin, int status) {
|
public Integer onOrOutLineByVIN(String vin, int status) {
|
||||||
|
|
||||||
|
@ -320,9 +332,16 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer addVehicle(Long userId, List<Long> vehicleIds) {
|
public Integer addVehicle(Long userId, List<Long> vehicleIds) {
|
||||||
return vehicleMapper.addVehicle(userId,vehicleIds);
|
return vehicleMapper.addVehicle(userId, vehicleIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @Author: LiuYunHu
|
||||||
|
* @Date: 2024/4/8 14:11
|
||||||
|
* @Description: 通过vin查询车辆,因为是plus,所以是List
|
||||||
|
* @Param: [vin]
|
||||||
|
* @Return: java.util.List<com.couplet.common.domain.Vehicle>
|
||||||
|
**/
|
||||||
@Override
|
@Override
|
||||||
public List<Vehicle> findByVIN(String vin) {
|
public List<Vehicle> findByVIN(String vin) {
|
||||||
|
|
||||||
|
@ -338,32 +357,31 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
@Scheduled(cron = "0/1 * * * * *")
|
* @Author: LiuYunHu
|
||||||
public void aa() {
|
* @Date: 2024/4/8 14:12
|
||||||
System.out.println("********************************************************");
|
* @Description: 定时执行,查询缓存中下线的车辆,修改其状态
|
||||||
}
|
* @Param: []
|
||||||
|
* @Return: void
|
||||||
//判断车辆是否下线
|
**/
|
||||||
@Scheduled(cron = "0/1 * * * * *")
|
@Scheduled(cron = "0/1 * * * * *")
|
||||||
public void downLine() {
|
public void downLine() {
|
||||||
log.info("定时器启动");
|
log.info("定时器启动");
|
||||||
//先查询车辆列表
|
//先查询车辆列表
|
||||||
List<Vehicle> list = this.list(new VehicleListParams(null, null, null, null));
|
List<Vehicle> list = this.list(new VehicleListParams(null, null, null, null));
|
||||||
|
|
||||||
|
|
||||||
list.forEach(vehicle -> {
|
list.forEach(vehicle -> {
|
||||||
try {
|
try {
|
||||||
//只针对已经上线的车辆
|
//只针对已经上线的车辆
|
||||||
if (redis.hasKey(vehicle.getVin())) {
|
if (redis.hasKey("已上线的车辆vin:" + vehicle.getVin())) {
|
||||||
|
|
||||||
//如果vin的缓存 时间还剩一秒,则判断为已经下线
|
//如果vin的缓存 时间还剩一秒,则判断为已经下线
|
||||||
if (redis.getExpire(vehicle.getVin()) <= 3) {
|
if (redis.getExpire("已上线的车辆vin:" + vehicle.getVin()) <= 3) {
|
||||||
log.info(vehicle.getVin() + "的车辆已经下线");
|
log.info(vehicle.getVin() + "的车辆已经下线");
|
||||||
|
|
||||||
//执行修改下线状态的方法
|
//执行修改下线状态的方法
|
||||||
// Integer i = this.onOrOutLineByVIN(vehicle.getVin() + "," + 0);
|
// Integer i = this.onOrOutLineByVIN(vehicle.getVin() + "," + 0);
|
||||||
Integer i = this.onOrOutLineByVIN(vehicle.getVin() , 0);
|
Integer i = this.onOrOutLineByVIN(vehicle.getVin(), 0);
|
||||||
|
|
||||||
if (0 == i) {
|
if (0 == i) {
|
||||||
log.error("下线状态修改失败");
|
log.error("下线状态修改失败");
|
||||||
|
@ -380,4 +398,69 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @Author: LiuYunHu
|
||||||
|
* @Date: 2024/4/8 14:14
|
||||||
|
* @Description: 刷新缓存中 的数据 车辆绑定标识的缓存
|
||||||
|
* @Param: []
|
||||||
|
* @Return: void
|
||||||
|
**/
|
||||||
|
// @Scheduled(cron = "0/3 * * * * *")
|
||||||
|
|
||||||
|
//初始化
|
||||||
|
@PostConstruct
|
||||||
|
public void reCache() {
|
||||||
|
//刷新缓存执行开始
|
||||||
|
|
||||||
|
//先获取所有车辆的信息
|
||||||
|
List<Vehicle> list = list(new VehicleListParams());
|
||||||
|
|
||||||
|
list.forEach(vehicle -> {
|
||||||
|
//通过车辆的id获取对应的标识集合
|
||||||
|
List<Long> bindLogoById = getBindLogoById(vehicle.getVehicleId());
|
||||||
|
|
||||||
|
//遍历标识集合
|
||||||
|
bindLogoById.forEach(logoId -> {
|
||||||
|
|
||||||
|
//存标识id 的set
|
||||||
|
HashSet<Long> logos = new HashSet<>();
|
||||||
|
logos.add(logoId);
|
||||||
|
//存入redis
|
||||||
|
redis.setCacheSet("车辆vin和标识:" + vehicle.getVin(), logos);
|
||||||
|
redis.expire("车辆vin和标识:" + vehicle.getVin(), 2, TimeUnit.MINUTES);
|
||||||
|
|
||||||
|
|
||||||
|
//通过标识id获取标识绑定的电子围栏集合
|
||||||
|
List<Fence> fences = fenAndLogoService.findFencesByLogoId(logoId);
|
||||||
|
//遍历电子围栏集合
|
||||||
|
fences.forEach(fence -> {
|
||||||
|
HashSet<Fence> fanceSet = new HashSet<>();
|
||||||
|
fanceSet.add(fence);
|
||||||
|
//存入redis
|
||||||
|
redis.setCacheSet("车辆vin和电子围栏:" + vehicle.getVin(), fanceSet);
|
||||||
|
redis.expire("车辆vin和电子围栏:" + vehicle.getVin(), 2, TimeUnit.MINUTES);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @Author: LiuYunHu
|
||||||
|
* @Date: 2024/4/8 19:39
|
||||||
|
* @Description: 初始化 车辆事件 默认车辆有所有事件
|
||||||
|
* @Param: []
|
||||||
|
* @Return: void
|
||||||
|
**/
|
||||||
|
@PostConstruct
|
||||||
|
public void reEvent() {
|
||||||
|
List<Vehicle> list = list(new VehicleListParams());
|
||||||
|
|
||||||
|
list.forEach(vehicle -> {
|
||||||
|
eventCache.addEvent(vehicle.getVin(), AnalyzeEventContents.STORED_EVENT);
|
||||||
|
eventCache.addEvent(vehicle.getVin(), AnalyzeEventContents.BREAKDOWN);
|
||||||
|
eventCache.addEvent(vehicle.getVin(), AnalyzeEventContents.ELECTRONIC_FENCE);
|
||||||
|
eventCache.addEvent(vehicle.getVin(), AnalyzeEventContents.REAL_TIME_DATA);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,15 +10,15 @@
|
||||||
<result property="fenceDescription" column="fence_description"/>
|
<result property="fenceDescription" column="fence_description"/>
|
||||||
<result property="fenceLongitudeLatitude" column="fence_longitude_latitude"/>
|
<result property="fenceLongitudeLatitude" column="fence_longitude_latitude"/>
|
||||||
<result property="fenceState" column="fence_state"/>
|
<result property="fenceState" column="fence_state"/>
|
||||||
<result property="createName" column="create_name" />
|
<result property="createName" column="create_name"/>
|
||||||
<result property="updateTime" column="update_time" />
|
<result property="updateTime" column="update_time"/>
|
||||||
<result property="isDelete" column="is_delete" />
|
<result property="isDelete" column="is_delete"/>
|
||||||
<result property="maintainerName" column="maintainer_name" />
|
<result property="maintainerName" column="maintainer_name"/>
|
||||||
<result property="fenceCondition" column="fence_condition" />
|
<result property="fenceCondition" column="fence_condition"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<resultMap id="logoMap" type="com.couplet.common.domain.Logo">
|
<resultMap id="logoMap" type="com.couplet.common.domain.Logo">
|
||||||
<id property="logoId" column="logo_id"/>
|
<id property="logoId" column="logo_id"/>
|
||||||
<result property="logoName" column="logo_name" />
|
<result property="logoName" column="logo_name"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<insert id="addBach">
|
<insert id="addBach">
|
||||||
|
@ -36,11 +36,19 @@
|
||||||
fence_longitude_latitude,
|
fence_longitude_latitude,
|
||||||
logo_name
|
logo_name
|
||||||
FROM couplet_fences_and_logo a
|
FROM couplet_fences_and_logo a
|
||||||
INNER JOIN couplet_fence_info f on a.fences_id=f.fence_id
|
INNER JOIN couplet_fence_info f on a.fences_id = f.fence_id
|
||||||
INNER JOIN couplet_logo_info l on l.logo_id=a.logo_id
|
INNER JOIN couplet_logo_info l on l.logo_id = a.logo_id
|
||||||
left JOIN couplet_vehicle_and_logo c on l.logo_id=c.logo_id
|
left JOIN couplet_vehicle_and_logo c on l.logo_id = c.logo_id
|
||||||
WHERE l.logo_id=#{logoIds} and c.vehicle_id=#{id}
|
WHERE l.logo_id = #{logoIds}
|
||||||
|
and c.vehicle_id = #{id}
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
<select id="findFencesByLogoId" resultType="com.couplet.common.domain.Fence">
|
||||||
|
SELECT fi.*
|
||||||
|
FROM `couplet_fences_and_logo` fal
|
||||||
|
right JOIN couplet_fence_info fi on fal.fences_id = fi.fence_id
|
||||||
|
WHERE fal.logo_id = #{logoId}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
@ -26,6 +26,9 @@
|
||||||
<update id="cleanTroubleCode">
|
<update id="cleanTroubleCode">
|
||||||
truncate table couplet_trouble_code
|
truncate table couplet_trouble_code
|
||||||
</update>
|
</update>
|
||||||
|
<update id="updateState">
|
||||||
|
update couplet_trouble_code set processing_state = 1 where thourble_id = #{troubleId}
|
||||||
|
</update>
|
||||||
|
|
||||||
<select id="selectTroubleList" parameterType="com.couplet.business.server.mapper.SysTroubleMapper" resultMap="SysTroubleResult">
|
<select id="selectTroubleList" parameterType="com.couplet.business.server.mapper.SysTroubleMapper" resultMap="SysTroubleResult">
|
||||||
<include refid="selectTroubleVo"/>
|
<include refid="selectTroubleVo"/>
|
||||||
|
|
|
@ -27,10 +27,10 @@ public class KafkaTest {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
//生产者示例
|
//生产者示例
|
||||||
// produceMessage();
|
produceMessage();
|
||||||
|
|
||||||
//消费者示例
|
//消费者示例
|
||||||
// consumerMessages();
|
consumerMessages();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,33 +61,33 @@ public class KafkaTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
//消费者
|
//消费者
|
||||||
// private static void consumerMessages() {
|
private static void consumerMessages() {
|
||||||
// Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
// props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS);
|
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS);
|
||||||
// props.put(ConsumerConfig.GROUP_ID_CONFIG, "my-consumer-group");
|
props.put(ConsumerConfig.GROUP_ID_CONFIG, "my-consumer-group");
|
||||||
// props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
|
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
|
||||||
// props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
|
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
|
||||||
//
|
|
||||||
// //创建消费者
|
//创建消费者
|
||||||
// KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
|
KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
|
||||||
//
|
|
||||||
// try {
|
try {
|
||||||
//
|
|
||||||
// //订阅主题
|
//订阅主题
|
||||||
// consumer.subscribe(Collections.singletonList(TOPIC_NAME));
|
consumer.subscribe(Collections.singletonList(TOPIC_NAME));
|
||||||
//
|
|
||||||
// //持续消费消息
|
//持续消费消息
|
||||||
// while (true) {
|
while (true) {
|
||||||
// ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100));
|
ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100));
|
||||||
// records.forEach(record -> {
|
records.forEach(record -> {
|
||||||
// System.out.println("消费者接受到的消息值:" + record.value());
|
System.out.println("消费者接受到的消息值:" + record.value());
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
// } catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// e.printStackTrace();
|
e.printStackTrace();
|
||||||
// } finally {
|
} finally {
|
||||||
// consumer.close();
|
consumer.close();
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,15 +35,15 @@ logging:
|
||||||
com.couplet.system.mapper: DEBUG
|
com.couplet.system.mapper: DEBUG
|
||||||
|
|
||||||
# 订阅端配置
|
# 订阅端配置
|
||||||
mqtt:
|
#mqtt:
|
||||||
server:
|
# server:
|
||||||
broker: tcp://8.130.181.16:1883
|
# broker: tcp://8.130.181.16:1883
|
||||||
# broker: tcp://115.159.47.13:1883
|
## broker: tcp://115.159.47.13:1883
|
||||||
username:
|
# username:
|
||||||
password:
|
# password:
|
||||||
clientid: mqttx
|
# clientid: mqttx
|
||||||
qos: 0
|
# qos: 0
|
||||||
topic: test
|
# topic: test
|
||||||
|
|
||||||
# RabbitMQ配置
|
# RabbitMQ配置
|
||||||
mq:
|
mq:
|
||||||
|
|
|
@ -11,11 +11,11 @@
|
||||||
|
|
||||||
<artifactId>couplet-modules-online</artifactId>
|
<artifactId>couplet-modules-online</artifactId>
|
||||||
|
|
||||||
<!-- <properties>-->
|
<!-- <properties>-->
|
||||||
<!-- <maven.compiler.source>17</maven.compiler.source>-->
|
<!-- <maven.compiler.source>17</maven.compiler.source>-->
|
||||||
<!-- <maven.compiler.target>17</maven.compiler.target>-->
|
<!-- <maven.compiler.target>17</maven.compiler.target>-->
|
||||||
<!-- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>-->
|
<!-- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>-->
|
||||||
<!-- </properties>-->
|
<!-- </properties>-->
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
couplet-modules-online车辆上线的模块
|
couplet-modules-online车辆上线的模块
|
||||||
|
@ -91,7 +91,7 @@
|
||||||
<version>1.2.5</version>
|
<version>1.2.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 注入车辆服务,调用接口-->
|
<!-- 注入车辆服务,调用接口-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.couplet</groupId>
|
<groupId>com.couplet</groupId>
|
||||||
<artifactId>couplet-common-business</artifactId>
|
<artifactId>couplet-common-business</artifactId>
|
||||||
|
@ -99,10 +99,6 @@
|
||||||
|
|
||||||
|
|
||||||
<!-- Kafka依赖-->
|
<!-- Kafka依赖-->
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>org.springframework.kafka</groupId>-->
|
|
||||||
<!-- <artifactId>spring-kafka</artifactId>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.kafka</groupId>
|
<groupId>org.apache.kafka</groupId>
|
||||||
<artifactId>kafka-clients</artifactId>
|
<artifactId>kafka-clients</artifactId>
|
||||||
|
|
|
@ -11,7 +11,6 @@ import org.eclipse.paho.client.mqttv3.*;
|
||||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
@ -184,7 +183,7 @@ public class MqttMonitor {
|
||||||
|
|
||||||
//调取接口,通过vin查询车辆
|
//调取接口,通过vin查询车辆
|
||||||
List<Vehicle> vehicles = remoteVehicleService.findByVIN(start17).getData();
|
List<Vehicle> vehicles = remoteVehicleService.findByVIN(start17).getData();
|
||||||
System.out.println("**************" + vehicles);
|
// System.out.println("**************" + vehicles);
|
||||||
|
|
||||||
|
|
||||||
//如果不存在这个车
|
//如果不存在这个车
|
||||||
|
@ -198,7 +197,7 @@ public class MqttMonitor {
|
||||||
log.info("远程调用查询到的车辆数据:" + vehicle);
|
log.info("远程调用查询到的车辆数据:" + vehicle);
|
||||||
|
|
||||||
//上线车辆存入redis 6秒 用于判断车辆是否下线,还要写定时器,定时查询
|
//上线车辆存入redis 6秒 用于判断车辆是否下线,还要写定时器,定时查询
|
||||||
redis.setCacheObject(start17, start17, 6L, TimeUnit.SECONDS);
|
redis.setCacheObject("已上线的车辆vin:"+start17, start17, 6L, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
|
||||||
log.info("vin码为" + start17 + "的车辆属于本系统,允许上线!");
|
log.info("vin码为" + start17 + "的车辆属于本系统,允许上线!");
|
||||||
|
@ -207,7 +206,7 @@ public class MqttMonitor {
|
||||||
Integer i = remoteVehicleService.onOrOutLineByVIN(start17 + "," + 1);
|
Integer i = remoteVehicleService.onOrOutLineByVIN(start17 + "," + 1);
|
||||||
//上线成功
|
//上线成功
|
||||||
if (0 != i) {
|
if (0 != i) {
|
||||||
log.info("上线成功!");
|
// log.info("上线成功!");
|
||||||
try {
|
try {
|
||||||
produceMessage(message);
|
produceMessage(message);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -239,7 +238,7 @@ public class MqttMonitor {
|
||||||
//发送消息
|
//发送消息
|
||||||
kafkaProducer.send(new ProducerRecord<>(TOPIC_NAME, message));
|
kafkaProducer.send(new ProducerRecord<>(TOPIC_NAME, message));
|
||||||
|
|
||||||
System.out.println("发送消息:" + message);
|
// System.out.println("发送消息:" + message);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("消息发送失败:" + e.getMessage());
|
log.error("消息发送失败:" + e.getMessage());
|
||||||
|
|
|
@ -15,7 +15,6 @@ spring:
|
||||||
discovery:
|
discovery:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: 121.89.211.230:8848
|
server-addr: 121.89.211.230:8848
|
||||||
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
|
|
||||||
config:
|
config:
|
||||||
# 配置中心地址
|
# 配置中心地址
|
||||||
server-addr: 121.89.211.230:8848
|
server-addr: 121.89.211.230:8848
|
||||||
|
@ -24,7 +23,6 @@ spring:
|
||||||
# 共享配置
|
# 共享配置
|
||||||
shared-configs:
|
shared-configs:
|
||||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
|
|
||||||
main:
|
main:
|
||||||
allow-bean-definition-overriding: true
|
allow-bean-definition-overriding: true
|
||||||
logging:
|
logging:
|
||||||
|
@ -35,10 +33,10 @@ logging:
|
||||||
mqtt:
|
mqtt:
|
||||||
server:
|
server:
|
||||||
broker: tcp://115.159.47.13:1883
|
broker: tcp://115.159.47.13:1883
|
||||||
# broker: mqtt://115.159.47.13:1883
|
# broker: mqtt://115.159.47.13:1883
|
||||||
username:
|
username:
|
||||||
password:
|
password:
|
||||||
clientId: fluxMq
|
clientId: xiaoYao
|
||||||
qos: 0
|
qos: 0
|
||||||
topic: test
|
topic: xiaoYao
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,9 @@ spring:
|
||||||
discovery:
|
discovery:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: 121.89.211.230:8848
|
server-addr: 121.89.211.230:8848
|
||||||
namespace: 968741d4-299d-483c-8d30-ede2aff8cfd4
|
|
||||||
config:
|
config:
|
||||||
# 配置中心地址
|
# 配置中心地址
|
||||||
server-addr: 121.89.211.230:8848
|
server-addr: 121.89.211.230:8848
|
||||||
namespace: 968741d4-299d-483c-8d30-ede2aff8cfd4
|
|
||||||
# 配置文件格式
|
# 配置文件格式
|
||||||
file-extension: yml
|
file-extension: yml
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
|
Loading…
Reference in New Issue