diff --git a/ruoyi-system/src/main/java/com/ruoyi/official/controller/FileChunkFilelistController.java b/ruoyi-system/src/main/java/com/ruoyi/official/controller/FileChunkFilelistController.java index b74c837..07025c3 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/official/controller/FileChunkFilelistController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/official/controller/FileChunkFilelistController.java @@ -1,6 +1,7 @@ package com.ruoyi.official.controller; import cn.dev33.satoken.annotation.SaCheckPermission; +import cn.hutool.core.util.ObjectUtil; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.PageQuery; import com.ruoyi.common.core.domain.R; @@ -11,10 +12,16 @@ import com.ruoyi.official.domain.vo.CheckSysChunkVo; import com.ruoyi.official.domain.vo.FileChunkFilelistVo; import com.ruoyi.official.service.IFileChunkFilelistService; import lombok.RequiredArgsConstructor; +import org.springframework.core.io.InputStreamResource; +import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; /** * 已上传文件记录 @@ -46,8 +53,14 @@ public class FileChunkFilelistController extends BaseController { * @return 是否上传成功 */ @PostMapping("/upload") - public R postFileUpload(@ModelAttribute FileChunkParamBo fileChunkParam, HttpServletResponse response) { - return toAjax(iFileChunkFilelistService.postFileUpload(fileChunkParam, response)); + public R> postFileUpload(@ModelAttribute FileChunkParamBo fileChunkParam, HttpServletResponse response) { + boolean flag = iFileChunkFilelistService.postFileUpload(fileChunkParam, response); + Map map = new HashMap<>(); + if (flag){ + if (ObjectUtil.equal(fileChunkParam.getChunkNumber(),fileChunkParam.getTotalChunks()))map.put("needMerge", true); + return R.ok(map); + } + return R.warn("上传失败!"); } @@ -70,4 +83,19 @@ public class FileChunkFilelistController extends BaseController { return R.ok("操作成功", iFileChunkFilelistService.mergeFile(filelistBo)); } + /** + * 文件预览 + * @param param + * @return + */ + @GetMapping("/showConver") + public void showImage(@RequestParam("url") String url, HttpServletRequest request, HttpServletResponse response) { + try { + iFileChunkFilelistService.showFile(url,request,response); + } catch (IOException e) { + e.printStackTrace(); + } + } + + } diff --git a/ruoyi-system/src/main/java/com/ruoyi/official/domain/GwIndex.java b/ruoyi-system/src/main/java/com/ruoyi/official/domain/GwIndex.java index fb36f29..58d3b9f 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/official/domain/GwIndex.java +++ b/ruoyi-system/src/main/java/com/ruoyi/official/domain/GwIndex.java @@ -49,6 +49,11 @@ public class GwIndex extends BaseEntity { */ private String titleEnglish; + /** + * 视频链接地址 + */ + private String videoLink; + /** * 链接 diff --git a/ruoyi-system/src/main/java/com/ruoyi/official/domain/bo/GwIndexBo.java b/ruoyi-system/src/main/java/com/ruoyi/official/domain/bo/GwIndexBo.java index 7c1aa45..d37da4b 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/official/domain/bo/GwIndexBo.java +++ b/ruoyi-system/src/main/java/com/ruoyi/official/domain/bo/GwIndexBo.java @@ -40,6 +40,10 @@ public class GwIndexBo extends BaseEntity { */ private String fileType; + /** + * 视频链接地址 + */ + private String videoLink; /** * 链接 */ diff --git a/ruoyi-system/src/main/java/com/ruoyi/official/domain/vo/GwIndexVo.java b/ruoyi-system/src/main/java/com/ruoyi/official/domain/vo/GwIndexVo.java index 11cea12..f6f2578 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/official/domain/vo/GwIndexVo.java +++ b/ruoyi-system/src/main/java/com/ruoyi/official/domain/vo/GwIndexVo.java @@ -64,6 +64,11 @@ public class GwIndexVo { */ private String twLink; + /** + * 视频链接地址 + */ + private String videoLink; + /** * 图片标题英文描述 */ diff --git a/ruoyi-system/src/main/java/com/ruoyi/official/service/IFileChunkFilelistService.java b/ruoyi-system/src/main/java/com/ruoyi/official/service/IFileChunkFilelistService.java index 7464b1d..7ca5087 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/official/service/IFileChunkFilelistService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/official/service/IFileChunkFilelistService.java @@ -8,8 +8,12 @@ import com.ruoyi.official.domain.vo.FileChunkFilelistVo; import com.ruoyi.official.domain.bo.FileChunkFilelistBo; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.domain.PageQuery; +import org.springframework.core.io.InputStreamResource; +import org.springframework.http.ResponseEntity; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.util.Collection; import java.util.List; @@ -57,4 +61,6 @@ public interface IFileChunkFilelistService { CheckSysChunkVo getFileUpload(FileChunkParamBo fileChunkParam, HttpServletResponse response); String mergeFile(FileChunkFilelistBo FileChunkFilelistBo); + + void showFile(String imgUrl, HttpServletRequest request, HttpServletResponse response) throws IOException; } diff --git a/ruoyi-system/src/main/java/com/ruoyi/official/service/impl/FileChunkFilelistServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/official/service/impl/FileChunkFilelistServiceImpl.java index 1bd14e6..95c83e3 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/official/service/impl/FileChunkFilelistServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/official/service/impl/FileChunkFilelistServiceImpl.java @@ -1,44 +1,45 @@ package com.ruoyi.official.service.impl; import cn.hutool.core.bean.BeanUtil; -import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.common.core.page.TableDataInfo; -import com.ruoyi.common.core.domain.PageQuery; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.ruoyi.common.core.domain.PageQuery; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.official.domain.FileChunkFilelist; import com.ruoyi.official.domain.FileChunkParam; +import com.ruoyi.official.domain.bo.FileChunkFilelistBo; import com.ruoyi.official.domain.bo.FileChunkParamBo; import com.ruoyi.official.domain.vo.CheckSysChunkVo; +import com.ruoyi.official.domain.vo.FileChunkFilelistVo; import com.ruoyi.official.domain.vo.FileChunkParamVo; +import com.ruoyi.official.mapper.FileChunkFilelistMapper; import com.ruoyi.official.mapper.FileChunkParamMapper; +import com.ruoyi.official.service.IFileChunkFilelistService; import com.ruoyi.official.service.IFileChunkParamService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; -import com.ruoyi.official.domain.bo.FileChunkFilelistBo; -import com.ruoyi.official.domain.vo.FileChunkFilelistVo; -import com.ruoyi.official.domain.FileChunkFilelist; -import com.ruoyi.official.mapper.FileChunkFilelistMapper; -import com.ruoyi.official.service.IFileChunkFilelistService; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.io.Serializable; +import java.net.InetAddress; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; -import java.security.Security; +import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Map; -import java.util.Collection; import java.util.stream.Collectors; /** @@ -243,6 +244,25 @@ public class FileChunkFilelistServiceImpl implements IFileChunkFilelistService { return url; } + @Override + public void showFile(String imgUrl, HttpServletRequest request, HttpServletResponse response) throws IOException { + + // 设置响应的类型为视频流 + response.setContentType("video/mp4"); + + File videoFile = new File(filePath+imgUrl); + byte[] videoData = Files.readAllBytes(videoFile.toPath()); + + // 设置响应的长度为视频文件的长度 + response.setContentLength(videoData.length); + + OutputStream outputStream = response.getOutputStream(); + // 将视频数据写入输出流 + outputStream.write(videoData); + outputStream.flush(); + outputStream.close(); + } + /** * 生成块文件所在地址 */ @@ -308,7 +328,6 @@ public class FileChunkFilelistServiceImpl implements IFileChunkFilelistService { Files.delete(path); } } - } catch (IOException e) { log.error("合并出现错误:" + e); throw new RuntimeException("合并出现错误," + e.getMessage());