Parcourir la source

Merge branch 'DEV' into compete-analysis

# Conflicts:
#	mooctest-site-server/src/main/java/cn/iselab/mooctest/site/web/logic/impl/CalculateScoreLogicImpl.java
梅杰 il y a 7 ans
Parent
commit
d45ae6e18f

+ 18 - 16
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/service/impl/CaughtNodeServiceImpl.java

@@ -77,6 +77,23 @@ public class CaughtNodeServiceImpl implements CaughtNodeService {
         }
     }
 
+    private List<CaughtNodeDTO> extractCaughtNodeList(ResponseEntity<JSONObject> dto) {
+        JSONArray resultArray = dto.getBody().getJSONArray("_embedded");
+        if (resultArray.size() == 0) {
+            return null;
+        } else {
+            List<CaughtNodeDTO> caughtNodeList = new ArrayList<>();
+            for (int i = 0; i < resultArray.size(); i++) {
+                JSONObject result = resultArray.getJSONObject(i);
+                Gson gson = new Gson();
+                CaughtNodeDTO caughtNodeDTO = gson.fromJson(result.toString(), CaughtNodeDTO.class);
+//                caughtNodeDTO.setId(result.getJSONObject("_id").getString("$oid"));
+                caughtNodeList.add(caughtNodeDTO);
+            }
+            return caughtNodeList;
+        }
+    }
+
     @Override
     public List<CaughtNodeDTO> getCaughtNodeList(Long examId, Long caseId) {
         HttpHeaders headers = MongoAPIUtils.createAuthHeaderForMongo();
@@ -97,20 +114,5 @@ public class CaughtNodeServiceImpl implements CaughtNodeService {
         return extractCaughtNodeList(dto);
     }
 
-    private List<CaughtNodeDTO> extractCaughtNodeList(ResponseEntity<JSONObject> dto) {
-        JSONArray resultArray = dto.getBody().getJSONArray("_embedded");
-        if (resultArray.size() == 0) {
-            return null;
-        } else {
-            List<CaughtNodeDTO> caughtNodeList = new ArrayList<>();
-            for (int i = 0; i < resultArray.size(); i++) {
-                JSONObject result = resultArray.getJSONObject(i);
-                Gson gson = new Gson();
-                CaughtNodeDTO caughtNodeDTO = gson.fromJson(result.toString(), CaughtNodeDTO.class);
-//                caughtNodeDTO.setId(result.getJSONObject("_id").getString("$oid"));
-                caughtNodeList.add(caughtNodeDTO);
-            }
-            return caughtNodeList;
-        }
-    }
+
 }

+ 3 - 4
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/web/ctrl/CaseController.java

@@ -5,9 +5,9 @@ import cn.iselab.mooctest.site.common.web.ErrorResult;
 import cn.iselab.mooctest.site.common.web.ResponseMessage;
 import cn.iselab.mooctest.site.common.web.StatusCode;
 import cn.iselab.mooctest.site.common.web.SuccessResult;
-import cn.iselab.mooctest.site.models.*;
-import cn.iselab.mooctest.site.models.instancePermission.TaskPermission;
+import cn.iselab.mooctest.site.models.User;
 import cn.iselab.mooctest.site.models.instancePermission.CasePermission;
+import cn.iselab.mooctest.site.models.instancePermission.TaskPermission;
 import cn.iselab.mooctest.site.service.ExamService;
 import cn.iselab.mooctest.site.util.http.RequestUtils;
 import cn.iselab.mooctest.site.web.data.CaseExtendsVO;
@@ -28,7 +28,6 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.validation.constraints.NotNull;
-import java.net.URL;
 import java.util.List;
 import java.util.Map;
 
@@ -121,7 +120,7 @@ public class CaseController extends BaseController {
     }
 
     @RequiresPermissions("case:update")
-    @RequestMapping(value = UrlConstants.API + "case/{caseId}", method = RequestMethod.PUT)
+    @RequestMapping(value = UrlConstants.API + "case/{caseId}", method = RequestMethod.POST)
     public void updateCase(@RequestBody CaseExtendsVO caseExtendsVO,@PathVariable("caseId") Long caseId){
         User user = (User) SecurityUtils.getSubject().getSession().getAttribute("User");
         String permissionStr = user.getId().toString() + ":case:update:" + caseId.toString();

+ 22 - 23
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/web/ctrl/ScoreController.java

@@ -22,7 +22,7 @@ import java.util.Map;
  * Created by HenryLee on 2017/7/10.
  */
 @RestController
-public class ScoreController extends BaseController{
+public class ScoreController extends BaseController {
 
     @Autowired
     private CalculateSocreLogic calculateSocreLogic;
@@ -30,28 +30,28 @@ public class ScoreController extends BaseController{
 
 
     //一次考试的一道题的所有人的分
-    @RequestMapping(value= UrlConstants.API+"score/{taskId}/{caseId}", method = RequestMethod.PUT)
-    public void CalculateScore(@PathVariable("taskId") long taskId,@PathVariable("caseId") long caseId) throws Exception{
-        calculateSocreLogic.calculateScore(taskId,caseId);
-}
+    @RequestMapping(value = UrlConstants.API + "score/{taskId}/{caseId}", method = RequestMethod.PUT)
+    public void CalculateScore(@PathVariable("taskId") long taskId, @PathVariable("caseId") long caseId) throws Exception {
+        calculateSocreLogic.calculateScore(taskId, caseId);
+    }
 
     //一次考试的一道题的一个人的分
-    @RequestMapping(value= UrlConstants.API+"score/{taskId}/{caseId}/{userId}", method = RequestMethod.PUT)
-    public void CalculateScore(@PathVariable("taskId") long taskId,@PathVariable("caseId") long caseId, @PathVariable("userId") long userId) throws Exception{
-        calculateSocreLogic.calculateScore(taskId,caseId,userId);
+    @RequestMapping(value = UrlConstants.API + "score/{taskId}/{caseId}/{userId}", method = RequestMethod.PUT)
+    public void CalculateScore(@PathVariable("taskId") long taskId, @PathVariable("caseId") long caseId, @PathVariable("userId") long userId) throws Exception {
+        calculateSocreLogic.calculateScore(taskId, caseId, userId);
     }
 
     //一次考试的一个人的分 或者 一次考试的所有人的分
     @RequiresRoles("manager")
-    @RequestMapping(value = UrlConstants.API + "score",method = RequestMethod.PUT)
-    public List<Double> CalculateTaskScore(@RequestParam(name="examId") Long examId,
-                                           @RequestParam(name="participantId",required = false) Long participantId,
-                                           @RequestParam(name="calculateAll") boolean calculateAll,
-                                           @RequestBody WeightDirtyVO weightDirtyVO) throws Exception{
-        return calculateSocreLogic.calculateExamScore(examId,participantId,weightDirtyVO,calculateAll);
+    @RequestMapping(value = UrlConstants.API + "score", method = RequestMethod.PUT)
+    public List<Double> CalculateTaskScore(@RequestParam(name = "examId") Long examId,
+                                           @RequestParam(name = "participantId", required = false) Long participantId,
+                                           @RequestParam(name = "calculateAll") boolean calculateAll,
+                                           @RequestBody WeightDirtyVO weightDirtyVO) throws Exception {
+        return calculateSocreLogic.calculateExamScore(examId, participantId, weightDirtyVO, calculateAll);
     }
 
-    @RequestMapping(value= UrlConstants.API + "score/mutation", method = RequestMethod.PUT)
+    @RequestMapping(value = UrlConstants.API + "score/mutation", method = RequestMethod.PUT)
     public Map<String, Object> calculateAllMutationScore(@RequestParam("examId") long examId,
                                                          @RequestParam("caseId") long caseId) throws IOException {
 
@@ -59,14 +59,13 @@ public class ScoreController extends BaseController{
         return SuccessResult.ok();
     }
 
-    @RequestMapping(value = UrlConstants.API_COMMON + "caughtNode", method = RequestMethod.POST)
-    public CaughtNodeDTO catchNode(@RequestBody CaughtNodeDTO caughtNodeDTO) throws Exception{
-        return calculateSocreLogic.catchNode(caughtNodeDTO);
-    }
-
-    @RequestMapping(value = UrlConstants.API_COMMON + "caughtNode/generation", method = RequestMethod.POST)
-    public CaughtNodeDTO createCaughtNode(@RequestBody CaughtNodeDTO caughtNodeDTO)throws Exception{
-        return calculateSocreLogic.createCaughtNode(caughtNodeDTO);
+    //学生提交结果分析
+    @RequestMapping(value = UrlConstants.API_COMMON + "caughtNode/{examId}/{caseId}", method = RequestMethod.PUT)
+    public List<CaughtNodeDTO> catchNode(@PathVariable("examId") Long examId,
+                                         @PathVariable("caseId") Long caseId,
+                                         @RequestParam("userId") Long userId,
+                                         @RequestBody List<CaughtNodeDTO> caughtNodeDTOs) throws Exception {
+        return calculateSocreLogic.catchNode(examId, caseId, userId, caughtNodeDTOs);
     }
 
     @RequestMapping(value = UrlConstants.API + "competeAnalysis", method = RequestMethod.GET)

+ 4 - 2
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/web/data/forMongo/NodeCatch/CaughtNodeDTO.java

@@ -20,10 +20,12 @@ public class CaughtNodeDTO {
 
     private String nodeName;
 
+    private Boolean ifCatch;
+
     private List<Long> userIds;
 
     //default
-    private Integer catchNum = 0;
+    private Integer catchNum ;
 
-    private Integer totalNum = 0;
+    private Integer totalNum ;
 }

+ 0 - 10
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/web/data/forMongo/NodeCatch/UserCatchDTO.java

@@ -18,14 +18,4 @@ public class UserCatchDTO {
 
     private List<String> nodeNames;
 
-    public Boolean checkNodeNameUnique() {
-        long count = nodeNames.size();
-        long distinctCount = nodeNames.stream().distinct().count();
-        Boolean unique = count == distinctCount;
-        if (!unique) {
-            throw new IllegalArgumentException("node name must be unique!");
-        }
-        return unique;
-    }
-
 }

+ 1 - 3
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/web/logic/CalculateSocreLogic.java

@@ -20,7 +20,5 @@ public interface CalculateSocreLogic {
 
     void calculateAllMutationScore(long examId, long caseId) throws IOException;
 
-    CaughtNodeDTO catchNode(CaughtNodeDTO caughtNodeDTO);
-
-    CaughtNodeDTO createCaughtNode(CaughtNodeDTO caughtNodeDTO);
+    List<CaughtNodeDTO> catchNode(Long examId, Long caseId, Long userId, List<CaughtNodeDTO> caughtNodeDTOs);
 }

+ 68 - 57
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/web/logic/impl/CalculateScoreLogicImpl.java

@@ -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.caseGraph.CaseGraphDTO;
 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.logic.CalculateSocreLogic;
 import cn.iselab.mooctest.site.web.logic.CaseLogic;
 import cn.iselab.mooctest.site.web.util.mongodb.MongoAPIUtils;
+
 import org.json.JSONObject;
 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.web.client.RestTemplate;
 
 import java.io.IOException;
 import java.util.*;
@@ -289,62 +284,78 @@ public class CalculateScoreLogicImpl implements CalculateSocreLogic {
     }
 
     @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);
-    }
 
-    @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;
     }
+
 }

+ 3 - 3
mooctest-site-server/src/main/resources/application.yaml

@@ -54,9 +54,9 @@ aliOSS:
 spring:
     profiles: dev
     datasource:
-        url: jdbc:mysql://101.37.175.111:3306/mooctest_main_dev?useUnicode=yes&characterEncoding=UTF-8
-        username: mooctest
-        password: secr3t!
+        url: jdbc:mysql://106.14.81.62:3306/mooctest_main_dev?useUnicode=yes&characterEncoding=UTF-8
+        username: root
+        password: secr3t!0525
     dubbo:
         application.name: local-dubbo-main-site-provider-consumer3
         registry.address: zookeeper://101.37.175.111:2181