fast()指标预警,滑窗结果
parent
8f305f5ddc
commit
0a2bdc1adc
|
@ -26,6 +26,10 @@ public class DataSpecificationDev {
|
|||
* 标签
|
||||
*/
|
||||
private String label;
|
||||
/**
|
||||
* 浮动数据
|
||||
*/
|
||||
private String floating;
|
||||
/**
|
||||
* 标准数据
|
||||
*/
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
// String speed = ConversionUtil.hexStringToString(splicing(part,52,58));
|
||||
// //下标58-68是总里程
|
||||
// String totalMileage = ConversionUtil.hexStringToString(splicing(part,58,69));
|
||||
// //下标69-75是总电压
|
||||
// //下标69-74是总电压
|
||||
// String totalVoltage = ConversionUtil.hexStringToString(splicing(part,69,75));
|
||||
// //下标75-79是总电流
|
||||
// String totalCurrent = ConversionUtil.hexStringToString(splicing(part,75,80));
|
||||
|
|
|
@ -26,6 +26,10 @@ public class DataSpecification {
|
|||
* 标签
|
||||
*/
|
||||
private String label;
|
||||
/**
|
||||
* 浮动数据
|
||||
*/
|
||||
private String floating;
|
||||
/**
|
||||
* 标准数据
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package com.business.common.domain.event;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 预警信息
|
||||
* @ClassName WarningInfo
|
||||
* @Author GuanTieLin
|
||||
* @Date 2024/6/28 18:34
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class WarningInfo {
|
||||
|
||||
/**
|
||||
* 车架号
|
||||
*/
|
||||
private String vin;
|
||||
|
||||
/**
|
||||
* 预警字段
|
||||
*/
|
||||
private String field;
|
||||
|
||||
/**
|
||||
* 异常类型
|
||||
*/
|
||||
private String abnormalType;
|
||||
|
||||
/**
|
||||
* 发送时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
|
||||
private Date time;
|
||||
}
|
|
@ -23,7 +23,7 @@ public class Window {
|
|||
/**
|
||||
* 指向目标
|
||||
*/
|
||||
private String point;
|
||||
private String dateaCode;
|
||||
/**
|
||||
* 标准值
|
||||
*/
|
||||
|
@ -31,11 +31,11 @@ public class Window {
|
|||
/**
|
||||
* 启动时间
|
||||
*/
|
||||
private Date windowStartTime;
|
||||
private Date startTime;
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
private Date windowEndTime;
|
||||
private Date endTime;
|
||||
/**
|
||||
* 结果
|
||||
*/
|
||||
|
|
|
@ -12,6 +12,7 @@ import com.muyu.common.security.utils.SecurityUtils;
|
|||
import com.muyu.common.system.domain.LoginUser;
|
||||
import com.muyu.goods.Domain.WindowDonain;
|
||||
import com.muyu.goods.event.consumer.WindowListener;
|
||||
import com.muyu.goods.incident.mq.Producer;
|
||||
import com.muyu.goods.service.IForewarnService;
|
||||
import org.apache.kafka.common.protocol.types.Field;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -148,4 +149,33 @@ public class ForewarnController extends BaseController {
|
|||
return success(forewarnService.selectDateType());
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录指标预警
|
||||
* @param warningInfo
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("indexWarningInfo")
|
||||
public Result<Integer> indexWarningInfo(@RequestBody WarningInfo warningInfo) {
|
||||
return success(forewarnService.indexWarningInfo(warningInfo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 全部预警消息
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("listWarningInfo")
|
||||
public Result<List<WarningInfo>> listWarningInfo() {
|
||||
return success(forewarnService.listWarningInfo());
|
||||
}
|
||||
|
||||
/**
|
||||
* 车辆预警消息
|
||||
* @param vin
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("listWarningInfoById/{vin}")
|
||||
public Result<List<WarningInfo>> listWarningInfoById(@PathVariable String vin) {
|
||||
return success(forewarnService.listWarningInfoById(vin));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,4 +29,13 @@ public class Producer {
|
|||
public void redis_cache(String vin) {
|
||||
rabbitTemplate.convertAndSend("data_format_renewal",vin);
|
||||
}
|
||||
|
||||
public void data_specification_play(String name) {
|
||||
rabbitTemplate.convertAndSend("vehicle.event","window",name);
|
||||
}
|
||||
|
||||
public void data_and_mod(String name) {
|
||||
System.out.println(name);
|
||||
rabbitTemplate.convertAndSend("indicator_warning_message",name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,4 +35,11 @@ public interface ForewarnMapper {
|
|||
List<DateType> listDateType();
|
||||
|
||||
DataSpecification selectDataSpecificationById(@Param("id") Long id);
|
||||
|
||||
DataSpecification selectLostDataSpecification();
|
||||
|
||||
Integer indexWarningInfo(WarningInfo warningInfo);
|
||||
|
||||
List<WarningInfo> listWarningInfo();
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package com.muyu.goods.monitor.mq;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.business.common.domain.event.WarningInfo;
|
||||
import com.muyu.goods.controller.ForewarnController;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Component
|
||||
public class Consumer {
|
||||
@Autowired
|
||||
private ForewarnController forewarnController;
|
||||
|
||||
@RabbitListener(queuesToDeclare = {@Queue("indicator_warning_message")})
|
||||
public void hello(String message, Channel channel, Message messageProperties){
|
||||
System.out.println(message);
|
||||
//反序列化
|
||||
String string = JSON.parse(message).toString();
|
||||
WarningInfo warningInfo = JSONObject.parseObject(string, WarningInfo.class);
|
||||
Integer data = forewarnController.indexWarningInfo(warningInfo).getData();
|
||||
System.out.println(data);
|
||||
// 消费成功 手动确认
|
||||
try {
|
||||
channel.basicAck(messageProperties.getMessageProperties().getDeliveryTag(),false);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -93,4 +93,14 @@ public interface IForewarnService {
|
|||
|
||||
DataSpecification selectDataSpecificationById(Long id);
|
||||
|
||||
/**
|
||||
* 记录
|
||||
* @param warningInfo
|
||||
* @return
|
||||
*/
|
||||
Integer indexWarningInfo(WarningInfo warningInfo);
|
||||
|
||||
List<WarningInfo> listWarningInfo();
|
||||
|
||||
List<WarningInfo> listWarningInfoById(String vin);
|
||||
}
|
||||
|
|
|
@ -79,6 +79,49 @@ public class ForewarnService implements IForewarnService {
|
|||
*/
|
||||
@Override
|
||||
public Integer indexDataFormat(List<DataFormat> dataFormat, String vin) {
|
||||
int in = 1;
|
||||
for (DataFormat format : dataFormat) {
|
||||
if (format.getEnd() == null || format.getStart() == null){
|
||||
System.out.println("空值");
|
||||
in = 0;
|
||||
}
|
||||
for (DataFormat dataFormat1 : dataFormat) {
|
||||
//判断编码无冲突
|
||||
if (dataFormat1.getDataCode().equals(format.getDataCode())){
|
||||
if (!dataFormat1.equals(format)){
|
||||
System.out.println("编码冲突");
|
||||
in = 0;
|
||||
}
|
||||
|
||||
}
|
||||
//判断起始值无冲突
|
||||
if (dataFormat1.getStart() == format.getStart()){
|
||||
if (!dataFormat1.equals(format)){
|
||||
System.out.println("起始值冲突");
|
||||
in = 0;
|
||||
}
|
||||
|
||||
}
|
||||
//判断结束值无冲突
|
||||
if (dataFormat1.getEnd() == format.getEnd()){
|
||||
if (!dataFormat1.equals(format)){
|
||||
System.out.println("结束值冲突");
|
||||
in = 0;
|
||||
}
|
||||
}
|
||||
//判断起始值和结束值无冲突
|
||||
if (dataFormat1.getStart() == format.getEnd()){
|
||||
if (!dataFormat1.equals(format)){
|
||||
System.out.println("起始值与结束值冲突");
|
||||
in = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (in != 1) {
|
||||
return in;
|
||||
}
|
||||
deleteDataFormatById(vin);
|
||||
List<DataFormatDev> list = new ArrayList<>();
|
||||
for (DataFormat format : dataFormat) {
|
||||
|
@ -118,30 +161,37 @@ public class ForewarnService implements IForewarnService {
|
|||
List<DataSpecificationDev> dataSpecificationDevs = selectDataSpecificationDev(null);
|
||||
//进行分组
|
||||
Map<String, String> map = new HashMap<>();
|
||||
Map<String, Map<String,String>> mapMap = new HashMap<>();
|
||||
Map<String, String> map2 = new HashMap<>();
|
||||
Map<String, List<DataSpecificationDev>> collect = dataSpecificationDevs.stream().collect(Collectors.groupingBy(DataSpecificationDev::getVin));
|
||||
// 给每组数据改成字符串格式
|
||||
collect.forEach((a,b) -> {
|
||||
String name = "";
|
||||
String code = "";
|
||||
String dataCode = "";
|
||||
//编辑字符串
|
||||
for (DataSpecificationDev dataSpecificationDev : b) {
|
||||
name = "";
|
||||
dataCode = dataSpecificationDev.getDataCode();
|
||||
name += dataSpecificationDev.getDataCode() + "-" + dataSpecificationDev.getLabel() + "-"
|
||||
+ dataSpecificationDev.getRadius() + "-" + dataSpecificationDev.getLength() + "-" + dataSpecificationDev.getStandardData() + ",";
|
||||
+ dataSpecificationDev.getRadius() + "-" + dataSpecificationDev.getLength() + "-"
|
||||
+ dataSpecificationDev.getStandardData() + "-" + dataSpecificationDev.getFloating();
|
||||
code += dataSpecificationDev.getDataCode() + ",";
|
||||
map.put(dataCode,name);
|
||||
mapMap.put(a,map);
|
||||
}
|
||||
name = name.substring(0,name.length()-1);
|
||||
code = code.substring(0,code.length()-1);
|
||||
//存入map中
|
||||
map.put(a,name);
|
||||
map2.put(a,code);
|
||||
});
|
||||
//map数据导入redis
|
||||
map.forEach((key,val) -> {
|
||||
redisTemplate.opsForHash().put("event_handler:indicator_warning:execute_info:",key,val);
|
||||
mapMap.forEach((key,val) -> {
|
||||
val.forEach((ken,values) -> {
|
||||
redisTemplate.opsForHash().put("event_handler:indicator_warning:execute_info:"+key,ken,values);
|
||||
});
|
||||
});
|
||||
map2.forEach((key,val) -> {
|
||||
redisTemplate.opsForHash().put("event_handler:indicator_warning:warning_data:",key,val);
|
||||
redisTemplate.opsForHash().put("event_handler:indicator_warning:warning_data",key,val);
|
||||
});
|
||||
return dataSpecificationDevs.toString();
|
||||
}
|
||||
|
@ -164,6 +214,11 @@ public class ForewarnService implements IForewarnService {
|
|||
return forewarnMapper.listRadius();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看车辆滑窗
|
||||
* @param vin
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<DataSpecificationDev> selectDataSpecificationDev(String vin) {
|
||||
List<DataSpecificationDev> list = forewarnMapper.selectDataSpecificationDev();
|
||||
|
@ -186,6 +241,16 @@ public class ForewarnService implements IForewarnService {
|
|||
dataSpecification.setLabel(dateType1.getLabel());
|
||||
dataSpecification.setVin(vin);
|
||||
int i = forewarnMapper.indexDataSpecification(dataSpecification);
|
||||
if (i>0) {
|
||||
redisDataDormById();
|
||||
Boolean b = redisTemplate.opsForHash().hasKey("load_center:go_live", vin);
|
||||
if (b){
|
||||
DataSpecification dataSpecification1 = forewarnMapper.selectLostDataSpecification();
|
||||
String name = "window-"+ dataSpecification1.getVin()+"-"+dataSpecification1.getDataCode()+"-index";
|
||||
producer.data_specification_play(name);
|
||||
}
|
||||
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
|
@ -197,6 +262,16 @@ public class ForewarnService implements IForewarnService {
|
|||
@Override
|
||||
public Integer updataDataSpecification(DataSpecification dataSpecification) {
|
||||
int i = forewarnMapper.updataDataSpecification(dataSpecification);
|
||||
if (i>0) {
|
||||
DataSpecificationDev dataSpecificationDev1 = selectDataSpecificationDev(null).stream().filter(dataSpecificationDev -> dataSpecificationDev.getId() == dataSpecification.getId()).collect(Collectors.toList()).get(0);
|
||||
redisDataDormById();
|
||||
Boolean b = redisTemplate.opsForHash().hasKey("load_center:go_live", dataSpecificationDev1.getVin());
|
||||
if (b){
|
||||
|
||||
String name = "window-"+ dataSpecificationDev1.getVin()+"-"+dataSpecificationDev1.getDataCode()+"-update";
|
||||
producer.data_specification_play(name);
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
|
@ -207,7 +282,17 @@ public class ForewarnService implements IForewarnService {
|
|||
*/
|
||||
@Override
|
||||
public Integer deleteDataSpecification(Long id) {
|
||||
return forewarnMapper.deleteDataSpecification(id);
|
||||
DataSpecificationDev dataSpecificationDev1 = selectDataSpecificationDev(null).stream().filter(dataSpecificationDev -> dataSpecificationDev.getId() == id).collect(Collectors.toList()).get(0);
|
||||
int i = forewarnMapper.deleteDataSpecification(id);
|
||||
if (i>0) {
|
||||
redisTemplate.opsForHash().delete("event_handler:indicator_warning:execute_info:"+dataSpecificationDev1.getVin(),dataSpecificationDev1.getDataCode());
|
||||
Boolean b = redisTemplate.opsForHash().hasKey("load_center:go_live", dataSpecificationDev1.getVin());
|
||||
if (b){
|
||||
String name = "window-"+ dataSpecificationDev1.getVin()+"-"+dataSpecificationDev1.getDataCode()+"-delete";
|
||||
producer.data_specification_play(name);
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -238,5 +323,21 @@ public class ForewarnService implements IForewarnService {
|
|||
return forewarnMapper.selectDataSpecificationById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer indexWarningInfo(WarningInfo warningInfo) {
|
||||
return forewarnMapper.indexWarningInfo(warningInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WarningInfo> listWarningInfo() {
|
||||
return forewarnMapper.listWarningInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WarningInfo> listWarningInfoById(String vin) {
|
||||
List<WarningInfo> collect = listWarningInfo().stream().filter(warningInfo -> warningInfo.getVin().equals(vin)).collect(Collectors.toList());
|
||||
return collect;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<result property="vin" column="vin" />
|
||||
<result property="dataCode" column="data_code" />
|
||||
<result property="label" column="label" />
|
||||
<result property="floating" column="floating" />
|
||||
<result property="standardData" column="standard_data" />
|
||||
<result property="dateTypeId" column="date_type_id" />
|
||||
<result property="radiusId" column="radius_id" />
|
||||
|
@ -33,7 +34,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</resultMap>
|
||||
|
||||
<sql id="selectDataSpecificationVo">
|
||||
select d.id,d.vin,d.data_code,d.label,d.standard_data,d.date_type_id,d.radius_id,d.length_id,
|
||||
select d.id,d.vin,d.data_code,d.label,d.floating,d.standard_data,d.date_type_id,d.radius_id,d.length_id,
|
||||
r.radius_name, r.radius, l.length_name, l.length
|
||||
from data_specification d left join radius r on d.radius_id = r.radius_id
|
||||
left join length l on l.length_id = d.length_id
|
||||
|
@ -41,6 +42,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<sql id="selectDataFormat">
|
||||
select data_code, label, start,end from data_format
|
||||
</sql>
|
||||
<sql id="selectWarningInfoVo">
|
||||
select id, vin, field, abnormal_type, time from warning_info
|
||||
</sql>
|
||||
|
||||
<insert id="indexDataFormat" >
|
||||
insert into data_format
|
||||
values
|
||||
|
@ -54,6 +59,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="vin != null">vin,</if>
|
||||
<if test="dataCode != null">data_code,</if>
|
||||
<if test="label != null">label,</if>
|
||||
<if test="floating != null">floating,</if>
|
||||
<if test="standardData != null">standard_data,</if>
|
||||
<if test="dateTypeId != null">date_type_id,</if>
|
||||
<if test="radiusId != null">radius_id,</if>
|
||||
|
@ -63,17 +69,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="vin != null">#{vin},</if>
|
||||
<if test="dataCode != null">#{dataCode},</if>
|
||||
<if test="label != null">#{label},</if>
|
||||
<if test="floating != null">#{floating},</if>
|
||||
<if test="standardData != null">#{standardData},</if>
|
||||
<if test="dateTypeId != null">#{dateTypeId},</if>
|
||||
<if test="radiusId != null">#{radiusId},</if>
|
||||
<if test="lengthId != null">#{lengthId},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<insert id="indexWarningInfo">
|
||||
insert into warning_info (id,vin,field,abnormal_type,time)
|
||||
values (0,#{vin},#{field},#{abnormalType},#{time});
|
||||
</insert>
|
||||
<update id="updataDataSpecification">
|
||||
update data_specification
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="dataCode != null">data_code = #{dataCode},</if>
|
||||
<if test="label != null">label = #{label},</if>
|
||||
<if test="floating != null">floating = #{floating},</if>
|
||||
<if test="standardData != null">standard_data = #{standardData},</if>
|
||||
<if test="dateTypeId != null">date_type_id = #{dateTypeId},</if>
|
||||
<if test="radiusId != null">radius_id = #{radiusId},</if>
|
||||
|
@ -119,6 +131,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<select id="selectDataSpecificationById" resultType="com.business.common.domain.event.DataSpecification">
|
||||
select * from data_specification where id = #{id};
|
||||
</select>
|
||||
<select id="selectLostDataSpecification" resultType="com.business.common.domain.event.DataSpecification">
|
||||
select * from data_specification GROUP BY id desc limit 1
|
||||
</select>
|
||||
<select id="listWarningInfo" resultType="com.business.common.domain.event.WarningInfo">
|
||||
select *
|
||||
from warning_info
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue