diff --git a/src/main/java/com/msdw/tms/entity/vo/ProjectRecordVo.java b/src/main/java/com/msdw/tms/entity/vo/ProjectRecordVo.java index fc7884a..6132610 100644 --- a/src/main/java/com/msdw/tms/entity/vo/ProjectRecordVo.java +++ b/src/main/java/com/msdw/tms/entity/vo/ProjectRecordVo.java @@ -5,6 +5,7 @@ import lombok.Data; import lombok.experimental.Accessors; import java.io.Serializable; +import java.math.BigDecimal; import java.util.List; @Data diff --git a/src/main/java/com/msdw/tms/service/impl/ProjectRecordServiceImpl.java b/src/main/java/com/msdw/tms/service/impl/ProjectRecordServiceImpl.java index 543d8b6..ee92bb8 100644 --- a/src/main/java/com/msdw/tms/service/impl/ProjectRecordServiceImpl.java +++ b/src/main/java/com/msdw/tms/service/impl/ProjectRecordServiceImpl.java @@ -24,6 +24,8 @@ import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletResponse; import java.io.InputStream; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.text.DecimalFormat; import java.util.HashMap; import java.util.List; @@ -92,12 +94,53 @@ public class ProjectRecordServiceImpl extends ServiceImpl sumByPracticeNum = this.baseMapper.sumByPracticeNum(userId); + //练习总分 + Integer practiceByScore = 0; + //练习总耗时 + Integer practiceByTime = 0; + for (GetByUserRecordResp resp : sumByPracticeNum) { + //累计总分 + practiceByScore += resp.getScore(); + //累计时间 + practiceByTime += resp.getTimeSum(); + } + //考核统计 List sumByAssessmentNum = this.baseMapper.sumByAssessmentNum(userId); + //练习总分 + Integer assessmenteByScore = 0; + //练习总耗时 + double assessmentByTime = 0; + for (ProjectRecordVo vo : sumByAssessmentNum) { + //累计总分 + assessmenteByScore += vo.getScore(); + //累计时间 + assessmentByTime += vo.getTimeSum(); + } + + + //设置实验次数 Integer numer = sumByPracticeNum.size() + sumByAssessmentNum.size(); projectRecordVo.setExperimentNumber(numer); + + //取平均分 + //BigDecimal getSumByScore = (new BigDecimal(practiceByScore).add(new BigDecimal(assessmenteByScore))).divide(new BigDecimal(numer)).setScale(2, RoundingMode.HALF_UP); + + if (practiceByScore + assessmenteByScore != 0) { + double getSumByScore = (practiceByScore + assessmenteByScore) / numer; + projectRecordVo.setAvgScore(getSumByScore); + } else { + projectRecordVo.setAvgScore(0); + } + + + //获得总耗时 + double getTime = practiceByTime + assessmentByTime; + projectRecordVo.setTotalTime(new Double(getTime)); + + Double totalTime = projectRecordVo.getTotalTime(); if (totalTime != null) { DecimalFormat df = new DecimalFormat("0.00");