/** * 验证 DMS 的 `title` 字段行为 —— 为「改名同步 title」与「记录 title 用问题文本」两件事定契约。 * * 要回答的问题: * ① 1887 的模型今天新增了 4 个 must 字段(summary/qpyszx/qyzt/rzqpyx), * 不带它们写入会被 214 拒 —— 那**带上就成功吗**? * ② `title` 是系统字段,能不能直接在 content 里写?写了会被 214 还是被接受? * ③ 改 `c_title`(改名路径)后,系统的 `title` 会不会跟着变? * ④ 1889 的 `title` 现在恒为 "null",能否写成问题文本? * * 怎么跑(token 从参数读,不落盘): * node harness/tools/probe-dms-title.mjs * * 脚本只写 `probe-title-*` 标记的数据,**结束时全部清理**。 */ const HOST = process.env.DMS_HOST || '121.43.55.7:10081'; const BASE = `http://${HOST}/dms`; const TOKEN = process.argv[2] || ''; if (!TOKEN) { console.error('用法:node harness/tools/probe-dms-title.mjs '); process.exit(2); } const call = async (method, path, form) => { const init = { method, headers: { token: TOKEN } }; if (form) { init.headers['Content-Type'] = 'application/x-www-form-urlencoded'; init.body = new URLSearchParams(form).toString(); } const res = await fetch(`${BASE}${path}`, init); const text = await res.text(); let json = null; try { json = JSON.parse(text); } catch { /* 非 JSON */ } return { status: res.status, json, text }; }; const find = async (columnId, field, value) => { const r = await call('POST', '/content/selectContentList', { columnId: String(columnId), page: '0', pageSize: '10', search: JSON.stringify([{ field, searchType: 1, content: { value } }]), }); return (r.json?.content?.data || [])[0] || null; }; const add = (columnId, modelId, content) => call('POST', '/content/addContent', { columnId: String(columnId), modelId: String(modelId), content: JSON.stringify(content) }); const update = (columnId, modelId, content) => call('POST', '/content/updateContent', { columnId: String(columnId), modelId: String(modelId), content: JSON.stringify(content) }); const del = (columnId, id) => call('POST', '/content/updateAudit', { columnId: String(columnId), id, state: '4' }); const TAG = `probe-title-${Date.now().toString(36)}`; const created = []; const run = async () => { console.log(`\nDMS title 字段探测 标记=${TAG}\n`); // ── ① 1887:带 must 字段写入 ─────────────────────────────────────── console.log('【1】1887:带新 must 字段(summary/qpyszx/qyzt/rzqpyx)写入'); const base = { c_credit_code: TAG, c_session_id: TAG, c_title: '标题A', c_source: 'zhaoshang', summary: TAG, qpyszx: true, qyzt: true, rzqpyx: false, }; let r = await add(1887, 2034, base); console.log(' → code=%s %s', r.json?.code, r.json?.message); if (r.json?.code === 200) { created.push(['1887', String(r.json.content)]); let row = await find(1887, 'c_session_id', TAG); console.log(' 读回: c_title=%s | 系统 title=%s', JSON.stringify(row?.c_title), JSON.stringify(row?.title)); // ── ③ 改名:改 c_title,看系统 title 跟不跟 ────────────────────── console.log('\n【3】改 c_title → 看系统 title 是否跟随'); const u = await update(1887, 2034, { id: String(r.json.content), c_title: '标题B' }); console.log(' updateContent → code=%s %s', u.json?.code, u.json?.message); row = await find(1887, 'c_session_id', TAG); console.log(' 读回: c_title=%s | 系统 title=%s', JSON.stringify(row?.c_title), JSON.stringify(row?.title)); } // ── ② 1887:再试「显式带 title」能不能写 ────────────────────────── console.log('\n【2】1887:content 里显式带 title,会被接受还是 214?'); const base2 = { ...base, c_session_id: TAG + '-2', title: '显式title值' }; r = await add(1887, 2034, base2); console.log(' → code=%s %s', r.json?.code, r.json?.message); if (r.json?.code === 200) { created.push(['1887', String(r.json.content)]); const row = await find(1887, 'c_session_id', TAG + '-2'); console.log(' 读回: c_title=%s | 系统 title=%s', JSON.stringify(row?.c_title), JSON.stringify(row?.title)); } // ── ④ 1889:记录行写 title = 问题文本 ───────────────────────────── console.log('\n【4】1889:content 里带 title=问题文本'); const rec = { c_credit_code: TAG, c_session_id: TAG, c_record_id: TAG, c_question: '这是一条测试问题', c_answer: '这是测试回答', c_source: 'zhaoshang', title: '这是一条测试问题', summary: TAG, }; r = await add(1889, 2038, rec); console.log(' → code=%s %s', r.json?.code, r.json?.message); if (r.json?.code === 200) { created.push(['1889', String(r.json.content)]); const row = await find(1889, 'c_record_id', TAG); console.log(' 读回: c_question=%s | 系统 title=%s', JSON.stringify(row?.c_question), JSON.stringify(row?.title)); console.log('\n → 再试:不带 title,只带 c_question(对照)'); const r2 = await add(1889, 2038, { ...rec, c_record_id: TAG + '-2', title: undefined }); console.log(' code=%s %s', r2.json?.code, r2.json?.message); if (r2.json?.code === 200) { created.push(['1889', String(r2.json.content)]); const row2 = await find(1889, 'c_record_id', TAG + '-2'); console.log(' 读回: 系统 title=%s', JSON.stringify(row2?.title)); } } // ── 清理 ────────────────────────────────────────────────────────── console.log('\n【清理】'); for (const [col, id] of created) { const d = await del(Number(col), id); console.log(' 删 %s %s → %s', col, id.slice(0, 8), d.json?.code); } const left = [...(await find(1887, 'c_credit_code', TAG) ? [1] : []), ...(await find(1889, 'c_credit_code', TAG) ? [1] : [])]; console.log(' 残留:', left.length ? left.length + ' 行(需手工处理)' : '0 ✓'); }; run().catch((e) => { console.error('脚本异常:', e); process.exit(1); });