@cpzxrobot/sdk 1.0.3 → 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,7 +1,9 @@
1
+ import { Cpzxrobot } from "."
2
+
1
3
  //消息助手网关,获取消息助手的信息
2
4
  export class AssistantGateway extends Object {
3
- context: Shzx
4
- constructor(context: Shzx) {
5
+ context: Cpzxrobot
6
+ constructor(context: Cpzxrobot) {
5
7
  super()
6
8
  this.context = context
7
9
  }
package/camera_gateway.ts CHANGED
@@ -1,28 +1,32 @@
1
+ import { Cpzxrobot, Unit, Camera } from ".";
2
+
1
3
  export class CameraGateway extends Object {
2
- context: Shzx
3
- constructor(context: Shzx) {
4
- super()
5
- this.context = context
4
+ context: Cpzxrobot;
5
+ constructor(context: Cpzxrobot) {
6
+ super();
7
+ this.context = context;
6
8
  }
7
9
  //搜索摄像头
8
10
  async search(data: Unit): Promise<any> {
9
- await this.context.ready
10
- const response = await this.context.axios.post('/api/v1/camera/search', {
11
- unit_id: data.id
12
- })
13
- return response.data
11
+ await this.context.ready;
12
+ const response = await this.context.axios.post("/api/v1/camera/search", {
13
+ unit_id: data.id,
14
+ });
15
+ return response.data;
14
16
  }
15
17
 
16
18
  //获得摄像头的播放地址
17
19
  async getUrl(data: Camera): Promise<any> {
18
- await this.context.ready
19
- const response = await this.context.axios.get(`/api/v1/camera/${data.id}/url/wss`)
20
- return response.data
20
+ await this.context.ready;
21
+ const response = await this.context.axios.get(
22
+ `/api/v1/camera/${data.id}/url/wss`
23
+ );
24
+ return response.data;
21
25
  }
22
26
  //获取工厂天气
23
27
  async weather(id: number): Promise<any> {
24
- await this.context.ready
25
- const response = await this.context.axios.get(`/api/v1/weather?code=${id}`)
26
- return response.data
28
+ await this.context.ready;
29
+ const response = await this.context.axios.get(`/api/v1/weather?code=${id}`);
30
+ return response.data;
27
31
  }
28
32
  }
package/device_filter.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Cpzxrobot } from ".";
1
2
  import type { AxiosResponse } from "axios";
2
3
 
3
4
  export interface DataQueryArgs {
@@ -14,8 +15,8 @@ export interface DataQueryArgs {
14
15
  [key: string]: any;
15
16
  }
16
17
 
17
- export abstract class deviceFilter<T extends { id: number }> {
18
- context: Shzx;
18
+ export abstract class DeviceFilter<T extends { id: number }> {
19
+ context: Cpzxrobot;
19
20
  protected devices: T[] = [];
20
21
 
21
22
  // private getDetail!: (info: T, id: number, context: Shzx) => Promise<any> | null
@@ -23,7 +24,7 @@ export abstract class deviceFilter<T extends { id: number }> {
23
24
  // user: UserGateway;
24
25
  // ready: Promise<boolean>;
25
26
 
26
- constructor(context: Shzx) {
27
+ constructor(context: Cpzxrobot) {
27
28
  this.context = context;
28
29
  }
29
30
 
@@ -62,7 +63,7 @@ export abstract class deviceFilter<T extends { id: number }> {
62
63
 
63
64
  //获得单个设备的详细信息和状态,包括设备的基本信息和跟业务类型相关的附加状态信息
64
65
  //不应单独使用getInfo和getDetail,应使用getStatus
65
- getStatus(id: number) {
66
+ getStatus(id: number): Promise<any> {
66
67
  return this.context.ready
67
68
  .then(() => this.getInfo(id))
68
69
  .then((info) => {
@@ -275,6 +276,7 @@ export abstract class deviceFilter<T extends { id: number }> {
275
276
  | null; //如果data为null,则不获取数据,只获取设备列表,否则获取设备列表和数据
276
277
  status?: string;
277
278
  unit?: Number;
279
+ detail?: boolean;
278
280
  } = undefined
279
281
  ): Promise<T[]> {
280
282
  // if (this.devices.length > 0) {
package/device_gateway.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DeviceTypeGateway } from "./device_type_gateway";
2
- import { deviceFilter } from "./device_filter";
3
- import type { FeedTower, ElectricMeter } from ".";
2
+ import { DeviceFilter } from "./device_filter";
3
+ import type { ElectricMeter, Cpzxrobot } from ".";
4
4
  import { FeedTowerGateway } from "./device_types/feedtower";
5
5
  import { ElectricMeterGateway } from "./device_types/electricmeter";
6
6
  import { NormalGateway } from "./device_types/normal_type";
@@ -12,11 +12,11 @@ import { NormalGateway } from "./device_types/normal_type";
12
12
  export class DeviceGateway extends Object {
13
13
  // private devices: Device[]
14
14
  public type: DeviceTypeGateway;
15
- filters: Map<string, deviceFilter<any>>;
16
- normalFilter: NormalGateway;
17
- context: Shzx;
15
+ filters: Map<string, DeviceFilter<any>>;
16
+ public normalFilter: NormalGateway;
17
+ context: Cpzxrobot;
18
18
 
19
- constructor(context: Shzx) {
19
+ constructor(context: Cpzxrobot) {
20
20
  super();
21
21
  this.context = context;
22
22
  // this.devices = []
@@ -26,21 +26,21 @@ export class DeviceGateway extends Object {
26
26
  }
27
27
 
28
28
  //料塔设备的数据获取网关
29
- get feedTower(): deviceFilter<FeedTower> {
30
- return this.getFilter("FeedTower", FeedTowerGateway);
29
+ public get feedTower(): FeedTowerGateway {
30
+ return this.getFilter("FeedTower", FeedTowerGateway) as FeedTowerGateway;
31
31
  }
32
32
 
33
33
  //电表设备的数据获取网关
34
- get electricMeter(): deviceFilter<ElectricMeter> {
34
+ get electricMeter(): DeviceFilter<ElectricMeter> {
35
35
  return this.getFilter("ElectricMeter", ElectricMeterGateway);
36
36
  }
37
37
 
38
38
  private getFilter<T extends { id: number }>(
39
39
  type: string,
40
- cls: new (context: Shzx) => deviceFilter<T>
41
- ): deviceFilter<T> {
40
+ cls: new (context: Cpzxrobot) => DeviceFilter<T>
41
+ ): DeviceFilter<T> {
42
42
  if (this.filters.has(type)) {
43
- return this.filters.get(type) as deviceFilter<T>;
43
+ return this.filters.get(type) as DeviceFilter<T>;
44
44
  }
45
45
  const filter = new cls(this.context);
46
46
  this.filters.set(type, filter);
@@ -1,10 +1,12 @@
1
+ import { Cpzxrobot, Unit } from "."
2
+
1
3
  //缓存设备类型数据
2
4
  export class DeviceTypeGateway {
3
5
  deviceTypes: any
4
6
  // axios: MyAxiosInstance;
5
- context: Shzx
7
+ context: Cpzxrobot
6
8
 
7
- constructor(context: Shzx) {
9
+ constructor(context: Cpzxrobot) {
8
10
  this.context = context
9
11
  }
10
12
 
@@ -1,7 +1,7 @@
1
1
  import { type ElectricMeter } from "..";
2
- import { deviceFilter } from "../device_filter";
2
+ import { DeviceFilter } from "../device_filter";
3
3
 
4
- export class ElectricMeterGateway extends deviceFilter<ElectricMeter> {
4
+ export class ElectricMeterGateway extends DeviceFilter<ElectricMeter> {
5
5
  // Add properties and methods specific to the FeedTower type here
6
6
 
7
7
  get deviceType() {
@@ -1,7 +1,7 @@
1
- import { type FeedTower } from '..'
2
- import { deviceFilter, type DataQueryArgs } from '../device_filter'
1
+ import { type FodderOrderList, type FeedTower,type FeedTowerExtraInfo } from '..'
2
+ import { DeviceFilter, type DataQueryArgs } from '../device_filter'
3
3
 
4
- export class FeedTowerGateway extends deviceFilter<FeedTower> {
4
+ export class FeedTowerGateway extends DeviceFilter<FeedTower> {
5
5
  // Add properties and methods specific to the FeedTower type here
6
6
 
7
7
  get deviceType() {
@@ -50,7 +50,7 @@ export class FeedTowerGateway extends deviceFilter<FeedTower> {
50
50
  //TODO 其他设备的详情需要支持,目前只有喂料塔
51
51
  return this.context.axios
52
52
  .post('/api/v1/pigfarm/device/status/list', ids)
53
- .then((res) => {
53
+ .then((res:any) => {
54
54
  if (res.data.code != 200) {
55
55
  throw res.data.message
56
56
  } else {
@@ -66,7 +66,7 @@ export class FeedTowerGateway extends deviceFilter<FeedTower> {
66
66
  }
67
67
 
68
68
 
69
- async enter(data: FodderAdd): Promise<any> {
69
+ async enter(data: FodderOrderList): Promise<any> {
70
70
  const res = await this.context.axios.post('/api/v1/pigfarm/device/fodder/import', data)
71
71
  return res
72
72
  }
@@ -1,7 +1,8 @@
1
- import { deviceFilter } from "../device_filter";
1
+ import { Device } from "..";
2
+ import { DeviceFilter } from "../device_filter";
2
3
 
3
4
  //适配常见设备类型
4
- export class NormalGateway extends deviceFilter<Device> {
5
+ export class NormalGateway extends DeviceFilter<Device> {
5
6
  get deviceType() {
6
7
  return null;
7
8
  }
@@ -9,8 +9,8 @@ class CameraGateway extends Object {
9
9
  //搜索摄像头
10
10
  async search(data) {
11
11
  await this.context.ready;
12
- const response = await this.context.axios.post('/api/v1/camera/search', {
13
- unit_id: data.id
12
+ const response = await this.context.axios.post("/api/v1/camera/search", {
13
+ unit_id: data.id,
14
14
  });
15
15
  return response.data;
16
16
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deviceFilter = void 0;
4
- class deviceFilter {
3
+ exports.DeviceFilter = void 0;
4
+ class DeviceFilter {
5
5
  // private getDetail!: (info: T, id: number, context: Shzx) => Promise<any> | null
6
6
  // axios: MyAxiosInstance;
7
7
  // user: UserGateway;
@@ -250,4 +250,4 @@ class deviceFilter {
250
250
  });
251
251
  }
252
252
  }
253
- exports.deviceFilter = deviceFilter;
253
+ exports.DeviceFilter = DeviceFilter;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ElectricMeterGateway = void 0;
4
4
  const device_filter_1 = require("../device_filter");
5
- class ElectricMeterGateway extends device_filter_1.deviceFilter {
5
+ class ElectricMeterGateway extends device_filter_1.DeviceFilter {
6
6
  // Add properties and methods specific to the FeedTower type here
7
7
  get deviceType() {
8
8
  return "Electric";
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FeedTowerGateway = void 0;
4
4
  const device_filter_1 = require("../device_filter");
5
- class FeedTowerGateway extends device_filter_1.deviceFilter {
5
+ class FeedTowerGateway extends device_filter_1.DeviceFilter {
6
6
  // Add properties and methods specific to the FeedTower type here
7
7
  get deviceType() {
8
8
  return 'FeedTower';
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NormalGateway = void 0;
4
4
  const device_filter_1 = require("../device_filter");
5
5
  //适配常见设备类型
6
- class NormalGateway extends device_filter_1.deviceFilter {
6
+ class NormalGateway extends device_filter_1.DeviceFilter {
7
7
  get deviceType() {
8
8
  return null;
9
9
  }
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.ElectricMeterGateway = void 0;
7
- const __1 = __importDefault(require(".."));
8
4
  //消息助手网关,获取消息助手的信息
9
5
  class ElectricMeterGateway extends Object {
10
6
  constructor(context) {
@@ -13,7 +9,7 @@ class ElectricMeterGateway extends Object {
13
9
  }
14
10
  //返回峰谷平电表的阶梯区间
15
11
  getRates() {
16
- return (0, __1.default)().ready.then((axios) => {
12
+ return this.context.ready.then((axios) => {
17
13
  return axios.get('/api/v1/energy/electricRange').then((res) => {
18
14
  if (res.data.code !== 200) {
19
15
  throw res.data.message;
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Cpzxrobot = void 0;
6
7
  exports.default = default_1;
7
8
  const device_gateway_1 = require("./device_gateway");
8
9
  const user_gateway_1 = require("./user_gateway");
@@ -13,7 +14,7 @@ const assistant_gateway_1 = require("./assistant_gateway");
13
14
  const energy_gateway_1 = require("./energy_gateway");
14
15
  const camera_gateway_1 = require("./camera_gateway");
15
16
  const pigfarm_gateway_1 = require("./pigfarm_gateway");
16
- class shzx {
17
+ class Cpzxrobot {
17
18
  constructor(appCode) {
18
19
  this.pigfarm = new pigfarm_gateway_1.PigfarmGateway(this);
19
20
  this.hash = "shzx";
@@ -186,6 +187,7 @@ class shzx {
186
187
  return localDomains.includes(domain);
187
188
  }
188
189
  }
190
+ exports.Cpzxrobot = Cpzxrobot;
189
191
  let _instance;
190
192
  function default_1(args = {
191
193
  devAuth: "",
@@ -203,7 +205,7 @@ function default_1(args = {
203
205
  },
204
206
  }) {
205
207
  if (!_instance) {
206
- _instance = new shzx(args.appCode);
208
+ _instance = new Cpzxrobot(args.appCode);
207
209
  _instance.setAuth(args.devAuth, args.baseURL);
208
210
  if (args.selectedFarm) {
209
211
  _instance.user.selectedFarm = args.selectedFarm;
@@ -4,7 +4,7 @@ exports.TransportGateway = void 0;
4
4
  class TransportGateway extends Object {
5
5
  constructor(context) {
6
6
  super();
7
- this._selectedFarm = '';
7
+ this._selectedFarm = "";
8
8
  this.context = context;
9
9
  }
10
10
  get fodder() {
@@ -13,12 +13,12 @@ class TransportGateway extends Object {
13
13
  getData: (id = undefined, page = {
14
14
  current: 1,
15
15
  pageSize: 10,
16
- deviceId: id
16
+ deviceId: id,
17
17
  }) => {
18
18
  return this.context.ready.then(() => {
19
19
  return this.context.axios
20
- .get('/api/v1/pigfarm/device/fodder', {
21
- params: page
20
+ .get("/api/v1/pigfarm/device/fodder", {
21
+ params: page,
22
22
  })
23
23
  .then((res) => {
24
24
  if (res.data.code != 200) {
@@ -28,9 +28,24 @@ class TransportGateway extends Object {
28
28
  });
29
29
  });
30
30
  },
31
+ //获取设备打料数据
32
+ getDetail: (ids, date) => {
33
+ return this.context.ready.then(() => {
34
+ return this.context.axios
35
+ .post("/api/v1/pigfarm/device/fodderTower/detailDeviceLoad", {
36
+ ids,
37
+ date,
38
+ })
39
+ .then((res) => {
40
+ return res.data;
41
+ });
42
+ });
43
+ },
31
44
  create: (data) => {
32
45
  return this.context.ready.then(() => {
33
- return this.context.axios.post('/api/v1/pigfarm/device/fodder/add', data).then((res) => {
46
+ return this.context.axios
47
+ .post("/api/v1/pigfarm/device/fodder/add", data)
48
+ .then((res) => {
34
49
  if (res.data.code != 200) {
35
50
  throw res.data.message;
36
51
  }
@@ -41,7 +56,7 @@ class TransportGateway extends Object {
41
56
  bind: (data) => {
42
57
  return this.context.ready.then(() => {
43
58
  return this.context.axios
44
- .post('/api/v1/pigfarm/device/fodderTower/addList', data)
59
+ .post("/api/v1/pigfarm/device/fodderTower/addList", data)
45
60
  .then((res) => {
46
61
  if (res.data.code != 200) {
47
62
  throw res.data.message;
@@ -49,7 +64,7 @@ class TransportGateway extends Object {
49
64
  return res.data.data;
50
65
  });
51
66
  });
52
- }
67
+ },
53
68
  };
54
69
  }
55
70
  }
package/energy_gateway.ts CHANGED
@@ -1,10 +1,11 @@
1
+ import { Cpzxrobot } from ".";
1
2
  import { ElectricMeterGateway } from "./energy_types/electric_meter_gateway";
2
3
  //消息助手网关,获取消息助手的信息
3
4
  export class EnergyGateway extends Object {
4
- context: Shzx;
5
+ context: Cpzxrobot;
5
6
  _electric: ElectricMeterGateway | null = null;
6
7
 
7
- constructor(context: Shzx) {
8
+ constructor(context: Cpzxrobot) {
8
9
  super();
9
10
  this.context = context;
10
11
  }
@@ -1,4 +1,4 @@
1
- import shzx from ".."
1
+ import { type Cpzxrobot } from "..";
2
2
 
3
3
  export interface ElectricMeterRate {
4
4
  endHour: number;
@@ -12,16 +12,16 @@ export interface ElectricMeterRate {
12
12
 
13
13
  //消息助手网关,获取消息助手的信息
14
14
  export class ElectricMeterGateway extends Object {
15
- context: Shzx
15
+ context: Cpzxrobot
16
16
 
17
- constructor(context: Shzx) {
17
+ constructor(context: Cpzxrobot) {
18
18
  super()
19
19
  this.context = context
20
20
  }
21
21
 
22
22
  //返回峰谷平电表的阶梯区间
23
23
  getRates() {
24
- return shzx().ready.then((axios) => {
24
+ return this.context.ready.then((axios) => {
25
25
  return axios.get('/api/v1/energy/electricRange').then((res) => {
26
26
  if (res.data.code !== 200) {
27
27
  throw res.data.message
@@ -1,3 +1,5 @@
1
+ import { Cpzxrobot, Factory } from "./types"
2
+
1
3
  export class FactoryGateway extends Object {
2
4
  _selectedFarm: Factory = {
3
5
  code: '',
@@ -5,8 +7,8 @@ export class FactoryGateway extends Object {
5
7
  company_code: '',
6
8
  id: 0
7
9
  }
8
- context: Shzx
9
- constructor(context: Shzx) {
10
+ context: Cpzxrobot
11
+ constructor(context: Cpzxrobot) {
10
12
  super()
11
13
  this.context = context
12
14
  }
package/index.ts CHANGED
@@ -8,8 +8,9 @@ import { EnergyGateway } from "./energy_gateway";
8
8
  import { CameraGateway } from "./camera_gateway";
9
9
  import { type ElectricMeterRate } from "./energy_types/electric_meter_gateway";
10
10
  import { PigfarmGateway } from "./pigfarm_gateway";
11
+ import { Device, Factory, MyAxiosInstance, Unit } from "./types";
11
12
 
12
- class shzx {
13
+ export class Cpzxrobot {
13
14
  device: DeviceGateway;
14
15
  pigfarm: PigfarmGateway = new PigfarmGateway(this);
15
16
  public hash = "shzx";
@@ -220,7 +221,7 @@ class shzx {
220
221
  }
221
222
  }
222
223
 
223
- let _instance!: shzx;
224
+ let _instance!: Cpzxrobot;
224
225
 
225
226
  export default function (
226
227
  args: {
@@ -244,9 +245,9 @@ export default function (
244
245
  name: "",
245
246
  },
246
247
  }
247
- ): shzx {
248
+ ): Cpzxrobot {
248
249
  if (!_instance) {
249
- _instance = new shzx(args.appCode);
250
+ _instance = new Cpzxrobot(args.appCode);
250
251
  _instance.setAuth(args.devAuth,args.baseURL);
251
252
  if (args.selectedFarm) {
252
253
  _instance.user.selectedFarm = args.selectedFarm;
@@ -257,29 +258,5 @@ export default function (
257
258
  }
258
259
  return _instance;
259
260
  }
260
- export interface FeedTower {
261
- id: number;
262
- name: string;
263
- currentAmount: number;
264
- lastZeroTime: string;
265
- cycle?: number;
266
- "pg.feedtower.status"?: string;
267
- "pg.feedtower.near-zero"?: string;
268
- deviation: number;
269
- towerVolume: number;
270
- unit: string;
271
- deviceId: number;
272
- fodderUnit: string;
273
- fodderCode: string;
274
- }
275
- export interface Assistant {
276
- info: String;
277
- status: Number;
278
- name: String;
279
- id: Number;
280
- }
281
- export interface ElectricMeter extends Device {
282
- coefficient: number;
283
- status: string;
284
- }
261
+
285
262
  export { type ElectricMeterRate };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -14,5 +14,7 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "axios": "^1.7.2"
17
- }
17
+ },
18
+ "types": "types.d.ts",
19
+ "typings": "types.d.ts"
18
20
  }
@@ -1,6 +1,8 @@
1
+ import { Cpzxrobot, Unit } from ".";
2
+
1
3
  export class PigfarmGateway extends Object {
2
- context: Shzx
3
- constructor(context: Shzx) {
4
+ context: Cpzxrobot
5
+ constructor(context: Cpzxrobot) {
4
6
  super()
5
7
  this.context = context
6
8
  }
package/readme.md CHANGED
@@ -85,7 +85,7 @@ factory_id: 工厂id
85
85
 
86
86
  ### 摄像头相关
87
87
 
88
- cpzxrobot().camera.search(args)
88
+ `cpzxrobot().camera.search(args)`
89
89
 
90
90
  搜索摄像头
91
91
 
@@ -96,3 +96,14 @@ cpzxrobot().camera.search(args)
96
96
  如果入参为:{unit_id:xxx}则按单元搜索
97
97
 
98
98
  如果入参为:{factory_id:xxx}则按工厂搜索
99
+
100
+ ### app功能相关
101
+
102
+ `cpzxrobot().saveBlob(blob,filname)`
103
+
104
+ 保存blob为文件
105
+
106
+
107
+ `cpzxrobot().saveBase64(base64,filename)`
108
+
109
+ 保存Base64内容为文件
@@ -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":