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 246e98a2..f951dba4 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 @@ -96,7 +96,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { stringBuilder.append(","); stringBuilder.append(dcDevice.getDeviceName()); }); - dcEmergencyPlans1.setControllableDeviceName(stringBuilder.toString().replaceFirst(",","")); + dcEmergencyPlans1.setControllableDeviceName(stringBuilder.toString().replaceFirst(",", "")); }); return dcEmergencyPlansList; } @@ -181,7 +181,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { list.forEach(dcEmergencyPlans -> { List dcExecuteActions = dcEmergencyPlans.getDcExecuteAction(); dcExecuteActions.forEach(dcExecuteAction -> { - handleConfigurationData(dcExecuteAction,dcEvent,markArray); + handleConfigurationData(dcExecuteAction, dcEvent, markArray); }); }); } @@ -191,7 +191,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { */ public void handleConfigurationData(DcExecuteAction dcExecuteAction, DcEvent dcEvent, - String[] markArray){ + String[] markArray) { List deviceList = ruleFiltering(dcExecuteAction, markArray, dcEvent.getDirection()); String devices = deviceList.stream() .map(DcDevice::getIotDeviceId) @@ -207,10 +207,10 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { if (executeConfig.getString("operationType").equals("2")) { // 说明是智能发布 String content = intelligentPublishingOfInformation(dcEvent); - updateIntelligentPublishingContent(dcExecuteAction,markArray,deviceList,content,dcEvent.getDirection()); - }else { + updateIntelligentPublishingContent(dcExecuteAction, markArray, deviceList, content, dcEvent.getDirection()); + } else { // 说明是自定义发布 - customPublishingDataFormatProcessing(deviceList,executeConfig,dcExecuteAction.getDeviceType()); + customPublishingDataFormatProcessing(deviceList, executeConfig, dcExecuteAction.getDeviceType()); dcExecuteAction.setExecuteConfig(executeConfig.toJSONString()); } } @@ -218,53 +218,55 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { if (dcExecuteAction.getDeviceType() == DeviceTypeEnum.VARIABLE_INFORMATION_FLAG.getCode()) { if (recoverConfig.getString("operationType").equals("1")) { // 说明是恢复操作中的自定义发布 (只有情报板会走) - customPublishingDataFormatProcessing(deviceList,recoverConfig,dcExecuteAction.getDeviceType()); - }else { + customPublishingDataFormatProcessing(deviceList, recoverConfig, dcExecuteAction.getDeviceType()); + } else { recoverConfig.remove("contentList"); } dcExecuteAction.setRecoverConfig(recoverConfig.toJSONString()); } } + /** * 自定义发布数据格式处理 */ public void customPublishingDataFormatProcessing(List deviceList, JSONObject otherConfig, int deviceType) { - List> contentList = new ArrayList<>(); + List> contentList = new ArrayList<>(); if (!ObjectUtils.isEmpty(otherConfig.get("contentList"))) { - contentList.addAll((List>) otherConfig.get("contentList")); + contentList.addAll((List>) otherConfig.get("contentList")); contentList.removeIf(cont -> deviceList.stream().noneMatch(device -> device.getId().toString().equals(cont.get("dcDeviceId").toString()))); deviceList.forEach(dcDevice -> { boolean filter = contentList.stream().anyMatch(content -> - content.get("dcDeviceId").toString().equals(dcDevice.getId().toString())); + content.get("dcDeviceId").toString().equals(dcDevice.getId().toString())); if (!filter) { - handleContentList(dcDevice,deviceType,otherConfig,contentList); + handleContentList(dcDevice, deviceType, otherConfig, contentList); } }); - }else { + } else { deviceList.forEach(dcDevice -> { - handleContentList(dcDevice,deviceType,otherConfig,contentList); + handleContentList(dcDevice, deviceType, otherConfig, contentList); }); } - otherConfig.put("contentList",contentList); + otherConfig.put("contentList", contentList); } - public void handleContentList(DcDevice dcDevice, int deviceType, JSONObject otherConfig, List> contentList) { - Map map = new HashMap<>(); - map.put("dcDeviceId",dcDevice.getId()); - map.put("deviceName",dcDevice.getDeviceName()); + public void handleContentList(DcDevice dcDevice, int deviceType, JSONObject otherConfig, List> contentList) { + Map map = new HashMap<>(); + map.put("dcDeviceId", dcDevice.getId()); + map.put("deviceName", dcDevice.getDeviceName()); if (deviceType == DeviceTypeEnum.VARIABLE_INFORMATION_FLAG.getCode()) { JSONObject dcInfoBoardTemplate = JSON.parseObject(otherConfig.get("dcInfoBoardTemplate").toString()); dcInfoBoardTemplate.keySet().forEach(key -> map.put(key, dcInfoBoardTemplate.get(key))); - }else { + } else { // 语音广播 - map.put("content",otherConfig.get("content")); + map.put("content", otherConfig.get("content")); } contentList.add(map); } /** * 交通事件-根据事件、单个执行操作筛选设备 + * * @param dcEventAnDcEmergencyPlans * @return */ @@ -283,6 +285,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { /** * 设备管控-确认按钮生成内容 + * * @param dcEventAnDcEmergencyPlans * @return */ @@ -296,7 +299,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { markArray[1] = String.format("%0" + 3 + "d", markArray[1]); } DcExecuteAction dcExecuteAction = dcEventAnDcEmergencyPlans.getDcExecuteAction(); - handleConfigurationData(dcExecuteAction,dcEvent,markArray); + handleConfigurationData(dcExecuteAction, dcEvent, markArray); return dcExecuteAction; } @@ -310,11 +313,11 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { String direction) { JSONObject executeConfig = JSON.parseObject(dcExecuteAction.getExecuteConfig()); - List> contentList = new ArrayList<>(); + List> contentList = new ArrayList<>(); deviceList.forEach(dcDevice -> { - Map map = new HashMap<>(); - map.put("dcDeviceId",dcDevice.getId()); - map.put("deviceName",dcDevice.getDeviceName()); + Map map = new HashMap<>(); + map.put("dcDeviceId", dcDevice.getId()); + map.put("deviceName", dcDevice.getDeviceName()); // 公里数 int kilometers = 0; // 米数 @@ -328,20 +331,20 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { if (direction.equals("菏泽方向") || direction.equals("1")) { kilometers = Math.abs(Integer.parseInt(markArray[0]) - Integer.parseInt(deviceMarkArray[0])); meters = Integer.parseInt(markArray[1]) - Integer.parseInt(deviceMarkArray[1]); - }else { + } else { kilometers = Math.abs(Integer.parseInt(deviceMarkArray[0]) - Integer.parseInt(markArray[0])); meters = Integer.parseInt(deviceMarkArray[1]) - Integer.parseInt(markArray[1]); } double roundedDistance = Math.round((kilometers + meters / 1000.0) * 10.0) / 10.0; if (roundedDistance < 1) { - map.put("content",content.replace("*",(int) (roundedDistance * 1000)+"米")); - }else { + map.put("content", content.replace("*", (int) (roundedDistance * 1000) + "米")); + } else { if (roundedDistance % 1 == 0) { // 去除掉1.0公里的情况 - map.put("content",content.replace("*",(int)roundedDistance+"公里")); - }else { - map.put("content",content.replace("*",roundedDistance+"公里")); + map.put("content", content.replace("*", (int) roundedDistance + "公里")); + } else { + map.put("content", content.replace("*", roundedDistance + "公里")); } } @@ -367,7 +370,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { } contentList.add(map); }); - executeConfig.put("contentList",contentList); + executeConfig.put("contentList", contentList); dcExecuteAction.setExecuteConfig(executeConfig.toJSONString()); } @@ -401,40 +404,40 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { dcDevices.forEach(dcDevice -> { threadPoolTaskExecutor.execute(() -> { try { - if (StringUtils.isNotEmpty(dcDevice.getIotDeviceId())){ - AjaxResult ajaxResult = dcDeviceController.getDeviceRealtimeProperty(dcDevice.getIotDeviceId(), "3A", new HashMap<>()); - if (ajaxResult.get("code").equals(200)) { - JSONObject properties = JSON.parseObject(JSON.parseObject(ajaxResult.get("data").toString()).get("3A").toString()); - JSONArray contentArray = JSONArray.parseArray(properties.get("content").toString()); - List list = new ArrayList<>(); - contentArray.forEach(content -> { - DcInfoBoardTemplate dcInfoBoardTemplate = new DcInfoBoardTemplate(); - JSONObject jsonObject = JSON.parseObject(content.toString()); - String displayAreaWidth = jsonObject.get("displayAreaWidth").toString(); - String displayAreaHeight = jsonObject.get("displayAreaHeight").toString(); - // 内容 - dcInfoBoardTemplate.setContent(jsonObject.get("textContent").toString()); - // 前景颜色 - dcInfoBoardTemplate.setFontColor(jsonObject.get("foregroundColor").toString()); - // 屏幕尺寸 - dcInfoBoardTemplate.setScreenSize(displayAreaWidth + "*" + displayAreaHeight); - // 字号 - dcInfoBoardTemplate.setFontSize(jsonObject.get("fontSize").toString()); - // 字体风格 - dcInfoBoardTemplate.setFontType(jsonObject.get("fontStyle").toString()); - // 字距 - dcInfoBoardTemplate.setFontSpacing(jsonObject.get("fontSpacing").toString()); - // 停留时间 - dcInfoBoardTemplate.setStopTime(jsonObject.get("residenceTime").toString()); - // 入屏方式 - dcInfoBoardTemplate.setInScreenMode(jsonObject.get("screenEntryMethod").toString()); - // 水平对齐 - dcInfoBoardTemplate.setFormatStyle(jsonObject.get("horizontalAlignment").toString()); - list.add(dcInfoBoardTemplate); - }); - map.put(dcDevice.getDeviceName(), list); + if (StringUtils.isNotEmpty(dcDevice.getIotDeviceId())) { + AjaxResult ajaxResult = dcDeviceController.getDeviceRealtimeProperty(dcDevice.getIotDeviceId(), "3A", new HashMap<>()); + if (ajaxResult.get("code").equals(200)) { + JSONObject properties = JSON.parseObject(JSON.parseObject(ajaxResult.get("data").toString()).get("3A").toString()); + JSONArray contentArray = JSONArray.parseArray(properties.get("content").toString()); + List list = new ArrayList<>(); + contentArray.forEach(content -> { + DcInfoBoardTemplate dcInfoBoardTemplate = new DcInfoBoardTemplate(); + JSONObject jsonObject = JSON.parseObject(content.toString()); + String displayAreaWidth = jsonObject.get("displayAreaWidth").toString(); + String displayAreaHeight = jsonObject.get("displayAreaHeight").toString(); + // 内容 + dcInfoBoardTemplate.setContent(jsonObject.get("textContent").toString()); + // 前景颜色 + dcInfoBoardTemplate.setFontColor(jsonObject.get("foregroundColor").toString()); + // 屏幕尺寸 + dcInfoBoardTemplate.setScreenSize(displayAreaWidth + "*" + displayAreaHeight); + // 字号 + dcInfoBoardTemplate.setFontSize(jsonObject.get("fontSize").toString()); + // 字体风格 + dcInfoBoardTemplate.setFontType(jsonObject.get("fontStyle").toString()); + // 字距 + dcInfoBoardTemplate.setFontSpacing(jsonObject.get("fontSpacing").toString()); + // 停留时间 + dcInfoBoardTemplate.setStopTime(jsonObject.get("residenceTime").toString()); + // 入屏方式 + dcInfoBoardTemplate.setInScreenMode(jsonObject.get("screenEntryMethod").toString()); + // 水平对齐 + dcInfoBoardTemplate.setFormatStyle(jsonObject.get("horizontalAlignment").toString()); + list.add(dcInfoBoardTemplate); + }); + map.put(dcDevice.getDeviceName(), list); + } } - } } catch (Exception e) { e.printStackTrace(); } finally { @@ -498,7 +501,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { if (dcDevices.size() > 0) { if (dcExecuteAction.getNumber() > dcDevices.size()) { dcDevices = dcDevices.subList(0, dcDevices.size()); - }else { + } else { dcDevices = dcDevices.subList(0, dcExecuteAction.getNumber()); } @@ -521,7 +524,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { if (dcDevices.size() > 0) { if (dcExecuteAction.getNumber() > dcDevices.size()) { dcDevices = dcDevices.subList(0, dcDevices.size()); - }else { + } else { dcDevices = dcDevices.subList(0, dcExecuteAction.getNumber()); } } @@ -547,7 +550,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { if (dcDevices.size() > 0) { if (dcExecuteAction.getNumber() > dcDevices.size()) { dcDevices = dcDevices.subList(0, dcDevices.size()); - }else { + } else { dcDevices = dcDevices.subList(0, dcExecuteAction.getNumber()); } } @@ -571,7 +574,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { if (dcDevices.size() > 0) { if (dcExecuteAction.getNumber() > dcDevices.size()) { dcDevices = dcDevices.subList(0, dcDevices.size()); - }else { + } else { dcDevices = dcDevices.subList(0, dcExecuteAction.getNumber()); } } @@ -605,10 +608,10 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { // 菏泽方向 桩号增大 设备桩号要小于事件桩号 kilometers = Integer.parseInt(markArray[0]) - Integer.parseInt(deviceMarkArray[0]); meters = Integer.parseInt(markArray[1]) - Integer.parseInt(deviceMarkArray[1]); - }else { + } else { // 济南方向 桩号减小 设备桩号要大于事件桩号 - kilometers = Integer.parseInt(deviceMarkArray[0]) - Integer.parseInt(markArray[0]); - meters = Integer.parseInt(deviceMarkArray[1]) - Integer.parseInt(markArray[1]); + kilometers = Integer.parseInt(deviceMarkArray[0]) - Integer.parseInt(markArray[0]); + meters = Integer.parseInt(deviceMarkArray[1]) - Integer.parseInt(markArray[1]); } double roundedDistance = Math.round((kilometers + meters / 1000.0) * 10.0) / 10.0; return kilometers >= 0 && roundedDistance > 0; @@ -636,6 +639,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { /** * 根据事件id-查询预案事件关联表 + * * @param eventId 事件id * @return */ @@ -648,6 +652,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { /** * 根据id-查询预案事件关联表 + * * @param id id * @return */ @@ -702,7 +707,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { Integer facilityId = dcEventVehicleAccident.getFacilityId(); DcFacility facility = dcFacilityService.getFacility(facilityId.toString()); String facilityName = facility.getFacilityName(); - content = "前方*"+facilityName+"发生车辆故障"; + content = "前方*" + facilityName + "发生车辆故障"; } } else if (eventType == EventTypeEnum.TRAFFIC_CONTROL.getCode()) { @@ -729,9 +734,9 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { * @return */ public JSONObject executionConfirmation(DcEventAnDcEmergencyPlans dcEventAnDcEmergencyPlans, - String stakeMark, - String direction, - String id) { + String stakeMark, + String direction, + String id) { // 存储所有设备id StringBuilder deviceIds = new StringBuilder(); // 存储所有设备的执行结果 @@ -754,8 +759,8 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { .forEach(dcExecuteAction -> { List dcDevices = ruleFiltering(dcExecuteAction, markArray, direction); - JSONObject otherConfig = operationType.equals(1)? - JSON.parseObject(dcExecuteAction.getExecuteConfig()): JSON.parseObject(dcExecuteAction.getRecoverConfig()); + JSONObject otherConfig = operationType.equals(1) ? + JSON.parseObject(dcExecuteAction.getExecuteConfig()) : JSON.parseObject(dcExecuteAction.getRecoverConfig()); try { // 根据不通设备类型,执行不通的功能操作 invokedFunction( @@ -794,7 +799,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { eventPlanAssoc.setCreateTime(DateUtils.getNowDate()); eventPlanAssoc.setControl(JSON.toJSONString(dcEmergencyPlans.getDcExecuteAction())); eventPlanAssocMapper.insertEventPlanAssoc(eventPlanAssoc); - resultObject.put("eventPlanAssocId",eventPlanAssoc.getId()); + resultObject.put("eventPlanAssocId", eventPlanAssoc.getId()); DcEventProcess dcEventProcess = new DcEventProcess(); dcEventProcess.setEventId(id); @@ -804,7 +809,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { dcEventProcess.setContext("设备管控"); dcEventProcessService.insertDcEventProcess(dcEventProcess); - resultObject.put("deviceOperationResult",resultArray); + resultObject.put("deviceOperationResult", resultArray); return resultObject; } @@ -818,136 +823,99 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { for (DcDevice device : dcDevices) { - String iotDeviceId = ""; - String functionId = ""; - StringBuilder remark = new StringBuilder(); - iotDeviceId = device.getIotDeviceId(); - HashMap props = new HashMap<>(); - - // 构造设备控制记录数据格式 - List>>> propsList = new ArrayList<>(); - // 调用状态 0正常 1异常 - Integer status = 0; - HashMap>> proDevice = new HashMap<>(); - // devices - List> dev = new ArrayList<>(); - Map deviceMap = new HashMap<>(); - deviceMap.put("id",device.getId()); - deviceMap.put("iotDeviceId",device.getIotDeviceId()); - deviceMap.put("deviceType",device.getDeviceType()); - dev.add(deviceMap); - proDevice.put("devices",dev); - - // functions - List> functionList = new ArrayList<>(); - remark.append("在"); - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Calendar calendar = Calendar.getInstance(); - remark.append(dateFormat.format(calendar.getTime())); - remark.append("调用"); - remark.append(device.getDeviceName()); - try { - if (device.getDeviceType().equals(DeviceTypeConstants.DRIVING_GUIDANCE.toString())) { - // 行车诱导 - functionId = DeviceFunctionIdConstants.DRIVING_GUIDANCE; - // 控制模式 00-手动 01-自动 02-万年历 - String controlModel = otherConfig.get("controlModel").toString(); - props.put("onWorkStatus", otherConfig.get("state").toString()); - props.put("inWorkStatus", otherConfig.get("state").toString()); - props.put("mode", controlModel); - JSONObject result = new JSONObject(); - String stateName = otherConfig.get("name").toString(); - if (controlModel.equals("01")) { - String startTime = otherConfig.get("startTime").toString(); - String endTime = otherConfig.get("endTime").toString(); - props.put("startDisplayTime", startTime); - props.put("endDisplayTime", endTime); - result.put("content","自动:"+stateName+";时间范围:"+startTime+"-"+endTime); - } else if (controlModel.equals("00")) { - result.put("content","手动:"+stateName); - }else { - result.put("content","万年历:"+stateName); - } - result.put("device", device.getId()); - result.put("deviceName",device.getDeviceName()); + String iotDeviceId = ""; + String functionId = ""; + StringBuilder remark = new StringBuilder(); + iotDeviceId = device.getIotDeviceId(); + HashMap props = new HashMap<>(); + + // 构造设备控制记录数据格式 + List>>> propsList = new ArrayList<>(); + // 调用状态 0正常 1异常 + Integer status = 0; + HashMap>> proDevice = new HashMap<>(); + // devices + List> dev = new ArrayList<>(); + Map deviceMap = new HashMap<>(); + deviceMap.put("id", device.getId()); + deviceMap.put("iotDeviceId", device.getIotDeviceId()); + deviceMap.put("deviceType", device.getDeviceType()); + dev.add(deviceMap); + proDevice.put("devices", dev); + + // functions + List> functionList = new ArrayList<>(); + remark.append("在"); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Calendar calendar = Calendar.getInstance(); + remark.append(dateFormat.format(calendar.getTime())); + remark.append("调用"); + remark.append(device.getDeviceName()); + try { + if (device.getDeviceType().equals(DeviceTypeConstants.DRIVING_GUIDANCE.toString())) { + // 行车诱导 + functionId = DeviceFunctionIdConstants.DRIVING_GUIDANCE; + // 控制模式 00-手动 01-自动 02-万年历 + String controlModel = otherConfig.get("controlModel").toString(); + props.put("onWorkStatus", otherConfig.get("state").toString()); + props.put("inWorkStatus", otherConfig.get("state").toString()); + props.put("mode", controlModel); + JSONObject result = new JSONObject(); + String stateName = otherConfig.get("name").toString(); + if (controlModel.equals("01")) { + String startTime = otherConfig.get("startTime").toString(); + String endTime = otherConfig.get("endTime").toString(); + props.put("startDisplayTime", startTime); + props.put("endDisplayTime", endTime); + result.put("content", "自动:" + stateName + ";时间范围:" + startTime + "-" + endTime); + } else if (controlModel.equals("00")) { + result.put("content", "手动:" + stateName); + } else { + result.put("content", "万年历:" + stateName); + } + result.put("device", device.getId()); + result.put("deviceName", device.getDeviceName()); - processingDeviceParameters(functionId,functionList,props); + processingDeviceParameters(functionId, functionList, props); - AjaxResult ajaxResult = dcDeviceController.getAjaxResult(iotDeviceId, functionId, props); - // 将调用结果存入到 resultArray(操作结果) 中 + AjaxResult ajaxResult = dcDeviceController.getAjaxResult(iotDeviceId, functionId, props); + // 将调用结果存入到 resultArray(操作结果) 中 - if (ajaxResult.get("code").equals(200)) { + if (ajaxResult.get("code").equals(200)) { + status = 0; + remark.append("成功"); + } else { + status = 1; + remark.append("失败"); + } + result.put("result", ajaxResult); + resultArray.add(result); + + + } else if (device.getDeviceType().equals(DeviceTypeConstants.VARIABLE_INFORMATION_FLAG.toString())) { + if (operationType == 2 && otherConfig.getString("operationType").equals("2")) { + // 还原上次 恢复操作 + props.put("fileId", "10"); + functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_1B; + + processingDeviceParameters(functionId, functionList, props); + + AjaxResult ajaxResult1B = dcDeviceController.getAjaxResult(iotDeviceId, functionId, props); + JSONObject result = new JSONObject(); + result.put("device", device.getId()); + result.put("deviceName", device.getDeviceName()); + result.put("content", "还原上次"); + result.put("result", ajaxResult1B); + resultArray.add(result); + if (ajaxResult1B.get("code").equals(200)) { status = 0; remark.append("成功"); - }else { + } else { status = 1; remark.append("失败"); } - result.put("result", ajaxResult); - resultArray.add(result); - - - } - else if (device.getDeviceType().equals(DeviceTypeConstants.VARIABLE_INFORMATION_FLAG.toString())) { - if (operationType == 2 && otherConfig.getString("operationType").equals("2")) { - // 还原上次 恢复操作 - props.put("fileId", "10"); - functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_1B; - - processingDeviceParameters(functionId,functionList,props); - - AjaxResult ajaxResult1B = dcDeviceController.getAjaxResult(iotDeviceId, functionId, props); - JSONObject result = new JSONObject(); - result.put("device", device.getId()); - result.put("deviceName",device.getDeviceName()); - result.put("content","还原上次"); - result.put("result", ajaxResult1B); - resultArray.add(result); - if (ajaxResult1B.get("code").equals(200)) { - status = 0; - remark.append("成功"); - }else { - status = 1; - remark.append("失败"); - } - } else { - // 情报板发布全流程 - JSONArray contentList = JSON.parseArray(otherConfig.get("contentList").toString()); - JSONObject foundContent = contentList.stream() - .map(content -> JSON.parseObject(content.toString())) - .filter(jsonObject -> - jsonObject.get("dcDeviceId").toString().equals(device.getId().toString())) - .findFirst() - .orElse(null); - if (foundContent == null) { - // 说明没有匹配到设备 - JSONObject errorResult = new JSONObject(); - errorResult.put("device",device.getId()); - errorResult.put("content","未匹配到对应的模板内容"); - resultArray.add(errorResult); - status = 1; - remark.append("失败"); - }else { - JSONObject jsonObject = new JSONObject(); - jsonObject.put("dcInfoBoardTemplate",foundContent); - status = boardReleaseProcess(props, iotDeviceId, jsonObject, device, resultArray, functionList); - if (status.equals(0)) { - remark.append("成功"); - }else { - remark.append("失败"); - } - } - - } - - } - else if (device.getDeviceType().equals(DeviceTypeConstants.ROAD_SECTION_VOICE_BROADCASTING.toString()) - && operationType.equals(1)) { - // 路段广播 - JSONObject params = new JSONObject(); - params.put("name", "task-event"); - params.put("outVVol", "8"); - params.put("priority", "1"); + } else { + // 情报板发布全流程 JSONArray contentList = JSON.parseArray(otherConfig.get("contentList").toString()); JSONObject foundContent = contentList.stream() .map(content -> JSON.parseObject(content.toString())) @@ -958,87 +926,120 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { if (foundContent == null) { // 说明没有匹配到设备 JSONObject errorResult = new JSONObject(); - errorResult.put("device",device.getId()); - errorResult.put("deviceName",device.getDeviceName()); - errorResult.put("content","未匹配到对应的广播内容"); + errorResult.put("device", device.getId()); + errorResult.put("content", "未匹配到对应的模板内容"); resultArray.add(errorResult); - } - if (StringUtils.isEmpty(foundContent.getString("content"))) { - params.put("text", "山东高速欢迎您"); - }else { - params.put("text", foundContent.getString("content")); - } - - params.put("repeatTimes", "3"); - params.put("functionType", "startPaTts"); - JSONArray termList = new JSONArray(); - termList.add(JSON.parseObject(device.getOtherConfig())); - params.put("termList", termList); - - JSONObject result = new JSONObject(); - result.put("device", device.getId()); - result.put("deviceName",device.getDeviceName()); - result.put("content",params.get("text")); - - processingDeviceParameters("A1",functionList,props); - - JSONObject returnResult = broadcastController.nearCamListDistance(params); - result.put("result", returnResult); - resultArray.add(result); - - if (returnResult.get("retCode").equals("0")) { - status = 0; - remark.append("成功"); - }else { status = 1; remark.append("失败"); + } else { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("dcInfoBoardTemplate", foundContent); + status = boardReleaseProcess(props, iotDeviceId, jsonObject, device, resultArray, functionList); + if (status.equals(0)) { + remark.append("成功"); + } else { + remark.append("失败"); + } } + } + } else if (device.getDeviceType().equals(DeviceTypeConstants.ROAD_SECTION_VOICE_BROADCASTING.toString()) + && operationType.equals(1)) { + // 路段广播 + JSONObject params = new JSONObject(); + params.put("name", "task-event"); + params.put("outVVol", "8"); + params.put("priority", "1"); + JSONArray contentList = JSON.parseArray(otherConfig.get("contentList").toString()); + JSONObject foundContent = contentList.stream() + .map(content -> JSON.parseObject(content.toString())) + .filter(jsonObject -> + jsonObject.get("dcDeviceId").toString().equals(device.getId().toString())) + .findFirst() + .orElse(null); + if (foundContent == null) { + // 说明没有匹配到设备 + JSONObject errorResult = new JSONObject(); + errorResult.put("device", device.getId()); + errorResult.put("deviceName", device.getDeviceName()); + errorResult.put("content", "未匹配到对应的广播内容"); + resultArray.add(errorResult); + } + if (StringUtils.isEmpty(foundContent.getString("content"))) { + params.put("text", "山东高速欢迎您"); + } else { + params.put("text", foundContent.getString("content")); } - else if (device.getDeviceType().equals(DeviceTypeConstants.LASER_FATIGUE_AWAKENING.toString())) { - // 激光疲劳唤醒 - HashMap map = new HashMap<>(); - map.put("SET",otherConfig.get("operationType").toString()); - JSONObject resultTime = new JSONObject(); - resultTime.put("device", device.getId()); - resultTime.put("deviceName",device.getDeviceName()); - processingDeviceParameters("SETMD",functionList,map); + params.put("repeatTimes", "3"); + params.put("functionType", "startPaTts"); + JSONArray termList = new JSONArray(); + termList.add(JSON.parseObject(device.getOtherConfig())); + params.put("termList", termList); + + JSONObject result = new JSONObject(); + result.put("device", device.getId()); + result.put("deviceName", device.getDeviceName()); + result.put("content", params.get("text")); + + processingDeviceParameters("A1", functionList, props); + + JSONObject returnResult = broadcastController.nearCamListDistance(params); + result.put("result", returnResult); + resultArray.add(result); + if (Objects.equals(returnResult.getString("retCode"), "0")) { + status = 0; + remark.append("成功"); + } else { + status = 1; + remark.append("失败"); + } - AjaxResult ajaxResultState = dcDeviceController.getAjaxResult(iotDeviceId, "SETMD", map); - resultTime.put("resultState", ajaxResultState); - // 操作时长 - String operationDuration = "SETTM" + otherConfig.get("operationDuration").toString(); - String name = otherConfig.get("name").toString(); - HashMap propsTime = new HashMap<>(); - propsTime.put("SET", operationDuration); - functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_SETTM; - resultTime.put("content","状态:"+name+";操作时长"+otherConfig.get("operationDuration")+"分钟"); + } else if (device.getDeviceType().equals(DeviceTypeConstants.LASER_FATIGUE_AWAKENING.toString())) { + // 激光疲劳唤醒 + HashMap map = new HashMap<>(); + map.put("SET", otherConfig.get("operationType").toString()); + JSONObject resultTime = new JSONObject(); + resultTime.put("device", device.getId()); + resultTime.put("deviceName", device.getDeviceName()); - processingDeviceParameters(functionId,functionList,propsTime); + processingDeviceParameters("SETMD", functionList, map); - AjaxResult ajaxResult = dcDeviceController.getAjaxResult(iotDeviceId, functionId, propsTime); - resultTime.put("result", ajaxResult); - resultArray.add(resultTime); + AjaxResult ajaxResultState = dcDeviceController.getAjaxResult(iotDeviceId, "SETMD", map); + resultTime.put("resultState", ajaxResultState); - if (ajaxResultState.get("code").equals(200) && ajaxResult.get("code").equals(200)) { - status = 0; - remark.append("成功"); - }else { - status = 1; - remark.append("失败"); - } + // 操作时长 + String operationDuration = "SETTM" + otherConfig.get("operationDuration").toString(); + String name = otherConfig.get("name").toString(); + HashMap propsTime = new HashMap<>(); + propsTime.put("SET", operationDuration); + functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_SETTM; + resultTime.put("content", "状态:" + name + ";操作时长" + otherConfig.get("operationDuration") + "分钟"); + processingDeviceParameters(functionId, functionList, propsTime); + + AjaxResult ajaxResult = dcDeviceController.getAjaxResult(iotDeviceId, functionId, propsTime); + resultTime.put("result", ajaxResult); + resultArray.add(resultTime); + + if (ajaxResultState.get("code").equals(200) && ajaxResult.get("code").equals(200)) { + status = 0; + remark.append("成功"); + } else { + status = 1; + remark.append("失败"); } - proDevice.put("functions",functionList); - propsList.add(proDevice); - insertEquipmentControlRecordTable(device,propsList,resultArray,status,remark.toString()); - } catch (HttpException | IOException e) { - log.error(e.toString()); - throw new RuntimeException(e); + } + proDevice.put("functions", functionList); + propsList.add(proDevice); + insertEquipmentControlRecordTable(device, propsList, resultArray, status, remark.toString()); + } catch (HttpException | IOException e) { + log.error(e.toString()); + throw new RuntimeException(e); + } } } @@ -1047,12 +1048,12 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { * 调用设备参数存储格式 */ public void processingDeviceParameters(String functionId, - List> functionList, + List> functionList, Object props) { // 调用设备参数存储格式 - Map functionMap = new HashMap<>(); - functionMap.put("functionId",functionId); - functionMap.put("params",props); + Map functionMap = new HashMap<>(); + functionMap.put("functionId", functionId); + functionMap.put("params", props); functionList.add(functionMap); } @@ -1060,12 +1061,12 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { * 情报板发布全流程 */ public Integer boardReleaseProcess(HashMap props, - String iotDeviceId, - JSONObject otherConfig, - DcDevice device, - JSONArray resultArray, - List> functionList - ) throws HttpException, IOException { + String iotDeviceId, + JSONObject otherConfig, + DcDevice device, + JSONArray resultArray, + List> functionList + ) throws HttpException, IOException { String functionId = ""; Integer status = 0; // 执行操作 @@ -1075,7 +1076,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { props.put("fileName", "play011.lst"); props.put("size", "65535"); - processingDeviceParameters(functionId,functionList,props); + processingDeviceParameters(functionId, functionList, props); AjaxResult ajaxResult11 = dcDeviceController.getAjaxResult(iotDeviceId, functionId, props); if (ajaxResult11.get("code").equals(200)) { @@ -1109,35 +1110,35 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { list.add(parameters); props11.put("parameters", list); - processingDeviceParameters(functionId,functionList,props11); + processingDeviceParameters(functionId, functionList, props11); AjaxResult ajaxResult13 = dcDeviceController.getAjaxResult(iotDeviceId, functionId, props11); JSONObject result = new JSONObject(); result.put("device", device.getId()); - result.put("deviceName",device.getDeviceName()); + result.put("deviceName", device.getDeviceName()); if (ajaxResult13.get("code").equals(200)) { HashMap props1B = new HashMap<>(); // 3: 执行1B功能码 functionId = DeviceFunctionIdConstants.VARIABLE_INFORMATION_FLAG_1B; props1B.put("fileId", "11"); - processingDeviceParameters(functionId,functionList,props1B); + processingDeviceParameters(functionId, functionList, props1B); AjaxResult ajaxResult1B = dcDeviceController.getAjaxResult(iotDeviceId, functionId, props1B); if (ajaxResult1B.get("code").equals(200)) { status = 0; - }else { + } else { status = 1; } - result.put("content",dcInfoBoardTemplate.getContent()); + result.put("content", dcInfoBoardTemplate.getContent()); result.put("result", ajaxResult1B); } else { - result.put("content","发布失败"); + result.put("content", "发布失败"); result.put("result", ajaxResult13); status = 1; } resultArray.add(result); - }else { + } else { resultArray.add(ajaxResult11); status = 1; } @@ -1148,7 +1149,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { * 设备控制记录表插入 */ public void insertEquipmentControlRecordTable(DcDevice dcDevice, - List>>> propsList, + List>>> propsList, JSONArray resultList, Integer status, String remark) { @@ -1318,35 +1319,33 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService { JSONObject jsonObject = JSON.parseObject(executeConfig); if (dcExecuteAction.getDeviceType() == DeviceTypeConstants.DRIVING_GUIDANCE) { // 行车诱导 - config.put("controlModelName",jsonObject.get("controlModelName")); - config.put("name",jsonObject.get("name")); + config.put("controlModelName", jsonObject.get("controlModelName")); + config.put("name", jsonObject.get("name")); if (jsonObject.get("controlModel").toString().equals("01")) { - config.put("time",jsonObject.get("startTime").toString() +"-"+jsonObject.get("endTime").toString()); + config.put("time", jsonObject.get("startTime").toString() + "-" + jsonObject.get("endTime").toString()); } - }else if (dcExecuteAction.getDeviceType() == DeviceTypeConstants.VARIABLE_INFORMATION_FLAG ) { + } else if (dcExecuteAction.getDeviceType() == DeviceTypeConstants.VARIABLE_INFORMATION_FLAG) { // 情报板 if (jsonObject.getString("operationType").equals("1")) { - JSONObject dcInfoBoardTemplate = JSON.parseObject(jsonObject.get("dcInfoBoardTemplate").toString()) ; - config.put("content",dcInfoBoardTemplate.get("content")); - }else { - config.put("operationType","智能发布"); + JSONObject dcInfoBoardTemplate = JSON.parseObject(jsonObject.get("dcInfoBoardTemplate").toString()); + config.put("content", dcInfoBoardTemplate.get("content")); + } else { + config.put("operationType", "智能发布"); } - } - else if (dcExecuteAction.getDeviceType() == DeviceTypeConstants.ROAD_SECTION_VOICE_BROADCASTING) { + } else if (dcExecuteAction.getDeviceType() == DeviceTypeConstants.ROAD_SECTION_VOICE_BROADCASTING) { // 语音广播 if (jsonObject.getString("operationType").equals("1")) { - config.put("content",jsonObject.get("content")); - }else { - config.put("operationType","智能发布"); + config.put("content", jsonObject.get("content")); + } else { + config.put("operationType", "智能发布"); } - } - else if (dcExecuteAction.getDeviceType() == DeviceTypeConstants.LASER_FATIGUE_AWAKENING) { + } else if (dcExecuteAction.getDeviceType() == DeviceTypeConstants.LASER_FATIGUE_AWAKENING) { // 激光疲劳唤醒 - config.put("name",jsonObject.get("name")); - config.put("operationDuration",jsonObject.get("operationDuration")+"分钟"); + config.put("name", jsonObject.get("name")); + config.put("operationDuration", jsonObject.get("operationDuration") + "分钟"); } return JSON.toJSONString(config); })