126 lines
3.4 KiB
Dart
126 lines
3.4 KiB
Dart
|
|
class StaffProfile {
|
||
|
|
const StaffProfile({
|
||
|
|
required this.identity,
|
||
|
|
required this.name,
|
||
|
|
required this.phone,
|
||
|
|
required this.roleCode,
|
||
|
|
required this.workStatus,
|
||
|
|
});
|
||
|
|
|
||
|
|
final String identity;
|
||
|
|
final String name;
|
||
|
|
final String phone;
|
||
|
|
final String roleCode;
|
||
|
|
final String workStatus;
|
||
|
|
|
||
|
|
factory StaffProfile.fromJson(Map<String, Object?> json) => StaffProfile(
|
||
|
|
identity: json['identity'] as String? ?? '',
|
||
|
|
name: json['name'] as String? ?? '',
|
||
|
|
phone: json['phone'] as String? ?? '',
|
||
|
|
roleCode: json['role_code'] as String? ?? '',
|
||
|
|
workStatus: json['work_status'] as String? ?? 'off_duty',
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
class PreflightResult {
|
||
|
|
const PreflightResult({
|
||
|
|
required this.roleCode,
|
||
|
|
required this.workStatus,
|
||
|
|
required this.canWork,
|
||
|
|
required this.checks,
|
||
|
|
});
|
||
|
|
|
||
|
|
final String roleCode;
|
||
|
|
final String workStatus;
|
||
|
|
final bool canWork;
|
||
|
|
final Map<String, Object?> checks;
|
||
|
|
|
||
|
|
factory PreflightResult.fromJson(Map<String, Object?> json) => PreflightResult(
|
||
|
|
roleCode: json['role_code'] as String? ?? '',
|
||
|
|
workStatus: json['work_status'] as String? ?? 'off_duty',
|
||
|
|
canWork: json['can_work'] as bool? ?? false,
|
||
|
|
checks: _map(json['checks']),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
class WorkItem {
|
||
|
|
const WorkItem({
|
||
|
|
required this.identity,
|
||
|
|
required this.number,
|
||
|
|
required this.title,
|
||
|
|
required this.address,
|
||
|
|
required this.status,
|
||
|
|
required this.allowedActions,
|
||
|
|
required this.raw,
|
||
|
|
});
|
||
|
|
|
||
|
|
final String identity;
|
||
|
|
final String number;
|
||
|
|
final String title;
|
||
|
|
final String address;
|
||
|
|
final int status;
|
||
|
|
final List<String> allowedActions;
|
||
|
|
final Map<String, Object?> raw;
|
||
|
|
|
||
|
|
factory WorkItem.delivery(Map<String, Object?> json) => WorkItem(
|
||
|
|
identity: json['identity'] as String? ?? '',
|
||
|
|
number: json['order_no'] as String? ?? '',
|
||
|
|
title: '燃气配送',
|
||
|
|
address: json['address'] as String? ?? '',
|
||
|
|
status: (json['order_status'] as num?)?.toInt() ?? 0,
|
||
|
|
allowedActions: (json['allowed_actions'] as List? ?? const [])
|
||
|
|
.map((item) => item.toString())
|
||
|
|
.toList(growable: false),
|
||
|
|
raw: json,
|
||
|
|
);
|
||
|
|
|
||
|
|
factory WorkItem.ticket(Map<String, Object?> json) => WorkItem(
|
||
|
|
identity: json['identity'] as String? ?? '',
|
||
|
|
number: json['ticket_no'] as String? ?? '',
|
||
|
|
title: _ticketTitle(json['category'] as String? ?? ''),
|
||
|
|
address: json['address'] as String? ?? '',
|
||
|
|
status: (json['ticket_status'] as num?)?.toInt() ?? 0,
|
||
|
|
allowedActions: _ticketActions((json['ticket_status'] as num?)?.toInt() ?? 0),
|
||
|
|
raw: json,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
Map<String, Object?> _map(Object? value) {
|
||
|
|
if (value is Map<String, Object?>) return value;
|
||
|
|
if (value is Map) return value.map((key, item) => MapEntry(key.toString(), item));
|
||
|
|
return const {};
|
||
|
|
}
|
||
|
|
|
||
|
|
String _ticketTitle(String category) => switch (category) {
|
||
|
|
'installation' => '安装任务',
|
||
|
|
'repair' => '维修任务',
|
||
|
|
'inspection' => '安全检查',
|
||
|
|
'reinspection' => '复检任务',
|
||
|
|
_ => '服务任务',
|
||
|
|
};
|
||
|
|
|
||
|
|
List<String> _ticketActions(int status) => switch (status) {
|
||
|
|
18 => const ['start'],
|
||
|
|
11 => const ['submit_result', 'exception'],
|
||
|
|
21 => const ['recover'],
|
||
|
|
_ => const [],
|
||
|
|
};
|
||
|
|
|
||
|
|
String roleName(String role) => switch (role) {
|
||
|
|
'delivery' => '配送员',
|
||
|
|
'installer' => '安装维修员',
|
||
|
|
'operations' => '安检员',
|
||
|
|
_ => '工作人员',
|
||
|
|
};
|
||
|
|
|
||
|
|
String statusName(int status) => switch (status) {
|
||
|
|
11 => '处理中',
|
||
|
|
18 => '已分派',
|
||
|
|
20 => '已就绪',
|
||
|
|
21 => '异常',
|
||
|
|
23 => '已完成',
|
||
|
|
33 => '配送中',
|
||
|
|
34 => '待确认',
|
||
|
|
_ => '状态 $status',
|
||
|
|
};
|