Merge branch 'develop' into 'main'
Develop See merge request india/india_market_java!6
This commit is contained in:
@@ -945,8 +945,10 @@ public class StockService {
|
||||
market.setName("BSESENSEX指数");
|
||||
vo1.setIndexVo(market);
|
||||
|
||||
String type = "min";
|
||||
List<JSONObject> list = InvestingApis.of().kline(StockCode.of(stockCode), type);
|
||||
String period = "P1D";
|
||||
String interval = "PT5M";
|
||||
String type = "day";
|
||||
List<JSONObject> list = InvestingApis.of().kIndex(stockCode,period,interval, type);
|
||||
if(list == null || list.size() == 0){
|
||||
type = "day";
|
||||
list = InvestingApis.of().kline(StockCode.of(stockCode), type);
|
||||
@@ -958,13 +960,15 @@ public class StockService {
|
||||
}
|
||||
try {
|
||||
IndiaIndexVo vo2 = new IndiaIndexVo();
|
||||
String stockCode = "8985"; //"17940";
|
||||
String stockCode = "17940"; //"17940";8985
|
||||
IndiaStockVO market = InvestingApis.of().market(StockCode.of(stockCode));
|
||||
market.setName("NIFTY50指数");
|
||||
vo2.setIndexVo(market);
|
||||
|
||||
String type = "min";
|
||||
List<JSONObject> list = InvestingApis.of().kline(StockCode.of(stockCode), type);
|
||||
String period = "P1D";
|
||||
String interval = "PT1M";
|
||||
String type = "day";
|
||||
List<JSONObject> list = InvestingApis.of().kIndex(stockCode,period,interval, type);
|
||||
if(list == null || list.size() == 0){
|
||||
type = "day";
|
||||
list = InvestingApis.of().kline(StockCode.of(stockCode), type);
|
||||
|
||||
@@ -153,7 +153,6 @@ public class InvestingApis {
|
||||
"Time": "1698055197",
|
||||
"Url": "/equities/aditya-birla",
|
||||
"Volume": 3693615
|
||||
* @param httpClient
|
||||
* @param currPage
|
||||
* @param pageSize
|
||||
* @return
|
||||
@@ -252,6 +251,34 @@ public class InvestingApis {
|
||||
.collect(Collectors.toList())
|
||||
;
|
||||
}
|
||||
public List<JSONObject> kIndex(String code,String period, String interval,String type) throws IOException {
|
||||
if(code == null) {
|
||||
throw new RuntimeException("找不到股票信息");
|
||||
}
|
||||
Date nowDate = new Date();
|
||||
JSONObject json = InvestingInvokerApis.of().__IndiaIndex(code, period,interval);
|
||||
return json
|
||||
.getJSONArray("data")
|
||||
.stream()
|
||||
.map(val -> {
|
||||
JSONArray _ar = (JSONArray) val;
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("date", _ar.get(0));
|
||||
item.put("open", _ar.get(1));
|
||||
item.put("high", _ar.get(2));
|
||||
item.put("low", _ar.get(3));
|
||||
item.put("close", _ar.get(4));
|
||||
item.put("volume", _ar.get(5));
|
||||
return item;
|
||||
}).filter(val -> {
|
||||
if("day".equalsIgnoreCase(type)) {
|
||||
return DateUtil.isSameDay(nowDate, new Date(val.getLong("date")));
|
||||
}
|
||||
return true;
|
||||
})
|
||||
.collect(Collectors.toList())
|
||||
;
|
||||
}
|
||||
|
||||
public static InvestingApis of() {
|
||||
return new InvestingApis();
|
||||
|
||||
@@ -202,6 +202,15 @@ public class InvestingInvokerApis {
|
||||
return JSON.parseObject(body);
|
||||
}
|
||||
|
||||
public JSONObject __IndiaIndex(String code,String period, String interval)throws IOException {
|
||||
String tmpl = "https://api.investing.com/api/financialdata/{}/historical/chart/?period={}&interval={}&pointscount=160";
|
||||
String url = StrFormatter.format(tmpl, code, period, interval);
|
||||
Builder builder = builderGet(url);
|
||||
|
||||
String body = httpClient().newCall(builder.build()).execute().body().string();
|
||||
return JSON.parseObject(body);
|
||||
}
|
||||
|
||||
public static InvestingInvokerApis of() {
|
||||
return new InvestingInvokerApis();
|
||||
}
|
||||
|
||||
@@ -71,4 +71,10 @@ public class BtodayStockPO {
|
||||
/**
|
||||
* 上次更新时间 */
|
||||
Date lastUpdateTime;
|
||||
|
||||
/** 是否锁定 0否 1是 */
|
||||
Integer isLock;
|
||||
|
||||
/** 是否展示 0是 1否 */
|
||||
Integer isShow;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -49,6 +50,7 @@ public class MoneyScraper {
|
||||
private MoneyStockRepository moneyStockRepository;
|
||||
|
||||
@GetMapping("testScraperGetMoneyControlStock")
|
||||
@Scheduled(cron = "0 0 2 */2 * ?")
|
||||
public void schedule(){
|
||||
List<String> letters = new ArrayList<>();
|
||||
for (char c = 'A'; c <= 'Z'; c++) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package cn.stock.market.infrastructure.job;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.stock.market.domain.basic.entity.BtodayStock;
|
||||
import cn.stock.market.domain.basic.entity.StockIpo;
|
||||
import cn.stock.market.domain.basic.repository.BtodayStockRepository;
|
||||
@@ -151,7 +152,7 @@ public class Scraper {
|
||||
stockIpo.setApply(entry.getString("total_subs"));
|
||||
stockIpo.setCreateDate(new Date());
|
||||
stockIpo.setUpdateDate(new Date());
|
||||
stockIpo.setSourceType("2");
|
||||
stockIpo.setSourceType("3");
|
||||
listStockIpoList.add(stockIpo);
|
||||
}
|
||||
|
||||
@@ -173,17 +174,23 @@ public class Scraper {
|
||||
|
||||
// stockIpoRepository.saveAll(listStockIpoList);
|
||||
|
||||
List<String> nameList = Lists.transform(listStockIpoList, StockIpo::getStockName);
|
||||
List<StockIpo> existStockIpoList = stockIpoRepository.findAll(QStockIpoPO.stockIpoPO.stockName.in(nameList));
|
||||
List<String> existingStockNames = existStockIpoList.stream()
|
||||
.map(StockIpo::getStockName)
|
||||
List<String> scIdList = Lists.transform(listStockIpoList, StockIpo::getStockCode);
|
||||
if(CollectionUtil.isNotEmpty(scIdList)){
|
||||
List<StockIpo> existStockIpoList = stockIpoRepository.findAll(QStockIpoPO.stockIpoPO.stockCode.in(scIdList));
|
||||
List<String> existingStockScIds = existStockIpoList.stream()
|
||||
.map(StockIpo::getStockCode)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
listStockIpoList = listStockIpoList.stream()
|
||||
.filter(stockIpos -> !existingStockNames.contains(stockIpos.getStockName()))
|
||||
.filter(stockIpos -> !existingStockScIds.contains(stockIpos.getStockCode()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
//保存全部的新股
|
||||
if(CollectionUtil.isNotEmpty(listStockIpoList)){
|
||||
stockIpoRepository.saveAll(listStockIpoList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 输出整个 JSON 数据
|
||||
} else {
|
||||
@@ -257,6 +264,8 @@ public class Scraper {
|
||||
btodayStock.setSelfUrl(url);
|
||||
btodayStock.setUrl(detailUrl);
|
||||
btodayStock.setLastUpdateTime(new Date());
|
||||
btodayStock.setIsLock(0);
|
||||
btodayStock.setIsShow(0);
|
||||
btodayStockRepo.save(btodayStock);
|
||||
|
||||
/* if (webInfo != null) {
|
||||
|
||||
@@ -744,17 +744,17 @@ public class MoneyApiController {
|
||||
|
||||
private Cache<String, List<MoneyStockSuggestDTO>> gainerStockSuggestCache = CacheBuilder.newBuilder()
|
||||
.maximumSize(100) // 设置缓存的最大大小
|
||||
.expireAfterWrite(1, TimeUnit.HOURS) // 设置缓存条目的过期时间
|
||||
.expireAfterWrite(1, TimeUnit.MINUTES) // 设置缓存条目的过期时间
|
||||
.build();
|
||||
|
||||
private Cache<String, List<MoneyStockSuggestDTO>> loserStockSuggestCache = CacheBuilder.newBuilder()
|
||||
.maximumSize(100) // 设置缓存的最大大小
|
||||
.expireAfterWrite(1, TimeUnit.HOURS) // 设置缓存条目的过期时间
|
||||
.expireAfterWrite(1, TimeUnit.MINUTES) // 设置缓存条目的过期时间
|
||||
.build();
|
||||
|
||||
private Cache<String, List<MoneyStockSuggestDTO>> activesStockSuggestCache = CacheBuilder.newBuilder()
|
||||
.maximumSize(100) // 设置缓存的最大大小
|
||||
.expireAfterWrite(30, TimeUnit.MINUTES) // 设置缓存条目的过期时间
|
||||
.expireAfterWrite(1, TimeUnit.MINUTES) // 设置缓存条目的过期时间
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
@@ -167,6 +167,34 @@ public class StockApiController {
|
||||
return ServerResponse.createBySuccess(newsRepository.findAll(ConditionBuilder.builder().build(), PageParam.of(pageNum, pageSize), QSiteNewsPO.siteNewsPO.id.desc()));
|
||||
}
|
||||
|
||||
@RequestMapping({"test.do"})
|
||||
@ResponseBody
|
||||
public ServerResponse test(@RequestParam("url") String url, @RequestParam("pageNum") Integer pageNum) {
|
||||
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);
|
||||
|
||||
SiteNews siteNews = new SiteNews();
|
||||
siteNews.setAddTime(new Date());
|
||||
siteNews.setSourceId(id);
|
||||
siteNews.setDescription(time);
|
||||
siteNews.setImgurl(imgUrl);
|
||||
List<String> newsInfo = stockService.getNewsInfo(contentUrl);
|
||||
siteNews.setContent(newsInfo.get(0));
|
||||
siteNews.setTitle(newsInfo.get(1));
|
||||
List<SiteNews> list = newsRepository.findAll(QSiteNewsPO.siteNewsPO.sourceId.eq(id));
|
||||
if (list.size() == 0) {
|
||||
newsRepository.save(siteNews);
|
||||
}
|
||||
});
|
||||
return ServerResponse.createBySuccess();
|
||||
}
|
||||
|
||||
//印度股票时线-K线
|
||||
@RequestMapping({"getINDTimeK.do"})
|
||||
@ApiOperation(value = "印度股票K线", httpMethod = "GET")
|
||||
|
||||
Reference in New Issue
Block a user