From 4e91adbb41c89688fe5b0ef03807cfe748a7d59d Mon Sep 17 00:00:00 2001
From: zhanzhiqin <895896009@qq.com>
Date: 星期四, 26 五月 2022 17:17:02 +0800
Subject: [PATCH] 角色

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/C3ChargingService.java |  194 ++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 168 insertions(+), 26 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/C3ChargingService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/C3ChargingService.java
index 8b1fd16..4e1d2bd 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/C3ChargingService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/C3ChargingService.java
@@ -18,13 +18,14 @@
 import com.sandu.ximon.admin.manager.iot.rrpc.mainboard.MainBoardInvokeSyncService;
 import com.sandu.ximon.admin.param.C3ChargingAddParam;
 import com.sandu.ximon.admin.param.C3ChargingParam;
-import com.sandu.ximon.admin.param.PoleBindingParam;
+import com.sandu.ximon.admin.security.SecurityUtils;
 import com.sandu.ximon.admin.utils.LogUtils;
 import com.sandu.ximon.admin.utils.RedisUtils;
+import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils;
+import com.sandu.ximon.admin.vo.EquipmentInfomation;
 import com.sandu.ximon.dao.bo.C3ChargingBo;
 import com.sandu.ximon.dao.domain.C3mCharging;
 import com.sandu.ximon.dao.domain.C3mChargingCharge;
-import com.sandu.ximon.dao.domain.Pole;
 import com.sandu.ximon.dao.domain.PoleBinding;
 import com.sandu.ximon.dao.mapper.C3mChargingMapper;
 import lombok.AllArgsConstructor;
@@ -32,6 +33,7 @@
 import org.springframework.stereotype.Service;
 
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Set;
@@ -56,7 +58,7 @@
      * @return 鏄惁鎴愬姛
      */
     public boolean updateReportState(String deviceName, String c3Mac, String statusBit, String deviceTemperature) {
-        C3mCharging one = getOne(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getPoleDevicesCode, deviceName));
+        C3mCharging one = getOne(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getMcuUdid, c3Mac));
         if (one != null) {
 //            one.setStatusBit(Integer.valueOf(statusBit));
             one.setDeviceTemperature(deviceTemperature);
@@ -95,15 +97,6 @@
                 c3mChargingChargeService.initCharge((c3mCharging1.getC3Id()).intValue());
             }
 
-            //娣诲姞缁戝畾鍏崇郴
-            Pole pole = poleService.getOne(Wrappers.lambdaQuery(Pole.class).eq(Pole::getDeviceCode, deviceName));
-            if(pole != null){
-                PoleBindingParam poleBindingParam = new PoleBindingParam();
-                poleBindingParam.setDeviceType(2);
-                poleBindingParam.setDeviceCode(mcuUdid);
-                bindingService.bindPole(pole.getId(), poleBindingParam);
-            }
-
         } else {
             //灏嗚澶囦俊鎭坊鍔犲埌鍏呯數妗╄澶囪〃
             one.setPoleDevicesCode(deviceName);
@@ -116,6 +109,28 @@
                 c3mChargingChargeService.initCharge((c3mCharging1.getC3Id()).intValue());
             }
         }
+//        /**
+//         * 娣诲姞缁戝畾鍏崇郴寮�濮�
+//         */
+//        Pole pole = poleService.getOne(Wrappers.lambdaQuery(Pole.class).eq(Pole::getDeviceCode, deviceName));
+//        if (pole == null) {
+//            Pole pole1 = new Pole();
+//            pole1.setDeviceCode(deviceName);
+//            pole1.setPoleName(deviceName);
+//            pole1.setPoleCode(poleService.generatePoleCode());
+//            poleService.save(pole1);
+//        }
+//
+//        Long poleId = poleService.getOne(Wrappers.lambdaQuery(Pole.class).eq(Pole::getDeviceCode, deviceName)).getId();
+//        PoleBindingParam poleBindingParam = new PoleBindingParam();
+//        poleBindingParam.setDeviceType(2);
+//        poleBindingParam.setDeviceCode(mcuUdid);
+//        bindingService.bindPole(poleId, poleBindingParam);
+
+        /**
+         * 娣诲姞缁戝畾鍏崇郴缁撴潫
+         */
+
         //鍚屾鏃堕棿鎴�
         String date = new SimpleDateFormat("yyMMddHHmmss").format(new Date());
         String s = SetCalendar(c3Mac, Integer.parseInt(date.substring(0, 2)), Integer.parseInt(date.substring(2, 4)),
@@ -170,7 +185,9 @@
      * @return
      */
     public List<C3ChargingBo> getC3ChargingListByKeyword(BaseConditionVO baseConditionVO, C3ChargingParam c3ChargingParam) {
-        PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
+        if (baseConditionVO != null) {
+            PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
+        }
         if (c3ChargingParam == null) {
             c3ChargingParam = new C3ChargingParam();
         }
@@ -180,12 +197,22 @@
             c3ChargingParam.setKeyword(c3ChargingParam.getKeyword().trim());
         }
 
-        List<C3ChargingBo> c3ChargingBoList = c3mChargingMapper.listC3mChargingDto(c3ChargingParam.getKeyword());
+        List<C3ChargingBo> c3ChargingBoList;
+        if (SecurityUtils.getClientId() == null) {
+            c3ChargingBoList = c3mChargingMapper.listC3mChargingDto(c3ChargingParam.getKeyword(), null);
+        } else {
+            c3ChargingBoList = c3mChargingMapper.listC3mChargingDto(c3ChargingParam.getKeyword(), SecurityUtils.getUserId());
+        }
         for (C3ChargingBo one : c3ChargingBoList) {
             String s = RedisUtils.getBean().get(C3mRedisConstant.C3_STATUS.getCode() + one.getC3Mac());
-            if(s != null){
-                one.setStatusBit(1);
-            }else{
+            if (s != null) {
+                try {
+                    A5C3HeartbeatReportInnerFrame.HeartBeatDataPackage beatDataPackage = JSON.parseObject(s, A5C3HeartbeatReportInnerFrame.HeartBeatDataPackage.class);
+                    one.setStatusBit((Integer.valueOf(beatDataPackage.getStatusBit())));
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            } else {
                 one.setStatusBit(0);
             }
 
@@ -195,17 +222,75 @@
 
     /**
      * 鏌ヨ鍏呯數妗�
+     *
      * @return
      */
-    public C3mCharging getByC3Mac(String c3Mac){
-        C3mCharging one = getOne(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getC3Mac, c3Mac));
+    public C3mCharging getByC3Mac(String udid) {
+        C3mCharging one = getOne(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getMcuUdid, udid));
         String s = RedisUtils.getBean().get(C3mRedisConstant.C3_STATUS.getCode() + one.getC3Mac());
-        if(s != null){
-            one.setStatusBit(1);
-        }else{
+        if (s != null) {
+            try {
+                A5C3HeartbeatReportInnerFrame.HeartBeatDataPackage beatDataPackage = JSON.parseObject(s, A5C3HeartbeatReportInnerFrame.HeartBeatDataPackage.class);
+                one.setStatusBit((Integer.valueOf(beatDataPackage.getStatusBit())));
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        } else {
             one.setStatusBit(0);
         }
         return one;
+    }
+
+    /**
+     * 棣栭〉鐏潌缁戝畾淇℃伅
+     *
+     * @return
+     */
+    public EquipmentInfomation getByC3MacInfo(String udid) {
+        EquipmentInfomation equipmentInfo = new EquipmentInfomation();
+        equipmentInfo.setEquipmentType("C3鍏呯數妗�");
+        if (udid == null || udid.trim().length() == 0) {
+            return equipmentInfo;
+        }
+        C3mCharging one = getOne(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getMcuUdid, udid));
+        if (one != null) {
+            String s = RedisUtils.getBean().get(C3mRedisConstant.C3_STATUS.getCode() + one.getC3Mac());
+            if (s != null) {
+                try {
+                    A5C3HeartbeatReportInnerFrame.HeartBeatDataPackage beatDataPackage = JSON.parseObject(s, A5C3HeartbeatReportInnerFrame.HeartBeatDataPackage.class);
+                    switch (beatDataPackage.getStatusBit()) {
+                        case "1":
+                            equipmentInfo.setEquipmentState("绌洪棽");
+                            break;
+                        case "2":
+                            equipmentInfo.setEquipmentState("鍏呯數涓�");
+                            break;
+                        case "3":
+                            equipmentInfo.setEquipmentState("鍏呯數涓柇锛岀瓑寰呮湇鍔″櫒纭");
+                            break;
+                        case "4":
+                            equipmentInfo.setEquipmentState("鍏呯數缁撴潫锛岀瓑寰呮湇鍔″櫒纭");
+                            break;
+                        case "5":
+                            equipmentInfo.setEquipmentState("鏈夋晠闅�");
+                            break;
+                        case "6":
+                            equipmentInfo.setEquipmentState("涓庡厖鐢垫々瀵规帴涓�");
+                            break;
+                        default:
+                            equipmentInfo.setEquipmentState("鏈煡");
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            } else {
+                equipmentInfo.setEquipmentState("绂荤嚎");
+            }
+            equipmentInfo.setEquipmentCreateTime(one.getUpdateTime());
+            equipmentInfo.setEquipmentMac(one.getMcuUdid());
+            equipmentInfo.setEquipmentName(one.getC3Name());
+        }
+        return equipmentInfo;
     }
 
 
@@ -228,6 +313,7 @@
             throw new BusinessException("C3鍏呯數妗╃‖浠秏cu_udid涓嶅瓨鍦�");
         }
         CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
+        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3甯�-寮�濮嬪厖鐢�", a5Frame, commonFrame);
         System.out.println(commonFrame + "            -----commonFrame");
 
 
@@ -261,7 +347,7 @@
             throw new BusinessException("C3鍏呯數妗╃‖浠秏cu_udid涓嶅瓨鍦�");
         }
         CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
-
+        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3甯�-缁撴潫鍏呯數", a5Frame, commonFrame);
         System.out.println(commonFrame + "            -----commonFrame");
 
         A5C3OperationReportInnerFrame operationReportInnerFrame = new A5C3OperationReportInnerFrame().transformFrame(commonFrame.getPayload());
@@ -291,6 +377,8 @@
             throw new BusinessException("C3鍏呯數妗╃‖浠秏cu_udid涓嶅瓨鍦�");
         }
         CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
+        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3甯�-鍚屾缁撴潫", a5Frame, commonFrame);
+
 
         System.out.println(commonFrame + "            -----commonFrame");
 
@@ -319,6 +407,8 @@
             throw new BusinessException("C3鍏呯數妗╃‖浠秏cu_udid涓嶅瓨鍦�");
         }
         CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
+        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3甯�-浜岀淮鐮�", a5Frame, commonFrame);
+
 
         System.out.println(commonFrame + "            -----commonFrame");
 
@@ -348,6 +438,8 @@
             throw new BusinessException("C3鍏呯數妗╃‖浠秏cu_udid涓嶅瓨鍦�");
         }
         CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
+        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3甯�-鐗堟湰鏌ヨ", a5Frame, commonFrame);
+
 
         System.out.println(commonFrame + "            -----commonFrame");
 
@@ -377,6 +469,7 @@
             throw new BusinessException("C3鍏呯數妗╃‖浠秏cu_udid涓嶅瓨鍦�");
         }
         CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
+        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3甯�-鏌ヨ蹇冭烦鍖呴棿闅旀椂闂�", a5Frame, commonFrame);
 
         System.out.println(commonFrame + "            -----commonFrame");
 
@@ -406,6 +499,8 @@
             throw new BusinessException("C3鍏呯數妗╃‖浠秏cu_udid涓嶅瓨鍦�");
         }
         CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
+        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3甯�-鏌ヨ鐢靛帇/鐢垫祦甯告暟", a5Frame, commonFrame);
+
 
         System.out.println(commonFrame + "            -----commonFrame");
 
@@ -435,6 +530,8 @@
             throw new BusinessException("C3鍏呯數妗╃‖浠秏cu_udid涓嶅瓨鍦�");
         }
         CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
+        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3甯�-鏌ヨ鍦板潃", a5Frame, commonFrame);
+
 
         System.out.println(commonFrame + "            -----commonFrame");
 
@@ -464,6 +561,8 @@
             throw new BusinessException("C3鍏呯數妗╃‖浠秏cu_udid涓嶅瓨鍦�");
         }
         CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
+        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3甯�-鏌ヨ鏁呴殰鐮�", a5Frame, commonFrame);
+
 
         System.out.println(commonFrame + "            -----commonFrame");
 
@@ -493,6 +592,8 @@
             throw new BusinessException("C3鍏呯數妗╃‖浠秏cu_udid涓嶅瓨鍦�");
         }
         CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
+        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3甯�-璇诲彇蹇冭烦鍖�", a5Frame, commonFrame);
+
 
         System.out.println(commonFrame + "            -----commonFrame");
 
@@ -526,6 +627,8 @@
             throw new BusinessException("C3鍏呯數妗╃‖浠秏cu_udid涓嶅瓨鍦�");
         }
         CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
+        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3甯�-璁剧疆蹇冭烦鍖呴棿闅旀椂闂�", a5Frame, commonFrame);
+
 
         System.out.println(commonFrame + "            -----commonFrame");
 
@@ -557,6 +660,8 @@
             throw new BusinessException("C3鍏呯數妗╃‖浠秏cu_udid涓嶅瓨鍦�");
         }
         CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
+        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3甯�-璁剧疆鐢靛帇/鐢垫祦甯告暟", a5Frame, commonFrame);
+
 
         System.out.println(commonFrame + "            -----commonFrame");
 
@@ -597,6 +702,8 @@
 
 
         CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
+        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3甯�-璁剧疆鍦板潃", a5Frame, commonFrame);
+
 
         System.out.println(commonFrame + "            -----commonFrame");
 
@@ -634,6 +741,7 @@
             throw new BusinessException("C3鍏呯數妗╃‖浠秏cu_udid涓嶅瓨鍦�");
         }
         CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
+        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3甯�-璁剧疆鏃ュ巻", a5Frame, commonFrame);
 
         System.out.println(commonFrame + "            -----commonFrame");
 
@@ -665,6 +773,7 @@
             throw new BusinessException("C3鍏呯數妗╃‖浠秏cu_udid涓嶅瓨鍦�");
         }
         CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
+        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3甯�-娓呴櫎鏁呴殰鐮佷笂鎶�", a5Frame, commonFrame);
 
         System.out.println(commonFrame + "            -----commonFrame");
 
@@ -696,6 +805,7 @@
             throw new BusinessException("C3鍏呯數妗╃‖浠秏cu_udid涓嶅瓨鍦�");
         }
         CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
+        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3甯�-鎭㈠鍑哄巶璁剧疆", a5Frame, commonFrame);
 
         System.out.println(commonFrame + "            -----commonFrame");
 
@@ -724,7 +834,8 @@
             throw new BusinessException("C3鍏呯數妗╃‖浠秏cu_udid涓嶅瓨鍦�");
         }
         CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame);
-//        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC("32313243305008ff1a06ffff", a5Frame);
+        StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3甯�-杞噸鍚�", a5Frame, commonFrame);
+
 
         System.out.println(commonFrame + "            -----commonFrame");
 
@@ -752,7 +863,23 @@
             c3mCharging.setC3Name(c3ChargingAddParam.getC3Name());
         }
         c3mCharging.setC3Mac(c3ChargingAddParam.getC3Mac());
-        return save(c3mCharging);
+        /**
+         * 娣诲姞鍏呯數妗� 鏃ュ織璁板綍寮�濮�
+         */
+        List<String> listCode = new ArrayList<>(1);
+        listCode.add(c3mCharging.getMcuUdid());
+        String content = "{璁惧code锛�" + c3mCharging.getMcuUdid() + "璁惧鍚�:" + c3mCharging.getC3Name() +
+                "}";
+
+        StoreOperationRecordsUtils.storeOperationData(listCode, null, "娣诲姞鍏呯數妗�", content);
+        /**
+         * 娣诲姞鍏呯數妗� 鏃ュ織璁板綍缁撴潫
+         */
+
+        return
+
+                save(c3mCharging);
+
     }
 
     public boolean updateC3ChargingName(C3ChargingAddParam c3ChargingAddParam) {
@@ -767,6 +894,21 @@
         C3mCharging c3mCharging = new C3mCharging();
         c3mCharging.setC3Id(c3ChargingAddParam.getC3Id());
         c3mCharging.setC3Name(c3ChargingAddParam.getC3Name());
+
+        /**
+         * 淇敼鍏呯數妗� 鏃ュ織璁板綍寮�濮�
+         */
+        List<String> listCode = new ArrayList<>(1);
+        listCode.add(c3mCharging.getMcuUdid());
+        String content = "{璁惧code锛�" + c3mCharging.getMcuUdid() + "璁惧鍘熷悕:" + one.getC3Name() + "鏇存敼鍚庣殑璁惧鍚�:" + c3mCharging.getC3Name() +
+                "}";
+
+        StoreOperationRecordsUtils.storeOperationData(listCode, null, "缂栬緫鍏呯數妗�", content);
+        /**
+         * 淇敼鍏呯數妗� 鏃ュ織璁板綍缁撴潫
+         */
+
+
         return updateById(c3mCharging);
     }
 
@@ -775,7 +917,7 @@
         if (one == null) {
             throw new BusinessException("鏈壘鍒扮粦瀹氬叧绯�");
         }
-        return getOne(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getC3Mac, one.getDeviceCode()));
+        return getOne(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getMcuUdid, one.getDeviceCode()));
     }
 
 

--
Gitblit v1.9.3