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
package/src/lib/data-sources.js
CHANGED
|
@@ -1,118 +1,118 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('node:fs');
|
|
4
|
-
const path = require('node:path');
|
|
5
|
-
const { DatabaseSync } = require('node:sqlite');
|
|
6
|
-
const dataImport = require('./data-import');
|
|
7
|
-
|
|
8
|
-
const pageSize = 200;
|
|
9
|
-
const fail = (message,status=400) => { throw Object.assign(new Error(message),{status}); };
|
|
10
|
-
const label = (value,max) => typeof value==='string' ? value.trim().slice(0,max) : '';
|
|
11
|
-
const quoted = (name) => '"' + name.replace(/"/g,'""') + '"';
|
|
12
|
-
|
|
13
|
-
function config(input, previous, workshops, protectedDirs) {
|
|
14
|
-
const name=label(input.name,100), workshop=label(input.workshop,80), target=input.target, kind=input.kind;
|
|
15
|
-
if (!name || !workshops.includes(workshop) || !['http','sqlite'].includes(kind)) fail('请填写名称、车间及数据源类型');
|
|
16
|
-
const fields=dataImport.fields(target);
|
|
17
|
-
const cursorField=label(input.cursorField,128);
|
|
18
|
-
if (!cursorField) fail('请填写单调递增的整数游标列');
|
|
19
|
-
const mapping={};
|
|
20
|
-
for (const {key,required} of fields) {
|
|
21
|
-
const field=label(input.mapping?.[key],128);
|
|
22
|
-
if (required && !field) fail('请配置必需字段 '+key+' 的映射');
|
|
23
|
-
if (field) mapping[key]=field;
|
|
24
|
-
}
|
|
25
|
-
const minutes=Number(input.minutes);
|
|
26
|
-
if (!Number.isInteger(minutes)||minutes<1||minutes>1440) fail('同步间隔须为 1 至 1,440 分钟');
|
|
27
|
-
const settings={name,workshop,target,kind,mapping,cursorField,minutes,enabled:input.enabled===true};
|
|
28
|
-
if (kind==='http') {
|
|
29
|
-
let address;
|
|
30
|
-
try { address=new URL(String(input.endpoint||'')); } catch { fail('请输入完整的 HTTP JSON 接口地址'); }
|
|
31
|
-
const local=['localhost','127.0.0.1','[::1]'].includes(address.hostname);
|
|
32
|
-
if (!(address.protocol==='https:' || local && address.protocol==='http:') || address.username || address.password || address.hash) {
|
|
33
|
-
fail('远程接口需使用 HTTPS,鉴权请填写在独立字段');
|
|
34
|
-
}
|
|
35
|
-
if (/\/qip-real(?:-workbench)?\/api(?:\/|$)/.test(address.pathname)) fail('同步源须指向外部业务系统');
|
|
36
|
-
settings.endpoint=address.href;
|
|
37
|
-
} else {
|
|
38
|
-
const filename=label(input.filename,512), table=label(input.table,128);
|
|
39
|
-
if (!path.isAbsolute(filename) || !table) fail('请填写本机或服务器上的 SQLite 绝对路径及表名');
|
|
40
|
-
if (!fs.existsSync(filename) || !fs.statSync(filename).isFile()) fail('找不到 SQLite 文件');
|
|
41
|
-
settings.filename=fs.realpathSync(filename);
|
|
42
|
-
const normalize=(value)=>process.platform==='win32'?value.toLowerCase():value;
|
|
43
|
-
if (protectedDirs.some(dir=>normalize(settings.filename).startsWith(normalize(path.resolve(dir)+path.sep)))) {
|
|
44
|
-
fail('请使用外部业务数据库文件');
|
|
45
|
-
}
|
|
46
|
-
settings.table=table;
|
|
47
|
-
}
|
|
48
|
-
const changes=previous && ['kind','workshop','target','cursorField','endpoint','filename','table','mapping'].some(key=>
|
|
49
|
-
JSON.stringify(previous[key])!==JSON.stringify(settings[key]));
|
|
50
|
-
return {...settings,cursor:changes?0:previous?.cursor || 0,revision:(previous?.revision||0)+1};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function readSqlite(source,limit) {
|
|
54
|
-
const db=new DatabaseSync(source.filename,{readOnly:true});
|
|
55
|
-
try {
|
|
56
|
-
db.exec('PRAGMA trusted_schema=OFF; PRAGMA query_only=ON; PRAGMA busy_timeout=1500');
|
|
57
|
-
const table=db.prepare("SELECT name FROM sqlite_schema WHERE name=? AND type='table' AND name NOT LIKE 'sqlite_%'").get(source.table);
|
|
58
|
-
if (!table) fail('找不到配置的业务表',422);
|
|
59
|
-
const known=new Set(db.prepare('SELECT name FROM pragma_table_info(?)').all(source.table).map(col=>col.name));
|
|
60
|
-
const fields=[...new Set([source.cursorField,...Object.values(source.mapping)])];
|
|
61
|
-
if (fields.some(field=>!known.has(field))) fail('数据库缺少配置中的列,请核对映射',422);
|
|
62
|
-
const key=quoted(source.cursorField);
|
|
63
|
-
return db.prepare('SELECT '+fields.map(quoted).join(',')+' FROM '+quoted(source.table)+
|
|
64
|
-
' WHERE '+key+'>? ORDER BY '+key+' ASC LIMIT ?').all(source.cursor,limit);
|
|
65
|
-
} finally { db.close(); }
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async function readHttp(source,secret,limit,signal) {
|
|
69
|
-
const address=new URL(source.endpoint);
|
|
70
|
-
address.searchParams.set('after',source.cursor);
|
|
71
|
-
address.searchParams.set('limit',limit);
|
|
72
|
-
const headers={Accept:'application/json'};
|
|
73
|
-
if (secret) headers.Authorization='Bearer '+secret;
|
|
74
|
-
let res;
|
|
75
|
-
try { res=await fetch(address,{headers,redirect:'error',signal}); }
|
|
76
|
-
catch { fail('无法连接数据源,请核对地址、TLS 和服务状态',502); }
|
|
77
|
-
if (!res.ok) fail('数据源返回 HTTP '+res.status,502);
|
|
78
|
-
const reader=res.body.getReader(), chunks=[];
|
|
79
|
-
let size=0;
|
|
80
|
-
try {
|
|
81
|
-
for (;;) {
|
|
82
|
-
const {done,value}=await reader.read();
|
|
83
|
-
if (done) break;
|
|
84
|
-
size+=value.byteLength;
|
|
85
|
-
if (size>4*1024*1024) fail('数据源响应超过 4 MB,请缩小单页内容',422);
|
|
86
|
-
chunks.push(Buffer.from(value));
|
|
87
|
-
}
|
|
88
|
-
} finally { await reader.cancel().catch(()=>{}); reader.releaseLock(); }
|
|
89
|
-
let json;
|
|
90
|
-
try { json=JSON.parse(Buffer.concat(chunks).toString('utf8')); }
|
|
91
|
-
catch { fail('数据源应返回 JSON 数组或包含 rows 的对象',422); }
|
|
92
|
-
return Array.isArray(json) ? json : json?.rows;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
async function read(source,secret,signal) {
|
|
96
|
-
const raw=source.kind==='sqlite' ? readSqlite(source,pageSize+1) : await readHttp(source,secret,pageSize,signal);
|
|
97
|
-
if (!Array.isArray(raw) || raw.length>pageSize+(source.kind==='sqlite'?1:0)) fail('检查数据源 JSON 结构与 limit 参数',422);
|
|
98
|
-
let cursor=source.cursor;
|
|
99
|
-
const rows=[];
|
|
100
|
-
for (const sourceRow of raw) {
|
|
101
|
-
if (!sourceRow || typeof sourceRow!=='object' || Array.isArray(sourceRow)) fail('数据源返回了无效行',422);
|
|
102
|
-
const key=Object.hasOwn(sourceRow,source.cursorField) ? sourceRow[source.cursorField] : undefined;
|
|
103
|
-
const number=typeof key==='number'||typeof key==='string' && /^\d+$/.test(key) ? Number(key) : NaN;
|
|
104
|
-
if (!Number.isSafeInteger(number) || number<=cursor) fail('游标必须为严格递增且唯一的整数',422);
|
|
105
|
-
cursor=number;
|
|
106
|
-
const record=Object.fromEntries(Object.entries(source.mapping).map(([field,column])=>[field,
|
|
107
|
-
Object.hasOwn(sourceRow,column)?sourceRow[column]:undefined]));
|
|
108
|
-
if (!record.workshop) record.workshop=source.workshop;
|
|
109
|
-
if (source.target==='issues' && !record.externalIssueNumber) record.externalIssueNumber=source.id+'-'+number;
|
|
110
|
-
if (source.target==='measurements') Object.assign(record,{sourceSystem:source.id,sourceMeasurementId:String(number)});
|
|
111
|
-
if (source.target==='defects') Object.assign(record,{sourceSystem:source.id,sourceRecordId:String(number)});
|
|
112
|
-
rows.push({record,cursor:number});
|
|
113
|
-
}
|
|
114
|
-
const page=rows.slice(0,pageSize);
|
|
115
|
-
return {records:page.map(row=>row.record),cursor:page.at(-1)?.cursor ?? source.cursor,hasMore:raw.length>=pageSize};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
module.exports = { config,read };
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const { DatabaseSync } = require('node:sqlite');
|
|
6
|
+
const dataImport = require('./data-import');
|
|
7
|
+
|
|
8
|
+
const pageSize = 200;
|
|
9
|
+
const fail = (message,status=400) => { throw Object.assign(new Error(message),{status}); };
|
|
10
|
+
const label = (value,max) => typeof value==='string' ? value.trim().slice(0,max) : '';
|
|
11
|
+
const quoted = (name) => '"' + name.replace(/"/g,'""') + '"';
|
|
12
|
+
|
|
13
|
+
function config(input, previous, workshops, protectedDirs) {
|
|
14
|
+
const name=label(input.name,100), workshop=label(input.workshop,80), target=input.target, kind=input.kind;
|
|
15
|
+
if (!name || !workshops.includes(workshop) || !['http','sqlite'].includes(kind)) fail('请填写名称、车间及数据源类型');
|
|
16
|
+
const fields=dataImport.fields(target);
|
|
17
|
+
const cursorField=label(input.cursorField,128);
|
|
18
|
+
if (!cursorField) fail('请填写单调递增的整数游标列');
|
|
19
|
+
const mapping={};
|
|
20
|
+
for (const {key,required} of fields) {
|
|
21
|
+
const field=label(input.mapping?.[key],128);
|
|
22
|
+
if (required && !field) fail('请配置必需字段 '+key+' 的映射');
|
|
23
|
+
if (field) mapping[key]=field;
|
|
24
|
+
}
|
|
25
|
+
const minutes=Number(input.minutes);
|
|
26
|
+
if (!Number.isInteger(minutes)||minutes<1||minutes>1440) fail('同步间隔须为 1 至 1,440 分钟');
|
|
27
|
+
const settings={name,workshop,target,kind,mapping,cursorField,minutes,enabled:input.enabled===true};
|
|
28
|
+
if (kind==='http') {
|
|
29
|
+
let address;
|
|
30
|
+
try { address=new URL(String(input.endpoint||'')); } catch { fail('请输入完整的 HTTP JSON 接口地址'); }
|
|
31
|
+
const local=['localhost','127.0.0.1','[::1]'].includes(address.hostname);
|
|
32
|
+
if (!(address.protocol==='https:' || local && address.protocol==='http:') || address.username || address.password || address.hash) {
|
|
33
|
+
fail('远程接口需使用 HTTPS,鉴权请填写在独立字段');
|
|
34
|
+
}
|
|
35
|
+
if (/\/qip-real(?:-workbench)?\/api(?:\/|$)/.test(address.pathname)) fail('同步源须指向外部业务系统');
|
|
36
|
+
settings.endpoint=address.href;
|
|
37
|
+
} else {
|
|
38
|
+
const filename=label(input.filename,512), table=label(input.table,128);
|
|
39
|
+
if (!path.isAbsolute(filename) || !table) fail('请填写本机或服务器上的 SQLite 绝对路径及表名');
|
|
40
|
+
if (!fs.existsSync(filename) || !fs.statSync(filename).isFile()) fail('找不到 SQLite 文件');
|
|
41
|
+
settings.filename=fs.realpathSync(filename);
|
|
42
|
+
const normalize=(value)=>process.platform==='win32'?value.toLowerCase():value;
|
|
43
|
+
if (protectedDirs.some(dir=>normalize(settings.filename).startsWith(normalize(path.resolve(dir)+path.sep)))) {
|
|
44
|
+
fail('请使用外部业务数据库文件');
|
|
45
|
+
}
|
|
46
|
+
settings.table=table;
|
|
47
|
+
}
|
|
48
|
+
const changes=previous && ['kind','workshop','target','cursorField','endpoint','filename','table','mapping'].some(key=>
|
|
49
|
+
JSON.stringify(previous[key])!==JSON.stringify(settings[key]));
|
|
50
|
+
return {...settings,cursor:changes?0:previous?.cursor || 0,revision:(previous?.revision||0)+1};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function readSqlite(source,limit) {
|
|
54
|
+
const db=new DatabaseSync(source.filename,{readOnly:true});
|
|
55
|
+
try {
|
|
56
|
+
db.exec('PRAGMA trusted_schema=OFF; PRAGMA query_only=ON; PRAGMA busy_timeout=1500');
|
|
57
|
+
const table=db.prepare("SELECT name FROM sqlite_schema WHERE name=? AND type='table' AND name NOT LIKE 'sqlite_%'").get(source.table);
|
|
58
|
+
if (!table) fail('找不到配置的业务表',422);
|
|
59
|
+
const known=new Set(db.prepare('SELECT name FROM pragma_table_info(?)').all(source.table).map(col=>col.name));
|
|
60
|
+
const fields=[...new Set([source.cursorField,...Object.values(source.mapping)])];
|
|
61
|
+
if (fields.some(field=>!known.has(field))) fail('数据库缺少配置中的列,请核对映射',422);
|
|
62
|
+
const key=quoted(source.cursorField);
|
|
63
|
+
return db.prepare('SELECT '+fields.map(quoted).join(',')+' FROM '+quoted(source.table)+
|
|
64
|
+
' WHERE '+key+'>? ORDER BY '+key+' ASC LIMIT ?').all(source.cursor,limit);
|
|
65
|
+
} finally { db.close(); }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function readHttp(source,secret,limit,signal) {
|
|
69
|
+
const address=new URL(source.endpoint);
|
|
70
|
+
address.searchParams.set('after',source.cursor);
|
|
71
|
+
address.searchParams.set('limit',limit);
|
|
72
|
+
const headers={Accept:'application/json'};
|
|
73
|
+
if (secret) headers.Authorization='Bearer '+secret;
|
|
74
|
+
let res;
|
|
75
|
+
try { res=await fetch(address,{headers,redirect:'error',signal}); }
|
|
76
|
+
catch { fail('无法连接数据源,请核对地址、TLS 和服务状态',502); }
|
|
77
|
+
if (!res.ok) fail('数据源返回 HTTP '+res.status,502);
|
|
78
|
+
const reader=res.body.getReader(), chunks=[];
|
|
79
|
+
let size=0;
|
|
80
|
+
try {
|
|
81
|
+
for (;;) {
|
|
82
|
+
const {done,value}=await reader.read();
|
|
83
|
+
if (done) break;
|
|
84
|
+
size+=value.byteLength;
|
|
85
|
+
if (size>4*1024*1024) fail('数据源响应超过 4 MB,请缩小单页内容',422);
|
|
86
|
+
chunks.push(Buffer.from(value));
|
|
87
|
+
}
|
|
88
|
+
} finally { await reader.cancel().catch(()=>{}); reader.releaseLock(); }
|
|
89
|
+
let json;
|
|
90
|
+
try { json=JSON.parse(Buffer.concat(chunks).toString('utf8')); }
|
|
91
|
+
catch { fail('数据源应返回 JSON 数组或包含 rows 的对象',422); }
|
|
92
|
+
return Array.isArray(json) ? json : json?.rows;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function read(source,secret,signal) {
|
|
96
|
+
const raw=source.kind==='sqlite' ? readSqlite(source,pageSize+1) : await readHttp(source,secret,pageSize,signal);
|
|
97
|
+
if (!Array.isArray(raw) || raw.length>pageSize+(source.kind==='sqlite'?1:0)) fail('检查数据源 JSON 结构与 limit 参数',422);
|
|
98
|
+
let cursor=source.cursor;
|
|
99
|
+
const rows=[];
|
|
100
|
+
for (const sourceRow of raw) {
|
|
101
|
+
if (!sourceRow || typeof sourceRow!=='object' || Array.isArray(sourceRow)) fail('数据源返回了无效行',422);
|
|
102
|
+
const key=Object.hasOwn(sourceRow,source.cursorField) ? sourceRow[source.cursorField] : undefined;
|
|
103
|
+
const number=typeof key==='number'||typeof key==='string' && /^\d+$/.test(key) ? Number(key) : NaN;
|
|
104
|
+
if (!Number.isSafeInteger(number) || number<=cursor) fail('游标必须为严格递增且唯一的整数',422);
|
|
105
|
+
cursor=number;
|
|
106
|
+
const record=Object.fromEntries(Object.entries(source.mapping).map(([field,column])=>[field,
|
|
107
|
+
Object.hasOwn(sourceRow,column)?sourceRow[column]:undefined]));
|
|
108
|
+
if (!record.workshop) record.workshop=source.workshop;
|
|
109
|
+
if (source.target==='issues' && !record.externalIssueNumber) record.externalIssueNumber=source.id+'-'+number;
|
|
110
|
+
if (source.target==='measurements') Object.assign(record,{sourceSystem:source.id,sourceMeasurementId:String(number)});
|
|
111
|
+
if (source.target==='defects') Object.assign(record,{sourceSystem:source.id,sourceRecordId:String(number)});
|
|
112
|
+
rows.push({record,cursor:number});
|
|
113
|
+
}
|
|
114
|
+
const page=rows.slice(0,pageSize);
|
|
115
|
+
return {records:page.map(row=>row.record),cursor:page.at(-1)?.cursor ?? source.cursor,hasMore:raw.length>=pageSize};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
module.exports = { config,read };
|
package/src/lib/demo-data.js
CHANGED
|
@@ -8,6 +8,11 @@ const { seedSme } = require('../data/seed-sme');
|
|
|
8
8
|
const main = ['issues', 'projects', 'measurements', 'spcChars', 'knowledge', 'defects', 'qrqc', 'workflows', 'todos', 'benefits', 'members'];
|
|
9
9
|
const supplier = ['suppliers', 'scars'];
|
|
10
10
|
const rd = ['rdprojects', 'dfmea', 'trialRuns', 'designIssues', 'relTests'];
|
|
11
|
+
const rdProjectExamples = new Map([
|
|
12
|
+
['RDP-001', { name: '产品甲二代·轻量化外壳', number: 1 }],
|
|
13
|
+
['RDP-002', { name: '产品乙·带防错线束总成', number: 2 }],
|
|
14
|
+
['RDP-003', { name: '产品甲·快装卡扣改型', number: 3 }],
|
|
15
|
+
]);
|
|
11
16
|
const collections = [...main, ...supplier, ...rd];
|
|
12
17
|
const names = {
|
|
13
18
|
issues: '质量问题', projects: '改进项目', measurements: 'SPC 测量', spcChars: 'SPC 特性',
|
|
@@ -28,6 +33,27 @@ function fixture(scale, date, extras) {
|
|
|
28
33
|
return sample.db;
|
|
29
34
|
}
|
|
30
35
|
|
|
36
|
+
function numberRdExamples(store, projectName, reserved = []) {
|
|
37
|
+
const projects = store.col('rdprojects').all();
|
|
38
|
+
const used = new Set([...reserved, ...projects.map(({ name }) => name)]);
|
|
39
|
+
const records = store.db.meta.demoRecords || {};
|
|
40
|
+
let next = rdProjectExamples.size;
|
|
41
|
+
let changed = false;
|
|
42
|
+
const numbered = projects.map((row) => {
|
|
43
|
+
const example = rdProjectExamples.get(row.id);
|
|
44
|
+
if (!example || row.name !== example.name) return row;
|
|
45
|
+
let name = projectName(example.number);
|
|
46
|
+
while (used.has(name)) name = projectName(++next);
|
|
47
|
+
used.add(name);
|
|
48
|
+
const updated = { ...row, name };
|
|
49
|
+
const key = keyOf('rdprojects', row);
|
|
50
|
+
if (records[key] === hash(row)) records[key] = hash(updated);
|
|
51
|
+
changed = true;
|
|
52
|
+
return updated;
|
|
53
|
+
});
|
|
54
|
+
if (changed) store.replace('rdprojects', numbered);
|
|
55
|
+
}
|
|
56
|
+
|
|
31
57
|
// Old seeders never wrote provenance. Require an exact match to the original content and seed time.
|
|
32
58
|
function legacyMatches(db, scale, extras) {
|
|
33
59
|
const date = new Date(db.meta.createdAt);
|
|
@@ -192,4 +218,4 @@ function prune(db) {
|
|
|
192
218
|
for (const key of Object.keys(records)) if (!existing.has(key)) delete records[key];
|
|
193
219
|
}
|
|
194
220
|
|
|
195
|
-
module.exports = { names, legacyMatches, load, preview, remove, prune };
|
|
221
|
+
module.exports = { names, rdProjectExamples, numberRdExamples, legacyMatches, load, preview, remove, prune };
|
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { createHash, randomBytes } = require('node:crypto');
|
|
4
|
-
const workbench = require('./workbench');
|
|
5
|
-
|
|
6
|
-
const tokenPath = 'employeeIntakeTokens';
|
|
7
|
-
const validity = 30 * 86400000;
|
|
8
|
-
const fileLimit = 20 * 1024 * 1024;
|
|
9
|
-
const acceptableFile = /\.(?:docx|pdf|xlsx|csv|txt|md|png|jpe?g)$/i;
|
|
10
|
-
const targets = { issues:'问题清单', measurements:'测量数据', defects:'质检缺陷' };
|
|
11
|
-
const fail = (message, status = 400) => { throw Object.assign(new Error(message), { status }); };
|
|
12
|
-
const digest = (token) => createHash('sha256').update(token).digest('hex');
|
|
13
|
-
|
|
14
|
-
function employeeScope(actor, workshops) {
|
|
15
|
-
const assigned = workshops.includes(actor?.workshop) ? actor.workshop : '';
|
|
16
|
-
return {
|
|
17
|
-
key: workbench.personKey(actor), actor, workshop: assigned,
|
|
18
|
-
allowed: (target) => !actor || !!assigned || target === 'issues',
|
|
19
|
-
charAllowed: (row) => workshops.includes(row.workshop) && (!assigned || row.workshop === assigned),
|
|
20
|
-
row(target, record, feature, inputWorkshop) {
|
|
21
|
-
if (assigned && inputWorkshop && inputWorkshop !== assigned) fail('该行车间超出您的导入范围');
|
|
22
|
-
const workshop = feature?.workshop || inputWorkshop || assigned;
|
|
23
|
-
if (!workshops.includes(workshop) || assigned && workshop !== assigned) fail('请填写当前工作范围内的车间');
|
|
24
|
-
if (feature && inputWorkshop && inputWorkshop !== feature.workshop) fail('该行车间与特性所属车间不一致');
|
|
25
|
-
if (record.severity && !['A','B','C'].includes(record.severity)) fail('等级须填写 A、B 或 C');
|
|
26
|
-
if (record.confidence !== undefined && (record.confidence < 0 || record.confidence > 1)) fail('置信度须在 0 到 1 之间');
|
|
27
|
-
const attribution = { workshop, reporterMemberId: this.key, reportedBy: actor?.name || '本机使用者', source:'员工导入' };
|
|
28
|
-
return target === 'issues' ? { ...record, ...attribution, owner:'待指派', status:'整改中', reviewRequired:true, severity:record.severity || 'B' }
|
|
29
|
-
: { ...record, ...attribution };
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function tokenInfo(store, actor) {
|
|
35
|
-
const row = store.getSetting(tokenPath, {})[workbench.personKey(actor)];
|
|
36
|
-
return row && Date.parse(row.expiresAt) > Date.now() ? { expiresAt:row.expiresAt } : null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function rotateToken(store, actor) {
|
|
40
|
-
const token = 'qip_' + randomBytes(32).toString('hex');
|
|
41
|
-
const expiresAt = new Date(Date.now()+validity).toISOString();
|
|
42
|
-
const key = workbench.personKey(actor);
|
|
43
|
-
store.transaction(() => {
|
|
44
|
-
store.setSetting(tokenPath, {
|
|
45
|
-
...store.getSetting(tokenPath,{}), [key]: { digest:digest(token), expiresAt, workshop:actor?.workshop || '' },
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
return { token, expiresAt };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function revokeToken(store, actor) {
|
|
52
|
-
const key = workbench.personKey(actor);
|
|
53
|
-
store.transaction(() => {
|
|
54
|
-
const { [key]: removed, ...tokens } = store.getSetting(tokenPath,{});
|
|
55
|
-
store.setSetting(tokenPath, tokens);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function tokenActor(req, store, identity) {
|
|
60
|
-
const token = /^Bearer (qip_[0-9a-f]{64})$/i.exec(req.headers.authorization || '')?.[1];
|
|
61
|
-
if (!token) fail('请提供有效的员工导入令牌',401);
|
|
62
|
-
if (!identity.loopback(req) && !req.socket.encrypted) fail('远程数据接入需要 HTTPS',403);
|
|
63
|
-
const hash = digest(token);
|
|
64
|
-
const entry = Object.entries(store.getSetting(tokenPath,{})).find(([,row]) => row.digest === hash &&
|
|
65
|
-
Date.parse(row.expiresAt) > Date.now());
|
|
66
|
-
if (!entry) fail('导入令牌已失效,请重新生成',401);
|
|
67
|
-
const [owner, grant] = entry;
|
|
68
|
-
if (owner === 'local') {
|
|
69
|
-
if (identity.configured() || !identity.loopback(req)) fail('本机工作台的令牌仅在本机单人模式有效',403);
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
const account = identity.directoryView().accounts.find((item) => item.memberId === owner);
|
|
73
|
-
if (!account || !store.col('members').get(owner) || (account.workshop || '') !== grant.workshop) {
|
|
74
|
-
fail('员工或所属车间已变更,请重新生成令牌',403);
|
|
75
|
-
}
|
|
76
|
-
return account;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function allowFile(name, size) {
|
|
80
|
-
if (!acceptableFile.test(name || '')) fail('支持 PDF、Word、Excel、CSV、TXT、Markdown、PNG 和 JPG');
|
|
81
|
-
if (Number(size) > fileLimit) fail('单个文件最多 20 MB',413);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
module.exports = { employeeScope, tokenInfo, rotateToken, revokeToken, tokenActor, allowFile, fileLimit, targets };
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { createHash, randomBytes } = require('node:crypto');
|
|
4
|
+
const workbench = require('./workbench');
|
|
5
|
+
|
|
6
|
+
const tokenPath = 'employeeIntakeTokens';
|
|
7
|
+
const validity = 30 * 86400000;
|
|
8
|
+
const fileLimit = 20 * 1024 * 1024;
|
|
9
|
+
const acceptableFile = /\.(?:docx|pdf|xlsx|csv|txt|md|png|jpe?g)$/i;
|
|
10
|
+
const targets = { issues:'问题清单', measurements:'测量数据', defects:'质检缺陷' };
|
|
11
|
+
const fail = (message, status = 400) => { throw Object.assign(new Error(message), { status }); };
|
|
12
|
+
const digest = (token) => createHash('sha256').update(token).digest('hex');
|
|
13
|
+
|
|
14
|
+
function employeeScope(actor, workshops) {
|
|
15
|
+
const assigned = workshops.includes(actor?.workshop) ? actor.workshop : '';
|
|
16
|
+
return {
|
|
17
|
+
key: workbench.personKey(actor), actor, workshop: assigned,
|
|
18
|
+
allowed: (target) => !actor || !!assigned || target === 'issues',
|
|
19
|
+
charAllowed: (row) => workshops.includes(row.workshop) && (!assigned || row.workshop === assigned),
|
|
20
|
+
row(target, record, feature, inputWorkshop) {
|
|
21
|
+
if (assigned && inputWorkshop && inputWorkshop !== assigned) fail('该行车间超出您的导入范围');
|
|
22
|
+
const workshop = feature?.workshop || inputWorkshop || assigned;
|
|
23
|
+
if (!workshops.includes(workshop) || assigned && workshop !== assigned) fail('请填写当前工作范围内的车间');
|
|
24
|
+
if (feature && inputWorkshop && inputWorkshop !== feature.workshop) fail('该行车间与特性所属车间不一致');
|
|
25
|
+
if (record.severity && !['A','B','C'].includes(record.severity)) fail('等级须填写 A、B 或 C');
|
|
26
|
+
if (record.confidence !== undefined && (record.confidence < 0 || record.confidence > 1)) fail('置信度须在 0 到 1 之间');
|
|
27
|
+
const attribution = { workshop, reporterMemberId: this.key, reportedBy: actor?.name || '本机使用者', source:'员工导入' };
|
|
28
|
+
return target === 'issues' ? { ...record, ...attribution, owner:'待指派', status:'整改中', reviewRequired:true, severity:record.severity || 'B' }
|
|
29
|
+
: { ...record, ...attribution };
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function tokenInfo(store, actor) {
|
|
35
|
+
const row = store.getSetting(tokenPath, {})[workbench.personKey(actor)];
|
|
36
|
+
return row && Date.parse(row.expiresAt) > Date.now() ? { expiresAt:row.expiresAt } : null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function rotateToken(store, actor) {
|
|
40
|
+
const token = 'qip_' + randomBytes(32).toString('hex');
|
|
41
|
+
const expiresAt = new Date(Date.now()+validity).toISOString();
|
|
42
|
+
const key = workbench.personKey(actor);
|
|
43
|
+
store.transaction(() => {
|
|
44
|
+
store.setSetting(tokenPath, {
|
|
45
|
+
...store.getSetting(tokenPath,{}), [key]: { digest:digest(token), expiresAt, workshop:actor?.workshop || '' },
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
return { token, expiresAt };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function revokeToken(store, actor) {
|
|
52
|
+
const key = workbench.personKey(actor);
|
|
53
|
+
store.transaction(() => {
|
|
54
|
+
const { [key]: removed, ...tokens } = store.getSetting(tokenPath,{});
|
|
55
|
+
store.setSetting(tokenPath, tokens);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function tokenActor(req, store, identity) {
|
|
60
|
+
const token = /^Bearer (qip_[0-9a-f]{64})$/i.exec(req.headers.authorization || '')?.[1];
|
|
61
|
+
if (!token) fail('请提供有效的员工导入令牌',401);
|
|
62
|
+
if (!identity.loopback(req) && !req.socket.encrypted) fail('远程数据接入需要 HTTPS',403);
|
|
63
|
+
const hash = digest(token);
|
|
64
|
+
const entry = Object.entries(store.getSetting(tokenPath,{})).find(([,row]) => row.digest === hash &&
|
|
65
|
+
Date.parse(row.expiresAt) > Date.now());
|
|
66
|
+
if (!entry) fail('导入令牌已失效,请重新生成',401);
|
|
67
|
+
const [owner, grant] = entry;
|
|
68
|
+
if (owner === 'local') {
|
|
69
|
+
if (identity.configured() || !identity.loopback(req)) fail('本机工作台的令牌仅在本机单人模式有效',403);
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const account = identity.directoryView().accounts.find((item) => item.memberId === owner);
|
|
73
|
+
if (!account || !store.col('members').get(owner) || (account.workshop || '') !== grant.workshop) {
|
|
74
|
+
fail('员工或所属车间已变更,请重新生成令牌',403);
|
|
75
|
+
}
|
|
76
|
+
return account;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function allowFile(name, size) {
|
|
80
|
+
if (!acceptableFile.test(name || '')) fail('支持 PDF、Word、Excel、CSV、TXT、Markdown、PNG 和 JPG');
|
|
81
|
+
if (Number(size) > fileLimit) fail('单个文件最多 20 MB',413);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
module.exports = { employeeScope, tokenInfo, rotateToken, revokeToken, tokenActor, allowFile, fileLimit, targets };
|
package/src/lib/growth.js
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const skills = ['8D', '数据分析', '现场工艺', '沟通协调', '标准法规', 'AI应用'];
|
|
4
|
-
const lastStage = 6;
|
|
5
|
-
|
|
6
|
-
function optionalNumber(input, name, min, max, integer = false) {
|
|
7
|
-
if (input === null || input === undefined || input === '') return null;
|
|
8
|
-
if (typeof input !== 'number' || !Number.isFinite(input) ||
|
|
9
|
-
input < min || input > max || integer && !Number.isInteger(input)) {
|
|
10
|
-
throw Object.assign(new Error(name + '须填写 ' + min + '~' + max + (integer ? ' 的整数' : ' 的数字')), { status: 400 });
|
|
11
|
-
}
|
|
12
|
-
return input;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function goals(input) {
|
|
16
|
-
return {
|
|
17
|
-
independentWeeks: optionalNumber(input.independentWeeks, '独立上手目标周期', 1, 104, true),
|
|
18
|
-
firstPassTarget: optionalNumber(input.firstPassTarget, '8D 一次通过率目标', 0, 100),
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function profile(input, dept, previous) {
|
|
23
|
-
const scores = { ...previous.skills };
|
|
24
|
-
for (const skill of skills) {
|
|
25
|
-
const value = optionalNumber(input.skills?.[skill], skill + '评分', 0, 100);
|
|
26
|
-
if (value === null) delete scores[skill];
|
|
27
|
-
else scores[skill] = value;
|
|
28
|
-
}
|
|
29
|
-
return {
|
|
30
|
-
dept,
|
|
31
|
-
seniority: optionalNumber(input.seniority, '司龄', 0, 80),
|
|
32
|
-
growthStage: optionalNumber(input.growthStage, '已完成阶段', 0, lastStage, true),
|
|
33
|
-
skills: scores,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function snapshot(rows, dept) {
|
|
38
|
-
const members = rows.map(({ id, name, dept: department, seniority, skills: scores, growthStage, updatedAt }) =>
|
|
39
|
-
({ id, name, dept: String(department || '').trim(), seniority, skills: scores, growthStage, updatedAt }));
|
|
40
|
-
const team = members.filter((m) => dept && m.dept === dept);
|
|
41
|
-
const isScore = (value) => typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= 100;
|
|
42
|
-
const averages = skills.map((skill) => {
|
|
43
|
-
const values = team.map((m) => m.skills?.[skill]).filter(isScore);
|
|
44
|
-
return { skill, count: values.length, value: values.length ? Math.round(values.reduce((a, b) => a + b, 0) / values.length * 10) / 10 : null };
|
|
45
|
-
});
|
|
46
|
-
const tracked = team.filter(({ growthStage }) => Number.isInteger(growthStage) && growthStage >= 0 && growthStage <= lastStage);
|
|
47
|
-
return { members, dept, headcount: team.length, averages, tracked: tracked.length,
|
|
48
|
-
recentHires: team.filter((m) => isScore(m.seniority) && m.seniority <= 2).length,
|
|
49
|
-
unrecordedSeniority: team.filter((m) => !isScore(m.seniority)).length,
|
|
50
|
-
completed: Array.from({ length: lastStage }, (_, index) => tracked.filter((m) => m.growthStage > index).length) };
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
module.exports = { goals, profile, snapshot };
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const skills = ['8D', '数据分析', '现场工艺', '沟通协调', '标准法规', 'AI应用'];
|
|
4
|
+
const lastStage = 6;
|
|
5
|
+
|
|
6
|
+
function optionalNumber(input, name, min, max, integer = false) {
|
|
7
|
+
if (input === null || input === undefined || input === '') return null;
|
|
8
|
+
if (typeof input !== 'number' || !Number.isFinite(input) ||
|
|
9
|
+
input < min || input > max || integer && !Number.isInteger(input)) {
|
|
10
|
+
throw Object.assign(new Error(name + '须填写 ' + min + '~' + max + (integer ? ' 的整数' : ' 的数字')), { status: 400 });
|
|
11
|
+
}
|
|
12
|
+
return input;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function goals(input) {
|
|
16
|
+
return {
|
|
17
|
+
independentWeeks: optionalNumber(input.independentWeeks, '独立上手目标周期', 1, 104, true),
|
|
18
|
+
firstPassTarget: optionalNumber(input.firstPassTarget, '8D 一次通过率目标', 0, 100),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function profile(input, dept, previous) {
|
|
23
|
+
const scores = { ...previous.skills };
|
|
24
|
+
for (const skill of skills) {
|
|
25
|
+
const value = optionalNumber(input.skills?.[skill], skill + '评分', 0, 100);
|
|
26
|
+
if (value === null) delete scores[skill];
|
|
27
|
+
else scores[skill] = value;
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
dept,
|
|
31
|
+
seniority: optionalNumber(input.seniority, '司龄', 0, 80),
|
|
32
|
+
growthStage: optionalNumber(input.growthStage, '已完成阶段', 0, lastStage, true),
|
|
33
|
+
skills: scores,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function snapshot(rows, dept) {
|
|
38
|
+
const members = rows.map(({ id, name, dept: department, seniority, skills: scores, growthStage, updatedAt }) =>
|
|
39
|
+
({ id, name, dept: String(department || '').trim(), seniority, skills: scores, growthStage, updatedAt }));
|
|
40
|
+
const team = members.filter((m) => dept && m.dept === dept);
|
|
41
|
+
const isScore = (value) => typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= 100;
|
|
42
|
+
const averages = skills.map((skill) => {
|
|
43
|
+
const values = team.map((m) => m.skills?.[skill]).filter(isScore);
|
|
44
|
+
return { skill, count: values.length, value: values.length ? Math.round(values.reduce((a, b) => a + b, 0) / values.length * 10) / 10 : null };
|
|
45
|
+
});
|
|
46
|
+
const tracked = team.filter(({ growthStage }) => Number.isInteger(growthStage) && growthStage >= 0 && growthStage <= lastStage);
|
|
47
|
+
return { members, dept, headcount: team.length, averages, tracked: tracked.length,
|
|
48
|
+
recentHires: team.filter((m) => isScore(m.seniority) && m.seniority <= 2).length,
|
|
49
|
+
unrecordedSeniority: team.filter((m) => !isScore(m.seniority)).length,
|
|
50
|
+
completed: Array.from({ length: lastStage }, (_, index) => tracked.filter((m) => m.growthStage > index).length) };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = { goals, profile, snapshot };
|