Commit 8e0d465b by gdj

fix:fleetuser sql bug

parent 158b19bd
...@@ -12,7 +12,9 @@ import com.dji.sdk.cloudapi.device.DeviceEnum; ...@@ -12,7 +12,9 @@ import com.dji.sdk.cloudapi.device.DeviceEnum;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -58,6 +60,9 @@ public class FleetDeviceServiceImpl extends ServiceImpl<IFleetDeviceMapper, Flee ...@@ -58,6 +60,9 @@ public class FleetDeviceServiceImpl extends ServiceImpl<IFleetDeviceMapper, Flee
@Override @Override
public List<FleetDeviceDTO> searchDeviceDTOListByFleetIds(List<Integer> fleetId) { public List<FleetDeviceDTO> searchDeviceDTOListByFleetIds(List<Integer> fleetId) {
if (CollectionUtils.isEmpty(fleetId)) {
return new ArrayList<>();
}
LambdaQueryWrapper<FleetDeviceEntity> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<FleetDeviceEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(FleetDeviceEntity::getFleetId, fleetId); queryWrapper.in(FleetDeviceEntity::getFleetId, fleetId);
...@@ -95,8 +100,13 @@ public class FleetDeviceServiceImpl extends ServiceImpl<IFleetDeviceMapper, Flee ...@@ -95,8 +100,13 @@ public class FleetDeviceServiceImpl extends ServiceImpl<IFleetDeviceMapper, Flee
public List<FleetDeviceDTO> fleetDeviceEntityToDTOList(List<FleetDeviceEntity> entityList) { public List<FleetDeviceDTO> fleetDeviceEntityToDTOList(List<FleetDeviceEntity> entityList) {
List<FleetDeviceDTO> fleetDeviceDTOList = new ArrayList<>(); List<FleetDeviceDTO> fleetDeviceDTOList = new ArrayList<>();
if (CollectionUtils.isEmpty(entityList)) {
List<String> deviceIdList = entityList.stream().map(FleetDeviceEntity::getDeviceId).distinct().collect(Collectors.toList()); return fleetDeviceDTOList;
}
List<String> deviceIdList = entityList.stream().map(FleetDeviceEntity::getDeviceId).filter(StringUtils::hasText).distinct().collect(Collectors.toList());
if (CollectionUtils.isEmpty(deviceIdList)) {
return fleetDeviceDTOList;
}
LambdaQueryWrapper<DeviceEntity> deviceQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<DeviceEntity> deviceQueryWrapper = new LambdaQueryWrapper<>();
deviceQueryWrapper.in(DeviceEntity::getId, deviceIdList); deviceQueryWrapper.in(DeviceEntity::getId, deviceIdList);
List<DeviceEntity> deviceEntities = deviceService.list(deviceQueryWrapper); List<DeviceEntity> deviceEntities = deviceService.list(deviceQueryWrapper);
......
...@@ -23,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -23,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -82,7 +83,7 @@ public class FleetServiceImpl extends ServiceImpl<IFleetMapper, FleetEntity> imp ...@@ -82,7 +83,7 @@ public class FleetServiceImpl extends ServiceImpl<IFleetMapper, FleetEntity> imp
.collect(Collectors.toList()); .collect(Collectors.toList());
// 查询全部userList 和 deviceList // 查询全部userList 和 deviceList
List<Integer> fleetIdList = fleetList.stream().map(FleetDTO::getId).collect(Collectors.toList()); List<Integer> fleetIdList = fleetList.stream().map(FleetDTO::getId).filter(x -> !ObjectUtils.isEmpty(x)).collect(Collectors.toList());
// 查询用户 // 查询用户
List<FleetUserDTO> fleetUserDTOList = fleetUserService.searchUserDTOListByFleetIds(fleetIdList); List<FleetUserDTO> fleetUserDTOList = fleetUserService.searchUserDTOListByFleetIds(fleetIdList);
Map<String, List<FleetUserDTO>> fleetUserDTOMap = fleetUserDTOList.stream().collect(Collectors.groupingBy(FleetUserDTO::getFleetId)); Map<String, List<FleetUserDTO>> fleetUserDTOMap = fleetUserDTOList.stream().collect(Collectors.groupingBy(FleetUserDTO::getFleetId));
......
...@@ -12,7 +12,9 @@ import com.dji.sample.manage.service.IUserService; ...@@ -12,7 +12,9 @@ import com.dji.sample.manage.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -59,6 +61,9 @@ public class FleetUserServiceImpl extends ServiceImpl<IFleetUserMapper, FleetUse ...@@ -59,6 +61,9 @@ public class FleetUserServiceImpl extends ServiceImpl<IFleetUserMapper, FleetUse
@Override @Override
public List<FleetUserDTO> searchUserDTOListByFleetIds(List<Integer> fleetIds) { public List<FleetUserDTO> searchUserDTOListByFleetIds(List<Integer> fleetIds) {
if (CollectionUtils.isEmpty(fleetIds)) {
return new ArrayList<>();
}
LambdaQueryWrapper<FleetUserEntity> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<FleetUserEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(FleetUserEntity::getFleetId, fleetIds); queryWrapper.in(FleetUserEntity::getFleetId, fleetIds);
List<FleetUserEntity> fleetUserEntities = this.list(queryWrapper); List<FleetUserEntity> fleetUserEntities = this.list(queryWrapper);
...@@ -92,7 +97,13 @@ public class FleetUserServiceImpl extends ServiceImpl<IFleetUserMapper, FleetUse ...@@ -92,7 +97,13 @@ public class FleetUserServiceImpl extends ServiceImpl<IFleetUserMapper, FleetUse
List<FleetUserDTO> fleetUserDTOList = new ArrayList<>(); List<FleetUserDTO> fleetUserDTOList = new ArrayList<>();
List<String> userIdList = entityList.stream().map(FleetUserEntity::getUserId).distinct().collect(Collectors.toList()); if (CollectionUtils.isEmpty(entityList)) {
return fleetUserDTOList;
}
List<String> userIdList = entityList.stream().map(FleetUserEntity::getUserId).filter(StringUtils::hasText).distinct().collect(Collectors.toList());
if (CollectionUtils.isEmpty(userIdList)) {
return fleetUserDTOList;
}
// 查询 user // 查询 user
LambdaQueryWrapper<UserEntity> userQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<UserEntity> userQueryWrapper = new LambdaQueryWrapper<>();
userQueryWrapper.in(UserEntity::getId, userIdList); userQueryWrapper.in(UserEntity::getId, userIdList);
......
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