index.bak2.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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>车牌识别监控系统</title>
  7. <style>
  8. * { box-sizing: border-box; margin: 0; padding: 0; }
  9. body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f5f5f5; }
  10. .header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 20px; text-align: center; }
  11. .header h1 { font-size: 24px; margin-bottom: 5px; }
  12. .container { display: flex; gap: 20px; padding: 20px; max-width: 1400px; margin: 0 auto; }
  13. .panel { background: white; border-radius: 10px; padding: 20px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
  14. .report-panel { width: 320px; flex-shrink: 0; }
  15. .list-panel { flex: 1; min-width: 0; }
  16. .panel h2 { font-size: 18px; color: #333; margin-bottom: 15px; border-bottom: 2px solid #667eea; padding-bottom: 10px; }
  17. .metric { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid #eee; }
  18. .metric:last-child { border-bottom: none; }
  19. .metric-label { color: #666; font-size: 14px; }
  20. .metric-value { font-weight: bold; color: #333; font-size: 14px; }
  21. .metric-value.success { color: #52c41a; }
  22. .metric-value.warning { color: #faad14; }
  23. .metric-value.error { color: #f5222d; }
  24. .search-box { display: flex; gap: 10px; margin-bottom: 15px; }
  25. .search-box input { flex: 1; padding: 10px; border: 1px solid #ddd; border-radius: 5px; font-size: 14px; }
  26. .search-box button { padding: 10px 20px; background: #667eea; color: white; border: none; border-radius: 5px; cursor: pointer; font-size: 14px; }
  27. .search-box button:hover { background: #764ba2; }
  28. .table-container { overflow-x: auto; }
  29. table { width: 100%; border-collapse: collapse; font-size: 13px; }
  30. th, td { padding: 10px 8px; text-align: left; border-bottom: 1px solid #eee; }
  31. th { background: #f8f9fa; font-weight: 600; color: #333; white-space: nowrap; }
  32. tr:hover { background: #f8f9fa; }
  33. .status { padding: 3px 8px; border-radius: 3px; font-size: 12px; display: inline-block; }
  34. .status-success { background: #d9f7be; color: #52c41a; }
  35. .status-failed { background: #fff1f0; color: #f5222d; }
  36. .status-retry { background: #fff7e6; color: #fa8c16; }
  37. .status-pending { background: #f0f5ff; color: #1890ff; }
  38. .btn-retry { padding: 3px 8px; background: #1890ff; color: white; border: none; border-radius: 3px; cursor: pointer; font-size: 12px; }
  39. .btn-retry:hover { background: #40a9ff; }
  40. .btn-retry:disabled { background: #d9d9d9; cursor: not-allowed; }
  41. .photo-thumb { width: 60px; height: 40px; object-fit: cover; border-radius: 3px; cursor: pointer; border: 1px solid #ddd; }
  42. .photo-modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); z-index: 1000; justify-content: center; align-items: center; }
  43. .photo-modal.active { display: flex; }
  44. .photo-modal img { max-width: 90%; max-height: 90%; border-radius: 5px; }
  45. .photo-modal-close { position: absolute; top: 20px; right: 20px; color: white; font-size: 30px; cursor: pointer; }
  46. .pagination { display: flex; justify-content: center; align-items: center; gap: 10px; margin-top: 15px; }
  47. .pagination button { padding: 8px 15px; border: 1px solid #ddd; background: white; border-radius: 5px; cursor: pointer; }
  48. .pagination button:hover { background: #f0f5ff; }
  49. .pagination button:disabled { background: #f5f5f5; color: #d9d9d9; cursor: not-allowed; }
  50. .pagination .info { color: #666; font-size: 14px; }
  51. .refresh-info { text-align: center; margin-top: 10px; color: #999; font-size: 12px; }
  52. .loading { text-align: center; padding: 20px; color: #666; }
  53. @media (max-width: 900px) {
  54. .container { flex-direction: column; }
  55. .report-panel { width: 100%; }
  56. }
  57. </style>
  58. </head>
  59. <body>
  60. <div class="header">
  61. <h1>车牌识别监控系统</h1>
  62. <p>Plate Recognition Monitoring System v43.2-fix9</p>
  63. </div>
  64. <div class="container">
  65. <div class="panel report-panel">
  66. <h2>监控报告</h2>
  67. <div id="monitor-report">
  68. <div class="loading">加载中...</div>
  69. </div>
  70. </div>
  71. <div class="panel list-panel">
  72. <h2>实时消息列表</h2>
  73. <div class="search-box">
  74. <input type="text" id="search-input" placeholder="搜索车牌号/联单编号/日期时间">
  75. <button onclick="searchMessages(1)">搜索</button>
  76. </div>
  77. <div class="table-container">
  78. <table>
  79. <thead>
  80. <tr>
  81. <th>编号</th>
  82. <th>日期时间</th>
  83. <th>车牌号</th>
  84. <th>联单编号</th>
  85. <th>类型</th>
  86. <th>低位照片</th>
  87. <th>高位照片</th>
  88. <th>上传状态</th>
  89. <th>飞书状态</th>
  90. <th>操作</th>
  91. </tr>
  92. </thead>
  93. <tbody id="messages-body">
  94. <tr><td colspan="10" class="loading">加载中...</td></tr>
  95. </tbody>
  96. </table>
  97. </div>
  98. <div class="pagination" id="pagination"></div>
  99. <div class="refresh-info">数据自动刷新间隔: 30秒</div>
  100. </div>
  101. </div>
  102. <div class="photo-modal" id="photo-modal" onclick="closePhotoModal()">
  103. <span class="photo-modal-close">&times;</span>
  104. <img id="photo-modal-img" src="" alt="照片">
  105. </div>
  106. <script>
  107. let currentPage = 1;
  108. let currentKeyword = '';
  109. function loadMonitorReport() {
  110. fetch('/api/monitor')
  111. .then(r => r.json())
  112. .then(data => {
  113. document.getElementById('monitor-report').innerHTML = `
  114. <div class="metric">
  115. <span class="metric-label">createBill成功率</span>
  116. <span class="metric-value ${data.createbill_success_rate >= 90 ? 'success' : data.createbill_success_rate >= 70 ? 'warning' : 'error'}">${data.createbill_success_rate.toFixed(1)}%</span>
  117. </div>
  118. <div class="metric">
  119. <span class="metric-label">createBill总调用</span>
  120. <span class="metric-value">${data.createbill_total} / 成功 ${data.createbill_success}</span>
  121. </div>
  122. <div class="metric">
  123. <span class="metric-label">照片平均耗时</span>
  124. <span class="metric-value">${data.avg_upload_time}ms</span>
  125. </div>
  126. <div class="metric">
  127. <span class="metric-label">TIME_WINDOW命中</span>
  128. <span class="metric-value">${data.time_window_hits}</span>
  129. </div>
  130. <div class="metric">
  131. <span class="metric-label">进站缓存命中率</span>
  132. <span class="metric-value">${data.in_cache_hit_rate.toFixed(1)}%</span>
  133. </div>
  134. <div class="metric">
  135. <span class="metric-label">出站缓存命中率</span>
  136. <span class="metric-value">${data.out_cache_hit_rate.toFixed(1)}%</span>
  137. </div>
  138. <div class="metric">
  139. <span class="metric-label">进站统计</span>
  140. <span class="metric-value">${data.in_station_count}</span>
  141. </div>
  142. <div class="metric">
  143. <span class="metric-label">出站统计</span>
  144. <span class="metric-value">${data.out_station_count}</span>
  145. </div>
  146. <div class="metric">
  147. <span class="metric-label">总记录数</span>
  148. <span class="metric-value">${data.total_records}</span>
  149. </div>
  150. <div class="metric">
  151. <span class="metric-label">失败记录</span>
  152. <span class="metric-value ${data.failed_records > 0 ? 'error' : ''}">${data.failed_records}</span>
  153. </div>
  154. <div class="metric">
  155. <span class="metric-label">飞书成功数</span>
  156. <span class="metric-value">${data.feishu_success_count}</span>
  157. </div>
  158. <div class="metric">
  159. <span class="metric-label">系统运行时间</span>
  160. <span class="metric-value">${data.uptime}</span>
  161. </div>
  162. <div class="metric">
  163. <span class="metric-label">网络超时</span>
  164. <span class="metric-value ${data.network_timeouts > 10 ? 'warning' : ''}">${data.network_timeouts}</span>
  165. </div>
  166. <div class="metric">
  167. <span class="metric-label">服务器错误</span>
  168. <span class="metric-value ${data.server_errors > 5 ? 'warning' : ''}">${data.server_errors}</span>
  169. </div>
  170. <div class="metric">
  171. <span class="metric-label">总上传错误</span>
  172. <span class="metric-value ${data.upload_errors > 0 ? 'error' : ''}">${data.upload_errors}</span>
  173. </div>
  174. <div class="metric">
  175. <span class="metric-label">交替锁定</span>
  176. <span class="metric-value ${data.alternating_merge_enabled ? 'success' : ''}">${data.alternating_merge_enabled ? '启用' : '禁用'}</span>
  177. </div>
  178. <div class="metric">
  179. <span class="metric-label">紧急告警抑制</span>
  180. <span class="metric-value ${data.emergency_alert_suppressed ? 'warning' : 'success'}">${data.emergency_alert_suppressed ? '已抑制' : '正常'}</span>
  181. </div>
  182. <div class="metric">
  183. <span class="metric-label">交替锁定间隔</span>
  184. <span class="metric-value">${data.in_out_interval_sec}秒</span>
  185. </div>
  186. `;
  187. })
  188. .catch(e => console.error('监控报告加载失败:', e));
  189. }
  190. function loadMessages(page, keyword) {
  191. let url = '/api/messages?page=' + page;
  192. if (keyword) url += '&keyword=' + encodeURIComponent(keyword);
  193. fetch(url)
  194. .then(r => r.json())
  195. .then(data => {
  196. let html = '';
  197. if (data.records.length === 0) {
  198. html = '<tr><td colspan="10" style="text-align:center;padding:30px;color:#999;">暂无数据</td></tr>';
  199. } else {
  200. data.records.forEach(rec => {
  201. const stationType = rec.station_type === 1 ? '进站' : '出站';
  202. const uploadStatus = rec.lo_upload_status === 1 && rec.hi_upload_status === 1 ? '成功' : '失败';
  203. const uploadClass = rec.lo_upload_status === 1 && rec.hi_upload_status === 1 ? 'status-success' : 'status-failed';
  204. const feishuClass = rec.feishu_status === 1 ? 'status-success' : rec.feishu_status === 2 ? 'status-failed' : 'status-pending';
  205. const feishuText = rec.feishu_status === 1 ? '已发送' : rec.feishu_status === 2 ? '失败' : '未发送';
  206. const retryDisabled = rec.retry_count >= 5 ? 'disabled' : '';
  207. html += '<tr>';
  208. html += '<td>' + rec.id + '</td>';
  209. html += '<td>' + rec.create_time + '</td>';
  210. html += '<td><b>' + rec.plate_number + '</b></td>';
  211. html += '<td style="font-family:monospace;">' + rec.tb_num.substring(0, 22) + '</td>';
  212. html += '<td>' + stationType + '</td>';
  213. html += '<td>' + (rec.lo_photo_path ? '<img class="photo-thumb" src="/photo?path=' + encodeURIComponent(rec.lo_photo_path) + '" onclick="showPhoto(this.src)">' : '-') + '</td>';
  214. html += '<td>' + (rec.hi_photo_path ? '<img class="photo-thumb" src="/photo?path=' + encodeURIComponent(rec.hi_photo_path) + '" onclick="showPhoto(this.src)">' : '-') + '</td>';
  215. html += '<td><span class="status ' + uploadClass + '">' + uploadStatus + '</span></td>';
  216. html += '<td><span class="status ' + feishuClass + '">' + feishuText + '</span></td>';
  217. html += '<td><button class="btn-retry" onclick="retryRecord(' + rec.id + ')" ' + retryDisabled + '>重试(' + rec.retry_count + '/5)</button></td>';
  218. html += '</tr>';
  219. });
  220. }
  221. document.getElementById('messages-body').innerHTML = html;
  222. // 分页
  223. let pageHtml = '<button onclick="searchMessages(' + (data.page - 1) + ')" ' + (data.page <= 1 ? 'disabled' : '') + '>上一页</button>';
  224. pageHtml += '<span class="info">第 ' + data.page + ' 页</span>';
  225. pageHtml += '<button onclick="searchMessages(' + (data.page + 1) + ')">下一页</button>';
  226. document.getElementById('pagination').innerHTML = pageHtml;
  227. })
  228. .catch(e => {
  229. console.error('消息列表加载失败:', e);
  230. document.getElementById('messages-body').innerHTML = '<tr><td colspan="10" style="text-align:center;color:#f5222d;">加载失败,请刷新页面</td></tr>';
  231. });
  232. }
  233. function searchMessages(page) {
  234. currentPage = page;
  235. currentKeyword = document.getElementById('search-input').value;
  236. loadMessages(currentPage, currentKeyword);
  237. }
  238. function retryRecord(id) {
  239. if (!confirm('确定要重试此记录吗?')) return;
  240. var btn = event.target;
  241. btn.disabled = true;
  242. btn.textContent = '重试中...';
  243. fetch('/api/retry', {
  244. method: 'POST',
  245. body: 'id=' + id,
  246. headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
  247. })
  248. .then(r => r.json())
  249. .then(data => {
  250. btn.disabled = false;
  251. btn.textContent = '重试';
  252. if (data.success) {
  253. var msg = '✅ 重试成功';
  254. if (data.tb_num) msg += '\n联单编号: ' + data.tb_num;
  255. if (data.uploaded_photos > 0) msg += '\n上传照片: ' + data.uploaded_photos + '张';
  256. alert(msg);
  257. } else {
  258. alert('❌ 重试失败: ' + (data.message || '未知错误'));
  259. }
  260. loadMessages(currentPage, currentKeyword);
  261. loadMonitorReport();
  262. })
  263. .catch(e => {
  264. btn.disabled = false;
  265. btn.textContent = '重试';
  266. alert('重试请求失败: ' + e);
  267. });
  268. }
  269. function showPhoto(src) {
  270. document.getElementById('photo-modal-img').src = src;
  271. document.getElementById('photo-modal').classList.add('active');
  272. }
  273. function closePhotoModal() {
  274. document.getElementById('photo-modal').classList.remove('active');
  275. }
  276. // 初始化
  277. loadMonitorReport();
  278. loadMessages(1, '');
  279. // 自动刷新
  280. setInterval(() => {
  281. loadMonitorReport();
  282. if (currentPage === 1 && !currentKeyword) {
  283. loadMessages(1, '');
  284. }
  285. }, 30000);
  286. // 回车搜索
  287. document.getElementById('search-input').addEventListener('keypress', e => {
  288. if (e.key === 'Enter') searchMessages(1);
  289. });
  290. </script>
  291. </body>
  292. </html>