修正后端

This commit is contained in:
hh 2024-03-27 16:06:28 +08:00
parent 5a5e9d4acd
commit 6e569bd9e4
5 changed files with 155 additions and 21 deletions

View File

@ -6,14 +6,18 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CacheConstant; 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.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.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
@RestController @RestController
@RequestMapping("/cet") @RequestMapping("/cet")
@ -21,14 +25,33 @@ import javax.annotation.Resource;
public class CenterController { public class CenterController {
@Resource @Resource
private CenterService centerService; private CenterService centerService;
@Autowired
ICet_4Service cet4Service;
@Autowired
ICet_6Service cet6Service;
/** /**
* 统计四级表和六级表中存在得学院和年级 * 统计四级表和六级表中存在年级
*/ */
@GetMapping(value = "/getGradeAndCollege") @GetMapping(value = "/getEntrydate")
@Cacheable(value = "getGradeAndCollege", key = "'getGradeAndCollege'") public Result<JSONObject> getEntrydate() {
public Result<JSONObject> getGradeAndCollege() { return Result.ok(centerService.getEntrydate());
return centerService.getGradeAndCollege(); }
/**
* 统计四级表和六级表中存在的学院
*/
@GetMapping(value = "/getCollege")
public Result<JSONObject> getCollege() {
return Result.ok(centerService.getCollege());
}
/**
* 统计四级表和六级表中存在的批次
*/
@GetMapping(value = "/getBatch")
public Result<JSONObject> getBatch() {
return Result.ok(centerService.getBatch());
} }
/** /**
@ -39,4 +62,37 @@ public class CenterController {
public Result<JSONObject> getData(@RequestParam String college, @RequestParam String entrydate) { public Result<JSONObject> getData(@RequestParam String college, @RequestParam String entrydate) {
return centerService.getData(college,entrydate); return centerService.getData(college,entrydate);
} }
@GetMapping("/getRate/{batch}/{level}")
public Result<JSONObject> getRateByBatch(@PathVariable("batch") Date batch, @PathVariable("level") String level) {
//四六级分开查询
if (level.equals("cet4")) {
Cet_4 cet = new Cet_4();
cet.setBatch(batch);
return cet4Service.getRate(cet);
} else if (level.equals("cet6")) {
Cet_6 cet = new Cet_6();
cet.setBatch(batch);
return cet6Service.getRate(cet);
} else {
return null;
}
}
//根据batch/college是否为空判断两种查询方式
@GetMapping("getRate/{college}/{level}")
public Result<JSONObject> getRateByCollege(@PathVariable("college") String college, @PathVariable("level") String level) {
if (level.equals("cet4")) {
Cet_4 cet = new Cet_4();
cet.setCollege(college);
return cet4Service.getRate(cet);
} else if (level.equals("cet6")) {
Cet_6 cet = new Cet_6();
cet.setCollege(college);
return cet6Service.getRate(cet);
} else {
return null;
}
}
} }

View File

@ -12,3 +12,4 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
public interface Cet_4Mapper extends BaseMapper<Cet_4> { public interface Cet_4Mapper extends BaseMapper<Cet_4> {
} }

View File

@ -10,6 +10,11 @@ import org.jeecg.common.api.vo.Result;
* @Version: V1.0 * @Version: V1.0
*/ */
public interface CenterService { public interface CenterService {
Result<JSONObject> getGradeAndCollege(); JSONObject getEntrydate();
JSONObject getCollege();
JSONObject getBatch();
Result<JSONObject> getData(String college, String entryDate); Result<JSONObject> getData(String college, String entryDate);
} }

View File

@ -17,6 +17,6 @@ import java.util.Date;
* @Version: V1.0 * @Version: V1.0
*/ */
public interface ICet_4Service extends IService<Cet_4> { public interface ICet_4Service extends IService<Cet_4> {
public Result<JSONObject> getRate(Cet_4 cet); Result<JSONObject> getRate(Cet_4 cet);
} }

View File

@ -9,6 +9,8 @@ import org.jeecg.modules.entity.Cet_6;
import org.jeecg.modules.mapper.Cet_4Mapper; import org.jeecg.modules.mapper.Cet_4Mapper;
import org.jeecg.modules.mapper.Cet_6Mapper; import org.jeecg.modules.mapper.Cet_6Mapper;
import org.jeecg.modules.service.CenterService; import org.jeecg.modules.service.CenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -28,8 +30,14 @@ public class CenterServiceImpl implements CenterService {
@Resource @Resource
private Cet_6Mapper cet6Mapper; private Cet_6Mapper cet6Mapper;
@Resource
private RedisTemplate<String, Object> redisTemplate;
/**
* 统计四级表和六级表中存在的年级
*/
@Override @Override
public Result<JSONObject> getGradeAndCollege() { public JSONObject getCollege() {
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
// 收集学院名称 // 收集学院名称
LambdaQueryWrapper<Cet_4> Cet_4CollegeQW = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Cet_4> Cet_4CollegeQW = new LambdaQueryWrapper<>();
@ -44,10 +52,10 @@ public class CenterServiceImpl implements CenterService {
// 收集不重复的学院名称 // 收集不重复的学院名称
Set<String> collegeSet = new HashSet<>(); Set<String> collegeSet = new HashSet<>();
for (Map<String, Object> map : Cet_4College) { for (Map<String, Object> map : Cet_4College) {
collegeSet.add((String) map.get("college")); collegeSet.add(String.valueOf(map.get("college")));
} }
for (Map<String, Object> map : Cet_6College) { for (Map<String, Object> map : Cet_6College) {
collegeSet.add((String) map.get("college")); collegeSet.add(String.valueOf(map.get("college")));
} }
JSONArray colleges = new JSONArray(); JSONArray colleges = new JSONArray();
for (String college : collegeSet) { for (String college : collegeSet) {
@ -57,23 +65,83 @@ public class CenterServiceImpl implements CenterService {
colleges.add(collegeObj); colleges.add(collegeObj);
} }
result.put("colleges", colleges); result.put("colleges", colleges);
// 将数据存入缓存
redisTemplate.opsForValue().set("getBatch", result);
return result;
}
// 收集入学年级 /**
* 统计四级表和六级表中存在的批次
*/
@Override
public JSONObject getBatch() {
// 判断是否存在缓存 getBatch
if (Boolean.TRUE.equals(redisTemplate.hasKey("getBatch"))) {
return (JSONObject) redisTemplate.opsForValue().get("getBatch");
}
JSONObject result = new JSONObject();
// 收集批次
LambdaQueryWrapper<Cet_4> Cet_4BatchQW = new LambdaQueryWrapper<>();
Cet_4BatchQW.select(Cet_4::getBatch)
.groupBy(Cet_4::getBatch);
LambdaQueryWrapper<Cet_6> Cet_6BatchQW = new LambdaQueryWrapper<>();
Cet_6BatchQW.select(Cet_6::getBatch)
.groupBy(Cet_6::getBatch);
List<Map<String, Object>> Cet_4Batch = cet4Mapper.selectMaps(Cet_4BatchQW);
List<Map<String, Object>> Cet_6Batch = cet6Mapper.selectMaps(Cet_6BatchQW);
// 收集不重复的批次
Set<String> batchSet = new HashSet<>();
for (Map<String, Object> map : Cet_4Batch) {
batchSet.add(String.valueOf(map.get("batch")));
}
for (Map<String, Object> map : Cet_6Batch) {
batchSet.add(String.valueOf(map.get("batch")));
}
JSONArray batches = new JSONArray();
for (String batch : batchSet) {
JSONObject batchObj = new JSONObject();
batchObj.put("label", batch);
batchObj.put("value", batch);
batches.add(batchObj);
}
result.put("batches", batches);
// 将数据存入缓存
redisTemplate.opsForValue().set("getBatch", result);
return result;
}
/**
* 统计四级表和六级表中存在的年级
*/
@Override
public JSONObject getEntrydate() {
// 判断是否存在缓存 getEntrydate
if (Boolean.TRUE.equals(redisTemplate.hasKey("getEntrydate"))) {
return (JSONObject) redisTemplate.opsForValue().get("getEntrydate");
}
// 判断是否存在缓存 getEntrydate
if (Boolean.TRUE.equals(redisTemplate.hasKey("getEntrydate"))) {
return (JSONObject) redisTemplate.opsForValue().get("getEntrydate");
}
JSONObject result = new JSONObject();
// 收集年级
LambdaQueryWrapper<Cet_4> Cet_4EntrydateQW = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Cet_4> Cet_4EntrydateQW = new LambdaQueryWrapper<>();
Cet_4EntrydateQW.select(Cet_4::getEntrydate) Cet_4EntrydateQW.select(Cet_4::getEntrydate)
.groupBy(Cet_4::getEntrydate); .groupBy(Cet_4::getEntrydate);
LambdaQueryWrapper<Cet_6> Cet_6EntrydateQW = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Cet_6> Cet_6EntrydateQW = new LambdaQueryWrapper<>();
Cet_6EntrydateQW.select(Cet_6::getEntrydate) Cet_6EntrydateQW.select(Cet_6::getEntrydate)
.groupBy(Cet_6::getEntrydate); .groupBy(Cet_6::getEntrydate);
List<Map<String, Object>> Cet_4Entrydate = cet4Mapper.selectMaps(Cet_4EntrydateQW); List<Map<String, Object>> Cet_4Entrydate = cet4Mapper.selectMaps(Cet_4EntrydateQW);
List<Map<String, Object>> Cet_6Entrydate = cet6Mapper.selectMaps(Cet_6EntrydateQW); List<Map<String, Object>> Cet_6Entrydate = cet6Mapper.selectMaps(Cet_6EntrydateQW);
// 收集不重复的入学年级 // 收集不重复的年级
Set<String> entrydateSet = new HashSet<>(); Set<String> entrydateSet = new HashSet<>();
for (Map<String, Object> map : Cet_4Entrydate) { for (Map<String, Object> map : Cet_4Entrydate) {
entrydateSet.add((String) map.get("entrydate")); entrydateSet.add(String.valueOf(map.get("entrydate")));
} }
for (Map<String, Object> map : Cet_6Entrydate) { for (Map<String, Object> map : Cet_6Entrydate) {
entrydateSet.add((String) map.get("entrydate")); entrydateSet.add(String.valueOf(map.get("entrydate")));
} }
JSONArray entrydates = new JSONArray(); JSONArray entrydates = new JSONArray();
for (String entrydate : entrydateSet) { for (String entrydate : entrydateSet) {
@ -83,7 +151,9 @@ public class CenterServiceImpl implements CenterService {
entrydates.add(entrydateObj); entrydates.add(entrydateObj);
} }
result.put("entrydates", entrydates); result.put("entrydates", entrydates);
return Result.ok(result); // 将数据存入缓存
redisTemplate.opsForValue().set("getEntrydate", result);
return result;
} }
@Override @Override
@ -186,4 +256,6 @@ public class CenterServiceImpl implements CenterService {
result.put("data", ans); result.put("data", ans);
return Result.ok(result); return Result.ok(result);
} }
} }