From cbe37efac5f2cdc7ff1287f24947efb9bda0fc96 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=88=98=E9=B9=8F?= <845871400@qq.com>
Date: Tue, 13 Aug 2024 01:12:26 +0800
Subject: [PATCH] =?UTF-8?q?add=20oa=20=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/shkd/fi/fi/oa/OAInvoiceImpl.java | 98 -------
.../shkd/fi/fi/opplugin/DzpzkOPPlugin.java | 2 +-
.../fi/fi/opplugin/SynOAInvoiceOPPlugin.java | 276 +++++++++++-------
.../main/java/shkd/fi/fi/util/HttpUtils.java | 43 ++-
4 files changed, 205 insertions(+), 214 deletions(-)
delete mode 100644 fi/shkd-fi-fi/src/main/java/shkd/fi/fi/oa/OAInvoiceImpl.java
diff --git a/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/oa/OAInvoiceImpl.java b/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/oa/OAInvoiceImpl.java
deleted file mode 100644
index cb251c3..0000000
--- a/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/oa/OAInvoiceImpl.java
+++ /dev/null
@@ -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("");
- xml.append("");
- xml.append("");
- xml.append("");
- xml.append("");
- xml.append(" ");
- xml.append("");
- xml.append("Y");
- xml.append("");
- xml.append("");
- xml.append("");
- xml.append("fphm");
- xml.append("").append(inovice.getString("")).append("");
- xml.append("");
- xml.append("");
- xml.append("kpdw");
- xml.append("上海亿升海运仓储有限公司");
- xml.append("");
- xml.append("");
- xml.append("fpnr");
- xml.append("发票内容测试");
- xml.append("");
- xml.append("");
- xml.append("fpze");
- xml.append("119.36");
- xml.append("");
- xml.append("");
- xml.append("fplx");
- xml.append("0");
- xml.append("");
- xml.append("");
- xml.append("kprq");
- xml.append("2024-07-02");
- xml.append("");
- xml.append("");
- xml.append("zt");
- xml.append("1");
- xml.append("");
- xml.append("");
- xml.append("bhsje");
- xml.append("115.88");
- xml.append("");
- xml.append("");
- xml.append("se");
- xml.append("3.48");
- xml.append("");
- xml.append("");
- xml.append("shje");
- xml.append("200");
- xml.append("");
- xml.append("");
- xml.append("sl");
- xml.append("0.13");
- xml.append("");
- xml.append("");
- xml.append("sfyf");
- xml.append("1");
- xml.append("");
- xml.append("");
- xml.append("fpsfdw");
- xml.append("5621");
- xml.append("");
-// xml.append("");
-// xml.append("yfje");
-// xml.append("0");
-// xml.append("");
- xml.append("");
- xml.append("sapkm");
- xml.append("").append(soaAccountNumber).append("");
- xml.append("");
-// xml.append("");
-// xml.append("cbzx");
-// xml.append("\"\"");
-// xml.append("");
- xml.append("");
- xml.append("");
- xml.append("");
- xml.append("]]>");
-
-
- xml.append("");
- xml.append("");
- xml.append("");
- xml.append("");
-
- return xml.toString();
- }
-}
diff --git a/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/opplugin/DzpzkOPPlugin.java b/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/opplugin/DzpzkOPPlugin.java
index a3ed10d..b2537d8 100644
--- a/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/opplugin/DzpzkOPPlugin.java
+++ b/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/opplugin/DzpzkOPPlugin.java
@@ -870,7 +870,7 @@ public class DzpzkOPPlugin extends AbstractOperationServicePlugIn {
* @param billId 当前单据ID
* @return 下游单据id集合
*/
- private static List down(String entity,Long billId) {
+ public static List down(String entity,Long billId) {
List idList = new ArrayList();
Map> dirtSourceBillMap = BFTrackerServiceHelper.findDirtTargetBills(entity, new Long[]{billId});
List bfRows = dirtSourceBillMap.get(billId);
diff --git a/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/opplugin/SynOAInvoiceOPPlugin.java b/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/opplugin/SynOAInvoiceOPPlugin.java
index 7148289..4e3f2e2 100644
--- a/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/opplugin/SynOAInvoiceOPPlugin.java
+++ b/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/opplugin/SynOAInvoiceOPPlugin.java
@@ -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 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 billTypeList = new ArrayList();
+ 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 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 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 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.append("").append(sapOrgNum).append("");
- item.append("").append(sapVoucherNo).append("");
- item.append("").append(periodYear).append("");
- item.append("").append(zbudat).append("");
- item.append("
");
- 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("");
+ xml.append("");
+ xml.append("");
+ xml.append("");
+ xml.append("");
+ xml.append(" ");
+ xml.append("");
+ xml.append("Y");
+ xml.append("");
+ xml.append("");
+ xml.append("");
+ xml.append("fphm");
+ xml.append("").append(invoiceBill.getString("shkd_invoiceno")).append("");
+ xml.append("");
+ xml.append("");
+ xml.append("kpdw");
+ xml.append("").append(invoiceBill.getString("shkd_asstactname")).append("");
+ xml.append("");
+ xml.append("");
+ xml.append("fpnr");
+ xml.append("");
+ xml.append("");
+ xml.append("");
+ xml.append("fpze");
+ xml.append("").append(invoiceBill.getBigDecimal("shkd_pricetaxtotal")).append("");
+ xml.append("");
+ xml.append("");
+ xml.append("fplx");
+ xml.append("0");
+ xml.append("");
+ xml.append("");
+ xml.append("kprq");
+ xml.append("").append(DateUtils.format(invoiceBill.getDate("shkd_invoicedate"), DateUtils.COMPACT_YY_MM_DD)).append("");
+ xml.append("");
+ xml.append("");
+ xml.append("zt");
+ xml.append("1");
+ xml.append("");
+ xml.append("");
+ xml.append("bhsje");
+ xml.append("").append(invoiceBill.getBigDecimal("shkd_amount")).append("");
+ xml.append("");
+ xml.append("");
+ xml.append("se");
+ xml.append("").append(invoiceBill.getBigDecimal("shkd_tax")).append("");
+ xml.append("");
+ xml.append("");
+ xml.append("shje");
+ xml.append("").append(invoiceBill.getBigDecimal("shkd_pricetaxtotal")).append("");
+ xml.append("");
+ xml.append("");
+ xml.append("sl");
+ xml.append("").append(invoiceBill.getString("shkd_taxrate1").replace("%","")).append("");
+ xml.append("");
+ xml.append("");
+ xml.append("sfyf");
+ xml.append("1");
+ xml.append("");
+ xml.append("");
+ xml.append("fpsfdw");
+ xml.append("").append(OA_orgId).append("");
+ xml.append("");
+// xml.append("");
+// xml.append("yfje");
+// xml.append("0");
+// xml.append("");
+ xml.append("");
+ xml.append("sapkm");
+ xml.append("").append(soaAccountNumber).append("");
+ xml.append("");
+// xml.append("");
+// xml.append("cbzx");
+// xml.append("\"\"");
+// xml.append("");
+ xml.append("");
+ xml.append("");
+ xml.append("");
+ xml.append("]]>");
+
+
+ xml.append("");
+ xml.append("");
+ xml.append("");
+ xml.append("");
+
+
+ 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());
+ }
+ }
+
+ }
}
}
diff --git a/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/util/HttpUtils.java b/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/util/HttpUtils.java
index da9c2d6..9dd7071 100644
--- a/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/util/HttpUtils.java
+++ b/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/util/HttpUtils.java
@@ -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 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 sendPostToSAP(String url,String token,String xmlString){
Map resultMap = new HashMap();
//创建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");