Search in sources :

Example 1 with FundInfoQueryRequest

use of com.tony.billing.request.fund.FundInfoQueryRequest 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);
}
Also used : BaseResponse(com.tony.billing.response.BaseResponse) Response(okhttp3.Response) FundsExistenceCheckResponse(com.tony.billing.response.fund.FundsExistenceCheckResponse) FundInfoQueryResponse(com.tony.billing.response.fund.FundInfoQueryResponse) OkHttpClient(okhttp3.OkHttpClient) JSONObject(com.alibaba.fastjson.JSONObject) FundUpdateRequest(com.tony.billing.request.fund.FundUpdateRequest) FundAddRequest(com.tony.billing.request.fund.FundAddRequest) FundEnhanceRequest(com.tony.billing.request.fund.FundEnhanceRequest) FundDeleteRequest(com.tony.billing.request.fund.FundDeleteRequest) Request(okhttp3.Request) FundBatchAddRequest(com.tony.billing.request.fund.FundBatchAddRequest) FundsExistenceCheckRequest(com.tony.billing.request.fund.FundsExistenceCheckRequest) FundInfoQueryRequest(com.tony.billing.request.fund.FundInfoQueryRequest) FundInfoQueryResponse(com.tony.billing.response.fund.FundInfoQueryResponse) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

JSONObject (com.alibaba.fastjson.JSONObject)1 FundAddRequest (com.tony.billing.request.fund.FundAddRequest)1 FundBatchAddRequest (com.tony.billing.request.fund.FundBatchAddRequest)1 FundDeleteRequest (com.tony.billing.request.fund.FundDeleteRequest)1 FundEnhanceRequest (com.tony.billing.request.fund.FundEnhanceRequest)1 FundInfoQueryRequest (com.tony.billing.request.fund.FundInfoQueryRequest)1 FundUpdateRequest (com.tony.billing.request.fund.FundUpdateRequest)1 FundsExistenceCheckRequest (com.tony.billing.request.fund.FundsExistenceCheckRequest)1 BaseResponse (com.tony.billing.response.BaseResponse)1 FundInfoQueryResponse (com.tony.billing.response.fund.FundInfoQueryResponse)1 FundsExistenceCheckResponse (com.tony.billing.response.fund.FundsExistenceCheckResponse)1 IOException (java.io.IOException)1 OkHttpClient (okhttp3.OkHttpClient)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1