import request from "@/utils/request";
|
import type { BaseResult, PageResult } from "@/models/base";
|
|
export type TimelinessMaterialType = "单丝" | "绞线";
|
|
export interface TimeSensitiveTaskQuery {
|
current: number;
|
size?: number;
|
initiatorName?: string;
|
machineName?: string;
|
materialType?: TimelinessMaterialType | string;
|
taskStatus?: number | string;
|
startTime?: string;
|
endTime?: string;
|
}
|
|
export interface TimeSensitiveTaskForm {
|
materialType: TimelinessMaterialType;
|
initiatorName: string;
|
initiateTime: string;
|
setTemperature: number | string;
|
agingDuration: number | string;
|
machineName: string;
|
inspectorName: string;
|
}
|
|
export interface TimeSensitiveTaskStartForm extends TimeSensitiveTaskForm {
|
id: number | string;
|
furnaceInTime: string;
|
}
|
|
export interface TimeSensitiveCandidateQuery {
|
current: number;
|
size?: number;
|
taskId: number | string;
|
materialType: TimelinessMaterialType;
|
model?: string;
|
materialCode?: string;
|
}
|
|
export interface TimelinessInspectionDetailForm {
|
id?: number | string;
|
routingInspectionUser?: string;
|
zoneOne?: number | string;
|
zoneTwo?: number | string;
|
zoneThree?: number | string;
|
zoneFour?: number | string;
|
zoneFive?: number | string;
|
zoneSix?: number | string;
|
timelinessInspectionId?: number | string;
|
}
|
|
/** 联调完成后改为 false 即可恢复下方真实接口。 */
|
export const USE_TIME_SENSITIVE_MOCK = true;
|
|
const mockTasks: any[] = [
|
{
|
id: 9001,
|
taskCode: "SX-20260904-001",
|
materialType: "单丝",
|
initiatorName: "张工",
|
initiateTime: "2026-09-04 09:10:00",
|
setTemperature: 180,
|
agingDuration: "2+4+1",
|
machineName: "时效炉-01",
|
itemCount: 2,
|
furnaceInTime: "",
|
furnaceOutTime: "",
|
inspectorName: "李师傅",
|
taskStatus: 0,
|
},
|
{
|
id: 9002,
|
taskCode: "JX-20260904-001",
|
materialType: "绞线",
|
initiatorName: "王工",
|
initiateTime: "2026-09-04 08:30:00",
|
setTemperature: 175,
|
agingDuration: "2+3+1",
|
machineName: "时效炉-02",
|
itemCount: 2,
|
furnaceInTime: "2026-09-04 10:00:00",
|
furnaceOutTime: "",
|
inspectorName: "赵师傅",
|
taskStatus: 1,
|
},
|
{
|
id: 9003,
|
taskCode: "SX-20260903-001",
|
materialType: "单丝",
|
initiatorName: "刘工",
|
initiateTime: "2026-09-03 08:00:00",
|
setTemperature: 180,
|
agingDuration: "2+4+1",
|
machineName: "时效炉-01",
|
itemCount: 1,
|
furnaceInTime: "2026-09-03 08:30:00",
|
furnaceOutTime: "2026-09-03 15:30:00",
|
inspectorName: "孙师傅",
|
taskStatus: 2,
|
},
|
];
|
|
const mockMaterialPool: Record<TimelinessMaterialType, any[]> = {
|
单丝: [
|
{
|
id: 9101,
|
materialType: "单丝",
|
model: "Φ5.6",
|
poleModel: "1A60 H12 Φ9.5 A2",
|
rodNo: "720526083102-014",
|
batchCode: "750826090101-005",
|
monofilamentNumber: "750826090101-005",
|
weight: 2875,
|
supplier: "山东元旺电工科技有限公司",
|
},
|
{
|
id: 9102,
|
materialType: "单丝",
|
model: "L-3.45",
|
poleModel: "1A60-H14 Φ9.5 A6",
|
rodNo: "710726081602-003",
|
batchCode: "750426083002-037",
|
monofilamentNumber: "750426083002-037",
|
weight: 2650,
|
supplier: "山东元旺电工科技有限公司",
|
},
|
{
|
id: 9301,
|
outputId: 9301,
|
materialType: "单丝",
|
model: "8030-95L",
|
poleModel: "8030",
|
rodNo: "720626082404-001",
|
batchCode: "750626083101-001",
|
monofilamentNumber: "750626083101-001",
|
weight: 2400,
|
supplier: "山东元旺电工科技有限公司",
|
},
|
{
|
id: 9302,
|
outputId: 9302,
|
materialType: "单丝",
|
model: "Φ3.20",
|
poleModel: "1A60 H14 Φ9.5 A6",
|
rodNo: "710726090401-002",
|
batchCode: "750726090401-002",
|
monofilamentNumber: "750726090401-002",
|
weight: 2520,
|
supplier: "山东元旺电工科技有限公司",
|
},
|
{
|
id: 9501,
|
materialType: "单丝",
|
model: "Φ4.50",
|
poleModel: "1A60 H12 Φ9.5 A2",
|
rodNo: "720526083102-018",
|
batchCode: "750826090201-001",
|
monofilamentNumber: "750826090201-001",
|
weight: 2780,
|
supplier: "山东元旺电工科技有限公司",
|
},
|
],
|
绞线: [
|
{
|
id: 9201,
|
outputId: 9201,
|
materialType: "绞线",
|
model: "JLHA1/G1A-16/3-6/1",
|
batchCode: "JX260904001-01",
|
weight: 1180,
|
},
|
{
|
id: 9202,
|
outputId: 9202,
|
materialType: "绞线",
|
model: "JLHA1/G1A-25/4-6/1",
|
batchCode: "JX260904001-02",
|
weight: 1260,
|
},
|
{
|
id: 9401,
|
outputId: 9401,
|
materialType: "绞线",
|
model: "JLHA1/G1A-35/6-6/1",
|
batchCode: "JX260904002-01",
|
weight: 1380,
|
},
|
{
|
id: 9402,
|
outputId: 9402,
|
materialType: "绞线",
|
model: "JLHA1/G1A-50/8-6/1",
|
batchCode: "JX260904002-02",
|
weight: 1460,
|
},
|
],
|
};
|
|
const findMockMaterial = (id: number | string) =>
|
[...mockMaterialPool.单丝, ...mockMaterialPool.绞线].find(
|
(item) => String(item.id) === String(id)
|
);
|
|
const cloneMockMaterial = (id: number | string) => {
|
const item = findMockMaterial(id);
|
return item ? { ...item } : undefined;
|
};
|
|
const mockItems: Record<string, any[]> = {
|
"9001": [cloneMockMaterial(9101), cloneMockMaterial(9102)].filter(Boolean),
|
"9002": [cloneMockMaterial(9201), cloneMockMaterial(9202)].filter(Boolean),
|
"9003": [cloneMockMaterial(9501)].filter(Boolean),
|
};
|
|
const mockInspections: Record<string, any[]> = {
|
"9002": [
|
{
|
id: 9601,
|
routingInspectionUser: "赵师傅",
|
zoneOne: 175,
|
zoneTwo: 175.2,
|
zoneThree: 174.8,
|
zoneFour: 175.1,
|
zoneFive: 175,
|
zoneSix: 174.9,
|
createTime: "2026-09-04 11:00:00",
|
timelinessInspectionId: 9002,
|
},
|
],
|
"9003": [
|
{
|
id: 9602,
|
routingInspectionUser: "孙师傅",
|
zoneOne: 180,
|
zoneTwo: 180,
|
zoneThree: 179.8,
|
zoneFour: 180.1,
|
zoneFive: 180,
|
zoneSix: 179.9,
|
createTime: "2026-09-03 10:30:00",
|
timelinessInspectionId: 9003,
|
},
|
],
|
};
|
|
const mockOperations: Record<string, any[]> = {
|
"9001": [
|
{
|
id: 9701,
|
operationType: 1,
|
operationTypeDesc: "新增",
|
beforeStatus: "",
|
afterStatus: "待开始",
|
operationDetail: "张工创建时效任务",
|
operatorName: "张工",
|
operateTime: "2026-09-04 09:10:00",
|
},
|
],
|
"9002": [
|
{
|
id: 9702,
|
operationType: 2,
|
operationTypeDesc: "开始时效",
|
beforeStatus: "待开始",
|
afterStatus: "时效中",
|
operationDetail: "赵师傅确认任务信息并开始时效",
|
operatorName: "赵师傅",
|
operateTime: "2026-09-04 10:00:00",
|
},
|
],
|
"9003": [
|
{
|
id: 9703,
|
operationType: 3,
|
operationTypeDesc: "结束时效",
|
beforeStatus: "时效中",
|
afterStatus: "时效结束",
|
operationDetail: "孙师傅结束时效任务",
|
operatorName: "孙师傅",
|
operateTime: "2026-09-03 15:30:00",
|
},
|
],
|
};
|
|
const mockUsers = [
|
{ userId: 1, nickName: "张工" },
|
{ userId: 2, nickName: "王工" },
|
{ userId: 3, nickName: "刘工" },
|
{ userId: 4, nickName: "李师傅" },
|
{ userId: 5, nickName: "赵师傅" },
|
{ userId: 6, nickName: "孙师傅" },
|
];
|
|
const mockMachines = [
|
{ deviceId: 1, deviceModel: "时效炉-01" },
|
{ deviceId: 2, deviceModel: "时效炉-02" },
|
{ deviceId: 3, deviceModel: "时效炉-03" },
|
];
|
|
const pad = (value: number) => String(value).padStart(2, "0");
|
const mockDateTime = () => {
|
const date = new Date();
|
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(
|
date.getHours()
|
)}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
|
};
|
|
const mockResult = <T>(data: T, msg = "success") =>
|
new Promise<BaseResult<T>>((resolve) => {
|
setTimeout(() => resolve({ code: 200, msg, data }), 120);
|
});
|
|
const mockMaterialCode = (item: any) =>
|
String(item?.flowCode || item?.batchCode || item?.monofilamentNumber || "").trim();
|
|
const updateMockItemCount = (taskId: number | string) => {
|
const task = mockTasks.find((item) => String(item.id) === String(taskId));
|
if (task) task.itemCount = (mockItems[String(taskId)] || []).length;
|
};
|
|
const addMockOperation = (
|
taskId: number | string,
|
operationType: number,
|
operationTypeDesc: string,
|
beforeStatus: string,
|
afterStatus: string,
|
operationDetail: string,
|
operatorName: string
|
) => {
|
const key = String(taskId);
|
mockOperations[key] ||= [];
|
mockOperations[key].unshift({
|
id: Date.now(),
|
operationType,
|
operationTypeDesc,
|
beforeStatus,
|
afterStatus,
|
operationDetail,
|
operatorName,
|
operateTime: mockDateTime(),
|
});
|
};
|
|
const TimeSensitiveTaskApi = {
|
queryPage(params: TimeSensitiveTaskQuery) {
|
if (USE_TIME_SENSITIVE_MOCK) {
|
let rows = [...mockTasks];
|
if (params.initiatorName) {
|
rows = rows.filter((item) => item.initiatorName.includes(params.initiatorName!));
|
}
|
if (params.machineName) {
|
rows = rows.filter((item) => item.machineName.includes(params.machineName!));
|
}
|
if (params.materialType) {
|
rows = rows.filter((item) => item.materialType === params.materialType);
|
}
|
if (params.taskStatus !== undefined && params.taskStatus !== "") {
|
rows = rows.filter((item) => Number(item.taskStatus) === Number(params.taskStatus));
|
}
|
if (params.startTime) {
|
rows = rows.filter((item) => item.initiateTime >= params.startTime!);
|
}
|
if (params.endTime) {
|
rows = rows.filter((item) => item.initiateTime <= params.endTime!);
|
}
|
const current = Number(params.current || 1);
|
const size = Number(params.size || 10);
|
return mockResult<PageResult>({
|
records: rows.slice((current - 1) * size, current * size),
|
total: rows.length,
|
current,
|
size,
|
pages: current * size < rows.length,
|
});
|
}
|
return request<BaseResult<PageResult>>({
|
url: "/timeSensitiveTask/queryPage",
|
method: "GET",
|
data: params,
|
});
|
},
|
|
getDetail(id: number | string) {
|
if (USE_TIME_SENSITIVE_MOCK) {
|
return mockResult(mockTasks.find((item) => String(item.id) === String(id)) || null);
|
}
|
return request<BaseResult<any>>({
|
url: "/timeSensitiveTask/getDetailById",
|
method: "GET",
|
data: { id },
|
});
|
},
|
|
getItems(taskId: number | string) {
|
if (USE_TIME_SENSITIVE_MOCK) {
|
return mockResult<any[]>((mockItems[String(taskId)] || []).map((item) => ({ ...item })));
|
}
|
return request<BaseResult<any[]>>({
|
url: "/timeSensitiveTask/getItems",
|
method: "GET",
|
data: { taskId },
|
});
|
},
|
|
create(data: TimeSensitiveTaskForm) {
|
if (USE_TIME_SENSITIVE_MOCK) {
|
const id = Date.now();
|
const taskCode = `${data.materialType === "单丝" ? "SX" : "JX"}-${String(id).slice(-10)}`;
|
mockTasks.unshift({
|
id,
|
taskCode,
|
...data,
|
itemCount: 0,
|
furnaceInTime: "",
|
furnaceOutTime: "",
|
taskStatus: 0,
|
});
|
mockItems[String(id)] = [];
|
addMockOperation(
|
id,
|
1,
|
"新增",
|
"",
|
"待开始",
|
`${data.initiatorName}创建时效任务`,
|
data.initiatorName
|
);
|
return mockResult({ id, taskCode }, "时效任务新增成功");
|
}
|
return request<BaseResult<any>>({
|
url: "/timeSensitiveTask/add",
|
method: "POST",
|
data,
|
});
|
},
|
|
update(data: TimeSensitiveTaskForm & { id: number | string }) {
|
if (USE_TIME_SENSITIVE_MOCK) {
|
const task = mockTasks.find((item) => String(item.id) === String(data.id));
|
if (task) Object.assign(task, data);
|
addMockOperation(
|
data.id,
|
2,
|
"修改",
|
"待开始",
|
"待开始",
|
"修改时效任务基础信息",
|
data.initiatorName
|
);
|
return mockResult(task, "时效任务修改成功");
|
}
|
return request<BaseResult<any>>({
|
url: "/timeSensitiveTask/update",
|
method: "POST",
|
data,
|
});
|
},
|
|
delete(id: number | string) {
|
if (USE_TIME_SENSITIVE_MOCK) {
|
const index = mockTasks.findIndex((item) => String(item.id) === String(id));
|
if (index >= 0) mockTasks.splice(index, 1);
|
delete mockItems[String(id)];
|
delete mockOperations[String(id)];
|
delete mockInspections[String(id)];
|
return mockResult(true, "时效任务删除成功");
|
}
|
return request<BaseResult<any>>({
|
url: "/timeSensitiveTask/delete",
|
method: "DELETE",
|
data: { id },
|
});
|
},
|
|
start(data: TimeSensitiveTaskStartForm) {
|
if (USE_TIME_SENSITIVE_MOCK) {
|
const task = mockTasks.find((item) => String(item.id) === String(data.id));
|
if (task) Object.assign(task, data, { taskStatus: 1 });
|
addMockOperation(
|
data.id,
|
2,
|
"开始时效",
|
"待开始",
|
"时效中",
|
`${data.inspectorName}确认任务信息并开始时效`,
|
data.inspectorName
|
);
|
return mockResult(task, "时效已开始");
|
}
|
return request<BaseResult<any>>({
|
url: "/timeSensitiveTask/start",
|
method: "POST",
|
data,
|
});
|
},
|
|
checkEnd(id: number | string) {
|
if (USE_TIME_SENSITIVE_MOCK) {
|
return mockResult({
|
canEnd: false,
|
reachedDuration: false,
|
elapsedMinutes: 120,
|
requiredMinutes: 360,
|
message: "Mock:尚未达到设定时效时长。",
|
});
|
}
|
return request<BaseResult<any>>({
|
url: "/timeSensitiveTask/checkEnd",
|
method: "GET",
|
data: { id },
|
});
|
},
|
|
end(data: { id: number | string; forceEnd: boolean }) {
|
if (USE_TIME_SENSITIVE_MOCK) {
|
const task = mockTasks.find((item) => String(item.id) === String(data.id));
|
if (task) Object.assign(task, { taskStatus: 2, furnaceOutTime: mockDateTime() });
|
addMockOperation(
|
data.id,
|
3,
|
"结束时效",
|
"时效中",
|
"时效结束",
|
data.forceEnd ? "未达到时长,确认强制结束时效" : "结束时效任务",
|
task?.inspectorName || "操作人"
|
);
|
return mockResult(task, "时效已结束");
|
}
|
return request<BaseResult<any>>({
|
url: "/timeSensitiveTask/end",
|
method: "POST",
|
data,
|
});
|
},
|
|
queryCandidates(params: TimeSensitiveCandidateQuery) {
|
if (USE_TIME_SENSITIVE_MOCK) {
|
const existingIds = new Set(
|
(mockItems[String(params.taskId)] || []).map((item) => String(item.id))
|
);
|
let rows = mockMaterialPool[params.materialType]
|
.filter((item) => !existingIds.has(String(item.id)))
|
.map((item) => ({ ...item }));
|
if (params.model) {
|
const model = params.model.trim().toUpperCase();
|
rows = rows.filter((item) =>
|
String(item.model || "")
|
.toUpperCase()
|
.includes(model)
|
);
|
}
|
if (params.materialCode) {
|
const code = params.materialCode.trim().toUpperCase();
|
rows = rows.filter(
|
(item) =>
|
mockMaterialCode(item).toUpperCase().includes(code) ||
|
String(item.id).toUpperCase() === code ||
|
String(item.outputId || "").toUpperCase() === code
|
);
|
}
|
const current = Number(params.current || 1);
|
const size = Number(params.size || 10);
|
return mockResult<PageResult>({
|
records: rows.slice((current - 1) * size, current * size),
|
total: rows.length,
|
current,
|
size,
|
pages: current * size < rows.length,
|
});
|
}
|
return request<BaseResult<PageResult>>({
|
url: "/timeSensitiveTask/queryCandidates",
|
method: "GET",
|
data: params,
|
});
|
},
|
|
addItems(data: { taskId: number | string; itemIds: Array<number | string> }) {
|
if (USE_TIME_SENSITIVE_MOCK) {
|
const key = String(data.taskId);
|
mockItems[key] ||= [];
|
const existingIds = new Set(mockItems[key].map((item) => String(item.id)));
|
data.itemIds.forEach((id) => {
|
const material = cloneMockMaterial(id);
|
if (material && !existingIds.has(String(id))) mockItems[key].push(material);
|
});
|
updateMockItemCount(data.taskId);
|
const task = mockTasks.find((item) => String(item.id) === key);
|
addMockOperation(
|
data.taskId,
|
1,
|
"新增明细",
|
"待开始",
|
"待开始",
|
`新增 ${data.itemIds.length} 条时效明细`,
|
task?.initiatorName || "操作人"
|
);
|
return mockResult(true, "时效明细新增成功");
|
}
|
return request<BaseResult<any>>({
|
url: "/timeSensitiveTask/addItems",
|
method: "POST",
|
data,
|
});
|
},
|
|
deleteItems(data: { taskId: number | string; itemIds: Array<number | string> }) {
|
if (USE_TIME_SENSITIVE_MOCK) {
|
const key = String(data.taskId);
|
const idSet = new Set(data.itemIds.map(String));
|
mockItems[key] = (mockItems[key] || []).filter((item) => !idSet.has(String(item.id)));
|
updateMockItemCount(data.taskId);
|
const task = mockTasks.find((item) => String(item.id) === key);
|
addMockOperation(
|
data.taskId,
|
4,
|
"删除明细",
|
"待开始",
|
"待开始",
|
`删除 ${data.itemIds.length} 条时效明细`,
|
task?.initiatorName || "操作人"
|
);
|
return mockResult(true, "时效明细删除成功");
|
}
|
return request<BaseResult<any>>({
|
url: "/timeSensitiveTask/deleteItems",
|
method: "POST",
|
data,
|
});
|
},
|
|
getMachines() {
|
if (USE_TIME_SENSITIVE_MOCK) return mockResult(mockMachines.map((item) => ({ ...item })));
|
return request<BaseResult<any[]>>({
|
url: "/device/querydeviceSx",
|
method: "GET",
|
});
|
},
|
|
getUsers() {
|
if (USE_TIME_SENSITIVE_MOCK) return mockResult(mockUsers.map((item) => ({ ...item })));
|
return request<BaseResult<any[]>>({
|
url: "/team/getUser",
|
method: "GET",
|
});
|
},
|
|
getOperationRecords(recordId: number | string) {
|
if (USE_TIME_SENSITIVE_MOCK) {
|
return mockResult<any[]>(
|
(mockOperations[String(recordId)] || []).map((item) => ({ ...item }))
|
);
|
}
|
return request<BaseResult<any[]>>({
|
url: "/operationRecord/list",
|
method: "POST",
|
data: { tableName: "time_sensitive_task", recordId },
|
});
|
},
|
|
getInspectionDetails(id: number | string) {
|
if (USE_TIME_SENSITIVE_MOCK) {
|
return mockResult<any[]>((mockInspections[String(id)] || []).map((item) => ({ ...item })));
|
}
|
return request<BaseResult<any>>({
|
url: "/timelinessInspection/getDetailById",
|
method: "GET",
|
data: { id },
|
});
|
},
|
|
saveInspectionDetails(data: TimelinessInspectionDetailForm[]) {
|
if (USE_TIME_SENSITIVE_MOCK) {
|
const inspectionId = data[0]?.timelinessInspectionId;
|
if (inspectionId !== undefined) {
|
mockInspections[String(inspectionId)] = data.map((item, index) => ({
|
...item,
|
id: item.id || Date.now() + index,
|
createTime: (item as any).createTime || mockDateTime(),
|
}));
|
}
|
return mockResult(true, "巡检记录保存成功");
|
}
|
return request<BaseResult<any>>({
|
url: "/timelinessInspectionDetail/add",
|
method: "POST",
|
data,
|
});
|
},
|
|
deleteInspectionDetail(id: number | string) {
|
if (USE_TIME_SENSITIVE_MOCK) {
|
Object.keys(mockInspections).forEach((key) => {
|
mockInspections[key] = mockInspections[key].filter(
|
(item) => String(item.id) !== String(id)
|
);
|
});
|
return mockResult(true, "巡检记录删除成功");
|
}
|
return request<BaseResult<any>>({
|
url: "/timelinessInspectionDetail/delete",
|
method: "DELETE",
|
data: { id },
|
});
|
},
|
};
|
|
export default TimeSensitiveTaskApi;
|