@newpeak/barista-cli 0.1.8 → 0.1.9
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/README.md +10 -10
- package/dist/commands/liberica/index.d.ts.map +1 -1
- package/dist/commands/liberica/index.js +2 -0
- package/dist/commands/liberica/index.js.map +1 -1
- package/dist/commands/liberica/materials/create.d.ts.map +1 -1
- package/dist/commands/liberica/materials/create.js +13 -6
- package/dist/commands/liberica/materials/create.js.map +1 -1
- package/dist/commands/liberica/materials/update.js +1 -1
- package/dist/commands/liberica/materials/update.js.map +1 -1
- package/dist/commands/liberica/mould/get.d.ts +3 -0
- package/dist/commands/liberica/mould/get.d.ts.map +1 -0
- package/dist/commands/liberica/mould/get.js +90 -0
- package/dist/commands/liberica/mould/get.js.map +1 -0
- package/dist/commands/liberica/mould/index.d.ts +3 -0
- package/dist/commands/liberica/mould/index.d.ts.map +1 -0
- package/dist/commands/liberica/mould/index.js +15 -0
- package/dist/commands/liberica/mould/index.js.map +1 -0
- package/dist/commands/liberica/mould/list.d.ts +3 -0
- package/dist/commands/liberica/mould/list.d.ts.map +1 -0
- package/dist/commands/liberica/mould/list.js +114 -0
- package/dist/commands/liberica/mould/list.js.map +1 -0
- package/dist/commands/liberica/mould/set-status.d.ts +3 -0
- package/dist/commands/liberica/mould/set-status.d.ts.map +1 -0
- package/dist/commands/liberica/mould/set-status.js +84 -0
- package/dist/commands/liberica/mould/set-status.js.map +1 -0
- package/dist/commands/liberica/mould/stock-in.d.ts +3 -0
- package/dist/commands/liberica/mould/stock-in.d.ts.map +1 -0
- package/dist/commands/liberica/mould/stock-in.js +160 -0
- package/dist/commands/liberica/mould/stock-in.js.map +1 -0
- package/dist/core/api/client.d.ts +17 -0
- package/dist/core/api/client.d.ts.map +1 -1
- package/dist/core/api/client.js +172 -0
- package/dist/core/api/client.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/material.d.ts +1 -1
- package/dist/types/material.d.ts.map +1 -1
- package/dist/types/mould-stock-in.d.ts +70 -0
- package/dist/types/mould-stock-in.d.ts.map +1 -0
- package/dist/types/mould-stock-in.js +3 -0
- package/dist/types/mould-stock-in.js.map +1 -0
- package/dist/types/mould.d.ts +61 -0
- package/dist/types/mould.d.ts.map +1 -0
- package/dist/types/mould.js +2 -0
- package/dist/types/mould.js.map +1 -0
- package/package.json +1 -1
- package/src/commands/liberica/index.ts +2 -0
- package/src/commands/liberica/materials/create.ts +13 -5
- package/src/commands/liberica/materials/update.ts +1 -1
- package/src/commands/liberica/mould/get.ts +111 -0
- package/src/commands/liberica/mould/index.ts +17 -0
- package/src/commands/liberica/mould/list.ts +157 -0
- package/src/commands/liberica/mould/set-status.ts +99 -0
- package/src/commands/liberica/mould/stock-in.ts +165 -0
- package/src/core/api/client.ts +202 -0
- package/src/index.ts +1 -1
- package/src/types/index.ts +2 -0
- package/src/types/material.ts +1 -1
- package/src/types/mould-stock-in.ts +82 -0
- package/src/types/mould.ts +74 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mould-stock-in.js","sourceRoot":"","sources":["../../src/types/mould-stock-in.ts"],"names":[],"mappings":"AAAA,6BAA6B"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export type MouldStatus = 'FINE' | 'REPAIR' | 'SCRAP';
|
|
2
|
+
export type MouldStatusFlag = 1 | 2;
|
|
3
|
+
export interface MouldEntity {
|
|
4
|
+
mouldEntityId: string;
|
|
5
|
+
mouldEntityCode: string;
|
|
6
|
+
mouldEntityRegFormItemId?: string;
|
|
7
|
+
tenantId?: string;
|
|
8
|
+
materialCode?: string;
|
|
9
|
+
materialNo?: string;
|
|
10
|
+
materialName?: string;
|
|
11
|
+
seqNo?: string;
|
|
12
|
+
lotNo?: string;
|
|
13
|
+
mouldType?: string;
|
|
14
|
+
mouldFaceNumber?: number;
|
|
15
|
+
mouldStatus?: MouldStatus;
|
|
16
|
+
currentWarehouseCode?: string;
|
|
17
|
+
unitPrice?: number;
|
|
18
|
+
currency?: string;
|
|
19
|
+
producedDate?: string;
|
|
20
|
+
lastStockOutTime?: string;
|
|
21
|
+
remark?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface MouldEntityQueryParams {
|
|
24
|
+
pageNo?: number;
|
|
25
|
+
pageSize?: number;
|
|
26
|
+
status?: MouldStatusFlag;
|
|
27
|
+
mouldEntityId?: string;
|
|
28
|
+
mouldEntityCode?: string;
|
|
29
|
+
materialCode?: string;
|
|
30
|
+
materialNo?: string;
|
|
31
|
+
materialName?: string;
|
|
32
|
+
seqNo?: string;
|
|
33
|
+
lotNo?: string;
|
|
34
|
+
mouldType?: string;
|
|
35
|
+
mouldFaceNumber?: number;
|
|
36
|
+
mouldStatus?: MouldStatus;
|
|
37
|
+
currentWarehouseCode?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface PageResult<T> {
|
|
40
|
+
totalRows: number;
|
|
41
|
+
pageSize: number;
|
|
42
|
+
pageNo: number;
|
|
43
|
+
rows: T[];
|
|
44
|
+
}
|
|
45
|
+
export interface MouldEntityListResponse extends PageResult<MouldEntity> {
|
|
46
|
+
}
|
|
47
|
+
export interface MouldEntitySetStatusRequest {
|
|
48
|
+
mouldEntityId: string;
|
|
49
|
+
tenantId?: string;
|
|
50
|
+
mouldStatus: MouldStatus;
|
|
51
|
+
remark?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface MouldEntityApiResponse {
|
|
54
|
+
success: boolean;
|
|
55
|
+
data?: MouldEntity | MouldEntityListResponse;
|
|
56
|
+
error?: {
|
|
57
|
+
code: string;
|
|
58
|
+
message: string;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=mould.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mould.d.ts","sourceRoot":"","sources":["../../src/types/mould.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;AAGtD,MAAM,MAAM,eAAe,GAAG,CAAC,GAAG,CAAC,CAAC;AAGpC,MAAM,WAAW,WAAW;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAGD,MAAM,WAAW,sBAAsB;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAGD,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,CAAC,EAAE,CAAC;CACX;AAGD,MAAM,WAAW,uBAAwB,SAAQ,UAAU,CAAC,WAAW,CAAC;CAAG;AAG3E,MAAM,WAAW,2BAA2B;IAC1C,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,WAAW,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAGD,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,WAAW,GAAG,uBAAuB,CAAC;IAC7C,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mould.js","sourceRoot":"","sources":["../../src/types/mould.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -20,6 +20,7 @@ import { createStockCommand } from './stock/index.js';
|
|
|
20
20
|
import { createCalendarCommand } from './calendar/index.js';
|
|
21
21
|
import { createClientContactsCommand } from './client-contacts/index.js';
|
|
22
22
|
import { createSupplierContactsCommand } from './supplier-contacts/index.js';
|
|
23
|
+
import { createMouldCommand } from './mould/index.js';
|
|
23
24
|
|
|
24
25
|
export function createLibericaCommand(): Command {
|
|
25
26
|
const libericaCommand = new Command('liberica');
|
|
@@ -45,6 +46,7 @@ export function createLibericaCommand(): Command {
|
|
|
45
46
|
libericaCommand.addCommand(createCalendarCommand());
|
|
46
47
|
libericaCommand.addCommand(createClientContactsCommand());
|
|
47
48
|
libericaCommand.addCommand(createSupplierContactsCommand());
|
|
49
|
+
libericaCommand.addCommand(createMouldCommand());
|
|
48
50
|
|
|
49
51
|
libericaCommand.action(() => {
|
|
50
52
|
console.log(chalk.bold('\n☕ Liberica Commands\n'));
|
|
@@ -12,7 +12,7 @@ function formatTable(data: MaterialRequest): string {
|
|
|
12
12
|
lines.push(` ${chalk.gray('Code:')} ${data.materialCode}`);
|
|
13
13
|
lines.push(` ${chalk.gray('Class:')} ${data.materialClass || '(not set)'}`);
|
|
14
14
|
if (data.materialType) lines.push(` ${chalk.gray('Type:')} ${data.materialType}`);
|
|
15
|
-
if (data.
|
|
15
|
+
if (data.materialUomCode) lines.push(` ${chalk.gray('Unit:')} ${data.materialUomCode}`);
|
|
16
16
|
return lines.join('\n');
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -36,7 +36,7 @@ export function createMaterialsCreateCommand(): Command {
|
|
|
36
36
|
let materialNo = (options.no as string | undefined) || (options['no'] as string | undefined);
|
|
37
37
|
let materialClass = options.class as string | undefined;
|
|
38
38
|
const materialType = options.type as string | undefined;
|
|
39
|
-
const
|
|
39
|
+
const materialUomCode = options.unit as string | undefined;
|
|
40
40
|
const dryRun = options.dryRun === true;
|
|
41
41
|
const outputJson = options.json === true;
|
|
42
42
|
|
|
@@ -100,6 +100,14 @@ export function createMaterialsCreateCommand(): Command {
|
|
|
100
100
|
materialNo = inputNo;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
const dictResponse = await apiClient.getDictItems(context.environment, context.tenant, 'MATERIAL_CLASS');
|
|
104
|
+
if (dictResponse.success && dictResponse.data) {
|
|
105
|
+
const matchedItem = dictResponse.data.find(item => item.dictName === materialClass);
|
|
106
|
+
if (matchedItem) {
|
|
107
|
+
materialClass = matchedItem.dictCode;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
103
111
|
const codeResponse = await apiClient.getCodeByType(context.environment, context.tenant, 'TenantMaterialCode');
|
|
104
112
|
if (!codeResponse.success || !codeResponse.data) {
|
|
105
113
|
const errMsg = codeResponse.error?.message || 'Failed to generate material code';
|
|
@@ -118,7 +126,7 @@ export function createMaterialsCreateCommand(): Command {
|
|
|
118
126
|
materialCode: materialCode,
|
|
119
127
|
materialClass: materialClass!,
|
|
120
128
|
materialType: materialType,
|
|
121
|
-
|
|
129
|
+
materialUomCode: materialUomCode,
|
|
122
130
|
};
|
|
123
131
|
|
|
124
132
|
if (dryRun) {
|
|
@@ -162,7 +170,7 @@ export function createMaterialsCreateCommand(): Command {
|
|
|
162
170
|
materialName?: string;
|
|
163
171
|
materialClass?: string;
|
|
164
172
|
materialType?: string;
|
|
165
|
-
|
|
173
|
+
materialUomCode?: string;
|
|
166
174
|
statusFlag?: number;
|
|
167
175
|
createTime?: string;
|
|
168
176
|
} | undefined;
|
|
@@ -177,7 +185,7 @@ export function createMaterialsCreateCommand(): Command {
|
|
|
177
185
|
if (material?.materialCode) console.log(` ${chalk.gray('Code:')} ${material.materialCode}`);
|
|
178
186
|
if (material?.materialClass) console.log(` ${chalk.gray('Class:')} ${material.materialClass}`);
|
|
179
187
|
if (material?.materialType) console.log(` ${chalk.gray('Type:')} ${material.materialType}`);
|
|
180
|
-
if (material?.
|
|
188
|
+
if (material?.materialUomCode) console.log(` ${chalk.gray('Unit:')} ${material.materialUomCode}`);
|
|
181
189
|
if (material?.statusFlag !== undefined) {
|
|
182
190
|
const statusText = material.statusFlag === 1 ? 'Enabled' : 'Disabled';
|
|
183
191
|
console.log(` ${chalk.gray('Status:')} ${chalk.green(statusText)}`);
|
|
@@ -25,7 +25,7 @@ export function createMaterialUpdateCommand(): Command {
|
|
|
25
25
|
if (options.name) fields.materialName = options.name as string;
|
|
26
26
|
if (options.class) fields.materialClass = options.class as string;
|
|
27
27
|
if (options.type) fields.materialType = options.type as string;
|
|
28
|
-
if (options.unit) fields.
|
|
28
|
+
if (options.unit) fields.materialUomCode = options.unit as string;
|
|
29
29
|
|
|
30
30
|
const providedFields = Object.keys(fields).filter(
|
|
31
31
|
(k) => fields[k as keyof MaterialRequest] !== undefined
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { configManager } from '../../../core/config/manager.js';
|
|
4
|
+
import { apiClient } from '../../../core/api/client.js';
|
|
5
|
+
import { MouldEntityApiResponse, MouldEntity } from '../../../types/mould.js';
|
|
6
|
+
|
|
7
|
+
function formatMouldStatus(status?: string): string {
|
|
8
|
+
if (!status) return chalk.gray('-');
|
|
9
|
+
switch (status) {
|
|
10
|
+
case 'FINE':
|
|
11
|
+
return chalk.green('FINE');
|
|
12
|
+
case 'REPAIR':
|
|
13
|
+
return chalk.yellow('REPAIR');
|
|
14
|
+
case 'SCRAP':
|
|
15
|
+
return chalk.red('SCRAP');
|
|
16
|
+
default:
|
|
17
|
+
return status;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function outputMouldDetails(mould: MouldEntity): void {
|
|
22
|
+
console.log(chalk.bold('\n🔧 Mould Details\n'));
|
|
23
|
+
|
|
24
|
+
console.log(chalk.gray(' ID: ') + mould.mouldEntityId);
|
|
25
|
+
console.log(chalk.gray(' Code: ') + (mould.mouldEntityCode || chalk.gray('-')));
|
|
26
|
+
console.log(chalk.gray(' Material Code: ') + (mould.materialCode || chalk.gray('-')));
|
|
27
|
+
console.log(chalk.gray(' Material Name: ') + (mould.materialName || chalk.gray('-')));
|
|
28
|
+
console.log(chalk.gray(' Material No: ') + (mould.materialNo || chalk.gray('-')));
|
|
29
|
+
console.log(chalk.gray(' Type: ') + (mould.mouldType || chalk.gray('-')));
|
|
30
|
+
console.log(chalk.gray(' Status: ') + formatMouldStatus(mould.mouldStatus));
|
|
31
|
+
console.log(chalk.gray(' Warehouse Code: ') + (mould.currentWarehouseCode || chalk.gray('-')));
|
|
32
|
+
console.log(chalk.gray(' Seq No: ') + (mould.seqNo || chalk.gray('-')));
|
|
33
|
+
console.log(chalk.gray(' Lot No: ') + (mould.lotNo || chalk.gray('-')));
|
|
34
|
+
console.log(chalk.gray(' Face Number: ') + (mould.mouldFaceNumber !== undefined ? String(mould.mouldFaceNumber) : chalk.gray('-')));
|
|
35
|
+
console.log(chalk.gray(' Unit Price: ') + (mould.unitPrice !== undefined ? `${mould.unitPrice} ${mould.currency || ''}` : chalk.gray('-')));
|
|
36
|
+
console.log(chalk.gray(' Produced Date: ') + (mould.producedDate || chalk.gray('-')));
|
|
37
|
+
console.log(chalk.gray(' Last Stock Out: ') + (mould.lastStockOutTime || chalk.gray('-')));
|
|
38
|
+
console.log(chalk.gray(' Remark: ') + (mould.remark || chalk.gray('-')));
|
|
39
|
+
console.log();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function createMouldGetCommand(): Command {
|
|
43
|
+
const getCommand = new Command('get');
|
|
44
|
+
getCommand.description('Get mould entity details by ID');
|
|
45
|
+
|
|
46
|
+
getCommand
|
|
47
|
+
.argument('<mouldEntityId>', 'Mould entity ID (BigInteger string)')
|
|
48
|
+
.option('--json', 'Output as JSON')
|
|
49
|
+
.action(async (mouldEntityId: string, options: { json?: boolean }) => {
|
|
50
|
+
if (!mouldEntityId) {
|
|
51
|
+
console.error(chalk.red('\n✗ Mould ID is required\n'));
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const context = configManager.getCurrentContext();
|
|
56
|
+
const environment = context.environment;
|
|
57
|
+
const tenant = context.tenant;
|
|
58
|
+
|
|
59
|
+
const response: MouldEntityApiResponse = await apiClient.getMouldEntity(
|
|
60
|
+
environment,
|
|
61
|
+
tenant,
|
|
62
|
+
mouldEntityId
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
if (!response.success) {
|
|
66
|
+
const errorMessage = response.error?.message || 'Unknown error';
|
|
67
|
+
const errorCode = response.error?.code;
|
|
68
|
+
|
|
69
|
+
if (errorMessage.includes('不存在') || errorMessage.includes('not exist')) {
|
|
70
|
+
console.error(chalk.red(`\n✗ Mould not found: ${mouldEntityId}\n`));
|
|
71
|
+
} else {
|
|
72
|
+
console.error(chalk.red(`\n✗ Failed to get mould: ${errorMessage}`));
|
|
73
|
+
if (errorCode) {
|
|
74
|
+
console.error(chalk.gray(` Error code: ${errorCode}`));
|
|
75
|
+
}
|
|
76
|
+
console.error();
|
|
77
|
+
}
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const data = response.data as MouldEntity | null;
|
|
82
|
+
|
|
83
|
+
if (!data) {
|
|
84
|
+
if (options.json) {
|
|
85
|
+
console.log(JSON.stringify({ success: true, data: null }, null, 2));
|
|
86
|
+
} else {
|
|
87
|
+
console.log(chalk.bold('\n🔧 Mould Details\n'));
|
|
88
|
+
console.log(chalk.gray(' Not found\n'));
|
|
89
|
+
}
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (options.json) {
|
|
94
|
+
console.log(
|
|
95
|
+
JSON.stringify(
|
|
96
|
+
{
|
|
97
|
+
success: true,
|
|
98
|
+
data,
|
|
99
|
+
},
|
|
100
|
+
null,
|
|
101
|
+
2
|
|
102
|
+
)
|
|
103
|
+
);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
outputMouldDetails(data);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
return getCommand;
|
|
111
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { createMouldListCommand } from './list.js';
|
|
3
|
+
import { createMouldGetCommand } from './get.js';
|
|
4
|
+
import { createMouldSetStatusCommand } from './set-status.js';
|
|
5
|
+
import { createMouldStockInCommand } from './stock-in.js';
|
|
6
|
+
|
|
7
|
+
export function createMouldCommand(): Command {
|
|
8
|
+
const mouldCommand = new Command('mould');
|
|
9
|
+
mouldCommand.description('Manage mould entities');
|
|
10
|
+
|
|
11
|
+
mouldCommand.addCommand(createMouldListCommand());
|
|
12
|
+
mouldCommand.addCommand(createMouldGetCommand());
|
|
13
|
+
mouldCommand.addCommand(createMouldSetStatusCommand());
|
|
14
|
+
mouldCommand.addCommand(createMouldStockInCommand());
|
|
15
|
+
|
|
16
|
+
return mouldCommand;
|
|
17
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import Table from 'cli-table3';
|
|
4
|
+
import { configManager } from '../../../core/config/manager.js';
|
|
5
|
+
import { apiClient } from '../../../core/api/client.js';
|
|
6
|
+
import { MouldEntityListResponse, MouldStatus } from '../../../types/mould.js';
|
|
7
|
+
|
|
8
|
+
const VALID_STATUSES = ['FINE', 'REPAIR', 'SCRAP'] as const;
|
|
9
|
+
|
|
10
|
+
export function createMouldListCommand(): Command {
|
|
11
|
+
const listCommand = new Command('list');
|
|
12
|
+
listCommand.description('List mould entities with pagination');
|
|
13
|
+
|
|
14
|
+
listCommand
|
|
15
|
+
.option('-p, --page <number>', 'Page number', '1')
|
|
16
|
+
.option('-s, --size <number>', 'Page size', '20')
|
|
17
|
+
.option('--status <status>', `Mould status filter (${VALID_STATUSES.join('|')})`)
|
|
18
|
+
.option('--material-code <code>', 'Material code filter')
|
|
19
|
+
.option('--material-name <name>', 'Material name filter (fuzzy)')
|
|
20
|
+
.option('--json', 'Output as JSON')
|
|
21
|
+
.action(async (options) => {
|
|
22
|
+
const context = configManager.getCurrentContext();
|
|
23
|
+
const tenant = context.tenant;
|
|
24
|
+
const environment = context.environment;
|
|
25
|
+
|
|
26
|
+
const page = parseInt(options.page as string, 10);
|
|
27
|
+
const size = parseInt(options.size as string, 10);
|
|
28
|
+
|
|
29
|
+
const params: {
|
|
30
|
+
pageNo: number;
|
|
31
|
+
pageSize: number;
|
|
32
|
+
mouldStatus?: MouldStatus;
|
|
33
|
+
materialCode?: string;
|
|
34
|
+
materialName?: string;
|
|
35
|
+
} = { pageNo: page, pageSize: size };
|
|
36
|
+
|
|
37
|
+
if (options.status !== undefined) {
|
|
38
|
+
const status = options.status as MouldStatus;
|
|
39
|
+
if (VALID_STATUSES.includes(status)) {
|
|
40
|
+
params.mouldStatus = status;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (options.materialCode !== undefined) {
|
|
45
|
+
params.materialCode = options.materialCode as string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (options.materialName !== undefined) {
|
|
49
|
+
params.materialName = options.materialName as string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const response = await apiClient.listMouldEntities(environment, tenant, params);
|
|
53
|
+
|
|
54
|
+
if (!response.success) {
|
|
55
|
+
console.error(chalk.red(`\n✗ Failed to list moulds: ${response.error?.message || 'Unknown error'}`));
|
|
56
|
+
if (response.error?.code) {
|
|
57
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
58
|
+
}
|
|
59
|
+
console.error();
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const data = response.data as MouldEntityListResponse | null;
|
|
64
|
+
|
|
65
|
+
if (!data) {
|
|
66
|
+
if (options.json) {
|
|
67
|
+
console.log(
|
|
68
|
+
JSON.stringify(
|
|
69
|
+
{ success: true, data: { rows: [], pagination: { pageNo: 0, pageSize: 20, totalRows: 0 } } },
|
|
70
|
+
null,
|
|
71
|
+
2
|
|
72
|
+
)
|
|
73
|
+
);
|
|
74
|
+
} else {
|
|
75
|
+
console.log(chalk.bold('\n📋 Mould List\n'));
|
|
76
|
+
console.log(chalk.gray(' No moulds found\n'));
|
|
77
|
+
}
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (options.json) {
|
|
82
|
+
console.log(
|
|
83
|
+
JSON.stringify(
|
|
84
|
+
{
|
|
85
|
+
success: true,
|
|
86
|
+
data: {
|
|
87
|
+
rows: data.rows || [],
|
|
88
|
+
pagination: {
|
|
89
|
+
pageNo: data.pageNo,
|
|
90
|
+
pageSize: data.pageSize,
|
|
91
|
+
totalRows: data.totalRows,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
null,
|
|
96
|
+
2
|
|
97
|
+
)
|
|
98
|
+
);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const records = data.rows || [];
|
|
103
|
+
|
|
104
|
+
if (records.length === 0) {
|
|
105
|
+
console.log(chalk.bold('\n📋 Mould List\n'));
|
|
106
|
+
console.log(chalk.gray(' No moulds found\n'));
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
console.log(chalk.bold('\n📋 Mould List\n'));
|
|
111
|
+
|
|
112
|
+
const table = new Table({
|
|
113
|
+
head: [
|
|
114
|
+
chalk.bold('Code'),
|
|
115
|
+
chalk.bold('Material'),
|
|
116
|
+
chalk.bold('Type'),
|
|
117
|
+
chalk.bold('Status'),
|
|
118
|
+
chalk.bold('Warehouse'),
|
|
119
|
+
chalk.bold('Produced'),
|
|
120
|
+
],
|
|
121
|
+
colWidths: [16, 20, 14, 10, 14, 12],
|
|
122
|
+
style: {
|
|
123
|
+
head: [],
|
|
124
|
+
border: [],
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
for (const mould of records) {
|
|
129
|
+
const statusText =
|
|
130
|
+
mould.mouldStatus === 'FINE'
|
|
131
|
+
? chalk.green('FINE')
|
|
132
|
+
: mould.mouldStatus === 'REPAIR'
|
|
133
|
+
? chalk.yellow('REPAIR')
|
|
134
|
+
: chalk.red('SCRAP');
|
|
135
|
+
|
|
136
|
+
table.push([
|
|
137
|
+
mould.mouldEntityCode || '-',
|
|
138
|
+
mould.materialName || '-',
|
|
139
|
+
mould.mouldType || '-',
|
|
140
|
+
statusText,
|
|
141
|
+
mould.currentWarehouseCode || '-',
|
|
142
|
+
mould.producedDate || '-',
|
|
143
|
+
]);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
console.log(table.toString());
|
|
147
|
+
console.log();
|
|
148
|
+
console.log(
|
|
149
|
+
chalk.gray(
|
|
150
|
+
` Total: ${data.totalRows} | Page: ${data.pageNo + 1} / ${Math.ceil(data.totalRows / data.pageSize) || 1} | Size: ${data.pageSize}`
|
|
151
|
+
)
|
|
152
|
+
);
|
|
153
|
+
console.log();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
return listCommand;
|
|
157
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { configManager } from '../../../core/config/manager.js';
|
|
4
|
+
import { apiClient } from '../../../core/api/client.js';
|
|
5
|
+
import { MouldStatus, MouldEntitySetStatusRequest } from '../../../types/mould.js';
|
|
6
|
+
|
|
7
|
+
const VALID_STATUSES: MouldStatus[] = ['FINE', 'REPAIR', 'SCRAP'];
|
|
8
|
+
|
|
9
|
+
export function createMouldSetStatusCommand(): Command {
|
|
10
|
+
const cmd = new Command('set-status');
|
|
11
|
+
cmd.description('Set mould status (FINE | REPAIR | SCRAP)');
|
|
12
|
+
|
|
13
|
+
cmd
|
|
14
|
+
.argument('<mouldEntityId>', 'Mould entity ID')
|
|
15
|
+
.argument('<status>', 'New status (FINE, REPAIR, or SCRAP)')
|
|
16
|
+
.option('--remark <remark>', 'Remark for status change')
|
|
17
|
+
.option('--json', 'Output as JSON')
|
|
18
|
+
.action(async (mouldEntityId: string, status: string, options: { remark?: string; json?: boolean }) => {
|
|
19
|
+
const context = configManager.getCurrentContext();
|
|
20
|
+
const tenant = context.tenant;
|
|
21
|
+
const environment = context.environment;
|
|
22
|
+
|
|
23
|
+
const mouldStatus = status.toUpperCase() as MouldStatus;
|
|
24
|
+
if (!VALID_STATUSES.includes(mouldStatus)) {
|
|
25
|
+
const errMsg = `Invalid status value: ${status}. Must be one of: ${VALID_STATUSES.join(', ')}`;
|
|
26
|
+
if (options.json) {
|
|
27
|
+
console.log(
|
|
28
|
+
JSON.stringify({
|
|
29
|
+
success: false,
|
|
30
|
+
error: { code: 'INVALID_STATUS', message: errMsg },
|
|
31
|
+
})
|
|
32
|
+
);
|
|
33
|
+
} else {
|
|
34
|
+
console.error(chalk.red(`\n✗ ${errMsg}\n`));
|
|
35
|
+
}
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const request: MouldEntitySetStatusRequest = {
|
|
40
|
+
mouldEntityId,
|
|
41
|
+
mouldStatus,
|
|
42
|
+
remark: options.remark,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
if (!options.json) {
|
|
46
|
+
console.log(chalk.bold('\n🔧 Set Mould Status\n'));
|
|
47
|
+
console.log(` ${chalk.gray('Mould ID:')} ${mouldEntityId}`);
|
|
48
|
+
console.log(` ${chalk.gray('New Status:')} ${mouldStatus}`);
|
|
49
|
+
if (options.remark) {
|
|
50
|
+
console.log(` ${chalk.gray('Remark:')} ${options.remark}`);
|
|
51
|
+
}
|
|
52
|
+
console.log();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const response = await apiClient.setMouldStatus(environment, tenant, request);
|
|
56
|
+
|
|
57
|
+
if (!response.success) {
|
|
58
|
+
const errorMsg = response.error?.message || 'Failed to set mould status';
|
|
59
|
+
const errorCode = response.error?.code || 'SET_MOULD_STATUS_ERROR';
|
|
60
|
+
|
|
61
|
+
if (options.json) {
|
|
62
|
+
console.log(
|
|
63
|
+
JSON.stringify({
|
|
64
|
+
success: false,
|
|
65
|
+
error: { code: errorCode, message: errorMsg },
|
|
66
|
+
})
|
|
67
|
+
);
|
|
68
|
+
} else {
|
|
69
|
+
console.error(chalk.red(`\n✗ Failed to set mould status: ${errorMsg}`));
|
|
70
|
+
if (response.error?.code) {
|
|
71
|
+
console.error(chalk.gray(` Error code: ${response.error.code}`));
|
|
72
|
+
}
|
|
73
|
+
console.error();
|
|
74
|
+
}
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const data = response.data as { mouldEntityId?: string; mouldEntityCode?: string; mouldName?: string; mouldStatus?: string } | undefined;
|
|
79
|
+
|
|
80
|
+
if (options.json) {
|
|
81
|
+
console.log(
|
|
82
|
+
JSON.stringify({
|
|
83
|
+
success: true,
|
|
84
|
+
data: {
|
|
85
|
+
mouldId: data?.mouldEntityId || mouldEntityId,
|
|
86
|
+
mouldName: data?.mouldName,
|
|
87
|
+
currentStatus: data?.mouldStatus || mouldStatus,
|
|
88
|
+
remark: options.remark,
|
|
89
|
+
},
|
|
90
|
+
})
|
|
91
|
+
);
|
|
92
|
+
} else {
|
|
93
|
+
console.log(chalk.green(`✓ Mould status set to ${mouldStatus}`));
|
|
94
|
+
console.log();
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
return cmd;
|
|
99
|
+
}
|