feat: add production task set API client and item mapping

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-08-18 16:16:04 +08:00
1 parent 49e208c241
commit d60d4bd4b6
4 files changed
+162

No files matched your search

+95
View File
@@ -0,0 +1,95 @@
import request from '@/utils/http'
type PageList<T> = {
list: T[]
total: number
page: number
pageSize: number
totalPages: number
}
export type ProductionTaskSetItem = {
id?: string
taskName: string
routeId?: string
routeName?: string
description?: string
remark?: string
orderNum?: number
}
export type ProductionTaskSet = {
id: string
setName: string
status: string
itemCount?: number
items?: ProductionTaskSetItem[]
remark?: string
createTime?: string
skippedEmptyNameCount?: number
}
export type ProductionTaskSetPayload = {
setName: string
status?: string
remark?: string
items: Array<{
taskName: string
routeId?: string
description?: string
remark?: string
}>
}
export function fetchProductionTaskSetList(params?: {
page?: number
pageSize?: number
keyword?: string
status?: string
}) {
return request.get<PageList<ProductionTaskSet>>({
url: '/web/admin/production-task-sets',
params
})
}
export function fetchProductionTaskSetsActive() {
return request.get<{ list: ProductionTaskSet[] }>({
url: '/web/admin/production-task-sets/active'
})
}
export function fetchProductionTaskSetDetail(id: string) {
return request.get<ProductionTaskSet>({
url: `/web/admin/production-task-sets/${id}`
})
}
export function fetchCreateProductionTaskSet(data: ProductionTaskSetPayload) {
return request.post<ProductionTaskSet>({
url: '/web/admin/production-task-sets',
params: data
})
}
export function fetchUpdateProductionTaskSet(id: string, data: Partial<ProductionTaskSetPayload>) {
return request.put<ProductionTaskSet>({
url: `/web/admin/production-task-sets/${id}`,
params: data
})
}
export function fetchDeleteProductionTaskSet(id: string) {
return request.del({ url: `/web/admin/production-task-sets/${id}` })
}
export function fetchCreateProductionTaskSetFromWorkOrder(data: {
workOrderId: string
setName: string
remark?: string
}) {
return request.post<ProductionTaskSet>({
url: '/web/admin/production-task-sets/from-work-order',
params: data
})
}
+7
View File
@@ -10,6 +10,13 @@ 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
@@ -0,0 +1,30 @@
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { mapWorkOrderTasksToSetItems } from './production-task-set'
describe('mapWorkOrderTasksToSetItems', () => {
it('skips empty names and keeps route/description/remark', () => {
const { items, skippedEmptyNameCount } = mapWorkOrderTasksToSetItems([
{ taskName: '分离', routeId: 'r1', routeName: '路线A', description: 'd', remark: 'm' },
{ taskName: ' ', routeId: 'r2' },
{ taskName: '培养' }
])
assert.equal(skippedEmptyNameCount, 1)
assert.deepEqual(items, [
{
taskName: '分离',
routeId: 'r1',
routeName: '路线A',
description: 'd',
remark: 'm'
},
{
taskName: '培养',
routeId: '',
routeName: '',
description: '',
remark: ''
}
])
})
})
@@ -0,0 +1,30 @@
export type ProductionTaskSetItemPreview = {
taskName: string
routeId: string
routeName: string
description: string
remark: string
}
export function mapWorkOrderTasksToSetItems(tasks: Record<string, any>[] | undefined): {
items: ProductionTaskSetItemPreview[]
skippedEmptyNameCount: number
} {
const items: ProductionTaskSetItemPreview[] = []
let skippedEmptyNameCount = 0
for (const row of tasks || []) {
const taskName = String(row.taskName || '').trim()
if (!taskName) {
skippedEmptyNameCount += 1
continue
}
items.push({
taskName,
routeId: String(row.routeId || '').trim(),
routeName: String(row.routeName || '').trim(),
description: String(row.description || '').trim(),
remark: String(row.remark || '').trim()
})
}
return { items, skippedEmptyNameCount }
}