probe-dms-title.mjs 6.5 KB

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