| 
 | 
 | 
 package com.sunyo.wlpt.cgonms.provide.controller;
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 import com.alibaba.fastjson.JSON;
 | 
| 
 | 
 | 
 import com.google.common.collect.Lists;
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 import com.sunyo.wlpt.cgonms.provide.domain.*;
 | 
| 
...
 | 
...
 | 
@@ -7,14 +8,19 @@ import com.sunyo.wlpt.cgonms.provide.feign.GetCgoAsmFeign; | 
| 
 | 
 | 
 import com.sunyo.wlpt.cgonms.provide.feign.GetDataWareHouseFeign;
 | 
| 
 | 
 | 
 import com.sunyo.wlpt.cgonms.provide.feign.GetTransportFeign;
 | 
| 
 | 
 | 
 import com.sunyo.wlpt.cgonms.provide.response.ResultJson;
 | 
| 
 | 
 | 
 import com.sunyo.wlpt.cgonms.provide.response.ResultWs;
 | 
| 
 | 
 | 
 import com.sunyo.wlpt.cgonms.provide.service.*;
 | 
| 
 | 
 | 
 import com.sunyo.wlpt.cgonms.provide.thread.ExitThreadPoolFactory;
 | 
| 
 | 
 | 
 import com.sunyo.wlpt.cgonms.provide.websocket.WebSocketServer;
 | 
| 
 | 
 | 
 import lombok.extern.slf4j.Slf4j;
 | 
| 
 | 
 | 
 import org.springframework.beans.propertyeditors.CustomDateEditor;
 | 
| 
 | 
 | 
 import org.springframework.web.bind.WebDataBinder;
 | 
| 
 | 
 | 
 import org.springframework.web.bind.annotation.*;
 | 
| 
 | 
 | 
 import java.io.IOException;
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 import javax.annotation.Resource;
 | 
| 
 | 
 | 
 import javax.servlet.http.HttpServletRequest;
 | 
| 
 | 
 | 
 import java.io.IOException;
 | 
| 
 | 
 | 
 import java.text.SimpleDateFormat;
 | 
| 
 | 
 | 
 import java.util.Date;
 | 
| 
 | 
 | 
 import java.util.List;
 | 
| 
...
 | 
...
 | 
@@ -55,6 +61,7 @@ public class NmsController { | 
| 
 | 
 | 
     @Resource
 | 
| 
 | 
 | 
     GetDataWareHouseFeign getDataWareHouseFeign;
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
     /**
 | 
| 
 | 
 | 
      * 线程数量
 | 
| 
 | 
 | 
      */
 | 
| 
...
 | 
...
 | 
@@ -81,10 +88,18 @@ public class NmsController { | 
| 
 | 
 | 
     @GetMapping("/getInfo")
 | 
| 
 | 
 | 
     public ResultJson getData(
 | 
| 
 | 
 | 
             @RequestParam(value = "flightDate", required = false) Date flightDate,
 | 
| 
 | 
 | 
             @RequestParam(value = "flightNo", required = false) String flightNo) {
 | 
| 
 | 
 | 
             @RequestParam(value = "flightNo", required = false) String flightNo,
 | 
| 
 | 
 | 
             HttpServletRequest request) {
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
         /**
 | 
| 
 | 
 | 
          * 1.取token作爲websocket的sid
 | 
| 
 | 
 | 
          * 2.每個可以返回給前端的消息通過websocket發送回去
 | 
| 
 | 
 | 
          */
 | 
| 
 | 
 | 
         String sid = request.getHeader("Authorization");
 | 
| 
 | 
 | 
         log.info("token的值:"+sid);
 | 
| 
 | 
 | 
         final String startTime = sdf.format(new Date());
 | 
| 
 | 
 | 
         System.out.println("开始时间:" + startTime);
 | 
| 
 | 
 | 
         sendMsgByWebsocket("开始时间:" + startTime,sid);
 | 
| 
 | 
 | 
         System.out.println("出港数据,开始获取");
 | 
| 
 | 
 | 
         ResultJson resultJson = new ResultJson();
 | 
| 
 | 
 | 
 
 | 
| 
...
 | 
...
 | 
@@ -110,6 +125,9 @@ public class NmsController { | 
| 
 | 
 | 
                         for (i = 0; i < THREAD_ACCOUNT; i++) {
 | 
| 
 | 
 | 
                             ResultExitData result = threadJob(resultList.get(i + index), latch, threadPool);
 | 
| 
 | 
 | 
                             resultList.set(i, result);
 | 
| 
 | 
 | 
                             int temp=i+index;
 | 
| 
 | 
 | 
                             String resultJs=JSON.toJSONString(new ResultWs(sid,"获取数据,第"+temp+"条",result));
 | 
| 
 | 
 | 
                             sendMsgByWebsocket(resultJs,sid);
 | 
| 
 | 
 | 
                         }
 | 
| 
 | 
 | 
                         index = index + i;
 | 
| 
 | 
 | 
                         //完成一次,就等待。每次减1,为0的时候往下执行
 | 
| 
...
 | 
...
 | 
@@ -122,7 +140,9 @@ public class NmsController { | 
| 
 | 
 | 
                         int i;
 | 
| 
 | 
 | 
                         for (i = 0; i < resultList.size() - index; i++) {
 | 
| 
 | 
 | 
                             ResultExitData result = threadJob(resultList.get(i + index), latch, threadPool);
 | 
| 
 | 
 | 
                             resultList.set(i, result);
 | 
| 
 | 
 | 
                             int temp=i+index;
 | 
| 
 | 
 | 
                             String resultJs=JSON.toJSONString(new ResultWs(sid,"获取数据,第"+temp+"条",result));
 | 
| 
 | 
 | 
                             sendMsgByWebsocket(resultJs,sid);
 | 
| 
 | 
 | 
                         }
 | 
| 
 | 
 | 
                         index = index + i;
 | 
| 
 | 
 | 
                         //完成一次,就等待。每次减1,为0的时候往下执行
 | 
| 
...
 | 
...
 | 
@@ -137,6 +157,8 @@ public class NmsController { | 
| 
 | 
 | 
                 for (int i = 0; i < resultList.size(); i++) {
 | 
| 
 | 
 | 
                     ResultExitData result = threadJob(resultList.get(i), latch, threadPool);
 | 
| 
 | 
 | 
                     resultList.set(i, result);
 | 
| 
 | 
 | 
                     String resultJs=JSON.toJSONString(new ResultWs(sid,"获取数据,第"+i+"条",result));
 | 
| 
 | 
 | 
                     sendMsgByWebsocket(resultJs,sid);
 | 
| 
 | 
 | 
                 }
 | 
| 
 | 
 | 
                 //完成一次,就等待。等所有的全部完成,再一起返回
 | 
| 
 | 
 | 
                 latch.await();
 | 
| 
...
 | 
...
 | 
@@ -146,10 +168,14 @@ public class NmsController { | 
| 
 | 
 | 
             log.error("获取目录文件出错", e);
 | 
| 
 | 
 | 
         }
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
         final String endTime = sdf.format(new Date());
 | 
| 
 | 
 | 
         System.out.println("结束时间:" + endTime);
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
         System.out.println("出港信息,获取完毕");
 | 
| 
 | 
 | 
         System.out.println("index的值为:" + index);
 | 
| 
 | 
 | 
         final String endTime = sdf.format(new Date());
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
         System.out.println("结束时间:" + endTime);
 | 
| 
 | 
 | 
         sendMsgByWebsocket("出港信息,获取完毕,结束时间:" + endTime,sid);
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
         resultJson.setCode("200");
 | 
| 
 | 
 | 
         resultJson.setData(resultList);
 | 
| 
 | 
 | 
         return resultJson;
 | 
| 
...
 | 
...
 | 
@@ -278,4 +304,13 @@ public class NmsController { | 
| 
 | 
 | 
         dateFormat.setLenient(false);
 | 
| 
 | 
 | 
         binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
 | 
| 
 | 
 | 
     }
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
     private void sendMsgByWebsocket(String msg,String sid){
 | 
| 
 | 
 | 
         try {
 | 
| 
 | 
 | 
             WebSocketServer.sendInfo(msg,sid);
 | 
| 
 | 
 | 
         } catch (IOException e) {
 | 
| 
 | 
 | 
             e.printStackTrace();
 | 
| 
 | 
 | 
 
 | 
| 
 | 
 | 
         }
 | 
| 
 | 
 | 
     }
 | 
| 
 | 
 | 
 } | 
...
 | 
...
 | 
 |