| 1 | package com.sunyo.wlpt.cgonms.provide.controller; | 1 | package com.sunyo.wlpt.cgonms.provide.controller; | 
| 2 |  | 2 |  | 
| 3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; | 
|  |  | 4 | +import com.alibaba.fastjson.serializer.SerializerFeature; | 
| 4 | import com.google.common.collect.Lists; | 5 | import com.google.common.collect.Lists; | 
| 5 |  | 6 |  | 
| 6 | import com.sunyo.wlpt.cgonms.provide.domain.*; | 7 | import com.sunyo.wlpt.cgonms.provide.domain.*; | 
|  | @@ -16,6 +17,7 @@ import lombok.extern.slf4j.Slf4j; |  | @@ -16,6 +17,7 @@ import lombok.extern.slf4j.Slf4j; | 
| 16 | import org.springframework.beans.propertyeditors.CustomDateEditor; | 17 | import org.springframework.beans.propertyeditors.CustomDateEditor; | 
| 17 | import org.springframework.web.bind.WebDataBinder; | 18 | import org.springframework.web.bind.WebDataBinder; | 
| 18 | import org.springframework.web.bind.annotation.*; | 19 | import org.springframework.web.bind.annotation.*; | 
|  |  | 20 | + | 
| 19 | import java.io.IOException; | 21 | import java.io.IOException; | 
| 20 |  | 22 |  | 
| 21 | import javax.annotation.Resource; | 23 | import javax.annotation.Resource; | 
|  | @@ -96,10 +98,10 @@ public class NmsController { |  | @@ -96,10 +98,10 @@ public class NmsController { | 
| 96 | * 2.每個可以返回給前端的消息通過websocket發送回去 | 98 | * 2.每個可以返回給前端的消息通過websocket發送回去 | 
| 97 | */ | 99 | */ | 
| 98 | String sid = request.getHeader("Authorization"); | 100 | String sid = request.getHeader("Authorization"); | 
| 99 | -        log.info("token的值:"+sid); | 101 | +        log.info("token的值:" + sid); | 
| 100 | final String startTime = sdf.format(new Date()); | 102 | final String startTime = sdf.format(new Date()); | 
| 101 | System.out.println("开始时间:" + startTime); | 103 | System.out.println("开始时间:" + startTime); | 
| 102 | -        sendMsgByWebsocket("开始时间:" + startTime,sid); | 104 | +        sendMsgByWebsocket("开始时间:" + startTime, sid); | 
| 103 | System.out.println("出港数据,开始获取"); | 105 | System.out.println("出港数据,开始获取"); | 
| 104 | ResultJson resultJson = new ResultJson(); | 106 | ResultJson resultJson = new ResultJson(); | 
| 105 |  | 107 |  | 
|  | @@ -123,13 +125,18 @@ public class NmsController { |  | @@ -123,13 +125,18 @@ public class NmsController { | 
| 123 | log.trace("获取开始{},剩余数量:{}", startTime, resultList.size()); | 125 | log.trace("获取开始{},剩余数量:{}", startTime, resultList.size()); | 
| 124 | int i; | 126 | int i; | 
| 125 | for (i = 0; i < THREAD_ACCOUNT; i++) { | 127 | for (i = 0; i < THREAD_ACCOUNT; i++) { | 
| 126 | -                            ResultExitData result = threadJob(resultList.get(i + index), latch, threadPool); | 128 | +                            ResultExitData result = new ResultExitData(); | 
|  |  | 129 | +                            result = threadJob(resultList.get(i + index), latch, threadPool); | 
| 127 | resultList.set(i, result); | 130 | resultList.set(i, result); | 
| 128 | -                            int temp=i+index; |  |  | 
| 129 | -                            String resultJs=JSON.toJSONString(new ResultWs(sid,"获取数据,第"+temp+"条",result)); |  |  | 
| 130 | -                            sendMsgByWebsocket(resultJs,sid); | 131 | + | 
|  |  | 132 | +                            int temp = i + index; | 
|  |  | 133 | +                            ResultWs resultWs = new ResultWs(); | 
|  |  | 134 | +                            resultWs = new ResultWs(sid, "获取数据,第" + temp + "条", result); | 
|  |  | 135 | +                            String resultJs = JSON.toJSONString(resultWs, SerializerFeature.DisableCircularReferenceDetect); | 
|  |  | 136 | + | 
|  |  | 137 | +                            sendMsgByWebsocket(resultJs, sid); | 
| 131 | } | 138 | } | 
| 132 | -                        index = index + i; | 139 | +                        index = index + i + 1; | 
| 133 | //完成一次,就等待。每次减1,为0的时候往下执行 | 140 | //完成一次,就等待。每次减1,为0的时候往下执行 | 
| 134 | latch.await(); | 141 | latch.await(); | 
| 135 | } | 142 | } | 
|  | @@ -139,10 +146,15 @@ public class NmsController { |  | @@ -139,10 +146,15 @@ public class NmsController { | 
| 139 | log.trace("获取开始{},剩余数量:{}", startTime, resultList.size()); | 146 | log.trace("获取开始{},剩余数量:{}", startTime, resultList.size()); | 
| 140 | int i; | 147 | int i; | 
| 141 | for (i = 0; i < resultList.size() - index; i++) { | 148 | for (i = 0; i < resultList.size() - index; i++) { | 
| 142 | -                            ResultExitData result = threadJob(resultList.get(i + index), latch, threadPool); |  |  | 
| 143 | -                            int temp=i+index; |  |  | 
| 144 | -                            String resultJs=JSON.toJSONString(new ResultWs(sid,"获取数据,第"+temp+"条",result)); |  |  | 
| 145 | -                            sendMsgByWebsocket(resultJs,sid); | 149 | +                            ResultExitData result = new ResultExitData(); | 
|  |  | 150 | +                            result = threadJob(resultList.get(i + index), latch, threadPool); | 
|  |  | 151 | + | 
|  |  | 152 | +                            int temp = i + index; | 
|  |  | 153 | +                            ResultWs resultWs = new ResultWs(); | 
|  |  | 154 | +                            resultWs = new ResultWs(sid, "获取数据,第" + temp + "条", result); | 
|  |  | 155 | + | 
|  |  | 156 | +                            String resultJs = JSON.toJSONString(resultWs, SerializerFeature.DisableCircularReferenceDetect); | 
|  |  | 157 | +                            sendMsgByWebsocket(resultJs, sid); | 
| 146 | } | 158 | } | 
| 147 | index = index + i; | 159 | index = index + i; | 
| 148 | //完成一次,就等待。每次减1,为0的时候往下执行 | 160 | //完成一次,就等待。每次减1,为0的时候往下执行 | 
|  | @@ -155,10 +167,15 @@ public class NmsController { |  | @@ -155,10 +167,15 @@ public class NmsController { | 
| 155 | CountDownLatch latch = new CountDownLatch(resultList.size()); | 167 | CountDownLatch latch = new CountDownLatch(resultList.size()); | 
| 156 | log.trace("获取开始{},剩余数量:{}", startTime, resultList.size()); | 168 | log.trace("获取开始{},剩余数量:{}", startTime, resultList.size()); | 
| 157 | for (int i = 0; i < resultList.size(); i++) { | 169 | for (int i = 0; i < resultList.size(); i++) { | 
| 158 | -                    ResultExitData result = threadJob(resultList.get(i), latch, threadPool); | 170 | +                    ResultExitData result = new ResultExitData(); | 
|  |  | 171 | +                    result = threadJob(resultList.get(i), latch, threadPool); | 
|  |  | 172 | + | 
| 159 | resultList.set(i, result); | 173 | resultList.set(i, result); | 
| 160 | -                    String resultJs=JSON.toJSONString(new ResultWs(sid,"获取数据,第"+i+"条",result)); |  |  | 
| 161 | -                    sendMsgByWebsocket(resultJs,sid); | 174 | +                    ResultWs resultWs = new ResultWs(); | 
|  |  | 175 | +                    resultWs = new ResultWs(sid, "获取数据,第" + i + "条", result); | 
|  |  | 176 | +                    String resultJs = JSON.toJSONString(resultWs, SerializerFeature.DisableCircularReferenceDetect); | 
|  |  | 177 | + | 
|  |  | 178 | +                    sendMsgByWebsocket(resultJs, sid); | 
| 162 | } | 179 | } | 
| 163 | //完成一次,就等待。等所有的全部完成,再一起返回 | 180 | //完成一次,就等待。等所有的全部完成,再一起返回 | 
| 164 | latch.await(); | 181 | latch.await(); | 
|  | @@ -174,10 +191,13 @@ public class NmsController { |  | @@ -174,10 +191,13 @@ public class NmsController { | 
| 174 | final String endTime = sdf.format(new Date()); | 191 | final String endTime = sdf.format(new Date()); | 
| 175 |  | 192 |  | 
| 176 | System.out.println("结束时间:" + endTime); | 193 | System.out.println("结束时间:" + endTime); | 
| 177 | -        sendMsgByWebsocket("出港信息,获取完毕,结束时间:" + endTime,sid); | 194 | +        String resultJs = JSON.toJSONString(new ResultWs(sid, "获取数据,完毕", resultList)); | 
|  |  | 195 | +        sendMsgByWebsocket(resultJs, sid); | 
|  |  | 196 | +        sendMsgByWebsocket("出港信息,获取完毕,结束时间:" + endTime, sid); | 
| 178 |  | 197 |  | 
| 179 | resultJson.setCode("200"); | 198 | resultJson.setCode("200"); | 
| 180 | resultJson.setData(resultList); | 199 | resultJson.setData(resultList); | 
|  |  | 200 | + | 
| 181 | return resultJson; | 201 | return resultJson; | 
| 182 | } | 202 | } | 
| 183 |  | 203 |  | 
|  | @@ -193,7 +213,7 @@ public class NmsController { |  | @@ -193,7 +213,7 @@ public class NmsController { | 
| 193 | Runnable run = new Runnable() { | 213 | Runnable run = new Runnable() { | 
| 194 | @Override | 214 | @Override | 
| 195 | public void run() { | 215 | public void run() { | 
| 196 | - | 216 | +                try { | 
| 197 | //设置航班 | 217 | //设置航班 | 
| 198 | result.setSegment(result.getOriginatingStation() + " — " + result.getDestinationStation()); | 218 | result.setSegment(result.getOriginatingStation() + " — " + result.getDestinationStation()); | 
| 199 |  | 219 |  | 
|  | @@ -281,16 +301,20 @@ public class NmsController { |  | @@ -281,16 +301,20 @@ public class NmsController { | 
| 281 | //            if (result.getWaybillNoMaster() != null && result.getWaybillNoMaster() != "") { } | 301 | //            if (result.getWaybillNoMaster() != null && result.getWaybillNoMaster() != "") { } | 
| 282 | ResultExitData asmInfo = new ResultExitData(); | 302 | ResultExitData asmInfo = new ResultExitData(); | 
| 283 | asmInfo = getCgoAsmFeign.getInfo(result.getWaybillNoMaster()); | 303 | asmInfo = getCgoAsmFeign.getInfo(result.getWaybillNoMaster()); | 
| 284 | -                //设置代理人全称 |  |  | 
| 285 | -                result.setFullName(asmInfo.getFullName()); |  |  | 
| 286 | -                //设置货主类型 |  |  | 
| 287 | -                result.setTheShipperType(asmInfo.getTheShipperType()); | 304 | +                    //设置结算代理人 | 
|  |  | 305 | +                    result.setCountName(asmInfo.getCountName()); | 
|  |  | 306 | +                    //设置订舱代理人 | 
|  |  | 307 | +                    result.setOrderName(asmInfo.getOrderName()); | 
| 288 | //设置品名 | 308 | //设置品名 | 
| 289 | result.setSdCargoName(asmInfo.getSdCargoName()); | 309 | result.setSdCargoName(asmInfo.getSdCargoName()); | 
| 290 | //设置二级类名称 | 310 | //设置二级类名称 | 
| 291 | result.setTwoTypeName(asmInfo.getTwoTypeName()); | 311 | result.setTwoTypeName(asmInfo.getTwoTypeName()); | 
| 292 | //设置一级类名称 | 312 | //设置一级类名称 | 
| 293 | result.setTypeName(asmInfo.getTypeName()); | 313 | result.setTypeName(asmInfo.getTypeName()); | 
|  |  | 314 | +                } catch (Exception e) { | 
|  |  | 315 | +                    latch.countDown(); | 
|  |  | 316 | +                    e.printStackTrace(); | 
|  |  | 317 | +                } | 
| 294 | latch.countDown(); | 318 | latch.countDown(); | 
| 295 | } | 319 | } | 
| 296 | }; | 320 | }; | 
|  | @@ -305,9 +329,9 @@ public class NmsController { |  | @@ -305,9 +329,9 @@ public class NmsController { | 
| 305 | binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); | 329 | binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); | 
| 306 | } | 330 | } | 
| 307 |  | 331 |  | 
| 308 | -    private void sendMsgByWebsocket(String msg,String sid){ | 332 | +    private void sendMsgByWebsocket(String msg, String sid) { | 
| 309 | try { | 333 | try { | 
| 310 | -            WebSocketServer.sendInfo(msg,sid); | 334 | +            WebSocketServer.sendInfo(msg, sid); | 
| 311 | } catch (IOException e) { | 335 | } catch (IOException e) { | 
| 312 | e.printStackTrace(); | 336 | e.printStackTrace(); | 
| 313 |  | 337 |  |