feat commit

存储事件、故障事件
server_2024_4_2_yuanyonghao
JangCan 2024-04-08 15:00:36 +08:00
parent c99d1e0e89
commit 08a8480ab5
21 changed files with 296 additions and 16 deletions

View File

@ -15,9 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 10.10.25.2:8848
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
config:
# 配置中心地址
server-addr: 10.10.25.2:8848
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -20,6 +20,7 @@
<module>zhilian-common-system</module>
<module>zhilian-common-resolver</module>
<module>zhilian-common-business</module>
<module>zhilian-common-event</module>
</modules>
<artifactId>zhilian-common</artifactId>

View File

@ -0,0 +1,27 @@
<?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.zhilian</groupId>
<artifactId>zhilian-common</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>zhilian-common-event</artifactId>
<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.zhilian</groupId>
<artifactId>zhilian-common-redis</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,18 @@
package com.zhilian.common.event;
import com.zhilian.common.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
public class VehicleEventCache {
@Autowired
private RedisService redisService;
public String encode(String vin){
return "event:arr"+vin;
}
public void addEvent(String vin ,String eventName){
redisService.setCacheSet(encode(vin),eventName);
}
}

View File

@ -0,0 +1,4 @@
package com.zhilian.common.event;
public interface VehicleEventConstants {
}

View File

@ -154,6 +154,19 @@ public class RedisService {
return setOperation;
}
/**
* Set
*
* @param key
* @param setValue
* @return
*/
public <T> BoundSetOperations<String, T> setCacheSet(final String key, final T setValue) {
BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
setOperation.add(setValue);
return setOperation;
}
/**
* set
*

View File

@ -0,0 +1,23 @@
package com.zhilian.common.resolver.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @ClassName ErrorCar
* @Description
* @Author Can.J
* @Date 2024/4/8 12:50
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
public class ErrorCar {
private Long id;
private String vin;
private String code;
private int level;
}

View File

@ -15,9 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 10.10.25.2:8848
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
config:
# 配置中心地址
server-addr: 10.10.25.2:8848
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
# 配置文件格式
file-extension: yml
# 共享配置
@ -38,3 +40,4 @@ spring:
groupId: DEFAULT_GROUP
data-type: json
rule-type: gw-flow

View File

@ -15,9 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 10.10.25.2:8848
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
config:
# 配置中心地址
server-addr: 10.10.25.2:8848
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -15,9 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 10.10.25.2:8848
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
config:
# 配置中心地址
server-addr: 10.10.25.2:8848
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -15,9 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 10.10.25.2:8848
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
config:
# 配置中心地址
server-addr: 10.10.25.2:8848
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -15,9 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 10.10.25.2:8848
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
config:
# 配置中心地址
server-addr: 10.10.25.2:8848
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -15,9 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 10.10.25.2:8848
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
config:
# 配置中心地址
server-addr: 10.10.25.2:8848
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -15,9 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 10.10.25.2:8848
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
config:
# 配置中心地址
server-addr: 10.10.25.2:8848
namespace: 9d9e22dc-ff70-42c5-adac-fa69e6d62dbe
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -117,6 +117,10 @@
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
</dependency>
<dependency>
<groupId>com.zhilian</groupId>
<artifactId>zhilian-common-business</artifactId>
</dependency>
</dependencies>

View File

@ -0,0 +1,19 @@
package com.zhilian.resolver;
import com.zhilian.common.security.annotation.EnableMyFeignClients;
import com.zhilian.common.swagger.annotation.EnableCustomSwagger2;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@EnableCustomSwagger2
@EnableScheduling
@EnableMyFeignClients
@MapperScan({"com.zhilian.resolver.mapper", "com.zhilian.resolver.resolverReport"})
@SpringBootApplication
public class ZhiLianResolverApplication {
public static void main(String[] args) {
SpringApplication.run(ZhiLianResolverApplication.class, args);
}
}

View File

@ -1,10 +1,18 @@
package com.zhilian.resolver.service.impl.eventGeofence;
import com.zhilian.business.domain.Fence;
import com.zhilian.business.domain.vo.FenceVo;
import com.zhilian.common.resolver.domain.ResolverReportData;
import com.zhilian.resolver.service.ResolverEventService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
import static java.lang.Double.parseDouble;
/**
* @ClassName GeofenceEventServiceImpl
* @Description
@ -14,14 +22,68 @@ import org.springframework.stereotype.Service;
@Slf4j
@Service("geofence")
public class GeofenceEventServiceImpl implements ResolverEventService {
// @Autowired
// private FenceMapper fenceMapper;
@Override
public void execute(ResolverReportData resolverReportData) {
log.info("电子围挡执行");
String vin = resolverReportData.getVin();
log.info("vin :"+vin);
//经度
double pointLng = parseDouble(resolverReportData.getLongitude());
//维度
double pointLat = parseDouble(resolverReportData.getLatitude());
FenceVo fenceVo = new FenceVo();
// List<Fence> list=fenceMapper.fenceList(fenceVo);
//
// for (Fence fence : list) {
// if (fence.getVin().equals(vin)){
// String[] split = fence.getFenceMessage().split(";");
//
// boolean withinFence = isWithinFence(pointLat, pointLng, Arrays.asList(split));
//
// if(withinFence){
// log.info("在围栏内");
// }else {
// log.error("不在围栏内");
// }
// }
// }
log.info("电子围挡结束");
}
@Override
public String getEventName() {
return "geofence";
}
public boolean isWithinFence(double pointLat, double pointLng, List<String> split){
if(split.size()<4){
throw new IllegalArgumentException("不符合条件");
}
double[] longitudes = new double[4];
double[] latitudes = new double[4];
for (int i = 0; i < 4; i++) {
String[] coordinates = split.get(i).split(",");
latitudes[i] = parseDouble(coordinates[0]);
longitudes[i] = parseDouble(coordinates[1]);
}
return isPointInRectangle(pointLat,pointLat,latitudes,longitudes);
}
private boolean isPointInRectangle(double pointLat, double pointLng, double[] latitudes, double[] longitudes) {
// 根据矩形顶点顺序确定最小和最大纬度、经度
double minLatitude = Arrays.stream(latitudes).min().orElseThrow();
double maxLatitude = Arrays.stream(latitudes).max().orElseThrow();
double minLongitude = Arrays.stream(longitudes).min().orElseThrow();
double maxLongitude = Arrays.stream(longitudes).max().orElseThrow();
return pointLat >= minLatitude && pointLat <= maxLatitude &&
pointLng >= minLongitude && pointLng <= maxLongitude;
}
}

View File

@ -1,5 +1,8 @@
package com.zhilian.resolver.service.impl.eventMalfunction;
import com.alibaba.fastjson.JSON;
import com.zhilian.common.redis.service.RedisService;
import com.zhilian.common.resolver.domain.ErrorCar;
import com.zhilian.common.resolver.domain.ResolverReportData;
import com.zhilian.common.resolver.domain.SysUserEnhancedServices;
import com.zhilian.resolver.mapper.UserMapper;
@ -9,6 +12,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.concurrent.TimeUnit;
/**
* @ClassName MalfunctionEventServiceImpl
* @Description
@ -18,6 +23,8 @@ import org.springframework.stereotype.Service;
@Slf4j
@Service("malfunction")
public class MalfunctionEventServiceImpl implements ResolverEventService {
@Autowired
private RedisService redisService;
/**
*
@ -34,15 +41,107 @@ public class MalfunctionEventServiceImpl implements ResolverEventService {
@Override
public void execute(ResolverReportData vehicleData) {
log.info("故障事件开始执行");
//模拟故障 获取用户信息
for (SysUserEnhancedServices userEnhancedService : userMapper.getUserEnhancedServices()) {
if(userEnhancedService.getEnhancedServicesId()==3 && userEnhancedService.getUseId()==102){
if(isAnyFieldZero(vehicleData)){
resolverReportInfoService.saveDataToDatabaseByMalfunction(vehicleData);
ErrorCar errorCar = new ErrorCar();
errorCar.setVin(vehicleData.getVin());
// * 车辆状态 1正常 0故障
if(vehicleData.getVehicleStatus()==0){
errorCar.setCode("GZ001");
errorCar.setLevel(1);
}
// * 充电状态 1正常 0故障
// private int chargingStatus;
if(vehicleData.getChargingStatus()==0){
errorCar.setCode("GZ001");
errorCar.setLevel(1);
}
// * 运行状态 1正常 0故障
if(vehicleData.getOperatingStatus()==0){
errorCar.setCode("GZ002");
errorCar.setLevel(3);
}
// * SOC 状态 1正常 0故障
if(vehicleData.getSocStatus()==0){
errorCar.setCode("GZ003");
errorCar.setLevel(3);
}
//
// /**
// * 可充电储能装置工作状态 1正常 0故障
// */
// private int chargingEnergyStorageStatus;
//
// /**
// * 驱动电机状态 1正常 0故障
// */
// private int driveMotorStatus;
//
// /**
// * 定位是否有效 1有效 0无效
// */
// private int positionStatus;
//
// /**
// * EAS(汽车防盗系统)状态 1正常 0故障
// */
// private int easStatus;
//
// /**
// * PTC(电动加热器)状态 1正常 0故障
// */
// private int ptcStatus;
//
// /**
// * EPS(电动助力系统)状态 1正常 0故障
// */
// private int epsStatus;
//
// /**
// * ABS(防抱死)状态 1正常 0故障
// */
// private int absStatus;
//
// /**
// * MCU(电机/逆变器)状态 1正常 0故障
// */
// private int mcuStatus;
//
// /**
// * 动力电池加热状态 1正常 0故障
// */
// private int heatingStatus;
//
// /**
// * 动力电池当前状态 1正常 0故障
// */
// private int batteryStatus;
//
// /**
// * 动力电池保温状态 1正常 0故障
// */
// private int batteryInsulationStatus;
//
// /**
// * DCDC(电力交换系统) 状态 1正常 0故障
// */
// private int dcdcStatus;
//
// /**
// * CHG(充电机)状态 1正常 0故障
// */
// private int chgStatus;
String key = "breakdown";
String value = JSON.toJSONString(errorCar);
redisService.setCacheObject(key,value);
long expireTime = 30;
redisService.expire(key, expireTime, TimeUnit.MINUTES);
}
@ -67,6 +166,7 @@ public class MalfunctionEventServiceImpl implements ResolverEventService {
resolverReportData.getBatteryInsulationStatus() == 0 ||
resolverReportData.getDcdcStatus() == 0 ||
resolverReportData.getChgStatus() == 0;
}
@Override
public String getEventName() {

View File

@ -25,16 +25,7 @@ public class StorageEventServiceImpl implements ResolverEventService {
@Override
public void execute(ResolverReportData vehicleData) {
log.info("开始存储");
//模拟 用户userid 100 事件1(存储事件)
for (SysUserEnhancedServices userEnhancedService : userMapper.getUserEnhancedServices()) {
//userId 事件编号 客户
//100 1 客户100-增值服务 存储事件
if(userEnhancedService.getEnhancedServicesId()==1 && userEnhancedService.getUseId()==100){
resolverReportInfoService.saveDataToDatabase(vehicleData);
}
}
log.info("结束存储");
}