Browse Source

视频AI感知事件存储

develop
xiepufeng 1 year ago
parent
commit
8439c24b0f
  1. 13
      zc-business/src/main/java/com/zc/business/constant/RedisKeyConstants.java
  2. 35
      zc-business/src/main/java/com/zc/business/enums/IotProductEnum.java
  3. 31
      zc-business/src/main/java/com/zc/business/enums/WarningSourceEnum.java
  4. 30
      zc-business/src/main/java/com/zc/business/enums/WarningStateEnum.java
  5. 75
      zc-business/src/main/java/com/zc/business/enums/WarningSubclassEnum.java
  6. 39
      zc-business/src/main/java/com/zc/business/enums/WarningTypeEnum.java
  7. 97
      zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java
  8. 69
      zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java

13
zc-business/src/main/java/com/zc/business/constant/RedisKeyConstants.java

@ -0,0 +1,13 @@
package com.zc.business.constant;
/**
* Redis key 常量定义
* @author xiepufeng
*/
public class RedisKeyConstants
{
/**
* 设备
*/
public static final String DC_DEVICES = "dc:devices";
}

35
zc-business/src/main/java/com/zc/business/enums/IotProductEnum.java

@ -0,0 +1,35 @@
package com.zc.business.enums;
/**
* 物联网产品类型
* @author xiepufeng
*/
public enum IotProductEnum {
// 摄像头检测事件
CAMERA_DETECTION_EVENT("video-event"),
// 情报板
VARIABLE_MESSAGE_SIGN("7877"),
// 行车诱导
TRAFFIC_GUIDANCE("8866"),
// 气象检测器
WEATHER_DETECTOR("zc-meteorological"),
// 设备箱
EQUIPMENT_BOX("zc-shebeixiang-1883"),
// 一站式情况调查产品
ONE_STOP_PRODUCT("zc-yzsqkdc-3131")
;
private final String value;
IotProductEnum(String value) {
this.value = value;
}
public String value() {
return this.value;
}
}

31
zc-business/src/main/java/com/zc/business/enums/WarningSourceEnum.java

@ -0,0 +1,31 @@
package com.zc.business.enums;
/**
* 预警事件信息来源
* @author xiepufeng
*/
public enum WarningSourceEnum {
VIDEO_AI(1, "视频AI"),
RADAR_RECOGNITION(2,"雷达识别"),
CONE_DETECTION(3,"锥桶感应"),
GUARDRAIL_COLLISION(4,"护栏碰撞"),
QR_CODE_ALERT(5,"扫码报警"),
NON_MOTOR_VEHICLE_WARNING(6,"非机动车预警");
private final Integer code;
private final String description;
WarningSourceEnum(Integer code, String description) {
this.code = code;
this.description = description;
}
public Integer getCode()
{
return code;
}
public String getDescription() {
return description;
}
}

30
zc-business/src/main/java/com/zc/business/enums/WarningStateEnum.java

@ -0,0 +1,30 @@
package com.zc.business.enums;
/**
* 警情状态
* @author xiepufeng
*/
public enum WarningStateEnum {
REPORTED(1, "上报"),
COMPLETED(2, "已完成"),
TERMINATED(3, "已终止"),
AUTO_ENDED(4, "自动结束");
private final Integer code;
private final String description;
public Integer getCode()
{
return code;
}
WarningStateEnum(Integer code, String description) {
this.code = code;
this.description = description;
}
public String getDescription() {
return description;
}
}

75
zc-business/src/main/java/com/zc/business/enums/WarningSubclassEnum.java

@ -0,0 +1,75 @@
package com.zc.business.enums;
import lombok.Getter;
import java.util.HashMap;
import java.util.Map;
/**
* 预警事件子类
* @author xiepufeng
*/
public enum WarningSubclassEnum {
TRAFFIC_JAM("1-1", "拥堵", "发生"),
SLOW_TRAFFIC("1-2", "缓行", "发生"),
REGULAR_PEDESTRIAN("2-1", "普通行人", "有行人:"),
STAFF_MEMBER("2-2", "工作人员", "有行人:"),
MOTORCYCLE("3-1", "摩托车", "非机动车:"),
BICYCLE("3-2", "自行车","非机动车:"),
THREE_WHEELER("3-3", "三轮车","非机动车:"),
NON_CONSTRUCTION_VEHICLE("4-1", "非工程车", "非法停车:"),
CONSTRUCTION_VEHICLE("4-2", "工程车", "非法停车:"),
MAIN_ROAD_OCCUPIED("4-3", "主路有车", "非法停车:"),
RAMP_OCCUPIED("4-4", "匝道有车", "非法停车:"),
VEHICLE_BREAKDOWN("4-5", "车辆故障", "发生"),
TRAFFIC_ACCIDENT("4-6", "交通事故", "发生"),
EMERGENCY_LANE_BLOCKED("4-7", "应急车道被占用", ""),
VEHICLE_EXIT_EMERGENCY_LANE("4-8", "车离开应急车道", ""),
OTHER_CONDITION("4-9", "其他", "非法停车:"),
REVERSING_OR_GOING_BACKWARDS("5-1", "倒车/逆行", "发现"),
FIREWORKS("6-1", "烟火", ""),
DEBRIS_ON_ROAD("7-1", "撒落物", "发现"),
RAIN("8-1", "雨", "异常天气:"),
HAIL("8-2", "冰雹", "异常天气:"),
WIND("8-3", "风", "异常天气:"),
FOG("8-4", "雾", "异常天气:"),
HIGH_TEMPERATURE("8-5", "高温", "异常天气:"),
WATER_POOLING("8-6", "积水", "异常天气:"),
SLIPPERY_ROAD_SURFACE("8-6", "路面湿滑", "异常天气:"),
ICY_ROAD("8-8", "路面结冰", "异常天气:"),
LOW_VISIBILITY("8-9", "道路能见度低", "异常天气:"),
ROAD_FOG("8-10", "道路团雾", "异常天气:"),
COLLISION_ONLY("9-1", "只碰撞不倾斜", "护栏碰撞:"),
TILTED_WITHOUT_COLLISION("9-1", "只倾斜无碰撞", "护栏碰撞:"),
COLLISION_AND_TILTED("9-3", "碰撞后倾斜", "护栏碰撞:");
@Getter
private final String code;
@Getter
private final String info;
private final String decorate;
private static final Map<String, WarningSubclassEnum> ENUM_BY_CODE = new HashMap<>();
static {
for (WarningSubclassEnum value : values()) {
ENUM_BY_CODE.put(value.getCode(), value);
}
}
WarningSubclassEnum(String code, String info, String decorate)
{
this.code = code;
this.info = info;
this.decorate = decorate;
}
public String getDecorateInfo() {
return decorate + decorate;
}
public static String getDecorateInfo(String code) {
return ENUM_BY_CODE.get(code).getDecorateInfo();
}
}

39
zc-business/src/main/java/com/zc/business/enums/WarningTypeEnum.java

@ -0,0 +1,39 @@
package com.zc.business.enums;
/**
* 感知事件类型主类
* @author xiepufeng
*/
public enum WarningTypeEnum {
TRAFFIC_JAM(1, "交通拥堵"),
PEDESTRIAN(2, "行人"),
NON_MOTOR_VEHICLE(3, "非机动车"),
PARK(4, "停车"),
VEHICLE_CONVERSE_RUNNING(5, "倒车/逆行"),
FIREWORKS(6, "烟火"),
OUTFALL(7, "撒落物"),
UNUSUAL_WEATHER(8, "异常天气"),
BARRIER_CRASH(9, "护栏碰撞"),
TRAFFIC_ACCIDENT(10, "交通事故"),
VEHICLE_FAULT(11, "车辆故障"),
OTHER(99, "其他");
private final Integer code;
private final String info;
WarningTypeEnum(Integer code, String info)
{
this.code = code;
this.info = info;
}
public Integer getCode()
{
return code;
}
public String getInfo()
{
return info;
}
}

97
zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java

@ -2,52 +2,42 @@ package com.zc.business.message.device.handler;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.redis.RedisCache;
import com.zc.business.constant.RedisKeyConstants;
import com.zc.business.domain.DcDevice; import com.zc.business.domain.DcDevice;
import com.zc.business.domain.DcWarning;
import com.zc.business.enums.IotProductEnum;
import com.zc.business.enums.WarningSourceEnum;
import com.zc.business.enums.WarningStateEnum;
import com.zc.business.enums.WarningSubclassEnum;
import com.zc.business.service.IDcDeviceService; import com.zc.business.service.IDcDeviceService;
import com.zc.business.service.IDcWarningService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* 设备消息处理 * 设备消息处理
* @author xiepufeng
*/ */
@Service @Service
public class DeviceMessageHandler { public class DeviceMessageHandler {
enum ProductType { private final Logger logger = LoggerFactory.getLogger(this.getClass());
// 摄像头检测事件
CAMERA_DETECTION_EVENT("video-event"),
// 情报板
VARIABLE_MESSAGE_SIGN("7877"),
// 行车诱导
TRAFFIC_GUIDANCE("8866"),
// 气象检测器
WEATHER_DETECTOR("zc-meteorological"),
// 设备箱
EQUIPMENT_BOX("zc-shebeixiang-1883"),
// 一站式情况调查产品
ONE_STOP_PRODUCT("zc-yzsqkdc-3131")
; @Resource
private final String value; private IDcDeviceService dcDeviceService;
ProductType(String value) {
this.value = value;
}
public String value() { @Resource
return this.value; private IDcWarningService dcWarningService;
}
}
@Resource @Resource
private IDcDeviceService dcDeviceService; private RedisCache redisCache;
/** /**
* 更新设备状态 * 更新设备状态
@ -76,11 +66,18 @@ public class DeviceMessageHandler {
public void handle(String msg) { public void handle(String msg) {
JSONObject data = JSON.parseObject(msg, JSONObject.class); JSONObject data = JSON.parseObject(msg, JSONObject.class);
JSONObject headers = data.getJSONObject("headers");
if (headers == null) {
logger.error("物联网消息解析处理,消息中缺少headers数据");
return;
}
// 产品id // 产品id
String productId = data.getJSONObject("headers").getString("productId"); String productId = headers.getString("productId");
// 摄像头检测事件 // 摄像头检测事件
if (productId.equals(ProductType.CAMERA_DETECTION_EVENT.value)) { if (IotProductEnum.CAMERA_DETECTION_EVENT.value().equals(productId)) {
this.cameraDetectionEventHandle(data); this.cameraDetectionEventHandle(data);
} }
} }
@ -92,7 +89,47 @@ public class DeviceMessageHandler {
*/ */
private void cameraDetectionEventHandle(JSONObject event) { private void cameraDetectionEventHandle(JSONObject event) {
JSONObject data = event.getJSONObject("data");
DcWarning dcWarning = new DcWarning();
// 桩号
dcWarning.setStakeMark(data.getString("stakeMark"));
// 方向
dcWarning.setDirection(data.getString("direction"));
// 警情状态
dcWarning.setWarningState(WarningStateEnum.REPORTED.getCode());
// 捕获时间
Long captureTime = data.getLong("captureTime");
// 预警时间
dcWarning.setWarningTime(new Date(captureTime));
// 信息来源
dcWarning.setWarningSource(WarningSourceEnum.VIDEO_AI.getCode());
// 事件主类型
dcWarning.setWarningType(data.getInteger("warningType"));
String warningSubclass = data.getString("warningSubclass");
// 子类型
dcWarning.setWarningSubclass(warningSubclass);
String stakeMarkDescription = data.getString("stakeMarkDescription");
// 标题
dcWarning.setWarningTitle(stakeMarkDescription + WarningSubclassEnum.getDecorateInfo(warningSubclass));
// 影响车道
dcWarning.setLane(String.valueOf(data.getInteger("relatedLaneNo")));
// 物联设备id
String iotDeviceId = event.getString("deviceId");
DcDevice dcDevice = redisCache.getCacheMapValue(RedisKeyConstants.DC_DEVICES, iotDeviceId);
if (dcDevice != null) {
// 所属机构
dcWarning.setDeptId(dcDevice.getGroupId());
} }
dcWarningService.insertDcWarning(dcWarning);
}
} }

69
zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java

@ -3,8 +3,10 @@ package com.zc.business.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.constant.HttpStatus; import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.PageUtils; import com.ruoyi.common.utils.PageUtils;
import com.zc.business.constant.RedisKeyConstants;
import com.zc.business.domain.DcDevice; import com.zc.business.domain.DcDevice;
import com.zc.business.domain.DcProduct; import com.zc.business.domain.DcProduct;
import com.zc.business.domain.DcStakeMark; import com.zc.business.domain.DcStakeMark;
@ -15,6 +17,7 @@ import com.zc.business.service.IDcStakeMarkService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -35,6 +38,42 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i
@Resource @Resource
private DcDeviceMapper dcDeviceMapper; private DcDeviceMapper dcDeviceMapper;
@Resource
private RedisCache redisCache;
@PostConstruct
public void init()
{
/*
添加数据到 redis 缓存
*/
updateRedisCache();
}
/**
* 添加数据到 redis 缓存
*/
public void updateRedisCache()
{
// 获取全部设备列表数据
List<DcDevice> dcDevices = list();
if (dcDevices == null || dcDevices.isEmpty())
{
return;
}
// 清楚 redis 缓存数据
redisCache.deleteObject(RedisKeyConstants.DC_DEVICES);
// 添加 redis 缓存数据
dcDevices.forEach(val -> {
String iotDeviceId = val.getIotDeviceId();
if (StringUtils.hasText(iotDeviceId)) {
redisCache.setCacheMapValue(RedisKeyConstants.DC_DEVICES, val.getIotDeviceId(), val);
}
});
}
public LambdaQueryWrapper<DcDevice> deviceQueryWrapper(DcDevice dcDevice) { public LambdaQueryWrapper<DcDevice> deviceQueryWrapper(DcDevice dcDevice) {
@ -175,7 +214,14 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i
dcDevice.setCreateTime(new Date()); dcDevice.setCreateTime(new Date());
dcDevice.setUseState(DcDevice.UNUSEDSTATE); dcDevice.setUseState(DcDevice.UNUSEDSTATE);
return save(dcDevice);
if (save(dcDevice)) {
// 更新缓存
updateRedisCache();
return true;
}
return false;
} }
/** /**
@ -197,7 +243,14 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i
} }
dcDevice.setUpdateTime(new Date()); dcDevice.setUpdateTime(new Date());
return updateById(dcDevice);
if (updateById(dcDevice)) {
// 更新缓存
updateRedisCache();
return true;
}
return false;
} }
/** /**
@ -217,7 +270,14 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i
throw new ServiceException("设备正在使用", HttpStatus.MOVED_PERM); throw new ServiceException("设备正在使用", HttpStatus.MOVED_PERM);
} }
}); });
return removeByIds(ids);
if (removeByIds(ids)) {
// 更新缓存
updateRedisCache();
return true;
}
return false;
} }
/** /**
@ -257,6 +317,9 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i
queryWrapper.eq(DcDevice::getIotDeviceId,device.getIotDeviceId()); queryWrapper.eq(DcDevice::getIotDeviceId,device.getIotDeviceId());
update(device,queryWrapper); update(device,queryWrapper);
} }
// 更新缓存
updateRedisCache();
return true; return true;
} }

Loading…
Cancel
Save