From 77d5e2a158cca43fbbf3264e1feabd7101f47e28 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Mon, 23 Sep 2024 21:24:58 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E6=95=85=E9=9A=9C=E3=80=81=E8=A7=86?= =?UTF-8?q?=E9=A2=91=E5=90=8C=E6=AD=A5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hnac/hzims/fdp/vo/FdpFaultMatchVO.java | 58 +++++++++++++ .../fdp/controller/FdpFaultMatchController.java | 37 ++++++++ .../hzims/fdp/service/IFdpFaultMatchService.java | 16 ++++ .../fdp/service/impl/FdpFaultMatchServiceImpl.java | 99 ++++++++++++++++++++++ .../controller/StationVideoTypeController.java | 4 +- .../station/mapper/StationVideoTypeMapper.java | 3 +- .../station/mapper/StationVideoTypeMapper.xml | 33 ++------ .../station/service/IStationVideoTypeService.java | 2 +- .../service/impl/StationVideoTypeServiceImpl.java | 2 +- 9 files changed, 224 insertions(+), 30 deletions(-) create mode 100644 hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/fdp/vo/FdpFaultMatchVO.java create mode 100644 hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/controller/FdpFaultMatchController.java create mode 100644 hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/IFdpFaultMatchService.java create mode 100644 hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpFaultMatchServiceImpl.java diff --git a/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/fdp/vo/FdpFaultMatchVO.java b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/fdp/vo/FdpFaultMatchVO.java new file mode 100644 index 0000000..e291305 --- /dev/null +++ b/hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/fdp/vo/FdpFaultMatchVO.java @@ -0,0 +1,58 @@ +package com.hnac.hzims.fdp.vo; + +import com.alibaba.fastjson.annotation.JSONField; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.tool.utils.Func; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/09/23 14:35 + */ +@Data +@EqualsAndHashCode +public class FdpFaultMatchVO implements Serializable { + + @JSONField(name = "item_id") + private String itemId; + + @JSONField(name = "item_name") + private String itemName; + + @JSONField(name = "ord") + private String ord; + + @JSONField(name = "station_id") + private String stationId; + + @JSONField(name = "station_name") + private String stationName; + + @JSONField(name = "device_name") + private String deviceName; + + @JSONField(name = "fault_name") + private String faultName; + + @JSONField(name = "is_root") + private Integer isRoot; + + private Integer display; + + @JSONField(name = "device_fault_name") + private String deviceFaultName; + + public void setItemName() { + this.itemId = String.format("%s %s", this.deviceName, this.faultName); + } + + public void setDeviceFaultName() { + if(Func.isNotEmpty(this.ord)) { + this.deviceFaultName = String.format("%s %s", this.ord, this.faultName); + } else { + this.deviceFaultName = String.format("%s %s", this.deviceName, this.faultName); + } + } +} diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/controller/FdpFaultMatchController.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/controller/FdpFaultMatchController.java new file mode 100644 index 0000000..eac836f --- /dev/null +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/controller/FdpFaultMatchController.java @@ -0,0 +1,37 @@ +package com.hnac.hzims.fdp.controller; + +import com.alibaba.fastjson.JSONObject; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.fdp.service.IFdpFaultMatchService; +import com.hnac.hzinfo.api.annotation.ApiInterface; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +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; + +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/09/23 19:11 + */ +@RestController +@AllArgsConstructor +@RequestMapping("/fdp/faultMatch") +@Api(value = "故障匹配数据接口管理",tags = "故障匹配数据接口管理") +public class FdpFaultMatchController { + + private final IFdpFaultMatchService fdpFaultMatchService; + + @GetMapping("/getFdpFaultMatchList") + @ApiOperation("获取故障匹配数据列表") + @ApiOperationSupport(order = 1) + @ApiInterface + public R> getFdpFaultMatchList() { + return R.data(fdpFaultMatchService.getFdpFaultMatchList()); + } + +} diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/IFdpFaultMatchService.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/IFdpFaultMatchService.java new file mode 100644 index 0000000..2747aed --- /dev/null +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/IFdpFaultMatchService.java @@ -0,0 +1,16 @@ +package com.hnac.hzims.fdp.service; + +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.fdp.vo.FdpFaultMatchVO; + +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/09/23 16:14 + */ +public interface IFdpFaultMatchService { + + List getFdpFaultMatchList(); + +} diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpFaultMatchServiceImpl.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpFaultMatchServiceImpl.java new file mode 100644 index 0000000..1d877f2 --- /dev/null +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/fdp/service/impl/FdpFaultMatchServiceImpl.java @@ -0,0 +1,99 @@ +package com.hnac.hzims.fdp.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.google.common.collect.Lists; +import com.hnac.hzims.fdp.service.IFdpFaultMatchService; +import com.hnac.hzims.fdp.util.HttpRequestUtil; +import com.hnac.hzims.fdp.vo.FdpFaultMatchVO; +import lombok.RequiredArgsConstructor; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * @Author: huangxing + * @Date: 2024/09/23 16:15 + */ +@Service +@RequiredArgsConstructor +public class FdpFaultMatchServiceImpl implements IFdpFaultMatchService { + + @Value("${url.getStations}") + public String stationDataPath; + @Value("${url.getFaultAndMonitor}") + public String faultDataPath; + + @Override + public List getFdpFaultMatchList() { + List matchVOList = Lists.newArrayList(); + // 获取站点列表 + String result = HttpRequestUtil.postCall(null, stationDataPath, "POST"); + if (StringUtil.isNotBlank(result)) { + JSONObject resultObject = JSONObject.parseObject(result); + JSONArray dataArray = Optional.ofNullable(resultObject.getString("data")).map(JSONArray::parseArray).orElse(null); + if(Func.isNotEmpty(dataArray)) { + dataArray.forEach(jsonObject -> { + JSONObject station = JSONObject.parseObject(jsonObject.toString()); + String stationId = station.getString("ID"); + String stationName = station.getString("NAME"); + List faultMatchVOList = this.getFdpFaultListByStation(stationId,stationName); + if(Func.isNotEmpty(faultMatchVOList)) { + matchVOList.addAll(faultMatchVOList); + } + }); + } + } + // 根据站点获取故障列表 + return matchVOList.stream().map(vo -> JSON.toJSONString(vo, SerializerFeature.WriteMapNullValue)).map(JSONObject::parseObject).collect(Collectors.toList()); + } + + /** + * 根据站点获取故障列表 + * @param stationId 站点ID + * @param stationName 站点名称 + * @return List + */ + private List getFdpFaultListByStation(String stationId, String stationName) { + if (StringUtil.isNotBlank(stationId)) { + HashMap paramMap = new HashMap<>(); + paramMap.put("stationId", stationId); + String result = HttpRequestUtil.postCall(paramMap, faultDataPath, "POST"); + if (StringUtil.isNotBlank(result)) { + JSONObject resultObject = JSONObject.parseObject(result); + JSONArray dataArray = Optional.ofNullable(resultObject.getString("data")) + .map(JSONObject::parseObject) + .map(data -> data.getString("faults")) + .map(JSONArray::parseArray).orElse(null); + if (Func.isNotEmpty(dataArray)) { + return dataArray.stream().map(jsonObject -> { + FdpFaultMatchVO matchVO = new FdpFaultMatchVO(); + JSONObject fault = JSONObject.parseObject(jsonObject.toString()); + matchVO.setItemId(fault.getString("ID")); + matchVO.setOrd(fault.getString("ORD")); + matchVO.setStationId(stationId); + matchVO.setStationName(stationName); + matchVO.setFaultName(fault.getString("NAME")); + matchVO.setDeviceName(fault.getString("DEVICE_NAME")); + matchVO.setIsRoot(fault.getInteger("IS_ROOT")); + matchVO.setDisplay(fault.getInteger("DISPLAY")); + matchVO.setDeviceFaultName(); + matchVO.setItemName(); + return matchVO; + }).collect(Collectors.toList()); + } + } + } + return null; + } + +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java index 252e1c4..ce784c8 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/controller/StationVideoTypeController.java @@ -26,6 +26,7 @@ import com.hnac.hzims.operational.station.vo.StationVO; import com.hnac.hzims.operational.station.vo.StationVideoTypeVO; import com.hnac.hzims.operational.station.vo.VideoMonitorVO; import com.hnac.hzims.operational.station.wrapper.StationVideoTypeWrapper; +import com.hnac.hzinfo.api.annotation.ApiInterface; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @@ -390,7 +391,8 @@ public class StationVideoTypeController extends BladeController { @GetMapping ("/listAll") @ApiOperationSupport(order = 200) @ApiOperation(value = "获取所有站点视频") - public R> listAll() { + @ApiInterface + public R>> listAll() { return R.data(stationVideoTypeService.listAll()); } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationVideoTypeMapper.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationVideoTypeMapper.java index f37a9a6..7c20ab7 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationVideoTypeMapper.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationVideoTypeMapper.java @@ -16,6 +16,7 @@ import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper; import java.sql.Wrapper; import java.util.List; +import java.util.Map; /** * @author hx @@ -45,5 +46,5 @@ public interface StationVideoTypeMapper extends UserDataScopeBaseMapper getAgencyStationsByVideo(@Param("type") String type); - List listAll(); + List> listAll(); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationVideoTypeMapper.xml b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationVideoTypeMapper.xml index ca41715..38f35b1 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationVideoTypeMapper.xml +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/mapper/StationVideoTypeMapper.xml @@ -72,34 +72,15 @@ order by hs.sort - SELECT - hsvt.id, - hsvt.name, - hsvt.station_id, - hsvt.dept_id, - hsvt.is_hikvideo, - hsvt.address, - hsvt.type, - hsvt.live_source_address, - hsvt.point_code, - hsvt.tenant_id, - hsvt.create_time, - hsvt.update_time, - hsvt.create_user, - hsvt.update_user, - hsvt.is_deleted, - hsvt.status, - hsvt.create_dept, - hsvt.video_host, - hsvt.app_key, - hsvt.app_secret, - hsvt.sort, - hsvt.video_type, - hsvt.platform_id, - hs.`name` AS stationName + hsvt.`id` AS item_id, + hsvt.`name` AS video_name, + hsvt.station_id AS station_id, + hs.`name` AS station_name, + concat(hs.`code`, ' ', hs.`name`) AS item_name FROM `hzims_station_video_type` hsvt - LEFT JOIN hzims_station hs ON hsvt.station_id = hs.`code` + LEFT JOIN hzims_station hs ON hsvt.station_id = hs.`code` WHERE hsvt.is_deleted = 0 AND hs.is_deleted = 0 diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java index de5618c..b5fcf8b 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java @@ -80,6 +80,6 @@ public interface IStationVideoTypeService extends IService getVideoByPointCodes(String pointCodes); - List listAll(); + List> listAll(); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java index 443da4a..355a291 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java @@ -368,7 +368,7 @@ public class StationVideoTypeServiceImpl extends ServiceImpl listAll() { + public List> listAll() { return baseMapper.listAll(); } }