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
03acb059
Commit
03acb059
authored
Oct 14, 2019
by
root
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改接口
parent
882e5fa5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
1 deletion
+2
-1
BFileServiceImpl.java
...rcisoft/business/bfile/service/impl/BFileServiceImpl.java
+1
-1
BLessonServiceImpl.java
...oft/business/blesson/service/impl/BLessonServiceImpl.java
+1
-0
No files found.
src/main/java/org/rcisoft/business/bfile/service/impl/BFileServiceImpl.java
View file @
03acb059
package
org
.
rcisoft
.
business
.
bfile
.
service
.
impl
;
import
com.itextpdf.text.pdf.PdfReader
;
import
org.apache.commons.io.FileUtils
;
import
org.rcisoft.business.bchapter.entity.BChapter
;
import
org.rcisoft.business.bfile.dao.BFileRepository
;
import
org.rcisoft.business.bfile.dto.uploadDTO
;
import
org.rcisoft.business.bfile.entity.BFile
;
import
org.rcisoft.business.bfile.service.BFileService
;
import
org.rcisoft.business.bfile.util.GetVideoTime
;
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
uploadDTO
uploadVideoToServer
(
MultipartFile
file
,
String
type
)
{
String
videoUrl
=
""
;
String
fileName
=
file
.
getOriginalFilename
();
uploadDTO
dto
=
new
uploadDTO
();
try
{
if
(
type
.
equals
(
"0"
))
{
videoUrl
=
"https://s2.luckincoffeecdn.com/luckywebrm/images/index/luckincoffee_TVC30.mp4"
;
}
else
if
(
type
.
equals
(
"1"
))
{
videoUrl
=
"http://www.ytmp3.cn/down/48032.mp3"
;
}
else
if
(
type
.
equals
(
"2"
))
{
videoUrl
=
"http://f.hiphotos.baidu.com/image/pic/item/0e2442a7d933c8956c0e8eeadb1373f08202002a.jpg"
;
}
else
if
(
type
.
equals
(
"3"
))
{
videoUrl
=
"https://web.stanford.edu/~xgzhou/zhou_book2017.pdf "
;
}
else
{
videoUrl
=
"http://f.hiphotos.baidu.com/image/pic/item/0e2442a7d933c8956c0e8eeadb1373f08202002a.jpg"
;
}
dto
.
setFileName
(
fileName
);
dto
.
setVideoUrl
(
videoUrl
);
dto
.
setType
(
type
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
ServiceException
(
ResultServiceEnums
.
UPLOAD_ERROR
);
}
return
dto
;
}
/** * 将原视频复制到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
{
throw
new
ServiceException
(
"路径错误!"
);
}
if
(
bFile
.
getType
().
equals
(
"0"
))
{
pathName
=
global
.
getVIDEO_LOCATION
();
//视频路径 } else if (bFile.getType().equals("1")) { pathName = global.getAUDIO_LOCATION();//音频路径 } else if (bFile.getType().equals("2")) { pathName = global.getPPT_LOCATION();//ppt路径 } else if (bFile.getType().equals("3")) { pathName = global.getPDF_LOCATION();//pdf路径 } else { pathName = global.getFILE_LOCATION();//文件路径 } 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); } } @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; }*/ }
package
org
.
rcisoft
.
business
.
bfile
.
service
.
impl
;
import
com.itextpdf.text.pdf.PdfReader
;
import
org.apache.commons.io.FileUtils
;
import
org.rcisoft.business.bchapter.entity.BChapter
;
import
org.rcisoft.business.bfile.dao.BFileRepository
;
import
org.rcisoft.business.bfile.dto.uploadDTO
;
import
org.rcisoft.business.bfile.entity.BFile
;
import
org.rcisoft.business.bfile.service.BFileService
;
import
org.rcisoft.business.bfile.util.GetVideoTime
;
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
uploadDTO
uploadVideoToServer
(
MultipartFile
file
,
String
type
)
{
String
videoUrl
=
""
;
String
fileName
=
file
.
getOriginalFilename
();
uploadDTO
dto
=
new
uploadDTO
();
try
{
if
(
type
.
equals
(
"0"
))
{
videoUrl
=
"https://s2.luckincoffeecdn.com/luckywebrm/images/index/luckincoffee_TVC30.mp4"
;
}
else
if
(
type
.
equals
(
"1"
))
{
videoUrl
=
"http://www.ytmp3.cn/down/48032.mp3"
;
}
else
if
(
type
.
equals
(
"2"
))
{
videoUrl
=
"http://f.hiphotos.baidu.com/image/pic/item/0e2442a7d933c8956c0e8eeadb1373f08202002a.jpg"
;
}
else
if
(
type
.
equals
(
"3"
))
{
videoUrl
=
"https://web.stanford.edu/~xgzhou/zhou_book2017.pdf "
;
}
else
{
videoUrl
=
"http://downsc.chinaz.net/Files/DownLoad/moban/201909/zppt5601.rar"
;
}
dto
.
setFileName
(
fileName
);
dto
.
setVideoUrl
(
videoUrl
);
dto
.
setType
(
type
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
ServiceException
(
ResultServiceEnums
.
UPLOAD_ERROR
);
}
return
dto
;
}
/** * 将原视频复制到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
{
throw
new
ServiceException
(
"路径错误!"
);
}
if
(
bFile
.
getType
().
equals
(
"0"
))
{
pathName
=
global
.
getVIDEO_LOCATION
();
//视频路径 } else if (bFile.getType().equals("1")) { pathName = global.getAUDIO_LOCATION();//音频路径 } else if (bFile.getType().equals("2")) { pathName = global.getPPT_LOCATION();//ppt路径 } else if (bFile.getType().equals("3")) { pathName = global.getPDF_LOCATION();//pdf路径 } else { pathName = global.getFILE_LOCATION();//文件路径 } 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); } } @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
\ No newline at end of file
...
...
src/main/java/org/rcisoft/business/blesson/service/impl/BLessonServiceImpl.java
View file @
03acb059
...
@@ -320,6 +320,7 @@ public class BLessonServiceImpl implements BLessonService {
...
@@ -320,6 +320,7 @@ public class BLessonServiceImpl implements BLessonService {
//更新课程表recommend字段
//更新课程表recommend字段
BLesson
bLesson
=
new
BLesson
();
BLesson
bLesson
=
new
BLesson
();
UserUtil
.
setCurrentMergeOperation
(
bLesson
);
UserUtil
.
setCurrentMergeOperation
(
bLesson
);
bLesson
.
setBusinessId
(
recommendLessonDTO
.
getLessonId
());
bLesson
.
setRecommend
(
"1"
);
bLesson
.
setRecommend
(
"1"
);
bLessonRepository
.
updateByPrimaryKeySelective
(
bLesson
);
bLessonRepository
.
updateByPrimaryKeySelective
(
bLesson
);
//插入推荐表
//插入推荐表
...
...
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