Commit cbbe86bc authored by luzhuang's avatar luzhuang

Merge remote-tracking branch 'origin/meiteng' into meiteng

# Conflicts:
#	src/main/java/org/rcisoft/core/util/FileReadableUtil.java
parents a0f512f7 83fd69fa
...@@ -39,6 +39,7 @@ import org.rcisoft.core.result.ResultServiceEnums; ...@@ -39,6 +39,7 @@ import org.rcisoft.core.result.ResultServiceEnums;
import org.rcisoft.core.util.*; import org.rcisoft.core.util.*;
import org.rcisoft.sys.user.bean.CurUser; import org.rcisoft.sys.user.bean.CurUser;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -90,6 +91,14 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -90,6 +91,14 @@ public class BChapterServiceImpl implements BChapterService {
@Autowired @Autowired
BLessonServiceImpl bLessonServiceImpl; BLessonServiceImpl bLessonServiceImpl;
@Value("${upload.fileMaxSize:100}")
private Long fileMaxSize;
@Value("${upload.fileMaxPages:100}")
private Integer fileMaxPages;
@Override @Override
public BChapter selectOne(String businessId) { public BChapter selectOne(String businessId) {
BChapter result = bChapterRepository.selectByPrimaryKey(businessId); BChapter result = bChapterRepository.selectByPrimaryKey(businessId);
...@@ -636,7 +645,7 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -636,7 +645,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); FileReadableUtil.fileReadable(filePath + File.separator + downLoadName,fileMaxSize,fileMaxPages);
} }
return flag; return flag;
} }
...@@ -686,7 +695,7 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -686,7 +695,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); FileReadableUtil.fileReadable(filePath + File.separator + downLoadName,fileMaxSize,fileMaxPages);
LogUtil.fileChangeLog("------------------返回下载后路径-----------------------------" + downLoadName); LogUtil.fileChangeLog("------------------返回下载后路径-----------------------------" + downLoadName);
return returnBasePath + File.separator + downLoadName; return returnBasePath + File.separator + downLoadName;
} }
...@@ -705,7 +714,7 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -705,7 +714,7 @@ public class BChapterServiceImpl implements BChapterService {
//判断文件是否可读 //判断文件是否可读
LogUtil.fileChangeLog("------------------判断文件是否可读-----------------------------" + filePath + File.separator + name); LogUtil.fileChangeLog("------------------判断文件是否可读-----------------------------" + filePath + File.separator + name);
FileReadableUtil.fileReadable(filePath + File.separator + downLoadFileName); 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);
......
...@@ -257,6 +257,10 @@ public class BLesson extends IdEntity<BLesson> { ...@@ -257,6 +257,10 @@ public class BLesson extends IdEntity<BLesson> {
@Transient @Transient
private String lecturerDeptName; private String lecturerDeptName;
@ApiModelProperty(value = "讲师头像")
@Transient
private String lecturerPic;
@ApiModelProperty(value = "登录人是否为讲师0 不是 1 是") @ApiModelProperty(value = "登录人是否为讲师0 不是 1 是")
@Transient @Transient
private String userIsLecturer; private String userIsLecturer;
......
...@@ -1313,6 +1313,7 @@ public class BLessonServiceImpl implements BLessonService { ...@@ -1313,6 +1313,7 @@ public class BLessonServiceImpl implements BLessonService {
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());
bLesson.setLecturerPic(mtUserInfoRspDTO.getAvatar());
} }
}); });
} }
......
...@@ -253,6 +253,8 @@ public enum ResultServiceEnums { ...@@ -253,6 +253,8 @@ public enum ResultServiceEnums {
TRAIN_SIGNED(153,"您已签到,请勿重复签到"), TRAIN_SIGNED(153,"您已签到,请勿重复签到"),
FILE_UNREADABLE(154,"该文件无法识别,可能已加密或损坏,请修正当前文件或上传其他文件"), FILE_UNREADABLE(154,"该文件无法识别,可能已加密或损坏,请修正当前文件或上传其他文件"),
DUP_FILE(155,"文件重复"), DUP_FILE(155,"文件重复"),
FILE_OVER_SIZE(156,"文件超过规定大小"),
FILE_OVER_PAGES(157,"文件页数超过规定个数"),
; ;
private Integer code; private Integer code;
......
...@@ -2,67 +2,77 @@ package org.rcisoft.core.util; ...@@ -2,67 +2,77 @@ package org.rcisoft.core.util;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.pdfbox.io.RandomAccessBuffer; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.poi.POIXMLDocument; import org.apache.poi.POIXMLDocument;
import org.apache.poi.hslf.usermodel.HSLFSlideShow; import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.hwpf.extractor.WordExtractor; import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.rcisoft.core.exception.ServiceException; import org.rcisoft.core.exception.ServiceException;
import org.rcisoft.core.result.ResultServiceEnums; import org.rcisoft.core.result.ResultServiceEnums;
import java.io.*; import java.io.*;
@Slf4j @Slf4j
public class FileReadableUtil { public class FileReadableUtil {
public static void main(String[] args) { public static void main(String[] args) {
String filePath = "F:\\桌面整理\\文件归纳\\测试资料\\05.pdf"; String filePath = "C:\\Users\\三\\Desktop\\素材\\加密-pdf.pdf";
fileReadable(filePath); fileReadable(filePath,(long)100,100);
} }
public static void fileReadable(String path) { public static void fileReadable(String path,Long fileMaxSize,Integer fileMaxPages) {
LogUtil.fileChangeLog("-----------FileReadableUtil-路径------------"+path); LogUtil.fileChangeLog("-----------FileReadableUtil-路径------------"+path);
File file = new File(path); File file = new File(path);
InputStream is = null; InputStream is = null;
HSLFSlideShow slideShow = null; HSLFSlideShow slideShow = null;
WordExtractor ex = null; // RandomAccessBuffer randomAccessBuffer = null;
RandomAccessBuffer randomAccessBuffer = null; PDDocument doc = null;
OPCPackage opcPackage = null; OPCPackage opcPackage = null;
Long size = file.length();
if (size > (long)(1024 * 1024 * fileMaxSize)){
throw new ServiceException(ResultServiceEnums.FILE_OVER_SIZE);
}
int pages = -1;
try { try {
if (path.endsWith(".doc")) { if (path.endsWith(".doc")) {
is = new FileInputStream(new File(path)); is = new FileInputStream(new File(path));
ex = new WordExtractor(is); WordExtractor ex = new WordExtractor(is);
pages = ex.getSummaryInformation().getPageCount();//总页数
}else if (path.endsWith("ppt")) { }else if (path.endsWith("ppt")) {
is =new FileInputStream(file); is =new FileInputStream(file);
slideShow = new HSLFSlideShow(is); slideShow = new HSLFSlideShow(is);
pages = slideShow.getSlides().size();
} else if (path.endsWith("pdf")) { } else if (path.endsWith("pdf")) {
is = new FileInputStream(file); doc = PDDocument.load(file);
randomAccessBuffer = new RandomAccessBuffer(is); pages = doc.getDocumentCatalog().getPages().getCount();
PDFParser parser = new PDFParser(randomAccessBuffer); }else if (path.endsWith("docx")) {
parser.parse(); opcPackage = POIXMLDocument.openPackage(path);
}else if (path.endsWith("docx") || path.endsWith("pptx")) { XWPFDocument docx = new XWPFDocument(opcPackage);
pages = docx.getProperties().getExtendedProperties().getUnderlyingProperties().getPages();
}else if (path.endsWith("pptx")){
opcPackage = POIXMLDocument.openPackage(path); opcPackage = POIXMLDocument.openPackage(path);
XMLSlideShow pptxfile = new XMLSlideShow(opcPackage);
pages = pptxfile.getSlides().size();
} }
} catch (Exception e) { } catch (Exception e) {
log.error("文件不可读---"+e); log.error("文件不可读---"+e);
throw new ServiceException(ResultServiceEnums.FILE_UNREADABLE); throw new ServiceException(ResultServiceEnums.FILE_UNREADABLE);
}finally { }finally {
}
try{
if(ex != null){
ex.close();
}
}catch(Exception e){
log.error("关闭 WordExtractor 输出流错误!", e);
}
try{ try{
if(randomAccessBuffer != null){ if(doc != null){
randomAccessBuffer.close(); doc.close();
} }
}catch(Exception e){ }catch(Exception e){
log.error("关闭 RandomAccessBuffer 输出流错误!", e); log.error("关闭 PDDocument 输出流错误!", e);
} }
try{ try{
if(opcPackage != null){ if(opcPackage != null){
opcPackage.close(); opcPackage.close();
...@@ -84,6 +94,10 @@ public class FileReadableUtil { ...@@ -84,6 +94,10 @@ public class FileReadableUtil {
}catch(Exception e){ }catch(Exception e){
log.error("关闭 InputStream 输出流错误!", e); log.error("关闭 InputStream 输出流错误!", e);
} }
}
if (pages != -1 && pages > fileMaxPages) {
throw new ServiceException(ResultServiceEnums.FILE_OVER_PAGES);
}
if (!CheckFileHeaderUtil.toCheck(path)){ if (!CheckFileHeaderUtil.toCheck(path)){
......
...@@ -130,3 +130,8 @@ notice: ...@@ -130,3 +130,8 @@ notice:
appId: appId:
globalAppId: 1 globalAppId: 1
noticeAppId: 9 noticeAppId: 9
upload:
fileMaxSize: 100
fileMaxPages: 100
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