diff --git a/src_core/com/tenwa/voucher/serviceImp/VoucherToNCforAssistContract.java b/src_core/com/tenwa/voucher/serviceImp/VoucherToNCforAssistContract.java index f40da6762..7dcc9acad 100644 --- a/src_core/com/tenwa/voucher/serviceImp/VoucherToNCforAssistContract.java +++ b/src_core/com/tenwa/voucher/serviceImp/VoucherToNCforAssistContract.java @@ -14,15 +14,12 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.UUID; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; 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; @@ -46,72 +43,110 @@ import com.tenwa.util.SerialNumberUtil; public class VoucherToNCforAssistContract implements Job{ private static Log logger=ARE.getLog(); - // 客商信息传输 + /** + * 客户信息传输 + */ public void execute(JobExecutionContext arg0) throws JobExecutionException { - String plan_date = DateAssistant.getToday(); + String plan_date = DateAssistant.getToday(); Object userId = arg0.getTrigger().getJobDataMap().get("CurUserId"); String curUserId = userId == null? "system" : userId.toString(); + // 定义事物 JBOTransaction tx=null; Transaction Sqlca = null; + // 获取配置文件的输入流 + FileInputStream in; try { tx= JBOFactory.createJBOTransaction(); Sqlca = Transaction.createTransaction(tx); - File file=null; // 文件对象 - XMLWriter writer=null; // 输出对象 - String uuid=""; // xml传输id - String insertSql=""; // 插入sql对象 - String contract_number=""; // 合同编码对象 - String contract_name=""; // 合同名称对象 - String type="contract"; // xml类别 - String ID=""; // xml类别 - - // 获取特定的日期 + /** + * 读取配置文件信息 + * */ + // 创建Properties对象 + Properties properties = new Properties(); + // 获取配置文件输入流 + in = new FileInputStream("/vouchers.properties"); + // 通过Properties对象读取配置文件 + properties.load(in); + // 获取配置文件数据 + // 账套 + String account = properties.getProperty("contract_account"); + // 单据类型 + String billtype = properties.getProperty("contract_billtype"); + // 集团编码 + String groupcode = properties.getProperty("contract_groupcode"); + // 系统参数 + String isexchange = properties.getProperty("contract_isexchange"); + // 接收方 + String receiver = properties.getProperty("contract_receiver"); + // 外系统编码 + String sender = properties.getProperty("contract_sender"); + // 系统参数 + String replace = properties.getProperty("contract_replace"); + // 所属组织 + String pk_org = properties.getProperty("contract_pk_org"); + // 所属集团 + String pk_group = properties.getProperty("contract_pk_group"); + /** + * 定义全局变量 + */ + // 文件对象 + File file=null; + // 输出对象 + XMLWriter writer=null; + // xml传输id + String uuid=""; + // 插入sql对象 + 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());// 年月日时分秒 // 获取未传输及之前传输失败的数据 - String sql="SELECT CONTRACT_NUMBER,PRODUCT_NAME,ID 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 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> rs = DataOperatorUtil.getDataBySql(Sqlca,sql,null); if(rs!=null && rs.size()>0) { // 生成xml头 Document document = DocumentHelper.createDocument(); // 生成每个xml的头 Element root = document.addElement("ufinterface"); - root.addAttribute("account","bq1217"); - root.addAttribute("billtype","defdoc"); + root.addAttribute("account",account); + root.addAttribute("billtype",billtype); root.addAttribute("businessunitcode",""); root.addAttribute("filename",""); - root.addAttribute("groupcode","06"); - root.addAttribute("isexchange","Y"); + root.addAttribute("groupcode",groupcode); + root.addAttribute("isexchange",isexchange); root.addAttribute("orgcode",""); - root.addAttribute("receiver","807001002001"); - root.addAttribute("replace","Y"); + root.addAttribute("receiver",receiver); + root.addAttribute("replace",replace); root.addAttribute("roottag",""); - root.addAttribute("sender","001"); + root.addAttribute("sender",sender); // 获取批次号 String batch = SerialNumberUtil.getVoucherPCNumber(Sqlca); // 遍历结果集 for (Map map : rs) { contract_number=(map.get("CONTRACT_NUMBER")==null)?"":map.get("CONTRACT_NUMBER"); - contract_name=(map.get("PRODUCT_NAME")==null)?"":map.get("PRODUCT_NAME"); - ID=(map.get("ID")==null)?"":map.get("ID"); Element bill = root.addElement("bill"); uuid=UUID.randomUUID().toString().replace("-", ""); bill.addAttribute("id", uuid); Element billhead = bill.addElement("billhead"); Element pk_defdoclist = billhead.addElement("pk_defdoclist");// 自定义档案列表主键,最大长度为20,类型为:String - pk_defdoclist.setText(ID); + pk_defdoclist.setText("ct01"); Element pk_defdoc = billhead.addElement("pk_defdoc");// pk_defdoc.setText(""); - Element pk_group = billhead.addElement("pk_group");// 所属集团,最大长度为20,类型为:String - pk_group.setText("06"); - Element pk_org = billhead.addElement("pk_org");// 所属组织,最大长度为20,类型为:String - pk_org.setText("807001002001"); + Element pk_group1 = billhead.addElement("pk_group");// 所属集团,最大长度为20,类型为:String + pk_group1.setText(pk_group); + Element pk_org1 = billhead.addElement("pk_org");// 所属组织,最大长度为20,类型为:String + pk_org1.setText(pk_org); Element code = billhead.addElement("code");// 档案编码,最大长度为40,类型为:String code.setText(contract_number); Element name = billhead.addElement("name");// 档案名称,最大长度为200,类型为:String - name.setText((contract_name==null)?"":contract_name); + name.setText(contract_number); Element shortname = billhead.addElement("shortname");// 简称,最大长度为200,类型为:String - shortname.setText(contract_name); + shortname.setText(""); Element mnecode = billhead.addElement("mnecode");// 助记码,最大长度为50,类型为:String mnecode.setText(""); Element pid = billhead.addElement("pid");// 上级档案,最大长度为20,类型为:String @@ -157,43 +192,34 @@ public class VoucherToNCforAssistContract implements Job{ /** * 像NC传输xml, 获取NC回执xml信息, 根据回执信息更改状态 */ - public static String 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) throws Exception { String updateSql = ""; // 更新sql对象 String insertSql = ""; // 新增SQL对象 - String deleteSql = ""; // 删除SQL对象 String resultcode= ""; // 单条返回结果 String bdocid = ""; // xml回执id String resultdescription=""; //错误信息 - String returns="true"; - /** * 获取对方post连接 */ - //String url = "http://47.93.227.86:8858/service/XChangeServlet?account=q0225&groupcode=001"; String url = "http://172.16.0.88:9990/service/XChangeServlet?account=bq1217&groupcode=06"; URL realURL = new URL(url); HttpURLConnection connection = (HttpURLConnection)realURL.openConnection(); connection.setDoOutput(true); connection.setRequestProperty("Content-type", "text/xml"); connection.setRequestMethod("POST"); - /** * 读取本方生成的xml, 传输到NC */ File file = new File(inputURL); BufferedOutputStream out = new BufferedOutputStream(connection.getOutputStream()); - BufferedReader reader = new BufferedReader (new InputStreamReader(new FileInputStream(file),"UTF-8")); - String xml=""; - String ss=null; - while((ss=reader.readLine()) != null) { - xml+=ss; - xml+="\r\n"; - out.write(ss.getBytes()); + BufferedInputStream input = new BufferedInputStream(new FileInputStream(file)); + int length; + byte[] buffer = new byte[1000]; + while ((length = input.read(buffer, 0, 1000)) != -1) { + out.write(buffer, 0, length); } - System.out.println(xml); - reader.close(); + input.close(); out.close(); - /** * 获取NC回执信息 */ @@ -208,13 +234,6 @@ public class VoucherToNCforAssistContract implements Job{ } System.out.println(xmlString); bufreader.close(); -/* int c; - while ((c = bufreader.read()) != -1) { - System.out.print((char) c); - xmlString += (char) c; - }*/ - //input.close(); - System.out.println("--------------------------" + xmlString); /** * 将获取到的回执信息生成本地xml */ @@ -226,83 +245,71 @@ public class VoucherToNCforAssistContract implements Job{ //设置文档的换行与缩进 transformer.setOutputProperty(OutputKeys.INDENT, "YES"); - // 将回执信息输出到本地 + // 文件拼接名称 SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmss"); - SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 年月日时分秒 - // File file2 = new File("D:\\VOUCHER_RECEIPT"); - // if (!file2.exists()) {file2.mkdirs();}// 判断是否存在, 如果不存在就创建该文件夹 + // 表数据记录日期 + 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); /** * 解析xml, 根据回执信息更新状态 */ - SAXReader sr = new SAXReader(); Document doc = sr.read(resFile); Element root= doc.getRootElement(); - //获取根元素,得到导入用友是否成功successful的值,值为Y:成功 N:失败 + // 根据successful判断是否有失败的, 有则为N, 全部成功为Y String resSuc = root.attributeValue("successful"); - //后面对回执结果做判断,然后改变导入状态就行了 if(null != resSuc){ + // 状态为N说明本批次传输有失败的 if("N".equals(resSuc)){ - logger.info("导入失败"); - // 导入失败, 将本次在明细表中存储的数据删除 - deleteSql = "DELETE FROM NCXML_DETAIL_RECORDS WHERE BATCH='"+batch+"' AND XML_TYPE = '"+type+"'"; - // 导入失败, 将失败数据记录入总记录表 + // 失败记录数 + int failed_count=0; List list = root.elements(); + // 遍历list, 获取所有回执信息 + System.out.println(list.size()); for (Element element : list) { String names = element.getName(); String value = element.getStringValue(); + // 获取单条回执信息的详细信息 List list2 = element.elements(); for (Element el : list2) { + // 获取标签名 String s = el.getName(); + // xml回执id + if("bdocid".equals(s)) { + bdocid = el.getStringValue(); + } + // 回执状态: 1=成功, <>1 =失败 if("resultcode".equals(s)) { resultcode = el.getStringValue(); } + // 回执信息 if("resultdescription".equals(s)) { resultdescription = el.getStringValue(); } } - 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+"','"+resultdescription+"','"+formatter2.format(new Date())+"')"; + // 判断, 若失败, 更新错误录入明细表 + 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++; + } } - Sqlca.executeSQL(deleteSql); + 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); - returns="false"; + logger.info("本批次包含失败数据 !"); + // 状态为Y表示, 本次导入全部成功 }else if(resSuc.equals("Y")){ logger.info("导入成功"); - List list = root.elements(); - int failed_count=0; // 失败记录数 - for (Element element : list) { - List list2 = element.elements(); - for (Element el : list2) { - String s = el.getName(); - // 获取单条回执状态 - if("resultcode".equals(s)) { - resultcode = el.getStringValue(); - } - // xml回执id - if("bdocid".equals(s)) { - bdocid = el.getStringValue(); - } - // 错误信息 - if("resultdescription".equals(s)) { - resultdescription = el.getStringValue(); - } - } - - if(!"1".equals(resultcode)) { - // 如果回执状态不等于1, 说明有误, 更新到记录字表并记录错误信息 - updateSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='"+resultcode+"',ERR_DESCRIBE='"+resultdescription+"' WHERE BUILLID='"+bdocid+"' AND XML_TYPE= '"+type+"'"; - Sqlca.executeSQL(updateSql); - logger.info("根据回执信息, 修改传输失败状态, 记录错误信息"+updateSql); - failed_count++; - } - } - // 将本批次传输总量及 失败数量记录入记录总表 - 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+"','"+failed_count+"','"+resultdescription+"','"+formatter2.format(new Date())+"')"; + // 将本次导入信息记录入记录总表 + 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); }else{ logger.info("出现未知错误"); @@ -310,6 +317,5 @@ public class VoucherToNCforAssistContract implements Job{ }else{ logger.info("未找到successful属性"); } - return returns; } } diff --git a/src_core/com/tenwa/voucher/serviceImp/VoucherToNCforCustomer.java b/src_core/com/tenwa/voucher/serviceImp/VoucherToNCforCustomer.java index 7d82e28f8..fea1a230f 100644 --- a/src_core/com/tenwa/voucher/serviceImp/VoucherToNCforCustomer.java +++ b/src_core/com/tenwa/voucher/serviceImp/VoucherToNCforCustomer.java @@ -14,6 +14,7 @@ import java.text.SimpleDateFormat; 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; @@ -50,45 +51,96 @@ public class VoucherToNCforCustomer implements Job{ * @throws Exception */ public void execute(JobExecutionContext arg0) throws JobExecutionException { + // 获取时间 String plan_date = DateAssistant.getToday(); + // 获取用户 Object userId = arg0.getTrigger().getJobDataMap().get("CurUserId"); String curUserId = userId == null? "system" : userId.toString(); + // 定义事物 JBOTransaction tx=null; Transaction Sqlca = null; + // 获取配置文件的输入流 + FileInputStream in =null; try { tx= JBOFactory.createJBOTransaction(); Sqlca = Transaction.createTransaction(tx); - File file=null; // 定义文件对象 - XMLWriter writer=null; // 定义输出对象 - String type="customer"; // 定义xml类型对象 - String insertSql=""; // 定义新增语句对象 - String uuid=""; // 定义xml传输id对象 - String customer_num=""; // 定义客户编号对象 - String customername=""; // 定义客户名称对象 - String customertype=""; // 定义客户类型对象 - // 获取特定格式日期 + /** + * 读取配置文件信息 + */ + // 创建Properties对象 + Properties properties = new Properties(); + // 获取配置文件输入流 + in = new FileInputStream("/vouchers.properties"); + // 通过Properties对象读取配置文件 + properties.load(in); + // 获取配置文件数据 + // 账套 + String account = properties.getProperty("customer_account"); + // 单据类型 + String billtype = properties.getProperty("customer_billtype"); + // 集团编码 + String groupcode = properties.getProperty("customer_groupcode"); + // 系统参数 + String isexchange = properties.getProperty("customer_isexchange"); + // 接收方 + String receiver = properties.getProperty("customer_receiver"); + // 外系统编码 + String sender = properties.getProperty("customer_sender"); + // 系统参数 + String replace = properties.getProperty("customer_replace"); + // 所属组织 + String pk_org = properties.getProperty("customer_pk_org"); + // 所属集团 + String pk_group = properties.getProperty("customer_pk_group"); + // 客户基本分类 + String pk_custclass = properties.getProperty("customer_pk_custclass"); + // 国家地区 + String pk_country = properties.getProperty("customer_pk_country"); + // 时区 + String pk_timezone = properties.getProperty("customer_pk_timezone"); + // 数据格式 + String pk_format = properties.getProperty("customer_pk_format"); + + // 定义文件对象 + File file=null; + // 定义Document对象 + Document document=null; + // 定义输出对象 + XMLWriter writer=null; + // 定义xml类型对象 + String type="customer"; + // 定义新增语句对象 + String insertSql=""; + // 定义xml传输id对象 + String uuid=""; + // 定义客户编号对象 + String customer_num=""; + // 定义客户名称对象 + 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 customer_num,customername,customertype,customerid FROM CUSTOMER_INFO WHERE customer_num NOT IN(SELECT TABLE_NUM FROM NCXML_DETAIL_RECORDS WHERE FLAG='1' AND XML_TYPE='"+type+"') "; + 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 "; List> rs = DataOperatorUtil.getDataBySql(Sqlca,sql,null); if(rs != null && rs.size()>0) { // 生成xml头 - Document document= DocumentHelper.createDocument(); + document= DocumentHelper.createDocument(); Element root = document.addElement("ufinterface"); - root.addAttribute("account", "bq1217"); - root.addAttribute("billtype", "customer"); + root.addAttribute("account", account); + root.addAttribute("billtype",billtype); root.addAttribute("businessunitcode", "develop"); root.addAttribute("filename", ""); - root.addAttribute("groupcode", "06"); - root.addAttribute("isexchange", "Y"); + root.addAttribute("groupcode", groupcode); + root.addAttribute("isexchange", isexchange); root.addAttribute("orgcode", ""); - root.addAttribute("receiver", "807001002001"); - root.addAttribute("replace", "Y"); + root.addAttribute("receiver", receiver); + root.addAttribute("replace", replace); root.addAttribute("roottag", ""); - root.addAttribute("sender", "kh01"); + root.addAttribute("sender", sender); String batch = SerialNumberUtil.getVoucherPCNumber(Sqlca);// 生成批次号 @@ -96,16 +148,15 @@ public class VoucherToNCforCustomer implements Job{ for(int i=0;i list = root.elements(); + // 遍历list, 获取所有回执信息 + System.out.println(list.size()); for (Element element : list) { String names = element.getName(); String value = element.getStringValue(); + // 获取单条回执信息的详细信息 List list2 = element.elements(); for (Element el : list2) { + // 获取标签名 String s = el.getName(); + // xml回执id + if("bdocid".equals(s)) { + bdocid = el.getStringValue(); + } + // 回执状态: 1=成功, <>1 =失败 if("resultcode".equals(s)) { resultcode = el.getStringValue(); } + // 回执信息 if("resultdescription".equals(s)) { resultdescription = el.getStringValue(); } } - 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+"','"+resultdescription+"','"+formatter2.format(new Date())+"')"; + // 判断, 若失败, 更新错误录入明细表 + 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++; + } } - Sqlca.executeSQL(deleteSql); + 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); - returns="false"; + logger.info("本批次包含失败数据 !"); + // 状态为Y表示, 本次导入全部成功 }else if(resSuc.equals("Y")){ logger.info("导入成功"); - List list = root.elements(); - int failed_count=0; // 失败记录数 - for (Element element : list) { - List list2 = element.elements(); - for (Element el : list2) { - String s = el.getName(); - // 获取单条回执状态 - if("resultcode".equals(s)) { - resultcode = el.getStringValue(); - } - // xml回执id - if("bdocid".equals(s)) { - bdocid = el.getStringValue(); - } - // 错误信息 - if("resultdescription".equals(s)) { - resultdescription = el.getStringValue(); - } - } - - if(!"1".equals(resultcode)) { - // 如果回执状态不等于1, 说明有误, 更新到记录字表并记录错误信息 - updateSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='"+resultcode+"',ERR_DESCRIBE='"+resultdescription+"' WHERE BUILLID='"+bdocid+"' AND XML_TYPE= '"+type+"'"; - Sqlca.executeSQL(updateSql); - logger.info("根据回执信息, 修改传输失败状态, 记录错误信息"+updateSql); - failed_count++; - } - } - // 将本批次传输总量及 失败数量记录入记录总表 - 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+"','"+failed_count+"','"+resultdescription+"','"+formatter2.format(new Date())+"')"; + // 将本次导入信息记录入记录总表 + 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); }else{ logger.info("出现未知错误"); @@ -363,6 +386,5 @@ public class VoucherToNCforCustomer implements Job{ }else{ logger.info("未找到successful属性"); } - return returns; } } \ No newline at end of file diff --git a/src_core/com/tenwa/voucher/serviceImp/VoucherToNCforDistributor.java b/src_core/com/tenwa/voucher/serviceImp/VoucherToNCforDistributor.java index c430c0ed0..7167dc7dd 100644 --- a/src_core/com/tenwa/voucher/serviceImp/VoucherToNCforDistributor.java +++ b/src_core/com/tenwa/voucher/serviceImp/VoucherToNCforDistributor.java @@ -14,6 +14,7 @@ import java.text.SimpleDateFormat; 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; @@ -54,11 +55,53 @@ public class VoucherToNCforDistributor implements Job{ String plan_date = DateAssistant.getToday(); Object userId = arg0.getTrigger().getJobDataMap().get("CurUserId"); String curUserId = userId == null? "system" : userId.toString(); + // 定义事物 JBOTransaction tx=null; Transaction Sqlca = null; + // 获取配置文件的输入流 + FileInputStream in=null; try { tx= JBOFactory.createJBOTransaction(); Sqlca = Transaction.createTransaction(tx); + /** + * 读取配置文件信息 + * */ + // 创建Properties对象 + Properties properties = new Properties(); + // 获取配置文件输入流 + in = new FileInputStream("/vouchers.properties"); + // 通过Properties对象读取配置文件 + properties.load(in); + // 获取配置文件数据 + // 账套 + String account = properties.getProperty("distributor_account"); + // 单据类型 + String billtype = properties.getProperty("distributor_billtype"); + // 集团编码 + String groupcode = properties.getProperty("distributor_groupcode"); + // 系统参数 + String isexchange = properties.getProperty("distributor_isexchange"); + // 接收方 + String receiver = properties.getProperty("distributor_receiver"); + // 外系统编码 + String sender = properties.getProperty("distributor_sender"); + // 系统参数 + String replace = properties.getProperty("distributor_replace"); + // 所属组织 + String pk_org = properties.getProperty("distributor_pk_org"); + // 所属集团 + String pk_group = properties.getProperty("distributor_pk_group"); + // 供应商基本分类 + String pk_supplierclass = properties.getProperty("distributor_pk_supplierclass"); + // 国家地区 + String pk_country = properties.getProperty("distributor_pk_country"); + // 时区 + String pk_timezone = properties.getProperty("distributor_pk_timezone"); + // 账数据格式 + String pk_format = properties.getProperty("distributor_pk_format"); + + + File file = null; // 文件对象 XMLWriter writer = null; // 输出对象 String type="distributor"; // xml类别 @@ -94,15 +137,15 @@ public class VoucherToNCforDistributor implements Job{ // 设置xml标签头 Document document = DocumentHelper.createDocument(); Element root = document.addElement("ufinterface"); - root.addAttribute("account", "bq1217"); - root.addAttribute("billtype", "supplier"); + root.addAttribute("account",account); + root.addAttribute("billtype",billtype); root.addAttribute("filename", ""); - root.addAttribute("groupcode", "06"); - root.addAttribute("isexchange", "Y"); - root.addAttribute("receiver", "807001002001"); - root.addAttribute("replace", "Y"); + root.addAttribute("groupcode", groupcode); + root.addAttribute("isexchange",isexchange); + root.addAttribute("receiver", receiver); + root.addAttribute("replace", replace); root.addAttribute("roottag", ""); - root.addAttribute("sender", "gys01"); + root.addAttribute("sender",sender); // 获取批次号 String batch = SerialNumberUtil.getVoucherPCNumber(Sqlca); @@ -132,10 +175,10 @@ public class VoucherToNCforDistributor implements Job{ uuid=UUID.randomUUID().toString().replace("-", ""); bill.addAttribute("id",uuid); Element billhead = bill.addElement("billhead"); - Element pk_group = billhead.addElement("pk_group"); // 所属集团,最大长度为20,类型为:String - pk_group.setText("06"); - Element pk_org = billhead.addElement("pk_org"); // 所属组织,最大长度为20,类型为:String - pk_org.setText("807001002001"); + Element pk_group1 = billhead.addElement("pk_group"); // 所属集团,最大长度为20,类型为:String + pk_group1.setText(pk_group); + Element pk_org1 = billhead.addElement("pk_org"); // 所属组织,最大长度为20,类型为:String + pk_org1.setText(pk_org); Element code = billhead.addElement("code"); // 供应商编号,最大长度为40,类型为:String code.setText((DISTRIBUTOR_CODING==null)?"":DISTRIBUTOR_CODING); Element name = billhead.addElement("name"); // 供应商名称,最大长度为200,类型为:String @@ -150,14 +193,15 @@ public class VoucherToNCforDistributor implements Job{ Element trade = billhead.addElement("trade"); // 所属行业,最大长度为20,类型为:String trade.setText((BUSINESS_SCOPE==null)?"":BUSINESS_SCOPE); Element pk_supplier_main = billhead.addElement("pk_supplier_main"); // 上级供应商,最大长度为20,类型为:String - pk_supplier_main.setText((SUBSIDIARY_COMPANY==null)?"":SUBSIDIARY_COMPANY); - Element supprop = billhead.addElement("supprop"); // 供应商类型,最大长度为1,类型为:Integer - supprop.setText("外部单位"); + // pk_supplier_main.setText((SUBSIDIARY_COMPANY==null)?"":SUBSIDIARY_COMPANY); + pk_supplier_main.setText(""); + Element supprop1 = billhead.addElement("supprop"); // 供应商类型,最大长度为1,类型为:Integer + supprop1.setText("外部单位"); Element pk_areacl = billhead.addElement("pk_areacl"); // 地区分类,最大长度为20,类型为:String - pk_areacl.setText((region==null)?"":region); - Element pk_supplierclass = billhead.addElement("pk_supplierclass"); // 供应商基本分类,最大长度为20,类型为:String + pk_areacl.setText(""); + Element pk_supplierclass1 = billhead.addElement("pk_supplierclass"); // 供应商基本分类,最大长度为20,类型为:String //pk_supplierclass.setText((TYPE==null)?"":TYPE); - pk_supplierclass.setText("0201"); + pk_supplierclass1.setText(pk_supplierclass); Element iscustomer = billhead.addElement("iscustomer"); // 客户,最大长度为1,类型为:UFBoolean iscustomer.setText(""); Element corcustomer = billhead.addElement("corcustomer"); // 对应客户,最大长度为20,类型为:String @@ -188,9 +232,9 @@ public class VoucherToNCforDistributor implements Job{ Element item1 = suplinkman.addElement("item"); // 编码,最大长度为64,类型为:String Element linkmanvo = item1.addElement("linkmanvo"); Element code2 = linkmanvo.addElement("code"); // 编码,最大长度为64,类型为:String - code2.setText((DISTRIBUTOR_CODING==null)?"":DISTRIBUTOR_CODING); + code2.setText(""); Element name2 = linkmanvo.addElement("name"); // 名称,最大长度为64,类型为:String - name2.setText((DISTRIBUTOR_NAME==null)?"":DISTRIBUTOR_NAME); + name2.setText(""); Element sex = linkmanvo.addElement("sex"); // 性别,最大长度为64,类型为:Integer sex.setText(""); Element vjob2 = linkmanvo.addElement("vjob"); // 职位,最大长度为64,类型为:String @@ -217,10 +261,6 @@ public class VoucherToNCforDistributor implements Job{ pk_linkman.setText(""); Element isdefault = item1.addElement("isdefault"); // 是否默认,最大长度为1,类型为:UFBoolean isdefault.setText(""); - - - - Element tel1 = billhead.addElement("tel1"); // 电话1,最大长度为50,类型为:String tel1.setText(""); Element tel2 = billhead.addElement("tel2"); // 电话2,最大长度为50,类型为:String @@ -233,31 +273,32 @@ public class VoucherToNCforDistributor implements Job{ fax2.setText(""); Element email2 = billhead.addElement("email"); // e-mail地址,最大长度为50,类型为:String email2.setText((E_MAIL==null)?"":E_MAIL); - Element pk_country = billhead.addElement("pk_country"); // 国家/地区,最大长度为20,类型为:String - pk_country.setText("CN"); - Element pk_timezone = billhead.addElement("pk_timezone"); // 时区,最大长度为20,类型为:String - pk_timezone.setText("P0800"); - Element pk_format = billhead.addElement("pk_format"); // 数据格式,最大长度为20,类型为:String - pk_format.setText("ZH-CN"); + Element pk_country1 = billhead.addElement("pk_country"); // 国家/地区,最大长度为20,类型为:String + pk_country1.setText(pk_country); + Element pk_timezone1 = billhead.addElement("pk_timezone"); // 时区,最大长度为20,类型为:String + pk_timezone1.setText(pk_timezone); + Element pk_format1 = billhead.addElement("pk_format"); // 数据格式,最大长度为20,类型为:String + pk_format1.setText(pk_format); Element enablestate = billhead.addElement("enablestate"); // 启用状态,最大长度为0,类型为:Integer - enablestate.setText((DISTRIBUTOR_STATUS==null)?"":DISTRIBUTOR_STATUS); - Element aaa = billhead.addElement("企业地址"); + // enablestate.setText((DISTRIBUTOR_STATUS==null)?"":DISTRIBUTOR_STATUS); + enablestate.setText("2"); + /*Element aaa = billhead.addElement("企业地址"); Element code3 = aaa.addElement("code"); // 编码,最大长度为64,类型为:String - code3.setText((BUSINESS_LICENSE_NO==null)?"":BUSINESS_LICENSE_NO); + code3.setText(""); Element country = aaa.addElement("country"); // 国家,最大长度为64,类型为:String - country.setText(""); + country.setText("CN"); Element detailinfo = aaa.addElement("detailinfo"); // 详细地址,最大长度为64,类型为:String - detailinfo.setText((REGISTERED_ADDR==null)?"":REGISTERED_ADDR); + detailinfo.setText(""); Element postcode3 = aaa.addElement("postcode"); // 邮编,最大长度为64,类型为:String - postcode3.setText((POSTCODE==null)?"":POSTCODE); + postcode3.setText(""); Element province = aaa.addElement("province"); // 省份,最大长度为64,类型为:String - province.setText((PROVINCES==null)?"":PROVINCES); + province.setText(""); Element status = aaa.addElement("status"); // status,最大长度为64,类型为:Integer status.setText("0"); Element vsection = aaa.addElement("vsection"); // 区县,最大长度为64,类型为:String - vsection.setText((region==null)?"":region); + vsection.setText(""); Element corpaddress = billhead.addElement("corpaddress"); // 企业地址主键,最大长度为20,类型为:String - corpaddress.setText((FACT_ADDR==null)?"":FACT_ADDR); + 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+"')"; @@ -299,43 +340,34 @@ public class VoucherToNCforDistributor implements Job{ /** * 像NC传输xml, 获取NC回执xml信息, 根据回执信息更改状态 */ - public static String 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) throws Exception { String updateSql = ""; // 更新sql对象 String insertSql = ""; // 新增SQL对象 - String deleteSql = ""; // 删除SQL对象 String resultcode= ""; // 单条返回结果 String bdocid = ""; // xml回执id String resultdescription=""; //错误信息 - String returns="true"; - /** * 获取对方post连接 */ - //String url = "http://47.93.227.86:8858/service/XChangeServlet?account=q0225&groupcode=001"; String url = "http://172.16.0.88:9990/service/XChangeServlet?account=bq1217&groupcode=06"; URL realURL = new URL(url); HttpURLConnection connection = (HttpURLConnection)realURL.openConnection(); connection.setDoOutput(true); connection.setRequestProperty("Content-type", "text/xml"); connection.setRequestMethod("POST"); - /** * 读取本方生成的xml, 传输到NC */ File file = new File(inputURL); BufferedOutputStream out = new BufferedOutputStream(connection.getOutputStream()); - BufferedReader reader = new BufferedReader (new InputStreamReader(new FileInputStream(file),"UTF-8")); - String xml=""; - String ss=null; - while((ss=reader.readLine()) != null) { - xml+=ss; - xml+="\r\n"; - out.write(ss.getBytes()); + BufferedInputStream input = new BufferedInputStream(new FileInputStream(file)); + int length; + byte[] buffer = new byte[1000]; + while ((length = input.read(buffer, 0, 1000)) != -1) { + out.write(buffer, 0, length); } - System.out.println(xml); - reader.close(); + input.close(); out.close(); - /** * 获取NC回执信息 */ @@ -350,13 +382,6 @@ public class VoucherToNCforDistributor implements Job{ } System.out.println(xmlString); bufreader.close(); -/* int c; - while ((c = bufreader.read()) != -1) { - System.out.print((char) c); - xmlString += (char) c; - }*/ - //input.close(); - System.out.println("--------------------------" + xmlString); /** * 将获取到的回执信息生成本地xml */ @@ -368,83 +393,71 @@ public class VoucherToNCforDistributor implements Job{ //设置文档的换行与缩进 transformer.setOutputProperty(OutputKeys.INDENT, "YES"); - // 将回执信息输出到本地 + // 文件拼接名称 SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmss"); - SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 年月日时分秒 - // File file2 = new File("D:\\VOUCHER_RECEIPT"); - // if (!file2.exists()) {file2.mkdirs();}// 判断是否存在, 如果不存在就创建该文件夹 + // 表数据记录日期 + 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); /** * 解析xml, 根据回执信息更新状态 */ - SAXReader sr = new SAXReader(); Document doc = sr.read(resFile); Element root= doc.getRootElement(); - //获取根元素,得到导入用友是否成功successful的值,值为Y:成功 N:失败 + // 根据successful判断是否有失败的, 有则为N, 全部成功为Y String resSuc = root.attributeValue("successful"); - //后面对回执结果做判断,然后改变导入状态就行了 if(null != resSuc){ + // 状态为N说明本批次传输有失败的 if("N".equals(resSuc)){ - logger.info("导入失败"); - // 导入失败, 将本次在明细表中存储的数据删除 - deleteSql = "DELETE FROM NCXML_DETAIL_RECORDS WHERE BATCH='"+batch+"' AND XML_TYPE = '"+type+"'"; - // 导入失败, 将失败数据记录入总记录表 + // 失败记录数 + int failed_count=0; List list = root.elements(); + // 遍历list, 获取所有回执信息 + System.out.println(list.size()); for (Element element : list) { String names = element.getName(); String value = element.getStringValue(); + // 获取单条回执信息的详细信息 List list2 = element.elements(); for (Element el : list2) { + // 获取标签名 String s = el.getName(); + // xml回执id + if("bdocid".equals(s)) { + bdocid = el.getStringValue(); + } + // 回执状态: 1=成功, <>1 =失败 if("resultcode".equals(s)) { resultcode = el.getStringValue(); } + // 回执信息 if("resultdescription".equals(s)) { resultdescription = el.getStringValue(); } } - 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+"','"+resultdescription+"','"+formatter2.format(new Date())+"')"; + // 判断, 若失败, 更新错误录入明细表 + 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++; + } } - Sqlca.executeSQL(deleteSql); + 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); - returns="false"; + logger.info("本批次包含失败数据 !"); + // 状态为Y表示, 本次导入全部成功 }else if(resSuc.equals("Y")){ logger.info("导入成功"); - List list = root.elements(); - int failed_count=0; // 失败记录数 - for (Element element : list) { - List list2 = element.elements(); - for (Element el : list2) { - String s = el.getName(); - // 获取单条回执状态 - if("resultcode".equals(s)) { - resultcode = el.getStringValue(); - } - // xml回执id - if("bdocid".equals(s)) { - bdocid = el.getStringValue(); - } - // 错误信息 - if("resultdescription".equals(s)) { - resultdescription = el.getStringValue(); - } - } - - if(!"1".equals(resultcode)) { - // 如果回执状态不等于1, 说明有误, 更新到记录字表并记录错误信息 - updateSql=" UPDATE NCXML_DETAIL_RECORDS SET FLAG='"+resultcode+"',ERR_DESCRIBE='"+resultdescription+"' WHERE BUILLID='"+bdocid+"' AND XML_TYPE= '"+type+"'"; - Sqlca.executeSQL(updateSql); - logger.info("根据回执信息, 修改传输失败状态, 记录错误信息"+updateSql); - failed_count++; - } - } - // 将本批次传输总量及 失败数量记录入记录总表 - 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+"','"+failed_count+"','"+resultdescription+"','"+formatter2.format(new Date())+"')"; + // 将本次导入信息记录入记录总表 + 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); }else{ logger.info("出现未知错误"); @@ -452,6 +465,5 @@ public class VoucherToNCforDistributor implements Job{ }else{ logger.info("未找到successful属性"); } - return returns; } }