From bd8da139decc60e8c7765e375ffda037f5209e3a Mon Sep 17 00:00:00 2001
From: liuhaonan <31457034@qq.com>
Date: 星期三, 18 五月 2022 14:32:13 +0800
Subject: [PATCH] 日志

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightTaskService.java |  117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 110 insertions(+), 7 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightTaskService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightTaskService.java
index fa39c72..d4d8cae 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightTaskService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightTaskService.java
@@ -13,6 +13,7 @@
 import com.sandu.common.execption.BusinessException;
 import com.sandu.common.object.BaseConditionVO;
 import com.sandu.common.service.impl.BaseServiceImpl;
+import com.sandu.common.util.SpringContextHolder;
 import com.sandu.ximon.admin.dto.LightTaskDto;
 import com.sandu.ximon.admin.dto.SingleLightOrderDto;
 import com.sandu.ximon.admin.manager.iot.frame.FrameBuilder;
@@ -26,6 +27,7 @@
 import com.sandu.ximon.admin.param.LightTaskIssueParam;
 import com.sandu.ximon.admin.param.LightTaskParam;
 import com.sandu.ximon.admin.security.SecurityUtils;
+import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils;
 import com.sandu.ximon.admin.utils.TaskOrderUtil;
 import com.sandu.ximon.dao.bo.LightTaskStatusAndPole;
 import com.sandu.ximon.dao.domain.LightTask;
@@ -44,6 +46,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+import java.util.stream.Collectors;
 
 /**
  * @author chenjiantian
@@ -75,6 +78,7 @@
         lightTask.setClientId(SecurityUtils.getClientId());
         lightTask.setTaskName(param.getTaskName());
         lightTask.setWeek(week);
+        lightTask.setLightAdress(param.getLightAddress());
         lightTask.setCloseOrder(param.getCloseOrder());
         lightTask.setOpenOrder(param.getOpenOrder());
         lightTask.setControlOrder(param.getControlOrder());
@@ -84,10 +88,32 @@
             throw new BusinessException("淇濆瓨璺伅浠诲姟澶辫触");
         }
 
+
+        /**
+         * 鏂板璺伅浠诲姟鏃ュ織璁板綍寮�濮�
+         */
+        List<String> poleCodeList = new ArrayList<>();
+        if (CollectionUtil.isNotEmpty(param.getPoleIdList())) {
+            List<Pole> poleList = SpringContextHolder.getBean(PoleService.class).listByIds(param.getPoleIdList());
+            if (CollectionUtil.isNotEmpty(poleList)) {
+                poleCodeList = poleList.stream().map(Pole::getDeviceCode).collect(Collectors.toList());
+            }
+        }
+        String content = "{浠诲姟ID锛�" + lightTask.getTaskId()
+                + "锛� 浠诲姟鍚嶏細" + lightTask.getTaskName()
+                + "}锛寋鍐呭抚鎸囦护" + lightTask.getFramePayload()
+                + "锛� 鐏潌ID锛�" + param.getPoleIdList().toString()
+                + "锛� 鎺у埗鐨勭伅澶村湴鍧�锛�" + param.getLightAddress()
+                + " }";
+        StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "鏂板璺伅浠诲姟", content);
+        /**
+         * 鏂板璺伅浠诲姟鏃ュ織璁板綍缁撴潫
+         */
+
         List<Long> poleIdList = param.getPoleIdList();
         if (CollectionUtil.isNotEmpty(poleIdList)) {
 
-            List<LightTaskPoleRelation> lightTaskPoleRelationList = sendControllerFrame(lightTask, poleIdList, lightTask.getFramePayload());
+            List<LightTaskPoleRelation> lightTaskPoleRelationList = sendControllerFrame(lightTask, poleIdList, lightTask.getFramePayload(), param.getLightAddress());
 
             // 娣诲姞缁戝畾鐏潌
             if (!lightTaskPoleRelationService.saveBatch(lightTaskPoleRelationList)) {
@@ -96,6 +122,19 @@
 
             // 涓�涓伅鏉嗗彧鑳戒娇鐢ㄤ竴涓换鍔★紝鏂颁换鍔¤瑕嗙洊鏃т换鍔�
             lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getPoleId, poleIdList).ne(LightTaskPoleRelation::getTaskId, lightTask.getTaskId()));
+
+            /**
+             * 涓嬪彂璺伅浠诲姟鏃ュ織璁板綍寮�濮�
+             */
+
+            String content1 = "{浠诲姟ID锛�" + lightTask.getTaskId()
+                    + "锛� 浠诲姟鍚嶏細" + lightTask.getTaskName()
+                    + "}," + " 鐏潌ID锛�" + param.getPoleIdList().toString()
+                    + " }";
+            StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "涓嬪彂璺伅浠诲姟", content1);
+            /**
+             * 涓嬪彂璺伅浠诲姟鏃ュ織璁板綍缁撴潫
+             */
         }
         return true;
     }
@@ -118,6 +157,7 @@
         lightTask.setControlOrder(param.getControlOrder());
         lightTask.setOpenOrder(param.getOpenOrder());
         lightTask.setCloseOrder(param.getCloseOrder());
+        lightTask.setLightAdress(param.getLightAddress());
         lightTask.setUpdateTime(LocalDateTime.now());
         lightTask.setFramePayload(buildControlFramePayload(param.getOpenOrder(), param.getCloseOrder(), param.getControlOrder(), week));
 
@@ -125,10 +165,31 @@
             throw new BusinessException("缂栬緫浠诲姟澶辫触");
         }
 
+        /**
+         * 缂栬緫璺伅浠诲姟鏃ュ織璁板綍寮�濮�
+         */
+        List<String> poleCodeList = new ArrayList<>();
+        if (CollectionUtil.isNotEmpty(param.getPoleIdList())) {
+            List<Pole> poleList = SpringContextHolder.getBean(PoleService.class).listByIds(param.getPoleIdList());
+            if (CollectionUtil.isNotEmpty(poleList)) {
+                poleCodeList = poleList.stream().map(Pole::getDeviceCode).collect(Collectors.toList());
+            }
+        }
+        String content = "{浠诲姟ID锛�" + taskId
+                + "锛� 浠诲姟鍚嶏細" + lightTask.getTaskName()
+                + "}锛寋鍐呭抚鎸囦护" + lightTask.getFramePayload()
+                + "锛� 鐏潌ID锛�" + param.getPoleIdList().toString()
+                + "锛� 鎺у埗鐨勭伅澶村湴鍧�锛�" + param.getLightAddress()
+                + " }";
+        StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "缂栬緫璺伅浠诲姟", content);
+        /**
+         * 缂栬緫璺伅浠诲姟鏃ュ織璁板綍缁撴潫
+         */
+
         List<Long> poleIdList = param.getPoleIdList();
         if (CollectionUtil.isNotEmpty(poleIdList)) {
 
-            List<LightTaskPoleRelation> lightTaskPoleRelationList = sendControllerFrame(lightTask, poleIdList, lightTask.getFramePayload());
+            List<LightTaskPoleRelation> lightTaskPoleRelationList = sendControllerFrame(lightTask, poleIdList, lightTask.getFramePayload(), param.getLightAddress());
 
             lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).eq(LightTaskPoleRelation::getTaskId, lightTask.getTaskId()));
             // 娣诲姞缁戝畾鐏潌
@@ -138,6 +199,19 @@
 
             // 涓�涓伅鏉嗗彧鑳戒娇鐢ㄤ竴涓换鍔★紝鏂颁换鍔¤瑕嗙洊鏃т换鍔�
             lightTaskPoleRelationService.remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getPoleId, poleIdList).ne(LightTaskPoleRelation::getTaskId, lightTask.getTaskId()));
+
+            /**
+             * 涓嬪彂璺伅浠诲姟鏃ュ織璁板綍寮�濮�
+             */
+
+            String content1 = "{浠诲姟ID锛�" + lightTask.getTaskId()
+                    + "锛� 浠诲姟鍚嶏細" + lightTask.getTaskName()
+                    + "}," + " 鐏潌ID锛�" + param.getPoleIdList().toString()
+                    + " }";
+            StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "涓嬪彂璺伅浠诲姟", content1);
+            /**
+             * 涓嬪彂璺伅浠诲姟鏃ュ織璁板綍缁撴潫
+             */
         }
 
         return true;
@@ -150,8 +224,8 @@
      * @param deviceCode   璁惧鍚�
      * @return 杩斿洖甯�
      */
-    public A5LightTimerRespInnerFrame sendTimeRRpc(String framePayload, String deviceCode) {
-        IRequestFrame requestFrame = FrameBuilder.builderA5().innerFrame(new A5LightTimerReqInnerFrame(framePayload))
+    public A5LightTimerRespInnerFrame sendTimeRRpc(String framePayload, String deviceCode, String lightAddress) {
+        IRequestFrame requestFrame = FrameBuilder.builderA5().innerFrame(new A5LightTimerReqInnerFrame(framePayload, lightAddress))
                 .orderType(A5OrderEnum.REQUEST_LIGHT_DATA.getCode()).build();
         WrapResponseCommonFrame<A5LightTimerRespInnerFrame> responseCommonFrame = MainBoardInvokeSyncService.getInstance()
                 .sendRRPC(deviceCode, requestFrame, A5LightTimerRespInnerFrame.class);
@@ -207,7 +281,7 @@
 
 
     // 姣忎釜璺伅鍙戦�佹帶鍒跺抚 杩斿洖鍏宠仈鍒楄〃
-    private List<LightTaskPoleRelation> sendControllerFrame(LightTask lightTask, List<Long> poleIdList, String framePayload) {
+    private List<LightTaskPoleRelation> sendControllerFrame(LightTask lightTask, List<Long> poleIdList, String framePayload, String lightAddress) {
         List<LightTaskPoleRelation> lightTaskPoleRelationList = new ArrayList<>();
 
         List<Pole> poles = poleService.listByIds(poleIdList);
@@ -221,7 +295,7 @@
             lightTaskPoleRelation.setTaskId(lightTask.getTaskId());
             // rrpc 鍙戠敓瀹氭椂鍛戒护
             try {
-                A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame = sendTimeRRpc(framePayload, pole.getDeviceCode());
+                A5LightTimerRespInnerFrame a5LightTimerRespInnerFrame = sendTimeRRpc(framePayload, pole.getDeviceCode(), lightAddress);
                 if (a5LightTimerRespInnerFrame == null) {
                     lightTaskPoleRelation.setIssueStatus(DeviceRespStatusEnums.OTHER_ERROR.getCode());
                 } else {
@@ -260,6 +334,14 @@
                 }
         );
 
+        /**
+         * 鍒犻櫎鎺х伅浠诲姟鏃ュ織璁板綍寮�濮�
+         */
+        String content = "{鎺х伅浠诲姟id锛�" + taskIdList + " }";
+        StoreOperationRecordsUtils.storeOperationData(null, null, "鍒犻櫎鎺х伅浠诲姟", content);
+        /**
+         * 鍒犻櫎鎺х伅浠诲姟鏃ュ織璁板綍缁撴潫
+         */
         return true;
     }
 
@@ -332,12 +414,33 @@
             throw new BusinessException("鎵句笉鍒颁换鍔�");
         }
         String framePayload = buildControlFramePayload(lightTask.getOpenOrder(), lightTask.getCloseOrder(), lightTask.getControlOrder(), lightTask.getWeek());
-        List<LightTaskPoleRelation> lightTaskPoleRelationList = sendControllerFrame(lightTask, ListUtil.toList(param.getPoleId()), framePayload);
+        List<LightTaskPoleRelation> lightTaskPoleRelationList = sendControllerFrame(lightTask, ListUtil.toList(param.getPoleId()), framePayload, lightTask.getLightAdress());
+
+        /**
+         * 涓嬪彂璺伅浠诲姟鏃ュ織璁板綍寮�濮�
+         */
+        List<String> poleCodeList = new ArrayList<>();
+        List<Pole> list = SpringContextHolder.getBean(PoleService.class).list(Wrappers.lambdaQuery(Pole.class).eq(Pole::getId, param.getPoleId()));
+        if (CollectionUtil.isNotEmpty(list)) {
+            poleCodeList = list.stream().map(Pole::getDeviceCode).collect(Collectors.toList());
+        }
+        String content = "{浠诲姟ID锛�" + lightTask.getTaskId()
+                + "锛� 浠诲姟鍚嶏細" + lightTask.getTaskName()
+                + "}," + " 鐏潌ID锛�" + param.getPoleId()
+                + " }";
+        StoreOperationRecordsUtils.storeOperationData(poleCodeList, null, "涓嬪彂璺伅浠诲姟", content);
+        /**
+         * 涓嬪彂璺伅浠诲姟鏃ュ織璁板綍缁撴潫
+         */
+
+
         if (CollectionUtil.isNotEmpty(lightTaskPoleRelationList)) {
             return lightTaskPoleRelationService.update(lightTaskPoleRelationList.get(0),
                     Wrappers.lambdaUpdate(LightTaskPoleRelation.class).eq(LightTaskPoleRelation::getPoleId, param.getPoleId())
                             .eq(LightTaskPoleRelation::getTaskId, param.getTaskId()));
         }
+
+
         return true;
     }
 }

--
Gitblit v1.9.3