Compare commits
31 Commits
bug/update
...
huy-featur
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ef7b46038 | ||
|
|
9785a391a2 | ||
|
|
5b3504f32a | ||
|
|
f67af0d3e9 | ||
|
|
af21d583d9 | ||
|
|
cd06493b9c | ||
|
|
3255012fba | ||
|
|
476645109d | ||
|
|
66eccce4cb | ||
|
|
5ab279daa6 | ||
|
|
be24a57d2d | ||
|
|
aa796cf853 | ||
|
|
9a06979f07 | ||
|
|
d1f9600361 | ||
|
|
fcab660024 | ||
|
|
ad95848c2c | ||
|
|
90a26823f0 | ||
|
|
c72c0ff4cd | ||
|
|
85094c22b2 | ||
|
|
59684cccfc | ||
|
|
57690ecb5e | ||
|
|
8cf511f1b7 | ||
|
|
f612b5128e | ||
|
|
07a69f29b9 | ||
|
|
3e1ff24bb6 | ||
|
|
b26d3962c4 | ||
|
|
d085d8de12 | ||
|
|
0476ad100b | ||
|
|
f87df03715 | ||
|
|
fc59d1f47c | ||
|
|
6b5623dc33 |
@@ -4,6 +4,11 @@ stages:
|
|||||||
- dockerize
|
- dockerize
|
||||||
- deploy
|
- deploy
|
||||||
|
|
||||||
|
variables:
|
||||||
|
company_name: juyoutech
|
||||||
|
project_name: germany_stock
|
||||||
|
service_name: market
|
||||||
|
|
||||||
build:
|
build:
|
||||||
image: maven:3.6.3-openjdk-8
|
image: maven:3.6.3-openjdk-8
|
||||||
stage: build
|
stage: build
|
||||||
@@ -48,18 +53,22 @@ dockerize:
|
|||||||
- main
|
- main
|
||||||
- develop
|
- develop
|
||||||
script:
|
script:
|
||||||
- echo ">>>>>>Start Building Image<<<<<<"
|
- echo ">>>>>>Start Building Docker Image<<<<<<"
|
||||||
- ls
|
- pwd
|
||||||
- ls target
|
- ls -lah
|
||||||
- echo $DOCKER_PASSWORD
|
- echo $DOCKER_PASSWORD | docker login -u ${company_name} --password-stdin
|
||||||
- echo $CI_PIPELINE_ID
|
- docker build -t ${company_name}/${project_name}_${service_name} .
|
||||||
- docker build -t juyoutech/india_stock_market:latest .
|
|
||||||
- docker tag juyoutech/india_stock_market:latest juyoutech/india_stock_market:$CI_PIPELINE_ID
|
- docker push ${company_name}/${project_name}_${service_name}
|
||||||
- docker tag juyoutech/india_stock_market:latest juyoutech/india_stock_market:$CI_COMMIT_BRANCH
|
|
||||||
- docker login -u juyoutech -p dckr_pat_8rg23IBA2kZMOCX4IJKApb8m5l8
|
- docker tag ${company_name}/${project_name}_${service_name} ${company_name}/${project_name}_${service_name}:$CI_PIPELINE_ID
|
||||||
- docker push juyoutech/india_stock_market:latest
|
- docker push ${company_name}/${project_name}_${service_name}:$CI_PIPELINE_ID
|
||||||
- docker push juyoutech/india_stock_market:$CI_PIPELINE_ID
|
|
||||||
- docker push juyoutech/india_stock_market:$CI_COMMIT_BRANCH
|
- docker tag ${company_name}/${project_name}_${service_name} ${company_name}/${project_name}_${service_name}:$CI_COMMIT_BRANCH
|
||||||
|
- docker push ${company_name}/${project_name}_${service_name}:$CI_COMMIT_BRANCH
|
||||||
|
|
||||||
|
- echo ${company_name}/${project_name}_${service_name}:$CI_COMMIT_BRANCH
|
||||||
|
|
||||||
deploy-dev:
|
deploy-dev:
|
||||||
stage: deploy
|
stage: deploy
|
||||||
only:
|
only:
|
||||||
@@ -67,13 +76,13 @@ deploy-dev:
|
|||||||
script:
|
script:
|
||||||
- echo "Deploying application..."
|
- echo "Deploying application..."
|
||||||
- ls
|
- ls
|
||||||
- apt-get update
|
- apk update
|
||||||
- apt-get install -y curl
|
- apk add curl
|
||||||
- |
|
- |
|
||||||
curl -X POST \
|
curl -X POST \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{"namespace":"yddev", "deployment_name":"india-stock-market"}' \
|
-d '{"namespace":"dgdev", "deployment_name":"germany-stock-market"}' \
|
||||||
https://updater-yddev.moneytj.com/restart-deployment
|
https://updater-dgdev.moneytj.com/restart-deployment
|
||||||
- echo "Application successfully deployed."
|
- echo "Application successfully deployed."
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
6
pom.xml
6
pom.xml
@@ -89,6 +89,12 @@
|
|||||||
<version>4.1.0</version>
|
<version>4.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.json</groupId>
|
||||||
|
<artifactId>json</artifactId>
|
||||||
|
<version>20240303</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.springfox</groupId>
|
<groupId>io.springfox</groupId>
|
||||||
<artifactId>springfox-swagger2</artifactId>
|
<artifactId>springfox-swagger2</artifactId>
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ public class QMoneyStockPO extends EntityPathBase<MoneyStockPO> {
|
|||||||
|
|
||||||
public final StringPath moneyScId = createString("moneyScId");
|
public final StringPath moneyScId = createString("moneyScId");
|
||||||
|
|
||||||
|
public final StringPath nseIndiaChartId = createString("nseIndiaChartId");
|
||||||
|
|
||||||
|
public final StringPath nseIndiaId = createString("nseIndiaId");
|
||||||
|
|
||||||
public final DateTimePath<java.util.Date> saveTime = createDateTime("saveTime", java.util.Date.class);
|
public final DateTimePath<java.util.Date> saveTime = createDateTime("saveTime", java.util.Date.class);
|
||||||
|
|
||||||
public final StringPath selfDispId = createString("selfDispId");
|
public final StringPath selfDispId = createString("selfDispId");
|
||||||
@@ -39,6 +43,8 @@ public class QMoneyStockPO extends EntityPathBase<MoneyStockPO> {
|
|||||||
|
|
||||||
public final StringPath stockType = createString("stockType");
|
public final StringPath stockType = createString("stockType");
|
||||||
|
|
||||||
|
public final BooleanPath useFromBseindia = createBoolean("useFromBseindia");
|
||||||
|
|
||||||
public QMoneyStockPO(String variable) {
|
public QMoneyStockPO(String variable) {
|
||||||
super(MoneyStockPO.class, forVariable(variable));
|
super(MoneyStockPO.class, forVariable(variable));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ public class QStockIpoPO extends EntityPathBase<StockIpoPO> {
|
|||||||
|
|
||||||
public final DateTimePath<java.util.Date> createDate = createDateTime("createDate", java.util.Date.class);
|
public final DateTimePath<java.util.Date> createDate = createDateTime("createDate", java.util.Date.class);
|
||||||
|
|
||||||
|
public final StringPath exchangeType = createString("exchangeType");
|
||||||
|
|
||||||
public final NumberPath<Integer> id = createNumber("id", Integer.class);
|
public final NumberPath<Integer> id = createNumber("id", Integer.class);
|
||||||
|
|
||||||
public final NumberPath<Integer> isList = createNumber("isList", Integer.class);
|
public final NumberPath<Integer> isList = createNumber("isList", Integer.class);
|
||||||
@@ -38,7 +40,6 @@ public class QStockIpoPO extends EntityPathBase<StockIpoPO> {
|
|||||||
public final StringPath stockCode = createString("stockCode");
|
public final StringPath stockCode = createString("stockCode");
|
||||||
|
|
||||||
public final StringPath stockName = createString("stockName");
|
public final StringPath stockName = createString("stockName");
|
||||||
public final StringPath exchangeType = createString("exchangeType");
|
|
||||||
|
|
||||||
public final NumberPath<java.math.BigDecimal> stockPrice = createNumber("stockPrice", java.math.BigDecimal.class);
|
public final NumberPath<java.math.BigDecimal> stockPrice = createNumber("stockPrice", java.math.BigDecimal.class);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package cn.stock.market.infrastructure.db.po;
|
||||||
|
|
||||||
|
import static com.querydsl.core.types.PathMetadataFactory.*;
|
||||||
|
|
||||||
|
import com.querydsl.core.types.dsl.*;
|
||||||
|
|
||||||
|
import com.querydsl.core.types.PathMetadata;
|
||||||
|
import javax.annotation.Generated;
|
||||||
|
import com.querydsl.core.types.Path;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QStockTempPO is a Querydsl query type for StockTempPO
|
||||||
|
*/
|
||||||
|
@Generated("com.querydsl.codegen.EntitySerializer")
|
||||||
|
public class QStockTempPO extends EntityPathBase<StockTempPO> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1973569078L;
|
||||||
|
|
||||||
|
public static final QStockTempPO stockTempPO = new QStockTempPO("stockTempPO");
|
||||||
|
|
||||||
|
public final NumberPath<Integer> id = createNumber("id", Integer.class);
|
||||||
|
|
||||||
|
public final StringPath stockGid = createString("stockGid");
|
||||||
|
|
||||||
|
public final StringPath stockLogo = createString("stockLogo");
|
||||||
|
|
||||||
|
public final StringPath stockType = createString("stockType");
|
||||||
|
|
||||||
|
public QStockTempPO(String variable) {
|
||||||
|
super(StockTempPO.class, forVariable(variable));
|
||||||
|
}
|
||||||
|
|
||||||
|
public QStockTempPO(Path<? extends StockTempPO> path) {
|
||||||
|
super(path.getType(), path.getMetadata());
|
||||||
|
}
|
||||||
|
|
||||||
|
public QStockTempPO(PathMetadata metadata) {
|
||||||
|
super(StockTempPO.class, metadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package cn.stock.market.domain.basic.convert;
|
||||||
|
|
||||||
|
import cn.qutaojing.common.domain.convert.SimpleEntityPOConvert;
|
||||||
|
import cn.qutaojing.common.utils.SpringUtils;
|
||||||
|
import cn.stock.market.domain.basic.entity.Stock;
|
||||||
|
import cn.stock.market.domain.basic.entity.StockTemp;
|
||||||
|
import cn.stock.market.infrastructure.db.po.StockPO;
|
||||||
|
import cn.stock.market.infrastructure.db.po.StockTempPO;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StockConvert
|
||||||
|
*
|
||||||
|
* @author rplees
|
||||||
|
* @email rplees.i.ly@gmail.com
|
||||||
|
* @created 2023/06/17
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Lazy
|
||||||
|
public class StockTempConvert extends SimpleEntityPOConvert<StockTemp, StockTempPO> {
|
||||||
|
public static StockTempConvert of() {
|
||||||
|
return SpringUtils.getBean(StockTempConvert.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package cn.stock.market.domain.basic.entity;
|
||||||
|
|
||||||
|
import cn.qutaojing.common.utils.Beans;
|
||||||
|
import cn.stock.market.dto.command.StockCreateCommand;
|
||||||
|
import cn.stock.market.infrastructure.db.po.StockPO;
|
||||||
|
import cn.stock.market.infrastructure.db.po.StockTempPO;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stock
|
||||||
|
*
|
||||||
|
* @author rplees
|
||||||
|
* @email rplees.i.ly@gmail.com
|
||||||
|
* @created 2023/06/17
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@SuperBuilder
|
||||||
|
@EqualsAndHashCode(
|
||||||
|
callSuper = false
|
||||||
|
)
|
||||||
|
public class StockTemp extends StockTempPO {
|
||||||
|
}
|
||||||
@@ -54,6 +54,11 @@ public class StockRepository extends LocalCacheRepository<Stock, StockPO, Intege
|
|||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, Stock> cacheGidMap() {
|
||||||
|
Map<String, Stock> map = cacheList().stream().collect(Collectors.toMap(Stock::getStockGid, val -> val, (u, v) -> u));
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String, Stock> cacheNameMap() {
|
public Map<String, Stock> cacheNameMap() {
|
||||||
Map<String, Stock> map = cacheList()
|
Map<String, Stock> map = cacheList()
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package cn.stock.market.domain.basic.repository;
|
||||||
|
|
||||||
|
import cn.qutaojing.common.domain.convert.IEntityPOConvert;
|
||||||
|
import cn.qutaojing.common.domain.respostory.LocalCacheBean;
|
||||||
|
import cn.qutaojing.common.domain.respostory.LocalCacheRepository;
|
||||||
|
import cn.qutaojing.common.jpa.ConditionBuilder;
|
||||||
|
import cn.qutaojing.common.utils.SpringUtils;
|
||||||
|
import cn.stock.market.domain.basic.convert.StockConvert;
|
||||||
|
import cn.stock.market.domain.basic.convert.StockTempConvert;
|
||||||
|
import cn.stock.market.domain.basic.entity.Stock;
|
||||||
|
import cn.stock.market.domain.basic.entity.StockTemp;
|
||||||
|
import cn.stock.market.infrastructure.db.po.QStockPO;
|
||||||
|
import cn.stock.market.infrastructure.db.po.QStockTempPO;
|
||||||
|
import cn.stock.market.infrastructure.db.po.StockPO;
|
||||||
|
import cn.stock.market.infrastructure.db.po.StockTempPO;
|
||||||
|
import cn.stock.market.infrastructure.db.repo.StockRepo;
|
||||||
|
import cn.stock.market.infrastructure.db.repo.StockTempRepo;
|
||||||
|
import com.google.common.cache.CacheBuilder;
|
||||||
|
import com.rp.spring.jpa.GenericJpaRepository;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StockRepository
|
||||||
|
*
|
||||||
|
* @author rplees
|
||||||
|
* @email rplees.i.ly@gmail.com
|
||||||
|
* @created 2023/06/17
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||||
|
public class StockTempRepository extends LocalCacheRepository<StockTemp, StockTempPO, Integer> {
|
||||||
|
final StockTempRepo repo;
|
||||||
|
final StockTempConvert convert;
|
||||||
|
final static QStockTempPO q = QStockTempPO.stockTempPO;
|
||||||
|
|
||||||
|
public List<StockTemp> findAllForCheck() {
|
||||||
|
return findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GenericJpaRepository<StockTempPO, Integer> repo() {
|
||||||
|
return repo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IEntityPOConvert<StockTemp, StockTempPO> convert() {
|
||||||
|
return convert;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StockTempRepository of() {
|
||||||
|
return SpringUtils.getBean(StockTempRepository.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,11 +13,9 @@ import cn.hutool.core.text.StrFormatter;
|
|||||||
import cn.stock.market.dto.model.*;
|
import cn.stock.market.dto.model.*;
|
||||||
import cn.stock.market.infrastructure.api.EttechchartsApis;
|
import cn.stock.market.infrastructure.api.EttechchartsApis;
|
||||||
import cn.stock.market.infrastructure.api.GrowwInApis;
|
import cn.stock.market.infrastructure.api.GrowwInApis;
|
||||||
|
import cn.stock.market.infrastructure.api.HomeApiIndex;
|
||||||
import cn.stock.market.infrastructure.api.TodayApis;
|
import cn.stock.market.infrastructure.api.TodayApis;
|
||||||
import cn.stock.market.infrastructure.api.investing.IndiaIndexVo;
|
import cn.stock.market.infrastructure.api.investing.*;
|
||||||
import cn.stock.market.infrastructure.api.investing.IndiaStockVO;
|
|
||||||
import cn.stock.market.infrastructure.api.investing.InvestingApis;
|
|
||||||
import cn.stock.market.infrastructure.api.investing.InvestingInvokerApis;
|
|
||||||
import cn.stock.market.infrastructure.api.sina.vo.HotSearchVO;
|
import cn.stock.market.infrastructure.api.sina.vo.HotSearchVO;
|
||||||
import cn.stock.market.utils.*;
|
import cn.stock.market.utils.*;
|
||||||
import com.ag.utils.CollectionUtils;
|
import com.ag.utils.CollectionUtils;
|
||||||
@@ -255,47 +253,106 @@ public class StockService {
|
|||||||
// .header("Accept-Language", "en-US,en;q=0.9")
|
// .header("Accept-Language", "en-US,en;q=0.9")
|
||||||
// .get();
|
// .get();
|
||||||
String url = "https://www.business-standard.com/markets/news";
|
String url = "https://www.business-standard.com/markets/news";
|
||||||
Document doc = Jsoup.connect(url)
|
// Document doc = Jsoup.connect(url)
|
||||||
.referrer("https://www.business-standard.com/")
|
// .userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36")
|
||||||
.header("Accept-Language", "en-US,en;q=0.9")
|
// .header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
|
||||||
.userAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1")
|
// .header("Accept-Language", "en-US,en;q=0.5")
|
||||||
.timeout(5000) // timeout 5 seconds
|
// .header("Connection", "keep-alive")
|
||||||
.get();
|
// .referrer("https://www.google.com")
|
||||||
// result = doc.html().substring(doc.html().indexOf("<div class=\"listingstyle_shortvideoimg__0TWuX shortvideoimg\">"),doc.html().lastIndexOf("<div class=\"listingstyle_shortvideoimg__0TWuX shortvideoimg\">")+500);
|
// .ignoreHttpErrors(true)
|
||||||
Elements divElements = doc.select("div.listingstyle_cardlistlist__dfq57");
|
// .timeout(10000)
|
||||||
StringBuilder sb = new StringBuilder();
|
// .get();
|
||||||
for (Element divElement : divElements) {
|
String doGetNews = HttpClientRequest.doGetNews(url);
|
||||||
sb.append(divElement.outerHtml()).append("\n");
|
// result = doc.html().substring(doc.html().indexOf("<div class=\"listingstyle_shortvideoimg__0TWuX shortvideoimg\">"),doc.html().lastIndexOf("<div class=\"listingstyle_shortvideoimg__0TWuX shortvideoimg\">")+500);
|
||||||
}
|
// Elements divElements = doc.select("div.listingstyle_cardlistlist__dfq57");
|
||||||
result = sb.toString();
|
// StringBuilder sb = new StringBuilder();
|
||||||
|
// for (Element divElement : divElements) {
|
||||||
|
// sb.append(divElement.outerHtml()).append("\n");
|
||||||
|
// }
|
||||||
|
// result = sb.toString();
|
||||||
|
result = extractNewsFromHtml(doGetNews);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return e.toString();
|
return e.toString();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String extractNewsFromHtml(String rawHtml) {
|
||||||
|
Document doc = Jsoup.parse(rawHtml);
|
||||||
|
|
||||||
|
// Optional: extract raw block around <div class="listingstyle_shortvideoimg__0TWuX shortvideoimg">
|
||||||
|
int start = rawHtml.indexOf("<div class=\"listingstyle_shortvideoimg__0TWuX shortvideoimg\">");
|
||||||
|
int end = rawHtml.lastIndexOf("<div class=\"listingstyle_shortvideoimg__0TWuX shortvideoimg\">") + 500;
|
||||||
|
String result = (start != -1 && end > start) ? rawHtml.substring(start, end) : "";
|
||||||
|
|
||||||
|
// Extract article list using CSS selector
|
||||||
|
Elements divElements = doc.select("div.listingstyle_cardlistlist__dfq57");
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (Element divElement : divElements) {
|
||||||
|
sb.append(divElement.outerHtml()).append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// If you only want the div content:
|
||||||
|
result = sb.toString();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> getNewsInfo(String url) {
|
public List<String> getNewsInfo(String url) {
|
||||||
|
// String result = "";
|
||||||
|
// List<String> list = new ArrayList<>();
|
||||||
|
// try {
|
||||||
|
// // 使用Jsoup连接到网页
|
||||||
|
//// Document doc = Jsoup.connect(url)
|
||||||
|
//// .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36")
|
||||||
|
//// .header("Referer", "https://www.business-standard.com/")
|
||||||
|
//// .header("Accept-Language", "en-US,en;q=0.9")
|
||||||
|
//// .get();
|
||||||
|
// Document doc = Jsoup.connect(url)
|
||||||
|
// .referrer("https://www.business-standard.com/")
|
||||||
|
// .header("Accept-Language", "en-US,en;q=0.9")
|
||||||
|
// .userAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1")
|
||||||
|
// .timeout(5000) // timeout 5 seconds
|
||||||
|
// .get();
|
||||||
|
// result = doc.html().substring(doc.html().indexOf("articleBody") + 14, doc.html().indexOf(",\"author\":") - 1);
|
||||||
|
// list.add(result);
|
||||||
|
// list.add(doc.html().substring(doc.html().indexOf("og:title") + 19, doc.html().indexOf("<meta property=\"og:url") - 5));
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// list.add(e.toString());
|
||||||
|
// return list;
|
||||||
|
// }
|
||||||
|
// return list;
|
||||||
String result = "";
|
String result = "";
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
// 使用Jsoup连接到网页
|
// Step 1: Get raw HTML via HttpClient
|
||||||
// Document doc = Jsoup.connect(url)
|
String rawHtml = HttpClientRequest.doGetNews(url);
|
||||||
// .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36")
|
|
||||||
// .header("Referer", "https://www.business-standard.com/")
|
// Step 2: Parse HTML with Jsoup
|
||||||
// .header("Accept-Language", "en-US,en;q=0.9")
|
Document doc = Jsoup.parse(rawHtml);
|
||||||
// .get();
|
|
||||||
Document doc = Jsoup.connect(url)
|
// Step 3: Extract content manually (like original)
|
||||||
.referrer("https://www.business-standard.com/")
|
int startIdx = rawHtml.indexOf("articleBody") + 14;
|
||||||
.header("Accept-Language", "en-US,en;q=0.9")
|
int endIdx = rawHtml.indexOf(",\"author\":") - 1;
|
||||||
.userAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1")
|
|
||||||
.timeout(5000) // timeout 5 seconds
|
if (startIdx > 0 && endIdx > startIdx) {
|
||||||
.get();
|
result = rawHtml.substring(startIdx, endIdx);
|
||||||
result = doc.html().substring(doc.html().indexOf("articleBody") + 14, doc.html().indexOf(",\"author\":") - 1);
|
} else {
|
||||||
|
result = "[articleBody not found]";
|
||||||
|
}
|
||||||
list.add(result);
|
list.add(result);
|
||||||
list.add(doc.html().substring(doc.html().indexOf("og:title") + 19, doc.html().indexOf("<meta property=\"og:url") - 5));
|
|
||||||
|
// Step 4: Extract og:title
|
||||||
|
int titleStart = rawHtml.indexOf("og:title") + 19;
|
||||||
|
int titleEnd = rawHtml.indexOf("<meta property=\"og:url") - 5;
|
||||||
|
|
||||||
|
if (titleStart > 0 && titleEnd > titleStart) {
|
||||||
|
list.add(rawHtml.substring(titleStart, titleEnd));
|
||||||
|
} else {
|
||||||
|
list.add("[title not found]");
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
list.add(e.toString());
|
list.add("[Error] " + e.getMessage());
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@@ -989,70 +1046,33 @@ public class StockService {
|
|||||||
return ServerResponse.createBySuccess(indexVoList);
|
return ServerResponse.createBySuccess(indexVoList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServerResponse getIndexByBtoday(){
|
public ServerResponse getIndexByBtoday() throws Exception {
|
||||||
List<IndiaIndexVo> indexVoList = new ArrayList<>();
|
List<StockIndex> list = HomeApiIndex.fetchStockIndices();
|
||||||
try {
|
|
||||||
String exchange = "bse";
|
List<IndiaIndexNewVo> indexVoList = new ArrayList<>();
|
||||||
IndiaIndexVo vo1 = new IndiaIndexVo();
|
|
||||||
String coCode = "20558";
|
for (StockIndex stockIndex : list) {
|
||||||
JSONObject object = TodayApis.getStockDetail("in%3BSEN", coCode);
|
IndiaIndexNewVo vo1 = new IndiaIndexNewVo();
|
||||||
IndiaStockVO market = objToVo(object);
|
IndiaStockVO market = new IndiaStockVO();
|
||||||
market.setName("BSESENSEX指数");
|
market.setClose(String.valueOf(stockIndex.getClose()));
|
||||||
|
market.setHigh(String.valueOf(stockIndex.getHigh()));
|
||||||
|
market.setLow(String.valueOf(stockIndex.getLow()));
|
||||||
|
market.setName(stockIndex.getName());
|
||||||
|
market.setNowPrice(String.valueOf(stockIndex.getClose()));
|
||||||
|
market.setOpen(String.valueOf(stockIndex.getOpen()));
|
||||||
|
market.setRate(String.valueOf(stockIndex.getPercentChange()));
|
||||||
vo1.setIndexVo(market);
|
vo1.setIndexVo(market);
|
||||||
|
|
||||||
//获取k线图 1D 当天的数据
|
List<ChartCandle> kLines = HomeApiIndex.fetchChartData(stockIndex.getId(), 419);
|
||||||
String format = "S";
|
// List kline = HomeApiIndex.convertToJsonList(kLines);
|
||||||
String durationType = "D";
|
vo1.setKLine(kLines);
|
||||||
String duration = "1";
|
|
||||||
List kine = TodayApis.getStockKline(exchange,coCode,format,durationType,duration);
|
|
||||||
vo1.setKLine(kine);
|
|
||||||
indexVoList.add(vo1);
|
indexVoList.add(vo1);
|
||||||
}catch (Exception e){
|
|
||||||
log.error("BToday获取BSESENSEX指数数据异常,异常信息。。。。", e);
|
|
||||||
try {
|
|
||||||
GrowwInApis.requestSenSexData(indexVoList);
|
|
||||||
} catch (Exception e1) {
|
|
||||||
log.error("GrowwIn获取BSESENSEX指数数据异常,异常信息。。。。", e1);
|
|
||||||
try{
|
|
||||||
EttechchartsApis.requestSensexData(indexVoList);
|
|
||||||
} catch (Exception e2) {
|
|
||||||
log.error("Ettechcharts获取BSESENSEX指数数据异常,异常信息。。。。", e2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
String exchange = "nse";
|
|
||||||
IndiaIndexVo vo1 = new IndiaIndexVo();
|
|
||||||
String coCode = "20559";
|
|
||||||
JSONObject object = TodayApis.getStockDetail("in%3BNSX", coCode);
|
|
||||||
IndiaStockVO market = objToVo(object);
|
|
||||||
market.setName("NIFTY50指数");
|
|
||||||
vo1.setIndexVo(market);
|
|
||||||
|
|
||||||
//获取k线图 1D 当天的数据
|
|
||||||
String format = "S";
|
|
||||||
String durationType = "D";
|
|
||||||
String duration = "1";
|
|
||||||
List kine = TodayApis.getStockKline(exchange,coCode,format,durationType,duration);
|
|
||||||
vo1.setKLine(kine);
|
|
||||||
indexVoList.add(vo1);
|
|
||||||
}catch (Exception e){
|
|
||||||
log.error("BToday获取NIFTY50指数数据异常,异常信息。。。。", e);
|
|
||||||
try {
|
|
||||||
GrowwInApis.requestNifty50Data(indexVoList);
|
|
||||||
} catch (Exception e1) {
|
|
||||||
log.error("GrowwIn获取NIFTY50指数数据异常,异常信息。。。。", e1);
|
|
||||||
try{
|
|
||||||
EttechchartsApis.requestNifty50Data(indexVoList);
|
|
||||||
} catch (Exception e2) {
|
|
||||||
log.error("Ettechcharts获取NIFTY50指数数据异常,异常信息。。。。", e2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ServerResponse.createBySuccess(indexVoList);
|
return ServerResponse.createBySuccess(indexVoList);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private IndiaStockVO objToVo(JSONObject object){
|
private IndiaStockVO objToVo(JSONObject object){
|
||||||
IndiaStockVO market = new IndiaStockVO();
|
IndiaStockVO market = new IndiaStockVO();
|
||||||
if(object.containsKey("priceprevclose")){
|
if(object.containsKey("priceprevclose")){
|
||||||
|
|||||||
11
src/main/java/cn/stock/market/dto/model/ChartCandle.java
Normal file
11
src/main/java/cn/stock/market/dto/model/ChartCandle.java
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package cn.stock.market.dto.model;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ChartCandle {
|
||||||
|
private String upd_date;
|
||||||
|
private Double price;
|
||||||
|
|
||||||
|
// Getters & Setters (hoặc @Data nếu dùng Lombok)
|
||||||
|
}
|
||||||
31
src/main/java/cn/stock/market/dto/model/StockIndex.java
Normal file
31
src/main/java/cn/stock/market/dto/model/StockIndex.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package cn.stock.market.dto.model;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class StockIndex {
|
||||||
|
private String id;
|
||||||
|
private String symbol;
|
||||||
|
private String name;
|
||||||
|
private String exchange;
|
||||||
|
private String micCode;
|
||||||
|
private String datetime;
|
||||||
|
private long timestamp;
|
||||||
|
private Double open;
|
||||||
|
private Double high;
|
||||||
|
private Double low;
|
||||||
|
private Double close;
|
||||||
|
private Long volume;
|
||||||
|
private Double previousClose;
|
||||||
|
private Double change;
|
||||||
|
private Double percentChange;
|
||||||
|
private Long averageVolume;
|
||||||
|
private Boolean isMarketOpen;
|
||||||
|
private Long marketCap;
|
||||||
|
private String fiftyTwoWeek;
|
||||||
|
private Integer icon;
|
||||||
|
|
||||||
|
// Getters & setters (hoặc dùng @Data nếu có Lombok)
|
||||||
|
}
|
||||||
28
src/main/java/cn/stock/market/dto/model/Symbol.java
Normal file
28
src/main/java/cn/stock/market/dto/model/Symbol.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package cn.stock.market.dto.model;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class Symbol {
|
||||||
|
private String symbol;
|
||||||
|
private String description;
|
||||||
|
private String stockGid;
|
||||||
|
private String type;
|
||||||
|
private String exchange;
|
||||||
|
private String currencyCode;
|
||||||
|
private String currencyLogoid;
|
||||||
|
private String logoid;
|
||||||
|
private String providerId;
|
||||||
|
private String sourceLogoid;
|
||||||
|
private String sourceId;
|
||||||
|
private String country;
|
||||||
|
private boolean isPrimaryListing;
|
||||||
|
private List<String> typespecs;
|
||||||
|
|
||||||
|
// Getters and setters
|
||||||
|
// Bạn có thể dùng Lombok nếu muốn ngắn gọn hơn
|
||||||
|
// Hoặc generate getter/setter trong IDE
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
package cn.stock.market.infrastructure.api;
|
||||||
|
import cn.stock.market.dto.model.ChartCandle;
|
||||||
|
import cn.stock.market.dto.model.StockIndex;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class HomeApiIndex {
|
||||||
|
private static final OkHttpClient client = new OkHttpClient();
|
||||||
|
private static final String API_URL = "https://apinode-dgdev.moneytj.com/api/ger-market/stocks/query-list?symbols=XETR:DAX,XETR:MDAX,XETR:SDXP,XETR:HDAX";
|
||||||
|
private static final String BASE_URL = "https://apinode-dgdev.moneytj.com/api/ger-market/chart";
|
||||||
|
|
||||||
|
public static List<StockIndex> fetchStockIndices() throws Exception {
|
||||||
|
List<StockIndex> result = new ArrayList<>();
|
||||||
|
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(API_URL)
|
||||||
|
.addHeader("User-Agent", "Mozilla/5.0")
|
||||||
|
.addHeader("Accept", "application/json")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Response response = client.newCall(request).execute();
|
||||||
|
|
||||||
|
if (!response.isSuccessful()) {
|
||||||
|
throw new RuntimeException("HTTP error code: " + response.code());
|
||||||
|
}
|
||||||
|
|
||||||
|
String body = response.body().string();
|
||||||
|
JSONObject json = new JSONObject(body);
|
||||||
|
JSONArray data = json.getJSONArray("data");
|
||||||
|
|
||||||
|
for (int i = 0; i < data.length(); i++) {
|
||||||
|
JSONObject obj = data.getJSONObject(i);
|
||||||
|
StockIndex index = new StockIndex();
|
||||||
|
|
||||||
|
index.setId(obj.optString("id"));
|
||||||
|
index.setSymbol(obj.optString("symbol"));
|
||||||
|
index.setName(obj.optString("name"));
|
||||||
|
index.setExchange(obj.optString("exchange"));
|
||||||
|
index.setMicCode(obj.optString("mic_code"));
|
||||||
|
index.setDatetime(obj.optString("datetime"));
|
||||||
|
index.setTimestamp(obj.optLong("timestamp"));
|
||||||
|
index.setOpen(getDoubleOrNull(obj, "open"));
|
||||||
|
index.setHigh(getDoubleOrNull(obj, "high"));
|
||||||
|
index.setLow(getDoubleOrNull(obj, "low"));
|
||||||
|
index.setClose(getDoubleOrNull(obj, "close"));
|
||||||
|
index.setVolume(getLongOrNull(obj, "volume"));
|
||||||
|
index.setPreviousClose(getDoubleOrNull(obj, "previous_close"));
|
||||||
|
index.setChange(getDoubleOrNull(obj, "change"));
|
||||||
|
index.setPercentChange(getDoubleOrNull(obj, "percent_change"));
|
||||||
|
index.setAverageVolume(getLongOrNull(obj, "average_volume"));
|
||||||
|
index.setIsMarketOpen(obj.optBoolean("is_market_open"));
|
||||||
|
index.setMarketCap(getLongOrNull(obj, "market_cap"));
|
||||||
|
index.setFiftyTwoWeek(obj.optString("fifty_two_week", null));
|
||||||
|
index.setIcon(obj.optInt("icon", 0));
|
||||||
|
|
||||||
|
result.add(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<ChartCandle> fetchChartData(String symbol, int amount) throws Exception {
|
||||||
|
List<ChartCandle> result = new ArrayList<>();
|
||||||
|
|
||||||
|
String url = BASE_URL + "?symbol=" + symbol + "&interval=D&amount=" + amount;
|
||||||
|
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.addHeader("User-Agent", "Mozilla/5.0")
|
||||||
|
.addHeader("Accept", "application/json")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Response response = client.newCall(request).execute();
|
||||||
|
|
||||||
|
if (!response.isSuccessful()) {
|
||||||
|
throw new RuntimeException("HTTP error code: " + response.code());
|
||||||
|
}
|
||||||
|
|
||||||
|
String body = response.body().string();
|
||||||
|
JSONObject json = new JSONObject(body);
|
||||||
|
JSONArray data = json.getJSONArray("data");
|
||||||
|
|
||||||
|
for (int i = 0; i < data.length(); i++) {
|
||||||
|
JSONObject obj = data.getJSONObject(i);
|
||||||
|
ChartCandle candle = new ChartCandle();
|
||||||
|
|
||||||
|
long ts = obj.optLong("time");
|
||||||
|
String formattedTime = convertToGermanTime(ts);
|
||||||
|
|
||||||
|
candle.setUpd_date(formattedTime);
|
||||||
|
candle.setPrice(getDoubleOrNull(obj, "close"));
|
||||||
|
|
||||||
|
result.add(candle);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public static List<JSONObject> convertToJsonList(List<ChartCandle> candles) {
|
||||||
|
// List<JSONObject> result = new ArrayList<>();
|
||||||
|
//
|
||||||
|
// for (ChartCandle c : candles) {
|
||||||
|
// JSONObject obj = new JSONObject();
|
||||||
|
// String formattedTime = convertToGermanTime(c.getTime());
|
||||||
|
// obj.put("upd_date", formattedTime);
|
||||||
|
// obj.put("price", c.getClose());
|
||||||
|
// result.add(obj);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return result;
|
||||||
|
// }
|
||||||
|
|
||||||
|
public static String convertToGermanTime(long epochSeconds) {
|
||||||
|
ZoneId germanyZone = ZoneId.of("Europe/Berlin");
|
||||||
|
Instant instant = Instant.ofEpochSecond(epochSeconds);
|
||||||
|
ZonedDateTime zonedDateTime = instant.atZone(germanyZone);
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
|
||||||
|
return formatter.format(zonedDateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper to safely parse nullable numbers
|
||||||
|
private static Double getDoubleOrNull(JSONObject obj, String key) {
|
||||||
|
return obj.isNull(key) ? null : obj.optDouble(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Long getLongOrNull(JSONObject obj, String key) {
|
||||||
|
return obj.isNull(key) ? null : obj.optLong(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package cn.stock.market.infrastructure.api.investing;
|
||||||
|
|
||||||
|
import cn.stock.market.dto.model.ChartCandle;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@ApiModel(value = "指数信息")
|
||||||
|
public class IndiaIndexNewVo {
|
||||||
|
@ApiModelProperty(value = "指数详情")
|
||||||
|
private IndiaStockVO indexVo;
|
||||||
|
@ApiModelProperty(value = "指数k线")
|
||||||
|
private List<ChartCandle> kLine;
|
||||||
|
}
|
||||||
@@ -61,11 +61,11 @@ public class StockIpoPO {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否显示【1 显示,2 不显示】 */
|
* 是否显示【1 显示,2 不显示】 */
|
||||||
Integer isShow;
|
Integer isShow = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否上市【1 未上市,2 已上市】 */
|
* 是否上市【1 未上市,2 已上市】 */
|
||||||
Integer isList;
|
Integer isList = 1;
|
||||||
|
|
||||||
Date createDate;
|
Date createDate;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package cn.stock.market.infrastructure.db.po;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
import org.hibernate.annotations.DynamicInsert;
|
||||||
|
import org.hibernate.annotations.DynamicUpdate;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StockPO
|
||||||
|
*
|
||||||
|
* @author rplees
|
||||||
|
* @email rplees.i.ly@gmail.com
|
||||||
|
* @created 2023/06/17
|
||||||
|
*/
|
||||||
|
@SuperBuilder
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@DynamicInsert
|
||||||
|
@DynamicUpdate
|
||||||
|
@Table(name = "stockTemp")
|
||||||
|
public class StockTempPO {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
Integer id;
|
||||||
|
|
||||||
|
String stockType;
|
||||||
|
|
||||||
|
String stockGid;
|
||||||
|
|
||||||
|
String stockLogo;
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package cn.stock.market.infrastructure.db.repo;
|
||||||
|
|
||||||
|
import cn.stock.market.infrastructure.db.po.StockPO;
|
||||||
|
import cn.stock.market.infrastructure.db.po.StockTempPO;
|
||||||
|
import com.rp.spring.jpa.GenericJpaRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StockRepo
|
||||||
|
*
|
||||||
|
* @author rplees
|
||||||
|
* @email rplees.i.ly@gmail.com
|
||||||
|
* @created 2023/06/17
|
||||||
|
*/
|
||||||
|
public interface StockTempRepo extends GenericJpaRepository<StockTempPO, Integer> {
|
||||||
|
}
|
||||||
@@ -110,7 +110,7 @@ public class InvestingTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*新闻接口*/
|
/*新闻接口*/
|
||||||
@Scheduled(cron = "0 0 0/3 * * ?")
|
// @Scheduled(cron = "0 0 0/3 * * ?")
|
||||||
public void saveStockNews() {
|
public void saveStockNews() {
|
||||||
log.info("英文股票新闻数据同步开始");
|
log.info("英文股票新闻数据同步开始");
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -115,15 +115,15 @@ public class MoneyScraper {
|
|||||||
if (ulElement != null) {
|
if (ulElement != null) {
|
||||||
for (Element aElement : ulElement.select("a")) {
|
for (Element aElement : ulElement.select("a")) {
|
||||||
String exchangeValue = aElement.text().trim();
|
String exchangeValue = aElement.text().trim();
|
||||||
if ("BSE".equals(exchangeValue) || "NSE".equals(exchangeValue)) {
|
if ("BSE".equals(exchangeValue.toUpperCase()) || "NSE".equals(exchangeValue.toUpperCase())) {
|
||||||
log.info(Thread.currentThread().getName() + ",the stock url: " + url +
|
log.info(Thread.currentThread().getName() + ",the stock url: " + url +
|
||||||
", the exchange Value: " + exchangeValue);
|
", the exchange Value: " + exchangeValue);
|
||||||
MoneyStock build = MoneyStock.builder().stockName(name).stockType(exchangeValue.toLowerCase(Locale.ROOT))
|
MoneyStock build = MoneyStock.builder().stockName(name).stockType(exchangeValue.toUpperCase(Locale.ROOT))
|
||||||
.detailUrl(String.format("https://priceapi.moneycontrol.com/pricefeed/%s/equitycash/%s", exchangeValue.toLowerCase(), companyCodeId))
|
.detailUrl(String.format("https://priceapi.moneycontrol.com/pricefeed/%s/equitycash/%s", exchangeValue.toLowerCase(), companyCodeId))
|
||||||
.selfUrl(url)
|
.selfUrl(url)
|
||||||
.selfDispId(extractDispId(url))
|
.selfDispId(extractDispId(url))
|
||||||
.moneyScId(companyCodeId).saveTime(new Date()).build();
|
.moneyScId(companyCodeId).saveTime(new Date()).build();
|
||||||
List<MoneyStock> all = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.stockName.eq(name), QMoneyStockPO.moneyStockPO.stockType.eq(exchangeValue.toLowerCase(Locale.ROOT)));
|
List<MoneyStock> all = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.stockName.eq(name), QMoneyStockPO.moneyStockPO.stockType.upper().eq(exchangeValue.toUpperCase(Locale.ROOT)));
|
||||||
if (CollectionUtil.isEmpty(all)) {
|
if (CollectionUtil.isEmpty(all)) {
|
||||||
moneyStockRepository.save(build);
|
moneyStockRepository.save(build);
|
||||||
}
|
}
|
||||||
@@ -264,15 +264,15 @@ public class MoneyScraper {
|
|||||||
for (Element aElement : ulElement.select("a")) {
|
for (Element aElement : ulElement.select("a")) {
|
||||||
String exchangeValue = aElement.text().trim();
|
String exchangeValue = aElement.text().trim();
|
||||||
|
|
||||||
if ("BSE".equals(exchangeValue) || "NSE".equals(exchangeValue)) {
|
if ("BSE".equals(exchangeValue.toUpperCase(Locale.ROOT)) || "NSE".equals(exchangeValue.toUpperCase(Locale.ROOT))) {
|
||||||
log.info(Thread.currentThread().getName()+",stockName: " + textContent + ", self_link: " + linkAttribute +
|
log.info(Thread.currentThread().getName()+",stockName: " + textContent + ", self_link: " + linkAttribute +
|
||||||
", the exchange Value: " + exchangeValue);
|
", the exchange Value: " + exchangeValue);
|
||||||
MoneyStock build = MoneyStock.builder().stockName(textContent).stockType(exchangeValue.toLowerCase(Locale.ROOT))
|
MoneyStock build = MoneyStock.builder().stockName(textContent).stockType(exchangeValue.toUpperCase(Locale.ROOT))
|
||||||
.detailUrl(String.format("https://priceapi.moneycontrol.com/pricefeed/%s/equitycash/%s", exchangeValue.toLowerCase(), companyCodeId))
|
.detailUrl(String.format("https://priceapi.moneycontrol.com/pricefeed/%s/equitycash/%s", exchangeValue.toLowerCase(), companyCodeId))
|
||||||
.selfUrl(linkAttribute)
|
.selfUrl(linkAttribute)
|
||||||
.selfDispId(extractDispId(linkAttribute))
|
.selfDispId(extractDispId(linkAttribute))
|
||||||
.moneyScId(companyCodeId).saveTime(new Date()).build();
|
.moneyScId(companyCodeId).saveTime(new Date()).build();
|
||||||
List<MoneyStock> all = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.stockName.eq(textContent), QMoneyStockPO.moneyStockPO.stockType.eq(exchangeValue.toLowerCase(Locale.ROOT)));
|
List<MoneyStock> all = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.stockName.eq(textContent), QMoneyStockPO.moneyStockPO.stockType.upper().eq(exchangeValue.toUpperCase(Locale.ROOT)));
|
||||||
if(CollectionUtil.isEmpty(all)){
|
if(CollectionUtil.isEmpty(all)){
|
||||||
moneyStockRepository.save(build);
|
moneyStockRepository.save(build);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class RealTimeTask {
|
|||||||
|
|
||||||
/*每天9点定时删除股票k线数据*/
|
/*每天9点定时删除股票k线数据*/
|
||||||
@Transactional
|
@Transactional
|
||||||
@Scheduled(cron = "0 00 9 * * MON-FRI")
|
// @Scheduled(cron = "0 00 9 * * MON-FRI")
|
||||||
public void deleteStockCode() {
|
public void deleteStockCode() {
|
||||||
log.info("每天9点定时删除股票k线数据");
|
log.info("每天9点定时删除股票k线数据");
|
||||||
repo.deleteStockCode();
|
repo.deleteStockCode();
|
||||||
@@ -24,7 +24,7 @@ public class RealTimeTask {
|
|||||||
|
|
||||||
/*每天0点定时删除期货k线数据*/
|
/*每天0点定时删除期货k线数据*/
|
||||||
@Transactional
|
@Transactional
|
||||||
@Scheduled(cron = "0 00 0 * * MON-FRI")
|
// @Scheduled(cron = "0 00 0 * * MON-FRI")
|
||||||
public void deleteStockFuturesCode() {
|
public void deleteStockFuturesCode() {
|
||||||
log.info("每天0点定时删除期货k线数据");
|
log.info("每天0点定时删除期货k线数据");
|
||||||
repo.deleteStockFuturesCode();
|
repo.deleteStockFuturesCode();
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class Scraper {
|
|||||||
private boolean times = false;
|
private boolean times = false;
|
||||||
|
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 1 */2 * ?")
|
// @Scheduled(cron = "0 0 1 */2 * ?")
|
||||||
@RequestMapping("/testScraperGetBusinessToday")
|
@RequestMapping("/testScraperGetBusinessToday")
|
||||||
public void schedule() {
|
public void schedule() {
|
||||||
String BASE_URL = "https://akm-img-a-in.tosshub.com/businesstoday/resource/market-widgets/prod/company-master-23-01-2023.json";
|
String BASE_URL = "https://akm-img-a-in.tosshub.com/businesstoday/resource/market-widgets/prod/company-master-23-01-2023.json";
|
||||||
@@ -110,178 +110,200 @@ public class Scraper {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 18 * * ?")
|
// @Scheduled(cron = "0 0 18 * * ?")
|
||||||
// @PostConstruct
|
// @PostConstruct
|
||||||
@RequestMapping("/testScraperGetMoneyControllerNewIPO")
|
@RequestMapping("/testScraperGetMoneyControllerNewIPO")
|
||||||
public void getMoneyControllerNewIPOSchedule() {
|
public void getMoneyControllerNewIPOSchedule() {
|
||||||
log.info("定时任务执行获取新股ipo的方法开始执行");
|
log.info("定时任务执行获取新股ipo的方法开始执行");
|
||||||
// 目标 URL
|
// 目标 URL
|
||||||
String url = "https://www.moneycontrol.com/ipo/open-upcoming-ipos";
|
List<String> urls = Arrays.asList("https://www.moneycontrol.com/ipo/upcoming-ipos/", "https://www.moneycontrol.com/ipo/open-ipos/");
|
||||||
// 创建 HttpClient 实例
|
// 创建 HttpClient 实例
|
||||||
HttpClient client = HttpClients.createDefault();
|
HttpClient client = HttpClients.createDefault();
|
||||||
// 创建 HttpGet 请求
|
// 创建 HttpGet 请求
|
||||||
HttpGet request = new HttpGet(url);
|
for (String url : urls) {
|
||||||
try {
|
HttpGet request = new HttpGet(url);
|
||||||
// 执行请求
|
try {
|
||||||
HttpResponse response = client.execute(request);
|
// 执行请求
|
||||||
|
HttpResponse response = client.execute(request);
|
||||||
|
|
||||||
// 检查请求是否成功
|
// 检查请求是否成功
|
||||||
if (response.getStatusLine().getStatusCode() == 200) {
|
if (response.getStatusLine().getStatusCode() == 200) {
|
||||||
// 获取响应体
|
// 获取响应体
|
||||||
String responseBody = EntityUtils.toString(response.getEntity());
|
String responseBody = EntityUtils.toString(response.getEntity());
|
||||||
|
|
||||||
// 使用 Jsoup 解析 HTML
|
// 使用 Jsoup 解析 HTML
|
||||||
Document doc = Jsoup.parse(responseBody);
|
Document doc = Jsoup.parse(responseBody);
|
||||||
|
|
||||||
// 找到包含 JSON 数据的 <script> 标签
|
// 找到包含 JSON 数据的 <script> 标签
|
||||||
Element scriptTag = doc.selectFirst("script#__NEXT_DATA__");
|
Element scriptTag = doc.selectFirst("script#__NEXT_DATA__");
|
||||||
|
|
||||||
if (scriptTag != null) {
|
if (scriptTag != null) {
|
||||||
// 获取 JSON 数据
|
// 获取 JSON 数据
|
||||||
String jsonDataStr = scriptTag.html();
|
String jsonDataStr = scriptTag.html();
|
||||||
|
|
||||||
// 将 JSON 字符串解析为 Java JSONObject
|
// 将 JSON 字符串解析为 Java JSONObject
|
||||||
JSONObject jsonObject = JSONObject.parseObject(jsonDataStr);
|
JSONObject jsonObject = JSONObject.parseObject(jsonDataStr);
|
||||||
log.info("获取到新股的json信息:"+jsonObject.toJSONString());
|
log.info("获取到新股的json信息:"+jsonObject.toJSONString());
|
||||||
|
|
||||||
JSONObject pageProps = jsonObject.getJSONObject("props").getJSONObject("pageProps");
|
|
||||||
JSONObject ipoTableData = pageProps.getJSONObject("ipoTableData");
|
|
||||||
|
|
||||||
// 解析 openData 和 upcomingData
|
|
||||||
JSONArray openData = ipoTableData.getJSONArray("openData");
|
|
||||||
JSONArray upcomingData = ipoTableData.getJSONArray("upcomingData");
|
|
||||||
List<StockIpo> listStockIpoList = new ArrayList<>();
|
|
||||||
for (int i = 0; i < openData.size(); i++) {
|
|
||||||
JSONObject entry = openData.getJSONObject(i);
|
|
||||||
StockIpo stockIpo = new StockIpo();
|
|
||||||
stockIpo.setStockCode(entry.getString("sc_id"));
|
|
||||||
stockIpo.setStockName(entry.getString("company_name"));
|
|
||||||
stockIpo.setStockPrice(entry.getBigDecimal("issue_price"));
|
|
||||||
stockIpo.setSubscriptionDate(convertStringToTimestamp(entry.getString("open_date")));
|
|
||||||
stockIpo.setListingDate(convertStringToTimestamp(entry.getString("listing_date")));
|
|
||||||
Integer totalNumber = 0;
|
|
||||||
if(null!=entry.getInteger("issue_size")&&entry.getBigDecimal("issue_price")!=null&&!entry.getBigDecimal("issue_price").equals(BigDecimal.valueOf(0))){
|
|
||||||
Integer issue_size = entry.getInteger("issue_size");
|
|
||||||
BigDecimal issueSize = new BigDecimal(issue_size);
|
|
||||||
BigDecimal totalNumberBigDecimal = issueSize.divide(entry.getBigDecimal("issue_price"), 2, BigDecimal.ROUND_HALF_UP);
|
|
||||||
totalNumber = totalNumberBigDecimal.intValue();
|
|
||||||
}
|
|
||||||
stockIpo.setTotalNumber(totalNumber);
|
|
||||||
stockIpo.setApply(entry.getString("total_subs"));
|
|
||||||
stockIpo.setCreateDate(new Date());
|
|
||||||
stockIpo.setUpdateDate(new Date());
|
|
||||||
stockIpo.setSourceType("3");
|
|
||||||
|
|
||||||
if (stockIpo.getStockCode() == null || stockIpo.getStockName() == null){
|
JSONObject pageProps = jsonObject.getJSONObject("props").getJSONObject("pageProps");
|
||||||
continue;
|
JSONObject ipoTableData = pageProps.getJSONObject("ipoTableData");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 解析 openData 和 upcomingData
|
||||||
|
JSONArray openData = ipoTableData.getJSONArray("openData");
|
||||||
|
// if (openData.isEmpty()){
|
||||||
|
// openData = ipoTableData.getJSONArray("openUpcomingData");
|
||||||
|
// }
|
||||||
|
JSONArray upcomingData = ipoTableData.getJSONArray("upcomingData");
|
||||||
|
List<StockIpo> listStockIpoList = new ArrayList<>();
|
||||||
|
for (int i = 0; i < openData.size(); i++) {
|
||||||
|
JSONObject entry = openData.getJSONObject(i);
|
||||||
|
StockIpo stockIpo = new StockIpo();
|
||||||
|
stockIpo.setStockCode(entry.getString("sc_id"));
|
||||||
|
stockIpo.setStockName(entry.getString("company_name"));
|
||||||
|
stockIpo.setStockPrice(entry.getBigDecimal("issue_price"));
|
||||||
|
stockIpo.setSubscriptionDate(convertStringToTimestamp(entry.getString("open_date")));
|
||||||
|
stockIpo.setListingDate(convertStringToTimestamp(entry.getString("listing_date")));
|
||||||
|
Integer totalNumber = 0;
|
||||||
|
if(null!=entry.getInteger("issue_size")&&entry.getBigDecimal("issue_price")!=null&&!entry.getBigDecimal("issue_price").equals(BigDecimal.valueOf(0))){
|
||||||
|
BigDecimal issueSize = new BigDecimal(entry.getLong("issue_size"));
|
||||||
|
BigDecimal totalNumberBigDecimal = issueSize.divide(entry.getBigDecimal("issue_price"), 2, BigDecimal.ROUND_HALF_UP);
|
||||||
|
totalNumber = totalNumberBigDecimal.intValue();
|
||||||
|
}
|
||||||
|
stockIpo.setTotalNumber(totalNumber);
|
||||||
|
stockIpo.setApply(entry.getString("total_subs"));
|
||||||
|
stockIpo.setCreateDate(new Date());
|
||||||
|
stockIpo.setUpdateDate(new Date());
|
||||||
|
stockIpo.setSourceType("3");
|
||||||
|
|
||||||
|
if (stockIpo.getStockCode() == null || stockIpo.getStockName() == null){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String codeDetail = entry.getString("url").substring(entry.getString("url").lastIndexOf('/') + 1);;
|
||||||
|
List<String> exchanges = getIpoExchange(stockIpo.getStockName(), codeDetail);
|
||||||
|
|
||||||
|
for (String exchange : exchanges) {
|
||||||
|
StockIpo ipo = new StockIpo();
|
||||||
|
ipo.setStockCode(stockIpo.getStockCode());
|
||||||
|
ipo.setStockName(stockIpo.getStockName());
|
||||||
|
ipo.setStockPrice(stockIpo.getStockPrice());
|
||||||
|
ipo.setSubscriptionDate(stockIpo.getSubscriptionDate());
|
||||||
|
ipo.setListingDate(stockIpo.getListingDate());
|
||||||
|
ipo.setTotalNumber(stockIpo.getTotalNumber());
|
||||||
|
ipo.setApply(stockIpo.getApply());
|
||||||
|
ipo.setCreateDate(stockIpo.getCreateDate());
|
||||||
|
ipo.setUpdateDate(stockIpo.getUpdateDate());
|
||||||
|
ipo.setExchangeType(exchange);
|
||||||
|
ipo.setSourceType("3");
|
||||||
|
listStockIpoList.add(ipo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> exchanges = getIpoExchange(stockIpo.getStockName(), stockIpo.getStockCode());
|
for (int i = 0; i < upcomingData.size(); i++) {
|
||||||
|
JSONObject entry = upcomingData.getJSONObject(i);
|
||||||
|
StockIpo stockIpo = new StockIpo();
|
||||||
|
stockIpo.setStockCode(entry.getString("sc_id"));
|
||||||
|
stockIpo.setStockName(entry.getString("company_name"));
|
||||||
|
stockIpo.setStockPrice(entry.getBigDecimal("issue_price"));
|
||||||
|
stockIpo.setSubscriptionDate(convertStringToTimestamp(entry.getString("open_date")));
|
||||||
|
stockIpo.setListingDate(convertStringToTimestamp(entry.getString("listing_date")));
|
||||||
|
Integer totalNumber = 0;
|
||||||
|
if(null!=entry.getInteger("issue_size")&&entry.getBigDecimal("issue_price")!=null&&!entry.getBigDecimal("issue_price").equals(BigDecimal.valueOf(0))){
|
||||||
|
Integer issue_size = entry.getInteger("issue_size");
|
||||||
|
BigDecimal issueSize = new BigDecimal(issue_size);
|
||||||
|
BigDecimal totalNumberBigDecimal = issueSize.divide(entry.getBigDecimal("issue_price"), 2, BigDecimal.ROUND_HALF_UP);
|
||||||
|
totalNumber = totalNumberBigDecimal.intValue();
|
||||||
|
}
|
||||||
|
stockIpo.setTotalNumber(totalNumber);
|
||||||
|
stockIpo.setApply(entry.getString("total_subs"));
|
||||||
|
stockIpo.setCreateDate(new Date());
|
||||||
|
stockIpo.setUpdateDate(new Date());
|
||||||
|
stockIpo.setSourceType("3");
|
||||||
|
|
||||||
for (String exchange : exchanges) {
|
if (stockIpo.getStockCode() == null || stockIpo.getStockName() == null){
|
||||||
StockIpo ipo = new StockIpo();
|
continue;
|
||||||
ipo.setStockCode(stockIpo.getStockCode());
|
}
|
||||||
ipo.setStockName(stockIpo.getStockName());
|
|
||||||
ipo.setStockPrice(stockIpo.getStockPrice());
|
|
||||||
ipo.setSubscriptionDate(stockIpo.getSubscriptionDate());
|
|
||||||
ipo.setListingDate(stockIpo.getListingDate());
|
|
||||||
ipo.setTotalNumber(stockIpo.getTotalNumber());
|
|
||||||
ipo.setApply(stockIpo.getApply());
|
|
||||||
ipo.setCreateDate(stockIpo.getCreateDate());
|
|
||||||
ipo.setUpdateDate(stockIpo.getUpdateDate());
|
|
||||||
ipo.setExchangeType(exchange);
|
|
||||||
|
|
||||||
listStockIpoList.add(ipo);
|
List<String> exchanges = getIpoExchange(stockIpo.getStockName(), stockIpo.getStockCode());
|
||||||
|
|
||||||
|
for (String exchange : exchanges) {
|
||||||
|
StockIpo ipo = new StockIpo();
|
||||||
|
ipo.setStockCode(stockIpo.getStockCode());
|
||||||
|
ipo.setStockName(stockIpo.getStockName());
|
||||||
|
ipo.setStockPrice(stockIpo.getStockPrice());
|
||||||
|
ipo.setSubscriptionDate(stockIpo.getSubscriptionDate());
|
||||||
|
ipo.setListingDate(stockIpo.getListingDate());
|
||||||
|
ipo.setTotalNumber(stockIpo.getTotalNumber());
|
||||||
|
ipo.setApply(stockIpo.getApply());
|
||||||
|
ipo.setCreateDate(stockIpo.getCreateDate());
|
||||||
|
ipo.setUpdateDate(stockIpo.getUpdateDate());
|
||||||
|
ipo.setExchangeType(exchange);
|
||||||
|
ipo.setSourceType("3");
|
||||||
|
listStockIpoList.add(ipo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stockIpoRepository.saveAll(listStockIpoList);
|
||||||
|
|
||||||
|
if (!listStockIpoList.isEmpty())
|
||||||
|
{
|
||||||
|
listStockIpoList = listStockIpoList.stream().filter(a -> StringUtils.isNotBlank(a.getStockName())).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
|
||||||
|
for (StockIpo stockIpo : listStockIpoList) {
|
||||||
|
StockIpo existIpo = existStockIpoList.stream().filter(a -> a.getStockCode().equals(stockIpo.getStockCode()) && (a.getExchangeType() == null || a.getExchangeType().isEmpty() || a.getExchangeType().toLowerCase().trim().equals(stockIpo.getExchangeType().toLowerCase().trim()))).findFirst().orElse(null);
|
||||||
|
if (existIpo != null) {
|
||||||
|
if (existIpo.getExchangeType() == null || existIpo.getExchangeType().isEmpty()){
|
||||||
|
existIpo.setExchangeType(stockIpo.getExchangeType());
|
||||||
|
}
|
||||||
|
stockIpo.setId(existIpo.getId());
|
||||||
|
if (existIpo.getStockPrice() != null){
|
||||||
|
stockIpo.setStockPrice(existIpo.getStockPrice());
|
||||||
|
stockIpo.setApply(existIpo.getApply());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// listStockIpoList = listStockIpoList.stream()
|
||||||
|
// .filter(stockIpos -> !existingStockScIds.contains(stockIpos.getStockCode())).filter(stockIpo -> StringUtils.isNotBlank(stockIpo.getStockName()))
|
||||||
|
// .collect(Collectors.toList());
|
||||||
|
|
||||||
|
//保存全部的新股
|
||||||
|
if(CollectionUtil.isNotEmpty(listStockIpoList)){
|
||||||
|
stockIpoRepository.saveAll(listStockIpoList);
|
||||||
|
|
||||||
|
log.info("定时任务执行获取新股ipo的方法开始结束,保存了数据:{}", JSON.toJSONString(listStockIpoList));
|
||||||
|
}else {
|
||||||
|
log.info("定时任务执行获取新股ipo的方法开始结束,没有数据");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 输出整个 JSON 数据
|
||||||
|
} else {
|
||||||
|
log.info("未找到包含 JSON 数据的 <script> 标签");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < upcomingData.size(); i++) {
|
|
||||||
JSONObject entry = upcomingData.getJSONObject(i);
|
|
||||||
StockIpo stockIpo = new StockIpo();
|
|
||||||
stockIpo.setStockCode(entry.getString("sc_id"));
|
|
||||||
stockIpo.setStockName(entry.getString("company_name"));
|
|
||||||
stockIpo.setStockPrice(entry.getBigDecimal("issue_price"));
|
|
||||||
stockIpo.setSubscriptionDate(convertStringToTimestamp(entry.getString("open_date")));
|
|
||||||
stockIpo.setListingDate(convertStringToTimestamp(entry.getString("listing_date")));
|
|
||||||
Integer totalNumber = 0;
|
|
||||||
if(null!=entry.getInteger("issue_size")&&entry.getBigDecimal("issue_price")!=null&&!entry.getBigDecimal("issue_price").equals(BigDecimal.valueOf(0))){
|
|
||||||
Integer issue_size = entry.getInteger("issue_size");
|
|
||||||
BigDecimal issueSize = new BigDecimal(issue_size);
|
|
||||||
BigDecimal totalNumberBigDecimal = issueSize.divide(entry.getBigDecimal("issue_price"), 2, BigDecimal.ROUND_HALF_UP);
|
|
||||||
totalNumber = totalNumberBigDecimal.intValue();
|
|
||||||
}
|
|
||||||
stockIpo.setTotalNumber(totalNumber);
|
|
||||||
stockIpo.setApply(entry.getString("total_subs"));
|
|
||||||
stockIpo.setCreateDate(new Date());
|
|
||||||
stockIpo.setUpdateDate(new Date());
|
|
||||||
stockIpo.setSourceType("3");
|
|
||||||
|
|
||||||
if (stockIpo.getStockCode() == null || stockIpo.getStockName() == null){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> exchanges = getIpoExchange(stockIpo.getStockName(), stockIpo.getStockCode());
|
|
||||||
|
|
||||||
for (String exchange : exchanges) {
|
|
||||||
StockIpo ipo = new StockIpo();
|
|
||||||
ipo.setStockCode(stockIpo.getStockCode());
|
|
||||||
ipo.setStockName(stockIpo.getStockName());
|
|
||||||
ipo.setStockPrice(stockIpo.getStockPrice());
|
|
||||||
ipo.setSubscriptionDate(stockIpo.getSubscriptionDate());
|
|
||||||
ipo.setListingDate(stockIpo.getListingDate());
|
|
||||||
ipo.setTotalNumber(stockIpo.getTotalNumber());
|
|
||||||
ipo.setApply(stockIpo.getApply());
|
|
||||||
ipo.setCreateDate(stockIpo.getCreateDate());
|
|
||||||
ipo.setUpdateDate(stockIpo.getUpdateDate());
|
|
||||||
ipo.setExchangeType(exchange);
|
|
||||||
|
|
||||||
listStockIpoList.add(ipo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// stockIpoRepository.saveAll(listStockIpoList);
|
|
||||||
|
|
||||||
if (!listStockIpoList.isEmpty())
|
|
||||||
{
|
|
||||||
listStockIpoList = listStockIpoList.stream().filter(a -> StringUtils.isNotBlank(a.getStockName())).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
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 -> !existingStockScIds.contains(stockIpos.getStockCode())).filter(stockIpo -> StringUtils.isNotBlank(stockIpo.getStockName()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
//保存全部的新股
|
|
||||||
if(CollectionUtil.isNotEmpty(listStockIpoList)){
|
|
||||||
stockIpoRepository.saveAll(listStockIpoList);
|
|
||||||
|
|
||||||
log.info("定时任务执行获取新股ipo的方法开始结束,保存了数据:{}", JSON.toJSONString(listStockIpoList));
|
|
||||||
}else {
|
|
||||||
log.info("定时任务执行获取新股ipo的方法开始结束,没有数据");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 输出整个 JSON 数据
|
|
||||||
} else {
|
} else {
|
||||||
log.info("未找到包含 JSON 数据的 <script> 标签");
|
log.info("HTTP请求失败,状态码:" + response.getStatusLine().getStatusCode());
|
||||||
}
|
}
|
||||||
} else {
|
} catch (IOException e) {
|
||||||
log.info("HTTP请求失败,状态码:" + response.getStatusLine().getStatusCode());
|
log.error("获取新股接口发生异常",e);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
log.error("获取新股接口发生异常",e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 19 * * ?")
|
// @Scheduled(cron = "0 0 19 * * ?")
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
@RequestMapping("/addMoneyStock")
|
@RequestMapping("/addMoneyStock")
|
||||||
public void addMoneyStock() {
|
public void addMoneyStock() {
|
||||||
@@ -506,22 +528,23 @@ public class Scraper {
|
|||||||
public List<MoneyStock> convertToMoneyStock(List<StockIpo> stockIpoList) {
|
public List<MoneyStock> convertToMoneyStock(List<StockIpo> stockIpoList) {
|
||||||
// Lấy danh sách tất cả stockCode và exchangeType từ stockIpoList
|
// Lấy danh sách tất cả stockCode và exchangeType từ stockIpoList
|
||||||
Set<String> stockCodes = stockIpoList.stream().map(StockIpo::getStockCode).collect(Collectors.toSet());
|
Set<String> stockCodes = stockIpoList.stream().map(StockIpo::getStockCode).collect(Collectors.toSet());
|
||||||
Set<String> exchangeTypes = stockIpoList.stream().map(StockIpo::getExchangeType).collect(Collectors.toSet());
|
// Set<String> exchangeTypes = stockIpoList.stream().map(StockIpo::getExchangeType).collect(Collectors.toSet());
|
||||||
|
Set<String> exchangeTypes = stockIpoList.stream().map(stockIpo -> stockIpo.getExchangeType().toUpperCase()).collect(Collectors.toSet());
|
||||||
|
|
||||||
// Lấy tất cả các MoneyStock tồn tại trong database với stockCode và exchangeType trong stockIpoList
|
// Lấy tất cả các MoneyStock tồn tại trong database với stockCode và exchangeType trong stockIpoList
|
||||||
List<MoneyStock> existingMoneyStocks = moneyStockRepository.findAll(
|
List<MoneyStock> existingMoneyStocks = moneyStockRepository.findAll(
|
||||||
QMoneyStockPO.moneyStockPO.moneyScId.in(stockCodes)
|
QMoneyStockPO.moneyStockPO.moneyScId.in(stockCodes)
|
||||||
.and(QMoneyStockPO.moneyStockPO.stockType.in(exchangeTypes))
|
.and(QMoneyStockPO.moneyStockPO.stockType.upper().in(exchangeTypes))
|
||||||
);
|
);
|
||||||
|
|
||||||
// Lưu các stockCode và exchangeType đã tồn tại
|
// Lưu các stockCode và exchangeType đã tồn tại
|
||||||
Set<String> existingKeys = existingMoneyStocks.stream()
|
Set<String> existingKeys = existingMoneyStocks.stream()
|
||||||
.map(ms -> ms.getMoneyScId() + ms.getStockType())
|
.map(ms -> ms.getMoneyScId() + ms.getStockType().toUpperCase())
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
// Chỉ giữ những StockIpo chưa tồn tại
|
// Chỉ giữ những StockIpo chưa tồn tại
|
||||||
return stockIpoList.stream()
|
return stockIpoList.stream()
|
||||||
.filter(stockIpo -> !existingKeys.contains(stockIpo.getStockCode() + stockIpo.getExchangeType()))
|
.filter(stockIpo -> !existingKeys.contains(stockIpo.getStockCode() + stockIpo.getExchangeType().toUpperCase()))
|
||||||
.map(this::convert)
|
.map(this::convert)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
@@ -542,7 +565,7 @@ public class Scraper {
|
|||||||
moneyStock.setStockName(stockIpo.getStockName());
|
moneyStock.setStockName(stockIpo.getStockName());
|
||||||
moneyStock.setMoneyScId(stockIpo.getStockCode());
|
moneyStock.setMoneyScId(stockIpo.getStockCode());
|
||||||
moneyStock.setSelfDispId(stockIpo.getStockCode());
|
moneyStock.setSelfDispId(stockIpo.getStockCode());
|
||||||
moneyStock.setStockType(stockIpo.getExchangeType());
|
moneyStock.setStockType(stockIpo.getExchangeType().toUpperCase());
|
||||||
moneyStock.setSaveTime(DateTime.now());
|
moneyStock.setSaveTime(DateTime.now());
|
||||||
moneyStock.setNseIndiaId(getNSEId(stockIpo));
|
moneyStock.setNseIndiaId(getNSEId(stockIpo));
|
||||||
|
|
||||||
@@ -573,10 +596,10 @@ public class Scraper {
|
|||||||
|
|
||||||
JSONObject jsonData = jsonObject.getJSONObject("data");
|
JSONObject jsonData = jsonObject.getJSONObject("data");
|
||||||
|
|
||||||
if(stockIpo.getExchangeType().equals("NSE")){
|
if(stockIpo.getExchangeType().toUpperCase(Locale.ROOT).equals("NSE")){
|
||||||
return jsonData.getString("NSEID");
|
return jsonData.getString("NSEID");
|
||||||
}
|
}
|
||||||
else if(stockIpo.getExchangeType().equals("BSE")){
|
else if(stockIpo.getExchangeType().toUpperCase(Locale.ROOT).equals("BSE")){
|
||||||
return jsonData.getString("BSEID");
|
return jsonData.getString("BSEID");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,112 @@
|
|||||||
|
package cn.stock.market.infrastructure.job;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import cn.stock.market.domain.basic.entity.Stock;
|
||||||
|
import cn.stock.market.domain.basic.entity.StockTemp;
|
||||||
|
import cn.stock.market.domain.basic.repository.StockRepository;
|
||||||
|
import cn.stock.market.domain.basic.repository.StockTempRepository;
|
||||||
|
import cn.stock.market.dto.model.Symbol;
|
||||||
|
import cn.stock.market.infrastructure.db.po.StockPO;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
import org.json.*;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class StockNewTask {
|
||||||
|
private static final OkHttpClient client = new OkHttpClient();
|
||||||
|
private static final String BASE_URL = "https://symbol-search.tradingview.com/symbol_search/v3/";
|
||||||
|
private static final String PARAMS = "?start={start}&hl=1&country=DE&lang=en&search_type=stocks&domain=production&sort_by_country=US&promo=true&exchange={exchange}";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
StockRepository stockRepository;
|
||||||
|
|
||||||
|
|
||||||
|
// @PostConstruct
|
||||||
|
@Scheduled(cron = "0 01 22 * * ?")
|
||||||
|
public void syncStock() throws Exception {
|
||||||
|
|
||||||
|
int limit = 20000;
|
||||||
|
List<String> exchanges = Arrays.asList("BER", "DUS", "HAM", "HAN", "MUN", "SWB", "FWB", "XETR");
|
||||||
|
Map<String, Stock> stockGidMap = stockRepository.cacheGidMap();
|
||||||
|
for (String exchange : exchanges) {
|
||||||
|
List<Stock> newStocks = new ArrayList<>();
|
||||||
|
int start = 0;
|
||||||
|
int symbolsRemaining;
|
||||||
|
do {
|
||||||
|
int finalStart = start;
|
||||||
|
if(start > 0){
|
||||||
|
finalStart = start + 1;
|
||||||
|
}
|
||||||
|
String url = BASE_URL + PARAMS.replace("{start}", String.valueOf(finalStart)).replace("{exchange}", exchange);
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.addHeader("Origin", "https://www.tradingview.com")
|
||||||
|
.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
|
||||||
|
.addHeader("Accept", "application/json, text/plain, */*")
|
||||||
|
.addHeader("Referer", "https://www.tradingview.com/")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Response response = client.newCall(request).execute();
|
||||||
|
|
||||||
|
if (!response.isSuccessful()) {
|
||||||
|
throw new RuntimeException("Unexpected response code: " + response.code());
|
||||||
|
}
|
||||||
|
|
||||||
|
String responseBody = response.body().string();
|
||||||
|
JSONObject json = new JSONObject(responseBody);
|
||||||
|
JSONArray symbols = json.getJSONArray("symbols");
|
||||||
|
symbolsRemaining = json.getInt("symbols_remaining");
|
||||||
|
|
||||||
|
for (int i = 0; i < symbols.length(); i++) {
|
||||||
|
JSONObject s = symbols.getJSONObject(i);
|
||||||
|
if (s.optString("type").equals("stock") && !stockGidMap.containsKey(s.optString("exchange") + ":" + s.getString("symbol"))) {
|
||||||
|
Stock stock = new Stock();
|
||||||
|
stock.setStockGid(s.optString("exchange") + ":" +s.getString("symbol"));
|
||||||
|
stock.setStockCode(stock.getStockGid());
|
||||||
|
stock.setStockSpell(s.optString("symbol"));
|
||||||
|
stock.setStockName(s.optString("description"));
|
||||||
|
stock.setStockSymbol(s.optString("symbol"));
|
||||||
|
stock.setStockType(s.optString("exchange"));
|
||||||
|
stock.setIsLock(0);
|
||||||
|
stock.setIsShow(0);
|
||||||
|
stock.setAddTime(new Date());
|
||||||
|
stock.setStockState(0);
|
||||||
|
stock.setStockPlate("https://s3-symbol-logo.tradingview.com/" + s.optString("source_logoid") + "--big.svg");
|
||||||
|
newStocks.add(stock);
|
||||||
|
stockGidMap.put(s.optString("exchange") + ":" + s.getString("symbol"), stock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Thread.sleep(500);
|
||||||
|
|
||||||
|
start += symbols.length();
|
||||||
|
System.out.println("Fetched: " + symbols.length() + ", Remaining: " + symbolsRemaining);
|
||||||
|
try {
|
||||||
|
if (!newStocks.isEmpty()) {
|
||||||
|
stockRepository.saveAll(newStocks);
|
||||||
|
}
|
||||||
|
}catch (Exception e) {
|
||||||
|
log.error("Insert stock failed: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start >= limit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
} while (symbolsRemaining > 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -112,7 +112,7 @@ public class StockTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*同步股票列表*/
|
/*同步股票列表*/
|
||||||
@Scheduled(cron = "0 0 6 * * ?")
|
// @Scheduled(cron = "0 0 6 * * ?")
|
||||||
public void syncAFutureStockList() {
|
public void syncAFutureStockList() {
|
||||||
PageInfo<JSONObject> info = EastmoneyApi.ipoApplyDate(1, 300);
|
PageInfo<JSONObject> info = EastmoneyApi.ipoApplyDate(1, 300);
|
||||||
Map<String, Stock> stockMap = StockRepository.of().cacheCodeMap();
|
Map<String, Stock> stockMap = StockRepository.of().cacheCodeMap();
|
||||||
@@ -154,7 +154,7 @@ public class StockTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*同步股票列表*/
|
/*同步股票列表*/
|
||||||
@Scheduled(cron = "0 0 6 * * ?")
|
// @Scheduled(cron = "0 0 6 * * ?")
|
||||||
public void syncAStockList() {
|
public void syncAStockList() {
|
||||||
MdcUtil.setTraceIdIfAbsent();
|
MdcUtil.setTraceIdIfAbsent();
|
||||||
Config config = SpringUtils.getBean(Config.class);
|
Config config = SpringUtils.getBean(Config.class);
|
||||||
|
|||||||
@@ -265,6 +265,56 @@ public class HttpClientRequest {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String doGetNews(String url) {
|
||||||
|
CloseableHttpClient httpClient = null;
|
||||||
|
CloseableHttpResponse response = null;
|
||||||
|
String result = "";
|
||||||
|
|
||||||
|
try {
|
||||||
|
httpClient = HttpClients.createDefault();
|
||||||
|
|
||||||
|
HttpGet httpGet = new HttpGet(url);
|
||||||
|
|
||||||
|
// Spoof real browser headers
|
||||||
|
httpGet.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
|
||||||
|
httpGet.setHeader("Accept-Language", "en-US,en;q=0.9,vi;q=0.8,ug;q=0.7,fr;q=0.6");
|
||||||
|
httpGet.setHeader("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1");
|
||||||
|
httpGet.setHeader("Priority", "u=0, i");
|
||||||
|
httpGet.setHeader("Sec-Fetch-Dest", "document");
|
||||||
|
httpGet.setHeader("Sec-Fetch-Mode", "navigate");
|
||||||
|
httpGet.setHeader("Sec-Fetch-Site", "none");
|
||||||
|
httpGet.setHeader("Sec-Fetch-User", "?1");
|
||||||
|
httpGet.setHeader("Upgrade-Insecure-Requests", "1");
|
||||||
|
|
||||||
|
// Set cookies exactly like in curl
|
||||||
|
httpGet.setHeader("Cookie", "userUid=1747102033185-d570fba9-62fd-40be-93ca-ed08b4de57d4; _sid=MTc0NzEwMjAzMzE4Ni4ycTU%3D; _scor_uid=135c13065ff84620b5318b489af93e87; _gcl_au=1.1.249135292.1747102036; _ga=GA1.1.1031614211.1747102037; WZRK_G=28895afb56ff48dda59fe8de0af746bf; FCNEC=%5B%5B%22AKsRol8sHYeSYz_FYPkInYXN3P4ZDPfVKbsRfILfDuOMLhDtkTuoCJP5MlvT9gIbOe7IlDfY8ZeHszhwdVtAoKF1gWv0pLAq5EqpLpse8CEm_ZNv-bUSs6zEyqpOkeKWFI_Ei6VfNAvnZAO8PcXdF8_ncsaO902X7g%3D%3D%22%5D%5D; _ga_KRGL1M61LX=GS2.1.s1747105135$o2$g0$t1747105135$j60$l0$h0");
|
||||||
|
|
||||||
|
RequestConfig requestConfig = RequestConfig.custom()
|
||||||
|
.setConnectTimeout(10000)
|
||||||
|
.setSocketTimeout(15000)
|
||||||
|
.setConnectionRequestTimeout(10000)
|
||||||
|
.build();
|
||||||
|
httpGet.setConfig(requestConfig);
|
||||||
|
|
||||||
|
response = httpClient.execute(httpGet);
|
||||||
|
HttpEntity entity = response.getEntity();
|
||||||
|
|
||||||
|
if (entity != null) {
|
||||||
|
result = EntityUtils.toString(entity);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (response != null) response.close();
|
||||||
|
if (httpClient != null) httpClient.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String url = "https://marketapi.intoday.in/widget/topgainer/view?exchange=nse";
|
String url = "https://marketapi.intoday.in/widget/topgainer/view?exchange=nse";
|
||||||
String str = doGet(url);
|
String str = doGet(url);
|
||||||
|
|||||||
@@ -816,7 +816,7 @@ public class MoneyApiController {
|
|||||||
for (String dateStr : dates) {
|
for (String dateStr : dates) {
|
||||||
try {
|
try {
|
||||||
Date date = sdf.parse(dateStr);
|
Date date = sdf.parse(dateStr);
|
||||||
list.add(date.getTime());
|
list.add(date.getTime() / 1000);
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -827,7 +827,7 @@ public class MoneyApiController {
|
|||||||
try {
|
try {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a", Locale.US);
|
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a", Locale.US);
|
||||||
Date date = sdf.parse(dateStr);
|
Date date = sdf.parse(dateStr);
|
||||||
return date.getTime();
|
return date.getTime() / 1000;
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return 0L;
|
return 0L;
|
||||||
@@ -980,6 +980,33 @@ public class MoneyApiController {
|
|||||||
response.setC(closeList);
|
response.setC(closeList);
|
||||||
response.setV(volumeList);
|
response.setV(volumeList);
|
||||||
|
|
||||||
|
// if (resolution.equals("H")) {
|
||||||
|
// Set<String> desiredTimes = new HashSet<>(Arrays.asList("09:30", "10:30", "11:30", "12:30", "13:30", "14:30"));
|
||||||
|
//
|
||||||
|
// // Filter data based on timestamps
|
||||||
|
// SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
|
||||||
|
// List<Integer> indicesToKeep = new ArrayList<>();
|
||||||
|
// for (int i = 0; i < dateList.size(); i++) {
|
||||||
|
// String time = sdf.format(new Date(dateList.get(i) * 1000));
|
||||||
|
// if (desiredTimes.contains(time)) {
|
||||||
|
// indicesToKeep.add(i);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Filter corresponding data
|
||||||
|
// List<Long> filteredT = indicesToKeep.stream().map(dateList::get).collect(Collectors.toList());
|
||||||
|
// List<Double> filteredO = indicesToKeep.stream().map(openList::get).collect(Collectors.toList());
|
||||||
|
// List<Double> filteredH = indicesToKeep.stream().map(highList::get).collect(Collectors.toList());
|
||||||
|
// List<Double> filteredL = indicesToKeep.stream().map(lowList::get).collect(Collectors.toList());
|
||||||
|
// List<Double> filteredC = indicesToKeep.stream().map(closeList::get).collect(Collectors.toList());
|
||||||
|
// List<Long> filteredV = indicesToKeep.stream().map(volumeList::get).collect(Collectors.toList());
|
||||||
|
// response.setT(filteredT);
|
||||||
|
// response.setO(filteredO);
|
||||||
|
// response.setH(filteredH);
|
||||||
|
// response.setL(filteredL);
|
||||||
|
// response.setC(filteredC);
|
||||||
|
// response.setV(filteredV);
|
||||||
|
// }
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,13 +26,14 @@ public class MoneyProxyApiControl {
|
|||||||
|
|
||||||
@GetMapping({"/market/api/proxy/queryStockMoneyProxy","/api/proxy/queryStockMoneyProxy"})
|
@GetMapping({"/market/api/proxy/queryStockMoneyProxy","/api/proxy/queryStockMoneyProxy"})
|
||||||
public JSONObject queryStockByMoneyIdAndExchangeType(String scId,String exchangeType){
|
public JSONObject queryStockByMoneyIdAndExchangeType(String scId,String exchangeType){
|
||||||
|
log.info("queryStockByMoneyIdAndExchangeType");
|
||||||
return stockByMoneyIdAndExchangeTypeFromHttp(scId,exchangeType);
|
return stockByMoneyIdAndExchangeTypeFromHttp(scId,exchangeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static JSONObject stockByMoneyIdAndExchangeTypeFromHttp(String scId, String exchangeType) {
|
public static JSONObject stockByMoneyIdAndExchangeTypeFromHttp(String scId, String exchangeType) {
|
||||||
try {
|
try {
|
||||||
String url = "https://priceapi.moneycontrol.com/pricefeed/"+exchangeType+"/equitycash/" + scId ;
|
String url = "https://moneycontrol.titanrwa.org/pricefeed/"+exchangeType+"/equitycash/" + scId ;
|
||||||
URL obj = new URL(url);
|
URL obj = new URL(url);
|
||||||
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
||||||
con.setRequestMethod("GET");
|
con.setRequestMethod("GET");
|
||||||
@@ -53,7 +54,8 @@ public class MoneyProxyApiControl {
|
|||||||
log.error("HTTP request failed with response code: " + responseCode);
|
log.error("HTTP request failed with response code: " + responseCode);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("stockByMoneyIdAndExchangeTypeFromHttp",e);
|
e.printStackTrace();
|
||||||
|
log.error("stockByMoneyIdAndExchangeTypeFromHttp failed {}",e.getMessage());
|
||||||
}
|
}
|
||||||
return new JSONObject();
|
return new JSONObject();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -249,8 +249,12 @@ public class StockApiController {
|
|||||||
public ServerResponse getIndiaIndexByToday() {
|
public ServerResponse getIndiaIndexByToday() {
|
||||||
String INDEX_CODE = "TODAY_INDEX";
|
String INDEX_CODE = "TODAY_INDEX";
|
||||||
return RequestCacheUtils.cache("getIndiaIndexByToday.do", INDEX_CODE,6000, (string) -> {
|
return RequestCacheUtils.cache("getIndiaIndexByToday.do", INDEX_CODE,6000, (string) -> {
|
||||||
return this.stockService.getIndexByBtoday();
|
try {
|
||||||
});
|
return this.stockService.getIndexByBtoday();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
@RequestMapping({"getIndiaIndexByEttech.do"})
|
@RequestMapping({"getIndiaIndexByEttech.do"})
|
||||||
@ApiOperation(value = "印度--获取指定指数信息-Ettech", httpMethod = "GET")
|
@ApiOperation(value = "印度--获取指定指数信息-Ettech", httpMethod = "GET")
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ spring:
|
|||||||
show-sql: true
|
show-sql: true
|
||||||
# Redis配置
|
# Redis配置
|
||||||
redis:
|
redis:
|
||||||
host: 43.156.40.39
|
host: 43.153.142.41
|
||||||
password: a5v8b86P4mVzFlUqJV
|
password: a5v8b86P4mVzFlUqJV
|
||||||
port: 30031
|
port: 30041
|
||||||
database: 1
|
database: 1
|
||||||
lettuce:
|
lettuce:
|
||||||
pool:
|
pool:
|
||||||
@@ -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.142.41:30040/germany_stock?useUnicode=true&characterEncoding=utf-8
|
||||||
username: root
|
username: root
|
||||||
password: uNejHIFQGJOUtYTmE
|
password: uNejHIFQGJOUtYTmE
|
||||||
maxActive: 500
|
maxActive: 500
|
||||||
|
|||||||
Reference in New Issue
Block a user