Commit 12bf4565 authored by zhangqingle's avatar zhangqingle

修改接口

parent 6b21b775
......@@ -307,14 +307,17 @@ public class BChapterServiceImpl implements BChapterService {
public String changeFile(BFile bFile){
String filePath = global.getBASE_UPLOAD_SERVER_LOCATION()+ File.separator +global.getCOURSE_LOCATION()+File.separator+bFile.getLessonId();
String returnBasePath = global.getRETURN_UPLOAD_SERVER_LOCATION()+File.separator+global.getCOURSE_LOCATION()+bFile.getLessonId();
String name = bFile.getVideoUrl().substring(bFile.getVideoUrl().lastIndexOf("/")+1);
String filePath = global.getBASE_UPLOAD_SERVER_LOCATION() +global.getCOURSE_LOCATION()+File.separator+bFile.getLessonId();
String returnBasePath = global.getRETURN_UPLOAD_SERVER_LOCATION()+global.getCOURSE_LOCATION()+ File.separator + bFile.getLessonId();
File file=new File(filePath);
//2. pdf 本地是否存在, word ppt 转换后的pdf是否存在
log.debug("------------------z1-----------------------------"+filePath);
File fileOld = new File(filePath + File.separator + bFile.getFileName());
File fileOld = new File(filePath + File.separator + name);
log.debug("------------------z2-----------------------------"+fileOld);
String newName = bFile.getFileName().substring(0, bFile.getFileName().indexOf(".")) + "-pdf.pdf";
String newName = name.substring(0, name.indexOf(".")) + "-pdf.pdf";
log.debug("------------------z3-----------------------------"+newName);
//转换后的路径
File fileNew = new File(filePath + File.separator + newName);
......@@ -323,7 +326,7 @@ public class BChapterServiceImpl implements BChapterService {
log.debug("------------------z5-----------------------------");
if (fileOld.exists()) {
log.debug("------------------z6-----------------------------"+fileOld);
return returnBasePath + File.separator + bFile.getFileName();
return returnBasePath + File.separator + name;
} else {
String downLoadName = downLoadFile(bFile, file, filePath);
log.debug("------------------z7-----------------------------"+downLoadName);
......@@ -332,30 +335,32 @@ public class BChapterServiceImpl implements BChapterService {
}
//3. pdf不存在,下载 , 删除word ppt,重新下载,转换
if ("2".equals(bFile.getType()) || "4".equals(bFile.getType())) {
log.debug("------------------z1-----------------------------");
log.debug("------------------z8-----------------------------");
if (fileNew.exists()) {
log.debug("------------------z1-----------------------------");
log.debug("------------------z9-----------------------------");
return returnBasePath + File.separator + newName;
} else {
log.debug("------------------z1-----------------------------");
log.debug("------------------z10-----------------------------");
fileOld.delete();
log.debug("------------------z1-----------------------------");
log.debug("------------------z11-----------------------------");
String downLoadFileUrl = downLoadFile(bFile, file, filePath);
log.debug("------------------z1-----------------------------");
int result = officeToPdf.transformToPdf(downLoadFileUrl, filePath + File.separator + newName);
log.debug("------------------z1-----------------------------");
log.debug("------------------z12-----------------------------downLoadFileUrl:"+filePath+ File.separator + downLoadFileUrl);
log.debug("------------------z12-----------------------------filePath:"+filePath + File.separator + newName);
int result = officeToPdf.transformToPdf(filePath+ File.separator + downLoadFileUrl, filePath + File.separator + newName);
log.debug("------------------z13-----------------------------");
if (result < 1) {
log.error("文件转换异常");
throw new ServiceException(ResultServiceEnums.CHANGE_FILE_ERROR);
}
//4. 更新在 bfile 表 , ppt和word 存一下转换之后的url filePath
if (StringUtils.isNotEmpty(bFile.getChapterId())){
log.debug("------------------z1-----------------------------");
log.debug("------------------z14-----------------------------");
bFile.setFileUrl(filePath+File.separator+newName);
log.debug("------------------z1-----------------------------");
log.debug("------------------z15-----------------------------");
bFileRepository.updateByPrimaryKeySelective(bFile);
}
log.debug("------------------z1-----------------------------");
log.debug("------------------z16-----------------------------");
return returnBasePath+File.separator+newName;
}
} else {
......@@ -366,6 +371,8 @@ public class BChapterServiceImpl implements BChapterService {
//下载
public String downLoadFile(BFile bFile, File file, String filePath) {
String name = bFile.getVideoUrl().substring(bFile.getVideoUrl().lastIndexOf("/")+1);
log.debug("------------------D1-----------------------------"+filePath);
//判断文件夹是否存在
if (!file.exists()) {
......@@ -403,7 +410,7 @@ public class BChapterServiceImpl implements BChapterService {
filePath += File.separator;
}
//写入到文件(注意文件保存路径的后面一定要加上文件的名称)
fileOut = new FileOutputStream(filePath + bFile.getFileName());
fileOut = new FileOutputStream(filePath + name);
log.debug("------------------D10-----------------------------");
BufferedOutputStream bos = new BufferedOutputStream(fileOut);
log.debug("------------------D11-----------------------------");
......@@ -422,8 +429,8 @@ public class BChapterServiceImpl implements BChapterService {
log.error(e.getMessage() + "下载文件异常");
throw new ServiceException(ResultServiceEnums.DOWNLOAD_ERROR);
}
log.debug("------------------D13-----------------------------"+bFile.getFileName());
return bFile.getFileName();
log.debug("------------------D13-----------------------------"+name);
return name;
}
@Override
......
......@@ -35,7 +35,7 @@ public interface BViewrangeRepository extends BaseMapper<BViewrange> {
" <if test='delFlag != null'>del_flag=#{delFlag},</if> ",
" <if test='flag != null'>flag=#{flag},</if> ",
" <if test='remarks != null'>remarks=#{remarks},</if> ",
" <if test='lesson_id != null'>lesson_id=#{lessonId},</if> ",
" <if test='lessonId != null'>lesson_id=#{lessonId},</if> ",
" <if test='type != null'>type=#{type},</if> ",
" <if test='corp_id != null'>corp_id=#{corp_id},</if> ",
" </set>",
......
......@@ -90,19 +90,23 @@ public class OfficeToPdf {
if (!inputFile.exists()) {
return -1;// 找不到源文件, 则返回-1
}
log.debug("----------ZH------------");
// 如果目标路径不存在, 则新建该路径
File outputFile = new File(destFile);
if (!outputFile.getParentFile().exists()) {
outputFile.getParentFile().mkdirs();
}
log.debug("----------ZH------------");
// connect to an OpenOffice.org instance running on port 8100
connection = new SocketOpenOfficeConnection(
global.getLibreofficeIp(), global.getLibreofficePort());
connection.connect();
// convert
log.debug("----------ZH------------");
DocumentConverter converter = new OpenOfficeDocumentConverter(
connection);
DocumentFormatRegistry factory = new BasicDocumentFormatRegistry();
log.debug("----------ZH------------");
DocumentFormat inputDocumentFormat = factory
.getFormatByFileExtension(FileUtil.getFilePostfix(sourceFile));
DocumentFormat outputDocumentFormat = factory
......@@ -120,7 +124,7 @@ public class OfficeToPdf {
if(connection!=null) {
connection.disconnect();
}else{
throw new ServiceException(ResultServiceEnums.UPLOAD_ERROR);
throw new ServiceException(ResultServiceEnums.CHANGE_FILE_ERROR);
}
}
return 1;
......
......@@ -74,7 +74,7 @@ global:
licPath: /lk/license.lic
pubPath: /lk/publicCerts.store
path:
base_upload_server_location: /working/resource/eduServer/
base_upload_server_location: /working/eduServer/
return_upload_server_location: http://192.168.5.201:18080/eduServer/
course_location: course
lesson_location: lesson
......@@ -93,7 +93,7 @@ global:
cut_pdf_num: 30
libreoffice:
ip: mt_office
ip: mt_libre
port: 8997
mt:
api: http://192.168.5.201/api/
......
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