|
@@ -1,9 +1,12 @@
|
|
|
package com.zx.dataservice.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.jfinal.plugin.activerecord.Db;
|
|
|
import com.zx.dataservice.controller.WebSocketController;
|
|
|
import com.zx.dataservice.mapper1.ChoiceStockMapper;
|
|
|
import com.zx.dataservice.options.DataOptions;
|
|
|
+import com.zx.dataservice.options.RiskOptions;
|
|
|
+import com.zx.dataservice.options.WSOptions;
|
|
|
import com.zx.dataservice.pojo.StockRestPojo;
|
|
|
import com.zx.dataservice.service.ChoiceTempIndexService;
|
|
|
import com.zx.dataservice.utils.*;
|
|
@@ -48,12 +51,11 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
|
|
|
return;
|
|
|
}
|
|
|
List<StockRestPojo> stockRestPojoList = new ArrayList<>();
|
|
|
- List<StockRestVO> stockRestVOList = new ArrayList<>();
|
|
|
List<StockRestRedisVO> stockRestRedisVOList = new ArrayList<>();
|
|
|
Map<String,List<StockRestRedisVO>>mapws = new HashMap<>();
|
|
|
- mapws.put("stockRestRedisVO",new ArrayList<>()); // 无风控数据
|
|
|
- for(String key: DataOptions.keySet()){ // 所有的需要风控的 客户
|
|
|
- mapws.put("stockRestRedisVO_"+key,new ArrayList<>());
|
|
|
+// mapws.put("stockRestRedisVO",new ArrayList<>()); // 无风控数据
|
|
|
+ for(String key: WSOptions.keySet()){ // 所有的需要推送的 客户
|
|
|
+ mapws.put("stockRestRedisVO_"+ WSOptions.get(key).split("_")[0],new ArrayList<>());
|
|
|
}
|
|
|
StockRestPojo stockRestPojo;
|
|
|
StockRestVO stockRestVO;
|
|
@@ -185,7 +187,6 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
|
|
|
stockRestPojoList.add(stockRestPojo);
|
|
|
stockRestVO = new StockRestVO();
|
|
|
BeanUtils.copyProperties(stockRestPojo, stockRestVO);
|
|
|
- stockRestVOList.add(stockRestVO);
|
|
|
stockRestRedisVO = new StockRestRedisVO();
|
|
|
stockRestRedisVO.setCode(entry.getKey().toUpperCase());
|
|
|
stockRestRedisVO.setNowPrice(stockRestPojo.getNow());
|
|
@@ -194,24 +195,29 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
|
|
|
stockRestRedisVO.setHighlimit(stockRestPojo.getHighlimit());
|
|
|
stockRestRedisVO.setLowlimit(stockRestPojo.getLowlimit());
|
|
|
// stockRestRedisVOList.add(stockRestRedisVO);// old
|
|
|
- mapws.get("stockRestRedisVO").add(stockRestRedisVO);
|
|
|
- if(DataOptions.keySet().contains(entry.getKey())){// 存在该股票的风控
|
|
|
- for(String key: DataOptions.keySet()){ // 所有的需要风控的 客户 BTC_hy LTC_hy 000001.SZ_hy
|
|
|
- // 风控 逻辑
|
|
|
- StockRestPojo stockRestPojoRisk = getRiskNow(stockRestPojo,key,DataOptions.get(key)); // 风控后的数据
|
|
|
- stockRestPojoList.add(stockRestPojoRisk);
|
|
|
- stockRestRedisVO = new StockRestRedisVO();
|
|
|
- stockRestRedisVO.setCode(entry.getKey().toUpperCase());
|
|
|
- stockRestRedisVO.setNowPrice(stockRestPojoRisk.getNow());
|
|
|
- stockRestRedisVO.setChange(stockRestPojoRisk.getChange());
|
|
|
- stockRestRedisVO.setHcrate(stockRestPojoRisk.getPctchange());
|
|
|
- stockRestRedisVO.setHighlimit(stockRestPojoRisk.getHighlimit());
|
|
|
- stockRestRedisVO.setLowlimit(stockRestPojoRisk.getLowlimit());
|
|
|
- mapws.get("stockRestRedisVO_"+key).add(stockRestRedisVO);
|
|
|
+
|
|
|
+ for (String key2 : WSOptions.keySet()){ // 所有的需要推送的客户
|
|
|
+ // 如果该股票需要风控
|
|
|
+ if(DataOptions.get("keyall").contains((WSOptions.get(key2).split("_")[0]+"_"+entry.getKey().toUpperCase()))){ // 存在该用户的该股票的风控 记录
|
|
|
+ for (String key : DataOptions.keySet()) { // 所有的需要风控的 客户 BTC_BTC_hy LTC_hy 000001.SZ_hy LTC_test test_BTC_BTC
|
|
|
+ // 风控 逻辑
|
|
|
+ if (key.contains(entry.getKey())) {// 存在该股票的风控 LTC_hy . contains (LTC)
|
|
|
+ StockRestPojo stockRestPojoRisk = getRiskNow(stockRestPojo, key, DataOptions.get(key)); // 风控后的数据 //tocode & mini & risk & multiples & status
|
|
|
+ stockRestPojoList.add(stockRestPojoRisk);
|
|
|
+ stockRestRedisVO = new StockRestRedisVO();
|
|
|
+ stockRestRedisVO.setCode(entry.getKey().toUpperCase());
|
|
|
+ stockRestRedisVO.setNowPrice(stockRestPojoRisk.getNow());
|
|
|
+ stockRestRedisVO.setChange(stockRestPojoRisk.getChange());
|
|
|
+ stockRestRedisVO.setHcrate(stockRestPojoRisk.getPctchange());
|
|
|
+ stockRestRedisVO.setHighlimit(stockRestPojoRisk.getHighlimit());
|
|
|
+ stockRestRedisVO.setLowlimit(stockRestPojoRisk.getLowlimit());
|
|
|
+ mapws.get("stockRestRedisVO_" + WSOptions.get(key2).split("_")[0]).add(stockRestRedisVO); // stockRestRedisVO_hy
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ mapws.get("stockRestRedisVO_"+ WSOptions.get(key2).split("_")[0]).add(stockRestRedisVO);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
log.error("错误数据导致失败" + e);
|
|
@@ -220,7 +226,7 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
|
|
|
map = null;
|
|
|
}
|
|
|
// 5.入库
|
|
|
- insertList(stockRestPojoList, stockRestVOList, mapws,type);
|
|
|
+ insertList(stockRestPojoList, mapws,type);
|
|
|
stockRestPojoList = null;
|
|
|
}
|
|
|
|
|
@@ -236,6 +242,11 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
|
|
|
List<StockRestPojo> stockRestPojoList = new ArrayList<>();
|
|
|
List<StockRestVO> stockRestVOList = new ArrayList<>();
|
|
|
List<StockRestRedisVO> stockRestRedisVOList = new ArrayList<>();
|
|
|
+ Map<String,List<StockRestRedisVO>>mapws = new HashMap<>();
|
|
|
+// mapws.put("stockRestRedisVO",new ArrayList<>()); // 无风控数据
|
|
|
+ for(String key: WSOptions.keySet()){ // 所有的需要推送的 客户
|
|
|
+ mapws.put("stockRestRedisVO_"+ WSOptions.get(key).split("_")[0],new ArrayList<>());
|
|
|
+ }
|
|
|
StockRestPojo stockRestPojo;
|
|
|
StockRestVO stockRestVO;
|
|
|
StockRestRedisVO stockRestRedisVO;
|
|
@@ -373,7 +384,31 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
|
|
|
stockRestRedisVO.setHcrate(stockRestPojo.getPctchange());
|
|
|
stockRestRedisVO.setHighlimit(stockRestPojo.getHighlimit());
|
|
|
stockRestRedisVO.setLowlimit(stockRestPojo.getLowlimit());
|
|
|
- stockRestRedisVOList.add(stockRestRedisVO);
|
|
|
+// stockRestRedisVOList.add(stockRestRedisVO);
|
|
|
+
|
|
|
+ for (String key2 : WSOptions.keySet()){ // 所有的需要推送的客户
|
|
|
+ // 如果该股票需要风控
|
|
|
+ if(DataOptions.get("keyall").contains((WSOptions.get(key2).split("_")[0]+entry.getKey().toUpperCase()))){ // 存在该用户的该股票的风控 记录
|
|
|
+ for (String key : DataOptions.keySet()) { // 所有的需要风控的 客户 BTC_BTC_hy LTC_hy 000001.SZ_hy LTC_test test_BTC_BTC
|
|
|
+ // 风控 逻辑
|
|
|
+ if (key.contains(entry.getKey())) {// 存在该股票的风控 LTC_hy . contains (LTC)
|
|
|
+ StockRestPojo stockRestPojoRisk = getRiskNow(stockRestPojo, key, DataOptions.get(key)); // 风控后的数据 //tocode & mini & risk & multiples & status
|
|
|
+ stockRestPojoList.add(stockRestPojoRisk);
|
|
|
+ stockRestRedisVO = new StockRestRedisVO();
|
|
|
+ stockRestRedisVO.setCode(entry.getKey().toUpperCase());
|
|
|
+ stockRestRedisVO.setNowPrice(stockRestPojoRisk.getNow());
|
|
|
+ stockRestRedisVO.setChange(stockRestPojoRisk.getChange());
|
|
|
+ stockRestRedisVO.setHcrate(stockRestPojoRisk.getPctchange());
|
|
|
+ stockRestRedisVO.setHighlimit(stockRestPojoRisk.getHighlimit());
|
|
|
+ stockRestRedisVO.setLowlimit(stockRestPojoRisk.getLowlimit());
|
|
|
+ mapws.get("stockRestRedisVO_" + WSOptions.get(key2).split("_")[0]).add(stockRestRedisVO); // stockRestRedisVO_hy
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ mapws.get("stockRestRedisVO_"+ WSOptions.get(key2).split("_")[0]).add(stockRestRedisVO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
log.error("错误数据导致失败" + e);
|
|
@@ -382,60 +417,42 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
|
|
|
map = null;
|
|
|
}
|
|
|
// 5.入库
|
|
|
- insertListAfter(stockRestPojoList, stockRestVOList, stockRestRedisVOList,type);
|
|
|
+ insertListAfter(stockRestPojoList, stockRestVOList, mapws,type);
|
|
|
stockRestPojoList = null;
|
|
|
}
|
|
|
|
|
|
- private void insertListAfter(List<StockRestPojo> list, List<StockRestVO> stockRestVOList, List<StockRestRedisVO> stockRestRedisVOList,String type) {
|
|
|
+ private void insertListAfter(List<StockRestPojo> list, List<StockRestVO> stockRestVOList, Map<String,List<StockRestRedisVO>>mapws ,String type) {
|
|
|
int insertLength = list.size();
|
|
|
int i = 0;
|
|
|
int insertSize = 500;
|
|
|
while (insertLength > insertSize) {
|
|
|
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;
|
|
|
insertLength = insertLength - insertSize;
|
|
|
- Thread thread=new Thread(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
-// HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
|
|
|
-// if(BuyAndSellUtils.isTransState()){
|
|
|
- try {
|
|
|
- new WebSocketController().sendSysMsgType("ZS",JSON.toJSONString(subRedisList));
|
|
|
-// HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
|
|
|
- }catch (Exception e){
|
|
|
- log.error("插入redis错误" + e);
|
|
|
- }
|
|
|
-// }
|
|
|
- }
|
|
|
- });
|
|
|
- thread.start();
|
|
|
+
|
|
|
}
|
|
|
if (insertLength > 0) {
|
|
|
-
|
|
|
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() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
+ }
|
|
|
+
|
|
|
+ Thread thread=new Thread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
// HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
|
|
|
// if(BuyAndSellUtils.isTransState()){
|
|
|
- try {
|
|
|
- new WebSocketController().sendSysMsgType("ZS",JSON.toJSONString(subRedisList));
|
|
|
+ try {
|
|
|
+ new WebSocketController().sendSysMsgType("ZS",mapws);
|
|
|
// HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
|
|
|
- }catch (Exception e){
|
|
|
- log.error("插入redis错误" + e);
|
|
|
- }
|
|
|
-// }
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("插入redis错误" + e);
|
|
|
}
|
|
|
- });
|
|
|
- thread.start();
|
|
|
- }
|
|
|
+// }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ thread.start();
|
|
|
}
|
|
|
|
|
|
- private void insertList(List<StockRestPojo> list, List<StockRestVO> stockRestVOList,Map<String,List<StockRestRedisVO>>mapws ,String type) { // List<StockRestRedisVO> stockRestRedisVOList
|
|
|
+ private void insertList(List<StockRestPojo> list,Map<String,List<StockRestRedisVO>>mapws ,String type) { // List<StockRestRedisVO> stockRestRedisVOList
|
|
|
int insertLength = list.size();
|
|
|
int i = 0;
|
|
|
int insertSize = 500;
|
|
@@ -445,25 +462,8 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
|
|
|
}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;
|
|
|
insertLength = insertLength - insertSize;
|
|
|
- Thread thread=new Thread(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
-// HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
|
|
|
-// if(BuyAndSellUtils.isTransState()){
|
|
|
- try {
|
|
|
- new WebSocketController().sendSysMsgType("ZS",JSON.toJSONString(subRedisList));
|
|
|
-// HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
|
|
|
- }catch (Exception e){
|
|
|
- log.error("插入redis错误" + e);
|
|
|
- }
|
|
|
-// }
|
|
|
- }
|
|
|
- });
|
|
|
- thread.start();
|
|
|
}
|
|
|
if (insertLength > 0) {
|
|
|
if("now".equals(type)){
|
|
@@ -471,38 +471,66 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
|
|
|
}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() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
+ }
|
|
|
+ Thread thread=new Thread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
// HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
|
|
|
// if(BuyAndSellUtils.isTransState()){
|
|
|
- try {
|
|
|
- new WebSocketController().sendSysMsgType("ZS",JSON.toJSONString(subRedisList));
|
|
|
+ try {
|
|
|
+ new WebSocketController().sendSysMsgType("ZS",mapws);
|
|
|
// HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
|
|
|
- }catch (Exception e){
|
|
|
- log.error("插入redis错误" + e);
|
|
|
- }
|
|
|
-// }
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("插入redis错误" + e);
|
|
|
}
|
|
|
- });
|
|
|
- thread.start();
|
|
|
- }
|
|
|
+// }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ thread.start();
|
|
|
}
|
|
|
|
|
|
|
|
|
public StockRestPojo getRiskNow (StockRestPojo stockRestPojo,String key,String value){
|
|
|
- // KEY = code _ hy // BTC_hy
|
|
|
+ // KEY = code _ hy // BTC_BTC_hy
|
|
|
String [] valueArr = value.split("&"); //tocode & mini & risk & multiples & status
|
|
|
+ String [] keyArr = key.split("_"); //code _ hy // BTC_BTC_hy CODE to tocode
|
|
|
+ StringBuffer tableName = new StringBuffer("data_rt_");
|
|
|
+ tableName.append(valueArr[0].replace(".", "_").toLowerCase());
|
|
|
+ tableName.append("_"+keyArr[0]);
|
|
|
if("1".equals(valueArr[4])){ // 如果此时没有开启风控 那么不变化
|
|
|
- StringBuffer tableName = new StringBuffer("data_rt_");
|
|
|
- tableName.append(valueArr[0].replace(".", "_").toLowerCase());
|
|
|
-
|
|
|
stockRestPojo.setTableName(tableName.toString());
|
|
|
return stockRestPojo;
|
|
|
}else {
|
|
|
+ String tocode = valueArr[0]; // 新币
|
|
|
+ String mini = valueArr[1];// 最小波动
|
|
|
+ String risk1 = valueArr[2].substring(0, 1); // 风险 +-*/110
|
|
|
+ String multiples = valueArr[3]; //倍数
|
|
|
+ String risk2 = BigdecimalUtil.getNew(mini,valueArr[2].substring(1, valueArr[2].length()),"*",4,2) ; // 风险 +-*/110
|
|
|
StockRestPojo stockRestPojoNew = new StockRestPojo();
|
|
|
+ BeanUtils.copyProperties(stockRestPojo,stockRestPojoNew,StockRestPojo.class);
|
|
|
+ String nnow = BigdecimalUtil.getNew(stockRestPojo.getNow() + "", risk2, risk1, 4, 2, multiples);
|
|
|
+ stockRestPojoNew.setTableName(tableName.toString()); // 表
|
|
|
+ stockRestPojoNew.setNow(nnow); // 现价
|
|
|
+ // 高
|
|
|
+ stockRestPojoNew.setHigh(BigdecimalUtil.getNew(stockRestPojo.getHigh() + "", risk2, risk1, 4, 2, multiples));
|
|
|
+ // 低
|
|
|
+ stockRestPojoNew.setLow(BigdecimalUtil.getNew(stockRestPojo.getLow() + "", risk2, risk1, 4, 2, multiples));
|
|
|
+ //开 取当天第一条 存缓存
|
|
|
+ if(StringUtils.isBlank(RiskOptions.get("open_"+key))){ // 为空就存 当前的now价为开盘价
|
|
|
+ RiskOptions.set("open_"+key,stockRestPojoNew.getNow()+"");
|
|
|
+ }
|
|
|
+ stockRestPojoNew.setOpen(RiskOptions.get("open_"+key));
|
|
|
+ //前收
|
|
|
+ if(StringUtils.isBlank(RiskOptions.get("preclose_"+key))){ // 为空就存 当前的计算当前的 收盘价 为收盘价 因为 除非是系统上线 不然不会在这出现为空的情况
|
|
|
+ String preclose = (BigdecimalUtil.getNew(stockRestPojo.getPreclose() + "", risk2, risk1, 4, 2, multiples)) ;
|
|
|
+ RiskOptions.set("preclose_"+key,preclose);
|
|
|
+ }
|
|
|
+ stockRestPojoNew.setPreclose(RiskOptions.get("preclose_"+key));
|
|
|
+
|
|
|
+ stockRestPojoNew.setChange((new BigDecimal(stockRestPojoNew.getNow() + "").
|
|
|
+ subtract(new BigDecimal(stockRestPojoNew.getPreclose() + ""))).setScale(4, 2)+"");
|
|
|
+ stockRestPojoNew.setPctchange(((!"0".equals(stockRestPojoNew.getPreclose())) ?
|
|
|
+ ((new BigDecimal(stockRestPojoNew.getChange() + "").divide(new BigDecimal(stockRestPojoNew.getPreclose() + ""), 4, 2))) : 0)+"");
|
|
|
|
|
|
|
|
|
return stockRestPojoNew;
|