First Commit
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package quant.rich.emoney.pojo.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@Data
|
||||
@Accessors(chain=true)
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
public class EmoneyConvertResult extends R<Object> {
|
||||
|
||||
private Integer protocolId;
|
||||
private String supposedClassName;
|
||||
|
||||
public static EmoneyConvertResult error(String msg) {
|
||||
return (EmoneyConvertResult) new EmoneyConvertResult()
|
||||
.setResultCode(HttpStatus.BAD_REQUEST.value())
|
||||
.setMessage(msg)
|
||||
.setData(null);
|
||||
}
|
||||
|
||||
public static EmoneyConvertResult ok(Serializable result) {
|
||||
return (EmoneyConvertResult) new EmoneyConvertResult()
|
||||
.setResultCode(HttpStatus.OK.value())
|
||||
.setMessage("")
|
||||
.setData(result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package quant.rich.emoney.pojo.dto;
|
||||
|
||||
import java.util.Base64;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain=true)
|
||||
public class EmoneyProtobufBody {
|
||||
|
||||
private Integer protocolId = null;
|
||||
private String protocolBody = null;
|
||||
private String className = null;
|
||||
|
||||
public byte[] protocolBodyToByte() {
|
||||
if (protocolBody == null) {
|
||||
return null;
|
||||
}
|
||||
return Base64.getDecoder().decode(protocolBody);
|
||||
}
|
||||
|
||||
}
|
||||
43
src/main/java/quant/rich/emoney/pojo/dto/LayPageReq.java
Normal file
43
src/main/java/quant/rich/emoney/pojo/dto/LayPageReq.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package quant.rich.emoney.pojo.dto;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 后台管理分页查询,适配 layui
|
||||
* @author Doghole
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
public class LayPageReq<T> extends Page<T> {
|
||||
|
||||
private static final long serialVersionUID = 3471995935637905622L;
|
||||
|
||||
public LayPageReq<T> setPage(Long page) {
|
||||
current = page;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Long getPage() {
|
||||
return current;
|
||||
}
|
||||
|
||||
public LayPageReq<T> setLimit(Long limit) {
|
||||
size = limit;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Long getLimit() {
|
||||
return size;
|
||||
}
|
||||
|
||||
Integer start;
|
||||
|
||||
T condition;
|
||||
}
|
||||
41
src/main/java/quant/rich/emoney/pojo/dto/LayPageResp.java
Normal file
41
src/main/java/quant/rich/emoney/pojo/dto/LayPageResp.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package quant.rich.emoney.pojo.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 后台查询结果,适配 layui
|
||||
* @author Doghole
|
||||
**/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class LayPageResp<T> implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 3706125181722544872L;
|
||||
|
||||
//状态码
|
||||
private int code;
|
||||
|
||||
//提示消息
|
||||
private String msg;
|
||||
|
||||
//总条数
|
||||
private long count;
|
||||
|
||||
//表格数据
|
||||
private List<T> data;
|
||||
|
||||
public LayPageResp() {}
|
||||
|
||||
public LayPageResp(IPage<T> page) {
|
||||
this.data = page.getRecords();
|
||||
this.count = page.getTotal();
|
||||
}
|
||||
}
|
||||
223
src/main/java/quant/rich/emoney/pojo/dto/R.java
Normal file
223
src/main/java/quant/rich/emoney/pojo/dto/R.java
Normal file
@@ -0,0 +1,223 @@
|
||||
package quant.rich.emoney.pojo.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.Accessors;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import quant.rich.emoney.exception.RException;
|
||||
|
||||
/**
|
||||
* application/json 返回
|
||||
* <p>
|
||||
* 此处返回若非提前指定,虽然 resultCode 可以设置对应 HttpStatus, 但 Response 的 HttpStatus 依然会是
|
||||
* 200.<br>
|
||||
* 需要同时指定 HttpStatus 的,见 {@code RException}
|
||||
* </p>
|
||||
*
|
||||
* @see me.qwq.doghouse.exception.RException
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Slf4j
|
||||
public class R<T> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -7658884488696622015L;
|
||||
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
private int resultCode;
|
||||
private String message;
|
||||
private boolean ok;
|
||||
private T data;
|
||||
|
||||
public R() {
|
||||
}
|
||||
|
||||
public R(int resultCode, String message) {
|
||||
this.resultCode = resultCode;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否成功
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isOk() {
|
||||
return HttpStatus.OK.value() == getResultCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* 对当前 R<T> 类型的 T 数据调用 toString(),并将其结果作为生成的 R<String> 的 data, 返回一个相应的
|
||||
* R<String> 对象
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public R<String> toStringifyR() {
|
||||
return new R<String>().setResultCode(resultCode).setMessage(message).setData(data.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回指定状态且 data 为空(类型为 String)的 R
|
||||
*
|
||||
* @param constants
|
||||
* @return
|
||||
*/
|
||||
public static R<String> status(HttpStatus constants) {
|
||||
return new R<String>().setResultCode(constants.value()).setMessage(constants.getReasonPhrase());
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回指定状态和 data 的 R
|
||||
*
|
||||
* @param constants
|
||||
* @return
|
||||
*/
|
||||
public static <T> R<T> status(HttpStatus constants, T data) {
|
||||
return new R<T>().setResultCode(constants.value()).setMessage(constants.getReasonPhrase()).setData(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 HttpStatus.OK 状态和指定的 Data
|
||||
*
|
||||
* @param <T>
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
public static <T> R<T> ok(T data) {
|
||||
return status(HttpStatus.OK, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 HttpStatus.OK
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static R<?> ok() {
|
||||
return new R<>().setResultCode(HttpStatus.OK.value());
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 HttpStatus.UNAUTHORIZED 状态和指定的 Data
|
||||
*
|
||||
* @param <T>
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
public static <T> R<T> unauthorized(T data) {
|
||||
return status(HttpStatus.UNAUTHORIZED, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 HttpStatus.UNAUTHORIZED
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static R<?> unauthorized() {
|
||||
return status(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 HttpStatus.BAD_REQUEST 状态和指定的 Data
|
||||
*
|
||||
* @param <T>
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
public static <T> R<T> badRequest(T data) {
|
||||
return status(HttpStatus.BAD_REQUEST, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 HttpStatus.BAD_REQUEST
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static R<?> badRequest() {
|
||||
return status(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 HttpStatus.INTERNAL_SERVER_ERROR 状态和指定的 Data
|
||||
*
|
||||
* @param <T>
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
public static <T> R<T> internalServerError(T data) {
|
||||
return status(HttpStatus.INTERNAL_SERVER_ERROR, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 HttpStatus.INTERNAL_SERVER_ERROR
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static R<?> internalServerError() {
|
||||
return status(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据布尔值判断返回<br>
|
||||
* true 返回 R.ok()<br>
|
||||
* false throw RException.badRequest()
|
||||
* @param condition
|
||||
* @return
|
||||
*/
|
||||
public static R<?> judge(boolean condition) {
|
||||
if (condition) return R.ok();
|
||||
throw RException.badRequest();
|
||||
}
|
||||
|
||||
|
||||
public static R<?> judgeNonNull(Object obj) {
|
||||
if (obj != null) return R.ok(obj);
|
||||
throw RException.badRequest();
|
||||
}
|
||||
|
||||
|
||||
public static R<?> judge(ThrowingSupplier<?> supplier) {
|
||||
try {
|
||||
return R.ok(supplier.get());
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw RException.badRequest(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static R<?> judgeThrow(ThrowingSupplier<?> supplier) throws Exception {
|
||||
return R.ok(supplier.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据布尔值判断返回<br>
|
||||
* true 返回 R.ok(T okData)<br>
|
||||
* false throw RException.badRequest(failedMessage)
|
||||
* @param condition
|
||||
* @return
|
||||
*/
|
||||
public static <T> R<?> judge(boolean condition, T okData, String failedMessage) {
|
||||
if (condition) return R.ok(okData);
|
||||
throw RException.badRequest(failedMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据布尔值判断返回<br>
|
||||
* true 返回 R.ok(null)<br>
|
||||
* false throw RException.badRequest(failedMessage)
|
||||
* @param condition
|
||||
* @return
|
||||
*/
|
||||
public static R<?> judge(boolean condition, String failedMessage) {
|
||||
return R.judge(condition, null, failedMessage);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public static interface ThrowingSupplier<T> {
|
||||
T get() throws Exception;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package quant.rich.emoney.pojo.dto.valid;
|
||||
|
||||
import org.quartz.CronExpression;
|
||||
|
||||
import jakarta.validation.ConstraintValidator;
|
||||
import jakarta.validation.ConstraintValidatorContext;
|
||||
|
||||
public class CronExpressionValidator implements ConstraintValidator<ValidCron, String> {
|
||||
|
||||
@Override
|
||||
public boolean isValid(String value, ConstraintValidatorContext context) {
|
||||
if (value == null || value.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
return CronExpression.isValidExpression(value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package quant.rich.emoney.pojo.dto.valid;
|
||||
|
||||
import jakarta.validation.ConstraintValidator;
|
||||
import jakarta.validation.ConstraintValidatorContext;
|
||||
import quant.rich.emoney.entity.sqlite.Plan;
|
||||
|
||||
public class PlanValidator implements ConstraintValidator<ValidPlan, Plan> {
|
||||
|
||||
@Override
|
||||
public boolean isValid(Plan value, ConstraintValidatorContext context) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package quant.rich.emoney.pojo.dto.valid;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import jakarta.validation.Constraint;
|
||||
import jakarta.validation.Payload;
|
||||
|
||||
@Documented
|
||||
@Constraint(validatedBy = CronExpressionValidator.class)
|
||||
@Target({ ElementType.FIELD, ElementType.PARAMETER })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ValidCron {
|
||||
|
||||
String message() default "非法的 Cron 表达式";
|
||||
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package quant.rich.emoney.pojo.dto.valid;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import jakarta.validation.Constraint;
|
||||
|
||||
@Documented
|
||||
@Constraint(validatedBy = PlanValidator.class)
|
||||
@Target({ ElementType.TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ValidPlan {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user