Compare commits
21 Commits
develop_re
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8038891403 | ||
|
|
0df7255807 | ||
|
|
3bb8281043 | ||
|
|
d2c03b32f0 | ||
|
|
d4dd23ba34 | ||
|
|
3ecb064f75 | ||
|
|
8f1abca911 | ||
|
|
20686a03df | ||
|
|
645e70281c | ||
|
|
c4a45c8e67 | ||
|
|
64f0aa3d1f | ||
|
|
5bfc9ff014 | ||
|
|
c391c5da4f | ||
|
|
4d70f2412c | ||
|
|
831a0bfb06 | ||
|
|
7883966077 | ||
|
|
47eaf3bea3 | ||
|
|
388ab7fe5b | ||
|
|
e601911c2a | ||
|
|
7f444cf90b | ||
|
|
31975d348d |
@@ -15,7 +15,6 @@ build:
|
|||||||
only:
|
only:
|
||||||
- main
|
- main
|
||||||
- develop
|
- develop
|
||||||
- develop_red
|
|
||||||
before_script:
|
before_script:
|
||||||
- echo '<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
|
- echo '<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
@@ -53,7 +52,6 @@ dockerize:
|
|||||||
only:
|
only:
|
||||||
- main
|
- main
|
||||||
- develop
|
- develop
|
||||||
- develop_red
|
|
||||||
script:
|
script:
|
||||||
- echo ">>>>>>Start Building Docker Image<<<<<<"
|
- echo ">>>>>>Start Building Docker Image<<<<<<"
|
||||||
- pwd
|
- pwd
|
||||||
@@ -74,15 +72,17 @@ dockerize:
|
|||||||
deploy-dev:
|
deploy-dev:
|
||||||
stage: deploy
|
stage: deploy
|
||||||
only:
|
only:
|
||||||
- develop_red
|
- develop
|
||||||
script:
|
script:
|
||||||
- echo "Deploying application..."
|
- echo "Deploying application..."
|
||||||
- ls
|
- ls
|
||||||
- apk update
|
- apk update
|
||||||
- apk add curl
|
- apk add curl
|
||||||
- apk add curl openssh sshpass
|
|
||||||
- |
|
- |
|
||||||
sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no ubuntu@"$SSH_HOST" "./deploy_service.sh market $CI_PIPELINE_ID"
|
curl -X POST \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"namespace":"dgdev", "deployment_name":"germany-stock-market"}' \
|
||||||
|
https://updater-dgdev.moneytj.com/restart-deployment
|
||||||
- echo "Application successfully deployed."
|
- echo "Application successfully deployed."
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,12 +20,6 @@ import cn.stock.market.domain.basic.entity.SiteSetting;
|
|||||||
import cn.stock.market.domain.basic.repository.SiteSettingRepository;
|
import cn.stock.market.domain.basic.repository.SiteSettingRepository;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
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 = {
|
@SpringBootApplication(exclude = {
|
||||||
MongoAutoConfiguration.class, MongoDataAutoConfiguration.class,
|
MongoAutoConfiguration.class, MongoDataAutoConfiguration.class,
|
||||||
RedisAutoConfiguration.class,
|
RedisAutoConfiguration.class,
|
||||||
@@ -37,11 +31,6 @@ public class StockMarketLaunch implements CommandLineRunner {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
HttpGlobalConfig.setTimeout(45000);
|
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);
|
SpringApplication.run(StockMarketLaunch.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1063,25 +1063,10 @@ public class StockService {
|
|||||||
market.setRate(String.valueOf(stockIndex.getPercentChange()));
|
market.setRate(String.valueOf(stockIndex.getPercentChange()));
|
||||||
vo1.setIndexVo(market);
|
vo1.setIndexVo(market);
|
||||||
|
|
||||||
// 只获取最近交易日的K线数据,智能跳过周末,优化性能和网络传输
|
List<ChartCandle> kLines = HomeApiIndex.fetchChartData(stockIndex.getId(), 419);
|
||||||
List<ChartCandle> kLines = HomeApiIndex.fetchTodayAndYesterdayChartData(stockIndex.getId());
|
// List kline = HomeApiIndex.convertToJsonList(kLines);
|
||||||
vo1.setKLine(kLines);
|
vo1.setKLine(kLines);
|
||||||
indexVoList.add(vo1);
|
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);
|
return ServerResponse.createBySuccess(indexVoList);
|
||||||
|
|||||||
@@ -9,21 +9,17 @@ import okhttp3.Response;
|
|||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.time.DayOfWeek;
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class HomeApiIndex {
|
public class HomeApiIndex {
|
||||||
private static final OkHttpClient client = new OkHttpClient();
|
private static final OkHttpClient client = new OkHttpClient();
|
||||||
static Config config = SpringUtils.getBean(Config.class);
|
static Config config = SpringUtils.getBean(Config.class);
|
||||||
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 API_URL = config.getStockUrlPrefix() + "/api/ger-market/stocks/query-list?symbols=DAX,MDAX,SDXP,HDAX";
|
||||||
private static final String BASE_URL = config.getStockUrlPrefix() + "/api/ger-market/chart";
|
private static final String BASE_URL = config.getStockUrlPrefix() + "/api/ger-market/chart";
|
||||||
|
|
||||||
public static List<StockIndex> fetchStockIndices() throws Exception {
|
public static List<StockIndex> fetchStockIndices() throws Exception {
|
||||||
@@ -55,12 +51,10 @@ public class HomeApiIndex {
|
|||||||
index.setName("DAX Index");
|
index.setName("DAX Index");
|
||||||
}else if (index.getSymbol().equals("MDAX")) {
|
}else if (index.getSymbol().equals("MDAX")) {
|
||||||
index.setName("MDAX Index");
|
index.setName("MDAX Index");
|
||||||
}else if (index.getSymbol().equals("IBC:BME")) {
|
}else if (index.getSymbol().equals("HDAX")) {
|
||||||
index.setName("IBEX 35 Index");
|
index.setName("HDAX PERFORMANCE-INDEX");
|
||||||
} else if (index.getSymbol().equals("SDXP")) {
|
} else if (index.getSymbol().equals("SDXP")) {
|
||||||
index.setName("SDAX Index");
|
index.setName("SDAX Index");
|
||||||
}else {
|
|
||||||
index.setName(obj.optString("name"));
|
|
||||||
}
|
}
|
||||||
index.setExchange(obj.optString("exchange"));
|
index.setExchange(obj.optString("exchange"));
|
||||||
index.setMicCode(obj.optString("mic_code"));
|
index.setMicCode(obj.optString("mic_code"));
|
||||||
@@ -86,32 +80,10 @@ public class HomeApiIndex {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取图表数据(原方法,保持向后兼容)
|
|
||||||
*/
|
|
||||||
public static List<ChartCandle> fetchChartData(String symbol, int amount) throws Exception {
|
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<>();
|
List<ChartCandle> result = new ArrayList<>();
|
||||||
|
|
||||||
String url = BASE_URL + "?symbol=" + symbol + "&interval=H&amount=" + amount;
|
String url = BASE_URL + "?symbol=" + symbol + "&interval=D&amount=" + amount;
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
@@ -129,72 +101,22 @@ public class HomeApiIndex {
|
|||||||
JSONObject json = new JSONObject(body);
|
JSONObject json = new JSONObject(body);
|
||||||
JSONArray data = json.getJSONArray("data");
|
JSONArray data = json.getJSONArray("data");
|
||||||
|
|
||||||
if (filterRecentDays) {
|
|
||||||
// 获取最近的交易日期
|
|
||||||
Set<LocalDate> recentTradingDays = getRecentTradingDays();
|
|
||||||
|
|
||||||
for (int i = 0; i < data.length(); i++) {
|
for (int i = 0; i < data.length(); i++) {
|
||||||
JSONObject obj = data.getJSONObject(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();
|
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");
|
long ts = obj.optLong("time");
|
||||||
String formattedTime = convertToGermanTime(ts);
|
String formattedTime = convertToGermanTime(ts);
|
||||||
|
|
||||||
ChartCandle candle = new ChartCandle();
|
|
||||||
candle.setUpd_date(formattedTime);
|
candle.setUpd_date(formattedTime);
|
||||||
candle.setPrice(getDoubleOrNull(obj, "close"));
|
candle.setPrice(getDoubleOrNull(obj, "close"));
|
||||||
|
|
||||||
result.add(candle);
|
result.add(candle);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
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) {
|
// public static List<JSONObject> convertToJsonList(List<ChartCandle> candles) {
|
||||||
// List<JSONObject> result = new ArrayList<>();
|
// List<JSONObject> result = new ArrayList<>();
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import javax.persistence.GenerationType;
|
|||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import org.hibernate.annotations.DynamicInsert;
|
import org.hibernate.annotations.DynamicInsert;
|
||||||
import org.hibernate.annotations.DynamicUpdate;
|
import org.hibernate.annotations.DynamicUpdate;
|
||||||
@@ -76,7 +75,6 @@ public class SiteNewsPO {
|
|||||||
/**
|
/**
|
||||||
* 显示时间 */
|
* 显示时间 */
|
||||||
@ApiModelProperty("显示时间")
|
@ApiModelProperty("显示时间")
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Europe/Madrid")
|
|
||||||
Date showTime;
|
Date showTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ import javax.annotation.PostConstruct;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -312,97 +311,84 @@ public class InvestingTask {
|
|||||||
|
|
||||||
@Scheduled(cron = "0 0 0/3 * * ?")
|
@Scheduled(cron = "0 0 0/3 * * ?")
|
||||||
// @PostConstruct
|
// @PostConstruct
|
||||||
public void getCincoDiasNews() {
|
public void getBoerseNews(){
|
||||||
String baseUrl = "https://cincodias.elpais.com";
|
String url_request = "https://www.boerse-online.de";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<SiteNews> results = new ArrayList<>();
|
List<SiteNews> results = new ArrayList<>();
|
||||||
String listUrl = baseUrl + "/ultimas-noticias/";
|
|
||||||
|
String listUrl = url_request + "/nachrichten/1";
|
||||||
Document doc = Jsoup.connect(listUrl)
|
Document doc = Jsoup.connect(listUrl)
|
||||||
.userAgent("Mozilla/5.0")
|
.userAgent("Mozilla/5.0")
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
Elements articles = doc.select("article.c");
|
Elements articles = doc.select("article.article-list-item");
|
||||||
|
|
||||||
for (Element article : articles) {
|
for (Element article : articles) {
|
||||||
// Title and Link
|
Element aTag = article.selectFirst("h2 a");
|
||||||
Element aTag = article.selectFirst("h2.c_t a");
|
|
||||||
String title = aTag != null ? aTag.text().trim() : null;
|
String title = aTag != null ? aTag.text().trim() : null;
|
||||||
String link = aTag != null ? aTag.absUrl("href") : null;
|
String link = aTag != null ? url_request + aTag.attr("href") : null;
|
||||||
|
|
||||||
// Author
|
Element imgTag = article.selectFirst("figure a picture img");
|
||||||
Element authorTag = article.selectFirst("a.c_a_a");
|
String image = imgTag != null ? imgTag.attr("src") : null;
|
||||||
String author = authorTag != null ? authorTag.text().trim() : null;
|
|
||||||
|
|
||||||
Element figure = article.selectFirst("figure.c_m a img");
|
Element timeTag = article.selectFirst("small.article-info time");
|
||||||
|
|
||||||
String imageUrl = null;
|
|
||||||
if (figure != null) {
|
|
||||||
imageUrl = figure.attr("src");
|
|
||||||
}
|
|
||||||
// Date
|
|
||||||
Date publishedDate = null;
|
Date publishedDate = null;
|
||||||
try {
|
|
||||||
Element timeTag = article.selectFirst("time");
|
|
||||||
if (timeTag != null) {
|
if (timeTag != null) {
|
||||||
String datetimeAttr = timeTag.attr("datetime");
|
String datetimeAttr = timeTag.attr("datetime");
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
||||||
ZonedDateTime zonedDateTime = ZonedDateTime.parse(datetimeAttr, formatter);
|
LocalDateTime dateTime = LocalDateTime.parse(datetimeAttr, formatter);
|
||||||
publishedDate = Date.from(zonedDateTime.toInstant());
|
ZoneId berlinZone = ZoneId.of("Europe/Berlin");
|
||||||
}
|
publishedDate = Date.from(dateTime.atZone(berlinZone).toInstant());
|
||||||
} catch (Exception e) {
|
|
||||||
log.warn("Failed to parse published date for article: {}", link);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Summary
|
Element authorTag = article.selectFirst("small.article-info strong");
|
||||||
String summary = article.selectFirst("p.c_d") != null ? article.selectFirst("p.c_d").text() : null;
|
String author = authorTag != null ? authorTag.text().trim() : null;
|
||||||
|
|
||||||
// Optional: Get full content from article detail page
|
// Fetch article detail page
|
||||||
String htmlContent = "";
|
String htmlContent = "";
|
||||||
if (link != null) {
|
if (link != null) {
|
||||||
try {
|
try {
|
||||||
Document detailDoc = Jsoup.connect(link)
|
Document detailPage = Jsoup.connect(link)
|
||||||
.userAgent("Mozilla/5.0")
|
.userAgent("Mozilla/5.0")
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
// ✅ Extract article main content
|
Element body = detailPage.selectFirst("div.article-body");
|
||||||
Element body = detailDoc.selectFirst("div.a_c.clearfix[data-dtm-region=articulo_cuerpo]");
|
|
||||||
if (body != null) {
|
if (body != null) {
|
||||||
htmlContent = body.html();
|
htmlContent = body.html(); // ✅ inner HTML only
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("Error fetching detail page: {}", link);
|
System.err.println("Error fetching article detail: " + link);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build SiteNews object
|
|
||||||
SiteNews siteNews = new SiteNews();
|
SiteNews siteNews = new SiteNews();
|
||||||
siteNews.setAddTime(new Date());
|
siteNews.setAddTime(new Date());
|
||||||
siteNews.setSourceId(link);
|
siteNews.setSourceId(link);
|
||||||
siteNews.setTitle(title);
|
siteNews.setTitle(title);
|
||||||
siteNews.setSourceName("CINCO_DIAS");
|
siteNews.setSourceName("BOERSE");
|
||||||
siteNews.setDescription(summary != null ? summary : title);
|
siteNews.setDescription(title);
|
||||||
siteNews.setImgurl(imageUrl);
|
siteNews.setImgurl(image);
|
||||||
siteNews.setContent(htmlContent);
|
siteNews.setContent(htmlContent);
|
||||||
siteNews.setStatus(1);
|
siteNews.setStatus(1);
|
||||||
siteNews.setType(1);
|
siteNews.setType(1); // Set as financial news type
|
||||||
siteNews.setViews(0);
|
siteNews.setViews(0);
|
||||||
siteNews.setShowTime(publishedDate);
|
siteNews.setShowTime(publishedDate);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
newsRepository.save(siteNews);
|
newsRepository.save(siteNews);
|
||||||
log.info("Saved Spanish news: {}", title);
|
log.info("Saved German news : {}", title);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("Failed to save Spanish news {}: {}", link, e.getMessage());
|
log.warn("Failed to save German news {}: {}", link, e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}catch (Exception e){
|
||||||
} catch (Exception e) {
|
log.error("Error fetching article detail: {}", e.getMessage());
|
||||||
log.error("Error fetching Spanish news: {}", e.getMessage());
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -31,9 +31,6 @@ public class StockNewTask {
|
|||||||
private static final String BASE_URL = "https://symbol-search.tradingview.com/symbol_search/v3/";
|
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 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
|
@Autowired
|
||||||
StockRepository stockRepository;
|
StockRepository stockRepository;
|
||||||
|
|
||||||
@@ -116,71 +113,4 @@ public class StockNewTask {
|
|||||||
e.printStackTrace();
|
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,7 +1,6 @@
|
|||||||
package cn.stock.market.web;
|
package cn.stock.market.web;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.qutaojing.common.jpa.ConditionBuilder;
|
|
||||||
import cn.stock.market.MoneyStockSuggestDTO;
|
import cn.stock.market.MoneyStockSuggestDTO;
|
||||||
import cn.stock.market.domain.basic.entity.MoneyStock;
|
import cn.stock.market.domain.basic.entity.MoneyStock;
|
||||||
import cn.stock.market.domain.basic.entity.OptionalStock;
|
import cn.stock.market.domain.basic.entity.OptionalStock;
|
||||||
@@ -615,27 +614,10 @@ public class MoneyApiController {
|
|||||||
@ResponseBody
|
@ResponseBody
|
||||||
@EncryptFilter(decryptRequest = false)
|
@EncryptFilter(decryptRequest = false)
|
||||||
|
|
||||||
public List<StockQuoteData> getTopActive(@RequestParam(value = "stockType", required = false) String stockType, @RequestParam(value = "type", required = false) String type) {
|
public List<StockQuoteData> getTopActive(@RequestParam String stockType) {
|
||||||
List<String> topActiveCode = Arrays.asList("AAPL:NASDAQ","MSFT:NASDAQ","GOOGL:NASDAQ","AMZN:NASDAQ","META:NASDAQ","TSLA:NASDAQ","NVDA:NASDAQ","BRK.B:NYSE","JPM:NYSE",
|
List<String> topActiveCode = Arrays.asList("SAP","LIN","SIE","DTE","RHM","MUV2","SHL","DB1","MRK",
|
||||||
"UNH:NYSE", "V:NYSE", "MA:NYSE","JNJ:NYSE","XOM:NYSE","PG:NYSE","HD:NYSE","LLY:NYSE","KO:NYSE", "PEP:NASDAQ", "NFLX:NASDAQ",
|
"BMW", "VOW3", "DHL","ENI","BAS","HEI","ADS","CBK","TLX", "BAYN", "RWE");
|
||||||
"SAP:XETR", "SIE:XETR", "DTE:XETR", "ALV:XETR", "BAS:XETR", "BMW:XETR", "VOW3:XETR", "ADS:XETR", "BAYN:XETR", "RWE:XETR",
|
List<Stock> stocks = stockRepository.findAll(QStockPO.stockPO.stockCode.in(topActiveCode));
|
||||||
"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);
|
List<StockQuoteData> stockQuoteDatas = moneyApiService.getStocksQuote(stocks);
|
||||||
for (StockQuoteData stockQuoteData : stockQuoteDatas) {
|
for (StockQuoteData stockQuoteData : stockQuoteDatas) {
|
||||||
Stock name = stocks.stream().filter(e->e.getStockCode().equals(stockQuoteData.getSymbol())).findFirst().orElse(null);
|
Stock name = stocks.stream().filter(e->e.getStockCode().equals(stockQuoteData.getSymbol())).findFirst().orElse(null);
|
||||||
|
|||||||
@@ -244,18 +244,15 @@ public class StockApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping({"getIndiaIndexByToday.do"})
|
@RequestMapping({"getIndiaIndexByToday.do"})
|
||||||
@ApiOperation(value = "德国--获取指定指数信息(最近交易日K线)", httpMethod = "GET")
|
@ApiOperation(value = "印度--获取指定指数信息", httpMethod = "GET")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public ServerResponse getIndiaIndexByToday() {
|
public ServerResponse getIndiaIndexByToday() {
|
||||||
String INDEX_CODE = "TODAY_INDEX";
|
String INDEX_CODE = "TODAY_INDEX";
|
||||||
// 优化缓存时间为15秒,平衡数据实时性和系统性能
|
return RequestCacheUtils.cache("getIndiaIndexByToday.do", INDEX_CODE,6000, (string) -> {
|
||||||
// 由于只返回最近交易日数据,可以适当延长缓存时间
|
|
||||||
return RequestCacheUtils.cache("getIndiaIndexByToday.do", INDEX_CODE, 15000, (string) -> {
|
|
||||||
try {
|
try {
|
||||||
return this.stockService.getIndexByBtoday();
|
return this.stockService.getIndexByBtoday();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("获取德国指数数据失败: {}", e.getMessage(), e);
|
throw new RuntimeException(e);
|
||||||
throw new RuntimeException("获取指数数据失败: " + e.getMessage(), e);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
spring:
|
spring:
|
||||||
jpa:
|
jpa:
|
||||||
show-sql: true
|
show-sql: true
|
||||||
|
|
||||||
# Redis配置
|
# Redis配置
|
||||||
redis:
|
redis:
|
||||||
host: 167.235.39.59
|
host: 43.153.142.41
|
||||||
password: a5v8b86P4mVzFlUqJV
|
password: a5v8b86P4mVzFlUqJV
|
||||||
port: 47379
|
port: 30041
|
||||||
database: 1
|
database: 1
|
||||||
lettuce:
|
lettuce:
|
||||||
pool:
|
pool:
|
||||||
@@ -18,9 +17,9 @@ spring:
|
|||||||
datasource:
|
datasource:
|
||||||
stock-market:
|
stock-market:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
url: jdbc:mysql://de-cdb-pj5o5m8b.sql.tencentcdb.com:24110/stock-api?useUnicode=true&characterEncoding=utf-8
|
url: jdbc:mysql://43.153.142.41:30040/germany_stock?useUnicode=true&characterEncoding=utf-8
|
||||||
username: root
|
username: root
|
||||||
password: 6QJXv8dA76klnqsWh6f
|
password: uNejHIFQGJOUtYTmE
|
||||||
maxActive: 500
|
maxActive: 500
|
||||||
testWhileIdle: true
|
testWhileIdle: true
|
||||||
validationQuery: SELECT 1
|
validationQuery: SELECT 1
|
||||||
|
|||||||
Reference in New Issue
Block a user