|
@@ -263,106 +263,134 @@ public class CalculateScoreLogicImpl implements CalculateSocreLogic {
|
|
|
|
|
|
@Override
|
|
|
public List<CaughtNodeDTO> catchNode(Long examId, Long caseId, Long userId, List<CaughtNodeDTO> caughtNodeDTOs) {
|
|
|
- List<CaughtNodeDTO> caughtNodeDTOList = new ArrayList<>();
|
|
|
- for (CaughtNodeDTO caughtNodeDTO : caughtNodeDTOs) {
|
|
|
- List<CaughtNodeDTO> cnDTOs = caughtNodeService.getCaughtNodeList(examId, caseId);
|
|
|
- for (CaughtNodeDTO cnDTO : cnDTOs) {
|
|
|
- cnDTO.setTotalNum(cnDTO.getTotalNum() + 1);
|
|
|
- caughtNodeService.updateCaughtNodeDTO(cnDTO);
|
|
|
+ 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);
|
|
|
}
|
|
|
-
|
|
|
- if (!caughtNodeDTO.getNodeName().isEmpty()) {
|
|
|
- String nodeName = caughtNodeDTO.getNodeName();
|
|
|
- //caughtNode
|
|
|
- caughtNodeDTO = caughtNodeService.getCaughtNodeDTO(examId, caseId, nodeName);
|
|
|
- if (caughtNodeDTO != null) {
|
|
|
- List<Long> userIds = caughtNodeDTO.getUserIds();
|
|
|
- userIds.add(userId);
|
|
|
- caughtNodeDTO.setUserIds(userIds);
|
|
|
- caughtNodeDTO.setCatchNum(caughtNodeDTO.getCatchNum() + 1);
|
|
|
- } else {
|
|
|
- List<Long> userIds = new ArrayList<>();
|
|
|
- userIds.add(userId);
|
|
|
-
|
|
|
- caughtNodeDTO = new CaughtNodeDTO();
|
|
|
- caughtNodeDTO.setNodeName(nodeName);
|
|
|
- caughtNodeDTO.setExamId(examId);
|
|
|
- caughtNodeDTO.setCaseId(caseId);
|
|
|
- caughtNodeDTO.setUserIds(userIds);
|
|
|
- caughtNodeDTO.setCatchNum(1);
|
|
|
- caughtNodeDTO.setTotalNum(1);
|
|
|
+ } 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");
|
|
|
}
|
|
|
- caughtNodeDTOList.add(caughtNodeService.updateCaughtNodeDTO(caughtNodeDTO));
|
|
|
-
|
|
|
-
|
|
|
- //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);
|
|
|
+ List<Long> userIds = oldcnDTO.getUserIds();
|
|
|
+ userIds.add(userId);
|
|
|
+ oldcnDTO.setUserIds(userIds);
|
|
|
+ if (caughtNodeDTO.getIfCatch().equals(Boolean.TRUE)) {
|
|
|
+ oldcnDTO.setCatchNum(oldcnDTO.getCatchNum() + 1);
|
|
|
}
|
|
|
- userCatchService.updateUserCatch(userCatchDTO);
|
|
|
+ oldcnDTO.setTotalNum(oldcnDTO.getTotalNum() + 1);
|
|
|
+ cn = caughtNodeService.updateCaughtNodeDTO(oldcnDTO);
|
|
|
+ returnList.add(cn);
|
|
|
}
|
|
|
}
|
|
|
- return caughtNodeDTOList;
|
|
|
+
|
|
|
+ //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);
|
|
|
+ }
|
|
|
+
|
|
|
+ userCatchService.updateUserCatch(userCatchDTO);
|
|
|
+ return returnList;
|
|
|
}
|
|
|
|
|
|
-// @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");
|
|
|
-// }
|
|
|
-// if (taskService.ifCaseInTask(caseId, examId)) {
|
|
|
-// throw new HttpBadRequestException("case not belong to the exam");
|
|
|
-// }
|
|
|
-// //caughtNode
|
|
|
-// caughtNodeDTO = caughtNodeService.getCaughtNodeDTO(examId, caseId, caughtNodeDTO.getNodeName());
|
|
|
+
|
|
|
+// List<CaughtNodeDTO> caughtNodeDTOList = new ArrayList<>();
|
|
|
+// for (CaughtNodeDTO caughtNodeDTO : caughtNodeDTOs) {
|
|
|
//
|
|
|
-// if (caughtNodeDTO == null) {
|
|
|
-// caughtNodeDTO = caughtNodeService.createCaughtNode(caughtNodeDTO);
|
|
|
-// }
|
|
|
-// if (caughtNodeDTO != null) {
|
|
|
-// List<Long> userIds = caughtNodeDTO.getUserIds();
|
|
|
-// Long userId = userIdList.get(0);
|
|
|
-// userIds.add(userId);
|
|
|
-// caughtNodeDTO.setUserIds(userIds);
|
|
|
-// caughtNodeDTO.setCatchNum(caughtNodeDTO.getCatchNum() + 1);
|
|
|
+// if (!caughtNodeDTO.getNodeName().isEmpty()) {
|
|
|
+// String nodeName = caughtNodeDTO.getNodeName();
|
|
|
+// //caughtNode
|
|
|
+// caughtNodeDTO = caughtNodeService.getCaughtNodeDTO(examId, caseId, nodeName);
|
|
|
+// if (caughtNodeDTO != null) {
|
|
|
+// List<CaughtNodeDTO> cnDTOs = caughtNodeService.getCaughtNodeList(examId, caseId);
|
|
|
+// addTotalNum(cnDTOs);
|
|
|
//
|
|
|
-// //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);
|
|
|
-// }
|
|
|
+// List<Long> userIds = caughtNodeDTO.getUserIds();
|
|
|
+// userIds.add(userId);
|
|
|
+// caughtNodeDTO.setUserIds(userIds);
|
|
|
+// caughtNodeDTO.setCatchNum(caughtNodeDTO.getCatchNum() + 1);
|
|
|
+// caughtNodeDTO = caughtNodeService.updateCaughtNodeDTO(caughtNodeDTO);
|
|
|
+//// caughtNodeDTOList.add(caughtNodeService.updateCaughtNodeDTO(caughtNodeDTO));
|
|
|
+//
|
|
|
+// } else {
|
|
|
+// List<CaughtNodeDTO> cnDTOs = caughtNodeService.getCaughtNodeList(examId, caseId);
|
|
|
+// if (cnDTOs != null) {
|
|
|
+// addTotalNum(cnDTOs);
|
|
|
+//
|
|
|
+// caughtNodeDTO = createNewCaughtNodeDTO(userId, caseId, examId, nodeName);
|
|
|
+// caughtNodeDTO.setTotalNum(caughtNodeService.getCaughtNodeList(examId, caseId).get(0).getTotalNum() + 1);
|
|
|
+// } else {
|
|
|
+// caughtNodeDTO = createNewCaughtNodeDTO(userId, caseId, examId, nodeName);
|
|
|
+// }
|
|
|
//
|
|
|
-// List<CaughtNodeDTO> caughtNodeDTOs = caughtNodeService.getCaughtNodeList(examId, caseId);
|
|
|
-// caughtNodeDTOs.stream().forEach(caughtNodeDTO1 -> caughtNodeDTO1.setTotalNum(caughtNodeDTO1.getTotalNum() + 1));
|
|
|
-// return caughtNodeService.updateCaughtNodeDTO(caughtNodeDTO);
|
|
|
+// caughtNodeDTOList.add(caughtNodeService.updateCaughtNodeDTO(caughtNodeDTO));
|
|
|
+// }
|
|
|
+
|
|
|
+// //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);
|
|
|
+//}
|
|
|
+//}
|
|
|
+// return caughtNodeDTOList;
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ return caughtNodeService.updateCaughtNodeDTO(caughtNodeDTO);
|
|
|
+ }
|
|
|
|
|
|
}
|