Merge remote-tracking branch 'refs/remotes/origin/dev.template' into dev
commit
0aa33b36a0
|
@ -13,6 +13,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
@EnableMyFeignClients
|
@EnableMyFeignClients
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class CloudTemplateApplication {
|
public class CloudTemplateApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(CloudTemplateApplication.class, args);
|
SpringApplication.run(CloudTemplateApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
package com.muyu.template.controller;
|
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author liuxinyue
|
|
||||||
* @Package:com.muyu.template.controller
|
|
||||||
* @name:TemplateController
|
|
||||||
* @Date:2024/10/7 10:28
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/template")
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Tag(name = "协议解析管理",description = "协议解析管理")
|
|
||||||
@Log4j2
|
|
||||||
public class TemplateController {
|
|
||||||
}
|
|
|
@ -1,11 +1,27 @@
|
||||||
package com.muyu.template;
|
package com.muyu.template;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
|
import com.muyu.cache.MessageTemplateTypeCacheService;
|
||||||
|
import com.muyu.cache.SysCarCacheService;
|
||||||
|
import com.muyu.cache.WarnRuleCacheService;
|
||||||
|
import com.muyu.cache.WarnStrategyCacheService;
|
||||||
|
import com.muyu.common.domain.MessageTemplateType;
|
||||||
|
import com.muyu.common.domain.SysCar;
|
||||||
|
import com.muyu.common.domain.resp.SysCarVo;
|
||||||
|
import com.muyu.common.domain.resp.WarnRuleResp;
|
||||||
|
import com.muyu.common.domain.resp.WarnStrategyResp;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
/**
|
/**
|
||||||
* @author liuxinyue
|
* @author liuxinyue
|
||||||
* @Package:com.muyu.template
|
* @Package:com.muyu.template
|
||||||
|
@ -14,14 +30,82 @@ import java.util.concurrent.TimeUnit;
|
||||||
*/
|
*/
|
||||||
@Log4j2
|
@Log4j2
|
||||||
public class test {
|
public class test {
|
||||||
|
|
||||||
private static int DURATION_SECONDS = 5;
|
private static int DURATION_SECONDS = 5;
|
||||||
private static List<JSONObject> receivedStrings = new ArrayList<>();
|
private static List<JSONObject> receivedStrings = new ArrayList<>();
|
||||||
private static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
private static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||||
private static int elapsedSeconds = 0;
|
private static int elapsedSeconds = 0;
|
||||||
private static String file="elapsed";
|
private static String file="elapsed";
|
||||||
|
//预警策略
|
||||||
public static void main(String[] args) {
|
@Resource
|
||||||
|
private WarnStrategyCacheService warnStrategyCacheService;
|
||||||
|
//车辆
|
||||||
|
@Resource
|
||||||
|
private SysCarCacheService sysCarCacheService;
|
||||||
|
//预警规则
|
||||||
|
@Resource
|
||||||
|
private WarnRuleCacheService warnRuleCacheService;
|
||||||
|
//报文模版
|
||||||
|
@Resource
|
||||||
|
private MessageTemplateTypeCacheService messageTemplateTypeCacheService;
|
||||||
|
public void main(String[] args) {
|
||||||
|
//协议解析:每秒穿过来一个JSONObject jsonObject; 添加进receivedStrings
|
||||||
|
//根据这个车辆VIN查询出他对应的车辆类型
|
||||||
|
String carVin=null;
|
||||||
|
//报文模版的ID
|
||||||
|
Integer templateId=null;
|
||||||
|
for (JSONObject receivedString : receivedStrings) {
|
||||||
|
carVin = receivedString.getStr("carVin");
|
||||||
|
}
|
||||||
|
SysCar carByVin = null;
|
||||||
|
List<SysCarVo> carVoList = sysCarCacheService.get(sysCarCacheService.keyPre());
|
||||||
|
Map<String, SysCarVo> carMap = carVoList.stream()
|
||||||
|
.collect(Collectors.toMap(SysCarVo::getCarVin, Function.identity()));
|
||||||
|
//获取到了这个车辆的信息
|
||||||
|
carByVin = carMap.get(carVin);
|
||||||
|
//获取到这辆车绑定的报文模版
|
||||||
|
templateId=carByVin.getTemplateId();
|
||||||
|
//这个是这辆车对应的所有策略
|
||||||
|
List<WarnStrategyResp> carWithWarnStrategyList=null;
|
||||||
|
List<WarnStrategyResp> warnStrategyResps = warnStrategyCacheService.get(warnStrategyCacheService.keyPre());
|
||||||
|
for (WarnStrategyResp warnStrategyResp : warnStrategyResps) {
|
||||||
|
if(warnStrategyResp.getCarTypeId()==carByVin.getCarTypeId()){
|
||||||
|
carWithWarnStrategyList.add(warnStrategyResp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//该车对应的所有预警规则
|
||||||
|
List<WarnRuleResp> warnRuleResp=null;
|
||||||
|
List<WarnRuleResp> warnRuleResps = warnRuleCacheService.get(warnRuleCacheService.keyPre());
|
||||||
|
for (WarnStrategyResp warnStrategyResp : carWithWarnStrategyList) {
|
||||||
|
for (WarnRuleResp ruleResp : warnRuleResps) {
|
||||||
|
if(warnStrategyResp.getId().equals(ruleResp.getStrategyId())){
|
||||||
|
warnRuleResp.add(ruleResp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//报文模版
|
||||||
|
List<MessageTemplateType> messageTemplateTypes = messageTemplateTypeCacheService.get(messageTemplateTypeCacheService.keyPre());
|
||||||
|
Long msgTypeId=null;
|
||||||
|
//滑窗时间
|
||||||
|
Long slideTime=null;
|
||||||
|
//增长率
|
||||||
|
Long slideFrequency=null;
|
||||||
|
for (WarnRuleResp ruleResp : warnRuleResp) {
|
||||||
|
//每一个规则他绑定了报文模版里面对应的一个配置 比如:电池,或者车速
|
||||||
|
msgTypeId = ruleResp.getMsgTypeId();
|
||||||
|
slideTime = ruleResp.getSlideTime();
|
||||||
|
slideFrequency = ruleResp.getSlideFrequency();
|
||||||
|
}
|
||||||
|
for (JSONObject receivedString : receivedStrings) {
|
||||||
|
for (MessageTemplateType messageTemplateType : messageTemplateTypes) {
|
||||||
|
if(messageTemplateType.getMessageTemplateTypeId().equals(msgTypeId)){
|
||||||
|
//例如: 车速 {"车速":127}
|
||||||
|
Long str = Long.valueOf(receivedString.getStr(messageTemplateType.getMessageField()));
|
||||||
|
if(str+slideFrequency>slideFrequency){
|
||||||
|
log.info("出错啦,出错啦,您的"+messageTemplateType.getMessageField()+"不正常,请检查!!!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// 定义一个任务,每秒执行一次
|
// 定义一个任务,每秒执行一次
|
||||||
Runnable task = new Runnable() {
|
Runnable task = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -39,6 +123,7 @@ public class test {
|
||||||
scheduler.scheduleAtFixedRate(task, 0, 1, TimeUnit.SECONDS);
|
scheduler.scheduleAtFixedRate(task, 0, 1, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 模拟从某个源获取字符串的方法
|
// 模拟从某个源获取字符串的方法
|
||||||
private static JSONObject getStringFromSource() {
|
private static JSONObject getStringFromSource() {
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
@ -47,7 +132,6 @@ public class test {
|
||||||
jsonObject.put("elapsed", elapsedSeconds);
|
jsonObject.put("elapsed", elapsedSeconds);
|
||||||
return jsonObject;
|
return jsonObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清理超过60秒的数据
|
// 清理超过60秒的数据
|
||||||
private static void cleanUpOldStrings() {
|
private static void cleanUpOldStrings() {
|
||||||
long currentTime = System.currentTimeMillis();
|
long currentTime = System.currentTimeMillis();
|
||||||
|
@ -55,16 +139,13 @@ public class test {
|
||||||
currentTime - jsonObject.getLong("time") > TimeUnit.SECONDS.toMillis(DURATION_SECONDS)
|
currentTime - jsonObject.getLong("time") > TimeUnit.SECONDS.toMillis(DURATION_SECONDS)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否有超速情况
|
// 检查是否有超速情况
|
||||||
private static void checkForSpeeding() {
|
private static void checkForSpeeding() {
|
||||||
if (receivedStrings.size() < 2) return; // 如果数据不足,直接返回
|
if (receivedStrings.size() < 2) return; // 如果数据不足,直接返回
|
||||||
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
jsonObject.put("message", "Hello World");
|
jsonObject.put("message", "Hello World");
|
||||||
jsonObject.put("time", System.currentTimeMillis());
|
jsonObject.put("time", System.currentTimeMillis());
|
||||||
jsonObject.put("elapsed", 100);
|
jsonObject.put("elapsed", 100);
|
||||||
|
|
||||||
for (int i = 0; i < receivedStrings.size() - 1; i++) {
|
for (int i = 0; i < receivedStrings.size() - 1; i++) {
|
||||||
JSONObject current = receivedStrings.get(i);
|
JSONObject current = receivedStrings.get(i);
|
||||||
JSONObject next = receivedStrings.get(i + 1);
|
JSONObject next = receivedStrings.get(i + 1);
|
||||||
|
@ -78,6 +159,4 @@ public class test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class MessageTemplateType implements Serializable {
|
||||||
* 主键
|
* 主键
|
||||||
*/
|
*/
|
||||||
@TableId(value = "message_template_type_id",type = IdType.AUTO)
|
@TableId(value = "message_template_type_id",type = IdType.AUTO)
|
||||||
private String messageTemplateTypeId;
|
private Long messageTemplateTypeId;
|
||||||
/**
|
/**
|
||||||
* 报文类别
|
* 报文类别
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue