优化对比多学院接口
This commit is contained in:
parent
9f24ffb871
commit
2ee73def1c
|
@ -265,7 +265,7 @@ public class Cet_4ServiceImpl extends ServiceImpl<Cet_4Mapper, Cet_4> implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public Result<JSONObject> getRateByCollege(JSONObject webData){
|
||||
public Result<JSONObject> getRateByCollege(JSONObject webData) {
|
||||
|
||||
JSONArray colleges = webData.getJSONArray("college");
|
||||
JSONArray entryDateArray = webData.getJSONArray("entrydate");
|
||||
|
@ -279,43 +279,33 @@ public class Cet_4ServiceImpl extends ServiceImpl<Cet_4Mapper, Cet_4> implements
|
|||
}
|
||||
JSONObject result = new JSONObject();
|
||||
JSONObject oneEntryDate = new JSONObject();
|
||||
//遍历每个年级
|
||||
for (Object entryDate : entryDateArray) {
|
||||
//根据entrydate转换为入学年份之后的八次list
|
||||
List<String> batchList = new ArrayList<>();
|
||||
for (int i = 0; i < batchs.length; i++) {
|
||||
if (batchList.size() >= 8) {
|
||||
break;
|
||||
}
|
||||
String value = batchs[i];
|
||||
//获取入学年份之后的批次
|
||||
if (Integer.parseInt(value.substring(0, 4)) > Integer.parseInt((String) entryDate)) {
|
||||
batchList.add(value);
|
||||
} else if (Integer.parseInt(value.substring(0, 4)) == Integer.parseInt((String) entryDate)) {
|
||||
if (Integer.parseInt(value.substring(5, 7)) > 9) {
|
||||
batchList.add(value);
|
||||
//遍历每个学院
|
||||
for (Object collegeName : colleges) {
|
||||
JSONArray ans = new JSONArray();
|
||||
//遍历每个年级
|
||||
for (Object entryDate : entryDateArray) {
|
||||
//根据entrydate转换为入学年份之后的八次list
|
||||
List<String> batchList = new ArrayList<>();
|
||||
for (String s : batchs) {
|
||||
if (batchList.size() >= 8) {
|
||||
break;
|
||||
}
|
||||
//获取入学年份之后的批次
|
||||
if (Integer.parseInt(s.substring(0, 4)) > Integer.parseInt((String) entryDate)) {
|
||||
batchList.add(s);
|
||||
} else if (Integer.parseInt(s.substring(0, 4)) == Integer.parseInt((String) entryDate)) {
|
||||
if (Integer.parseInt(s.substring(5, 7)) > 9) {
|
||||
batchList.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///学院/专业的全部在籍学生
|
||||
long allStudent = 0;
|
||||
JSONArray ans = new JSONArray();
|
||||
|
||||
//获取所有学院列表
|
||||
LambdaQueryWrapper<Cet_4> collegeQueryWrapper = new LambdaQueryWrapper<>();
|
||||
collegeQueryWrapper.select(Cet_4::getCollege).groupBy(Cet_4::getCollege);
|
||||
List<Object> collegeList = cet4Mapper.selectObjs(collegeQueryWrapper);
|
||||
if (colleges.size() > 1) {
|
||||
collegeList = colleges;
|
||||
}
|
||||
//学院/专业的全部在籍学生
|
||||
long allStudent;
|
||||
//查某个入学年级的所有学院
|
||||
LambdaQueryWrapper<Cet4_major> cet4MajorQW = new LambdaQueryWrapper<>();
|
||||
cet4MajorQW.select(Cet4_major::getCollege).eq(Cet4_major::getEntrydate, entryDate).groupBy(Cet4_major::getCollege);
|
||||
|
||||
//若无该学院则剔除
|
||||
List<Object> collegeSet = cet4_MajorMapper.selectObjs(cet4MajorQW);
|
||||
|
||||
// 在循环开始之前,获取所有学院的在籍学生数量
|
||||
LambdaQueryWrapper<Cet4_major> allStudentQW = new LambdaQueryWrapper<>();
|
||||
allStudentQW.select(Cet4_major::getCollege, Cet4_major::getId).eq(Cet4_major::getState, "在校").eq(Cet4_major::getEntrydate, entryDate);
|
||||
|
@ -327,46 +317,41 @@ public class Cet_4ServiceImpl extends ServiceImpl<Cet_4Mapper, Cet_4> implements
|
|||
allBatchQW.select(Cet_4::getCollege, Cet_4::getId, Cet_4::getResult).eq(Cet_4::getEntrydate, entryDate).in(Cet_4::getBatch, batchList);
|
||||
List<Map<String, Object>> allBatchList = cet4Mapper.selectMaps(allBatchQW);
|
||||
Map<String, List<Map<String, Object>>> allBatchMap = allBatchList.stream().collect(Collectors.groupingBy(map -> (String) map.get("college")));
|
||||
|
||||
//对于每个学院,获取数据
|
||||
for (Object collegeName : collegeList) {
|
||||
if (collegeSet.contains(collegeName)) {
|
||||
//所有参加过四级考试的学生
|
||||
Map<String, Integer> attendMap4 = new HashMap<>();
|
||||
//获取该学院在籍学生数量
|
||||
allStudent = allStudentMap.getOrDefault(collegeName, 0L);
|
||||
JSONObject json = new JSONObject();
|
||||
//一次性获取所有批次的数据
|
||||
List<Map<String, Object>> Cet_4eEntrydate = allBatchMap.get(collegeName);
|
||||
for (Map<String, Object> map : Cet_4eEntrydate) {
|
||||
String str = (String) map.get("id");
|
||||
if ((int) map.get("result") >= 425) {
|
||||
attendMap4.put(str, 1);
|
||||
} else {
|
||||
if (!attendMap4.containsKey(str)) {//排除已经通过的人
|
||||
attendMap4.put(str, 0);
|
||||
}
|
||||
if (collegeSet.contains(collegeName)) {
|
||||
//所有参加过四级考试的学生
|
||||
Map<String, Integer> attendMap4 = new HashMap<>();
|
||||
//获取该学院在籍学生数量
|
||||
allStudent = allStudentMap.getOrDefault(collegeName, 0L);
|
||||
JSONObject json = new JSONObject();
|
||||
//一次性获取所有批次的数据
|
||||
List<Map<String, Object>> Cet_4eEntrydate = allBatchMap.get(collegeName);
|
||||
for (Map<String, Object> map : Cet_4eEntrydate) {
|
||||
String str = (String) map.get("id");
|
||||
if ((int) map.get("result") >= 425) {
|
||||
attendMap4.put(str, 1);
|
||||
} else {
|
||||
if (!attendMap4.containsKey(str)) {//排除已经通过的人
|
||||
attendMap4.put(str, 0);
|
||||
}
|
||||
}
|
||||
//累计通过的人数
|
||||
int passNumber = (int) attendMap4.values().stream().filter(value -> value == 1).count();
|
||||
//每个年级的累计通过率保留三位小数
|
||||
double passRate = passNumber / (double) allStudent;
|
||||
passRate = passRate * 100;
|
||||
//保留三位小数
|
||||
DecimalFormat df = new DecimalFormat("#.#");
|
||||
json.put("college", collegeName);
|
||||
json.put("passRate", df.format(passRate));
|
||||
// System.out.println("学院:" + collegeName + ",累计通过人数:" + passNumber + ",总人数:" + allStudent + ", 通过率" + passRate);
|
||||
ans.add(json);
|
||||
|
||||
}
|
||||
//累计通过的人数
|
||||
int passNumber = (int) attendMap4.values().stream().filter(value -> value == 1).count();
|
||||
//每个年级的累计通过率保留三位小数
|
||||
double passRate = passNumber / (double) allStudent;
|
||||
passRate = passRate * 100;
|
||||
//保留三位小数
|
||||
DecimalFormat df = new DecimalFormat("#.#");
|
||||
json.put("entrydate", entryDate);
|
||||
json.put("passRate", df.format(passRate));
|
||||
// System.out.println("学院:" + collegeName + ",累计通过人数:" + passNumber + ",总人数:" + allStudent + ", 通过率" + passRate);
|
||||
ans.add(json);
|
||||
}
|
||||
oneEntryDate.put((String) entryDate, ans);
|
||||
}
|
||||
oneEntryDate.put((String) collegeName, ans);
|
||||
}
|
||||
result.put("data", oneEntryDate);
|
||||
return Result.ok(result);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue