AML 操作方法文档

AML 操作方法文档

一、AML 基本格式

1.1 标准格式

``xml

`

1.2 操作类型

操作说明示例
get查询获取对象列表或单个对象
add创建创建新对象
edit编辑修改现有对象
delete删除删除对象

二、AML 操作模板

2.1 查询操作 (get)

文件位置/app/lib/aml/queries.ts

`typescript

// 查询对象列表

export const queryTemplates = {

// ECR查询

ecrList: (status?: string) =>

${status ? ${status} : ''}

,

// ECR单个查询

ecrById: (id: string) =>

,

// Part查询

partList: (partNumber?: string) =>

${partNumber ? ${partNumber} : ''}

,

// Vendor查询

vendorList: () =>

,

// BOM查询

bomList: (partId?: string) =>

${partId ? ${partId} : ''}

,

// Inventory查询

inventoryList: () =>

};

`

2.2 创建操作 (add)

`typescript

// 文件位置:/app/lib/aml/creates.ts

export const createTemplates = {

// 创建ECR

ecr: (data: { changeNumber: string; title: string; description: string }) =>

${data.changeNumber}

<![CDATA[${data.title}]]>

new

,

// 创建Part

part: (data: { partNumber: string; name: string; description?: string; unitCost?: number; weight?: number }) =>

${data.partNumber}

${data.description ? : ''}

${data.unitCost ? ${data.unitCost} : ''}

${data.weight ? ${data.weight} : ''}

,

// 创建Vendor

vendor: (data: { name: string; contact?: string; phone?: string; email?: string; address?: string }) =>

${data.contact ? : ''}

${data.phone ? ${data.phone} : ''}

${data.email ? ${data.email} : ''}

${data.address ?

: ''}

,

// 创建BOM

bom: (data: { partId: string; itemId: string; quantity: number; unit?: string }) =>

${data.partId}

${data.itemId}

${data.quantity}

${data.unit ? ${data.unit} : ''}

};

`

2.3 编辑操作 (edit)

`typescript

// 文件位置:/app/lib/aml/edits.ts

export const editTemplates = {

// 更新ECR

ecr: (id: string, data: { status?: string; description?: string }) =>

${data.status ? ${data.status} : ''}

${data.description ? : ''}

,

// 更新Part

part: (id: string, data: { name?: string; description?: string; unitCost?: number; weight?: number }) =>

${data.name ? : ''}

${data.description ? : ''}

${data.unitCost ? ${data.unitCost} : ''}

${data.weight ? ${data.weight} : ''}

,

// 更新Vendor

vendor: (id: string, data: { name?: string; contact?: string; phone?: string; email?: string; address?: string }) =>

${data.name ? : ''}

${data.contact ? : ''}

${data.phone ? ${data.phone} : ''}

${data.email ? ${data.email} : ''}

${data.address ?

: ''}

};

`

2.4 删除操作 (delete)

`typescript

// 文件位置:/app/lib/aml/deletes.ts

export const deleteTemplates = {

// 删除ECR

ecr: (id: string) =>

,

// 删除Part

part: (id: string) =>

,

// 删除Vendor

vendor: (id: string) =>

};

`

三、AML 调用封装

文件位置/app/lib/aml/index.ts

`typescript

import { executeAmlWithFallback } from '../SCSAI/fallback';

import { queryTemplates } from './queries';

import { createTemplates } from './creates';

import { editTemplates } from './edits';

import { deleteTemplates } from './deletes';

// 查询对象列表

export async function queryItems(itemType: string, status?: string): Promise {

let aml: string;

switch (itemType) {

case 'ECR':

aml = queryTemplates.ecrList(status);

break;

case 'Part':

aml = queryTemplates.partList();

break;

case 'Vendor':

aml = queryTemplates.vendorList();

break;

case 'BOM':

aml = queryTemplates.bomList();

break;

case 'Inventory':

aml = queryTemplates.inventoryList();

break;

default:

throw new Error(Unsupported item type: ${itemType});

}

return await executeAmlWithFallback(aml, itemType);

}

// 创建对象

export async function createItem(itemType: string, data: any): Promise {

let aml: string;

switch (itemType) {

case 'ECR':

aml = createTemplates.ecr(data);

break;

case 'Part':

aml = createTemplates.part(data);

break;

case 'Vendor':

aml = createTemplates.vendor(data);

break;

case 'BOM':

aml = createTemplates.bom(data);

break;

default:

throw new Error(Unsupported item type: ${itemType});

}

return await executeAmlWithFallback(aml, itemType);

}

// 更新对象

export async function updateItem(itemType: string, id: string, data: any): Promise {

let aml: string;

switch (itemType) {

case 'ECR':

aml = editTemplates.ecr(id, data);

break;

case 'Part':

aml = editTemplates.part(id, data);

break;

case 'Vendor':

aml = editTemplates.vendor(id, data);

break;

default:

throw new Error(Unsupported item type: ${itemType});

}

return await executeAmlWithFallback(aml, itemType);

}

// 删除对象

export async function deleteItem(itemType: string, id: string): Promise {

let aml: string;

switch (itemType) {

case 'ECR':

aml = deleteTemplates.ecr(id);

break;

case 'Part':

aml = deleteTemplates.part(id);

break;

case 'Vendor':

aml = deleteTemplates.vendor(id);

break;

default:

throw new Error(Unsupported item type: ${itemType});

}

return await executeAmlWithFallback(aml, itemType);

}

`

四、常用对象类型

4.1 对象类型列表

对象类型说明主要字段
ECR工程变更请求change_number, title, description, status
ECO工程变更指令change_number, title, affected_items, status
Part零件part_number, name, description, unit_cost, weight
BOM物料清单part_id, item_id, quantity, unit
Vendor供应商name, contact, phone, email, address
Inventory库存part_id, quantity, location, warehouse

4.2 状态流转

ECR状态

  • new → pending_approval → approved → in_progress → completed
  • new → pending_approval → rejected

ECO状态

  • new → pending_approval → approved → in_progress → completed
  • new → pending_approval → rejected

五、快速使用示例

`typescript

// 文件位置:/app/api/objects/route.ts

import { queryItems, createItem, updateItem, deleteItem } from '@/app/lib/aml';

// GET /api/objects?type=ECR&status=pending_approval

export async function GET(request: Request) {

const { searchParams } = new URL(request.url);

const type = searchParams.get('type') || 'ECR';

const status = searchParams.get('status');

const result = await queryItems(type, status);

return Response.json(result);

}

// POST /api/objects

export async function POST(request: Request) {

const { type, data } = await request.json();

const result = await createItem(type, data);

return Response.json(result);

}

// PUT /api/objects

export async function PUT(request: Request) {

const { type, id, data } = await request.json();

const result = await updateItem(type, id, data);

return Response.json(result);

}

// DELETE /api/objects

export async function DELETE(request: Request) {

const { searchParams } = new URL(request.url);

const type = searchParams.get('type');

const id = searchParams.get('id');

if (!type || !id) {

return Response.json({ success: false, error: 'Missing type or id' }, { status: 400 });

}

const result = await deleteItem(type, id);

return Response.json(result);

}

``

六、文件位置总结

文件位置用途
queries.ts/app/lib/aml/queries.ts查询模板
creates.ts/app/lib/aml/creates.ts创建模板
edits.ts/app/lib/aml/edits.ts编辑模板
deletes.ts/app/lib/aml/deletes.ts删除模板
index.ts/app/lib/aml/index.ts统一导出和调用封装
← 返回案例列表
分享:
🤖 Try Now →
🤖
🎁