From c72c0ff4cde72663872d21583937b9bcc7c9df40 Mon Sep 17 00:00:00 2001 From: VoGiaHuy2058 <39868777+vogiahuy2058@users.noreply.github.com> Date: Mon, 12 May 2025 18:53:06 +0700 Subject: [PATCH] Revert "fix cron" This reverts commit 85094c22b223a680795794b240f3feb9647200f9. --- .../domain/basic/service/SiteNewsService.java | 82 +++++++++---------- .../market/infrastructure/job/JobBoot.java | 75 ++++++++--------- src/main/resources/application-base-alpha.yml | 4 +- 3 files changed, 74 insertions(+), 87 deletions(-) diff --git a/src/main/java/cn/stock/market/domain/basic/service/SiteNewsService.java b/src/main/java/cn/stock/market/domain/basic/service/SiteNewsService.java index 0628f6f..08d39db 100644 --- a/src/main/java/cn/stock/market/domain/basic/service/SiteNewsService.java +++ b/src/main/java/cn/stock/market/domain/basic/service/SiteNewsService.java @@ -5,7 +5,6 @@ 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; @@ -40,26 +39,23 @@ import net.sf.json.JSONObject; @SuppressWarnings("rawtypes") @RequiredArgsConstructor(onConstructor = @__(@Autowired)) public class SiteNewsService { - final SiteNewsRepository repository; - final SiteNewsFactory factory; - - @Value("${news.main.url}") - private String mainUrl; - - /*新闻资讯-查询列表*/ + final SiteNewsRepository repository; + final SiteNewsFactory factory; + + /*新闻资讯-查询列表*/ public ServerResponse getList(int pageNum, int pageSize, Integer type, String sort, String keyword, HttpServletRequest request){ - SiteNewsQuery query = new SiteNewsQuery(); - query.setStatus(1); - query.setType(type); - query.setOrderSpecifier(sort); - query.setKeyword(keyword); - Page page = repository.findAll(query.where(), PageParam.of(pageNum, pageSize), query.orderSpecifier()); - + SiteNewsQuery query = new SiteNewsQuery(); + query.setStatus(1); + query.setType(type); + query.setOrderSpecifier(sort); + query.setKeyword(keyword); + Page page = repository.findAll(query.where(), PageParam.of(pageNum, pageSize), query.orderSpecifier()); + return ServerResponse.createBySuccess(Utils.toPageHelperInfo(page)); } /*新闻资讯-查询详情*/ - public ServerResponse getDetail(int id) { + public ServerResponse getDetail(int id) { return ServerResponse.createBySuccess(repository.find(id)); } @@ -70,48 +66,48 @@ public class SiteNewsService { /*新闻资讯-top最新新闻资讯*/ public ServerResponse getTopNewsList(int pageSize){ - SiteNewsQuery query = new SiteNewsQuery(); - query.setStatus(1); - - List list = repository.findAll(query.where(), pageSize, query.orderSpecifier()); - + SiteNewsQuery query = new SiteNewsQuery(); + query.setStatus(1); + + List list = repository.findAll(query.where(), pageSize, query.orderSpecifier()); + PageInfo pageInfo = new PageInfo(); pageInfo.setList(list); return ServerResponse.createBySuccess(pageInfo); } - - /*新闻资讯-抓取*/ + + /*新闻资讯-抓取*/ public int grabNews() { int ret = 0; //新闻类型: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); - 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); - 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); - 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); - 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); - 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); - 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); return ret; } /* - *抓取新闻专用 - * type:新闻类型:1、财经要闻,2、经济数据,3、全球股市,4、7*24全球,5、商品资讯,6、上市公司,7、全球央行 - * */ + *抓取新闻专用 + * type:新闻类型:1、财经要闻,2、经济数据,3、全球股市,4、7*24全球,5、商品资讯,6、上市公司,7、全球央行 + * */ private int addNews(Integer type, String url){ int k = 0; try { @@ -128,7 +124,7 @@ public class SiteNewsService { //新闻不存在则添加 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.replace("\\\"","\""); newdata = StringUtils.UnicodeToCN(newdata); @@ -149,9 +145,9 @@ public class SiteNewsService { siteNews.setStatus(1); siteNews.setType(type); try { - repository.saveAndFlush(siteNews); + repository.saveAndFlush(siteNews); } catch(Exception e) { - log.warn("siteNewsMapper insert error: {}", e.getLocalizedMessage()); + log.warn("siteNewsMapper insert error: {}", e.getLocalizedMessage()); } k++; } @@ -163,12 +159,12 @@ public class SiteNewsService { } return k; } + + public SiteNewsRepository repository() { + return repository; + } - public SiteNewsRepository repository() { - return repository; - } - - public static SiteNewsService of() { - return SpringUtils.getBean(SiteNewsService.class); - } + public static SiteNewsService of() { + return SpringUtils.getBean(SiteNewsService.class); + } } diff --git a/src/main/java/cn/stock/market/infrastructure/job/JobBoot.java b/src/main/java/cn/stock/market/infrastructure/job/JobBoot.java index fec3dbe..a3aa98f 100644 --- a/src/main/java/cn/stock/market/infrastructure/job/JobBoot.java +++ b/src/main/java/cn/stock/market/infrastructure/job/JobBoot.java @@ -2,7 +2,6 @@ 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; @@ -13,29 +12,21 @@ 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表达式定义:  - 字段   允许值   允许的特殊字符 - 秒   0-59   , - * / - 分   0-59   , - * / - 小时   0-23   , - * / - 日期   1-31   , - * ? / L W C - 月份   1-12 或者 JAN-DEC   , - * / - 星期   1-7 或者 SUN-SAT   , - * ? / L C # - 年(可选)   留空, 1970-2099   , - * / - - https://blog.csdn.net/ClementAD/article/details/42042111 + 字段   允许值   允许的特殊字符 + 秒   0-59   , - * / + 分   0-59   , - * / + 小时   0-23   , - * / + 日期   1-31   , - * ? / L W C + 月份   1-12 或者 JAN-DEC   , - * / + 星期   1-7 或者 SUN-SAT   , - * ? / L C # + 年(可选)   留空, 1970-2099   , - * / + + https://blog.csdn.net/ClementAD/article/details/42042111 */ // @Scheduled(cron="0 0/1 * * * ? ") @Scheduled(cron="0/30 * * * * ? ") @@ -44,33 +35,33 @@ public class JobBoot { // Stopwatch stopwatch = Stopwatch.createStarted(); // log.info("batchStockTrust执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS)); } - + @Scheduled(cron="0/30 * * * * ? ") public void batchStockPosition() { MdcUtil.setTraceIdIfAbsent(); // Stopwatch stopwatch = Stopwatch.createStarted(); // log.info("batchStockPosition执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS)); } - - /* - * 新闻资讯抓取 - * */ + + /* + * 新闻资讯抓取 + * */ @Scheduled(cron = "0 0/30 9-20 * * ?") - public void artInfoTask() { - MdcUtil.setTraceIdIfAbsent(); - Stopwatch stopwatch = Stopwatch.createStarted(); - int count = siteArticleService.grabArticle(); - log.info("artInfoTask执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS)); - } - - /* - * 新闻资讯抓取 - * */ - @Scheduled(cron = "0 0/30 9-20 * * ?") - public void newsInfoTask() { - MdcUtil.setTraceIdIfAbsent(); - Stopwatch stopwatch = Stopwatch.createStarted(); - int count = siteNewsService.grabNews(); - log.info("newsInfoTask执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS)); - } + public void artInfoTask() { + MdcUtil.setTraceIdIfAbsent(); + Stopwatch stopwatch = Stopwatch.createStarted(); + int count = SiteArticleService.of().grabArticle(); + log.info("artInfoTask执行, 受影响数{}, 耗时:{}毫秒", 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)); + } } diff --git a/src/main/resources/application-base-alpha.yml b/src/main/resources/application-base-alpha.yml index b92fe23..590859e 100644 --- a/src/main/resources/application-base-alpha.yml +++ b/src/main/resources/application-base-alpha.yml @@ -17,7 +17,7 @@ spring: datasource: stock-market: 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 password: uNejHIFQGJOUtYTmE maxActive: 500 @@ -36,7 +36,7 @@ spring: validationQuery: SELECT 1 timeBetweenEvictionRunsMillis: 6000 type: com.alibaba.druid.pool.DruidDataSource - + ig507Licence: 4CEF3CDC-3A2E-76AB-9BF1-BE856F3D4468 gugudataAppKey: K5LZKV8KAYM4 aliyunAccessKeyId: LTAI5tJi2z8cegG8fTW7BSQu