WANG 6 years ago
parent
commit
c0eff97ff0

+ 34 - 28
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/controller/ExamController.java

@@ -99,6 +99,7 @@ import cn.com.qmth.examcloud.core.oe.admin.api.response.CheckExamIsStartedResp;
 import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
 import cn.com.qmth.examcloud.task.api.request.SyncExamReq;
 import cn.com.qmth.examcloud.web.config.SystemConfig;
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 import cn.com.qmth.examcloud.web.redis.RedisClient;
 import cn.com.qmth.examcloud.web.support.ControllerSupport;
 import io.swagger.annotations.ApiOperation;
@@ -115,6 +116,9 @@ import io.swagger.annotations.ApiOperation;
 @RequestMapping("${$rmp.ctr.examwork}/exam")
 public class ExamController extends ControllerSupport {
 
+	@Autowired
+	SystemConfig systemConfig;
+
 	@Autowired
 	ExamPropertyRepo examPropertyRepo;
 
@@ -178,7 +182,7 @@ public class ExamController extends ControllerSupport {
 		if (null == courseId) {
 			throw new StatusException("E-001252", "courseId is null");
 		}
-		ExamEntity one = examRepo.findOne(examId);
+		ExamEntity one = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
 		if (null == one) {
 			throw new StatusException("E-001253", "examId is wrong");
 		}
@@ -198,7 +202,7 @@ public class ExamController extends ControllerSupport {
 			@RequestParam(required = false) String level,
 			@RequestParam(required = false) Boolean enable) {
 
-		ExamEntity one = examRepo.findOne(examId);
+		ExamEntity one = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
 		if (null == one) {
 			throw new StatusException("E-001250", "examId is wrong");
 		}
@@ -225,7 +229,7 @@ public class ExamController extends ControllerSupport {
 			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
 		};
 
-		PageRequest pageRequest = new PageRequest(0, 50, new Sort(Direction.DESC, "updateTime"));
+		PageRequest pageRequest = PageRequest.of(0, 50, new Sort(Direction.DESC, "updateTime"));
 
 		Page<ExamCourseRelationEntity> page = examCourseRelationRepo.findAll(specification,
 				pageRequest);
@@ -279,7 +283,7 @@ public class ExamController extends ControllerSupport {
 			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
 		};
 
-		PageRequest pageRequest = new PageRequest(curPage, pageSize,
+		PageRequest pageRequest = PageRequest.of(curPage, pageSize,
 				new Sort(Direction.DESC, "updateTime"));
 
 		Page<ExamEntity> page = examRepo.findAll(specification, pageRequest);
@@ -389,7 +393,7 @@ public class ExamController extends ControllerSupport {
 			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
 		};
 
-		PageRequest pageRequest = new PageRequest(0, 100, new Sort(Direction.DESC, "updateTime"));
+		PageRequest pageRequest = PageRequest.of(0, 100, new Sort(Direction.DESC, "updateTime"));
 		Page<ExamEntity> page = examRepo.findAll(specification, pageRequest);
 
 		Iterator<ExamEntity> iterator = page.iterator();
@@ -455,7 +459,7 @@ public class ExamController extends ControllerSupport {
 	@ApiOperation(value = "按ID查询考试批次", notes = "ID查询")
 	@GetMapping("{examId}")
 	public ExamDomain getExamById(@PathVariable Long examId) {
-		ExamEntity one = examRepo.findOne(examId);
+		ExamEntity one = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
 		if (null == one) {
 			throw new StatusException("E-001250", "examId is wrong");
 		}
@@ -570,7 +574,7 @@ public class ExamController extends ControllerSupport {
 	@GetMapping("allProperties/{examId}")
 	public Map<String, String> getAllExamProperties(@PathVariable Long examId) {
 
-		ExamEntity examEntity = examRepo.findOne(examId);
+		ExamEntity examEntity = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
 		if (null == examEntity) {
 			throw new StatusException("E-001250", "examId is wrong");
 		}
@@ -597,7 +601,7 @@ public class ExamController extends ControllerSupport {
 	@ApiOperation(value = "查询考试批次单个属性")
 	@GetMapping("property/{examId}/{key}")
 	public String getExamProperty(@PathVariable Long examId, @PathVariable String key) {
-		ExamEntity examEntity = examRepo.findOne(examId);
+		ExamEntity examEntity = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
 		if (null == examEntity) {
 			throw new StatusException("E-001250", "examId is wrong");
 		}
@@ -622,7 +626,7 @@ public class ExamController extends ControllerSupport {
 	@GetMapping("examOrgProperty/{examId}/{key}")
 	public String getExamOrgProperty(@PathVariable Long examId, @PathVariable String key) {
 		User accessUser = getAccessUser();
-		ExamEntity examEntity = examRepo.findOne(examId);
+		ExamEntity examEntity = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
 		if (null == examEntity) {
 			throw new StatusException("E-001250", "examId is wrong");
 		}
@@ -645,7 +649,7 @@ public class ExamController extends ControllerSupport {
 	@GetMapping("examOrgProperty/{examId}/{orgId}/{key}")
 	public String getExamOrgProperty(@PathVariable Long examId, @PathVariable Long orgId,
 			@PathVariable String key) {
-		ExamEntity examEntity = examRepo.findOne(examId);
+		ExamEntity examEntity = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
 		if (null == examEntity) {
 			throw new StatusException("E-001250", "examId is wrong");
 		}
@@ -669,13 +673,13 @@ public class ExamController extends ControllerSupport {
 		List<Long> examIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
 				.collect(Collectors.toList());
 		for (Long examId : examIds) {
-			ExamEntity exam = examRepo.findOne(examId);
+			ExamEntity exam = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
 			exam.setEnable(true);
 			examRepo.save(exam);
 		}
 
 		for (Long examId : examIds) {
-			ExamEntity exam = examRepo.findOne(examId);
+			ExamEntity exam = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
 			SyncExamReq req = new SyncExamReq();
 			req.setId(exam.getId());
 			req.setBeginTime(exam.getBeginTime());
@@ -706,13 +710,13 @@ public class ExamController extends ControllerSupport {
 		List<Long> examIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
 				.collect(Collectors.toList());
 		for (Long examId : examIds) {
-			ExamEntity exam = examRepo.findOne(examId);
+			ExamEntity exam = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
 			exam.setEnable(false);
 			examRepo.save(exam);
 		}
 
 		for (Long examId : examIds) {
-			ExamEntity exam = examRepo.findOne(examId);
+			ExamEntity exam = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
 			SyncExamReq req = new SyncExamReq();
 			req.setId(exam.getId());
 			req.setBeginTime(exam.getBeginTime());
@@ -751,7 +755,7 @@ public class ExamController extends ControllerSupport {
 	public List<ExamCourseGroupDomain> getCourseGroupListByExamId(@PathVariable Long examId,
 			@PathVariable Integer curPage, @PathVariable Integer pageSize) {
 
-		Pageable pageable = new PageRequest(curPage - 1, pageSize, Sort.Direction.DESC,
+		Pageable pageable = PageRequest.of(curPage - 1, pageSize, Sort.Direction.DESC,
 				"updateTime");
 		List<ExamCourseGroupSettingsEntity> groupList = examCourseGroupSettingsRepo
 				.findAllByExamId(examId, pageable);
@@ -873,7 +877,7 @@ public class ExamController extends ControllerSupport {
 			relation.setGroupId(courseGroup.getId());
 			relationList.add(relation);
 		}
-		examCourseGroupRelationRepo.save(relationList);
+		examCourseGroupRelationRepo.saveAll(relationList);
 	}
 
 	/**
@@ -885,7 +889,7 @@ public class ExamController extends ControllerSupport {
 	@ApiOperation(value = "删除课程组", notes = "")
 	@DeleteMapping("courseGroup/{id}")
 	public void deleteCourseGroup(@PathVariable Long id) {
-		examCourseGroupSettingsRepo.delete(id);
+		examCourseGroupSettingsRepo.deleteById(id);
 		examCourseGroupRelationRepo.deleteByGroupId(id);
 	}
 
@@ -907,7 +911,7 @@ public class ExamController extends ControllerSupport {
 		if (null == examOrgDomain.getExamId()) {
 			throw new StatusException("E-001210", "examId is null");
 		}
-		ExamEntity examEntity = examRepo.findOne(examId);
+		ExamEntity examEntity = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
 		if (null == examEntity) {
 			throw new StatusException("E-001250", "examId is wrong");
 		}
@@ -927,7 +931,7 @@ public class ExamController extends ControllerSupport {
 			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
 		};
 
-		Pageable pageable = new PageRequest(curPage, pageSize, Sort.Direction.DESC, "updateTime");
+		Pageable pageable = PageRequest.of(curPage, pageSize, Sort.Direction.DESC, "updateTime");
 		Page<ExamSpecialSettingsEntity> page = examSpecialSettingsRepo.findAll(specification,
 				pageable);
 
@@ -978,7 +982,7 @@ public class ExamController extends ControllerSupport {
 	@PostMapping("examOrgSettings/{examId}")
 	public ExamDomain getExamOrgSettings(@PathVariable Long examId) {
 		User accessUser = getAccessUser();
-		ExamEntity examEntity = examRepo.findOne(examId);
+		ExamEntity examEntity = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
 		if (null == examEntity) {
 			throw new StatusException("E-001250", "examId is wrong");
 		}
@@ -1055,7 +1059,7 @@ public class ExamController extends ControllerSupport {
 	private ExamSpecialSettingsEntity saveExamOrgSettings(ExamOrgSettingsDomain domain) {
 		Long examId = domain.getExamId();
 
-		ExamEntity examEntity = examRepo.findOne(examId);
+		ExamEntity examEntity = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
 		if (null == examEntity) {
 			throw new StatusException("E-001250", "examId is wrong");
 		}
@@ -1130,10 +1134,10 @@ public class ExamController extends ControllerSupport {
 			String examLimit = null == cur.getExamLimit() ? "否" : cur.getExamLimit() ? "否" : "是";
 			String beginTime = null == cur.getBeginTime()
 					? null
-					: DateUtil.format(cur.getBeginTime(), DatePatterns.ISO);
+					: DateUtil.format(cur.getBeginTime(), DatePatterns.CHINA_DEFAULT);
 			String endTime = null == cur.getEndTime()
 					? null
-					: DateUtil.format(cur.getEndTime(), DatePatterns.ISO);
+					: DateUtil.format(cur.getEndTime(), DatePatterns.CHINA_DEFAULT);
 			datas.add(new Object[]{String.valueOf(orgBean.getId()), orgBean.getCode(),
 					orgBean.getName(), examLimit, beginTime, endTime});
 		}
@@ -1152,7 +1156,7 @@ public class ExamController extends ControllerSupport {
 					orgBean.getName(), null, null, null});
 		}
 
-		String filePath = SystemConfig.getTempDataDir() + File.separator
+		String filePath = systemConfig.getTempDataDir() + File.separator
 				+ System.currentTimeMillis() + ".xlsx";
 		File file = new File(filePath);
 
@@ -1171,7 +1175,7 @@ public class ExamController extends ControllerSupport {
 	public Map<String, Object> importExamOrgSettings(@PathVariable Long examId,
 			@RequestParam CommonsMultipartFile file) {
 
-		ExamEntity exam = examRepo.findOne(examId);
+		ExamEntity exam = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
 		if (null == exam) {
 			throw new StatusException("E-001010", "考试不存在");
 		}
@@ -1195,7 +1199,8 @@ public class ExamController extends ControllerSupport {
 				.collect(Collectors.toList());
 		List<String> ret = Lists.newArrayList();
 		for (Long cur : orgSettingsIds) {
-			ExamSpecialSettingsEntity entity = examSpecialSettingsRepo.findOne(cur);
+			ExamSpecialSettingsEntity entity = GlobalHelper.getEntity(examSpecialSettingsRepo, cur,
+					ExamSpecialSettingsEntity.class);
 			entity.setExamLimit(true);
 			examSpecialSettingsRepo.save(entity);
 			ret.add(entity.getExamId() + ":" + entity.getOrgId());
@@ -1210,7 +1215,8 @@ public class ExamController extends ControllerSupport {
 				.collect(Collectors.toList());
 		List<String> ret = Lists.newArrayList();
 		for (Long cur : orgSettingsIds) {
-			ExamSpecialSettingsEntity entity = examSpecialSettingsRepo.findOne(cur);
+			ExamSpecialSettingsEntity entity = GlobalHelper.getEntity(examSpecialSettingsRepo, cur,
+					ExamSpecialSettingsEntity.class);
 			entity.setExamLimit(false);
 			examSpecialSettingsRepo.save(entity);
 			ret.add(entity.getExamId() + ":" + entity.getOrgId());
@@ -1229,7 +1235,7 @@ public class ExamController extends ControllerSupport {
 	@ApiOperation(value = "考试IP限制", notes = "")
 	@GetMapping("ipLimit/{examId}")
 	public Map<String, Object> ipLimit(HttpServletRequest request, @PathVariable Long examId) {
-		ExamEntity exam = examRepo.findOne(examId);
+		ExamEntity exam = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
 		if (null == exam) {
 			throw new StatusException("E-001010", "考试不存在");
 		}

+ 8 - 5
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/controller/ExamStudentController.java

@@ -55,6 +55,7 @@ import cn.com.qmth.examcloud.core.examwork.service.bean.ExamStudentInfo;
 import cn.com.qmth.examcloud.core.oe.admin.api.ExamRecordCloudService;
 import cn.com.qmth.examcloud.core.oe.admin.api.request.CheckExamIsStartedReq;
 import cn.com.qmth.examcloud.core.oe.admin.api.response.CheckExamIsStartedResp;
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 import cn.com.qmth.examcloud.web.support.ControllerSupport;
 import io.swagger.annotations.ApiOperation;
 
@@ -186,7 +187,7 @@ public class ExamStudentController extends ControllerSupport {
 			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
 		};
 
-		PageRequest pageRequest = new PageRequest(curPage, pageSize,
+		PageRequest pageRequest = PageRequest.of(curPage, pageSize,
 				new Sort(Direction.DESC, "updateTime"));
 
 		Page<ExamStudentEntity> examStudents = examStudentRepo.findAll(specification, pageRequest);
@@ -194,7 +195,7 @@ public class ExamStudentController extends ControllerSupport {
 		List<ExamStudentDomain> ret = Lists.newArrayList();
 
 		for (ExamStudentEntity cur : examStudents) {
-			ExamEntity exam = examRepo.findOne(cur.getExamId());
+			ExamEntity exam = GlobalHelper.getEntity(examRepo, cur.getExamId(), ExamEntity.class);
 
 			GetOrgReq getOrgReq = new GetOrgReq();
 			getOrgReq.setOrgId(cur.getOrgId());
@@ -274,7 +275,7 @@ public class ExamStudentController extends ControllerSupport {
 	@ApiOperation(value = "按ID查询考试学生", notes = "ID查询")
 	@GetMapping("{id}")
 	public ExamStudentEntity getExamStudentById(@PathVariable Long id) {
-		ExamStudentEntity es = examStudentRepo.findOne(id);
+		ExamStudentEntity es = GlobalHelper.getEntity(examStudentRepo, id, ExamStudentEntity.class);
 		if (null == es) {
 			throw new StatusException("E-520001", "考生不存在");
 		}
@@ -417,7 +418,8 @@ public class ExamStudentController extends ControllerSupport {
 				.collect(Collectors.toList());
 		List<String> ret = Lists.newArrayList();
 		for (Long cur : examStuIds) {
-			ExamStudentEntity s = examStudentRepo.findOne(cur);
+			ExamStudentEntity s = GlobalHelper.getEntity(examStudentRepo, cur,
+					ExamStudentEntity.class);
 			s.setEnable(true);
 			examStudentRepo.save(s);
 			ret.add(s.getId() + ":" + s.getName());
@@ -439,7 +441,8 @@ public class ExamStudentController extends ControllerSupport {
 				.collect(Collectors.toList());
 		List<String> ret = Lists.newArrayList();
 		for (Long cur : examStuIds) {
-			ExamStudentEntity s = examStudentRepo.findOne(cur);
+			ExamStudentEntity s = GlobalHelper.getEntity(examStudentRepo, cur,
+					ExamStudentEntity.class);
 			s.setEnable(false);
 			examStudentRepo.save(s);
 			ret.add(s.getId() + ":" + s.getName());

+ 9 - 8
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/provider/ExamCloudServiceProvider.java

@@ -77,6 +77,7 @@ import cn.com.qmth.examcloud.examwork.api.response.LockExamStudentsResp;
 import cn.com.qmth.examcloud.examwork.api.response.SaveExamResp;
 import cn.com.qmth.examcloud.examwork.api.response.SetExamPropertyResp;
 import cn.com.qmth.examcloud.examwork.api.response.UnlockExamStudentsResp;
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 import cn.com.qmth.examcloud.web.support.ControllerSupport;
 import io.swagger.annotations.ApiOperation;
 
@@ -167,12 +168,12 @@ public class ExamCloudServiceProvider extends ControllerSupport implements ExamC
 		ExamEntity exam = null;
 
 		if (null != id) {
-			exam = examRepo.findOne(id);
+			exam = GlobalHelper.getEntity(examRepo, id, ExamEntity.class);
 		} else if (StringUtils.isNotBlank(name)) {
 			if (null == rootOrgId) {
 				throw new StatusException("E-002004", "rootOrgId is null");
 			}
-			exam = examService.findExamByNameAndRootOrgId(name, rootOrgId);
+			exam = examRepo.findByNameAndRootOrgId(name, rootOrgId);
 		}
 
 		if (null == exam) {
@@ -300,7 +301,7 @@ public class ExamCloudServiceProvider extends ControllerSupport implements ExamC
 			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
 		};
 
-		PageRequest pageRequest = new PageRequest(0, 10000, new Sort(Direction.ASC, "beginTime"));
+		PageRequest pageRequest = PageRequest.of(0, 10000, new Sort(Direction.ASC, "beginTime"));
 
 		List<ExamSpecialSettingsEntity> entityList = examSpecialSettingsRepo
 				.findAll(specification, pageRequest).getContent();
@@ -360,7 +361,7 @@ public class ExamCloudServiceProvider extends ControllerSupport implements ExamC
 			if (null == examId) {
 				throw new StatusException("E-002001", "examId is null");
 			}
-			ExamEntity exam = examRepo.findOne(examId);
+			ExamEntity exam = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
 			if (null == exam) {
 				throw new StatusException("E-002002", "ExamEntity is null");
 			}
@@ -388,7 +389,7 @@ public class ExamCloudServiceProvider extends ControllerSupport implements ExamC
 			if (null == examId) {
 				throw new StatusException("E-002001", "examId is null");
 			}
-			ExamEntity exam = examRepo.findOne(examId);
+			ExamEntity exam = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
 			if (null == exam) {
 				throw new StatusException("E-002002", "ExamEntity is null");
 			}
@@ -419,7 +420,7 @@ public class ExamCloudServiceProvider extends ControllerSupport implements ExamC
 
 		final long start = null == req.getStart() ? 1 : req.getStart();
 
-		Pageable pageable = new PageRequest(0, 100, Sort.Direction.ASC, "id");
+		Pageable pageable = PageRequest.of(0, 100, Sort.Direction.ASC, "id");
 
 		Specification<ExamEntity> specification = (root, query, cb) -> {
 			List<Predicate> predicates = new ArrayList<>();
@@ -483,7 +484,7 @@ public class ExamCloudServiceProvider extends ControllerSupport implements ExamC
 
 		final long start = null == req.getStart() ? 1 : req.getStart();
 
-		Pageable pageable = new PageRequest(0, 100, Sort.Direction.ASC, "courseId");
+		Pageable pageable = PageRequest.of(0, 100, Sort.Direction.ASC, "courseId");
 
 		Specification<ExamCourseRelationEntity> specification = (root, query, cb) -> {
 			List<Predicate> predicates = new ArrayList<>();
@@ -539,7 +540,7 @@ public class ExamCloudServiceProvider extends ControllerSupport implements ExamC
 
 		final long start = null == req.getStart() ? 1 : req.getStart();
 
-		Pageable pageable = new PageRequest(0, 100, Sort.Direction.ASC, "courseId");
+		Pageable pageable = PageRequest.of(0, 100, Sort.Direction.ASC, "courseId");
 
 		Specification<ExamPaperTypeRelationEntity> specification = (root, query, cb) -> {
 			List<Predicate> predicates = new ArrayList<>();

+ 8 - 6
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/provider/ExamStudentCloudServiceProvider.java

@@ -48,6 +48,7 @@ import cn.com.qmth.examcloud.examwork.api.response.GetExamStudentPageResp;
 import cn.com.qmth.examcloud.examwork.api.response.GetExamStudentResp;
 import cn.com.qmth.examcloud.examwork.api.response.SaveExamStudentResp;
 import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 import cn.com.qmth.examcloud.web.support.ControllerSupport;
 import io.swagger.annotations.ApiOperation;
 
@@ -167,8 +168,8 @@ public class ExamStudentCloudServiceProvider extends ControllerSupport
 			throw new StatusException("E-210002", "examId2 is null");
 		}
 
-		ExamEntity exam1 = examRepo.findOne(examId1);
-		ExamEntity exam2 = examRepo.findOne(examId2);
+		ExamEntity exam1 = GlobalHelper.getEntity(examRepo, examId1, ExamEntity.class);
+		ExamEntity exam2 = GlobalHelper.getEntity(examRepo, examId2, ExamEntity.class);
 		if (null == exam1) {
 			throw new StatusException("E-210003", "ExamEntity is null");
 		}
@@ -184,7 +185,7 @@ public class ExamStudentCloudServiceProvider extends ControllerSupport
 
 		final long start = null == req.getStart() ? 1 : req.getStart();
 
-		Pageable pageable = new PageRequest(0, 10, Sort.Direction.ASC, "id");
+		Pageable pageable = PageRequest.of(0, 10, Sort.Direction.ASC, "id");
 
 		Specification<ExamStudentEntity> specification = (root, query, cb) -> {
 			List<Predicate> predicates = new ArrayList<>();
@@ -267,7 +268,8 @@ public class ExamStudentCloudServiceProvider extends ControllerSupport
 	public GetExamStudentResp getExamStudent(@RequestBody GetExamStudentReq req) {
 		Long examStudentId = req.getExamStudentId();
 
-		ExamStudentEntity saved = examStudentRepo.findOne(examStudentId);
+		ExamStudentEntity saved = GlobalHelper.getEntity(examStudentRepo, examStudentId,
+				ExamStudentEntity.class);
 
 		ExamStudentBean examStudentBean = new ExamStudentBean();
 		examStudentBean.setId(saved.getId());
@@ -361,7 +363,7 @@ public class ExamStudentCloudServiceProvider extends ControllerSupport
 			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
 		};
 
-		PageRequest pageRequest = new PageRequest(curPage, pageSize,
+		PageRequest pageRequest = PageRequest.of(curPage, pageSize,
 				new Sort(Direction.DESC, "updateTime"));
 
 		Page<ExamStudentEntity> examStudents = examStudentRepo.findAll(specification, pageRequest);
@@ -369,7 +371,7 @@ public class ExamStudentCloudServiceProvider extends ControllerSupport
 		List<ExamStudentBean> list = Lists.newArrayList();
 
 		for (ExamStudentEntity cur : examStudents) {
-			ExamEntity exam = examRepo.findOne(cur.getExamId());
+			ExamEntity exam = GlobalHelper.getEntity(examRepo, cur.getExamId(), ExamEntity.class);
 
 			GetOrgReq getOrgReq = new GetOrgReq();
 			getOrgReq.setOrgId(cur.getOrgId());

+ 10 - 24
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/impl/ExamServiceImpl.java

@@ -11,7 +11,6 @@ import java.util.Map.Entry;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Example;
 import org.springframework.stereotype.Service;
 
 import com.google.common.collect.Lists;
@@ -44,6 +43,7 @@ import cn.com.qmth.examcloud.core.examwork.service.bean.ExamInfo;
 import cn.com.qmth.examcloud.core.examwork.service.bean.ExamSpecialSettingsInfo;
 import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
 import cn.com.qmth.examcloud.task.api.request.SyncExamReq;
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 
 /**
  * 类注释
@@ -78,21 +78,6 @@ public class ExamServiceImpl implements ExamService {
 	private static final String[] EXAM_ORG_SETTINGS_EXCEL_HEADER = new String[]{"学习中心ID", "学习中心代码",
 			"学习中心名称", "是否可以考试(是/否)", "开始考试时间 yyyy-MM-dd hh:mm:ss", "结束考试时间 yyyy-MM-dd hh:mm:ss"};
 
-	/**
-	 * 方法注释
-	 *
-	 * @author WANGWEI
-	 * @param examName
-	 * @param rootOrgId
-	 * @return
-	 */
-	public ExamEntity findExamByNameAndRootOrgId(String examName, Long rootOrgId) {
-		ExamEntity exam = new ExamEntity();
-		exam.setName(examName);
-		exam.setRootOrgId(rootOrgId);
-		return examRepo.findOne(Example.of(exam));
-	}
-
 	/*
 	 * 实现
 	 *
@@ -131,7 +116,7 @@ public class ExamServiceImpl implements ExamService {
 		// 更新
 		if (es.equals(CURD.UPDATE)) {
 			if (null != examInfo.getId()) {
-				exam = examRepo.findOne(examInfo.getId());
+				exam = GlobalHelper.getEntity(examRepo, examInfo.getId(), ExamEntity.class);
 				if (null == exam) {
 					throw new StatusException("E-002001", "id is wrong");
 				}
@@ -245,7 +230,7 @@ public class ExamServiceImpl implements ExamService {
 		examSpecialInfo.setExamLimit(saved.getExamLimit());
 		examSpecialInfo.setRootOrgId(saved.getRootOrgId());
 		this.saveExamSpecialSettings(examSpecialInfo);
-		
+
 		examSpecialSettingsRepo.updateExamEnableByExamId(saved.getId(), saved.getEnable());
 
 		SyncExamReq req = new SyncExamReq();
@@ -345,7 +330,8 @@ public class ExamServiceImpl implements ExamService {
 				examOrgEntity = new ExamSpecialSettingsEntity();
 			}
 		} else {
-			examOrgEntity = examSpecialSettingsRepo.findOne(examSpecialInfo.getId());
+			examOrgEntity = GlobalHelper.getEntity(examSpecialSettingsRepo, examSpecialInfo.getId(),
+					ExamSpecialSettingsEntity.class);
 			if (null == examOrgEntity) {
 				throw new StatusException("E-001101", "id is wrong");
 			}
@@ -415,7 +401,7 @@ public class ExamServiceImpl implements ExamService {
 	@Override
 	public List<Map<String, Object>> importExamSpecialSettings(Long examId, File file) {
 
-		ExamEntity examEntity = examRepo.findOne(examId);
+		ExamEntity examEntity = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
 		List<String[]> lineList = null;
 		try {
 			lineList = ExcelReader.readSheetBySax(PathUtil.getCanonicalPath(file), 1, 6);
@@ -494,20 +480,20 @@ public class ExamServiceImpl implements ExamService {
 			String beginTime = trimAndNullIfBlank(line[4]);
 			if (StringUtils.isNotBlank(beginTime)) {
 				try {
-					Date beginDate = DateUtil.parse(beginTime, DatePatterns.ISO);
+					Date beginDate = DateUtil.parse(beginTime, DatePatterns.CHINA_DEFAULT);
 					specialSettings.setBeginTime(beginDate);
 				} catch (Exception e) {
-					msg.append("  开始考试时间格式错误. 正确格式为 " + DatePatterns.ISO);
+					msg.append("  开始考试时间格式错误. 正确格式为 " + DatePatterns.CHINA_DEFAULT);
 					hasError = true;
 				}
 			}
 			String endTime = trimAndNullIfBlank(line[5]);
 			if (StringUtils.isNotBlank(endTime)) {
 				try {
-					Date endDate = DateUtil.parse(endTime, DatePatterns.ISO);
+					Date endDate = DateUtil.parse(endTime, DatePatterns.CHINA_DEFAULT);
 					specialSettings.setEndTime(endDate);
 				} catch (Exception e) {
-					msg.append("  结束考试时间格式错误. 正确格式为 " + DatePatterns.ISO);
+					msg.append("  结束考试时间格式错误. 正确格式为 " + DatePatterns.CHINA_DEFAULT);
 					hasError = true;
 				}
 			}

+ 3 - 2
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/impl/ExamStudentServiceImpl.java

@@ -35,6 +35,7 @@ import cn.com.qmth.examcloud.core.oe.admin.api.request.CheckExamIsStartedReq;
 import cn.com.qmth.examcloud.core.oe.admin.api.response.CheckExamIsStartedResp;
 import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
 import cn.com.qmth.examcloud.task.api.request.SyncExamStudentReq;
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 
 /**
  * 考试学生服务类 Created by songyue on 17/1/14.
@@ -161,7 +162,7 @@ public class ExamStudentServiceImpl implements ExamStudentService {
 	 */
 	@Override
 	public void deleteExamStudentsByExamId(Long examId) {
-		ExamEntity exam = examRepo.findOne(examId);
+		ExamEntity exam = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
 		// 已经开考
 		if ((!forceDeleteExamStudent()) && isStarted(exam.getId(), null, null)) {
 			throw new StatusException("E-150113", "该考试已开始,不能删除");
@@ -209,7 +210,7 @@ public class ExamStudentServiceImpl implements ExamStudentService {
 		String examName = examStudentInfo.getExamName();
 
 		if (null != examId) {
-			exam = examRepo.findOne(examId);
+			exam = GlobalHelper.getEntity(examRepo, examId, ExamEntity.class);
 			if (null == exam) {
 				throw new StatusException("E-100020", "examId is wrong");
 			}

+ 16 - 77
examcloud-core-examwork-starter/src/main/java/cn/com/qmth/examcloud/core/examwork/starter/CoreExamWorkApp.java

@@ -1,52 +1,37 @@
 package cn.com.qmth.examcloud.core.examwork.starter;
 
-import org.slf4j.MDC;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.domain.EntityScan;
-import org.springframework.boot.autoconfigure.web.MultipartAutoConfiguration;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
-import org.springframework.cloud.client.loadbalancer.LoadBalanced;
 import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
-import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
 import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
 import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
-import org.springframework.data.redis.connection.RedisConnectionFactory;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
-import org.springframework.data.redis.serializer.StringRedisSerializer;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
-import org.springframework.web.client.RestTemplate;
-import org.springframework.web.multipart.MultipartResolver;
-import org.springframework.web.multipart.commons.CommonsMultipartResolver;
 
-import com.fasterxml.jackson.annotation.JsonAutoDetect;
-import com.fasterxml.jackson.annotation.PropertyAccessor;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import cn.com.qmth.examcloud.web.bootstrap.AppBootstrap;
 
-import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
-import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
-import cn.com.qmth.examcloud.commons.logging.SLF4JImpl;
-import cn.com.qmth.examcloud.core.examwork.base.enums.ExamProperty;
-import cn.com.qmth.examcloud.web.boot.ExamCloudApp;
-import cn.com.qmth.examcloud.web.redis.RedisClient;
-import cn.com.qmth.examcloud.web.redis.RedisClientImpl;
-import cn.com.qmth.examcloud.web.support.CustomResponseErrorHandler;
-
-@ComponentScan(basePackages = {"cn.com.qmth"})
-@EntityScan(basePackages = {"cn.com.qmth"})
-@EnableJpaRepositories(basePackages = {"cn.com.qmth"})
+@SpringBootApplication
+@Configuration
+@EnableAutoConfiguration
 @EnableJpaAuditing
 @EnableTransactionManagement
-@SpringBootApplication
 @EnableEurekaClient
 @EnableDiscoveryClient
-@EnableAutoConfiguration(exclude = {MultipartAutoConfiguration.class})
+@ComponentScan(basePackages = {"cn.com.qmth"})
+@EntityScan(basePackages = {"cn.com.qmth"})
+@EnableJpaRepositories(basePackages = {"cn.com.qmth"})
 public class CoreExamWorkApp {
 
-	private static final ExamCloudLog LOG = ExamCloudLogFactory.getLog(CoreExamWorkApp.class);
+	static {
+		String runtimeLevel = System.getProperty("log.commonLevel");
+		if (null == runtimeLevel) {
+			System.setProperty("log.commonLevel", "DEBUG");
+		}
+		System.setProperty("hibernate.dialect.storage_engine", "innodb");
+	}
 
 	/**
 	 * main
@@ -56,53 +41,7 @@ public class CoreExamWorkApp {
 	 * @throws Exception
 	 */
 	public static void main(String[] args) throws Exception {
-		if (LOG instanceof SLF4JImpl) {
-			MDC.put("TRACE_ID", Thread.currentThread().getName());
-		}
-
-		ExamProperty.init();
-
-		ExamCloudApp.run(CoreExamWorkApp.class, "examwork", args);
-	}
-
-	@Bean
-	@LoadBalanced
-	public RestTemplate restTemplate() {
-		RestTemplate restTemplate = new RestTemplate();
-		restTemplate.setErrorHandler(new CustomResponseErrorHandler());
-		return restTemplate;
+		AppBootstrap.run(CoreExamWorkApp.class, args);
 	}
 
-	@Bean
-	public RedisTemplate<String, Object> redisTemplate(
-			RedisConnectionFactory redisConnectionFactory) {
-		RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
-		redisTemplate.setConnectionFactory(redisConnectionFactory);
-		Jackson2JsonRedisSerializer<?> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(
-				Object.class);
-		ObjectMapper objectMapper = new ObjectMapper();
-		objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
-		objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
-		jackson2JsonRedisSerializer.setObjectMapper(objectMapper);
-		redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
-		redisTemplate.setKeySerializer(new StringRedisSerializer());
-		redisTemplate.afterPropertiesSet();
-		return redisTemplate;
-	}
-
-	@Bean
-	@Autowired
-	public RedisClient redisClient(RedisTemplate<String, Object> redisTemplate) {
-		return new RedisClientImpl(redisTemplate);
-	}
-
-	@Bean(name = "multipartResolver")
-	public MultipartResolver multipartResolver() {
-		CommonsMultipartResolver resolver = new CommonsMultipartResolver();
-		resolver.setDefaultEncoding("UTF-8");
-		resolver.setResolveLazily(true);
-		resolver.setMaxInMemorySize(2);
-		resolver.setMaxUploadSize(200 * 1024 * 1024);
-		return resolver;
-	}
 }

+ 0 - 39
examcloud-core-examwork-starter/src/main/java/cn/com/qmth/examcloud/core/examwork/starter/config/AppSelfInspection.java

@@ -1,39 +0,0 @@
-package cn.com.qmth.examcloud.core.examwork.starter.config;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.ApplicationArguments;
-import org.springframework.boot.ApplicationRunner;
-import org.springframework.core.annotation.Order;
-import org.springframework.stereotype.Component;
-
-import cn.com.qmth.examcloud.web.support.RemoteProcedureCallTester;
-
-/**
- * 应用自检
- *
- * @author WANGWEI
- * @date 2018年6月21日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-@Component
-@Order(1)
-public class AppSelfInspection implements ApplicationRunner {
-
-	@Autowired
-	private RemoteProcedureCallTester remoteCallTester;
-
-	/**
-	 * 自检
-	 *
-	 * @author WANGWEI
-	 */
-	private void inspect() {
-		remoteCallTester.testRestTemplate("EC-CORE-BASIC", "EC-CORE-OE-ADMIN");
-	}
-
-	@Override
-	public void run(ApplicationArguments args) throws Exception {
-		inspect();
-	}
-
-}

+ 0 - 123
examcloud-core-examwork-starter/src/main/java/cn/com/qmth/examcloud/core/examwork/starter/config/DefaultWebMvcConfigurerAdapter.java

@@ -1,123 +0,0 @@
-package cn.com.qmth.examcloud.core.examwork.starter.config;
-
-import java.util.List;
-import java.util.Set;
-
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
-
-import com.google.common.collect.Sets;
-
-import cn.com.qmth.examcloud.api.commons.security.bean.Role;
-import cn.com.qmth.examcloud.api.commons.security.bean.User;
-import cn.com.qmth.examcloud.api.commons.security.bean.UserType;
-import cn.com.qmth.examcloud.api.commons.security.enums.RoleMeta;
-import cn.com.qmth.examcloud.commons.util.PathUtil;
-import cn.com.qmth.examcloud.commons.util.PropertiesUtil;
-import cn.com.qmth.examcloud.commons.util.RegExpUtil;
-import cn.com.qmth.examcloud.web.interceptor.FirstInterceptor;
-import cn.com.qmth.examcloud.web.redis.RedisClient;
-import cn.com.qmth.examcloud.web.security.RequestPermissionInterceptor;
-import cn.com.qmth.examcloud.web.security.SpringCloudInterceptor;
-
-/**
- * 默认WebMvcConfigurer
- *
- * @author WANGWEI
- * @date 2018年5月22日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-@Configuration
-public class DefaultWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {
-
-	@Autowired
-	RedisClient redisClient;
-
-	static {
-		PropertiesUtil.configure(PathUtil.getResoucePath("security-mapping.properties"));
-	}
-
-	@Override
-	public void addInterceptors(InterceptorRegistry registry) {
-		registry.addInterceptor(new FirstInterceptor()).addPathPatterns("/**");
-
-		SpringCloudInterceptor springCloudInterceptor = new SpringCloudInterceptor();
-		springCloudInterceptor.setRedisClient(redisClient);
-		registry.addInterceptor(springCloudInterceptor).addPathPatterns("/**");
-
-		RequestPermissionInterceptor requestPermissionInterceptor = getRequestPermissionInterceptor();
-		requestPermissionInterceptor.configure("security-exclusions.conf");
-		registry.addInterceptor(requestPermissionInterceptor).addPathPatterns("/**");
-
-		super.addInterceptors(registry);
-	}
-
-	@Bean
-	public RequestPermissionInterceptor getRequestPermissionInterceptor() {
-		return new RequestPermissionInterceptor(redisClient) {
-
-			@Override
-			public boolean hasPermission(String mappingPath, User user) {
-
-				// 学生鉴权
-				if (user.getUserType().equals(UserType.STUDENT)) {
-					String key = "[s]" + mappingPath;
-					return PropertiesUtil.getBoolean(key, false);
-				}
-
-				List<Role> roleList = user.getRoleList();
-
-				if (CollectionUtils.isEmpty(roleList)) {
-					return false;
-				}
-
-				for (Role role : roleList) {
-					if (role.getRoleCode().equals(RoleMeta.SUPER_ADMIN.name())) {
-						return true;
-					}
-				}
-
-				// 权限组集合
-				String privilegeGroups = PropertiesUtil.getString(mappingPath);
-				if (StringUtils.isBlank(privilegeGroups)) {
-					return true;
-				}
-
-				// 用户权限集合
-				Set<String> rolePrivilegeList = Sets.newHashSet();
-				Long rootOrgId = user.getRootOrgId();
-				for (Role role : roleList) {
-					String key = "$_P_" + rootOrgId + "_" + role.getRoleId();
-					String rolePrivileges = redisClient.get(key, String.class);
-
-					List<String> rpList = RegExpUtil.findAll(rolePrivileges, "\\w+");
-					rolePrivilegeList.addAll(rpList);
-				}
-
-				List<String> privilegeGroupList = RegExpUtil.findAll(privilegeGroups, "[^\\;]+");
-
-				for (String pg : privilegeGroupList) {
-					pg = pg.trim();
-					if (StringUtils.isBlank(pg)) {
-						continue;
-					}
-
-					List<String> pList = RegExpUtil.findAll(pg, "[^\\,]+");
-					if (rolePrivilegeList.containsAll(pList)) {
-						return true;
-					} else {
-						continue;
-					}
-				}
-
-				return false;
-			}
-
-		};
-	}
-}