fix:app指数接口增加economictimes数据源兜底

This commit is contained in:
xiaoliuhu
2024-04-20 19:11:47 +08:00
parent 4b25467bd2
commit ece782497f
4 changed files with 290 additions and 5 deletions

View File

@@ -11,6 +11,7 @@ import javax.servlet.http.HttpServletRequest;
import cn.hutool.core.text.StrFormatter;
import cn.stock.market.dto.model.*;
import cn.stock.market.infrastructure.api.EttechchartsApis;
import cn.stock.market.infrastructure.api.GrowwInApis;
import cn.stock.market.infrastructure.api.TodayApis;
import cn.stock.market.infrastructure.api.investing.IndiaIndexVo;
@@ -18,6 +19,7 @@ import cn.stock.market.infrastructure.api.investing.IndiaStockVO;
import cn.stock.market.infrastructure.api.investing.InvestingApis;
import cn.stock.market.infrastructure.api.investing.InvestingInvokerApis;
import cn.stock.market.infrastructure.api.sina.vo.HotSearchVO;
import cn.stock.market.utils.*;
import com.ag.utils.CollectionUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
@@ -52,11 +54,6 @@ import cn.stock.market.infrastructure.api.sina.vo.MarketVO;
import cn.stock.market.infrastructure.api.sina.vo.MarketVOResult;
import cn.stock.market.infrastructure.api.sina.vo.k.MinDataVO;
import cn.stock.market.infrastructure.api.sina.vo.k.echarts.EchartsDataVO;
import cn.stock.market.utils.GetPyByChinese;
import cn.stock.market.utils.HttpClientRequest;
import cn.stock.market.utils.PropertiesUtil;
import cn.stock.market.utils.ServerResponse;
import cn.stock.market.utils.Utils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.client.RestTemplate;
@@ -995,6 +992,11 @@ public class StockService {
GrowwInApis.requestSenSexData(indexVoList);
} catch (Exception e1) {
log.error("GrowwIn获取BSESENSEX指数数据异常异常信息。。。。", e1);
try{
EttechchartsApis.requestSensexData(indexVoList);
} catch (Exception e2) {
log.error("Ettechcharts获取BSESENSEX指数数据异常异常信息。。。。", e2);
}
}
}
@@ -1020,6 +1022,11 @@ public class StockService {
GrowwInApis.requestNifty50Data(indexVoList);
} catch (Exception e1) {
log.error("GrowwIn获取NIFTY50指数数据异常异常信息。。。。", e1);
try{
EttechchartsApis.requestNifty50Data(indexVoList);
} catch (Exception e2) {
log.error("Ettechcharts获取NIFTY50指数数据异常异常信息。。。。", e2);
}
}
}
return ServerResponse.createBySuccess(indexVoList);
@@ -1061,4 +1068,68 @@ public class StockService {
}
public ServerResponse getEttechcharts(){
List<IndiaIndexVo> indexVoList = new ArrayList<>();
try {
//获取详情
String scripcode = "SENSEX";
String exchangeid = "47";
String currentTime = DateTimeUtil.dateToStr(new Date(),DateTimeUtil.YMD_FORMAT);
IndiaIndexVo vo1 = new IndiaIndexVo();
JSONObject object = EttechchartsApis.getStockDetail(scripcode, exchangeid,currentTime);
IndiaStockVO market = ettechchartsObjToVo(object);
market.setName("BSESENSEX指数");
vo1.setIndexVo(market);
//获取k线图 1min 当天的数据 分钟
List kine = EttechchartsApis.getStockKline(scripcode,exchangeid);
vo1.setKLine(kine);
indexVoList.add(vo1);
}catch (Exception e){
log.info("获取BSESENSEX指数数据异常异常信息{}。。。。",e.getMessage());
}
try {
//获取详情
String scripcode = "NSE+Index";
String exchangeid = "50";
String currentTime = DateTimeUtil.dateToStr(new Date(),DateTimeUtil.YMD_FORMAT);
IndiaIndexVo vo1 = new IndiaIndexVo();
JSONObject object = EttechchartsApis.getStockDetail(scripcode, exchangeid,currentTime);
IndiaStockVO market = ettechchartsObjToVo(object);
market.setName("NIFTY50指数");
vo1.setIndexVo(market);
//获取k线图 1min 当天的数据 分钟
List kine = EttechchartsApis.getStockKline(scripcode,exchangeid);
vo1.setKLine(kine);
indexVoList.add(vo1);
}catch (Exception e){
log.info("获取NIFTY50指数数据异常异常信息{}。。。。",e.getMessage());
}
return ServerResponse.createBySuccess(indexVoList);
}
private IndiaStockVO ettechchartsObjToVo(JSONObject object) {
IndiaStockVO market = new IndiaStockVO();
if (object.containsKey("Close")) {
market.setClose(object.getString("Close"));
}
if (object.containsKey("Adj_Close")) {
market.setNowPrice(object.getString("Adj_Close"));
}
if (object.containsKey("perchg")) {
market.setRate(object.getString("perchg"));
}
if (object.containsKey("High")) {
market.setHigh(object.getString("High"));
}
if (object.containsKey("Low")) {
market.setLow(object.getString("Low"));
}
if (object.containsKey("Open")) {
market.setOpen(object.getString("Open"));
}
return market;
}
}

File diff suppressed because one or more lines are too long

View File

@@ -212,6 +212,59 @@ public class HttpClientRequest {
return result;
}
public static String doEttechchartsGet(String url) {
CloseableHttpClient httpClient = null;
CloseableHttpResponse response = null;
String result = "";
try {
httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(url);
// httpGet.setHeader(":authority","ettechcharts.indiatimes.com");
// httpGet.setHeader(":method","GET");
// httpGet.setHeader(":scheme","https");
httpGet.setHeader("accept","*/*");
httpGet.setHeader("accept-encoding","gzip, deflate, br");
httpGet.setHeader("accept-language","zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6");
httpGet.setHeader("user-agent","Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36");
httpGet.setHeader("Referer", "https://economictimes.indiatimes.com/");
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000).setConnectionRequestTimeout(35000).setSocketTimeout(60000).build();
httpGet.setConfig(requestConfig);
response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
result = EntityUtils.toString(entity);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (null != response) {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != httpClient) {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return result;
}
public static void main(String[] args) {
String url = "https://marketapi.intoday.in/widget/topgainer/view?exchange=nse";
String str = doGet(url);

View File

@@ -242,6 +242,15 @@ public class StockApiController {
return this.stockService.getIndexByBtoday();
});
}
@RequestMapping({"getIndiaIndexByEttech.do"})
@ApiOperation(value = "印度--获取指定指数信息-Ettech", httpMethod = "GET")
@ResponseBody
public ServerResponse getIndiaIndexByEttech() {
String INDEX_CODE = "TODAY_INDEX";
return RequestCacheUtils.cache("getIndiaIndexByEttech.do", INDEX_CODE, (string) -> {
return this.stockService.getEttechcharts();
});
}
//根据股票id查询 股票指数、大盘指数信息
@RequestMapping({"getMarketByStockGid.do"})