|
@@ -24,7 +24,6 @@ import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
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;
|
|
@@ -38,8 +37,10 @@ import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
|
import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
+import cn.com.qmth.examcloud.commons.base.helpers.poi.ExcelWriter;
|
|
|
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.SystemConfig;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.CourseCloudService;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.controller.bean.CourseDomain;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.CourseRepo;
|
|
@@ -67,6 +68,8 @@ public class CourseController extends ControllerSupport {
|
|
|
@Autowired
|
|
|
CourseCloudService courseCloudService;
|
|
|
|
|
|
+ private static final String[] EXCEL_HEADER = new String[]{"课程名称", "课程代码", "层次(ZSB,GQZ,ALL)"};
|
|
|
+
|
|
|
/**
|
|
|
* 方法注释
|
|
|
*
|
|
@@ -152,12 +155,6 @@ public class CourseController extends ControllerSupport {
|
|
|
|
|
|
User accessUser = getAccessUser();
|
|
|
Long rootOrgId = accessUser.getRootOrgId();
|
|
|
- // 过载保护
|
|
|
- int total = courseRepo.countByRootOrgIdAndNameLike(rootOrgId, toSqlSearchPattern(name));
|
|
|
- if (total > 1000) {
|
|
|
- List<CourseEntity> list = Lists.newArrayList();
|
|
|
- return list;
|
|
|
- }
|
|
|
|
|
|
Specification<CourseEntity> specification = (root, query, cb) -> {
|
|
|
List<Predicate> predicates = new ArrayList<>();
|
|
@@ -192,6 +189,13 @@ public class CourseController extends ControllerSupport {
|
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
};
|
|
|
|
|
|
+ // 过载保护
|
|
|
+ long total = courseRepo.count(specification);
|
|
|
+ if (total > 1000) {
|
|
|
+ List<CourseEntity> list = Lists.newArrayList();
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
List<CourseEntity> list = courseRepo.findAll(specification);
|
|
|
return list;
|
|
|
}
|
|
@@ -336,8 +340,69 @@ public class CourseController extends ControllerSupport {
|
|
|
|
|
|
@ApiOperation(value = "导出课程", notes = "导出")
|
|
|
@GetMapping("export")
|
|
|
- public void exportCourse(@ModelAttribute CourseEntity orgCriteria,
|
|
|
- HttpServletResponse response) {
|
|
|
+ public void export(@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();
|
|
|
+
|
|
|
+ Specification<CourseEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+
|
|
|
+ predicates.add(cb.equal(root.get("rootOrgId"), accessUser.getRootOrgId()));
|
|
|
+
|
|
|
+ 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"), CourseLevel.valueOf(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.get("courseId"));
|
|
|
+ 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()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ long count = courseRepo.count(specification);
|
|
|
+ if (100000 < count) {
|
|
|
+ throw new StatusException("B-620200", "数据量过大,无法导出");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<CourseEntity> list = courseRepo.findAll(specification);
|
|
|
+
|
|
|
+ List<Object[]> datas = Lists.newArrayList();
|
|
|
+
|
|
|
+ for (CourseEntity cur : list) {
|
|
|
+ datas.add(new Object[]{cur.getName(), cur.getCode(), cur.getLevel().name()});
|
|
|
+ }
|
|
|
+
|
|
|
+ String filePath = SystemConfig.getTempDataDir() + File.separator
|
|
|
+ + System.currentTimeMillis() + ".xlsx";
|
|
|
+ File file = new File(filePath);
|
|
|
+
|
|
|
+ ExcelWriter.write(EXCEL_HEADER, new Class[]{String.class, String.class, String.class},
|
|
|
+ datas, new File(filePath));
|
|
|
+
|
|
|
+ exportFile("课程列表-" + getRootOrgId() + ".xlsx", file);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|