Compare commits
50 Commits
twelvedata
...
feature/up
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa02ebf03b | ||
|
|
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 |
@@ -2,7 +2,7 @@ stages:
|
|||||||
# 构建
|
# 构建
|
||||||
- build
|
- build
|
||||||
- dockerize
|
- dockerize
|
||||||
- webhook
|
- deploy
|
||||||
|
|
||||||
build:
|
build:
|
||||||
image: maven:3.6.3-openjdk-8
|
image: maven:3.6.3-openjdk-8
|
||||||
@@ -60,16 +60,20 @@ dockerize:
|
|||||||
- docker push juyoutech/india_stock_market:latest
|
- docker push juyoutech/india_stock_market:latest
|
||||||
- docker push juyoutech/india_stock_market:$CI_PIPELINE_ID
|
- docker push juyoutech/india_stock_market:$CI_PIPELINE_ID
|
||||||
- docker push juyoutech/india_stock_market:$CI_COMMIT_BRANCH
|
- docker push juyoutech/india_stock_market:$CI_COMMIT_BRANCH
|
||||||
webhook:
|
deploy-dev:
|
||||||
stage: webhook
|
stage: deploy
|
||||||
only:
|
only:
|
||||||
- develop
|
- develop
|
||||||
script:
|
script:
|
||||||
- echo ">>>>>>Start Deploy<<<<<<"
|
- echo "Deploying application..."
|
||||||
- ls
|
- ls
|
||||||
- apt-get update
|
- apt-get update
|
||||||
- apt-get install -y curl
|
- apt-get install -y curl
|
||||||
- curl --max-time 30 http://149.88.86.7:11113/api/webhook/justpull?project=india_market_java\&setenv_file=alpha.sh\&publish_env=alpha\&shell=deploy-test.sh
|
- |
|
||||||
- echo ">>>>>>Start Deploy Finish<<<<<<"
|
curl -X POST \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"namespace":"yddev", "deployment_name":"india-stock-market"}' \
|
||||||
|
https://updater-yddev.moneytj.com/restart-deployment
|
||||||
|
- echo "Application successfully deployed."
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
6
pom.xml
6
pom.xml
@@ -185,6 +185,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>
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -38,6 +38,7 @@ public class QStockIpoPO extends EntityPathBase<StockIpoPO> {
|
|||||||
public final StringPath stockCode = createString("stockCode");
|
public final StringPath stockCode = createString("stockCode");
|
||||||
|
|
||||||
public final StringPath stockName = createString("stockName");
|
public final StringPath stockName = createString("stockName");
|
||||||
|
public final StringPath exchangeType = createString("exchangeType");
|
||||||
|
|
||||||
public final NumberPath<java.math.BigDecimal> stockPrice = createNumber("stockPrice", java.math.BigDecimal.class);
|
public final NumberPath<java.math.BigDecimal> stockPrice = createNumber("stockPrice", java.math.BigDecimal.class);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,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,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,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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,6 +30,8 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import cn.stock.market.infrastructure.db.po.QStockPO;
|
import cn.stock.market.infrastructure.db.po.QStockPO;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
|
import org.jsoup.nodes.Element;
|
||||||
|
import org.jsoup.select.Elements;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpEntity;
|
||||||
@@ -247,12 +249,25 @@ public class StockService {
|
|||||||
String result = "";
|
String result = "";
|
||||||
try {
|
try {
|
||||||
// 使用Jsoup连接到网页
|
// 使用Jsoup连接到网页
|
||||||
Document doc = Jsoup.connect("https://www.business-standard.com/markets/news")
|
// Document doc = Jsoup.connect("https://www.business-standard.com/markets/news")
|
||||||
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36")
|
// .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36")
|
||||||
.header("Referer", "https://www.business-standard.com/")
|
// .header("Referer", "https://www.business-standard.com/")
|
||||||
|
// .header("Accept-Language", "en-US,en;q=0.9")
|
||||||
|
// .get();
|
||||||
|
String url = "https://www.business-standard.com/markets/news";
|
||||||
|
Document doc = Jsoup.connect(url)
|
||||||
|
.referrer("https://www.business-standard.com/")
|
||||||
.header("Accept-Language", "en-US,en;q=0.9")
|
.header("Accept-Language", "en-US,en;q=0.9")
|
||||||
|
.userAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1")
|
||||||
|
.timeout(5000) // timeout 5 seconds
|
||||||
.get();
|
.get();
|
||||||
result = doc.html().substring(doc.html().indexOf("<div class=\"shortvideoimg\" style=\"position:relative\">"),doc.html().lastIndexOf("<div class=\"shortvideoimg\" style=\"position:relative\">")+1200);
|
// 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();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return e.toString();
|
return e.toString();
|
||||||
}
|
}
|
||||||
@@ -264,10 +279,16 @@ public class StockService {
|
|||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
// 使用Jsoup连接到网页
|
// 使用Jsoup连接到网页
|
||||||
|
// Document doc = Jsoup.connect(url)
|
||||||
|
// .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36")
|
||||||
|
// .header("Referer", "https://www.business-standard.com/")
|
||||||
|
// .header("Accept-Language", "en-US,en;q=0.9")
|
||||||
|
// .get();
|
||||||
Document doc = Jsoup.connect(url)
|
Document doc = Jsoup.connect(url)
|
||||||
.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")
|
.referrer("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")
|
||||||
|
.userAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1")
|
||||||
|
.timeout(5000) // timeout 5 seconds
|
||||||
.get();
|
.get();
|
||||||
result = doc.html().substring(doc.html().indexOf("articleBody") + 14, doc.html().indexOf(",\"author\":") - 1);
|
result = doc.html().substring(doc.html().indexOf("articleBody") + 14, doc.html().indexOf(",\"author\":") - 1);
|
||||||
list.add(result);
|
list.add(result);
|
||||||
@@ -974,7 +995,7 @@ public class StockService {
|
|||||||
String exchange = "bse";
|
String exchange = "bse";
|
||||||
IndiaIndexVo vo1 = new IndiaIndexVo();
|
IndiaIndexVo vo1 = new IndiaIndexVo();
|
||||||
String coCode = "20558";
|
String coCode = "20558";
|
||||||
JSONObject object = TodayApis.getStockDetail(exchange, coCode);
|
JSONObject object = TodayApis.getStockDetail("in%3BSEN", coCode);
|
||||||
IndiaStockVO market = objToVo(object);
|
IndiaStockVO market = objToVo(object);
|
||||||
market.setName("BSESENSEX指数");
|
market.setName("BSESENSEX指数");
|
||||||
vo1.setIndexVo(market);
|
vo1.setIndexVo(market);
|
||||||
@@ -1004,7 +1025,7 @@ public class StockService {
|
|||||||
String exchange = "nse";
|
String exchange = "nse";
|
||||||
IndiaIndexVo vo1 = new IndiaIndexVo();
|
IndiaIndexVo vo1 = new IndiaIndexVo();
|
||||||
String coCode = "20559";
|
String coCode = "20559";
|
||||||
JSONObject object = TodayApis.getStockDetail(exchange, coCode);
|
JSONObject object = TodayApis.getStockDetail("in%3BNSX", coCode);
|
||||||
IndiaStockVO market = objToVo(object);
|
IndiaStockVO market = objToVo(object);
|
||||||
market.setName("NIFTY50指数");
|
market.setName("NIFTY50指数");
|
||||||
vo1.setIndexVo(market);
|
vo1.setIndexVo(market);
|
||||||
@@ -1034,23 +1055,23 @@ public class StockService {
|
|||||||
}
|
}
|
||||||
private IndiaStockVO objToVo(JSONObject object){
|
private IndiaStockVO objToVo(JSONObject object){
|
||||||
IndiaStockVO market = new IndiaStockVO();
|
IndiaStockVO market = new IndiaStockVO();
|
||||||
if(object.containsKey("prev_close")){
|
if(object.containsKey("priceprevclose")){
|
||||||
market.setClose(object.getString("prev_close"));
|
market.setClose(object.getString("priceprevclose"));
|
||||||
}
|
}
|
||||||
if(object.containsKey("price")){
|
if(object.containsKey("pricecurrent")){
|
||||||
market.setNowPrice(object.getString("price"));
|
market.setNowPrice(object.getString("pricecurrent"));
|
||||||
}
|
}
|
||||||
if(object.containsKey("perchg")){
|
if(object.containsKey("pricepercentchange")){
|
||||||
market.setRate(object.getString("perchg"));
|
market.setRate(object.getString("pricepercentchange"));
|
||||||
}
|
}
|
||||||
if(object.containsKey("high_price")){
|
if(object.containsKey("HIGH")){
|
||||||
market.setHigh(object.getString("high_price"));
|
market.setHigh(object.getString("HIGH"));
|
||||||
}
|
}
|
||||||
if(object.containsKey("low_price")){
|
if(object.containsKey("LOW")){
|
||||||
market.setLow(object.getString("low_price"));
|
market.setLow(object.getString("LOW"));
|
||||||
}
|
}
|
||||||
if(object.containsKey("open_price")){
|
if(object.containsKey("OPEN")){
|
||||||
market.setOpen(object.getString("open_price"));
|
market.setOpen(object.getString("OPEN"));
|
||||||
}
|
}
|
||||||
return market;
|
return market;
|
||||||
// stockListVO.setName(jsonObject.getString("companyname"));
|
// stockListVO.setName(jsonObject.getString("companyname"));
|
||||||
|
|||||||
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -187,18 +187,17 @@ public class TodayApis {
|
|||||||
|
|
||||||
//获取详情
|
//获取详情
|
||||||
public static JSONObject getStockDetail(String exchange,String coCode){
|
public static JSONObject getStockDetail(String exchange,String coCode){
|
||||||
String url = String.format("https://marketapi.intoday.in/widget/stockdetail/pullview?co_code=%s&exchange=%s",coCode,exchange);
|
String url = String.format("https://priceapi.moneycontrol.com/pricefeed/notapplicable/inidicesindia/%s",exchange);
|
||||||
String str = get(url);
|
String str = get(url);
|
||||||
JSONObject object = JSON.parseObject(str);
|
JSONObject object = JSON.parseObject(str);
|
||||||
boolean bool = false;
|
boolean bool = false;
|
||||||
if(object.containsKey("success")){
|
if(object.containsKey("code")){
|
||||||
bool = object.getBoolean("success");
|
bool = object.getInteger("code") == 200;
|
||||||
}
|
}
|
||||||
if(!bool){
|
if(!bool){
|
||||||
return new JSONObject();
|
return new JSONObject();
|
||||||
}
|
}
|
||||||
JSONArray jsonArray = JSON.parseArray(object.getString("data"));
|
JSONObject entity = JSON.parseObject(object.getString("data"));
|
||||||
JSONObject entity = JSON.parseObject(jsonArray.get(0).toString());
|
|
||||||
return entity;
|
return entity;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -79,6 +79,8 @@ public class StockIpoPO {
|
|||||||
* 申请总额 */
|
* 申请总额 */
|
||||||
String apply;
|
String apply;
|
||||||
|
|
||||||
|
String exchangeType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 市盈率 */
|
* 市盈率 */
|
||||||
BigDecimal peRatio;
|
BigDecimal peRatio;
|
||||||
|
|||||||
@@ -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> {
|
||||||
|
}
|
||||||
@@ -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
|
||||||
@@ -118,8 +121,16 @@ public class InvestingTask {
|
|||||||
newsList.forEach( n -> {
|
newsList.forEach( n -> {
|
||||||
String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2);
|
String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2);
|
||||||
String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_"));
|
String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_"));
|
||||||
String imgUrl = n.substring(n.indexOf("img loading=\"lazy\" src=") + 24, n.indexOf("?"));
|
// String imgUrl = n.substring(n.indexOf("img loading=\"lazy\" src=") + 24, n.indexOf("?"));
|
||||||
String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9);
|
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());
|
||||||
@@ -140,4 +151,22 @@ public class InvestingTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String extractImgSrc(String htmlData) {
|
||||||
|
String searchString = "<noscript>";
|
||||||
|
int startPos = htmlData.indexOf(searchString);
|
||||||
|
|
||||||
|
if (startPos != -1) {
|
||||||
|
String startTag = "src=";
|
||||||
|
startPos = htmlData.indexOf(startTag, startPos) + startTag.length() + 1;
|
||||||
|
|
||||||
|
int endPos = htmlData.indexOf("?", startPos);
|
||||||
|
|
||||||
|
if (endPos != -1) {
|
||||||
|
return htmlData.substring(startPos, endPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,20 @@
|
|||||||
package cn.stock.market.infrastructure.job;
|
package cn.stock.market.infrastructure.job;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import cn.hutool.core.date.DateTime;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.stock.market.domain.basic.entity.BtodayStock;
|
import cn.stock.market.domain.basic.entity.BtodayStock;
|
||||||
|
import cn.stock.market.domain.basic.entity.MoneyStock;
|
||||||
import cn.stock.market.domain.basic.entity.StockIpo;
|
import cn.stock.market.domain.basic.entity.StockIpo;
|
||||||
import cn.stock.market.domain.basic.repository.BtodayStockRepository;
|
import cn.stock.market.domain.basic.repository.BtodayStockRepository;
|
||||||
|
import cn.stock.market.domain.basic.repository.MoneyStockRepository;
|
||||||
import cn.stock.market.domain.basic.repository.StockIpoRepository;
|
import cn.stock.market.domain.basic.repository.StockIpoRepository;
|
||||||
import cn.stock.market.dto.StockIpoDTO;
|
import cn.stock.market.dto.StockIpoDTO;
|
||||||
|
import cn.stock.market.infrastructure.db.po.QMoneyStockPO;
|
||||||
import cn.stock.market.infrastructure.db.po.QStockIpoPO;
|
import cn.stock.market.infrastructure.db.po.QStockIpoPO;
|
||||||
import cn.stock.market.infrastructure.db.po.StockIpoPO;
|
import cn.stock.market.infrastructure.db.po.StockIpoPO;
|
||||||
import cn.stock.market.infrastructure.db.repo.BtodayStockRepo;
|
import cn.stock.market.infrastructure.db.repo.BtodayStockRepo;
|
||||||
|
import com.alibaba.druid.sql.visitor.functions.Now;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
@@ -31,14 +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.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;
|
||||||
@@ -54,6 +57,10 @@ 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 * ?")
|
||||||
@@ -104,6 +111,7 @@ public class Scraper {
|
|||||||
|
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 18 * * ?")
|
@Scheduled(cron = "0 0 18 * * ?")
|
||||||
|
// @PostConstruct
|
||||||
@RequestMapping("/testScraperGetMoneyControllerNewIPO")
|
@RequestMapping("/testScraperGetMoneyControllerNewIPO")
|
||||||
public void getMoneyControllerNewIPOSchedule() {
|
public void getMoneyControllerNewIPOSchedule() {
|
||||||
log.info("定时任务执行获取新股ipo的方法开始执行");
|
log.info("定时任务执行获取新股ipo的方法开始执行");
|
||||||
@@ -163,7 +171,28 @@ public class Scraper {
|
|||||||
stockIpo.setCreateDate(new Date());
|
stockIpo.setCreateDate(new Date());
|
||||||
stockIpo.setUpdateDate(new Date());
|
stockIpo.setUpdateDate(new Date());
|
||||||
stockIpo.setSourceType("3");
|
stockIpo.setSourceType("3");
|
||||||
listStockIpoList.add(stockIpo);
|
|
||||||
|
if (stockIpo.getStockCode() == null || stockIpo.getStockName() == null){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> exchanges = getIpoExchange(stockIpo.getStockName(), stockIpo.getStockCode());
|
||||||
|
|
||||||
|
for (String exchange : exchanges) {
|
||||||
|
StockIpo ipo = new StockIpo();
|
||||||
|
ipo.setStockCode(stockIpo.getStockCode());
|
||||||
|
ipo.setStockName(stockIpo.getStockName());
|
||||||
|
ipo.setStockPrice(stockIpo.getStockPrice());
|
||||||
|
ipo.setSubscriptionDate(stockIpo.getSubscriptionDate());
|
||||||
|
ipo.setListingDate(stockIpo.getListingDate());
|
||||||
|
ipo.setTotalNumber(stockIpo.getTotalNumber());
|
||||||
|
ipo.setApply(stockIpo.getApply());
|
||||||
|
ipo.setCreateDate(stockIpo.getCreateDate());
|
||||||
|
ipo.setUpdateDate(stockIpo.getUpdateDate());
|
||||||
|
ipo.setExchangeType(exchange);
|
||||||
|
|
||||||
|
listStockIpoList.add(ipo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < upcomingData.size(); i++) {
|
for (int i = 0; i < upcomingData.size(); i++) {
|
||||||
@@ -186,11 +215,37 @@ public class Scraper {
|
|||||||
stockIpo.setCreateDate(new Date());
|
stockIpo.setCreateDate(new Date());
|
||||||
stockIpo.setUpdateDate(new Date());
|
stockIpo.setUpdateDate(new Date());
|
||||||
stockIpo.setSourceType("3");
|
stockIpo.setSourceType("3");
|
||||||
listStockIpoList.add(stockIpo);
|
|
||||||
|
if (stockIpo.getStockCode() == null || stockIpo.getStockName() == null){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> exchanges = getIpoExchange(stockIpo.getStockName(), stockIpo.getStockCode());
|
||||||
|
|
||||||
|
for (String exchange : exchanges) {
|
||||||
|
StockIpo ipo = new StockIpo();
|
||||||
|
ipo.setStockCode(stockIpo.getStockCode());
|
||||||
|
ipo.setStockName(stockIpo.getStockName());
|
||||||
|
ipo.setStockPrice(stockIpo.getStockPrice());
|
||||||
|
ipo.setSubscriptionDate(stockIpo.getSubscriptionDate());
|
||||||
|
ipo.setListingDate(stockIpo.getListingDate());
|
||||||
|
ipo.setTotalNumber(stockIpo.getTotalNumber());
|
||||||
|
ipo.setApply(stockIpo.getApply());
|
||||||
|
ipo.setCreateDate(stockIpo.getCreateDate());
|
||||||
|
ipo.setUpdateDate(stockIpo.getUpdateDate());
|
||||||
|
ipo.setExchangeType(exchange);
|
||||||
|
|
||||||
|
listStockIpoList.add(ipo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// stockIpoRepository.saveAll(listStockIpoList);
|
// stockIpoRepository.saveAll(listStockIpoList);
|
||||||
|
|
||||||
|
if (!listStockIpoList.isEmpty())
|
||||||
|
{
|
||||||
|
listStockIpoList = listStockIpoList.stream().filter(a -> StringUtils.isNotBlank(a.getStockName())).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
List<String> scIdList = Lists.transform(listStockIpoList, StockIpo::getStockCode);
|
List<String> scIdList = Lists.transform(listStockIpoList, StockIpo::getStockCode);
|
||||||
if(CollectionUtil.isNotEmpty(scIdList)){
|
if(CollectionUtil.isNotEmpty(scIdList)){
|
||||||
List<StockIpo> existStockIpoList = stockIpoRepository.findAll(QStockIpoPO.stockIpoPO.stockCode.in(scIdList));
|
List<StockIpo> existStockIpoList = stockIpoRepository.findAll(QStockIpoPO.stockIpoPO.stockCode.in(scIdList));
|
||||||
@@ -205,6 +260,7 @@ public class Scraper {
|
|||||||
//保存全部的新股
|
//保存全部的新股
|
||||||
if(CollectionUtil.isNotEmpty(listStockIpoList)){
|
if(CollectionUtil.isNotEmpty(listStockIpoList)){
|
||||||
stockIpoRepository.saveAll(listStockIpoList);
|
stockIpoRepository.saveAll(listStockIpoList);
|
||||||
|
|
||||||
log.info("定时任务执行获取新股ipo的方法开始结束,保存了数据:{}", JSON.toJSONString(listStockIpoList));
|
log.info("定时任务执行获取新股ipo的方法开始结束,保存了数据:{}", JSON.toJSONString(listStockIpoList));
|
||||||
}else {
|
}else {
|
||||||
log.info("定时任务执行获取新股ipo的方法开始结束,没有数据");
|
log.info("定时任务执行获取新股ipo的方法开始结束,没有数据");
|
||||||
@@ -225,6 +281,36 @@ public class Scraper {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 19 * * ?")
|
||||||
|
@PostConstruct
|
||||||
|
@RequestMapping("/addMoneyStock")
|
||||||
|
public void addMoneyStock() {
|
||||||
|
log.info("定时任务执行获取新股ipo的方法开始执行");
|
||||||
|
|
||||||
|
List<StockIpo> stockIpoList;
|
||||||
|
|
||||||
|
if(!times){
|
||||||
|
stockIpoList = stockIpoRepository.findAll(QStockIpoPO.stockIpoPO.listingDate.isNotNull()
|
||||||
|
.and(QStockIpoPO.stockIpoPO.listingDate.loe(DateTime.now()))
|
||||||
|
.and(QStockIpoPO.stockIpoPO.exchangeType.isNotNull())
|
||||||
|
.and(QStockIpoPO.stockIpoPO.exchangeType.isNotEmpty())
|
||||||
|
); // first time run
|
||||||
|
|
||||||
|
times = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
stockIpoList = stockIpoRepository.findAll(QStockIpoPO.stockIpoPO.listingDate.isNotNull()
|
||||||
|
.and(QStockIpoPO.stockIpoPO.listingDate.loe(DateTime.now())
|
||||||
|
.and(QStockIpoPO.stockIpoPO.listingDate.goe(DateUtil.offsetDay(DateTime.now(), -3))))
|
||||||
|
.and(QStockIpoPO.stockIpoPO.exchangeType.isNotNull())
|
||||||
|
.and(QStockIpoPO.stockIpoPO.exchangeType.isNotEmpty())
|
||||||
|
); // from second run
|
||||||
|
}
|
||||||
|
|
||||||
|
List<MoneyStock> moneyStockList = convertToMoneyStock(stockIpoList);
|
||||||
|
moneyStockRepository.saveAll(moneyStockList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static Timestamp convertStringToTimestamp(String dateString) {
|
private static Timestamp convertStringToTimestamp(String dateString) {
|
||||||
// 实现将字符串转换为 Timestamp 的逻辑
|
// 实现将字符串转换为 Timestamp 的逻辑
|
||||||
@@ -236,12 +322,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();
|
||||||
@@ -378,4 +458,134 @@ public class Scraper {
|
|||||||
log.info("Getting web detail URL: " + url + "...");
|
log.info("Getting web detail URL: " + url + "...");
|
||||||
return Jsoup.connect(url).ignoreContentType(true).execute().body();
|
return Jsoup.connect(url).ignoreContentType(true).execute().body();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getIpoExchange(String stockName, String stockCode) {
|
||||||
|
List<String> exchanges = new ArrayList<>();
|
||||||
|
String url = "https://www.moneycontrol.com/ipo/{stockName}-{stockCode}-ipodetail";
|
||||||
|
url = url.replace("{stockName}", stockName.toLowerCase().replace(" ", "-")).replace("{stockCode}", stockCode.toLowerCase());
|
||||||
|
|
||||||
|
org.apache.http.client.HttpClient client = HttpClients.createDefault();
|
||||||
|
HttpGet request = new HttpGet(url);
|
||||||
|
try {
|
||||||
|
org.apache.http.HttpResponse response = client.execute(request);
|
||||||
|
|
||||||
|
if (response.getStatusLine().getStatusCode() == 200) {
|
||||||
|
String responseBody = EntityUtils.toString(response.getEntity());
|
||||||
|
Document doc = Jsoup.parse(responseBody);
|
||||||
|
|
||||||
|
Element scriptTag = doc.selectFirst("script#__NEXT_DATA__");
|
||||||
|
|
||||||
|
if (scriptTag != null) {
|
||||||
|
String jsonDataStr = scriptTag.html();
|
||||||
|
|
||||||
|
com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(jsonDataStr);
|
||||||
|
log.info("获取到新股的json信息:" + jsonObject.toJSONString());
|
||||||
|
|
||||||
|
com.alibaba.fastjson.JSONObject pageProps = jsonObject.getJSONObject("props").getJSONObject("pageProps");
|
||||||
|
com.alibaba.fastjson.JSONObject overview = pageProps.getJSONObject("ipoDetails").getJSONObject("ipoDetails").getJSONObject("overview");
|
||||||
|
|
||||||
|
String exchangeStr = overview.getString("listing_on");
|
||||||
|
|
||||||
|
if (exchangeStr != null && !exchangeStr.isEmpty() && !exchangeStr.equals("null")) {
|
||||||
|
exchanges.addAll(new ArrayList<>(Arrays.asList(exchangeStr.split(","))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
log.info(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exchanges.isEmpty()) {
|
||||||
|
exchanges.add("");
|
||||||
|
}
|
||||||
|
|
||||||
|
return exchanges;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MoneyStock> convertToMoneyStock(List<StockIpo> stockIpoList) {
|
||||||
|
// Lấy danh sách tất cả stockCode và exchangeType từ stockIpoList
|
||||||
|
Set<String> stockCodes = stockIpoList.stream().map(StockIpo::getStockCode).collect(Collectors.toSet());
|
||||||
|
Set<String> exchangeTypes = stockIpoList.stream().map(StockIpo::getExchangeType).collect(Collectors.toSet());
|
||||||
|
|
||||||
|
// Lấy tất cả các MoneyStock tồn tại trong database với stockCode và exchangeType trong stockIpoList
|
||||||
|
List<MoneyStock> existingMoneyStocks = moneyStockRepository.findAll(
|
||||||
|
QMoneyStockPO.moneyStockPO.moneyScId.in(stockCodes)
|
||||||
|
.and(QMoneyStockPO.moneyStockPO.stockType.in(exchangeTypes))
|
||||||
|
);
|
||||||
|
|
||||||
|
// Lưu các stockCode và exchangeType đã tồn tại
|
||||||
|
Set<String> existingKeys = existingMoneyStocks.stream()
|
||||||
|
.map(ms -> ms.getMoneyScId() + ms.getStockType())
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
// Chỉ giữ những StockIpo chưa tồn tại
|
||||||
|
return stockIpoList.stream()
|
||||||
|
.filter(stockIpo -> !existingKeys.contains(stockIpo.getStockCode() + stockIpo.getExchangeType()))
|
||||||
|
.map(this::convert)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
// public List<MoneyStock> convertToMoneyStock(List<StockIpo> stockIpoList) {
|
||||||
|
// return stockIpoList.stream()
|
||||||
|
// .filter(stockIpo -> !moneyStockRepository.exists(
|
||||||
|
// QMoneyStockPO.moneyStockPO.stockType.eq(stockIpo.getExchangeType())
|
||||||
|
// .and(QMoneyStockPO.moneyStockPO.moneyScId.eq(stockIpo.getStockCode()))
|
||||||
|
// )) // Chỉ giữ những StockIpo chưa tồn tại
|
||||||
|
// .map(this::convert)
|
||||||
|
// .collect(Collectors.toList());
|
||||||
|
// }
|
||||||
|
|
||||||
|
private MoneyStock convert(StockIpo stockIpo) {
|
||||||
|
MoneyStock moneyStock = new MoneyStock();
|
||||||
|
|
||||||
|
moneyStock.setStockName(stockIpo.getStockName());
|
||||||
|
moneyStock.setMoneyScId(stockIpo.getStockCode());
|
||||||
|
moneyStock.setSelfDispId(stockIpo.getStockCode());
|
||||||
|
moneyStock.setStockType(stockIpo.getExchangeType());
|
||||||
|
moneyStock.setSaveTime(DateTime.now());
|
||||||
|
moneyStock.setNseIndiaId(getNSEId(stockIpo));
|
||||||
|
|
||||||
|
return moneyStock;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getNSEId(StockIpo stockIpo){
|
||||||
|
String url = "https://priceapi.moneycontrol.com/pricefeed/" + stockIpo.getExchangeType().toLowerCase() + "/equitycash/" + stockIpo.getStockCode();
|
||||||
|
// 创建 HttpClient 实例
|
||||||
|
HttpClient client = HttpClients.createDefault();
|
||||||
|
// 创建 HttpGet 请求
|
||||||
|
HttpGet request = new HttpGet(url);
|
||||||
|
try {
|
||||||
|
// 执行请求
|
||||||
|
HttpResponse response = client.execute(request);
|
||||||
|
|
||||||
|
// 检查请求是否成功
|
||||||
|
if (response.getStatusLine().getStatusCode() == 200) {
|
||||||
|
// 获取响应体
|
||||||
|
String responseBody = EntityUtils.toString(response.getEntity());
|
||||||
|
|
||||||
|
if (responseBody != null) {
|
||||||
|
// 获取 JSON 数据
|
||||||
|
|
||||||
|
// 将 JSON 字符串解析为 Java JSONObject
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(responseBody);
|
||||||
|
log.info("获取到新股的json信息:" + jsonObject.toJSONString());
|
||||||
|
|
||||||
|
JSONObject jsonData = jsonObject.getJSONObject("data");
|
||||||
|
|
||||||
|
if(stockIpo.getExchangeType().equals("NSE")){
|
||||||
|
return jsonData.getString("NSEID");
|
||||||
|
}
|
||||||
|
else if(stockIpo.getExchangeType().equals("BSE")){
|
||||||
|
return jsonData.getString("BSEID");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e){
|
||||||
|
log.info(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,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;
|
||||||
|
|
||||||
@@ -159,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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,17 +3,25 @@ package cn.stock.market.web;
|
|||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.stock.market.MoneyStockSuggestDTO;
|
import cn.stock.market.MoneyStockSuggestDTO;
|
||||||
import cn.stock.market.domain.basic.entity.MoneyStock;
|
import cn.stock.market.domain.basic.entity.MoneyStock;
|
||||||
|
import cn.stock.market.domain.basic.entity.OptionalStock;
|
||||||
import cn.stock.market.domain.basic.repository.MoneyStockRepository;
|
import cn.stock.market.domain.basic.repository.MoneyStockRepository;
|
||||||
import cn.stock.market.dto.StockHistoryRequest;
|
import cn.stock.market.domain.basic.repository.OptionalStockRepository;
|
||||||
import cn.stock.market.dto.StockHistoryResponse;
|
import cn.stock.market.dto.*;
|
||||||
|
import cn.stock.market.dto.query.StockChartDto;
|
||||||
import cn.stock.market.infrastructure.db.po.QMoneyStockPO;
|
import cn.stock.market.infrastructure.db.po.QMoneyStockPO;
|
||||||
import cn.stock.market.utils.RequestCacheUtils;
|
import cn.stock.market.utils.HttpRequest;
|
||||||
|
import cn.stock.market.utils.NseIndiaRequest;
|
||||||
import cn.stock.market.utils.ServerResponse;
|
import cn.stock.market.utils.ServerResponse;
|
||||||
import cn.stock.market.web.annotations.EncryptFilter;
|
import cn.stock.market.web.annotations.EncryptFilter;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.common.cache.Cache;
|
import com.google.common.cache.Cache;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
@@ -23,26 +31,38 @@ import io.swagger.annotations.ApiResponses;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.client.ClientProtocolException;
|
||||||
|
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 org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.*;
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
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.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.client.RestClientException;
|
import org.springframework.web.client.RestClientException;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
import org.springframework.web.util.UriUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.YearMonth;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,15 +81,20 @@ public class MoneyApiController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private MoneyStockRepository moneyStockRepository;
|
private MoneyStockRepository moneyStockRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OptionalStockRepository optionalStockRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
private static final String EXTERNAL_API_URL = "https://priceapi.moneycontrol.com/techCharts/indianMarket/stock/history";
|
private static final String EXTERNAL_API_URL = "https://priceapi.moneycontrol.com/techCharts/indianMarket/stock/history";
|
||||||
|
private static final String OPTIONAL_STOCK_MONEYCONTROL_URL = "https://priceapi.moneycontrol.com/pricefeed/notapplicable/inidicesindia/";
|
||||||
|
|
||||||
|
@ApiOperation(value = "股票详情信息", httpMethod = "GET")
|
||||||
|
|
||||||
@ApiOperation(value = "股票详情信息",httpMethod = "GET")
|
|
||||||
@ApiImplicitParams({
|
@ApiImplicitParams({
|
||||||
@ApiImplicitParam(name="stockType",value = "BSE或者NSE"),
|
@ApiImplicitParam(name = "stockType", value = "BSE或者NSE"),
|
||||||
@ApiImplicitParam(name="symbol",value = "scId值"),
|
@ApiImplicitParam(name = "symbol", value = "scId值"),
|
||||||
@ApiImplicitParam(name="id",value = "id值"),
|
@ApiImplicitParam(name = "id", value = "id值"),
|
||||||
})
|
})
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(code = 200, message = "" +
|
@ApiResponse(code = 200, message = "" +
|
||||||
@@ -168,12 +193,10 @@ public class MoneyApiController {
|
|||||||
"priceprevclose: 前一交易日的收盘价\n" +
|
"priceprevclose: 前一交易日的收盘价\n" +
|
||||||
"30DayAvg: 过去30天的平均", response = JSONObject.class),
|
"30DayAvg: 过去30天的平均", response = JSONObject.class),
|
||||||
})
|
})
|
||||||
@GetMapping({"/market/api/market/money/getStockDetail","/api/market/money/getStockDetail"})
|
@GetMapping({"/market/api/market/money/getStockDetail", "/api/market/money/getStockDetail"})
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@EncryptFilter(decryptRequest = false)
|
@EncryptFilter(decryptRequest = false)
|
||||||
|
public ServerResponse getStockDetail(@RequestParam String stockType, @RequestParam String symbol) {
|
||||||
public ServerResponse getStockDetail(@RequestParam String stockType, @RequestParam String symbol ) {
|
|
||||||
String url = String.format("https://priceapi.moneycontrol.com/pricefeed/%s/equitycash/%s",stockType,symbol);
|
|
||||||
MoneyStock moneyStock = moneyStockRepository.findOne(QMoneyStockPO.moneyStockPO.stockType.eq(stockType)
|
MoneyStock moneyStock = moneyStockRepository.findOne(QMoneyStockPO.moneyStockPO.stockType.eq(stockType)
|
||||||
.and(QMoneyStockPO.moneyStockPO.moneyScId.eq(symbol))
|
.and(QMoneyStockPO.moneyStockPO.moneyScId.eq(symbol))
|
||||||
.and(QMoneyStockPO.moneyStockPO.isLock.eq(0))
|
.and(QMoneyStockPO.moneyStockPO.isLock.eq(0))
|
||||||
@@ -183,37 +206,100 @@ public class MoneyApiController {
|
|||||||
return ServerResponse.createByErrorMsg("没有找到该股票");
|
return ServerResponse.createByErrorMsg("没有找到该股票");
|
||||||
}*/
|
}*/
|
||||||
// 设置重试次数
|
// 设置重试次数
|
||||||
|
if ("ANI".equals(symbol)) {
|
||||||
|
JSONObject json1 = new JSONObject();
|
||||||
|
json1.put("company", "Archit Nuwood Industries Ltd");
|
||||||
|
json1.put("pricepercentchange", "Archit Nuwood Industries Ltd");
|
||||||
|
json1.put("stockType", stockType);
|
||||||
|
json1.put("pricecurrent", "386");
|
||||||
|
json1.put("dataSourceType", "3");
|
||||||
|
json1.put("symbol", "ANI");
|
||||||
|
json1.put("BSEID", "ANI");
|
||||||
|
json1.put("NSEID", "ANI");
|
||||||
|
return ServerResponse.createBySuccess(json1);
|
||||||
|
}
|
||||||
|
|
||||||
|
String url = String.format("https://priceapi.moneycontrol.com/pricefeed/%s/equitycash/%s", stockType.toLowerCase(), symbol);
|
||||||
int maxRetries = 3;
|
int maxRetries = 3;
|
||||||
|
if (moneyStock.getUseFromBseindia()) {
|
||||||
|
String bseUrl = "https://api.bseindia.com/BseIndiaAPI/api/getScripHeaderData/w?Debtflag=&scripcode=" + moneyStock.getNseIndiaId() + "&seriesid=";
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.add("accept", "application/json, text/plain, */*");
|
||||||
|
headers.add("accept-language", "en-US,en;q=0.9,vi;q=0.8");
|
||||||
|
headers.add("origin", "https://www.bseindia.com");
|
||||||
|
headers.add("referer", "https://www.bseindia.com/");
|
||||||
|
headers.add("sec-ch-ua", "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"");
|
||||||
|
headers.add("sec-ch-ua-mobile", "?0");
|
||||||
|
headers.add("sec-ch-ua-platform", "\"Windows\"");
|
||||||
|
headers.add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36");
|
||||||
|
|
||||||
|
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||||
|
|
||||||
|
try {
|
||||||
|
ResponseEntity<String> responseEntity = restTemplate.exchange(bseUrl, HttpMethod.GET, entity, String.class);
|
||||||
|
if (responseEntity.getStatusCode().value() == 200 && responseEntity.getBody() != null) {
|
||||||
|
JSONObject bseData = JSONObject.parseObject(responseEntity.getBody());
|
||||||
|
JSONObject json1 = new JSONObject();
|
||||||
|
json1.put("company", bseData.getJSONObject("Cmpname").getString("FullN"));
|
||||||
|
json1.put("pricepercentchange", bseData.getJSONObject("CurrRate").getString("PcChg"));
|
||||||
|
json1.put("stockType", stockType);
|
||||||
|
json1.put("pricechange", bseData.getJSONObject("CurrRate").getString("Chg"));
|
||||||
|
json1.put("pricecurrent", bseData.getJSONObject("CurrRate").getString("LTP"));
|
||||||
|
json1.put("priceprevclose", bseData.getJSONObject("Header").getString("PrevClose"));
|
||||||
|
json1.put("PREVDATE", "");
|
||||||
|
|
||||||
|
json1.put("dataSourceType", "3");
|
||||||
|
json1.put("symbol", symbol);
|
||||||
|
json1.put("BSEID", moneyStock.getNseIndiaId());
|
||||||
|
json1.put("NSEID", moneyStock.getNseIndiaId());
|
||||||
|
json1.put("LTH", bseData.getJSONObject("Header").getString("High"));
|
||||||
|
json1.put("LTL", bseData.getJSONObject("Header").getString("Low"));
|
||||||
|
json1.put("OPN", bseData.getJSONObject("Header").getString("Open"));
|
||||||
|
|
||||||
|
|
||||||
|
if (moneyStock != null) {
|
||||||
|
json1.put("id", moneyStock.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
json1.put("VOL", this.getVolume(moneyStock.getNseIndiaId()));
|
||||||
|
return ServerResponse.createBySuccess(json1);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("Error fetching data from BSE India: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int retry = 1; retry <= maxRetries; retry++) {
|
for (int retry = 1; retry <= maxRetries; retry++) {
|
||||||
try {
|
try {
|
||||||
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.GET, null, String.class);
|
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.GET, null, String.class);
|
||||||
JSONObject json1 = new JSONObject();
|
JSONObject json1 = new JSONObject();
|
||||||
if (responseEntity.getStatusCode().value() == 200 && responseEntity.getBody() != null ) {
|
if (responseEntity.getStatusCode().value() == 200 && responseEntity.getBody() != null) {
|
||||||
JSONObject data = JSONObject.parseObject(responseEntity.getBody()).getJSONObject("data");
|
JSONObject data = JSONObject.parseObject(responseEntity.getBody()).getJSONObject("data");
|
||||||
if(data!=null){
|
if (data != null) {
|
||||||
json1.put("company",data.getString("company"));
|
json1.put("company", data.getString("SC_FULLNM"));
|
||||||
json1.put("pricepercentchange",data.getString("pricepercentchange"));
|
json1.put("pricepercentchange", data.getString("pricepercentchange"));
|
||||||
json1.put("stockType",stockType);
|
json1.put("stockType", stockType);
|
||||||
json1.put("pricechange",data.getString("pricechange"));
|
json1.put("pricechange", data.getString("pricechange"));
|
||||||
json1.put("pricecurrent",data.getString("pricecurrent"));
|
json1.put("pricecurrent", data.getString("pricecurrent"));
|
||||||
json1.put("priceprevclose",data.getString("priceprevclose"));
|
json1.put("priceprevclose", data.getString("priceprevclose"));
|
||||||
json1.put("PREVDATE",data.getString("PREVDATE"));
|
json1.put("PREVDATE", data.getString("PREVDATE"));
|
||||||
json1.put("VOL",data.getString("VOL"));
|
json1.put("VOL", data.getString("VOL"));
|
||||||
json1.put("dataSourceType","3");
|
json1.put("dataSourceType", "3");
|
||||||
json1.put("symbol",data.getString("symbol"));
|
json1.put("symbol", data.getString("symbol"));
|
||||||
json1.put("BSEID",data.getString("BSEID"));
|
json1.put("BSEID", data.getString("BSEID"));
|
||||||
json1.put("NSEID",data.getString("NSEID"));
|
json1.put("NSEID", data.getString("NSEID"));
|
||||||
json1.put("LTH",data.getString("HP"));
|
json1.put("LTH", data.getString("HP"));
|
||||||
json1.put("LTL",data.getString("LP"));
|
json1.put("LTL", data.getString("LP"));
|
||||||
json1.put("OPN",data.getString("OPN"));
|
json1.put("OPN", data.getString("OPN"));
|
||||||
if(null!=moneyStock){
|
if (null != moneyStock) {
|
||||||
json1.put("id",moneyStock.getId());
|
json1.put("id", moneyStock.getId());
|
||||||
}
|
}
|
||||||
if(StringUtils.equals(data.getString("pricecurrent"),"0.00")
|
if (StringUtils.equals(data.getString("pricecurrent"), "0.00")
|
||||||
&& (!StringUtils.equals(data.getString("priceprevclose"),"0.00"))){
|
&& (!StringUtils.equals(data.getString("priceprevclose"), "0.00"))) {
|
||||||
json1.put("pricecurrent",data.getString("priceprevclose"));
|
json1.put("pricecurrent", data.getString("priceprevclose"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (json1.size() > 0)
|
||||||
return ServerResponse.createBySuccess(json1);
|
return ServerResponse.createBySuccess(json1);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -228,10 +314,72 @@ public class MoneyApiController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (moneyStock != null && moneyStock.getNseIndiaId() != null && !moneyStock.getNseIndiaId().isEmpty()) {
|
||||||
|
try {
|
||||||
|
// Get data from nseindia
|
||||||
|
JSONObject json = NseIndiaRequest.stockByJYSFromHttp(stockType, symbol, moneyStock.getNseIndiaId());
|
||||||
|
json.put("id", moneyStock.getId());
|
||||||
|
json.put("company",moneyStock.getStockName());
|
||||||
|
return ServerResponse.createBySuccess(json);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getVolume(String scripcode) {
|
||||||
|
String url = "https://api.bseindia.com/BseIndiaAPI/api/StockTrading/w?flag="etype=EQ&scripcode=" + scripcode;
|
||||||
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.add("accept", "application/json, text/plain, */*");
|
||||||
|
headers.add("accept-language", "en-US,en;q=0.9,vi;q=0.8");
|
||||||
|
headers.add("origin", "https://www.bseindia.com");
|
||||||
|
headers.add("referer", "https://www.bseindia.com/");
|
||||||
|
headers.add("sec-ch-ua", "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"");
|
||||||
|
headers.add("sec-ch-ua-mobile", "?0");
|
||||||
|
headers.add("sec-ch-ua-platform", "\"Windows\"");
|
||||||
|
headers.add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36");
|
||||||
|
|
||||||
|
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||||
|
|
||||||
|
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||||
|
BigDecimal volume = BigDecimal.ZERO;
|
||||||
|
|
||||||
|
if (response.getStatusCode().value() == 200 && response.getBody() != null) {
|
||||||
|
JSONObject volumeData = JSONObject.parseObject(response.getBody());
|
||||||
|
if (volumeData.getString("TTQ") != null) {
|
||||||
|
volume = new BigDecimal(volumeData.getString("TTQ"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return volume.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getChartData(String scripcode, String resolution) {
|
||||||
|
String url = "https://charting.bseindia.com/charting/RestDataProvider.svc/getDat?exch=B&type=b&mode=bseL&fromdate=01-01-1991-01%3A01%3A00-AM&scode=" + scripcode;
|
||||||
|
if (resolution.equals("H")) {
|
||||||
|
url = "https://charting.bseindia.com/charting/RestDataProvider.svc/getDatI?exch=B&type=b&mode=bseL&fromdate=01-01-1991-01%3A01%3A00-AM&scode=" + scripcode;
|
||||||
|
}
|
||||||
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
|
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.add("accept", "application/json, text/plain, */*");
|
||||||
|
headers.add("accept-language", "en-US,en;q=0.9,vi;q=0.8");
|
||||||
|
headers.add("origin", "https://www.bseindia.com");
|
||||||
|
headers.add("referer", "https://www.bseindia.com/");
|
||||||
|
headers.add("sec-ch-ua", "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"");
|
||||||
|
headers.add("sec-ch-ua-mobile", "?0");
|
||||||
|
headers.add("sec-ch-ua-platform", "\"Windows\"");
|
||||||
|
headers.add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36");
|
||||||
|
|
||||||
|
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||||
|
|
||||||
|
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
|
||||||
|
|
||||||
|
return response.getBody();
|
||||||
|
}
|
||||||
|
|
||||||
private static List<MoneyStockSuggestDTO> nseActives() {
|
private static List<MoneyStockSuggestDTO> nseActives() {
|
||||||
List<MoneyStockSuggestDTO> list = new ArrayList<>();
|
List<MoneyStockSuggestDTO> list = new ArrayList<>();
|
||||||
@@ -239,9 +387,9 @@ public class MoneyApiController {
|
|||||||
try {
|
try {
|
||||||
Document doc = Jsoup.connect(url).get();
|
Document doc = Jsoup.connect(url).get();
|
||||||
int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size();
|
int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size();
|
||||||
for (int i =1;i<=size;i++){
|
for (int i = 1; i <= size; i++) {
|
||||||
MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO();
|
MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO();
|
||||||
Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child("+i+") > td.PR > span > a").first();
|
Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child(" + i + ") > td.PR > span > a").first();
|
||||||
if (company_a != null) {
|
if (company_a != null) {
|
||||||
String stockUrl = company_a.attr("href");
|
String stockUrl = company_a.attr("href");
|
||||||
String stockName = company_a.text();
|
String stockName = company_a.text();
|
||||||
@@ -249,7 +397,7 @@ public class MoneyApiController {
|
|||||||
dto.setStockUrl(stockUrl);
|
dto.setStockUrl(stockUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
String highPrice = getTextOrEmpty(doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child("+i+") > td:nth-child(2)").first());
|
String highPrice = getTextOrEmpty(doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child(" + i + ") > td:nth-child(2)").first());
|
||||||
dto.setHighPrice(highPrice);
|
dto.setHighPrice(highPrice);
|
||||||
|
|
||||||
String lowPrice = getTextOrEmpty(doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child(" + i + ") > td:nth-child(3)").first());
|
String lowPrice = getTextOrEmpty(doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child(" + i + ") > td:nth-child(3)").first());
|
||||||
@@ -282,9 +430,9 @@ public class MoneyApiController {
|
|||||||
Document doc = Jsoup.connect(url).get();
|
Document doc = Jsoup.connect(url).get();
|
||||||
int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size();
|
int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size();
|
||||||
System.err.println(size);
|
System.err.println(size);
|
||||||
for (int i =1;i<=size;i++){
|
for (int i = 1; i <= size; i++) {
|
||||||
MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO();
|
MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO();
|
||||||
Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child("+i+") > td.PR > span > a").first();
|
Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child(" + i + ") > td.PR > span > a").first();
|
||||||
if (company_a != null) {
|
if (company_a != null) {
|
||||||
String stockUrl = company_a.attr("href");
|
String stockUrl = company_a.attr("href");
|
||||||
String stockName = company_a.text();
|
String stockName = company_a.text();
|
||||||
@@ -313,7 +461,7 @@ public class MoneyApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("occur Exception",e);
|
log.error("occur Exception", e);
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@@ -324,8 +472,8 @@ public class MoneyApiController {
|
|||||||
try {
|
try {
|
||||||
Document doc = Jsoup.connect(url).get();
|
Document doc = Jsoup.connect(url).get();
|
||||||
int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size();
|
int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size();
|
||||||
for (int i =1;i<=size;i++){
|
for (int i = 1; i <= size; i++) {
|
||||||
Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child("+i+") > td.PR > span > a").first();
|
Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child(" + i + ") > td.PR > span > a").first();
|
||||||
MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO();
|
MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO();
|
||||||
if (company_a != null) {
|
if (company_a != null) {
|
||||||
String stockUrl = company_a.attr("href");
|
String stockUrl = company_a.attr("href");
|
||||||
@@ -369,9 +517,9 @@ public class MoneyApiController {
|
|||||||
try {
|
try {
|
||||||
Document doc = Jsoup.connect(url).get();
|
Document doc = Jsoup.connect(url).get();
|
||||||
int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size();
|
int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size();
|
||||||
for (int i =1;i<=size;i++){
|
for (int i = 1; i <= size; i++) {
|
||||||
MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO();
|
MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO();
|
||||||
Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child("+i+") > td.PR > span > h3 > a").first();
|
Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child(" + i + ") > td.PR > span > h3 > a").first();
|
||||||
if (company_a != null) {
|
if (company_a != null) {
|
||||||
String stockUrl = company_a.attr("href");
|
String stockUrl = company_a.attr("href");
|
||||||
String stockName = company_a.text();
|
String stockName = company_a.text();
|
||||||
@@ -413,9 +561,9 @@ public class MoneyApiController {
|
|||||||
try {
|
try {
|
||||||
Document doc = Jsoup.connect(url).get();
|
Document doc = Jsoup.connect(url).get();
|
||||||
int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size();
|
int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size();
|
||||||
for (int i =1;i<=size;i++){
|
for (int i = 1; i <= size; i++) {
|
||||||
MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO();
|
MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO();
|
||||||
Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child("+i+") > td.PR > span > h3 > a").first();
|
Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child(" + i + ") > td.PR > span > h3 > a").first();
|
||||||
if (company_a != null) {
|
if (company_a != null) {
|
||||||
String stockUrl = company_a.attr("href");
|
String stockUrl = company_a.attr("href");
|
||||||
String stockName = company_a.text();
|
String stockName = company_a.text();
|
||||||
@@ -456,7 +604,7 @@ public class MoneyApiController {
|
|||||||
try {
|
try {
|
||||||
Document doc = Jsoup.connect(url).get();
|
Document doc = Jsoup.connect(url).get();
|
||||||
int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size();
|
int size = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr").size();
|
||||||
for (int i =1;i<=size;i++){
|
for (int i = 1; i <= size; i++) {
|
||||||
Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child(" + i + ") > td.PR > span > a").first();
|
Element company_a = doc.select("#mc_content > section > section > div.clearfix.stat_container > div.columnst.FR.wbg.brdwht > div > div > div.bsr_table.hist_tbl_hm > table > tbody > tr:nth-child(" + i + ") > td.PR > span > a").first();
|
||||||
MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO();
|
MoneyStockSuggestDTO dto = new MoneyStockSuggestDTO();
|
||||||
if (company_a != null) {
|
if (company_a != null) {
|
||||||
@@ -501,17 +649,15 @@ public class MoneyApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation(value = "股票推荐TopGainer", httpMethod = "GET")
|
||||||
|
|
||||||
@ApiOperation(value = "股票推荐TopGainer",httpMethod = "GET")
|
|
||||||
@ApiImplicitParams({
|
@ApiImplicitParams({
|
||||||
@ApiImplicitParam(name="stockType",value = "BSE或者NSE"),
|
@ApiImplicitParam(name = "stockType", value = "BSE或者NSE"),
|
||||||
})
|
})
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(code = 200, message = "" +
|
@ApiResponse(code = 200, message = "" +
|
||||||
"股票推荐相关: top gainer", response = JSONObject.class),
|
"股票推荐相关: top gainer", response = JSONObject.class),
|
||||||
})
|
})
|
||||||
@GetMapping({"/market/api/market/money/getTopGainer","/api/market/money/getTopGainer"})
|
@GetMapping({"/market/api/market/money/getTopGainer", "/api/market/money/getTopGainer"})
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@EncryptFilter(decryptRequest = false)
|
@EncryptFilter(decryptRequest = false)
|
||||||
|
|
||||||
@@ -529,15 +675,15 @@ public class MoneyApiController {
|
|||||||
}
|
}
|
||||||
Map<Object, Boolean> map = new HashMap<>();
|
Map<Object, Boolean> map = new HashMap<>();
|
||||||
moneyStockSuggestDTOS = moneyStockSuggestDTOS.stream()
|
moneyStockSuggestDTOS = moneyStockSuggestDTOS.stream()
|
||||||
.filter(f->StringUtils.isNotBlank(f.getStockName()))
|
.filter(f -> StringUtils.isNotBlank(f.getStockName()))
|
||||||
.filter(i -> map.putIfAbsent(i.getStockName(), Boolean.TRUE) == null).collect(Collectors.toList());
|
.filter(i -> map.putIfAbsent(i.getStockName(), Boolean.TRUE) == null).collect(Collectors.toList());
|
||||||
if(CollectionUtils.isNotEmpty(moneyStockSuggestDTOS)){
|
if (CollectionUtils.isNotEmpty(moneyStockSuggestDTOS)) {
|
||||||
List<String> selfUlrList = moneyStockSuggestDTOS.stream().map(MoneyStockSuggestDTO::getStockName).collect(Collectors.toList());
|
List<String> selfUlrList = moneyStockSuggestDTOS.stream().map(MoneyStockSuggestDTO::getStockName).collect(Collectors.toList());
|
||||||
if(CollectionUtils.isNotEmpty(selfUlrList)){
|
if (CollectionUtils.isNotEmpty(selfUlrList)) {
|
||||||
List<MoneyStock> all = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.stockName.in(selfUlrList));
|
List<MoneyStock> all = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.stockName.in(selfUlrList));
|
||||||
if(CollectionUtils.isNotEmpty(all)){
|
if (CollectionUtils.isNotEmpty(all)) {
|
||||||
moneyStockSuggestDTOS.stream().filter(f->all.stream().anyMatch(s->s.getStockName().equals(f.getStockName())))
|
moneyStockSuggestDTOS.stream().filter(f -> all.stream().anyMatch(s -> s.getStockName().equals(f.getStockName())))
|
||||||
.forEach(f->f.setScId(all.stream().filter(s->s.getStockName().equals(f.getStockName())).findFirst().orElse(null).getMoneyScId()));
|
.forEach(f -> f.setScId(all.stream().filter(s -> s.getStockName().equals(f.getStockName())).findFirst().orElse(null).getMoneyScId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gainerStockSuggestCache.put(stockType, moneyStockSuggestDTOS);
|
gainerStockSuggestCache.put(stockType, moneyStockSuggestDTOS);
|
||||||
@@ -548,47 +694,47 @@ public class MoneyApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation(value = "股票推荐TopLoser",httpMethod = "GET")
|
@ApiOperation(value = "股票推荐TopLoser", httpMethod = "GET")
|
||||||
@ApiImplicitParams({
|
@ApiImplicitParams({
|
||||||
@ApiImplicitParam(name="stockType",value = "BSE或者NSE"),
|
@ApiImplicitParam(name = "stockType", value = "BSE或者NSE"),
|
||||||
})
|
})
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(code = 200, message = "" +
|
@ApiResponse(code = 200, message = "" +
|
||||||
"股票推荐相关: TopLoser", response = JSONObject.class),
|
"股票推荐相关: TopLoser", response = JSONObject.class),
|
||||||
})
|
})
|
||||||
@GetMapping({"/market/api/market/money/getTopLoser","/api/market/money/getTopLoser"})
|
@GetMapping({"/market/api/market/money/getTopLoser", "/api/market/money/getTopLoser"})
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@EncryptFilter(decryptRequest = false)
|
@EncryptFilter(decryptRequest = false)
|
||||||
|
|
||||||
public List<MoneyStockSuggestDTO> getTopLoser(@RequestParam String stockType) {
|
public List<MoneyStockSuggestDTO> getTopLoser(@RequestParam String stockType) {
|
||||||
List<MoneyStockSuggestDTO> moneyStockSuggestDTOS = null;
|
List<MoneyStockSuggestDTO> moneyStockSuggestDTOS = null;
|
||||||
moneyStockSuggestDTOS = loserStockSuggestCache.getIfPresent(stockType);
|
moneyStockSuggestDTOS = loserStockSuggestCache.getIfPresent(stockType);
|
||||||
if(null==moneyStockSuggestDTOS){
|
if (null == moneyStockSuggestDTOS) {
|
||||||
if(StringUtils.equals(stockType,"nse")){
|
if (StringUtils.equals(stockType, "nse")) {
|
||||||
moneyStockSuggestDTOS = nseTopLoser();
|
moneyStockSuggestDTOS = nseTopLoser();
|
||||||
}else if(StringUtils.equals(stockType,"bse")){
|
} else if (StringUtils.equals(stockType, "bse")) {
|
||||||
moneyStockSuggestDTOS = bseTopLoser();
|
moneyStockSuggestDTOS = bseTopLoser();
|
||||||
}
|
}
|
||||||
Map<Object, Boolean> map = new HashMap<>();
|
Map<Object, Boolean> map = new HashMap<>();
|
||||||
moneyStockSuggestDTOS = moneyStockSuggestDTOS.stream()
|
moneyStockSuggestDTOS = moneyStockSuggestDTOS.stream()
|
||||||
.filter(f->StringUtils.isNotBlank(f.getStockName()))
|
.filter(f -> StringUtils.isNotBlank(f.getStockName()))
|
||||||
.filter(i -> map.putIfAbsent(i.getStockName(), Boolean.TRUE) == null).collect(Collectors.toList());
|
.filter(i -> map.putIfAbsent(i.getStockName(), Boolean.TRUE) == null).collect(Collectors.toList());
|
||||||
if(CollectionUtils.isNotEmpty(moneyStockSuggestDTOS)){
|
if (CollectionUtils.isNotEmpty(moneyStockSuggestDTOS)) {
|
||||||
moneyStockSuggestDTOS.stream().forEach(f->f.setDispId(extractLastSegment(f.getStockUrl())));
|
moneyStockSuggestDTOS.stream().forEach(f -> f.setDispId(extractLastSegment(f.getStockUrl())));
|
||||||
List<String> selfUlrList = moneyStockSuggestDTOS.stream().map(MoneyStockSuggestDTO::getStockName).collect(Collectors.toList());
|
List<String> selfUlrList = moneyStockSuggestDTOS.stream().map(MoneyStockSuggestDTO::getStockName).collect(Collectors.toList());
|
||||||
if(CollectionUtils.isNotEmpty(selfUlrList)){
|
if (CollectionUtils.isNotEmpty(selfUlrList)) {
|
||||||
List<MoneyStock> all = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.stockName.in(selfUlrList));
|
List<MoneyStock> all = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.stockName.in(selfUlrList));
|
||||||
if(CollectionUtils.isNotEmpty(all)){
|
if (CollectionUtils.isNotEmpty(all)) {
|
||||||
moneyStockSuggestDTOS.stream().filter(f->all.stream().anyMatch(s->s.getStockName().equals(f.getStockName())))
|
moneyStockSuggestDTOS.stream().filter(f -> all.stream().anyMatch(s -> s.getStockName().equals(f.getStockName())))
|
||||||
.forEach(f->f.setScId(all.stream().filter(s->s.getStockName().equals(f.getStockName())).findFirst().orElse(null).getMoneyScId()));
|
.forEach(f -> f.setScId(all.stream().filter(s -> s.getStockName().equals(f.getStockName())).findFirst().orElse(null).getMoneyScId()));
|
||||||
}
|
}
|
||||||
List<MoneyStockSuggestDTO> noScIdList = moneyStockSuggestDTOS.stream().filter(f->StringUtils.isBlank(f.getScId())).collect(Collectors.toList());
|
List<MoneyStockSuggestDTO> noScIdList = moneyStockSuggestDTOS.stream().filter(f -> StringUtils.isBlank(f.getScId())).collect(Collectors.toList());
|
||||||
if(CollectionUtils.isNotEmpty(noScIdList)){
|
if (CollectionUtils.isNotEmpty(noScIdList)) {
|
||||||
List<String> dispIdList = noScIdList.stream().map(MoneyStockSuggestDTO::getDispId).collect(Collectors.toList());
|
List<String> dispIdList = noScIdList.stream().map(MoneyStockSuggestDTO::getDispId).collect(Collectors.toList());
|
||||||
List<MoneyStock> all1 = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.selfDispId.in(dispIdList));
|
List<MoneyStock> all1 = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.selfDispId.in(dispIdList));
|
||||||
if(CollectionUtils.isNotEmpty(all1)){
|
if (CollectionUtils.isNotEmpty(all1)) {
|
||||||
moneyStockSuggestDTOS.stream().filter(f->all1.stream().anyMatch(s->s.getSelfDispId().equals(f.getDispId())))
|
moneyStockSuggestDTOS.stream().filter(f -> all1.stream().anyMatch(s -> s.getSelfDispId().equals(f.getDispId())))
|
||||||
.forEach(f->f.setScId(all.stream().filter(s->s.getSelfDispId().equals(f.getDispId())).findFirst().orElse(null).getMoneyScId()));
|
.forEach(f -> f.setScId(all.stream().filter(s -> s.getSelfDispId().equals(f.getDispId())).findFirst().orElse(null).getMoneyScId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -599,49 +745,47 @@ public class MoneyApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation(value = "股票推荐TopActive", httpMethod = "GET")
|
||||||
|
|
||||||
@ApiOperation(value = "股票推荐TopActive",httpMethod = "GET")
|
|
||||||
@ApiImplicitParams({
|
@ApiImplicitParams({
|
||||||
@ApiImplicitParam(name="stockType",value = "BSE或者NSE"),
|
@ApiImplicitParam(name = "stockType", value = "BSE或者NSE"),
|
||||||
})
|
})
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(code = 200, message = "" +
|
@ApiResponse(code = 200, message = "" +
|
||||||
"股票推荐相关: top active", response = JSONObject.class),
|
"股票推荐相关: top active", response = JSONObject.class),
|
||||||
})
|
})
|
||||||
@GetMapping({"/market/api/market/money/getTopActives","/api/market/money/getTopActives"})
|
@GetMapping({"/market/api/market/money/getTopActives", "/api/market/money/getTopActives"})
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@EncryptFilter(decryptRequest = false)
|
@EncryptFilter(decryptRequest = false)
|
||||||
|
|
||||||
public List<MoneyStockSuggestDTO> getTopActive(@RequestParam String stockType) {
|
public List<MoneyStockSuggestDTO> getTopActive(@RequestParam String stockType) {
|
||||||
List<MoneyStockSuggestDTO> moneyStockSuggestDTOS = null;
|
List<MoneyStockSuggestDTO> moneyStockSuggestDTOS = null;
|
||||||
moneyStockSuggestDTOS = activesStockSuggestCache.getIfPresent(stockType);
|
moneyStockSuggestDTOS = activesStockSuggestCache.getIfPresent(stockType);
|
||||||
if(moneyStockSuggestDTOS ==null){
|
if (moneyStockSuggestDTOS == null) {
|
||||||
if(StringUtils.equals(stockType,"nse")){
|
if (StringUtils.equals(stockType, "nse")) {
|
||||||
moneyStockSuggestDTOS = nseActives();
|
moneyStockSuggestDTOS = nseActives();
|
||||||
}else if(StringUtils.equals(stockType,"bse")){
|
} else if (StringUtils.equals(stockType, "bse")) {
|
||||||
moneyStockSuggestDTOS = bseActives();
|
moneyStockSuggestDTOS = bseActives();
|
||||||
}
|
}
|
||||||
Map<Object, Boolean> map = new HashMap<>();
|
Map<Object, Boolean> map = new HashMap<>();
|
||||||
moneyStockSuggestDTOS = moneyStockSuggestDTOS.stream()
|
moneyStockSuggestDTOS = moneyStockSuggestDTOS.stream()
|
||||||
.filter(f->StringUtils.isNotBlank(f.getStockName()))
|
.filter(f -> StringUtils.isNotBlank(f.getStockName()))
|
||||||
.filter(i -> map.putIfAbsent(i.getStockName(), Boolean.TRUE) == null).collect(Collectors.toList());
|
.filter(i -> map.putIfAbsent(i.getStockName(), Boolean.TRUE) == null).collect(Collectors.toList());
|
||||||
if(CollectionUtils.isNotEmpty(moneyStockSuggestDTOS)){
|
if (CollectionUtils.isNotEmpty(moneyStockSuggestDTOS)) {
|
||||||
moneyStockSuggestDTOS.stream().forEach(f->f.setDispId(extractLastSegment(f.getStockUrl())));
|
moneyStockSuggestDTOS.stream().forEach(f -> f.setDispId(extractLastSegment(f.getStockUrl())));
|
||||||
List<String> selfUlrList = moneyStockSuggestDTOS.stream().map(MoneyStockSuggestDTO::getStockName).collect(Collectors.toList());
|
List<String> selfUlrList = moneyStockSuggestDTOS.stream().map(MoneyStockSuggestDTO::getStockName).collect(Collectors.toList());
|
||||||
if(CollectionUtils.isNotEmpty(selfUlrList)){
|
if (CollectionUtils.isNotEmpty(selfUlrList)) {
|
||||||
List<MoneyStock> all = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.stockName.in(selfUlrList));
|
List<MoneyStock> all = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.stockName.in(selfUlrList));
|
||||||
if(CollectionUtils.isNotEmpty(all)){
|
if (CollectionUtils.isNotEmpty(all)) {
|
||||||
moneyStockSuggestDTOS.stream().filter(f->all.stream().anyMatch(s->s.getStockName().equals(f.getStockName())))
|
moneyStockSuggestDTOS.stream().filter(f -> all.stream().anyMatch(s -> s.getStockName().equals(f.getStockName())))
|
||||||
.forEach(f->f.setScId(all.stream().filter(s->s.getStockName().equals(f.getStockName())).findFirst().orElse(null).getMoneyScId()));
|
.forEach(f -> f.setScId(all.stream().filter(s -> s.getStockName().equals(f.getStockName())).findFirst().orElse(null).getMoneyScId()));
|
||||||
}
|
}
|
||||||
List<MoneyStockSuggestDTO> noScIdList = moneyStockSuggestDTOS.stream().filter(f->StringUtils.isBlank(f.getScId())).collect(Collectors.toList());
|
List<MoneyStockSuggestDTO> noScIdList = moneyStockSuggestDTOS.stream().filter(f -> StringUtils.isBlank(f.getScId())).collect(Collectors.toList());
|
||||||
if(CollectionUtils.isNotEmpty(noScIdList)){
|
if (CollectionUtils.isNotEmpty(noScIdList)) {
|
||||||
List<String> dispIdList = noScIdList.stream().map(MoneyStockSuggestDTO::getDispId).collect(Collectors.toList());
|
List<String> dispIdList = noScIdList.stream().map(MoneyStockSuggestDTO::getDispId).collect(Collectors.toList());
|
||||||
List<MoneyStock> all1 = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.selfDispId.in(dispIdList));
|
List<MoneyStock> all1 = moneyStockRepository.findAll(QMoneyStockPO.moneyStockPO.selfDispId.in(dispIdList));
|
||||||
if(CollectionUtils.isNotEmpty(all1)){
|
if (CollectionUtils.isNotEmpty(all1)) {
|
||||||
moneyStockSuggestDTOS.stream().filter(f->all1.stream().anyMatch(s->s.getSelfDispId().equals(f.getDispId())))
|
moneyStockSuggestDTOS.stream().filter(f -> all1.stream().anyMatch(s -> s.getSelfDispId().equals(f.getDispId())))
|
||||||
.forEach(f->f.setScId(all.stream().filter(s->s.getSelfDispId().equals(f.getDispId())).findFirst().orElse(null).getMoneyScId()));
|
.forEach(f -> f.setScId(all.stream().filter(s -> s.getSelfDispId().equals(f.getDispId())).findFirst().orElse(null).getMoneyScId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -652,10 +796,36 @@ public class MoneyApiController {
|
|||||||
return moneyStockSuggestDTOS;
|
return moneyStockSuggestDTOS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void addToListDouble(List<Double> list, String value) {
|
||||||
|
String[] values = value.split(",");
|
||||||
|
for (String v : values) {
|
||||||
|
list.add(Double.parseDouble(v));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addToList(List<Long> list, String value) {
|
||||||
|
String[] values = value.split(",");
|
||||||
|
for (String v : values) {
|
||||||
|
list.add(Math.round(Double.parseDouble(v)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addDatesToList(List<Long> list, String value) {
|
||||||
|
String[] dates = value.split(",");
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a", Locale.US);
|
||||||
|
for (String dateStr : dates) {
|
||||||
|
try {
|
||||||
|
Date date = sdf.parse(dateStr);
|
||||||
|
list.add(date.getTime());
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@GetMapping({"/market/api/market/money/history/kLine","/api/market/money/history/kLine"})
|
@GetMapping({"/market/api/market/money/history/kLine", "/api/market/money/history/kLine"})
|
||||||
@ApiOperation(value = "获取kline的money数据源", notes = "获取kline的money数据源",response = StockHistoryResponse.class)
|
@ApiOperation(value = "获取kline的money数据源", notes = "获取kline的money数据源", response = StockHistoryResponse.class)
|
||||||
@ApiImplicitParams({
|
@ApiImplicitParams({
|
||||||
@ApiImplicitParam(name = "symbol", value = "Stock symbol 对应的是NSEID 或者是BSEID", required = true, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "symbol", value = "Stock symbol 对应的是NSEID 或者是BSEID", required = true, dataType = "String", paramType = "query"),
|
||||||
@ApiImplicitParam(name = "resolution", value = "单位:60 1D 1W 1D 对应H,D,W,Y", required = true, dataType = "String", paramType = "query"),
|
@ApiImplicitParam(name = "resolution", value = "单位:60 1D 1W 1D 对应H,D,W,Y", required = true, dataType = "String", paramType = "query"),
|
||||||
@@ -666,9 +836,72 @@ public class MoneyApiController {
|
|||||||
})
|
})
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@EncryptFilter(decryptRequest = false)
|
@EncryptFilter(decryptRequest = false)
|
||||||
public ResponseEntity<StockHistoryResponse> getStockHistory( @RequestParam String symbol,
|
public ResponseEntity<StockHistoryResponse> getStockHistory(@RequestParam String symbol,
|
||||||
@RequestParam String resolution
|
@RequestParam String resolution
|
||||||
) {
|
) {
|
||||||
|
MoneyStock moneyStock1 = moneyStockRepository.findOne(
|
||||||
|
QMoneyStockPO.moneyStockPO.moneyScId.eq(symbol)
|
||||||
|
.and(QMoneyStockPO.moneyStockPO.isLock.eq(0))
|
||||||
|
.and(QMoneyStockPO.moneyStockPO.isShow.eq(0)))
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
if (moneyStock1 != null) {
|
||||||
|
|
||||||
|
String json = this.getChartData(moneyStock1.getNseIndiaId(), resolution);
|
||||||
|
|
||||||
|
Gson gson = new Gson();
|
||||||
|
|
||||||
|
JsonObject outerJson = gson.fromJson(json, JsonObject.class);
|
||||||
|
|
||||||
|
String innerJsonString;
|
||||||
|
|
||||||
|
if (resolution.equals("H")) {
|
||||||
|
innerJsonString = outerJson.get("getDatIResult").getAsString();
|
||||||
|
} else {
|
||||||
|
innerJsonString = outerJson.get("getDatResult").getAsString();
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonObject innerJson = gson.fromJson(innerJsonString, JsonObject.class);
|
||||||
|
|
||||||
|
JsonArray dataInputValues = innerJson.getAsJsonArray("DataInputValues");
|
||||||
|
|
||||||
|
List<Double> openList = new ArrayList<>();
|
||||||
|
List<Double> highList = new ArrayList<>();
|
||||||
|
List<Double> lowList = new ArrayList<>();
|
||||||
|
List<Double> closeList = new ArrayList<>();
|
||||||
|
List<Long> volumeList = new ArrayList<>();
|
||||||
|
List<Long> dateList = new ArrayList<>();
|
||||||
|
|
||||||
|
if (dataInputValues.size() > 0) {
|
||||||
|
JsonObject dataObject = dataInputValues.get(0).getAsJsonObject();
|
||||||
|
|
||||||
|
JsonArray openArray = dataObject.getAsJsonArray("OpenData");
|
||||||
|
JsonArray highArray = dataObject.getAsJsonArray("HighData");
|
||||||
|
JsonArray lowArray = dataObject.getAsJsonArray("LowData");
|
||||||
|
JsonArray closeArray = dataObject.getAsJsonArray("CloseData");
|
||||||
|
JsonArray volumeArray = dataObject.getAsJsonArray("VolumeData");
|
||||||
|
JsonArray dateArray = dataObject.getAsJsonArray("DateData");
|
||||||
|
|
||||||
|
openArray.forEach(o -> addToListDouble(openList, o.getAsJsonObject().get("Open").getAsString()));
|
||||||
|
highArray.forEach(h -> addToListDouble(highList, h.getAsJsonObject().get("High").getAsString()));
|
||||||
|
lowArray.forEach(l -> addToListDouble(lowList, l.getAsJsonObject().get("Low").getAsString()));
|
||||||
|
closeArray.forEach(c -> addToListDouble(closeList, c.getAsJsonObject().get("Close").getAsString()));
|
||||||
|
volumeArray.forEach(v -> addToList(volumeList, v.getAsJsonObject().get("Volume").getAsString()));
|
||||||
|
dateArray.forEach(d -> addDatesToList(dateList, d.getAsJsonObject().get("Date").getAsString()));
|
||||||
|
|
||||||
|
StockHistoryResponse response = new StockHistoryResponse();
|
||||||
|
response.setS("ok");
|
||||||
|
response.setT(dateList);
|
||||||
|
response.setO(openList);
|
||||||
|
response.setH(highList);
|
||||||
|
response.setL(lowList);
|
||||||
|
response.setC(closeList);
|
||||||
|
response.setV(volumeList);
|
||||||
|
|
||||||
|
return ResponseEntity.ok(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 向外部API发起请求,并获取响应
|
// 向外部API发起请求,并获取响应
|
||||||
StockHistoryRequest request = new StockHistoryRequest();
|
StockHistoryRequest request = new StockHistoryRequest();
|
||||||
request.setSymbol(symbol);
|
request.setSymbol(symbol);
|
||||||
@@ -677,24 +910,24 @@ public class MoneyApiController {
|
|||||||
int countback = 5;
|
int countback = 5;
|
||||||
if(StringUtils.equals("H",resolution)){
|
if(StringUtils.equals("H",resolution)){
|
||||||
to = (long) (System.currentTimeMillis() / 1000);
|
to = (long) (System.currentTimeMillis() / 1000);
|
||||||
from = to - ( 60 * 60 );
|
from = to - (10 * 60 * 60 );
|
||||||
countback = 60;
|
countback = 328;
|
||||||
request.setResolution("1");
|
request.setResolution("60");
|
||||||
}else if(StringUtils.equals("D",resolution)){
|
}else if(StringUtils.equals("D",resolution)){
|
||||||
to = (long) (System.currentTimeMillis() / 1000);
|
to = (long) (System.currentTimeMillis() / 1000);
|
||||||
from = to - (24 * 60 * 60 );
|
from = to - (2 * 30 * 24 * 60 * 60 );
|
||||||
countback = 390;
|
countback = 730;
|
||||||
request.setResolution("1");
|
request.setResolution("1D");
|
||||||
}else if(StringUtils.equals("W",resolution)){
|
} else if (StringUtils.equals("W", resolution)) {
|
||||||
to = (long) (System.currentTimeMillis() / 1000);
|
to = (long) (System.currentTimeMillis() / 1000);
|
||||||
from = to - (7 * 24 * 60 * 60 );
|
from = to - (7 * 24 * 60 * 60);
|
||||||
countback = 471;
|
countback = 730;
|
||||||
request.setResolution("5");
|
request.setResolution("1W");
|
||||||
}else if(StringUtils.equals("M",resolution)){
|
} else if (StringUtils.equals("M", resolution)) {
|
||||||
to = (long) (System.currentTimeMillis() / 1000);
|
to = (long) (System.currentTimeMillis() / 1000);
|
||||||
from = to - (35 * 24 * 60 * 60 );
|
from = to - (15 * 30 * 24 * 60 * 60);
|
||||||
countback = 328;
|
countback = 730;
|
||||||
request.setResolution("30");
|
request.setResolution("1D");
|
||||||
}
|
}
|
||||||
|
|
||||||
request.setFrom(from);
|
request.setFrom(from);
|
||||||
@@ -702,14 +935,88 @@ public class MoneyApiController {
|
|||||||
request.setCountback(countback);
|
request.setCountback(countback);
|
||||||
request.setCurrencyCode("INR");
|
request.setCurrencyCode("INR");
|
||||||
String apiUrl = buildApiUrl(request);
|
String apiUrl = buildApiUrl(request);
|
||||||
log.info("request url:"+apiUrl);
|
log.info("request url:" + apiUrl);
|
||||||
StockHistoryResponse response = null;
|
StockHistoryResponse response = null;
|
||||||
int maxRetries = 3;
|
int maxRetries = 3;
|
||||||
int retryCount = 0;
|
int retryCount = 0;
|
||||||
|
|
||||||
while (response == null && retryCount < maxRetries) {
|
while (response == null && retryCount < maxRetries) {
|
||||||
try {
|
try {
|
||||||
|
if (StringUtils.equals("M", resolution)) {
|
||||||
|
CloseableHttpClient client = HttpClients.createDefault();
|
||||||
|
HttpGet req = new HttpGet(apiUrl);
|
||||||
|
HttpResponse resp = client.execute(req);
|
||||||
|
String jsonResponse = EntityUtils.toString(resp.getEntity(), "UTF-8");
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
JsonNode rootNode = mapper.readTree(jsonResponse);
|
||||||
|
|
||||||
|
JsonNode timeNode = rootNode.get("t");
|
||||||
|
JsonNode lowNode = rootNode.get("l");
|
||||||
|
JsonNode highNode = rootNode.get("h");
|
||||||
|
JsonNode openNode = rootNode.get("o");
|
||||||
|
JsonNode closeNode = rootNode.get("c");
|
||||||
|
JsonNode volumeNote = rootNode.get("v");
|
||||||
|
|
||||||
|
List<StockChartDto> stocks = new ArrayList<>();
|
||||||
|
for (int i = 0; i < timeNode.size(); i++) {
|
||||||
|
long timestamp = timeNode.get(i).asLong();
|
||||||
|
double closePrice = closeNode.get(i).asDouble();
|
||||||
|
double openPrice = openNode.get(i).asDouble();
|
||||||
|
double volume = volumeNote.get(i).asDouble();
|
||||||
|
double low = lowNode.get(i).asDouble();
|
||||||
|
double high = highNode.get(i).asDouble();
|
||||||
|
|
||||||
|
stocks.add(new StockChartDto(timestamp, openPrice, high, low, closePrice, volume));
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, List<StockChartDto>> groupedByMonth = stocks.stream()
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
sp -> Instant.ofEpochSecond(sp.getTimestamp())
|
||||||
|
.atZone(ZoneId.systemDefault())
|
||||||
|
.toLocalDate()
|
||||||
|
.format(DateTimeFormatter.ofPattern("yyyy-MM")),
|
||||||
|
LinkedHashMap::new,
|
||||||
|
Collectors.toList()
|
||||||
|
));
|
||||||
|
|
||||||
|
List<Long> timestamps = new ArrayList<>();
|
||||||
|
List<Double> opens = new ArrayList<>();
|
||||||
|
List<Double> closes = new ArrayList<>();
|
||||||
|
List<Double> highs = new ArrayList<>();
|
||||||
|
List<Double> lows = new ArrayList<>();
|
||||||
|
List<Long> volumes = new ArrayList<>();
|
||||||
|
|
||||||
|
response = new StockHistoryResponse();
|
||||||
|
groupedByMonth.forEach((month, prices) -> {
|
||||||
|
double open = prices.get(0).getOpen();
|
||||||
|
double close = prices.get(prices.size() - 1).getClose();
|
||||||
|
double high = prices.stream().mapToDouble(StockChartDto::getHigh).max().orElse(0);
|
||||||
|
double low = prices.stream().mapToDouble(StockChartDto::getLow).min().orElse(0);
|
||||||
|
double volume = prices.stream().mapToDouble(StockChartDto::getVolume).sum();
|
||||||
|
|
||||||
|
long timestamp = YearMonth.parse(month, DateTimeFormatter.ofPattern("yyyy-MM")).atDay(1).atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli() / 1000;
|
||||||
|
timestamps.add(timestamp);
|
||||||
|
opens.add(open);
|
||||||
|
closes.add(close);
|
||||||
|
highs.add(high);
|
||||||
|
lows.add(low);
|
||||||
|
volumes.add((long) volume);
|
||||||
|
|
||||||
|
System.out.println("Month: " + month);
|
||||||
|
System.out.println("Open: " + open + ", Close: " + close + ", High: " + high + ", Low: " + low);
|
||||||
|
});
|
||||||
|
|
||||||
|
response.setS("ok");
|
||||||
|
response.setT(timestamps);
|
||||||
|
response.setL(lows);
|
||||||
|
response.setH(highs);
|
||||||
|
response.setO(opens);
|
||||||
|
response.setC(closes);
|
||||||
|
response.setV(volumes);
|
||||||
|
|
||||||
|
} else {
|
||||||
response = restTemplate.getForObject(apiUrl, StockHistoryResponse.class);
|
response = restTemplate.getForObject(apiUrl, StockHistoryResponse.class);
|
||||||
|
}
|
||||||
} catch (RestClientException e) {
|
} catch (RestClientException e) {
|
||||||
// Log the exception or perform any other error handling
|
// Log the exception or perform any other error handling
|
||||||
log.error("Error while making API request. Retrying... (Retry count: {})", retryCount + 1);
|
log.error("Error while making API request. Retrying... (Retry count: {})", retryCount + 1);
|
||||||
@@ -722,14 +1029,34 @@ public class MoneyApiController {
|
|||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ex) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
|
} catch (ClientProtocolException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response != null) {
|
if (response != null && !response.getS().equals("error")) {
|
||||||
setResponse(response,resolution);
|
// setResponse(response, resolution);
|
||||||
// API request successful, return the response
|
// API request successful, return the response
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(response);
|
||||||
} else {
|
} else {
|
||||||
|
try {
|
||||||
|
MoneyStock moneyStock = moneyStockRepository.findOne((QMoneyStockPO.moneyStockPO.moneyScId.eq(symbol))
|
||||||
|
.and(QMoneyStockPO.moneyStockPO.isLock.eq(0))
|
||||||
|
.and(QMoneyStockPO.moneyStockPO.isShow.eq(0)))
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
if (moneyStock != null && moneyStock.getNseIndiaChartId() != null && !moneyStock.getNseIndiaChartId().isEmpty()) {
|
||||||
|
request.setSymbol(moneyStock.getNseIndiaChartId());
|
||||||
|
response = NseIndiaRequest.stockKLineFromHttp(request, resolution);
|
||||||
|
return ResponseEntity.ok(response);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to get data from nseindia.", e.getMessage());
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
|
||||||
|
}
|
||||||
|
|
||||||
// All retries failed, return an error response
|
// All retries failed, return an error response
|
||||||
log.error("Failed to get a successful response after {} retries.", maxRetries);
|
log.error("Failed to get a successful response after {} retries.", maxRetries);
|
||||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
@@ -737,14 +1064,41 @@ public class MoneyApiController {
|
|||||||
// 返回响应
|
// 返回响应
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setResponse(StockHistoryResponse response,String resolution){
|
@GetMapping({"/market/api/market/stock/optional", "/api/market/stock/optional"})
|
||||||
if(!"ok".equals(response.getS())){
|
@ResponseBody
|
||||||
|
@EncryptFilter(decryptRequest = false)
|
||||||
|
public ResponseEntity<List<Object>> getOptionalStock() {
|
||||||
|
List<OptionalStock> optionalStocks = optionalStockRepository.findAll();
|
||||||
|
List<Object> data = optionalStocks.stream().map(stock -> {
|
||||||
|
try {
|
||||||
|
String responseStr = HttpRequest.doGrabGet(OPTIONAL_STOCK_MONEYCONTROL_URL + URLEncoder.encode(stock.getSymbol(), "UTF-8"));
|
||||||
|
OptionalStockResponse response = objectMapper.readValue(responseStr, OptionalStockResponse.class);
|
||||||
|
if (response != null && response.getCode().equals(200)) {
|
||||||
|
return response.getData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
log.error("Failed to get optional stock from moneycontrol for " + stock.getSymbol(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
OptionalStockResponse response = new OptionalStockResponse();
|
||||||
|
response.getData().setSymbol(stock.getSymbol());
|
||||||
|
response.getData().setSymbol(stock.getCompany());
|
||||||
|
|
||||||
|
return response.getData();
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
return ResponseEntity.ok(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setResponse(StockHistoryResponse response, String resolution) {
|
||||||
|
if (!"ok".equals(response.getS())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(Objects.isNull(response.getT())){
|
if (Objects.isNull(response.getT())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(StringUtils.equals("H",resolution) || StringUtils.equals("D",resolution)) {
|
if (StringUtils.equals("H", resolution) || StringUtils.equals("D", resolution)) {
|
||||||
List<Long> t = new ArrayList<>();
|
List<Long> t = new ArrayList<>();
|
||||||
List<Double> o = new ArrayList<>();
|
List<Double> o = new ArrayList<>();
|
||||||
List<Double> h = new ArrayList<>();
|
List<Double> h = new ArrayList<>();
|
||||||
@@ -756,7 +1110,7 @@ public class MoneyApiController {
|
|||||||
Date currentTime = new Date();
|
Date currentTime = new Date();
|
||||||
//判断最后一条是不是当天的数据,如果不是,把最后一条的时间作为当天的时间
|
//判断最后一条是不是当天的数据,如果不是,把最后一条的时间作为当天的时间
|
||||||
long getTime = response.getT().get(response.getT().size() - 1) * 1000L;
|
long getTime = response.getT().get(response.getT().size() - 1) * 1000L;
|
||||||
if(!DateUtil.isSameDay(currentTime, new Date(getTime))){
|
if (!DateUtil.isSameDay(currentTime, new Date(getTime))) {
|
||||||
currentTime = new Date(getTime);
|
currentTime = new Date(getTime);
|
||||||
}
|
}
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -782,14 +1136,14 @@ public class MoneyApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private String buildApiUrl(StockHistoryRequest request) {
|
private String buildApiUrl(StockHistoryRequest request) {
|
||||||
// 构建外部API的URL
|
// 构建外部API的URL
|
||||||
return String.format("%s?symbol=%s&resolution=%s&from=%d&to=%d&countback=%d¤cyCode=%s",
|
return String.format("%s?symbol=%s&resolution=%s&from=%d&to=%d&countback=%d¤cyCode=%s",
|
||||||
EXTERNAL_API_URL, request.getSymbol(), request.getResolution(), request.getFrom(),
|
EXTERNAL_API_URL, request.getSymbol(), request.getResolution(), request.getFrom(),
|
||||||
request.getTo(), request.getCountback(), request.getCurrencyCode());
|
request.getTo(), request.getCountback(), request.getCurrencyCode());
|
||||||
};
|
}
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
private static String extractLastSegment(String url) {
|
private static String extractLastSegment(String url) {
|
||||||
@@ -814,7 +1168,7 @@ public class MoneyApiController {
|
|||||||
//// bseTopLoser();
|
//// bseTopLoser();
|
||||||
System.out.println(new Date());
|
System.out.println(new Date());
|
||||||
System.out.println(new Date(1713949200000L));
|
System.out.println(new Date(1713949200000L));
|
||||||
System.out.println(DateUtil.isSameDay(new Date(),new Date(1713949200000L)));
|
System.out.println(DateUtil.isSameDay(new Date(), new Date(1713949200000L)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Cache<String, List<MoneyStockSuggestDTO>> gainerStockSuggestCache = CacheBuilder.newBuilder()
|
private Cache<String, List<MoneyStockSuggestDTO>> gainerStockSuggestCache = CacheBuilder.newBuilder()
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -169,15 +172,22 @@ public class StockApiController {
|
|||||||
|
|
||||||
@RequestMapping({"test.do"})
|
@RequestMapping({"test.do"})
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public ServerResponse test(@RequestParam("url") String url, @RequestParam("pageNum") Integer pageNum) {
|
public ServerResponse test(/*@RequestParam("url") String url, @RequestParam("pageNum") Integer pageNum*/) {
|
||||||
String news = stockService.getNews();
|
String news = stockService.getNews();
|
||||||
List<String> newsList = Arrays.asList(news.split("<a href="));
|
List<String> newsList = Arrays.asList(news.split("<a href="));
|
||||||
newsList = newsList.subList(1, newsList.size());
|
newsList = newsList.subList(1, newsList.size());
|
||||||
newsList.forEach( n -> {
|
newsList.forEach( n -> {
|
||||||
String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2);
|
String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2);
|
||||||
String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_"));
|
String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_"));
|
||||||
String imgUrl = n.substring(n.indexOf("img loading=\"lazy\" src=") + 24, n.indexOf("?"));
|
String imgUrl = InvestingTask.extractImgSrc(n);
|
||||||
String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9);
|
// String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9);
|
||||||
|
// Extract the date and time using regex
|
||||||
|
Pattern pattern = Pattern.compile("Updated On :<!-- --> <!-- -->(.*?)<!-- -->");
|
||||||
|
Matcher matcher = pattern.matcher(n);
|
||||||
|
String time = "";
|
||||||
|
if (matcher.find()) {
|
||||||
|
time = matcher.group(1).trim();
|
||||||
|
}
|
||||||
|
|
||||||
SiteNews siteNews = new SiteNews();
|
SiteNews siteNews = new SiteNews();
|
||||||
siteNews.setAddTime(new Date());
|
siteNews.setAddTime(new Date());
|
||||||
@@ -238,7 +248,7 @@ public class StockApiController {
|
|||||||
@ResponseBody
|
@ResponseBody
|
||||||
public ServerResponse getIndiaIndexByToday() {
|
public ServerResponse getIndiaIndexByToday() {
|
||||||
String INDEX_CODE = "TODAY_INDEX";
|
String INDEX_CODE = "TODAY_INDEX";
|
||||||
return RequestCacheUtils.cache("getIndiaIndexByToday.do", INDEX_CODE,60000, (string) -> {
|
return RequestCacheUtils.cache("getIndiaIndexByToday.do", INDEX_CODE,6000, (string) -> {
|
||||||
return this.stockService.getIndexByBtoday();
|
return this.stockService.getIndexByBtoday();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ spring:
|
|||||||
show-sql: true
|
show-sql: true
|
||||||
# Redis配置
|
# Redis配置
|
||||||
redis:
|
redis:
|
||||||
host: 43.132.212.180
|
host: 43.156.40.39
|
||||||
password: ruTZ9J3gaDhknJ
|
password: a5v8b86P4mVzFlUqJV
|
||||||
port: 36379
|
port: 30031
|
||||||
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://149.88.86.7:33306/india_stock?useUnicode=true&characterEncoding=utf-8
|
url: jdbc:mysql://43.156.40.39:30030/india_stock?useUnicode=true&characterEncoding=utf-8
|
||||||
username: root
|
username: root
|
||||||
password: 33BsUUcnXRYgwtIND
|
password: uNejHIFQGJOUtYTmE
|
||||||
maxActive: 500
|
maxActive: 500
|
||||||
testWhileIdle: true
|
testWhileIdle: true
|
||||||
validationQuery: SELECT 1
|
validationQuery: SELECT 1
|
||||||
|
|||||||
Reference in New Issue
Block a user