| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- import service from '/@/utils/request';
- import { withAidopTenantParams } from './aidopTenant';
- export interface Paged<T> {
- total: number;
- page: number;
- pageSize: number;
- list: T[];
- }
- export interface WorkOrderDispatchRow {
- id: number;
- domain?: string | null;
- workOrd?: string | null;
- priority?: string | null;
- itemNum?: string | null;
- descr?: string | null;
- descr1?: string | null;
- qtyOrded?: number | null;
- materialSituation?: string | null;
- ordDate?: string | null;
- dueDate?: string | null;
- status?: string | null;
- lotSerial?: string | null;
- prevNbr?: string | null;
- nbr?: string | null;
- wl?: string | null;
- }
- export interface WorkOrderReleaseParams {
- workOrd: string;
- ordDate: string;
- lotSerial?: string | null;
- /** 登录账号(批量齐套检查等场景使用) */
- userAccount: string;
- }
- /** 物料齐套检查(租户下 p/r 工单批量检查) */
- export async function kitCheck(domain: string, userAccount: string): Promise<void> {
- await service.post('/api/WorkOrder/dispatch/kitting-check', null, {
- params: { domain, userAccount },
- timeout: 300000,
- });
- }
- export interface KittingCheckSingleResult {
- materialSituation?: string | null;
- isKitted?: boolean;
- shortageLineCount?: number;
- }
- /** 单工单齐套检查(替代旧 WorkOrdKittingCheckByNo);缺料属正常结论,由调用方按 isKitted 呈现 */
- export async function kittingCheckSingle(
- workOrd: string,
- domain: string,
- userAccount: string
- ): Promise<KittingCheckSingleResult> {
- const res = await service.post('/api/WorkOrder/dispatch/work-order-kitting-check', null, {
- params: { workord: workOrd, domain, userAccount },
- timeout: 300000,
- });
- const body = res.data as (KittingCheckSingleResult & { result?: KittingCheckSingleResult }) | undefined;
- return body?.result ?? body ?? {};
- }
- /** MRP 生成结果 */
- export interface MrpGenerateResult {
- message?: string;
- demandScheduleCount?: number;
- prCreatedCount?: number;
- shortageItemCount?: number;
- }
- /** 生成物料需求 */
- export async function mrpGenerate(domain: string): Promise<MrpGenerateResult> {
- const res = await service.post<MrpGenerateResult>('/api/WorkOrder/material-requirement/generate', null, {
- params: { domain },
- });
- return res.data ?? {};
- }
- export interface NextLotSerialResult {
- lotSerial: string;
- }
- /** 下一生产批号:本系统接口(租户由认证后 JWT 解析,按 tenant_id + 初始工单取号) */
- export function fetchNextLotSerial(payload: { workOrd: string }) {
- const params: Record<string, string | number> = {
- workOrd: payload.workOrd.trim(),
- };
- return service
- .get<NextLotSerialResult & { result?: NextLotSerialResult }>('/api/WorkOrder/dispatch/next-lot-serial', {
- params,
- })
- .then((res) => {
- const body = res.data as NextLotSerialResult & { result?: NextLotSerialResult };
- if (body && typeof body.lotSerial === 'string') return { lotSerial: body.lotSerial };
- if (body?.result && typeof body.result.lotSerial === 'string') return { lotSerial: body.result.lotSerial };
- throw new Error('获取生产批号返回格式异常');
- });
- }
- // ── BOM 上传 ──
- export interface BomItemDto {
- itemNum: string;
- descr: string;
- descr1?: string;
- um?: string;
- qtyRequired: number;
- op: number;
- salesOrderNo?: string;
- parentItemNum?: string;
- }
- export interface BomCheckResult {
- existing: string[];
- missing: BomItemDto[];
- }
- export interface BomUploadResult {
- inserted: number;
- updated: number;
- newItems: number;
- total: number;
- matchedWorkOrders: number;
- unmatched: string[];
- }
- /** BOM 物料存在性校验 */
- export function checkBomMaterials(items: BomItemDto[]) {
- return service
- .post<BomCheckResult>('/api/WorkOrder/dispatch/bom/check-materials', { items })
- .then((r) => r.data);
- }
- /** BOM 写入工单物料明细(按订单号+父物料号自动匹配未下达工单) */
- export function uploadBom(createMissingItems: boolean, items: BomItemDto[]) {
- return service
- .post<BomUploadResult>('/api/WorkOrder/dispatch/bom/upload', { createMissingItems, items })
- .then((r) => r.data);
- }
- export function fetchWorkOrderDispatchList(params: Record<string, unknown>) {
- return service
- .get<Paged<WorkOrderDispatchRow>>('/api/WorkOrder/dispatch/list', { params: withAidopTenantParams(params) })
- .then((r) => r.data);
- }
- /** 下达成功后的响应体(统一包装或非统一 JSON) */
- export type WorkOrderReleaseResponse = Record<string, unknown>;
- /**
- * 工单下达:本系统 `POST .../dispatch/release`(含齐套检查与状态落库)。
- */
- export async function releaseWorkOrder(body: WorkOrderReleaseParams): Promise<WorkOrderReleaseResponse> {
- const { userAccount: _ua, ...releaseBody } = body;
- const res = await service.post('/api/WorkOrder/dispatch/release', releaseBody, {
- headers: { 'X-Silent-Error': '1' },
- });
- const data = res.data as WorkOrderReleaseResponse | undefined;
- if (data == null || typeof data !== 'object') {
- throw new Error('工单下达返回异常');
- }
- if (Object.prototype.hasOwnProperty.call(data, 'code')) {
- const code = Number(data.code);
- if (!Number.isFinite(code) || code !== 200) {
- const msg =
- typeof data.message === 'string' && data.message.trim() ? data.message : '工单下达失败';
- throw new Error(msg);
- }
- }
- if (typeof data.type === 'string' && data.type && data.type !== 'success') {
- const msg =
- typeof data.message === 'string' && data.message.trim() ? data.message : '工单下达失败';
- throw new Error(msg);
- }
- return data;
- }
|