nayota-show-sdk 1.3.65 → 1.3.66

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.
@@ -10,6 +10,10 @@ function shouldUseIot(action) {
10
10
  * @file 设备类型api
11
11
  * @module 设备类型接口
12
12
  * @category 设备管理
13
+ * @import
14
+ * import { deviceClass } from 'nayota-show-sdk'
15
+ * const { list, create, getOne, updateOne, deleteOne, deleteMany, getDeviceOffline, onlineRate } = deviceClass
16
+ * list({ page: 1, limit: 10 })
13
17
  * @categoryOrder 2
14
18
  */
15
19
 
@@ -209,6 +213,48 @@ export function getDeviceOffline(data) {
209
213
  })
210
214
  }
211
215
 
216
+ /**
217
+ * 获取设备类型在线率
218
+ * @param {Object} query - 查询参数
219
+ * @param {number} query.year - 统计年份,例如 2026
220
+ * @param {number} [query.month] - 统计月份,1-12;不传表示查询整年
221
+ * @param {string} [query.creator] - 所属用户ID
222
+ * @param {Array<string>|string} [query.deviceClasses] - 设备类型ID列表,也兼容逗号分隔字符串
223
+ * @returns {number} code - 返回码,0表示成功
224
+ * @returns {Object} data - 在线率统计结果
225
+ * @returns {number} data.year - 统计年份
226
+ * @returns {number|null} data.month - 统计月份;查询全年时为 null
227
+ * @returns {number} data.startTime - 统计开始时间戳
228
+ * @returns {number} data.endTime - 统计结束时间戳
229
+ * @returns {Object} data.summary - 所有设备类型汇总在线率
230
+ * @returns {number} data.summary.onlineDuration - 汇总在线时长,单位毫秒
231
+ * @returns {number} data.summary.offlineDuration - 汇总离线时长,单位毫秒
232
+ * @returns {number} data.summary.totalDuration - 汇总总时长,单位毫秒
233
+ * @returns {number} data.summary.onlineRate - 汇总在线率,0-1
234
+ * @returns {number} data.summary.onlineRatePercent - 汇总在线率百分比
235
+ * @returns {Array<Object>} data.items - 各设备类型在线率列表
236
+ * @returns {string} data.items[].deviceClass - 设备类型ID
237
+ * @returns {string} data.items[].deviceClassName - 设备类型名称
238
+ * @returns {number} data.items[].alarmTotal - 参与统计的在离线 alarm 数量
239
+ * @returns {Object} data.items[].summary - 当前设备类型在线率汇总
240
+ * @returns {number} data.items[].summary.onlineDuration - 在线时长,单位毫秒
241
+ * @returns {number} data.items[].summary.offlineDuration - 离线时长,单位毫秒
242
+ * @returns {number} data.items[].summary.totalDuration - 总时长,单位毫秒
243
+ * @returns {number} data.items[].summary.onlineRate - 在线率,0-1
244
+ * @returns {number} data.items[].summary.onlineRatePercent - 在线率百分比
245
+ */
246
+ export function onlineRate(query) {
247
+ if (shouldUseIot('onlineRate')) {
248
+ return executeIotModuleAction(MODULE_NAME, 'onlineRate', query)
249
+ }
250
+
251
+ return requestShow({
252
+ url: '/device-classes/online-rate',
253
+ method: 'get',
254
+ params: query
255
+ })
256
+ }
257
+
212
258
  export default {
213
259
  list,
214
260
  create,
@@ -216,5 +262,6 @@ export default {
216
262
  deleteOne,
217
263
  deleteMany,
218
264
  getOne,
219
- getDeviceOffline
265
+ getDeviceOffline,
266
+ onlineRate
220
267
  }
package/index.test.js CHANGED
@@ -1,27 +1,38 @@
1
- import sdk from './index'
1
+ let modules
2
+ beforeAll(() => {
3
+ jest.mock('./__mocks__/requireContext')
2
4
 
3
- describe('nayota-show-sdk exports', () => {
4
- test('exposes config entry and core API modules', () => {
5
- expect(sdk).toBeDefined()
6
- expect(typeof sdk.config).toBe('function')
7
- expect(typeof sdk.on).toBe('function')
8
-
9
- expect(sdk.area).toBeDefined()
10
- expect(typeof sdk.area.list).toBe('function')
11
-
12
- expect(sdk.areaClass).toBeDefined()
13
- expect(typeof sdk.areaClass.getOne).toBe('function')
14
-
15
- expect(sdk.components).toBeDefined()
16
- expect(typeof sdk.components.create).toBe('function')
5
+ modules = require('./index.js')
6
+ })
17
7
 
18
- expect(sdk.departs).toBeDefined()
19
- expect(typeof sdk.departs.updateOne).toBe('function')
8
+ // Test the modules object
9
+ describe('modules', () => {
10
+ test('should have the correct structure', () => {
11
+ expect(modules).toBeDefined()
12
+ expect(typeof modules).toBe('object')
13
+ expect(Object.keys(modules)).toHaveLength(17) // Assuming there is only one module in the littleTool directory
20
14
 
21
- expect(sdk.devices).toBeDefined()
22
- expect(typeof sdk.devices.easyList).toBe('function')
15
+ // Test the structure of the module
16
+ // const module = modules['api'] // Assuming the module name is 'api'
17
+ // expect(module).toBeDefined()
18
+ // expect(typeof module).toBe('object')
19
+ // expect(Object.keys(module)).toHaveLength(13) // Assuming there are 13 sub-modules in the api directory
23
20
 
24
- expect(sdk.deviceClass).toBeDefined()
25
- expect(typeof sdk.deviceClass.deleteOne).toBe('function')
21
+ // // Test the structure of each sub-module
22
+ // expect(module['alarms']).toBeDefined()
23
+ // expect(module['checkReduces']).toBeDefined()
24
+ // expect(module['user']).toBeDefined()
25
+ // expect(module['httpDrives']).toBeDefined()
26
+ // expect(module['hardwares']).toBeDefined()
27
+ // expect(module['checks']).toBeDefined()
28
+ // expect(module['cloudHardwares']).toBeDefined()
29
+ // expect(module['loraSlaves']).toBeDefined()
30
+ // expect(module['lorawanDevices']).toBeDefined()
31
+ // expect(module['nbiotDrives']).toBeDefined()
32
+ // expect(module['nbm2mDevices']).toBeDefined()
33
+ // expect(module['netDrives']).toBeDefined()
34
+ // expect(module['netMqttDevices']).toBeDefined()
35
+ // // 添加alarms list请求的测试
36
+ // expect(module['alarms']['list']).toBeDefined()
26
37
  })
27
38
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nayota-show-sdk",
3
- "version": "1.3.65",
3
+ "version": "1.3.66",
4
4
  "description": "nayota-show-server rest-api",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -1,95 +0,0 @@
1
- import httpConfigIot from './utils/http-config-iot'
2
-
3
- jest.mock('axios', () => {
4
- const create = jest.fn(() => {
5
- const instance = jest.fn()
6
- instance.interceptors = {
7
- request: { use: jest.fn() },
8
- response: { use: jest.fn() }
9
- }
10
- return instance
11
- })
12
-
13
- return {
14
- __esModule: true,
15
- default: {
16
- create,
17
- defaults: {
18
- headers: {
19
- common: {}
20
- }
21
- }
22
- }
23
- }
24
- })
25
-
26
- describe('httpConfigIot', () => {
27
- test('normalizes iot success code 200 into legacy success code 0', () => {
28
- const http = httpConfigIot()
29
- const responseInterceptor = http.interceptors.response.use.mock.calls[0][0]
30
-
31
- expect(
32
- responseInterceptor({
33
- status: 200,
34
- headers: {},
35
- data: {
36
- code: 200,
37
- data: {
38
- id: 'space-1'
39
- }
40
- }
41
- })
42
- ).toEqual({
43
- code: 0,
44
- data: {
45
- id: 'space-1'
46
- }
47
- })
48
- })
49
-
50
- test('normalizes any 2xx iot code into legacy success code 0', () => {
51
- const http = httpConfigIot()
52
- const responseInterceptor = http.interceptors.response.use.mock.calls[0][0]
53
-
54
- expect(
55
- responseInterceptor({
56
- status: 201,
57
- headers: {},
58
- data: {
59
- code: 201,
60
- data: {
61
- id: 'space-2'
62
- }
63
- }
64
- })
65
- ).toEqual({
66
- code: 0,
67
- data: {
68
- id: 'space-2'
69
- }
70
- })
71
- })
72
-
73
- test('accepts string based 2xx iot codes as legacy success too', () => {
74
- const http = httpConfigIot()
75
- const responseInterceptor = http.interceptors.response.use.mock.calls[0][0]
76
-
77
- expect(
78
- responseInterceptor({
79
- status: 204,
80
- headers: {},
81
- data: {
82
- code: '204',
83
- data: {
84
- id: 'space-3'
85
- }
86
- }
87
- })
88
- ).toEqual({
89
- code: 0,
90
- data: {
91
- id: 'space-3'
92
- }
93
- })
94
- })
95
- })
@@ -1,59 +0,0 @@
1
- import { buildLegacyListResponse } from './utils/iot-adapter-helpers'
2
-
3
- describe('iot adapter helpers', () => {
4
- test('wraps list responses as code + data.total/data.rows', () => {
5
- const result = buildLegacyListResponse({
6
- total: 1,
7
- items: [
8
- {
9
- id: 'type-1',
10
- name: '风速仪'
11
- }
12
- ]
13
- })
14
-
15
- expect(result).toEqual({
16
- code: 0,
17
- data: {
18
- total: 1,
19
- rows: [
20
- {
21
- id: 'type-1',
22
- _id: 'type-1',
23
- name: '风速仪'
24
- }
25
- ]
26
- }
27
- })
28
- })
29
-
30
- test('unwraps nested iot data.items responses before mapping to legacy rows', () => {
31
- const result = buildLegacyListResponse({
32
- code: 0,
33
- success: true,
34
- data: {
35
- total: 1,
36
- items: [
37
- {
38
- id: 'depart-1',
39
- name: '研发园B区'
40
- }
41
- ]
42
- }
43
- })
44
-
45
- expect(result).toEqual({
46
- code: 0,
47
- data: {
48
- total: 1,
49
- rows: [
50
- {
51
- id: 'depart-1',
52
- _id: 'depart-1',
53
- name: '研发园B区'
54
- }
55
- ]
56
- }
57
- })
58
- })
59
- })
@@ -1,72 +0,0 @@
1
- import { iotModuleSpecs } from './utils/iot-module-specs'
2
-
3
- describe('iot module specs', () => {
4
- test('devices.easyList unwraps nested data.rows payloads', () => {
5
- const response = iotModuleSpecs.devices.operations.easyList.fromResponse({
6
- code: 0,
7
- success: true,
8
- data: {
9
- total: 2,
10
- rows: [
11
- {
12
- id: 'device-1',
13
- name: '风速仪'
14
- },
15
- {
16
- id: 'device-2',
17
- name: '温湿度传感器'
18
- }
19
- ]
20
- }
21
- })
22
-
23
- expect(response).toEqual({
24
- code: 0,
25
- data: {
26
- total: 2,
27
- rows: [
28
- {
29
- id: 'device-1',
30
- _id: 'device-1',
31
- name: '风速仪'
32
- },
33
- {
34
- id: 'device-2',
35
- _id: 'device-2',
36
- name: '温湿度传感器'
37
- }
38
- ]
39
- }
40
- })
41
- })
42
-
43
- test('devices.easyList also supports nested data.items payloads', () => {
44
- const response = iotModuleSpecs.devices.operations.easyList.fromResponse({
45
- code: 0,
46
- success: true,
47
- data: {
48
- total: 1,
49
- items: [
50
- {
51
- id: 'device-3',
52
- name: '层级设备'
53
- }
54
- ]
55
- }
56
- })
57
-
58
- expect(response).toEqual({
59
- code: 0,
60
- data: {
61
- total: 1,
62
- rows: [
63
- {
64
- id: 'device-3',
65
- _id: 'device-3',
66
- name: '层级设备'
67
- }
68
- ]
69
- }
70
- })
71
- })
72
- })