提交
This commit is contained in:
1 parent
04d462ad43
commit
7e9155fef1
7 files changed
+1754
-68
No files matched your search
@@ -0,0 +1,106 @@
|
||||
import type { QcTask } from '../api/qc-task'
|
||||
|
||||
export type QcTaskListLabItem = { kind: 'lab'; task: QcTask }
|
||||
export type QcTaskListOrphanThirdItem = { kind: 'orphan-third'; task: QcTask }
|
||||
export type QcTaskListCompanyItem = {
|
||||
kind: 'company'
|
||||
companyId: string
|
||||
companyName: string
|
||||
tasks: QcTask[]
|
||||
}
|
||||
export type QcTaskListDisplayItem =
|
||||
| QcTaskListLabItem
|
||||
| QcTaskListOrphanThirdItem
|
||||
| QcTaskListCompanyItem
|
||||
|
||||
function trimId(v?: string) {
|
||||
return (v || '').trim()
|
||||
}
|
||||
|
||||
/** 自检卡在前(原序);有 companyId 的第三方按首次出现公司顺序分组;无 companyId 降级为 orphan-third */
|
||||
export function buildTaskListDisplayItems(tasks: QcTask[]): QcTaskListDisplayItem[] {
|
||||
const lab: QcTaskListDisplayItem[] = []
|
||||
const orphans: QcTaskListDisplayItem[] = []
|
||||
const companyOrder: string[] = []
|
||||
const companyMap = new Map<string, QcTaskListCompanyItem>()
|
||||
|
||||
for (const t of tasks || []) {
|
||||
if ((t.taskType || '').trim() === 'sysz') {
|
||||
lab.push({ kind: 'lab', task: t })
|
||||
continue
|
||||
}
|
||||
if ((t.taskType || '').trim() !== 'dsfjc') {
|
||||
lab.push({ kind: 'lab', task: t })
|
||||
continue
|
||||
}
|
||||
const cid = trimId(t.companyId)
|
||||
if (!cid) {
|
||||
orphans.push({ kind: 'orphan-third', task: t })
|
||||
continue
|
||||
}
|
||||
let g = companyMap.get(cid)
|
||||
if (!g) {
|
||||
g = {
|
||||
kind: 'company',
|
||||
companyId: cid,
|
||||
companyName: (t.companyName || '').trim() || '第三方公司',
|
||||
tasks: []
|
||||
}
|
||||
companyMap.set(cid, g)
|
||||
companyOrder.push(cid)
|
||||
}
|
||||
g.tasks.push(t)
|
||||
}
|
||||
|
||||
return [...lab, ...companyOrder.map((id) => companyMap.get(id)!), ...orphans]
|
||||
}
|
||||
|
||||
export function companyGroupProgress(tasks: QcTask[]) {
|
||||
const list = tasks || []
|
||||
const completed = list.filter((t) => (t.taskStatus || '').trim() === 'ywc').length
|
||||
return { completed, total: list.length }
|
||||
}
|
||||
|
||||
function timeMs(v?: string) {
|
||||
if (!v) return 0
|
||||
const n = Date.parse(String(v).replace(/-/g, '/'))
|
||||
return Number.isFinite(n) ? n : 0
|
||||
}
|
||||
|
||||
export function pickSharedRemarkAndAttachments(tasks: QcTask[]): {
|
||||
remark: string
|
||||
thirdPartyAttachments: string
|
||||
attachmentFiles: NonNullable<QcTask['attachmentFiles']>
|
||||
} {
|
||||
const list = [...(tasks || [])].sort((a, b) => timeMs(b.updateTime) - timeMs(a.updateTime))
|
||||
let remark = ''
|
||||
let thirdPartyAttachments = ''
|
||||
let attachmentFiles: NonNullable<QcTask['attachmentFiles']> = []
|
||||
for (const t of list) {
|
||||
if (!remark && (t.remark || '').trim()) remark = (t.remark || '').trim()
|
||||
const urls = (t.thirdPartyAttachments || '').trim()
|
||||
const files = t.attachmentFiles || []
|
||||
if (!thirdPartyAttachments && (urls || files.length)) {
|
||||
thirdPartyAttachments = urls
|
||||
attachmentFiles = files.length ? [...files] : []
|
||||
}
|
||||
if (remark && (thirdPartyAttachments || attachmentFiles.length)) break
|
||||
}
|
||||
return { remark, thirdPartyAttachments, attachmentFiles }
|
||||
}
|
||||
|
||||
export function uniqueAssigneeNames(tasks: QcTask[]): string {
|
||||
const names: string[] = []
|
||||
const seen = new Set<string>()
|
||||
for (const t of tasks || []) {
|
||||
const raw = (t.assigneeUserNames || '').trim()
|
||||
if (!raw) continue
|
||||
for (const part of raw.split(/[,,、]/)) {
|
||||
const n = part.trim()
|
||||
if (!n || seen.has(n)) continue
|
||||
seen.add(n)
|
||||
names.push(n)
|
||||
}
|
||||
}
|
||||
return names.join('、') || '—'
|
||||
}
|
||||
Reference in new issue
Block a user