Compare commits
14 Commits
main
...
develop_re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5aef88988e | ||
|
|
02d7b9d027 | ||
|
|
d1fb4bded8 | ||
| dd5eeede7d | |||
|
|
f3dd600189 | ||
|
|
7caaccb580 | ||
| 7deabedfa3 | |||
|
|
721317de0a | ||
|
|
88bfdfa7fa | ||
|
|
51bcd72051 | ||
|
|
769b35046e | ||
|
|
368f4f2f9f | ||
|
|
4053683339 | ||
|
|
9fd87aaf89 |
@@ -15,6 +15,7 @@ build:
|
||||
only:
|
||||
- main
|
||||
- develop
|
||||
- develop_red
|
||||
before_script:
|
||||
- echo '<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
@@ -52,6 +53,7 @@ dockerize:
|
||||
only:
|
||||
- main
|
||||
- develop
|
||||
- develop_red
|
||||
script:
|
||||
- echo ">>>>>>Start Building Docker Image<<<<<<"
|
||||
- pwd
|
||||
@@ -72,17 +74,15 @@ dockerize:
|
||||
deploy-dev:
|
||||
stage: deploy
|
||||
only:
|
||||
- develop
|
||||
- develop_red
|
||||
script:
|
||||
- echo "Deploying application..."
|
||||
- ls
|
||||
- apk update
|
||||
- apk add curl
|
||||
- apk add curl openssh sshpass
|
||||
- |
|
||||
curl -X POST \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"namespace":"dgdev", "deployment_name":"germany-stock-market"}' \
|
||||
https://updater-dgdev.moneytj.com/restart-deployment
|
||||
sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no ubuntu@"$SSH_HOST" "./deploy_service.sh market $CI_PIPELINE_ID"
|
||||
- echo "Application successfully deployed."
|
||||
|
||||
|
||||
|
||||
@@ -20,6 +20,12 @@ import cn.stock.market.domain.basic.entity.SiteSetting;
|
||||
import cn.stock.market.domain.basic.repository.SiteSettingRepository;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@SpringBootApplication(exclude = {
|
||||
MongoAutoConfiguration.class, MongoDataAutoConfiguration.class,
|
||||
RedisAutoConfiguration.class,
|
||||
@@ -31,6 +37,11 @@ public class StockMarketLaunch implements CommandLineRunner {
|
||||
|
||||
public static void main(String[] args) {
|
||||
HttpGlobalConfig.setTimeout(45000);
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("Europe/Madrid"));
|
||||
log.info("JVM ZoneId: {}", ZoneId.systemDefault());
|
||||
log.info("Sample: now={}, madrid={}",
|
||||
new Date(),
|
||||
ZonedDateTime.now(ZoneId.of("Europe/Madrid")));
|
||||
SpringApplication.run(StockMarketLaunch.class, args);
|
||||
}
|
||||
|
||||
|
||||
@@ -1063,10 +1063,25 @@ public class StockService {
|
||||
market.setRate(String.valueOf(stockIndex.getPercentChange()));
|
||||
vo1.setIndexVo(market);
|
||||
|
||||
List<ChartCandle> kLines = HomeApiIndex.fetchChartData(stockIndex.getId(), 419);
|
||||
// List kline = HomeApiIndex.convertToJsonList(kLines);
|
||||
// 只获取最近交易日的K线数据,智能跳过周末,优化性能和网络传输
|
||||
List<ChartCandle> kLines = HomeApiIndex.fetchTodayAndYesterdayChartData(stockIndex.getId());
|
||||
vo1.setKLine(kLines);
|
||||
indexVoList.add(vo1);
|
||||
List<String> order = Arrays.asList(
|
||||
"IBEX 35 Index",
|
||||
"DAX Index",
|
||||
"Dow Jones Industrial Average",
|
||||
"S&P 500 Index"
|
||||
|
||||
);
|
||||
|
||||
|
||||
Map<String, Integer> orderMap = new HashMap<>();
|
||||
for (int i = 0; i < order.size(); i++) {
|
||||
orderMap.put(order.get(i), i);
|
||||
}
|
||||
|
||||
indexVoList.sort(Comparator.comparingInt(o -> orderMap.getOrDefault(o.getIndexVo().getName(), Integer.MAX_VALUE)));
|
||||
}
|
||||
|
||||
return ServerResponse.createBySuccess(indexVoList);
|
||||
|
||||
@@ -9,17 +9,21 @@ import okhttp3.Response;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class HomeApiIndex {
|
||||
private static final OkHttpClient client = new OkHttpClient();
|
||||
static Config config = SpringUtils.getBean(Config.class);
|
||||
private static final String API_URL = config.getStockUrlPrefix() + "/api/ger-market/stocks/query-list?symbols=DAX,MDAX,SDXP,HDAX";
|
||||
private static final String API_URL = config.getStockUrlPrefix() + "/api/ger-market/stocks/query-list?symbols=IBC:BME,DAX,^DJI:NASDAQ,^SPX:NASDAQ";
|
||||
private static final String BASE_URL = config.getStockUrlPrefix() + "/api/ger-market/chart";
|
||||
|
||||
public static List<StockIndex> fetchStockIndices() throws Exception {
|
||||
@@ -51,10 +55,12 @@ public class HomeApiIndex {
|
||||
index.setName("DAX Index");
|
||||
}else if (index.getSymbol().equals("MDAX")) {
|
||||
index.setName("MDAX Index");
|
||||
}else if (index.getSymbol().equals("HDAX")) {
|
||||
index.setName("HDAX PERFORMANCE-INDEX");
|
||||
}else if (index.getSymbol().equals("IBC:BME")) {
|
||||
index.setName("IBEX 35 Index");
|
||||
} else if (index.getSymbol().equals("SDXP")) {
|
||||
index.setName("SDAX Index");
|
||||
}else {
|
||||
index.setName(obj.optString("name"));
|
||||
}
|
||||
index.setExchange(obj.optString("exchange"));
|
||||
index.setMicCode(obj.optString("mic_code"));
|
||||
@@ -80,10 +86,32 @@ public class HomeApiIndex {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图表数据(原方法,保持向后兼容)
|
||||
*/
|
||||
public static List<ChartCandle> fetchChartData(String symbol, int amount) throws Exception {
|
||||
return fetchChartDataWithDateFilter(symbol, amount, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最近的交易日K线数据(支持跨周末)
|
||||
* @param symbol 股票代码
|
||||
* @return 最近交易日的K线数据
|
||||
*/
|
||||
public static List<ChartCandle> fetchTodayAndYesterdayChartData(String symbol) throws Exception {
|
||||
return fetchChartDataWithDateFilter(symbol, 168, true); // 获取7天数据,确保包含交易日
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图表数据,支持日期过滤
|
||||
* @param symbol 股票代码
|
||||
* @param amount 数据量
|
||||
* @param filterRecentDays 是否只返回最近交易日的数据
|
||||
*/
|
||||
private static List<ChartCandle> fetchChartDataWithDateFilter(String symbol, int amount, boolean filterRecentDays) throws Exception {
|
||||
List<ChartCandle> result = new ArrayList<>();
|
||||
|
||||
String url = BASE_URL + "?symbol=" + symbol + "&interval=D&amount=" + amount;
|
||||
String url = BASE_URL + "?symbol=" + symbol + "&interval=H&amount=" + amount;
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
@@ -101,22 +129,72 @@ public class HomeApiIndex {
|
||||
JSONObject json = new JSONObject(body);
|
||||
JSONArray data = json.getJSONArray("data");
|
||||
|
||||
for (int i = 0; i < data.length(); i++) {
|
||||
JSONObject obj = data.getJSONObject(i);
|
||||
ChartCandle candle = new ChartCandle();
|
||||
|
||||
long ts = obj.optLong("time");
|
||||
String formattedTime = convertToGermanTime(ts);
|
||||
|
||||
candle.setUpd_date(formattedTime);
|
||||
candle.setPrice(getDoubleOrNull(obj, "close"));
|
||||
|
||||
result.add(candle);
|
||||
if (filterRecentDays) {
|
||||
// 获取最近的交易日期
|
||||
Set<LocalDate> recentTradingDays = getRecentTradingDays();
|
||||
|
||||
for (int i = 0; i < data.length(); i++) {
|
||||
JSONObject obj = data.getJSONObject(i);
|
||||
|
||||
long ts = obj.optLong("time");
|
||||
ZonedDateTime zonedDateTime = Instant.ofEpochSecond(ts).atZone(ZoneId.of("Europe/Berlin"));
|
||||
LocalDate dataDate = zonedDateTime.toLocalDate();
|
||||
|
||||
// 只保留最近交易日的数据
|
||||
if (recentTradingDays.contains(dataDate)) {
|
||||
ChartCandle candle = new ChartCandle();
|
||||
String formattedTime = convertToGermanTime(ts);
|
||||
candle.setUpd_date(formattedTime);
|
||||
candle.setPrice(getDoubleOrNull(obj, "close"));
|
||||
result.add(candle);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 不过滤,返回所有数据
|
||||
for (int i = 0; i < data.length(); i++) {
|
||||
JSONObject obj = data.getJSONObject(i);
|
||||
|
||||
long ts = obj.optLong("time");
|
||||
String formattedTime = convertToGermanTime(ts);
|
||||
|
||||
ChartCandle candle = new ChartCandle();
|
||||
candle.setUpd_date(formattedTime);
|
||||
candle.setPrice(getDoubleOrNull(obj, "close"));
|
||||
result.add(candle);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最近的交易日期(排除周末)
|
||||
* @return 最近两个交易日的日期集合
|
||||
*/
|
||||
public static Set<LocalDate> getRecentTradingDays() {
|
||||
Set<LocalDate> tradingDays = new HashSet<>();
|
||||
ZoneId germanyZone = ZoneId.of("Europe/Berlin");
|
||||
LocalDate current = LocalDate.now(germanyZone);
|
||||
|
||||
int foundDays = 0;
|
||||
int daysBack = 0;
|
||||
|
||||
// 向前查找最近的两个交易日
|
||||
while (foundDays < 2 && daysBack < 10) { // 最多向前查找10天
|
||||
LocalDate checkDate = current.minusDays(daysBack);
|
||||
|
||||
// 排除周末(周六=6, 周日=7)
|
||||
if (checkDate.getDayOfWeek() != DayOfWeek.SATURDAY &&
|
||||
checkDate.getDayOfWeek() != DayOfWeek.SUNDAY) {
|
||||
tradingDays.add(checkDate);
|
||||
foundDays++;
|
||||
}
|
||||
daysBack++;
|
||||
}
|
||||
|
||||
return tradingDays;
|
||||
}
|
||||
|
||||
// public static List<JSONObject> convertToJsonList(List<ChartCandle> candles) {
|
||||
// List<JSONObject> result = new ArrayList<>();
|
||||
//
|
||||
|
||||
@@ -8,6 +8,7 @@ import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.hibernate.annotations.DynamicInsert;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
@@ -75,6 +76,7 @@ public class SiteNewsPO {
|
||||
/**
|
||||
* 显示时间 */
|
||||
@ApiModelProperty("显示时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Europe/Madrid")
|
||||
Date showTime;
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,6 +36,7 @@ import javax.annotation.PostConstruct;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -311,84 +312,97 @@ public class InvestingTask {
|
||||
|
||||
@Scheduled(cron = "0 0 0/3 * * ?")
|
||||
// @PostConstruct
|
||||
public void getBoerseNews(){
|
||||
String url_request = "https://www.boerse-online.de";
|
||||
public void getCincoDiasNews() {
|
||||
String baseUrl = "https://cincodias.elpais.com";
|
||||
|
||||
try {
|
||||
List<SiteNews> results = new ArrayList<>();
|
||||
|
||||
String listUrl = url_request + "/nachrichten/1";
|
||||
String listUrl = baseUrl + "/ultimas-noticias/";
|
||||
Document doc = Jsoup.connect(listUrl)
|
||||
.userAgent("Mozilla/5.0")
|
||||
.get();
|
||||
|
||||
Elements articles = doc.select("article.article-list-item");
|
||||
Elements articles = doc.select("article.c");
|
||||
|
||||
for (Element article : articles) {
|
||||
Element aTag = article.selectFirst("h2 a");
|
||||
// Title and Link
|
||||
Element aTag = article.selectFirst("h2.c_t a");
|
||||
String title = aTag != null ? aTag.text().trim() : null;
|
||||
String link = aTag != null ? url_request + aTag.attr("href") : null;
|
||||
String link = aTag != null ? aTag.absUrl("href") : null;
|
||||
|
||||
Element imgTag = article.selectFirst("figure a picture img");
|
||||
String image = imgTag != null ? imgTag.attr("src") : null;
|
||||
|
||||
Element timeTag = article.selectFirst("small.article-info time");
|
||||
Date publishedDate = null;
|
||||
|
||||
if (timeTag != null) {
|
||||
String datetimeAttr = timeTag.attr("datetime");
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
||||
LocalDateTime dateTime = LocalDateTime.parse(datetimeAttr, formatter);
|
||||
ZoneId berlinZone = ZoneId.of("Europe/Berlin");
|
||||
publishedDate = Date.from(dateTime.atZone(berlinZone).toInstant());
|
||||
}
|
||||
|
||||
Element authorTag = article.selectFirst("small.article-info strong");
|
||||
// Author
|
||||
Element authorTag = article.selectFirst("a.c_a_a");
|
||||
String author = authorTag != null ? authorTag.text().trim() : null;
|
||||
|
||||
// Fetch article detail page
|
||||
Element figure = article.selectFirst("figure.c_m a img");
|
||||
|
||||
String imageUrl = null;
|
||||
if (figure != null) {
|
||||
imageUrl = figure.attr("src");
|
||||
}
|
||||
// Date
|
||||
Date publishedDate = null;
|
||||
try {
|
||||
Element timeTag = article.selectFirst("time");
|
||||
if (timeTag != null) {
|
||||
String datetimeAttr = timeTag.attr("datetime");
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
||||
ZonedDateTime zonedDateTime = ZonedDateTime.parse(datetimeAttr, formatter);
|
||||
publishedDate = Date.from(zonedDateTime.toInstant());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to parse published date for article: {}", link);
|
||||
}
|
||||
|
||||
// Summary
|
||||
String summary = article.selectFirst("p.c_d") != null ? article.selectFirst("p.c_d").text() : null;
|
||||
|
||||
// Optional: Get full content from article detail page
|
||||
String htmlContent = "";
|
||||
if (link != null) {
|
||||
try {
|
||||
Document detailPage = Jsoup.connect(link)
|
||||
Document detailDoc = Jsoup.connect(link)
|
||||
.userAgent("Mozilla/5.0")
|
||||
.get();
|
||||
|
||||
Element body = detailPage.selectFirst("div.article-body");
|
||||
// ✅ Extract article main content
|
||||
Element body = detailDoc.selectFirst("div.a_c.clearfix[data-dtm-region=articulo_cuerpo]");
|
||||
if (body != null) {
|
||||
htmlContent = body.html(); // ✅ inner HTML only
|
||||
htmlContent = body.html();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error fetching article detail: " + link);
|
||||
log.warn("Error fetching detail page: {}", link);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Build SiteNews object
|
||||
SiteNews siteNews = new SiteNews();
|
||||
siteNews.setAddTime(new Date());
|
||||
siteNews.setSourceId(link);
|
||||
siteNews.setTitle(title);
|
||||
siteNews.setSourceName("BOERSE");
|
||||
siteNews.setDescription(title);
|
||||
siteNews.setImgurl(image);
|
||||
siteNews.setSourceName("CINCO_DIAS");
|
||||
siteNews.setDescription(summary != null ? summary : title);
|
||||
siteNews.setImgurl(imageUrl);
|
||||
siteNews.setContent(htmlContent);
|
||||
siteNews.setStatus(1);
|
||||
siteNews.setType(1); // Set as financial news type
|
||||
siteNews.setType(1);
|
||||
siteNews.setViews(0);
|
||||
siteNews.setShowTime(publishedDate);
|
||||
|
||||
try {
|
||||
newsRepository.save(siteNews);
|
||||
log.info("Saved German news : {}", title);
|
||||
log.info("Saved Spanish news: {}", title);
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to save German news {}: {}", link, e.getMessage());
|
||||
log.warn("Failed to save Spanish news {}: {}", link, e.getMessage());
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("Error fetching article detail: {}", e.getMessage());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Error fetching Spanish news: {}", e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,6 +31,9 @@ public class StockNewTask {
|
||||
private static final String BASE_URL = "https://symbol-search.tradingview.com/symbol_search/v3/";
|
||||
private static final String PARAMS = "?start={start}&hl=1&country=DE&lang=en&search_type=stocks&domain=production&sort_by_country=US&promo=true&exchange={exchange}";
|
||||
|
||||
private static final String US_URL =
|
||||
"https://financialmodelingprep.com/api/v3/stock-screener";
|
||||
private static final String US_API_KEY = "57ZI1xeAsqHY7ag0FBuMkwQzt6TQ60dG";
|
||||
@Autowired
|
||||
StockRepository stockRepository;
|
||||
|
||||
@@ -113,4 +116,71 @@ public class StockNewTask {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 0 8 * * *")
|
||||
// @PostConstruct
|
||||
public void fetchListStock() {
|
||||
try {
|
||||
List<Stock> nasdaqStocks = fetchStocksByExchange("NASDAQ");
|
||||
List<Stock> nyseStocks = fetchStocksByExchange("NYSE");
|
||||
|
||||
List<Stock> allActiveStocks = new ArrayList<>();
|
||||
allActiveStocks.addAll(nasdaqStocks);
|
||||
allActiveStocks.addAll(nyseStocks);
|
||||
|
||||
try {
|
||||
if (!allActiveStocks.isEmpty()) {
|
||||
stockRepository.saveAll(allActiveStocks);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Insert stock failed: {}", e.getMessage());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Error fetchListStock every day: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Stock> fetchStocksByExchange(String exchange) throws Exception {
|
||||
List<Stock> result = new ArrayList<>();
|
||||
|
||||
String url = US_URL + "?exchange=" + exchange + "&apikey=" + US_API_KEY;
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.addHeader("accept", "application/json")
|
||||
.addHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||
.build();
|
||||
|
||||
Response response = client.newCall(request).execute();
|
||||
|
||||
if (!response.isSuccessful()) {
|
||||
throw new RuntimeException("HTTP error code: " + response.code());
|
||||
}
|
||||
|
||||
String body = response.body().string();
|
||||
JSONArray array = new JSONArray(body);
|
||||
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
JSONObject obj = array.getJSONObject(i);
|
||||
if (!obj.optBoolean("isActivelyTrading", false) && obj.optBoolean("isEtf", false)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Stock stock = new Stock();
|
||||
|
||||
String stockCodeNew = obj.getString("symbol") + ":" + obj.getString("exchangeShortName");
|
||||
|
||||
stock.setStockName(obj.getString("companyName"));
|
||||
stock.setStockCode(stockCodeNew);
|
||||
stock.setStockSpell(obj.getString("symbol"));
|
||||
stock.setStockType(obj.getString("exchangeShortName"));
|
||||
stock.setStockGid(stockCodeNew);
|
||||
stock.setStockSymbol(obj.getString("symbol"));
|
||||
|
||||
result.add(stock);
|
||||
}
|
||||
|
||||
System.out.println("Fetched " + result.size() + " stocks for exchange: " + exchange);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.stock.market.web;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.qutaojing.common.jpa.ConditionBuilder;
|
||||
import cn.stock.market.MoneyStockSuggestDTO;
|
||||
import cn.stock.market.domain.basic.entity.MoneyStock;
|
||||
import cn.stock.market.domain.basic.entity.OptionalStock;
|
||||
@@ -614,10 +615,27 @@ public class MoneyApiController {
|
||||
@ResponseBody
|
||||
@EncryptFilter(decryptRequest = false)
|
||||
|
||||
public List<StockQuoteData> getTopActive(@RequestParam String stockType) {
|
||||
List<String> topActiveCode = Arrays.asList("SAP","LIN","SIE","DTE","RHM","MUV2","SHL","DB1","MRK",
|
||||
"BMW", "VOW3", "DHL","ENI","BAS","HEI","ADS","CBK","TLX", "BAYN", "RWE");
|
||||
List<Stock> stocks = stockRepository.findAll(QStockPO.stockPO.stockCode.in(topActiveCode));
|
||||
public List<StockQuoteData> getTopActive(@RequestParam(value = "stockType", required = false) String stockType, @RequestParam(value = "type", required = false) String type) {
|
||||
List<String> topActiveCode = Arrays.asList("AAPL:NASDAQ","MSFT:NASDAQ","GOOGL:NASDAQ","AMZN:NASDAQ","META:NASDAQ","TSLA:NASDAQ","NVDA:NASDAQ","BRK.B:NYSE","JPM:NYSE",
|
||||
"UNH:NYSE", "V:NYSE", "MA:NYSE","JNJ:NYSE","XOM:NYSE","PG:NYSE","HD:NYSE","LLY:NYSE","KO:NYSE", "PEP:NASDAQ", "NFLX:NASDAQ",
|
||||
"SAP:XETR", "SIE:XETR", "DTE:XETR", "ALV:XETR", "BAS:XETR", "BMW:XETR", "VOW3:XETR", "ADS:XETR", "BAYN:XETR", "RWE:XETR",
|
||||
"DBK:XETR", "MUV2:XETR", "FME:XETR", "FRE:XETR", "HEI:XETR", "HEN3:XETR", "LIN:XETR", "IFX:XETR", "CON:XETR", "ZAL:XETR",
|
||||
"ITX:BME", "AIR:BME", "SAN:BME", "IBE:BME", "BBVA:BME", "XPBR:BME", "XPBRA:BME", "CABK:BME", "XAMXB:BME", "CCEP:BME",
|
||||
"XVALO:BME", "AENA:BME", "FER:BME", "AMS:BME", "ELE:BME", "TEF:BME", "NTGY:BME", "XBBDC:BME", "CLNX:BME", "XNOR:BME"
|
||||
);
|
||||
QStockPO q = QStockPO.stockPO;
|
||||
ConditionBuilder builder = ConditionBuilder.builder();
|
||||
builder.and(q.stockCode.in(topActiveCode));
|
||||
if(type != null && !type.trim().isEmpty()) {
|
||||
if (type.equals("us")) {
|
||||
builder.and(q.stockType.in("NASDAQ", "NYSE"));
|
||||
} else if (type.equals("dg")) {
|
||||
builder.and(q.stockType.in("XETR"));
|
||||
} else if (type.equals("es")) {
|
||||
builder.and(q.stockType.in("BME"));
|
||||
}
|
||||
}
|
||||
List<Stock> stocks = stockRepository.findAll(builder.build());
|
||||
List<StockQuoteData> stockQuoteDatas = moneyApiService.getStocksQuote(stocks);
|
||||
for (StockQuoteData stockQuoteData : stockQuoteDatas) {
|
||||
Stock name = stocks.stream().filter(e->e.getStockCode().equals(stockQuoteData.getSymbol())).findFirst().orElse(null);
|
||||
|
||||
@@ -244,15 +244,18 @@ public class StockApiController {
|
||||
}
|
||||
|
||||
@RequestMapping({"getIndiaIndexByToday.do"})
|
||||
@ApiOperation(value = "印度--获取指定指数信息", httpMethod = "GET")
|
||||
@ApiOperation(value = "德国--获取指定指数信息(最近交易日K线)", httpMethod = "GET")
|
||||
@ResponseBody
|
||||
public ServerResponse getIndiaIndexByToday() {
|
||||
String INDEX_CODE = "TODAY_INDEX";
|
||||
return RequestCacheUtils.cache("getIndiaIndexByToday.do", INDEX_CODE,6000, (string) -> {
|
||||
// 优化缓存时间为15秒,平衡数据实时性和系统性能
|
||||
// 由于只返回最近交易日数据,可以适当延长缓存时间
|
||||
return RequestCacheUtils.cache("getIndiaIndexByToday.do", INDEX_CODE, 15000, (string) -> {
|
||||
try {
|
||||
return this.stockService.getIndexByBtoday();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
log.error("获取德国指数数据失败: {}", e.getMessage(), e);
|
||||
throw new RuntimeException("获取指数数据失败: " + e.getMessage(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
spring:
|
||||
jpa:
|
||||
show-sql: true
|
||||
|
||||
# Redis配置
|
||||
redis:
|
||||
host: 43.153.142.41
|
||||
host: 167.235.39.59
|
||||
password: a5v8b86P4mVzFlUqJV
|
||||
port: 30041
|
||||
port: 47379
|
||||
database: 1
|
||||
lettuce:
|
||||
pool:
|
||||
@@ -17,9 +18,9 @@ spring:
|
||||
datasource:
|
||||
stock-market:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://43.153.142.41:30040/germany_stock?useUnicode=true&characterEncoding=utf-8
|
||||
url: jdbc:mysql://de-cdb-pj5o5m8b.sql.tencentcdb.com:24110/stock-api?useUnicode=true&characterEncoding=utf-8
|
||||
username: root
|
||||
password: uNejHIFQGJOUtYTmE
|
||||
password: 6QJXv8dA76klnqsWh6f
|
||||
maxActive: 500
|
||||
testWhileIdle: true
|
||||
validationQuery: SELECT 1
|
||||
|
||||
Reference in New Issue
Block a user