Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
platform
/
platform-charging-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit ba34f04c
authored
Nov 07, 2023
by
zhouhaibao
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]删除无用类
1 parent
5d977921
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
98 deletions
platform-charging/src/main/java/cn/com/glsx/charging/Application.java
platform-charging/src/main/java/cn/com/glsx/charging/util/VOHelpler.java
platform-charging/src/main/java/cn/com/glsx/charging/Application.java
View file @
ba34f04
platform-charging/src/main/java/cn/com/glsx/charging/util/VOHelpler.java
deleted
100644 → 0
View file @
5d97792
/*
package cn.com.glsx.charging.util;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;
import com.google.common.collect.Lists;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class VOHelpler {
private static AtomicInteger rec = new AtomicInteger();
@SuppressWarnings("unchecked")
public static <T, D> T random(Class<T> t, Class<D> d) {
T o = null;
try {
if (StringUtils.startsWithAny(t.getName(), "org.glsx", "cn.com.glsx.charging")) {
o = initSwaggerExample(t.newInstance());
} else if (t == Integer.class || t == int.class) {
o = (T) Integer.valueOf(RandomUtils.nextInt(10, 3000) + 1);
} else if (t == List.class) {
o = (T) Lists.newArrayList();
for (int i = 0; i < 3; i++) {
if (d != null) {
((List) o).add(random(d, null));
} else {
((List) o).add(initSwaggerExample(ClassUtils.getGenricType(t, 0)));
}
}
} else if (t == String.class) {
o = (T) "test_str";
} else if (t == Date.class) {
o = (T) DateUtils.addDay(DateUtils.today(), -rec.getAndIncrement());
if (rec.get() >= 7) {
rec.set(0);
}
} else if (t == BigDecimal.class) {
o = (T) BigDecimal.valueOf(RandomUtils.nextDouble()).setScale(4, RoundingMode.HALF_UP);
} else {
log.info("not init type:{}", t.getName());
}
} catch (Exception e) {
e.printStackTrace();
}
return o;
}
public static <O> O initSwaggerExample(O o) {
if (o == null) {
return o;
}
List<Field> fields = BeanUtils.getFields(o.getClass());
for (Field f : fields) {
try {
f.setAccessible(true);
if (StringUtils.startsWithAny(f.getType().getName(), "org.glsx", "cn.com.glsx.charging")) {
if (f.get(o) == null && !Modifier.isAbstract(f.getType().getModifiers())) {
// 直接初始化
Object v = initSwaggerExample(f.getType().newInstance());
f.set(o, v);
} else {
initSwaggerExample(f.get(o));
}
} else if (StringUtils.startsWith(f.getType().getName(), "java")) {
ApiModelProperty annon = f.getAnnotation(ApiModelProperty.class);
if (annon != null && StringUtils.isNotEmpty(annon.example())) {
if (StringUtils.isNotEmpty(annon.dataType())) {
f.set(o, TypeConvertUtil.convert(annon.example(), f.getType().getName(), annon.dataType()));
} else {
f.set(o, TypeConvertUtil.convert(annon.example(), f.getType().getName(), null));
}
} else {
// 直接初始化
f.setAccessible(true);
f.set(o, random(f.getType(), ClassUtils.getFieldGenericType(f, 0)));
}
}
} catch (Exception e) {
log.warn("field:{}", f, e);
}
}
return o;
}
}
*/
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment