|
|
package com.sunyo.wlpt.cgonms.provide.controller;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
import com.sunyo.wlpt.cgonms.provide.domain.*;
|
...
|
...
|
@@ -16,6 +17,7 @@ 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;
|
...
|
...
|
@@ -96,10 +98,10 @@ public class NmsController { |
|
|
* 2.每個可以返回給前端的消息通過websocket發送回去
|
|
|
*/
|
|
|
String sid = request.getHeader("Authorization");
|
|
|
log.info("token的值:"+sid);
|
|
|
log.info("token的值:" + sid);
|
|
|
final String startTime = sdf.format(new Date());
|
|
|
System.out.println("开始时间:" + startTime);
|
|
|
sendMsgByWebsocket("开始时间:" + startTime,sid);
|
|
|
sendMsgByWebsocket("开始时间:" + startTime, sid);
|
|
|
System.out.println("出港数据,开始获取");
|
|
|
ResultJson resultJson = new ResultJson();
|
|
|
|
...
|
...
|
@@ -123,13 +125,18 @@ public class NmsController { |
|
|
log.trace("获取开始{},剩余数量:{}", startTime, resultList.size());
|
|
|
int i;
|
|
|
for (i = 0; i < THREAD_ACCOUNT; i++) {
|
|
|
ResultExitData result = threadJob(resultList.get(i + index), latch, threadPool);
|
|
|
ResultExitData result = new 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);
|
|
|
|
|
|
int temp = i + index;
|
|
|
ResultWs resultWs = new ResultWs();
|
|
|
resultWs = new ResultWs(sid, "获取数据,第" + temp + "条", result);
|
|
|
String resultJs = JSON.toJSONString(resultWs, SerializerFeature.DisableCircularReferenceDetect);
|
|
|
|
|
|
sendMsgByWebsocket(resultJs, sid);
|
|
|
}
|
|
|
index = index + i;
|
|
|
index = index + i + 1;
|
|
|
//完成一次,就等待。每次减1,为0的时候往下执行
|
|
|
latch.await();
|
|
|
}
|
...
|
...
|
@@ -139,10 +146,15 @@ public class NmsController { |
|
|
log.trace("获取开始{},剩余数量:{}", startTime, resultList.size());
|
|
|
int i;
|
|
|
for (i = 0; i < resultList.size() - index; i++) {
|
|
|
ResultExitData result = threadJob(resultList.get(i + index), latch, threadPool);
|
|
|
int temp=i+index;
|
|
|
String resultJs=JSON.toJSONString(new ResultWs(sid,"获取数据,第"+temp+"条",result));
|
|
|
sendMsgByWebsocket(resultJs,sid);
|
|
|
ResultExitData result = new ResultExitData();
|
|
|
result = threadJob(resultList.get(i + index), latch, threadPool);
|
|
|
|
|
|
int temp = i + index;
|
|
|
ResultWs resultWs = new ResultWs();
|
|
|
resultWs = new ResultWs(sid, "获取数据,第" + temp + "条", result);
|
|
|
|
|
|
String resultJs = JSON.toJSONString(resultWs, SerializerFeature.DisableCircularReferenceDetect);
|
|
|
sendMsgByWebsocket(resultJs, sid);
|
|
|
}
|
|
|
index = index + i;
|
|
|
//完成一次,就等待。每次减1,为0的时候往下执行
|
...
|
...
|
@@ -155,10 +167,15 @@ public class NmsController { |
|
|
CountDownLatch latch = new CountDownLatch(resultList.size());
|
|
|
log.trace("获取开始{},剩余数量:{}", startTime, resultList.size());
|
|
|
for (int i = 0; i < resultList.size(); i++) {
|
|
|
ResultExitData result = threadJob(resultList.get(i), latch, threadPool);
|
|
|
ResultExitData result = new ResultExitData();
|
|
|
result = threadJob(resultList.get(i), latch, threadPool);
|
|
|
|
|
|
resultList.set(i, result);
|
|
|
String resultJs=JSON.toJSONString(new ResultWs(sid,"获取数据,第"+i+"条",result));
|
|
|
sendMsgByWebsocket(resultJs,sid);
|
|
|
ResultWs resultWs = new ResultWs();
|
|
|
resultWs = new ResultWs(sid, "获取数据,第" + i + "条", result);
|
|
|
String resultJs = JSON.toJSONString(resultWs, SerializerFeature.DisableCircularReferenceDetect);
|
|
|
|
|
|
sendMsgByWebsocket(resultJs, sid);
|
|
|
}
|
|
|
//完成一次,就等待。等所有的全部完成,再一起返回
|
|
|
latch.await();
|
...
|
...
|
@@ -174,10 +191,13 @@ public class NmsController { |
|
|
final String endTime = sdf.format(new Date());
|
|
|
|
|
|
System.out.println("结束时间:" + endTime);
|
|
|
sendMsgByWebsocket("出港信息,获取完毕,结束时间:" + endTime,sid);
|
|
|
String resultJs = JSON.toJSONString(new ResultWs(sid, "获取数据,完毕", resultList));
|
|
|
sendMsgByWebsocket(resultJs, sid);
|
|
|
sendMsgByWebsocket("出港信息,获取完毕,结束时间:" + endTime, sid);
|
|
|
|
|
|
resultJson.setCode("200");
|
|
|
resultJson.setData(resultList);
|
|
|
|
|
|
return resultJson;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -193,7 +213,7 @@ public class NmsController { |
|
|
Runnable run = new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
|
|
|
try {
|
|
|
//设置航班
|
|
|
result.setSegment(result.getOriginatingStation() + " — " + result.getDestinationStation());
|
|
|
|
...
|
...
|
@@ -281,16 +301,20 @@ public class NmsController { |
|
|
// if (result.getWaybillNoMaster() != null && result.getWaybillNoMaster() != "") { }
|
|
|
ResultExitData asmInfo = new ResultExitData();
|
|
|
asmInfo = getCgoAsmFeign.getInfo(result.getWaybillNoMaster());
|
|
|
//设置代理人全称
|
|
|
result.setFullName(asmInfo.getFullName());
|
|
|
//设置货主类型
|
|
|
result.setTheShipperType(asmInfo.getTheShipperType());
|
|
|
//设置结算代理人
|
|
|
result.setCountName(asmInfo.getCountName());
|
|
|
//设置订舱代理人
|
|
|
result.setOrderName(asmInfo.getOrderName());
|
|
|
//设置品名
|
|
|
result.setSdCargoName(asmInfo.getSdCargoName());
|
|
|
//设置二级类名称
|
|
|
result.setTwoTypeName(asmInfo.getTwoTypeName());
|
|
|
//设置一级类名称
|
|
|
result.setTypeName(asmInfo.getTypeName());
|
|
|
} catch (Exception e) {
|
|
|
latch.countDown();
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
latch.countDown();
|
|
|
}
|
|
|
};
|
...
|
...
|
@@ -305,9 +329,9 @@ public class NmsController { |
|
|
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
|
|
|
}
|
|
|
|
|
|
private void sendMsgByWebsocket(String msg,String sid){
|
|
|
private void sendMsgByWebsocket(String msg, String sid) {
|
|
|
try {
|
|
|
WebSocketServer.sendInfo(msg,sid);
|
|
|
WebSocketServer.sendInfo(msg, sid);
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
|
...
|
...
|
|