作者 朱兆平

集成IMF

正在显示 111 个修改的文件 包含 319 行增加15 行删除
  1 +#log4j=/home/imf/log_api.xml
  2 +isneedlog=N
  3 +#psip=218.28.199.134
  4 +psip=10.50.3.74
  5 +psport=7484
  6 +encoding=UTF-8
  1 +########Log4j configuration#####################################
  2 +log4j.rootLogger=INFO, stdout, fileout
  3 +
  4 +
  5 +log4j.logger.com.fiscal = INFO
  6 +#*******************************
  7 +log4j.logger.com.system = INFO
  8 +#*******************************
  9 +log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  10 +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
  11 +log4j.appender.stdout.layout.ConversionPattern=%d{MM-dd HH:mm:ss,SSSS}[%p] %m%n
  12 +
  13 +#yyyy-MM-dd HH:mm:ss
  14 +
  15 +
  16 +log4j.appender.fileout=org.apache.log4j.RollingFileAppender
  17 +log4j.appender.fileout.File=logs/imf.log
  18 +log4j.appender.fileout.MaxFileSize=50MB
  19 +log4j.appender.fileout.MaxBackupIndex=10
  20 +log4j.appender.fileout.layout=org.apache.log4j.PatternLayout
  21 +log4j.appender.fileout.layout.ConversionPattern=%d{MM-dd HH:mm:ss,SSSS}[%p] %m%n
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
1 package com.example.demo; 1 package com.example.demo;
2 2
3 -  
4 import org.slf4j.Logger; 3 import org.slf4j.Logger;
5 import org.slf4j.LoggerFactory; 4 import org.slf4j.LoggerFactory;
6 import org.mybatis.spring.annotation.MapperScan; 5 import org.mybatis.spring.annotation.MapperScan;
@@ -11,15 +10,15 @@ import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @@ -11,15 +10,15 @@ import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
11 import org.springframework.scheduling.annotation.EnableScheduling; 10 import org.springframework.scheduling.annotation.EnableScheduling;
12 11
13 12
  13 +
14 @SpringBootApplication 14 @SpringBootApplication
15 @EnableScheduling 15 @EnableScheduling
16 @EnableEurekaClient 16 @EnableEurekaClient
17 @MapperScan("com.example.demo.mapper")//将项目中对应的mapper类的路径加进来就可以了 17 @MapperScan("com.example.demo.mapper")//将项目中对应的mapper类的路径加进来就可以了
18 public class DemoApplication { 18 public class DemoApplication {
  19 + protected static final Logger logger = LoggerFactory.getLogger(DemoApplication.class);
19 20
20 public static void main(String[] args) { 21 public static void main(String[] args) {
21 -  
22 SpringApplication.run(DemoApplication.class, args); 22 SpringApplication.run(DemoApplication.class, args);
23 -  
24 } 23 }
25 } 24 }
  1 +package com.example.demo.handle.IMF;
  2 +
  3 +import com.caac.imf.api.IMFClient;
  4 +import com.example.demo.scheduled.IMF_KAKO_Task;
  5 +import org.apache.log4j.Logger;
  6 +
  7 +public class KAKO_Reader extends Thread{
  8 + protected static final Logger logger = Logger.getLogger(KAKO_Reader.class);
  9 + private IMFClient client;
  10 + public static boolean isrunning;
  11 +
  12 + public KAKO_Reader(IMFClient client) {
  13 + this.client = client;
  14 + }
  15 +
  16 + public void run() {
  17 +
  18 + try{
  19 + isrunning =true;
  20 + while(true) {
  21 + if (IMF_KAKO_Task.LOGIN_OK) {
  22 + synchronized(this) {
  23 + String message = this.client.getMSG();
  24 + if (message != null) {
  25 + logger.info(message);
  26 + }
  27 + }
  28 + } else {
  29 + //logger.info("***");
  30 + }
  31 +
  32 + try {
  33 + Thread.sleep(100L);
  34 + } catch (InterruptedException var3) {
  35 + var3.printStackTrace();
  36 +
  37 + }
  38 + }
  39 +
  40 + }catch (Exception e){
  41 +
  42 + }
  43 + isrunning=false;
  44 + logger.info("****************读取线程不在了****************");
  45 + }
  46 +}
  1 +package com.example.demo.handle.IMF;
  2 +
  3 +import com.caac.imf.api.IMFClient;
  4 +import com.example.demo.scheduled.IMF_KAKO_Task;
  5 +import org.apache.log4j.Logger;
  6 +import org.slf4j.LoggerFactory;
  7 +
  8 +public class KAKO_Sender extends Thread{
  9 +
  10 + protected static final Logger logger = Logger.getLogger(KAKO_Sender.class);
  11 + public static boolean isrunning;
  12 + private IMFClient client;
  13 + public KAKO_Sender(IMFClient client) {
  14 + this.client = client;
  15 + }
  16 + private String SendMsg = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
  17 + "<Msg>\n" +
  18 + "\t<META>\n" +
  19 + "\t\t<SNDR>ZWY</SNDR>\n" +
  20 + "\t\t<RCVR/>\n" +
  21 + "\t\t<SEQN>16078357182</SEQN>\n" +
  22 + "\t\t<DDTM>20181116175107671</DDTM>\n" +
  23 + "\t\t<TYPE>HYXX</TYPE>\n" +
  24 + "\t\t<STYP>NDLR</STYP>\n" +
  25 + "\t</META>\n" +
  26 + "\t<DECLAREPREPAREMASTERXMLBODY>\n" +
  27 + "\t\t<Head>\n" +
  28 + "\t\t\t<MessageID>CN_MT2201_1p1_4604729604327_20181116174636305</MessageID>\n" +
  29 + "\t\t\t<FunctionCode>9</FunctionCode>\n" +
  30 + "\t\t\t<MessageType>MT2201MASTER</MessageType>\n" +
  31 + "\t\t\t<SenderID>460470678920X_DXPENT0000460002_20181116175107671</SenderID>\n" +
  32 + "\t\t\t<ReceiverID>4604_20181116175107671</ReceiverID>\n" +
  33 + "\t\t\t<SendTime>20181116175107671</SendTime>\n" +
  34 + "\t\t\t<Version>1.0</Version>\n" +
  35 + "\t\t</Head>\n" +
  36 + "\t\t<Declaration>\n" +
  37 + "\t\t\t<Carrier>\n" +
  38 + "\t\t\t\t<ID>KA</ID>\n" +
  39 + "\t\t\t</Carrier>\n" +
  40 + "\t\t\t<ORG>\n" +
  41 + "\t\t\t\t<ID>CGO</ID>\n" +
  42 + "\t\t\t</ORG>\n" +
  43 + "\t\t\t<DES>\n" +
  44 + "\t\t\t\t<ID>LAX</ID>\n" +
  45 + "\t\t\t</DES>\n" +
  46 + "\t\t\t<BorderTransportMeans>\n" +
  47 + "\t\t\t\t<JourneyID>749/2018-11-18</JourneyID>\n" +
  48 + "\t\t\t</BorderTransportMeans>\n" +
  49 + "\t\t\t<Consignment>\n" +
  50 + "\t\t\t\t<TransportContractDocument>\n" +
  51 + "\t\t\t\t\t<ID>160-78357182</ID>\n" +
  52 + "\t\t\t\t</TransportContractDocument>\n" +
  53 + "\t\t\t\t<AssociatedTransportDocument>\n" +
  54 + "\t\t\t\t\t<ID/>\n" +
  55 + "\t\t\t\t</AssociatedTransportDocument>\n" +
  56 + "\t\t\t\t<LoadingLocation>\n" +
  57 + "\t\t\t\t\t<ID>CGO/4620</ID>\n" +
  58 + "\t\t\t\t\t<LoadingDate>2018-11-16 21:46</LoadingDate>\n" +
  59 + "\t\t\t\t</LoadingLocation>\n" +
  60 + "\t\t\t\t<UnloadingLocation>\n" +
  61 + "\t\t\t\t\t<ID>CGO/4620</ID>\n" +
  62 + "\t\t\t\t</UnloadingLocation>\n" +
  63 + "\t\t\t\t<TransportSplitIndicator>0</TransportSplitIndicator>\n" +
  64 + "\t\t\t\t<ConsignmentPackaging>\n" +
  65 + "\t\t\t\t\t<QuantityQuantity>1</QuantityQuantity>\n" +
  66 + "\t\t\t\t</ConsignmentPackaging>\n" +
  67 + "\t\t\t\t<TotalGrossMassMeasure>65</TotalGrossMassMeasure>\n" +
  68 + "\t\t\t\t<PreQuantityQuantity>1</PreQuantityQuantity>\n" +
  69 + "\t\t\t\t<PreTotalGrossMassMeasure>65</PreTotalGrossMassMeasure>\n" +
  70 + "\t\t\t\t<CustomsStatus>001</CustomsStatus>\n" +
  71 + "\t\t\t\t<FreightPayment>\n" +
  72 + "\t\t\t\t\t<MethodCode>PP</MethodCode>\n" +
  73 + "\t\t\t\t</FreightPayment>\n" +
  74 + "\t\t\t\t<ProductName>CELL PHONE</ProductName>\n" +
  75 + "\t\t\t\t<PrepareTime>2018-11-16 21:46</PrepareTime>\n" +
  76 + "\t\t\t\t<CustomsCode>4620</CustomsCode>\n" +
  77 + "\t\t\t\t<AgentName>中外运空运发展股份有限公司郑州分公司</AgentName>\n" +
  78 + "\t\t\t\t<AgentCompany>中外运空运发展股份有限公司郑州分公司</AgentCompany>\n" +
  79 + "\t\t\t\t<NameOfgoods>CELL PHONE</NameOfgoods>\n" +
  80 + "\t\t\t\t<DeliveryStation>001</DeliveryStation>\n" +
  81 + "\t\t\t\t<UNnumber/>\n" +
  82 + "\t\t\t\t<Category/>\n" +
  83 + "\t\t\t\t<Consignee>\n" +
  84 + "\t\t\t\t\t<Name>FEDEX TRADE NETWORKS TRANSPORT</Name>\n" +
  85 + "\t\t\t\t\t<Address>\n" +
  86 + "\t\t\t\t\t\t<Line>17210 SOUTH MAIN STREET GARDENA</Line>\n" +
  87 + "\t\t\t\t\t\t<CityName>LOS ANGELES</CityName>\n" +
  88 + "\t\t\t\t\t\t<CountryCode>US</CountryCode>\n" +
  89 + "\t\t\t\t\t\t<ZipCode/>\n" +
  90 + "\t\t\t\t\t\t<PROVINCECODE/>\n" +
  91 + "\t\t\t\t\t\t<PROVINCENAME/>\n" +
  92 + "\t\t\t\t\t\t<Deltaname/>\n" +
  93 + "\t\t\t\t\t\t<TelePhone>3109655000</TelePhone>\n" +
  94 + "\t\t\t\t\t\t<Fax/>\n" +
  95 + "\t\t\t\t\t\t<CNECUSID>EIN+160807223</CNECUSID>\n" +
  96 + "\t\t\t\t\t\t<CNEAEO/>\n" +
  97 + "\t\t\t\t\t\t<Unlodingcode>LAX</Unlodingcode>\n" +
  98 + "\t\t\t\t\t</Address>\n" +
  99 + "\t\t\t\t</Consignee>\n" +
  100 + "\t\t\t\t<Consignor>\n" +
  101 + "\t\t\t\t\t<name>FEDEX</name>\n" +
  102 + "\t\t\t\t\t<Address>\n" +
  103 + "\t\t\t\t\t\t<Line>ROOM7</Line>\n" +
  104 + "\t\t\t\t\t\t<CountryCode>CN</CountryCode>\n" +
  105 + "\t\t\t\t\t\t<ZipCode/>\n" +
  106 + "\t\t\t\t\t\t<Deltaname/>\n" +
  107 + "\t\t\t\t\t\t<TelePhone>8637155131789</TelePhone>\n" +
  108 + "\t\t\t\t\t\t<Fax/>\n" +
  109 + "\t\t\t\t\t\t<SHPAEO/>\n" +
  110 + "\t\t\t\t\t\t<SHPCUSID>USCI+91410100053384175K</SHPCUSID>\n" +
  111 + "\t\t\t\t\t</Address>\n" +
  112 + "\t\t\t\t</Consignor>\n" +
  113 + "\t\t\t</Consignment>\n" +
  114 + "\t\t</Declaration>\n" +
  115 + "\t</DECLAREPREPAREMASTERXMLBODY>\n" +
  116 + "</Msg>";
  117 +
  118 + public void run(){
  119 + try {
  120 +
  121 + if (this.client == null) {
  122 + logger.info("IMFClient has been closed");
  123 + return;
  124 + }
  125 + isrunning=true;
  126 + if(IMF_KAKO_Task.isSuc){
  127 +// logger.info("<<<<<<<<<<<主线程初始化成功>>>>>>>>>>>>");
  128 + if(IMF_KAKO_Task.LOGIN_OK){
  129 +
  130 + String returnMsg = this.client.sendMSG(SendMsg);
  131 + logger.info("《--------发送信息成功开始轮询500mm一次--------"+returnMsg);
  132 + }else{
  133 + logger.info("<<<<<<<<<<<登陆中>>>>>>>>>>>>");
  134 + }
  135 + }
  136 +
  137 + }catch (Exception var14) {
  138 + var14.printStackTrace();
  139 + logger.info(var14.getMessage());
  140 + }
  141 +
  142 +
  143 +
  144 +
  145 + isrunning=false;
  146 + logger.info("<<<<<<<<<<<发送线程不在了>>>>>>>>>>>>");
  147 + }
  148 +}
@@ -2,13 +2,8 @@ package com.example.demo.scheduled; @@ -2,13 +2,8 @@ package com.example.demo.scheduled;
2 2
3 import com.example.demo.handle.T_ETL_FWB_Handle; 3 import com.example.demo.handle.T_ETL_FWB_Handle;
4 import com.example.demo.model.T_ETL_MESSAGE; 4 import com.example.demo.model.T_ETL_MESSAGE;
5 -import com.example.demo.model.T_TXD_FWB;  
6 -import com.example.demo.model.T_TXD_FWBPARTY;  
7 import com.example.demo.service.T_ETL_MESSAGE_Service; 5 import com.example.demo.service.T_ETL_MESSAGE_Service;
8 -import com.example.demo.service.T_TXD_FWB_Service;  
9 -import com.example.demo.util.XML.XML2ENTITY;  
10 -import org.dom4j.Document;  
11 -import org.dom4j.DocumentHelper; 6 +
12 import org.slf4j.Logger; 7 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory; 8 import org.slf4j.LoggerFactory;
14 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.beans.factory.annotation.Autowired;
@@ -16,12 +11,9 @@ import org.springframework.scheduling.annotation.Scheduled; @@ -16,12 +11,9 @@ import org.springframework.scheduling.annotation.Scheduled;
16 import org.springframework.stereotype.Component; 11 import org.springframework.stereotype.Component;
17 12
18 import java.math.BigDecimal; 13 import java.math.BigDecimal;
19 -import java.math.BigInteger;  
20 import java.text.SimpleDateFormat; 14 import java.text.SimpleDateFormat;
21 -import java.time.ZonedDateTime;  
22 import java.util.Date; 15 import java.util.Date;
23 import java.util.List; 16 import java.util.List;
24 -import java.util.Map;  
25 17
26 /** 18 /**
27 * 定时任务 19 * 定时任务
@@ -36,7 +28,7 @@ public class FWBTask { @@ -36,7 +28,7 @@ public class FWBTask {
36 private T_ETL_MESSAGE_Service message_service; 28 private T_ETL_MESSAGE_Service message_service;
37 29
38 // @Scheduled(fixedRate = 5000) 30 // @Scheduled(fixedRate = 5000)
39 - @Scheduled(cron="0/10 * * * * ?") 31 +// @Scheduled(cron="0/10 * * * * ?")
40 public void FWB_analysis(){ 32 public void FWB_analysis(){
41 logger.info("scheduled - fixedRate - print time every 5 seconds:{}", format.format(new Date()) ); 33 logger.info("scheduled - fixedRate - print time every 5 seconds:{}", format.format(new Date()) );
42 34
@@ -71,7 +63,7 @@ public class FWBTask { @@ -71,7 +63,7 @@ public class FWBTask {
71 "0 10,44 14 ? 3 WED" 三月的每周三的14:10和14:44触发 63 "0 10,44 14 ? 3 WED" 三月的每周三的14:10和14:44触发
72 "0 15 10 ? * MON-FRI" 每个周一、周二、周三、周四、周五的10:15触发 64 "0 15 10 ? * MON-FRI" 每个周一、周二、周三、周四、周五的10:15触发
73 */ 65 */
74 - @Scheduled(cron="0/10 * * * * ?") 66 +// @Scheduled(cron="0/10 * * * * ?")
75 public void scheduledCronDemo(){ 67 public void scheduledCronDemo(){
76 logger.info("scheduled - cron - print time every 10 seconds:{}", format.format(new Date()) ); 68 logger.info("scheduled - cron - print time every 10 seconds:{}", format.format(new Date()) );
77 69
  1 +package com.example.demo.scheduled;
  2 +
  3 +import com.caac.imf.api.IMFClient;
  4 +import com.caac.imf.api.IMFClientFactory;
  5 +import com.example.demo.handle.IMF.KAKO_Reader;
  6 +import com.example.demo.handle.IMF.KAKO_Sender;
  7 +import org.apache.log4j.Logger;
  8 +import org.apache.log4j.PropertyConfigurator;
  9 +import org.springframework.scheduling.annotation.Scheduled;
  10 +import org.springframework.stereotype.Component;
  11 +
  12 +@Component
  13 +public class IMF_KAKO_Task {
  14 + protected static final Logger logger = Logger.getLogger(IMF_KAKO_Task.class);
  15 +
  16 + public static boolean LOGIN_OK = false;
  17 + public static boolean isSuc = true;
  18 + public static IMFClient client = null;
  19 +
  20 + @Scheduled(fixedRate = 5000)
  21 + private static void start() throws Exception {
  22 + PropertyConfigurator.configure("config/log4j.properties");
  23 + client = IMFClientFactory.createInstance();
  24 +
  25 +
  26 + if (client != null) {
  27 + if (!KAKO_Reader.isrunning) {
  28 + KAKO_Reader kako_reader = new KAKO_Reader(client);
  29 + kako_reader.start();
  30 + logger.info("*********KAKO读取线程已开启***********");
  31 + } else {
  32 + logger.info("*********KAKO读取线程已开启-不再启动线程*********");
  33 + }
  34 +
  35 + if(!KAKO_Sender.isrunning){
  36 + KAKO_Sender kako_sender = new KAKO_Sender(client);
  37 + kako_sender.start();
  38 + logger.info("<<<<<<<<<KAKO发送线程已开启>>>>>>>>>>>>");
  39 + }else {
  40 + logger.info("<<<<<<<<<KAKO发送线程已开启-不再启动线程>>>>>>>>>>>>");
  41 + }
  42 +
  43 + }
  44 + if (!LOGIN_OK){
  45 + loginIMF(client, "KAKO", "KAKO", "config/imf_config.properties");
  46 + }
  47 +
  48 +
  49 +
  50 + }
  51 +
  52 + private static void loginIMF(IMFClient client, String userName, String password, String confFileName) {
  53 + if (client.initial(confFileName)) {
  54 + String message = client.login(userName, password);
  55 + logger.info("message=" + message);
  56 + if (message.indexOf("<CODE>1</CODE>") > 0) {
  57 + logger.info("登陆成功");
  58 + LOGIN_OK = true;
  59 + } else {
  60 + int times = 0;
  61 +
  62 + while(times <= 3) {
  63 + logger.info("try connection...");
  64 + ++times;
  65 + logger.info("message.=" + message);
  66 + if (message.indexOf("<CODE>1</CODE>") > 0) {
  67 + logger.info("登陆成功");
  68 + LOGIN_OK = true;
  69 + break;
  70 + }
  71 +
  72 + logger.info("登录失败~~~~");
  73 + message = client.login(userName, password);
  74 +
  75 + try {
  76 + Thread.sleep(4000L);
  77 + } catch (InterruptedException var7) {
  78 + var7.printStackTrace();
  79 + }
  80 + }
  81 +
  82 + if (!LOGIN_OK) {
  83 + logger.info("多次尝试登录失败,退出登陆");
  84 + client.disconnect();
  85 + isSuc =false;
  86 + System.exit(-1);
  87 + }
  88 + }
  89 + }
  90 +
  91 + }
  92 +}
@@ -8,7 +8,7 @@ eureka.instance.status-page-url=http://localhost:7002/index @@ -8,7 +8,7 @@ eureka.instance.status-page-url=http://localhost:7002/index
8 #eureka注册中心服务器地址 8 #eureka注册中心服务器地址
9 eureka.client.service-url.defaultZone=http://localhost:7001/eureka/ 9 eureka.client.service-url.defaultZone=http://localhost:7001/eureka/
10 #服务名 10 #服务名
11 -spring.application.name=fileServer-01 11 +spring.application.name=wareHouseAnalysis
12 12
13 #spring.datasource.name=CGOETL 13 #spring.datasource.name=CGOETL
14 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource 14 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource