add oa 接口
This commit is contained in:
parent
cf75f0bd76
commit
cbe37efac5
|
@ -1,98 +0,0 @@
|
|||
package shkd.fi.fi.oa;
|
||||
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
|
||||
public class OAInvoiceImpl {
|
||||
|
||||
public static String getSynData(DynamicObject inovice,String soaAccountNumber){
|
||||
|
||||
StringBuffer xml = new StringBuffer();
|
||||
xml.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:mod=\"http://localhost/services/ModeDateService\">");
|
||||
xml.append("<soapenv:Header/>");
|
||||
xml.append("<soapenv:Body>");
|
||||
xml.append("<mod:saveModeData>");
|
||||
xml.append("<mod:in0>");
|
||||
xml.append(" <![CDATA[");
|
||||
xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||
xml.append("<ROOT><header><userid>1</userid><modeid>3281</modeid><id></id></header>");
|
||||
xml.append("<search><condition /><right>Y</right></search>");
|
||||
xml.append("<data id=\"\">");
|
||||
xml.append("<maintable>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>fphm</filedname>");
|
||||
xml.append("<filedvalue>").append(inovice.getString("")).append("</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>kpdw</filedname>");
|
||||
xml.append("<filedvalue>上海亿升海运仓储有限公司</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>fpnr</filedname>");
|
||||
xml.append("<filedvalue>发票内容测试</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>fpze</filedname>");
|
||||
xml.append("<filedvalue>119.36</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>fplx</filedname>");
|
||||
xml.append("<filedvalue>0</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>kprq</filedname>");
|
||||
xml.append("<filedvalue>2024-07-02</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>zt</filedname>");
|
||||
xml.append("<filedvalue>1</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>bhsje</filedname>");
|
||||
xml.append("<filedvalue>115.88</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>se</filedname>");
|
||||
xml.append("<filedvalue>3.48</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>shje</filedname>");
|
||||
xml.append("<filedvalue>200</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>sl</filedname>");
|
||||
xml.append("<filedvalue>0.13</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>sfyf</filedname>");
|
||||
xml.append("<filedvalue>1</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>fpsfdw</filedname>");
|
||||
xml.append("<filedvalue>5621</filedvalue>");
|
||||
xml.append("</field>");
|
||||
// xml.append("<field>");
|
||||
// xml.append("<filedname>yfje</filedname>");
|
||||
// xml.append("<filedvalue>0</filedvalue>");
|
||||
// xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>sapkm</filedname>");
|
||||
xml.append("<filedvalue>").append(soaAccountNumber).append("</filedvalue>");
|
||||
xml.append("</field>");
|
||||
// xml.append("<field>");
|
||||
// xml.append("<filedname>cbzx</filedname>");
|
||||
// xml.append("<filedvalue>\"\"</filedvalue>");
|
||||
// xml.append("</field>");
|
||||
xml.append("</maintable>");
|
||||
xml.append("</data>");
|
||||
xml.append("</ROOT>");
|
||||
xml.append("]]>");
|
||||
|
||||
|
||||
xml.append("</mod:in0>");
|
||||
xml.append("</mod:saveModeData>");
|
||||
xml.append("</soapenv:Body>");
|
||||
xml.append("</soapenv:Envelope>");
|
||||
|
||||
return xml.toString();
|
||||
}
|
||||
}
|
|
@ -870,7 +870,7 @@ public class DzpzkOPPlugin extends AbstractOperationServicePlugIn {
|
|||
* @param billId 当前单据ID
|
||||
* @return 下游单据id集合
|
||||
*/
|
||||
private static List<Long> down(String entity,Long billId) {
|
||||
public static List<Long> down(String entity,Long billId) {
|
||||
List<Long> idList = new ArrayList<Long>();
|
||||
Map<Long, List<BFRow>> dirtSourceBillMap = BFTrackerServiceHelper.findDirtTargetBills(entity, new Long[]{billId});
|
||||
List<BFRow> bfRows = dirtSourceBillMap.get(billId);
|
||||
|
|
|
@ -2,24 +2,20 @@ package shkd.fi.fi.opplugin;
|
|||
|
||||
import com.alibaba.druid.support.logging.Log;
|
||||
import com.alibaba.druid.support.logging.LogFactory;
|
||||
import com.sap.db.jdbc.packet.ErrorLevel;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.entity.operate.result.OperateErrorInfo;
|
||||
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
||||
import kd.bos.entity.plugin.args.AfterOperationArgs;
|
||||
import kd.bos.orm.query.QCP;
|
||||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||
import kd.bos.util.StringUtils;
|
||||
import shkd.fi.fi.common.AppflgConstant;
|
||||
import shkd.fi.fi.oa.OAInvoiceImpl;
|
||||
import shkd.fi.fi.sap.result.docuentif.cxdocuentif.MT_CXDOCUMENT_IF_RET;
|
||||
import shkd.fi.fi.util.DateUtils;
|
||||
import shkd.fi.fi.util.HttpUtils;
|
||||
import shkd.fi.fi.util.LogBillUtils;
|
||||
import shkd.fi.fi.util.XmlUtils;
|
||||
import shkd.fi.fi.util.ParamsUtils;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
|
@ -27,17 +23,21 @@ import java.util.*;
|
|||
*/
|
||||
public class SynOAInvoiceOPPlugin extends AbstractOperationServicePlugIn {
|
||||
private static final Log log = LogFactory.getLog(SynOAInvoiceOPPlugin.class);
|
||||
/**
|
||||
* 采购入库单
|
||||
*/
|
||||
private static final String im_purinbill="im_purinbill";
|
||||
/**
|
||||
* 财务应付单
|
||||
*/
|
||||
private static final String ap_finapbill="ap_finapbill";
|
||||
@Override
|
||||
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
|
||||
super.afterExecuteOperationTransaction(e);
|
||||
String operationKey = e.getOperationKey();
|
||||
switch (operationKey){
|
||||
case "cx_sap_voucher"://冲销SAP凭证
|
||||
//冲销SAP凭证
|
||||
cxSapVoucher(e);
|
||||
//组装参数
|
||||
//记录返回接口到凭证
|
||||
//记录接口日志
|
||||
case "oa_inv"://冲销SAP凭证
|
||||
oa_inv(e);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -45,7 +45,7 @@ public class SynOAInvoiceOPPlugin extends AbstractOperationServicePlugIn {
|
|||
|
||||
}
|
||||
|
||||
public void cxSapVoucher(AfterOperationArgs e){
|
||||
public void oa_inv(AfterOperationArgs e){
|
||||
//1.校验,不满足冲销条件的凭证,移除,不传输,校验是否满足冲销条件:必须是已同步过SAP的凭证才允许冲销
|
||||
DynamicObjectCollection voucherColl = new DynamicObjectCollection();
|
||||
StringBuffer errStr = new StringBuffer();
|
||||
|
@ -83,10 +83,8 @@ public class SynOAInvoiceOPPlugin extends AbstractOperationServicePlugIn {
|
|||
|
||||
//校验通过,进行冲销
|
||||
//2.组装转换参数
|
||||
String spa_user_pass = System.getProperty(AppflgConstant.SAP_USER_PASS);
|
||||
byte[] token = Base64.getEncoder().encode(spa_user_pass.getBytes());
|
||||
String tokenStr = new String(token);
|
||||
String sap_cx_voucher_url = System.getProperty(AppflgConstant.SAP_CX_VOUCHER_URL);
|
||||
Map<String, String> paramsMap = ParamsUtils.getParamsMap();
|
||||
String oaurl = AppflgConstant.OA_INV_URL(paramsMap);
|
||||
|
||||
String crdate = DateUtils.formatDate(new Date(),DateUtils.COMPACT_TIME);
|
||||
Random random = new Random();
|
||||
|
@ -94,109 +92,163 @@ public class SynOAInvoiceOPPlugin extends AbstractOperationServicePlugIn {
|
|||
String time_random = crdate+""+ randomNumber;
|
||||
for (DynamicObject gl_voucher : voucherColl) {
|
||||
DynamicObject org = gl_voucher.getDynamicObject("org");
|
||||
String shkd_sap_number = org.getString("shkd_sap_number");
|
||||
DynamicObject creator = gl_voucher.getDynamicObject("creator");
|
||||
String packgId = System.getProperty(AppflgConstant.SYS_NUMBER)+time_random;
|
||||
String shkd_oa_orgid = org.getString("shkd_oa_orgid");
|
||||
String shkd_belnr = gl_voucher.getString("shkd_belnr");//sap凭证号
|
||||
|
||||
String billno = gl_voucher.getString("billno");
|
||||
String shkd_belnr = gl_voucher.getString("shkd_belnr");
|
||||
Date bookeddate = gl_voucher.getDate("bookeddate");
|
||||
String zbudat = DateUtils.format(bookeddate, DateUtils.COMPACT_DATE);//冲销日期
|
||||
String xml = OAInvoiceImpl.getSynData(gl_voucher, "");
|
||||
//DAP关系
|
||||
QFilter filter = new QFilter("voucherid", QCP.equals,gl_voucher.getPkValue());
|
||||
List<String> billTypeList = new ArrayList<String>();
|
||||
billTypeList.add(im_purinbill);
|
||||
billTypeList.add(ap_finapbill);
|
||||
QFilter filter2 = new QFilter("billtype.number",QCP.in,billTypeList);
|
||||
DynamicObject[] ai_daptrackers = BusinessDataServiceHelper.load("ai_daptracker", "id,billtype.number,voucherid,sourcebillid", new QFilter[]{filter.and(filter2)});
|
||||
|
||||
try {
|
||||
Map<String, Object> result = HttpUtils.sendPostToSAP(sap_cx_voucher_url, "tokenStr", xml);
|
||||
String responseStr = "";
|
||||
if (null != result) {
|
||||
String status = String.valueOf(result.get(HttpUtils.STATUS));
|
||||
responseStr = String.valueOf(result.get(HttpUtils.RESPONSE_STRING));
|
||||
log.info(status);
|
||||
log.info(responseStr);
|
||||
//4.处理接口返回结果:解析记录结果到凭证上,
|
||||
if (status.equals("200")) {//成功
|
||||
MT_CXDOCUMENT_IF_RET mtDocumentIFRet = XmlUtils.xmlToObject(MT_CXDOCUMENT_IF_RET.class, responseStr, XmlUtils.START_SUB_STR, XmlUtils.END_SUB_STR);
|
||||
if (null != mtDocumentIFRet && null != mtDocumentIFRet.getData()
|
||||
&& null != mtDocumentIFRet.getData().getOtRetn()
|
||||
&& null != mtDocumentIFRet.getData().getOtRetn().getItemList()) {
|
||||
List<MT_CXDOCUMENT_IF_RET.ITEM> itemList = mtDocumentIFRet.getData().getOtRetn().getItemList();
|
||||
for (int i = 0; i < itemList.size(); i++) {
|
||||
MT_CXDOCUMENT_IF_RET.ITEM item = itemList.get(i);
|
||||
String zstatus1 = item.getZstatus();
|
||||
if ("S".equals(zstatus1.toUpperCase())) {//成功
|
||||
//成功提示
|
||||
this.operationResult.setShowMessage(true);
|
||||
this.operationResult.setSuccess(true);
|
||||
this.operationResult.setMessage("同步成功");
|
||||
|
||||
} else {//失败
|
||||
//失败提示
|
||||
this.operationResult.setShowMessage(true);
|
||||
this.operationResult.setSuccess(false);
|
||||
this.operationResult.setMessage("同步失败:" + item.getPromsg());
|
||||
}
|
||||
//更新凭证上接口返回字段
|
||||
updateVoucher(gl_voucher, item);
|
||||
|
||||
}
|
||||
}
|
||||
} else {//失败
|
||||
//更新凭证上接口返回字段
|
||||
this.operationResult.setShowMessage(true);
|
||||
this.operationResult.setSuccess(false);
|
||||
this.operationResult.setMessage("同步失败:" + responseStr);
|
||||
}
|
||||
//5.记录到接口日志表
|
||||
LogBillUtils.SaveLogBill(sap_cx_voucher_url, responseStr, AppflgConstant.SAP_CX_VOUCHER_URL_NAME, xml.toString());
|
||||
for (int i = 0; i < ai_daptrackers.length; i++) {
|
||||
DynamicObject ai_daptracker = ai_daptrackers[i];
|
||||
DynamicObject billtype = ai_daptracker.getDynamicObject("billtype");
|
||||
String number = billtype.getString("number");
|
||||
DynamicObject dynamicObject = BusinessDataServiceHelper.newDynamicObject(ap_finapbill);
|
||||
long sourcebillid = ai_daptracker.getLong("sourcebillid");
|
||||
if(im_purinbill.equals(number)){//来源单据是采购入库单,需查询下游单据,财务应付单
|
||||
List<Long> apBillIdList = DzpzkOPPlugin.down(im_purinbill, sourcebillid);
|
||||
DynamicObject[] ap_invoices = BusinessDataServiceHelper.load(apBillIdList.toArray(), dynamicObject.getDynamicObjectType());
|
||||
getSynData(oaurl,ap_invoices, shkd_belnr,shkd_oa_orgid,gl_voucher);
|
||||
}else if(ap_finapbill.equals(number)){//来源单据是财务应付单
|
||||
DynamicObject[] ap_invoices = BusinessDataServiceHelper.load(new Long[]{sourcebillid}, dynamicObject.getDynamicObjectType());
|
||||
getSynData(oaurl,ap_invoices, shkd_belnr,shkd_oa_orgid,gl_voucher);
|
||||
}
|
||||
}catch (JAXBException ex) {
|
||||
OperateErrorInfo operateErrorInfo = new OperateErrorInfo();
|
||||
// operateErrorInfo.setMessage(exc.getMessage());
|
||||
operateErrorInfo.setErrorLevel(ErrorLevel.Error.name());
|
||||
operateErrorInfo.setPkValue(gl_voucher.getPkValue());
|
||||
this.operationResult.addErrorInfo(operateErrorInfo);
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 item 明细项
|
||||
* @param sapOrgNum SAP组织编码
|
||||
* @param sapVoucherNo SAP凭证号
|
||||
* @param periodYear SAP会计年 YYYY
|
||||
* @param zbudat 冲销日期 yyyyMMdd
|
||||
* @return
|
||||
*/
|
||||
public String createItem(String sapOrgNum,String sapVoucherNo,String periodYear,String zbudat){
|
||||
StringBuffer item = new StringBuffer();
|
||||
item.append("<ITEM>");
|
||||
item.append("<BUKRS>").append(sapOrgNum).append("</BUKRS>");
|
||||
item.append("<BELNR>").append(sapVoucherNo).append("</BELNR>");
|
||||
item.append("<GJAHR>").append(periodYear).append("</GJAHR>");
|
||||
item.append("<ZBUDAT>").append(zbudat).append("</ZBUDAT>");
|
||||
item.append("</ITEM>");
|
||||
return item.toString();
|
||||
}
|
||||
public static void updateVoucher (DynamicObject voucher,String resultStr) {
|
||||
voucher.set("zstatus","0");
|
||||
voucher.set("promsg",resultStr);
|
||||
SaveServiceHelper.save(new DynamicObject[]{voucher});
|
||||
}
|
||||
public void getSynData(String oaurl,DynamicObject[] ap_finapbillObjects,String soaAccountNumber,String OA_orgId,DynamicObject voucher) {
|
||||
|
||||
public static void updateVoucher (DynamicObject voucher,MT_CXDOCUMENT_IF_RET.ITEM item) {
|
||||
String zstatus = item.getZstatus();
|
||||
String packgid = item.getPackgid();
|
||||
String promsg = item.getPromsg();
|
||||
String belnr = item.getBelnr();
|
||||
String wbdate = item.getWbdate();
|
||||
//TODO:元数据 增加下拉框,已冲销,下拉框值为2
|
||||
voucher.set("shkd_zstatus","S".equals(zstatus)?"2":"0");
|
||||
voucher.set("shkd_packgid",packgid);
|
||||
voucher.set("shkd_promsg",promsg);
|
||||
voucher.set("shkd_belnr",belnr);
|
||||
voucher.set("shkd_wbdate",wbdate);
|
||||
SaveServiceHelper.save(new DynamicObject[]{voucher});
|
||||
for (DynamicObject apBillObj : ap_finapbillObjects) {
|
||||
DynamicObjectCollection inventry = apBillObj.getDynamicObjectCollection("shkd_inventry");
|
||||
for (DynamicObject apInvoice : inventry) {
|
||||
DynamicObject shkd_invoicereceipt = apInvoice.getDynamicObject("shkd_invoicereceipt");//发票识别单
|
||||
DynamicObject invoiceBill = BusinessDataServiceHelper.loadSingle(shkd_invoicereceipt.getPkValue(), "shkd_invoicereceipt");
|
||||
|
||||
StringBuffer xml = new StringBuffer();
|
||||
xml.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:mod=\"http://localhost/services/ModeDateService\">");
|
||||
xml.append("<soapenv:Header/>");
|
||||
xml.append("<soapenv:Body>");
|
||||
xml.append("<mod:saveModeData>");
|
||||
xml.append("<mod:in0>");
|
||||
xml.append(" <![CDATA[");
|
||||
xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||
xml.append("<ROOT><header><userid>1</userid><modeid>3281</modeid><id></id></header>");
|
||||
xml.append("<search><condition /><right>Y</right></search>");
|
||||
xml.append("<data id=\"\">");
|
||||
xml.append("<maintable>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>fphm</filedname>");
|
||||
xml.append("<filedvalue>").append(invoiceBill.getString("shkd_invoiceno")).append("</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>kpdw</filedname>");
|
||||
xml.append("<filedvalue>").append(invoiceBill.getString("shkd_asstactname")).append("</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>fpnr</filedname>");
|
||||
xml.append("<filedvalue></filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>fpze</filedname>");
|
||||
xml.append("<filedvalue>").append(invoiceBill.getBigDecimal("shkd_pricetaxtotal")).append("</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>fplx</filedname>");
|
||||
xml.append("<filedvalue>0</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>kprq</filedname>");
|
||||
xml.append("<filedvalue>").append(DateUtils.format(invoiceBill.getDate("shkd_invoicedate"), DateUtils.COMPACT_YY_MM_DD)).append("</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>zt</filedname>");
|
||||
xml.append("<filedvalue>1</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>bhsje</filedname>");
|
||||
xml.append("<filedvalue>").append(invoiceBill.getBigDecimal("shkd_amount")).append("</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>se</filedname>");
|
||||
xml.append("<filedvalue>").append(invoiceBill.getBigDecimal("shkd_tax")).append("</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>shje</filedname>");
|
||||
xml.append("<filedvalue>").append(invoiceBill.getBigDecimal("shkd_pricetaxtotal")).append("</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>sl</filedname>");
|
||||
xml.append("<filedvalue>").append(invoiceBill.getString("shkd_taxrate1").replace("%","")).append("</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>sfyf</filedname>");
|
||||
xml.append("<filedvalue>1</filedvalue>");
|
||||
xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>fpsfdw</filedname>");
|
||||
xml.append("<filedvalue>").append(OA_orgId).append("</filedvalue>");
|
||||
xml.append("</field>");
|
||||
// xml.append("<field>");
|
||||
// xml.append("<filedname>yfje</filedname>");
|
||||
// xml.append("<filedvalue>0</filedvalue>");
|
||||
// xml.append("</field>");
|
||||
xml.append("<field>");
|
||||
xml.append("<filedname>sapkm</filedname>");
|
||||
xml.append("<filedvalue>").append(soaAccountNumber).append("</filedvalue>");
|
||||
xml.append("</field>");
|
||||
// xml.append("<field>");
|
||||
// xml.append("<filedname>cbzx</filedname>");
|
||||
// xml.append("<filedvalue>\"\"</filedvalue>");
|
||||
// xml.append("</field>");
|
||||
xml.append("</maintable>");
|
||||
xml.append("</data>");
|
||||
xml.append("</ROOT>");
|
||||
xml.append("]]>");
|
||||
|
||||
|
||||
xml.append("</mod:in0>");
|
||||
xml.append("</mod:saveModeData>");
|
||||
xml.append("</soapenv:Body>");
|
||||
xml.append("</soapenv:Envelope>");
|
||||
|
||||
|
||||
String s = HttpUtils.sendPostToOA(oaurl, xml.toString());
|
||||
if (s.contains("id>") && s.contains("</id")) {
|
||||
String id = s.substring(s.indexOf("id>") + 6, s.indexOf("</id"));
|
||||
try {
|
||||
int i = Integer.parseInt(id);
|
||||
if (i > 0) {
|
||||
this.operationResult.setShowMessage(true);
|
||||
this.operationResult.setSuccess(true);
|
||||
this.operationResult.setMessage("同步成功");
|
||||
voucher.set("shkd_oa_status","1");
|
||||
SaveServiceHelper.save(new DynamicObject[]{voucher});
|
||||
} else {
|
||||
this.operationResult.setShowMessage(true);
|
||||
this.operationResult.setSuccess(false);
|
||||
this.operationResult.setMessage("同步失败:" + xml.toString());
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
this.operationResult.setShowMessage(true);
|
||||
this.operationResult.setSuccess(false);
|
||||
this.operationResult.setMessage("同步失败:" + xml.toString());
|
||||
}
|
||||
|
||||
} else {
|
||||
this.operationResult.setShowMessage(true);
|
||||
this.operationResult.setSuccess(false);
|
||||
this.operationResult.setMessage("同步失败:" + xml.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package shkd.fi.fi.util;
|
||||
|
||||
import oadd.org.apache.calcite.avatica.org.apache.http.entity.StringEntity;
|
||||
import oadd.org.apache.commons.httpclient.HttpClient;
|
||||
import oadd.org.apache.commons.httpclient.methods.PostMethod;
|
||||
import oadd.org.apache.commons.httpclient.methods.StringRequestEntity;
|
||||
|
@ -17,11 +16,48 @@ public class HttpUtils {
|
|||
|
||||
/**
|
||||
* 发送xml请求到server端
|
||||
*
|
||||
* @param url xml请求数据地址
|
||||
* @param xmlString 发送的xml数据流
|
||||
* @return null发送失败,否则返回响应内容
|
||||
*/
|
||||
public static Map<String,Object> sendPostToSAP(String url, String token,String xmlString){
|
||||
public static String sendPostToOA(String url, String xmlString){
|
||||
//创建httpclient工具对象
|
||||
HttpClient client = new HttpClient();
|
||||
//创建post请求方法
|
||||
PostMethod myPost = new PostMethod(url);
|
||||
//设置请求超时时间
|
||||
client.setConnectionTimeout(3000*1000);
|
||||
String responseString = "";
|
||||
try{
|
||||
//设置请求头部类型
|
||||
myPost.setRequestHeader("Content-Type","application/xml");
|
||||
myPost.setRequestHeader("charset","UTF-8");
|
||||
//设置请求体,即xml文本内容,一种是直接获取xml内容字符串,一种是读取xml文件以流的形式
|
||||
byte[] utf8Bytes = xmlString.getBytes("UTF-8");
|
||||
String utf8Str = new String(utf8Bytes, "UTF-8");
|
||||
// myPost.setRequestBody(utf8Str);
|
||||
// String content, String contentType, String charset
|
||||
StringRequestEntity requestEntity = new StringRequestEntity(utf8Str, "application/xml","UTF-8");
|
||||
myPost.setRequestEntity(requestEntity);
|
||||
|
||||
int status = client.executeMethod(myPost);
|
||||
InputStream inputStream = myPost.getResponseBodyAsStream();
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream,"utf-8"));
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
String str = "";
|
||||
while ((str = br.readLine()) != null) {
|
||||
stringBuffer.append(str);
|
||||
}
|
||||
responseString = stringBuffer.toString();
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}finally{
|
||||
myPost.releaseConnection();
|
||||
}
|
||||
return responseString;
|
||||
}
|
||||
|
||||
public static Map<String,Object> sendPostToSAP(String url,String token,String xmlString){
|
||||
Map<String,Object> resultMap = new HashMap<String,Object>();
|
||||
//创建httpclient工具对象
|
||||
HttpClient client = new HttpClient();
|
||||
|
@ -35,6 +71,7 @@ public class HttpUtils {
|
|||
myPost.setRequestHeader("Content-Type","application/xml");
|
||||
myPost.setRequestHeader("charset","UTF-8");
|
||||
myPost.setRequestHeader("Authorization", "Basic "+token);
|
||||
|
||||
//设置请求体,即xml文本内容,一种是直接获取xml内容字符串,一种是读取xml文件以流的形式
|
||||
byte[] utf8Bytes = xmlString.getBytes("UTF-8");
|
||||
String utf8Str = new String(utf8Bytes, "UTF-8");
|
||||
|
|
Loading…
Reference in New Issue