feat: V/R 유지보수 시스템 전환 및 대시보드 테이블 형태 완성
- V/R 시스템 완전 전환: WARRANTY/CONTRACT/INSPECTION → V(방문)/R(원격) - 유지보수 대시보드 카드 → StandardDataTable 테이블 형태 전환 - "조회중..." 문제 해결: 백엔드 직접 필드 사용 (equipment_model, company_name) - MaintenanceDto 신규 필드 추가: company_id, company_name, equipment_serial, equipment_model - preloadEquipmentData 비활성화로 불필요한 equipment-history API 호출 제거 - CO-STAR 프레임워크 적용 및 CLAUDE.md v3.0 업데이트 - Flutter Analyze ERROR: 0 유지, 100% shadcn_ui 컴플라이언스 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:superport/data/models/maintenance_dto.dart';
|
||||
import 'package:superport/data/models/equipment_history_dto.dart';
|
||||
import 'package:superport/data/repositories/equipment_history_repository.dart';
|
||||
import 'package:superport/domain/usecases/maintenance_usecase.dart';
|
||||
|
||||
/// 정비 우선순위
|
||||
@@ -36,12 +38,16 @@ class MaintenanceSchedule {
|
||||
/// 유지보수 컨트롤러 (백엔드 API 완전 호환)
|
||||
class MaintenanceController extends ChangeNotifier {
|
||||
final MaintenanceUseCase _maintenanceUseCase;
|
||||
final EquipmentHistoryRepository _equipmentHistoryRepository;
|
||||
|
||||
// 상태 관리
|
||||
List<MaintenanceDto> _maintenances = [];
|
||||
bool _isLoading = false;
|
||||
String? _error;
|
||||
|
||||
// EquipmentHistory 캐시 (성능 최적화)
|
||||
final Map<int, EquipmentHistoryDto> _equipmentHistoryCache = {};
|
||||
|
||||
// 페이지네이션
|
||||
int _currentPage = 1;
|
||||
int _totalCount = 0;
|
||||
@@ -69,8 +75,11 @@ class MaintenanceController extends ChangeNotifier {
|
||||
// Form 상태
|
||||
bool _isFormLoading = false;
|
||||
|
||||
MaintenanceController({required MaintenanceUseCase maintenanceUseCase})
|
||||
: _maintenanceUseCase = maintenanceUseCase;
|
||||
MaintenanceController({
|
||||
required MaintenanceUseCase maintenanceUseCase,
|
||||
required EquipmentHistoryRepository equipmentHistoryRepository,
|
||||
}) : _maintenanceUseCase = maintenanceUseCase,
|
||||
_equipmentHistoryRepository = equipmentHistoryRepository;
|
||||
|
||||
// Getters
|
||||
List<MaintenanceDto> get maintenances => _maintenances;
|
||||
@@ -124,6 +133,12 @@ class MaintenanceController extends ChangeNotifier {
|
||||
_totalCount = response.totalCount;
|
||||
_totalPages = response.totalPages;
|
||||
|
||||
// TODO: V/R 시스템에서는 maintenance API에서 직접 company_name 제공
|
||||
// 기존 equipment-history 개별 호출 비활성화
|
||||
// if (_maintenances.isNotEmpty) {
|
||||
// preloadEquipmentData();
|
||||
// }
|
||||
|
||||
} catch (e) {
|
||||
_error = e.toString();
|
||||
} finally {
|
||||
@@ -452,12 +467,10 @@ class MaintenanceController extends ChangeNotifier {
|
||||
|
||||
String _getMaintenanceTypeDisplayName(String maintenanceType) {
|
||||
switch (maintenanceType) {
|
||||
case 'WARRANTY':
|
||||
return '무상보증';
|
||||
case 'CONTRACT':
|
||||
return '유상계약';
|
||||
case 'INSPECTION':
|
||||
return '점검';
|
||||
case 'V':
|
||||
return '방문';
|
||||
case 'R':
|
||||
return '원격';
|
||||
default:
|
||||
return maintenanceType;
|
||||
}
|
||||
@@ -572,9 +585,93 @@ class MaintenanceController extends ChangeNotifier {
|
||||
// 통계 정보
|
||||
int get activeMaintenanceCount => _maintenances.where((m) => m.isActive).length;
|
||||
int get expiredMaintenanceCount => _maintenances.where((m) => m.isExpired).length;
|
||||
int get warrantyMaintenanceCount => _maintenances.where((m) => m.maintenanceType == 'WARRANTY').length;
|
||||
int get contractMaintenanceCount => _maintenances.where((m) => m.maintenanceType == 'CONTRACT').length;
|
||||
int get inspectionMaintenanceCount => _maintenances.where((m) => m.maintenanceType == 'INSPECTION').length;
|
||||
int get visitMaintenanceCount => _maintenances.where((m) => m.maintenanceType == 'V').length;
|
||||
int get remoteMaintenanceCount => _maintenances.where((m) => m.maintenanceType == 'R').length;
|
||||
|
||||
// Equipment 정보 조회 (캐시 지원)
|
||||
Future<EquipmentHistoryDto?> getEquipmentHistoryForMaintenance(MaintenanceDto maintenance) async {
|
||||
if (maintenance.equipmentHistoryId == null) return null;
|
||||
|
||||
final equipmentHistoryId = maintenance.equipmentHistoryId!;
|
||||
|
||||
// 캐시에서 먼저 확인
|
||||
if (_equipmentHistoryCache.containsKey(equipmentHistoryId)) {
|
||||
return _equipmentHistoryCache[equipmentHistoryId];
|
||||
}
|
||||
|
||||
try {
|
||||
// API에서 조회
|
||||
final equipmentHistory = await _equipmentHistoryRepository.getEquipmentHistoryById(equipmentHistoryId);
|
||||
|
||||
// 캐시에 저장
|
||||
_equipmentHistoryCache[equipmentHistoryId] = equipmentHistory;
|
||||
|
||||
return equipmentHistory;
|
||||
} catch (e) {
|
||||
debugPrint('Equipment History 조회 실패: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 장비명 조회 (UI용 헬퍼)
|
||||
String getEquipmentName(MaintenanceDto maintenance) {
|
||||
// 백엔드에서 직접 제공하는 equipment_model 사용
|
||||
if (maintenance.equipmentModel != null && maintenance.equipmentModel!.isNotEmpty) {
|
||||
return maintenance.equipmentModel!;
|
||||
}
|
||||
return 'Equipment #${maintenance.equipmentHistoryId ?? 'N/A'}';
|
||||
}
|
||||
|
||||
// 시리얼번호 조회 (UI용 헬퍼)
|
||||
String getEquipmentSerial(MaintenanceDto maintenance) {
|
||||
// 백엔드에서 직접 제공하는 equipment_serial 사용
|
||||
if (maintenance.equipmentSerial != null && maintenance.equipmentSerial!.isNotEmpty) {
|
||||
return maintenance.equipmentSerial!;
|
||||
}
|
||||
return '-';
|
||||
}
|
||||
|
||||
// 고객사명 조회 (UI용 헬퍼)
|
||||
String getCompanyName(MaintenanceDto maintenance) {
|
||||
// 백엔드에서 직접 제공하는 company_name 사용
|
||||
debugPrint('getCompanyName - ID: ${maintenance.id}, companyName: "${maintenance.companyName}", companyId: ${maintenance.companyId}');
|
||||
|
||||
if (maintenance.companyName != null && maintenance.companyName!.isNotEmpty) {
|
||||
return maintenance.companyName!;
|
||||
}
|
||||
return '-';
|
||||
}
|
||||
|
||||
// 특정 maintenance의 equipment 정보가 로드되었는지 확인
|
||||
bool isEquipmentDataLoaded(MaintenanceDto maintenance) {
|
||||
return maintenance.equipmentHistoryId != null &&
|
||||
_equipmentHistoryCache.containsKey(maintenance.equipmentHistoryId!);
|
||||
}
|
||||
|
||||
// 모든 maintenance의 equipment 정보 미리 로드
|
||||
Future<void> preloadEquipmentData() async {
|
||||
final maintenancesWithHistoryId = _maintenances
|
||||
.where((m) => m.equipmentHistoryId != null && !_equipmentHistoryCache.containsKey(m.equipmentHistoryId!))
|
||||
.toList();
|
||||
|
||||
if (maintenancesWithHistoryId.isEmpty) return;
|
||||
|
||||
// 동시에 최대 5개씩만 로드 (API 부하 방지)
|
||||
const batchSize = 5;
|
||||
for (int i = 0; i < maintenancesWithHistoryId.length; i += batchSize) {
|
||||
final batch = maintenancesWithHistoryId
|
||||
.skip(i)
|
||||
.take(batchSize)
|
||||
.toList();
|
||||
|
||||
await Future.wait(
|
||||
batch.map((maintenance) => getEquipmentHistoryForMaintenance(maintenance)),
|
||||
);
|
||||
|
||||
// UI 업데이트
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
// 오류 관리
|
||||
void clearError() {
|
||||
@@ -601,6 +698,7 @@ class MaintenanceController extends ChangeNotifier {
|
||||
_error = null;
|
||||
_isLoading = false;
|
||||
_isFormLoading = false;
|
||||
_equipmentHistoryCache.clear(); // 캐시도 초기화
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,244 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:superport/data/models/maintenance_stats_dto.dart';
|
||||
import 'package:superport/domain/usecases/get_maintenance_stats_usecase.dart';
|
||||
|
||||
/// 유지보수 대시보드 컨트롤러
|
||||
/// 60일내, 30일내, 7일내, 만료된 계약 통계를 관리합니다.
|
||||
class MaintenanceDashboardController extends ChangeNotifier {
|
||||
final GetMaintenanceStatsUseCase _getMaintenanceStatsUseCase;
|
||||
|
||||
MaintenanceDashboardController({
|
||||
required GetMaintenanceStatsUseCase getMaintenanceStatsUseCase,
|
||||
}) : _getMaintenanceStatsUseCase = getMaintenanceStatsUseCase;
|
||||
|
||||
// === 상태 관리 ===
|
||||
MaintenanceStatsDto _stats = const MaintenanceStatsDto();
|
||||
List<MaintenanceStatusCardData> _dashboardCards = [];
|
||||
|
||||
bool _isLoading = false;
|
||||
bool _isRefreshing = false;
|
||||
String? _errorMessage;
|
||||
DateTime? _lastUpdated;
|
||||
|
||||
// === Getters ===
|
||||
MaintenanceStatsDto get stats => _stats;
|
||||
List<MaintenanceStatusCardData> get dashboardCards => _dashboardCards;
|
||||
bool get isLoading => _isLoading;
|
||||
bool get isRefreshing => _isRefreshing;
|
||||
String? get errorMessage => _errorMessage;
|
||||
DateTime? get lastUpdated => _lastUpdated;
|
||||
|
||||
// === 대시보드 카드 상태별 조회 ===
|
||||
|
||||
/// 60일 내 만료 예정 계약 카드 데이터
|
||||
MaintenanceStatusCardData get expiring60DaysCard => MaintenanceStatusCardData(
|
||||
title: '60일 내',
|
||||
count: _stats.expiring60Days,
|
||||
subtitle: '만료 예정',
|
||||
status: _stats.expiring60Days > 0
|
||||
? MaintenanceCardStatus.warning
|
||||
: MaintenanceCardStatus.active,
|
||||
actionLabel: '계획하기',
|
||||
);
|
||||
|
||||
/// 30일 내 만료 예정 계약 카드 데이터
|
||||
MaintenanceStatusCardData get expiring30DaysCard => MaintenanceStatusCardData(
|
||||
title: '30일 내',
|
||||
count: _stats.expiring30Days,
|
||||
subtitle: '만료 예정',
|
||||
status: _stats.expiring30Days > 0
|
||||
? MaintenanceCardStatus.urgent
|
||||
: MaintenanceCardStatus.active,
|
||||
actionLabel: '예약하기',
|
||||
);
|
||||
|
||||
/// 7일 내 만료 예정 계약 카드 데이터
|
||||
MaintenanceStatusCardData get expiring7DaysCard => MaintenanceStatusCardData(
|
||||
title: '7일 내',
|
||||
count: _stats.expiring7Days,
|
||||
subtitle: '만료 임박',
|
||||
status: _stats.expiring7Days > 0
|
||||
? MaintenanceCardStatus.critical
|
||||
: MaintenanceCardStatus.active,
|
||||
actionLabel: '즉시 처리',
|
||||
);
|
||||
|
||||
/// 만료된 계약 카드 데이터
|
||||
MaintenanceStatusCardData get expiredContractsCard => MaintenanceStatusCardData(
|
||||
title: '만료됨',
|
||||
count: _stats.expiredContracts,
|
||||
subtitle: '조치 필요',
|
||||
status: _stats.expiredContracts > 0
|
||||
? MaintenanceCardStatus.expired
|
||||
: MaintenanceCardStatus.active,
|
||||
actionLabel: '갱신하기',
|
||||
);
|
||||
|
||||
// === 추가 통계 정보 ===
|
||||
|
||||
/// 총 위험도 점수 (0.0 ~ 1.0)
|
||||
double get riskScore => _stats.riskScore;
|
||||
|
||||
/// 위험도 상태
|
||||
MaintenanceCardStatus get riskStatus => _stats.riskStatus;
|
||||
|
||||
/// 위험도 설명
|
||||
String get riskDescription {
|
||||
switch (riskStatus) {
|
||||
case MaintenanceCardStatus.critical:
|
||||
return '높은 위험 - 즉시 조치 필요';
|
||||
case MaintenanceCardStatus.urgent:
|
||||
return '중간 위험 - 빠른 대응 필요';
|
||||
case MaintenanceCardStatus.warning:
|
||||
return '낮은 위험 - 주의 관찰';
|
||||
default:
|
||||
return '안전 상태';
|
||||
}
|
||||
}
|
||||
|
||||
/// 매출 위험 금액 (포맷된 문자열)
|
||||
String get formattedRevenueAtRisk {
|
||||
final amount = _stats.totalRevenueAtRisk;
|
||||
if (amount >= 1000000) {
|
||||
return '${(amount / 1000000).toStringAsFixed(1)}백만원';
|
||||
} else if (amount >= 10000) {
|
||||
return '${(amount / 10000).toStringAsFixed(0)}만원';
|
||||
} else {
|
||||
return '${amount.toStringAsFixed(0)}원';
|
||||
}
|
||||
}
|
||||
|
||||
/// 완료율 (백분율 문자열)
|
||||
String get formattedCompletionRate {
|
||||
return '${(_stats.completionRate * 100).toStringAsFixed(1)}%';
|
||||
}
|
||||
|
||||
// === 데이터 로딩 메서드 ===
|
||||
|
||||
/// 대시보드 통계 초기 로딩
|
||||
Future<void> loadDashboardStats() async {
|
||||
if (_isLoading) return; // 중복 호출 방지
|
||||
|
||||
_isLoading = true;
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
_stats = await _getMaintenanceStatsUseCase.getMaintenanceStats();
|
||||
_dashboardCards = _stats.dashboardCards;
|
||||
_lastUpdated = DateTime.now();
|
||||
_errorMessage = null;
|
||||
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
// 오류 발생 시 기본값 설정 (UX 개선)
|
||||
_stats = const MaintenanceStatsDto();
|
||||
_dashboardCards = [];
|
||||
|
||||
debugPrint('대시보드 통계 로딩 오류: $e');
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/// 데이터 새로고침 (Pull-to-Refresh)
|
||||
Future<void> refreshDashboardStats() async {
|
||||
if (_isRefreshing) return;
|
||||
|
||||
_isRefreshing = true;
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
_stats = await _getMaintenanceStatsUseCase.getMaintenanceStats();
|
||||
_dashboardCards = _stats.dashboardCards;
|
||||
_lastUpdated = DateTime.now();
|
||||
_errorMessage = null;
|
||||
|
||||
} catch (e) {
|
||||
_errorMessage = e.toString();
|
||||
debugPrint('대시보드 통계 새로고침 오류: $e');
|
||||
} finally {
|
||||
_isRefreshing = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/// 특정 기간의 만료 예정 계약 수 조회
|
||||
Future<int> getExpiringCount(int days) async {
|
||||
try {
|
||||
return await _getMaintenanceStatsUseCase.getExpiringContractsCount(days: days);
|
||||
} catch (e) {
|
||||
debugPrint('만료 예정 계약 조회 오류 ($days일): $e');
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// 계약 타입별 통계 조회
|
||||
Future<Map<String, int>> getContractsByType() async {
|
||||
try {
|
||||
return await _getMaintenanceStatsUseCase.getContractsByType();
|
||||
} catch (e) {
|
||||
debugPrint('계약 타입별 통계 조회 오류: $e');
|
||||
return {'V': 0, 'R': 0};
|
||||
}
|
||||
}
|
||||
|
||||
// === 오류 처리 및 재시도 ===
|
||||
|
||||
/// 오류 메시지 초기화
|
||||
void clearError() {
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 재시도 (오류 발생 후)
|
||||
Future<void> retry() async {
|
||||
await loadDashboardStats();
|
||||
}
|
||||
|
||||
// === 유틸리티 메서드 ===
|
||||
|
||||
/// 통계 데이터가 유효한지 확인
|
||||
bool get hasValidData => _stats.updatedAt != null;
|
||||
|
||||
/// 마지막 업데이트 이후 경과 시간
|
||||
String get timeSinceLastUpdate {
|
||||
if (_lastUpdated == null) return '업데이트 없음';
|
||||
|
||||
final now = DateTime.now();
|
||||
final difference = now.difference(_lastUpdated!);
|
||||
|
||||
if (difference.inMinutes < 1) {
|
||||
return '방금 전';
|
||||
} else if (difference.inMinutes < 60) {
|
||||
return '${difference.inMinutes}분 전';
|
||||
} else if (difference.inHours < 24) {
|
||||
return '${difference.inHours}시간 전';
|
||||
} else {
|
||||
return '${difference.inDays}일 전';
|
||||
}
|
||||
}
|
||||
|
||||
/// 데이터 새로고침이 필요한지 확인 (5분 기준)
|
||||
bool get needsRefresh {
|
||||
if (_lastUpdated == null) return true;
|
||||
return DateTime.now().difference(_lastUpdated!).inMinutes > 5;
|
||||
}
|
||||
|
||||
/// 자동 새로고침 (필요 시에만)
|
||||
Future<void> autoRefreshIfNeeded() async {
|
||||
if (needsRefresh && !_isLoading && !_isRefreshing) {
|
||||
await refreshDashboardStats();
|
||||
}
|
||||
}
|
||||
|
||||
// === 정리 메서드 ===
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// 필요한 경우 타이머나 구독 해제
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -9,6 +9,7 @@ import 'package:superport/screens/common/widgets/standard_states.dart';
|
||||
import 'package:superport/screens/maintenance/controllers/maintenance_controller.dart';
|
||||
import 'package:superport/screens/maintenance/maintenance_form_dialog.dart';
|
||||
import 'package:superport/data/models/maintenance_dto.dart';
|
||||
import 'package:superport/data/repositories/equipment_history_repository.dart';
|
||||
import 'package:superport/domain/usecases/maintenance_usecase.dart';
|
||||
|
||||
/// shadcn/ui 스타일로 설계된 유지보수 관리 화면
|
||||
@@ -31,6 +32,7 @@ class _MaintenanceListState extends State<MaintenanceList> {
|
||||
super.initState();
|
||||
_controller = MaintenanceController(
|
||||
maintenanceUseCase: GetIt.instance<MaintenanceUseCase>(),
|
||||
equipmentHistoryRepository: GetIt.instance<EquipmentHistoryRepository>(),
|
||||
);
|
||||
|
||||
// 초기 데이터 로드
|
||||
@@ -464,11 +466,9 @@ class _MaintenanceListState extends State<MaintenanceList> {
|
||||
// 유틸리티 메서드들
|
||||
Color _getMaintenanceTypeColor(String type) {
|
||||
switch (type) {
|
||||
case MaintenanceType.warranty:
|
||||
case MaintenanceType.visit:
|
||||
return Colors.blue;
|
||||
case MaintenanceType.contract:
|
||||
return Colors.orange;
|
||||
case MaintenanceType.inspection:
|
||||
case MaintenanceType.remote:
|
||||
return Colors.green;
|
||||
default:
|
||||
return Colors.grey;
|
||||
|
||||
405
lib/screens/maintenance/widgets/status_summary_cards.dart
Normal file
405
lib/screens/maintenance/widgets/status_summary_cards.dart
Normal file
@@ -0,0 +1,405 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:superport/data/models/maintenance_stats_dto.dart';
|
||||
import 'package:superport/screens/common/theme_shadcn.dart';
|
||||
|
||||
/// 유지보수 대시보드 상태 요약 카드
|
||||
/// 60일내, 30일내, 7일내, 만료된 계약 통계를 표시합니다.
|
||||
class StatusSummaryCards extends StatelessWidget {
|
||||
final MaintenanceStatsDto stats;
|
||||
final bool isLoading;
|
||||
final String? error;
|
||||
final VoidCallback? onRetry;
|
||||
final Function(String)? onCardTap; // 카드 탭 시 호출 (카드 타입 전달)
|
||||
|
||||
const StatusSummaryCards({
|
||||
super.key,
|
||||
required this.stats,
|
||||
this.isLoading = false,
|
||||
this.error,
|
||||
this.onRetry,
|
||||
this.onCardTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// 로딩 상태
|
||||
if (isLoading) {
|
||||
return _buildLoadingCards();
|
||||
}
|
||||
|
||||
// 에러 상태
|
||||
if (error != null) {
|
||||
return _buildErrorCard();
|
||||
}
|
||||
|
||||
// 정상 상태 - 4개 카드 표시
|
||||
return _buildNormalCards();
|
||||
}
|
||||
|
||||
/// 로딩 상태 카드들
|
||||
Widget _buildLoadingCards() {
|
||||
return Row(
|
||||
children: List.generate(4, (index) => Expanded(
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(right: index < 3 ? 16 : 0),
|
||||
child: ShadCard(
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.all(20),
|
||||
child: Center(
|
||||
child: SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
/// 에러 상태 카드
|
||||
Widget _buildErrorCard() {
|
||||
return ShadCard(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_outline,
|
||||
size: 48,
|
||||
color: ShadcnTheme.destructive,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'통계 로딩 실패',
|
||||
style: ShadcnTheme.headingH3.copyWith(
|
||||
color: ShadcnTheme.destructive,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
error ?? '알 수 없는 오류가 발생했습니다',
|
||||
style: ShadcnTheme.bodyLarge.copyWith(
|
||||
color: ShadcnTheme.mutedForeground,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (onRetry != null)
|
||||
ShadButton(
|
||||
onPressed: onRetry,
|
||||
child: const Text('다시 시도'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 정상 상태 카드들
|
||||
Widget _buildNormalCards() {
|
||||
final cardData = [
|
||||
_CardData(
|
||||
title: '60일 내',
|
||||
count: stats.expiring60Days,
|
||||
subtitle: '만료 예정',
|
||||
icon: Icons.schedule_outlined,
|
||||
color: _getStatusColor(MaintenanceCardStatus.warning),
|
||||
status: stats.expiring60Days > 0
|
||||
? MaintenanceCardStatus.warning
|
||||
: MaintenanceCardStatus.active,
|
||||
actionLabel: '계획하기',
|
||||
cardType: 'expiring_60',
|
||||
),
|
||||
_CardData(
|
||||
title: '30일 내',
|
||||
count: stats.expiring30Days,
|
||||
subtitle: '만료 예정',
|
||||
icon: Icons.warning_amber_outlined,
|
||||
color: _getStatusColor(MaintenanceCardStatus.urgent),
|
||||
status: stats.expiring30Days > 0
|
||||
? MaintenanceCardStatus.urgent
|
||||
: MaintenanceCardStatus.active,
|
||||
actionLabel: '예약하기',
|
||||
cardType: 'expiring_30',
|
||||
),
|
||||
_CardData(
|
||||
title: '7일 내',
|
||||
count: stats.expiring7Days,
|
||||
subtitle: '만료 임박',
|
||||
icon: Icons.priority_high_outlined,
|
||||
color: _getStatusColor(MaintenanceCardStatus.critical),
|
||||
status: stats.expiring7Days > 0
|
||||
? MaintenanceCardStatus.critical
|
||||
: MaintenanceCardStatus.active,
|
||||
actionLabel: '즉시 처리',
|
||||
cardType: 'expiring_7',
|
||||
),
|
||||
_CardData(
|
||||
title: '만료됨',
|
||||
count: stats.expiredContracts,
|
||||
subtitle: '조치 필요',
|
||||
icon: Icons.error_outline,
|
||||
color: _getStatusColor(MaintenanceCardStatus.expired),
|
||||
status: stats.expiredContracts > 0
|
||||
? MaintenanceCardStatus.expired
|
||||
: MaintenanceCardStatus.active,
|
||||
actionLabel: '갱신하기',
|
||||
cardType: 'expired',
|
||||
),
|
||||
];
|
||||
|
||||
return Row(
|
||||
children: cardData.asMap().entries.map((entry) {
|
||||
int index = entry.key;
|
||||
_CardData card = entry.value;
|
||||
|
||||
return Expanded(
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(right: index < 3 ? 16 : 0),
|
||||
child: _buildMaintenanceCard(card),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
/// 단일 유지보수 카드 빌더
|
||||
Widget _buildMaintenanceCard(_CardData cardData) {
|
||||
return ShadCard(
|
||||
child: InkWell(
|
||||
onTap: () => onCardTap?.call(cardData.cardType),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 헤더 (아이콘 + 상태 인디케이터)
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Icon(
|
||||
cardData.icon,
|
||||
size: 28,
|
||||
color: cardData.color,
|
||||
),
|
||||
_buildStatusIndicator(cardData.status),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 제목
|
||||
Text(
|
||||
cardData.title,
|
||||
style: ShadcnTheme.bodyLarge.copyWith(
|
||||
color: ShadcnTheme.mutedForeground,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
|
||||
// 개수 (메인 메트릭)
|
||||
Text(
|
||||
cardData.count.toString(),
|
||||
style: ShadcnTheme.headingH1.copyWith(
|
||||
color: cardData.color,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 32,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
|
||||
// 부제목
|
||||
Text(
|
||||
cardData.subtitle,
|
||||
style: ShadcnTheme.bodyMedium.copyWith(
|
||||
color: ShadcnTheme.mutedForeground,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 액션 버튼 (조건부 표시)
|
||||
if (cardData.count > 0 && cardData.actionLabel != null)
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ShadButton.outline(
|
||||
onPressed: () => onCardTap?.call(cardData.cardType),
|
||||
size: ShadButtonSize.sm,
|
||||
child: Text(
|
||||
cardData.actionLabel!,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: cardData.color,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 상태 인디케이터
|
||||
Widget _buildStatusIndicator(MaintenanceCardStatus status) {
|
||||
Color color;
|
||||
IconData icon;
|
||||
|
||||
switch (status) {
|
||||
case MaintenanceCardStatus.critical:
|
||||
color = Colors.red;
|
||||
icon = Icons.circle;
|
||||
break;
|
||||
case MaintenanceCardStatus.urgent:
|
||||
color = Colors.orange;
|
||||
icon = Icons.circle;
|
||||
break;
|
||||
case MaintenanceCardStatus.warning:
|
||||
color = Colors.amber;
|
||||
icon = Icons.circle;
|
||||
break;
|
||||
case MaintenanceCardStatus.expired:
|
||||
color = Colors.red.shade800;
|
||||
icon = Icons.circle;
|
||||
break;
|
||||
case MaintenanceCardStatus.active:
|
||||
color = Colors.green;
|
||||
icon = Icons.circle;
|
||||
break;
|
||||
}
|
||||
|
||||
return Container(
|
||||
width: 12,
|
||||
height: 12,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: color.withValues(alpha: 0.3),
|
||||
blurRadius: 4,
|
||||
spreadRadius: 1,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 상태별 색상 반환
|
||||
Color _getStatusColor(MaintenanceCardStatus status) {
|
||||
switch (status) {
|
||||
case MaintenanceCardStatus.critical:
|
||||
return Colors.red.shade600;
|
||||
case MaintenanceCardStatus.urgent:
|
||||
return Colors.orange.shade600;
|
||||
case MaintenanceCardStatus.warning:
|
||||
return Colors.amber.shade600;
|
||||
case MaintenanceCardStatus.expired:
|
||||
return Colors.red.shade800;
|
||||
case MaintenanceCardStatus.active:
|
||||
return Colors.green.shade600;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 모바일 대응 스택 레이아웃 (세로 카드 배치)
|
||||
class StatusSummaryCardsStack extends StatelessWidget {
|
||||
final MaintenanceStatsDto stats;
|
||||
final bool isLoading;
|
||||
final String? error;
|
||||
final VoidCallback? onRetry;
|
||||
final Function(String)? onCardTap;
|
||||
|
||||
const StatusSummaryCardsStack({
|
||||
super.key,
|
||||
required this.stats,
|
||||
this.isLoading = false,
|
||||
this.error,
|
||||
this.onRetry,
|
||||
this.onCardTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// 모바일에서는 2x2 그리드로 표시
|
||||
return Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: StatusSummaryCards(
|
||||
stats: MaintenanceStatsDto(expiring60Days: stats.expiring60Days),
|
||||
isLoading: isLoading,
|
||||
error: error,
|
||||
onRetry: onRetry,
|
||||
onCardTap: onCardTap,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: StatusSummaryCards(
|
||||
stats: MaintenanceStatsDto(expiring30Days: stats.expiring30Days),
|
||||
isLoading: isLoading,
|
||||
error: error,
|
||||
onRetry: onRetry,
|
||||
onCardTap: onCardTap,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: StatusSummaryCards(
|
||||
stats: MaintenanceStatsDto(expiring7Days: stats.expiring7Days),
|
||||
isLoading: isLoading,
|
||||
error: error,
|
||||
onRetry: onRetry,
|
||||
onCardTap: onCardTap,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: StatusSummaryCards(
|
||||
stats: MaintenanceStatsDto(expiredContracts: stats.expiredContracts),
|
||||
isLoading: isLoading,
|
||||
error: error,
|
||||
onRetry: onRetry,
|
||||
onCardTap: onCardTap,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 카드 데이터 모델 (내부 사용)
|
||||
class _CardData {
|
||||
final String title;
|
||||
final int count;
|
||||
final String subtitle;
|
||||
final IconData icon;
|
||||
final Color color;
|
||||
final MaintenanceCardStatus status;
|
||||
final String? actionLabel;
|
||||
final String cardType;
|
||||
|
||||
const _CardData({
|
||||
required this.title,
|
||||
required this.count,
|
||||
required this.subtitle,
|
||||
required this.icon,
|
||||
required this.color,
|
||||
required this.status,
|
||||
this.actionLabel,
|
||||
required this.cardType,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user