Merge branch 'develop' into 'main'

代码返回参数优化

See merge request india/india_market_java!13
This commit is contained in:
guoshuai
2024-02-15 15:47:04 +00:00

View File

@@ -1,6 +1,7 @@
package cn.stock.market.web; package cn.stock.market.web;
import cn.stock.market.dto.model.StockListVO; import cn.stock.market.dto.model.StockListVO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@@ -23,12 +24,12 @@ public class MoneyProxyApiControl {
@RequestMapping(value = "/api/proxy/queryStockMoneyProxy",method = RequestMethod.GET) @RequestMapping(value = "/api/proxy/queryStockMoneyProxy",method = RequestMethod.GET)
public StockListVO queryStockByMoneyIdAndExchangeType(String scId,String exchangeType){ public JSONObject queryStockByMoneyIdAndExchangeType(String scId,String exchangeType){
return stockByMoneyIdAndExchangeTypeFromHttp(scId,exchangeType); return stockByMoneyIdAndExchangeTypeFromHttp(scId,exchangeType);
} }
public static StockListVO stockByMoneyIdAndExchangeTypeFromHttp(String scId, String exchangeType) { public static JSONObject stockByMoneyIdAndExchangeTypeFromHttp(String scId, String exchangeType) {
try { try {
String url = "https://priceapi.moneycontrol.com/pricefeed/"+exchangeType+"/equitycash/" + scId ; String url = "https://priceapi.moneycontrol.com/pricefeed/"+exchangeType+"/equitycash/" + scId ;
URL obj = new URL(url); URL obj = new URL(url);
@@ -45,23 +46,15 @@ public class MoneyProxyApiControl {
} }
in.close(); in.close();
// 解析JSON数据 // 解析JSON数据
JSONObject jsonObject = null; log.info("stockByCodeAndExchangeType获取 sc_id:{}, exchangeType: {} 的实时价格的结果:{} ",scId,exchangeType,response.toString());
try { return JSONObject.parseObject(response.toString());
jsonObject = JSONObject.parseObject(response.toString());
} catch (Exception e) {
}
log.info("stockByCodeAndExchangeType获取 sc_id:{}, exchangeType: {} 的实时价格的结果:{} ",scId,exchangeType,jsonObject.toJSONString());
StockListVO stockListVO = mapJsonToMoneyStockListVO(jsonObject);
stockListVO.setStock_type(exchangeType);
return stockListVO;
} else { } else {
log.error("HTTP request failed with response code: " + responseCode); log.error("HTTP request failed with response code: " + responseCode);
} }
} catch (Exception e) { } catch (Exception e) {
log.error("stockByMoneyIdAndExchangeTypeFromHttp",e); log.error("stockByMoneyIdAndExchangeTypeFromHttp",e);
} }
return null; return new JSONObject();
} }