dsh-total-quality 2.0.55 → 2.0.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +51 -47
- package/LICENSE.md +37 -37
- package/README.en.md +32 -30
- package/README.md +90 -88
- package/agent-host.cjs +277 -277
- package/client.js +199 -92
- package/cordis.patch.yml +5 -5
- package/docs/enterprise-onboarding.md +10 -10
- package/docs/technical-reference.md +223 -223
- package/host.cjs +91 -124
- package/llm-bridge.cjs +234 -234
- package/locale/en.json +5 -5
- package/locale/zh.json +5 -5
- package/package.json +3 -2
- package/public/app.css +3 -0
- package/public/app.js +6 -2
- package/public/index.html +8 -9
- package/public/js/api.js +152 -152
- package/public/js/assistant-history.js +62 -62
- package/public/js/material-library.js +100 -100
- package/public/js/mobile-preview.js +119 -0
- package/public/js/pages-company-knowledge.js +9 -32
- package/public/js/pages-core.js +232 -232
- package/public/js/pages-growth.js +148 -148
- package/public/js/pages-qms.js +1 -1
- package/public/js/pages-qtools.js +410 -410
- package/public/js/pages-thanks.js +71 -71
- package/public/js/plugin-updates.js +53 -0
- package/public/js/quality-workflow.js +205 -205
- package/public/js/survey-dates.js +41 -41
- package/public/js/survey-knowledge.js +301 -301
- package/public/js/tool-wizards.js +621 -621
- package/public/js/ui.js +467 -467
- package/public/js/voice-capture-worklet.js +30 -30
- package/public/js/xiaozhi-voice.js +264 -264
- package/public/js/xiaozhi.js +468 -468
- package/public/platform-help.html +426 -426
- package/public/platform-site/assets/0468a68574112812.css +10703 -10703
- package/public/platform-site/assets/159e086d35adfa1c.css +2094 -2094
- package/public/platform-site/assets/169e3159cade0d9f.css +98 -98
- package/public/platform-site/assets/22b917c4a3d4ae3d.svg +14 -14
- package/public/platform-site/assets/476f9254ccf723e7.css +8265 -8265
- package/public/platform-site/assets/85a0a4fb4416ded9.css +120 -120
- package/public/platform-site/assets/a3b272383226f6d9.svg +135 -135
- package/public/platform-site/assets/fd16dc5f3cc9d97e.svg +104 -104
- package/public/platform-site/assets/qip-favicon.svg +5 -5
- package/public/platform-site/index.html +279 -279
- package/public/platform-site/offline.js +261 -261
- package/public/platform-site/qip-brand.css +566 -566
- package/public/platform-site/qip-module-guides.js +237 -237
- package/public/responsive.css +103 -101
- package/public/vendor/markdown-it-15.0.3.LICENSE +22 -22
- package/public/vendor/markdown-it-15.0.3.umd.min.js +13 -13
- package/public/workbench.css +7 -7
- package/public/xiaozhi.css +292 -292
- package/resources/qms-templates/019ffb58f24ed48d.docx +0 -0
- package/resources/qms-templates/04a69165fc15143a.docx +0 -0
- package/resources/qms-templates/09af69358c989a63.docx +0 -0
- package/resources/qms-templates/0e7ac77844e45311.docx +0 -0
- package/resources/qms-templates/12446a1b5e173c71.docx +0 -0
- package/resources/qms-templates/15ae40f67f9a3efc.docx +0 -0
- package/resources/qms-templates/18a69bbebf2ece7f.docx +0 -0
- package/resources/qms-templates/1978faa989134f02.docx +0 -0
- package/resources/qms-templates/1a30e121de752f7b.docx +0 -0
- package/resources/qms-templates/1b88907969ea7d4c.docx +0 -0
- package/resources/qms-templates/1e92b808722bf90a.docx +0 -0
- package/resources/qms-templates/2091cad340dc0e7f.docx +0 -0
- package/resources/qms-templates/271ae1002c896ed7.docx +0 -0
- package/resources/qms-templates/280ce53e5d3b5fcf.docx +0 -0
- package/resources/qms-templates/28ca8e4ede0adf6d.docx +0 -0
- package/resources/qms-templates/2ac6675f3cb1f993.docx +0 -0
- package/resources/qms-templates/2c3b799389909d8b.docx +0 -0
- package/resources/qms-templates/2c51038ba2cc3264.docx +0 -0
- package/resources/qms-templates/30c888851d16d764.docx +0 -0
- package/resources/qms-templates/3459fc4daaa2743d.docx +0 -0
- package/resources/qms-templates/3751dafc335e0e80.docx +0 -0
- package/resources/qms-templates/38798cd4298cd2db.docx +0 -0
- package/resources/qms-templates/38f551f9d738ab0a.docx +0 -0
- package/resources/qms-templates/3c85a23ea17018b4.docx +0 -0
- package/resources/qms-templates/3cdb7d14caf1b852.docx +0 -0
- package/resources/qms-templates/3f23239bb6b3e1db.docx +0 -0
- package/resources/qms-templates/42a5b9efeeaa8007.docx +0 -0
- package/resources/qms-templates/47352aafe9b8dac1.docx +0 -0
- package/resources/qms-templates/495359b1e3cbb8fe.docx +0 -0
- package/resources/qms-templates/4ca6920464785166.docx +0 -0
- package/resources/qms-templates/4ce862582a7791be.docx +0 -0
- package/resources/qms-templates/54c9a02a10991b9e.docx +0 -0
- package/resources/qms-templates/5aeb8fddf5f3693f.docx +0 -0
- package/resources/qms-templates/5d7e5576b0e73be7.docx +0 -0
- package/resources/qms-templates/5db3a40edac37791.docx +0 -0
- package/resources/qms-templates/5ffa21eb78eb6f77.docx +0 -0
- package/resources/qms-templates/60d0fbcb709b7161.docx +0 -0
- package/resources/qms-templates/63e1d3a166756095.docx +0 -0
- package/resources/qms-templates/65c724c080d32f10.docx +0 -0
- package/resources/qms-templates/674bd7826c6cbac2.docx +0 -0
- package/resources/qms-templates/677e851acca1b879.docx +0 -0
- package/resources/qms-templates/6bf15feb1a0d2a8d.docx +0 -0
- package/resources/qms-templates/6c3889c7d0918db9.docx +0 -0
- package/resources/qms-templates/6c4c349eeb0a96a8.docx +0 -0
- package/resources/qms-templates/6c5befbd33f759c1.docx +0 -0
- package/resources/qms-templates/6df8367901347508.docx +0 -0
- package/resources/qms-templates/71db51997037692b.docx +0 -0
- package/resources/qms-templates/78a8ef8c76510c99.docx +0 -0
- package/resources/qms-templates/8397bfd1c0a1b013.docx +0 -0
- package/resources/qms-templates/84d750cf858b60a1.docx +0 -0
- package/resources/qms-templates/880de58a4b334533.docx +0 -0
- package/resources/qms-templates/88c37d1b87d9b78c.docx +0 -0
- package/resources/qms-templates/88e9cd42f1849462.docx +0 -0
- package/resources/qms-templates/8956597403be35b6.docx +0 -0
- package/resources/qms-templates/94675c810a233e1f.docx +0 -0
- package/resources/qms-templates/94dff59dd7ebec6e.docx +0 -0
- package/resources/qms-templates/9670b9cd02141594.docx +0 -0
- package/resources/qms-templates/98c373ebd7b5163d.docx +0 -0
- package/resources/qms-templates/a4078cf2378a9388.docx +0 -0
- package/resources/qms-templates/a5b110c7ef917139.docx +0 -0
- package/resources/qms-templates/aec75820e45774be.docx +0 -0
- package/resources/qms-templates/b31c085e281d230c.docx +0 -0
- package/resources/qms-templates/b7c1c3c72f8ffeef.docx +0 -0
- package/resources/qms-templates/b81b82eaa5c8f422.docx +0 -0
- package/resources/qms-templates/b92a2fa31f75f137.docx +0 -0
- package/resources/qms-templates/b96c54ae9cfffc54.docx +0 -0
- package/resources/qms-templates/bc47cfd626c010e7.docx +0 -0
- package/resources/qms-templates/be60792734afca69.docx +0 -0
- package/resources/qms-templates/c0018d8ae9ad19e1.docx +0 -0
- package/resources/qms-templates/c171027c964c8be3.docx +0 -0
- package/resources/qms-templates/c4b93d71f5d98b4b.docx +0 -0
- package/resources/qms-templates/c531da29fcb3090f.docx +0 -0
- package/resources/qms-templates/c88eddd43358d015.docx +0 -0
- package/resources/qms-templates/cb978da542f0d892.docx +0 -0
- package/resources/qms-templates/ccde4a94532a8d36.docx +0 -0
- package/resources/qms-templates/cf3fb1e20ae6f24d.docx +0 -0
- package/resources/qms-templates/d231b4982fc8113e.docx +0 -0
- package/resources/qms-templates/d3c55aa5ed14055c.docx +0 -0
- package/resources/qms-templates/db45c44a00a13349.docx +0 -0
- package/resources/qms-templates/db849a41210f54e0.docx +0 -0
- package/resources/qms-templates/dba9ce363d83ddc8.docx +0 -0
- package/resources/qms-templates/dca3ea4c95eb2225.docx +0 -0
- package/resources/qms-templates/dfa4220d2b6b8131.docx +0 -0
- package/resources/qms-templates/dfa51222c777734f.docx +0 -0
- package/resources/qms-templates/e07ea511507e14f5.docx +0 -0
- package/resources/qms-templates/e0a2e00c03458dfa.docx +0 -0
- package/resources/qms-templates/e0e802f46b6764d1.docx +0 -0
- package/resources/qms-templates/e53fc85717f2852b.docx +0 -0
- package/resources/qms-templates/e9dd82d5e54520e5.docx +0 -0
- package/resources/qms-templates/ea7bfc22c06d82a9.docx +0 -0
- package/resources/qms-templates/ecf0db9f37294536.docx +0 -0
- package/resources/qms-templates/f05fcfc87e82ff39.docx +0 -0
- package/resources/qms-templates/fb9e56a17c4a4f97.docx +0 -0
- package/resources/qms-templates/manifest.json +932 -0
- package/src/data/seed-sme.js +317 -317
- package/src/data/seed.js +879 -879
- package/src/lib/backup-identity.js +57 -57
- package/src/lib/chat-answer.js +225 -225
- package/src/lib/chat-context.js +99 -99
- package/src/lib/company-library.js +28 -19
- package/src/lib/data-import.js +217 -217
- package/src/lib/data-sources.js +118 -118
- package/src/lib/demo-data.js +27 -1
- package/src/lib/employee-intake.js +84 -84
- package/src/lib/growth.js +53 -53
- package/src/lib/intake-packets.js +119 -119
- package/src/lib/issue-intake.js +88 -88
- package/src/lib/kb-revision.js +214 -214
- package/src/lib/llm.js +279 -279
- package/src/lib/model-error.js +14 -14
- package/src/lib/privacy.js +26 -26
- package/src/lib/qms-drafting.js +194 -194
- package/src/lib/qms-jobs.js +11 -7
- package/src/lib/qms-manual-review.js +185 -185
- package/src/lib/qms-procedure-review.js +109 -109
- package/src/lib/qms-templates.js +358 -326
- package/src/lib/qms.js +369 -369
- package/src/lib/quality-priority.js +100 -100
- package/src/lib/quality-state.js +92 -92
- package/src/lib/quality-workflow.js +65 -65
- package/src/lib/retrieval.js +159 -159
- package/src/lib/spc.js +127 -127
- package/src/lib/voice-hotwords.txt +22 -22
- package/src/lib/voice-text.js +13 -13
- package/src/lib/voice-worker.js +72 -72
- package/src/lib/voice.js +330 -330
- package/src/lib/workbench-notices.js +49 -49
- package/src/lib/workbench.js +103 -106
- package/src/package.json +3 -3
- package/src/tools/analysis.js +306 -306
- package/src/tools/data.js +596 -596
- package/src/tools/docs.js +430 -430
- package/src/tools/registry.js +57 -57
- package/tools-dsh.cjs +153 -153
- package//345/256/211/350/243/205/350/257/264/346/230/216.md +33 -25
- package//346/234/254/346/234/272/347/213/254/347/253/213/345/256/211/350/243/205/350/257/264/346/230/216.md +17 -17
- package//350/207/252/346/243/200.cjs +88 -88
- package/public/js/remote-knowledge.js +0 -165
- package/public/js/workbench-notices.js +0 -67
- package/public/remote-knowledge-help.html +0 -35
- package/public/remote-knowledge.css +0 -40
- package/src/lib/remote-knowledge.js +0 -284
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const day = 86400000;
|
|
4
|
-
const zone = 'Asia/Shanghai';
|
|
5
|
-
const localDate = new Intl.DateTimeFormat('sv-SE', { timeZone: zone, year: 'numeric', month: '2-digit', day: '2-digit' });
|
|
6
|
-
const localTime = new Intl.DateTimeFormat('sv-SE', {
|
|
7
|
-
timeZone: zone, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hourCycle: 'h23',
|
|
8
|
-
});
|
|
9
|
-
const dateOnly = /^\d{4}-\d\d-\d\d$/;
|
|
10
|
-
const { deadlineTime, isOpen } = require('./quality-state');
|
|
11
|
-
|
|
12
|
-
function deadline(raw) {
|
|
13
|
-
const value = String(raw || '').trim();
|
|
14
|
-
const time = deadlineTime(value);
|
|
15
|
-
if (!Number.isFinite(time)) return { time: Infinity, label: '未记录' };
|
|
16
|
-
return { time, label: dateOnly.test(value) ? value : localTime.format(time) };
|
|
17
|
-
}
|
|
18
|
-
function cell(value) {
|
|
19
|
-
return String(value || '未记录').replace(/\|/g, '|').replace(/[\r\n]+/g, ' ').replace(/[<>]/g, (char) => char === '<' ? '‹' : '›');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function build(db, scan, now = Date.now()) {
|
|
23
|
-
const today = localDate.format(now);
|
|
24
|
-
const endToday = Date.parse(today + 'T00:00:00+08:00') + day;
|
|
25
|
-
const endSoon = endToday + 3 * day;
|
|
26
|
-
const groups = [
|
|
27
|
-
{ name: '质量问题库', rows: db.issues, url: 'issues' },
|
|
28
|
-
{ name: '8D 改进项目', rows: db.projects, url: 'projects' },
|
|
29
|
-
{ name: '站内待办', rows: db.todos, url: 'todos' },
|
|
30
|
-
{ name: '供应商整改单', rows: db.scars, url: 'sqm/scars' },
|
|
31
|
-
{ name: '研发质量问题', rows: db.designIssues, url: 'rdq/issues' },
|
|
32
|
-
];
|
|
33
|
-
const sources = [];
|
|
34
|
-
const items = groups.flatMap(({ name, rows, url }) => {
|
|
35
|
-
const entries = (rows || []).filter((row) => isOpen(row,now + 1)).flatMap((row) => {
|
|
36
|
-
const { time, label } = deadline(row.dueAt);
|
|
37
|
-
const severity = String(row.severity || row.priority || '').toUpperCase();
|
|
38
|
-
const high = /^(?:A|A级|高|高风险|HIGH)$/i.test(severity);
|
|
39
|
-
const status = time < now ? '已逾期' : time < endToday ? '今天到期'
|
|
40
|
-
: time < endSoon ? '即将到期' : Number.isFinite(time) ? '未临期' : '未记录期限';
|
|
41
|
-
if (!high && time >= endSoon) return [];
|
|
42
|
-
return [{ id: row.id, related: row.issueId || row.link, title: row.title || row.name,
|
|
43
|
-
owner: row.owner || row.user, label, status, time, severity, rank: high ? 1 : time < endToday ? 2 : 3 }];
|
|
44
|
-
});
|
|
45
|
-
if (!entries.length) return entries;
|
|
46
|
-
const ref = sources.length + 1;
|
|
47
|
-
sources.push({ ref, kind: '业务记录', title: name, detail: entries.length + ' 条符合条件',
|
|
48
|
-
excerpt: '包含未关闭的高风险、逾期、今日及未来 3 天到期事项。', url: '/qip-real-workbench/api/' + url });
|
|
49
|
-
return entries.map((entry) => ({ ...entry, ref }));
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const processRisks = (scan?.风险清单 || []).filter((risk) => risk.等级 === 'A' &&
|
|
53
|
-
['@SPC 判异', '@AQI 视觉质检'].includes(risk.风险源));
|
|
54
|
-
const scanRef = sources.length + 1;
|
|
55
|
-
if (scan?.ok) {
|
|
56
|
-
sources.push({ ref: scanRef, kind: '业务记录', title: 'SPC / AQI 质量风险扫描', detail: '近 7 天',
|
|
57
|
-
excerpt: 'A级过程信号 ' + processRisks.length + ' 条。统计结果受测量与视觉质检数据覆盖范围限制。' });
|
|
58
|
-
}
|
|
59
|
-
for (const risk of processRisks) {
|
|
60
|
-
items.push({ id: risk.对象, title: risk.描述, owner: '', label: '', status: '近期过程信号', time: Infinity,
|
|
61
|
-
severity: 'A', rank: 1, ref: scanRef, detail: [risk.数据支撑, risk.建议动作].filter(Boolean).join('。') });
|
|
62
|
-
}
|
|
63
|
-
items.sort((a, b) => a.rank - b.rank || a.time - b.time || String(a.id).localeCompare(String(b.id)));
|
|
64
|
-
return {
|
|
65
|
-
asOf: localTime.format(now),
|
|
66
|
-
dueThrough: localDate.format(endSoon - 1),
|
|
67
|
-
scanAvailable: !!scan?.ok,
|
|
68
|
-
signalCount: processRisks.length,
|
|
69
|
-
scanRef: scan?.ok ? scanRef : null,
|
|
70
|
-
items: items.map(({ time, ...item }) => item),
|
|
71
|
-
sources,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function formatList({ asOf, scanAvailable, signalCount, scanRef, items }) {
|
|
76
|
-
const lines = ['## 今日质量优先事项', '', '截至 **' + asOf + '(北京时间)**。临期范围为今天及未来 3 个日历日,过程信号取近 7 天。', ''];
|
|
77
|
-
if (!items.length) lines.push('当前台账中没有查到符合上述范围的未关闭高风险、逾期或临期事项。');
|
|
78
|
-
else {
|
|
79
|
-
lines.push('**' + items.length + ' 项**。先看高风险及 A 级信号,再看逾期和今天到期,其次安排未来 3 天到期的事项。', '',
|
|
80
|
-
'| 优先级 | 事项与记录编号 | 等级及状态 | 责任人 | 截止时间 | 来源 |',
|
|
81
|
-
'| --- | --- | --- | --- | --- | --- |');
|
|
82
|
-
for (const item of items) {
|
|
83
|
-
const identifier = [item.id, item.related && '关联 ' + item.related].filter(Boolean).join(' · ');
|
|
84
|
-
const title = [identifier, item.title].filter(Boolean).join(' · ');
|
|
85
|
-
lines.push('| P' + item.rank + ' | ' + cell(title) + ' | ' +
|
|
86
|
-
cell([item.severity, item.status].filter(Boolean).join(' · ')) + ' | ' +
|
|
87
|
-
cell(item.owner) + ' | ' + cell(item.label) + ' | [' + item.ref + '] |');
|
|
88
|
-
}
|
|
89
|
-
const details = items.filter((item) => item.detail);
|
|
90
|
-
if (details.length) {
|
|
91
|
-
lines.push('', '### 过程信号与建议动作', '');
|
|
92
|
-
details.forEach((item) => lines.push('- **' + cell(item.id) + '** ' + cell(item.detail) + ' [' + item.ref + ']'));
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (!scanAvailable) lines.push('', '本次未取得 SPC / AQI 风险扫描结果。');
|
|
96
|
-
else if (!signalCount) lines.push('', '近 7 天扫描未返回 A 级过程信号,结论以实际测量和质检记录覆盖为限。 [' + scanRef + ']');
|
|
97
|
-
return lines.join('\n');
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
module.exports = { build, formatList };
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const day = 86400000;
|
|
4
|
+
const zone = 'Asia/Shanghai';
|
|
5
|
+
const localDate = new Intl.DateTimeFormat('sv-SE', { timeZone: zone, year: 'numeric', month: '2-digit', day: '2-digit' });
|
|
6
|
+
const localTime = new Intl.DateTimeFormat('sv-SE', {
|
|
7
|
+
timeZone: zone, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hourCycle: 'h23',
|
|
8
|
+
});
|
|
9
|
+
const dateOnly = /^\d{4}-\d\d-\d\d$/;
|
|
10
|
+
const { deadlineTime, isOpen } = require('./quality-state');
|
|
11
|
+
|
|
12
|
+
function deadline(raw) {
|
|
13
|
+
const value = String(raw || '').trim();
|
|
14
|
+
const time = deadlineTime(value);
|
|
15
|
+
if (!Number.isFinite(time)) return { time: Infinity, label: '未记录' };
|
|
16
|
+
return { time, label: dateOnly.test(value) ? value : localTime.format(time) };
|
|
17
|
+
}
|
|
18
|
+
function cell(value) {
|
|
19
|
+
return String(value || '未记录').replace(/\|/g, '|').replace(/[\r\n]+/g, ' ').replace(/[<>]/g, (char) => char === '<' ? '‹' : '›');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function build(db, scan, now = Date.now()) {
|
|
23
|
+
const today = localDate.format(now);
|
|
24
|
+
const endToday = Date.parse(today + 'T00:00:00+08:00') + day;
|
|
25
|
+
const endSoon = endToday + 3 * day;
|
|
26
|
+
const groups = [
|
|
27
|
+
{ name: '质量问题库', rows: db.issues, url: 'issues' },
|
|
28
|
+
{ name: '8D 改进项目', rows: db.projects, url: 'projects' },
|
|
29
|
+
{ name: '站内待办', rows: db.todos, url: 'todos' },
|
|
30
|
+
{ name: '供应商整改单', rows: db.scars, url: 'sqm/scars' },
|
|
31
|
+
{ name: '研发质量问题', rows: db.designIssues, url: 'rdq/issues' },
|
|
32
|
+
];
|
|
33
|
+
const sources = [];
|
|
34
|
+
const items = groups.flatMap(({ name, rows, url }) => {
|
|
35
|
+
const entries = (rows || []).filter((row) => isOpen(row,now + 1)).flatMap((row) => {
|
|
36
|
+
const { time, label } = deadline(row.dueAt);
|
|
37
|
+
const severity = String(row.severity || row.priority || '').toUpperCase();
|
|
38
|
+
const high = /^(?:A|A级|高|高风险|HIGH)$/i.test(severity);
|
|
39
|
+
const status = time < now ? '已逾期' : time < endToday ? '今天到期'
|
|
40
|
+
: time < endSoon ? '即将到期' : Number.isFinite(time) ? '未临期' : '未记录期限';
|
|
41
|
+
if (!high && time >= endSoon) return [];
|
|
42
|
+
return [{ id: row.id, related: row.issueId || row.link, title: row.title || row.name,
|
|
43
|
+
owner: row.owner || row.user, label, status, time, severity, rank: high ? 1 : time < endToday ? 2 : 3 }];
|
|
44
|
+
});
|
|
45
|
+
if (!entries.length) return entries;
|
|
46
|
+
const ref = sources.length + 1;
|
|
47
|
+
sources.push({ ref, kind: '业务记录', title: name, detail: entries.length + ' 条符合条件',
|
|
48
|
+
excerpt: '包含未关闭的高风险、逾期、今日及未来 3 天到期事项。', url: '/qip-real-workbench/api/' + url });
|
|
49
|
+
return entries.map((entry) => ({ ...entry, ref }));
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const processRisks = (scan?.风险清单 || []).filter((risk) => risk.等级 === 'A' &&
|
|
53
|
+
['@SPC 判异', '@AQI 视觉质检'].includes(risk.风险源));
|
|
54
|
+
const scanRef = sources.length + 1;
|
|
55
|
+
if (scan?.ok) {
|
|
56
|
+
sources.push({ ref: scanRef, kind: '业务记录', title: 'SPC / AQI 质量风险扫描', detail: '近 7 天',
|
|
57
|
+
excerpt: 'A级过程信号 ' + processRisks.length + ' 条。统计结果受测量与视觉质检数据覆盖范围限制。' });
|
|
58
|
+
}
|
|
59
|
+
for (const risk of processRisks) {
|
|
60
|
+
items.push({ id: risk.对象, title: risk.描述, owner: '', label: '', status: '近期过程信号', time: Infinity,
|
|
61
|
+
severity: 'A', rank: 1, ref: scanRef, detail: [risk.数据支撑, risk.建议动作].filter(Boolean).join('。') });
|
|
62
|
+
}
|
|
63
|
+
items.sort((a, b) => a.rank - b.rank || a.time - b.time || String(a.id).localeCompare(String(b.id)));
|
|
64
|
+
return {
|
|
65
|
+
asOf: localTime.format(now),
|
|
66
|
+
dueThrough: localDate.format(endSoon - 1),
|
|
67
|
+
scanAvailable: !!scan?.ok,
|
|
68
|
+
signalCount: processRisks.length,
|
|
69
|
+
scanRef: scan?.ok ? scanRef : null,
|
|
70
|
+
items: items.map(({ time, ...item }) => item),
|
|
71
|
+
sources,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function formatList({ asOf, scanAvailable, signalCount, scanRef, items }) {
|
|
76
|
+
const lines = ['## 今日质量优先事项', '', '截至 **' + asOf + '(北京时间)**。临期范围为今天及未来 3 个日历日,过程信号取近 7 天。', ''];
|
|
77
|
+
if (!items.length) lines.push('当前台账中没有查到符合上述范围的未关闭高风险、逾期或临期事项。');
|
|
78
|
+
else {
|
|
79
|
+
lines.push('**' + items.length + ' 项**。先看高风险及 A 级信号,再看逾期和今天到期,其次安排未来 3 天到期的事项。', '',
|
|
80
|
+
'| 优先级 | 事项与记录编号 | 等级及状态 | 责任人 | 截止时间 | 来源 |',
|
|
81
|
+
'| --- | --- | --- | --- | --- | --- |');
|
|
82
|
+
for (const item of items) {
|
|
83
|
+
const identifier = [item.id, item.related && '关联 ' + item.related].filter(Boolean).join(' · ');
|
|
84
|
+
const title = [identifier, item.title].filter(Boolean).join(' · ');
|
|
85
|
+
lines.push('| P' + item.rank + ' | ' + cell(title) + ' | ' +
|
|
86
|
+
cell([item.severity, item.status].filter(Boolean).join(' · ')) + ' | ' +
|
|
87
|
+
cell(item.owner) + ' | ' + cell(item.label) + ' | [' + item.ref + '] |');
|
|
88
|
+
}
|
|
89
|
+
const details = items.filter((item) => item.detail);
|
|
90
|
+
if (details.length) {
|
|
91
|
+
lines.push('', '### 过程信号与建议动作', '');
|
|
92
|
+
details.forEach((item) => lines.push('- **' + cell(item.id) + '** ' + cell(item.detail) + ' [' + item.ref + ']'));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (!scanAvailable) lines.push('', '本次未取得 SPC / AQI 风险扫描结果。');
|
|
96
|
+
else if (!signalCount) lines.push('', '近 7 天扫描未返回 A 级过程信号,结论以实际测量和质检记录覆盖为限。 [' + scanRef + ']');
|
|
97
|
+
return lines.join('\n');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
module.exports = { build, formatList };
|
package/src/lib/quality-state.js
CHANGED
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const day = 86400000;
|
|
4
|
-
const closedStatus = /^(?:已关闭|已结案|已完成|已归档|已取消|closed|cancelled|canceled|done|completed)$/i;
|
|
5
|
-
const issueStatuses = new Set(['新建', '待处理', '待分派', '整改中', 'QRQC 跟踪', '监控中', '验证中', '已关闭']);
|
|
6
|
-
|
|
7
|
-
function deadlineTime(raw) {
|
|
8
|
-
const value = String(raw || '').trim();
|
|
9
|
-
if (/^\d{4}-\d\d-\d\d$/.test(value)) return Date.parse(value + 'T23:59:59.999+08:00');
|
|
10
|
-
if (/^\d{4}-\d\d-\d\d[ T]\d\d:\d\d(?::\d\d(?:\.\d+)?)?$/.test(value)) return Date.parse(value.replace(' ', 'T') + '+08:00');
|
|
11
|
-
return Date.parse(value);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function legacyReopening(row, closed) {
|
|
15
|
-
if (!issueStatuses.has(row.status) || closedStatus.test(row.status) || !Array.isArray(row.history)) return null;
|
|
16
|
-
if (!row.history.some((event) => event.action === '发现问题' || event.action === '更新问题')) return null;
|
|
17
|
-
for (let i=row.history.length-1;i>=0;i--) {
|
|
18
|
-
const event=row.history[i];
|
|
19
|
-
if (event.action!=='更新问题' || Date.parse(event.ts)<=closed) continue;
|
|
20
|
-
try { if (JSON.parse(event.note).status===row.status) return event.ts; }
|
|
21
|
-
catch (_) { /* Preserve the fallback for legacy notes typed by the user. */ }
|
|
22
|
-
}
|
|
23
|
-
return Date.parse(row.updatedAt)>closed ? row.updatedAt : null;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function isOpen(row, at = Date.now() + 1) {
|
|
27
|
-
if (row.deletedAt || row.done === true) return false;
|
|
28
|
-
const created = Date.parse(row.createdAt || row.ts);
|
|
29
|
-
if (created >= at) return false;
|
|
30
|
-
if (row.statusTransitions?.length) {
|
|
31
|
-
let status = row.statusTransitions[0].from;
|
|
32
|
-
for (const event of row.statusTransitions) {
|
|
33
|
-
if (Date.parse(event.at) < at) status = event.to;
|
|
34
|
-
}
|
|
35
|
-
return !closedStatus.test(status || '');
|
|
36
|
-
}
|
|
37
|
-
const completion = Date.parse(row.closedAt || row.completedAt);
|
|
38
|
-
if (Number.isFinite(completion)) return completion >= at || Date.parse(legacyReopening(row,completion)) < at;
|
|
39
|
-
return !closedStatus.test(row.status || '') && !closedStatus.test(row.stage || '');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function projectTiming(project, at = Date.now() + 1) {
|
|
43
|
-
const deadline = deadlineTime(project.dueAt);
|
|
44
|
-
const overdue = isOpen(project, at) && deadline < at;
|
|
45
|
-
return { ...project, overdue, overdueDays: overdue ? Math.floor((at - deadline) / day) : 0 };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function changeIssue(store, issue, changes, user, note, event = {}) {
|
|
49
|
-
if (issue.review?.state==='accepted' && (Object.keys(changes).length || note)) {
|
|
50
|
-
throw Object.assign(Error('该事项已经验收结案,原验收记录保留供追溯'),{status:409});
|
|
51
|
-
}
|
|
52
|
-
if (issue.review?.state === 'pending' && !changes.review) {
|
|
53
|
-
throw Object.assign(Error('验收中,请先处理当前申请再修改事项'),{status:409});
|
|
54
|
-
}
|
|
55
|
-
if (issue.reviewRequired && changes.status === '已关闭' && changes.status !== issue.status && !event.acceptance) {
|
|
56
|
-
throw Object.assign(Error('请通过验收申请完成结案'),{status:409});
|
|
57
|
-
}
|
|
58
|
-
if (changes.status !== undefined && changes.status !== issue.status && !issueStatuses.has(changes.status)) {
|
|
59
|
-
throw Object.assign(new Error('请选择有效的问题状态'), { status:400 });
|
|
60
|
-
}
|
|
61
|
-
const patch = { ...changes };
|
|
62
|
-
if (patch.owner !== undefined && patch.owner !== issue.owner && patch.ownerMemberId === undefined) {
|
|
63
|
-
patch.ownerMemberId = null;
|
|
64
|
-
}
|
|
65
|
-
if ((patch.workshop !== undefined && patch.workshop !== issue.workshop && patch.workshopWarning === undefined) ||
|
|
66
|
-
((patch.status === '已关闭' || patch.severity === 'C') && issue.workshopWarning)) {
|
|
67
|
-
patch.workshopWarning = false;
|
|
68
|
-
patch.warningMessage = '';
|
|
69
|
-
}
|
|
70
|
-
const at = new Date().toISOString();
|
|
71
|
-
if (patch.status && patch.status !== issue.status) {
|
|
72
|
-
const transitions = Array.isArray(issue.statusTransitions) ? [...issue.statusTransitions] : [];
|
|
73
|
-
if (!transitions.length && issue.closedAt) {
|
|
74
|
-
if (closedStatus.test(issue.status || '')) transitions.push({ from:'整改中', to:issue.status, at:issue.closedAt });
|
|
75
|
-
else {
|
|
76
|
-
const reopened = legacyReopening(issue,Date.parse(issue.closedAt));
|
|
77
|
-
if (reopened) transitions.push({ from:'整改中', to:'已关闭', at:issue.closedAt }, { from:'已关闭', to:issue.status, at:reopened });
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
transitions.push({ from:issue.status, to:patch.status, at });
|
|
81
|
-
patch.statusTransitions = transitions;
|
|
82
|
-
patch.closedAt = closedStatus.test(patch.status) ? at : null;
|
|
83
|
-
}
|
|
84
|
-
if (!Object.keys(patch).length && !note) return issue;
|
|
85
|
-
patch.history = [...(issue.history || []), {
|
|
86
|
-
ts:at, user, action:event.action || '更新问题', ...(event.signature ? {signature:event.signature} : {}), note:note || (patch.status && patch.status !== issue.status
|
|
87
|
-
? [issue.status || '未登记状态', patch.status].join(' → ') : '更新 ' + Object.keys(changes).join('、')),
|
|
88
|
-
}];
|
|
89
|
-
return store.col('issues').update(issue.id, patch);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
module.exports = { deadlineTime, isOpen, projectTiming, changeIssue };
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const day = 86400000;
|
|
4
|
+
const closedStatus = /^(?:已关闭|已结案|已完成|已归档|已取消|closed|cancelled|canceled|done|completed)$/i;
|
|
5
|
+
const issueStatuses = new Set(['新建', '待处理', '待分派', '整改中', 'QRQC 跟踪', '监控中', '验证中', '已关闭']);
|
|
6
|
+
|
|
7
|
+
function deadlineTime(raw) {
|
|
8
|
+
const value = String(raw || '').trim();
|
|
9
|
+
if (/^\d{4}-\d\d-\d\d$/.test(value)) return Date.parse(value + 'T23:59:59.999+08:00');
|
|
10
|
+
if (/^\d{4}-\d\d-\d\d[ T]\d\d:\d\d(?::\d\d(?:\.\d+)?)?$/.test(value)) return Date.parse(value.replace(' ', 'T') + '+08:00');
|
|
11
|
+
return Date.parse(value);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function legacyReopening(row, closed) {
|
|
15
|
+
if (!issueStatuses.has(row.status) || closedStatus.test(row.status) || !Array.isArray(row.history)) return null;
|
|
16
|
+
if (!row.history.some((event) => event.action === '发现问题' || event.action === '更新问题')) return null;
|
|
17
|
+
for (let i=row.history.length-1;i>=0;i--) {
|
|
18
|
+
const event=row.history[i];
|
|
19
|
+
if (event.action!=='更新问题' || Date.parse(event.ts)<=closed) continue;
|
|
20
|
+
try { if (JSON.parse(event.note).status===row.status) return event.ts; }
|
|
21
|
+
catch (_) { /* Preserve the fallback for legacy notes typed by the user. */ }
|
|
22
|
+
}
|
|
23
|
+
return Date.parse(row.updatedAt)>closed ? row.updatedAt : null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function isOpen(row, at = Date.now() + 1) {
|
|
27
|
+
if (row.deletedAt || row.done === true) return false;
|
|
28
|
+
const created = Date.parse(row.createdAt || row.ts);
|
|
29
|
+
if (created >= at) return false;
|
|
30
|
+
if (row.statusTransitions?.length) {
|
|
31
|
+
let status = row.statusTransitions[0].from;
|
|
32
|
+
for (const event of row.statusTransitions) {
|
|
33
|
+
if (Date.parse(event.at) < at) status = event.to;
|
|
34
|
+
}
|
|
35
|
+
return !closedStatus.test(status || '');
|
|
36
|
+
}
|
|
37
|
+
const completion = Date.parse(row.closedAt || row.completedAt);
|
|
38
|
+
if (Number.isFinite(completion)) return completion >= at || Date.parse(legacyReopening(row,completion)) < at;
|
|
39
|
+
return !closedStatus.test(row.status || '') && !closedStatus.test(row.stage || '');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function projectTiming(project, at = Date.now() + 1) {
|
|
43
|
+
const deadline = deadlineTime(project.dueAt);
|
|
44
|
+
const overdue = isOpen(project, at) && deadline < at;
|
|
45
|
+
return { ...project, overdue, overdueDays: overdue ? Math.floor((at - deadline) / day) : 0 };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function changeIssue(store, issue, changes, user, note, event = {}) {
|
|
49
|
+
if (issue.review?.state==='accepted' && (Object.keys(changes).length || note)) {
|
|
50
|
+
throw Object.assign(Error('该事项已经验收结案,原验收记录保留供追溯'),{status:409});
|
|
51
|
+
}
|
|
52
|
+
if (issue.review?.state === 'pending' && !changes.review) {
|
|
53
|
+
throw Object.assign(Error('验收中,请先处理当前申请再修改事项'),{status:409});
|
|
54
|
+
}
|
|
55
|
+
if (issue.reviewRequired && changes.status === '已关闭' && changes.status !== issue.status && !event.acceptance) {
|
|
56
|
+
throw Object.assign(Error('请通过验收申请完成结案'),{status:409});
|
|
57
|
+
}
|
|
58
|
+
if (changes.status !== undefined && changes.status !== issue.status && !issueStatuses.has(changes.status)) {
|
|
59
|
+
throw Object.assign(new Error('请选择有效的问题状态'), { status:400 });
|
|
60
|
+
}
|
|
61
|
+
const patch = { ...changes };
|
|
62
|
+
if (patch.owner !== undefined && patch.owner !== issue.owner && patch.ownerMemberId === undefined) {
|
|
63
|
+
patch.ownerMemberId = null;
|
|
64
|
+
}
|
|
65
|
+
if ((patch.workshop !== undefined && patch.workshop !== issue.workshop && patch.workshopWarning === undefined) ||
|
|
66
|
+
((patch.status === '已关闭' || patch.severity === 'C') && issue.workshopWarning)) {
|
|
67
|
+
patch.workshopWarning = false;
|
|
68
|
+
patch.warningMessage = '';
|
|
69
|
+
}
|
|
70
|
+
const at = new Date().toISOString();
|
|
71
|
+
if (patch.status && patch.status !== issue.status) {
|
|
72
|
+
const transitions = Array.isArray(issue.statusTransitions) ? [...issue.statusTransitions] : [];
|
|
73
|
+
if (!transitions.length && issue.closedAt) {
|
|
74
|
+
if (closedStatus.test(issue.status || '')) transitions.push({ from:'整改中', to:issue.status, at:issue.closedAt });
|
|
75
|
+
else {
|
|
76
|
+
const reopened = legacyReopening(issue,Date.parse(issue.closedAt));
|
|
77
|
+
if (reopened) transitions.push({ from:'整改中', to:'已关闭', at:issue.closedAt }, { from:'已关闭', to:issue.status, at:reopened });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
transitions.push({ from:issue.status, to:patch.status, at });
|
|
81
|
+
patch.statusTransitions = transitions;
|
|
82
|
+
patch.closedAt = closedStatus.test(patch.status) ? at : null;
|
|
83
|
+
}
|
|
84
|
+
if (!Object.keys(patch).length && !note) return issue;
|
|
85
|
+
patch.history = [...(issue.history || []), {
|
|
86
|
+
ts:at, user, action:event.action || '更新问题', ...(event.signature ? {signature:event.signature} : {}), note:note || (patch.status && patch.status !== issue.status
|
|
87
|
+
? [issue.status || '未登记状态', patch.status].join(' → ') : '更新 ' + Object.keys(changes).join('、')),
|
|
88
|
+
}];
|
|
89
|
+
return store.col('issues').update(issue.id, patch);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
module.exports = { deadlineTime, isOpen, projectTiming, changeIssue };
|
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { randomUUID } = require('node:crypto');
|
|
4
|
-
const qualityState = require('./quality-state');
|
|
5
|
-
|
|
6
|
-
const fail = (message, status = 409) => { throw Object.assign(new Error(message),{status}); };
|
|
7
|
-
const detail = (value) => typeof value === 'string' ? value.trim().slice(0,4000) : '';
|
|
8
|
-
|
|
9
|
-
function request(store, issue, input, signer, files) {
|
|
10
|
-
if (!qualityState.isOpen(issue)) fail('事项已结束');
|
|
11
|
-
if (issue.review?.state === 'pending') {
|
|
12
|
-
if (issue.review.requestId === input.requestId &&
|
|
13
|
-
issue.review.submittedBy?.memberId === signer.memberId) return issue;
|
|
14
|
-
fail('已有一份验收申请待处理');
|
|
15
|
-
}
|
|
16
|
-
if (!/^[a-f0-9-]{36}$/i.test(input.requestId || '')) fail('缺少提交编号,请重新打开表单',400);
|
|
17
|
-
const note = detail(input.note);
|
|
18
|
-
if (!note) fail('请填写整改完成情况和验收依据',400);
|
|
19
|
-
if (!detail(issue.verifyResult) && !files.length) fail('请先补充复测结果,或上传相关证据',422);
|
|
20
|
-
const at = new Date().toISOString();
|
|
21
|
-
const review = {
|
|
22
|
-
id:randomUUID(), requestId:input.requestId, state:'pending', requestedAt:at,
|
|
23
|
-
submittedBy:signer, note, evidence:files.map(({id,name})=>({id,name})).slice(0,50),
|
|
24
|
-
containment:issue.containment || '', verifyResult:issue.verifyResult || '',
|
|
25
|
-
};
|
|
26
|
-
store.audit({user:signer.name,plugin:'质量事项',action:'提交验收',params:{issueId:issue.id,reviewId:review.id,signature:signer}});
|
|
27
|
-
const reviewHistory=issue.review ? [...(issue.reviewHistory||[]),issue.review] : issue.reviewHistory || [];
|
|
28
|
-
return qualityState.changeIssue(store,issue,{status:'验证中',review,reviewHistory,reviewRequired:true},signer.name,note,{action:'提交验收',signature:signer});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function decide(store, issue, input, signer) {
|
|
32
|
-
const before = issue.review;
|
|
33
|
-
if (!before || before.id !== input.reviewId) fail('验收申请已变化,请刷新后核对');
|
|
34
|
-
if (!['accepted','returned'].includes(input.decision)) fail('请选择通过或退回',400);
|
|
35
|
-
if (before.state !== 'pending') {
|
|
36
|
-
if (before.state === input.decision && before.decidedBy?.memberId === signer.memberId) return issue;
|
|
37
|
-
fail('这份验收申请已经处理');
|
|
38
|
-
}
|
|
39
|
-
if (signer.verified && before.submittedBy?.memberId === signer.memberId) fail('请由另一位质量主管验收本人的申请',403);
|
|
40
|
-
const opinion = detail(input.opinion);
|
|
41
|
-
if (!opinion) fail('请填写验收结论或退回原因',400);
|
|
42
|
-
const approved = input.decision === 'accepted';
|
|
43
|
-
const action = approved ? '验收结案' : '退回整改';
|
|
44
|
-
const review = {...before,state:input.decision,opinion,decidedAt:new Date().toISOString(),decidedBy:signer};
|
|
45
|
-
const updated = qualityState.changeIssue(store,issue,{review,status:approved?'已关闭':'整改中'},signer.name,opinion,
|
|
46
|
-
{action,signature:signer,acceptance:approved});
|
|
47
|
-
store.audit({user:signer.name,plugin:'质量事项',action,params:{issueId:issue.id,reviewId:review.id,signature:signer}});
|
|
48
|
-
return updated;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const nearDue = 3 * 86400000;
|
|
52
|
-
function duePriority(row, now = Date.now()) {
|
|
53
|
-
const remaining = qualityState.deadlineTime(row.dueAt) - now;
|
|
54
|
-
return remaining < 0 ? 'overdue' : remaining <= nearDue ? 'soon' : '';
|
|
55
|
-
}
|
|
56
|
-
function reporterName(row) {
|
|
57
|
-
if (!row.reporterMemberId) return '';
|
|
58
|
-
return row.reporterName || row.reportedBy || row.history?.find(entry=>entry.action==='发现问题')?.user || '';
|
|
59
|
-
}
|
|
60
|
-
function caseSummary(row) {
|
|
61
|
-
return {id:row.id,title:row.title,workshop:row.workshop,owner:row.owner,reporterName:reporterName(row),severity:row.severity,
|
|
62
|
-
status:row.status,review:row.review?.state || '',dueAt:row.dueAt,priority:duePriority(row)};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
module.exports = { request, decide, duePriority, caseSummary, reporterName };
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { randomUUID } = require('node:crypto');
|
|
4
|
+
const qualityState = require('./quality-state');
|
|
5
|
+
|
|
6
|
+
const fail = (message, status = 409) => { throw Object.assign(new Error(message),{status}); };
|
|
7
|
+
const detail = (value) => typeof value === 'string' ? value.trim().slice(0,4000) : '';
|
|
8
|
+
|
|
9
|
+
function request(store, issue, input, signer, files) {
|
|
10
|
+
if (!qualityState.isOpen(issue)) fail('事项已结束');
|
|
11
|
+
if (issue.review?.state === 'pending') {
|
|
12
|
+
if (issue.review.requestId === input.requestId &&
|
|
13
|
+
issue.review.submittedBy?.memberId === signer.memberId) return issue;
|
|
14
|
+
fail('已有一份验收申请待处理');
|
|
15
|
+
}
|
|
16
|
+
if (!/^[a-f0-9-]{36}$/i.test(input.requestId || '')) fail('缺少提交编号,请重新打开表单',400);
|
|
17
|
+
const note = detail(input.note);
|
|
18
|
+
if (!note) fail('请填写整改完成情况和验收依据',400);
|
|
19
|
+
if (!detail(issue.verifyResult) && !files.length) fail('请先补充复测结果,或上传相关证据',422);
|
|
20
|
+
const at = new Date().toISOString();
|
|
21
|
+
const review = {
|
|
22
|
+
id:randomUUID(), requestId:input.requestId, state:'pending', requestedAt:at,
|
|
23
|
+
submittedBy:signer, note, evidence:files.map(({id,name})=>({id,name})).slice(0,50),
|
|
24
|
+
containment:issue.containment || '', verifyResult:issue.verifyResult || '',
|
|
25
|
+
};
|
|
26
|
+
store.audit({user:signer.name,plugin:'质量事项',action:'提交验收',params:{issueId:issue.id,reviewId:review.id,signature:signer}});
|
|
27
|
+
const reviewHistory=issue.review ? [...(issue.reviewHistory||[]),issue.review] : issue.reviewHistory || [];
|
|
28
|
+
return qualityState.changeIssue(store,issue,{status:'验证中',review,reviewHistory,reviewRequired:true},signer.name,note,{action:'提交验收',signature:signer});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function decide(store, issue, input, signer) {
|
|
32
|
+
const before = issue.review;
|
|
33
|
+
if (!before || before.id !== input.reviewId) fail('验收申请已变化,请刷新后核对');
|
|
34
|
+
if (!['accepted','returned'].includes(input.decision)) fail('请选择通过或退回',400);
|
|
35
|
+
if (before.state !== 'pending') {
|
|
36
|
+
if (before.state === input.decision && before.decidedBy?.memberId === signer.memberId) return issue;
|
|
37
|
+
fail('这份验收申请已经处理');
|
|
38
|
+
}
|
|
39
|
+
if (signer.verified && before.submittedBy?.memberId === signer.memberId) fail('请由另一位质量主管验收本人的申请',403);
|
|
40
|
+
const opinion = detail(input.opinion);
|
|
41
|
+
if (!opinion) fail('请填写验收结论或退回原因',400);
|
|
42
|
+
const approved = input.decision === 'accepted';
|
|
43
|
+
const action = approved ? '验收结案' : '退回整改';
|
|
44
|
+
const review = {...before,state:input.decision,opinion,decidedAt:new Date().toISOString(),decidedBy:signer};
|
|
45
|
+
const updated = qualityState.changeIssue(store,issue,{review,status:approved?'已关闭':'整改中'},signer.name,opinion,
|
|
46
|
+
{action,signature:signer,acceptance:approved});
|
|
47
|
+
store.audit({user:signer.name,plugin:'质量事项',action,params:{issueId:issue.id,reviewId:review.id,signature:signer}});
|
|
48
|
+
return updated;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const nearDue = 3 * 86400000;
|
|
52
|
+
function duePriority(row, now = Date.now()) {
|
|
53
|
+
const remaining = qualityState.deadlineTime(row.dueAt) - now;
|
|
54
|
+
return remaining < 0 ? 'overdue' : remaining <= nearDue ? 'soon' : '';
|
|
55
|
+
}
|
|
56
|
+
function reporterName(row) {
|
|
57
|
+
if (!row.reporterMemberId) return '';
|
|
58
|
+
return row.reporterName || row.reportedBy || row.history?.find(entry=>entry.action==='发现问题')?.user || '';
|
|
59
|
+
}
|
|
60
|
+
function caseSummary(row) {
|
|
61
|
+
return {id:row.id,title:row.title,workshop:row.workshop,owner:row.owner,reporterName:reporterName(row),severity:row.severity,
|
|
62
|
+
status:row.status,review:row.review?.state || '',dueAt:row.dueAt,priority:duePriority(row)};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = { request, decide, duePriority, caseSummary, reporterName };
|