提供查询接口(批次/学院)

This commit is contained in:
Cool 2024-03-27 15:06:45 +08:00
parent 700cdddf4a
commit 4d3aed9965
5 changed files with 193 additions and 5 deletions

View File

@ -1,18 +1,23 @@
package org.jeecg.modules.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CacheConstant;
import org.jeecg.modules.entity.Cet_4;
import org.jeecg.modules.entity.Cet_6;
import org.jeecg.modules.service.CenterService;
import org.jeecg.modules.service.ICet_4Service;
import org.jeecg.modules.service.ICet_6Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Date;
@RestController
@RequestMapping("/cet")
@ -20,6 +25,10 @@ import javax.annotation.Resource;
public class CenterController {
@Resource
private CenterService centerService;
@Autowired
ICet_4Service cet4Service;
@Autowired
ICet_6Service cet6Service;
/**
* 统计四级表和六级表中存在得学院和年级
@ -29,4 +38,40 @@ public class CenterController {
public Result<JSONObject> getGradeAndCollege() {
return centerService.getGradeAndCollege();
}
@PostMapping("getRate/{batch}/{level}")
public Result<JSONObject> getRateByBatch(@PathVariable("batch") Date batch, @PathVariable("level") String level) {
//四六级分开查询
if (level.equals("英语四级")) {
Cet_4 cet = new Cet_4();
cet.setBatch(batch);
return cet4Service.getRate(cet);
} else if (level.equals("英语六级")) {
Cet_6 cet = new Cet_6();
cet.setBatch(batch);
return cet6Service.getRate(cet);
} else {
return null;
}
}
//根据batch/college是否为空判断两种查询方式
@PostMapping("getRate/{college}/{level}")
public Result<JSONObject> getRateByCollege(@PathVariable("college") String college, @PathVariable("level") String level) {
if (level.equals("英语四级")) {
Cet_4 cet = new Cet_4();
cet.setCollege(college);
return cet4Service.getRate(cet);
} else if (level.equals("英语六级")) {
Cet_6 cet = new Cet_6();
cet.setCollege(college);
return cet6Service.getRate(cet);
} else {
return null;
}
}
}

View File

@ -1,7 +1,14 @@
package org.jeecg.modules.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.entity.Cet_4;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.entity.Cet_6;
import java.util.Date;
/**
* @Description: cet_4
@ -10,5 +17,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
* @Version: V1.0
*/
public interface ICet_4Service extends IService<Cet_4> {
public Result<JSONObject> getRate(Cet_4 cet);
}

View File

@ -1,8 +1,14 @@
package org.jeecg.modules.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.entity.Cet_6;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.Date;
/**
* @Description: cet_6
* @Author: jeecg-boot
@ -10,5 +16,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
* @Version: V1.0
*/
public interface ICet_6Service extends IService<Cet_6> {
public Result<JSONObject> getRate(Cet_6 data);
}

View File

@ -1,19 +1,84 @@
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 org.jeecg.common.api.vo.Result;
import org.jeecg.modules.entity.Cet_4;
import org.jeecg.modules.mapper.Cet_4Mapper;
import org.jeecg.modules.service.ICet_4Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @Description: cet_4
* @Author: jeecg-boot
* @Date: 2024-03-26
* @Date: 2024-03-26
* @Version: V1.0
*/
@Service
public class Cet_4ServiceImpl extends ServiceImpl<Cet_4Mapper, Cet_4> implements ICet_4Service {
@Autowired
Cet_4Mapper cet4Mapper;
public Result<JSONObject> getRate(Cet_4 cet) {
JSONObject jsonObject = new JSONObject();
//select count(*) from cet_4 where college ='?' and result>=425
LambdaQueryWrapper<Cet_4> queryWrapper = new LambdaQueryWrapper<>();
//构造查询条件
if (cet.getBatch() == null) {
//根据学院查人数
queryWrapper.eq(Cet_4::getCollege, cet.getCollege()).ge(Cet_4::getResult, 425);
List<Cet_4> result = cet4Mapper.selectList(queryWrapper);
Map<String, List<Cet_4>> collect = result.stream().collect(Collectors.groupingBy(Cet_4::getCollege));
for (Map.Entry<String, List<Cet_4>> entry : collect.entrySet()) {
double sum = (double) getNum(cet);
double size = entry.getValue().size();
double passRate = sum / size;
jsonObject.put(String.valueOf(entry.getKey()),
passRate);
}
return Result.OK(jsonObject);
} else if (cet.getCollege() == null) {
//根据批次查人数
queryWrapper.eq(Cet_4::getBatch, cet.getBatch()).ge(Cet_4::getResult, 425);
List<Cet_4> result = cet4Mapper.selectList(queryWrapper);
Map<Date, List<Cet_4>> collect = result.stream().collect(Collectors.groupingBy(Cet_4::getBatch));
for (Map.Entry<Date, List<Cet_4>> entry : collect.entrySet()) {
double sum = (double) getNum(cet);
double size = entry.getValue().size();
double passRate = sum / size;
jsonObject.put(String.valueOf(entry.getKey()),
passRate);
}
return Result.OK(jsonObject);
}
else return null;
}
private long getNum(Cet_4 cet) {
LambdaQueryWrapper<Cet_4> queryWrapper = new LambdaQueryWrapper<>();
if (cet.getCollege() == null) {
queryWrapper.eq(Cet_4::getBatch, cet.getBatch());
}
if (cet.getBatch() == null) {
queryWrapper.eq(Cet_4::getCollege, cet.getCollege());
}
return cet4Mapper.selectCount(queryWrapper);
}
}

View File

@ -1,5 +1,10 @@
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 org.jeecg.common.api.vo.Result;
import org.jeecg.modules.entity.Cet_6;
import org.jeecg.modules.mapper.Cet_6Mapper;
import org.jeecg.modules.service.ICet_6Service;
@ -7,6 +12,12 @@ import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @Description: cet_6
* @Author: jeecg-boot
@ -15,5 +26,58 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
*/
@Service
public class Cet_6ServiceImpl extends ServiceImpl<Cet_6Mapper, Cet_6> implements ICet_6Service {
@Resource
Cet_6Mapper cet6Mapper;
@Override
public Result<JSONObject> getRate(Cet_6 cet) {
JSONObject jsonObject = new JSONObject();
//select count(*) from cet_6 where college ='?' and result>=425
LambdaQueryWrapper<Cet_6> queryWrapper = new LambdaQueryWrapper<>();
//构造查询条件
if (cet.getBatch() == null) {
//根据学院查人数
queryWrapper.eq(Cet_6::getCollege, cet.getCollege()).ge(Cet_6::getResult, 425);
List<Cet_6> result = cet6Mapper.selectList(queryWrapper);
Map<String, List<Cet_6>> collect = result.stream().collect(Collectors.groupingBy(Cet_6::getCollege));
for (Map.Entry<String, List<Cet_6>> entry : collect.entrySet()) {
double sum = (double) getNum(cet);
double size = entry.getValue().size();
double passRate = sum / size;
jsonObject.put(String.valueOf(entry.getKey()),
passRate);
}
return Result.OK(jsonObject);
} else if (cet.getCollege() == null) {
//根据批次查人数
queryWrapper.eq(Cet_6::getBatch, cet.getBatch()).ge(Cet_6::getResult, 425);
List<Cet_6> result = cet6Mapper.selectList(queryWrapper);
Map<Date, List<Cet_6>> collect = result.stream().collect(Collectors.groupingBy(Cet_6::getBatch));
for (Map.Entry<Date, List<Cet_6>> entry : collect.entrySet()) {
double sum = (double) getNum(cet);
double size = entry.getValue().size();
double passRate = sum / size;
jsonObject.put(String.valueOf(entry.getKey()),
passRate);
}
return Result.OK(jsonObject);
}
else return null;
}
private long getNum(Cet_6 cet) {
LambdaQueryWrapper<Cet_6> queryWrapper = new LambdaQueryWrapper<>();
if (cet.getCollege() == null) {
queryWrapper.eq(Cet_6::getBatch, cet.getBatch());
}
if (cet.getBatch() == null) {
queryWrapper.eq(Cet_6::getCollege, cet.getCollege());
}
return cet6Mapper.selectCount(queryWrapper);
}
}