Commit 32c90bb5 authored by luzhuang's avatar luzhuang

mp3、mp4

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