Commit 93ba7d21 by gdj

fix:fleetuser sql bug

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