public static List getAllFunds() {
List dataList = Lists.newArrayList();
typeList.forEach(type -> {
dataList.addAll(getTypeFunds(api, type));
});
return dataList;
}
public static List getTypeFunds(String API, String type) {
List dataList = Lists.newArrayList();
String body = HttpUtil.get(API + type + “&pi=1&pn=1000”);
Integer pages = getPages(body);
dataList.addAll(parseFundData(body));
for (int i = 0; i < pages; i++) {
body = HttpUtil.get(API + type + “&pi=” + (i + 2) + “&pn=1000”);
dataList.addAll(parseFundData(body));
}
return dataList;
}
public static List parseFundData(String text) {
List funds = Lists.newArrayList();
text = text.replace("var rankData = ", “”);
text = text.replace(“;”, “”);
JSONObject json = JSONObject.parseObject(text);
JSONArray array = json.getJSONArray(“datas”);
for (int i = 0; i < array.size(); i++) {
Fund fund = conversion(array.getString(i));
funds.add(fund);
}
return funds;
}
public static Integer getPages(String text) {
text = text.replace("var rankData = ", “”);
text = text.replace(“;”, “”);
JSONObject json = JSONObject.parseObject(text);
Integer pages = json.getInteger(“allPages”);
return pages;
}
public static Fund conversion(String text) {
String[] args = text.split(“\|”);
Fund fund = new Fund();
fund.setRowData(text);
fund.setCode(args[0]);
fund.setName(args[1]);
fund.setType(args[2]);
fund.setDate(args[3]);
fund.setNetValue(StrToDouble(args[4]));
fund.setDayRise(StrToDouble(args[5]));
fund.setWeekRise(StrToDouble(args[6]));
fund.setMonthRise(StrToDouble(args[7]));
fund.setThreeMonthsRise(StrToDouble(args[8]));
fund.setSixMonthsRise(StrToDouble(args[9]));
fund.setOneYearRise(StrToDouble(args[10]));
fund.setTwoYearsRise(StrToDouble(args[11]));
fund.setThreeYearsRise(StrToDouble(args[12]));
fund.setCurYearRise(StrToDouble(args[13]));
fund.setHistoryRise(StrToDouble(args[14]));
fund.setPoundage(StrToDouble(args[18]));
fund.setDtStatus(Integer.valueOf(args[22]));
fund.setDealStatus(Integer.valueOf(args[23]));
return fund;
}
public static Double StrToDouble(String str) {
str = str.replace(“,”, “”);
return StringUtils.isEmpty(str) ? 0 : Double.valueOf(str);
}
@Data
static
class Fund {
/**
- 基金代码
**/
private String code;
/**
- 基金名称
**/
private String name;
/**
- 基金类型
**/
private String type;
/**
- 净值时间
**/
private String date;
/**
- 基金净值
**/
private Double netValue;
/**
- 日增长率
**/
private Double dayRise;
/**
- 近1周
**/
private Double weekRise;
/**
- 近1个月
**/
private Double monthRise;
/**
- 近3个月
**/
private Double threeMonthsRise;
/**
- 近6个月
**/
private Double sixMonthsRise;
/**
- 近1年
**/
private Double oneYearRise;
/**
- 近2年
**/
private Double twoYearsRise;
/**
- 近3年
**/
private Double threeYearsRise;
/**
- 近1年
**/
private Double curYearRise;
/**
- 成立以来
**/
private Double historyRise;
/**