@cpzxrobot/sdk 1.0.4 → 1.0.5

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.
@@ -1,10 +1,12 @@
1
+ import { Cpzxrobot, FodderOrder } from ".";
2
+
1
3
  export class TransportGateway extends Object {
2
- _selectedFarm: string = ''
3
- context: Shzx
4
+ _selectedFarm: string = "";
5
+ context: Cpzxrobot;
4
6
 
5
- constructor(context: Shzx) {
6
- super()
7
- this.context = context
7
+ constructor(context: Cpzxrobot) {
8
+ super();
9
+ this.context = context;
8
10
  }
9
11
 
10
12
  get fodder() {
@@ -13,55 +15,70 @@ export class TransportGateway extends Object {
13
15
  getData: (
14
16
  id: number | undefined = undefined,
15
17
  page: {
16
- current: number
17
- pageSize: number
18
- deviceId: number | undefined
18
+ current: number;
19
+ pageSize: number;
20
+ deviceId: number | undefined;
19
21
  } = {
20
- current: 1,
21
- pageSize: 10,
22
- deviceId: id
23
- }
22
+ current: 1,
23
+ pageSize: 10,
24
+ deviceId: id,
25
+ }
24
26
  ): Promise<FodderOrder[]> => {
25
27
  return this.context.ready.then(() => {
26
28
  return this.context.axios
27
- .get('/api/v1/pigfarm/device/fodder', {
28
- params: page
29
+ .get("/api/v1/pigfarm/device/fodder", {
30
+ params: page,
29
31
  })
30
32
  .then((res) => {
31
33
  if (res.data.code != 200) {
32
- throw res.data.message
34
+ throw res.data.message;
33
35
  }
34
- return res.data.data.list
36
+ return res.data.data.list;
37
+ });
38
+ });
39
+ },
40
+ //获取设备打料数据
41
+ getDetail: (ids: Array<number>, date: string): Promise<any> => {
42
+ return this.context.ready.then(() => {
43
+ return this.context.axios
44
+ .post("/api/v1/pigfarm/device/fodderTower/detailDeviceLoad", {
45
+ ids,
46
+ date,
35
47
  })
36
- })
48
+ .then((res) => {
49
+ return res.data;
50
+ });
51
+ });
37
52
  },
38
53
  create: (data: FodderOrder) => {
39
54
  return this.context.ready.then(() => {
40
- return this.context.axios.post('/api/v1/pigfarm/device/fodder/add', data).then((res) => {
41
- if (res.data.code != 200) {
42
- throw res.data.message
43
- }
44
- return res.data.data
45
- })
46
- })
55
+ return this.context.axios
56
+ .post("/api/v1/pigfarm/device/fodder/add", data)
57
+ .then((res) => {
58
+ if (res.data.code != 200) {
59
+ throw res.data.message;
60
+ }
61
+ return res.data.data;
62
+ });
63
+ });
47
64
  },
48
65
  bind: (data: {
49
- deviceIds: number[]
50
- fodderType: string //料塔类型
51
- fodderAmount: number //料塔容量
52
- fodderId: number //料塔id,类 ZC2023 用于绑定料塔
66
+ deviceIds: number[];
67
+ fodderType: string; //料塔类型
68
+ fodderAmount: number; //料塔容量
69
+ fodderId: number; //料塔id,类 ZC2023 用于绑定料塔
53
70
  }) => {
54
71
  return this.context.ready.then(() => {
55
72
  return this.context.axios
56
- .post('/api/v1/pigfarm/device/fodderTower/addList', data)
73
+ .post("/api/v1/pigfarm/device/fodderTower/addList", data)
57
74
  .then((res) => {
58
75
  if (res.data.code != 200) {
59
- throw res.data.message
76
+ throw res.data.message;
60
77
  }
61
- return res.data.data
62
- })
63
- })
64
- }
65
- }
78
+ return res.data.data;
79
+ });
80
+ });
81
+ },
82
+ };
66
83
  }
67
84
  }
package/types.d.ts CHANGED
@@ -1,102 +1,182 @@
1
-
1
+ import { DeviceGateway } from "@cpzxrobot/sdk/device_gateway";
2
+ import { FactoryGateway } from "@cpzxrobot/sdk/factory_gateway";
3
+ import { TransportGateway } from "@cpzxrobot/sdk/transport_gateway";
4
+ import { UserGateway } from "@cpzxrobot/sdk/user_gateway";
2
5
 
3
6
  type Device = {
4
- id: number
5
- deviceId: string
6
- name: string
7
- type: number
8
- typeCode:string
9
- currentAmount: number
10
- location: string
11
- supplier?: string
12
- data?: number[]
13
- typeCode: string
14
- }
7
+ id: number;
8
+ deviceId: string;
9
+ name: string;
10
+ type: number;
11
+ typeCode: string;
12
+ currentAmount: number;
13
+ location: string;
14
+ supplier?: string;
15
+ data?: number[];
16
+ typeCode: string;
17
+ };
15
18
 
16
- type FeedTowerExtraInfo = {
17
- currentAmount: number
18
- loadAmount: number
19
- feedTowerAmount: number
20
- feedTowerCode: string
21
- id: number
22
- surplus_amount: number
23
- }
19
+ export type FeedTowerExtraInfo = {
20
+ currentAmount: number;
21
+ loadAmount: number;
22
+ feedTowerAmount: number;
23
+ feedTowerCode: string;
24
+ id: number;
25
+ surplus_amount: number;
26
+ };
24
27
 
25
- type FodderOrder = {
26
- id?: number
27
- fodderId?: string
28
- fodderAmount: number
29
- fodderCode: string
30
- createTime: string
31
- status: string
32
- fodderUnit: string
33
- truckCode?: string
34
- date?: string
35
- type?: string
36
- }
37
- //录入
38
- type FodderAdd = {
39
- car: string //车牌号
40
- date: string //日期
41
- source: string //来源
42
- factoryCode: string //当前工厂编号
43
- results: FodderUpdate[]
44
- }
45
- type FodderUpdate = {
46
- farm: string //工厂名称
47
- fodderCode: string //料号
48
- towers: Fodder[]
49
- }
28
+ //FodderOrder 料单信息
29
+ export type FodderOrder = {
30
+ id?: number;
31
+ fodderId?: string;
32
+ fodderAmount: number;
33
+ fodderCode: string;
34
+ createTime: string;
35
+ status: string;
36
+ fodderUnit: string;
37
+ truckCode?: string;
38
+ date?: string;
39
+ type?: string;
40
+ };
41
+ //
42
+ export type FodderOrderList = {
43
+ car: string; //车牌号
44
+ date: string; //日期
45
+ source: string; //来源
46
+ factoryCode: string; //当前工厂编号
47
+ results: FodderOrderInFactory[];
48
+ };
49
+ type FodderOrderInFactory = {
50
+ farm: string; //工厂名称
51
+ fodderCode: string; //料号
52
+ towers: FodderOrderInTower[];
53
+ };
50
54
 
51
- type Fodder = {
52
- name: string //料塔名称
53
- unit: string //单位
54
- weight: number //重量
55
- }
55
+ export type FodderOrderInTower = {
56
+ name: string; //料塔名称
57
+ unit: string; //单位
58
+ weight: number; //重量
59
+ };
56
60
 
57
- type Shzx = {
58
- user: UserGateway
59
- ready: Promise<MyAxiosInstance>
60
- axios: MyAxiosInstance
61
- _getSelectedFarmFromMiniApp: () => Promise<Factory>
62
- _getSelectedUnitFromMiniApp: () => Promise<Unit>
63
- mode: string
64
- }
65
61
  type Assistant = {
66
- info: String
67
- status: String
68
- name: String
69
- id: Number
70
- }
71
- type Factory = {
72
- code: string
73
- name?: string
74
- company_code: string
75
- id?: number
76
- }
62
+ info: String;
63
+ status: String;
64
+ name: String;
65
+ id: Number;
66
+ };
67
+ export type Factory = {
68
+ code: string;
69
+ name?: string;
70
+ company_code: string;
71
+ id?: number;
72
+ };
77
73
  type Unit = {
78
- name?: string
79
- id?: number
80
- type?: string
81
- workshopName?:string
82
- }
74
+ name?: string;
75
+ id?: number;
76
+ type?: string;
77
+ workshopName?: string;
78
+ };
83
79
 
84
80
  type Electricity = {
85
- deviceId: string
86
- nextDeviceList: number[] | []
87
- power: number
88
- }
81
+ deviceId: string;
82
+ nextDeviceList: number[] | [];
83
+ power: number;
84
+ };
89
85
 
90
86
  type Camera = {
91
- id: number
92
- name: string
87
+ id: number;
88
+ name: string;
89
+ };
90
+
91
+ export type FeedTower = {
92
+ id: number;
93
+ name: string;
94
+ currentAmount: number;
95
+ lastZeroTime: string;
96
+ cycle?: number;
97
+ "pg.feedtower.status"?: string;
98
+ "pg.feedtower.near-zero"?: string;
99
+ deviation: number;
100
+ towerVolume: number;
101
+ unit: string;
102
+ unitId: number;
103
+ deviceId: number;
104
+ fodderUnit: string;
105
+ fodderCode: string;
106
+ diff: number;
107
+ };
108
+
109
+ export interface MyAxiosInstance {
110
+ get: (url: string, config?: any) => Promise<any>;
111
+ post: (url: string, data?: any, config?: any) => Promise<any>;
93
112
  }
94
113
 
95
- interface MyAxiosInstance {
96
- get: (url: string, config?: any) => Promise<any>
97
- post: (url: string, data?: any, config?: any) => Promise<any>
114
+ export interface Assistant {
115
+ info: String;
116
+ status: Number;
117
+ name: String;
118
+ id: Number;
119
+ }
120
+ export interface ElectricMeter extends Device {
121
+ coefficient: number;
122
+ status: string;
123
+ }
124
+
125
+ export class Cpzxrobot {
126
+ transport: TransportGateway;
127
+ ready: Promise<MyAxiosInstance>;
128
+ factory: FactoryGateway;
129
+ user: UserGateway;
130
+ device: DeviceGateway;
131
+ mode: string;
132
+ axios: MyAxiosInstance;
133
+ _getSelectedFarmFromMiniApp: () => Promise<Factory>;
134
+ _getSelectedUnitFromMiniApp: () => Promise<Unit>;
98
135
  }
99
136
 
100
137
  declare global {
101
- let getAuth: () => string
138
+ let getAuth: () => string;
139
+ }
140
+
141
+ declare module "@cpzxrobot/sdk" {
142
+ export default function (
143
+ args: {
144
+ devAuth: string;
145
+ baseURL: string;
146
+ appCode: string;
147
+ selectedFarm: Factory;
148
+ selectedUnit: Unit;
149
+ } = {
150
+ devAuth: "",
151
+ appCode: "",
152
+ baseURL: "https://www.cpzxrobot.com/",
153
+ selectedFarm: {
154
+ id: 0,
155
+ code: "",
156
+ name: "",
157
+ company_code: "",
158
+ },
159
+ selectedUnit: {
160
+ id: 0,
161
+ name: "",
162
+ },
163
+ }
164
+ ): Cpzxrobot;
165
+ export {
166
+ Cpzxrobot,
167
+ Factory,
168
+ Unit,
169
+ Device,
170
+ FeedTower,
171
+ FodderOrder,
172
+ FodderOrderList,
173
+ FodderOrderInFactory,
174
+ FodderOrderInTower,
175
+ MyAxiosInstance,
176
+ Assistant,
177
+ ElectricMeter,
178
+ Camera,
179
+ FeedTowerExtraInfo,
180
+ Electricity,
181
+ };
102
182
  }
package/user_gateway.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { Cpzxrobot, Factory, Unit } from "./types";
2
+
1
3
  export class UserGateway extends Object {
2
4
  _selectedFarm: Factory = {
3
5
  code: "",
@@ -5,19 +7,19 @@ export class UserGateway extends Object {
5
7
  company_code: "",
6
8
  id: 0,
7
9
  };
8
- context: Shzx;
10
+ context: Cpzxrobot;
9
11
  _selectedUnit: Unit = {
10
12
  name: "",
11
13
  id: 0,
12
14
  };
13
15
 
14
- constructor(context: Shzx) {
16
+ constructor(context: Cpzxrobot) {
15
17
  super();
16
18
  this.context = context;
17
19
  }
18
20
 
19
21
  //获得当前用户选择的工厂
20
- getSelectedFarm() {
22
+ public getSelectedFarm(): Promise<Factory> {
21
23
  return new Promise<Factory>((resolve, reject) => {
22
24
  switch (this.context.mode) {
23
25
  case "dev":