Merge remote-tracking branch 'origin/master'

This commit is contained in:
刘鹏 2024-07-12 16:45:21 +08:00
commit dae2c17ab1
1 changed files with 159 additions and 0 deletions

View File

@ -0,0 +1,159 @@
package shkd.fi.fi.opplugin;
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.logging.LogFactory;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 凭证--SAP
* :shkd_gl_voucher_ext
*/
public class SynchronizaSapOPPlugin extends AbstractOperationServicePlugIn {
@Override
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
super.afterExecuteOperationTransaction(e);
Integer integer = 0;
for (DynamicObject dataEntity : e.getDataEntities()) {
DynamicObject gl_voucher = BusinessDataServiceHelper.loadSingle(dataEntity.getPkValue(), "gl_voucher");
try {
//1.公司代码(BUKRS)--核算组织(org)
DynamicObject org = gl_voucher.getDynamicObject("org");
String shkd_sap_number = "";
if (null != org) {
DynamicObject bos_org = BusinessDataServiceHelper.loadSingle(org.getPkValue(), "bos_org");
if (null != bos_org) {
shkd_sap_number = bos_org.getString("shkd_sap_number");
}
}
//2.公司代码(CRDATE)--当前时间
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String crdate = simpleDateFormat.format(date);
//3.创建人(CRNAME)--创建人名称(creator)
DynamicObject creator = gl_voucher.getDynamicObject("creator");
String crname = "";
if (null != creator) {
crname = creator.getString("name");
}
//4.记录条数(ZRTOALL)--所传数据的凭证分录总条数
DynamicObjectCollection entries = gl_voucher.getDynamicObjectCollection("entries");
integer +=entries.size();
//5.数据包唯一标识号(PACKGID)--格式JDN+时间戳
String packgid = "JDN" + date.getTime();
//6.数据状态T测试运行P正式运行(ZFLAG)--固定传T
String zflag = "T";
//7.库存凭证号(DOCID)--凭证号_凭证ID
Long id = gl_voucher.getLong("id");
String billno = gl_voucher.getString("billno");
String docid = id + "_" + billno;
//8.库存行项目号(ITEMID)--凭证分录行号从1开始
String seq = "";
for (DynamicObject entry : entries) {
seq = entry.getString("seq");
}
//9.数据处理状态 I未处理V校验失败F过账失败S过账成功写死"I未处理"(ZSTATUS)--固定值I
String zstatus = "I";
//10.公司代码----同1重复
//11.凭证中的过账日期(BUDAT)--记账日期(bookeddate)20181031
//12.凭证中的凭证日期(BLDAT)--记账日期
//15.凭证中的凭证日期(WWERT)--记账日期
Date bookeddate = gl_voucher.getDate("bookeddate");
String budat = "";
String bldat = "";
String wwert = "";
if (null != bookeddate) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
budat = simpleDateFormat.format(bookeddate);
budat = budat.substring(0,8);
bldat = simpleDateFormat.format(bookeddate);
bldat = bldat.substring(0,8);
wwert = simpleDateFormat.format(bookeddate);
wwert = wwert.substring(0,8);
}
//13.抬头文本(BKTXT)----凭证分录第一行摘要(如超长需截位保留前25个字)(edescription)
//14.货币码(WAERS)----币别基础资料的货币代码(currency)
String edescription = "";
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");
if (null != currency) {
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");
String hkont = "";
if (null != account) {
DynamicObject bd_accountview = BusinessDataServiceHelper.loadSingle(account.getPkValue(), "bd_accountview");
hkont = bd_accountview.getString("shkd_sap_number");
}else {
hkont = "9999999999";
}
//记账代码
String bschl = "";
if ("1".equals(entry.getString("entrydc"))) {
bschl = "40";
} else if ("-1".equals(entry.getString("entrydc"))) {
bschl = "50";
}
//凭证货币金额
BigDecimal oriamount = entry.getBigDecimal("oriamount");
String wrbtr = oriamount.toString();
String dmbtr = oriamount.toString();
//项目文本
String sgtxt = entry.getString("edescription");
if (sgtxt.length() > 25) {
sgtxt = sgtxt.substring(0,25);
}
//todo 核算维度--未调试(待维护数据)
Object assgrp = entry.get("assgrp");
}
System.out.println(docid);
}catch (Exception exc){
OperateErrorInfo operateErrorInfo = new OperateErrorInfo();
operateErrorInfo.setMessage(exc.getMessage());
operateErrorInfo.setErrorLevel(ErrorLevel.Error.name());
operateErrorInfo.setPkValue(dataEntity.getPkValue());
this.operationResult.addErrorInfo(operateErrorInfo);
}
}
System.out.println(integer);
}
}