Search in sources :

Example 1 with TrainingRecord

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);
}
Also used : Training(top.hcode.hoj.pojo.entity.training.Training) TrainingRecord(top.hcode.hoj.pojo.entity.training.TrainingRecord) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) TrainingProblem(top.hcode.hoj.pojo.entity.training.TrainingProblem) Problem(top.hcode.hoj.pojo.entity.problem.Problem) TrainingProblem(top.hcode.hoj.pojo.entity.training.TrainingProblem) ContestProblem(top.hcode.hoj.pojo.entity.contest.ContestProblem) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with 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);
    }
}
Also used : TrainingRecord(top.hcode.hoj.pojo.entity.training.TrainingRecord) Judge(top.hcode.hoj.pojo.entity.judge.Judge)

Example 3 with TrainingRecord

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;
}
Also used : Training(top.hcode.hoj.pojo.entity.training.Training) TrainingRecord(top.hcode.hoj.pojo.entity.training.TrainingRecord) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) CommonResult(top.hcode.hoj.common.result.CommonResult) TrainingProblem(top.hcode.hoj.pojo.entity.training.TrainingProblem) Problem(top.hcode.hoj.pojo.entity.problem.Problem) TrainingProblem(top.hcode.hoj.pojo.entity.training.TrainingProblem) ContestProblem(top.hcode.hoj.pojo.entity.contest.ContestProblem) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with TrainingRecord

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);
    }
}
Also used : TrainingRecord(top.hcode.hoj.pojo.entity.training.TrainingRecord) ArrayList(java.util.ArrayList) Judge(top.hcode.hoj.pojo.entity.judge.Judge)

Aggregations

TrainingRecord (top.hcode.hoj.pojo.entity.training.TrainingRecord)4 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ContestProblem (top.hcode.hoj.pojo.entity.contest.ContestProblem)2 Judge (top.hcode.hoj.pojo.entity.judge.Judge)2 Problem (top.hcode.hoj.pojo.entity.problem.Problem)2 Training (top.hcode.hoj.pojo.entity.training.Training)2 TrainingProblem (top.hcode.hoj.pojo.entity.training.TrainingProblem)2 ArrayList (java.util.ArrayList)1 StatusFailException (top.hcode.hoj.common.exception.StatusFailException)1 StatusForbiddenException (top.hcode.hoj.common.exception.StatusForbiddenException)1 CommonResult (top.hcode.hoj.common.result.CommonResult)1