From 944c3cc919544602547dbf56e6b91fdbaccc5710 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Tue, 3 Jun 2025 09:29:29 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=88=86=E7=89=87?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=EF=BC=8C=E6=96=AD=E7=82=B9=E7=BB=AD=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/file/FileController.java | 200 ++++++++++++++++++ .../com/ruoyi/platform/domain/TChunkInfo.java | 142 +++++++++++++ .../com/ruoyi/platform/domain/TFileInfo.java | 161 ++++++++++++++ .../ruoyi/platform/domain/UploadResult.java | 69 ++++++ .../ruoyi/platform/mapper/TChunkInfoDao.java | 23 ++ .../ruoyi/platform/mapper/TFileInfoDao.java | 27 +++ .../ruoyi/platform/service/ChunkService.java | 36 ++++ .../platform/service/FileInfoService.java | 29 +++ .../service/impl/ChunkServiceImpl.java | 34 +++ .../service/impl/FileInfoServiceImpl.java | 46 ++++ .../ruoyi/platform/utils/FileInfoUtils.java | 97 +++++++++ .../ruoyi/platform/utils/ServletUtils.java | 41 ++++ .../platform/utils/SnowflakeIdWorker.java | 149 +++++++++++++ .../com/ruoyi/platform/vo/TFileInfoVO.java | 92 ++++++++ .../managementPlatform/TChunkInfoMapper.xml | 150 +++++++++++++ .../managementPlatform/TFileInfoMapper.xml | 178 ++++++++++++++++ 16 files changed, 1474 insertions(+) create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/file/FileController.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/TChunkInfo.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/TFileInfo.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/UploadResult.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/TChunkInfoDao.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/TFileInfoDao.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ChunkService.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/FileInfoService.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ChunkServiceImpl.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/FileInfoServiceImpl.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/FileInfoUtils.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/ServletUtils.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/SnowflakeIdWorker.java create mode 100644 ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/TFileInfoVO.java create mode 100644 ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/TChunkInfoMapper.xml create mode 100644 ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/TFileInfoMapper.xml diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/file/FileController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/file/FileController.java new file mode 100644 index 00000000..d47cb479 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/file/FileController.java @@ -0,0 +1,200 @@ +package com.ruoyi.platform.controller.file; + +import com.ruoyi.common.core.web.controller.BaseController; +import com.ruoyi.common.core.web.domain.GenericsAjaxResult; +import com.ruoyi.platform.domain.TChunkInfo; +import com.ruoyi.platform.domain.TFileInfo; +import com.ruoyi.platform.domain.UploadResult; +import com.ruoyi.platform.service.ChunkService; +import com.ruoyi.platform.service.FileInfoService; +import com.ruoyi.platform.utils.FileInfoUtils; +import com.ruoyi.platform.utils.ServletUtils; +import com.ruoyi.platform.vo.TFileInfoVO; +import io.swagger.annotations.Api; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; + +/** + * 上传下载文件 + * @author JaredJia + * + */ +@RestController +@RequestMapping("/uploader") +@Api("文件上传") +public class FileController extends BaseController { + + @Value("${git.localPath}/temp") + String uploadFolder; + + @Resource + private FileInfoService fileInfoService; + + @Resource + private ChunkService chunkService; + + private final Logger logger = LoggerFactory.getLogger(FileController.class); + + /** + * 上传文件块 + * @param chunk + * @return + */ + @PostMapping("/chunk") + public GenericsAjaxResult uploadChunk(TChunkInfo chunk) throws IOException { + String apiRlt = "200"; + + MultipartFile file = chunk.getUpfile(); + logger.info("file originName: {}, chunkNumber: {}", file.getOriginalFilename(), chunk.getChunkNumber()); + + try { + byte[] bytes = file.getBytes(); + Path path = Paths.get(FileInfoUtils.generatePath(uploadFolder, chunk)); + //文件写入指定路径 + Files.write(path, bytes); + if(chunkService.saveChunk(chunk) < 0) apiRlt = "415"; + + } catch (IOException e) { + throw new IOException(e.getMessage()); + } + return genericsSuccess(apiRlt); + } + + @GetMapping("/chunk") + public GenericsAjaxResult checkChunk(TChunkInfo chunk, HttpServletResponse response) { + UploadResult ur = new UploadResult(); + + //默认返回其他状态码,前端不进去checkChunkUploadedByResponse函数,正常走标准上传 + response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); + + String file = uploadFolder + "/" + chunk.getIdentifier() + "/" + chunk.getFilename(); + + //先判断整个文件是否已经上传过了,如果是,则告诉前端跳过上传,实现秒传 + if(FileInfoUtils.fileExists(file)) { + ur.setSkipUpload(true); + ur.setLocation(file); + response.setStatus(HttpServletResponse.SC_OK); + ur.setMessage("完整文件已存在,直接跳过上传,实现秒传"); + return genericsSuccess(ur); + } + + //如果完整文件不存在,则去数据库判断当前哪些文件块已经上传过了,把结果告诉前端,跳过这些文件块的上传,实现断点续传 + ArrayList list = chunkService.checkChunk(chunk); + if (list !=null && list.size() > 0) { + ur.setSkipUpload(false); + ur.setUploadedChunks(list); + response.setStatus(HttpServletResponse.SC_OK); + ur.setMessage("部分文件块已存在,继续上传剩余文件块,实现断点续传"); + return genericsSuccess(ur); + } + return genericsSuccess(ur); + } + + @PostMapping("/mergeFile") + public GenericsAjaxResult mergeFile(@RequestBody TFileInfoVO fileInfoVO){ + + String rlt = "FAILURE"; + + //前端组件参数转换为model对象 + TFileInfo fileInfo = new TFileInfo(); + fileInfo.setFilename(fileInfoVO.getName()); + fileInfo.setIdentifier(fileInfoVO.getUniqueIdentifier()); + fileInfo.setId(fileInfoVO.getId()); + fileInfo.setTotalSize(fileInfoVO.getSize()); + fileInfo.setRefProjectId(fileInfoVO.getRefProjectId()); + + //进行文件的合并操作 + String filename = fileInfo.getFilename(); + String file = uploadFolder + "/" + fileInfo.getIdentifier() + "/" + filename; + String folder = uploadFolder + "/" + fileInfo.getIdentifier(); + String fileSuccess = FileInfoUtils.merge(file, folder, filename); + + fileInfo.setLocation(file); + + //文件合并成功后,保存记录至数据库 + if("200".equals(fileSuccess)) { + if(fileInfoService.addFileInfo(fileInfo) > 0) rlt = "SUCCESS"; + } + + //如果已经存在,则判断是否同一个项目,同一个项目的不用新增记录,否则新增 + if("300".equals(fileSuccess)) { + List tfList = fileInfoService.selectFileByParams(fileInfo); + if(tfList != null) { + if(tfList.size() == 0 || (tfList.size() > 0 && !fileInfo.getRefProjectId().equals(tfList.get(0).getRefProjectId()))) { + if(fileInfoService.addFileInfo(fileInfo) > 0) rlt = "SUCCESS"; + } + } + } + + return genericsSuccess(fileInfo); + } + + /** + * 查询列表 + * + * @return ApiResult + */ + @RequestMapping(value = "/selectFileList", method = RequestMethod.GET) + public GenericsAjaxResult> selectFileList(TFileInfo file){ + List list = fileInfoService.selectFileList(file); + return genericsSuccess(list); + } + + /** + * 下载文件 + * @param req + * @param resp + */ + @RequestMapping(value = "/download", method = RequestMethod.GET) + public void download(HttpServletRequest req, HttpServletResponse resp){ + String location = req.getParameter("location"); + String fileName = req.getParameter("filename"); + BufferedInputStream bis = null; + BufferedOutputStream bos = null; + OutputStream fos = null; + try { + bis = new BufferedInputStream(new FileInputStream(location)); + fos = resp.getOutputStream(); + bos = new BufferedOutputStream(fos); + ServletUtils.setFileDownloadHeader(req, resp, fileName); + int byteRead = 0; + byte[] buffer = new byte[8192]; + while ((byteRead = bis.read(buffer, 0, 8192)) != -1) { + bos.write(buffer, 0, byteRead); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + bos.flush(); + bis.close(); + fos.close(); + bos.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + /** + * 删除 + */ + @RequestMapping(value = "/deleteFile", method = RequestMethod.POST) + public GenericsAjaxResult deleteFile(@RequestBody TFileInfo tFileInfo ){ + int result = fileInfoService.deleteFile(tFileInfo); + return genericsSuccess(result); + } +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/TChunkInfo.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/TChunkInfo.java new file mode 100644 index 00000000..900bde90 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/TChunkInfo.java @@ -0,0 +1,142 @@ +package com.ruoyi.platform.domain; + +import org.springframework.web.multipart.MultipartFile; + +import java.io.Serializable; + +public class TChunkInfo implements Serializable { + + private static final long serialVersionUID = 1L; + + private String id; + /** + * 当前文件块,从1开始 + */ + private Integer chunkNumber; + /** + * 每块大小 + */ + private Long chunkSize; + /** + * 当前分块大小 + */ + private Long currentChunkSize; + /** + * 总大小 + */ + private Long totalSize; + /** + * 文件标识 + */ + private String identifier; + /** + * 文件名 + */ + private String filename; + /** + * 相对路径 + */ + private String relativePath; + /** + * 总块数 + */ + private Integer totalChunks; + /** + * 文件类型 + */ + private String type; + + /** + * 块内容 + */ + private transient MultipartFile upfile; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Integer getChunkNumber() { + return chunkNumber; + } + + public void setChunkNumber(Integer chunkNumber) { + this.chunkNumber = chunkNumber; + } + + public Long getChunkSize() { + return chunkSize; + } + + public void setChunkSize(Long chunkSize) { + this.chunkSize = chunkSize; + } + + public Long getCurrentChunkSize() { + return currentChunkSize; + } + + public void setCurrentChunkSize(Long currentChunkSize) { + this.currentChunkSize = currentChunkSize; + } + + public Long getTotalSize() { + return totalSize; + } + + public void setTotalSize(Long totalSize) { + this.totalSize = totalSize; + } + + public String getIdentifier() { + return identifier; + } + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + public String getFilename() { + return filename; + } + + public void setFilename(String filename) { + this.filename = filename; + } + + public String getRelativePath() { + return relativePath; + } + + public void setRelativePath(String relativePath) { + this.relativePath = relativePath; + } + + public Integer getTotalChunks() { + return totalChunks; + } + + public void setTotalChunks(Integer totalChunks) { + this.totalChunks = totalChunks; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public MultipartFile getUpfile() { + return upfile; + } + + public void setUpfile(MultipartFile upfile) { + this.upfile = upfile; + } + +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/TFileInfo.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/TFileInfo.java new file mode 100644 index 00000000..40afc9bd --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/TFileInfo.java @@ -0,0 +1,161 @@ +package com.ruoyi.platform.domain; + +import java.io.Serializable; +import java.util.Date; + +/** + * 文件模型 + * @author JaredJia + * + */ +public class TFileInfo implements Serializable { + + private static final long serialVersionUID = 6969462437970901728L; + + //附件编号 + private String id; + + //附件名称 + private String filename; + + private String nameSearch; + + //附件MD5标识 + private String identifier; + + //附件总大小 + private Long totalSize; + + private String totalSizeName; + + //附件类型 + private String type; + + //附件存储地址 + private String location; + + //删除标志 + private String delFlag; + + //文件所属目标(项目、学生、档案等,预留字段) + private String refProjectId; + + //上传人 + private String uploadBy; + + //上传时间 + private Date uploadTime; + + private String uploadTimeString; + + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getFilename() { + return filename; + } + + public void setFilename(String filename) { + this.filename = filename; + } + + public String getNameSearch() { + return nameSearch; + } + + public void setNameSearch(String nameSearch) { + this.nameSearch = nameSearch; + } + + public String getIdentifier() { + return identifier; + } + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + public Long getTotalSize() { + return totalSize; + } + + public void setTotalSize(Long totalSize) { + this.totalSize = totalSize; + if(1024*1024 > this.totalSize && this.totalSize >= 1024 ) { + this.totalSizeName = String.format("%.2f",this.totalSize.doubleValue()/1024) + "KB"; + }else if(1024*1024*1024 > this.totalSize && this.totalSize >= 1024*1024 ) { + this.totalSizeName = String.format("%.2f",this.totalSize.doubleValue()/(1024*1024)) + "MB"; + }else if(this.totalSize >= 1024*1024*1024 ) { + this.totalSizeName = String.format("%.2f",this.totalSize.doubleValue()/(1024*1024*1024)) + "GB"; + }else { + this.totalSizeName = this.totalSize.toString() + "B"; + } + } + + public String getTotalSizeName() { + return totalSizeName; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public String getDelFlag() { + return delFlag; + } + + public void setDelFlag(String delFlag) { + this.delFlag = delFlag; + } + + public String getRefProjectId() { + return refProjectId; + } + + public void setRefProjectId(String refProjectId) { + this.refProjectId = refProjectId; + } + + public String getUploadBy() { + return uploadBy; + } + + public void setUploadBy(String uploadBy) { + this.uploadBy = uploadBy; + } + + public Date getUploadTime() { + return uploadTime; + } + + public void setUploadTime(Date uploadTime) { + this.uploadTime = uploadTime; + } + + public String getUploadTimeString() { + return uploadTimeString; + } + + public void setUploadTimeString(String uploadTimeString) { + this.uploadTimeString = uploadTimeString; + } + +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/UploadResult.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/UploadResult.java new file mode 100644 index 00000000..029ede5a --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/UploadResult.java @@ -0,0 +1,69 @@ +package com.ruoyi.platform.domain; + +import java.io.Serializable; +import java.util.ArrayList; + +/** + * 文件上传结果 + * @author JaredJia + * + */ +public class UploadResult implements Serializable { + + private static final long serialVersionUID = -9000695051292877324L; + + //是否跳过上传(已上传的可以直接跳过,达到秒传的效果) + private boolean skipUpload; + + //已经上传的文件块编号,可以跳过,断点续传 + private ArrayList uploadedChunks; + + //返回结果码 + private String status; + + //返回结果信息 + private String message; + + //已上传完整附件的地址 + private String location; + + public boolean isSkipUpload() { + return skipUpload; + } + + public void setSkipUpload(boolean skipUpload) { + this.skipUpload = skipUpload; + } + + public ArrayList getUploadedChunks() { + return uploadedChunks; + } + + public void setUploadedChunks(ArrayList uploadedChunks) { + this.uploadedChunks = uploadedChunks; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/TChunkInfoDao.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/TChunkInfoDao.java new file mode 100644 index 00000000..fb5bbb7a --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/TChunkInfoDao.java @@ -0,0 +1,23 @@ +package com.ruoyi.platform.mapper; + +import com.ruoyi.platform.domain.TChunkInfo; +import org.apache.ibatis.annotations.Mapper; + +import java.util.ArrayList; + +@Mapper +public interface TChunkInfoDao { + int deleteByPrimaryKey(String id); + + int insert(TChunkInfo record); + + int insertSelective(TChunkInfo record); + + TChunkInfo selectByPrimaryKey(String id); + + int updateByPrimaryKeySelective(TChunkInfo record); + + int updateByPrimaryKey(TChunkInfo record); + + ArrayList selectChunkNumbers(TChunkInfo record); +} \ No newline at end of file diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/TFileInfoDao.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/TFileInfoDao.java new file mode 100644 index 00000000..bf85e32f --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/mapper/TFileInfoDao.java @@ -0,0 +1,27 @@ +package com.ruoyi.platform.mapper; + +import com.ruoyi.platform.domain.TFileInfo; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface TFileInfoDao { + + int deleteByPrimaryKey(String id); + + int insert(TFileInfo record); + + int insertSelective(TFileInfo record); + + TFileInfo selectByPrimaryKey(String id); + + int updateByPrimaryKeySelective(TFileInfo record); + + int updateByPrimaryKey(TFileInfo record); + + List selectFileByParams(TFileInfo fileInfo); + + List selectFileList(TFileInfo fileInfo); + +} \ No newline at end of file diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ChunkService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ChunkService.java new file mode 100644 index 00000000..418fd1e4 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ChunkService.java @@ -0,0 +1,36 @@ +package com.ruoyi.platform.service; + + +import com.ruoyi.platform.domain.TChunkInfo; + +import java.util.ArrayList; + +/** + * 文件块处理 + * @author JaredJia + * + */ +public interface ChunkService { + /** + * 保存文件块 + * + * @param chunk + */ + public int saveChunk(TChunkInfo chunk); + + /** + * 检查文件块是否存在 + * + * @param identifier + * @param chunkNumber + * @return + */ + boolean checkChunk(String identifier, Integer chunkNumber); + + /** + * 查询哪些文件块已经上传 + * @param chunk + * @return + */ + public ArrayList checkChunk(TChunkInfo chunk); +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/FileInfoService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/FileInfoService.java new file mode 100644 index 00000000..89577772 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/FileInfoService.java @@ -0,0 +1,29 @@ +package com.ruoyi.platform.service; + + +import com.ruoyi.platform.domain.TFileInfo; + +import java.util.List; + +public interface FileInfoService { + + public int addFileInfo(TFileInfo fileInfo); + + public List selectFileByParams(TFileInfo fileInfo); + + /** + * 查询 + * + * @param File 查询条件 + * @return List + */ + List selectFileList(TFileInfo file); + + + /** + * 删除 + * @param TFileInfo + * @return + */ + int deleteFile(TFileInfo tFileInfo); +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ChunkServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ChunkServiceImpl.java new file mode 100644 index 00000000..2974aafc --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ChunkServiceImpl.java @@ -0,0 +1,34 @@ +package com.ruoyi.platform.service.impl; + +import com.ruoyi.platform.domain.TChunkInfo; +import com.ruoyi.platform.mapper.TChunkInfoDao; +import com.ruoyi.platform.service.ChunkService; +import com.ruoyi.platform.utils.SnowflakeIdWorker; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.ArrayList; + +@Service +public class ChunkServiceImpl implements ChunkService { + + @Resource + TChunkInfoDao tChunkInfoMapper; + + @Override + public int saveChunk(TChunkInfo chunk) { + chunk.setId(SnowflakeIdWorker.getUUID()+ SnowflakeIdWorker.getUUID()); + return tChunkInfoMapper.insertSelective(chunk); + } + + @Override + public ArrayList checkChunk(TChunkInfo chunk) { + return tChunkInfoMapper.selectChunkNumbers(chunk); + } + + @Override + public boolean checkChunk(String identifier, Integer chunkNumber) { + return false; + } + +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/FileInfoServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/FileInfoServiceImpl.java new file mode 100644 index 00000000..cbbf5c04 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/FileInfoServiceImpl.java @@ -0,0 +1,46 @@ +package com.ruoyi.platform.service.impl; + +import com.ruoyi.platform.domain.TFileInfo; +import com.ruoyi.platform.mapper.TFileInfoDao; +import com.ruoyi.platform.service.FileInfoService; +import com.ruoyi.platform.utils.SnowflakeIdWorker; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 文件处理类 + * @author JaredJia + * + */ +@Service +public class FileInfoServiceImpl implements FileInfoService { + + @Resource + TFileInfoDao tFileInfoMapper; + + @Override + public int addFileInfo(TFileInfo fileInfo) { + fileInfo.setId(SnowflakeIdWorker.getUUID()+SnowflakeIdWorker.getUUID()); + return tFileInfoMapper.insertSelective(fileInfo); + } + + @Override + public List selectFileByParams(TFileInfo fileInfo) { + return tFileInfoMapper.selectFileByParams(fileInfo); + } + + @Override + public List selectFileList(TFileInfo file) { + return tFileInfoMapper.selectFileList(file); + } + + @Override + public int deleteFile(TFileInfo tFileInfo) { + TFileInfo t = new TFileInfo(); + t.setId(tFileInfo.getId()); + t.setDelFlag("1"); + return tFileInfoMapper.updateByPrimaryKeySelective(t); + } +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/FileInfoUtils.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/FileInfoUtils.java new file mode 100644 index 00000000..3cb35965 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/FileInfoUtils.java @@ -0,0 +1,97 @@ +package com.ruoyi.platform.utils; + +import com.ruoyi.platform.domain.TChunkInfo; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.nio.file.*; + +/** + * 文件工具类 + * @author JaredJia + * + */ +public class FileInfoUtils { + + private final static Logger logger = LoggerFactory.getLogger(FileInfoUtils.class); + + public static String generatePath(String uploadFolder, TChunkInfo chunk) { + StringBuilder sb = new StringBuilder(); + sb.append(uploadFolder).append("/").append(chunk.getIdentifier()); + //判断uploadFolder/identifier 路径是否存在,不存在则创建 + if (!Files.isWritable(Paths.get(sb.toString()))) { + logger.info("path not exist,create path: {}", sb.toString()); + try { + Files.createDirectories(Paths.get(sb.toString())); + } catch (IOException e) { + logger.error(e.getMessage(), e); + } + } + + return sb.append("/") + .append(chunk.getFilename()) + .append("-") + .append(chunk.getChunkNumber()).toString(); + } + + /** + * 文件合并 + * + * @param targetFile + * @param folder + */ + public static String merge(String file, String folder, String filename){ + //默认合并成功 + String rlt = "200"; + + try { + //先判断文件是否存在 + if(fileExists(file)) { + //文件已存在 + rlt = "300"; + }else { + //不存在的话,进行合并 + Files.createFile(Paths.get(file)); + + Files.list(Paths.get(folder)) + .filter(path -> !path.getFileName().toString().equals(filename)) + .sorted((o1, o2) -> { + String p1 = o1.getFileName().toString(); + String p2 = o2.getFileName().toString(); + int i1 = p1.lastIndexOf("-"); + int i2 = p2.lastIndexOf("-"); + return Integer.valueOf(p2.substring(i2)).compareTo(Integer.valueOf(p1.substring(i1))); + }) + .forEach(path -> { + try { + //以追加的形式写入文件 + Files.write(Paths.get(file), Files.readAllBytes(path), StandardOpenOption.APPEND); + //合并后删除该块 + Files.delete(path); + } catch (IOException e) { + logger.error(e.getMessage(), e); + } + }); + } + } catch (IOException e) { + logger.error(e.getMessage(), e); + //合并失败 + rlt = "400"; + } + + return rlt; + } + + /** + * 根据文件的全路径名判断文件是否存在 + * @param file + * @return + */ + public static boolean fileExists(String file) { + boolean fileExists = false; + Path path = Paths.get(file); + fileExists = Files.exists(path,new LinkOption[]{ LinkOption.NOFOLLOW_LINKS}); + return fileExists; + } +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/ServletUtils.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/ServletUtils.java new file mode 100644 index 00000000..5d592122 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/ServletUtils.java @@ -0,0 +1,41 @@ +package com.ruoyi.platform.utils; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.net.URLEncoder; + +/** + * Servlet工具类 + * + * @author JaredJia + */ +public class ServletUtils { + + /** + * 文件下载时用于写文件头部信息 + * @param request http请求 + * @param response http响应 + * @param fileName 文件名 + */ + public static void setFileDownloadHeader(HttpServletRequest request, + HttpServletResponse response, String fileName) { + try { + String encodedFileName = null; + String agent = request.getHeader("USER-AGENT"); + if (null != agent && -1 != agent.indexOf("MSIE")) { + encodedFileName = URLEncoder.encode(fileName, "UTF-8"); + } else if (null != agent && -1 != agent.indexOf("Mozilla")) { + encodedFileName = new String(fileName.getBytes("UTF-8"), + "iso-8859-1"); + } else { + encodedFileName = URLEncoder.encode(fileName, "UTF-8"); + } + + response.setHeader("Content-Disposition", "attachment; filename=\"" + + encodedFileName + "\""); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/SnowflakeIdWorker.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/SnowflakeIdWorker.java new file mode 100644 index 00000000..9c251c39 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/SnowflakeIdWorker.java @@ -0,0 +1,149 @@ +package com.ruoyi.platform.utils; + +/** + * 雪花算法生成uuid + * + * @author JaredJia + */ +public class SnowflakeIdWorker { + + // ==============================Fields=========================================== + /** 开始时间截 (2015-01-01) */ + private final long twepoch = 1420041600000L; + + /** 机器id所占的位数 */ + private final long workerIdBits = 5L; + + /** 数据标识id所占的位数 */ + private final long datacenterIdBits = 5L; + + /** 支持的最大机器id,结果是31 (这个移位算法可以很快的计算出几位二进制数所能表示的最大十进制数) */ + private final long maxWorkerId = -1L ^ (-1L << workerIdBits); + + /** 支持的最大数据标识id,结果是31 */ + private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits); + + /** 序列在id中占的位数 */ + private final long sequenceBits = 12L; + + /** 机器ID向左移12位 */ + private final long workerIdShift = sequenceBits; + + /** 数据标识id向左移17位(12+5) */ + private final long datacenterIdShift = sequenceBits + workerIdBits; + + /** 时间截向左移22位(5+5+12) */ + private final long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits; + + /** 生成序列的掩码,这里为4095 (0b111111111111=0xfff=4095) */ + private final long sequenceMask = -1L ^ (-1L << sequenceBits); + + /** 工作机器ID(0~31) */ + private long workerId; + + /** 数据中心ID(0~31) */ + private long datacenterId; + + /** 毫秒内序列(0~4095) */ + private long sequence = 0L; + + /** 上次生成ID的时间截 */ + private long lastTimestamp = -1L; + + // ==============================Constructors===================================== + /** + * 构造函数 + * + * @param workerId + * 工作ID (0~31) + * @param datacenterId + * 数据中心ID (0~31) + */ + public SnowflakeIdWorker(long workerId, long datacenterId) { + if (workerId > maxWorkerId || workerId < 0) { + throw new IllegalArgumentException( + String.format("worker Id can't be greater than %d or less than 0", maxWorkerId)); + } + if (datacenterId > maxDatacenterId || datacenterId < 0) { + throw new IllegalArgumentException( + String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId)); + } + this.workerId = workerId; + this.datacenterId = datacenterId; + } + + // ==============================Methods========================================== + /** + * 获得下一个ID (该方法是线程安全的) + * + * @return SnowflakeId + */ + public synchronized long nextId() { + long timestamp = timeGen(); + + // 如果当前时间小于上一次ID生成的时间戳,说明系统时钟回退过这个时候应当抛出异常 + if (timestamp < lastTimestamp) { + throw new RuntimeException(String.format( + "Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp)); + } + + // 如果是同一时间生成的,则进行毫秒内序列 + if (lastTimestamp == timestamp) { + sequence = (sequence + 1) & sequenceMask; + // 毫秒内序列溢出 + if (sequence == 0) { + // 阻塞到下一个毫秒,获得新的时间戳 + timestamp = tilNextMillis(lastTimestamp); + } + } + // 时间戳改变,毫秒内序列重置 + else { + sequence = 0L; + } + + // 上次生成ID的时间截 + lastTimestamp = timestamp; + + // 移位并通过或运算拼到一起组成64位的ID + return ((timestamp - twepoch) << timestampLeftShift) // + | (datacenterId << datacenterIdShift) // + | (workerId << workerIdShift) // + | sequence; + } + + /** + * 阻塞到下一个毫秒,直到获得新的时间戳 + * + * @param lastTimestamp + * 上次生成ID的时间截 + * @return 当前时间戳 + */ + protected long tilNextMillis(long lastTimestamp) { + long timestamp = timeGen(); + while (timestamp <= lastTimestamp) { + timestamp = timeGen(); + } + return timestamp; + } + + /** + * 返回以毫秒为单位的当前时间 + * + * @return 当前时间(毫秒) + */ + protected long timeGen() { + return System.currentTimeMillis(); + } + + /** + * 获取UUID + * + * @return + */ + public static String getUUID() { + SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0); + long id = idWorker.nextId(); + return String.valueOf(id); + } + +} diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/TFileInfoVO.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/TFileInfoVO.java new file mode 100644 index 00000000..d0192adf --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/vo/TFileInfoVO.java @@ -0,0 +1,92 @@ +package com.ruoyi.platform.vo; + +import java.io.Serializable; + +/** + * 文件模型参数 + * @author JaredJia + * + */ +public class TFileInfoVO implements Serializable { + + private static final long serialVersionUID = -668666237985927833L; + + //附件编号 + private String id; + + //附件类型 + private String fileType; + + //附件名称 + private String name; + + //附件总大小 + private Long size; + + //附件地址 + private String relativePath; + + //附件MD5标识 + private String uniqueIdentifier; + + //附件所属项目ID + private String refProjectId; + + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getFileType() { + return fileType; + } + + public void setFileType(String fileType) { + this.fileType = fileType; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getSize() { + return size; + } + + public void setSize(Long size) { + this.size = size; + } + + public String getRelativePath() { + return relativePath; + } + + public void setRelativePath(String relativePath) { + this.relativePath = relativePath; + } + + public String getUniqueIdentifier() { + return uniqueIdentifier; + } + + public void setUniqueIdentifier(String uniqueIdentifier) { + this.uniqueIdentifier = uniqueIdentifier; + } + + public String getRefProjectId() { + return refProjectId; + } + + public void setRefProjectId(String refProjectId) { + this.refProjectId = refProjectId; + } + +} diff --git a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/TChunkInfoMapper.xml b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/TChunkInfoMapper.xml new file mode 100644 index 00000000..6aafb804 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/TChunkInfoMapper.xml @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + id, chunk_number, chunk_size, current_chunkSize, identifier, filename, relative_path, + total_chunks, type + + + + delete from t_chunk_info + where id = #{id,jdbcType=VARCHAR} + + + insert into t_chunk_info (id, chunk_number, chunk_size, + current_chunkSize, identifier, filename, + relative_path, total_chunks, type + ) + values (#{id,jdbcType=VARCHAR}, #{chunkNumber,jdbcType=DECIMAL}, #{chunkSize,jdbcType=DECIMAL}, + #{currentChunkSize,jdbcType=DECIMAL}, #{identifier,jdbcType=VARCHAR}, #{filename,jdbcType=VARCHAR}, + #{relativePath,jdbcType=VARCHAR}, #{totalChunks,jdbcType=DECIMAL}, #{type,jdbcType=DECIMAL} + ) + + + insert into t_chunk_info + + + id, + + + chunk_number, + + + chunk_size, + + + current_chunkSize, + + + identifier, + + + filename, + + + relative_path, + + + total_chunks, + + + type, + + + + + #{id,jdbcType=VARCHAR}, + + + #{chunkNumber,jdbcType=DECIMAL}, + + + #{chunkSize,jdbcType=DECIMAL}, + + + #{currentChunkSize,jdbcType=DECIMAL}, + + + #{identifier,jdbcType=VARCHAR}, + + + #{filename,jdbcType=VARCHAR}, + + + #{relativePath,jdbcType=VARCHAR}, + + + #{totalChunks,jdbcType=DECIMAL}, + + + #{type,jdbcType=DECIMAL}, + + + + + update t_chunk_info + + + chunk_number = #{chunkNumber,jdbcType=DECIMAL}, + + + chunk_size = #{chunkSize,jdbcType=DECIMAL}, + + + current_chunkSize = #{currentChunkSize,jdbcType=DECIMAL}, + + + identifier = #{identifier,jdbcType=VARCHAR}, + + + filename = #{filename,jdbcType=VARCHAR}, + + + relative_path = #{relativePath,jdbcType=VARCHAR}, + + + total_chunks = #{totalChunks,jdbcType=DECIMAL}, + + + type = #{type,jdbcType=DECIMAL}, + + + where id = #{id,jdbcType=VARCHAR} + + + update t_chunk_info + set chunk_number = #{chunkNumber,jdbcType=DECIMAL}, + chunk_size = #{chunkSize,jdbcType=DECIMAL}, + current_chunkSize = #{currentChunkSize,jdbcType=DECIMAL}, + identifier = #{identifier,jdbcType=VARCHAR}, + filename = #{filename,jdbcType=VARCHAR}, + relative_path = #{relativePath,jdbcType=VARCHAR}, + total_chunks = #{totalChunks,jdbcType=DECIMAL}, + type = #{type,jdbcType=DECIMAL} + where id = #{id,jdbcType=VARCHAR} + + + + \ No newline at end of file diff --git a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/TFileInfoMapper.xml b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/TFileInfoMapper.xml new file mode 100644 index 00000000..4caeb021 --- /dev/null +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/TFileInfoMapper.xml @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + id, filename, identifier, type, total_size, location, del_flag, ref_project_id, upload_by, + upload_time + + + + delete from t_file_info + where id = #{id,jdbcType=VARCHAR} + + + insert into t_file_info (id, filename, identifier, + type, total_size, location, + del_flag, ref_project_id, upload_by, + upload_time) + values (#{id,jdbcType=VARCHAR}, #{filename,jdbcType=VARCHAR}, #{identifier,jdbcType=VARCHAR}, + #{type,jdbcType=VARCHAR}, #{totalSize,jdbcType=DECIMAL}, #{location,jdbcType=VARCHAR}, + #{delFlag,jdbcType=VARCHAR}, #{refProjectId,jdbcType=VARCHAR}, #{uploadBy,jdbcType=VARCHAR}, + #{uploadTime,jdbcType=TIMESTAMP}) + + + insert into t_file_info + + + id, + + + filename, + + + identifier, + + + type, + + + total_size, + + + location, + + + del_flag, + + + ref_project_id, + + + upload_by, + + + upload_time, + + + + + #{id,jdbcType=VARCHAR}, + + + #{filename,jdbcType=VARCHAR}, + + + #{identifier,jdbcType=VARCHAR}, + + + #{type,jdbcType=VARCHAR}, + + + #{totalSize,jdbcType=DECIMAL}, + + + #{location,jdbcType=VARCHAR}, + + + #{delFlag,jdbcType=VARCHAR}, + + + #{refProjectId,jdbcType=VARCHAR}, + + + #{uploadBy,jdbcType=VARCHAR}, + + + #{uploadTime,jdbcType=TIMESTAMP}, + + + + + update t_file_info + + + filename = #{filename,jdbcType=VARCHAR}, + + + identifier = #{identifier,jdbcType=VARCHAR}, + + + type = #{type,jdbcType=VARCHAR}, + + + total_size = #{totalSize,jdbcType=DECIMAL}, + + + location = #{location,jdbcType=VARCHAR}, + + + del_flag = #{delFlag,jdbcType=VARCHAR}, + + + ref_project_id = #{refProjectId,jdbcType=VARCHAR}, + + + upload_by = #{uploadBy,jdbcType=VARCHAR}, + + + upload_time = #{uploadTime,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=VARCHAR} + + + update t_file_info + set filename = #{filename,jdbcType=VARCHAR}, + identifier = #{identifier,jdbcType=VARCHAR}, + type = #{type,jdbcType=VARCHAR}, + total_size = #{totalSize,jdbcType=DECIMAL}, + location = #{location,jdbcType=VARCHAR}, + del_flag = #{delFlag,jdbcType=VARCHAR}, + ref_project_id = #{refProjectId,jdbcType=VARCHAR}, + upload_by = #{uploadBy,jdbcType=VARCHAR}, + upload_time = #{uploadTime,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=VARCHAR} + + + + + + + \ No newline at end of file From 0b0ccd26d5094a3e1bff0e8719d2bab7144e907a Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Wed, 4 Jun 2025 14:14:11 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=88=86=E7=89=87?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=EF=BC=8C=E6=96=AD=E7=82=B9=E7=BB=AD=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/file/FileController.java | 144 +++++++++--------- 1 file changed, 75 insertions(+), 69 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/file/FileController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/file/FileController.java index d47cb479..0a86bf24 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/file/FileController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/file/FileController.java @@ -10,6 +10,7 @@ import com.ruoyi.platform.service.FileInfoService; import com.ruoyi.platform.utils.FileInfoUtils; import com.ruoyi.platform.utils.ServletUtils; import com.ruoyi.platform.vo.TFileInfoVO; +import com.ruoyi.system.api.constant.Constant; import io.swagger.annotations.Api; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,8 +30,8 @@ import java.util.List; /** * 上传下载文件 - * @author JaredJia * + * @author JaredJia */ @RestController @RequestMapping("/uploader") @@ -42,21 +43,22 @@ public class FileController extends BaseController { @Resource private FileInfoService fileInfoService; - + @Resource private ChunkService chunkService; private final Logger logger = LoggerFactory.getLogger(FileController.class); - + /** * 上传文件块 + * * @param chunk * @return */ @PostMapping("/chunk") public GenericsAjaxResult uploadChunk(TChunkInfo chunk) throws IOException { - String apiRlt = "200"; - + String apiRlt = "200"; + MultipartFile file = chunk.getUpfile(); logger.info("file originName: {}, chunkNumber: {}", file.getOriginalFilename(), chunk.getChunkNumber()); @@ -65,8 +67,8 @@ public class FileController extends BaseController { Path path = Paths.get(FileInfoUtils.generatePath(uploadFolder, chunk)); //文件写入指定路径 Files.write(path, bytes); - if(chunkService.saveChunk(chunk) < 0) apiRlt = "415"; - + if (chunkService.saveChunk(chunk) < 0) apiRlt = "415"; + } catch (IOException e) { throw new IOException(e.getMessage()); } @@ -75,94 +77,98 @@ public class FileController extends BaseController { @GetMapping("/chunk") public GenericsAjaxResult checkChunk(TChunkInfo chunk, HttpServletResponse response) { - UploadResult ur = new UploadResult(); - - //默认返回其他状态码,前端不进去checkChunkUploadedByResponse函数,正常走标准上传 - response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); - - String file = uploadFolder + "/" + chunk.getIdentifier() + "/" + chunk.getFilename(); - - //先判断整个文件是否已经上传过了,如果是,则告诉前端跳过上传,实现秒传 - if(FileInfoUtils.fileExists(file)) { - ur.setSkipUpload(true); - ur.setLocation(file); - response.setStatus(HttpServletResponse.SC_OK); - ur.setMessage("完整文件已存在,直接跳过上传,实现秒传"); - return genericsSuccess(ur); - } - - //如果完整文件不存在,则去数据库判断当前哪些文件块已经上传过了,把结果告诉前端,跳过这些文件块的上传,实现断点续传 - ArrayList list = chunkService.checkChunk(chunk); - if (list !=null && list.size() > 0) { - ur.setSkipUpload(false); - ur.setUploadedChunks(list); - response.setStatus(HttpServletResponse.SC_OK); - ur.setMessage("部分文件块已存在,继续上传剩余文件块,实现断点续传"); - return genericsSuccess(ur); + UploadResult ur = new UploadResult(); + + //默认返回其他状态码,前端不进去checkChunkUploadedByResponse函数,正常走标准上传 + response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); + + String file = uploadFolder + "/" + chunk.getIdentifier() + "/" + chunk.getFilename(); + + //先判断整个文件是否已经上传过了,如果是,则告诉前端跳过上传,实现秒传 + if (FileInfoUtils.fileExists(file)) { + ur.setSkipUpload(true); + ur.setLocation(file); + response.setStatus(HttpServletResponse.SC_OK); + ur.setMessage("完整文件已存在,直接跳过上传,实现秒传"); + return genericsSuccess(ur); + } + + //如果完整文件不存在,则去数据库判断当前哪些文件块已经上传过了,把结果告诉前端,跳过这些文件块的上传,实现断点续传 + ArrayList list = chunkService.checkChunk(chunk); + if (list != null && list.size() > 0) { + ur.setSkipUpload(false); + ur.setUploadedChunks(list); + response.setStatus(HttpServletResponse.SC_OK); + ur.setMessage("部分文件块已存在,继续上传剩余文件块,实现断点续传"); + return genericsSuccess(ur); } return genericsSuccess(ur); } @PostMapping("/mergeFile") - public GenericsAjaxResult mergeFile(@RequestBody TFileInfoVO fileInfoVO){ - - String rlt = "FAILURE"; - - //前端组件参数转换为model对象 - TFileInfo fileInfo = new TFileInfo(); - fileInfo.setFilename(fileInfoVO.getName()); - fileInfo.setIdentifier(fileInfoVO.getUniqueIdentifier()); - fileInfo.setId(fileInfoVO.getId()); - fileInfo.setTotalSize(fileInfoVO.getSize()); - fileInfo.setRefProjectId(fileInfoVO.getRefProjectId()); - - //进行文件的合并操作 + public GenericsAjaxResult mergeFile(@RequestBody TFileInfoVO fileInfoVO) throws Exception { + + String result = Constant.Failed; + + //前端组件参数转换为model对象 + TFileInfo fileInfo = new TFileInfo(); + fileInfo.setFilename(fileInfoVO.getName()); + fileInfo.setIdentifier(fileInfoVO.getUniqueIdentifier()); + fileInfo.setId(fileInfoVO.getId()); + fileInfo.setTotalSize(fileInfoVO.getSize()); + fileInfo.setRefProjectId(fileInfoVO.getRefProjectId()); + + //进行文件的合并操作 String filename = fileInfo.getFilename(); String file = uploadFolder + "/" + fileInfo.getIdentifier() + "/" + filename; String folder = uploadFolder + "/" + fileInfo.getIdentifier(); String fileSuccess = FileInfoUtils.merge(file, folder, filename); - + fileInfo.setLocation(file); - + //文件合并成功后,保存记录至数据库 - if("200".equals(fileSuccess)) { - if(fileInfoService.addFileInfo(fileInfo) > 0) rlt = "SUCCESS"; + if ("200".equals(fileSuccess)) { + if (fileInfoService.addFileInfo(fileInfo) > 0) result = Constant.Succeeded; } //如果已经存在,则判断是否同一个项目,同一个项目的不用新增记录,否则新增 - if("300".equals(fileSuccess)) { - List tfList = fileInfoService.selectFileByParams(fileInfo); - if(tfList != null) { - if(tfList.size() == 0 || (tfList.size() > 0 && !fileInfo.getRefProjectId().equals(tfList.get(0).getRefProjectId()))) { - if(fileInfoService.addFileInfo(fileInfo) > 0) rlt = "SUCCESS"; - } - } + if ("300".equals(fileSuccess)) { + List tfList = fileInfoService.selectFileByParams(fileInfo); + if (tfList != null) { + if (tfList.size() == 0 || (tfList.size() > 0 && !fileInfo.getRefProjectId().equals(tfList.get(0).getRefProjectId()))) { + if (fileInfoService.addFileInfo(fileInfo) > 0) result = Constant.Succeeded; + } + } + } + if (Constant.Succeeded.equals(result)) { + return genericsSuccess(fileInfo); + } else { + throw new Exception("文件上传失败"); } - - return genericsSuccess(fileInfo); } - + /** * 查询列表 * * @return ApiResult */ @RequestMapping(value = "/selectFileList", method = RequestMethod.GET) - public GenericsAjaxResult> selectFileList(TFileInfo file){ - List list = fileInfoService.selectFileList(file); + public GenericsAjaxResult> selectFileList(TFileInfo file) { + List list = fileInfoService.selectFileList(file); return genericsSuccess(list); } - + /** * 下载文件 + * * @param req * @param resp */ @RequestMapping(value = "/download", method = RequestMethod.GET) - public void download(HttpServletRequest req, HttpServletResponse resp){ - String location = req.getParameter("location"); - String fileName = req.getParameter("filename"); - BufferedInputStream bis = null; + public void download(HttpServletRequest req, HttpServletResponse resp) { + String location = req.getParameter("location"); + String fileName = req.getParameter("filename"); + BufferedInputStream bis = null; BufferedOutputStream bos = null; OutputStream fos = null; try { @@ -176,7 +182,7 @@ public class FileController extends BaseController { bos.write(buffer, 0, byteRead); } } catch (Exception e) { - e.printStackTrace(); + e.printStackTrace(); } finally { try { bos.flush(); @@ -188,13 +194,13 @@ public class FileController extends BaseController { } } } - + /** * 删除 */ @RequestMapping(value = "/deleteFile", method = RequestMethod.POST) - public GenericsAjaxResult deleteFile(@RequestBody TFileInfo tFileInfo ){ - int result = fileInfoService.deleteFile(tFileInfo); + public GenericsAjaxResult deleteFile(@RequestBody TFileInfo tFileInfo) { + int result = fileInfoService.deleteFile(tFileInfo); return genericsSuccess(result); } } From 24798fa4dd5559b92a99e11dc8c00de472504f74 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Fri, 6 Jun 2025 10:56:01 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E4=BC=98=E5=8C=96dvc=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java index 8e0beab8..2d7c33f2 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java @@ -184,6 +184,8 @@ public class NewDatasetServiceImpl implements NewDatasetService { // 命令行操作 git clone 项目地址 dvcUtils.gitClone(localPath1, projectUrl, "master", gitLinkUsername, gitLinkPassword); dvcUtils.refreshRemoteBranches(localPath1, gitLinkUsername, gitLinkPassword, "master"); + //检查是否存在本地重名分支,有的话干掉 + dvcUtils.deleteLocalBranch(localPath1, branchName); // 创建本地分支 dvcUtils.createLocalBranchBasedOnMaster(localPath1, branchName); //dvc checkout From 2f618703e4043eafdda813eafb2327a0f8ed9e83 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Fri, 6 Jun 2025 11:12:48 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E4=BC=98=E5=8C=96dvc=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/service/impl/ModelsServiceImpl.java | 2 +- .../platform/service/impl/NewDatasetServiceImpl.java | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java index ad9a1ac7..457864ab 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java @@ -613,7 +613,7 @@ public class ModelsServiceImpl implements ModelsService { String relatePath = ci4sUsername + "/model/" + gitlinIid + "/" + repositoryName + "/" + branchName + "/model"; // 创建分支 - gitService.createBranch(token, (String) userInfo.get("login"), repositoryName, branchName, "master"); + gitService.createBranch(token, owner, repositoryName, branchName, "master"); // 定义标签 标签1:model 标签2:ModelTag 标签3:ModelType gitService.createTopic(token, gitlinIid, Constant.Topic_model); if (StringUtils.isNotEmpty(modelsVo.getModelTag())) { diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java index 2d7c33f2..827c9ef2 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java @@ -136,7 +136,7 @@ public class NewDatasetServiceImpl implements NewDatasetService { gitService.createTopic(token, gitlinIid, "datatype-" + datasetVo.getDataType()); } - String relatePath = ci4sUsername + "/datasets/" + gitlinIid + "/" + repositoryName + "/master"; + String relatePath = ci4sUsername + "/datasets/" + gitlinIid + "/" + repositoryName + "/master-dvc"; String localPath = localPathlocal + relatePath; String datasetPath = localPath + "/dataset"; String s3Path = bucketName + "/mini-model-management-platform-files" + "/" + relatePath; @@ -144,8 +144,9 @@ public class NewDatasetServiceImpl implements NewDatasetService { // 得到项目地址 String projectUrl = gitCloneEndpoint + "/" + owner + "/" + repositoryName + ".git"; - // 创建master分支 - dvcUtils.gitClone(localPath, projectUrl, "master", gitLinkUsername, gitLinkPassword); + // 创建master-dvc分支 + gitService.createBranch(token, owner, repositoryName, "master-dvc", "master"); + dvcUtils.gitClone(localPath, projectUrl, "master-dvc", gitLinkUsername, gitLinkPassword); // 拼接生产的元数据后写入yaml文件 datasetVo.setCreateBy(String.valueOf(StringUtils.isNotEmpty((String) userInfo.get("nickname")) ? userInfo.get("nickname") : userInfo.get("login"))); datasetVo.setUpdateTime(DateUtils.getTime()); @@ -182,8 +183,8 @@ public class NewDatasetServiceImpl implements NewDatasetService { String datasetPath1 = localPath1 + "/dataset"; // 命令行操作 git clone 项目地址 - dvcUtils.gitClone(localPath1, projectUrl, "master", gitLinkUsername, gitLinkPassword); - dvcUtils.refreshRemoteBranches(localPath1, gitLinkUsername, gitLinkPassword, "master"); + dvcUtils.gitClone(localPath1, projectUrl, "master-dvc", gitLinkUsername, gitLinkPassword); + dvcUtils.refreshRemoteBranches(localPath1, gitLinkUsername, gitLinkPassword, "master-dvc"); //检查是否存在本地重名分支,有的话干掉 dvcUtils.deleteLocalBranch(localPath1, branchName); // 创建本地分支 From 163e9bab8d2c72a5c8fac773a6acceddf1547404 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Fri, 6 Jun 2025 11:23:00 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E4=BC=98=E5=8C=96dvc=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/NewDatasetServiceImpl.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java index 827c9ef2..3de0904a 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java @@ -136,7 +136,7 @@ public class NewDatasetServiceImpl implements NewDatasetService { gitService.createTopic(token, gitlinIid, "datatype-" + datasetVo.getDataType()); } - String relatePath = ci4sUsername + "/datasets/" + gitlinIid + "/" + repositoryName + "/master-dvc"; + String relatePath = ci4sUsername + "/datasets/" + gitlinIid + "/" + repositoryName + "/origin"; String localPath = localPathlocal + relatePath; String datasetPath = localPath + "/dataset"; String s3Path = bucketName + "/mini-model-management-platform-files" + "/" + relatePath; @@ -145,8 +145,8 @@ public class NewDatasetServiceImpl implements NewDatasetService { String projectUrl = gitCloneEndpoint + "/" + owner + "/" + repositoryName + ".git"; // 创建master-dvc分支 - gitService.createBranch(token, owner, repositoryName, "master-dvc", "master"); - dvcUtils.gitClone(localPath, projectUrl, "master-dvc", gitLinkUsername, gitLinkPassword); + gitService.createBranch(token, owner, repositoryName, "origin", "master"); + dvcUtils.gitClone(localPath, projectUrl, "origin", gitLinkUsername, gitLinkPassword); // 拼接生产的元数据后写入yaml文件 datasetVo.setCreateBy(String.valueOf(StringUtils.isNotEmpty((String) userInfo.get("nickname")) ? userInfo.get("nickname") : userInfo.get("login"))); datasetVo.setUpdateTime(DateUtils.getTime()); @@ -183,8 +183,8 @@ public class NewDatasetServiceImpl implements NewDatasetService { String datasetPath1 = localPath1 + "/dataset"; // 命令行操作 git clone 项目地址 - dvcUtils.gitClone(localPath1, projectUrl, "master-dvc", gitLinkUsername, gitLinkPassword); - dvcUtils.refreshRemoteBranches(localPath1, gitLinkUsername, gitLinkPassword, "master-dvc"); + dvcUtils.gitClone(localPath1, projectUrl, "origin", gitLinkUsername, gitLinkPassword); + dvcUtils.refreshRemoteBranches(localPath1, gitLinkUsername, gitLinkPassword, "origin"); //检查是否存在本地重名分支,有的话干掉 dvcUtils.deleteLocalBranch(localPath1, branchName); // 创建本地分支 @@ -271,8 +271,8 @@ public class NewDatasetServiceImpl implements NewDatasetService { // String oldBranch = (String) brancheList.stream() // .filter(branch -> !"master".equals(branch.get("name"))).collect(Collectors.toList()).get(0).get("name"); - dvcUtils.gitClone(localPath, projectUrl, "master", gitLinkUsername, gitLinkPassword); - dvcUtils.refreshRemoteBranches(localPath, gitLinkUsername, gitLinkPassword, "master"); + dvcUtils.gitClone(localPath, projectUrl, "origin", gitLinkUsername, gitLinkPassword); + dvcUtils.refreshRemoteBranches(localPath, gitLinkUsername, gitLinkPassword, "origin"); //检查是否存在本地重名分支,有的话删掉 dvcUtils.deleteLocalBranch(localPath, branchName); From 089b13aafba4504b0e6a3c8992917875d3c3f76a Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Fri, 6 Jun 2025 11:40:52 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E4=BC=98=E5=8C=96dvc=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/NewDatasetServiceImpl.java | 100 ++++++++---------- 1 file changed, 47 insertions(+), 53 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java index 3de0904a..05fe67f4 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java @@ -144,7 +144,7 @@ public class NewDatasetServiceImpl implements NewDatasetService { // 得到项目地址 String projectUrl = gitCloneEndpoint + "/" + owner + "/" + repositoryName + ".git"; - // 创建master-dvc分支 + // 创建origin分支 gitService.createBranch(token, owner, repositoryName, "origin", "master"); dvcUtils.gitClone(localPath, projectUrl, "origin", gitLinkUsername, gitLinkPassword); // 拼接生产的元数据后写入yaml文件 @@ -154,7 +154,6 @@ public class NewDatasetServiceImpl implements NewDatasetService { datasetVo.setId(gitlinIid); datasetVo.setOwner(owner); datasetVo.setRelativePaths(relatePath + "/dataset"); -// addDatasetSourceToDataVo(datasetVo); YamlUtils.generateYamlFile(JsonUtils.objectToMap(datasetVo), localPath, "dataset"); // dvc init 初始化 @@ -174,53 +173,52 @@ public class NewDatasetServiceImpl implements NewDatasetService { dvcUtils.dvcPush(localPath); // 创建分支 - String branchName = datasetVo.getVersion(); - - // 得到用户操作的路径 - String sourcePath = datasetVo.getDatasetVersionVos().get(0).getUrl(); - String relatePath1 = ci4sUsername + "/datasets/" + gitlinIid + "/" + repositoryName + "/" + branchName; - String localPath1 = localPathlocal + relatePath1; - String datasetPath1 = localPath1 + "/dataset"; - - // 命令行操作 git clone 项目地址 - dvcUtils.gitClone(localPath1, projectUrl, "origin", gitLinkUsername, gitLinkPassword); - dvcUtils.refreshRemoteBranches(localPath1, gitLinkUsername, gitLinkPassword, "origin"); - //检查是否存在本地重名分支,有的话干掉 - dvcUtils.deleteLocalBranch(localPath1, branchName); - // 创建本地分支 - dvcUtils.createLocalBranchBasedOnMaster(localPath1, branchName); - //dvc checkout - dvcUtils.dvcPull(localPath1); - dvcUtils.dvcCheckout(localPath1); - - String s3Path1 = bucketName + "/mini-model-management-platform-files" + "/" + relatePath1; - //删掉已存在文件夹 - dvcUtils.deleteDirectory(datasetPath1); - dvcUtils.moveFiles(sourcePath, datasetPath1); - // 拼接生产的元数据后写入yaml文件 - datasetVo.setUpdateTime(DateUtils.getTime()); - datasetVo.setUsage("
" +
-                "# 克隆数据集配置文件与存储参数到本地\n" +
-                "git clone -b " + branchName + " " + projectUrl + "\n" +
-                "# 远程拉取配置文件\n" +
-                "dvc pull\n" +
-                "
"); - datasetVo.setRelativePaths(relatePath1 + "/dataset"); - YamlUtils.generateYamlFile(JsonUtils.objectToMap(datasetVo), localPath1, "dataset"); - -// CompletableFuture.supplyAsync(() -> { -// try { - // 配置远程S3地址 - dvcUtils.dvcRemoteAdd(localPath1, s3Path1); - dvcUtils.dvcConfigS3Credentials(localPath1, endpoint); - dvcUtils.dvcConfigS3Credentials2(localPath1, accessKeyId); - dvcUtils.dvcConfigS3Credentials3(localPath1, secretAccessKey); - // dvc 跟踪 - dvcUtils.dvcAdd(localPath1, "dataset"); - // git commit - dvcUtils.pushNewBranchToRemote(localPath1, gitLinkUsername, gitLinkPassword, branchName); - // dvc push 到远程S3 - dvcUtils.dvcPush(localPath1); + newCreateVersion(datasetVo); +// String branchName = datasetVo.getVersion(); +// +// // 得到用户操作的路径 +// String sourcePath = datasetVo.getDatasetVersionVos().get(0).getUrl(); +// String relatePath1 = ci4sUsername + "/datasets/" + gitlinIid + "/" + repositoryName + "/" + branchName; +// String localPath1 = localPathlocal + relatePath1; +// String datasetPath1 = localPath1 + "/dataset"; +// +// // 命令行操作 git clone 项目地址 +// dvcUtils.gitClone(localPath1, projectUrl, "origin", gitLinkUsername, gitLinkPassword); +// dvcUtils.refreshRemoteBranches(localPath1, gitLinkUsername, gitLinkPassword, "origin"); +// // 创建本地分支 +// dvcUtils.createLocalBranchBasedOnMaster(localPath1, branchName); +// //dvc checkout +// dvcUtils.dvcPull(localPath1); +// dvcUtils.dvcCheckout(localPath1); +// +// String s3Path1 = bucketName + "/mini-model-management-platform-files" + "/" + relatePath1; +// //删掉已存在文件夹 +// dvcUtils.deleteDirectory(datasetPath1); +// dvcUtils.moveFiles(sourcePath, datasetPath1); +// // 拼接生产的元数据后写入yaml文件 +// datasetVo.setUpdateTime(DateUtils.getTime()); +// datasetVo.setUsage("
" +
+//                "# 克隆数据集配置文件与存储参数到本地\n" +
+//                "git clone -b " + branchName + " " + projectUrl + "\n" +
+//                "# 远程拉取配置文件\n" +
+//                "dvc pull\n" +
+//                "
"); +// datasetVo.setRelativePaths(relatePath1 + "/dataset"); +// YamlUtils.generateYamlFile(JsonUtils.objectToMap(datasetVo), localPath1, "dataset"); +// +//// CompletableFuture.supplyAsync(() -> { +//// try { +// // 配置远程S3地址 +// dvcUtils.dvcRemoteAdd(localPath1, s3Path1); +// dvcUtils.dvcConfigS3Credentials(localPath1, endpoint); +// dvcUtils.dvcConfigS3Credentials2(localPath1, accessKeyId); +// dvcUtils.dvcConfigS3Credentials3(localPath1, secretAccessKey); +// // dvc 跟踪 +// dvcUtils.dvcAdd(localPath1, "dataset"); +// // git commit +// dvcUtils.pushNewBranchToRemote(localPath1, gitLinkUsername, gitLinkPassword, branchName); +// // dvc push 到远程S3 +// dvcUtils.dvcPush(localPath1); // } catch (Exception e) { // logger.error(e.getMessage(), e); // throw new RuntimeException(e.getMessage()); @@ -267,10 +265,6 @@ public class NewDatasetServiceImpl implements NewDatasetService { Map projectDetail = gitService.getProjectDetail(owner, repositoryName, token); //克隆 -// List> brancheList = gitService.getBrancheList(token, owner, repositoryName); -// String oldBranch = (String) brancheList.stream() -// .filter(branch -> !"master".equals(branch.get("name"))).collect(Collectors.toList()).get(0).get("name"); - dvcUtils.gitClone(localPath, projectUrl, "origin", gitLinkUsername, gitLinkPassword); dvcUtils.refreshRemoteBranches(localPath, gitLinkUsername, gitLinkPassword, "origin"); From 94555dea40b26225cc02bb50af57089c89b88bde Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Fri, 6 Jun 2025 14:00:30 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E4=BC=98=E5=8C=96dvc=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ModelsServiceImpl.java | 92 ++++++++++--------- .../service/impl/NewDatasetServiceImpl.java | 61 ++---------- 2 files changed, 55 insertions(+), 98 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java index 457864ab..391ad6d4 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java @@ -568,6 +568,9 @@ public class ModelsServiceImpl implements ModelsService { @Override public String newCreateModel(ModelsVo modelsVo) { try { + if ("master".equals(modelsVo.getVersion()) || "origin".equals(modelsVo.getVersion())) { + throw new Exception("不允许创建" + modelsVo.getVersion() + "分支"); + } String token = gitService.checkoutToken(); LoginUser loginUser = SecurityUtils.getLoginUser(); String ci4sUsername = loginUser.getUsername(); @@ -586,7 +589,6 @@ public class ModelsServiceImpl implements ModelsService { } //新建模型 - // 拼接project GitProjectVo gitProjectVo = new GitProjectVo(); gitProjectVo.setRepositoryName(repositoryName); gitProjectVo.setName(Constant.Topic_model + "-" + modelsVo.getName()); @@ -602,18 +604,6 @@ public class ModelsServiceImpl implements ModelsService { throw new RuntimeException("创建模型失败:" + project.get("message")); } - String branchName = modelsVo.getVersion(); - String owner = (String) userInfo.get("login"); - - String projectUrl = gitCloneEndpoint + "/" + owner + "/" + repositoryName + ".git"; - String sourcePath = modelsVo.getModelVersionVos().get(0).getUrl(); - String rootPath = localPath + ci4sUsername + "/model/" + gitlinIid + "/" + repositoryName + "/" + branchName; - String modelPath = rootPath + "/model"; - String metaPath = rootPath + "/metadata"; - String relatePath = ci4sUsername + "/model/" + gitlinIid + "/" + repositoryName + "/" + branchName + "/model"; - - // 创建分支 - gitService.createBranch(token, owner, repositoryName, branchName, "master"); // 定义标签 标签1:model 标签2:ModelTag 标签3:ModelType gitService.createTopic(token, gitlinIid, Constant.Topic_model); if (StringUtils.isNotEmpty(modelsVo.getModelTag())) { @@ -623,7 +613,18 @@ public class ModelsServiceImpl implements ModelsService { gitService.createTopic(token, gitlinIid, "modeltype-" + modelsVo.getModelType()); } - dvcUtils.gitClone(rootPath, projectUrl, branchName, gitLinkUsername, decryptGitLinkPassword); + String owner = (String) userInfo.get("login"); + String projectUrl = gitCloneEndpoint + "/" + owner + "/" + repositoryName + ".git"; + String sourcePath = modelsVo.getModelVersionVos().get(0).getUrl(); + String relationPath = ci4sUsername + "/model/" + gitlinIid + "/" + repositoryName + "/origin"; + String rootPath = localPath + relationPath; + String modelPath = rootPath + "/model"; + String metaPath = rootPath + "/metadata"; + String relatePath = relationPath + "/model"; + + // 创建origin分支 + gitService.createBranch(token, owner, repositoryName, "origin", "master"); + dvcUtils.gitClone(rootPath, projectUrl, "origin", gitLinkUsername, decryptGitLinkPassword); //干掉目标文件夹 dvcUtils.deleteDirectory(modelPath); @@ -636,13 +637,6 @@ public class ModelsServiceImpl implements ModelsService { modelMetaVo.setCreateBy(String.valueOf(StringUtils.isNotEmpty((String) userInfo.get("nickname")) ? userInfo.get("nickname") : userInfo.get("login"))); modelMetaVo.setCreateTime(DateUtils.getTime()); modelMetaVo.setUpdateTime(DateUtils.getTime()); - String projectUrlIp = gitCloneEndpointIp + "/" + owner + "/" + repositoryName + ".git"; - modelMetaVo.setUsage("
" +
-                    "# 克隆模型配置文件与存储参数到本地\n" +
-                    "git clone -b " + branchName + " " + projectUrlIp + "\n" +
-                    "# 远程拉取配置文件\n" +
-                    "dvc pull\n" +
-                    "
"); modelMetaVo.setIdentifier(repositoryName); modelMetaVo.setOwner(owner); modelMetaVo.setRelativePaths(relatePath); @@ -665,28 +659,32 @@ public class ModelsServiceImpl implements ModelsService { modelDependency.setState(Constant.State_valid); modelDependency1Dao.insert(modelDependency); - String s3Path = bucketName + "/mini-model-management-platform-files/" + ci4sUsername + "/model/" + gitlinIid + "/" + repositoryName + "/" + branchName; - CompletableFuture.supplyAsync(() -> { - try { - dvcUtils.dvcInit(rootPath); - // 配置远程S3地址 - dvcUtils.dvcRemoteAdd(rootPath, s3Path); - dvcUtils.dvcConfigS3Credentials(rootPath, endpoint); - dvcUtils.dvcConfigS3Credentials2(rootPath, accessKeyId); - dvcUtils.dvcConfigS3Credentials3(rootPath, secretAccessKey); - - // dvc 跟踪 - dvcUtils.dvcAdd(rootPath, "model"); - // git commit - dvcUtils.gitCommit(rootPath, "commit from ci4s with " + loginUser.getUsername()); - dvcUtils.gitPush(rootPath, gitLinkUsername, decryptGitLinkPassword); - dvcUtils.dvcPush(rootPath); - } catch (Exception e) { - logger.error(e.getMessage(), e); - throw new RuntimeException(e.getMessage()); - } - return null; - }); + String s3Path = bucketName + "/mini-model-management-platform-files/" + relationPath; +// CompletableFuture.supplyAsync(() -> { +// try { + dvcUtils.mkdir(modelPath); + dvcUtils.dvcInit(rootPath); + // 配置远程S3地址 + dvcUtils.dvcRemoteAdd(rootPath, s3Path); + dvcUtils.dvcConfigS3Credentials(rootPath, endpoint); + dvcUtils.dvcConfigS3Credentials2(rootPath, accessKeyId); + dvcUtils.dvcConfigS3Credentials3(rootPath, secretAccessKey); + + // dvc 跟踪 + dvcUtils.dvcAdd(rootPath, "model"); + // git commit + dvcUtils.gitCommit(rootPath, "commit from ci4s with " + loginUser.getUsername()); + dvcUtils.gitPush(rootPath, gitLinkUsername, decryptGitLinkPassword); + dvcUtils.dvcPush(rootPath); + + // 创建分支 + newCreateVersion(modelsVo); +// } catch (Exception e) { +// logger.error(e.getMessage(), e); +// throw new RuntimeException(e.getMessage()); +// } +// return null; +// }); return "新增模型成功"; } catch (Exception e) { @@ -697,6 +695,9 @@ public class ModelsServiceImpl implements ModelsService { @Override public String newCreateVersion(ModelsVo modelsVo) throws Exception { + if ("master".equals(modelsVo.getVersion()) || "origin".equals(modelsVo.getVersion())) { + throw new Exception("不允许创建" + modelsVo.getVersion() + "分支"); + } LoginUser loginUser = SecurityUtils.getLoginUser(); String ci4sUsername = loginUser.getUsername(); String gitLinkUsername = loginUser.getSysUser().getUserName(); @@ -775,9 +776,10 @@ public class ModelsServiceImpl implements ModelsService { modelMetaVo.setCreateBy(String.valueOf(StringUtils.isNotEmpty((String) userInfo.get("nickname")) ? userInfo.get("nickname") : userInfo.get("login"))); modelMetaVo.setCreateTime(DateUtils.getTime()); modelMetaVo.setUpdateTime(DateUtils.getTime()); + String projectUrlIp = gitCloneEndpointIp + "/" + owner + "/" + repositoryName + ".git"; modelMetaVo.setUsage("
" +
                     "# 克隆模型配置文件与存储参数到本地\n" +
-                    "git clone -b " + branchName + " " + projectUrl + "\n" +
+                    "git clone -b " + branchName + " " + projectUrlIp + "\n" +
                     "# 远程拉取配置文件\n" +
                     "dvc pull\n" +
                     "
"); @@ -984,7 +986,7 @@ public class ModelsServiceImpl implements ModelsService { String token = gitService.checkoutToken(); List> collect = gitService.getBrancheList(token, owner, identifier); List> result = collect.stream() - .filter(branch -> !"master".equals(branch.get("name"))) + .filter(branch -> !"master".equals(branch.get("name")) && !"origin".equals(branch.get("name"))) .skip((pageRequest.getPageNumber()) * pageRequest.getPageSize()).limit(pageRequest.getPageSize()) .collect(Collectors.toList()); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java index 05fe67f4..0ebd9030 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java @@ -97,6 +97,9 @@ public class NewDatasetServiceImpl implements NewDatasetService { @Override public String newCreateDataset(NewDatasetVo datasetVo) throws Exception { + if ("master".equals(datasetVo.getVersion()) || "origin".equals(datasetVo.getVersion())) { + throw new Exception("不允许创建" + datasetVo.getVersion() + "分支"); + } String token = gitService.checkoutToken(); Jedis jedis = new Jedis(redisHost, redisPort); LoginUser loginUser = SecurityUtils.getLoginUser(); @@ -174,61 +177,13 @@ public class NewDatasetServiceImpl implements NewDatasetService { // 创建分支 newCreateVersion(datasetVo); -// String branchName = datasetVo.getVersion(); -// -// // 得到用户操作的路径 -// String sourcePath = datasetVo.getDatasetVersionVos().get(0).getUrl(); -// String relatePath1 = ci4sUsername + "/datasets/" + gitlinIid + "/" + repositoryName + "/" + branchName; -// String localPath1 = localPathlocal + relatePath1; -// String datasetPath1 = localPath1 + "/dataset"; -// -// // 命令行操作 git clone 项目地址 -// dvcUtils.gitClone(localPath1, projectUrl, "origin", gitLinkUsername, gitLinkPassword); -// dvcUtils.refreshRemoteBranches(localPath1, gitLinkUsername, gitLinkPassword, "origin"); -// // 创建本地分支 -// dvcUtils.createLocalBranchBasedOnMaster(localPath1, branchName); -// //dvc checkout -// dvcUtils.dvcPull(localPath1); -// dvcUtils.dvcCheckout(localPath1); -// -// String s3Path1 = bucketName + "/mini-model-management-platform-files" + "/" + relatePath1; -// //删掉已存在文件夹 -// dvcUtils.deleteDirectory(datasetPath1); -// dvcUtils.moveFiles(sourcePath, datasetPath1); -// // 拼接生产的元数据后写入yaml文件 -// datasetVo.setUpdateTime(DateUtils.getTime()); -// datasetVo.setUsage("
" +
-//                "# 克隆数据集配置文件与存储参数到本地\n" +
-//                "git clone -b " + branchName + " " + projectUrl + "\n" +
-//                "# 远程拉取配置文件\n" +
-//                "dvc pull\n" +
-//                "
"); -// datasetVo.setRelativePaths(relatePath1 + "/dataset"); -// YamlUtils.generateYamlFile(JsonUtils.objectToMap(datasetVo), localPath1, "dataset"); -// -//// CompletableFuture.supplyAsync(() -> { -//// try { -// // 配置远程S3地址 -// dvcUtils.dvcRemoteAdd(localPath1, s3Path1); -// dvcUtils.dvcConfigS3Credentials(localPath1, endpoint); -// dvcUtils.dvcConfigS3Credentials2(localPath1, accessKeyId); -// dvcUtils.dvcConfigS3Credentials3(localPath1, secretAccessKey); -// // dvc 跟踪 -// dvcUtils.dvcAdd(localPath1, "dataset"); -// // git commit -// dvcUtils.pushNewBranchToRemote(localPath1, gitLinkUsername, gitLinkPassword, branchName); -// // dvc push 到远程S3 -// dvcUtils.dvcPush(localPath1); -// } catch (Exception e) { -// logger.error(e.getMessage(), e); -// throw new RuntimeException(e.getMessage()); -// } -// return null; -// }); return "新增数据集成功"; } public String newCreateVersion(NewDatasetVo datasetVo) throws Exception { + if ("master".equals(datasetVo.getVersion()) || "origin".equals(datasetVo.getVersion())) { + throw new Exception("不允许创建" + datasetVo.getVersion() + "分支"); + } List> versionList = getVersionList(datasetVo.getIdentifier(), datasetVo.getOwner()); for (Map versionMap : versionList) { String version = (String) versionMap.get("name"); @@ -278,7 +233,7 @@ public class NewDatasetServiceImpl implements NewDatasetService { dvcUtils.dvcCheckout(localPath); // 准备数据 - String s3Path = bucketName + "/mini-model-management-platform-files" + "/" + relatePath + "/" + branchName; + String s3Path = bucketName + "/mini-model-management-platform-files" + "/" + relatePath; //删掉已存在文件夹 dvcUtils.deleteDirectory(datasetPath); @@ -434,7 +389,7 @@ public class NewDatasetServiceImpl implements NewDatasetService { String token = gitService.checkoutToken(); List> brancheList = gitService.getBrancheList(token, owner, repo); return brancheList.stream() - .filter(branch -> !"master".equals(branch.get("name"))) + .filter(branch -> !"master".equals(branch.get("name")) && !"origin".equals(branch.get("name"))) .collect(Collectors.toList()); } From fb863bf1de8b53711cbc1e1dc2e33e450b517ab3 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Fri, 6 Jun 2025 14:14:29 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E4=BC=98=E5=8C=96dvc=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ModelsServiceImpl.java | 31 ++++++------------- .../service/impl/NewDatasetServiceImpl.java | 6 ---- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java index 391ad6d4..840ab6ff 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java @@ -568,9 +568,6 @@ public class ModelsServiceImpl implements ModelsService { @Override public String newCreateModel(ModelsVo modelsVo) { try { - if ("master".equals(modelsVo.getVersion()) || "origin".equals(modelsVo.getVersion())) { - throw new Exception("不允许创建" + modelsVo.getVersion() + "分支"); - } String token = gitService.checkoutToken(); LoginUser loginUser = SecurityUtils.getLoginUser(); String ci4sUsername = loginUser.getUsername(); @@ -615,7 +612,6 @@ public class ModelsServiceImpl implements ModelsService { String owner = (String) userInfo.get("login"); String projectUrl = gitCloneEndpoint + "/" + owner + "/" + repositoryName + ".git"; - String sourcePath = modelsVo.getModelVersionVos().get(0).getUrl(); String relationPath = ci4sUsername + "/model/" + gitlinIid + "/" + repositoryName + "/origin"; String rootPath = localPath + relationPath; String modelPath = rootPath + "/model"; @@ -626,10 +622,6 @@ public class ModelsServiceImpl implements ModelsService { gitService.createBranch(token, owner, repositoryName, "origin", "master"); dvcUtils.gitClone(rootPath, projectUrl, "origin", gitLinkUsername, decryptGitLinkPassword); - //干掉目标文件夹 - dvcUtils.deleteDirectory(modelPath); - dvcUtils.moveFiles(sourcePath, modelPath); - //拼接生产的元数据后写入yaml文件 ModelMetaVo modelMetaVo = new ModelMetaVo(); BeanUtils.copyProperties(modelsVo, modelMetaVo); @@ -646,18 +638,18 @@ public class ModelsServiceImpl implements ModelsService { Map metaMap = JSON.parseObject(JSON.toJSONString(modelMetaVo), Map.class); YamlUtils.generateYamlFile(metaMap, metaPath, "metadata"); - String meta = JSON.toJSONString(modelMetaVo); +// String meta = JSON.toJSONString(modelMetaVo); //保存模型依赖 - modelDependency.setRepoId(gitlinIid); - modelDependency.setIdentifier(repositoryName); - modelDependency.setModelName(modelsVo.getName()); - modelDependency.setVersion(modelsVo.getVersion()); - modelDependency.setParentModel(modelsVo.getParentModel()); - modelDependency.setOwner(gitLinkUsername); - modelDependency.setMeta(meta); - modelDependency.setState(Constant.State_valid); - modelDependency1Dao.insert(modelDependency); +// modelDependency.setRepoId(gitlinIid); +// modelDependency.setIdentifier(repositoryName); +// modelDependency.setModelName(modelsVo.getName()); +// modelDependency.setVersion(modelsVo.getVersion()); +// modelDependency.setParentModel(modelsVo.getParentModel()); +// modelDependency.setOwner(gitLinkUsername); +// modelDependency.setMeta(meta); +// modelDependency.setState(Constant.State_valid); +// modelDependency1Dao.insert(modelDependency); String s3Path = bucketName + "/mini-model-management-platform-files/" + relationPath; // CompletableFuture.supplyAsync(() -> { @@ -695,9 +687,6 @@ public class ModelsServiceImpl implements ModelsService { @Override public String newCreateVersion(ModelsVo modelsVo) throws Exception { - if ("master".equals(modelsVo.getVersion()) || "origin".equals(modelsVo.getVersion())) { - throw new Exception("不允许创建" + modelsVo.getVersion() + "分支"); - } LoginUser loginUser = SecurityUtils.getLoginUser(); String ci4sUsername = loginUser.getUsername(); String gitLinkUsername = loginUser.getSysUser().getUserName(); diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java index 0ebd9030..24bc4fca 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java @@ -97,9 +97,6 @@ public class NewDatasetServiceImpl implements NewDatasetService { @Override public String newCreateDataset(NewDatasetVo datasetVo) throws Exception { - if ("master".equals(datasetVo.getVersion()) || "origin".equals(datasetVo.getVersion())) { - throw new Exception("不允许创建" + datasetVo.getVersion() + "分支"); - } String token = gitService.checkoutToken(); Jedis jedis = new Jedis(redisHost, redisPort); LoginUser loginUser = SecurityUtils.getLoginUser(); @@ -181,9 +178,6 @@ public class NewDatasetServiceImpl implements NewDatasetService { } public String newCreateVersion(NewDatasetVo datasetVo) throws Exception { - if ("master".equals(datasetVo.getVersion()) || "origin".equals(datasetVo.getVersion())) { - throw new Exception("不允许创建" + datasetVo.getVersion() + "分支"); - } List> versionList = getVersionList(datasetVo.getIdentifier(), datasetVo.getOwner()); for (Map versionMap : versionList) { String version = (String) versionMap.get("name"); From 284115b499729b79ea61a1d2633822c1af1f1707 Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Fri, 6 Jun 2025 14:31:52 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E4=BC=98=E5=8C=96dvc=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ModelsServiceImpl.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java index 840ab6ff..49a1165a 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java @@ -638,18 +638,18 @@ public class ModelsServiceImpl implements ModelsService { Map metaMap = JSON.parseObject(JSON.toJSONString(modelMetaVo), Map.class); YamlUtils.generateYamlFile(metaMap, metaPath, "metadata"); -// String meta = JSON.toJSONString(modelMetaVo); + String meta = JSON.toJSONString(modelMetaVo); //保存模型依赖 -// modelDependency.setRepoId(gitlinIid); -// modelDependency.setIdentifier(repositoryName); -// modelDependency.setModelName(modelsVo.getName()); -// modelDependency.setVersion(modelsVo.getVersion()); -// modelDependency.setParentModel(modelsVo.getParentModel()); -// modelDependency.setOwner(gitLinkUsername); -// modelDependency.setMeta(meta); -// modelDependency.setState(Constant.State_valid); -// modelDependency1Dao.insert(modelDependency); + modelDependency.setRepoId(gitlinIid); + modelDependency.setIdentifier(repositoryName); + modelDependency.setModelName(modelsVo.getName()); + modelDependency.setVersion("origin"); + modelDependency.setParentModel(modelsVo.getParentModel()); + modelDependency.setOwner(gitLinkUsername); + modelDependency.setMeta(meta); + modelDependency.setState(Constant.State_valid); + modelDependency1Dao.insert(modelDependency); String s3Path = bucketName + "/mini-model-management-platform-files/" + relationPath; // CompletableFuture.supplyAsync(() -> { @@ -1078,7 +1078,7 @@ public class ModelsServiceImpl implements ModelsService { String token = gitService.checkoutToken(); List> branchList = gitService.getBrancheList(token, owner, identifier); return branchList.stream() - .filter(branch -> !"master".equals(branch.get("name"))) + .filter(branch -> !"master".equals(branch.get("name")) && !"origin".equals(branch.get("name"))) .collect(Collectors.toList()); } From 6d2a84aa93d5e15bed5bcc8b695d75878399bb1f Mon Sep 17 00:00:00 2001 From: chenzhihang <709011834@qq.com> Date: Fri, 6 Jun 2025 14:44:01 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E4=BC=98=E5=8C=96dvc=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/platform/service/impl/ModelsServiceImpl.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java index 49a1165a..6df28844 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java @@ -635,6 +635,7 @@ public class ModelsServiceImpl implements ModelsService { File folder = new File(modelPath); long folderSize = FileUtil.getFolderSize(folder); modelMetaVo.setModelSize(FileUtil.formatFileSize(folderSize)); + BeanUtils.copyProperties(modelMetaVo, modelsVo); Map metaMap = JSON.parseObject(JSON.toJSONString(modelMetaVo), Map.class); YamlUtils.generateYamlFile(metaMap, metaPath, "metadata"); @@ -717,8 +718,8 @@ public class ModelsServiceImpl implements ModelsService { FileUtil.renameFile(rootPath, rootPath + "_deleted_" + System.currentTimeMillis()); //克隆 - dvcUtils.gitClone(rootPath, projectUrl, oldModelDependencys.get(0).getVersion(), gitLinkUsername, gitLinkPassword); - dvcUtils.refreshRemoteBranches(rootPath, gitLinkUsername, gitLinkPassword, oldModelDependencys.get(0).getVersion()); + dvcUtils.gitClone(rootPath, projectUrl, "origin", gitLinkUsername, gitLinkPassword); + dvcUtils.refreshRemoteBranches(rootPath, gitLinkUsername, gitLinkPassword, "origin"); //查询项目信息 String token = gitService.checkoutToken();