|
@@ -1,5 +1,6 @@
|
|
package com.ruoyi.system.service.impl.score;
|
|
package com.ruoyi.system.service.impl.score;
|
|
|
|
|
|
|
|
+import java.text.DecimalFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
import com.ruoyi.common.constant.CacheConstants;
|
|
import com.ruoyi.common.constant.CacheConstants;
|
|
@@ -15,6 +16,7 @@ import com.ruoyi.system.mapper.FormalParentsStudentMapper;
|
|
import com.ruoyi.system.mapper.FormalTeacherClassMapper;
|
|
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.apache.commons.lang3.ObjectUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -23,6 +25,7 @@ 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.constant.CacheConstants.*;
|
|
import static com.ruoyi.common.utils.PageUtils.startPage;
|
|
import static com.ruoyi.common.utils.PageUtils.startPage;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -46,11 +49,29 @@ public class ScoreDataServiceImpl implements IScoreDataService {
|
|
/**
|
|
/**
|
|
* 查询成绩
|
|
* 查询成绩
|
|
*
|
|
*
|
|
- * @param scoreId 成绩主键
|
|
|
|
|
|
+ * @param scoreData 成绩主键
|
|
* @return 成绩
|
|
* @return 成绩
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public ScoreData selectScoreDataByScoreId(Long scoreId) {
|
|
|
|
|
|
+ public ScoreData selectScoreDataByScoreId(ScoreData scoreData) {
|
|
|
|
+ Long scoreId = scoreData.getScoreId();
|
|
|
|
+ Map<String, Object> params = scoreData.getParams();
|
|
|
|
+ String role = "admin";
|
|
|
|
+ if (params != null && params.size() > 0) {
|
|
|
|
+ role = (String) params.get("role");
|
|
|
|
+ }
|
|
|
|
+ if ("parents".equals(role)) {
|
|
|
|
+ Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
|
+ //如果是家长要记录到redis中
|
|
|
|
+ redisCache.setCacheObject(SCORE_PEOPLE_CHAKAN + scoreId+":"+userId, userId);
|
|
|
|
+ //获取查看人数
|
|
|
|
+ String chaKanCount = redisCache.getCacheObject(SCORE_PEOPLE_CHAKAN_COUNT + scoreId);
|
|
|
|
+ if (ObjectUtils.isEmpty(chaKanCount)){
|
|
|
|
+ redisCache.setCacheObject(SCORE_PEOPLE_CHAKAN_COUNT + scoreId,1);
|
|
|
|
+ }else {
|
|
|
|
+ redisCache.setCacheObject(SCORE_PEOPLE_CHAKAN_COUNT + scoreId,Integer.parseInt(chaKanCount)+1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return scoreDataMapper.selectScoreDataByScoreId(scoreId);
|
|
return scoreDataMapper.selectScoreDataByScoreId(scoreId);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -102,6 +123,33 @@ public class ScoreDataServiceImpl implements IScoreDataService {
|
|
startPage();
|
|
startPage();
|
|
scoreDataList = scoreDataMapper.selectScoreDataList(scoreData);
|
|
scoreDataList = scoreDataMapper.selectScoreDataList(scoreData);
|
|
}
|
|
}
|
|
|
|
+ //赋值查看率
|
|
|
|
+ if (scoreDataList != null && scoreDataList.size() > 0) {
|
|
|
|
+ DecimalFormat df = new DecimalFormat("##.0%");
|
|
|
|
+ String percent = "0.00%";
|
|
|
|
+ for (ScoreData data : scoreDataList) {
|
|
|
|
+ //全部人数
|
|
|
|
+ double chaKanAll = 0D;
|
|
|
|
+ double chaKanCount = 0D;
|
|
|
|
+ if (ObjectUtils.isNotEmpty(redisCache.getCacheObject(SCORE_PEOPLE_ALL + data.getScoreId()))&&ObjectUtils.isNotEmpty(redisCache.getCacheObject(SCORE_PEOPLE_ALL + data.getScoreId()))){
|
|
|
|
+ chaKanAll = redisCache.getCacheObject(SCORE_PEOPLE_ALL + data.getScoreId());
|
|
|
|
+ //已查看
|
|
|
|
+ chaKanCount = redisCache.getCacheObject(SCORE_PEOPLE_CHAKAN_COUNT + data.getScoreId());
|
|
|
|
+ }
|
|
|
|
+ double weiChaKan = chaKanAll;
|
|
|
|
+ if (chaKanAll > 0 && chaKanCount >= 0){
|
|
|
|
+ weiChaKan = chaKanAll - chaKanCount;
|
|
|
|
+ }
|
|
|
|
+ double z = chaKanCount / chaKanAll;
|
|
|
|
+ //计算百分比
|
|
|
|
+ if(Math.abs(z)>=0.1){
|
|
|
|
+ percent = df.format(z);
|
|
|
|
+ }
|
|
|
|
+ data.setChaKan(chaKanCount);
|
|
|
|
+ data.setWeiChaKan(weiChaKan);
|
|
|
|
+ data.setPercentage(percent);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return scoreDataList;
|
|
return scoreDataList;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -124,6 +172,11 @@ public class ScoreDataServiceImpl implements IScoreDataService {
|
|
}
|
|
}
|
|
insertScoreDataDetails(scoreData);
|
|
insertScoreDataDetails(scoreData);
|
|
}
|
|
}
|
|
|
|
+ Long scoreId = scoreData.getScoreId();
|
|
|
|
+ //新增成绩的时候,往redis中放入该次考试总人数
|
|
|
|
+ int count = scoreDataMapper.selectDetailsCountByScoreId(scoreId);
|
|
|
|
+ redisCache.setCacheObject(SCORE_PEOPLE_ALL + scoreId, count);
|
|
|
|
+ redisCache.setCacheObject(SCORE_PEOPLE_CHAKAN_COUNT + scoreId,0);
|
|
return rows;
|
|
return rows;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -187,7 +240,7 @@ public class ScoreDataServiceImpl implements IScoreDataService {
|
|
@Override
|
|
@Override
|
|
public Map<String, Object> indexBingTu(ScoreData scoreData) {
|
|
public Map<String, Object> indexBingTu(ScoreData scoreData) {
|
|
//获取缓存的数据
|
|
//获取缓存的数据
|
|
- Map<String, Object> cacheMap = redisCache.getCacheMap(CacheConstants.FEN_DUAN_NEW);
|
|
|
|
|
|
+ Map<String, Object> cacheMap = redisCache.getCacheMap(CacheConstants.FEN_DUAN_NEW + scoreData.getScoreClassId());
|
|
//获取班级id对应的最新考试id
|
|
//获取班级id对应的最新考试id
|
|
Long scoreDataId = (Long) redisCache.getCacheObject(CacheConstants.SCORE_ID + scoreData.getScoreClassId());
|
|
Long scoreDataId = (Long) redisCache.getCacheObject(CacheConstants.SCORE_ID + scoreData.getScoreClassId());
|
|
boolean flag = false;
|
|
boolean flag = false;
|
|
@@ -195,7 +248,7 @@ public class ScoreDataServiceImpl implements IScoreDataService {
|
|
//获取redis缓存的考试id
|
|
//获取redis缓存的考试id
|
|
Long scoreId = (Long) cacheMap.get("scoreId");
|
|
Long scoreId = (Long) cacheMap.get("scoreId");
|
|
//判断最新一次考试id和缓存id是否匹配
|
|
//判断最新一次考试id和缓存id是否匹配
|
|
- if (scoreDataId.equals(scoreId)) {
|
|
|
|
|
|
+ if (scoreDataId != null && scoreDataId.equals(scoreId)) {
|
|
//说明缓存就是最新的
|
|
//说明缓存就是最新的
|
|
return cacheMap;
|
|
return cacheMap;
|
|
} else {
|
|
} else {
|
|
@@ -205,19 +258,22 @@ public class ScoreDataServiceImpl implements IScoreDataService {
|
|
}
|
|
}
|
|
Map<String, Object> map = new HashMap<>(8);
|
|
Map<String, Object> map = new HashMap<>(8);
|
|
int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0;
|
|
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);
|
|
|
|
|
|
+ map.put("One", a);
|
|
|
|
+ map.put("Tow", b);
|
|
|
|
+ map.put("Thr", c);
|
|
|
|
+ map.put("For", d);
|
|
|
|
+ map.put("Fiv", e);
|
|
|
|
+ map.put("Six", f);
|
|
|
|
+ map.put("Sev", g);
|
|
|
|
+ map.put("Eig", h);
|
|
List<ScoreDataDetails> scoreDataDetails = scoreDataMapper.selectScoreDataByScoreClassId(scoreData.getScoreClassId());
|
|
List<ScoreDataDetails> scoreDataDetails = scoreDataMapper.selectScoreDataByScoreClassId(scoreData.getScoreClassId());
|
|
if (scoreDataDetails != null && scoreDataDetails.size() > 0) {
|
|
if (scoreDataDetails != null && scoreDataDetails.size() > 0) {
|
|
|
|
+ int zongfen = 0;
|
|
//计算各个分数段有多少人
|
|
//计算各个分数段有多少人
|
|
for (ScoreDataDetails scoreDataDetail : scoreDataDetails) {
|
|
for (ScoreDataDetails scoreDataDetail : scoreDataDetails) {
|
|
- int zongfen = scoreDataDetail.getZongfen();
|
|
|
|
|
|
+ if (scoreDataDetail.getZongfen() != null) {
|
|
|
|
+ zongfen = scoreDataDetail.getZongfen();
|
|
|
|
+ }
|
|
if (zongfen >= 0 && zongfen <= 100) {
|
|
if (zongfen >= 0 && zongfen <= 100) {
|
|
a++;
|
|
a++;
|
|
} else if (zongfen > 100 && zongfen <= 200) {
|
|
} else if (zongfen > 100 && zongfen <= 200) {
|
|
@@ -236,21 +292,21 @@ public class ScoreDataServiceImpl implements IScoreDataService {
|
|
h++;
|
|
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("One", a);
|
|
|
|
+ map.put("Tow", b);
|
|
|
|
+ map.put("Thr", c);
|
|
|
|
+ map.put("For", d);
|
|
|
|
+ map.put("Fiv", e);
|
|
|
|
+ map.put("Six", f);
|
|
|
|
+ map.put("Sev", g);
|
|
|
|
+ map.put("Eig", h);
|
|
map.put("scoreId", scoreDataDetails.get(0).getScoreId());
|
|
map.put("scoreId", scoreDataDetails.get(0).getScoreId());
|
|
//把最新数据放到最新缓存key中
|
|
//把最新数据放到最新缓存key中
|
|
- redisCache.setCacheMap(CacheConstants.FEN_DUAN_NEW, map);
|
|
|
|
|
|
+ redisCache.setCacheMap(CacheConstants.FEN_DUAN_NEW + scoreData.getScoreClassId(), map);
|
|
redisCache.setCacheObject(CacheConstants.SCORE_ID + scoreData.getScoreClassId(), scoreDataDetails.get(0).getScoreId());
|
|
redisCache.setCacheObject(CacheConstants.SCORE_ID + scoreData.getScoreClassId(), scoreDataDetails.get(0).getScoreId());
|
|
if (flag) {
|
|
if (flag) {
|
|
//放入对比数据
|
|
//放入对比数据
|
|
- redisCache.setCacheMap(CacheConstants.FEN_DUAN_LAST, cacheMap);
|
|
|
|
|
|
+ redisCache.setCacheMap(CacheConstants.FEN_DUAN_LAST + scoreData.getScoreClassId(), cacheMap);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return map;
|
|
return map;
|
|
@@ -265,20 +321,41 @@ public class ScoreDataServiceImpl implements IScoreDataService {
|
|
Map<String, Object> map = new HashMap<>(8);
|
|
Map<String, Object> map = new HashMap<>(8);
|
|
//分段
|
|
//分段
|
|
List<String> x = new ArrayList<>();
|
|
List<String> x = new ArrayList<>();
|
|
|
|
+ x.add("One");
|
|
|
|
+ x.add("Tow");
|
|
|
|
+ x.add("Thr");
|
|
|
|
+ x.add("For");
|
|
|
|
+ x.add("Fiv");
|
|
|
|
+ x.add("Six");
|
|
|
|
+ x.add("Sev");
|
|
|
|
+ x.add("Eig");
|
|
//本次
|
|
//本次
|
|
- List<Integer> y1 = new ArrayList<>();
|
|
|
|
|
|
+ List<Object> 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)));
|
|
|
|
|
|
+ List<Object> y2 = new ArrayList<>();
|
|
|
|
+ Map<String, Object> cacheMapNew = redisCache.getCacheMap(CacheConstants.FEN_DUAN_NEW + scoreData.getScoreClassId());
|
|
|
|
+ Map<String, Object> cacheMapLast = redisCache.getCacheMap(CacheConstants.FEN_DUAN_LAST + scoreData.getScoreClassId());
|
|
|
|
+ if (cacheMapNew != null && cacheMapNew.size() > 0) {
|
|
|
|
+ for (String key : cacheMapNew.keySet()) {
|
|
|
|
+ if (!"scoreId".equals(key)) {
|
|
|
|
+ y1.add(cacheMapNew.get(key));
|
|
|
|
+ if (cacheMapLast.get(key) != null) {
|
|
|
|
+ y2.add(cacheMapLast.get(key));
|
|
|
|
+ } else {
|
|
|
|
+ y2.add(0);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ for (int i = 0; i < 8; i++) {
|
|
|
|
+ y1.add(0);
|
|
|
|
+ y2.add(0);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- map.put("x",x);
|
|
|
|
- map.put("y1",y1);
|
|
|
|
- map.put("y2",y2);
|
|
|
|
|
|
+
|
|
|
|
+ map.put("x", x);
|
|
|
|
+ map.put("y1", y1);
|
|
|
|
+ map.put("y2", y2);
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
|