feat: 电子围栏报警
parent
c4eb443372
commit
b4ad3e4f47
|
@ -0,0 +1,28 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.couplet</groupId>
|
||||||
|
<artifactId>couplet-common</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>couplet-common-event</artifactId>
|
||||||
|
|
||||||
|
<description>事件系统</description>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.couplet</groupId>
|
||||||
|
<artifactId>couplet-common-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,338 @@
|
||||||
|
package com.couplet.analyze.msg.utils;
|
||||||
|
|
||||||
|
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongXiaoDong
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2024/4/6 14:12
|
||||||
|
* @description
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class MsgUtils {
|
||||||
|
|
||||||
|
public static String generateGTA() {
|
||||||
|
// 生成四位以"GTA"开头的字符串
|
||||||
|
String prefix = "GTA";
|
||||||
|
// 生成三位随机数字
|
||||||
|
String randomNumber = generateRandomNumber(4);
|
||||||
|
// 拼接字符串
|
||||||
|
return prefix + randomNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String generateRandomNumber(int length) {
|
||||||
|
// 生成随机数
|
||||||
|
Random random = new Random();
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
// 生成0到9之间的随机数字,并转换为字符串
|
||||||
|
sb.append(random.nextInt(10));
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将16进制字符串转换为ASCII字符串
|
||||||
|
* @param s 16进制字符串
|
||||||
|
* @return ASCII字符串
|
||||||
|
*/
|
||||||
|
public static String hexToString(String s) {
|
||||||
|
if (s == null || s.equals("")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
s = s.replace(" ", "");
|
||||||
|
byte[] baKeyword = new byte[s.length() / 2];
|
||||||
|
for (int i = 0; i < baKeyword.length; i++) {
|
||||||
|
try {
|
||||||
|
baKeyword[i] = (byte) (0xff & Integer.parseInt(s.substring(i * 2, i * 2 + 2), 16));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
s = new String(baKeyword, StandardCharsets.UTF_8);
|
||||||
|
} catch (Exception e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将解析后的数据进行截取封装
|
||||||
|
* @param str
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<CoupletMsgData> sendMsg(String str) {
|
||||||
|
List<CoupletMsgData> coupletMsgDataList = new ArrayList<>();
|
||||||
|
CoupletMsgData coupletMsgData = new CoupletMsgData();
|
||||||
|
|
||||||
|
coupletMsgData.setVin(str.substring(1,18));
|
||||||
|
|
||||||
|
log.info("vin=="+coupletMsgData.getVin());
|
||||||
|
|
||||||
|
//时间
|
||||||
|
String tim =str.substring(18,31);
|
||||||
|
long timestamp = Long.parseLong(tim);
|
||||||
|
|
||||||
|
Date date = new Date(timestamp);
|
||||||
|
coupletMsgData.setCreateTime(date);
|
||||||
|
|
||||||
|
//经度
|
||||||
|
String lt = str.substring(31,42);
|
||||||
|
// 如果末尾是零,则舍去
|
||||||
|
int endIndex = lt.length() - 1;
|
||||||
|
while (lt.charAt(endIndex) == '0'){
|
||||||
|
endIndex--;
|
||||||
|
}
|
||||||
|
|
||||||
|
String longitude = lt.substring(0, endIndex + 1);
|
||||||
|
coupletMsgData.setLongitude(longitude);
|
||||||
|
|
||||||
|
//维度
|
||||||
|
String latitudeIndex =str.substring(42,52);
|
||||||
|
int endIndexT = latitudeIndex.length() - 1;
|
||||||
|
while (latitudeIndex.charAt(endIndexT) == '0'){
|
||||||
|
endIndexT--;
|
||||||
|
}
|
||||||
|
|
||||||
|
String latitude = latitudeIndex.substring(0, endIndexT + 1);
|
||||||
|
coupletMsgData.setLatitude(latitude);
|
||||||
|
|
||||||
|
//速度speed
|
||||||
|
String speed =str.substring(52,58);
|
||||||
|
coupletMsgData.setSpeed(speed);
|
||||||
|
|
||||||
|
//里程
|
||||||
|
BigDecimal mileage= new BigDecimal(str.substring(58,69));
|
||||||
|
mileage=mileage.stripTrailingZeros();
|
||||||
|
coupletMsgData.setMileage(mileage);
|
||||||
|
|
||||||
|
//总电压
|
||||||
|
String voltage =str.substring(69,75);
|
||||||
|
while (voltage.endsWith("0")) {
|
||||||
|
voltage = voltage.substring(0, voltage.length() - 1); // 去除末尾的零
|
||||||
|
}
|
||||||
|
coupletMsgData.setVoltage(voltage);
|
||||||
|
|
||||||
|
//总电流
|
||||||
|
String current =str.substring(75,80);
|
||||||
|
while (current.endsWith("0")){
|
||||||
|
current=current.substring(0,current.length()-1);
|
||||||
|
}
|
||||||
|
coupletMsgData.setCurrent(current);
|
||||||
|
|
||||||
|
//绝缘电阻 resistance
|
||||||
|
String res =str.substring(80,89);
|
||||||
|
String resistance = res.substring(0, 5);
|
||||||
|
coupletMsgData.setResistance(resistance);
|
||||||
|
|
||||||
|
//档位
|
||||||
|
String gear =str.substring(89,90);
|
||||||
|
coupletMsgData.setGear(gear);
|
||||||
|
|
||||||
|
//accelerationPedal 加速踏板行程值
|
||||||
|
String accelerationPedal =str.substring(90,91);
|
||||||
|
coupletMsgData.setAccelerationPedal(accelerationPedal);
|
||||||
|
|
||||||
|
//brakePedal 制动踏板行程值
|
||||||
|
String brakePedal =str.substring(92,93);
|
||||||
|
coupletMsgData.setBrakePedal(brakePedal);
|
||||||
|
|
||||||
|
//fuelConsumptionRate 燃料消耗率
|
||||||
|
String fuelConsumptionRate =str.substring(94,99);
|
||||||
|
coupletMsgData.setFuelConsumptionRate(fuelConsumptionRate);
|
||||||
|
|
||||||
|
//motorControllerTemperature 电机控制器温度
|
||||||
|
String motorControllerTemperature =str.substring(99,105);
|
||||||
|
while (motorControllerTemperature.endsWith("0")){
|
||||||
|
motorControllerTemperature=motorControllerTemperature.substring(0,motorControllerTemperature.length()-1);
|
||||||
|
}
|
||||||
|
coupletMsgData.setMotorControllerTemperature(motorControllerTemperature);
|
||||||
|
|
||||||
|
//motorSpeed 电机转速
|
||||||
|
String motorSpeed =str.substring(105,110);
|
||||||
|
coupletMsgData.setMotorSpeed(motorSpeed);
|
||||||
|
|
||||||
|
//motorTorque 电机转矩
|
||||||
|
String motorTorque =str.substring(110,114);
|
||||||
|
while (motorTorque.endsWith("0")){
|
||||||
|
motorTorque=motorTorque.substring(0,motorTorque.length()-1);
|
||||||
|
}
|
||||||
|
coupletMsgData.setMotorTorque(motorTorque);
|
||||||
|
|
||||||
|
//motorTemperature 电机温度
|
||||||
|
String motorTemperature =str.substring(114,120);
|
||||||
|
while (motorTemperature.endsWith("0")){
|
||||||
|
motorTemperature=motorTemperature.substring(0,motorTemperature.length()-1);
|
||||||
|
}
|
||||||
|
coupletMsgData.setMotorTemperature(motorTemperature);
|
||||||
|
|
||||||
|
//motorVoltage 电机电压
|
||||||
|
String motorVoltage =str.substring(120,125);
|
||||||
|
while (motorVoltage.endsWith("0")){
|
||||||
|
motorVoltage=motorVoltage.substring(0,motorVoltage.length()-1);
|
||||||
|
}
|
||||||
|
coupletMsgData.setMotorVoltage(motorVoltage);
|
||||||
|
|
||||||
|
//motorCurrent 电机电流
|
||||||
|
String motorCurrent =str.substring(125,133);
|
||||||
|
while (motorCurrent.endsWith("0")){
|
||||||
|
motorCurrent=motorCurrent.substring(0,motorCurrent.length()-1);
|
||||||
|
}
|
||||||
|
coupletMsgData.setMotorCurrent(motorCurrent);
|
||||||
|
|
||||||
|
//remainingBattery 动力电池剩余电量SOC
|
||||||
|
BigDecimal remainingBattery = new BigDecimal(str.substring(133,138));
|
||||||
|
coupletMsgData.setRemainingBattery(remainingBattery);
|
||||||
|
|
||||||
|
//maximumFeedbackPower 当前状态允许的最大反馈功率
|
||||||
|
String maximumFeedbackPower =str.substring(139,144);
|
||||||
|
while (maximumFeedbackPower.endsWith("0")){
|
||||||
|
maximumFeedbackPower=maximumFeedbackPower.substring(0,maximumFeedbackPower.length()-1);
|
||||||
|
}
|
||||||
|
coupletMsgData.setMaximumFeedbackPower(maximumFeedbackPower);
|
||||||
|
|
||||||
|
//maximumDischargePower 当前状态允许最大放电功率
|
||||||
|
String maximumDischargePower =str.substring(145,151);
|
||||||
|
while (maximumDischargePower.endsWith("0")){
|
||||||
|
maximumDischargePower=maximumDischargePower.substring(0,maximumDischargePower.length()-1);
|
||||||
|
}
|
||||||
|
coupletMsgData.setMaximumDischargePower(maximumDischargePower);
|
||||||
|
|
||||||
|
//selfCheckCounter BMS自检计数器
|
||||||
|
String selfCheckCounter =str.substring(151,153);
|
||||||
|
String selfCheckCounterReplace = selfCheckCounter.replace("0", "");
|
||||||
|
coupletMsgData.setSelfCheckCounter(selfCheckCounterReplace);
|
||||||
|
|
||||||
|
//totalBatteryCurrent 动力电池充放电电流
|
||||||
|
String totalBatteryCurrent =str.substring(153,158);
|
||||||
|
while (totalBatteryCurrent.endsWith("0")){
|
||||||
|
totalBatteryCurrent=totalBatteryCurrent.substring(0,totalBatteryCurrent.length()-1);
|
||||||
|
}
|
||||||
|
coupletMsgData.setTotalBatteryCurrent(totalBatteryCurrent);
|
||||||
|
|
||||||
|
//totalBatteryVoltage 动力电池负载端总电压V3
|
||||||
|
String totalBatteryVoltage =str.substring(158,164);
|
||||||
|
while (totalBatteryVoltage.endsWith("0")){
|
||||||
|
totalBatteryVoltage=totalBatteryVoltage.substring(0,totalBatteryVoltage.length()-1);
|
||||||
|
}
|
||||||
|
coupletMsgData.setTotalBatteryVoltage(totalBatteryVoltage);
|
||||||
|
|
||||||
|
//singleBatteryMaxVoltage 单次最大电压
|
||||||
|
String singleBatteryMaxVoltage =str.substring(164,168);
|
||||||
|
while (singleBatteryMaxVoltage.endsWith("0")){
|
||||||
|
singleBatteryMaxVoltage=singleBatteryMaxVoltage.substring(0,singleBatteryMaxVoltage.length()-1);
|
||||||
|
}
|
||||||
|
coupletMsgData.setSingleBatteryMaxVoltage(singleBatteryMaxVoltage);
|
||||||
|
|
||||||
|
//singleBatteryMinVoltage 单体电池最低电压
|
||||||
|
String singleBatteryMinVoltage =str.substring(168,172);
|
||||||
|
while (singleBatteryMinVoltage.endsWith("0")){
|
||||||
|
singleBatteryMinVoltage=singleBatteryMinVoltage.substring(0,singleBatteryMinVoltage.length()-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
coupletMsgData.setSingleBatteryMinVoltage(singleBatteryMinVoltage);
|
||||||
|
|
||||||
|
//singleBatteryMaxTemperature 单体电池最高温度
|
||||||
|
String singleBatteryMaxTemperature =str.substring(172,178);
|
||||||
|
while (singleBatteryMaxTemperature.endsWith("0")){
|
||||||
|
singleBatteryMaxTemperature=singleBatteryMaxTemperature.substring(0,singleBatteryMaxTemperature.length()-1);
|
||||||
|
}
|
||||||
|
coupletMsgData.setSingleBatteryMaxTemperature(singleBatteryMaxTemperature);
|
||||||
|
|
||||||
|
//singleBatteryMinTemperature 单体电池最低温度
|
||||||
|
String singleBatteryMinTemperature =str.substring(178,184);
|
||||||
|
while (singleBatteryMinTemperature.endsWith("0")){
|
||||||
|
singleBatteryMinTemperature=singleBatteryMinTemperature.substring(0,singleBatteryMinTemperature.length()-1);
|
||||||
|
}
|
||||||
|
coupletMsgData.setSingleBatteryMinTemperature(singleBatteryMinTemperature);
|
||||||
|
|
||||||
|
//availableBatteryCapacity 可用电池容量
|
||||||
|
String availableBatteryCapacity =str.substring(184,190);
|
||||||
|
while (availableBatteryCapacity.endsWith("0")){
|
||||||
|
availableBatteryCapacity=availableBatteryCapacity.substring(0,availableBatteryCapacity.length()-1);
|
||||||
|
}
|
||||||
|
coupletMsgData.setAvailableBatteryCapacity(availableBatteryCapacity);
|
||||||
|
|
||||||
|
//vehicleStatus 车辆状态
|
||||||
|
int vehicleStatus = Integer.parseInt(str.substring(190,191));
|
||||||
|
coupletMsgData.setVehicleStatus(vehicleStatus);
|
||||||
|
|
||||||
|
//chargingStatus 充电状态
|
||||||
|
int chargingStatus = Integer.parseInt(str.substring(191,192));
|
||||||
|
coupletMsgData.setChargingStatus(chargingStatus);
|
||||||
|
|
||||||
|
//operatingStatus 运行状态
|
||||||
|
int operatingStatus = Integer.parseInt(str.substring(192,193));
|
||||||
|
coupletMsgData.setOperatingStatus(operatingStatus);
|
||||||
|
|
||||||
|
//socStatus SOC
|
||||||
|
int socStatus = Integer.parseInt(str.substring(193,194));
|
||||||
|
coupletMsgData.setSocStatus(socStatus);
|
||||||
|
|
||||||
|
//chargingEnergyStorageStatus 可充电储能装置工作状态
|
||||||
|
int chargingEnergyStorageStatus = Integer.parseInt(str.substring(194,195));
|
||||||
|
coupletMsgData.setChargingEnergyStorageStatus(chargingEnergyStorageStatus);
|
||||||
|
|
||||||
|
//driveMotorStatus 驱动电机状态
|
||||||
|
int driveMotorStatus = Integer.parseInt(str.substring(195,196));
|
||||||
|
coupletMsgData.setDriveMotorStatus(driveMotorStatus);
|
||||||
|
|
||||||
|
//positionStatus 定位是否有效
|
||||||
|
int positionStatus = Integer.parseInt(str.substring(196,197));
|
||||||
|
coupletMsgData.setPositionStatus(positionStatus);
|
||||||
|
|
||||||
|
//easStatus EAS(汽车防盗系统)状态
|
||||||
|
int easStatus = Integer.parseInt(str.substring(197,198));
|
||||||
|
coupletMsgData.setEasStatus(easStatus);
|
||||||
|
|
||||||
|
//ptcStatus PTC(电动加热器)状态
|
||||||
|
int ptcStatus = Integer.parseInt(str.substring(198,199));
|
||||||
|
coupletMsgData.setPtcStatus(ptcStatus);
|
||||||
|
|
||||||
|
//epsStatus
|
||||||
|
int epsStatus = Integer.parseInt(str.substring(199,200));
|
||||||
|
coupletMsgData.setEpsStatus(epsStatus);
|
||||||
|
|
||||||
|
//absStatus EPS(电动助力系统)状态
|
||||||
|
int absStatus = Integer.parseInt(str.substring(200,201));
|
||||||
|
coupletMsgData.setAbsStatus(absStatus);
|
||||||
|
|
||||||
|
//mcuStatus MCU(电机/逆变器)状态
|
||||||
|
int mcuStatus = Integer.parseInt(str.substring(201,202));
|
||||||
|
coupletMsgData.setMcuStatus(mcuStatus);
|
||||||
|
|
||||||
|
//heatingStatus 动力电池加热状态
|
||||||
|
int heatingStatus = Integer.parseInt(str.substring(202,203));
|
||||||
|
coupletMsgData.setHeatingStatus(heatingStatus);
|
||||||
|
|
||||||
|
//batteryStatus 动力电池当前状态
|
||||||
|
int batteryStatus = Integer.parseInt(str.substring(203,204));
|
||||||
|
coupletMsgData.setBatteryStatus(batteryStatus);
|
||||||
|
|
||||||
|
//batteryInsulationStatus 动力电池保温状态
|
||||||
|
int batteryInsulationStatus = Integer.parseInt(str.substring(204,205));
|
||||||
|
coupletMsgData.setBatteryInsulationStatus(batteryInsulationStatus);
|
||||||
|
|
||||||
|
//dcdcStatus DCDC(电力交换系统)状态
|
||||||
|
int dcdcStatus = Integer.parseInt(str.substring(205,206));
|
||||||
|
coupletMsgData.setDcdcStatus(dcdcStatus);
|
||||||
|
|
||||||
|
//chgStatus CHG(充电机)状态
|
||||||
|
int chgStatus = Integer.parseInt(str.substring(206,207));
|
||||||
|
coupletMsgData.setChgStatus(chgStatus);
|
||||||
|
|
||||||
|
coupletMsgDataList.add(coupletMsgData);
|
||||||
|
|
||||||
|
return coupletMsgDataList;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
com.couplet.common.core.utils.SpringUtils
|
|
@ -166,8 +166,21 @@ public class RedisService {
|
||||||
setOperation.add(it.next());
|
setOperation.add(it.next());
|
||||||
}
|
}
|
||||||
return setOperation;
|
return setOperation;
|
||||||
|
} /**
|
||||||
|
* 缓存Set
|
||||||
|
*
|
||||||
|
* @param key 缓存键值
|
||||||
|
* @param dataSet 缓存的数据
|
||||||
|
*
|
||||||
|
* @return 缓存数据的对象
|
||||||
|
*/
|
||||||
|
public <T> BoundSetOperations<String, T> setCacheSet (final String key, final T dataSet) {
|
||||||
|
BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
|
||||||
|
setOperation.add(dataSet);
|
||||||
|
return setOperation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得缓存的set
|
* 获得缓存的set
|
||||||
*
|
*
|
||||||
|
@ -179,6 +192,7 @@ public class RedisService {
|
||||||
return redisTemplate.opsForSet().members(key);
|
return redisTemplate.opsForSet().members(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存Map
|
* 缓存Map
|
||||||
*
|
*
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
<module>couplet-common-datasource</module>
|
<module>couplet-common-datasource</module>
|
||||||
<module>couplet-common-system</module>
|
<module>couplet-common-system</module>
|
||||||
<module>couplet-common-business</module>
|
<module>couplet-common-business</module>
|
||||||
|
<module>couplet-common-event</module>
|
||||||
|
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
|
|
@ -86,13 +86,10 @@
|
||||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||||
<version>1.2.5</version>
|
<version>1.2.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- 事件核心配置 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.couplet</groupId>
|
<groupId>com.couplet</groupId>
|
||||||
<artifactId>couplet-modules-mq</artifactId>
|
<artifactId>couplet-common-event</artifactId>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.couplet</groupId>
|
|
||||||
<artifactId>couplet-common-business</artifactId>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
|
@ -74,9 +74,7 @@ public class BreakdownServiceImpl extends KeyExpirationEventMessageListener impl
|
||||||
//获取过期的key
|
//获取过期的key
|
||||||
String key = "breakdown";
|
String key = "breakdown";
|
||||||
log.debug("失效+key is:"+ key);
|
log.debug("失效+key is:"+ key);
|
||||||
HashSet<CoupletMsgData> objects = new HashSet<>();
|
redisService.setCacheSet(key, coupletMsgData);
|
||||||
objects.add(coupletMsgData);
|
|
||||||
redisService.setCacheSet(key, objects);
|
|
||||||
long expireTime = 30;
|
long expireTime = 30;
|
||||||
redisService.expire(key, expireTime, TimeUnit.MINUTES);
|
redisService.expire(key, expireTime, TimeUnit.MINUTES);
|
||||||
scheduledRedis();
|
scheduledRedis();
|
||||||
|
@ -98,112 +96,108 @@ public class BreakdownServiceImpl extends KeyExpirationEventMessageListener impl
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scheduledRedis() {
|
public void scheduledRedis() {
|
||||||
|
|
||||||
// Get all members of the set
|
// Get all members of the set
|
||||||
Set<String> members = redisService.getCacheSet("breakdown");
|
String key = "breakdown";
|
||||||
if (members.size()!=0){
|
Set<CoupletMsgData> members = redisService.getCacheSet(key);
|
||||||
for (String member : members){
|
if (members.size()>0){
|
||||||
CoupletMsgData code = JSON.parseObject(member, CoupletMsgData.class);
|
for (CoupletMsgData member : members) {
|
||||||
String vin = code.getVin();
|
Set<String> breakdownIds = redisService.getCacheSet(member.getVin()+":"+key);
|
||||||
Set<String> breakdownIds = redisService.getCacheSet(vin+":"+"breakdown");
|
|
||||||
if (breakdownIds.size()==0){
|
if (breakdownIds.size()==0){
|
||||||
CoupletTroubleCode troubleCode = new CoupletTroubleCode();
|
CoupletTroubleCode troubleCode = new CoupletTroubleCode();
|
||||||
troubleCode.setTroubleStartTime(new Date());
|
troubleCode.setTroubleStartTime(new Date());
|
||||||
troubleCode.setTroubleVin(code.getVin());
|
troubleCode.setTroubleVin(member.getVin());
|
||||||
// 随机生成故障码
|
// 随机生成故障码
|
||||||
String faultCode = MsgUtils.generateGTA();
|
String faultCode = MsgUtils.generateGTA();
|
||||||
troubleCode.setTroubleCode(faultCode);
|
troubleCode.setTroubleCode(faultCode);
|
||||||
|
|
||||||
// 检查车辆状态,若为0,则设置故障位置为"190"
|
// 检查车辆状态,若为0,则设置故障位置为"190"
|
||||||
if(code.getVehicleStatus() == 0) {
|
if(member.getVehicleStatus() == 0) {
|
||||||
troubleCode.setTroublePosition("190");
|
troubleCode.setTroublePosition("190");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查充电状态,若为0,则设置故障位置为"191"
|
// 检查充电状态,若为0,则设置故障位置为"191"
|
||||||
if (code.getChargingStatus() == 0) {
|
if (member.getChargingStatus() == 0) {
|
||||||
troubleCode.setTroublePosition("191");
|
troubleCode.setTroublePosition("191");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查运行状态,若为0,则设置故障位置为"192"
|
// 检查运行状态,若为0,则设置故障位置为"192"
|
||||||
if (code.getOperatingStatus() == 0) {
|
if (member.getOperatingStatus() == 0) {
|
||||||
troubleCode.setTroublePosition("192");
|
troubleCode.setTroublePosition("192");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查电池荷电状态(SOC), 若为0,则设置故障位置为"193"
|
// 检查电池荷电状态(SOC), 若为0,则设置故障位置为"193"
|
||||||
if (code.getSocStatus() == 0) {
|
if (member.getSocStatus() == 0) {
|
||||||
troubleCode.setTroublePosition("193");
|
troubleCode.setTroublePosition("193");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查充电能源存储状态,若为0,则设置故障位置为"194"
|
// 检查充电能源存储状态,若为0,则设置故障位置为"194"
|
||||||
if (code.getChargingEnergyStorageStatus() == 0) {
|
if (member.getChargingEnergyStorageStatus() == 0) {
|
||||||
troubleCode.setTroublePosition("194");
|
troubleCode.setTroublePosition("194");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查驱动电机状态,若为0,则设置故障位置为"195"
|
// 检查驱动电机状态,若为0,则设置故障位置为"195"
|
||||||
if (code.getDriveMotorStatus() == 0) {
|
if (member.getDriveMotorStatus() == 0) {
|
||||||
troubleCode.setTroublePosition("195");
|
troubleCode.setTroublePosition("195");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查定位状态,若为0,则设置故障位置为"196"
|
// 检查定位状态,若为0,则设置故障位置为"196"
|
||||||
if (code.getPositionStatus() == 0) {
|
if (member.getPositionStatus() == 0) {
|
||||||
troubleCode.setTroublePosition("196");
|
troubleCode.setTroublePosition("196");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查电子驻车系统(EAS)状态,若为0,则设置故障位置为"197"
|
// 检查电子驻车系统(EAS)状态,若为0,则设置故障位置为"197"
|
||||||
if (code.getEasStatus() == 0) {
|
if (member.getEasStatus() == 0) {
|
||||||
troubleCode.setTroublePosition("197");
|
troubleCode.setTroublePosition("197");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查PTC(正温度系数热敏电阻)状态,若为0,则设置故障位置为"198"
|
// 检查PTC(正温度系数热敏电阻)状态,若为0,则设置故障位置为"198"
|
||||||
if (code.getPtcStatus() == 0) {
|
if (member.getPtcStatus() == 0) {
|
||||||
troubleCode.setTroublePosition("198");
|
troubleCode.setTroublePosition("198");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查电动助力转向系统(EPS)状态,若为0,则设置故障位置为"199"
|
// 检查电动助力转向系统(EPS)状态,若为0,则设置故障位置为"199"
|
||||||
if (code.getEpsStatus() == 0) {
|
if (member.getEpsStatus() == 0) {
|
||||||
troubleCode.setTroublePosition("199");
|
troubleCode.setTroublePosition("199");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查防抱死制动系统(ABS)状态,若为0,则设置故障位置为"200"
|
// 检查防抱死制动系统(ABS)状态,若为0,则设置故障位置为"200"
|
||||||
if (code.getAbsStatus() == 0) {
|
if (member.getAbsStatus() == 0) {
|
||||||
troubleCode.setTroublePosition("200");
|
troubleCode.setTroublePosition("200");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查主控制器(MCU)状态,若为0,则设置故障位置为"201"
|
// 检查主控制器(MCU)状态,若为0,则设置故障位置为"201"
|
||||||
if (code.getMcuStatus() == 0) {
|
if (member.getMcuStatus() == 0) {
|
||||||
troubleCode.setTroublePosition("201");
|
troubleCode.setTroublePosition("201");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查加热状态,若为0,则设置故障位置为"202"
|
// 检查加热状态,若为0,则设置故障位置为"202"
|
||||||
if (code.getHeatingStatus() == 0) {
|
if (member.getHeatingStatus() == 0) {
|
||||||
troubleCode.setTroublePosition("202");
|
troubleCode.setTroublePosition("202");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查电池状态,若为0,则设置故障位置为"203"
|
// 检查电池状态,若为0,则设置故障位置为"203"
|
||||||
if (code.getBatteryStatus() == 0) {
|
if (member.getBatteryStatus() == 0) {
|
||||||
troubleCode.setTroublePosition("203");
|
troubleCode.setTroublePosition("203");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查电池绝缘状态,若为0,则设置故障位置为"204"
|
// 检查电池绝缘状态,若为0,则设置故障位置为"204"
|
||||||
if (code.getBatteryInsulationStatus() == 0) {
|
if (member.getBatteryInsulationStatus() == 0) {
|
||||||
troubleCode.setTroublePosition("204");
|
troubleCode.setTroublePosition("204");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查直流-直流转换器(DC/DC)状态,若为0,则设置故障位置为"205"
|
// 检查直流-直流转换器(DC/DC)状态,若为0,则设置故障位置为"205"
|
||||||
if (code.getDcdcStatus() == 0) {
|
if (member.getDcdcStatus() == 0) {
|
||||||
troubleCode.setTroublePosition("205");
|
troubleCode.setTroublePosition("205");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查充电机(CHG)状态,若为0,则设置故障位置为"206"
|
// 检查充电机(CHG)状态,若为0,则设置故障位置为"206"
|
||||||
if (code.getChgStatus() == 0) {
|
if (member.getChgStatus() == 0) {
|
||||||
troubleCode.setTroublePosition("206");
|
troubleCode.setTroublePosition("206");
|
||||||
}
|
}
|
||||||
remoteTroubleService.newFaultData(troubleCode);
|
remoteTroubleService.newFaultData(troubleCode);
|
||||||
HashSet<Object> objects = new HashSet<>();
|
redisService.setCacheSet(member.getVin()+":"+key, member.getVin()+":"+member);
|
||||||
objects.add(code.getVin()+":"+code);
|
|
||||||
redisService.setCacheSet(vin+":"+"breakdown", objects);
|
|
||||||
long expireTime = 30;
|
long expireTime = 30;
|
||||||
redisService.expire(vin+":"+"breakdown", expireTime, TimeUnit.MINUTES);
|
redisService.expire(member.getVin()+":"+key, expireTime, TimeUnit.MINUTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,11 +44,11 @@ public class ElectronicFenceServiceImpl implements IncidentService {
|
||||||
ArrayList<Fence> fences = new ArrayList<>();
|
ArrayList<Fence> fences = new ArrayList<>();
|
||||||
if (redisService.hasKey(fenceKey)) {
|
if (redisService.hasKey(fenceKey)) {
|
||||||
log.info("电子围栏事件redis存在.......");
|
log.info("电子围栏事件redis存在.......");
|
||||||
redisService.getCacheObject();
|
// redisService.getCacheObject();
|
||||||
for (String s : fence) {
|
// for (String s : fence) {
|
||||||
Fence parseObject = JSON.parseObject(s, Fence.class);
|
// Fence parseObject = JSON.parseObject(s, Fence.class);
|
||||||
fences.add(parseObject);
|
// fences.add(parseObject);
|
||||||
}
|
// }
|
||||||
// jingdu;
|
// jingdu;
|
||||||
// longitude;
|
// longitude;
|
||||||
// weidu;
|
// weidu;
|
||||||
|
@ -64,10 +64,12 @@ public class ElectronicFenceServiceImpl implements IncidentService {
|
||||||
|
|
||||||
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 {
|
||||||
|
@ -78,12 +80,9 @@ public class ElectronicFenceServiceImpl implements IncidentService {
|
||||||
}else {
|
}else {
|
||||||
throw new RuntimeException("电子围栏经纬度格式错误"+strings);
|
throw new RuntimeException("电子围栏经纬度格式错误"+strings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
log.info("更改的电子围栏内容是:"+fence);
|
// log.info("更改的电子围栏内容是:"+fence);
|
||||||
log.info("电子围栏事件结束.......");
|
log.info("电子围栏事件结束.......");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.couplet.analyze.msg.service.impl.breakdown;
|
package com.couplet.analyze.msg.service.impl.breakdown;
|
||||||
|
|
||||||
|
import com.couplet.common.redis.service.RedisService;
|
||||||
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.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -12,7 +13,7 @@ import org.springframework.stereotype.Component;
|
||||||
@Component
|
@Component
|
||||||
public class BreakdownEvent {
|
public class BreakdownEvent {
|
||||||
@Autowired
|
@Autowired
|
||||||
private StringRedisTemplate redisTemplate;
|
private RedisService redisService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,73 +21,4 @@
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
|
|
||||||
<!-- SpringCloud Alibaba Nacos -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- SpringCloud Alibaba Nacos Config -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- SpringCloud Alibaba Sentinel -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- SpringBoot Actuator -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Swagger UI -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.springfox</groupId>
|
|
||||||
<artifactId>springfox-swagger-ui</artifactId>
|
|
||||||
<version>${swagger.fox.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Mysql Connector -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.mysql</groupId>
|
|
||||||
<artifactId>mysql-connector-j</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- MuYu Common DataSource -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.couplet</groupId>
|
|
||||||
<artifactId>couplet-common-datasource</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- MuYu Common DataScope -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.couplet</groupId>
|
|
||||||
<artifactId>couplet-common-datascope</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- MuYu Common Log -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.couplet</groupId>
|
|
||||||
<artifactId>couplet-common-log</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- MuYu Common Swagger -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.couplet</groupId>
|
|
||||||
<artifactId>couplet-common-swagger</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.kafka</groupId>
|
|
||||||
<artifactId>spring-kafka</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -87,11 +87,6 @@
|
||||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.couplet</groupId>
|
|
||||||
<artifactId>couplet-analyze-msg</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- RabbitMQ依赖-->
|
<!-- RabbitMQ依赖-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|
|
@ -51,11 +51,11 @@ public class FenceController extends BaseController {
|
||||||
@PostMapping("/fenceAdd")
|
@PostMapping("/fenceAdd")
|
||||||
@RequiresPermissions("couplet:fence:fenceAdd")
|
@RequiresPermissions("couplet:fence:fenceAdd")
|
||||||
@Log(title = "电子围栏新增",businessType = BusinessType.INSERT)
|
@Log(title = "电子围栏新增",businessType = BusinessType.INSERT)
|
||||||
public Result<?> fenceInsert(HttpServletRequest request, @RequestBody FenceRequest fenceRequest){
|
public Result<?> fenceInsert(@RequestBody FenceRequest fenceRequest){
|
||||||
// if (!fenceService.checkFenceKeyUnique(fenceRequest.getFenceName())) {
|
// if (!fenceService.checkFenceKeyUnique(fenceRequest.getFenceName())) {
|
||||||
// return error("新增参数'" + fenceRequest.getFenceName() + "'失败,参数键名已存在");
|
// return error("新增参数'" + fenceRequest.getFenceName() + "'失败,参数键名已存在");
|
||||||
// }
|
// }
|
||||||
fenceService.fenceInsert(request,fenceRequest);
|
fenceService.fenceInsert(fenceRequest);
|
||||||
return Result.success("新增成功");
|
return Result.success("新增成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import com.couplet.common.domain.request.FenceConfig;
|
||||||
import com.couplet.common.domain.request.FenceRequest;
|
import com.couplet.common.domain.request.FenceRequest;
|
||||||
import com.couplet.common.domain.request.FenceUpdateRequest;
|
import com.couplet.common.domain.request.FenceUpdateRequest;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,7 +26,7 @@ public interface FenceService extends IService<Fence> {
|
||||||
*
|
*
|
||||||
* @param fenceRequest
|
* @param fenceRequest
|
||||||
*/
|
*/
|
||||||
void fenceInsert(HttpServletRequest request, FenceRequest fenceRequest);
|
void fenceInsert(FenceRequest fenceRequest);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除电子围栏
|
* 删除电子围栏
|
||||||
|
|
|
@ -9,13 +9,13 @@ import com.couplet.common.domain.Fence;
|
||||||
import com.couplet.common.domain.request.FenceConfig;
|
import com.couplet.common.domain.request.FenceConfig;
|
||||||
import com.couplet.common.domain.request.FenceRequest;
|
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.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.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ public class FenceServiceImpl extends ServiceImpl<FenceMapper, Fence> implements
|
||||||
* 注入redis模板
|
* 注入redis模板
|
||||||
*/
|
*/
|
||||||
@Autowired
|
@Autowired
|
||||||
private StringRedisTemplate redisTemplate;
|
private RedisService redisService;
|
||||||
/**
|
/**
|
||||||
* 远程调用队列服务
|
* 远程调用队列服务
|
||||||
*/
|
*/
|
||||||
|
@ -55,6 +55,7 @@ public class FenceServiceImpl extends ServiceImpl<FenceMapper, Fence> implements
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void changeFenceStatus(FenceUpdateRequest fenceUpdateRequest) {
|
public void changeFenceStatus(FenceUpdateRequest fenceUpdateRequest) {
|
||||||
|
|
||||||
String username = SecurityUtils.getUsername();
|
String username = SecurityUtils.getUsername();
|
||||||
|
@ -63,45 +64,31 @@ public class FenceServiceImpl extends ServiceImpl<FenceMapper, Fence> implements
|
||||||
/**
|
/**
|
||||||
* 电子围栏发送改变
|
* 电子围栏发送改变
|
||||||
*/
|
*/
|
||||||
redisTemplate.opsForValue().set("changeFenceStatus", JSON.toJSONString(fenceUpdateRequest), 10, TimeUnit.MINUTES);
|
// redisService.setCacheObject("fence:info"+fenceUpdateRequest.getFenceId(),fenceUpdateRequest, 10, TimeUnit.MINUTES);
|
||||||
|
|
||||||
|
redisService.setCacheObject("fence:info:"+fenceUpdateRequest.getFenceId(),fenceUpdateRequest);
|
||||||
|
redisService.expire("fence:info:"+fenceUpdateRequest.getFenceId(),10,TimeUnit.MINUTES);
|
||||||
remoteFenceService.fenceQueue(fenceUpdateRequest);
|
remoteFenceService.fenceQueue(fenceUpdateRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 业务实现:添加围栏
|
* 业务实现:添加围栏
|
||||||
*
|
*
|
||||||
* @param request
|
|
||||||
* @param fenceRequest
|
* @param fenceRequest
|
||||||
*/
|
*/
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@Override
|
@Override
|
||||||
public void fenceInsert(HttpServletRequest request, FenceRequest fenceRequest) {
|
public void fenceInsert(FenceRequest fenceRequest) {
|
||||||
String username = SecurityUtils.getUsername();
|
String username = SecurityUtils.getUsername();
|
||||||
fenceRequest.setCrateName(username);
|
fenceRequest.setCrateName(username);
|
||||||
//先添加围栏
|
//先添加围栏
|
||||||
fenceMapper.insertFence(fenceRequest);
|
fenceMapper.insertFence(fenceRequest);
|
||||||
String[] logoIds = fenceRequest.getLogoIds();
|
fenAndLogoService.addBach(fenceRequest.getFenceId(), fenceRequest.getLogoIds());
|
||||||
String[] parts = new String[0];
|
|
||||||
for (String logoId : logoIds) {
|
|
||||||
//把前台传入的字符串分割成数组
|
|
||||||
parts = logoId.split(",");
|
|
||||||
//再添加围栏和标识中间表
|
|
||||||
fenAndLogoService.addBach(fenceRequest.getFenceId(), parts);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 电子围栏发送改变
|
|
||||||
*/
|
|
||||||
redisTemplate.opsForValue().set("fenceInsert", JSON.toJSONString(fenceRequest), 10, TimeUnit.MINUTES);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeByFenceId(Long fenceId) {
|
public void removeByFenceId(Long fenceId) {
|
||||||
fenceMapper.removeByFenceId(fenceId);
|
fenceMapper.removeByFenceId(fenceId);
|
||||||
/**
|
|
||||||
* 电子围栏发送改变
|
|
||||||
*/
|
|
||||||
redisTemplate.opsForValue().set("removeByFenceId", JSON.toJSONString(fenceId), 10, TimeUnit.MINUTES);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -16,11 +16,9 @@ spring:
|
||||||
discovery:
|
discovery:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: 121.89.211.230:8848
|
server-addr: 121.89.211.230:8848
|
||||||
namespace: 172469
|
|
||||||
config:
|
config:
|
||||||
# 配置中心地址
|
# 配置中心地址
|
||||||
server-addr: 121.89.211.230:8848
|
server-addr: 121.89.211.230:8848
|
||||||
namespace: 172469
|
|
||||||
# 配置文件格式
|
# 配置文件格式
|
||||||
file-extension: yml
|
file-extension: yml
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
|
|
@ -1,164 +1,165 @@
|
||||||
package com.couplet.mq.service;
|
//package com.couplet.mq.service;
|
||||||
|
//
|
||||||
import com.couplet.mq.domain.User;
|
//import com.couplet.common.redis.service.RedisService;
|
||||||
import com.rabbitmq.client.Channel;
|
//import com.couplet.mq.domain.User;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
//import com.rabbitmq.client.Channel;
|
||||||
import org.springframework.amqp.core.Message;
|
//import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
//import org.springframework.amqp.core.Message;
|
||||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
//import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
//import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
//import org.springframework.stereotype.Component;
|
||||||
import java.io.IOException;
|
//
|
||||||
import java.util.concurrent.TimeUnit;
|
//import java.io.IOException;
|
||||||
|
//import java.util.concurrent.TimeUnit;
|
||||||
/**
|
//
|
||||||
* @ProjectName: five-groups-couplet
|
///**
|
||||||
* @Author: LiuYunHu
|
// * @ProjectName: five-groups-couplet
|
||||||
* @CreateTime: 2024/3/28
|
// * @Author: LiuYunHu
|
||||||
* @Description: MQ消费者类
|
// * @CreateTime: 2024/3/28
|
||||||
*/
|
// * @Description: MQ消费者类
|
||||||
|
// */
|
||||||
@Component
|
//
|
||||||
@Slf4j
|
//@Component
|
||||||
@SuppressWarnings("all")
|
//@Slf4j
|
||||||
@RabbitListener(queues = "queueName")
|
//@SuppressWarnings("all")
|
||||||
public class MqConsumer {
|
//@RabbitListener(queues = "queueName")
|
||||||
@Autowired
|
//public class MqConsumer {
|
||||||
private StringRedisTemplate redis;
|
// @Autowired
|
||||||
|
// private RedisService redis;
|
||||||
/* 线程池执行
|
//
|
||||||
|
// /* 线程池执行
|
||||||
//创建一个定长线程池
|
//
|
||||||
private final Executor executor = Executors.newFixedThreadPool(5);
|
// //创建一个定长线程池
|
||||||
|
// private final Executor executor = Executors.newFixedThreadPool(5);
|
||||||
@Async
|
//
|
||||||
@RabbitHandler
|
// @Async
|
||||||
public void process(User param, Channel channel, Message message) {
|
// @RabbitHandler
|
||||||
executor.execute(() -> {
|
// public void process(User param, Channel channel, Message message) {
|
||||||
try {
|
// executor.execute(() -> {
|
||||||
handleMessage(param, channel, message);
|
// try {
|
||||||
} catch (IOException e) {
|
// handleMessage(param, channel, message);
|
||||||
log.error("处理消息失败:{}", e);
|
// } catch (IOException e) {
|
||||||
}
|
// log.error("处理消息失败:{}", e);
|
||||||
});
|
// }
|
||||||
}
|
// });
|
||||||
|
// }
|
||||||
//处理信息的方法
|
//
|
||||||
private void handleMessage(User param, Channel channel, Message message) throws IOException {
|
// //处理信息的方法
|
||||||
log.info("消费者收到消息为:{},{}" + param, message.getMessageProperties().getDeliveryTag());
|
// private void handleMessage(User param, Channel channel, Message message) throws IOException {
|
||||||
|
// log.info("消费者收到消息为:{},{}" + param, message.getMessageProperties().getDeliveryTag());
|
||||||
long deliveryTag = message.getMessageProperties().getDeliveryTag();
|
//
|
||||||
String messageId = message.getMessageProperties().getMessageId();
|
// long deliveryTag = message.getMessageProperties().getDeliveryTag();
|
||||||
|
// String messageId = message.getMessageProperties().getMessageId();
|
||||||
if (!redis.hasKey("value:" + messageId)) {
|
//
|
||||||
redis.opsForValue().set("value:" + messageId, "" + deliveryTag, 5, 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);
|
// // 1 添加成功新数据 0已有重复值,不允许再添加
|
||||||
//过期时间
|
// Long add = redis.opsForSet().add("set:" + messageId, "set:" + messageId);
|
||||||
redis.expire("set:" + messageId, 5, TimeUnit.MINUTES);
|
// //过期时间
|
||||||
|
// redis.expire("set:" + messageId, 5, TimeUnit.MINUTES);
|
||||||
|
//
|
||||||
try {
|
//
|
||||||
if (add == 1) {
|
// try {
|
||||||
//第一次 消费
|
// if (add == 1) {
|
||||||
System.out.println("*****************************");
|
// //第一次 消费
|
||||||
System.out.println("消费者收到消息:" + param);
|
// System.out.println("*****************************");
|
||||||
System.out.println("*****************************");
|
// System.out.println("消费者收到消息:" + param);
|
||||||
log.info("消费结束");
|
// System.out.println("*****************************");
|
||||||
|
// log.info("消费结束");
|
||||||
channel.basicAck(deliveryTag, false);
|
//
|
||||||
|
// channel.basicAck(deliveryTag, false);
|
||||||
} else {
|
//
|
||||||
//重复消费
|
// } else {
|
||||||
log.error("重复消费");
|
// //重复消费
|
||||||
channel.basicReject(deliveryTag, false);
|
// log.error("重复消费");
|
||||||
|
// channel.basicReject(deliveryTag, false);
|
||||||
//删除缓存
|
//
|
||||||
redis.opsForSet().remove("set:" + messageId, "set:" + messageId);
|
// //删除缓存
|
||||||
}
|
// redis.opsForSet().remove("set:" + messageId, "set:" + messageId);
|
||||||
|
// }
|
||||||
|
//
|
||||||
} catch (Exception e) {
|
//
|
||||||
log.error("消息没有成功消费!");
|
// } catch (Exception e) {
|
||||||
|
// log.error("消息没有成功消费!");
|
||||||
String s = redis.opsForValue().get("value:" + messageId);
|
//
|
||||||
|
// String s = redis.opsForValue().get("value:" + messageId);
|
||||||
long oldTag = Long.parseLong(s);
|
//
|
||||||
|
// long oldTag = Long.parseLong(s);
|
||||||
if (deliveryTag == (oldTag + 2)) {
|
//
|
||||||
log.error("确实消费不了,不入队了!");
|
// if (deliveryTag == (oldTag + 2)) {
|
||||||
channel.basicNack(deliveryTag, false, false);
|
// log.error("确实消费不了,不入队了!");
|
||||||
} else {
|
// channel.basicNack(deliveryTag, false, false);
|
||||||
log.info("消息消费失败,重新入队");
|
// } else {
|
||||||
channel.basicNack(deliveryTag, false, true);
|
// log.info("消息消费失败,重新入队");
|
||||||
}
|
// channel.basicNack(deliveryTag, false, true);
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
}
|
//
|
||||||
|
// }
|
||||||
**/
|
//
|
||||||
|
//**/
|
||||||
@RabbitHandler
|
//
|
||||||
public void process(User param, Channel channel, Message message) throws IOException {
|
// @RabbitHandler
|
||||||
log.info("消费者收到消息为:{},{}" + param, message.getMessageProperties().getDeliveryTag());
|
// 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();
|
// long deliveryTag = message.getMessageProperties().getDeliveryTag();
|
||||||
|
// String messageId = message.getMessageProperties().getMessageId();
|
||||||
if (!redis.hasKey("value:" + messageId)) {
|
//
|
||||||
redis.opsForValue().set("value:" + messageId, "" + deliveryTag, 5, TimeUnit.MINUTES);
|
// if (!redis.hasKey("value:" + messageId)) {
|
||||||
}
|
// redis.setCacheObject("value:" + messageId, "" + deliveryTag, 5, TimeUnit.MINUTES);
|
||||||
|
// }
|
||||||
// 1 添加成功新数据 0已有重复值,不允许再添加
|
//
|
||||||
Long add = redis.opsForSet().add("set:" + messageId, "set:" + messageId);
|
// // 1 添加成功新数据 0已有重复值,不允许再添加
|
||||||
//过期时间
|
// Long add = redis.opsForSet().add("set:" + messageId, "set:" + messageId);
|
||||||
redis.expire("set:" + messageId, 5, TimeUnit.MINUTES);
|
// //过期时间
|
||||||
|
// redis.expire("set:" + messageId, 5, TimeUnit.MINUTES);
|
||||||
|
//
|
||||||
try {
|
//
|
||||||
if (add == 1) {
|
// try {
|
||||||
//第一次 消费
|
// if (add == 1) {
|
||||||
System.out.println("*****************************");
|
// //第一次 消费
|
||||||
System.out.println("消费者收到消息:" + param);
|
// System.out.println("*****************************");
|
||||||
System.out.println("*****************************");
|
// System.out.println("消费者收到消息:" + param);
|
||||||
log.info("消费结束");
|
// System.out.println("*****************************");
|
||||||
|
// log.info("消费结束");
|
||||||
//确认消费
|
//
|
||||||
channel.basicAck(deliveryTag, false);
|
// //确认消费
|
||||||
|
// channel.basicAck(deliveryTag, false);
|
||||||
} else {
|
//
|
||||||
//重复消费
|
// } else {
|
||||||
log.error("重复消费");
|
// //重复消费
|
||||||
//拒绝消费
|
// log.error("重复消费");
|
||||||
channel.basicReject(deliveryTag, false);
|
// //拒绝消费
|
||||||
|
// channel.basicReject(deliveryTag, false);
|
||||||
//删除缓存
|
//
|
||||||
redis.opsForSet().remove("set:" + messageId, "set:" + messageId);
|
// //删除缓存
|
||||||
}
|
// redis.opsForSet().remove("set:" + messageId, "set:" + messageId);
|
||||||
|
// }
|
||||||
|
//
|
||||||
} catch (Exception e) {
|
//
|
||||||
log.error("消息没有成功消费!");
|
// } catch (Exception e) {
|
||||||
|
// log.error("消息没有成功消费!");
|
||||||
String s = redis.opsForValue().get("value:" + messageId);
|
//
|
||||||
|
// String s = redis.opsForValue().get("value:" + messageId);
|
||||||
long oldTag = Long.parseLong(s);
|
//
|
||||||
|
// long oldTag = Long.parseLong(s);
|
||||||
if (deliveryTag == (oldTag + 2)) {
|
//
|
||||||
log.error("确实消费不了,不入队了!");
|
// if (deliveryTag == (oldTag + 2)) {
|
||||||
|
// log.error("确实消费不了,不入队了!");
|
||||||
|
//
|
||||||
//拒绝消费
|
//
|
||||||
channel.basicNack(deliveryTag, false, false);
|
// //拒绝消费
|
||||||
} else {
|
// channel.basicNack(deliveryTag, false, false);
|
||||||
log.info("消息消费失败,重新入队");
|
// } else {
|
||||||
//重新入队
|
// log.info("消息消费失败,重新入队");
|
||||||
channel.basicNack(deliveryTag, false, true);
|
// //重新入队
|
||||||
}
|
// channel.basicNack(deliveryTag, false, true);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//}
|
||||||
|
|
|
@ -33,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
|
||||||
|
|
||||||
|
|
45
pom.xml
45
pom.xml
|
@ -211,63 +211,18 @@
|
||||||
<artifactId>couplet-modules-system</artifactId>
|
<artifactId>couplet-modules-system</artifactId>
|
||||||
<version>${couplet.version}</version>
|
<version>${couplet.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>com.couplet</groupId>-->
|
|
||||||
<!-- <artifactId>couplet-trouble</artifactId>-->
|
|
||||||
<!-- <version>${couplet.version}</version>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>com.couplet</groupId>-->
|
|
||||||
<!-- <artifactId>couplet-electronic-fence-server</artifactId>-->
|
|
||||||
<!-- <version>${couplet.version}</version>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>com.couplet</groupId>-->
|
|
||||||
<!-- <artifactId>couplet-electronic-fence-common</artifactId>-->
|
|
||||||
<!-- <version>${couplet.version}</version>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>com.couplet</groupId>-->
|
|
||||||
<!-- <artifactId>couplet-electronic-fence-remote</artifactId>-->
|
|
||||||
<!-- <version>${couplet.version}</version>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
|
|
||||||
<!-- <!– 企业服务 模块 公共依赖 –>-->
|
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>com.couplet</groupId>-->
|
|
||||||
<!-- <artifactId>couplet-enterprisemanagement-common</artifactId>-->
|
|
||||||
<!-- <version>${couplet.version}</version>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
|
|
||||||
<!-- <!– 企业服务 模块 远程调用依赖 –>-->
|
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>com.couplet</groupId>-->
|
|
||||||
<!-- <artifactId>couplet-enterprisemanagement-remote</artifactId>-->
|
|
||||||
<!-- <version>${couplet.version}</version>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
|
|
||||||
<!-- <!– 车辆管理模块 –>-->
|
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>com.couplet</groupId>-->
|
|
||||||
<!-- <artifactId>couplet-modules-vehicle</artifactId>-->
|
|
||||||
<!-- <version>${couplet.version}</version>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
|
|
||||||
<!-- RabbitMq模块 -->
|
<!-- RabbitMq模块 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.couplet</groupId>
|
<groupId>com.couplet</groupId>
|
||||||
<artifactId>couplet-modules-mq</artifactId>
|
<artifactId>couplet-modules-mq</artifactId>
|
||||||
<version>${couplet.version}</version>
|
<version>${couplet.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- 业务系统核心模块 -->
|
<!-- 业务系统核心模块 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.couplet</groupId>
|
<groupId>com.couplet</groupId>
|
||||||
<artifactId>couplet-common-business</artifactId>
|
<artifactId>couplet-common-business</artifactId>
|
||||||
<version>${couplet.version}</version>
|
<version>${couplet.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 车辆上线模块-->
|
<!-- 车辆上线模块-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.couplet</groupId>
|
<groupId>com.couplet</groupId>
|
||||||
|
|
Loading…
Reference in New Issue