test_debug_info_preservation.html 18 KB

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