Commit 479754df authored by root's avatar root

Merge branch 'meiteng' of ssh://103.249.252.28:10022/lcy/education into meiteng

parents 803abedf bc015db1
......@@ -71,10 +71,7 @@ public interface BChapterRepository extends BaseMapper<BChapter> {
" bc.lesson_id,\n" +
" bc.sort," +
" bf.video_url AS videoUrl,\n" +
" bf.file_url AS fileUrl,\n" +
" bf.ppt_url AS pptUrl,\n" +
" bf.pdf_url AS pdfUrl," +
" bf.video_name AS fileName\n" +
" bf.file_name AS fileName\n" +
" FROM\n" +
" b_chapter bc\n" +
" LEFT JOIN b_file bf ON bf.chapter_id = bc.business_id " +
......
......@@ -32,7 +32,7 @@ import java.util.List;
*/
@Api(tags = "04 文件")
@RestController
@RequestMapping("/BVideo")
@RequestMapping("/bfile")
public class BFileController extends PaginationController<BFile> {
@Autowired
private BFileService bFileService;
......@@ -40,15 +40,12 @@ public class BFileController extends PaginationController<BFile> {
private Global global;
@ApiOperation(value="401 上传文件", notes="上传文件")
@ApiImplicitParams({@ApiImplicitParam(name = "chapterId", value = "章节ID", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "type", value = "0视频 1音频 2ppt 3pdf 4附件", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "lessonId", value = "章节所在课程id", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "file", value = "视频文件", required = true, dataType = "MultipartFile")})
@PostMapping(value = "/uploadVideo")
@ApiImplicitParam(name = "file", value = "视频文件", required = true, dataType = "MultipartFile")
@PostMapping(value = "/upload")
public Result uploadVideo(BFile bFile, HttpServletRequest request) {
List<MultipartFile> list = ((MultipartHttpServletRequest)request).getFiles("file");
String videoUrl = bFileService.uploadVideoToServer(list, bFile);
String videoUrl = bFileService.uploadVideoToServer(list, bFile);
return Result.builder(new PersistModel(1),
"上传成功",
......
package org.rcisoft.business.bfile.service.impl; import com.itextpdf.text.pdf.PdfReader;import org.apache.commons.io.FileUtils;import org.rcisoft.business.bchapter.entity.BChapter;import org.rcisoft.business.bfile.dao.BFileRepository;import org.rcisoft.business.bfile.entity.BFile;import org.rcisoft.business.bfile.service.BFileService;import org.rcisoft.business.bfile.util.GetVideoTime;import org.rcisoft.business.bsl.task.SlTask;import org.rcisoft.common.component.Global;import org.rcisoft.core.aop.PageUtil;import org.rcisoft.core.bean.RcLkConfigBean;import org.rcisoft.core.constant.DelStatus;import org.rcisoft.core.exception.ServiceException;import org.rcisoft.core.model.PersistModel;import org.rcisoft.core.result.ResultServiceEnums;import org.rcisoft.core.util.FileUtil;import org.rcisoft.core.util.IdGen;import org.rcisoft.core.util.UserUtil;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import org.springframework.transaction.annotation.Propagation;import org.springframework.transaction.annotation.Transactional;import org.springframework.web.multipart.MultipartFile; 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.HashMap;import java.util.List;import java.util.Map; import static org.rcisoft.core.util.CutPdfUtil.partitionPdfFile; /** * Created by gaowenfneg on 2017-10-9 14:34:56. */@Service@Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)public class BFileServiceImpl implements BFileService { @Autowired private BFileRepository bFileRepository; @Autowired private SlTask slTask; @Autowired private Global global; @Autowired private RcLkConfigBean rcLkConfigBean; @Override public BFile selectOne(String businessId) { return bFileRepository.selectByPrimaryKey(businessId); } @Override public List<BFile> queryBVideosByPagination(PageUtil pageUtil, BFile model) { Map param = new HashMap<String, Object>(); return bFileRepository.queryBVideos(param); } @Override public List<BFile> queryBVideos(BFile model) { Map param = new HashMap<String, Object>(); return bFileRepository.queryBVideos(param); } @Override public PersistModel persist(BFile model) { UserUtil.setCurrentPersistOperation(model); int line = bFileRepository.insertSelective(model); return new PersistModel(line); } @Override public PersistModel removeBVideo(String id) { BFile bFile = bFileRepository.selectByPrimaryKey(id); bFile.setDelFlag(DelStatus.DELETED.getStatus()); UserUtil.setCurrentMergeOperation(bFile); int line = bFileRepository.updateByPrimaryKeySelective(bFile); return new PersistModel(line); } @Override @Transactional(propagation = Propagation.REQUIRED, readOnly = false) public String uploadVideoToServer(List<MultipartFile> list, BFile bFile) { String videoUrl = ""; if (list.size() > 0) { for (int i = 0; i < list.size(); ++i) { MultipartFile file = list.get(i); try { //查询此节是否已有视频或文件 BFile video = bFileRepository.selectInfoByChapterId(bFile.getChapterId()); if (video != null) {//此节已有视频或文件,将已有的视频或文件放置到temp目录下,然后上传新视频或文件 if (bFile.getType().equals("0") && video.getVideoUrl() != null && !video.getVideoUrl().equals("")) { this.removeVideoToTemp(bFile);//复制之前视频到temp文件下 } if (bFile.getType().equals("1") && video.getAudioUrl() != null && !video.getAudioUrl().equals("")) { this.removeVideoToTemp(bFile);//复制之前音频到temp文件下 } if (bFile.getType().equals("2") && video.getPptUrl() != null && !video.getPptUrl().equals("")) { this.removeVideoToTemp(bFile);//复制之前ppt到temp文件下 } if (bFile.getType().equals("3") && video.getPdfUrl() != null && !video.getPdfUrl().equals("")) { this.removeVideoToTemp(bFile);//复制之前pdf到temp文件下 } if (bFile.getType().equals("4") && video.getFileUrl() != null && !video.getFileUrl().equals("")) { this.removeVideoToTemp(bFile);//复制之前文件到temp文件下 } BFile newVideo = this.uploadVideo(file, bFile);//上传新文件 newVideo.setBusinessId(video.getBusinessId()); UserUtil.setCurrentMergeOperation(newVideo); bFileRepository.updateByPrimaryKeySelective(newVideo);//更新表中信息 if (bFile.getType().equals("0")) { videoUrl = newVideo.getVideoUrl(); } else if (bFile.getType().equals("1")) { videoUrl = newVideo.getAudioUrl(); } else if (bFile.getType().equals("2")) { videoUrl = newVideo.getPptUrl(); } else if (bFile.getType().equals("3")) { videoUrl = newVideo.getPdfUrl(); } else { videoUrl = newVideo.getFileUrl(); } } else { BFile newVideo = this.uploadVideo(file, bFile);//上传文件 this.persist(newVideo);//插入表信息 if (bFile.getType().equals("0")) { videoUrl = newVideo.getVideoUrl(); } else if (bFile.getType().equals("1")) { videoUrl = newVideo.getAudioUrl(); } else if (bFile.getType().equals("2")) { videoUrl = newVideo.getPptUrl(); } else if (bFile.getType().equals("3")) { videoUrl = newVideo.getPdfUrl(); } else { videoUrl = newVideo.getFileUrl(); } } } catch (Exception e) { e.printStackTrace(); throw new ServiceException(ResultServiceEnums.UPLOAD_ERROR); } } } return videoUrl; } /** * 将原视频复制到temp/video文件下,并删除原视频 * * @param bFile */ private void removeVideoToTemp(BFile bFile) throws Exception { String path; String pathName; if (bFile.getLessonId() != null && !bFile.getLessonId().equals("")) { path = global.getLESSON_LOCATION() + File.separator + bFile.getLessonId() + File.separator; } else { throw new ServiceException("路径错误!"); } if (bFile.getType().equals("0")) { pathName = global.getVIDEO_LOCATION();//视频路径 } else if (bFile.getType().equals("1")) { pathName = global.getAUDIO_LOCATION();//音频路径 } else if (bFile.getType().equals("2")) { pathName = global.getPPT_LOCATION();//ppt路径 } else if (bFile.getType().equals("3")) { pathName = global.getPDF_LOCATION();//pdf路径 } else { pathName = global.getFILE_LOCATION();//文件路径 } String tempPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + global.getCOURSE_LOCATION() + File.separator + global.getTEMP_LOCATION() + File.separator + path + bFile.getChapterId(); File tempFilePath = new File(tempPath); if (tempFilePath.exists()) { FileUtils.deleteDirectory(tempFilePath); } String realFilePath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + global.getCOURSE_LOCATION() + File.separator + path + bFile.getChapterId() + File.separator + pathName; File directory = new File(realFilePath); if (directory.exists()) { FileUtils.moveDirectory(directory, tempFilePath); } } /** * 上传视频到video目录 * * @param file * @param bFile * @return * @throws IOException */ private BFile uploadVideo(MultipartFile file, BFile bFile) throws IOException { BufferedOutputStream stream = null; String path; String pathName; if (bFile.getLessonId() != null && !bFile.getLessonId().equals("")) { path = global.getLESSON_LOCATION() + File.separator + bFile.getLessonId() + File.separator; } else { throw new ServiceException("路径错误!"); } if (bFile.getType().equals("0")) { pathName = global.getVIDEO_LOCATION();//视频路径 } else if (bFile.getType().equals("1")) { pathName = global.getAUDIO_LOCATION();//音频路径 } else if (bFile.getType().equals("2")) { pathName = global.getPPT_LOCATION();//ppt路径 } else if (bFile.getType().equals("3")) { pathName = global.getPDF_LOCATION();//pdf路径 } else { pathName = global.getFILE_LOCATION();//文件路径 } String realPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + global.getCOURSE_LOCATION() + File.separator + path + bFile.getChapterId() + File.separator + pathName + File.separator; File outFile = new File(realPath); if (!outFile.exists()) {//判断保存路径是否存在,不存在新建 outFile.mkdirs(); } //上传文件 String uploadFile = file.getOriginalFilename(); //文件的真实名称 String name = uploadFile.substring(uploadFile.lastIndexOf(File.separator) + 1, uploadFile.lastIndexOf('.')); // 截取上传文件的后缀 String uploadFileSuffix = FileUtil.getFilePostfix(uploadFile); //uploadFile.substring(uploadFile.lastIndexOf('.') + 1, uploadFile.length()); // 设置文件名为乱码 String uploadFileName = IdGen.uuid(); String filename = uploadFileName + "." + uploadFileSuffix; stream = new BufferedOutputStream(new FileOutputStream(new File(realPath + filename))); byte[] bytes = file.getBytes(); stream.write(bytes, 0, bytes.length); String newPath = global.getCOURSE_LOCATION() + File.separator + path + bFile.getChapterId() + File.separator + pathName + File.separator; if (uploadFileSuffix.equals("ppt") && bFile.getType().equals("2")) {//ppt转pdf String inputFile = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + newPath + filename; String outputFile = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + newPath + uploadFileName + ".pdf"; slTask.officeToPdf(inputFile, outputFile); } if (uploadFileSuffix.equals("pdf") && bFile.getType().equals("3")) {//pdf切割 try { slTask.cutPdf(newPath, filename, uploadFileName); } catch (Exception e) { e.printStackTrace(); } } //上传的是文件时才存文件名,方便下载时取 if (bFile.getType().equals("4")) { bFile.setVideoName(name + "." + uploadFileSuffix);//文件名 } if (bFile.getType().equals("0")) { bFile.setVideoUrl(newPath + filename);//视频路径 // String url = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + newPath + filename; //// 根据视频路径获取所添加视频的时间 // GetVideoTime getVideoTime = new GetVideoTime(); // String time = getVideoTime.getVideoDuration(url); // String id = bFile.getChapterId(); //// 获取当前课程的第一章第一节的章节id // String cid = bFileRepository.getFirstChapter(bFile.getLessonId()); //// 判断当章节id和当前课程的第一章第一节的章节id是否相同 // if (cid.equals(id)) { // bFileRepository.updateVideoTimeInLesson(time, bFile.getLessonId()); // } // bFileRepository.updateVideoTimeInChapter(time, id); } else if (bFile.getType().equals("1")) { bFile.setAudioUrl(newPath + filename);//音频路径 //// String url = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + newPath + filename; ////// 根据视频路径获取所添加音频的时间 //// GetVideoTime getVideoTime = new GetVideoTime(); //// String time = getVideoTime.getVideoDuration(url); //// String id = bFile.getChapterId(); ////// 获取当前课程的第一章第一节的章节id //// String cid = bFileRepository.getFirstChapter(bFile.getLessonId()); ////// 判断当章节id和当前课程的第一章第一节的章节id是否相同 //// if (cid.equals(id)) { //// bFileRepository.updateVideoTimeInLesson(time, bFile.getLessonId()); //// } // bFileRepository.updateVideoTimeInChapter(time, id); } else if (bFile.getType().equals("2")) { bFile.setPptUrl(newPath + uploadFileName + ".pdf");//ppt路径 } else if (bFile.getType().equals("3")) { bFile.setPdfUrl(newPath + filename);//pdf路径 } else { bFile.setFileUrl(newPath + filename);//文件路径 } stream.close(); return bFile; } @Override public BFile queryFileUrlByChapterId(String chapterId) { return bFileRepository.queryFileUrlByChapterId(chapterId); } @Override public void uploadLicense(MultipartFile file) { try { BufferedOutputStream stream = null; String path = global.getBASE_UPLOAD_SERVER_LOCATION() + rcLkConfigBean.getLicPath(); File oldFile = new File(path); if (oldFile.exists()) { FileUtils.forceDelete(oldFile); } File newFile = new File(path); stream = new BufferedOutputStream(new FileOutputStream(newFile)); byte[] bytes = file.getBytes(); stream.write(bytes, 0, bytes.length); stream.flush(); stream.close(); } catch (Exception e) { e.printStackTrace(); throw new ServiceException(ResultServiceEnums.UPLOAD_ERROR); } return; } /** * 重新转换ppt * * @param businessId * @param type 0开课 1课程 * @return */ @Override public List<String> reConversionPPT(String businessId, String type) { List<String> failPPTPath = new ArrayList<>(); try { String basePath = global.getSL_LOCATION(); if (type.equals("1")) { basePath = global.getLESSON_LOCATION(); } String path = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + global.getCOURSE_LOCATION() + File.separator + basePath + File.separator + businessId; File file = new File(path); failPPTPath = this.changePPTToPDF(file, failPPTPath); } catch (IOException e) { e.printStackTrace(); } return failPPTPath; } private List<String> changePPTToPDF(File slFile, List<String> failPPTPath) throws IOException { for (File chapterFile : slFile.listFiles()) { String pptPath = chapterFile.getPath() + File.separator + "ppt"; File pptFile = new File(pptPath); if (pptFile.exists()) { File[] pptFiles = pptFile.listFiles(); if (pptFiles.length == 1 && pptFiles[0].getName().endsWith("ppt")) { failPPTPath.add(pptFiles[0].getPath()); String inputFile = pptFiles[0].getPath(); String outputFile = pptFiles[0].getPath().substring(0, pptFiles[0].getPath().lastIndexOf(".")) + ".pdf"; slTask.officeToPdf(inputFile, outputFile); } } } return failPPTPath; } /*public String uploadFileToServer(MultipartFile file, BFile bFile) throws Exception{ String fileUrl = ""; //查询此节是否已有视频或文件 BFile f = bFileRepository.selectInfoByChapterId(bFile.getChapterId()); if (f!=null){ //复制文件到临时目录 this.removeVideoToTemp(bFile); }else{ BFile newVideo = this.uploadVideo(file, bFile);//上传文件 if (bFile.getType().equals("0")){ fileUrl = newVideo.getVideoUrl(); }else if(bFile.getType().equals("1")){ fileUrl = newVideo.getFileUrl(); }else if(bFile.getType().equals("2")){ fileUrl = newVideo.getPptUrl(); }else{ fileUrl = newVideo.getPdfUrl(); } } return fileUrl; }*/ }
\ No newline at end of file
package org.rcisoft.business.bfile.service.impl; import com.itextpdf.text.pdf.PdfReader;import org.apache.commons.io.FileUtils;import org.rcisoft.business.bchapter.entity.BChapter;import org.rcisoft.business.bfile.dao.BFileRepository;import org.rcisoft.business.bfile.entity.BFile;import org.rcisoft.business.bfile.service.BFileService;import org.rcisoft.business.bfile.util.GetVideoTime;import org.rcisoft.business.bsl.task.SlTask;import org.rcisoft.common.component.Global;import org.rcisoft.core.aop.PageUtil;import org.rcisoft.core.bean.RcLkConfigBean;import org.rcisoft.core.constant.DelStatus;import org.rcisoft.core.exception.ServiceException;import org.rcisoft.core.model.PersistModel;import org.rcisoft.core.result.ResultServiceEnums;import org.rcisoft.core.util.FileUtil;import org.rcisoft.core.util.IdGen;import org.rcisoft.core.util.UserUtil;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import org.springframework.transaction.annotation.Propagation;import org.springframework.transaction.annotation.Transactional;import org.springframework.web.multipart.MultipartFile; 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.HashMap;import java.util.List;import java.util.Map; import static org.rcisoft.core.util.CutPdfUtil.partitionPdfFile; /** * Created by gaowenfneg on 2017-10-9 14:34:56. */@Service@Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)public class BFileServiceImpl implements BFileService { @Autowired private BFileRepository bFileRepository; @Autowired private SlTask slTask; @Autowired private Global global; @Autowired private RcLkConfigBean rcLkConfigBean; @Override public BFile selectOne(String businessId) { return bFileRepository.selectByPrimaryKey(businessId); } @Override public List<BFile> queryBVideosByPagination(PageUtil pageUtil, BFile model) { Map param = new HashMap<String, Object>(); return bFileRepository.queryBVideos(param); } @Override public List<BFile> queryBVideos(BFile model) { Map param = new HashMap<String, Object>(); return bFileRepository.queryBVideos(param); } @Override public PersistModel persist(BFile model) { UserUtil.setCurrentPersistOperation(model); int line = bFileRepository.insertSelective(model); return new PersistModel(line); } @Override public PersistModel removeBVideo(String id) { BFile bFile = bFileRepository.selectByPrimaryKey(id); bFile.setDelFlag(DelStatus.DELETED.getStatus()); UserUtil.setCurrentMergeOperation(bFile); int line = bFileRepository.updateByPrimaryKeySelective(bFile); return new PersistModel(line); } @Override @Transactional(propagation = Propagation.REQUIRED, readOnly = false) public String uploadVideoToServer(List<MultipartFile> list, BFile bFile) { String videoUrl = ""; if (list.size() > 0) { try { if (bFile.getType().equals("0")) { videoUrl = "https://s2.luckincoffeecdn.com/luckywebrm/images/index/luckincoffee_TVC30.mp4"; } else if (bFile.getType().equals("1")) { videoUrl = "https://webfs.yun.kugou.com/201910101737/d56a90f4c0d75be840f66c7ed8e237ca/G171/M0B/18/10/i5QEAF2c0cKAJ63iADBEFy9sicA739.mp3"; } else if (bFile.getType().equals("2")) { videoUrl = "https://s2.luckincoffeecdn.com/luckywebrm/images/index/luckincoffee_TVC30.mp4"; } else if (bFile.getType().equals("3")) { videoUrl = "https://s2.luckincoffeecdn.com/luckywebrm/images/index/luckincoffee_TVC30.mp4"; } else { videoUrl = "https://s2.luckincoffeecdn.com/luckywebrm/images/index/luckincoffee_TVC30.mp4"; } } catch (Exception e) { e.printStackTrace(); throw new ServiceException(ResultServiceEnums.UPLOAD_ERROR); } } return videoUrl; } /** * 将原视频复制到temp/video文件下,并删除原视频 * * @param bFile */ private void removeVideoToTemp(BFile bFile) throws Exception { String path; String pathName; if (bFile.getLessonId() != null && !bFile.getLessonId().equals("")) { path = global.getLESSON_LOCATION() + File.separator + bFile.getLessonId() + File.separator; } else { throw new ServiceException("路径错误!"); } if (bFile.getType().equals("0")) { pathName = global.getVIDEO_LOCATION();//视频路径 } else if (bFile.getType().equals("1")) { pathName = global.getAUDIO_LOCATION();//音频路径 } else if (bFile.getType().equals("2")) { pathName = global.getPPT_LOCATION();//ppt路径 } else if (bFile.getType().equals("3")) { pathName = global.getPDF_LOCATION();//pdf路径 } else { pathName = global.getFILE_LOCATION();//文件路径 } String tempPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + global.getCOURSE_LOCATION() + File.separator + global.getTEMP_LOCATION() + File.separator + path + bFile.getChapterId(); File tempFilePath = new File(tempPath); if (tempFilePath.exists()) { FileUtils.deleteDirectory(tempFilePath); } String realFilePath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + global.getCOURSE_LOCATION() + File.separator + path + bFile.getChapterId() + File.separator + pathName; File directory = new File(realFilePath); if (directory.exists()) { FileUtils.moveDirectory(directory, tempFilePath); } } /** * 上传视频到video目录 * * @param file * @param bFile * @return * @throws IOException */ private BFile uploadVideo(MultipartFile file, BFile bFile) throws IOException { BufferedOutputStream stream = null; String path; String pathName; if (bFile.getLessonId() != null && !bFile.getLessonId().equals("")) { path = global.getLESSON_LOCATION() + File.separator + bFile.getLessonId() + File.separator; } else { throw new ServiceException("路径错误!"); } if (bFile.getType().equals("0")) { pathName = global.getVIDEO_LOCATION();//视频路径 } else if (bFile.getType().equals("1")) { pathName = global.getAUDIO_LOCATION();//音频路径 } else if (bFile.getType().equals("2")) { pathName = global.getPPT_LOCATION();//ppt路径 } else if (bFile.getType().equals("3")) { pathName = global.getPDF_LOCATION();//pdf路径 } else { pathName = global.getFILE_LOCATION();//文件路径 } String realPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + global.getCOURSE_LOCATION() + File.separator + path + bFile.getChapterId() + File.separator + pathName + File.separator; File outFile = new File(realPath); if (!outFile.exists()) {//判断保存路径是否存在,不存在新建 outFile.mkdirs(); } //上传文件 String uploadFile = file.getOriginalFilename(); //文件的真实名称 String name = uploadFile.substring(uploadFile.lastIndexOf(File.separator) + 1, uploadFile.lastIndexOf('.')); // 截取上传文件的后缀 String uploadFileSuffix = FileUtil.getFilePostfix(uploadFile); //uploadFile.substring(uploadFile.lastIndexOf('.') + 1, uploadFile.length()); // 设置文件名为乱码 String uploadFileName = IdGen.uuid(); String filename = uploadFileName + "." + uploadFileSuffix; stream = new BufferedOutputStream(new FileOutputStream(new File(realPath + filename))); byte[] bytes = file.getBytes(); stream.write(bytes, 0, bytes.length); String newPath = global.getCOURSE_LOCATION() + File.separator + path + bFile.getChapterId() + File.separator + pathName + File.separator; if (uploadFileSuffix.equals("ppt") && bFile.getType().equals("2")) {//ppt转pdf String inputFile = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + newPath + filename; String outputFile = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + newPath + uploadFileName + ".pdf"; slTask.officeToPdf(inputFile, outputFile); } if (uploadFileSuffix.equals("pdf") && bFile.getType().equals("3")) {//pdf切割 try { slTask.cutPdf(newPath, filename, uploadFileName); } catch (Exception e) { e.printStackTrace(); } } //上传的是文件时才存文件名,方便下载时取 if (bFile.getType().equals("4")) { bFile.setVideoName(name + "." + uploadFileSuffix);//文件名 } if (bFile.getType().equals("0")) { bFile.setVideoUrl(newPath + filename);//视频路径 // String url = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + newPath + filename; //// 根据视频路径获取所添加视频的时间 // GetVideoTime getVideoTime = new GetVideoTime(); // String time = getVideoTime.getVideoDuration(url); // String id = bFile.getChapterId(); //// 获取当前课程的第一章第一节的章节id // String cid = bFileRepository.getFirstChapter(bFile.getLessonId()); //// 判断当章节id和当前课程的第一章第一节的章节id是否相同 // if (cid.equals(id)) { // bFileRepository.updateVideoTimeInLesson(time, bFile.getLessonId()); // } // bFileRepository.updateVideoTimeInChapter(time, id); } else if (bFile.getType().equals("1")) { bFile.setAudioUrl(newPath + filename);//音频路径 //// String url = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + newPath + filename; ////// 根据视频路径获取所添加音频的时间 //// GetVideoTime getVideoTime = new GetVideoTime(); //// String time = getVideoTime.getVideoDuration(url); //// String id = bFile.getChapterId(); ////// 获取当前课程的第一章第一节的章节id //// String cid = bFileRepository.getFirstChapter(bFile.getLessonId()); ////// 判断当章节id和当前课程的第一章第一节的章节id是否相同 //// if (cid.equals(id)) { //// bFileRepository.updateVideoTimeInLesson(time, bFile.getLessonId()); //// } // bFileRepository.updateVideoTimeInChapter(time, id); } else if (bFile.getType().equals("2")) { bFile.setPptUrl(newPath + uploadFileName + ".pdf");//ppt路径 } else if (bFile.getType().equals("3")) { bFile.setPdfUrl(newPath + filename);//pdf路径 } else { bFile.setFileUrl(newPath + filename);//文件路径 } stream.close(); return bFile; } @Override public BFile queryFileUrlByChapterId(String chapterId) { return bFileRepository.queryFileUrlByChapterId(chapterId); } @Override public void uploadLicense(MultipartFile file) { try { BufferedOutputStream stream = null; String path = global.getBASE_UPLOAD_SERVER_LOCATION() + rcLkConfigBean.getLicPath(); File oldFile = new File(path); if (oldFile.exists()) { FileUtils.forceDelete(oldFile); } File newFile = new File(path); stream = new BufferedOutputStream(new FileOutputStream(newFile)); byte[] bytes = file.getBytes(); stream.write(bytes, 0, bytes.length); stream.flush(); stream.close(); } catch (Exception e) { e.printStackTrace(); throw new ServiceException(ResultServiceEnums.UPLOAD_ERROR); } return; } /** * 重新转换ppt * * @param businessId * @param type 0开课 1课程 * @return */ @Override public List<String> reConversionPPT(String businessId, String type) { List<String> failPPTPath = new ArrayList<>(); try { String basePath = global.getSL_LOCATION(); if (type.equals("1")) { basePath = global.getLESSON_LOCATION(); } String path = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + global.getCOURSE_LOCATION() + File.separator + basePath + File.separator + businessId; File file = new File(path); failPPTPath = this.changePPTToPDF(file, failPPTPath); } catch (IOException e) { e.printStackTrace(); } return failPPTPath; } private List<String> changePPTToPDF(File slFile, List<String> failPPTPath) throws IOException { for (File chapterFile : slFile.listFiles()) { String pptPath = chapterFile.getPath() + File.separator + "ppt"; File pptFile = new File(pptPath); if (pptFile.exists()) { File[] pptFiles = pptFile.listFiles(); if (pptFiles.length == 1 && pptFiles[0].getName().endsWith("ppt")) { failPPTPath.add(pptFiles[0].getPath()); String inputFile = pptFiles[0].getPath(); String outputFile = pptFiles[0].getPath().substring(0, pptFiles[0].getPath().lastIndexOf(".")) + ".pdf"; slTask.officeToPdf(inputFile, outputFile); } } } return failPPTPath; } /*public String uploadFileToServer(MultipartFile file, BFile bFile) throws Exception{ String fileUrl = ""; //查询此节是否已有视频或文件 BFile f = bFileRepository.selectInfoByChapterId(bFile.getChapterId()); if (f!=null){ //复制文件到临时目录 this.removeVideoToTemp(bFile); }else{ BFile newVideo = this.uploadVideo(file, bFile);//上传文件 if (bFile.getType().equals("0")){ fileUrl = newVideo.getVideoUrl(); }else if(bFile.getType().equals("1")){ fileUrl = newVideo.getFileUrl(); }else if(bFile.getType().equals("2")){ fileUrl = newVideo.getPptUrl(); }else{ fileUrl = newVideo.getPdfUrl(); } } return fileUrl; }*/ }
\ No newline at end of file
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment