凭证--SAP

This commit is contained in:
weiyunlong 2024-07-23 17:15:32 +08:00
parent aa92bc7daf
commit e23407a616
1 changed files with 183 additions and 50 deletions

View File

@ -6,12 +6,18 @@ import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.operate.result.OperateErrorInfo; import kd.bos.entity.operate.result.OperateErrorInfo;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn; import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.AfterOperationArgs; import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.logging.LogFactory;
import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.bos.servicehelper.BusinessDataServiceHelper;
import shkd.fi.fi.sap.*;
import javax.xml.rpc.ServiceException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
* 凭证--SAP * 凭证--SAP
@ -25,8 +31,15 @@ public class SynchronizaSapOPPlugin extends AbstractOperationServicePlugIn {
Integer integer = 0; Integer integer = 0;
for (DynamicObject dataEntity : e.getDataEntities()) { for (DynamicObject dataEntity : e.getDataEntities()) {
//结构ZFIS_YS_HEAD 库存-财务系统PI接口表头结构 (1-6)
DT_DOCUMENT_IF_SRCDATAIS_HEADER header = new DT_DOCUMENT_IF_SRCDATAIS_HEADER();
//结构ZFIS_YS_ITEM 库存-财务系统PI接口行项目结构
ArrayList<DT_DOCUMENT_IF_SRCDATAIT_ITEMITEM> items = new ArrayList<>();
DynamicObject gl_voucher = BusinessDataServiceHelper.loadSingle(dataEntity.getPkValue(), "gl_voucher"); DynamicObject gl_voucher = BusinessDataServiceHelper.loadSingle(dataEntity.getPkValue(), "gl_voucher");
try { try {
//1.公司代码(BUKRS)--核算组织(org) //1.公司代码(BUKRS)--核算组织(org)
DynamicObject org = gl_voucher.getDynamicObject("org"); DynamicObject org = gl_voucher.getDynamicObject("org");
String shkd_sap_number = ""; String shkd_sap_number = "";
@ -36,42 +49,56 @@ public class SynchronizaSapOPPlugin extends AbstractOperationServicePlugIn {
shkd_sap_number = bos_org.getString("shkd_sap_number"); shkd_sap_number = bos_org.getString("shkd_sap_number");
} }
} }
//2.公司代码(CRDATE)--当前时间 //2.创建日期(CRDATE)--当前时间
Date date = new Date(); Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String crdate = simpleDateFormat.format(date); String crdate = simpleDateFormat.format(date);
//3.创建人(CRNAME)--创建人名称(creator) //3.创建人(CRNAME)--创建人名称(creator)
DynamicObject creator = gl_voucher.getDynamicObject("creator"); DynamicObject creator = gl_voucher.getDynamicObject("creator");
String crname = ""; String crname = "";
if (null != creator) { if (null != creator) {
crname = creator.getString("name"); crname = creator.getString("name");
} }
//4.记录条数(ZRTOALL)--所传数据的凭证分录总条数 //4.记录条数(ZRTOALL)--所传数据的凭证分录总条数
DynamicObjectCollection entries = gl_voucher.getDynamicObjectCollection("entries"); DynamicObjectCollection entries = gl_voucher.getDynamicObjectCollection("entries");
integer +=entries.size(); integer +=entries.size();
//5.数据包唯一标识号(PACKGID)--格式JDN+时间戳 //5.数据包唯一标识号(PACKGID)--格式JDN+时间戳
String packgid = "JDN" + date.getTime(); String packgid = "JDN" + date.getTime();
//6.数据状态T测试运行P正式运行(ZFLAG)--固定传T //6.数据状态T测试运行P正式运行(ZFLAG)--固定传T
String zflag = "T"; String zflag = "T";
header.setBUKRS(shkd_sap_number);
header.setCRDATE(crdate);
header.setCRNAME(crname);
header.setZRTOALL(integer.toString());
header.setPACKGID(packgid);
header.setZFLAG(zflag);
//7.库存凭证号(DOCID)--凭证号_凭证ID //7.库存凭证号(DOCID)--凭证号_凭证ID
Long id = gl_voucher.getLong("id"); Long id = gl_voucher.getLong("id");
String billno = gl_voucher.getString("billno"); String billno = gl_voucher.getString("billno");
String docid = id + "_" + billno; String docid = id + "_" + billno;
//9.数据处理状态 I未处理V校验失败F过账失败S过账成功写死"I未处理"(ZSTATUS)--固定值I
String zstatus = "I";
//13.抬头文本(BKTXT)----凭证分录第一行摘要(如超长需截位保留前25个字)(edescription)
String bktxt = "";
//14.货币码(WAERS)----币别基础资料的货币代码(currency)
String waers = "";
//16.凭证类型 SAP凭证类型默认值具体值待定(BLART)--固定值SA
String blart = "SA";
//17.总账科目(HKONT)----取会计科目上SAP科目编码测试时可传9999999999(account)
//18.记账代码y(BSCHL)----借贷方向40=借方50=贷方(entrydc)
//19.凭证货币金额(WRBTR)----原币金额(oriamount)
//19.按本位币计的金额(DMBTR)----原币金额(oriamount)
//20.项目文本(SGTXT)----凭证行摘要(edescription)
//21.成本中心(KOSTL)----金蝶核算维度成本中心SAP编码()
for (DynamicObject entry : entries) {
DT_DOCUMENT_IF_SRCDATAIT_ITEMITEM items1 = new DT_DOCUMENT_IF_SRCDATAIT_ITEMITEM();
//8.库存行项目号(ITEMID)--凭证分录行号从1开始 //8.库存行项目号(ITEMID)--凭证分录行号从1开始
String seq = ""; String seq = "";
for (DynamicObject entry : entries) {
seq = entry.getString("seq"); seq = entry.getString("seq");
}
//9.数据处理状态 I未处理V校验失败F过账失败S过账成功写死"I未处理"(ZSTATUS)--固定值I
String zstatus = "I";
//10.公司代码----同1重复 //10.公司代码----同1重复
//11.凭证中的过账日期(BUDAT)--记账日期(bookeddate)20181031 //11.凭证中的过账日期(BUDAT)--记账日期(bookeddate)20181031
@ -91,32 +118,16 @@ public class SynchronizaSapOPPlugin extends AbstractOperationServicePlugIn {
wwert = wwert.substring(0,8); wwert = wwert.substring(0,8);
} }
//13.抬头文本(BKTXT)----凭证分录第一行摘要(如超长需截位保留前25个字)(edescription) bktxt = entries.get(0).getString("edescription");
//14.货币码(WAERS)----币别基础资料的货币代码(currency) if (bktxt.length() > 25) {
String edescription = ""; bktxt = bktxt.substring(0,25);//摘要
String waers = "";
if (entries.size() > 0) {
edescription = entries.get(0).getString("edescription");
if (edescription.length() > 25) {
edescription = edescription.substring(0,25);//摘要
} }
//币别 //币别
DynamicObject currency = entries.get(0).getDynamicObject("currency"); DynamicObject currency = entries.get(0).getDynamicObject("currency");
if (null != currency) { if (null != currency) {
waers = currency.getString("number"); waers = currency.getString("number");
} }
}
//16.凭证类型 SAP凭证类型默认值具体值待定(BLART)--固定值SA
String blart = "SA";
//17.总账科目(HKONT)----取会计科目上SAP科目编码测试时可传9999999999(account)
//18.记账代码y(BSCHL)----借贷方向40=借方50=贷方(entrydc)
//19.凭证货币金额(WRBTR)----原币金额(oriamount)
//19.按本位币计的金额(DMBTR)----原币金额(oriamount)
//20.项目文本(SGTXT)----凭证行摘要(edescription)
//21.成本中心(KOSTL)----金蝶核算维度成本中心SAP编码()
for (DynamicObject entry : entries) {
//总账科目 //总账科目
DynamicObject account = entry.getDynamicObject("account"); DynamicObject account = entry.getDynamicObject("account");
String hkont = ""; String hkont = "";
@ -142,10 +153,73 @@ public class SynchronizaSapOPPlugin extends AbstractOperationServicePlugIn {
if (sgtxt.length() > 25) { if (sgtxt.length() > 25) {
sgtxt = sgtxt.substring(0,25); sgtxt = sgtxt.substring(0,25);
} }
//todo 核算维度--未调试(待维护数据)
Object assgrp = entry.get("assgrp"); //todo
DynamicObject assgrp = entry.getDynamicObject("assgrp");
if (null != assgrp) {
DynamicObject bd_accountview = BusinessDataServiceHelper.loadSingle(assgrp.getPkValue(), "bd_asstacttype");
String number = bd_accountview.getString("number");
switch (number){
case "0001":
//客户
System.out.println("客户");
break;
case "0005":
//供应商
break;
default:
break;
}
}
items1.setDOCID(docid);
items1.setITEMNO(seq);
items1.setZSTATUS(zstatus);
items1.setBUKRS(shkd_sap_number);
items1.setBUDAT(budat);
items1.setBLDAT(budat);
items1.setBKTXT(bktxt);
items1.setWAERS(waers);
items1.setWWERT(budat);
items1.setBLART(blart);
items1.setHKONT(hkont);
items1.setBSCHL(bschl);
items1.setUMSKZ("");
items1.setWRBTR(wrbtr);
items1.setDMBTR(dmbtr);
items1.setZUONR("");
items1.setSGTXT(sgtxt);
items1.setKOSTL("");
items1.setPRCTR("");
items1.setGSBER("");
items1.setKUNNR("");
items1.setLIFNR("");
items1.setAUFNR("");
items1.setVALUT("");
items1.setXREF1("");
items1.setXREF2("");
items1.setXREF3("");
items1.setVBUND("");
items1.setZZCUSTOMER("");
items1.setZZVENDOR("");
items1.setZZFIELD1("");
items1.setZZFIELD2("");
items1.setZZFIELD3("");
items1.setZZFIELD4("");
items1.setZZFIELD5("");
items1.setZZFIELD6("");
items1.setHBKID("");
items1.setHKTID("");
items1.setXNEGP("");
items1.setKIDNO("");
items.add(items1);
} }
System.out.println(docid);
}catch (Exception exc){ }catch (Exception exc){
OperateErrorInfo operateErrorInfo = new OperateErrorInfo(); OperateErrorInfo operateErrorInfo = new OperateErrorInfo();
operateErrorInfo.setMessage(exc.getMessage()); operateErrorInfo.setMessage(exc.getMessage());
@ -153,7 +227,66 @@ public class SynchronizaSapOPPlugin extends AbstractOperationServicePlugIn {
operateErrorInfo.setPkValue(dataEntity.getPkValue()); operateErrorInfo.setPkValue(dataEntity.getPkValue());
this.operationResult.addErrorInfo(operateErrorInfo); this.operationResult.addErrorInfo(operateErrorInfo);
} }
//调接口
//todo 核算维度--未调试(待维护数据) ,记录条数(ZRTOALL)待确认
try {
test (header, items);
} catch (MalformedURLException | ServiceException | RemoteException ex) {
throw new RuntimeException(ex);
}
} }
System.out.println(integer); System.out.println(integer);
} }
static String userName = "PIEXTIFUSER";
static String password = "Welcome8";
public static void test (DT_DOCUMENT_IF_SRCDATAIS_HEADER header, List<DT_DOCUMENT_IF_SRCDATAIT_ITEMITEM> itemss) throws MalformedURLException, ServiceException, RemoteException {
// URL url = new URL("http://172.17.8.62:50000/dir/wsdl?p=ic/29ea716b5b95384591a91eb5d10c5715");
//必须用调用具体方法的地址
URL url = new URL("http://sappodev.cns.cosco.cos:50000/XISOAPAdapter/MessageServlet?senderParty=&senderService=ZBS&receiverParty=&receiverService=&interface=SI_DOCUMENT_IF&interfaceNamespace=urn:coscoshipping:shhy:2020");
SI_DOCUMENT_IFService service = new SI_DOCUMENT_IFServiceLocator();
SI_DOCUMENT_IFBindingStub stub = new SI_DOCUMENT_IFBindingStub(url, service);
stub.setUsername(userName);
stub.setPassword(password);
stub.setTimeout(8000);
// org.apache.axis.client.Call createCall = stub.createCall();
// createCall.setUsername(userName);
// createCall.setPassword(password);
// createCall.setTimeout(8000);
DT_DOCUMENT_IF_SRC srcData = setData(header,itemss);
DT_DOCUMENT_IF_RET result = null;
// SI_DOCUMENT_IF document_IF = new SI_DOCUMENT_IFProxy();
// result = document_IF.SI_DOCUMENT_IF(srcData);
result = stub.SI_DOCUMENT_IF(srcData);
// SI_DOCUMENT_IFServiceLocator locator = new SI_DOCUMENT_IFServiceLocator();
// SI_DOCUMENT_IF http_Port = locator.getHTTP_Port();
// result = http_Port.SI_DOCUMENT_IF(srcData);
System.out.println(result);
DT_DOCUMENT_IF_RETDATA returnData = result.getDATA();
DT_DOCUMENT_IF_RETDATAOT_RETNITEM[] ot_RETN = returnData.getOT_RETN();
}
public static DT_DOCUMENT_IF_SRC setData(DT_DOCUMENT_IF_SRCDATAIS_HEADER header, List<DT_DOCUMENT_IF_SRCDATAIT_ITEMITEM> itemss){
DT_DOCUMENT_IF_SRC srcData = new DT_DOCUMENT_IF_SRC();
DT_DOCUMENT_IF_SRCDATA data = new DT_DOCUMENT_IF_SRCDATA();
// build header
data.setIS_HEADER(header);
//build items1
DT_DOCUMENT_IF_SRCDATAIT_ITEMITEM[] items = itemss.toArray(new DT_DOCUMENT_IF_SRCDATAIT_ITEMITEM[itemss.size()] );
data.setIT_ITEM(items);
srcData.setDATA(data);
return srcData;
}
} }