use of top.hcode.hoj.pojo.entity.training.TrainingProblem in project HOJ by HimitZH.
the class AdminTrainingController method importTrainingRemoteOJProblem.
@GetMapping("/import-remote-oj-problem")
@RequiresAuthentication
@RequiresRoles(value = { "root", "admin", "problem_admin" }, logical = Logical.OR)
@Transactional(rollbackFor = Exception.class)
public CommonResult importTrainingRemoteOJProblem(@RequestParam("name") String name, @RequestParam("problemId") String problemId, @RequestParam("tid") Long tid, HttpServletRequest request) {
QueryWrapper<Problem> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("problem_id", name.toUpperCase() + "-" + problemId);
Problem problem = problemService.getOne(queryWrapper, false);
// 如果该题目不存在,需要先导入
if (problem == null) {
HttpSession session = request.getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
try {
ProblemStrategy.RemoteProblemInfo otherOJProblemInfo = problemService.getOtherOJProblemInfo(name.toUpperCase(), problemId, userRolesVo.getUsername());
if (otherOJProblemInfo != null) {
problem = problemService.adminAddOtherOJProblem(otherOJProblemInfo, name);
if (problem == null) {
return CommonResult.errorResponse("导入新题目失败!请重新尝试!");
}
} else {
return CommonResult.errorResponse("导入新题目失败!原因:可能是与该OJ链接超时或题号格式错误!");
}
} catch (Exception e) {
return CommonResult.errorResponse(e.getMessage());
}
}
QueryWrapper<TrainingProblem> trainingProblemQueryWrapper = new QueryWrapper<>();
Problem finalProblem = problem;
trainingProblemQueryWrapper.eq("tid", tid).and(wrapper -> wrapper.eq("pid", finalProblem.getId()).or().eq("display_id", finalProblem.getProblemId()));
TrainingProblem trainingProblem = trainingProblemService.getOne(trainingProblemQueryWrapper, false);
if (trainingProblem != null) {
return CommonResult.errorResponse("添加失败,该题目已添加或者题目的训练展示ID已存在!", CommonResult.STATUS_FAIL);
}
TrainingProblem newTProblem = new TrainingProblem();
boolean result = trainingProblemService.saveOrUpdate(newTProblem.setTid(tid).setPid(problem.getId()).setDisplayId(problem.getProblemId()));
if (result) {
// 添加成功
trainingRegisterService.syncAlreadyRegisterUserRecord(tid, problem.getId(), newTProblem.getId());
return CommonResult.successResponse(null, "添加成功!");
} else {
return CommonResult.errorResponse("添加失败", CommonResult.STATUS_FAIL);
}
}
use of top.hcode.hoj.pojo.entity.training.TrainingProblem in project HOJ by HimitZH.
the class AdminTrainingController method addProblemFromPublic.
@PostMapping("/add-problem-from-public")
@RequiresAuthentication
@RequiresRoles(value = { "root", "admin", "problem_admin" }, logical = Logical.OR)
public CommonResult addProblemFromPublic(@RequestBody HashMap<String, String> params) {
String pidStr = params.get("pid");
String tidStr = params.get("tid");
String displayId = params.get("displayId");
if (StringUtils.isEmpty(pidStr) || StringUtils.isEmpty(tidStr) || StringUtils.isEmpty(displayId)) {
return CommonResult.errorResponse("参数错误!", CommonResult.STATUS_FAIL);
}
Long pid = Long.valueOf(pidStr);
Long tid = Long.valueOf(tidStr);
QueryWrapper<TrainingProblem> trainingProblemQueryWrapper = new QueryWrapper<>();
trainingProblemQueryWrapper.eq("tid", tid).and(wrapper -> wrapper.eq("pid", pid).or().eq("display_id", displayId));
TrainingProblem trainingProblem = trainingProblemService.getOne(trainingProblemQueryWrapper, false);
if (trainingProblem != null) {
return CommonResult.errorResponse("添加失败,该题目已添加或者题目的训练展示ID已存在!", CommonResult.STATUS_FAIL);
}
TrainingProblem newTProblem = new TrainingProblem();
boolean result = trainingProblemService.saveOrUpdate(newTProblem.setTid(tid).setPid(pid).setDisplayId(displayId));
if (result) {
// 添加成功
trainingRegisterService.syncAlreadyRegisterUserRecord(tid, pid, newTProblem.getId());
return CommonResult.successResponse(null, "添加成功!");
} else {
return CommonResult.errorResponse("添加失败", CommonResult.STATUS_FAIL);
}
}
use of top.hcode.hoj.pojo.entity.training.TrainingProblem in project HOJ by HimitZH.
the class TrainingRecordServiceImpl method syncAllUserProblemRecord.
private void syncAllUserProblemRecord(Long tid) {
QueryWrapper<TrainingProblem> trainingProblemQueryWrapper = new QueryWrapper<>();
trainingProblemQueryWrapper.eq("tid", tid);
List<TrainingProblem> trainingProblemList = trainingProblemService.list(trainingProblemQueryWrapper);
if (trainingProblemList.size() == 0) {
return;
}
List<Long> pidList = new ArrayList<>();
HashMap<Long, Long> pidMapTPid = new HashMap<>();
for (TrainingProblem trainingProblem : trainingProblemList) {
pidList.add(trainingProblem.getPid());
pidMapTPid.put(trainingProblem.getPid(), trainingProblem.getId());
}
List<String> uidList = trainingRegisterService.getAlreadyRegisterUidList(tid);
if (uidList.size() == 0) {
return;
}
QueryWrapper<Judge> judgeQueryWrapper = new QueryWrapper<>();
judgeQueryWrapper.in("pid", pidList).eq("cid", 0).eq("status", // 只同步ac的提交
Constants.Judge.STATUS_ACCEPTED.getStatus()).in("uid", uidList);
List<Judge> judgeList = judgeService.list(judgeQueryWrapper);
saveBatchNewRecordByJudgeList(judgeList, tid, null, pidMapTPid);
}
use of top.hcode.hoj.pojo.entity.training.TrainingProblem in project HOJ by HimitZH.
the class TrainingRecordServiceImpl method syncUserSubmissionToRecordByTid.
@Override
@Async
public void syncUserSubmissionToRecordByTid(Long tid, String uid) {
QueryWrapper<TrainingProblem> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("tid", tid);
List<TrainingProblem> trainingProblemList = trainingProblemService.list(queryWrapper);
List<Long> pidList = new ArrayList<>();
HashMap<Long, Long> pidMapTPid = new HashMap<>();
for (TrainingProblem trainingProblem : trainingProblemList) {
pidList.add(trainingProblem.getPid());
pidMapTPid.put(trainingProblem.getPid(), trainingProblem.getId());
}
if (!CollectionUtils.isEmpty(pidList)) {
QueryWrapper<Judge> judgeQueryWrapper = new QueryWrapper<>();
judgeQueryWrapper.in("pid", pidList).eq("cid", 0).eq("status", // 只同步ac的提交
Constants.Judge.STATUS_ACCEPTED.getStatus()).eq("uid", uid);
List<Judge> judgeList = judgeService.list(judgeQueryWrapper);
saveBatchNewRecordByJudgeList(judgeList, tid, null, pidMapTPid);
}
}
use of top.hcode.hoj.pojo.entity.training.TrainingProblem 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);
}
Aggregations