@ -426,20 +426,34 @@ public class EvaluationServiceImpl implements EvaluationService {
academicYearId ,
String . format ( PK . PK_APPRAISE_RECORD , schoolId )
) ;
int stuInClassCount = studentRepository . countByClassIdAndCode ( classId , String . format ( PK . STUDENT , schoolId ) ) ;
List < AppraiseRecord > classRecord = appraiseRecordRepository . findClassRecord ( String . format ( PK . PK_APPRAISE_RECORD , schoolId ) , academicYearId , classId ) ;
if ( appraiseRecord = = null | | appraiseRecord . getNodes ( ) = = null ) {
return null ;
throw new ServiceException ( ErrorCode . OPERATION_ERROR . getCode ( ) , "当前学生暂未产生评价数据,无法生成报告" ) ;
}
Integer praiseCount = appraiseRecord . getPraiseCount ( ) ;
List < AppraiseRecordItem > records = appraiseRecord . getNodes ( ) ;
records = records . stream ( ) . sorted ( Comparator . comparing ( AppraiseRecordItem : : getCreateTime ) . reversed ( ) ) . collect ( Collectors . toList ( ) ) ;
// 查询成就规则
Appraise appraise = RepositoryUtil . findOne ( appraiseRepository . findRulesById ( schoolId , periodId ) , "当前成就规则还未创建" ) ;
List < AchievementRule > rules = appraise . getAchievementRules ( ) ;
if ( CollectionUtil . isEmpty ( rules ) ) {
throw new ServiceException ( ErrorCode . OPERATION_ERROR . getCode ( ) , "当前成就规则为空" ) ;
}
StudentReportVo reportVo = new StudentReportVo ( ) ;
// 计算雷达图
Map < String , Integer > praiseDistribution = StudentReportVo . ofFiveEducation ( ) ;
Map < String , Integer > criticalDistribution = StudentReportVo . ofFiveEducation ( ) ;
// 计算数据
Map < String , Integer > praiseTeacherMap = new HashMap < > ( ) ;
Map < String , Integer > criticalTeacherMap = new HashMap < > ( ) ;
Map < String , Integer > praiseNodeMap = new HashMap < > ( ) ;
Map < String , Integer > criticalNodeMap = new HashMap < > ( ) ;
// 计算当前学生排名在全班次位
float beyondPercent = 0 ;
long currentRank = classRecord . stream ( ) . filter ( item - > item . getPraiseCount ( ) < praiseCount ) . count ( ) ;
beyondPercent = ( float ) currentRank / stuInClassCount ;
// 根据全部数据计算结果
for ( AppraiseRecordItem record : records ) {
AppraiseTreeNode appraiseNode = record . getAppraiseNode ( ) ;
String [ ] path = appraiseNode . getPath ( ) ;
@ -450,19 +464,28 @@ public class EvaluationServiceImpl implements EvaluationService {
String root = path [ 0 ] ;
// 一级评价项不在预期中
String key = FiveEducations . getCodeByName ( root ) ;
if ( key = = null ) {
// todo: 这里的数据异常情况是否需要上报一下
continue ;
// 计算雷达图
if ( key ! = null ) {
if ( appraiseNode . isPraise ( ) ) {
praiseDistribution . put ( key , praiseDistribution . getOrDefault ( key , 0 ) + 1 ) ;
} else {
criticalDistribution . put ( key , criticalDistribution . getOrDefault ( key , 0 ) + 1 ) ;
}
}
String teacherId = record . getCreatorId ( ) ;
String nodeName = appraiseNode . getName ( ) ;
// 根据评价是否为表扬计算数据
if ( appraiseNode . isPraise ( ) ) {
praiseDistribution . put ( key , praiseDistribution . getOrDefault ( key , 0 ) + 1 ) ;
praiseTeacherMap . put ( teacherId , praiseTeacherMap . getOrDefault ( teacherId , 0 ) + 1 ) ;
praiseNodeMap . put ( nodeName , praiseNodeMap . getOrDefault ( nodeName , 0 ) + 1 ) ;
} else {
criticalDistribution . put ( key , criticalDistribution . getOrDefault ( key , 0 ) + 1 ) ;
criticalTeacherMap . put ( teacherId , criticalTeacherMap . getOrDefault ( teacherId , 0 ) + 1 ) ;
criticalNodeMap . put ( nodeName , criticalNodeMap . getOrDefault ( nodeName , 0 ) + 1 ) ;
}
}
// 计算成就项 (排序
rules = rules . stream ( ) . sorted ( Comparator . comparing ( AchievementRule : : getLevel ) . reversed ( ) ) . collect ( Collectors . toList ( ) ) ;
Integer praiseCount = appraiseRecord . getPraiseCount ( ) ;
AchievementRule curAchievement = rules . get ( rules . size ( ) - 1 ) ;
for ( AchievementRule rule : rules ) {
Integer promotionCount = rule . getPromotionCount ( ) ;
@ -473,12 +496,31 @@ public class EvaluationServiceImpl implements EvaluationService {
break ;
}
}
reportVo . setPraiseCount ( appraiseRecord . getPraiseCount ( ) ) ;
reportVo . setScore ( appraiseRecord . getScore ( ) ) ;
reportVo . setPraiseDistribution ( praiseDistribution ) ;
reportVo . setCriticalDistribution ( criticalDistribution ) ;
reportVo . setCurAchievement ( curAchievement ) ;
return reportVo ;
// 汇总数据
String topPraiseTeacherId = praiseTeacherMap . entrySet ( ) . stream ( ) . max ( Map . Entry . comparingByValue ( ) ) . map ( Map . Entry : : getKey ) . orElse ( null ) ;
AppraiseRecordItem tmp1 = records . stream ( ) . filter ( item - > item . getCreatorId ( ) . equals ( topPraiseTeacherId ) ) . findFirst ( ) . orElse ( null ) ;
String topPraiseTeacherName = tmp1 = = null ? null : tmp1 . getCreator ( ) ;
String topCriticalTeacherId = criticalTeacherMap . entrySet ( ) . stream ( ) . max ( Map . Entry . comparingByValue ( ) ) . map ( Map . Entry : : getKey ) . orElse ( null ) ;
AppraiseRecordItem tmp2 = records . stream ( ) . filter ( item - > item . getCreatorId ( ) . equals ( topCriticalTeacherId ) ) . findFirst ( ) . orElse ( null ) ;
String topCriticalTeacherName = tmp2 = = null ? null : tmp2 . getCreator ( ) ;
String topPraiseNode = praiseNodeMap . entrySet ( ) . stream ( ) . max ( Map . Entry . comparingByValue ( ) ) . map ( Map . Entry : : getKey ) . orElse ( null ) ;
String topCriticalNode = criticalNodeMap . entrySet ( ) . stream ( ) . max ( Map . Entry . comparingByValue ( ) ) . map ( Map . Entry : : getKey ) . orElse ( null ) ;
return StudentReportVo . builder ( )
. praiseCount ( praiseCount )
. score ( appraiseRecord . getScore ( ) )
. beyondPercent ( beyondPercent )
. topPraiseTeacher ( new StudentReportVo . Teacher ( topPraiseTeacherId , topPraiseTeacherName ) )
. topCriticalTeacher ( new StudentReportVo . Teacher ( topCriticalTeacherId , topCriticalTeacherName ) )
. topPraiseNode ( topPraiseNode )
. topCriticalNode ( topCriticalNode )
. praiseDistribution ( praiseDistribution )
. criticalDistribution ( criticalDistribution )
. curAchievement ( curAchievement )
. records ( records )
. build ( ) ;
}
/ * *