作者 朱兆平

集成IMF

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