@cpzxrobot/sdk 1.0.50 → 1.0.52

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.
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ const assistant_gateway_1 = require("./assistant_gateway");
14
14
  const energy_gateway_1 = require("./energy_gateway");
15
15
  const camera_gateway_1 = require("./camera_gateway");
16
16
  const pigfarm_gateway_1 = require("./pigfarm_gateway");
17
+ const unit_gateway_1 = require("./unit_gateway");
17
18
  class Cpzxrobot {
18
19
  constructor(appCode) {
19
20
  this.pigfarm = new pigfarm_gateway_1.PigfarmGateway(this);
@@ -30,6 +31,7 @@ class Cpzxrobot {
30
31
  this.appCode = appCode;
31
32
  this.user = new user_gateway_1.UserGateway(this);
32
33
  this.factory = new factory_gateway_1.FactoryGateway(this);
34
+ this.unit = new unit_gateway_1.UnitGateway(this);
33
35
  this.device = new device_gateway_1.DeviceGateway(this);
34
36
  this.transport = new transport_gateway_1.TransportGateway(this);
35
37
  this.assistant = new assistant_gateway_1.AssistantGateway(this);
@@ -24,7 +24,7 @@ class PigfarmGateway extends Object {
24
24
  * @param start 开始时间,格式为"yyyy-MM-dd"
25
25
  * @param end 结束时间,格式为"yyyy-MM-dd"
26
26
  * @returns 返回Promise对象,解析后得到axios响应结果
27
- */
27
+ */
28
28
  }
29
29
  unitStat(unitIds, start, end) {
30
30
  return this.context.ready.then((axios) => {
@@ -62,6 +62,25 @@ class PigfarmGateway extends Object {
62
62
  });
63
63
  });
64
64
  }
65
+ get relay() {
66
+ return {
67
+ list: (unit) => {
68
+ return this.context.ready.then((axios) => {
69
+ return axios.get(`/api/v2/pigfarm/relay/config/${unit.id}`);
70
+ });
71
+ },
72
+ add: (unit, data) => {
73
+ return this.context.ready.then((axios) => {
74
+ return axios.post(`/api/v2/pigfarm/relay/config/add/${unit.id}`, data);
75
+ });
76
+ },
77
+ update: (unit, data) => {
78
+ return this.context.ready.then((axios) => {
79
+ return axios.post(`/api/v2/pigfarm/relay/config/update/${unit.id}`, data);
80
+ });
81
+ },
82
+ };
83
+ }
65
84
  get heatlamp() {
66
85
  return {
67
86
  add: (unit, data) => {
@@ -94,10 +113,12 @@ class PigfarmGateway extends Object {
94
113
  //设置,传入id或对象,action为dayage时需要传回设置的天数
95
114
  set: async (lamp, action, arg) => {
96
115
  var axios = await this.context.ready;
97
- var url = action === "dayage" ? "/api/v1/pigfarm/heatLamp/syncDayage" : `/api/v1/pigfarm/heatLamp/config/set`;
116
+ var url = action === "dayage"
117
+ ? "/api/v1/pigfarm/heatLamp/syncDayage"
118
+ : `/api/v1/pigfarm/heatLamp/config/set`;
98
119
  var id = typeof lamp === "number" ? lamp : lamp.id;
99
120
  var body = {
100
- id
121
+ id,
101
122
  };
102
123
  switch (action) {
103
124
  case "dayage":
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnitGateway = void 0;
4
+ class UnitGateway extends Object {
5
+ constructor(context) {
6
+ super();
7
+ this.context = context;
8
+ }
9
+ get config() {
10
+ return {
11
+ add: (unit, type, config) => {
12
+ return this.context.ready.then((axios) => {
13
+ return axios.post(`/api/v2/unit/config/add`, {
14
+ unitId: unit.id,
15
+ type,
16
+ config,
17
+ });
18
+ });
19
+ },
20
+ update: (unit, type, config) => {
21
+ return this.context.ready.then((axios) => {
22
+ return axios.post(`/api/v2/unit/config/update`, {
23
+ unitId: unit.id,
24
+ type,
25
+ config,
26
+ });
27
+ });
28
+ },
29
+ get: (unit, type) => {
30
+ return this.context.ready.then((axios) => {
31
+ return axios.get(`/api/v2/unit/config`, {
32
+ params: {
33
+ unitId: unit.id,
34
+ type,
35
+ },
36
+ });
37
+ });
38
+ },
39
+ };
40
+ }
41
+ }
42
+ exports.UnitGateway = UnitGateway;
package/index.ts CHANGED
@@ -9,6 +9,7 @@ import { CameraGateway } from "./camera_gateway";
9
9
  import { type ElectricMeterRate } from "./energy_types/electric_meter_gateway";
10
10
  import { PigfarmGateway } from "./pigfarm_gateway";
11
11
  import { Device, Factory, MyAxiosInstance, Unit } from "./types";
12
+ import { UnitGateway } from "./unit_gateway";
12
13
 
13
14
  export class Cpzxrobot {
14
15
  device: DeviceGateway;
@@ -37,6 +38,7 @@ export class Cpzxrobot {
37
38
  assistant: AssistantGateway;
38
39
  energy: EnergyGateway;
39
40
  camera: CameraGateway;
41
+ unit: UnitGateway;
40
42
 
41
43
  constructor(appCode: string) {
42
44
  //获取当前浏览器的域名
@@ -48,6 +50,7 @@ export class Cpzxrobot {
48
50
  this.appCode = appCode;
49
51
  this.user = new UserGateway(this);
50
52
  this.factory = new FactoryGateway(this);
53
+ this.unit = new UnitGateway(this);
51
54
  this.device = new DeviceGateway(this);
52
55
  this.transport = new TransportGateway(this);
53
56
  this.assistant = new AssistantGateway(this);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.0.50",
3
+ "version": "1.0.52",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,4 +1,4 @@
1
- import { Cpzxrobot, HeatLamp, Unit } from ".";
1
+ import { Cpzxrobot, DeviceConfig, HeatLamp, Unit } from ".";
2
2
 
3
3
  export class PigfarmGateway extends Object {
4
4
  context: Cpzxrobot;
@@ -18,15 +18,16 @@ export class PigfarmGateway extends Object {
18
18
  return this.context.ready.then((axios) => {
19
19
  return axios.get(`/api/v1/pigfarm/pigcount/${unit.id}`);
20
20
  });
21
-
22
- /**
23
- * 获取单元统计信息
24
- *
25
- * @param unitIds 单元ID数组
26
- * @param start 开始时间,格式为"yyyy-MM-dd"
27
- * @param end 结束时间,格式为"yyyy-MM-dd"
28
- * @returns 返回Promise对象,解析后得到axios响应结果
29
- */ }
21
+
22
+ /**
23
+ * 获取单元统计信息
24
+ *
25
+ * @param unitIds 单元ID数组
26
+ * @param start 开始时间,格式为"yyyy-MM-dd"
27
+ * @param end 结束时间,格式为"yyyy-MM-dd"
28
+ * @returns 返回Promise对象,解析后得到axios响应结果
29
+ */
30
+ }
30
31
  unitStat(unitIds: Number[], start: string, end: string) {
31
32
  return this.context.ready.then((axios) => {
32
33
  return axios.post(`/api/v1/pigfarm/feedStatics`, {
@@ -71,6 +72,26 @@ export class PigfarmGateway extends Object {
71
72
  });
72
73
  }
73
74
 
75
+ get relay() {
76
+ return {
77
+ list: (unit: Unit) => {
78
+ return this.context.ready.then((axios) => {
79
+ return axios.get(`/api/v2/pigfarm/relay/config/${unit.id}`);
80
+ });
81
+ },
82
+ add: (unit: Unit, data: DeviceConfig) => {
83
+ return this.context.ready.then((axios) => {
84
+ return axios.post(`/api/v2/pigfarm/relay/config/add/${unit.id}`, data);
85
+ });
86
+ },
87
+ update: (unit: Unit, data: DeviceConfig) => {
88
+ return this.context.ready.then((axios) => {
89
+ return axios.post(`/api/v2/pigfarm/relay/config/update/${unit.id}`, data);
90
+ });
91
+ },
92
+ };
93
+ }
94
+
74
95
  get heatlamp() {
75
96
  return {
76
97
  add: (unit: Unit, data: HeatLamp) => {
@@ -89,16 +110,12 @@ export class PigfarmGateway extends Object {
89
110
  },
90
111
  list: async (unit: Unit): Promise<any> => {
91
112
  var axios = await this.context.ready;
92
- return axios.post(
93
- `/api/v1/pigfarm/heatLamp/list/${unit.id}`
94
- );
113
+ return axios.post(`/api/v1/pigfarm/heatLamp/list/${unit.id}`);
95
114
  },
96
115
  //返回物联网相关的字段
97
116
  iotFields: async (lamp: HeatLamp): Promise<any> => {
98
117
  var axios = await this.context.ready;
99
- return axios.post(
100
- `/api/v1/pigfarm/heatLamp/iotFields/${lamp.id}`
101
- );
118
+ return axios.post(`/api/v1/pigfarm/heatLamp/iotFields/${lamp.id}`);
102
119
  },
103
120
  //开关,传入id或对象,action为on或off
104
121
  switch: async (lamp: HeatLamp | number, action: "on" | "off") => {
@@ -110,15 +127,18 @@ export class PigfarmGateway extends Object {
110
127
  });
111
128
  },
112
129
  //设置,传入id或对象,action为dayage时需要传回设置的天数
113
- set: async (lamp: HeatLamp, action: "dayage",arg: any): Promise<any> => {
130
+ set: async (lamp: HeatLamp, action: "dayage", arg: any): Promise<any> => {
114
131
  var axios = await this.context.ready;
115
- var url = action === "dayage" ? "/api/v1/pigfarm/heatLamp/syncDayage" : `/api/v1/pigfarm/heatLamp/config/set`;
132
+ var url =
133
+ action === "dayage"
134
+ ? "/api/v1/pigfarm/heatLamp/syncDayage"
135
+ : `/api/v1/pigfarm/heatLamp/config/set`;
116
136
  var id = typeof lamp === "number" ? lamp : lamp.id;
117
- var body:{
118
- id: number,
119
- days?: number,
137
+ var body: {
138
+ id: number;
139
+ days?: number;
120
140
  } = {
121
- id
141
+ id,
122
142
  };
123
143
  switch (action) {
124
144
  case "dayage":
package/types.d.ts CHANGED
@@ -4,6 +4,7 @@ import { TransportGateway } from "@cpzxrobot/sdk/transport_gateway";
4
4
  import { UserGateway } from "@cpzxrobot/sdk/user_gateway";
5
5
  import { CameraGateway } from "@cpzxrobot/sdk/camera_gateway";
6
6
  import { PigfarmGateway } from "@cpzxrobot/sdk/pigfarm_gateway";
7
+ import { UnitGateway } from "@cpzxrobot/sdk//unit_gateway";
7
8
 
8
9
  type Device = {
9
10
  id: number;
@@ -95,10 +96,19 @@ type HeatLamp = {
95
96
  // 环境温度补偿值
96
97
  tempCompensation: number;
97
98
  periodList: {
98
- startTemp: number,
99
- startDayage: number,
100
- }[]
101
- }
99
+ startTemp: number;
100
+ startDayage: number;
101
+ }[];
102
+ };
103
+
104
+ //针对具有SN码的设备的统一配置
105
+ type DeviceConfig = {
106
+ id?: "";
107
+ unitId?: string;
108
+ serialNumber: string;
109
+ address?: string;
110
+ type?: string;
111
+ };
102
112
 
103
113
  type Electricity = {
104
114
  deviceId: string;
@@ -166,6 +176,7 @@ export class Cpzxrobot {
166
176
  transport: TransportGateway;
167
177
  ready: Promise<MyAxiosInstance>;
168
178
  factory: FactoryGateway;
179
+ unit: UnitGateway;
169
180
  user: UserGateway;
170
181
  device: DeviceGateway;
171
182
  mode: string;
@@ -177,9 +188,9 @@ export class Cpzxrobot {
177
188
  _getSelectedUnitFromMiniApp: () => Promise<Unit>;
178
189
  openMiniApp: (url: string) => void;
179
190
  on: (event: string, callback: (data: any) => void) => void;
180
- setTitle: (title: string) => void;
181
- saveBase64: (base64: string, filename: string) => void;
182
- saveBlob: (blob: Blob, filename: string) => void;
191
+ setTitle: (title: string) => void;
192
+ saveBase64: (base64: string, filename: string) => void;
193
+ saveBlob: (blob: Blob, filename: string) => void;
183
194
  }
184
195
 
185
196
  declare global {
@@ -226,5 +237,8 @@ declare module "@cpzxrobot/sdk" {
226
237
  Camera,
227
238
  FeedTowerExtraInfo,
228
239
  Electricity,
240
+ DeviceConfig,
241
+ DataQueryArgs,
242
+ HeatLamp
229
243
  };
230
244
  }
@@ -0,0 +1,53 @@
1
+ import { Cpzxrobot, Unit } from "./types";
2
+
3
+ export class UnitGateway extends Object {
4
+ context: Cpzxrobot;
5
+ constructor(context: Cpzxrobot) {
6
+ super();
7
+ this.context = context;
8
+ }
9
+ get config() {
10
+ return {
11
+ add: (
12
+ unit: Unit,
13
+ type: "heatLamp",
14
+ config: {
15
+ [key: string]: any;
16
+ }
17
+ ) => {
18
+ return this.context.ready.then((axios) => {
19
+ return axios.post(`/api/v2/unit/config/add`, {
20
+ unitId: unit.id,
21
+ type,
22
+ config,
23
+ });
24
+ });
25
+ },
26
+ update: (
27
+ unit: Unit,
28
+ type: "heatLamp",
29
+ config: {
30
+ [key: string]: any;
31
+ }
32
+ ) => {
33
+ return this.context.ready.then((axios) => {
34
+ return axios.post(`/api/v2/unit/config/update`, {
35
+ unitId: unit.id,
36
+ type,
37
+ config,
38
+ });
39
+ });
40
+ },
41
+ get: (unit: Unit, type: "heatLamp") => {
42
+ return this.context.ready.then((axios) => {
43
+ return axios.get(`/api/v2/unit/config`, {
44
+ params: {
45
+ unitId: unit.id,
46
+ type,
47
+ },
48
+ });
49
+ });
50
+ },
51
+ };
52
+ }
53
+ }