派生自 projectDept/qhighschool

yn147
2023-11-24 26780c533f2c2af6b9216306f649c1bcede94e4a
src/main/java/com/qxueyou/scc/controller/SubjectController.java
@@ -1,10 +1,15 @@
package com.qxueyou.scc.controller;
import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.qxueyou.scc.base.util.DateUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@@ -30,15 +35,17 @@
import io.swagger.annotations.ApiOperation;
/**
 * 课程管理控制器
 * 课程管理控制器
 * 
 * @author chenjunliang
 *
 */
@Api(tags = "课程管理-教师端")
@Api(tags = "课程管理-教师端")
@RestController
@RequestMapping(value = "/teach/subject")
public class SubjectController {
   private final Logger log = LogManager.getLogger(SubjectController.class);
   @Autowired
   ISubjectService subjectService;
@@ -49,51 +56,53 @@
   @Autowired
   private ITeacherService teacherService;
   
   /**-------------------------------------------------------------------app接口------------------------------------------------------------------------------------------**/
   /**-------------------------------------------------------------------app接口------------------------------------------------------------------------------------------**/
   
   /**
    * 课程管理列表
    * 课程管理列表
    * 
    * @param keyword
    *            索搜关键字
    *            索搜关键字
    * @param limit
    *            显示几条
    *            显示几条
    * @param pageNum
    *            当前页码
    *            当前页码
    * @param status
    *            ״̬
    *            状态
    */
   @ApiOperation(value = "获取列表数据-教师端", notes = "")
   @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")
        @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 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 : ClientUtils.getUserId();
      //判断是否是教师
      String teacherId = ClientUtils.isAdmin() ? null : teacherService.getTeacherIdByUserId(ClientUtils.getUserId());
      List<Subject> lst = subjectService.list(keyword, teacherId, status, type, limit, pageNum);
@@ -101,23 +110,23 @@
      return new Result(true, "success", CollectionUtils.newObjectMap("subjectLst",
            QBeanUtils.listBean2ListMap(lst,
                  CollectionUtils.newStringMap("name", "subjectName", "subjectId", "subjectId","type","type", "status",
                  CollectionUtils.newStringMap("name", "subjectName", "subjectId", "subjectId","type","type","startTime","startTime","endTime","endTime", "status",
                        "status", "updateTime", "updateTime", "lectureCount", "lectureCount")),
            "subjectCount", count));
   }
   /**
    * 课程管理列表
    * 课程管理列表
    * 
    * @param keyword
    *            索搜关键字
    *            索搜关键字
    * @param limit
    *            显示几条
    *            显示几条
    * @param pageNum
    *            当前页码
    *            当前页码
    * @param status
    *            ״̬
    *            状态
    */
   @GetMapping(value = "/listAllSimple")
   public Result listAllSimple() {
@@ -129,9 +138,9 @@
   }
   /**
    * 课程发布
    * 课程发布
    * a
    * @param 课程ids
    * @param 课程ids
    */
   @GetMapping(value = "/release")
   public Result release(String subjectIds) {
@@ -141,10 +150,10 @@
   }
   /**
    * 课程下架
    * 课程下架
    * 
    * @param subjectIds
    *            课程ids
    *            课程ids
    */
   @GetMapping(value = "/soldOut")
   public Result soldOut(String subjectIds) {
@@ -152,10 +161,10 @@
   }
   /**
    * 课程删除
    * 课程删除
    * 
    * @param subjectIds
    *            课程ids
    *            课程ids
    */
   @GetMapping(value = "/delete")
   public Result delete(String subjectIds) {
@@ -163,35 +172,35 @@
   }
   /**
    * 复制课程
    * 复制课程
    * 
    * @param subjectId
    *            课程id
    *            课程id
    * @param subjectName
    *            课程名称
    *            课程名称
    * @param imgPath
    *            ͼƬurl
    *            图片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);
   public Result copy(String subjectId, String subjectName, String imgPath, String content,int type,String startTime,String endTime) {
      return add(subjectName, imgPath, content,type,startTime,endTime);
   }
   /**
    * 新增课程
    * 新增课程
    * 
    * @param subjectName
    *            课程名称
    *            课程名称
    * @param imgPath
    *            ͼƬurl
    *            图片url
    * @param content
    *            课程介绍
    *            课程介绍
    * @return
    */
   @PostMapping(value = "/add")
   public Result add(String subjectName, String imgPath, String content,int type) {
   public Result add(String subjectName, String imgPath, String content, int type, String startTime, String endTime) {
      String contentFileId = null;
      
      if(StringUtils.isNotEmpty(content)){
@@ -204,21 +213,25 @@
      if (StringUtils.isNotBlank(imgPath)) {
         coverPageFileId = fileService.readIdByPath(imgPath);
      }
      return subjectService.add(subjectName, coverPageFileId,contentFileId,type);
      try {
         return subjectService.add(subjectName, coverPageFileId,contentFileId,type, DateUtils.convertStringToDate(startTime),DateUtils.convertStringToDate(endTime));
      }catch (ParseException e) {
         log.error(e, e);
         return new Result(false, "日期参数错误");
      }
   }
   /**
    * 新增练习
    * 新增练习
    * 
    * @param name
    *            题目名称
    *            题目名称
    * @param type
    *            题库类型
    *            题库类型
    * @param difficulty
    *            难度系数
    *            难度系数
    * @param repeatFlag
    *            是否重复
    *            是否重复
    * @return
    */
   @PostMapping(value = "addExercise")
@@ -227,16 +240,16 @@
   }
   /**
    * 更新课程
    * 更新课程
    * 
    * @param subjectId
    *            课程id
    *            课程id
    * @param subjectName
    *            课程名称
    *            课程名称
    * @param imgPath
    *            ͼƬurl
    *            图片url
    * @param content
    *            课程介绍
    *            课程介绍
    */
   @PostMapping(value = "/update")
   public Result update(String subjectId, String subjectName, String imgPath, String content,int type) {
@@ -256,14 +269,14 @@
   }
   /**
    * 更新课程获取课程内容
    * 更新课程获取课程内容
    * 
    * @param subjectId
    *            课程id
    *            课程id
    */
   @ApiOperation(value = "获取课程详情-教师端", notes = "")
   @ApiOperation(value = "获取课程详情-教师端", notes = "")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "subjectId", value = "课程id", required = false, paramType="query", dataType = "String")
        @ApiImplicitParam(name = "subjectId", value = "课程id", required = false, paramType="query", dataType = "String")
    })
   @GetMapping(value = "getSubjectDetail")
   public Result getSubjectDetail(String subjectId) {
@@ -288,14 +301,14 @@
   
   
   /**
    * 获取可用课程下拉列表接口
    * 获取可用课程下拉列表接口
    * 
    * @param examId
    * @return
    */
   @RequestMapping(value = "/selectlist", method = RequestMethod.GET)
   public @ResponseBody List<Map<String,Object>> subjectList(Integer subjectType) {
      //判断是否是教师
      //判断是否是教师
       String teacherId = ClientUtils.isAdmin() ? null : teacherService.getTeacherIdByUserId(ClientUtils.getUserId());
      
       if(subjectType==null){