|
@@ -1,24 +1,30 @@
|
|
package com.ruoyi.system.service.impl.score;
|
|
package com.ruoyi.system.service.impl.score;
|
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
-import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
|
|
+import com.ruoyi.common.constant.CacheConstants;
|
|
|
|
+import com.ruoyi.common.core.domain.entity.FormalParentsStudent;
|
|
|
|
+import com.ruoyi.common.core.domain.entity.FormalTeacherClass;
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
-import com.ruoyi.common.exception.CustomException;
|
|
|
|
|
|
+import com.ruoyi.common.core.redis.RedisCache;
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
import com.ruoyi.system.domain.score.ScoreData;
|
|
import com.ruoyi.system.domain.score.ScoreData;
|
|
import com.ruoyi.system.domain.score.ScoreDataDetails;
|
|
import com.ruoyi.system.domain.score.ScoreDataDetails;
|
|
|
|
+import com.ruoyi.system.mapper.FormalParentsStudentMapper;
|
|
|
|
+import com.ruoyi.system.mapper.FormalTeacherClassMapper;
|
|
import com.ruoyi.system.mapper.score.ScoreDataMapper;
|
|
import com.ruoyi.system.mapper.score.ScoreDataMapper;
|
|
import com.ruoyi.system.service.score.IScoreDataService;
|
|
import com.ruoyi.system.service.score.IScoreDataService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
+import static com.ruoyi.common.utils.PageUtils.startPage;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 成绩Service业务层处理
|
|
* 成绩Service业务层处理
|
|
*
|
|
*
|
|
@@ -30,6 +36,13 @@ public class ScoreDataServiceImpl implements IScoreDataService {
|
|
@Autowired
|
|
@Autowired
|
|
private ScoreDataMapper scoreDataMapper;
|
|
private ScoreDataMapper scoreDataMapper;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private FormalTeacherClassMapper formalTeacherClassMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private FormalParentsStudentMapper formalParentsStudentMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisCache redisCache;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 查询成绩
|
|
* 查询成绩
|
|
*
|
|
*
|
|
@@ -49,7 +62,47 @@ public class ScoreDataServiceImpl implements IScoreDataService {
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public List<ScoreData> selectScoreDataList(ScoreData scoreData) {
|
|
public List<ScoreData> selectScoreDataList(ScoreData scoreData) {
|
|
- return scoreDataMapper.selectScoreDataList(scoreData);
|
|
|
|
|
|
+ SysUser user = SecurityUtils.getLoginUser().getUser();
|
|
|
|
+ StringBuilder classId = new StringBuilder("0,");
|
|
|
|
+ Map<String, Object> params = scoreData.getParams();
|
|
|
|
+ String role = "admin";
|
|
|
|
+ if (params != null && params.size() > 0) {
|
|
|
|
+ role = (String) params.get("role");
|
|
|
|
+ }
|
|
|
|
+ List<ScoreData> scoreDataList = new ArrayList<>();
|
|
|
|
+ if ("teacher".equals(role)) {
|
|
|
|
+ FormalTeacherClass formalTeacherClass = new FormalTeacherClass();
|
|
|
|
+ formalTeacherClass.setTeacherId(user.getUserId());
|
|
|
|
+ List<FormalTeacherClass> formalTeacherClasses = formalTeacherClassMapper.selectFormalTeacherClassList(formalTeacherClass);
|
|
|
|
+ if (formalTeacherClasses != null && formalTeacherClasses.size() > 0) {
|
|
|
|
+ for (FormalTeacherClass teacherClass : formalTeacherClasses) {
|
|
|
|
+ classId.append(teacherClass.getClassId()).append(",");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(classId.toString())) {
|
|
|
|
+ classId = new StringBuilder(classId.substring(0, classId.length() - 1));
|
|
|
|
+ }
|
|
|
|
+ startPage();
|
|
|
|
+ scoreData.setScoreClassId(classId.toString());
|
|
|
|
+ scoreDataList = scoreDataMapper.selectScoreDataList(scoreData);
|
|
|
|
+ } else if ("parents".equals(role)) {
|
|
|
|
+ FormalParentsStudent formalParentsStudent = new FormalParentsStudent();
|
|
|
|
+ formalParentsStudent.setParentsId(user.getUserId());
|
|
|
|
+ List<FormalParentsStudent> formalParentsStudents = formalParentsStudentMapper.selectFormalParentsStudentList(formalParentsStudent);
|
|
|
|
+ for (FormalParentsStudent parentsStudent : formalParentsStudents) {
|
|
|
|
+ classId.append(parentsStudent.getClassId()).append(",");
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotBlank(classId.toString())) {
|
|
|
|
+ classId = new StringBuilder(classId.substring(0, classId.length() - 1));
|
|
|
|
+ }
|
|
|
|
+ startPage();
|
|
|
|
+ scoreData.setScoreClassId(classId.toString());
|
|
|
|
+ scoreDataList = scoreDataMapper.selectScoreDataList(scoreData);
|
|
|
|
+ } else if ("admin".equals(role)) {
|
|
|
|
+ startPage();
|
|
|
|
+ scoreDataList = scoreDataMapper.selectScoreDataList(scoreData);
|
|
|
|
+ }
|
|
|
|
+ return scoreDataList;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -58,12 +111,19 @@ public class ScoreDataServiceImpl implements IScoreDataService {
|
|
* @param scoreData 成绩
|
|
* @param scoreData 成绩
|
|
* @return 结果
|
|
* @return 结果
|
|
*/
|
|
*/
|
|
- @Transactional
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
@Override
|
|
@Override
|
|
public int insertScoreData(ScoreData scoreData) {
|
|
public int insertScoreData(ScoreData scoreData) {
|
|
scoreData.setCreateTime(DateUtils.getNowDate());
|
|
scoreData.setCreateTime(DateUtils.getNowDate());
|
|
int rows = scoreDataMapper.insertScoreData(scoreData);
|
|
int rows = scoreDataMapper.insertScoreData(scoreData);
|
|
- insertScoreDataDetails(scoreData);
|
|
|
|
|
|
+ List<ScoreDataDetails> scoreDataDetailsList = scoreData.getScoreDataDetailsList();
|
|
|
|
+ if (scoreDataDetailsList != null && scoreDataDetailsList.size() > 0) {
|
|
|
|
+ scoreDataDetailsList.stream().sorted(Comparator.comparing(ScoreDataDetails::getZongfen).reversed()).collect(Collectors.toList());
|
|
|
|
+ for (int i = 0; i < scoreDataDetailsList.size(); i++) {
|
|
|
|
+ scoreDataDetailsList.get(i).setScoreSort(i + 1 + "");
|
|
|
|
+ }
|
|
|
|
+ insertScoreDataDetails(scoreData);
|
|
|
|
+ }
|
|
return rows;
|
|
return rows;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -108,6 +168,120 @@ public class ScoreDataServiceImpl implements IScoreDataService {
|
|
return scoreDataMapper.deleteScoreDataByScoreId(scoreId);
|
|
return scoreDataMapper.deleteScoreDataByScoreId(scoreId);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 后台首页成绩统计排名
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public List<ScoreDataDetails> indexPaiMing(ScoreData scoreData) {
|
|
|
|
+ //最新一次考试
|
|
|
|
+ List<ScoreDataDetails> scoreDataDetails = scoreDataMapper.selectScoreDataByScoreClassId(scoreData.getScoreClassId());
|
|
|
|
+ if (scoreDataDetails != null && scoreDataDetails.size() > 0) {
|
|
|
|
+ scoreDataDetails = scoreDataDetails.subList(0, Math.min(scoreDataDetails.size(), 10));
|
|
|
|
+ }
|
|
|
|
+ return scoreDataDetails;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 后台首页成绩统计分段人数饼图最新一次考试
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Map<String, Object> indexBingTu(ScoreData scoreData) {
|
|
|
|
+ //获取缓存的数据
|
|
|
|
+ Map<String, Object> cacheMap = redisCache.getCacheMap(CacheConstants.FEN_DUAN_NEW);
|
|
|
|
+ //获取班级id对应的最新考试id
|
|
|
|
+ Long scoreDataId = (Long) redisCache.getCacheObject(CacheConstants.SCORE_ID + scoreData.getScoreClassId());
|
|
|
|
+ boolean flag = false;
|
|
|
|
+ if (cacheMap != null) {
|
|
|
|
+ //获取redis缓存的考试id
|
|
|
|
+ Long scoreId = (Long) cacheMap.get("scoreId");
|
|
|
|
+ //判断最新一次考试id和缓存id是否匹配
|
|
|
|
+ if (scoreDataId.equals(scoreId)) {
|
|
|
|
+ //说明缓存就是最新的
|
|
|
|
+ return cacheMap;
|
|
|
|
+ } else {
|
|
|
|
+ //说明缓存数据不是最新的需要放到对比数据key中去 成为对比数据
|
|
|
|
+ flag = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Map<String, Object> map = new HashMap<>(8);
|
|
|
|
+ int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0;
|
|
|
|
+ map.put("0", a);
|
|
|
|
+ map.put("100", b);
|
|
|
|
+ map.put("200", c);
|
|
|
|
+ map.put("300", d);
|
|
|
|
+ map.put("400", e);
|
|
|
|
+ map.put("500", f);
|
|
|
|
+ map.put("600", g);
|
|
|
|
+ map.put("700", h);
|
|
|
|
+ List<ScoreDataDetails> scoreDataDetails = scoreDataMapper.selectScoreDataByScoreClassId(scoreData.getScoreClassId());
|
|
|
|
+ if (scoreDataDetails != null && scoreDataDetails.size() > 0) {
|
|
|
|
+ //计算各个分数段有多少人
|
|
|
|
+ for (ScoreDataDetails scoreDataDetail : scoreDataDetails) {
|
|
|
|
+ int zongfen = scoreDataDetail.getZongfen();
|
|
|
|
+ if (zongfen >= 0 && zongfen <= 100) {
|
|
|
|
+ a++;
|
|
|
|
+ } else if (zongfen > 100 && zongfen <= 200) {
|
|
|
|
+ b++;
|
|
|
|
+ } else if (zongfen > 200 && zongfen <= 300) {
|
|
|
|
+ c++;
|
|
|
|
+ } else if (zongfen > 300 && zongfen <= 400) {
|
|
|
|
+ d++;
|
|
|
|
+ } else if (zongfen > 400 && zongfen <= 500) {
|
|
|
|
+ e++;
|
|
|
|
+ } else if (zongfen > 500 && zongfen <= 600) {
|
|
|
|
+ f++;
|
|
|
|
+ } else if (zongfen > 600 && zongfen <= 700) {
|
|
|
|
+ g++;
|
|
|
|
+ } else if (zongfen > 700) {
|
|
|
|
+ h++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ map.put("0", a);
|
|
|
|
+ map.put("100", b);
|
|
|
|
+ map.put("200", c);
|
|
|
|
+ map.put("300", d);
|
|
|
|
+ map.put("400", e);
|
|
|
|
+ map.put("500", f);
|
|
|
|
+ map.put("600", g);
|
|
|
|
+ map.put("700", h);
|
|
|
|
+ map.put("scoreId", scoreDataDetails.get(0).getScoreId());
|
|
|
|
+ //把最新数据放到最新缓存key中
|
|
|
|
+ redisCache.setCacheMap(CacheConstants.FEN_DUAN_NEW, map);
|
|
|
|
+ redisCache.setCacheObject(CacheConstants.SCORE_ID + scoreData.getScoreClassId(), scoreDataDetails.get(0).getScoreId());
|
|
|
|
+ if (flag) {
|
|
|
|
+ //放入对比数据
|
|
|
|
+ redisCache.setCacheMap(CacheConstants.FEN_DUAN_LAST, cacheMap);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 后台首页成绩统计分段人数折线图
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Map<String, Object> indexZheXian(ScoreData scoreData) {
|
|
|
|
+ Map<String, Object> map = new HashMap<>(8);
|
|
|
|
+ //分段
|
|
|
|
+ List<String> x = new ArrayList<>();
|
|
|
|
+ //本次
|
|
|
|
+ List<Integer> y1 = new ArrayList<>();
|
|
|
|
+ //上次
|
|
|
|
+ List<Integer> y2 = new ArrayList<>();
|
|
|
|
+ Map<String, Object> cacheMapNew = redisCache.getCacheMap(CacheConstants.FEN_DUAN_NEW);
|
|
|
|
+ Map<String, Object> cacheMapLast = redisCache.getCacheMap(CacheConstants.FEN_DUAN_LAST);
|
|
|
|
+ for (String key : cacheMapNew.keySet()) {
|
|
|
|
+ x.add(key);
|
|
|
|
+ y1.add(Integer.parseInt((String) cacheMapNew.get(key)));
|
|
|
|
+ y2.add(Integer.parseInt((String) cacheMapLast.get(key)));
|
|
|
|
+ }
|
|
|
|
+ map.put("x",x);
|
|
|
|
+ map.put("y1",y1);
|
|
|
|
+ map.put("y2",y2);
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 新增成绩_子信息
|
|
* 新增成绩_子信息
|
|
*
|
|
*
|