|
@@ -1,232 +1,241 @@
|
|
|
-package cn.com.qmth.examcloud.service.core.api;
|
|
|
-
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-import java.util.stream.Stream;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.domain.PageRequest;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
-import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.PutMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
-import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
-
|
|
|
-import com.google.common.collect.Lists;
|
|
|
-
|
|
|
-import cn.com.qmth.examcloud.commons.base.util.ErrorMsg;
|
|
|
-import cn.com.qmth.examcloud.commons.base.util.excel.ExcelError;
|
|
|
-import cn.com.qmth.examcloud.commons.web.security.entity.AccessUser;
|
|
|
-import cn.com.qmth.examcloud.core.basic.dao.CourseRepo;
|
|
|
-import cn.com.qmth.examcloud.core.basic.dao.entity.Course;
|
|
|
-import cn.com.qmth.examcloud.core.basic.service.bean.CourseAssembler;
|
|
|
-import cn.com.qmth.examcloud.core.basic.service.bean.CourseDto;
|
|
|
-import cn.com.qmth.examcloud.core.basic.service.impl.CourseService;
|
|
|
-import cn.com.qmth.examcloud.core.basic.service.impl.ExportService;
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
-
|
|
|
-/**
|
|
|
- * 课程服务API
|
|
|
- * Created by songyue on 17/1/14.
|
|
|
- */
|
|
|
-@RestController
|
|
|
-@RequestMapping("${app.api.root}/course")
|
|
|
-public class CourseApi {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- CourseRepo courseRepo;
|
|
|
- @Autowired
|
|
|
- CourseService courseService;
|
|
|
- @Autowired
|
|
|
- CourseAssembler courseAssembler;
|
|
|
-
|
|
|
- @ApiOperation(value="查询课程分页带查询",notes="分页带查询")
|
|
|
- @GetMapping("/all/{curPage}/{pageSize}")
|
|
|
- public ResponseEntity getAllOrg(@ModelAttribute Course course,
|
|
|
- @RequestParam(required = false ) Long specialtyId,
|
|
|
- @PathVariable Integer curPage,
|
|
|
- @PathVariable Integer pageSize,
|
|
|
- HttpServletRequest request){
|
|
|
- AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
- if(accessUser != null){
|
|
|
- course.setOrgId(accessUser.getRootOrgId());
|
|
|
- }else{
|
|
|
- return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
|
- }
|
|
|
- return new ResponseEntity(courseService.findAll(course,specialtyId,new PageRequest(curPage - 1,pageSize)), HttpStatus.OK);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value="按代码或名称查询课程",notes = "代码或名称查询")
|
|
|
- @GetMapping("/codeOrName")
|
|
|
- public ResponseEntity getByCodeName(@RequestParam String codeName,HttpServletRequest request){
|
|
|
- AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
- if(accessUser != null){
|
|
|
- return new ResponseEntity(courseRepo.findByCodeName(accessUser.getRootOrgId(),codeName), HttpStatus.OK);
|
|
|
- }else{
|
|
|
- return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value="查询课程不分页带查询",notes = "不分页带查询")
|
|
|
- @GetMapping("/all")
|
|
|
- public ResponseEntity getEnableExam(@ModelAttribute Course course,HttpServletRequest request){
|
|
|
- AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
- if(accessUser != null){
|
|
|
- course.setOrgId(accessUser.getRootOrgId());
|
|
|
- }
|
|
|
- course.setEnable(true);
|
|
|
- return new ResponseEntity(courseService.findAll(course), HttpStatus.OK);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value="查询课程不分页带查询",notes = "不分页带查询")
|
|
|
- @GetMapping("/all/both")
|
|
|
- public ResponseEntity getAllExam(@ModelAttribute Course course,HttpServletRequest request){
|
|
|
- AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
- if(accessUser != null){
|
|
|
- course.setOrgId(accessUser.getRootOrgId());
|
|
|
- }
|
|
|
- return new ResponseEntity(courseService.findAll(course), HttpStatus.OK);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value="按ID查询课程",notes="ID查询")
|
|
|
- @GetMapping("/{id}")
|
|
|
- public ResponseEntity getCourseById(@PathVariable Long id){
|
|
|
- return new ResponseEntity(courseRepo.findOne(id),HttpStatus.OK);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value="按code查询课程",notes="code查询")
|
|
|
- @GetMapping()
|
|
|
- public ResponseEntity getCourseByCode(@RequestParam Long orgId,@RequestParam String code){
|
|
|
- return new ResponseEntity(courseRepo.findByOrgIdAndCode(orgId, code),HttpStatus.OK);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value="按orgId查询课程",notes="orgId查询")
|
|
|
- @GetMapping("/org/{orgId}")
|
|
|
- public ResponseEntity getCourseByOrgId(@PathVariable Long orgId){
|
|
|
- return new ResponseEntity(courseRepo.findByOrgId(orgId),HttpStatus.OK);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "批量查询课程", notes = "批量查询课程")
|
|
|
- @PostMapping("/batchGetCourses")
|
|
|
- public ResponseEntity<List<Course>> batchGetCourses(@RequestBody String[] funcIds, HttpServletRequest request) {
|
|
|
- List<Course> list = Lists.newArrayList();
|
|
|
- for (String id : funcIds) {
|
|
|
- Course one = courseRepo.findOne(Long.parseLong(id));
|
|
|
- if (null != one) {
|
|
|
- list.add(one);
|
|
|
- }
|
|
|
- }
|
|
|
- return new ResponseEntity<List<Course>>(list, HttpStatus.OK);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value="新增课程",notes="新增")
|
|
|
- @PostMapping
|
|
|
- public ResponseEntity addCourse(@RequestBody Course course,HttpServletRequest request){
|
|
|
- course.setCreateTime(new Date());
|
|
|
- AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
- if(accessUser != null){
|
|
|
- course.setOrgId(accessUser.getRootOrgId());
|
|
|
- }else{
|
|
|
- return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
|
- }
|
|
|
- try {
|
|
|
- return new ResponseEntity(courseService.save(course),HttpStatus.CREATED);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value="更新课程",notes="更新")
|
|
|
- @PutMapping
|
|
|
- public ResponseEntity updateCourse(@RequestBody Course course,HttpServletRequest request){
|
|
|
- AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
- if(accessUser != null){
|
|
|
- course.setOrgId(accessUser.getRootOrgId());
|
|
|
- }else{
|
|
|
- return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
|
- }
|
|
|
- try {
|
|
|
- return new ResponseEntity(courseService.update(course.getId(),course), HttpStatus.OK);
|
|
|
- } catch (Exception e) {
|
|
|
- return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value="按ID删除课程",notes="删除")
|
|
|
- @DeleteMapping("/{ids}")
|
|
|
- public ResponseEntity deleteCourse(@PathVariable String ids){
|
|
|
- courseService.delete(ids);
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value="导入课程",notes = "导入")
|
|
|
- @PostMapping("/import")
|
|
|
- public ResponseEntity importCourse(HttpServletRequest request,
|
|
|
- @RequestParam CommonsMultipartFile file){
|
|
|
- AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
- Long orgId = null;
|
|
|
- if(accessUser != null){
|
|
|
- orgId = accessUser.getRootOrgId();
|
|
|
- }else{
|
|
|
- return new ResponseEntity(new ErrorMsg("用户token不存在或已失效"),HttpStatus.NOT_FOUND);
|
|
|
- }
|
|
|
- try {
|
|
|
- List<ExcelError> errors = courseService.importCourse(orgId,file.getInputStream());
|
|
|
- return new ResponseEntity(errors,HttpStatus.OK);
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value="下载导入模板",notes = "下载导入模板")
|
|
|
- @GetMapping("/download")
|
|
|
- public void importFileTemplate(HttpServletResponse response){
|
|
|
- List<CourseDto> list= new ArrayList<CourseDto>();
|
|
|
- list.add(new CourseDto("大学英语", "000001", "0"));
|
|
|
- ExportService.exportEXCEL("课程导入模板", CourseDto.class, list, response);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value="导出课程",notes = "导出")
|
|
|
- @GetMapping("/export")
|
|
|
- public void exportCourse(@ModelAttribute Course orgCriteria,HttpServletResponse response){
|
|
|
- List<CourseDto> list = new ArrayList<CourseDto>();
|
|
|
- courseService.findAll(orgCriteria).forEach(c -> {
|
|
|
- list.add(courseAssembler.toDTO(c));
|
|
|
- });
|
|
|
- ExportService.exportEXCEL("课程列表", CourseDto.class, list, response);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value="禁用课程",notes="禁用")
|
|
|
- @PutMapping("/disable/{ids}")
|
|
|
- public ResponseEntity disableCourse(@PathVariable String ids){
|
|
|
- List<Long> courseIds = Stream.of(ids.split(",")).map(s->Long.parseLong(s.trim()))
|
|
|
- .collect(Collectors.toList());
|
|
|
- courseService.enableCourse(courseIds,false);
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value="启用课程",notes="启用")
|
|
|
- @PutMapping("/enable/{ids}")
|
|
|
- public ResponseEntity enableCourse(@PathVariable String ids){
|
|
|
- List<Long> courseIds = Stream.of(ids.split(",")).map(s->Long.parseLong(s.trim()))
|
|
|
- .collect(Collectors.toList());
|
|
|
- courseService.enableCourse(courseIds,true);
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
- }
|
|
|
-}
|
|
|
+package cn.com.qmth.examcloud.service.core.api;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
+
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.commons.base.util.ErrorMsg;
|
|
|
+import cn.com.qmth.examcloud.commons.base.util.excel.ExcelError;
|
|
|
+import cn.com.qmth.examcloud.commons.web.security.bean.User;
|
|
|
+import cn.com.qmth.examcloud.commons.web.security.entity.AccessUser;
|
|
|
+import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.CourseRepo;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.Course;
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.bean.CourseAssembler;
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.bean.CourseDto;
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.impl.CourseService;
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.impl.ExportService;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 课程服务API
|
|
|
+ * Created by songyue on 17/1/14.
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("${app.api.root}/course")
|
|
|
+public class CourseApi extends ControllerSupport {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CourseRepo courseRepo;
|
|
|
+ @Autowired
|
|
|
+ CourseService courseService;
|
|
|
+ @Autowired
|
|
|
+ CourseAssembler courseAssembler;
|
|
|
+
|
|
|
+ @ApiOperation(value="查询课程分页带查询",notes="分页带查询")
|
|
|
+ @GetMapping("/all/{curPage}/{pageSize}")
|
|
|
+ public ResponseEntity getAllOrg(@ModelAttribute Course course,
|
|
|
+ @RequestParam(required = false ) Long specialtyId,
|
|
|
+ @PathVariable Integer curPage,
|
|
|
+ @PathVariable Integer pageSize,
|
|
|
+ HttpServletRequest request){
|
|
|
+ //AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
+ User user = getAccessUser();
|
|
|
+ if(user != null){
|
|
|
+ course.setOrgId(user.getRootOrgId());
|
|
|
+ }else{
|
|
|
+ return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
|
+ }
|
|
|
+ return new ResponseEntity(courseService.findAll(course,specialtyId,new PageRequest(curPage - 1,pageSize)), HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="按代码或名称查询课程",notes = "代码或名称查询")
|
|
|
+ @GetMapping("/codeOrName")
|
|
|
+ public ResponseEntity getByCodeName(@RequestParam String codeName,HttpServletRequest request){
|
|
|
+ //AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
+ User user = getAccessUser();
|
|
|
+ if(user != null){
|
|
|
+ return new ResponseEntity(courseRepo.findByCodeName(user.getRootOrgId(),codeName), HttpStatus.OK);
|
|
|
+ }else{
|
|
|
+ return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="查询课程不分页带查询",notes = "不分页带查询")
|
|
|
+ @GetMapping("/all")
|
|
|
+ public ResponseEntity getEnableExam(@ModelAttribute Course course,HttpServletRequest request){
|
|
|
+ User user = getAccessUser();
|
|
|
+ //AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
+ if(user != null){
|
|
|
+ course.setOrgId(user.getRootOrgId());
|
|
|
+ }
|
|
|
+ course.setEnable(true);
|
|
|
+ return new ResponseEntity(courseService.findAll(course), HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="查询课程不分页带查询",notes = "不分页带查询")
|
|
|
+ @GetMapping("/all/both")
|
|
|
+ public ResponseEntity getAllExam(@ModelAttribute Course course,HttpServletRequest request){
|
|
|
+ User user = getAccessUser();
|
|
|
+ //AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
+ if(user != null){
|
|
|
+ course.setOrgId(user.getRootOrgId());
|
|
|
+ }
|
|
|
+ return new ResponseEntity(courseService.findAll(course), HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="按ID查询课程",notes="ID查询")
|
|
|
+ @GetMapping("/{id}")
|
|
|
+ public ResponseEntity getCourseById(@PathVariable Long id){
|
|
|
+ return new ResponseEntity(courseRepo.findOne(id),HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="按code查询课程",notes="code查询")
|
|
|
+ @GetMapping()
|
|
|
+ public ResponseEntity getCourseByCode(@RequestParam Long orgId,@RequestParam String code){
|
|
|
+ return new ResponseEntity(courseRepo.findByOrgIdAndCode(orgId, code),HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="按orgId查询课程",notes="orgId查询")
|
|
|
+ @GetMapping("/org/{orgId}")
|
|
|
+ public ResponseEntity getCourseByOrgId(@PathVariable Long orgId){
|
|
|
+ return new ResponseEntity(courseRepo.findByOrgId(orgId),HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "批量查询课程", notes = "批量查询课程")
|
|
|
+ @PostMapping("/batchGetCourses")
|
|
|
+ public ResponseEntity<List<Course>> batchGetCourses(@RequestBody String[] funcIds, HttpServletRequest request) {
|
|
|
+ List<Course> list = Lists.newArrayList();
|
|
|
+ for (String id : funcIds) {
|
|
|
+ Course one = courseRepo.findOne(Long.parseLong(id));
|
|
|
+ if (null != one) {
|
|
|
+ list.add(one);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new ResponseEntity<List<Course>>(list, HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="新增课程",notes="新增")
|
|
|
+ @PostMapping
|
|
|
+ public ResponseEntity addCourse(@RequestBody Course course,HttpServletRequest request){
|
|
|
+ course.setCreateTime(new Date());
|
|
|
+ User user = getAccessUser();
|
|
|
+ //AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
+ if(user != null){
|
|
|
+ course.setOrgId(user.getRootOrgId());
|
|
|
+ }else{
|
|
|
+ return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return new ResponseEntity(courseService.save(course),HttpStatus.CREATED);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="更新课程",notes="更新")
|
|
|
+ @PutMapping
|
|
|
+ public ResponseEntity updateCourse(@RequestBody Course course,HttpServletRequest request){
|
|
|
+ User user = getAccessUser();
|
|
|
+ //AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
+ if(user != null){
|
|
|
+ course.setOrgId(user.getRootOrgId());
|
|
|
+ }else{
|
|
|
+ return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return new ResponseEntity(courseService.update(course.getId(),course), HttpStatus.OK);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="按ID删除课程",notes="删除")
|
|
|
+ @DeleteMapping("/{ids}")
|
|
|
+ public ResponseEntity deleteCourse(@PathVariable String ids){
|
|
|
+ courseService.delete(ids);
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="导入课程",notes = "导入")
|
|
|
+ @PostMapping("/import")
|
|
|
+ public ResponseEntity importCourse(HttpServletRequest request,
|
|
|
+ @RequestParam CommonsMultipartFile file){
|
|
|
+ User user = getAccessUser();
|
|
|
+ //AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
+ Long orgId = null;
|
|
|
+ if(user != null){
|
|
|
+ orgId = user.getRootOrgId();
|
|
|
+ }else{
|
|
|
+ return new ResponseEntity(new ErrorMsg("用户token不存在或已失效"),HttpStatus.NOT_FOUND);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ List<ExcelError> errors = courseService.importCourse(orgId,file.getInputStream());
|
|
|
+ return new ResponseEntity(errors,HttpStatus.OK);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="下载导入模板",notes = "下载导入模板")
|
|
|
+ @GetMapping("/download")
|
|
|
+ public void importFileTemplate(HttpServletResponse response){
|
|
|
+ List<CourseDto> list= new ArrayList<CourseDto>();
|
|
|
+ list.add(new CourseDto("大学英语", "000001", "0"));
|
|
|
+ ExportService.exportEXCEL("课程导入模板", CourseDto.class, list, response);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="导出课程",notes = "导出")
|
|
|
+ @GetMapping("/export")
|
|
|
+ public void exportCourse(@ModelAttribute Course orgCriteria,HttpServletResponse response){
|
|
|
+ List<CourseDto> list = new ArrayList<CourseDto>();
|
|
|
+ courseService.findAll(orgCriteria).forEach(c -> {
|
|
|
+ list.add(courseAssembler.toDTO(c));
|
|
|
+ });
|
|
|
+ ExportService.exportEXCEL("课程列表", CourseDto.class, list, response);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="禁用课程",notes="禁用")
|
|
|
+ @PutMapping("/disable/{ids}")
|
|
|
+ public ResponseEntity disableCourse(@PathVariable String ids){
|
|
|
+ List<Long> courseIds = Stream.of(ids.split(",")).map(s->Long.parseLong(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ courseService.enableCourse(courseIds,false);
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="启用课程",notes="启用")
|
|
|
+ @PutMapping("/enable/{ids}")
|
|
|
+ public ResponseEntity enableCourse(@PathVariable String ids){
|
|
|
+ List<Long> courseIds = Stream.of(ids.split(",")).map(s->Long.parseLong(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ courseService.enableCourse(courseIds,true);
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
+ }
|
|
|
+}
|