瀏覽代碼

Merge branch 'feature-score-page-service' into 'DEV'

add interfaces for score adjustion

添加分数调整所需后台接口

See merge request !796

huangyong 7 年之前
父節點
當前提交
de3df5ab93

+ 5 - 0
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/dao/Exam2CaseDao.java

@@ -2,11 +2,13 @@ package cn.iselab.mooctest.site.dao;
 
 import cn.iselab.mooctest.site.models.Exam2Case;
 import cn.iselab.mooctest.site.models.Exam2Paper;
+import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.repository.CrudRepository;
 
 
 import javax.transaction.Transactional;
 import java.util.List;
+import org.springframework.data.repository.query.Param;
 
 /**
  * Created by HenryLee on 2017/7/19.
@@ -20,4 +22,7 @@ public interface Exam2CaseDao extends CrudRepository<Exam2Case, Long> {
     List<Exam2Case> findByExamId(Long examId);
 
     List<Exam2Case> findByCaseId(long caseId);
+
+    @Query("select distinct e.caseId from Exam2Case e where e.examId = :examId")
+    List<Long> findCasesByExamId(@Param("examId") Long examId);
 }

+ 2 - 1
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/dao/GradeGeneralDao.java

@@ -30,7 +30,8 @@ public interface GradeGeneralDao extends JpaRepository<GradeGeneral,Long> {
 
   @Query("select g from GradeGeneral g where g.uploadTime="
       + "(select max(g1.uploadTime) from GradeGeneral g1 where g1.workerId=:workerId and "
-      + "g1.examId=:examId and g1.caseId=:caseId)")
+      + "g1.examId=:examId and g1.caseId=:caseId) "
+      + "and g.workerId=:workerId and g.examId=:examId and g.caseId=:caseId")
   List<GradeGeneral> getLatestScores(@Param("workerId")long workerId, @Param("examId")long
       examId, @Param("caseId")long caseId);
 

+ 2 - 0
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/service/Exam2CaseService.java

@@ -24,4 +24,6 @@ public interface Exam2CaseService {
     List<CaseBlock> getCasesByExamId(Long examId);
 
     int getScoreStrategyByExamIdAndCaseId(Long examId, Long caseId);
+
+    List<Long> getCaseIdsByExamId(Long examId);
 }

+ 6 - 0
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/service/impl/Exam2CaseServiceImpl.java

@@ -110,4 +110,10 @@ public class Exam2CaseServiceImpl implements Exam2CaseService {
             return 0;
         }
     }
+
+    @Override
+    public List<Long> getCaseIdsByExamId(Long examId) {
+        List<Long> caseIds = exam2CaseDao.findCasesByExamId(examId);
+        return caseIds;
+    }
 }

+ 18 - 0
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/web/ctrl/ExamController.java

@@ -189,6 +189,24 @@ public class ExamController extends BaseSearchController {
         return examLogic.getAssignedTasks(examId, keyword, needFilter, pageable);
     }
 
+    @RequiresPermissions("assignedTasks:view")
+    @RequestMapping(value = UrlConstants.API + "workerAssignedTask", method = RequestMethod.GET)
+    public AssignedTaskVO getAssignedTaskByExamIdAndWorkerId(@RequestParam(name = "examId") Long examId,
+        @RequestParam(name = "workerId") Long workerId ) throws Exception {
+        Long userId = (Long) SecurityUtils.getSubject().getSession().getAttribute("userId");
+        String examPermissionStr = userId.toString() + ":task:view:" + examId.toString();
+        if (!SecurityUtils.getSubject().isPermitted(new ExamPermission(examPermissionStr))) {
+            throw new UnauthenticatedException("forbidden");
+        }
+
+        boolean hasScorePermission = SecurityUtils.getSubject().isPermitted(new ExamPermission(userId.toString() + ":task:score:" + examId.toString()));
+        if(hasScorePermission){
+            return examLogic.getAssignedTask(examId,workerId);
+        }else{
+            throw new UnauthenticatedException("forbidden");
+        }
+    }
+
     public Page<UserVO> getUsersExamId(@RequestParam(name = "examId", required = false) Long examId,
                                        @RequestParam(name = "sortOrder", required = false, defaultValue = "desc") String sortOrder,
                                        @RequestParam(name = "sortBy", required = false, defaultValue = "id") String sortBy,

+ 24 - 0
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/web/ctrl/ScoreController.java

@@ -105,6 +105,15 @@ public class ScoreController extends BaseController {
     }
 
     @RequestMapping(value = UrlConstants.API_COMMON +
+        "generalCalculateScoreSingle", method = RequestMethod.PUT)
+    public void updateCaseScore(@RequestParam("examId") long examId,
+        @RequestParam("caseId") long caseId,
+        @RequestParam("userId") long userId) {
+        //重新从type得分计算某个学生的分数
+        generalCalculateScoreLogic.calculateCaseScore(examId, caseId, userId);
+    }
+
+    @RequestMapping(value = UrlConstants.API_COMMON +
             "generalCalculateScoreAll", method = RequestMethod.PUT)
     public void updateCaseScore(@RequestParam("examId") long examId,
                                 @RequestParam("caseId") long caseId) {
@@ -113,6 +122,13 @@ public class ScoreController extends BaseController {
     }
 
     @RequestMapping(value = UrlConstants.API_COMMON +
+        "generalCalculateExamScoreAll", method = RequestMethod.PUT)
+    public void updateCaseScore(@RequestParam("examId") long examId) {
+        //重新从type得分计算整场考试所有人的分数
+        generalCalculateScoreLogic.calculateExamScore(examId);
+    }
+
+    @RequestMapping(value = UrlConstants.API_COMMON +
             "generalCalculateScoreAllFromNode", method = RequestMethod.PUT)
     public void generalCatchNode(@RequestParam("examId") long examId,
                                  @RequestParam("caseId") long caseId,
@@ -122,6 +138,14 @@ public class ScoreController extends BaseController {
     }
 
     @RequestMapping(value = UrlConstants.API_COMMON +
+        "generalCalculateExamScoreAllFromNode", method = RequestMethod.PUT)
+    public void generalCatchNode(@RequestParam("examId") long examId,
+        @RequestParam("source") String source) throws Exception {
+        //重新从node计算整场考试所有人的分数
+        generalCalculateScoreLogic.calculateExamScoreFromNode(examId,source);
+    }
+
+    @RequestMapping(value = UrlConstants.API_COMMON +
             "uploadCaseScore", method = RequestMethod.PUT)
     public void updateCaseScore(@RequestParam("examId") long examId,
                                 @RequestParam("caseId") long caseId,

+ 2 - 0
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/web/logic/ExamLogic.java

@@ -33,6 +33,8 @@ public interface ExamLogic {
 
     Page<AssignedTaskVO> getAssignedTasks(Long examId, String keyword, Boolean needFilter, Pageable pageable);
 
+    AssignedTaskVO getAssignedTask(Long examId, Long workerId);
+
     Page<UserVO> getUsers(Long examId, Boolean needFilter, Long userId, String keyword, Pageable pageable);
 
     Map<Long, UserVO> getParticipantMap(long examId);

+ 17 - 2
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/web/logic/GeneralCalculateScoreLogic.java

@@ -9,11 +9,26 @@ package cn.iselab.mooctest.site.web.logic;
 public interface GeneralCalculateScoreLogic {
 
     /**
-     * 计算一场考试中一道题的得分
+     * 从node计算一场考试的得分
+     * @param examId
+     * @param source
+     * @throws Exception
+     */
+    void calculateExamScoreFromNode(long examId, String source) throws Exception;
+
+    /**
+     * 从general_grade计算一场考试的得分
+     * @param examId
+     * @throws Exception
+     */
+    void calculateExamScore(long examId);
+
+    /**
+     * 从node计算一场考试中一道题的得分
      *
      * @param examId examId
      * @param caseId caseId
-     * @param userId userId
+     * @param userId userId 为null时表示计算所有人
      * @param source source
      */
     void calculateScore(long examId, long caseId, Long userId, String source) throws Exception;

+ 13 - 0
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/web/logic/impl/ExamLogicImpl.java

@@ -233,6 +233,19 @@ public class ExamLogicImpl extends BaseLogic implements ExamLogic {
     }
 
     @Override
+    public AssignedTaskVO getAssignedTask(Long examId, Long workerId) {
+        SubmitRecord submitRecord = submitRecordService.getAssignedTask(examId,workerId);
+        AssignedTaskVO vo = assignedTaskVOWrapper.wrap(submitRecord);
+        UserDTOForMT worker = userService.findByUserId(workerId);
+        vo.setWorkerName(worker.getName());
+        vo.setWorkerSchool(worker.getSchool());
+        vo.setWorkerId(worker.getId());
+        vo.setAssignedCases(assignedCaseVOWrapper.wrap(submitRecordService.wrapAssignedCases(submitRecord)));
+
+        return vo;
+    }
+
+    @Override
     public Page<UserVO> getUsers(Long examId, Boolean needFilter, Long userId, String keyword, Pageable pageable) {
         Page<UserVO> userVOS;
         if(needFilter) {

+ 21 - 0
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/web/logic/impl/GeneralCalculateScoreLogicImpl.java

@@ -1,5 +1,6 @@
 package cn.iselab.mooctest.site.web.logic.impl;
 
+import cn.iselab.mooctest.site.service.Exam2CaseService;
 import cn.iselab.mooctest.site.service.GeneralCalculateScoreService;
 import cn.iselab.mooctest.site.service.SubmitRecordService;
 import cn.iselab.mooctest.site.service.WeightGeneralService;
@@ -29,7 +30,27 @@ public class GeneralCalculateScoreLogicImpl implements GeneralCalculateScoreLogi
   @Autowired
   GeneralCalculateScoreComponent generalCalculateScoreComponent;
 
+  @Autowired
+  Exam2CaseService exam2CaseService;
+
 
+  @Override
+  public void calculateExamScoreFromNode(long examId, String source) throws Exception {
+    List<Long> caseIds = exam2CaseService.getCaseIdsByExamId(examId);
+    caseIds.forEach(caseId -> {
+      try {
+        calculateScore(examId,caseId,null,source);
+      } catch (Exception e) {
+        e.printStackTrace();
+      }
+    });
+  }
+
+  @Override
+  public void calculateExamScore(long examId){
+    List<Long> caseIds = exam2CaseService.getCaseIdsByExamId(examId);
+    caseIds.forEach(caseId -> calculateCaseScore(examId,caseId));
+  }
 
   @Override
   public void calculateScore(long examId, long caseId, Long userId, String source) throws Exception{