feat: 自动提交 - 周二 2025/09/23 15:32:55.51

This commit is contained in:
赵杰
2025-09-23 15:32:55 +01:00
parent 6b0c03439f
commit 63600d1bc2
5 changed files with 1313 additions and 31 deletions

View File

@@ -287,14 +287,47 @@ class QueryOptimizer:
status_counts = Counter([wo.status for wo in workorders])
category_counts = Counter([wo.category for wo in workorders])
priority_counts = Counter([wo.priority for wo in workorders])
resolved_count = status_counts.get('resolved', 0)
# 调试信息
logger.info(f"工单状态统计: {dict(status_counts)}")
logger.info(f"工单总数: {total}")
# 处理状态映射(支持中英文状态)
status_mapping = {
'open': ['open', '待处理', '新建', 'new'],
'in_progress': ['in_progress', '处理中', '进行中', 'progress', 'processing'],
'resolved': ['resolved', '已解决', '已完成'],
'closed': ['closed', '已关闭', '关闭']
}
# 统计各状态的数量
mapped_counts = {'open': 0, 'in_progress': 0, 'resolved': 0, 'closed': 0}
for status, count in status_counts.items():
if status is None:
continue
status_lower = str(status).lower()
mapped = False
for mapped_status, possible_values in status_mapping.items():
if status_lower in [v.lower() for v in possible_values]:
mapped_counts[mapped_status] += count
mapped = True
break
if not mapped:
logger.warning(f"未映射的状态: '{status}' (数量: {count})")
# 调试信息
logger.info(f"映射后的状态统计: {mapped_counts}")
resolved_count = mapped_counts['resolved']
workorders_stats = {
'total': total,
'open': status_counts.get('open', 0),
'in_progress': status_counts.get('in_progress', 0),
'resolved': resolved_count,
'closed': status_counts.get('closed', 0),
'open': mapped_counts['open'],
'in_progress': mapped_counts['in_progress'],
'resolved': mapped_counts['resolved'],
'closed': mapped_counts['closed'],
'by_category': dict(category_counts),
'by_priority': dict(priority_counts)
}

View File

@@ -190,6 +190,133 @@ def get_analytics() -> Dict[str, Any]:
return jsonify(analytics)
@core_bp.route('/workorders/by-status/<status>')
@handle_api_errors
def get_workorders_by_status(status: str) -> Dict[str, Any]:
"""根据状态获取工单列表"""
try:
with db_manager.get_session() as session:
# 状态映射
status_mapping = {
'open': ['open', '待处理', '新建', 'new'],
'in_progress': ['in_progress', '处理中', '进行中', 'progress', 'processing'],
'resolved': ['resolved', '已解决', '已完成'],
'closed': ['closed', '已关闭', '关闭']
}
# 处理特殊状态
if status == 'all':
# 查询所有工单
workorders = session.query(WorkOrder).order_by(WorkOrder.created_at.desc()).limit(50).all()
else:
# 查找匹配的状态值
actual_statuses = []
for mapped_status, possible_values in status_mapping.items():
if mapped_status == status:
actual_statuses = possible_values
break
if not actual_statuses:
return create_error_response(f"无效的状态: {status}")
# 查询工单
workorders = session.query(WorkOrder).filter(
WorkOrder.status.in_(actual_statuses)
).order_by(WorkOrder.created_at.desc()).limit(50).all()
result = []
for wo in workorders:
result.append({
"id": wo.id,
"order_id": wo.order_id,
"title": wo.title,
"description": wo.description,
"category": wo.category,
"priority": wo.priority,
"status": wo.status,
"created_at": wo.created_at.isoformat() if wo.created_at else None,
"updated_at": wo.updated_at.isoformat() if wo.updated_at else None,
"resolution": wo.resolution,
"satisfaction_score": wo.satisfaction_score
})
return create_success_response({
"workorders": result,
"count": len(result),
"status": status
})
except Exception as e:
return create_error_response(f"获取工单失败: {str(e)}")
@core_bp.route('/alerts/by-level/<level>')
@handle_api_errors
def get_alerts_by_level(level: str) -> Dict[str, Any]:
"""根据级别获取预警列表"""
try:
with db_manager.get_session() as session:
alerts = session.query(Alert).filter(
Alert.level == level,
Alert.is_active == True
).order_by(Alert.created_at.desc()).limit(50).all()
result = []
for alert in alerts:
result.append({
"id": alert.id,
"message": alert.message,
"level": alert.level,
"alert_type": alert.alert_type,
"created_at": alert.created_at.isoformat() if alert.created_at else None,
"is_active": alert.is_active
})
return create_success_response({
"alerts": result,
"count": len(result),
"level": level
})
except Exception as e:
return create_error_response(f"获取预警失败: {str(e)}")
@core_bp.route('/knowledge/by-status/<status>')
@handle_api_errors
def get_knowledge_by_status(status: str) -> Dict[str, Any]:
"""根据验证状态获取知识库条目"""
try:
with db_manager.get_session() as session:
from src.core.models import KnowledgeEntry
is_verified = status == 'verified'
knowledge_entries = session.query(KnowledgeEntry).filter(
KnowledgeEntry.is_verified == is_verified
).order_by(KnowledgeEntry.created_at.desc()).limit(50).all()
result = []
for entry in knowledge_entries:
result.append({
"id": entry.id,
"title": entry.title,
"content": entry.content,
"category": entry.category,
"is_verified": entry.is_verified,
"created_at": entry.created_at.isoformat() if entry.created_at else None,
"updated_at": entry.updated_at.isoformat() if entry.updated_at else None
})
return create_success_response({
"knowledge": result,
"count": len(result),
"status": status
})
except Exception as e:
return create_error_response(f"获取知识库条目失败: {str(e)}")
@core_bp.route('/batch-delete/workorders', methods=['POST'])
@handle_api_errors
def batch_delete_workorders() -> Dict[str, Any]:

View File

@@ -11,6 +11,256 @@ body {
color: var(--text-primary);
}
/* ===== 图标和按钮优化样式 ===== */
/* 操作按钮组优化 */
.btn-group .btn {
position: relative;
transition: all 0.2s ease;
}
.btn-group .btn:hover {
transform: translateY(-1px);
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
/* 小尺寸按钮优化 */
.btn-sm {
padding: 0.375rem 0.5rem;
font-size: 0.75rem;
border-radius: 0.375rem;
min-width: 2rem;
height: 2rem;
display: inline-flex;
align-items: center;
justify-content: center;
}
/* 操作按钮图标优化 */
.btn-sm i {
font-size: 0.875rem;
line-height: 1;
}
/* 按钮组间距优化 */
.btn-group .btn:not(:last-child) {
margin-right: 0.25rem;
}
/* 表格操作按钮优化 */
.table .btn-group {
white-space: nowrap;
}
.table .btn-group .btn {
margin: 0 0.125rem;
}
/* 悬停效果优化 */
.btn-outline-info:hover {
background-color: #0dcaf0;
border-color: #0dcaf0;
color: white;
}
.btn-outline-primary:hover {
background-color: #0d6efd;
border-color: #0d6efd;
color: white;
}
.btn-outline-danger:hover {
background-color: #dc3545;
border-color: #dc3545;
color: white;
}
.btn-outline-success:hover {
background-color: #198754;
border-color: #198754;
color: white;
}
.btn-outline-warning:hover {
background-color: #ffc107;
border-color: #ffc107;
color: #000;
}
/* 工具提示优化 */
.btn[title] {
position: relative;
}
.btn[title]:hover::after {
content: attr(title);
position: absolute;
bottom: 100%;
left: 50%;
transform: translateX(-50%);
background-color: rgba(0,0,0,0.8);
color: white;
padding: 0.25rem 0.5rem;
border-radius: 0.25rem;
font-size: 0.75rem;
white-space: nowrap;
z-index: 1000;
margin-bottom: 0.25rem;
}
/* 快速操作按钮优化 */
.quick-action-btn {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border: none;
color: white;
padding: 0.5rem 1rem;
border-radius: 0.5rem;
font-size: 0.875rem;
transition: all 0.3s ease;
margin: 0.25rem;
cursor: pointer;
}
.quick-action-btn:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}
/* 批量操作按钮优化 */
.btn-group .btn-sm {
font-weight: 500;
}
.btn-group .btn-sm i {
margin-right: 0.25rem;
}
/* 空状态图标优化 */
.empty-state i {
font-size: 3rem;
color: #6c757d;
margin-bottom: 1rem;
opacity: 0.5;
}
/* 状态指示器优化 */
.health-dot {
width: 12px;
height: 12px;
border-radius: 50%;
background-color: #ffc107;
animation: pulse 2s infinite;
}
@keyframes pulse {
0% { opacity: 1; }
50% { opacity: 0.5; }
100% { opacity: 1; }
}
.health-dot.normal {
background-color: #28a745;
}
.health-dot.warning {
background-color: #ffc107;
}
.health-dot.error {
background-color: #dc3545;
}
/* 加载动画优化 */
.loading-spinner i {
animation: spin 1s linear infinite;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
/* 可点击统计数字样式 */
.clickable-stat {
transition: all 0.2s ease;
border-radius: 0.375rem;
padding: 0.25rem 0.5rem;
margin: -0.25rem -0.5rem;
}
.clickable-stat:hover {
background-color: rgba(255, 255, 255, 0.1);
transform: scale(1.05);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.clickable-stat:active {
transform: scale(0.95);
}
/* 预览模态框优化 */
.modal-xl {
max-width: 90vw;
}
.modal-xl .modal-body {
max-height: 70vh;
overflow-y: auto;
}
/* 表格预览优化 */
.table-responsive {
border-radius: 0.5rem;
overflow: hidden;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.table-hover tbody tr:hover {
background-color: rgba(0, 123, 255, 0.05);
}
/* 空状态样式 */
.empty-state {
padding: 3rem 1rem;
text-align: center;
color: #6c757d;
}
.empty-state i {
font-size: 4rem;
margin-bottom: 1rem;
opacity: 0.3;
}
/* 响应式图标优化 */
@media (max-width: 768px) {
.btn-sm {
min-width: 1.75rem;
height: 1.75rem;
padding: 0.25rem 0.375rem;
}
.btn-sm i {
font-size: 0.75rem;
}
.btn-group .btn:not(:last-child) {
margin-right: 0.125rem;
}
.table .btn-group .btn {
margin: 0 0.0625rem;
}
.clickable-stat {
font-size: 1.5rem;
}
.modal-xl {
max-width: 95vw;
}
}
.navbar-brand {
font-size: var(--font-size-2xl);
font-weight: var(--font-weight-bold);

File diff suppressed because it is too large Load Diff

View File

@@ -805,7 +805,7 @@
<div class="card-body">
<div class="d-flex justify-content-between">
<div>
<h4 id="critical-alerts">0</h4>
<h4 id="critical-alerts" class="clickable-stat" data-type="alert" data-level="critical" style="cursor: pointer;">0</h4>
<p class="mb-0" data-i18n="alerts-critical">严重预警</p>
</div>
<div class="align-self-center">
@@ -820,7 +820,7 @@
<div class="card-body">
<div class="d-flex justify-content-between">
<div>
<h4 id="warning-alerts">0</h4>
<h4 id="warning-alerts" class="clickable-stat" data-type="alert" data-level="warning" style="cursor: pointer;">0</h4>
<p class="mb-0" data-i18n="alerts-warning">警告预警</p>
</div>
<div class="align-self-center">
@@ -835,7 +835,7 @@
<div class="card-body">
<div class="d-flex justify-content-between">
<div>
<h4 id="info-alerts">0</h4>
<h4 id="info-alerts" class="clickable-stat" data-type="alert" data-level="info" style="cursor: pointer;">0</h4>
<p class="mb-0" data-i18n="alerts-info">信息预警</p>
</div>
<div class="align-self-center">
@@ -1018,19 +1018,19 @@
<div class="card-body">
<div class="mb-3">
<small class="text-muted">总工单数</small>
<h4 id="workorders-total">0</h4>
<h4 id="workorders-total" class="clickable-stat" data-type="workorder" data-status="all" style="cursor: pointer; color: #0d6efd;">0</h4>
</div>
<div class="mb-3">
<small class="text-muted">待处理</small>
<h4 id="workorders-open">0</h4>
<h4 id="workorders-open" class="clickable-stat" data-type="workorder" data-status="open" style="cursor: pointer; color: #fd7e14;">0</h4>
</div>
<div class="mb-3">
<small class="text-muted">处理中</small>
<h4 id="workorders-progress">0</h4>
<h4 id="workorders-progress" class="clickable-stat" data-type="workorder" data-status="in_progress" style="cursor: pointer; color: #0dcaf0;">0</h4>
</div>
<div class="mb-3">
<small class="text-muted">已解决</small>
<h4 id="workorders-resolved">0</h4>
<h4 id="workorders-resolved" class="clickable-stat" data-type="workorder" data-status="resolved" style="cursor: pointer; color: #198754;">0</h4>
</div>
</div>
</div>
@@ -2472,6 +2472,6 @@
<!-- 脚本 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@3.9.1/dist/chart.min.js"></script>
<script src="{{ url_for('static', filename='js/dashboard.js') }}?v=1.0.7"></script>
<script src="{{ url_for('static', filename='js/dashboard.js') }}?v=1.0.9"></script>
</body>
</html>