wangwei hace 6 años
padre
commit
52efff78f2

+ 74 - 9
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/CourseController.java

@@ -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);
+
 	}
 
 	/**

+ 3 - 3
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/FaceController.java

@@ -31,7 +31,7 @@ import io.swagger.annotations.ApiOperation;
  */
 @Transactional
 @RestController
-@RequestMapping("${$rmp.ctr.basic}/faceset")
+@RequestMapping("${$rmp.ctr.basic}/face")
 public class FaceController extends ControllerSupport {
 
 	@Autowired
@@ -69,8 +69,8 @@ public class FaceController extends ControllerSupport {
 	}
 
 	@ApiOperation(value = "获取可用的faceset集合")
-	@GetMapping("studentFacre/{studentId}")
-	public StudentFaceEntity getStudentFacre(@PathVariable Long studentId) {
+	@GetMapping("studentFace/{studentId}")
+	public StudentFaceEntity getStudentFace(@PathVariable Long studentId) {
 
 		if (null == studentId) {
 			throw new StatusException("B-710001", "studentId is null");

+ 8 - 7
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/OrgController.java

@@ -356,13 +356,6 @@ public class OrgController extends ControllerSupport {
 			return list;
 		}
 
-		// 过载保护
-		int total = orgRepo.countByRootIdAndNameLike(getRootOrgId(), name);
-		if (total > 1000) {
-			List<OrgEntity> list = Lists.newArrayList();
-			return list;
-		}
-
 		Specification<OrgEntity> specification = (root, query, cb) -> {
 			List<Predicate> predicates = new ArrayList<>();
 			predicates.add(cb.equal(root.get("rootId"), getRootOrgId()));
@@ -375,6 +368,14 @@ public class OrgController extends ControllerSupport {
 
 			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
 		};
+
+		// 过载保护
+		long total = orgRepo.count(specification);
+		if (total > 1000) {
+			List<OrgEntity> list = Lists.newArrayList();
+			return list;
+		}
+
 		Sort sort = new Sort(Direction.DESC, "updateTime");
 		List<OrgEntity> list = orgRepo.findAll(specification, sort);
 

+ 7 - 6
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/SpecialtyController.java

@@ -137,12 +137,6 @@ public class SpecialtyController extends ControllerSupport {
 		User accessUser = getAccessUser();
 
 		Long rootOrgId = accessUser.getRootOrgId();
-		// 过载保护
-		int total = specialtyRepo.countByRootOrgIdAndNameLike(rootOrgId, toSqlSearchPattern(name));
-		if (total > 1000) {
-			List<SpecialtyEntity> list = Lists.newArrayList();
-			return list;
-		}
 
 		Specification<SpecialtyEntity> specification = (root, query, cb) -> {
 			List<Predicate> predicates = new ArrayList<>();
@@ -174,6 +168,13 @@ public class SpecialtyController extends ControllerSupport {
 			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
 		};
 
+		// 过载保护
+		long total = specialtyRepo.count(specification);
+		if (total > 1000) {
+			List<SpecialtyEntity> list = Lists.newArrayList();
+			return list;
+		}
+
 		List<SpecialtyEntity> list = specialtyRepo.findAll(specification,
 				new Sort(Direction.DESC, "updateTime"));
 		return list;