Bladeren bron

1.websocket 订阅
3.推送—— qlm

qlm 4 jaren geleden
bovenliggende
commit
e94c4e8948

+ 1 - 0
src/main/java/com/zx/dataservice/config/JfinalActiveRecordConfig.java

@@ -171,6 +171,7 @@ public class JfinalActiveRecordConfig implements ApplicationRunner {
             Thread.sleep(1000);
         }
         ZXOptions.set("run","true");
+        ZXOptions.set("isold","false"); // 是否推送
 
     }
 

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

@@ -2,17 +2,25 @@ package com.zx.dataservice.controller;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.jfinal.plugin.activerecord.Db;
 import com.jfinal.plugin.activerecord.Record;
 import com.zx.dataservice.config.ActiveConfig;
+import com.zx.dataservice.options.DataOptions;
 import com.zx.dataservice.options.WSOptions;
 import com.zx.dataservice.options.ZXOptions;
+import com.zx.dataservice.pojo.StockRestPojo;
 import com.zx.dataservice.redismessage.util.RedisUtil;
 import com.zx.dataservice.service.ChoiceHisService;
+import com.zx.dataservice.service.ChoiceService;
+import com.zx.dataservice.utils.DateUtils;
+import com.zx.dataservice.vo.StockRestRedisVO;
+import com.zx.dataservice.vo.StockRestVO;
 import com.zx.dataservice.vo.StockVO;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -22,6 +30,8 @@ import org.springframework.web.bind.annotation.ResponseBody;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
 
 @Controller
 @RequestMapping({"/admin/"})
@@ -32,6 +42,12 @@ public class CallBackController {
     @Autowired
     private ChoiceHisService choiceHisService;
 
+    @Autowired
+    private RedisUtil redisUtil;
+
+    @Autowired
+    private ChoiceService choiceService;
+
     @GetMapping("/t1")
     @ResponseBody
     public String quantCallBack(String code){
@@ -148,6 +164,29 @@ public class CallBackController {
         }
         return true;
     }
+    @GetMapping("/tows")
+    @ResponseBody
+    public boolean tows(String code){
+        try {
+            ZXOptions.set("isold",code);
+        } catch (Exception e) {
+            if(e.toString().length()>500){                LOG.error(e.toString().substring(0,450));            }else {                LOG.error(e.toString());            }
+        }
+        return true;
+    }
+
+
+
+    @GetMapping("/sendws")
+    @ResponseBody
+    public boolean sendws(String code){
+        try {
+            choiceService.analysisDataTask();
+        } catch (Exception e) {
+            if(e.toString().length()>500){                LOG.error(e.toString().substring(0,450));            }else {                LOG.error(e.toString());            }
+        }
+        return true;
+    }
 
     @GetMapping("/showWs")
     @ResponseBody
@@ -160,8 +199,7 @@ public class CallBackController {
         }
         return s;
     }
-    @Autowired
-    private RedisUtil redisUtil;
+
 
     @RequestMapping({"showRedis.do"})
     @ResponseBody
@@ -195,8 +233,262 @@ public class CallBackController {
         return redisData;
     }
 
+    private int randomInt() {
+        int max = 10000;
+        int min = 5000;
+        int ran = (int) (Math.random() * (max - min) + min);
+        return ran;
+    }
+    @GetMapping("/testr")
+    @ResponseBody
+    public String testr(String key1){
+
+        String redisKeystock = String.format("stock");
+        List<String> itemLikeListstock = redisUtil.getItemLikeList(redisKeystock);
+//        List<StockVO> stockRedisListStock = new ArrayList<>();
+        ConcurrentHashMap<String, StockVO> stockRedisListStock = new ConcurrentHashMap<>();
+        for (String str:itemLikeListstock) {
+            StockVO stockVO = JSONObject.parseObject(str, StockVO.class);
+            stockRedisListStock.put(stockVO.getCode(),stockVO);
+        }
+        String redisKeybond = String.format("bond");
+        List<String> itemLikeListbond = redisUtil.getItemLikeList(redisKeybond);
+//        List<StockVO> stockRedisListBond = new ArrayList<>();
+        ConcurrentHashMap<String, StockVO> stockRedisListBond = new ConcurrentHashMap<>();
+        for (String str:itemLikeListbond) {
+            StockVO stockVO = JSONObject.parseObject(str, StockVO.class);
+            stockRedisListBond.put(stockVO.getCode(),stockVO);
+        }
+        for (String key2 : WSOptions.keySet()) {
+            if(!(new WebSocketController().showWs("").contains(key2+";"))){ // 只推送在线的服务器 加符号 是 防止 类似的key
+                continue;
+            }
+//            List<StockVO> stockRedisListALL = new ArrayList<>();
+            ConcurrentHashMap<String, StockVO> stockRedisListALL = new ConcurrentHashMap<>();
+
+            if(WSOptions.get(key2).split("_")[1].toLowerCase().contains("gp")&&(!WSOptions.get(key2).split("_")[1].toLowerCase().contains("ALL".toLowerCase()))){
+                stockRedisListALL.putAll(stockRedisListStock);
+            }
+            if(WSOptions.get(key2).split("_")[1].toLowerCase().contains("zq")&&(!WSOptions.get(key2).split("_")[1].toLowerCase().contains("ALL".toLowerCase()))){
+                stockRedisListALL.putAll(stockRedisListBond);
+            }
+            if(WSOptions.get(key2).split("_")[1].toLowerCase().contains("zs")||WSOptions.get(key2).split("_")[1].toLowerCase().contains("ALL".toLowerCase())) {
+                String redisKeyindex = "index_" + WSOptions.get(key2).split("_")[0] + "_";  // 对应的风控 redis  index_sl_XXX.SH
+                List<String> itemLikeListindexk = redisUtil.getItemLikeList(redisKeyindex);
+//                List<StockVO> stockRedisListWS = new ArrayList<>();
+                ConcurrentHashMap<String, StockVO> stockRedisListWS = new ConcurrentHashMap<>();
+                for (String str : itemLikeListindexk) {
+                    StockVO stockVO = JSONObject.parseObject(str, StockVO.class);
+                    stockRedisListWS.put(stockVO.getCode(),stockVO);
+                }
+                stockRedisListALL.putAll(stockRedisListWS);
+            }
+            if(WSOptions.get(key2).split("_")[1].toLowerCase().contains("ALL".toLowerCase())) { // 推送所有
+                stockRedisListALL.putAll(stockRedisListStock);
+                stockRedisListALL.putAll(stockRedisListBond);
+            }
+            new WebSocketController().sendSysMsg(key2, JSON.toJSONString(stockRedisListALL));
+        }
+
+        return "true" ;
+    }
+
+
+    @GetMapping("/testq")
+    @ResponseBody
+    public boolean testq(String key1){
+        try {
+            redisUtil.deleteItemLike("stock");
+            redisUtil.deleteItemLike("bond");
+            redisUtil.deleteItemLike("index");
+            List<Record> records = Db.find("select id,stock_code from stock where stock_or_bond = 0  and stock_plate <>'5' ");
+            List<Record> recordsb = Db.find("select id,stock_code from stock where stock_or_bond = 1 ");
+            List<Record> recordsi = Db.find("select id,stock_code from stock where stock_or_bond = 0  and stock_plate = '5' ");
+
+            for (int ii = 10; ii < 20; ii++) {
+
+                System.out.println("操作开始**"+DateUtils.getCurrentTimeSSS()+"**");
+                int i = 10000 ;
+                for (Record r:records) {
+                    i++;
+                    StockRestRedisVO stockRestRedisVO = new StockRestRedisVO();
+                    stockRestRedisVO.setCode(r.getStr("stock_code").toUpperCase());
+                    stockRestRedisVO.setNowPrice(ii+""+i+"");
+                    stockRestRedisVO.setChange(ii+""+i+"");
+                    stockRestRedisVO.setHcrate(ii+""+i+"");
+
+                    stockRestRedisVO.setHighlimit(ii+""+i+"");
+                    stockRestRedisVO.setLowlimit(ii+""+i+"");
+
+
+                    stockRestRedisVO.setBuy1(ii+""+i+"");
+                    stockRestRedisVO.setBuy2(ii+""+i+"");
+                    stockRestRedisVO.setBuy3(ii+""+i+"");
+                    stockRestRedisVO.setBuy4(ii+""+i+"");
+                    stockRestRedisVO.setBuy5(ii+""+i+"");
+
+                    stockRestRedisVO.setSell1(ii+""+i+"");
+                    stockRestRedisVO.setSell2(ii+""+i+"");
+                    stockRestRedisVO.setSell3(ii+""+i+"");
+                    stockRestRedisVO.setSell4(ii+""+i+"");
+                    stockRestRedisVO.setSell5(ii+""+i+"");
+
+                    stockRestRedisVO.setBuy1_num(ii+""+i+"");
+                    stockRestRedisVO.setBuy2_num(ii+""+i+"");
+                    stockRestRedisVO.setBuy3_num(ii+""+i+"");
+                    stockRestRedisVO.setBuy4_num(ii+""+i+"");
+                    stockRestRedisVO.setBuy5_num(ii+""+i+"");
+
+                    stockRestRedisVO.setSell1_num(ii+""+i+"");
+                    stockRestRedisVO.setSell2_num(ii+""+i+"");
+                    stockRestRedisVO.setSell3_num(ii+""+i+"");
+                    stockRestRedisVO.setSell4_num(ii+""+i+"");
+                    stockRestRedisVO.setSell5_num(ii+""+i+"");
+                    redisUtil.saveItem("stock_"+r.get("stock_code"),JSON.toJSONString(stockRestRedisVO), 10, TimeUnit.DAYS);
+                }
+
+                int j = 10000 ;
+                for (Record r:recordsb) {
+                    j++;
+                    StockRestRedisVO stockRestRedisVO = new StockRestRedisVO();
+                    stockRestRedisVO.setCode(r.getStr("stock_code").toUpperCase());
+                    stockRestRedisVO.setNowPrice(ii+""+j+"");
+                    stockRestRedisVO.setChange(ii+""+j+"");
+                    stockRestRedisVO.setHcrate(ii+""+j+"");
+
+                    stockRestRedisVO.setHighlimit(ii+""+j+"");
+                    stockRestRedisVO.setLowlimit(ii+""+j+"");
+
+
+                    stockRestRedisVO.setBuy1(ii+""+j+"");
+                    stockRestRedisVO.setBuy2(ii+""+j+"");
+                    stockRestRedisVO.setBuy3(ii+""+j+"");
+                    stockRestRedisVO.setBuy4(ii+""+j+"");
+                    stockRestRedisVO.setBuy5(ii+""+j+"");
+
+                    stockRestRedisVO.setSell1(ii+""+j+"");
+                    stockRestRedisVO.setSell2(ii+""+j+"");
+                    stockRestRedisVO.setSell3(ii+""+j+"");
+                    stockRestRedisVO.setSell4(ii+""+j+"");
+                    stockRestRedisVO.setSell5(ii+""+j+"");
+
+                    stockRestRedisVO.setBuy1_num(ii+""+j+"");
+                    stockRestRedisVO.setBuy2_num(ii+""+j+"");
+                    stockRestRedisVO.setBuy3_num(ii+""+j+"");
+                    stockRestRedisVO.setBuy4_num(ii+""+j+"");
+                    stockRestRedisVO.setBuy5_num(ii+""+j+"");
+
+                    stockRestRedisVO.setSell1_num(ii+""+j+"");
+                    stockRestRedisVO.setSell2_num(ii+""+j+"");
+                    stockRestRedisVO.setSell3_num(ii+""+j+"");
+                    stockRestRedisVO.setSell4_num(ii+""+j+"");
+                    stockRestRedisVO.setSell5_num(ii+""+j+"");
+                    redisUtil.saveItem("bond_"+r.get("stock_code"),JSON.toJSONString(stockRestRedisVO), 10, TimeUnit.DAYS);
+                }
+
+                int k = 10000 ;
+                for (Record r:recordsi) {
+                    k++;
+                    StockRestRedisVO stockRestRedisVO = new StockRestRedisVO();
+                    stockRestRedisVO.setCode(r.getStr("stock_code").toUpperCase());
+                    stockRestRedisVO.setNowPrice(ii+""+k + "");
+                    stockRestRedisVO.setChange(ii+""+k + "");
+                    stockRestRedisVO.setHcrate(ii+""+k + "");
+
+                    stockRestRedisVO.setHighlimit(ii+""+k + "");
+                    stockRestRedisVO.setLowlimit(ii+""+k + "");
+
+
+                    stockRestRedisVO.setBuy1(ii+""+k + "");
+                    stockRestRedisVO.setBuy2(ii+""+k + "");
+                    stockRestRedisVO.setBuy3(ii+""+k + "");
+                    stockRestRedisVO.setBuy4(ii+""+k + "");
+                    stockRestRedisVO.setBuy5(ii+""+k + "");
+
+                    stockRestRedisVO.setSell1(ii+""+k + "");
+                    stockRestRedisVO.setSell2(ii+""+k + "");
+                    stockRestRedisVO.setSell3(ii+""+k + "");
+                    stockRestRedisVO.setSell4(ii+""+k + "");
+                    stockRestRedisVO.setSell5(ii+""+k + "");
+
+                    stockRestRedisVO.setBuy1_num(ii+""+k + "");
+                    stockRestRedisVO.setBuy2_num(ii+""+k + "");
+                    stockRestRedisVO.setBuy3_num(ii+""+k + "");
+                    stockRestRedisVO.setBuy4_num(ii+""+k + "");
+                    stockRestRedisVO.setBuy5_num(ii+""+k + "");
+
+                    stockRestRedisVO.setSell1_num(ii+""+k + "");
+                    stockRestRedisVO.setSell2_num(ii+""+k + "");
+                    stockRestRedisVO.setSell3_num(ii+""+k + "");
+                    stockRestRedisVO.setSell4_num(ii+""+k + "");
+                    stockRestRedisVO.setSell5_num(ii+""+k + "");
+
+                    int f = 0;
+                    for (String key2 : WSOptions.keySet()) {  // 所有的需要推送的客户
+                        // 如果该股票需要风控
+                        if (DataOptions.get("keyall").contains((WSOptions.get(key2).split("_")[0] + "_" + stockRestRedisVO.getCode().toUpperCase()))) {  // 存在该用户的该股票的风控 记录
+                            for (String key : DataOptions.keySet()) {  // 所有的需要风控的 客户  BTC_BTC_hy  LTC_hy  000001.SZ_hy  LTC_test  test_BTC_BTC
+                                // 风控 逻辑
+                                if ("keyall".equals(key)) {
+                                    continue;
+                                }
+                                if (key.contains((WSOptions.get(key2).split("_")[0] + "_" + stockRestRedisVO.getCode().toUpperCase()))) {// 存在该股票的风控  LTC_hy . contains (LTC)
+                                    f++;
+                                    StockRestRedisVO stockRestRedisVOf = new StockRestRedisVO();
+                                    stockRestRedisVOf.setCode(stockRestRedisVO.getCode());
+                                    stockRestRedisVOf.setNowPrice(ii+""+k + "999"+f);
+                                    stockRestRedisVOf.setChange(ii+""+k + "999"+f);
+                                    stockRestRedisVOf.setHcrate(ii+""+k + "999"+f);
+                                    stockRestRedisVOf.setHighlimit(ii+""+k + "999"+f);
+                                    stockRestRedisVOf.setLowlimit(ii+""+k + "999"+f);
+
+                                    stockRestRedisVOf.setBuy1(ii+""+k + "999"+f);
+                                    stockRestRedisVOf.setBuy2(ii+""+k + "999"+f);
+                                    stockRestRedisVOf.setBuy3(ii+""+k + "999"+f);
+                                    stockRestRedisVOf.setBuy4(ii+""+k + "999"+f);
+                                    stockRestRedisVOf.setBuy5(ii+""+k + "999"+f);
+
+                                    stockRestRedisVOf.setSell1(ii+""+k + "999"+f);
+                                    stockRestRedisVOf.setSell2(ii+""+k + "999"+f);
+                                    stockRestRedisVOf.setSell3(ii+""+k + "999"+f);
+                                    stockRestRedisVOf.setSell4(ii+""+k + "999"+f);
+                                    stockRestRedisVOf.setSell5(ii+""+k + "999"+f);
+
+                                    stockRestRedisVOf.setBuy1_num(ii+""+k + "999"+f);
+                                    stockRestRedisVOf.setBuy2_num(ii+""+k + "999"+f);
+                                    stockRestRedisVOf.setBuy3_num(ii+""+k + "999"+f);
+                                    stockRestRedisVOf.setBuy4_num(ii+""+k + "999"+f);
+                                    stockRestRedisVOf.setBuy5_num(ii+""+k + "999"+f);
+
+                                    stockRestRedisVOf.setSell1_num(ii+""+k + "999"+f);
+                                    stockRestRedisVOf.setSell2_num(ii+""+k + "999"+f);
+                                    stockRestRedisVOf.setSell3_num(ii+""+k + "999"+f);
+                                    stockRestRedisVOf.setSell4_num(ii+""+k + "999"+f);
+                                    stockRestRedisVOf.setSell5_num(ii+""+k + "999"+f);
+
+                                    redisUtil.saveItem("index_" + WSOptions.get(key2).split("_")[0] + "_" + r.get("stock_code"), JSON.toJSONString(stockRestRedisVOf), 10, TimeUnit.DAYS);
+                                    break;
+                                }
+                            }
+                        } else {
+                            redisUtil.saveItem("index_" + WSOptions.get(key2).split("_")[0] + "_" + r.get("stock_code"), JSON.toJSONString(stockRestRedisVO), 10, TimeUnit.DAYS);
+
+                        }
+
+                    }
+                }
+                System.out.println("操作结束**"+DateUtils.getCurrentTimeSSS()+"**"+k);
+                Thread.sleep(1000);
+            }
 
 
+        } catch (Exception e) {
+            if(e.toString().length()>500){                LOG.error(e.toString().substring(0,450));            }else {                LOG.error(e.toString());            }
+        }
+
+        return true;
+    }
+
 
     @GetMapping("/remMap")
     @ResponseBody

+ 32 - 0
src/main/java/com/zx/dataservice/redismessage/util/RedisUtil.java

@@ -46,6 +46,8 @@ public class RedisUtil {
         this.redisTemplate.opsForValue().set(redisKey, redisValue);
     }
 
+
+
     /**
      * 保存指定时间有效的键值对
      *
@@ -69,6 +71,25 @@ public class RedisUtil {
     }
 
     /**
+     * 获取LIKE key的值
+     * @param redisKey
+     */
+    public String getItemLike(String redisKey) {
+        Set<String> keys = redisTemplate.keys(redisKey + "*");
+        StringBuffer s = new StringBuffer("");
+        for (String k : keys) {
+            s.append(this.redisTemplate.opsForValue().get(k));
+        }
+        return  s.toString();
+    }
+    public List<String> getItemLikeList(String redisKey) {
+        Set<String> keys = redisTemplate.keys(redisKey + "*");
+        List<String> stringList = redisTemplate.opsForValue().multiGet(keys);
+        return  stringList;
+    }
+
+
+    /**
      * 获取符合正则表达式的key的集合
      *
      * @param keyPattern
@@ -101,6 +122,17 @@ public class RedisUtil {
     }
 
     /**
+     * 删除指定的key
+     *
+     * @param redisKey
+     */
+    public void deleteItemLike(String redisKey) {
+        Set<String> keys = redisTemplate.keys(redisKey + "*");
+        this.redisTemplate.delete(keys);
+        logger.debug("remove redis key:[" + redisKey + "]");
+    }
+
+    /**
      * 删除指定的key并返回value
      *
      * @param redisKey

+ 7 - 0
src/main/java/com/zx/dataservice/service/ChoiceService.java

@@ -0,0 +1,7 @@
+package com.zx.dataservice.service;
+
+public interface ChoiceService {
+
+
+    void analysisDataTask();
+}

+ 76 - 69
src/main/java/com/zx/dataservice/service/impl/ChoiceBondServiceImpl.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
 import com.zx.dataservice.controller.WebSocketController;
 import com.zx.dataservice.mapper2.ChoiceBondMapper;
 import com.zx.dataservice.pojo.StockRestPojo;
+import com.zx.dataservice.redismessage.util.RedisUtil;
 import com.zx.dataservice.service.ChoiceBondService;
 import com.zx.dataservice.utils.*;
 import com.zx.dataservice.vo.StockRestRedisVO;
@@ -18,6 +19,7 @@ import org.springframework.stereotype.Service;
 import java.io.File;
 import java.math.BigDecimal;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 
 @Service
 public class ChoiceBondServiceImpl implements ChoiceBondService {
@@ -41,6 +43,9 @@ public class ChoiceBondServiceImpl implements ChoiceBondService {
     @Autowired
     private ChoiceBondMapper choiceBondMapper;
 
+    @Autowired
+    private RedisUtil redisUtil;
+
     @Override
     public void analysisBondRestData(String type) {
         // 1.获取文件夹文件 按照时间顺序拿到一个
@@ -215,7 +220,8 @@ public class ChoiceBondServiceImpl implements ChoiceBondService {
                         stockRestRedisVO.setSell4_num(stockRestPojo.getSellvolume4());
                         stockRestRedisVO.setSell5_num(stockRestPojo.getSellvolume5());
 
-                    stockRestRedisVOList.add(stockRestRedisVO);
+                        redisUtil.saveItem("bond_"+stockRestRedisVO.getCode(),JSON.toJSONString(stockRestRedisVO), 10, TimeUnit.DAYS);
+//                    stockRestRedisVOList.add(stockRestRedisVO);
                     }
                 }catch (Exception e){
                     log.error("错误数据导致失败" + e);
@@ -406,7 +412,8 @@ public class ChoiceBondServiceImpl implements ChoiceBondService {
                         stockRestRedisVO.setSell4_num(stockRestPojo.getSellvolume4());
                         stockRestRedisVO.setSell5_num(stockRestPojo.getSellvolume5());
 
-                        stockRestRedisVOList.add(stockRestRedisVO);
+                        redisUtil.saveItem("bond_"+stockRestRedisVO.getCode(),JSON.toJSONString(stockRestRedisVO), 10, TimeUnit.DAYS);
+//                        stockRestRedisVOList.add(stockRestRedisVO);
                     }
                 }catch (Exception e){
                     log.error("错误数据导致失败" + e);
@@ -426,48 +433,48 @@ public class ChoiceBondServiceImpl implements ChoiceBondService {
         while (insertLength > insertSize) {
 
                 choiceBondMapper.insertBatchByAfter(list.subList(i, i + insertSize));
-            List<StockRestVO> subList = stockRestVOList.subList(i, i + insertSize);
-            List<StockRestRedisVO> subRedisList = stockRestRedisVOList.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("ZQ",JSON.toJSONString(subRedisList));
-
-//                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
-                    }catch (Exception e){
-                        log.error("插入redis错误" + e);
-                    }
+//            Thread thread=new Thread(new Runnable() {
+//                @Override
+//                public void run() {
+////                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
+////                    if(BuyAndSellUtils.isTransState()){
+//                    try{
+//                        new WebSocketController().sendSysMsgType("ZQ",JSON.toJSONString(subRedisList));
+//
+////                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
+//                    }catch (Exception e){
+//                        log.error("插入redis错误" + e);
 //                    }
-                }
-            });
-            thread.start();
+////                    }
+//                }
+//            });
+//            thread.start();
         }
         if (insertLength > 0) {
 
                 choiceBondMapper.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() {
-//                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
-//                    if(BuyAndSellUtils.isTransState()){
-                    try {
-                        new WebSocketController().sendSysMsgType("ZQ",JSON.toJSONString(subRedisList));
-
-//                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
-                    }catch (Exception e){
-                        log.error("插入redis错误" + e);
-                    }
+//            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() {
+////                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
+////                    if(BuyAndSellUtils.isTransState()){
+//                    try {
+//                        new WebSocketController().sendSysMsgType("ZQ",JSON.toJSONString(subRedisList));
+//
+////                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
+//                    }catch (Exception e){
+//                        log.error("插入redis错误" + e);
 //                    }
-                }
-            });
-            thread.start();
+////                    }
+//                }
+//            });
+//            thread.start();
         }
     }
 
@@ -478,45 +485,45 @@ public class ChoiceBondServiceImpl implements ChoiceBondService {
         while (insertLength > insertSize) {
                 choiceBondMapper.insertBatch(list.subList(i, i + insertSize));
 
-            List<StockRestVO> subList = stockRestVOList.subList(i, i + insertSize);
-            List<StockRestRedisVO> subRedisList = stockRestRedisVOList.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("ZQ",JSON.toJSONString(subRedisList));
-//                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
-                        }catch (Exception e){
-                            log.error("插入redis错误" + e);
-                        }
-//                    }
-                }
-            });
-            thread.start();
+//            Thread thread=new Thread(new Runnable() {
+//                @Override
+//                public void run() {
+////                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
+////                    if(BuyAndSellUtils.isTransState()){
+//                        try{
+//                            new WebSocketController().sendSysMsgType("ZQ",JSON.toJSONString(subRedisList));
+////                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
+//                        }catch (Exception e){
+//                            log.error("插入redis错误" + e);
+//                        }
+////                    }
+//                }
+//            });
+//            thread.start();
         }
         if (insertLength > 0) {
             choiceBondMapper.insertBatch(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() {
-//                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
-//                    if(BuyAndSellUtils.isTransState()){
-                    try {
-                        new WebSocketController().sendSysMsgType("ZQ",JSON.toJSONString(subRedisList));
-//                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
-                    }catch (Exception e){
-                        log.error("插入redis错误" + e);
-                    }
+//            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() {
+////                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
+////                    if(BuyAndSellUtils.isTransState()){
+//                    try {
+//                        new WebSocketController().sendSysMsgType("ZQ",JSON.toJSONString(subRedisList));
+////                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
+//                    }catch (Exception e){
+//                        log.error("插入redis错误" + e);
 //                    }
-                }
-            });
-            thread.start();
+////                    }
+//                }
+//            });
+//            thread.start();
         }
     }
 }

+ 86 - 0
src/main/java/com/zx/dataservice/service/impl/ChoiceServiceImpl.java

@@ -0,0 +1,86 @@
+package com.zx.dataservice.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.zx.dataservice.controller.WebSocketController;
+import com.zx.dataservice.options.DataOptions;
+import com.zx.dataservice.options.WSOptions;
+import com.zx.dataservice.redismessage.util.RedisUtil;
+import com.zx.dataservice.service.ChoiceHisService;
+import com.zx.dataservice.service.ChoiceService;
+import com.zx.dataservice.utils.BigdecimalUtil;
+import com.zx.dataservice.utils.DateUtils;
+import com.zx.dataservice.utils.WorkingDayUtil;
+import com.zx.dataservice.vo.StockVO;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+@Service
+public class ChoiceServiceImpl implements ChoiceService {
+
+    @Autowired
+    private RedisUtil redisUtil;
+
+    @Override
+    public void analysisDataTask() {
+        String redisKeystock = String.format("stock");
+        List<String> itemLikeListstock = redisUtil.getItemLikeList(redisKeystock);
+//        List<StockVO> stockRedisListStock = new ArrayList<>();
+        ConcurrentHashMap<String, StockVO> stockRedisListStock = new ConcurrentHashMap<>();
+        for (String str:itemLikeListstock) {
+            StockVO stockVO = JSONObject.parseObject(str, StockVO.class);
+            stockRedisListStock.put(stockVO.getCode(),stockVO);
+        }
+        String redisKeybond = String.format("bond");
+        List<String> itemLikeListbond = redisUtil.getItemLikeList(redisKeybond);
+//        List<StockVO> stockRedisListBond = new ArrayList<>();
+        ConcurrentHashMap<String, StockVO> stockRedisListBond = new ConcurrentHashMap<>();
+        for (String str:itemLikeListbond) {
+            StockVO stockVO = JSONObject.parseObject(str, StockVO.class);
+            stockRedisListBond.put(stockVO.getCode(),stockVO);
+        }
+        for (String key2 : WSOptions.keySet()) {
+            if(!(new WebSocketController().showWs("").contains(key2+";"))){ // 只推送在线的服务器 加符号 是 防止 类似的key
+                continue;
+            }
+//            List<StockVO> stockRedisListALL = new ArrayList<>();
+            ConcurrentHashMap<String, StockVO> stockRedisListALL = new ConcurrentHashMap<>();
+
+            if(WSOptions.get(key2).split("_")[1].toLowerCase().contains("gp")&&(!WSOptions.get(key2).split("_")[1].toLowerCase().contains("ALL".toLowerCase()))){
+                stockRedisListALL.putAll(stockRedisListStock);
+            }
+            if(WSOptions.get(key2).split("_")[1].toLowerCase().contains("zq")&&(!WSOptions.get(key2).split("_")[1].toLowerCase().contains("ALL".toLowerCase()))){
+                stockRedisListALL.putAll(stockRedisListBond);
+            }
+            if(WSOptions.get(key2).split("_")[1].toLowerCase().contains("zs")||WSOptions.get(key2).split("_")[1].toLowerCase().contains("ALL".toLowerCase())) {
+                String redisKeyindex = "index_" + WSOptions.get(key2).split("_")[0] + "_";  // 对应的风控 redis  index_sl_XXX.SH
+                List<String> itemLikeListindexk = redisUtil.getItemLikeList(redisKeyindex);
+//                List<StockVO> stockRedisListWS = new ArrayList<>();
+                ConcurrentHashMap<String, StockVO> stockRedisListWS = new ConcurrentHashMap<>();
+                for (String str : itemLikeListindexk) {
+                    StockVO stockVO = JSONObject.parseObject(str, StockVO.class);
+                    stockRedisListWS.put(stockVO.getCode(),stockVO);
+                }
+                stockRedisListALL.putAll(stockRedisListWS);
+            }
+            if(WSOptions.get(key2).split("_")[1].toLowerCase().contains("ALL".toLowerCase())) { // 推送所有
+                stockRedisListALL.putAll(stockRedisListStock);
+                stockRedisListALL.putAll(stockRedisListBond);
+            }
+            if(stockRedisListALL!=null&&stockRedisListALL.size()>0){
+                new WebSocketController().sendSysMsg(key2, JSON.toJSONString(stockRedisListALL));
+            }
+        }
+
+    }
+}

+ 108 - 71
src/main/java/com/zx/dataservice/service/impl/ChoiceStockServiceImpl.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
 import com.zx.dataservice.controller.WebSocketController;
 import com.zx.dataservice.mapper1.ChoiceStockMapper;
 import com.zx.dataservice.pojo.StockRestPojo;
+import com.zx.dataservice.redismessage.util.RedisUtil;
 import com.zx.dataservice.service.ChoiceStockService;
 import com.zx.dataservice.utils.*;
 import com.zx.dataservice.vo.StockRestRedisVO;
@@ -18,6 +19,7 @@ import org.springframework.stereotype.Service;
 import java.io.File;
 import java.math.BigDecimal;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 
 @Service
 public class ChoiceStockServiceImpl implements ChoiceStockService {
@@ -40,7 +42,8 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
 
     private static final String goalFileUrlInFront = "/www/wwwroot/csqdata/stock/backup/InFront"; //盘前 备份
 
-
+    @Autowired
+    private RedisUtil redisUtil;
 
     @Autowired
     private ChoiceStockMapper choiceStockMapper;
@@ -218,7 +221,9 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
                         stockRestRedisVO.setSell4_num(stockRestPojo.getSellvolume4());
                         stockRestRedisVO.setSell5_num(stockRestPojo.getSellvolume5());
 
-                        stockRestRedisVOList.add(stockRestRedisVO);
+                        redisUtil.saveItem("stock_"+stockRestRedisVO.getCode(),JSON.toJSONString(stockRestRedisVO), 10, TimeUnit.DAYS);
+
+//                        stockRestRedisVOList.add(stockRestRedisVO);
                     }
                 }catch (Exception e){
                     log.error("错误数据导致失败" + e);
@@ -405,7 +410,9 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
                         stockRestRedisVO.setSell4_num(stockRestPojo.getSellvolume4());
                         stockRestRedisVO.setSell5_num(stockRestPojo.getSellvolume5());
 
-                        stockRestRedisVOList.add(stockRestRedisVO);
+                        redisUtil.saveItem("stock_"+stockRestRedisVO.getCode(),JSON.toJSONString(stockRestRedisVO), 10, TimeUnit.DAYS);
+
+//                        stockRestRedisVOList.add(stockRestRedisVO);
                     }
                 }catch (Exception e){
                     log.error("错误数据导致失败" + e);
@@ -424,47 +431,47 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
         int insertSize = 500;
         while (insertLength > insertSize) {
             choiceStockMapper.insertBatch(list.subList(i, i + insertSize));
-            List<StockRestVO> subList = stockRestVOList.subList(i, i + insertSize);
-            List<StockRestRedisVO> subRedisList = stockRestRedisVOList.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("GP",JSON.toJSONString(subRedisList));
-
-//                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
-                    }catch (Exception e){
-                        log.error("插入redis错误" + e);
-                    }
+//            Thread thread=new Thread(new Runnable() {
+//                @Override
+//                public void run() {
+////                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
+////                    if(BuyAndSellUtils.isTransState()){
+//                    try {
+//                        new WebSocketController().sendSysMsgType("GP",JSON.toJSONString(subRedisList));
+//
+////                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
+//                    }catch (Exception e){
+//                        log.error("插入redis错误" + e);
 //                    }
-
-                }
-            });
-            thread.start();
+////                    }
+//
+//                }
+//            });
+//            thread.start();
         }
         if (insertLength > 0) {
             choiceStockMapper.insertBatch(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() {
-//                   HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
-//                    if(BuyAndSellUtils.isTransState()){
-                    try {
-                        new WebSocketController().sendSysMsgType("GP",JSON.toJSONString(subRedisList));
-//                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
-                    }catch (Exception e){
-                        log.error("插入redis错误" + e);
-                    }
+//            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() {
+////                   HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
+////                    if(BuyAndSellUtils.isTransState()){
+//                    try {
+//                        new WebSocketController().sendSysMsgType("GP",JSON.toJSONString(subRedisList));
+////                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
+//                    }catch (Exception e){
+//                        log.error("插入redis错误" + e);
 //                    }
-                }
-            });
-            thread.start();
+////                    }
+//                }
+//            });
+//            thread.start();
         }
     }
 
@@ -478,47 +485,47 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
         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);
+//            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("GP",JSON.toJSONString(subRedisList));
-//                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
-                    }catch (Exception e){
-                        log.error("插入redis错误" + e);
-                    }
+//            Thread thread=new Thread(new Runnable() {
+//                @Override
+//                public void run() {
+////                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
+////                    if(BuyAndSellUtils.isTransState()){
+//                    try {
+//                        new WebSocketController().sendSysMsgType("GP",JSON.toJSONString(subRedisList));
+////                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
+//                    }catch (Exception e){
+//                        log.error("插入redis错误" + e);
 //                    }
-
-                }
-            });
-            thread.start();
+////                    }
+//
+//                }
+//            });
+//            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() {
-//                   HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
-//                    if(BuyAndSellUtils.isTransState()){
-                    try {
-                        new WebSocketController().sendSysMsgType("GP",JSON.toJSONString(subRedisList));
-//                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
-                    }catch (Exception e){
-                        log.error("插入redis错误" + e);
-                    }
+//            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() {
+////                   HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
+////                    if(BuyAndSellUtils.isTransState()){
+//                    try {
+//                        new WebSocketController().sendSysMsgType("GP",JSON.toJSONString(subRedisList));
+////                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
+//                    }catch (Exception e){
+//                        log.error("插入redis错误" + e);
 //                    }
-                }
-            });
-            thread.start();
+////                    }
+//                }
+//            });
+//            thread.start();
         }
     }
 
@@ -671,7 +678,37 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
 
                         stockRestRedisVO.setHighlimit(stockRestPojo.getHighlimit());
                         stockRestRedisVO.setLowlimit(stockRestPojo.getLowlimit());
-                        stockRestRedisVOList.add(stockRestRedisVO);
+
+
+                        stockRestRedisVO.setBuy1(stockRestPojo.getBuyprice1());
+                        stockRestRedisVO.setBuy2(stockRestPojo.getBuyprice2());
+                        stockRestRedisVO.setBuy3(stockRestPojo.getBuyprice3());
+                        stockRestRedisVO.setBuy4(stockRestPojo.getBuyprice4());
+                        stockRestRedisVO.setBuy5(stockRestPojo.getBuyprice5());
+
+                        stockRestRedisVO.setSell1(stockRestPojo.getSellprice1());
+                        stockRestRedisVO.setSell2(stockRestPojo.getSellprice2());
+                        stockRestRedisVO.setSell3(stockRestPojo.getSellprice3());
+                        stockRestRedisVO.setSell4(stockRestPojo.getSellprice4());
+                        stockRestRedisVO.setSell5(stockRestPojo.getSellprice5());
+
+                        stockRestRedisVO.setBuy1_num(stockRestPojo.getBuyvolume1());
+                        stockRestRedisVO.setBuy2_num(stockRestPojo.getBuyvolume2());
+                        stockRestRedisVO.setBuy3_num(stockRestPojo.getBuyvolume3());
+                        stockRestRedisVO.setBuy4_num(stockRestPojo.getBuyvolume4());
+                        stockRestRedisVO.setBuy5_num(stockRestPojo.getBuyvolume5());
+
+                        stockRestRedisVO.setSell1_num(stockRestPojo.getSellvolume1());
+                        stockRestRedisVO.setSell2_num(stockRestPojo.getSellvolume2());
+                        stockRestRedisVO.setSell3_num(stockRestPojo.getSellvolume3());
+                        stockRestRedisVO.setSell4_num(stockRestPojo.getSellvolume4());
+                        stockRestRedisVO.setSell5_num(stockRestPojo.getSellvolume5());
+
+
+                        redisUtil.saveItem("stock_"+stockRestRedisVO.getCode(),JSON.toJSONString(stockRestRedisVO), 10, TimeUnit.DAYS);
+
+//                        stockRestRedisVOList.add(stockRestRedisVO);
+
                     }
                 }catch (Exception e){
                     log.error("错误数据导致失败" + e);

+ 118 - 99
src/main/java/com/zx/dataservice/service/impl/ChoiceTempIndexServiceImpl.java

@@ -8,6 +8,7 @@ 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.redismessage.util.RedisUtil;
 import com.zx.dataservice.service.ChoiceTempIndexService;
 import com.zx.dataservice.utils.*;
 import com.zx.dataservice.vo.StockRestRedisVO;
@@ -22,6 +23,7 @@ import org.springframework.stereotype.Service;
 import java.io.File;
 import java.math.BigDecimal;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 
 @Service
 public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
@@ -43,6 +45,9 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
     @Autowired
     private ChoiceStockMapper choiceStockMapper;
 
+    @Autowired
+    private RedisUtil redisUtil;
+
     @Override
     public void analysisStockRestData(String    type) {
         // 1.获取文件夹文件 按照时间顺序拿到一个
@@ -238,42 +243,48 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
                                     if (key.contains((WSOptions.get(key2).split("_")[0]+"_"+entry.getKey().toUpperCase()))) {// 存在该股票的风控  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());
-
-                                        stockRestRedisVO.setBuy1(stockRestPojo.getBuyprice1());
-                                        stockRestRedisVO.setBuy2(stockRestPojo.getBuyprice2());
-                                        stockRestRedisVO.setBuy3(stockRestPojo.getBuyprice3());
-                                        stockRestRedisVO.setBuy4(stockRestPojo.getBuyprice4());
-                                        stockRestRedisVO.setBuy5(stockRestPojo.getBuyprice5());
-
-                                        stockRestRedisVO.setSell1(stockRestPojo.getSellprice1());
-                                        stockRestRedisVO.setSell2(stockRestPojo.getSellprice2());
-                                        stockRestRedisVO.setSell3(stockRestPojo.getSellprice3());
-                                        stockRestRedisVO.setSell4(stockRestPojo.getSellprice4());
-                                        stockRestRedisVO.setSell5(stockRestPojo.getSellprice5());
-
-                                        stockRestRedisVO.setBuy1_num(stockRestPojo.getBuyvolume1());
-                                        stockRestRedisVO.setBuy2_num(stockRestPojo.getBuyvolume2());
-                                        stockRestRedisVO.setBuy3_num(stockRestPojo.getBuyvolume3());
-                                        stockRestRedisVO.setBuy4_num(stockRestPojo.getBuyvolume4());
-                                        stockRestRedisVO.setBuy5_num(stockRestPojo.getBuyvolume5());
-
-                                        stockRestRedisVO.setSell1_num(stockRestPojo.getSellvolume1());
-                                        stockRestRedisVO.setSell2_num(stockRestPojo.getSellvolume2());
-                                        stockRestRedisVO.setSell3_num(stockRestPojo.getSellvolume3());
-                                        stockRestRedisVO.setSell4_num(stockRestPojo.getSellvolume4());
-                                        stockRestRedisVO.setSell5_num(stockRestPojo.getSellvolume5());
-                                        mapws.get("stockRestRedisVO_" + WSOptions.get(key2).split("_")[0]).add(stockRestRedisVO);   //  stockRestRedisVO_hy
+                                        StockRestRedisVO stockRestRedisVOf = new StockRestRedisVO();
+                                        stockRestRedisVOf.setCode(stockRestPojoRisk.getCode().toUpperCase());
+                                        stockRestRedisVOf.setNowPrice(stockRestPojoRisk.getNow());
+                                        stockRestRedisVOf.setChange(stockRestPojoRisk.getChange());
+                                        stockRestRedisVOf.setHcrate(stockRestPojoRisk.getPctchange());
+                                        stockRestRedisVOf.setHighlimit(stockRestPojoRisk.getHighlimit());
+                                        stockRestRedisVOf.setLowlimit(stockRestPojoRisk.getLowlimit());
+
+                                        stockRestRedisVOf.setBuy1(stockRestPojo.getBuyprice1());
+                                        stockRestRedisVOf.setBuy2(stockRestPojo.getBuyprice2());
+                                        stockRestRedisVOf.setBuy3(stockRestPojo.getBuyprice3());
+                                        stockRestRedisVOf.setBuy4(stockRestPojo.getBuyprice4());
+                                        stockRestRedisVOf.setBuy5(stockRestPojo.getBuyprice5());
+
+                                        stockRestRedisVOf.setSell1(stockRestPojo.getSellprice1());
+                                        stockRestRedisVOf.setSell2(stockRestPojo.getSellprice2());
+                                        stockRestRedisVOf.setSell3(stockRestPojo.getSellprice3());
+                                        stockRestRedisVOf.setSell4(stockRestPojo.getSellprice4());
+                                        stockRestRedisVOf.setSell5(stockRestPojo.getSellprice5());
+
+                                        stockRestRedisVOf.setBuy1_num(stockRestPojo.getBuyvolume1());
+                                        stockRestRedisVOf.setBuy2_num(stockRestPojo.getBuyvolume2());
+                                        stockRestRedisVOf.setBuy3_num(stockRestPojo.getBuyvolume3());
+                                        stockRestRedisVOf.setBuy4_num(stockRestPojo.getBuyvolume4());
+                                        stockRestRedisVOf.setBuy5_num(stockRestPojo.getBuyvolume5());
+
+                                        stockRestRedisVOf.setSell1_num(stockRestPojo.getSellvolume1());
+                                        stockRestRedisVOf.setSell2_num(stockRestPojo.getSellvolume2());
+                                        stockRestRedisVOf.setSell3_num(stockRestPojo.getSellvolume3());
+                                        stockRestRedisVOf.setSell4_num(stockRestPojo.getSellvolume4());
+                                        stockRestRedisVOf.setSell5_num(stockRestPojo.getSellvolume5());
+
+                                        redisUtil.saveItem("index_"+WSOptions.get(key2).split("_")[0]+"_"+stockRestRedisVOf.getCode(),JSON.toJSONString(stockRestRedisVOf), 10, TimeUnit.DAYS);
+
+//                                        mapws.get("stockRestRedisVO_" + WSOptions.get(key2).split("_")[0]).add(stockRestRedisVOf);   //  stockRestRedisVO_hy
                                     }
                                 }
                             }else {
-                                mapws.get("stockRestRedisVO_"+ WSOptions.get(key2).split("_")[0]).add(stockRestRedisVO);
+
+                                redisUtil.saveItem("index_"+WSOptions.get(key2).split("_")[0]+"_"+stockRestRedisVO.getCode(),JSON.toJSONString(stockRestRedisVO), 10, TimeUnit.DAYS);
+
+//                                mapws.get("stockRestRedisVO_"+ WSOptions.get(key2).split("_")[0]).add(stockRestRedisVO);
                             }
                         }
                     }
@@ -302,9 +313,9 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
         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<>());
-        }
+//        for(String key: WSOptions.keySet()){  // 所有的需要推送的 客户
+//            mapws.put("stockRestRedisVO_"+ WSOptions.get(key).split("_")[0],new ArrayList<>());
+//        }
         StockRestPojo stockRestPojo;
         StockRestVO stockRestVO;
         StockRestRedisVO stockRestRedisVO;
@@ -481,42 +492,48 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
                                     if (key.contains((WSOptions.get(key2).split("_")[0]+"_"+entry.getKey().toUpperCase()))) {// 存在该股票的风控  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());
-
-                                        stockRestRedisVO.setBuy1(stockRestPojo.getBuyprice1());
-                                        stockRestRedisVO.setBuy2(stockRestPojo.getBuyprice2());
-                                        stockRestRedisVO.setBuy3(stockRestPojo.getBuyprice3());
-                                        stockRestRedisVO.setBuy4(stockRestPojo.getBuyprice4());
-                                        stockRestRedisVO.setBuy5(stockRestPojo.getBuyprice5());
-
-                                        stockRestRedisVO.setSell1(stockRestPojo.getSellprice1());
-                                        stockRestRedisVO.setSell2(stockRestPojo.getSellprice2());
-                                        stockRestRedisVO.setSell3(stockRestPojo.getSellprice3());
-                                        stockRestRedisVO.setSell4(stockRestPojo.getSellprice4());
-                                        stockRestRedisVO.setSell5(stockRestPojo.getSellprice5());
-
-                                        stockRestRedisVO.setBuy1_num(stockRestPojo.getBuyvolume1());
-                                        stockRestRedisVO.setBuy2_num(stockRestPojo.getBuyvolume2());
-                                        stockRestRedisVO.setBuy3_num(stockRestPojo.getBuyvolume3());
-                                        stockRestRedisVO.setBuy4_num(stockRestPojo.getBuyvolume4());
-                                        stockRestRedisVO.setBuy5_num(stockRestPojo.getBuyvolume5());
-
-                                        stockRestRedisVO.setSell1_num(stockRestPojo.getSellvolume1());
-                                        stockRestRedisVO.setSell2_num(stockRestPojo.getSellvolume2());
-                                        stockRestRedisVO.setSell3_num(stockRestPojo.getSellvolume3());
-                                        stockRestRedisVO.setSell4_num(stockRestPojo.getSellvolume4());
-                                        stockRestRedisVO.setSell5_num(stockRestPojo.getSellvolume5());
-                                        mapws.get("stockRestRedisVO_" + WSOptions.get(key2).split("_")[0]).add(stockRestRedisVO);   //  stockRestRedisVO_hy
+                                        StockRestRedisVO stockRestRedisVOf = new StockRestRedisVO();
+                                        stockRestRedisVOf.setCode(stockRestPojoRisk.getCode().toUpperCase());
+                                        stockRestRedisVOf.setNowPrice(stockRestPojoRisk.getNow());
+                                        stockRestRedisVOf.setChange(stockRestPojoRisk.getChange());
+                                        stockRestRedisVOf.setHcrate(stockRestPojoRisk.getPctchange());
+                                        stockRestRedisVOf.setHighlimit(stockRestPojoRisk.getHighlimit());
+                                        stockRestRedisVOf.setLowlimit(stockRestPojoRisk.getLowlimit());
+
+                                        stockRestRedisVOf.setBuy1(stockRestPojo.getBuyprice1());
+                                        stockRestRedisVOf.setBuy2(stockRestPojo.getBuyprice2());
+                                        stockRestRedisVOf.setBuy3(stockRestPojo.getBuyprice3());
+                                        stockRestRedisVOf.setBuy4(stockRestPojo.getBuyprice4());
+                                        stockRestRedisVOf.setBuy5(stockRestPojo.getBuyprice5());
+
+                                        stockRestRedisVOf.setSell1(stockRestPojo.getSellprice1());
+                                        stockRestRedisVOf.setSell2(stockRestPojo.getSellprice2());
+                                        stockRestRedisVOf.setSell3(stockRestPojo.getSellprice3());
+                                        stockRestRedisVOf.setSell4(stockRestPojo.getSellprice4());
+                                        stockRestRedisVOf.setSell5(stockRestPojo.getSellprice5());
+
+                                        stockRestRedisVOf.setBuy1_num(stockRestPojo.getBuyvolume1());
+                                        stockRestRedisVOf.setBuy2_num(stockRestPojo.getBuyvolume2());
+                                        stockRestRedisVOf.setBuy3_num(stockRestPojo.getBuyvolume3());
+                                        stockRestRedisVOf.setBuy4_num(stockRestPojo.getBuyvolume4());
+                                        stockRestRedisVOf.setBuy5_num(stockRestPojo.getBuyvolume5());
+
+                                        stockRestRedisVOf.setSell1_num(stockRestPojo.getSellvolume1());
+                                        stockRestRedisVOf.setSell2_num(stockRestPojo.getSellvolume2());
+                                        stockRestRedisVOf.setSell3_num(stockRestPojo.getSellvolume3());
+                                        stockRestRedisVOf.setSell4_num(stockRestPojo.getSellvolume4());
+                                        stockRestRedisVOf.setSell5_num(stockRestPojo.getSellvolume5());
+
+                                        redisUtil.saveItem("index_"+WSOptions.get(key2).split("_")[0]+"_"+stockRestRedisVOf.getCode(),JSON.toJSONString(stockRestRedisVOf), 10, TimeUnit.DAYS);
+
+//                                        mapws.get("stockRestRedisVO_" + WSOptions.get(key2).split("_")[0]).add(stockRestRedisVO);   //  stockRestRedisVO_hy
                                     }
                                 }
                             }else {
-                                mapws.get("stockRestRedisVO_"+ WSOptions.get(key2).split("_")[0]).add(stockRestRedisVO);
+
+                                redisUtil.saveItem("index_"+WSOptions.get(key2).split("_")[0]+"_"+stockRestRedisVO.getCode(),JSON.toJSONString(stockRestRedisVO), 10, TimeUnit.DAYS);
+
+//                                mapws.get("stockRestRedisVO_"+ WSOptions.get(key2).split("_")[0]).add(stockRestRedisVO);
                             }
                         }
 
@@ -546,21 +563,21 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
             choiceStockMapper.insertBatchByAfter(list.subList(i, i + insertLength));
         }
 
-        Thread thread=new Thread(new Runnable() {
-            @Override
-            public void run() {
-//                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
-//                    if(BuyAndSellUtils.isTransState()){
-                try {
-                    new WebSocketController().sendSysMsgType("ZS",mapws);
-//                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
-                }catch (Exception e){
-                    log.error("插入redis错误" + e);
-                }
-//                    }
-            }
-        });
-        thread.start();
+//        Thread thread=new Thread(new Runnable() {
+//            @Override
+//            public void run() {
+////                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
+////                    if(BuyAndSellUtils.isTransState()){
+//                try {
+//                    new WebSocketController().sendSysMsgType("ZS",mapws);
+////                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
+//                }catch (Exception e){
+//                    log.error("插入redis错误" + e);
+//                }
+////                    }
+//            }
+//        });
+//        thread.start();
     }
 
     private void insertList(List<StockRestPojo> list,Map<String,List<StockRestRedisVO>>mapws ,String type) { // List<StockRestRedisVO> stockRestRedisVOList
@@ -583,21 +600,21 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
                 choiceStockMapper.insertBatchByAfter(list.subList(i, i + insertLength));
             }
         }
-        Thread thread=new Thread(new Runnable() {
-            @Override
-            public void run() {
-//                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
-//                    if(BuyAndSellUtils.isTransState()){
-                try {
-                    new WebSocketController().sendSysMsgType("ZS",mapws);
-//                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
-                }catch (Exception e){
-                    log.error("插入redis错误" + e);
-                }
-//                    }
-            }
-        });
-        thread.start();
+//        Thread thread=new Thread(new Runnable() {
+//            @Override
+//            public void run() {
+////                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
+////                    if(BuyAndSellUtils.isTransState()){
+//                try {
+//                    new WebSocketController().sendSysMsgType("ZS",mapws);
+////                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
+//                }catch (Exception e){
+//                    log.error("插入redis错误" + e);
+//                }
+////                    }
+//            }
+//        });
+//        thread.start();
     }
 
 
@@ -611,6 +628,7 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
         if("1".equals(valueArr[4])){ // 如果此时没有开启风控 那么不变化
             StockRestPojo stockRestPojoNew = new StockRestPojo();
             BeanUtils.copyProperties(stockRestPojo,stockRestPojoNew,StockRestPojo.class);
+            stockRestPojoNew.setCode(valueArr[0]);
             stockRestPojoNew.setTableName(tableName.toString());
             return stockRestPojoNew;
         }else {
@@ -623,6 +641,7 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
             BeanUtils.copyProperties(stockRestPojo,stockRestPojoNew,StockRestPojo.class);
             String nnow = BigdecimalUtil.getNew(stockRestPojo.getNow() + "", risk2, risk1, 4, 2, multiples);
             stockRestPojoNew.setTableName(tableName.toString()); // 表
+            stockRestPojoNew.setCode(tocode);
             stockRestPojoNew.setNow(nnow); // 现价
             // 高
             stockRestPojoNew.setHigh(BigdecimalUtil.getNew(stockRestPojo.getHigh() + "", risk2, risk1, 4, 2, multiples));

+ 31 - 0
src/main/java/com/zx/dataservice/task/AnalysisDataTask.java

@@ -0,0 +1,31 @@
+package com.zx.dataservice.task;
+
+import com.zx.dataservice.options.ZXOptions;
+import com.zx.dataservice.service.ChoiceHisService;
+import com.zx.dataservice.service.ChoiceService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+/**
+ * 推送实时数据
+ */
+@Component
+public class AnalysisDataTask {
+
+    private static final Logger log = LoggerFactory.getLogger(AnalysisDataTask.class);
+
+    @Autowired
+    private ChoiceService choiceService;
+
+
+    @Scheduled(cron = "1/5 * * * * ? ")
+    public void toAnalysisDataTask() {
+        if("true".equals(ZXOptions.get("isold"))){
+            this.choiceService.analysisDataTask();
+        }
+    }
+
+}

File diff suppressed because it is too large
+ 4 - 3
src/main/java/com/zx/dataservice/task/AnalysisRiskDataTask.java


+ 12 - 0
src/main/resources/application-real.properties

@@ -41,5 +41,17 @@ spring.datasource.test2.driver-class-name=com.mysql.cj.jdbc.Driver
 #spring.datasource.test2.password=qlmroot
 #spring.datasource.test2.driver-class-name=com.mysql.cj.jdbc.Driver
 
+
+redis1.ip=127.0.0.1
+redis1.port=6379
+redis1.pwd=
+#redis2.ip=47.52.34.37
+#redis2.port=6380
+redis.max.total=20
+redis.max.idle=10
+redis.min.idle=2
+redis.test.borrow=true
+redis.test.return=true
+
 #ÊÇ·ñ¼¤»î swagger true or false
 swagger.enable=false