|
@@ -35,13 +35,17 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
|
|
|
|
|
|
private static final String urlRedis = "http://taifooksec.com/init/redis/updateInfo.do";
|
|
|
|
|
|
+ private static final String sourceAfterFileUrl = "D:/www/wwwroot/csqdata/stock/after";
|
|
|
+
|
|
|
+ private static final String goalAfterFileUrl = "D:/www/wwwroot/csqdata/stock/after/backup";
|
|
|
+
|
|
|
@Autowired
|
|
|
private ChoiceStockMapper choiceStockMapper;
|
|
|
|
|
|
@Override
|
|
|
- public void analysisStockRestData() {
|
|
|
+ public void analysisStockRestData(String type) {
|
|
|
// 1.获取文件夹文件 按照时间顺序拿到一个
|
|
|
- List<File> files = FileStockUtil.getFile(sourceFileUrl);
|
|
|
+ List<File> files = FileStockUtil.getFile("now".equals(type)?sourceFileUrl:sourceAfterFileUrl);
|
|
|
if(null == files || 0 == files.size()){
|
|
|
return;
|
|
|
}
|
|
@@ -53,9 +57,16 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
|
|
|
StockRestRedisVO stockRestRedisVO;
|
|
|
for (File file : files){
|
|
|
// 2.移动文件去另外一个文件夹
|
|
|
- FileStockUtil.moveFile(sourceFileUrl + File.separator + file.getName(), goalFileUrl);
|
|
|
- // 3.读取文件内容
|
|
|
- String str = FileStockUtil.readFileContent(goalFileUrl + File.separator + file.getName());
|
|
|
+ String str = "";
|
|
|
+ if("now".equals(type)){
|
|
|
+ FileStockUtil.moveFile(sourceFileUrl + File.separator + file.getName(), goalFileUrl);
|
|
|
+ // 3.读取文件内容
|
|
|
+ str = FileStockUtil.readFileContent(goalFileUrl + File.separator + file.getName());
|
|
|
+ }else if("after".equals(type)){
|
|
|
+ FileStockUtil.moveFile(sourceAfterFileUrl + File.separator + file.getName(), goalAfterFileUrl);
|
|
|
+ // 3.读取文件内容
|
|
|
+ str = FileStockUtil.readFileContent(goalAfterFileUrl + File.separator + file.getName());
|
|
|
+ }
|
|
|
// 4.并解析
|
|
|
if(StringUtils.isEmpty(str)){
|
|
|
continue;
|
|
@@ -70,7 +81,7 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
|
|
|
if(String.valueOf(entry.getValue().get(1)).equals("0")){
|
|
|
continue;
|
|
|
}
|
|
|
- stockRestPojo.setTime(String.valueOf(entry.getValue().get(1)));
|
|
|
+ stockRestPojo.setTime("now".equals(type)?String.valueOf(entry.getValue().get(1)):"150000");
|
|
|
stockRestPojo.setNow(String.valueOf(entry.getValue().get(2)));
|
|
|
stockRestPojo.setHigh(String.valueOf(entry.getValue().get(3)));
|
|
|
stockRestPojo.setLow(String.valueOf(entry.getValue().get(4)));
|
|
@@ -188,16 +199,21 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
|
|
|
map = null;
|
|
|
}
|
|
|
// 5.入库
|
|
|
- insertList(stockRestPojoList, stockRestVOList, stockRestRedisVOList);
|
|
|
+ insertList(stockRestPojoList, stockRestVOList, stockRestRedisVOList,type);
|
|
|
stockRestPojoList = null;
|
|
|
}
|
|
|
|
|
|
- private void insertList(List<StockRestPojo> list, List<StockRestVO> stockRestVOList, List<StockRestRedisVO> stockRestRedisVOList) {
|
|
|
+
|
|
|
+ private void insertList(List<StockRestPojo> list, List<StockRestVO> stockRestVOList, List<StockRestRedisVO> stockRestRedisVOList,String type) {
|
|
|
int insertLength = list.size();
|
|
|
int i = 0;
|
|
|
int insertSize = 500;
|
|
|
while (insertLength > insertSize) {
|
|
|
- choiceStockMapper.insertBatch(list.subList(i, i + insertSize));
|
|
|
+ if("now".equals(type)){
|
|
|
+ choiceStockMapper.insertBatch(list.subList(i, i + insertSize));
|
|
|
+ }else {
|
|
|
+ choiceStockMapper.insertBatchByAfter(list.subList(i, i + insertSize));
|
|
|
+ }
|
|
|
List<StockRestVO> subList = stockRestVOList.subList(i, i + insertSize);
|
|
|
List<StockRestRedisVO> subRedisList = stockRestRedisVOList.subList(i, i + insertSize);
|
|
|
i = i + insertSize;
|
|
@@ -207,7 +223,7 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
|
|
|
public void run() {
|
|
|
// HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
|
|
|
if(BuyAndSellUtils.isTransState()){
|
|
|
- HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
|
|
|
+ // HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -215,7 +231,11 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
|
|
|
thread.start();
|
|
|
}
|
|
|
if (insertLength > 0) {
|
|
|
- choiceStockMapper.insertBatch(list.subList(i, i + insertLength));
|
|
|
+ if("now".equals(type)){
|
|
|
+ choiceStockMapper.insertBatch(list.subList(i, i + insertLength));
|
|
|
+ }else {
|
|
|
+ choiceStockMapper.insertBatchByAfter(list.subList(i, i + insertLength));
|
|
|
+ }
|
|
|
List<StockRestVO> subList = stockRestVOList.subList(i, i + insertLength);
|
|
|
List<StockRestRedisVO> subRedisList = stockRestRedisVOList.subList(i, i + insertLength);
|
|
|
Thread thread=new Thread(new Runnable() {
|
|
@@ -223,7 +243,7 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
|
|
|
public void run() {
|
|
|
// HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
|
|
|
if(BuyAndSellUtils.isTransState()){
|
|
|
- HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
|
|
|
+ // HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
|
|
|
}
|
|
|
}
|
|
|
});
|