probe-dms-title.mjs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**
  2. * 验证 DMS 的 `title` 字段行为 —— 为「改名同步 title」与「记录 title 用问题文本」两件事定契约。
  3. *
  4. * 要回答的问题:
  5. * ① 1887 的模型今天新增了 4 个 must 字段(summary/qpyszx/qyzt/rzqpyx),
  6. * 不带它们写入会被 214 拒 —— 那**带上就成功吗**?
  7. * ② `title` 是系统字段,能不能直接在 content 里写?写了会被 214 还是被接受?
  8. * ③ 改 `c_title`(改名路径)后,系统的 `title` 会不会跟着变?
  9. * ④ 1889 的 `title` 现在恒为 "null",能否写成问题文本?
  10. *
  11. * 怎么跑(token 从参数读,不落盘):
  12. * node harness/tools/probe-dms-title.mjs <DMS_TOKEN>
  13. *
  14. * 脚本只写 `probe-title-*` 标记的数据,**结束时全部清理**。
  15. */
  16. const HOST = process.env.DMS_HOST || '121.43.55.7:10081';
  17. const BASE = `http://${HOST}/dms`;
  18. const TOKEN = process.argv[2] || '';
  19. if (!TOKEN) {
  20. console.error('用法:node harness/tools/probe-dms-title.mjs <DMS_TOKEN>');
  21. process.exit(2);
  22. }
  23. const call = async (method, path, form) => {
  24. const init = { method, headers: { token: TOKEN } };
  25. if (form) {
  26. init.headers['Content-Type'] = 'application/x-www-form-urlencoded';
  27. init.body = new URLSearchParams(form).toString();
  28. }
  29. const res = await fetch(`${BASE}${path}`, init);
  30. const text = await res.text();
  31. let json = null;
  32. try { json = JSON.parse(text); } catch { /* 非 JSON */ }
  33. return { status: res.status, json, text };
  34. };
  35. const find = async (columnId, field, value) => {
  36. const r = await call('POST', '/content/selectContentList', {
  37. columnId: String(columnId), page: '0', pageSize: '10',
  38. search: JSON.stringify([{ field, searchType: 1, content: { value } }]),
  39. });
  40. return (r.json?.content?.data || [])[0] || null;
  41. };
  42. const add = (columnId, modelId, content) =>
  43. call('POST', '/content/addContent', { columnId: String(columnId), modelId: String(modelId), content: JSON.stringify(content) });
  44. const update = (columnId, modelId, content) =>
  45. call('POST', '/content/updateContent', { columnId: String(columnId), modelId: String(modelId), content: JSON.stringify(content) });
  46. const del = (columnId, id) => call('POST', '/content/updateAudit', { columnId: String(columnId), id, state: '4' });
  47. const TAG = `probe-title-${Date.now().toString(36)}`;
  48. const created = [];
  49. const run = async () => {
  50. console.log(`\nDMS title 字段探测 标记=${TAG}\n`);
  51. // ── ① 1887:带 must 字段写入 ───────────────────────────────────────
  52. console.log('【1】1887:带新 must 字段(summary/qpyszx/qyzt/rzqpyx)写入');
  53. const base = {
  54. c_credit_code: TAG, c_session_id: TAG, c_title: '标题A', c_source: 'zhaoshang',
  55. summary: TAG, qpyszx: true, qyzt: true, rzqpyx: false,
  56. };
  57. let r = await add(1887, 2034, base);
  58. console.log(' → code=%s %s', r.json?.code, r.json?.message);
  59. if (r.json?.code === 200) {
  60. created.push(['1887', String(r.json.content)]);
  61. let row = await find(1887, 'c_session_id', TAG);
  62. console.log(' 读回: c_title=%s | 系统 title=%s', JSON.stringify(row?.c_title), JSON.stringify(row?.title));
  63. // ── ③ 改名:改 c_title,看系统 title 跟不跟 ──────────────────────
  64. console.log('\n【3】改 c_title → 看系统 title 是否跟随');
  65. const u = await update(1887, 2034, { id: String(r.json.content), c_title: '标题B' });
  66. console.log(' updateContent → code=%s %s', u.json?.code, u.json?.message);
  67. row = await find(1887, 'c_session_id', TAG);
  68. console.log(' 读回: c_title=%s | 系统 title=%s', JSON.stringify(row?.c_title), JSON.stringify(row?.title));
  69. }
  70. // ── ② 1887:再试「显式带 title」能不能写 ──────────────────────────
  71. console.log('\n【2】1887:content 里显式带 title,会被接受还是 214?');
  72. const base2 = { ...base, c_session_id: TAG + '-2', title: '显式title值' };
  73. r = await add(1887, 2034, base2);
  74. console.log(' → code=%s %s', r.json?.code, r.json?.message);
  75. if (r.json?.code === 200) {
  76. created.push(['1887', String(r.json.content)]);
  77. const row = await find(1887, 'c_session_id', TAG + '-2');
  78. console.log(' 读回: c_title=%s | 系统 title=%s', JSON.stringify(row?.c_title), JSON.stringify(row?.title));
  79. }
  80. // ── ④ 1889:记录行写 title = 问题文本 ─────────────────────────────
  81. console.log('\n【4】1889:content 里带 title=问题文本');
  82. const rec = {
  83. c_credit_code: TAG, c_session_id: TAG, c_record_id: TAG,
  84. c_question: '这是一条测试问题', c_answer: '这是测试回答',
  85. c_source: 'zhaoshang', title: '这是一条测试问题',
  86. summary: TAG,
  87. };
  88. r = await add(1889, 2038, rec);
  89. console.log(' → code=%s %s', r.json?.code, r.json?.message);
  90. if (r.json?.code === 200) {
  91. created.push(['1889', String(r.json.content)]);
  92. const row = await find(1889, 'c_record_id', TAG);
  93. console.log(' 读回: c_question=%s | 系统 title=%s', JSON.stringify(row?.c_question), JSON.stringify(row?.title));
  94. console.log('\n → 再试:不带 title,只带 c_question(对照)');
  95. const r2 = await add(1889, 2038, { ...rec, c_record_id: TAG + '-2', title: undefined });
  96. console.log(' code=%s %s', r2.json?.code, r2.json?.message);
  97. if (r2.json?.code === 200) {
  98. created.push(['1889', String(r2.json.content)]);
  99. const row2 = await find(1889, 'c_record_id', TAG + '-2');
  100. console.log(' 读回: 系统 title=%s', JSON.stringify(row2?.title));
  101. }
  102. }
  103. // ── 清理 ──────────────────────────────────────────────────────────
  104. console.log('\n【清理】');
  105. for (const [col, id] of created) {
  106. const d = await del(Number(col), id);
  107. console.log(' 删 %s %s → %s', col, id.slice(0, 8), d.json?.code);
  108. }
  109. const left = [...(await find(1887, 'c_credit_code', TAG) ? [1] : []), ...(await find(1889, 'c_credit_code', TAG) ? [1] : [])];
  110. console.log(' 残留:', left.length ? left.length + ' 行(需手工处理)' : '0 ✓');
  111. };
  112. run().catch((e) => { console.error('脚本异常:', e); process.exit(1); });