Compare commits
222 Commits
money
...
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 | ||
|
|
6fdc13a72d | ||
|
|
6b5623dc33 | ||
|
|
4a22fc0a95 | ||
|
|
563dae1c45 | ||
|
|
fa02ebf03b | ||
|
|
0f5f25f744 | ||
|
|
615aae7e1d | ||
|
|
c89345329d | ||
|
|
f18521d190 | ||
|
|
e84c212bf0 | ||
|
|
1ff1797b0b | ||
|
|
89c0fe0321 | ||
|
|
b6052a46ff | ||
|
|
d40c30bcb5 | ||
|
|
5b16f1f2c9 | ||
|
|
b8d4e0d3f2 | ||
|
|
c19277e390 | ||
|
|
514875878f | ||
|
|
4257541342 | ||
|
|
441adac15a | ||
|
|
ba29ab98c7 | ||
|
|
94ec73874b | ||
|
|
549345719a | ||
|
|
3870400411 | ||
|
|
94d2936ffb | ||
|
|
59e4aa9e1a | ||
|
|
bae645e3c6 | ||
|
|
94d9aea2c8 | ||
|
|
5ae9762d45 | ||
|
|
ece52491dd | ||
|
|
6235d41711 | ||
|
|
c865eccaf4 | ||
|
|
136020a497 | ||
|
|
d7da59aca1 | ||
|
|
8427bed427 | ||
|
|
269f02b79d | ||
|
|
7cc456bcd8 | ||
|
|
be05d403af | ||
|
|
4a29bf6659 | ||
|
|
5b2eb8519a | ||
|
|
2e4449bd64 | ||
|
|
b321fd9d4e | ||
|
|
2f9e54bf4f | ||
| 3bb354bbc6 | |||
| a403cba964 | |||
|
|
99bde81670 | ||
|
|
bae941828e | ||
|
|
2f86571578 | ||
|
|
d491bef735 | ||
|
|
74c64eb7d4 | ||
|
|
f50b6b5519 | ||
| 2446d89b30 | |||
|
|
33a68eb7e8 | ||
|
|
7b0a08150d | ||
|
|
146e9d9bc0 | ||
|
|
59a0480be0 | ||
|
|
5fe3200ea1 | ||
|
|
943c6c77e4 | ||
|
|
b2e93f646c | ||
|
|
9af156cd4a | ||
|
|
8660354dc1 | ||
|
|
ed924d85ae | ||
|
|
b7f0793d88 | ||
|
|
4e9810e074 | ||
|
|
d2e186cae6 | ||
|
|
d8862710a1 | ||
|
|
efae848b4f | ||
|
|
0cec277282 | ||
|
|
f6cc52bb9c | ||
|
|
45fe49a398 | ||
|
|
e0007aa6cc | ||
|
|
3982de78be | ||
|
|
d24ce12179 | ||
|
|
7524952c46 | ||
|
|
40555fcd64 | ||
|
|
30d95acdcf | ||
|
|
c340bba073 | ||
|
|
4a3b75e0c6 | ||
|
|
33c83af353 | ||
|
|
11130a9eda | ||
|
|
5a95d6be9a | ||
|
|
e680bee42b | ||
|
|
fbc7815365 | ||
|
|
37bb619e24 | ||
|
|
a7e6cc0b05 | ||
|
|
ece782497f | ||
|
|
4b25467bd2 | ||
|
|
5b3cc7e156 | ||
|
|
55c9865845 | ||
|
|
07d3b0623e | ||
|
|
03e6d9ecb9 | ||
|
|
cf97e84538 | ||
|
|
63014508d4 | ||
|
|
85fe98cc29 | ||
|
|
7de157fc2e | ||
|
|
9d6413bc43 | ||
|
|
fb4840f8a9 | ||
|
|
8c472d2973 | ||
|
|
5a9029f950 | ||
|
|
1d945f126e | ||
|
|
11d4062859 | ||
|
|
c1e0bbd77d | ||
|
|
1314d9271c | ||
|
|
df22b2fd22 | ||
|
|
f4567f94b6 | ||
|
|
19cb36b33a | ||
|
|
fba16687df | ||
|
|
77c436df1d | ||
|
|
a977f7c5fe | ||
|
|
4df20a07a0 | ||
|
|
f7bf2cb0eb | ||
|
|
3d59acf8fd | ||
|
|
3ec78dbe9a | ||
|
|
de44d54ece | ||
|
|
4b944f9d84 | ||
|
|
ff2896a0fd | ||
|
|
92a5ac5be1 | ||
|
|
3e0d209b34 | ||
|
|
c515b0ff0e | ||
|
|
d15535bf9b | ||
|
|
877154c1cc | ||
|
|
f4dd0b4542 | ||
|
|
4caad1b6a5 | ||
|
|
96c23943ab | ||
|
|
2b3f511ff6 | ||
|
|
0112687ce2 | ||
|
|
4874e3bee4 | ||
|
|
bcff09cbec | ||
|
|
592431d70a | ||
|
|
930e1e79cf | ||
|
|
8266094509 | ||
|
|
6c429ba58f | ||
|
|
5fa22c8410 | ||
|
|
529aa76cb3 | ||
|
|
bbcbdcc856 | ||
|
|
7b87dd8186 | ||
|
|
277ee7dfe4 | ||
|
|
960946692d | ||
|
|
3e26a9db28 | ||
|
|
56232a42a7 | ||
|
|
bdded7b3fc | ||
|
|
933dadca3c | ||
|
|
a9704b62ae | ||
|
|
ef392a7fe7 | ||
|
|
82ede6e680 | ||
|
|
0d23d57eae | ||
|
|
7c807ba521 | ||
|
|
a03ee86223 | ||
|
|
825c26dba6 | ||
|
|
87c1504421 | ||
|
|
d221ed3d04 | ||
|
|
8b368cfcc8 | ||
|
|
91a557cc51 | ||
|
|
6fa3428ca1 | ||
|
|
37425eff84 | ||
|
|
27bb313f74 | ||
|
|
baca671bbf | ||
|
|
dd34ab116f | ||
|
|
49e7593da5 | ||
|
|
f2c369c73d | ||
|
|
a968f61a05 | ||
|
|
3de67ae9ec | ||
|
|
bc5cf91a88 | ||
|
|
bc3efbc2de | ||
|
|
a49ad82f3f | ||
|
|
875d4faf0e | ||
|
|
a9fe1c39a7 | ||
|
|
c646988219 | ||
|
|
c7284e8081 | ||
|
|
e87c451b3f | ||
|
|
2ba716d87c | ||
|
|
a986870d4b | ||
|
|
43f08fc073 | ||
|
|
e98b6d0463 | ||
|
|
175bc87824 | ||
|
|
c24f3a86fb | ||
|
|
53b4223370 | ||
|
|
65656ef10b | ||
|
|
32e65dc2c2 | ||
|
|
88baedb546 | ||
|
|
c9f0d8f4cf | ||
|
|
163c92970d | ||
|
|
bc852cbf7c | ||
|
|
90c5eb9644 | ||
|
|
9264f08c77 | ||
|
|
28f33672e5 | ||
|
|
2601d5cf77 | ||
|
|
a0bd21b645 | ||
|
|
95468dba5c | ||
|
|
0a0c969e28 | ||
|
|
2087d8914b | ||
|
|
42a40b9ff8 |
@@ -1,7 +1,13 @@
|
|||||||
stages:
|
stages:
|
||||||
# 构建
|
# 构建
|
||||||
- build
|
- build
|
||||||
- webhook
|
- dockerize
|
||||||
|
- 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
|
||||||
@@ -37,16 +43,46 @@ build:
|
|||||||
- mvn clean install -Dmaven.test.skip=true
|
- mvn clean install -Dmaven.test.skip=true
|
||||||
- ls
|
- ls
|
||||||
- echo ">>>>>>Finish Building<<<<<<"
|
- echo ">>>>>>Finish Building<<<<<<"
|
||||||
webhook:
|
dockerize:
|
||||||
stage: webhook
|
stage: dockerize
|
||||||
|
tags:
|
||||||
|
- hk2
|
||||||
|
dependencies:
|
||||||
|
- build
|
||||||
|
only:
|
||||||
|
- main
|
||||||
|
- develop
|
||||||
|
script:
|
||||||
|
- echo ">>>>>>Start Building Docker Image<<<<<<"
|
||||||
|
- pwd
|
||||||
|
- ls -lah
|
||||||
|
- echo $DOCKER_PASSWORD | docker login -u ${company_name} --password-stdin
|
||||||
|
- docker build -t ${company_name}/${project_name}_${service_name} .
|
||||||
|
|
||||||
|
- docker push ${company_name}/${project_name}_${service_name}
|
||||||
|
|
||||||
|
- docker tag ${company_name}/${project_name}_${service_name} ${company_name}/${project_name}_${service_name}:$CI_PIPELINE_ID
|
||||||
|
- docker push ${company_name}/${project_name}_${service_name}:$CI_PIPELINE_ID
|
||||||
|
|
||||||
|
- 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:
|
||||||
|
stage: deploy
|
||||||
only:
|
only:
|
||||||
- develop
|
- develop
|
||||||
script:
|
script:
|
||||||
- echo ">>>>>>Start Deploy<<<<<<"
|
- echo "Deploying application..."
|
||||||
- ls
|
- ls
|
||||||
- apt-get update
|
- apk update
|
||||||
- apt-get install -y curl
|
- apk add curl
|
||||||
- curl --max-time 30 http://124.156.133.209:11113/api/webhook/justpull?project=india_market_java\&setenv_file=alpha.sh\&publish_env=alpha\&shell=india/deploy-test.sh
|
- |
|
||||||
- echo ">>>>>>Start Deploy Finish<<<<<<"
|
curl -X POST \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"namespace":"dgdev", "deployment_name":"germany-stock-market"}' \
|
||||||
|
https://updater-dgdev.moneytj.com/restart-deployment
|
||||||
|
- echo "Application successfully deployed."
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
17
Dockerfile
Normal file
17
Dockerfile
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
FROM openjdk:8
|
||||||
|
|
||||||
|
RUN echo "deb http://archive.debian.org/debian/ stretch main contrib non-free" > /etc/apt/sources.list \
|
||||||
|
&& echo "deb-src http://archive.debian.org/debian/ stretch main contrib non-free" >> /etc/apt/sources.list \
|
||||||
|
&& echo 'Acquire::Check-Valid-Until "false";' > /etc/apt/apt.conf.d/10no-check-valid
|
||||||
|
|
||||||
|
RUN apt-get update
|
||||||
|
#RUN apt-get install -y iputils-ping dnsutils vim net-tools --allow-unauthenticated
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY target/india_market_java.jar /app/app.jar
|
||||||
|
|
||||||
|
COPY docker-entrypoint.sh /usr/local/bin/
|
||||||
|
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||||
|
|
||||||
|
CMD ["docker-entrypoint.sh"]
|
||||||
21
docker-entrypoint.sh
Normal file
21
docker-entrypoint.sh
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
export JAVA_OPTS="$JAVA_OPTS -XX:-OmitStackTraceInFastThrow \
|
||||||
|
-Dspring.redis.host=$REDIS_HOST \
|
||||||
|
-Dspring.redis.password=$REDIS_PASS \
|
||||||
|
-Dmarket.domain=$MARKET_HOST \
|
||||||
|
-Dspring.redis.port=$REDIS_PORT \
|
||||||
|
-Dspring.datasource.stock-market.url=jdbc:mysql://$MYSQL_HOST:$MYSQL_PORT/$MYSQL_DB?useUnicode=true&autoReconnect=true&allowPublicKeyRetrieval=true&useSSL=true \
|
||||||
|
-Dspring.datasource.stock-market.username=$MYSQL_USER \
|
||||||
|
-Dspring.datasource.stock-market.password=$MYSQL_PASSWORD \
|
||||||
|
-Dspring.datasource.stock.url=jdbc:mysql://$MYSQL_HOST:$MYSQL_PORT/$MYSQL_DB?useUnicode=true&autoReconnect=true&allowPublicKeyRetrieval=true&useSSL=true \
|
||||||
|
-Dspring.datasource.stock.username=$MYSQL_USER \
|
||||||
|
-Dspring.datasource.stock.password=$MYSQL_PASSWORD"
|
||||||
|
|
||||||
|
|
||||||
|
echo 'param:'$@
|
||||||
|
echo 'JAVA_OPTS:'$JAVA_OPTS
|
||||||
|
|
||||||
|
java $JAVA_OPTS -jar /app/app.jar $@
|
||||||
|
|
||||||
|
tail -f /dev/null
|
||||||
14
pom.xml
14
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>
|
||||||
@@ -185,6 +191,12 @@
|
|||||||
<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>
|
||||||
@@ -264,7 +276,7 @@
|
|||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>nexus</id>
|
<id>nexus</id>
|
||||||
<url>https://nexus.duofu88.com/repository/maven-public/</url>
|
<url>https://nexus.main99.com/repository/maven-public/</url>
|
||||||
<releases>
|
<releases>
|
||||||
<enabled>true</enabled>
|
<enabled>true</enabled>
|
||||||
</releases>
|
</releases>
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ public class QBtodayStockPO extends EntityPathBase<BtodayStockPO> {
|
|||||||
|
|
||||||
public final NumberPath<Integer> id = createNumber("id", Integer.class);
|
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> lastUpdateTime = createDateTime("lastUpdateTime", java.util.Date.class);
|
public final DateTimePath<java.util.Date> lastUpdateTime = createDateTime("lastUpdateTime", java.util.Date.class);
|
||||||
|
|
||||||
public final StringPath selfUrl = createString("selfUrl");
|
public final StringPath selfUrl = createString("selfUrl");
|
||||||
|
|||||||
@@ -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));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -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);
|
||||||
|
|||||||
@@ -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,16 @@
|
|||||||
|
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,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,16 @@
|
|||||||
|
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,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 {
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,26 +1,21 @@
|
|||||||
package cn.stock.market.domain.basic.service;
|
package cn.stock.market.domain.basic.service;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.net.ssl.X509TrustManager;
|
|
||||||
import javax.persistence.EntityExistsException;
|
import javax.persistence.EntityExistsException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
|
||||||
import cn.hutool.core.text.StrFormatter;
|
import cn.hutool.core.text.StrFormatter;
|
||||||
import cn.stock.market.dto.model.*;
|
import cn.stock.market.dto.model.*;
|
||||||
import cn.stock.market.infrastructure.api.investing.IndiaIndexVo;
|
import cn.stock.market.infrastructure.api.EttechchartsApis;
|
||||||
import cn.stock.market.infrastructure.api.investing.IndiaStockVO;
|
import cn.stock.market.infrastructure.api.GrowwInApis;
|
||||||
import cn.stock.market.infrastructure.api.investing.InvestingApis;
|
import cn.stock.market.infrastructure.api.HomeApiIndex;
|
||||||
import cn.stock.market.infrastructure.api.investing.InvestingInvokerApis;
|
import cn.stock.market.infrastructure.api.TodayApis;
|
||||||
|
import cn.stock.market.infrastructure.api.investing.*;
|
||||||
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;
|
||||||
@@ -28,9 +23,6 @@ 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;
|
||||||
import com.google.common.base.Stopwatch;
|
import com.google.common.base.Stopwatch;
|
||||||
import okhttp3.OkHttpClient;
|
|
||||||
import okhttp3.Protocol;
|
|
||||||
import okhttp3.Request;
|
|
||||||
import okhttp3.Request.Builder;
|
import okhttp3.Request.Builder;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import cn.stock.market.infrastructure.db.po.QStockPO;
|
import cn.stock.market.infrastructure.db.po.QStockPO;
|
||||||
@@ -62,11 +54,6 @@ import cn.stock.market.infrastructure.api.sina.vo.MarketVO;
|
|||||||
import cn.stock.market.infrastructure.api.sina.vo.MarketVOResult;
|
import cn.stock.market.infrastructure.api.sina.vo.MarketVOResult;
|
||||||
import cn.stock.market.infrastructure.api.sina.vo.k.MinDataVO;
|
import cn.stock.market.infrastructure.api.sina.vo.k.MinDataVO;
|
||||||
import cn.stock.market.infrastructure.api.sina.vo.k.echarts.EchartsDataVO;
|
import cn.stock.market.infrastructure.api.sina.vo.k.echarts.EchartsDataVO;
|
||||||
import cn.stock.market.utils.GetPyByChinese;
|
|
||||||
import cn.stock.market.utils.HttpClientRequest;
|
|
||||||
import cn.stock.market.utils.PropertiesUtil;
|
|
||||||
import cn.stock.market.utils.ServerResponse;
|
|
||||||
import cn.stock.market.utils.Utils;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
@@ -260,34 +247,116 @@ 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")
|
// .header("Accept-Language", "en-US,en;q=0.9")
|
||||||
.get();
|
// .get();
|
||||||
result = doc.html().substring(doc.html().indexOf("<div class=\"short-video-img\">"),doc.html().lastIndexOf("<div class=\"short-video-img\">")+500);
|
String url = "https://www.business-standard.com/markets/news";
|
||||||
|
// Document doc = Jsoup.connect(url)
|
||||||
|
// .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", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
|
||||||
|
// .header("Accept-Language", "en-US,en;q=0.5")
|
||||||
|
// .header("Connection", "keep-alive")
|
||||||
|
// .referrer("https://www.google.com")
|
||||||
|
// .ignoreHttpErrors(true)
|
||||||
|
// .timeout(10000)
|
||||||
|
// .get();
|
||||||
|
String doGetNews = HttpClientRequest.doGetNews(url);
|
||||||
|
// 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");
|
||||||
|
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNewsInfo(String url) {
|
private String extractNewsFromHtml(String rawHtml) {
|
||||||
String result = "";
|
Document doc = Jsoup.parse(rawHtml);
|
||||||
try {
|
|
||||||
// 使用Jsoup连接到网页
|
// Optional: extract raw block around <div class="listingstyle_shortvideoimg__0TWuX shortvideoimg">
|
||||||
Document doc = Jsoup.connect(url)
|
int start = rawHtml.indexOf("<div class=\"listingstyle_shortvideoimg__0TWuX shortvideoimg\">");
|
||||||
.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")
|
int end = rawHtml.lastIndexOf("<div class=\"listingstyle_shortvideoimg__0TWuX shortvideoimg\">") + 500;
|
||||||
.header("Referer", "https://www.business-standard.com/")
|
String result = (start != -1 && end > start) ? rawHtml.substring(start, end) : "";
|
||||||
.header("Accept-Language", "en-US,en;q=0.9")
|
|
||||||
.get();
|
// Extract article list using CSS selector
|
||||||
result = doc.html().substring(doc.html().indexOf("articleBody") + 15, doc.html().indexOf(",\"author\":") - 1);
|
Elements divElements = doc.select("div.listingstyle_cardlistlist__dfq57");
|
||||||
} catch (Exception e) {
|
StringBuilder sb = new StringBuilder();
|
||||||
return e.toString();
|
for (Element divElement : divElements) {
|
||||||
|
sb.append(divElement.outerHtml()).append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If you only want the div content:
|
||||||
|
result = sb.toString();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 = "";
|
||||||
|
List<String> list = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
// Step 1: Get raw HTML via HttpClient
|
||||||
|
String rawHtml = HttpClientRequest.doGetNews(url);
|
||||||
|
|
||||||
|
// Step 2: Parse HTML with Jsoup
|
||||||
|
Document doc = Jsoup.parse(rawHtml);
|
||||||
|
|
||||||
|
// Step 3: Extract content manually (like original)
|
||||||
|
int startIdx = rawHtml.indexOf("articleBody") + 14;
|
||||||
|
int endIdx = rawHtml.indexOf(",\"author\":") - 1;
|
||||||
|
|
||||||
|
if (startIdx > 0 && endIdx > startIdx) {
|
||||||
|
result = rawHtml.substring(startIdx, endIdx);
|
||||||
|
} else {
|
||||||
|
result = "[articleBody not found]";
|
||||||
|
}
|
||||||
|
list.add(result);
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
list.add("[Error] " + e.getMessage());
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
public ServerResponse getStock(int pageNum, int pageSize, String keyWords, String stockPlate, String stockType,
|
public ServerResponse getStock(int pageNum, int pageSize, String keyWords, String stockPlate, String stockType,
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
Page<Stock> page = repository.findStockListByKeyWords(keyWords, stockPlate, stockType, 0, PageParam.of(pageNum, pageSize));
|
Page<Stock> page = repository.findStockListByKeyWords(keyWords, stockPlate, stockType, 0, PageParam.of(pageNum, pageSize));
|
||||||
@@ -941,8 +1010,10 @@ public class StockService {
|
|||||||
market.setName("BSESENSEX指数");
|
market.setName("BSESENSEX指数");
|
||||||
vo1.setIndexVo(market);
|
vo1.setIndexVo(market);
|
||||||
|
|
||||||
String type = "min";
|
String period = "P1D";
|
||||||
List<JSONObject> list = InvestingApis.of().kline(StockCode.of(stockCode), type);
|
String interval = "PT5M";
|
||||||
|
String type = "day";
|
||||||
|
List<JSONObject> list = InvestingApis.of().kIndex(stockCode,period,interval, type);
|
||||||
if(list == null || list.size() == 0){
|
if(list == null || list.size() == 0){
|
||||||
type = "day";
|
type = "day";
|
||||||
list = InvestingApis.of().kline(StockCode.of(stockCode), type);
|
list = InvestingApis.of().kline(StockCode.of(stockCode), type);
|
||||||
@@ -954,13 +1025,15 @@ public class StockService {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
IndiaIndexVo vo2 = new IndiaIndexVo();
|
IndiaIndexVo vo2 = new IndiaIndexVo();
|
||||||
String stockCode = "8985"; //"17940";
|
String stockCode = "17940"; //"17940";8985
|
||||||
IndiaStockVO market = InvestingApis.of().market(StockCode.of(stockCode));
|
IndiaStockVO market = InvestingApis.of().market(StockCode.of(stockCode));
|
||||||
market.setName("NIFTY50指数");
|
market.setName("NIFTY50指数");
|
||||||
vo2.setIndexVo(market);
|
vo2.setIndexVo(market);
|
||||||
|
|
||||||
String type = "min";
|
String period = "P1D";
|
||||||
List<JSONObject> list = InvestingApis.of().kline(StockCode.of(stockCode), type);
|
String interval = "PT1M";
|
||||||
|
String type = "day";
|
||||||
|
List<JSONObject> list = InvestingApis.of().kIndex(stockCode,period,interval, type);
|
||||||
if(list == null || list.size() == 0){
|
if(list == null || list.size() == 0){
|
||||||
type = "day";
|
type = "day";
|
||||||
list = InvestingApis.of().kline(StockCode.of(stockCode), type);
|
list = InvestingApis.of().kline(StockCode.of(stockCode), type);
|
||||||
@@ -972,4 +1045,112 @@ public class StockService {
|
|||||||
}
|
}
|
||||||
return ServerResponse.createBySuccess(indexVoList);
|
return ServerResponse.createBySuccess(indexVoList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ServerResponse getIndexByBtoday() throws Exception {
|
||||||
|
List<StockIndex> list = HomeApiIndex.fetchStockIndices();
|
||||||
|
|
||||||
|
List<IndiaIndexNewVo> indexVoList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (StockIndex stockIndex : list) {
|
||||||
|
IndiaIndexNewVo vo1 = new IndiaIndexNewVo();
|
||||||
|
IndiaStockVO market = new IndiaStockVO();
|
||||||
|
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);
|
||||||
|
|
||||||
|
List<ChartCandle> kLines = HomeApiIndex.fetchChartData(stockIndex.getId(), 419);
|
||||||
|
// List kline = HomeApiIndex.convertToJsonList(kLines);
|
||||||
|
vo1.setKLine(kLines);
|
||||||
|
indexVoList.add(vo1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ServerResponse.createBySuccess(indexVoList);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private IndiaStockVO objToVo(JSONObject object){
|
||||||
|
IndiaStockVO market = new IndiaStockVO();
|
||||||
|
if(object.containsKey("priceprevclose")){
|
||||||
|
market.setClose(object.getString("priceprevclose"));
|
||||||
|
}
|
||||||
|
if(object.containsKey("pricecurrent")){
|
||||||
|
market.setNowPrice(object.getString("pricecurrent"));
|
||||||
|
}
|
||||||
|
if(object.containsKey("pricepercentchange")){
|
||||||
|
market.setRate(object.getString("pricepercentchange"));
|
||||||
|
}
|
||||||
|
if(object.containsKey("HIGH")){
|
||||||
|
market.setHigh(object.getString("HIGH"));
|
||||||
|
}
|
||||||
|
if(object.containsKey("LOW")){
|
||||||
|
market.setLow(object.getString("LOW"));
|
||||||
|
}
|
||||||
|
if(object.containsKey("OPEN")){
|
||||||
|
market.setOpen(object.getString("OPEN"));
|
||||||
|
}
|
||||||
|
return market;
|
||||||
|
// stockListVO.setName(jsonObject.getString("companyname"));
|
||||||
|
// stockListVO.setCode(jsonObject.getString("co_code"));
|
||||||
|
// stockListVO.setSpell(jsonObject.getString("symbol"));
|
||||||
|
// stockListVO.setGid(jsonObject.getString("co_code"));
|
||||||
|
// stockListVO.setNowPrice(jsonObject.getString("price"));
|
||||||
|
// stockListVO.setHcrate(jsonObject.getBigDecimal("perchg"));
|
||||||
|
// stockListVO.setToday_max(jsonObject.getString("high_price"));
|
||||||
|
// stockListVO.setToday_min(jsonObject.getString("low_price"));
|
||||||
|
// stockListVO.setBusiness_balance(jsonObject.getString("val_traded"));
|
||||||
|
// stockListVO.setBusiness_amount(jsonObject.getString("vol_traded"));
|
||||||
|
// stockListVO.setPreclose_px(jsonObject.getString("prev_close"));
|
||||||
|
// stockListVO.setOpen_px(jsonObject.getString("open_price"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServerResponse getEttechcharts(){
|
||||||
|
List<IndiaIndexVo> indexVoList = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
//获取详情
|
||||||
|
String indexid = "2365";
|
||||||
|
String exchange = "47";
|
||||||
|
String keyName = "sensex";
|
||||||
|
IndiaIndexVo vo1 = new IndiaIndexVo();
|
||||||
|
JSONObject object = EttechchartsApis.getStockDetail(indexid, exchange,keyName);
|
||||||
|
IndiaStockVO market = EttechchartsApis.ettechchartsObjToVo(object);
|
||||||
|
market.setName("BSESENSEX指数");
|
||||||
|
vo1.setIndexVo(market);
|
||||||
|
|
||||||
|
//获取k线图 1min 当天的数据 分钟
|
||||||
|
String scripcode = "SENSEX";
|
||||||
|
List kine = EttechchartsApis.getStockKline(scripcode,exchange);
|
||||||
|
vo1.setKLine(kine);
|
||||||
|
indexVoList.add(vo1);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.info("获取BSESENSEX指数数据异常,异常信息{}。。。。",e.getMessage());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
//获取详情
|
||||||
|
String indexid = "2369";
|
||||||
|
String exchangeid = "50";
|
||||||
|
String keyName = "nifty";
|
||||||
|
IndiaIndexVo vo1 = new IndiaIndexVo();
|
||||||
|
JSONObject object = EttechchartsApis.getStockDetail(indexid, exchangeid,keyName);
|
||||||
|
IndiaStockVO market = EttechchartsApis.ettechchartsObjToVo(object);
|
||||||
|
market.setName("NIFTY50指数");
|
||||||
|
vo1.setIndexVo(market);
|
||||||
|
|
||||||
|
//获取k线图 1min 当天的数据 分钟
|
||||||
|
String scripcode = "NSE+Index";
|
||||||
|
List kine = EttechchartsApis.getStockKline(scripcode,exchangeid);
|
||||||
|
vo1.setKLine(kine);
|
||||||
|
indexVoList.add(vo1);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.info("获取NIFTY50指数数据异常,异常信息{}。。。。",e.getMessage());
|
||||||
|
}
|
||||||
|
return ServerResponse.createBySuccess(indexVoList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
18
src/main/java/cn/stock/market/dto/OptionalStockResponse.java
Normal file
18
src/main/java/cn/stock/market/dto/OptionalStockResponse.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/main/java/cn/stock/market/dto/TodayStockDTO.java
Normal file
18
src/main/java/cn/stock/market/dto/TodayStockDTO.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package cn.stock.market.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class TodayStockDTO {
|
||||||
|
private String stockType;
|
||||||
|
private String stockName;
|
||||||
|
private String stockUrl;
|
||||||
|
private String highPrice;
|
||||||
|
private String lowPrice;
|
||||||
|
private String lastPrice;
|
||||||
|
private String prevClosePrice;
|
||||||
|
private String change;
|
||||||
|
private String changePercent;
|
||||||
|
private String dispId;
|
||||||
|
private String scId;
|
||||||
|
}
|
||||||
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)
|
||||||
|
}
|
||||||
@@ -35,6 +35,11 @@ public class StockListVO {
|
|||||||
/*是否添加自选:1、添加自选,0、未添加自选*/
|
/*是否添加自选:1、添加自选,0、未添加自选*/
|
||||||
private String isOption;
|
private String isOption;
|
||||||
|
|
||||||
|
private String pricechange;
|
||||||
|
|
||||||
|
|
||||||
|
private String symbol;
|
||||||
|
|
||||||
public void setCode(String code) {
|
public void setCode(String code) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
}
|
}
|
||||||
@@ -255,4 +260,20 @@ public class StockListVO {
|
|||||||
public void setIsOption(String isOption) {
|
public void setIsOption(String isOption) {
|
||||||
this.isOption = isOption;
|
this.isOption = isOption;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPricechange() {
|
||||||
|
return pricechange;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPricechange(String pricechange) {
|
||||||
|
this.pricechange = pricechange;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSymbol() {
|
||||||
|
return symbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSymbol(String symbol) {
|
||||||
|
this.symbol = symbol;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
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
|
||||||
|
|
||||||
|
}
|
||||||
48
src/main/java/cn/stock/market/dto/query/StockChartDto.java
Normal file
48
src/main/java/cn/stock/market/dto/query/StockChartDto.java
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,233 @@
|
|||||||
|
package cn.stock.market.infrastructure.api;
|
||||||
|
|
||||||
|
import cn.stock.market.dto.TodayStockDTO;
|
||||||
|
import cn.stock.market.infrastructure.api.investing.IndiaIndexVo;
|
||||||
|
import cn.stock.market.infrastructure.api.investing.IndiaStockVO;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import org.apache.http.HttpEntity;
|
||||||
|
import org.apache.http.client.config.RequestConfig;
|
||||||
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据来源网站:<a href="https://groww.in/indices/nifty">...</a>, <a href="https://groww.in/indices/sp-bse-sensex">...</a>
|
||||||
|
*
|
||||||
|
* @auther jnerh
|
||||||
|
*/
|
||||||
|
public class GrowwInApis {
|
||||||
|
|
||||||
|
public static final String INDEX_DETAIL_URL = "https://groww.in/v1/api/stocks_data/v1/accord_points/exchange/%s/segment/CASH/latest_indices_ohlc/%s";
|
||||||
|
public static final String INDEX_KLINE_URL = "https://groww.in/v1/api/charting_service/v2/chart/delayed/exchange/%s/segment/CASH/%s/daily?intervalInMinutes=%s&minimal=true";
|
||||||
|
|
||||||
|
|
||||||
|
public static void requestSenSexData(List<IndiaIndexVo> indexVoList) {
|
||||||
|
IndiaIndexVo vo1 = new IndiaIndexVo();
|
||||||
|
JSONObject object = GrowwInApis.getSenSexDetail();
|
||||||
|
IndiaStockVO market = GrowwInApis.objToVo(object);
|
||||||
|
market.setName("BSESENSEX指数");
|
||||||
|
vo1.setIndexVo(market);
|
||||||
|
|
||||||
|
List kine = GrowwInApis.getSenSexKline();
|
||||||
|
vo1.setKLine(kine);
|
||||||
|
indexVoList.add(vo1);
|
||||||
|
}
|
||||||
|
public static void requestNifty50Data(List<IndiaIndexVo> indexVoList) {
|
||||||
|
IndiaIndexVo vo1 = new IndiaIndexVo();
|
||||||
|
JSONObject object = GrowwInApis.getNifty50Detail();
|
||||||
|
IndiaStockVO market = GrowwInApis.objToVo(object);
|
||||||
|
market.setName("NIFTY50指数");
|
||||||
|
vo1.setIndexVo(market);
|
||||||
|
|
||||||
|
List kine = GrowwInApis.getNifty50Kline();
|
||||||
|
vo1.setKLine(kine);
|
||||||
|
indexVoList.add(vo1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Nifty50指数详情
|
||||||
|
*/
|
||||||
|
public static JSONObject getIndexDetail(String exchange, String type) {
|
||||||
|
String url = String.format(INDEX_DETAIL_URL, exchange, type);
|
||||||
|
String str = get(url);
|
||||||
|
return JSON.parseObject(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取k线图
|
||||||
|
*/
|
||||||
|
public static List getIndexKline(String exchange, String type, String intervalInMinutes) {
|
||||||
|
String url = String.format(INDEX_KLINE_URL, exchange, type, intervalInMinutes);
|
||||||
|
String str = get(url);
|
||||||
|
JSONObject object = JSON.parseObject(str);
|
||||||
|
return getList(object.getString("candles"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Nifty50指数详情
|
||||||
|
*/
|
||||||
|
public static JSONObject getSenSexDetail() {
|
||||||
|
return getIndexDetail("BSE", "1");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取k线图
|
||||||
|
*/
|
||||||
|
public static List getSenSexKline() {
|
||||||
|
return getIndexKline("BSE", "1", "1");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Nifty50指数详情
|
||||||
|
*/
|
||||||
|
public static JSONObject getNifty50Detail() {
|
||||||
|
return getIndexDetail("NSE", "NIFTY");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取k线图
|
||||||
|
*/
|
||||||
|
public static List getNifty50Kline() {
|
||||||
|
return getIndexKline("NSE", "NIFTY", "5");
|
||||||
|
}
|
||||||
|
|
||||||
|
static String get(String url) {
|
||||||
|
CloseableHttpClient httpClient = null;
|
||||||
|
CloseableHttpResponse response = null;
|
||||||
|
String result = "";
|
||||||
|
|
||||||
|
try {
|
||||||
|
httpClient = HttpClients.createDefault();
|
||||||
|
HttpGet httpGet = new HttpGet(url);
|
||||||
|
httpGet.setHeader("Referer", "https://groww.in/indices/nifty");
|
||||||
|
httpGet.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0");
|
||||||
|
httpGet.setHeader("X-App-Id", "growwWeb");
|
||||||
|
httpGet.setHeader("X-Device-Id", "fd4815a2-49e4-570a-931a-0316d4d8a52d");
|
||||||
|
httpGet.setHeader("X-Device-Type", "desktop");
|
||||||
|
httpGet.setHeader("X-Platform", "web");
|
||||||
|
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000).setConnectionRequestTimeout(35000).setSocketTimeout(60000).build();
|
||||||
|
httpGet.setConfig(requestConfig);
|
||||||
|
response = httpClient.execute(httpGet);
|
||||||
|
HttpEntity entity = response.getEntity();
|
||||||
|
result = EntityUtils.toString(entity);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
|
||||||
|
if (null != response) {
|
||||||
|
try {
|
||||||
|
response.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (null != httpClient) {
|
||||||
|
try {
|
||||||
|
httpClient.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IndiaStockVO objToVo(JSONObject object) {
|
||||||
|
IndiaStockVO market = new IndiaStockVO();
|
||||||
|
if (object.containsKey("close")) {
|
||||||
|
market.setClose(object.getString("close"));
|
||||||
|
}
|
||||||
|
if (object.containsKey("value")) {
|
||||||
|
market.setNowPrice(object.getString("value"));
|
||||||
|
}
|
||||||
|
if (object.containsKey("dayChangePerc")) {
|
||||||
|
market.setRate(object.getString("dayChangePerc"));
|
||||||
|
}
|
||||||
|
if (object.containsKey("high")) {
|
||||||
|
market.setHigh(object.getString("high"));
|
||||||
|
}
|
||||||
|
if (object.containsKey("low")) {
|
||||||
|
market.setLow(object.getString("low"));
|
||||||
|
}
|
||||||
|
if (object.containsKey("open")) {
|
||||||
|
market.setOpen(object.getString("open"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return market;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List getList(String json) {
|
||||||
|
List<JSONObject> dataObject = new ArrayList<>();
|
||||||
|
JSONArray jsonArray = JSON.parseArray(json);
|
||||||
|
for (Object obj : jsonArray) {
|
||||||
|
JSONObject entity = new JSONObject();
|
||||||
|
JSONArray jsonArray1 = JSON.parseArray(obj.toString());
|
||||||
|
entity.put("upd_date", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(JSON.parseArray(obj.toString()).getLong(0) * 1000)).replace(" ", "T"));
|
||||||
|
entity.put("price", jsonArray1.getBigDecimal(1));
|
||||||
|
dataObject.add(entity);
|
||||||
|
}
|
||||||
|
return dataObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static TodayStockDTO todayStockDTO(JSONObject jsonObject) {
|
||||||
|
TodayStockDTO dto = new TodayStockDTO();
|
||||||
|
if (jsonObject.containsKey("exchange")) {
|
||||||
|
dto.setStockType(jsonObject.getString("exchange"));
|
||||||
|
} else {
|
||||||
|
dto.setStockType("");
|
||||||
|
}
|
||||||
|
if (jsonObject.containsKey("lname")) {
|
||||||
|
dto.setStockName(jsonObject.getString("lname"));
|
||||||
|
} else {
|
||||||
|
dto.setStockName("");
|
||||||
|
}
|
||||||
|
if (jsonObject.containsKey("high_price")) {
|
||||||
|
dto.setHighPrice(jsonObject.getString("highPrice"));
|
||||||
|
} else {
|
||||||
|
dto.setHighPrice("0.00");
|
||||||
|
}
|
||||||
|
if (jsonObject.containsKey("low_price")) {
|
||||||
|
dto.setLowPrice(jsonObject.getString("low_price"));
|
||||||
|
} else {
|
||||||
|
dto.setLowPrice("0.00");
|
||||||
|
}
|
||||||
|
if (jsonObject.containsKey("price")) {
|
||||||
|
dto.setLastPrice(jsonObject.getString("price"));
|
||||||
|
} else {
|
||||||
|
dto.setLastPrice("0.00");
|
||||||
|
}
|
||||||
|
if (jsonObject.containsKey("close_price")) {
|
||||||
|
dto.setPrevClosePrice(jsonObject.getString("close_price"));
|
||||||
|
} else {
|
||||||
|
dto.setPrevClosePrice("0.00");
|
||||||
|
}
|
||||||
|
if (jsonObject.containsKey("netchg")) {
|
||||||
|
dto.setChange(jsonObject.getString("netchg"));
|
||||||
|
} else {
|
||||||
|
dto.setChange("0.00");
|
||||||
|
}
|
||||||
|
if (jsonObject.containsKey("perchg")) {
|
||||||
|
dto.setChangePercent(jsonObject.getString("perchg"));
|
||||||
|
} else {
|
||||||
|
dto.setChangePercent("0.00");
|
||||||
|
}
|
||||||
|
return dto;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(getNifty50Detail());
|
||||||
|
System.out.println(getNifty50Kline());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package cn.stock.market.infrastructure.api;
|
package cn.stock.market.infrastructure.api;
|
||||||
|
|
||||||
|
import cn.stock.market.dto.TodayStockDTO;
|
||||||
import cn.stock.market.utils.HttpClientRequest;
|
import cn.stock.market.utils.HttpClientRequest;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
@@ -20,7 +21,7 @@ public class TodayApis {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//获取Top Gainers
|
//获取Top Gainers
|
||||||
public static List<JSONObject> getTopGainers(String exchange){
|
public static List getTopGainers(String exchange){
|
||||||
String url = "https://marketapi.intoday.in/widget/topgainer/view?exchange=" + exchange;
|
String url = "https://marketapi.intoday.in/widget/topgainer/view?exchange=" + exchange;
|
||||||
//返回字符串对象格式:{"status_code":1,"success":true,"data":[{}],"message":"Successful","fromredis":true}
|
//返回字符串对象格式:{"status_code":1,"success":true,"data":[{}],"message":"Successful","fromredis":true}
|
||||||
String str = get(url);
|
String str = get(url);
|
||||||
@@ -32,17 +33,19 @@ public class TodayApis {
|
|||||||
if(!bool){
|
if(!bool){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
return getList(object.getString("data"),1);
|
||||||
//进行数据转换
|
//进行数据转换
|
||||||
List<JSONObject> dataObject = new ArrayList<>();
|
// List<TodayStockDTO> dataObject = new ArrayList<>();
|
||||||
JSONArray jsonArray = JSON.parseArray(object.getString("data"));
|
// JSONArray jsonArray = JSON.parseArray(object.getString("data"));
|
||||||
for (Object obj : jsonArray){
|
// for (Object obj : jsonArray){
|
||||||
JSONObject entity = JSON.parseObject(obj.toString());
|
//// JSONObject entity = JSON.parseObject(obj.toString());
|
||||||
dataObject.add(entity);
|
// TodayStockDTO entity = todayStockDTO(JSON.parseObject(obj.toString()));
|
||||||
}
|
// dataObject.add(entity);
|
||||||
return dataObject;
|
// }
|
||||||
|
// return dataObject;
|
||||||
}
|
}
|
||||||
//获取Top Losers
|
//获取Top Losers
|
||||||
public static List<JSONObject> getTopLosers(String exchange){
|
public static List getTopLosers(String exchange){
|
||||||
String url = "https://marketapi.intoday.in/widget/toploser/view?exchange=" + exchange;
|
String url = "https://marketapi.intoday.in/widget/toploser/view?exchange=" + exchange;
|
||||||
//返回字符串对象格式:{"status_code":1,"success":true,"data":[{}],"message":"Successful","fromredis":true}
|
//返回字符串对象格式:{"status_code":1,"success":true,"data":[{}],"message":"Successful","fromredis":true}
|
||||||
String str = get(url);
|
String str = get(url);
|
||||||
@@ -54,17 +57,20 @@ public class TodayApis {
|
|||||||
if(!bool){
|
if(!bool){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
return getList(object.getString("data"),1);
|
||||||
//进行数据转换
|
//进行数据转换
|
||||||
List<JSONObject> dataObject = new ArrayList<>();
|
//// List<TodayStockDTO> dataObject = new ArrayList<>();
|
||||||
JSONArray jsonArray = JSON.parseArray(object.getString("data"));
|
// List<JSONObject> dataObject = new ArrayList<>();
|
||||||
for (Object obj : jsonArray){
|
// JSONArray jsonArray = JSON.parseArray(object.getString("data"));
|
||||||
JSONObject entity = JSON.parseObject(obj.toString());
|
// for (Object obj : jsonArray){
|
||||||
dataObject.add(entity);
|
// JSONObject entity = JSON.parseObject(obj.toString());
|
||||||
}
|
//// TodayStockDTO entity = todayStockDTO(JSON.parseObject(obj.toString()));
|
||||||
return dataObject;
|
// dataObject.add(entity);
|
||||||
|
// }
|
||||||
|
// return dataObject;
|
||||||
}
|
}
|
||||||
//获取Most Active Volume
|
//获取Most Active Volume
|
||||||
public static List<JSONObject> getMostActiveVolume(String exchange){
|
public static List getMostActiveVolume(String exchange){
|
||||||
String url = "https://marketapi.intoday.in/widget/mostactivetopper/view?exchange=" + exchange;
|
String url = "https://marketapi.intoday.in/widget/mostactivetopper/view?exchange=" + exchange;
|
||||||
//返回字符串对象格式:{"status_code":1,"success":true,"data":[{}],"message":"Successful","fromredis":true}
|
//返回字符串对象格式:{"status_code":1,"success":true,"data":[{}],"message":"Successful","fromredis":true}
|
||||||
String str = get(url);
|
String str = get(url);
|
||||||
@@ -76,17 +82,19 @@ public class TodayApis {
|
|||||||
if(!bool){
|
if(!bool){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
return getList(object.getString("data"),1);
|
||||||
//进行数据转换
|
//进行数据转换
|
||||||
List<JSONObject> dataObject = new ArrayList<>();
|
// List<TodayStockDTO> dataObject = new ArrayList<>();
|
||||||
JSONArray jsonArray = JSON.parseArray(object.getString("data"));
|
// JSONArray jsonArray = JSON.parseArray(object.getString("data"));
|
||||||
for (Object obj : jsonArray){
|
// for (Object obj : jsonArray){
|
||||||
JSONObject entity = JSON.parseObject(obj.toString());
|
//// JSONObject entity = JSON.parseObject(obj.toString());
|
||||||
dataObject.add(entity);
|
// TodayStockDTO entity = todayStockDTO(JSON.parseObject(obj.toString()));
|
||||||
}
|
// dataObject.add(entity);
|
||||||
return dataObject;
|
// }
|
||||||
|
// return dataObject;
|
||||||
}
|
}
|
||||||
//获取Most Active Value
|
//获取Most Active Value
|
||||||
public static List<JSONObject> getMostActiveValue(String exchange){
|
public static List getMostActiveValue(String exchange){
|
||||||
String url = "https://marketapi.intoday.in/widget/mostactivetopperbyvalue/view?exchange=" + exchange;
|
String url = "https://marketapi.intoday.in/widget/mostactivetopperbyvalue/view?exchange=" + exchange;
|
||||||
//返回字符串对象格式:{"status_code":1,"success":true,"data":[{}],"message":"Successful","fromredis":true}
|
//返回字符串对象格式:{"status_code":1,"success":true,"data":[{}],"message":"Successful","fromredis":true}
|
||||||
String str = get(url);
|
String str = get(url);
|
||||||
@@ -98,14 +106,116 @@ public class TodayApis {
|
|||||||
if(!bool){
|
if(!bool){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
//进行数据转换
|
return getList(object.getString("data"),1);
|
||||||
List<JSONObject> dataObject = new ArrayList<>();
|
// //进行数据转换
|
||||||
JSONArray jsonArray = JSON.parseArray(object.getString("data"));
|
// List<TodayStockDTO> dataObject = new ArrayList<>();
|
||||||
for (Object obj : jsonArray){
|
// JSONArray jsonArray = JSON.parseArray(object.getString("data"));
|
||||||
JSONObject entity = JSON.parseObject(obj.toString());
|
// for (Object obj : jsonArray){
|
||||||
dataObject.add(entity);
|
//// JSONObject entity = JSON.parseObject(obj.toString());
|
||||||
|
// TodayStockDTO entity = todayStockDTO(JSON.parseObject(obj.toString()));
|
||||||
|
// dataObject.add(entity);
|
||||||
|
// }
|
||||||
|
// return dataObject;
|
||||||
|
}
|
||||||
|
private static List getList(String json, int type){
|
||||||
|
if(type == 1){
|
||||||
|
List<JSONObject> dataObject = new ArrayList<>();
|
||||||
|
JSONArray jsonArray = JSON.parseArray(json);
|
||||||
|
for (Object obj : jsonArray){
|
||||||
|
JSONObject entity = JSON.parseObject(obj.toString());
|
||||||
|
dataObject.add(entity);
|
||||||
|
}
|
||||||
|
return dataObject;
|
||||||
|
}else{
|
||||||
|
//进行数据转换
|
||||||
|
List<TodayStockDTO> dataObject = new ArrayList<>();
|
||||||
|
JSONArray jsonArray = JSON.parseArray(json);
|
||||||
|
for (Object obj : jsonArray){
|
||||||
|
TodayStockDTO entity = todayStockDTO(JSON.parseObject(obj.toString()));
|
||||||
|
dataObject.add(entity);
|
||||||
|
}
|
||||||
|
return dataObject;
|
||||||
}
|
}
|
||||||
return dataObject;
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static TodayStockDTO todayStockDTO(JSONObject jsonObject){
|
||||||
|
TodayStockDTO dto = new TodayStockDTO();
|
||||||
|
if(jsonObject.containsKey("exchange")){
|
||||||
|
dto.setStockType(jsonObject.getString("exchange"));
|
||||||
|
}else {
|
||||||
|
dto.setStockType("");
|
||||||
|
}
|
||||||
|
if(jsonObject.containsKey("lname")){
|
||||||
|
dto.setStockName(jsonObject.getString("lname"));
|
||||||
|
}else{
|
||||||
|
dto.setStockName("");
|
||||||
|
}
|
||||||
|
if(jsonObject.containsKey("high_price")){
|
||||||
|
dto.setHighPrice(jsonObject.getString("highPrice"));
|
||||||
|
}else{
|
||||||
|
dto.setHighPrice("0.00");
|
||||||
|
}
|
||||||
|
if(jsonObject.containsKey("low_price")){
|
||||||
|
dto.setLowPrice(jsonObject.getString("low_price"));
|
||||||
|
}else {
|
||||||
|
dto.setLowPrice("0.00");
|
||||||
|
}
|
||||||
|
if(jsonObject.containsKey("price")){
|
||||||
|
dto.setLastPrice(jsonObject.getString("price"));
|
||||||
|
}else{
|
||||||
|
dto.setLastPrice("0.00");
|
||||||
|
}
|
||||||
|
if(jsonObject.containsKey("close_price")){
|
||||||
|
dto.setPrevClosePrice(jsonObject.getString("close_price"));
|
||||||
|
}else{
|
||||||
|
dto.setPrevClosePrice("0.00");
|
||||||
|
}
|
||||||
|
if(jsonObject.containsKey("netchg")){
|
||||||
|
dto.setChange(jsonObject.getString("netchg"));
|
||||||
|
}else{
|
||||||
|
dto.setChange("0.00");
|
||||||
|
}
|
||||||
|
if(jsonObject.containsKey("perchg")){
|
||||||
|
dto.setChangePercent(jsonObject.getString("perchg"));
|
||||||
|
}else{
|
||||||
|
dto.setChangePercent("0.00");
|
||||||
|
}
|
||||||
|
return dto;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取详情
|
||||||
|
public static JSONObject getStockDetail(String exchange,String coCode){
|
||||||
|
String url = String.format("https://priceapi.moneycontrol.com/pricefeed/notapplicable/inidicesindia/%s",exchange);
|
||||||
|
String str = get(url);
|
||||||
|
JSONObject object = JSON.parseObject(str);
|
||||||
|
boolean bool = false;
|
||||||
|
if(object.containsKey("code")){
|
||||||
|
bool = object.getInteger("code") == 200;
|
||||||
|
}
|
||||||
|
if(!bool){
|
||||||
|
return new JSONObject();
|
||||||
|
}
|
||||||
|
JSONObject entity = JSON.parseObject(object.getString("data"));
|
||||||
|
return entity;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取k线图
|
||||||
|
public static List getStockKline(String exchange, String coCode, String format, String durationType, String duration){
|
||||||
|
String url = String.format("https://marketapi.intoday.in/widget/pricechart_company/pullview?exchange=%s&co_code=%s&format=%s&durationtype=%s&duration=%s",
|
||||||
|
exchange, coCode, format, durationType, duration);
|
||||||
|
String str = get(url);
|
||||||
|
JSONObject object = JSON.parseObject(str);
|
||||||
|
boolean bool = false;
|
||||||
|
if(object.containsKey("success")){
|
||||||
|
bool = object.getBoolean("success");
|
||||||
|
}
|
||||||
|
if(!bool){
|
||||||
|
return new ArrayList();
|
||||||
|
}
|
||||||
|
return getList(object.getString("data"),1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -153,7 +153,6 @@ public class InvestingApis {
|
|||||||
"Time": "1698055197",
|
"Time": "1698055197",
|
||||||
"Url": "/equities/aditya-birla",
|
"Url": "/equities/aditya-birla",
|
||||||
"Volume": 3693615
|
"Volume": 3693615
|
||||||
* @param httpClient
|
|
||||||
* @param currPage
|
* @param currPage
|
||||||
* @param pageSize
|
* @param pageSize
|
||||||
* @return
|
* @return
|
||||||
@@ -252,7 +251,35 @@ public class InvestingApis {
|
|||||||
.collect(Collectors.toList())
|
.collect(Collectors.toList())
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
public List<JSONObject> kIndex(String code,String period, String interval,String type) throws IOException {
|
||||||
|
if(code == null) {
|
||||||
|
throw new RuntimeException("找不到股票信息");
|
||||||
|
}
|
||||||
|
Date nowDate = new Date();
|
||||||
|
JSONObject json = InvestingInvokerApis.of().__IndiaIndex(code, period,interval);
|
||||||
|
return json
|
||||||
|
.getJSONArray("data")
|
||||||
|
.stream()
|
||||||
|
.map(val -> {
|
||||||
|
JSONArray _ar = (JSONArray) val;
|
||||||
|
JSONObject item = new JSONObject();
|
||||||
|
item.put("date", _ar.get(0));
|
||||||
|
item.put("open", _ar.get(1));
|
||||||
|
item.put("high", _ar.get(2));
|
||||||
|
item.put("low", _ar.get(3));
|
||||||
|
item.put("close", _ar.get(4));
|
||||||
|
item.put("volume", _ar.get(5));
|
||||||
|
return item;
|
||||||
|
}).filter(val -> {
|
||||||
|
if("day".equalsIgnoreCase(type)) {
|
||||||
|
return DateUtil.isSameDay(nowDate, new Date(val.getLong("date")));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList())
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
public static InvestingApis of() {
|
public static InvestingApis of() {
|
||||||
return new InvestingApis();
|
return new InvestingApis();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -201,6 +201,15 @@ public class InvestingInvokerApis {
|
|||||||
String body = httpClient().newCall(builder.build()).execute().body().string();
|
String body = httpClient().newCall(builder.build()).execute().body().string();
|
||||||
return JSON.parseObject(body);
|
return JSON.parseObject(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JSONObject __IndiaIndex(String code,String period, String interval)throws IOException {
|
||||||
|
String tmpl = "https://api.investing.com/api/financialdata/{}/historical/chart/?period={}&interval={}&pointscount=160";
|
||||||
|
String url = StrFormatter.format(tmpl, code, period, interval);
|
||||||
|
Builder builder = builderGet(url);
|
||||||
|
|
||||||
|
String body = httpClient().newCall(builder.build()).execute().body().string();
|
||||||
|
return JSON.parseObject(body);
|
||||||
|
}
|
||||||
|
|
||||||
public static InvestingInvokerApis of() {
|
public static InvestingInvokerApis of() {
|
||||||
return new InvestingInvokerApis();
|
return new InvestingInvokerApis();
|
||||||
|
|||||||
@@ -71,4 +71,10 @@ public class BtodayStockPO {
|
|||||||
/**
|
/**
|
||||||
* 上次更新时间 */
|
* 上次更新时间 */
|
||||||
Date lastUpdateTime;
|
Date lastUpdateTime;
|
||||||
|
|
||||||
|
/** 是否锁定 0否 1是 */
|
||||||
|
Integer isLock;
|
||||||
|
|
||||||
|
/** 是否展示 0是 1否 */
|
||||||
|
Integer isShow;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,14 @@ 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;
|
||||||
@@ -75,4 +83,6 @@ public class MoneyStockPO {
|
|||||||
/**
|
/**
|
||||||
* 是否展示 0是 1否 */
|
* 是否展示 0是 1否 */
|
||||||
Integer isShow;
|
Integer isShow;
|
||||||
|
|
||||||
|
Boolean useFromBseindia = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
|
||||||
@@ -79,6 +79,8 @@ public class StockIpoPO {
|
|||||||
* 申请总额 */
|
* 申请总额 */
|
||||||
String apply;
|
String apply;
|
||||||
|
|
||||||
|
String exchangeType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 市盈率 */
|
* 市盈率 */
|
||||||
BigDecimal peRatio;
|
BigDecimal peRatio;
|
||||||
|
|||||||
@@ -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,7 @@
|
|||||||
|
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.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> {
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ 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;
|
||||||
@@ -25,6 +26,8 @@ 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
|
||||||
@@ -107,30 +110,63 @@ public class InvestingTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*新闻接口*/
|
/*新闻接口*/
|
||||||
@Scheduled(cron = "0 0 1 * * ?")
|
// @Scheduled(cron = "0 0 0/3 * * ?")
|
||||||
public void saveStockNews() {
|
public void saveStockNews() {
|
||||||
String news = stockService.getNews();
|
log.info("英文股票新闻数据同步开始");
|
||||||
List<String> newsList = Arrays.asList(news.split("<a href="));
|
try {
|
||||||
newsList = newsList.subList(1, newsList.size());
|
String news = stockService.getNews();
|
||||||
newsList.forEach( n -> {
|
log.info("获取英文股票新闻数据----"+news);
|
||||||
String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2);
|
List<String> newsList = Arrays.asList(news.split("<a href="));
|
||||||
String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_"));
|
newsList = newsList.subList(1, newsList.size());
|
||||||
String imgUrl = n.substring(n.indexOf("img src=") + 9, n.indexOf("?"));
|
newsList.forEach( n -> {
|
||||||
String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9);
|
String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2);
|
||||||
String title = n.substring(n.indexOf("html\">") + 6, n.indexOf("<div class=\"short-video-img\">") - 47);
|
String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_"));
|
||||||
|
// 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);
|
||||||
|
// 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());
|
||||||
siteNews.setSourceId(id);
|
siteNews.setSourceId(id);
|
||||||
siteNews.setTitle(title);
|
siteNews.setDescription(time);
|
||||||
siteNews.setDescription(time);
|
siteNews.setImgurl(imgUrl);
|
||||||
siteNews.setImgurl(imgUrl);
|
List<String> newsInfo = stockService.getNewsInfo(contentUrl);
|
||||||
siteNews.setContent(stockService.getNewsInfo(contentUrl));
|
siteNews.setContent(newsInfo.get(0));
|
||||||
List<SiteNews> list = newsRepository.findAll(QSiteNewsPO.siteNewsPO.sourceId.eq(id));
|
siteNews.setTitle(newsInfo.get(1));
|
||||||
if (list.size() == 0) {
|
List<SiteNews> list = newsRepository.findAll(QSiteNewsPO.siteNewsPO.sourceId.eq(id));
|
||||||
newsRepository.save(siteNews);
|
if (list.size() == 0) {
|
||||||
}
|
newsRepository.save(siteNews);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
log.info("英文股票新闻数据同步完成");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("新闻数据同步异常,异常信息{}。。。。",e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ import org.jsoup.nodes.Document;
|
|||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
import org.jsoup.select.Elements;
|
import org.jsoup.select.Elements;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@@ -48,6 +50,7 @@ public class MoneyScraper {
|
|||||||
private MoneyStockRepository moneyStockRepository;
|
private MoneyStockRepository moneyStockRepository;
|
||||||
|
|
||||||
@GetMapping("testScraperGetMoneyControlStock")
|
@GetMapping("testScraperGetMoneyControlStock")
|
||||||
|
//@Scheduled(cron = "0 0 2 */1 * ?")
|
||||||
public void schedule(){
|
public void schedule(){
|
||||||
List<String> letters = new ArrayList<>();
|
List<String> letters = new ArrayList<>();
|
||||||
for (char c = 'A'; c <= 'Z'; c++) {
|
for (char c = 'A'; c <= 'Z'; c++) {
|
||||||
@@ -93,9 +96,8 @@ public class MoneyScraper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("testScraperGetMoneyControlStockNoScId")
|
@GetMapping("testScraperGetMoneyControlStockNoScId")
|
||||||
public String testScraperGetMoneyControlStockNoScId() {
|
public String testScraperGetMoneyControlStockNoScId(@RequestParam("url") String url) {
|
||||||
String url = "http://www.moneycontrol.com/india/stockpricequote/foodprocessing/nestleindia/NI";
|
Document soup2 = fetchCompanyDetails(url);
|
||||||
/* Document soup2 = fetchCompanyDetails(url);
|
|
||||||
|
|
||||||
if (soup2 != null) {
|
if (soup2 != null) {
|
||||||
Element comIdInput = soup2.selectFirst("input[id=ap_sc_id]");
|
Element comIdInput = soup2.selectFirst("input[id=ap_sc_id]");
|
||||||
@@ -109,19 +111,19 @@ public class MoneyScraper {
|
|||||||
|
|
||||||
if (soup2 != null) {
|
if (soup2 != null) {
|
||||||
Element ulElement = soup2.selectFirst("ul[id=nseBseTab]");
|
Element ulElement = soup2.selectFirst("ul[id=nseBseTab]");
|
||||||
|
String name = soup2.selectFirst("#stockName > h1").text();
|
||||||
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("sss").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("Nestle"), 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);
|
||||||
}
|
}
|
||||||
@@ -129,7 +131,7 @@ public class MoneyScraper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
return "ok";
|
return "ok";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,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();
|
||||||
|
|||||||
@@ -1,13 +1,21 @@
|
|||||||
package cn.stock.market.infrastructure.job;
|
package cn.stock.market.infrastructure.job;
|
||||||
|
|
||||||
|
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.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@@ -29,13 +37,11 @@ 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.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
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;
|
||||||
@@ -51,9 +57,13 @@ 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 * ?")
|
||||||
@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";
|
||||||
@@ -100,101 +110,227 @@ public class Scraper {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 5 * * ?")
|
// @Scheduled(cron = "0 0 18 * * ?")
|
||||||
|
// @PostConstruct
|
||||||
@RequestMapping("/testScraperGetMoneyControllerNewIPO")
|
@RequestMapping("/testScraperGetMoneyControllerNewIPO")
|
||||||
public void schedule2() {
|
public void getMoneyControllerNewIPOSchedule() {
|
||||||
|
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(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");
|
JSONObject pageProps = jsonObject.getJSONObject("props").getJSONObject("pageProps");
|
||||||
JSONArray upcomingData = ipoTableData.getJSONArray("upcomingData");
|
JSONObject ipoTableData = pageProps.getJSONObject("ipoTableData");
|
||||||
List<StockIpo> listStockIpoList = new ArrayList<>();
|
|
||||||
for (int i = 0; i < openData.size(); i++) {
|
|
||||||
JSONObject entry = openData.getJSONObject(i);
|
|
||||||
StockIpo stockIpo = new StockIpo();
|
// 解析 openData 和 upcomingData
|
||||||
stockIpo.setStockCode(entry.getString("sc_id"));
|
JSONArray openData = ipoTableData.getJSONArray("openData");
|
||||||
stockIpo.setStockName(entry.getString("company_name"));
|
// if (openData.isEmpty()){
|
||||||
stockIpo.setStockPrice(entry.getBigDecimal("issue_price"));
|
// openData = ipoTableData.getJSONArray("openUpcomingData");
|
||||||
stockIpo.setSubscriptionDate(convertStringToTimestamp(entry.getString("open_date")));
|
// }
|
||||||
stockIpo.setListingDate(convertStringToTimestamp(entry.getString("listing_date")));
|
JSONArray upcomingData = ipoTableData.getJSONArray("upcomingData");
|
||||||
stockIpo.setTotalNumber(entry.getInteger("lot_size"));
|
List<StockIpo> listStockIpoList = new ArrayList<>();
|
||||||
stockIpo.setApply(entry.getString("total_subs"));
|
for (int i = 0; i < openData.size(); i++) {
|
||||||
stockIpo.setCreateDate(new Date());
|
JSONObject entry = openData.getJSONObject(i);
|
||||||
stockIpo.setUpdateDate(new Date());
|
StockIpo stockIpo = new StockIpo();
|
||||||
stockIpo.setSourceType("2");
|
stockIpo.setStockCode(entry.getString("sc_id"));
|
||||||
listStockIpoList.add(stockIpo);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
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")));
|
|
||||||
stockIpo.setTotalNumber(entry.getInteger("lot_size"));
|
|
||||||
stockIpo.setApply(entry.getString("total_subs"));
|
|
||||||
stockIpo.setCreateDate(new Date());
|
|
||||||
stockIpo.setUpdateDate(new Date());
|
|
||||||
stockIpo.setSourceType("3");
|
|
||||||
listStockIpoList.add(stockIpo);
|
|
||||||
}
|
|
||||||
|
|
||||||
// stockIpoRepository.saveAll(listStockIpoList);
|
|
||||||
|
|
||||||
List<String> nameList = Lists.transform(listStockIpoList, StockIpo::getStockName);
|
|
||||||
List<StockIpo> existStockIpoList = stockIpoRepository.findAll(QStockIpoPO.stockIpoPO.stockName.in(nameList));
|
|
||||||
List<String> existingStockNames = existStockIpoList.stream()
|
|
||||||
.map(StockIpo::getStockName)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
listStockIpoList = listStockIpoList.stream()
|
|
||||||
.filter(stockIpos -> !existingStockNames.contains(stockIpos.getStockName()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
//保存全部的新股
|
|
||||||
stockIpoRepository.saveAll(listStockIpoList);
|
|
||||||
|
|
||||||
// 输出整个 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 * * ?")
|
||||||
|
@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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -208,12 +344,6 @@ 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();
|
||||||
@@ -257,6 +387,8 @@ public class Scraper {
|
|||||||
btodayStock.setSelfUrl(url);
|
btodayStock.setSelfUrl(url);
|
||||||
btodayStock.setUrl(detailUrl);
|
btodayStock.setUrl(detailUrl);
|
||||||
btodayStock.setLastUpdateTime(new Date());
|
btodayStock.setLastUpdateTime(new Date());
|
||||||
|
btodayStock.setIsLock(0);
|
||||||
|
btodayStock.setIsShow(0);
|
||||||
btodayStockRepo.save(btodayStock);
|
btodayStockRepo.save(btodayStock);
|
||||||
|
|
||||||
/* if (webInfo != null) {
|
/* if (webInfo != null) {
|
||||||
@@ -348,4 +480,135 @@ 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());
|
||||||
|
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
|
||||||
|
List<MoneyStock> existingMoneyStocks = moneyStockRepository.findAll(
|
||||||
|
QMoneyStockPO.moneyStockPO.moneyScId.in(stockCodes)
|
||||||
|
.and(QMoneyStockPO.moneyStockPO.stockType.upper().in(exchangeTypes))
|
||||||
|
);
|
||||||
|
|
||||||
|
// Lưu các stockCode và exchangeType đã tồn tại
|
||||||
|
Set<String> existingKeys = existingMoneyStocks.stream()
|
||||||
|
.map(ms -> ms.getMoneyScId() + ms.getStockType().toUpperCase())
|
||||||
|
.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().toUpperCase()))
|
||||||
|
.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().toUpperCase());
|
||||||
|
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().toUpperCase(Locale.ROOT).equals("NSE")){
|
||||||
|
return jsonData.getString("NSEID");
|
||||||
|
}
|
||||||
|
else if(stockIpo.getExchangeType().toUpperCase(Locale.ROOT).equals("BSE")){
|
||||||
|
return jsonData.getString("BSEID");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e){
|
||||||
|
log.info(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ 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;
|
||||||
@@ -186,6 +188,25 @@ 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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -212,6 +212,109 @@ public class HttpClientRequest {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String doEttechchartsGet(String url) {
|
||||||
|
CloseableHttpClient httpClient = null;
|
||||||
|
CloseableHttpResponse response = null;
|
||||||
|
String result = "";
|
||||||
|
|
||||||
|
try {
|
||||||
|
httpClient = HttpClients.createDefault();
|
||||||
|
|
||||||
|
HttpGet httpGet = new HttpGet(url);
|
||||||
|
|
||||||
|
// httpGet.setHeader(":authority","ettechcharts.indiatimes.com");
|
||||||
|
// httpGet.setHeader(":method","GET");
|
||||||
|
// httpGet.setHeader(":scheme","https");
|
||||||
|
httpGet.setHeader("accept","*/*");
|
||||||
|
httpGet.setHeader("accept-encoding","gzip, deflate, br");
|
||||||
|
httpGet.setHeader("accept-language","zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6");
|
||||||
|
httpGet.setHeader("user-agent","Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36");
|
||||||
|
httpGet.setHeader("Referer", "https://economictimes.indiatimes.com/");
|
||||||
|
|
||||||
|
|
||||||
|
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000).setConnectionRequestTimeout(35000).setSocketTimeout(60000).build();
|
||||||
|
|
||||||
|
httpGet.setConfig(requestConfig);
|
||||||
|
|
||||||
|
response = httpClient.execute(httpGet);
|
||||||
|
|
||||||
|
HttpEntity entity = response.getEntity();
|
||||||
|
|
||||||
|
result = EntityUtils.toString(entity);
|
||||||
|
} catch (ClientProtocolException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
|
||||||
|
if (null != response) {
|
||||||
|
try {
|
||||||
|
response.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (null != httpClient) {
|
||||||
|
try {
|
||||||
|
httpClient.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
|||||||
181
src/main/java/cn/stock/market/utils/NseIndiaRequest.java
Normal file
181
src/main/java/cn/stock/market/utils/NseIndiaRequest.java
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -65,6 +65,50 @@ public class RequestCacheUtils {
|
|||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据时间创建缓存
|
||||||
|
* @param key key
|
||||||
|
* @param duration 时间(毫秒)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Cache<String, ServerResponse<?>> cacheByMilliseconds(String key,long duration) {
|
||||||
|
if(! map.containsKey(key)) {
|
||||||
|
log.info("创建缓存: {}", key);
|
||||||
|
Cache<String, ServerResponse<?>> cache = CacheBuilder.newBuilder()
|
||||||
|
.maximumSize(1000)
|
||||||
|
.expireAfterWrite(duration,TimeUnit.MILLISECONDS)
|
||||||
|
.weakValues()
|
||||||
|
.recordStats()
|
||||||
|
.build(
|
||||||
|
// new CacheLoader<String, Object>() {
|
||||||
|
// @Override
|
||||||
|
// public Object load(String key) throws Exception {
|
||||||
|
// return func.apply(key);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
);
|
||||||
|
map.put(key, cache);
|
||||||
|
}
|
||||||
|
|
||||||
|
return map.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
public static <T> ServerResponse<T> cache(String module, String key,long duration, Function<String, ServerResponse<?>> func) {
|
||||||
|
Cache<String, ServerResponse<?>> cache = cacheByMilliseconds(module,duration);
|
||||||
|
AtomicBoolean bool = new AtomicBoolean(true);
|
||||||
|
ServerResponse<T> response = (ServerResponse<T>) cache.get(key, () -> {
|
||||||
|
bool.set(false);
|
||||||
|
return func.apply(key);
|
||||||
|
});
|
||||||
|
|
||||||
|
if(bool.get()) {
|
||||||
|
log.info("命中缓存 module: {}, key: {}, 时间戳: {}", module, key, System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
ServerResponse<Object> response = null;
|
ServerResponse<Object> response = null;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import cn.stock.market.domain.basic.service.SiteArticleService;
|
|||||||
import cn.stock.market.utils.ServerResponse;
|
import cn.stock.market.utils.ServerResponse;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping({"/api/market/art/", "/api/hq/art/"})
|
@RequestMapping({"/market/api/market/art/","/market/api/market/art/","/api/market/art/", "/api/hq/art/"})
|
||||||
@Api(tags = "公告信息")
|
@Api(tags = "公告信息")
|
||||||
public class ArticleApiController extends BaseController {
|
public class ArticleApiController extends BaseController {
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package cn.stock.market.web;
|
|||||||
|
|
||||||
import cn.stock.market.domain.basic.entity.BtodayStock;
|
import cn.stock.market.domain.basic.entity.BtodayStock;
|
||||||
import cn.stock.market.domain.basic.service.BtodayStockService;
|
import cn.stock.market.domain.basic.service.BtodayStockService;
|
||||||
|
import cn.stock.market.web.annotations.EncryptFilter;
|
||||||
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;
|
||||||
@@ -21,6 +22,7 @@ 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;
|
||||||
|
|
||||||
@@ -34,7 +36,7 @@ public class BTodayStockController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private BtodayStockService btodayStockService;
|
private BtodayStockService btodayStockService;
|
||||||
|
|
||||||
@GetMapping("/api/bToday/kLine")
|
@GetMapping({"/market/api/bToday/kLine","/api/bToday/kLine"})
|
||||||
@ApiOperation(value = "股票详情K线图",httpMethod = "GET")
|
@ApiOperation(value = "股票详情K线图",httpMethod = "GET")
|
||||||
@ApiImplicitParams({
|
@ApiImplicitParams({
|
||||||
@ApiImplicitParam(name="exchange",value = "BSE或者NSE"),
|
@ApiImplicitParam(name="exchange",value = "BSE或者NSE"),
|
||||||
@@ -43,6 +45,8 @@ public class BTodayStockController {
|
|||||||
@ApiImplicitParam(name="durationtype",value = "D(1D的时候传D),D(5D的时候传D),M(3M的时候传M),Y(1Y的时候传Y),Y(5Y的时候传Y),Y(10Y的时候传Y)"),
|
@ApiImplicitParam(name="durationtype",value = "D(1D的时候传D),D(5D的时候传D),M(3M的时候传M),Y(1Y的时候传Y),Y(5Y的时候传Y),Y(10Y的时候传Y)"),
|
||||||
@ApiImplicitParam(name="duration",value = "1(1D的时候传1),5(5D的时候传5),3(3M的时候传3),1(1Y的时候传1),5(5Y的时候传5),10(10Y的时候传10)"),
|
@ApiImplicitParam(name="duration",value = "1(1D的时候传1),5(5D的时候传5),3(3M的时候传3),1(1Y的时候传1),5(5Y的时候传5),10(10Y的时候传10)"),
|
||||||
})
|
})
|
||||||
|
@EncryptFilter(decryptRequest = false)
|
||||||
|
|
||||||
public JSONArray getPriceChartCompanyPullView(
|
public JSONArray getPriceChartCompanyPullView(
|
||||||
@RequestParam(value = "exchange") String exchange,
|
@RequestParam(value = "exchange") String exchange,
|
||||||
@RequestParam(value = "co_code") String coCode,
|
@RequestParam(value = "co_code") String coCode,
|
||||||
@@ -137,7 +141,8 @@ public class BTodayStockController {
|
|||||||
"fromredis: 标志是否来自 Redis 缓存,false 表示不是", response = JSONObject.class),
|
"fromredis: 标志是否来自 Redis 缓存,false 表示不是", response = JSONObject.class),
|
||||||
|
|
||||||
})
|
})
|
||||||
@GetMapping("/api/bToday/stockDetail")
|
@GetMapping({"/market/api/bToday/stockDetail","/api/bToday/stockDetail"})
|
||||||
|
@EncryptFilter(decryptRequest = false)
|
||||||
public com.alibaba.fastjson.JSONObject getPriceChartCompanyPullView(
|
public com.alibaba.fastjson.JSONObject getPriceChartCompanyPullView(
|
||||||
@RequestParam(value = "exchange") String exchange,
|
@RequestParam(value = "exchange") String exchange,
|
||||||
@RequestParam(value = "co_code") String coCode
|
@RequestParam(value = "co_code") String coCode
|
||||||
@@ -155,6 +160,19 @@ 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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import springfox.documentation.annotations.ApiIgnore;
|
|||||||
* @created Dec 4, 2018 10:22:44 PM
|
* @created Dec 4, 2018 10:22:44 PM
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/hq/")
|
@RequestMapping({"/market/api/hq/","/api/hq/"})
|
||||||
@ApiIgnore
|
@ApiIgnore
|
||||||
public class InfoController {
|
public class InfoController {
|
||||||
@Value("${spring.application.name}")
|
@Value("${spring.application.name}")
|
||||||
@@ -40,6 +40,7 @@ public class InfoController {
|
|||||||
public Map<String, Object> test(@RequestParam(required = false) String key) {
|
public Map<String, Object> test(@RequestParam(required = false) String key) {
|
||||||
Map<String, Object> map = Maps.newHashMap();
|
Map<String, Object> map = Maps.newHashMap();
|
||||||
map.put("stockMarketDbUrl", stockMarketDbUrl);
|
map.put("stockMarketDbUrl", stockMarketDbUrl);
|
||||||
|
map.put("stockMarketDbUrl1", stockMarketDbUrl);
|
||||||
if(StringUtils.isNotBlank(key)) {
|
if(StringUtils.isNotBlank(key)) {
|
||||||
map.put("key", PropertiesUtil.getProperty(key));
|
map.put("key", PropertiesUtil.getProperty(key));
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
84
src/main/java/cn/stock/market/web/MoneyProxyApiControl.java
Normal file
84
src/main/java/cn/stock/market/web/MoneyProxyApiControl.java
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
package cn.stock.market.web;
|
||||||
|
|
||||||
|
import cn.stock.market.dto.model.StockListVO;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author gs
|
||||||
|
* @date 2024/2/15 下午9:18
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
public class MoneyProxyApiControl {
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping({"/market/api/proxy/queryStockMoneyProxy","/api/proxy/queryStockMoneyProxy"})
|
||||||
|
public JSONObject queryStockByMoneyIdAndExchangeType(String scId,String exchangeType){
|
||||||
|
log.info("queryStockByMoneyIdAndExchangeType");
|
||||||
|
return stockByMoneyIdAndExchangeTypeFromHttp(scId,exchangeType);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static JSONObject stockByMoneyIdAndExchangeTypeFromHttp(String scId, String exchangeType) {
|
||||||
|
try {
|
||||||
|
String url = "https://moneycontrol.titanrwa.org/pricefeed/"+exchangeType+"/equitycash/" + scId ;
|
||||||
|
URL obj = new URL(url);
|
||||||
|
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
||||||
|
con.setRequestMethod("GET");
|
||||||
|
|
||||||
|
int responseCode = con.getResponseCode();
|
||||||
|
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||||
|
String inputLine;
|
||||||
|
StringBuilder response = new StringBuilder();
|
||||||
|
while ((inputLine = in.readLine()) != null) {
|
||||||
|
response.append(inputLine);
|
||||||
|
}
|
||||||
|
in.close();
|
||||||
|
// 解析JSON数据
|
||||||
|
log.info("stockByCodeAndExchangeType:获取 sc_id:{}, exchangeType: {} 的实时价格的结果:{} ",scId,exchangeType,response.toString());
|
||||||
|
return JSONObject.parseObject(response.toString());
|
||||||
|
} else {
|
||||||
|
log.error("HTTP request failed with response code: " + responseCode);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
log.error("stockByMoneyIdAndExchangeTypeFromHttp failed {}",e.getMessage());
|
||||||
|
}
|
||||||
|
return new JSONObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static StockListVO mapJsonToMoneyStockListVO(JSONObject jsonObject) {
|
||||||
|
StockListVO stockListVO = new StockListVO();
|
||||||
|
if (jsonObject != null) {
|
||||||
|
JSONObject data = jsonObject.getJSONObject("data");
|
||||||
|
if(data!=null&&!data.isEmpty()){
|
||||||
|
stockListVO.setName(data.getString("company"));
|
||||||
|
stockListVO.setCode(data.getString("code"));
|
||||||
|
stockListVO.setSpell(data.getString("company"));
|
||||||
|
stockListVO.setGid(data.getString("symbol"));
|
||||||
|
stockListVO.setNowPrice(data.getString("pricecurrent"));
|
||||||
|
stockListVO.setOpen_px(data.getString("OPN"));
|
||||||
|
stockListVO.setPreclose_px(data.getString("priceprevclose"));
|
||||||
|
stockListVO.setHcrate(new BigDecimal(data.getString("pricepercentchange")));
|
||||||
|
stockListVO.setSymbol(data.getString("symbol"));
|
||||||
|
stockListVO.setPricechange(data.getString("pricechange"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stockListVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@ import cn.stock.market.domain.basic.service.SiteNewsService;
|
|||||||
import cn.stock.market.utils.ServerResponse;
|
import cn.stock.market.utils.ServerResponse;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping({"/api/market/news/", "/api/hq/news/"})
|
@RequestMapping({"/market/api/market/news/", "/market/api/hq/news/","/api/market/news/", "/api/hq/news/"})
|
||||||
@Api(tags="新闻资讯")
|
@Api(tags="新闻资讯")
|
||||||
public class SiteNewsController {
|
public class SiteNewsController {
|
||||||
private static final Logger log = LoggerFactory.getLogger(SiteNewsController.class);
|
private static final Logger log = LoggerFactory.getLogger(SiteNewsController.class);
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ 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;
|
||||||
@@ -12,6 +14,7 @@ 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;
|
||||||
@@ -56,7 +59,7 @@ import springfox.documentation.annotations.ApiIgnore;
|
|||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@Api(value = "/StockApiController", tags = "股票行情")
|
@Api(value = "/StockApiController", tags = "股票行情")
|
||||||
@RequestMapping({"/api/market/stock/", "/api/hq/stock/"})
|
@RequestMapping({"/market/api/market/stock/", "/market/api/hq/stock/","/api/market/stock/", "/api/hq/stock/"})
|
||||||
public class StockApiController {
|
public class StockApiController {
|
||||||
private static final Logger log = LoggerFactory.getLogger(StockApiController.class);
|
private static final Logger log = LoggerFactory.getLogger(StockApiController.class);
|
||||||
|
|
||||||
@@ -167,6 +170,41 @@ public class StockApiController {
|
|||||||
return ServerResponse.createBySuccess(newsRepository.findAll(ConditionBuilder.builder().build(), PageParam.of(pageNum, pageSize), QSiteNewsPO.siteNewsPO.id.desc()));
|
return ServerResponse.createBySuccess(newsRepository.findAll(ConditionBuilder.builder().build(), PageParam.of(pageNum, pageSize), QSiteNewsPO.siteNewsPO.id.desc()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping({"test.do"})
|
||||||
|
@ResponseBody
|
||||||
|
public ServerResponse test(/*@RequestParam("url") String url, @RequestParam("pageNum") Integer pageNum*/) {
|
||||||
|
String news = stockService.getNews();
|
||||||
|
List<String> newsList = Arrays.asList(news.split("<a href="));
|
||||||
|
newsList = newsList.subList(1, newsList.size());
|
||||||
|
newsList.forEach( n -> {
|
||||||
|
String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2);
|
||||||
|
String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_"));
|
||||||
|
String imgUrl = InvestingTask.extractImgSrc(n);
|
||||||
|
// 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.setAddTime(new Date());
|
||||||
|
siteNews.setSourceId(id);
|
||||||
|
siteNews.setDescription(time);
|
||||||
|
siteNews.setImgurl(imgUrl);
|
||||||
|
List<String> newsInfo = stockService.getNewsInfo(contentUrl);
|
||||||
|
siteNews.setContent(newsInfo.get(0));
|
||||||
|
siteNews.setTitle(newsInfo.get(1));
|
||||||
|
List<SiteNews> list = newsRepository.findAll(QSiteNewsPO.siteNewsPO.sourceId.eq(id));
|
||||||
|
if (list.size() == 0) {
|
||||||
|
newsRepository.save(siteNews);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return ServerResponse.createBySuccess();
|
||||||
|
}
|
||||||
|
|
||||||
//印度股票时线-K线
|
//印度股票时线-K线
|
||||||
@RequestMapping({"getINDTimeK.do"})
|
@RequestMapping({"getINDTimeK.do"})
|
||||||
@ApiOperation(value = "印度股票K线", httpMethod = "GET")
|
@ApiOperation(value = "印度股票K线", httpMethod = "GET")
|
||||||
@@ -205,6 +243,29 @@ public class StockApiController {
|
|||||||
return this.stockService.getIndiaIndex();
|
return this.stockService.getIndiaIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping({"getIndiaIndexByToday.do"})
|
||||||
|
@ApiOperation(value = "印度--获取指定指数信息", httpMethod = "GET")
|
||||||
|
@ResponseBody
|
||||||
|
public ServerResponse getIndiaIndexByToday() {
|
||||||
|
String INDEX_CODE = "TODAY_INDEX";
|
||||||
|
return RequestCacheUtils.cache("getIndiaIndexByToday.do", INDEX_CODE,6000, (string) -> {
|
||||||
|
try {
|
||||||
|
return this.stockService.getIndexByBtoday();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@RequestMapping({"getIndiaIndexByEttech.do"})
|
||||||
|
@ApiOperation(value = "印度--获取指定指数信息-Ettech", httpMethod = "GET")
|
||||||
|
@ResponseBody
|
||||||
|
public ServerResponse getIndiaIndexByEttech() {
|
||||||
|
String INDEX_CODE = "TODAY_INDEX";
|
||||||
|
return RequestCacheUtils.cache("getIndiaIndexByEttech.do", INDEX_CODE, (string) -> {
|
||||||
|
return this.stockService.getEttechcharts();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//根据股票id查询 股票指数、大盘指数信息
|
//根据股票id查询 股票指数、大盘指数信息
|
||||||
@RequestMapping({"getMarketByStockGid.do"})
|
@RequestMapping({"getMarketByStockGid.do"})
|
||||||
@ApiOperation(value = "根据股票id查询 股票指数、大盘指数信息", httpMethod = "GET")
|
@ApiOperation(value = "根据股票id查询 股票指数、大盘指数信息", httpMethod = "GET")
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package cn.stock.market.web;
|
|||||||
|
|
||||||
import cn.stock.market.infrastructure.api.TodayApis;
|
import cn.stock.market.infrastructure.api.TodayApis;
|
||||||
import cn.stock.market.utils.ServerResponse;
|
import cn.stock.market.utils.ServerResponse;
|
||||||
|
import cn.stock.market.web.annotations.EncryptFilter;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
@@ -11,12 +12,13 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@Api(value = "/TodayApiController", tags = "today股票行情")
|
@Api(value = "/TodayApiController", tags = "today股票行情")
|
||||||
@RequestMapping({"/api/market/today/"})
|
@RequestMapping({"/market/api/market/today/","/api/market/today/"})
|
||||||
public class TodayApiController {
|
public class TodayApiController {
|
||||||
|
|
||||||
@RequestMapping({"getTopGainers.do"})
|
@RequestMapping({"getTopGainers.do"})
|
||||||
@ApiOperation(value = "获取Top Gainers",notes = "exchange传nse或者bse", httpMethod = "GET")
|
@ApiOperation(value = "获取Top Gainers",notes = "exchange传nse或者bse", httpMethod = "GET")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
@EncryptFilter(decryptRequest = false)
|
||||||
public ServerResponse getTopGainers(@RequestParam("exchange") String exchange) {
|
public ServerResponse getTopGainers(@RequestParam("exchange") String exchange) {
|
||||||
return ServerResponse.createBySuccess(TodayApis.getTopGainers(exchange));
|
return ServerResponse.createBySuccess(TodayApis.getTopGainers(exchange));
|
||||||
}
|
}
|
||||||
@@ -24,6 +26,7 @@ public class TodayApiController {
|
|||||||
@RequestMapping({"getTopLosers.do"})
|
@RequestMapping({"getTopLosers.do"})
|
||||||
@ApiOperation(value = "获取 Top Losers",notes = "exchange传nse或者bse", httpMethod = "GET")
|
@ApiOperation(value = "获取 Top Losers",notes = "exchange传nse或者bse", httpMethod = "GET")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
@EncryptFilter(decryptRequest = false)
|
||||||
public ServerResponse getTopLosers(@RequestParam("exchange") String exchange) {
|
public ServerResponse getTopLosers(@RequestParam("exchange") String exchange) {
|
||||||
return ServerResponse.createBySuccess(TodayApis.getTopLosers(exchange));
|
return ServerResponse.createBySuccess(TodayApis.getTopLosers(exchange));
|
||||||
}
|
}
|
||||||
@@ -31,6 +34,7 @@ public class TodayApiController {
|
|||||||
@RequestMapping({"getMostActiveVolume.do"})
|
@RequestMapping({"getMostActiveVolume.do"})
|
||||||
@ApiOperation(value = "获取 Most Active Volume",notes = "exchange传nse或者bse", httpMethod = "GET")
|
@ApiOperation(value = "获取 Most Active Volume",notes = "exchange传nse或者bse", httpMethod = "GET")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
@EncryptFilter(decryptRequest = false)
|
||||||
public ServerResponse getMostActiveVolume(@RequestParam("exchange") String exchange) {
|
public ServerResponse getMostActiveVolume(@RequestParam("exchange") String exchange) {
|
||||||
return ServerResponse.createBySuccess(TodayApis.getMostActiveVolume(exchange));
|
return ServerResponse.createBySuccess(TodayApis.getMostActiveVolume(exchange));
|
||||||
}
|
}
|
||||||
@@ -38,6 +42,7 @@ public class TodayApiController {
|
|||||||
@RequestMapping({"getMostActiveValue.do"})
|
@RequestMapping({"getMostActiveValue.do"})
|
||||||
@ApiOperation(value = "获取 Most Active Value",notes = "exchange传nse或者bse",httpMethod = "GET")
|
@ApiOperation(value = "获取 Most Active Value",notes = "exchange传nse或者bse",httpMethod = "GET")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
@EncryptFilter(decryptRequest = false)
|
||||||
public ServerResponse getMostActiveValue(@RequestParam("exchange") String exchange) {
|
public ServerResponse getMostActiveValue(@RequestParam("exchange") String exchange) {
|
||||||
return ServerResponse.createBySuccess(TodayApis.getMostActiveValue(exchange));
|
return ServerResponse.createBySuccess(TodayApis.getMostActiveValue(exchange));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ spring:
|
|||||||
show-sql: true
|
show-sql: true
|
||||||
# Redis配置
|
# Redis配置
|
||||||
redis:
|
redis:
|
||||||
host: 43.132.212.180
|
host: 43.153.142.41
|
||||||
password: ruTZ9J3gaDhknJ
|
password: a5v8b86P4mVzFlUqJV
|
||||||
port: 36379
|
port: 30041
|
||||||
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.132.212.180:33306/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: 33BsUUcnXRYgwt
|
password: uNejHIFQGJOUtYTmE
|
||||||
maxActive: 500
|
maxActive: 500
|
||||||
testWhileIdle: true
|
testWhileIdle: true
|
||||||
validationQuery: SELECT 1
|
validationQuery: SELECT 1
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user