Commit f4fc0d1b authored by zhangqingle's avatar zhangqingle

增加培训文件可读验证,增加收藏时间

parent eb47ad80
......@@ -154,6 +154,18 @@ public class BChapterController extends PaginationController<BChapter> {
newFileUrl);
}
@ApiOperation(value = "209 判断文件是否可读", notes = "判断文件是否可读(培训 需要预览的附件)")
@GetMapping("/fileReadable")
public Result fileReadable(CurUser curUser, @Valid BFile file, BindingResult br) throws IOException {
String res = bChapterService.fileReadable(file);
return Result.builder(new PersistModel(1),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
res);
}
// @ApiOperation(value = "209 查询章节带进度(外部分享)", notes = "查询章节带进度(外部分享)", response = QueryChapterListResDTO.class)
// @GetMapping(value = "/queryShareBChaptersWithProgress")
// public Result queryShareBChaptersWithProgress(CurUser curUser, @RequestParam String lessonId, BindingResult br) {
......
......@@ -7,6 +7,7 @@ public enum FileTypeEnum {
PPT("2"),
PDF("3"),
WORD("4"),
TXT("6"),
;
FileTypeEnum(String code) {
......
......@@ -104,6 +104,13 @@ public interface BChapterService{
*/
String getDownLoadUrl(BFile bFile);
/**
* 判断文件是否
* @param bFile
* @return
*/
String fileReadable(BFile bFile);
/**
* 打分
* @param scoreInfoDTOS
......
......@@ -625,6 +625,25 @@ public class BChapterServiceImpl implements BChapterService {
}
}
@Override
public String fileReadable(BFile bFile) {
String flag = "1";
String name = bFile.getVideoUrl().substring(bFile.getVideoUrl().lastIndexOf("/") + 1);
String filePath = global.getBASE_UPLOAD_SERVER_LOCATION() + global.getCOURSE_LOCATION() + File.separator + "temp";
File file = new File(filePath);
File fileOld = new File(filePath + File.separator + name);
if (fileOld.exists()) {
LogUtil.fileChangeLog("------------------文件名重复-------------------------" + fileOld);
throw new ServiceException(ResultServiceEnums.DUP_FILE);
} else {
LogUtil.fileChangeLog("------------------下载-------------------------" + fileOld);
String downLoadName = downLoadFile(bFile, file, filePath);
LogUtil.fileChangeLog("------------------判断可读-------------------------" + fileOld);
FileReadableUtil.fileReadable(filePath + File.separator + downLoadName);
}
return flag;
}
public String changeFile(BFile bFile) {
LogUtil.fileChangeLog("****************request + begin***********" + DateFormatUtils.format(new Date(), "HH:mm:ss"));
......@@ -654,8 +673,8 @@ public class BChapterServiceImpl implements BChapterService {
}
}
//3. pdf不存在,下载 , 删除word ppt,重新下载,转换
if (FileTypeEnum.PPT.getCode().equals(bFile.getType()) || FileTypeEnum.WORD.getCode().equals(bFile.getType())) {
LogUtil.fileChangeLog("------------------文件为ppt或word----------------------------");
if (FileTypeEnum.PPT.getCode().equals(bFile.getType()) || FileTypeEnum.WORD.getCode().equals(bFile.getType()) || FileTypeEnum.TXT.getCode().equals(bFile.getType())) {
LogUtil.fileChangeLog("------------------文件为ppt或word或txt----------------------------");
if (fileNew.exists()) {
LogUtil.fileChangeLog("------------------转换后文件存在直接返回-----------------------------");
return returnBasePath + File.separator + newName;
......@@ -663,15 +682,14 @@ public class BChapterServiceImpl implements BChapterService {
LogUtil.fileChangeLog("------------------删除老文件----------------------------");
fileOld.delete();
LogUtil.fileChangeLog("------------------设置下载路径----------------------------");
String downLoadFileUrl = downLoadFile(bFile, file, filePath);
String downLoadFileName = downLoadFile(bFile, file, filePath);
//判断文件是否可读
LogUtil.fileChangeLog("------------------判断文件是否可读-----------------------------" + filePath + File.separator + name);
FileReadableUtil.fileReadable(filePath + File.separator + downLoadFileUrl);
LogUtil.fileChangeLog("-----------------------------------------------downLoadFileUrl:" + filePath + File.separator + downLoadFileUrl);
FileReadableUtil.fileReadable(filePath + File.separator + downLoadFileName);
LogUtil.fileChangeLog("-----------------------------------------------downLoadFileUrl:" + filePath + File.separator + downLoadFileName);
LogUtil.fileChangeLog("-----------------------------------------------filePath:" + filePath + File.separator + newName);
int result = officeToPdf.transformToPdf(filePath + File.separator + downLoadFileUrl, filePath + File.separator + newName);
int result = officeToPdf.transformToPdf(filePath + File.separator + downLoadFileName, filePath + File.separator + newName);
LogUtil.fileChangeLog("------------------转换完毕-----------------------------");
if (result < 1) {
log.error("文件转换异常");
......
......@@ -122,19 +122,18 @@ public class BDiscussServiceImpl implements BDiscussService {
}
if (StringUtils.isBlank(bDiscuss.getLevel()) && "1".equals(bDiscuss.getLevel()) && "1".equals(messageFBPL.getFlag())){
try {
BNotice bNotice = new BNotice();
bNotice.setInfoType(InfoTypeEnum.REPLY_DISCUSS.getValue());
bNotice.setLessonId(bDiscuss.getLessonId());
bNotice.setSenderId(curUser.getUserId());
bNotice.setCorpId(curUser.getCorpId());
// 获取课程信息
BLesson bLesson = lessonRepository.selectByPrimaryKey(bDiscuss.getLessonId());
bNotice.setRecipientIds(new ArrayList<>(Arrays.asList(bLesson.getLecturerId())));
String lessonType = LessonTypeEnum.LESSON.getCode().equals(bLesson.getLessonType()) ? "线上课程" : "线下培训";
String urlType = LessonTypeEnum.LESSON.getCode().equals(bLesson.getLessonType()) ? UrlTypeEnum.LESSON.getName() : UrlTypeEnum.TRAIN.getName();
bNotice.setInfoText(sysUserServiceImpl.getNameById(bDiscuss.getStudentId()).getName() + "评论了您主讲的" + lessonType +"\"" + bLesson.getLessonName()+"\"" );
// 发消息
BNotice bNotice = new BNotice();
bNotice.setInfoType(InfoTypeEnum.REPLY_DISCUSS.getValue());
bNotice.setLessonId(bDiscuss.getLessonId());
bNotice.setSenderId(curUser.getUserId());
bNotice.setCorpId(curUser.getCorpId());
// 获取课程信息
BLesson bLesson = lessonRepository.selectByPrimaryKey(bDiscuss.getLessonId());
bNotice.setRecipientIds(new ArrayList<>(Arrays.asList(bLesson.getLecturerId())));
String lessonType = LessonTypeEnum.LESSON.getCode().equals(bLesson.getLessonType()) ? "线上课程" : "线下培训";
String urlType = LessonTypeEnum.LESSON.getCode().equals(bLesson.getLessonType()) ? UrlTypeEnum.LESSON.getName() : UrlTypeEnum.TRAIN.getName();
bNotice.setInfoText(sysUserServiceImpl.getNameById(bDiscuss.getStudentId()).getName() + "评论了您主讲的" + lessonType +"\"" + bLesson.getLessonName()+"\"" );
// 发消息
client.send(bNotice,InfoTypeEnum.REPLY_DISCUSS.getLable(), MessageEnum.FBPL.getName(),urlType);
}catch (Exception e){
log.info("发送通知失败,"+e);
......
......@@ -1120,7 +1120,9 @@ public interface BLessonRepository extends BaseMapper<BLesson> {
"and bl.del_flag = 0 and bl.flag = 1 " +
"and bl.corp_id = #{curUser.corpId} " +
" <if test=\"lessonType!=null and lessonType != ''\">and bl.lesson_type = #{lessonType}</if>" +
"AND bc.person_id = #{curUser.userId} </script>")
" AND bc.person_id = #{curUser.userId} " +
" order by bc.collect_date desc " +
" </script>")
@ResultMap(value = "BaseResultMap")
List<BLesson> selectMyCollect(@Param("lessonType") String lessonType, @Param("curUser")CurUser curUser);
......
......@@ -28,6 +28,6 @@ public class BCollect{
private String lessonId;
private Date collectDate;
}
......@@ -1146,6 +1146,7 @@ public class BLessonServiceImpl implements BLessonService {
BCollect bCollect = new BCollect();
bCollect.setLessonId(lessonId);
bCollect.setPersonId(curUser.getUserId());
bCollect.setCollectDate(new Date());
int line = bCollectRepository.insertSelective(bCollect);
//重新统计课程收藏数
bLessonRepository.collectNumberReCount(lessonId);
......@@ -1257,11 +1258,7 @@ public class BLessonServiceImpl implements BLessonService {
if (one.size() > 0) {
return new PersistModel(1);
}
BCollect bCollect = new BCollect();
bCollect.setBusinessId(IdGen.uuid());
bCollect.setLessonId(lessonId);
bCollect.setPersonId(curUser.getUserId());
BCollect bCollect = new BCollect(IdGen.uuid(),curUser.getUserId(),lessonId,new Date());
int line = bCollectRepository.insert(bCollect);
//更新课程表收藏个数
bLessonRepository.collectNumberReCount(lessonId);
......@@ -1392,7 +1389,27 @@ public class BLessonServiceImpl implements BLessonService {
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public List<BLesson> queryCollectByPagination(PageUtil pageUtil, String lessonType, CurUser curUser) {
return bLessonRepository.selectMyCollect(lessonType, curUser);
List<BLesson> bLessonList = bLessonRepository.selectMyCollect(lessonType, curUser);
Date now = new Date();
if (LessonTypeEnum.TRAIN.getCode().equals(lessonType)){
bLessonList.forEach(bLesson -> {
setDateState(bLesson);
if (bLesson.getTrainStartDate() == null || bLesson.getTrainOverDate() == null || bLesson.getTrainSignTime() == null) {
return;
}
Long time = Long.parseLong(bLesson.getTrainSignTime()) * 60 * 1000;
Date signStart = new Date(bLesson.getTrainStartDate().getTime() - time);
if (now.before(signStart)) {
bLesson.setTrainType("0");
} else if (bLesson.getTrainOverDate().before(now)) {
bLesson.setTrainType("2");
} else {
bLesson.setTrainType("1");
}
});
}
return bLessonList;
}
@Override
......
......@@ -252,6 +252,7 @@ public enum ResultServiceEnums {
VALUE_NOT_NULL(152,"积分不能为空"),
TRAIN_SIGNED(153,"您已签到,请勿重复签到"),
FILE_UNREADABLE(154,"该文件无法识别,可能已加密或损坏,请修正当前文件或上传其他文件"),
DUP_FILE(155,"文件重复"),
;
private Integer code;
......
package org.rcisoft.core.util;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.pdfbox.io.RandomAccessBuffer;
import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.poi.POIXMLDocument;
......@@ -10,9 +11,7 @@ import org.apache.poi.openxml4j.opc.OPCPackage;
import org.rcisoft.core.exception.ServiceException;
import org.rcisoft.core.result.ResultServiceEnums;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.*;
@Slf4j
public class FileReadableUtil {
......@@ -49,12 +48,6 @@ public class FileReadableUtil {
log.error("文件不可读---"+e);
throw new ServiceException(ResultServiceEnums.FILE_UNREADABLE);
}finally {
try{
if(is != null){
is.close();
}
}catch(Exception e){
log.error("关闭 InputStream 输出流错误!", e);
}
try{
if(ex != null){
......@@ -84,8 +77,42 @@ public class FileReadableUtil {
}catch(Exception e){
log.error("关闭 HSLFSlideShow 输出流错误!", e);
}
}
try{
if(is != null){
is.close();
}
}catch(Exception e){
log.error("关闭 InputStream 输出流错误!", e);
}
}
public File TXTHandler(File file) {
//或GBK
String code = "gb2312";
byte[] head = new byte[3];
try {
InputStream inputStream = new FileInputStream(file);
inputStream.read(head);
if (head[0] == -1 && head[1] == -2) {
code = "UTF-16";
} else if (head[0] == -2 && head[1] == -1) {
code = "Unicode";
} else if (head[0] == -17 && head[1] == -69 && head[2] == -65) {
code = "UTF-8";
}
inputStream.close();
System.out.println(code);
if (code.equals("UTF-8")) {
return file;
}
String str = FileUtils.readFileToString(file, code);
FileUtils.writeStringToFile(file, str, "UTF-8");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return file;
}
}
......@@ -131,6 +131,13 @@ public class OfficeToPdf {
if (!inputFile.exists()) {
return -1;// 找不到源文件, 则返回-1
}
//若为txt 设置txt编码集
if (sourceFile.substring(sourceFile.lastIndexOf(".")).equalsIgnoreCase(".txt")) {
LogUtil.fileChangeLog("------------------设置txt编码集-----------------------------");
new FileReadableUtil().TXTHandler(inputFile);
}
LogUtil.fileChangeLog("----------如果目标路径不存在, 则新建该路径------------");
// 如果目标路径不存在, 则新建该路径
File outputFile = new File(destFile);
......
......@@ -3,13 +3,7 @@
<mapper namespace="org.rcisoft.business.blesson.dao.BCollectRepository">
<resultMap id="BaseResultMap" type="org.rcisoft.business.blesson.entity.BCollect">
<id column="business_id" jdbcType="VARCHAR" property="businessId"/>
<result column="create_by" jdbcType="VARCHAR" property="createBy"/>
<result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
<result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
<result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
<result column="del_flag" jdbcType="VARCHAR" property="delFlag"/>
<result column="flag" jdbcType="VARCHAR" property="flag"/>
<result column="remarks" jdbcType="VARCHAR" property="remarks"/>
<result column="collect_date" jdbcType="TIMESTAMP" property="collectDate"/>
<result column="person_id" jdbcType="VARCHAR" property="personId"/>
<result column="lesson_id" jdbcType="VARCHAR" property="lessonId"/>
</resultMap>
......
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