feat(后端): 联调修改1
parent
7e9be02d61
commit
b3304804a1
|
@ -18,9 +18,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
|
@ -68,11 +66,7 @@ public class ClientController {
|
|||
deviceUserReq.setDeviceId(loginReq.getDeviceId());
|
||||
deviceUserReq.setUserName(loginReq.getUsername());
|
||||
deviceUserReq.setPassword(loginReq.getPassword());
|
||||
//todo 后面再调
|
||||
// Result<?> result = deviceUserMappingService.loginUser(deviceUserReq);
|
||||
HashMap<String, Object> hashMap = new HashMap<>();
|
||||
hashMap.put("token", "123456");
|
||||
return Result.successResult(hashMap);
|
||||
return deviceUserMappingService.loginUser(deviceUserReq);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取镜像列表")
|
||||
|
@ -83,24 +77,23 @@ public class ClientController {
|
|||
}
|
||||
log.info("获取镜像列表请求参数为:{}", JSONUtil.toJsonStr(loginReq));
|
||||
|
||||
// Result<?> imageList = clientService.getImageList(loginReq.getDeviceId(), loginReq.getToken());
|
||||
List<HashMap<String, Object>> hashMaps = new ArrayList<>();
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
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");
|
||||
hashMaps.add(map);
|
||||
HashMap<String, Object> map1 = new HashMap<>();
|
||||
map1.put("name", "uos_nbd_20250806.qcow2");
|
||||
map1.put("torrent", "http://10.100.51.86:8114/api/vdi/file/down/win10_v2307_uefi_demo.vhdx.torrent");
|
||||
hashMaps.add(map1);
|
||||
HashMap<String, Object> map2 = new HashMap<>();
|
||||
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");
|
||||
hashMaps.add(map2);
|
||||
|
||||
HashMap<String, Object> hashMap = new HashMap<>();
|
||||
hashMap.put("list", hashMaps);
|
||||
return Result.successResult(hashMap);
|
||||
// List<HashMap<String, Object>> hashMaps = new ArrayList<>();
|
||||
// HashMap<String, Object> map = new HashMap<>();
|
||||
// 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");
|
||||
// hashMaps.add(map);
|
||||
// HashMap<String, Object> map1 = new HashMap<>();
|
||||
// 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");
|
||||
// hashMaps.add(map1);
|
||||
// HashMap<String, Object> map2 = new HashMap<>();
|
||||
// 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");
|
||||
// hashMaps.add(map2);
|
||||
//
|
||||
// HashMap<String, Object> hashMap = new HashMap<>();
|
||||
// hashMap.put("list", hashMaps);
|
||||
return clientService.getImageList(loginReq.getDeviceId(), loginReq.getToken());
|
||||
}
|
||||
|
||||
@ApiOperation(value = "版本更新")
|
||||
|
|
|
@ -48,7 +48,7 @@ public class DeviceImageMappingController {
|
|||
log.info("终端镜像映射新增请求参数为:{}", JSONUtil.toJsonStr(deviceImageMappingReq));
|
||||
|
||||
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<>();
|
||||
wrapper.lambda().eq(DeviceImageMapping::getDeviceId, reqData.get(0).getDeviceId());
|
||||
|
|
|
@ -47,7 +47,7 @@ public class DeviceUserMappingController {
|
|||
}
|
||||
log.info("终端用户映射新增请求参数为:{}", JSONUtil.toJsonStr(deviceUserMappingReq));
|
||||
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<>();
|
||||
wrapper.lambda().eq(DeviceUserMapping::getDeviceId, userMappingReqData.get(0).getDeviceId());
|
||||
|
@ -55,12 +55,14 @@ public class DeviceUserMappingController {
|
|||
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
Set<Long> requestIds = userMappingReqData.stream()
|
||||
.distinct()
|
||||
.map(DeviceUserMappingReq::getId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
List<Long> idsToDelete = list.stream()
|
||||
.map(DeviceUserMapping::getId)
|
||||
.distinct()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(id -> !requestIds.contains(id))
|
||||
.collect(Collectors.toList());
|
||||
|
@ -72,7 +74,7 @@ public class DeviceUserMappingController {
|
|||
}
|
||||
if (CollectionUtil.isNotEmpty(addList)) {
|
||||
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");
|
||||
}).collect(Collectors.toList());
|
||||
boolean insert = deviceUserMappingService.saveBatch(deviceUserMapping);
|
||||
|
|
|
@ -37,9 +37,9 @@ public class DeviceUserMappingRes implements Serializable {
|
|||
private Long deviceGroupId;
|
||||
|
||||
/**
|
||||
* 分组名称
|
||||
* 终端分组名称
|
||||
*/
|
||||
@ApiModelProperty("分组名称")
|
||||
@ApiModelProperty("终端分组名称")
|
||||
@JsonProperty("device_group_name")
|
||||
private String deviceGroupName;
|
||||
|
||||
|
@ -50,6 +50,14 @@ public class DeviceUserMappingRes implements Serializable {
|
|||
@JsonProperty("user_group_id")
|
||||
private Long userGroupId;
|
||||
|
||||
/**
|
||||
* 用户分组名称
|
||||
*/
|
||||
@ApiModelProperty("用户分组名称")
|
||||
@JsonProperty("user_group_name")
|
||||
private String userGroupName;
|
||||
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.springframework.stereotype.Service;
|
|||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
@ -46,12 +47,10 @@ public class ClientServiceImpl implements ClientService {
|
|||
if (CollectionUtil.isEmpty(deviceImageMappings)) {
|
||||
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<>();
|
||||
String imageListStr = StringUtils.join(imageIdList, ",");
|
||||
log.info("用户登录查询镜像id结果:{}", JSONUtil.toJsonStr(imageListStr));
|
||||
imageQueryWrapper.lambda().in(Image::getId, imageListStr);
|
||||
imageQueryWrapper.lambda().in(Image::getId, imageIdList);
|
||||
List<Image> images = imageMapper.selectList(imageQueryWrapper);
|
||||
log.info("用户登录查询镜像结果:{}", JSONUtil.toJsonStr(images));
|
||||
List<ImageRes> imageRes = BeanUtil.copyToList(images, ImageRes.class);
|
||||
|
@ -69,5 +68,7 @@ public class ClientServiceImpl implements ClientService {
|
|||
hashMap.put("list", collect);
|
||||
return Result.successResult(hashMap);
|
||||
}
|
||||
return Result.successResult();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.springframework.stereotype.Service;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
@ -59,9 +60,9 @@ public class DeviceImageMappingServiceImpl extends ServiceImpl<DeviceImageMappin
|
|||
return Result.successResult();
|
||||
} else {
|
||||
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)) {
|
||||
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);
|
||||
if (CollectionUtil.isNotEmpty(images)) {
|
||||
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)) {
|
||||
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);
|
||||
if (CollectionUtil.isNotEmpty(userDeviceGroups)) {
|
||||
deviceImageMappingRes.forEach(deviceImage -> {
|
||||
|
|
|
@ -48,6 +48,12 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device>
|
|||
@Override
|
||||
public Result<?> insert(DeviceReq deviceReq) {
|
||||
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");
|
||||
int insert = deviceMapper.insert(device);
|
||||
log.info("终端新增insert:{}", insert);
|
||||
|
@ -111,7 +117,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device>
|
|||
} else {
|
||||
PageResult<DeviceRes> convert = PageResult.convertIPage(userPage, DeviceRes.class);
|
||||
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<>();
|
||||
wrapper.lambda().in(UserDeviceGroup::getId, deviceIdList);
|
||||
List<UserDeviceGroup> userDeviceGroups = groupMapper.selectList(wrapper);
|
||||
|
|
|
@ -20,7 +20,6 @@ import com.unisinsight.project.mapper.UserMapper;
|
|||
import com.unisinsight.project.service.DeviceUserMappingService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -70,9 +69,8 @@ public class DeviceUserMappingServiceImpl extends ServiceImpl<DeviceUserMappingM
|
|||
return Result.successResult();
|
||||
} else {
|
||||
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));
|
||||
|
||||
List<Long> userList = deviceUserMappingRes.stream().map(DeviceUserMappingRes::getUserId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(userList)) {
|
||||
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
|
||||
userQueryWrapper.lambda().in(User::getId, userList);
|
||||
|
@ -86,8 +84,7 @@ public class DeviceUserMappingServiceImpl extends ServiceImpl<DeviceUserMappingM
|
|||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
List<Long> deviceList = deviceUserMappingRes.stream().distinct().map(DeviceUserMappingRes::getDeviceGroupId).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
deviceList = new ArrayList<>(new HashSet<>(deviceList));
|
||||
List<Long> deviceList = deviceUserMappingRes.stream().map(DeviceUserMappingRes::getDeviceGroupId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(deviceList)) {
|
||||
QueryWrapper<UserDeviceGroup> groupQueryWrapper = new QueryWrapper<>();
|
||||
groupQueryWrapper.lambda().in(UserDeviceGroup::getId, deviceList);
|
||||
|
@ -100,38 +97,21 @@ public class DeviceUserMappingServiceImpl extends ServiceImpl<DeviceUserMappingM
|
|||
}
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
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);
|
||||
} 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<>();
|
||||
userQueryWrapper.lambda().in(User::getId, userList);
|
||||
List<User> users = userMapper.selectList(userQueryWrapper);
|
||||
List<DeviceUserMappingRes> collect = 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());
|
||||
return Result.successResult(collect);
|
||||
} else {
|
||||
List<Long> deviceList = deviceUserMappingRes.stream().distinct().map(DeviceUserMappingRes::getDeviceGroupId).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
deviceList = new ArrayList<>(new HashSet<>(deviceList));
|
||||
QueryWrapper<UserDeviceGroup> groupQueryWrapper = new QueryWrapper<>();
|
||||
groupQueryWrapper.lambda().eq(UserDeviceGroup::getType, 1);
|
||||
groupQueryWrapper.lambda().in(UserDeviceGroup::getId, deviceList);
|
||||
List<UserDeviceGroup> userDeviceGroups = groupMapper.selectList(groupQueryWrapper);
|
||||
List<DeviceUserMappingRes> collect = 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(collect);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -140,20 +120,16 @@ public class DeviceUserMappingServiceImpl extends ServiceImpl<DeviceUserMappingM
|
|||
@Override
|
||||
public Result<?> loginUser(DeviceUserReq deviceUserReq) {
|
||||
QueryWrapper<DeviceUserMapping> wrapper = new QueryWrapper<>();
|
||||
|
||||
wrapper.lambda().eq(DeviceUserMapping::getDeviceId, deviceUserReq.getDeviceId());
|
||||
|
||||
List<DeviceUserMapping> deviceUserMappings = deviceUserMappingMapper.selectList(wrapper);
|
||||
log.info("用户登录查询映射结果:{}", JSONUtil.toJsonStr(deviceUserMappings));
|
||||
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));
|
||||
if (CollectionUtil.isNotEmpty(userIdList)) {
|
||||
QueryWrapper<User> groupWrapper = new QueryWrapper<>();
|
||||
String userListStr = StringUtils.join(userIdList, ",");
|
||||
log.info("用户id结果:{}", JSONUtil.toJsonStr(userListStr));
|
||||
groupWrapper.lambda().in(User::getId, userListStr);
|
||||
groupWrapper.lambda().in(User::getId, userIdList);
|
||||
List<User> userList = userMapper.selectList(groupWrapper);
|
||||
log.info("用户id查询结果:{}", JSONUtil.toJsonStr(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));
|
||||
if (CollectionUtil.isNotEmpty(groupList)) {
|
||||
QueryWrapper<User> groupWrapper = new QueryWrapper<>();
|
||||
String groupListStr = StringUtils.join(groupList, ",");
|
||||
log.info("用户组id结果:{}", JSONUtil.toJsonStr(groupListStr));
|
||||
groupWrapper.lambda().in(User::getUserGroupId, groupListStr);
|
||||
groupWrapper.lambda().in(User::getUserGroupId, groupList);
|
||||
List<User> userDeviceGroups = userMapper.selectList(groupWrapper);
|
||||
log.info("用户组id查询结果:{}", JSONUtil.toJsonStr(userDeviceGroups));
|
||||
if (CollectionUtil.isNotEmpty(userDeviceGroups)) {
|
||||
|
@ -186,7 +160,7 @@ public class DeviceUserMappingServiceImpl extends ServiceImpl<DeviceUserMappingM
|
|||
return Result.errorResultMessage(BaseErrorCode.PARAMS_CHK_ERROR, "密码错误,请重新输入");
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -66,39 +66,28 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, Image>
|
|||
public Result<?> delete(DeleteIdReq deleteIdReq) {
|
||||
Image image = imageMapper.selectById(deleteIdReq.getId());
|
||||
if (ObjectUtils.isNotEmpty(image)) {
|
||||
boolean cleanUploadFile = cleanUploadFile(image.getStoragePath(), image.getImageName());
|
||||
if (cleanUploadFile) {
|
||||
try {
|
||||
Path filePath = Paths.get(image.getStoragePath(), image.getImageName());
|
||||
if (Files.exists(filePath)) {
|
||||
// 删除文件
|
||||
Files.delete(filePath);
|
||||
log.info("已删除文件: {}", filePath);
|
||||
int deleted = imageMapper.deleteById(deleteIdReq.getId());
|
||||
log.info("镜像删除insert:{}", deleted);
|
||||
if (deleted == 1) {
|
||||
return Result.successResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.errorResult(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);
|
||||
return Result.errorResultMessage(BaseErrorCode.HTTP_ERROR_CODE_500, "文件不存在,无需删除");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("删除文件失败: {}", e.getMessage(), e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return Result.errorResultMessage(BaseErrorCode.HTTP_ERROR_CODE_500, "删除文件失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue