package com.ruoyi.web.controller; import java.util.List; import javax.servlet.http.HttpServletResponse; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.system.domain.Routes; import com.ruoyi.system.service.IRoutesService; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.core.page.TableDataInfo; /** * 实体部署与航线Controller * * @author ruoyi * @date 2026-01-14 */ @RestController @RequestMapping("/system/routes") public class RoutesController extends BaseController { @Autowired private IRoutesService routesService; /** * 查询实体部署与航线列表 */ @PreAuthorize("@ss.hasPermi('system:routes:list')") @GetMapping("/list") public TableDataInfo list(Routes routes) { startPage(); List list = routesService.selectRoutesList(routes); return getDataTable(list); } /** * 导出实体部署与航线列表 */ @PreAuthorize("@ss.hasPermi('system:routes:export')") @Log(title = "实体部署与航线", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, Routes routes) { List list = routesService.selectRoutesList(routes); ExcelUtil util = new ExcelUtil(Routes.class); util.exportExcel(response, list, "实体部署与航线数据"); } /** * 获取实体部署与航线详细信息 */ @PreAuthorize("@ss.hasPermi('system:routes:query')") @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { return success(routesService.selectRoutesById(id)); } /** * 新增实体部署与航线 */ @PreAuthorize("@ss.hasPermi('system:routes:add')") @Log(title = "实体部署与航线", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@RequestBody Routes routes) { // 1. 执行插入,MyBatis 会通过 useGeneratedKeys="true" 自动将新 ID 注入 routes 对象 int rows = routesService.insertRoutes(routes); // 2. 不要用 toAjax,直接返回 success 并带上 routes 对象 // 这样前端 response.data 就会包含这个带有 ID 的完整对象 return rows > 0 ? AjaxResult.success(routes) : AjaxResult.error("新增航线失败"); } /** * 修改实体部署与航线 */ @PreAuthorize("@ss.hasPermi('system:routes:edit')") @Log(title = "实体部署与航线", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody Routes routes) { return toAjax(routesService.updateRoutes(routes)); } /** * 删除实体部署与航线 */ @PreAuthorize("@ss.hasPermi('system:routes:remove')") @Log(title = "实体部署与航线", businessType = BusinessType.DELETE) @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(routesService.deleteRoutesByIds(ids)); } }