|
|
|
package com.teaching.backend.controller.courses;
|
|
|
|
|
|
|
|
|
|
|
|
import com.teaching.backend.common.BaseResponse;
|
|
|
|
import com.teaching.backend.common.CommonResult;
|
|
|
|
import com.teaching.backend.common.ErrorCode;
|
|
|
|
import com.teaching.backend.common.ResultUtils;
|
|
|
|
import com.teaching.backend.exception.BusinessException;
|
|
|
|
|
|
|
|
import com.teaching.backend.filter.ValidateParams;
|
|
|
|
import com.teaching.backend.model.dto.courses.CoursesDTO;
|
|
|
|
import com.teaching.backend.model.dto.courses.PageDTO;
|
|
|
|
|
|
|
|
import com.teaching.backend.model.entity.courses.Courses;
|
|
|
|
import com.teaching.backend.model.entity.umsAdmin.UmsStudent;
|
|
|
|
import com.teaching.backend.model.query.CourseQuery;
|
|
|
|
import com.teaching.backend.model.vo.courses.CoursesVO;
|
|
|
|
import com.teaching.backend.model.vo.umsAdmin.UmsStudentVO;
|
|
|
|
import com.teaching.backend.service.courses.ICoursesService;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>
|
|
|
|
* 前端控制器
|
|
|
|
* </p>
|
|
|
|
*
|
|
|
|
* @author zjh
|
|
|
|
* @since 2024-05-30
|
|
|
|
*/
|
|
|
|
@Api(tags = "课程管理接口")
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/api/coursesteacher")
|
|
|
|
public class CoursesController {
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
ICoursesService coursesService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @ApiOperation("网站首页")
|
|
|
|
// @GetMapping("/index")
|
|
|
|
// public BaseResponse<Map<String,Object>> getData(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize) {
|
|
|
|
// List<CoursesVO> coursesVo = coursesService.getPagePageSize(page, pageSize);
|
|
|
|
//// System.out.println(coursesVo);
|
|
|
|
// long totalcount = coursesService.count();
|
|
|
|
// long toatlPages = (int) Math.ceil((double)totalcount / pageSize);
|
|
|
|
// Map<String,Object> objectMap = new HashMap<>();
|
|
|
|
// objectMap.put("content",coursesVo);
|
|
|
|
// objectMap.put("totalcount", totalcount);
|
|
|
|
// objectMap.put("totalPages", toatlPages);
|
|
|
|
// objectMap.put("currentPage", page);
|
|
|
|
// return ResultUtils.success(objectMap);
|
|
|
|
// }
|
|
|
|
|
|
|
|
@ApiOperation("网站首页")
|
|
|
|
@GetMapping("/index")
|
|
|
|
public BaseResponse<Map<String,Object>> getData(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize) {
|
|
|
|
Map<String, Object> result = coursesService.getPagePageSize2(page, pageSize);
|
|
|
|
|
|
|
|
// 将结果放入新的Map对象中返回
|
|
|
|
Map<String, Object> objectMap = new HashMap<>();
|
|
|
|
objectMap.put("content", result.get("courses"));
|
|
|
|
objectMap.put("totalcount", result.get("totalcount"));
|
|
|
|
objectMap.put("totalPages", result.get("totalPages"));
|
|
|
|
objectMap.put("currentPage", result.get("currentPage"));
|
|
|
|
|
|
|
|
return ResultUtils.success(objectMap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("新增课程--同步新增课程的总体目标并同时添加所有的分项目标")
|
|
|
|
@ValidateParams({"teacher","img", "category", "nature","name","code","credit","classhours","assessmenttype","assessmentway"}) // 需要校验的参数
|
|
|
|
@PostMapping("/addcourse")
|
|
|
|
public BaseResponse<String> saveCourse(@RequestBody CoursesDTO coursesDTO){
|
|
|
|
String data = coursesService.saveCourseWithObjective(coursesDTO);
|
|
|
|
return ResultUtils.success(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("查询课程列表")
|
|
|
|
@ValidateParams({"userId"})
|
|
|
|
@GetMapping("/page")
|
|
|
|
// @PostMapping("/page")
|
|
|
|
public BaseResponse<PageDTO<CoursesVO>> getCourses(CourseQuery courseQuery){
|
|
|
|
PageDTO<CoursesVO> coursesList = coursesService.queryCourses(courseQuery);
|
|
|
|
return ResultUtils.success(coursesList);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation("根据id查询课程")
|
|
|
|
@ValidateParams({"id"})
|
|
|
|
@GetMapping("/{id}")
|
|
|
|
public BaseResponse<CoursesDTO> getByIdCourse(@PathVariable String id){
|
|
|
|
if(id==null){
|
|
|
|
throw new BusinessException(ErrorCode.PARAMS_ERROR,"课程id为空");
|
|
|
|
}
|
|
|
|
Courses course = coursesService.getById(id);
|
|
|
|
CoursesDTO coursesDTO = new CoursesDTO();
|
|
|
|
BeanUtils.copyProperties(course,coursesDTO);
|
|
|
|
return ResultUtils.success(coursesDTO);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation("根据id修改课程")
|
|
|
|
@ValidateParams({"id","teacher","img", "category", "nature","name","code","credit","classhours","assessmenttype","assessmentway"})
|
|
|
|
@PutMapping
|
|
|
|
public BaseResponse<String> editCourse(@RequestBody CoursesDTO coursesDTO){
|
|
|
|
coursesService.updateCourse(coursesDTO);
|
|
|
|
return ResultUtils.success("编辑成功");
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO:删除功能暂未完善,数据缺失
|
|
|
|
// 暂时发现有个漏洞 就是目标关联的有知识点的时候还是可以直接删除
|
|
|
|
// (当有内容的时候本来就是得先删除内容--关联也有知识点 所以内容下面的不用校验 )
|
|
|
|
@ApiOperation("根据id删除课程")
|
|
|
|
@ValidateParams({"id"})
|
|
|
|
@DeleteMapping("/{id}")
|
|
|
|
public BaseResponse deleteCourses(@PathVariable String id){
|
|
|
|
|
|
|
|
coursesService.deleteBatchByIds(id);
|
|
|
|
// coursesService.removeBatchByIds(ids);
|
|
|
|
return ResultUtils.success("删除成功");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 导出word
|
|
|
|
* @param response
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
@ApiOperation("导出word")
|
|
|
|
@GetMapping(value = "/down")
|
|
|
|
public void test( HttpServletResponse response) throws Exception{
|
|
|
|
//-------------------------查询课程通过课程id查
|
|
|
|
String id = "de3100cad98f76be3176dd39aa748a9e";
|
|
|
|
coursesService.down(response, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation("查询学生列表")
|
|
|
|
@PostMapping("/studentList")
|
|
|
|
public CommonResult<HashSet<UmsStudent>> getStudentList(CourseQuery courseQuery){
|
|
|
|
HashSet<UmsStudent> umsStudentList = coursesService.queryStudentList(courseQuery);
|
|
|
|
return CommonResult.success(umsStudentList);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|