Merge remote-tracking branch 'origin/develop' into develop

# Conflicts:
#	src/main/java/cn/stock/market/web/StockApiController.java
This commit is contained in:
dengli
2023-12-05 08:47:03 +08:00
9 changed files with 188 additions and 35 deletions

View File

@@ -227,18 +227,8 @@ public class InvestingApis {
if(code == null) { if(code == null) {
throw new RuntimeException("找不到股票信息"); throw new RuntimeException("找不到股票信息");
} }
String interval = null;
if("min".equalsIgnoreCase(string)) {
interval = "PT5M";
} else if("day".equalsIgnoreCase(string)) {
interval = "P1D";
} else if("week".equalsIgnoreCase(string)) {
interval = "P1W";
} else if("month".equalsIgnoreCase(string)) {
interval = "P1M";
}
Date nowDate = new Date(); Date nowDate = new Date();
JSONObject json = InvestingInvokerApis.of().__kline(code, interval); JSONObject json = InvestingInvokerApis.of().__kline(code, string);
return json return json
.getJSONArray("data") .getJSONArray("data")
.stream() .stream()

View File

@@ -138,6 +138,7 @@ public class InvestingInvokerApis {
throw new RuntimeException("找不到股票信息"); throw new RuntimeException("找不到股票信息");
} }
String interval = null; String interval = null;
String period = null;
if("min".equalsIgnoreCase(string)) { if("min".equalsIgnoreCase(string)) {
interval = "PT5M"; interval = "PT5M";
} else if("day".equalsIgnoreCase(string)) { } else if("day".equalsIgnoreCase(string)) {
@@ -146,13 +147,30 @@ public class InvestingInvokerApis {
interval = "P1W"; interval = "P1W";
} else if("month".equalsIgnoreCase(string)) { } else if("month".equalsIgnoreCase(string)) {
interval = "P1M"; interval = "P1M";
} else if("3month".equalsIgnoreCase(string)) {
interval = "P1D";
period = "P3M";
} else if("6month".equalsIgnoreCase(string)) {
interval = "P1D";
period = "P6M";
} else if("year".equalsIgnoreCase(string)) {
interval = "P1W";
period = "P1Y";
} }
if(StringUtils.isBlank(interval)) { if(StringUtils.isBlank(interval)) {
interval = string; interval = string;
} }
String tmpl = "https://api.investing.com/api/financialdata/{}/historical/chart/?interval={}&pointscount=160";
String url = StrFormatter.format(tmpl, code.getCode(), interval); String url = null;
if(StringUtils.isNotBlank(period)) {
String tmpl = "https://api.investing.com/api/financialdata/{}/historical/chart/?period={}&interval={}&pointscount=160";
url = StrFormatter.format(tmpl, code.getCode(), period, interval);
} else {
String tmpl = "https://api.investing.com/api/financialdata/{}/historical/chart/?interval={}&pointscount=160";
url = StrFormatter.format(tmpl, code.getCode(), interval);
}
Builder builder = builderGet(url); Builder builder = builderGet(url);
String body = httpClient().newCall(builder.build()).execute().body().string(); String body = httpClient().newCall(builder.build()).execute().body().string();

View File

@@ -66,7 +66,7 @@ public class StockPO {
Integer stockState; Integer stockState;
Integer stockExchangeId; String stockExchangeId;
Integer stockSymbol; String stockSymbol;
} }

View File

@@ -0,0 +1,93 @@
package cn.stock.market.infrastructure.job;
import cn.stock.market.domain.basic.entity.Stock;
import cn.stock.market.domain.basic.repository.StockRepository;
import cn.stock.market.infrastructure.api.investing.InvestingInvokerApis;
import cn.stock.market.utils.Utils;
import com.ag.utils.CollectionUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Stopwatch;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@Slf4j
@Component
public class InvestingTask {
@Scheduled(cron = "0 0 5 * * ?")
public void syncIndiaData(){
log.info("同步股票数据开始。。。。");
Map<String, Stock> stockMap = StockRepository.of().cacheCodeMap();
Stopwatch stopwatch = Stopwatch.createStarted();
List<Stock> list = Lists.newArrayList();
int currentTotal = 0;
int pageNum =1;
int pageSize = 300;
try {
for(int i = 0;i < pageNum;i ++) {
JSONObject jsonObject = InvestingInvokerApis.of().__page(pageNum, pageSize);
int total = 0;
if(jsonObject.containsKey("total")){
total = Integer.parseInt(jsonObject.get("total").toString());
}
JSONArray dataObjArray = new JSONArray();
if(jsonObject.containsKey("data")){
dataObjArray = JSON.parseArray(jsonObject.get("data").toString());
}
for (Object obj : dataObjArray) {
JSONObject jsonObject2 = JSON.parseObject(obj.toString());
String code = jsonObject2.get("Id").toString();
String name = jsonObject2.get("Name").toString();
String stockSymbol = jsonObject2.get("Symbol").toString();
String exchangeId = jsonObject2.get("ExchangeId").toString();
if (stockMap.containsKey(code)) {
log.info("已经存在 {} 信息, 跳过", code);
continue;
}
if(! Utils.isShOrSzOrBJ(code)) {
log.info("{} 非 sh 或者 sz 或者 bj , 跳过", code);
continue;
}
Stock stock = new Stock();
stock.setStockSymbol(stockSymbol);
stock.setStockExchangeId(exchangeId);
stock.setStockName(name);
stock.setStockCode(code);
stock.setIsLock(0);
stock.setIsShow(0);
stock.setAddTime(new Date());
stock.setStockState(0);
list.add(stock);
}
currentTotal += pageSize;
if((total - currentTotal) < pageSize ){
pageSize = total - currentTotal;
}
if(total == currentTotal){
break;
}
pageNum ++;
}
if(CollectionUtils.isNotEmpty(list)) {
StockRepository.of().saveAll(list);
}
int count = list.size();
log.info("syncAFutureStockList执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
log.info("同步股票数据结束。。。。");
} catch (Exception e) {
log.info("同步股票数据异常,异常信息{}。。。。",e.getMessage());
}
}
}

View File

@@ -13,7 +13,7 @@ import cn.stock.market.domain.basic.service.SiteNewsService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@Component //@Component
public class JobBoot { public class JobBoot {
/** /**
* cronExpression表达式定义  * cronExpression表达式定义 

View File

@@ -37,7 +37,7 @@ import cn.stock.market.web.config.Config;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@Component //@Component
public class StockTask { public class StockTask {
@Autowired RealtimeRepository realtimeRepository; @Autowired RealtimeRepository realtimeRepository;
@Autowired StockRepository stockRepository; @Autowired StockRepository stockRepository;
@@ -202,7 +202,7 @@ public class StockTask {
} }
/*同步股票列表*/ /*同步股票列表*/
@Scheduled(cron = "0 5 6 * * ?") // @Scheduled(cron = "0 5 6 * * ?")
public void syncBjsStockList() { public void syncBjsStockList() {
MdcUtil.setTraceIdIfAbsent(); MdcUtil.setTraceIdIfAbsent();
boolean flag = true; boolean flag = true;

View File

@@ -1,16 +1,18 @@
package cn.stock.market.utils; package cn.stock.market.utils;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.time.DayOfWeek; import java.time.DayOfWeek;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@@ -394,13 +396,55 @@ public final class Utils {
return returnStr; return returnStr;
} }
//读取txt文本内容
public static String readTxt() {
FileReader fr = null;
BufferedReader br = null;
StringBuilder buffer = new StringBuilder();
try {
String file = Objects.requireNonNull(Utils.class.getResource("/india.txt")).getPath();
fr = new FileReader(file);
br = new BufferedReader(fr);
String line = "";
while ((line = br.readLine()) != null) {
buffer.append(line);
}
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
if (fr != null) {
try {
fr.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
return buffer.toString();
}
public static void main(String[] args) { public static void main(String[] args) {
System.out.println(getFirstLetter("0L神鼎ds飞#@#丹砂")); // System.out.println(getFirstLetter("0L神鼎ds飞#@#丹砂"));
System.out.println(getFirstLetter("0L神鼎ds飞#@#丹砂")); // System.out.println(getFirstLetter("0L神鼎ds飞#@#丹砂"));
System.out.println(highVersion("1.0.8", "1.0.9")); // System.out.println(highVersion("1.0.8", "1.0.9"));
System.out.println(highVersion("1.0.9", "1.0.10")); // System.out.println(highVersion("1.0.9", "1.0.10"));
System.out.println(highVersion("1.0.10", "1.0.11")); // System.out.println(highVersion("1.0.10", "1.0.11"));
System.out.println(highVersion("1.0.10", "1.0.9")); // System.out.println(highVersion("1.0.10", "1.0.9"));
String str = readTxt();
JSONArray jsonArray = JSON.parseArray(str);
System.out.println(Arrays.toString(jsonArray.toArray()));
// for (Object object : jsonArray){
// object.
// }
} }
} }

View File

@@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
import com.ag.utils.DateUtils; import com.ag.utils.DateUtils;
import com.ag.utils.Jsons; import com.ag.utils.Jsons;
import com.ag.utils.param.ParamUtils;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
@@ -41,6 +42,9 @@ import cn.stock.market.domain.basic.service.StockService;
import cn.stock.market.dto.model.StockCode; import cn.stock.market.dto.model.StockCode;
import cn.stock.market.dto.model.StockVO; import cn.stock.market.dto.model.StockVO;
import cn.stock.market.infrastructure.api.EastmoneyApi; import cn.stock.market.infrastructure.api.EastmoneyApi;
import cn.stock.market.infrastructure.api.investing.IndiaStockVO;
import cn.stock.market.infrastructure.api.investing.InvestingApis;
import cn.stock.market.infrastructure.api.investing.InvestingInvokerApis;
import cn.stock.market.infrastructure.api.qq.QqStockApi; import cn.stock.market.infrastructure.api.qq.QqStockApi;
import cn.stock.market.infrastructure.api.sina.SinaStockApi; import cn.stock.market.infrastructure.api.sina.SinaStockApi;
import cn.stock.market.utils.RequestCacheUtils; import cn.stock.market.utils.RequestCacheUtils;
@@ -139,11 +143,15 @@ public class StockApiController {
@ApiOperation(value = "印度股票K线", httpMethod = "GET") @ApiOperation(value = "印度股票K线", httpMethod = "GET")
@ResponseBody @ResponseBody
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "stockCode",value = "股票对应代码",dataType ="String",required = true), @ApiImplicitParam(name = "stockCode",value = "股票对应代码",dataType ="String", paramType = "query", required = true),
@ApiImplicitParam(name = "type",value = "type 0-时分线 1-日线 2-周线 3-月线",dataType ="Integer",required = true), @ApiImplicitParam(name = "type",value = "min-时分线 day-日线 week-周线 month-月线, 3month-季度, 6month-半年, year-年",dataType ="String", paramType = "query", required = true),
}) })
public ServerResponse getINDTimeK(@RequestParam("stockCode") String stockCode, @RequestParam("type") Integer type) { public ServerResponse getINDTimeK(@RequestParam("stockCode") String stockCode, @RequestParam("type") String type) throws IOException {
return this.stockService.getIndiaK(stockCode, type); ParamUtils.verify("股票代码", stockCode, ParamUtils.STRING_NOT_EMPTY_VERIFY_AND_CONVERT_VALUE);
ParamUtils.verify("K线类型", stockCode, ParamUtils.STRING_NOT_EMPTY_VERIFY_AND_CONVERT_VALUE);
List<JSONObject> list = InvestingApis.of().kline(StockCode.of(stockCode), type);
return ServerResponse.createBySuccess(list);
} }
//根据股票id查询 股票指数、大盘指数信息 //根据股票id查询 股票指数、大盘指数信息

View File

@@ -128,7 +128,7 @@ public class Swagger2Config {
public ApiInfoBuilder commonApiInfoBuilder() { public ApiInfoBuilder commonApiInfoBuilder() {
return new ApiInfoBuilder() return new ApiInfoBuilder()
.description("鑫宝 接口文档") .description("英文股票接口文档")
.termsOfServiceUrl("http://www.xxxx.cn/") .termsOfServiceUrl("http://www.xxxx.cn/")
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0").version("v1.0"); .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0").version("v1.0");
} }