From ce88de4891b87c3b7b2750575e15d6e48d518852 Mon Sep 17 00:00:00 2001 From: hxb <hxb@hdlchina.com.cn> Date: 星期四, 24 十月 2024 10:39:12 +0800 Subject: [PATCH] 增加云端库 --- HDLLinkPMSdk/src/main/java/com/hdl/linkpm/sdk/template/controller/HDLTemplateController.java | 642 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 642 insertions(+), 0 deletions(-) diff --git a/HDLLinkPMSdk/src/main/java/com/hdl/linkpm/sdk/template/controller/HDLTemplateController.java b/HDLLinkPMSdk/src/main/java/com/hdl/linkpm/sdk/template/controller/HDLTemplateController.java new file mode 100644 index 0000000..090fec5 --- /dev/null +++ b/HDLLinkPMSdk/src/main/java/com/hdl/linkpm/sdk/template/controller/HDLTemplateController.java @@ -0,0 +1,642 @@ +package com.hdl.linkpm.sdk.template.controller;/* + *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.api.HDLCloudUserApi; +import com.hdl.linkpm.sdk.core.callback.IDefaultCallBack; +import com.hdl.linkpm.sdk.core.exception.HDLException; +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.utils.HDLExceptionSubmitUtils; +import com.hdl.linkpm.sdk.utils.HDLGsonUtils; + +import java.util.List; + +import io.reactivex.rxjava3.disposables.Disposable; + +public class HDLTemplateController { + private volatile static HDLTemplateController instance; + + public static synchronized HDLTemplateController getInstance() { + if (instance == null) { + synchronized (HDLTemplateController.class) { + if (instance == null) { + instance = new HDLTemplateController(); + } + } + } + return instance; + } + + + /** + * 鍒涘缓妯℃澘 + * @param templateName + * @param communityCode + * @param houseLayoutId + * @param templateDesc + * @param callBack + * @return + */ + public Disposable CreateTemplate(String templateName, String communityCode, String houseLayoutId, String templateDesc, ICreateTemplateCallBack callBack) { + String requestUrl = HDLLinkPMSdk.getUserRegionUrl() + HDLCloudUserApi.POST_TEMPLATE_CREATE; + JsonObject json = new JsonObject(); + json.addProperty("templateName", templateName); + json.addProperty("templateSourcePlatform", "app"); + json.addProperty("communityCode", communityCode); + json.addProperty("houseLayoutId", houseLayoutId); + json.addProperty("templateDesc", templateDesc); + return HxHttp.builder() + .url(requestUrl) + .raw(json.toString()) + .build() + .post() + .subscribeWith(new HDLResponse<String>() { + @Override + public void onResponse(String data) { + if (callBack != null) { + callBack.onSuccess(data); + } + } + + @Override + public void onFailure(HDLException e) { + HDLExceptionSubmitUtils.submit(requestUrl, json, e); + if (callBack != null) { + callBack.onFailure(e); + } + } + }); + } + + public Disposable GetTemplateList(int pageNo,int pageSize,ITemplateListCallBack callBack) { + String requestUrl = HDLLinkPMSdk.getUserRegionUrl() + HDLCloudUserApi.POST_TEMPLATE_GET_LIST; + JsonObject json = new JsonObject(); + json.addProperty("pageNo",pageNo); + json.addProperty("pageSize",pageSize); + return HxHttp.builder() + .url(requestUrl) + .raw(json.toString()) + .build() + .post() + .subscribeWith(new HDLResponse<TemplateListResponseBean>() { + @Override + public void onResponse(TemplateListResponseBean beans) { + if (callBack != null) { + callBack.onSuccess(beans); + } + } + + @Override + public void onFailure(HDLException e) { + HDLExceptionSubmitUtils.submit(requestUrl, json, e); + if (callBack != null) { + callBack.onFailure(e); + } + } + }); + } + /** + * 鍒犻櫎妯℃澘 + * @param templateExtendsId 妯℃澘ID + * @param callBack + * @return + */ + public Disposable DeleteTemplate(String templateExtendsId,IDefaultCallBack callBack) { + String requestUrl = HDLLinkPMSdk.getUserRegionUrl() + HDLCloudUserApi.POST_TEMPLATE_DELETE; + 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 code) { + if (callBack != null) { + callBack.onSuccess(); + } + } + + @Override + public void onFailure(HDLException e) { + HDLExceptionSubmitUtils.submit(requestUrl, json, e); + if (callBack != null) { + callBack.onFailure(e); + } + } + }); + } + + /** + * 鏇存柊缃戝叧鍒楄〃(鍏ㄩ噺) + * @param templateExtendsId + * @param gatewayBeans + * @param callBack + * @return + */ + public Disposable UpdateTemplateGateway(String templateExtendsId, List<TemplateGatewayBean> gatewayBeans,IDefaultCallBack callBack){ + String requestUrl = HDLLinkPMSdk.getUserRegionUrl() + HDLCloudUserApi.POST_TEMPLATE_UPDATE_GATEWAY; + JsonObject json = new JsonObject(); + json.addProperty("templateExtendsId", templateExtendsId); + json.add("beans", HDLGsonUtils.toJsonArray(gatewayBeans)); + return HxHttp.builder() + .url(requestUrl) + .raw(json.toString()) + .build() + .post() + .subscribeWith(new HDLResponse<String>() { + @Override + public void onResponse(String code) { + if (callBack != null) { + callBack.onSuccess(); + } + } + + @Override + public void onFailure(HDLException e) { + HDLExceptionSubmitUtils.submit(requestUrl, json, e); + if (callBack != null) { + callBack.onFailure(e); + } + } + }); + } + + /** + * 鏇存柊鎴块棿锛堟ゼ灞傦級淇℃伅(鍏ㄩ噺) + * @param templateExtendsId + * @param rooms + * @param callBack + * @return + */ + public Disposable UpdateTemplateRoom(String templateExtendsId ,List<TemplateRoomPackBean.TemplateRoomInfoBean> rooms, + IDefaultCallBack callBack){ + String requestUrl = HDLLinkPMSdk.getUserRegionUrl() + HDLCloudUserApi.POST_TEMPLATE_UPDATE_ROOM; + JsonObject json = new JsonObject(); + json.addProperty("templateExtendsId", templateExtendsId); + json.add("roomInfos", HDLGsonUtils.toJsonArray(rooms)); + return HxHttp.builder() + .url(requestUrl) + .raw(json.toString()) + .build() + .post() + .subscribeWith(new HDLResponse<String>() { + @Override + public void onResponse(String code) { + if (callBack != null) { + callBack.onSuccess(); + } + } + + @Override + public void onFailure(HDLException e) { + HDLExceptionSubmitUtils.submit(requestUrl, json, e); + if (callBack != null) { + callBack.onFailure(e); + } + } + }); + } + + /** + * 娣诲姞璁惧(鍏ㄩ噺) + * @param templateExtendsId + * @param beans + * @param callBack + * @return + */ + public Disposable UpdateTemplateDevices(String templateExtendsId,List<TemplateDeviceBean> beans, + IDefaultCallBack callBack) { + String requestUrl = HDLLinkPMSdk.getUserRegionUrl() + HDLCloudUserApi.POST_TEMPLATE_UPDATE_DEVICES; + JsonObject json = new JsonObject(); + json.addProperty("templateExtendsId", templateExtendsId); + json.add("beans", HDLGsonUtils.toJsonArray(beans)); + return HxHttp.builder() + .url(requestUrl) + .raw(json.toString()) + .build() + .post() + .subscribeWith(new HDLResponse<String>() { + @Override + public void onResponse(String code) { + if (callBack != null) { + callBack.onSuccess(); + } + } + + @Override + public void onFailure(HDLException e) { + HDLExceptionSubmitUtils.submit(requestUrl, json, e); + if (callBack != null) { + callBack.onFailure(e); + } + } + }); + } + + /** + * 娣诲姞鍔熻兘(鍏ㄩ噺) + * @param templateExtendsId + * @param functionInfoList + * @param callBack + * @return + */ + public Disposable UpdateTemplateFunctions(String templateExtendsId, List<TemplateFunctionBean> functionInfoList, + IDefaultCallBack callBack) { + String requestUrl = HDLLinkPMSdk.getUserRegionUrl() + HDLCloudUserApi.POST_TEMPLATE_UPDATE_FUNCTIONS; + JsonObject json = new JsonObject(); + json.addProperty("templateExtendsId", templateExtendsId); + json.add("deviceInfos", HDLGsonUtils.toJsonArray(functionInfoList)); + return HxHttp.builder() + .url(requestUrl) + .raw(json.toString()) + .build() + .post() + .subscribeWith(new HDLResponse<String>() { + @Override + public void onResponse(String code) { + if (callBack != null) { + callBack.onSuccess(); + } + } + + @Override + public void onFailure(HDLException e) { + HDLExceptionSubmitUtils.submit(requestUrl, json, e); + if (callBack != null) { + callBack.onFailure(e); + } + } + }); + } + + /** + * 鏇存柊妯℃澘鍦烘櫙(鍏ㄩ噺) + * @param templateExtendsId + * @param sceneBeans + * @param callBack + * @return + */ + public Disposable UpdataTemplateScenes(String templateExtendsId, List<TemplateSceneBean> sceneBeans, + IDefaultCallBack callBack){ + String requestUrl = HDLLinkPMSdk.getUserRegionUrl() + HDLCloudUserApi.POST_TEMPLATE_UPDATE_SCENES; + JsonObject json = new JsonObject(); + json.addProperty("templateExtendsId", templateExtendsId); + json.add("sceneInfos", HDLGsonUtils.toJsonArray(sceneBeans)); + return HxHttp.builder() + .url(requestUrl) + .raw(json.toString()) + .build() + .post() + .subscribeWith(new HDLResponse<String>() { + @Override + public void onResponse(String code) { + if (callBack != null) { + callBack.onSuccess(); + } + } + + @Override + public void onFailure(HDLException e) { + HDLExceptionSubmitUtils.submit(requestUrl, json, e); + if (callBack != null) { + callBack.onFailure(e); + } + } + }); + } + + /** + * 鏇存柊妯℃澘鑷姩鍖� (鍏ㄩ噺) + * @param templateExtendsId + * @param logicBeansJson + * @param callBack + * @return + */ + public Disposable UpdataTemplateLogic(String templateExtendsId, JsonElement logicBeansJson,// List<TemplateLogicBean> logicBeans, + IDefaultCallBack callBack){ + String requestUrl = HDLLinkPMSdk.getUserRegionUrl() + HDLCloudUserApi.POST_TEMPLATE_UPDATE_LOGIC; + JsonObject json = new JsonObject(); + json.addProperty("templateExtendsId", templateExtendsId); + json.add("logicInfos", logicBeansJson); +// json.add("logicInfos", HDLGsonUtils.toJsonArray(logicBeans)); + return HxHttp.builder() + .url(requestUrl) + .raw(json.toString()) + .build() + .post() + .subscribeWith(new HDLResponse<String>() { + @Override + public void onResponse(String code) { + if (callBack != null) { + callBack.onSuccess(); + } + } + + @Override + public void onFailure(HDLException e) { + HDLExceptionSubmitUtils.submit(requestUrl, json, e); + if (callBack != null) { + callBack.onFailure(e); + } + } + }); + } + + /** + * 鏇存柊妯℃澘瀹夐槻鍒楄〃 鍏ㄩ噺 + * @param templateExtendsId + * @param securityBeansJson + * @param callBack + * @return + */ + public Disposable UpdataTemplateSecurity(String templateExtendsId, JsonElement securityBeansJson,// List<TemplateLogicBean> logicBeans, + IDefaultCallBack callBack){ + String requestUrl = HDLLinkPMSdk.getUserRegionUrl() + HDLCloudUserApi.POST_TEMPLATE_UPDATE_SECURITY; + JsonObject json = new JsonObject(); + json.addProperty("templateExtendsId", templateExtendsId); + json.add("securityInfos", securityBeansJson); +// json.add("logicInfos", HDLGsonUtils.toJsonArray(logicBeans)); + return HxHttp.builder() + .url(requestUrl) + .raw(json.toString()) + .build() + .post() + .subscribeWith(new HDLResponse<String>() { + @Override + public void onResponse(String code) { + if (callBack != null) { + callBack.onSuccess(); + } + } + + @Override + public void onFailure(HDLException e) { + HDLExceptionSubmitUtils.submit(requestUrl, json, e); + if (callBack != null) { + callBack.onFailure(e); + } + } + }); + } + + + /** + * 鑾峰彇妯℃澘鍖哄煙淇℃伅鍒楄〃 + * @param templateExtendsId + * @param callBack + * @return + */ + public Disposable GetTemplateAreaSpatialInfo(String templateExtendsId, IGetTemplateSpatialInfoCallBack callBack){ + String requestUrl = HDLLinkPMSdk.getUserRegionUrl() + HDLCloudUserApi.POST_GET_TEMPLATE_SPATIAL_INFO; + JsonObject json = new JsonObject(); + json.addProperty("templateExtendsId", templateExtendsId); + return HxHttp.builder() + .url(requestUrl) + .raw(json.toString()) + .build() + .post() + .subscribeWith(new HDLResponse<List<CloudTemplateSpatialInfo>>() { + @Override + public void onResponse(List<CloudTemplateSpatialInfo> data) { + if (callBack != null) { + callBack.onSuccess(data); + } + } + + @Override + public void onFailure(HDLException e) { + HDLExceptionSubmitUtils.submit(requestUrl, json, e); + if (callBack != null) { + callBack.onFailure(e); + } + } + }); + } + + /** + * 鑾峰彇缃戝叧鍒楄〃 + * @param templateExtendsId + * @param callBack + * @return + */ + public Disposable GetTemplateGatewayList(String templateExtendsId, IGetTemplateGatewayListCallBack callBack){ + String requestUrl = HDLLinkPMSdk.getUserRegionUrl() + HDLCloudUserApi.POST_GET_TEMPLATE_GATEWAY_LIST; + JsonObject json = new JsonObject(); + json.addProperty("templateExtendsId", templateExtendsId); + return HxHttp.builder() + .url(requestUrl) + .raw(json.toString()) + .build() + .post() + .subscribeWith(new HDLResponse<List<TemplateGatewayBean>>() { + @Override + public void onResponse(List<TemplateGatewayBean> data) { + if (callBack != null) { + callBack.onSuccess(data); + } + } + + @Override + public void onFailure(HDLException e) { + HDLExceptionSubmitUtils.submit(requestUrl, json, e); + if (callBack != null) { + callBack.onFailure(e); + } + } + }); + } + + /** + * 鑾峰彇璁惧淇℃伅 + * @param templateExtendsId + * @param callBack + * @return + */ + public Disposable GetTemplateDeviceList(String templateExtendsId, IGetTemplateDeviceListCallBack callBack){ + String requestUrl = HDLLinkPMSdk.getUserRegionUrl() + HDLCloudUserApi.POST_TEMPALTE_GET_DEVICES; + JsonObject json = new JsonObject(); + json.addProperty("templateExtendsId", templateExtendsId); + return HxHttp.builder() + .url(requestUrl) + .raw(json.toString()) + .build() + .post() + .subscribeWith(new HDLResponse<List<CloudTemplateDevice>>() { + @Override + public void onResponse(List<CloudTemplateDevice> data) { + if (callBack != null) { + callBack.onSuccess(data); + } + } + + @Override + public void onFailure(HDLException e) { + HDLExceptionSubmitUtils.submit(requestUrl, json, e); + if (callBack != null) { + callBack.onFailure(e); + } + } + }); + } + + /** + * 鑾峰彇鍔熻兘鍒楄〃 + * @param templateExtendsId + * @param callBack + * @return + */ + public Disposable GetTemplateFunctions(String templateExtendsId , ITemplateFunctionsCallBack callBack) { + String requestUrl = HDLLinkPMSdk.getUserRegionUrl() + HDLCloudUserApi.POST_GET_TEMPLATE_FUNCTION_LIST; + JsonObject json = new JsonObject(); + json.addProperty("templateExtendsId", templateExtendsId); + return HxHttp.builder() + .url(requestUrl) + .raw(json.toString()) + .build() + .post() + .subscribeWith(new HDLResponse<List<TemplateFunctionBean>>() { + @Override + public void onResponse(List<TemplateFunctionBean> data) { + if (callBack != null) { + callBack.onSuccess(data); + } + } + + @Override + public void onFailure(HDLException e) { + HDLExceptionSubmitUtils.submit(requestUrl, json, e); + if (callBack != null) { + callBack.onFailure(e); + } + } + }); + } + + /** + * 鑾峰彇鍦烘櫙鍒楄〃 + * @param templateExtendsId + * @param callBack + * @return + */ + public Disposable GetTemplateScenes(String templateExtendsId , ITemplateScenesCallBack callBack) { + String requestUrl = HDLLinkPMSdk.getUserRegionUrl() + HDLCloudUserApi.POST_GET_TEMPLATE_SCENE_LIST; + JsonObject json = new JsonObject(); + json.addProperty("templateExtendsId", templateExtendsId); + return HxHttp.builder() + .url(requestUrl) + .raw(json.toString()) + .build() + .post() + .subscribeWith(new HDLResponse<List<TemplateSceneBean>>() { + @Override + public void onResponse(List<TemplateSceneBean> data) { + if (callBack != null) { + callBack.onSuccess(data); + } + } + + @Override + public void onFailure(HDLException e) { + HDLExceptionSubmitUtils.submit(requestUrl, json, e); + if (callBack != null) { + callBack.onFailure(e); + } + } + }); + } + + /** + * 鑾峰彇瀹夐槻鍒楄〃 + * @param templateExtendsId + * @param callBack + * @return + */ + public Disposable GetTemplateSecurity(String templateExtendsId , ITemplateSecurityCallBack callBack) { + String requestUrl = HDLLinkPMSdk.getUserRegionUrl() + HDLCloudUserApi.POST_GET_TEMPLATE_SECURITY_LIST; + JsonObject json = new JsonObject(); + json.addProperty("templateExtendsId", templateExtendsId); + return HxHttp.builder() + .url(requestUrl) + .raw(json.toString()) + .build() + .post() + .subscribeWith(new HDLResponse<List<TemplateSecurityBean>>() { + @Override + public void onResponse(List<TemplateSecurityBean> data) { + if (callBack != null) { + callBack.onSuccess(data); + } + } + + @Override + public void onFailure(HDLException e) { + HDLExceptionSubmitUtils.submit(requestUrl, json, e); + if (callBack != null) { + callBack.onFailure(e); + } + } + }); + } + + + /** + * 鑾峰彇閫昏緫鍒楄〃 + * @param templateExtendsId + * @param callBack + * @return + */ + public Disposable GetTemplateLogic(String templateExtendsId , ITemplateLogicCallBack callBack) { + String requestUrl = HDLLinkPMSdk.getUserRegionUrl() + HDLCloudUserApi.POST_GET_TEMPLATE_LOGIC_LIST; + JsonObject json = new JsonObject(); + json.addProperty("templateExtendsId", templateExtendsId); + return HxHttp.builder() + .url(requestUrl) + .raw(json.toString()) + .build() + .post() + .subscribeWith(new HDLResponse<List<TemplateLogicBean>>() { + @Override + public void onResponse(List<TemplateLogicBean> data) { + if (callBack != null) { + callBack.onSuccess(data); + } + } + + @Override + public void onFailure(HDLException e) { + HDLExceptionSubmitUtils.submit(requestUrl, json, e); + if (callBack != null) { + callBack.onFailure(e); + } + } + }); + } + + +} -- Gitblit v1.8.0