Browse Source

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

develop
王兴琳 5 months ago
parent
commit
b15412a99e
  1. 58
      zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java
  2. 32
      zc-business/src/main/java/com/zc/business/controller/DeviceStatus.java
  3. 6
      zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java
  4. 2
      zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java
  5. 8
      zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java

58
zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java

@ -192,6 +192,7 @@ public class DcDeviceController extends BaseController {
/**
* 导出
*
* @param response 响应
* @param iotDevice 导入数据结果
*/
@ -591,8 +592,8 @@ public class DcDeviceController extends BaseController {
resultArray.add(getAjaxResult(deviceId, functionId, (HashMap<String, Object>) param));
}
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("SET", UniversalEnum.SEVEN.getValue());
getAjaxResult(deviceId, "SETMD", hashMap);
hashMap.put(UniversalEnum.SET.getValue(), UniversalEnum.SEVEN.getValue());
getAjaxResult(deviceId, UniversalEnum.SETMD.getValue(), hashMap);
return AjaxResult.success(resultArray);
}
@ -648,7 +649,7 @@ public class DcDeviceController extends BaseController {
if (!StringUtils.hasText(deviceId) || !StringUtils.hasText(type)) {
return AjaxResult.error(UniversalEnum.DEVICE_NOT_CONNECTED.getValue());
}
if (type.equals(UniversalEnum.ALL.getValue())){
if (type.equals(UniversalEnum.ALL.getValue())) {
OkHttp okHttp = new OkHttp();
@ -656,11 +657,11 @@ public class DcDeviceController extends BaseController {
Response response // 请求响应
= okHttp
.url(iotAddress + UniversalEnum.QUERY_EVENT_DATA_OF_IOT_DEVICES.getValue()+deviceId) // 请求地址
.url(iotAddress + UniversalEnum.QUERY_EVENT_DATA_OF_IOT_DEVICES.getValue() + deviceId) // 请求地址
.data(requestParams)
.get(); // 请求方法
return JSON.parseObject(response.body().string(), AjaxResult.class);
}else {
} else {
return queryPagerDeviceEvents(deviceId, type, queryParam);
}
}
@ -678,27 +679,25 @@ public class DcDeviceController extends BaseController {
OkHttp okHttp = new OkHttp();
Response response // 请求响应
= okHttp
.url(iotAddress + UniversalEnum.GET_A_PHYSICAL_MODEL_OF_AN_IOT_DEVICE.getValue()+ id) // 请求地址
.url(iotAddress + UniversalEnum.GET_A_PHYSICAL_MODEL_OF_AN_IOT_DEVICE.getValue() + id) // 请求地址
.get(); // 请求方法
return JSON.parseObject(response.body().string(), AjaxResult.class);
}
/**
* @Description 查询上游10公里内的情报板
*
* @author liuwenge
* @date 2024/4/15 14:22
* @param stakeMark
* @param direction
* @return com.ruoyi.common.core.domain.AjaxResult
* @Description 查询上游10公里内的情报板
* @author liuwenge
* @date 2024/4/15 14:22
*/
@ApiOperation("查询上游10公里内的情报板")
@PostMapping("/selectNearBoard")
public AjaxResult selectNearBoard(@ApiParam(value="桩号", name="stakeMark", required=true) @RequestParam ("stakeMark") String stakeMark,
@ApiParam(value="方向", name="direction", required=true) @RequestParam ("direction") String direction){
return dcDeviceService.selectNearBoard(stakeMark,direction);
public AjaxResult selectNearBoard(@ApiParam(value = "桩号", name = "stakeMark", required = true) @RequestParam("stakeMark") String stakeMark,
@ApiParam(value = "方向", name = "direction", required = true) @RequestParam("direction") String direction) {
return dcDeviceService.selectNearBoard(stakeMark, direction);
}
@OperationLog(operUrl = "/business/device/batchFunctions")
@ -710,6 +709,7 @@ public class DcDeviceController extends BaseController {
/**
* 分页查询设备名称列表
*
* @param dcDevice 请求参数
* @return 分页查询结果
*/
@ -718,10 +718,12 @@ public class DcDeviceController extends BaseController {
startPage();
return getDataTable(dcDeviceService.selectDeviceNameList(dcDevice));
}
@GetMapping("/deviceParameter")
public AjaxResult selectDeviceParameterProperties(DcDevice dcDevice) {
return AjaxResult.success(dcDeviceService.selectDeviceParameterProperties(dcDevice));
}
/**
* 查询设备指定属性属性列表
* param参数
@ -730,13 +732,14 @@ public class DcDeviceController extends BaseController {
* propertyName 属性名称
* deviceType 设备类型
* dateTime 时间
*
* @return 属性列表
*/
@PostMapping("/properties/deviceNameData")
public AjaxResult queryDevice(@RequestBody HashMap map) throws HttpException, IOException {
if (map==null||!map.containsKey("deviceId")||!map.containsKey("deviceType")
||!map.containsKey("propertyName")||!map.containsKey("propertyId")
||!map.containsKey("dateTime")){
if (map == null || !map.containsKey("deviceId") || !map.containsKey("deviceType")
|| !map.containsKey("propertyName") || !map.containsKey("propertyId")
|| !map.containsKey("dateTime")) {
return AjaxResult.error(UniversalEnum.PARAMETER_ERROR.getValue());
}
String deviceType = map.get("deviceType").toString();//设备类型
@ -763,7 +766,7 @@ public class DcDeviceController extends BaseController {
props.put("sorts[0].name", "timestamp");
AjaxResult ajaxResult = queryDeviceProperties(deviceId, propertyId, props);
String code = ajaxResult.get("code").toString();
if ("500".equals(code)){
if (UniversalEnum.FIVE_HUNDRED.getValue().equals(code)) {
return ajaxResult;
}
if (UniversalEnum.THIRTEEN.getValue().equals(deviceType) || UniversalEnum.SIXTEEN.getValue().equals(deviceType)) { //判断是否为设备箱/远端机
@ -813,6 +816,7 @@ public class DcDeviceController extends BaseController {
}
return null;
}
/**
* 设备箱-设备操作口令校验
*/
@ -911,4 +915,22 @@ public class DcDeviceController extends BaseController {
return AjaxResult.success(resultsMapValue);
}
///***
// * 合流区预警设备设备电量不足警告
// */
//@Scheduled(cron = "0 0/1 * * * ?")
//public void ConfluenceAreaEarlyWarningDeviceBatteryLowWarning() throws HttpException, IOException {
// DcDevice dcDevice = new DcDevice();
// dcDevice.setDeviceType("8");
// List<DcDevice> devices = dcDeviceService.listDevice(dcDevice);
// for (DcDevice device : devices) {
// String iotDeviceId = device.getIotDeviceId();
// if (iotDeviceId != null && !iotDeviceId.equals("")) {
// AjaxResult deviceLatestProperty = queryDeviceProperties(iotDeviceId, "batteryCapacity",new HashMap<>());
// System.out.println(deviceLatestProperty.get("code"));
// System.out.println(deviceLatestProperty.get("msg"));
// }
// }
//}
}

32
zc-business/src/main/java/com/zc/business/controller/DeviceStatus.java

@ -63,13 +63,19 @@ public class DeviceStatus {
AjaxResult deviceByIotDeviceId = deviceService.getDeviceByIotDeviceId(device.getIotDeviceId());
String deviceState = ((JSONObject) JSON.toJSON(deviceByIotDeviceId.get("data"))).getString("deviceState");
if (Objects.equals(deviceState, UniversalEnum.ON_LINE.getValue())) {
extracted(statusService, device, UniversalEnum.ONE_HUNDRED_PERCENT.getValue());
extracted(statusService, device, true, UniversalEnum.ZERO_PERCENT.getValue());
} else {
extracted(statusService, device, UniversalEnum.ZERO_PERCENT.getValue());
extracted(statusService, device, false, UniversalEnum.ONE_HUNDRED_PERCENT.getValue());
}
} else {
extracted(statusService, device, getPingPacketLossRate(device.getDeviceIp()));
if (StringUtil.isNotEmpty(device.getDeviceIp())) {
InetAddress address = InetAddress.getByName(device.getDeviceIp());
boolean reachable = address.isReachable(UniversalEnum.FIVE_THOUSAND.getNumber()); // Timeout: 5 seconds
extracted(statusService, device, reachable, getPingPacketLossRate(device.getDeviceIp()));
} else {
extracted(statusService, device, false, UniversalEnum.ONE_HUNDRED_PERCENT.getValue());
}
}
return null;
};
@ -88,8 +94,7 @@ public class DeviceStatus {
executor.shutdown();
}
private void extracted(StatusService statusService, DcDevice device, String lostRate) {
try {
private void extracted(StatusService statusService, DcDevice device, boolean reachable, String packetLossRate) {
Status status = new Status();
status.setDeviceNo(device.getStakeMark());
status.setDeviceName(device.getDeviceName());
@ -97,10 +102,7 @@ public class DeviceStatus {
status.setDeviceId(device.getId());
LocalDateTime localDateTime = LocalDateTime.now();
status.setTime(localDateTime);
if (StringUtil.isNotEmpty(device.getDeviceIp())) {
InetAddress address = InetAddress.getByName(device.getDeviceIp());
boolean reachable = address.isReachable(UniversalEnum.FIVE_THOUSAND.getNumber()); // Timeout: 5 seconds
status.setLostRate(lostRate);
status.setLostRate(packetLossRate);
if (reachable) {
status.setDeviceStatus(UniversalEnum.ONE.getValue());
status.setSuccessRate(UniversalEnum.ONE_HUNDRED_PERCENT.getValue());
@ -108,15 +110,7 @@ public class DeviceStatus {
status.setDeviceStatus(UniversalEnum.ZERO.getValue());
status.setSuccessRate(UniversalEnum.ZERO_PERCENT.getValue());
}
} else {
status.setDeviceStatus(UniversalEnum.ZERO.getValue());
status.setSuccessRate(UniversalEnum.ZERO_PERCENT.getValue());
status.setLostRate(UniversalEnum.ONE_HUNDRED_PERCENT.getValue());
}
statusService.Add(status);
} catch (IOException e) {
System.out.println("Error pinging " + device.getDeviceIp() + ": " + e.getMessage());
}
}
@ -139,8 +133,8 @@ public class DeviceStatus {
if (line.contains("packets transmitted")) {
// Extract the number of packets sent and lost
String[] stats = line.split(", ");
packetsSent = Integer.parseInt(stats[UniversalEnum.ZERO.getNumber()].split(" ")[UniversalEnum.ZERO.getNumber()]);
packetsLost = Integer.parseInt(stats[UniversalEnum.ZERO.getNumber()].split(" ")[UniversalEnum.ZERO.getNumber()]) - Integer.parseInt(stats[UniversalEnum.ONE.getNumber()].split(" ")[UniversalEnum.ZERO.getNumber()]);
packetsSent = Integer.parseInt(stats[UniversalEnum.ZERO.getNumber()].split(UniversalEnum.BLANK_SPACE.getValue())[UniversalEnum.ZERO.getNumber()]);
packetsLost = Integer.parseInt(stats[UniversalEnum.ZERO.getNumber()].split(UniversalEnum.BLANK_SPACE.getValue())[UniversalEnum.ZERO.getNumber()]) - Integer.parseInt(stats[UniversalEnum.ONE.getNumber()].split(UniversalEnum.BLANK_SPACE.getValue())[UniversalEnum.ZERO.getNumber()]);
}
}

6
zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java

@ -2077,6 +2077,12 @@ public enum UniversalEnum {
// 中冒号
IN_THE_COLON(0, ":"),
// 左小括号
OPEN_PARENTHESIS(0, "("),
// 右小括号
CLOSING_PARENTHESIS(0, ")"),
// 左中括号
LEFT_CENTER_BRACKET(0, "["),

2
zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java

@ -587,7 +587,7 @@ public class DeviceMessageHandler {
//设备名称
meteorologicalDetectorData.setDeviceName(deviceName+"("+stakeMark+")");
meteorologicalDetectorData.setDeviceName(deviceName+UniversalEnum.OPEN_PARENTHESIS.getValue()+stakeMark+UniversalEnum.CLOSING_PARENTHESIS.getValue());
//位置
meteorologicalDetectorData.setStakeMark(stakeMark);
//方向

8
zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java

@ -923,7 +923,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
Response response // 请求响应
= okHttp
.headers(headers)
.url(baseUrl + "/api/dc/query/rd_tr_congestion_jh") // 请求地址
.url(baseUrl + UniversalEnum.GETS_THE_URI_OF_THE_CURRENT_CONGESTION_EVENT.getValue()) // 请求地址
.data(requestParams) // 请求参数
.post(); // 请求方法
@ -1035,10 +1035,10 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi
double dLon = endLonRad - startLonRad;
// Haversine公式
double a = Math.pow(Math.sin(dLat / 2), 2) +
double a = Math.pow(Math.sin(dLat / UniversalEnum.TWO.getNumber()), UniversalEnum.TWO.getNumber()) +
Math.cos(startLatRad) * Math.cos(endLatRad) *
Math.pow(Math.sin(dLon / 2), 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
Math.pow(Math.sin(dLon / UniversalEnum.TWO.getNumber()), UniversalEnum.TWO.getNumber());
double c = UniversalEnum.TWO.getNumber() * Math.atan2(Math.sqrt(a), Math.sqrt(UniversalEnum.ONE.getNumber() - a));
// 计算两点间的距离
double distance = EARTH_RADIUS * c;

Loading…
Cancel
Save