211 lines
6.7 KiB
Java
211 lines
6.7 KiB
Java
package com.ruoyi.device.controller;
|
||
|
||
import com.ruoyi.common.core.domain.R;
|
||
import com.ruoyi.common.core.web.controller.BaseController;
|
||
import com.ruoyi.device.api.domain.*;
|
||
import com.ruoyi.device.controller.convert.DockVOConvert;
|
||
import com.ruoyi.device.controller.convert.DockWithGPSVOConvert;
|
||
import com.ruoyi.device.controller.convert.GroupVOConvert;
|
||
import com.ruoyi.device.domain.api.IDockDomain;
|
||
import com.ruoyi.device.domain.model.Dock;
|
||
import com.ruoyi.device.service.impl.DefaultBufferDeviceImpl;
|
||
import com.ruoyi.device.service.api.IGroupService;
|
||
import com.ruoyi.device.service.dto.DockDetailDTO;
|
||
import com.ruoyi.device.service.dto.DockGroupDTO;
|
||
import com.ruoyi.device.service.dto.GroupDTO;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.util.CollectionUtils;
|
||
import org.springframework.web.bind.annotation.*;
|
||
|
||
import java.util.*;
|
||
|
||
/**
|
||
* 分组Controller
|
||
*
|
||
* @author ruoyi
|
||
* @date 2026-01-20
|
||
*/
|
||
@RestController
|
||
@RequestMapping("/group")
|
||
public class GroupController extends BaseController
|
||
{
|
||
@Autowired
|
||
private IGroupService groupService;
|
||
|
||
@Autowired
|
||
private DefaultBufferDeviceImpl bufferDeviceService;
|
||
|
||
@Autowired
|
||
private IDockDomain dockDomain;
|
||
/**
|
||
* 创建分组
|
||
*
|
||
* @param request 分组创建请求
|
||
* @return 分组ID
|
||
*/
|
||
//@InnerAuth
|
||
@PostMapping("/create")
|
||
public R<Long> createGroup(@RequestBody GroupCreateRequest request)
|
||
{
|
||
try
|
||
{
|
||
GroupDTO dto = new GroupDTO();
|
||
dto.setGroupName(request.getGroupName());
|
||
Long groupId = groupService.createGroup(dto);
|
||
return R.ok(groupId);
|
||
}
|
||
catch (RuntimeException e)
|
||
{
|
||
return R.fail("新增分组'" + request.getGroupName() + "'失败,分组名称已存在");
|
||
}
|
||
}
|
||
/**
|
||
* 删除分组
|
||
*
|
||
* @param groupId 分组ID
|
||
* @return 结果
|
||
*/
|
||
//@InnerAuth
|
||
@DeleteMapping("/delete/{groupId}")
|
||
public R<Void> deleteGroup(@PathVariable("groupId") Long groupId)
|
||
{
|
||
groupService.deleteGroup(groupId);
|
||
return R.ok();
|
||
}
|
||
|
||
/**
|
||
* 修改分组名称
|
||
*
|
||
* @param request 分组更新请求
|
||
* @return 结果
|
||
*/
|
||
//@InnerAuth
|
||
@PostMapping("/update")
|
||
public R<Void> updateGroup(@RequestBody GroupUpdateRequest request)
|
||
{
|
||
try
|
||
{
|
||
GroupDTO dto = new GroupDTO();
|
||
dto.setGroupId(request.getGroupId());
|
||
dto.setGroupName(request.getGroupName());
|
||
groupService.updateGroup(dto);
|
||
return R.ok();
|
||
}
|
||
catch (RuntimeException e)
|
||
{
|
||
return R.fail("修改分组'" + request.getGroupName() + "'失败,分组名称已存在");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 切换机场所在的分组
|
||
*
|
||
* @param request 切换分组请求
|
||
* @return 结果
|
||
*/
|
||
@PostMapping("/switch")
|
||
public R<Void> switchDockGroup(@RequestBody SwitchDockGroupRequest request)
|
||
{
|
||
|
||
if(!CollectionUtils.isEmpty(request.getDockIds())){
|
||
for (Long dockId : request.getDockIds()) {
|
||
groupService.switchDockGroup(dockId, request.getGroupId());
|
||
}
|
||
}
|
||
return R.ok();
|
||
}
|
||
|
||
/**
|
||
* 查看分组下的机场
|
||
*
|
||
* @param groupId 分组ID
|
||
* @return 机场列表
|
||
*/
|
||
//@InnerAuth
|
||
@GetMapping("/docks/{groupId}")
|
||
public R<List<DockWithGPSVO>> getDocksByGroupId(@PathVariable("groupId") Long groupId)
|
||
{
|
||
logger.info("getDocksByGroupId {}", groupId);
|
||
|
||
if(Objects.equals(groupId, -1L)){
|
||
// List<DockGroupDTO> groupDTOS = groupService.getDocksByGroupId(groupId);
|
||
List<DockDetailDTO> dtoList = new ArrayList<>();
|
||
Dock queryDock = new Dock();
|
||
List<Dock> allDocks = dockDomain.selectDockList(queryDock);
|
||
|
||
if (allDocks != null) {
|
||
for (Dock dock : allDocks) {
|
||
if (dock.getLastActiveTime() != null) {
|
||
DockDetailDTO dockDetailDTO = bufferDeviceService.getDockDetailById(dock.getDockId());
|
||
if (dockDetailDTO != null) {
|
||
dockDetailDTO.setLastActiveTime(dock.getLastActiveTime());
|
||
dockDetailDTO.setCabinVideoUrl(dock.getCabinVideoUrl());
|
||
dockDetailDTO.setOutsideVideoUrl(dock.getOutsideVideoUrl());
|
||
dockDetailDTO.setLiveVideoUrl(dock.getLiveVideoUrl());
|
||
dtoList.add(dockDetailDTO);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
dtoList.sort(Comparator.comparing(DockDetailDTO::getLastActiveTime).reversed());
|
||
|
||
return R.ok(DockWithGPSVOConvert.fromList(dtoList));
|
||
}else {
|
||
List<DockGroupDTO> groupDTOS = groupService.getDocksByGroupId(groupId);
|
||
List<DockDetailDTO> dtoList = new ArrayList<>();
|
||
for (DockGroupDTO dockGroupDTO : groupDTOS) {
|
||
DockDetailDTO dockDetailDTO = bufferDeviceService.getDockDetailById(dockGroupDTO.getDockId());
|
||
if (dockDetailDTO != null) {
|
||
dtoList.add(dockDetailDTO);
|
||
}
|
||
}
|
||
|
||
return R.ok(DockWithGPSVOConvert.fromList(dtoList));
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 查看所有分组
|
||
*
|
||
* @return 分组ID列表
|
||
*/
|
||
//@InnerAuth
|
||
@GetMapping("/list")
|
||
public R<List<GroupVO>> getAllGroupIds()
|
||
{
|
||
List<GroupDTO> groupDTOs = groupService.getAllGroupIds();
|
||
List<GroupVO> groupVOS = new ArrayList<>();
|
||
|
||
// 添加虚拟的"最近使用"分组(groupId = -1)
|
||
// 统计 last_active_time 不为空的机场数量
|
||
Dock queryDock = new Dock();
|
||
List<Dock> allDocks = dockDomain.selectDockList(queryDock);
|
||
int recentlyUsedCount = 0;
|
||
if (allDocks != null) {
|
||
for (Dock dock : allDocks) {
|
||
if (dock.getLastActiveTime() != null) {
|
||
recentlyUsedCount++;
|
||
}
|
||
}
|
||
}
|
||
|
||
// 创建"最近使用"虚拟分组
|
||
GroupVO recentlyUsedGroup = new GroupVO();
|
||
recentlyUsedGroup.setGroupId(-1L);
|
||
recentlyUsedGroup.setGroupName("最近使用");
|
||
recentlyUsedGroup.setDockCount(recentlyUsedCount);
|
||
groupVOS.add(recentlyUsedGroup);
|
||
|
||
// 添加其他真实分组
|
||
for(GroupDTO groupDTO : groupDTOs){
|
||
GroupVO groupVO = GroupVOConvert.from(groupDTO);
|
||
List<DockGroupDTO> dockGroupDTOs = groupService.getDocksByGroupId(groupDTO.getGroupId());
|
||
groupVO.setDockCount(dockGroupDTOs.size());
|
||
groupVOS.add(groupVO);
|
||
}
|
||
|
||
return R.ok(groupVOS);
|
||
}
|
||
}
|