Commit d69a95be0c9cb1710a145a2d15651cf48e99ffe2

Authored by ww
1 parent cc2941d6

perf: socket send message optimize

@@ -33,7 +33,6 @@ const GLOBAL_PLATFORM_INFO = (() => { @@ -33,7 +33,6 @@ const GLOBAL_PLATFORM_INFO = (() => {
33 * @type {{JWT_TOKEN: {value: string}}} 33 * @type {{JWT_TOKEN: {value: string}}}
34 */ 34 */
35 const common = ls.get(GLOBAL_PLATFORM_INFO_KEY) 35 const common = ls.get(GLOBAL_PLATFORM_INFO_KEY)
36 - console.log(common)  
37 return common 36 return common
38 })() 37 })()
39 38
@@ -174,10 +174,15 @@ @@ -174,10 +174,15 @@
174 if (!chartDom) return 174 if (!chartDom) return
175 chartDom.style.width = `${width}px` 175 chartDom.style.width = `${width}px`
176 chartDom.style.height = `${height}px` 176 chartDom.style.height = `${height}px`
177 - const myChart = echarts.init(chartDom);  
178 - const option = chartOptionMapping[chartType] ? chartOptionMapping[chartType]() : {}  
179 - option && myChart.setOption(option);  
180 - chartsInstanceMapping.set(id, myChart) 177 + try {
  178 + const myChart = echarts.init(chartDom);
  179 + const option = chartOptionMapping[chartType] ? chartOptionMapping[chartType]() : {}
  180 + option && myChart.setOption(option);
  181 + chartsInstanceMapping.set(id, myChart)
  182 + } catch (error) {
  183 +
  184 + }
  185 +
181 } 186 }
182 187
183 /** 188 /**
@@ -13033,18 +13033,56 @@ function previewAction(editorUi, currentPage) { @@ -13033,18 +13033,56 @@ function previewAction(editorUi, currentPage) {
13033 class DispatchCenter { 13033 class DispatchCenter {
13034 13034
13035 /** 13035 /**
13036 - * @description 节点映射  
13037 - * @type {Map<string, Map<string, object>>}  
13038 - */  
13039 - nodeMapping  
13040 -  
13041 - /**  
13042 * @description cmd ID 与 node 映射关系 13036 * @description cmd ID 与 node 映射关系
13043 * @type {Map<number, string>} 13037 * @type {Map<number, string>}
13044 */ 13038 */
13045 cmdIdMapping = new Map() 13039 cmdIdMapping = new Map()
13046 13040
13047 /** 13041 /**
  13042 + * @type { Map<string, {
  13043 + * deviceId: string,
  13044 + * dataOrigin: 'dataSources' | 'act',
  13045 + * slaveDeviceId: string,
  13046 + * nodeId: string,
  13047 + * attr: string
  13048 + * condition?: { max?: number, min?: number },
  13049 + * additional?: {
  13050 + * agg?: string,
  13051 + * attrName?: string,
  13052 + * dataType?: 'tsSubCmds' | 'historyCmds',
  13053 + * deviceName?: string,
  13054 + * effectScope?: string,
  13055 + * interval?: string,
  13056 + * orgName?: string,
  13057 + * slaveDeviceName?: string
  13058 + * }
  13059 + * }[]>}
  13060 + */
  13061 + deviceIdMapping = new Map()
  13062 +
  13063 + /**
  13064 + * @type {Map<number, {
  13065 + * deviceId: string,
  13066 + * slaveDeviceId: string,
  13067 + * nodeId: string,
  13068 + * attr: string
  13069 + * dataOrigin: 'dataSources' | 'act',
  13070 + * condition?: { max?: number, min?: number },
  13071 + * additional?: {
  13072 + * agg?: string,
  13073 + * attrName?: string,
  13074 + * dataType?: 'tsSubCmds' | 'historyCmds',
  13075 + * deviceName?: string,
  13076 + * effectScope?: string,
  13077 + * interval?: string,
  13078 + * orgName?: string,
  13079 + * slaveDeviceName?: string
  13080 + * }
  13081 + * }[]>}
  13082 + */
  13083 + subscribeIdMapping = new Map()
  13084 +
  13085 + /**
13048 * @description 13086 * @description
13049 */ 13087 */
13050 editorUi 13088 editorUi
@@ -13150,7 +13188,6 @@ class DispatchCenter { @@ -13150,7 +13188,6 @@ class DispatchCenter {
13150 13188
13151 13189
13152 constructor(editorUi, currentPage) { 13190 constructor(editorUi, currentPage) {
13153 - this.nodeMapping = new Map()  
13154 this.editorUi = editorUi 13191 this.editorUi = editorUi
13155 this.init(editorUi, currentPage) 13192 this.init(editorUi, currentPage)
13156 } 13193 }
@@ -13169,6 +13206,7 @@ class DispatchCenter { @@ -13169,6 +13206,7 @@ class DispatchCenter {
13169 this.dataInteractionInstance = new HandleDataInteraction(this) 13206 this.dataInteractionInstance = new HandleDataInteraction(this)
13170 this.dynamicEffectInstance = new HandleDynamicEffect(this) 13207 this.dynamicEffectInstance = new HandleDynamicEffect(this)
13171 this.updateQueueInstance = new UpdateQueue(this) 13208 this.updateQueueInstance = new UpdateQueue(this)
  13209 + this.sendSubscribeMessage()
13172 } 13210 }
13173 13211
13174 /** 13212 /**
@@ -13176,7 +13214,7 @@ class DispatchCenter { @@ -13176,7 +13214,7 @@ class DispatchCenter {
13176 */ 13214 */
13177 connectSocket() { 13215 connectSocket() {
13178 Ws.instance?.destroy?.() 13216 Ws.instance?.destroy?.()
13179 - this.socket = Ws.getInstance({ url: GLOBAL_WS_URL(), onmessageCallback: this.socketOnmessage }) 13217 + this.socket = Ws.getInstance({ url: GLOBAL_WS_URL(), onmessageCallback: this.socketOnMessage.bind(this) })
13180 } 13218 }
13181 13219
13182 /** 13220 /**
@@ -13185,9 +13223,29 @@ class DispatchCenter { @@ -13185,9 +13223,29 @@ class DispatchCenter {
13185 * @param event 13223 * @param event
13186 * @param ws 13224 * @param ws
13187 */ 13225 */
13188 - socketOnmessage(message, event, ws) {  
13189 - const { subscriptionId, data } = message  
13190 - DispatchCenter.instance.publishEvent(subscriptionId, data, message, event, ws) 13226 + socketOnMessage(message, event, ws) {
  13227 + const { subscriptionId, errorMsg } = message
  13228 + if (errorMsg) return
  13229 + const subList = this.subscribeIdMapping.get(subscriptionId)
  13230 + subList.forEach(item => {
  13231 + const { dataOrigin, additional } = item
  13232 + if (dataOrigin === 'dataSources') {
  13233 + if (additional)
  13234 + this.dataSourceHandlerInstance.updateRealTimeDataSource(message, item)
  13235 + else
  13236 + this.dataSourceHandlerInstance.updateCommonDataSource(message, item)
  13237 + }
  13238 + if (dataOrigin === 'act') {
  13239 + const { type } = item
  13240 + // this.dynamicEffectInstance.videoPlay()
  13241 + const handleFunction = this.dynamicEffectInstance.dispatch.call(this.dynamicEffectInstance, type)
  13242 + handleFunction(message, item)
  13243 + }
  13244 + })
  13245 + // this.subscribeEvent(cmdId, this.updateCommonDataSource.bind(this))
  13246 + return
  13247 + // const { subscriptionId, data } = message
  13248 + // DispatchCenter.instance.publishEvent(subscriptionId, data, message, event, ws)
13191 } 13249 }
13192 13250
13193 /** 13251 /**
@@ -13220,6 +13278,175 @@ class DispatchCenter { @@ -13220,6 +13278,175 @@ class DispatchCenter {
13220 this.contentData = res 13278 this.contentData = res
13221 } 13279 }
13222 13280
  13281 + sendSubscribeMessage() {
  13282 + const message = this.generateSubscribeMessage()
  13283 + this.socket.send(JSON.stringify(message))
  13284 + }
  13285 +
  13286 + /**
  13287 + * @description 创建订阅消息
  13288 + */
  13289 + generateSubscribeMessage() {
  13290 +
  13291 + /**
  13292 + * @type {{dataSources: [], act: [], event: [], enabled: boolean}}
  13293 + */
  13294 + const data = JSON.parse(JSON.stringify(this.contentData))
  13295 + delete data.enabled
  13296 +
  13297 + /**
  13298 + *
  13299 + * @param {'dataSources' | 'act'} key
  13300 + * @param {{
  13301 + * id: string,
  13302 + * enabled: boolean,
  13303 + * deviceId: string,
  13304 + * slaveDeviceId: string,
  13305 + * nodeId: string,
  13306 + * attr: string
  13307 + * condition?: { max?: number, min?: number },
  13308 + * additional?: {
  13309 + * agg?: string,
  13310 + * attrName?: string,
  13311 + * dataType?: 'tsSubCmds' | 'historyCmds',
  13312 + * deviceName?: string,
  13313 + * effectScope?: string,
  13314 + * interval?: string,
  13315 + * orgName?: string,
  13316 + * slaveDeviceName?: string
  13317 + * }
  13318 + * }} record
  13319 + */
  13320 + const setDeviceMapping = (record) => {
  13321 + const { deviceId, slaveDeviceId } = record
  13322 + if (this.deviceIdMapping.has(slaveDeviceId || deviceId)) {
  13323 + const group = this.deviceIdMapping.get(slaveDeviceId || deviceId)
  13324 + group.push(record)
  13325 + } else {
  13326 + this.deviceIdMapping.set(slaveDeviceId || deviceId, [record])
  13327 + }
  13328 + }
  13329 +
  13330 + Object.keys(data).forEach(key => {
  13331 + /**
  13332 + * @type {{
  13333 + * id: string,
  13334 + * nodeId: string,
  13335 + * deviceId: string,
  13336 + * slaveDeviceId: string,
  13337 + * attr: string,
  13338 + * enabled: boolean,
  13339 + * additional: object,
  13340 + * condition: object
  13341 + * }[]}
  13342 + */
  13343 + const list = data[key]
  13344 + if (key === 'dataSources') {
  13345 + for (const item of list) {
  13346 + setDeviceMapping({ dataOrigin: key, ...item })
  13347 + }
  13348 + }
  13349 + if (key === 'act') {
  13350 + for (const item of list) {
  13351 + const { enabled } = item
  13352 + if (!enabled) continue
  13353 + setDeviceMapping({ dataOrigin: key, ...item })
  13354 + }
  13355 + }
  13356 + })
  13357 +
  13358 + /**
  13359 + * @param {{
  13360 + * entityId: string,
  13361 + * cmdId: number,
  13362 + * keys: string,
  13363 + * agg?: string,
  13364 + * interval?: number,
  13365 + * startTs?: number,
  13366 + * endTs?: number
  13367 + * }} params
  13368 + * @returns {{ entityType: string, entityId: string, scope: string, cmdId: number, keys: string }}
  13369 + */
  13370 + const generateMessage = (params) => {
  13371 + const getDynamicAttr = (attr) => params[attr] ? { [attr]: params[attr] } : {}
  13372 + return {
  13373 + entityType: 'DEVICE',
  13374 + entityId: params.entityId,
  13375 + cmdId: params.cmdId,
  13376 + keys: params.keys,
  13377 +
  13378 + ... (params.interval ? {} : { scope: 'LATEST_TELEMETRY' }),
  13379 + ...getDynamicAttr('agg'),
  13380 + ...getDynamicAttr('interval'),
  13381 + ...getDynamicAttr('startTs'),
  13382 + ...getDynamicAttr('endTs'),
  13383 + }
  13384 + }
  13385 +
  13386 + const generateGroupMessage = () => {
  13387 + /**
  13388 + * @type {{
  13389 + * historyCmds: {
  13390 + * entityType: 'DEVICE',
  13391 + * entityId: string,
  13392 + * scope?: 'LATEST_TELEMETRY',
  13393 + * cmdId: number,
  13394 + * keys: string,
  13395 + * startTs?: number
  13396 + * endTs?: number
  13397 + * }[],
  13398 + * tsSubCmds: {
  13399 + * entityType: 'DEVICE',
  13400 + * entityId: string,
  13401 + * scope?: 'LATEST_TELEMETRY',
  13402 + * cmdId: number,
  13403 + * keys: string,
  13404 + * startTs?: number
  13405 + * endTs?: number
  13406 + * }[]}}
  13407 + */
  13408 + const messageList = { tsSubCmds: [], historyCmds: [] }
  13409 + let cmdId = 0
  13410 +
  13411 + const getKeys = (list) => Array.from(new Set(list)).join(',')
  13412 +
  13413 + const toNumber = (string, defaultValue = 0) => isNaN(string) ? defaultValue : Number(string)
  13414 +
  13415 + const setSubscribeMapping = (cmdId, record) => this.subscribeIdMapping.set(cmdId, record)
  13416 +
  13417 + this.deviceIdMapping.forEach((value, key) => {
  13418 + const basicRecord = value.filter(item => !item.additional)
  13419 + const moreFilterRecord = value.filter(item => item.additional)
  13420 +
  13421 + const message = generateMessage({ entityId: key, cmdId, keys: getKeys(basicRecord.map(item => item.attr)) })
  13422 + setSubscribeMapping(cmdId, basicRecord)
  13423 + cmdId++
  13424 + moreFilterRecord.forEach(item => {
  13425 + const { additional = {} } = item
  13426 + const { dataType = 'tsSubCmds', interval, effectScope, agg } = additional
  13427 + const message = generateMessage({
  13428 + entityId: key,
  13429 + cmdId,
  13430 + agg,
  13431 + keys: getKeys(moreFilterRecord.map(item => item.attr)),
  13432 + interval: toNumber(interval, 1000),
  13433 + startTs: Date.now() - toNumber(effectScope),
  13434 + ...(dataType === HandleDataSource.enumDataBindType.REAL ? {} : { endTs: Date.now() })
  13435 + })
  13436 + setSubscribeMapping(cmdId, moreFilterRecord)
  13437 + messageList[dataType].push(message)
  13438 + cmdId++
  13439 + })
  13440 +
  13441 + messageList.tsSubCmds.push(message)
  13442 + })
  13443 +
  13444 + return messageList
  13445 + }
  13446 +
  13447 + return generateGroupMessage()
  13448 + }
  13449 +
13223 /** 13450 /**
13224 * @description 发送消息去获取实时数据 13451 * @description 发送消息去获取实时数据
13225 */ 13452 */
@@ -13242,7 +13469,7 @@ class DispatchCenter { @@ -13242,7 +13469,7 @@ class DispatchCenter {
13242 /** 13469 /**
13243 * @description 生成节点映射表 13470 * @description 生成节点映射表
13244 * @param dataSources 13471 * @param dataSources
13245 - * @return {{cmdId: number, entityType: string, keys: *, scope: string, entityId: *}[]} 13472 + * @return {{cmdId: number, entityType: string, keys: string, scope: string, entityId: string}[]}
13246 */ 13473 */
13247 generatorDataSourceMapping(dataSources = []) { 13474 generatorDataSourceMapping(dataSources = []) {
13248 return dataSources.map((datum) => { 13475 return dataSources.map((datum) => {
@@ -13264,12 +13491,7 @@ class DispatchCenter { @@ -13264,12 +13491,7 @@ class DispatchCenter {
13264 * @description 分发事件 13491 * @description 分发事件
13265 */ 13492 */
13266 publishEvent(eventName, data, message, event, ws) { 13493 publishEvent(eventName, data, message, event, ws) {
13267 - // data = data ? data : {}  
13268 this.eventBus.emit(eventName, message, event, ws) 13494 this.eventBus.emit(eventName, message, event, ws)
13269 - // console.log(arguments)  
13270 - // Object.keys(data).forEach(() => {  
13271 - // this.eventBus.emit(eventName, message, event, ws)  
13272 - // })  
13273 } 13495 }
13274 13496
13275 /** 13497 /**
@@ -13414,8 +13636,8 @@ class HandleDataSource { @@ -13414,8 +13636,8 @@ class HandleDataSource {
13414 13636
13415 constructor(DispatchInstance) { 13637 constructor(DispatchInstance) {
13416 this.DispatchInstance = DispatchInstance 13638 this.DispatchInstance = DispatchInstance
13417 - this.generatorCommonDataSourceMapping()  
13418 - this.generatorChartDataSourceMapping() 13639 + // this.generatorCommonDataSourceMapping()
  13640 + // this.generatorChartDataSourceMapping()
13419 } 13641 }
13420 13642
13421 get graph() { 13643 get graph() {
@@ -13536,10 +13758,12 @@ class HandleDataSource { @@ -13536,10 +13758,12 @@ class HandleDataSource {
13536 * @description 更新变量值 13758 * @description 更新变量值
13537 * @param {} message 13759 * @param {} message
13538 */ 13760 */
13539 - updateCommonDataSource(message) {  
13540 - const { subscriptionId } = message  
13541 - const node = this.getNodeByCmdId(subscriptionId)  
13542 - const { attr } = this.getBindData(subscriptionId) 13761 + updateCommonDataSource(message, record) {
  13762 + // const { subscriptionId } = message
  13763 + const { nodeId, attr } = record
  13764 + const node = this.getNodeByCmdId(nodeId)
  13765 +
  13766 + // const { attr } = this.getBindData(nodeId)
13543 node && this.updatePage(() => { 13767 node && this.updatePage(() => {
13544 const { data } = message 13768 const { data } = message
13545 const type = this.getComponentType(node) 13769 const type = this.getComponentType(node)
@@ -13554,7 +13778,7 @@ class HandleDataSource { @@ -13554,7 +13778,7 @@ class HandleDataSource {
13554 } 13778 }
13555 13779
13556 if (type === this.componentType.IMAGE) { 13780 if (type === this.componentType.IMAGE) {
13557 - this.handleImageComponent(message) 13781 + this.handleImageComponent(message, record)
13558 return 13782 return
13559 } 13783 }
13560 13784
@@ -13568,11 +13792,11 @@ class HandleDataSource { @@ -13568,11 +13792,11 @@ class HandleDataSource {
13568 * @description 处理switch 组件 13792 * @description 处理switch 组件
13569 * @param {} message 13793 * @param {} message
13570 */ 13794 */
13571 - handleSwitchComponent(message) {  
13572 - const { subscriptionId, data = {} } = message  
13573 - const node = this.getNodeByCmdId(subscriptionId)  
13574 - const { nodeId, attr } = this.getBindData(subscriptionId)  
13575 - const [[timespan, receiveValue] = []] = data[attr] || [] 13795 + handleSwitchComponent(message, record) {
  13796 + const { data = {} } = message
  13797 + const { nodeId, attr } = record
  13798 + const node = this.getNodeByCmdId(nodeId)
  13799 + const [[_timespan, receiveValue] = []] = data[attr] || []
13576 const switchConfig = this.DispatchInstance.contentData.act.find(item => item.id === nodeId && item.type === 'SWITCH') 13800 const switchConfig = this.DispatchInstance.contentData.act.find(item => item.id === nodeId && item.type === 'SWITCH')
13577 const { condition = [] } = switchConfig || {} 13801 const { condition = [] } = switchConfig || {}
13578 let reg = /image=[^;]+/g 13802 let reg = /image=[^;]+/g
@@ -13611,22 +13835,22 @@ class HandleDataSource { @@ -13611,22 +13835,22 @@ class HandleDataSource {
13611 13835
13612 } 13836 }
13613 13837
13614 - handleParamSettingButton(message) {  
13615 - const { subscriptionId, data = {} } = message 13838 + handleParamSettingButton(message, record) {
  13839 + const { data = {} } = message
13616 if (!data) return 13840 if (!data) return
13617 - const node = this.getNodeByCmdId(subscriptionId)  
13618 - const { attr } = this.getBindData(subscriptionId)  
13619 - const [[timespan, receiveValue] = []] = data[attr] || [] 13841 + const { nodeId, attr } = record
  13842 + const node = this.getNodeByCmdId(nodeId)
  13843 + const [[_timespan, receiveValue] = []] = data[attr] || []
13620 this.updatePage(() => { 13844 this.updatePage(() => {
13621 node.setAttribute('label', `<button class="param-setting-button">${receiveValue}</button>`) 13845 node.setAttribute('label', `<button class="param-setting-button">${receiveValue}</button>`)
13622 }, node) 13846 }, node)
13623 } 13847 }
13624 13848
13625 - handleImageComponent(message) {  
13626 - const { subscriptionId, data = {} } = message  
13627 - const node = this.getNodeByCmdId(subscriptionId)  
13628 - const { attr } = this.getBindData(subscriptionId)  
13629 - const [[timespan, receiveValue] = []] = data[attr] || [] 13849 + handleImageComponent(message, record) {
  13850 + const { data = {} } = message
  13851 + const { nodeId, attr } = record
  13852 + const node = this.getNodeByCmdId(nodeId)
  13853 + const [[_timespan, receiveValue] = []] = data[attr] || []
13630 this.updatePage(() => { 13854 this.updatePage(() => {
13631 node.setAttribute('label', `<img class="basic-component__image" alt="图片" src="${receiveValue}" />`) 13855 node.setAttribute('label', `<img class="basic-component__image" alt="图片" src="${receiveValue}" />`)
13632 }, node) 13856 }, node)
@@ -13635,18 +13859,19 @@ class HandleDataSource { @@ -13635,18 +13859,19 @@ class HandleDataSource {
13635 /** 13859 /**
13636 * @description 更新实时数据 13860 * @description 更新实时数据
13637 * @param {} message 13861 * @param {} message
13638 - * @param {} agg 聚合方式 13862 + * @param {} record 聚合方式
13639 */ 13863 */
13640 - updateRealTimeDataSource(message, agg) {  
13641 - const { data = {}, subscriptionId } = message  
13642 - const node = this.getNodeByCmdId(subscriptionId) 13864 + updateRealTimeDataSource(message, record) {
  13865 + const { data = {} } = message
  13866 + const { nodeId, attr, additional = {} } = record
  13867 + const { agg } = additional
  13868 + const node = this.getNodeByCmdId(nodeId)
13643 if (!node) return 13869 if (!node) return
13644 const enumConst = Sidebar.prototype.enumCellBasicAttribute 13870 const enumConst = Sidebar.prototype.enumCellBasicAttribute
13645 const chartInstanceMap = Sidebar.prototype.chartsInstanceMapping 13871 const chartInstanceMap = Sidebar.prototype.chartsInstanceMapping
13646 const chartInstanceId = node.getAttribute(enumConst.CHART_INSTANCE_ID) 13872 const chartInstanceId = node.getAttribute(enumConst.CHART_INSTANCE_ID)
13647 const chartInstanceType = node.getAttribute(enumConst.COMPONENT_TYPE) 13873 const chartInstanceType = node.getAttribute(enumConst.COMPONENT_TYPE)
13648 const instance = chartInstanceMap.get(chartInstanceId) 13874 const instance = chartInstanceMap.get(chartInstanceId)
13649 - const { attr = [[]], additional } = this.getBindData(subscriptionId)  
13650 const realDataList = data[attr] || [] 13875 const realDataList = data[attr] || []
13651 13876
13652 const action = agg === 'NONE' ? 'unshift' : 'push' 13877 const action = agg === 'NONE' ? 'unshift' : 'push'
@@ -13655,12 +13880,12 @@ class HandleDataSource { @@ -13655,12 +13880,12 @@ class HandleDataSource {
13655 const isActive = instance.isActive 13880 const isActive = instance.isActive
13656 if (!isActive) { 13881 if (!isActive) {
13657 instance.isActive = true 13882 instance.isActive = true
13658 - const chartOption = this.getChartComponentOption(chartInstanceType, { chartType: chartInstanceType, attr, dataList: realDataList, action, nodeId: node.id , additional}) 13883 + const chartOption = this.getChartComponentOption(chartInstanceType, { chartType: chartInstanceType, attr, dataList: realDataList, action, nodeId: node.id, additional })
13659 instance.setOption(chartOption) 13884 instance.setOption(chartOption)
13660 13885
13661 } else { 13886 } else {
13662 const oldOptions = instance.getOption() 13887 const oldOptions = instance.getOption()
13663 - const options = this.getRealTimeUpdateChartOption(chartInstanceType, { oldOptions, dataList: realDataList , additional}) 13888 + const options = this.getRealTimeUpdateChartOption(chartInstanceType, { oldOptions, dataList: realDataList, additional })
13664 if (!instance) clearInterval(interval) 13889 if (!instance) clearInterval(interval)
13665 instance && instance.setOption(options) 13890 instance && instance.setOption(options)
13666 } 13891 }
@@ -13669,16 +13894,17 @@ class HandleDataSource { @@ -13669,16 +13894,17 @@ class HandleDataSource {
13669 /** 13894 /**
13670 * @description 更新历史数据 13895 * @description 更新历史数据
13671 */ 13896 */
13672 - updateHistoryDataSource(message, agg) {  
13673 - const { data = {}, subscriptionId } = message  
13674 - const node = this.getNodeByCmdId(subscriptionId) 13897 + updateHistoryDataSource(message, record) {
  13898 + const { data = {} } = message
  13899 + const { nodeId, attr, additional = {} } = record
  13900 + const { agg } = additional
  13901 + const node = this.getNodeByCmdId(nodeId)
13675 if (!node) return 13902 if (!node) return
13676 const enumConst = Sidebar.prototype.enumCellBasicAttribute 13903 const enumConst = Sidebar.prototype.enumCellBasicAttribute
13677 const chartInstanceMap = Sidebar.prototype.chartsInstanceMapping 13904 const chartInstanceMap = Sidebar.prototype.chartsInstanceMapping
13678 const chartInstanceId = node.getAttribute(enumConst.CHART_INSTANCE_ID) 13905 const chartInstanceId = node.getAttribute(enumConst.CHART_INSTANCE_ID)
13679 const chartInstanceType = node.getAttribute(enumConst.COMPONENT_TYPE) 13906 const chartInstanceType = node.getAttribute(enumConst.COMPONENT_TYPE)
13680 const instance = chartInstanceMap.get(chartInstanceId) 13907 const instance = chartInstanceMap.get(chartInstanceId)
13681 - const { attr = [[]], additional } = this.getBindData(subscriptionId)  
13682 const historyDataList = data[attr] || [] 13908 const historyDataList = data[attr] || []
13683 const showNumberOf = 4 13909 const showNumberOf = 4
13684 const action = agg === 'NONE' ? 'unshift' : 'push' 13910 const action = agg === 'NONE' ? 'unshift' : 'push'
@@ -13965,11 +14191,10 @@ class HandleDataSource { @@ -13965,11 +14191,10 @@ class HandleDataSource {
13965 /** 14191 /**
13966 * @description 获取仪表盘配置 14192 * @description 获取仪表盘配置
13967 */ 14193 */
13968 - getRealTimeUpdateDashboardChartOption(params = { dataList: [] , additional: {}}) { 14194 + getRealTimeUpdateDashboardChartOption(params = { dataList: [], additional: {} }) {
13969 const { dataList = [], oldOptions, additional } = params 14195 const { dataList = [], oldOptions, additional } = params
13970 const { attrName } = additional 14196 const { attrName } = additional
13971 const [timespan, value] = dataList[0] || [] 14197 const [timespan, value] = dataList[0] || []
13972 - console.log(value)  
13973 return { 14198 return {
13974 series: [ 14199 series: [
13975 { 14200 {
@@ -13990,8 +14215,7 @@ class HandleDataSource { @@ -13990,8 +14215,7 @@ class HandleDataSource {
13990 * @param actionType 14215 * @param actionType
13991 * @return {{attr: string, additional: { agg: string, dataType: string, effectScope: string, interval: string, unit: string, orgName: string, deviceName: string, slaveDeviceName: string, attrName: string }}} 14216 * @return {{attr: string, additional: { agg: string, dataType: string, effectScope: string, interval: string, unit: string, orgName: string, deviceName: string, slaveDeviceName: string, attrName: string }}}
13992 */ 14217 */
13993 - getBindData(subscriptionId) {  
13994 - const nodeId = this.getNodeIdByCmdId(subscriptionId) 14218 + getBindData(nodeId) {
13995 const temp = this.dataSourceNodeMapping.get(nodeId) || {} 14219 const temp = this.dataSourceNodeMapping.get(nodeId) || {}
13996 return temp 14220 return temp
13997 } 14221 }
@@ -14011,7 +14235,8 @@ class HandleDataSource { @@ -14011,7 +14235,8 @@ class HandleDataSource {
14011 * @return {string} 14235 * @return {string}
14012 */ 14236 */
14013 getNodeIdByCmdId(subscriptionId) { 14237 getNodeIdByCmdId(subscriptionId) {
14014 - return this.DispatchInstance.cmdIdMapping.get(subscriptionId) 14238 + // return this.DispatchInstance.cmdIdMapping.get(subscriptionId)
  14239 + return this.DispatchInstance.subscribeIdMapping.get(subscriptionId)
14015 } 14240 }
14016 14241
14017 /** 14242 /**
@@ -14019,8 +14244,8 @@ class HandleDataSource { @@ -14019,8 +14244,8 @@ class HandleDataSource {
14019 * @param subscriptionId 14244 * @param subscriptionId
14020 * @return {*} 14245 * @return {*}
14021 */ 14246 */
14022 - getNodeByCmdId(subscriptionId) {  
14023 - const nodeId = this.getNodeIdByCmdId(subscriptionId) 14247 + getNodeByCmdId(nodeId) {
  14248 + // const nodeId = this.getNodeIdByCmdId(subscriptionId)
14024 return this.contentAllCell.find(item => item.id === nodeId) 14249 return this.contentAllCell.find(item => item.id === nodeId)
14025 } 14250 }
14026 14251
@@ -14634,7 +14859,7 @@ class HandleDynamicEffect { @@ -14634,7 +14859,7 @@ class HandleDynamicEffect {
14634 */ 14859 */
14635 generatorMappingRelation() { 14860 generatorMappingRelation() {
14636 this.videoPlay() 14861 this.videoPlay()
14637 - const tsSubCmds = [] 14862 + // const tsSubCmds = []
14638 this.enableActList.forEach(each => { 14863 this.enableActList.forEach(each => {
14639 const { id, type, attr, deviceId, slaveDeviceId } = each 14864 const { id, type, attr, deviceId, slaveDeviceId } = each
14640 14865
@@ -14642,13 +14867,13 @@ class HandleDynamicEffect { @@ -14642,13 +14867,13 @@ class HandleDynamicEffect {
14642 const temp = this.actNodeMapping.get(id) 14867 const temp = this.actNodeMapping.get(id)
14643 temp.value.set(type, each) 14868 temp.value.set(type, each)
14644 14869
14645 - const cmdId = this.DispatchInstance.getCmdId(id) 14870 + // const cmdId = this.DispatchInstance.getCmdId(id)
14646 14871
14647 - tsSubCmds.push(this.generatorMessage(slaveDeviceId ? slaveDeviceId : deviceId, cmdId, attr)) 14872 + // tsSubCmds.push(this.generatorMessage(slaveDeviceId ? slaveDeviceId : deviceId, cmdId, attr))
14648 14873
14649 - this.subscribeEvent(cmdId, this.dispatch(type)) 14874 + // this.subscribeEvent(cmdId, this.dispatch(type))
14650 }) 14875 })
14651 - if (tsSubCmds.length) this.sendMsg({ tsSubCmds }) 14876 + // if (tsSubCmds.length) this.sendMsg({ tsSubCmds })
14652 } 14877 }
14653 14878
14654 /** 14879 /**
@@ -14718,15 +14943,16 @@ class HandleDynamicEffect { @@ -14718,15 +14943,16 @@ class HandleDynamicEffect {
14718 * @param message 14943 * @param message
14719 * @param attr 14944 * @param attr
14720 */ 14945 */
14721 - rotate(message) {  
14722 - const { subscriptionId, data } = message  
14723 - const node = this.getNodeByCmdId(subscriptionId) 14946 + rotate(message, record) {
  14947 + const { data } = message
  14948 + const { id } = record
  14949 + const node = this.getNodeByCmdId(id)
14724 const key = node.id + DispatchCenter.enumDynamicEffectType.ROTATE 14950 const key = node.id + DispatchCenter.enumDynamicEffectType.ROTATE
14725 if (!this.validatePriority(node.id)) { 14951 if (!this.validatePriority(node.id)) {
14726 this.delUpdateFn(key) 14952 this.delUpdateFn(key)
14727 return 14953 return
14728 } 14954 }
14729 - const { flag } = this.validate(subscriptionId, DispatchCenter.enumDynamicEffectType.ROTATE, data) 14955 + const { flag } = this.validate(record, DispatchCenter.enumDynamicEffectType.ROTATE, data)
14730 let deg = 0 14956 let deg = 0
14731 const updateFn = () => { 14957 const updateFn = () => {
14732 if (deg === 360) deg = 0 14958 if (deg === 360) deg = 0
@@ -14750,11 +14976,12 @@ class HandleDynamicEffect { @@ -14750,11 +14976,12 @@ class HandleDynamicEffect {
14750 * @param message 14976 * @param message
14751 * @param attr 14977 * @param attr
14752 */ 14978 */
14753 - display(message) {  
14754 - const { subscriptionId, data = {} } = message  
14755 - const { flag, condition } = this.validate(subscriptionId, HandleDynamicEffect.enumActType.DISPLAY, data) 14979 + display(message, record) {
  14980 + const { data = {} } = message
  14981 + const { id } = record
  14982 + const { flag, condition } = this.validate(record, HandleDynamicEffect.enumActType.DISPLAY, data)
14756 if (!flag) return 14983 if (!flag) return
14757 - const node = this.getNodeByCmdId(subscriptionId) 14984 + const node = this.getNodeByCmdId(id)
14758 let isShow = false 14985 let isShow = false
14759 if (condition.type === HandleDynamicEffect.enumDisplayType.SHOW) { 14986 if (condition.type === HandleDynamicEffect.enumDisplayType.SHOW) {
14760 isShow = true 14987 isShow = true
@@ -14784,15 +15011,16 @@ class HandleDynamicEffect { @@ -14784,15 +15011,16 @@ class HandleDynamicEffect {
14784 * @param message 15011 * @param message
14785 * @param attr 15012 * @param attr
14786 */ 15013 */
14787 - flash(message) {  
14788 - const { subscriptionId, data } = message  
14789 - const node = this.getNodeByCmdId(subscriptionId) 15014 + flash(message, record) {
  15015 + const { data } = message
  15016 + const { id } = record
  15017 + const node = this.getNodeByCmdId(id)
14790 const key = node.id + DispatchCenter.enumDynamicEffectType.FLASH 15018 const key = node.id + DispatchCenter.enumDynamicEffectType.FLASH
14791 - if (!this.validatePriority(node.id)) { 15019 + if (!this.validatePriority(id)) {
14792 this.delUpdateFn(key) 15020 this.delUpdateFn(key)
14793 return 15021 return
14794 } 15022 }
14795 - const { flag, condition } = this.validate(subscriptionId, HandleDynamicEffect.enumActType.FLASH, data) 15023 + const { flag } = this.validate(record, HandleDynamicEffect.enumActType.FLASH, data)
14796 let flashFlag = false 15024 let flashFlag = false
14797 const updateFn = () => { 15025 const updateFn = () => {
14798 node.setVisible(flashFlag) 15026 node.setVisible(flashFlag)
@@ -14810,10 +15038,11 @@ class HandleDynamicEffect { @@ -14810,10 +15038,11 @@ class HandleDynamicEffect {
14810 /** 15038 /**
14811 * @description 处理变量图片 15039 * @description 处理变量图片
14812 */ 15040 */
14813 - varImage(message) {  
14814 - const { subscriptionId, data } = message  
14815 - const node = this.getNodeByCmdId(subscriptionId)  
14816 - const { flag, condition } = this.validate(subscriptionId, HandleDynamicEffect.enumActType.IMAGE, data) 15041 + varImage(message, record) {
  15042 + const { data } = message
  15043 + const { id } = record
  15044 + const node = this.getNodeByCmdId(id)
  15045 + const { flag, condition } = this.validate(record, HandleDynamicEffect.enumActType.IMAGE, data)
14817 if (flag && node) { 15046 if (flag && node) {
14818 const { imagePath } = condition 15047 const { imagePath } = condition
14819 this.insertOnceUpdateFn( 15048 this.insertOnceUpdateFn(
@@ -14822,7 +15051,7 @@ class HandleDynamicEffect { @@ -14822,7 +15051,7 @@ class HandleDynamicEffect {
14822 node.setStyle(`image;image=${imagePath};imageAspect=0;`) 15051 node.setStyle(`image;image=${imagePath};imageAspect=0;`)
14823 }) 15052 })
14824 } else if (!flag && node) { 15053 } else if (!flag && node) {
14825 - const { condition = [], attr } = this.getBindData(subscriptionId, HandleDynamicEffect.enumActType.IMAGE) 15054 + const { condition = [], attr } = record
14826 const flag = HandleDynamicEffect.enumVarImageConst.DEFAULT_IMAGE_FLAG 15055 const flag = HandleDynamicEffect.enumVarImageConst.DEFAULT_IMAGE_FLAG
14827 const defaultBindData = condition.find(item => item[flag]) 15056 const defaultBindData = condition.find(item => item[flag])
14828 if (defaultBindData) { 15057 if (defaultBindData) {
@@ -14837,11 +15066,12 @@ class HandleDynamicEffect { @@ -14837,11 +15066,12 @@ class HandleDynamicEffect {
14837 } 15066 }
14838 } 15067 }
14839 15068
14840 - running(message) {  
14841 - const { subscriptionId, data = {} } = message  
14842 - const { flag, condition } = this.validate(subscriptionId, HandleDynamicEffect.enumActType.RUNNING, data) 15069 + running(message, record) {
  15070 + const { id } = record
  15071 + const { data = {} } = message
  15072 + const { flag, condition } = this.validate(record, HandleDynamicEffect.enumActType.RUNNING, data)
14843 if (!flag) return 15073 if (!flag) return
14844 - const node = this.getNodeByCmdId(subscriptionId) 15074 + const node = this.getNodeByCmdId(id)
14845 let isRun = false 15075 let isRun = false
14846 if (condition.type === HandleDynamicEffect.enumRunningType.RUN) { 15076 if (condition.type === HandleDynamicEffect.enumRunningType.RUN) {
14847 isRun = true 15077 isRun = true
@@ -14897,7 +15127,7 @@ class HandleDynamicEffect { @@ -14897,7 +15127,7 @@ class HandleDynamicEffect {
14897 const { geometry = {} } = cell 15127 const { geometry = {} } = cell
14898 const { width, height } = geometry 15128 const { width, height } = geometry
14899 const idEl = getIdEl() 15129 const idEl = getIdEl()
14900 - graph.getModel().beginUpdate() 15130 + graph.getModel().beginUpdate()
14901 try { 15131 try {
14902 let type 15132 let type
14903 if (videoUrl.replace(reg, '') === 'm3u8') type = 'application/x-mpegURL' 15133 if (videoUrl.replace(reg, '') === 'm3u8') type = 'application/x-mpegURL'
@@ -14939,13 +15169,13 @@ class HandleDynamicEffect { @@ -14939,13 +15169,13 @@ class HandleDynamicEffect {
14939 15169
14940 /** 15170 /**
14941 * @description 验证是否满足条件列表中的任意一条 15171 * @description 验证是否满足条件列表中的任意一条
14942 - * @param subscriptionId 15172 + * @param record
14943 * @param type 15173 * @param type
14944 * @param value 15174 * @param value
14945 * @return {{flag: boolean, condition: {}}} 15175 * @return {{flag: boolean, condition: {}}}
14946 */ 15176 */
14947 - validate(subscriptionId, type, value) {  
14948 - const { condition = [], attr } = this.getBindData(subscriptionId, type) 15177 + validate(record, type, value) {
  15178 + const { condition = [], attr } = record
14949 const result = { condition: {}, flag: false } 15179 const result = { condition: {}, flag: false }
14950 for (let i = 0; i < condition.length; i++) { 15180 for (let i = 0; i < condition.length; i++) {
14951 const { min, max } = condition[i] 15181 const { min, max } = condition[i]
@@ -14996,8 +15226,7 @@ class HandleDynamicEffect { @@ -14996,8 +15226,7 @@ class HandleDynamicEffect {
14996 * @param subscriptionId 15226 * @param subscriptionId
14997 * @return {*} 15227 * @return {*}
14998 */ 15228 */
14999 - getNodeByCmdId(subscriptionId) {  
15000 - const nodeId = this.getNodeIdByCmdId(subscriptionId) 15229 + getNodeByCmdId(nodeId) {
15001 return this.contentAllCell.find(item => item.id === nodeId) 15230 return this.contentAllCell.find(item => item.id === nodeId)
15002 } 15231 }
15003 15232