空洞逻辑

This commit is contained in:
mmc
2026-03-02 13:25:21 +08:00
parent 991c4fe174
commit fe9b763783
4 changed files with 300 additions and 168 deletions

View File

@@ -15,6 +15,33 @@ class PathHttpDatasourceImpl implements PathHttpDatasource {
@override
Future<List<DeviceAddPathPointModel>> generatePathRaw({required Map<String, dynamic> body}) async {
try {
// 1. 先打印基础信息
print('=== 最终发送给后端的请求体 ===');
print('请求体类型:${body.runtimeType}');
print('是否包含holes:${body.containsKey('holes')}, holes长度:${(body['holes'] as List).length}');
// 2. 格式化打印JSON(带缩进,清晰展示嵌套结构)
final jsonString = const JsonEncoder.withIndent(' ').convert(body);
print('完整JSON请求体:\n$jsonString');
// 3. 可选:单独打印holes的JSON(重点关注)
final holesJson = body['holes'] as List;
print('=== 单独打印holes的JSON ===');
if (holesJson.isEmpty) {
print('holes 为空数组');
} else {
for (int i = 0; i < holesJson.length; i++) {
print('第${i + 1}组hole:\n${const JsonEncoder.withIndent(' ').convert(holesJson[i])}');
}
}
} catch (e) {
// 防止JSON序列化失败导致崩溃
print('打印请求体失败:$e');
// 降级打印原始body(虽然格式乱,但能看基础数据)
print('原始body数据:$body');
}
final token = (await _userStorage.getUser())?.token;
if (token == null) throw Exception('Token missing');
@@ -23,7 +50,6 @@ class PathHttpDatasourceImpl implements PathHttpDatasource {
headers: {'Content-Type': 'application/json', 'Authorization': token},
body: jsonEncode(body),
);
//debugPrint('请求体: ${jsonEncode(body)}');
// 🔥 完整打印响应体
//printFullString(formatJson(jsonEncode(response.body)));

View File

@@ -12,9 +12,7 @@ import '../models/device_work_area_param_model.dart';
class PathRepositoryImpl implements PathRepository {
final PathHttpDatasource _datasource;
PathRepositoryImpl({
required PathHttpDatasource datasource,
}) : _datasource = datasource;
PathRepositoryImpl({required PathHttpDatasource datasource}) : _datasource = datasource;
// 生成路径
@override
Future<List<DeviceAddPathPointModel>> generatePath({
@@ -28,11 +26,11 @@ class PathRepositoryImpl implements PathRepository {
'reference': reference.toJson(),
'heading': heading,
'outer': outer.toJson(),
'holes': holes.map((h) => h.toJson()).toList(),
'holes': holes.map((hole) => hole.toJson()).toList(),
'workType': workType,
};
return await _datasource.generatePathRaw(body: body);
return await _datasource.generatePathRaw(body: body);
}
// 保存工作记录