From ea8e8e7dd5f10cff4054f5fde8fd3961aaac1834 Mon Sep 17 00:00:00 2001
From: zhanzhiqin <895896009@qq.com>
Date: 星期五, 14 十月 2022 16:55:30 +0800
Subject: [PATCH] 大气设备农耕

---
 ximon-admin/src/main/java/com/sandu/ximon/admin/service/AirEquipmentNongGengService.java |  251 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 251 insertions(+), 0 deletions(-)

diff --git a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/AirEquipmentNongGengService.java b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/AirEquipmentNongGengService.java
index ceb5e2a..541d5be 100644
--- a/ximon-admin/src/main/java/com/sandu/ximon/admin/service/AirEquipmentNongGengService.java
+++ b/ximon-admin/src/main/java/com/sandu/ximon/admin/service/AirEquipmentNongGengService.java
@@ -1,12 +1,36 @@
 package com.sandu.ximon.admin.service;
 
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.github.pagehelper.PageHelper;
+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.manager.iot.frame.A5Frame;
+import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5AtmosphereHeartBeatTimeReportInnerFrame;
+import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5AtmosphereOperationReportInnerFrame;
+import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5AtmosphereQueryVersionReportInnerFrame;
+import com.sandu.ximon.admin.manager.iot.frame.inner.request.AtmosphereQueryHeartBeatTimeReqInnerFrame;
+import com.sandu.ximon.admin.manager.iot.frame.inner.request.AtmosphereQueryVersionReqInnerFrame;
+import com.sandu.ximon.admin.manager.iot.frame.inner.request.AtmosphereRebootReqInnerFrame;
+import com.sandu.ximon.admin.manager.iot.frame.inner.request.AtmosphereSetHeartBeatTimeReqInnerFrame;
+import com.sandu.ximon.admin.manager.iot.rrpc.dto.CommonFrame;
+import com.sandu.ximon.admin.manager.iot.rrpc.enums.A5OrderEnum;
+import com.sandu.ximon.admin.manager.iot.rrpc.enums.AtmoFunctionCode;
+import com.sandu.ximon.admin.manager.iot.rrpc.mainboard.MainBoardInvokeSyncService;
+import com.sandu.ximon.admin.security.SecurityUtils;
+import com.sandu.ximon.admin.utils.RedisUtils;
+import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils;
+import com.sandu.ximon.admin.utils.StringUtil;
+import com.sandu.ximon.dao.bo.AirEquipmentNongGengBo;
 import com.sandu.ximon.dao.domain.AirEquipment;
 import com.sandu.ximon.dao.domain.AirEquipmentNongGeng;
 import com.sandu.ximon.dao.mapper.AirEquipmentNongGengMapper;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @author ZZQ
@@ -15,6 +39,9 @@
 @Service
 @AllArgsConstructor
 public class AirEquipmentNongGengService extends BaseServiceImpl<AirEquipmentNongGengMapper, AirEquipmentNongGeng> {
+    private final AirEquipmentNongGengMapper airEquipmentNongGengMapper;
+
+
     /**
      * 娣诲姞澶ф皵璁惧鏁版嵁
      *
@@ -23,7 +50,231 @@
     public void addAirEquipment(AirEquipmentNongGeng airEquipmentNongGeng) {
         AirEquipmentNongGeng one = getOne(Wrappers.lambdaQuery(AirEquipmentNongGeng.class).eq(AirEquipmentNongGeng::getMac, airEquipmentNongGeng.getMac()));
         if (one == null) {
+            //TODO
             save(airEquipmentNongGeng);
+            /**
+             * 娣诲姞鍐滆�曞ぇ姘旇澶� 鏃ュ織璁板綍寮�濮�
+             */
+            List<String> listCode = new ArrayList<>(1);
+            listCode.add(airEquipmentNongGeng.getMac());
+            String content = "{ 璁惧id:" + airEquipmentNongGeng.getId() + "璁惧code锛�" + airEquipmentNongGeng.getMac() +
+                    "}";
+
+            StoreOperationRecordsUtils.storeOperationData(listCode, null, "娣诲姞鍐滆�曞ぇ姘旇澶�", content);
+            /**
+             * 娣诲姞鍐滆�曞ぇ姘旇澶� 鏃ュ織璁板綍缁撴潫
+             */
         }
     }
+
+    /**
+     * 妯$硦鏌ヨ
+     */
+    public List<AirEquipmentNongGengBo> listAirEquipmentByKeyword(BaseConditionVO baseConditionVO, String keyword) {
+        if (baseConditionVO != null) {
+            PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
+        }
+        List<AirEquipmentNongGengBo> airEquipmentBos;
+//        if (SecurityUtils.getClientId() == null) {
+//            airEquipmentBos = airEquipmentNongGengMapper.listAirEquipmentByIds(keyword, null);
+//        } else {
+//            airEquipmentBos = airEquipmentNongGengMapper.listAirEquipmentByIds(keyword, SecurityUtils.getUserId());
+//        }
+
+        if (SecurityUtils.getClientId() == null) {
+            airEquipmentBos = airEquipmentNongGengMapper.listAirEquipmentByIds(keyword, null);
+        } else {
+            airEquipmentBos = airEquipmentNongGengMapper.listAirEquipmentByIds(keyword, SecurityUtils.getUserId());
+        }
+
+        return null;
+//        return airEquipmentBos;
+    }
+
+    /**
+     * 澶ф皵璁惧鍒楄〃锛堝啘鑰曪紝鐢ㄤ簬棣栭〉鏁版嵁缁熻锛�
+     */
+    public List<AirEquipmentNongGengBo> listAirEquipmentOnHome() {
+//        List<AirEquipmentNongGengBo> airEquipmentBos;
+//        if (SecurityUtils.getClientId() == null) {
+//            airEquipmentBos = airEquipmentNongGengMapper.listAirEquipmentByIds(null, null);
+//        } else {
+//            airEquipmentBos = airEquipmentNongGengMapper.listAirEquipmentByIds(null, SecurityUtils.getUserId());
+//        }
+
+//        return airEquipmentBos;
+        return null;
+    }
+
+    /**
+     * 鍒犻櫎澶ф皵璁惧鏁版嵁
+     *
+     * @param Id
+     * @return
+     */
+    public boolean deleteAirEquipment(Long Id) {
+        AirEquipmentNongGeng airEquipmentNongGeng = getById(Id);
+        if (airEquipmentNongGeng == null) {
+            throw new BusinessException("鎵句笉鍒板ぇ姘旇澶囨暟鎹�");
+        }
+
+        /**
+         * 鍒犻櫎鍐滆�曞ぇ姘旇澶� 鏃ュ織璁板綍寮�濮�
+         */
+        List<String> listCode = new ArrayList<>(1);
+        listCode.add(airEquipmentNongGeng.getMac());
+        String content = "{ 璁惧id:" + airEquipmentNongGeng.getId() + "璁惧code锛�" + airEquipmentNongGeng.getMac() +
+                "}";
+
+        StoreOperationRecordsUtils.storeOperationData(listCode, null, "鍒犻櫎鍐滆�曞ぇ姘旇澶�", content);
+        /**
+         * 鍒犻櫎鍐滆�曞ぇ姘旇澶� 鏃ュ織璁板綍缁撴潫
+         */
+        return removeById(Id);
+    }
+
+    /**
+     * 鏍规嵁Mac澶ф皵璁惧鏁版嵁璇︽儏
+     */
+    public AirEquipmentNongGeng getAirEquipment(String mac) {
+        AirEquipmentNongGeng one = getOne(Wrappers.lambdaQuery(AirEquipmentNongGeng.class).eq(AirEquipmentNongGeng::getMac, mac));
+        if (RedisUtils.getBean().get(AtmoFunctionCode.AIR_HEARTBEAT_NONG_GENG_STATE.getCode() + mac) != null) {
+            one.setState(1);
+        } else {
+            one.setState(0);
+        }
+        return one;
+    }
+
+    /**
+     * 璁剧疆澶ф皵璁惧蹇冭烦鍖呴棿闅旀椂闂�
+     *
+     * @param mac
+     * @param time
+     */
+    public String setHeartBeatTime(String mac, Integer time) {
+        if (StringUtil.strIsNullOrEmpty(mac)) {
+            throw new BusinessException("鐏潌mac鍙傛暟閿欒锛�");
+        }
+        if (time == null) {
+            throw new BusinessException("蹇冭烦鍖呴棿闅旀椂闂翠笉鑳戒负绌猴紒");
+        }
+
+        if (time < 30) {
+            throw new BusinessException("蹇冭烦鍖呴棿闅旀椂闂翠笉鑳藉皯浜�30s锛�");
+        }
+        AirEquipmentNongGeng airEquipmentNongGeng = SpringContextHolder.getBean(AirEquipmentNongGengService.class).
+                getOne(Wrappers.lambdaQuery(AirEquipmentNongGeng.class).eq(AirEquipmentNongGeng::getMac, mac).last("limit 1"));
+        if (airEquipmentNongGeng == null) {
+            throw new BusinessException("澶ф皵璁惧涓嶅瓨鍦紒");
+        }
+
+        AtmosphereSetHeartBeatTimeReqInnerFrame atmosphereSetHeartBeatTimeReqInnerFrame = new AtmosphereSetHeartBeatTimeReqInnerFrame(time);
+        A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_ATMOSPHERE_DATA.getCode(), atmosphereSetHeartBeatTimeReqInnerFrame);
+        System.out.println(a5Frame + "          --------a5Frame");
+        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(mac, a5Frame);
+        System.out.println(commonFrame + "         -----------commonFrame");
+
+        A5AtmosphereOperationReportInnerFrame a5AtmosphereOperationReportInnerFrame
+                = new A5AtmosphereOperationReportInnerFrame().transformFrame(commonFrame.getPayload());
+        if (a5AtmosphereOperationReportInnerFrame != null && a5AtmosphereOperationReportInnerFrame.isValidate()) {
+            return a5AtmosphereOperationReportInnerFrame.getState();
+        } else {
+            throw new BusinessException("鏁版嵁鏍¢獙寮傚父锛�");
+        }
+    }
+
+    /**
+     * 鏌ヨ澶ф皵璁惧蹇冭烦鍖呮椂闂�
+     */
+    public String QueryHeartBeatTime(String mac) {
+        if (StringUtil.strIsNullOrEmpty(mac)) {
+            throw new BusinessException("鐏潌mac鍙傛暟閿欒锛�");
+        }
+        AirEquipmentNongGeng airEquipmentNongGeng = SpringContextHolder.getBean(AirEquipmentNongGengService.class).
+                getOne(Wrappers.lambdaQuery(AirEquipmentNongGeng.class).eq(AirEquipmentNongGeng::getMac, mac).last("limit 1"));
+        if (airEquipmentNongGeng == null) {
+            throw new BusinessException("澶ф皵璁惧涓嶅瓨鍦紒");
+        }
+
+        AtmosphereQueryHeartBeatTimeReqInnerFrame atmosphereQueryHeartBeatTimeReqInnerFrame = new AtmosphereQueryHeartBeatTimeReqInnerFrame();
+        A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_ATMOSPHERE_DATA.getCode(), atmosphereQueryHeartBeatTimeReqInnerFrame);
+        System.out.println(a5Frame + "          --------a5Frame");
+        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(mac, a5Frame);
+        System.out.println(commonFrame + "         -----------commonFrame");
+
+        A5AtmosphereHeartBeatTimeReportInnerFrame a5AtmosphereHeartBeatTimeReportInnerFrame
+                = new A5AtmosphereHeartBeatTimeReportInnerFrame().transformFrame(commonFrame.getPayload());
+
+        if (a5AtmosphereHeartBeatTimeReportInnerFrame != null && a5AtmosphereHeartBeatTimeReportInnerFrame.isValidate()) {
+            return "璇ュぇ姘旇澶囧績璺冲寘闂撮殧鏃堕棿涓猴細" + a5AtmosphereHeartBeatTimeReportInnerFrame.getIntervalTime() + "s";
+        } else {
+            throw new BusinessException("鏁版嵁鏍¢獙寮傚父锛�");
+        }
+    }
+
+    /**
+     * 鏌ヨ杞‖浠剁増鏈�
+     *
+     * @param mac
+     * @return
+     */
+    public String QueryVersion(String mac) {
+        if (StringUtil.strIsNullOrEmpty(mac)) {
+            throw new BusinessException("鐏潌mac鍙傛暟閿欒锛�");
+        }
+        AirEquipmentNongGeng airEquipmentNongGeng = SpringContextHolder.getBean(AirEquipmentNongGengService.class).
+                getOne(Wrappers.lambdaQuery(AirEquipmentNongGeng.class).eq(AirEquipmentNongGeng::getMac, mac).last("limit 1"));
+        if (airEquipmentNongGeng == null) {
+            throw new BusinessException("澶ф皵璁惧涓嶅瓨鍦紒");
+        }
+
+        AtmosphereQueryVersionReqInnerFrame atmosphereQueryVersionReqInnerFrame = new AtmosphereQueryVersionReqInnerFrame();
+        A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_ATMOSPHERE_DATA.getCode(), atmosphereQueryVersionReqInnerFrame);
+        System.out.println(a5Frame + "          --------a5Frame");
+        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(mac, a5Frame);
+        System.out.println(commonFrame + "         -----------commonFrame");
+
+        A5AtmosphereQueryVersionReportInnerFrame a5AtmosphereQueryVersionReportInnerFrame =
+                new A5AtmosphereQueryVersionReportInnerFrame().transformFrame(commonFrame.getPayload());
+        if (a5AtmosphereQueryVersionReportInnerFrame != null && a5AtmosphereQueryVersionReportInnerFrame.isValidate()) {
+            return a5AtmosphereQueryVersionReportInnerFrame.getVersion();
+        } else {
+            throw new BusinessException("鏁版嵁鏍¢獙寮傚父锛�");
+        }
+    }
+
+    /**
+     * 杞噸鍚�
+     *
+     * @param mac
+     * @return
+     */
+    public String Reboot(String mac) {
+        if (StringUtil.strIsNullOrEmpty(mac)) {
+            throw new BusinessException("鐏潌mac鍙傛暟閿欒锛�");
+        }
+
+        AirEquipmentNongGeng airEquipmentNongGeng = SpringContextHolder.getBean(AirEquipmentNongGengService.class).
+                getOne(Wrappers.lambdaQuery(AirEquipmentNongGeng.class).eq(AirEquipmentNongGeng::getMac, mac).last("limit 1"));
+        if (airEquipmentNongGeng == null) {
+            throw new BusinessException("澶ф皵璁惧涓嶅瓨鍦紒");
+        }
+
+        AtmosphereRebootReqInnerFrame atmosphereRebootReqInnerFrame = new AtmosphereRebootReqInnerFrame();
+        A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_ATMOSPHERE_DATA.getCode(), atmosphereRebootReqInnerFrame);
+        System.out.println(a5Frame + "          --------a5Frame");
+        CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(mac, a5Frame);
+        System.out.println(commonFrame + "         -----------commonFrame");
+
+        A5AtmosphereOperationReportInnerFrame a5AtmosphereOperationReportInnerFrame =
+                new A5AtmosphereOperationReportInnerFrame().transformFrame(commonFrame.getPayload());
+
+        if (a5AtmosphereOperationReportInnerFrame != null && a5AtmosphereOperationReportInnerFrame.isValidate()) {
+            return a5AtmosphereOperationReportInnerFrame.getState();
+        } else {
+            throw new BusinessException("鏁版嵁鏍¢獙寮傚父锛�");
+        }
+    }
+
 }

--
Gitblit v1.9.3