From 727a69f859060093e685582fa10e5de82dcc138a Mon Sep 17 00:00:00 2001
From: Van333 <van666666@foxmail.com>
Date: 星期四, 29 十二月 2022 15:37:49 +0800
Subject: [PATCH] 放假备份。完成集中控制器对接。

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleService.java |   62 ++++++++++++++++++++++--------
 1 files changed, 45 insertions(+), 17 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleService.java
index 7e4519c..56a361b 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/PoleService.java
@@ -22,6 +22,7 @@
 import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5C3HeartbeatReportInnerFrame;
 import com.sandu.ximon.admin.manager.iot.frame.inner.request.A1TernaryCodeReqInnerFrame;
 import com.sandu.ximon.admin.manager.iot.frame.inner.request.A5LightResetReqInnerFrame;
+import com.sandu.ximon.admin.manager.iot.frame.inner.request.A7PlcResetReqInnerFrame;
 import com.sandu.ximon.admin.manager.iot.frame.inner.request.EmptyRequestInnerFrame;
 import com.sandu.ximon.admin.manager.iot.frame.inner.response.A1DeviceMacRespInnerFrame;
 import com.sandu.ximon.admin.manager.iot.frame.inner.response.A1TernaryCodeRespInnerFrame;
@@ -45,6 +46,7 @@
 import com.sandu.ximon.dao.domain.*;
 import com.sandu.ximon.dao.enums.OrderByEnums;
 import com.sandu.ximon.dao.mapper.PoleMapper;
+import eu.bitwalker.useragentutils.DeviceType;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.RandomStringUtils;
@@ -129,24 +131,26 @@
     /**
      * 鍒犻櫎鐏潌
      */
-    public boolean deletePole(Long poleId) {
-        Pole pole = getById(poleId);
-        if (pole == null) {
+    public boolean deletePole(List<Long> poleIds) {
+        List<Pole> poles = listByIds(poleIds);
+        if (poles.isEmpty()) {
             throw new BusinessException("鏈壘鍒拌鐏潌");
         }
         // 鍒犻櫎鐏潌缁戝畾鍏崇郴
-        poleBindingService.remove(Wrappers.<PoleBinding>lambdaQuery().eq(PoleBinding::getPoleId, poleId));
+        poleBindingService.remove(Wrappers.<PoleBinding>lambdaQuery().in(PoleBinding::getPoleId, poleIds));
+        SpringContextHolder.getBean(LightTaskPoleRelationService.class)
+                .remove(Wrappers.lambdaQuery(LightTaskPoleRelation.class).in(LightTaskPoleRelation::getPoleId, poleIds));
 
         /**
          * 鍒犻櫎鐏潌鏃ュ織璁板綍寮�濮�
          */
-        String content = "{鐏潌Code锛�" + pole.getDeviceCode() + "锛� 鐏潌鍚嶇О锛�" + pole.getPoleName() + " }";
+        String content = "{鐏潌id锛�" + poles + " }";
 
         StoreOperationRecordsUtils.storeOperationData(null, null, "鍒犻櫎鐏潌", content);
         /**
          * 鍒犻櫎鐏潌鏃ュ織璁板綍缁撴潫
          */
-        return removeById(poleId);
+        return removeByIds(poleIds);
     }
 
 
@@ -863,8 +867,8 @@
      *
      * @return 鏄惁鎴愬姛
      */
-    public boolean unBindPole(Long poleId, String deviceCode) {
-        return poleBindingService.unBindPole(poleId, deviceCode);
+    public boolean unBindPole(Long poleId, String deviceCode, Integer deviceType) {
+        return poleBindingService.unBindPole(poleId, deviceCode, deviceType);
     }
 
 
@@ -883,11 +887,21 @@
         if (deviceName.isEmpty()) {
             throw new BusinessException("璇ョ伅鏉哅ac涓虹┖");
         }
-        IRequestFrame build = FrameBuilder.builderA5().orderType(A5OrderEnum.REQUEST_LIGHT_DATA.getCode()).innerFrame(new A5LightResetReqInnerFrame()).build();
+        Integer deviceType = byId.getDeviceType();
+
+        IRequestFrame build = null;
+        if (deviceType < 2){
+            build = FrameBuilder.builderA5().orderType(A5OrderEnum.REQUEST_LIGHT_DATA.getCode()).innerFrame(new A5LightResetReqInnerFrame()).build();
+        }
+        else if (deviceType == 2){
+            build = FrameBuilder.builderA7().orderType(A7OrderEnum.REQUEST_PLC_DATA.getCode()).innerFrame(new A7PlcResetReqInnerFrame()).build();
+
+        }
+
         CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(deviceName, build);
+
         StoreOperationRecordsUtils.storeInnerFrameData(deviceName, "鐏潌鎭㈠鍑哄巶璁剧疆", build, commonFrame);
 
-        System.out.println(commonFrame.toString());
         IRequestFrame iRequestFrame = FrameBuilder.builderA2().innerFrame(new EmptyRequestInnerFrame()).orderType(A2OrderEnum.REQUEST_MAIN_BOARD_RESET.getCode()).build();
         CommonFrame rebootFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(deviceName, iRequestFrame);
         StoreOperationRecordsUtils.storeInnerFrameData(deviceName, "鐏潌閲嶅惎", iRequestFrame, commonFrame);
@@ -999,6 +1013,8 @@
             pole.setDeviceType(0);
         } else if ("01".equals(a1DeviceMacRespInnerFrame.getType())) {
             pole.setDeviceType(1);
+        } else if ("02".equals(a1DeviceMacRespInnerFrame.getType())) {
+            pole.setDeviceType(2);
         }
 
         pole.setPoleCode(generatePoleCode());
@@ -1006,12 +1022,24 @@
         boolean result = saveOrUpdate(pole);
 
         if (result) {
-            Light light = SpringContextHolder.getBean(LightService.class).getOne(Wrappers.lambdaQuery(Light.class).eq(Light::getDeviceCode, pole.getDeviceCode()).last("limit 1"));
-            if (light == null) {
-                light = new Light();
-                light.setDeviceCode(uniqueMac);
-                light.setLightCount(2);
-                SpringContextHolder.getBean(LightService.class).save(light);
+            if (pole.getDeviceType() < 2) {
+                Light light = SpringContextHolder.getBean(LightService.class).
+                        getOne(Wrappers.lambdaQuery(Light.class).eq(Light::getDeviceCode, pole.getDeviceCode()).last("limit 1"));
+                if (light == null) {
+                    light = new Light();
+                    light.setDeviceCode(uniqueMac);
+                    light.setLightCount(2);
+                    SpringContextHolder.getBean(LightService.class).save(light);
+                }
+            } else if (pole.getDeviceType() == 2) {
+                Plc plc = SpringContextHolder.getBean(PlcService.class).
+                        getOne(Wrappers.lambdaQuery(Plc.class).eq(Plc::getDeviceCode,pole.getDeviceCode()).last("limit 1"));
+                if (plc == null){
+                    plc = new Plc();
+                    plc.setDeviceCode(uniqueMac);
+                    plc.setPlcCount(3);
+                    SpringContextHolder.getBean(PlcService.class).save(plc);
+                }
             }
         }
 
@@ -1417,4 +1445,4 @@
 
     }
 
-}
\ No newline at end of file
+}

--
Gitblit v1.9.3