결재 및 마스터 모듈을 v4 API 계약에 맞게 조정
This commit is contained in:
@@ -64,10 +64,11 @@ class ApprovalController extends ChangeNotifier {
|
||||
int? _applyingTemplateId;
|
||||
ApprovalProceedStatus? _proceedStatus;
|
||||
String? _errorMessage;
|
||||
String _query = '';
|
||||
ApprovalStatusFilter _statusFilter = ApprovalStatusFilter.all;
|
||||
DateTime? _fromDate;
|
||||
DateTime? _toDate;
|
||||
int? _transactionIdFilter;
|
||||
int? _requestedById;
|
||||
String? _requestedByName;
|
||||
String? _requestedByEmployeeNo;
|
||||
List<ApprovalAction> _actions = const [];
|
||||
List<ApprovalTemplate> _templates = const [];
|
||||
final Map<String, LookupItem> _statusLookup = {};
|
||||
@@ -85,10 +86,11 @@ class ApprovalController extends ChangeNotifier {
|
||||
bool get isPerformingAction => _isPerformingAction;
|
||||
int? get processingStepId => _processingStepId;
|
||||
String? get errorMessage => _errorMessage;
|
||||
String get query => _query;
|
||||
ApprovalStatusFilter get statusFilter => _statusFilter;
|
||||
DateTime? get fromDate => _fromDate;
|
||||
DateTime? get toDate => _toDate;
|
||||
int? get transactionIdFilter => _transactionIdFilter;
|
||||
int? get requestedById => _requestedById;
|
||||
String? get requestedByName => _requestedByName;
|
||||
String? get requestedByEmployeeNo => _requestedByEmployeeNo;
|
||||
List<ApprovalAction> get actionOptions => _actions;
|
||||
bool get hasActionOptions => _actions.isNotEmpty;
|
||||
List<ApprovalTemplate> get templates => _templates;
|
||||
@@ -116,14 +118,13 @@ class ApprovalController extends ChangeNotifier {
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
try {
|
||||
final statusParam = _statusCodeFor(_statusFilter);
|
||||
final statusId = _statusIdFor(_statusFilter);
|
||||
final response = await _repository.list(
|
||||
page: page,
|
||||
pageSize: _result?.pageSize ?? 20,
|
||||
query: _query.isEmpty ? null : _query,
|
||||
status: statusParam,
|
||||
from: _fromDate,
|
||||
to: _toDate,
|
||||
transactionId: _transactionIdFilter,
|
||||
approvalStatusId: statusId,
|
||||
requestedById: _requestedById,
|
||||
includeSteps: false,
|
||||
includeHistories: false,
|
||||
);
|
||||
@@ -176,18 +177,29 @@ class ApprovalController extends ChangeNotifier {
|
||||
_statusLookup
|
||||
..clear()
|
||||
..addEntries(
|
||||
items.map(
|
||||
(item) => MapEntry(
|
||||
(item.code ?? item.name).toLowerCase(),
|
||||
item,
|
||||
),
|
||||
),
|
||||
items.expand((item) {
|
||||
final keys = <String>{};
|
||||
final code = item.code?.trim();
|
||||
if (code != null && code.isNotEmpty) {
|
||||
keys.add(code.toLowerCase());
|
||||
}
|
||||
final name = item.name.trim();
|
||||
if (name.isNotEmpty) {
|
||||
keys.add(name.toLowerCase());
|
||||
}
|
||||
keys.add(item.id.toString());
|
||||
return keys.map((key) => MapEntry(key, item));
|
||||
}),
|
||||
);
|
||||
for (final entry in _defaultStatusCodes.entries) {
|
||||
final code = entry.value.toLowerCase();
|
||||
final lookup = _statusLookup[code];
|
||||
final defaultCode = entry.value;
|
||||
final normalized = defaultCode.toLowerCase();
|
||||
final lookup = _statusLookup[normalized];
|
||||
if (lookup != null) {
|
||||
_statusCodeAliases[entry.value] = lookup.code?.toLowerCase() ?? code;
|
||||
final alias = lookup.code?.toLowerCase() ?? normalized;
|
||||
_statusCodeAliases[defaultCode] = alias;
|
||||
} else {
|
||||
_statusCodeAliases[defaultCode] = defaultCode;
|
||||
}
|
||||
}
|
||||
notifyListeners();
|
||||
@@ -229,6 +241,15 @@ class ApprovalController extends ChangeNotifier {
|
||||
return _statusCodeAliases[defaultCode] ?? defaultCode;
|
||||
}
|
||||
|
||||
int? _statusIdFor(ApprovalStatusFilter filter) {
|
||||
final code = _statusCodeFor(filter);
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
final lookup = _statusLookup[code.toLowerCase()];
|
||||
return lookup?.id;
|
||||
}
|
||||
|
||||
/// 활성화된 결재 템플릿 목록을 조회해 캐싱한다.
|
||||
///
|
||||
/// 템플릿이 비어 있거나 [force]가 `true`이면 API를 다시 호출한다.
|
||||
@@ -325,8 +346,7 @@ class ApprovalController extends ChangeNotifier {
|
||||
final proceedStatus = await _repository.canProceed(approvalId);
|
||||
_proceedStatus = proceedStatus;
|
||||
if (!proceedStatus.canProceed) {
|
||||
_errorMessage = proceedStatus.reason ??
|
||||
'결재 단계가 현재 상태에서 진행될 수 없습니다.';
|
||||
_errorMessage = proceedStatus.reason ?? '결재 단계가 현재 상태에서 진행될 수 없습니다.';
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -421,31 +441,33 @@ class ApprovalController extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// 검색 키워드를 변경하고 UI 갱신을 유도한다.
|
||||
void updateQuery(String value) {
|
||||
_query = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 상태 필터 값을 변경한다.
|
||||
void updateStatusFilter(ApprovalStatusFilter filter) {
|
||||
_statusFilter = filter;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 조회 기간을 설정한다. 두 값 모두 `null`이면 기간 조건을 해제한다.
|
||||
void updateDateRange(DateTime? from, DateTime? to) {
|
||||
_fromDate = from;
|
||||
_toDate = to;
|
||||
/// 트랜잭션 ID 필터를 갱신한다. null이면 조건을 제거한다.
|
||||
void updateTransactionFilter(int? transactionId) {
|
||||
_transactionIdFilter = transactionId;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 검색어/상태/기간 등의 필터 조건을 초기화한다.
|
||||
/// 상신자(요청자) 필터를 갱신한다. null 값을 전달하면 조건을 제거한다.
|
||||
void updateRequestedByFilter({int? id, String? name, String? employeeNo}) {
|
||||
_requestedById = id;
|
||||
_requestedByName = name;
|
||||
_requestedByEmployeeNo = employeeNo;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 상태/트랜잭션/상신자 필터를 초기값으로 되돌린다.
|
||||
void clearFilters() {
|
||||
_query = '';
|
||||
_statusFilter = ApprovalStatusFilter.all;
|
||||
_fromDate = null;
|
||||
_toDate = null;
|
||||
_transactionIdFilter = null;
|
||||
_requestedById = null;
|
||||
_requestedByName = null;
|
||||
_requestedByEmployeeNo = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user