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;
|
|
/**
|
* <p>
|
* 舰船表 服务实现类
|
* </p>
|
*
|
* @author zhangyy
|
* @since 2025-03-11
|
*/
|
@Service
|
@Component
|
public class DpShipsServiceImpl extends ServiceImpl<DpShipsMapper, DpShips> 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<ShipTypeVO> getDpShipTypeByWhId(Integer whId){
|
QueryWrapper<DpShips> queryWrapper = new QueryWrapper<>();
|
queryWrapper.select("SHIP_TYPE_ID").eq("WH_ID", whId);
|
List<Map<String, Object>> shipTypeMaps = dpShipsMapper.selectMaps(queryWrapper);
|
List<String> list= shipTypeMaps.stream()
|
.map(map -> String.valueOf(map.get("SHIP_TYPE_ID")))
|
.collect(Collectors.toList());
|
List<ShipTypeVO> shipTypeVOS = new ArrayList<>();
|
Map<String,String> 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<ShipTypeVO> getDpShipTypeByWhIdNEW(Integer whId){
|
DpShips ship = new DpShips();
|
ship.setWhId(whId);
|
List<DpShips> shipsList = dpShipsMapper.getByWhIdBeId(ship);
|
Map<String,List<Integer>> 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<ShipTypeVO> shipTypeVOS = new ArrayList<>();
|
for(Map.Entry<String,List<Integer>> 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<String,String> shipTypeByDict(){
|
SysDictData sysDictData = new SysDictData();
|
sysDictData.setDictType("dp_ship_type");
|
List<SysDictData> dictDataList = iSysDictDataService.selectDictDataList(sysDictData);
|
Map<String,String> shipTypeMap = new HashMap<>();
|
for (SysDictData dictData : dictDataList){
|
shipTypeMap.put(dictData.getDictValue(),dictData.getDictLabel());
|
}
|
return shipTypeMap;
|
}
|
|
//根据码头ID和泊位ID查询舰船列表
|
@Override
|
public List<DpShips> getByWhIdBeId(Integer whId,Integer beId){
|
DpShips dpShips = new DpShips();
|
dpShips.setWhId(whId);
|
dpShips.setBeId(beId);
|
return dpShipsMapper.getByWhIdBeId(dpShips);
|
}
|
|
//根据码头ID和舰船类型查询舰船列表
|
@Override
|
public List<TreeVO> getDpShipsByWhIdType(Integer whId, String shipType){
|
QueryWrapper<DpShips> queryWrapper = new QueryWrapper<>();
|
queryWrapper.eq("WH_ID",whId).eq("SHIP_TYPE_ID",shipType);
|
List<DpShips> list = dpShipsMapper.selectList(queryWrapper);
|
List<TreeVO> 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<TreeVO> treeListChil = new ArrayList<>();
|
QueryWrapper<DpShipDevice> deviceWrapper = new QueryWrapper<>();
|
deviceWrapper.eq("DEVICE_SHIP_ID", dpShip.getShipId());
|
List<DpShipDevice> 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<TreeVO> getDpShipsByWhIdTypeNEW(Integer whId, List<Integer> shipTypes){
|
QueryWrapper<DpShips> queryWrapper = new QueryWrapper<>();
|
queryWrapper.eq("WH_ID",whId).in("SHIP_TYPE_ID",shipTypes);
|
List<DpShips> list = dpShipsMapper.selectList(queryWrapper);
|
List<TreeVO> 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<TreeVO> treeListChil = new ArrayList<>();
|
QueryWrapper<DpShipDevice> deviceWrapper = new QueryWrapper<>();
|
deviceWrapper.eq("SHIP_TYPE_ID", dpShip.getShipTypeId());
|
List<DpShipDevice> 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<DpShips> 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);
|
}
|
|
}
|