huang
8 天以前 f13ba9e05f653bc3083c4d17fe8658e67054131e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
import request from '@/utils/request';
import { ElMessage } from 'element-plus';
import { de } from 'element-plus/es/locale/index.mjs';
 
// 格式化时间戳为年月日时间字符串的函数
function formatTimestamp(timestamp: string | number | Date): string {
    const date = new Date(timestamp)
    const year = date.getFullYear()
    const month = String(date.getMonth() + 1).padStart(2, '0')
    const day = String(date.getDate()).padStart(2, '0')
    const hours = String(date.getHours()).padStart(2, '0')
    const minutes = String(date.getMinutes()).padStart(2, '0')
    const seconds = String(date.getSeconds()).padStart(2, '0')
    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
}
// ==================== 仓储原片历史任务接口 ====================
// 历史任务查询方法
export const fetchHistoricalTasks = async (params: HistoryTaskParams) => {
    try {
        const response = await request.post("/glassStorage/rawGlassStorageHistoryTask/queryRawGlassHistoryTask", {
            pageNo: params.pageNo,
            pageSize: params.pageSize,
            taskState: params.taskState || [],
            taskType: params.taskType || [],
            beginDate: params.beginDate,
            endDate: params.endDate,
        });
        if (response?.code === 200 && response?.data) {
            ElMessage.success(response.message);
            const records = Array.isArray(response.data.records) ? response.data.records : [];
            // 格式化数据,添加非空判断
            const formattedData = records.map(record => ({
                ...record,
                formattedCreateTime: record?.createTime ? formatTimestamp(record.createTime) : '-',
                formattedUpdateTime: record?.updateTime ? formatTimestamp(record.updateTime) : '-',
            }));
            return {
                data: formattedData,
                total: response.data.total || 0
            };
        } else {
            const errorMessage = response?.message || '获取历史任务失败';
            ElMessage.error(errorMessage);
            throw new Error(errorMessage);
        }
    } catch (error) {
        console.error('Error fetching historical tasks:', error);
        ElMessage.error('获取历史任务失败');
        throw error;
    }
};
// 默认查询参数
export const getDefaultHistoryParams = (): HistoryTaskParams => {
    const getglobalDate = window.localStorage.getItem('getglobalDate');
    const defaultEndDate = getglobalDate ? formatTimestamp(new Date(getglobalDate)) : formatTimestamp(new Date());
 
    return {
        pageNo: 1,
        pageSize: 20,
        taskState: [],
        taskType: [],
        beginDate: window.localStorage.getItem('startTime') || '',
        endDate: defaultEndDate
    };
};
 
export interface HistoryTaskParams {
    pageNo: number
    pageSize: number
    taskState?: string[]
    taskType?: string[]
    beginDate?: string
    endDate?: string
    startSlot?: string
    targetSlot?: string
}
 
export interface HistoryTaskRecord {
    id: string
    createTime: string
    updateTime: string
    formattedCreateTime?: string
    formattedUpdateTime?: string
}
 
// ==================== 仓储原片详情接口 ====================
// 类型定义
export interface deviceIdParams {
    deviceIdList: number[]
}
 
export interface LeftingStationRawGlassDetailsParams {
    leftingStation: string
}
 
export interface InboundRequestsParams {
    leftingStation: string
}
 
export interface OutboundRequestParams {
    leftingStation: string;
    slot: string;
    rawWidth: string;
    rawHeight: string;
    rawThickness: string;
}
 
export interface BackWarehousingParams {
    leftingStation: string;
}
 
export interface RawGlassFormData {
    id: string;
    shelf: string;
    deviceId: string;
    slot: string;
    rawWidth: string;
    rawHeight: string;
    rawThickness: string;
    filmsId: string;
    rawMargin: string;
    remainQuantity: string;
    manufacturer: string;
    rawNumber: string;
}
 
export interface TaskRecord {
    id: string;
    createTime: string;
    updateTime: string;
    [key: string]: any;
}
 
// 查询所有消息接口
export const queryAllMessage = async () => {
    try {
        const response = await request.get("/glassStorage/rawJob/queryAllMessage");
        if (response.code === 200) {
            // 格式化任务列表时间
            const formattedTasks = response.data.historyTaskList.map((task: TaskRecord) => {
                const formattedTask = { ...task };
                if (formattedTask.createTime) {
                    formattedTask.createTime = formatTimestamp(formattedTask.createTime);
                }
                if (formattedTask.updateTime) {
                    formattedTask.updateTime = formatTimestamp(formattedTask.updateTime);
                }
                return formattedTask;
            });
            return {
                historyTaskList: formattedTasks,
                rawStorageSwitch: response.data.rawStorageSwitch
            };
        } else {
            ElMessage.warning(response.msg);
            throw new Error(response.msg);
        }
    } catch (error) {
        console.error('Error fetching all messages:', error);
        throw error;
    }
};
 
// 查询架子上原片详情列表
export const queryRawGlassList = async (params: deviceIdParams) => {
    try {
        const response = await request.post('/glassStorage/rawGlassStorageDetails/queryRawGlassList', {
            deviceIdList: params.deviceIdList
        });
        if (response.code === 200) {
            return response.data;
        } else {
            ElMessage.warning(response.data);
            throw new Error(response.data);
        }
    } catch (error) {
        console.error('Error fetching raw glass details:', error);
        throw error;
    }
};
 
// 查询所有架子状态
export const queryLeftingStation = async () => {
    try {
        const response = await request.post('/glassStorage/rawGlassStorageStation/queryLeftingStation', {});
        if (response.code === 200) {
            return response.data;
        } else {
            return [];
        }
    } catch (error) {
        ElMessage.error('获取架子状态失败');
        return [];
    }
};
 
// 查询吊装位架子
export const LeftingStationRawGlassDetails = async (params: LeftingStationRawGlassDetailsParams) => {
    try {
        const response = await request.post('/glassStorage/rawGlassStorageDetails/queryLeftingStationRawGlassDetails', {
            leftingStation: params.leftingStation,
        });
        if (response.code === 200) {
            params.leftingStation = '';
            return response.data;
        } else {
            return [];
        }
    } catch (error) {
        ElMessage.error('获取架子状态失败');
        return [];
    }
};
 
// 空架子到吊装位接口
export const InboundRequests = async (params: InboundRequestsParams) => {
    try {
        const response = await request.post("/glassStorage/rawGlassStorageDetails/warehousingRequest", {
            leftingStation: params.leftingStation,
        })
        if (response.code == 200) {
            ElMessage.success(response.message);
            params.leftingStation = '';
        } else {
            ElMessage.error(response.message);
        }
    }
    catch (error) {
        console.error(error);
    }
}
 
// 出库请求 - 架子到吊装位
export const outWarehousingRequest = async (params: OutboundRequestParams) => {
    try {
        const response = await request.post("/glassStorage/rawGlassStorageDetails/outWarehousingRequest", {
            leftingStation: params.leftingStation,
            slot: params.slot,
            rawWidth: params.rawWidth,
            rawHeight: params.rawHeight,
            rawThickness: params.rawThickness,
        });
        if (response.code === 200) {
            ElMessage.success(response.message);
            return response;
        } else {
            ElMessage.error(response.message);
            throw new Error(response.message);
        }
    } catch (error) {
        console.error('Error in outbound request:', error);
        throw error;
    }
};
 
// 回库请求 - 吊装位到架子
export const backWarehousing = async (params: BackWarehousingParams) => {
    try {
        const response = await request.post("/glassStorage/rawGlassStorageDetails/backWarehousing", {
            leftingStation: params.leftingStation,
        });
        if (response.code === 200) {
            ElMessage.success(response.message);
            return response;
        } else {
            ElMessage.error(response.message);
            throw new Error(response.message);
        }
    } catch (error) {
        console.error('Error in back warehousing:', error);
        throw error;
    }
};
 
// 原片解绑
export const rawGlassUnBind = async (id: string) => {
    try {
        const response = await request.post('/glassStorage/rawGlassStorageDetails/rawGlassUnBind', {
            id: id
        });
        if (response.code === 200) {
            ElMessage.success(response.message);
            return response;
        } else {
            ElMessage.error(response.msg);
            throw new Error(response.msg);
        }
    } catch (error) {
        console.error('Error unbinding raw glass:', error);
        throw error;
    }
};
 
// 删除原片详情
export const removeRawGlassDetails = async (id: string) => {
    try {
        const response = await request.post('/glassStorage/rawGlassStorageDetails/removeRawGlassDetails', {
            id: id
        });
        if (response.code === 200) {
            ElMessage.success(response.message);
            return response;
        } else {
            ElMessage.error(response.msg);
            throw new Error(response.msg);
        }
    } catch (error) {
        console.error('Error removing raw glass details:', error);
        throw error;
    }
};
 
// 更新架子状态
export const updateStorageCageState = async (params: { enableState: number; shelf: string }) => {
    try {
        const response = await request.post('/glassStorage/rawGlassStorageStation/updateStorageCageState', {
            enableState: params.enableState,
            shelf: params.shelf  
        });
        if (response.code === 200) {
            ElMessage.success(response.message);
            return response;
        } else {
            ElMessage.error(response.message);
            throw new Error(response.message);
        }
    } catch (error) {
        ElMessage.error('更新架子状态失败');
        throw error;
    }
};
 
// 查询未绑定原片详情列表
export const queryUnBindRawGlassList = async () => {
    try {
        const response = await request.post("/glassStorage/rawGlassStorageDetails/queryUnBindRawGlassList", {});
        if (response.code === 200) {
            ElMessage.success(response.message);
            return response.data;
        } else {
            ElMessage.error(response.message);
            throw new Error(response.message);
        }
    } catch (error) {
        console.error('Error querying unbound raw glass list:', error);
        throw error;
    }
};
 
// 添加原片详情
export const insertRawGlassDetails = async (formData: RawGlassFormData) => {
    try {
        const response = await request.post('/glassStorage/rawGlassStorageDetails/insertRawGlassDetails', {
            id: formData.id,
            deviceId: formData.deviceId,
            shelf: formData.shelf,
            slot: formData.slot,
            rawWidth: formData.rawWidth,
            rawHeight: formData.rawHeight,
            rawThickness: formData.rawThickness,
            filmsId: formData.filmsId,
            rawMargin: formData.rawMargin,
            remainQuantity: formData.remainQuantity,
            manufacturer: formData.manufacturer,
            rawNumber: formData.rawNumber,
        });
        if (response.code === 200) {
            ElMessage.success(response.message);
            return response;
        } else {
            ElMessage.error(response.message);
            throw new Error(response.message);
        }
    } catch (error) {
        console.error('Error inserting raw glass details:', error);
        throw error;
    }
};
 
// 原片入库 
export const glassWarehousing = async (formData: RawGlassFormData) => {
    try {
        const response = await request.post('/glassStorage/rawGlassStorageDetails/glassWarehousing', {
            id: formData.id,
            deviceId: formData.deviceId,
            shelf: formData.shelf,
            slot: formData.slot,
            rawWidth: formData.rawWidth,
            rawHeight: formData.rawHeight,
            rawThickness: formData.rawThickness,
            filmsId: formData.filmsId,
            rawMargin: formData.rawMargin,
            remainQuantity: formData.remainQuantity,
            manufacturer: formData.manufacturer,
            rawNumber: formData.rawNumber,
        });
        if (response.code === 200) {
            ElMessage.success(response.message);
            return response;
        } else {
            ElMessage.error(response.message);
            throw new Error(response.message);
        }
    } catch (error) {
        console.error('Error in glass warehousing:', error);
        throw error;
    }
};
 
// 更新原片详情
export const updateRawGlassDetails = async (params: {
    id: string;
    remainQuantity: string;
    rawMargin: string;
    rawWidth: string;
    rawHeight: string;
    rawThickness: string;
    filmsId: string;
    deviceId: string;
    shelf: string;
    slot: string;
    manufacturer: string;
    rawNumber: string;
}) => {
    try {
        const response = await request.post('/glassStorage/rawGlassStorageDetails/updateRawGlassDetails', params);
        if (response.code === 200) {
            ElMessage.success(response.message);
            return response;
        } else {
            ElMessage.error(response.message);
            throw new Error(response.message);
        }
    } catch (error) {
        console.error('Error updating raw glass details:', error);
        throw error;
    }
};
 
// // 任务成功处理
// export const taskSuccess = async (taskId: string) => {
//     try {
//         const url = `/glassStorage/rawGlassStorageTask/taskSuccess?taskId=${taskId}`;
//         const response = await request.post(url);
//         if (response.code === 200) {
//             ElMessage.success(response.message);
//             return response;
//         } else {
//             ElMessage.error(response.msg);
//             throw new Error(response.msg);
//         }
//     } catch (error) {
//         console.error('Error in task success:', error);
//         throw error;
//     }
// };
 
// // 任务失败处理
// export const taskError = async (taskId: string) => {
//     try {
//         const url = `/glassStorage/rawGlassStorageTask/taskError?taskId=${taskId}`;
//         const response = await request.post(url);
//         if (response.code === 200) {
//             ElMessage.success(response.message);
//             return response;
//         } else {
//             ElMessage.error(response.msg);
//             throw new Error(response.msg);
//         }
//     } catch (error) {
//         console.error('Error in task error:', error);
//         throw error;
//     }
// };
 
// 任务开关
export const rawStorageSwitch = async (switchValue: any) => {
    try {
        const response = await request.post('/glassStorage/rawJob/rawStorageSwitch', switchValue);
        if (response.code === 200) {
            ElMessage.success(response.message);
            return response.data;
        } else {
            ElMessage.error(response.message);
            throw new Error(response.message);
        }
    } catch (error) {
        console.error('Error in raw storage switch:', error);
        throw error;
    }
};
 
// 重新下发任务
export const reissueTask = async (taskId: string) => {
    try {
        const response = await request.post(`/glassStorage/rawGlassStorageHistoryTask/updateRawGlassHistoryTask`, { id: taskId, taskState: 0 });
        if (response.code === 200) {
            ElMessage.success(response.message);
            return response;
        } else {
            ElMessage.error(response.message);
            throw new Error(response.message);
        }
    } catch (error) {
        console.error('Error reissuing task:', error);
        throw error;
    }
};
// 删除
export const deleteTask = async (taskId: string) => {
    try {
        const response = await request.post(`/glassStorage/rawGlassStorageHistoryTask/removeRawGlassHistoryTask`, { id: taskId, taskState: 3 });
        if (response.code === 200) {
            ElMessage.success(response.message);
            return response;
        } else {
            ElMessage.error(response.message);
            throw new Error(response.message);
        }
    } catch (error) {
        console.error('Error reissuing task:', error);
        throw error;
    }
};