| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360 |
- 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 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)
- })
- }
|