代码返回参数优化

This commit is contained in:
gs
2024-02-15 23:45:13 +08:00
parent 92a5ac5be1
commit 4b944f9d84

View File

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