优化代码

This commit is contained in:
Achilles
2024-01-15 10:13:00 +08:00
parent 82ede6e680
commit bdded7b3fc
3 changed files with 19 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package cn.stock.market.web;
import cn.stock.market.domain.basic.entity.BtodayStock; import cn.stock.market.domain.basic.entity.BtodayStock;
import cn.stock.market.domain.basic.service.BtodayStockService; import cn.stock.market.domain.basic.service.BtodayStockService;
import cn.stock.market.web.annotations.EncryptFilter;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
@@ -43,6 +44,8 @@ public class BTodayStockController {
@ApiImplicitParam(name="durationtype",value = "D(1D的时候传D),D(5D的时候传D),M(3M的时候传M),Y(1Y的时候传Y),Y(5Y的时候传Y),Y(10Y的时候传Y)"), @ApiImplicitParam(name="durationtype",value = "D(1D的时候传D),D(5D的时候传D),M(3M的时候传M),Y(1Y的时候传Y),Y(5Y的时候传Y),Y(10Y的时候传Y)"),
@ApiImplicitParam(name="duration",value = "1(1D的时候传1),5(5D的时候传5),3(3M的时候传3),1(1Y的时候传1),5(5Y的时候传5),10(10Y的时候传10)"), @ApiImplicitParam(name="duration",value = "1(1D的时候传1),5(5D的时候传5),3(3M的时候传3),1(1Y的时候传1),5(5Y的时候传5),10(10Y的时候传10)"),
}) })
@EncryptFilter(decryptRequest = false)
public JSONArray getPriceChartCompanyPullView( public JSONArray getPriceChartCompanyPullView(
@RequestParam(value = "exchange") String exchange, @RequestParam(value = "exchange") String exchange,
@RequestParam(value = "co_code") String coCode, @RequestParam(value = "co_code") String coCode,
@@ -138,6 +141,7 @@ public class BTodayStockController {
}) })
@GetMapping("/api/bToday/stockDetail") @GetMapping("/api/bToday/stockDetail")
@EncryptFilter(decryptRequest = false)
public com.alibaba.fastjson.JSONObject getPriceChartCompanyPullView( public com.alibaba.fastjson.JSONObject getPriceChartCompanyPullView(
@RequestParam(value = "exchange") String exchange, @RequestParam(value = "exchange") String exchange,
@RequestParam(value = "co_code") String coCode @RequestParam(value = "co_code") String coCode

View File

@@ -8,6 +8,7 @@ import cn.stock.market.dto.StockHistoryResponse;
import cn.stock.market.infrastructure.db.po.QMoneyStockPO; import cn.stock.market.infrastructure.db.po.QMoneyStockPO;
import cn.stock.market.utils.RequestCacheUtils; import cn.stock.market.utils.RequestCacheUtils;
import cn.stock.market.utils.ServerResponse; import cn.stock.market.utils.ServerResponse;
import cn.stock.market.web.annotations.EncryptFilter;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
@@ -167,6 +168,8 @@ public class MoneyApiController {
}) })
@GetMapping("/api/market/money/getStockDetail") @GetMapping("/api/market/money/getStockDetail")
@ResponseBody @ResponseBody
@EncryptFilter(decryptRequest = false)
public ServerResponse getStockDetail(@RequestParam String stockType, @RequestParam String symbol ) { public ServerResponse getStockDetail(@RequestParam String stockType, @RequestParam String symbol ) {
String url = String.format("https://priceapi.moneycontrol.com/pricefeed/%s/equitycash/%s",stockType,symbol); String url = String.format("https://priceapi.moneycontrol.com/pricefeed/%s/equitycash/%s",stockType,symbol);
MoneyStock moneyStock = moneyStockRepository.findOne(QMoneyStockPO.moneyStockPO.stockType.eq(stockType).and(QMoneyStockPO.moneyStockPO.moneyScId.eq(symbol))).orElse(null); MoneyStock moneyStock = moneyStockRepository.findOne(QMoneyStockPO.moneyStockPO.stockType.eq(stockType).and(QMoneyStockPO.moneyStockPO.moneyScId.eq(symbol))).orElse(null);
@@ -501,6 +504,8 @@ public class MoneyApiController {
}) })
@GetMapping("/api/market/money/getTopGainer") @GetMapping("/api/market/money/getTopGainer")
@ResponseBody @ResponseBody
@EncryptFilter(decryptRequest = false)
public List<MoneyStockSuggestDTO> getTopGainer(@RequestParam String stockType) { public List<MoneyStockSuggestDTO> getTopGainer(@RequestParam String stockType) {
List<MoneyStockSuggestDTO> moneyStockSuggestDTOS = null; List<MoneyStockSuggestDTO> moneyStockSuggestDTOS = null;
// 尝试从缓存中获取结果 // 尝试从缓存中获取结果
@@ -542,6 +547,8 @@ public class MoneyApiController {
}) })
@GetMapping("/api/market/money/getTopLoser") @GetMapping("/api/market/money/getTopLoser")
@ResponseBody @ResponseBody
@EncryptFilter(decryptRequest = false)
public List<MoneyStockSuggestDTO> getTopLoser(@RequestParam String stockType) { public List<MoneyStockSuggestDTO> getTopLoser(@RequestParam String stockType) {
List<MoneyStockSuggestDTO> moneyStockSuggestDTOS = null; List<MoneyStockSuggestDTO> moneyStockSuggestDTOS = null;
moneyStockSuggestDTOS = loserStockSuggestCache.getIfPresent(stockType); moneyStockSuggestDTOS = loserStockSuggestCache.getIfPresent(stockType);
@@ -590,6 +597,8 @@ public class MoneyApiController {
}) })
@GetMapping("/api/market/money/getTopActives") @GetMapping("/api/market/money/getTopActives")
@ResponseBody @ResponseBody
@EncryptFilter(decryptRequest = false)
public List<MoneyStockSuggestDTO> getTopActive(@RequestParam String stockType) { public List<MoneyStockSuggestDTO> getTopActive(@RequestParam String stockType) {
List<MoneyStockSuggestDTO> moneyStockSuggestDTOS = null; List<MoneyStockSuggestDTO> moneyStockSuggestDTOS = null;
moneyStockSuggestDTOS = activesStockSuggestCache.getIfPresent(stockType); moneyStockSuggestDTOS = activesStockSuggestCache.getIfPresent(stockType);
@@ -639,6 +648,7 @@ public class MoneyApiController {
@ApiImplicitParam(name = "currencyCode", value = "INR 不变", required = true, dataType = "String", paramType = "query") @ApiImplicitParam(name = "currencyCode", value = "INR 不变", required = true, dataType = "String", paramType = "query")
}) })
@ResponseBody @ResponseBody
@EncryptFilter(decryptRequest = false)
public ResponseEntity<StockHistoryResponse> getStockHistory( @RequestParam String symbol, public ResponseEntity<StockHistoryResponse> getStockHistory( @RequestParam String symbol,
@RequestParam String resolution @RequestParam String resolution
) { ) {

View File

@@ -2,6 +2,7 @@ package cn.stock.market.web;
import cn.stock.market.infrastructure.api.TodayApis; import cn.stock.market.infrastructure.api.TodayApis;
import cn.stock.market.utils.ServerResponse; import cn.stock.market.utils.ServerResponse;
import cn.stock.market.web.annotations.EncryptFilter;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@@ -17,6 +18,7 @@ public class TodayApiController {
@RequestMapping({"getTopGainers.do"}) @RequestMapping({"getTopGainers.do"})
@ApiOperation(value = "获取Top Gainers",notes = "exchange传nse或者bse", httpMethod = "GET") @ApiOperation(value = "获取Top Gainers",notes = "exchange传nse或者bse", httpMethod = "GET")
@ResponseBody @ResponseBody
@EncryptFilter(decryptRequest = false)
public ServerResponse getTopGainers(@RequestParam("exchange") String exchange) { public ServerResponse getTopGainers(@RequestParam("exchange") String exchange) {
return ServerResponse.createBySuccess(TodayApis.getTopGainers(exchange)); return ServerResponse.createBySuccess(TodayApis.getTopGainers(exchange));
} }
@@ -24,6 +26,7 @@ public class TodayApiController {
@RequestMapping({"getTopLosers.do"}) @RequestMapping({"getTopLosers.do"})
@ApiOperation(value = "获取 Top Losers",notes = "exchange传nse或者bse", httpMethod = "GET") @ApiOperation(value = "获取 Top Losers",notes = "exchange传nse或者bse", httpMethod = "GET")
@ResponseBody @ResponseBody
@EncryptFilter(decryptRequest = false)
public ServerResponse getTopLosers(@RequestParam("exchange") String exchange) { public ServerResponse getTopLosers(@RequestParam("exchange") String exchange) {
return ServerResponse.createBySuccess(TodayApis.getTopLosers(exchange)); return ServerResponse.createBySuccess(TodayApis.getTopLosers(exchange));
} }
@@ -31,6 +34,7 @@ public class TodayApiController {
@RequestMapping({"getMostActiveVolume.do"}) @RequestMapping({"getMostActiveVolume.do"})
@ApiOperation(value = "获取 Most Active Volume",notes = "exchange传nse或者bse", httpMethod = "GET") @ApiOperation(value = "获取 Most Active Volume",notes = "exchange传nse或者bse", httpMethod = "GET")
@ResponseBody @ResponseBody
@EncryptFilter(decryptRequest = false)
public ServerResponse getMostActiveVolume(@RequestParam("exchange") String exchange) { public ServerResponse getMostActiveVolume(@RequestParam("exchange") String exchange) {
return ServerResponse.createBySuccess(TodayApis.getMostActiveVolume(exchange)); return ServerResponse.createBySuccess(TodayApis.getMostActiveVolume(exchange));
} }
@@ -38,6 +42,7 @@ public class TodayApiController {
@RequestMapping({"getMostActiveValue.do"}) @RequestMapping({"getMostActiveValue.do"})
@ApiOperation(value = "获取 Most Active Value",notes = "exchange传nse或者bse",httpMethod = "GET") @ApiOperation(value = "获取 Most Active Value",notes = "exchange传nse或者bse",httpMethod = "GET")
@ResponseBody @ResponseBody
@EncryptFilter(decryptRequest = false)
public ServerResponse getMostActiveValue(@RequestParam("exchange") String exchange) { public ServerResponse getMostActiveValue(@RequestParam("exchange") String exchange) {
return ServerResponse.createBySuccess(TodayApis.getMostActiveValue(exchange)); return ServerResponse.createBySuccess(TodayApis.getMostActiveValue(exchange));
} }