nayota-show-sdk 1.3.75 → 1.3.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@
7
7
  * const { list, getOne, create, updateOne, deleteOne, deleteMany } = alarmProgress
8
8
  * list({ page: 1, limit: 50 })
9
9
  */
10
- import { requestShow } from '../utils'
10
+ import requestAlarm from '../utils/alarm-request'
11
11
 
12
12
 
13
13
  /**
@@ -56,7 +56,7 @@ import { requestShow } from '../utils'
56
56
  ]}
57
57
  */
58
58
  export function list(query) {
59
- return requestShow({
59
+ return requestAlarm({
60
60
  url: '/alarm-progress',
61
61
  method: 'get',
62
62
  params: query
@@ -88,7 +88,7 @@ export function list(query) {
88
88
  * }
89
89
  */
90
90
  export function create(data) {
91
- return requestShow({
91
+ return requestAlarm({
92
92
  url: '/alarm-progress',
93
93
  method: 'post',
94
94
  data
@@ -115,7 +115,7 @@ export function create(data) {
115
115
  }
116
116
  */
117
117
  export function getOne(id) {
118
- return requestShow({
118
+ return requestAlarm({
119
119
  url: `/alarm-progress/${id}`,
120
120
  method: 'get'
121
121
  })
@@ -148,7 +148,7 @@ export function getOne(id) {
148
148
  * }
149
149
  */
150
150
  export function updateOne(data) {
151
- return requestShow({
151
+ return requestAlarm({
152
152
  url: `/alarm-progress/${data._id}`,
153
153
  method: 'put',
154
154
  data
@@ -175,7 +175,7 @@ export function updateOne(data) {
175
175
  * }
176
176
  */
177
177
  export function deleteOne(id) {
178
- return requestShow({
178
+ return requestAlarm({
179
179
  url: `/alarm-progress/${id}`,
180
180
  method: 'delete'
181
181
  })
@@ -194,7 +194,7 @@ export function deleteOne(id) {
194
194
  * }
195
195
  */
196
196
  export function deleteMany(ids) {
197
- return requestShow({
197
+ return requestAlarm({
198
198
  url: '/alarm-progress',
199
199
  method: 'delete',
200
200
  data: ids // delete传递主体要包含在data里
@@ -1,4 +1,4 @@
1
- import { requestShow } from '../utils'
1
+ import requestAlarm from '../utils/alarm-request'
2
2
  /**
3
3
  * @file 报警记录api
4
4
  * @module 报警记录接口
@@ -320,7 +320,7 @@ import { requestShow } from '../utils'
320
320
  }
321
321
  */
322
322
  export function list(query) {
323
- return requestShow({
323
+ return requestAlarm({
324
324
  url: '/alarm-records',
325
325
  method: 'get',
326
326
  params: query
@@ -373,7 +373,7 @@ export function list(query) {
373
373
  }
374
374
  */
375
375
  export function create(data) {
376
- return requestShow({
376
+ return requestAlarm({
377
377
  url: '/alarm-records',
378
378
  method: 'post',
379
379
  data
@@ -409,7 +409,7 @@ export function create(data) {
409
409
  * }
410
410
  */
411
411
  export function getOne(id) {
412
- return requestShow({
412
+ return requestAlarm({
413
413
  url: `/alarm-records/${id}`,
414
414
  method: 'get'
415
415
  })
@@ -461,7 +461,7 @@ export function getOne(id) {
461
461
  }
462
462
  */
463
463
  export function updateOne(data) {
464
- return requestShow({
464
+ return requestAlarm({
465
465
  url: `/alarm-records/${data._id}`,
466
466
  method: 'put',
467
467
  data
@@ -498,7 +498,7 @@ export function updateOne(data) {
498
498
  * }
499
499
  */
500
500
  export function deleteOne(id) {
501
- return requestShow({
501
+ return requestAlarm({
502
502
  url: `/alarm-records/${id}`,
503
503
  method: 'delete'
504
504
  })
@@ -516,7 +516,7 @@ export function deleteOne(id) {
516
516
  * }
517
517
  */
518
518
  export function deleteMany(ids) {
519
- return requestShow({
519
+ return requestAlarm({
520
520
  url: '/alarm-records',
521
521
  method: 'delete',
522
522
  data: ids // delete传递主体要包含在data里
@@ -563,7 +563,7 @@ export function deleteMany(ids) {
563
563
  }
564
564
  */
565
565
  export function getAlarmCount(data) {
566
- return requestShow({
566
+ return requestAlarm({
567
567
  url: '/alarm-records/alarm-count',
568
568
  method: 'post',
569
569
  data
@@ -593,7 +593,7 @@ export function getAlarmCount(data) {
593
593
  }
594
594
  */
595
595
  export function getAlarmTotalCount() {
596
- return requestShow({
596
+ return requestAlarm({
597
597
  url: '/alarm-records/alarm-total-count',
598
598
  method: 'post'
599
599
  })
@@ -638,7 +638,7 @@ export function getAlarmTotalCount() {
638
638
  }
639
639
  */
640
640
  export function processingManyAlarm(data) {
641
- return requestShow({
641
+ return requestAlarm({
642
642
  url: '/alarm-records/processing-many-alarm',
643
643
  method: 'post',
644
644
  data
@@ -668,7 +668,7 @@ export function processingManyAlarm(data) {
668
668
  }
669
669
  */
670
670
  export function exportAlarmRecord(data) {
671
- return requestShow({
671
+ return requestAlarm({
672
672
  url: '/alarm-records/export-alarm-excel',
673
673
  method: 'post',
674
674
  data
@@ -724,7 +724,7 @@ export function exportAlarmRecord(data) {
724
724
  ]}
725
725
  */
726
726
  export function getMoreAlarmCount(data) {
727
- return requestShow({
727
+ return requestAlarm({
728
728
  url: '/alarm-records/more-alarm-count',
729
729
  method: 'post',
730
730
  data
@@ -742,7 +742,7 @@ export function getMoreAlarmCount(data) {
742
742
  * @returns {Object} data - 统计结果
743
743
  */
744
744
  export function alarmStatistics(query) {
745
- return requestShow({
745
+ return requestAlarm({
746
746
  url: '/alarm-records/alarm-statistics',
747
747
  method: 'get',
748
748
  params: query
@@ -759,7 +759,7 @@ export function alarmStatistics(query) {
759
759
  * @returns {Object} data - 统计结果
760
760
  */
761
761
  export function alarmAverageResponseDuration(query) {
762
- return requestShow({
762
+ return requestAlarm({
763
763
  url: '/alarm-records/alarm-average-response-duration',
764
764
  method: 'get',
765
765
  params: query
@@ -779,7 +779,7 @@ export function alarmAverageResponseDuration(query) {
779
779
  * @returns {Array<Object>} data - 告警类型统计结果
780
780
  */
781
781
  export function alarmTypeCount(query) {
782
- return requestShow({
782
+ return requestAlarm({
783
783
  url: '/alarm-records/alarm-type-count',
784
784
  method: 'get',
785
785
  params: query
@@ -796,7 +796,7 @@ export function alarmTypeCount(query) {
796
796
  * @returns {Object} data - 查询结果
797
797
  */
798
798
  export function topDepart(query) {
799
- return requestShow({
799
+ return requestAlarm({
800
800
  url: '/alarm-records/top-depart',
801
801
  method: 'get',
802
802
  params: query
@@ -815,7 +815,7 @@ export function topDepart(query) {
815
815
  * @returns {Array<Object>} data - 排行榜结果
816
816
  */
817
817
  export function alarmRankingCount(query) {
818
- return requestShow({
818
+ return requestAlarm({
819
819
  url: '/alarm-records/alarm-ranking-count',
820
820
  method: 'get',
821
821
  params: query
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nayota-show-sdk",
3
- "version": "1.3.75",
3
+ "version": "1.3.77",
4
4
  "description": "nayota-show-server rest-api",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -0,0 +1,22 @@
1
+ import urlcfg from '../config/urlcfg'
2
+ import { requestIot, requestShow } from './index'
3
+
4
+ export function getAlarmRequestTarget() {
5
+ if (!urlcfg.isV2()) {
6
+ return 'show'
7
+ }
8
+
9
+ if (!urlcfg.getIotUrl()) {
10
+ throw new Error('[nayota-show-sdk][v2] iotServer is required for alarm module.')
11
+ }
12
+
13
+ return 'iot'
14
+ }
15
+
16
+ export function requestAlarm(config) {
17
+ return getAlarmRequestTarget() === 'iot'
18
+ ? requestIot(config)
19
+ : requestShow(config)
20
+ }
21
+
22
+ export default requestAlarm
@@ -0,0 +1,35 @@
1
+ const urlcfg = require('../config/urlcfg').default
2
+ const { getAlarmRequestTarget } = require('./alarm-request')
3
+
4
+ describe('alarm request target', () => {
5
+ const originalVersion = urlcfg.version
6
+ const originalIotServer = urlcfg.iotServer
7
+
8
+ afterEach(() => {
9
+ urlcfg.version = originalVersion
10
+ urlcfg.iotServer = originalIotServer
11
+ })
12
+
13
+ test('uses show target by default', () => {
14
+ urlcfg.version = 'v1'
15
+ urlcfg.iotServer = ''
16
+
17
+ expect(getAlarmRequestTarget()).toBe('show')
18
+ })
19
+
20
+ test('uses iot target in v2', () => {
21
+ urlcfg.version = 'v2'
22
+ urlcfg.iotServer = '/iot-api'
23
+
24
+ expect(getAlarmRequestTarget()).toBe('iot')
25
+ })
26
+
27
+ test('requires iotServer in v2', () => {
28
+ urlcfg.version = 'v2'
29
+ urlcfg.iotServer = ''
30
+
31
+ expect(() => getAlarmRequestTarget()).toThrow(
32
+ '[nayota-show-sdk][v2] iotServer is required for alarm module.'
33
+ )
34
+ })
35
+ })
@@ -41,6 +41,37 @@ function normalizeAreaFloorPlan(data = {}) {
41
41
  return undefined
42
42
  }
43
43
 
44
+ function normalizeAreaCenterPoint(data = {}) {
45
+ if (data.centerPoint) {
46
+ return data.centerPoint
47
+ }
48
+
49
+ if (Array.isArray(data.centerCoordinate) && data.centerCoordinate.length >= 2) {
50
+ return removeUndefinedFields({
51
+ x: data.centerCoordinate[0],
52
+ y: data.centerCoordinate[1]
53
+ })
54
+ }
55
+
56
+ return undefined
57
+ }
58
+
59
+ function normalizeAreaCenterCoordinate(item = {}) {
60
+ if (Array.isArray(item.centerCoordinate)) {
61
+ return item.centerCoordinate
62
+ }
63
+
64
+ if (item.centerPoint && typeof item.centerPoint === 'object') {
65
+ const x = item.centerPoint.x != null ? item.centerPoint.x : item.centerPoint.longitude
66
+ const y = item.centerPoint.y != null ? item.centerPoint.y : item.centerPoint.latitude
67
+ if (x != null && y != null) {
68
+ return [x, y]
69
+ }
70
+ }
71
+
72
+ return undefined
73
+ }
74
+
44
75
  function mapAreaToIotQuery(query = {}) {
45
76
  const next = removeUndefinedFields({
46
77
  ...omitKeys(query, ['_id', 'depart', 'visible', 'areaClass', 'sort']),
@@ -74,7 +105,8 @@ function mapAreaToIotBody(data = {}) {
74
105
  'areaClass',
75
106
  'targetDepartId',
76
107
  'type',
77
- 'relationInfo'
108
+ 'relationInfo',
109
+ 'centerCoordinate'
78
110
  ]),
79
111
  code: data.code || fallbackCode(data.name || data._id, 'SPACE'),
80
112
  spaceType: data.spaceType || 'zone',
@@ -83,6 +115,7 @@ function mapAreaToIotBody(data = {}) {
83
115
  area: data.area != null ? data.area : data.areaSize,
84
116
  areaClassId: data.areaClassId || resolveLegacyReference(data.areaClass),
85
117
  targetHierarchyId: data.targetHierarchyId || resolveLegacyReference(data.targetDepartId),
118
+ centerPoint: normalizeAreaCenterPoint(data),
86
119
  floorPlan: normalizeAreaFloorPlan(data),
87
120
  statisticsJson: parseLegacyJson(data.statisticsJson),
88
121
  metadata: Object.keys(metadata).length ? metadata : undefined
@@ -105,6 +138,7 @@ function mapIotAreaToLegacy(item = {}) {
105
138
  areaClass: entity.areaClassId,
106
139
  targetDepartId: entity.targetHierarchyId,
107
140
  type: metadata.legacyType || entity.type,
141
+ centerCoordinate: normalizeAreaCenterCoordinate(entity),
108
142
  imageUrl: entity.imageUrl || getNestedValue(entity, 'floorPlan.url'),
109
143
  statisticsJson: stringifyLegacyJson(entity.statisticsJson),
110
144
  relationInfo
@@ -215,12 +249,16 @@ function mapIotDepartsToLegacy(item = {}) {
215
249
  }
216
250
 
217
251
  function mapDevicesToIotQuery(query = {}) {
252
+ const digitalTwinTypeId = query.digitalTwinTypeId != null && query.digitalTwinTypeId !== ''
253
+ ? query.digitalTwinTypeId
254
+ : resolveLegacyReference(query.deviceClass) || undefined
255
+
218
256
  return removeUndefinedFields({
219
257
  ...omitKeys(query, ['_id', 'depart', 'area', 'deviceClass', 'cloudType', 'status', 'sort']),
220
258
  id: query.id || query._id,
221
259
  hierarchyId: query.hierarchyId || query.depart,
222
260
  spaceId: query.spaceId || query.area,
223
- digitalTwinTypeId: query.digitalTwinTypeId || resolveLegacyReference(query.deviceClass),
261
+ digitalTwinTypeId,
224
262
  isActive: query.isActive != null ? query.isActive : (query.cloudType != null ? query.cloudType : query.status),
225
263
  ...parseLegacySort(query.sort, {
226
264
  deviceClass: 'digitalTwinTypeId',
@@ -232,6 +270,10 @@ function mapDevicesToIotQuery(query = {}) {
232
270
  }
233
271
 
234
272
  function mapDevicesToIotBody(data = {}) {
273
+ const digitalTwinTypeId = data.digitalTwinTypeId != null && data.digitalTwinTypeId !== ''
274
+ ? data.digitalTwinTypeId
275
+ : resolveLegacyReference(data.deviceClass) || undefined
276
+
235
277
  const metadata = mergeMetadata(data.metadata, {
236
278
  configDeviceId: data.n_device,
237
279
  mapLatLng: data.mapLatLng,
@@ -268,7 +310,7 @@ function mapDevicesToIotBody(data = {}) {
268
310
  twinId: data.twinId || data.n_device || fallbackCode(data.name || data._id, 'TWIN'),
269
311
  hierarchyId: data.hierarchyId || data.depart,
270
312
  spaceId: data.spaceId || data.area,
271
- digitalTwinTypeId: data.digitalTwinTypeId || resolveLegacyReference(data.deviceClass),
313
+ digitalTwinTypeId,
272
314
  isActive: data.isActive != null ? data.isActive : (data.cloudType != null ? data.cloudType : data.status),
273
315
  metadata: Object.keys(metadata).length ? metadata : undefined
274
316
  })
@@ -360,60 +402,6 @@ function normalizeLegacyPropLine(source = {}, prop = {}, row = {}) {
360
402
  return null
361
403
  }
362
404
 
363
- const LEGACY_SWITCH_STATUS_KEYWORDS = [
364
- '开关',
365
- '电源',
366
- '启停',
367
- '启动',
368
- '运行',
369
- 'switch',
370
- 'power'
371
- ]
372
-
373
- const LEGACY_SWITCH_STATUS_EXCLUDE_KEYWORDS = [
374
- '模式',
375
- '温度',
376
- '风速',
377
- '设定',
378
- '设置',
379
- '锁屏',
380
- '锁定',
381
- 'lock',
382
- 'mode',
383
- 'temp',
384
- 'speed',
385
- 'set'
386
- ]
387
-
388
- function isLegacyBinaryInterval(interval) {
389
- try {
390
- const payload = typeof interval === 'string' ? JSON.parse(interval) : interval
391
- return Array.isArray(payload) && Array.isArray(payload[0]) && payload[0].length === 2
392
- } catch {
393
- return false
394
- }
395
- }
396
-
397
- function isLegacySwitchOperateStatus(source = {}, interval = '') {
398
- if (source.propType !== 'Operate' || !isLegacyBinaryInterval(interval)) {
399
- return false
400
- }
401
-
402
- const normalized = [
403
- source.propertyKey,
404
- source.propName,
405
- source.name,
406
- source.code,
407
- source.shortAddress
408
- ].filter(Boolean).join(' ').toLowerCase()
409
-
410
- if (LEGACY_SWITCH_STATUS_EXCLUDE_KEYWORDS.some(keyword => normalized.includes(keyword))) {
411
- return false
412
- }
413
-
414
- return LEGACY_SWITCH_STATUS_KEYWORDS.some(keyword => normalized.includes(keyword))
415
- }
416
-
417
405
  function normalizeLegacyNumber(value) {
418
406
  if (value === undefined || value === null || value === '') {
419
407
  return null
@@ -522,7 +510,7 @@ function normalizeLegacyEasyListProp(source = {}, row = {}) {
522
510
  const interval = prop.interval || source.interval || source.valueMap || ''
523
511
  const line = normalizeLegacyPropLine(source, prop, row)
524
512
  const isMain = Boolean(source.isMain)
525
- const isStatus = Boolean(source.isStatus || isLegacySwitchOperateStatus(source, interval))
513
+ const isStatus = Boolean(source.isStatus)
526
514
  const isNumber = Boolean(source.isNumber)
527
515
  const isImport = Boolean(source.isImport || isMain || isStatus || isNumber)
528
516
 
@@ -548,7 +536,7 @@ function normalizeLegacyEasyListProp(source = {}, row = {}) {
548
536
  })
549
537
 
550
538
  return removeUndefinedFields({
551
- ...source,
539
+ ...omitKeys(source, ['isShow', 'isCensus']),
552
540
  _id: source._id || source.id,
553
541
  propId,
554
542
  devicePropertyId: source.devicePropertyId || propId,
@@ -127,6 +127,62 @@ describe('iotModuleSpecs departs hierarchy compatibility', () => {
127
127
  })
128
128
  })
129
129
 
130
+ describe('iotModuleSpecs area space compatibility', () => {
131
+ const area = iotModuleSpecs.area.operations
132
+
133
+ test('maps legacy centerCoordinate to space centerPoint when creating areas', () => {
134
+ const request = area.create.toRequest({
135
+ name: '前厅区域',
136
+ depart: 'hierarchy-1',
137
+ bounds: [[0, 0], [10, 0], [10, 10], [0, 10]],
138
+ centerCoordinate: [5, 5]
139
+ })
140
+
141
+ expect(request.url).toBe('/spaces')
142
+ expect(request.method).toBe('post')
143
+ expect(request.data.centerCoordinate).toBeUndefined()
144
+ expect(request.data.centerPoint).toEqual({ x: 5, y: 5 })
145
+ })
146
+
147
+ test('maps space centerPoint back to legacy centerCoordinate', () => {
148
+ const response = area.list.fromResponse({
149
+ code: 0,
150
+ data: {
151
+ total: 1,
152
+ items: [
153
+ {
154
+ id: 'space-1',
155
+ name: '前厅区域',
156
+ hierarchyId: 'hierarchy-1',
157
+ centerPoint: { x: 12, y: 34 }
158
+ }
159
+ ]
160
+ }
161
+ })
162
+
163
+ expect(response.data.rows[0].centerCoordinate).toEqual([12, 34])
164
+ })
165
+ })
166
+
167
+ describe('iotModuleSpecs devices write compatibility', () => {
168
+ const devices = iotModuleSpecs.devices.operations
169
+
170
+ test('does not send digitalTwinTypeId null for partial map coordinate updates', () => {
171
+ const request = devices.updateOne.toRequest({
172
+ _id: '77b8889e-7d3a-4efa-9fc9-858305468d6c',
173
+ digitalTwinTypeId: null,
174
+ spaceId: 'c13c121f-1a23-4656-be54-9e7488f43c55',
175
+ svgCoordinates: [891.4283167347667, 739.999788571489]
176
+ })
177
+
178
+ expect(request.url).toBe('/digital-twins/77b8889e-7d3a-4efa-9fc9-858305468d6c')
179
+ expect(request.method).toBe('patch')
180
+ expect(request.data.digitalTwinTypeId).toBeUndefined()
181
+ expect(request.data.spaceId).toBe('c13c121f-1a23-4656-be54-9e7488f43c55')
182
+ expect(request.data.svgCoordinates).toEqual([891.4283167347667, 739.999788571489])
183
+ })
184
+ })
185
+
130
186
  describe('iotModuleSpecs devices easyList legacy compatibility', () => {
131
187
  const easyList = iotModuleSpecs.devices.operations.easyList
132
188
 
@@ -219,11 +275,11 @@ describe('iotModuleSpecs devices easyList legacy compatibility', () => {
219
275
 
220
276
  expect(row._id).toBe('twin-1')
221
277
  expect(row.status).toEqual({
222
- value: 1,
223
- label: '',
224
- valueStr: '',
225
- total: 3,
226
- open: 1
278
+ value: 0,
279
+ label: '解锁',
280
+ valueStr: '解锁',
281
+ total: 2,
282
+ open: 0
227
283
  })
228
284
  expect(modeProp).toEqual(
229
285
  expect.objectContaining({
@@ -251,12 +307,14 @@ describe('iotModuleSpecs devices easyList legacy compatibility', () => {
251
307
  expect(switchProp).toEqual(
252
308
  expect.objectContaining({
253
309
  propType: 'Operate',
254
- isStatus: true,
255
- isImport: true,
310
+ isStatus: false,
311
+ isImport: false,
256
312
  value: 1,
257
313
  valueStr: '开'
258
314
  })
259
315
  )
316
+ expect(switchProp.isShow).toBeUndefined()
317
+ expect(switchProp.isCensus).toBeUndefined()
260
318
  expect(electricProp).toEqual(
261
319
  expect.objectContaining({
262
320
  isMain: true,