凭证相关接口

This commit is contained in:
xiezhiwen 2019-02-26 18:29:14 +08:00
parent fb831ea047
commit 0ad29052eb
4 changed files with 495 additions and 152 deletions

View File

@ -11,6 +11,7 @@ import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -31,6 +32,7 @@ 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;
import com.amarsoft.are.jbo.JBOFactory;
import com.amarsoft.are.jbo.JBOTransaction;
@ -41,6 +43,8 @@ import com.tenwa.comm.util.date.DateAssistant;
import com.tenwa.comm.util.jboutil.DataOperatorUtil;
import com.tenwa.util.SerialNumberUtil;
import jbo.voucher.NCXML_DETAIL_RECORDS;
public class VoucherToNCforAssistContract implements Job{
private static Log logger=ARE.getLog();
/**
@ -105,9 +109,13 @@ public class VoucherToNCforAssistContract implements Job{
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 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_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) {
// 生成xml头
@ -130,8 +138,9 @@ public class VoucherToNCforAssistContract implements Job{
for (Map<String, String> map : rs) {
contract_number=(map.get("CONTRACT_NUMBER")==null)?"":map.get("CONTRACT_NUMBER");
Element bill = root.addElement("bill");
uuid=UUID.randomUUID().toString().replace("-", "");
bill.addAttribute("id", uuid);
//uuid=UUID.randomUUID().toString().replace("-", "");
uuid=map.get("id");
bill.addAttribute("id",uuid);
Element billhead = bill.addElement("billhead");
Element pk_defdoclist = billhead.addElement("pk_defdoclist");// 自定义档案列表主键,最大长度为20,类型为:String
pk_defdoclist.setText("ct01");
@ -153,10 +162,24 @@ public class VoucherToNCforAssistContract implements Job{
pid.setText("");
Element memo = billhead.addElement("memo");// 备注,最大长度为200,类型为:String
memo.setText("");
// 将记录写入辅助合同日志表
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);
logger.info("辅助合同记录语句: " + insertSql);
// 根据id查询记录表是否已经记录过, 没有记录过使用当前批次号记录, 如果已经记录了, 则不操作
BizObject record=JBOFactory.createBizObjectQuery(NCXML_DETAIL_RECORDS.CLASS_NAME, "BILLID='"+uuid+"'").getSingleResult(false);
// 等于null说明新数据, 新增入记录表
if(record==null || "".equals(record)) {
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);
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();
if(batchList.indexOf(batch1) == -1) {
batchList.add(batch1);
}
}
}
String URL="//data//files//apzl_leasing//tmp//XZW//APleasing_Defdoc_"+year_month_day+".xml";
// String URL="D:\\voucherXml_NC\\APleasing_Defdoc_"+year_month_day+".xml";
@ -165,7 +188,7 @@ public class VoucherToNCforAssistContract implements Job{
writer.setEscapeText(false);// 字符是否转义,默认true
writer.write(document);
writer.close();
InterActionToNC(Sqlca,URL,type,batch,rs.size());
InterActionToNC(Sqlca,URL,type,batch,count,batchList);
Sqlca.commit();
}
QuartzUtil.insertLog(plan_date,"com.tenwa.voucher.serviceImp.VoucherToNCforAssistContract", "success", "成功",curUserId);
@ -192,7 +215,8 @@ public class VoucherToNCforAssistContract implements Job{
/**
* 像NC传输xml, 获取NC回执xml信息, 根据回执信息更改状态
*/
public static void InterActionToNC(Transaction Sqlca,String inputURL,String type,String batch,int count) throws Exception {
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= ""; // 单条返回结果
@ -201,7 +225,7 @@ public class VoucherToNCforAssistContract implements Job{
/**
* 获取对方post连接
*/
String url = "http://172.16.0.88:9990/service/XChangeServlet?account=bq1217&groupcode=06";
String url = "http://172.16.0.88:9990/service/XChangeServlet?account=8&groupcode=06";
URL realURL = new URL(url);
HttpURLConnection connection = (HttpURLConnection)realURL.openConnection();
connection.setDoOutput(true);
@ -251,7 +275,7 @@ public class VoucherToNCforAssistContract implements Job{
SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 回执信息存放路径
String resFile = "//data//files//apzl_leasing//tmp//WEN//APleasing_"+type+""+fmt.format(new Date())+".xml";
// String resFile = "D:\\VOUCHER_RECEIPT\\APleasing_"+type+""+fmt.format(new Date())+".xml";
//String resFile = "D:\\VOUCHER_RECEIPT\\APleasing_"+type+""+fmt.format(new Date())+".xml";
StreamResult result = new StreamResult(new File(resFile));
// 将回执信息转化为xml
transformer.transform(source,result);
@ -264,6 +288,8 @@ public class VoucherToNCforAssistContract implements Job{
Element root= doc.getRootElement();
// 根据successful判断是否有失败的, 有则为N, 全部成功为Y
String resSuc = root.attributeValue("successful");
// 创建
if(null != resSuc){
// 状态为N说明本批次传输有失败的
if("N".equals(resSuc)){
@ -293,24 +319,84 @@ public class VoucherToNCforAssistContract implements Job{
resultdescription = el.getStringValue();
}
}
/*// 查询不是本批次号的bdocid, 如果有值说明是之前传输错误的数据
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 || !"".equals(old_record)) {
// 如果状态为1, 说明已经变更, 传输成功. 执行upddate操作, 变更记录状态
if(resultcode=="1" || "1".equals(resultcode)) {
updSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='"+resultcode+"',ERR_DESCRIBE=null,CREATE_TIME='"+formatter2+"' WHERE BILLID='"+bdocid+"' AND XML_TYPE= '"+type+"'";
}
}*/
// 判断, 若失败, 更新错误录入明细表
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);
failed_count++;
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++;
}
}
}
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+"','"+count+"','本次共导入: "+count+"条, 失败: "+failed_count+"条 !','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql);
logger.info("本批次包含失败数据 !");
// 判断集合为否为null, 不为空遍历集合, 获取旧数据的批次号
if(batchList != null || batchList.size()>0) {
// 定义当前批次, 错误记录数
int con=0;
for (String old_batch : batchList) {
// 查询集合, 获取旧批次的失败总数
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',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+"'";
}
Sqlca.executeSQL(updateSql);
}
}
// count不等于0说明有新数据, 否则就只有旧的错误数据, 不需要新增
if(count != 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+"','"+resSuc+"','"+count+"','"+failed_count+"','含失败记录 !','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql);
logger.info("本批次包含失败数据 !");
}
// 状态为Y表示, 本次导入全部成功
}else if(resSuc.equals("Y")){
logger.info("导入成功");
// 将本次导入信息记录入记录总表
String insertSql1="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+"','0','导入成功 !','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql1);
// count不等于0说明有新数据, 否则就只有旧的错误数据, 不需要新增
if(count != 0 ) {
// 将本次导入信息记录入记录总表
String insertSql1="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+"','0','导入成功 !','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql1);
}
// 判断集合为否为null, 不为空遍历集合, 获取旧数据的批次号
if(batchList != null) {
// 定义当前批次, 错误记录数
int con=0;
for (String old_batch : batchList) {
// 查询集合, 获取旧批次的失败总数
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',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+"'";
}
Sqlca.executeSQL(updateSql);
}
}
}else{
logger.info("出现未知错误");
}

View File

@ -11,6 +11,7 @@ import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -33,6 +34,7 @@ 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;
import com.amarsoft.are.jbo.JBOFactory;
import com.amarsoft.are.jbo.JBOTransaction;
@ -43,6 +45,8 @@ import com.tenwa.comm.util.date.DateAssistant;
import com.tenwa.comm.util.jboutil.DataOperatorUtil;
import com.tenwa.util.SerialNumberUtil;
import jbo.voucher.NCXML_DETAIL_RECORDS;
public class VoucherToNCforCustomer implements Job{
private static Log logger=ARE.getLog();
/**
@ -124,9 +128,13 @@ public class VoucherToNCforCustomer implements Job{
String year_month_days = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
// 查询为传输或之前传输失败的数据
String sql="SELECT cif.customer_num,MAX(cif.customername)customername,MAX(cif.customertype)customertype,MAX(cif.customerid) customerid 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 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 ";
List<Map<String, String>> rs = DataOperatorUtil.getDataBySql(Sqlca,sql,null);
if(rs != null && rs.size()>0) {
// 记录历史批次号
List<String> batchList= new ArrayList<String>();
// 记录当前批次传输总量
int count=0;
// 生成xml头
document= DocumentHelper.createDocument();
Element root = document.addElement("ufinterface");
@ -141,16 +149,16 @@ public class VoucherToNCforCustomer implements Job{
root.addAttribute("replace", replace);
root.addAttribute("roottag", "");
root.addAttribute("sender", sender);
String batch = SerialNumberUtil.getVoucherPCNumber(Sqlca);// 生成批次号
// 生成批次号
String batch = SerialNumberUtil.getVoucherPCNumber(Sqlca);
// 遍历要传输的结果集
for(int i=0;i<rs.size();i++) {
customer_num=rs.get(i).get("customer_num"); // 获取客户编号
customername=rs.get(i).get("customername"); // 获取客户名称
Element bill = root.addElement("bill");
uuid=UUID.randomUUID().toString().replace("-", "");
//uuid=UUID.randomUUID().toString().replace("-", "");
uuid=rs.get(i).get("id");
bill.addAttribute("id", uuid);
Element billhead = bill.addElement("billhead");
Element pk_group1 = billhead.addElement("pk_group"); // 所属集团,最大长度为20,类型为:String
@ -222,10 +230,24 @@ public class VoucherToNCforCustomer implements Job{
frozenflag.setText("");
Element enablestate = billhead.addElement("enablestate"); // 启用状态,最大长度为0,类型为:Integer
enablestate.setText("");
// 将客户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);
logger.info("客户记录语句: "+insertSql);
// 根据id查询记录表是否已经记录过, 没有记录过使用当前批次号记录, 如果已经记录了, 则不操作
BizObject record=JBOFactory.createBizObjectQuery(NCXML_DETAIL_RECORDS.CLASS_NAME, "BILLID='"+uuid+"'").getSingleResult(false);
// 等于null说明新数据, 新增入记录表
if(record==null || "".equals(record)) {
// 将客户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);
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();
if(batchList.indexOf(batch1) == -1) {
batchList.add(batch1);
}
}
}
String URL="//data//files//apzl_leasing//tmp//XZW//APleasing_Customer_"+year_month_day+".xml";
// String URL="D:\\voucherXml_NC\\APleasing_Customer_"+year_month_day+".xml";
@ -234,7 +256,7 @@ public class VoucherToNCforCustomer implements Job{
writer.setEscapeText(false);// 字符是否转义,默认true
writer.write(document);
writer.close();
InterActionToNC(Sqlca,URL,type,batch,rs.size());
InterActionToNC(Sqlca,URL,type,batch,count,batchList);
Sqlca.commit();
QuartzUtil.insertLog(plan_date,"com.tenwa.voucher.serviceImp.VoucherToNCforCustomer", "success", "成功",curUserId);
}
@ -261,7 +283,8 @@ public class VoucherToNCforCustomer implements Job{
/**
* 像NC传输xml, 获取NC回执xml信息, 根据回执信息更改状态
*/
public static void InterActionToNC(Transaction Sqlca,String inputURL,String type,String batch,int count) throws Exception {
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= ""; // 单条返回结果
@ -270,7 +293,7 @@ public class VoucherToNCforCustomer implements Job{
/**
* 获取对方post连接
*/
String url = "http://172.16.0.88:9990/service/XChangeServlet?account=bq1217&groupcode=06";
String url = "http://172.16.0.88:9990/service/XChangeServlet?account=8&groupcode=06";
URL realURL = new URL(url);
HttpURLConnection connection = (HttpURLConnection)realURL.openConnection();
connection.setDoOutput(true);
@ -320,7 +343,7 @@ public class VoucherToNCforCustomer implements Job{
SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 回执信息存放路径
String resFile = "//data//files//apzl_leasing//tmp//WEN//APleasing_"+type+""+fmt.format(new Date())+".xml";
// String resFile = "D:\\VOUCHER_RECEIPT\\APleasing_"+type+""+fmt.format(new Date())+".xml";
//String resFile = "D:\\VOUCHER_RECEIPT\\APleasing_"+type+""+fmt.format(new Date())+".xml";
StreamResult result = new StreamResult(new File(resFile));
// 将回执信息转化为xml
transformer.transform(source,result);
@ -333,6 +356,8 @@ public class VoucherToNCforCustomer implements Job{
Element root= doc.getRootElement();
// 根据successful判断是否有失败的, 有则为N, 全部成功为Y
String resSuc = root.attributeValue("successful");
// 创建
if(null != resSuc){
// 状态为N说明本批次传输有失败的
if("N".equals(resSuc)){
@ -362,24 +387,84 @@ public class VoucherToNCforCustomer implements Job{
resultdescription = el.getStringValue();
}
}
/*// 查询不是本批次号的bdocid, 如果有值说明是之前传输错误的数据
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 || !"".equals(old_record)) {
// 如果状态为1, 说明已经变更, 传输成功. 执行upddate操作, 变更记录状态
if(resultcode=="1" || "1".equals(resultcode)) {
updSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='"+resultcode+"',ERR_DESCRIBE=null,CREATE_TIME='"+formatter2+"' WHERE BILLID='"+bdocid+"' AND XML_TYPE= '"+type+"'";
}
}*/
// 判断, 若失败, 更新错误录入明细表
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);
failed_count++;
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++;
}
}
}
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+"','"+count+"','本次共导入: "+count+"条, 失败: "+failed_count+"条 !','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql);
logger.info("本批次包含失败数据 !");
// 判断集合为否为null, 不为空遍历集合, 获取旧数据的批次号
if(batchList != null || batchList.size()>0) {
// 定义当前批次, 错误记录数
int con=0;
for (String old_batch : batchList) {
// 查询集合, 获取旧批次的失败总数
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',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+"'";
}
Sqlca.executeSQL(updateSql);
}
}
// count不等于0说明有新数据, 否则就只有旧的错误数据, 不需要新增
if(count != 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+"','"+resSuc+"','"+count+"','"+failed_count+"','含失败记录 !','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql);
logger.info("本批次包含失败数据 !");
}
// 状态为Y表示, 本次导入全部成功
}else if(resSuc.equals("Y")){
logger.info("导入成功");
// 将本次导入信息记录入记录总表
String insertSql1="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+"','0','导入成功 !','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql1);
// count不等于0说明有新数据, 否则就只有旧的错误数据, 不需要新增
if(count != 0 ) {
// 将本次导入信息记录入记录总表
String insertSql1="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+"','0','导入成功 !','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql1);
}
// 判断集合为否为null, 不为空遍历集合, 获取旧数据的批次号
if(batchList != null) {
// 定义当前批次, 错误记录数
int con=0;
for (String old_batch : batchList) {
// 查询集合, 获取旧批次的失败总数
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',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+"'";
}
Sqlca.executeSQL(updateSql);
}
}
}else{
logger.info("出现未知错误");
}

View File

@ -11,6 +11,7 @@ import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -33,6 +34,7 @@ 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;
import com.amarsoft.are.jbo.JBOFactory;
import com.amarsoft.are.jbo.JBOTransaction;
@ -44,6 +46,8 @@ import com.tenwa.comm.util.date.DateAssistant;
import com.tenwa.comm.util.jboutil.DataOperatorUtil;
import com.tenwa.util.SerialNumberUtil;
import jbo.voucher.NCXML_DETAIL_RECORDS;
public class VoucherToNCforDistributor implements Job{
private static Log logger=ARE.getLog();
/**
@ -126,12 +130,16 @@ public class VoucherToNCforDistributor implements Job{
String insertSql=""; // 新增语句
String uuid=""; // uuid
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 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' ";
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) {
// 设置xml标签头
@ -172,7 +180,8 @@ public class VoucherToNCforDistributor implements Job{
region = NameManager.getItemName("AreaCode",DISTRIBUTOR_ADDRESS); // 获取地区
Element bill = root.addElement("bill");
uuid=UUID.randomUUID().toString().replace("-", "");
//uuid=UUID.randomUUID().toString().replace("-", "");
uuid=rs.get(i).get("id");
bill.addAttribute("id",uuid);
Element billhead = bill.addElement("billhead");
Element pk_group1 = billhead.addElement("pk_group"); // 所属集团,最大长度为20,类型为:String
@ -300,19 +309,32 @@ public class VoucherToNCforDistributor implements Job{
Element corpaddress = billhead.addElement("corpaddress"); // 企业地址主键,最大长度为20,类型为:String
corpaddress.setText((FACT_ADDR==null)?"":FACT_ADDR);*/
// 像记录表添加数据
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);
logger.info("经销商记录语句: "+ insertSql);
// 根据id查询记录表是否已经记录过, 没有记录过使用当前批次号记录, 如果已经记录了, 则不操作
BizObject record=JBOFactory.createBizObjectQuery(NCXML_DETAIL_RECORDS.CLASS_NAME, "BILLID='"+uuid+"'").getSingleResult(false);
// 等于null说明新数据, 新增入记录表
if(record==null || "".equals(record)) {
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);
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();
if(batchList.indexOf(batch1) == -1) {
batchList.add(batch1);
}
}
}
// String f="D:\\voucherXml_NC\\APleasing_Supplier_"+year_month_day+".xml";
//String f="D:\\voucherXml_NC\\APleasing_Supplier_"+year_month_day+".xml";
String f="//data//files//apzl_leasing//tmp//XZW//APleasing_Supplier_"+year_month_day+".xml";
file=new File(f);
writer = new XMLWriter(new FileOutputStream(file), OutputFormat.createPrettyPrint());
writer.setEscapeText(false);// 字符是否转义,默认true
writer.write(document);
writer.close();
InterActionToNC(Sqlca,f,type,batch,rs.size());
InterActionToNC(Sqlca,f,type,batch,count,batchList);
Sqlca.commit();
QuartzUtil.insertLog(plan_date,"com.tenwa.voucher.serviceImp.VoucherToNCforDistributor", "success", "成功",curUserId);
}
@ -340,7 +362,8 @@ public class VoucherToNCforDistributor implements Job{
/**
* 像NC传输xml, 获取NC回执xml信息, 根据回执信息更改状态
*/
public static void InterActionToNC(Transaction Sqlca,String inputURL,String type,String batch,int count) throws Exception {
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= ""; // 单条返回结果
@ -349,7 +372,7 @@ public class VoucherToNCforDistributor implements Job{
/**
* 获取对方post连接
*/
String url = "http://172.16.0.88:9990/service/XChangeServlet?account=bq1217&groupcode=06";
String url = "http://172.16.0.88:9990/service/XChangeServlet?account=8&groupcode=06";
URL realURL = new URL(url);
HttpURLConnection connection = (HttpURLConnection)realURL.openConnection();
connection.setDoOutput(true);
@ -399,7 +422,7 @@ public class VoucherToNCforDistributor implements Job{
SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 回执信息存放路径
String resFile = "//data//files//apzl_leasing//tmp//WEN//APleasing_"+type+""+fmt.format(new Date())+".xml";
// String resFile = "D:\\VOUCHER_RECEIPT\\APleasing_"+type+""+fmt.format(new Date())+".xml";
//String resFile = "D:\\VOUCHER_RECEIPT\\APleasing_"+type+""+fmt.format(new Date())+".xml";
StreamResult result = new StreamResult(new File(resFile));
// 将回执信息转化为xml
transformer.transform(source,result);
@ -412,6 +435,8 @@ public class VoucherToNCforDistributor implements Job{
Element root= doc.getRootElement();
// 根据successful判断是否有失败的, 有则为N, 全部成功为Y
String resSuc = root.attributeValue("successful");
// 创建
if(null != resSuc){
// 状态为N说明本批次传输有失败的
if("N".equals(resSuc)){
@ -441,24 +466,84 @@ public class VoucherToNCforDistributor implements Job{
resultdescription = el.getStringValue();
}
}
/*// 查询不是本批次号的bdocid, 如果有值说明是之前传输错误的数据
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 || !"".equals(old_record)) {
// 如果状态为1, 说明已经变更, 传输成功. 执行upddate操作, 变更记录状态
if(resultcode=="1" || "1".equals(resultcode)) {
updSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='"+resultcode+"',ERR_DESCRIBE=null,CREATE_TIME='"+formatter2+"' WHERE BILLID='"+bdocid+"' AND XML_TYPE= '"+type+"'";
}
}*/
// 判断, 若失败, 更新错误录入明细表
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);
failed_count++;
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++;
}
}
}
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+"','"+count+"','本次共导入: "+count+"条, 失败: "+failed_count+"条 !','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql);
logger.info("本批次包含失败数据 !");
// 判断集合为否为null, 不为空遍历集合, 获取旧数据的批次号
if(batchList != null || batchList.size()>0) {
// 定义当前批次, 错误记录数
int con=0;
for (String old_batch : batchList) {
// 查询集合, 获取旧批次的失败总数
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',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+"'";
}
Sqlca.executeSQL(updateSql);
}
}
// count不等于0说明有新数据, 否则就只有旧的错误数据, 不需要新增
if(count != 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+"','"+resSuc+"','"+count+"','"+failed_count+"','含失败记录 !','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql);
logger.info("本批次包含失败数据 !");
}
// 状态为Y表示, 本次导入全部成功
}else if(resSuc.equals("Y")){
logger.info("导入成功");
// 将本次导入信息记录入记录总表
String insertSql1="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+"','0','导入成功 !','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql1);
// count不等于0说明有新数据, 否则就只有旧的错误数据, 不需要新增
if(count != 0 ) {
// 将本次导入信息记录入记录总表
String insertSql1="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+"','0','导入成功 !','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql1);
}
// 判断集合为否为null, 不为空遍历集合, 获取旧数据的批次号
if(batchList != null) {
// 定义当前批次, 错误记录数
int con=0;
for (String old_batch : batchList) {
// 查询集合, 获取旧批次的失败总数
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',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+"'";
}
Sqlca.executeSQL(updateSql);
}
}
}else{
logger.info("出现未知错误");
}

View File

@ -11,6 +11,7 @@ import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@ -44,7 +45,10 @@ import com.tenwa.comm.util.date.DateAssistant;
import com.tenwa.comm.util.jboutil.DataOperatorUtil;
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;
public class VoucherToNCforVoucherPZ implements Job{
private static Log logger=ARE.getLog();
@ -167,9 +171,9 @@ public class VoucherToNCforVoucherPZ implements Job{
String year_month_days = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
// 查询凭证视图, 获取每条凭证
String sql = "SELECT 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-01-11','%Y-%m')";
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-01-11','%Y-%m') AND F3 IN('k5031','k5032','k5033')";
List<Map<String, String>> list = DataOperatorUtil.getDataBySql(Sqlca, sql, null);// 将所有凭证号封装到list集合中
// v8视图总数据量/ xml中生成的总条数
int a = list.size();
// 设置当前xml生成的条数
@ -178,8 +182,9 @@ public class VoucherToNCforVoucherPZ implements Job{
int c = (int)(a / b);
for (int i = 0; i <=c && a>0; i++) {
// 记录当前批次传输总量
int count=0;
Sqlca = Transaction.createTransaction(tx);
int count=0;
// 记录历史批次号
List<String> batchList= new ArrayList<String>();
document = DocumentHelper.createDocument(); // 创建Document对象
// 设置xml头
Element root = document.addElement("ufinterface");
@ -220,9 +225,10 @@ 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=UUID.randomUUID().toString().replace("-", "");
uuid=list.get(x).get("id");
Element voucher = root.addElement("voucher");
voucher.addAttribute("id", uuid);
voucher.addAttribute("id",uuid);
Element voucherHead = voucher.addElement("voucher_head");
Element pkVoucher = voucherHead.addElement("pk_voucher");// 凭证主键/非空
// pkVoucher.setText(uuid);
@ -283,11 +289,13 @@ public class VoucherToNCforVoucherPZ implements Job{
SUBJECT_ID=v8Lend.get("f6");
f5 = v8Lend.get("f5");
BizObject subject = JBOFactory.createBizObjectQuery(LV_STACTS_CONFIG.CLASS_NAME, "ID=:ID").setParameter("ID", SUBJECT_ID).getSingleResult(false);
// 获取辅助核算id
String ids=subject.getAttribute("AUXILIARY_TYPE").getString();
Element item1 = details.addElement("item"); // 借方
Element detailindex1 = item1.addElement("detailindex");// 分录号/非空
detailindex1.setText((v8Lend.get("f59")==null)?"":v8Lend.get("f59"));//------------------------------------
Element explanation1 = item1.addElement("explanation");// 摘要/非空
explanation1.setText(F3+"-"+f5);
explanation1.setText(F3+"-"+f5+"66");
Element verifydate1 = item1.addElement("verifydate");// 业务日期/可空
verifydate1.setText("");
Element price1 = item1.addElement("price");// 单价/可空
@ -315,44 +323,50 @@ public class VoucherToNCforVoucherPZ implements Job{
pk_unit_v1.setText("");//-------------------------------------------------
Element ass1 = item1.addElement("ass");// 金额必须有一方不为空
// 客商辅助核算
if(v8Lend.get("f65")!=null && !"".equals(v8Lend.get("f65"))) {
Element ass_item1 = ass1.addElement("item");
Element pk_Checktype1 = ass_item1.addElement("pk_Checktype");
pk_Checktype1.setText("客商");
Element pk_Checkvalue1 = ass_item1.addElement("pk_Checkvalue");
pk_Checkvalue1.setText((v8Lend.get("f65")==null)?"":v8Lend.get("f65"));
if(ids.contains("185b89e22dba458491306a647468d2a5")) {
Element ass_item1 = ass1.addElement("item");
Element pk_Checktype1 = ass_item1.addElement("pk_Checktype");
pk_Checktype1.setText("客商");
Element pk_Checkvalue1 = ass_item1.addElement("pk_Checkvalue");
//pk_Checkvalue1.setText("APZL0201000000");
pk_Checkvalue1.setText((v8Lend.get("f65")==null)?"APZL0201000000":v8Lend.get("f65"));
}
// 合同号辅助核算
if(v8Lend.get("f60")!=null && !"".equals(v8Lend.get("f60"))) {// 部门名称
Element ass_item2 = ass1.addElement("item");
Element pk_Checktype2 = ass_item2.addElement("pk_Checktype");
pk_Checktype2.setText("合同号");
Element pk_Checkvalue2 = ass_item2.addElement("pk_Checkvalue");
pk_Checkvalue2.setText((v8Lend.get("f60")==null)?"":v8Lend.get("f60"));
if(ids.contains("1869733a51f1486a97df402e8d899980")) {
Element ass_item2 = ass1.addElement("item");
Element pk_Checktype2 = ass_item2.addElement("pk_Checktype");
pk_Checktype2.setText("合同号");
Element pk_Checkvalue2 = ass_item2.addElement("pk_Checkvalue");
//pk_Checkvalue2.setText("ap0000");
pk_Checkvalue2.setText((v8Lend.get("f60")==null)?"ap0000":v8Lend.get("f60"));
}
// 主营类型辅助核算
if(v8Lend.get("f73")!=null && !"".equals(v8Lend.get("f73"))) {
Element ass_item3 = ass1.addElement("item");
Element pk_Checktype3 = ass_item3.addElement("pk_Checktype");
pk_Checktype3.setText("主营类型");
Element pk_Checkvalue3 = ass_item3.addElement("pk_Checkvalue");
pk_Checkvalue3.setText((v8Lend.get("f73")==null)?"":v8Lend.get("f73"));
if(ids.contains("1c981e6e47c24d069f9a2e08db819c4c")) {
if(v8Lend.get("f73")!=null && !"".equals(v8Lend.get("f73"))) {
Element ass_item3 = ass1.addElement("item");
Element pk_Checktype3 = ass_item3.addElement("pk_Checktype");
pk_Checktype3.setText("主营类型");
Element pk_Checkvalue3 = ass_item3.addElement("pk_Checkvalue");
pk_Checkvalue3.setText((v8Lend.get("f73")==null)?"":v8Lend.get("f73"));
}
}
//现金流量项目辅助核算
if(v8Lend.get("f74")!=null && !"".equals(v8Lend.get("f74"))) {
Element ass_item4 = ass1.addElement("item");
Element pk_Checktype4 = ass_item4.addElement("pk_Checktype");
pk_Checktype4.setText("现金流量项目");
Element pk_Checkvalue4 = ass_item4.addElement("pk_Checkvalue");
pk_Checkvalue4.setText((v8Lend.get("f74")==null)?"":v8Lend.get("f74"));
if(ids.contains("3f0177c4295d4ed99ef18adb37c3e79f")) {
Element ass_item4 = ass1.addElement("item");
Element pk_Checktype4 = ass_item4.addElement("pk_Checktype");
pk_Checktype4.setText("现金流量项目");
Element pk_Checkvalue4 = ass_item4.addElement("pk_Checkvalue");
pk_Checkvalue4.setText((v8Lend.get("f74")==null)?"":v8Lend.get("f74"));
}
//银行账户辅助核算
if(v8Lend.get("f75")!=null && !"".equals(v8Lend.get("f75"))) {
Element ass_item5 = ass1.addElement("item");
Element pk_Checktype5 = ass_item5.addElement("pk_Checktype");
pk_Checktype5.setText("银行账户");
Element pk_Checkvalue5 = ass_item5.addElement("pk_Checkvalue");
pk_Checkvalue5.setText((v8Lend.get("f75")==null)?"":v8Lend.get("f75"));
if(ids.contains("5d241cc0d2794ef7943df15c5f97976a")) {
Element ass_item5 = ass1.addElement("item");
Element pk_Checktype5 = ass_item5.addElement("pk_Checktype");
pk_Checktype5.setText("银行账户");
Element pk_Checkvalue5 = ass_item5.addElement("pk_Checkvalue");
pk_Checkvalue5.setText((v8Lend.get("f75")==null)?"":v8Lend.get("f75"));
}
Element cashFlow = item1.addElement("cashFlow");
Element cashFlow_item1 = cashFlow.addElement("item");
@ -377,6 +391,8 @@ public class VoucherToNCforVoucherPZ implements Job{
// 根据科目id, 获取当前数据对应的科目信息
SUBJECT_ID=v8loan.get("f6");
BizObject subject = JBOFactory.createBizObjectQuery(LV_STACTS_CONFIG.CLASS_NAME, "ID=:ID").setParameter("ID", SUBJECT_ID).getSingleResult(false);
// 获取辅助核算id
String ids=subject.getAttribute("AUXILIARY_TYPE").getString();
Element item2 = details.addElement("item"); // 贷方金额
Element creditquantity2 = item2.addElement("creditquantity");// 贷方数量 可空
creditquantity2.setText(v2.size()+"");
@ -391,7 +407,7 @@ public class VoucherToNCforVoucherPZ implements Job{
Element detailindex2 = item2.addElement("detailindex");// 分录号 非空
detailindex2.setText((v8loan.get("f59")==null)?"":v8loan.get("f59"));//-------------------------------------
Element explanation2 = item2.addElement("explanation");// 摘要 非空
explanation2.setText((v8loan.get("f5")==null)?"":v8loan.get("f5"));
explanation2.setText(F3+"-"+f5+"66");
Element verifydate2 = item2.addElement("verifydate");// 业务日期 可空
verifydate2.setText(timeAll);
Element price2 = item2.addElement("price");// 单价 可空
@ -409,44 +425,48 @@ public class VoucherToNCforVoucherPZ implements Job{
pk_unit_v2.setText("");//-----------------------------------------------
Element ass2 = item2.addElement("ass");//
// 客商辅助核算
if(v8loan.get("f65")!=null && !"".equals(v8loan.get("f65"))) {
Element ass_item1 = ass2.addElement("item");
Element pk_Checktype1 = ass_item1.addElement("pk_Checktype");
pk_Checktype1.setText("客商");
Element pk_Checkvalue1 = ass_item1.addElement("pk_Checkvalue");
pk_Checkvalue1.setText((v8loan.get("f65")==null)?"":v8loan.get("f65"));
if(ids.contains("185b89e22dba458491306a647468d2a5")) {
if(v8loan.get("f65")!=null && !"".equals(v8loan.get("f65"))) {
Element ass_item1 = ass2.addElement("item");
Element pk_Checktype1 = ass_item1.addElement("pk_Checktype");
pk_Checktype1.setText("客商");
Element pk_Checkvalue1 = ass_item1.addElement("pk_Checkvalue");
//pk_Checkvalue1.setText("APZL0201000000");
pk_Checkvalue1.setText((v8loan.get("f65")==null)?"APZL0201000000":v8loan.get("f65"));
}
}
// 合同号辅助核算
if(v8loan.get("f60")!=null && !"".equals(v8loan.get("f60"))) {// 部门名称
Element ass_item2 = ass2.addElement("item");
Element pk_Checktype2 = ass_item2.addElement("pk_Checktype");
pk_Checktype2.setText("合同号");
Element pk_Checkvalue2 = ass_item2.addElement("pk_Checkvalue");
pk_Checkvalue2.setText((v8loan.get("f60")==null)?"":v8loan.get("f60"));
if(ids.contains("1869733a51f1486a97df402e8d899980")) {
Element ass_item2 = ass2.addElement("item");
Element pk_Checktype2 = ass_item2.addElement("pk_Checktype");
pk_Checktype2.setText("合同号");
Element pk_Checkvalue2 = ass_item2.addElement("pk_Checkvalue");
//pk_Checkvalue2.setText("ap0000");
pk_Checkvalue2.setText((v8loan.get("f60")==null)?"ap0000":v8loan.get("f60"));
}
// 主营类型辅助核算
if(v8loan.get("f73")!=null && !"".equals(v8loan.get("f73"))) {
Element ass_item3 = ass2.addElement("item");
Element pk_Checktype3 = ass_item3.addElement("pk_Checktype");
pk_Checktype3.setText("主营类型");
Element pk_Checkvalue3 = ass_item3.addElement("pk_Checkvalue");
pk_Checkvalue3.setText((v8loan.get("f73")==null)?"":v8loan.get("f73"));
if(ids.contains("1c981e6e47c24d069f9a2e08db819c4c")) {
Element ass_item3 = ass2.addElement("item");
Element pk_Checktype3 = ass_item3.addElement("pk_Checktype");
pk_Checktype3.setText("主营类型");
Element pk_Checkvalue3 = ass_item3.addElement("pk_Checkvalue");
pk_Checkvalue3.setText((v8loan.get("f73")==null)?"":v8loan.get("f73"));
}
//现金流量项目辅助核算
if(v8loan.get("f74")!=null && !"".equals(v8loan.get("f74"))) {
Element ass_item4 = ass2.addElement("item");
Element pk_Checktype4 = ass_item4.addElement("pk_Checktype");
pk_Checktype4.setText("现金流量项目");
Element pk_Checkvalue4 = ass_item4.addElement("pk_Checkvalue");
pk_Checkvalue4.setText((v8loan.get("f74")==null)?"":v8loan.get("f74"));
if(ids.contains("3f0177c4295d4ed99ef18adb37c3e79f")) {
Element ass_item4 = ass2.addElement("item");
Element pk_Checktype4 = ass_item4.addElement("pk_Checktype");
pk_Checktype4.setText("现金流量项目");
Element pk_Checkvalue4 = ass_item4.addElement("pk_Checkvalue");
pk_Checkvalue4.setText((v8loan.get("f74")==null)?"":v8loan.get("f74"));
}
//银行账户辅助核算
if(v8loan.get("f75")!=null && !"".equals(v8loan.get("f75"))) {
Element ass_item5 = ass2.addElement("item");
Element pk_Checktype5 = ass_item5.addElement("pk_Checktype");
pk_Checktype5.setText("银行账户");
Element pk_Checkvalue5 = ass_item5.addElement("pk_Checkvalue");
pk_Checkvalue5.setText((v8loan.get("f75")==null)?"":v8loan.get("f75"));
if(ids.contains("5d241cc0d2794ef7943df15c5f97976a")) {
Element ass_item5 = ass2.addElement("item");
Element pk_Checktype5 = ass_item5.addElement("pk_Checktype");
pk_Checktype5.setText("银行账户");
Element pk_Checkvalue5 = ass_item5.addElement("pk_Checkvalue");
pk_Checkvalue5.setText((v8loan.get("f75")==null)?"":v8loan.get("f75"));
}
Element item2_cashFlow = item2.addElement("cashFlow");
Element cashflowitem2 = item2_cashFlow.addElement("item");
@ -465,23 +485,33 @@ public class VoucherToNCforVoucherPZ implements Job{
Element pk_innercorp2 = cashflowitem2.addElement("pk_innercorp");// 内部单位主键,最大长度为64,类型为:String
pk_innercorp2.setText("");
}
// 新增当条凭证信息入记录字表
//insertSql="INSERT INTO VOUCHER_LOG(BILLID,F3,FLAG,CREATE_TIME,BATCH) VALUES('"+str+"','"+F3+"','1','"+year_month_days+"','"+batch+"')";
insertSql="INSERT INTO NCXML_DETAIL_RECORDS(BILLID,XML_TYPE,TABLE_NUM,FLAG,CREATE_TIME,BATCH) VALUES('"+uuid+"','"+type+"','"+F3+"','1','"+year_month_days+"','"+batch+"')";
//sqlObject = new SqlObject(insertSql);
//Sqlca.executeSQL(sqlObject);
Sqlca.executeSQL(insertSql);
logger.info("凭证记录表插入语句: "+insertSql);
count++;
// 根据id查询记录表是否已经记录过, 没有记录过使用当前批次号记录, 如果已经记录了, 则不操作
BizObject record=JBOFactory.createBizObjectQuery(NCXML_DETAIL_RECORDS.CLASS_NAME, "BILLID='"+uuid+"'").getSingleResult(false);
if(record==null || "".equals(record)) {
// 等于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);
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();
if(batchList.indexOf(batch1) == -1) {
batchList.add(batch1);
}
}
}
//String URL="//data//files//apzl_leasing//tmp//XZW//APleasing_VOUCHER_"+year_month_day+".xml";
String URL="D:\\voucherXml_NC\\APleasing_VOUCHER_"+year_month_day+".xml";
String URL="//data//files//apzl_leasing//tmp//XZW//APleasing_VOUCHER_"+year_month_day+".xml";
//String URL="D:\\voucherXml_NC\\APleasing_VOUCHER_"+year_month_day+".xml";
file=new File(URL);
writer = new XMLWriter(new FileOutputStream(file), OutputFormat.createPrettyPrint());
writer.setEscapeText(false);// 字符是否转义,默认true
writer.write(document);
writer.close();
InterActionToNC(Sqlca,URL,type,batch,count);
InterActionToNC(Sqlca,URL,type,batch,count,batchList);
Sqlca.commit();
}
} catch (Exception e) {
@ -492,12 +522,6 @@ public class VoucherToNCforVoucherPZ implements Job{
e1.printStackTrace();
}
returns="false";
try {
Sqlca.rollback();
} catch (JBOException e1) {
e1.printStackTrace();
}
e.printStackTrace();
}finally {
if(Sqlca!=null) {
try {
@ -514,7 +538,8 @@ public class VoucherToNCforVoucherPZ implements Job{
/**
* 像NC传输xml, 获取NC回执xml信息, 根据回执信息更改状态
*/
public static void InterActionToNC(Transaction Sqlca,String inputURL,String type,String batch,int count) throws Exception {
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= ""; // 单条返回结果
@ -523,7 +548,7 @@ public class VoucherToNCforVoucherPZ implements Job{
/**
* 获取对方post连接
*/
String url = "http://172.16.0.88:9990/service/XChangeServlet?account=bq1217&groupcode=06";
String url = "http://172.16.0.88:9990/service/XChangeServlet?account=8&groupcode=06";
URL realURL = new URL(url);
HttpURLConnection connection = (HttpURLConnection)realURL.openConnection();
connection.setDoOutput(true);
@ -572,8 +597,8 @@ public class VoucherToNCforVoucherPZ implements Job{
// 表数据记录日期
SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 回执信息存放路径
//String resFile = "//data//files//apzl_leasing//tmp//WEN//APleasing_"+type+""+fmt.format(new Date())+".xml";
String resFile = "D:\\VOUCHER_RECEIPT\\APleasing_"+type+""+fmt.format(new Date())+".xml";
String resFile = "//data//files//apzl_leasing//tmp//WEN//APleasing_"+type+""+fmt.format(new Date())+".xml";
//String resFile = "D:\\VOUCHER_RECEIPT\\APleasing_"+type+""+fmt.format(new Date())+".xml";
StreamResult result = new StreamResult(new File(resFile));
// 将回执信息转化为xml
transformer.transform(source,result);
@ -586,6 +611,8 @@ public class VoucherToNCforVoucherPZ implements Job{
Element root= doc.getRootElement();
// 根据successful判断是否有失败的, 有则为N, 全部成功为Y
String resSuc = root.attributeValue("successful");
// 创建
if(null != resSuc){
// 状态为N说明本批次传输有失败的
if("N".equals(resSuc)){
@ -615,24 +642,84 @@ public class VoucherToNCforVoucherPZ implements Job{
resultdescription = el.getStringValue();
}
}
/*// 查询不是本批次号的bdocid, 如果有值说明是之前传输错误的数据
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 || !"".equals(old_record)) {
// 如果状态为1, 说明已经变更, 传输成功. 执行upddate操作, 变更记录状态
if(resultcode=="1" || "1".equals(resultcode)) {
updSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='"+resultcode+"',ERR_DESCRIBE=null,CREATE_TIME='"+formatter2+"' WHERE BILLID='"+bdocid+"' AND XML_TYPE= '"+type+"'";
}
}*/
// 判断, 若失败, 更新错误录入明细表
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);
failed_count++;
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++;
}
}
}
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+"','"+count+"','本次共导入: "+count+"条, 失败: "+failed_count+"条 !','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql);
logger.info("本批次包含失败数据 !");
// 判断集合为否为null, 不为空遍历集合, 获取旧数据的批次号
if(batchList != null || batchList.size()>0) {
// 定义当前批次, 错误记录数
int con=0;
for (String old_batch : batchList) {
// 查询集合, 获取旧批次的失败总数
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',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+"'";
}
Sqlca.executeSQL(updateSql);
}
}
// count不等于0说明有新数据, 否则就只有旧的错误数据, 不需要新增
if(count != 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+"','"+resSuc+"','"+count+"','"+failed_count+"','含失败记录 !','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql);
logger.info("本批次包含失败数据 !");
}
// 状态为Y表示, 本次导入全部成功
}else if(resSuc.equals("Y")){
logger.info("导入成功");
// 将本次导入信息记录入记录总表
String insertSql1="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+"','0','导入成功 !','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql1);
// count不等于0说明有新数据, 否则就只有旧的错误数据, 不需要新增
if(count != 0 ) {
// 将本次导入信息记录入记录总表
String insertSql1="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+"','0','导入成功 !','"+formatter2.format(new Date())+"')";
Sqlca.executeSQL(insertSql1);
}
// 判断集合为否为null, 不为空遍历集合, 获取旧数据的批次号
if(batchList != null) {
// 定义当前批次, 错误记录数
int con=0;
for (String old_batch : batchList) {
// 查询集合, 获取旧批次的失败总数
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',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+"'";
}
Sqlca.executeSQL(updateSql);
}
}
}else{
logger.info("出现未知错误");
}