路径规划点击 某项作业

This commit is contained in:
mmc
2026-02-28 09:55:14 +08:00
parent 4fd5877a3b
commit cf0c18f1ad
5 changed files with 276 additions and 158 deletions

View File

@@ -1,3 +1,5 @@
import 'dart:math';
import 'package:http/http.dart' as http;
import 'dart:convert';
@@ -31,7 +33,9 @@ class PathRepositoryImpl implements PathRepository {
final response = await http.post(url, headers: headers, body: body);
if (response.statusCode == 200) {
final List<dynamic> jsonData = jsonDecode(response.body)['path'];
return jsonData.map((item) => DeviceAddPathPointModel.fromJson(item)).toList();
return jsonData
.map((item) => DeviceAddPathPointModel.fromJson(item))
.toList();
} else {
throw Exception('Failed to load path: ${response.statusCode}');
}
@@ -39,6 +43,7 @@ class PathRepositoryImpl implements PathRepository {
throw Exception('Network error: $e');
}
}
// 保存工作记录
@override
Future<Map<String, dynamic>> saveWorkRecord({
@@ -68,13 +73,13 @@ class PathRepositoryImpl implements PathRepository {
}
@override
Future<List<Map<String, dynamic>>> getWorkRecord({required String userId}) async {
Future<List<Map<String, dynamic>>> getWorkRecord({
required String userId,
}) async {
final timestamp = DateTime.now().millisecondsSinceEpoch;
final url = Uri.parse('https://serviceri.satabot.com/iot/workRecord/selectByUserId')
.replace(queryParameters: {
'userId': userId,
'_t': timestamp.toString(),
});
final url = Uri.parse(
'https://serviceri.satabot.com/iot/workRecord/selectByUserId',
).replace(queryParameters: {'userId': userId, '_t': timestamp.toString()});
try {
final response = await http.get(url);
@@ -86,7 +91,9 @@ class PathRepositoryImpl implements PathRepository {
throw Exception('API error: ${data['msg'] ?? 'Unknown'}');
}
} else {
throw Exception('HTTP ${response.statusCode}: ${response.reasonPhrase}');
throw Exception(
'HTTP ${response.statusCode}: ${response.reasonPhrase}',
);
}
} catch (e) {
throw Exception('Network error in getWorkRecord: $e');
@@ -94,13 +101,16 @@ class PathRepositoryImpl implements PathRepository {
}
@override
Future<Map<String, dynamic>> deleteWorkRecord({required String workName}) async {
Future<Map<String, dynamic>> deleteWorkRecord({
required String workName,
}) async {
final timestamp = DateTime.now().millisecondsSinceEpoch;
final url = Uri.parse('https://serviceri.satabot.com/iot/workRecord/deleteByWorkName')
.replace(queryParameters: {
'workName': workName,
'_t': timestamp.toString(),
});
final url =
Uri.parse(
'https://serviceri.satabot.com/iot/workRecord/deleteByWorkName',
).replace(
queryParameters: {'workName': workName, '_t': timestamp.toString()},
);
try {
final response = await http.get(url);
@@ -109,27 +119,38 @@ class PathRepositoryImpl implements PathRepository {
if (response.statusCode == 200 && data['code'] == 200) {
return data; // 返回 {"code": 200, "msg": "删除成功"}
} else {
throw Exception('Delete failed: ${data['msg'] ?? response.reasonPhrase}');
throw Exception(
'Delete failed: ${data['msg'] ?? response.reasonPhrase}',
);
}
} catch (e) {
throw Exception('Network error in deleteWorkRecord: $e');
}
}
/// 选择工作记录
/// 选择工作记录
@override
Future<List<Map<String, dynamic>>> selectWorkRecordByName({required String workName}) async {
Future<List<Map<String, dynamic>>> selectWorkRecordByName({
required String workName,
}) async {
final timestamp = DateTime.now().millisecondsSinceEpoch;
final url = Uri.parse('https://serviceri.satabot.com/iot/workRecord/selectByWorkname')
.replace(queryParameters: {
'workName': workName,
'_t': timestamp.toString(), // 防缓存
});
final url =
Uri.parse(
'https://serviceri.satabot.com/iot/workRecord/selectByWorkname',
).replace(
queryParameters: {
'workName': workName,
'_t': timestamp.toString(), // 防缓存
},
);
print('请求URL: $url'); // 调试输出完整URL,检查参数是否正确附加
try {
final response = await http.get(url);
if (response.statusCode == 200) {
final data = jsonDecode(response.body) as Map<String, dynamic>;
print('响应数据: $data'); // 调试输出响应数据,检查结构和内容
if (data['code'] == 200 && data.containsKey('data')) {
final List<dynamic> records = data['data'];
@@ -138,15 +159,12 @@ class PathRepositoryImpl implements PathRepository {
throw Exception('API error: ${data['msg'] ?? 'Unknown'}');
}
} else {
throw Exception('HTTP ${response.statusCode}: ${response.reasonPhrase}');
throw Exception(
'HTTP ${response.statusCode}: ${response.reasonPhrase}',
);
}
} catch (e) {
throw Exception('Network error in selectWorkRecordByName: $e');
}
}
}

View File

@@ -8,7 +8,10 @@ class SelectWorkRecordUseCase {
SelectWorkRecordUseCase(this.repository);
Future<Either<DeviceFailure, List<Map<String, dynamic>>>> call(String workName) async {
Future<Either<DeviceFailure, List<Map<String, dynamic>>>> call(
String workName,
) async {
print('SelectWorkRecordUseCase called with workName: $workName'); // 调试输出
try {
final data = await repository.selectWorkRecordByName(workName: workName);
return Right(data);

View File

@@ -30,7 +30,7 @@ class DevicesCubit extends Cubit<DevicesState> {
this._deleteWorkRecordUseCase,
this._unbindDeviceUseCase,
this._updateDevicename,
this._selectWorkRecordUseCase
this._selectWorkRecordUseCase,
) : super(const DevicesState());
Future<void> unbindDevice(String deviceId, String deviceName) async {
@@ -86,7 +86,11 @@ class DevicesCubit extends Cubit<DevicesState> {
);
} catch (e) {
emit(
state.copyWith(isLoading: false, errorMessage: '解绑异常:${e.toString()}', operationType: DeviceOperationType.none),
state.copyWith(
isLoading: false,
errorMessage: '解绑异常:${e.toString()}',
operationType: DeviceOperationType.none,
),
);
}
}
@@ -262,18 +266,20 @@ class DevicesCubit extends Cubit<DevicesState> {
),
);
}
/// 加载指定作业名的路径数据
Future<void> loadSelectedPath(String workName) async {
emit(state.copyWith(isLoading: true));
try {
final result = await _selectWorkRecordUseCase.call(workName);
result.fold(
(failure) => emit(state.copyWith(isLoading: false, errorMessage: failure.message)),
(data) => emit(state.copyWith(isLoading: false, pathData: data)),
(failure) => emit(
state.copyWith(isLoading: false, errorMessage: failure.message),
),
(data) => emit(state.copyWith(isLoading: false, pathData: data)),
);
} catch (e) {
emit(state.copyWith(isLoading: false, errorMessage: e.toString()));
}
}
}