CodeMsg类
package cma.sxqxgxw.utils.result;
public class CodeMsg {
private int code;
private String msg;
//通用的错误码
public static CodeMsg SUCCESS = new CodeMsg(0, "success");
public static CodeMsg TOKEN_EXPIRED = new CodeMsg(400, "token过期");
public static CodeMsg TOKEN_INVALID = new CodeMsg(401, "token解析异常");
public static CodeMsg USER_NOT_LOGGED_IN = new CodeMsg(402, "未登录,请登录!");
public static CodeMsg SIGNATURE_ERROR = new CodeMsg(506, "签名失败");
public static CodeMsg SERVER_ERROR = new CodeMsg(500, "服务端异常");
public static CodeMsg FILE_ERROR = new CodeMsg(501, "文件不存在");
public static CodeMsg FILE_EXIST = new CodeMsg(5012, "文件已存在");
public static CodeMsg TIME_ERROR = new CodeMsg(502, "时间格式错误,应为 yyyy-MM-dd HH:mm:ss");
public static CodeMsg TIMEMISS_ERROR = new CodeMsg(503, "查询时间缺失,应为 yyyy-MM-dd HH:mm:ss");
public static CodeMsg BIND_ERROR = new CodeMsg(504, "参数绑定异常");
public static CodeMsg CONTROL_ERROR = new CodeMsg(505, "请检查参数是否缺失,输入是否正确");
public static CodeMsg BINDING_FAILED = new CodeMsg(506, "绑定失败");
public static CodeMsg UNBIND_FAILED = new CodeMsg(507, "解绑失败");
// user: 1000 - 1100
public static CodeMsg USER_PWD_ERROR = new CodeMsg(1001,"密码错误,请重新输入!");
public static CodeMsg USER_NAME_ERROR = new CodeMsg(1002,"用户名不存在,请注册!");
public static CodeMsg USER_NAME_EXIST_ERROR = new CodeMsg(1003, "用户名已存在");
public static CodeMsg USER_PWD_FORMAT_ERROR = new CodeMsg(1004, "密码是由8至16位的数字和字母组成,请重新输入");
// apply order: 1100 - 1200
public static CodeMsg ORDER_NOT_EXIST = new CodeMsg(1101,"非本人申请单或申请单不存在!");
public static CodeMsg ORDER_CANCELED = new CodeMsg(1102,"申请单已被撤销!");
public static CodeMsg ORDER_REJECTED = new CodeMsg(1103, "申请已被驳回!");
public static CodeMsg ORDER_AUDITED = new CodeMsg(1104, "申请单已被审核!");
public static CodeMsg ORDER_ACCEPTED_CAN_NOT_CANCELED = new CodeMsg(1105, "申请单已被处理,不能撤销!");
public static CodeMsg ORDER_NOT_AUDITED = new CodeMsg(1106, "当前申请单未被审核通过!");
public static CodeMsg ORDER_TIME_FORMAT = new CodeMsg(1107, "时间范围输入错误,正确格式为[yyyyMMddHHmmss,yyyyMMddHHmmss]");
public static CodeMsg ORDER_AUDITRESULT = new CodeMsg(1108, "请输入正确的auditResult!");
public static CodeMsg ORDER_AUDITED_FAILED = new CodeMsg(1109, "审核失败!");
public static CodeMsg ORDER_SELECTED_FAILED = new CodeMsg(1110, "查询失败!");
public static CodeMsg ORDER_CANCELED_FAILED = new CodeMsg(1111, "撤销失败!");
public static CodeMsg ORDER_UPLOAD_FAILED = new CodeMsg(1112, "上传附件失败!");
private CodeMsg() {
}
public CodeMsg(int code, String msg) {
this.code = code;
this.msg = msg;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
/**
* 返回带参数的错误码
* @param args
* @return
*/
public CodeMsg fillArgs(Object... args) {
int code = this.code;
String message = String.format(this.msg, args);
return new CodeMsg(code, message);
}
@Override
public String toString() {
return "CodeMsg [code=" + code + ", msg=" + msg + "]";
}
}
server类
@Override
public Result<Object> getAllApplyOrdersByTimeRange(String timeRange, Integer page, Integer pageSize) {
String dateString = timeRange.substring(1, timeRange.length() - 1); // 去掉中括号
String[] dateArray = dateString.split(",");
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
Date startDate;
Date endDate;
try {
startDate = format.parse(dateArray[0]);
endDate = format.parse(dateArray[1]);
} catch (ParseException e) {
return Result.error(CodeMsg.ORDER_TIME_FORMAT);
}
//admin
LambdaQueryWrapper<ApplyOrderDO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.lt(ApplyOrderDO::getCreateTime, endDate);
queryWrapper.gt(ApplyOrderDO::getCreateTime, startDate);
queryWrapper.orderByDesc(ApplyOrderDO::getCreateTime);
int pageInt = page != null && page > 0 ? page : 1;
int pageSizeInt = pageSize != null && pageSize > 0 ? pageSize : 10;
Page<ApplyOrderDO> pageDo = new Page<>(pageInt, pageSizeInt);
Page<ApplyOrderDO> applyOrderDOPage = applyOrderMapper.selectPage(pageDo, queryWrapper);
// DO 转 VO (Page对象)
Page<ApplyOrderVO> applyOrderVOPage = ApplyOrderMapper.INSTANCE.toVOPage(applyOrderDOPage);
return Result.success(applyOrderVOPage);
}