Commit 32c90bb5 authored by luzhuang's avatar luzhuang

mp3、mp4

parent 152c4b8c
...@@ -93,10 +93,10 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -93,10 +93,10 @@ public class BChapterServiceImpl implements BChapterService {
@Value("${upload.fileMaxSize:100}") @Value("${upload.fileMaxSize:100}")
private Long fileMaxSize; private Long fileMaxSize;
@Value("${upload.fileMaxPages:100}") @Value("${upload.fileMaxPages:100}")
private Integer fileMaxPages; private Integer fileMaxPages;
@Override @Override
...@@ -144,12 +144,12 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -144,12 +144,12 @@ public class BChapterServiceImpl implements BChapterService {
List<BLessonPerson> bLessonPersonList = bLessonPersonRepository.getAppointInTraining(lessonId, curUser.getUserId()); List<BLessonPerson> bLessonPersonList = bLessonPersonRepository.getAppointInTraining(lessonId, curUser.getUserId());
if (null != bLessonPersonList && bLessonPersonList.size() > 0 && bLessonPersonList.get(0) != null) { if (null != bLessonPersonList && bLessonPersonList.size() > 0 && bLessonPersonList.get(0) != null) {
map.put("totalProgress", bLessonPersonList.get(0).getLearnProgress()); map.put("totalProgress", bLessonPersonList.get(0).getLearnProgress());
}else { } else {
map.put("totalProgress", "0%"); map.put("totalProgress", "0%");
} }
List<BLesson> bLessonList = bLessonRepository.selectInfoById(lessonId,curUser); List<BLesson> bLessonList = bLessonRepository.selectInfoById(lessonId, curUser);
//判断课程是否存在 //判断课程是否存在
if (bLessonList == null || bLessonList.size() < 1 || bLessonList.get(0) == null){ if (bLessonList == null || bLessonList.size() < 1 || bLessonList.get(0) == null) {
throw new ServiceException(ResultServiceEnums.LESSON_NOT_EXISTA); throw new ServiceException(ResultServiceEnums.LESSON_NOT_EXISTA);
} }
BLesson bLesson = bLessonList.get(0); BLesson bLesson = bLessonList.get(0);
...@@ -164,8 +164,8 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -164,8 +164,8 @@ public class BChapterServiceImpl implements BChapterService {
mtUserGetsReqDTO.setIds(ids); mtUserGetsReqDTO.setIds(ids);
List<MTUserInfoRspDTO> mtUserInfoRspDTOList = mtCotactApiRequestClient.userGets(mtUserGetsReqDTO); List<MTUserInfoRspDTO> mtUserInfoRspDTOList = mtCotactApiRequestClient.userGets(mtUserGetsReqDTO);
List<String> departs = QueryDepart.queryDepart(mtUserInfoRspDTOList); List<String> departs = QueryDepart.queryDepart(mtUserInfoRspDTOList);
int result = bLessonRepository.isInViewRange(curUser,lessonId,departs); int result = bLessonRepository.isInViewRange(curUser, lessonId, departs);
if (result < 1){ if (result < 1) {
throw new ServiceException(ResultServiceEnums.NO_ACCESS); throw new ServiceException(ResultServiceEnums.NO_ACCESS);
} }
...@@ -176,9 +176,9 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -176,9 +176,9 @@ public class BChapterServiceImpl implements BChapterService {
mtUserGetsReqDTOlecDept.setCorpId(curUser.getCorpId()); mtUserGetsReqDTOlecDept.setCorpId(curUser.getCorpId());
mtUserGetsReqDTOlecDept.setIds(lecturerIds); mtUserGetsReqDTOlecDept.setIds(lecturerIds);
List<MTUserInfoRspDTO> mtUserInfoRspDTOLecDeptList = mtCotactApiRequestClient.userGets(mtUserGetsReqDTOlecDept); List<MTUserInfoRspDTO> mtUserInfoRspDTOLecDeptList = mtCotactApiRequestClient.userGets(mtUserGetsReqDTOlecDept);
if (mtUserInfoRspDTOLecDeptList != null && mtUserInfoRspDTOLecDeptList.size() > 0){ if (mtUserInfoRspDTOLecDeptList != null && mtUserInfoRspDTOLecDeptList.size() > 0) {
mtUserInfoRspDTOLecDeptList.forEach(mtUserInfoRspDTO -> { mtUserInfoRspDTOLecDeptList.forEach(mtUserInfoRspDTO -> {
if (mtUserInfoRspDTO.getDepts() != null && mtUserInfoRspDTO.getDepts().size() > 0 && mtUserInfoRspDTO.getId().equals(bLesson.getLecturerId())){ if (mtUserInfoRspDTO.getDepts() != null && mtUserInfoRspDTO.getDepts().size() > 0 && mtUserInfoRspDTO.getId().equals(bLesson.getLecturerId())) {
//设置部门名 //设置部门名
bLesson.setLecturerDeptName(mtUserInfoRspDTO.getDepts().get(0).getName()); bLesson.setLecturerDeptName(mtUserInfoRspDTO.getDepts().get(0).getName());
} }
...@@ -186,10 +186,10 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -186,10 +186,10 @@ public class BChapterServiceImpl implements BChapterService {
} }
//查询该课程是否收藏 //查询该课程是否收藏
int collectCount = bCollectRepository.selectCountbyLessonAndUser(curUser,bLesson.getBusinessId()); int collectCount = bCollectRepository.selectCountbyLessonAndUser(curUser, bLesson.getBusinessId());
if (collectCount>0){ if (collectCount > 0) {
bLesson.setIsCollect("1"); bLesson.setIsCollect("1");
}else { } else {
bLesson.setIsCollect("0"); bLesson.setIsCollect("0");
} }
map.put("lessonInfo", bLesson); // 课程信息 map.put("lessonInfo", bLesson); // 课程信息
...@@ -199,7 +199,7 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -199,7 +199,7 @@ public class BChapterServiceImpl implements BChapterService {
BChapter bChapter = bChapterRepository.selectByPrimaryKey(queryChapterListResDTO.getPid()); BChapter bChapter = bChapterRepository.selectByPrimaryKey(queryChapterListResDTO.getPid());
if (null != bChapter) { if (null != bChapter) {
queryChapterListResDTO.setPSort(bChapter.getSort()); queryChapterListResDTO.setPSort(bChapter.getSort());
queryChapterListResDTO.setProgress(Double.parseDouble(queryChapterListResDTO.getProgress())*100+"%"); queryChapterListResDTO.setProgress(Double.parseDouble(queryChapterListResDTO.getProgress()) * 100 + "%");
} }
map.put("currentChapter", queryChapterListResDTO); map.put("currentChapter", queryChapterListResDTO);
} else { } else {
...@@ -235,7 +235,7 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -235,7 +235,7 @@ public class BChapterServiceImpl implements BChapterService {
int line = 0; int line = 0;
BFile bFile = new BFile(); BFile bFile = new BFile();
BChapter model = new BChapter(); BChapter model = new BChapter();
if(chapterDTO.getChapterLevel() == 2 && (dto.getFileSize()== null || "".equals(dto.getFileSize()))){ if (chapterDTO.getChapterLevel() == 2 && (dto.getFileSize() == null || "".equals(dto.getFileSize()))) {
throw new ServiceException(ResultServiceEnums.FILE_NOT_NULL); throw new ServiceException(ResultServiceEnums.FILE_NOT_NULL);
} }
...@@ -295,19 +295,19 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -295,19 +295,19 @@ public class BChapterServiceImpl implements BChapterService {
//新建节数据插入到chapter表 //新建节数据插入到chapter表
chapterDTO.setIsTest(dto.getType()); chapterDTO.setIsTest(dto.getType());
line = bChapterRepository.insertSelective(model); line = bChapterRepository.insertSelective(model);
LogUtil.fileChangeLog("----------------------------文件时间:"+model.getCourseTime()+"---------------------"); LogUtil.fileChangeLog("----------------------------文件时间:" + model.getCourseTime() + "---------------------");
//先判断该课程的第一节是否是本节 更新blesson表中course_time字段 //先判断该课程的第一节是否是本节 更新blesson表中course_time字段
String cid = bChapterRepository.getFirstChapter(model.getLessonId()); String cid = bChapterRepository.getFirstChapter(model.getLessonId());
if (cid.equals(model.getBusinessId())) { if (cid.equals(model.getBusinessId())) {
bChapterRepository.updateVideoTimeInLesson(model.getCourseTime(), model.getLessonId()); bChapterRepository.updateVideoTimeInLesson(model.getCourseTime(), model.getLessonId());
LogUtil.fileChangeLog("-----------------------------更新lesson中time:"+model.getCourseTime()+"---------------------"); LogUtil.fileChangeLog("-----------------------------更新lesson中time:" + model.getCourseTime() + "---------------------");
} }
//上传文件数据插入到bfile表中 //上传文件数据插入到bfile表中
int x = bFileRepository.insertUploadFile(bFile); int x = bFileRepository.insertUploadFile(bFile);
bChapterRepository.updateClassHourInLesson(model.getLessonId());//更新b_lesson表中 class_hour bChapterRepository.updateClassHourInLesson(model.getLessonId());//更新b_lesson表中 class_hour
// 新增节 才更新进度 // 新增节 才更新进度
if (2 == chapterDTO.getChapterLevel()){ if (2 == chapterDTO.getChapterLevel()) {
// 更新课程总进度 // 更新课程总进度
this.updateLessonProgress(chapterDTO.getLessonId(), true, ""); this.updateLessonProgress(chapterDTO.getLessonId(), true, "");
} }
...@@ -315,9 +315,9 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -315,9 +315,9 @@ public class BChapterServiceImpl implements BChapterService {
} }
} else { } else {
BFile bFileOld = bFileRepository.selectInfoByChapterId(chapterDTO.getBusinessId()); BFile bFileOld = bFileRepository.selectInfoByChapterId(chapterDTO.getBusinessId());
if(model.getChapterLevel()==1){ if (model.getChapterLevel() == 1) {
int x = bChapterRepository.updateChapterName(model.getChapterName(),model.getBusinessId()); int x = bChapterRepository.updateChapterName(model.getChapterName(), model.getBusinessId());
return new PersistModel(x); return new PersistModel(x);
} }
UserUtil.setCurrentMergeOperation(model); UserUtil.setCurrentMergeOperation(model);
bFile.setChapterId(model.getBusinessId()); bFile.setChapterId(model.getBusinessId());
...@@ -337,16 +337,16 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -337,16 +337,16 @@ public class BChapterServiceImpl implements BChapterService {
} }
//判断修改前后pid是否发生改变 //判断修改前后pid是否发生改变
BChapter bChapter = bChapterRepository.selectByPrimaryKey(model.getBusinessId()); BChapter bChapter = bChapterRepository.selectByPrimaryKey(model.getBusinessId());
if(bChapter !=null && !bChapter.getPid().equals(model.getPid())){ if (bChapter != null && !bChapter.getPid().equals(model.getPid())) {
line = bChapterRepository.updateByPrimaryKeySelective(model); line = bChapterRepository.updateByPrimaryKeySelective(model);
//更新修改之前章中节的sort //更新修改之前章中节的sort
List<String> chapterIds = bChapterRepository.getChapterIds(bChapter.getPid(),bChapter.getLessonId()); List<String> chapterIds = bChapterRepository.getChapterIds(bChapter.getPid(), bChapter.getLessonId());
if(chapterIds != null && chapterIds.size() > 0){ if (chapterIds != null && chapterIds.size() > 0) {
List<Map<String,Object>> params = new ArrayList<>(); List<Map<String, Object>> params = new ArrayList<>();
for(int i = 0 ;i < chapterIds.size(); i++){ for (int i = 0; i < chapterIds.size(); i++) {
Map<String,Object> map = new HashedMap(); Map<String, Object> map = new HashedMap();
map.put("businessId",chapterIds.get(i)); map.put("businessId", chapterIds.get(i));
map.put("sort",i+1); map.put("sort", i + 1);
params.add(map); params.add(map);
} }
//更新表中sort //更新表中sort
...@@ -356,37 +356,37 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -356,37 +356,37 @@ public class BChapterServiceImpl implements BChapterService {
model.setSort(sort); model.setSort(sort);
line = bChapterRepository.updateByPrimaryKeySelective(model); line = bChapterRepository.updateByPrimaryKeySelective(model);
//更新修改之后章中节的sort //更新修改之后章中节的sort
List<String> chapterIds2 = bChapterRepository.getChapterIds(model.getPid(),model.getLessonId()); List<String> chapterIds2 = bChapterRepository.getChapterIds(model.getPid(), model.getLessonId());
if(chapterIds2 != null && chapterIds2.size() > 0){ if (chapterIds2 != null && chapterIds2.size() > 0) {
List<Map<String,Object>> params = new ArrayList<>(); List<Map<String, Object>> params = new ArrayList<>();
for(int i = 0 ;i < chapterIds2.size(); i++){ for (int i = 0; i < chapterIds2.size(); i++) {
Map<String,Object> map = new HashedMap(); Map<String, Object> map = new HashedMap();
map.put("businessId",chapterIds2.get(i)); map.put("businessId", chapterIds2.get(i));
map.put("sort",i+1); map.put("sort", i + 1);
params.add(map); params.add(map);
} }
//更新表中sort //更新表中sort
bChapterRepository.updateSort(params); bChapterRepository.updateSort(params);
} }
}else{ } else {
line = bChapterRepository.updateByPrimaryKeySelective(model); line = bChapterRepository.updateByPrimaryKeySelective(model);
} }
if(model.getChapterLevel() == 1) { if (model.getChapterLevel() == 1) {
return new PersistModel(line); return new PersistModel(line);
} }
int x = bFileRepository.updateUploadFile(bFile); int x = bFileRepository.updateUploadFile(bFile);
// 判断 新文件 更新 课程学习进度(总进度 此章节进度) // 判断 新文件 更新 课程学习进度(总进度 此章节进度)
if (bFileOld != null && StringUtils.isNotEmpty(bFileOld.getVideoUrl()) && !(bFileOld.getVideoUrl().equals(dto.getVideoUrl())) ) { if (bFileOld != null && StringUtils.isNotEmpty(bFileOld.getVideoUrl()) && !(bFileOld.getVideoUrl().equals(dto.getVideoUrl()))) {
// 所有学习过此课程的 学生课程信息 // 所有学习过此课程的 学生课程信息
List<BLessonPerson> bLessonPersonList = bLessonPersonRepository.selectByLessonId(chapterDTO.getLessonId(),""); List<BLessonPerson> bLessonPersonList = bLessonPersonRepository.selectByLessonId(chapterDTO.getLessonId(), "");
BLesson bLesson = bLessonRepository.selectByPrimaryKey(chapterDTO.getLessonId()); BLesson bLesson = bLessonRepository.selectByPrimaryKey(chapterDTO.getLessonId());
NumberFormat numberFormat = NumberFormat.getInstance(); NumberFormat numberFormat = NumberFormat.getInstance();
numberFormat.setMaximumFractionDigits(2); numberFormat.setMaximumFractionDigits(2);
for (BLessonPerson lessonPerson: bLessonPersonList){ for (BLessonPerson lessonPerson : bLessonPersonList) {
// 更新 学生针对此章节的中间表 // 更新 学生针对此章节的中间表
List<BRStudentChapter> brStudentChapterList = brStudentChapterRepository.queryByStuIdAndChapter(chapterDTO.getBusinessId(), ""); List<BRStudentChapter> brStudentChapterList = brStudentChapterRepository.queryByStuIdAndChapter(chapterDTO.getBusinessId(), "");
for (BRStudentChapter studentChapter: brStudentChapterList){ for (BRStudentChapter studentChapter : brStudentChapterList) {
if (lessonPerson.getPersonId().equals(studentChapter.getStudentId())) { if (lessonPerson.getPersonId().equals(studentChapter.getStudentId())) {
double learnProgress = Double.parseDouble(lessonPerson.getLearnProgress().split("%")[0]) / 100; double learnProgress = Double.parseDouble(lessonPerson.getLearnProgress().split("%")[0]) / 100;
...@@ -402,7 +402,7 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -402,7 +402,7 @@ public class BChapterServiceImpl implements BChapterService {
lessonPerson.setFinishDateSetNull("1"); lessonPerson.setFinishDateSetNull("1");
} }
// 规避 复数 和超100% 的情况 // 规避 复数 和超100% 的情况
newLearnProgress = newLearnProgress > 1 ? 1: newLearnProgress < 0 ? 0 : newLearnProgress; newLearnProgress = newLearnProgress > 1 ? 1 : newLearnProgress < 0 ? 0 : newLearnProgress;
lessonPerson.setLearnProgress(newLearnProgress * 100 + "%"); lessonPerson.setLearnProgress(newLearnProgress * 100 + "%");
bLessonPersonRepository.updateAtChapter(lessonPerson); bLessonPersonRepository.updateAtChapter(lessonPerson);
...@@ -439,44 +439,43 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -439,44 +439,43 @@ public class BChapterServiceImpl implements BChapterService {
} }
/** /**
*
* @param lessonId * @param lessonId
* @param add true: 新增 false 删除 * @param add true: 新增 false 删除
*/ */
// 新增章节 - 更新学生观看课程总进度 // 新增章节 - 更新学生观看课程总进度
private void updateLessonProgress(String lessonId, boolean add, String chapterId){ private void updateLessonProgress(String lessonId, boolean add, String chapterId) {
NumberFormat numberFormat = NumberFormat.getInstance(); NumberFormat numberFormat = NumberFormat.getInstance();
numberFormat.setMaximumFractionDigits(2); numberFormat.setMaximumFractionDigits(2);
List<BLessonPerson> bLessonPersonList = bLessonPersonRepository.selectByLessonId(lessonId, ""); List<BLessonPerson> bLessonPersonList = bLessonPersonRepository.selectByLessonId(lessonId, "");
BLesson bLesson = bLessonRepository.selectByPrimaryKey(lessonId); BLesson bLesson = bLessonRepository.selectByPrimaryKey(lessonId);
for (BLessonPerson lessonPerson: bLessonPersonList){ for (BLessonPerson lessonPerson : bLessonPersonList) {
if (!add && null != lessonPerson.getChapterId() && lessonPerson.getChapterId().equals(chapterId)){ if (!add && null != lessonPerson.getChapterId() && lessonPerson.getChapterId().equals(chapterId)) {
bLessonPersonRepository.clearChapterId(lessonPerson.getBusinessId()); bLessonPersonRepository.clearChapterId(lessonPerson.getBusinessId());
} }
String newLearnProgress; String newLearnProgress;
if(lessonPerson.getLearnProgress() == null){ if (lessonPerson.getLearnProgress() == null) {
break; break;
} }
List<BRStudentChapter> brStudentChapterList = brStudentChapterRepository.queryByStuIdAndChapter(chapterId, lessonPerson.getPersonId()); List<BRStudentChapter> brStudentChapterList = brStudentChapterRepository.queryByStuIdAndChapter(chapterId, lessonPerson.getPersonId());
double oldProgress = 0; double oldProgress = 0;
if (null !=brStudentChapterList && brStudentChapterList.size()>0){ if (null != brStudentChapterList && brStudentChapterList.size() > 0) {
oldProgress = brStudentChapterList.get(0).getProgress(); oldProgress = brStudentChapterList.get(0).getProgress();
} }
double learnProgress = Double.parseDouble(lessonPerson.getLearnProgress().split("%")[0]) / 100 ; double learnProgress = Double.parseDouble(lessonPerson.getLearnProgress().split("%")[0]) / 100;
if (add){ if (add) {
newLearnProgress =Integer.parseInt(bLesson.getClassHour()) -1 == 0? "0": numberFormat.format( learnProgress * (Integer.parseInt(bLesson.getClassHour()) -1) / (Double.parseDouble(bLesson.getClassHour())) ); newLearnProgress = Integer.parseInt(bLesson.getClassHour()) - 1 == 0 ? "0" : numberFormat.format(learnProgress * (Integer.parseInt(bLesson.getClassHour()) - 1) / (Double.parseDouble(bLesson.getClassHour())));
}else { } else {
int oldClassHour = Integer.parseInt(bLesson.getClassHour()) + 1; int oldClassHour = Integer.parseInt(bLesson.getClassHour()) + 1;
newLearnProgress = numberFormat.format((learnProgress * oldClassHour - oldProgress)/(oldClassHour -1) ); newLearnProgress = numberFormat.format((learnProgress * oldClassHour - oldProgress) / (oldClassHour - 1));
} }
if (0 == Double.parseDouble(newLearnProgress)){ if (0 == Double.parseDouble(newLearnProgress)) {
lessonPerson.setIsFinish("0"); lessonPerson.setIsFinish("0");
// lessonPerson.setFinishDate(null); // lessonPerson.setFinishDate(null);
lessonPerson.setFinishDateSetNull("1"); lessonPerson.setFinishDateSetNull("1");
}else { } else {
if (learnProgress > 0 && Double.parseDouble(newLearnProgress) < 0.01) { if (learnProgress > 0 && Double.parseDouble(newLearnProgress) < 0.01) {
newLearnProgress = "0.01"; newLearnProgress = "0.01";
} }
...@@ -492,17 +491,17 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -492,17 +491,17 @@ public class BChapterServiceImpl implements BChapterService {
} }
//TODO 判断 曾经是否学完过 奖励积分 //TODO 判断 曾经是否学完过 奖励积分
if (IsFinishEnum.FINISHED.getCode().equals(lessonPerson.getIsFinish()) && !(IsFinishEnum.LEARNING.getCode().equals(lessonPerson.getEverFinished()))){ if (IsFinishEnum.FINISHED.getCode().equals(lessonPerson.getIsFinish()) && !(IsFinishEnum.LEARNING.getCode().equals(lessonPerson.getEverFinished()))) {
//查询课程信息 //查询课程信息
BPersonValue bPersonValue = new BPersonValue(lessonPerson.getPersonId(),"学完!@#课程",bLesson.getValueGain(),"0",bLesson.getBusinessId()); BPersonValue bPersonValue = new BPersonValue(lessonPerson.getPersonId(), "学完!@#课程", bLesson.getValueGain(), "0", bLesson.getBusinessId());
bLessonServiceImpl.addValueEvent(lessonPerson.getPersonId(),bPersonValue,null); bLessonServiceImpl.addValueEvent(lessonPerson.getPersonId(), bPersonValue, null);
lessonPerson.setEverFinished("1"); lessonPerson.setEverFinished("1");
} }
// 规避 复数 和超100% 的情况 // 规避 复数 和超100% 的情况
float tempTotalProgress = Float.parseFloat(newLearnProgress); float tempTotalProgress = Float.parseFloat(newLearnProgress);
newLearnProgress = String.valueOf(tempTotalProgress > 1 ? 1: tempTotalProgress < 0 ? 0 : tempTotalProgress); newLearnProgress = String.valueOf(tempTotalProgress > 1 ? 1 : tempTotalProgress < 0 ? 0 : tempTotalProgress);
lessonPerson.setLearnProgress(Float.parseFloat(newLearnProgress)*100+"%"); lessonPerson.setLearnProgress(Float.parseFloat(newLearnProgress) * 100 + "%");
bLessonPersonRepository.updateAtChapter(lessonPerson); bLessonPersonRepository.updateAtChapter(lessonPerson);
// 根据chapter_id 删除b_r_student_chapter // 根据chapter_id 删除b_r_student_chapter
brStudentChapterRepository.deleteBatchByChapterId(chapterId); brStudentChapterRepository.deleteBatchByChapterId(chapterId);
...@@ -519,15 +518,15 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -519,15 +518,15 @@ public class BChapterServiceImpl implements BChapterService {
@Override @Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = false) @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public PersistModel removeBChapter(String id,CurUser curUser) { public PersistModel removeBChapter(String id, CurUser curUser) {
BChapter bChapter = bChapterRepository.selectByPrimaryKey(id); BChapter bChapter = bChapterRepository.selectByPrimaryKey(id);
String lessonId = bChapterRepository.getLessonIdBychaperId(id); String lessonId = bChapterRepository.getLessonIdBychaperId(id);
if (bChapter == null) if (bChapter == null)
throw new ServiceException(ResultServiceEnums.CHAPTER_NOT_EXISTS); throw new ServiceException(ResultServiceEnums.CHAPTER_NOT_EXISTS);
int chapterCount =bChapterRepository.getlessonHours(lessonId); int chapterCount = bChapterRepository.getlessonHours(lessonId);
BLesson bLesson = bLessonRepository.selectByPrimaryKey(lessonId); BLesson bLesson = bLessonRepository.selectByPrimaryKey(lessonId);
if((ReleaseStateEnum.RELEASED.getCode().equals(bLesson.getReleaseState()) || ReleaseStateEnum.CLOSED.getCode().equals(bLesson.getReleaseState())) && chapterCount == 1 && bChapter.getChapterLevel() != 1){ if ((ReleaseStateEnum.RELEASED.getCode().equals(bLesson.getReleaseState()) || ReleaseStateEnum.CLOSED.getCode().equals(bLesson.getReleaseState())) && chapterCount == 1 && bChapter.getChapterLevel() != 1) {
throw new ServiceException(ResultServiceEnums.CHAPTER_ONLY_ONE); throw new ServiceException(ResultServiceEnums.CHAPTER_ONLY_ONE);
} }
List<QueryChapterListResDTO> childList = bChapterRepository.queryBChaptersByPid(id); List<QueryChapterListResDTO> childList = bChapterRepository.queryBChaptersByPid(id);
...@@ -537,15 +536,15 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -537,15 +536,15 @@ public class BChapterServiceImpl implements BChapterService {
throw new ServiceException(ResultServiceEnums.CHAPTER_HAS_CHILD); throw new ServiceException(ResultServiceEnums.CHAPTER_HAS_CHILD);
} }
//获取第一节课的id 与当前id对比 //获取第一节课的id 与当前id对比
String firstId = bChapterRepository.getFirstChapter(lessonId); String firstId = bChapterRepository.getFirstChapter(lessonId);
int line = bChapterRepository.removeByPrimaryKey(id); int line = bChapterRepository.removeByPrimaryKey(id);
bChapterRepository.updateClassHourInLesson(lessonId); bChapterRepository.updateClassHourInLesson(lessonId);
if(StringUtils.isNotEmpty(id) && id.equals(firstId)){ if (StringUtils.isNotEmpty(id) && id.equals(firstId)) {
//当前节为第一节 获取下一节的课程时长 //当前节为第一节 获取下一节的课程时长
String secondId = bChapterRepository.getFirstChapter(lessonId); String secondId = bChapterRepository.getFirstChapter(lessonId);
String time = bChapterRepository.getTimeByChapterId(secondId); String time = bChapterRepository.getTimeByChapterId(secondId);
//更新到b_lesson 表 //更新到b_lesson 表
bChapterRepository.updateCourseTimeForLesson(time,lessonId); bChapterRepository.updateCourseTimeForLesson(time, lessonId);
} }
//获取删除的课的id 与当前用户最近观看课的id对比 //获取删除的课的id 与当前用户最近观看课的id对比
// QueryChapterListResDTO queryChapterListResDTO = bChapterRepository.getWithCurrentChapterBylessonId(lessonId, curUser.getUserId(), curUser.getCorpId()); // QueryChapterListResDTO queryChapterListResDTO = bChapterRepository.getWithCurrentChapterBylessonId(lessonId, curUser.getUserId(), curUser.getCorpId());
...@@ -560,13 +559,13 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -560,13 +559,13 @@ public class BChapterServiceImpl implements BChapterService {
// brStudentChapterRepository.deleteByPrimaryKey(queryChapterListResDTO.getBRSBusinessId()); // brStudentChapterRepository.deleteByPrimaryKey(queryChapterListResDTO.getBRSBusinessId());
// } // }
//更新表中sort //更新表中sort
List<String> chapterIds = bChapterRepository.getChapterIds(bChapter.getPid(),bChapter.getLessonId()); List<String> chapterIds = bChapterRepository.getChapterIds(bChapter.getPid(), bChapter.getLessonId());
if(chapterIds != null && chapterIds.size() > 0){ if (chapterIds != null && chapterIds.size() > 0) {
List<Map<String,Object>> params = new ArrayList<>(); List<Map<String, Object>> params = new ArrayList<>();
for(int i = 0 ;i < chapterIds.size(); i++){ for (int i = 0; i < chapterIds.size(); i++) {
Map<String,Object> map = new HashedMap(); Map<String, Object> map = new HashedMap();
map.put("businessId",chapterIds.get(i)); map.put("businessId", chapterIds.get(i));
map.put("sort",i+1); map.put("sort", i + 1);
params.add(map); params.add(map);
} }
//更新表中sort //更新表中sort
...@@ -575,7 +574,7 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -575,7 +574,7 @@ public class BChapterServiceImpl implements BChapterService {
// List<BRStudentChapter> brStudentChapterList = brStudentChapterRepository.queryByStuIdAndChapter(id, curUser.getUserId()); // List<BRStudentChapter> brStudentChapterList = brStudentChapterRepository.queryByStuIdAndChapter(id, curUser.getUserId());
// 判断 2-节 才重新计算进度 // 判断 2-节 才重新计算进度
if (2 == bChapter.getChapterLevel()){ if (2 == bChapter.getChapterLevel()) {
// double oldProgress = 0; // double oldProgress = 0;
// if (null !=brStudentChapterList && brStudentChapterList.size()>0){ // if (null !=brStudentChapterList && brStudentChapterList.size()>0){
// oldProgress = brStudentChapterList.get(0).getProgress(); // oldProgress = brStudentChapterList.get(0).getProgress();
...@@ -583,18 +582,18 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -583,18 +582,18 @@ public class BChapterServiceImpl implements BChapterService {
// 根据chapter_id 删除b_r_student_chapter // 根据chapter_id 删除b_r_student_chapter
// brStudentChapterRepository.deleteBatchByChapterId(id); // brStudentChapterRepository.deleteBatchByChapterId(id);
// 更新学生 对应章节总进度 // 更新学生 对应章节总进度
this.updateLessonProgress(lessonId, false,id); this.updateLessonProgress(lessonId, false, id);
} }
//删除student_chapter表中数据 //删除student_chapter表中数据
bChapterRepository.deleteBStudentChapter(id,curUser.getUserId()); bChapterRepository.deleteBStudentChapter(id, curUser.getUserId());
return new PersistModel(line); return new PersistModel(line);
} }
@Override @Override
public String changeFileToPdf(String chapterId) { public String changeFileToPdf(String chapterId) {
if (StringUtils.isEmpty(chapterId)){ if (StringUtils.isEmpty(chapterId)) {
return null; return null;
} }
//1. 获取文件信息 //1. 获取文件信息
...@@ -604,7 +603,7 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -604,7 +603,7 @@ public class BChapterServiceImpl implements BChapterService {
@Override @Override
public String changeFileToPdfAtView(BFile bFile) { public String changeFileToPdfAtView(BFile bFile) {
if (StringUtils.isEmpty(bFile.getVideoUrl()) || StringUtils.isEmpty(bFile.getLessonId()) || StringUtils.isEmpty(bFile.getType())){ if (StringUtils.isEmpty(bFile.getVideoUrl()) || StringUtils.isEmpty(bFile.getLessonId()) || StringUtils.isEmpty(bFile.getType())) {
return null; return null;
// throw new ServiceException(ResultServiceEnums.PARAM_NOT_NULL); // throw new ServiceException(ResultServiceEnums.PARAM_NOT_NULL);
} }
...@@ -614,7 +613,7 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -614,7 +613,7 @@ public class BChapterServiceImpl implements BChapterService {
@Override @Override
public String getDownLoadUrl(BFile bFile) { public String getDownLoadUrl(BFile bFile) {
if (StringUtils.isEmpty(bFile.getVideoUrl()) || StringUtils.isEmpty(bFile.getLessonId())){ if (StringUtils.isEmpty(bFile.getVideoUrl()) || StringUtils.isEmpty(bFile.getLessonId())) {
return null; return null;
// throw new ServiceException(ResultServiceEnums.PARAM_NOT_NULL); // throw new ServiceException(ResultServiceEnums.PARAM_NOT_NULL);
} }
...@@ -645,7 +644,7 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -645,7 +644,7 @@ public class BChapterServiceImpl implements BChapterService {
LogUtil.fileChangeLog("------------------下载-------------------------" + fileOld); LogUtil.fileChangeLog("------------------下载-------------------------" + fileOld);
String downLoadName = downLoadFile(bFile, file, filePath); String downLoadName = downLoadFile(bFile, file, filePath);
LogUtil.fileChangeLog("------------------判断可读-------------------------" + fileOld); LogUtil.fileChangeLog("------------------判断可读-------------------------" + fileOld);
FileReadableUtil.fileReadable(filePath + File.separator + downLoadName,fileMaxSize,fileMaxPages); FileReadableUtil.fileReadable(filePath + File.separator + downLoadName, fileMaxSize, fileMaxPages);
} }
return flag; return flag;
} }
...@@ -670,6 +669,12 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -670,6 +669,12 @@ public class BChapterServiceImpl implements BChapterService {
} }
} }
return flag; return flag;
// Boolean line = CheckFileHeaderUtil.toCheck(getDownLoadUrl(bFile));
// if (!line) {
// throw new ServiceException(ResultServiceEnums.FILE_CHECK_ERROR);
// }
// return "1";
} }
...@@ -695,7 +700,7 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -695,7 +700,7 @@ public class BChapterServiceImpl implements BChapterService {
return returnBasePath + File.separator + name; return returnBasePath + File.separator + name;
} else { } else {
String downLoadName = downLoadFile(bFile, file, filePath); String downLoadName = downLoadFile(bFile, file, filePath);
FileReadableUtil.fileReadable(filePath + File.separator + downLoadName,fileMaxSize,fileMaxPages); FileReadableUtil.fileReadable(filePath + File.separator + downLoadName, fileMaxSize, fileMaxPages);
LogUtil.fileChangeLog("------------------返回下载后路径-----------------------------" + downLoadName); LogUtil.fileChangeLog("------------------返回下载后路径-----------------------------" + downLoadName);
return returnBasePath + File.separator + downLoadName; return returnBasePath + File.separator + downLoadName;
} }
...@@ -714,7 +719,7 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -714,7 +719,7 @@ public class BChapterServiceImpl implements BChapterService {
//判断文件是否可读 //判断文件是否可读
LogUtil.fileChangeLog("------------------判断文件是否可读-----------------------------" + filePath + File.separator + name); LogUtil.fileChangeLog("------------------判断文件是否可读-----------------------------" + filePath + File.separator + name);
FileReadableUtil.fileReadable(filePath + File.separator + downLoadFileName,fileMaxSize,fileMaxPages); FileReadableUtil.fileReadable(filePath + File.separator + downLoadFileName, fileMaxSize, fileMaxPages);
LogUtil.fileChangeLog("-----------------------------------------------downLoadFileUrl:" + filePath + File.separator + downLoadFileName); LogUtil.fileChangeLog("-----------------------------------------------downLoadFileUrl:" + filePath + File.separator + downLoadFileName);
LogUtil.fileChangeLog("-----------------------------------------------filePath:" + filePath + File.separator + newName); LogUtil.fileChangeLog("-----------------------------------------------filePath:" + filePath + File.separator + newName);
int result = officeToPdf.transformToPdf(filePath + File.separator + downLoadFileName, filePath + File.separator + newName); int result = officeToPdf.transformToPdf(filePath + File.separator + downLoadFileName, filePath + File.separator + newName);
...@@ -742,6 +747,7 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -742,6 +747,7 @@ public class BChapterServiceImpl implements BChapterService {
/** /**
* 将阿里云文件下载到服务器本地 * 将阿里云文件下载到服务器本地
*
* @param bFile * @param bFile
* @param file * @param file
* @param filePath * @param filePath
...@@ -784,7 +790,7 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -784,7 +790,7 @@ public class BChapterServiceImpl implements BChapterService {
LogUtil.fileChangeLog("------------------判断文件的保存路径后面是否以/结尾-----------------------------"); LogUtil.fileChangeLog("------------------判断文件的保存路径后面是否以/结尾-----------------------------");
//判断文件的保存路径后面是否以/结尾 //判断文件的保存路径后面是否以/结尾
if (!filePath.endsWith(File.separator)) { if (!filePath.endsWith(File.separator)) {
LogUtil.fileChangeLog("------------------不以/结尾,拼接/-----------------------------"+ filePath); LogUtil.fileChangeLog("------------------不以/结尾,拼接/-----------------------------" + filePath);
filePath += File.separator; filePath += File.separator;
} }
//写入到文件(注意文件保存路径的后面一定要加上文件的名称) //写入到文件(注意文件保存路径的后面一定要加上文件的名称)
......
...@@ -255,6 +255,7 @@ public enum ResultServiceEnums { ...@@ -255,6 +255,7 @@ public enum ResultServiceEnums {
DUP_FILE(155,"文件重复"), DUP_FILE(155,"文件重复"),
FILE_OVER_SIZE(156,"文件超过规定大小"), FILE_OVER_SIZE(156,"文件超过规定大小"),
FILE_OVER_PAGES(157,"文件页数超过规定个数"), FILE_OVER_PAGES(157,"文件页数超过规定个数"),
FILE_CHECK_ERROR(158,"文件格式与后缀名不符,请上传其他文件"),
; ;
private Integer code; private Integer code;
......
...@@ -6,8 +6,8 @@ import java.io.FileInputStream; ...@@ -6,8 +6,8 @@ import java.io.FileInputStream;
@Slf4j @Slf4j
public class CheckFileHeaderUtil { public class CheckFileHeaderUtil {
public static void main(String[] args) { public static void main(String[] args) {
String filePath = "C:\\Users\\Administrator\\Desktop\\0001.doc"; String filePath = "C:\\Users\\Administrator\\Desktop\\003.mp4";
toCheck(filePath); System.out.println(toCheck(filePath));
} }
public static String bytesToHexString(byte[] src) { public static String bytesToHexString(byte[] src) {
...@@ -48,24 +48,42 @@ public class CheckFileHeaderUtil { ...@@ -48,24 +48,42 @@ public class CheckFileHeaderUtil {
} }
public static String checkType(String type) { public static String checkType(String type) {
switch (type) {
//pptx两种文件头 if(type.contains("504B030414000600080000002100DFCC18F5AD010000460C0000130008025B436F6E74656E745F54797065735D") ||
case "504B030414000600080000002100DFCC18F5AD010000460C0000130008025B436F6E74656E745F54797065735D": return "pptx"; type.contains("504B0304140006000800000021002A489F7FB80100004A0D0000130008025B436F6E74656E745F54797065735D"))
case "504B0304140006000800000021002A489F7FB80100004A0D0000130008025B436F6E74656E745F54797065735D": return "pptx"; return "pptx";
//docx两种文件头
case "504B0304140006000800000021004ABC02716D01000028060000130008025B436F6E74656E745F54797065735D": return "docx"; if(type.contains("504B0304140006000800000021004ABC02716D01000028060000130008025B436F6E74656E745F54797065735D") ||
case "504B030414000600080000002100DFA4D26C5A01000020050000130008025B436F6E74656E745F54797065735D": return "docx"; type.contains("504B030414000600080000002100DFA4D26C5A01000020050000130008025B436F6E74656E745F54797065735D"))
return "docx";
case "D0CF11E0A1B11AE1000000000000000000000000000000003E000300FEFF090006000000000000000000000001": return "doc";
case "D0CF11E0A1B11AE1000000000000000000000000000000003E000300FEFF090006000000000000000000000003": return "ppt"; if(type.contains("D0CF11E0A1B11AE1000000000000000000000000000000003E000300FEFF090006000000000000000000000001"))
case "4944330300000000054054414C420000000100000054594552000000010000005452434B000000010000005443": return "mp3"; return "doc";
case "255044462D312E350D0A25B5B5B5B50D0A312030206F626A0D0A3C3C2F547970652F436174616C6F672F506167": return "pdf";
case "FFD8FFE000104A46494600010101004800480000FFDB0043000302020302020303030304030304050805050404": return "jpg"; if(type.contains("D0CF11E0A1B11AE1000000000000000000000000000000003E000300FEFF090006000000000000000000000003"))
case "89504E470D0A1A0A0000000D49484452000000EC000000880806000000E4B6075800000006624B474400FF00FF": return "png"; return "ppt";
case "000000206674797069736F6D0000020069736F6D69736F32617663316D70343100000008667265650014359C6D": return "mp4";
case "E783A6E783A6E783A6E783A6E783A6E783A6E783A6E783A6E783A6E783A6E783A6E783A6E783A6E783A6E783A6": return "txt"; if(type.contains("255044462D312E35"))
case "504B0304140000000800A473374F5424F3E6576D09003D5C0B0008000000746573742E6D703444597540144D1B": return "zip"; return "pdf";
default: return "other";
} if(type.contains("FFD8FFE000104A46"))
return "jpg";
if(type.contains("89504E470D0A1A0A"))
return "png";
if(type.contains("0000002066747"))
return "mp4";
if(type.contains("4944330300000"))
return "mp3";
if(type.contains("E783A6E783A6E783"))
return "txt";
if(type.contains("504B030414000000080"))
return "zip";
return "other";
} }
} }
\ 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