瀏覽代碼

1.风控,ws订阅 新架构 改版 —— qlm

qlm 4 年之前
父節點
當前提交
80ec4649ec

File diff suppressed because it is too large
+ 51 - 1
src/main/java/com/zx/dataservice/config/JfinalActiveRecordConfig.java


+ 8 - 2
src/main/java/com/zx/dataservice/controller/CallBackController.java

@@ -1,9 +1,9 @@
 package com.zx.dataservice.controller;
 
-import com.alibaba.fastjson.JSON;
 import com.jfinal.plugin.activerecord.Db;
 import com.jfinal.plugin.activerecord.Record;
-import com.zx.dataservice.utils.ZXOptions;
+import com.zx.dataservice.options.WSOptions;
+import com.zx.dataservice.options.ZXOptions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Controller;
@@ -83,6 +83,12 @@ public class CallBackController {
             for (Record record:records) {
                 ZXOptions.set(record.getStr("config_key"),record.getStr("config_value"));
             }
+
+            List<Record> recordws = Db.use("gp").find("select key,value from ws_config ");
+            for (Record record:recordws) {
+                WSOptions.set(record.getStr("key"),record.getStr("value"));
+            }
+
             System.out.println(ZXOptions.get("ws.key"));
         } catch (Exception e) {
             if(e.toString().length()>500){                LOG.error(e.toString().substring(0,450));            }else {                LOG.error(e.toString());            }

+ 25 - 2
src/main/java/com/zx/dataservice/controller/WebSocketController.java

@@ -4,7 +4,9 @@ package com.zx.dataservice.controller;
  * Created by qlm on 2020-12-14.
  */
 
+import com.zx.dataservice.options.WSOptions;
 import com.zx.dataservice.utils.DateUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Component;
 
 import javax.websocket.*;
@@ -165,9 +167,7 @@ public class WebSocketController {
 
         try{
             // 数据服务器 id   :
-
             Session session = map.get( id);               //发送消息给对方
-
             if(session!=null&&session.isOpen()){
                 synchronized(session){
                     if(session.isOpen()){
@@ -179,5 +179,28 @@ public class WebSocketController {
             e.printStackTrace();
         }
     }
+    /**
+     *根据订阅发送消息
+     */
+    public static void sendSysMsgType(String type ,String  xMessage){
+        try{
+            for(String key:map.keySet()){
+                Session session = map.get(key);
+                if(session!=null&&session.isOpen()&& StringUtils.isNotBlank(WSOptions.get(key))){
+                    if(WSOptions.get(key).toLowerCase().equals("ALL".toLowerCase())||WSOptions.get(key).toLowerCase().equals(type.toLowerCase())){ // 推送所有
+                        synchronized(session){
+                            if(session.isOpen()){
+                                session.getBasicRemote().sendText(xMessage);
+                            }
+                        }
+                    }
+                }else { // 如果对方不是自己人 就删除
+                    map.remove(key);
+                }
+            }
+        }catch(IOException e) {
+            e.printStackTrace();
+        }
+    }
 
 }

+ 184 - 0
src/main/java/com/zx/dataservice/options/DataOptions.java

@@ -0,0 +1,184 @@
+/**
+ * Copyright (c) 2016-2019, Michael Yang 杨福海 (fuhai999@gmail.com).
+ * <p>
+ * Licensed under the GNU Lesser General Public License (LGPL) ,Version 3.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.gnu.org/licenses/lgpl-3.0.txt
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.zx.dataservice.options;
+
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * 风控 一些常量 配置
+ * 风控_config 表
+ * 2020-12-27
+ *  by qlm
+ */
+public class DataOptions {
+
+    private static Logger LOG = LoggerFactory.getLogger(DataOptions.class);
+
+    private static OptionStore store = new OptionStore() {
+        private final ConcurrentHashMap<String, String> cache = new ConcurrentHashMap<>();
+
+        @Override
+        public String get(String key) {
+            return cache.get(key);
+        }
+
+        @Override
+        public void put(String key, String value) {
+            if (StringUtils.isBlank(value)) {
+                remove(key);
+            } else {
+                cache.put(key, value);
+            }
+        }
+
+        @Override
+        public void remove(String key) {
+            cache.remove(key);
+        }
+
+        public ConcurrentHashMap.KeySetView<String, String> keySet() {
+            return cache.keySet();
+        }
+    };
+
+
+    private static List<OptionChangeListener> LISTENERS = new ArrayList<>();
+
+    public static void set(String key, String value) {
+        if (StringUtils.isBlank(key)) {
+            return;
+        }
+        String oldValue = store.get(key);
+        if (Objects.equals(value, oldValue)) {
+            return;
+        }
+        store.put(key, value);
+        for (OptionChangeListener listener : LISTENERS) {
+            try {
+                listener.onChanged(key, value, oldValue);
+            } catch (Throwable ex) {
+                LOG.error(ex.toString(), ex);
+            }
+        }
+        doFinishedChanged(key, value, oldValue);
+    }
+
+    public static String get(String key) {
+        return store.get(key);
+    }
+
+
+
+
+    public static String get(String key, String defaultvalue) {
+        String v = get(key);
+        return StringUtils.isBlank(v) ? defaultvalue : v;
+    }
+
+    public static  ConcurrentHashMap.KeySetView<String, String> keySet() {
+        return store.keySet();
+    }
+
+    public static boolean getAsBool(String key) {
+        return Boolean.parseBoolean(store.get(key));
+    }
+
+
+
+    public static boolean isTrueOrNull(String key) {
+        String data = get(key);
+        return data == null || "true".equals(data);
+    }
+
+    public static int getAsInt(String key, int defaultValue) {
+        String value = get(key);
+        if (StringUtils.isBlank(value)) {
+            return defaultValue;
+        }
+        try {
+            return Integer.parseInt(value);
+        } catch (Exception ex) {
+            LOG.warn(ex.toString(), ex);
+            return defaultValue;
+        }
+    }
+
+    public static float getAsFloat(String key, float defaultValue) {
+        String value = get(key);
+        if (StringUtils.isBlank(value)) {
+            return defaultValue;
+        }
+        try {
+            return Float.parseFloat(value);
+        } catch (Exception ex) {
+            LOG.warn(ex.toString(), ex);
+            return defaultValue;
+        }
+    }
+
+    public static void addListener(OptionChangeListener listener) {
+        LISTENERS.add(listener);
+    }
+
+    public static void removeListener(OptionChangeListener listener) {
+        LISTENERS.remove(listener);
+    }
+
+
+    public static interface OptionChangeListener {
+        public void onChanged(String key, String newValue, String oldValue);
+    }
+
+
+    private static void doFinishedChanged(String key, String value, String oldValue) {
+
+
+    }
+
+    private static boolean fakeStaticEnable = false;
+    private static String fakeStaticSuffix = "";
+
+    public static String getAppUrlSuffix() {
+        return fakeStaticEnable
+                ? (StringUtils.isBlank(fakeStaticSuffix) ? "" : fakeStaticSuffix)
+                : "";
+    }
+
+    public static OptionStore getStore() {
+        return store;
+    }
+
+
+    public static interface OptionStore {
+
+        public String get(String key);
+
+        public void put(String key, String value);
+
+        public void remove(String key);
+
+        public ConcurrentHashMap.KeySetView<String, String> keySet();
+
+    }
+}

+ 170 - 0
src/main/java/com/zx/dataservice/options/WSOptions.java

@@ -0,0 +1,170 @@
+/**
+ * Copyright (c) 2016-2019, Michael Yang 杨福海 (fuhai999@gmail.com).
+ * <p>
+ * Licensed under the GNU Lesser General Public License (LGPL) ,Version 3.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.gnu.org/licenses/lgpl-3.0.txt
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.zx.dataservice.options;
+
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * ws 一些常量 配置
+ * ws_config 表
+ * 2020-12-27
+ *  by qlm
+ */
+public class WSOptions {
+
+    private static Logger LOG = LoggerFactory.getLogger(WSOptions.class);
+
+    private static OptionStore store = new OptionStore() {
+        private final ConcurrentHashMap<String, String> cache = new ConcurrentHashMap<>();
+
+        @Override
+        public String get(String key) {
+            return cache.get(key);
+        }
+
+        @Override
+        public void put(String key, String value) {
+            if (StringUtils.isBlank(value)) {
+                remove(key);
+            } else {
+                cache.put(key, value);
+            }
+        }
+
+        @Override
+        public void remove(String key) {
+            cache.remove(key);
+        }
+    };
+
+    private static List<OptionChangeListener> LISTENERS = new ArrayList<>();
+
+    public static void set(String key, String value) {
+        if (StringUtils.isBlank(key)) {
+            return;
+        }
+        String oldValue = store.get(key);
+        if (Objects.equals(value, oldValue)) {
+            return;
+        }
+        store.put(key, value);
+        for (OptionChangeListener listener : LISTENERS) {
+            try {
+                listener.onChanged(key, value, oldValue);
+            } catch (Throwable ex) {
+                LOG.error(ex.toString(), ex);
+            }
+        }
+        doFinishedChanged(key, value, oldValue);
+    }
+
+    public static String get(String key) {
+        return store.get(key);
+    }
+
+    public static String get(String key, String defaultvalue) {
+        String v = get(key);
+        return StringUtils.isBlank(v) ? defaultvalue : v;
+    }
+
+    public static boolean getAsBool(String key) {
+        return Boolean.parseBoolean(store.get(key));
+    }
+
+
+
+    public static boolean isTrueOrNull(String key) {
+        String data = get(key);
+        return data == null || "true".equals(data);
+    }
+
+    public static int getAsInt(String key, int defaultValue) {
+        String value = get(key);
+        if (StringUtils.isBlank(value)) {
+            return defaultValue;
+        }
+        try {
+            return Integer.parseInt(value);
+        } catch (Exception ex) {
+            LOG.warn(ex.toString(), ex);
+            return defaultValue;
+        }
+    }
+
+    public static float getAsFloat(String key, float defaultValue) {
+        String value = get(key);
+        if (StringUtils.isBlank(value)) {
+            return defaultValue;
+        }
+        try {
+            return Float.parseFloat(value);
+        } catch (Exception ex) {
+            LOG.warn(ex.toString(), ex);
+            return defaultValue;
+        }
+    }
+
+    public static void addListener(OptionChangeListener listener) {
+        LISTENERS.add(listener);
+    }
+
+    public static void removeListener(OptionChangeListener listener) {
+        LISTENERS.remove(listener);
+    }
+
+
+    public static interface OptionChangeListener {
+        public void onChanged(String key, String newValue, String oldValue);
+    }
+
+
+    private static void doFinishedChanged(String key, String value, String oldValue) {
+
+
+    }
+
+    private static boolean fakeStaticEnable = false;
+    private static String fakeStaticSuffix = "";
+
+    public static String getAppUrlSuffix() {
+        return fakeStaticEnable
+                ? (StringUtils.isBlank(fakeStaticSuffix) ? "" : fakeStaticSuffix)
+                : "";
+    }
+
+    public static OptionStore getStore() {
+        return store;
+    }
+
+
+    public static interface OptionStore {
+
+        public String get(String key);
+
+        public void put(String key, String value);
+
+        public void remove(String key);
+
+    }
+}

+ 2 - 2
src/main/java/com/zx/dataservice/utils/ZXOptions.java

@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package com.zx.dataservice.utils;
+package com.zx.dataservice.options;
 
 
 import org.apache.commons.lang3.StringUtils;
@@ -37,7 +37,7 @@ public class ZXOptions {
     private static Logger LOG = LoggerFactory.getLogger(ZXOptions.class);
 
     private static OptionStore store = new OptionStore() {
-        private final Map<String, String> cache = new ConcurrentHashMap<>();
+        private final ConcurrentHashMap<String, String> cache = new ConcurrentHashMap<>();
 
         @Override
         public String get(String key) {

+ 6 - 24
src/main/java/com/zx/dataservice/service/impl/ChoiceBondServiceImpl.java

@@ -384,12 +384,8 @@ public class ChoiceBondServiceImpl implements ChoiceBondService {
 //                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
 //                    if(BuyAndSellUtils.isTransState()){
                     try{
-                        if(ZXOptions.get("ws.key")!=null){
-                            final String[] webArr = ZXOptions.get("ws.key").split(";");//websocket key
-                            for (int j = 0; j < webArr.length; j++) {
-                                new WebSocketController().sendSysMsg(webArr[j],JSON.toJSONString(subRedisList));
-                            }
-                        }
+                        new WebSocketController().sendSysMsgType("ZQ",JSON.toJSONString(subRedisList));
+
 //                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
                     }catch (Exception e){
                         log.error("插入redis错误" + e);
@@ -410,12 +406,8 @@ public class ChoiceBondServiceImpl implements ChoiceBondService {
 //                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
 //                    if(BuyAndSellUtils.isTransState()){
                     try {
-                        if(ZXOptions.get("ws.key")!=null){
-                            final String[] webArr = ZXOptions.get("ws.key").split(";");//websocket key
-                            for (int j = 0; j < webArr.length; j++) {
-                                new WebSocketController().sendSysMsg(webArr[j],JSON.toJSONString(subRedisList));
-                            }
-                        }
+                        new WebSocketController().sendSysMsgType("ZQ",JSON.toJSONString(subRedisList));
+
 //                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
                     }catch (Exception e){
                         log.error("插入redis错误" + e);
@@ -444,12 +436,7 @@ public class ChoiceBondServiceImpl implements ChoiceBondService {
 //                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
 //                    if(BuyAndSellUtils.isTransState()){
                         try{
-                            if(ZXOptions.get("ws.key")!=null){
-                                final String[] webArr = ZXOptions.get("ws.key").split(";");//websocket key
-                                for (int j = 0; j < webArr.length; j++) {
-                                    new WebSocketController().sendSysMsg(webArr[j],JSON.toJSONString(subRedisList));
-                                }
-                            }
+                            new WebSocketController().sendSysMsgType("ZQ",JSON.toJSONString(subRedisList));
 //                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
                         }catch (Exception e){
                             log.error("插入redis错误" + e);
@@ -469,12 +456,7 @@ public class ChoiceBondServiceImpl implements ChoiceBondService {
 //                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
 //                    if(BuyAndSellUtils.isTransState()){
                     try {
-                        if(ZXOptions.get("ws.key")!=null){
-                            final String[] webArr = ZXOptions.get("ws.key").split(";");//websocket key
-                            for (int j = 0; j < webArr.length; j++) {
-                                new WebSocketController().sendSysMsg(webArr[j],JSON.toJSONString(subRedisList));
-                            }
-                        }
+                        new WebSocketController().sendSysMsgType("ZQ",JSON.toJSONString(subRedisList));
 //                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
                     }catch (Exception e){
                         log.error("插入redis错误" + e);

+ 0 - 2
src/main/java/com/zx/dataservice/service/impl/ChoiceHisServiceImpl.java

@@ -3,10 +3,8 @@ package com.zx.dataservice.service.impl;
 import com.jfinal.plugin.activerecord.Db;
 import com.jfinal.plugin.activerecord.Record;
 import com.zx.dataservice.service.ChoiceHisService;
-import com.zx.dataservice.utils.DateTimeUtil;
 import com.zx.dataservice.utils.DateUtils;
 import com.zx.dataservice.utils.WorkingDayUtil;
-import com.zx.dataservice.utils.ZXOptions;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 

+ 7 - 38
src/main/java/com/zx/dataservice/service/impl/ChoiceStockServiceImpl.java

@@ -17,8 +17,6 @@ import org.springframework.stereotype.Service;
 
 import java.io.File;
 import java.math.BigDecimal;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
 import java.util.*;
 
 @Service
@@ -383,12 +381,8 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
 //                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
 //                    if(BuyAndSellUtils.isTransState()){
                     try {
-                        if(ZXOptions.get("ws.key")!=null){
-                            final String[] webArr = ZXOptions.get("ws.key").split(";");//websocket key
-                            for (int j = 0; j < webArr.length; j++) {
-                                new WebSocketController().sendSysMsg(webArr[j],JSON.toJSONString(subRedisList));
-                            }
-                        }
+                        new WebSocketController().sendSysMsgType("GP",JSON.toJSONString(subRedisList));
+
 //                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
                     }catch (Exception e){
                         log.error("插入redis错误" + e);
@@ -409,12 +403,7 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
 //                   HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
 //                    if(BuyAndSellUtils.isTransState()){
                     try {
-                        if(ZXOptions.get("ws.key")!=null){
-                            final String[] webArr = ZXOptions.get("ws.key").split(";");//websocket key
-                            for (int j = 0; j < webArr.length; j++) {
-                                new WebSocketController().sendSysMsg(webArr[j],JSON.toJSONString(subRedisList));
-                            }
-                        }
+                        new WebSocketController().sendSysMsgType("GP",JSON.toJSONString(subRedisList));
 //                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
                     }catch (Exception e){
                         log.error("插入redis错误" + e);
@@ -446,12 +435,7 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
 //                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
 //                    if(BuyAndSellUtils.isTransState()){
                     try {
-                        if(ZXOptions.get("ws.key")!=null){
-                            final String[] webArr = ZXOptions.get("ws.key").split(";");//websocket key
-                            for (int j = 0; j < webArr.length; j++) {
-                                new WebSocketController().sendSysMsg(webArr[j],JSON.toJSONString(subRedisList));
-                            }
-                        }
+                        new WebSocketController().sendSysMsgType("GP",JSON.toJSONString(subRedisList));
 //                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
                     }catch (Exception e){
                         log.error("插入redis错误" + e);
@@ -473,12 +457,7 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
 //                   HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
 //                    if(BuyAndSellUtils.isTransState()){
                     try {
-                        if(ZXOptions.get("ws.key")!=null){
-                            final String[] webArr = ZXOptions.get("ws.key").split(";");//websocket key
-                            for (int j = 0; j < webArr.length; j++) {
-                                new WebSocketController().sendSysMsg(webArr[j],JSON.toJSONString(subRedisList));
-                            }
-                        }
+                        new WebSocketController().sendSysMsgType("GP",JSON.toJSONString(subRedisList));
 //                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
                     }catch (Exception e){
                         log.error("插入redis错误" + e);
@@ -669,12 +648,7 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
 //                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
 //                    if(BuyAndSellUtils.isTransState()){
                     try {
-                        if(ZXOptions.get("ws.key")!=null){
-                            final String[] webArr = ZXOptions.get("ws.key").split(";");//websocket key
-                            for (int j = 0; j < webArr.length; j++) {
-                                new WebSocketController().sendSysMsg(webArr[j],JSON.toJSONString(subRedisList));
-                            }
-                        }
+                        new WebSocketController().sendSysMsgType("GP",JSON.toJSONString(subRedisList));
 //                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
                     }catch (Exception e){
                         log.error("插入redis错误" + e);
@@ -696,12 +670,7 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
 //                   HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
 //                    if(BuyAndSellUtils.isTransState()){
                     try {
-                        if(ZXOptions.get("ws.key")!=null){
-                            final String[] webArr = ZXOptions.get("ws.key").split(";");//websocket key
-                            for (int j = 0; j < webArr.length; j++) {
-                                new WebSocketController().sendSysMsg(webArr[j],JSON.toJSONString(subRedisList));
-                            }
-                        }
+                        new WebSocketController().sendSysMsgType("GP",JSON.toJSONString(subRedisList));
 //                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
                     }catch (Exception e){
                         log.error("插入redis错误" + e);

+ 51 - 27
src/main/java/com/zx/dataservice/service/impl/ChoiceTempIndexServiceImpl.java

@@ -3,6 +3,7 @@ package com.zx.dataservice.service.impl;
 import com.alibaba.fastjson.JSON;
 import com.zx.dataservice.controller.WebSocketController;
 import com.zx.dataservice.mapper1.ChoiceStockMapper;
+import com.zx.dataservice.options.DataOptions;
 import com.zx.dataservice.pojo.StockRestPojo;
 import com.zx.dataservice.service.ChoiceTempIndexService;
 import com.zx.dataservice.utils.*;
@@ -49,9 +50,15 @@ 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: DataOptions.keySet()){  // 所有的需要风控的 客户
+            mapws.put("stockRestRedisVO_"+key,new ArrayList<>());
+        }
         StockRestPojo stockRestPojo;
         StockRestVO stockRestVO;
         StockRestRedisVO stockRestRedisVO;
+
         for (File file : files){
             // 2.移动文件去另外一个文件夹
                 FileTempIndexUtil.moveFile(sourceFileUrl + File.separator + file.getName(), goalFileUrl);
@@ -186,7 +193,25 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
                         stockRestRedisVO.setHcrate(stockRestPojo.getPctchange());
                         stockRestRedisVO.setHighlimit(stockRestPojo.getHighlimit());
                         stockRestRedisVO.setLowlimit(stockRestPojo.getLowlimit());
-                        stockRestRedisVOList.add(stockRestRedisVO);
+//                        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);
+                            }
+                        }
+
+
                     }
                 }catch (Exception e){
                     log.error("错误数据导致失败" + e);
@@ -195,7 +220,7 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
             map = null;
         }
         // 5.入库
-        insertList(stockRestPojoList, stockRestVOList, stockRestRedisVOList,type);
+        insertList(stockRestPojoList, stockRestVOList, mapws,type);
         stockRestPojoList = null;
     }
 
@@ -377,12 +402,7 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
 //                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
 //                    if(BuyAndSellUtils.isTransState()){
                     try {
-                        if(ZXOptions.get("ws.key")!=null){
-                            final String[] webArr = ZXOptions.get("ws.key").split(";");//websocket key
-                            for (int j = 0; j < webArr.length; j++) {
-                                new WebSocketController().sendSysMsg(webArr[j],JSON.toJSONString(subRedisList));
-                            }
-                        }
+                        new WebSocketController().sendSysMsgType("ZS",JSON.toJSONString(subRedisList));
 //                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
                     }catch (Exception e){
                         log.error("插入redis错误" + e);
@@ -403,12 +423,7 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
 //                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
 //                    if(BuyAndSellUtils.isTransState()){
                     try {
-                        if(ZXOptions.get("ws.key")!=null){
-                            final String[] webArr = ZXOptions.get("ws.key").split(";");//websocket key
-                            for (int j = 0; j < webArr.length; j++) {
-                                new WebSocketController().sendSysMsg(webArr[j],JSON.toJSONString(subRedisList));
-                            }
-                        }
+                        new WebSocketController().sendSysMsgType("ZS",JSON.toJSONString(subRedisList));
 //                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
                     }catch (Exception e){
                         log.error("插入redis错误" + e);
@@ -420,7 +435,7 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
         }
     }
 
-    private void insertList(List<StockRestPojo> list, List<StockRestVO> stockRestVOList, List<StockRestRedisVO> stockRestRedisVOList,String type) {
+    private void insertList(List<StockRestPojo> list, List<StockRestVO> stockRestVOList,Map<String,List<StockRestRedisVO>>mapws ,String type) { // List<StockRestRedisVO> stockRestRedisVOList
         int insertLength = list.size();
         int i = 0;
         int insertSize = 500;
@@ -440,12 +455,7 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
 //                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
 //                    if(BuyAndSellUtils.isTransState()){
                     try {
-                        if(ZXOptions.get("ws.key")!=null){
-                            final String[] webArr = ZXOptions.get("ws.key").split(";");//websocket key
-                            for (int j = 0; j < webArr.length; j++) {
-                                new WebSocketController().sendSysMsg(webArr[j],JSON.toJSONString(subRedisList));
-                            }
-                        }
+                        new WebSocketController().sendSysMsgType("ZS",JSON.toJSONString(subRedisList));
 //                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
                     }catch (Exception e){
                         log.error("插入redis错误" + e);
@@ -469,12 +479,7 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
 //                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
 //                    if(BuyAndSellUtils.isTransState()){
                     try {
-                        if(ZXOptions.get("ws.key")!=null){
-                            final String[] webArr = ZXOptions.get("ws.key").split(";");//websocket key
-                            for (int j = 0; j < webArr.length; j++) {
-                                new WebSocketController().sendSysMsg(webArr[j],JSON.toJSONString(subRedisList));
-                            }
-                        }
+                        new WebSocketController().sendSysMsgType("ZS",JSON.toJSONString(subRedisList));
 //                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
                     }catch (Exception e){
                         log.error("插入redis错误" + e);
@@ -485,4 +490,23 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
             thread.start();
         }
     }
+
+
+    public StockRestPojo getRiskNow (StockRestPojo stockRestPojo,String key,String value){
+        // KEY =  code _ hy // BTC_hy
+        String [] valueArr = value.split("&");  //tocode & mini & risk & multiples & status
+        if("1".equals(valueArr[4])){ // 如果此时没有开启风控 那么不变化
+            StringBuffer tableName = new StringBuffer("data_rt_");
+            tableName.append(valueArr[0].replace(".", "_").toLowerCase());
+
+            stockRestPojo.setTableName(tableName.toString());
+            return stockRestPojo;
+        }else {
+            StockRestPojo stockRestPojoNew = new StockRestPojo();
+
+
+            return stockRestPojoNew;
+        }
+    }
+
 }