index.bak3.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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-fix19</p>
  63. <style>.video-link:hover{background:rgba(255,255,255,0.35)!important;}</style>
  64. <div class="video-links" style="margin-top:12px;display:flex;justify-content:center;gap:10px;flex-wrap:wrap;">
  65. <a href="/video?stream=in-low" class="video-link" style="background:rgba(255,255,255,0.2);color:white;padding:8px 16px;border-radius:20px;text-decoration:none;font-size:14px;transition:background 0.2s;">🎥 低位进站</a>
  66. <a href="/video?stream=in-high" class="video-link" style="background:rgba(255,255,255,0.2);color:white;padding:8px 16px;border-radius:20px;text-decoration:none;font-size:14px;transition:background 0.2s;">🎥 高位进站</a>
  67. <a href="/video?stream=out-low" class="video-link" style="background:rgba(255,255,255,0.2);color:white;padding:8px 16px;border-radius:20px;text-decoration:none;font-size:14px;transition:background 0.2s;">🎥 低位出站</a>
  68. <a href="/video?stream=out-high" class="video-link" style="background:rgba(255,255,255,0.2);color:white;padding:8px 16px;border-radius:20px;text-decoration:none;font-size:14px;transition:background 0.2s;">🎥 高位出站</a>
  69. </div>
  70. </div>
  71. <div class="container">
  72. <div class="panel report-panel">
  73. <h2>监控报告</h2>
  74. <div id="monitor-report">
  75. <div class="loading">加载中...</div>
  76. </div>
  77. </div>
  78. <div class="panel list-panel">
  79. <h2>实时消息列表</h2>
  80. <div class="search-box">
  81. <input type="text" id="search-input" placeholder="搜索车牌号/联单编号/日期时间">
  82. <button onclick="searchMessages(1)">搜索</button>
  83. </div>
  84. <div class="table-container">
  85. <table>
  86. <thead>
  87. <tr>
  88. <th>编号</th>
  89. <th>日期时间</th>
  90. <th>车牌号</th>
  91. <th>联单编号</th>
  92. <th>类型</th>
  93. <th>低位照片</th>
  94. <th>高位照片</th>
  95. <th>上传状态</th>
  96. <th>飞书状态</th>
  97. <th>操作</th>
  98. </tr>
  99. </thead>
  100. <tbody id="messages-body">
  101. <tr><td colspan="10" class="loading">加载中...</td></tr>
  102. </tbody>
  103. </table>
  104. </div>
  105. <div class="pagination" id="pagination"></div>
  106. <div class="refresh-info">数据自动刷新间隔: 30秒</div>
  107. </div>
  108. </div>
  109. <div class="photo-modal" id="photo-modal" onclick="closePhotoModal()">
  110. <span class="photo-modal-close">&times;</span>
  111. <img id="photo-modal-img" src="" alt="照片">
  112. </div>
  113. <script>
  114. let currentPage = 1;
  115. let currentKeyword = '';
  116. function loadMonitorReport() {
  117. fetch('/api/monitor')
  118. .then(r => r.json())
  119. .then(data => {
  120. document.getElementById('monitor-report').innerHTML = `
  121. <div class="metric">
  122. <span class="metric-label">createBill成功率</span>
  123. <span class="metric-value ${data.createbill_success_rate >= 90 ? 'success' : data.createbill_success_rate >= 70 ? 'warning' : 'error'}">${data.createbill_success_rate.toFixed(1)}%</span>
  124. </div>
  125. <div class="metric">
  126. <span class="metric-label">createBill总调用</span>
  127. <span class="metric-value">${data.createbill_total} / 成功 ${data.createbill_success}</span>
  128. </div>
  129. <div class="metric">
  130. <span class="metric-label">照片平均耗时</span>
  131. <span class="metric-value">${data.avg_upload_time}ms</span>
  132. </div>
  133. <div class="metric">
  134. <span class="metric-label">TIME_WINDOW命中</span>
  135. <span class="metric-value">${data.time_window_hits}</span>
  136. </div>
  137. <div class="metric">
  138. <span class="metric-label">进站缓存命中率</span>
  139. <span class="metric-value">${data.in_cache_hit_rate.toFixed(1)}%</span>
  140. </div>
  141. <div class="metric">
  142. <span class="metric-label">出站缓存命中率</span>
  143. <span class="metric-value">${data.out_cache_hit_rate.toFixed(1)}%</span>
  144. </div>
  145. <div class="metric">
  146. <span class="metric-label">进站统计</span>
  147. <span class="metric-value">${data.in_station_count}</span>
  148. </div>
  149. <div class="metric">
  150. <span class="metric-label">出站统计</span>
  151. <span class="metric-value">${data.out_station_count}</span>
  152. </div>
  153. <div class="metric">
  154. <span class="metric-label">总记录数</span>
  155. <span class="metric-value">${data.total_records}</span>
  156. </div>
  157. <div class="metric">
  158. <span class="metric-label">失败记录</span>
  159. <span class="metric-value ${data.failed_records > 0 ? 'error' : ''}">${data.failed_records}</span>
  160. </div>
  161. <div class="metric">
  162. <span class="metric-label">飞书成功数</span>
  163. <span class="metric-value">${data.feishu_success_count}</span>
  164. </div>
  165. <div class="metric">
  166. <span class="metric-label">系统运行时间</span>
  167. <span class="metric-value">${data.uptime}</span>
  168. </div>
  169. <div class="metric">
  170. <span class="metric-label">网络超时</span>
  171. <span class="metric-value ${data.network_timeouts > 10 ? 'warning' : ''}">${data.network_timeouts}</span>
  172. </div>
  173. <div class="metric">
  174. <span class="metric-label">服务器错误</span>
  175. <span class="metric-value ${data.server_errors > 5 ? 'warning' : ''}">${data.server_errors}</span>
  176. </div>
  177. <div class="metric">
  178. <span class="metric-label">总上传错误</span>
  179. <span class="metric-value ${data.upload_errors > 0 ? 'error' : ''}">${data.upload_errors}</span>
  180. </div>
  181. <div class="metric">
  182. <span class="metric-label">交替锁定</span>
  183. <span class="metric-value ${data.alternating_merge_enabled ? 'success' : ''}">${data.alternating_merge_enabled ? '启用' : '禁用'}</span>
  184. </div>
  185. <div class="metric">
  186. <span class="metric-label">紧急告警抑制</span>
  187. <span class="metric-value ${data.emergency_alert_suppressed ? 'warning' : 'success'}">${data.emergency_alert_suppressed ? '已抑制' : '正常'}</span>
  188. </div>
  189. <div class="metric">
  190. <span class="metric-label">交替锁定间隔</span>
  191. <span class="metric-value">${data.in_out_interval_sec}秒</span>
  192. </div>
  193. `;
  194. })
  195. .catch(e => console.error('监控报告加载失败:', e));
  196. }
  197. function loadMessages(page, keyword) {
  198. let url = '/api/messages?page=' + page;
  199. if (keyword) url += '&keyword=' + encodeURIComponent(keyword);
  200. fetch(url)
  201. .then(r => r.json())
  202. .then(data => {
  203. let html = '';
  204. if (data.records.length === 0) {
  205. html = '<tr><td colspan="10" style="text-align:center;padding:30px;color:#999;">暂无数据</td></tr>';
  206. } else {
  207. data.records.forEach(rec => {
  208. const stationType = rec.station_type === 1 ? '进站' : '出站';
  209. const uploadStatus = rec.lo_upload_status === 1 && rec.hi_upload_status === 1 ? '成功' : '失败';
  210. const uploadClass = rec.lo_upload_status === 1 && rec.hi_upload_status === 1 ? 'status-success' : 'status-failed';
  211. const feishuClass = rec.feishu_status === 1 ? 'status-success' : rec.feishu_status === 2 ? 'status-failed' : 'status-pending';
  212. const feishuText = rec.feishu_status === 1 ? '已发送' : rec.feishu_status === 2 ? '失败' : '未发送';
  213. const retryDisabled = rec.retry_count >= 5 ? 'disabled' : '';
  214. html += '<tr>';
  215. html += '<td>' + rec.id + '</td>';
  216. html += '<td>' + rec.create_time + '</td>';
  217. html += '<td><b>' + rec.plate_number + '</b></td>';
  218. html += '<td style="font-family:monospace;">' + rec.tb_num.substring(0, 22) + '</td>';
  219. html += '<td>' + stationType + '</td>';
  220. html += '<td>' + (rec.lo_photo_path ? '<img class="photo-thumb" src="/photo?path=' + encodeURIComponent(rec.lo_photo_path) + '" onclick="showPhoto(this.src)">' : '-') + '</td>';
  221. html += '<td>' + (rec.hi_photo_path ? '<img class="photo-thumb" src="/photo?path=' + encodeURIComponent(rec.hi_photo_path) + '" onclick="showPhoto(this.src)">' : '-') + '</td>';
  222. html += '<td><span class="status ' + uploadClass + '">' + uploadStatus + '</span></td>';
  223. html += '<td><span class="status ' + feishuClass + '">' + feishuText + '</span></td>';
  224. html += '<td><button class="btn-retry" onclick="retryRecord(' + rec.id + ')" ' + retryDisabled + '>重试(' + rec.retry_count + '/5)</button></td>';
  225. html += '</tr>';
  226. });
  227. }
  228. document.getElementById('messages-body').innerHTML = html;
  229. // 分页
  230. let pageHtml = '<button onclick="searchMessages(' + (data.page - 1) + ')" ' + (data.page <= 1 ? 'disabled' : '') + '>上一页</button>';
  231. pageHtml += '<span class="info">第 ' + data.page + ' 页</span>';
  232. pageHtml += '<button onclick="searchMessages(' + (data.page + 1) + ')">下一页</button>';
  233. document.getElementById('pagination').innerHTML = pageHtml;
  234. })
  235. .catch(e => {
  236. console.error('消息列表加载失败:', e);
  237. document.getElementById('messages-body').innerHTML = '<tr><td colspan="10" style="text-align:center;color:#f5222d;">加载失败,请刷新页面</td></tr>';
  238. });
  239. }
  240. function searchMessages(page) {
  241. currentPage = page;
  242. currentKeyword = document.getElementById('search-input').value;
  243. loadMessages(currentPage, currentKeyword);
  244. }
  245. function retryRecord(id) {
  246. if (!confirm('确定要重试此记录吗?')) return;
  247. var btn = event.target;
  248. btn.disabled = true;
  249. btn.textContent = '重试中...';
  250. fetch('/api/retry', {
  251. method: 'POST',
  252. body: 'id=' + id,
  253. headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
  254. })
  255. .then(r => r.json())
  256. .then(data => {
  257. btn.disabled = false;
  258. btn.textContent = '重试';
  259. if (data.success) {
  260. var msg = '✅ 重试成功';
  261. if (data.tb_num) msg += '\n联单编号: ' + data.tb_num;
  262. if (data.uploaded_photos > 0) msg += '\n上传照片: ' + data.uploaded_photos + '张';
  263. alert(msg);
  264. } else {
  265. alert('❌ 重试失败: ' + (data.message || '未知错误'));
  266. }
  267. loadMessages(currentPage, currentKeyword);
  268. loadMonitorReport();
  269. })
  270. .catch(e => {
  271. btn.disabled = false;
  272. btn.textContent = '重试';
  273. alert('重试请求失败: ' + e);
  274. });
  275. }
  276. function showPhoto(src) {
  277. document.getElementById('photo-modal-img').src = src;
  278. document.getElementById('photo-modal').classList.add('active');
  279. }
  280. function closePhotoModal() {
  281. document.getElementById('photo-modal').classList.remove('active');
  282. }
  283. // 初始化
  284. loadMonitorReport();
  285. loadMessages(1, '');
  286. // 自动刷新
  287. setInterval(() => {
  288. loadMonitorReport();
  289. if (currentPage === 1 && !currentKeyword) {
  290. loadMessages(1, '');
  291. }
  292. }, 30000);
  293. // 回车搜索
  294. document.getElementById('search-input').addEventListener('keypress', e => {
  295. if (e.key === 'Enter') searchMessages(1);
  296. });
  297. </script>
  298. </body>
  299. </html>