Commit ec523321 authored by luzhuang's avatar luzhuang

feat: 新增单个课程 课件下载接口

parent 6506f7af
...@@ -200,7 +200,17 @@ public class BChapterController extends PaginationController<BChapter> { ...@@ -200,7 +200,17 @@ public class BChapterController extends PaginationController<BChapter> {
@PostMapping("/getBatchsDownload") @PostMapping("/getBatchsDownload")
public Result getBatchsDownload(CurUser curUser,@RequestParam String ids, BindingResult br) throws IOException { public Result getBatchsDownload(CurUser curUser,@RequestParam String ids, BindingResult br) throws IOException {
String newFileUrl = bChapterService.getBatchsDownload(ids); String newFileUrl = bChapterService.getBatchsDownload(ids);
// String newFileUrl = "http://192.168.5.54/eduServer/course/zip/6d454523b48d4885a6e2bee4a2bcd967.zip"; return Result.builder(new PersistModel(1),
MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR,
newFileUrl);
}
@ApiOperation(value = "214 根据传入的课程id 单个课程下载文件 返回服务器Zip包地址", notes = "下载文件 批量返回服务器Zip包地址")
@ApiImplicitParam(name = "id", value = "课程id", required = true, dataType = "varchar")
@PostMapping("/getLessonDownload")
public Result getLessonDownload(CurUser curUser,@RequestParam String id, BindingResult br) throws IOException {
String newFileUrl = bChapterService.getLessonDownload(id);
return Result.builder(new PersistModel(1), return Result.builder(new PersistModel(1),
MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_SUCCESS,
MessageConstant.MESSAGE_ALERT_ERROR, MessageConstant.MESSAGE_ALERT_ERROR,
......
...@@ -112,12 +112,19 @@ public interface BChapterService{ ...@@ -112,12 +112,19 @@ public interface BChapterService{
* @return * @return
*/ */
String getBatchDownload(String bFileJson); String getBatchDownload(String bFileJson);
/** /**
* 下载文件 * 下载文件
* @param bFileJson * @param bFileJson
* @return * @return
*/ */
String getBatchsDownload(String bFileJson); String getBatchsDownload(String bFileJson);
/**
* 下载文件
* @param lessonId
* @return
*/
String getLessonDownload(String lessonId);
/** /**
* 判断文件是否 * 判断文件是否
......
...@@ -905,6 +905,46 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -905,6 +905,46 @@ public class BChapterServiceImpl implements BChapterService {
return returnAddress; return returnAddress;
} }
@Override
public String getLessonDownload(String id) {
//获取当前课程的信息
BLesson bLesson = bLessonRepository.selectByPrimaryKey(id);
List<BFile> fileList = bFileRepository.getFileByLessonId(id);
//batch是zip打包文件夹 bFile.getLessonId()替换形成name
String filePath = global.getBASE_UPLOAD_SERVER_LOCATION() + global.getCOURSE_LOCATION() + File.separator + bLesson.getLessonName() ;
File file = new File(filePath);
if (!file.exists())
file.mkdirs();
if (fileList != null && fileList.size() > 0){
//下载文件 并将这些文件包装成File
fileList.forEach(bFile -> {
if (StringUtils.isNotEmpty(bFile.getVideoUrl()))
downLoadFile(bFile, file, filePath, "1");
});
}
String uuid = IdGen.uuid();
//文件打包地址
File zipFilePath = new File(global.getBASE_UPLOAD_SERVER_LOCATION() + global.getCOURSE_LOCATION() + File.separator + global.getZIP_LOCATION());
if (!zipFilePath.exists())
zipFilePath.mkdirs();
//定义压缩包的生成路径
File zipFile = new File(zipFilePath.getPath() + File.separator + uuid + ".zip");
log.info("---------------批量课程下载----------zip压缩包 相对路径--------" + zipFile.getPath());
//返回地址
String returnAddress = global.getRETURN_UPLOAD_SERVER_LOCATION() + global.getCOURSE_LOCATION() + File.separator + global.getZIP_LOCATION() + File.separator + uuid + ".zip";
log.info("---------------批量课程下载----------zip压缩包 网络访问路径--------" + returnAddress);
try {
//打包
ZipMultiFile.toZip(filePath, new FileOutputStream(zipFile), true);
//删除 文件夹
ZipMultiFile.deleteDirectory(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return returnAddress;
}
@Override @Override
public String fileReadable(BFile bFile) { public String fileReadable(BFile bFile) {
String flag = "1"; String flag = "1";
......
...@@ -188,6 +188,7 @@ ...@@ -188,6 +188,7 @@
<result column="train_address" jdbcType="VARCHAR" property="trainAddress"/> <result column="train_address" jdbcType="VARCHAR" property="trainAddress"/>
<result column="train_sign_time" jdbcType="VARCHAR" property="trainSignTime"/> <result column="train_sign_time" jdbcType="VARCHAR" property="trainSignTime"/>
<result column="qr_code" jdbcType="VARCHAR" property="qrCode"/> <result column="qr_code" jdbcType="VARCHAR" property="qrCode"/>
<result column="corp_id" jdbcType="VARCHAR" property="corpId"/>
<!----> <!---->
<result column="value_consume" jdbcType="VARCHAR" property="valueConsume"/> <result column="value_consume" jdbcType="VARCHAR" property="valueConsume"/>
<result column="value_gain" jdbcType="VARCHAR" property="valueGain"/> <result column="value_gain" jdbcType="VARCHAR" property="valueGain"/>
......
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