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