Procházet zdrojové kódy

1.websocket 订阅
2.盘前数据解析
3.推送—— qlm

qlm před 4 roky
rodič
revize
7fb81d51a3

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

@@ -151,7 +151,7 @@ public class JfinalActiveRecordConfig implements ApplicationRunner {
     @Override
     public void run(ApplicationArguments args) throws Exception {
 
-        List<Record> records = Db.use("gp").find("select * from sys_config ");
+        List<Record> records = Db.use("gp").find("select config_key,config_value from sys_config ");
         for (Record record:records) {
             ZXOptions.set(record.getStr("config_key"),record.getStr("config_value"));
         }

+ 19 - 0
src/main/java/com/zx/dataservice/config/WebSocketConfig.java

@@ -0,0 +1,19 @@
+package com.zx.dataservice.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.socket.server.standard.ServerEndpointExporter;
+
+import java.io.Serializable;
+
+@Configuration
+public class WebSocketConfig implements Serializable {
+
+    private static final long serialVersionUID = 7600559593733357846L;
+
+    @Bean
+    public ServerEndpointExporter serverEndpointExporter() {
+        return new ServerEndpointExporter();
+    }
+
+}

+ 117 - 0
src/main/java/com/zx/dataservice/controller/CallBackController.java

@@ -0,0 +1,117 @@
+package com.zx.dataservice.controller;
+
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.zx.dataservice.utils.ZXOptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import java.util.List;
+
+@Controller
+@RequestMapping({"/admin/"})
+public class CallBackController {
+
+    private static Logger LOG = LoggerFactory.getLogger(CallBackController.class);
+
+    @GetMapping("/t1")
+    @ResponseBody
+    public String quantCallBack(String code){
+        String url1 = "https://api.huobi.pro/market/history/kline?period=1day&size=200&symbol=btcusdt";
+        String ur2 = "https://status.huobigroup.com/api/v2/summary.json";
+        String url = "https://api.huobi.pro/market/history/kline?period=1day&size=200&symbol=btcusdt";
+        String s1 = "";
+        try {
+//            String wssurl1 = "ws://192.168.1.101:8088/websocket/zxdata9876541+";
+//            String wssurl1 = "ws://101.32.215.72:8080/data_server_java/websocket/zxdata9876541+";
+// http://qwer16888.vip/stock2coin/ws/test/start.do
+//            String s = HttpRequest.doGet(url, "");
+//            WsClient myClient = new WsClient(new URI(wssurl1));
+//            myClient.connect();
+            // 判断是否连接成功,未成功后面发送消息时会报错
+//            while (!myClient.getReadyState().equals(WebSocket.READYSTATE.OPEN)) {
+//                System.out.println("连接中···请稍后");
+//                Thread.sleep(1000);
+//            }
+//            myClient.send("123");
+//            System.out.println("发送成功");
+
+//            new WebSocketController().sendSysMsg("zxdata987654+","sss");
+
+        } catch (Exception e) {
+            return e.toString();
+//            e.printStackTrace();
+//            if(e.toString().length()>500){                LOG.error(e.toString().substring(0,450));            }else {                LOG.error(e.toString());            }
+        }
+//        Request executeRequest = new Request.Builder()
+//                .url(url)
+//                .addHeader("Content-Type", "application/x-www-form-urlencoded")
+//                .build();
+//        String str = ConnectionFactory.execute(executeRequest);
+        return s1;
+    }
+
+
+
+    @GetMapping("/test")
+    @ResponseBody
+    public boolean test(String code){
+        try {
+
+//            QuantUtil quantUtil = new QuantUtil();
+////        System.out.println("初始化东方财富");
+//            quantUtil.init();
+////        //调用登录函数
+//        quantUtil.start();
+
+        } catch (Exception e) {
+            if(e.toString().length()>500){                LOG.error(e.toString().substring(0,450));            }else {                LOG.error(e.toString());            }
+        }
+        return true;
+    }
+
+    @GetMapping("/updateZX")
+    @ResponseBody
+    public boolean updateZX(String code){
+        try {
+            List<Record> records = Db.use("hb").find("select config_key,config_value from sys_config ");
+            for (Record record:records) {
+                ZXOptions.set(record.getStr("config_key"),record.getStr("config_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());            }
+        }
+        return true;
+    }
+
+
+    @GetMapping("/start")
+    @ResponseBody
+    public boolean start(String code){
+        try {
+
+        } 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
+    public boolean remMap2(String key){
+        try {
+
+        } catch (Exception e) {
+            if(e.toString().length()>500){                LOG.error(e.toString().substring(0,450));            }else {                LOG.error(e.toString());            }
+        }
+        return true;
+    }
+
+
+}

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

@@ -4,6 +4,8 @@ package com.zx.dataservice.controller;
  * Created by qlm on 2020-12-14.
  */
 
+import org.springframework.stereotype.Component;
+
 import javax.websocket.*;
 import javax.websocket.server.PathParam;
 import javax.websocket.server.ServerEndpoint;
@@ -11,13 +13,16 @@ import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
 
 
 @ServerEndpoint("/websocket/{userId}")
-//@Component
+@Component
 public class WebSocketController {
 
-    public static Map<String,Session> map = new HashMap<String,Session>();//根据用户找session
+//    public static Map<String,Session> map = new HashMap<String,Session>();
+
+    private static ConcurrentHashMap<String, Session> map = new ConcurrentHashMap<>();//根据用户找session
 
     /**
      * 连接建立成功时调用
@@ -96,6 +101,7 @@ public class WebSocketController {
      */
     @OnMessage
     public void onMessage(String requestJson, Session session) {
+
         System.out.println("啦啦啦");
 
     }

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

@@ -7,4 +7,6 @@ public interface ChoiceStockService {
      */
     void analysisStockRestData(String type);
 
+    void analysisStockRestDataInFront(String type);
+
 }

+ 21 - 17
src/main/java/com/zx/dataservice/service/impl/ChoiceBondServiceImpl.java

@@ -23,17 +23,19 @@ public class ChoiceBondServiceImpl implements ChoiceBondService {
 
     private static final Logger log = LoggerFactory.getLogger(ChoiceBondServiceImpl.class);
 
-    private static final String sourceFileUrl = "/www/wwwroot/csqdata/bond";
+    private static final String sourceFileUrl = "/www/wwwroot/csqdata/bond";// 盘中
 
-    private static final String goalFileUrl = "/www/wwwroot/csqdata/bond/backup";
 
-    private static final String url = "http://qwer16888.vip/api/stock/updateBatchStockInfo.do";
+    private static final String goalFileUrl = "/www/wwwroot/csqdata/bond/backup"; // 盘中 备份
+
+
+    private static final String url = "http://qwer16888.vip/api/stock/updateBatchStockInfo.do";  //
 
     private static final String urlRedis = "http://qwer16888.vip/init/redis/updateInfo.do";
 
-    private static final String sourceAfterFileUrl = "/www/wwwroot/csqdata/bond/after";
+    private static final String sourceAfterFileUrl = "/www/wwwroot/csqdata/bond/after";  // 盘后
 
-    private static final String goalAfterFileUrl = "/www/wwwroot/csqdata/bond/after/backup";
+    private static final String goalAfterFileUrl = "/www/wwwroot/csqdata/bond/after/backup"; // 盘后备份
 
     @Autowired
     private ChoiceBondMapper choiceBondMapper;
@@ -189,6 +191,8 @@ public class ChoiceBondServiceImpl implements ChoiceBondService {
                     stockRestRedisVO.setNowPrice(stockRestPojo.getNow());
                     stockRestRedisVO.setChange(stockRestPojo.getChange());
                     stockRestRedisVO.setHcrate(stockRestPojo.getPctchange());
+                    stockRestRedisVO.setHighlimit(stockRestPojo.getHighlimit());
+                    stockRestRedisVO.setLowlimit(stockRestPojo.getLowlimit());
                     stockRestRedisVOList.add(stockRestRedisVO);
                 }catch (Exception e){
                     log.error("错误数据导致失败" + e);
@@ -219,17 +223,17 @@ public class ChoiceBondServiceImpl implements ChoiceBondService {
                 @Override
                 public void run() {
 //                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
-                    if(BuyAndSellUtils.isTransState()){
+//                    if(BuyAndSellUtils.isTransState()){
                         try{
                             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));
                             }
-                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
+//                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
                         }catch (Exception e){
                             log.error("插入redis错误" + e);
                         }
-                    }
+//                    }
                 }
             });
             thread.start();
@@ -246,17 +250,17 @@ public class ChoiceBondServiceImpl implements ChoiceBondService {
                 @Override
                 public void run() {
 //                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
-                    if(BuyAndSellUtils.isTransState()) {
-                        try{
-                            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));
-                            }
-                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
-                        }catch (Exception e){
-                            log.error("插入redis错误" + e);
+//                    if(BuyAndSellUtils.isTransState()){
+                    try {
+                        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));
                         }
+//                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
+                    }catch (Exception e){
+                        log.error("插入redis错误" + e);
                     }
+//                    }
                 }
             });
             thread.start();

+ 270 - 17
src/main/java/com/zx/dataservice/service/impl/ChoiceStockServiceImpl.java

@@ -1,13 +1,11 @@
 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.pojo.StockRestPojo;
 import com.zx.dataservice.service.ChoiceStockService;
-import com.zx.dataservice.utils.BuyAndSellUtils;
-import com.zx.dataservice.utils.FileStockUtil;
-import com.zx.dataservice.utils.HttpRequest;
-import com.zx.dataservice.utils.TimeUtil;
+import com.zx.dataservice.utils.*;
 import com.zx.dataservice.vo.StockRestRedisVO;
 import com.zx.dataservice.vo.StockRestVO;
 import org.apache.commons.lang3.StringUtils;
@@ -39,6 +37,12 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
 
     private static final String goalAfterFileUrl = "/www/wwwroot/csqdata/stock/after/backup";
 
+    private static final String sourceFileUrlInFront = "/www/wwwroot/csqdata/stock/InFront"; // 盘前
+
+    private static final String goalFileUrlInFront = "/www/wwwroot/csqdata/stock/backup/InFront"; //盘前 备份
+
+
+
     @Autowired
     private ChoiceStockMapper choiceStockMapper;
 
@@ -66,6 +70,10 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
                 FileStockUtil.moveFile(sourceAfterFileUrl + File.separator + file.getName(), goalAfterFileUrl);
                 // 3.读取文件内容
                 str = FileStockUtil.readFileContent(goalAfterFileUrl + File.separator + file.getName());
+            }else if("inFront".equals(type)){
+                FileStockUtil.moveFile(sourceFileUrlInFront + File.separator + file.getName(), goalFileUrlInFront);
+                // 3.读取文件内容
+                str = FileStockUtil.readFileContent(goalFileUrlInFront + File.separator + file.getName());
             }
             // 4.并解析
             if(StringUtils.isEmpty(str)){
@@ -81,7 +89,7 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
                     if(String.valueOf(entry.getValue().get(1)).equals("0")){
                         continue;
                     }
-                    stockRestPojo.setTime("now".equals(type)?String.valueOf(entry.getValue().get(1)):"150000");
+                    stockRestPojo.setTime((!"now".equals(type))?String.valueOf(entry.getValue().get(1)):"150000");
                     stockRestPojo.setNow(String.valueOf(entry.getValue().get(2)));
                     stockRestPojo.setHigh(String.valueOf(entry.getValue().get(3)));
                     stockRestPojo.setLow(String.valueOf(entry.getValue().get(4)));
@@ -191,6 +199,9 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
                     stockRestRedisVO.setNowPrice(stockRestPojo.getNow());
                     stockRestRedisVO.setChange(stockRestPojo.getChange());
                     stockRestRedisVO.setHcrate(stockRestPojo.getPctchange());
+
+                    stockRestRedisVO.setHighlimit(stockRestPojo.getHighlimit());
+                    stockRestRedisVO.setLowlimit(stockRestPojo.getLowlimit());
                     stockRestRedisVOList.add(stockRestRedisVO);
                 }catch (Exception e){
                     log.error("错误数据导致失败" + e);
@@ -203,13 +214,12 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
         stockRestPojoList = null;
     }
 
-
     private void insertList(List<StockRestPojo> list, List<StockRestVO> stockRestVOList, List<StockRestRedisVO> stockRestRedisVOList,String type) {
         int insertLength = list.size();
         int i = 0;
         int insertSize = 500;
         while (insertLength > insertSize) {
-            if("now".equals(type)){
+            if((!"now".equals(type))){
                 choiceStockMapper.insertBatch(list.subList(i, i + insertSize));
             }else {
                 choiceStockMapper.insertBatchByAfter(list.subList(i, i + insertSize));
@@ -222,20 +232,257 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
                 @Override
                 public void run() {
 //                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
-                    if(BuyAndSellUtils.isTransState()){
-                        try {
-                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
-                        }catch (Exception e){
-                            log.error("插入redis错误" + e);
+//                    if(BuyAndSellUtils.isTransState()){
+                    try {
+                        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));
                         }
+//                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
+                    }catch (Exception e){
+                        log.error("插入redis错误" + e);
                     }
+//                    }
 
                 }
             });
             thread.start();
         }
         if (insertLength > 0) {
+            if((!"now".equals(type))){
+                choiceStockMapper.insertBatch(list.subList(i, i + insertLength));
+            }else {
+                choiceStockMapper.insertBatchByAfter(list.subList(i, i + insertLength));
+            }
+            List<StockRestVO> subList = stockRestVOList.subList(i, i + insertLength);
+            List<StockRestRedisVO> subRedisList = stockRestRedisVOList.subList(i, i + insertLength);
+            Thread thread=new Thread(new Runnable() {
+                @Override
+                public void run() {
+//                   HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
+//                    if(BuyAndSellUtils.isTransState()){
+                    try {
+                        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));
+                        }
+//                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
+                    }catch (Exception e){
+                        log.error("插入redis错误" + e);
+                    }
+//                    }
+                }
+            });
+            thread.start();
+        }
+    }
+
+
+
+    @Override
+    public void analysisStockRestDataInFront(String type) {
+        // 1.获取文件夹文件 按照时间顺序拿到一个
+        List<File> files = FileStockUtil.getFile(sourceFileUrlInFront);
+        if(null == files || 0 == files.size()){
+            return;
+        }
+        List<StockRestPojo> stockRestPojoList = new ArrayList<>();
+        List<StockRestVO> stockRestVOList = new ArrayList<>();
+        List<StockRestRedisVO> stockRestRedisVOList = new ArrayList<>();
+        StockRestPojo stockRestPojo;
+        StockRestVO stockRestVO;
+        StockRestRedisVO stockRestRedisVO;
+        for (File file : files){
+            // 2.移动文件去另外一个文件夹
+            String str = "";
             if("now".equals(type)){
+                FileStockUtil.moveFile(sourceFileUrl + File.separator + file.getName(), goalFileUrl);
+                // 3.读取文件内容
+                str = FileStockUtil.readFileContent(goalFileUrl + File.separator + file.getName());
+            }else if("after".equals(type)){
+                FileStockUtil.moveFile(sourceAfterFileUrl + File.separator + file.getName(), goalAfterFileUrl);
+                // 3.读取文件内容
+                str = FileStockUtil.readFileContent(goalAfterFileUrl + File.separator + file.getName());
+            }else if("inFront".equals(type)){
+                FileStockUtil.moveFile(sourceFileUrlInFront + File.separator + file.getName(), goalFileUrlInFront);
+                // 3.读取文件内容
+                str = FileStockUtil.readFileContent(goalFileUrlInFront + File.separator + file.getName());
+            }
+            // 4.并解析
+            if(StringUtils.isEmpty(str)){
+                continue;
+            }
+            Map<String, List<String>> map = new HashMap<String, List<String>>();
+            map = JSON.parseObject(str, HashMap.class);
+            str = null;
+            for (Map.Entry<String, List<String>> entry : map.entrySet()) {
+                try {
+                    stockRestPojo = new StockRestPojo();
+                    stockRestPojo.setDate(String.valueOf(entry.getValue().get(0)));
+                    if(String.valueOf(entry.getValue().get(1)).equals("0")){
+                        continue;
+                    }
+                    stockRestPojo.setTime((!"now".equals(type))?String.valueOf(entry.getValue().get(1)):"150000");
+                    stockRestPojo.setNow(String.valueOf(entry.getValue().get(2)));
+                    stockRestPojo.setHigh(String.valueOf(entry.getValue().get(3)));
+                    stockRestPojo.setLow(String.valueOf(entry.getValue().get(4)));
+                    stockRestPojo.setOpen(String.valueOf(entry.getValue().get(5)));
+                    stockRestPojo.setPreclose(String.valueOf(entry.getValue().get(6)));
+                    stockRestPojo.setRoundlot(String.valueOf(entry.getValue().get(7)));
+                    stockRestPojo.setChange(String.valueOf(entry.getValue().get(8)));
+                    stockRestPojo.setPctchange(String.valueOf(entry.getValue().get(9)));
+                    stockRestPojo.setVolume(String.valueOf(entry.getValue().get(10)));
+                    stockRestPojo.setAmount(String.valueOf(entry.getValue().get(11)));
+                    stockRestPojo.setVolumeratio(String.valueOf(entry.getValue().get(12)));
+                    stockRestPojo.setCommissionratio(String.valueOf(entry.getValue().get(13)));
+                    stockRestPojo.setCommissiondiff(String.valueOf(entry.getValue().get(14)));
+                    stockRestPojo.setTradestatus(String.valueOf(entry.getValue().get(15)));
+                    stockRestPojo.setOutvolume(String.valueOf(entry.getValue().get(16)));
+                    stockRestPojo.setInvolume(String.valueOf(entry.getValue().get(17)));
+                    stockRestPojo.setHighlimit(String.valueOf(entry.getValue().get(18)));
+                    stockRestPojo.setLowlimit(String.valueOf(entry.getValue().get(19)));
+                    stockRestPojo.setSpeed(String.valueOf(entry.getValue().get(20)));
+                    stockRestPojo.setAverageprice(String.valueOf(entry.getValue().get(21)));
+                    stockRestPojo.setBuyprice1(String.valueOf(entry.getValue().get(22)));
+                    stockRestPojo.setBuyprice2(String.valueOf(entry.getValue().get(23)));
+                    stockRestPojo.setBuyprice3(String.valueOf(entry.getValue().get(24)));
+                    stockRestPojo.setBuyprice4(String.valueOf(entry.getValue().get(25)));
+                    stockRestPojo.setBuyprice5(String.valueOf(entry.getValue().get(26)));
+                    stockRestPojo.setBuyvolume1(String.valueOf(entry.getValue().get(27)));
+                    stockRestPojo.setBuyvolume2(String.valueOf(entry.getValue().get(28)));
+                    stockRestPojo.setBuyvolume3(String.valueOf(entry.getValue().get(29)));
+                    stockRestPojo.setBuyvolume4(String.valueOf(entry.getValue().get(30)));
+                    stockRestPojo.setBuyvolume5(String.valueOf(entry.getValue().get(31)));
+                    stockRestPojo.setSellprice1(String.valueOf(entry.getValue().get(32)));
+                    stockRestPojo.setSellprice2(String.valueOf(entry.getValue().get(33)));
+                    stockRestPojo.setSellprice3(String.valueOf(entry.getValue().get(34)));
+                    stockRestPojo.setSellprice4(String.valueOf(entry.getValue().get(35)));
+                    stockRestPojo.setSellprice5(String.valueOf(entry.getValue().get(36)));
+                    stockRestPojo.setSellvolume1(String.valueOf(entry.getValue().get(37)));
+                    stockRestPojo.setSellvolume2(String.valueOf(entry.getValue().get(38)));
+                    stockRestPojo.setSellvolume3(String.valueOf(entry.getValue().get(39)));
+                    stockRestPojo.setSellvolume4(String.valueOf(entry.getValue().get(40)));
+                    stockRestPojo.setSellvolume5(String.valueOf(entry.getValue().get(41)));
+                    stockRestPojo.setClosedtime(String.valueOf(entry.getValue().get(42)));
+                    stockRestPojo.setClosedvolume(String.valueOf(entry.getValue().get(43)));
+                    stockRestPojo.setClosedamount(String.valueOf(entry.getValue().get(44)));
+                    StringBuffer dateStr = new StringBuffer(stockRestPojo.getDate());
+                    if (StringUtils.isEmpty(stockRestPojo.getTime())) {
+                        dateStr = dateStr.append(000000);
+                    } else {
+                        if (5 == stockRestPojo.getTime().length()) {
+                            // 长度为5表示 小时前面需要补0
+                            dateStr = dateStr.append(0).append(stockRestPojo.getTime());
+                        } else {
+                            dateStr = dateStr.append(stockRestPojo.getTime());
+                        }
+                    }
+                    Date date = TimeUtil.strToDate(dateStr.toString());
+                    // 毫秒转成秒
+                    stockRestPojo.setRealTime(date.getTime() / 1000);
+                    Calendar calendar = Calendar.getInstance();
+                    calendar.setTime(date);
+                    int min = calendar.get(Calendar.MINUTE); // 获取分钟
+                    int sec = calendar.get(Calendar.SECOND); // 获取秒数
+
+                    // 1分钟数据
+                    if (sec != 0) {
+                        stockRestPojo.setDateOne(stockRestPojo.getRealTime() + 60 - sec);
+                    } else {
+                        stockRestPojo.setDateOne(stockRestPojo.getRealTime());
+                    }
+
+                    // 5分钟数据
+                    if (sec != 0 || min % 5 != 0) {
+                        stockRestPojo.setDateFive(stockRestPojo.getRealTime() + (5 * 60) - sec - (min % 5 * 60));
+                    } else {
+                        stockRestPojo.setDateFive(stockRestPojo.getRealTime());
+                    }
+
+                    // 15分钟数据
+                    if (sec != 0 || min % 15 != 0) {
+                        stockRestPojo.setDateFifteen(stockRestPojo.getRealTime() + (15 * 60) - sec - (min % 15 * 60));
+                    } else {
+                        stockRestPojo.setDateFifteen(stockRestPojo.getRealTime());
+                    }
+
+                    // 30分钟数据
+                    if (sec != 0 || min % 30 != 0) {
+                        stockRestPojo.setDateThirty(stockRestPojo.getRealTime() + (30 * 60) - sec - (min % 30 * 60));
+                    } else {
+                        stockRestPojo.setDateThirty(stockRestPojo.getRealTime());
+                    }
+
+                    // 60分钟数据
+                    if (sec != 0 || min % 60 != 0) {
+                        stockRestPojo.setDateSixty(stockRestPojo.getRealTime() + (60 * 60) - sec - (min % 60 * 60));
+                    } else {
+                        stockRestPojo.setDateSixty(stockRestPojo.getRealTime());
+                    }
+                    StringBuffer tableName = new StringBuffer("data_rt_");
+                    tableName.append(entry.getKey().replace(".", "_").toLowerCase());
+                    stockRestPojo.setCode(entry.getKey().toUpperCase());
+                    stockRestPojo.setTableName(tableName.toString());
+                    stockRestPojoList.add(stockRestPojo);
+                    stockRestVO = new StockRestVO();
+                    BeanUtils.copyProperties(stockRestPojo, stockRestVO);
+                    stockRestVOList.add(stockRestVO);
+                    stockRestRedisVO = new StockRestRedisVO();
+                    stockRestRedisVO.setCode(entry.getKey().toUpperCase());
+                    stockRestRedisVO.setNowPrice(stockRestPojo.getNow());
+                    stockRestRedisVO.setChange(stockRestPojo.getChange());
+                    stockRestRedisVO.setHcrate(stockRestPojo.getPctchange());
+
+                    stockRestRedisVO.setHighlimit(stockRestPojo.getHighlimit());
+                    stockRestRedisVO.setLowlimit(stockRestPojo.getLowlimit());
+                    stockRestRedisVOList.add(stockRestRedisVO);
+                }catch (Exception e){
+                    log.error("错误数据导致失败" + e);
+                }
+            }
+            map = null;
+        }
+        // 5.入库
+        insertListInFront(stockRestPojoList, stockRestVOList, stockRestRedisVOList,type);
+        stockRestPojoList = null;
+    }
+
+    private void insertListInFront(List<StockRestPojo> list, List<StockRestVO> stockRestVOList, List<StockRestRedisVO> stockRestRedisVOList,String type) {
+        int insertLength = list.size();
+        int i = 0;
+        int insertSize = 500;
+        while (insertLength > insertSize) {
+            if((!"now".equals(type))){
+                choiceStockMapper.insertBatch(list.subList(i, i + insertSize));
+            }else {
+                choiceStockMapper.insertBatchByAfter(list.subList(i, i + insertSize));
+            }
+            List<StockRestVO> subList = stockRestVOList.subList(i, i + insertSize);
+            List<StockRestRedisVO> subRedisList = stockRestRedisVOList.subList(i, i + insertSize);
+            i = i + insertSize;
+            insertLength = insertLength - insertSize;
+            Thread thread=new Thread(new Runnable() {
+                @Override
+                public void run() {
+//                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
+//                    if(BuyAndSellUtils.isTransState()){
+                    try {
+                        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));
+                        }
+//                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
+                    }catch (Exception e){
+                        log.error("插入redis错误" + e);
+                    }
+//                    }
+
+                }
+            });
+            thread.start();
+        }
+        if (insertLength > 0) {
+            if((!"now".equals(type))){
                 choiceStockMapper.insertBatch(list.subList(i, i + insertLength));
             }else {
                 choiceStockMapper.insertBatchByAfter(list.subList(i, i + insertLength));
@@ -246,13 +493,17 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
                 @Override
                 public void run() {
 //                   HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
-                    if(BuyAndSellUtils.isTransState()){
-                        try {
-                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
-                        }catch (Exception e){
-                            log.error("插入redis错误" + e);
+//                    if(BuyAndSellUtils.isTransState()){
+                    try {
+                        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));
                         }
+//                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
+                    }catch (Exception e){
+                        log.error("插入redis错误" + e);
                     }
+//                    }
                 }
             });
             thread.start();
@@ -260,4 +511,6 @@ public class ChoiceStockServiceImpl implements ChoiceStockService {
     }
 
 
+
+
 }

+ 22 - 14
src/main/java/com/zx/dataservice/service/impl/ChoiceTempIndexServiceImpl.java

@@ -1,13 +1,11 @@
 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.pojo.StockRestPojo;
 import com.zx.dataservice.service.ChoiceTempIndexService;
-import com.zx.dataservice.utils.BuyAndSellUtils;
-import com.zx.dataservice.utils.FileTempIndexUtil;
-import com.zx.dataservice.utils.HttpRequest;
-import com.zx.dataservice.utils.TimeUtil;
+import com.zx.dataservice.utils.*;
 import com.zx.dataservice.vo.StockRestRedisVO;
 import com.zx.dataservice.vo.StockRestVO;
 import org.apache.commons.lang3.StringUtils;
@@ -190,6 +188,8 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
                     stockRestRedisVO.setNowPrice(stockRestPojo.getNow());
                     stockRestRedisVO.setChange(stockRestPojo.getChange());
                     stockRestRedisVO.setHcrate(stockRestPojo.getPctchange());
+                    stockRestRedisVO.setHighlimit(stockRestPojo.getHighlimit());
+                    stockRestRedisVO.setLowlimit(stockRestPojo.getLowlimit());
                     stockRestRedisVOList.add(stockRestRedisVO);
                 }catch (Exception e){
                     log.error("错误数据导致失败" + e);
@@ -222,13 +222,17 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
                 @Override
                 public void run() {
 //                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
-                    if(BuyAndSellUtils.isTransState()) {
-                        try{
-                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
-                        }catch (Exception e){
-                            log.error("插入redis错误" + e);
+//                    if(BuyAndSellUtils.isTransState()){
+                    try {
+                        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));
                         }
+//                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
+                    }catch (Exception e){
+                        log.error("插入redis错误" + e);
                     }
+//                    }
                 }
             });
             thread.start();
@@ -245,13 +249,17 @@ public class ChoiceTempIndexServiceImpl implements ChoiceTempIndexService {
                 @Override
                 public void run() {
 //                    HttpRequest.httpPostWithjson(url, JSON.toJSONString(subList));
-                    if(BuyAndSellUtils.isTransState()) {
-                        try{
-                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
-                        }catch (Exception e){
-                            log.error("插入redis错误" + e);
+//                    if(BuyAndSellUtils.isTransState()){
+                    try {
+                        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));
                         }
+//                            HttpRequest.httpPostWithjson(urlRedis, JSON.toJSONString(subRedisList));
+                    }catch (Exception e){
+                        log.error("插入redis错误" + e);
                     }
+//                    }
                 }
             });
             thread.start();

+ 6 - 0
src/main/java/com/zx/dataservice/task/AnalysisStockRestDataTask.java

@@ -35,5 +35,11 @@ public class AnalysisStockRestDataTask {
         doTask("after");
     }
 
+    @Async("executorInFrontStock")
+    @Scheduled(cron = "0/5 1-30 17 * * ? ")
+    public void toAnalysisRestInFrontData() {
+        this.choiceStockService.analysisStockRestDataInFront("inFront");
+    }
+
 
 }

+ 13 - 0
src/main/java/com/zx/dataservice/task/TaskConfig.java

@@ -87,4 +87,17 @@ public class TaskConfig {
         executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
         return executor;
     }
+
+    @Bean("executorInFrontStock")
+    public Executor taskSchedulerTempInFrontStock() {
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        //核心线程数
+        executor.setCorePoolSize(10);
+        //最大核心线程数
+        executor.setMaxPoolSize(20);
+        //队列中等待被调度的任务数
+        executor.setQueueCapacity(10);
+        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+        return executor;
+    }
 }

+ 3 - 0
src/main/java/com/zx/dataservice/vo/StockRestRedisVO.java

@@ -8,4 +8,7 @@ public class StockRestRedisVO {
     private String nowPrice;
     private String hcrate;
     private String change;
+    private String highlimit;
+    private String lowlimit;
+
 }

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

@@ -29,5 +29,17 @@ spring.datasource.test2.username=root
 spring.datasource.test2.password=TestBicon@123
 spring.datasource.test2.driver-class-name=com.mysql.cj.jdbc.Driver
 
+#
+#spring.datasource.test1.jdbc-Url=jdbc:mysql://127.0.0.1:3306/stock_data?characterEncoding=utf-8&serverTimezone=UTC&allowMultiQueries=true
+#spring.datasource.test1.username=root
+#spring.datasource.test1.password=qlmroot
+#spring.datasource.test1.driver-class-name=com.mysql.cj.jdbc.Driver
+#
+## 数据源2 债券数据库
+#spring.datasource.test2.jdbc-Url=jdbc:mysql://127.0.0.1:3306/stock_data_zhaiquan?characterEncoding=utf-8&serverTimezone=UTC&allowMultiQueries=true
+#spring.datasource.test2.username=root
+#spring.datasource.test2.password=qlmroot
+#spring.datasource.test2.driver-class-name=com.mysql.cj.jdbc.Driver
+
 #是否激活 swagger true or false
 swagger.enable=false