You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
5.3 KiB
148 lines
5.3 KiB
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;
|
|
import com.ruoyi.system.domain.dto.PlatformStyleDTO;
|
|
import com.alibaba.fastjson2.JSON;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
/**
|
|
* 实体部署与航线Controller
|
|
*
|
|
* @author ruoyi
|
|
* @date 2026-01-14
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/system/routes")
|
|
public class RoutesController extends BaseController
|
|
{
|
|
@Autowired
|
|
private IRoutesService routesService;
|
|
|
|
@Autowired
|
|
private RedisTemplate<String, Object> redisTemplate;
|
|
|
|
/**
|
|
* 保存平台样式到 Redis
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('system:routes:edit')")
|
|
@PostMapping("/savePlatformStyle")
|
|
public AjaxResult savePlatformStyle(@RequestBody PlatformStyleDTO dto)
|
|
{
|
|
if (dto.getRoomId() == null || dto.getRouteId() == null || dto.getPlatformId() == null) {
|
|
return AjaxResult.error("参数不完整");
|
|
}
|
|
String key = "room:" + dto.getRoomId() + ":route:" + dto.getRouteId() + ":platforms";
|
|
redisTemplate.opsForHash().put(key, String.valueOf(dto.getPlatformId()), JSON.toJSONString(dto));
|
|
return success();
|
|
}
|
|
|
|
/**
|
|
* 从 Redis 获取平台样式
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('system:routes:query')")
|
|
@GetMapping("/getPlatformStyle")
|
|
public AjaxResult getPlatformStyle(PlatformStyleDTO dto)
|
|
{
|
|
if (dto.getRoomId() == null || dto.getRouteId() == null || dto.getPlatformId() == null) {
|
|
return AjaxResult.error("参数不完整");
|
|
}
|
|
String key = "room:" + dto.getRoomId() + ":route:" + dto.getRouteId() + ":platforms";
|
|
Object val = redisTemplate.opsForHash().get(key, String.valueOf(dto.getPlatformId()));
|
|
if (val != null) {
|
|
return success(JSON.parseObject(val.toString(), PlatformStyleDTO.class));
|
|
}
|
|
return success();
|
|
}
|
|
|
|
/**
|
|
* 查询实体部署与航线列表
|
|
*/
|
|
@PreAuthorize("@ss.hasPermi('system:routes:list')")
|
|
@GetMapping("/list")
|
|
public TableDataInfo list(Routes routes)
|
|
{
|
|
startPage();
|
|
List<Routes> 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<Routes> list = routesService.selectRoutesList(routes);
|
|
ExcelUtil<Routes> util = new ExcelUtil<Routes>(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));
|
|
}
|
|
}
|
|
|