对接连续任务列表接口和连续任务下发,便捷操作中暂停任务的对接,底部导航tab项的设置根据用户角色显示和设置
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import 'dart:convert';
|
||||
import 'package:dio/dio.dart';
|
||||
import '../../../../core/consts/http_api_consts.dart';
|
||||
import '../../../../core/logging/i_logger_service.dart';
|
||||
import '../../domain/entities/work_history_record.dart';
|
||||
import '../models/work_history_model.dart';
|
||||
|
||||
class WorkHistoryRemoteDatasource {
|
||||
WorkHistoryRemoteDatasource(this.dio, this.logger);
|
||||
final Dio dio;
|
||||
final ILoggerService logger;
|
||||
|
||||
Future<WorkHistoryPage> load({
|
||||
required int siteId,
|
||||
required int orgId,
|
||||
required int pageNum,
|
||||
required int pageSize,
|
||||
}) async {
|
||||
final body = {
|
||||
'siteId': siteId,
|
||||
'orgId': orgId,
|
||||
'pageNum': pageNum,
|
||||
'pageSize': pageSize,
|
||||
};
|
||||
final url = HttpApiConsts.siteDeviceTaskHistory;
|
||||
final clock = Stopwatch()..start();
|
||||
logger.logWithLevel(
|
||||
'[作业记录] 请求: POST $url, 参数: ${jsonEncode(body)}',
|
||||
shouldLog: true,
|
||||
);
|
||||
try {
|
||||
final response = await dio.post(url, data: body);
|
||||
final data = response.data;
|
||||
if (response.statusCode != 200 ||
|
||||
data is! Map ||
|
||||
'${data['code']}' != '200') {
|
||||
throw Exception(data is Map ? data['msg'] ?? '作业记录查询失败' : '作业记录响应格式错误');
|
||||
}
|
||||
final rows = data['rows'];
|
||||
final total = int.tryParse('${data['total']}');
|
||||
if (rows is! List || total == null || total < 0) {
|
||||
throw const FormatException('作业记录响应缺少有效 rows 或 total');
|
||||
}
|
||||
final records = <int, WorkHistoryRecord>{};
|
||||
for (final row in rows) {
|
||||
if (row is! Map) throw const FormatException('作业记录行格式错误');
|
||||
if (row['delFlag'] == true ||
|
||||
row['delFlag'] == 1 ||
|
||||
row['delFlag'] == '1')
|
||||
continue;
|
||||
final record = WorkHistoryModel.fromJson(
|
||||
Map<String, dynamic>.from(row),
|
||||
);
|
||||
if (record.siteId != null && record.siteId != siteId) continue;
|
||||
if (record.orgId != null && record.orgId != orgId) continue;
|
||||
records[record.id] = record;
|
||||
}
|
||||
final sorted = records.values.toList()
|
||||
..sort((a, b) {
|
||||
final dateOrder = (b.recordDate ?? DateTime(1970)).compareTo(
|
||||
a.recordDate ?? DateTime(1970),
|
||||
);
|
||||
return dateOrder != 0 ? dateOrder : b.id.compareTo(a.id);
|
||||
});
|
||||
logger.logWithLevel(
|
||||
'[作业记录] 响应: HTTP ${response.statusCode}, code=${data['code']}, msg=${data['msg']}, total=$total, rows=${rows.length}, 当前场站有效记录=${sorted.length}, 耗时=${clock.elapsedMilliseconds}ms',
|
||||
shouldLog: true,
|
||||
);
|
||||
return WorkHistoryPage(total: total, records: sorted);
|
||||
} catch (error) {
|
||||
logger.logWithLevel(
|
||||
'[作业记录] 异常: $error, 参数: ${jsonEncode(body)}',
|
||||
shouldLog: true,
|
||||
);
|
||||
rethrow;
|
||||
} finally {
|
||||
clock.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import '../../domain/entities/work_history_record.dart';
|
||||
|
||||
class WorkHistoryModel {
|
||||
static int? _int(dynamic value) => int.tryParse('$value');
|
||||
static String? _text(dynamic value) {
|
||||
final text = value?.toString().trim();
|
||||
return text == null || text.isEmpty ? null : text;
|
||||
}
|
||||
|
||||
static WorkHistoryRecord fromJson(Map<String, dynamic> json) {
|
||||
final id = _int(json['id']);
|
||||
if (id == null || id <= 0) throw const FormatException('作业历史缺少有效任务 ID');
|
||||
final accepted = json['taskAccepted'];
|
||||
return WorkHistoryRecord(
|
||||
id: id,
|
||||
deviceId: _text(json['deviceId']) ?? '',
|
||||
deviceAlias: _text(json['deviceAlias']),
|
||||
workName: _text(json['workName']) ?? '',
|
||||
// 后端原字段为 taskStaus(缺少 t),优先按真实接口解析。
|
||||
status: _text(json['taskStaus'] ?? json['taskStatus']) ?? '',
|
||||
statusLabel:
|
||||
_text(json['taskStausTranslate'] ?? json['taskStatusTranslate']) ??
|
||||
'',
|
||||
siteId: _int(json['siteId']),
|
||||
orgId: _int(json['orgId']),
|
||||
planId: _int(json['planId']),
|
||||
routeId: _int(json['routeId']),
|
||||
createdAt: _text(json['createTime']),
|
||||
updatedAt: _text(json['updateTime']),
|
||||
startedAt: _text(json['startTime']),
|
||||
finishedAt: _text(json['finishTime']),
|
||||
taskType: _text(json['taskType']),
|
||||
routeType: _text(json['routeType']),
|
||||
remark: _text(json['remark']),
|
||||
accepted: accepted is bool
|
||||
? accepted
|
||||
: accepted == 1 || accepted == '1'
|
||||
? true
|
||||
: accepted == 0 || accepted == '0'
|
||||
? false
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import '../../../../core/error/failure.dart';
|
||||
import '../../domain/entities/work_history_record.dart';
|
||||
import '../../domain/repositories/work_history_repository.dart';
|
||||
import '../datasources/work_history_remote_datasource.dart';
|
||||
|
||||
class WorkHistoryRepositoryImpl implements WorkHistoryRepository {
|
||||
WorkHistoryRepositoryImpl(this.remote);
|
||||
final WorkHistoryRemoteDatasource remote;
|
||||
|
||||
@override
|
||||
Future<Either<Failure, WorkHistoryPage>> load({
|
||||
required int siteId,
|
||||
required int orgId,
|
||||
required int pageNum,
|
||||
required int pageSize,
|
||||
}) async {
|
||||
try {
|
||||
return Right(
|
||||
await remote.load(
|
||||
siteId: siteId,
|
||||
orgId: orgId,
|
||||
pageNum: pageNum,
|
||||
pageSize: pageSize,
|
||||
),
|
||||
);
|
||||
} catch (error) {
|
||||
return Left(Failure(error.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user