更新故障

master
王堂东 2023-12-06 08:13:12 +08:00
parent bfa16fa262
commit 0e78988ed1
5 changed files with 156 additions and 168 deletions

View File

@ -1,6 +1,6 @@
# Tomcat # Tomcat
server: server:
port: 8085 port: 8087
# Spring # Spring
spring: spring:
application: application:

View File

@ -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);
}

View File

@ -2,13 +2,19 @@ package com.fivegroup.analysis.service.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.fivegroup.analysis.domain.VehicleData; import com.fivegroup.analysis.domain.VehicleData;
import com.fivegroup.analysis.feign.FaultLogFeign;
import com.fivegroup.analysis.service.VehicleIncidentService; 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.AllArgsConstructor;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.UUID; import java.util.UUID;
/** /**
@ -23,10 +29,10 @@ import java.util.UUID;
public class VehicleBreakdownIncidentServiceImpl implements VehicleIncidentService { public class VehicleBreakdownIncidentServiceImpl implements VehicleIncidentService {
@Autowired @Autowired
private RabbitTemplate rabbitTemplate; private RabbitTemplate rabbitTemplate;
// @Autowired @Autowired
// private FaultLogMapper faultLogMapper; private FaultLogFeign faultLogFeign;
/** /**
* *
@ -35,130 +41,71 @@ public class VehicleBreakdownIncidentServiceImpl implements VehicleIncidentServ
@Override @Override
public void execute(VehicleData vehicleDate) { 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(); ArrayList<String> strings = new ArrayList<>();
// if (vehicleDate.getVehicleStatus() == 0) { ArrayList<String> strings2 = new ArrayList<>();
// faultLog.setCarVin(vehicleDate.getVin()); FaultLog faultLog = new FaultLog();
// faultLog.setFaultStartTime(new Date()); FaultCode faultCode = new FaultCode();
// faultLog.setFaultDetail("车辆状态异常"); if (vehicleDate.getVehicleStatus() == 0) {
// log.info("车辆状态异常,车辆VIN{}",vehicleDate.getVin()); log.info("车辆状态异常,车辆VIN{}", vehicleDate.getVin());
// strings.add("车辆状态异常"); strings.add("车辆状态异常");
// } strings2.add("GTX001");
// if (vehicleDate.getChargingStatus() == 0) { }
// faultLog.setCarVin(vehicleDate.getVin()); if (vehicleDate.getChargingStatus() == 0) {
// faultLog.setFaultStartTime(new Date()); log.info("充电状态异常,车辆VIN{}", vehicleDate.getVin());
// faultLog.setFaultDetail("充电状态异常"); strings.add("充电状态异常");
// log.info("充电状态异常,车辆VIN{}",vehicleDate.getVin()); strings2.add("GTX002");
// strings.add("充电状态异常"); }
// } if (vehicleDate.getOperatingStatus() == 0) {
// if (vehicleDate.getOperatingStatus() == 0) { log.info("运行状态异常,车辆VIN{}", vehicleDate.getVin());
// faultLog.setCarVin(vehicleDate.getVin()); strings.add("运行状态异常");
// faultLog.setFaultStartTime(new Date()); strings2.add("GTX003");
// faultLog.setFaultDetail("运行状态异常"); }
// log.info("运行状态异常,车辆VIN{}",vehicleDate.getVin()); if (vehicleDate.getSocStatus() == 0) {
// strings.add("运行状态异常"); log.info("SOC状态异常,车辆VIN{}", vehicleDate.getVin());
// } strings.add("SOC状态异常");
// if (vehicleDate.getSocStatus() == 0) { strings2.add("GTX004");
// faultLog.setCarVin(vehicleDate.getVin()); }
// faultLog.setFaultStartTime(new Date()); if (vehicleDate.getChargingEnergyStorageStatus() == 0) {
// faultLog.setFaultDetail("SOC状态异常"); log.info("充电电池状态异常,车辆VIN{}", vehicleDate.getVin());
// log.info("SOC状态异常,车辆VIN{}",vehicleDate.getVin()); strings.add("充电状态异常");
// strings.add("SOC状态异常"); strings2.add("GTX005");
// } }
// if (vehicleDate.getChargingEnergyStorageStatus() == 0) { if (vehicleDate.getDriveMotorStatus() == 0) {
// faultLog.setCarVin(vehicleDate.getVin()); log.info("驱动电机状态异常,车辆VIN{}", vehicleDate.getVin());
// faultLog.setFaultStartTime(new Date()); strings.add("驱动电机状态异常");
// faultLog.setFaultDetail("充电电池状态异常"); strings2.add("GTX006");
// log.info("充电电池状态异常,车辆VIN{}",vehicleDate.getVin()); }
// strings.add("充电状态异常"); if (vehicleDate.getPositionStatus() == 0) {
// } log.info("定位状态异常,车辆VIN{}", vehicleDate.getVin());
// if (vehicleDate.getDriveMotorStatus() == 0) { strings.add("定位状态异常");
// faultLog.setCarVin(vehicleDate.getVin()); strings2.add("GTX007");
// faultLog.setFaultStartTime(new Date()); }
// faultLog.setFaultDetail("驱动电机状态异常"); log.info("--------------");
// log.info("驱动电机状态异常,车辆VIN{}",vehicleDate.getVin()); log.info("settings集合" + strings);
// strings.add("驱动电机状态异常"); log.info("settings2集合" + strings2);
// } for (int i = 0; i < strings.size(); i++) {
// if (vehicleDate.getPositionStatus() == 0) { /**
// faultLog.setCarVin(vehicleDate.getVin()); *
// faultLog.setFaultStartTime(new Date()); */
// faultLog.setFaultDetail("定位状态异常"); faultCode.setFaultBh(strings2.get(i));
// log.info("定位状态异常,车辆VIN{}",vehicleDate.getVin()); faultCode.setFaultTypeId(1);
// strings.add("定位状态异常"); faultCode.setFaultSeat(200);
// } faultCode.setFaultValue("00");
// for (String string : strings) { faultCode.setFaultTag("小故障");
// faultLog.setFaultDetail(string); faultCode.setIsWarn(0);
// } faultCode.setFaultGrade(1);
// faultLogMapper.addLog(faultLog); faultLogFeign.addFaultCode(faultCode);
// log.info("--------------"); /**
log.info("车辆VIN{}有故障",vehicleDate.getVin()); *
if(vehicleDate.getVehicleStatus()==0){ */
rabbitTemplate.convertAndSend("faultQueue",JSONObject.toJSONString(vehicleDate),message -> { faultLog.setCarVin(vehicleDate.getVin());
message.getMessageProperties().setMessageId(UUID.randomUUID().toString().replaceAll("-","")); faultLog.setFaultDetail(strings.get(i));
return message; faultLog.setFaultStartTime(new Date());
}); faultLog.setFaultBh(strings2.get(i));
faultLogFeign.addFaultLog(faultLog);
}
} }
}
} }

View File

@ -1,39 +1,40 @@
# Tomcat
server: server:
port: 8081 port: 8081
# Spring
spring: spring:
rabbitmq: rabbitmq:
host: 101.34.69.116
port: 5672
username: guest username: guest
password: guest password: guest
template: virtualHost: /
mandatory: true port: 5672
host: 101.34.69.116
listener: listener:
simple: simple:
prefetch: 1 # 每次取一条消息消费 消费完成取下一条 prefetch: 1 # 每次只能获取一条,处理完成才能获取下一条
acknowledge-mode: manual # 设置消费端手动ack确认 publisher-confirm-type: correlated #确认消息已发送到交换机(Exchange)
retry:
enabled: true # 支持重试
publisher-confirms: true #确认消息已发送到交换机(Exchange)
publisher-returns: true #确认消息已发送到队列(Queue) publisher-returns: true #确认消息已发送到队列(Queue)
redis: application:
host: 101.34.69.116 # Redis服务器主机地址 # 应用名称
port: 6379 # Redis服务器端口号 name: fivegroup-analysis
password: # Redis密码如果没有则为空 profiles:
timeout: 3000 # 连接超时时间,单位为毫秒 # 环境配置
database: 0 # Redis数据库索引号默认为0 active: dev
datasource: cloud:
url: jdbc:mysql://101.34.69.116:3306/car?characterEncoding=utf-8&serverTimezone=Asia/Shanghai nacos:
username: root discovery:
password: zhang0318. # 服务注册地址
driver-class-name: com.mysql.cj.jdbc.Driver server-addr: 101.34.69.116:8848
druid: config:
initial-size: 5 # 初始化时建立物理连接的个数。初始化发生在显示调用init方法或者第一次getConnection时 # 配置中心地址
min-idle: 5 # 最小连接池数量 server-addr: 101.34.69.116:8848
max-active: 20 # 最大连接池数量 # 配置文件格式
max-wait: 60000 # 获取连接时最大等待时间单位毫秒。配置了maxWait之后缺省启用公平锁 file-extension: yml
mybatis: # 共享配置
# 搜索指定包别名 shared-configs:
typeAliasesPackage: com.fivegroup.analysis.domain - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
# 配置mapper的扫描找到所有的mapper.xml映射文件 logging:
mapperLocations: classpath:mapper/**/*.xml level:
com.fivegroup.system.mapper: DEBUG

View File

@ -14,6 +14,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import java.util.ArrayList; 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 { public class FaultDetailTest {
@Autowired @Autowired
private VehicleBreakdownIncidentServiceImpl vehicleBreakdownIncidentService; private VehicleBreakdownIncidentServiceImpl vehicleBreakdownIncidentService;
/** /**
* *
*/ */
@ -35,20 +40,30 @@ public class FaultDetailTest {
// 添加第三个JSON字符串 // 添加第三个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\"}"); 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->{ ExecutorService executor = Executors.newFixedThreadPool(5); // 创建一个具有5个线程的线程池
// 将JSON字符串转换为VehicleData对象
VehicleData vehicleData = JSONObject.parseObject(s, VehicleData.class); for (String data : list) {
// 执行车辆故障 breakdown 逻辑 executor.submit(() -> {
vehicleBreakdownIncidentService.execute(vehicleData);
try { try {
// 线程休眠1秒 VehicleData vehicleData = JSONObject.parseObject(data, VehicleData.class);
Thread.sleep(1000); vehicleBreakdownIncidentService.execute(vehicleData);
}catch (InterruptedException e){ } catch (Exception e) {
throw new RuntimeException(e); // 处理异常,这里可以选择记录日志或者进行其他适当的处理
e.printStackTrace();
} }
}); });
}).start();
try {
Thread.sleep(1000); // 休眠1秒钟
} catch (InterruptedException e) {
Thread.currentThread().interrupt(); // 保持线程的中断状态
}
}
executor.shutdown(); // 关闭线程池
} }