2021-03-02 00:58:59 +08:00
|
|
|
package cn.iocoder.dashboard.util;
|
|
|
|
|
2021-03-03 01:33:05 +08:00
|
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
2021-03-02 00:58:59 +08:00
|
|
|
import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO;
|
2021-03-03 01:33:05 +08:00
|
|
|
import uk.co.jemos.podam.api.PodamFactory;
|
|
|
|
import uk.co.jemos.podam.api.PodamFactoryImpl;
|
2021-03-02 00:58:59 +08:00
|
|
|
|
2021-03-03 01:33:05 +08:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.function.Consumer;
|
2021-03-02 00:58:59 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 随机工具类
|
|
|
|
*
|
|
|
|
* @author 芋道源码
|
|
|
|
*/
|
|
|
|
public class RandomUtils {
|
|
|
|
|
|
|
|
private static final int RANDOM_STRING_LENGTH = 10;
|
|
|
|
|
2021-03-03 01:33:05 +08:00
|
|
|
private static final int RANDOM_DATE_MAX = 30;
|
|
|
|
|
|
|
|
private static final PodamFactory PODAM_FACTORY = new PodamFactoryImpl();
|
|
|
|
|
2021-03-02 00:58:59 +08:00
|
|
|
public static String randomString() {
|
|
|
|
return RandomUtil.randomString(RANDOM_STRING_LENGTH);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Long randomLong() {
|
|
|
|
return RandomUtil.randomLong(0, Long.MAX_VALUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Integer randomInteger() {
|
|
|
|
return RandomUtil.randomInt(0, Integer.MAX_VALUE);
|
|
|
|
}
|
|
|
|
|
2021-03-03 01:33:05 +08:00
|
|
|
public static Date randomDate() {
|
|
|
|
return RandomUtil.randomDay(0, RANDOM_DATE_MAX);
|
|
|
|
}
|
|
|
|
|
2021-03-02 00:58:59 +08:00
|
|
|
public static Short randomShort() {
|
|
|
|
return (short) RandomUtil.randomInt(0, Short.MAX_VALUE);
|
|
|
|
}
|
|
|
|
|
2021-03-03 01:33:05 +08:00
|
|
|
@SafeVarargs
|
|
|
|
public static SysUserDO randomUserDO(Consumer<SysUserDO>... consumers) {
|
|
|
|
return randomPojo(SysUserDO.class, consumers);
|
2021-03-02 00:58:59 +08:00
|
|
|
}
|
|
|
|
|
2021-03-03 01:33:05 +08:00
|
|
|
@SafeVarargs
|
|
|
|
private static <T> T randomPojo(Class<T> clazz, Consumer<T>... consumers) {
|
|
|
|
T pojo = PODAM_FACTORY.manufacturePojo(clazz);
|
|
|
|
// 非空时,回调逻辑。通过它,可以实现 Pojo 的进一步处理
|
|
|
|
if (ArrayUtil.isNotEmpty(consumers)) {
|
|
|
|
Arrays.stream(consumers).forEach(consumer -> consumer.accept(pojo));
|
2021-03-02 00:58:59 +08:00
|
|
|
}
|
2021-03-03 01:33:05 +08:00
|
|
|
return pojo;
|
2021-03-02 00:58:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|