wangsixiang
2 weeks ago
9 changed files with 258 additions and 3 deletions
@ -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(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
@ -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(); |
||||
|
} |
@ -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(); |
||||
|
|
||||
|
} |
@ -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(); |
||||
|
} |
||||
|
|
||||
|
} |
@ -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> |
Loading…
Reference in new issue