feat:消费机更新
feat:人员调用钱包部门不调动的bug
This commit is contained in:
1 parent
842402e364
commit
60d9380a65
144 files changed
+27832
-1666
No files matched your search
@@ -1,3 +1,5 @@
|
||||
import 'package:common_utils/common_utils.dart';
|
||||
|
||||
import 'package:pj_supermarket_cloud/common/index.dart';
|
||||
|
||||
abstract class JsonTool {
|
||||
@@ -16,6 +18,28 @@ abstract class JsonTool {
|
||||
return int.tryParse(value);
|
||||
}
|
||||
|
||||
/// 兼容后端 Long 以字符串或数字返回的单值场景。
|
||||
static int anyToInt(Object? value) {
|
||||
if (value is int) return value;
|
||||
if (value is num) return value.toInt();
|
||||
final parsed = int.tryParse(value.toString());
|
||||
if (parsed == null) throw const FormatException('数字格式错误');
|
||||
return parsed;
|
||||
}
|
||||
|
||||
/// 兼容可选 Long 以字符串、数字或空值返回的场景,空值保持为空。
|
||||
static int? anyToNullableInt(Object? value) {
|
||||
if (value == null) return null;
|
||||
return anyToInt(value);
|
||||
}
|
||||
|
||||
/// 兼容后端 BigDecimal 以字符串或数字返回的可选小数。
|
||||
static double? anyToNullableDouble(Object? value) {
|
||||
if (value == null) return null;
|
||||
if (value is num) return value.toDouble();
|
||||
return double.tryParse(value.toString());
|
||||
}
|
||||
|
||||
static String? intToString(int? value) {
|
||||
if (value == null) return null;
|
||||
return value.toString();
|
||||
@@ -26,6 +50,33 @@ abstract class JsonTool {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
/// 将后端必填 Long 或字符串标识转换为非空字符串;缺失或空值时在模型边界直接拒绝。
|
||||
static String anyToRequiredString(Object? value) {
|
||||
final result = anyToString(value)?.trim();
|
||||
if (result == null || result.isEmpty) {
|
||||
throw const FormatException('必填标识不能为空');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// 将 Flutter 时间转换为 Java 后端 LocalDateTime 的统一请求格式,不携带时区和小数秒。
|
||||
static String dateTimeToServiceString(DateTime value) =>
|
||||
DateUtil.formatDate(value, format: DateFormats.full);
|
||||
|
||||
/// 后端为避免 19 位 Long 在部分客户端丢失精度,可能把 ID 序列化为字符串。
|
||||
/// 这里同时兼容字符串和数字,忽略无法安全转换的异常项。
|
||||
static List<int> anyListToIntList(Object? value) {
|
||||
if (value is! List) return const [];
|
||||
return value
|
||||
.map((item) {
|
||||
if (item is int) return item;
|
||||
if (item is num) return item.toInt();
|
||||
return int.tryParse(item.toString());
|
||||
})
|
||||
.whereType<int>()
|
||||
.toList(growable: false);
|
||||
}
|
||||
|
||||
static Map<String, dynamic>? anyToMap(dynamic value) {
|
||||
if (value == null) return null;
|
||||
return dynamic as Map<String, dynamic>?;
|
||||
|
||||
Reference in new issue
Block a user