fix:修改定时任务
This commit is contained in:
@@ -13,8 +13,10 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
import cn.stock.market.dto.model.*;
|
||||
import cn.stock.market.infrastructure.api.investing.InvestingInvokerApis;
|
||||
import cn.stock.market.infrastructure.api.sina.vo.HotSearchVO;
|
||||
import cn.stock.market.utils.*;
|
||||
import com.ag.utils.CollectionUtils;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
@@ -741,4 +743,69 @@ public class StockService {
|
||||
builder.header(key, value);
|
||||
}
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -203,7 +203,7 @@ public class InvestingInvokerApis {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
JSONObject __market = of().__market(StockCode.of("17988"));
|
||||
JSONObject __market = of().__page(1,100);
|
||||
System.out.println(__market);
|
||||
|
||||
JSONObject __page = of().__page(1, 10);
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.concurrent.TimeUnit;
|
||||
@Component
|
||||
public class InvestingTask {
|
||||
|
||||
@Scheduled(cron = "0 0 5 * * ?")
|
||||
@Scheduled(cron = "0 0 6 * * ?")
|
||||
public void syncIndiaData(){
|
||||
log.info("同步股票数据开始。。。。");
|
||||
Map<String, Stock> stockMap = StockRepository.of().cacheCodeMap();
|
||||
@@ -74,7 +74,7 @@ public class InvestingTask {
|
||||
if((total - currentTotal) < pageSize ){
|
||||
pageSize = total - currentTotal;
|
||||
}
|
||||
if(total == currentTotal){
|
||||
if(total <= currentTotal){
|
||||
break;
|
||||
}
|
||||
pageNum ++;
|
||||
|
||||
@@ -642,9 +642,17 @@ public class StockApiController {
|
||||
@ApiOperation(value = "新股待上市接口",httpMethod = "GET", response = ServerResponse.class)
|
||||
@RequestMapping({"getNewStockList.do"})
|
||||
@ResponseBody
|
||||
public
|
||||
ServerResponse getNewStockList() {
|
||||
public ServerResponse getNewStockList() {
|
||||
|
||||
return this.stockService.getNewStockList();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "印度股票入库",httpMethod = "GET", response = ServerResponse.class)
|
||||
@RequestMapping({"syncIndiaData.do"})
|
||||
@ResponseBody
|
||||
public ServerResponse syncIndiaData() {
|
||||
|
||||
stockService.syncIndiaData();
|
||||
return ServerResponse.createBySuccess();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user