diff --git a/ruoyi-admin/src/main/resources/application-druid.yml b/ruoyi-admin/src/main/resources/application-druid.yml index c40f2aa..037db5c 100644 --- a/ruoyi-admin/src/main/resources/application-druid.yml +++ b/ruoyi-admin/src/main/resources/application-druid.yml @@ -8,7 +8,7 @@ spring: master: url: jdbc:mysql://localhost:3306/ry?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 username: root - password: A20040303ctw! + password: 123456 # 从库数据源 slave: # 从数据源开关/默认关闭 diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/RouteWaypointsMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/RouteWaypointsMapper.java index 2e77e10..07ff430 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/RouteWaypointsMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/RouteWaypointsMapper.java @@ -55,6 +55,14 @@ public interface RouteWaypointsMapper public int deleteRouteWaypointsById(Long id); /** + * 删除航线具体航点明细 + * + * @param routeId 航线主键 + * @return 结果 + */ + public int deleteRouteWaypointsByRouteId(Long routeId); + + /** * 批量删除航线具体航点明细 * * @param ids 需要删除的数据主键集合 diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IRouteWaypointsService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IRouteWaypointsService.java index fc046e8..3e74e8d 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IRouteWaypointsService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IRouteWaypointsService.java @@ -58,4 +58,12 @@ public interface IRouteWaypointsService * @return 结果 */ public int deleteRouteWaypointsById(Long id); + + /** + * 删除航线具体航点明细信息 + * + * @param routeId 航线具体航点明细主键 + * @return 结果 + */ + public int deleteRouteWaypointsByRouteId(Long routeId); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/MissionScenarioServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/MissionScenarioServiceImpl.java index 600effa..ed72252 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/MissionScenarioServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/MissionScenarioServiceImpl.java @@ -1,11 +1,15 @@ package com.ruoyi.system.service.impl; import java.util.List; + +import com.ruoyi.system.domain.Routes; +import com.ruoyi.system.service.IRoutesService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.system.mapper.MissionScenarioMapper; import com.ruoyi.system.domain.MissionScenario; import com.ruoyi.system.service.IMissionScenarioService; +import org.springframework.transaction.annotation.Transactional; /** * 任务方案/沙箱Service业务层处理 @@ -19,6 +23,9 @@ public class MissionScenarioServiceImpl implements IMissionScenarioService @Autowired private MissionScenarioMapper missionScenarioMapper; + @Autowired + private IRoutesService routesService; + /** * 查询任务方案/沙箱 * @@ -74,9 +81,15 @@ public class MissionScenarioServiceImpl implements IMissionScenarioService * @return 结果 */ @Override + @Transactional public int deleteMissionScenarioByIds(Long[] ids) { - return missionScenarioMapper.deleteMissionScenarioByIds(ids); + int rows = 0; + for (Long id : ids) { + // 循环调用单条删除逻辑,确保每套方案下的从属数据都被清理干净 + rows += this.deleteMissionScenarioById(id); + } + return rows; } /** @@ -86,8 +99,19 @@ public class MissionScenarioServiceImpl implements IMissionScenarioService * @return 结果 */ @Override + @Transactional public int deleteMissionScenarioById(Long id) { + // 查找属于该方案的所有航线 + Routes queryRoute = new Routes(); + queryRoute.setScenarioId(id); + List relatedRoutes = routesService.selectRoutesList(queryRoute); + // 循环删除每一条航线 + if (relatedRoutes != null) { + for (Routes route : relatedRoutes) { + routesService.deleteRoutesById(route.getId()); + } + } return missionScenarioMapper.deleteMissionScenarioById(id); } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RouteWaypointsServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RouteWaypointsServiceImpl.java index fbc0848..63be94c 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RouteWaypointsServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RouteWaypointsServiceImpl.java @@ -101,4 +101,9 @@ public class RouteWaypointsServiceImpl implements IRouteWaypointsService { return routeWaypointsMapper.deleteRouteWaypointsById(id); } + + @Override + public int deleteRouteWaypointsByRouteId(Long routeId) { + return routeWaypointsMapper.deleteRouteWaypointsByRouteId(routeId); + } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RoutesServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RoutesServiceImpl.java index b3ee040..e106817 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RoutesServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/RoutesServiceImpl.java @@ -109,9 +109,17 @@ public class RoutesServiceImpl implements IRoutesService * @return 结果 */ @Override + @Transactional public int deleteRoutesByIds(Long[] ids) { - return routesMapper.deleteRoutesByIds(ids); + int rows = 0; + for (Long id : ids) { + // 1. 清理航点 + routeWaypointsService.deleteRouteWaypointsByRouteId(id); + // 2. 累加删除航线的行数 + rows += routesMapper.deleteRoutesById(id); + } + return rows; } /** @@ -121,8 +129,10 @@ public class RoutesServiceImpl implements IRoutesService * @return 结果 */ @Override + @Transactional public int deleteRoutesById(Long id) { + routeWaypointsService.deleteRouteWaypointsByRouteId(id); return routesMapper.deleteRoutesById(id); } } diff --git a/ruoyi-system/src/main/resources/mapper/system/RouteWaypointsMapper.xml b/ruoyi-system/src/main/resources/mapper/system/RouteWaypointsMapper.xml index f6209fb..7ccc118 100644 --- a/ruoyi-system/src/main/resources/mapper/system/RouteWaypointsMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/RouteWaypointsMapper.xml @@ -91,6 +91,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" delete from route_waypoints where id = #{id} + + delete from route_waypoints where route_id = #{routeId} + + delete from route_waypoints where id in diff --git a/ruoyi-ui/src/views/childRoom/RightPanel.vue b/ruoyi-ui/src/views/childRoom/RightPanel.vue index a377ed9..8bf4f5e 100644 --- a/ruoyi-ui/src/views/childRoom/RightPanel.vue +++ b/ruoyi-ui/src/views/childRoom/RightPanel.vue @@ -83,6 +83,7 @@
+
@@ -103,7 +104,7 @@
- +
@@ -251,6 +252,10 @@ export default { type: String, default: 'plan' }, + plans: { + type: Array, + default: () => [] + }, routes: { type: Array, default: () => [] @@ -258,7 +263,7 @@ export default { activeRouteIds: { type: Array, default: () => [] - }, + }, selectedPlanId: { type: [String, Number], default: null diff --git a/ruoyi-ui/src/views/childRoom/index.vue b/ruoyi-ui/src/views/childRoom/index.vue index 63e6ab0..b522d75 100644 --- a/ruoyi-ui/src/views/childRoom/index.vue +++ b/ruoyi-ui/src/views/childRoom/index.vue @@ -125,6 +125,7 @@ @select-route="selectRoute" @create-plan="createPlan" @create-route="createRoute" + @delete-route="handleDeleteRoute" @open-plan-dialog="openPlanDialog" @open-route-dialog="openRouteDialog" @open-waypoint-dialog="openWaypointDialog" @@ -270,7 +271,7 @@ import LeftMenu from './LeftMenu' import RightPanel from './RightPanel' import BottomLeftPanel from './BottomLeftPanel' import TopHeader from './TopHeader' -import { listRoutes, getRoutes, addRoutes } from "@/api/system/routes"; +import { listRoutes, getRoutes, addRoutes,delRoutes } from "@/api/system/routes"; import { updateWaypoints } from "@/api/system/waypoints"; export default { name: 'MissionPlanningView', @@ -546,7 +547,36 @@ export default { this.$refs.cesiumMap.startMissionRouteDrawing(); this.$message.success('进入航线规划模式'); } - + }, + async handleDeleteRoute(route) { + try { + // 二次确认,防止误删 + await this.$confirm(`确定要彻底删除航线 "${route.name}" 吗?`, '提示', { + type: 'warning' + }); + if (this.selectedRouteDetails && this.selectedRouteDetails.id === route.id) { + this.selectedRouteDetails = null; + } + const res = await delRoutes(route.id); + if (res.code === 200) { + this.$message.success('删除成功'); + // 同步地图:如果该航线正在显示,立即清除 + if (this.$refs.cesiumMap) { + this.$refs.cesiumMap.removeRouteById(route.id); + } + // 同步状态:从选中列表中移除该 ID + const idx = this.activeRouteIds.indexOf(route.id); + if (idx > -1) { + this.activeRouteIds.splice(idx, 1); + } + await this.getList(); + } + } catch (e) { + if (e !== 'cancel') { + console.error("删除航线失败:", e); + this.$message.error('删除操作失败'); + } + } }, /** 从数据库拉取最新的航线列表数据 */ async getList() { @@ -581,10 +611,16 @@ export default { this.$message.error('新增航线未命名,请输入名称后保存!'); return; } + // 获取当前选中的方案 ID + const currentScenarioId = this.selectedPlanId; + if (!currentScenarioId) { + this.$message.warning('请先在左侧选择一个方案,再保存航线!'); + return; + } // 构造符合后端 Routes 实体类的数据结构 const routeData = { callSign: this.newRouteName, - scenarioId: 1, // 示例:当前归属方案ID(实际应从全局状态获取) + scenarioId: currentScenarioId, platformId: 1, attributes: "{}", waypoints: this.tempMapPoints.map((p, index) => ({ @@ -602,7 +638,27 @@ export default { // 调用后端 API 保存到数据库 const response = await addRoutes(routeData); if (response.code === 200) { - this.$message.success('航线及其航点已成功保存至数据库'); + this.$message.success('航线及其航点已成功保存至当前方案'); + // 获取后端生成的正式 ID + const savedRoute = response.data; + const newRouteId = savedRoute ? savedRoute.id : null; + if (this.$refs.cesiumMap) { + this.$refs.cesiumMap.clearRoute(); + // 如果拿到了正式 ID,则按照“正式航线”的规则渲染一次 + if (newRouteId) { + if (!this.activeRouteIds.includes(savedRoute.id)) { + this.activeRouteIds.push(savedRoute.id); + } + // 更新当前详情,确保右侧下方航点列表立刻显示 + this.selectedRouteDetails = { + id: newRouteId, + name: this.newRouteName, + waypoints: routeData.waypoints + }; + //使用正式 ID 渲染点和线 + this.$refs.cesiumMap.renderRouteWaypoints(routeData.waypoints, newRouteId); + } + } // 重置 UI 状态 this.showNameDialog = false; this.drawDom = false; @@ -1108,7 +1164,6 @@ export default { /** 切换航线:实现多选/开关逻辑 */ async selectRoute(route) { const index = this.activeRouteIds.indexOf(route.id); - // 航线已在选中列表中 if (index > -1) { this.activeRouteIds.splice(index, 1);