From 60f74b306659cba1a8ed7378f9df54a71e48a614 Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期三, 28 六月 2023 18:04:09 +0800
Subject: [PATCH] 临时

---
 app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java |  125 ++++++++++++++++++++++++++++++++++++-----
 1 files changed, 109 insertions(+), 16 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
index 245bdbc..445dc0c 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
@@ -1,13 +1,27 @@
 package com.hdl.photovoltaic.other;
 
 
+import android.text.TextUtils;
+
+import com.alibaba.fastjson.JSON;
 import com.google.gson.Gson;
+import com.hdl.photovoltaic.HDLApp;
 import com.hdl.photovoltaic.config.UserConfigManage;
+import com.hdl.photovoltaic.listener.CloudCallBeak;
+import com.hdl.photovoltaic.ui.bean.HouseIdBean;
 import com.hdl.photovoltaic.uni.HDLUniMP;
 import com.hdl.photovoltaic.uni.HDLUniMPSDKManager;
+import com.hdl.photovoltaic.uni.UniToAndroidBean;
+import com.hdl.photovoltaic.utils.WifiUtils;
+import com.hdl.sdk.link.common.exception.HDLLinkException;
+import com.hdl.sdk.link.core.bean.gateway.GatewayBean;
+import com.hdl.sdk.link.core.callback.GatewayCallBack;
+import com.hdl.sdk.link.core.connect.HDLModBusConnect;
 
 import org.json.JSONObject;
 
+
+import java.util.List;
 
 import io.dcloud.feature.unimp.DCUniMPJSCallback;
 
@@ -44,18 +58,96 @@
      */
     @Override
     public void onOtherUniMPEventReceive(String appId, String event, Object data, DCUniMPJSCallback callback) {
-        if (!HDLUniMP.UNI_APP_ID.equals(appId)) {
-            return;
-        }
         try {
-            org.json.JSONObject jsonObject = null;
-            if (data != null) {
-                jsonObject = new org.json.JSONObject(data.toString());
+            if (!HDLUniMP.UNI_APP_ID.equals(appId)) {
+                return;
             }
-            //浣忓畢妯″潡
-            if (HDLUniMP.UNI_EVENT_REPLY_HOME_LIST.equals(event)) {
+            UniToAndroidBean uniToAndroidBean = com.alibaba.fastjson.JSONObject.parseObject(JSON.toJSONString(data), UniToAndroidBean.class);
+
+            if (HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL.equals(event)) {
+                //浣忓畢妯″潡
+                switch (uniToAndroidBean.getType()) {
+                    case HDLUniMP.UNI_EVENT_REPLY_HOME_CREATION: {
+                        //鍒涘缓
+                        HdlResidenceLogic.getInstance().getResidenceIdList("", "", new CloudCallBeak<List<HouseIdBean>>() {
+                            @Override
+                            public void onSuccess(List<HouseIdBean> list) {
+                                HdlResidenceLogic.getInstance().setHouseIdList(list);
+                            }
+
+                            @Override
+                            public void onFailure(Exception exception) {
+
+                            }
+                        });
+
+                    }
+                    break;
+                    case HDLUniMP.UNI_EVENT_REPLY_HOME_DETAILS: {
+                        //璇︽儏
+                    }
+                    break;
+
+                }
                 if (callback != null) {
                     uniCallbackData(null, "0", "", callback);
+                }
+            } else if (HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODEL.equals(event)) {
+                //璁惧妯″潡
+                switch (uniToAndroidBean.getType()) {
+                    case HDLUniMP.UNI_EVENT_REPLY_DEVICE_ADD: {
+                        //娣诲姞
+                    }
+                    break;
+                    case HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST: {
+                        //缃戝叧鎼滅储
+                        HdlDeviceLogic.getInstance().searchGateway(new GatewayCallBack() {
+                            @Override
+                            public void onSuccess(List<GatewayBean> gatewayBeanList) {
+                                HDLUniMP.UniCallBackBaseBean callBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
+                                callBackBaseBean.setTopic(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL);
+                                callBackBaseBean.setType(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_LIST);
+                                callBackBaseBean.setData(gatewayBeanList);
+                                sendUni(callBackBaseBean);
+                            }
+
+
+                            @Override
+                            public void onError(HDLLinkException e) {
+                                //鍙戦�佸け璐�
+                            }
+                        });
+                    }
+                    break;
+                    case HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODBUS_SEND:{
+                        //鍙戦�乵odbus鍗忚
+                        HDLModBusConnect.getInstance().Send(uniToAndroidBean.getGatewayOid(),null,);
+                    }
+                }
+
+            } else if (HDLUniMP.UNI_EVENT_REPLY_WIFI_MODEL.equals(event)) {
+                WifiUtils wifiUtils = new WifiUtils(HDLApp.getInstance());
+                //wifi妯″潡
+                switch (uniToAndroidBean.getType()) {
+                    case HDLUniMP.UNI_EVENT_REPLY_WIFI_LIST: {
+                        //鑾峰彇wifi鍒楄〃
+                        if (callback != null) {
+                            uniCallbackData(wifiUtils.getScanResult(), "0", "", callback);
+                        }
+                    }
+                    break;
+                    case HDLUniMP.UNI_EVENT_REPLY_WIFI_INFO: {
+                        //褰撳墠wifi璇︽儏
+                        if (callback != null) {
+                            uniCallbackData(wifiUtils.getCurrentConnectWifiInfo(), "0", "", callback);
+                        }
+                    }
+                    break;
+                    case HDLUniMP.UNI_EVENT_REPLY_WIFI_CONNECT: {
+                        //wifi杩炴帴
+                    }
+                    break;
+
                 }
             }
             HdlLogLogic.print("uni===鍘熺敓鎺ユ敹uni鍙戞潵鐨勬暟鎹�", event + "\r\n" + data);
@@ -81,15 +173,9 @@
     /**
      * 鍘熺敓銆愪富鍔ㄣ�戝悜灏忕▼搴忓彂閫侀�氱煡浜嬩欢
      * 娉ㄦ剰锛氶渶瑕佹彁鍓嶅皬绋嬪簭鍦ㄨ繍琛屾墠鍙垚鍔�
-     *
-     * @param topic 涓婚
-     * @param body  闄勪欢鏁版嵁(娌℃湁鏁版嵁濉玭ull)
      */
-    public void sendUni(String topic, String body) {
+    public void sendUni(HDLUniMP.UniCallBackBaseBean callBackBaseBean) {
         try {
-            HDLUniMP.UniCallBackBaseBean callBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
-            callBackBaseBean.setTopic(topic);
-            callBackBaseBean.setData(body);
             HDLUniMPSDKManager.getInstance().sendUniMPEvent(HDLUniMP.UNI_APP_ID, HDLUniMP.UNI_APP_ID, getJSONObject(callBackBaseBean));
         } catch (Exception e) {
             HdlLogLogic.print("uni===鍘熺敓涓诲姩鍚戝皬绋嬪簭鍙戦�侀�氱煡浜嬩欢", e.getMessage());
@@ -145,7 +231,7 @@
             uniCallBackBaseBean.setMes(msg);
             uniCallBackBaseBean.setData(obj);
             if (callback != null) {
-                callback.invoke(uniCallBackBaseBean);
+                callback.invoke(getJSONObject(uniCallBackBaseBean));
             }
         } catch (Exception e) {
             HdlLogLogic.print("uni===缁勮uni鍙戦�佹暟鎹牸寮�", e.getMessage());
@@ -177,7 +263,14 @@
      */
     private JSONObject getJSONObject(Object obj) {
         try {
+            if (obj == null) {
+                return new JSONObject();
+            }
+            if (TextUtils.isEmpty(obj.toString())) {
+                return new JSONObject();
+            }
             String json = new Gson().toJson(obj);
+
             return new JSONObject(json);
         } catch (Exception e) {
             return new JSONObject();

--
Gitblit v1.8.0