mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-14 05:42:06 +08:00
system微服务单元测试完善
This commit is contained in:
+3
-3
@@ -6,8 +6,8 @@ package com.cf.imes.module.system.enums.pay;
|
||||
* @author Gqr
|
||||
* @since 2025/8/12 17:49
|
||||
*/
|
||||
public class PayConstants {
|
||||
public static final String PAY_PRODUCT_DETAIL_AUTO_GENERATE_MONTH_ID_FORMAT = "1759029544%d"; // 1~12月定价规则自动生成ID格式
|
||||
public interface PayConstants {
|
||||
String PAY_PRODUCT_DETAIL_AUTO_GENERATE_MONTH_ID_FORMAT = "1759029544%d"; // 1~12月定价规则自动生成ID格式
|
||||
|
||||
public static final String PAY_PRODUCT_DETAIL_AUTO_GENERATE_YEAR_ID_FORMAT = "1759993429%d"; // 1年定价规则自动生成ID格式
|
||||
String PAY_PRODUCT_DETAIL_AUTO_GENERATE_YEAR_ID_FORMAT = "1759993429%d"; // 1年定价规则自动生成ID格式
|
||||
}
|
||||
+1
-10
@@ -13,22 +13,13 @@ import jakarta.validation.ConstraintValidatorContext;
|
||||
*/
|
||||
public class FundsStatisticsUnitInEnumValidator implements ConstraintValidator<FundsStatisticsUnitInEnum, Integer> {
|
||||
|
||||
@Override
|
||||
public void initialize(FundsStatisticsUnitInEnum constraintAnnotation) {
|
||||
ConstraintValidator.super.initialize(constraintAnnotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(Integer value, ConstraintValidatorContext context) {
|
||||
if (ObjectUtil.isNull(value)) {
|
||||
return true;
|
||||
}
|
||||
StatisticsUnit unit = StatisticsUnit.fromValue(value);
|
||||
if (ObjectUtil.isNotNull(unit)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return ObjectUtil.isNotNull(unit);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
package com.cf.imes.module.system.validation.recharge;
|
||||
|
||||
import jakarta.validation.Constraint;
|
||||
import jakarta.validation.Payload;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 自定义Double校验注解
|
||||
*
|
||||
*/
|
||||
@Target({
|
||||
ElementType.METHOD,
|
||||
ElementType.FIELD,
|
||||
ElementType.ANNOTATION_TYPE,
|
||||
ElementType.CONSTRUCTOR,
|
||||
ElementType.PARAMETER,
|
||||
ElementType.TYPE_USE
|
||||
})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Constraint(
|
||||
validatedBy = MoneyValidator.class
|
||||
)
|
||||
public @interface MoneyValid {
|
||||
|
||||
/**
|
||||
* 字段中文名
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String name();
|
||||
|
||||
/**
|
||||
* 校验提示信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String message() default "数字不合法";
|
||||
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
|
||||
/**
|
||||
* 整数最大位数
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int integer() default 7;
|
||||
|
||||
/**
|
||||
* 小数点后的最大位数
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int fraction() default 3;
|
||||
|
||||
}
|
||||
-87
@@ -1,87 +0,0 @@
|
||||
package com.cf.imes.module.system.validation.recharge;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import jakarta.validation.ConstraintValidator;
|
||||
import jakarta.validation.ConstraintValidatorContext;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Double类型校验器
|
||||
*/
|
||||
public class MoneyValidator implements ConstraintValidator<MoneyValid, Number> {
|
||||
|
||||
private static final String ZERO = "0";
|
||||
private static final String GREATER_THAN_ZERO_NOTIFICATION = "%s必须大于0";
|
||||
private static final String LENGTH_ERROR_NOTIFICATION = "%s长度不合法,总长度不超过%d位,小数点后不超过%d位";
|
||||
|
||||
private String name;
|
||||
private int maxIntegerDigits;
|
||||
private int maxFractionDigits;
|
||||
|
||||
@Override
|
||||
public void initialize(MoneyValid constraintAnnotation) {
|
||||
this.name = constraintAnnotation.name();
|
||||
this.maxIntegerDigits = constraintAnnotation.integer();
|
||||
this.maxFractionDigits = constraintAnnotation.fraction();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(Number value, ConstraintValidatorContext context) {
|
||||
if (ObjectUtil.isNull(value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String errorMessage = null;
|
||||
if (value instanceof Integer) {
|
||||
errorMessage = handleInteger((Integer) value);
|
||||
} else if (value instanceof Long) {
|
||||
errorMessage = handleLong((Long) value);
|
||||
} else if (value instanceof Double) {
|
||||
errorMessage = handleDouble((Double) value);
|
||||
} else if (value instanceof BigDecimal) {
|
||||
errorMessage = handleBigDecimal((BigDecimal) value);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotEmpty(errorMessage)) {
|
||||
context.disableDefaultConstraintViolation();
|
||||
context.buildConstraintViolationWithTemplate(errorMessage).addConstraintViolation();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private String handleInteger(Integer value) {
|
||||
if (value <= 0) {
|
||||
return String.format(GREATER_THAN_ZERO_NOTIFICATION, name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String handleLong(Long value) {
|
||||
if (value <= 0) {
|
||||
return String.format(GREATER_THAN_ZERO_NOTIFICATION, name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String handleDouble(Double value) {
|
||||
return handleBigDecimal(new BigDecimal(value.toString()));
|
||||
}
|
||||
|
||||
private String handleBigDecimal(BigDecimal value) {
|
||||
if (value.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
return String.format(GREATER_THAN_ZERO_NOTIFICATION, name);
|
||||
}
|
||||
|
||||
String[] parts = value.toPlainString().split("\\.");
|
||||
int integerPartLength = parts[0].length();
|
||||
int fractionalPartLength = parts.length > 1 ? parts[1].length() : 0;
|
||||
|
||||
if (integerPartLength > maxIntegerDigits || fractionalPartLength > maxFractionDigits) {
|
||||
return String.format(LENGTH_ERROR_NOTIFICATION, name, maxIntegerDigits + maxFractionDigits, maxFractionDigits);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+1
-9
@@ -12,20 +12,12 @@ import jakarta.validation.ConstraintValidatorContext;
|
||||
*/
|
||||
public class TokenConfigAppTypeEnumValidator implements ConstraintValidator<TokenConfigAppTypeEnumValid, Integer> {
|
||||
|
||||
@Override
|
||||
public void initialize(TokenConfigAppTypeEnumValid constraintAnnotation) {
|
||||
ConstraintValidator.super.initialize(constraintAnnotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(Integer value, ConstraintValidatorContext context) {
|
||||
if (ObjectUtil.isNull(value)) {
|
||||
return true;
|
||||
}
|
||||
TokenConfigAppTypeEnum configTypeEnum = TokenConfigAppTypeEnum.fromType(value);
|
||||
if (ObjectUtil.isNotNull(configTypeEnum)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return ObjectUtil.isNotNull(configTypeEnum);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user