revert 添加按批次对比分析两个接口
This commit is contained in:
YuNan 2024-10-17 14:16:07 +08:00
parent 2bec05f542
commit 9b86eec766
13 changed files with 16 additions and 538 deletions

View File

@ -177,7 +177,7 @@ public class ShiroConfig {
// <!-- 过滤链定义从上向下顺序执行一般将/**放在最为下边 // <!-- 过滤链定义从上向下顺序执行一般将/**放在最为下边
filterChainDefinitionMap.put("/**", "jwt"); filterChainDefinitionMap.put("/**", "jwt");
// 未授权界面返回JSON // 未授权界面返回JSON
shiroFilterFactoryBean.setUnauthorizedUrl("/sys/common/403"); shiroFilterFactoryBean.setUnauthorizedUrl("/sys/common/403");
shiroFilterFactoryBean.setLoginUrl("/sys/common/403"); shiroFilterFactoryBean.setLoginUrl("/sys/common/403");
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);

View File

@ -1,25 +1,17 @@
package org.jeecg.modules.controller; package org.jeecg.modules.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
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.modules.dto.getRateByEntryDate;
import org.jeecg.modules.dto.getRateByMajorAndLastestBatchDto;
import org.jeecg.modules.entity.Cet_6; 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_4Service;
import org.jeecg.modules.service.ICet_6Service; import org.jeecg.modules.service.ICet_6Service;
import org.jeecg.modules.util.WrapMapper;
import org.jeecg.modules.util.Wrapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.Valid;
@RestController @RestController
@RequestMapping("/cet") @RequestMapping("/cet")
@ -34,8 +26,6 @@ public class CenterController {
/** /**
* 统计四级表和六级表中存在的年级 * 统计四级表和六级表中存在的年级
*
* @return {@link Result }<{@link JSONObject }>
*/ */
@GetMapping(value = "/getEntrydate") @GetMapping(value = "/getEntrydate")
public Result<JSONObject> getEntrydate() { public Result<JSONObject> getEntrydate() {
@ -68,11 +58,6 @@ public class CenterController {
/** /**
* 依据学院和年级获取四级和六级通过数据 * 依据学院和年级获取四级和六级通过数据
*
* @param college
* @param major
* @param entrydate
* @return {@link Result }<{@link JSONObject }>
*/ */
@GetMapping(value = "/getData") @GetMapping(value = "/getData")
// @Cacheable(cacheNames = "getData", key = "#college+#major+#entrydate") // @Cacheable(cacheNames = "getData", key = "#college+#major+#entrydate")
@ -83,7 +68,7 @@ public class CenterController {
@PostMapping("/getAllRate") @PostMapping("/getAllRate")
@Cacheable(value = "getAllRate", key = "'getAllRate' + #webData") @Cacheable(value = "getAllRate", key = "'getAllRate' + #webData")
public Result<JSONObject> getAllRate(@RequestBody JSONObject webData) { public Result<JSONObject> getAllRate(@RequestBody JSONObject webData) {
String level = webData.getString("level"); String level= webData.getString("level");
//四六级分开查询 //四六级分开查询
if (level.equals("cet4")) { if (level.equals("cet4")) {
@ -96,19 +81,18 @@ public class CenterController {
return null; return null;
} }
} }
@PostMapping("/getRateByCollege") @PostMapping("/getRateByCollege")
public Result<JSONObject> getRateByCollege(@RequestBody JSONObject webData) { public Result<JSONObject> getRateByCollege(@RequestBody JSONObject webData){
return cet4Service.getRateByCollege(webData); return cet4Service.getRateByCollege(webData);
} }
@GetMapping("/getRateByAllBatch") @GetMapping("/getRateByAllBatch")
// @Cacheable(value = "getRateByAllBatch", key = "'getRateByAllBatch' + #college+#major+#level") // @Cacheable(value = "getRateByAllBatch", key = "'getRateByAllBatch' + #college+#major+#level")
public Result<JSONObject> getRateByAllBatch(@RequestParam("college") String college, @RequestParam("major") String major, @RequestParam("level") String level) { public Result<JSONObject> getRateByAllBatch(@RequestParam("college") String college,@RequestParam("major") String major, @RequestParam("level") String level) {
// System.out.println(college + " " + level); // System.out.println(college + " " + level);
if (level.equals("cet4")) { if (level.equals("cet4")) {
return cet4Service.getRateByAllBatch(college, major); return cet4Service.getRateByAllBatch(college,major);
} else if (level.equals("cet6")) { } else if (level.equals("cet6")) {
Cet_6 cet = new Cet_6(); Cet_6 cet = new Cet_6();
cet.setCollege(college); cet.setCollege(college);
@ -117,48 +101,15 @@ public class CenterController {
return null; return null;
} }
} }
@GetMapping("/getRateByBatch") @GetMapping("/getRateByBatch")
public Result<JSONObject> getRateByBatch(@RequestParam("batch") String batch, @RequestParam("college") String college, @RequestParam("level") String level) { public Result<JSONObject> getRateByBatch(@RequestParam("batch")String batch, @RequestParam("college") String college, @RequestParam("level")String level){
if (level.equals("cet4")) { if (level.equals("cet4")){
return cet4Service.getRateByBatch(college, batch); return cet4Service.getRateByBatch(college,batch);
} else return null; }else return null;
} }
@PostMapping("/getRateByMajor") @PostMapping("/getRateByMajor")
public Result<JSONObject> getRateByMajor(@RequestBody JSONObject webData) { public Result<JSONObject> getRateByMajor(@RequestBody JSONObject webData){
return cet4Service.getRateByMajor(webData); return cet4Service.getRateByMajor(webData);
}
@PostMapping("/getRateByMajorAndLastestBatch")
@ApiOperation(value = "根据专业获取每个年级最新批次的通过率")
public Wrapper getRateByMajorAndLastestBatch(@Valid @RequestBody getRateByMajorAndLastestBatchDto getRateByMajorAndLastestBatchParam, BindingResult bindingResult) {
log.info("根据专业获取最新批次的通过率入参:{}", JSONObject.toJSONString(getRateByMajorAndLastestBatchParam));
try {
if (bindingResult.hasErrors()) {
return WrapMapper.error(bindingResult.getFieldError().getDefaultMessage());
}
return cet4Service.getRateByMajorAndLastestBatch(getRateByMajorAndLastestBatchParam);
} catch (Exception e) {
log.error("调用根据专业获取最新批次的通过率出现错误!" + e.getMessage());
return WrapMapper.error("调用根据专业获取最新批次的通过率出现错误!" + e.getMessage());
}
}
@PostMapping( "/getRateByEntryDate")
@ApiOperation(value = "根据学院/专业的每个年级的通过率")
public Wrapper getRateByEntryDate(@RequestBody getRateByEntryDate getRateByEntryDateParams, BindingResult bindingResult) {
log.info("根据学院/专业的每个年级的通过率: {}", JSONObject.toJSONString(getRateByEntryDateParams));
try {
if(bindingResult.hasErrors()) {
return WrapMapper.error(bindingResult.getFieldError().getDefaultMessage());
}
return cet4Service.getRateByEntryDate(getRateByEntryDateParams);
}catch (Exception e){
log.error("调用根据学院/专业的每个年级的通过率!" + e.getMessage());
return WrapMapper.error("调用根据学院/专业的每个年级的通过率!" + e.getMessage());
}
} }
@GetMapping("/getTest") @GetMapping("/getTest")
public Result<JSONObject> getTest() { public Result<JSONObject> getTest() {

View File

@ -1,11 +1,9 @@
package org.jeecg.modules.mapper; package org.jeecg.modules.mapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.entity.Cet_4; import org.jeecg.modules.entity.Cet_4;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
@ -15,8 +13,5 @@ import java.util.List;
* @Version: V1.0 * @Version: V1.0
*/ */
public interface Cet_4Mapper extends BaseMapper<Cet_4> { public interface Cet_4Mapper extends BaseMapper<Cet_4> {
Date lastestDate();
long selectCountById(LambdaQueryWrapper<Cet_4> cet4Wrapper);
} }

View File

@ -1,10 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.mapper.Cet_4Mapper"> <mapper namespace="org.jeecg.modules.mapper.Cet_4Mapper">
<select id="lastestDate" resultType="java.util.Date">
SELECT MAX(batch) AS latest_batch FROM cet_4;
</select>
<select id="selectCountById" resultType="java.lang.Long">
SELECT DISTINCT id FROM cet_4;
</select>
</mapper> </mapper>

View File

@ -22,5 +22,4 @@ public interface CenterService extends IService<Cet_4> {
Result<JSONObject> getTest(); Result<JSONObject> getTest();
Result<JSONObject> getCollegeMajor(); Result<JSONObject> getCollegeMajor();
} }

View File

@ -3,11 +3,8 @@ package org.jeecg.modules.service;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.dto.getRateByEntryDate;
import org.jeecg.modules.dto.getRateByMajorAndLastestBatchDto;
import org.jeecg.modules.entity.Cet_4; import org.jeecg.modules.entity.Cet_4;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.util.Wrapper;
/** /**
* @Description: cet_4 * @Description: cet_4
@ -28,14 +25,4 @@ public interface ICet_4Service extends IService<Cet_4> {
Result<JSONObject> getDataByStudent(JSONObject jsonObject); Result<JSONObject> getDataByStudent(JSONObject jsonObject);
boolean cleanData(); boolean cleanData();
/**
* @param getRateByMajorAndLastestBatchParam
* @return {@link Wrapper }
*/
Wrapper getRateByMajorAndLastestBatch(getRateByMajorAndLastestBatchDto getRateByMajorAndLastestBatchParam);
Wrapper getRateByEntryDate(getRateByEntryDate getRateByEntryDateParams);
// Wrapper getRateByMajorAndLastestBatch(JSONObject webData);
} }

View File

@ -8,11 +8,13 @@ import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.entity.Cet4_major; import org.jeecg.modules.entity.Cet4_major;
import org.jeecg.modules.entity.Cet_4; import org.jeecg.modules.entity.Cet_4;
import org.jeecg.modules.entity.Cet_4old; import org.jeecg.modules.entity.Cet_4old;
import org.jeecg.modules.entity.Cet_6;
import org.jeecg.modules.mapper.Cet4_majorMapper; import org.jeecg.modules.mapper.Cet4_majorMapper;
import org.jeecg.modules.mapper.Cet_4Mapper; import org.jeecg.modules.mapper.Cet_4Mapper;
import org.jeecg.modules.mapper.Cet_4oldMapper; import org.jeecg.modules.mapper.Cet_4oldMapper;
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.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -112,30 +114,6 @@ public class CenterServiceImpl extends ServiceImpl<Cet_4Mapper, Cet_4> implement
return Result.ok(result); return Result.ok(result);
} }
/**
* 根据学院查对应的专业数据
* @param college
* @return
*/
// @Override
// public Result<JSONObject> getMajorByCollege(String college) {
//
// LambdaQueryWrapper<Cet_4> wrapper = new LambdaQueryWrapper<>();
// //收集某学院下专业数据
// JSONArray majors = new JSONArray();
// wrapper.eq(Cet_4::getCollege,college).groupBy(Cet_4::getMajorname);
// List<Cet_4> list = list(wrapper);
// JSONObject json = new JSONObject();
// json.put("college", college);
// json.put("major", list);
// majors.add(json);
// JSONObject result = new JSONObject();
// result.put("Majors", majors);
// // 将数据存入缓存
// redisTemplate.opsForValue().set("getMajor", result);
// return Result.ok(result);
// }
/** /**
* 统计四级表和六级表中存在的批次 * 统计四级表和六级表中存在的批次
*/ */

View File

@ -7,8 +7,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.dto.getRateByEntryDate;
import org.jeecg.modules.dto.getRateByMajorAndLastestBatchDto;
import org.jeecg.modules.entity.Cet4_major; import org.jeecg.modules.entity.Cet4_major;
import org.jeecg.modules.entity.CetClean; import org.jeecg.modules.entity.CetClean;
import org.jeecg.modules.entity.Cet_4; import org.jeecg.modules.entity.Cet_4;
@ -17,24 +15,19 @@ import org.jeecg.modules.mapper.Cet_4Mapper;
import org.jeecg.modules.service.CenterService; import org.jeecg.modules.service.CenterService;
import org.jeecg.modules.service.CetCleanService; import org.jeecg.modules.service.CetCleanService;
import org.jeecg.modules.service.ICet_4Service; import org.jeecg.modules.service.ICet_4Service;
import org.jeecg.modules.util.Wrapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import javax.annotation.Nullable;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.jeecgframework.poi.excel.entity.enmus.CellValueType.Null;
/** /**
* @Description: cet_4 * @Description: cet_4
* @Author: jeecg-boot * @Author: jeecg-boot
@ -53,6 +46,7 @@ public class Cet_4ServiceImpl extends ServiceImpl<Cet_4Mapper, Cet_4> implements
private Cet4_majorMapper cet4_majorMapper; private Cet4_majorMapper cet4_majorMapper;
@Autowired @Autowired
CetCleanService cetCleanService; CetCleanService cetCleanService;
@Resource @Resource
private RedisTemplate<String, Object> redisTemplate; private RedisTemplate<String, Object> redisTemplate;
@ -559,128 +553,6 @@ public class Cet_4ServiceImpl extends ServiceImpl<Cet_4Mapper, Cet_4> implements
return remove(cet4Wrapper); return remove(cet4Wrapper);
} }
/**
* @param getRateByMajorAndLastestBatchParam
* @return {@link Wrapper }
*/
@Override
public Wrapper getRateByMajorAndLastestBatch(getRateByMajorAndLastestBatchDto getRateByMajorAndLastestBatchParam) {
LambdaQueryWrapper<Cet_4> cet4Wrapper = new LambdaQueryWrapper<>();
Date lastestBatch = cet4Mapper.lastestDate();
cet4Wrapper.eq(Cet_4::getCollege, getRateByMajorAndLastestBatchParam.getCollege());
cet4Wrapper.eq(Cet_4::getBatch, lastestBatch);
if (getRateByMajorAndLastestBatchParam.getMajor() != null && !getRateByMajorAndLastestBatchParam.getMajor().isEmpty()) {
cet4Wrapper.eq(Cet_4::getMajorname, getRateByMajorAndLastestBatchParam.getMajor());
}
long allStudentCount = cet4Mapper.selectCount(cet4Wrapper);
//创建所以年级的list
List<Map<String, Object>> maps = cet4Mapper.selectMaps(cet4Wrapper);
cet4Wrapper.select(Cet_4::getEntrydate).groupBy(Cet_4::getEntrydate);
List<Map<String, Object>> entryDateList = cet4Mapper.selectMaps(cet4Wrapper);
JSONArray ansArray = new JSONArray();
for (Map<String, Object> Date : entryDateList) {
// 统计当前 entryDate 下的通过人数
//所有参加过四级考试的学生
Map<String, Integer> attendMap4 = new HashMap<>();
String currentEntryDate = (String) Date.get("entrydate");
for (Map<String, Object> map : maps) {
String studentEntryDate = (String) map.get("entrydate");
String str = (String) map.get("id");
// 仅处理当前 entryDate 下的学生数据
if (currentEntryDate.equals(studentEntryDate)) {
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) allStudentCount;
// passRate = passRate * 100;
//保留三位小数
DecimalFormat df = new DecimalFormat("#.###");
JSONObject json = new JSONObject();
json.put("entryDate", currentEntryDate);
json.put("passRate", df.format(passRate));
ansArray.add(json);
}
JSONObject result = new JSONObject();
result.put("data", ansArray);
return new Wrapper<>(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, result);
}
@Override
public Wrapper getRateByEntryDate(getRateByEntryDate getRateByEntryDateParams) {
LambdaQueryWrapper<Cet_4> cet4Wrapper = new LambdaQueryWrapper<>();
cet4Wrapper.eq(Cet_4::getCollege, getRateByEntryDateParams.getCollege());
if (getRateByEntryDateParams.getMajor() != null && !getRateByEntryDateParams.getMajor().isEmpty()) {
cet4Wrapper.eq(Cet_4::getMajorname, getRateByEntryDateParams.getMajor());
}
//创建所以年级的list
List<Map<String, Object>> maps = cet4Mapper.selectMaps(cet4Wrapper);
cet4Wrapper.select(Cet_4::getEntrydate).groupBy(Cet_4::getEntrydate);
List<Map<String, Object>> entryDateList = cet4Mapper.selectMaps(cet4Wrapper);
JSONArray ansArray = new JSONArray();
for (Map<String, Object> Date : entryDateList) {
//当前年纪的总人数
LambdaQueryWrapper<Cet_4> cet4StudentCount = new LambdaQueryWrapper<>();
cet4StudentCount.eq(Cet_4::getCollege, getRateByEntryDateParams.getCollege())
.eq(Cet_4::getEntrydate, Date.get("entrydate"));
if (getRateByEntryDateParams.getMajor() != null && !getRateByEntryDateParams.getMajor().isEmpty()) {
cet4StudentCount.eq(Cet_4::getMajorname, getRateByEntryDateParams.getMajor());
}
long allStudentCount = cet4Mapper.selectCount(cet4StudentCount);
// 统计当前 entryDate 下的通过人数
//所有参加过四级考试的学生
Map<String, Integer> attendMap4 = new HashMap<>();
String currentEntryDate = (String) Date.get("entrydate");
for (Map<String, Object> map : maps) {
String studentEntryDate = (String) map.get("entrydate");
String str = (String) map.get("id");
// 仅处理当前 entryDate 下的学生数据
if (currentEntryDate.equals(studentEntryDate)) {
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) allStudentCount;
//百分比
passRate = passRate * 100;
//保留两位小数
DecimalFormat df = new DecimalFormat("#.##");
JSONObject json = new JSONObject();
json.put("entryDate", currentEntryDate);
json.put("passRate", df.format(passRate));
ansArray.add(json);
}
JSONObject result = new JSONObject();
result.put("data", ansArray);
return new Wrapper<>(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, result);
}
/** /**
* 依据学生id和姓名获取四级数据 * 依据学生id和姓名获取四级数据
*/ */

View File

@ -1,140 +0,0 @@
package org.jeecg.modules.util;
import org.apache.commons.lang3.StringUtils;
/**
* 简化和统一创建Wrapper对象
*
* @author Xubx
* @date 2024/10/13
*/
public class WrapMapper {
/**
* Instantiates a new wrap mapper.
*/
private WrapMapper() {
}
/**
* Wrap.
*
* @param <E> the element type
* @param code the code
* @param message the message
* @param o the o
*
* @return the wrapper
*/
public static <E> Wrapper<E> wrap(int code, String message, E o) {
return new Wrapper<>(code, message, o);
}
/**
* Wrap.
*
* @param <E> the element type
* @param code the code
* @param message the message
*
* @return the wrapper
*/
public static <E> Wrapper<E> wrap(int code, String message) {
return wrap(code, message, null);
}
/**
* Wrap.
*
* @param <E> the element type
* @param code the code
*
* @return the wrapper
*/
public static <E> Wrapper<E> wrap(int code) {
return wrap(code, null);
}
/**
* Wrap.
*
* @param <E> the element type
* @param e the e
*
* @return the wrapper
*/
public static <E> Wrapper<E> wrap(Exception e) {
return new Wrapper<>(Wrapper.ERROR_CODE, e.getMessage());
}
/**
* Un wrapper.
*
* @param <E> the element type
* @param wrapper the wrapper
*
* @return the e
*/
public static <E> E unWrap(Wrapper<E> wrapper) {
return wrapper.getResult();
}
/**
* Wrap ERROR. code=100
*
* @param <E> the element type
*
* @return the wrapper
*/
public static <E> Wrapper<E> illegalArgument() {
return wrap(Wrapper.ILLEGAL_ARGUMENT_CODE_, Wrapper.ILLEGAL_ARGUMENT_MESSAGE);
}
/**
* Wrap ERROR. code=500
*
* @param <E> the element type
*
* @return the wrapper
*/
public static <E> Wrapper<E> error() {
return wrap(Wrapper.ERROR_CODE, Wrapper.ERROR_MESSAGE);
}
/**
* Error wrapper.
*
* @param <E> the type parameter
* @param message the message
*
* @return the wrapper
*/
public static <E> Wrapper<E> error(String message) {
return wrap(Wrapper.ERROR_CODE, StringUtils.isBlank(message) ? Wrapper.ERROR_MESSAGE : message);
}
/**
* Wrap SUCCESS. code=200
*
* @param <E> the element type
*
* @return the wrapper
*/
public static <E> Wrapper<E> ok() {
return new Wrapper<>();
}
/**
* Ok wrapper.
*
* @param <E> the type parameter
* @param o the o
*
* @return the wrapper
*/
public static <E> Wrapper<E> ok(E o) {
return new Wrapper<>(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, o);
}
}

View File

@ -1,155 +0,0 @@
package org.jeecg.modules.util;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;
import java.io.Serializable;
/**
* 通用的响应包装器
*
* @author Xubx
* @date 2024/10/13
*/
@Data
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class Wrapper<T> implements Serializable {
/**
* 序列化标识
*/
private static final long serialVersionUID = 4893280118017319089L;
/**
* 成功码.
*/
public static final int SUCCESS_CODE = 200;
/**
* 成功信息.
*/
public static final String SUCCESS_MESSAGE = "操作成功";
/**
* 错误码.
*/
public static final int ERROR_CODE = 500;
/**
* 错误信息.
*/
public static final String ERROR_MESSAGE = "内部异常";
/**
* 错误码参数非法
*/
public static final int ILLEGAL_ARGUMENT_CODE_ = 100;
/**
* 错误信息参数非法
*/
public static final String ILLEGAL_ARGUMENT_MESSAGE = "参数非法";
/**
* 编号.
*/
private int code;
/**
* 信息.
*/
private String message;
/**
* 结果数据
*/
private T result;
/**
* Instantiates a new wrapper. default code=200
*/
Wrapper() {
this(SUCCESS_CODE, SUCCESS_MESSAGE);
}
/**
* Instantiates a new wrapper.
*
* @param code the code
* @param message the message
*/
Wrapper(int code, String message) {
this(code, message, null);
}
/**
* Instantiates a new wrapper.
*
* @param code the code
* @param message the message
* @param result the result
*/
public Wrapper(int code, String message, T result) {
super();
this.code(code).message(message).result(result);
}
/**
* Sets the 编号 , 返回自身的引用.
*
* @param code the new 编号
*
* @return the wrapper
*/
private Wrapper<T> code(int code) {
this.setCode(code);
return this;
}
/**
* Sets the 信息 , 返回自身的引用.
*
* @param message the new 信息
*
* @return the wrapper
*/
private Wrapper<T> message(String message) {
this.setMessage(message);
return this;
}
/**
* Sets the 结果数据 , 返回自身的引用.
*
* @param result the new 结果数据
*
* @return the wrapper
*/
public Wrapper<T> result(T result) {
this.setResult(result);
return this;
}
/**
* 判断是否成功 依据 Wrapper.SUCCESS_CODE == this.code
*
* @return code =200,true;否则 false.
*/
@JsonIgnore
public boolean success() {
return Wrapper.SUCCESS_CODE == this.code;
}
/**
* 判断是否成功 依据 Wrapper.SUCCESS_CODE != this.code
*
* @return code !=200,true;否则 false.
*/
@JsonIgnore
public boolean error() {
return !success();
}
}

View File

@ -21,7 +21,7 @@ public class text {
System.err.println("Cet_4Controller 未正确注入"); System.err.println("Cet_4Controller 未正确注入");
return; return;
} }
// Result<JSONObject> result = cet_4Controller.getDataByStudent(); // Result<JSONObject> result = cet_4Controller.getDataByStudent(2023011559, "余映婵");
// System.out.println(result); System.out.println(result);
} }
} }

View File

@ -7,7 +7,6 @@
<groupId>org.jeecgframework.boot</groupId> <groupId>org.jeecgframework.boot</groupId>
<version>3.6.2</version> <version>3.6.2</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>jeecg-module-system</artifactId> <artifactId>jeecg-module-system</artifactId>

View File

@ -1,12 +1,10 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.jeecgframework.boot</groupId> <groupId>org.jeecgframework.boot</groupId>
<artifactId>jeecg-boot-parent</artifactId> <artifactId>jeecg-boot-parent</artifactId>
<version>3.6.2</version> <version>3.6.2</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>JEECG BOOT ${project.version}</name> <name>JEECG BOOT ${project.version}</name>
<developers> <developers>