package com.jsoj.app.jsoj.web.controller;
import com.jsoj.app.jsoj.competition.CompetitionGlobal;
import com.jsoj.app.jsoj.competition.CompetitionO2o;
import com.jsoj.app.jsoj.domain.Compercord;
import com.jsoj.app.jsoj.domain.Competition;
import com.jsoj.app.jsoj.domain.Question;
import com.jsoj.app.jsoj.domain.User;
import com.jsoj.app.jsoj.serive.CompercordService;
import com.jsoj.app.jsoj.serive.CompetitionService;
import com.jsoj.app.jsoj.serive.QuestionService;
import com.jsoj.app.jsoj.serive.UserService;
import com.jsoj.app.jsoj.util.ServerResponse;
import com.jsoj.app.jsoj.vo.Compedetail;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpSession;
import java.util.*;
import java.util.concurrent.TimeUnit;
@RestController
@RequestMapping("/api/Competition")
public class CompetitionController {
@Autowired
private QuestionService questionService;
@Autowired
private UserService userService;
@Autowired
private StringRedisTemplate redisTemplate;
@Autowired
private CompetitionService competitionService;
@Autowired
private CompercordService compercordService;
CompetitionGlobal competitionGlobal = CompetitionGlobal.getInstance();
@GetMapping("/MatchO2o")
public ServerResponse pipei(HttpSession session) throws InterruptedException {
User user1 = (User)session.getAttribute("user");
User user = new User();
BeanUtils.copyProperties(user1,user); //拷贝对象
user.setPassword(null);
CompetitionO2o competitionO2o = competitionGlobal.getCompetitionO2oForWait();
if (competitionO2o!=null){
competitionO2o.setUserTwo(user);
competitionO2o.setStatus(1);
Date now = new Date();
competitionO2o.setStartTime(now);
List<Question> randomQuestionMany = questionService.getRandomQuestionMany(10);
for (Question question:randomQuestionMany){
question.setDescription(question.getDescription().replaceAll("\\n","<br>"));
}
competitionO2o.setQuestions(randomQuestionMany);
Calendar ca= Calendar.getInstance();
ca.setTime(now);
ca.add(Calendar.MINUTE,2);
competitionO2o.setEndTime(ca.getTime());
competitionO2o.getRecord().put(user.getUsername(),new ArrayList());
competitionGlobal.pushCompetitionO2oRun(competitionO2o);
return ServerResponse.createBySuccess(competitionO2o.getId());
}else{
//创建存入 -> 检测变化 -> 返回
CompetitionO2o competitionO2o1 = new CompetitionO2o();
competitionO2o1.getRecord().put(user.getUsername(),new ArrayList());
competitionGlobal.pushCompetitionO2oWait(competitionO2o1);
competitionO2o1.setUserOne(user);
int i = 0 ;
while (true){
i++;
if (i>10){
competitionGlobal.getCompetitionO2oForWait();
return ServerResponse.createBySuccess();
}
if (competitionO2o1.getStatus()==1) {
return ServerResponse.createBySuccess(competitionO2o1.getId());
}
Thread.sleep(2000);
}
}
}
@GetMapping("/get/{id}")
public ServerResponse getIn(@PathVariable String id){
return ServerResponse.createBySuccess(competitionGlobal.getCompetitionO2oRu(id));
}
@PostMapping("/checkAnswer")
public Object checkAnswer(@RequestBody HashMap<String, String> map, HttpSession session){
String code = map.get("code");
String id = map.get("id");
String que_id = map.get("queid");
User user = (User)(session.getAttribute("user"));
if (competitionGlobal.isHaveRecord(user.getUsername(),id,que_id)){
return ServerResponse.createByErrorMessage("涉嫌重复提交刷分");
}
String runtime = questionService.checkAnswer(code, que_id, (User) session.getAttribute("user"));
questionService.incrQUestionAllCount(que_id); //提交+1
if (runtime!=null){ //runtime!=null
int count = competitionGlobal.putRecord(user.getUsername(), id, que_id);
if (count==10){
competitionGlobal.getCompetitionO2oRu(id).setEndTime(new Date());
competitionGlobal.win(id);
}
return ServerResponse.createBySuccess();
}else{
return ServerResponse.createByErrorMessage("未通过");
}
}
@GetMapping("/checkStatus/{id}")
@Scope("single")
public ServerResponse checkStatus(@PathVariable String id){
CompetitionO2o competitionO2o = competitionGlobal.getCompetitionO2oRu(id);
if (competitionO2o==null){
return ServerResponse.createByErrorMessage("无数据");
}
if (competitionO2o.getStatus()==2){
competitionO2o.setStatus(3);
}
HashMap<String, List<String>> status = competitionGlobal.checkStatus(id);
if (status==null){
return checkSync(competitionO2o);
}
return ServerResponse.createBySuccess(status);
}
@GetMapping("/getComp")
public ServerResponse getComp(HttpSession session){
User user = (User)session.getAttribute("user");
return ServerResponse.createBySuccess(compercordService.getCompercord(user.getId()));
}
@GetMapping("/getCompdetail")
public ServerResponse getCompdetail(int id){
HashMap<String,Object> map = new HashMap();
List<Compedetail> competition = competitionService.getCompetition(id);
String[] questions = competition.get(0).getQuestion().split("::");
ArrayList arrayList = new ArrayList();
for (String question:questions){
HashMap tempMap = new HashMap();
Question tempQues = questionService.getQuestion(question);
tempMap.put("id",tempQues.getId());
tempMap.put("title",tempQues.getTitle());
arrayList.add(tempMap);
}
map.put("detail",competition);
map.put("question",arrayList);
return ServerResponse.createBySuccess(map);
}
//同步检测删除
private synchronized ServerResponse checkSync(CompetitionO2o competitionO2o){
String id = competitionO2o.getId();
User userOne = competitionO2o.getUserOne();
User userTwo = competitionO2o.getUserTwo();
HashMap<String, List<String>> record = competitionO2o.getRecord();
List<Question> questions = competitionO2o.getQuestions();
int userOneScore = 0;
for(String temp:record.get(userOne.getUsername())){
for (Question question:questions){
if (temp.equals(question.getId())){
userOneScore+=question.getScore();
}
}
}
int userTwoScore = 0;
for(String temp:record.get(userTwo.getUsername())){
for (Question question:questions){
if (temp.equals(question.getId())){
userTwoScore+=question.getScore();
}
}
}
userOne.setScore(userOneScore);
userTwo.setScore(userTwoScore);
HashMap map = new HashMap();
map.put(userOne.getUsername(),userOne);
map.put(userTwo.getUsername(),userTwo);
if (redisTemplate.hasKey(competitionO2o.getId())){ //删除并存入记录
String qidStr = "";
List<Question> questionslist = competitionO2o.getQuestions();
for(Question question:questionslist){
qidStr+=question.getId()+"::";
}
没有合适的资源?快使用搜索试试~ 我知道了~
毕业设计&课设-基于SpringBoot的在线算法判题系统(在线判断)JavaScript.zip
共484个文件
js:214个
html:138个
css:69个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 197 浏览量
2024-06-16
07:24:41
上传
评论
收藏 1.05MB ZIP 举报
温馨提示
该资源内项目源码是个人的课程设计、毕业设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 该资源内项目源码是个人的课程设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。
资源推荐
资源详情
资源评论
收起资源包目录
毕业设计&课设-基于SpringBoot的在线算法判题系统(在线判断)JavaScript.zip (484个子文件)
mvnw.cmd 6KB
ambiance.css 26KB
codemirror.css 9KB
solarized.css 5KB
mdn-like.css 5KB
liquibyte.css 4KB
merge.css 3KB
yonce.css 3KB
xq-dark.css 3KB
lint.css 3KB
duotone-light.css 3KB
lesser-dark.css 3KB
duotone-dark.css 3KB
icecoder.css 2KB
material.css 2KB
pastel-on-dark.css 2KB
darcula.css 2KB
ttcn.css 2KB
shadowfox.css 2KB
tomorrow-night-eighties.css 2KB
erlang-dark.css 2KB
oceanic-next.css 2KB
xq-light.css 2KB
monokai.css 2KB
twilight.css 2KB
vibrant-ink.css 2KB
base16-light.css 2KB
base16-dark.css 2KB
mbo.css 2KB
nord.css 2KB
paraiso-light.css 2KB
paraiso-dark.css 2KB
3024-night.css 2KB
dracula.css 2KB
seti.css 2KB
zenburn.css 2KB
3024-day.css 2KB
abcdef.css 2KB
the-matrix.css 2KB
blackboard.css 2KB
lucario.css 2KB
yeti.css 2KB
tern.css 2KB
midnight.css 2KB
panda-syntax.css 2KB
rubyblue.css 2KB
tomorrow-night-bright.css 2KB
night.css 2KB
gruvbox-dark.css 2KB
cobalt.css 2KB
colorforth.css 2KB
idea.css 2KB
railscasts.css 1KB
hopscotch.css 1KB
isotope.css 1KB
bespin.css 1KB
simplescrollbars.css 1KB
eclipse.css 1KB
neo.css 947B
elegant.css 781B
ssms.css 751B
neat.css 688B
show-hint.css 623B
dialog.css 507B
tiki.css 439B
foldgutter.css 435B
tiddlywiki.css 220B
matchesonscrollbar.css 188B
fullscreen.css 116B
ambiance-mobile.css 103B
.gitignore 333B
scala.html 28KB
index.html 22KB
index.html 17KB
index.html 13KB
user.html 13KB
index.html 13KB
index.html 12KB
question.html 12KB
companies.html 12KB
companiesCode.html 12KB
Ouser.html 11KB
index.html 10KB
rank.html 10KB
index.html 10KB
record.html 9KB
index.html 9KB
index.html 9KB
code.html 9KB
index.html 8KB
index.html 8KB
index.html 8KB
vuet.html 8KB
index.html 7KB
index.html 7KB
login.html 6KB
index.html 6KB
index.html 6KB
index.html 6KB
index.html 6KB
共 484 条
- 1
- 2
- 3
- 4
- 5
资源评论
毕业小助手
- 粉丝: 2762
- 资源: 5583
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功