zjb 3 weeks ago
parent 15e1732793
commit b5a3409897

@ -1,4 +1,4 @@
#Sun Jul 13 00:33:51 CST 2025
#Sun Jul 13 00:54:46 CST 2025
base.0=D\:\\softwaregit\\AIDAP\\Src\\UAV\\DroneRecognitionApp\\app\\build\\intermediates\\dex\\debug\\mergeExtDexDebug\\classes.dex
base.1=D\:\\softwaregit\\AIDAP\\Src\\UAV\\DroneRecognitionApp\\app\\build\\intermediates\\dex\\debug\\mergeProjectDexDebug\\0\\classes.dex
base.2=D\:\\softwaregit\\AIDAP\\Src\\UAV\\DroneRecognitionApp\\app\\build\\intermediates\\dex\\debug\\mergeProjectDexDebug\\14\\classes.dex

@ -1384,68 +1384,64 @@ public class MapFragment extends Fragment {
*
*/
private void saveAndSendRoutes(List<RouteData> routes) {
// 这里需要获取当前选中的敌人和驻扎点信息
// 由于路径规划是在特定上下文中进行的,我们需要保存这些信息
if (currentPlannedRoutes != null && !currentPlannedRoutes.isEmpty()) {
// 显示任务创建对话框
showCreateMissionDialog(routes);
try {
// 直接发送路径规划消息给驻扎点用户,不创建新任务
sendRouteMessageDirectly(routes);
Toast.makeText(requireContext(), "✅ 路径已发送", Toast.LENGTH_LONG).show();
} catch (Exception e) {
Log.e("MapFragment", "发送路径失败", e);
Toast.makeText(requireContext(), "❌ 发送路径失败: " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(requireContext(), "没有可保存的路径数据", Toast.LENGTH_SHORT).show();
}
}
/**
*
*
*/
private void showCreateMissionDialog(List<RouteData> routes) {
View dialogView = getLayoutInflater().inflate(R.layout.dialog_new_mission, null);
EditText etMissionName = dialogView.findViewById(R.id.etMissionName);
EditText etMissionDescription = dialogView.findViewById(R.id.etMissionDescription);
// 设置默认任务名称
etMissionName.setText("路径规划任务 - " + getCurrentTime());
new AlertDialog.Builder(requireContext())
.setTitle("📋 创建新任务")
.setView(dialogView)
.setPositiveButton("✅ 创建", (dialog, which) -> {
String missionName = etMissionName.getText().toString().trim();
String missionDescription = etMissionDescription.getText().toString().trim();
if (missionName.isEmpty()) {
Toast.makeText(requireContext(), "请输入任务名称", Toast.LENGTH_SHORT).show();
private void sendRouteMessageDirectly(List<RouteData> routes) {
if (!sessionManager.isCommander() || routes.isEmpty()) {
return;
}
// 创建任务并保存路径
createMissionAndSaveRoutes(missionName, missionDescription, routes);
})
.setNegativeButton("❌ 取消", null)
.show();
}
// 创建路径规划消息
RouteMessage routeMessage = new RouteMessage();
routeMessage.setCommanderName(sessionManager.getCurrentUserRealName());
routeMessage.setCommanderId(sessionManager.getCurrentUserId());
routeMessage.setMissionName("路径规划任务 - " + getCurrentTime());
routeMessage.setMissionDescription("指挥员规划的路径任务");
routeMessage.setMissionId(0); // 临时任务ID
routeMessage.setRoutes(routes);
/**
*
*/
private void createMissionAndSaveRoutes(String missionName, String missionDescription, List<RouteData> routes) {
try {
// 获取当前选中的敌人(这里需要根据实际情况获取)
// 暂时使用一个默认的敌人ID实际应用中应该从当前上下文中获取
long enemyId = 1; // 临时值,需要根据实际情况修改
// 设置目标位置(使用路径的终点)
if (!routes.isEmpty() && routes.get(0).getRoutePoints() != null && !routes.get(0).getRoutePoints().isEmpty()) {
List<LatLng> points = routes.get(0).getRoutePoints();
LatLng endPoint = points.get(points.size() - 1);
routeMessage.setTargetEnemyLocation(String.format("%.6f, %.6f", endPoint.latitude, endPoint.longitude));
} else {
routeMessage.setTargetEnemyLocation("未知位置");
}
// 创建任务
long missionId = databaseHelper.insertMission(missionName, missionDescription, enemyId, new ArrayList<>());
// 获取目标驻扎点名称列表
List<String> targetBaseStations = new ArrayList<>();
for (RouteData route : routes) {
BaseStationData baseStation = databaseHelper.getBaseStationById(route.getBaseStationId());
if (baseStation != null) {
targetBaseStations.add(baseStation.getName());
}
}
routeMessage.setTargetBaseStations(targetBaseStations);
// 保存路径
saveRoutes(missionId, null, getBaseStationIdsFromRoutes(routes));
// 发送路径规划消息
RouteCommunicationService routeCommService = RouteCommunicationService.getInstance(requireContext());
routeCommService.sendRoute(routeMessage);
}
Toast.makeText(requireContext(), "✅ 任务创建成功,路径已发送", Toast.LENGTH_LONG).show();
} catch (Exception e) {
Log.e("MapFragment", "创建任务失败", e);
Toast.makeText(requireContext(), "❌ 创建任务失败: " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
/**
* ID

Loading…
Cancel
Save