Browse Source

Merge remote-tracking branch 'origin/develop' into develop

develop
wangsixiang 2 weeks ago
parent
commit
aa426f9f6b
  1. 41
      zc-business/src/main/java/com/zc/business/controller/BridgeMonitoringController.java
  2. 4
      zc-business/src/main/java/com/zc/business/domain/DcWarning.java
  3. 2
      zc-business/src/main/java/com/zc/business/enums/ValueConverter.java
  4. 3
      zc-business/src/main/java/com/zc/business/enums/WarningSourceEnum.java
  5. 27
      zc-business/src/main/java/com/zc/business/mapper/BridgeMonitoringMapper.java
  6. 21
      zc-business/src/main/java/com/zc/business/service/BridgeMonitoringService.java
  7. 146
      zc-business/src/main/java/com/zc/business/service/impl/BridgeMonitoringServiceImpl.java
  8. 15
      zc-business/src/main/resources/mapper/business/BridgeMonitoringMapper.xml
  9. 2
      zc-business/src/main/resources/mapper/business/DcEventMapper.xml

41
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();
}
}

4
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;
/** 预警级别 */

2
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","车辆故障");

3
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;

27
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<DcDevice> {
/**
* 查询桥梁列表
*/
List<DcFacility> selectFacilityList();
/**
* 查询当天的桥梁监测报警事件id
*/
List<String> selectTodayBridgeWarning();
}

21
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<DcFacility> selectFacilityList();
}

146
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<String, String> header = new HashMap<>();
header.put("Authorization", token);
//桥梁列表
List<DcFacility> facilityList = bridgeMonitoringMapper.selectFacilityList();
//当天的桥梁报警事件id
List<String> 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<DcFacility> selectFacilityList(){
return bridgeMonitoringMapper.selectFacilityList();
}
}

15
zc-business/src/main/resources/mapper/business/BridgeMonitoringMapper.xml

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zc.business.mapper.BridgeMonitoringMapper">
<select id="selectFacilityList" resultType="com.zc.business.domain.DcFacility">
select * from dc_facility where facility_type = '2'
</select>
<select id="selectTodayBridgeWarning" resultType="java.lang.String">
select JSON_UNQUOTE(JSON_EXTRACT(other_config, '$.id')) from dc_warning
where date_format(warning_time,'%Y-%m-%d') = date_format(now(),'%Y-%m-%d') and warning_source = '9'
</select>
</mapper>

2
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,

Loading…
Cancel
Save