集成 获取用户设备的作业列表/删除作业列表/添加作业区域
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
class ReferencePoint {
|
||||
final double lat;
|
||||
final double lon;
|
||||
|
||||
ReferencePoint({required this.lat, required this.lon});
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'lat': lat,
|
||||
'lon': lon,
|
||||
};
|
||||
}
|
||||
|
||||
class OuterBoundary {
|
||||
final List<Position> position;
|
||||
final double sideWidth;
|
||||
|
||||
OuterBoundary({required this.position, required this.sideWidth});
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'position': position.map((p) => p.toJson()).toList(),
|
||||
'sideWidth': sideWidth,
|
||||
};
|
||||
}
|
||||
|
||||
class HoleBoundary {
|
||||
final List<Position> position;
|
||||
final double sideWidth;
|
||||
|
||||
HoleBoundary({required this.position, required this.sideWidth});
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'position': position.map((p) => p.toJson()).toList(),
|
||||
'sideWidth': sideWidth,
|
||||
};
|
||||
}
|
||||
|
||||
class Position {
|
||||
final double lat;
|
||||
final double lon;
|
||||
|
||||
Position({required this.lat, required this.lon});
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'lat': lat,
|
||||
'lon': lon,
|
||||
};
|
||||
}
|
||||
@@ -3,16 +3,28 @@ import 'dart:convert';
|
||||
|
||||
import '../../domain/repositories/path_repository.dart';
|
||||
import '../models/device_add_path_point_model.dart';
|
||||
import '../models/device_work_area_param_model.dart';
|
||||
|
||||
class PathRepositoryImpl implements PathRepository {
|
||||
final String baseUrl = 'https://your-backend-api.com'; // 后端接口地址
|
||||
// 生成路径
|
||||
@override
|
||||
Future<List<DeviceAddPathPointModel>> generatePath(List<DeviceAddPathPointModel> coordinates) async {
|
||||
Future<List<DeviceAddPathPointModel>> generatePath({
|
||||
required ReferencePoint reference,
|
||||
required int heading,
|
||||
required OuterBoundary outer,
|
||||
required List<HoleBoundary> holes,
|
||||
required int workType,
|
||||
}) async {
|
||||
final url = Uri.parse('$baseUrl/api/path');
|
||||
final headers = {'Content-Type': 'application/json'};
|
||||
|
||||
final body = jsonEncode({
|
||||
'coordinates': coordinates.map((p) => p.toJson()).toList(),
|
||||
'reference': reference.toJson(),
|
||||
'heading': heading,
|
||||
'outer': outer.toJson(),
|
||||
'holes': holes.map((hole) => hole.toJson()).toList(),
|
||||
'workType': workType,
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -27,4 +39,85 @@ class PathRepositoryImpl implements PathRepository {
|
||||
throw Exception('Network error: $e');
|
||||
}
|
||||
}
|
||||
// 保存工作记录
|
||||
@override
|
||||
Future<Map<String, dynamic>> saveWorkRecord({
|
||||
required String workName,
|
||||
required String userId,
|
||||
required String jsonData,
|
||||
}) async {
|
||||
final url = Uri.parse('https://serviceri.satabot.com/iot/workRecord/add');
|
||||
final headers = {'Content-Type': 'application/json'};
|
||||
final body = jsonEncode({
|
||||
'workName': workName,
|
||||
'userId': userId,
|
||||
'jsonData': jsonData,
|
||||
});
|
||||
|
||||
try {
|
||||
final response = await http.post(url, headers: headers, body: body);
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
return data;
|
||||
} else {
|
||||
throw Exception('Save failed with status: ${response.statusCode}');
|
||||
}
|
||||
} catch (e) {
|
||||
throw Exception('Network error in saveWorkRecord: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
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(),
|
||||
});
|
||||
|
||||
try {
|
||||
final response = await http.get(url);
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
if (data['code'] == 200 && data.containsKey('data')) {
|
||||
return List<Map<String, dynamic>>.from(data['data']);
|
||||
} else {
|
||||
throw Exception('API error: ${data['msg'] ?? 'Unknown'}');
|
||||
}
|
||||
} else {
|
||||
throw Exception('HTTP ${response.statusCode}: ${response.reasonPhrase}');
|
||||
}
|
||||
} catch (e) {
|
||||
throw Exception('Network error in getWorkRecord: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
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(),
|
||||
});
|
||||
|
||||
try {
|
||||
final response = await http.get(url);
|
||||
final data = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
|
||||
if (response.statusCode == 200 && data['code'] == 200) {
|
||||
return data; // 返回 {"code": 200, "msg": "删除成功"}
|
||||
} else {
|
||||
throw Exception('Delete failed: ${data['msg'] ?? response.reasonPhrase}');
|
||||
}
|
||||
} catch (e) {
|
||||
throw Exception('Network error in deleteWorkRecord: $e');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user