|
@@ -3,16 +3,29 @@ package com.fdkankan.fusion.service.impl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.fdkankan.common.constant.ErrorCode;
|
|
|
+import com.fdkankan.fusion.common.FilePath;
|
|
|
+import com.fdkankan.fusion.common.ResultCode;
|
|
|
+import com.fdkankan.fusion.entity.CaseEntity;
|
|
|
+import com.fdkankan.fusion.entity.CaseVideoFolder;
|
|
|
import com.fdkankan.fusion.exception.BusinessException;
|
|
|
import com.fdkankan.fusion.entity.CaseVideo;
|
|
|
import com.fdkankan.fusion.mapper.ICaseVideoMapper;
|
|
|
import com.fdkankan.fusion.request.CaseParam;
|
|
|
import com.fdkankan.fusion.request.CaseVideoParam;
|
|
|
+import com.fdkankan.fusion.service.ICaseService;
|
|
|
+import com.fdkankan.fusion.service.ICaseVideoFolderService;
|
|
|
import com.fdkankan.fusion.service.ICaseVideoService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -26,33 +39,86 @@ import java.util.List;
|
|
|
@Service
|
|
|
public class CaseVideoServiceImpl extends ServiceImpl<ICaseVideoMapper, CaseVideo> implements ICaseVideoService {
|
|
|
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ UploadToOssUtil uploadToOssUtil;
|
|
|
+ @Autowired
|
|
|
+ ICaseVideoFolderService videoFolderService;
|
|
|
+ @Autowired
|
|
|
+ ICaseService caseService;
|
|
|
+ @Autowired
|
|
|
+ UploadService uploadService;
|
|
|
+
|
|
|
+ @Value("${upload.query-path}")
|
|
|
+ private String queryPath;
|
|
|
+
|
|
|
@Override
|
|
|
- public List<CaseVideo> getList(CaseVideoParam param) {
|
|
|
- if(param.getCaseId() == null){
|
|
|
+ public List<CaseVideo> getAllList(Integer folderId) {
|
|
|
+ if(folderId == null){
|
|
|
throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
}
|
|
|
QueryWrapper<CaseVideo> wrapper = new QueryWrapper<>();
|
|
|
- wrapper.lambda().eq(CaseVideo::getCaseId,param.getCaseId());
|
|
|
- if(StringUtils.isNotBlank(param.getOrderBy())){
|
|
|
- if(param.getSortBy().toLowerCase().equals("desc")){
|
|
|
- wrapper.orderByDesc(param.getOrderBy());
|
|
|
- }else {
|
|
|
- wrapper.orderByAsc(param.getOrderBy());
|
|
|
- }
|
|
|
- }
|
|
|
+ wrapper.lambda().eq(CaseVideo::getFolderId,folderId);
|
|
|
+ wrapper.lambda().orderByAsc(CaseVideo::getSort);
|
|
|
+ wrapper.lambda().orderByAsc(CaseVideo::getCreateTime);
|
|
|
return this.list(wrapper);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void add(CaseVideoParam param) {
|
|
|
- if(param.getCaseId() == null || StringUtils.isEmpty(param.getVideoName()) || StringUtils.isEmpty(param.getVideoPath())){
|
|
|
+ public void uploadAddVideo(MultipartFile[] files, Integer folderId,Integer caseId) throws IOException {
|
|
|
+ if(files.length <=0 || caseId == null){
|
|
|
throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
}
|
|
|
- CaseVideo caseVideo = new CaseVideo();
|
|
|
- caseVideo.setCaseId(param.getCaseId());
|
|
|
- caseVideo.setVideoPath(param.getVideoPath());
|
|
|
- caseVideo.setVoideName(param.getVideoName());
|
|
|
- caseVideo.setSort(param.getSort());
|
|
|
- this.save(caseVideo);
|
|
|
+ CaseEntity caseEntity = caseService.getById(caseId);
|
|
|
+ if(caseEntity == null){
|
|
|
+ throw new BusinessException(ResultCode.CASE_NOT_EXIST);
|
|
|
+ }
|
|
|
+ CaseVideoFolder videoFolder = videoFolderService.getByIdIfNotNew(folderId,caseId);
|
|
|
+ if(videoFolder == null){
|
|
|
+ throw new BusinessException(ResultCode.FOLDER_NOT_EXIST);
|
|
|
+ }
|
|
|
+ //替换文件夹中文件
|
|
|
+ this.deleteByFolderId(folderId);
|
|
|
+ List<CaseVideo> videoList = new ArrayList<>();
|
|
|
+ Integer sort = 1;
|
|
|
+ for (MultipartFile file : files) {
|
|
|
+ String ossPath = uploadService.uploadFile(file, true, String.format(FilePath.VIDEO_OSS_PATH,videoFolder.getVideoFolderId()));
|
|
|
+ CaseVideo caseVideo = new CaseVideo();
|
|
|
+ caseVideo.setFolderId(videoFolder.getVideoFolderId());
|
|
|
+ caseVideo.setVideoPath(ossPath);
|
|
|
+ caseVideo.setVideoName(file.getName());
|
|
|
+ caseVideo.setSort(sort);
|
|
|
+ videoList.add(caseVideo);
|
|
|
+ sort ++;
|
|
|
+ }
|
|
|
+ this.saveBatch(videoList);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteByFolderId(Integer videoFolderId) {
|
|
|
+ LambdaQueryWrapper<CaseVideo> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(CaseVideo::getFolderId,videoFolderId);
|
|
|
+ List<CaseVideo> list = this.list(wrapper);
|
|
|
+ if(list.size() <=0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (CaseVideo caseVideo : list) {
|
|
|
+ this.delete(caseVideo.getVideoId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delete(Integer videoId) {
|
|
|
+ CaseVideo caseVideo = this.getById(videoId);
|
|
|
+ this.removeById(videoId);
|
|
|
+ try {
|
|
|
+ String replace = caseVideo.getVideoPath().replace(queryPath, "");
|
|
|
+ uploadToOssUtil.delete(replace);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|