package com.ruoyi.manage.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.domain.entity.SysDictData; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.manage.domain.DpShipDevice; import com.ruoyi.manage.domain.vo.ShipTypeVO; import com.ruoyi.manage.domain.vo.TreeVO; import com.ruoyi.manage.mapper.DpShipDeviceMapper; import com.ruoyi.manage.mapper.DpShipsMapper; import com.ruoyi.manage.domain.DpShips; import com.ruoyi.manage.service.DpShipsService; import com.ruoyi.system.service.ISysDictDataService; import jakarta.annotation.Resource; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import java.util.*; import java.util.stream.Collectors; /** *

* 舰船表 服务实现类 *

* * @author zhangyy * @since 2025-03-11 */ @Service @Component public class DpShipsServiceImpl extends ServiceImpl implements DpShipsService { @Resource private DpShipsMapper dpShipsMapper; @Resource private DpShipDeviceMapper dpShipDeviceMapper; @Resource private ISysDictDataService iSysDictDataService; //根据ID查询舰船信息 @Override public DpShips getDpShipsById(String id){ return dpShipsMapper.getDpShipsById(id); } //根据码头ID查询船舰类型 @Override public List getDpShipTypeByWhId(Integer whId){ QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.select("SHIP_TYPE_ID").eq("WH_ID", whId); List> shipTypeMaps = dpShipsMapper.selectMaps(queryWrapper); List list= shipTypeMaps.stream() .map(map -> String.valueOf(map.get("SHIP_TYPE_ID"))) .collect(Collectors.toList()); List shipTypeVOS = new ArrayList<>(); Map shipTypeMap = shipTypeByDict(); for (String typeKey:list){ ShipTypeVO shipTypeVO =new ShipTypeVO(); shipTypeVO.setId(typeKey); shipTypeVO.setName(shipTypeMap.get(typeKey)); shipTypeVOS.add(shipTypeVO); } return shipTypeVOS; } //根据码头ID查询船舰类型(新) @Override public List getDpShipTypeByWhIdNEW(Integer whId){ DpShips ship = new DpShips(); ship.setWhId(whId); List shipsList = dpShipsMapper.getByWhIdBeId(ship); Map> mapShipType = new HashMap<>(); for (DpShips dpShips : shipsList){ String shipType = dpShips.getShipType(); Integer shipTypeId = dpShips.getShipTypeId(); mapShipType.putIfAbsent(shipType,new ArrayList<>()); mapShipType.get(shipType).add(shipTypeId); } List shipTypeVOS = new ArrayList<>(); for(Map.Entry> entry : mapShipType.entrySet()){ ShipTypeVO shipTypeVO =new ShipTypeVO(); shipTypeVO.setId(String.valueOf(generateId())); shipTypeVO.setName(entry.getKey()); shipTypeVO.setIds(entry.getValue()); shipTypeVOS.add(shipTypeVO); } return shipTypeVOS; } //根据字典获取舰艇类型 private Map shipTypeByDict(){ SysDictData sysDictData = new SysDictData(); sysDictData.setDictType("dp_ship_type"); List dictDataList = iSysDictDataService.selectDictDataList(sysDictData); Map shipTypeMap = new HashMap<>(); for (SysDictData dictData : dictDataList){ shipTypeMap.put(dictData.getDictValue(),dictData.getDictLabel()); } return shipTypeMap; } //根据码头ID和泊位ID查询舰船列表 @Override public List getByWhIdBeId(Integer whId,Integer beId){ DpShips dpShips = new DpShips(); dpShips.setWhId(whId); dpShips.setBeId(beId); return dpShipsMapper.getByWhIdBeId(dpShips); } //根据码头ID和舰船类型查询舰船列表 @Override public List getDpShipsByWhIdType(Integer whId, String shipType){ QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("WH_ID",whId).eq("SHIP_TYPE_ID",shipType); List list = dpShipsMapper.selectList(queryWrapper); List treeList = new ArrayList<>(); for (DpShips dpShip : list) { TreeVO treeVO = new TreeVO(); treeVO.setId(dpShip.getId()); treeVO.setLabel(dpShip.getShipName()); //非子节点disable为true treeVO.setDisabled(true); // 初始化子设备列表 List treeListChil = new ArrayList<>(); QueryWrapper deviceWrapper = new QueryWrapper<>(); deviceWrapper.eq("DEVICE_SHIP_ID", dpShip.getShipId()); List devices = dpShipDeviceMapper.selectList(deviceWrapper); for (DpShipDevice dpShipDevice : devices){ TreeVO treeChil = new TreeVO(); treeChil.setId(dpShipDevice.getId()); treeChil.setLabel(dpShipDevice.getDeviceName()); treeListChil.add(treeChil); } treeVO.setChildren(treeListChil); treeList.add(treeVO); } return treeList; } @Override public List getDpShipsByWhIdTypeNEW(Integer whId, List shipTypes){ QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("WH_ID",whId).in("SHIP_TYPE_ID",shipTypes); List list = dpShipsMapper.selectList(queryWrapper); List treeList = new ArrayList<>(); for (DpShips dpShip : list) { TreeVO treeVO = new TreeVO(); treeVO.setId(dpShip.getId()); treeVO.setLabel(dpShip.getShipName()); //非子节点disable为true treeVO.setDisabled(true); // 初始化子设备列表 List treeListChil = new ArrayList<>(); QueryWrapper deviceWrapper = new QueryWrapper<>(); deviceWrapper.eq("SHIP_TYPE_ID", dpShip.getShipTypeId()); List devices = dpShipDeviceMapper.selectList(deviceWrapper); for (DpShipDevice dpShipDevice : devices){ TreeVO treeChil = new TreeVO(); // treeChil.setId(dpShipDevice.getId()); treeChil.setId(String.valueOf(generateId())); treeChil.setLabel(dpShipDevice.getDeviceName()); treeChil.setDisabled(false); treeChil.setChildren(new ArrayList<>()); treeListChil.add(treeChil); } treeVO.setChildren(treeListChil); treeList.add(treeVO); } return treeList; } @Override public TableDataInfo getPageList(DpShips ships) { if(ships.getPageNum()!=null && ships.getPageSize()!=null){ Integer offset = (ships.getPageNum()-1)*ships.getPageSize(); ships.setOffset(offset); List records = dpShipsMapper.getPageList(ships); long total = dpShipsMapper.getTotal(ships); return new TableDataInfo(records,Integer.parseInt(String.valueOf(total))); } return null; } //生成不重复ID private int generateId(){ UUID uuid = UUID.randomUUID(); long hash = uuid.hashCode(); return (int)(hash&Integer.MAX_VALUE); } }