test_debug_info_preservation.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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>签到状态测试</h3>
  146. <p>测试签到状态接口,检查debug信息是否被正确保留:</p>
  147. <button onclick="testSignInStatus()">测试签到状态</button>
  148. <div id="signInStatusResult" class="result" style="display: none;"></div>
  149. </div>
  150. <div class="test-section">
  151. <h3>批量测试</h3>
  152. <p>批量测试所有接口,检查debug信息保留情况:</p>
  153. <button onclick="runAllTests()">运行所有测试</button>
  154. <div id="allTestsResult" class="result" style="display: none;"></div>
  155. </div>
  156. </div>
  157. <script>
  158. const API_BASE_URL = 'http://localhost:8321/api/entry/workinjury';
  159. // 共享别名映射与取值工具(供所有函数使用)
  160. const __aliasMap = {
  161. debug_entry_time: ['debug_si_init_call_time', 'request_parameters.timestamp'],
  162. debug_method_entered: ['debug_method_entered', 'debug_method_enter_time'],
  163. debug_stage: ['debug_handler_stage'],
  164. debug_timestamp: ['debug_final_timestamp', 'timestamp'],
  165. debug_step: ['debug_controller_step', 'debug_init_step']
  166. };
  167. function __getByPath(obj, path) {
  168. if (!obj || !path) return undefined;
  169. if (!path.includes('.')) return obj[path];
  170. const parts = path.split('.');
  171. let cur = obj;
  172. for (const p of parts) {
  173. if (cur == null) return undefined;
  174. cur = cur[p];
  175. }
  176. return cur;
  177. }
  178. function __getField(obj, key) {
  179. const direct = __getByPath(obj, key);
  180. if (direct !== undefined && direct !== null) return direct;
  181. const aliases = __aliasMap[key] || [];
  182. for (const alt of aliases) {
  183. const v = __getByPath(obj, alt);
  184. if (v !== undefined && v !== null) return v;
  185. }
  186. if (key === 'debug_method_entered') {
  187. const hasEntry = __getByPath(obj, 'debug_si_init_call_time') !== undefined
  188. || __getByPath(obj, 'debug_entry_time') !== undefined
  189. || __getByPath(obj, 'request_parameters.timestamp') !== undefined
  190. || __getByPath(obj, 'timestamp') !== undefined;
  191. if (hasEntry) return true;
  192. }
  193. if (key === 'debug_stage') {
  194. const success = __getByPath(obj, 'success');
  195. if (success === true) return '成功返回';
  196. if (success === false) return '失败返回';
  197. const code = __getByPath(obj, 'code');
  198. if (code !== undefined) return (code === 200) ? '成功返回' : '失败返回';
  199. }
  200. return undefined;
  201. }
  202. // 通用API调用函数
  203. async function callAPI(requestData) {
  204. try {
  205. const response = await fetch(API_BASE_URL, {
  206. method: 'POST',
  207. headers: {
  208. 'Content-Type': 'application/json',
  209. },
  210. body: JSON.stringify(requestData)
  211. });
  212. const result = await response.json();
  213. return {
  214. success: true,
  215. status: response.status,
  216. data: result
  217. };
  218. } catch (error) {
  219. return {
  220. success: false,
  221. error: error.message,
  222. data: null
  223. };
  224. }
  225. }
  226. // 检查debug信息是否完整
  227. function checkDebugInfo(data, testName) {
  228. function hasField(obj, key) {
  229. return __getField(obj, key) !== undefined;
  230. }
  231. const requiredFields = [
  232. 'debug_entry_time',
  233. 'debug_method_entered',
  234. 'debug_stage',
  235. 'debug_timestamp',
  236. 'debug_step'
  237. ];
  238. const missingFields = [];
  239. const presentFields = [];
  240. requiredFields.forEach(field => {
  241. if (hasField(data, field)) {
  242. presentFields.push(field);
  243. } else {
  244. missingFields.push(field);
  245. }
  246. });
  247. return {
  248. testName: testName,
  249. allPresent: missingFields.length === 0,
  250. presentFields: presentFields,
  251. missingFields: missingFields,
  252. totalRequired: requiredFields.length,
  253. presentCount: presentFields.length
  254. };
  255. }
  256. // 显示结果
  257. function showResult(elementId, apiResult, testName) {
  258. const element = document.getElementById(elementId);
  259. element.style.display = 'block';
  260. if (!apiResult.success) {
  261. element.className = 'result error';
  262. element.textContent = `API调用失败: ${apiResult.error}`;
  263. return;
  264. }
  265. const debugCheck = checkDebugInfo(apiResult.data, testName);
  266. let resultText = `=== ${testName} ===\n`;
  267. resultText += `HTTP状态: ${apiResult.status}\n`;
  268. resultText += `API成功: ${apiResult.data.success}\n`;
  269. resultText += `返回代码: ${apiResult.data.code}\n`;
  270. resultText += `消息: ${apiResult.data.message}\n\n`;
  271. resultText += `=== Debug信息检查 ===\n`;
  272. resultText += `完整性: ${debugCheck.allPresent ? '✅ 完整' : '❌ 不完整'}\n`;
  273. resultText += `必需字段: ${debugCheck.totalRequired}\n`;
  274. resultText += `存在字段: ${debugCheck.presentCount}\n`;
  275. resultText += `缺失字段: ${debugCheck.missingFields.length > 0 ? debugCheck.missingFields.join(', ') : '无'}\n\n`;
  276. resultText += `=== 存在的Debug字段 ===\n`;
  277. debugCheck.presentFields.forEach(field => {
  278. resultText += `${field}: ${__getField(apiResult.data, field)}\n`;
  279. });
  280. if (debugCheck.missingFields.length > 0) {
  281. resultText += `\n=== 缺失的Debug字段 ===\n`;
  282. debugCheck.missingFields.forEach(field => {
  283. resultText += `${field}: 缺失\n`;
  284. });
  285. }
  286. resultText += `\n=== 完整响应数据 ===\n`;
  287. resultText += JSON.stringify(apiResult.data, null, 2);
  288. element.className = debugCheck.allPresent ? 'result success' : 'result error';
  289. element.textContent = resultText;
  290. }
  291. // 测试初始化
  292. async function testInit() {
  293. const requestData = {
  294. action: "init",
  295. timestamp: new Date().toISOString()
  296. };
  297. const result = await callAPI(requestData);
  298. showResult('initResult', result, '初始化测试');
  299. }
  300. // 测试初始化(带配置)
  301. async function testInitWithConfig() {
  302. const requestData = {
  303. action: "init",
  304. timestamp: new Date().toISOString(),
  305. config: {
  306. fixmedinsCode: "SQ201348",
  307. fixmedinsName: "沭阳铭和医院",
  308. interfaceVersion: "V2.1"
  309. }
  310. };
  311. const result = await callAPI(requestData);
  312. showResult('initResult', result, '初始化测试(带配置)');
  313. }
  314. // 测试初始化(测试模式)
  315. async function testInitTestMode() {
  316. const requestData = {
  317. action: "init",
  318. timestamp: new Date().toISOString(),
  319. test_mode: "immediate_return",
  320. config: {
  321. fixmedinsCode: "SQ201348",
  322. fixmedinsName: "沭阳铭和医院",
  323. interfaceVersion: "V2.1"
  324. }
  325. };
  326. const result = await callAPI(requestData);
  327. showResult('initResult', result, '初始化测试(测试模式)');
  328. }
  329. // 测试健康检查
  330. async function testHealth() {
  331. const requestData = {
  332. action: "health",
  333. timestamp: new Date().toISOString()
  334. };
  335. const result = await callAPI(requestData);
  336. showResult('healthResult', result, '健康检查测试');
  337. }
  338. // 测试统计信息
  339. async function testStats() {
  340. const requestData = {
  341. action: "stats",
  342. timestamp: new Date().toISOString()
  343. };
  344. const result = await callAPI(requestData);
  345. showResult('statsResult', result, '统计信息测试');
  346. }
  347. // 测试签到状态
  348. async function testSignInStatus() {
  349. const requestData = {
  350. action: "signin_status",
  351. timestamp: new Date().toISOString()
  352. };
  353. const result = await callAPI(requestData);
  354. showResult('signInStatusResult', result, '签到状态测试');
  355. }
  356. // 运行所有测试
  357. async function runAllTests() {
  358. const element = document.getElementById('allTestsResult');
  359. element.style.display = 'block';
  360. element.className = 'result info';
  361. element.textContent = '正在运行所有测试...';
  362. const tests = [
  363. { name: '初始化', func: testInit },
  364. { name: '初始化(带配置)', func: testInitWithConfig },
  365. { name: '初始化(测试模式)', func: testInitTestMode },
  366. { name: '健康检查', func: testHealth },
  367. { name: '统计信息', func: testStats },
  368. { name: '签到状态', func: testSignInStatus }
  369. ];
  370. let allResults = `=== 批量测试结果 ===\n`;
  371. let successCount = 0;
  372. let totalCount = tests.length;
  373. for (const test of tests) {
  374. allResults += `\n--- ${test.name} ---\n`;
  375. const requestData = {
  376. action: test.name.includes('初始化') ? 'init' :
  377. test.name.includes('健康') ? 'health' :
  378. test.name.includes('统计') ? 'stats' :
  379. test.name.includes('签到') ? 'signin_status' : 'init',
  380. timestamp: new Date().toISOString()
  381. };
  382. if (test.name.includes('带配置')) {
  383. requestData.config = {
  384. fixmedinsCode: "SQ201348",
  385. fixmedinsName: "沭阳铭和医院",
  386. interfaceVersion: "V2.1"
  387. };
  388. } else if (test.name.includes('测试模式')) {
  389. requestData.test_mode = "immediate_return";
  390. requestData.config = {
  391. fixmedinsCode: "SQ201348",
  392. fixmedinsName: "沭阳铭和医院",
  393. interfaceVersion: "V2.1"
  394. };
  395. }
  396. const result = await callAPI(requestData);
  397. const debugCheck = checkDebugInfo(result.data || {}, test.name);
  398. allResults += `状态: ${result.success ? '✅ 成功' : '❌ 失败'}\n`;
  399. allResults += `Debug完整性: ${debugCheck.allPresent ? '✅ 完整' : '❌ 不完整'}\n`;
  400. allResults += `Debug字段: ${debugCheck.presentCount}/${debugCheck.totalRequired}\n`;
  401. if (result.success) successCount++;
  402. }
  403. allResults += `\n=== 总结 ===\n`;
  404. allResults += `总测试数: ${totalCount}\n`;
  405. allResults += `成功数: ${successCount}\n`;
  406. allResults += `失败数: ${totalCount - successCount}\n`;
  407. allResults += `成功率: ${((successCount / totalCount) * 100).toFixed(1)}%\n`;
  408. element.className = successCount === totalCount ? 'result success' : 'result error';
  409. element.textContent = allResults;
  410. }
  411. </script>
  412. </body>
  413. </html>