import type { Demand, Fields, AcceptanceItem } from './demand.ts'; import type { ReviewPerson } from './demand-review.ts'; export type Decision = { actor: ReviewPerson; time: string; approved: boolean; comment: string }; export type DeliveryPlan = { developer: string; testDate: string; releaseDate: string; version?: number; hours?: number; feedbackDate?: string; priority?: Fields['priority']; designRequired?: boolean; notes?: string; proposalVersion?: number; proposedBy?: ReviewPerson; proposedAt?: string; decision?: Decision; }; export type ChangeRecord = { id?: string; time: string; content: string; reason: string; actor: string; status: string; originalVersion: string; originalFields?: Fields; originalStatus?: string; assessment?: { time: string; actor: ReviewPerson; impact: string; fields: Fields; plan: DeliveryPlan }; decision?: Decision; }; export type TestingRound = { testVersion: string; environment: string; deadline: string; items: AcceptanceItem[]; instructions: string; round?: number; documentVersion?: string; selfTest?: string; codeReview?: string; integration?: string; actor?: ReviewPerson; time?: string; withdrawnAt?: string; }; export type Defect = { id: string; title: string; steps: string; expected: string; actual: string; evidence: string; version: string; blocking: boolean; reporter: ReviewPerson; time: string; status: '待处理' | '修复中' | '待复验' | '已关闭' | '待确认遗留' | '已确认遗留'; resolution?: string; fixVersion?: string; dueDate?: string; events: { time: string; actor: ReviewPerson; action: string; notes: string }[]; }; export type Release = { id: string; version: string; previousVersion: string; time: string; actor: ReviewPerson; acceptanceRound: number; documentVersion: string; rollbackPlan: string; backup: string; deployment: string; verificationPlan: string; observationMinutes: number; observeUntil: string; proposalVersion?: number; emergency?: { incidentId: string; reason: string; fixSummary: string; selfTest: string; codeReview: string; integration: string; knownIssues: string; followUpPlan: string; followUpDate: string; followUp?: Decision }; verification?: { actor: ReviewPerson; time: string; passed: boolean; results: string }; recoveryRequest?: { targetVersion: string; plan: string; dataImpact: string; actor: ReviewPerson; time: string; decision?: Decision; withdrawn?: { actor: ReviewPerson; time: string; reason: string } }; rollback?: { actor: ReviewPerson; time: string; reason: string; runningVersion: string; verification: string; dataRestored: boolean }; completion?: { actor: ReviewPerson; time: string; handover: string; monitoring: string; summary: string }; }; export type Delivery = { plans?: DeliveryPlan[]; design?: { reference: string; notes: string; time: string; actor: ReviewPerson; proposalVersion: number; decision?: Decision }; designHistory?: NonNullable[]; kickoff?: { actor: ReviewPerson; time: string; technicalPlan: string; dependencies: string; design: string }; progress?: { percent: number; notes: string; next: string; time: string; actor: ReviewPerson }; blocker?: { reason: string; owner: string; dueDate: string; time: string; actor: ReviewPerson }; testing?: TestingRound[]; defects?: Defect[]; releases?: Release[]; incidents?: { id: string; time: string; actor: ReviewPerson; impact: string; reason: string; releaseId?: string }[]; retrospectives?: { time: string; actor: ReviewPerson; cause: string; actions: string; owner: string; dueDate: string }[]; }; export const pendingChange = (d: Demand) => d.changes.find(c => ['待开发评估与双方确认', '待开发评估', '待业务确认'].includes(c.status)); export const changeKey = (d: Demand, change: ChangeRecord) => change.id || `legacy-${d.changes.indexOf(change)}`; export const latestRelease = (d: Demand) => d.delivery?.releases?.at(-1); export const pendingRecovery = (d: Demand) => d.delivery?.releases?.find(r => !r.rollback && r.recoveryRequest && !r.recoveryRequest.decision && !r.recoveryRequest.withdrawn); export const pendingEmergencyVerification = (d: Demand) => d.delivery?.releases?.find(r => !r.rollback && r.emergency && !r.emergency.followUp); export const activeIncident = (d: Demand) => d.delivery?.incidents?.findLast(i => i.releaseId === latestRelease(d)?.id); export const designCurrent = (d: Demand) => Boolean(planConfirmed(d) && d.delivery?.design && d.delivery.design.proposalVersion === d.review?.proposals.at(-1)?.version); export const designConfirmed = (d: Demand) => designCurrent(d) && Boolean(d.delivery?.design?.decision?.approved); export function nextAcceptanceId(items: Pick[]): string { const used = new Set(items.map(item => item.id.trim())); let index = 1; while (used.has(`AC-${String(index).padStart(2, '0')}`)) index++; return `AC-${String(index).padStart(2, '0')}`; } export const unresolvedDefects = (d: Demand) => (d.delivery?.defects ?? []).filter(x => !['已关闭', '已确认遗留'].includes(x.status)); export const planCurrent = (d: Demand) => Boolean(d.plan && d.plan.proposalVersion === d.review?.proposals.at(-1)?.version && d.review?.proposals.at(-1)?.decision?.result === 'confirmed' && !d.review?.proposals.at(-1)?.invalidated); export const planConfirmed = (d: Demand) => planCurrent(d) && Boolean(d.plan?.decision?.approved); export function workflowTask(d: Demand): string | undefined { const business = d.access?.business ?? true; const developer = Boolean(d.access?.developer); if (!business && !developer || ['草稿', '已取消'].includes(d.status)) return; if (business && pendingRecovery(d)) return '确认数据恢复方案'; if (business && pendingEmergencyVerification(d)) return '补充紧急发布业务验证'; const change = pendingChange(d); if (change) return change.status === '待业务确认' ? business ? '确认需求变更' : undefined : developer ? '评估需求变更' : undefined; if (d.delivery?.blocker) return (business && d.delivery.blocker.owner === '业务方') || (developer && d.delivery.blocker.owner === '开发责任人') ? '处理阻塞事项' : undefined; const defects = d.delivery?.defects ?? []; if (business && defects.some(x => ['待复验', '待确认遗留'].includes(x.status))) return '复验缺陷或确认遗留'; if (developer && defects.some(x => ['待处理', '修复中'].includes(x.status))) return '处理缺陷'; if(developer&&defects.some(x=>x.status==='已确认遗留'&&x.dueDate&&x.dueDate<=new Date().toLocaleDateString('sv-SE',{timeZone:'Asia/Shanghai'})))return '处理到期遗留事项'; if(d.status==='已完成')return; if(planCurrent(d)&&d.plan?.decision?.approved===false)return developer?'调整交付计划':undefined; if (planCurrent(d)&&d.plan?.proposedAt && !d.plan.decision) return business ? '确认交付计划' : undefined; const stage = d.review?.proposals.at(-1); if (d.status === '待评审' && stage?.decision?.result === 'confirmed' && !stage.invalidated) return developer ? '提出交付计划' : undefined; if (['已排期', '开发中'].includes(d.status) && planConfirmed(d) && d.plan?.designRequired && !designConfirmed(d)) return designCurrent(d) && !d.delivery?.design?.decision ? business ? '确认设计' : undefined : developer ? '提交设计' : undefined; if (d.status === '已排期') return developer ? '开始开发' : undefined; if (d.status === '开发中') return developer ? '推进开发并提测' : undefined; if (d.status === '待验收') return business ? '提交业务验收结论' : undefined; if (d.status === '待发布') return developer ? '完成发布检查并登记发布' : undefined; if (d.status === '已上线') { return developer ? '生产验证与观察归档' : undefined; } } export function dueDate(d: Demand): string | undefined { if (d.access?.business && pendingEmergencyVerification(d)) return pendingEmergencyVerification(d)?.emergency?.followUpDate; if (d.delivery?.blocker) return d.delivery.blocker.dueDate; if (d.status === '待验收') return d.acceptance?.deadline; if (['已排期', '开发中'].includes(d.status)) return d.plan?.testDate; if (d.status === '待发布') return d.plan?.releaseDate; return d.delivery?.defects?.filter(x=>x.status==='已确认遗留'&&x.dueDate).map(x=>x.dueDate!).sort()[0]; }