This commit is contained in:
VoGiaHuy2058
2025-05-12 18:44:16 +07:00
parent 59684cccfc
commit 85094c22b2
3 changed files with 87 additions and 74 deletions

View File

@@ -5,6 +5,7 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
@@ -42,6 +43,9 @@ public class SiteNewsService {
final SiteNewsRepository repository;
final SiteNewsFactory factory;
@Value("${news.main.url}")
private String mainUrl;
/*新闻资讯-查询列表*/
public ServerResponse<PageInfo> getList(int pageNum, int pageSize, Integer type, String sort, String keyword, HttpServletRequest request){
SiteNewsQuery query = new SiteNewsQuery();
@@ -80,25 +84,25 @@ public class SiteNewsService {
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");
ret = addNews(1, mainUrl + "/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=");
ret = addNews(2, mainUrl + "/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=");
ret = addNews(3, mainUrl + "/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=");
ret = addNews(4, mainUrl + "/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=");
ret = addNews(5, mainUrl + "/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=");
ret = addNews(6, mainUrl + "/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=");
ret = addNews(7, mainUrl + "/pc_news/FastNews/GetInfoList?code=118&pageNumber=1&pagesize=20&condition=&r=");
log.info("全球央行-抓取条数:" + ret);
return ret;
@@ -124,7 +128,7 @@ public class SiteNewsService {
//新闻不存在则添加
if(repository.getNewsBySourceIdCount(newsId) == 0){
//获取新闻详情
String newdata = HttpRequest.doGrabGet(PropertiesUtil.getProperty("news.main.url") + "/PC_News/Detail/GetDetailContent?id="+ newsId +"&type=1");
String newdata = HttpRequest.doGrabGet(mainUrl + "/PC_News/Detail/GetDetailContent?id="+ newsId +"&type=1");
newdata = newdata.substring(1,newdata.length()-1).replace("\\\\\\\"","\"");
newdata = newdata.replace("\\\"","\"");
newdata = StringUtils.UnicodeToCN(newdata);

View File

@@ -2,6 +2,7 @@ package cn.stock.market.infrastructure.job;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -12,9 +13,17 @@ import cn.stock.market.domain.basic.service.SiteArticleService;
import cn.stock.market.domain.basic.service.SiteNewsService;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.PostConstruct;
@Slf4j
//@Component
@Component
public class JobBoot {
@Autowired
private SiteNewsService siteNewsService;
@Autowired
private SiteArticleService siteArticleService;
/**
* cronExpression表达式定义 
字段   允许值   允许的特殊字符
@@ -50,7 +59,7 @@ public class JobBoot {
public void artInfoTask() {
MdcUtil.setTraceIdIfAbsent();
Stopwatch stopwatch = Stopwatch.createStarted();
int count = SiteArticleService.of().grabArticle();
int count = siteArticleService.grabArticle();
log.info("artInfoTask执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
}
@@ -61,7 +70,7 @@ public class JobBoot {
public void newsInfoTask() {
MdcUtil.setTraceIdIfAbsent();
Stopwatch stopwatch = Stopwatch.createStarted();
int count = SiteNewsService.of().grabNews();
int count = siteNewsService.grabNews();
log.info("newsInfoTask执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
}
}

View File

@@ -17,7 +17,7 @@ spring:
datasource:
stock-market:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://43.156.40.39:30030/india_stock?useUnicode=true&characterEncoding=utf-8
url: jdbc:mysql://43.153.174.179:30000/india_stock?useUnicode=true&characterEncoding=utf-8
username: root
password: uNejHIFQGJOUtYTmE
maxActive: 500