13693261870
2025-07-02 6708810c4de34dfb9513061432d656f91d56ee3a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
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);
    }
 
}