凭证相关--与nc对接的4个接口优化

This commit is contained in:
xiezhiwen 2019-07-09 18:32:14 +08:00
parent cabe00b3c1
commit 2a09455537
4 changed files with 381 additions and 222 deletions

View File

@ -17,10 +17,12 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
@ -31,6 +33,7 @@ import org.dom4j.io.XMLWriter;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import com.amarsoft.are.ARE;
import com.amarsoft.are.jbo.BizObject;
import com.amarsoft.are.jbo.JBOException;
@ -56,12 +59,26 @@ public class VoucherToNCforAssistContract implements Job{
Object userId = arg0.getTrigger().getJobDataMap().get("CurUserId");
String curUserId = userId == null? "system" : userId.toString();
// 定义事物
JBOTransaction tx1=null;
JBOTransaction tx=null;
Transaction Sqlca1 = null;
Transaction Sqlca = null;
// 获取配置文件的输入流
FileInputStream in=null;
// xml类别
String type="contract";
// 批次号
String batch = "";
// 文件名称
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());// 年月日时分秒
// 记录当前批次传输总量
int count=0;
try {
tx1= JBOFactory.createJBOTransaction();
tx= JBOFactory.createJBOTransaction();
Sqlca1 = Transaction.createTransaction(tx1);
Sqlca = Transaction.createTransaction(tx);
/**
* 读取配置文件信息
@ -109,14 +126,7 @@ public class VoucherToNCforAssistContract implements Job{
String insertSql="";
// 合同编码对象
String contract_number="";
// xml类别
String type="contract";
// 文件名称
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());// 年月日时分秒
// 记录当前批次传输总量
int count=0;
// 记录历史批次号
List<String> batchList= new ArrayList<String>();
@ -124,8 +134,6 @@ public class VoucherToNCforAssistContract implements Job{
String sql="SELECT id,CONTRACT_NUMBER FROM LB_CONTRACT_INFO WHERE CONTRACT_STATUS='31' AND CONTRACT_NUMBER NOT IN(SELECT TABLE_NUM FROM NCXML_DETAIL_RECORDS WHERE FLAG = '1' AND XML_TYPE='"+type+"')";
List<Map<String, String>> rs = DataOperatorUtil.getDataBySql(Sqlca,sql,null);
if(rs!=null && rs.size()>0) {
// 批次号
String batch = "";
// 生成xml头
Document document = DocumentHelper.createDocument(); // 生成每个xml的头
Element root = document.addElement("ufinterface");
@ -174,22 +182,23 @@ public class VoucherToNCforAssistContract implements Job{
// 等于null说明新数据, 新增入记录表
if(record==null || "".equals(record)) {
if("".equals(batch)) {
batch = SerialNumberUtil.getVoucherPCNumber(Sqlca);
batch = SerialNumberUtil.getVoucherPCNumber(Sqlca1);
}
insertSql="INSERT INTO NCXML_DETAIL_RECORDS(BILLID,XML_TYPE,TABLE_NUM,FLAG,CREATE_TIME,BATCH) VALUES('"+uuid+"','"+type+"','"+contract_number+"','1','"+year_month_days+"','"+batch+"')";
Sqlca.executeSQL(insertSql);
insertSql="INSERT INTO NCXML_DETAIL_RECORDS(BILLID,XML_TYPE,TABLE_NUM,FLAG,ERR_DESCRIBE,CREATE_TIME,BATCH) VALUES('"+uuid+"','"+type+"','"+contract_number+"','2','传输失败 , 请联系管理员 !','"+year_month_days+"','"+batch+"')";
Sqlca1.executeSQL(insertSql);
logger.info("辅助合同记录语句: " + insertSql);
count++;
}else {
String updSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='1',ERR_DESCRIBE=null,CREATE_TIME='"+year_month_days+"' WHERE BILLID='"+uuid+"' AND XML_TYPE= '"+type+"'";
Sqlca.executeSQL(updSql);
logger.info("旧批次号记录: "+updSql);
/*String updSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='1',ERR_DESCRIBE=null,CREATE_TIME='"+year_month_days+"' WHERE BILLID='"+uuid+"' AND XML_TYPE= '"+type+"'";
Sqlca.executeSQL(updSql);*/
String batch1= record.getAttribute("BATCH").getString();
logger.info("旧批次号记录: "+batch1);
if(batchList.indexOf(batch1) == -1) {
batchList.add(batch1);
}
}
}
Sqlca1.commit();
String URL=LOCALHOST_URL+"APleasing_Defdoc_"+year_month_day+".xml";
//String URL="D:\\voucherXml_NC\\APleasing_Defdoc_"+year_month_day+".xml";
file=new File(URL);
@ -200,23 +209,39 @@ public class VoucherToNCforAssistContract implements Job{
InterActionToNC(Sqlca,URL,type,batch,count,batchList);
Sqlca.commit();
}
QuartzUtil.insertLog(plan_date,"com.tenwa.voucher.serviceImp.VoucherToNCforAssistContract", "success", "成功",curUserId);
} catch (Exception e) {
QuartzUtil.insertLog(plan_date,"com.tenwa.voucher.serviceImp.VoucherToNCforAssistContract", "error", "失败",curUserId);
try {
Sqlca.rollback();
} catch (JBOException e1) {
e1.printStackTrace();
if(batch!=null || !"".equals(batch)){
logger.debug("合同xml传输失败");
/*String updateSql="UPDATE NCXML_DETAIL_RECORDS SET FLAG='2',ERR_DESCRIBE='传输过程中遇到异常, 请联系管理员 !' WHERE BATCH='"+batch+"'";
Sqlca1.executeSQL(updateSql);*/
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+"','传输失败, 请联系管理员 !','"+year_month_days+"')";
Sqlca1.executeSQL(insertSql);
Sqlca1.commit();
}
} catch (Exception e2) {
e2.printStackTrace();
}
e.printStackTrace();
}finally {
if(Sqlca!=null) {
try {
Sqlca.commit();
Sqlca.disConnect();
} catch (JBOException e) {
e.printStackTrace();
}
}
if(Sqlca1!=null) {
try {
Sqlca1.commit();
Sqlca1.disConnect();
} catch (JBOException e) {
e.printStackTrace();
}
}
}
}
@ -225,10 +250,24 @@ public class VoucherToNCforAssistContract implements Job{
*/
public String sendContractData(JBOTransaction tx) {
String returns="true";
JBOTransaction tx1=null;
Transaction Sqlca1 = null;
Transaction Sqlca = null;
// 获取配置文件的输入流
FileInputStream in=null;
// xml类别
String type="contract";
// 记录当前批次传输总量
int count=0;
// 批次号
String batch = "";
// 文件名称
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());// 年月日时分秒
try {
tx1= JBOFactory.createJBOTransaction();
Sqlca1 = Transaction.createTransaction(tx1);
Sqlca = Transaction.createTransaction(tx);
/**
* 读取配置文件信息
@ -276,23 +315,15 @@ public class VoucherToNCforAssistContract implements Job{
String insertSql="";
// 合同编码对象
String contract_number="";
// xml类别
String type="contract";
// 文件名称
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());// 年月日时分秒
// 记录当前批次传输总量
int count=0;
// 记录历史批次号
List<String> batchList= new ArrayList<String>();
// 获取未传输及之前传输失败的数据
String sql="SELECT id,CONTRACT_NUMBER FROM LB_CONTRACT_INFO WHERE CONTRACT_NUMBER NOT IN(SELECT TABLE_NUM FROM NCXML_DETAIL_RECORDS WHERE FLAG = '1' AND XML_TYPE='"+type+"')";
String sql="SELECT id,CONTRACT_NUMBER FROM LB_CONTRACT_INFO WHERE CONTRACT_STATUS='31' AND CONTRACT_NUMBER NOT IN(SELECT TABLE_NUM FROM NCXML_DETAIL_RECORDS WHERE FLAG = '1' AND XML_TYPE='"+type+"')";
List<Map<String, String>> rs = DataOperatorUtil.getDataBySql(Sqlca,sql,null);
if(rs!=null && rs.size()>0) {
// 批次号
String batch = "";
// 生成xml头
Document document = DocumentHelper.createDocument(); // 生成每个xml的头
Element root = document.addElement("ufinterface");
@ -341,22 +372,23 @@ public class VoucherToNCforAssistContract implements Job{
// 等于null说明新数据, 新增入记录表
if(record==null || "".equals(record)) {
if("".equals(batch)) {
batch = SerialNumberUtil.getVoucherPCNumber(Sqlca);
batch = SerialNumberUtil.getVoucherPCNumber(Sqlca1);
}
insertSql="INSERT INTO NCXML_DETAIL_RECORDS(BILLID,XML_TYPE,TABLE_NUM,FLAG,CREATE_TIME,BATCH) VALUES('"+uuid+"','"+type+"','"+contract_number+"','1','"+year_month_days+"','"+batch+"')";
Sqlca.executeSQL(insertSql);
insertSql="INSERT INTO NCXML_DETAIL_RECORDS(BILLID,XML_TYPE,TABLE_NUM,FLAG,ERR_DESCRIBE,CREATE_TIME,BATCH) VALUES('"+uuid+"','"+type+"','"+contract_number+"','2','传输失败 , 请联系管理员 !','"+year_month_days+"','"+batch+"')";
Sqlca1.executeSQL(insertSql);
logger.info("辅助合同记录语句: " + insertSql);
count++;
}else {
String updSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='1',ERR_DESCRIBE=null,CREATE_TIME='"+year_month_days+"' WHERE BILLID='"+uuid+"' AND XML_TYPE= '"+type+"'";
Sqlca.executeSQL(updSql);
logger.info("旧批次号记录: "+updSql);
/*String updSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='1',ERR_DESCRIBE=null,CREATE_TIME='"+year_month_days+"' WHERE BILLID='"+uuid+"' AND XML_TYPE= '"+type+"'";
Sqlca.executeSQL(updSql);*/
String batch1= record.getAttribute("BATCH").getString();
logger.info("旧批次号记录: "+batch1);
if(batchList.indexOf(batch1) == -1) {
batchList.add(batch1);
}
}
}
Sqlca1.commit();
String URL=LOCALHOST_URL+"APleasing_Defdoc_"+year_month_day+".xml";
//String URL="D:\\voucherXml_NC\\APleasing_Defdoc_"+year_month_day+".xml";
file=new File(URL);
@ -368,22 +400,38 @@ public class VoucherToNCforAssistContract implements Job{
Sqlca.commit();
}
} catch (Exception e) {
logger.info("客户xml传输失败");
try {
Sqlca.rollback();
} catch (JBOException e1) {
e1.printStackTrace();
if(batch!=null || !"".equals(batch)){
logger.debug("合同xml传输失败");
/*String updateSql="UPDATE NCXML_DETAIL_RECORDS SET FLAG='2',ERR_DESCRIBE='传输过程中遇到异常, 请联系管理员 !' WHERE BATCH='"+batch+"'";
Sqlca1.executeSQL(updateSql);*/
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+"','传输失败, 请联系管理员 !','"+year_month_days+"')";
Sqlca1.executeSQL(insertSql);
Sqlca1.commit();
}
} catch (Exception e2) {
e2.printStackTrace();
}
e.printStackTrace();
returns="false";
}finally {
if(Sqlca!=null) {
try {
Sqlca.commit();
Sqlca.disConnect();
} catch (JBOException e) {
e.printStackTrace();
}
}
if(Sqlca1!=null) {
try {
Sqlca1.commit();
Sqlca1.disConnect();
} catch (JBOException e) {
e.printStackTrace();
}
}
}
return returns;
}
@ -402,7 +450,6 @@ public class VoucherToNCforAssistContract implements Job{
String account = VouchersPropertiesUtil.get("account");
String groupcode = VouchersPropertiesUtil.get("groupcode");
String RECEIVE_URL = VouchersPropertiesUtil.get("RECEIVE_URL"); //回执信息存放路径
/**
* 获取对方post连接
*/
@ -413,6 +460,7 @@ public class VoucherToNCforAssistContract implements Job{
connection.setDoOutput(true);
connection.setRequestProperty("Content-type", "text/xml");
connection.setRequestMethod("POST");
/**
* 读取本方生成的xml, 传输到NC
*/
@ -511,17 +559,16 @@ public class VoucherToNCforAssistContract implements Job{
}
}*/
// 判断, 若失败, 更新错误录入明细表
if(!"1".equals(resultcode)) {
// 如果回执状态不等于1, 说明有误, 更新到记录字表并记录错误信息
updateSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='"+resultcode+"',ERR_DESCRIBE='"+resultdescription+"' WHERE BILLID='"+bdocid+"' AND XML_TYPE= '"+type+"'";
Sqlca.executeSQL(updateSql);
logger.info("根据回执信息, 修改传输失败状态, 记录错误信息"+updateSql);
BizObject old_record=JBOFactory.createBizObjectQuery(NCXML_DETAIL_RECORDS.CLASS_NAME, "BILLID='"+bdocid+"' AND BATCH <> '"+batch+"' AND XML_TYPE= '"+type+"'").getSingleResult(false);
if(old_record ==null) {
failed_count++;
}
}
/**
* 根据回执信息, 变更明细表记录
*/
updateSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='"+resultcode+"',ERR_DESCRIBE='"+resultdescription+"' WHERE BILLID='"+bdocid+"' AND XML_TYPE= '"+type+"'";
Sqlca.executeSQL(updateSql);
logger.info("根据回执信息, 变更明细表数据记录"+updateSql);
/*BizObject old_record=JBOFactory.createBizObjectQuery(NCXML_DETAIL_RECORDS.CLASS_NAME, "BILLID='"+bdocid+"' AND BATCH <> '"+batch+"' AND XML_TYPE= '"+type+"'").getSingleResult(false);
if(old_record ==null) {
failed_count++;
}*/
}
// 判断集合为否为null, 不为空遍历集合, 获取旧数据的批次号
@ -536,9 +583,9 @@ public class VoucherToNCforAssistContract implements Job{
con=Integer.valueOf(dataList.get(0).get("CON"));
}
if(con==0) {
updateSql="UPDATE NCXML_TOTAL_RECORDS SET FLAG_='Y',FAILED_COUNT='0',CREATETIME='"+formatter2.format(new Date())+"' WHERE XML_TYPE='"+type+"' AND BATCH='"+old_batch+"'";
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+"',CREATETIME='"+formatter2.format(new Date())+"' WHERE XML_TYPE='"+type+"' AND BATCH='"+old_batch+"'";
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);
}
@ -555,12 +602,12 @@ public class VoucherToNCforAssistContract implements Job{
}
// 如果con等于0, 说明没有失败记录, 插入成功记录
if(con==0) {
insertSql = "INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','Y','"+count+"','"+con+"','导入成功 !','"+formatter2.format(new Date())+"')";
insertSql = "INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','Y','"+count+"','"+con+"','"+resultdescription+"','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql);
logger.info("本批次传输成功!");
// 如果con不等于0, 记录含失败记录的数据如总表
}else {
insertSql = "INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','"+resSuc+"','"+count+"','"+con+"','含失败记录 !','"+formatter2.format(new Date())+"')";
insertSql = "INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','"+resSuc+"','"+count+"','"+con+"','"+resultdescription+"','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql);
logger.info("本批次包含失败数据 !");
}
@ -587,9 +634,9 @@ public class VoucherToNCforAssistContract implements Job{
con=Integer.valueOf(dataList.get(0).get("CON"));
}
if(con==0) {
updateSql="UPDATE NCXML_TOTAL_RECORDS SET FLAG_='Y',FAILED_COUNT='0',CREATETIME='"+formatter2.format(new Date())+"' WHERE XML_TYPE='"+type+"' AND BATCH='"+old_batch+"'";
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+"',CREATETIME='"+formatter2.format(new Date())+"' WHERE XML_TYPE='"+type+"' AND BATCH='"+old_batch+"'";
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);
}

View File

@ -17,10 +17,12 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
@ -31,6 +33,7 @@ import org.dom4j.io.XMLWriter;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import com.amarsoft.are.ARE;
import com.amarsoft.are.jbo.BizObject;
import com.amarsoft.are.jbo.JBOException;
@ -43,6 +46,7 @@ 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;
import jbo.voucher.NCXML_DETAIL_RECORDS;
public class VoucherToNCforCustomer implements Job{
@ -59,12 +63,26 @@ public class VoucherToNCforCustomer implements Job{
Object userId = arg0.getTrigger().getJobDataMap().get("CurUserId");
String curUserId = userId == null? "system" : userId.toString();
// 定义事物
JBOTransaction tx1=null;
Transaction Sqlca1 = null;
JBOTransaction tx=null;
Transaction Sqlca = null;
// 获取配置文件的输入流
FileInputStream in =null;
// 定义xml类型对象
String type="customer";
// 批次号
String batch = "";
// 记录当前批次传输总量
int count=0;
// 文件路径所需
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());
try {
tx1= JBOFactory.createJBOTransaction();
tx= JBOFactory.createJBOTransaction();
Sqlca1 = Transaction.createTransaction(tx1);
Sqlca = Transaction.createTransaction(tx);
/**
@ -115,8 +133,6 @@ public class VoucherToNCforCustomer implements Job{
Document document=null;
// 定义输出对象
XMLWriter writer=null;
// 定义xml类型对象
String type="customer";
// 定义新增语句对象
String insertSql="";
// 定义xml传输id对象
@ -127,21 +143,14 @@ public class VoucherToNCforCustomer implements Job{
String certid="";
// 定义客户名称对象
String customername="";
// 文件路径所需
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());
// 查询为传输或之前传输失败的数据
String sql="SELECT MAX(cif.customerid) id,cif.customer_num,MAX(cif.customername) customername,MAX(cif.customertype) customertype,MAX(cif.customerid) customerid, MAX(cif.certid) AS certid FROM CUSTOMER_INFO cif LEFT JOIN lb_union_lessee lul ON lul.customer_id = cif.customerid LEFT JOIN lb_contract_info lci ON lci.id = lul.contract_id WHERE lci.contract_status >= '31' AND cif.customer_num NOT IN (SELECT TABLE_NUM FROM NCXML_DETAIL_RECORDS WHERE FLAG = '1' AND XML_TYPE = 'customer') AND cif.customer_num NOT IN (SELECT cust_id FROM CUSTOMER_LIST WHERE CUST_STATUS = '2' ) GROUP BY CIF.CUSTOMER_NUM ";
List<Map<String, String>> rs = DataOperatorUtil.getDataBySql(Sqlca,sql,null);
if(rs != null && rs.size()>0) {
// 批次号
String batch = "";
// 记录历史批次号
List<String> batchList= new ArrayList<String>();
// 记录当前批次传输总量
int count=0;
// 生成xml头
document= DocumentHelper.createDocument();
Element root = document.addElement("ufinterface");
@ -241,23 +250,24 @@ public class VoucherToNCforCustomer implements Job{
// 等于null说明新数据, 新增入记录表
if(record==null || "".equals(record)) {
if("".equals(batch)) {
batch = SerialNumberUtil.getVoucherPCNumber(Sqlca);
batch = SerialNumberUtil.getVoucherPCNumber(Sqlca1);
}
// 将客户xml信息写入状态表中
insertSql="INSERT INTO NCXML_DETAIL_RECORDS(BILLID,XML_TYPE,TABLE_NUM,FLAG,CREATE_TIME,BATCH) VALUES('"+uuid+"','"+type+"','"+customer_num+"','1','"+year_month_days+"','"+batch+"')";
Sqlca.executeSQL(insertSql);
insertSql="INSERT INTO NCXML_DETAIL_RECORDS(BILLID,XML_TYPE,TABLE_NUM,FLAG,ERR_DESCRIBE,CREATE_TIME,BATCH) VALUES('"+uuid+"','"+type+"','"+customer_num+"','2','传输失败 , 请联系管理员 !','"+year_month_days+"','"+batch+"')";
Sqlca1.executeSQL(insertSql);
logger.info("客户记录语句: "+insertSql);
count++;
}else {
String updSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='1',ERR_DESCRIBE=null,CREATE_TIME='"+year_month_days+"' WHERE BILLID='"+uuid+"' AND XML_TYPE= '"+type+"'";
Sqlca.executeSQL(updSql);
logger.info("旧批次号记录: "+updSql);
/*String updSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='1',ERR_DESCRIBE=null,CREATE_TIME='"+year_month_days+"' WHERE BILLID='"+uuid+"' AND XML_TYPE= '"+type+"'";
Sqlca.executeSQL(updSql);*/
String batch1= record.getAttribute("BATCH").getString();
logger.info("旧批次号记录: "+batch1);
if(batchList.indexOf(batch1) == -1) {
batchList.add(batch1);
}
}
}
Sqlca1.commit();
String URL=LOCALHOST_URL+"APleasing_Customer_"+year_month_day+".xml";
//String URL="D:\\voucherXml_NC\\APleasing_Customer_"+year_month_day+".xml";
file=new File(URL);
@ -268,24 +278,39 @@ public class VoucherToNCforCustomer implements Job{
InterActionToNC(Sqlca,URL,type,batch,count,batchList);
Sqlca.commit();
}
QuartzUtil.insertLog(plan_date,"com.tenwa.voucher.serviceImp.VoucherToNCforCustomer", "success", "成功",curUserId);
} catch (Exception e) {
QuartzUtil.insertLog(plan_date,"com.tenwa.voucher.serviceImp.VoucherToNCforCustomer", "error", "失败",curUserId);
try {
logger.debug("客户xml传输失败");
Sqlca.rollback();
} catch (JBOException e1) {
e1.printStackTrace();
if(batch!=null || !"".equals(batch)){
logger.debug("客户xml传输失败");
/*String updateSql="UPDATE NCXML_DETAIL_RECORDS SET FLAG='2',ERR_DESCRIBE='传输过程中遇到异常, 请联系管理员 !' WHERE BATCH='"+batch+"'";
Sqlca1.executeSQL(updateSql);*/
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+"','传输失败, 请联系管理员 !','"+year_month_days+"')";
Sqlca1.executeSQL(insertSql);
Sqlca1.commit();
}
} catch (Exception e2) {
e2.printStackTrace();
}
e.printStackTrace();
}finally {
if (Sqlca!=null) {
try {
Sqlca.commit();
Sqlca.disConnect();
} catch (JBOException e) {
e.printStackTrace();
}
}
if (Sqlca1!=null) {
try {
Sqlca1.commit();
Sqlca1.disConnect();
} catch (JBOException e) {
e.printStackTrace();
}
}
}
}
@ -294,10 +319,24 @@ public class VoucherToNCforCustomer implements Job{
*/
public String sendCustomerData(JBOTransaction tx) {
String returns="true";
JBOTransaction tx1=null;
Transaction Sqlca1 = null;
Transaction Sqlca = null;
// 获取配置文件的输入流
FileInputStream in =null;
// 定义xml类型对象
String type="customer";
// 批次号
String batch = "";
// 记录当前批次传输总量
int count=0;
// 文件路径所需
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());
try {
tx1= JBOFactory.createJBOTransaction();
Sqlca1 = Transaction.createTransaction(tx1);
Sqlca = Transaction.createTransaction(tx);
/**
* 读取配置文件信息
@ -347,8 +386,7 @@ public class VoucherToNCforCustomer implements Job{
Document document=null;
// 定义输出对象
XMLWriter writer=null;
// 定义xml类型对象
String type="customer";
// 定义新增语句对象
String insertSql="";
// 定义xml传输id对象
@ -359,21 +397,14 @@ public class VoucherToNCforCustomer implements Job{
String certid="";
// 定义客户名称对象
String customername="";
// 文件路径所需
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());
// 查询为传输或之前传输失败的数据
String sql="SELECT max(cif.customerid) id,cif.customer_num,MAX(cif.customername)customername,MAX(cif.customertype)customertype,MAX(cif.customerid) customerid,MAX(cif.certid) as certid FROM CUSTOMER_INFO cif LEFT JOIN lb_union_lessee lul ON lul.customer_id=cif.customerid LEFT JOIN lb_contract_info lci ON lci.id=lul.contract_id WHERE lci.contract_status >='31' AND cif.customer_num NOT IN (SELECT TABLE_NUM FROM NCXML_DETAIL_RECORDS WHERE FLAG = '1' AND XML_TYPE = '"+type+"') GROUP BY CIF.CUSTOMER_NUM ";
// String sql="SELECT max(cif.customerid) id,cif.customer_num,MAX(cif.customername)customername,MAX(cif.customertype)customertype,MAX(cif.customerid) customerid,MAX(cif.certid) as certid FROM CUSTOMER_INFO cif LEFT JOIN lb_union_lessee lul ON lul.customer_id=cif.customerid LEFT JOIN lb_contract_info lci ON lci.id=lul.contract_id WHERE lci.contract_status >='31' AND cif.customer_num NOT IN (SELECT TABLE_NUM FROM NCXML_DETAIL_RECORDS WHERE FLAG = '1' AND XML_TYPE = '"+type+"') GROUP BY CIF.CUSTOMER_NUM ";
String sql="SELECT MAX(cif.customerid) id,cif.customer_num,MAX(cif.customername) customername,MAX(cif.customertype) customertype,MAX(cif.customerid) customerid, MAX(cif.certid) AS certid FROM CUSTOMER_INFO cif LEFT JOIN lb_union_lessee lul ON lul.customer_id = cif.customerid LEFT JOIN lb_contract_info lci ON lci.id = lul.contract_id WHERE lci.contract_status >= '31' AND cif.customer_num NOT IN (SELECT TABLE_NUM FROM NCXML_DETAIL_RECORDS WHERE FLAG = '1' AND XML_TYPE = 'customer') AND cif.customer_num NOT IN (SELECT cust_id FROM CUSTOMER_LIST WHERE CUST_STATUS = '2' ) GROUP BY CIF.CUSTOMER_NUM ";
List<Map<String, String>> rs = DataOperatorUtil.getDataBySql(Sqlca,sql,null);
if(rs != null && rs.size()>0) {
// 批次号
String batch = "";
// 记录历史批次号
List<String> batchList= new ArrayList<String>();
// 记录当前批次传输总量
int count=0;
// 生成xml头
document= DocumentHelper.createDocument();
Element root = document.addElement("ufinterface");
@ -473,23 +504,24 @@ public class VoucherToNCforCustomer implements Job{
// 等于null说明新数据, 新增入记录表
if(record==null || "".equals(record)) {
if("".equals(batch)) {
batch = SerialNumberUtil.getVoucherPCNumber(Sqlca);
batch = SerialNumberUtil.getVoucherPCNumber(Sqlca1);
}
// 将客户xml信息写入状态表中
insertSql="INSERT INTO NCXML_DETAIL_RECORDS(BILLID,XML_TYPE,TABLE_NUM,FLAG,CREATE_TIME,BATCH) VALUES('"+uuid+"','"+type+"','"+customer_num+"','1','"+year_month_days+"','"+batch+"')";
Sqlca.executeSQL(insertSql);
insertSql="INSERT INTO NCXML_DETAIL_RECORDS(BILLID,XML_TYPE,TABLE_NUM,FLAG,ERR_DESCRIBE,CREATE_TIME,BATCH) VALUES('"+uuid+"','"+type+"','"+customer_num+"','2','传输失败 , 请联系管理员 !','"+year_month_days+"','"+batch+"')";
Sqlca1.executeSQL(insertSql);
logger.info("客户记录语句: "+insertSql);
count++;
}else {
String updSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='1',ERR_DESCRIBE=null,CREATE_TIME='"+year_month_days+"' WHERE BILLID='"+uuid+"' AND XML_TYPE= '"+type+"'";
Sqlca.executeSQL(updSql);
logger.info("旧批次号记录: "+updSql);
/*String updSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='1',ERR_DESCRIBE=null,CREATE_TIME='"+year_month_days+"' WHERE BILLID='"+uuid+"' AND XML_TYPE= '"+type+"'";
Sqlca.executeSQL(updSql);*/
String batch1= record.getAttribute("BATCH").getString();
logger.info("旧批次号记录: "+batch1);
if(batchList.indexOf(batch1) == -1) {
batchList.add(batch1);
}
}
}
Sqlca1.commit();
String URL=LOCALHOST_URL+"APleasing_Customer_"+year_month_day+".xml";
//String URL="D:\\voucherXml_NC\\APleasing_Customer_"+year_month_day+".xml";
file=new File(URL);
@ -502,21 +534,38 @@ public class VoucherToNCforCustomer implements Job{
}
} catch (Exception e) {
try {
logger.debug("客户xml传输失败");
Sqlca.rollback();
} catch (JBOException e1) {
e1.printStackTrace();
if(batch!=null || !"".equals(batch)){
logger.debug("客户xml传输失败");
/*String updateSql="UPDATE NCXML_DETAIL_RECORDS SET FLAG='2',ERR_DESCRIBE='传输过程中遇到异常, 请联系管理员 !' WHERE BATCH='"+batch+"'";
Sqlca1.executeSQL(updateSql);*/
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+"','传输失败, 请联系管理员 !','"+year_month_days+"')";
Sqlca1.executeSQL(insertSql);
Sqlca1.commit();
}
} catch (Exception e2) {
e2.printStackTrace();
}
e.printStackTrace();
returns="false";
}finally {
if (Sqlca!=null) {
try {
Sqlca.commit();
Sqlca.disConnect();
} catch (JBOException e) {
e.printStackTrace();
}
}
if (Sqlca1!=null) {
try {
Sqlca1.commit();
Sqlca1.disConnect();
} catch (JBOException e) {
e.printStackTrace();
}
}
}
return returns;
}
@ -535,7 +584,6 @@ public class VoucherToNCforCustomer implements Job{
String account = VouchersPropertiesUtil.get("account");
String groupcode = VouchersPropertiesUtil.get("groupcode");
String RECEIVE_URL = VouchersPropertiesUtil.get("RECEIVE_URL"); //回执信息存放路径
/**
* 获取对方post连接
*/
@ -546,6 +594,7 @@ public class VoucherToNCforCustomer implements Job{
connection.setDoOutput(true);
connection.setRequestProperty("Content-type", "text/xml");
connection.setRequestMethod("POST");
/**
* 读取本方生成的xml, 传输到NC
*/
@ -580,7 +629,7 @@ public class VoucherToNCforCustomer implements Job{
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
DocumentSource source = new DocumentSource(resDoc);
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
//设置文档的换行与缩进
transformer.setOutputProperty(OutputKeys.INDENT, "YES");
@ -591,7 +640,6 @@ public class VoucherToNCforCustomer implements Job{
// 回执信息存放路径
String resFile = RECEIVE_URL+"APleasing_"+type+""+fmt.format(new Date())+".xml";
//String resFile = "D:\\VOUCHER_RECEIPT\\APleasing_"+type+""+fmt.format(new Date())+".xml";
System.out.println(resFile);
StreamResult result = new StreamResult(new File(resFile));
// 将回执信息转化为xml
transformer.transform(source,result);
@ -645,17 +693,16 @@ public class VoucherToNCforCustomer implements Job{
}
}*/
// 判断, 若失败, 更新错误录入明细表
if(!"1".equals(resultcode)) {
// 如果回执状态不等于1, 说明有误, 更新到记录字表并记录错误信息
updateSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='"+resultcode+"',ERR_DESCRIBE='"+resultdescription+"' WHERE BILLID='"+bdocid+"' AND XML_TYPE= '"+type+"'";
Sqlca.executeSQL(updateSql);
logger.info("根据回执信息, 修改传输失败状态, 记录错误信息"+updateSql);
BizObject old_record=JBOFactory.createBizObjectQuery(NCXML_DETAIL_RECORDS.CLASS_NAME, "BILLID='"+bdocid+"' AND BATCH <> '"+batch+"' AND XML_TYPE= '"+type+"'").getSingleResult(false);
if(old_record ==null) {
failed_count++;
}
}
/**
* 根据回执信息, 变更明细表记录
*/
updateSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='"+resultcode+"',ERR_DESCRIBE='"+resultdescription+"' WHERE BILLID='"+bdocid+"' AND XML_TYPE= '"+type+"'";
Sqlca.executeSQL(updateSql);
logger.info("根据回执信息, 变更明细表数据记录"+updateSql);
/*BizObject old_record=JBOFactory.createBizObjectQuery(NCXML_DETAIL_RECORDS.CLASS_NAME, "BILLID='"+bdocid+"' AND BATCH <> '"+batch+"' AND XML_TYPE= '"+type+"'").getSingleResult(false);
if(old_record ==null) {
failed_count++;
}*/
}
// 判断集合为否为null, 不为空遍历集合, 获取旧数据的批次号
@ -670,9 +717,9 @@ public class VoucherToNCforCustomer implements Job{
con=Integer.valueOf(dataList.get(0).get("CON"));
}
if(con==0) {
updateSql="UPDATE NCXML_TOTAL_RECORDS SET FLAG_='Y',FAILED_COUNT='0',CREATETIME='"+formatter2.format(new Date())+"' WHERE XML_TYPE='"+type+"' AND BATCH='"+old_batch+"'";
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+"',CREATETIME='"+formatter2.format(new Date())+"' WHERE XML_TYPE='"+type+"' AND BATCH='"+old_batch+"'";
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);
}
@ -689,12 +736,12 @@ public class VoucherToNCforCustomer implements Job{
}
// 如果con等于0, 说明没有失败记录, 插入成功记录
if(con==0) {
insertSql = "INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','Y','"+count+"','"+con+"','导入成功 !','"+formatter2.format(new Date())+"')";
insertSql = "INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','Y','"+count+"','"+con+"','"+resultdescription+"','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql);
logger.info("本批次传输成功!");
// 如果con不等于0, 记录含失败记录的数据如总表
}else {
insertSql = "INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','"+resSuc+"','"+count+"','"+con+"','含失败记录 !','"+formatter2.format(new Date())+"')";
insertSql = "INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','"+resSuc+"','"+count+"','"+con+"','"+resultdescription+"','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql);
logger.info("本批次包含失败数据 !");
}
@ -721,9 +768,9 @@ public class VoucherToNCforCustomer implements Job{
con=Integer.valueOf(dataList.get(0).get("CON"));
}
if(con==0) {
updateSql="UPDATE NCXML_TOTAL_RECORDS SET FLAG_='Y',FAILED_COUNT='0',CREATETIME='"+formatter2.format(new Date())+"' WHERE XML_TYPE='"+type+"' AND BATCH='"+old_batch+"'";
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+"',CREATETIME='"+formatter2.format(new Date())+"' WHERE XML_TYPE='"+type+"' AND BATCH='"+old_batch+"'";
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);
}

View File

@ -15,7 +15,6 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;
import javax.xml.transform.OutputKeys;
@ -33,6 +32,7 @@ import org.dom4j.io.XMLWriter;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import com.amarsoft.are.ARE;
import com.amarsoft.are.jbo.BizObject;
import com.amarsoft.are.jbo.JBOException;
@ -61,11 +61,24 @@ public class VoucherToNCforDistributor implements Job{
Object userId = arg0.getTrigger().getJobDataMap().get("CurUserId");
String curUserId = userId == null? "system" : userId.toString();
// 定义事物
JBOTransaction tx1=null;
Transaction Sqlca1 = null;
JBOTransaction tx=null;
Transaction Sqlca = null;
// 获取配置文件的输入流
FileInputStream in=null;
// 批次号
String batch = "";
// xml类别
String type="distributor";
// 记录当前批次传输总量
int count=0;
// 获取特定日期
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());
try {
tx1= JBOFactory.createJBOTransaction();
Sqlca1 = Transaction.createTransaction(tx1);
tx= JBOFactory.createJBOTransaction();
Sqlca = Transaction.createTransaction(tx);
/**
@ -112,7 +125,6 @@ public class VoucherToNCforDistributor implements Job{
File file = null; // 文件对象
XMLWriter writer = null; // 输出对象
String type="distributor"; // xml类别
String DISTRIBUTOR_NAME = ""; // 经销商名称
String DISTRIBUTOR_CODING = ""; // 经销商id
String DISTRIBUTOR_ADDRESS=""; // 地区编码
@ -136,18 +148,11 @@ public class VoucherToNCforDistributor implements Job{
String MBAFC_EARLYDISBURSEMENT_TYPE="";// 资金类型/支付类型
// 记录历史批次号
List<String> batchList= new ArrayList<String>();
// 记录当前批次传输总量
int count=0;
// 获取特定日期
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());
// 获取未传输及以前传输失败的数据
String sql="SELECT id,DISTRIBUTOR_NAME,DISTRIBUTOR_CODING,DISTRIBUTOR_ADDRESS,FACT_ADDR,PROVINCES,POSTCODE,REGISTERED_ADDR,BUSINESS_SCOPE,SUBSIDIARY_COMPANY,TYPE,BUSINESS_LICENSE_NO,DISTRIBUTOR_STATUS,E_MAIL,FAX_NUMBER,REGISTERED_ASSET,DISTRIBUTORER,MBAFC_EARLYDISBURSEMENT_TYPE,URL FROM DISTRIBUTOR_INFO WHERE (DISTRIBUTOR_CODING NOT IN(SELECT TABLE_NUM FROM NCXML_DETAIL_RECORDS WHERE FLAG ='1' AND XML_TYPE='"+type+"') and DISTRIBUTOR_CODING not in(SELECT cust_id FROM customer_list)) and DISTRIBUTOR_STATUS='distributor_status04' ";
List<Map<String, String>> rs = DataOperatorUtil.getDataBySql(Sqlca,sql,null);
if(rs !=null && rs.size()>0) {
// 批次号
String batch = "";
// 设置xml标签头
Document document = DocumentHelper.createDocument();
Element root = document.addElement("ufinterface");
@ -318,22 +323,23 @@ public class VoucherToNCforDistributor implements Job{
// 等于null说明新数据, 新增入记录表
if(record==null || "".equals(record)) {
if("".equals(batch)) {
batch = SerialNumberUtil.getVoucherPCNumber(Sqlca);
batch = SerialNumberUtil.getVoucherPCNumber(Sqlca1);
}
insertSql="INSERT INTO NCXML_DETAIL_RECORDS(BILLID,XML_TYPE,TABLE_NUM,FLAG,CREATE_TIME,BATCH) VALUES('"+uuid+"','"+type+"','"+DISTRIBUTOR_CODING+"','1','"+year_month_days+"','"+batch+"')";
Sqlca.executeSQL(insertSql);
insertSql="INSERT INTO NCXML_DETAIL_RECORDS(BILLID,XML_TYPE,TABLE_NUM,FLAG,ERR_DESCRIBE,CREATE_TIME,BATCH) VALUES('"+uuid+"','"+type+"','"+DISTRIBUTOR_CODING+"','2','传输失败 , 请联系管理员 !','"+year_month_days+"','"+batch+"')";
Sqlca1.executeSQL(insertSql);
logger.info("经销商记录语句: "+ insertSql);
count++;
}else {
String updSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='1',ERR_DESCRIBE=null,CREATE_TIME='"+year_month_days+"' WHERE BILLID='"+uuid+"' AND XML_TYPE= '"+type+"'";
Sqlca.executeSQL(updSql);
logger.info("旧批次号记录: "+updSql);
/*String updSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='1',ERR_DESCRIBE=null,CREATE_TIME='"+year_month_days+"' WHERE BILLID='"+uuid+"' AND XML_TYPE= '"+type+"'";
Sqlca.executeSQL(updSql);*/
String batch1= record.getAttribute("BATCH").getString();
logger.info("旧批次号记录: "+batch1);
if(batchList.indexOf(batch1) == -1) {
batchList.add(batch1);
}
}
}
Sqlca1.commit();
//String f="D:\\voucherXml_NC\\APleasing_Supplier_"+year_month_day+".xml";
String f=LOCALHOST_URL+"APleasing_Supplier_"+year_month_day+".xml";
file=new File(f);
@ -344,24 +350,38 @@ public class VoucherToNCforDistributor implements Job{
InterActionToNC(Sqlca,f,type,batch,count,batchList);
Sqlca.commit();
}
QuartzUtil.insertLog(plan_date,"com.tenwa.voucher.serviceImp.VoucherToNCforDistributor", "success", "成功",curUserId);
} catch (Exception e) {
QuartzUtil.insertLog(plan_date,"com.tenwa.voucher.serviceImp.VoucherToNCforDistributor", "error", "失败",curUserId);
try {
logger.debug("经销商xml传输失败");
Sqlca.rollback();
} catch (JBOException e1) {
e1.printStackTrace();
if(batch!=null || !"".equals(batch)){
logger.debug("经销商xml传输失败");
/*String updateSql="UPDATE NCXML_DETAIL_RECORDS SET FLAG='2',ERR_DESCRIBE='传输过程中遇到异常, 请联系管理员 !' WHERE BATCH='"+batch+"'";
Sqlca1.executeSQL(updateSql);*/
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+"','传输失败, 请联系管理员 !','"+year_month_days+"')";
Sqlca1.executeSQL(insertSql);
Sqlca1.commit();
}
} catch (Exception e2) {
e2.printStackTrace();
}
e.printStackTrace();
e.printStackTrace();
}finally {
if(Sqlca!=null) {
try {
Sqlca.commit();
Sqlca.disConnect();
} catch (JBOException e) {
e.printStackTrace();
}
}
if(Sqlca1!=null) {
try {
Sqlca1.commit();
Sqlca1.disConnect();
} catch (JBOException e) {
e.printStackTrace();
}
}
}
}
@ -370,10 +390,23 @@ public class VoucherToNCforDistributor implements Job{
*/
public String sendDistriturorData(JBOTransaction tx) {
String returns="true";
JBOTransaction tx1=null;
Transaction Sqlca1 = null;
Transaction Sqlca = null;
// xml类别
String type="distributor";
// 记录当前批次传输总量
int count=0;
// 获取特定日期
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());
// 获取配置文件的输入流
FileInputStream in=null;
// 批次号
String batch = "";
try {
tx1= JBOFactory.createJBOTransaction();
Sqlca1 = Transaction.createTransaction(tx1);
Sqlca = Transaction.createTransaction(tx);
/**
* 读取配置文件信息
@ -419,7 +452,6 @@ public class VoucherToNCforDistributor implements Job{
File file = null; // 文件对象
XMLWriter writer = null; // 输出对象
String type="distributor"; // xml类别
String DISTRIBUTOR_NAME = ""; // 经销商名称
String DISTRIBUTOR_CODING = ""; // 经销商id
String DISTRIBUTOR_ADDRESS=""; // 地区编码
@ -443,18 +475,10 @@ public class VoucherToNCforDistributor implements Job{
String MBAFC_EARLYDISBURSEMENT_TYPE="";// 资金类型/支付类型
// 记录历史批次号
List<String> batchList= new ArrayList<String>();
// 记录当前批次传输总量
int count=0;
// 获取特定日期
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());
// 获取未传输及以前传输失败的数据
String sql="SELECT id,DISTRIBUTOR_NAME,DISTRIBUTOR_CODING,DISTRIBUTOR_ADDRESS,FACT_ADDR,PROVINCES,POSTCODE,REGISTERED_ADDR,BUSINESS_SCOPE,SUBSIDIARY_COMPANY,TYPE,BUSINESS_LICENSE_NO,DISTRIBUTOR_STATUS,E_MAIL,FAX_NUMBER,REGISTERED_ASSET,DISTRIBUTORER,MBAFC_EARLYDISBURSEMENT_TYPE,URL FROM DISTRIBUTOR_INFO WHERE (DISTRIBUTOR_CODING NOT IN(SELECT TABLE_NUM FROM NCXML_DETAIL_RECORDS WHERE FLAG ='1' AND XML_TYPE='"+type+"') and DISTRIBUTOR_CODING not in(SELECT cust_id FROM customer_list)) and DISTRIBUTOR_STATUS='distributor_status04' ";
List<Map<String, String>> rs = DataOperatorUtil.getDataBySql(Sqlca,sql,null);
if(rs !=null && rs.size()>0) {
// 批次号
String batch = "";
// 设置xml标签头
Document document = DocumentHelper.createDocument();
Element root = document.addElement("ufinterface");
@ -625,22 +649,23 @@ public class VoucherToNCforDistributor implements Job{
// 等于null说明新数据, 新增入记录表
if(record==null || "".equals(record)) {
if("".equals(batch)) {
batch = SerialNumberUtil.getVoucherPCNumber(Sqlca);
batch = SerialNumberUtil.getVoucherPCNumber(Sqlca1);
}
insertSql="INSERT INTO NCXML_DETAIL_RECORDS(BILLID,XML_TYPE,TABLE_NUM,FLAG,CREATE_TIME,BATCH) VALUES('"+uuid+"','"+type+"','"+DISTRIBUTOR_CODING+"','1','"+year_month_days+"','"+batch+"')";
Sqlca.executeSQL(insertSql);
insertSql="INSERT INTO NCXML_DETAIL_RECORDS(BILLID,XML_TYPE,TABLE_NUM,FLAG,ERR_DESCRIBE,CREATE_TIME,BATCH) VALUES('"+uuid+"','"+type+"','"+DISTRIBUTOR_CODING+"','2','传输失败 , 请联系管理员 !','"+year_month_days+"','"+batch+"')";
Sqlca1.executeSQL(insertSql);
logger.info("经销商记录语句: "+ insertSql);
count++;
}else {
String updSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='1',ERR_DESCRIBE=null,CREATE_TIME='"+year_month_days+"' WHERE BILLID='"+uuid+"' AND XML_TYPE= '"+type+"'";
Sqlca.executeSQL(updSql);
logger.info("旧批次号记录: "+updSql);
/*String updSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='1',ERR_DESCRIBE=null,CREATE_TIME='"+year_month_days+"' WHERE BILLID='"+uuid+"' AND XML_TYPE= '"+type+"'";
Sqlca.executeSQL(updSql);*/
String batch1= record.getAttribute("BATCH").getString();
logger.info("旧批次号记录: "+batch1);
if(batchList.indexOf(batch1) == -1) {
batchList.add(batch1);
}
}
}
Sqlca1.commit();
//String f="D:\\voucherXml_NC\\APleasing_Supplier_"+year_month_day+".xml";
String f=LOCALHOST_URL+"APleasing_Supplier_"+year_month_day+".xml";
file=new File(f);
@ -652,22 +677,38 @@ public class VoucherToNCforDistributor implements Job{
Sqlca.commit();
}
} catch (Exception e) {
try {
try {
Sqlca.rollback();
if(batch!=null || !"".equals(batch)){
logger.debug("经销商xml传输失败");
Sqlca.rollback();
} catch (JBOException e1) {
e1.printStackTrace();
/*String updateSql="UPDATE NCXML_DETAIL_RECORDS SET FLAG='2',ERR_DESCRIBE='传输过程中遇到异常, 请联系管理员 !' WHERE BATCH='"+batch+"'";
Sqlca1.executeSQL(updateSql);*/
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+"','传输失败, 请联系管理员 !','"+year_month_days+"')";
Sqlca1.executeSQL(insertSql);
Sqlca1.commit();
}
e.printStackTrace();
} catch (Exception e2) {
e2.printStackTrace();
}
e.printStackTrace();
returns="false";
}finally {
if(Sqlca!=null) {
try {
Sqlca.commit();
Sqlca.disConnect();
} catch (JBOException e) {
e.printStackTrace();
}
}
if(Sqlca1!=null) {
try {
Sqlca1.commit();
Sqlca1.disConnect();
} catch (JBOException e) {
e.printStackTrace();
}
}
}
return returns;
}
@ -686,7 +727,6 @@ public class VoucherToNCforDistributor implements Job{
String account = VouchersPropertiesUtil.get("account");
String groupcode = VouchersPropertiesUtil.get("groupcode");
String RECEIVE_URL = VouchersPropertiesUtil.get("RECEIVE_URL"); //回执信息存放路径
/**
* 获取对方post连接
*/
@ -697,6 +737,7 @@ public class VoucherToNCforDistributor implements Job{
connection.setDoOutput(true);
connection.setRequestProperty("Content-type", "text/xml");
connection.setRequestMethod("POST");
/**
* 读取本方生成的xml, 传输到NC
*/
@ -795,17 +836,16 @@ public class VoucherToNCforDistributor implements Job{
}
}*/
// 判断, 若失败, 更新错误录入明细表
if(!"1".equals(resultcode)) {
// 如果回执状态不等于1, 说明有误, 更新到记录字表并记录错误信息
updateSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='"+resultcode+"',ERR_DESCRIBE='"+resultdescription+"' WHERE BILLID='"+bdocid+"' AND XML_TYPE= '"+type+"'";
Sqlca.executeSQL(updateSql);
logger.info("根据回执信息, 修改传输失败状态, 记录错误信息"+updateSql);
BizObject old_record=JBOFactory.createBizObjectQuery(NCXML_DETAIL_RECORDS.CLASS_NAME, "BILLID='"+bdocid+"' AND BATCH <> '"+batch+"' AND XML_TYPE= '"+type+"'").getSingleResult(false);
if(old_record ==null) {
failed_count++;
}
}
/**
* 根据回执信息, 变更明细表记录
*/
updateSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='"+resultcode+"',ERR_DESCRIBE='"+resultdescription+"' WHERE BILLID='"+bdocid+"' AND XML_TYPE= '"+type+"'";
Sqlca.executeSQL(updateSql);
logger.info("根据回执信息, 变更明细表数据记录"+updateSql);
/*BizObject old_record=JBOFactory.createBizObjectQuery(NCXML_DETAIL_RECORDS.CLASS_NAME, "BILLID='"+bdocid+"' AND BATCH <> '"+batch+"' AND XML_TYPE= '"+type+"'").getSingleResult(false);
if(old_record ==null) {
failed_count++;
}*/
}
// 判断集合为否为null, 不为空遍历集合, 获取旧数据的批次号
@ -820,9 +860,9 @@ public class VoucherToNCforDistributor implements Job{
con=Integer.valueOf(dataList.get(0).get("CON"));
}
if(con==0) {
updateSql="UPDATE NCXML_TOTAL_RECORDS SET FLAG_='Y',FAILED_COUNT='0',CREATETIME='"+formatter2.format(new Date())+"' WHERE XML_TYPE='"+type+"' AND BATCH='"+old_batch+"'";
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+"',CREATETIME='"+formatter2.format(new Date())+"' WHERE XML_TYPE='"+type+"' AND BATCH='"+old_batch+"'";
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);
}
@ -839,12 +879,12 @@ public class VoucherToNCforDistributor implements Job{
}
// 如果con等于0, 说明没有失败记录, 插入成功记录
if(con==0) {
insertSql = "INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','Y','"+count+"','"+con+"','导入成功 !','"+formatter2.format(new Date())+"')";
insertSql = "INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','Y','"+count+"','"+con+"','"+resultdescription+"','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql);
logger.info("本批次传输成功!");
// 如果con不等于0, 记录含失败记录的数据如总表
}else {
insertSql = "INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','"+resSuc+"','"+count+"','"+con+"','含失败记录 !','"+formatter2.format(new Date())+"')";
insertSql = "INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','"+resSuc+"','"+count+"','"+con+"','"+resultdescription+"','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql);
logger.info("本批次包含失败数据 !");
}
@ -871,9 +911,9 @@ public class VoucherToNCforDistributor implements Job{
con=Integer.valueOf(dataList.get(0).get("CON"));
}
if(con==0) {
updateSql="UPDATE NCXML_TOTAL_RECORDS SET FLAG_='Y',FAILED_COUNT='0',CREATETIME='"+formatter2.format(new Date())+"' WHERE XML_TYPE='"+type+"' AND BATCH='"+old_batch+"'";
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+"',CREATETIME='"+formatter2.format(new Date())+"' WHERE XML_TYPE='"+type+"' AND BATCH='"+old_batch+"'";
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);
}

View File

@ -16,12 +16,13 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
@ -32,6 +33,7 @@ import org.dom4j.io.XMLWriter;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import com.amarsoft.are.ARE;
import com.amarsoft.are.jbo.BizObject;
import com.amarsoft.are.jbo.JBOException;
@ -40,14 +42,11 @@ 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.itextpdf.text.log.SysoCounter;
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;
import jbo.com.tenwa.entity.comm.own.OWN_ACCOUNT;
import jbo.sys.USER_INFO;
import jbo.voucher.LV_STACTS_CONFIG;
import jbo.voucher.NCXML_DETAIL_RECORDS;
@ -89,14 +88,28 @@ public class VoucherToNCforVoucherPZ implements Job{
private static String DOM4JcreateToVoucher(){
// 定义事物
JBOTransaction tx=null;
JBOTransaction tx1=null;
Transaction Sqlca = null;
Transaction Sqlca1 = null;
String returns="true";
// 获取配置文件的输入流
FileInputStream in=null;
// 记录表类别
String type="voucher";
// 批次号
String batch="";
// 记录当前批次传输总量
int count=0;
// 用于文件名凭借
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());
try {
// 定义全局对象
tx= JBOFactory.createJBOTransaction();
tx1= JBOFactory.createJBOTransaction();
Sqlca = Transaction.createTransaction(tx);
Sqlca1 = Transaction.createTransaction(tx1);
Map<String, String> map = new HashMap<String, String>();
/**
* 读取配置文件信息
@ -150,8 +163,6 @@ public class VoucherToNCforVoucherPZ implements Job{
File file=null;
// 输出对象
XMLWriter writer=null;
// 记录表类别
String type="voucher";
// xml主键id
String uuid="";
// 获取科目id
@ -166,10 +177,6 @@ public class VoucherToNCforVoucherPZ implements Job{
String f5="";
// 定义新增语句对象
String insertSql="";
// 用于文件名凭借
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());
// 查询凭证视图, 获取每条凭证
String sql = "SELECT id,f3,f60,ID,MODULE_NAME,DEPT_NAME,F1,F15,V8_STATUS,F5,GENERATE_DATE FROM VI_VOUCHER_V8 WHERE F3 NOT IN(SELECT TABLE_NUM FROM NCXML_DETAIL_RECORDS WHERE FLAG = '1' AND XML_TYPE='"+type+"') AND DATE_FORMAT(f1,'%Y-%m')>DATE_FORMAT('2019-02-11','%Y-%m')";
@ -183,9 +190,9 @@ public class VoucherToNCforVoucherPZ implements Job{
int c = (int)(a / b);
for (int i = 0; i <=c && a>0; i++) {
// 批次号
String batch="";
batch="";
// 记录当前批次传输总量
int count=0;
count=0;
// 记录历史批次号
List<String> batchList= new ArrayList<String>();
document = DocumentHelper.createDocument(); // 创建Document对象
@ -211,11 +218,11 @@ public class VoucherToNCforVoucherPZ implements Job{
// 获取v8表借方数据
String sql1 = "SELECT f5,f6,f7,f15,f59,f60,f65,f73,f74,f75,f76 FROM VOUCHER_V8 WHERE F3=:F3 AND ENTRYDC='1'";
List<Map<String, String>> v1 = DataOperatorUtil.getDataBySql(Sqlca,sql1,map);
List<Map<String, String>> v1 = DataOperatorUtil.getDataBySql(Sqlca1,sql1,map);
// 获取v8表贷方数据
String sql2 = "SELECT f1,f5,f6,f8,f15,f51,f52,f59,f60,f65,f73,f74,f75,f76 FROM VOUCHER_V8 WHERE F3=:F3 AND ENTRYDC='-1'";
List<Map<String, String>> v2 = DataOperatorUtil.getDataBySql(Sqlca,sql2,map);
List<Map<String, String>> v2 = DataOperatorUtil.getDataBySql(Sqlca1,sql2,map);
// 获取v8表公共信息
for (Map<String, String> map2 : v2) {
@ -517,23 +524,24 @@ public class VoucherToNCforVoucherPZ implements Job{
if(record==null || "".equals(record)) {
// 有新数据, 当前批次批次号为空才会生成
if("".equals(batch)) {
batch = SerialNumberUtil.getVoucherPCNumber(Sqlca);
batch = SerialNumberUtil.getVoucherPCNumber(Sqlca1);
}
// 等于null说明新数据, 新增入记录表
insertSql="INSERT INTO NCXML_DETAIL_RECORDS(BILLID,XML_TYPE,TABLE_NUM,FLAG,CREATE_TIME,BATCH) VALUES('"+uuid+"','"+type+"','"+F3+"','1','"+year_month_days+"','"+batch+"')";
Sqlca.executeSQL(insertSql);
insertSql="INSERT INTO NCXML_DETAIL_RECORDS(BILLID,XML_TYPE,TABLE_NUM,FLAG,ERR_DESCRIBE,CREATE_TIME,BATCH) VALUES('"+uuid+"','"+type+"','"+F3+"','2','传输失败 , 请联系管理员 !','"+year_month_days+"','"+batch+"')";
Sqlca1.executeSQL(insertSql);
logger.info("凭证记录表插入语句: "+insertSql);
count++;
}else {
String updSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='1',ERR_DESCRIBE=null,CREATE_TIME='"+year_month_days+"' WHERE BILLID='"+uuid+"' AND XML_TYPE= '"+type+"'";
Sqlca.executeSQL(updSql);
logger.info("旧批次号记录: "+updSql);
// 统计旧批次
String batch1= record.getAttribute("BATCH").getString();
logger.info("记录旧批次: "+batch1);
if(batchList.indexOf(batch1) == -1) {
batchList.add(batch1);
}
}
}
}
Sqlca1.commit();
String URL=LOCALHOST_URL+"APleasing_VOUCHER_"+year_month_day+".xml";
//String URL="D:\\voucherXml_NC\\APleasing_VOUCHER_"+year_month_day+".xml";
file=new File(URL);
@ -546,22 +554,40 @@ public class VoucherToNCforVoucherPZ implements Job{
Sqlca.commit();
}
} catch (Exception e) {
logger.info("凭证xml传输失败");
try {
Sqlca.rollback();
} catch (JBOException e1) {
e1.printStackTrace();
logger.info("凭证xml传输失败");
try {
Sqlca.rollback();
if(batch!=null || !"".equals(batch)){
logger.debug("凭证xml传输失败");
/*String updateSql="UPDATE NCXML_DETAIL_RECORDS SET FLAG='2',ERR_DESCRIBE='传输过程中遇到异常, 请联系管理员 !' WHERE BATCH='"+batch+"'";
Sqlca1.executeSQL(updateSql);*/
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+"','传输失败, 请联系管理员 !','"+year_month_days+"')";
Sqlca1.executeSQL(insertSql);
Sqlca1.commit();
}
e.printStackTrace();
} catch (Exception e2) {
e2.printStackTrace();
}
e.printStackTrace();
returns="false";
}finally {
if(Sqlca!=null) {
try {
Sqlca.commit();
Sqlca.disConnect();
} catch (JBOException e) {
e.printStackTrace();
}
}
if(Sqlca1!=null) {
try {
Sqlca1.commit();
Sqlca1.disConnect();
} catch (JBOException e) {
e.printStackTrace();
}
}
}
return returns;
}
@ -690,17 +716,16 @@ public class VoucherToNCforVoucherPZ implements Job{
}
}*/
// 判断, 若失败, 更新错误录入明细表
if(!"1".equals(resultcode)) {
// 如果回执状态不等于1, 说明有误, 更新到记录字表并记录错误信息
updateSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='"+resultcode+"',ERR_DESCRIBE='"+resultdescription+"' WHERE BILLID='"+bdocid+"' AND XML_TYPE= '"+type+"'";
Sqlca.executeSQL(updateSql);
logger.info("根据回执信息, 修改传输失败状态, 记录错误信息"+updateSql);
BizObject old_record=JBOFactory.createBizObjectQuery(NCXML_DETAIL_RECORDS.CLASS_NAME, "BILLID='"+bdocid+"' AND BATCH <> '"+batch+"' AND XML_TYPE= '"+type+"'").getSingleResult(false);
if(old_record ==null) {
failed_count++;
}
}
/**
* 根据回执信息, 变更明细表记录
*/
updateSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='"+resultcode+"',ERR_DESCRIBE='"+resultdescription+"' WHERE BILLID='"+bdocid+"' AND XML_TYPE= '"+type+"'";
Sqlca.executeSQL(updateSql);
logger.info("根据回执信息, 变更明细表数据记录"+updateSql);
/*BizObject old_record=JBOFactory.createBizObjectQuery(NCXML_DETAIL_RECORDS.CLASS_NAME, "BILLID='"+bdocid+"' AND BATCH <> '"+batch+"' AND XML_TYPE= '"+type+"'").getSingleResult(false);
if(old_record ==null) {
failed_count++;
}*/
}
// 判断集合为否为null, 不为空遍历集合, 获取旧数据的批次号
@ -715,9 +740,9 @@ public class VoucherToNCforVoucherPZ implements Job{
con=Integer.valueOf(dataList.get(0).get("CON"));
}
if(con==0) {
updateSql="UPDATE NCXML_TOTAL_RECORDS SET FLAG_='Y',FAILED_COUNT='0',CREATETIME='"+formatter2.format(new Date())+"' WHERE XML_TYPE='"+type+"' AND BATCH='"+old_batch+"'";
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+"',CREATETIME='"+formatter2.format(new Date())+"' WHERE XML_TYPE='"+type+"' AND BATCH='"+old_batch+"'";
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);
}
@ -734,12 +759,12 @@ public class VoucherToNCforVoucherPZ implements Job{
}
// 如果con等于0, 说明没有失败记录, 插入成功记录
if(con==0) {
insertSql = "INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','Y','"+count+"','"+con+"','导入成功 !','"+formatter2.format(new Date())+"')";
insertSql = "INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','Y','"+count+"','"+con+"','"+resultdescription+"','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql);
logger.info("本批次传输成功!");
// 如果con不等于0, 记录含失败记录的数据如总表
}else {
insertSql = "INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','"+resSuc+"','"+count+"','"+con+"','含失败记录 !','"+formatter2.format(new Date())+"')";
insertSql = "INSERT INTO NCXML_TOTAL_RECORDS(ID,BATCH,XML_TYPE,FLAG_,COUNT_,FAILED_COUNT,ERR_DESCRIBE,CREATETIME) VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+batch+"','"+type+"','"+resSuc+"','"+count+"','"+con+"','"+resultdescription+"','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql);
logger.info("本批次包含失败数据 !");
}
@ -766,9 +791,9 @@ public class VoucherToNCforVoucherPZ implements Job{
con=Integer.valueOf(dataList.get(0).get("CON"));
}
if(con==0) {
updateSql="UPDATE NCXML_TOTAL_RECORDS SET FLAG_='Y',FAILED_COUNT='0',CREATETIME='"+formatter2.format(new Date())+"' WHERE XML_TYPE='"+type+"' AND BATCH='"+old_batch+"'";
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+"',CREATETIME='"+formatter2.format(new Date())+"' WHERE XML_TYPE='"+type+"' AND BATCH='"+old_batch+"'";
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);
}