|
|
@@ -1,119 +0,0 @@
|
|
|
-package cn.reghao.tnb.file.app.service;
|
|
|
-
|
|
|
-import cn.reghao.jutil.tool.id.IdGenerator;
|
|
|
-import cn.reghao.tnb.file.api.constant.FileType;
|
|
|
-import cn.reghao.tnb.file.api.constant.VideoUrlType;
|
|
|
-import cn.reghao.tnb.file.app.db.mapper.FileInfoMapper;
|
|
|
-import cn.reghao.tnb.file.app.db.mapper.FileUrlMapper;
|
|
|
-import cn.reghao.tnb.file.app.db.mapper.ImageFileMapper;
|
|
|
-import cn.reghao.tnb.file.app.db.mapper.VideoFileMapper;
|
|
|
-import cn.reghao.tnb.file.app.model.dto.*;
|
|
|
-import cn.reghao.tnb.file.app.model.dto.auto.VideoFileDto;
|
|
|
-import cn.reghao.tnb.file.app.model.po.FileInfo;
|
|
|
-import cn.reghao.tnb.file.app.model.po.FileUrl;
|
|
|
-import cn.reghao.tnb.file.app.model.po.ImageFile;
|
|
|
-import cn.reghao.tnb.file.app.model.po.VideoFile;
|
|
|
-import cn.reghao.tnb.file.app.util.StringUtil;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-/**
|
|
|
- * @author reghao
|
|
|
- * @date 2021-08-04 17:29:47
|
|
|
- */
|
|
|
-@Slf4j
|
|
|
-@Service
|
|
|
-@Deprecated
|
|
|
-public class FileAutoService {
|
|
|
- private final IdGenerator idGenerator;
|
|
|
- private final FileInfoMapper fileInfoMapper;
|
|
|
- private final FileUrlMapper fileUrlMapper;
|
|
|
- private final VideoFileMapper videoFileMapper;
|
|
|
- private final ImageFileMapper imageFileMapper;
|
|
|
-
|
|
|
- public FileAutoService(FileInfoMapper fileInfoMapper, FileUrlMapper fileUrlMapper,
|
|
|
- VideoFileMapper videoFileMapper, ImageFileMapper imageFileMapper) {
|
|
|
- this.idGenerator = new IdGenerator("file-id");
|
|
|
- this.fileInfoMapper = fileInfoMapper;
|
|
|
- this.fileUrlMapper = fileUrlMapper;
|
|
|
- this.videoFileMapper = videoFileMapper;
|
|
|
- this.imageFileMapper = imageFileMapper;
|
|
|
- }
|
|
|
-
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public Map<String, String> processVideoFile(VideoFileDto videoFileDto) throws Exception {
|
|
|
- String sha256sum = videoFileDto.getSha256sum();
|
|
|
- if (fileInfoMapper.findBySha256sum(sha256sum) != null) {
|
|
|
- String msg = String.format("%s exists", sha256sum);
|
|
|
- throw new Exception(msg);
|
|
|
- }
|
|
|
-
|
|
|
- String filename = videoFileDto.getFilename();
|
|
|
- Long size = videoFileDto.getSize();
|
|
|
- String fileUrl = videoFileDto.getFileUrl();
|
|
|
- String videoFileType = FileType.mp4.getContentType();
|
|
|
- FileDto fileDto = saveFile(sha256sum, filename, size, 3, fileUrl);
|
|
|
- String videoFileId = fileDto.getFileId();
|
|
|
- String videoUrl = fileDto.getUrl();
|
|
|
-
|
|
|
- String sha256sumCover = videoFileDto.getSha256sumCover();
|
|
|
- String coverUrl = videoFileDto.getCoverUrl();
|
|
|
- long imgSize = videoFileDto.getImgSize();
|
|
|
- int imgWidth = videoFileDto.getImgWidth();
|
|
|
- int imgHeight = videoFileDto.getImgHeight();
|
|
|
- String imgFileType = FileType.jpg.getContentType();
|
|
|
- FileDto fileDto1 = saveFile(sha256sumCover, "default.jpg", imgSize, 1, coverUrl);
|
|
|
- saveVideoCover(fileDto1.getFileId(), fileDto1.getUrl(), imgWidth, imgHeight);
|
|
|
- String coverFileId = fileDto1.getFileId();
|
|
|
-
|
|
|
- VideoFile videoFile = new VideoFile(videoFileId, VideoUrlType.mp4.getName(), videoUrl);
|
|
|
- videoFile.setWidth(videoFileDto.getWidth());
|
|
|
- videoFile.setHeight(videoFileDto.getHeight());
|
|
|
- videoFile.setHorizontal(videoFileDto.getWidth() >= videoFileDto.getHeight());
|
|
|
- videoFile.setFrameRate(videoFileDto.getFps());
|
|
|
- videoFile.setDuration(videoFileDto.getDuration());
|
|
|
- videoFile.setRotate(videoFileDto.getRotate());
|
|
|
- videoFile.setBaseCoverUrl(fileDto1.getUrl());
|
|
|
- videoFileMapper.save(videoFile);
|
|
|
-
|
|
|
- addVideoPost(videoFile.getFileId(), videoFileDto);
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
- map.put("videoFileId", videoFileId);
|
|
|
- map.put("coverFileId", coverFileId);
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
- public void saveVideoCover(String fileId, String url, int width, int height) {
|
|
|
- ImageFile imageFile = new ImageFile(fileId, url, width, height);
|
|
|
- imageFileMapper.save(imageFile);
|
|
|
- }
|
|
|
-
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public FileDto saveFile(String sha256sum, String filename, long size, int fileType, String fileUrl) {
|
|
|
- String suffix = StringUtil.getSuffix(filename);
|
|
|
- String fileId = idGenerator.getUuid();
|
|
|
- String url = fileUrl.substring(0, fileUrl.lastIndexOf("/")+1) + fileId + suffix;
|
|
|
- String url1 = "//static.reghao.cn/group0/node0" + url;
|
|
|
-
|
|
|
- FileInfo fileInfo = new FileInfo();
|
|
|
- FileUrl fileUrl1 = new FileUrl(fileId, "", url1, "");
|
|
|
- fileInfoMapper.save(fileInfo);
|
|
|
- fileUrlMapper.save(fileUrl1);
|
|
|
- return new FileDto(fileId, "", "", url1);
|
|
|
- }
|
|
|
-
|
|
|
- public void addVideoPost(String fileId, VideoFileDto videoFileDto) {
|
|
|
- String title = videoFileDto.getTitle();
|
|
|
- String tags = videoFileDto.getTags();
|
|
|
- int categoryPid = videoFileDto.getCategoryPid();
|
|
|
- int categoryId = videoFileDto.getCategoryId();
|
|
|
- long userId = videoFileDto.getUserId();
|
|
|
-
|
|
|
- //VideoAutoPostDto videoAutoPostDto = new VideoAutoPostDto(fileId, userId, title, tags, categoryPid, categoryId);
|
|
|
- //videoPostService.createAndPublish(videoAutoPostDto);
|
|
|
- }
|
|
|
-}
|