NC接口优化
This commit is contained in:
parent
0b2ca06ccd
commit
f5182f1eca
@ -1,2 +1,3 @@
|
||||
# 微信推送消息接口路径
|
||||
WechatURL=http://ont.ap-leasing.com/wxapi/template/send
|
||||
# WechatURL=http://ont.ap-leasing.com/wxapi/template/send
|
||||
WechatURL=http://ext.ap-leasing.com/wxapi/template/send
|
||||
@ -10,7 +10,7 @@ voucher_isexchange=Y
|
||||
#接收方
|
||||
voucher_receiver=807001002001
|
||||
#外系统编码
|
||||
voucher_sender=GL
|
||||
voucher_sender=GL
|
||||
#系统参数
|
||||
voucher_replace=Y
|
||||
#凭证类别
|
||||
|
||||
@ -223,7 +223,7 @@ public class VoucherToNCforAssistContract implements Job{
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
Sqlca.rollback();
|
||||
if(batch!=null || !"".equals(batch)){
|
||||
if(batch!=null && !"".equals(batch)){
|
||||
logger.debug("ºÏͬxml´«Êäʧ°Ü");
|
||||
String insertSql="INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','N','"+count+"','"+count+"','"+e.toString()+"','"+year_month_days+"')";
|
||||
Sqlca1.executeSQL(insertSql);
|
||||
@ -429,7 +429,7 @@ public class VoucherToNCforAssistContract implements Job{
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
Sqlca.rollback();
|
||||
if(batch!=null || !"".equals(batch)){
|
||||
if(batch!=null && !"".equals(batch)){
|
||||
logger.debug("ºÏͬxml´«Êäʧ°Ü");
|
||||
String insertSql="INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','N','"+count+"','"+count+"','"+e.toString()+"','"+year_month_days+"')";
|
||||
Sqlca1.executeSQL(insertSql);
|
||||
|
||||
@ -293,7 +293,7 @@ public class VoucherToNCforCustomer implements Job{
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
Sqlca.rollback();
|
||||
if(batch!=null || !"".equals(batch)){
|
||||
if(batch!=null && !"".equals(batch)){
|
||||
logger.debug("客户xml传输失败");
|
||||
String insertSql="INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','N','"+count+"','"+count+"','"+e.toString()+"','"+year_month_days+"')";
|
||||
Sqlca1.executeSQL(insertSql);
|
||||
@ -562,7 +562,7 @@ public class VoucherToNCforCustomer implements Job{
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
Sqlca.rollback();
|
||||
if(batch!=null || !"".equals(batch)){
|
||||
if(batch!=null && !"".equals(batch)){
|
||||
logger.debug("客户xml传输失败");
|
||||
String insertSql="INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','N','"+count+"','"+count+"','"+e.toString()+"','"+year_month_days+"')";
|
||||
Sqlca1.executeSQL(insertSql);
|
||||
|
||||
@ -363,7 +363,7 @@ public class VoucherToNCforDistributor implements Job{
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
Sqlca.rollback();
|
||||
if(batch!=null || !"".equals(batch)){
|
||||
if(batch!=null && !"".equals(batch)){
|
||||
logger.debug("¾ÏúÉÌxml´«Êäʧ°Ü");
|
||||
String insertSql="INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','N','"+count+"','"+count+"','"+e.toString()+"','"+year_month_days+"')";
|
||||
Sqlca1.executeSQL(insertSql);
|
||||
@ -705,7 +705,7 @@ public class VoucherToNCforDistributor implements Job{
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
Sqlca.rollback();
|
||||
if(batch!=null || !"".equals(batch)){
|
||||
if(batch!=null && !"".equals(batch)){
|
||||
logger.debug("¾ÏúÉÌxml´«Êäʧ°Ü");
|
||||
String insertSql="INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','N','"+count+"','"+count+"','"+e.toString()+"','"+year_month_days+"')";
|
||||
Sqlca1.executeSQL(insertSql);
|
||||
|
||||
@ -3,17 +3,13 @@ package com.tenwa.voucher.serviceImp;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
@ -47,8 +43,6 @@ import com.amarsoft.are.jbo.JBOFactory;
|
||||
import com.amarsoft.are.jbo.JBOTransaction;
|
||||
import com.amarsoft.are.log.Log;
|
||||
import com.amarsoft.awe.util.Transaction;
|
||||
import com.base.util.QuartzUtil;
|
||||
import com.tenwa.comm.util.date.DateAssistant;
|
||||
import com.tenwa.comm.util.jboutil.DataOperatorUtil;
|
||||
import com.tenwa.httpclient.resources.VouchersPropertiesUtil;
|
||||
import com.tenwa.util.SerialNumberUtil;
|
||||
@ -63,13 +57,9 @@ public class VoucherToNCforVoucherPZ implements Job{
|
||||
* 定时任务凭证NC传输
|
||||
*/
|
||||
public void execute(JobExecutionContext arg0) throws JobExecutionException {
|
||||
// 获取当前日期
|
||||
String plan_date = DateAssistant.getToday();
|
||||
// 获取当前用户id
|
||||
Object userId = arg0.getTrigger().getJobDataMap().get("CurUserId");
|
||||
String curUserId = userId == null? "system" : userId.toString();
|
||||
// 获取回执信息判断成功与否
|
||||
String ss = DOM4JcreateToVoucher();
|
||||
String returns = DOM4JcreateToVoucher();
|
||||
System.out.println(returns);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,7 +73,7 @@ public class VoucherToNCforVoucherPZ implements Job{
|
||||
}
|
||||
|
||||
/**
|
||||
* 凭证信息xml生成, 每1000条生成一个xml
|
||||
* 凭证信息xml生成, 每100条生成一个xml
|
||||
* @throws Exception
|
||||
*/
|
||||
private static String DOM4JcreateToVoucher(){
|
||||
@ -93,8 +83,6 @@ public class VoucherToNCforVoucherPZ implements Job{
|
||||
Transaction Sqlca = null;
|
||||
Transaction Sqlca1 = null;
|
||||
String returns="true";
|
||||
// 获取配置文件的输入流
|
||||
FileInputStream in=null;
|
||||
//用于记录异常
|
||||
File file1 = null;
|
||||
PrintStream stream = null;
|
||||
@ -116,6 +104,7 @@ public class VoucherToNCforVoucherPZ implements Job{
|
||||
Sqlca = Transaction.createTransaction(tx);
|
||||
Sqlca1 = Transaction.createTransaction(tx1);
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
List<String> conList=new ArrayList<String>();
|
||||
/**
|
||||
* 读取配置文件信息
|
||||
* */
|
||||
@ -214,7 +203,6 @@ public class VoucherToNCforVoucherPZ implements Job{
|
||||
for (int x = i * b; x < (i + 1) * b && x < a; x++) { // 决定当前xml生成的数据量
|
||||
// 获取凭证编号
|
||||
String F3=list.get(x).get("f3");
|
||||
String F60=list.get(x).get("f60");
|
||||
map.clear();
|
||||
map.put("F3",F3);
|
||||
|
||||
@ -238,6 +226,7 @@ public class VoucherToNCforVoucherPZ implements Job{
|
||||
//BizObject own = JBOFactory.createBizObjectQuery(OWN_INFO.CLASS_NAME, "id=:OWNED_COMPANY").setParameter("OWNED_COMPANY", OWNED_COMPANY).getSingleResult(false);
|
||||
//uuid=UUID.randomUUID().toString().replace("-", "");
|
||||
uuid=list.get(x).get("id");
|
||||
|
||||
Element voucher = root.addElement("voucher");
|
||||
voucher.addAttribute("id",uuid);
|
||||
Element voucherHead = voucher.addElement("voucher_head");
|
||||
@ -536,6 +525,8 @@ public class VoucherToNCforVoucherPZ implements Job{
|
||||
}else {
|
||||
// 统计旧批次
|
||||
String batch1= record.getAttribute("BATCH").getString();
|
||||
// 记录当前旧批次id
|
||||
conList.add(uuid);
|
||||
// 初始化将就数据描述信息变更为: 传输失败 , 请联系管理员
|
||||
String updSql="UPDATE NCXML_DETAIL_RECORDS SET FLAG='2',ERR_DESCRIBE='传输失败 , 请联系管理员 !',CREATE_TIME='"+year_month_days+"' WHERE BILLID='"+uuid+"' AND XML_TYPE= '"+type+"' AND BATCH='"+batch1+"'";
|
||||
Sqlca1.executeSQL(updSql);
|
||||
@ -556,27 +547,11 @@ public class VoucherToNCforVoucherPZ implements Job{
|
||||
writer.setEscapeText(false);// 字符是否转义,默认true
|
||||
writer.write(document);
|
||||
writer.close();
|
||||
InterActionToNC(Sqlca,URL,type,batch,count,batchList);
|
||||
InterActionToNC(Sqlca,URL,type,batch,count,conList,batchList);
|
||||
Sqlca.commit();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.info("凭证xml传输失败");
|
||||
try {
|
||||
Sqlca.rollback();
|
||||
if(batch!=null || !"".equals(batch)){
|
||||
logger.debug("凭证xml传输失败");
|
||||
String insertSql="INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','N','"+count+"','"+count+"','"+e.toString()+"','"+year_month_days+"')";
|
||||
Sqlca1.executeSQL(insertSql);
|
||||
Sqlca1.commit();
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
/*try {
|
||||
new PrintWriter(new BufferedWriter(new FileWriter("E:/log.txt",true)),true).println(e.toString());
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}*/
|
||||
// 异常记录路径
|
||||
file1=new File(ERROR_URL+"NC_ERROR-VOUCHER-"+year_month_day+".txt");
|
||||
try {
|
||||
@ -613,17 +588,21 @@ public class VoucherToNCforVoucherPZ implements Job{
|
||||
/**
|
||||
* 向NC传输xml, 获取NC回执xml信息, 根据回执信息更改状态
|
||||
*/
|
||||
public static void InterActionToNC(Transaction Sqlca,String inputURL,String type,String batch,int count,List<String> batchList) throws Exception {
|
||||
String updSql=""; // 更新历史记录
|
||||
String updateSql = ""; // 更新sql对象
|
||||
String insertSql = ""; // 新增SQL对象
|
||||
String resultcode= ""; // 单条返回结果
|
||||
String bdocid = ""; // xml回执id
|
||||
String resultdescription=""; //错误信息
|
||||
String NC_URL = VouchersPropertiesUtil.get("NC_URL");// ip地址及端口号
|
||||
String account = VouchersPropertiesUtil.get("account");
|
||||
String groupcode = VouchersPropertiesUtil.get("groupcode");
|
||||
String RECEIVE_URL = VouchersPropertiesUtil.get("RECEIVE_URL"); //回执信息存放路径
|
||||
public static void InterActionToNC(Transaction Sqlca,String inputURL,String type,String batch,int count,List<String> conList,List<String> batchList) throws Exception {
|
||||
String updSql=""; // 更新历史记录
|
||||
String updateSql = ""; // 更新sql对象
|
||||
String insertSql = ""; // 新增SQL对象
|
||||
String resultcode= ""; // 单条返回结果
|
||||
String bdocid = ""; // xml回执id
|
||||
String resultdescription="";// 错误信息
|
||||
String NC_URL = VouchersPropertiesUtil.get("NC_URL"); // ip地址及端口号
|
||||
String account = VouchersPropertiesUtil.get("account"); // 账套
|
||||
String groupcode = VouchersPropertiesUtil.get("groupcode"); // 集团编码
|
||||
String RECEIVE_URL = VouchersPropertiesUtil.get("RECEIVE_URL"); // 回执信息存放路径
|
||||
String ERROR_URL = VouchersPropertiesUtil.get("ERROR_URL"); // 错误信息存放路径
|
||||
String year_month_day = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); // 用于文件名凭借
|
||||
String year_month_days = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());// 明细表时间记录
|
||||
|
||||
/**
|
||||
* 获取对方post连接
|
||||
*/
|
||||
@ -634,39 +613,69 @@ public class VoucherToNCforVoucherPZ implements Job{
|
||||
connection.setDoOutput(true);
|
||||
connection.setRequestProperty("Content-type", "text/xml");
|
||||
connection.setRequestMethod("POST");
|
||||
//connection.setConnectTimeout(1*1);
|
||||
//connection.setConnectTimeout(600000);
|
||||
//connection.setReadTimeout(600000);
|
||||
|
||||
/**
|
||||
* 读取本方生成的xml, 传输到NC
|
||||
*/
|
||||
File file = new File(inputURL);
|
||||
BufferedOutputStream out = new BufferedOutputStream(connection.getOutputStream());
|
||||
BufferedInputStream input = new BufferedInputStream(new FileInputStream(file));
|
||||
int length;
|
||||
byte[] buffer = new byte[1000];
|
||||
while ((length = input.read(buffer, 0, 1000)) != -1) {
|
||||
out.write(buffer, 0, length);
|
||||
}
|
||||
input.close();
|
||||
out.close();
|
||||
/**
|
||||
* 获取NC回执信息
|
||||
*/
|
||||
System.out.println("-------------开始获取回执信息--------------");
|
||||
InputStream inputStream = connection.getInputStream();
|
||||
InputStreamReader isr = new InputStreamReader(inputStream,"UTF-8");
|
||||
BufferedReader bufreader = new BufferedReader(isr);
|
||||
String xmlString = "";
|
||||
String b=null;
|
||||
while((b=bufreader.readLine()) !=null) {
|
||||
xmlString+=b;
|
||||
xmlString+="\r\n";
|
||||
try {
|
||||
File file = new File(inputURL);
|
||||
BufferedOutputStream out = new BufferedOutputStream(connection.getOutputStream());
|
||||
BufferedInputStream input = new BufferedInputStream(new FileInputStream(file));
|
||||
int length;
|
||||
byte[] buffer = new byte[1000];
|
||||
while ((length = input.read(buffer, 0, 1000)) != -1) {
|
||||
out.write(buffer, 0, length);
|
||||
}
|
||||
input.close();
|
||||
out.close();
|
||||
/**
|
||||
* 获取NC回执信息
|
||||
*/
|
||||
System.out.println("-------------开始获取回执信息--------------");
|
||||
InputStream inputStream = connection.getInputStream();
|
||||
InputStreamReader isr = new InputStreamReader(inputStream,"UTF-8");
|
||||
BufferedReader bufreader = new BufferedReader(isr);
|
||||
|
||||
String b=null;
|
||||
while((b=bufreader.readLine()) !=null) {
|
||||
xmlString+=b;
|
||||
xmlString+="\r\n";
|
||||
}
|
||||
System.out.println("-------------获取回执信息完成--------------");
|
||||
System.out.println(xmlString);
|
||||
bufreader.close();
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.info("凭证xml传输失败");
|
||||
try {
|
||||
if(batch!=null && !"".equals(batch)){
|
||||
logger.debug("凭证xml传输失败");
|
||||
insertSql="INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','N','"+count+"','"+count+"','"+e.toString()+"','"+year_month_days+"')";
|
||||
Sqlca.executeSQL(insertSql);
|
||||
Sqlca.commit();
|
||||
}
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
/*try {
|
||||
new PrintWriter(new BufferedWriter(new FileWriter("E:/log.txt",true)),true).println(e.toString());
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}*/
|
||||
// 异常记录路径
|
||||
File file=new File(ERROR_URL+"NC_ERROR-VOUCHER-"+year_month_day+".txt");
|
||||
PrintStream stream =null;
|
||||
try {
|
||||
stream = new PrintStream(file);
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
e.printStackTrace(stream);
|
||||
stream.flush();
|
||||
stream.close();
|
||||
throw new Exception("推送失败!");
|
||||
}
|
||||
System.out.println("-------------获取回执信息完成--------------");
|
||||
System.out.println(xmlString);
|
||||
bufreader.close();
|
||||
/**
|
||||
* 将获取到的回执信息生成本地xml
|
||||
*/
|
||||
@ -796,11 +805,25 @@ public class VoucherToNCforVoucherPZ implements Job{
|
||||
}
|
||||
// 判断集合为否为null, 不为空遍历集合, 获取旧数据的批次号
|
||||
if(batchList != null) {
|
||||
// 变更传输状态
|
||||
for(String billid : conList){
|
||||
updSql="UPDATE NCXML_DETAIL_RECORDS SET FLAG='1',ERR_DESCRIBE='传输成功 !' WHERE XML_TYPE= '"+type+"' AND BILLID='"+billid+"'";
|
||||
Sqlca.executeSQL(updSql);
|
||||
}
|
||||
// 定义当前批次, 错误记录数
|
||||
for (String old_batch : batchList) {
|
||||
updateSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='1',ERR_DESCRIBE='传输成功 !' WHERE XML_TYPE= '"+type+"' AND BATCH='"+old_batch+"'";
|
||||
Sqlca.executeSQL(updateSql);
|
||||
updateSql="UPDATE NCXML_TOTAL_RECORDS SET FLAG_='Y',FAILED_COUNT='0',ERR_DESCRIBE='"+resultdescription+"',CREATETIME='"+formatter2.format(new Date())+"' WHERE XML_TYPE='"+type+"' AND BATCH='"+old_batch+"'";
|
||||
int con=0;
|
||||
// 查询集合, 获取旧批次的失败总数
|
||||
String selectSql="SELECT BATCH,COUNT(BILLID) CON FROM ncxml_detail_records WHERE flag !=1 AND xml_type='"+type+"' AND BATCH='"+old_batch+"' GROUP BY BATCH";
|
||||
List<Map<String,String>> dataList=DataOperatorUtil.getDataBySql(Sqlca, selectSql,null);
|
||||
if(dataList!=null && dataList.size()>0) {
|
||||
con=Integer.valueOf(dataList.get(0).get("CON"));
|
||||
}
|
||||
if(con==0) {
|
||||
updateSql="UPDATE NCXML_TOTAL_RECORDS SET FLAG_='Y',FAILED_COUNT='0',ERR_DESCRIBE='"+resultdescription+"',CREATETIME='"+formatter2.format(new Date())+"' WHERE XML_TYPE='"+type+"' AND BATCH='"+old_batch+"'";
|
||||
}else {
|
||||
updateSql="UPDATE NCXML_TOTAL_RECORDS SET FAILED_COUNT='"+con+"',ERR_DESCRIBE='"+resultdescription+"',CREATETIME='"+formatter2.format(new Date())+"' WHERE XML_TYPE='"+type+"' AND BATCH='"+old_batch+"'";
|
||||
}
|
||||
Sqlca.executeSQL(updateSql);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user