Revert "fix cron"

This reverts commit 85094c22b2.
This commit is contained in:
VoGiaHuy2058
2025-05-12 18:53:06 +07:00
parent 85094c22b2
commit c72c0ff4cd
3 changed files with 74 additions and 87 deletions

View File

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

View File

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

View File

@@ -17,7 +17,7 @@ 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://43.153.174.179:30000/india_stock?useUnicode=true&characterEncoding=utf-8 url: jdbc:mysql://43.156.40.39:30030/india_stock?useUnicode=true&characterEncoding=utf-8
username: root username: root
password: uNejHIFQGJOUtYTmE password: uNejHIFQGJOUtYTmE
maxActive: 500 maxActive: 500