From 6d31b47e76502644448b27cc7a3f24829b6ce027 Mon Sep 17 00:00:00 2001
From: "Mr.Wang" <wang@qq.com>
Date: Tue, 9 Jul 2024 16:43:19 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A2=84=E6=A1=88-=E8=AE=BE?=
 =?UTF-8?q?=E5=A4=87=E6=8E=A7=E5=88=B6=E8=AE=B0=E5=BD=95=E5=AD=98=E5=82=A8?=
 =?UTF-8?q?=E6=A0=BC=E5=BC=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../impl/DcEmergencyPlansServiceImpl.java     | 99 ++++++++++++-------
 1 file changed, 63 insertions(+), 36 deletions(-)

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 38c4fbfa..c98aab20 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
@@ -855,6 +855,8 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
             StringBuilder remark = new StringBuilder();
             iotDeviceId = device.getIotDeviceId();
             HashMap<String, Object> props = new HashMap<>();
+            // 设备管控记录结果
+            JSONArray dcOperLog = new JSONArray();
 
             // 构造设备控制记录数据格式
             List<HashMap<String, List<Map<String, Object>>>> propsList = new ArrayList<>();
@@ -912,6 +914,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
                     }
                     remark.append(UniversalEnum.DEVICE_CONTROL_MODE.getValue());
                     result.put("result", ajaxResult);
+                    dcOperLog.add(result);
                     resultArray.add(result);
 
 
@@ -931,6 +934,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
                         result.put("content", UniversalEnum.RESTORE_LAST_TIME.getValue());
                         result.put("result", ajaxResult1B);
                         resultArray.add(result);
+                        dcOperLog.add(result);
                         if (ajaxResult1B.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) {
                             status = UniversalEnum.ZERO.getNumber();
                         } else {
@@ -963,11 +967,12 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
                             result.put("code",UniversalEnum.FIVE_HUNDRED.getNumber());
                             result.put("msg",UniversalEnum.OPERATION_FAILURE.getValue());
                             resultArray.add(result);
+                            dcOperLog.add(result);
                             status = UniversalEnum.ONE.getNumber();
                         } else {
                             JSONObject jsonObject = new JSONObject();
                             jsonObject.put("dcInfoBoardTemplate", foundContent);
-                            status = boardReleaseProcess(props, iotDeviceId, jsonObject, device, resultArray, functionList);
+                            status = boardReleaseProcess(props, iotDeviceId, jsonObject, device, resultArray, functionList, dcOperLog);
                         }
 
                     }
@@ -993,40 +998,47 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
                         errorResult.put("deviceName", device.getDeviceName());
                         errorResult.put("deviceType", deviceType);
                         errorResult.put("content", UniversalEnum.NO_BROADCAST_CONTENT_IS_MATCHED_PROCEDURE.getValue());
+                        JSONObject resu = new JSONObject();
+                        resu.put("code",UniversalEnum.FIVE_HUNDRED.getNumber());
+                        resu.put("msg","操作失败,检查设备");
+                        errorResult.put("result",resu);
+                        dcOperLog.add(errorResult);
                         resultArray.add(errorResult);
-                    }
-                    if (StringUtils.isEmpty(foundContent.getString("content"))) {
-                        params.put("text", UniversalEnum.WELCOME_TO_SHANDONG_EXPRESSWAY.getValue());
-                    } else {
-                        params.put("text", foundContent.getString("content"));
-                    }
+                    }else {
+                        if (StringUtils.isEmpty(foundContent.getString("content"))) {
+                            params.put("text", UniversalEnum.WELCOME_TO_SHANDONG_EXPRESSWAY.getValue());
+                        } else {
+                            params.put("text", foundContent.getString("content"));
+                        }
 
-                    params.put("repeatTimes", UniversalEnum.THREE.getValue());
-                    params.put("functionType", UniversalEnum.START_PA_TTS.getValue());
-                    JSONArray termList = new JSONArray();
-                    termList.add(JSON.parseObject(device.getOtherConfig()));
-                    params.put("termList", termList);
+                        params.put("repeatTimes", UniversalEnum.THREE.getValue());
+                        params.put("functionType", UniversalEnum.START_PA_TTS.getValue());
+                        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("deviceType", deviceType);
-                    result.put("content", params.get("text"));
+                        JSONObject result = new JSONObject();
+                        result.put("device", device.getId());
+                        result.put("deviceName", device.getDeviceName());
+                        result.put("deviceType", deviceType);
+                        result.put("content", params.get("text"));
 
-                    remark.append(UniversalEnum.RELEASE_VOICE_BROADCAST.getValue());
+                        remark.append(UniversalEnum.RELEASE_VOICE_BROADCAST.getValue());
 
-                    processingDeviceParameters(UniversalEnum.A_ONE.getValue(), functionList, params);
+                        processingDeviceParameters(UniversalEnum.A_ONE.getValue(), functionList, params);
 
-                    JSONObject returnResult = broadcastController.nearCamListDistance(params);
-                    if (Objects.equals(returnResult.getString("retCode"), UniversalEnum.ZERO.getValue())) {
-                        status = UniversalEnum.ZERO.getNumber();
-                        returnResult.put("code", UniversalEnum.TWO_HUNDRED.getNumber());
-                    } else {
-                        status = UniversalEnum.ONE.getNumber();
-                        returnResult.put("code", UniversalEnum.FIVE_HUNDRED.getNumber());
+                        JSONObject returnResult = broadcastController.nearCamListDistance(params);
+                        if (Objects.equals(returnResult.getString("retCode"), UniversalEnum.ZERO.getValue())) {
+                            status = UniversalEnum.ZERO.getNumber();
+                            returnResult.put("code", UniversalEnum.TWO_HUNDRED.getNumber());
+                        } else {
+                            status = UniversalEnum.ONE.getNumber();
+                            returnResult.put("code", UniversalEnum.FIVE_HUNDRED.getNumber());
+                        }
+                        result.put("result", returnResult);
+                        dcOperLog.add(result);
+                        resultArray.add(result);
                     }
-                    result.put("result", returnResult);
-                    resultArray.add(result);
 
 
                 } else if (device.getDeviceType().equals(DeviceTypeConstants.LASER_FATIGUE_AWAKENING.toString())) {
@@ -1046,6 +1058,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
 
                     AjaxResult ajaxResultState = dcDeviceController.getAjaxResult(iotDeviceId, UniversalEnum.SETMD.getValue(), map);
                     resultTime.put("resultState", ajaxResultState);
+                    dcOperLog.add(getDcOperLog(device,ajaxResultState));
 
                     // 操作时长
                     String operationDuration = UniversalEnum.SETTM.getValue() + otherConfig.get("operationDuration").toString();
@@ -1059,6 +1072,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
 
                     AjaxResult ajaxResult = dcDeviceController.getAjaxResult(iotDeviceId, functionId, propsTime);
                     resultTime.put("result", ajaxResult);
+                    dcOperLog.add(getDcOperLog(device,ajaxResult));
                     resultArray.add(resultTime);
 
                     if (ajaxResultState.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber()) && ajaxResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) {
@@ -1073,7 +1087,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
                 // 语音广播恢复操作不存记录
                 if (!(device.getDeviceType().equals(DeviceTypeConstants.ROAD_SECTION_VOICE_BROADCASTING.toString())
                         && operationType.equals(UniversalEnum.TWO.getNumber()))) {
-                    insertEquipmentControlRecordTable(device, propsList, resultArray, status, remark.toString(),eventId);
+                    insertEquipmentControlRecordTable(device, propsList, dcOperLog, status, remark.toString(),eventId);
                 }
 
             } catch (HttpException | IOException e) {
@@ -1105,7 +1119,8 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
                                        JSONObject otherConfig,
                                        DcDevice device,
                                        JSONArray resultArray,
-                                       List<Map<String, Object>> functionList
+                                       List<Map<String, Object>> functionList,
+                                       JSONArray dcOperLog
     ) throws HttpException, IOException {
         String functionId = UniversalEnum.EMPTY_STRING.getValue();
         Integer status = UniversalEnum.ZERO.getNumber();
@@ -1119,7 +1134,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
         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")),
@@ -1154,6 +1169,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
         if (ajaxResult11.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) {
             // 2:执行13功能码
             AjaxResult ajaxResult13 = dcDeviceController.getAjaxResult(iotDeviceId, functionId, props11);
+            dcOperLog.add(getDcOperLog(device,ajaxResult13));
             JSONObject result = new JSONObject();
             result.put("device", device.getId());
             result.put("deviceName", device.getDeviceName());
@@ -1167,6 +1183,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
                 processingDeviceParameters(functionId, functionList, props1B);
 
                 AjaxResult ajaxResult1B = dcDeviceController.getAjaxResult(iotDeviceId, functionId, props1B);
+                dcOperLog.add(getDcOperLog(device,ajaxResult1B));
                 if (ajaxResult1B.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) {
                     status = UniversalEnum.ZERO.getNumber();
                 } else {
@@ -1175,6 +1192,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
                 result.put("content", dcInfoBoardTemplate.getContent());
                 result.put("result", ajaxResult1B);
             } else {
+                dcOperLog.add(getDcOperLog(device,new AjaxResult(UniversalEnum.FIVE_HUNDRED.getNumber(),"操作失败")));
                 result.put("content", UniversalEnum.PUBLISHING_FAILURE.getValue());
                 result.put("result", ajaxResult13);
                 status = UniversalEnum.ONE.getNumber();
@@ -1188,11 +1206,24 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
             error.put("device",device.getId());
             error.put("content",dcInfoBoardTemplate.getContent());
             resultArray.add(error);
+            dcOperLog.add(error);
             status = UniversalEnum.ONE.getNumber();
         }
         return status;
     }
 
+    /**
+     * 设备管控记录结果
+     */
+    public JSONObject getDcOperLog(DcDevice device,AjaxResult ajaxResult) {
+        JSONObject result = new JSONObject();
+        result.put("device", device.getId());
+        result.put("deviceName", device.getDeviceName());
+        result.put("deviceType", device.getDeviceType());
+        result.put("result", ajaxResult);
+        return result;
+    }
+
     /**
      * 设备控制记录表插入
      */
@@ -1222,11 +1253,7 @@ public class DcEmergencyPlansServiceImpl implements DcEmergencyPlansService {
         dcOperLog.setOperIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
         dcOperLog.setOperLocation(SecurityUtils.getLoginUser().getLoginLocation());
         dcOperLog.setOperParam(JSON.toJSONString(propsList));
-        List<JSONObject> filterResult = resultList.stream()
-                .map(o -> JSON.parseObject(o.toString()))
-                .filter(jsonObject -> jsonObject.getString("device").equals(dcDevice.getId().toString()))
-                .collect(Collectors.toList());
-        dcOperLog.setJsonResult(String.valueOf(filterResult));
+        dcOperLog.setJsonResult(String.valueOf(resultList));
         dcOperLog.setStatus(status);
         dcOperLog.setOperTime(new Date());
         dcOperLog.setRemark(remark);