First Commit

This commit is contained in:
Administrator
2025-05-12 12:04:42 +08:00
commit 6a5e13974c
1248 changed files with 366157 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
package quant.rich.emoney.interfaces;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
/**
* 将该注解用在配置上,给后台 ConfigController 自动渲染配置页用
*
* @author Doghole
*
*/
@Bean
@Lazy(false)
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface ConfigInfo {
/**
* @return 配置 field 标识,用以自动注入、持久化配置文件名
*/
String field() default "";
/**
* @return 名称
*/
String name() default "配置";
/**
* <p>
* 为 true 时,最终会调用其无参构造方法,若需要填充默认值的,请在无参构造器中填充。
* 当为 true 且无法载入配置文件而触发初始化时,若存在 ./conf/system/{field}.fallback.json 文件时,从 fallback
* 文件中初始化。fallback 仅参与初始化,不参与持久化
* </p>
*
* @return 是否初始化默认值
*/
boolean initDefault() default false;
/**
* @return 是否提供后台控制
*/
boolean managed() default true;
/**
* 是否持久化
*/
boolean save() default true;
}

View File

@@ -0,0 +1,84 @@
package quant.rich.emoney.interfaces;
import java.util.Objects;
import org.springframework.stereotype.Component;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import jakarta.annotation.PostConstruct;
import quant.rich.emoney.service.ConfigService;
import quant.rich.emoney.util.SpringContextHolder;
/**
* 配置项必须实现该接口
*
* @author Doghole
*
*/
@Component
public interface IConfig<T extends IConfig<T>> {
@SuppressWarnings("unchecked")
public default boolean saveOrUpdate() {
return SpringContextHolder.getBean(ConfigService.class).saveOrUpdate((T)this);
}
/**
* 保存前处理。无论 @ConfigInfo 是否设置 save = true 都会调用
*/
@SuppressWarnings("unchecked")
public default T afterSaving() {
return (T) this;
}
/**
* 保存后处理。无论 @ConfigInfo 是否设置 save = true 都会调用
*/
@SuppressWarnings("unchecked")
public default T beforeSaving() {
return (T) this;
}
/**
* 合并到 other且返回合并后的 other
* @return
*/
public default T mergeTo(T other) {
if (!Objects.equals(this, other)) {
BeanUtil.copyProperties(this, other,
CopyOptions.create().setIgnoreNullValue(true));
}
return other;
}
/**
* 合并其他,并返回本身
* @param other
* @return
*/
@SuppressWarnings("unchecked")
public default T mergeFrom(T other) {
if (!Objects.equals(this, other)) {
BeanUtil.copyProperties(other, this,
CopyOptions.create().setIgnoreNullValue(true));
}
return (T) this;
}
/**
* 初始化完成之后的方法,会在
* <code><i>beanFactory</i>.autowireBean(bean)</code>
* 和
* <code><i>beanFactory</i>.initializeBean(bean, beanName)</code>
* 后执行。<br>
* @see quant.rich.emoney.config.ConfigServiceFactoryBean
*/
@PostConstruct
public default void afterBeanInit() {}
public static class Views {
public static class Persistence {}
}
}

View File

@@ -0,0 +1,21 @@
package quant.rich.emoney.interfaces;
import java.lang.annotation.Documented;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;
import quant.rich.emoney.validator.EmoneyRequestConfigValidator;
@Documented
@Constraint(validatedBy = EmoneyRequestConfigValidator.class)
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface ValidEmoneyRequestConfig {
String message() default "非法的 EmoneyRequestConfig";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}