作者 王勇

功能基本完善

@@ -19,9 +19,6 @@ public class MyWebMvcConfigurer implements WebMvcConfigurer { @@ -19,9 +19,6 @@ public class MyWebMvcConfigurer implements WebMvcConfigurer {
19 @Override 19 @Override
20 public void addResourceHandlers(ResourceHandlerRegistry registry) { 20 public void addResourceHandlers(ResourceHandlerRegistry registry) {
21 registry.addResourceHandler("/exit/**").addResourceLocations("file:" + dir + "/"); 21 registry.addResourceHandler("/exit/**").addResourceLocations("file:" + dir + "/");
22 -// registry.addResourceHandler("/exit/excel/**").addResourceLocations("file:excel/");  
23 -// registry.addResourceHandler("/exit/downExcel/**").addResourceLocations("file:excel/");  
24 -// registry.addResourceHandler("/exit/delete/**").addResourceLocations("file:excel/");  
25 WebMvcConfigurer.super.addResourceHandlers(registry); 22 WebMvcConfigurer.super.addResourceHandlers(registry);
26 } 23 }
27 24
@@ -154,7 +154,7 @@ public class NmsController { @@ -154,7 +154,7 @@ public class NmsController {
154 String resultJs = GsonUtils.toJsonStr(resultWs); 154 String resultJs = GsonUtils.toJsonStr(resultWs);
155 sendMsgByWebsocket(resultJs, sid); 155 sendMsgByWebsocket(resultJs, sid);
156 } 156 }
157 - index = index + i - 1; 157 + index = index + i;
158 //完成一次,就等待。每次减1,为0的时候往下执行 158 //完成一次,就等待。每次减1,为0的时候往下执行
159 latch.await(); 159 latch.await();
160 } 160 }
@@ -182,7 +182,6 @@ public class NmsController { @@ -182,7 +182,6 @@ public class NmsController {
182 log.error("获取数据出错", e); 182 log.error("获取数据出错", e);
183 } 183 }
184 final String endTime = sdf.format(new Date()); 184 final String endTime = sdf.format(new Date());
185 - log.info("出港信息,获取完毕,index的值为:" + index);  
186 log.info("结束时间:" + endTime); 185 log.info("结束时间:" + endTime);
187 String resultJs = GsonUtils.toJsonStr(new ResultWs("获取数据,完成", resultList, "200", resultList.size(), resultList.size())); 186 String resultJs = GsonUtils.toJsonStr(new ResultWs("获取数据,完成", resultList, "200", resultList.size(), resultList.size()));
188 sendMsgByWebsocket(resultJs, sid); 187 sendMsgByWebsocket(resultJs, sid);
@@ -251,18 +250,18 @@ public class NmsController { @@ -251,18 +250,18 @@ public class NmsController {
251 result.setAimStation(pm.get(0).getDestinationStation()); 250 result.setAimStation(pm.get(0).getDestinationStation());
252 } 251 }
253 /** 252 /**
254 - * //获取数据仓库的对应数据  
255 -  
256 - // if (result.getWaybillNoMaster() != null && result.getWaybillNoMaster() != "") {}  
257 - ResultExitData dataWareHouseInfo=new ResultExitData(); 253 + * 获取数据仓库的对应数据
  254 + */
  255 + ResultExitData dataWareHouseInfo = new ResultExitData();
258 dataWareHouseInfo = getDataWareHouseFeign.getInfo(result.getWaybillNoMaster()); 256 dataWareHouseInfo = getDataWareHouseFeign.getInfo(result.getWaybillNoMaster());
259 //设置体积 257 //设置体积
260 result.setVolumeMeasure(dataWareHouseInfo.getVolumeMeasure()); 258 result.setVolumeMeasure(dataWareHouseInfo.getVolumeMeasure());
261 //设置计费重量 259 //设置计费重量
262 result.setTotalGrossWeightMeasure(dataWareHouseInfo.getTotalGrossWeightMeasure()); 260 result.setTotalGrossWeightMeasure(dataWareHouseInfo.getTotalGrossWeightMeasure());
263 - */  
264 261
265 - //获取运输工具的对应数据 262 + /**
  263 + * 获取运输工具的对应数据
  264 + */
266 ResultExitData transportInfo = new ResultExitData(); 265 ResultExitData transportInfo = new ResultExitData();
267 transportInfo = getTransportFeign.getInfo(result.getFlightNo(), result.getFlightDate()); 266 transportInfo = getTransportFeign.getInfo(result.getFlightNo(), result.getFlightDate());
268 //设置航班公司 267 //设置航班公司
@@ -278,7 +277,9 @@ public class NmsController { @@ -278,7 +277,9 @@ public class NmsController {
278 //设置航班计划时间 277 //设置航班计划时间
279 result.setFlightPlanTime(transportInfo.getFlightPlanTime()); 278 result.setFlightPlanTime(transportInfo.getFlightPlanTime());
280 279
281 - //获取代理人的相关数据 280 + /**
  281 + * 获取代理人的相关数据
  282 + */
282 ResultExitData asmInfo = new ResultExitData(); 283 ResultExitData asmInfo = new ResultExitData();
283 asmInfo = getCgoAsmFeign.getInfo(result.getWaybillNoMaster()); 284 asmInfo = getCgoAsmFeign.getInfo(result.getWaybillNoMaster());
284 //设置结算代理人 285 //设置结算代理人
@@ -17,11 +17,15 @@ import javax.annotation.Resource; @@ -17,11 +17,15 @@ import javax.annotation.Resource;
17 @RequestMapping("exit") 17 @RequestMapping("exit")
18 @RestController 18 @RestController
19 public class DeleteExcel { 19 public class DeleteExcel {
  20 +
20 @Resource 21 @Resource
21 private DeleteExpiredFile deleteExpiredFile; 22 private DeleteExpiredFile deleteExpiredFile;
22 23
23 -  
24 - // @Scheduled(cron="0 48 18 * * ? ") 24 + /**
  25 + * 每天凌晨4点,执行定时任务,删除缓存的文件
  26 + *
  27 + * @return
  28 + */
25 @Scheduled(cron = "0 0 4 * * ? ") 29 @Scheduled(cron = "0 0 4 * * ? ")
26 @GetMapping("/delete") 30 @GetMapping("/delete")
27 public ResultJson deleteExcel() { 31 public ResultJson deleteExcel() {
@@ -30,7 +30,6 @@ public class DeleteExpiredFile { @@ -30,7 +30,6 @@ public class DeleteExpiredFile {
30 long timeInterval; 30 long timeInterval;
31 31
32 public void deleteExpiredFileTask() { 32 public void deleteExpiredFileTask() {
33 - //File.separator  
34 String path = dir + "/"; 33 String path = dir + "/";
35 File file = new File(path); 34 File file = new File(path);
36 deleteExpiredFile(file); 35 deleteExpiredFile(file);
@@ -70,7 +69,7 @@ public class DeleteExpiredFile { @@ -70,7 +69,7 @@ public class DeleteExpiredFile {
70 // 当前时间的时间戳 69 // 当前时间的时间戳
71 long currentTime = System.currentTimeMillis(); 70 long currentTime = System.currentTimeMillis();
72 // 设置时间范围 71 // 设置时间范围
73 -// long timeInterval = 7 * 24 * 60 * 60 * 1000; 72 + // long timeInterval = 7 * 24 * 60 * 60 * 1000;
74 // 删除七天(一周)前的所有文件 73 // 删除七天(一周)前的所有文件
75 if (currentTime - lastModifiedTime > timeInterval) { 74 if (currentTime - lastModifiedTime > timeInterval) {
76 file.delete(); 75 file.delete();
@@ -15,7 +15,7 @@ public class ExitThreadPoolFactory { @@ -15,7 +15,7 @@ public class ExitThreadPoolFactory {
15 public static ThreadPoolExecutor instance() { 15 public static ThreadPoolExecutor instance() {
16 if (threadPool == null) { 16 if (threadPool == null) {
17 ExitThreadFactory exitThreadFactory = new ExitThreadFactory("exit"); 17 ExitThreadFactory exitThreadFactory = new ExitThreadFactory("exit");
18 - threadPool = new ThreadPoolExecutor(10, 100, 18 + threadPool = new ThreadPoolExecutor(20, 100,
19 0L, TimeUnit.MILLISECONDS, 19 0L, TimeUnit.MILLISECONDS,
20 new LinkedBlockingQueue<Runnable>(1024), 20 new LinkedBlockingQueue<Runnable>(1024),
21 exitThreadFactory, 21 exitThreadFactory,
1 package com.sunyo.wlpt.cgonms.provide.websocket; 1 package com.sunyo.wlpt.cgonms.provide.websocket;
2 2
3 3
4 -  
5 import cn.hutool.log.Log; 4 import cn.hutool.log.Log;
6 import cn.hutool.log.LogFactory; 5 import cn.hutool.log.LogFactory;
7 import com.sunyo.wlpt.cgonms.provide.controller.NmsController; 6 import com.sunyo.wlpt.cgonms.provide.controller.NmsController;
@@ -29,13 +28,17 @@ public class WebSocketServer { @@ -29,13 +28,17 @@ public class WebSocketServer {
29 28
30 static Log log = LogFactory.get(WebSocketServer.class); 29 static Log log = LogFactory.get(WebSocketServer.class);
31 30
32 - //静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。 31 + /**
  32 + * 静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。
  33 + */
33 private static int onlineCount = 0; 34 private static int onlineCount = 0;
34 35
35 //concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。 36 //concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。
36 private static CopyOnWriteArraySet<WebSocketServer> webSocketSet = new CopyOnWriteArraySet<WebSocketServer>(); 37 private static CopyOnWriteArraySet<WebSocketServer> webSocketSet = new CopyOnWriteArraySet<WebSocketServer>();
37 38
38 - //与某个客户端的连接会话,需要通过它来给客户端发送数据 39 + /**
  40 + * 与某个客户端的连接会话,需要通过它来给客户端发送数据
  41 + */
39 private Session session; 42 private Session session;
40 43
41 //接收sid 44 //接收sid
@@ -47,8 +50,10 @@ public class WebSocketServer { @@ -47,8 +50,10 @@ public class WebSocketServer {
47 @OnOpen 50 @OnOpen
48 public void onOpen(Session session, @PathParam("sid") String sid) { 51 public void onOpen(Session session, @PathParam("sid") String sid) {
49 this.session = session; 52 this.session = session;
50 - webSocketSet.add(this); //加入set中  
51 - addOnlineCount(); //在线数加1 53 + //加入set中
  54 + webSocketSet.add(this);
  55 + //在线数加1
  56 + addOnlineCount();
52 log.info("有新窗口开始监听:" + sid + ",当前在线人数为" + getOnlineCount()); 57 log.info("有新窗口开始监听:" + sid + ",当前在线人数为" + getOnlineCount());
53 this.sid = sid; 58 this.sid = sid;
54 try { 59 try {
@@ -64,8 +69,10 @@ public class WebSocketServer { @@ -64,8 +69,10 @@ public class WebSocketServer {
64 */ 69 */
65 @OnClose 70 @OnClose
66 public void onClose() { 71 public void onClose() {
67 - webSocketSet.remove(this); //从set中删除  
68 - subOnlineCount(); //在线数减1 72 + //从set中删除
  73 + webSocketSet.remove(this);
  74 + //在线数减1
  75 + subOnlineCount();
69 log.info("有一连接关闭!当前在线人数为" + getOnlineCount()); 76 log.info("有一连接关闭!当前在线人数为" + getOnlineCount());
70 } 77 }
71 78
@@ -76,11 +83,6 @@ public class WebSocketServer { @@ -76,11 +83,6 @@ public class WebSocketServer {
76 */ 83 */
77 @OnMessage 84 @OnMessage
78 public void onMessage(String message, Session session) { 85 public void onMessage(String message, Session session) {
79 -// JSONObject jsonObj = new JSONObject(message);  
80 -// String flightNo = jsonObj.get("flightNo").toString();  
81 -// String flightDate = jsonObj.get("flightDate").toString();  
82 -  
83 -// nmsController.getData()  
84 log.info("收到来自窗口" + sid + "的信息:" + message); 86 log.info("收到来自窗口" + sid + "的信息:" + message);
85 //群发消息 87 //群发消息
86 for (WebSocketServer item : webSocketSet) { 88 for (WebSocketServer item : webSocketSet) {
@@ -114,7 +116,6 @@ public class WebSocketServer { @@ -114,7 +116,6 @@ public class WebSocketServer {
114 * 群发自定义消息 116 * 群发自定义消息
115 */ 117 */
116 public static void sendInfo(String message, @PathParam("sid") String sid) throws IOException { 118 public static void sendInfo(String message, @PathParam("sid") String sid) throws IOException {
117 - //log.info("推送消息到窗口"+sid+",推送内容:"+message);  
118 for (WebSocketServer item : webSocketSet) { 119 for (WebSocketServer item : webSocketSet) {
119 try { 120 try {
120 //这里可以设定只推送给这个sid的,为null则全部推送 121 //这里可以设定只推送给这个sid的,为null则全部推送