feat(后端): 镜像调整
parent
2dd8de87de
commit
deb4e08ecf
|
@ -1,17 +1,17 @@
|
||||||
package com.unisinsight.project.controller;
|
package com.unisinsight.project.controller;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.unisinsight.project.entity.dao.Image;
|
import com.unisinsight.project.entity.dao.Image;
|
||||||
import com.unisinsight.project.exception.BaseErrorCode;
|
import com.unisinsight.project.exception.BaseErrorCode;
|
||||||
import com.unisinsight.project.exception.Result;
|
import com.unisinsight.project.exception.Result;
|
||||||
import com.unisinsight.project.mapper.ImageMapper;
|
import com.unisinsight.project.service.ImageService;
|
||||||
import com.unisinsight.project.util.DigestUtil;
|
import com.unisinsight.project.util.DigestUtil;
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
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.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
@ -27,7 +27,10 @@ import java.io.OutputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.*;
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@ -60,7 +63,7 @@ public class FileChunkController {
|
||||||
private final Map<String, FileUploadInfo> fileUploadMap = new ConcurrentHashMap<>();
|
private final Map<String, FileUploadInfo> fileUploadMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ImageMapper imageMapper;
|
private ImageService imageService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传文件分片
|
* 上传文件分片
|
||||||
|
@ -86,7 +89,8 @@ public class FileChunkController {
|
||||||
@ApiImplicitParam(name = "file_size", value = "文件总大小", required = true, dataType = "long", paramType = "query"),
|
@ApiImplicitParam(name = "file_size", value = "文件总大小", required = true, dataType = "long", paramType = "query"),
|
||||||
@ApiImplicitParam(name = "image_name", value = "镜像名称", required = true, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "image_name", value = "镜像名称", required = true, dataType = "String", paramType = "query"),
|
||||||
@ApiImplicitParam(name = "image_version", value = "镜像版本", required = true, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "image_version", value = "镜像版本", required = true, dataType = "String", paramType = "query"),
|
||||||
@ApiImplicitParam(name = "os_version", value = "操作系统", required = true, dataType = "String", paramType = "query")
|
@ApiImplicitParam(name = "os_version", value = "操作系统", required = true, dataType = "String", paramType = "query"),
|
||||||
|
@ApiImplicitParam(name = "description", value = "描述", required = true, dataType = "String", paramType = "query")
|
||||||
})
|
})
|
||||||
@ApiResponses({
|
@ApiResponses({
|
||||||
@ApiResponse(code = 200, message = "上传成功"),
|
@ApiResponse(code = 200, message = "上传成功"),
|
||||||
|
@ -103,8 +107,9 @@ public class FileChunkController {
|
||||||
@RequestParam("image_name") String imageName,
|
@RequestParam("image_name") String imageName,
|
||||||
@RequestParam("file_size") long totalSize,
|
@RequestParam("file_size") long totalSize,
|
||||||
@RequestParam("image_version") String imageVersion,
|
@RequestParam("image_version") String imageVersion,
|
||||||
@RequestParam("os_version") String osVersion
|
@RequestParam("os_version") String osVersion,
|
||||||
) {
|
@RequestParam("description") String description
|
||||||
|
) {
|
||||||
Map<String, Object> response = new HashMap<>();
|
Map<String, Object> response = new HashMap<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -113,10 +118,10 @@ public class FileChunkController {
|
||||||
log.info("分片文件md5校验失败,chunkMd5:{},md5:{}", chunkMd5, md5);
|
log.info("分片文件md5校验失败,chunkMd5:{},md5:{}", chunkMd5, md5);
|
||||||
throw new RuntimeException("分片文件md5校验失败");
|
throw new RuntimeException("分片文件md5校验失败");
|
||||||
}
|
}
|
||||||
QueryWrapper<Image> wrapper = new QueryWrapper<>();
|
LambdaQueryWrapper<Image> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.lambda().eq(Image::getImageName, fileName);
|
wrapper.eq(Image::getImageFileName, fileName);
|
||||||
List<Image> imageList = imageMapper.selectList(wrapper);
|
int count = imageService.count(wrapper);
|
||||||
if (CollectionUtil.isNotEmpty(imageList)) {
|
if (count > 0) {
|
||||||
response.put("success", false);
|
response.put("success", false);
|
||||||
response.put("status", "error");
|
response.put("status", "error");
|
||||||
response.put("message", "当前文件已经上传");
|
response.put("message", "当前文件已经上传");
|
||||||
|
@ -163,9 +168,12 @@ public class FileChunkController {
|
||||||
image.setOsVersion(osVersion);
|
image.setOsVersion(osVersion);
|
||||||
image.setStoragePath(String.valueOf(finalFilePath));
|
image.setStoragePath(String.valueOf(finalFilePath));
|
||||||
image.setImageStatus(1);
|
image.setImageStatus(1);
|
||||||
int insert = imageMapper.insert(image);
|
if (StringUtils.isNotBlank(description)) {
|
||||||
log.info("镜像新增insert:{}", insert);
|
image.setDescription(description);
|
||||||
if (insert == 1) {
|
}
|
||||||
|
boolean save = imageService.save(image);
|
||||||
|
log.info("镜像新增insert:{}", save);
|
||||||
|
if (save) {
|
||||||
|
|
||||||
// 异步执行创建和做种操作
|
// 异步执行创建和做种操作
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() -> {
|
||||||
|
@ -180,12 +188,12 @@ public class FileChunkController {
|
||||||
boolean result = Boolean.TRUE.equals(responseEntity.getBody());
|
boolean result = Boolean.TRUE.equals(responseEntity.getBody());
|
||||||
if (result) {
|
if (result) {
|
||||||
log.info("请求bt创建接口成功");
|
log.info("请求bt创建接口成功");
|
||||||
QueryWrapper<Image> imageQueryWrapper = new QueryWrapper<>();
|
LambdaQueryWrapper<Image> imageQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
imageQueryWrapper.lambda().eq(Image::getImageName, fileName);
|
imageQueryWrapper.eq(Image::getImageFileName, fileName);
|
||||||
Image imageBt = imageMapper.selectOne(imageQueryWrapper);
|
Image imageBt = imageService.getOne(imageQueryWrapper);
|
||||||
if (ObjectUtils.isNotEmpty(imageBt)) {
|
if (ObjectUtils.isNotEmpty(imageBt)) {
|
||||||
imageBt.setBtPath(finalFilePath + ".torrent");
|
imageBt.setBtPath(finalFilePath + ".torrent");
|
||||||
int update = imageMapper.updateById(imageBt);
|
boolean update = imageService.updateById(imageBt);
|
||||||
log.info("镜像bt更新insert:{}", update);
|
log.info("镜像bt更新insert:{}", update);
|
||||||
} else {
|
} else {
|
||||||
log.info("镜像bt更新查询失败:{}", fileName);
|
log.info("镜像bt更新查询失败:{}", fileName);
|
||||||
|
|
|
@ -9,17 +9,16 @@ import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @TableName image
|
* @TableName image
|
||||||
*/
|
*/
|
||||||
@TableName(value ="image")
|
@TableName(value = "image")
|
||||||
@Data
|
@Data
|
||||||
@ApiModel("镜像相关信息")
|
@ApiModel("镜像相关信息")
|
||||||
public class Image implements Serializable {
|
public class Image implements Serializable {
|
||||||
/**
|
/**
|
||||||
* ID
|
* ID
|
||||||
*/
|
*/
|
||||||
@TableId(value = "id",type = IdType.AUTO)
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
@ApiModelProperty("id")
|
@ApiModelProperty("id")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,12 @@ public class ImageReq implements Serializable {
|
||||||
@JsonProperty("storage_path")
|
@JsonProperty("storage_path")
|
||||||
private String storagePath;
|
private String storagePath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("描述")
|
||||||
|
@JsonProperty("description")
|
||||||
|
private String description;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询页
|
* 查询页
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.unisinsight.project.entity.res;
|
package com.unisinsight.project.entity.res;
|
||||||
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
@ -86,4 +85,11 @@ public class ImageRes implements Serializable {
|
||||||
@JsonProperty("create_time")
|
@JsonProperty("create_time")
|
||||||
private Date createTime;
|
private Date createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("描述")
|
||||||
|
@JsonProperty("description")
|
||||||
|
private String description;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, Image>
|
||||||
if (ObjectUtils.isNotEmpty(image)) {
|
if (ObjectUtils.isNotEmpty(image)) {
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
String url = btUrl + "/vdi/stop?sourceFile=%s";
|
String url = btUrl + "/vdi/stop?sourceFile=%s.torrent";
|
||||||
url = String.format(url, image.getStoragePath());
|
url = String.format(url, image.getStoragePath());
|
||||||
log.info("请求bt停止接口参数: {}", url);
|
log.info("请求bt停止接口参数: {}", url);
|
||||||
ResponseEntity<Boolean> responseEntity = restTemplate.exchange(url, HttpMethod.GET, null, Boolean.class);
|
ResponseEntity<Boolean> responseEntity = restTemplate.exchange(url, HttpMethod.GET, null, Boolean.class);
|
||||||
|
|
Loading…
Reference in New Issue