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() { @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() { @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() { @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 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() { @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 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() { @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 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() { @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 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() { @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 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() { @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 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() { @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 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() { @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>() { @Override public void onResponse(List 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>() { @Override public void onResponse(List 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>() { @Override public void onResponse(List 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>() { @Override public void onResponse(List 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>() { @Override public void onResponse(List 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>() { @Override public void onResponse(List 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>() { @Override public void onResponse(List data) { if (callBack != null) { callBack.onSuccess(data); } } @Override public void onFailure(HDLException e) { HDLExceptionSubmitUtils.submit(requestUrl, json, e); if (callBack != null) { callBack.onFailure(e); } } }); } }