修正按时交付统计并增加流程筛选

This commit is contained in:
江林铖 2026-08-28 09:34:58 +08:00
parent bcac7e0eab
commit c3cb493a1b
7 changed files with 352 additions and 100 deletions

View File

@ -133,6 +133,7 @@ components:
- 人员架构在 Department Shell 内直接复用真实组织工作面,并将组织树根节点限定为“品牌中心”。
- 素材资产库按权威组织归属选择外壳:品牌中心成员保留 Department Shell,外部普通用户只显示 64px 中性顶栏、素材工作面与退出入口。
- 进行中项目明细采用可键盘聚焦的横向滚动数据表:桌面固定“审批单标题”首列并保留 14 项业务字段,移动端转换为同字段的语义化定义列表;节点时间在数值下方标注对应流程节点名称。
- 按时交付明细使用紧凑的三项流程筛选条;当前项用浅蓝底和蓝字表达,未选项悬停为灰底,切换时同步更新公式、数量和横向明细表。
## Colors

View File

@ -32,6 +32,7 @@ web
- 美术设计申请流程的 `ding_WorkflowTask.activityId` 按已确认流程定义映射为精确中文节点名并写入本地快照;未知节点继续使用同步字段推断或明确回退,不改写上游只读数据。
- 钉钉流程快照每小时从只读报表库的 `ding_Workflow`、`ding_WorkflowTask`、`ding_WorkflowScheme` 联合增量同步,只接收已批准的美术设计申请和内容视频流程;三表复合游标写入现有同步状态并继续复用同一批生产快照数据。
- “本月上新”只读取表单字段“需求类型”为“新品”的六品牌美术设计流程,不以流程标题关键词判断,也不计“优化”等其他需求类型;分子为本月整条流程已完结数量,分母为本月已完结数量与当前进行中数量之和;其中进行中流程直接复用“进行中项目”的美术设计流程状态、时间与当前品牌中心处理人条件。
- “按时交付”只统计本月审批状态为已完结且审批结论未拒绝的美术设计与内容视频流程;详情页可在全部流程、美术设计流程和内容视频流程之间筛选,公式、数量与明细必须共用当前筛选口径。
- 除素材资产库、自动化工作流、人员架构、数据口径和已接入的中心指标外,其余板块现阶段只展示可理解、可扩展的模块框架,不虚构业务数据。
- 沿用项目现有 Next.js、NextAuth、Tailwind CSS 和权限体系。

View File

@ -21,6 +21,7 @@ import type {
import DepartmentShell from './DepartmentShell'
import MonthlyLaunchesInsights from './MonthlyLaunchesInsights'
import OngoingProjectsInsights from './OngoingProjectsInsights'
import OnTimeDeliveryInsightsView from './OnTimeDeliveryInsights'
import OnTimeDeliveryRate from './OnTimeDeliveryRate'
import type { CoreMetric } from './core-metrics'
@ -251,106 +252,6 @@ function PendingDataSource({ metric }: { metric: CoreMetric }) {
)
}
function formatDuration(value: number | null, unit: 'day' | 'hour') {
if (value === null) return '—'
const amount = Number.isInteger(value) ? value.toFixed(0) : value.toFixed(2)
return `${amount} ${unit === 'day' ? '天' : '小时'}`
}
function DeliveryStatusBadge({ status }: { status: 'on_time' | 'overtime' | 'pending' }) {
const styles = status === 'on_time'
? 'bg-emerald-50 text-emerald-800'
: status === 'overtime'
? 'bg-red-50 text-red-700'
: 'bg-amber-50 text-amber-800'
const label = status === 'on_time' ? '未超时' : status === 'overtime' ? '已超时' : '待计算'
return <span className={`inline-flex min-h-7 items-center rounded-lg px-2.5 text-xs font-bold ${styles}`}>{label}</span>
}
function OnTimeDeliveryInsightsView({ insights }: { insights: OnTimeDeliveryInsights }) {
const { items, summary } = insights
return (
<section aria-labelledby="on-time-delivery-list-title" className="mt-10">
<div className="rounded-lg border border-[#e2e8f0] bg-white px-5 py-4">
<p className="text-xs font-bold text-slate-500">统计公式</p>
<p className="mt-1 text-sm font-bold text-slate-900">
本月按时交付率 = 本月未超时完结流程数 ÷ 本月全部完结流程数 × 100%
</p>
<p className="mt-2 text-xs tabular-nums text-slate-500">
当前口径:{summary.onTime} ÷ {summary.total} = {formatRate(summary.rate)} · 超时 {summary.overtime} · 待计算 {summary.pending}
</p>
</div>
<div className="mt-8 flex flex-wrap items-end justify-between gap-3">
<div>
<h2 id="on-time-delivery-list-title" className="text-xl font-bold tracking-[-0.02em] sm:text-2xl">本月完结流程时效明细</h2>
<p className="mt-1 max-w-3xl text-sm leading-6 text-slate-600">
美术按“品牌策划主管分配任务”至“品牌策划主管审核”计算;内容按规则计至“编导审核”或“内容主管审核”。
</p>
</div>
<p className="text-sm font-semibold tabular-nums text-slate-600">共 {summary.total} 条</p>
</div>
{items.length === 0 ? (
<div role="status" className="mt-6 rounded-lg border border-[#e2e8f0] bg-white px-5 py-14 text-center">
<Database className="mx-auto h-8 w-8 text-slate-400" aria-hidden="true" />
<h3 className="mt-4 text-base font-bold text-slate-900">本月暂无完结流程</h3>
<p className="mt-2 text-sm text-slate-600">流程完结并完成每小时同步后,将自动进入本月交付时效统计。</p>
</div>
) : (
<div className="mt-6 overflow-x-auto rounded-lg border border-[#e2e8f0] bg-white">
<table aria-label="本月完结流程按时交付明细" className="min-w-[1180px] w-full text-left text-sm">
<thead className="bg-slate-50 text-xs font-bold text-slate-500">
<tr>
<th scope="col" className="w-[25%] px-5 py-3.5">流程</th>
<th scope="col" className="w-[14%] px-4 py-3.5">发起人 / 部门</th>
<th scope="col" className="w-[22%] px-4 py-3.5">计时节点</th>
<th scope="col" className="w-[13%] px-4 py-3.5">标准时效</th>
<th scope="col" className="w-[13%] px-4 py-3.5">实际用时</th>
<th scope="col" className="w-[13%] px-5 py-3.5">判定</th>
</tr>
</thead>
<tbody className="divide-y divide-slate-200">
{items.map((item) => (
<tr key={item.id} className="align-top transition-colors hover:bg-slate-50">
<td className="px-5 py-4">
<p className="font-bold text-slate-950">{item.title}</p>
<p className="mt-1 text-xs tabular-nums text-slate-500">{item.businessId || item.id}</p>
<p className="mt-1 text-xs font-semibold text-[#176fc1]">{item.projectType}</p>
</td>
<td className="px-4 py-4">
<p className="font-bold text-slate-900">{item.initiatorName}</p>
<p className="mt-1 leading-5 text-slate-500">{item.initiatorDepartment}</p>
</td>
<td className="px-4 py-4">
<p className="font-semibold text-slate-800">{item.assessment.startNodeLabel}</p>
<p className="mt-1 tabular-nums text-slate-500">{formatDate(item.assessment.startedAt, true)}</p>
<p className="mt-3 font-semibold text-slate-800">{item.assessment.endNodeLabel}</p>
<p className="mt-1 tabular-nums text-slate-500">{formatDate(item.assessment.finishedAt, true)}</p>
</td>
<td className="px-4 py-4 font-bold tabular-nums text-slate-900">
{formatDuration(item.assessment.standardDuration, item.assessment.durationUnit)}
</td>
<td className="px-4 py-4 font-bold tabular-nums text-slate-900">
{formatDuration(item.assessment.actualDuration, item.assessment.durationUnit)}
</td>
<td className="px-5 py-4">
<DeliveryStatusBadge status={item.assessment.status} />
{item.assessment.status === 'pending' && (
<p className="mt-2 max-w-40 text-xs leading-5 text-slate-500">缺少标准配置或关键节点时间</p>
)}
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</section>
)
}
export default function CoreMetricDetail({ metric, query, projectInsights, monthlyLaunches, onTimeDelivery, firstPassPage }: CoreMetricDetailProps) {
const hasRealProjectSource = metric.key === 'ongoing-projects' && projectInsights
const hasMonthlyLaunchSource = metric.key === 'monthly-launches' && monthlyLaunches

View File

@ -0,0 +1,109 @@
import { fireEvent, render, screen } from '@testing-library/react'
import type { OnTimeDeliveryWorkflowItem } from '@/lib/ding-workflow-sync'
import OnTimeDeliveryInsightsView from './OnTimeDeliveryInsights'
const ART_PROCESS_CODE = 'PROC-3571C915-0506-4490-A91A-8AA7EA33F838'
const CONTENT_PROCESS_CODE = 'PROC-AE9FF3E1-A442-4E6A-85CF-0F2B86409673'
function buildItem(
id: string,
processCode: string,
assessmentStatus: 'on_time' | 'overtime' | 'pending',
): OnTimeDeliveryWorkflowItem {
const isContent = processCode === CONTENT_PROCESS_CODE
return {
id,
businessId: `BIZ-${id}`,
title: isContent ? `内容流程-${id}` : `美术流程-${id}`,
status: 'COMPLETED',
originatorUserId: `user-${id}`,
originatorDeptName: '品牌中心',
sourceCreatedAt: '2026-08-01T00:00:00.000Z',
sourceUpdatedAt: '2026-08-03T00:00:00.000Z',
activeTaskCount: 0,
taskCount: 2,
schemeFieldCount: 3,
latestTaskStatus: 'COMPLETED',
processCode,
projectType: isContent ? '内容视频和图片拍摄' : '美术设计流程',
brand: '亿家达',
requesterName: '测试需求人',
requesterDepartment: '品牌中心',
initiatorName: '测试发起人',
initiatorDepartment: '运营中心A',
formFields: {
platform: null,
brand: null,
category: null,
spu: null,
demandType: null,
standardOutputDeadline: null,
sourceType: null,
taskType: null,
installVideo: null,
quantity: null,
cameraQuantity: null,
planningTaskStats: null,
graphicTaskStats: null,
imageTaskStats: null,
},
assignmentNodeLabel: isContent ? '内容主管分配任务' : '品牌策划主管分配任务',
assignmentStartedAt: '2026-08-01T00:00:00.000Z',
reviewNodeLabel: isContent ? '编导审核' : '品牌策划主管审核',
reviewFinishedAt: '2026-08-03T00:00:00.000Z',
activeTasks: [],
result: 'AGREE',
sourceFinishedAt: '2026-08-03T00:00:00.000Z',
assessment: {
status: assessmentStatus,
standardDuration: 3,
durationUnit: isContent ? 'hour' : 'day',
actualDuration: assessmentStatus === 'pending' ? null : 2,
startedAt: '2026-08-01T00:00:00.000Z',
finishedAt: '2026-08-03T00:00:00.000Z',
startNodeLabel: isContent ? '内容主管分配任务' : '品牌策划主管分配任务',
endNodeLabel: isContent ? '编导审核' : '品牌策划主管审核',
},
}
}
describe('OnTimeDeliveryInsightsView', () => {
it('按全部、美术和内容流程切换公式、数量与明细', () => {
render(
<OnTimeDeliveryInsightsView
insights={{
items: [
buildItem('art-on-time', ART_PROCESS_CODE, 'on_time'),
buildItem('art-overtime', ART_PROCESS_CODE, 'overtime'),
buildItem('content-on-time', CONTENT_PROCESS_CODE, 'on_time'),
],
summary: {
onTime: 2,
overtime: 1,
pending: 0,
total: 3,
rate: 66.7,
monthStart: '2026-07-31T16:00:00.000Z',
monthEnd: '2026-08-31T16:00:00.000Z',
lastSyncedAt: '2026-08-14T02:30:00.000Z',
syncStatus: 'ready',
},
}}
/>,
)
expect(screen.getByText('当前口径:2 ÷ 3 = 66.7% · 超时 1 · 待计算 0')).toBeInTheDocument()
expect(screen.getByRole('tab', { name: '筛选全部流程,共3条' })).toHaveAttribute('aria-selected', 'true')
fireEvent.click(screen.getByRole('tab', { name: '筛选内容视频流程,共1条' }))
expect(screen.getByText('当前口径:1 ÷ 1 = 100% · 超时 0 · 待计算 0')).toBeInTheDocument()
expect(screen.getByRole('tab', { name: '筛选内容视频流程,共1条' })).toHaveClass('bg-[#e7f3ff]')
expect(screen.getByText('内容流程-content-on-time')).toBeInTheDocument()
expect(screen.queryByText('美术流程-art-on-time')).not.toBeInTheDocument()
fireEvent.click(screen.getByRole('tab', { name: '筛选美术设计流程,共2条' }))
expect(screen.getByText('当前口径:1 ÷ 2 = 50% · 超时 1 · 待计算 0')).toBeInTheDocument()
expect(screen.getByText('美术流程-art-overtime')).toBeInTheDocument()
expect(screen.queryByText('内容流程-content-on-time')).not.toBeInTheDocument()
})
})

View File

@ -0,0 +1,200 @@
'use client'
import { useMemo, useState } from 'react'
import { Database } from 'lucide-react'
import type {
OnTimeDeliveryInsights,
OnTimeDeliveryWorkflowItem,
} from '@/lib/ding-workflow-sync'
const ART_PROCESS_CODE = 'PROC-3571C915-0506-4490-A91A-8AA7EA33F838'
const CONTENT_PROCESS_CODE = 'PROC-AE9FF3E1-A442-4E6A-85CF-0F2B86409673'
type ProcessFilter = 'all' | 'art' | 'content'
const PROCESS_FILTERS: Array<{ key: ProcessFilter; label: string }> = [
{ key: 'all', label: '全部流程' },
{ key: 'art', label: '美术设计流程' },
{ key: 'content', label: '内容视频流程' },
]
function formatDate(value: string | null) {
if (!value) return '—'
return new Intl.DateTimeFormat('zh-CN', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
hour12: false,
timeZone: 'Asia/Shanghai',
}).format(new Date(value))
}
function formatRate(rate: number | null) {
if (rate === null) return '—'
return `${Number.isInteger(rate) ? rate.toFixed(0) : rate.toFixed(1)}%`
}
function formatDuration(value: number | null, unit: 'day' | 'hour') {
if (value === null) return '—'
const amount = Number.isInteger(value) ? value.toFixed(0) : value.toFixed(2)
return `${amount} ${unit === 'day' ? '天' : '小时'}`
}
function matchesProcessFilter(item: OnTimeDeliveryWorkflowItem, filter: ProcessFilter) {
if (filter === 'art') return item.processCode === ART_PROCESS_CODE
if (filter === 'content') return item.processCode === CONTENT_PROCESS_CODE
return true
}
function summarize(items: OnTimeDeliveryWorkflowItem[]) {
const onTime = items.filter((item) => item.assessment.status === 'on_time').length
const overtime = items.filter((item) => item.assessment.status === 'overtime').length
const pending = items.filter((item) => item.assessment.status === 'pending').length
const total = items.length
return {
onTime,
overtime,
pending,
total,
rate: total > 0 ? Math.round((onTime / total) * 1_000) / 10 : null,
}
}
function DeliveryStatusBadge({ status }: { status: 'on_time' | 'overtime' | 'pending' }) {
const styles = status === 'on_time'
? 'bg-emerald-50 text-emerald-800'
: status === 'overtime'
? 'bg-red-50 text-red-700'
: 'bg-amber-50 text-amber-800'
const label = status === 'on_time' ? '未超时' : status === 'overtime' ? '已超时' : '待计算'
return <span className={`inline-flex min-h-7 items-center rounded-lg px-2.5 text-xs font-bold ${styles}`}>{label}</span>
}
export default function OnTimeDeliveryInsightsView({ insights }: { insights: OnTimeDeliveryInsights }) {
const [activeFilter, setActiveFilter] = useState<ProcessFilter>('all')
const { items, summary } = insights
const counts = useMemo(() => ({
all: summary.total,
art: items.filter((item) => matchesProcessFilter(item, 'art')).length,
content: items.filter((item) => matchesProcessFilter(item, 'content')).length,
}), [items, summary.total])
const filteredItems = useMemo(
() => items.filter((item) => matchesProcessFilter(item, activeFilter)),
[activeFilter, items],
)
const filteredSummary = activeFilter === 'all' ? summary : summarize(filteredItems)
const activeLabel = PROCESS_FILTERS.find((filter) => filter.key === activeFilter)?.label || '全部流程'
return (
<section aria-labelledby="on-time-delivery-list-title" className="mt-10">
<div className="rounded-lg border border-[#e2e8f0] bg-white px-5 py-4">
<div className="flex flex-col gap-4 lg:flex-row lg:items-end lg:justify-between">
<div>
<p className="text-xs font-bold text-slate-500">统计公式</p>
<p className="mt-1 text-sm font-bold text-slate-900">
本月按时交付率 = 本月未超时完结流程数 ÷ 本月全部完结流程数 × 100%
</p>
</div>
<div className="flex flex-wrap gap-2" role="tablist" aria-label="流程类型筛选">
{PROCESS_FILTERS.map((filter) => {
const selected = filter.key === activeFilter
return (
<button
key={filter.key}
type="button"
role="tab"
aria-selected={selected}
aria-controls="on-time-delivery-results"
aria-label={`筛选${filter.label},共${counts[filter.key]}条`}
onClick={() => setActiveFilter(filter.key)}
className={`inline-flex min-h-11 items-center gap-2 rounded-lg border px-3.5 text-sm font-bold transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#78aee9] focus-visible:ring-offset-2 ${selected
? 'border-[#9fcaf2] bg-[#e7f3ff] text-[#176fc1]'
: 'border-slate-200 bg-white text-slate-700 hover:bg-slate-100'
}`}
>
<span>{filter.label}</span>
<span className={`rounded-md px-1.5 py-0.5 text-xs tabular-nums ${selected ? 'bg-white/80 text-[#176fc1]' : 'bg-slate-100 text-slate-500'}`}>
{counts[filter.key]}
</span>
</button>
)
})}
</div>
</div>
<p className="mt-3 text-xs tabular-nums text-slate-500" aria-live="polite">
当前口径:{filteredSummary.onTime} ÷ {filteredSummary.total} = {formatRate(filteredSummary.rate)} · 超时 {filteredSummary.overtime} · 待计算 {filteredSummary.pending}
</p>
</div>
<div className="mt-8 flex flex-wrap items-end justify-between gap-3">
<div>
<h2 id="on-time-delivery-list-title" className="text-xl font-bold tracking-[-0.02em] sm:text-2xl">本月完结流程时效明细</h2>
<p className="mt-1 max-w-3xl text-sm leading-6 text-slate-600">
仅统计审批状态为已完结且未被拒绝的流程。美术按“品牌策划主管分配任务”至“品牌策划主管审核”计算;内容按规则计至“编导审核”或“内容主管审核”。
</p>
</div>
<p className="text-sm font-semibold tabular-nums text-slate-600" aria-live="polite">{activeLabel} · 共 {filteredSummary.total} 条</p>
</div>
<div id="on-time-delivery-results" role="tabpanel">
{filteredItems.length === 0 ? (
<div role="status" className="mt-6 rounded-lg border border-[#e2e8f0] bg-white px-5 py-14 text-center">
<Database className="mx-auto h-8 w-8 text-slate-400" aria-hidden="true" />
<h3 className="mt-4 text-base font-bold text-slate-900">{activeLabel}本月暂无符合口径的完结流程</h3>
<p className="mt-2 text-sm text-slate-600">审批完结且未被拒绝的流程完成每小时同步后,将自动进入本月交付时效统计。</p>
</div>
) : (
<div className="mt-6 overflow-x-auto rounded-lg border border-[#e2e8f0] bg-white">
<table aria-label={`${activeLabel}本月完结流程按时交付明细`} className="min-w-[1180px] w-full text-left text-sm">
<thead className="bg-slate-50 text-xs font-bold text-slate-500">
<tr>
<th scope="col" className="w-[25%] px-5 py-3.5">流程</th>
<th scope="col" className="w-[14%] px-4 py-3.5">发起人 / 部门</th>
<th scope="col" className="w-[22%] px-4 py-3.5">计时节点</th>
<th scope="col" className="w-[13%] px-4 py-3.5">标准时效</th>
<th scope="col" className="w-[13%] px-4 py-3.5">实际用时</th>
<th scope="col" className="w-[13%] px-5 py-3.5">判定</th>
</tr>
</thead>
<tbody className="divide-y divide-slate-200">
{filteredItems.map((item) => (
<tr key={item.id} className="align-top transition-colors hover:bg-slate-50">
<td className="px-5 py-4">
<p className="font-bold text-slate-950">{item.title}</p>
<p className="mt-1 text-xs tabular-nums text-slate-500">{item.businessId || item.id}</p>
<p className="mt-1 text-xs font-semibold text-[#176fc1]">{item.processCode === CONTENT_PROCESS_CODE ? '内容视频流程' : item.projectType}</p>
</td>
<td className="px-4 py-4">
<p className="font-bold text-slate-900">{item.initiatorName}</p>
<p className="mt-1 leading-5 text-slate-500">{item.initiatorDepartment}</p>
</td>
<td className="px-4 py-4">
<p className="font-semibold text-slate-800">{item.assessment.startNodeLabel}</p>
<p className="mt-1 tabular-nums text-slate-500">{formatDate(item.assessment.startedAt)}</p>
<p className="mt-3 font-semibold text-slate-800">{item.assessment.endNodeLabel}</p>
<p className="mt-1 tabular-nums text-slate-500">{formatDate(item.assessment.finishedAt)}</p>
</td>
<td className="px-4 py-4 font-bold tabular-nums text-slate-900">
{formatDuration(item.assessment.standardDuration, item.assessment.durationUnit)}
</td>
<td className="px-4 py-4 font-bold tabular-nums text-slate-900">
{formatDuration(item.assessment.actualDuration, item.assessment.durationUnit)}
</td>
<td className="px-5 py-4">
<DeliveryStatusBadge status={item.assessment.status} />
{item.assessment.status === 'pending' && (
<p className="mt-2 max-w-40 text-xs leading-5 text-slate-500">缺少标准配置或关键节点时间</p>
)}
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</div>
</section>
)
}

View File

@ -14,6 +14,7 @@ import {
isDingWorkflowStartedOnOrAfterCutoff,
isDingWorkflowOngoing,
isDingWorkflowCompletedInRange,
isDingWorkflowApprovedCompletion,
normalizeDingWorkflowBrand,
normalizeDingWorkflowDepartment,
normalizeDingWorkflowDetailValue,
@ -71,6 +72,15 @@ describe('ding workflow snapshot sync semantics', () => {
expect(isDingWorkflowCompletedInRange('COMPLETED', null, range)).toBe(false)
})
it('only treats completed workflows without a rejected decision as approved completions', () => {
expect(isDingWorkflowApprovedCompletion('COMPLETED', 'AGREE', null)).toBe(true)
expect(isDingWorkflowApprovedCompletion('completed', null, 'NONE')).toBe(true)
expect(isDingWorkflowApprovedCompletion('COMPLETED', 'REFUSE', null)).toBe(false)
expect(isDingWorkflowApprovedCompletion('COMPLETED', '已拒绝', null)).toBe(false)
expect(isDingWorkflowApprovedCompletion('COMPLETED', null, 'reject')).toBe(false)
expect(isDingWorkflowApprovedCompletion('TERMINATED', 'AGREE', null)).toBe(false)
})
it('only accepts the two approved process types', () => {
expect(DING_WORKFLOW_ALLOWED_PROCESS_CODES).toEqual([
'PROC-3571C915-0506-4490-A91A-8AA7EA33F838',

View File

@ -12,6 +12,18 @@ import { prisma } from '@/lib/prisma'
const SYNC_STATE_ID = 'ding-workflow-hourly'
const TERMINAL_WORKFLOW_STATUSES = new Set(['COMPLETED', 'TERMINATED', 'CANCELED'])
const REJECTED_WORKFLOW_DECISIONS = new Set([
'REFUSE',
'REFUSED',
'REJECT',
'REJECTED',
'DISAGREE',
'DENY',
'DENIED',
'拒绝',
'已拒绝',
'不同意',
])
const LEASE_DURATION_MS = 20 * 60 * 1000
const DEFAULT_SYNC_INTERVAL_MS = 60 * 60 * 1000
const INITIAL_SYNC_DELAY_MS = 5_000
@ -684,6 +696,22 @@ export function isDingWorkflowCompletedInRange(
return finishedAtMs >= range.start.getTime() && finishedAtMs < range.end.getTime()
}
/**
* 钉钉会把审批结束状态和审批结论分开保存:被拒绝的流程也可能处于 COMPLETED。
* 按时交付只统计已完结且没有明确拒绝结论的流程,避免拒绝单进入分母。
*/
export function isDingWorkflowApprovedCompletion(
status: unknown,
result: unknown,
bizAction: unknown,
) {
if (String(status || '').trim().toUpperCase() !== 'COMPLETED') return false
return ![result, bizAction].some((value) => {
const decision = String(value || '').trim().toUpperCase()
return decision ? REJECTED_WORKFLOW_DECISIONS.has(decision) : false
})
}
export function isDingWorkflowStartedOnOrAfterCutoff(value: unknown): boolean {
const startedAt = sourceWorkflowTimestampToIso(value)
return Boolean(startedAt && startedAt >= DING_WORKFLOW_STARTED_AT_CUTOFF_ISO)
@ -1489,6 +1517,7 @@ const ONGOING_WORKFLOW_SELECT = {
const MONTHLY_LAUNCH_WORKFLOW_SELECT = {
...ONGOING_WORKFLOW_SELECT,
result: true,
bizAction: true,
sourceFinishedAtRaw: true,
} as const
@ -1803,6 +1832,7 @@ async function readOnTimeDeliveryInsightsWithoutAccessCheck(now = new Date()): P
])
const rows = candidates.filter((row) => (
isDingWorkflowCompletedInRange(row.status, row.sourceFinishedAtRaw, range)
&& isDingWorkflowApprovedCompletion(row.status, row.result, row.bizAction)
))
const initiatorDirectory = await readInitiatorDirectory(rows)
const items = rows.map((row): OnTimeDeliveryWorkflowItem => {