新增成绩分析页面

This commit is contained in:
Cool 2025-03-28 13:49:08 +08:00
parent d5c7172fed
commit f23a1dd5dd
3 changed files with 70 additions and 11 deletions

View File

@ -176,6 +176,10 @@ public class Cet_4Controller extends JeecgController<Cet_4, ICet_4Service> {
public Result<JSONObject> loadImportDataList() {
return cet_4Service.loadImportDataList();
}
@RequestMapping("analyze")
public Result<JSONObject> analyze(@RequestBody JSONObject webData) {
return cet_4Service.getAnalyze(webData);
}
}

View File

@ -43,4 +43,7 @@ public interface ICet_4Service extends IService<Cet_4> {
Result<JSONObject> loadImportDataList();
List<JSONObject> getJsonObjects(List<Map<String, Object>> list);
Result<JSONObject> getAnalyze(JSONObject webData);
}

View File

@ -3,9 +3,9 @@ package org.jeecg.modules.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.dto.getRateByEntryDateDto;
@ -23,10 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import javax.annotation.Resource;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@ -125,7 +122,7 @@ public class Cet_4ServiceImpl extends ServiceImpl<Cet_4Mapper, Cet_4> implements
queryWrapper.ge(Cet_4::getResult, 425);
List<Cet_4> passedList = cet4Mapper.selectList(queryWrapper);
passedList = passedList.stream().filter(e -> trueEntryDate.contains(e.getEntrydate())).collect(Collectors.toList());
if(college.equals("全校")){
if (college.equals("全校")) {
collect = passedList.stream().collect(Collectors.groupingBy(Cet_4::getCollege));
} else {
collect = passedList.stream()
@ -142,11 +139,11 @@ public class Cet_4ServiceImpl extends ServiceImpl<Cet_4Mapper, Cet_4> implements
String rate = decimalFormat.format(passRateSum);
double res;
try {
res= Double.parseDouble(rate);
res = Double.parseDouble(rate);
}catch (NumberFormatException e){
} catch (NumberFormatException e) {
e.printStackTrace();
res=0;
res = 0;
}
// double res = Double.parseDouble(rate);
@ -187,7 +184,7 @@ public class Cet_4ServiceImpl extends ServiceImpl<Cet_4Mapper, Cet_4> implements
for (Map.Entry<String, Object> stringObjectEntry : list) {
jsonObject.put(stringObjectEntry.getKey(), stringObjectEntry.getValue());
}
JSONObject gradeByBatch = getGradeByBatch(batch,college);
JSONObject gradeByBatch = getGradeByBatch(batch, college);
resultData.put("data", jsonObject);
resultData.put("gradeData", gradeByBatch);
System.out.println(resultData);
@ -662,7 +659,7 @@ public class Cet_4ServiceImpl extends ServiceImpl<Cet_4Mapper, Cet_4> implements
@NotNull
@Override
public List<JSONObject> getJsonObjects(List<Map<String, Object>> list) {
public List<JSONObject> getJsonObjects(List<Map<String, Object>> list) {
List<JSONObject> res = new ArrayList<>();
for (Map<String, Object> map : list) {
JSONObject jsonObject = new JSONObject();
@ -674,6 +671,61 @@ public class Cet_4ServiceImpl extends ServiceImpl<Cet_4Mapper, Cet_4> implements
return res;
}
@Override
public Result<JSONObject> getAnalyze(JSONObject webData) {
String college = webData.getString("college");
String major = webData.getString("major");
//只返回最新批次的数据
QueryWrapper<Cet_4> getMaxBatch = Wrappers.query();
getMaxBatch
.select("MAX(batch) as batch");
Cet_4 maxBatch = getOne(getMaxBatch);
Date batch = maxBatch.getBatch();
LambdaQueryWrapper<Cet_4> queryWrapper = Wrappers.lambdaQuery(Cet_4.class)
.eq(!Objects.equals(college, "全校"),Cet_4::getCollege, college)
.eq(!major.isEmpty(), Cet_4::getMajorname, major)
.eq(Cet_4::getBatch, batch);
List<Cet_4> list = list(queryWrapper);
JSONObject rateByLastBatch = getRateByLastBatch(list);
JSONObject scoreRateByLastBatch = getScoreRateByLastBatch(list);
JSONObject result = new JSONObject();
result.put("rateByBatch", rateByLastBatch);
result.put("scoreByBatch", scoreRateByLastBatch);
return Result.ok(result);
}
//400-425占比
public JSONObject getRateByLastBatch(List<Cet_4> list) {
int total = list.size();
int count = (int) list.stream().filter(e -> e.getResult() >= 400 && e.getResult() < 425).count();
JSONObject jsonObject = new JSONObject();
double rate = count / (double) total;
rate=rate*100;
DecimalFormat df = new DecimalFormat("#.##");
jsonObject.put("rate", df.format(rate));
return jsonObject;
}
//听力阅读等各个模块占比
public JSONObject getScoreRateByLastBatch(List<Cet_4> list) {
int total = list.size();
int listen=0;
int read=0;
int write=0;
//求平均数
for (Cet_4 cet_4 : list) {
listen+=cet_4.getListen();
read+=cet_4.getReading();
write+=cet_4.getWriting();
}
DecimalFormat df = new DecimalFormat("#.##");
JSONObject jsonObject=new JSONObject();
jsonObject.put("listen",df.format(listen/(double)total));
jsonObject.put("read",df.format(read/(double)total));
jsonObject.put("write",df.format(write/(double)total));
return jsonObject;
}
/**
* 依据学生id和姓名获取四级数据
*/