|
@@ -3,18 +3,26 @@ package cn.iselab.mooctest.site.web.logic.impl;
|
|
|
import cn.iselab.mooctest.site.common.enums.EntityTypeEnum;
|
|
|
import cn.iselab.mooctest.site.models.*;
|
|
|
import cn.iselab.mooctest.site.service.*;
|
|
|
+import cn.iselab.mooctest.site.service.common.PdfService;
|
|
|
import cn.iselab.mooctest.site.web.data.*;
|
|
|
import cn.iselab.mooctest.site.web.data.wrapper.CaseExtendsVOWrapper;
|
|
|
import cn.iselab.mooctest.site.web.data.wrapper.ExamVOWrapper;
|
|
|
import cn.iselab.mooctest.site.web.data.wrapper.PaperVOWrapper;
|
|
|
import cn.iselab.mooctest.site.web.data.wrapper.ThemeVOWrapper;
|
|
|
+import cn.iselab.mooctest.site.web.logic.OSSLogic;
|
|
|
import cn.iselab.mooctest.site.web.logic.ThemeLogic;
|
|
|
import com.google.common.collect.Lists;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -26,6 +34,7 @@ import java.util.stream.Collectors;
|
|
|
* @create: 2019-04-28 12:14
|
|
|
**/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class ThemeLogicImpl implements ThemeLogic {
|
|
|
@Autowired
|
|
|
private ThemeVOWrapper themeVOWrapper;
|
|
@@ -45,13 +54,42 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
private PaperService paperService;
|
|
|
@Autowired
|
|
|
private User2ThemeService user2ThemeService;
|
|
|
+ @Autowired
|
|
|
+ private PdfService pdfService;
|
|
|
+ @Autowired
|
|
|
+ private OSSLogic ossLogic;
|
|
|
+ @Autowired
|
|
|
+ private CourseResourceService courseResourceService;
|
|
|
+
|
|
|
+ private static final String BASE_DIR = "theme";
|
|
|
@Override
|
|
|
public ThemeDetailVO newThemeDetail(ThemeDetailVO themeDetailVO) {
|
|
|
ThemeDetail themeDetail = themeVOWrapper.unWrapperThemeDetail(themeDetailVO);
|
|
|
- themeDetail = themeService.createThemeDetail(themeDetail);
|
|
|
+// //异步上传
|
|
|
+// String localDir = pdfService.pdf2imageList(themeDetail.getSliderPdfUrl(),"png");
|
|
|
+// String parentDir = localDir.split("/")[localDir.split("/").length-1];
|
|
|
+// log.info("讲义的图片列表存储位置:{},相对目录:{}",localDir,parentDir);
|
|
|
+// uploadImages2Oss(localDir,parentDir);
|
|
|
+// themeDetail.setSliderImagesParentDir(parentDir);
|
|
|
+// themeDetail = themeService.createThemeDetail(themeDetail);
|
|
|
return themeVOWrapper.wrapperThemeDetail(themeDetail);
|
|
|
}
|
|
|
|
|
|
+ @Async("generateUpload2Oss")
|
|
|
+ protected void uploadImages2Oss(String localDir,String parentDir){
|
|
|
+ File file = new File(localDir);
|
|
|
+ File[] fs = file.listFiles();
|
|
|
+ for(File f:fs){
|
|
|
+ if(!f.isDirectory())
|
|
|
+ log.info(f.getName());
|
|
|
+ try(InputStream inputStream = new FileInputStream(f)) {
|
|
|
+ ossLogic.uploadByUrl("theme/"+parentDir+"/"+f.getName(), inputStream);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("读取文件流失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Page<ThemeDetailVO> getThemeDetailList(Pageable pageable) {
|
|
|
Page<ThemeDetail> themeDetailPageable = themeService.getThemeDetails(pageable);
|
|
@@ -59,8 +97,9 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Page<ThemeVO> getThemeList(Pageable pageable) {
|
|
|
- return null;
|
|
|
+ public Page<ThemeDetailVO> getThemeList(Pageable pageable,int type, int publicStatus) {
|
|
|
+ Page<ThemeDetail> themeDetails = themeService.getThemeDetails(pageable, type, publicStatus);
|
|
|
+ return themeDetails.map(themeVOWrapper::wrapperThemeDetail);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -117,6 +156,10 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
paperList.add(paperService.getById(t.getEntityId()));
|
|
|
}
|
|
|
theme.setPaperList(paperList);
|
|
|
+ } else if (key == EntityTypeEnum.COURSE_RESOURCE) {
|
|
|
+ List<Long> courseIds = map.get(key).stream().map(ThemeEntityRelations::getEntityId).collect(Collectors.toList());
|
|
|
+ List<CourseResource> courseResourceList = courseResourceService.getCourseResourceById(courseIds);
|
|
|
+ theme.setCourseResourceList(courseResourceList);
|
|
|
}
|
|
|
}
|
|
|
return themeVOWrapper.wrapper(theme);
|