|
@@ -2,28 +2,109 @@ package org.dromara.web.task;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.lang.UUID;
|
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
+import cn.hutool.json.JSON;
|
|
|
import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
|
|
import org.dromara.common.core.service.OssService;
|
|
|
import org.dromara.common.core.utils.SpringUtils;
|
|
|
+import org.dromara.system.domain.bo.TblDeviceBo;
|
|
|
import org.dromara.system.domain.bo.TblEventBo;
|
|
|
import org.dromara.system.domain.vo.SysOssUploadVo;
|
|
|
import org.dromara.system.domain.vo.SysOssVo;
|
|
|
+import org.dromara.system.domain.vo.TblDeviceVo;
|
|
|
+import org.dromara.system.domain.vo.TblEventVo;
|
|
|
+import org.dromara.system.service.ISysConfigService;
|
|
|
import org.dromara.system.service.ISysOssService;
|
|
|
+import org.dromara.system.service.ITblDeviceService;
|
|
|
import org.dromara.system.service.ITblEventService;
|
|
|
+import org.dromara.system.utils.Utils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
+@Component
|
|
|
public class KafkaMessageConsumer {
|
|
|
+ private static final Logger log = org.slf4j.LoggerFactory.getLogger(KafkaMessageConsumer.class);
|
|
|
+ private Map<String, Long> eventMap = new java.util.HashMap<>();
|
|
|
+ private Map<String, Long> eventSaveMap = new java.util.HashMap<>();
|
|
|
+
|
|
|
+ private String finalEventTime = "200";
|
|
|
+ private String finalEventChangeTime = "400";
|
|
|
+
|
|
|
+
|
|
|
+ @Scheduled(cron = "*/1 * * * * *")
|
|
|
+ public void doChange() {
|
|
|
+ System.out.println("事件判断");
|
|
|
+ try{
|
|
|
+ eventMap.forEach((key, value) -> {
|
|
|
+ if(DateUtil.current()-value>Integer.parseInt(finalEventChangeTime)){
|
|
|
+ //改变状态
|
|
|
+ ThreadUtil.execAsync(() -> {
|
|
|
+ //先查找状态
|
|
|
+ TblEventVo tblEventVo = SpringUtils.getBean(ITblEventService.class).queryById(eventSaveMap.get(key));
|
|
|
+ if(tblEventVo != null && tblEventVo.getStatus().equals("2")){
|
|
|
+ TblEventBo tblEventBo = new TblEventBo();
|
|
|
+ tblEventBo.setId(eventSaveMap.get(key));
|
|
|
+ tblEventBo.setStatus("4");
|
|
|
+ SpringUtils.getBean(ITblEventService.class).updateByBo(tblEventBo);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
public void consumerMessage(List<ConsumerRecord<String, Object>> message) {
|
|
|
System.out.println("收到消息:" + message);
|
|
|
+
|
|
|
+ String eventTime = SpringUtils.getBean(ISysConfigService.class).selectConfigByKey("event_time");
|
|
|
+ if(StrUtil.isEmptyIfStr(eventTime)){
|
|
|
+ eventTime = "200";
|
|
|
+ }
|
|
|
+ finalEventTime = eventTime;
|
|
|
+ String eventChangeTime = SpringUtils.getBean(ISysConfigService.class).selectConfigByKey("event_change_time");
|
|
|
+ if(StrUtil.isEmptyIfStr(eventChangeTime)){
|
|
|
+ eventChangeTime = "400";
|
|
|
+ }
|
|
|
+ finalEventChangeTime = eventChangeTime;
|
|
|
+
|
|
|
+ //查询摄像头
|
|
|
+ List<TblDeviceVo> listdev = SpringUtils.getBean(ITblDeviceService.class).queryList(new TblDeviceBo());
|
|
|
+ Map<String, TblDeviceVo> map = new java.util.HashMap<>();
|
|
|
+ listdev.forEach(item ->{
|
|
|
+ if(item.getExt1()!=null){
|
|
|
+ try{
|
|
|
+ JSONObject ysObject = JSONUtil.parseObj(item.getExt1());
|
|
|
+ if(ysObject.get("name")!=null){
|
|
|
+ map.put(ysObject.getStr("name"), item);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
message.forEach(consumerRecord ->{
|
|
|
|
|
|
if(consumerRecord.topic().equals("zs_events_r2p3")){
|
|
@@ -36,6 +117,14 @@ public class KafkaMessageConsumer {
|
|
|
JSONArray envlist = item.getJSONArray("Evt_List");
|
|
|
for (int j = 0; j < envlist.size(); j++) {
|
|
|
JSONObject envitem = envlist.getJSONObject(j);
|
|
|
+ String key = envitem.getInt("EvtType")+msg.getStr("DevNo")+"源驶科技";
|
|
|
+ if(eventMap.get(key)!=null){
|
|
|
+ if(DateUtil.current()-eventMap.get(key)<Integer.parseInt(finalEventTime)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ eventMap.put(key,DateUtil.current());
|
|
|
+
|
|
|
envitem.set("from","源驶科技");
|
|
|
envitem.set("lx", getEventName(envitem.getInt("EvtType")));
|
|
|
TblEventBo tblEventBo = new TblEventBo();
|
|
@@ -70,7 +159,15 @@ public class KafkaMessageConsumer {
|
|
|
}
|
|
|
tblEventBo.setExt1(JSONUtil.toJsonStr(urls));
|
|
|
tblEventBo.setAddr(msg.getStr("DevNo"));
|
|
|
+ //根据DevNo 查询设备名称
|
|
|
+ TblDeviceVo deviceVo = map.get(msg.getStr("DevNo"));
|
|
|
+ if(deviceVo!=null){
|
|
|
+ tblEventBo.setAddr(deviceVo.getName());
|
|
|
+ envitem.set("deviceVo", deviceVo);
|
|
|
+ tblEventBo.setExt2(JSONUtil.toJsonStr(envitem));
|
|
|
+ }
|
|
|
SpringUtils.getBean(ITblEventService.class).insertByBo(tblEventBo);
|
|
|
+ eventSaveMap.put(key,tblEventBo.getId());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -92,9 +189,24 @@ public class KafkaMessageConsumer {
|
|
|
FileUtil.mkdir("./temp/");
|
|
|
}
|
|
|
File file = HttpUtil.downloadFileFromUrl(path, FileUtil.file("./temp/"));
|
|
|
+ try{
|
|
|
+ String pathfile = "./"+ UUID.fastUUID()+".mp4";
|
|
|
+ Utils.exchangeToMp4("/Users/wenhongquan/miniforge3/bin/ffmpeg",file.toPath().toString(),pathfile);
|
|
|
+ FileUtil.del(file);
|
|
|
+ file = new File(pathfile);;
|
|
|
+ }catch (Exception e){
|
|
|
+
|
|
|
+ }
|
|
|
SysOssVo oss = SpringUtils.getBean(ISysOssService.class).upload(file);
|
|
|
+ FileUtil.del(file);
|
|
|
return oss.getFileName();
|
|
|
}
|
|
|
+// public static void main(String[] args) {
|
|
|
+// KafkaMessageConsumer kafkaMessageConsumer = new KafkaMessageConsumer();
|
|
|
+// kafkaMessageConsumer.downloadImage("http://jtjai.xt.wenhq.top:8083/api/oss/local/upload/image/2025/06/13/1.mp4");
|
|
|
+// }
|
|
|
+//
|
|
|
+
|
|
|
|
|
|
|
|
|
|