Compare commits
6 Commits
us-gold
...
develop_re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5aef88988e | ||
|
|
02d7b9d027 | ||
|
|
d1fb4bded8 | ||
| dd5eeede7d | |||
|
|
f3dd600189 | ||
|
|
7caaccb580 |
@@ -16,7 +16,6 @@ build:
|
||||
- main
|
||||
- develop
|
||||
- develop_red
|
||||
- us-gold
|
||||
before_script:
|
||||
- echo '<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
@@ -55,7 +54,6 @@ dockerize:
|
||||
- main
|
||||
- develop
|
||||
- develop_red
|
||||
- us-gold
|
||||
script:
|
||||
- echo ">>>>>>Start Building Docker Image<<<<<<"
|
||||
- pwd
|
||||
|
||||
5
pom.xml
5
pom.xml
@@ -82,10 +82,7 @@
|
||||
<artifactId>redisson-spring-boot-starter</artifactId>
|
||||
<version>3.13.3</version>
|
||||
</dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper</artifactId>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,30 +1,11 @@
|
||||
package cn.stock.market.domain.basic.service;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import cn.qutaojing.common.jpa.ConditionBuilder;
|
||||
import cn.stock.market.infrastructure.db.po.QSiteNewsPO;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
@@ -44,8 +25,7 @@ import cn.stock.market.utils.StringUtils;
|
||||
import cn.stock.market.utils.Utils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
/**
|
||||
* SiteNewsService
|
||||
@@ -60,8 +40,6 @@ import org.springframework.web.client.RestTemplate;
|
||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||
public class SiteNewsService {
|
||||
final SiteNewsRepository repository;
|
||||
private final RedisTemplate<String, String> redisTemplate;
|
||||
private final RestTemplate restTemplate;
|
||||
final SiteNewsFactory factory;
|
||||
|
||||
/*新闻资讯-查询列表*/
|
||||
@@ -76,92 +54,6 @@ public class SiteNewsService {
|
||||
return ServerResponse.createBySuccess(Utils.toPageHelperInfo(page));
|
||||
}
|
||||
|
||||
public ServerResponse getLatestStockNews(int pageNum) {
|
||||
int pageSize = 20;
|
||||
String redisKey = "fmp:stock:latest:news:page:" + pageNum;
|
||||
|
||||
try {
|
||||
// Step 1: get from cache
|
||||
String cached = redisTemplate.opsForValue().get(redisKey);
|
||||
List<SiteNews> list;
|
||||
if (cached!= null && !cached.isEmpty()) {
|
||||
list = JSON.parseArray(cached, SiteNews.class);
|
||||
} else {
|
||||
// Step 2: call FMP API
|
||||
String url = String.format("https://financialmodelingprep.com/stable/news/stock-latest?page=%d&limit=%d&apikey=57ZI1xeAsqHY7ag0FBuMkwQzt6TQ60dG", pageNum, pageSize);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("accept", "application/json");
|
||||
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||
|
||||
if (response.getStatusCode().value() != 200 || response.getBody() == null) {
|
||||
return ServerResponse.createByErrorMsg("Failed to fetch news");
|
||||
}
|
||||
|
||||
JSONArray newsArray = JSON.parseArray(response.getBody());
|
||||
list = new ArrayList<>();
|
||||
for (int i = 0; i < newsArray.size(); i++) {
|
||||
JSONObject obj = newsArray.getJSONObject(i);
|
||||
String sourceId = obj.getString("url");
|
||||
|
||||
SiteNews news = new SiteNews();
|
||||
news.setSourceId(sourceId);
|
||||
news.setTitle(obj.getString("title"));
|
||||
news.setSourceName(obj.getString("publisher"));
|
||||
news.setDescription(obj.getString("text"));
|
||||
news.setContent(obj.getString("text"));
|
||||
news.setImgurl(obj.getString("image"));
|
||||
news.setStatus(1);
|
||||
news.setType(1);
|
||||
news.setViews(0);
|
||||
news.setAddTime(new Date());
|
||||
|
||||
try {
|
||||
ZonedDateTime ny = ZonedDateTime.of(
|
||||
LocalDateTime.parse(obj.getString("publishedDate"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),
|
||||
ZoneId.of("America/New_York")
|
||||
);
|
||||
news.setShowTime(Date.from(ny.withZoneSameInstant(ZoneId.systemDefault()).toInstant()));
|
||||
} catch (Exception e) {
|
||||
news.setShowTime(new Date());
|
||||
}
|
||||
|
||||
list.add(news);
|
||||
}
|
||||
|
||||
redisTemplate.opsForValue().set(redisKey, JSON.toJSONString(list), Duration.ofMinutes(10));
|
||||
}
|
||||
int simulatedTotal = 100;
|
||||
|
||||
Page<SiteNews> page = buildPage(list, pageNum, pageSize, simulatedTotal);
|
||||
return ServerResponse.createBySuccess(page);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Error getting latest stock news page {}", pageNum, e);
|
||||
try{
|
||||
Page<SiteNews> page = repository.findAll(ConditionBuilder.builder().build(), PageParam.of(pageNum, pageSize), QSiteNewsPO.siteNewsPO.showTime.desc());
|
||||
|
||||
return ServerResponse.createBySuccess(page);
|
||||
}catch (Exception e1) {
|
||||
return ServerResponse.createByErrorMsg("Internal error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Page<SiteNews> buildPage(List<SiteNews> allNews, int pageNum, int pageSize, int totalCount) {
|
||||
int offset = pageNum * pageSize;
|
||||
|
||||
// Defensive bounds check
|
||||
int toIndex = Math.min(offset + pageSize, allNews.size());
|
||||
|
||||
List<SiteNews> pagedList = offset >= allNews.size() ? allNews : allNews.subList(offset, toIndex);
|
||||
|
||||
Pageable pageable = PageRequest.of(pageNum, pageSize);
|
||||
|
||||
// You can pass total = 100 to simulate full dataset
|
||||
return new PageImpl<>(pagedList, pageable, totalCount);
|
||||
}
|
||||
|
||||
/*新闻资讯-查询详情*/
|
||||
public ServerResponse getDetail(int id) {
|
||||
return ServerResponse.createBySuccess(repository.find(id));
|
||||
@@ -184,8 +76,89 @@ public class SiteNewsService {
|
||||
return ServerResponse.createBySuccess(pageInfo);
|
||||
}
|
||||
|
||||
/*新闻资讯-抓取*/
|
||||
public int grabNews() {
|
||||
int ret = 0;
|
||||
//新闻类型:1、财经要闻,2、经济数据,3、全球股市,4、7*24全球,5、商品资讯,6、上市公司,7、全球央行
|
||||
ret = addNews(1, PropertiesUtil.getProperty("news.main.url") + "/pc_news/FastNews/GetImportantNewsList");
|
||||
log.info("财经要闻-抓取条数:" + ret);
|
||||
|
||||
ret = addNews(2, PropertiesUtil.getProperty("news.main.url") + "/pc_news/FastNews/GetInfoList?code=125&pageNumber=1&pagesize=20&condition=&r=");
|
||||
log.info("经济数据-抓取条数:" + ret);
|
||||
|
||||
ret = addNews(3, PropertiesUtil.getProperty("news.main.url") + "/pc_news/FastNews/GetInfoList?code=105&pageNumber=1&pagesize=20&condition=&r=");
|
||||
log.info("全球股市-抓取条数:" + ret);
|
||||
|
||||
ret = addNews(4, PropertiesUtil.getProperty("news.main.url") + "/pc_news/FastNews/GetInfoList?code=100&pageNumber=1&pagesize=20&condition=&r=");
|
||||
log.info("7*24全球-抓取条数:" + ret);
|
||||
|
||||
ret = addNews(5, PropertiesUtil.getProperty("news.main.url") + "/pc_news/FastNews/GetInfoList?code=106&pageNumber=1&pagesize=20&condition=&r=");
|
||||
log.info("商品资讯-抓取条数:" + ret);
|
||||
|
||||
ret = addNews(6, PropertiesUtil.getProperty("news.main.url") + "/pc_news/FastNews/GetInfoList?code=103&pageNumber=1&pagesize=20&condition=&r=");
|
||||
log.info("上市公司-抓取条数:" + ret);
|
||||
|
||||
ret = addNews(7, PropertiesUtil.getProperty("news.main.url") + "/pc_news/FastNews/GetInfoList?code=118&pageNumber=1&pagesize=20&condition=&r=");
|
||||
log.info("全球央行-抓取条数:" + ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
*抓取新闻专用
|
||||
* type:新闻类型:1、财经要闻,2、经济数据,3、全球股市,4、7*24全球,5、商品资讯,6、上市公司,7、全球央行
|
||||
* */
|
||||
private int addNews(Integer type, String url){
|
||||
int k = 0;
|
||||
try {
|
||||
String newlist = HttpRequest.doGrabGet(url);
|
||||
JSONObject json = JSONObject.fromObject(newlist);
|
||||
if(json != null && json.getJSONArray("items") != null && json.getJSONArray("items").size() > 0){
|
||||
for (int i = 0; i < json.getJSONArray("items").size(); i++){
|
||||
JSONObject model = JSONObject.fromObject(json.getJSONArray("items").getString(i));
|
||||
String newsId = model.getString("code");
|
||||
String imgUrl = null;
|
||||
if(model.has("imgUrl")){
|
||||
imgUrl = model.getString("imgUrl");
|
||||
}
|
||||
//新闻不存在则添加
|
||||
if(repository.getNewsBySourceIdCount(newsId) == 0){
|
||||
//获取新闻详情
|
||||
String newdata = HttpRequest.doGrabGet(PropertiesUtil.getProperty("news.main.url") + "/PC_News/Detail/GetDetailContent?id="+ newsId +"&type=1");
|
||||
newdata = newdata.substring(1,newdata.length()-1).replace("\\\\\\\"","\"");
|
||||
newdata = newdata.replace("\\\"","\"");
|
||||
newdata = StringUtils.UnicodeToCN(newdata);
|
||||
newdata = StringUtils.delHTMLTag(newdata);
|
||||
|
||||
JSONObject jsonnew = JSONObject.fromObject(newdata);
|
||||
if(jsonnew != null && jsonnew.get("data") != null){
|
||||
JSONObject news = JSONObject.fromObject(jsonnew.get("data"));
|
||||
SiteNews siteNews = new SiteNews();
|
||||
siteNews.setSourceId(newsId);
|
||||
siteNews.setSourceName(news.getString("source"));
|
||||
siteNews.setTitle(news.getString("title"));
|
||||
String showTime = news.getString("showTime");
|
||||
siteNews.setShowTime(DateTimeUtil.strToDate(showTime));
|
||||
siteNews.setImgurl(imgUrl);
|
||||
siteNews.setDescription(news.getString("description"));
|
||||
siteNews.setContent(news.getString("content"));
|
||||
siteNews.setStatus(1);
|
||||
siteNews.setType(type);
|
||||
try {
|
||||
repository.saveAndFlush(siteNews);
|
||||
} catch(Exception e) {
|
||||
log.warn("siteNewsMapper insert error: {}", e.getLocalizedMessage());
|
||||
}
|
||||
k++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return k;
|
||||
}
|
||||
|
||||
public SiteNewsRepository repository() {
|
||||
return repository;
|
||||
|
||||
@@ -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=^DJI:NASDAQ,^GSPC:NASDAQ,^IXIC:NASDAQ,^NDX:NASDAQ,^RUI:NASDAQ";
|
||||
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 {
|
||||
@@ -47,9 +51,17 @@ public class HomeApiIndex {
|
||||
|
||||
index.setId(obj.optString("id"));
|
||||
index.setSymbol(obj.optString("symbol"));
|
||||
|
||||
index.setName(obj.optString("name"));
|
||||
|
||||
if (index.getSymbol().equals("DAX")) {
|
||||
index.setName("DAX Index");
|
||||
}else if (index.getSymbol().equals("MDAX")) {
|
||||
index.setName("MDAX 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"));
|
||||
index.setDatetime(obj.optString("datetime"));
|
||||
@@ -74,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)
|
||||
@@ -95,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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,6 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
@@ -190,172 +189,220 @@ public class InvestingTask {
|
||||
}
|
||||
|
||||
/*德国新闻接口*/
|
||||
@Scheduled(cron = "0 0 0/3 * * ?")
|
||||
// @PostConstruct
|
||||
// @Scheduled(cron = "0 0 0/3 * * ?")
|
||||
public void saveGerNews() {
|
||||
log.info("FMP 股票新闻数据同步开始");
|
||||
log.info("德国股票新闻数据同步开始");
|
||||
int savedCount = 0;
|
||||
int totalCount = 0;
|
||||
|
||||
try {
|
||||
String newsListUrl = "https://financialmodelingprep.com/stable/news/stock-latest?page=0&limit=30&apikey=57ZI1xeAsqHY7ag0FBuMkwQzt6TQ60dG";
|
||||
|
||||
// API URL for getting news list
|
||||
String newsListUrl = "https://api.boerse-frankfurt.de/v1/data/category_news?newsType=ALL&lang=de&offset=0&limit=50";
|
||||
|
||||
// Headers for the API request
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("accept", "application/json");
|
||||
headers.add("accept", "application/json, text/plain, */*");
|
||||
headers.add("accept-language", "en-US,en;q=0.9,vi;q=0.8,ug;q=0.7,fr;q=0.6");
|
||||
headers.add("origin", "https://www.boerse-frankfurt.de");
|
||||
headers.add("priority", "u=1, i");
|
||||
headers.add("referer", "https://www.boerse-frankfurt.de/");
|
||||
headers.add("user-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36");
|
||||
|
||||
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||
|
||||
// Get news list
|
||||
ResponseEntity<String> response = restTemplate.exchange(
|
||||
newsListUrl,
|
||||
HttpMethod.GET,
|
||||
entity,
|
||||
String.class
|
||||
newsListUrl,
|
||||
HttpMethod.GET,
|
||||
entity,
|
||||
String.class
|
||||
);
|
||||
|
||||
if (response.getStatusCode().value() == 200 && response.getBody() != null) {
|
||||
JSONArray newsArray = JSON.parseArray(response.getBody());
|
||||
totalCount = newsArray.size();
|
||||
log.info("Found {} news items to process", totalCount);
|
||||
|
||||
for (int i = 0; i < newsArray.size(); i++) {
|
||||
try {
|
||||
JSONObject newsItem = newsArray.getJSONObject(i);
|
||||
String sourceId = newsItem.getString("url");
|
||||
|
||||
// Check existence
|
||||
List<SiteNews> existingNews = newsRepository.findAll(QSiteNewsPO.siteNewsPO.sourceId.eq(sourceId));
|
||||
if (!existingNews.isEmpty()) {
|
||||
log.debug("News {} already exists, skipping", sourceId);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create and populate SiteNews entity
|
||||
SiteNews siteNews = new SiteNews();
|
||||
siteNews.setAddTime(new Date());
|
||||
siteNews.setSourceId(sourceId);
|
||||
siteNews.setTitle(newsItem.getString("title"));
|
||||
siteNews.setSourceName(newsItem.getString("publisher"));
|
||||
siteNews.setDescription(newsItem.getString("symbol"));
|
||||
siteNews.setImgurl(newsItem.getString("image"));
|
||||
siteNews.setContent(newsItem.getString("text"));
|
||||
siteNews.setStatus(1);
|
||||
siteNews.setType(1);
|
||||
siteNews.setViews(0);
|
||||
|
||||
// Parse publishedDate
|
||||
String publishedDate = newsItem.getString("publishedDate");
|
||||
JSONObject newsListResponse = JSON.parseObject(response.getBody());
|
||||
JSONArray newsData = newsListResponse.getJSONArray("data");
|
||||
|
||||
if (newsData != null && newsData.size() > 0) {
|
||||
totalCount = newsData.size();
|
||||
log.info("Found {} German news items to process", totalCount);
|
||||
|
||||
for (int i = 0; i < newsData.size(); i++) {
|
||||
try {
|
||||
ZonedDateTime nyTime = ZonedDateTime.of(
|
||||
LocalDateTime.parse(publishedDate, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),
|
||||
ZoneId.of("America/New_York")
|
||||
);
|
||||
|
||||
ZonedDateTime localTime = nyTime.withZoneSameInstant(ZoneId.systemDefault());
|
||||
siteNews.setShowTime(Date.from(localTime.toInstant()));
|
||||
JSONObject newsItem = newsData.getJSONObject(i);
|
||||
String newsId = newsItem.getString("id");
|
||||
String headline = newsItem.getString("headline");
|
||||
String time = newsItem.getString("time");
|
||||
String source = newsItem.getString("source");
|
||||
String teaserText = newsItem.getString("teaserText");
|
||||
String teaserImageUrl = newsItem.getString("teaserImageUrl");
|
||||
|
||||
// Check if news already exists
|
||||
List<SiteNews> existingNews = newsRepository.findAll(QSiteNewsPO.siteNewsPO.sourceId.eq(newsId));
|
||||
if (existingNews.size() == 0) {
|
||||
// Get news detail
|
||||
String newsDetailUrl = "https://api.boerse-frankfurt.de/v1/data/news?id=" + newsId + "&lang=de";
|
||||
HttpEntity<String> detailEntity = new HttpEntity<>(headers);
|
||||
|
||||
ResponseEntity<String> detailResponse = restTemplate.exchange(
|
||||
newsDetailUrl,
|
||||
HttpMethod.GET,
|
||||
detailEntity,
|
||||
String.class
|
||||
);
|
||||
|
||||
if (detailResponse.getStatusCode().value() == 200 && detailResponse.getBody() != null) {
|
||||
JSONObject newsDetail = JSON.parseObject(detailResponse.getBody());
|
||||
String body = newsDetail.getString("body");
|
||||
|
||||
// Create SiteNews entity
|
||||
SiteNews siteNews = new SiteNews();
|
||||
siteNews.setAddTime(new Date());
|
||||
siteNews.setSourceId(newsId);
|
||||
siteNews.setTitle(headline);
|
||||
siteNews.setSourceName(source);
|
||||
siteNews.setDescription(teaserText != null ? teaserText : "");
|
||||
siteNews.setImgurl(teaserImageUrl);
|
||||
siteNews.setContent(body != null ? body : "");
|
||||
siteNews.setStatus(1);
|
||||
siteNews.setType(1); // Set as financial news type
|
||||
siteNews.setViews(0);
|
||||
|
||||
// Parse and set show time
|
||||
if (time != null && !time.isEmpty()) {
|
||||
try {
|
||||
// Parse ISO 8601 format: "2025-06-19T08:37:58+02:00"
|
||||
// Remove timezone offset and convert to standard format
|
||||
String timeStr = time.replace("+02:00", "").replace("T", " ");
|
||||
siteNews.setShowTime(DateTimeUtil.strToDate(timeStr, "yyyy-MM-dd HH:mm:ss"));
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to parse time for news {}: {}", newsId, time);
|
||||
siteNews.setShowTime(new Date());
|
||||
}
|
||||
} else {
|
||||
siteNews.setShowTime(new Date());
|
||||
}
|
||||
|
||||
try {
|
||||
newsRepository.save(siteNews);
|
||||
savedCount++;
|
||||
log.info("Saved German news [{}/{}]: {}", savedCount, totalCount, headline);
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to save German news {}: {}", newsId, e.getMessage());
|
||||
}
|
||||
} else {
|
||||
log.warn("Failed to get news detail for {}: HTTP {}", newsId, detailResponse.getStatusCode());
|
||||
}
|
||||
} else {
|
||||
log.debug("News {} already exists, skipping", newsId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to parse publishedDate with timezone for {}: {}", sourceId, publishedDate);
|
||||
siteNews.setShowTime(new Date());
|
||||
log.warn("Error processing news item {}: {}", i, e.getMessage());
|
||||
}
|
||||
|
||||
// Save news
|
||||
newsRepository.save(siteNews);
|
||||
savedCount++;
|
||||
log.info("Saved news [{}/{}]: {}", savedCount, totalCount, siteNews.getTitle());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.warn("Error processing news item {}: {}", i, e.getMessage());
|
||||
}
|
||||
} else {
|
||||
log.warn("No news data found in API response");
|
||||
}
|
||||
|
||||
} else {
|
||||
log.error("Failed to fetch news: HTTP {}", response.getStatusCode());
|
||||
log.error("Failed to get news list: HTTP {}", response.getStatusCode());
|
||||
}
|
||||
|
||||
log.info("FMP 股票新闻数据同步完成,总数 {},已保存 {}", totalCount, savedCount);
|
||||
log.info("德国股票新闻数据同步完成,处理了 {} 条新闻,保存了 {} 条新闻", totalCount, savedCount);
|
||||
} catch (Exception e) {
|
||||
log.error("FMP 新闻同步异常: {}", e.getMessage(), e);
|
||||
log.error("德国新闻数据同步异常,异常信息: {}", e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
// @Scheduled(cron = "0 0 0/3 * * ?")
|
||||
@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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -57,11 +57,11 @@ public class JobBoot {
|
||||
/*
|
||||
* 新闻资讯抓取
|
||||
* */
|
||||
// @Scheduled(cron = "0 0/30 9-20 * * ?")
|
||||
// public void newsInfoTask() {
|
||||
// MdcUtil.setTraceIdIfAbsent();
|
||||
// Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
// int count = SiteNewsService.of().grabNews();
|
||||
// log.info("newsInfoTask执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
|
||||
// }
|
||||
@Scheduled(cron = "0 0/30 9-20 * * ?")
|
||||
public void newsInfoTask() {
|
||||
MdcUtil.setTraceIdIfAbsent();
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
int count = SiteNewsService.of().grabNews();
|
||||
log.info("newsInfoTask执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +1,70 @@
|
||||
package cn.stock.market.infrastructure.redis.config;
|
||||
|
||||
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.RedisPassword;
|
||||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(RedisProperties.class)
|
||||
public class RedisConfig {
|
||||
|
||||
private RedisProperties redisProperties;
|
||||
|
||||
public RedisConfig(RedisProperties redisProperties) {
|
||||
this.redisProperties = redisProperties;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RedisConnectionFactory redisConnectionFactory() {
|
||||
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
|
||||
config.setHostName(redisProperties.getHost());
|
||||
config.setPort(redisProperties.getPort());
|
||||
config.setDatabase(redisProperties.getDatabase());
|
||||
|
||||
if (redisProperties.getPassword() != null) {
|
||||
config.setPassword(RedisPassword.of(redisProperties.getPassword()));
|
||||
}
|
||||
|
||||
return new LettuceConnectionFactory(config);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory connectionFactory) {
|
||||
RedisTemplate<String, String> template = new RedisTemplate<>();
|
||||
template.setConnectionFactory(connectionFactory);
|
||||
|
||||
StringRedisSerializer serializer = new StringRedisSerializer();
|
||||
template.setKeySerializer(serializer);
|
||||
template.setValueSerializer(serializer);
|
||||
template.setHashKeySerializer(serializer);
|
||||
template.setHashValueSerializer(serializer);
|
||||
|
||||
template.afterPropertiesSet();
|
||||
return template;
|
||||
}
|
||||
}
|
||||
//package cn.stock.market.infrastructure.redis.config;
|
||||
//
|
||||
//import java.time.Duration;
|
||||
//
|
||||
//import org.redisson.api.RedissonClient;
|
||||
//import org.springframework.cache.CacheManager;
|
||||
//import org.springframework.cache.annotation.EnableCaching;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||
//import org.springframework.data.redis.cache.RedisCacheManager;
|
||||
//import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
//import org.springframework.data.redis.core.RedisTemplate;
|
||||
//import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
//import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||
//import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
//
|
||||
//import cn.qutaojing.common.aop.distributedlock.DistributedLockTemplate;
|
||||
//import cn.stock.market.infrastructure.redis.SingleDistributedLockTemplate;
|
||||
//
|
||||
///**
|
||||
// *
|
||||
// * @author xlfd
|
||||
// * @email xlfd@gmail.com
|
||||
// * @version 1.0
|
||||
// * @created Jun 3, 2021 4:56:28 PM
|
||||
// */
|
||||
//@Configuration
|
||||
//@EnableCaching
|
||||
//public class RedisConfig {
|
||||
//
|
||||
// @Bean
|
||||
// public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
||||
// RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();
|
||||
// redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||
// redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<>(Object.class));
|
||||
// redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
//
|
||||
// redisTemplate.setHashValueSerializer(new Jackson2JsonRedisSerializer<>(Object.class));
|
||||
// redisTemplate.setHashKeySerializer(new StringRedisSerializer());
|
||||
//
|
||||
// return redisTemplate;
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
|
||||
// // 配置序列化
|
||||
// RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig();
|
||||
// config.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()));
|
||||
// config.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new Jackson2JsonRedisSerializer<>(Object.class)));
|
||||
//
|
||||
// // 设置缓存的默认过期时间 ,30分钟
|
||||
// config.entryTtl(Duration.ofMinutes(30));
|
||||
// // 不缓存空值
|
||||
// config.disableCachingNullValues();
|
||||
// RedisCacheManager cacheManager = RedisCacheManager.builder(redisConnectionFactory).cacheDefaults(config)
|
||||
// .build();
|
||||
// return cacheManager;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 分布式锁实现
|
||||
// * @param redissonClient
|
||||
// * @return
|
||||
// */
|
||||
// @Bean
|
||||
// public DistributedLockTemplate distributedLockTemplate(RedissonClient redissonClient) {
|
||||
// return new SingleDistributedLockTemplate(redissonClient);
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class SiteNewsController {
|
||||
@RequestParam(value = "type", defaultValue = "0") Integer type,
|
||||
@RequestParam(value = "sort", defaultValue = "time1") String sort,
|
||||
@RequestParam(value = "keyword", required = false) String keyword, HttpServletRequest request) {
|
||||
return this.iSiteNewsService.getLatestStockNews(pageNum);
|
||||
return this.iSiteNewsService.getList(pageNum, pageSize, type, sort, keyword, request);
|
||||
}
|
||||
|
||||
//新闻资讯-详情
|
||||
|
||||
@@ -13,7 +13,6 @@ import cn.qutaojing.common.PageParam;
|
||||
import cn.qutaojing.common.jpa.ConditionBuilder;
|
||||
import cn.stock.market.domain.basic.entity.SiteNews;
|
||||
import cn.stock.market.domain.basic.repository.SiteNewsRepository;
|
||||
import cn.stock.market.domain.basic.service.SiteNewsService;
|
||||
import cn.stock.market.infrastructure.db.po.QSiteNewsPO;
|
||||
import cn.stock.market.infrastructure.job.InvestingTask;
|
||||
import cn.stock.market.web.annotations.EncryptFilter;
|
||||
@@ -73,8 +72,6 @@ public class StockApiController {
|
||||
StockService stockService;
|
||||
@Autowired
|
||||
SiteNewsRepository newsRepository;
|
||||
@Autowired
|
||||
SiteNewsService siteNewsService;
|
||||
|
||||
@RequestMapping({"getRawSinaStock.do"})
|
||||
@ResponseBody
|
||||
@@ -170,7 +167,7 @@ public class StockApiController {
|
||||
@ApiOperation(value = "印度新闻列表", httpMethod = "GET")
|
||||
@ResponseBody
|
||||
public ServerResponse getINDNews(@RequestParam("pageSize") Integer pageSize, @RequestParam("pageNum") Integer pageNum) {
|
||||
return siteNewsService.getLatestStockNews(pageNum);
|
||||
return ServerResponse.createBySuccess(newsRepository.findAll(ConditionBuilder.builder().build(), PageParam.of(pageNum, pageSize), QSiteNewsPO.siteNewsPO.showTime.desc()));
|
||||
}
|
||||
|
||||
@RequestMapping({"test.do"})
|
||||
@@ -247,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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import cn.stock.market.domain.basic.repository.StockRepository;
|
||||
import cn.stock.market.dto.*;
|
||||
import cn.stock.market.infrastructure.db.po.QStockPO;
|
||||
import cn.stock.market.web.config.Config;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpEntity;
|
||||
@@ -16,7 +15,8 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@@ -172,7 +172,6 @@ public class MoneyApiService {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
public List<StockQuoteData> getTopStocksFromTradingView(String sortOrder) {
|
||||
String url = "https://scanner.tradingview.com/germany/scan";
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
spring:
|
||||
jpa:
|
||||
show-sql: true
|
||||
|
||||
# Redis配置
|
||||
redis:
|
||||
host: 43.165.126.173
|
||||
host: 167.235.39.59
|
||||
password: a5v8b86P4mVzFlUqJV
|
||||
port: 6379
|
||||
port: 47379
|
||||
database: 1
|
||||
lettuce:
|
||||
pool:
|
||||
@@ -17,7 +18,7 @@ spring:
|
||||
datasource:
|
||||
stock-market:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://use-cdb-45wol5su.sql.tencentcdb.com:22490/stock-api?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: 6QJXv8dA76klnqsWh6f
|
||||
maxActive: 500
|
||||
|
||||
Reference in New Issue
Block a user