Commit 52441469 authored by root's avatar root

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

parents d61e4eb1 448f77e7
......@@ -16,6 +16,7 @@ import org.rcisoft.business.bchapter.dto.ScoreInfoDTO;
import org.rcisoft.business.bchapter.entity.BChapter;
import org.rcisoft.business.bchapter.enums.IsCompleteEnum;
import org.rcisoft.business.bchapter.service.BChapterService;
import org.rcisoft.business.bfile.dto.uploadDTO;
import org.rcisoft.business.bfile.entity.BFile;
import org.rcisoft.common.component.Global;
import org.rcisoft.common.controller.PaginationController;
......@@ -72,8 +73,8 @@ public class BChapterController extends PaginationController<BChapter> {
@ApiImplicitParam(name = "chapterLevel", value = "等级,1:章 2:节", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "isTest", value = "课件类型(单选) 1视频 2音频 3PPT 4pdf 5资料", required = true, dataType = "varchar")})
@PostMapping(value = "/add")
public Result add(CurUser curUser, @Valid BChapter bChapter, BindingResult bindingResult) {
PersistModel data = bChapterService.persist(bChapter,curUser.getCorpId());
public Result add(CurUser curUser, @Valid BChapter bChapter, BindingResult bindingResult, uploadDTO dto) {
PersistModel data = bChapterService.persist(bChapter,curUser.getCorpId(),dto);
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
......
......@@ -4,6 +4,7 @@ package org.rcisoft.business.bchapter.service;
import org.rcisoft.business.bchapter.dto.*;
import org.rcisoft.business.bchapter.entity.BChapter;
import org.rcisoft.business.bchapter.vo.StudentChapterScoreVO;
import org.rcisoft.business.bfile.dto.uploadDTO;
import org.rcisoft.business.bfile.entity.BFile;
import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.core.model.PersistModel;
......@@ -56,7 +57,7 @@ public interface BChapterService{
* @param model
* @return
*/
PersistModel persist(BChapter model, String corpId);
PersistModel persist(BChapter model, String corpId, uploadDTO dto);
/**
* 修改
......
......@@ -11,6 +11,7 @@ import org.rcisoft.business.bchapter.enums.HasMarkEnum;
import org.rcisoft.business.bchapter.enums.StateEnum;
import org.rcisoft.business.bchapter.service.BChapterService;
import org.rcisoft.business.bchapter.vo.StudentChapterScoreVO;
import org.rcisoft.business.bfile.dto.uploadDTO;
import org.rcisoft.business.bfile.util.GetVideoTime;
import org.rcisoft.business.blesson.dao.BLessonRepository;
import org.rcisoft.business.blesson.entity.BLesson;
......@@ -71,8 +72,8 @@ public class BChapterServiceImpl implements BChapterService {
}
@Override
public List<QueryChapterListResDTO> queryBChaptersByPagination(PageUtil pageUtil, QueryChapterListDTO model,String corpId) {
return queryChapterListResDTO(model,corpId);
public List<QueryChapterListResDTO> queryBChaptersByPagination(PageUtil pageUtil, QueryChapterListDTO model, String corpId) {
return queryChapterListResDTO(model, corpId);
}
@Override
......@@ -81,23 +82,24 @@ public class BChapterServiceImpl implements BChapterService {
}
@Override
public List<QueryChapterListResDTO> queryBChapters(QueryChapterListDTO model,String corpId) {
return queryChapterListResDTO(model,corpId);
public List<QueryChapterListResDTO> queryBChapters(QueryChapterListDTO model, String corpId) {
return queryChapterListResDTO(model, corpId);
}
@Override
public Map queryBChaptersWithProgress(QueryChapterListDTO model,String corpId) {
List<QueryChapterListResDTO> queryChapterListResDTOS = queryChapterListResDTO(model,corpId);
public Map queryBChaptersWithProgress(QueryChapterListDTO model, String corpId) {
List<QueryChapterListResDTO> queryChapterListResDTOS = queryChapterListResDTO(model, corpId);
queryChapterListResDTOS.stream().forEach(queryChapterListResDTO -> {
queryChapterListResDTO.getChildList().stream().forEach(childList -> {
List<BRStudentChapter> brStudentChapterList = brStudentChapterRepository.queryByStuIdAndChapter(childList.getBusinessId(),model.getStudentId());
if (null != brStudentChapterList && brStudentChapterList.size()>0){
List<BRStudentChapter> brStudentChapterList = brStudentChapterRepository.queryByStuIdAndChapter(childList.getBusinessId(), model.getStudentId());
if (null != brStudentChapterList && brStudentChapterList.size() > 0) {
childList.setProgress(brStudentChapterList.get(0).getProgress());
}
});
});
Map map = new HashMap();
map.put("chapterList",queryChapterListResDTOS);
map.put("lessonInfo",bLessonRepository.selectByPrimaryKey(model.getLessonId()));
map.put("chapterList", queryChapterListResDTOS);
map.put("lessonInfo", bLessonRepository.selectByPrimaryKey(model.getLessonId()));
return map;
}
......@@ -107,20 +109,25 @@ public class BChapterServiceImpl implements BChapterService {
* @param model
* @return
*/
public List<QueryChapterListResDTO> queryChapterListResDTO(QueryChapterListDTO model,String corpId) {
public List<QueryChapterListResDTO> queryChapterListResDTO(QueryChapterListDTO model, String corpId) {
Map param = new HashMap<String, Object>();
if (model.getLessonId() != null && !"".equals(model.getLessonId())) {
param.put("lessonId", model.getLessonId());
}
param.put("corpId",corpId);
param.put("corpId", corpId);
return bChapterRepository.queryBChapters(param);
}
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
@Override
public PersistModel persist(BChapter model,String corpId) {
public PersistModel persist(BChapter model, String corpId, uploadDTO dto) {
int line = 0;
BFile bFile = new BFile();
bFile.setFileName(dto.getFileName());
bFile.setVideoUrl(dto.getVideoUrl());
bFile.setType(dto.getType());
if (model.getBusinessId() == null) {
UserUtil.setCurrentPersistOperation(model);
......@@ -139,8 +146,11 @@ public class BChapterServiceImpl implements BChapterService {
int sort = bChapterRepository.selectMaxSort(model.getPid(), model.getLessonId());
model.setSort(sort);
model.setCorpId(corpId);
bFile.setChapterId(model.getBusinessId());
bFile.setLessonId(model.getLessonId());
UserUtil.setCurrentPersistOperation(bFile);
line = bChapterRepository.insertSelective(model);
int x = bFileRepository.insertUploadFile(bFile);
bChapterRepository.updateClassHourInLesson(model.getLessonId());//更新b_lesson表中 class_hour
} else {
UserUtil.setCurrentMergeOperation(model);
......
......@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.IOUtils;
import org.rcisoft.business.bfile.dto.uploadDTO;
import org.rcisoft.business.bfile.entity.BFile;
import org.rcisoft.business.bfile.service.BFileService;
import org.rcisoft.common.component.Global;
......@@ -26,6 +27,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.List;
import java.util.Map;
/**
* Created by gaowenfneg on 2017-10-9 14:34:56.
......@@ -40,17 +42,15 @@ public class BFileController extends PaginationController<BFile> {
private Global global;
@ApiOperation(value="401 上传文件", notes="上传文件")
@ApiImplicitParam(name = "file", value = "视频文件", required = true, dataType = "MultipartFile")
@ApiImplicitParams({@ApiImplicitParam(name = "type", value = "0视频 1音频 2ppt 3pdf 4附件", required = true, dataType = "varchar"),
@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);
public Result uploadVideo(String type, MultipartFile file) {
uploadDTO data = bFileService.uploadVideoToServer(file, type);
return Result.builder(new PersistModel(1),
"上传成功",
MessageConstant.MESSAGE_ALERT_ERROR,
videoUrl);
data);
}
// /**
......
......@@ -51,5 +51,15 @@ public interface BFileRepository extends BaseMapper<BFile> {
@ResultMap(value = "BaseResultMap" )
BFile queryBVideoByChapterId(String chapterId);
/**
* 添加文件信息到file表
* @return
*/
@Insert("INSERT INTO `b_file` " +
"(business_id,lesson_id,chapter_id,file_name,video_url,file_url,type,flag,del_flag,remarks,create_by,update_by,update_date,create_date) " +
"VALUES (#{businessId}, #{lessonId}, #{chapterId}, #{fileName}, #{videoUrl}, #{fileUrl}, #{type}, #{flag}, #{delFlag}, #{remarks}, #{createBy}, #{updateBy}, #{updateDate}, #{createDate})")
int insertUploadFile(BFile bFile);
}
package org.rcisoft.business.bfile.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
@Data
public class uploadDTO {
@ApiModelProperty(value = "文件名称")
@Length(min = 1,max = 256,message = "长度最小为1,最大为200")
private String fileName;
@ApiModelProperty(value = "文件路径")
@Length(min = 1,max = 256,message = "长度最小为1,最大为200")
private String videoUrl;
@ApiModelProperty(value = "0视频 1音频 2ppt 3pdf 4附件")
private String type;
}
......@@ -25,7 +25,7 @@ public class BFile extends IdEntity<BFile> {
/*视频名称*/
@Length(min = 1,max = 256,message = "长度最小为1,最大为200")
@NotBlank
private String videoName;
private String fileName;
/*视频地址*/
@Length(min = 1,max = 256,message = "长度最小为1,最大为200")
......@@ -39,23 +39,10 @@ public class BFile extends IdEntity<BFile> {
@NotBlank
private String fileUrl;
@Length(min = 1,max = 256,message = "长度最小为1,最大为200")
@NotBlank
private String audioUrl;
@Length(min = 1,max = 256,message = "长度最小为1,最大为200")
@NotBlank
private String pptUrl;
@Length(min = 1,max = 256,message = "长度最小为1,最大为200")
@NotBlank
private String pdfUrl;
@Length(min = 1,max = 64,message = "长度最小为1,最大为50")
@NotBlank
private String lessonId;//课程ID
@Length(min = 1,max = 64,message = "长度最小为1,最大为50")
@NotBlank
private String chapterId;//节ID
......
package org.rcisoft.business.bfile.service;
import org.rcisoft.business.bfile.dto.uploadDTO;
import org.rcisoft.business.bfile.entity.BFile;
import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.core.model.PersistModel;
......@@ -7,6 +8,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
* Created by gaowenfneg on 2017-10-9 14:34:56.
......@@ -48,7 +50,7 @@ public interface BFileService {
*/
PersistModel removeBVideo(String id);
public String uploadVideoToServer(List<MultipartFile> list, BFile bFile);
public uploadDTO uploadVideoToServer(MultipartFile file, String type);
public BFile queryFileUrlByChapterId(String chapterId);
......
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
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.dto.uploadDTO;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 uploadDTO uploadVideoToServer(MultipartFile file, String type) { String videoUrl = ""; String fileName = file.getOriginalFilename(); uploadDTO dto = new uploadDTO(); try { if (type.equals("0")) { videoUrl = "https://s2.luckincoffeecdn.com/luckywebrm/images/index/luckincoffee_TVC30.mp4"; } else if (type.equals("1")) { videoUrl = "https://webfs.yun.kugou.com/201910101737/d56a90f4c0d75be840f66c7ed8e237ca/G171/M0B/18/10/i5QEAF2c0cKAJ63iADBEFy9sicA739.mp3"; } else if (type.equals("2")) { videoUrl = "http://f.hiphotos.baidu.com/image/pic/item/0e2442a7d933c8956c0e8eeadb1373f08202002a.jpg"; } else if (type.equals("3")) { videoUrl = "http://f.hiphotos.baidu.com/image/pic/item/0e2442a7d933c8956c0e8eeadb1373f08202002a.jpg"; } else { videoUrl = "http://f.hiphotos.baidu.com/image/pic/item/0e2442a7d933c8956c0e8eeadb1373f08202002a.jpg"; } dto.setFileName(fileName); dto.setVideoUrl(videoUrl); dto.setType(type); } catch (Exception e) { e.printStackTrace(); throw new ServiceException(ResultServiceEnums.UPLOAD_ERROR); } return dto; } /** * 将原视频复制到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); } } @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
......
......@@ -34,7 +34,7 @@ public class SysRoleController extends PaginationController<SysRole> {
private SysRoleService sysRoleServiceImpl;
@ApiOperation(value="1001 分页查询角色", notes="分页查询角色")
@ApiOperation(value="1001 分页查询所有角色", notes="分页查询所有角色")
@GetMapping(value = "/queryRoles")
public GridModel queryRolesByPagination(CurUser curUser, @Valid FindRolePaginDTO findRolePaginDTO, BindingResult bindingResult){
sysRoleServiceImpl.queryRolesByPagination(getPaginationUtility(), findRolePaginDTO);
......@@ -52,38 +52,16 @@ public class SysRoleController extends PaginationController<SysRole> {
}
@ApiOperation(value="1003 增加/修改角色", notes="增加/修改角色")
@PostMapping(value = "/add")
public Result roleAdd(CurUser curUser, @Valid AddOrUpdateRoleDTO addOrUpdateRoleDTO, BindingResult bindingResult){
int line = sysRoleServiceImpl.persistRole(addOrUpdateRoleDTO);
return Result.builder(new PersistModel(line),
@ApiOperation(value="1003 数据权限分配", notes="数据权限分配")
@ApiImplicitParams({@ApiImplicitParam(name = "businessId", value = "角色id", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "type", value = "0:仅可看自己 1:可看全部 2:查看指定", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "departIds", value = "部门id,逗号间隔", required = true, dataType = "varchar")})
@PostMapping(value = "/roleData")
public Result roleData(CurUser curUser,@Valid SysRole sysRole,BindingResult br){
return Result.builder(sysRoleServiceImpl.updateRoleData(sysRole),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
addOrUpdateRoleDTO);
}
@ApiOperation(value="1004 删除角色", notes="删除角色")
@ApiImplicitParam(name = "businessId", value = "businessId", required = true, dataType = "varchar", paramType = "path")
@PostMapping(value = "/delete")
public Result roleDelete(CurUser curUser, String businessId, BindingResult bindingResult){
int line = sysRoleServiceImpl.removeRole(businessId);
return Result.builder(new PersistModel(line),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
businessId);
}
@ApiOperation(value="权限分配", notes="权限分配")
@ApiImplicitParams({@ApiImplicitParam(name = "roleId", value = "businessId", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "menus", value = "菜单id,逗号间隔", required = true, dataType = "varchar")})
@PostMapping(value = "/rolePermission")
public Result rolePermission(@RequestParam("roleId") String roleId, @RequestParam("menus") String menus ){
return Result.builder(sysRoleServiceImpl.doAuthorization(roleId,menus),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
roleId);
sysRole);
}
}
......@@ -199,11 +199,6 @@ public interface SysRoleRepository extends BaseMapper<SysRole> {
@ResultMap(value = "BaseResultMap")
List<SysRole> queryRolesByName(SysRole sysRole);
// @Select("SELECT COUNT(*) FROM s_menu sm \n" +
// "LEFT JOIN s_role_menu rm ON sm.BUSINESS_ID = rm.MENU_ID\n" +
// "LEFT JOIN s_role sr ON rm.ROLE_ID = sr.business_id\n" +
// "WHERE sr.`code` = #{roleCode} AND sm.BUSINESS_ID = #{businessId}")
// int queryRoleByRoleCode(@Param("roleCode") String roleCode, @Param("businessId") String businessId);
@Select("SELECT count(*) FROM s_menu \n" +
"LEFT JOIN s_role_menu ON s_menu.BUSINESS_ID = s_role_menu.MENU_ID " +
......@@ -211,35 +206,6 @@ public interface SysRoleRepository extends BaseMapper<SysRole> {
"WHERE s_menu.MODEL_ID = #{modelId} AND ROLE_ID = #{roleId}")
int queryRoleByRoleCode(@Param("modelId") String modelId, @Param("roleId") String roleId);
/**
* 根据子表id 删除 s_r_user_role
*
* @param tableByKey
* @param businessId
* @return
*/
@Delete("DELETE\n" +
"FROM\n" +
"\ts_r_user_role\n" +
"WHERE\n" +
"\ts_r_user_role.business_id = (\n" +
"\t\tSELECT\n" +
"\t\t\tab.*\n" +
"\t\tFROM\n" +
"\t\t\t(\n" +
"\t\t\t\tSELECT\n" +
"\t\t\t\t\ts_r_user_role.business_id\n" +
"\t\t\t\tFROM\n" +
"\t\t\t\t\ts_r_user_role\n" +
"\t\t\t\tLEFT JOIN s_user ON s_r_user_role.user_id = s_user.business_id\n" +
"\t\t\t\tLEFT JOIN ${tb} ON ${tb}.`code` = s_user.login_name\n" +
"\t\t\t\tWHERE\n" +
"\t\t\t\t\t${tb}.business_id = #{cid}\n" +
"\t\t\t) ab\n" +
"\t)")
int deleteUserRoleByChildrenId(@Param("tb") String tableByKey, @Param("cid") String businessId);
@Select("<script>select count(1) " +
"from tm_admin_role " +
"where corp_id = #{corpId} " +
......@@ -263,4 +229,7 @@ public interface SysRoleRepository extends BaseMapper<SysRole> {
"values(#{businessId},#{userId},#{roleId}) " +
"</script>")
int addUserRole(UserRoleDTO param);
@Update("update tm_admin_role set type = #{type} , depart_ids = #{departIds} where r_id = #{businessId}")
int updateRoleData(SysRole sysRole);
}
......@@ -14,7 +14,7 @@ import javax.validation.constraints.NotBlank;
* Created by gaowenfeng on 2017/8/9.
*/
@Data
@Table(name = "s_role")
@Table(name = "tm_admin_role")
@NoArgsConstructor
@AllArgsConstructor
public class SysRole extends IdEntity<SysRole> {
......@@ -22,9 +22,10 @@ public class SysRole extends IdEntity<SysRole> {
@Length(min = 1,max = 64,message = "长度最小为1,最大为50")
@NotBlank
private String roleName;
@Length(min = 1,max = 64,message = "长度最小为1,最大为50")
@NotBlank
private String businessId;
private String type;
private String departIds;
@Transient
private int userNum;
......
......@@ -22,6 +22,8 @@ public interface SysRoleService {
*/
int persistRole(AddOrUpdateRoleDTO addOrUpdateRoleDTO);
PersistModel updateRoleData(SysRole sysRole);
/**
* 删除
......
......@@ -64,6 +64,12 @@ public class SysRoleServiceImpl implements SysRoleService {
return line;
}
@Override
public PersistModel updateRoleData(SysRole sysRole) {
int line = sysRoleRepository.updateRoleData(sysRole);
return new PersistModel(line);
}
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
@Override
......
......@@ -50,6 +50,9 @@ public class SysUser extends IdEntity<SysUser> {
private String gitLabUsername; //gitLab账号
private String gitLabImpressionToken; //gitLab账号模拟令牌
private String depart;
private String position;
/**
* 角色ID
*/
......
......@@ -54,7 +54,13 @@ public class SysUserServiceImpl implements SysUserService {
@Override
public List<SysUser> queryUsersByPagination(PageUtil pageUtil, QuerySysUserDTO dto) {
return sysUserMapper.queryUsers(dto);
List<SysUser> users = sysUserMapper.queryUsers(dto);
List<String> list = new ArrayList<>();
for(SysUser user:users){
list.add(user.getBusinessId());
}
return users;
}
@Override
......
......@@ -10,12 +10,9 @@
<result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
<result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
<result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
<result column="video_name" jdbcType="VARCHAR" property="videoName"/>
<result column="file_name" jdbcType="VARCHAR" property="fileName"/>
<result column="video_url" jdbcType="VARCHAR" property="videoUrl"/>
<result column="audio_url" jdbcType="VARCHAR" property="audioUrl"/>
<result column="file_url" jdbcType="VARCHAR" property="fileUrl"/>
<result column="ppt_url" jdbcType="VARCHAR" property="pptUrl"/>
<result column="pdf_url" jdbcType="VARCHAR" property="pdfUrl"/>
<result column="type" jdbcType="VARCHAR" property="type"/>
<result column="chapter_id" jdbcType="VARCHAR" property="chapterId"/>
<result column="lesson_id" jdbcType="VARCHAR" property="lessonId"/>
......
......@@ -2,7 +2,6 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.rcisoft.sys.role.dao.SysRoleRepository">
<resultMap id="BaseResultMap" type="org.rcisoft.sys.role.entity.SysRole">
<id column="business_id" jdbcType="VARCHAR" property="businessId" />
<result column="role_name" jdbcType="VARCHAR" property="roleName" />
<result column="CODE" jdbcType="VARCHAR" property="code" />
<result column="checked" jdbcType="VARCHAR" property="checked" />
......
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