fix:关闭A股资讯定时任务
This commit is contained in:
@@ -66,7 +66,7 @@ public class StockPO {
|
||||
|
||||
Integer stockState;
|
||||
|
||||
Integer stockExchangeId;
|
||||
String stockExchangeId;
|
||||
|
||||
Integer stockSymbol;
|
||||
String stockSymbol;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import cn.stock.market.domain.basic.service.SiteNewsService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
//@Component
|
||||
public class JobBoot {
|
||||
/**
|
||||
* cronExpression表达式定义:
|
||||
|
||||
@@ -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.
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user