更新故障
parent
bfa16fa262
commit
0e78988ed1
|
@ -1,6 +1,6 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 8085
|
||||
port: 8087
|
||||
# Spring
|
||||
spring:
|
||||
application:
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package com.fivegroup.analysis.feign;
|
||||
|
||||
import com.fivegroup.common.core.domain.Result;
|
||||
import com.fivegroup.fault.aspect.WebLog;
|
||||
import com.fivegroup.fault.domain.FaultCode;
|
||||
import com.fivegroup.fault.domain.FaultLog;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* @program: car-server
|
||||
* @description:
|
||||
* @author: Mr.Wang
|
||||
* @create: 2023-12-05 14:07
|
||||
**/
|
||||
@FeignClient(value = "fivegroup-fault")
|
||||
public interface FaultLogFeign {
|
||||
@PostMapping("/faultLog/add")
|
||||
@WebLog(description = "新增故障日志")
|
||||
public void addFaultLog(@RequestBody FaultLog faultLog);
|
||||
@PostMapping("/faultCode/add")
|
||||
@WebLog(description = "添加故障码信息")
|
||||
public Result addFaultCode(@RequestBody FaultCode faultCode);
|
||||
}
|
|
@ -2,13 +2,19 @@ package com.fivegroup.analysis.service.impl;
|
|||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fivegroup.analysis.domain.VehicleData;
|
||||
import com.fivegroup.analysis.feign.FaultLogFeign;
|
||||
import com.fivegroup.analysis.service.VehicleIncidentService;
|
||||
import com.fivegroup.fault.domain.FaultCode;
|
||||
import com.fivegroup.fault.domain.FaultLog;
|
||||
import com.fivegroup.fault.domain.req.FaultCodeReq;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
@ -25,8 +31,8 @@ public class VehicleBreakdownIncidentServiceImpl implements VehicleIncidentServ
|
|||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
// @Autowired
|
||||
// private FaultLogMapper faultLogMapper;
|
||||
@Autowired
|
||||
private FaultLogFeign faultLogFeign;
|
||||
|
||||
/**
|
||||
* 车辆故障信息
|
||||
|
@ -35,130 +41,71 @@ public class VehicleBreakdownIncidentServiceImpl implements VehicleIncidentServ
|
|||
@Override
|
||||
public void execute(VehicleData vehicleDate) {
|
||||
|
||||
// ArrayList<String> strings = new ArrayList<>();
|
||||
// FaultLog faultLog = new FaultLog();
|
||||
// List<VehicleData> vehicleData = new ArrayList<>();
|
||||
// vehicleData.add(vehicleDate);
|
||||
//
|
||||
// vehicleData.forEach(item->{
|
||||
// if (item.getVehicleStatus() == 0) {
|
||||
// faultLog.setCarVin(item.getVin());
|
||||
// faultLog.setFaultStartTime(new Date());
|
||||
// faultLog.setFaultDetail("车辆状态异常");
|
||||
// log.info("车辆状态异常,车辆VIN:{}",item.getVin());
|
||||
// strings.add("车辆状态异常");
|
||||
// }
|
||||
// if (item.getChargingStatus() == 0) {
|
||||
// faultLog.setCarVin(item.getVin());
|
||||
// faultLog.setFaultStartTime(new Date());
|
||||
// faultLog.setFaultDetail("充电状态异常");
|
||||
// log.info("充电状态异常,车辆VIN:{}",item.getVin());
|
||||
// strings.add("充电状态异常");
|
||||
// }
|
||||
// if (item.getOperatingStatus() == 0) {
|
||||
// faultLog.setCarVin(item.getVin());
|
||||
// faultLog.setFaultStartTime(new Date());
|
||||
// faultLog.setFaultDetail("运行状态异常");
|
||||
// log.info("运行状态异常,车辆VIN:{}",item.getVin());
|
||||
// strings.add("运行状态异常");
|
||||
// }
|
||||
// if (item.getSocStatus() == 0) {
|
||||
// faultLog.setCarVin(item.getVin());
|
||||
// faultLog.setFaultStartTime(new Date());
|
||||
// faultLog.setFaultDetail("SOC状态异常");
|
||||
// log.info("SOC状态异常,车辆VIN:{}",item.getVin());
|
||||
// strings.add("SOC状态异常");
|
||||
// }
|
||||
// if (item.getChargingEnergyStorageStatus() == 0) {
|
||||
// faultLog.setCarVin(item.getVin());
|
||||
// faultLog.setFaultStartTime(new Date());
|
||||
// faultLog.setFaultDetail("充电电池状态异常");
|
||||
// log.info("充电电池状态异常,车辆VIN:{}",item.getVin());
|
||||
// strings.add("充电状态异常");
|
||||
// }
|
||||
// if (item.getDriveMotorStatus() == 0) {
|
||||
// faultLog.setCarVin(item.getVin());
|
||||
// faultLog.setFaultStartTime(new Date());
|
||||
// faultLog.setFaultDetail("驱动电机状态异常");
|
||||
// log.info("驱动电机状态异常,车辆VIN:{}",item.getVin());
|
||||
// strings.add("驱动电机状态异常");
|
||||
// }
|
||||
// if (item.getPositionStatus() == 0) {
|
||||
// faultLog.setCarVin(item.getVin());
|
||||
// faultLog.setFaultStartTime(new Date());
|
||||
// faultLog.setFaultDetail("定位状态异常");
|
||||
// log.info("定位状态异常,车辆VIN:{}",item.getVin());
|
||||
// strings.add("定位状态异常");
|
||||
// }
|
||||
// faultLogMapper.addLog(faultLog);
|
||||
// });
|
||||
|
||||
// FaultLog faultLog = new FaultLog();
|
||||
// if (vehicleDate.getVehicleStatus() == 0) {
|
||||
// faultLog.setCarVin(vehicleDate.getVin());
|
||||
// faultLog.setFaultStartTime(new Date());
|
||||
// faultLog.setFaultDetail("车辆状态异常");
|
||||
// log.info("车辆状态异常,车辆VIN:{}",vehicleDate.getVin());
|
||||
// strings.add("车辆状态异常");
|
||||
// }
|
||||
// if (vehicleDate.getChargingStatus() == 0) {
|
||||
// faultLog.setCarVin(vehicleDate.getVin());
|
||||
// faultLog.setFaultStartTime(new Date());
|
||||
// faultLog.setFaultDetail("充电状态异常");
|
||||
// log.info("充电状态异常,车辆VIN:{}",vehicleDate.getVin());
|
||||
// strings.add("充电状态异常");
|
||||
// }
|
||||
// if (vehicleDate.getOperatingStatus() == 0) {
|
||||
// faultLog.setCarVin(vehicleDate.getVin());
|
||||
// faultLog.setFaultStartTime(new Date());
|
||||
// faultLog.setFaultDetail("运行状态异常");
|
||||
// log.info("运行状态异常,车辆VIN:{}",vehicleDate.getVin());
|
||||
// strings.add("运行状态异常");
|
||||
// }
|
||||
// if (vehicleDate.getSocStatus() == 0) {
|
||||
// faultLog.setCarVin(vehicleDate.getVin());
|
||||
// faultLog.setFaultStartTime(new Date());
|
||||
// faultLog.setFaultDetail("SOC状态异常");
|
||||
// log.info("SOC状态异常,车辆VIN:{}",vehicleDate.getVin());
|
||||
// strings.add("SOC状态异常");
|
||||
// }
|
||||
// if (vehicleDate.getChargingEnergyStorageStatus() == 0) {
|
||||
// faultLog.setCarVin(vehicleDate.getVin());
|
||||
// faultLog.setFaultStartTime(new Date());
|
||||
// faultLog.setFaultDetail("充电电池状态异常");
|
||||
// log.info("充电电池状态异常,车辆VIN:{}",vehicleDate.getVin());
|
||||
// strings.add("充电状态异常");
|
||||
// }
|
||||
// if (vehicleDate.getDriveMotorStatus() == 0) {
|
||||
// faultLog.setCarVin(vehicleDate.getVin());
|
||||
// faultLog.setFaultStartTime(new Date());
|
||||
// faultLog.setFaultDetail("驱动电机状态异常");
|
||||
// log.info("驱动电机状态异常,车辆VIN:{}",vehicleDate.getVin());
|
||||
// strings.add("驱动电机状态异常");
|
||||
// }
|
||||
// if (vehicleDate.getPositionStatus() == 0) {
|
||||
// faultLog.setCarVin(vehicleDate.getVin());
|
||||
// faultLog.setFaultStartTime(new Date());
|
||||
// faultLog.setFaultDetail("定位状态异常");
|
||||
// log.info("定位状态异常,车辆VIN:{}",vehicleDate.getVin());
|
||||
// strings.add("定位状态异常");
|
||||
// }
|
||||
// for (String string : strings) {
|
||||
// faultLog.setFaultDetail(string);
|
||||
// }
|
||||
// faultLogMapper.addLog(faultLog);
|
||||
// log.info("--------------");
|
||||
log.info("车辆VIN:{}有故障",vehicleDate.getVin());
|
||||
if(vehicleDate.getVehicleStatus()==0){
|
||||
rabbitTemplate.convertAndSend("faultQueue",JSONObject.toJSONString(vehicleDate),message -> {
|
||||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString().replaceAll("-",""));
|
||||
return message;
|
||||
});
|
||||
ArrayList<String> strings = new ArrayList<>();
|
||||
ArrayList<String> strings2 = new ArrayList<>();
|
||||
FaultLog faultLog = new FaultLog();
|
||||
FaultCode faultCode = new FaultCode();
|
||||
if (vehicleDate.getVehicleStatus() == 0) {
|
||||
log.info("车辆状态异常,车辆VIN:{}", vehicleDate.getVin());
|
||||
strings.add("车辆状态异常");
|
||||
strings2.add("GTX001");
|
||||
}
|
||||
if (vehicleDate.getChargingStatus() == 0) {
|
||||
log.info("充电状态异常,车辆VIN:{}", vehicleDate.getVin());
|
||||
strings.add("充电状态异常");
|
||||
strings2.add("GTX002");
|
||||
}
|
||||
if (vehicleDate.getOperatingStatus() == 0) {
|
||||
log.info("运行状态异常,车辆VIN:{}", vehicleDate.getVin());
|
||||
strings.add("运行状态异常");
|
||||
strings2.add("GTX003");
|
||||
}
|
||||
if (vehicleDate.getSocStatus() == 0) {
|
||||
log.info("SOC状态异常,车辆VIN:{}", vehicleDate.getVin());
|
||||
strings.add("SOC状态异常");
|
||||
strings2.add("GTX004");
|
||||
}
|
||||
if (vehicleDate.getChargingEnergyStorageStatus() == 0) {
|
||||
log.info("充电电池状态异常,车辆VIN:{}", vehicleDate.getVin());
|
||||
strings.add("充电状态异常");
|
||||
strings2.add("GTX005");
|
||||
}
|
||||
if (vehicleDate.getDriveMotorStatus() == 0) {
|
||||
log.info("驱动电机状态异常,车辆VIN:{}", vehicleDate.getVin());
|
||||
strings.add("驱动电机状态异常");
|
||||
strings2.add("GTX006");
|
||||
}
|
||||
if (vehicleDate.getPositionStatus() == 0) {
|
||||
log.info("定位状态异常,车辆VIN:{}", vehicleDate.getVin());
|
||||
strings.add("定位状态异常");
|
||||
strings2.add("GTX007");
|
||||
}
|
||||
log.info("--------------");
|
||||
log.info("settings集合" + strings);
|
||||
log.info("settings2集合" + strings2);
|
||||
for (int i = 0; i < strings.size(); i++) {
|
||||
/**
|
||||
* 故障码信息添加
|
||||
*/
|
||||
faultCode.setFaultBh(strings2.get(i));
|
||||
faultCode.setFaultTypeId(1);
|
||||
faultCode.setFaultSeat(200);
|
||||
faultCode.setFaultValue("00");
|
||||
faultCode.setFaultTag("小故障");
|
||||
faultCode.setIsWarn(0);
|
||||
faultCode.setFaultGrade(1);
|
||||
faultLogFeign.addFaultCode(faultCode);
|
||||
/**
|
||||
* 故障日志添加
|
||||
*/
|
||||
faultLog.setCarVin(vehicleDate.getVin());
|
||||
faultLog.setFaultDetail(strings.get(i));
|
||||
faultLog.setFaultStartTime(new Date());
|
||||
faultLog.setFaultBh(strings2.get(i));
|
||||
faultLogFeign.addFaultLog(faultLog);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,39 +1,40 @@
|
|||
# Tomcat
|
||||
server:
|
||||
port: 8081
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
rabbitmq:
|
||||
host: 101.34.69.116
|
||||
port: 5672
|
||||
username: guest
|
||||
password: guest
|
||||
template:
|
||||
mandatory: true
|
||||
virtualHost: /
|
||||
port: 5672
|
||||
host: 101.34.69.116
|
||||
listener:
|
||||
simple:
|
||||
prefetch: 1 # 每次取一条消息消费 消费完成取下一条
|
||||
acknowledge-mode: manual # 设置消费端手动ack确认
|
||||
retry:
|
||||
enabled: true # 支持重试
|
||||
publisher-confirms: true #确认消息已发送到交换机(Exchange)
|
||||
prefetch: 1 # 每次只能获取一条,处理完成才能获取下一条
|
||||
publisher-confirm-type: correlated #确认消息已发送到交换机(Exchange)
|
||||
publisher-returns: true #确认消息已发送到队列(Queue)
|
||||
redis:
|
||||
host: 101.34.69.116 # Redis服务器主机地址
|
||||
port: 6379 # Redis服务器端口号
|
||||
password: # Redis密码,如果没有则为空
|
||||
timeout: 3000 # 连接超时时间,单位为毫秒
|
||||
database: 0 # Redis数据库索引号,默认为0
|
||||
datasource:
|
||||
url: jdbc:mysql://101.34.69.116:3306/car?characterEncoding=utf-8&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: zhang0318.
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
druid:
|
||||
initial-size: 5 # 初始化时建立物理连接的个数。初始化发生在显示调用init方法,或者第一次getConnection时
|
||||
min-idle: 5 # 最小连接池数量
|
||||
max-active: 20 # 最大连接池数量
|
||||
max-wait: 60000 # 获取连接时最大等待时间,单位毫秒。配置了maxWait之后,缺省启用公平锁,并
|
||||
mybatis:
|
||||
# 搜索指定包别名
|
||||
typeAliasesPackage: com.fivegroup.analysis.domain
|
||||
# 配置mapper的扫描,找到所有的mapper.xml映射文件
|
||||
mapperLocations: classpath:mapper/**/*.xml
|
||||
application:
|
||||
# 应用名称
|
||||
name: fivegroup-analysis
|
||||
profiles:
|
||||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 101.34.69.116:8848
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 101.34.69.116:8848
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
logging:
|
||||
level:
|
||||
com.fivegroup.system.mapper: DEBUG
|
||||
|
||||
|
|
|
@ -14,6 +14,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 测试
|
||||
|
@ -22,6 +26,7 @@ import java.util.ArrayList;
|
|||
public class FaultDetailTest {
|
||||
@Autowired
|
||||
private VehicleBreakdownIncidentServiceImpl vehicleBreakdownIncidentService;
|
||||
|
||||
/**
|
||||
* 故障详情测试方法
|
||||
*/
|
||||
|
@ -35,20 +40,30 @@ public class FaultDetailTest {
|
|||
// 添加第三个JSON字符串
|
||||
list.add("{\"absStatus\":1,\"accelerationPedal\":\"8\",\"availableBatteryCapacity\":\"90\",\"batteryInsulationStatus\":1,\"batteryLevel\":50000,\"batteryStatus\":1,\"brakePedal\":\"3\",\"chargingEnergyStorageStatus\":1,\"chargingStatus\":1,\"chgStatus\":1,\"current\":\"43\",\"dcdcStatus\":1,\"driveMotorStatus\":1,\"easStatus\":1,\"epsStatus\":1,\"fuelConsumptionRate\":\"9.90\",\"gear\":\"D\",\"heatingStatus\":1,\"latitude\":\"39.536898\",\"longitude\":\"116.670799\",\"maximumDischargePower\":\"45\",\"maximumFeedbackPower\":\"68\",\"mcuStatus\":1,\"mileage\":12.94,\"motorControllerTemperature\":\"72\",\"motorCurrent\":\"2762\",\"motorSpeed\":\"25959\",\"motorTemperature\":\"13\",\"motorTorque\":\"467\",\"motorVoltage\":\"116\",\"msg\":\"VIN323456789123451701419209989116.670799039.536898072.00012.9400000052700043000287600000D80309.900720007013000002595946116002762000044970.68000045000080800007390003000400031000053000090000011111111111111111\",\"operatingStatus\":1,\"positionStatus\":1,\"ptcStatus\":1,\"remainingBattery\":44970.30,\"resistance\":\"2876\",\"selfCheckCounter\":\"8\",\"singleBatteryMaxTemperature\":\"31\",\"singleBatteryMaxVoltage\":\"3\",\"singleBatteryMinTemperature\":\"53\",\"singleBatteryMinVoltage\":\"4\",\"socStatus\":1,\"speed\":\"72.00\",\"totalBatteryCurrent\":\"8\",\"totalBatteryVoltage\":\"739\",\"vehicleStatus\":1,\"vin\":\"VIN32345678912345\",\"voltage\":\"527\"}");
|
||||
// 在新线程中执行逻辑
|
||||
new Thread(() -> {
|
||||
list.forEach(s->{
|
||||
// 将JSON字符串转换为VehicleData对象
|
||||
VehicleData vehicleData = JSONObject.parseObject(s, VehicleData.class);
|
||||
// 执行车辆故障 breakdown 逻辑
|
||||
vehicleBreakdownIncidentService.execute(vehicleData);
|
||||
|
||||
ExecutorService executor = Executors.newFixedThreadPool(5); // 创建一个具有5个线程的线程池
|
||||
|
||||
for (String data : list) {
|
||||
executor.submit(() -> {
|
||||
try {
|
||||
// 线程休眠1秒
|
||||
Thread.sleep(1000);
|
||||
}catch (InterruptedException e){
|
||||
throw new RuntimeException(e);
|
||||
VehicleData vehicleData = JSONObject.parseObject(data, VehicleData.class);
|
||||
vehicleBreakdownIncidentService.execute(vehicleData);
|
||||
} catch (Exception e) {
|
||||
// 处理异常,这里可以选择记录日志或者进行其他适当的处理
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}).start();
|
||||
|
||||
try {
|
||||
Thread.sleep(1000); // 休眠1秒钟
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt(); // 保持线程的中断状态
|
||||
}
|
||||
}
|
||||
|
||||
executor.shutdown(); // 关闭线程池
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue