|
@@ -20,19 +20,14 @@ import cn.iselab.mooctest.site.web.data.forMongo.NodeCatch.CaughtNodeDTO;
|
|
import cn.iselab.mooctest.site.web.data.forMongo.NodeCatch.UserCatchDTO;
|
|
import cn.iselab.mooctest.site.web.data.forMongo.NodeCatch.UserCatchDTO;
|
|
import cn.iselab.mooctest.site.web.data.forMongo.caseGraph.CaseGraphDTO;
|
|
import cn.iselab.mooctest.site.web.data.forMongo.caseGraph.CaseGraphDTO;
|
|
import cn.iselab.mooctest.site.web.data.fromKibug.ScoreRuleItemVO;
|
|
import cn.iselab.mooctest.site.web.data.fromKibug.ScoreRuleItemVO;
|
|
-import cn.iselab.mooctest.site.web.exception.HttpBadRequestException;
|
|
|
|
import cn.iselab.mooctest.site.web.exception.HttpNotFoundException;
|
|
import cn.iselab.mooctest.site.web.exception.HttpNotFoundException;
|
|
import cn.iselab.mooctest.site.web.logic.CalculateSocreLogic;
|
|
import cn.iselab.mooctest.site.web.logic.CalculateSocreLogic;
|
|
import cn.iselab.mooctest.site.web.logic.CaseLogic;
|
|
import cn.iselab.mooctest.site.web.logic.CaseLogic;
|
|
import cn.iselab.mooctest.site.web.util.mongodb.MongoAPIUtils;
|
|
import cn.iselab.mooctest.site.web.util.mongodb.MongoAPIUtils;
|
|
|
|
+
|
|
import org.json.JSONObject;
|
|
import org.json.JSONObject;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
-import org.springframework.http.HttpEntity;
|
|
|
|
-import org.springframework.http.HttpHeaders;
|
|
|
|
-import org.springframework.http.HttpMethod;
|
|
|
|
-import org.springframework.http.MediaType;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
-import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
@@ -289,62 +284,78 @@ public class CalculateScoreLogicImpl implements CalculateSocreLogic {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public CaughtNodeDTO catchNode(CaughtNodeDTO caughtNodeDTO) {
|
|
|
|
- Long examId = caughtNodeDTO.getExamId();
|
|
|
|
- Long caseId = caughtNodeDTO.getCaseId();
|
|
|
|
- List<Long> userIdList = caughtNodeDTO.getUserIds();
|
|
|
|
- String nodeName = caughtNodeDTO.getNodeName();
|
|
|
|
- if (taskService.getTask(examId) == null) {
|
|
|
|
- throw new HttpNotFoundException("exam not exist");
|
|
|
|
- }
|
|
|
|
- if (caseService.getCaseById(caseId) == null) {
|
|
|
|
- throw new HttpNotFoundException("case not exist");
|
|
|
|
|
|
+ public List<CaughtNodeDTO> catchNode(Long examId, Long caseId, Long userId, List<CaughtNodeDTO> caughtNodeDTOs) {
|
|
|
|
+ List<CaughtNodeDTO> returnList = new ArrayList<>();
|
|
|
|
+ List<CaughtNodeDTO> caughtNodeList = caughtNodeService.getCaughtNodeList(examId, caseId);
|
|
|
|
+ CaughtNodeDTO cn = new CaughtNodeDTO();
|
|
|
|
+ if (caughtNodeList == null) {
|
|
|
|
+ for (CaughtNodeDTO caughtNodeDTO : caughtNodeDTOs) {
|
|
|
|
+ cn = createNewCaughtNodeDTO(userId, caseId, examId, caughtNodeDTO.getNodeName(), caughtNodeDTO.getIfCatch());
|
|
|
|
+ returnList.add(cn);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ for (CaughtNodeDTO caughtNodeDTO : caughtNodeDTOs) {
|
|
|
|
+ CaughtNodeDTO oldcnDTO = caughtNodeService.getCaughtNodeDTO(examId, caseId, caughtNodeDTO.getNodeName());
|
|
|
|
+ if (oldcnDTO == null) {
|
|
|
|
+ throw new HttpNotFoundException("this node in this exam not exist");
|
|
|
|
+ }
|
|
|
|
+ List<Long> userIds = oldcnDTO.getUserIds();
|
|
|
|
+ userIds.add(userId);
|
|
|
|
+ oldcnDTO.setUserIds(userIds);
|
|
|
|
+
|
|
|
|
+ if (caughtNodeDTO.getIfCatch().equals(Boolean.TRUE)) {
|
|
|
|
+ oldcnDTO.setCatchNum(oldcnDTO.getCatchNum() + 1);
|
|
|
|
+ oldcnDTO.setIfCatch(caughtNodeDTO.getIfCatch());
|
|
|
|
+ }
|
|
|
|
+ oldcnDTO.setTotalNum(oldcnDTO.getTotalNum() + 1);
|
|
|
|
+ cn = caughtNodeService.updateCaughtNodeDTO(oldcnDTO);
|
|
|
|
+ returnList.add(cn);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- if (taskService.ifCaseInTask(caseId, examId)) {
|
|
|
|
- throw new HttpBadRequestException("case not belong to the exam");
|
|
|
|
|
|
+
|
|
|
|
+ //userCatch
|
|
|
|
+ UserCatchDTO userCatchDTO = userCatchService.getUserCatchDTO(userId);
|
|
|
|
+ if (userCatchDTO != null)
|
|
|
|
+
|
|
|
|
+ {
|
|
|
|
+ List<String> nodeNames = userCatchDTO.getNodeNames();
|
|
|
|
+ nodeNames.add(cn.getNodeName());
|
|
|
|
+ List<String> distinctNodeNames = nodeNames.stream().distinct().collect(Collectors.toList());
|
|
|
|
+ userCatchDTO.setNodeNames(distinctNodeNames);
|
|
|
|
+ } else
|
|
|
|
+
|
|
|
|
+ {
|
|
|
|
+ userCatchDTO = new UserCatchDTO();
|
|
|
|
+ userCatchDTO.setUserId(userId);
|
|
|
|
+ List<String> nodeNames = new ArrayList<>();
|
|
|
|
+ nodeNames.add(cn.getNodeName());
|
|
|
|
+ userCatchDTO.setNodeNames(nodeNames);
|
|
}
|
|
}
|
|
- //caughtNode
|
|
|
|
- caughtNodeDTO = caughtNodeService.getCaughtNodeDTO(examId, caseId, caughtNodeDTO.getNodeName());
|
|
|
|
-
|
|
|
|
- if (caughtNodeDTO != null) {
|
|
|
|
- List<Long> userIds = caughtNodeDTO.getUserIds();
|
|
|
|
- Long userId = userIdList.get(0);
|
|
|
|
- userIds.add(userId);
|
|
|
|
- caughtNodeDTO.setUserIds(userIds);
|
|
|
|
- caughtNodeDTO.setCatchNum(caughtNodeDTO.getCatchNum() + 1);
|
|
|
|
-
|
|
|
|
- //userCatch
|
|
|
|
- UserCatchDTO userCatchDTO = userCatchService.getUserCatchDTO(userId);
|
|
|
|
- if (userCatchDTO != null) {
|
|
|
|
- List<String> nodeNames = userCatchDTO.getNodeNames();
|
|
|
|
- nodeNames.add(caughtNodeDTO.getNodeName());
|
|
|
|
- List<String> distinctNodeNames = nodeNames.stream().distinct().collect(Collectors.toList());
|
|
|
|
- userCatchDTO.setNodeNames(distinctNodeNames);
|
|
|
|
- } else {
|
|
|
|
- userCatchDTO = new UserCatchDTO();
|
|
|
|
- userCatchDTO.setUserId(userId);
|
|
|
|
- List<String> nodeNames = new ArrayList<>();
|
|
|
|
- nodeNames.add(caughtNodeDTO.getNodeName());
|
|
|
|
- userCatchDTO.setNodeNames(nodeNames);
|
|
|
|
- }
|
|
|
|
- userCatchService.updateUserCatch(userCatchDTO);
|
|
|
|
|
|
+
|
|
|
|
+ userCatchService.updateUserCatch(userCatchDTO);
|
|
|
|
+ return returnList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private CaughtNodeDTO createNewCaughtNodeDTO(Long userId, Long caseId, Long examId, String nodeName, Boolean ifCatch) {
|
|
|
|
+ CaughtNodeDTO caughtNodeDTO = new CaughtNodeDTO();
|
|
|
|
+ List<Long> userIds = new ArrayList<>();
|
|
|
|
+ userIds.add(userId);
|
|
|
|
+
|
|
|
|
+ caughtNodeDTO.setNodeName(nodeName);
|
|
|
|
+ caughtNodeDTO.setExamId(examId);
|
|
|
|
+ caughtNodeDTO.setCaseId(caseId);
|
|
|
|
+ caughtNodeDTO.setUserIds(userIds);
|
|
|
|
+ caughtNodeDTO.setIfCatch(ifCatch);
|
|
|
|
+ if (ifCatch.equals(Boolean.TRUE)) {
|
|
|
|
+ caughtNodeDTO.setCatchNum(1);
|
|
|
|
+ } else {
|
|
|
|
+ caughtNodeDTO.setCatchNum(0);
|
|
}
|
|
}
|
|
|
|
+ caughtNodeDTO.setTotalNum(1);
|
|
|
|
|
|
- List<CaughtNodeDTO> caughtNodeDTOs = caughtNodeService.getCaughtNodeList(examId, caseId);
|
|
|
|
- caughtNodeDTOs.stream().forEach(caughtNodeDTO1 -> caughtNodeDTO1.setTotalNum(caughtNodeDTO1.getTotalNum() + 1));
|
|
|
|
return caughtNodeService.updateCaughtNodeDTO(caughtNodeDTO);
|
|
return caughtNodeService.updateCaughtNodeDTO(caughtNodeDTO);
|
|
- }
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
- public CaughtNodeDTO createCaughtNode(CaughtNodeDTO caughtNodeDTO) {
|
|
|
|
- RestTemplate rt = new RestTemplate();
|
|
|
|
- HttpHeaders headers = MongoAPIUtils.createAuthHeaderForMongo();
|
|
|
|
- headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
|
- HttpEntity<CaughtNodeDTO> httpEntity = new HttpEntity<>(caughtNodeDTO, headers);
|
|
|
|
- String url = MongoAPIUtils.generateCommonUrl(mongoDBConfig.getDb(),
|
|
|
|
- mongoDBConfig.getCaughtNodeCollection());
|
|
|
|
- rt.exchange(url, HttpMethod.POST, httpEntity, String.class);
|
|
|
|
-
|
|
|
|
- return caughtNodeDTO;
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|