diff --git a/frontend/assets/styles.css b/frontend/assets/styles.css
index b533644..965e799 100644
--- a/frontend/assets/styles.css
+++ b/frontend/assets/styles.css
@@ -533,3 +533,46 @@ input[type="date"]::-webkit-calendar-picker-indicator:hover{
background-repeat: no-repeat;
background-position: center;
}
+
+/* Table styles */
+.table {
+ width: 100%;
+ border-collapse: collapse;
+ background: var(--surface);
+ border-radius: 8px;
+ overflow: hidden;
+}
+
+.table thead {
+ background: var(--border);
+}
+
+.table th {
+ padding: 12px;
+ text-align: left;
+ font-weight: 600;
+ color: var(--text);
+ border-bottom: 2px solid var(--border);
+}
+
+.table td {
+ padding: 12px;
+ border-bottom: 1px solid var(--border);
+ color: var(--text);
+}
+
+.table tbody tr:hover {
+ background: var(--hover);
+}
+
+.table tbody tr:last-child td {
+ border-bottom: none;
+}
+
+@media(max-width: 768px) {
+ .table th,
+ .table td {
+ padding: 8px;
+ font-size: 14px;
+ }
+}
diff --git a/frontend/index.html b/frontend/index.html
index 372af0e..4394b2b 100644
--- a/frontend/index.html
+++ b/frontend/index.html
@@ -52,10 +52,23 @@
扩展采集
@@ -159,6 +172,7 @@
+
diff --git a/frontend/js/router.js b/frontend/js/router.js
index b503201..ac9f7dc 100644
--- a/frontend/js/router.js
+++ b/frontend/js/router.js
@@ -83,8 +83,9 @@ const Router = (() => {
stats: '良/不良统计',
defects: '不良明细',
repairs: '返修记录',
- shipments: '发货记录',
- query: '查询',
+ shipments: '发货',
+ query: '详细记录查询',
+ summary: '汇总信息查询',
devices: '设备状态',
environment: '环境参数',
personnel: '人员信息',
diff --git a/server/app.py b/server/app.py
index 11fd82f..519af9e 100644
--- a/server/app.py
+++ b/server/app.py
@@ -1542,11 +1542,25 @@ def clear_module():
table = tables.get(module)
if not table:
return jsonify({'error': 'invalid module'}), 400
+
+ # 清空 SQLite 表
conn = get_db()
c = conn.cursor()
c.execute(f'DELETE FROM {table}')
conn.commit()
conn.close()
+
+ # 如果是清空发货记录,同时清空 Redis
+ if module == 'shipments':
+ try:
+ r = get_redis()
+ redis_key = 'shipment_sn_mapping'
+ redis_count = r.hlen(redis_key)
+ r.delete(redis_key)
+ log('clear_module_redis', f'shipments: cleared {redis_count} records from redis')
+ except Exception as e:
+ log('clear_module_redis_error', str(e))
+
log('clear_module', module)
return jsonify({'ok': True})
@@ -1999,27 +2013,71 @@ def shipments_redis_stats():
return jsonify({'error': f'获取统计失败:{str(e)}'}), 500
+@app.get('/api/shipments/summary')
+@require_login
+def shipments_summary():
+ """查询发货记录汇总信息(按日期范围)"""
+ try:
+ start_date = request.args.get('start')
+ end_date = request.args.get('end')
+
+ if not start_date or not end_date:
+ return jsonify({'error': '请提供开始和结束日期'}), 400
+
+ conn = get_db()
+ c = conn.cursor()
+
+ # 查询指定日期范围内的发货记录
+ c.execute('''
+ SELECT date, qty, receiver, ts
+ FROM shipments
+ WHERE date >= ? AND date <= ?
+ ORDER BY date DESC
+ ''', (start_date, end_date))
+
+ rows = [dict(r) for r in c.fetchall()]
+ conn.close()
+
+ log('shipments_summary', f'start={start_date}, end={end_date}, count={len(rows)}')
+
+ return jsonify({
+ 'ok': True,
+ 'records': rows,
+ 'count': len(rows)
+ })
+ except Exception as e:
+ log('shipments_summary_error', str(e))
+ return jsonify({'error': f'查询失败:{str(e)}'}), 500
+
+
@app.post('/api/shipments/clear-redis')
@require_login
@require_any_role('admin','superadmin')
def clear_shipments_redis():
- """清空 Redis 中的发货记录数据"""
+ """清空 Redis 和 SQLite 中的发货记录数据"""
try:
+ # 清空 Redis
r = get_redis()
redis_key = 'shipment_sn_mapping'
-
- # 获取删除前的数量
- count_before = r.hlen(redis_key)
-
- # 删除整个 Hash
+ redis_count = r.hlen(redis_key)
r.delete(redis_key)
- log('clear_shipments_redis', f'cleared {count_before} records')
+ # 同时清空 SQLite 中的 shipments 表
+ conn = get_db()
+ c = conn.cursor()
+ c.execute('SELECT COUNT(*) as cnt FROM shipments')
+ sqlite_count = c.fetchone()['cnt']
+ c.execute('DELETE FROM shipments')
+ conn.commit()
+ conn.close()
+
+ log('clear_shipments_all', f'cleared redis={redis_count}, sqlite={sqlite_count}')
return jsonify({
'ok': True,
- 'message': f'已清空 {count_before} 条发货记录',
- 'count': count_before
+ 'message': f'已清空 Redis {redis_count} 条记录和 SQLite {sqlite_count} 条记录',
+ 'redis_count': redis_count,
+ 'sqlite_count': sqlite_count
})
except Exception as e:
log('clear_shipments_redis_error', str(e))