feat: 장비 관리 기능 강화 및 이력 추적 개선

- EquipmentHistoryDto 모델 확장 (상세 정보 추가)
- 장비 이력 화면 UI/UX 개선
- 장비 입고 폼 검증 로직 강화
- 테스트 이력 화면 추가
- API 응답 처리 개선

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
JiWoong Sul
2025-08-09 02:17:16 +09:00
parent f8e8a95391
commit cddde57450
9 changed files with 738 additions and 258 deletions

View File

@@ -18,7 +18,8 @@ class EquipmentInFormController extends ChangeNotifier {
final EquipmentService _equipmentService = GetIt.instance<EquipmentService>();
final WarehouseService _warehouseService = GetIt.instance<WarehouseService>();
final CompanyService _companyService = GetIt.instance<CompanyService>();
final int? equipmentInId;
final int? equipmentInId; // 실제로는 장비 ID (입고 ID가 아님)
int? actualEquipmentId; // API 호출용 실제 장비 ID
bool _isLoading = false;
String? _error;
@@ -85,9 +86,13 @@ class EquipmentInFormController extends ChangeNotifier {
_loadWarehouseLocations();
_loadPartnerCompanies();
_loadWarrantyLicenses();
if (isEditMode) {
_loadEquipmentIn();
}
// 수정 모드일 때 초기 데이터 로드는 initializeForEdit() 메서드로 이동
}
// 수정 모드 초기화 (외부에서 호출)
Future<void> initializeForEdit() async {
if (!isEditMode || equipmentInId == null) return;
await _loadEquipmentIn();
}
// 제조사 목록 로드
@@ -185,7 +190,7 @@ class EquipmentInFormController extends ChangeNotifier {
}
// 기존 데이터 로드(수정 모드)
void _loadEquipmentIn() async {
Future<void> _loadEquipmentIn() async {
if (equipmentInId == null) return;
_isLoading = true;
@@ -194,50 +199,67 @@ class EquipmentInFormController extends ChangeNotifier {
try {
if (_useApi) {
// API에서 장비 정보 로드
// 현재는 장비 정보만 가져올 수 있으므로, 일단 Mock 데이터와 병용
final equipmentIn = dataService.getEquipmentInById(equipmentInId!);
if (equipmentIn != null && equipmentIn.equipment.id != null) {
try {
// API에서 최신 장비 정보 가져오기
final equipment = await _equipmentService.getEquipment(equipmentIn.equipment.id!);
manufacturer = equipment.manufacturer;
name = equipment.name;
category = equipment.category;
subCategory = equipment.subCategory;
subSubCategory = equipment.subSubCategory;
serialNumber = equipment.serialNumber ?? '';
barcode = equipment.barcode ?? '';
quantity = equipment.quantity;
remarkController.text = equipment.remark ?? '';
hasSerialNumber = serialNumber.isNotEmpty;
// 워런티 정보
warrantyLicense = equipment.warrantyLicense;
warrantyStartDate = equipment.warrantyStartDate ?? DateTime.now();
warrantyEndDate = equipment.warrantyEndDate ?? DateTime.now().add(const Duration(days: 365));
// 입고 관련 정보는 아직 Mock 데이터 사용
inDate = equipmentIn.inDate;
equipmentType = equipmentIn.type;
warehouseLocation = equipmentIn.warehouseLocation;
partnerCompany = equipmentIn.partnerCompany;
} catch (e) {
// API 실패 시 Mock 데이터 사용
// equipmentInId는 실제로 장비 ID임 (입고 ID가 아님)
actualEquipmentId = equipmentInId;
try {
// API에서 장비 정보 가져오기
DebugLogger.log('장비 정보 로드 시작', tag: 'EQUIPMENT_IN', data: {
'equipmentId': actualEquipmentId,
});
final equipment = await _equipmentService.getEquipmentDetail(actualEquipmentId!);
DebugLogger.log('장비 정보 로드 성공', tag: 'EQUIPMENT_IN', data: {
'equipment': equipment.toJson(),
});
// 장비 정보 설정
manufacturer = equipment.manufacturer;
name = equipment.name;
category = equipment.category;
subCategory = equipment.subCategory;
subSubCategory = equipment.subSubCategory;
serialNumber = equipment.serialNumber ?? '';
barcode = equipment.barcode ?? '';
quantity = equipment.quantity;
remarkController.text = equipment.remark ?? '';
hasSerialNumber = serialNumber.isNotEmpty;
// 워런티 정보
warrantyLicense = equipment.warrantyLicense;
warrantyStartDate = equipment.warrantyStartDate ?? DateTime.now();
warrantyEndDate = equipment.warrantyEndDate ?? DateTime.now().add(const Duration(days: 365));
// 입고 관련 정보는 현재 API에서 제공하지 않으므로 기본값 사용
inDate = equipment.inDate ?? DateTime.now();
equipmentType = EquipmentType.new_;
// 창고 위치와 파트너사는 사용자가 수정 시 입력
} catch (e) {
DebugLogger.logError('장비 정보 로드 실패', error: e);
// API 실패 시 Mock 데이터 시도
final equipmentIn = dataService.getEquipmentInById(equipmentInId!);
if (equipmentIn != null) {
actualEquipmentId = equipmentIn.equipment.id;
_loadFromMockData(equipmentIn);
} else {
throw ServerFailure(message: '장비 정보를 찾을 수 없습니다.');
}
} else if (equipmentIn != null) {
_loadFromMockData(equipmentIn);
}
} else {
// Mock 데이터 사용
final equipmentIn = dataService.getEquipmentInById(equipmentInId!);
if (equipmentIn != null) {
actualEquipmentId = equipmentIn.equipment.id;
_loadFromMockData(equipmentIn);
} else {
throw ServerFailure(message: '장비 정보를 찾을 수 없습니다.');
}
}
} catch (e) {
_error = 'Failed to load equipment: $e';
_error = '장비 정보를 불러오는데 실패했습니다: $e';
DebugLogger.logError('장비 로드 실패', error: e);
} finally {
_isLoading = false;
notifyListeners();
@@ -356,7 +378,18 @@ class EquipmentInFormController extends ChangeNotifier {
// API 호출
if (isEditMode) {
// 수정 모드 - API로 장비 정보 업데이트
await _equipmentService.updateEquipment(equipmentInId!, equipment);
if (actualEquipmentId == null) {
throw ServerFailure(message: '장비 ID가 없습니다.');
}
DebugLogger.log('장비 정보 업데이트 시작', tag: 'EQUIPMENT_IN', data: {
'equipmentId': actualEquipmentId,
'data': equipment.toJson(),
});
await _equipmentService.updateEquipment(actualEquipmentId!, equipment);
DebugLogger.log('장비 정보 업데이트 성공', tag: 'EQUIPMENT_IN');
} else {
// 생성 모드
try {