作者 朱兆平

修复IMF客户端异常问题导致不获取数据,优化卡口业务部分代码

@@ -61,3 +61,7 @@ feign.okhttp.enabled=true @@ -61,3 +61,7 @@ feign.okhttp.enabled=true
61 feign.hystrix.enabled=true 61 feign.hystrix.enabled=true
62 # 请求连接超时时间(毫秒) 62 # 请求连接超时时间(毫秒)
63 feign.httpclient.connection-timeout=3000 63 feign.httpclient.connection-timeout=3000
  64 +#码头接口通知地址,注意尾部带/符号
  65 +wharf.interface.host=http://10.50.3.66:1983/
  66 +#新舱单运单查询数据接口,注意尾部带/符号
  67 +nmms.interface.host=http://10.50.3.82:8081/
@@ -18,28 +18,30 @@ public class IMF_Tesk { @@ -18,28 +18,30 @@ public class IMF_Tesk {
18 public static IMFClient client = null; 18 public static IMFClient client = null;
19 19
20 @Scheduled(fixedRate = 5000) 20 @Scheduled(fixedRate = 5000)
21 - private static void start() throws Exception {  
22 - PropertyConfigurator.configure("config/log4j.properties");  
23 - client = IMFClientFactory.createInstance();  
24 - String loginname = FileTool.readProperties("loginname");  
25 - String loginpass = FileTool.readProperties("loginpass");  
26 -  
27 -  
28 - if (client != null) {  
29 - /**  
30 - * 从IMF接收报文  
31 - */  
32 - if (!KAKO_Reader.isrunning) {  
33 - KAKO_Reader kako_reader = new KAKO_Reader(client);  
34 - kako_reader.start();  
35 - logger.info("*********读取线程已开启***********");  
36 - } else {  
37 - logger.info("*********读取线程已开启-不再启动线程*********");  
38 - } 21 + private static void start() {
  22 + //尝试catch SDK异常
  23 + try{
  24 + PropertyConfigurator.configure("config/log4j.properties");
  25 + client = IMFClientFactory.createInstance();
  26 + String loginname = FileTool.readProperties("loginname");
  27 + String loginpass = FileTool.readProperties("loginpass");
  28 +
  29 +
  30 + if (client != null && LOGIN_OK) {
  31 + /**
  32 + * 从IMF接收报文
  33 + */
  34 + if (!KAKO_Reader.isrunning) {
  35 + KAKO_Reader kako_reader = new KAKO_Reader(client);
  36 + kako_reader.start();
  37 + logger.info("*********读取线程重新开启***********");
  38 + } else {
  39 + logger.info("*********读取线程已开启-不再启动线程*********");
  40 + }
39 41
40 - /**  
41 - * 往IMF发送报文  
42 - */ 42 + /**
  43 + * 往IMF发送报文
  44 + */
43 /*if(!KAKO_Sender.isrunning){ 45 /*if(!KAKO_Sender.isrunning){
44 KAKO_Sender kako_sender = new KAKO_Sender(client); 46 KAKO_Sender kako_sender = new KAKO_Sender(client);
45 kako_sender.start(); 47 kako_sender.start();
@@ -48,10 +50,17 @@ public class IMF_Tesk { @@ -48,10 +50,17 @@ public class IMF_Tesk {
48 logger.info("<<<<<<<<<KAKO发送线程已开启-不再启动线程>>>>>>>>>>>>"); 50 logger.info("<<<<<<<<<KAKO发送线程已开启-不再启动线程>>>>>>>>>>>>");
49 }*/ 51 }*/
50 52
  53 + }
  54 + if (!LOGIN_OK){
  55 + loginIMF(client, loginname, loginpass, "config/imf_config.properties");
  56 + }
  57 + }catch (Exception e){
  58 + logger.info("!!!!![IMF-ERROR]-IMF客户端异常!!!!!----->"+ e.toString());
  59 + //异常后短线, 下一次定时任务时重新登录客户端
  60 + client.disconnect();
  61 + LOGIN_OK = false;
51 } 62 }
52 - if (!LOGIN_OK){  
53 - loginIMF(client, loginname, loginpass, "config/imf_config.properties");  
54 - } 63 +
55 64
56 } 65 }
57 66
@@ -2,6 +2,7 @@ package com.sy.IMF; @@ -2,6 +2,7 @@ package com.sy.IMF;
2 2
3 import com.caac.imf.api.IMFClient; 3 import com.caac.imf.api.IMFClient;
4 import com.sy.bwAnalysis.AnalysisRoute; 4 import com.sy.bwAnalysis.AnalysisRoute;
  5 +import org.apache.commons.lang.StringUtils;
5 import org.apache.log4j.Logger; 6 import org.apache.log4j.Logger;
6 7
7 public class KAKO_Reader extends Thread{ 8 public class KAKO_Reader extends Thread{
@@ -13,29 +14,36 @@ public class KAKO_Reader extends Thread{ @@ -13,29 +14,36 @@ public class KAKO_Reader extends Thread{
13 this.client = client; 14 this.client = client;
14 } 15 }
15 16
  17 + @Override
16 public void run() { 18 public void run() {
17 try{ 19 try{
18 isrunning =true; 20 isrunning =true;
  21 + logger.info("********已进入读取线程**********");
19 logger.info("********读取线程状态true**********"); 22 logger.info("********读取线程状态true**********");
  23 + logger.info("********Client-INFO= "+client+"********");
  24 + Thread t =Thread.currentThread();
20 while(true) { 25 while(true) {
21 if (IMF_Tesk.LOGIN_OK){ 26 if (IMF_Tesk.LOGIN_OK){
22 String message = this.client.getMSG(); 27 String message = this.client.getMSG();
23 - logger.info("读取线程已获取到消息");  
24 - if (message != null) { 28 + logger.info(t.toString()+"读取线程已获取到消息");
  29 + if (message != null && StringUtils.isNotEmpty(message)) {
25 // logger.info(message); 30 // logger.info(message);
26 AnalysisRoute.analysis(message); 31 AnalysisRoute.analysis(message);
27 // if(message.indexOf("<TYPE>CARM</TYPE>") > 0){ 32 // if(message.indexOf("<TYPE>CARM</TYPE>") > 0){
28 // this.client.sendMSG(); 33 // this.client.sendMSG();
29 // } 34 // }
  35 + }else {
  36 + logger.info("[READER-INFO]-获取到空消息,不处理");
30 } 37 }
31 } 38 }
32 else { 39 else {
33 - //logger.info("***"); 40 + logger.info("[READER-INFO]-CLIENT为未登录状态,不获取消息!!!!!");
34 } 41 }
35 42
36 try { 43 try {
37 - Thread.sleep(1000L); 44 + Thread.sleep(500L);
38 } catch (InterruptedException var3) { 45 } catch (InterruptedException var3) {
  46 + logger.info("********读取线程循环获取消息异常---->"+var3.toString());
39 var3.printStackTrace(); 47 var3.printStackTrace();
40 48
41 } 49 }
@@ -44,7 +52,7 @@ public class KAKO_Reader extends Thread{ @@ -44,7 +52,7 @@ public class KAKO_Reader extends Thread{
44 }catch (Exception e){ 52 }catch (Exception e){
45 isrunning=false; 53 isrunning=false;
46 logger.info("****************读取线程不在了****************"); 54 logger.info("****************读取线程不在了****************");
47 - logger.info("解析消息出错----------->"+e.toString()); 55 + logger.info("读取线程异常----------->"+e.toString());
48 } 56 }
49 isrunning=false; 57 isrunning=false;
50 } 58 }
@@ -145,7 +145,7 @@ public class AnalysisRoute { @@ -145,7 +145,7 @@ public class AnalysisRoute {
145 v_express_billno billno = clrAnalysis.toBill(message); 145 v_express_billno billno = clrAnalysis.toBill(message);
146 route.clrService.save(billno); 146 route.clrService.save(billno);
147 } else if (stype.equals("IS1")) { 147 } else if (stype.equals("IS1")) {
148 - airone_im_stock imStock = imStockAnalysis.toImStock(message); 148 + airone_im_stock imStock = ImStockAnalysis.toImStock(message);
149 T_AIR_REPERTORY repertory = route.repertoryService.selectByPermaryKey(imStock.getMawbNo()); 149 T_AIR_REPERTORY repertory = route.repertoryService.selectByPermaryKey(imStock.getMawbNo());
150 if(repertory!=null){ 150 if(repertory!=null){
151 repertory.setCnt(repertory.getCnt()+imStock.getCnt()); 151 repertory.setCnt(repertory.getCnt()+imStock.getCnt());
@@ -25,14 +25,16 @@ public class CommandInfoAnalysis { @@ -25,14 +25,16 @@ public class CommandInfoAnalysis {
25 bean.setCheckResult(info.getCheckResult()); 25 bean.setCheckResult(info.getCheckResult());
26 bean.setEsealId(info.getSeal().getEsealId()); 26 bean.setEsealId(info.getSeal().getEsealId());
27 bean.setSealKey(info.getSeal().getSealKey()); 27 bean.setSealKey(info.getSeal().getSealKey());
28 - bean.setVeName(info.getGps().getVeName());  
29 - bean.setGpsId(info.getGps().getGpsId());  
30 - bean.setDestCustoms(info.getGps().getDestCostoms());  
31 - bean.setOriginCustoms(info.getGps().getOpiginCostoms()); 28 + if(info.getGps()!=null){
  29 + bean.setVeName(info.getGps().getVeName());
  30 + bean.setGpsId(info.getGps().getGpsId());
  31 + bean.setDestCustoms(info.getGps().getDestCostoms());
  32 + bean.setOriginCustoms(info.getGps().getOpiginCostoms());
  33 + }
32 bean.setFormId(info.getFormId()); 34 bean.setFormId(info.getFormId());
33 bean.setOpHint(info.getOpHint()); 35 bean.setOpHint(info.getOpHint());
34 36
35 return bean; 37 return bean;
36 } 38 }
37 - 39 +
38 } 40 }
@@ -16,6 +16,7 @@ import org.apache.http.impl.client.DefaultHttpClient; @@ -16,6 +16,7 @@ import org.apache.http.impl.client.DefaultHttpClient;
16 import org.apache.http.util.EntityUtils; 16 import org.apache.http.util.EntityUtils;
17 import org.apache.log4j.PropertyConfigurator; 17 import org.apache.log4j.PropertyConfigurator;
18 import org.springframework.beans.factory.annotation.Autowired; 18 import org.springframework.beans.factory.annotation.Autowired;
  19 +import org.springframework.beans.factory.annotation.Value;
19 import org.springframework.scheduling.annotation.Async; 20 import org.springframework.scheduling.annotation.Async;
20 import org.springframework.stereotype.Component; 21 import org.springframework.stereotype.Component;
21 import org.apache.log4j.Logger; 22 import org.apache.log4j.Logger;
@@ -51,6 +52,12 @@ public class LiftBar { @@ -51,6 +52,12 @@ public class LiftBar {
51 private BusnesslistinfoService busnesslistinfoService; 52 private BusnesslistinfoService busnesslistinfoService;
52 @Autowired 53 @Autowired
53 BusnessViewService busnessViewService; 54 BusnessViewService busnessViewService;
  55 + @Value("${wharf.interface.host}")
  56 + private String wharfHost;
  57 +
  58 + @Value("${nmms.interface.host}")
  59 + private String nmmsHost;
  60 +
54 private static LiftBar logic = new LiftBar(); 61 private static LiftBar logic = new LiftBar();
55 //从配置文件中读取货物重差可控范围 62 //从配置文件中读取货物重差可控范围
56 private static String checkWt = FileTool.readProperties("grossWt"); 63 private static String checkWt = FileTool.readProperties("grossWt");
@@ -77,6 +84,8 @@ public class LiftBar { @@ -77,6 +84,8 @@ public class LiftBar {
77 logic.feignService=this.feignService; 84 logic.feignService=this.feignService;
78 logic.busnesslistinfoService=this.busnesslistinfoService; 85 logic.busnesslistinfoService=this.busnesslistinfoService;
79 logic.busnessViewService=this.busnessViewService; 86 logic.busnessViewService=this.busnessViewService;
  87 + logic.wharfHost=this.wharfHost;
  88 + logic.nmmsHost=this.nmmsHost;
80 } 89 }
81 90
82 /** 91 /**
@@ -269,7 +278,7 @@ public class LiftBar { @@ -269,7 +278,7 @@ public class LiftBar {
269 * @param IEtype 278 * @param IEtype
270 */ 279 */
271 public static void sendData(String stationCode, String carNo, boolean IEtype) { 280 public static void sendData(String stationCode, String carNo, boolean IEtype) {
272 - String url = "http://10.50.3.73:8881/air-api/car/channelCar?stationCode=" + stationCode + "&carNo=" + carNo + "&isPickup=" + IEtype; 281 + String url = logic.wharfHost+"air-api/car/channelCar?stationCode=" + stationCode + "&carNo=" + carNo + "&isPickup=" + IEtype;
273 try { 282 try {
274 HttpClient httpClient = new DefaultHttpClient(); 283 HttpClient httpClient = new DefaultHttpClient();
275 HttpGet httpGet = new HttpGet(url); 284 HttpGet httpGet = new HttpGet(url);
@@ -403,7 +412,7 @@ public class LiftBar { @@ -403,7 +412,7 @@ public class LiftBar {
403 if (!(waybill.indexOf("-") != -1)) { 412 if (!(waybill.indexOf("-") != -1)) {
404 waybill = waybill.substring(0, 3) + "-" + waybill.substring(3); 413 waybill = waybill.substring(0, 3) + "-" + waybill.substring(3);
405 } 414 }
406 - String url = "http://10.50.3.82:8081/orig/orig?waybill=" + waybill + "&imp=" + imp; 415 + String url = logic.nmmsHost+"orig/orig?waybill=" + waybill + "&imp=" + imp;
407 // String url = "http://tjfx.15miaoo.com:8003/tj/orig/orig?waybill=" + waybill + "&imp=" + imp; 416 // String url = "http://tjfx.15miaoo.com:8003/tj/orig/orig?waybill=" + waybill + "&imp=" + imp;
408 StringBuilder json = new StringBuilder(); 417 StringBuilder json = new StringBuilder();
409 Map map = null; 418 Map map = null;
1 package com.sy; 1 package com.sy;
2 2
  3 +import com.sy.bwAnalysis.AnalysisRoute;
  4 +import com.sy.logic.LiftBar;
3 import org.junit.Test; 5 import org.junit.Test;
4 import org.junit.runner.RunWith; 6 import org.junit.runner.RunWith;
5 import org.springframework.boot.test.context.SpringBootTest; 7 import org.springframework.boot.test.context.SpringBootTest;
@@ -9,8 +11,17 @@ import org.springframework.test.context.junit4.SpringRunner; @@ -9,8 +11,17 @@ import org.springframework.test.context.junit4.SpringRunner;
9 @SpringBootTest 11 @SpringBootTest
10 public class AnalysisImfApplicationTests { 12 public class AnalysisImfApplicationTests {
11 13
  14 + private static String message = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
  15 + "<MSG><META><SNDR>KAO</SNDR><RCVR></RCVR><SEQN>20220117192051</SEQN><DDTM>20220117192051</DDTM><TYPE>KAKO</TYPE><STYP>CARM</STYP></META><COMMAND_INFO AREA_ID=\"4604499001\" CHNL_NO=\"4604444412\" I_E_TYPE=\"E\" SEQ_NO=\"20220117192014000017\"><CHECK_RESULT>00000000100000000000</CHECK_RESULT><OP_HINT>直接放行</OP_HINT><SEAL><ESEAL_ID>CNSM2816998419</ESEAL_ID><SEAL_KEY>1234567890</SEAL_KEY><OPEN_TIMES/><ESEAL_IC_NO/></SEAL><SZ_MSG/></COMMAND_INFO></MSG>";
  16 +
12 @Test 17 @Test
13 public void contextLoads() { 18 public void contextLoads() {
  19 + AnalysisRoute.analysis(message);
  20 +
  21 + LiftBar.sendData("1","aaa",true);
  22 +
  23 + System.out.println("99");
14 } 24 }
15 25
  26 +
16 } 27 }