@cpzxrobot/sdk 1.3.21 → 1.3.23

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.
@@ -11,53 +11,45 @@ class ProductionGateway extends Object {
11
11
  * 添加产品类型
12
12
  * @param productName 产品名称
13
13
  */
14
- async addType(productName) {
14
+ async add(productName) {
15
15
  const axios = await this.context.ready;
16
+ const factory = await this.context.user.getSelectedFarm();
16
17
  return axios.post('/api/v3/production/add', {
17
- product_name: productName
18
+ product_name: productName,
19
+ factory_id: factory.id
18
20
  });
19
21
  }
20
22
  /**
21
23
  * 获取所有产品类型列表
22
24
  */
23
- async listTypes() {
25
+ async list() {
24
26
  const axios = await this.context.ready;
25
- return axios.get('/api/v3/production/list');
27
+ const factory = await this.context.user.getSelectedFarm();
28
+ return axios.get(`/api/v3/production/list/${factory.id}`);
26
29
  }
27
- /**
28
- * 录入产量统计数据
29
- * @param request 统计请求参数
30
- */
31
- async createStat(request) {
32
- if (!request.factory_id) {
33
- const factory = await this.context.user.getSelectedFarm();
34
- request.factory_id = factory.id;
35
- }
36
- const axios = await this.context.ready;
37
- return axios.post('/api/v3/production/stat', {
38
- factory_id: request.factory_id,
39
- time: request.time.toISOString(),
40
- period: request.period,
41
- products: request.products
42
- });
43
- }
44
- /**
45
- * 查询产量统计数据
46
- * @param period 统计周期(month|quater|year)
47
- * @param factoryId 工厂ID
48
- */
49
- async getStats(period, factoryId) {
50
- if (!factoryId) {
51
- const factory = await this.context.user.getSelectedFarm();
52
- factoryId = factory.id;
53
- }
54
- const axios = await this.context.ready;
55
- return axios.get('/api/v3/production/stat', {
56
- params: {
57
- period,
58
- factory_id: factoryId
30
+ get stat() {
31
+ return {
32
+ get: async (type, period, factoryId) => {
33
+ if (!factoryId) {
34
+ const factory = await this.context.user.getSelectedFarm();
35
+ factoryId = factory.id;
36
+ }
37
+ const axios = await this.context.ready;
38
+ return axios.get(`/api/v3/production/stat/${type}/${period}`, {
39
+ params: {
40
+ factory_id: factoryId
41
+ }
42
+ });
43
+ },
44
+ create: async (request) => {
45
+ if (!request.factory_id) {
46
+ const factory = await this.context.user.getSelectedFarm();
47
+ request.factory_id = factory.id;
48
+ }
49
+ const axios = await this.context.ready;
50
+ return axios.post('/api/v3/production/stat', request);
59
51
  }
60
- });
52
+ };
61
53
  }
62
54
  }
63
55
  exports.ProductionGateway = ProductionGateway;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.3.21",
3
+ "version": "1.3.23",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -13,63 +13,57 @@ export class ProductionGateway extends Object {
13
13
  * 添加产品类型
14
14
  * @param productName 产品名称
15
15
  */
16
- async addType(productName: string): Promise<{ code: number; message: string }> {
16
+ async add(productName: string): Promise<{ code: number; message: string }> {
17
17
  const axios = await this.context.ready;
18
+ const factory = await this.context.user.getSelectedFarm();
18
19
  return axios.post('/api/v3/production/add', {
19
- product_name: productName
20
+ product_name: productName,
21
+ factory_id: factory.id
20
22
  });
21
23
  }
22
24
 
23
25
  /**
24
26
  * 获取所有产品类型列表
25
27
  */
26
- async listTypes(): Promise<{ types: Production[] }> {
28
+ async list(): Promise<{ types: Production[] }> {
27
29
  const axios = await this.context.ready;
28
- return axios.get('/api/v3/production/list');
30
+ const factory = await this.context.user.getSelectedFarm();
31
+ return axios.get(`/api/v3/production/list/${factory.id}`);
29
32
  }
30
33
 
31
- /**
32
- * 录入产量统计数据
33
- * @param request 统计请求参数
34
- */
35
- async createStat(request: {
36
- factory_id?: number;
37
- time: Date;
38
- period: number; // 1:月度, 2:季度, 3:年度
39
- products: Record<number, number>; // 产品名称到产量的映射
40
- }): Promise<void> {
41
- if (!request.factory_id) {
42
- const factory = await this.context.user.getSelectedFarm();
43
- request.factory_id = factory.id;
34
+ get stat() {
35
+ return {
36
+ get: async (
37
+ type: 'sale' | 'order' | 'production',
38
+ period: 'month' | 'quater' | 'year', factoryId?: number): Promise<Array<{
39
+ time: string;
40
+ products: Record<number, number>;
41
+ }>> => {
42
+ if (!factoryId) {
43
+ const factory = await this.context.user.getSelectedFarm();
44
+ factoryId = factory.id;
45
+ }
46
+ const axios = await this.context.ready;
47
+ return axios.get(`/api/v3/production/stat/${type}/${period}`, {
48
+ params: {
49
+ factory_id: factoryId
50
+ }
51
+ });
52
+ },
53
+ create: async (request: {
54
+ factory_id?: number;
55
+ time: Date;
56
+ period: number; // 1:月度, 2:季度, 3:年度
57
+ products: Record<number, number>; // 产品名称到产量的映射
58
+ }) => {
59
+ if (!request.factory_id) {
60
+ const factory = await this.context.user.getSelectedFarm();
61
+ request.factory_id = factory.id;
62
+ }
63
+ const axios = await this.context.ready;
64
+ return axios.post('/api/v3/production/stat', request);
65
+ }
44
66
  }
45
- const axios = await this.context.ready;
46
- return axios.post('/api/v3/production/stat', {
47
- factory_id: request.factory_id,
48
- time: request.time.toISOString(),
49
- period: request.period,
50
- products: request.products
51
- });
52
67
  }
53
68
 
54
- /**
55
- * 查询产量统计数据
56
- * @param period 统计周期(month|quater|year)
57
- * @param factoryId 工厂ID
58
- */
59
- async getStats(period: 'month' | 'quater' | 'year', factoryId?: number): Promise<Array<{
60
- time: string;
61
- products: Record<number, number>;
62
- }>> {
63
- if (!factoryId) {
64
- const factory = await this.context.user.getSelectedFarm();
65
- factoryId = factory.id;
66
- }
67
- const axios = await this.context.ready;
68
- return axios.get('/api/v3/production/stat', {
69
- params: {
70
- period,
71
- factory_id: factoryId
72
- }
73
- });
74
- }
75
69
  }