获取指标说明的能力
This commit is contained in:
47
src/main/java/quant/rich/emoney/pojo/dto/IndexDetail.java
Normal file
47
src/main/java/quant/rich/emoney/pojo/dto/IndexDetail.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package quant.rich.emoney.pojo.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
public interface IndexDetail {
|
||||
|
||||
/**
|
||||
* 获取 indexName
|
||||
* @return
|
||||
*/
|
||||
public String getIndexName();
|
||||
|
||||
/**
|
||||
* 获取 indexCode
|
||||
* @return
|
||||
*/
|
||||
public String getIndexCode();
|
||||
|
||||
/**
|
||||
* 详情接口
|
||||
* @return
|
||||
*/
|
||||
public List<Detail> getDetails();
|
||||
|
||||
/**
|
||||
* 清洗 HTML 内容
|
||||
*/
|
||||
public void sanitize();
|
||||
|
||||
|
||||
@Data
|
||||
@Accessors(chain=true)
|
||||
public static class Detail {
|
||||
private String content;
|
||||
private DetailType type;
|
||||
}
|
||||
|
||||
public static enum DetailType {
|
||||
TITLE,
|
||||
TEXT,
|
||||
IMAGE
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public class IpInfo {
|
||||
if (StringUtils.isNoneBlank(getIpv6())) {
|
||||
sb.append(", ").append("IPv6: ").append(getIpv6());
|
||||
}
|
||||
sb.append(getGeoString());
|
||||
sb.append('(').append(getGeoString()).append(')');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@ public class IpInfo {
|
||||
|
||||
public String getGeoString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("(");
|
||||
if (StringUtils.isNotBlank(getCountry())) {
|
||||
// 国家
|
||||
sb.append(getCountry());
|
||||
@@ -60,7 +59,6 @@ public class IpInfo {
|
||||
else {
|
||||
sb.append("未知位置");
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package quant.rich.emoney.pojo.dto;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import quant.rich.emoney.util.HtmlSanitizer;
|
||||
|
||||
@Data
|
||||
@Accessors(chain=true)
|
||||
public class NonParamsIndexDetail implements IndexDetail {
|
||||
|
||||
@JsonView(IndexDetail.class)
|
||||
private String id;
|
||||
@JsonView(IndexDetail.class)
|
||||
private String name;
|
||||
@JsonView(IndexDetail.class)
|
||||
private String nameCode;
|
||||
@JsonView(IndexDetail.class)
|
||||
private List<NonParamsIndexDetailData> data = new ArrayList<>();
|
||||
|
||||
@Data
|
||||
@Accessors(chain=true)
|
||||
public static class NonParamsIndexDetailData {
|
||||
@JsonView(IndexDetail.class)
|
||||
private String title;
|
||||
@JsonView(IndexDetail.class)
|
||||
private List<String> items;
|
||||
@JsonView(IndexDetail.class)
|
||||
private String image;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIndexName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIndexCode() {
|
||||
return nameCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Detail> getDetails() {
|
||||
List<Detail> list = new ArrayList<>();
|
||||
data.forEach(d -> {
|
||||
if (StringUtils.isNotBlank(d.getTitle())) {
|
||||
list.add(new Detail().setContent(d.getTitle()).setType(DetailType.TITLE));
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(d.getItems())) {
|
||||
d.getItems().forEach(i -> {
|
||||
list.add(new Detail().setContent(i).setType(DetailType.TEXT));
|
||||
});
|
||||
}
|
||||
String image = d.getImage();
|
||||
if (StringUtils.isNotBlank(image)) {
|
||||
// 判断是否是合法 base64 图片,如果不是,生成警告
|
||||
if (!image.startsWith("data:image/") || !image.contains("base64")) {
|
||||
list.add(new Detail()
|
||||
.setContent(
|
||||
new StringBuilder()
|
||||
.append("配图 url: ")
|
||||
.append(image)
|
||||
.append(" 无法获取其地址,请检查或重试")
|
||||
.toString()
|
||||
)
|
||||
.setType(DetailType.TEXT));
|
||||
}
|
||||
else {
|
||||
list.add(new Detail().setContent(image).setType(DetailType.IMAGE));
|
||||
}
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sanitize() {
|
||||
for (NonParamsIndexDetailData data : getData()) {
|
||||
String title = data.getTitle();
|
||||
if (StringUtils.isNotBlank(title)) {
|
||||
data.setTitle(HtmlSanitizer.sanitize(title));
|
||||
}
|
||||
if (data.getItems() != null) {
|
||||
List<String> items = new ArrayList<>();
|
||||
for (String item : data.getItems()) {
|
||||
items.add(HtmlSanitizer.sanitize(item));
|
||||
}
|
||||
data.setItems(items);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package quant.rich.emoney.pojo.dto;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import quant.rich.emoney.util.HtmlSanitizer;
|
||||
|
||||
@Data
|
||||
@Accessors(chain=true)
|
||||
public class ParamsIndexDetail implements IndexDetail {
|
||||
|
||||
@JsonView(IndexDetail.class)
|
||||
private String id;
|
||||
@JsonView(IndexDetail.class)
|
||||
private String name;
|
||||
@JsonView(IndexDetail.class)
|
||||
private String code;
|
||||
@JsonView(IndexDetail.class)
|
||||
private List<String> descriptions = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public String getIndexName() {
|
||||
return name;
|
||||
}
|
||||
@Override
|
||||
public String getIndexCode() {
|
||||
return code;
|
||||
}
|
||||
@Override
|
||||
public List<Detail> getDetails() {
|
||||
List<Detail> list = new ArrayList<>();
|
||||
descriptions.forEach(des -> {
|
||||
list.add(new Detail().setContent(des).setType(DetailType.TEXT));
|
||||
});
|
||||
return list;
|
||||
}
|
||||
@Override
|
||||
public void sanitize() {
|
||||
List<String> descriptions = new ArrayList<>();
|
||||
for (String description : getDescriptions()) {
|
||||
descriptions.add(HtmlSanitizer.sanitize(description));
|
||||
}
|
||||
setDescriptions(descriptions);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user