backup: 사용하지 않는 파일 삭제 전 복구 지점
- 전체 371개 파일 중 82개 미사용 파일 식별 - Phase 1: 33개 파일 삭제 예정 (100% 안전) - Phase 2: 30개 파일 삭제 검토 예정 - Phase 3: 19개 파일 수동 검토 예정 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,13 +1,43 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../data/models/maintenance_dto.dart';
|
||||
import '../../../domain/usecases/maintenance_usecase.dart';
|
||||
import '../../../utils/constants.dart';
|
||||
import 'package:superport/data/models/maintenance_dto.dart';
|
||||
import 'package:superport/domain/usecases/maintenance_usecase.dart';
|
||||
|
||||
/// 유지보수 컨트롤러 (백엔드 실제 스키마 기반)
|
||||
/// 정비 우선순위
|
||||
enum MaintenancePriority { low, medium, high }
|
||||
|
||||
/// 정비 스케줄 상태
|
||||
enum MaintenanceScheduleStatus {
|
||||
scheduled,
|
||||
inProgress,
|
||||
completed,
|
||||
overdue,
|
||||
cancelled
|
||||
}
|
||||
|
||||
/// 정비 스케줄 모델 (UI 전용)
|
||||
class MaintenanceSchedule {
|
||||
final String id;
|
||||
final String title;
|
||||
final DateTime date;
|
||||
final MaintenancePriority priority;
|
||||
final MaintenanceScheduleStatus status;
|
||||
final String description;
|
||||
|
||||
MaintenanceSchedule({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.date,
|
||||
required this.priority,
|
||||
required this.status,
|
||||
required this.description,
|
||||
});
|
||||
}
|
||||
|
||||
/// 유지보수 컨트롤러 (백엔드 API 완전 호환)
|
||||
class MaintenanceController extends ChangeNotifier {
|
||||
final MaintenanceUseCase _maintenanceUseCase;
|
||||
|
||||
// 상태 관리 (단순화)
|
||||
// 상태 관리
|
||||
List<MaintenanceDto> _maintenances = [];
|
||||
bool _isLoading = false;
|
||||
String? _error;
|
||||
@@ -15,28 +45,55 @@ class MaintenanceController extends ChangeNotifier {
|
||||
// 페이지네이션
|
||||
int _currentPage = 1;
|
||||
int _totalCount = 0;
|
||||
static const int _pageSize = PaginationConstants.defaultPageSize;
|
||||
int _totalPages = 0;
|
||||
static const int _perPage = 20;
|
||||
|
||||
// 필터 (백엔드 실제 필드만)
|
||||
// 필터 (백엔드 API와 일치)
|
||||
int? _equipmentId;
|
||||
String? _maintenanceType;
|
||||
int? _equipmentHistoryId;
|
||||
bool? _isExpired;
|
||||
int? _expiringDays;
|
||||
bool _includeDeleted = false;
|
||||
|
||||
// 검색 및 정렬
|
||||
String _searchQuery = '';
|
||||
String _sortField = 'startedAt';
|
||||
bool _sortAscending = false;
|
||||
|
||||
// 선택된 유지보수
|
||||
MaintenanceDto? _selectedMaintenance;
|
||||
|
||||
// Getters (단순화)
|
||||
List<MaintenanceDto> get maintenances => _maintenances;
|
||||
bool get isLoading => _isLoading;
|
||||
String? get error => _error;
|
||||
int get currentPage => _currentPage;
|
||||
int get totalPages => (_totalCount / _pageSize).ceil();
|
||||
int get totalCount => _totalCount;
|
||||
MaintenanceDto? get selectedMaintenance => _selectedMaintenance;
|
||||
// 만료 예정 유지보수
|
||||
List<MaintenanceDto> _expiringMaintenances = [];
|
||||
|
||||
// Form 상태
|
||||
bool _isFormLoading = false;
|
||||
|
||||
MaintenanceController({required MaintenanceUseCase maintenanceUseCase})
|
||||
: _maintenanceUseCase = maintenanceUseCase;
|
||||
|
||||
// Getters
|
||||
List<MaintenanceDto> get maintenances => _maintenances;
|
||||
bool get isLoading => _isLoading;
|
||||
bool get isFormLoading => _isFormLoading;
|
||||
String? get error => _error;
|
||||
int get currentPage => _currentPage;
|
||||
int get totalPages => _totalPages;
|
||||
int get totalCount => _totalCount;
|
||||
MaintenanceDto? get selectedMaintenance => _selectedMaintenance;
|
||||
List<MaintenanceDto> get expiringMaintenances => _expiringMaintenances;
|
||||
|
||||
// 유지보수 목록 로드 (백엔드 단순 구조)
|
||||
// Filter getters
|
||||
int? get equipmentId => _equipmentId;
|
||||
String? get maintenanceType => _maintenanceType;
|
||||
bool? get isExpired => _isExpired;
|
||||
int? get expiringDays => _expiringDays;
|
||||
bool get includeDeleted => _includeDeleted;
|
||||
String get searchQuery => _searchQuery;
|
||||
String get sortField => _sortField;
|
||||
bool get sortAscending => _sortAscending;
|
||||
|
||||
/// 유지보수 목록 로드
|
||||
Future<void> loadMaintenances({bool refresh = false}) async {
|
||||
if (refresh) {
|
||||
_currentPage = 1;
|
||||
@@ -50,22 +107,23 @@ class MaintenanceController extends ChangeNotifier {
|
||||
try {
|
||||
final response = await _maintenanceUseCase.getMaintenances(
|
||||
page: _currentPage,
|
||||
pageSize: _pageSize,
|
||||
equipmentHistoryId: _equipmentHistoryId,
|
||||
perPage: _perPage,
|
||||
equipmentId: _equipmentId,
|
||||
maintenanceType: _maintenanceType,
|
||||
isExpired: _isExpired,
|
||||
expiringDays: _expiringDays,
|
||||
includeDeleted: _includeDeleted,
|
||||
);
|
||||
|
||||
// response는 MaintenanceListResponse 타입
|
||||
final maintenanceResponse = response;
|
||||
if (refresh) {
|
||||
_maintenances = maintenanceResponse.items;
|
||||
_maintenances = response.items;
|
||||
} else {
|
||||
_maintenances.addAll(maintenanceResponse.items);
|
||||
_maintenances.addAll(response.items);
|
||||
}
|
||||
|
||||
_totalCount = maintenanceResponse.totalCount;
|
||||
_totalCount = response.totalCount;
|
||||
_totalPages = response.totalPages;
|
||||
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
_error = e.toString();
|
||||
} finally {
|
||||
@@ -73,70 +131,64 @@ class MaintenanceController extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
// 특정 장비 이력의 유지보수 로드
|
||||
Future<void> loadMaintenancesByEquipmentHistory(int equipmentHistoryId) async {
|
||||
_isLoading = true;
|
||||
_error = null;
|
||||
_equipmentHistoryId = equipmentHistoryId;
|
||||
notifyListeners();
|
||||
|
||||
|
||||
/// 유지보수 상세 조회
|
||||
Future<MaintenanceDto?> getMaintenanceDetail(int id) async {
|
||||
try {
|
||||
_maintenances = await _maintenanceUseCase.getMaintenancesByEquipmentHistory(
|
||||
equipmentHistoryId,
|
||||
);
|
||||
_isLoading = true;
|
||||
notifyListeners();
|
||||
|
||||
final maintenance = await _maintenanceUseCase.getMaintenanceDetail(id);
|
||||
_selectedMaintenance = maintenance;
|
||||
|
||||
return maintenance;
|
||||
} catch (e) {
|
||||
_error = e.toString();
|
||||
_error = '유지보수 상세 조회 실패: ${e.toString()}';
|
||||
return null;
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
// 간단한 통계 (백엔드 데이터 기반)
|
||||
int get totalMaintenances => _totalCount;
|
||||
int get activeMaintenances => _maintenances.where((m) => !(m.isDeleted ?? false)).length;
|
||||
int get completedMaintenances => _maintenances.where((m) => m.endedAt.isBefore(DateTime.now())).length;
|
||||
|
||||
// 유지보수 생성 (백엔드 실제 스키마)
|
||||
|
||||
/// 유지보수 생성
|
||||
Future<bool> createMaintenance({
|
||||
required int equipmentHistoryId,
|
||||
int? equipmentHistoryId,
|
||||
required DateTime startedAt,
|
||||
required DateTime endedAt,
|
||||
required int periodMonth,
|
||||
required String maintenanceType,
|
||||
}) async {
|
||||
_isLoading = true;
|
||||
_isFormLoading = true;
|
||||
_error = null;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
final maintenance = await _maintenanceUseCase.createMaintenance(
|
||||
MaintenanceRequestDto(
|
||||
equipmentHistoryId: equipmentHistoryId,
|
||||
startedAt: startedAt,
|
||||
endedAt: endedAt,
|
||||
periodMonth: periodMonth,
|
||||
maintenanceType: maintenanceType,
|
||||
),
|
||||
final request = MaintenanceRequestDto(
|
||||
equipmentHistoryId: equipmentHistoryId,
|
||||
startedAt: startedAt,
|
||||
endedAt: endedAt,
|
||||
periodMonth: periodMonth,
|
||||
maintenanceType: maintenanceType,
|
||||
);
|
||||
|
||||
_maintenances.insert(0, maintenance);
|
||||
final newMaintenance = await _maintenanceUseCase.createMaintenance(request);
|
||||
|
||||
// 리스트 업데이트
|
||||
_maintenances.insert(0, newMaintenance);
|
||||
_totalCount++;
|
||||
|
||||
notifyListeners();
|
||||
return true;
|
||||
} catch (e) {
|
||||
_error = '유지보수 등록 실패: ${e.toString()}';
|
||||
_error = '유지보수 생성 실패: ${e.toString()}';
|
||||
return false;
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
_isFormLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
// 유지보수 수정 (백엔드 실제 스키마)
|
||||
|
||||
/// 유지보수 수정
|
||||
Future<bool> updateMaintenance({
|
||||
required int id,
|
||||
DateTime? startedAt,
|
||||
@@ -144,312 +196,414 @@ class MaintenanceController extends ChangeNotifier {
|
||||
int? periodMonth,
|
||||
String? maintenanceType,
|
||||
}) async {
|
||||
_isLoading = true;
|
||||
_isFormLoading = true;
|
||||
_error = null;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
final updatedMaintenance = await _maintenanceUseCase.updateMaintenance(
|
||||
id,
|
||||
MaintenanceUpdateRequestDto(
|
||||
startedAt: startedAt,
|
||||
endedAt: endedAt,
|
||||
periodMonth: periodMonth,
|
||||
maintenanceType: maintenanceType,
|
||||
),
|
||||
final request = MaintenanceUpdateRequestDto(
|
||||
startedAt: startedAt,
|
||||
endedAt: endedAt,
|
||||
periodMonth: periodMonth,
|
||||
maintenanceType: maintenanceType,
|
||||
);
|
||||
|
||||
final updatedMaintenance = await _maintenanceUseCase.updateMaintenance(id, request);
|
||||
|
||||
// 리스트 업데이트
|
||||
final index = _maintenances.indexWhere((m) => m.id == id);
|
||||
if (index != -1) {
|
||||
_maintenances[index] = updatedMaintenance;
|
||||
}
|
||||
|
||||
// 선택된 항목 업데이트
|
||||
if (_selectedMaintenance != null && _selectedMaintenance!.id == id) {
|
||||
_selectedMaintenance = updatedMaintenance;
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
return true;
|
||||
} catch (e) {
|
||||
_error = '유지보수 수정 실패: ${e.toString()}';
|
||||
return false;
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
_isFormLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
// 유지보수 삭제 (백엔드 실제 구조)
|
||||
|
||||
/// 유지보수 삭제 (Soft Delete)
|
||||
Future<bool> deleteMaintenance(int id) async {
|
||||
_isLoading = true;
|
||||
_isFormLoading = true;
|
||||
_error = null;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
await _maintenanceUseCase.deleteMaintenance(id);
|
||||
|
||||
// 리스트에서 제거
|
||||
_maintenances.removeWhere((m) => m.id == id);
|
||||
_totalCount--;
|
||||
|
||||
// 선택된 항목 해제
|
||||
if (_selectedMaintenance != null && _selectedMaintenance!.id == id) {
|
||||
_selectedMaintenance = null;
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
return true;
|
||||
} catch (e) {
|
||||
_error = '유지보수 삭제 실패: ${e.toString()}';
|
||||
return false;
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
_isFormLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/// 만료 예정 유지보수 조회
|
||||
Future<void> loadExpiringMaintenances({int days = 30}) async {
|
||||
try {
|
||||
_expiringMaintenances = await _maintenanceUseCase.getExpiringMaintenances(days: days);
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
_error = '만료 예정 유지보수 조회 실패: ${e.toString()}';
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/// 특정 장비의 유지보수 조회
|
||||
Future<void> loadMaintenancesByEquipment(int equipmentId) async {
|
||||
_equipmentId = equipmentId;
|
||||
await loadMaintenances(refresh: true);
|
||||
}
|
||||
|
||||
/// 활성 유지보수만 조회
|
||||
Future<void> loadActiveMaintenances() async {
|
||||
_includeDeleted = false;
|
||||
await loadMaintenances(refresh: true);
|
||||
}
|
||||
|
||||
/// 만료된 유지보수 조회
|
||||
Future<void> loadExpiredMaintenances() async {
|
||||
_isExpired = true;
|
||||
await loadMaintenances(refresh: true);
|
||||
}
|
||||
|
||||
// 필터 설정 메서드들
|
||||
void setEquipmentFilter(int? equipmentId) {
|
||||
if (_equipmentId != equipmentId) {
|
||||
_equipmentId = equipmentId;
|
||||
loadMaintenances(refresh: true);
|
||||
}
|
||||
}
|
||||
|
||||
void setMaintenanceTypeFilter(String? maintenanceType) {
|
||||
if (_maintenanceType != maintenanceType) {
|
||||
_maintenanceType = maintenanceType;
|
||||
loadMaintenances(refresh: true);
|
||||
}
|
||||
}
|
||||
|
||||
void setExpiredFilter(bool? isExpired) {
|
||||
if (_isExpired != isExpired) {
|
||||
_isExpired = isExpired;
|
||||
loadMaintenances(refresh: true);
|
||||
}
|
||||
}
|
||||
|
||||
void setExpiringDaysFilter(int? days) {
|
||||
if (_expiringDays != days) {
|
||||
_expiringDays = days;
|
||||
loadMaintenances(refresh: true);
|
||||
}
|
||||
}
|
||||
|
||||
void setIncludeDeleted(bool includeDeleted) {
|
||||
if (_includeDeleted != includeDeleted) {
|
||||
_includeDeleted = includeDeleted;
|
||||
loadMaintenances(refresh: true);
|
||||
}
|
||||
}
|
||||
|
||||
/// 모든 필터 초기화
|
||||
void clearFilters() {
|
||||
_equipmentId = null;
|
||||
_maintenanceType = null;
|
||||
_isExpired = null;
|
||||
_expiringDays = null;
|
||||
_includeDeleted = false;
|
||||
_searchQuery = '';
|
||||
loadMaintenances(refresh: true);
|
||||
}
|
||||
|
||||
/// 검색어 설정
|
||||
void setSearchQuery(String query) {
|
||||
if (_searchQuery != query) {
|
||||
_searchQuery = query;
|
||||
// 검색어가 변경되면 0.5초 후에 검색 실행 (디바운스)
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
if (_searchQuery == query) {
|
||||
_filterMaintenancesBySearch();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// 상태 필터 설정
|
||||
void setMaintenanceFilter(String? status) {
|
||||
switch (status) {
|
||||
case 'active':
|
||||
_isExpired = false;
|
||||
break;
|
||||
case 'completed':
|
||||
case 'expired':
|
||||
_isExpired = true;
|
||||
break;
|
||||
case 'upcoming':
|
||||
_isExpired = false;
|
||||
break;
|
||||
default:
|
||||
_isExpired = null;
|
||||
break;
|
||||
}
|
||||
loadMaintenances(refresh: true);
|
||||
}
|
||||
|
||||
/// 정렬 설정
|
||||
void setSorting(String field, bool ascending) {
|
||||
if (_sortField != field || _sortAscending != ascending) {
|
||||
_sortField = field;
|
||||
_sortAscending = ascending;
|
||||
_sortMaintenances();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
// 유지보수 상세 조회
|
||||
Future<MaintenanceDto?> getMaintenanceDetail(int id) async {
|
||||
try {
|
||||
return await _maintenanceUseCase.getMaintenance(id);
|
||||
} catch (e) {
|
||||
_error = '유지보수 상세 조회 실패: ${e.toString()}';
|
||||
return null;
|
||||
/// 검색어로 유지보수 필터링 (로컬 필터링)
|
||||
void _filterMaintenancesBySearch() {
|
||||
if (_searchQuery.trim().isEmpty) {
|
||||
notifyListeners();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 유지보수 선택
|
||||
void selectMaintenance(MaintenanceDto? maintenance) {
|
||||
_selectedMaintenance = maintenance;
|
||||
|
||||
// 검색어가 있으면 로컬에서 필터링
|
||||
final query = _searchQuery.toLowerCase();
|
||||
// 여기서는 간단히 notifyListeners만 호출 (실제 필터링은 UI에서 수행)
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// 장비 이력별 유지보수 설정
|
||||
void setEquipmentHistoryFilter(int equipmentHistoryId) {
|
||||
_equipmentHistoryId = equipmentHistoryId;
|
||||
loadMaintenances(refresh: true);
|
||||
/// 유지보수 목록 정렬
|
||||
void _sortMaintenances() {
|
||||
_maintenances.sort((a, b) {
|
||||
int comparison = 0;
|
||||
|
||||
switch (_sortField) {
|
||||
case 'startedAt':
|
||||
comparison = a.startedAt.compareTo(b.startedAt);
|
||||
break;
|
||||
case 'endedAt':
|
||||
comparison = a.endedAt.compareTo(b.endedAt);
|
||||
break;
|
||||
case 'maintenanceType':
|
||||
comparison = a.maintenanceType.compareTo(b.maintenanceType);
|
||||
break;
|
||||
case 'periodMonth':
|
||||
comparison = a.periodMonth.compareTo(b.periodMonth);
|
||||
break;
|
||||
default:
|
||||
comparison = a.startedAt.compareTo(b.startedAt);
|
||||
}
|
||||
|
||||
return _sortAscending ? comparison : -comparison;
|
||||
});
|
||||
}
|
||||
|
||||
// 필터 설정
|
||||
void setMaintenanceType(String? type) {
|
||||
if (_maintenanceType != type) {
|
||||
_maintenanceType = type;
|
||||
loadMaintenances(refresh: true);
|
||||
/// 특정 날짜의 유지보수 스케줄 생성
|
||||
MaintenanceSchedule? getScheduleForMaintenance(DateTime date) {
|
||||
if (_maintenances.isEmpty) return null;
|
||||
|
||||
MaintenanceDto? maintenance;
|
||||
try {
|
||||
maintenance = _maintenances.firstWhere(
|
||||
(m) => m.startedAt.year == date.year &&
|
||||
m.startedAt.month == date.month &&
|
||||
m.startedAt.day == date.day,
|
||||
);
|
||||
} catch (e) {
|
||||
// 해당 날짜의 정비가 없으면 가장 가까운 정비를 찾거나 null 반환
|
||||
maintenance = _maintenances.isNotEmpty ? _maintenances.first : null;
|
||||
}
|
||||
|
||||
if (maintenance == null) return null;
|
||||
|
||||
return MaintenanceSchedule(
|
||||
id: maintenance.id.toString(),
|
||||
title: _getMaintenanceTitle(maintenance),
|
||||
date: maintenance.startedAt,
|
||||
priority: _getMaintenancePriority(maintenance),
|
||||
status: _getMaintenanceScheduleStatus(maintenance),
|
||||
description: _getMaintenanceDescription(maintenance),
|
||||
);
|
||||
}
|
||||
|
||||
String _getMaintenanceTitle(MaintenanceDto maintenance) {
|
||||
final typeDisplay = _getMaintenanceTypeDisplayName(maintenance.maintenanceType);
|
||||
return '$typeDisplay 정비';
|
||||
}
|
||||
|
||||
String _getMaintenanceTypeDisplayName(String maintenanceType) {
|
||||
switch (maintenanceType) {
|
||||
case 'WARRANTY':
|
||||
return '무상보증';
|
||||
case 'CONTRACT':
|
||||
return '유상계약';
|
||||
case 'INSPECTION':
|
||||
return '점검';
|
||||
default:
|
||||
return maintenanceType;
|
||||
}
|
||||
}
|
||||
|
||||
// 필터 초기화
|
||||
void clearFilters() {
|
||||
_maintenanceType = null;
|
||||
_equipmentHistoryId = null;
|
||||
loadMaintenances(refresh: true);
|
||||
MaintenancePriority _getMaintenancePriority(MaintenanceDto maintenance) {
|
||||
if (maintenance.isExpired) return MaintenancePriority.high;
|
||||
|
||||
final now = DateTime.now();
|
||||
final daysUntilStart = maintenance.startedAt.difference(now).inDays;
|
||||
|
||||
if (daysUntilStart <= 7) return MaintenancePriority.high;
|
||||
if (daysUntilStart <= 30) return MaintenancePriority.medium;
|
||||
return MaintenancePriority.low;
|
||||
}
|
||||
|
||||
// 페이지 변경
|
||||
MaintenanceScheduleStatus _getMaintenanceScheduleStatus(MaintenanceDto maintenance) {
|
||||
if (maintenance.isDeleted) return MaintenanceScheduleStatus.cancelled;
|
||||
if (maintenance.isExpired) return MaintenanceScheduleStatus.overdue;
|
||||
|
||||
final now = DateTime.now();
|
||||
if (maintenance.startedAt.isAfter(now)) return MaintenanceScheduleStatus.scheduled;
|
||||
if (maintenance.endedAt.isBefore(now)) return MaintenanceScheduleStatus.completed;
|
||||
return MaintenanceScheduleStatus.inProgress;
|
||||
}
|
||||
|
||||
String _getMaintenanceDescription(MaintenanceDto maintenance) {
|
||||
final status = getMaintenanceStatusText(maintenance);
|
||||
return '상태: $status\n주기: ${maintenance.periodMonth}개월';
|
||||
}
|
||||
|
||||
// 페이지네이션 메서드들
|
||||
void goToPage(int page) {
|
||||
if (page >= 1 && page <= totalPages) {
|
||||
if (page >= 1 && page <= _totalPages && page != _currentPage) {
|
||||
_currentPage = page;
|
||||
loadMaintenances();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void nextPage() {
|
||||
if (_currentPage < totalPages) {
|
||||
if (_currentPage < _totalPages) {
|
||||
_currentPage++;
|
||||
loadMaintenances();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void previousPage() {
|
||||
if (_currentPage > 1) {
|
||||
_currentPage--;
|
||||
loadMaintenances();
|
||||
}
|
||||
}
|
||||
|
||||
void goToFirstPage() {
|
||||
if (_currentPage != 1) {
|
||||
_currentPage = 1;
|
||||
loadMaintenances();
|
||||
}
|
||||
}
|
||||
|
||||
void goToLastPage() {
|
||||
if (_currentPage != _totalPages && _totalPages > 0) {
|
||||
_currentPage = _totalPages;
|
||||
loadMaintenances();
|
||||
}
|
||||
}
|
||||
|
||||
// 선택 관리
|
||||
void selectMaintenance(MaintenanceDto? maintenance) {
|
||||
_selectedMaintenance = maintenance;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// 유틸리티 메서드들
|
||||
String getMaintenanceStatusText(MaintenanceDto maintenance) {
|
||||
if (maintenance.isDeleted) return '삭제됨';
|
||||
if (maintenance.isExpired) return '만료됨';
|
||||
|
||||
final now = DateTime.now();
|
||||
if (maintenance.startedAt.isAfter(now)) return '예정';
|
||||
if (maintenance.endedAt.isBefore(now)) return '완료';
|
||||
return '진행중';
|
||||
}
|
||||
|
||||
Color getMaintenanceStatusColor(MaintenanceDto maintenance) {
|
||||
final status = getMaintenanceStatusText(maintenance);
|
||||
switch (status) {
|
||||
case '예정': return Colors.blue;
|
||||
case '진행중': return Colors.green;
|
||||
case '완료': return Colors.grey;
|
||||
case '만료됨': return Colors.red;
|
||||
case '삭제됨': return Colors.grey.withValues(alpha: 0.5);
|
||||
default: return Colors.black;
|
||||
}
|
||||
}
|
||||
|
||||
// Alert 시스템 (기존 화면 호환성)
|
||||
List<MaintenanceDto> get upcomingAlerts => _expiringMaintenances;
|
||||
List<MaintenanceDto> get overdueAlerts => _maintenances
|
||||
.where((m) => m.isExpired && m.isActive)
|
||||
.toList();
|
||||
|
||||
// 오류 초기화
|
||||
int get upcomingCount => upcomingAlerts.length;
|
||||
int get overdueCount => overdueAlerts.length;
|
||||
|
||||
/// Alert 데이터 로드 (기존 화면 호환성)
|
||||
Future<void> loadAlerts() async {
|
||||
await loadExpiringMaintenances();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// 통계 정보
|
||||
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;
|
||||
|
||||
// 오류 관리
|
||||
void clearError() {
|
||||
_error = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// 유지보수 상태 표시명 (UI 호환성)
|
||||
String getMaintenanceStatusDisplayName(String status) {
|
||||
switch (status.toLowerCase()) {
|
||||
case '예정':
|
||||
case 'scheduled':
|
||||
return '예정';
|
||||
case '진행중':
|
||||
case 'in_progress':
|
||||
return '진행중';
|
||||
case '완료':
|
||||
case 'completed':
|
||||
return '완료';
|
||||
case '취소':
|
||||
case 'cancelled':
|
||||
return '취소';
|
||||
default:
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
// 유지보수 상태 간단 판단 (백엔드 데이터 기반)
|
||||
String getMaintenanceStatus(MaintenanceDto maintenance) {
|
||||
final now = DateTime.now();
|
||||
|
||||
if (maintenance.isDeleted ?? false) return '취소';
|
||||
if (maintenance.startedAt.isAfter(now)) return '예정';
|
||||
if (maintenance.endedAt.isBefore(now)) return '완료';
|
||||
|
||||
return '진행중';
|
||||
}
|
||||
|
||||
// ================== 누락된 메서드들 추가 ==================
|
||||
|
||||
// 추가된 필드들
|
||||
List<MaintenanceDto> _upcomingAlerts = [];
|
||||
List<MaintenanceDto> _overdueAlerts = [];
|
||||
String _searchQuery = '';
|
||||
String _currentSortField = '';
|
||||
bool _isAscending = true;
|
||||
|
||||
// 추가 Getters
|
||||
List<MaintenanceDto> get upcomingAlerts => _upcomingAlerts;
|
||||
List<MaintenanceDto> get overdueAlerts => _overdueAlerts;
|
||||
int get upcomingCount => _upcomingAlerts.length;
|
||||
int get overdueCount => _overdueAlerts.length;
|
||||
|
||||
// ID로 유지보수 조회 (호환성)
|
||||
Future<MaintenanceDto?> getMaintenanceById(int id) async {
|
||||
return await getMaintenanceDetail(id);
|
||||
}
|
||||
|
||||
// 알람 로드 (백엔드 스키마 기반)
|
||||
Future<void> loadAlerts() async {
|
||||
_isLoading = true;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
final now = DateTime.now();
|
||||
|
||||
// 예정된 유지보수 (시작일이 미래인 것)
|
||||
_upcomingAlerts = _maintenances.where((maintenance) {
|
||||
return maintenance.startedAt.isAfter(now) &&
|
||||
!(maintenance.isDeleted ?? false);
|
||||
}).take(10).toList();
|
||||
|
||||
// 연체된 유지보수 (종료일이 과거이고 아직 완료되지 않은 것)
|
||||
_overdueAlerts = _maintenances.where((maintenance) {
|
||||
return maintenance.endedAt.isBefore(now) &&
|
||||
maintenance.startedAt.isBefore(now) &&
|
||||
!(maintenance.isDeleted ?? false);
|
||||
}).take(10).toList();
|
||||
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
_error = '알람 로드 실패: ${e.toString()}';
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 검색 쿼리 설정
|
||||
void setSearchQuery(String query) {
|
||||
if (_searchQuery != query) {
|
||||
_searchQuery = query;
|
||||
// TODO: 실제 검색 구현 시 백엔드 API 호출 필요
|
||||
loadMaintenances(refresh: true);
|
||||
}
|
||||
}
|
||||
|
||||
// 유지보수 필터 설정 (호환성)
|
||||
void setMaintenanceFilter(String? type) {
|
||||
setMaintenanceType(type);
|
||||
}
|
||||
|
||||
// 정렬 설정
|
||||
void setSorting(String field, bool ascending) {
|
||||
if (_currentSortField != field || _isAscending != ascending) {
|
||||
_currentSortField = field;
|
||||
_isAscending = ascending;
|
||||
|
||||
// 클라이언트 사이드 정렬 (백엔드 정렬 API가 없는 경우)
|
||||
_maintenances.sort((a, b) {
|
||||
dynamic valueA, valueB;
|
||||
|
||||
switch (field) {
|
||||
case 'startedAt':
|
||||
valueA = a.startedAt;
|
||||
valueB = b.startedAt;
|
||||
break;
|
||||
case 'endedAt':
|
||||
valueA = a.endedAt;
|
||||
valueB = b.endedAt;
|
||||
break;
|
||||
case 'maintenanceType':
|
||||
valueA = a.maintenanceType;
|
||||
valueB = b.maintenanceType;
|
||||
break;
|
||||
case 'periodMonth':
|
||||
valueA = a.periodMonth;
|
||||
valueB = b.periodMonth;
|
||||
break;
|
||||
default:
|
||||
valueA = a.id;
|
||||
valueB = b.id;
|
||||
}
|
||||
|
||||
if (valueA == null && valueB == null) return 0;
|
||||
if (valueA == null) return ascending ? -1 : 1;
|
||||
if (valueB == null) return ascending ? 1 : -1;
|
||||
|
||||
final comparison = valueA.compareTo(valueB);
|
||||
return ascending ? comparison : -comparison;
|
||||
});
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
// 유지보수 일정 조회 (백엔드 스키마 기반)
|
||||
List<MaintenanceDto> getScheduleForMaintenance(DateTime date) {
|
||||
return _maintenances.where((maintenance) {
|
||||
final startDate = DateTime(
|
||||
maintenance.startedAt.year,
|
||||
maintenance.startedAt.month,
|
||||
maintenance.startedAt.day,
|
||||
);
|
||||
final endDate = DateTime(
|
||||
maintenance.endedAt.year,
|
||||
maintenance.endedAt.month,
|
||||
maintenance.endedAt.day,
|
||||
);
|
||||
final targetDate = DateTime(date.year, date.month, date.day);
|
||||
|
||||
return (targetDate.isAfter(startDate) || targetDate.isAtSameMomentAs(startDate)) &&
|
||||
(targetDate.isBefore(endDate) || targetDate.isAtSameMomentAs(endDate)) &&
|
||||
!(maintenance.isDeleted ?? false);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
// 초기화 (백엔드 실제 구조)
|
||||
|
||||
// 초기화
|
||||
void reset() {
|
||||
_maintenances.clear();
|
||||
_expiringMaintenances.clear();
|
||||
_selectedMaintenance = null;
|
||||
_currentPage = 1;
|
||||
_totalCount = 0;
|
||||
_totalPages = 0;
|
||||
_equipmentId = null;
|
||||
_maintenanceType = null;
|
||||
_equipmentHistoryId = null;
|
||||
_isExpired = null;
|
||||
_expiringDays = null;
|
||||
_includeDeleted = false;
|
||||
_searchQuery = '';
|
||||
_sortField = 'startedAt';
|
||||
_sortAscending = false;
|
||||
_error = null;
|
||||
_isLoading = false;
|
||||
_upcomingAlerts.clear();
|
||||
_overdueAlerts.clear();
|
||||
_searchQuery = '';
|
||||
_currentSortField = '';
|
||||
_isAscending = true;
|
||||
_isFormLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
reset();
|
||||
|
||||
@@ -180,32 +180,6 @@ class _MaintenanceAlertDashboardState extends State<MaintenanceAlertDashboard> {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Widget _buildStatCard(String title, String value, IconData icon, Color color) {
|
||||
return Column(
|
||||
children: [
|
||||
Icon(icon, color: color, size: 32),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAlertSections(MaintenanceController controller) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
@@ -30,6 +30,7 @@ class _MaintenanceFormDialogState extends State<MaintenanceFormDialog> {
|
||||
|
||||
List<EquipmentHistoryDto> _equipmentHistories = [];
|
||||
bool _isLoadingHistories = false;
|
||||
String? _historiesError;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -66,6 +67,7 @@ class _MaintenanceFormDialogState extends State<MaintenanceFormDialog> {
|
||||
void _loadEquipmentHistories() async {
|
||||
setState(() {
|
||||
_isLoadingHistories = true;
|
||||
_historiesError = null; // 오류 상태 초기화
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -75,20 +77,21 @@ class _MaintenanceFormDialogState extends State<MaintenanceFormDialog> {
|
||||
setState(() {
|
||||
_equipmentHistories = controller.historyList;
|
||||
_isLoadingHistories = false;
|
||||
_historiesError = null; // 성공 시 오류 상태 클리어
|
||||
});
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_isLoadingHistories = false;
|
||||
_historiesError = '장비 이력을 불러오는 중 오류가 발생했습니다: ${e.toString()}';
|
||||
});
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('장비 이력 로드 실패: $e')),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 재시도 기능 추가
|
||||
void _retryLoadHistories() {
|
||||
_loadEquipmentHistories();
|
||||
}
|
||||
|
||||
// _calculateNextDate 메서드 제거 - 백엔드에 nextMaintenanceDate 필드 없음
|
||||
|
||||
@override
|
||||
@@ -196,36 +199,89 @@ class _MaintenanceFormDialogState extends State<MaintenanceFormDialog> {
|
||||
}
|
||||
|
||||
Widget _buildEquipmentHistorySelector() {
|
||||
if (_isLoadingHistories) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
return DropdownButtonFormField<int>(
|
||||
value: _selectedEquipmentHistoryId,
|
||||
decoration: const InputDecoration(
|
||||
labelText: '장비 이력 선택',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
items: _equipmentHistories.map((history) {
|
||||
final equipment = history.equipment;
|
||||
return DropdownMenuItem(
|
||||
value: history.id,
|
||||
child: Text(
|
||||
'${equipment?.serialNumber ?? "Unknown"} - '
|
||||
'${equipment?.serialNumber ?? "No Serial"} '
|
||||
'(${history.transactionType == "I" ? "입고" : "출고"})',
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: widget.maintenance == null
|
||||
? (value) => setState(() => _selectedEquipmentHistoryId = value)
|
||||
: null, // 수정 모드에서는 변경 불가
|
||||
validator: (value) {
|
||||
if (value == null) {
|
||||
return '장비 이력을 선택해주세요';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('장비 이력 선택 *', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// 3단계 상태 처리 (UserForm 패턴 적용)
|
||||
_isLoadingHistories
|
||||
? const SizedBox(
|
||||
height: 56,
|
||||
child: Center(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
CircularProgressIndicator(),
|
||||
SizedBox(width: 8),
|
||||
Text('장비 이력을 불러오는 중...'),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
// 오류 발생 시 오류 컨테이너 표시
|
||||
: _historiesError != null
|
||||
? Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red.shade50,
|
||||
border: Border.all(color: Colors.red.shade200),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.error, color: Colors.red.shade600, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
const Text('장비 이력 로딩 실패', style: TextStyle(fontWeight: FontWeight.w500)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
_historiesError!,
|
||||
style: TextStyle(color: Colors.red.shade700, fontSize: 14),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
ElevatedButton.icon(
|
||||
onPressed: _retryLoadHistories,
|
||||
icon: const Icon(Icons.refresh, size: 16),
|
||||
label: const Text('다시 시도'),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
// 정상 상태: shadcn_ui 드롭다운 표시
|
||||
: DropdownButtonFormField<int>(
|
||||
value: _selectedEquipmentHistoryId,
|
||||
decoration: const InputDecoration(
|
||||
labelText: '장비 이력 선택',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
items: _equipmentHistories.map((history) {
|
||||
final equipment = history.equipment;
|
||||
return DropdownMenuItem(
|
||||
value: history.id,
|
||||
child: Text(
|
||||
'${equipment?.serialNumber ?? "Unknown"} - '
|
||||
'${equipment?.modelName ?? "No Model"} '
|
||||
'(${TransactionType.getDisplayName(history.transactionType)})',
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: widget.maintenance == null
|
||||
? (value) => setState(() => _selectedEquipmentHistoryId = value)
|
||||
: null, // 수정 모드에서는 변경 불가
|
||||
validator: (value) {
|
||||
if (value == null) {
|
||||
return '장비 이력을 선택해주세요';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1048,13 +1048,4 @@ class _MaintenanceHistoryScreenState extends State<MaintenanceHistoryScreen>
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _exportHistory() {
|
||||
ShadToaster.of(context).show(
|
||||
const ShadToast(
|
||||
title: Text('엑셀 내보내기'),
|
||||
description: Text('엑셀 내보내기 기능은 준비 중입니다'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
629
lib/screens/maintenance/maintenance_list.dart
Normal file
629
lib/screens/maintenance/maintenance_list.dart
Normal file
@@ -0,0 +1,629 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:superport/screens/common/theme_shadcn.dart';
|
||||
import 'package:superport/screens/common/widgets/pagination.dart';
|
||||
import 'package:superport/screens/common/widgets/standard_action_bar.dart';
|
||||
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/domain/usecases/maintenance_usecase.dart';
|
||||
|
||||
/// shadcn/ui 스타일로 설계된 유지보수 관리 화면
|
||||
class MaintenanceList extends StatefulWidget {
|
||||
const MaintenanceList({super.key});
|
||||
|
||||
@override
|
||||
State<MaintenanceList> createState() => _MaintenanceListState();
|
||||
}
|
||||
|
||||
class _MaintenanceListState extends State<MaintenanceList> {
|
||||
late final MaintenanceController _controller;
|
||||
bool _showDetailedColumns = true;
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final ScrollController _horizontalScrollController = ScrollController();
|
||||
final Set<int> _selectedItems = {};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = MaintenanceController(
|
||||
maintenanceUseCase: GetIt.instance<MaintenanceUseCase>(),
|
||||
);
|
||||
|
||||
// 초기 데이터 로드
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_controller.loadMaintenances(refresh: true);
|
||||
_controller.loadExpiringMaintenances();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchController.dispose();
|
||||
_horizontalScrollController.dispose();
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_adjustColumnsForScreenSize();
|
||||
}
|
||||
|
||||
/// 화면 크기에 따라 컬럼 표시 조정
|
||||
void _adjustColumnsForScreenSize() {
|
||||
final width = MediaQuery.of(context).size.width;
|
||||
setState(() {
|
||||
_showDetailedColumns = width > 1000;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ChangeNotifierProvider.value(
|
||||
value: _controller,
|
||||
child: Scaffold(
|
||||
backgroundColor: ShadcnTheme.background,
|
||||
body: Column(
|
||||
children: [
|
||||
_buildActionBar(),
|
||||
_buildFilterBar(),
|
||||
Expanded(child: _buildMainContent()),
|
||||
_buildBottomBar(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 상단 액션바
|
||||
Widget _buildActionBar() {
|
||||
return Consumer<MaintenanceController>(
|
||||
builder: (context, controller, child) {
|
||||
return StandardActionBar(
|
||||
totalCount: controller.totalCount,
|
||||
selectedCount: _selectedItems.length,
|
||||
leftActions: const [
|
||||
Text('유지보수 관리', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
],
|
||||
rightActions: [
|
||||
// 만료 예정 알림
|
||||
if (controller.expiringMaintenances.isNotEmpty)
|
||||
ShadButton.outline(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.notification_important, size: 16),
|
||||
const SizedBox(width: 4),
|
||||
Text('만료 예정 ${controller.expiringMaintenances.length}건'),
|
||||
],
|
||||
),
|
||||
onPressed: () => _showExpiringMaintenances(),
|
||||
),
|
||||
|
||||
// 새로운 유지보수 등록
|
||||
ShadButton(
|
||||
child: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.add, size: 16),
|
||||
SizedBox(width: 4),
|
||||
Text('유지보수 등록'),
|
||||
],
|
||||
),
|
||||
onPressed: () => _showMaintenanceForm(),
|
||||
),
|
||||
|
||||
// 선택된 항목 삭제
|
||||
if (_selectedItems.isNotEmpty)
|
||||
ShadButton.destructive(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.delete, size: 16),
|
||||
const SizedBox(width: 4),
|
||||
Text('삭제 (${_selectedItems.length})'),
|
||||
],
|
||||
),
|
||||
onPressed: () => _showDeleteConfirmation(),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 필터바
|
||||
Widget _buildFilterBar() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: ShadcnTheme.card,
|
||||
border: Border(
|
||||
bottom: BorderSide(color: ShadcnTheme.border),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// 유지보수 타입 필터
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: ShadSelect<String>(
|
||||
placeholder: const Text('유지보수 타입'),
|
||||
options: [
|
||||
const ShadOption(value: 'all', child: Text('전체')),
|
||||
...MaintenanceType.typeOptions.map((option) =>
|
||||
ShadOption(
|
||||
value: option['value']!,
|
||||
child: Text(option['label']!),
|
||||
),
|
||||
),
|
||||
],
|
||||
selectedOptionBuilder: (context, value) {
|
||||
if (value == 'all') return const Text('전체');
|
||||
final option = MaintenanceType.typeOptions
|
||||
.firstWhere((o) => o['value'] == value, orElse: () => {'label': value});
|
||||
return Text(option['label']!);
|
||||
},
|
||||
onChanged: (value) {
|
||||
_controller.setMaintenanceTypeFilter(
|
||||
value == 'all' ? null : value,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(width: 12),
|
||||
|
||||
// 상태 필터
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: ShadSelect<String>(
|
||||
placeholder: const Text('상태'),
|
||||
options: const [
|
||||
ShadOption(value: 'all', child: Text('전체')),
|
||||
ShadOption(value: 'active', child: Text('활성')),
|
||||
ShadOption(value: 'expired', child: Text('만료')),
|
||||
ShadOption(value: 'expiring', child: Text('만료 예정')),
|
||||
],
|
||||
selectedOptionBuilder: (context, value) {
|
||||
switch (value) {
|
||||
case 'active': return const Text('활성');
|
||||
case 'expired': return const Text('만료');
|
||||
case 'expiring': return const Text('만료 예정');
|
||||
default: return const Text('전체');
|
||||
}
|
||||
},
|
||||
onChanged: (value) {
|
||||
_applyStatusFilter(value ?? 'all');
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(width: 12),
|
||||
|
||||
// 검색
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: ShadInput(
|
||||
controller: _searchController,
|
||||
placeholder: const Text('장비 시리얼 번호 또는 모델명 검색...'),
|
||||
onSubmitted: (_) => _performSearch(),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(width: 12),
|
||||
|
||||
// 필터 초기화
|
||||
ShadButton.outline(
|
||||
child: const Icon(Icons.refresh, size: 16),
|
||||
onPressed: _resetFilters,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 메인 컨텐츠
|
||||
Widget _buildMainContent() {
|
||||
return Consumer<MaintenanceController>(
|
||||
builder: (context, controller, child) {
|
||||
if (controller.isLoading && controller.maintenances.isEmpty) {
|
||||
return const StandardLoadingState(message: '유지보수 목록을 불러오는 중...');
|
||||
}
|
||||
|
||||
if (controller.error != null) {
|
||||
return StandardErrorState(
|
||||
message: controller.error!,
|
||||
onRetry: () => controller.loadMaintenances(refresh: true),
|
||||
);
|
||||
}
|
||||
|
||||
if (controller.maintenances.isEmpty) {
|
||||
return const StandardEmptyState(
|
||||
icon: Icons.build_circle_outlined,
|
||||
title: '유지보수가 없습니다',
|
||||
message: '새로운 유지보수를 등록해보세요.',
|
||||
);
|
||||
}
|
||||
|
||||
return _buildDataTable(controller);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 데이터 테이블
|
||||
Widget _buildDataTable(MaintenanceController controller) {
|
||||
return SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
controller: _horizontalScrollController,
|
||||
child: DataTable(
|
||||
columns: _buildHeaders(),
|
||||
rows: _buildRows(controller.maintenances),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 테이블 헤더
|
||||
List<DataColumn> _buildHeaders() {
|
||||
return [
|
||||
const DataColumn(label: Text('선택')),
|
||||
const DataColumn(label: Text('ID')),
|
||||
const DataColumn(label: Text('장비 정보')),
|
||||
const DataColumn(label: Text('유지보수 타입')),
|
||||
const DataColumn(label: Text('시작일')),
|
||||
const DataColumn(label: Text('종료일')),
|
||||
if (_showDetailedColumns) ...[
|
||||
const DataColumn(label: Text('주기')),
|
||||
const DataColumn(label: Text('상태')),
|
||||
const DataColumn(label: Text('남은 일수')),
|
||||
],
|
||||
const DataColumn(label: Text('작업')),
|
||||
];
|
||||
}
|
||||
|
||||
/// 테이블 로우
|
||||
List<DataRow> _buildRows(List<MaintenanceDto> maintenances) {
|
||||
return maintenances.map((maintenance) {
|
||||
final isSelected = _selectedItems.contains(maintenance.id);
|
||||
|
||||
return DataRow(
|
||||
selected: isSelected,
|
||||
onSelectChanged: (_) => _showMaintenanceDetail(maintenance),
|
||||
cells: [
|
||||
// 선택 체크박스
|
||||
DataCell(
|
||||
Checkbox(
|
||||
value: isSelected,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
if (value == true) {
|
||||
_selectedItems.add(maintenance.id!);
|
||||
} else {
|
||||
_selectedItems.remove(maintenance.id!);
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
// ID
|
||||
DataCell(Text(maintenance.id?.toString() ?? '-')),
|
||||
|
||||
// 장비 정보
|
||||
DataCell(
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
maintenance.equipmentSerial ?? '시리얼 번호 없음',
|
||||
style: const TextStyle(fontWeight: FontWeight.w500),
|
||||
),
|
||||
if (maintenance.equipmentModel != null)
|
||||
Text(
|
||||
maintenance.equipmentModel!,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// 유지보수 타입
|
||||
DataCell(
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: _getMaintenanceTypeColor(maintenance.maintenanceType),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
MaintenanceType.getDisplayName(maintenance.maintenanceType),
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// 시작일
|
||||
DataCell(Text(DateFormat('yyyy-MM-dd').format(maintenance.startedAt))),
|
||||
|
||||
// 종료일
|
||||
DataCell(Text(DateFormat('yyyy-MM-dd').format(maintenance.endedAt))),
|
||||
|
||||
// 상세 컬럼들
|
||||
if (_showDetailedColumns) ...[
|
||||
// 주기
|
||||
DataCell(Text('${maintenance.periodMonth}개월')),
|
||||
|
||||
// 상태
|
||||
DataCell(
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: _controller.getMaintenanceStatusColor(maintenance),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
_controller.getMaintenanceStatusText(maintenance),
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// 남은 일수
|
||||
DataCell(
|
||||
Text(
|
||||
maintenance.daysRemaining != null
|
||||
? '${maintenance.daysRemaining}일'
|
||||
: '-',
|
||||
style: TextStyle(
|
||||
color: maintenance.daysRemaining != null &&
|
||||
maintenance.daysRemaining! <= 30
|
||||
? Colors.red
|
||||
: null,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
// 작업 버튼들
|
||||
DataCell(
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ShadButton.ghost(
|
||||
child: const Icon(Icons.edit, size: 16),
|
||||
onPressed: () => _showMaintenanceForm(maintenance: maintenance),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
ShadButton.ghost(
|
||||
child: Icon(
|
||||
Icons.delete,
|
||||
size: 16,
|
||||
color: Colors.red[400],
|
||||
),
|
||||
onPressed: () => _deleteMaintenance(maintenance),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
/// 하단바 (페이지네이션)
|
||||
Widget _buildBottomBar() {
|
||||
return Consumer<MaintenanceController>(
|
||||
builder: (context, controller, child) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: ShadcnTheme.card,
|
||||
border: Border(
|
||||
top: BorderSide(color: ShadcnTheme.border),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// 선택된 항목 정보
|
||||
if (_selectedItems.isNotEmpty)
|
||||
Text('${_selectedItems.length}개 선택됨'),
|
||||
|
||||
const Spacer(),
|
||||
|
||||
// 페이지네이션
|
||||
Pagination(
|
||||
totalCount: controller.totalCount,
|
||||
currentPage: controller.currentPage,
|
||||
pageSize: 20, // MaintenanceController._perPage 상수값
|
||||
onPageChanged: (page) => controller.goToPage(page),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// 유틸리티 메서드들
|
||||
Color _getMaintenanceTypeColor(String type) {
|
||||
switch (type) {
|
||||
case MaintenanceType.warranty:
|
||||
return Colors.blue;
|
||||
case MaintenanceType.contract:
|
||||
return Colors.orange;
|
||||
case MaintenanceType.inspection:
|
||||
return Colors.green;
|
||||
default:
|
||||
return Colors.grey;
|
||||
}
|
||||
}
|
||||
|
||||
void _applyStatusFilter(String status) {
|
||||
switch (status) {
|
||||
case 'active':
|
||||
_controller.setExpiredFilter(false);
|
||||
break;
|
||||
case 'expired':
|
||||
_controller.setExpiredFilter(true);
|
||||
break;
|
||||
case 'expiring':
|
||||
_controller.setExpiringDaysFilter(30);
|
||||
break;
|
||||
default:
|
||||
_controller.setExpiredFilter(null);
|
||||
_controller.setExpiringDaysFilter(null);
|
||||
}
|
||||
}
|
||||
|
||||
void _performSearch() {
|
||||
// TODO: 장비 시리얼/모델 검색 구현
|
||||
// 백엔드에 검색 API가 추가되면 구현
|
||||
}
|
||||
|
||||
void _resetFilters() {
|
||||
setState(() {
|
||||
_searchController.clear();
|
||||
});
|
||||
_controller.clearFilters();
|
||||
}
|
||||
|
||||
// 다이얼로그 메서드들
|
||||
void _showMaintenanceForm({MaintenanceDto? maintenance}) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => ChangeNotifierProvider.value(
|
||||
value: _controller,
|
||||
child: MaintenanceFormDialog(maintenance: maintenance),
|
||||
),
|
||||
).then((_) {
|
||||
// 폼 닫힌 후 목록 새로고침
|
||||
_controller.loadMaintenances(refresh: true);
|
||||
});
|
||||
}
|
||||
|
||||
void _showMaintenanceDetail(MaintenanceDto maintenance) {
|
||||
_controller.selectMaintenance(maintenance);
|
||||
_showMaintenanceForm(maintenance: maintenance);
|
||||
}
|
||||
|
||||
void _showExpiringMaintenances() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('만료 예정 유지보수'),
|
||||
content: SizedBox(
|
||||
width: 600,
|
||||
height: 400,
|
||||
child: ListView.builder(
|
||||
itemCount: _controller.expiringMaintenances.length,
|
||||
itemBuilder: (context, index) {
|
||||
final maintenance = _controller.expiringMaintenances[index];
|
||||
return ListTile(
|
||||
title: Text(maintenance.equipmentSerial ?? '시리얼 번호 없음'),
|
||||
subtitle: Text(
|
||||
'${MaintenanceType.getDisplayName(maintenance.maintenanceType)} - '
|
||||
'${DateFormat('yyyy-MM-dd').format(maintenance.endedAt)} 만료',
|
||||
),
|
||||
trailing: maintenance.daysRemaining != null
|
||||
? Text(
|
||||
'${maintenance.daysRemaining}일 남음',
|
||||
style: TextStyle(
|
||||
color: maintenance.daysRemaining! <= 7
|
||||
? Colors.red
|
||||
: Colors.orange,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
)
|
||||
: null,
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
_showMaintenanceDetail(maintenance);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('닫기'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _deleteMaintenance(MaintenanceDto maintenance) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('유지보수 삭제'),
|
||||
content: Text(
|
||||
'${maintenance.equipmentSerial ?? "선택된"} 장비의 유지보수를 삭제하시겠습니까?\n'
|
||||
'삭제된 데이터는 복구할 수 있습니다.',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(context);
|
||||
final success = await _controller.deleteMaintenance(maintenance.id!);
|
||||
if (success && mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('유지보수가 삭제되었습니다')),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: const Text('삭제', style: TextStyle(color: Colors.red)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showDeleteConfirmation() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('선택된 유지보수 삭제'),
|
||||
content: Text('선택된 ${_selectedItems.length}개의 유지보수를 삭제하시겠습니까?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(context);
|
||||
// TODO: 일괄 삭제 구현
|
||||
setState(() {
|
||||
_selectedItems.clear();
|
||||
});
|
||||
},
|
||||
child: const Text('삭제', style: TextStyle(color: Colors.red)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -179,47 +179,6 @@ class _MaintenanceScheduleScreenState extends State<MaintenanceScheduleScreen>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatCard(
|
||||
String title,
|
||||
String value,
|
||||
IconData icon,
|
||||
Color color,
|
||||
) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, color: color, size: 32),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFilterBar() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
|
||||
@@ -513,17 +472,6 @@ class _MaintenanceScheduleScreenState extends State<MaintenanceScheduleScreen>
|
||||
);
|
||||
}
|
||||
|
||||
void _showCreateMaintenanceDialog() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => const MaintenanceFormDialog(),
|
||||
).then((result) {
|
||||
if (result == true) {
|
||||
context.read<MaintenanceController>().loadMaintenances(refresh: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _showMaintenanceDetails(MaintenanceDto maintenance) {
|
||||
showDialog(
|
||||
context: context,
|
||||
|
||||
Reference in New Issue
Block a user