사용하지 않는 파일 정리 전 백업 (Phase 10 완료 후 상태)
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
/// - 지점 생성/수정 요청
|
||||
/// - 폼 유효성 검증
|
||||
/// - 수정 모드에서 기존 데이터 로드
|
||||
library;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:superport/models/address_model.dart';
|
||||
@@ -135,7 +136,7 @@ class BranchController extends ChangeNotifier {
|
||||
/// 폼에 지점 데이터 설정 (수정 모드에서만 사용)
|
||||
void _populateFormWithBranchData(Company company) {
|
||||
nameController.text = company.name;
|
||||
addressController.text = company.address?.detailAddress ?? '';
|
||||
addressController.text = company.address.detailAddress ?? '';
|
||||
contactNameController.text = company.contactName ?? '';
|
||||
contactPositionController.text = company.contactPosition ?? '';
|
||||
contactEmailController.text = company.contactEmail ?? '';
|
||||
@@ -273,7 +274,7 @@ class BranchController extends ChangeNotifier {
|
||||
);
|
||||
|
||||
return nameController.text.trim() != _originalBranch!.name ||
|
||||
currentAddress.detailAddress != (_originalBranch!.address?.detailAddress ?? '') ||
|
||||
currentAddress.detailAddress != (_originalBranch!.address.detailAddress ?? '') ||
|
||||
contactNameController.text.trim() != (_originalBranch!.contactName ?? '') ||
|
||||
contactPositionController.text.trim() != (_originalBranch!.contactPosition ?? '') ||
|
||||
currentFullPhone != (_originalBranch!.contactPhone ?? '') ||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
/// - 전화번호 처리
|
||||
/// - 중복 회사명 체크
|
||||
/// - 회사 유형 관리
|
||||
library;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:superport/models/address_model.dart';
|
||||
@@ -15,7 +16,6 @@ import 'package:superport/models/company_model.dart';
|
||||
// import 'package:superport/services/mock_data_service.dart'; // Mock 서비스 제거
|
||||
import 'package:superport/services/company_service.dart';
|
||||
import 'package:superport/core/errors/failures.dart';
|
||||
import 'package:superport/utils/phone_utils.dart';
|
||||
import 'dart:async';
|
||||
import 'branch_form_controller.dart'; // 분리된 지점 컨트롤러 import
|
||||
|
||||
@@ -42,6 +42,10 @@ class CompanyFormController {
|
||||
|
||||
// 회사 유형 선택값 (복수)
|
||||
List<CompanyType> selectedCompanyTypes = [CompanyType.customer];
|
||||
|
||||
// 부모 회사 선택
|
||||
int? selectedParentCompanyId;
|
||||
List<Company> availableParentCompanies = [];
|
||||
|
||||
List<String> companyNames = [];
|
||||
List<String> filteredCompanyNames = [];
|
||||
@@ -96,15 +100,23 @@ class CompanyFormController {
|
||||
List<Company> companies;
|
||||
|
||||
// API만 사용 (PaginatedResponse에서 items 추출)
|
||||
final response = await _companyService.getCompanies();
|
||||
final response = await _companyService.getCompanies(page: 1, perPage: 1000);
|
||||
companies = response.items;
|
||||
|
||||
companyNames = companies.map((c) => c.name).toList();
|
||||
filteredCompanyNames = companyNames;
|
||||
|
||||
// 부모 회사 목록도 설정 (자기 자신은 제외)
|
||||
if (companyId != null) {
|
||||
availableParentCompanies = companies.where((c) => c.id != companyId).toList();
|
||||
} else {
|
||||
availableParentCompanies = companies;
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('❌ 회사명 목록 로드 실패: $e');
|
||||
companyNames = [];
|
||||
filteredCompanyNames = [];
|
||||
availableParentCompanies = [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,86 +142,81 @@ class CompanyFormController {
|
||||
}
|
||||
|
||||
debugPrint('📝 로드된 회사 정보:');
|
||||
debugPrint(' - ID: ${company?.id}');
|
||||
debugPrint(' - 이름: ${company?.name}');
|
||||
debugPrint(' - 담당자: ${company?.contactName}');
|
||||
debugPrint(' - 연락처: ${company?.contactPhone}');
|
||||
debugPrint(' - 이메일: ${company?.contactEmail}');
|
||||
debugPrint(' - ID: ${company.id}');
|
||||
debugPrint(' - 이름: ${company.name}');
|
||||
debugPrint(' - 담당자: ${company.contactName}');
|
||||
debugPrint(' - 연락처: ${company.contactPhone}');
|
||||
debugPrint(' - 이메일: ${company.contactEmail}');
|
||||
|
||||
if (company != null) {
|
||||
// 폼 필드에 데이터 설정
|
||||
debugPrint('📝 회사명 설정 전: "${nameController.text}"');
|
||||
nameController.text = company.name;
|
||||
debugPrint('📝 회사명 설정 후: "${nameController.text}"');
|
||||
// 폼 필드에 데이터 설정
|
||||
debugPrint('📝 회사명 설정 전: "${nameController.text}"');
|
||||
nameController.text = company.name;
|
||||
debugPrint('📝 회사명 설정 후: "${nameController.text}"');
|
||||
|
||||
companyAddress = company.address;
|
||||
debugPrint('📝 주소 설정: $companyAddress');
|
||||
companyAddress = company.address;
|
||||
debugPrint('📝 주소 설정: $companyAddress');
|
||||
|
||||
contactNameController.text = company.contactName ?? '';
|
||||
debugPrint('📝 담당자명 설정: "${contactNameController.text}"');
|
||||
contactNameController.text = company.contactName ?? '';
|
||||
debugPrint('📝 담당자명 설정: "${contactNameController.text}"');
|
||||
|
||||
contactPositionController.text = company.contactPosition ?? '';
|
||||
debugPrint('📝 직급 설정: "${contactPositionController.text}"');
|
||||
contactPositionController.text = company.contactPosition ?? '';
|
||||
debugPrint('📝 직급 설정: "${contactPositionController.text}"');
|
||||
|
||||
contactEmailController.text = company.contactEmail ?? '';
|
||||
debugPrint('📝 이메일 설정: "${contactEmailController.text}"');
|
||||
contactEmailController.text = company.contactEmail ?? '';
|
||||
debugPrint('📝 이메일 설정: "${contactEmailController.text}"');
|
||||
|
||||
remarkController.text = company.remark ?? '';
|
||||
debugPrint('📝 비고 설정: "${remarkController.text}"');
|
||||
remarkController.text = company.remark ?? '';
|
||||
debugPrint('📝 비고 설정: "${remarkController.text}"');
|
||||
|
||||
// 전화번호 처리
|
||||
if (company.contactPhone != null && company.contactPhone!.isNotEmpty) {
|
||||
selectedPhonePrefix = extractPhonePrefix(
|
||||
company.contactPhone!,
|
||||
phonePrefixes,
|
||||
);
|
||||
contactPhoneController.text = extractPhoneNumberWithoutPrefix(
|
||||
company.contactPhone!,
|
||||
phonePrefixes,
|
||||
);
|
||||
debugPrint('📝 전화번호 설정: $selectedPhonePrefix-${contactPhoneController.text}');
|
||||
}
|
||||
|
||||
// 회사 유형 설정
|
||||
selectedCompanyTypes = List.from(company.companyTypes);
|
||||
debugPrint('📝 회사 유형 설정: $selectedCompanyTypes');
|
||||
|
||||
// 지점 정보 설정
|
||||
if (company.branches != null && company.branches!.isNotEmpty) {
|
||||
branchControllers.clear();
|
||||
for (final branch in company.branches!) {
|
||||
branchControllers.add(
|
||||
BranchFormController(
|
||||
branch: branch,
|
||||
positions: positions,
|
||||
phonePrefixes: phonePrefixes,
|
||||
),
|
||||
);
|
||||
}
|
||||
debugPrint('📝 지점 설정 완료: ${branchControllers.length}개');
|
||||
}
|
||||
|
||||
debugPrint('📝 폼 필드 설정 완료:');
|
||||
debugPrint(' - 회사명: "${nameController.text}"');
|
||||
debugPrint(' - 담당자: "${contactNameController.text}"');
|
||||
debugPrint(' - 이메일: "${contactEmailController.text}"');
|
||||
debugPrint(' - 전화번호: "$selectedPhonePrefix-${contactPhoneController.text}"');
|
||||
debugPrint(' - 지점 수: ${branchControllers.length}');
|
||||
debugPrint(' - 회사 유형: $selectedCompanyTypes');
|
||||
|
||||
// 강제로 TextEditingController 리스너 트리거
|
||||
nameController.notifyListeners();
|
||||
contactNameController.notifyListeners();
|
||||
contactPositionController.notifyListeners();
|
||||
contactEmailController.notifyListeners();
|
||||
contactPhoneController.notifyListeners();
|
||||
remarkController.notifyListeners();
|
||||
|
||||
debugPrint('✅ 폼 데이터 로드 완료');
|
||||
} else {
|
||||
debugPrint('❌ 회사 정보가 null입니다');
|
||||
// 전화번호 처리
|
||||
if (company.contactPhone != null && company.contactPhone!.isNotEmpty) {
|
||||
selectedPhonePrefix = extractPhonePrefix(
|
||||
company.contactPhone!,
|
||||
phonePrefixes,
|
||||
);
|
||||
contactPhoneController.text = extractPhoneNumberWithoutPrefix(
|
||||
company.contactPhone!,
|
||||
phonePrefixes,
|
||||
);
|
||||
debugPrint('📝 전화번호 설정: $selectedPhonePrefix-${contactPhoneController.text}');
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
|
||||
// 회사 유형 설정
|
||||
selectedCompanyTypes = List.from(company.companyTypes);
|
||||
debugPrint('📝 회사 유형 설정: $selectedCompanyTypes');
|
||||
|
||||
// 부모 회사 설정
|
||||
selectedParentCompanyId = company.parentCompanyId;
|
||||
debugPrint('📝 부모 회사 설정: $selectedParentCompanyId');
|
||||
|
||||
// 지점 정보 설정
|
||||
if (company.branches != null && company.branches!.isNotEmpty) {
|
||||
branchControllers.clear();
|
||||
for (final branch in company.branches!) {
|
||||
branchControllers.add(
|
||||
BranchFormController(
|
||||
branch: branch,
|
||||
positions: positions,
|
||||
phonePrefixes: phonePrefixes,
|
||||
),
|
||||
);
|
||||
}
|
||||
debugPrint('📝 지점 설정 완료: ${branchControllers.length}개');
|
||||
}
|
||||
|
||||
debugPrint('📝 폼 필드 설정 완료:');
|
||||
debugPrint(' - 회사명: "${nameController.text}"');
|
||||
debugPrint(' - 담당자: "${contactNameController.text}"');
|
||||
debugPrint(' - 이메일: "${contactEmailController.text}"');
|
||||
debugPrint(' - 전화번호: "$selectedPhonePrefix-${contactPhoneController.text}"');
|
||||
debugPrint(' - 지점 수: ${branchControllers.length}');
|
||||
debugPrint(' - 회사 유형: $selectedCompanyTypes');
|
||||
|
||||
// TextEditingController는 text 설정 시 자동으로 리스너 트리거됨
|
||||
// notifyListeners() 직접 호출은 불필요하고 부적절함
|
||||
|
||||
debugPrint('✅ 폼 데이터 로드 완료');
|
||||
} catch (e, stackTrace) {
|
||||
debugPrint('❌ 회사 정보 로드 실패: $e');
|
||||
debugPrint('❌ 스택 트레이스: $stackTrace');
|
||||
rethrow;
|
||||
@@ -356,6 +363,7 @@ class CompanyFormController {
|
||||
companyTypes: List.from(selectedCompanyTypes), // 복수 유형 저장
|
||||
isPartner: selectedCompanyTypes.contains(CompanyType.partner),
|
||||
isCustomer: selectedCompanyTypes.contains(CompanyType.customer),
|
||||
parentCompanyId: selectedParentCompanyId, // 부모 회사 ID 추가
|
||||
);
|
||||
|
||||
if (_useApi) {
|
||||
|
||||
@@ -6,17 +6,29 @@ import 'package:superport/services/company_service.dart';
|
||||
import 'package:superport/core/utils/error_handler.dart';
|
||||
import 'package:superport/core/controllers/base_list_controller.dart';
|
||||
import 'package:superport/data/models/common/pagination_params.dart';
|
||||
import 'package:superport/domain/entities/company_hierarchy.dart';
|
||||
import 'package:superport/domain/usecases/company/get_company_hierarchy_usecase.dart';
|
||||
import 'package:superport/domain/usecases/company/update_parent_company_usecase.dart';
|
||||
import 'package:superport/domain/usecases/company/validate_company_deletion_usecase.dart';
|
||||
|
||||
/// 회사 목록 화면의 상태 및 비즈니스 로직을 담당하는 컨트롤러 (리팩토링 버전)
|
||||
/// BaseListController를 상속받아 공통 기능을 재사용
|
||||
/// CompanyItem 모델을 사용하여 회사와 지점을 통합 관리
|
||||
class CompanyListController extends BaseListController<CompanyItem> {
|
||||
late final CompanyService _companyService;
|
||||
late final GetCompanyHierarchyUseCase _getCompanyHierarchyUseCase;
|
||||
late final UpdateParentCompanyUseCase _updateParentCompanyUseCase;
|
||||
late final ValidateCompanyDeletionUseCase _validateCompanyDeletionUseCase;
|
||||
|
||||
// 추가 상태 관리
|
||||
final Set<int> selectedCompanyIds = {};
|
||||
int _actualHeadquartersCount = 0; // 실제 본사 개수 (헤드쿼터 API 기준)
|
||||
|
||||
// 계층 구조 관련
|
||||
CompanyHierarchy? _companyHierarchy;
|
||||
bool _isTreeView = false;
|
||||
final Map<String, bool> _expandedNodes = {};
|
||||
|
||||
// 필터
|
||||
bool? _isActiveFilter;
|
||||
CompanyType? _typeFilter;
|
||||
@@ -34,7 +46,7 @@ class CompanyListController extends BaseListController<CompanyItem> {
|
||||
|
||||
// 호환성을 위한 기존 getter (deprecated, 사용하지 말 것)
|
||||
@deprecated
|
||||
List<Company> get companies => items.where((item) => !item.isBranch).map((item) => item.company!).toList();
|
||||
List<Company> get companies => items.where((item) => !item.isBranch).map((item) => item.company).toList();
|
||||
@deprecated
|
||||
List<Company> get filteredCompanies => companies;
|
||||
bool? get isActiveFilter => _isActiveFilter;
|
||||
@@ -47,9 +59,17 @@ class CompanyListController extends BaseListController<CompanyItem> {
|
||||
loadData(isRefresh: true);
|
||||
}
|
||||
|
||||
// 계층 구조 getter
|
||||
CompanyHierarchy? get companyHierarchy => _companyHierarchy;
|
||||
bool get isTreeView => _isTreeView;
|
||||
Map<String, bool> get expandedNodes => _expandedNodes;
|
||||
|
||||
CompanyListController() {
|
||||
if (GetIt.instance.isRegistered<CompanyService>()) {
|
||||
_companyService = GetIt.instance<CompanyService>();
|
||||
_getCompanyHierarchyUseCase = GetIt.instance<GetCompanyHierarchyUseCase>();
|
||||
_updateParentCompanyUseCase = GetIt.instance<UpdateParentCompanyUseCase>();
|
||||
_validateCompanyDeletionUseCase = GetIt.instance<ValidateCompanyDeletionUseCase>();
|
||||
} else {
|
||||
throw Exception('CompanyService not registered in GetIt');
|
||||
}
|
||||
@@ -326,4 +346,107 @@ class CompanyListController extends BaseListController<CompanyItem> {
|
||||
}
|
||||
clearSelection();
|
||||
}
|
||||
|
||||
// ==================== 계층 구조 관련 메서드 ====================
|
||||
|
||||
/// Tree View 모드 토글
|
||||
void toggleTreeView() {
|
||||
_isTreeView = !_isTreeView;
|
||||
if (_isTreeView) {
|
||||
loadHierarchy();
|
||||
} else {
|
||||
loadData(isRefresh: true);
|
||||
}
|
||||
}
|
||||
|
||||
/// 계층 구조 로드
|
||||
Future<void> loadHierarchy() async {
|
||||
isLoadingState = true;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
final result = await _getCompanyHierarchyUseCase.call(
|
||||
const GetCompanyHierarchyParams(includeInactive: false),
|
||||
);
|
||||
|
||||
result.fold(
|
||||
(failure) {
|
||||
errorState = failure.message;
|
||||
_companyHierarchy = null;
|
||||
},
|
||||
(hierarchy) {
|
||||
_companyHierarchy = hierarchy;
|
||||
errorState = null;
|
||||
// 초기 확장 상태 설정 (루트 노드들만 확장)
|
||||
for (final child in hierarchy.children) {
|
||||
_expandedNodes[child.id] = true;
|
||||
}
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
errorState = '계층 구조 로드 중 오류가 발생했습니다: $e';
|
||||
_companyHierarchy = null;
|
||||
}
|
||||
|
||||
isLoadingState = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 노드 확장/축소 토글
|
||||
void toggleNodeExpansion(String nodeId) {
|
||||
_expandedNodes[nodeId] = !(_expandedNodes[nodeId] ?? false);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 부모 회사 변경
|
||||
Future<void> updateParentCompany(int companyId, int? newParentId) async {
|
||||
try {
|
||||
final result = await _updateParentCompanyUseCase.call(
|
||||
UpdateParentCompanyParams(
|
||||
companyId: companyId,
|
||||
newParentId: newParentId,
|
||||
),
|
||||
);
|
||||
|
||||
await result.fold(
|
||||
(failure) async {
|
||||
errorState = failure.message;
|
||||
notifyListeners();
|
||||
},
|
||||
(_) async {
|
||||
// 성공적으로 업데이트되면 리스트 새로고침
|
||||
if (_isTreeView) {
|
||||
await loadHierarchy();
|
||||
} else {
|
||||
await refresh();
|
||||
}
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
errorState = '부모 회사 변경 중 오류가 발생했습니다: $e';
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/// 회사 삭제 가능 여부 검증
|
||||
Future<bool> canDeleteCompany(int companyId) async {
|
||||
try {
|
||||
final result = await _validateCompanyDeletionUseCase.call(
|
||||
ValidateCompanyDeletionParams(companyId: companyId),
|
||||
);
|
||||
|
||||
return result.fold(
|
||||
(failure) {
|
||||
errorState = failure.message;
|
||||
notifyListeners();
|
||||
return false;
|
||||
},
|
||||
(validationResult) => validationResult.canDelete,
|
||||
);
|
||||
} catch (e) {
|
||||
errorState = '삭제 검증 중 오류가 발생했습니다: $e';
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user