diff --git a/ruoyi-ui/src/views/monitor/Interface/index.vue b/ruoyi-ui/src/views/monitor/Interface/index.vue index 66b89320..d429020c 100644 --- a/ruoyi-ui/src/views/monitor/Interface/index.vue +++ b/ruoyi-ui/src/views/monitor/Interface/index.vue @@ -160,6 +160,8 @@ export default { }, /** 重置 */ resetQuery() { + this.queryParams.startTime = undefined; + this.queryParams.endTime = undefined; this.resetForm("queryForm"); this.handleQuery(); }, diff --git a/zc-business/src/main/java/com/zc/business/constant/RedisKeyConstants.java b/zc-business/src/main/java/com/zc/business/constant/RedisKeyConstants.java index cd29ee5e..71ea7e2a 100644 --- a/zc-business/src/main/java/com/zc/business/constant/RedisKeyConstants.java +++ b/zc-business/src/main/java/com/zc/business/constant/RedisKeyConstants.java @@ -49,4 +49,8 @@ public class RedisKeyConstants * 交通流 */ public static final String TRAFFIC_FLOW = "trafficFlow"; + /* + * 设备在线监测 + * */ + public static final String DEVICE_ONLINE = "deviceOnline"; } diff --git a/zc-business/src/main/java/com/zc/business/controller/CodeScanningAlarmController.java b/zc-business/src/main/java/com/zc/business/controller/CodeScanningAlarmController.java index 14b9cfee..a0ae62d8 100644 --- a/zc-business/src/main/java/com/zc/business/controller/CodeScanningAlarmController.java +++ b/zc-business/src/main/java/com/zc/business/controller/CodeScanningAlarmController.java @@ -16,6 +16,7 @@ import javax.annotation.Resource; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashMap; import java.util.Map; import java.util.Objects; @@ -44,7 +45,9 @@ public class CodeScanningAlarmController extends BaseController { DcWarning dcWarning = new DcWarning(); dcWarning.setId(id); dcWarning.setOtherConfig(String.valueOf(JSONObject.parseObject(JSONObject.toJSONString(returnParameters)))); - if (dcWarningService.selectDcWarningById(id) == null) { + + HashMap oldData = dcWarningService.selectAlarmById(id); + if (oldData == null) { dcWarning.setStakeMark(String.valueOf(returnParameters.get("stakeNum"))); String roadCode = String.valueOf(returnParameters.get("roadCode")); dcWarning.setDirection(Objects.equals(roadCode, UniversalEnum.ONE.getValue()) ? UniversalEnum.THREE.getValue() : UniversalEnum.ONE.getValue()); @@ -79,12 +82,18 @@ public class CodeScanningAlarmController extends BaseController { dcWarning.setWarningSubclass(UniversalEnum.TEN_THREE.getValue()); break; } + + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mmXXX"); + String warningTitle = "G35济菏高速" + dcWarning.getStakeMark() + (Objects.equals(roadCode, UniversalEnum.ONE.getValue()) ? UniversalEnum.DIRECTION_OF_JINAN.getValue() : UniversalEnum.DIRECTION_OF_HEZE.getValue()) + "发生" + (Integer.parseInt(accidentType) >= 4 ? UniversalEnum.TRAFFIC_ACCIDENT_EVENT.getValue() : UniversalEnum.VEHICLE_BREAKDOWN_EVENT.getValue()); dcWarning.setWarningTitle(warningTitle); + dcWarning.setRemark(simpleDateFormat.format(dcWarning.getWarningTime()) + warningTitle); dcWarning.setWarningSource(UniversalEnum.FIVE.getNumber()); dcWarning.setWarningState(UniversalEnum.ONE.getNumber()); return AjaxResult.success(dcWarningService.insertDcWarning(dcWarning)); } else { + dcWarning.setId(oldData.get("id").toString()); + return AjaxResult.success(dcWarningService.updateDcWarning(dcWarning)); } } diff --git a/zc-business/src/main/java/com/zc/business/controller/DcBatchFunctionsJobGroupController.java b/zc-business/src/main/java/com/zc/business/controller/DcBatchFunctionsJobGroupController.java index e4b043a9..f3835775 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcBatchFunctionsJobGroupController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcBatchFunctionsJobGroupController.java @@ -86,6 +86,22 @@ public class DcBatchFunctionsJobGroupController extends BaseController { return AjaxResult.success(dcBatchFunctionsJobGroupService.addDcBatchFunctionsJobGroup(dcBatchFunctionsJobGroup)); } + + + /** + * 新增 + * + * @param dcBatchFunctionsJobGroup 新增参数 + * @return 新增操作结果 + */ + @ApiOperation("新增") + //@PreAuthorize("@ss.hasPermi('iot:facility:add')") + @Log(title = "新增", businessType = BusinessType.INSERT) + @PostMapping("/add") + public AjaxResult adddcBatchFunctionsJobGroupAnddcBatchFunctionsJob(@Valid @RequestBody DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) throws SchedulerException, TaskException { + return AjaxResult.success(dcBatchFunctionsJobGroupService.adddcBatchFunctionsJobGroupAnddcBatchFunctionsJob(dcBatchFunctionsJobGroup)); + } + /** * 修改 * diff --git a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java index b1cdbaac..25b62aaa 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java @@ -534,22 +534,137 @@ public class DcDeviceController extends BaseController { JSONObject device = (JSONObject) JSON.toJSON(dev); //JSONObject device = (JSONObject) JSON.toJSON(dev.toString()); String iotDeviceId = device.getString("iotDeviceId"); - for (Object function : functions) { - JSONObject functionJSONObject = (JSONObject) JSON.toJSON(function); - //JSONObject functionJSONObject = (JSONObject) JSON.toJSON(function.toString()) ; - String functionId = functionJSONObject.getString("functionId"); - JSONObject jsonObject = functionJSONObject.getJSONObject("params") != null ? functionJSONObject.getJSONObject("params") : new JSONObject(); - JSONObject result = getResult(device, iotDeviceId, functionId, jsonObject); - resultArray.add(result); - AjaxResult ajaxResult = (AjaxResult) result.get("result"); - if (!Objects.equals(String.valueOf(ajaxResult.get("code")), UniversalEnum.TWO_HUNDRED.getValue())) { - if (Objects.equals(device.getString("deviceType"), UniversalEnum.FIFTEEN.getValue())) { - return AjaxResult.error(UniversalEnum.TWO_HUNDRED.getNumber(), UniversalEnum.FIVE_HUNDRED.getValue()); + String deviceType = device.getString("deviceType"); + boolean continueToExecute = true; + if (Objects.equals(deviceType, UniversalEnum.TEN.getValue())) { + if (iotDeviceId == null) { + + for (Object function : functions) { + JSONObject functionJSONObject = (JSONObject) JSON.toJSON(function); + //JSONObject functionJSONObject = (JSONObject) JSON.toJSON(function.toString()) ; + String functionId = functionJSONObject.getString("functionId"); + List collect = resultArray.stream().filter(item -> Objects.equals(((JSONObject) JSON.toJSON(item)).getString("device"), device.getString("id"))).collect(Collectors.toList()); + if (collect.size() == UniversalEnum.ZERO.getNumber()) { + JSONObject result = new JSONObject(); + result.put("device", device.getString("id")); + result.put("deviceType", device.getInteger("deviceType")); + result.put("functionId", functionId); + result.put("result", AjaxResult.error()); + resultArray.add(result); + } else { + for (int i = UniversalEnum.ZERO.getNumber(); i < resultArray.size(); i++) { + JSONObject jsonObject = (JSONObject) JSON.toJSON(resultArray.get(i)); + if (!Objects.equals(jsonObject.getString("device"), device.getString("id"))) { + JSONObject result = jsonObject.getJSONObject("result"); + if (!Objects.equals(result.getString("code"), UniversalEnum.TWO_HUNDRED.getValue())) { + break; + } else { + result.put("code", UniversalEnum.FIVE_HUNDRED.getValue()); + jsonObject.put("result", result); + resultArray.add(i, jsonObject); + } + } else { + break; + } + } + + } + } + } else { + + JSONObject mdJSONObject = (JSONObject) JSON.toJSON(getDeviceLatestProperty(iotDeviceId, UniversalEnum.MD.getValue()).get("data")); + + String mdValue = mdJSONObject.getString("value"); + + JSONObject tmJSONObject = (JSONObject) JSON.toJSON(getDeviceLatestProperty(iotDeviceId, UniversalEnum.TM.getValue()).get("data")); + + String tmValue = tmJSONObject.getString("value"); + + for (Object function : functions) { + JSONObject functionJSONObject = (JSONObject) JSON.toJSON(function); + //JSONObject functionJSONObject = (JSONObject) JSON.toJSON(function.toString()) ; + String functionId = functionJSONObject.getString("functionId"); + if (continueToExecute) { + JSONObject jsonObject = functionJSONObject.getJSONObject("params") != null ? functionJSONObject.getJSONObject("params") : new JSONObject(); + JSONObject result = getResult(device, iotDeviceId, functionId, jsonObject); + resultArray.add(result); + AjaxResult ajaxResult = (AjaxResult) result.get("result"); + if (!Objects.equals(String.valueOf(ajaxResult.get("code")), UniversalEnum.TWO_HUNDRED.getValue())) { + continueToExecute = false; + if (Objects.equals(device.getString("deviceType"), UniversalEnum.FIFTEEN.getValue())) { + return AjaxResult.error(UniversalEnum.TWO_HUNDRED.getNumber(), UniversalEnum.FIVE_HUNDRED.getValue()); + } + } + } else { + List collect = resultArray.stream().filter(item -> Objects.equals(((JSONObject) JSON.toJSON(item)).getString("device"), device.getString("id"))).collect(Collectors.toList()); + if (collect.size() == UniversalEnum.ZERO.getNumber()) { + JSONObject result = new JSONObject(); + result.put("device", device.getString("id")); + result.put("deviceType", device.getInteger("deviceType")); + result.put("functionId", functionId); + result.put("result", AjaxResult.error()); + resultArray.add(result); + } else { + for (int i = UniversalEnum.ZERO.getNumber(); i < resultArray.size(); i++) { + JSONObject jsonObject = (JSONObject) JSON.toJSON(resultArray.get(i)); + if (!Objects.equals(jsonObject.getString("device"), device.getString("id"))) { + JSONObject result = jsonObject.getJSONObject("result"); + if (!Objects.equals(result.getString("code"), UniversalEnum.TWO_HUNDRED.getValue())) { + break; + } else { + result.put("code", UniversalEnum.FIVE_HUNDRED.getValue()); + jsonObject.put("result", result); + resultArray.add(i, jsonObject); + } + } else { + break; + } + } + + } + if (Objects.equals(functionId, UniversalEnum.SETMD.getValue())) { + JSONObject jsonObjectMD = new JSONObject(); + jsonObjectMD.put(UniversalEnum.SET.getValue(), mdValue); + getAjaxResult(iotDeviceId, functionId, jsonObjectMD.toJavaObject(new TypeReference>() { + })); + } + if (Objects.equals(functionId, UniversalEnum.SETTM.getValue())) { + JSONObject jsonObjectTM = new JSONObject(); + jsonObjectTM.put(UniversalEnum.SET.getValue(), tmValue); + getAjaxResult(iotDeviceId, functionId, jsonObjectTM.toJavaObject(new TypeReference>() { + })); + } + } + } + } + } else { + + for (Object function : functions) { + JSONObject functionJSONObject = (JSONObject) JSON.toJSON(function); + //JSONObject functionJSONObject = (JSONObject) JSON.toJSON(function.toString()) ; + String functionId = functionJSONObject.getString("functionId"); + if (continueToExecute) { + JSONObject jsonObject = functionJSONObject.getJSONObject("params") != null ? functionJSONObject.getJSONObject("params") : new JSONObject(); + JSONObject result = getResult(device, iotDeviceId, functionId, jsonObject); + resultArray.add(result); + AjaxResult ajaxResult = (AjaxResult) result.get("result"); + if (!Objects.equals(String.valueOf(ajaxResult.get("code")), UniversalEnum.TWO_HUNDRED.getValue())) { + continueToExecute = false; + if (Objects.equals(device.getString("deviceType"), UniversalEnum.FIFTEEN.getValue())) { + return AjaxResult.error(UniversalEnum.TWO_HUNDRED.getNumber(), UniversalEnum.FIVE_HUNDRED.getValue()); + } + } } else { - //return AjaxResult.success(resultArray); + JSONObject result = new JSONObject(); + result.put("device", device.getString("id")); + result.put("deviceType", device.getInteger("deviceType")); + result.put("functionId", functionId); + result.put("result", AjaxResult.error()); + resultArray.add(result); } } } + } return AjaxResult.success(resultArray); } @@ -567,9 +682,9 @@ public class DcDeviceController extends BaseController { value.keySet().forEach(item -> { ajaxResult.put(item, value.getString(item)); }); - if (Objects.equals(String.valueOf(ajaxResult.get("retCode")), UniversalEnum.ZERO.getValue())){ + if (Objects.equals(String.valueOf(ajaxResult.get("retCode")), UniversalEnum.ZERO.getValue())) { ajaxResult.put("code", UniversalEnum.TWO_HUNDRED.getNumber()); - }else { + } else { ajaxResult.put("code", UniversalEnum.FIVE_HUNDRED.getNumber()); } @@ -798,8 +913,8 @@ public class DcDeviceController extends BaseController { results.sort(Comparator.comparing(hashMap -> hashMap.get("timestamp"))); return AjaxResult.success(results); } - if (UniversalEnum.THREE.getValue().equals(deviceType)||UniversalEnum.SEVENTEEN.getValue().equals(deviceType)|| - UniversalEnum.FIFTEEN.getValue().equals(deviceType)){ //气象预警/ups设备/太阳能板 + if (UniversalEnum.THREE.getValue().equals(deviceType) || UniversalEnum.SEVENTEEN.getValue().equals(deviceType) || + UniversalEnum.FIFTEEN.getValue().equals(deviceType)) { //气象预警/ups设备/太阳能板 JSONObject data = (JSONObject) ajaxResult.get("data"); JSONArray dataValue = (JSONArray) data.get("data"); List jsonObjectList = dataValue.toJavaList(JSONObject.class); @@ -831,10 +946,11 @@ public class DcDeviceController extends BaseController { String key = configService.selectConfigByKey(UniversalEnum.SBX_FUN_KL.getValue());//密钥 return AjaxResult.success(key.equals(secretKey)); } + //设备分析 @PostMapping("/properties/deviceAnalysis") public AjaxResult deviceAnalysis(@RequestBody HashMap map) throws IOException, HttpException { - if (map==null||!map.containsKey("deviceId")||!map.containsKey("deviceType") ||!map.containsKey("dateTime")){ + if (map == null || !map.containsKey("deviceId") || !map.containsKey("deviceType") || !map.containsKey("dateTime")) { return AjaxResult.error(UniversalEnum.PARAMETER_ERROR.getValue()); } String type = map.get("deviceType").toString();//设备类型 @@ -860,7 +976,7 @@ public class DcDeviceController extends BaseController { props.put("sorts[0].order", "asc"); props.put("sorts[0].name", "timestamp"); List> mapList = dcDeviceService.selectDeviceParameterProperties(dcDevice);//属性的参数信息 - List resultsMapValue=new ArrayList<>(); + List resultsMapValue = new ArrayList<>(); for (HashMap hashMap : mapList) { HashMap resultsMap = new HashMap<>(); String name = hashMap.get("name").toString();//属性名称 diff --git a/zc-business/src/main/java/com/zc/business/controller/DcEventProcessController.java b/zc-business/src/main/java/com/zc/business/controller/DcEventProcessController.java index 00cb1f23..4b0317f4 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcEventProcessController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcEventProcessController.java @@ -112,13 +112,13 @@ public class DcEventProcessController extends BaseController } } if (dcEvent.getEventType() == 1 || dcEvent.getEventType() == 2 || dcEvent.getEventType() == 6){ - if (dcEventProcess.getProcessId() == 3) { + if (dcEventProcess.getProcessId() != null && dcEventProcess.getProcessId() == 3) { //中间库 更新清障到达时间 MdEvent mdEvent = new MdEvent(); mdEvent.setFusionId(dcEventProcess.getEventId()); mdEvent.setClearArriveTime(new Date()); middleDatabaseService.updateMiddleDatabaseEvent(mdEvent); - } else if (dcEventProcess.getProcessId() == 6){ + } else if (dcEventProcess.getProcessId() != null && dcEventProcess.getProcessId() == 6){ //中间库 更新清障结束时间 MdEvent mdEvent = new MdEvent(); mdEvent.setFusionId(dcEventProcess.getEventId()); diff --git a/zc-business/src/main/java/com/zc/business/controller/DeviceStatus.java b/zc-business/src/main/java/com/zc/business/controller/DeviceStatus.java index 2d3b050c..070ecd19 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DeviceStatus.java +++ b/zc-business/src/main/java/com/zc/business/controller/DeviceStatus.java @@ -15,7 +15,6 @@ import com.zc.business.service.impl.StatusService; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.scheduling.annotation.EnableScheduling; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.io.BufferedReader; @@ -23,7 +22,9 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.net.InetAddress; +import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; import java.util.ArrayList; @@ -103,7 +104,8 @@ public class DeviceStatus { //@Scheduled(cron = "0 30 23 * * ?") public void periodicDataClearing() { StatusService statusService = SpringUtils.getBean(StatusService.class); - LocalDateTime startTime = LocalDateTime.now().minusMonths(UniversalEnum.THREE.getNumber()); + LocalDateTime startTime = LocalDateTime.of(LocalDate.now().minusMonths(UniversalEnum.THREE.getNumber()), LocalTime.MIN); + ; Status status = new Status(); status.setStartTime(startTime); statusService.delStatusByTime(status); diff --git a/zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java b/zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java index d1e14635..54d91195 100644 --- a/zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java +++ b/zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java @@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Objects; @@ -84,7 +85,9 @@ public class WeatherForecastController extends BaseController { JSONArray data = (JSONArray) JSON.toJSON(ajaxResult.get("data")); if (data.size() > UniversalEnum.ZERO.getNumber()) { - List dcNoStakeWarningTables = noStakeWarningTableService.listDcNoStakeWarningTable(new DcNoStakeWarningTable(), null, null); + DcNoStakeWarningTable noStakeWarningTable = new DcNoStakeWarningTable(); + noStakeWarningTable.setWarningType(UniversalEnum.TWO.getValue()); + List dcNoStakeWarningTables = noStakeWarningTableService.listDcNoStakeWarningTable(noStakeWarningTable, null, null); data.forEach(item -> { JSONObject jsonObject = (JSONObject) JSON.toJSON(item); String earlyWorningSignal = jsonObject.getString("earlyWorningSignal"); @@ -256,150 +259,9 @@ public class WeatherForecastController extends BaseController { JSONObject jsonResult = JSONObject.parseObject(response.body().string()); if (jsonResult.getInteger("code") == UniversalEnum.TWO_HUNDRED.getNumber()) { JSONArray data = jsonResult.getJSONArray("data"); - JSONArray jsonArray = new JSONArray(); - for (int i = UniversalEnum.ZERO.getNumber(); i < data.size(); i++) { - - JSONObject jsonObject = (JSONObject) JSON.toJSON(data.get(i)); - String pre = jsonObject.getString("pre"); - if (Objects.equals(pre, UniversalEnum.ZERO.getValue())) { - - String visLevel = jsonObject.getString("visLevel"); - - if (Objects.equals(visLevel, UniversalEnum.ONE.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber()); - } else if (Objects.equals(visLevel, UniversalEnum.TWO.getValue()) || Objects.equals(visLevel, UniversalEnum.THREE.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.CLOUDY.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.CLOUDY.getNumber()); - } else if (Objects.equals(visLevel, UniversalEnum.FOUR.getValue()) || Objects.equals(visLevel, UniversalEnum.FIVE.getValue()) || Objects.equals(visLevel, UniversalEnum.SIX.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.OVERCAST_SKY.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.OVERCAST_SKY.getNumber()); - } - } else { - - String preLevel = jsonObject.getString("preLevel"); - String pph = jsonObject.getString("pph"); - - switch (preLevel) { - case "0": - jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber()); - break; - case "1": - case "2": - if (Objects.equals(pph, UniversalEnum.ONE.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.SPIT.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.SPIT.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.SLEET.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.SLEET.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.LIGHT_SNOW.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.LIGHT_SNOW.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.FREEZING_RAIN.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.FREEZING_RAIN.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber()); - } - break; - case "3": - if (Objects.equals(pph, UniversalEnum.ONE.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.MODERATE_RAIN.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.MODERATE_RAIN.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.SLEET.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.SLEET.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.MODERATE_SNOW.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.MODERATE_SNOW.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.FREEZING_RAIN.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.FREEZING_RAIN.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber()); - } - break; - case "4": - if (Objects.equals(pph, UniversalEnum.ONE.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.HEAVY_RAIN.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.HEAVY_RAIN.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.SLEET.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.SLEET.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.HEAVY_SNOW.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.HEAVY_SNOW.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.FREEZING_RAIN.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.FREEZING_RAIN.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber()); - } - break; - case "5": - if (Objects.equals(pph, UniversalEnum.ONE.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.RAINSTORM.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.RAINSTORM.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.SLEET.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.SLEET.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.BLIZZARD.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.BLIZZARD.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.FREEZING_RAIN.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.FREEZING_RAIN.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber()); - } - break; - case "6": - if (Objects.equals(pph, UniversalEnum.ONE.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.BIG_RAINSTORM.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.BIG_RAINSTORM.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.SLEET.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.SLEET.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.BIG_BLIZZARD.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.BIG_BLIZZARD.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.FREEZING_RAIN.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.FREEZING_RAIN.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber()); - } - break; - case "7": - if (Objects.equals(pph, UniversalEnum.ONE.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.EXTREMELY_HEAVY_RAINSTORM.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.EXTREMELY_HEAVY_RAINSTORM.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.SLEET.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.SLEET.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.HEAVY_SNOWSTORM.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.HEAVY_SNOWSTORM.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.FREEZING_RAIN.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.FREEZING_RAIN.getNumber()); - } else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) { - jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue()); - jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber()); - } - break; - } - - } - jsonArray.add(i, jsonObject); - } ; + JSONArray jsonArray = processingWeatherData(data); + if (jsonArray.size() != UniversalEnum.ZERO.getNumber()) { redisCache.deleteObject(UniversalEnum.CURRENT_WEATHER_AND_FORECAST_INFORMATION_SINGLE_WORD.getValue() + numStake); redisCache.setCacheObject(UniversalEnum.CURRENT_WEATHER_AND_FORECAST_INFORMATION_SINGLE_WORD.getValue() + numStake, jsonArray); @@ -409,7 +271,8 @@ public class WeatherForecastController extends BaseController { return AjaxResult.success(cacheObject); } } else { - return AjaxResult.error(jsonResult.getInteger("code"), UniversalEnum.REQUEST_FAILED.getValue()); + JSONArray cacheObject = redisCache.getCacheObject(UniversalEnum.CURRENT_WEATHER_AND_FORECAST_INFORMATION_SINGLE_WORD.getValue() + numStake); + return AjaxResult.success(cacheObject); } } } catch (Exception ignored) { @@ -417,9 +280,171 @@ public class WeatherForecastController extends BaseController { logger.error(String.valueOf(ignored)); } - return AjaxResult.error(UniversalEnum.REQUEST_FAILED.getValue()); + JSONArray cacheObject = redisCache.getCacheObject(UniversalEnum.CURRENT_WEATHER_AND_FORECAST_INFORMATION_SINGLE_WORD.getValue() + numStake); + return AjaxResult.success(cacheObject); } + public JSONArray processingWeatherData(JSONArray data) { + JSONArray jsonArray = new JSONArray(); + for (int i = UniversalEnum.ZERO.getNumber(); i < data.size(); i++) { + + JSONObject jsonObject = (JSONObject) JSON.toJSON(data.get(i)); + String pre = jsonObject.getString("pre"); + if (Objects.equals(pre, UniversalEnum.ZERO.getValue()) || Double.parseDouble(pre) == UniversalEnum.ZERO.getNumber()) { + + String visLevel = jsonObject.getString("visLevel"); + + Double rhu = jsonObject.getDouble("rhu"); + + if (rhu > UniversalEnum.NINETY.getNumber()) { + jsonObject.put("weatherCondition", UniversalEnum.OVERCAST_SKY.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.OVERCAST_SKY.getNumber()); + } else { + if (Objects.equals(visLevel, UniversalEnum.ONE.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber()); + } else if (Objects.equals(visLevel, UniversalEnum.TWO.getValue()) || Objects.equals(visLevel, UniversalEnum.THREE.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.CLOUDY.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.CLOUDY.getNumber()); + } else if (Objects.equals(visLevel, UniversalEnum.FOUR.getValue()) || Objects.equals(visLevel, UniversalEnum.FIVE.getValue()) || Objects.equals(visLevel, UniversalEnum.SIX.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.OVERCAST_SKY.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.OVERCAST_SKY.getNumber()); + } + } + } else { + + String preLevel = jsonObject.getString("preLevel"); + String pph = jsonObject.getString("pph"); + + switch (preLevel) { + case "0": + jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber()); + break; + case "1": + case "2": + if (Objects.equals(pph, UniversalEnum.ONE.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.SPIT.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.SPIT.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.SLEET.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.SLEET.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.LIGHT_SNOW.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.LIGHT_SNOW.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.FREEZING_RAIN.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.FREEZING_RAIN.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber()); + } + break; + case "3": + if (Objects.equals(pph, UniversalEnum.ONE.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.MODERATE_RAIN.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.MODERATE_RAIN.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.SLEET.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.SLEET.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.MODERATE_SNOW.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.MODERATE_SNOW.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.FREEZING_RAIN.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.FREEZING_RAIN.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber()); + } + break; + case "4": + if (Objects.equals(pph, UniversalEnum.ONE.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.HEAVY_RAIN.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.HEAVY_RAIN.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.SLEET.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.SLEET.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.HEAVY_SNOW.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.HEAVY_SNOW.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.FREEZING_RAIN.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.FREEZING_RAIN.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber()); + } + break; + case "5": + if (Objects.equals(pph, UniversalEnum.ONE.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.RAINSTORM.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.RAINSTORM.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.SLEET.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.SLEET.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.BLIZZARD.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.BLIZZARD.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.FREEZING_RAIN.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.FREEZING_RAIN.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber()); + } + break; + case "6": + if (Objects.equals(pph, UniversalEnum.ONE.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.BIG_RAINSTORM.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.BIG_RAINSTORM.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.SLEET.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.SLEET.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.BIG_BLIZZARD.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.BIG_BLIZZARD.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.FREEZING_RAIN.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.FREEZING_RAIN.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber()); + } + break; + case "7": + if (Objects.equals(pph, UniversalEnum.ONE.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.EXTREMELY_HEAVY_RAINSTORM.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.EXTREMELY_HEAVY_RAINSTORM.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.TWO.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.SLEET.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.SLEET.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.THREE.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.HEAVY_SNOWSTORM.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.HEAVY_SNOWSTORM.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.FOUR.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.FREEZING_RAIN.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.FREEZING_RAIN.getNumber()); + } else if (Objects.equals(pph, UniversalEnum.ZERO.getValue())) { + jsonObject.put("weatherCondition", UniversalEnum.CLEAR_WEATHER.getValue()); + jsonObject.put("weatherConditionCode", UniversalEnum.CLEAR_WEATHER.getNumber()); + } + break; + } + + } + JSONArray forecastList = jsonObject.getJSONArray("forecastList"); + if (forecastList != null && forecastList.size() != UniversalEnum.ZERO.getNumber()) { + + jsonObject.put("forecastList", processingWeatherData(forecastList)); + } + + jsonArray.add(i, jsonObject); + } + return jsonArray; + } + + public static int findNearestMultipleOfFive(int number) { // 计算除以5的余数 int remainder = number % UniversalEnum.FIVE.getNumber(); @@ -517,14 +542,14 @@ public class WeatherForecastController extends BaseController { // return AjaxResult.success(redisCache.getCacheList("currentWeatherWarningInformationQuery")); //} } else { - return AjaxResult.error(jsonResult.getInteger("code"), UniversalEnum.REQUEST_FAILED.getValue()); + return AjaxResult.success(new ArrayList<>()); } } } catch (Exception ignored) { } - return AjaxResult.error(UniversalEnum.REQUEST_FAILED.getValue()); + return AjaxResult.success(new ArrayList<>()); } diff --git a/zc-business/src/main/java/com/zc/business/domain/ComprehensiveIndexQuery.java b/zc-business/src/main/java/com/zc/business/domain/ComprehensiveIndexQuery.java index 7e7620a2..c0ef7b69 100644 --- a/zc-business/src/main/java/com/zc/business/domain/ComprehensiveIndexQuery.java +++ b/zc-business/src/main/java/com/zc/business/domain/ComprehensiveIndexQuery.java @@ -34,4 +34,6 @@ public class ComprehensiveIndexQuery { private Integer crowdingRate; private Integer periodType; private String startDate; + private String endDate; + } diff --git a/zc-business/src/main/java/com/zc/business/domain/DcBatchFunctionsJobGroup.java b/zc-business/src/main/java/com/zc/business/domain/DcBatchFunctionsJobGroup.java index 1945506a..b1e67209 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcBatchFunctionsJobGroup.java +++ b/zc-business/src/main/java/com/zc/business/domain/DcBatchFunctionsJobGroup.java @@ -1,12 +1,15 @@ package com.zc.business.domain; import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.util.ArrayList; import java.util.Date; +import java.util.List; @Data @ApiModel(value = "DcBatchFunctionsJobGroup", description = "定时任务组实体") @@ -30,4 +33,6 @@ public class DcBatchFunctionsJobGroup { private Date updateBy; @ApiModelProperty("修改时间") private Date updateTime; + @TableField(exist = false) + private List dcBatchFunctionsJobList; } diff --git a/zc-business/src/main/java/com/zc/business/domain/OnlineLog.java b/zc-business/src/main/java/com/zc/business/domain/OnlineLog.java new file mode 100644 index 00000000..a94b0dd4 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/domain/OnlineLog.java @@ -0,0 +1,236 @@ +package com.zc.business.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.utils.DateUtils; +import com.zc.business.enums.UniversalEnum; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.time.LocalDateTime; +import java.util.Arrays; +import java.util.Date; + +public class OnlineLog implements Serializable { + private static final long serialVersionUID = 1L; + private long id; + private Long deviceId; + private String deviceIp; + private String deviceName; + private String stakeMark; + private String deviceStatus; + private String networkQuality;//网络质量 + private int sendCount;//发送数 + private int receiveCount;//返回数 + private int lossCount;//丢包数 + private String lossRate;//丢包率 + private double rttAvg;//平均往返时延 + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime monitorTime; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public Long getDeviceId() { + return deviceId; + } + + public void setDeviceId(Long deviceId) { + this.deviceId = deviceId; + } + + public String getDeviceIp() { + return deviceIp; + } + + public void setDeviceIp(String deviceIp) { + this.deviceIp = deviceIp; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getStakeMark() { + return stakeMark; + } + + public void setStakeMark(String stakeMark) { + this.stakeMark = stakeMark; + } + + public String getDeviceStatus() { + return deviceStatus; + } + + public void setDeviceStatus(String deviceStatus) { + this.deviceStatus = deviceStatus; + } + + public String getNetworkQuality() { + return networkQuality; + } + + public void setNetworkQuality(String networkQuality) { + this.networkQuality = networkQuality; + } + + public int getSendCount() { + return sendCount; + } + + public void setSendCount(int sendCount) { + this.sendCount = sendCount; + } + + public int getReceiveCount() { + return receiveCount; + } + + public void setReceiveCount(int receiveCount) { + this.receiveCount = receiveCount; + } + + public int getLossCount() { + return lossCount; + } + + public void setLossCount(int lossCount) { + this.lossCount = lossCount; + } + + public String getLossRate() { + return lossRate; + } + + public void setLossRate(String lossRate) { + this.lossRate = lossRate; + } + + public double getRttAvg() { + return rttAvg; + } + + public void setRttAvg(double rttAvg) { + this.rttAvg = rttAvg; + } + + public LocalDateTime getMonitorTime() { + return monitorTime; + } + + public void setMonitorTime(LocalDateTime monitorTime) { + this.monitorTime = monitorTime; + } + + @Override + public String toString() { + return "OnlineLog{" + + "id=" + id + + ", deviceId=" + deviceId + + ", deviceIp='" + deviceIp + '\'' + + ", deviceName='" + deviceName + '\'' + + ", stakeMark='" + stakeMark + '\'' + + ", deviceStatus='" + deviceStatus + '\'' + + ", networkQuality='" + networkQuality + '\'' + + ", sendCount=" + sendCount + + ", receiveCount=" + receiveCount + + ", lossCount=" + lossCount + + ", lossRate='" + lossRate + '\'' + + ", rttAvg=" + rttAvg + + ", monitorTime=" + monitorTime + + '}'; + } + + public static class LogBuilder{ + OnlineLog onlineLog = new OnlineLog(); + public LogBuilder setDeviceStatus(String deviceStatus) { + onlineLog.setDeviceStatus(deviceStatus); + return this; + } + public LogBuilder setSendCount(int sendCount) { + onlineLog.setSendCount(sendCount); + return this; + } + public LogBuilder setReceiveCount(int receiveCount) { + onlineLog.setReceiveCount(receiveCount); + return this; + } + public LogBuilder setRttAvg(double rttAvg) { + onlineLog.setRttAvg(rttAvg); + return this; + } + public OnlineLog build(DcDevice device) { + onlineLog.setDeviceId(device.getId()); + onlineLog.setDeviceIp(device.getDeviceIp()); + onlineLog.setDeviceName(device.getDeviceName()); + onlineLog.setStakeMark(device.getStakeMark()); + String lossRate = String.format("%.2f%%", (double) onlineLog.getLossCount() / onlineLog.getSendCount() * 100); + onlineLog.setLossRate(lossRate); + double rttAvg = onlineLog.getRttAvg(); + if(rttAvg > 0 && rttAvg <= 30){ + onlineLog.setNetworkQuality(NetworkQuality.GOOD.getValue()); + }else if(rttAvg >30 && rttAvg <= 100){ + onlineLog.setNetworkQuality(NetworkQuality.NORMAL.getValue()); + }else { + onlineLog.setNetworkQuality(NetworkQuality.BAD.getValue()); + } + onlineLog.setLossCount(onlineLog.getSendCount() - onlineLog.getReceiveCount()); + onlineLog.setMonitorTime(LocalDateTime.now()); + return onlineLog; + } + public OnlineLog buildBad(DcDevice device){ + onlineLog.setDeviceId(device.getId()); + onlineLog.setDeviceIp(device.getDeviceIp()); + onlineLog.setDeviceName(device.getDeviceName()); + onlineLog.setStakeMark(device.getStakeMark()); + onlineLog.setNetworkQuality(NetworkQuality.BAD.getValue()); + onlineLog.setMonitorTime(LocalDateTime.now()); + onlineLog.setSendCount(4); + onlineLog.setReceiveCount(0); + onlineLog.setLossCount(4); + onlineLog.setLossRate("100.00%"); + onlineLog.setRttAvg(0); + onlineLog.setDeviceStatus(UniversalEnum.ZERO.getValue()); + return onlineLog; + } + public OnlineLog buildGood(DcDevice device){ + onlineLog.setDeviceId(device.getId()); + onlineLog.setDeviceIp(device.getDeviceIp()); + onlineLog.setDeviceName(device.getDeviceName()); + onlineLog.setStakeMark(device.getStakeMark()); + onlineLog.setNetworkQuality(NetworkQuality.GOOD.getValue()); + onlineLog.setMonitorTime(LocalDateTime.now()); + onlineLog.setSendCount(4); + onlineLog.setReceiveCount(4); + onlineLog.setLossCount(0); + onlineLog.setLossRate("0.00%"); + onlineLog.setRttAvg(30); + onlineLog.setDeviceStatus(UniversalEnum.ONE.getValue()); + return onlineLog; + } + } + enum NetworkQuality{ + GOOD("优"), + NORMAL("良"), + BAD("差"); + private final String value; + String getValue() { + return value; + } + NetworkQuality(String value) { + this.value = value; + } + } + +} diff --git a/zc-business/src/main/java/com/zc/business/domain/OnlineSum.java b/zc-business/src/main/java/com/zc/business/domain/OnlineSum.java new file mode 100644 index 00000000..2146b6f2 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/domain/OnlineSum.java @@ -0,0 +1,186 @@ +package com.zc.business.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import org.springframework.format.annotation.DateTimeFormat; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.Date; + +public class OnlineSum implements java.io.Serializable { + private static final long serialVersionUID = 1L; + private long id; + private long deviceId; + private String deviceName; + private String deviceIp; + private String stakeMark; + private String deviceStatus; + private int sendCount;//发送数 + private int receiveCount;//返回数 + private int lossCount;//丢包数 + private String lossRate;//丢包率 + private double rttAvg;//平均往返时延 + private String networkQuality;//网络质量 + @DateTimeFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd") + private Date statisticalDate;//统计日期 + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public Long getDeviceId() { + return deviceId; + } + + public void setDeviceId(Long deviceId) { + this.deviceId = deviceId; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getDeviceIp() { + return deviceIp; + } + + public void setDeviceIp(String deviceIp) { + this.deviceIp = deviceIp; + } + + public String getStakeMark() { + return stakeMark; + } + + public void setStakeMark(String stakeMark) { + this.stakeMark = stakeMark; + } + + public String getDeviceStatus() { + return deviceStatus; + } + + public void setDeviceStatus(String deviceStatus) { + this.deviceStatus = deviceStatus; + } + + public int getSendCount() { + return sendCount; + } + + public void setSendCount(int sendCount) { + this.sendCount = sendCount; + } + + public int getReceiveCount() { + return receiveCount; + } + + public void setReceiveCount(int receiveCount) { + this.receiveCount = receiveCount; + } + + public int getLossCount() { + return lossCount; + } + + public void setLossCount(int lossCount) { + this.lossCount = lossCount; + } + + public String getLossRate() { + return lossRate; + } + + public void setLossRate(String lossRate) { + this.lossRate = lossRate; + } + + public double getRttAvg() { + return rttAvg; + } + + public void setRttAvg(double rttAvg) { + this.rttAvg = rttAvg; + } + + public String getNetworkQuality() { + return networkQuality; + } + + public void setNetworkQuality(String networkQuality) { + this.networkQuality = networkQuality; + } + + public Date getStatisticalDate() { + return statisticalDate; + } + + public void setStatisticalDate(Date statisticalDate) { + this.statisticalDate = statisticalDate; + } + + @Override + public String toString() { + return "OnlineSum{" + + "id=" + id + + ", deviceId='" + deviceId + '\'' + + ", deviceName='" + deviceName + '\'' + + ", deviceIp='" + deviceIp + '\'' + + ", stakeMark='" + stakeMark + '\'' + + ", deviceStatus='" + deviceStatus + '\'' + + ", sendCount=" + sendCount + + ", receiveCount=" + receiveCount + + ", lossCount=" + lossCount + + ", lossRate='" + lossRate + '\'' + + ", rttAvg=" + rttAvg + + ", networkQuality='" + networkQuality + '\'' + + ", statisticalDate=" + statisticalDate + + '}'; + } + + public OnlineSum copyFromLog(OnlineLog onlineLog) { + this.deviceId = onlineLog.getDeviceId(); + this.deviceName = onlineLog.getDeviceName(); + this.deviceIp = onlineLog.getDeviceIp(); + this.stakeMark = onlineLog.getStakeMark(); + this.deviceStatus = onlineLog.getDeviceStatus(); + this.sendCount = onlineLog.getSendCount(); + this.receiveCount = onlineLog.getReceiveCount(); + this.lossCount = onlineLog.getLossCount(); + this.lossRate = onlineLog.getLossRate(); + this.rttAvg = onlineLog.getRttAvg(); + this.networkQuality = onlineLog.getNetworkQuality(); + this.statisticalDate = new Date(); + return this; + } + + public OnlineSum incrementSummary(OnlineLog onlineLog) { + double rtt = this.rttAvg*this.sendCount+onlineLog.getRttAvg()*onlineLog.getSendCount(); + this.deviceStatus = onlineLog.getDeviceStatus(); + this.sendCount += onlineLog.getSendCount(); + this.receiveCount += onlineLog.getReceiveCount(); + this.lossCount += onlineLog.getLossCount(); + this.lossRate = String.format("%.2f%%", (this.sendCount==0?0:(double)this.lossCount/this.sendCount)*100); + BigDecimal bd = new BigDecimal(Double.toString(this.sendCount==0?0:rtt/this.sendCount)); + bd = bd.setScale(2, RoundingMode.HALF_UP); + this.rttAvg =bd.doubleValue(); + if(this.rttAvg > 0 && this.rttAvg <= 30){ + this.networkQuality = OnlineLog.NetworkQuality.GOOD.getValue(); + }else if(this.rttAvg >30 && this.rttAvg <= 100){ + this.networkQuality = OnlineLog.NetworkQuality.NORMAL.getValue(); + }else { + this.networkQuality = OnlineLog.NetworkQuality.BAD.getValue(); + } + return this; + } +} diff --git a/zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java b/zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java index bf575f57..00a79b0e 100644 --- a/zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java +++ b/zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java @@ -772,6 +772,36 @@ public enum UniversalEnum { // 内容 CONTENT(0, "内容"), + // 关闭 + OFF(0, "关闭"), + + // 打开 + UNPACK(0, "打开"), + + // 常亮 + STEADY_ON(0, "常亮"), + + // 间隔100ms闪烁 + BLINK_AT_AN_INTERVAL_OF_100_MS(0, "间隔100ms闪烁"), + + // 间隔200ms闪烁 + BLINK_AT_AN_INTERVAL_OF_200_MS(0, "间隔200ms闪烁"), + + // 间隔500ms闪烁 + BLINK_AT_AN_INTERVAL_OF_500_MS(0, "间隔500ms闪烁"), + + // 2次闪烁 + DOUBLE_FLICKER(0, "2次闪烁"), + + // SOS + SOS(0, "SOS"), + + // 自定义闪烁时间 + CUSTOMIZE_THE_BLINKING_TIME(0, "自定义闪烁时间"), + + // 模式 + MODE(0, "模式"), + // 一般 NORMAL(0, "一般"), @@ -1162,12 +1192,18 @@ public enum UniversalEnum { // SETMD SETMD(0, "SETMD"), + // MD + MD(0, "MD"), + // ASKMD ASKMD(0, "ASKMD"), // SETTM SETTM(0, "SETTM"), + // TM + TM(0, "TM"), + // ASKTM ASKTM(0, "ASKTM"), @@ -1369,6 +1405,9 @@ public enum UniversalEnum { // 70 SEVENTY(70, "70"), + // 90 + NINETY(90, "90"), + // 91 NINETY_ONE(91, "91"), @@ -2064,6 +2103,15 @@ public enum UniversalEnum { // 行车诱导功能码 01 ZERO_ONE(0, "01"), + // 行车诱导功能码 02 + ZERO_TWO(0, "02"), + + // 行车诱导功能码 03 + ZERO_THREE(0, "03"), + + // 行车诱导功能码 04 + ZERO_FOUR(0, "04"), + // 行车诱导功能码 0b ZERO_B(0, "0b"), diff --git a/zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java b/zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java index ff8670b4..0ccd7215 100644 --- a/zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java +++ b/zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java @@ -81,6 +81,7 @@ public class OperationLogAspect { put(UniversalEnum.THREE_C.getValue(), UniversalEnum.READ_THE_CURRENT_DEVICE_STATUS.getValue()); }}); put(UniversalEnum.THIRTEEN.getValue(), new HashMap() {{ + put("102", "设备开关"); }}); put(UniversalEnum.FOURTEEN.getValue(), new HashMap() {{ }}); @@ -93,6 +94,7 @@ public class OperationLogAspect { put(UniversalEnum.A_SIX.getValue(), UniversalEnum.QUERY_DATA.getValue()); }}); put(UniversalEnum.SIXTEEN.getValue(), new HashMap() {{ + put("102", "设备开关"); }}); }}; @@ -104,7 +106,7 @@ public class OperationLogAspect { @AfterThrowing(value = "@annotation(operationLog)", throwing = "e") public void AfterThrowing(JoinPoint joinPoint, OperationLog operationLog, Exception e) throws Throwable { - around((ProceedingJoinPoint) joinPoint, operationLog, UniversalEnum.ONE.getValue(), null, e); + around((ProceedingJoinPoint) joinPoint, operationLog, UniversalEnum.ONE.getValue(), AjaxResult.error(), e); } public void around(ProceedingJoinPoint joinPoint, OperationLog operationLog, String state, Object jsonResult, Exception exception) throws Throwable { @@ -208,21 +210,241 @@ public class OperationLogAspect { return; } - remark.append(deviceName); - String hashMap = Objects.equals(deviceType, UniversalEnum.FIVE.getValue()) ? - UniversalEnum.RELEASE_VOICE_BROADCAST.getValue() : - String.valueOf( - ((HashMap) (DEVICEFUNCTIONNAME.get(deviceType))) - .get(functionId) == null ? - UniversalEnum.UNKNOWN_METHOD.getValue() : - ((HashMap) (DEVICEFUNCTIONNAME.get(deviceType))) - .get(functionId)); + //String hashMap = Objects.equals(deviceType, UniversalEnum.FIVE.getValue()) ? + // UniversalEnum.RELEASE_VOICE_BROADCAST.getValue() : + // String.valueOf( + // ((HashMap) (DEVICEFUNCTIONNAME.get(deviceType))) + // .get(functionId) == null ? + // UniversalEnum.UNKNOWN_METHOD.getValue() : + // ((HashMap) (DEVICEFUNCTIONNAME.get(deviceType))) + // .get(functionId)); + //remark.append(hashMap).append(":"); - remark.append(UniversalEnum.INVOKE.getValue()).append(hashMap).append(UniversalEnum.FEATURE.getValue()); + JSONObject params = function.getJSONObject("params"); - if (i1 < functions.size() - UniversalEnum.ONE.getNumber()) { - remark.append(UniversalEnum.SEMICOLON.getValue()); + + if (Objects.equals(deviceType, UniversalEnum.TWO.getValue())) { + + //if (Objects.equals(functionId, UniversalEnum.ELEVEN.getValue())) { + // + // remark.append("文件名称:").append(params.getString("fileName")).append("、文件大小:").append(params.getString("size")).append("KB"); + // + //} else + if (Objects.equals(functionId, UniversalEnum.THIRTEEN.getValue())) { + + JSONArray parameters = params.getJSONArray("parameters"); + + for (int i2 = UniversalEnum.ZERO.getNumber(); i2 < parameters.size(); i2++) { + + remark.append(((JSONObject) JSON.toJSON(parameters.get(i2))).getString("CONTENT")); + //remark.append("文件内容:").append(((JSONObject) JSON.toJSON(parameters.get(i2))).getString("CONTENT")); + + if (i2 < parameters.size() - UniversalEnum.ONE.getNumber()) { + remark.append(UniversalEnum.SEMICOLON.getValue()); + } + } + + } + //else if (Objects.equals(functionId, UniversalEnum.ONE_B.getValue())) { + // + // remark.append("文件标识:").append(params.getString("fileId")); + // + //} + + } else if (Objects.equals(deviceType, UniversalEnum.FIVE.getValue())) { + + remark.append(params.getString("text")); + + } else if (Objects.equals(deviceType, UniversalEnum.TEN.getValue())) { + + String set = params.getString(UniversalEnum.SET.getValue()); + if (Objects.equals(functionId, UniversalEnum.SETMD.getValue())) { + + if (Objects.equals(set, UniversalEnum.ZERO.getValue())) { + + remark.append(UniversalEnum.OFF.getValue()); + + } else if (Objects.equals(set, UniversalEnum.ONE.getValue())) { + + remark.append(UniversalEnum.STEADY_ON.getValue()); + + } else if (Objects.equals(set, UniversalEnum.TWO.getValue())) { + + remark.append(UniversalEnum.BLINK_AT_AN_INTERVAL_OF_100_MS.getValue()); + + } else if (Objects.equals(set, UniversalEnum.THREE.getValue())) { + + remark.append(UniversalEnum.BLINK_AT_AN_INTERVAL_OF_200_MS.getValue()); + + } else if (Objects.equals(set, UniversalEnum.FOUR.getValue())) { + + remark.append(UniversalEnum.BLINK_AT_AN_INTERVAL_OF_500_MS.getValue()); + + } else if (Objects.equals(set, UniversalEnum.FIVE.getValue())) { + + remark.append(UniversalEnum.DOUBLE_FLICKER.getValue()); + + } else if (Objects.equals(set, UniversalEnum.SIX.getValue())) { + + remark.append(UniversalEnum.SOS.getValue()); + + } else if (Objects.equals(set, UniversalEnum.SEVEN.getValue())) { + + remark.append(UniversalEnum.CUSTOMIZE_THE_BLINKING_TIME.getValue()); + + } + + remark.append(UniversalEnum.MODE.getValue()); + + } else if (Objects.equals(functionId, UniversalEnum.SETTM.getValue())) { + + remark.append(set).append(UniversalEnum.MINUTES.getValue()); + } + + } else if (Objects.equals(deviceType, UniversalEnum.TWELVE.getValue())) { + + if (Objects.equals(functionId, UniversalEnum.FIFTY_ONE.getValue())) { + + //remark.append("模式:"); + + String mode = params.getString("mode"); + + if (Objects.equals(mode, UniversalEnum.ZERO_ZERO.getValue())) { + + remark.append("远程手动控制模式:上行:"); + String onWorkStatus = params.getString("onWorkStatus"); + String inWorkStatus = params.getString("inWorkStatus"); + + if (Objects.equals(onWorkStatus, UniversalEnum.ZERO_ZERO.getValue())) { + + remark.append("不更新状态,下行:"); + + } else if (Objects.equals(onWorkStatus, UniversalEnum.ZERO_ONE.getValue())) { + + remark.append("常亮,下行:"); + + } else if (Objects.equals(onWorkStatus, UniversalEnum.ZERO_TWO.getValue())) { + + remark.append("流水,下行:"); + + } else if (Objects.equals(onWorkStatus, UniversalEnum.ZERO_THREE.getValue())) { + + remark.append("闪烁,下行:"); + + } else if (Objects.equals(onWorkStatus, UniversalEnum.ZERO_FOUR.getValue())) { + + remark.append("关闭,下行:"); + + } + + if (Objects.equals(inWorkStatus, UniversalEnum.ZERO_ZERO.getValue())) { + + remark.append("不更新状态"); + + } else if (Objects.equals(inWorkStatus, UniversalEnum.ZERO_ONE.getValue())) { + + remark.append("常亮"); + + } else if (Objects.equals(inWorkStatus, UniversalEnum.ZERO_TWO.getValue())) { + + remark.append("流水"); + + } else if (Objects.equals(inWorkStatus, UniversalEnum.ZERO_THREE.getValue())) { + + remark.append("闪烁"); + + } else if (Objects.equals(inWorkStatus, UniversalEnum.ZERO_FOUR.getValue())) { + + remark.append("关闭"); + + } + + } else if (Objects.equals(mode, UniversalEnum.ZERO_ONE.getValue())) { + + remark.append("时间段自动控制模式:") + .append(params.getString("startDisplayTime")) + .append("-") + .append(params.getString("endDisplayTime")); + + } else if (Objects.equals(mode, UniversalEnum.ZERO_TWO.getValue())) { + + remark.append("万年历自动控制模式"); + + } else if (Objects.equals(mode, UniversalEnum.ZERO_THREE.getValue())) { + + remark.append("能见度自动控制模式"); + + } + + } else if (Objects.equals(functionId, UniversalEnum.THIRTY.getValue())) { + + String onWorkStatus = params.getString("onWorkStatus"); + String inWorkStatus = params.getString("inWorkStatus"); + + if (Objects.equals(onWorkStatus, UniversalEnum.ZERO_ZERO.getValue())) { + + remark.append("上行:不更新状态,下行:"); + + } else if (Objects.equals(onWorkStatus, UniversalEnum.ZERO_ONE.getValue())) { + + remark.append("上行:常亮,下行:"); + + } else if (Objects.equals(onWorkStatus, UniversalEnum.ZERO_TWO.getValue())) { + + remark.append("上行:流水,下行:"); + + } else if (Objects.equals(onWorkStatus, UniversalEnum.ZERO_THREE.getValue())) { + + remark.append("上行:闪烁,下行:"); + + } else if (Objects.equals(onWorkStatus, UniversalEnum.ZERO_FOUR.getValue())) { + + remark.append("上行:关闭,下行:"); + + } + + if (Objects.equals(inWorkStatus, UniversalEnum.ZERO_ZERO.getValue())) { + + remark.append("不更新状态"); + + } else if (Objects.equals(inWorkStatus, UniversalEnum.ZERO_ONE.getValue())) { + + remark.append("常亮"); + + } else if (Objects.equals(inWorkStatus, UniversalEnum.ZERO_TWO.getValue())) { + + remark.append("流水"); + + } else if (Objects.equals(inWorkStatus, UniversalEnum.ZERO_THREE.getValue())) { + + remark.append("闪烁"); + + } else if (Objects.equals(inWorkStatus, UniversalEnum.ZERO_FOUR.getValue())) { + + remark.append("关闭"); + + } + } + + } + + + //remark.append(deviceName); + + //String hashMap = Objects.equals(deviceType, UniversalEnum.FIVE.getValue()) ? + // UniversalEnum.RELEASE_VOICE_BROADCAST.getValue() : + // String.valueOf( + // ((HashMap) (DEVICEFUNCTIONNAME.get(deviceType))) + // .get(functionId) == null ? + // UniversalEnum.UNKNOWN_METHOD.getValue() : + // ((HashMap) (DEVICEFUNCTIONNAME.get(deviceType))) + // .get(functionId)); + + //remark.append(UniversalEnum.INVOKE.getValue()).append(hashMap).append(UniversalEnum.FEATURE.getValue()); + + if (i1 < functions.size() - UniversalEnum.ONE.getNumber() && !Objects.equals(deviceType, "2")) { + remark.append(UniversalEnum.COMMA.getValue()); } @@ -239,7 +461,7 @@ public class OperationLogAspect { } if (i < (devices.size() - UniversalEnum.ONE.getNumber())) { - remark.append(UniversalEnum.COMMA.getValue()); + remark.append(UniversalEnum.UNDERLINE.getValue()); } } @@ -317,6 +539,8 @@ public class OperationLogAspect { String functionId = String.valueOf(pointArgs[UniversalEnum.ONE.getNumber()]); + JSONObject params = (JSONObject) JSON.toJSON(pointArgs[UniversalEnum.TWO.getNumber()]); + if (Objects.equals(functionId, UniversalEnum.A_ONE.getValue()) || Objects.equals(functionId, UniversalEnum.A_TWO.getValue()) || Objects.equals(functionId, UniversalEnum.A_THREE.getValue()) || @@ -332,9 +556,39 @@ public class OperationLogAspect { return; } - String hashMap = Objects.equals(deviceType, UniversalEnum.FIVE.getValue()) ? UniversalEnum.RELEASE_VOICE_BROADCAST.getValue() : String.valueOf(((HashMap) (DEVICEFUNCTIONNAME.get(deviceType))).get(functionId)); + //String hashMap = Objects.equals(deviceType, UniversalEnum.FIVE.getValue()) + // ? UniversalEnum.RELEASE_VOICE_BROADCAST.getValue() + // : String.valueOf(((HashMap) (DEVICEFUNCTIONNAME.get(deviceType))).get(functionId)); + // + //remark.append(hashMap).append(":"); + if (Objects.equals(deviceType, UniversalEnum.THIRTEEN.getValue()) || Objects.equals(deviceType, UniversalEnum.SIXTEEN.getValue())) { + + String identification = params.getString("deviceName"); + String value = params.getString("value"); + + if (Objects.equals(identification, "ac_out_1_en")) { + + remark.append("220V 输出 1").append(Objects.equals(value, UniversalEnum.ONE.getValue()) ? UniversalEnum.UNPACK.getValue() : UniversalEnum.OFF.getValue()); + + } else if (Objects.equals(identification, "ac_out_2_en")) { + + remark.append("220V 输出 2").append(Objects.equals(value, UniversalEnum.ONE.getValue()) ? UniversalEnum.UNPACK.getValue() : UniversalEnum.OFF.getValue()); + + } else if (Objects.equals(identification, "dc_out_1_en")) { + + remark.append("12V 输出 1").append(Objects.equals(value, UniversalEnum.ONE.getValue()) ? UniversalEnum.UNPACK.getValue() : UniversalEnum.OFF.getValue()); - remark.append(deviceName).append(UniversalEnum.INVOKE.getValue()).append(hashMap).append(UniversalEnum.FEATURE.getValue()); + } else if (Objects.equals(identification, "dc_out_2_en")) { + + remark.append("12V 输出 2").append(Objects.equals(value, UniversalEnum.ONE.getValue()) ? UniversalEnum.UNPACK.getValue() : UniversalEnum.OFF.getValue()); + + } else if (Objects.equals(identification, "fan_out_en")) { + + remark.append("风扇").append(Objects.equals(value, UniversalEnum.ONE.getValue()) ? UniversalEnum.UNPACK.getValue() : UniversalEnum.OFF.getValue()); + + } + + } if (loginUser != null) { SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId()); @@ -396,7 +650,7 @@ public class OperationLogAspect { operLog.setOperTime(new Date()); operLog.setDcDeviceType(deviceType); operLog.setRemark(remark.toString()); - operLog.setJsonResult(jsonResult.toJSONString()); + operLog.setJsonResult(jsonResult != null ? jsonResult.toJSONString() : AjaxResult.error().toString()); dcOperLogService.save(operLog); } } diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcWarningMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcWarningMapper.java index 05795762..a480dbef 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/DcWarningMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/DcWarningMapper.java @@ -34,6 +34,14 @@ public interface DcWarningMapper */ public HashMap selectDcWarningById(String id); + /** + * 查询预警信息 + * + * @param id 预警信息主键 + * @return 预警信息 + */ + public HashMap selectAlarmById(String id); + /** * 查询预警信息列表 * diff --git a/zc-business/src/main/java/com/zc/business/mapper/OnlineLogMapper.java b/zc-business/src/main/java/com/zc/business/mapper/OnlineLogMapper.java new file mode 100644 index 00000000..ada5bc3a --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/mapper/OnlineLogMapper.java @@ -0,0 +1,9 @@ +package com.zc.business.mapper; + +import com.zc.business.domain.OnlineLog; + +import java.util.List; + +public interface OnlineLogMapper { + int addBatch(List onlineLogs); +} diff --git a/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java b/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java index f401e0fe..dfc2fef7 100644 --- a/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java +++ b/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java @@ -171,9 +171,9 @@ public class DeviceMessageHandler { String directio; if (Objects.equals(direction, UniversalEnum.ONE.getValue())) { - directio = UniversalEnum.DIRECTION_OF_JINAN.getValue(); - } else { directio = UniversalEnum.DIRECTION_OF_HEZE.getValue(); + } else { + directio = UniversalEnum.DIRECTION_OF_JINAN.getValue(); } DcWarning dcWarning = new DcWarning(); @@ -320,7 +320,9 @@ public class DeviceMessageHandler { String title = direction + WarningSubclassEnum.getDecorateInfo(warningSubclass); // 标题 dcWarning.setWarningTitle(title); - dcWarning.setRemark(DateUtil.formatDateTime(DateUtil.date(captureTime)) + UniversalEnum.BLANK_SPACE.getValue() + title); + SimpleDateFormat sdf = new SimpleDateFormat(UniversalEnum.CHINESE_CHARACTER_TIME_FORMAT.getValue()); + String formattedDate = sdf.format(new Date()); + dcWarning.setRemark(formattedDate + UniversalEnum.BLANK_SPACE.getValue() + title); // 影响车道 // 物联设备id @@ -614,7 +616,6 @@ public class DeviceMessageHandler { } String content = direction + stakeMark + precipitationType; - Map contentMap = new HashMap<>(); JSONObject object = new JSONObject(); object.put("meteorologicalDetectorData", meteorologicalDetectorData); @@ -622,7 +623,9 @@ public class DeviceMessageHandler { DcWarning dcWarning = new DcWarning(); dcWarning.setWarningState(UniversalEnum.ONE.getNumber()); - dcWarning.setRemark(new Date() + UniversalEnum.BLANK_SPACE.getValue() + content); + SimpleDateFormat sdf = new SimpleDateFormat(UniversalEnum.CHINESE_CHARACTER_TIME_FORMAT.getValue()); + String formattedDate = sdf.format(new Date()); + dcWarning.setRemark(formattedDate + UniversalEnum.BLANK_SPACE.getValue() + content); dcWarning.setWarningTime(new Date()); dcWarning.setWarningType(UniversalEnum.EIGHT_ONE.getNumber()); dcWarning.setWarningSubclass(UniversalEnum.EIGHT_ONE.getValue()); @@ -637,13 +640,10 @@ public class DeviceMessageHandler { if (direction.equals(UniversalEnum.DIRECTION_OF_JINAN.getValue())) { dcWarning.setDirection(UniversalEnum.THREE.getValue()); } - contentMap.put("content", content); - contentMap.put("event", dcWarning); - - WebSocketService.broadcast(WebSocketEvent.WARNING, contentMap); dcWarningService.insertDcWarning(dcWarning); + //待确认数量 dcEventService.getCountNum(); } @@ -660,16 +660,15 @@ public class DeviceMessageHandler { } String content = direction + stakeMark + precipitationType; - Map contentMap = new HashMap<>(); - contentMap.put("content", content); - contentMap.put("event", meteorologicalDetectorData); - WebSocketService.broadcast(WebSocketEvent.WARNING, contentMap); + JSONObject object = new JSONObject(); object.put("meteorologicalDetectorData", meteorologicalDetectorData); String string = object.toString(); DcWarning dcWarning = new DcWarning(); dcWarning.setWarningState(UniversalEnum.ONE.getNumber()); - dcWarning.setRemark(new Date() + UniversalEnum.BLANK_SPACE.getValue() + content); + SimpleDateFormat sdf = new SimpleDateFormat(UniversalEnum.CHINESE_CHARACTER_TIME_FORMAT.getValue()); + String formattedDate = sdf.format(new Date()); + dcWarning.setRemark(formattedDate + UniversalEnum.BLANK_SPACE.getValue() + content); dcWarning.setWarningTime(new Date()); dcWarning.setWarningType(UniversalEnum.EIGHT_FOUR.getNumber()); dcWarning.setWarningSubclass(UniversalEnum.EIGHT_FOUR.getValue()); @@ -685,9 +684,7 @@ public class DeviceMessageHandler { } dcWarningService.insertDcWarning(dcWarning); - contentMap.put("content", content); - contentMap.put("event", dcWarning); - WebSocketService.broadcast(WebSocketEvent.WARNING, contentMap); + //待确认数量 dcEventService.getCountNum(); diff --git a/zc-business/src/main/java/com/zc/business/service/IDcBatchFunctionsJobGroupService.java b/zc-business/src/main/java/com/zc/business/service/IDcBatchFunctionsJobGroupService.java index 9dda4855..701bc6d7 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcBatchFunctionsJobGroupService.java +++ b/zc-business/src/main/java/com/zc/business/service/IDcBatchFunctionsJobGroupService.java @@ -50,4 +50,6 @@ public interface IDcBatchFunctionsJobGroupService extends IService listDcBatchFunctionsJobGroup(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup); boolean changeStatus(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) throws SchedulerException, TaskException; + + DcBatchFunctionsJobGroup adddcBatchFunctionsJobGroupAnddcBatchFunctionsJob(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) throws SchedulerException, TaskException; } diff --git a/zc-business/src/main/java/com/zc/business/service/IDcWarningService.java b/zc-business/src/main/java/com/zc/business/service/IDcWarningService.java index 73f3312c..f4d8576f 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcWarningService.java +++ b/zc-business/src/main/java/com/zc/business/service/IDcWarningService.java @@ -32,6 +32,8 @@ public interface IDcWarningService */ public HashMap selectDcWarningById(String id); + public HashMap selectAlarmById(String id); + /** * 查询预警信息列表 * diff --git a/zc-business/src/main/java/com/zc/business/service/IOnlineLogService.java b/zc-business/src/main/java/com/zc/business/service/IOnlineLogService.java new file mode 100644 index 00000000..b40e6ff7 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/service/IOnlineLogService.java @@ -0,0 +1,12 @@ +package com.zc.business.service; + +import com.zc.business.domain.OnlineLog; + +import java.util.List; + +/** + * 设备在线日志 + */ +public interface IOnlineLogService { + int addBatch(List list); +} diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcBatchFunctionsJobGroupServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcBatchFunctionsJobGroupServiceImpl.java index a9f91a3b..c0412f2d 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcBatchFunctionsJobGroupServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcBatchFunctionsJobGroupServiceImpl.java @@ -1,5 +1,6 @@ package com.zc.business.service.impl; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -13,11 +14,14 @@ import com.zc.business.service.IDcBatchFunctionsJobGroupService; import com.zc.business.service.IDcBatchFunctionsJobService; import org.quartz.SchedulerException; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; /** * 定时任务组Service业务层处理 @@ -49,9 +53,9 @@ public class DcBatchFunctionsJobGroupServiceImpl extends ServiceImpl dcBatchFunctionsJobLambdaQueryWrapper = new LambdaQueryWrapper<>(); - dcBatchFunctionsJobLambdaQueryWrapper.eq(DcBatchFunctionsJob::getJobGroup,dcBatchFunctionsJobGroup.getId()); + dcBatchFunctionsJobLambdaQueryWrapper.eq(DcBatchFunctionsJob::getJobGroup, dcBatchFunctionsJobGroup.getId()); List list = dcBatchFunctionsJobService.list(dcBatchFunctionsJobLambdaQueryWrapper); - list.forEach(item->{ + list.forEach(item -> { try { dcBatchFunctionsJobService.editDcBatchFunctionsJob(item); } catch (SchedulerException e) { @@ -134,5 +138,25 @@ public class DcBatchFunctionsJobGroupServiceImpl extends ServiceImpl dcBatchFunctionsJobList = dcBatchFunctionsJobGroup.getDcBatchFunctionsJobList(); + DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup1 = addDcBatchFunctionsJobGroup(dcBatchFunctionsJobGroup); + if (dcBatchFunctionsJobGroup1 == null) { + throw new NullPointerException(); + } + for (DcBatchFunctionsJob job : dcBatchFunctionsJobList) { + + job.setJobGroup(String.valueOf(dcBatchFunctionsJobGroup1.getId())); + + DcBatchFunctionsJob dcBatchFunctionsJob = dcBatchFunctionsJobService.addDcBatchFunctionsJob(job); + if (dcBatchFunctionsJob == null) { + throw new NullPointerException(); + } + } + return dcBatchFunctionsJobGroup1; + } } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcEmergencyPlansServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcEmergencyPlansServiceImpl.java index 0aec039c..ad6b7fee 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcEmergencyPlansServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcEmergencyPlansServiceImpl.java @@ -880,8 +880,6 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { // functions List> functionList = new ArrayList<>(); - remark.append(device.getDeviceName()); - remark.append(UniversalEnum.INVOKE.getValue()); try { if (device.getDeviceType().equals(DeviceTypeConstants.DRIVING_GUIDANCE.toString())) { // 行车诱导 @@ -899,11 +897,23 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { props.put("startDisplayTime", startTime); props.put("endDisplayTime", endTime); result.put("content", "自动:" + stateName + ";时间范围:" + startTime + UniversalEnum.SHORT_BAR.getValue() + endTime); + remark.append("时间自动控制模式:"); + remark.append(startTime); + remark.append("-"); + remark.append(endTime); } else if (controlModel.equals(UniversalEnum.ZERO_ZERO.getValue())) { result.put("content", "手动:" + stateName); + remark.append("远程手动控制模式"); } else { result.put("content", "万年历:" + stateName); + remark.append("万年历自动控制模式"); } + remark.append(":"); + remark.append("上行:"); + remark.append(otherConfig.get("name").toString()); + remark.append(","); + remark.append("下行:"); + remark.append(otherConfig.get("name").toString()); result.put("device", device.getId()); result.put("deviceName", device.getDeviceName()); result.put("deviceType", device.getDeviceType()); @@ -918,7 +928,6 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { } else { status = UniversalEnum.ONE.getNumber(); } - remark.append(UniversalEnum.DEVICE_CONTROL_MODE.getValue()); result.put("result", ajaxResult); dcOperLog.add(result); resultArray.add(result); @@ -956,11 +965,6 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { jsonObject.get("dcDeviceId").toString().equals(device.getId().toString())) .findFirst() .orElse(null); - remark.append(UniversalEnum.FILE_NAME_SENDING.getValue()); - remark.append("、"); - remark.append(UniversalEnum.FILE_SENDING.getValue()); - remark.append("、"); - remark.append(UniversalEnum.SPECIFIES_THE_LIST_THAT_CURRENTLY_NEEDS_TO_BE_PLAYED.getValue()); if (foundContent == null) { // 说明没有匹配到设备 JSONObject errorResult = new JSONObject(); @@ -975,10 +979,11 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { resultArray.add(result); dcOperLog.add(result); status = UniversalEnum.ONE.getNumber(); + remark.append(errorResult.get("content")); } else { JSONObject jsonObject = new JSONObject(); jsonObject.put("dcInfoBoardTemplate", foundContent); - status = boardReleaseProcess(props, iotDeviceId, jsonObject, device, resultArray, functionList, dcOperLog); + status = boardReleaseProcess(props, iotDeviceId, jsonObject, device, resultArray, functionList, dcOperLog, remark); } } @@ -1010,6 +1015,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { errorResult.put("result",resu); dcOperLog.add(errorResult); resultArray.add(errorResult); + remark.append(errorResult.get("content")); }else { if (StringUtils.isEmpty(foundContent.getString("content"))) { params.put("text", UniversalEnum.WELCOME_TO_SHANDONG_EXPRESSWAY.getValue()); @@ -1028,8 +1034,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { result.put("deviceName", device.getDeviceName()); result.put("deviceType", device.getDeviceType()); result.put("content", params.get("text")); - - remark.append(UniversalEnum.RELEASE_VOICE_BROADCAST.getValue()); + remark.append(result.get("content")); processingDeviceParameters(UniversalEnum.A_ONE.getValue(), functionList, params); @@ -1049,17 +1054,27 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { } else if (device.getDeviceType().equals(DeviceTypeConstants.LASER_FATIGUE_AWAKENING.toString())) { // 激光疲劳唤醒 - HashMap map = new HashMap<>(); - map.put(UniversalEnum.SET.getValue(), otherConfig.get("operationType").toString()); + + // 查看当前设备控制的状态 + JSONObject mdJSONObject = (JSONObject) JSON.toJSON(dcDeviceController.getDeviceLatestProperty(iotDeviceId, "MD").get("data")); + String mdValue = mdJSONObject.containsKey("value")? mdJSONObject.getString("value") : null; + + JSONObject tmJSONObject = (JSONObject) JSON.toJSON(dcDeviceController.getDeviceLatestProperty(iotDeviceId, "TM").get("data")); + String tmValue = tmJSONObject.containsKey("value")? tmJSONObject.getString("value") : null; + JSONObject resultTime = new JSONObject(); resultTime.put("device", device.getId()); resultTime.put("deviceName", device.getDeviceName()); resultTime.put("deviceType", device.getDeviceType()); - remark.append(UniversalEnum.MODE_SETTING_COMMAND.getValue()); - remark.append("、"); - remark.append(UniversalEnum.WORK_TIME_SETTING_COMMAND.getValue()); + remark.append(otherConfig.get("name").toString()); + remark.append(","); + remark.append(otherConfig.get("operationDuration")); + remark.append(UniversalEnum.MINUTES.getValue()); + HashMap map = new HashMap<>(); + map.put(UniversalEnum.SET.getValue(), otherConfig.get("operationType").toString()); + // 调用设备参数存储格式 processingDeviceParameters(UniversalEnum.SETMD.getValue(), functionList, map); AjaxResult ajaxResultState = dcDeviceController.getAjaxResult(iotDeviceId, UniversalEnum.SETMD.getValue(), map); @@ -1074,6 +1089,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_SETTM; resultTime.put("content", "状态:" + name + ";操作时长" + otherConfig.get("operationDuration") + UniversalEnum.MINUTES.getValue()); + // 调用设备参数存储格式 processingDeviceParameters(functionId, functionList, propsTime); AjaxResult ajaxResult = dcDeviceController.getAjaxResult(iotDeviceId, functionId, propsTime); @@ -1085,6 +1101,15 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { status = UniversalEnum.ZERO.getNumber(); } else { status = UniversalEnum.ONE.getNumber(); + // 模拟事务,回滚设备当前的使用状态 + if (!ajaxResultState.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber()) && mdValue != null) { + map.put(UniversalEnum.SET.getValue(), mdValue); + dcDeviceController.getAjaxResult(iotDeviceId, UniversalEnum.SETMD.getValue(), map); + } + if (!ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber()) && tmValue != null) { + propsTime.put(UniversalEnum.SET.getValue(), UniversalEnum.SETTM.getValue() + tmValue); + dcDeviceController.getAjaxResult(iotDeviceId, DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_SETTM, propsTime); + } } } @@ -1098,7 +1123,6 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { } catch (HttpException | IOException e) { log.error(e.toString()); - throw new RuntimeException(e); } } @@ -1126,7 +1150,8 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { DcDevice device, JSONArray resultArray, List> functionList, - JSONArray dcOperLog + JSONArray dcOperLog, + StringBuilder remark ) throws HttpException, IOException { String functionId = UniversalEnum.EMPTY_STRING.getValue(); Integer status = UniversalEnum.ZERO.getNumber(); @@ -1138,13 +1163,14 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { props.put("size", UniversalEnum.SIXTY_FIVE_THOUSAND_FIVE_HUNDRED_THIRTY_FIVE.getValue()); processingDeviceParameters(functionId, functionList, props); - - AjaxResult ajaxResult11 = dcDeviceController.getAjaxResult(iotDeviceId, functionId, props); - dcOperLog.add(getDcOperLog(device,ajaxResult11)); - // 13功能码执行参数构造 DcInfoBoardTemplate dcInfoBoardTemplate = JSON.parseObject( JSON.toJSONString(otherConfig.get("dcInfoBoardTemplate")), DcInfoBoardTemplate.class); + remark.append(dcInfoBoardTemplate.getContent()); + AjaxResult ajaxResult11 = dcDeviceController.getAjaxResult(iotDeviceId, functionId, props); + dcOperLog.add(getDcOperLog(device,ajaxResult11)); + // 13功能码执行参数构造 + HashMap props11 = new HashMap<>(); functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_13; List> list = new ArrayList<>(); diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java index 82d7d60f..d072cb49 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java @@ -1172,6 +1172,9 @@ public class DcEventServiceImpl extends ServiceImpl impl public DcEvent selectEventSubclassById(String id) { // DcEvent dcEvent = dcEventMapper.selectDcEventById(id); + if (dcEvent ==null){ + return new DcEvent(); + } int eventType = Math.toIntExact(dcEvent.getEventType()); List processConfigList = dcProcessConfigMapper.selectDcProcessConfigByEventType(Math.toIntExact(dcEvent.getEventType())); dcEvent.setProcessConfigList(processConfigList); diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcNoStakeWarningTableServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcNoStakeWarningTableServiceImpl.java index 0009d2bc..71dac816 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcNoStakeWarningTableServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcNoStakeWarningTableServiceImpl.java @@ -31,22 +31,22 @@ public class DcNoStakeWarningTableServiceImpl extends ServiceImpl locations = new ArrayList<>(); + for (String s1 : lngLatsString) { + String[] s2 = s1.split(","); + locations.add(new Location(Double.parseDouble(s2[1]), Double.parseDouble(s2[0]))); // 示例地点1 + } + double fixedLat = firstLat; // Los Angeles的纬度 + // System.out.println("Lat Angeles的纬度"+fixedLat); + double fixedLon = firstLon; // Los Angeles的经度 + // System.out.println("Lon Angeles的纬度"+fixedLon); + + // 根据距离固定点的远近排序 + // Collections.sort(locations, Comparator.comparingDouble(location -> haversineDistance(fixedLat, fixedLon, location.latitude, location.longitude))); + // 按照经度升序排序坐标数组 + Collections.sort(locations, Comparator.comparingDouble(location ->location.getLongitude())); + + // 将排序后的坐标重新格式化为原始的字符串格式 + StringBuilder sortedLngLatsBuilder = new StringBuilder(); + // 输出排序后的地点及其距离 + for (int i = 0; i < locations.size(); i++) { + Location loc = locations.get(i); + if (i > 0) { + sortedLngLatsBuilder.append(";"); + } + sortedLngLatsBuilder.append(loc.longitude) + .append(",") + .append(loc.latitude); + // System.out.println("Location " + (i + 1) + ": (" + loc.latitude + ", " + loc.longitude + ") - Distance from Los Angeles: " + haversineDistance(fixedLat, fixedLon, loc.latitude, loc.longitude) + " km"); + } + String sortedLngLats = sortedLngLatsBuilder.toString(); + jsonObject.put("link_lng_lats",sortedLngLats); + // System.out.println("排序后的坐标字符串:" + sortedLngLats); + //as_one_road //是否为同一条路,1-是,0-否 if (asOneRoad == UniversalEnum.ZERO.getNumber()) { - - String string = jsonObject.getString("list_link_info"); - JSONArray jsonlist = JSON.parseArray(string); - JSONObject o = (JSONObject) jsonlist.get(UniversalEnum.ZERO.getNumber()); - - String string1 = o.getString("firstPoint"); - String string2 = o.getString("lastPoint"); - String lngLats = o.getString("lngLats"); - String[] lngLatsString = lngLats.split(";"); - double s = Double.parseDouble(lngLatsString[UniversalEnum.ZERO.getNumber()].split(",")[UniversalEnum.ZERO.getNumber()]); - double s2 = Double.parseDouble(lngLatsString[UniversalEnum.ZERO.getNumber()].split(",")[UniversalEnum.ONE.getNumber()]); - double s3 = Double.parseDouble(lngLatsString[lngLatsString.length - UniversalEnum.ONE.getNumber()].split(",")[UniversalEnum.ZERO.getNumber()]); - double s4 = Double.parseDouble(lngLatsString[lngLatsString.length - UniversalEnum.ONE.getNumber()].split(",")[UniversalEnum.ONE.getNumber()]); + double s = locations.get(UniversalEnum.ZERO.getNumber()).longitude; + double s2 =locations.get(UniversalEnum.ZERO.getNumber()).latitude ; + double s3 = locations.get(locations.size()-UniversalEnum.ONE.getNumber()).longitude; + double s4 = locations.get(locations.size()-UniversalEnum.ONE.getNumber()).latitude; double distanceM = calculateDistance(s2, s, s4, s3); // System.out.printf("最大距离为: %.2f 米%n", distanceM); jsonObject.put("max_jam_dist", distanceM);//最大拥堵距离 @@ -1181,9 +1216,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi String endmark = formatNumber(endMake); jsonObject.put("endMark", endmark);//结束桩号 - String[] split = string1.split(","); - double firstLon = Double.parseDouble(split[UniversalEnum.ZERO.getNumber()]); - double firstLat = Double.parseDouble(split[UniversalEnum.ONE.getNumber()]); + String[] split2 = string2.split(","); double lastLon = Double.parseDouble(split2[UniversalEnum.ZERO.getNumber()]); double lastLat = Double.parseDouble(split2[UniversalEnum.ONE.getNumber()]); @@ -1353,5 +1386,46 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi return distance; } + static class Location { + double latitude; + double longitude; + + // 构造函数 + public Location(double latitude, double longitude) { + this.latitude = latitude; + this.longitude = longitude; + } + + // Getter 和 Setter(可选) + public double getLatitude() { + return latitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + } + + // 使用哈弗辛公式计算两点之间的距离(单位:千米) + static double haversineDistance(double lat1, double lon1, double lat2, double lon2) { + final int R = 6371; // 地球半径,单位千米 + double dLat = Math.toRadians(lat2 - lat1); + double dLon = Math.toRadians(lon2 - lon1); + lat1 = Math.toRadians(lat1); + lat2 = Math.toRadians(lat2); + + double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2); + double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); + return R * c; + } } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java index d63aadf7..e9986b8c 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java @@ -93,6 +93,18 @@ public class DcWarningServiceImpl implements IDcWarningService return dcWarningMapper.selectDcWarningById(id); } + /** + * 查询预警信息 + * + * @param id 预警信息主键 + * @return 预警信息 + */ + @Override + public HashMap selectAlarmById(String id) + { + return dcWarningMapper.selectAlarmById(id); + } + /** * 查询预警信息列表 * @@ -230,9 +242,17 @@ public class DcWarningServiceImpl implements IDcWarningService break; } } - String content= direction+UniversalEnum.BLANK_SPACE.getValue() + dcWarning.getStakeMark()+UniversalEnum.BLANK_SPACE.getValue()+HAPPEN+EventSubclass+EVENT ; Map contentMap = new HashMap<>(); - contentMap.put("content",content); + + if (dcWarning.getWarningSource() == 7) { + String remark = dcWarning.getRemark(); + String[] split = remark.split(" "); + String s = split[split.length - 1]; + contentMap.put("content",s); + }else { + String content= direction+UniversalEnum.BLANK_SPACE.getValue() + dcWarning.getStakeMark()+UniversalEnum.BLANK_SPACE.getValue()+HAPPEN+EventSubclass+EVENT ; + contentMap.put("content",content); + } contentMap.put("event",dcWarning); WebSocketService.broadcast(WebSocketEvent.WARNING, contentMap); //推送事件消息 0不是感知事件 dcEventService.getCountNum(); diff --git a/zc-business/src/main/java/com/zc/business/service/impl/OnlineLogServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/OnlineLogServiceImpl.java new file mode 100644 index 00000000..4ec7ac6d --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/service/impl/OnlineLogServiceImpl.java @@ -0,0 +1,19 @@ +package com.zc.business.service.impl; + +import com.zc.business.domain.OnlineLog; +import com.zc.business.mapper.OnlineLogMapper; +import com.zc.business.service.IOnlineLogService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; +@Service +public class OnlineLogServiceImpl implements IOnlineLogService { + @Resource + private OnlineLogMapper onlineLogMapper; + + @Override + public int addBatch(List list) { + return onlineLogMapper.addBatch(list); + } +} diff --git a/zc-business/src/main/java/com/zc/business/task/DeviceOnlineTask.java b/zc-business/src/main/java/com/zc/business/task/DeviceOnlineTask.java new file mode 100644 index 00000000..ea98f764 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/task/DeviceOnlineTask.java @@ -0,0 +1,349 @@ +package com.zc.business.task; + +import com.alibaba.excel.util.DateUtils; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.redis.RedisCache; +import com.ruoyi.common.utils.spring.SpringUtils; +import com.zc.business.constant.RedisKeyConstants; +import com.zc.business.domain.DcDevice; +import com.zc.business.domain.OnlineLog; +import com.zc.business.domain.OnlineSum; +import com.zc.business.enums.UniversalEnum; +import com.zc.business.service.IDcDeviceService; +import com.zc.business.service.IOnlineLogService; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.InetAddress; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.temporal.ChronoUnit; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.springframework.util.ObjectUtils; + +import javax.tools.JavaFileManager; +import javax.xml.stream.Location; + +/** + * 设备在线率检测 + */ +@Component("DeviceOnline") +public class DeviceOnlineTask { + Logger logger = LoggerFactory.getLogger(DeviceOnlineTask.class); + IDcDeviceService dcDeviceService = SpringUtils.getBean(IDcDeviceService.class); + IOnlineLogService onlineLogService = SpringUtils.getBean(IOnlineLogService.class); + RedisCache redisCache = SpringUtils.getBean(RedisCache.class); + ExecutorService executorService; + final static int BATCH_SIZE = 100; + /** + * 设备在线率检测一小时执行一次 + */ + public void deviceOnlineTask() { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + List deviceList = dcDeviceService.list(lambdaQueryWrapper); + Map onlineLogMap = new ConcurrentHashMap<>(); + executorService = Executors.newFixedThreadPool(UniversalEnum.ONE_HUNDRED.getNumber()); + for (DcDevice device : deviceList) { + executorService.submit(()->{ + try { + String ipAddress = device.getDeviceIp(); + OnlineLog onlineLog; + if(ipAddress == null || ipAddress.isEmpty()){ + //IP为空,查询物联状态 + onlineLog = getIotDeviceStatus(device); + }else { + if(isReachable(ipAddress)){ + onlineLog = sendPingPacket(device); + }else { + onlineLog = new OnlineLog.LogBuilder().buildBad(device); + } + } + if(onlineLog != null){ + onlineLogMap.put(device.getId(), onlineLog); + } + } catch (Exception e) { + e.printStackTrace(); + logger.error("Error pinging device {},message {}", device.getDeviceIp(), e.getMessage()); + } + }); + } + shutdown(); + //批量处理数据 + addBatch(new ArrayList<>(onlineLogMap.values())); + } + + /** + * 是否可达 + * @param ipAddress IP地址 + * @return @see boolean + */ + private boolean isReachable(String ipAddress) { + try { + InetAddress address = InetAddress.getByName(ipAddress); + return address.isReachable(UniversalEnum.FIVE_THOUSAND.getNumber()); + } catch (IOException e) { + e.printStackTrace(); + return false; + } + } + + /** + * 发送ping包(通用) + * @param device ip地址 + * @return @see OnlineLog + */ + private OnlineLog sendPingPacket(DcDevice device){ + switch (SystemType.checkSystem()){ + case LINUX_SYSTEM: + return sendPingPacketOfLinux(device); + case WIN_SYSTEM: + return sendPingPacketOfWindows(device); + case AIX_SYSTEM: + case UNIX_SYSTEM: + throw new UnsupportedOperationException("不支持的系统类型"); + default: + throw new IllegalStateException("未知的系统类型,无法执行命令"); + } + } + + /** + * 发送ping包(linux) + * @param device ip地址 + * @return @see OnlineLog + */ + public OnlineLog sendPingPacketOfLinux(DcDevice device) { + OnlineLog.LogBuilder logBuilder = new OnlineLog.LogBuilder(); + try { + // Execute the ping command + Process process = Runtime.getRuntime().exec(PingCommand.LINUX_PING.getValue() + device.getDeviceIp()); // Sending 4 ICMP Echo Request packets + // Read the output of the command + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + int transmitted = 0; + int received = 0; + double rttAvg = 0.0; + String line; + while ((line = reader.readLine()) != null) { + if (line.contains("packets transmitted")) { + String[] stats = line.split(", "); + transmitted = Integer.parseInt(stats[0].split(" ")[0]); + received = Integer.parseInt(stats[1].split(" ")[0]); + } + if(line.contains("rtt")){ + String[] stats = line.split(" "); + rttAvg = Double.parseDouble(stats[3].split("/")[1]); + } + } + return logBuilder.setDeviceStatus(UniversalEnum.ONE.getValue()) + .setSendCount(transmitted) + .setReceiveCount(received) + .setRttAvg(rttAvg) + .build(device); + } catch (IOException e) { + e.printStackTrace(); + return logBuilder.buildBad(device); + } + } + + public OnlineLog sendPingPacketOfWindows(DcDevice device) { + OnlineLog.LogBuilder logBuilder = new OnlineLog.LogBuilder(); + ProcessBuilder processBuilder = new ProcessBuilder("cmd.exe", "/c", "ping", "-n", "4", device.getDeviceIp()); + try { + // 启动进程 + Process process = processBuilder.start(); + // 读取命令的标准输出 + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(),"GBK")); + int transmitted = 0; + int received = 0; + double rttAvg = 0.0; + String line; + while ((line = reader.readLine()) != null) { + if (line.contains("已发送")) { + String[] stats = line.split(","); + transmitted = Integer.parseInt(stats[0].split("= ")[1]); + received = Integer.parseInt(stats[1].split("= ")[1]); + } + if(line.contains("平均")){ + String[] stats = line.split(","); + rttAvg = Double.parseDouble(stats[2].split("= ")[1].substring(0, stats[2].split("= ")[1].length()-2)); + } + } + // 等待进程结束 + process.waitFor(); + return logBuilder.setDeviceStatus(UniversalEnum.ONE.getValue()) + .setSendCount(transmitted) + .setReceiveCount(received) + .setRttAvg(rttAvg) + .build(device); + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + return logBuilder.buildBad(device); + } + } + + /** + * 关闭线程池 + */ + public void shutdown() { + executorService.shutdown(); // 发起关闭请求,不再接受新任务,但会等待已提交的任务完成 + try { + // 等待所有任务完成,或者等待直到超时 + if (!executorService.awaitTermination(55, TimeUnit.MINUTES)) { + // 超时后尝试停止所有正在执行的任务 + executorService.shutdownNow(); // 这不会等待正在执行的任务完成 + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); // 重新设置中断状态 + executorService.shutdownNow(); // 尝试停止所有任务 + } + } + + /** + * 批量处理数据 + * @param onlineLogs 待处理数据 + */ + private void addBatch(List onlineLogs) { + for (int i = 0; i < onlineLogs.size(); i += BATCH_SIZE) { + int endIndex = Math.min(i + BATCH_SIZE, onlineLogs.size()); + List subList = onlineLogs.subList(i, endIndex); + int rows = onlineLogService.addBatch(subList); + if(rows >0) { + for (OnlineLog onlineLog : subList) { + incrementSummary(onlineLog); + } + } + } + } + /** + * 增量汇总,当天数据增量汇总到Redis + */ + private void incrementSummary(OnlineLog onlineLog) { + // 获取当天日期 + String date = DateUtils.format(new Date(), "yyyy-MM-dd"); + long deviceId = onlineLog.getDeviceId(); + OnlineSum onlineSum = redisCache.getCacheMapValue(RedisKeyConstants.DEVICE_ONLINE , date+":"+deviceId); + if (ObjectUtils.isEmpty(onlineSum)){ + onlineSum = new OnlineSum().copyFromLog(onlineLog); + redisCache.setCacheMapValue(RedisKeyConstants.DEVICE_ONLINE, date+":"+deviceId, onlineSum); + Long ttl = redisCache.getExpire(RedisKeyConstants.DEVICE_ONLINE); + if(ttl == -1) redisCache.expire(RedisKeyConstants.DEVICE_ONLINE,getTimeout()); + }else { + //增量计算 + onlineSum.incrementSummary(onlineLog); + redisCache.setCacheMapValue(RedisKeyConstants.DEVICE_ONLINE, date+":"+deviceId, onlineSum); + } + } + + /** + * 获取设备在线状态 + * @param device 设备信息 + * @return @see PingResult + */ + private OnlineLog getIotDeviceStatus(DcDevice device){ + OnlineLog.LogBuilder logBuilder = new OnlineLog.LogBuilder(); + try { + AjaxResult deviceByIotDeviceId = dcDeviceService.getDeviceByIotDeviceId(device.getIotDeviceId()); + if (Objects.equals(String.valueOf(deviceByIotDeviceId.get("code")), UniversalEnum.TWO_HUNDRED.getValue())){ + String deviceState = ((JSONObject) JSON.toJSON(deviceByIotDeviceId.get("data"))).getString("deviceState"); + if (!ObjectUtils.isEmpty(deviceState) && Objects.equals(deviceState, UniversalEnum.ON_LINE.getValue())) { + return logBuilder.buildGood(device); + } + } + return logBuilder.buildBad(device); + } catch (Exception e) { + e.printStackTrace(); + return logBuilder.buildBad(device); + } + } + + private long getTimeout(){ + // 获取当前时间 + ZonedDateTime now = ZonedDateTime.now(ZoneId.systemDefault()); + // 获取今天午夜的时间(即今天的00:00:00) + ZonedDateTime midnight = now.truncatedTo(ChronoUnit.DAYS); + // 计算两个时间点之间的秒数差 + long secondsToday = ChronoUnit.SECONDS.between(midnight, now); + // 一天的秒数 + long secondsInDay = ChronoUnit.SECONDS.between(midnight, midnight.plusDays(1)); + // 当天剩余的秒数 + return secondsInDay - secondsToday; + } + enum SystemType { + WIN_SYSTEM("win"), + LINUX_SYSTEM("linux"), + AIX_SYSTEM("aix"), + UNIX_SYSTEM("unix"), + UNKNOWN_SYSTEM("unknown"); + String value; + String getValue() { + return value; + } + SystemType(String value) { + this.value = value; + } + static SystemType checkSystem(){ + String osName = System.getProperty("os.name").toLowerCase(); + if (osName.contains(SystemType.WIN_SYSTEM.getValue())) { + return SystemType.WIN_SYSTEM; + } else if (osName.contains(SystemType.LINUX_SYSTEM.getValue())) { + return SystemType.LINUX_SYSTEM; + } else if (osName.contains(SystemType.AIX_SYSTEM.getValue())) { + return SystemType.AIX_SYSTEM; + } else if (osName.contains(SystemType.UNIX_SYSTEM.getValue())) { + return SystemType.UNIX_SYSTEM; + } + return SystemType.UNKNOWN_SYSTEM; + } + } + enum PingCommand{ + LINUX_PING("ping -c 4 "), + WINDOWS_PING("ping "); + private final String value; + + String getValue() { + return value; + } + PingCommand(String value) { + this.value = value; + } + } + + public static void main(String[] args) { + // 假设你要ping的主机地址 + String host = "10.0.111.11"; + + // 构建ping命令,注意:Windows和Unix/Linux的ping命令略有不同 + // Windows: ping -n 4 www.google.com + // Unix/Linux: ping -c 4 www.google.com + ProcessBuilder processBuilder = new ProcessBuilder("cmd.exe", "/c", "ping", "-n", "4", host); + + try { + // 启动进程 + Process process = processBuilder.start(); + + // 读取命令的标准输出 + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(),"GBK")); + String line; + while ((line = reader.readLine()) != null) { + System.out.println(line); + } + + // 等待进程结束 + int exitCode = process.waitFor(); + System.out.println("\nExited with error code : " + exitCode); + + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + } + } +} diff --git a/zc-business/src/main/java/com/zc/business/task/ExternalInterfaceMonitoringTask.java b/zc-business/src/main/java/com/zc/business/task/ExternalInterfaceMonitoringTask.java index 8c6aa902..44fbf843 100644 --- a/zc-business/src/main/java/com/zc/business/task/ExternalInterfaceMonitoringTask.java +++ b/zc-business/src/main/java/com/zc/business/task/ExternalInterfaceMonitoringTask.java @@ -223,7 +223,7 @@ public class ExternalInterfaceMonitoringTask extends BaseController { /** * 交通流通用 */ - public void dcTrafficStatisticsCurrency(String path, String operationName) throws Exception { + public void dcTrafficStatisticsCurrency(String path, String operationName) { // 参数 RequestParams requestParams = new RequestParams(); @@ -232,18 +232,27 @@ public class ExternalInterfaceMonitoringTask extends BaseController { Map headers = new HashMap<>(); headers.put("Authorization", DcTrafficStatisticsServiceImpl.getAccessToken()); String url = UniversalEnum.DATA_CENTER_TRAFFIC_STATISTICS_IP_PORT.getValue() + path; - // 请求 - Response response = postRequestByHeadersAndParams(headers, url, requestParams); // 构造 ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.TRAFFIC_FLOW.getCode()); externalInterfaceMonitoring.setInterfaceName(operationName); - // 插入 - trafficFlowResultProcessing(externalInterfaceMonitoring, response); + try { + Response response = postRequestByHeadersAndParams(headers, url, requestParams); + // 插入 + trafficFlowResultProcessing(externalInterfaceMonitoring, response); + }catch (Exception e) { + externalInterfaceMonitoring.setOperationResult(e.getMessage()); + externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); + externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); + externalInterfaceMonitoring.setOperatorName("系统"); + externalInterfaceMonitoring.setOperationTime(new Date()); + externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring); + } + } //车辆 - public void dcTrafficStatisticsCurrencyVehicle(String path, String operationName) throws Exception { + public void dcTrafficStatisticsCurrencyVehicle(String path, String operationName) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern(UniversalEnum.TIME_FORMAT_YEARS_MONTH_DAY.getValue()); LocalDate currentDate = LocalDate.now(); String nowYear = currentDate.format(formatter); @@ -264,18 +273,27 @@ public class ExternalInterfaceMonitoringTask extends BaseController { Map headers = new HashMap<>(); headers.put("Authorization", DcTrafficStatisticsServiceImpl.getAccessToken()); String url = UniversalEnum.DATA_CENTER_TRAFFIC_STATISTICS_IP_PORT.getValue() + path; - // 请求 - Response response = postRequestByHeadersAndParams(headers, url, requestParams); // 构造 ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.TRAFFIC_FLOW.getCode()); externalInterfaceMonitoring.setInterfaceName(operationName); - // 插入 - trafficFlowResultProcessing(externalInterfaceMonitoring, response); + try { + // 请求 + Response response = postRequestByHeadersAndParams(headers, url, requestParams); + // 插入 + trafficFlowResultProcessing(externalInterfaceMonitoring, response); + } catch (Exception e) { + externalInterfaceMonitoring.setOperationResult(e.getMessage()); + externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); + externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); + externalInterfaceMonitoring.setOperatorName("系统"); + externalInterfaceMonitoring.setOperationTime(new Date()); + externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring); + } } //获取门架指标数据 - public void obtainTheShelfIndicatorData(String path, String operationName) throws Exception { + public void obtainTheShelfIndicatorData(String path, String operationName) { // 计算一小时前的时间点 DateTime lastHour = DateUtil.offsetHour(new Date(), UniversalEnum.MINUS_ONE.getNumber()); @@ -299,22 +317,33 @@ public class ExternalInterfaceMonitoringTask extends BaseController { Map headers = new HashMap<>(); headers.put("Authorization", DcTrafficStatisticsServiceImpl.getAccessToken()); - Response response // 请求响应 - = okHttp - .headers(headers) - .url(UniversalEnum.DATA_CENTER_TRAFFIC_STATISTICS_IP_PORT.getValue() + path) // 请求地址 - .data(requestParams) // 请求参数 - .post(); // 请求方法 + // 构造 ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.TRAFFIC_FLOW.getCode()); externalInterfaceMonitoring.setInterfaceName(operationName); - // 插入 - trafficFlowResultProcessing(externalInterfaceMonitoring, response); + + try { + Response response // 请求响应 + = okHttp + .headers(headers) + .url(UniversalEnum.DATA_CENTER_TRAFFIC_STATISTICS_IP_PORT.getValue() + path) // 请求地址 + .data(requestParams) // 请求参数 + .post(); // 请求方法 + // 插入 + trafficFlowResultProcessing(externalInterfaceMonitoring, response); + } catch (Exception e) { + externalInterfaceMonitoring.setOperationResult(e.getMessage()); + externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); + externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); + externalInterfaceMonitoring.setOperatorName("系统"); + externalInterfaceMonitoring.setOperationTime(new Date()); + externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring); + } } //收费站 TollStation - public void dcTrafficStatisticsCurrencyTollStation(String path, String operationName, String stationType) throws Exception { + public void dcTrafficStatisticsCurrencyTollStation(String path, String operationName, String stationType) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern(UniversalEnum.TIME_FORMAT_YEARS_MONTH_DAY.getValue()); LocalDate currentDate = LocalDate.now(); String nowYear = currentDate.format(formatter); @@ -336,56 +365,84 @@ public class ExternalInterfaceMonitoringTask extends BaseController { Map headers = new HashMap<>(); headers.put("Authorization", DcTrafficStatisticsServiceImpl.getAccessToken()); String url = UniversalEnum.DATA_CENTER_TRAFFIC_STATISTICS_IP_PORT.getValue() + path; - // 请求 - Response response = postRequestByHeadersAndParams(headers, url, requestParams); // 构造 ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.TRAFFIC_FLOW.getCode()); externalInterfaceMonitoring.setInterfaceName(operationName); - // 插入 - trafficFlowResultProcessing(externalInterfaceMonitoring, response); + + try { + // 请求 + Response response = postRequestByHeadersAndParams(headers, url, requestParams); + // 插入 + trafficFlowResultProcessing(externalInterfaceMonitoring, response); + } catch (Exception e) { + externalInterfaceMonitoring.setOperationResult(e.getMessage()); + externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); + externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); + externalInterfaceMonitoring.setOperatorName("系统"); + externalInterfaceMonitoring.setOperationTime(new Date()); + externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring); + } } /** * 全国气象数据 - 雷达数据 */ - public void getRadarData() throws Exception { + public void getRadarData() { ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); - OkHttp okHttp = new OkHttp(); - Response response // 请求响应 - = okHttp - .url(UniversalEnum.RADAR_DATA.getValue()) // 请求地址 - .get(); // 请求方法 externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.NATIONAL_METEOROLOGY.getCode()); externalInterfaceMonitoring.setInterfaceName("雷达数据"); - if (response.code() == UniversalEnum.TWO_HUNDRED.getNumber()) { - externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ONE.getNumber()); - if (response.body() != null) { - JSONArray array = DcNmcController.parseHtmlContent(response.body().string()); - externalInterfaceMonitoring.setOperationResult(JSON.toJSONString(array)); + + + try { + OkHttp okHttp = new OkHttp(); + Response response // 请求响应 + = okHttp + .url(UniversalEnum.RADAR_DATA.getValue()) // 请求地址 + .get(); // 请求方法 + if (response.code() == UniversalEnum.TWO_HUNDRED.getNumber()) { + externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ONE.getNumber()); + if (response.body() != null) { + JSONArray array = DcNmcController.parseHtmlContent(response.body().string()); + externalInterfaceMonitoring.setOperationResult(JSON.toJSONString(array)); + } + } else { + externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); + externalInterfaceMonitoring.setOperationResult(response.toString()); } - } else { + } catch (Exception e) { + externalInterfaceMonitoring.setOperationResult(e.getMessage()); externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); - externalInterfaceMonitoring.setOperationResult(response.toString()); + }finally { + externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); + externalInterfaceMonitoring.setOperatorName("系统"); + externalInterfaceMonitoring.setOperationTime(new Date()); + externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring); } - externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); - externalInterfaceMonitoring.setOperatorName("系统"); - externalInterfaceMonitoring.setOperationTime(new Date()); - externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring); } /** * 全国气象数据 - 雷达图 */ - public void getRadarChart() throws Exception { + public void getRadarChart() { Map headers = new HashMap<>(); headers.put("Referer", UniversalEnum.RADAR_MAP_WEATHER.getValue()); - Response response = getRequestByHeaders(headers, UniversalEnum.RADAR_MAP.getValue() + new Date().getTime()); ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.NATIONAL_METEOROLOGY.getCode()); externalInterfaceMonitoring.setInterfaceName("雷达图"); - insertIntoExternalInterface(externalInterfaceMonitoring, response); + + try { + Response response = getRequestByHeaders(headers, UniversalEnum.RADAR_MAP.getValue() + new Date().getTime()); + insertIntoExternalInterface(externalInterfaceMonitoring, response); + } catch (Exception e) { + externalInterfaceMonitoring.setOperationResult(e.getMessage()); + externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); + externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); + externalInterfaceMonitoring.setOperatorName("系统"); + externalInterfaceMonitoring.setOperationTime(new Date()); + externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring); + } } /** @@ -398,25 +455,31 @@ public class ExternalInterfaceMonitoringTask extends BaseController { parameter.put("stakeNum", UniversalEnum.STAKE_NUM.getValue()); parameter.put("forecastHour", UniversalEnum.STAKE_NUM.getNumber()); parameter.put("managerId", UniversalEnum.MANAGER_ID.getValue()); - // 结果 - AjaxResult ajaxResult = weatherForecastController.currentWeatherAndForecastInformation(parameter); // 构造 ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.WEATHER.getCode()); externalInterfaceMonitoring.setInterfaceName("当前气象及预报信息查询"); - resultAnalysis(ajaxResult, externalInterfaceMonitoring); externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); externalInterfaceMonitoring.setOperatorName("系统"); externalInterfaceMonitoring.setOperationTime(new Date()); - // 插入 - externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring); + + try { + // 结果 + AjaxResult ajaxResult = weatherForecastController.currentWeatherAndForecastInformation(parameter); + resultAnalysis(ajaxResult, externalInterfaceMonitoring); + } catch (Exception e) { + externalInterfaceMonitoring.setOperationResult(e.getMessage()); + externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); + }finally { + externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring); + } } /** * 天气预报 - 当前气象预警信息查询 */ - public void currentWeatherWarningInformationQuery() throws Exception { + public void currentWeatherWarningInformationQuery() { // 参数 JSONObject weather = JSONObject.parseObject(configService.selectConfigByKey("weather")); HashMap parameter = new HashMap<>(); @@ -424,14 +487,25 @@ public class ExternalInterfaceMonitoringTask extends BaseController { parameter.put("earlyWorningLevel", UniversalEnum.EARLY_WORNING_LEVEL.getValue()); String url = weather.getString("get_earlyworning_info"); RequestParams requestParams = new RequestParams(parameter); - //结果 - Response response = postRequestByHeadersAndParams(new HashMap<>(), url, requestParams); + //构造 ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.WEATHER.getCode()); externalInterfaceMonitoring.setInterfaceName("当前气象预警信息查询"); - //插入 - insertIntoExternalInterface(externalInterfaceMonitoring, response); + + try { + //结果 + Response response = postRequestByHeadersAndParams(new HashMap<>(), url, requestParams); + //插入 + insertIntoExternalInterface(externalInterfaceMonitoring, response); + } catch (Exception e) { + externalInterfaceMonitoring.setOperationResult(e.getMessage()); + externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); + externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); + externalInterfaceMonitoring.setOperatorName("系统"); + externalInterfaceMonitoring.setOperationTime(new Date()); + externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring); + } } /** @@ -448,14 +522,24 @@ public class ExternalInterfaceMonitoringTask extends BaseController { header.put("Authorization", videoTOKEN); - Response response = getRequestByHeaders(header, - cameraInfo.getString("URL") + UniversalEnum.EXAMPLE_QUERY_SYNC_CAMERA_DATA.getValue()); //构造 ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.VIDEO.getCode()); externalInterfaceMonitoring.setInterfaceName("查询同步相机数据"); - //插入 - videoResultInsertInto(externalInterfaceMonitoring, response); + + try { + Response response = getRequestByHeaders(header, + cameraInfo.getString("URL") + UniversalEnum.EXAMPLE_QUERY_SYNC_CAMERA_DATA.getValue()); + //插入 + videoResultInsertInto(externalInterfaceMonitoring, response); + } catch (Exception e) { + externalInterfaceMonitoring.setOperationResult(e.getMessage()); + externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); + externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); + externalInterfaceMonitoring.setOperatorName("系统"); + externalInterfaceMonitoring.setOperationTime(new Date()); + externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring); + } } @@ -476,16 +560,26 @@ public class ExternalInterfaceMonitoringTask extends BaseController { header.put("Authorization", videoTOKEN); - Response response = postRequestByHeadersAndParams(header, - cameraInfo.getString("URL") + UniversalEnum.GET_VIDEO_STREAM_INFORMATION.getValue(), - requestParams); //构造 ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.VIDEO.getCode()); externalInterfaceMonitoring.setInterfaceName("获取视频流信息"); - //插入 - videoResultInsertInto(externalInterfaceMonitoring, response); + + try { + Response response = postRequestByHeadersAndParams(header, + cameraInfo.getString("URL") + UniversalEnum.GET_VIDEO_STREAM_INFORMATION.getValue(), + requestParams); + //插入 + videoResultInsertInto(externalInterfaceMonitoring, response); + } catch (Exception e) { + externalInterfaceMonitoring.setOperationResult(e.getMessage()); + externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); + externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); + externalInterfaceMonitoring.setOperatorName("系统"); + externalInterfaceMonitoring.setOperationTime(new Date()); + externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring); + } } /** @@ -494,8 +588,6 @@ public class ExternalInterfaceMonitoringTask extends BaseController { public void queryPresetPositionList() throws Exception { JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo")); - OkHttp okHttp = new OkHttp(); - RequestParams requestParams = new RequestParams(); requestParams.put("camId", "57941"); @@ -507,16 +599,25 @@ public class ExternalInterfaceMonitoringTask extends BaseController { header.put("Authorization", videoTOKEN); - Response response = getRequestByHeadersByParam(header, - cameraInfo.getString("URL") + UniversalEnum.EXAMPLE_QUERY_THE_PRESET_BIT_LIST.getValue(), - requestParams); - //构造 ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.VIDEO.getCode()); externalInterfaceMonitoring.setInterfaceName("查询预置位列表"); - //插入 - videoResultInsertInto(externalInterfaceMonitoring, response); + + try { + Response response = getRequestByHeadersByParam(header, + cameraInfo.getString("URL") + UniversalEnum.EXAMPLE_QUERY_THE_PRESET_BIT_LIST.getValue(), + requestParams); + //插入 + videoResultInsertInto(externalInterfaceMonitoring, response); + } catch (Exception e) { + externalInterfaceMonitoring.setOperationResult(e.getMessage()); + externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); + externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); + externalInterfaceMonitoring.setOperatorName("系统"); + externalInterfaceMonitoring.setOperationTime(new Date()); + externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring); + } } /** @@ -535,21 +636,32 @@ public class ExternalInterfaceMonitoringTask extends BaseController { } header.put("Authorization", videoTOKEN); - Response response = getRequestByHeadersByParam(header, - cameraInfo.getString("URL") + UniversalEnum.GET_CAMERA_INFORMATION_BY_ORGANIZATION.getValue(), - requestParams); //构造 ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.VIDEO.getCode()); externalInterfaceMonitoring.setInterfaceName("根据组织机构获取摄像机信息"); - //插入 - videoResultInsertInto(externalInterfaceMonitoring, response); + + + try { + Response response = getRequestByHeadersByParam(header, + cameraInfo.getString("URL") + UniversalEnum.GET_CAMERA_INFORMATION_BY_ORGANIZATION.getValue(), + requestParams); + //插入 + videoResultInsertInto(externalInterfaceMonitoring, response); + } catch (Exception e) { + externalInterfaceMonitoring.setOperationResult(e.getMessage()); + externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); + externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); + externalInterfaceMonitoring.setOperatorName("系统"); + externalInterfaceMonitoring.setOperationTime(new Date()); + externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring); + } } /** * 云平台控制 */ - public void cloudPlatformControl() throws Exception { + public void cloudPlatformControl() { JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo")); RequestParams requestParams = new RequestParams(); @@ -563,15 +675,26 @@ public class ExternalInterfaceMonitoringTask extends BaseController { header.put("Authorization", videoTOKEN); - Response response = getRequestByHeadersByParam(header, - cameraInfo.getString("URL") + UniversalEnum.CLOUD_PLATFORM_CONTROL.getValue(), - requestParams); //构造 ExternalInterfaceMonitoring externalInterfaceMonitoring = new ExternalInterfaceMonitoring(); externalInterfaceMonitoring.setInterfaceOwnership(InterfaceOwnershipEnum.VIDEO.getCode()); externalInterfaceMonitoring.setInterfaceName("云平台控制"); - //插入 - videoResultInsertInto(externalInterfaceMonitoring, response); + + + try { + Response response = getRequestByHeadersByParam(header, + cameraInfo.getString("URL") + UniversalEnum.CLOUD_PLATFORM_CONTROL.getValue(), + requestParams); + //插入 + videoResultInsertInto(externalInterfaceMonitoring, response); + } catch (Exception e) { + externalInterfaceMonitoring.setOperationResult(e.getMessage()); + externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber()); + externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID()); + externalInterfaceMonitoring.setOperatorName("系统"); + externalInterfaceMonitoring.setOperationTime(new Date()); + externalInterfaceMonitoringMapper.insert(externalInterfaceMonitoring); + } } /** diff --git a/zc-business/src/main/resources/mapper/business/DcGantryMetricsStatisticsDataMapper.xml b/zc-business/src/main/resources/mapper/business/DcGantryMetricsStatisticsDataMapper.xml index 985a7ce4..1cc1f5ea 100644 --- a/zc-business/src/main/resources/mapper/business/DcGantryMetricsStatisticsDataMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcGantryMetricsStatisticsDataMapper.xml @@ -199,18 +199,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ON ps.facility_code = dgsd.gantry_code AND - YEAR(dgsd.statistical_date) = #{startDate} + YEAR(dgsd.statistical_date) = #{startDate} AND - DATE_FORMAT(dgsd.statistical_date, '%Y-%m') = #{startDate} + DATE_FORMAT(dgsd.statistical_date, '%Y-%m') = #{startDate} AND - - DATE(dgsd.statistical_date) = DATE(#{startDate}) + + dgsd.statistical_date BETWEEN DATE(#{startDate}) and DATE(#{endDate}) AND + + + DATE(dgsd.statistical_date) = DATE(#{startDate}) AND - DATE(dgsd.statistical_date) = DATE(#{startDate}) + DATE(dgsd.statistical_date) = DATE(#{startDate}) AND - AND dgsd.period_type = #{periodType} + + dgsd.period_type = #{periodType} ORDER BY dgsd.statistical_date DESC diff --git a/zc-business/src/main/resources/mapper/business/DcGantryStatisticsDataMapper.xml b/zc-business/src/main/resources/mapper/business/DcGantryStatisticsDataMapper.xml index b4c8a6e1..03a98a3a 100644 --- a/zc-business/src/main/resources/mapper/business/DcGantryStatisticsDataMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcGantryStatisticsDataMapper.xml @@ -328,7 +328,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" JOIN dc_gantry_statistics_data AS dgsd ON ps.facility_code = dgsd.gantry_code - AND DATE(dgsd.statistical_date) BETWEEN #{startDate} AND #{endDate} + + AND DATE(dgsd.statistical_date) BETWEEN #{startDate} AND #{endDate} + AND dgsd.period_type = #{periodType} diff --git a/zc-business/src/main/resources/mapper/business/DcWarningMapper.xml b/zc-business/src/main/resources/mapper/business/DcWarningMapper.xml index 514ba14f..7d6bb3a8 100644 --- a/zc-business/src/main/resources/mapper/business/DcWarningMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcWarningMapper.xml @@ -77,6 +77,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where id = #{id} + +