|
@@ -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", "考试不存在");
|
|
|
}
|