wjc
2024-12-23 f753d8366041354da60b8096060f3ab5159e3880
app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
@@ -13,6 +13,7 @@
import android.os.SystemClock;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import androidx.core.app.ActivityCompat;
@@ -141,10 +142,12 @@
            if (!HDLUniMP.UNI_APP_ID.equals(appId)) {
                return;
            }
            long startTime = System.currentTimeMillis();
            Log.d("===开始时间===", String.valueOf(startTime));
            String type = getKeyValue("type", data);//小类
            String logTag = getKeyValue("logTag", data);//标记uni指令
            String mode_type = "大类-" + topic + "---" + "小类-" + type;//用来打印的
            HdlLogLogic.print(logTag + ":" + "uni---发送---" + mode_type + "\r\n" + data, true);
//            HdlLogLogic.print(logTag + ":" + "uni---发送---" + mode_type + "\r\n" + data, true);
            if (HDLUniMP.UNI_EVENT_REPLY_USER_MODEL.equals(topic)) {
                //用户模块
                switch (type) {
@@ -244,9 +247,14 @@
                        }
                    }
                    break;
                    //电站的交付二维码(安装商)
//                    //电站的交付二维码(安装商)
//                    case HDLUniMP.UNI_EVENT_REPLY_HOME_DELIVERYURLQRCODE: {
//                        uniGetDeliveryUrlQrcode(type, data, callback);
//                    }
//                    break;
                    //电站的交付URL(安装商)
                    case HDLUniMP.UNI_EVENT_REPLY_HOME_DELIVERYURLQRCODE: {
                        uniGetDeliveryUrlQrcode(type, data, callback);
                        uniGetDeliveryUrl(type, data, callback);
                    }
                    break;
                    //电站手动交付(安装商)
@@ -724,11 +732,15 @@
                                    String s = HdlESLocalJsonLogic.getInstance().readHdlESLocalJson(url, deviceModel);
                                    //本地缓存数据
                                    if (callback != null) {
                                        if (s.startsWith("{")) {
                                            uniSuccessCallback(type, new Gson().fromJson(s, JsonObject.class), callback);
                                        } else if (s.startsWith("[")) {
                                            uniSuccessCallback(type, new Gson().fromJson(s, JsonArray.class), callback);
                                        } else {
                                        try {
                                            if (s.startsWith("{")) {
                                                uniSuccessCallback(type, new Gson().fromJson(s, JsonObject.class), callback);
                                            } else if (s.startsWith("[")) {
                                                uniSuccessCallback(type, new Gson().fromJson(s, JsonArray.class), callback);
                                            } else {
                                                uniSuccessCallback(type, s, callback);
                                            }
                                        } catch (Exception e) {
                                            uniSuccessCallback(type, s, callback);
                                        }
                                    }
@@ -744,13 +756,19 @@
                        } else {
                            //本地缓存数据
                            if (callback != null) {
                                if (json.startsWith("{")) {
                                    uniSuccessCallback(type, new Gson().fromJson(json, JsonObject.class), callback);
                                } else if (json.startsWith("[")) {
                                    uniSuccessCallback(type, new Gson().fromJson(json, JsonArray.class), callback);
                                } else {
                                try {
                                    if (json.startsWith("{")) {
                                        uniSuccessCallback(type, new Gson().fromJson(json, JsonObject.class), callback);
                                    } else if (json.startsWith("[")) {
                                        uniSuccessCallback(type, new Gson().fromJson(json, JsonArray.class), callback);
                                    } else {
                                        uniSuccessCallback(type, json, callback);
                                    }
                                } catch (Exception e) {
                                    uniSuccessCallback(type, json, callback);
                                }
                                long endTime = System.currentTimeMillis() - startTime;
                                Log.d("====耗时时间====", String.valueOf(endTime));
                            }
                        }
                    }
@@ -798,7 +816,7 @@
    public void openUniMP(String path, JSONObject jsonObject) {
        JSONObject json = this.createdJSONObject(jsonObject, true);
        HDLUniMPSDKManager.getInstance().openUniMP(HDLUniMP.UNI_APP_ID, path, json, HdlUniLogic.this);
        HdlLogLogic.print("uni---组装uni发送数据格式---" + json, false);
//        HdlLogLogic.print("uni---组装uni发送数据格式---" + json, false);
    }
    /**
@@ -964,6 +982,32 @@
            @Override
            public void onSuccess(String obj) {
                uniSuccessCallback(type, obj, callback);
            }
            @Override
            public void onFailure(HDLException e) {
                uniExceptionCallback(type, e, callback);
            }
        });
    }
    /**
     * 电站的交付URl(安装商)
     */
    private void uniGetDeliveryUrl(String type, Object data, DCUniMPJSCallback callback) {
        String homeId = getKeyValue("homeId", getKeyValue("data", data));
        HdlResidenceLogic.getInstance().getDeliveryUrl(homeId, new CloudCallBeak<String>() {
            @Override
            public void onSuccess(String obj) {
                try {
                    Gson g = new Gson();
                    JsonObject jObject = g.fromJson(obj, JsonObject.class);
                    String deliveryUrl = jObject.get("deliveryUrl").toString();
                    uniSuccessCallback(type, deliveryUrl, callback);
                } catch (Exception ignored) {
                    uniSuccessCallback(type, obj, callback);
                }
            }
            @Override
@@ -2326,8 +2370,9 @@
        HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(homeId, new CloudCallBeak<List<GatewayBean>>() {
            @Override
            public void onSuccess(List<GatewayBean> list) {
                List<GatewayBean> newList = sortLogic(list);
                if (callback != null) {
                    uniSuccessCallback(type, list, callback);
                    uniSuccessCallback(type, newList, callback);
                }
                //EventBus事件分发,进入住宅开始订阅主题
                BaseEventBus baseEventBus = new BaseEventBus();
@@ -2336,7 +2381,7 @@
                baseEventBus.setData(homeId);
                EventBus.getDefault().post(baseEventBus);
                //进来住宅详情都要上传一次oid列表到云端;
                HdlDeviceLogic.getInstance().uploadOidDataToCloud(homeId, list, false, null);
                HdlDeviceLogic.getInstance().uploadOidDataToCloud(homeId, newList, false, null);
            }
            @Override
@@ -2347,6 +2392,31 @@
            }
        });
    }
    /**
     * 进行排序(逆变器-负载中心)
     *
     * @param list 源数据
     * @return 返回列表
     */
    private List<GatewayBean> sortLogic(List<GatewayBean> list) {
        if (list == null || list.size() == 0) {
            return new ArrayList<>();
        }
        List<GatewayBean> newList = new ArrayList<>();
        List<GatewayBean> inverterList = new ArrayList<>();
        List<GatewayBean> lcList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getSpk().equals(HdlDeviceLogic.getInstance().INVERTER_DEVICE_SPK)) {
                inverterList.add(list.get(i));
            } else {
                lcList.add(list.get(i));
            }
        }
        newList.addAll(inverterList);
        newList.addAll(lcList);
        return newList;
    }
    /**
@@ -2721,12 +2791,14 @@
        //HdlLogLogic.print("uni---发送---ModBus---" + Arrays.toString(modBusBean.getData()), true);
        //发送modbus协议
        long startTime = System.currentTimeMillis();
        HDLModBusConnect.getInstance().Send(modBusBean.getMac(), modBusBean.getData(), new ModbusCallBack() {
            @Override
            public void onSuccess(int[] data) {
                uniSuccessCallback(type, data, callback);
//                HdlLogLogic.print("uni---接收---ModBus---" + Arrays.toString(data), true);
                long endTime = System.currentTimeMillis() - startTime;
                Log.d("====Mobus耗时时间====", String.valueOf(endTime));
            }
            @Override
@@ -2800,7 +2872,7 @@
            if (callback != null) {
                callback.invoke(getJSONObject(uniCallBackBaseBean));
//                callback.invoke(uniCallBackBaseBean);
                HdlLogLogic.print("回复---uni---" + type + "---" + new Gson().toJson(uniCallBackBaseBean), true);
//                HdlLogLogic.print("回复---uni---" + type + "---" + new Gson().toJson(uniCallBackBaseBean), true);
            }
        } catch (Exception e) {
            HdlLogLogic.print("回复---uni---" + type + "---" + e.getMessage(), true);