From 5e080d063f213f2b2c2ed34e1d54b9fd7df1c6b0 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期四, 23 十一月 2023 19:28:47 +0800
Subject: [PATCH] 2023年11月23日19:28:37

---
 app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java |   67 +++++++++++++++++++--------------
 1 files changed, 38 insertions(+), 29 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 a5be3d4..36f0772 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
@@ -53,6 +53,7 @@
 import java.util.Objects;
 
 import io.dcloud.feature.unimp.DCUniMPJSCallback;
+import okhttp3.ResponseBody;
 
 /**
  * uni灏忕▼搴忕殑閫昏緫
@@ -264,6 +265,11 @@
                     //璁惧椹卞姩鍗囩骇
                     case HDLUniMP.UNI_EVENT_REPLY_OTA_DRIVER_UPGRADE: {
                         this.uniUpgradeGatewayDriver(data, callback);
+                    }
+                    break;
+                    //璁惧鍙栨秷涓嬭浇鍗囩骇鏂囦欢
+                    case HDLUniMP.UNI_EVENT_REPLY_OTA_DRIVER_CANCEL_DOWNLOAD: {
+                        this.uniCancelDownloadingUpgradeFile(data, callback);
                     }
                     break;
 
@@ -530,12 +536,15 @@
             File file = new File(driverFileList);
             if (file.list() != null) {
                 for (int i = 0; i < Objects.requireNonNull(file.list()).length; i++) {
-                    String path = Objects.requireNonNull(file.list())[i];
-                    String[] ary = path.split("/");
-                    String[] driverInfoAry = ary[ary.length - 1].split("_");
+                    String fileName = Objects.requireNonNull(file.list())[i];
+                    if (!fileName.contains(driveCode)) {
+                        continue;
+                    }
+                    String[] driverInfoAry = fileName.split("_");
                     GatewayDriverBean gatewayDriverBean = new GatewayDriverBean();
                     gatewayDriverBean.setDriverCode(driverInfoAry[0]);
                     gatewayDriverBean.setVersion(driverInfoAry[1].replace(".zip", ""));
+                    gatewayDriverBean.setLocalUrl(HdlFileLogic.getInstance().getDrivePathFileName(gatewayDriverBean.getDriverCode(), gatewayDriverBean.getVersion()));
                     list.add(gatewayDriverBean);
                 }
             }
@@ -549,7 +558,7 @@
     }
 
     /**
-     * 鍚戜簯绔彂璧枫�愯澶囬┍鍔ㄣ�戜笅杞芥寚浠�
+     * 鍚戜簯绔彂璧枫�愯澶囬┍鍔ㄤ笅杞姐�戞寚浠�
      */
     private void uniGatewayDriverDownload(Object data, DCUniMPJSCallback callback) {
         String deviceOid = getKeyValue("oid", getKeyValue("data", data));//缃戝叧璁惧oid
@@ -557,32 +566,25 @@
         String imageId = getKeyValue("imageId", getKeyValue("data", data));//椹卞姩闀滃儚id
         String version = getKeyValue("version", getKeyValue("data", data));//椹卞姩鐗堟湰
         String driverVersionId = getKeyValue("driverVersionId", getKeyValue("data", data));//椹卞姩鐗堟湰id
-        HdlOtaLogic.getInstance().getDeviceDriverDownloadUrl(driverVersionId, new CloudCallBeak<DownloadUrlBean>() {
+        String localUrl = getKeyValue("localUrl", getKeyValue("data", data));//鍌ㄥ瓨鍦ㄦ湰鍦伴┍鍔ㄦ枃浠惰矾寰�
+        String url = getKeyValue("url", getKeyValue("data", data));//浜戠涓婃枃浠跺湴鍧�
+        String md5 = getKeyValue("md5", getKeyValue("data", data));//浜戠涓婃枃浠禡D5
+        HdlOtaLogic.getInstance().getDeviceDriverDownloadFile(url, new CloudCallBeak<ResponseBody>() {
             @Override
-            public void onSuccess(DownloadUrlBean downloadUrlBean) {
-                if (downloadUrlBean == null) {
-                    uniCallbackData(null, -2, "涓嬭浇閾炬帴鎵句笉鍒�", callback);
-                    return;
+            public void onSuccess(ResponseBody responseBody) {
+                String drivePathFileName = HdlFileLogic.getInstance().getDrivePathFileName(driverCode, version);
+                boolean isBoolean = HdlOtaLogic.getInstance().disposeDownLoadFile(drivePathFileName, responseBody, md5, HdlOtaLogic.driver_type);
+                if (isBoolean) {
+                    HdlFileLogic.getInstance().deleteFile(localUrl);//涓嬭浇鎴愬姛,鍒犻櫎鏃ф枃浠�;
+                } else {
+                    HdlFileLogic.getInstance().deleteFile(drivePathFileName);//涓嬭浇澶辫触鍒犻櫎涓嶅畬鎴愭暟鎹�;
                 }
-                HdlOtaLogic.getInstance().getDeviceDriverDownloadFile(downloadUrlBean.getDownloadUrl(), new CloudCallBeak<DownloadUrlBean>() {
-                    @Override
-                    public void onSuccess(DownloadUrlBean obj) {
-                        Gson gson = new Gson();
-                        String json = gson.toJson(obj);
-                        String drivePathFileName = HdlFileLogic.getInstance().getDrivePathFileName(driverCode, version);
-                        HdlFileLogic.getInstance().writeFile(drivePathFileName, json);
-
-                    }
-
-                    @Override
-                    public void onFailure(HDLException e) {
-
-                    }
-                });
+                HdlLogLogic.print("鍐欏叆鏂伴┍鍔ㄦ枃浠跺埌鍐呭瓨鎴愬姛.", false);
             }
 
             @Override
             public void onFailure(HDLException e) {
+                HdlLogLogic.print("涓嬭浇椹卞姩鏂囦欢鍒板唴瀛樺け璐�.", false);
                 uniCallbackData(null, e.getCode(), e.getMsg(), callback);
             }
         });
@@ -636,17 +638,17 @@
                 }
             });
         } else {
-            //杩滅▼鍗囩骇闇�瑕佹娴嬪湪閫嗗彉鍣ㄦ湁娌℃湁杩炴帴涓婁簯
+            //杩滅▼鍗囩骇闇�瑕併�愭娴嬨�戝湪閫嗗彉鍣ㄦ湁娌℃湁杩炴帴涓婁簯
             HdlDeviceLogic.getInstance().checkInverterConnectedCloud(deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
                 @Override
                 public void onSuccess(CloudInverterDeviceBean cloudInverterDeviceBean) {
-                    //1:寰呮満,2:杩炴帴涓�,3:鏁呴殰,4:杩愯,5:绂荤嚎,6:閫嗗彉鍣ㄨ繛涓嶄笂浜�(鑷畾涔�)
+                    //1锛氳繛鎺ヤ腑,2锛氭晠闅�,3锛氳繍琛�,4锛氱绾�,6:閫嗗彉鍣ㄨ繛涓嶄笂浜�(鑷畾涔�)
                     if (cloudInverterDeviceBean == null) {
-                        uniCallbackData(null, 6, HDLApp.getInstance().getString(R.string.ota_not_cloud_upgrade_fails), callback);
+                        uniCallbackData(null, 6, HDLApp.getInstance().getString(R.string.ota_binding_cloud_upgrade_fails), callback);
                         return;
                     }
-                    if (cloudInverterDeviceBean.getDeviceStatus() != 4) {
-                        uniCallbackData(null, cloudInverterDeviceBean.getDeviceStatus(), getDeviceStatusString(cloudInverterDeviceBean.getDeviceStatus()), callback);
+                    if (cloudInverterDeviceBean.getDeviceStatus() != 3) {
+                        uniCallbackData(null, cloudInverterDeviceBean.getDeviceStatus(), HDLApp.getInstance().getString(R.string.ota_not_cloud_upgrade_fails), callback);
                         return;
                     }
                     //4:杩愯
@@ -673,6 +675,13 @@
         }
     }
 
+    /**
+     * 鍙栨秷涓嬭浇鍗囩骇鏂囦欢
+     */
+    private void uniCancelDownloadingUpgradeFile(Object data, DCUniMPJSCallback callback) {
+        HdlOtaLogic.getInstance().setStopDriversDownload();
+    }
+
 
     /**
      * @param deviceStatus 閫嗗彉鍣ㄨ繛鎺ヤ簯绔姸鎬佸�硷紙 1:寰呮満,2:杩炴帴涓�,3:鏁呴殰,4:杩愯,5:绂荤嚎锛�

--
Gitblit v1.8.0