wucl há 1 ano atrás
pai
commit
e089f0c847

+ 4 - 2
src/main/java/com/dayou/controller/DocumentController.java

@@ -58,8 +58,10 @@ public class DocumentController {
     @IgnoreAuth
     @PostMapping("/commit")
     public RestResponse<Boolean> commitDocument(@RequestBody @Valid DocumentCycleVO documentCycleVO){
-        Boolean result = professorResultService.commitDocument(documentCycleVO);
-        return RestResponse.data(result);
+        synchronized (this){
+            Boolean result = professorResultService.commitDocument(documentCycleVO);
+            return RestResponse.data(result);
+        }
     }
 
     /**

+ 1 - 1
src/main/java/com/dayou/dao/ProfessorResultMapper.java

@@ -22,7 +22,7 @@ import java.util.Map;
  * created with IntelliJ IDEA.
  */
 public interface ProfessorResultMapper extends BaseMapper<ProfessorResult> {
-    List<QuestionAnalysis> getAvgScore(@Param("cycleId") Long cycleId, @Param("questionId")Long questionId);
+    List<QuestionAnalysis> getAvgScore(@Param("cycleId") Long cycleId);
 
 
     List<ProfessorResultVO> getResultList(@Param("cycle") Cycle cycle);

+ 2 - 0
src/main/java/com/dayou/entity/Question.java

@@ -35,4 +35,6 @@ public class Question extends BaseEntity {
 
     @TableField(exist = false)
     private BigDecimal score;
+    @TableField(exist = false)
+    private BigDecimal previousAvgScore;
 }

+ 1 - 0
src/main/java/com/dayou/service/IQuestionService.java

@@ -17,4 +17,5 @@ public interface IQuestionService extends IService<Question> {
     List<QuestionTreeVO> getQuestionTree(Question question);
 
     List<Question>  getFailQuestions(List<Long> parentIds);
+
 }

+ 22 - 8
src/main/java/com/dayou/service/impl/DocumentServiceImpl.java

@@ -16,6 +16,7 @@ import org.apache.commons.collections.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -47,6 +48,9 @@ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, Document> i
     @Autowired
     private ICycleService cycleService;
 
+    @Autowired
+    private IQuestionAnalysisService questionAnalysisService;
+
     @Override
     public DocumentCycleVO getDocumentCycleVO() {
         Configuration mini = configurationService.getOne(new LambdaQueryWrapper<Configuration>().eq(Configuration::getName, "mini").eq(BaseEntity::getDeleted, Boolean.FALSE));
@@ -55,31 +59,41 @@ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, Document> i
         }
         DocumentCycleVO documentCycleVO = documentMapper.getDocumentCycleVO();
 
+        //是否需要返回上一轮的平均分
+        Map<Long, BigDecimal> previousCycleAvgScore = new HashMap<>();
+        if (documentCycleVO.getCycleNum()>1){
+            Cycle previousCycle = cycleService.getOne(new LambdaQueryWrapper<Cycle>().eq(Cycle::getDocumentId, documentCycleVO.getDocumentId())
+                    .eq(Cycle::getCycleNum, (documentCycleVO.getCycleNum() - 1)));
+            previousCycleAvgScore = questionAnalysisService.list(new LambdaQueryWrapper<QuestionAnalysis>()
+                            .select(QuestionAnalysis::getQuestionId, QuestionAnalysis::getAvgScore).eq(QuestionAnalysis::getCycleId,previousCycle.getId()))
+                    .stream().collect(Collectors.toMap(QuestionAnalysis::getQuestionId, QuestionAnalysis::getAvgScore));
+        }
         List<FailQuestion> failQuestions = failQuestionService.list(new LambdaQueryWrapper<FailQuestion>()
                 .eq(FailQuestion::getCycleId, documentCycleVO.getId()).eq(BaseEntity::getDeleted, Boolean.FALSE));
         List<List<Question>> results = new ArrayList<>();
+        Map<Long,List<Question>> result = new LinkedHashMap<>();
         if (CollectionUtils.isNotEmpty(failQuestions)){
             //未通过评分项下发逻辑
             List<Long> parentIds = failQuestions.stream().map(FailQuestion::getQuestionParentId).collect(Collectors.toList());
             List<Question> fQuestions = questionService.getFailQuestions(parentIds);
             Map<Long, List<Question>> fails = fQuestions.stream().collect(Collectors.groupingBy(Question::getParentId));
-            for(Map.Entry<Long,List<Question>> map :fails.entrySet()){
-                results.add(map.getValue());
-            }
-            documentCycleVO.setQuestions(results);
+            fails.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEachOrdered(e->result.put(e.getKey(),e.getValue()));
         }else {
             //全量评分项下发逻辑
             Long typeId = documentCycleVO.getTypeId();
             List<Question> children = Lists.newArrayList();
             children = findChildren(typeId, children);
-            Map<Long,List<Question>> result = new LinkedHashMap<>();
             Map<Long, List<Question>> collect = children.stream().collect(Collectors.groupingBy(Question::getParentId));
             collect.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEachOrdered(e->result.put(e.getKey(),e.getValue()));
-            for(Map.Entry<Long,List<Question>> map :result.entrySet()){
-                results.add(map.getValue());
+        }
+        for(Map.Entry<Long,List<Question>> map :result.entrySet()){
+            List<Question> value = map.getValue();
+            for (Question question :value){
+                question.setPreviousAvgScore(previousCycleAvgScore.get(question.getId()));
             }
-            documentCycleVO.setQuestions(results);
+            results.add(value);
         }
+        documentCycleVO.setQuestions(results);
         return documentCycleVO;
     }
 

+ 4 - 12
src/main/java/com/dayou/service/impl/ProfessorResultServiceImpl.java

@@ -46,7 +46,7 @@ public class ProfessorResultServiceImpl extends ServiceImpl<ProfessorResultMappe
 
     @Transactional
     @Override
-    public synchronized Boolean commitDocument(DocumentCycleVO documentCycleVO) {
+    public Boolean commitDocument(DocumentCycleVO documentCycleVO) {
         List<Question> questions = documentCycleVO.getResult();
         String professorNo = documentCycleVO.getProfessorNo();
         Long cycleId = documentCycleVO.getId();
@@ -67,8 +67,8 @@ public class ProfessorResultServiceImpl extends ServiceImpl<ProfessorResultMappe
             this.saveBatch(collect);
         }
 
-        Set<Long> allQuestionId = this.list(new LambdaQueryWrapper<ProfessorResult>().eq(ProfessorResult::getCycleId, cycleId)).stream().map(ProfessorResult::getQuestionId).collect(Collectors.toSet());
-        analysisScore(cycleId,allQuestionId);
+        List<QuestionAnalysis> avgScores = professorResultMapper.getAvgScore(cycleId);
+        questionAnalysisService.saveOrUpdateBatch(avgScores);
         webSocketServer.sendSocket("data");
         return Boolean.TRUE;
     }
@@ -104,7 +104,7 @@ public class ProfessorResultServiceImpl extends ServiceImpl<ProfessorResultMappe
         this.removeById(id);
         Long cycleId = pr.getCycleId();
         Long questionId = pr.getQuestionId();
-        List<QuestionAnalysis> avgScores = professorResultMapper.getAvgScore(cycleId,questionId);
+        List<QuestionAnalysis> avgScores = professorResultMapper.getAvgScore(cycleId);
         return questionAnalysisService.saveOrUpdateBatch(avgScores);
     }
 
@@ -120,12 +120,4 @@ public class ProfessorResultServiceImpl extends ServiceImpl<ProfessorResultMappe
         Map<Long, BigDecimal> currentAvgScoreMap = currentAvgScoreList.stream().collect(Collectors.toMap(QuestionAnalysis::getQuestionId, QuestionAnalysis::getAvgScore));
         return currentAvgScoreMap;
     }
-
-    private Boolean analysisScore(Long cycleId,Set<Long> questionIds){
-        for (Long questionId : questionIds){
-            List<QuestionAnalysis> avgScores = professorResultMapper.getAvgScore(cycleId,questionId);
-            questionAnalysisService.saveOrUpdateBatch(avgScores);
-        }
-        return Boolean.TRUE;
-    }
 }

+ 1 - 0
src/main/java/com/dayou/service/impl/QuestionServiceImpl.java

@@ -59,4 +59,5 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
         List<Question> list = questionMapper.getFailQuestions(parentIds);
         return list;
     }
+
 }

+ 4 - 0
src/main/java/com/dayou/vo/DocumentCycleVO.java

@@ -5,6 +5,7 @@ import com.github.liangbaika.validate.annations.AbcValidate;
 import com.github.liangbaika.validate.enums.Check;
 import lombok.Data;
 
+import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.util.List;
@@ -41,4 +42,7 @@ public class DocumentCycleVO {
 
     @AbcValidate(required = true,message = "专家编号不能为空",fun = Check.NotEmpty)
     private String professorNo;
+
+    private Integer cycleNum;
+
 }

+ 1 - 0
src/main/resources/mapper/AnalysisResultMapper.xml

@@ -59,6 +59,7 @@
 
     <select id="getParentLabel" resultType="com.dayou.vo.ChildrenParentName">
         SELECT
+        DISTINCT
             q.label AS label,
             qq.label AS parentLabel
         FROM

+ 2 - 0
src/main/resources/mapper/DocumentMapper.xml

@@ -11,6 +11,7 @@
         <result column="type_id" property="typeId" />
         <result column="item_name" property="itemName" />
         <result column="created" property="created" />
+        <result column="type_id" property="typeId" />
 <!--        <collection property="questions"  ofType="com.dayou.vo.QuestionVO" select="selectQuestion" column="document_id"/>-->
     </resultMap>
 
@@ -29,6 +30,7 @@
             d.type_id,
             qq.label as type,
             CONCAT('第',t.cycle_num,'轮') as cycleName,
+            t.cycle_num,
             d.id AS document_id,
             t.id,
             t.created