package com.qxueyou.scc.controller; import java.util.List; import java.util.Map; import org.apache.commons.io.IOUtils; 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.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import com.qxueyou.scc.admin.teacher.service.ITeacherService; import com.qxueyou.scc.base.model.Pager; 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.service.IFileService; import com.qxueyou.scc.teach.subject.model.Subject; import com.qxueyou.scc.teach.subject.service.ISubjectService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; /** * 课程管理控制器 * * @author chenjunliang * */ @Api(tags = "课程管理-教师端") @RestController @RequestMapping(value = "/teach/subject") public class SubjectController { @Autowired ISubjectService subjectService; @Autowired IFileService fileService; @Autowired private ITeacherService teacherService; /**-------------------------------------------------------------------app接口------------------------------------------------------------------------------------------**/ /** * 课程管理列表 * * @param keyword * 索搜关键字 * @param limit * 显示几条 * @param pageNum * 当前页码 * @param status * 状态 */ @ApiOperation(value = "获取列表数据-教师端", notes = "") @ApiImplicitParams({ @ApiImplicitParam(name = "status", value = "状态", required = false, paramType="query", dataType = "String"), @ApiImplicitParam(name = "type", value = "类型(1:班级课程,3:公开课程)", required = false, paramType="query", dataType = "Integer") }) @GetMapping(value = "/app/teacherSubjectList") public Result list(Pager pager, @RequestParam(defaultValue="")String keyword, String status, Integer type) { if(type == null) { return new Result(false, "参数错误"); } return subjectService.teacherSubjectList(pager, keyword, status, type); } /**-------------------------------------------------------------------后端接口------------------------------------------------------------------------------------------**/ /** * 课程管理列表 * * @param keyword * 索搜关键字 * @param limit * 显示几条 * @param pageNum * 当前页码 * @param status * 状态 */ @GetMapping(value = "/list") public Result list(String keyword,String status,Integer type, Integer limit, Integer pageNum) { // String teacherId = ClientUtils.isAdmin() ? null : ClientUtils.getUserId(); //判断是否是教师 String teacherId = ClientUtils.isAdmin() ? null : teacherService.getTeacherIdByUserId(ClientUtils.getUserId()); List lst = subjectService.list(keyword, teacherId, status, type, limit, pageNum); int count = subjectService.listCount(keyword, teacherId, status,type); return new Result(true, "success", CollectionUtils.newObjectMap("subjectLst", QBeanUtils.listBean2ListMap(lst, CollectionUtils.newStringMap("name", "subjectName", "subjectId", "subjectId","type","type", "status", "status", "updateTime", "updateTime", "lectureCount", "lectureCount")), "subjectCount", count)); } /** * 课程管理列表 * * @param keyword * 索搜关键字 * @param limit * 显示几条 * @param pageNum * 当前页码 * @param status * 状态 */ @GetMapping(value = "/listAllSimple") public Result listAllSimple() { List lst = subjectService.list("", null, "1", null,1000, 1); return new Result(true, "success", QBeanUtils.listBean2ListMap(lst, CollectionUtils.newStringMap("name", "subjectName", "subjectId", "subjectId"))); } /** * 课程发布 * a * @param 课程ids */ @GetMapping(value = "/release") public Result release(String subjectIds) { return subjectService.doRelease(subjectIds.split(",")); } /** * 课程下架 * * @param subjectIds * 课程ids */ @GetMapping(value = "/soldOut") public Result soldOut(String subjectIds) { return subjectService.doCancel(subjectIds.split(",")); } /** * 课程删除 * * @param subjectIds * 课程ids */ @GetMapping(value = "/delete") public Result delete(String subjectIds) { return subjectService.delete(subjectIds.split(",")); } /** * 复制课程 * * @param subjectId * 课程id * @param subjectName * 课程名称 * @param imgPath * 图片url * @param content * 课程介绍 */ @PostMapping(value = "/copy") public Result copy(String subjectId, String subjectName, String imgPath, String content,int type) { return add(subjectName, imgPath, content,type); } /** * 新增课程 * * @param subjectName * 课程名称 * @param imgPath * 图片url * @param content * 课程介绍 * @return */ @PostMapping(value = "/add") public Result add(String subjectName, String imgPath, String content,int type) { String contentFileId = null; if(StringUtils.isNotEmpty(content)){ Result fileResult = fileService.doUpload(IOUtils.toInputStream(content), subjectName + ".data"); contentFileId = fileResult.getDataT("fileId"); } String coverPageFileId = null; if (StringUtils.isNotBlank(imgPath)) { coverPageFileId = fileService.readIdByPath(imgPath); } return subjectService.add(subjectName, coverPageFileId,contentFileId,type); } /** * 新增练习 * * @param name * 题目名称 * @param type * 题库类型 * @param difficulty * 难度系数 * @param repeatFlag * 是否重复 * @return */ @PostMapping(value = "addExercise") public Result addOrgExercise(String name, Integer type, Integer difficulty, Boolean repeatFlag) { return new Result(true, "success"); } /** * 更新课程 * * @param subjectId * 课程id * @param subjectName * 课程名称 * @param imgPath * 图片url * @param content * 课程介绍 */ @PostMapping(value = "/update") public Result update(String subjectId, String subjectName, String imgPath, String content,int type) { String contentFileId = null; if(StringUtils.isNotEmpty(content)){ Result fileResult = fileService.doUpload(IOUtils.toInputStream(content), subjectName + ".data"); contentFileId = fileResult.getDataT("fileId"); } String coverPageFileId = null; if (StringUtils.isNotBlank(imgPath)) { coverPageFileId = fileService.readIdByPath(imgPath); } return subjectService.update(subjectId, subjectName, coverPageFileId, contentFileId,type); } /** * 更新课程获取课程内容 * * @param subjectId * 课程id */ @ApiOperation(value = "获取课程详情-教师端", notes = "") @ApiImplicitParams({ @ApiImplicitParam(name = "subjectId", value = "课程id", required = false, paramType="query", dataType = "String") }) @GetMapping(value = "getSubjectDetail") public Result getSubjectDetail(String subjectId) { Map result = QBeanUtils.bean2Map(subjectService.read(subjectId), CollectionUtils .newStringMap("name", "subjectName", "subjectId", "subjectId", "type","type", "coverPageUrl", "imgPath", "teacherId","teacherId", "teacherName","teacherName", "schoolYear","schoolYear", "createTime","createTime", "creator","creator", "term","term")); result.put("reSubjects",this.subjectService.querySubjectReClassInfos(subjectId)); result.put("content", subjectService.readSubjectContent(subjectId)); result.put("lectureCount", subjectService.getLectureCount(subjectId)); return new Result(true, "success", result); } /** * 获取可用课程下拉列表接口 * * @param examId * @return */ @RequestMapping(value = "/selectlist", method = RequestMethod.GET) public @ResponseBody List> subjectList(Integer subjectType) { //判断是否是教师 String teacherId = ClientUtils.isAdmin() ? null : teacherService.getTeacherIdByUserId(ClientUtils.getUserId()); if(subjectType==null){ subjectType= Subject.TYPE_ORG_SUBJECT; } return this.subjectService.queryAvailableSubjectIdAndName(teacherId,subjectType); } }