feat(后端): 联调修改1

master
rdpnr_puzhi 2025-08-12 16:14:10 +08:00
parent 7e9be02d61
commit b3304804a1
9 changed files with 112 additions and 138 deletions

View File

@ -18,9 +18,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Objects; import java.util.Objects;
/** /**
@ -68,11 +66,7 @@ public class ClientController {
deviceUserReq.setDeviceId(loginReq.getDeviceId()); deviceUserReq.setDeviceId(loginReq.getDeviceId());
deviceUserReq.setUserName(loginReq.getUsername()); deviceUserReq.setUserName(loginReq.getUsername());
deviceUserReq.setPassword(loginReq.getPassword()); deviceUserReq.setPassword(loginReq.getPassword());
//todo 后面再调 return deviceUserMappingService.loginUser(deviceUserReq);
// Result<?> result = deviceUserMappingService.loginUser(deviceUserReq);
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("token", "123456");
return Result.successResult(hashMap);
} }
@ApiOperation(value = "获取镜像列表") @ApiOperation(value = "获取镜像列表")
@ -83,24 +77,23 @@ public class ClientController {
} }
log.info("获取镜像列表请求参数为:{}", JSONUtil.toJsonStr(loginReq)); log.info("获取镜像列表请求参数为:{}", JSONUtil.toJsonStr(loginReq));
// Result<?> imageList = clientService.getImageList(loginReq.getDeviceId(), loginReq.getToken()); // List<HashMap<String, Object>> hashMaps = new ArrayList<>();
List<HashMap<String, Object>> hashMaps = new ArrayList<>(); // HashMap<String, Object> map = new HashMap<>();
HashMap<String, Object> map = new HashMap<>(); // map.put("name", "ubuntu-20.04.6-desktop-amd64.iso");
map.put("name", "ubuntu-20.04.6-desktop-amd64.iso"); // map.put("torrent", "https://releases.ubuntu.com/20.04.6/ubuntu-20.04.6-desktop-amd64.iso.torrent");
map.put("torrent", "https://releases.ubuntu.com/20.04.6/ubuntu-20.04.6-desktop-amd64.iso.torrent"); // hashMaps.add(map);
hashMaps.add(map); // HashMap<String, Object> map1 = new HashMap<>();
HashMap<String, Object> map1 = new HashMap<>(); // map1.put("name", "uos_nbd_20250806.qcow2");
map1.put("name", "uos_nbd_20250806.qcow2"); // map1.put("torrent", "http://10.100.51.86:8114/api/vdi/file/down/uos_nbd_20250806.qcow2.torrent");
map1.put("torrent", "http://10.100.51.86:8114/api/vdi/file/down/win10_v2307_uefi_demo.vhdx.torrent"); // hashMaps.add(map1);
hashMaps.add(map1); // HashMap<String, Object> map2 = new HashMap<>();
HashMap<String, Object> map2 = new HashMap<>(); // map2.put("name", "win10_v2307_uefi_demo.vhdx");
map2.put("name", "win10_v2307_uefi_demo.vhdx"); // map2.put("torrent", "http://10.100.51.86:8114/api/vdi/file/down/win10_v2307_uefi_demo.vhdx.torrent");
map2.put("torrent", "http://10.100.51.86:8114/api/vdi/file/down/win10_v2307_uefi_demo.vhdx.torrent"); // hashMaps.add(map2);
hashMaps.add(map2); //
// HashMap<String, Object> hashMap = new HashMap<>();
HashMap<String, Object> hashMap = new HashMap<>(); // hashMap.put("list", hashMaps);
hashMap.put("list", hashMaps); return clientService.getImageList(loginReq.getDeviceId(), loginReq.getToken());
return Result.successResult(hashMap);
} }
@ApiOperation(value = "版本更新") @ApiOperation(value = "版本更新")

View File

@ -48,7 +48,7 @@ public class DeviceImageMappingController {
log.info("终端镜像映射新增请求参数为:{}", JSONUtil.toJsonStr(deviceImageMappingReq)); log.info("终端镜像映射新增请求参数为:{}", JSONUtil.toJsonStr(deviceImageMappingReq));
List<DeviceImageMappingReq> reqData = deviceImageMappingReq.getData(); List<DeviceImageMappingReq> reqData = deviceImageMappingReq.getData();
List<DeviceImageMappingReq> addList = reqData.stream().filter(e -> Objects.isNull(e.getId())).collect(Collectors.toList()); List<DeviceImageMappingReq> addList = reqData.stream().distinct().filter(e -> Objects.isNull(e.getId())).collect(Collectors.toList());
QueryWrapper<DeviceImageMapping> wrapper = new QueryWrapper<>(); QueryWrapper<DeviceImageMapping> wrapper = new QueryWrapper<>();
wrapper.lambda().eq(DeviceImageMapping::getDeviceId, reqData.get(0).getDeviceId()); wrapper.lambda().eq(DeviceImageMapping::getDeviceId, reqData.get(0).getDeviceId());

View File

@ -47,7 +47,7 @@ public class DeviceUserMappingController {
} }
log.info("终端用户映射新增请求参数为:{}", JSONUtil.toJsonStr(deviceUserMappingReq)); log.info("终端用户映射新增请求参数为:{}", JSONUtil.toJsonStr(deviceUserMappingReq));
List<DeviceUserMappingReq> userMappingReqData = deviceUserMappingReq.getData(); List<DeviceUserMappingReq> userMappingReqData = deviceUserMappingReq.getData();
List<DeviceUserMappingReq> addList = userMappingReqData.stream().filter(e -> Objects.isNull(e.getId())).collect(Collectors.toList()); List<DeviceUserMappingReq> addList = userMappingReqData.stream().distinct().filter(e -> Objects.isNull(e.getId())).collect(Collectors.toList());
QueryWrapper<DeviceUserMapping> wrapper = new QueryWrapper<>(); QueryWrapper<DeviceUserMapping> wrapper = new QueryWrapper<>();
wrapper.lambda().eq(DeviceUserMapping::getDeviceId, userMappingReqData.get(0).getDeviceId()); wrapper.lambda().eq(DeviceUserMapping::getDeviceId, userMappingReqData.get(0).getDeviceId());
@ -55,12 +55,14 @@ public class DeviceUserMappingController {
if (CollectionUtil.isNotEmpty(list)) { if (CollectionUtil.isNotEmpty(list)) {
Set<Long> requestIds = userMappingReqData.stream() Set<Long> requestIds = userMappingReqData.stream()
.distinct()
.map(DeviceUserMappingReq::getId) .map(DeviceUserMappingReq::getId)
.filter(Objects::nonNull) .filter(Objects::nonNull)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
List<Long> idsToDelete = list.stream() List<Long> idsToDelete = list.stream()
.map(DeviceUserMapping::getId) .map(DeviceUserMapping::getId)
.distinct()
.filter(Objects::nonNull) .filter(Objects::nonNull)
.filter(id -> !requestIds.contains(id)) .filter(id -> !requestIds.contains(id))
.collect(Collectors.toList()); .collect(Collectors.toList());
@ -72,7 +74,7 @@ public class DeviceUserMappingController {
} }
if (CollectionUtil.isNotEmpty(addList)) { if (CollectionUtil.isNotEmpty(addList)) {
List<DeviceUserMapping> deviceUserMappings = BeanUtil.copyToList(addList, DeviceUserMapping.class); List<DeviceUserMapping> deviceUserMappings = BeanUtil.copyToList(addList, DeviceUserMapping.class);
List<DeviceUserMapping> deviceUserMapping = deviceUserMappings.stream().peek(e -> { List<DeviceUserMapping> deviceUserMapping = deviceUserMappings.stream().distinct().peek(e -> {
e.setCreateUser("admin"); e.setCreateUser("admin");
}).collect(Collectors.toList()); }).collect(Collectors.toList());
boolean insert = deviceUserMappingService.saveBatch(deviceUserMapping); boolean insert = deviceUserMappingService.saveBatch(deviceUserMapping);

View File

@ -37,9 +37,9 @@ public class DeviceUserMappingRes implements Serializable {
private Long deviceGroupId; private Long deviceGroupId;
/** /**
* *
*/ */
@ApiModelProperty("分组名称") @ApiModelProperty("终端分组名称")
@JsonProperty("device_group_name") @JsonProperty("device_group_name")
private String deviceGroupName; private String deviceGroupName;
@ -50,6 +50,14 @@ public class DeviceUserMappingRes implements Serializable {
@JsonProperty("user_group_id") @JsonProperty("user_group_id")
private Long userGroupId; private Long userGroupId;
/**
*
*/
@ApiModelProperty("用户分组名称")
@JsonProperty("user_group_name")
private String userGroupName;
/** /**
* ID * ID
*/ */

View File

@ -19,6 +19,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -46,28 +47,28 @@ public class ClientServiceImpl implements ClientService {
if (CollectionUtil.isEmpty(deviceImageMappings)) { if (CollectionUtil.isEmpty(deviceImageMappings)) {
return Result.errorResultMessage(BaseErrorCode.PARAMS_CHK_ERROR, "请先配置终端镜像"); return Result.errorResultMessage(BaseErrorCode.PARAMS_CHK_ERROR, "请先配置终端镜像");
} }
List<Long> imageIdList = deviceImageMappings.stream().map(DeviceImageMapping::getImageId).collect(Collectors.toList()); List<Long> imageIdList = deviceImageMappings.stream().map(DeviceImageMapping::getImageId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(imageIdList)) {
QueryWrapper<Image> imageQueryWrapper = new QueryWrapper<>(); QueryWrapper<Image> imageQueryWrapper = new QueryWrapper<>();
String imageListStr = StringUtils.join(imageIdList, ","); imageQueryWrapper.lambda().in(Image::getId, imageIdList);
log.info("用户登录查询镜像id结果:{}", JSONUtil.toJsonStr(imageListStr)); List<Image> images = imageMapper.selectList(imageQueryWrapper);
imageQueryWrapper.lambda().in(Image::getId, imageListStr); log.info("用户登录查询镜像结果:{}", JSONUtil.toJsonStr(images));
List<Image> images = imageMapper.selectList(imageQueryWrapper); List<ImageRes> imageRes = BeanUtil.copyToList(images, ImageRes.class);
log.info("用户登录查询镜像结果:{}", JSONUtil.toJsonStr(images)); List<HashMap<String, Object>> collect = imageRes.stream().distinct().map(e -> {
List<ImageRes> imageRes = BeanUtil.copyToList(images, ImageRes.class); HashMap<String, Object> hashMap = new HashMap<>();
List<HashMap<String, Object>> collect = imageRes.stream().distinct().map(e -> { if (StringUtils.isNotBlank(e.getImageName())) {
hashMap.put("name", e.getImageName());
}
if (StringUtils.isNotBlank(e.getBtPath())) {
hashMap.put("torrent", e.getBtPath());
}
return hashMap;
}).collect(Collectors.toList());
HashMap<String, Object> hashMap = new HashMap<>(); HashMap<String, Object> hashMap = new HashMap<>();
if (StringUtils.isNotBlank(e.getImageName())) { hashMap.put("list", collect);
hashMap.put("name", e.getImageName()); return Result.successResult(hashMap);
} }
if (StringUtils.isNotBlank(e.getBtPath())) { return Result.successResult();
hashMap.put("torrent", e.getBtPath());
}
return hashMap;
}).collect(Collectors.toList());
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("list", collect);
return Result.successResult(hashMap);
} }
} }

View File

@ -22,6 +22,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -59,9 +60,9 @@ public class DeviceImageMappingServiceImpl extends ServiceImpl<DeviceImageMappin
return Result.successResult(); return Result.successResult();
} else { } else {
List<DeviceImageMappingRes> deviceImageMappingRes = BeanUtil.copyToList(deviceUserMappings, DeviceImageMappingRes.class); List<DeviceImageMappingRes> deviceImageMappingRes = BeanUtil.copyToList(deviceUserMappings, DeviceImageMappingRes.class);
List<Long> imageIds = deviceImageMappingRes.stream().map(DeviceImageMappingRes::getImageId).collect(Collectors.toList()); List<Long> imageIds = deviceImageMappingRes.stream().map(DeviceImageMappingRes::getImageId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(imageIds)) { if (CollectionUtil.isNotEmpty(imageIds)) {
LambdaQueryWrapper<Image> imageLambdaQueryWrapper = new QueryWrapper<Image>().lambda().eq(Image::getId, imageIds); LambdaQueryWrapper<Image> imageLambdaQueryWrapper = new QueryWrapper<Image>().lambda().in(Image::getId, imageIds);
List<Image> images = imageMapper.selectList(imageLambdaQueryWrapper); List<Image> images = imageMapper.selectList(imageLambdaQueryWrapper);
if (CollectionUtil.isNotEmpty(images)) { if (CollectionUtil.isNotEmpty(images)) {
deviceImageMappingRes.forEach(deviceImage -> { deviceImageMappingRes.forEach(deviceImage -> {
@ -73,9 +74,9 @@ public class DeviceImageMappingServiceImpl extends ServiceImpl<DeviceImageMappin
}); });
} }
} }
List<Long> groupIdList = deviceImageMappingRes.stream().map(DeviceImageMappingRes::getDeviceGroupId).collect(Collectors.toList()); List<Long> groupIdList = deviceImageMappingRes.stream().map(DeviceImageMappingRes::getDeviceGroupId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(groupIdList)) { if (CollectionUtil.isNotEmpty(groupIdList)) {
LambdaQueryWrapper<UserDeviceGroup> groupLambdaQueryWrapper = new QueryWrapper<UserDeviceGroup>().lambda().eq(UserDeviceGroup::getId, groupIdList); LambdaQueryWrapper<UserDeviceGroup> groupLambdaQueryWrapper = new QueryWrapper<UserDeviceGroup>().lambda().in(UserDeviceGroup::getId, groupIdList);
List<UserDeviceGroup> userDeviceGroups = groupMapper.selectList(groupLambdaQueryWrapper); List<UserDeviceGroup> userDeviceGroups = groupMapper.selectList(groupLambdaQueryWrapper);
if (CollectionUtil.isNotEmpty(userDeviceGroups)) { if (CollectionUtil.isNotEmpty(userDeviceGroups)) {
deviceImageMappingRes.forEach(deviceImage -> { deviceImageMappingRes.forEach(deviceImage -> {

View File

@ -48,6 +48,12 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device>
@Override @Override
public Result<?> insert(DeviceReq deviceReq) { public Result<?> insert(DeviceReq deviceReq) {
Device device = BeanUtil.copyProperties(deviceReq, Device.class); Device device = BeanUtil.copyProperties(deviceReq, Device.class);
QueryWrapper<Device> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(Device::getDeviceId, deviceReq.getDeviceId());
Device selectOne = deviceMapper.selectOne(queryWrapper);
if (ObjectUtils.isNotEmpty(selectOne)) {
return new Result<>("200", "终端已存在");
}
device.setCreateUser("admin"); device.setCreateUser("admin");
int insert = deviceMapper.insert(device); int insert = deviceMapper.insert(device);
log.info("终端新增insert:{}", insert); log.info("终端新增insert:{}", insert);
@ -111,7 +117,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device>
} else { } else {
PageResult<DeviceRes> convert = PageResult.convertIPage(userPage, DeviceRes.class); PageResult<DeviceRes> convert = PageResult.convertIPage(userPage, DeviceRes.class);
List<DeviceRes> deviceResList = convert.getData(); List<DeviceRes> deviceResList = convert.getData();
List<Long> deviceIdList = deviceResList.stream().distinct().map(DeviceRes::getDeviceGroupId).filter(Objects::nonNull).collect(Collectors.toList()); List<Long> deviceIdList = deviceResList.stream().map(DeviceRes::getDeviceGroupId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
QueryWrapper<UserDeviceGroup> wrapper = new QueryWrapper<>(); QueryWrapper<UserDeviceGroup> wrapper = new QueryWrapper<>();
wrapper.lambda().in(UserDeviceGroup::getId, deviceIdList); wrapper.lambda().in(UserDeviceGroup::getId, deviceIdList);
List<UserDeviceGroup> userDeviceGroups = groupMapper.selectList(wrapper); List<UserDeviceGroup> userDeviceGroups = groupMapper.selectList(wrapper);

View File

@ -20,7 +20,6 @@ import com.unisinsight.project.mapper.UserMapper;
import com.unisinsight.project.service.DeviceUserMappingService; import com.unisinsight.project.service.DeviceUserMappingService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -70,68 +69,49 @@ public class DeviceUserMappingServiceImpl extends ServiceImpl<DeviceUserMappingM
return Result.successResult(); return Result.successResult();
} else { } else {
List<DeviceUserMappingRes> deviceUserMappingRes = BeanUtil.copyToList(deviceUserMappings, DeviceUserMappingRes.class); List<DeviceUserMappingRes> deviceUserMappingRes = BeanUtil.copyToList(deviceUserMappings, DeviceUserMappingRes.class);
if (ObjectUtil.isEmpty(deviceUserMappingReq.getType())) {
List<Long> userList = deviceUserMappingRes.stream().distinct().map(DeviceUserMappingRes::getUserId).filter(Objects::nonNull).collect(Collectors.toList());
userList = new ArrayList<>(new HashSet<>(userList));
if (CollectionUtil.isNotEmpty(userList)) {
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
userQueryWrapper.lambda().in(User::getId, userList);
List<User> users = userMapper.selectList(userQueryWrapper);
deviceUserMappingRes = deviceUserMappingRes.stream().distinct().peek(device -> {
for (User user : users) {
if (!ObjectUtils.isEmpty(device.getUserId()) && device.getUserId().equals(user.getId())) {
device.setUserName(user.getUserName());
}
}
}).collect(Collectors.toList());
}
List<Long> deviceList = deviceUserMappingRes.stream().distinct().map(DeviceUserMappingRes::getDeviceGroupId).filter(Objects::nonNull).collect(Collectors.toList()); List<Long> userList = deviceUserMappingRes.stream().map(DeviceUserMappingRes::getUserId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
deviceList = new ArrayList<>(new HashSet<>(deviceList)); if (CollectionUtil.isNotEmpty(userList)) {
if (CollectionUtil.isNotEmpty(deviceList)) {
QueryWrapper<UserDeviceGroup> groupQueryWrapper = new QueryWrapper<>();
groupQueryWrapper.lambda().in(UserDeviceGroup::getId, deviceList);
List<UserDeviceGroup> userDeviceGroups = groupMapper.selectList(groupQueryWrapper);
deviceUserMappingRes = deviceUserMappingRes.stream().distinct().peek(device -> {
for (UserDeviceGroup userDeviceGroup : userDeviceGroups) {
if (!ObjectUtils.isEmpty(device.getDeviceGroupId()) && device.getDeviceGroupId().equals(userDeviceGroup.getId())) {
device.setDeviceGroupName(userDeviceGroup.getName());
}
}
}).collect(Collectors.toList());
}
return Result.successResult(deviceUserMappingRes);
} else if (deviceUserMappingReq.getType() == 1) {
List<Long> userList = deviceUserMappingRes.stream().distinct().map(DeviceUserMappingRes::getUserId).filter(Objects::nonNull).collect(Collectors.toList());
userList = new ArrayList<>(new HashSet<>(userList));
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>(); QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
userQueryWrapper.lambda().in(User::getId, userList); userQueryWrapper.lambda().in(User::getId, userList);
List<User> users = userMapper.selectList(userQueryWrapper); List<User> users = userMapper.selectList(userQueryWrapper);
List<DeviceUserMappingRes> collect = deviceUserMappingRes.stream().distinct().peek(device -> { deviceUserMappingRes = deviceUserMappingRes.stream().distinct().peek(device -> {
for (User user : users) { for (User user : users) {
if (!ObjectUtils.isEmpty(device.getUserId()) && device.getUserId().equals(user.getId())) { if (!ObjectUtils.isEmpty(device.getUserId()) && device.getUserId().equals(user.getId())) {
device.setUserName(user.getUserName()); device.setUserName(user.getUserName());
} }
} }
}).collect(Collectors.toList()); }).collect(Collectors.toList());
return Result.successResult(collect); }
} else {
List<Long> deviceList = deviceUserMappingRes.stream().distinct().map(DeviceUserMappingRes::getDeviceGroupId).filter(Objects::nonNull).collect(Collectors.toList()); List<Long> deviceList = deviceUserMappingRes.stream().map(DeviceUserMappingRes::getDeviceGroupId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
deviceList = new ArrayList<>(new HashSet<>(deviceList)); if (CollectionUtil.isNotEmpty(deviceList)) {
QueryWrapper<UserDeviceGroup> groupQueryWrapper = new QueryWrapper<>(); QueryWrapper<UserDeviceGroup> groupQueryWrapper = new QueryWrapper<>();
groupQueryWrapper.lambda().eq(UserDeviceGroup::getType, 1);
groupQueryWrapper.lambda().in(UserDeviceGroup::getId, deviceList); groupQueryWrapper.lambda().in(UserDeviceGroup::getId, deviceList);
List<UserDeviceGroup> userDeviceGroups = groupMapper.selectList(groupQueryWrapper); List<UserDeviceGroup> userDeviceGroups = groupMapper.selectList(groupQueryWrapper);
List<DeviceUserMappingRes> collect = deviceUserMappingRes.stream().distinct().peek(device -> { deviceUserMappingRes = deviceUserMappingRes.stream().distinct().peek(device -> {
for (UserDeviceGroup userDeviceGroup : userDeviceGroups) { for (UserDeviceGroup userDeviceGroup : userDeviceGroups) {
if (!ObjectUtils.isEmpty(device.getDeviceGroupId()) && device.getDeviceGroupId().equals(userDeviceGroup.getId())) { if (!ObjectUtils.isEmpty(device.getDeviceGroupId()) && device.getDeviceGroupId().equals(userDeviceGroup.getId())) {
device.setDeviceGroupName(userDeviceGroup.getName()); device.setDeviceGroupName(userDeviceGroup.getName());
} }
} }
}).collect(Collectors.toList()); }).collect(Collectors.toList());
return Result.successResult(collect);
} }
List<Long> userGroupId = deviceUserMappingRes.stream().map(DeviceUserMappingRes::getUserGroupId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(userGroupId)) {
QueryWrapper<UserDeviceGroup> groupQueryWrapper = new QueryWrapper<>();
groupQueryWrapper.lambda().in(UserDeviceGroup::getId, userGroupId);
List<UserDeviceGroup> userDeviceGroups = groupMapper.selectList(groupQueryWrapper);
deviceUserMappingRes = deviceUserMappingRes.stream().distinct().peek(group -> {
for (UserDeviceGroup userDeviceGroup : userDeviceGroups) {
if (!ObjectUtils.isEmpty(group.getUserGroupId()) && group.getUserGroupId().equals(userDeviceGroup.getId())) {
group.setUserGroupName(userDeviceGroup.getName());
}
}
}).collect(Collectors.toList());
}
return Result.successResult(deviceUserMappingRes);
} }
} }
@ -140,20 +120,16 @@ public class DeviceUserMappingServiceImpl extends ServiceImpl<DeviceUserMappingM
@Override @Override
public Result<?> loginUser(DeviceUserReq deviceUserReq) { public Result<?> loginUser(DeviceUserReq deviceUserReq) {
QueryWrapper<DeviceUserMapping> wrapper = new QueryWrapper<>(); QueryWrapper<DeviceUserMapping> wrapper = new QueryWrapper<>();
wrapper.lambda().eq(DeviceUserMapping::getDeviceId, deviceUserReq.getDeviceId()); wrapper.lambda().eq(DeviceUserMapping::getDeviceId, deviceUserReq.getDeviceId());
List<DeviceUserMapping> deviceUserMappings = deviceUserMappingMapper.selectList(wrapper); List<DeviceUserMapping> deviceUserMappings = deviceUserMappingMapper.selectList(wrapper);
log.info("用户登录查询映射结果:{}", JSONUtil.toJsonStr(deviceUserMappings)); log.info("用户登录查询映射结果:{}", JSONUtil.toJsonStr(deviceUserMappings));
List<User> users = new ArrayList<>(); List<User> users = new ArrayList<>();
List<Long> userIdList = deviceUserMappings.stream().map(DeviceUserMapping::getUserId).filter(Objects::nonNull).collect(Collectors.toList()); List<Long> userIdList = deviceUserMappings.stream().map(DeviceUserMapping::getUserId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
log.info("用户登录查询用户id结果:{}", JSONUtil.toJsonStr(userIdList)); log.info("用户登录查询用户id结果:{}", JSONUtil.toJsonStr(userIdList));
if (CollectionUtil.isNotEmpty(userIdList)) { if (CollectionUtil.isNotEmpty(userIdList)) {
QueryWrapper<User> groupWrapper = new QueryWrapper<>(); QueryWrapper<User> groupWrapper = new QueryWrapper<>();
String userListStr = StringUtils.join(userIdList, ","); groupWrapper.lambda().in(User::getId, userIdList);
log.info("用户id结果:{}", JSONUtil.toJsonStr(userListStr));
groupWrapper.lambda().in(User::getId, userListStr);
List<User> userList = userMapper.selectList(groupWrapper); List<User> userList = userMapper.selectList(groupWrapper);
log.info("用户id查询结果:{}", JSONUtil.toJsonStr(userList)); log.info("用户id查询结果:{}", JSONUtil.toJsonStr(userList));
if (CollectionUtil.isNotEmpty(userList)) { if (CollectionUtil.isNotEmpty(userList)) {
@ -162,13 +138,11 @@ public class DeviceUserMappingServiceImpl extends ServiceImpl<DeviceUserMappingM
} }
} }
List<Long> groupList = deviceUserMappings.stream().map(DeviceUserMapping::getUserGroupId).filter(Objects::nonNull).collect(Collectors.toList()); List<Long> groupList = deviceUserMappings.stream().map(DeviceUserMapping::getUserGroupId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
log.info("用户登录查询用户组id结果:{}", JSONUtil.toJsonStr(groupList)); log.info("用户登录查询用户组id结果:{}", JSONUtil.toJsonStr(groupList));
if (CollectionUtil.isNotEmpty(groupList)) { if (CollectionUtil.isNotEmpty(groupList)) {
QueryWrapper<User> groupWrapper = new QueryWrapper<>(); QueryWrapper<User> groupWrapper = new QueryWrapper<>();
String groupListStr = StringUtils.join(groupList, ","); groupWrapper.lambda().in(User::getUserGroupId, groupList);
log.info("用户组id结果:{}", JSONUtil.toJsonStr(groupListStr));
groupWrapper.lambda().in(User::getUserGroupId, groupListStr);
List<User> userDeviceGroups = userMapper.selectList(groupWrapper); List<User> userDeviceGroups = userMapper.selectList(groupWrapper);
log.info("用户组id查询结果:{}", JSONUtil.toJsonStr(userDeviceGroups)); log.info("用户组id查询结果:{}", JSONUtil.toJsonStr(userDeviceGroups));
if (CollectionUtil.isNotEmpty(userDeviceGroups)) { if (CollectionUtil.isNotEmpty(userDeviceGroups)) {
@ -186,7 +160,7 @@ public class DeviceUserMappingServiceImpl extends ServiceImpl<DeviceUserMappingM
return Result.errorResultMessage(BaseErrorCode.PARAMS_CHK_ERROR, "密码错误,请重新输入"); return Result.errorResultMessage(BaseErrorCode.PARAMS_CHK_ERROR, "密码错误,请重新输入");
} }
HashMap<String, Object> hashMap = new HashMap<>(); HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("token", users.get(0).getId()); hashMap.put("token", users.get(0).getId().toString());
return new Result<>("200", "登录成功", hashMap); return new Result<>("200", "登录成功", hashMap);
} }

View File

@ -66,39 +66,28 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, Image>
public Result<?> delete(DeleteIdReq deleteIdReq) { public Result<?> delete(DeleteIdReq deleteIdReq) {
Image image = imageMapper.selectById(deleteIdReq.getId()); Image image = imageMapper.selectById(deleteIdReq.getId());
if (ObjectUtils.isNotEmpty(image)) { if (ObjectUtils.isNotEmpty(image)) {
boolean cleanUploadFile = cleanUploadFile(image.getStoragePath(), image.getImageName()); try {
if (cleanUploadFile) { Path filePath = Paths.get(image.getStoragePath(), image.getImageName());
int deleted = imageMapper.deleteById(deleteIdReq.getId()); if (Files.exists(filePath)) {
log.info("镜像删除insert:{}", deleted); // 删除文件
if (deleted == 1) { Files.delete(filePath);
return Result.successResult(); log.info("已删除文件: {}", filePath);
int deleted = imageMapper.deleteById(deleteIdReq.getId());
log.info("镜像删除insert:{}", deleted);
if (deleted == 1) {
return Result.successResult();
}
} else {
log.warn("文件不存在,无需删除: {}", filePath);
return Result.errorResultMessage(BaseErrorCode.HTTP_ERROR_CODE_500, "文件不存在,无需删除");
} }
} catch (IOException e) {
log.error("删除文件失败: {}", e.getMessage(), e);
} }
} }
return Result.errorResult(BaseErrorCode.HTTP_ERROR_CODE_500); return Result.errorResultMessage(BaseErrorCode.HTTP_ERROR_CODE_500, "删除文件失败");
} }
/**
*
*
* @param fileName
*/
private boolean cleanUploadFile(String uploadDir, String fileName) {
try {
Path filePath = Paths.get(uploadDir, fileName);
if (Files.exists(filePath)) {
// 删除文件
Files.delete(filePath);
log.info("已删除文件: {}", filePath);
return true;
} else {
log.warn("文件不存在,无需删除: {}", filePath);
}
} catch (IOException e) {
log.error("删除文件失败: {}", e.getMessage(), e);
}
return false;
}
} }