package com.qxueyou.scc.controller;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import com.qxueyou.scc.admin.classes.model.ClsSubjectChapter;
|
import com.qxueyou.scc.admin.classes.model.ClsSubjectLecture;
|
import com.qxueyou.scc.admin.classes.service.IClassLectureService;
|
import com.qxueyou.scc.admin.progress.model.Progress;
|
import com.qxueyou.scc.admin.progress.service.IProgressService;
|
import com.qxueyou.scc.base.model.Result;
|
import com.qxueyou.scc.base.util.ClientUtils;
|
import com.qxueyou.scc.base.util.CollectionUtils;
|
import com.qxueyou.scc.base.util.QBeanUtils;
|
import com.qxueyou.scc.teach.res.model.Res;
|
import com.qxueyou.scc.teach.res.model.ResLib;
|
import com.qxueyou.scc.teach.res.service.IResService;
|
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
|
@Api(tags = "¿Î¼þ¹ÜÀí-½Ìʦ¶Ë")
|
@RestController
|
@RequestMapping(value = "teach/clsLecture")
|
public class ClsLectureController {
|
@Autowired
|
IClassLectureService classLectureService;
|
|
@Autowired
|
IProgressService progressService;
|
|
@Autowired
|
IResService resService;
|
|
/**-------------------------------------------------------------------app½Ó¿Ú------------------------------------------------------------------------------------------**/
|
@SuppressWarnings("unchecked")
|
@ApiOperation(value = "»ñÈ¡¿Î³ÌÏ¿μþ", notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "classId", value = "°à¼¶id", required = true, paramType="query", dataType = "String"),
|
@ApiImplicitParam(name = "subjectId", value = "¿Î³Ìid", required = true, paramType="query", dataType = "String"),
|
@ApiImplicitParam(name = "type", value = "¿Î¼þÀàÐÍ", required = false, paramType="query", dataType = "String")
|
})
|
@GetMapping(value = "/app/coursewareList")
|
public Result coursewareList(String classId,String subjectId, String type) {
|
|
if(StringUtils.isEmpty(subjectId)) {
|
return new Result(false, "¿Î³Ìid²»ÄÜΪ¿Õ");
|
}
|
|
//¹«¿ª¿ÎºÍ¹ÜÀíÔ±¿Î³Ì
|
if(StringUtils.isEmpty(classId)) {
|
Object obj = this.classLectureService.coursewareChapterList(classId, subjectId, type).getData();
|
if(obj == null) {
|
return new Result(true, "success", new ArrayList<>());
|
}
|
return new Result(true, "success", ((Map<String, Object>)obj).get("listData"));
|
}
|
|
//²éѯ¿Î¼þ
|
List<Map<String, Object>> lectures = classLectureService.listLectureBySubject(subjectId, type, classId);
|
|
//²éѯÕ½Ú
|
List<ClsSubjectChapter> chapterLst = classLectureService.getChapterLectures(classLectureService.getListChapter(classId, subjectId, null), lectures);
|
|
return new Result(true, "success", QBeanUtils.listBean2ListMap(chapterLst,
|
CollectionUtils.newStringMap("name", "name", "chapterId", "chapterId", "lectures", "lectures")));
|
}
|
|
/**-------------------------------------------------------------------ºó¶Ë½Ó¿Ú------------------------------------------------------------------------------------------**/
|
|
/**
|
* ¼ÓÔØ¿Î¼þtree
|
*
|
* @param parentId
|
* ¸¸½Úµãid
|
*/
|
@ApiOperation(value = "»ñÈ¡¿Î³ÌÏÂÕ½Ú", notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "classId", value = "°à¼¶id", required = false, paramType="query", dataType = "String"),
|
@ApiImplicitParam(name = "subjectId", value = "¿Î³Ìid", required = false, paramType="query", dataType = "String"),
|
@ApiImplicitParam(name = "parentId", value = "¸¸½Úµãid", required = false, paramType="query", dataType = "String")
|
})
|
@GetMapping(value = "categoryTree")
|
public Result categoryTree(String classId,String subjectId, String parentId) {
|
|
List<ClsSubjectChapter> chapterLst = classLectureService.doGetListChapter(classId,subjectId, parentId);
|
|
return new Result(true, "success", QBeanUtils.listBean2ListMap(chapterLst,
|
CollectionUtils.newStringMap("name", "name", "chapterId", "id")));
|
}
|
|
/**
|
* »ñÈ¡¿Î¼þÁбí
|
*
|
* @param chapterId
|
* Õ½Úid
|
* @param type
|
* ¿Î¼þÀàÐÍ
|
* @param keyword
|
* ËÑË÷¹Ø¼ü×Ö
|
* @param limit
|
* ÿҳÏÔʾ¼¸Ìõ
|
* @param pageNum
|
* Ò³Âë
|
* @return ״̬˵Ã÷(0,ÊÓÆµ¡£1,ÒôƵ¡£2,Îĵµ¡£3,Á·Ï°¡£)
|
*/
|
@ApiOperation(value = "»ñÈ¡¿Î³ÌÏÂÕ½Ú", notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "classId", value = "°à¼¶id", required = false, paramType="query", dataType = "String"),
|
@ApiImplicitParam(name = "chapterId", value = "Õ½Úid", required = false, paramType="query", dataType = "String"),
|
@ApiImplicitParam(name = "type", value = "¿Î¼þÀàÐÍ", required = false, paramType="query", dataType = "String")
|
})
|
@GetMapping(value = "coursewareList")
|
public Result lectureList(String chapterId, String type, String keyword, Integer limit, Integer pageNum,
|
String classId) {
|
|
List<ClsSubjectLecture> lectures = classLectureService.listLecture(chapterId, keyword, limit, pageNum, type,
|
classId);
|
|
int lectureCount = classLectureService.listLectureCount(chapterId, keyword, type);
|
|
return new Result(true, "success",
|
CollectionUtils.newObjectMap("coursewareLst",
|
QBeanUtils.listBean2ListMap(lectures,
|
CollectionUtils.newStringMap("name", "name", "lectureId", "id", "lectureType", "type",
|
"chapterId", "chapterId", "status", "status", "updateTime", "updateTime")),
|
"count", lectureCount));
|
|
}
|
|
/**
|
* ²é¿´¿Î¼þ
|
*
|
* @param id
|
* ¿Î¼þid
|
* @param attribute
|
* À©Õ¹ÊôÐÔ video:"mp4:HD","m3u8:SD" ¿É²»Óô« audio:¿É²»Óô« doc:¿É²»Óô«
|
*/
|
@ApiOperation(value = "²é¿´¿Î¼þ", notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "id", value = "¿Î¼þid", required = false, paramType="query", dataType = "String"),
|
@ApiImplicitParam(name = "attribute", value = "À©Õ¹ÊôÐÔ video:\"mp4:HD\",\"m3u8:SD\" ¿É²»Óô« audio:¿É²»Óô« doc:¿É²»Óô«", required = false, paramType="query", dataType = "String"),
|
})
|
@GetMapping(value = "showCourseware")
|
public Result showLecture(String id, String attribute) {
|
|
Result result = classLectureService.readLectureAccessPath(id, attribute);
|
|
Progress progress = progressService.query(Progress.PROGRESS_TYPE_LECTURE, id, ClientUtils.getUserId());
|
|
return new Result(true, "true",
|
CollectionUtils.newObjectMap("name", result.getDataT("name"), "fullPath", result.getDataT("path"), "id", id, "size", result.getDataT("size"),
|
"percent", progress == null ? 0 : String.valueOf(progress.getProgressPercent())));
|
}
|
|
/**
|
* ɾ³ý¿Î¼þ
|
*
|
* @param id
|
* ¿Î¼þids
|
*/
|
@GetMapping(value = "deleteCourseware")
|
public Result deleteLecture(String id) {
|
|
return classLectureService.deleteLecture(id.split(","));
|
|
}
|
|
/**
|
* ¿Î¼þ¹ÜÀí ÐÂÔöϼ¶£¬Í¬¼¶
|
*
|
* @param type
|
* (add:ÐÂÔö,edit :±à¼)
|
* @param chapterId
|
* Õ½Úid
|
* @param classId
|
* °à¼¶id
|
* @param name
|
* Ãû³Æ
|
* @param childFlag
|
* ÊÇ·ñ²Ù×÷ϼ¶
|
*
|
*/
|
@PostMapping(value = "addOrUpdateChapter")
|
public Result addOrUpdateChapter(String type, String name, String chapterId, boolean childFlag) {
|
ClsSubjectChapter chapter = classLectureService.readChapter(chapterId);
|
String parentChapterId = childFlag ? chapterId : chapter.getParentChapterId();
|
|
if ("add".equals(type)) {
|
return classLectureService.addChapter(parentChapterId, name);
|
} else {
|
return classLectureService.updateChapter(chapterId, name);
|
}
|
}
|
|
/**
|
* ¿Î¼þ¹ÜÀí Ŀ¼ɾ³ý
|
*
|
* @param chapterId
|
* Ŀ¼id
|
*/
|
@GetMapping(value = "deleteChapter")
|
public Result deleteChapter(String chapterId) {
|
return classLectureService.deleteChapter(chapterId.split(","));
|
}
|
|
/**
|
* Ìí¼Ó/¸üÐÂ(ÊÓÆµ£¬½²Ò壬ÒôƵ)
|
*
|
* @param name
|
* Ãû³Æ
|
* @param coverUrl
|
* ·âÃæUrl
|
* @param remark:
|
* <p>
|
* ÊÓÆµ°¡°¡°¡
|
* </p>
|
* ½éÉÜ
|
*
|
* @param id
|
* ¿Î¼þid
|
* @param sectionId
|
* С½ÚId
|
* @param type
|
* @return ״̬˵Ã÷(0,ÊÓÆµ¡£1,ÒôƵ¡£2,Îĵµ¡£3,Á·Ï°¡£)
|
*/
|
@PostMapping(value = "addOrUpdate")
|
public Result addOrUpdate(String id, String remark, String name, String coverUrl, String type, String fileId,
|
String sectionId) {
|
|
if (StringUtils.isEmpty(id)) {
|
Result resResult = resService.add(
|
resService.doGetRootDir(ResLib.OWNNER_TYPE_USER, ClientUtils.getUserId()).getDirId(), fileId, name,
|
remark, type, coverUrl);
|
return classLectureService.addClsLecture(sectionId, resResult.getDataT("resId"));
|
|
} else {
|
|
ClsSubjectLecture lecture = classLectureService.readClsLecture(id);
|
resService.update(lecture.getResItemId(), name, remark, coverUrl);
|
return classLectureService.updateLecture(lecture.getLectureId(), lecture.getResItemId());
|
}
|
}
|
|
/**
|
* ±à¼ »ñÈ¡ÄÚÈÝ
|
*
|
* @param id
|
* ¿Î¼þid
|
*/
|
@GetMapping(value = "getCoursewareDetail")
|
public Result getLectureDetail(String id) {
|
|
ClsSubjectLecture lecture = classLectureService.readClsLecture(id);
|
|
Res res = resService.read(lecture.getResItemId());
|
|
return new Result(true, "success",
|
CollectionUtils.newObjectMap("coursewareName", lecture.getName(), "coverUrl", res.getCoverPageUrl(),
|
"remark", res.getRemark(), "fileId", null, "name", lecture.getName(), "id",
|
lecture.getLectureId()));
|
}
|
|
/**
|
* ¿Î¼þ»ñÈ¡×ÊÔ´Áбí
|
*
|
* @param dirId
|
* Ŀ¼Id
|
* @param limit
|
* ÿҳÏÔʾ¼¸Ìõ
|
* @param pageNum
|
* Ò³Âë
|
* @return ״̬˵Ã÷(0,ÊÓÆµ¡£1,ÒôƵ¡£2,Îĵµ¡£3,Á·Ï°¡£)
|
*/
|
@ApiOperation(value = "¿Î¼þ»ñÈ¡×ÊÔ´Áбí", notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "dirId", value = "Ŀ¼Id", required = false, paramType="query", dataType = "String")
|
})
|
@GetMapping(value = "getResLst")
|
public Result getResLst(String dirId, Integer limit, Integer pageNum, String keyword) {
|
|
List<Res> resLst = resService.listMyRes(keyword, limit, pageNum, "");
|
|
return new Result(true, "success",
|
CollectionUtils.newObjectMap("resCount", resService.listMyResCount(keyword, ""), "resLst",
|
|
QBeanUtils.listBean2ListMap(resLst,
|
CollectionUtils.newStringMap("resId", "resId", "name", "resName", "type", "type"))));
|
}
|
|
/**
|
* ¿Î¼þ´Ó×ÊÔ´Ñ¡Ôñºó±£´æ
|
*
|
* @param resId
|
* ×ÊÔ´Îļþid
|
* @param sectionId
|
* С½Úid
|
*
|
*/
|
@GetMapping(value = "saveCourseware4Res")
|
public Result saveLecture4Res(String resId, String sectionId) {
|
|
int successCount = 0;
|
Result result = new Result(true);
|
|
for (String resId_ : resId.split(",")) {
|
result = classLectureService.addClsLecture(sectionId, resId_);
|
successCount = result.isSuccess() ? 1 : 0;
|
}
|
|
return new Result(true, null, successCount);
|
}
|
|
}
|