修复 RandomUtils 产生的 LocalDateTime 入库后精度缺失问题

This commit is contained in:
YunaiV 2023-07-25 20:48:20 +08:00
parent c906a616f8
commit 85d55d1af5

View File

@ -7,10 +7,7 @@ import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import uk.co.jemos.podam.api.PodamFactory; import uk.co.jemos.podam.api.PodamFactory;
import uk.co.jemos.podam.api.PodamFactoryImpl; import uk.co.jemos.podam.api.PodamFactoryImpl;
import uk.co.jemos.podam.common.AttributeStrategy;
import javax.validation.constraints.Email;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Arrays; import java.util.Arrays;
@ -55,6 +52,9 @@ public class RandomUtils {
} }
return RandomUtil.randomInt(); return RandomUtil.randomInt();
}); });
// LocalDateTime
PODAM_FACTORY.getStrategy().addOrReplaceTypeManufacturer(LocalDateTime.class,
(dataProviderStrategy, attributeMetadata, map) -> randomLocalDateTime());
// Boolean // Boolean
PODAM_FACTORY.getStrategy().addOrReplaceTypeManufacturer(Boolean.class, (dataProviderStrategy, attributeMetadata, map) -> { PODAM_FACTORY.getStrategy().addOrReplaceTypeManufacturer(Boolean.class, (dataProviderStrategy, attributeMetadata, map) -> {
// 如果是 deleted 的字段返回非删除 // 如果是 deleted 的字段返回非删除
@ -82,7 +82,8 @@ public class RandomUtils {
} }
public static LocalDateTime randomLocalDateTime() { public static LocalDateTime randomLocalDateTime() {
return LocalDateTimeUtil.of(randomDate()); // 设置 Nano 为零的原因避免 MySQLH2 存储不到时间戳
return LocalDateTimeUtil.of(randomDate()).withNano(0);
} }
public static Short randomShort() { public static Short randomShort() {
@ -102,6 +103,10 @@ public class RandomUtils {
return randomString() + "@qq.com"; return randomString() + "@qq.com";
} }
public static String randomURL() {
return "https://www.iocoder.cn/" + randomString();
}
@SafeVarargs @SafeVarargs
public static <T> T randomPojo(Class<T> clazz, Consumer<T>... consumers) { public static <T> T randomPojo(Class<T> clazz, Consumer<T>... consumers) {
T pojo = PODAM_FACTORY.manufacturePojo(clazz); T pojo = PODAM_FACTORY.manufacturePojo(clazz);