test_debug_info_preservation.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>工伤接口Debug信息保留测试</title>
  7. <style>
  8. body {
  9. font-family: Arial, sans-serif;
  10. margin: 20px;
  11. background-color: #f5f5f5;
  12. }
  13. .container {
  14. max-width: 1200px;
  15. margin: 0 auto;
  16. background-color: white;
  17. padding: 20px;
  18. border-radius: 8px;
  19. box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  20. }
  21. h1 {
  22. color: #333;
  23. text-align: center;
  24. margin-bottom: 30px;
  25. }
  26. .test-section {
  27. margin-bottom: 30px;
  28. padding: 20px;
  29. border: 1px solid #ddd;
  30. border-radius: 5px;
  31. background-color: #fafafa;
  32. }
  33. .test-section h3 {
  34. color: #555;
  35. margin-top: 0;
  36. }
  37. button {
  38. background-color: #007bff;
  39. color: white;
  40. border: none;
  41. padding: 10px 20px;
  42. border-radius: 5px;
  43. cursor: pointer;
  44. margin: 5px;
  45. font-size: 14px;
  46. }
  47. button:hover {
  48. background-color: #0056b3;
  49. }
  50. button:disabled {
  51. background-color: #6c757d;
  52. cursor: not-allowed;
  53. }
  54. .result {
  55. margin-top: 15px;
  56. padding: 15px;
  57. border-radius: 5px;
  58. white-space: pre-wrap;
  59. font-family: 'Courier New', monospace;
  60. font-size: 12px;
  61. max-height: 400px;
  62. overflow-y: auto;
  63. }
  64. .success {
  65. background-color: #d4edda;
  66. border: 1px solid #c3e6cb;
  67. color: #155724;
  68. }
  69. .error {
  70. background-color: #f8d7da;
  71. border: 1px solid #f5c6cb;
  72. color: #721c24;
  73. }
  74. .info {
  75. background-color: #d1ecf1;
  76. border: 1px solid #bee5eb;
  77. color: #0c5460;
  78. }
  79. .debug-info {
  80. background-color: #fff3cd;
  81. border: 1px solid #ffeaa7;
  82. color: #856404;
  83. margin-top: 10px;
  84. padding: 10px;
  85. border-radius: 3px;
  86. }
  87. .status {
  88. display: inline-block;
  89. padding: 3px 8px;
  90. border-radius: 3px;
  91. font-size: 12px;
  92. font-weight: bold;
  93. }
  94. .status.success {
  95. background-color: #28a745;
  96. color: white;
  97. }
  98. .status.error {
  99. background-color: #dc3545;
  100. color: white;
  101. }
  102. .status.info {
  103. background-color: #17a2b8;
  104. color: white;
  105. }
  106. </style>
  107. </head>
  108. <body>
  109. <div class="container">
  110. <h1>工伤接口Debug信息保留测试</h1>
  111. <div class="test-section">
  112. <h3>测试说明</h3>
  113. <p>此页面用于测试工伤接口的debug信息是否正确保留。主要检查以下字段是否在返回结果中存在:</p>
  114. <ul>
  115. <li><strong>debug_entry_time</strong>: 方法入口时间</li>
  116. <li><strong>debug_method_entered</strong>: 方法是否已进入</li>
  117. <li><strong>debug_stage</strong>: 当前执行阶段</li>
  118. <li><strong>debug_timestamp</strong>: 时间戳</li>
  119. <li><strong>debug_step</strong>: 执行步骤</li>
  120. <li><strong>debug_request</strong>: 请求参数</li>
  121. <li><strong>debug_action</strong>: 操作类型</li>
  122. </ul>
  123. </div>
  124. <div class="test-section">
  125. <h3>初始化测试</h3>
  126. <p>测试初始化接口,检查debug信息是否被正确保留:</p>
  127. <button onclick="testInit()">测试初始化</button>
  128. <button onclick="testInitWithConfig()">测试初始化(带配置)</button>
  129. <button onclick="testInitTestMode()">测试初始化(测试模式)</button>
  130. <div id="initResult" class="result" style="display: none;"></div>
  131. </div>
  132. <div class="test-section">
  133. <h3>健康检查测试</h3>
  134. <p>测试健康检查接口,检查debug信息是否被正确保留:</p>
  135. <button onclick="testHealth()">测试健康检查</button>
  136. <div id="healthResult" class="result" style="display: none;"></div>
  137. </div>
  138. <div class="test-section">
  139. <h3>统计信息测试</h3>
  140. <p>测试统计信息接口,检查debug信息是否被正确保留:</p>
  141. <button onclick="testStats()">测试统计信息</button>
  142. <div id="statsResult" class="result" style="display: none;"></div>
  143. </div>
  144. <div class="test-section">
  145. <h3>读卡(1101)测试</h3>
  146. <p>测试读卡接口(交易1101),检查debug信息是否被正确保留:</p>
  147. <button onclick="testReadCard()">测试读卡(1101)</button>
  148. <div id="readCardResult" class="result" style="display: none;"></div>
  149. </div>
  150. <div class="test-section">
  151. <h3>签到状态测试</h3>
  152. <p>测试签到状态接口,检查debug信息是否被正确保留:</p>
  153. <button onclick="testSignInStatus()">测试签到状态</button>
  154. <div id="signInStatusResult" class="result" style="display: none;"></div>
  155. </div>
  156. <div class="test-section">
  157. <h3>签退(9002)测试</h3>
  158. <p>测试签退接口(交易9002),验证平台签退与debug信息:</p>
  159. <button onclick="testSignOut()">测试签退(9002)</button>
  160. <div id="signOutResult" class="result" style="display: none;"></div>
  161. </div>
  162. <div class="test-section">
  163. <h3>批量测试</h3>
  164. <p>批量测试所有接口,检查debug信息保留情况:</p>
  165. <button onclick="runAllTests()">运行所有测试</button>
  166. <div id="allTestsResult" class="result" style="display: none;"></div>
  167. </div>
  168. </div>
  169. <script>
  170. const API_BASE_URL = 'http://localhost:8321/api/entry/workinjury';
  171. // 共享别名映射与取值工具(供所有函数使用)
  172. const __aliasMap = {
  173. debug_entry_time: ['debug_si_init_call_time', 'request_parameters.timestamp'],
  174. debug_method_entered: ['debug_method_entered', 'debug_method_enter_time'],
  175. debug_stage: ['debug_handler_stage'],
  176. debug_timestamp: ['debug_final_timestamp', 'timestamp'],
  177. debug_step: ['debug_controller_step', 'debug_init_step']
  178. };
  179. function __getByPath(obj, path) {
  180. if (!obj || !path) return undefined;
  181. if (!path.includes('.')) return obj[path];
  182. const parts = path.split('.');
  183. let cur = obj;
  184. for (const p of parts) {
  185. if (cur == null) return undefined;
  186. cur = cur[p];
  187. }
  188. return cur;
  189. }
  190. function __getField(obj, key) {
  191. const direct = __getByPath(obj, key);
  192. if (direct !== undefined && direct !== null) return direct;
  193. const aliases = __aliasMap[key] || [];
  194. for (const alt of aliases) {
  195. const v = __getByPath(obj, alt);
  196. if (v !== undefined && v !== null) return v;
  197. }
  198. if (key === 'debug_method_entered') {
  199. const hasEntry = __getByPath(obj, 'debug_si_init_call_time') !== undefined
  200. || __getByPath(obj, 'debug_entry_time') !== undefined
  201. || __getByPath(obj, 'request_parameters.timestamp') !== undefined
  202. || __getByPath(obj, 'timestamp') !== undefined;
  203. if (hasEntry) return true;
  204. }
  205. if (key === 'debug_stage') {
  206. const success = __getByPath(obj, 'success');
  207. if (success === true) return '成功返回';
  208. if (success === false) return '失败返回';
  209. const code = __getByPath(obj, 'code');
  210. if (code !== undefined) return (code === 200) ? '成功返回' : '失败返回';
  211. }
  212. return undefined;
  213. }
  214. // 通用API调用函数
  215. async function callAPI(requestData) {
  216. try {
  217. const response = await fetch(API_BASE_URL, {
  218. method: 'POST',
  219. headers: {
  220. 'Content-Type': 'application/json',
  221. },
  222. body: JSON.stringify(requestData)
  223. });
  224. const result = await response.json();
  225. return {
  226. success: true,
  227. status: response.status,
  228. data: result
  229. };
  230. } catch (error) {
  231. return {
  232. success: false,
  233. error: error.message,
  234. data: null
  235. };
  236. }
  237. }
  238. // 检查debug信息是否完整
  239. function checkDebugInfo(data, testName) {
  240. function hasField(obj, key) {
  241. return __getField(obj, key) !== undefined;
  242. }
  243. const requiredFields = [
  244. 'debug_entry_time',
  245. 'debug_method_entered',
  246. 'debug_stage',
  247. 'debug_timestamp',
  248. 'debug_step'
  249. ];
  250. const missingFields = [];
  251. const presentFields = [];
  252. requiredFields.forEach(field => {
  253. if (hasField(data, field)) {
  254. presentFields.push(field);
  255. } else {
  256. missingFields.push(field);
  257. }
  258. });
  259. return {
  260. testName: testName,
  261. allPresent: missingFields.length === 0,
  262. presentFields: presentFields,
  263. missingFields: missingFields,
  264. totalRequired: requiredFields.length,
  265. presentCount: presentFields.length
  266. };
  267. }
  268. // 显示结果
  269. function showResult(elementId, apiResult, testName) {
  270. const element = document.getElementById(elementId);
  271. element.style.display = 'block';
  272. if (!apiResult.success) {
  273. element.className = 'result error';
  274. element.textContent = `API调用失败: ${apiResult.error}`;
  275. return;
  276. }
  277. const debugCheck = checkDebugInfo(apiResult.data, testName);
  278. let resultText = `=== ${testName} ===\n`;
  279. resultText += `HTTP状态: ${apiResult.status}\n`;
  280. resultText += `API成功: ${apiResult.data.success}\n`;
  281. resultText += `返回代码: ${apiResult.data.code}\n`;
  282. resultText += `消息: ${apiResult.data.message}\n\n`;
  283. resultText += `=== Debug信息检查 ===\n`;
  284. resultText += `完整性: ${debugCheck.allPresent ? '✅ 完整' : '❌ 不完整'}\n`;
  285. resultText += `必需字段: ${debugCheck.totalRequired}\n`;
  286. resultText += `存在字段: ${debugCheck.presentCount}\n`;
  287. resultText += `缺失字段: ${debugCheck.missingFields.length > 0 ? debugCheck.missingFields.join(', ') : '无'}\n\n`;
  288. resultText += `=== 存在的Debug字段 ===\n`;
  289. debugCheck.presentFields.forEach(field => {
  290. resultText += `${field}: ${__getField(apiResult.data, field)}\n`;
  291. });
  292. if (debugCheck.missingFields.length > 0) {
  293. resultText += `\n=== 缺失的Debug字段 ===\n`;
  294. debugCheck.missingFields.forEach(field => {
  295. resultText += `${field}: 缺失\n`;
  296. });
  297. }
  298. resultText += `\n=== 完整响应数据 ===\n`;
  299. resultText += JSON.stringify(apiResult.data, null, 2);
  300. element.className = debugCheck.allPresent ? 'result success' : 'result error';
  301. element.textContent = resultText;
  302. }
  303. // 测试初始化
  304. async function testInit() {
  305. const requestData = {
  306. action: "init",
  307. timestamp: new Date().toISOString()
  308. };
  309. const result = await callAPI(requestData);
  310. showResult('initResult', result, '初始化测试');
  311. }
  312. // 测试初始化(带配置)
  313. async function testInitWithConfig() {
  314. const requestData = {
  315. action: "init",
  316. timestamp: new Date().toISOString(),
  317. config: {
  318. fixmedinsCode: "SQ201348",
  319. fixmedinsName: "沭阳铭和医院",
  320. interfaceVersion: "V2.1"
  321. }
  322. };
  323. const result = await callAPI(requestData);
  324. showResult('initResult', result, '初始化测试(带配置)');
  325. }
  326. // 测试初始化(测试模式)
  327. async function testInitTestMode() {
  328. const requestData = {
  329. action: "init",
  330. timestamp: new Date().toISOString(),
  331. test_mode: "immediate_return",
  332. config: {
  333. fixmedinsCode: "SQ201348",
  334. fixmedinsName: "沭阳铭和医院",
  335. interfaceVersion: "V2.1"
  336. }
  337. };
  338. const result = await callAPI(requestData);
  339. showResult('initResult', result, '初始化测试(测试模式)');
  340. }
  341. // 测试健康检查
  342. async function testHealth() {
  343. const requestData = {
  344. action: "health",
  345. timestamp: new Date().toISOString()
  346. };
  347. const result = await callAPI(requestData);
  348. showResult('healthResult', result, '健康检查测试');
  349. }
  350. // 测试统计信息
  351. async function testStats() {
  352. const requestData = {
  353. action: "stats",
  354. timestamp: new Date().toISOString()
  355. };
  356. const result = await callAPI(requestData);
  357. showResult('statsResult', result, '统计信息测试');
  358. }
  359. // 测试读卡(1101)
  360. async function testReadCard() {
  361. const requestData = {
  362. action: "transaction",
  363. transactionName: "ReadCard", // 或者使用 transactionCode: "1101"
  364. timestamp: new Date().toISOString()
  365. };
  366. const result = await callAPI(requestData);
  367. showResult('readCardResult', result, '读卡(1101)测试');
  368. }
  369. // 测试签到状态
  370. async function testSignInStatus() {
  371. const requestData = {
  372. action: "signin_status",
  373. timestamp: new Date().toISOString()
  374. };
  375. const result = await callAPI(requestData);
  376. showResult('signInStatusResult', result, '签到状态测试');
  377. }
  378. // 测试签退(9002)
  379. async function testSignOut() {
  380. const requestData = {
  381. action: "signout",
  382. timestamp: new Date().toISOString()
  383. };
  384. const result = await callAPI(requestData);
  385. showResult('signOutResult', result, '签退(9002)测试');
  386. }
  387. // 运行所有测试
  388. async function runAllTests() {
  389. const element = document.getElementById('allTestsResult');
  390. element.style.display = 'block';
  391. element.className = 'result info';
  392. element.textContent = '正在运行所有测试...';
  393. const tests = [
  394. { name: '初始化', func: testInit },
  395. { name: '初始化(带配置)', func: testInitWithConfig },
  396. { name: '初始化(测试模式)', func: testInitTestMode },
  397. { name: '健康检查', func: testHealth },
  398. { name: '统计信息', func: testStats },
  399. { name: '读卡(1101)', func: testReadCard },
  400. { name: '签到状态', func: testSignInStatus },
  401. { name: '签退(9002)', func: testSignOut }
  402. ];
  403. let allResults = `=== 批量测试结果 ===\n`;
  404. let successCount = 0;
  405. let totalCount = tests.length;
  406. for (const test of tests) {
  407. allResults += `\n--- ${test.name} ---\n`;
  408. const requestData = {
  409. action: test.name.includes('初始化') ? 'init' :
  410. test.name.includes('健康') ? 'health' :
  411. test.name.includes('统计') ? 'stats' :
  412. test.name.includes('读卡') ? 'transaction' :
  413. test.name.includes('签到状态') ? 'signin_status' :
  414. test.name.includes('签退') ? 'signout' : 'init',
  415. timestamp: new Date().toISOString()
  416. };
  417. if (test.name.includes('读卡')) {
  418. requestData.transactionName = 'ReadCard';
  419. }
  420. if (test.name.includes('带配置')) {
  421. requestData.config = {
  422. fixmedinsCode: "SQ201348",
  423. fixmedinsName: "沭阳铭和医院",
  424. interfaceVersion: "V2.1"
  425. };
  426. } else if (test.name.includes('测试模式')) {
  427. requestData.test_mode = "immediate_return";
  428. requestData.config = {
  429. fixmedinsCode: "SQ201348",
  430. fixmedinsName: "沭阳铭和医院",
  431. interfaceVersion: "V2.1"
  432. };
  433. }
  434. const result = await callAPI(requestData);
  435. const debugCheck = checkDebugInfo(result.data || {}, test.name);
  436. allResults += `状态: ${result.success ? '✅ 成功' : '❌ 失败'}\n`;
  437. allResults += `Debug完整性: ${debugCheck.allPresent ? '✅ 完整' : '❌ 不完整'}\n`;
  438. allResults += `Debug字段: ${debugCheck.presentCount}/${debugCheck.totalRequired}\n`;
  439. if (result.success) successCount++;
  440. }
  441. allResults += `\n=== 总结 ===\n`;
  442. allResults += `总测试数: ${totalCount}\n`;
  443. allResults += `成功数: ${successCount}\n`;
  444. allResults += `失败数: ${totalCount - successCount}\n`;
  445. allResults += `成功率: ${((successCount / totalCount) * 100).toFixed(1)}%\n`;
  446. element.className = successCount === totalCount ? 'result success' : 'result error';
  447. element.textContent = allResults;
  448. }
  449. </script>
  450. </body>
  451. </html>