fix cron
This commit is contained in:
@@ -5,6 +5,7 @@ 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;
|
||||||
|
|
||||||
@@ -39,23 +40,26 @@ import net.sf.json.JSONObject;
|
|||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||||
public class SiteNewsService {
|
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();
|
||||||
query.setStatus(1);
|
query.setStatus(1);
|
||||||
query.setType(type);
|
query.setType(type);
|
||||||
query.setOrderSpecifier(sort);
|
query.setOrderSpecifier(sort);
|
||||||
query.setKeyword(keyword);
|
query.setKeyword(keyword);
|
||||||
Page<SiteNews> page = repository.findAll(query.where(), PageParam.of(pageNum, pageSize), query.orderSpecifier());
|
Page<SiteNews> page = repository.findAll(query.where(), PageParam.of(pageNum, pageSize), query.orderSpecifier());
|
||||||
|
|
||||||
return ServerResponse.createBySuccess(Utils.toPageHelperInfo(page));
|
return ServerResponse.createBySuccess(Utils.toPageHelperInfo(page));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*新闻资讯-查询详情*/
|
/*新闻资讯-查询详情*/
|
||||||
public ServerResponse getDetail(int id) {
|
public ServerResponse getDetail(int id) {
|
||||||
return ServerResponse.createBySuccess(repository.find(id));
|
return ServerResponse.createBySuccess(repository.find(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,48 +70,48 @@ public class SiteNewsService {
|
|||||||
|
|
||||||
/*新闻资讯-top最新新闻资讯*/
|
/*新闻资讯-top最新新闻资讯*/
|
||||||
public ServerResponse getTopNewsList(int pageSize){
|
public ServerResponse getTopNewsList(int pageSize){
|
||||||
SiteNewsQuery query = new SiteNewsQuery();
|
SiteNewsQuery query = new SiteNewsQuery();
|
||||||
query.setStatus(1);
|
query.setStatus(1);
|
||||||
|
|
||||||
List<SiteNews> list = repository.findAll(query.where(), pageSize, query.orderSpecifier());
|
List<SiteNews> list = repository.findAll(query.where(), pageSize, query.orderSpecifier());
|
||||||
|
|
||||||
PageInfo pageInfo = new PageInfo();
|
PageInfo pageInfo = new PageInfo();
|
||||||
pageInfo.setList(list);
|
pageInfo.setList(list);
|
||||||
return ServerResponse.createBySuccess(pageInfo);
|
return ServerResponse.createBySuccess(pageInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*新闻资讯-抓取*/
|
/*新闻资讯-抓取*/
|
||||||
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, PropertiesUtil.getProperty("news.main.url") + "/pc_news/FastNews/GetImportantNewsList");
|
ret = addNews(1, mainUrl + "/pc_news/FastNews/GetImportantNewsList");
|
||||||
log.info("财经要闻-抓取条数:" + ret);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
log.info("全球央行-抓取条数:" + ret);
|
||||||
|
|
||||||
return 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){
|
private int addNews(Integer type, String url){
|
||||||
int k = 0;
|
int k = 0;
|
||||||
try {
|
try {
|
||||||
@@ -124,7 +128,7 @@ public class SiteNewsService {
|
|||||||
//新闻不存在则添加
|
//新闻不存在则添加
|
||||||
if(repository.getNewsBySourceIdCount(newsId) == 0){
|
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.substring(1,newdata.length()-1).replace("\\\\\\\"","\"");
|
||||||
newdata = newdata.replace("\\\"","\"");
|
newdata = newdata.replace("\\\"","\"");
|
||||||
newdata = StringUtils.UnicodeToCN(newdata);
|
newdata = StringUtils.UnicodeToCN(newdata);
|
||||||
@@ -145,9 +149,9 @@ public class SiteNewsService {
|
|||||||
siteNews.setStatus(1);
|
siteNews.setStatus(1);
|
||||||
siteNews.setType(type);
|
siteNews.setType(type);
|
||||||
try {
|
try {
|
||||||
repository.saveAndFlush(siteNews);
|
repository.saveAndFlush(siteNews);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
log.warn("siteNewsMapper insert error: {}", e.getLocalizedMessage());
|
log.warn("siteNewsMapper insert error: {}", e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
@@ -159,12 +163,12 @@ public class SiteNewsService {
|
|||||||
}
|
}
|
||||||
return k;
|
return k;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SiteNewsRepository repository() {
|
|
||||||
return repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SiteNewsService of() {
|
public SiteNewsRepository repository() {
|
||||||
return SpringUtils.getBean(SiteNewsService.class);
|
return repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SiteNewsService of() {
|
||||||
|
return SpringUtils.getBean(SiteNewsService.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ 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;
|
||||||
|
|
||||||
@@ -12,21 +13,29 @@ 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表达式定义:
|
||||||
字段 允许值 允许的特殊字符
|
字段 允许值 允许的特殊字符
|
||||||
秒 0-59 , - * /
|
秒 0-59 , - * /
|
||||||
分 0-59 , - * /
|
分 0-59 , - * /
|
||||||
小时 0-23 , - * /
|
小时 0-23 , - * /
|
||||||
日期 1-31 , - * ? / L W C
|
日期 1-31 , - * ? / L W C
|
||||||
月份 1-12 或者 JAN-DEC , - * /
|
月份 1-12 或者 JAN-DEC , - * /
|
||||||
星期 1-7 或者 SUN-SAT , - * ? / L C #
|
星期 1-7 或者 SUN-SAT , - * ? / L C #
|
||||||
年(可选) 留空, 1970-2099 , - * /
|
年(可选) 留空, 1970-2099 , - * /
|
||||||
|
|
||||||
https://blog.csdn.net/ClementAD/article/details/42042111
|
https://blog.csdn.net/ClementAD/article/details/42042111
|
||||||
*/
|
*/
|
||||||
// @Scheduled(cron="0 0/1 * * * ? ")
|
// @Scheduled(cron="0 0/1 * * * ? ")
|
||||||
@Scheduled(cron="0/30 * * * * ? ")
|
@Scheduled(cron="0/30 * * * * ? ")
|
||||||
@@ -35,33 +44,33 @@ public class JobBoot {
|
|||||||
// Stopwatch stopwatch = Stopwatch.createStarted();
|
// Stopwatch stopwatch = Stopwatch.createStarted();
|
||||||
// log.info("batchStockTrust执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
|
// log.info("batchStockTrust执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(cron="0/30 * * * * ? ")
|
@Scheduled(cron="0/30 * * * * ? ")
|
||||||
public void batchStockPosition() {
|
public void batchStockPosition() {
|
||||||
MdcUtil.setTraceIdIfAbsent();
|
MdcUtil.setTraceIdIfAbsent();
|
||||||
// Stopwatch stopwatch = Stopwatch.createStarted();
|
// Stopwatch stopwatch = Stopwatch.createStarted();
|
||||||
// log.info("batchStockPosition执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
|
// log.info("batchStockPosition执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 新闻资讯抓取
|
* 新闻资讯抓取
|
||||||
* */
|
* */
|
||||||
@Scheduled(cron = "0 0/30 9-20 * * ?")
|
@Scheduled(cron = "0 0/30 9-20 * * ?")
|
||||||
public void artInfoTask() {
|
public void artInfoTask() {
|
||||||
MdcUtil.setTraceIdIfAbsent();
|
MdcUtil.setTraceIdIfAbsent();
|
||||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||||
int count = SiteArticleService.of().grabArticle();
|
int count = siteArticleService.grabArticle();
|
||||||
log.info("artInfoTask执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
|
log.info("artInfoTask执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 新闻资讯抓取
|
* 新闻资讯抓取
|
||||||
* */
|
* */
|
||||||
@Scheduled(cron = "0 0/30 9-20 * * ?")
|
@Scheduled(cron = "0 0/30 9-20 * * ?")
|
||||||
public void newsInfoTask() {
|
public void newsInfoTask() {
|
||||||
MdcUtil.setTraceIdIfAbsent();
|
MdcUtil.setTraceIdIfAbsent();
|
||||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||||
int count = SiteNewsService.of().grabNews();
|
int count = siteNewsService.grabNews();
|
||||||
log.info("newsInfoTask执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
|
log.info("newsInfoTask执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.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
|
username: root
|
||||||
password: uNejHIFQGJOUtYTmE
|
password: uNejHIFQGJOUtYTmE
|
||||||
maxActive: 500
|
maxActive: 500
|
||||||
@@ -36,7 +36,7 @@ spring:
|
|||||||
validationQuery: SELECT 1
|
validationQuery: SELECT 1
|
||||||
timeBetweenEvictionRunsMillis: 6000
|
timeBetweenEvictionRunsMillis: 6000
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
|
|
||||||
ig507Licence: 4CEF3CDC-3A2E-76AB-9BF1-BE856F3D4468
|
ig507Licence: 4CEF3CDC-3A2E-76AB-9BF1-BE856F3D4468
|
||||||
gugudataAppKey: K5LZKV8KAYM4
|
gugudataAppKey: K5LZKV8KAYM4
|
||||||
aliyunAccessKeyId: LTAI5tJi2z8cegG8fTW7BSQu
|
aliyunAccessKeyId: LTAI5tJi2z8cegG8fTW7BSQu
|
||||||
|
|||||||
Reference in New Issue
Block a user