Compare commits
4 Commits
bug/update
...
twelvedata
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f565132607 | ||
|
|
67a3d6fd74 | ||
|
|
c8b0bcd336 | ||
|
|
a12000f99e |
@@ -2,7 +2,7 @@ stages:
|
|||||||
# 构建
|
# 构建
|
||||||
- build
|
- build
|
||||||
- dockerize
|
- dockerize
|
||||||
- deploy
|
- webhook
|
||||||
|
|
||||||
build:
|
build:
|
||||||
image: maven:3.6.3-openjdk-8
|
image: maven:3.6.3-openjdk-8
|
||||||
@@ -60,20 +60,16 @@ dockerize:
|
|||||||
- docker push juyoutech/india_stock_market:latest
|
- docker push juyoutech/india_stock_market:latest
|
||||||
- docker push juyoutech/india_stock_market:$CI_PIPELINE_ID
|
- docker push juyoutech/india_stock_market:$CI_PIPELINE_ID
|
||||||
- docker push juyoutech/india_stock_market:$CI_COMMIT_BRANCH
|
- docker push juyoutech/india_stock_market:$CI_COMMIT_BRANCH
|
||||||
deploy-dev:
|
webhook:
|
||||||
stage: deploy
|
stage: webhook
|
||||||
only:
|
only:
|
||||||
- develop
|
- develop
|
||||||
script:
|
script:
|
||||||
- echo "Deploying application..."
|
- echo ">>>>>>Start Deploy<<<<<<"
|
||||||
- ls
|
- ls
|
||||||
- apt-get update
|
- apt-get update
|
||||||
- apt-get install -y curl
|
- apt-get install -y curl
|
||||||
- |
|
- curl --max-time 30 http://149.88.86.7:11113/api/webhook/justpull?project=india_market_java\&setenv_file=alpha.sh\&publish_env=alpha\&shell=deploy-test.sh
|
||||||
curl -X POST \
|
- echo ">>>>>>Start Deploy Finish<<<<<<"
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{"namespace":"yddev", "deployment_name":"india-stock-market"}' \
|
|
||||||
https://updater-yddev.moneytj.com/restart-deployment
|
|
||||||
- echo "Application successfully deployed."
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
6
pom.xml
6
pom.xml
@@ -185,12 +185,6 @@
|
|||||||
<version>30.1-jre</version>
|
<version>30.1-jre</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
|
||||||
<artifactId>httpclient</artifactId>
|
|
||||||
<version>4.5.13</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
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;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* QOptionalStockPO is a Querydsl query type for OptionalStockPO
|
|
||||||
*/
|
|
||||||
@Generated("com.querydsl.codegen.EntitySerializer")
|
|
||||||
public class QOptionalStockPO extends EntityPathBase<OptionalStockPO> {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1161631810L;
|
|
||||||
|
|
||||||
public static final QOptionalStockPO optionalStockPO = new QOptionalStockPO("optionalStockPO");
|
|
||||||
|
|
||||||
public final StringPath company = createString("company");
|
|
||||||
|
|
||||||
public final NumberPath<Integer> id = createNumber("id", Integer.class);
|
|
||||||
|
|
||||||
public final StringPath symbol = createString("symbol");
|
|
||||||
|
|
||||||
public QOptionalStockPO(String variable) {
|
|
||||||
super(OptionalStockPO.class, forVariable(variable));
|
|
||||||
}
|
|
||||||
|
|
||||||
public QOptionalStockPO(Path<? extends OptionalStockPO> path) {
|
|
||||||
super(path.getType(), path.getMetadata());
|
|
||||||
}
|
|
||||||
|
|
||||||
public QOptionalStockPO(PathMetadata metadata) {
|
|
||||||
super(OptionalStockPO.class, metadata);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -38,7 +38,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,49 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QTwelveStockPO is a Querydsl query type for TwelveStockPO
|
||||||
|
*/
|
||||||
|
@Generated("com.querydsl.codegen.EntitySerializer")
|
||||||
|
public class QTwelveStockPO extends EntityPathBase<TwelveStockPO> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -100071895L;
|
||||||
|
|
||||||
|
public static final QTwelveStockPO twelveStockPO = new QTwelveStockPO("twelveStockPO");
|
||||||
|
|
||||||
|
public final NumberPath<Integer> id = createNumber("id", Integer.class);
|
||||||
|
|
||||||
|
public final NumberPath<Integer> isLock = createNumber("isLock", Integer.class);
|
||||||
|
|
||||||
|
public final NumberPath<Integer> isShow = createNumber("isShow", Integer.class);
|
||||||
|
|
||||||
|
public final DateTimePath<java.util.Date> saveTime = createDateTime("saveTime", java.util.Date.class);
|
||||||
|
|
||||||
|
public final StringPath stockCode = createString("stockCode");
|
||||||
|
|
||||||
|
public final StringPath stockName = createString("stockName");
|
||||||
|
|
||||||
|
public final StringPath stockType = createString("stockType");
|
||||||
|
|
||||||
|
public QTwelveStockPO(String variable) {
|
||||||
|
super(TwelveStockPO.class, forVariable(variable));
|
||||||
|
}
|
||||||
|
|
||||||
|
public QTwelveStockPO(Path<? extends TwelveStockPO> path) {
|
||||||
|
super(path.getType(), path.getMetadata());
|
||||||
|
}
|
||||||
|
|
||||||
|
public QTwelveStockPO(PathMetadata metadata) {
|
||||||
|
super(TwelveStockPO.class, metadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package cn.stock.market.application.assembler;
|
||||||
|
|
||||||
|
import cn.qutaojing.common.utils.Beans;
|
||||||
|
import cn.qutaojing.common.utils.SpringUtils;
|
||||||
|
import cn.stock.market.domain.basic.entity.TwelveStock;
|
||||||
|
import cn.stock.market.dto.TwelveStockDTO;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TwelveStockAssembler
|
||||||
|
*
|
||||||
|
* @author rplees
|
||||||
|
* @email rplees.i.ly@gmail.com
|
||||||
|
* @created 2024/05/30
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Lazy
|
||||||
|
public class TwelveStockAssembler {
|
||||||
|
public TwelveStockDTO toDTO(TwelveStock e) {
|
||||||
|
TwelveStockDTO dto = Beans.mapper(e, TwelveStockDTO.class);
|
||||||
|
if(dto == null) return dto;
|
||||||
|
fill(e, dto);
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fill(TwelveStock e, TwelveStockDTO dto) {
|
||||||
|
if(dto == null) return;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TwelveStockAssembler of() {
|
||||||
|
return SpringUtils.getBean(TwelveStockAssembler.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
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.OptionalStock;
|
|
||||||
import cn.stock.market.infrastructure.db.po.OptionalStockPO;
|
|
||||||
import org.springframework.context.annotation.Lazy;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@Lazy
|
|
||||||
public class OptionalStockConvert extends SimpleEntityPOConvert<OptionalStock, OptionalStockPO> {
|
|
||||||
public static OptionalStockConvert of() {
|
|
||||||
return SpringUtils.getBean(OptionalStockConvert.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
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.TwelveStock;
|
||||||
|
import cn.stock.market.infrastructure.db.po.TwelveStockPO;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TwelveStockConvert
|
||||||
|
*
|
||||||
|
* @author rplees
|
||||||
|
* @email rplees.i.ly@gmail.com
|
||||||
|
* @created 2024/05/30
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Lazy
|
||||||
|
public class TwelveStockConvert extends SimpleEntityPOConvert<TwelveStock, TwelveStockPO> {
|
||||||
|
public static TwelveStockConvert of() {
|
||||||
|
return SpringUtils.getBean(TwelveStockConvert.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package cn.stock.market.domain.basic.entity;
|
|
||||||
|
|
||||||
import cn.stock.market.infrastructure.db.po.OptionalStockPO;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.experimental.SuperBuilder;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@NoArgsConstructor
|
|
||||||
@SuperBuilder
|
|
||||||
@EqualsAndHashCode(
|
|
||||||
callSuper = false
|
|
||||||
)
|
|
||||||
public class OptionalStock extends OptionalStockPO {
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package cn.stock.market.domain.basic.entity;
|
||||||
|
|
||||||
|
import cn.qutaojing.common.utils.Beans;
|
||||||
|
import cn.stock.market.dto.command.TwelveStockCreateCommand;
|
||||||
|
import cn.stock.market.infrastructure.db.po.TwelveStockPO;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TwelveStock
|
||||||
|
*
|
||||||
|
* @author rplees
|
||||||
|
* @email rplees.i.ly@gmail.com
|
||||||
|
* @created 2024/05/30
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@SuperBuilder
|
||||||
|
@EqualsAndHashCode(
|
||||||
|
callSuper = false
|
||||||
|
)
|
||||||
|
public class TwelveStock extends TwelveStockPO {
|
||||||
|
public void update(TwelveStockCreateCommand cmd) {
|
||||||
|
Beans.copyProperties(cmd, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package cn.stock.market.domain.basic.factory;
|
||||||
|
|
||||||
|
import cn.qutaojing.common.utils.SpringUtils;
|
||||||
|
import cn.stock.market.domain.basic.entity.TwelveStock;
|
||||||
|
import cn.stock.market.dto.command.TwelveStockCreateCommand;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TwelveStockFactory
|
||||||
|
*
|
||||||
|
* @author rplees
|
||||||
|
* @email rplees.i.ly@gmail.com
|
||||||
|
* @created 2024/05/30
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Lazy
|
||||||
|
public class TwelveStockFactory {
|
||||||
|
public static TwelveStockFactory of() {
|
||||||
|
return SpringUtils.getBean(TwelveStockFactory.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TwelveStock from(TwelveStockCreateCommand cmd) {
|
||||||
|
TwelveStock e = TwelveStock.builder().build();
|
||||||
|
e.update(cmd);
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package cn.stock.market.domain.basic.repository;
|
|
||||||
|
|
||||||
import cn.qutaojing.common.domain.convert.IEntityPOConvert;
|
|
||||||
import cn.qutaojing.common.domain.respostory.SimplePoConvertEntityRepository;
|
|
||||||
import cn.stock.market.domain.basic.convert.OptionalStockConvert;
|
|
||||||
import cn.stock.market.domain.basic.entity.OptionalStock;
|
|
||||||
import cn.stock.market.infrastructure.db.po.OptionalStockPO;
|
|
||||||
import cn.stock.market.infrastructure.db.repo.OptionalStockRepo;
|
|
||||||
import com.rp.spring.jpa.GenericJpaRepository;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
@RequiredArgsConstructor(
|
|
||||||
onConstructor = @__(@Autowired)
|
|
||||||
)
|
|
||||||
public class OptionalStockRepository extends SimplePoConvertEntityRepository<OptionalStock, OptionalStockPO, Integer> {
|
|
||||||
final OptionalStockRepo repo;
|
|
||||||
|
|
||||||
final OptionalStockConvert convert;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GenericJpaRepository<OptionalStockPO, Integer> repo() {
|
|
||||||
return repo;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IEntityPOConvert<OptionalStock, OptionalStockPO> convert() {
|
|
||||||
return convert;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package cn.stock.market.domain.basic.repository;
|
||||||
|
|
||||||
|
import cn.qutaojing.common.domain.convert.IEntityPOConvert;
|
||||||
|
import cn.qutaojing.common.domain.respostory.SimplePoConvertEntityRepository;
|
||||||
|
import cn.qutaojing.common.utils.SpringUtils;
|
||||||
|
import cn.stock.market.domain.basic.convert.TwelveStockConvert;
|
||||||
|
import cn.stock.market.domain.basic.entity.TwelveStock;
|
||||||
|
import cn.stock.market.infrastructure.db.po.TwelveStockPO;
|
||||||
|
import cn.stock.market.infrastructure.db.repo.TwelveStockRepo;
|
||||||
|
import com.rp.spring.jpa.GenericJpaRepository;
|
||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.Override;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TwelveStockRepository
|
||||||
|
*
|
||||||
|
* @author rplees
|
||||||
|
* @email rplees.i.ly@gmail.com
|
||||||
|
* @created 2024/05/30
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
@RequiredArgsConstructor(
|
||||||
|
onConstructor = @__(@Autowired)
|
||||||
|
)
|
||||||
|
public class TwelveStockRepository extends SimplePoConvertEntityRepository<TwelveStock, TwelveStockPO, Integer> {
|
||||||
|
final TwelveStockRepo repo;
|
||||||
|
|
||||||
|
final TwelveStockConvert convert;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GenericJpaRepository<TwelveStockPO, Integer> repo() {
|
||||||
|
return repo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IEntityPOConvert<TwelveStock, TwelveStockPO> convert() {
|
||||||
|
return convert;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TwelveStockRepository of() {
|
||||||
|
return SpringUtils.getBean(TwelveStockRepository.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,8 +30,6 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import cn.stock.market.infrastructure.db.po.QStockPO;
|
import cn.stock.market.infrastructure.db.po.QStockPO;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpEntity;
|
||||||
@@ -249,25 +247,12 @@ public class StockService {
|
|||||||
String result = "";
|
String result = "";
|
||||||
try {
|
try {
|
||||||
// 使用Jsoup连接到网页
|
// 使用Jsoup连接到网页
|
||||||
// Document doc = Jsoup.connect("https://www.business-standard.com/markets/news")
|
Document doc = Jsoup.connect("https://www.business-standard.com/markets/news")
|
||||||
// .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("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("Referer", "https://www.business-standard.com/")
|
||||||
// .header("Accept-Language", "en-US,en;q=0.9")
|
|
||||||
// .get();
|
|
||||||
String url = "https://www.business-standard.com/markets/news";
|
|
||||||
Document doc = Jsoup.connect(url)
|
|
||||||
.referrer("https://www.business-standard.com/")
|
|
||||||
.header("Accept-Language", "en-US,en;q=0.9")
|
.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();
|
.get();
|
||||||
// result = doc.html().substring(doc.html().indexOf("<div class=\"listingstyle_shortvideoimg__0TWuX shortvideoimg\">"),doc.html().lastIndexOf("<div class=\"listingstyle_shortvideoimg__0TWuX shortvideoimg\">")+500);
|
result = doc.html().substring(doc.html().indexOf("<div class=\"shortvideoimg\" style=\"position:relative\">"),doc.html().lastIndexOf("<div class=\"shortvideoimg\" style=\"position:relative\">")+1200);
|
||||||
Elements divElements = doc.select("div.listingstyle_cardlistlist__dfq57");
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (Element divElement : divElements) {
|
|
||||||
sb.append(divElement.outerHtml()).append("\n");
|
|
||||||
}
|
|
||||||
result = sb.toString();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return e.toString();
|
return e.toString();
|
||||||
}
|
}
|
||||||
@@ -279,16 +264,10 @@ public class StockService {
|
|||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
// 使用Jsoup连接到网页
|
// 使用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)
|
Document doc = Jsoup.connect(url)
|
||||||
.referrer("https://www.business-standard.com/")
|
.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")
|
.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();
|
.get();
|
||||||
result = doc.html().substring(doc.html().indexOf("articleBody") + 14, doc.html().indexOf(",\"author\":") - 1);
|
result = doc.html().substring(doc.html().indexOf("articleBody") + 14, doc.html().indexOf(",\"author\":") - 1);
|
||||||
list.add(result);
|
list.add(result);
|
||||||
@@ -995,7 +974,7 @@ public class StockService {
|
|||||||
String exchange = "bse";
|
String exchange = "bse";
|
||||||
IndiaIndexVo vo1 = new IndiaIndexVo();
|
IndiaIndexVo vo1 = new IndiaIndexVo();
|
||||||
String coCode = "20558";
|
String coCode = "20558";
|
||||||
JSONObject object = TodayApis.getStockDetail("in%3BSEN", coCode);
|
JSONObject object = TodayApis.getStockDetail(exchange, coCode);
|
||||||
IndiaStockVO market = objToVo(object);
|
IndiaStockVO market = objToVo(object);
|
||||||
market.setName("BSESENSEX指数");
|
market.setName("BSESENSEX指数");
|
||||||
vo1.setIndexVo(market);
|
vo1.setIndexVo(market);
|
||||||
@@ -1025,7 +1004,7 @@ public class StockService {
|
|||||||
String exchange = "nse";
|
String exchange = "nse";
|
||||||
IndiaIndexVo vo1 = new IndiaIndexVo();
|
IndiaIndexVo vo1 = new IndiaIndexVo();
|
||||||
String coCode = "20559";
|
String coCode = "20559";
|
||||||
JSONObject object = TodayApis.getStockDetail("in%3BNSX", coCode);
|
JSONObject object = TodayApis.getStockDetail(exchange, coCode);
|
||||||
IndiaStockVO market = objToVo(object);
|
IndiaStockVO market = objToVo(object);
|
||||||
market.setName("NIFTY50指数");
|
market.setName("NIFTY50指数");
|
||||||
vo1.setIndexVo(market);
|
vo1.setIndexVo(market);
|
||||||
@@ -1055,23 +1034,23 @@ public class StockService {
|
|||||||
}
|
}
|
||||||
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("prev_close")){
|
||||||
market.setClose(object.getString("priceprevclose"));
|
market.setClose(object.getString("prev_close"));
|
||||||
}
|
}
|
||||||
if(object.containsKey("pricecurrent")){
|
if(object.containsKey("price")){
|
||||||
market.setNowPrice(object.getString("pricecurrent"));
|
market.setNowPrice(object.getString("price"));
|
||||||
}
|
}
|
||||||
if(object.containsKey("pricepercentchange")){
|
if(object.containsKey("perchg")){
|
||||||
market.setRate(object.getString("pricepercentchange"));
|
market.setRate(object.getString("perchg"));
|
||||||
}
|
}
|
||||||
if(object.containsKey("HIGH")){
|
if(object.containsKey("high_price")){
|
||||||
market.setHigh(object.getString("HIGH"));
|
market.setHigh(object.getString("high_price"));
|
||||||
}
|
}
|
||||||
if(object.containsKey("LOW")){
|
if(object.containsKey("low_price")){
|
||||||
market.setLow(object.getString("LOW"));
|
market.setLow(object.getString("low_price"));
|
||||||
}
|
}
|
||||||
if(object.containsKey("OPEN")){
|
if(object.containsKey("open_price")){
|
||||||
market.setOpen(object.getString("OPEN"));
|
market.setOpen(object.getString("open_price"));
|
||||||
}
|
}
|
||||||
return market;
|
return market;
|
||||||
// stockListVO.setName(jsonObject.getString("companyname"));
|
// stockListVO.setName(jsonObject.getString("companyname"));
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package cn.stock.market.domain.basic.service;
|
||||||
|
|
||||||
|
import cn.qutaojing.common.utils.SpringUtils;
|
||||||
|
import cn.stock.market.domain.basic.factory.TwelveStockFactory;
|
||||||
|
import cn.stock.market.domain.basic.repository.TwelveStockRepository;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TwelveStockService
|
||||||
|
*
|
||||||
|
* @author rplees
|
||||||
|
* @email rplees.i.ly@gmail.com
|
||||||
|
* @created 2024/05/30
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor(
|
||||||
|
onConstructor = @__(@Autowired)
|
||||||
|
)
|
||||||
|
public class TwelveStockService {
|
||||||
|
final TwelveStockRepository repository;
|
||||||
|
|
||||||
|
final TwelveStockFactory factory;
|
||||||
|
|
||||||
|
public TwelveStockRepository repository() {
|
||||||
|
return repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TwelveStockService of() {
|
||||||
|
return SpringUtils.getBean(TwelveStockService.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package cn.stock.market.dto;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class OptionalStockResponse {
|
|
||||||
private String message;
|
|
||||||
private Integer code;
|
|
||||||
private DataResponse data = new DataResponse();
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class DataResponse {
|
|
||||||
private String symbol;
|
|
||||||
private String company;
|
|
||||||
private Double pricecurrent;
|
|
||||||
private Float pricepercentchange;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
23
src/main/java/cn/stock/market/dto/TwelveStockDTO.java
Normal file
23
src/main/java/cn/stock/market/dto/TwelveStockDTO.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package cn.stock.market.dto;
|
||||||
|
|
||||||
|
import cn.stock.market.infrastructure.db.po.TwelveStockPO;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TwelveStockDTO
|
||||||
|
*
|
||||||
|
* @author rplees
|
||||||
|
* @email rplees.i.ly@gmail.com
|
||||||
|
* @created 2024/05/30
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@SuperBuilder
|
||||||
|
@EqualsAndHashCode(
|
||||||
|
callSuper = false
|
||||||
|
)
|
||||||
|
public class TwelveStockDTO extends TwelveStockPO {
|
||||||
|
}
|
||||||
22
src/main/java/cn/stock/market/dto/TwelveStockData.java
Normal file
22
src/main/java/cn/stock/market/dto/TwelveStockData.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package cn.stock.market.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class TwelveStockData {
|
||||||
|
|
||||||
|
private String symbol;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String currency;
|
||||||
|
|
||||||
|
private String exchange;
|
||||||
|
|
||||||
|
private String mic_code;
|
||||||
|
|
||||||
|
private String country;
|
||||||
|
|
||||||
|
private String type;
|
||||||
|
}
|
||||||
|
|
||||||
61
src/main/java/cn/stock/market/dto/TwelveStockInfo.java
Normal file
61
src/main/java/cn/stock/market/dto/TwelveStockInfo.java
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
package cn.stock.market.dto;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
/**
|
||||||
|
* TwelveStockInfo类用于存储股票信息。
|
||||||
|
* 该类包含了股票的基本信息和交易数据。
|
||||||
|
*/
|
||||||
|
@ApiModel("TwelveStockInfo")
|
||||||
|
public class TwelveStockInfo {
|
||||||
|
@ApiModelProperty("股票代码")
|
||||||
|
private String stockCode;
|
||||||
|
|
||||||
|
@ApiModelProperty("交易代码")
|
||||||
|
private String symbol;
|
||||||
|
|
||||||
|
@ApiModelProperty("股票名称")
|
||||||
|
private String stockName;
|
||||||
|
|
||||||
|
@ApiModelProperty("股票类型")
|
||||||
|
private String stockType;
|
||||||
|
|
||||||
|
@ApiModelProperty("当前价格")
|
||||||
|
private String lastPrice;
|
||||||
|
|
||||||
|
@ApiModelProperty("变动百分比")
|
||||||
|
private String perchg;
|
||||||
|
@ApiModelProperty("变动值")
|
||||||
|
private String change;
|
||||||
|
|
||||||
|
@ApiModelProperty("开盘价格")
|
||||||
|
private String openPrice;
|
||||||
|
|
||||||
|
@ApiModelProperty("昨日收盘价格")
|
||||||
|
private String previousPrice;
|
||||||
|
|
||||||
|
@ApiModelProperty("成交量")
|
||||||
|
private String volume;
|
||||||
|
|
||||||
|
@ApiModelProperty("最高价格")
|
||||||
|
private String highPrice;
|
||||||
|
|
||||||
|
@ApiModelProperty("最低价格")
|
||||||
|
private String lowPrice;
|
||||||
|
|
||||||
|
@ApiModelProperty("52周最高价格")
|
||||||
|
private String week52HighPrice;
|
||||||
|
|
||||||
|
@ApiModelProperty("52周最低价格")
|
||||||
|
private String week52LowPrice;
|
||||||
|
|
||||||
|
@ApiModelProperty("股票当前的交易状态: 1-表示退市Closed, 2-Opening Auction, 3-Continuous Trading, 15-Intra-day Close (scheduled)")
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
@ApiModelProperty("股票id")
|
||||||
|
private Integer id;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package cn.stock.market.dto.command;
|
||||||
|
|
||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.String;
|
||||||
|
import java.util.Date;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TwelveStockCreateCommand
|
||||||
|
*
|
||||||
|
* @author rplees
|
||||||
|
* @email rplees.i.ly@gmail.com
|
||||||
|
* @created 2024/05/30
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@SuperBuilder
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class TwelveStockCreateCommand {
|
||||||
|
/**
|
||||||
|
* 主键 */
|
||||||
|
Integer id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 股票code */
|
||||||
|
String stockCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 股票名称 */
|
||||||
|
String stockName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BSE or NSE */
|
||||||
|
String stockType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存时间 */
|
||||||
|
Date saveTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否锁定 0否 1是 */
|
||||||
|
Integer isLock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否展示 0是 1否 */
|
||||||
|
Integer isShow;
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package cn.stock.market.dto.command;
|
||||||
|
|
||||||
|
import java.lang.Integer;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TwelveStockModifyCommand
|
||||||
|
*
|
||||||
|
* @author rplees
|
||||||
|
* @email rplees.i.ly@gmail.com
|
||||||
|
* @created 2024/05/30
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@SuperBuilder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@EqualsAndHashCode(
|
||||||
|
callSuper = false
|
||||||
|
)
|
||||||
|
public class TwelveStockModifyCommand extends TwelveStockCreateCommand {
|
||||||
|
Integer id;
|
||||||
|
}
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package cn.stock.market.dto.query;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class StockChartDto {
|
|
||||||
private Long timestamp;
|
|
||||||
private double open;
|
|
||||||
private double high;
|
|
||||||
private double low;
|
|
||||||
private double close;
|
|
||||||
private double volume;
|
|
||||||
|
|
||||||
public StockChartDto(Long date, double open, double high, double low, double close, double volume) {
|
|
||||||
this.timestamp = date;
|
|
||||||
this.open = open;
|
|
||||||
this.high = high;
|
|
||||||
this.low = low;
|
|
||||||
this.close = close;
|
|
||||||
this.volume = volume;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getVolume() {
|
|
||||||
return volume;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getTimestamp() {
|
|
||||||
return timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getOpen() {
|
|
||||||
return open;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getHigh() {
|
|
||||||
return high;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getLow() {
|
|
||||||
return low;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getClose() {
|
|
||||||
return close;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -187,17 +187,18 @@ public class TodayApis {
|
|||||||
|
|
||||||
//获取详情
|
//获取详情
|
||||||
public static JSONObject getStockDetail(String exchange,String coCode){
|
public static JSONObject getStockDetail(String exchange,String coCode){
|
||||||
String url = String.format("https://priceapi.moneycontrol.com/pricefeed/notapplicable/inidicesindia/%s",exchange);
|
String url = String.format("https://marketapi.intoday.in/widget/stockdetail/pullview?co_code=%s&exchange=%s",coCode,exchange);
|
||||||
String str = get(url);
|
String str = get(url);
|
||||||
JSONObject object = JSON.parseObject(str);
|
JSONObject object = JSON.parseObject(str);
|
||||||
boolean bool = false;
|
boolean bool = false;
|
||||||
if(object.containsKey("code")){
|
if(object.containsKey("success")){
|
||||||
bool = object.getInteger("code") == 200;
|
bool = object.getBoolean("success");
|
||||||
}
|
}
|
||||||
if(!bool){
|
if(!bool){
|
||||||
return new JSONObject();
|
return new JSONObject();
|
||||||
}
|
}
|
||||||
JSONObject entity = JSON.parseObject(object.getString("data"));
|
JSONArray jsonArray = JSON.parseArray(object.getString("data"));
|
||||||
|
JSONObject entity = JSON.parseObject(jsonArray.get(0).toString());
|
||||||
return entity;
|
return entity;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,14 +56,6 @@ public class MoneyStockPO {
|
|||||||
* 展示表示 */
|
* 展示表示 */
|
||||||
String selfDispId;
|
String selfDispId;
|
||||||
|
|
||||||
/**
|
|
||||||
* NSE India的id */
|
|
||||||
String nseIndiaId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NSE India Chart的id */
|
|
||||||
String nseIndiaChartId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自有self_url */
|
* 自有self_url */
|
||||||
String selfUrl;
|
String selfUrl;
|
||||||
@@ -83,6 +75,4 @@ public class MoneyStockPO {
|
|||||||
/**
|
/**
|
||||||
* 是否展示 0是 1否 */
|
* 是否展示 0是 1否 */
|
||||||
Integer isShow;
|
Integer isShow;
|
||||||
|
|
||||||
Boolean useFromBseindia = false;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
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.Entity;
|
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
|
|
||||||
@SuperBuilder
|
|
||||||
@Data
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Entity
|
|
||||||
@DynamicInsert
|
|
||||||
@DynamicUpdate
|
|
||||||
@Table(
|
|
||||||
name = "optional_stock"
|
|
||||||
)
|
|
||||||
public class OptionalStockPO {
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(
|
|
||||||
strategy = javax.persistence.GenerationType.IDENTITY
|
|
||||||
)
|
|
||||||
Integer id;
|
|
||||||
|
|
||||||
String symbol;
|
|
||||||
|
|
||||||
String company;
|
|
||||||
}
|
|
||||||
@@ -79,8 +79,6 @@ public class StockIpoPO {
|
|||||||
* 申请总额 */
|
* 申请总额 */
|
||||||
String apply;
|
String apply;
|
||||||
|
|
||||||
String exchangeType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 市盈率 */
|
* 市盈率 */
|
||||||
BigDecimal peRatio;
|
BigDecimal peRatio;
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package cn.stock.market.infrastructure.db.po;
|
||||||
|
|
||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.String;
|
||||||
|
import java.util.Date;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
import org.hibernate.annotations.DynamicInsert;
|
||||||
|
import org.hibernate.annotations.DynamicUpdate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TwelveStockPO
|
||||||
|
*
|
||||||
|
* @author rplees
|
||||||
|
* @email rplees.i.ly@gmail.com
|
||||||
|
* @created 2024/05/30
|
||||||
|
*/
|
||||||
|
@SuperBuilder
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@DynamicInsert
|
||||||
|
@DynamicUpdate
|
||||||
|
@Table(
|
||||||
|
name = "twelve_stock"
|
||||||
|
)
|
||||||
|
public class TwelveStockPO {
|
||||||
|
/**
|
||||||
|
* 主键 */
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(
|
||||||
|
strategy = javax.persistence.GenerationType.IDENTITY
|
||||||
|
)
|
||||||
|
Integer id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 股票code */
|
||||||
|
String stockCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 股票名称 */
|
||||||
|
String stockName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BSE or NSE */
|
||||||
|
String stockType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存时间 */
|
||||||
|
Date saveTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否锁定 0否 1是 */
|
||||||
|
Integer isLock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否展示 0是 1否 */
|
||||||
|
Integer isShow;
|
||||||
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package cn.stock.market.infrastructure.db.repo;
|
|
||||||
|
|
||||||
import cn.stock.market.infrastructure.db.po.OptionalStockPO;
|
|
||||||
import com.rp.spring.jpa.GenericJpaRepository;
|
|
||||||
|
|
||||||
public interface OptionalStockRepo extends GenericJpaRepository<OptionalStockPO, Integer> {
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package cn.stock.market.infrastructure.db.repo;
|
||||||
|
|
||||||
|
import cn.stock.market.infrastructure.db.po.TwelveStockPO;
|
||||||
|
import com.rp.spring.jpa.GenericJpaRepository;
|
||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TwelveStockRepo
|
||||||
|
*
|
||||||
|
* @author rplees
|
||||||
|
* @email rplees.i.ly@gmail.com
|
||||||
|
* @created 2024/05/30
|
||||||
|
*/
|
||||||
|
public interface TwelveStockRepo extends GenericJpaRepository<TwelveStockPO, Integer> {
|
||||||
|
}
|
||||||
@@ -7,7 +7,6 @@ import cn.stock.market.domain.basic.repository.StockRepository;
|
|||||||
import cn.stock.market.domain.basic.service.StockService;
|
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.infrastructure.db.po.QSiteNewsPO;
|
||||||
import cn.stock.market.utils.DateTimeUtil;
|
|
||||||
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;
|
||||||
@@ -26,8 +25,6 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
@@ -121,16 +118,8 @@ public class InvestingTask {
|
|||||||
newsList.forEach( n -> {
|
newsList.forEach( n -> {
|
||||||
String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2);
|
String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2);
|
||||||
String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_"));
|
String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_"));
|
||||||
// String imgUrl = n.substring(n.indexOf("img loading=\"lazy\" src=") + 24, n.indexOf("?"));
|
String imgUrl = n.substring(n.indexOf("img loading=\"lazy\" src=") + 24, n.indexOf("?"));
|
||||||
String imgUrl = extractImgSrc(n);
|
String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9);
|
||||||
// String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9);
|
|
||||||
// Extract the date and time using regex
|
|
||||||
Pattern pattern = Pattern.compile("Updated On :<!-- --> <!-- -->(.*?)<!-- -->");
|
|
||||||
Matcher matcher = pattern.matcher(n);
|
|
||||||
String time = "";
|
|
||||||
if (matcher.find()) {
|
|
||||||
time = DateTimeUtil.formatDateTimeFor24H(matcher.group(1).trim(),"dd MMM yyyy | hh:mm a");
|
|
||||||
}
|
|
||||||
|
|
||||||
SiteNews siteNews = new SiteNews();
|
SiteNews siteNews = new SiteNews();
|
||||||
siteNews.setAddTime(new Date());
|
siteNews.setAddTime(new Date());
|
||||||
@@ -151,22 +140,4 @@ public class InvestingTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String extractImgSrc(String htmlData) {
|
|
||||||
String searchString = "<noscript>";
|
|
||||||
int startPos = htmlData.indexOf(searchString);
|
|
||||||
|
|
||||||
if (startPos != -1) {
|
|
||||||
String startTag = "src=";
|
|
||||||
startPos = htmlData.indexOf(startTag, startPos) + startTag.length() + 1;
|
|
||||||
|
|
||||||
int endPos = htmlData.indexOf("?", startPos);
|
|
||||||
|
|
||||||
if (endPos != -1) {
|
|
||||||
return htmlData.substring(startPos, endPos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,14 @@
|
|||||||
package cn.stock.market.infrastructure.job;
|
package cn.stock.market.infrastructure.job;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.date.DateTime;
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
|
||||||
import cn.stock.market.domain.basic.entity.BtodayStock;
|
import cn.stock.market.domain.basic.entity.BtodayStock;
|
||||||
import cn.stock.market.domain.basic.entity.MoneyStock;
|
|
||||||
import cn.stock.market.domain.basic.entity.StockIpo;
|
import cn.stock.market.domain.basic.entity.StockIpo;
|
||||||
import cn.stock.market.domain.basic.repository.BtodayStockRepository;
|
import cn.stock.market.domain.basic.repository.BtodayStockRepository;
|
||||||
import cn.stock.market.domain.basic.repository.MoneyStockRepository;
|
|
||||||
import cn.stock.market.domain.basic.repository.StockIpoRepository;
|
import cn.stock.market.domain.basic.repository.StockIpoRepository;
|
||||||
import cn.stock.market.dto.StockIpoDTO;
|
import cn.stock.market.dto.StockIpoDTO;
|
||||||
import cn.stock.market.infrastructure.db.po.QMoneyStockPO;
|
|
||||||
import cn.stock.market.infrastructure.db.po.QStockIpoPO;
|
import cn.stock.market.infrastructure.db.po.QStockIpoPO;
|
||||||
import cn.stock.market.infrastructure.db.po.StockIpoPO;
|
import cn.stock.market.infrastructure.db.po.StockIpoPO;
|
||||||
import cn.stock.market.infrastructure.db.repo.BtodayStockRepo;
|
import cn.stock.market.infrastructure.db.repo.BtodayStockRepo;
|
||||||
import com.alibaba.druid.sql.visitor.functions.Now;
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
@@ -37,11 +31,14 @@ import org.springframework.stereotype.Component;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
@@ -57,10 +54,6 @@ public class Scraper {
|
|||||||
private StockIpoRepository stockIpoRepository;
|
private StockIpoRepository stockIpoRepository;
|
||||||
|
|
||||||
private final ExecutorService executorService = Executors.newFixedThreadPool(5);
|
private final ExecutorService executorService = Executors.newFixedThreadPool(5);
|
||||||
@Autowired
|
|
||||||
private MoneyStockRepository moneyStockRepository;
|
|
||||||
|
|
||||||
private boolean times = false;
|
|
||||||
|
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 1 */2 * ?")
|
@Scheduled(cron = "0 0 1 */2 * ?")
|
||||||
@@ -111,7 +104,6 @@ public class Scraper {
|
|||||||
|
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 18 * * ?")
|
@Scheduled(cron = "0 0 18 * * ?")
|
||||||
// @PostConstruct
|
|
||||||
@RequestMapping("/testScraperGetMoneyControllerNewIPO")
|
@RequestMapping("/testScraperGetMoneyControllerNewIPO")
|
||||||
public void getMoneyControllerNewIPOSchedule() {
|
public void getMoneyControllerNewIPOSchedule() {
|
||||||
log.info("定时任务执行获取新股ipo的方法开始执行");
|
log.info("定时任务执行获取新股ipo的方法开始执行");
|
||||||
@@ -171,28 +163,7 @@ public class Scraper {
|
|||||||
stockIpo.setCreateDate(new Date());
|
stockIpo.setCreateDate(new Date());
|
||||||
stockIpo.setUpdateDate(new Date());
|
stockIpo.setUpdateDate(new Date());
|
||||||
stockIpo.setSourceType("3");
|
stockIpo.setSourceType("3");
|
||||||
|
listStockIpoList.add(stockIpo);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < upcomingData.size(); i++) {
|
for (int i = 0; i < upcomingData.size(); i++) {
|
||||||
@@ -215,37 +186,11 @@ public class Scraper {
|
|||||||
stockIpo.setCreateDate(new Date());
|
stockIpo.setCreateDate(new Date());
|
||||||
stockIpo.setUpdateDate(new Date());
|
stockIpo.setUpdateDate(new Date());
|
||||||
stockIpo.setSourceType("3");
|
stockIpo.setSourceType("3");
|
||||||
|
listStockIpoList.add(stockIpo);
|
||||||
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);
|
// 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);
|
List<String> scIdList = Lists.transform(listStockIpoList, StockIpo::getStockCode);
|
||||||
if(CollectionUtil.isNotEmpty(scIdList)){
|
if(CollectionUtil.isNotEmpty(scIdList)){
|
||||||
List<StockIpo> existStockIpoList = stockIpoRepository.findAll(QStockIpoPO.stockIpoPO.stockCode.in(scIdList));
|
List<StockIpo> existStockIpoList = stockIpoRepository.findAll(QStockIpoPO.stockIpoPO.stockCode.in(scIdList));
|
||||||
@@ -260,7 +205,6 @@ public class Scraper {
|
|||||||
//保存全部的新股
|
//保存全部的新股
|
||||||
if(CollectionUtil.isNotEmpty(listStockIpoList)){
|
if(CollectionUtil.isNotEmpty(listStockIpoList)){
|
||||||
stockIpoRepository.saveAll(listStockIpoList);
|
stockIpoRepository.saveAll(listStockIpoList);
|
||||||
|
|
||||||
log.info("定时任务执行获取新股ipo的方法开始结束,保存了数据:{}", JSON.toJSONString(listStockIpoList));
|
log.info("定时任务执行获取新股ipo的方法开始结束,保存了数据:{}", JSON.toJSONString(listStockIpoList));
|
||||||
}else {
|
}else {
|
||||||
log.info("定时任务执行获取新股ipo的方法开始结束,没有数据");
|
log.info("定时任务执行获取新股ipo的方法开始结束,没有数据");
|
||||||
@@ -281,36 +225,6 @@ public class Scraper {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 19 * * ?")
|
|
||||||
@PostConstruct
|
|
||||||
@RequestMapping("/addMoneyStock")
|
|
||||||
public void addMoneyStock() {
|
|
||||||
log.info("定时任务执行获取新股ipo的方法开始执行");
|
|
||||||
|
|
||||||
List<StockIpo> stockIpoList;
|
|
||||||
|
|
||||||
if(!times){
|
|
||||||
stockIpoList = stockIpoRepository.findAll(QStockIpoPO.stockIpoPO.listingDate.isNotNull()
|
|
||||||
.and(QStockIpoPO.stockIpoPO.listingDate.loe(DateTime.now()))
|
|
||||||
.and(QStockIpoPO.stockIpoPO.exchangeType.isNotNull())
|
|
||||||
.and(QStockIpoPO.stockIpoPO.exchangeType.isNotEmpty())
|
|
||||||
); // first time run
|
|
||||||
|
|
||||||
times = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
stockIpoList = stockIpoRepository.findAll(QStockIpoPO.stockIpoPO.listingDate.isNotNull()
|
|
||||||
.and(QStockIpoPO.stockIpoPO.listingDate.loe(DateTime.now())
|
|
||||||
.and(QStockIpoPO.stockIpoPO.listingDate.goe(DateUtil.offsetDay(DateTime.now(), -3))))
|
|
||||||
.and(QStockIpoPO.stockIpoPO.exchangeType.isNotNull())
|
|
||||||
.and(QStockIpoPO.stockIpoPO.exchangeType.isNotEmpty())
|
|
||||||
); // from second run
|
|
||||||
}
|
|
||||||
|
|
||||||
List<MoneyStock> moneyStockList = convertToMoneyStock(stockIpoList);
|
|
||||||
moneyStockRepository.saveAll(moneyStockList);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static Timestamp convertStringToTimestamp(String dateString) {
|
private static Timestamp convertStringToTimestamp(String dateString) {
|
||||||
// 实现将字符串转换为 Timestamp 的逻辑
|
// 实现将字符串转换为 Timestamp 的逻辑
|
||||||
@@ -322,6 +236,12 @@ public class Scraper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void processSubMap(Map<String, String> sefUrlList) {
|
private void processSubMap(Map<String, String> sefUrlList) {
|
||||||
for (Map.Entry<String, String> entry : sefUrlList.entrySet()) {
|
for (Map.Entry<String, String> entry : sefUrlList.entrySet()) {
|
||||||
String companyName = entry.getKey();
|
String companyName = entry.getKey();
|
||||||
@@ -458,134 +378,4 @@ public class Scraper {
|
|||||||
log.info("Getting web detail URL: " + url + "...");
|
log.info("Getting web detail URL: " + url + "...");
|
||||||
return Jsoup.connect(url).ignoreContentType(true).execute().body();
|
return Jsoup.connect(url).ignoreContentType(true).execute().body();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getIpoExchange(String stockName, String stockCode) {
|
|
||||||
List<String> exchanges = new ArrayList<>();
|
|
||||||
String url = "https://www.moneycontrol.com/ipo/{stockName}-{stockCode}-ipodetail";
|
|
||||||
url = url.replace("{stockName}", stockName.toLowerCase().replace(" ", "-")).replace("{stockCode}", stockCode.toLowerCase());
|
|
||||||
|
|
||||||
org.apache.http.client.HttpClient client = HttpClients.createDefault();
|
|
||||||
HttpGet request = new HttpGet(url);
|
|
||||||
try {
|
|
||||||
org.apache.http.HttpResponse response = client.execute(request);
|
|
||||||
|
|
||||||
if (response.getStatusLine().getStatusCode() == 200) {
|
|
||||||
String responseBody = EntityUtils.toString(response.getEntity());
|
|
||||||
Document doc = Jsoup.parse(responseBody);
|
|
||||||
|
|
||||||
Element scriptTag = doc.selectFirst("script#__NEXT_DATA__");
|
|
||||||
|
|
||||||
if (scriptTag != null) {
|
|
||||||
String jsonDataStr = scriptTag.html();
|
|
||||||
|
|
||||||
com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(jsonDataStr);
|
|
||||||
log.info("获取到新股的json信息:" + jsonObject.toJSONString());
|
|
||||||
|
|
||||||
com.alibaba.fastjson.JSONObject pageProps = jsonObject.getJSONObject("props").getJSONObject("pageProps");
|
|
||||||
com.alibaba.fastjson.JSONObject overview = pageProps.getJSONObject("ipoDetails").getJSONObject("ipoDetails").getJSONObject("overview");
|
|
||||||
|
|
||||||
String exchangeStr = overview.getString("listing_on");
|
|
||||||
|
|
||||||
if (exchangeStr != null && !exchangeStr.isEmpty() && !exchangeStr.equals("null")) {
|
|
||||||
exchanges.addAll(new ArrayList<>(Arrays.asList(exchangeStr.split(","))));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
log.info(e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (exchanges.isEmpty()) {
|
|
||||||
exchanges.add("");
|
|
||||||
}
|
|
||||||
|
|
||||||
return exchanges;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<MoneyStock> convertToMoneyStock(List<StockIpo> 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> exchangeTypes = stockIpoList.stream().map(StockIpo::getExchangeType).collect(Collectors.toSet());
|
|
||||||
|
|
||||||
// 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(
|
|
||||||
QMoneyStockPO.moneyStockPO.moneyScId.in(stockCodes)
|
|
||||||
.and(QMoneyStockPO.moneyStockPO.stockType.in(exchangeTypes))
|
|
||||||
);
|
|
||||||
|
|
||||||
// Lưu các stockCode và exchangeType đã tồn tại
|
|
||||||
Set<String> existingKeys = existingMoneyStocks.stream()
|
|
||||||
.map(ms -> ms.getMoneyScId() + ms.getStockType())
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
|
|
||||||
// Chỉ giữ những StockIpo chưa tồn tại
|
|
||||||
return stockIpoList.stream()
|
|
||||||
.filter(stockIpo -> !existingKeys.contains(stockIpo.getStockCode() + stockIpo.getExchangeType()))
|
|
||||||
.map(this::convert)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
// public List<MoneyStock> convertToMoneyStock(List<StockIpo> stockIpoList) {
|
|
||||||
// return stockIpoList.stream()
|
|
||||||
// .filter(stockIpo -> !moneyStockRepository.exists(
|
|
||||||
// QMoneyStockPO.moneyStockPO.stockType.eq(stockIpo.getExchangeType())
|
|
||||||
// .and(QMoneyStockPO.moneyStockPO.moneyScId.eq(stockIpo.getStockCode()))
|
|
||||||
// )) // Chỉ giữ những StockIpo chưa tồn tại
|
|
||||||
// .map(this::convert)
|
|
||||||
// .collect(Collectors.toList());
|
|
||||||
// }
|
|
||||||
|
|
||||||
private MoneyStock convert(StockIpo stockIpo) {
|
|
||||||
MoneyStock moneyStock = new MoneyStock();
|
|
||||||
|
|
||||||
moneyStock.setStockName(stockIpo.getStockName());
|
|
||||||
moneyStock.setMoneyScId(stockIpo.getStockCode());
|
|
||||||
moneyStock.setSelfDispId(stockIpo.getStockCode());
|
|
||||||
moneyStock.setStockType(stockIpo.getExchangeType());
|
|
||||||
moneyStock.setSaveTime(DateTime.now());
|
|
||||||
moneyStock.setNseIndiaId(getNSEId(stockIpo));
|
|
||||||
|
|
||||||
return moneyStock;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getNSEId(StockIpo stockIpo){
|
|
||||||
String url = "https://priceapi.moneycontrol.com/pricefeed/" + stockIpo.getExchangeType().toLowerCase() + "/equitycash/" + stockIpo.getStockCode();
|
|
||||||
// 创建 HttpClient 实例
|
|
||||||
HttpClient client = HttpClients.createDefault();
|
|
||||||
// 创建 HttpGet 请求
|
|
||||||
HttpGet request = new HttpGet(url);
|
|
||||||
try {
|
|
||||||
// 执行请求
|
|
||||||
HttpResponse response = client.execute(request);
|
|
||||||
|
|
||||||
// 检查请求是否成功
|
|
||||||
if (response.getStatusLine().getStatusCode() == 200) {
|
|
||||||
// 获取响应体
|
|
||||||
String responseBody = EntityUtils.toString(response.getEntity());
|
|
||||||
|
|
||||||
if (responseBody != null) {
|
|
||||||
// 获取 JSON 数据
|
|
||||||
|
|
||||||
// 将 JSON 字符串解析为 Java JSONObject
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject(responseBody);
|
|
||||||
log.info("获取到新股的json信息:" + jsonObject.toJSONString());
|
|
||||||
|
|
||||||
JSONObject jsonData = jsonObject.getJSONObject("data");
|
|
||||||
|
|
||||||
if(stockIpo.getExchangeType().equals("NSE")){
|
|
||||||
return jsonData.getString("NSEID");
|
|
||||||
}
|
|
||||||
else if(stockIpo.getExchangeType().equals("BSE")){
|
|
||||||
return jsonData.getString("BSEID");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e){
|
|
||||||
log.info(e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
package cn.stock.market.infrastructure.job;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.google.common.base.Stopwatch;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import cn.qutaojing.common.utils.SpringUtils;
|
||||||
|
import cn.stock.market.domain.basic.entity.TwelveStock;
|
||||||
|
import cn.stock.market.domain.basic.service.TwelveStockService;
|
||||||
|
import cn.stock.market.dto.TwelveStockData;
|
||||||
|
import cn.stock.market.utils.HttpRequest;
|
||||||
|
import cn.stock.market.web.config.Config;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@RestController
|
||||||
|
public class TwelvedataTask {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TwelveStockService twelveStockService;
|
||||||
|
|
||||||
|
@GetMapping("/task/syncStockData")
|
||||||
|
@Scheduled(cron = "0 0 18 * * ?")
|
||||||
|
public void syncStockData() {
|
||||||
|
log.info("每天18点定时同步Twelvedata股票数据开始");
|
||||||
|
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||||
|
// 获取股票symbol列表
|
||||||
|
List<TwelveStockData> stockList = getStockList();
|
||||||
|
// 查询出数据库中所有股票
|
||||||
|
List<TwelveStock> allStocks = twelveStockService.repository().findAll();
|
||||||
|
List<String> savedSymbols = allStocks.stream().map(p-> p.getStockCode() + "#" + p.getStockType()).distinct().collect(Collectors.toList());
|
||||||
|
// 去除数据库中已经存在的股票
|
||||||
|
// 使用Iterator安全地移除元素
|
||||||
|
if(stockList!=null && stockList.size()>0) {
|
||||||
|
Iterator<TwelveStockData> iterator = stockList.iterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
TwelveStockData stockData = iterator.next();
|
||||||
|
if (savedSymbols.contains(stockData.getSymbol() + "#" + stockData.getExchange())) { // 根据条件移除元素
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//剩余数据入库
|
||||||
|
List<TwelveStock> addList = Lists.newArrayList();
|
||||||
|
if(stockList!=null && stockList.size()>0) {
|
||||||
|
for(TwelveStockData stockData:stockList) {
|
||||||
|
addList.add(cover(stockData));
|
||||||
|
}
|
||||||
|
twelveStockService.repository().saveAll(addList);
|
||||||
|
}
|
||||||
|
log.info("syncStockData执行, 受影响数{}, 耗时:{}毫秒", addList.size(), stopwatch.elapsed(TimeUnit.MILLISECONDS));
|
||||||
|
}
|
||||||
|
|
||||||
|
private TwelveStock cover(TwelveStockData data) {
|
||||||
|
TwelveStock stock = new TwelveStock();
|
||||||
|
stock.setStockCode(data.getSymbol());
|
||||||
|
stock.setStockName(data.getName());
|
||||||
|
stock.setStockType(data.getExchange());
|
||||||
|
stock.setSaveTime(new Date());
|
||||||
|
return stock;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<TwelveStockData> getStockList() {
|
||||||
|
try {
|
||||||
|
String source = "docs";
|
||||||
|
String country = "India";
|
||||||
|
List<TwelveStockData> list = Lists.newArrayList();
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
Config config = SpringUtils.getBean(Config.class);
|
||||||
|
String url = String.format("https://api.twelvedata.com/stocks?source=%s&country=%s&apikey=%s",source,country,config.getTwelveApikey());
|
||||||
|
String result = HttpRequest.doTwelveGet(url);
|
||||||
|
log.info("getStockList:获取 {} {} 的股票全量列表结束,耗时: {} ms ",source,country,(System.currentTimeMillis()-start));
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||||
|
if (jsonObject != null && !jsonObject.isEmpty()) {
|
||||||
|
JSONArray jsonArray = jsonObject.getJSONArray("data");
|
||||||
|
if(jsonArray!=null && jsonArray.size()>0) {
|
||||||
|
for (int i = 0; i < jsonArray.size(); i++) {
|
||||||
|
JSONObject item = jsonArray.getJSONObject(i);
|
||||||
|
TwelveStockData stock = JSONObject.toJavaObject(item, TwelveStockData.class);
|
||||||
|
list.add(stock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
log.error("getStockList同步twelvedata股票数据异常,Exception:{}", e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,8 +5,6 @@ import java.sql.Timestamp;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.format.DateTimeFormat;
|
import org.joda.time.format.DateTimeFormat;
|
||||||
import org.joda.time.format.DateTimeFormatter;
|
import org.joda.time.format.DateTimeFormatter;
|
||||||
@@ -188,25 +186,6 @@ public class DateTimeUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String formatDateTimeFor24H(String inputDateTime,String inputFormatStr){
|
|
||||||
String outputDateTime = "";
|
|
||||||
// 1. 解析日期时间
|
|
||||||
SimpleDateFormat inputFormat = new SimpleDateFormat(inputFormatStr, Locale.ENGLISH);
|
|
||||||
Date date = null;
|
|
||||||
try {
|
|
||||||
date = inputFormat.parse(inputDateTime);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (date != null) {
|
|
||||||
// 2. 转换为24小时制
|
|
||||||
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
||||||
outputDateTime = outputFormat.format(date);
|
|
||||||
}
|
|
||||||
return outputDateTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
parseToDateByMinute(10);
|
parseToDateByMinute(10);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package cn.stock.market.utils;
|
|||||||
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
@@ -142,6 +143,52 @@ public class HttpRequest {
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String doTwelveGet(String url) throws Exception{
|
||||||
|
int maxRetries = 3;
|
||||||
|
for (int retry = 1; retry <= maxRetries; retry++) {
|
||||||
|
BufferedReader reader = null;
|
||||||
|
StringBuilder response = new StringBuilder();
|
||||||
|
try {
|
||||||
|
URL obj = new URL(url);
|
||||||
|
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
||||||
|
con.setRequestMethod("GET");
|
||||||
|
con.setRequestProperty("Accept", "application/json");
|
||||||
|
con.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
|
||||||
|
//模拟postman请求,否则返回403
|
||||||
|
con.setRequestProperty("User-Agent", "PostmanRuntime/7.26.8");
|
||||||
|
|
||||||
|
int responseCode = con.getResponseCode();
|
||||||
|
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||||
|
reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||||
|
String inputLine;
|
||||||
|
while ((inputLine = reader.readLine()) != null) {
|
||||||
|
response.append(inputLine);
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
return response.toString();
|
||||||
|
} else {
|
||||||
|
log.error("HTTP request failed with response code: " + responseCode);
|
||||||
|
}
|
||||||
|
}catch(Exception e) {
|
||||||
|
log.error("请求twelvedata数据url:{},exception:{} ", url,e);
|
||||||
|
}finally {
|
||||||
|
if (reader != null) {
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 如果不是最后一次重试,则等待一段时间再进行下一次重试
|
||||||
|
if (retry < maxRetries) {
|
||||||
|
try {
|
||||||
|
// 1秒钟
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String url = "";
|
String url = "";
|
||||||
|
|||||||
@@ -1,181 +0,0 @@
|
|||||||
package cn.stock.market.utils;
|
|
||||||
|
|
||||||
import cn.stock.market.dto.StockHistoryRequest;
|
|
||||||
import cn.stock.market.dto.StockHistoryResponse;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import okhttp3.*;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class NseIndiaRequest {
|
|
||||||
private static final String NSE_INDIA_URL = "https://www.nseindia.com";
|
|
||||||
private static final String NSE_INDIA_CHART_URL = "https://charting.nseindia.com";
|
|
||||||
private static final OkHttpClient client;
|
|
||||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
|
||||||
|
|
||||||
static {
|
|
||||||
client = new OkHttpClient.Builder()
|
|
||||||
.cookieJar(new CookieJar() {
|
|
||||||
private final Map<String, List<Cookie>> cookieStore = new HashMap<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
|
|
||||||
cookieStore.put(url.host(), cookies);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Cookie> loadForRequest(HttpUrl url) {
|
|
||||||
List<Cookie> cookies = cookieStore.get(url.host());
|
|
||||||
return cookies != null ? cookies : new ArrayList<Cookie>();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Request createRequest(String url) {
|
|
||||||
Request request = new Request.Builder()
|
|
||||||
.url(url)
|
|
||||||
.header("accept", "application/json, text/plain, */*")
|
|
||||||
.header("accept-language", "en-US,en;q=0.9")
|
|
||||||
.header("cache-control", "no-cache")
|
|
||||||
.header("pragma", "no-cache")
|
|
||||||
.header("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
return request;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void initCookie(String url) {
|
|
||||||
Request request = createRequest(url);
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
|
||||||
if (!response.isSuccessful()) {
|
|
||||||
throw new IOException("Failed to fetch initial cookies");
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException("Failed to initialize cookies", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Integer getCode(String symbol) {
|
|
||||||
Request request = createRequest(NSE_INDIA_CHART_URL + "//Charts/GetEQMasters").newBuilder()
|
|
||||||
.addHeader("referer", NSE_INDIA_CHART_URL)
|
|
||||||
.addHeader("origin", NSE_INDIA_CHART_URL)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
|
||||||
if (!response.isSuccessful()) {
|
|
||||||
throw new IOException("Failed to get EQ code");
|
|
||||||
}
|
|
||||||
|
|
||||||
String result = response.body().string();
|
|
||||||
|
|
||||||
String regex = "(\\d+)\\|" + symbol + "\\|.*";
|
|
||||||
Pattern pattern = Pattern.compile(regex);
|
|
||||||
Matcher matcher = pattern.matcher(result);
|
|
||||||
|
|
||||||
if (matcher.find()) {
|
|
||||||
return Integer.valueOf(matcher.group(1));
|
|
||||||
}
|
|
||||||
throw new IOException("No data found");
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException("Failed to get EQ code", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JSONObject stockByJYSFromHttp(String stockType, String symbol, String nseIndiaId) {
|
|
||||||
initCookie(NSE_INDIA_URL);
|
|
||||||
|
|
||||||
String url = NSE_INDIA_URL + "/api/quote-equity?symbol=" + nseIndiaId;
|
|
||||||
Request request = createRequest(url).newBuilder()
|
|
||||||
.addHeader("referer", NSE_INDIA_URL)
|
|
||||||
.addHeader("origin", NSE_INDIA_URL)
|
|
||||||
.build();
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
|
||||||
if (!response.isSuccessful()) {
|
|
||||||
throw new IOException("Request failed with code: " + response.code());
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONObject jsonData = JSONObject.parseObject(response.body().string());
|
|
||||||
JSONObject data =jsonData.getJSONObject("priceInfo");
|
|
||||||
JSONObject json = new JSONObject();
|
|
||||||
|
|
||||||
json.put("pricepercentchange",data.getString("pChange"));
|
|
||||||
json.put("stockType",stockType);
|
|
||||||
json.put("pricechange",data.getString("change"));
|
|
||||||
json.put("pricecurrent",data.getString("lastPrice"));
|
|
||||||
json.put("priceprevclose",data.getString("previousClose"));
|
|
||||||
json.put("PREVDATE","");
|
|
||||||
json.put("VOL",jsonData.getJSONObject("preOpenMarket").getString("totalTradedVolume"));
|
|
||||||
json.put("dataSourceType","3");
|
|
||||||
json.put("symbol",symbol);
|
|
||||||
json.put("BSEID",symbol);
|
|
||||||
json.put("NSEID",symbol);
|
|
||||||
json.put("LTH",data.getString("upperCP"));
|
|
||||||
json.put("LTL",data.getString("lowerCP"));
|
|
||||||
json.put("OPN",data.getString("open"));
|
|
||||||
|
|
||||||
return json;
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException("Failed to fetch data", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static StockHistoryResponse stockKLineFromHttp(StockHistoryRequest stockHistoryRequest, String resolution) {
|
|
||||||
initCookie(NSE_INDIA_CHART_URL);
|
|
||||||
|
|
||||||
Integer code = getCode(stockHistoryRequest.getSymbol());
|
|
||||||
|
|
||||||
int interval = 1;
|
|
||||||
if (StringUtils.equals("H", resolution)) {
|
|
||||||
resolution = "I";
|
|
||||||
interval = 60;
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, Object> body = new HashMap<>();
|
|
||||||
body.put("chartPeriod", resolution);
|
|
||||||
body.put("chartStart", 0);
|
|
||||||
body.put("exch", "N");
|
|
||||||
body.put("fromDate", 0);
|
|
||||||
body.put("instrType", "C");
|
|
||||||
body.put("scripCode", code);
|
|
||||||
body.put("timeInterval", interval);
|
|
||||||
body.put("toDate", stockHistoryRequest.getTo() + 18000);
|
|
||||||
body.put("ulToken", code);
|
|
||||||
|
|
||||||
String payload;
|
|
||||||
try {
|
|
||||||
payload = objectMapper.writeValueAsString(body);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException("Failed to serialize body", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
RequestBody requestBody = RequestBody.create(
|
|
||||||
MediaType.get("application/json; charset=utf-8"),
|
|
||||||
payload
|
|
||||||
);
|
|
||||||
|
|
||||||
Request request = createRequest(NSE_INDIA_CHART_URL + "//Charts/symbolhistoricaldata/").newBuilder()
|
|
||||||
.addHeader("referer", NSE_INDIA_CHART_URL)
|
|
||||||
.addHeader("origin", NSE_INDIA_CHART_URL)
|
|
||||||
.post(requestBody)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
try (Response response = client.newCall(request).execute()) {
|
|
||||||
if (!response.isSuccessful()) {
|
|
||||||
throw new IOException("Request failed with code: " + response.code());
|
|
||||||
}
|
|
||||||
|
|
||||||
StockHistoryResponse result = objectMapper.readValue(response.body().string(), StockHistoryResponse.class);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException("Failed to fetch data", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -22,7 +22,6 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.text.DecimalFormat;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -160,19 +159,6 @@ public class BTodayStockController {
|
|||||||
|
|
||||||
String forObject = restTemplate.getForObject(apiUrl, String.class);
|
String forObject = restTemplate.getForObject(apiUrl, String.class);
|
||||||
JSONObject jsonObject = JSON.parseObject(forObject);
|
JSONObject jsonObject = JSON.parseObject(forObject);
|
||||||
JSONArray arryData = jsonObject.getJSONArray("data");
|
|
||||||
if (arryData != null&&arryData.size()>0) {
|
|
||||||
try {
|
|
||||||
JSONObject jsonObject1 = arryData.getJSONObject(0);
|
|
||||||
String price = jsonObject1.getString("price");
|
|
||||||
double priceValue = Double.parseDouble(price);
|
|
||||||
DecimalFormat df = new DecimalFormat("0.00");
|
|
||||||
jsonObject1.put("price", df.format(priceValue));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
// Handle the case where price is not a valid double
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
jsonObject.put("id",btodayStock.getId());
|
jsonObject.put("id",btodayStock.getId());
|
||||||
return jsonObject;
|
return jsonObject;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -3,8 +3,6 @@ package cn.stock.market.web;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -14,7 +12,6 @@ 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;
|
||||||
import cn.stock.market.infrastructure.job.InvestingTask;
|
|
||||||
import cn.stock.market.web.annotations.EncryptFilter;
|
import cn.stock.market.web.annotations.EncryptFilter;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
@@ -172,22 +169,15 @@ public class StockApiController {
|
|||||||
|
|
||||||
@RequestMapping({"test.do"})
|
@RequestMapping({"test.do"})
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public ServerResponse test(/*@RequestParam("url") String url, @RequestParam("pageNum") Integer pageNum*/) {
|
public ServerResponse test(@RequestParam("url") String url, @RequestParam("pageNum") Integer pageNum) {
|
||||||
String news = stockService.getNews();
|
String news = stockService.getNews();
|
||||||
List<String> newsList = Arrays.asList(news.split("<a href="));
|
List<String> newsList = Arrays.asList(news.split("<a href="));
|
||||||
newsList = newsList.subList(1, newsList.size());
|
newsList = newsList.subList(1, newsList.size());
|
||||||
newsList.forEach( n -> {
|
newsList.forEach( n -> {
|
||||||
String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2);
|
String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2);
|
||||||
String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_"));
|
String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_"));
|
||||||
String imgUrl = InvestingTask.extractImgSrc(n);
|
String imgUrl = n.substring(n.indexOf("img loading=\"lazy\" src=") + 24, n.indexOf("?"));
|
||||||
// String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9);
|
String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9);
|
||||||
// Extract the date and time using regex
|
|
||||||
Pattern pattern = Pattern.compile("Updated On :<!-- --> <!-- -->(.*?)<!-- -->");
|
|
||||||
Matcher matcher = pattern.matcher(n);
|
|
||||||
String time = "";
|
|
||||||
if (matcher.find()) {
|
|
||||||
time = matcher.group(1).trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
SiteNews siteNews = new SiteNews();
|
SiteNews siteNews = new SiteNews();
|
||||||
siteNews.setAddTime(new Date());
|
siteNews.setAddTime(new Date());
|
||||||
@@ -248,7 +238,7 @@ public class StockApiController {
|
|||||||
@ResponseBody
|
@ResponseBody
|
||||||
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,60000, (string) -> {
|
||||||
return this.stockService.getIndexByBtoday();
|
return this.stockService.getIndexByBtoday();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
137
src/main/java/cn/stock/market/web/TwelveApiController.java
Normal file
137
src/main/java/cn/stock/market/web/TwelveApiController.java
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
package cn.stock.market.web;
|
||||||
|
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.github.pagehelper.StringUtil;
|
||||||
|
import com.google.common.cache.Cache;
|
||||||
|
import com.google.common.cache.CacheBuilder;
|
||||||
|
import cn.qutaojing.common.utils.SpringUtils;
|
||||||
|
import cn.stock.market.dto.StockHistoryResponse;
|
||||||
|
import cn.stock.market.dto.TwelveStockInfo;
|
||||||
|
import cn.stock.market.utils.HttpRequest;
|
||||||
|
import cn.stock.market.utils.ServerResponse;
|
||||||
|
import cn.stock.market.web.annotations.EncryptFilter;
|
||||||
|
import cn.stock.market.web.config.Config;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* twelvedata数据源接口
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@Api(value = "/TwelveApiController", tags = "twelvedata股票行情")
|
||||||
|
@Slf4j
|
||||||
|
@RequestMapping({"/api/market/twelvedata", "/api/hq/twelvedata"})
|
||||||
|
public class TwelveApiController {
|
||||||
|
|
||||||
|
@ApiOperation(value = "股票详情信息", httpMethod = "GET")
|
||||||
|
@ApiImplicitParams({
|
||||||
|
@ApiImplicitParam(name = "stockCode",value = "股票对应代码",dataType ="String",required = true, paramType = "query"),
|
||||||
|
@ApiImplicitParam(name = "stockType",value = "股票对应代码:BSE/NSE",dataType ="String",required = true, paramType = "query")
|
||||||
|
})
|
||||||
|
@GetMapping("/getStockDetail")
|
||||||
|
@EncryptFilter(decryptRequest = false)
|
||||||
|
public ServerResponse<?> getStockDetail(String stockCode,String stockType) {
|
||||||
|
try {
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
Config config = SpringUtils.getBean(Config.class);
|
||||||
|
String url = String.format("https://api.twelvedata.com/quote?symbol=%s&exchange=%s&apikey=%s",stockCode,stockType,config.getTwelveApikey());
|
||||||
|
String result = HttpRequest.doTwelveGet(url);
|
||||||
|
if(StringUtil.isNotEmpty(result)) {
|
||||||
|
JSONObject data = JSONObject.parseObject(result);
|
||||||
|
TwelveStockInfo info = mapJsonToTwelveStock(data);
|
||||||
|
log.info("getStockDetail:获取 {}, {} 的股票详情结束,耗时: {} ms ",stockCode,stockType,(System.currentTimeMillis()-start));
|
||||||
|
return ServerResponse.createBySuccess("操作成功", info);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取股票详情参数:{},{}. Exception:{}" , stockCode,stockType, e);
|
||||||
|
}
|
||||||
|
return ServerResponse.createBySuccess("操作成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
private TwelveStockInfo mapJsonToTwelveStock(JSONObject jsonObject) {
|
||||||
|
TwelveStockInfo info = new TwelveStockInfo();
|
||||||
|
if (jsonObject != null && !jsonObject.isEmpty()) {
|
||||||
|
info.setStockCode(jsonObject.getString("symbol"));
|
||||||
|
info.setSymbol(jsonObject.getString("symbol"));
|
||||||
|
info.setStockName(jsonObject.getString("name"));
|
||||||
|
info.setStockType(jsonObject.getString("exchange"));
|
||||||
|
info.setLastPrice(jsonObject.getString("close"));
|
||||||
|
info.setPerchg(jsonObject.getString("percent_change"));
|
||||||
|
info.setChange(jsonObject.getString("change"));
|
||||||
|
info.setOpenPrice(jsonObject.getString("open"));
|
||||||
|
info.setPreviousPrice(jsonObject.getString("previous_close"));
|
||||||
|
info.setVolume(jsonObject.getString("volume"));
|
||||||
|
info.setHighPrice(jsonObject.getString("high"));
|
||||||
|
info.setLowPrice(jsonObject.getString("low"));
|
||||||
|
JSONObject json = jsonObject.getJSONObject("fifty_two_week");
|
||||||
|
if(json!=null && !json.isEmpty()) {
|
||||||
|
info.setWeek52HighPrice(json.getString("high"));
|
||||||
|
info.setWeek52LowPrice(json.getString("low"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "股票详情列表", httpMethod = "GET")
|
||||||
|
@ApiImplicitParams({
|
||||||
|
@ApiImplicitParam(name = "stockCodes",value = "股票对应代码, 多个时以英文逗号分隔",dataType ="String",required = true, paramType = "query"),
|
||||||
|
@ApiImplicitParam(name = "stockType",value = "股票对应代码:BSE/NSE",dataType ="String",required = true, paramType = "query")
|
||||||
|
})
|
||||||
|
@GetMapping("/getStockDetailList")
|
||||||
|
@EncryptFilter(decryptRequest = false)
|
||||||
|
public ServerResponse<?> getStockDetailList(String stockCodes,String stockType) {
|
||||||
|
try {
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
Config config = SpringUtils.getBean(Config.class);
|
||||||
|
String url = String.format("https://api.twelvedata.com/quote?symbol=%s&exchange=%s&apikey=%s",stockCodes,stockType,config.getTwelveApikey());
|
||||||
|
String result = HttpRequest.doTwelveGet(url);
|
||||||
|
if(StringUtil.isNotEmpty(result)) {
|
||||||
|
JSONObject data = JSONObject.parseObject(result);
|
||||||
|
List<TwelveStockInfo> list = mapJsonToTwelveList(stockCodes,data);
|
||||||
|
log.info("getStockDetailList:获取 {}, {} 的股票列表详情结束,耗时: {} ms ",stockCodes,stockType,(System.currentTimeMillis()-start));
|
||||||
|
return ServerResponse.createBySuccess("操作成功", list);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取股票详情参数:{},{}. Exception:{}" , stockCodes,stockType, e);
|
||||||
|
}
|
||||||
|
return ServerResponse.createBySuccess("操作成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<TwelveStockInfo> mapJsonToTwelveList(String stockCodes,JSONObject jsonObject) {
|
||||||
|
if (jsonObject == null || jsonObject.isEmpty()) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
List<TwelveStockInfo> list = new ArrayList<>();
|
||||||
|
String[] items = stockCodes.split(",");
|
||||||
|
if(items!=null && items.length>0) {
|
||||||
|
if(items.length == 1) {
|
||||||
|
TwelveStockInfo info = mapJsonToTwelveStock(jsonObject);
|
||||||
|
list.add(info);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
for (String str : items) {
|
||||||
|
JSONObject json = jsonObject.getJSONObject(str);
|
||||||
|
TwelveStockInfo vo = mapJsonToTwelveStock(json);
|
||||||
|
list.add(vo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -39,4 +39,5 @@ public class Config {
|
|||||||
String aliyunAccessKeyId;
|
String aliyunAccessKeyId;
|
||||||
String aliyunAccessKeySecret;
|
String aliyunAccessKeySecret;
|
||||||
String aliyunAppCode;
|
String aliyunAppCode;
|
||||||
|
String twelveApikey;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ spring:
|
|||||||
show-sql: true
|
show-sql: true
|
||||||
# Redis配置
|
# Redis配置
|
||||||
redis:
|
redis:
|
||||||
host: 43.156.40.39
|
host: 43.132.212.180
|
||||||
password: a5v8b86P4mVzFlUqJV
|
password: ruTZ9J3gaDhknJ
|
||||||
port: 30031
|
port: 36379
|
||||||
database: 1
|
database: 1
|
||||||
lettuce:
|
lettuce:
|
||||||
pool:
|
pool:
|
||||||
@@ -17,9 +17,9 @@ 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://149.88.86.7:33306/india_stock?useUnicode=true&characterEncoding=utf-8
|
||||||
username: root
|
username: root
|
||||||
password: uNejHIFQGJOUtYTmE
|
password: 33BsUUcnXRYgwtIND
|
||||||
maxActive: 500
|
maxActive: 500
|
||||||
testWhileIdle: true
|
testWhileIdle: true
|
||||||
validationQuery: SELECT 1
|
validationQuery: SELECT 1
|
||||||
@@ -42,6 +42,7 @@ gugudataAppKey: K5LZKV8KAYM4
|
|||||||
aliyunAccessKeyId: LTAI5tJi2z8cegG8fTW7BSQu
|
aliyunAccessKeyId: LTAI5tJi2z8cegG8fTW7BSQu
|
||||||
aliyunAccessKeySecret: fnCI9LUcqLuH7D6nkhvSHQMob1JSm8
|
aliyunAccessKeySecret: fnCI9LUcqLuH7D6nkhvSHQMob1JSm8
|
||||||
aliyunAppCode: 75ef2615da614eaaa71e2e2058fc53b0
|
aliyunAppCode: 75ef2615da614eaaa71e2e2058fc53b0
|
||||||
|
twelveApikey: 4098a6fc2c3245a88c7da804f10223c2
|
||||||
# 具体看类:CloudStorageConfig
|
# 具体看类:CloudStorageConfig
|
||||||
oss:
|
oss:
|
||||||
type: 2 # 类型 1:七牛 2:阿里云 3:腾讯云
|
type: 2 # 类型 1:七牛 2:阿里云 3:腾讯云
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ gugudataAppKey: K5LZKV8KAYM4
|
|||||||
aliyunAccessKeyId: LTAI5tCQRp7t158TVyoF2Yhe
|
aliyunAccessKeyId: LTAI5tCQRp7t158TVyoF2Yhe
|
||||||
aliyunAccessKeySecret: glyzOno773Cv7HeWDliveu2H5gX486
|
aliyunAccessKeySecret: glyzOno773Cv7HeWDliveu2H5gX486
|
||||||
aliyunAppCode: 75ef2615da614eaaa71e2e2058fc53b0
|
aliyunAppCode: 75ef2615da614eaaa71e2e2058fc53b0
|
||||||
|
twelveApikey: 4098a6fc2c3245a88c7da804f10223c2
|
||||||
# 具体看类:CloudStorageConfig
|
# 具体看类:CloudStorageConfig
|
||||||
oss:
|
oss:
|
||||||
type: 2 # 类型 1:七牛 2:阿里云 3:腾讯云
|
type: 2 # 类型 1:七牛 2:阿里云 3:腾讯云
|
||||||
|
|||||||
@@ -31,9 +31,9 @@ public class JpaDDDGen {
|
|||||||
*/
|
*/
|
||||||
public static DataSource getMySQLDataSource() {
|
public static DataSource getMySQLDataSource() {
|
||||||
MysqlDataSource mysqlDS = new MysqlDataSource();
|
MysqlDataSource mysqlDS = new MysqlDataSource();
|
||||||
mysqlDS.setURL("jdbc:mysql://43.132.212.180:33306/india_stock?useUnicode=true&characterEncoding=utf-8");
|
mysqlDS.setURL("jdbc:mysql://149.88.86.7:33306/india_stock?useUnicode=true&characterEncoding=utf-8");
|
||||||
mysqlDS.setUser("root");
|
mysqlDS.setUser("root");
|
||||||
mysqlDS.setPassword("33BsUUcnXRYgwt");
|
mysqlDS.setPassword("33BsUUcnXRYgwtIND");
|
||||||
return mysqlDS;
|
return mysqlDS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ public class JpaDDDGen {
|
|||||||
/**
|
/**
|
||||||
* cs_statistic - 要生成的数据库表
|
* cs_statistic - 要生成的数据库表
|
||||||
*/
|
*/
|
||||||
Cons.tableNameToEntiyMapping.put("money_stock", null);
|
Cons.tableNameToEntiyMapping.put("twelve_stock", null);
|
||||||
|
|
||||||
ToolDDD.g(getMySQLDataSource().getConnection());
|
ToolDDD.g(getMySQLDataSource().getConnection());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user