From d723fee177238df0dbab80eb788876ebd154927d Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期四, 24 十月 2024 11:55:46 +0800
Subject: [PATCH] Update HDLLoginInterceptor.java

---
 HDLLinkPMSdk/src/main/java/com/hdl/linkpm/sdk/template/HDLLinkPMTemplate.java |  630 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 630 insertions(+), 0 deletions(-)

diff --git a/HDLLinkPMSdk/src/main/java/com/hdl/linkpm/sdk/template/HDLLinkPMTemplate.java b/HDLLinkPMSdk/src/main/java/com/hdl/linkpm/sdk/template/HDLLinkPMTemplate.java
new file mode 100644
index 0000000..e95f41d
--- /dev/null
+++ b/HDLLinkPMSdk/src/main/java/com/hdl/linkpm/sdk/template/HDLLinkPMTemplate.java
@@ -0,0 +1,630 @@
+package com.hdl.linkpm.sdk.template;/*
+ *create by wxr
+ *date 2022/1/19
+ */
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.hdl.hdlhttp.HxHttp;
+import com.hdl.linkpm.sdk.HDLLinkPMSdk;
+import com.hdl.linkpm.sdk.core.callback.IDefaultCallBack;
+import com.hdl.linkpm.sdk.core.exception.HDLException;
+import com.hdl.linkpm.sdk.core.interceptor.HDLSmartHeader;
+import com.hdl.linkpm.sdk.core.response.HDLResponse;
+import com.hdl.linkpm.sdk.template.bean.CloudTemplateDevice;
+import com.hdl.linkpm.sdk.template.bean.CloudTemplateSpatialInfo;
+import com.hdl.linkpm.sdk.template.bean.TemplateDeviceBean;
+import com.hdl.linkpm.sdk.template.bean.TemplateFunctionBean;
+import com.hdl.linkpm.sdk.template.bean.TemplateGatewayBean;
+import com.hdl.linkpm.sdk.template.bean.TemplateListResponseBean;
+import com.hdl.linkpm.sdk.template.bean.TemplateLogicBean;
+import com.hdl.linkpm.sdk.template.bean.TemplateRoomPackBean;
+import com.hdl.linkpm.sdk.template.bean.TemplateSceneBean;
+import com.hdl.linkpm.sdk.template.bean.TemplateSecurityBean;
+import com.hdl.linkpm.sdk.template.callback.ICreateTemplateCallBack;
+import com.hdl.linkpm.sdk.template.callback.IGetTemplateDeviceListCallBack;
+import com.hdl.linkpm.sdk.template.callback.IGetTemplateGatewayListCallBack;
+import com.hdl.linkpm.sdk.template.callback.IGetTemplateSpatialInfoCallBack;
+import com.hdl.linkpm.sdk.template.callback.ITemplateFunctionsCallBack;
+import com.hdl.linkpm.sdk.template.callback.ITemplateListCallBack;
+import com.hdl.linkpm.sdk.template.callback.ITemplateLogicCallBack;
+import com.hdl.linkpm.sdk.template.callback.ITemplateScenesCallBack;
+import com.hdl.linkpm.sdk.template.callback.ITemplateSecurityCallBack;
+import com.hdl.linkpm.sdk.template.controller.HDLTemplateController;
+import com.hdl.linkpm.sdk.utils.HDLFileUtils;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+import io.reactivex.rxjava3.disposables.Disposable;
+import io.reactivex.rxjava3.functions.Consumer;
+import okhttp3.ResponseBody;
+
+public class HDLLinkPMTemplate {
+
+    /**
+     * instance
+     */
+    private volatile static HDLLinkPMTemplate instance;
+
+    /**
+     * getInstance
+     *
+     * @return HDLPMTemplateController
+     */
+    public static synchronized HDLLinkPMTemplate getInstance() {
+        if (instance == null) {
+            synchronized (HDLLinkPMTemplate.class) {
+                if (instance == null) {
+                    instance = new HDLLinkPMTemplate();
+                }
+            }
+        }
+        return instance;
+    }
+
+    /**
+     * 鍒涘缓妯℃澘
+     * @param templateName 妯℃澘鍚嶇О
+     * @param communityCode 绀惧尯缂栫爜
+     * @param houseLayoutId 鎴峰瀷id (瑕佽皟鐢ㄦ埛鍨嬪垪琛ㄧ殑鎺ュ彛)
+     * @param templateDesc 妯℃澘鎻忚堪
+     * @param callBack 鍥炶皟
+     */
+    public void CreateTemplate(String templateName,String communityCode,String houseLayoutId,String templateDesc,ICreateTemplateCallBack callBack) {
+        HDLTemplateController.getInstance().CreateTemplate(templateName, communityCode, houseLayoutId, templateDesc, new ICreateTemplateCallBack() {
+            @Override
+            public void onSuccess(String templateId) {
+                callBack.onSuccess(templateId);
+            }
+
+            @Override
+            public void onFailure(HDLException error) {
+                callBack.onFailure(error);
+            }
+        });
+    }
+
+    /**
+     * 娣诲姞璁惧(鍏ㄩ噺)
+     * @param templateExtendsId
+     * @param beans
+     * @param callBack
+     */
+    public void UpdateTemplateDevices(String templateExtendsId,List<TemplateDeviceBean> beans,IDefaultCallBack callBack){
+        HDLTemplateController.getInstance().UpdateTemplateDevices(templateExtendsId, beans, new IDefaultCallBack() {
+            @Override
+            public void onSuccess() {
+                if (callBack != null) {
+                    callBack.onSuccess();
+                }
+            }
+
+            @Override
+            public void onFailure(HDLException error) {
+                if (callBack != null) {
+                    callBack.onFailure(error);
+                }
+            }
+        });
+    }
+
+    /**
+     * 涓婁紶妯℃澘zb鏁版嵁鏂囦欢鏂囦欢
+     *
+     * @param templateExtendsId   妯℃澘ID
+     * @param file  涓婁紶鐨勬枃浠�
+     * @param callBack
+     * @return
+     */
+    public Disposable TemplateZbFileUpload(String templateExtendsId, File file, IDefaultCallBack callBack) {
+        String requestUrl = HDLLinkPMSdk.getUserRegionUrl() +  "/iot-cloud/debug/backup/file/zigbeeDataUpload?templateExtendsId=" + templateExtendsId;
+        return HxHttp.builder()
+                .file(file, "file")
+                .url(requestUrl)
+                .build()
+                .upload()
+                .subscribeWith(new HDLResponse<String>() {
+                    @Override
+                    public void onResponse(String code) {
+//                        FileUtils.deleteFile(file);//涓嶇敤鍒犳帀鏈湴鏂囦欢 2022-09-28 17:24:06
+                        if (callBack != null) {
+                            callBack.onSuccess();
+                        }
+                    }
+
+                    @Override
+                    public void onFailure(HDLException e) {
+                        HDLFileUtils.deleteFile(file);
+                        if (callBack != null) {
+                            callBack.onFailure(e);
+                        }
+                    }
+                });
+    }
+
+
+    /**
+     * 涓嬭浇妯℃澘zb鏁版嵁鏂囦欢鏂囦欢
+     */
+    public static boolean saveTempalteZbFile(ResponseBody zipData,File file) {
+        // 濡傛灉瀛樺湪灏卞厛鍒犻櫎鏁版嵁锛屾暟鎹細杩藉姞
+        if(file.exists()){
+            file.delete();
+            file.deleteOnExit();
+        }
+        InputStream is = null;
+        byte[] buf = new byte[4096];
+        int len = 0;
+        FileOutputStream fos = null;
+        try {
+            is = zipData.byteStream();
+            long total = zipData.contentLength();
+            fos = new FileOutputStream(file);
+            long sum = 0;
+            while ((len = is.read(buf)) != -1) {
+                fos.write(buf, 0, len);
+                sum += len;
+            }
+            fos.flush();
+            return true;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
+        } finally {
+            try {
+                if (is != null)
+                    is.close();
+            } catch (IOException e) {
+            }
+            try {
+                if (fos != null)
+                    fos.close();
+            } catch (IOException e) {
+            }
+        }
+    }
+
+    /**
+     * 鑾峰彇妯℃澘zb鏁版嵁鏂囦欢Url
+     * @return
+     */
+    public Disposable getTempalteZbFileUrl(String templateExtendsId,File file,  IDefaultCallBack callBack) {
+        String requestUrl = HDLLinkPMSdk.getUserRegionUrl() +  "/iot-cloud/debug/backup/file/zigbeeDataNewestUrl";
+
+
+        JsonObject json = new JsonObject();
+        json.addProperty("templateExtendsId", templateExtendsId);
+
+        return HxHttp.builder()
+                .url(requestUrl)
+                .raw(json.toString())
+                .build()
+                .post()
+                .subscribeWith(new HDLResponse<String>() {
+                    @Override
+                    public void onResponse(String url) {
+                        if (url == null) {
+                            callBack.onSuccess();
+                        } else {
+                            if (callBack != null) {
+                                downloadTempalteZbFile(url, file, new IDefaultCallBack() {
+                                    @Override
+                                    public void onSuccess() {
+                                        callBack.onSuccess();
+
+                                    }
+
+                                    @Override
+                                    public void onFailure(HDLException error) {
+                                        callBack.onFailure(error);
+                                    }
+                                });
+                            }
+                        }
+                    }
+                    @Override
+                    public void onFailure(HDLException e) {
+                        if (callBack != null) {
+                            callBack.onFailure(e);
+                        }
+                    }
+                });
+    }
+
+
+    /**
+     * 涓嬭浇妯℃澘zb鏁版嵁鏂囦欢鏂囦欢
+     * @param callBack
+     * @return
+     */
+    public Disposable downloadTempalteZbFile(String url,File file, IDefaultCallBack callBack) {
+        return HxHttp.builder()
+                .url(url)
+                .headers(HDLSmartHeader.IGNORE_SIGN_HEADER,1)
+                .build()
+                .download()
+                .subscribe(new Consumer<ResponseBody>() {
+                    @Override
+                    public void accept(ResponseBody responseBody) throws Exception {
+                        //缃戠粶璇锋眰鎴愬姛锛岃鍙栨枃浠朵繚瀛樺埌sd鍗�
+//                        callBack.onSuccess(responseBody);
+                        //淇濆瓨鏂囦欢
+//                        File file = new File(getUserFilesPath() + "/" + templateBean.getTemplateExtendsId());
+
+                        boolean saveResult = saveTempalteZbFile(responseBody,file);
+                        if(saveResult) {
+                            callBack.onSuccess();
+                        }else {
+                            callBack.onFailure(new HDLException(0,""));
+                        }
+                    }
+                }, new Consumer<Throwable>() {
+                    @Override
+                    public void accept(Throwable throwable) throws Exception {
+                        /**
+                         * 缃戠粶璇锋眰澶辫触
+                         * 鍏蜂綋鍙互鑷繁瀹炵幇
+                         */
+                        callBack.onFailure(new HDLException(404,""));
+                    }
+                });
+    }
+
+
+    /**
+     * 鑾峰彇妯℃澘鍒楄〃
+     * @param callBack
+     */
+    public void GetTemplateList(int pageNo, int pageSize, ITemplateListCallBack callBack) {
+        HDLTemplateController.getInstance().GetTemplateList(pageNo,pageSize,new ITemplateListCallBack() {
+            @Override
+            public void onSuccess(TemplateListResponseBean templateListResponseBeans) {
+                callBack.onSuccess(templateListResponseBeans);
+            }
+
+            @Override
+            public void onFailure(HDLException error) {
+                if (callBack != null) {
+                    callBack.onFailure(error);
+                }
+            }
+        });
+    }
+
+    /**
+     * 鍒犻櫎妯℃澘
+     * @param templateExtendsId 妯℃澘ID
+     * @param callBack
+     */
+    public void DeleteTemplate(String templateExtendsId,IDefaultCallBack callBack){
+        HDLTemplateController.getInstance().DeleteTemplate(templateExtendsId, new IDefaultCallBack() {
+            @Override
+            public void onSuccess() {
+                if (callBack != null) {
+                    callBack.onSuccess();
+                }
+            }
+
+            @Override
+            public void onFailure(HDLException error) {
+                if (callBack != null) {
+                    callBack.onFailure(error);
+                }
+            }
+        });
+    }
+
+    /**
+     * 鏇存柊缃戝叧鏁版嵁(鍏ㄩ噺)
+     */
+    public void UpdateTemplateGateway(String templateExtendsId , List<TemplateGatewayBean> gatewayBeans,
+                                      IDefaultCallBack callBack){
+        HDLTemplateController.getInstance().UpdateTemplateGateway(templateExtendsId, gatewayBeans, new IDefaultCallBack() {
+            @Override
+            public void onSuccess() {
+                if (callBack != null) {
+                    callBack.onSuccess();
+                }
+            }
+
+            @Override
+            public void onFailure(HDLException error) {
+                if (callBack != null) {
+                    callBack.onFailure(error);
+                }
+            }
+        });
+    }
+
+    /**
+     * 鏇存柊鎴块棿锛堟ゼ灞傦級淇℃伅(鍏ㄩ噺)
+     * @param templateExtendsId
+     * @param rooms
+     * @param callBack
+     * @return
+     */
+    public void UpdateTemplateRoom(String templateExtendsId ,List<TemplateRoomPackBean.TemplateRoomInfoBean> rooms,
+                                         IDefaultCallBack callBack){
+        HDLTemplateController.getInstance().UpdateTemplateRoom(templateExtendsId, rooms, new IDefaultCallBack() {
+            @Override
+            public void onSuccess() {
+                if (callBack != null) {
+                    callBack.onSuccess();
+                }
+            }
+
+            @Override
+            public void onFailure(HDLException error) {
+                if (callBack != null) {
+                    callBack.onFailure(error);
+                }
+            }
+        });
+    }
+
+    /**
+     * 娣诲姞鍔熻兘(鍏ㄩ噺)
+     * @param templateExtendsId 妯℃澘鍚嶇О
+     * @param functionInfoList 鍔熻兘鍒楄〃
+     * @param callBack 鍥炶皟
+     */
+    public void UpdateTemplateFunctions(String templateExtendsId, List<TemplateFunctionBean> functionInfoList,
+                                              IDefaultCallBack callBack){
+        HDLTemplateController.getInstance().UpdateTemplateFunctions(templateExtendsId, functionInfoList, new IDefaultCallBack() {
+            @Override
+            public void onSuccess() {
+                if (callBack != null) {
+                    callBack.onSuccess();
+                }
+            }
+
+            @Override
+            public void onFailure(HDLException error) {
+                if (callBack != null) {
+                    callBack.onFailure(error);
+                }
+            }
+        });
+    }
+
+    /**
+     * 鏇存柊妯℃澘鍦烘櫙(鍏ㄩ噺)
+     * @param templateExtendsId
+     * @param sceneBeans
+     * @param callBack
+     */
+    public void UpdataTemplateScenes(String templateExtendsId, List<TemplateSceneBean> sceneBeans,
+                                     IDefaultCallBack callBack){
+        HDLTemplateController.getInstance().UpdataTemplateScenes(templateExtendsId, sceneBeans, new IDefaultCallBack() {
+            @Override
+            public void onSuccess() {
+                if(callBack != null){
+                    callBack.onSuccess();
+                }
+            }
+
+            @Override
+            public void onFailure(HDLException error) {
+                if(callBack != null){
+                    callBack.onFailure(error);
+                }
+            }
+        });
+    }
+
+    /**
+     * 鏇存柊妯℃澘鑷姩鍖� (鍏ㄩ噺)
+     * @param templateExtendsId
+     * @param logicBeansJson
+     * @param callBack
+     */
+    public void UpdataTemplateLogic(String templateExtendsId, JsonElement logicBeansJson,// List<TemplateLogicBean> logicBeans,
+                                    IDefaultCallBack callBack){
+        HDLTemplateController.getInstance().UpdataTemplateLogic(templateExtendsId, logicBeansJson, new IDefaultCallBack() {
+            @Override
+            public void onSuccess() {
+                if(callBack != null){
+                    callBack.onSuccess();
+                }
+            }
+
+            @Override
+            public void onFailure(HDLException error) {
+                if(callBack != null){
+                    callBack.onFailure(error);
+                }
+            }
+        });
+    }
+
+    /**
+     * 鏇存柊妯℃澘瀹夐槻 (鍏ㄩ噺)
+     * @param templateExtendsId
+     * @param securityInfos
+     * @param callBack
+     */
+    public void UpdataTemplateSecurity(String templateExtendsId, JsonElement securityInfos ,IDefaultCallBack callBack  ){
+        HDLTemplateController.getInstance().UpdataTemplateSecurity(templateExtendsId, securityInfos, new IDefaultCallBack() {
+            @Override
+            public void onSuccess() {
+                if(callBack != null){
+                    callBack.onSuccess();
+                }
+            }
+
+            @Override
+            public void onFailure(HDLException error) {
+                if(callBack != null){
+                    callBack.onFailure(error);
+                }
+            }
+        });
+    }
+
+    /**
+     * 鑾峰彇鍖哄煙淇℃伅
+     * @param templateExtendsId
+     * @param callBack
+     */
+    public void GetTemplateAreaSpatialInfo(String templateExtendsId ,IGetTemplateSpatialInfoCallBack callBack){
+        HDLTemplateController.getInstance().GetTemplateAreaSpatialInfo(templateExtendsId, new IGetTemplateSpatialInfoCallBack() {
+            @Override
+            public void onSuccess(List<CloudTemplateSpatialInfo> data) {
+                if (callBack != null) {
+                    callBack.onSuccess(data);
+                }
+            }
+
+            @Override
+            public void onFailure(HDLException error) {
+                if (callBack != null) {
+                    callBack.onFailure(error);
+                }
+            }
+        });
+    }
+
+    /**
+     * 鑾峰彇缃戝叧鍒楄〃
+     * @param id
+     * @param callBack
+     */
+    public void GetTemplateGatewayList(String id, IGetTemplateGatewayListCallBack callBack){
+        HDLTemplateController.getInstance().GetTemplateGatewayList(id, new IGetTemplateGatewayListCallBack() {
+            @Override
+            public void onSuccess(List<TemplateGatewayBean> data) {
+                if (callBack != null) {
+                    callBack.onSuccess(data);
+                }
+            }
+
+            @Override
+            public void onFailure(HDLException error) {
+                if (callBack != null) {
+                    callBack.onFailure(error);
+                }
+            }
+        });
+    }
+
+    /**
+     * 鑾峰彇璁惧淇℃伅
+     * @param templateId
+     * @param callBack
+     */
+    public void GetTemplateDeviceList(String templateId,IGetTemplateDeviceListCallBack callBack){
+        HDLTemplateController.getInstance().GetTemplateDeviceList(templateId, new IGetTemplateDeviceListCallBack() {
+            @Override
+            public void onSuccess(List<CloudTemplateDevice> data) {
+                if (callBack != null) {
+                    callBack.onSuccess(data);
+                }
+            }
+
+            @Override
+            public void onFailure(HDLException error) {
+                if (callBack != null) {
+                    callBack.onFailure(error);
+                }
+            }
+        });
+    }
+
+    /**
+     * 鑾峰彇鍔熻兘鍒楄〃
+     * @param templateExtendsId
+     * @param callBack
+     */
+    public void GetTemplateFunctions(String templateExtendsId , ITemplateFunctionsCallBack callBack){
+        HDLTemplateController.getInstance().GetTemplateFunctions(templateExtendsId, new ITemplateFunctionsCallBack() {
+            @Override
+            public void onSuccess(List<TemplateFunctionBean> templateFunctionBean) {
+                if (callBack != null) {
+                    callBack.onSuccess(templateFunctionBean);
+                }
+            }
+
+            @Override
+            public void onFailure(HDLException error) {
+                if (callBack != null) {
+                    callBack.onFailure(error);
+                }
+            }
+        });
+    }
+
+    /**
+     * 鑾峰彇鍦烘櫙鍒楄〃
+     * @param templateExtendsId
+     * @param callBack
+     */
+    public void GetTemplateScenes(String templateExtendsId , ITemplateScenesCallBack callBack){
+        HDLTemplateController.getInstance().GetTemplateScenes(templateExtendsId, new ITemplateScenesCallBack() {
+            @Override
+            public void onSuccess(List<TemplateSceneBean> data) {
+                if (callBack != null) {
+                    callBack.onSuccess(data);
+                }
+            }
+
+            @Override
+            public void onFailure(HDLException error) {
+                if (callBack != null) {
+                    callBack.onFailure(error);
+                }
+            }
+        });
+    }
+
+    /**
+     * 鑾峰彇瀹夐槻鍒楄〃
+     * @param templateExtendsId
+     * @param callBack
+     */
+    public void GetTemplateSecurity(String templateExtendsId , ITemplateSecurityCallBack callBack){
+        HDLTemplateController.getInstance().GetTemplateSecurity(templateExtendsId, new ITemplateSecurityCallBack() {
+                    @Override
+                    public void onSuccess(List<TemplateSecurityBean> data) {
+                        if (callBack != null) {
+                            callBack.onSuccess(data);
+                        }
+                    }
+
+                    @Override
+                    public void onFailure(HDLException error) {
+                        if (callBack != null) {
+                            callBack.onFailure(error);
+                        }
+                    }
+                }
+        );
+    }
+
+    /**
+     * 鑾峰彇閫昏緫鍒楄〃
+     * @param templateExtendsId
+     * @param callBack
+     */
+    public void GetTemplateLogic(String templateExtendsId ,ITemplateLogicCallBack  callBack){
+        HDLTemplateController.getInstance().GetTemplateLogic(templateExtendsId, new ITemplateLogicCallBack() {
+                    @Override
+                    public void onSuccess(List<TemplateLogicBean> data) {
+                        if (callBack != null) {
+                            callBack.onSuccess(data);
+                        }
+                    }
+
+                    @Override
+                    public void onFailure(HDLException error) {
+                        if (callBack != null) {
+                            callBack.onFailure(error);
+                        }
+                    }
+                }
+        );
+    }
+}

--
Gitblit v1.8.0