use of top.hcode.hoj.pojo.entity.training.TrainingRecord in project HOJ by HimitZH.
the class BeforeDispatchInitManager method initTrainingSubmission.
@Transactional(rollbackFor = Exception.class)
public void initTrainingSubmission(Long tid, String displayId, UserRolesVo userRolesVo, Judge judge) throws StatusForbiddenException, StatusFailException, StatusAccessDeniedException {
Training training = trainingEntityService.getById(tid);
if (training == null || !training.getStatus()) {
throw new StatusFailException("该训练不存在或不允许显示!");
}
trainingValidator.validateTrainingAuth(training, userRolesVo);
// 查询获取对应的pid和cpid
QueryWrapper<TrainingProblem> trainingProblemQueryWrapper = new QueryWrapper<>();
trainingProblemQueryWrapper.eq("tid", tid).eq("display_id", displayId);
TrainingProblem trainingProblem = trainingProblemEntityService.getOne(trainingProblemQueryWrapper);
judge.setPid(trainingProblem.getPid());
Problem problem = problemEntityService.getById(trainingProblem.getPid());
if (problem.getAuth() == 2) {
throw new StatusForbiddenException("错误!当前题目不可提交!");
}
judge.setDisplayPid(problem.getProblemId()).setGid(training.getGid());
// 将新提交数据插入数据库
judgeEntityService.save(judge);
// 非私有训练不记录
if (!training.getAuth().equals(Constants.Training.AUTH_PRIVATE.getValue())) {
return;
}
TrainingRecord trainingRecord = new TrainingRecord();
trainingRecord.setPid(problem.getId()).setTid(tid).setTpid(trainingProblem.getId()).setSubmitId(judge.getSubmitId()).setUid(userRolesVo.getUid());
trainingRecordEntityService.save(trainingRecord);
}
use of top.hcode.hoj.pojo.entity.training.TrainingRecord in project HOJ by HimitZH.
the class TrainingRecordServiceImpl method saveBatchNewRecordByJudgeList.
private void saveBatchNewRecordByJudgeList(List<Judge> judgeList, Long tid, Long tpId, HashMap<Long, Long> pidMapTPid) {
if (!CollectionUtils.isEmpty(judgeList)) {
List<TrainingRecord> trainingRecordList = new ArrayList<>();
for (Judge judge : judgeList) {
TrainingRecord trainingRecord = new TrainingRecord().setPid(judge.getPid()).setSubmitId(judge.getSubmitId()).setTid(tid).setUid(judge.getUid());
if (pidMapTPid != null) {
trainingRecord.setTpid(pidMapTPid.get(judge.getPid()));
}
if (tpId != null) {
trainingRecord.setTpid(tpId);
}
trainingRecordList.add(trainingRecord);
}
saveBatch(trainingRecordList);
}
}
use of top.hcode.hoj.pojo.entity.training.TrainingRecord in project HOJ by HimitZH.
the class TrainingRecordServiceImpl method submitTrainingProblem.
@Override
@Transactional(rollbackFor = Exception.class)
public CommonResult submitTrainingProblem(ToJudgeDto judgeDto, UserRolesVo userRolesVo, Judge judge) {
Training training = trainingService.getById(judgeDto.getTid());
if (training == null || !training.getStatus()) {
return CommonResult.errorResponse("该训练不存在或不允许显示!");
}
CommonResult result = trainingRegisterService.checkTrainingAuth(training, userRolesVo);
if (result != null) {
return result;
}
// 查询获取对应的pid和cpid
QueryWrapper<TrainingProblem> trainingProblemQueryWrapper = new QueryWrapper<>();
trainingProblemQueryWrapper.eq("tid", judgeDto.getTid()).eq("display_id", judgeDto.getPid());
TrainingProblem trainingProblem = trainingProblemService.getOne(trainingProblemQueryWrapper);
judge.setPid(trainingProblem.getPid());
Problem problem = problemService.getById(trainingProblem.getPid());
if (problem.getAuth() == 2) {
return CommonResult.errorResponse("错误!当前题目不可提交!", CommonResult.STATUS_FORBIDDEN);
}
judge.setDisplayPid(problem.getProblemId());
// 将新提交数据插入数据库
judgeService.saveOrUpdate(judge);
// 非私有训练不记录
if (!training.getAuth().equals(Constants.Training.AUTH_PRIVATE.getValue())) {
return null;
}
TrainingRecord trainingRecord = new TrainingRecord();
trainingRecord.setPid(problem.getId()).setTid(judgeDto.getTid()).setTpid(trainingProblem.getId()).setSubmitId(judge.getSubmitId()).setUid(userRolesVo.getUid());
trainingRecordMapper.insert(trainingRecord);
return null;
}
use of top.hcode.hoj.pojo.entity.training.TrainingRecord in project HOJ by HimitZH.
the class AdminTrainingRecordManager method saveBatchNewRecordByJudgeList.
private void saveBatchNewRecordByJudgeList(List<Judge> judgeList, Long tid, Long tpId, HashMap<Long, Long> pidMapTPid) {
if (!CollectionUtils.isEmpty(judgeList)) {
List<TrainingRecord> trainingRecordList = new ArrayList<>();
for (Judge judge : judgeList) {
TrainingRecord trainingRecord = new TrainingRecord().setPid(judge.getPid()).setSubmitId(judge.getSubmitId()).setTid(tid).setUid(judge.getUid());
if (pidMapTPid != null) {
trainingRecord.setTpid(pidMapTPid.get(judge.getPid()));
}
if (tpId != null) {
trainingRecord.setTpid(tpId);
}
trainingRecordList.add(trainingRecord);
}
trainingRecordEntityService.saveBatch(trainingRecordList);
}
}
Aggregations