mac
2024-10-24 73a49ddd0516e5c9a4b697c593d62c74e420403b
HDLLinkPMSdk/src/main/java/com/hdl/linkpm/sdk/template/controller/HDLTemplateController.java
New file
@@ -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);
                        }
                    }
                });
    }
}