use of com.tony.billing.response.fund.FundInfoQueryResponse in project BillingDubbo by TonyJiangWJ.
the class FundInfoController method queryFundInfo.
@RequestMapping(value = "/fund/info/query", method = RequestMethod.POST)
public FundInfoQueryResponse queryFundInfo(@ModelAttribute("request") @Validated FundInfoQueryRequest request) {
FundInfoQueryResponse response = ResponseUtil.success(new FundInfoQueryResponse());
response.setFundCode(request.getFundCode());
if (StringUtils.isEmpty(request.getPurchaseDate())) {
Optional<String> fundName = redisUtils.hGet(FUND_INFO_HASH_KEY, FUND_INFO_KEY_PREFIX + request.getFundCode(), String.class);
if (fundName.isPresent()) {
response.setFundName(fundName.get());
return response;
}
String queryUrl = String.format(fundValueQueryUrl, request.getFundCode());
OkHttpClient client = new OkHttpClient.Builder().callTimeout(10, TimeUnit.SECONDS).build();
Request req = new Request.Builder().url(queryUrl).build();
try (Response res = client.newCall(req).execute()) {
if (res.isSuccessful() && res.body() != null) {
String responseBodyStr = res.body().string();
responseBodyStr = responseBodyStr.replaceAll("jsonpgz\\(", "").replaceAll("\\);", "");
logger.debug("responseBody: {}", responseBodyStr);
JSONObject jsonObject = JSONObject.parseObject(responseBodyStr);
response.setFundConfirmedDate(jsonObject.getString("jzrq"));
response.setFundConfirmedValue(jsonObject.getString("dwjz"));
response.setFundName(jsonObject.getString("name"));
if (StringUtils.isNotEmpty(response.getFundName())) {
redisUtils.hSet(FUND_INFO_HASH_KEY, FUND_INFO_KEY_PREFIX + request.getFundCode(), response.getFundName());
return response;
}
}
} catch (IOException e) {
logger.error("获取基金:" + request.getFundCode() + " 估值信息失败", e);
}
}
return ResponseUtil.dataNotExisting(response);
}
Aggregations