图谱-后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

141 lines
5.3 KiB

package com.teaching.backend.controller.courses;
import com.teaching.backend.common.BaseResponse;
import com.teaching.backend.common.CommonResult;
import com.teaching.backend.common.ResultUtils;
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.courses.PersonalCenterStudentListVO;
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.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
/**
* <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")
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){
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("编辑成功");
}
@ApiOperation("根据id删除课程")
@ValidateParams({"id"})
@DeleteMapping("/{id}")
public BaseResponse deleteCourses(@PathVariable String id){
coursesService.deleteBatchByIds(id);
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<List<PersonalCenterStudentListVO>> getStudentList(@RequestParam String userId){
List<PersonalCenterStudentListVO> umsStudentList = coursesService.queryStudentList(userId);
return CommonResult.success(umsStudentList);
}
}