From 354399856f006de32d0dce69278b023c4ac113c8 Mon Sep 17 00:00:00 2001 From: xiaoliuhu Date: Mon, 4 Dec 2023 18:14:44 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=E5=85=B3=E9=97=ADA=E8=82=A1=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/stock/market/infrastructure/job/StockTask.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/cn/stock/market/infrastructure/job/StockTask.java b/src/main/java/cn/stock/market/infrastructure/job/StockTask.java index 2f7e947..4cbac87 100644 --- a/src/main/java/cn/stock/market/infrastructure/job/StockTask.java +++ b/src/main/java/cn/stock/market/infrastructure/job/StockTask.java @@ -37,7 +37,7 @@ import cn.stock.market.web.config.Config; import lombok.extern.slf4j.Slf4j; @Slf4j -@Component +//@Component public class StockTask { @Autowired RealtimeRepository realtimeRepository; @Autowired StockRepository stockRepository; @@ -202,7 +202,7 @@ public class StockTask { } /*同步股票列表*/ - @Scheduled(cron = "0 5 6 * * ?") +// @Scheduled(cron = "0 5 6 * * ?") public void syncBjsStockList() { MdcUtil.setTraceIdIfAbsent(); boolean flag = true; From 19e7fb544e0dff8f72d29323d5707b5e4714a4bc Mon Sep 17 00:00:00 2001 From: rplees Date: Mon, 4 Dec 2023 20:56:38 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:K=E7=BA=BF-=E5=AD=A3=E5=BA=A6/?= =?UTF-8?q?=E5=8D=8A=E5=B9=B4/=E5=B9=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/investing/InvestingApis.java | 12 +--------- .../api/investing/InvestingInvokerApis.java | 22 +++++++++++++++++-- .../stock/market/web/StockApiController.java | 2 +- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/main/java/cn/stock/market/infrastructure/api/investing/InvestingApis.java b/src/main/java/cn/stock/market/infrastructure/api/investing/InvestingApis.java index 2358b71..d53a99f 100644 --- a/src/main/java/cn/stock/market/infrastructure/api/investing/InvestingApis.java +++ b/src/main/java/cn/stock/market/infrastructure/api/investing/InvestingApis.java @@ -227,18 +227,8 @@ public class InvestingApis { if(code == null) { 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(); - JSONObject json = InvestingInvokerApis.of().__kline(code, interval); + JSONObject json = InvestingInvokerApis.of().__kline(code, string); return json .getJSONArray("data") .stream() diff --git a/src/main/java/cn/stock/market/infrastructure/api/investing/InvestingInvokerApis.java b/src/main/java/cn/stock/market/infrastructure/api/investing/InvestingInvokerApis.java index 92a44ee..f8fbf3d 100644 --- a/src/main/java/cn/stock/market/infrastructure/api/investing/InvestingInvokerApis.java +++ b/src/main/java/cn/stock/market/infrastructure/api/investing/InvestingInvokerApis.java @@ -138,6 +138,7 @@ public class InvestingInvokerApis { throw new RuntimeException("找不到股票信息"); } String interval = null; + String period = null; if("min".equalsIgnoreCase(string)) { interval = "PT5M"; } else if("day".equalsIgnoreCase(string)) { @@ -146,13 +147,30 @@ public class InvestingInvokerApis { interval = "P1W"; } else if("month".equalsIgnoreCase(string)) { 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)) { 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); String body = httpClient().newCall(builder.build()).execute().body().string(); diff --git a/src/main/java/cn/stock/market/web/StockApiController.java b/src/main/java/cn/stock/market/web/StockApiController.java index 7f6fb9a..b259023 100644 --- a/src/main/java/cn/stock/market/web/StockApiController.java +++ b/src/main/java/cn/stock/market/web/StockApiController.java @@ -144,7 +144,7 @@ public class StockApiController { @ResponseBody @ApiImplicitParams({ @ApiImplicitParam(name = "stockCode",value = "股票对应代码",dataType ="String", paramType = "query", required = true), - @ApiImplicitParam(name = "type",value = "type min-时分线 day-日线 week-周线 month-月线",dataType ="String", paramType = "query", 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") String type) throws IOException { ParamUtils.verify("股票代码", stockCode, ParamUtils.STRING_NOT_EMPTY_VERIFY_AND_CONVERT_VALUE); From fa385e671f21e1ae6ae05633090b94434595513f Mon Sep 17 00:00:00 2001 From: xiaoliuhu Date: Mon, 4 Dec 2023 21:36:42 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=E5=85=B3=E9=97=ADA=E8=82=A1=E8=B5=84?= =?UTF-8?q?=E8=AE=AF=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../market/infrastructure/db/po/StockPO.java | 4 +- .../infrastructure/job/InvestingTask.java | 93 +++++++++++++++++++ .../market/infrastructure/job/JobBoot.java | 2 +- .../java/cn/stock/market/utils/Utils.java | 66 ++++++++++--- .../market/web/config/Swagger2Config.java | 2 +- 5 files changed, 152 insertions(+), 15 deletions(-) create mode 100644 src/main/java/cn/stock/market/infrastructure/job/InvestingTask.java diff --git a/src/main/java/cn/stock/market/infrastructure/db/po/StockPO.java b/src/main/java/cn/stock/market/infrastructure/db/po/StockPO.java index 1bd76cb..398dba2 100644 --- a/src/main/java/cn/stock/market/infrastructure/db/po/StockPO.java +++ b/src/main/java/cn/stock/market/infrastructure/db/po/StockPO.java @@ -66,7 +66,7 @@ public class StockPO { Integer stockState; - Integer stockExchangeId; + String stockExchangeId; - Integer stockSymbol; + String stockSymbol; } diff --git a/src/main/java/cn/stock/market/infrastructure/job/InvestingTask.java b/src/main/java/cn/stock/market/infrastructure/job/InvestingTask.java new file mode 100644 index 0000000..cb512db --- /dev/null +++ b/src/main/java/cn/stock/market/infrastructure/job/InvestingTask.java @@ -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 stockMap = StockRepository.of().cacheCodeMap(); + Stopwatch stopwatch = Stopwatch.createStarted(); + List 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()); + } + + } +} diff --git a/src/main/java/cn/stock/market/infrastructure/job/JobBoot.java b/src/main/java/cn/stock/market/infrastructure/job/JobBoot.java index d9de463..a3aa98f 100644 --- a/src/main/java/cn/stock/market/infrastructure/job/JobBoot.java +++ b/src/main/java/cn/stock/market/infrastructure/job/JobBoot.java @@ -13,7 +13,7 @@ import cn.stock.market.domain.basic.service.SiteNewsService; import lombok.extern.slf4j.Slf4j; @Slf4j -@Component +//@Component public class JobBoot { /** * cronExpression表达式定义:  diff --git a/src/main/java/cn/stock/market/utils/Utils.java b/src/main/java/cn/stock/market/utils/Utils.java index 6a68794..1a0017d 100644 --- a/src/main/java/cn/stock/market/utils/Utils.java +++ b/src/main/java/cn/stock/market/utils/Utils.java @@ -1,16 +1,18 @@ package cn.stock.market.utils; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.time.DayOfWeek; import java.time.LocalDate; import java.time.LocalTime; -import java.util.ArrayList; -import java.util.Date; -import java.util.Hashtable; -import java.util.List; -import java.util.Map; +import java.util.*; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import org.apache.commons.lang3.StringUtils; import org.springframework.data.domain.Page; @@ -394,13 +396,55 @@ public final class Utils { 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) { - 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.9", "1.0.10")); - System.out.println(highVersion("1.0.10", "1.0.11")); - System.out.println(highVersion("1.0.10", "1.0.9")); +// 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.9", "1.0.10")); +// System.out.println(highVersion("1.0.10", "1.0.11")); +// 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. +// } } } diff --git a/src/main/java/cn/stock/market/web/config/Swagger2Config.java b/src/main/java/cn/stock/market/web/config/Swagger2Config.java index 5766e7b..3f09760 100644 --- a/src/main/java/cn/stock/market/web/config/Swagger2Config.java +++ b/src/main/java/cn/stock/market/web/config/Swagger2Config.java @@ -128,7 +128,7 @@ public class Swagger2Config { public ApiInfoBuilder commonApiInfoBuilder() { return new ApiInfoBuilder() - .description("鑫宝 接口文档") + .description("英文股票接口文档") .termsOfServiceUrl("http://www.xxxx.cn/") .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0").version("v1.0"); }