Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
education
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李丛阳
education
Commits
9a1d1453
Commit
9a1d1453
authored
Sep 20, 2019
by
root
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复端口异常
parent
c3941d9a
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
192 additions
and
29 deletions
+192
-29
BFileServiceImpl.java
...rcisoft/business/bfile/service/impl/BFileServiceImpl.java
+1
-1
BLessonController.java
...cisoft/business/blesson/controller/BLessonController.java
+13
-12
BLesson.java
...ain/java/org/rcisoft/business/blesson/entity/BLesson.java
+6
-6
BLessonPersonController.java
...ess/blessonperson/controller/BLessonPersonController.java
+7
-3
SlTask.java
src/main/java/org/rcisoft/business/bsl/task/SlTask.java
+7
-0
UserController.java
...in/java/org/rcisoft/common/controller/UserController.java
+25
-7
MessageConstant.java
src/main/java/org/rcisoft/core/constant/MessageConstant.java
+3
-0
OfficeToPdf.java
src/main/java/org/rcisoft/core/util/OfficeToPdf.java
+130
-0
No files found.
src/main/java/org/rcisoft/business/bfile/service/impl/BFileServiceImpl.java
View file @
9a1d1453
package
org
.
rcisoft
.
business
.
bfile
.
service
.
impl
;
import
com.itextpdf.text.pdf.PdfReader
;
import
org.apache.commons.io.FileUtils
;
import
org.rcisoft.business.bfile.dao.BFileRepository
;
import
org.rcisoft.business.bfile.entity.BFile
;
import
org.rcisoft.business.bfile.service.BFileService
;
import
org.rcisoft.business.bsl.task.SlTask
;
import
org.rcisoft.common.component.Global
;
import
org.rcisoft.core.aop.PageUtil
;
import
org.rcisoft.core.bean.RcLkConfigBean
;
import
org.rcisoft.core.constant.DelStatus
;
import
org.rcisoft.core.exception.ServiceException
;
import
org.rcisoft.core.model.PersistModel
;
import
org.rcisoft.core.result.ResultServiceEnums
;
import
org.rcisoft.core.util.FileUtil
;
import
org.rcisoft.core.util.IdGen
;
import
org.rcisoft.core.util.UserUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.*
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
static
org
.
rcisoft
.
core
.
util
.
CutPdfUtil
.
partitionPdfFile
;
/** * Created by gaowenfneg on 2017-10-9 14:34:56. */
@Service
@Transactional
(
readOnly
=
true
,
propagation
=
Propagation
.
NOT_SUPPORTED
)
public
class
BFileServiceImpl
implements
BFileService
{
@Autowired
private
BFileRepository
bFileRepository
;
@Autowired
private
SlTask
slTask
;
@Autowired
private
Global
global
;
@Autowired
private
RcLkConfigBean
rcLkConfigBean
;
@Override
public
BFile
selectOne
(
String
businessId
){
return
bFileRepository
.
selectByPrimaryKey
(
businessId
);
}
@Override
public
List
<
BFile
>
queryBVideosByPagination
(
PageUtil
pageUtil
,
BFile
model
)
{
Map
param
=
new
HashMap
<
String
,
Object
>();
return
bFileRepository
.
queryBVideos
(
param
);
}
@Override
public
List
<
BFile
>
queryBVideos
(
BFile
model
)
{
Map
param
=
new
HashMap
<
String
,
Object
>();
return
bFileRepository
.
queryBVideos
(
param
);
}
@Override
public
PersistModel
persist
(
BFile
model
){
UserUtil
.
setCurrentPersistOperation
(
model
);
int
line
=
bFileRepository
.
insertSelective
(
model
);
return
new
PersistModel
(
line
);
}
@Override
public
PersistModel
removeBVideo
(
String
id
)
{
BFile
bFile
=
bFileRepository
.
selectByPrimaryKey
(
id
);
bFile
.
setDelFlag
(
DelStatus
.
DELETED
.
getStatus
());
UserUtil
.
setCurrentMergeOperation
(
bFile
);
int
line
=
bFileRepository
.
updateByPrimaryKeySelective
(
bFile
);
return
new
PersistModel
(
line
);
}
@Override
@Transactional
(
propagation
=
Propagation
.
REQUIRED
,
readOnly
=
false
)
public
String
uploadVideoToServer
(
List
<
MultipartFile
>
list
,
BFile
bFile
)
{
String
videoUrl
=
""
;
if
(
list
.
size
()>
0
)
{
for
(
int
i
=
0
;
i
<
list
.
size
();
++
i
)
{
MultipartFile
file
=
list
.
get
(
i
);
try
{
//查询此节是否已有视频或文件 BFile video = bFileRepository.selectInfoByChapterId(bFile.getChapterId()); if (video!=null){//此节已有视频或文件,将已有的视频或文件放置到temp目录下,然后上传新视频或文件 if(bFile.getType().equals("0")&&video.getVideoUrl()!=null&&!video.getVideoUrl().equals("")){ this.removeVideoToTemp(bFile);//复制之前视频到temp文件下 } if(bFile.getType().equals("1")&&video.getFileUrl()!=null&&!video.getFileUrl().equals("")){ this.removeVideoToTemp(bFile);//复制之前文件到temp文件下 } if(bFile.getType().equals("2")&&video.getPptUrl()!=null&&!video.getPptUrl().equals("")){ this.removeVideoToTemp(bFile);//复制之前ppt到temp文件下 } if(bFile.getType().equals("3")&&video.getPdfUrl()!=null&&!video.getPdfUrl().equals("")){ this.removeVideoToTemp(bFile);//复制之前pdf到temp文件下 } BFile newVideo = this.uploadVideo(file, bFile);//上传新文件 newVideo.setBusinessId(video.getBusinessId()); UserUtil.setCurrentMergeOperation(newVideo); bFileRepository.updateByPrimaryKeySelective(newVideo);//更新表中信息 if (bFile.getType().equals("0")){ videoUrl = newVideo.getVideoUrl(); }else if(bFile.getType().equals("1")){ videoUrl = newVideo.getFileUrl(); }else if(bFile.getType().equals("2")){ videoUrl = newVideo.getPptUrl(); }else{ videoUrl = newVideo.getPdfUrl(); } }else{ BFile newVideo = this.uploadVideo(file, bFile);//上传文件 this.persist(newVideo);//插入表信息 if (bFile.getType().equals("0")){ videoUrl = newVideo.getVideoUrl(); }else if(bFile.getType().equals("1")){ videoUrl = newVideo.getFileUrl(); }else if(bFile.getType().equals("2")){ videoUrl = newVideo.getPptUrl(); }else{ videoUrl = newVideo.getPdfUrl(); } } } catch (Exception e) { e.printStackTrace(); throw new ServiceException(ResultServiceEnums.UPLOAD_ERROR); } } } return videoUrl; } /** * 将原视频复制到temp/video文件下,并删除原视频 * @param bFile */ private void removeVideoToTemp(BFile bFile) throws Exception{ String path; String pathName; if(bFile.getLessonId()!=null&&!bFile.getLessonId().equals("")){ path = global.getLESSON_LOCATION() + File.separator + bFile.getLessonId() + File.separator; }else{ path = global.getSL_LOCATION() + File.separator + bFile.getSlId() + File.separator; } if (bFile.getType().equals("0")){ pathName = global.getVIDEO_LOCATION();//视频路径 }else if(bFile.getType().equals("1")){ pathName = global.getFILE_LOCATION();//文件路径 }else if(bFile.getType().equals("2")){ pathName = global.getPPT_LOCATION();//ppt路径 }else{ pathName = global.getPDF_LOCATION();//pdf路径 } String tempPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + global.getCOURSE_LOCATION() + File.separator + global.getTEMP_LOCATION() + File.separator + path + bFile.getChapterId(); File tempFilePath = new File(tempPath); if(tempFilePath.exists()){ FileUtils.deleteDirectory(tempFilePath); } String realFilePath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + global.getCOURSE_LOCATION() + File.separator + path + bFile.getChapterId() + File.separator + pathName; File directory = new File(realFilePath); if(directory.exists()){ FileUtils.moveDirectory(directory,tempFilePath); } } /** * 上传视频到video目录 * @param file * @param bFile * @return * @throws IOException */ private BFile uploadVideo(MultipartFile file, BFile bFile) throws IOException { BufferedOutputStream stream = null; String path; String pathName; if(bFile.getLessonId()!=null&&!bFile.getLessonId().equals("")){ path = global.getLESSON_LOCATION() + File.separator + bFile.getLessonId() + File.separator; }else{ path = global.getSL_LOCATION() + File.separator + bFile.getSlId() + File.separator; } if (bFile.getType().equals("0")){ pathName = global.getVIDEO_LOCATION();//视频路径 }else if(bFile.getType().equals("1")){ pathName = global.getFILE_LOCATION();//文件路径 }else if(bFile.getType().equals("2")){ pathName = global.getPPT_LOCATION();//ppt路径 }else{ pathName = global.getPDF_LOCATION();//pdf路径 } String realPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + global.getCOURSE_LOCATION() + File.separator + path + bFile.getChapterId() + File.separator + pathName + File.separator; File outFile=new File(realPath); if(!outFile.exists()){//判断保存路径是否存在,不存在新建 outFile.mkdirs(); } //上传文件 String uploadFile = file.getOriginalFilename(); //文件的真实名称 String name = uploadFile.substring(uploadFile.lastIndexOf(File.separator) + 1,uploadFile.lastIndexOf('.')); // 截取上传文件的后缀 String uploadFileSuffix = FileUtil.getFilePostfix(uploadFile); //uploadFile.substring(uploadFile.lastIndexOf('.') + 1, uploadFile.length()); // 设置文件名为乱码 String uploadFileName = IdGen.uuid(); String filename = uploadFileName + "." + uploadFileSuffix; stream = new BufferedOutputStream(new FileOutputStream(new File(realPath + filename))); byte[] bytes = file.getBytes(); stream.write(bytes,0,bytes.length); String newPath = global.getCOURSE_LOCATION() + File.separator + path + bFile.getChapterId() + File.separator + pathName + File.separator; if(uploadFileSuffix.equals("ppt")&&bFile.getType().equals("2")){//ppt转pdf String inputFile = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + newPath+ filename; String outputFile = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + newPath + uploadFileName + ".pdf"; // slTask.officeToPdf(inputFile,outputFile); } if(uploadFileSuffix.equals("pdf")&&bFile.getType().equals("3")){//pdf切割 try { slTask.cutPdf(newPath, filename, uploadFileName); } catch (Exception e) { e.printStackTrace(); } } //上传的是文件时才存文件名,方便下载时取 if(bFile.getType().equals("1")){ bFile.setVideoName(name+ "." +uploadFileSuffix);//文件名 } if (bFile.getType().equals("0")){ bFile.setVideoUrl(newPath+ filename);//视频路径 }else if(bFile.getType().equals("1")){ bFile.setFileUrl(newPath+ filename);//文件路径 }else if(bFile.getType().equals("2")){ bFile.setPptUrl(newPath + uploadFileName + ".pdf");//ppt路径 }else{ bFile.setPdfUrl(newPath+ filename);//pdf路径 } stream.close(); return bFile; } @Override public BFile queryFileUrlByChapterId(String chapterId) { return bFileRepository.queryFileUrlByChapterId(chapterId); } @Override public void uploadLicense(MultipartFile file) { try { BufferedOutputStream stream = null; String path = global.getBASE_UPLOAD_SERVER_LOCATION() + rcLkConfigBean.getLicPath(); File oldFile = new File(path); if(oldFile.exists()){ FileUtils.forceDelete(oldFile); } File newFile = new File(path); stream = new BufferedOutputStream(new FileOutputStream(newFile)); byte[] bytes = file.getBytes(); stream.write(bytes,0,bytes.length); stream.flush(); stream.close(); } catch (Exception e) { e.printStackTrace(); throw new ServiceException(ResultServiceEnums.UPLOAD_ERROR); } return; } /** * 重新转换ppt * @param businessId * @param type 0开课 1课程 * @return */ @Override public List<String> reConversionPPT(String businessId, String type) { List<String> failPPTPath = new ArrayList<>(); try { String basePath = global.getSL_LOCATION(); if(type.equals("1")){ basePath = global.getLESSON_LOCATION(); } String path = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + global.getCOURSE_LOCATION() + File.separator + basePath + File.separator + businessId; File file = new File(path); failPPTPath = this.changePPTToPDF(file,failPPTPath); } catch (IOException e) { e.printStackTrace(); } return failPPTPath; } private List<String> changePPTToPDF(File slFile, List<String> failPPTPath) throws IOException { for (File chapterFile : slFile.listFiles()) { String pptPath = chapterFile.getPath()+File.separator+"ppt"; File pptFile = new File(pptPath); if(pptFile.exists()){ File[] pptFiles = pptFile.listFiles(); if(pptFiles.length==1&&pptFiles[0].getName().endsWith("ppt")){ failPPTPath.add(pptFiles[0].getPath()); String inputFile = pptFiles[0].getPath(); String outputFile = pptFiles[0].getPath().substring(0,pptFiles[0].getPath().lastIndexOf(".")) + ".pdf"; //slTask.officeToPdf(inputFile,outputFile); } } } return failPPTPath; } /*public String uploadFileToServer(MultipartFile file, BFile bFile) throws Exception{ String fileUrl = ""; //查询此节是否已有视频或文件 BFile f = bFileRepository.selectInfoByChapterId(bFile.getChapterId()); if (f!=null){ //复制文件到临时目录 this.removeVideoToTemp(bFile); }else{ BFile newVideo = this.uploadVideo(file, bFile);//上传文件 if (bFile.getType().equals("0")){ fileUrl = newVideo.getVideoUrl(); }else if(bFile.getType().equals("1")){ fileUrl = newVideo.getFileUrl(); }else if(bFile.getType().equals("2")){ fileUrl = newVideo.getPptUrl(); }else{ fileUrl = newVideo.getPdfUrl(); } } return fileUrl; }*/ }
\ No newline at end of file
package
org
.
rcisoft
.
business
.
bfile
.
service
.
impl
;
import
com.itextpdf.text.pdf.PdfReader
;
import
org.apache.commons.io.FileUtils
;
import
org.rcisoft.business.bfile.dao.BFileRepository
;
import
org.rcisoft.business.bfile.entity.BFile
;
import
org.rcisoft.business.bfile.service.BFileService
;
import
org.rcisoft.business.bsl.task.SlTask
;
import
org.rcisoft.common.component.Global
;
import
org.rcisoft.core.aop.PageUtil
;
import
org.rcisoft.core.bean.RcLkConfigBean
;
import
org.rcisoft.core.constant.DelStatus
;
import
org.rcisoft.core.exception.ServiceException
;
import
org.rcisoft.core.model.PersistModel
;
import
org.rcisoft.core.result.ResultServiceEnums
;
import
org.rcisoft.core.util.FileUtil
;
import
org.rcisoft.core.util.IdGen
;
import
org.rcisoft.core.util.UserUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.*
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
static
org
.
rcisoft
.
core
.
util
.
CutPdfUtil
.
partitionPdfFile
;
/** * Created by gaowenfneg on 2017-10-9 14:34:56. */
@Service
@Transactional
(
readOnly
=
true
,
propagation
=
Propagation
.
NOT_SUPPORTED
)
public
class
BFileServiceImpl
implements
BFileService
{
@Autowired
private
BFileRepository
bFileRepository
;
@Autowired
private
SlTask
slTask
;
@Autowired
private
Global
global
;
@Autowired
private
RcLkConfigBean
rcLkConfigBean
;
@Override
public
BFile
selectOne
(
String
businessId
){
return
bFileRepository
.
selectByPrimaryKey
(
businessId
);
}
@Override
public
List
<
BFile
>
queryBVideosByPagination
(
PageUtil
pageUtil
,
BFile
model
)
{
Map
param
=
new
HashMap
<
String
,
Object
>();
return
bFileRepository
.
queryBVideos
(
param
);
}
@Override
public
List
<
BFile
>
queryBVideos
(
BFile
model
)
{
Map
param
=
new
HashMap
<
String
,
Object
>();
return
bFileRepository
.
queryBVideos
(
param
);
}
@Override
public
PersistModel
persist
(
BFile
model
){
UserUtil
.
setCurrentPersistOperation
(
model
);
int
line
=
bFileRepository
.
insertSelective
(
model
);
return
new
PersistModel
(
line
);
}
@Override
public
PersistModel
removeBVideo
(
String
id
)
{
BFile
bFile
=
bFileRepository
.
selectByPrimaryKey
(
id
);
bFile
.
setDelFlag
(
DelStatus
.
DELETED
.
getStatus
());
UserUtil
.
setCurrentMergeOperation
(
bFile
);
int
line
=
bFileRepository
.
updateByPrimaryKeySelective
(
bFile
);
return
new
PersistModel
(
line
);
}
@Override
@Transactional
(
propagation
=
Propagation
.
REQUIRED
,
readOnly
=
false
)
public
String
uploadVideoToServer
(
List
<
MultipartFile
>
list
,
BFile
bFile
)
{
String
videoUrl
=
""
;
if
(
list
.
size
()>
0
)
{
for
(
int
i
=
0
;
i
<
list
.
size
();
++
i
)
{
MultipartFile
file
=
list
.
get
(
i
);
try
{
//查询此节是否已有视频或文件 BFile video = bFileRepository.selectInfoByChapterId(bFile.getChapterId()); if (video!=null){//此节已有视频或文件,将已有的视频或文件放置到temp目录下,然后上传新视频或文件 if(bFile.getType().equals("0")&&video.getVideoUrl()!=null&&!video.getVideoUrl().equals("")){ this.removeVideoToTemp(bFile);//复制之前视频到temp文件下 } if(bFile.getType().equals("1")&&video.getFileUrl()!=null&&!video.getFileUrl().equals("")){ this.removeVideoToTemp(bFile);//复制之前文件到temp文件下 } if(bFile.getType().equals("2")&&video.getPptUrl()!=null&&!video.getPptUrl().equals("")){ this.removeVideoToTemp(bFile);//复制之前ppt到temp文件下 } if(bFile.getType().equals("3")&&video.getPdfUrl()!=null&&!video.getPdfUrl().equals("")){ this.removeVideoToTemp(bFile);//复制之前pdf到temp文件下 } BFile newVideo = this.uploadVideo(file, bFile);//上传新文件 newVideo.setBusinessId(video.getBusinessId()); UserUtil.setCurrentMergeOperation(newVideo); bFileRepository.updateByPrimaryKeySelective(newVideo);//更新表中信息 if (bFile.getType().equals("0")){ videoUrl = newVideo.getVideoUrl(); }else if(bFile.getType().equals("1")){ videoUrl = newVideo.getFileUrl(); }else if(bFile.getType().equals("2")){ videoUrl = newVideo.getPptUrl(); }else{ videoUrl = newVideo.getPdfUrl(); } }else{ BFile newVideo = this.uploadVideo(file, bFile);//上传文件 this.persist(newVideo);//插入表信息 if (bFile.getType().equals("0")){ videoUrl = newVideo.getVideoUrl(); }else if(bFile.getType().equals("1")){ videoUrl = newVideo.getFileUrl(); }else if(bFile.getType().equals("2")){ videoUrl = newVideo.getPptUrl(); }else{ videoUrl = newVideo.getPdfUrl(); } } } catch (Exception e) { e.printStackTrace(); throw new ServiceException(ResultServiceEnums.UPLOAD_ERROR); } } } return videoUrl; } /** * 将原视频复制到temp/video文件下,并删除原视频 * @param bFile */ private void removeVideoToTemp(BFile bFile) throws Exception{ String path; String pathName; if(bFile.getLessonId()!=null&&!bFile.getLessonId().equals("")){ path = global.getLESSON_LOCATION() + File.separator + bFile.getLessonId() + File.separator; }else{ path = global.getSL_LOCATION() + File.separator + bFile.getSlId() + File.separator; } if (bFile.getType().equals("0")){ pathName = global.getVIDEO_LOCATION();//视频路径 }else if(bFile.getType().equals("1")){ pathName = global.getFILE_LOCATION();//文件路径 }else if(bFile.getType().equals("2")){ pathName = global.getPPT_LOCATION();//ppt路径 }else{ pathName = global.getPDF_LOCATION();//pdf路径 } String tempPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + global.getCOURSE_LOCATION() + File.separator + global.getTEMP_LOCATION() + File.separator + path + bFile.getChapterId(); File tempFilePath = new File(tempPath); if(tempFilePath.exists()){ FileUtils.deleteDirectory(tempFilePath); } String realFilePath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + global.getCOURSE_LOCATION() + File.separator + path + bFile.getChapterId() + File.separator + pathName; File directory = new File(realFilePath); if(directory.exists()){ FileUtils.moveDirectory(directory,tempFilePath); } } /** * 上传视频到video目录 * @param file * @param bFile * @return * @throws IOException */ private BFile uploadVideo(MultipartFile file, BFile bFile) throws IOException { BufferedOutputStream stream = null; String path; String pathName; if(bFile.getLessonId()!=null&&!bFile.getLessonId().equals("")){ path = global.getLESSON_LOCATION() + File.separator + bFile.getLessonId() + File.separator; }else{ path = global.getSL_LOCATION() + File.separator + bFile.getSlId() + File.separator; } if (bFile.getType().equals("0")){ pathName = global.getVIDEO_LOCATION();//视频路径 }else if(bFile.getType().equals("1")){ pathName = global.getFILE_LOCATION();//文件路径 }else if(bFile.getType().equals("2")){ pathName = global.getPPT_LOCATION();//ppt路径 }else{ pathName = global.getPDF_LOCATION();//pdf路径 } String realPath = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + global.getCOURSE_LOCATION() + File.separator + path + bFile.getChapterId() + File.separator + pathName + File.separator; File outFile=new File(realPath); if(!outFile.exists()){//判断保存路径是否存在,不存在新建 outFile.mkdirs(); } //上传文件 String uploadFile = file.getOriginalFilename(); //文件的真实名称 String name = uploadFile.substring(uploadFile.lastIndexOf(File.separator) + 1,uploadFile.lastIndexOf('.')); // 截取上传文件的后缀 String uploadFileSuffix = FileUtil.getFilePostfix(uploadFile); //uploadFile.substring(uploadFile.lastIndexOf('.') + 1, uploadFile.length()); // 设置文件名为乱码 String uploadFileName = IdGen.uuid(); String filename = uploadFileName + "." + uploadFileSuffix; stream = new BufferedOutputStream(new FileOutputStream(new File(realPath + filename))); byte[] bytes = file.getBytes(); stream.write(bytes,0,bytes.length); String newPath = global.getCOURSE_LOCATION() + File.separator + path + bFile.getChapterId() + File.separator + pathName + File.separator; if(uploadFileSuffix.equals("ppt")&&bFile.getType().equals("2")){//ppt转pdf String inputFile = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + newPath+ filename; String outputFile = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + newPath + uploadFileName + ".pdf"; slTask.officeToPdf(inputFile,outputFile); } if(uploadFileSuffix.equals("pdf")&&bFile.getType().equals("3")){//pdf切割 try { slTask.cutPdf(newPath, filename, uploadFileName); } catch (Exception e) { e.printStackTrace(); } } //上传的是文件时才存文件名,方便下载时取 if(bFile.getType().equals("1")){ bFile.setVideoName(name+ "." +uploadFileSuffix);//文件名 } if (bFile.getType().equals("0")){ bFile.setVideoUrl(newPath+ filename);//视频路径 }else if(bFile.getType().equals("1")){ bFile.setFileUrl(newPath+ filename);//文件路径 }else if(bFile.getType().equals("2")){ bFile.setPptUrl(newPath + uploadFileName + ".pdf");//ppt路径 }else{ bFile.setPdfUrl(newPath+ filename);//pdf路径 } stream.close(); return bFile; } @Override public BFile queryFileUrlByChapterId(String chapterId) { return bFileRepository.queryFileUrlByChapterId(chapterId); } @Override public void uploadLicense(MultipartFile file) { try { BufferedOutputStream stream = null; String path = global.getBASE_UPLOAD_SERVER_LOCATION() + rcLkConfigBean.getLicPath(); File oldFile = new File(path); if(oldFile.exists()){ FileUtils.forceDelete(oldFile); } File newFile = new File(path); stream = new BufferedOutputStream(new FileOutputStream(newFile)); byte[] bytes = file.getBytes(); stream.write(bytes,0,bytes.length); stream.flush(); stream.close(); } catch (Exception e) { e.printStackTrace(); throw new ServiceException(ResultServiceEnums.UPLOAD_ERROR); } return; } /** * 重新转换ppt * @param businessId * @param type 0开课 1课程 * @return */ @Override public List<String> reConversionPPT(String businessId, String type) { List<String> failPPTPath = new ArrayList<>(); try { String basePath = global.getSL_LOCATION(); if(type.equals("1")){ basePath = global.getLESSON_LOCATION(); } String path = global.getBASE_UPLOAD_SERVER_LOCATION() + File.separator + global.getCOURSE_LOCATION() + File.separator + basePath + File.separator + businessId; File file = new File(path); failPPTPath = this.changePPTToPDF(file,failPPTPath); } catch (IOException e) { e.printStackTrace(); } return failPPTPath; } private List<String> changePPTToPDF(File slFile, List<String> failPPTPath) throws IOException { for (File chapterFile : slFile.listFiles()) { String pptPath = chapterFile.getPath()+File.separator+"ppt"; File pptFile = new File(pptPath); if(pptFile.exists()){ File[] pptFiles = pptFile.listFiles(); if(pptFiles.length==1&&pptFiles[0].getName().endsWith("ppt")){ failPPTPath.add(pptFiles[0].getPath()); String inputFile = pptFiles[0].getPath(); String outputFile = pptFiles[0].getPath().substring(0,pptFiles[0].getPath().lastIndexOf(".")) + ".pdf"; slTask.officeToPdf(inputFile,outputFile); } } } return failPPTPath; } /*public String uploadFileToServer(MultipartFile file, BFile bFile) throws Exception{ String fileUrl = ""; //查询此节是否已有视频或文件 BFile f = bFileRepository.selectInfoByChapterId(bFile.getChapterId()); if (f!=null){ //复制文件到临时目录 this.removeVideoToTemp(bFile); }else{ BFile newVideo = this.uploadVideo(file, bFile);//上传文件 if (bFile.getType().equals("0")){ fileUrl = newVideo.getVideoUrl(); }else if(bFile.getType().equals("1")){ fileUrl = newVideo.getFileUrl(); }else if(bFile.getType().equals("2")){ fileUrl = newVideo.getPptUrl(); }else{ fileUrl = newVideo.getPdfUrl(); } } return fileUrl; }*/ }
\ No newline at end of file
...
...
src/main/java/org/rcisoft/business/blesson/controller/BLessonController.java
View file @
9a1d1453
...
...
@@ -157,22 +157,23 @@ public class BLessonController extends PaginationController<BLesson> {
@ApiImplicitParam
(
name
=
"classHour"
,
value
=
"课时"
,
required
=
false
,
dataType
=
"varchar"
),
@ApiImplicitParam
(
name
=
"credits"
,
value
=
"学分"
,
required
=
false
,
dataType
=
"varchar"
)})
@GetMapping
(
value
=
"/queryBLessonsByPagination"
)
// public GridModel queryBLessonsByPagination(BLesson param,String userId) {
public
GridModel
queryBLessonsByPagination
(
BLesson
param
,
String
uid
)
{
// param.setCreateBy(UserUtil.getUserInfoProp(getToken(),UserUtil.USER_ID));
// param.setCreateBy(userId);
public
Result
queryBLessonsByPagination
(
BLesson
param
,
String
uid
)
{
bLessonService
.
queryBLessonsByPagination
(
getPaginationUtility
(),
param
,
uid
);
GridModel
gridModel
=
getGridModelResponse
();
return
gridModel
;
// return gridModel;
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
gridModel
);
}
@GetMapping
(
value
=
"/queryLearnBLessonsByPagination"
)
public
GridModel
queryLearnBLessonsByPagination
(
BLesson
param
,
String
userId
)
{
// param.setCreateBy(UserUtil.getUserInfoProp(getToken(),UserUtil.USER_ID));
bLessonService
.
queryLearnBLessonsByPagination
(
getPaginationUtility
(),
param
,
userId
);
GridModel
gridModel
=
getGridModelResponse
();
return
gridModel
;
}
//
@GetMapping(value = "/queryLearnBLessonsByPagination")
//
public GridModel queryLearnBLessonsByPagination(BLesson param,String userId) {
//
//
param.setCreateBy(UserUtil.getUserInfoProp(getToken(),UserUtil.USER_ID));
//
bLessonService.queryLearnBLessonsByPagination(getPaginationUtility(),param,userId);
//
GridModel gridModel = getGridModelResponse();
//
return gridModel;
//
}
@ApiOperation
(
value
=
"根据条件查询"
,
notes
=
"根据URL中的参数查询全部"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"businessId"
,
value
=
"businessId"
,
required
=
false
,
dataType
=
"varchar"
),
...
...
src/main/java/org/rcisoft/business/blesson/entity/BLesson.java
View file @
9a1d1453
...
...
@@ -65,17 +65,17 @@ public class BLesson extends IdEntity<BLesson> {
private
Date
releaseDate
;
@Length
(
min
=
1
,
max
=
64
,
message
=
"长度最小为1,最大为50"
)
private
String
lessonType
;
//
可见范围
private
String
lessonType
;
//
课程类型(0:课程 1:培训)
@Length
(
min
=
1
,
max
=
64
,
message
=
"长度最小为1,最大为50"
)
private
String
discussNumber
;
//
可见范围
private
String
discussNumber
;
//
评论数
@Length
(
min
=
1
,
max
=
64
,
message
=
"长度最小为1,最大为50"
)
private
String
recommend
;
//
可见范围
private
String
recommend
;
//
推荐(0:不推荐 1:推荐)
@Length
(
min
=
1
,
max
=
64
,
message
=
"长度最小为1,最大为50"
)
private
String
collectNumber
;
//
可见范围
private
String
collectNumber
;
//
关注数
@Length
(
min
=
1
,
max
=
64
,
message
=
"长度最小为1,最大为50"
)
private
String
hotNumber
;
//
可见范围
private
String
hotNumber
;
//
热度
@Length
(
min
=
1
,
max
=
64
,
message
=
"长度最小为1,最大为50"
)
private
String
value
;
//
可见范围
private
String
value
;
//
价值
@Transient
...
...
src/main/java/org/rcisoft/business/blessonperson/controller/BLessonPersonController.java
View file @
9a1d1453
...
...
@@ -38,18 +38,22 @@ public class BLessonPersonController extends PaginationController<BLesson> {
}
//-------
@ApiOperation
(
value
=
"
退出课程"
,
notes
=
"根据ID停用一条记录
"
)
@ApiOperation
(
value
=
"
分页查询听课"
,
notes
=
"
"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"businessId"
,
value
=
"businessId"
,
required
=
false
,
dataType
=
"varchar"
),
@ApiImplicitParam
(
name
=
"code"
,
value
=
"课程编号"
,
required
=
false
,
dataType
=
"varchar"
),
@ApiImplicitParam
(
name
=
"condition"
,
value
=
"模糊查询条件"
,
required
=
false
,
dataType
=
"varchar"
),
@ApiImplicitParam
(
name
=
"classHour"
,
value
=
"课时"
,
required
=
false
,
dataType
=
"varchar"
),
@ApiImplicitParam
(
name
=
"credits"
,
value
=
"学分"
,
required
=
false
,
dataType
=
"varchar"
)})
@GetMapping
(
value
=
"/queryLearnBLessonsByPagination"
)
public
GridModel
queryLearnBLessonsByPagination
(
BLessonPerson
param
,
String
uid
)
{
public
Result
queryLearnBLessonsByPagination
(
BLessonPerson
param
,
String
uid
)
{
// param.setCreateBy(UserUtil.getUserInfoProp(getToken(),UserUtil.USER_ID));
bLessonPersonService
.
queryLearnBLessonsByPagination
(
getPaginationUtility
(),
param
,
uid
);
GridModel
gridModel
=
getGridModelResponse
();
return
gridModel
;
// return gridModel;
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_ALERT_ERROR
,
gridModel
);
}
}
src/main/java/org/rcisoft/business/bsl/task/SlTask.java
View file @
9a1d1453
...
...
@@ -4,6 +4,7 @@ import com.itextpdf.text.pdf.PdfReader;
import
lombok.extern.slf4j.Slf4j
;
import
org.rcisoft.common.component.Global
;
import
org.rcisoft.core.util.CutPdfUtil
;
import
org.rcisoft.core.util.OfficeToPdf
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Component
;
...
...
@@ -17,6 +18,8 @@ import java.io.File;
@Slf4j
public
class
SlTask
{
@Autowired
private
OfficeToPdf
officeToPdf
;
@Autowired
private
CutPdfUtil
cutPdfUtil
;
...
...
@@ -24,6 +27,10 @@ public class SlTask {
@Autowired
private
Global
global
;
@Async
public
void
officeToPdf
(
String
sourceFile
,
String
destFile
){
officeToPdf
.
transformToPdf
(
sourceFile
,
destFile
);
}
@Async
...
...
src/main/java/org/rcisoft/common/controller/UserController.java
View file @
9a1d1453
...
...
@@ -5,12 +5,14 @@ import io.swagger.annotations.ApiImplicitParam;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.rcisoft.base.Ret
;
import
org.rcisoft.common.util.feignDto.*
;
import
org.rcisoft.common.util.outClient.MTCotactApiRequestClient
;
import
org.rcisoft.common.util.outClient.MTMessageApiRequestClient
;
import
org.rcisoft.common.util.outClient.MTNotificationApiRequestClient
;
import
org.rcisoft.common.util.outClient.MTOauthApiRequestClient
;
import
org.rcisoft.core.constant.MessageConstant
;
import
org.rcisoft.core.model.PersistModel
;
import
org.rcisoft.core.result.Result
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -45,7 +47,7 @@ public class UserController {
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"code"
,
value
=
"用户code"
,
required
=
true
)
})
public
Ret
loginByCode
(
String
code
)
{
public
Re
sul
t
loginByCode
(
String
code
)
{
MTMyInfoRspDTO
mtMyInfoRspDTO
;
try
{
Map
<
String
,
String
>
tokens
=
mtOauthApiRequestClient
.
getTokenByCode
(
code
);
...
...
@@ -54,11 +56,19 @@ public class UserController {
mtMyInfoRspDTO
=
mtCotactApiRequestClient
.
userGetByToken
(
token
);
mtMyInfoRspDTO
.
setAccess_token
(
token
);
mtMyInfoRspDTO
.
setRefresh_token
(
refreshToken
);
return
Ret
.
ok
().
setData
(
mtMyInfoRspDTO
);
// return Ret.ok().setData(mtMyInfoRspDTO);
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_FREE_ACCESS_ERROR
,
mtMyInfoRspDTO
);
}
catch
(
Exception
e
){
log
.
error
(
e
.
getMessage
());
}
return
Ret
.
error
().
setMsg
(
"免登失败"
);
// return Ret.error().setMsg("免登失败");
return
Result
.
builder
(
new
PersistModel
(
0
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_FREE_ACCESS_ERROR
,
""
);
}
@GetMapping
(
"/refreshToken"
)
...
...
@@ -66,14 +76,22 @@ public class UserController {
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"refreshToken"
,
value
=
"刷新token"
,
required
=
true
)
})
public
Ret
refreshToken
(
String
refreshToken
)
{
public
Re
sul
t
refreshToken
(
String
refreshToken
)
{
try
{
RefreshDTO
refreshDTO
=
mtCotactApiRequestClient
.
refreshToken
(
refreshToken
);
return
Ret
.
ok
().
setData
(
refreshDTO
);
// return Ret.ok().setData(refreshDTO);
return
Result
.
builder
(
new
PersistModel
(
1
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_FREE_ACCESS_ERROR
,
refreshDTO
);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
return
Ret
.
error
().
setMsg
(
"免登失败"
);
// return Ret.error().setMsg("免登失败");
return
Result
.
builder
(
new
PersistModel
(
0
),
MessageConstant
.
MESSAGE_ALERT_SUCCESS
,
MessageConstant
.
MESSAGE_FREE_ACCESS_ERROR
,
""
);
}
}
src/main/java/org/rcisoft/core/constant/MessageConstant.java
View file @
9a1d1453
...
...
@@ -11,4 +11,7 @@ public class MessageConstant {
public
static
final
String
MESSAGE_ALERT_ERROR
=
"操作失败"
;
//信息非法
public
static
final
String
MESSAGE_ALERT_INFO_INVALID
=
"信息不合法"
;
//免登失败
public
static
final
String
MESSAGE_FREE_ACCESS_ERROR
=
"免登失败"
;
}
src/main/java/org/rcisoft/core/util/OfficeToPdf.java
0 → 100644
View file @
9a1d1453
package
org
.
rcisoft
.
core
.
util
;
import
com.artofsolving.jodconverter.BasicDocumentFormatRegistry
;
import
com.artofsolving.jodconverter.DocumentConverter
;
import
com.artofsolving.jodconverter.DocumentFormat
;
import
com.artofsolving.jodconverter.DocumentFormatRegistry
;
import
com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection
;
import
com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection
;
import
com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter
;
import
lombok.extern.slf4j.Slf4j
;
import
org.rcisoft.common.component.Global
;
import
org.rcisoft.core.exception.ServiceException
;
import
org.rcisoft.core.result.ResultServiceEnums
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.io.File
;
import
java.io.IOException
;
import
java.net.ConnectException
;
/**
* Created by Administrator on 2018/1/19.
*/
@Component
@Slf4j
public
class
OfficeToPdf
{
@Autowired
private
Global
global
;
/*
private static OfficeManager officeManager;
private static int port[] = { 8100 };
public void pptToPdf(String inputFile, String outputFile) throws FileNotFoundException {
startService();
System.out.println("进行文档转换转换:" + inputFile + " --> " + outputFile);
OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager);
converter.convert(new File(inputFile), new File(outputFile));
stopService();
}
// 打开服务器
public void startService() {
DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
try {
System.out.println("准备启动服务....");
configuration.setOfficeHome(global.getOPEN_OFFICE_HOME());// 设置OpenOffice.org安装目录
configuration.setPortNumbers(port); // 设置转换端口,默认为8100
configuration.setTaskExecutionTimeout(1000 * 60 * 5L);// 设置任务执行超时为5分钟
configuration.setTaskQueueTimeout(1000 * 60 * 60 * 24L);// 设置任务队列超时为24小时
officeManager = configuration.buildOfficeManager();
officeManager.start(); // 启动服务
System.out.println("office转换服务启动成功!");
} catch (Exception ce) {
System.out.println("office转换服务启动失败!详细信息:" + ce);
}
}
// 关闭服务器
public static void stopService() {
System.out.println("关闭office转换服务....");
if (officeManager != null) {
officeManager.stop();
}
System.out.println("关闭office转换成功!");
}*/
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
path
=
"C:/Users/Administrator/Desktop/"
;
OfficeToPdf
opc
=
new
OfficeToPdf
();
opc
.
transformToPdf
(
path
+
"abc.pptx"
,
path
+
"1.pdf"
);
}
/**
* 转换pdf
* @param sourceFile
* @param destFile
* @return 1 成功 0 失败 -1 错误
*/
public
synchronized
int
transformToPdf
(
String
sourceFile
,
String
destFile
){
OpenOfficeConnection
connection
=
null
;
try
{
File
inputFile
=
new
File
(
sourceFile
);
if
(!
inputFile
.
exists
())
{
return
-
1
;
// 找不到源文件, 则返回-1
}
// 如果目标路径不存在, 则新建该路径
File
outputFile
=
new
File
(
destFile
);
if
(!
outputFile
.
getParentFile
().
exists
())
{
outputFile
.
getParentFile
().
mkdirs
();
}
// connect to an OpenOffice.org instance running on port 8100
connection
=
new
SocketOpenOfficeConnection
(
global
.
getLibreofficeIp
(),
global
.
getLibreofficePort
());
connection
.
connect
();
// convert
DocumentConverter
converter
=
new
OpenOfficeDocumentConverter
(
connection
);
DocumentFormatRegistry
factory
=
new
BasicDocumentFormatRegistry
();
DocumentFormat
inputDocumentFormat
=
factory
.
getFormatByFileExtension
(
FileUtil
.
getFilePostfix
(
sourceFile
));
DocumentFormat
outputDocumentFormat
=
factory
.
getFormatByFileExtension
(
FileUtil
.
getFilePostfix
(
destFile
));
log
.
info
(
"开始转换--> "
+
sourceFile
);
converter
.
convert
(
inputFile
,
inputDocumentFormat
,
outputFile
,
outputDocumentFormat
);
log
.
info
(
"转换完毕--> "
+
destFile
);
// close the connection
}
catch
(
ConnectException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
0
;
}
finally
{
if
(
connection
!=
null
)
{
connection
.
disconnect
();
}
else
{
throw
new
ServiceException
(
ResultServiceEnums
.
UPLOAD_ERROR
);
}
}
return
1
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment