Commit 4b98f49b authored by YangZhaoJun1's avatar YangZhaoJun1

完善接口

parent 1836d5d1
......@@ -66,12 +66,12 @@ public class BChapterController extends PaginationController<BChapter> {
@ApiImplicitParams({@ApiImplicitParam(name = "businessId", value = "businessId", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "slId", value = "开课id", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "chapterName", value = "章节名称", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "pid", value = "上一级", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "pid", value = "上一级", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "classHour", value = "课时", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "isTest", value = "1:实验 2:视频 3:PPT'", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "lessonOrSl", value = "课程或开课;0:开课 1:课程", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "lessonId", value = "课程ID(课程ID和开课ID只能存在一个)", required = false, dataType = "varchar")})
@PreAuthorize("hasAnyRole('ROLE_1002','ROLE_1002')")
@PreAuthorize("hasAnyRole('ROLE_1001','ROLE_1002')")
@PostMapping(value = "/add")
public Result add(@Valid BChapter bChapter,
BindingResult bindingResult
......@@ -91,7 +91,7 @@ public class BChapterController extends PaginationController<BChapter> {
@ApiOperation(value="删除章节", notes="根据ID删除一条记录")
@ApiImplicitParam(name = "id", value = "businessId", required = true, dataType = "varchar")
@PreAuthorize("hasRole('ROLE_1002')")
@PreAuthorize("hasAnyRole('ROLE_1001','ROLE_1002')")
@PostMapping(value = "/remove")
public Result remove(String id) {
PersistModel data = bChapterService.removeBChapter(id,getToken());
......
......@@ -46,13 +46,14 @@ public interface BChapterRepository extends BaseMapper<BChapter> {
*/
@Select("<script>SELECT\n" +
" bc.*,\n" +
" (SELECT bv.video_url FROM b_video bv WHERE bv.business_id = bcv1.video_id) AS videoUrl,\n" +
" (SELECT bv.video_url FROM b_video bv WHERE bv.business_id = bcv2.video_id) AS fileUrl,\n" +
" bf.video_url AS videoUrl,\n" +
" bf.file_url AS fileUrl,\n" +
" bf.ppt_url AS pptUrl,\n" +
" bf.pdf_url AS pdfUrl,\n" +
" (SELECT count(*) FROM b_r_student_chapter brs WHERE brs.chapter_id = bc.business_id AND brs.score = - 1) AS studentNum \n" +
" FROM\n" +
" b_chapter bc\n" +
" LEFT JOIN b_r_chapter_video bcv1 ON bcv1.chapter_id = bc.business_id and bcv1.type = '0'\n" +
" LEFT JOIN b_r_chapter_video bcv2 ON bcv2.chapter_id = bc.business_id and bcv2.type = '1'\n" +
" LEFT JOIN b_file bf ON bf.chapter_id = bc.business_id " +
" \n" +
" WHERE\n" +
" bc.del_flag = 0\n" +
......
......@@ -71,10 +71,23 @@ public class BChapter extends IdEntity<BChapter> {
@Transient
private String videoUrl;
@Transient
private String fileUrl;
@Transient
private String pptUrl;
@Transient
private String pdfUrl;
/**
* 课程的父ID(当作map的key存放开课的父ID用)
*/
@Transient
private String lPid;
@Transient
private String sPid;
......
package org.rcisoft.business.bchapter.service.impl;
import com.sun.org.apache.xerces.internal.xs.datatypes.ObjectList;
import org.apache.commons.io.FileUtils;
import org.rcisoft.business.bchapter.dao.BChapterRepository;
import org.rcisoft.business.bchapter.dto.QueryScoreListDTO;
import org.rcisoft.business.bchapter.dto.ScoreInfoDTO;
......@@ -17,9 +17,8 @@ import org.rcisoft.business.brslstudent.dao.BRSlStudentRepository;
import org.rcisoft.business.bsl.dao.BSlRepository;
import org.rcisoft.business.bsl.enums.AuditStatusEnum;
import org.rcisoft.business.bstudent.dao.BStudentRepository;
import org.rcisoft.business.bvideo.dao.BVideoRepository;
import org.rcisoft.business.bvideo.entity.BVideo;
import org.rcisoft.business.bvideo.entity.UrlDto;
import org.rcisoft.business.bfile.dao.BFileRepository;
import org.rcisoft.business.bfile.entity.BFile;
import org.rcisoft.common.component.Global;
import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.core.exception.ServiceException;
......@@ -55,7 +54,7 @@ public class BChapterServiceImpl implements BChapterService {
@Autowired
private BLessonRepository bLessonRepository;
@Autowired
private BVideoRepository bVideoRepository;
private BFileRepository bFileRepository;
@Autowired
private Global global;
......@@ -204,7 +203,7 @@ public class BChapterServiceImpl implements BChapterService {
//获取课程的章节列表
List<BChapter> lessonList = bChapterRepository.queryChapterByLessonId(bLessonId);
List<BChapter> chapterList = new ArrayList<>();
//map存放章的ID(key:章名称 value:新的章ID)
//map存放章的ID(key:老的章id value:新的章ID)
Map map = new HashMap();
for (int i=0;i<lessonList.size();i++){
BChapter sl_chapter = new BChapter();
......@@ -221,20 +220,27 @@ public class BChapterServiceImpl implements BChapterService {
UserUtil.setCurrentPersistOperation(sl_chapter);
if(lessonList.get(i).getPid().equals("-1")){
sl_chapter.setPid(lessonList.get(i).getPid());
map.put(sl_chapter.getChapterName(),sl_chapter.getBusinessId());
map.put(lessonList.get(i).getBusinessId(),sl_chapter.getBusinessId());
}else{
sl_chapter.setPid("0");
sl_chapter.setLPid(lessonList.get(i).getPid());
}
//set老的章节ID后面比对用
lessonList.get(i).setSPid(lessonList.get(i).getBusinessId());
sl_chapter.setSPid(lessonList.get(i).getBusinessId());
chapterList.add(sl_chapter);
}
for (int i=0;i<chapterList.size();i++){
if(!chapterList.get(i).getPid().equals("-1")){
//根据父ID获取父节点章节名称
String chapterName = bChapterRepository.selectChapterNameByPid(lessonList.get(i).getPid());
//取出map中存放的新的章ID作为父节点ID
chapterList.get(i).setPid(String.valueOf(map.get(chapterName)));
chapterList.get(i).setPid(String.valueOf(map.get(chapterList.get(i).getLPid())));
}
}
if(chapterList.size()>0){
result = bChapterRepository.insertChapterList(chapterList);
}
String oldPath = global.getBASE_UPLOAD_SERVER_LOCATION()+File.separator
+global.getCOURSE_LOCATION()+File.separator
+global.getLESSON_LOCATION()+File.separator
......@@ -243,9 +249,58 @@ public class BChapterServiceImpl implements BChapterService {
+global.getCOURSE_LOCATION()+File.separator
+global.getSL_LOCATION()+File.separator
+slId;
//复制章节的所有文件
try {
//copyFileToSl(oldPath,newPath,bLessonId,slId);
if(chapterList.size()>0){
result = bChapterRepository.insertChapterList(chapterList);
File oldFile = new File(oldPath);
File newFile = new File(newPath);
FileUtils.copyDirectory(oldFile,newFile,true);
} catch (IOException e) {
e.printStackTrace();
}
//数据库操作
for (BChapter leBChapter : lessonList){
for(BChapter slChapter : chapterList){
if(leBChapter.getSPid().equals(slChapter.getSPid())&&!leBChapter.getPid().equals("-1")){
BFile bFile = bFileRepository.queryBVideoByChapterId(leBChapter.getBusinessId());
BFile newVideo = new BFile();
newVideo.setChapterId(slChapter.getBusinessId());
newVideo.setVideoName(bFile.getVideoName());
UserUtil.setCurrentPersistOperation(newVideo);
//将节的ID替换成新的
if(bFile !=null){
if(bFile.getVideoUrl()!=null&&!bFile.getVideoUrl().equals("")){
String newUrl = bFile.getVideoUrl().replace(bLessonId,slId);
String path = newUrl.replace(leBChapter.getBusinessId(),slChapter.getBusinessId());
newVideo.setVideoUrl(path);
}
if(bFile.getFileUrl()!=null&&!bFile.getFileUrl().equals("")){
String newUrl = bFile.getVideoUrl().replace(bLessonId,slId);
String path = newUrl.replace(leBChapter.getBusinessId(),slChapter.getBusinessId());
newVideo.setFileUrl(path);
}
if(bFile.getPptUrl()!=null&&!bFile.getPptUrl().equals("")){
String newUrl = bFile.getVideoUrl().replace(bLessonId,slId);
String path = newUrl.replace(leBChapter.getBusinessId(),slChapter.getBusinessId());
newVideo.setPptUrl(path);
}
if(bFile.getPdfUrl()!=null&&!bFile.getPdfUrl().equals("")){
String newUrl = bFile.getVideoUrl().replace(bLessonId,slId);
String path = newUrl.replace(leBChapter.getBusinessId(),slChapter.getBusinessId());
newVideo.setPdfUrl(path);
}
//重命名复制之后的文件
String filePath = newPath + File.separator + leBChapter.getBusinessId();
String newFilePath = newPath + File.separator + slChapter.getBusinessId();
File file = new File(filePath);
file.renameTo(new File(newFilePath));
//插入对象
bFileRepository.insertSelective(newVideo);
}
}
}
}
return result;
}
......@@ -255,9 +310,8 @@ public class BChapterServiceImpl implements BChapterService {
* @param oldPath
* @param newPath
*/
private void copyFileToSl(String oldPath, String newPath, String bLessonId, String slId) {
private void copyFileToSl(String oldPath, String newPath, String bLessonId, String slId) throws IOException {
UrlDto urlDto = new UrlDto();
File oldFile = new File(oldPath);
File[] fs=oldFile.listFiles();
File newFile=new File(newPath);
......@@ -271,40 +325,6 @@ public class BChapterServiceImpl implements BChapterService {
copyFileToSl(f.getPath(),newPath+File.separator+f.getName(), bLessonId, slId);
}
}
List<BChapter> leChapters = bChapterRepository.queryChapterByLessonId(bLessonId);
List<BChapter> slChapters = bChapterRepository.queryChapterBySlId(slId);
for (BChapter leBChapter : leChapters){
for(BChapter slChapter : slChapters){
if(leBChapter.getChapterName().equals(slChapter.getChapterName())){
BVideo bVideo = bVideoRepository.queryBVideoByChapterId(leBChapter.getBusinessId());
BVideo newVideo = new BVideo();
newVideo.setBusinessId(bVideo.getBusinessId());
if(bVideo!=null){
if(bVideo.getVideoUrl()!=null&&!bVideo.getVideoUrl().equals("")){
String newUrl = bVideo.getVideoUrl().replace(bLessonId,slId);
String path = newUrl.replace(leBChapter.getBusinessId(),slChapter.getBusinessId());
newVideo.setVideoUrl(path);
}
if(bVideo.getFileUrl()!=null&&!bVideo.getFileUrl().equals("")){
String newUrl = bVideo.getVideoUrl().replace(bLessonId,slId);
String path = newUrl.replace(leBChapter.getBusinessId(),slChapter.getBusinessId());
newVideo.setFileUrl(path);
}
if(bVideo.getPptUrl()!=null&&!bVideo.getPptUrl().equals("")){
String newUrl = bVideo.getVideoUrl().replace(bLessonId,slId);
String path = newUrl.replace(leBChapter.getBusinessId(),slChapter.getBusinessId());
newVideo.setPptUrl(path);
}
if(bVideo.getPdfUrl()!=null&&!bVideo.getPdfUrl().equals("")){
String newUrl = bVideo.getVideoUrl().replace(bLessonId,slId);
String path = newUrl.replace(leBChapter.getBusinessId(),slChapter.getBusinessId());
newVideo.setPdfUrl(path);
}
bVideoRepository.updateByPrimaryKeySelective(newVideo);
}
}
}
}
}
private void fileCopy(String oldPath, String newPath) {
......@@ -330,7 +350,7 @@ public class BChapterServiceImpl implements BChapterService {
e.printStackTrace();
}
}
}
}
@Transactional(propagation = Propagation.REQUIRED,readOnly = false)
@Override
......
package org.rcisoft.business.bvideo.controller;
package org.rcisoft.business.bfile.controller;
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.bvideo.entity.BVideo;
import org.rcisoft.business.bvideo.service.BVideoService;
import org.rcisoft.business.bfile.entity.BFile;
import org.rcisoft.business.bfile.service.BFileService;
import org.rcisoft.common.component.Global;
import org.rcisoft.common.controller.PaginationController;
import org.rcisoft.common.model.GridModel;
import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.result.Result;
import org.rcisoft.core.result.ResultCode;
import org.rcisoft.core.util.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
......@@ -31,9 +29,9 @@ import java.util.List;
*/
@RestController
@RequestMapping("/BVideo")
public class BVideoController extends PaginationController<BVideo> {
public class BFileController extends PaginationController<BFile> {
@Autowired
private BVideoService bVideoService;
private BFileService bFileService;
@Autowired
private Global global;
......@@ -46,12 +44,12 @@ public class BVideoController extends PaginationController<BVideo> {
@ApiImplicitParam(name = "remarks", value = "备注", required = false, dataType = "varchar")})
@PreAuthorize("hasRole('ROLE_1002')")
@PostMapping(value = "/add")
public Result add(BVideo bVideo) {
PersistModel data = bVideoService.persist(bVideo,getToken());
public Result add(BFile bFile) {
PersistModel data = bFileService.persist(bFile,getToken());
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
bVideo);
bFile);
}
@ApiOperation(value="逻辑删除", notes="根据ID删除一条记录")
......@@ -59,7 +57,7 @@ public class BVideoController extends PaginationController<BVideo> {
@PreAuthorize("hasRole('ROLE_1001')")
@PostMapping(value = "/remove")
public Result remove(String id) {
PersistModel data = bVideoService.removeBVideo(id,getToken());
PersistModel data = bFileService.removeBVideo(id,getToken());
return Result.builder(data,
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
......@@ -73,7 +71,7 @@ public class BVideoController extends PaginationController<BVideo> {
return Result.builder(new PersistModel(1),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
bVideoService.selectOne(businessId));
bFileService.selectOne(businessId));
}
......@@ -84,9 +82,9 @@ public class BVideoController extends PaginationController<BVideo> {
@ApiImplicitParam(name = "type", value = "'0'为视频,'1'为附件", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "remarks", value = "备注", required = false, dataType = "varchar")})
@GetMapping(value = "/queryBVideosByPagination")
public GridModel queryBVideosByPagination(BVideo param) {
public GridModel queryBVideosByPagination(BFile param) {
param.setCreateBy(UserUtil.getUserInfoProp(getToken(),UserUtil.USER_ID));
bVideoService.queryBVideosByPagination(getPaginationUtility(),param);
bFileService.queryBVideosByPagination(getPaginationUtility(),param);
GridModel gridModel = getGridModelResponse();
return gridModel;
}
......@@ -98,12 +96,12 @@ public class BVideoController extends PaginationController<BVideo> {
@ApiImplicitParam(name = "type", value = "'0'为视频,'1'为附件", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "remarks", value = "备注", required = false, dataType = "varchar")})
@GetMapping(value = "/queryBVideos")
public Result queryBVideos(BVideo param) {
public Result queryBVideos(BFile param) {
param.setCreateBy(UserUtil.getUserInfoProp(getToken(),UserUtil.USER_ID));
return Result.builder(new PersistModel(1),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
bVideoService.queryBVideos(param));
bFileService.queryBVideos(param));
}
......@@ -111,30 +109,14 @@ public class BVideoController extends PaginationController<BVideo> {
@ApiImplicitParams({@ApiImplicitParam(name = "businessId", value = "businessId", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "videoName", value = "视频名称", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "videoUrl", value = "视频地址", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "type", value = "'0'为视频,'1'为附件", required = false, dataType = "varchar"),
@ApiImplicitParam(name = "type", value = "'0'为视频,'1'为附件,'2'为ppt,'3'为pdf", required = true, dataType = "varchar"),
@ApiImplicitParam(name = "file", value = "视频文件", required = true, dataType = "MultipartFile")})
@PreAuthorize("hasRole('ROLE_1002')")
@PostMapping(value = "/uploadVideo")
public Result uploadVideo(BVideo bVideo, HttpServletRequest request) {
Result result = new Result();
public Result uploadVideo(BFile bFile, HttpServletRequest request) {
List<MultipartFile> list = ((MultipartHttpServletRequest)request).getFiles("file");
try{
String pathName;
if (bVideo.getType().equals("0")){
pathName = global.getVIDEO_LOCATION();//视频路径
}else{
pathName = global.getFILE_LOCATION();//文件路径
}
String path= global.getBASE_UPLOAD_SERVER_LOCATION()
+ pathName
+ File.separator + bVideo.getLessonId() + File.separator;//根据开课ID区分文件
File outFile=new File(path);
if(!outFile.exists()){//判断保存路径是否存在,不存在新建
outFile.mkdirs();
}
String videoUrl = bVideoService.uploadVideoToServer(list,bVideo,path,getToken());
String videoUrl = bFileService.uploadVideoToServer(list, bFile,getToken());
return Result.builder(new PersistModel(1),
"上传成功",
MessageConstant.MESSAGE_ALERT_ERROR,
......@@ -161,7 +143,7 @@ public class BVideoController extends PaginationController<BVideo> {
@ApiImplicitParam(name = "chapterId", value = "章节ID", required = true, dataType = "varchar")
@PostMapping(value = "/downloadFile")
public Result downloadFile(String chapterId, HttpServletResponse response){
BVideo video = bVideoService.queryFileUrlByChapterId(chapterId);
BFile video = bFileService.queryFileUrlByChapterId(chapterId);
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
if(video.getVideoUrl()!=""&&video.getVideoUrl()!=null){
......
package org.rcisoft.business.bfile.dao;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.rcisoft.business.bfile.entity.BFile;
import org.rcisoft.core.base.BaseMapper;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Map;
/**
* Created with gaowenfneg on 2017-10-9 14:34:56.
*/
@Repository
public interface BFileRepository extends BaseMapper<BFile> {
/**
* 根据条件查找
* @param param
* @return
*/
@Select("<script>select * from b_file</script>")
@ResultMap(value = "BaseResultMap" )
List<BFile> queryBVideos(Map<String, Object> param);
@Select("<script>SELECT * from b_file " +
"where chapter_id = #{chapterId} </script>")
@ResultMap(value = "BaseResultMap" )
BFile selectInfoByChapterId(String chapterId);
@Select("<script>SELECT * FROM b_file WHERE chapter_id = #{chapterId}</script>")
@ResultMap(value = "BaseResultMap" )
BFile queryFileUrlByChapterId(String chapterId);
@Select("<script>SELECT * FROM b_file WHERE chapter_id = #{chapterId}</script>")
@ResultMap(value = "BaseResultMap" )
BFile queryBVideoByChapterId(String chapterId);
}
package org.rcisoft.business.bvideo.entity;
package org.rcisoft.business.bfile.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
......@@ -13,11 +13,11 @@ import javax.persistence.Transient;
* Created with gaowenfneg on 2017-10-9 14:34:56.
*/
@Entity
@Table(name = "b_video")
@Table(name = "b_file")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BVideo extends IdEntity<BVideo> {
public class BFile extends IdEntity<BFile> {
private static final long serialVersionUID = 5501554322621964535L;
/*视频名称*/
......@@ -35,10 +35,10 @@ public class BVideo extends IdEntity<BVideo> {
private String pdfUrl;
@Transient
private String lessonId;//开课ID
private String lessonId;//课程ID
private String slId;//开课ID
@Transient
private String chapterId;//节ID
}
package org.rcisoft.business.bvideo.service;
package org.rcisoft.business.bfile.service;
import org.rcisoft.business.bvideo.entity.BVideo;
import org.rcisoft.business.bfile.entity.BFile;
import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.core.model.PersistModel;
import org.springframework.web.multipart.MultipartFile;
......@@ -10,13 +10,13 @@ import java.util.List;
/**
* Created by gaowenfneg on 2017-10-9 14:34:56.
*/
public interface BVideoService{
public interface BFileService {
/**
* 根据主键唯一查找
* @param businessId
* @return
*/
BVideo selectOne(String businessId);
BFile selectOne(String businessId);
/**
* 根据条件分页查找
......@@ -24,21 +24,21 @@ public interface BVideoService{
* @param model
* @return
*/
List<BVideo> queryBVideosByPagination(PageUtil pageUtil, BVideo model);
List<BFile> queryBVideosByPagination(PageUtil pageUtil, BFile model);
/**
* 根据条件查找全部
* @param model
* @return
*/
List<BVideo> queryBVideos(BVideo model);
List<BFile> queryBVideos(BFile model);
/**
* 插入
* @param model
* @return
*/
PersistModel persist(BVideo model,String token);
PersistModel persist(BFile model, String token);
/**
* 逻辑删除
......@@ -47,7 +47,7 @@ public interface BVideoService{
*/
PersistModel removeBVideo(String id, String token);
public String uploadVideoToServer(List<MultipartFile> list, BVideo bVideo, String path,String token);
public String uploadVideoToServer(List<MultipartFile> list, BFile bFile, String token);
public BVideo queryFileUrlByChapterId(String chapterId);
public BFile queryFileUrlByChapterId(String chapterId);
}
package org.rcisoft.business.bvideo.service.impl;
package org.rcisoft.business.bfile.service.impl;
import org.rcisoft.business.bvideo.dao.BVideoRepository;
import org.rcisoft.business.bvideo.entity.BVideo;
import org.rcisoft.business.bvideo.service.BVideoService;
import org.rcisoft.business.bfile.dao.BFileRepository;
import org.rcisoft.business.bfile.entity.BFile;
import org.rcisoft.business.bfile.service.BFileService;
import org.rcisoft.common.component.Global;
import org.rcisoft.core.aop.PageUtil;
import org.rcisoft.core.constant.DelStatus;
......@@ -26,49 +26,48 @@ import java.util.Map;
*/
@Service
@Transactional(readOnly = true,propagation = Propagation.NOT_SUPPORTED)
public class BVideoServiceImpl implements BVideoService {
public class BFileServiceImpl implements BFileService {
@Autowired
private BVideoRepository bVideoRepository;
private BFileRepository bFileRepository;
@Autowired
private Global global;
@Override
public BVideo selectOne(String businessId){
return bVideoRepository.selectByPrimaryKey(businessId);
public BFile selectOne(String businessId){
return bFileRepository.selectByPrimaryKey(businessId);
}
@Override
public List<BVideo> queryBVideosByPagination(PageUtil pageUtil, BVideo model) {
public List<BFile> queryBVideosByPagination(PageUtil pageUtil, BFile model) {
Map param = new HashMap<String,Object>();
return bVideoRepository.queryBVideos(param);
return bFileRepository.queryBVideos(param);
}
@Override
public List<BVideo> queryBVideos(BVideo model) {
public List<BFile> queryBVideos(BFile model) {
Map param = new HashMap<String,Object>();
return bVideoRepository.queryBVideos(param);
return bFileRepository.queryBVideos(param);
}
@Override
public PersistModel persist(BVideo model, String token){
public PersistModel persist(BFile model, String token){
UserUtil.setCurrentPersistOperation(model);
int line = bVideoRepository.insertSelective(model);
bVideoRepository.insertChapterVideo(model);
int line = bFileRepository.insertSelective(model);
return new PersistModel(line);
}
@Override
public PersistModel removeBVideo(String id, String token) {
BVideo bVideo = bVideoRepository.selectByPrimaryKey(id);
bVideo.setDelFlag(DelStatus.DELETED.getStatus());
UserUtil.setCurrentMergeOperation(bVideo);
int line = bVideoRepository.updateByPrimaryKeySelective(bVideo);
BFile bFile = bFileRepository.selectByPrimaryKey(id);
bFile.setDelFlag(DelStatus.DELETED.getStatus());
UserUtil.setCurrentMergeOperation(bFile);
int line = bFileRepository.updateByPrimaryKeySelective(bFile);
return new PersistModel(line);
}
@Override
public String uploadVideoToServer(List<MultipartFile> list, BVideo bVideo, String path, String token) {
public String uploadVideoToServer(List<MultipartFile> list, BFile bFile, String token) {
String videoUrl = "";
......@@ -77,20 +76,37 @@ public class BVideoServiceImpl implements BVideoService {
MultipartFile file = list.get(i);
try {
//查询此节是否已有视频或文件
BVideo video = bVideoRepository.selectInfoByChapterId(bVideo.getChapterId(),bVideo.getType());
BFile video = bFileRepository.selectInfoByChapterId(bFile.getChapterId());
if (video!=null){//此节已有视频或文件,将已有的视频或文件放置到temp目录下,然后上传新视频或文件
String oldPath = global.getBASE_UPLOAD_SERVER_LOCATION() + video.getVideoUrl();
this.removeVideoToTemp(oldPath,video.getVideoName(),video.getType());//复制之前视频到temp/video文件下
BVideo newVideo = this.uploadVideo(file,bVideo,path);//上传新视频
if(bFile.getType().equals("0")&&video.getVideoUrl()!=null&&!video.getVideoUrl().equals("")){
this.removeVideoToTemp(video.getVideoUrl(),bFile);//复制之前视频到temp文件下
}
if(bFile.getType().equals("1")&&video.getFileUrl()!=null&&!video.getFileUrl().equals("")){
this.removeVideoToTemp(video.getFileUrl(),bFile);//复制之前文件到temp文件下
}
if(bFile.getType().equals("2")&&video.getPptUrl()!=null&&!video.getPptUrl().equals("")){
this.removeVideoToTemp(video.getPptUrl(),bFile);//复制之前ppt到temp文件下
}
if(bFile.getType().equals("3")&&video.getPdfUrl()!=null&&!video.getPdfUrl().equals("")){
this.removeVideoToTemp(video.getPdfUrl(),bFile);//复制之前pdf到temp文件下
}
BFile newVideo = this.uploadVideo(file, bFile);//上传新文件
newVideo.setBusinessId(video.getBusinessId());
UserUtil.setCurrentMergeOperation(newVideo);
bVideoRepository.updateByPrimaryKeySelective(newVideo);//更新表中信息
bFileRepository.updateByPrimaryKeySelective(newVideo);//更新表中信息
if (bFile.getType().equals("0")){
videoUrl = newVideo.getVideoUrl();
}else if(bFile.getType().equals("1")){
videoUrl = newVideo.getFileUrl();
}else if(bFile.getType().equals("2")){
videoUrl = newVideo.getPptUrl();
}else{
BVideo newVideo = this.uploadVideo(file,bVideo,path);//上传新视频
videoUrl = newVideo.getPdfUrl();
}
}else{
BFile newVideo = this.uploadVideo(file, bFile);//上传文件
this.persist(newVideo,token);//插入表信息
videoUrl = newVideo.getVideoUrl();
}
......@@ -108,20 +124,36 @@ public class BVideoServiceImpl implements BVideoService {
/**
* 将原视频复制到temp/video文件下,并删除原视频
* @param oldPath
* @param videoName
* @param url
* @param bFile
*/
private void removeVideoToTemp(String oldPath, String videoName, String type) {
private void removeVideoToTemp(String url, BFile bFile) {
String path;
String pathName;
if (type=="0"){
pathName = global.getVIDEO_LOCATION();//视频路径
if(bFile.getLessonId()!=null&&!bFile.getLessonId().equals("")){
path = global.getLESSON_LOCATION() + File.separator + bFile.getLessonId() + File.separator;
}else{
path = global.getSL_LOCATION() + File.separator + bFile.getSlId() + File.separator;
}
if (bFile.getType().equals("0")){
pathName = global.getVIDEO_LOCATION();//视频路径
}else if(bFile.getType().equals("1")){
pathName = global.getFILE_LOCATION();//文件路径
}else if(bFile.getType().equals("2")){
pathName = global.getPPT_LOCATION();//ppt路径
}else{
pathName = global.getPDF_LOCATION();//pdf路径
}
String tempPath = global.getBASE_UPLOAD_SERVER_LOCATION()
+ global.getTEMP_LOCATION()
+ pathName;
String oldPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator
+ global.getCOURSE_LOCATION() + File.separator
+ path.substring(0,path.indexOf(File.separator))
+ url;
String tempPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator
+ global.getCOURSE_LOCATION() + File.separator
+ global.getTEMP_LOCATION() + File.separator
+ path + bFile.getChapterId() + File.separator + pathName;
File filePath = new File(tempPath);
if(!filePath.exists()){
......@@ -133,7 +165,7 @@ public class BVideoServiceImpl implements BVideoService {
File oldfile = new File(oldPath);
if (oldfile.exists()) { //文件存在时
InputStream inStream = new FileInputStream(oldPath); //读入原文件
FileOutputStream fs = new FileOutputStream(tempPath+ File.separator+videoName);
FileOutputStream fs = new FileOutputStream(tempPath+ File.separator+bFile.getVideoName());
byte[] buffer = new byte[1024000];
int length;
while ( (byteread = inStream.read(buffer)) != -1) {
......@@ -155,20 +187,39 @@ public class BVideoServiceImpl implements BVideoService {
/**
* 上传视频到video目录
* @param file
* @param bVideo
* @param path
* @param bFile
* @return
* @throws IOException
*/
private BVideo uploadVideo(MultipartFile file, BVideo bVideo, String path) throws IOException {
private BFile uploadVideo(MultipartFile file, BFile bFile) throws IOException {
BufferedOutputStream stream = null;
String path;
String pathName;
if (bVideo.getType().equals("0")){
pathName = global.getVIDEO_LOCATION();//视频路径
if(bFile.getLessonId()!=null&&!bFile.getLessonId().equals("")){
path = global.getLESSON_LOCATION() + File.separator + bFile.getLessonId() + File.separator;
}else{
path = global.getSL_LOCATION() + File.separator + bFile.getSlId() + File.separator;
}
if (bFile.getType().equals("0")){
pathName = global.getVIDEO_LOCATION();//视频路径
}else if(bFile.getType().equals("1")){
pathName = global.getFILE_LOCATION();//文件路径
}else if(bFile.getType().equals("2")){
pathName = global.getPPT_LOCATION();//ppt路径
}else{
pathName = global.getPDF_LOCATION();//pdf路径
}
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();
}
//上传文件
......@@ -185,21 +236,22 @@ public class BVideoServiceImpl implements BVideoService {
String filename = uploadFileName + "." + uploadFileSuffix;
stream = new BufferedOutputStream(new FileOutputStream(new File(path + filename)));
stream = new BufferedOutputStream(new FileOutputStream(new File(realPath + filename)));
byte[] bytes = file.getBytes();
stream.write(bytes,0,bytes.length);
String newPath = pathName
+ File.separator + bVideo.getLessonId() + File.separator;
String newPath = path.substring(path.indexOf(File.separator)+1) + File.separator
+ bFile.getChapterId() + File.separator
+ pathName + File.separator;
bVideo.setVideoName(name+ "." +uploadFileSuffix);//文件名
bVideo.setVideoUrl(newPath+ filename);//存储地址
bFile.setVideoName(name+ "." +uploadFileSuffix);//文件名
bFile.setVideoUrl(newPath+ filename);//存储地址
stream.close();
return bVideo;
return bFile;
}
@Override
public BVideo queryFileUrlByChapterId(String chapterId) {
return bVideoRepository.queryFileUrlByChapterId(chapterId);
public BFile queryFileUrlByChapterId(String chapterId) {
return bFileRepository.queryFileUrlByChapterId(chapterId);
}
}
package org.rcisoft.business.bsl.service.impl;
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.rcisoft.business.bchapter.dao.BChapterRepository;
import org.rcisoft.business.bchapter.entity.BChapter;
......@@ -135,6 +136,7 @@ public class BSlServiceImpl implements BSlService {
//添加课程方向信息
direction.setBusinessId(IdGen.uuid());
direction.setSlId(model.getBusinessId());
direction.setDirectionId(model.getDirectionId());
bLessonRepository.insertLessonDirection(direction);
if(data!=0&&result!=0){
line= data;
......@@ -151,10 +153,7 @@ public class BSlServiceImpl implements BSlService {
ArrayList<String> repeatCode = new ArrayList<String>();
ArrayList<String> lessonCode = new ArrayList<String>();
ArrayList<String> teacherCode = new ArrayList<String>();
ArrayList<String> gitlab = new ArrayList<String>();
ArrayList<String> termCode = new ArrayList<String>();
ArrayList<String> classHour = new ArrayList<String>();
ArrayList<String> credits = new ArrayList<String>();
List<BSl> repeatSl = new ArrayList<>();
Map map = new HashMap();
......@@ -166,7 +165,7 @@ public class BSlServiceImpl implements BSlService {
}
for(String[] value:values){ //将数据封装到entity
if(value.length>=4) {
if(value.length>=6) {
//1. 检查数据正确性
BSl bSl = null;
BSl b = new BSl(value[0]);
......@@ -176,7 +175,7 @@ public class BSlServiceImpl implements BSlService {
bSl1.setLessonCode(value[1]);
bSl1.setClassHour(value[4]);
bSl1.setCredits(value[5]);
if (value[0] == null || value[0].equals("") || value[1] == null || value[1].equals("")) {
if (StringUtils.isAnyEmpty(value[0]) || value[1] == null || value[1].equals("")) {
continue;
}
if ((bSl = bSlRepository.selectOne(b)) != null) {
......@@ -209,18 +208,6 @@ public class BSlServiceImpl implements BSlService {
bSl.setSlCoverUrl(bLessonRepository.queryBLessonByCode(value[1]).getDefaultUrl());
UserUtil.setCurrentPersistOperation(bSl);
//3. 封装git lab
/*User user = userRepository.selectOne(new User(value[2]));
AccountDTO dto = new AccountDTO(user.getGitLabId(),user.getGitLabImpressionToken());
dto.setUsername(user.getGitLabUsername());
if(StringUtils.isEmpty(dto.getId())|| StringUtils.isEmpty(dto.getImpersonationToken())){
gitlab.add(value[2]);
continue;
}
Project project = action.createProject(pName,dto);
bSl.setGitLabProjectId(project.getId());
String pName = global.getGIT_LAB_PROJECT_PREFIX()+value[0];
bSl.setGitLabProjectName(pName);*/
if (!bSls.contains(bSl)) {
bSls.add(bSl);
}
......@@ -256,18 +243,10 @@ public class BSlServiceImpl implements BSlService {
if(termCode.size()>0){
nullResult.append("以下学期编号不存在:").append(JSON.toJSONString(termCode)).append("。 ");
}
if(gitlab.size()>0){
nullResult.append("以下教师的gitlab账户不存在(请重试新增该教师):").append(JSON.toJSONString(gitlab));
}
result+=nullResult;
if(bSls.size()<1){
throw new ServiceException(ResultServiceEnums.EXCEL_IMPORT_DB_INSERT_ERROR.getCode(),result);
}
return new PersistModel(1,result);
}
......
package org.rcisoft.business.bvideo.dao;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.rcisoft.business.bvideo.entity.BVideo;
import org.rcisoft.core.base.BaseMapper;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Map;
/**
* Created with gaowenfneg on 2017-10-9 14:34:56.
*/
@Repository
public interface BVideoRepository extends BaseMapper<BVideo> {
/**
* 根据条件查找
* @param param
* @return
*/
@Select("<script>select * from b_video</script>")
@ResultMap(value = "BaseResultMap" )
List<BVideo> queryBVideos(Map<String, Object> param);
@Insert("<script>insert into b_r_chapter_video (video_id,chapter_id,type) values (#{businessId},#{chapterId},#{type})</script>")
int insertChapterVideo(BVideo model);
@Select("<script>SELECT\n" +
"\tbv.* from b_video bv\n" +
"\tLEFT JOIN b_r_chapter_video bcv on bcv.video_id = bv.business_id\n" +
"\twhere bcv.chapter_id = #{0} " +
"and bcv.type = #{1}</script>")
@ResultMap(value = "BaseResultMap" )
BVideo selectInfoByChapterId(String chapterId, String type);
@Select("<script>SELECT\n" +
"\tbv.*\n" +
"FROM\n" +
"\tb_video bv\n" +
"LEFT JOIN b_r_chapter_video brc ON bv.business_id = brc.video_id\n" +
"WHERE\n" +
"\tbrc.chapter_id = #{chapterId}\n" +
"AND brc.type = '1'</script>")
@ResultMap(value = "BaseResultMap" )
BVideo queryFileUrlByChapterId(String chapterId);
@Select("<script>SELECT\n" +
"\tbv.*\n" +
"FROM\n" +
"\tb_video bv\n" +
"LEFT JOIN b_r_chapter_video brc ON bv.business_id = brc.video_id\n" +
"WHERE\n" +
"\tbrc.chapter_id = #{chapterId}</script>")
@ResultMap(value = "BaseResultMap" )
BVideo queryBVideoByChapterId(String chapterId);
}
......@@ -68,6 +68,14 @@ public class Global {
@Value("${global.path.file_location}")
private String FILE_LOCATION;
/*ppt路径*/
@Value("${global.path.ppt_location}")
private String PPT_LOCATION;
/*pdf路径*/
@Value("${global.path.pdf_location}")
private String PDF_LOCATION;
/*excel模板位置*/
@Value("${global.path.excel_template_location}")
private String EXCEL_TEMPLATE_LOCATION;
......
......@@ -107,9 +107,11 @@ global:
sl_location: sl
freemarker_location: /freemarker
image_location: /upload
video_location: /video
temp_location: /temp
file_location: /file
video_location: video
temp_location: temp
file_location: file
ppt_location: ppt
pdf_location: pdf
excel_template_location: excel-template/
cource_logo_location: /course/logo
images_location: /images
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.rcisoft.business.bvideo.dao.BVideoRepository">
<resultMap id="BaseResultMap" type="org.rcisoft.business.bvideo.entity.BVideo">
<mapper namespace="org.rcisoft.business.bfile.dao.BFileRepository">
<resultMap id="BaseResultMap" type="org.rcisoft.business.bfile.entity.BFile">
<id column="business_id" jdbcType="VARCHAR" property="businessId"/>
<result column="del_flag" jdbcType="VARCHAR" property="delFlag"/>
<result column="flag" jdbcType="VARCHAR" property="flag"/>
......@@ -16,5 +16,8 @@
<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="sl_id" jdbcType="VARCHAR" property="slId"/>
<result column="lesson_id" jdbcType="VARCHAR" property="lessonId"/>
</resultMap>
</mapper>
\ 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