|
@@ -1,6 +1,5 @@
|
|
package cn.com.qmth.examcloud.core.basic.api.controller;
|
|
package cn.com.qmth.examcloud.core.basic.api.controller;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -12,16 +11,14 @@ import javax.persistence.criteria.Subquery;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.PageRequest;
|
|
import org.springframework.data.domain.PageRequest;
|
|
import org.springframework.data.domain.Sort;
|
|
import org.springframework.data.domain.Sort;
|
|
import org.springframework.data.domain.Sort.Direction;
|
|
import org.springframework.data.domain.Sort.Direction;
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
-import org.springframework.http.HttpStatus;
|
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
-import org.springframework.util.StringUtils;
|
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
@@ -36,6 +33,7 @@ import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
import cn.com.qmth.examcloud.commons.base.util.excel.ExcelError;
|
|
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.bean.User;
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
@@ -44,11 +42,11 @@ import cn.com.qmth.examcloud.core.basic.api.bean.CourseBean;
|
|
import cn.com.qmth.examcloud.core.basic.api.request.SaveCourseReq;
|
|
import cn.com.qmth.examcloud.core.basic.api.request.SaveCourseReq;
|
|
import cn.com.qmth.examcloud.core.basic.api.response.SaveCourseResp;
|
|
import cn.com.qmth.examcloud.core.basic.api.response.SaveCourseResp;
|
|
import cn.com.qmth.examcloud.core.basic.dao.CourseRepo;
|
|
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.dao.entity.CourseSpeciatly;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.CourseEntity;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.CourseSpeciatlyRelationEntity;
|
|
import cn.com.qmth.examcloud.core.basic.service.bean.CourseAssembler;
|
|
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.bean.CourseDto;
|
|
-import cn.com.qmth.examcloud.core.basic.service.impl.CourseService;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.service.impl.CourseServiceImpl;
|
|
import cn.com.qmth.examcloud.core.basic.service.impl.ExportService;
|
|
import cn.com.qmth.examcloud.core.basic.service.impl.ExportService;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
@@ -64,7 +62,7 @@ public class CourseController extends ControllerSupport {
|
|
CourseRepo courseRepo;
|
|
CourseRepo courseRepo;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- CourseService courseService;
|
|
|
|
|
|
+ CourseServiceImpl courseService;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
CourseAssembler courseAssembler;
|
|
CourseAssembler courseAssembler;
|
|
@@ -76,119 +74,166 @@ public class CourseController extends ControllerSupport {
|
|
* 方法注释
|
|
* 方法注释
|
|
*
|
|
*
|
|
* @author WANGWEI
|
|
* @author WANGWEI
|
|
- * @param courseCriteria
|
|
|
|
- * @param specialtyId
|
|
|
|
* @param curPage
|
|
* @param curPage
|
|
* @param pageSize
|
|
* @param pageSize
|
|
- * @param request
|
|
|
|
|
|
+ * @param name
|
|
|
|
+ * @param code
|
|
|
|
+ * @param level
|
|
|
|
+ * @param enable
|
|
|
|
+ * @param specialtyId
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- @ApiOperation(value = "查询课程分页带查询", notes = "分页带查询")
|
|
|
|
- @GetMapping("/all/{curPage}/{pageSize}")
|
|
|
|
- public Page<Course> getCourseList(@ModelAttribute Course courseCriteria,
|
|
|
|
- @RequestParam(required = false) Long specialtyId, @PathVariable Integer curPage,
|
|
|
|
- @PathVariable Integer pageSize, HttpServletRequest request) {
|
|
|
|
|
|
+ @ApiOperation(value = "分页查询课程")
|
|
|
|
+ @GetMapping("coursePage/{curPage}/{pageSize}")
|
|
|
|
+ public Page<CourseEntity> getCoursePage(@PathVariable Integer curPage, @PathVariable Integer pageSize,
|
|
|
|
+ @RequestParam(required = false) String name,
|
|
|
|
+ @RequestParam(required = false) String code,
|
|
|
|
+ @RequestParam(required = false) String level,
|
|
|
|
+ @RequestParam(required = false) Boolean enable,
|
|
|
|
+ @RequestParam(required = false) Long specialtyId) {
|
|
|
|
+
|
|
User accessUser = getAccessUser();
|
|
User accessUser = getAccessUser();
|
|
|
|
|
|
- Specification<Course> specification = (root, query, cb) -> {
|
|
|
|
|
|
+ Specification<CourseEntity> specification = (root, query, cb) -> {
|
|
List<Predicate> predicates = new ArrayList<>();
|
|
List<Predicate> predicates = new ArrayList<>();
|
|
|
|
|
|
- predicates.add(cb.equal(root.get("orgId"), accessUser.getRootOrgId()));
|
|
|
|
|
|
+ predicates.add(cb.equal(root.get("rootOrgId"), accessUser.getRootOrgId()));
|
|
|
|
|
|
- if (!StringUtils.isEmpty(courseCriteria.getName())) {
|
|
|
|
- predicates.add(cb.like(root.get("name"), "%" + courseCriteria.getName() + "%"));
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(name)) {
|
|
|
|
+ predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
|
|
}
|
|
}
|
|
- if (!StringUtils.isEmpty(courseCriteria.getCode())) {
|
|
|
|
- predicates.add(cb.like(root.get("code"), "%" + courseCriteria.getCode() + "%"));
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(code)) {
|
|
|
|
+ predicates.add(cb.like(root.get("code"), toSqlSearchPattern(code)));
|
|
}
|
|
}
|
|
- if (!StringUtils.isEmpty(courseCriteria.getLevel())) {
|
|
|
|
- predicates.add(cb.equal(root.get("level"), courseCriteria.getLevel()));
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(level)) {
|
|
|
|
+ predicates.add(cb.equal(root.get("level"), toSqlSearchPattern(level)));
|
|
}
|
|
}
|
|
- if (!StringUtils.isEmpty(courseCriteria.getEnable())) {
|
|
|
|
- predicates.add(cb.equal(root.get("enable"), courseCriteria.getEnable()));
|
|
|
|
|
|
+ if (null != enable) {
|
|
|
|
+ predicates.add(cb.equal(root.get("enable"), enable));
|
|
}
|
|
}
|
|
- if (specialtyId != null) {
|
|
|
|
- Subquery<CourseSpeciatly> subquery = query.subquery(CourseSpeciatly.class);
|
|
|
|
- Root<CourseSpeciatly> subRoot = subquery.from(CourseSpeciatly.class);
|
|
|
|
|
|
+
|
|
|
|
+ if (null != specialtyId) {
|
|
|
|
+ Subquery<CourseSpeciatlyRelationEntity> subquery = query.subquery(CourseSpeciatlyRelationEntity.class);
|
|
|
|
+ Root<CourseSpeciatlyRelationEntity> subRoot = subquery.from(CourseSpeciatlyRelationEntity.class);
|
|
subquery.select(subRoot);
|
|
subquery.select(subRoot);
|
|
Predicate p1 = cb.equal(subRoot.get("specialtyId"), specialtyId);
|
|
Predicate p1 = cb.equal(subRoot.get("specialtyId"), specialtyId);
|
|
Predicate p2 = cb.equal(subRoot.get("courseId"), root.get("id"));
|
|
Predicate p2 = cb.equal(subRoot.get("courseId"), root.get("id"));
|
|
subquery.where(cb.and(p1, p2));
|
|
subquery.where(cb.and(p1, p2));
|
|
predicates.add(cb.exists(subquery));
|
|
predicates.add(cb.exists(subquery));
|
|
}
|
|
}
|
|
|
|
+
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
};
|
|
};
|
|
|
|
|
|
- PageRequest pageRequest = new PageRequest(curPage - 1, pageSize,
|
|
|
|
|
|
+ PageRequest pageRequest = new PageRequest(curPage, pageSize,
|
|
new Sort(Direction.DESC, "updateTime"));
|
|
new Sort(Direction.DESC, "updateTime"));
|
|
|
|
|
|
- Page<Course> page = courseRepo.findAll(specification, pageRequest);
|
|
|
|
|
|
+ Page<CourseEntity> page = courseRepo.findAll(specification, pageRequest);
|
|
return page;
|
|
return page;
|
|
}
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "按代码或名称查询课程", notes = "代码或名称查询")
|
|
|
|
- @GetMapping("/codeOrName")
|
|
|
|
- public ResponseEntity getByCodeName(@RequestParam String codeName, HttpServletRequest request) {
|
|
|
|
- cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
|
|
|
|
- if (accessUser != null) {
|
|
|
|
- return new ResponseEntity(
|
|
|
|
- courseRepo.findByCodeName(accessUser.getRootOrgId(), codeName), HttpStatus.OK);
|
|
|
|
- } else {
|
|
|
|
- return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 方法注释
|
|
|
|
+ *
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ * @param name
|
|
|
|
+ * @param code
|
|
|
|
+ * @param level
|
|
|
|
+ * @param enable
|
|
|
|
+ * @param specialtyId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "查询课程")
|
|
|
|
+ @GetMapping("queryByNameLike")
|
|
|
|
+ public List<CourseEntity> queryByNameLike(@RequestParam(required = false) String name,
|
|
|
|
+ @RequestParam(required = false) String code,
|
|
|
|
+ @RequestParam(required = false) String level,
|
|
|
|
+ @RequestParam(required = false) Boolean enable,
|
|
|
|
+ @RequestParam(required = false) Long specialtyId) {
|
|
|
|
|
|
- @ApiOperation(value = "查询课程不分页带查询", notes = "不分页带查询")
|
|
|
|
- @GetMapping("/all")
|
|
|
|
- public ResponseEntity getEnableExam(@ModelAttribute Course course, HttpServletRequest request) {
|
|
|
|
- cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
|
|
|
|
- if (accessUser != null) {
|
|
|
|
- course.setOrgId(accessUser.getRootOrgId());
|
|
|
|
|
|
+ User accessUser = getAccessUser();
|
|
|
|
+ Long rootOrgId = accessUser.getRootOrgId();
|
|
|
|
+ // 过载保护
|
|
|
|
+ int total = courseRepo.countByRootOrgIdAndNameLike(rootOrgId, name);
|
|
|
|
+ if (total > 1000) {
|
|
|
|
+ List<CourseEntity> list = Lists.newArrayList();
|
|
|
|
+ return list;
|
|
}
|
|
}
|
|
- 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) {
|
|
|
|
- cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
|
|
|
|
- if (accessUser != null) {
|
|
|
|
- course.setOrgId(accessUser.getRootOrgId());
|
|
|
|
- }
|
|
|
|
- return new ResponseEntity(courseService.findAll(course), HttpStatus.OK);
|
|
|
|
|
|
+ Specification<CourseEntity> specification = (root, query, cb) -> {
|
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ predicates.add(cb.equal(root.get("rootOrgId"), rootOrgId));
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isNotBlank(name)) {
|
|
|
|
+ predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(code)) {
|
|
|
|
+ predicates.add(cb.like(root.get("code"), toSqlSearchPattern(code)));
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(level)) {
|
|
|
|
+ predicates.add(cb.equal(root.get("level"), toSqlSearchPattern(level)));
|
|
|
|
+ }
|
|
|
|
+ if (null != enable) {
|
|
|
|
+ predicates.add(cb.equal(root.get("enable"), enable));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (null != specialtyId) {
|
|
|
|
+ Subquery<CourseSpeciatlyRelationEntity> subquery = query.subquery(CourseSpeciatlyRelationEntity.class);
|
|
|
|
+ Root<CourseSpeciatlyRelationEntity> subRoot = subquery.from(CourseSpeciatlyRelationEntity.class);
|
|
|
|
+ subquery.select(subRoot);
|
|
|
|
+ Predicate p1 = cb.equal(subRoot.get("specialtyId"), specialtyId);
|
|
|
|
+ Predicate p2 = cb.equal(subRoot.get("courseId"), root.get("id"));
|
|
|
|
+ subquery.where(cb.and(p1, p2));
|
|
|
|
+ predicates.add(cb.exists(subquery));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ List<CourseEntity> list = courseRepo.findAll(specification);
|
|
|
|
+ return list;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 方法注释
|
|
|
|
+ *
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ * @param id
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
@ApiOperation(value = "按ID查询课程", notes = "ID查询")
|
|
@ApiOperation(value = "按ID查询课程", notes = "ID查询")
|
|
- @GetMapping("/{id}")
|
|
|
|
- public ResponseEntity getCourseById(@PathVariable Long id) {
|
|
|
|
- return new ResponseEntity(courseRepo.findOne(id), HttpStatus.OK);
|
|
|
|
- }
|
|
|
|
|
|
+ @GetMapping("{id}")
|
|
|
|
+ public CourseEntity getCourseById(@PathVariable Long id) {
|
|
|
|
+ CourseEntity course = courseRepo.findOne(id);
|
|
|
|
+ if (null == course) {
|
|
|
|
+ throw new StatusException("B-540001", "课程不存在");
|
|
|
|
+ }
|
|
|
|
|
|
- @ApiOperation(value = "按code查询课程", notes = "code查询")
|
|
|
|
- @GetMapping()
|
|
|
|
- public ResponseEntity getCourseByCode(@RequestParam Long orgId, @RequestParam String code) {
|
|
|
|
- return new ResponseEntity(courseRepo.findByOrgIdAndCode(orgId, code), HttpStatus.OK);
|
|
|
|
|
|
+ Long rootOrgId = course.getRootOrgId();
|
|
|
|
+ validateRootOrgIsolation(rootOrgId);
|
|
|
|
+ return course;
|
|
}
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "按orgId查询课程", notes = "orgId查询")
|
|
|
|
- @GetMapping("/org/{orgId}")
|
|
|
|
- public ResponseEntity getCourseByOrgId(@PathVariable Long orgId) {
|
|
|
|
- return new ResponseEntity(courseRepo.findByOrgId(orgId), HttpStatus.OK);
|
|
|
|
- }
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 方法注释
|
|
|
|
+ *
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ * @param rootOrgId
|
|
|
|
+ * @param code
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @ApiOperation(value = "按code查询课程", notes = "code查询")
|
|
|
|
+ @GetMapping("byCode")
|
|
|
|
+ public CourseEntity getCourseByCode(@RequestParam Long rootOrgId, @RequestParam String code) {
|
|
|
|
+ validateRootOrgIsolation(rootOrgId);
|
|
|
|
|
|
- @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);
|
|
|
|
- }
|
|
|
|
|
|
+ CourseEntity course = courseRepo.findByRootOrgIdAndCode(rootOrgId, code);
|
|
|
|
+ if (null == course) {
|
|
|
|
+ throw new StatusException("B-540001", "课程不存在");
|
|
}
|
|
}
|
|
- return new ResponseEntity<List<Course>>(list, HttpStatus.OK);
|
|
|
|
|
|
+
|
|
|
|
+ return course;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -200,7 +245,7 @@ public class CourseController extends ControllerSupport {
|
|
*/
|
|
*/
|
|
@ApiOperation(value = "新增课程", notes = "新增")
|
|
@ApiOperation(value = "新增课程", notes = "新增")
|
|
@PostMapping
|
|
@PostMapping
|
|
- public Long addCourse(@RequestBody Course course) {
|
|
|
|
|
|
+ public Long addCourse(@RequestBody CourseEntity course) {
|
|
trim(course);
|
|
trim(course);
|
|
User accessUser = getAccessUser();
|
|
User accessUser = getAccessUser();
|
|
|
|
|
|
@@ -225,7 +270,7 @@ public class CourseController extends ControllerSupport {
|
|
*/
|
|
*/
|
|
@ApiOperation(value = "更新课程", notes = "更新")
|
|
@ApiOperation(value = "更新课程", notes = "更新")
|
|
@PutMapping
|
|
@PutMapping
|
|
- public Long updateCourse(@RequestBody Course course, HttpServletRequest request) {
|
|
|
|
|
|
+ public Long updateCourse(@RequestBody CourseEntity course, HttpServletRequest request) {
|
|
User accessUser = getAccessUser();
|
|
User accessUser = getAccessUser();
|
|
|
|
|
|
SaveCourseReq saveCourseReq = new SaveCourseReq();
|
|
SaveCourseReq saveCourseReq = new SaveCourseReq();
|
|
@@ -242,34 +287,37 @@ public class CourseController extends ControllerSupport {
|
|
return courseBean.getId();
|
|
return courseBean.getId();
|
|
}
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "按ID删除课程", notes = "删除")
|
|
|
|
- @DeleteMapping("/{ids}")
|
|
|
|
- public ResponseEntity deleteCourse(@PathVariable String ids) {
|
|
|
|
- courseService.delete(ids);
|
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
|
|
|
+ @ApiOperation(value = "删除课程", notes = "删除")
|
|
|
|
+ @DeleteMapping("{ids}")
|
|
|
|
+ public void deleteCourse(@PathVariable String ids) {
|
|
|
|
+ List<Long> courseIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ for (Long courseId : courseIds) {
|
|
|
|
+ CourseEntity one = courseRepo.findOne(courseId);
|
|
|
|
+ if (null == one) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ validateRootOrgIsolation(one.getRootOrgId());
|
|
|
|
+ courseRepo.delete(one);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value = "下载导入模板", notes = "下载导入模板")
|
|
|
|
+ @GetMapping("importTemplate")
|
|
|
|
+ public void getImportTemplate(HttpServletResponse response) {
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "导入课程", notes = "导入")
|
|
@ApiOperation(value = "导入课程", notes = "导入")
|
|
@PostMapping("/import")
|
|
@PostMapping("/import")
|
|
public List<ExcelError> importCourse(HttpServletRequest request,
|
|
public List<ExcelError> importCourse(HttpServletRequest request,
|
|
- @RequestParam CommonsMultipartFile file) throws IOException {
|
|
|
|
- User accessUser = getAccessUser();
|
|
|
|
- Long rootOrgId = accessUser.getRootOrgId();
|
|
|
|
- List<ExcelError> errors = courseService.importCourse(rootOrgId, file.getInputStream());
|
|
|
|
- return errors;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @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);
|
|
|
|
|
|
+ @RequestParam CommonsMultipartFile file) {
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "导出课程", notes = "导出")
|
|
@ApiOperation(value = "导出课程", notes = "导出")
|
|
- @GetMapping("/export")
|
|
|
|
- public void exportCourse(@ModelAttribute Course orgCriteria, HttpServletResponse response) {
|
|
|
|
|
|
+ @GetMapping("export")
|
|
|
|
+ public void exportCourse(@ModelAttribute CourseEntity orgCriteria, HttpServletResponse response) {
|
|
List<CourseDto> list = new ArrayList<CourseDto>();
|
|
List<CourseDto> list = new ArrayList<CourseDto>();
|
|
courseService.findAll(orgCriteria).forEach(c -> {
|
|
courseService.findAll(orgCriteria).forEach(c -> {
|
|
list.add(courseAssembler.toDTO(c));
|
|
list.add(courseAssembler.toDTO(c));
|
|
@@ -285,11 +333,17 @@ public class CourseController extends ControllerSupport {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@ApiOperation(value = "禁用课程", notes = "禁用")
|
|
@ApiOperation(value = "禁用课程", notes = "禁用")
|
|
- @PutMapping("/disable/{ids}")
|
|
|
|
|
|
+ @PutMapping("disable/{ids}")
|
|
public List<Long> disableCourse(@PathVariable String ids) {
|
|
public List<Long> disableCourse(@PathVariable String ids) {
|
|
List<Long> courseIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
List<Long> courseIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
- courseService.setCourseEnable(courseIds, false);
|
|
|
|
|
|
+
|
|
|
|
+ for (Long courseId : courseIds) {
|
|
|
|
+ CourseEntity course = courseRepo.findOne(courseId);
|
|
|
|
+ course.setEnable(false);
|
|
|
|
+ courseRepo.save(course);
|
|
|
|
+ }
|
|
|
|
+
|
|
return courseIds;
|
|
return courseIds;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -301,11 +355,17 @@ public class CourseController extends ControllerSupport {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@ApiOperation(value = "启用课程", notes = "启用")
|
|
@ApiOperation(value = "启用课程", notes = "启用")
|
|
- @PutMapping("/enable/{ids}")
|
|
|
|
|
|
+ @PutMapping("enable/{ids}")
|
|
public List<Long> enableCourse(@PathVariable String ids) {
|
|
public List<Long> enableCourse(@PathVariable String ids) {
|
|
List<Long> courseIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
List<Long> courseIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
- courseService.setCourseEnable(courseIds, true);
|
|
|
|
|
|
+
|
|
|
|
+ for (Long courseId : courseIds) {
|
|
|
|
+ CourseEntity course = courseRepo.findOne(courseId);
|
|
|
|
+ course.setEnable(true);
|
|
|
|
+ courseRepo.save(course);
|
|
|
|
+ }
|
|
|
|
+
|
|
return courseIds;
|
|
return courseIds;
|
|
}
|
|
}
|
|
}
|
|
}
|