Joburgess 5 anni fa
parent
commit
f7b07a5d99

+ 9 - 0
edu-user/edu-user-biz/src/main/java/com/keao/edu/user/dao/ExamReviewDao.java

@@ -37,4 +37,13 @@ public interface ExamReviewDao extends BaseDAO<Long, ExamReview> {
     List<ExamReviewRecordDto> queryExamReviewRecordList(Map<String, Object> params);
 
     ExamReview findByRegistrationId(@Param("examRegistrationId") Long examRegistrationId, @Param("teacherId") Integer teacherId);
+
+    /**
+     * @describe 获取考场中学员的评审记录
+     * @author Joburgess
+     * @date 2020.07.30
+     * @param examRoomId:
+     * @return java.util.List<com.keao.edu.user.entity.ExamReview>
+     */
+    List<ExamReview> getWithExamRoom(@Param("examRoomId") Long examRoomId);
 }

+ 9 - 0
edu-user/edu-user-biz/src/main/java/com/keao/edu/user/dao/StudentExamResultDao.java

@@ -87,4 +87,13 @@ public interface StudentExamResultDao extends BaseDAO<Long, StudentExamResult> {
      * @param userId
      */
     StudentExamResult findByRoomIdAndUserId(@Param("roomId") String roomId, @Param("userId") String userId);
+
+    /**
+     * @describe 批量修改考试结果
+     * @author Joburgess
+     * @date 2020.07.30
+     * @param results:
+     * @return int
+     */
+    int updateRegistAvgScore(@Param("results") List<StudentExamResult> results);
 }

+ 9 - 0
edu-user/edu-user-biz/src/main/java/com/keao/edu/user/service/StudentExamResultService.java

@@ -37,6 +37,15 @@ public interface StudentExamResultService extends BaseService<Long, StudentExamR
      */
     void examResultConfirmPush(Long examId);
 
+    /**
+     * @describe 计算考场中学员平均分
+     * @author Joburgess
+     * @date 2020.07.30
+     * @param examRoomId:
+     * @return void
+     */
+    void calculateStudentExamAvgScore(Long examRoomId);
+
     StudentExamResultStatisticsDto getStudentExamResultStatisticsInfo(Integer organId, Integer examId);
 
     /**

+ 6 - 1
edu-user/edu-user-biz/src/main/java/com/keao/edu/user/service/impl/ExamRoomServiceImpl.java

@@ -91,6 +91,8 @@ public class ExamRoomServiceImpl extends BaseServiceImpl<Long, ExamRoom> impleme
 	private IdGeneratorService idGeneratorService;
 	@Autowired
 	private SysConfigService sysConfigService;
+	@Autowired
+	private StudentExamResultService studentExamResultService;
 
 	@Override
 	public BaseDAO<Long, ExamRoom> getDAO() {
@@ -852,6 +854,7 @@ public class ExamRoomServiceImpl extends BaseServiceImpl<Long, ExamRoom> impleme
 			}
 			imFeignService.dismissGroup(sysUser.getId().toString(),examRoomId.toString());
 			imFeignService.destroyRoom(examRoomId);
+			studentExamResultService.calculateStudentExamAvgScore(examRoomId);
 		}
 	}
 
@@ -866,9 +869,10 @@ public class ExamRoomServiceImpl extends BaseServiceImpl<Long, ExamRoom> impleme
 			throw new BizException("考场不存在");
 		}
 		examRoom.setOpenFlag(0);
-		examRoomDao.update(examRoom);
 		imFeignService.dismissGroup(examRoom.getMainTeacherUserId().toString(),examRoomId.toString());
 		imFeignService.destroyRoom(examRoomId);
+		examRoomDao.update(examRoom);
+		studentExamResultService.calculateStudentExamAvgScore(examRoomId);
 		return BaseController.succeed();
 	}
 
@@ -883,6 +887,7 @@ public class ExamRoomServiceImpl extends BaseServiceImpl<Long, ExamRoom> impleme
 			examRoom.setOpenFlag(0);
 			imFeignService.dismissGroup(examRoom.getMainTeacherUserId().toString(),examRoom.getId().toString());
 			imFeignService.destroyRoom(examRoom.getId());
+			studentExamResultService.calculateStudentExamAvgScore(examRoom.getId());
 		}
 		examRoomDao.batchUpdate(examRooms);
 	}

+ 27 - 4
edu-user/edu-user-biz/src/main/java/com/keao/edu/user/service/impl/StudentExamResultServiceImpl.java

@@ -17,15 +17,13 @@ import com.keao.edu.user.api.entity.ExamRoom;
 import com.keao.edu.user.api.entity.ExamRoomStudentRelation;
 import com.keao.edu.user.api.entity.Student;
 import com.keao.edu.user.api.enums.StudentExamResultApiDto;
+import com.keao.edu.user.dao.ExamReviewDao;
 import com.keao.edu.user.dao.ExaminationBasicDao;
 import com.keao.edu.user.dao.StudentExamResultDao;
 import com.keao.edu.user.dto.ExaminationBasicDto;
 import com.keao.edu.user.dto.RecordNotify;
 import com.keao.edu.user.dto.StudentExamResultStatisticsDto;
-import com.keao.edu.user.entity.ExaminationBasic;
-import com.keao.edu.user.entity.Organization;
-import com.keao.edu.user.entity.StudentExamResult;
-import com.keao.edu.user.entity.Subject;
+import com.keao.edu.user.entity.*;
 import com.keao.edu.user.enums.ExamStatusEnum;
 import com.keao.edu.user.enums.LevelEnum;
 import com.keao.edu.user.page.StudentExamResultQueryInfo;
@@ -41,7 +39,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -66,6 +66,8 @@ public class StudentExamResultServiceImpl extends BaseServiceImpl<Long, StudentE
 	private ExamRoomService examRoomService;
 	@Autowired
 	private RedisTemplate<String,String> redisTemplate;
+	@Autowired
+	private ExamReviewDao examReviewDao;
 
 	private final static Logger logger = LoggerFactory.getLogger(StudentExamResultServiceImpl.class);
 
@@ -163,6 +165,27 @@ public class StudentExamResultServiceImpl extends BaseServiceImpl<Long, StudentE
 	}
 
 	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public void calculateStudentExamAvgScore(Long examRoomId) {
+		List<ExamReview> examReviews = examReviewDao.getWithExamRoom(examRoomId);
+		if(CollectionUtils.isEmpty(examReviews)){
+			return;
+		}
+		Map<Long, List<ExamReview>> registReviewMap = examReviews.stream().collect(Collectors.groupingBy(ExamReview::getExamRegistrationId));
+		List<StudentExamResult> needUpdateStudentExamResult = new ArrayList<>();
+		for (Map.Entry<Long, List<ExamReview>> registReviewEntry : registReviewMap.entrySet()) {
+			StudentExamResult studentExamResult=new StudentExamResult();
+			studentExamResult.setExamRegistrationId(registReviewEntry.getKey());
+			List<ExamReview> reviews = registReviewEntry.getValue();
+			long totalScore = reviews.stream().mapToLong(ExamReview::getEvaluationResult).sum();
+			BigDecimal avgScore = new BigDecimal(totalScore).divide(new BigDecimal(reviews.size()), 2, BigDecimal.ROUND_CEILING);
+			studentExamResult.setAvgScore(avgScore.floatValue());
+			needUpdateStudentExamResult.add(studentExamResult);
+		}
+		studentExamResultDao.updateRegistAvgScore(needUpdateStudentExamResult);
+	}
+
+	@Override
 	public StudentExamResultStatisticsDto getStudentExamResultStatisticsInfo(Integer organId, Integer examId) {
 		if(Objects.isNull(examId)){
 			throw new BizException("请指定考级项目");

+ 4 - 0
edu-user/edu-user-biz/src/main/resources/config/mybatis/ExamReviewMapper.xml

@@ -226,4 +226,8 @@
 	<select id="findByRegistrationId" resultMap="ExamReviewRecordDtoMap">
 		SELECT * FROM exam_review WHERE exam_registration_id_ = #{examRegistrationId} AND teacher_id_ = #{teacherId} LIMIT 1
 	</select>
+
+    <select id="getWithExamRoom" resultMap="ExamReview">
+		SELECT * FROM exam_review WHERE exam_room_id_=#{examRoomId}
+	</select>
 </mapper>

+ 8 - 1
edu-user/edu-user-biz/src/main/resources/config/mybatis/StudentExamResultMapper.xml

@@ -114,7 +114,14 @@
 		WHERE exam_registration_id_ = #{examRegistrationId}
 	</update>
 
-    <!-- 根据主键删除一条记录 -->
+	<update id="updateRegistAvgScore" parameterType="com.keao.edu.user.entity.StudentExamResult">
+		<foreach collection="results" item="result" separator=";">
+			UPDATE student_exam_result SET avg_score_=#{result.avgScore},update_time_=NOW()
+			WHERE exam_registration_id_ = #{result.examRegistrationId}
+		</foreach>
+	</update>
+
+	<!-- 根据主键删除一条记录 -->
 	<delete id="delete" >
 		DELETE FROM student_exam_result WHERE id_ = #{id} 
 	</delete>