Merge branch 'develop' into 'main'

Develop

See merge request india/india_market_java!2
This commit is contained in:
rplees
2024-01-03 12:00:31 +00:00
3 changed files with 67 additions and 27 deletions

View File

@@ -1,8 +1,12 @@
package cn.stock.market.infrastructure.job; package cn.stock.market.infrastructure.job;
import cn.stock.market.domain.basic.entity.SiteNews;
import cn.stock.market.domain.basic.entity.Stock; import cn.stock.market.domain.basic.entity.Stock;
import cn.stock.market.domain.basic.repository.SiteNewsRepository;
import cn.stock.market.domain.basic.repository.StockRepository; import cn.stock.market.domain.basic.repository.StockRepository;
import cn.stock.market.domain.basic.service.StockService;
import cn.stock.market.infrastructure.api.investing.InvestingInvokerApis; import cn.stock.market.infrastructure.api.investing.InvestingInvokerApis;
import cn.stock.market.infrastructure.db.po.QSiteNewsPO;
import cn.stock.market.utils.Utils; import cn.stock.market.utils.Utils;
import com.ag.utils.CollectionUtils; import com.ag.utils.CollectionUtils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
@@ -11,10 +15,12 @@ import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Stopwatch; import com.google.common.base.Stopwatch;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
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;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -24,6 +30,11 @@ import java.util.concurrent.TimeUnit;
@Component @Component
public class InvestingTask { public class InvestingTask {
@Autowired
StockService stockService;
@Autowired
SiteNewsRepository newsRepository;
// @Scheduled(cron = "0 0 6 * * ?") // @Scheduled(cron = "0 0 6 * * ?")
public void syncIndiaData(){ public void syncIndiaData(){
log.info("同步股票数据开始。。。。"); log.info("同步股票数据开始。。。。");
@@ -94,4 +105,32 @@ public class InvestingTask {
} }
} }
/*新闻接口*/
@Scheduled(cron = "0 0 1 * * ?")
public void saveStockNews() {
String news = stockService.getNews();
List<String> newsList = Arrays.asList(news.split("<a href="));
newsList = newsList.subList(1, newsList.size());
newsList.forEach( n -> {
String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2);
String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_"));
String imgUrl = n.substring(n.indexOf("img src=") + 9, n.indexOf("?"));
String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9);
String title = n.substring(n.indexOf("html\">") + 6, n.indexOf("<div class=\"short-video-img\">") - 47);
SiteNews siteNews = new SiteNews();
siteNews.setAddTime(new Date());
siteNews.setSourceId(id);
siteNews.setTitle(title);
siteNews.setDescription(time);
siteNews.setImgurl(imgUrl);
siteNews.setContent(stockService.getNewsInfo(contentUrl));
List<SiteNews> list = newsRepository.findAll(QSiteNewsPO.siteNewsPO.sourceId.eq(id));
if (list.size() == 0) {
newsRepository.save(siteNews);
}
});
}
} }

View File

@@ -349,30 +349,30 @@ public class StockTask {
// } // }
/*新闻接口*/ /*新闻接口*/
@Scheduled(cron = "0 0 1 * * ?") //@Scheduled(cron = "0 0 1 * * ?")
public void saveStockNews() { //@Scheduled(cron = "*/5 * * * * ?")
String news = stockService.getNews(); //public void saveStockNews() {
List<String> newsList = Arrays.asList(news.split("<a href=")); // String news = stockService.getNews();
newsList = newsList.subList(1, newsList.size()); // List<String> newsList = Arrays.asList(news.split("<a href="));
newsList.forEach( n -> { // newsList = newsList.subList(1, newsList.size());
String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2); // newsList.forEach( n -> {
String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_")); // String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2);
String imgUrl = n.substring(n.indexOf("img src=") + 9, n.indexOf("?")); // String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_"));
String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9); // String imgUrl = n.substring(n.indexOf("img src=") + 9, n.indexOf("?"));
String title = n.substring(n.indexOf("html\">") + 6, n.indexOf("<div class=\"short-video-img\">") - 47); // String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9);
// String title = n.substring(n.indexOf("html\">") + 6, n.indexOf("<div class=\"short-video-img\">") - 47);
SiteNews siteNews = new SiteNews(); //
siteNews.setAddTime(new Date()); // SiteNews siteNews = new SiteNews();
siteNews.setSourceId(id); // siteNews.setAddTime(new Date());
siteNews.setTitle(title); // siteNews.setSourceId(id);
siteNews.setDescription(time); // siteNews.setTitle(title);
siteNews.setImgurl(imgUrl); // siteNews.setDescription(time);
siteNews.setContent(stockService.getNewsInfo(contentUrl)); // siteNews.setImgurl(imgUrl);
List<SiteNews> list = newsRepository.findAll(QSiteNewsPO.siteNewsPO.sourceId.eq(id)); // siteNews.setContent(stockService.getNewsInfo(contentUrl));
if (list.size() == 0) { // List<SiteNews> list = newsRepository.findAll(QSiteNewsPO.siteNewsPO.sourceId.eq(id));
newsRepository.save(siteNews); // if (list.size() == 0) {
} // newsRepository.save(siteNews);
}); // }
// });
} //}
} }

View File

@@ -8,6 +8,7 @@ import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import cn.qutaojing.common.PageParam; 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.entity.SiteNews;
import cn.stock.market.domain.basic.repository.SiteNewsRepository; import cn.stock.market.domain.basic.repository.SiteNewsRepository;
import cn.stock.market.infrastructure.db.po.QSiteNewsPO; import cn.stock.market.infrastructure.db.po.QSiteNewsPO;
@@ -163,7 +164,7 @@ public class StockApiController {
@ApiOperation(value = "印度新闻列表", httpMethod = "GET") @ApiOperation(value = "印度新闻列表", httpMethod = "GET")
@ResponseBody @ResponseBody
public ServerResponse getINDNews(@RequestParam("pageSize") Integer pageSize, @RequestParam("pageNum") Integer pageNum) { public ServerResponse getINDNews(@RequestParam("pageSize") Integer pageSize, @RequestParam("pageNum") Integer pageNum) {
return ServerResponse.createBySuccess(newsRepository.findAll(PageParam.of(pageNum, pageSize))); return ServerResponse.createBySuccess(newsRepository.findAll(ConditionBuilder.builder().build(), PageParam.of(pageNum, pageSize), QSiteNewsPO.siteNewsPO.id.desc()));
} }
//印度股票时线-K线 //印度股票时线-K线