From 4a9e4985e9e70f9ffee4e1658b58d7258fdc5ef0 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Tue, 12 Dec 2023 14:23:23 +0800 Subject: [PATCH] =?UTF-8?q?#AI=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/constant/VideoEnumConstants.java | 40 +++++++++++ .../hzims/operational/main/vo/VideoAlarmVO.java | 24 +++++++ .../scheduled/scheduled/MonitorScheduledTask.java | 7 +- .../operation/monitor/impl/MonitorServiceImpl.java | 2 +- .../main/controller/AiAlarmController.java | 38 ++++++++++ .../operational/main/service/AiAlarmService.java | 14 ++++ .../main/service/impl/AiAlarmServiceImpl.java | 82 ++++++++++++++++++++++ 7 files changed, 202 insertions(+), 5 deletions(-) create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/VideoEnumConstants.java create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/VideoAlarmVO.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AiAlarmController.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/AiAlarmService.java create mode 100644 hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AiAlarmServiceImpl.java diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/VideoEnumConstants.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/VideoEnumConstants.java new file mode 100644 index 0000000..9839c58 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/VideoEnumConstants.java @@ -0,0 +1,40 @@ +package com.hnac.hzims.operational.main.constant; + +import lombok.Getter; + +/** + * @author ysj + * @version 4.0.0 + * @create 2023-11-07-14:31 + */ +public interface VideoEnumConstants { + + @Getter + enum SoeKindEnum{ + /** + * 视频告警类型 + */ + MOTION_DETECTION("131331","移动侦测"), + REGIONAL_INTRUSION("131588","区域入侵"), + CROSS_BORDER_DETECTION("131585","越界侦测"), + SMOKE_FIRE_DETECTION("192514","烟火检测"), + OTHER_FLOATING_OBJECTS("42200047146001","其他漂浮物"), + PLANT_FLOATING_OBJECTS("42200047146000","植物类漂浮物"), + PLASTIC_FLOATING_OBJECTS("42200047146002","塑料类漂浮物"); + private final String instance; + private final String name; + SoeKindEnum(String instance,String name){ + this.instance = instance; + this.name = name; + } + public static String getValueByKey(String key) { + for (SoeKindEnum kind : SoeKindEnum.values()) { + if (kind.instance.equals(key)) { + return kind.getName(); + } + } + throw new IllegalArgumentException("Invalid key: " + key); + } + + } +} \ No newline at end of file diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/VideoAlarmVO.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/VideoAlarmVO.java new file mode 100644 index 0000000..a46f330 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/VideoAlarmVO.java @@ -0,0 +1,24 @@ +package com.hnac.hzims.operational.main.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + + +/** + * @author ysj + */ +@Data +public class VideoAlarmVO { + + @ApiModelProperty("设备编码") + private String deviceCode; + + @ApiModelProperty("设备名称") + private String deviceName; + + @ApiModelProperty("开始时间") + private String startTime; + + @ApiModelProperty("结束时间") + private String endTime; +} diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/MonitorScheduledTask.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/MonitorScheduledTask.java index daed33c..51131e3 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/MonitorScheduledTask.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/MonitorScheduledTask.java @@ -55,10 +55,9 @@ public class MonitorScheduledTask { * 集中监控数据处理 * @return ReturnT */ - //@XxlJob(CENTRALIZED_MONITORING) - @Scheduled(cron = "0/40 * * * * ? ") - public ReturnT loadMonitoring() { - String param = ""; + @XxlJob(CENTRALIZED_MONITORING) + //@Scheduled(cron = "0/40 * * * * ? ") + public ReturnT loadMonitoring(String param) { if (Func.isBlank(param)) { param = DateUtil.format(new Date(), "yyyy-MM"); } diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java index 700feef..e7e3558 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java @@ -451,7 +451,7 @@ public class MonitorServiceImpl implements MonitorService { return; } item.setStationName(station.getName()); - item.setWaterLevelMax(station.getLimitWaterLevel()); + item.setWaterLevelMax(Optional.ofNullable(station.getLimitWaterLevel()).orElse(0.0)); item.setServerType(station.getServeType()); item.setStationDeptId(station.getRefDept()); item.setSort(9999); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AiAlarmController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AiAlarmController.java new file mode 100644 index 0000000..acabaeb --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/controller/AiAlarmController.java @@ -0,0 +1,38 @@ +package com.hnac.hzims.operational.main.controller; + +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.operational.main.service.AiAlarmService; +import com.hnac.hzims.operational.main.vo.VideoAlarmVO; +import com.hnac.hzinfo.datasearch.soe.vo.DeviceSoeVO; +import com.hnac.hzinfo.sdk.core.response.HzPage; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import org.springblade.core.boot.ctrl.BladeController; +import org.springblade.core.log.annotation.ApiLog; +import org.springblade.core.mp.support.Condition; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author ysj + */ +@RestController +@RequestMapping("/ai") +@Api(value = "ai视频告警", tags = "ai视频告警") +@AllArgsConstructor +public class AiAlarmController extends BladeController { + + private final AiAlarmService aiAlarmService; + + @ApiLog + @GetMapping("/video/alarm_page") + @ApiOperationSupport(order = 15) + @ApiOperation(value = "视频告警数据查询接口", notes = "station") + public R> alarmPage(VideoAlarmVO videoAlarm, Query query) { + return R.data(aiAlarmService.alarmPage(videoAlarm, Condition.getPage(query))); + } +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/AiAlarmService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/AiAlarmService.java new file mode 100644 index 0000000..900338e --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/AiAlarmService.java @@ -0,0 +1,14 @@ +package com.hnac.hzims.operational.main.service; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.hnac.hzims.operational.main.vo.VideoAlarmVO; +import com.hnac.hzinfo.datasearch.soe.vo.DeviceSoeVO; +import com.hnac.hzinfo.sdk.core.response.HzPage; + +/** + * @author ysj + */ +public interface AiAlarmService { + + HzPage alarmPage(VideoAlarmVO videoAlarm, IPage page); +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AiAlarmServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AiAlarmServiceImpl.java new file mode 100644 index 0000000..6e48f38 --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AiAlarmServiceImpl.java @@ -0,0 +1,82 @@ +package com.hnac.hzims.operational.main.service.impl; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.hnac.hzims.operational.main.constant.VideoEnumConstants; +import com.hnac.hzims.operational.main.service.AiAlarmService; +import com.hnac.hzims.operational.main.vo.VideoAlarmVO; +import com.hnac.hzinfo.datasearch.soe.ISoeClient; +import com.hnac.hzinfo.datasearch.soe.vo.DeviceSoeVO; +import com.hnac.hzinfo.sdk.core.response.HzPage; +import com.hnac.hzinfo.sdk.core.response.Result; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.stereotype.Service; + +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author ysj + */ +@Slf4j +@RequiredArgsConstructor +@Service +public class AiAlarmServiceImpl implements AiAlarmService { + + private final ISoeClient alarmClient; + + /** + * 设备告警列表查询 + * @param videoAlarm + * @param page + * @return + */ + @Override + public HzPage alarmPage(VideoAlarmVO videoAlarm, IPage page) { + String startTime,endTime; + if(StringUtils.isEmpty(videoAlarm.getStartTime())){ + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.DAY_OF_MONTH,-calendar.get(Calendar.DAY_OF_MONTH)); + startTime = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; + }else{ + startTime = videoAlarm.getStartTime(); + } + if(StringUtils.isEmpty(videoAlarm.getEndTime())){ + endTime = DateUtil.format(new Date(),DateUtil.PATTERN_DATETIME); + }else{ + endTime = videoAlarm.getEndTime(); + } + // 查询视频告警数据 + Result> soe = alarmClient.getDeviceCodeByTaosSoe(startTime,endTime,videoAlarm.getDeviceCode(),(int) page.getCurrent(), String.valueOf(page.getSize())); + if(!soe.isSuccess() || CollectionUtil.isEmpty(soe.getData().getRecords())){ + return new HzPage<>(); + } + List records = soe.getData().getRecords(); + soe.getData().setRecords(records.stream().peek(record -> { + record.setSoeType(videoAlarm.getDeviceName() + "_" + VideoEnumConstants.SoeKindEnum.getValueByKey(record.getInstanceFieldName()) + "_触发告警"); + if(!StringUtil.isEmpty(record.getSoeExplain())) { + String soeExplain = StringUtils.strip(record.getSoeExplain(), "[]"); + StringBuilder sb = new StringBuilder(); + if(record.getSoeExplain().contains("http")){ + String[] imgs = soeExplain.split(","); + for (String img : imgs){ + sb.append(img).append(","); + } + }else{ + String[] imgs = soeExplain.split(","); + for (String img : imgs){ + sb.append("https://172.30.100.204").append(img).append(","); + } + } + record.setSoeAlarmType(sb.substring(0, sb.length() - 1).replace("\"", "")); + } + }).collect(Collectors.toList())); + return soe.getData(); + } +} \ No newline at end of file