feat: handle off-shelf registration results

This commit is contained in:
Misaka_Company
2026-05-13 12:43:22 +08:00
parent b975b15ba7
commit b32c9c5aad
3 changed files with 145 additions and 18 deletions

View File

@@ -5,23 +5,41 @@ import 'package:http/http.dart' as http;
class RegistrationResult {
final bool success;
final bool isDuplicate;
final bool isAlreadyOffShelf;
final bool isOffShelfSuccess;
final String? errorMessage;
final Map<String, dynamic>? duplicateInfo;
final Map<String, dynamic>? conflictInfo;
RegistrationResult({
required this.success,
this.isDuplicate = false,
this.isAlreadyOffShelf = false,
this.isOffShelfSuccess = false,
this.errorMessage,
this.duplicateInfo,
this.conflictInfo,
});
factory RegistrationResult.ok() => RegistrationResult(success: true);
factory RegistrationResult.offShelfSuccess() =>
RegistrationResult(success: true, isOffShelfSuccess: true);
factory RegistrationResult.duplicate(Map<String, dynamic> info) =>
RegistrationResult(
success: false,
isDuplicate: true,
duplicateInfo: info,
conflictInfo: info,
);
factory RegistrationResult.alreadyOffShelf(Map<String, dynamic> info) =>
RegistrationResult(
success: false,
isAlreadyOffShelf: true,
errorMessage: info['message']?.toString() ?? '该总排号已下架至转运区域,不可重新上架',
conflictInfo: info,
);
factory RegistrationResult.error(String message) =>
@@ -228,6 +246,10 @@ class ApiService {
switch (response.statusCode) {
case 200:
final body = jsonDecode(response.body) as Map<String, dynamic>;
if (body['previous_location'] != null) {
return RegistrationResult.offShelfSuccess();
}
return RegistrationResult.ok();
case 400:
final body = jsonDecode(response.body) as Map<String, dynamic>;
@@ -235,7 +257,15 @@ class ApiService {
return RegistrationResult.error(msg);
case 409:
final body = jsonDecode(response.body) as Map<String, dynamic>;
return RegistrationResult.duplicate(body);
final errorCode = body['error_code']?.toString();
if (errorCode == 'DUPLICATE_LOCATION') {
return RegistrationResult.duplicate(body);
}
if (errorCode == 'ALREADY_OFF_SHELF') {
return RegistrationResult.alreadyOffShelf(body);
}
final msg = body['message']?.toString() ?? '提交失败';
return RegistrationResult.error(msg);
default:
final body = jsonDecode(response.body) as Map<String, dynamic>;
final msg =