diff --git a/zc-business/src/main/java/com/zc/business/controller/BridgeMonitoringController.java b/zc-business/src/main/java/com/zc/business/controller/BridgeMonitoringController.java new file mode 100644 index 00000000..632e7d06 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/controller/BridgeMonitoringController.java @@ -0,0 +1,41 @@ +package com.zc.business.controller; + +import com.ruoyi.common.core.controller.BaseController; +import com.zc.business.service.BridgeMonitoringService; +import com.zc.common.core.httpclient.exception.HttpException; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.io.IOException; + + +/** + * @Description 桥梁监测Controller + * + * @author liuwenge + * @date 2024/11/12 14:38 + */ +@Api(tags = "桥梁监测") +@RestController +@Component +@RequestMapping("/bridgeMonitoring") +public class BridgeMonitoringController extends BaseController { + + @Autowired + private BridgeMonitoringService bridgeMonitoringService; + + @ApiOperation("获取当天的桥梁监测报警事件") + @PostMapping("/getWarningEvent") + @Scheduled(cron = "0 */5 * * * ?") + public void getWarningEvent() throws IOException, HttpException { + bridgeMonitoringService.getWarningEvent(); + } + + +} diff --git a/zc-business/src/main/java/com/zc/business/domain/DcWarning.java b/zc-business/src/main/java/com/zc/business/domain/DcWarning.java index 0cf1ccaa..aab5e4d4 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcWarning.java +++ b/zc-business/src/main/java/com/zc/business/domain/DcWarning.java @@ -44,8 +44,8 @@ public class DcWarning extends BaseEntity /** 处理人员 */ private Long userId; - /** 信息来源:1-视频AI2-雷达识别3-锥桶4-护栏碰撞5-扫码报警6-非机预警,7-气象监测器,8-边坡监测 */ - @Excel(name = "信息来源", readConverterExp = "1=视频AI,2=雷达识别,3=锥桶,4=护栏碰撞,5=扫码报警,6=非机预警,7=气象监测器,8=边坡监测") + /** 信息来源:1-视频AI2-雷达识别3-锥桶4-护栏碰撞5-扫码报警6-非机预警,7-气象监测器,8-边坡监测,9-桥梁监测 */ + @Excel(name = "信息来源", readConverterExp = "1=视频AI,2=雷达识别,3=锥桶,4=护栏碰撞,5=扫码报警,6=非机预警,7=气象监测器,8=边坡监测,9-桥梁监测") private Integer warningSource; /** 预警级别 */ diff --git a/zc-business/src/main/java/com/zc/business/enums/ValueConverter.java b/zc-business/src/main/java/com/zc/business/enums/ValueConverter.java index 3346ee11..181a5e8a 100644 --- a/zc-business/src/main/java/com/zc/business/enums/ValueConverter.java +++ b/zc-business/src/main/java/com/zc/business/enums/ValueConverter.java @@ -42,6 +42,7 @@ public class ValueConverter { valueMappingSource.put(5,11); valueMappingSource.put(6,12); valueMappingSource.put(8,14); + valueMappingSource.put(9,15); valueMappingHost.put(1, 4); valueMappingHost.put(2, 5); valueMappingHost.put(3, 5); @@ -127,6 +128,7 @@ public class ValueConverter { eventSourceName.put("12","非机预警"); eventSourceName.put("13","气象检测器"); eventSourceName.put("14","边坡监测"); + eventSourceName.put("15","桥梁监测"); eventTypeName.put("1","交通事故"); eventTypeName.put("2","车辆故障"); diff --git a/zc-business/src/main/java/com/zc/business/enums/WarningSourceEnum.java b/zc-business/src/main/java/com/zc/business/enums/WarningSourceEnum.java index 4b080b9e..247dee07 100644 --- a/zc-business/src/main/java/com/zc/business/enums/WarningSourceEnum.java +++ b/zc-business/src/main/java/com/zc/business/enums/WarningSourceEnum.java @@ -12,7 +12,8 @@ public enum WarningSourceEnum { QR_CODE_ALERT(5,"扫码报警"), NON_MOTOR_VEHICLE_WARNING(6,"非机动车预警"), WEATHER_WARNING(7,"气象检测器"), - SIDE_SLOPE_WARNING(8,"边坡监测"); + SIDE_SLOPE_WARNING(8,"边坡监测"), + BRIDGE_WARNING(9,"桥梁监测"); private final Integer code; private final String description; diff --git a/zc-business/src/main/java/com/zc/business/mapper/BridgeMonitoringMapper.java b/zc-business/src/main/java/com/zc/business/mapper/BridgeMonitoringMapper.java new file mode 100644 index 00000000..ab00ac8b --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/mapper/BridgeMonitoringMapper.java @@ -0,0 +1,27 @@ +package com.zc.business.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.zc.business.domain.DcDevice; +import com.zc.business.domain.DcFacility; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * 桥梁监测Mapper接口 + * + */ +@Mapper +public interface BridgeMonitoringMapper extends BaseMapper { + + + /** + * 查询桥梁列表 + */ + List selectFacilityList(); + + /** + * 查询当天的桥梁监测报警事件id + */ + List selectTodayBridgeWarning(); +} diff --git a/zc-business/src/main/java/com/zc/business/service/BridgeMonitoringService.java b/zc-business/src/main/java/com/zc/business/service/BridgeMonitoringService.java new file mode 100644 index 00000000..53113107 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/service/BridgeMonitoringService.java @@ -0,0 +1,21 @@ +package com.zc.business.service; + +import com.zc.business.domain.DcFacility; +import com.zc.common.core.httpclient.exception.HttpException; + +import java.io.IOException; +import java.util.List; + +/** + * 桥梁监测Service接口 + * + * @author liuwenge + * @date 2024-11-12 + */ +public interface BridgeMonitoringService { + + void getWarningEvent() throws IOException, HttpException; + + List selectFacilityList(); + +} diff --git a/zc-business/src/main/java/com/zc/business/service/impl/BridgeMonitoringServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/BridgeMonitoringServiceImpl.java new file mode 100644 index 00000000..b5f0bfbd --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/service/impl/BridgeMonitoringServiceImpl.java @@ -0,0 +1,146 @@ +package com.zc.business.service.impl; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.system.service.ISysConfigService; +import com.zc.business.domain.DcFacility; +import com.zc.business.domain.DcWarning; +import com.zc.business.mapper.BridgeMonitoringMapper; +import com.zc.business.service.BridgeMonitoringService; +import com.zc.business.service.IDcWarningService; +import com.zc.common.core.httpclient.OkHttp; +import com.zc.common.core.httpclient.exception.HttpException; +import com.zc.common.core.httpclient.request.RequestParams; +import okhttp3.Response; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.*; +import java.util.stream.Collectors; + +/** + * 桥梁监测Service业务层处理 + * + * @author ruoyi + * @date 2024-11-12 + */ +@Service +public class BridgeMonitoringServiceImpl implements BridgeMonitoringService { + + @Autowired + private BridgeMonitoringMapper bridgeMonitoringMapper; + + @Resource + private IDcWarningService dcWarningService; + + @Autowired + private ISysConfigService configService; + + + @Override + public void getWarningEvent() throws IOException, HttpException { + String config = configService.selectConfigByKey("bridgeMonitoringApi"); + if (StringUtils.isEmpty(config)){ + return; + } + JSONObject bridgeMonitoringApi = JSONObject.parseObject(config); + String token = bridgeMonitoringApi.getString("token"); + String url = bridgeMonitoringApi.getString("url"); + if (StringUtils.isEmpty(token) || StringUtils.isEmpty(url)){ + return; + } + + OkHttp okHttp = new OkHttp(); + + RequestParams requestParams = new RequestParams(); + //查询当天的 + LocalDate today = LocalDate.now(); + ZonedDateTime startOfDay = today.atStartOfDay(ZoneId.systemDefault()); + requestParams.put("start", startOfDay.toEpochSecond()); + + Map header = new HashMap<>(); + header.put("Authorization", token); + + //桥梁列表 + List facilityList = bridgeMonitoringMapper.selectFacilityList(); + //当天的桥梁报警事件id + List bridgeWarningEvent = bridgeMonitoringMapper.selectTodayBridgeWarning(); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss"); + + for (DcFacility dcFacility : facilityList) { + JSONObject otherConfig = JSONObject.parseObject(dcFacility.getOtherConfig()); + if (!otherConfig.containsKey("codeName") || StringUtils.isEmpty(otherConfig.getString("codeName"))){ + continue; + } + + Response response // 请求响应 + = okHttp + .headers(header) + .url(String.format(url,otherConfig.getString("codeName"))) // 请求地址 + .data(requestParams) // 请求参数 + .get(); // 请求方法 + if (response.body() != null) { + JSONObject jsonResult = JSONObject.parseObject(response.body().string()); + JSONArray data = jsonResult.getJSONArray("data"); + for (Object datum : data) { + JSONObject dataItem = (JSONObject) datum; + //如果库中有此条数据则跳过 + if (bridgeWarningEvent.contains(dataItem.getString("id"))){ + continue; + } + + DcWarning dcWarning = new DcWarning(); + dcWarning.setStakeMark(dcFacility.getStakeMark()); + dcWarning.setDirection("1"); + Date warningTime = new Date(dataItem.getLong("first_addon") * 1000); + dcWarning.setWarningTime(warningTime); + dcWarning.setOtherConfig(dataItem.toJSONString()); + dcWarning.setWarningType(99); + dcWarning.setWarningSubclass("99-1"); + dcWarning.setWarningSource(9); + dcWarning.setWarningState(1); + + String timeStr = simpleDateFormat.format(warningTime); + String warningLevel = ""; + if (dataItem.getString("level").equals("-3")){ + warningLevel = "超下限重度预警"; + } else if (dataItem.getString("level").equals("-2")){ + warningLevel = "超下限中度预警"; + } else if (dataItem.getString("level").equals("-1")){ + warningLevel = "超下限轻度预警"; + } else if (dataItem.getString("level").equals("1")){ + warningLevel = "超上限轻度预警"; + } else if (dataItem.getString("level").equals("2")){ + warningLevel = "超上限中度预警"; + } else if (dataItem.getString("level").equals("3")){ + warningLevel = "超上限重度预警"; + } + + //2024年10月23日 14:45:00 K066+666 菏泽方向 桥梁监测上报了一起超上限中度预警事件(左幅116-117跨中新桥左侧腹板上部数据超限异常30.23με) + String remark = timeStr + " " + dcFacility.getStakeMark() + " 菏泽方向 桥梁监测上报了一起" + + warningLevel +"事件(" + dataItem.getString("location") + dataItem.getString("exception") + + String.format("%.2f", dataItem.getFloat("val")) + dataItem.getString("unit") + ")"; + dcWarning.setRemark(remark); + + dcWarningService.insertDcWarning(dcWarning); + } + + } + } + + } + + + @Override + public List selectFacilityList(){ + return bridgeMonitoringMapper.selectFacilityList(); + } + +} diff --git a/zc-business/src/main/resources/mapper/business/BridgeMonitoringMapper.xml b/zc-business/src/main/resources/mapper/business/BridgeMonitoringMapper.xml new file mode 100644 index 00000000..6b43943e --- /dev/null +++ b/zc-business/src/main/resources/mapper/business/BridgeMonitoringMapper.xml @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/zc-business/src/main/resources/mapper/business/DcEventMapper.xml b/zc-business/src/main/resources/mapper/business/DcEventMapper.xml index 07e7aba9..9f92106a 100644 --- a/zc-business/src/main/resources/mapper/business/DcEventMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcEventMapper.xml @@ -259,6 +259,7 @@ WHEN '12' THEN '非机预警' WHEN '13' THEN '气象检测器' WHEN '14' THEN '边坡监测' + WHEN '15' THEN '桥梁监测' ELSE '其他' END AS stringEventSource, event_nature, @@ -507,6 +508,7 @@ WHEN '12' THEN '非机预警' WHEN '13' THEN '气象检测器' WHEN '14' THEN '边坡监测' + WHEN '15' THEN '桥梁监测' ELSE '其他' END AS stringEventSource, dc_event.event_nature,