对接连续任务列表接口和连续任务下发,便捷操作中暂停任务的对接,底部导航tab项的设置根据用户角色显示和设置
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import '../../domain/entities/site_task_plan.dart';
|
||||
|
||||
class SiteTaskPlanModel {
|
||||
static String _text(Object? value) => value?.toString().trim() ?? '';
|
||||
|
||||
static String? _optionalText(Object? value) {
|
||||
final text = _text(value);
|
||||
return text.isEmpty ? null : text;
|
||||
}
|
||||
|
||||
static List<String> _items(Object? value) {
|
||||
final items = value is List ? value : _text(value).split(RegExp(r'[,,、]'));
|
||||
return List.unmodifiable(items.map(_text).where((item) => item.isNotEmpty));
|
||||
}
|
||||
|
||||
static SiteTaskPlan fromJson(Map<dynamic, dynamic> json) {
|
||||
final id = int.tryParse(_text(json['id']));
|
||||
if (id == null || id <= 0) throw const FormatException('任务计划缺少有效 ID');
|
||||
final rule = json['deviceTaskPlanRules'];
|
||||
return SiteTaskPlan(
|
||||
id: id,
|
||||
name: _text(json['planName']),
|
||||
deviceId: _text(json['deviceId']),
|
||||
deviceAlias: _optionalText(json['deviceAlias']),
|
||||
// 接口沿用 taskStaus 拼写,兼容规范拼写。
|
||||
status: _text(json['taskStaus'] ?? json['taskStatus']),
|
||||
statusLabel: _text(
|
||||
json['taskStausTranslate'] ?? json['taskStatusTranslate'],
|
||||
),
|
||||
routeId: int.tryParse(_text(json['routeId'])),
|
||||
startsAt: _optionalText(json['startTime']),
|
||||
endsAt: _optionalText(json['finishTime']),
|
||||
rule: rule is Map
|
||||
? SiteTaskPlanRule(
|
||||
type: _text(rule['type']).toUpperCase(),
|
||||
time: _optionalText(rule['dayTime']),
|
||||
weekdays: _items(rule['daysTranslate']).isNotEmpty
|
||||
? _items(rule['daysTranslate'])
|
||||
: _items(rule['days']),
|
||||
monthDays: _items(rule['dayOfMonth']),
|
||||
)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user