index.js 7.24 KB
class ConfigurationNodeApi {

    /**
     * @description 获取用户权限
     */
    static getUserPermissions() {
        return defHttp.get('/yt/role/me/permissions')
    }

    /**
     * @description 获取组态信息
     * @param {'CONFIGURE' | 'CONTENT' | 'NODE'} levelType - 组态资源类型
     * @param {string} levelId - 组态资源ID
     */
    static getConfigurationInfo( levelType, levelId) {
        var configurationId = urlParams['configurationId']
        return defHttp.get(`/yt/configuration/node/${configurationId}/${levelType}/${levelId}`)
    }

    /**
     * @description 获取组织节点树
     * @returns
     */
    static getOrgTree() {
        return defHttp.get('/yt/organization/me/list')
    }

    /**
     * @description 通过设备ID 获取 设备属性
     * @param tbDeviceId
     * @returns {Promise<*>}
     */
    static getDeviceAttr(tbDeviceId) {
        return defHttp.get(`/plugins/telemetry/DEVICE/${tbDeviceId}/keys/timeseries`)
    }

    /**
     * @description 获取组织下的设备
     * @param {'DIRECT_CONNECTION' | 'GATEWAY' | 'SENDOR'} deviceType - 'DIRECT_CONNECTION' 直连设备 'GATEWAY' 网关设备 'SENDOR' 传感器
     * @param {string} orgId - 组织ID
     * @returns {Promise<*>}
     */
    static getDeviceUnderTheOrg(deviceType, orgId) {
        return defHttp.get(`/yt/device/list?deviceType=${deviceType}&organizationId=${orgId}`)
    }

    /**
     * @description 获取所有的网关设备和直连设备
     * @param {string} orgId 
     * @returns 
     */
    static getAllGatewayDeviceAndConnectionDevice(orgId) {
        return defHttp.get(`/yt/device/list/master/${orgId}`)
    }

    /**
     * @description 查询设备的子设备
     * @param deviceId 设备ID
     * @returns {Promise<*>}
     */
    static getDeviceChildDevice(deviceId) {
        return defHttp.get(`/yt/device/relation?page=1&pageSize=10&fromId=${deviceId}`)
    }

    /**
     * @description 查询所有主设备列表
     * @param orgId
     * @returns {Promise<*>}
     */
    static getMasterDevice(orgId) {
        return defHttp.get(`/yt/device/list/master/${orgId}`)
    }

    /**
     * @description 查询所有从设备
     * @param orgId
     * @param masterDeviceId
     * @returns {Promise<*>}
     */
    static getSlaveDevice(orgId, masterDeviceId) {
        return defHttp.get(`/yt/device/list/slave/${orgId}?masterId=${masterDeviceId}`)
    }

    /**
     * @description 编辑数据交互
     */
    static updateNodeEvent(data) {
        return defHttp.post('/yt/configuration/node/event', data)
    }

    /**
     * @description 编辑动画效果
     * @param {*} data
     * @returns
     */
    static updateNodeAct(data) {
        return defHttp.post('/yt/configuration/node/act', data)
    }

    /**
     * @description 更新节点绑定信息
     * @param {*} data
     * @returns
     */
    static updateNodeInfo(data) {
        return defHttp.post('/yt/configuration/node', data)
    }

    /**
     * @description 下发指令 单向
     * @param {string} deviceId - tbDeviceId
     * @param {object} data - 数据
     */
    static sendInstructionOneWay(deviceId, data) {
        return defHttp.post(`/rpc/oneway/${deviceId}`, data)
    }

    /**
     * @description 下发指令 单向
     * @param {string} deviceId - tbDeviceId
     * @param {object} data - 数据
     */
    static sendInstructionTwoWay(deviceId, data) {
        return defHttp.post(`/rpc/twoway/${deviceId}`, data)
    }

    /**
     * @description 下发指令
     * @param {'oneway' | 'twoway'} way
     * @param deviceId
     * @param data
     * @return {*}
     */
    static sendInstruction(way, deviceId, data) {
        return defHttp.post(`/rpc/${way}/${deviceId}`, data)
    }

    /**
     * @description 判断设备是否在线
     * @param deviceId
     * @return {*}
     */
    static deviceIsOnLine(deviceId) {
        return defHttp.get(`/plugins/telemetry/DEVICE/${deviceId}/values/attributes?keys=active`)
    }

    /**
     * @description 上传图片
     * @param data
     * @returns {*}
     */
    static uploadImg(data) {
        return defHttp.post('/yt/oss/upload', data)
    }

    /**
     * @description 获取流媒体
     * @param {number} page 
     * @param {number} pageSize 
     * @returns 
     */
    static getStreamingMediaList(organizationId, page = 1, pageSize = 100) {
        return defHttp.get(`/yt/video`, { params: { organizationId, page, pageSize } })
    }


    /**
     * @description 获取流媒体播放地址
     * @param {string} id 
     * @returns 
     */
    static getStreamingVideoPlayUrl(id) {
        return defHttp.get(`/yt/video/url/${id}`)
    }

    /**
     * @description 获取设备物模型属性
     * @param {*} deviceProfileId 
     * @param {*} dataType 
     * @returns 
     */
    static getDeviceAttribute(deviceProfileId, dataType) {
        return defHttp.get(`/yt/device/attributes/${deviceProfileId}`, { params: { dataType } })
    }

    /**
     * @description 获取产品
     * @param {string} deviceType 
     * @returns 
     */
    static getProduct(deviceType) {
        return defHttp.get('/yt/device_profile/me/list', { params: { deviceType } })
    }

    /**
     * @description 获取满足条件的设备
     * @param {{deviceLabel: string, deviceProfileId: string, deviceType: string, organizationId: string }} params 
     * @returns 
     */
    static getMeetConditionsDevice(params = {}) {
        const { deviceLabel, deviceProfileId, deviceType, organizationId } = params
        return defHttp.get('/yt/device/list', { params: { deviceLabel, deviceProfileId, deviceType, organizationId } })
    }

    /**
     * @description 获取字典值
     * @param {string} dictCode 
     * @returns 
     */
    static getDictionaryValue(dictCode) {
        return defHttp.post('/yt/dict_item/find', { dictCode })
    }

    /**
     * @description 获取设备配置详情通过id
     * @param {string} id 
     * @returns 
     */
    static getDeviceProfileDetailById(id) {
        return defHttp.get('/yt/device_profile/' + id)
    }

    /**
     * @description 获取产品服务通过设备配置id
     * @param {string} id 
     * @returns 
     */
    static getThingsModelServiceByDeviceProfileId(id) {
        return defHttp.get('/yt/things_model/get_services/' + id)
    }

    static getFlvPlay(url, browserId) {
        return `/api/yt/rtsp/openFlv?url=${encodeURIComponent(url)}&browserId=${browserId}`
    }

    static closeFlvPlay(url, browserId) {
        return defHttp.get(`/yt/rtsp/closeFlv?url=${encodeURIComponent(url)}&browserId=${browserId}`)
    }

    /**
     * 
     * @typedef {object} AlarmListRequestParamsType
     * @property { number } page
     * @property { number } pageSize
     * @property { string } status
     * @property { string } alarmType
     * @property { string } severity
     * @property { string[] } deviceIds
     * @property { string } organizationId
     * @property { string } deviceName
     * @property { string } startTime
     * @property { string } endTime
     * @param {AlarmListRequestParamsType} params 
     * @returns 
     */
    static getAlarmList(params) {
        return defHttp.post('/yt/alarm/configuration/page', params)
    }

    static getModbusCommand(params) {
        return defHttp.post('/yt/js/modbus', params)
    }

}