wjc
2026-03-24 c4ae4589c6c001329ebb731589b209e8ddcbf7ca
app/src/main/java/com/hdl/photovoltaic/ui/BPowerStationActivity.java
@@ -5,7 +5,6 @@
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Lifecycle;
import android.Manifest;
import android.content.Context;
@@ -21,8 +20,9 @@
import android.view.View;
import android.widget.TextView;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.linkpm.sdk.home.type.HomeType;
@@ -37,6 +37,7 @@
import com.hdl.photovoltaic.enums.LowerTagType;
import com.hdl.photovoltaic.enums.NetworkType;
import com.hdl.photovoltaic.listener.CloudCallBeak;
import com.hdl.photovoltaic.other.HdlAiLogic;
import com.hdl.photovoltaic.other.HdlCommonLogic;
import com.hdl.photovoltaic.other.HdlDeviceLogic;
import com.hdl.photovoltaic.other.HdlESLocalJsonLogic;
@@ -44,22 +45,26 @@
import com.hdl.photovoltaic.other.HdlMessageLogic;
import com.hdl.photovoltaic.other.HdlMqttLogic;
import com.hdl.photovoltaic.other.HdlOtaLogic;
import com.hdl.photovoltaic.other.HdlPushLogic;
import com.hdl.photovoltaic.other.HdlResidenceLogic;
import com.hdl.photovoltaic.other.HdlThreadLogic;
import com.hdl.photovoltaic.other.HdlUniLogic;
import com.hdl.photovoltaic.push.PushMessageInfoBean;
import com.hdl.photovoltaic.ui.bean.ChatInfoBean;
import com.hdl.photovoltaic.ui.bean.ChatMessageListBean;
import com.hdl.photovoltaic.ui.bean.ChatMessagePageBean;
import com.hdl.photovoltaic.ui.bean.DeviceRemoteInfo;
import com.hdl.photovoltaic.ui.bean.HouseIdBean;
import com.hdl.photovoltaic.ui.bean.MessageBean;
import com.hdl.photovoltaic.ui.bean.OidBean;
import com.hdl.photovoltaic.ui.bean.UnCountBean;
import com.hdl.photovoltaic.ui.home.HomePageFragment;
import com.hdl.photovoltaic.ui.me.MeFragment;
import com.hdl.photovoltaic.ui.message.MessageFragment;
import com.hdl.photovoltaic.ui.newC.PowerStationsListActivity;
import com.hdl.photovoltaic.ui.newC.PowerStationsMoveActivity;
import com.hdl.photovoltaic.ui.message.MessageHouseFragment;
import com.hdl.photovoltaic.ui.message.MessageInfoActivity;
import com.hdl.photovoltaic.ui.powerstation.HouseAndDeviceFragment;
import com.hdl.photovoltaic.uni.HDLUniMP;
import com.hdl.photovoltaic.uni.HDLUniMPSDKManager;
import com.hdl.photovoltaic.utils.AppManagerUtils;
import com.hdl.photovoltaic.utils.FragmentUtils;
import com.hdl.photovoltaic.utils.GPSManagerUtils;
import com.hdl.photovoltaic.utils.PermissionUtils;
import com.hdl.photovoltaic.utils.SharedPreUtils;
@@ -82,6 +87,7 @@
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import cn.jpush.android.api.JPushInterface;
@@ -109,6 +115,10 @@
    @Override
    public void onBindView(Bundle savedInstanceState) {
////        //通知栏点击进来,防止应用在后台时被重复启动,阿里云推动通知指定打开某个Activity,没有设置Flags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);默认启动新实例,导致多个实例
//        if (!isTaskRoot()) {
//            finish();
//        }
        setStatusBarTranslucent();
        getWindow().setNavigationBarColor(getColor(R.color.text_FF1C1C1E));
        //初始化碎片
@@ -121,20 +131,55 @@
        this.registerAllTopicsListener();
        //初始化mqtt客户端
        this.initMqttClient();
        //上传极光注册ID到云端
        this.pushTokens();
        //点击极光通知栏消息进来
        this.clickJpushNotificationMessage();
//        //上传极光注册ID到云端 隐藏2025-11-21 11:52:27
//        this.pushTokens();
        //上传推动令牌到云端(谷歌FCM推送)
        this.sendPushTokenToServer(UserConfigManage.getInstance().getPushToken());
//        //点击极光通知栏消息进来
//        this.clickJpushNotificationMessage();
        //点击通知栏消息进来
        this.OpenSpecifiedPage(getIntent(), "onBindView");
        //初始化权限
        this.requestPermissions();
        //读取消息未读数量
        this.getUnreadCount();
        //获取云端脚本
        HdlESLocalJsonLogic.getInstance().getAllHdlESLocalJson();
        this.getChatInfo();
    }
    /**
     * 点击通知栏消息进来
     */
    private void OpenSpecifiedPage(Intent intent, String tag) {
        Log.d("==========", tag);
        try {
            String data = getIntentExpantData(intent);
            if (TextUtils.isEmpty(data)) {
                return;
            }
//            PushMessageInfoBean pushMessageInfoBean = new Gson().fromJson(data, PushMessageInfoBean.class);
            PushMessageInfoBean pushMessageInfoBean = HdlPushLogic.getInstance().pushDataProcessing("", "", data);
            if (TextUtils.isEmpty(pushMessageInfoBean.getMsgId())) {
                return;
            }
            MessageBean messageBean = new MessageBean();
            messageBean.setMsgId(Long.valueOf(pushMessageInfoBean.getMsgId()));
            Intent intentMessageInfoActivity = new Intent();
            intentMessageInfoActivity.setClass(_mActivity, MessageInfoActivity.class);
            intentMessageInfoActivity.putExtra("messageBean", JSONObject.toJSONString(messageBean));
            startActivity(intentMessageInfoActivity);
            this.clickNotificationMessageTab();
            if (null != HDLUniMPSDKManager.getInstance().getUniMP()) {
                Log.d("HDLUniMPSDKManager.getInstance().getUniMP()", "HDLUniMPSDKManager.getInstance().getUniMP()");
                HDLUniMPSDKManager.getInstance().getUniMP().closeUniMP();
            }
        } catch (Exception e) {
            Log.d("错误", " " + e.getMessage());
        }
    }
    /**
     * 初始化Fragment
@@ -146,7 +191,7 @@
        //碎片初始化
        HomePageFragment mHomePageFragment = new HomePageFragment();
        HouseAndDeviceFragment mHouseAndDeviceFragment = new HouseAndDeviceFragment();
        MessageFragment mMessageFragment = new MessageFragment();
        MessageHouseFragment mMessageHouseFragment = new MessageHouseFragment();
        MeFragment mMeFragment = new MeFragment();
        if (savedInstanceState != null) {
            //“内存重启”时调用 获取“内存重启”时保存的索引下标
@@ -168,7 +213,7 @@
            }
            fragmentList.add(mHomePageFragment);
            fragmentList.add(mHouseAndDeviceFragment);
            fragmentList.add(mMessageFragment);
            fragmentList.add(mMessageHouseFragment);
            fragmentList.add(mMeFragment);
            this.showFragment();
        }
@@ -251,12 +296,6 @@
        //启动页与mainActivity样式一样,这样启动页和mainActivity看上去是一个界面,目的是为了mainActivity遮住下一页;
//        AppManagerUtils.getAppManager().finishActivity(StartActivity.class);
        portConflictDialog();
//        Intent intent = new Intent(_mActivity, BPowerStationActivity.class);
//        intent.setFlags(Intent.Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
//        intent.putExtra("skip", "skip");//里面判断有这个标识就跳转到消息中心界面
//        _mActivity.startActivity(intent);
        //点击极光通知栏消息进来
//        this.clickJpushNotificationMessage();
    }
@@ -289,12 +328,12 @@
//                    UserConfigManage.getInstance().setRegistrationID(registrationID);
//                    UserConfigManage.getInstance().Save();
                    String finalRegistrationID = registrationID;
                    HdlResidenceLogic.getInstance().pushAdd(new CloudCallBeak<String>() {
                    HdlPushLogic.getInstance().pushAdd(new CloudCallBeak<String>() {
                        @Override
                        public void onSuccess(String pushId) {
                            if (!TextUtils.isEmpty(pushId)) {
                                UserConfigManage.getInstance().setRegistrationID(finalRegistrationID);
                                UserConfigManage.getInstance().setPushToken(finalRegistrationID);
                                UserConfigManage.getInstance().setPushId(pushId);
                                UserConfigManage.getInstance().Save();
                            }
@@ -313,6 +352,63 @@
                }
            }
        });
    }
    /**
     * 上传 token 到服务器
     *
     * @param token 令牌
     */
    private void sendPushTokenToServer(final String token) {
        if (TextUtils.isEmpty(token)) {
            return;
        }
        HdlPushLogic.getInstance().pushAdd(new CloudCallBeak<String>() {
            @Override
            public void onSuccess(String pushId) {
                HdlLogLogic.print("添加令牌到云端 PushToken:" + UserConfigManage.getInstance().getPushToken() + " pushId:" + pushId, true);
            }
            @Override
            public void onFailure(HDLException e) {
                HdlLogLogic.print("添加令牌到云端失败 PushToken:" + UserConfigManage.getInstance().getPushToken() + " 错误:" + e.getMessage(), true);
            }
        });
    }
    /**
     * 查看智能体详情
     *
     */
    private void getChatInfo() {
        HdlAiLogic.getInstance().getChatInfo(new CloudCallBeak<ChatInfoBean>() {
            @Override
            public void onSuccess(ChatInfoBean chatInfoBean) {
                UserConfigManage.getInstance().setAgentSecret(chatInfoBean.getAgentSecret());
                UserConfigManage.getInstance().setAgentUrl(chatInfoBean.getAgentUrl());
                UserConfigManage.getInstance().Save();
                HdlAiLogic.getInstance().chatMessagesList(new CloudCallBeak<ChatMessagePageBean>() {
                    @Override
                    public void onSuccess(ChatMessagePageBean obj) {
                        if (obj != null && !obj.getData().isEmpty()) {
                            UserConfigManage.getInstance().setConversationId(obj.getData().get(0).getId());
                            UserConfigManage.getInstance().Save();
                        }
                    }
                    @Override
                    public void onFailure(HDLException e) {
                    }
                });
            }
            @Override
            public void onFailure(HDLException e) {
                HdlLogLogic.print("获取智能体AppKey失败 Pu" + e.getMessage(), true);
            }
        });
    }
@@ -417,6 +513,7 @@
    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d("BPowerStationActivity", "onDestroy");
        HdlUniLogic.getInstance().checkRemoveOtherUniMPEventCallBack();
        //移除监听
        HDLLinkLocalSdk.getInstance().removeAllTopicsListener(allTopicsListener);
@@ -608,7 +705,7 @@
                        uniCallBackBaseBean.setData(topicArray[1]);
                        HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean);
                        HdlLogLogic.print(linkResponse.getTopic() + new Gson().toJson(linkResponse.getData()), true);
                    } else if (linkResponse.getTopic().endsWith("/app/thing/event/appHomeRefresh/up")) {
                    } else if (linkResponse.getTopic().endsWith("/app/thing/event/appHomeDeliverRollbackRefresh/up")) {
                        //B端登录电站回滚时,收到回滚的事件时,发个通知给uniapp,uniapp刷新下电站的权限,调整下菜单栏的内容。
                        String[] topicArray = linkResponse.getTopic().split("/");
                        if (topicArray.length < 2) {
@@ -728,7 +825,7 @@
                    public void run() {
                        //防止app启动的时候没有网络(app也登录不了),导致获取不了mqtt远程连接信息;
                        initMqttClient();
                        HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<GatewayBean>>() {
                        HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(UserConfigManage.getInstance().getHomeId(), UserConfigManage.getInstance().getPowerStationType(), new CloudCallBeak<List<GatewayBean>>() {
                            @Override
                            public void onSuccess(List<GatewayBean> obj) {
//                                AppManagerUtils.getAppManager().hideLoading();
@@ -749,6 +846,12 @@
                bottomViewChangeOfStyle();
                showFragment();
            }
        } else if (event.getTopic().contains(ConstantManage.refresh_push_token)) {
            String token = event.getType();
            UserConfigManage.getInstance().setPushToken(token);
            UserConfigManage.getInstance().Save();
            //pushToken更新
            sendPushTokenToServer(UserConfigManage.getInstance().getPushToken());
        }
    }
@@ -801,19 +904,28 @@
        });
    }
    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        //AndroidManifest.xml 需要添加启动模式android:launchMode="singleTask"才执行这个方法
        OpenSpecifiedPage(intent, "onNewIntent");
    }
    /**
     * 点击极光通知栏消息进来
     * 点击通知栏消息进来,默认选择消息模块
     */
    private void clickJpushNotificationMessage() {
        Intent intent = getIntent();
        if (intent != null) {
            String key = intent.getStringExtra("skip");
            if (key != null) {
                //触发消息点击事件
                viewBinding.myMessageBottomIl2.clickTv.performClick();
            }
        }
    private void clickNotificationMessageTab() {
        //触发消息点击事件
        viewBinding.myMessageBottomIl2.clickTv.performClick();
//        if (currentFragmentIndex == 2) {
//            HdlCommonLogic.getInstance().postEventBusSticky(ConstantManage.refresh_message_house, ConstantManage.refresh_message_house);
//            return;
//        }
//        currentFragmentIndex = 2;
//        bottomViewChangeOfStyle();
//        showFragment();
//        HdlCommonLogic.lowerTagType = LowerTagType.message;
//        HdlCommonLogic.getInstance().postEventBusSticky(ConstantManage.refresh_message_house, ConstantManage.refresh_message_house);
    }
@@ -907,5 +1019,29 @@
        }
    }
    /**
     * 处理从通知点击带来的数据,这里获取数据,然后透传给主界面做处理
     *
     * @return 返回附加数据
     */
    private String getIntentExpantData(Intent intent) {
        try {
            if (intent == null) {
                return "";
            }
            // 处理从通知点击带来的数据,这里获取数据,然后透传给主界面做处理
            if (intent.getExtras() != null) {
                for (String key : intent.getExtras().keySet()) {
                    if (key.equals("pushData")) {
                        return Objects.requireNonNull(intent.getExtras().get(key)).toString();
                    }
                }
            }
        } catch (Exception e) {
            return "";
        }
        return "";
    }
}