368 lines
9.2 KiB
TypeScript
368 lines
9.2 KiB
TypeScript
import request from '@/utils/http'
|
|
|
|
export type ProductionTaskOperateScope = 'mine' | 'manage'
|
|
|
|
function scopeQuery(scope?: ProductionTaskOperateScope) {
|
|
return scope === 'mine' ? { operateScope: 'mine' } : undefined
|
|
}
|
|
|
|
export function fetchCreateProductionTask(data: Record<string, any>) {
|
|
return request.post({ url: '/web/admin/production-tasks', params: data })
|
|
}
|
|
|
|
export function fetchCreateProductionTasksFromSet(data: { workOrderId: string; setId: string }) {
|
|
return request.post<{ createdCount: number; list: any[] }>({
|
|
url: '/web/admin/production-tasks/from-set',
|
|
params: data
|
|
})
|
|
}
|
|
|
|
export function fetchProductionTaskList(params?: {
|
|
page?: number
|
|
pageSize?: number
|
|
keyword?: string
|
|
taskStatus?: string
|
|
workOrderId?: string
|
|
startedTimeStart?: string
|
|
startedTimeEnd?: string
|
|
includeStepSummary?: boolean
|
|
}) {
|
|
return request.get<{
|
|
list: any[]
|
|
total: number
|
|
page: number
|
|
pageSize: number
|
|
totalPages: number
|
|
}>({ url: '/web/admin/production-tasks', params })
|
|
}
|
|
|
|
/** 批量拉取当前页工单下的生产任务(含步骤摘要),POST 避免 GET URL 过长 */
|
|
export function fetchProductionTasksByWorkOrderIds(workOrderIds: string[]) {
|
|
const ids = workOrderIds.map((id) => String(id || '').trim()).filter(Boolean)
|
|
if (!ids.length) {
|
|
return Promise.resolve({ list: [] as any[], total: 0, page: 1, pageSize: 0, totalPages: 0 })
|
|
}
|
|
return request.post<{
|
|
list: any[]
|
|
total: number
|
|
page: number
|
|
pageSize: number
|
|
totalPages: number
|
|
}>({
|
|
url: '/web/admin/production-tasks/list-by-work-orders',
|
|
params: {
|
|
workOrderIds: ids,
|
|
includeStepSummary: true,
|
|
pageSize: Math.min(500, ids.length * 100)
|
|
}
|
|
})
|
|
}
|
|
|
|
export function groupProductionTasksByWorkOrderId(
|
|
tasks: Record<string, any>[]
|
|
): Record<string, Record<string, any>[]> {
|
|
const map: Record<string, Record<string, any>[]> = {}
|
|
for (const task of tasks || []) {
|
|
const workOrderId = String(task.workOrderId || '').trim()
|
|
if (!workOrderId) continue
|
|
if (!map[workOrderId]) map[workOrderId] = []
|
|
map[workOrderId].push(task)
|
|
}
|
|
return map
|
|
}
|
|
|
|
export function fetchMyProductionTasks(params: {
|
|
page?: number
|
|
pageSize?: number
|
|
keyword?: string
|
|
taskStatus?: string
|
|
workOrderType?: string
|
|
receptionSource?: string
|
|
bizType?: string
|
|
scope: 'current' | 'history'
|
|
includeStepSummary?: boolean
|
|
excludeVoidProtocol?: boolean
|
|
plannedStartTimeStart?: string
|
|
plannedStartTimeEnd?: string
|
|
}) {
|
|
return request.get<{
|
|
list: any[]
|
|
total: number
|
|
page: number
|
|
pageSize: number
|
|
totalPages: number
|
|
}>({ url: '/web/admin/production-tasks/mine', params })
|
|
}
|
|
|
|
export function fetchForwardProductionTask(
|
|
id: string,
|
|
data: { toUserId: string; remark?: string },
|
|
operateScope: ProductionTaskOperateScope = 'mine'
|
|
) {
|
|
return request.post({
|
|
url: `/web/admin/production-tasks/${id}/forward`,
|
|
data,
|
|
params: { operateScope }
|
|
})
|
|
}
|
|
|
|
export function fetchReassignProductionTask(
|
|
id: string,
|
|
data: { assigneeUserId: string; remark?: string }
|
|
) {
|
|
return request.put({
|
|
url: `/web/admin/production-tasks/${id}/assignee`,
|
|
data
|
|
})
|
|
}
|
|
|
|
export function fetchDispatchProductionTaskSteps(
|
|
taskId: string,
|
|
data: {
|
|
steps: Array<{
|
|
stepId: string
|
|
assigneeUserIds: string[]
|
|
plannedStartTime?: string | null
|
|
}>
|
|
},
|
|
operateScope?: ProductionTaskOperateScope
|
|
) {
|
|
return request.put<any>({
|
|
url: `/web/admin/production-tasks/${taskId}/steps/dispatch`,
|
|
data,
|
|
params: scopeQuery(operateScope)
|
|
})
|
|
}
|
|
|
|
export function fetchProductionTaskDetail(
|
|
id: string,
|
|
options?: { includeStepSubTables?: boolean }
|
|
) {
|
|
const params =
|
|
options?.includeStepSubTables === false ? { includeStepSubTables: false } : undefined
|
|
return request.get<any>({ url: `/web/admin/production-tasks/${id}`, params })
|
|
}
|
|
|
|
export type ProductionTaskEditorInitPayload = {
|
|
task: Record<string, any>
|
|
processLibrary?: Record<string, any>[]
|
|
options?: {
|
|
processCategories: Record<string, any>[]
|
|
sops: Record<string, any>[]
|
|
outputTypes: Record<string, any>[]
|
|
equipments: Record<string, any>[]
|
|
reagents: Record<string, any>[]
|
|
consumables: Record<string, any>[]
|
|
itemUnits: Record<string, any>[]
|
|
}
|
|
}
|
|
|
|
/** 编辑生产任务弹窗初始化(任务详情 + 工艺库 + 步骤配置参考数据,聚合为单次请求) */
|
|
export function fetchProductionTaskEditorInit(
|
|
id: string,
|
|
options?: { includeReference?: boolean }
|
|
) {
|
|
const params = options?.includeReference === false ? { includeReference: false } : undefined
|
|
return request.get<ProductionTaskEditorInitPayload>({
|
|
url: `/web/admin/production-tasks/${id}/editor-init`,
|
|
params
|
|
})
|
|
}
|
|
|
|
export function fetchUpdateProductionTask(id: string, data: Record<string, any>) {
|
|
return request.put({ url: `/web/admin/production-tasks/${id}`, params: data })
|
|
}
|
|
|
|
export function fetchUpdateProductionTaskStatus(
|
|
id: string,
|
|
data: Record<string, any>,
|
|
operateScope?: ProductionTaskOperateScope
|
|
) {
|
|
return request.put({
|
|
url: `/web/admin/production-tasks/${id}/status`,
|
|
data,
|
|
params: scopeQuery(operateScope)
|
|
})
|
|
}
|
|
|
|
export function fetchDeleteProductionTask(id: string) {
|
|
return request.del({ url: `/web/admin/production-tasks/${id}` })
|
|
}
|
|
|
|
export function fetchAddTaskStep(
|
|
taskId: string,
|
|
data: Record<string, any>,
|
|
operateScope?: ProductionTaskOperateScope
|
|
) {
|
|
return request.post({
|
|
url: `/web/admin/production-tasks/${taskId}/steps`,
|
|
data,
|
|
params: scopeQuery(operateScope)
|
|
})
|
|
}
|
|
|
|
export function fetchUpdateTaskStep(
|
|
taskId: string,
|
|
stepId: string,
|
|
data: Record<string, any>,
|
|
operateScope?: ProductionTaskOperateScope
|
|
) {
|
|
return request.put({
|
|
url: `/web/admin/production-tasks/${taskId}/steps/${stepId}`,
|
|
data,
|
|
params: scopeQuery(operateScope)
|
|
})
|
|
}
|
|
|
|
export function fetchDeleteTaskStep(
|
|
taskId: string,
|
|
stepId: string,
|
|
operateScope?: ProductionTaskOperateScope
|
|
) {
|
|
return request.del({
|
|
url: `/web/admin/production-tasks/${taskId}/steps/${stepId}`,
|
|
params: scopeQuery(operateScope)
|
|
})
|
|
}
|
|
|
|
export function fetchReplaceStepReagents(
|
|
taskId: string,
|
|
stepId: string,
|
|
data: any[],
|
|
operateScope?: ProductionTaskOperateScope
|
|
) {
|
|
return request.put({
|
|
url: `/web/admin/production-tasks/${taskId}/steps/${stepId}/reagents`,
|
|
data,
|
|
params: scopeQuery(operateScope)
|
|
})
|
|
}
|
|
|
|
export function fetchReplaceStepConsumables(
|
|
taskId: string,
|
|
stepId: string,
|
|
data: any[],
|
|
operateScope?: ProductionTaskOperateScope
|
|
) {
|
|
return request.put({
|
|
url: `/web/admin/production-tasks/${taskId}/steps/${stepId}/consumables`,
|
|
data,
|
|
params: scopeQuery(operateScope)
|
|
})
|
|
}
|
|
|
|
export function fetchReplaceStepConfiguredReagents(
|
|
taskId: string,
|
|
stepId: string,
|
|
data: any[],
|
|
operateScope?: ProductionTaskOperateScope
|
|
) {
|
|
return request.put({
|
|
url: `/web/admin/production-tasks/${taskId}/steps/${stepId}/configured-reagents`,
|
|
data,
|
|
params: scopeQuery(operateScope)
|
|
})
|
|
}
|
|
|
|
export function fetchReplaceStepDataCollection(
|
|
taskId: string,
|
|
stepId: string,
|
|
data: any[],
|
|
operateScope?: ProductionTaskOperateScope
|
|
) {
|
|
return request.put({
|
|
url: `/web/admin/production-tasks/${taskId}/steps/${stepId}/data-collection`,
|
|
data,
|
|
params: scopeQuery(operateScope)
|
|
})
|
|
}
|
|
|
|
export function fetchSetTaskInputs(
|
|
taskId: string,
|
|
data: any[] | Record<string, any>,
|
|
operateScope?: ProductionTaskOperateScope
|
|
) {
|
|
return request.post({
|
|
url: `/web/admin/production-tasks/${taskId}/inputs`,
|
|
data,
|
|
params: scopeQuery(operateScope)
|
|
})
|
|
}
|
|
|
|
export interface SpawnTemporaryWorkOrderResult {
|
|
workOrder: {
|
|
id: string
|
|
workOrderNo: string
|
|
workOrderStatus: string
|
|
remark?: string
|
|
}
|
|
sourceTaskId: string
|
|
sourceTaskNo: string
|
|
inputItems: Array<{
|
|
inputType: string
|
|
inputId?: string
|
|
inputCode?: string
|
|
inputName?: string
|
|
remark?: string
|
|
}>
|
|
}
|
|
|
|
export function fetchSpawnTemporaryWorkOrderFromTask(
|
|
taskId: string,
|
|
data: { remark?: string },
|
|
operateScope?: ProductionTaskOperateScope
|
|
) {
|
|
return request.post<SpawnTemporaryWorkOrderResult>({
|
|
url: `/web/admin/production-tasks/${taskId}/spawn-temporary-work-order`,
|
|
data,
|
|
params: scopeQuery(operateScope)
|
|
})
|
|
}
|
|
|
|
export function fetchSetTaskOutputs(
|
|
taskId: string,
|
|
data: any[] | Record<string, any>,
|
|
operateScope?: ProductionTaskOperateScope
|
|
) {
|
|
return request.post({
|
|
url: `/web/admin/production-tasks/${taskId}/outputs`,
|
|
data,
|
|
params: scopeQuery(operateScope)
|
|
})
|
|
}
|
|
|
|
export function fetchReorderTaskSteps(
|
|
data: { taskId: string; stepIds: string[] },
|
|
operateScope?: ProductionTaskOperateScope
|
|
) {
|
|
return request.put({
|
|
url: '/web/admin/production-tasks/step/reorder',
|
|
data,
|
|
params: scopeQuery(operateScope)
|
|
})
|
|
}
|
|
|
|
export function fetchCopyTaskStep(
|
|
data: { taskId: string; stepId: string },
|
|
operateScope?: ProductionTaskOperateScope
|
|
) {
|
|
return request.post({
|
|
url: `/web/admin/production-tasks/${data.taskId}/steps/${data.stepId}/copy`,
|
|
data: {},
|
|
params: scopeQuery(operateScope)
|
|
})
|
|
}
|
|
|
|
export function fetchReplaceStepOutputs(
|
|
taskId: string,
|
|
stepId: string,
|
|
data: any[],
|
|
operateScope?: ProductionTaskOperateScope
|
|
) {
|
|
return request.put({
|
|
url: `/web/admin/production-tasks/${taskId}/steps/${stepId}/outputs`,
|
|
data,
|
|
params: scopeQuery(operateScope)
|
|
})
|
|
}
|