From 814a2405f075573837f5f1aa296a0882c68385f2 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期三, 28 六月 2023 18:56:43 +0800
Subject: [PATCH] 2023年06月28日18:56:38

---
 app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java |   83 +++++++++++++++++++++--------------------
 1 files changed, 43 insertions(+), 40 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 445dc0c..3179558 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
@@ -6,6 +6,8 @@
 import com.alibaba.fastjson.JSON;
 import com.google.gson.Gson;
 import com.hdl.photovoltaic.HDLApp;
+import com.hdl.photovoltaic.bean.BaseEventBus;
+import com.hdl.photovoltaic.config.ConstantManage;
 import com.hdl.photovoltaic.config.UserConfigManage;
 import com.hdl.photovoltaic.listener.CloudCallBeak;
 import com.hdl.photovoltaic.ui.bean.HouseIdBean;
@@ -18,6 +20,7 @@
 import com.hdl.sdk.link.core.callback.GatewayCallBack;
 import com.hdl.sdk.link.core.connect.HDLModBusConnect;
 
+import org.greenrobot.eventbus.EventBus;
 import org.json.JSONObject;
 
 
@@ -62,25 +65,16 @@
             if (!HDLUniMP.UNI_APP_ID.equals(appId)) {
                 return;
             }
-            UniToAndroidBean uniToAndroidBean = com.alibaba.fastjson.JSONObject.parseObject(JSON.toJSONString(data), UniToAndroidBean.class);
-
+            String type = getKeyValue("type", data);
             if (HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL.equals(event)) {
                 //浣忓畢妯″潡
-                switch (uniToAndroidBean.getType()) {
+                switch (type) {
                     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) {
-
-                            }
-                        });
-
+                        //EventBus浜嬩欢鍒嗗彂
+                        BaseEventBus baseEventBus = new BaseEventBus();
+                        baseEventBus.setType(ConstantManage.EVENTBUS_POST_HOME_CREATED);
+                        EventBus.getDefault().post(baseEventBus);
                     }
                     break;
                     case HDLUniMP.UNI_EVENT_REPLY_HOME_DETAILS: {
@@ -94,7 +88,7 @@
                 }
             } else if (HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODEL.equals(event)) {
                 //璁惧妯″潡
-                switch (uniToAndroidBean.getType()) {
+                switch (type) {
                     case HDLUniMP.UNI_EVENT_REPLY_DEVICE_ADD: {
                         //娣诲姞
                     }
@@ -105,10 +99,9 @@
                             @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);
+                                sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, callBackBaseBean);
                             }
 
 
@@ -119,16 +112,16 @@
                         });
                     }
                     break;
-                    case HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODBUS_SEND:{
+                    case HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODBUS_SEND: {
                         //鍙戦�乵odbus鍗忚
-                        HDLModBusConnect.getInstance().Send(uniToAndroidBean.getGatewayOid(),null,);
+//                        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()) {
+                switch (type) {
                     case HDLUniMP.UNI_EVENT_REPLY_WIFI_LIST: {
                         //鑾峰彇wifi鍒楄〃
                         if (callback != null) {
@@ -173,10 +166,13 @@
     /**
      * 鍘熺敓銆愪富鍔ㄣ�戝悜灏忕▼搴忓彂閫侀�氱煡浜嬩欢
      * 娉ㄦ剰锛氶渶瑕佹彁鍓嶅皬绋嬪簭鍦ㄨ繍琛屾墠鍙垚鍔�
+     *
+     * @param topic            涓婚澶х被(濡�:UNI_EVENT_REPLY_HOME_MODEL)
+     * @param callBackBaseBean 鈥斺��
      */
-    public void sendUni(HDLUniMP.UniCallBackBaseBean callBackBaseBean) {
+    public void sendUni(String topic, HDLUniMP.UniCallBackBaseBean callBackBaseBean) {
         try {
-            HDLUniMPSDKManager.getInstance().sendUniMPEvent(HDLUniMP.UNI_APP_ID, HDLUniMP.UNI_APP_ID, getJSONObject(callBackBaseBean));
+            HDLUniMPSDKManager.getInstance().sendUniMPEvent(HDLUniMP.UNI_APP_ID, topic, getJSONObject(callBackBaseBean));
         } catch (Exception e) {
             HdlLogLogic.print("uni===鍘熺敓涓诲姩鍚戝皬绋嬪簭鍙戦�侀�氱煡浜嬩欢", e.getMessage());
         }
@@ -240,22 +236,6 @@
 
     }
 
-
-    /**
-     * 鑾峰彇uni鍙戦�佸璞�
-     *
-     * @param obj  闄勫姞鏁版嵁
-     * @param code 鐘舵�佺爜
-     * @param msg  缁撴灉鎻忚堪鐨勪俊鎭�
-     */
-    private HDLUniMP.UniCallBackBaseBean getUniCallBackBaseBean(Object obj, String code, String msg) {
-        HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
-        uniCallBackBaseBean.setCode(code);
-        uniCallBackBaseBean.setMes(msg);
-        uniCallBackBaseBean.setData(obj);
-        return uniCallBackBaseBean;
-    }
-
     /**
      * 褰撳墠瀵硅薄杞� JSONObject
      *
@@ -269,12 +249,35 @@
             if (TextUtils.isEmpty(obj.toString())) {
                 return new JSONObject();
             }
+            if (obj instanceof JSONObject) {
+                return (JSONObject) obj;
+            }
             String json = new Gson().toJson(obj);
-
             return new JSONObject(json);
         } catch (Exception e) {
             return new JSONObject();
         }
     }
+
+
+    /**
+     * 鑾峰彇 KeyValue
+     *
+     * @param key -
+     * @param obj -
+     * @return value
+     */
+    private String getKeyValue(String key, Object obj) {
+        try {
+            JSONObject jsonObject = this.getJSONObject(obj);
+            if (jsonObject.has(key)) {
+                return jsonObject.getString(key);
+            }
+            return "";
+        } catch (Exception e) {
+            return "";
+        }
+    }
+
 }
 

--
Gitblit v1.8.0