mac
2024-06-28 f7ad7bee1edf3f9ece0dab01479df57b4c4a5c6a
app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
@@ -10,6 +10,7 @@
import android.location.Location;
import android.location.LocationManager;
import android.os.IBinder;
import android.os.SystemClock;
import android.print.PageRange;
import android.provider.Settings;
import android.text.TextUtils;
@@ -33,7 +34,9 @@
import com.hdl.photovoltaic.bean.ModBusBean;
import com.hdl.photovoltaic.bean.PageNumberObject;
import com.hdl.photovoltaic.config.AppConfigManage;
import com.hdl.photovoltaic.config.ConstantManage;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.enums.LowerTagType;
import com.hdl.photovoltaic.internet.HttpServer.MyNanoHttpServer;
import com.hdl.photovoltaic.internet.TcpClient;
import com.hdl.photovoltaic.internet.api.HttpApi;
@@ -44,6 +47,7 @@
import com.hdl.photovoltaic.ui.bean.CloudInverterDeviceBean;
import com.hdl.photovoltaic.ui.bean.DeviceTimeBean;
import com.hdl.photovoltaic.ui.bean.Geolocation;
import com.hdl.photovoltaic.ui.bean.HouseIdBean;
import com.hdl.photovoltaic.ui.bean.LinkBean;
import com.hdl.photovoltaic.ui.bean.MemberBean;
import com.hdl.photovoltaic.ui.bean.OidBean;
@@ -89,6 +93,7 @@
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
import io.dcloud.feature.sdk.DCUniMPSDK;
import io.dcloud.feature.unimp.DCUniMPJSCallback;
import okhttp3.ResponseBody;
@@ -165,45 +170,98 @@
            } else if (HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL.equals(topic)) {
                //住宅模块
                switch (type) {
                    //扫码添加电站
                    case HDLUniMP.UNI_EVENT_REPLY_HOME_ADD: {
                        String url = getKeyValue("url", getKeyValue("data", data));
                        //EventBus事件分发
                        HdlCommonLogic.getInstance().postEventBusSticky(
                                HDLUniMP.UNI_EVENT_REPLY_HOME_ADD,
                                HDLUniMP.UNI_EVENT_REPLY_HOME_ADD,
                                url);
                        if (callback != null) {
                            uniSuccessCallback(type, null, callback);
                        }
                    }
                    break;
                    //账号下是否有电站列表
                    case HDLUniMP.UNI_EVENT_REPLY_HOME_LIST: {
                        if (callback != null) {
                            uniSuccessCallback(type, HdlResidenceLogic.getInstance().getHouseIdList().size(), callback);
                        }
                    }
                    break;
                    //创建电站
                    case HDLUniMP.UNI_EVENT_REPLY_HOME_CREATION: {
                        //EventBus事件分发
                        BaseEventBus baseEventBus = new BaseEventBus();
                        baseEventBus.setTopic(HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL);
                        baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_HOME_CREATION);
                        baseEventBus.setData(getKeyValue("data", data));
                        EventBus.getDefault().post(baseEventBus);
                        HdlCommonLogic.getInstance().postEventBus(
                                HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL,
                                HDLUniMP.UNI_EVENT_REPLY_HOME_CREATION,
                                getKeyValue("data", data));
                        if (callback != null) {
                            uniSuccessCallback(type, null, callback);
                        }
                    }
                    break;
                    //读取详情
                    case HDLUniMP.UNI_EVENT_REPLY_HOME_DETAILS: {
                        if (callback != null) {
                            uniSuccessCallback(type, null, callback);
                        }
                    }
                    break;
                    //电站删除
                    case HDLUniMP.UNI_EVENT_REPLY_HOME_DEl: {
                        this.uniGetDelResidence(mode_type, data, callback);
                    }
                    break;
                    //关闭详情页
                    case HDLUniMP.UNI_EVENT_REPLY_HOME_CLOSE_HOME_DETAILS_PAGE: {
                        //EventBus事件分发
                        BaseEventBus baseEventBus = new BaseEventBus();
                        baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_HOME_CLOSE_HOME_DETAILS_PAGE);
                        baseEventBus.setData(getKeyValue("data", data));
                        EventBus.getDefault().post(baseEventBus);
                        // todo 在HDLUniMPSDKManager类里面有方法()监听到小程序关闭,然后发布调用EventBus发布出去;
//                        HdlCommonLogic.getInstance().postEventBus(
//                                HDLUniMP.UNI_EVENT_REPLY_HOME_CLOSE_HOME_DETAILS_PAGE,
//                                LowerTagType.power_station.toString(),
//                                getKeyValue("data", data));
                        if (callback != null) {
                            uniSuccessCallback(type, null, callback);
                        }
                    }
                    break;
                    //住宅【电站】编辑
                    case HDLUniMP.UNI_EVENT_REPLY_HOME_EDIT: {
                        //EventBus事件分发
                        BaseEventBus baseEventBus = new BaseEventBus();
                        baseEventBus.setTopic(HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL);
                        baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_HOME_EDIT);
                        baseEventBus.setData(getKeyValue("data", data));
                        EventBus.getDefault().post(baseEventBus);
                        HdlCommonLogic.getInstance().postEventBus(
                                HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL,
                                HDLUniMP.UNI_EVENT_REPLY_HOME_EDIT,
                                getKeyValue("data", data));
                        if (callback != null) {
                            uniSuccessCallback(type, null, callback);
                        }
                    }
                    break;
                    //电站的交付二维码(安装商)
                    case HDLUniMP.UNI_EVENT_REPLY_HOME_DELIVERYURLQRCODE: {
                        uniGetDeliveryUrlQrcode(type, data, callback);
                    }
                    break;
                    //电站手动交付(安装商)
                    case HDLUniMP.UNI_EVENT_REPLY_HOME_DELIVERTOACCOUNT: {
                        uniGetDeliverToAccount(type, data, callback);
                    }
                    break;
                    //电站授权安装商(C端)
                    case HDLUniMP.UNI_EVENT_REPLY_HOME_UPDATEDEBUGPERM: {
                        uniHomeUpdateDebugPerm(type, data, callback);
                    }
                    break;
                }
                if (callback != null) {
                    uniSuccessCallback(type, null, callback);
                }
            } else if (HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODEL.equals(topic)) {
                //设备模块
                switch (type) {
@@ -474,6 +532,12 @@
                    }
                    break;
                    //下载成员(子账号)头像
                    case HDLUniMP.UNI_EVENT_REPLY_DOWNLOAD_MEMBER_AVATAR: {
                        uniGetHeadPIortrait(type, data, callback);
                    }
                    break;
                    //成员列表
                    case HDLUniMP.UNI_EVENT_REPLY_MEMBER_LIST: {
                        uniGetMemberList(type, data, callback);
@@ -507,6 +571,13 @@
                    }
                    break;
                    //员工详情获取
                    case HDLUniMP.UNI_EVENT_REPLY_STAFF_DETAIL: {
                        uniGetStaffInfo(type, data, callback);
                    }
                    break;
                    //员工删除
                    case HDLUniMP.UNI_EVENT_REPLY_STAFF_DELETE: {
@@ -521,7 +592,7 @@
                    }
                    break;
                    //获取当前账号在公司的身份
                    case HDLUniMP.UNI_EVENT_REPLY_USERRIGHTTYPe: {
                    case HDLUniMP.UNI_EVENT_REPLY_USERRIGHTTYP: {
                        uniGetUserRightType(type, data, callback);
                    }
@@ -595,12 +666,6 @@
        HdlLogLogic.print("uni---组装uni发送数据格式---" + json, false);
    }
    public void openUniMPDelay(String path, JSONObject jsonObject) {
        JSONObject json = this.createdJSONObject(jsonObject, true);
        HDLUniMPSDKManager.getInstance().openUniMPDelay(HDLUniMP.UNI_APP_ID, path, json, HdlUniLogic.this);
        HdlLogLogic.print("uni---组装uni发送数据格式---" + json, false);
    }
    /**
     * 原生【主动】向小程序发送通知事件
     * 注意:需要提前小程序在运行才可成功
@@ -627,6 +692,129 @@
    //region ******uni接口方法******
    /**
     * 电站删除
     */
    private void uniGetDelResidence(String type, Object data, DCUniMPJSCallback callback) {
        String homeId = getKeyValue("homeId", getKeyValue("data", data));
        HdlResidenceLogic.getInstance().delResidence(homeId, new CloudCallBeak<Boolean>() {
            @Override
            public void onSuccess(Boolean obj) {
                if (callback != null) {
                    uniSuccessCallback(type, null, callback);
                }
                List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId);
                for (int i = 0; i < list.size(); i++) {
                    GatewayBean gatewayBean = list.get(i);
                    HdlDeviceLogic.getInstance().initializeInverter(gatewayBean.getDevice_mac(), null);
                }
                list.clear();//清空缓存;
//              HDLLinkLocalGateway.getInstance().getGatewayList().clear();
                HdlResidenceLogic.getInstance().delHouseId(homeId);//删除电站缓存
                if (UserConfigManage.getInstance().isBAccount()) {
                    //B端
                    //收到成功结果响应后,会自动关闭小程序,在HDLUniMPSDKManager类里面有方法()监听到小程序关闭,监听到小程序关闭事件后,会重新获取电站列表进行刷界面;
                    if (null != HDLUniMPSDKManager.getInstance().getUniMP()) {
                        HDLUniMPSDKManager.getInstance().getUniMP().closeUniMP();
                    }
                } else {
                    //C端
                    List<HouseIdBean> HouseIdList = HdlResidenceLogic.getInstance().getHouseIdList();
                    if (HouseIdList.size() == 0) {
                        String path = HDLUniMP.UNI_EVENT_OPEN_HOME_Null_C;
                        HdlUniLogic.getInstance().openUniMP(path, null);
                    } else {
                        HouseIdBean houseIdBean = HouseIdList.get(0);//默认拿第一个
                        HdlResidenceLogic.getInstance().switchHouse(houseIdBean);
                        JsonObject jsonObject = new JsonObject();
                        jsonObject.addProperty("homeId", houseIdBean.getHomeId());
                        jsonObject.addProperty("homeName", houseIdBean.getHomeName());
                        jsonObject.addProperty("powerStationStatus", houseIdBean.getPowerStationStatus() + "");
                        HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
                        uniCallBackBaseBean.setType(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_REFRESH_DETAILS);
                        uniCallBackBaseBean.setData(jsonObject);
                        HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean);
                    }
                }
            }
            @Override
            public void onFailure(HDLException e) {
                uniExceptionCallback(type, e, callback);
            }
        });
    }
    /**
     * 电站授权安装商(C端)
     */
    private void uniHomeUpdateDebugPerm(String type, Object data, DCUniMPJSCallback callback) {
        String homeId = getKeyValue("homeId", getKeyValue("data", data));
        boolean debugPerm = Boolean.parseBoolean(getKeyValue("debugPerm", getKeyValue("data", data)));
        HdlResidenceLogic.getInstance().homeUpdateDebugPerm(homeId, debugPerm, new CloudCallBeak<Boolean>() {
            @Override
            public void onSuccess(Boolean obj) {
                uniSuccessCallback(type, obj, callback);
            }
            @Override
            public void onFailure(HDLException e) {
                uniExceptionCallback(type, e, callback);
            }
        });
    }
    /**
     * 电站手动交付(安装商)
     */
    private void uniGetDeliverToAccount(String type, Object data, DCUniMPJSCallback callback) {
        String homeId = getKeyValue("homeId", getKeyValue("data", data));
        String account = getKeyValue("account", getKeyValue("data", data));
        HdlResidenceLogic.getInstance().getDeliverToAccount(homeId, account, new CloudCallBeak<Boolean>() {
            @Override
            public void onSuccess(Boolean obj) {
                uniSuccessCallback(type, obj, callback);
                //收到成功结果响应后,会自动关闭小程序,在HDLUniMPSDKManager类里面有方法()监听到小程序关闭,监听到小程序关闭事件后,会重新获取电站列表进行刷界面;
                if (null != HDLUniMPSDKManager.getInstance().getUniMP()) {
                    HDLUniMPSDKManager.getInstance().getUniMP().closeUniMP();
                }
            }
            @Override
            public void onFailure(HDLException e) {
                uniExceptionCallback(type, e, callback);
            }
        });
    }
    /**
     * 电站的交付二维码(安装商)
     */
    private void uniGetDeliveryUrlQrcode(String type, Object data, DCUniMPJSCallback callback) {
        String homeId = getKeyValue("homeId", getKeyValue("data", data));
        HdlResidenceLogic.getInstance().getDeliveryUrlQrcode(homeId, new CloudCallBeak<String>() {
            @Override
            public void onSuccess(String obj) {
                uniSuccessCallback(type, obj, callback);
            }
            @Override
            public void onFailure(HDLException e) {
                uniExceptionCallback(type, e, callback);
            }
        });
    }
    /**
     * 获取当前账号在公司的身份
     */
    private void uniGetUserRightType(String type, Object data, DCUniMPJSCallback callback) {
@@ -648,10 +836,10 @@
     */
    private void uniGetStaffEdit(String type, Object data, DCUniMPJSCallback callback) {
        StaffBean staffBean = new StaffBean();
        String member_info = getKeyValue("staff_info", getKeyValue("data", data));
        if (!TextUtils.isEmpty(member_info)) {
        String staffInfo = getKeyValue("staffInfo", getKeyValue("data", data));
        if (!TextUtils.isEmpty(staffInfo)) {
            try {
                staffBean = new Gson().fromJson(member_info, StaffBean.class);
                staffBean = new Gson().fromJson(staffInfo, StaffBean.class);
            } catch (Exception ignored) {
            }
        }
@@ -669,14 +857,14 @@
    }
    /**
     * 员工添加
     * 员工删除
     */
    private void uniGetStaffDelete(String type, Object data, DCUniMPJSCallback callback) {
        StaffBean staffBean = new StaffBean();
        String member_info = getKeyValue("staff_info", getKeyValue("data", data));
        if (!TextUtils.isEmpty(member_info)) {
        String staffInfo = getKeyValue("staffInfo", getKeyValue("data", data));
        if (!TextUtils.isEmpty(staffInfo)) {
            try {
                staffBean = new Gson().fromJson(member_info, StaffBean.class);
                staffBean = new Gson().fromJson(staffInfo, StaffBean.class);
            } catch (Exception ignored) {
            }
        }
@@ -698,10 +886,10 @@
     */
    private void uniGetStaffAdd(String type, Object data, DCUniMPJSCallback callback) {
        StaffBean staffBean = new StaffBean();
        String member_info = getKeyValue("staff_info", getKeyValue("data", data));
        if (!TextUtils.isEmpty(member_info)) {
        String staffInfo = getKeyValue("staffInfo", getKeyValue("data", data));
        if (!TextUtils.isEmpty(staffInfo)) {
            try {
                staffBean = new Gson().fromJson(member_info, StaffBean.class);
                staffBean = new Gson().fromJson(staffInfo, StaffBean.class);
            } catch (Exception ignored) {
            }
        }
@@ -719,13 +907,14 @@
    }
    /**
     * 获取员工列表
     * 获取员工详情
     */
    private void uniGetStaffList(String type, Object data, DCUniMPJSCallback callback) {
        HdlMemberLogic.getInstance().getStaffList(1, 50, new CloudCallBeak<PageNumberObject<List<StaffBean>>>() {
    private void uniGetStaffInfo(String type, Object data, DCUniMPJSCallback callback) {
        String userId = getKeyValue("userId", getKeyValue("data", data));
        HdlMemberLogic.getInstance().getStaffInfo(userId, new CloudCallBeak<StaffBean>() {
            @Override
            public void onSuccess(PageNumberObject<List<StaffBean>> obj) {
                uniSuccessCallback(type, obj.getList(), callback);
            public void onSuccess(StaffBean obj) {
                uniSuccessCallback(type, obj, callback);
            }
            @Override
@@ -736,14 +925,34 @@
    }
    /**
     * 获取员工列表
     */
    private void uniGetStaffList(String type, Object data, DCUniMPJSCallback callback) {
        long pageNo = Long.parseLong(getKeyValue("pageNo", getKeyValue("data", data)));
        long pageSize = Long.parseLong(getKeyValue("pageSize", getKeyValue("data", data)));
        HdlMemberLogic.getInstance().getStaffList(pageNo, pageSize, new CloudCallBeak<PageNumberObject<StaffBean>>() {
            @Override
            public void onSuccess(PageNumberObject<StaffBean> obj) {
                uniSuccessCallback(type, obj.getList(), callback);
            }
            @Override
            public void onFailure(HDLException e) {
                uniExceptionCallback(type, e, callback);
            }
        });
    }
    /**
     * 成员编辑
     */
    private void uniGetMemberEdit(String type, Object data, DCUniMPJSCallback callback) {
        MemberBean memberBean = new MemberBean();
        String member_info = getKeyValue("member_info", getKeyValue("data", data));
        if (!TextUtils.isEmpty(member_info)) {
        String memberInfo = getKeyValue("memberInfo", getKeyValue("data", data));
        if (!TextUtils.isEmpty(memberInfo)) {
            try {
                memberBean = new Gson().fromJson(member_info, MemberBean.class);
                memberBean = new Gson().fromJson(memberInfo, MemberBean.class);
            } catch (Exception ignored) {
            }
        }
@@ -765,10 +974,10 @@
     */
    private void uniGetMemberDelete(String type, Object data, DCUniMPJSCallback callback) {
        MemberBean memberBean = new MemberBean();
        String member_info = getKeyValue("member_info", getKeyValue("data", data));
        if (!TextUtils.isEmpty(member_info)) {
        String memberInfo = getKeyValue("memberInfo", getKeyValue("data", data));
        if (!TextUtils.isEmpty(memberInfo)) {
            try {
                memberBean = new Gson().fromJson(member_info, MemberBean.class);
                memberBean = new Gson().fromJson(memberInfo, MemberBean.class);
            } catch (Exception ignored) {
            }
        }
@@ -790,16 +999,42 @@
     */
    private void uniGetMemberAdd(String type, Object data, DCUniMPJSCallback callback) {
        MemberBean memberBean = new MemberBean();
        String member_info = getKeyValue("member_info", getKeyValue("data", data));
        if (!TextUtils.isEmpty(member_info)) {
        String memberInfo = getKeyValue("memberInfo", getKeyValue("data", data));
        if (!TextUtils.isEmpty(memberInfo)) {
            try {
                memberBean = new Gson().fromJson(member_info, MemberBean.class);
                memberBean = new Gson().fromJson(memberInfo, MemberBean.class);
            } catch (Exception ignored) {
            }
        }
        HdlMemberLogic.getInstance().getMemberAdd(memberBean, new CloudCallBeak<Boolean>() {
            @Override
            public void onSuccess(Boolean obj) {
                uniSuccessCallback(type, obj, callback);
            }
            @Override
            public void onFailure(HDLException e) {
                uniExceptionCallback(type, e, callback);
            }
        });
    }
    /**
     * 下载成员(子账号)头像
     */
    private void uniGetHeadPIortrait(String type, Object data, DCUniMPJSCallback callback) {
        MemberBean memberBean = new MemberBean();
        String memberInfo = getKeyValue("memberInfo", getKeyValue("data", data));
        if (!TextUtils.isEmpty(memberInfo)) {
            try {
                memberBean = new Gson().fromJson(memberInfo, MemberBean.class);
            } catch (Exception ignored) {
            }
        }
        HdlMemberLogic.getInstance().getHeadPIortrait(memberBean, new CloudCallBeak<byte[]>() {
            @Override
            public void onSuccess(byte[] obj) {
                uniSuccessCallback(type, obj, callback);
            }
@@ -1833,12 +2068,14 @@
    private void uniDelInverterDevice(String type, Object data, DCUniMPJSCallback callback) {
        String deviceId = getKeyValue("deviceId", getKeyValue("data", data));
        String homeId = getKeyValue("homeId", getKeyValue("data", data));
        if (TextUtils.isEmpty(homeId)) {
            homeId = UserConfigManage.getInstance().getHomeId();
        }
        String mac = getKeyValue("mac", getKeyValue("data", data));
        HdlDeviceLogic.getInstance().delInverterDevice(homeId, deviceId, new CloudCallBeak<Boolean>() {
            @Override
            public void onSuccess(Boolean obj) {
                //初始化逆变器设备
                HdlDeviceLogic.getInstance().initializeInverter(mac, null);
                //移除本地缓存
                HdlDeviceLogic.getInstance().removeLocalCacheMemoryGatewayToDeviceId(homeId, deviceId);
                uniSuccessCallback(type, null, callback);
            }
@@ -2271,12 +2508,11 @@
            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);
            HdlLogLogic.print("回复---uni---" + type + "---" + e.getMessage(), true);
        }
    }