Commit 34677034 by gdj

机队列表返回相关的用户和设备信息。

parent 712e2d63
......@@ -14,4 +14,5 @@ public interface IFleetDeviceService extends IService<FleetDeviceEntity> {
void addFleetDevice(List<FleetDeviceEntity> deviceList);
List<FleetDeviceDTO> searchDeviceDTOListByFleetId(String fleetId);
List<FleetDeviceDTO> searchDeviceDTOListByFleetIds(List<Integer> fleetId);
}
......@@ -14,5 +14,6 @@ public interface IFleetUserService extends IService<FleetUserEntity> {
void addFleetUser(List<FleetUserEntity> userList);
List<FleetUserDTO> searchUserDTOListByFleetId(String fleetId);
List<FleetUserDTO> searchUserDTOListByFleetIds(List<Integer> fleetIds);
}
......@@ -16,6 +16,9 @@ import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @author guan
......@@ -53,6 +56,17 @@ public class FleetDeviceServiceImpl extends ServiceImpl<IFleetDeviceMapper, Flee
return deviceDTOList;
}
@Override
public List<FleetDeviceDTO> searchDeviceDTOListByFleetIds(List<Integer> fleetId) {
LambdaQueryWrapper<FleetDeviceEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(FleetDeviceEntity::getFleetId, fleetId);
List<FleetDeviceEntity> fleetDeviceEntities = this.list(queryWrapper);
List<FleetDeviceDTO> deviceDTOList = fleetDeviceEntityToDTOList(fleetDeviceEntities);
return deviceDTOList;
}
public FleetDeviceDTO fleetDeviceEntityToDTO(FleetDeviceEntity entity) {
FleetDeviceDTO fleetDeviceDTO = new FleetDeviceDTO();
......@@ -73,4 +87,33 @@ public class FleetDeviceServiceImpl extends ServiceImpl<IFleetDeviceMapper, Flee
return fleetDeviceDTO;
}
public List<FleetDeviceDTO> fleetDeviceEntityToDTOList(List<FleetDeviceEntity> entityList) {
List<FleetDeviceDTO> fleetDeviceDTOList = new ArrayList<>();
List<String> deviceIdList = entityList.stream().map(FleetDeviceEntity::getDeviceId).distinct().collect(Collectors.toList());
LambdaQueryWrapper<DeviceEntity> deviceQueryWrapper = new LambdaQueryWrapper<>();
deviceQueryWrapper.in(DeviceEntity::getId, deviceIdList);
List<DeviceEntity> deviceEntities = deviceService.list(deviceQueryWrapper);
Map<Integer, DeviceEntity> deviceEntityMap = deviceEntities.stream().collect(Collectors.toMap(DeviceEntity::getId, Function.identity(), (key1, key2) -> key1));
for (FleetDeviceEntity entity : entityList) {
FleetDeviceDTO fleetDeviceDTO = new FleetDeviceDTO();
fleetDeviceDTO.setId(entity.getId());
fleetDeviceDTO.setDeviceId(entity.getDeviceId());
fleetDeviceDTO.setFleetId(entity.getFleetId());
DeviceEntity device = deviceEntityMap.getOrDefault(Integer.valueOf(entity.getDeviceId()), null);
if (!ObjectUtils.isEmpty(device)) {
fleetDeviceDTO.setDeviceNickname(device.getNickname());
// 型号
DeviceEnum deviceEnum = DeviceEnum.find(device.getDomain(), device.getDeviceType(), device.getSubType());
fleetDeviceDTO.setDeviceEnumName(deviceEnum.name());
}
fleetDeviceDTOList.add(fleetDeviceDTO);
}
return fleetDeviceDTOList;
}
}
......@@ -27,6 +27,7 @@ import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
......@@ -80,6 +81,21 @@ public class FleetServiceImpl extends ServiceImpl<IFleetMapper, FleetEntity> imp
// })
.collect(Collectors.toList());
// 查询全部userList 和 deviceList
List<Integer> fleetIdList = fleetList.stream().map(FleetDTO::getId).collect(Collectors.toList());
// 查询用户
List<FleetUserDTO> fleetUserDTOList = fleetUserService.searchUserDTOListByFleetIds(fleetIdList);
Map<String, List<FleetUserDTO>> fleetUserDTOMap = fleetUserDTOList.stream().collect(Collectors.groupingBy(FleetUserDTO::getFleetId));
// 查询设备
List<FleetDeviceDTO> fleetDeviceDTOList = fleetDeviceService.searchDeviceDTOListByFleetIds(fleetIdList);
Map<String, List<FleetDeviceDTO>> fleetDeviceDTOMap = fleetDeviceDTOList.stream().collect(Collectors.groupingBy(FleetDeviceDTO::getFleetId));
for (FleetDTO fleetDTO : fleetList) {
fleetDTO.setUserList(fleetUserDTOMap.getOrDefault(fleetDTO.getId().toString(), new ArrayList<>()));
fleetDTO.setDeviceList(fleetDeviceDTOMap.getOrDefault(fleetDTO.getId().toString(), new ArrayList<>()));
}
return new PaginationData<>(fleetList, new Pagination(pagination.getCurrent(), pagination.getSize(), pagination.getTotal()));
}
......
......@@ -16,6 +16,9 @@ import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @author guan
......@@ -54,6 +57,16 @@ public class FleetUserServiceImpl extends ServiceImpl<IFleetUserMapper, FleetUse
return userDTOList;
}
@Override
public List<FleetUserDTO> searchUserDTOListByFleetIds(List<Integer> fleetIds) {
LambdaQueryWrapper<FleetUserEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(FleetUserEntity::getFleetId, fleetIds);
List<FleetUserEntity> fleetUserEntities = this.list(queryWrapper);
List<FleetUserDTO> userDTOList = fleetUserEntityToDTOList(fleetUserEntities);
return userDTOList;
}
public FleetUserDTO fleetUserEntityToDTO(FleetUserEntity entity) {
FleetUserDTO fleetUserDTO = new FleetUserDTO();
......@@ -74,4 +87,34 @@ public class FleetUserServiceImpl extends ServiceImpl<IFleetUserMapper, FleetUse
return fleetUserDTO;
}
public List<FleetUserDTO> fleetUserEntityToDTOList(List<FleetUserEntity> entityList) {
List<FleetUserDTO> fleetUserDTOList = new ArrayList<>();
List<String> userIdList = entityList.stream().map(FleetUserEntity::getUserId).distinct().collect(Collectors.toList());
// 查询 user
LambdaQueryWrapper<UserEntity> userQueryWrapper = new LambdaQueryWrapper<>();
userQueryWrapper.in(UserEntity::getId, userIdList);
List<UserEntity> userEntityList = userService.list(userQueryWrapper);
Map<Integer, UserEntity> userEntityMap = userEntityList.stream().collect(Collectors.toMap(UserEntity::getId, Function.identity(), (key1, key2) -> key1));
for (FleetUserEntity entity : entityList) {
FleetUserDTO fleetUserDTO = new FleetUserDTO();
fleetUserDTO.setId(entity.getId());
fleetUserDTO.setFleetId(entity.getFleetId());
fleetUserDTO.setUserId(entity.getUserId());
UserEntity user = userEntityMap.getOrDefault(Integer.valueOf(entity.getUserId()), null);
if (!ObjectUtils.isEmpty(user)) {
fleetUserDTO.setUsername(user.getUsername());
fleetUserDTO.setUserTypeName(UserTypeEnum.find(user.getUserType()).name());
}
fleetUserDTOList.add(fleetUserDTO);
}
return fleetUserDTOList;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment