电子凭证库系统附件归档接口

This commit is contained in:
刘鹏 2024-08-07 08:57:29 +08:00
parent 26d54d61a3
commit cdf8418cd1
12 changed files with 809 additions and 29 deletions

View File

@ -26,9 +26,73 @@ public class AppflgConstant {
public static final String SAP_CX_VOUCHER_URL_NAME = "SAP凭证冲销接口";
public static final String DZPZK_TOKEN = "dzpzk.coscoshipping.com.token";
/**
* 电子凭证库client_id
*/
public static final String DZPZK_CLIENT_ID = "dzpzk_client_id";
/**
* 电子凭证库client_secret
*/
public static final String DZPZK_CLIENT_SECRET = "dzpzk_client_secret";
/**
* 电子凭证库username
*/
public static final String DZPZK_USERNAME = "dzpzk_username";
/**
* 电子凭证库password
*/
public static final String DZPZK_PASSWORD = "dzpzk_password";
/**
* 电子凭证库获取token接口地址
*/
public static final String DZPZK_TOKE_URL = "dzpzk_toke_url";
public static final String DZPZK_TOKE_URL_NAME = "电子凭证库获取token接口";
/**
* 电子凭证库附件归档接口URL
*/
public static final String DZPZK_GUIDANG_URL = "dzpzk_guidang_url";
public static final String DZPZK_GUIDANG_URL_NAME = "电子凭证库附件归档接口";
/**
* 电子凭证库附件归档接口结果查询URL
*/
public static final String DZPZK_GUIDANG_RES_URL = "dzpzk_guidang_res_url";
public static final String DZPZK_GUIDANG_RES_URL_NAME = "电子凭证库附件归档结果查询接口";
/**
* 电子凭证库业务数据同步接口URL
*/
public static final String SHKD_DZPZK_BIZ_URL = "shkd_dzpzk_biz_url";
public static final String SHKD_DZPZK_BIZ_URL_NAME = "电子凭证库业务数据接口";
/**
* 电子凭证库业务数据同步接口结果查询URL
*/
public static final String SHKD_DZPZK_BIZ_RES_URL = "shkd_dzpzk_biz_res_url";
public static final String SHKD_DZPZK_BIZ_RES_URL_NAME = "电子凭证库业务数据结果查询接口";
/***
* OA发票池接口URL
*/
public static final String OA_INV_URL = "oa_inv_url";
public static final String OA_INV_URL_NAME = "OA发票池接口";
/**
* 系统编码
*/
public static final String SYS_NUMBER = "JDN";
/**
* 获取电子凭证库tokenURL
* @return
*/
public static String getDzpzkTokenURL(){
return System.getProperty("DZPZK_TOKE_URL")+"&client_id="+System.getProperty(AppflgConstant.DZPZK_CLIENT_ID)+"&client_secret="+
System.getProperty(AppflgConstant.DZPZK_CLIENT_SECRET)+"&username="+System.getProperty(AppflgConstant.DZPZK_USERNAME)+"&password="+
System.getProperty(AppflgConstant.DZPZK_PASSWORD);
}
}

View File

@ -15,7 +15,7 @@ public class Attr {
private String invoiceCode;
private String invoiceNumber;
private String invoiceType;
private Date invoiceDate;
private String invoiceDate;
private double taxExcludedAmount;
private double taxAmount;
private double taxIncludedAmount;
@ -28,7 +28,7 @@ public class Attr {
private String sourceDocNumber;
private String sourceDocCategory;
private String remarks;
private Date accountPeriod;
private String accountPeriod;
private String accountYear;
private String journalSummary;
private String journalNumber;
@ -53,10 +53,10 @@ public class Attr {
return invoiceType;
}
public void setInvoiceDate(Date invoiceDate) {
public void setInvoiceDate(String invoiceDate) {
this.invoiceDate = invoiceDate;
}
public Date getInvoiceDate() {
public String getInvoiceDate() {
return invoiceDate;
}
@ -144,10 +144,10 @@ public class Attr {
return remarks;
}
public void setAccountPeriod(Date accountPeriod) {
public void setAccountPeriod(String accountPeriod) {
this.accountPeriod = accountPeriod;
}
public Date getAccountPeriod() {
public String getAccountPeriod() {
return accountPeriod;
}

View File

@ -9,7 +9,7 @@ package shkd.fi.fi.common.dzpzk.guidang.req;
* @author bejson.com (i@bejson.com)
* @website http://www.bejson.com/java2pojo/
*/
public class DuidangRequestBean {
public class GuidangRequestBean {
private Head head;
private Body body;

View File

@ -2,7 +2,6 @@
* Copyright 2024 bejson.com
*/
package shkd.fi.fi.common.dzpzk.guidang.req;
import java.util.Date;
/**
* Auto-generated: 2024-08-03 17:16:18
@ -13,7 +12,7 @@ import java.util.Date;
public class Head {
private String sourceSys;
private Date requestTime;
private String requestTime;
private String requestNo;
public void setSourceSys(String sourceSys) {
this.sourceSys = sourceSys;
@ -22,10 +21,10 @@ public class Head {
return sourceSys;
}
public void setRequestTime(Date requestTime) {
public void setRequestTime(String requestTime) {
this.requestTime = requestTime;
}
public Date getRequestTime() {
public String getRequestTime() {
return requestTime;
}

View File

@ -0,0 +1,22 @@
/**
* Copyright 2024 bejson.com
*/
package shkd.fi.fi.common.dzpzk.guidangquery.req;
/**
* Auto-generated: 2024-08-06 20:51:49
*
* @author bejson.com (i@bejson.com)
* @website http://www.bejson.com/java2pojo/
*/
public class Body {
private String linkRequestNo;
public void setLinkRequestNo(String linkRequestNo) {
this.linkRequestNo = linkRequestNo;
}
public String getLinkRequestNo() {
return linkRequestNo;
}
}

View File

@ -0,0 +1,30 @@
/**
* Copyright 2024 bejson.com
*/
package shkd.fi.fi.common.dzpzk.guidangquery.req;
/**
* Auto-generated: 2024-08-06 20:51:49
*
* @author bejson.com (i@bejson.com)
* @website http://www.bejson.com/java2pojo/
*/
public class GuidangQueryReqBean {
private Head head;
private Body body;
public void setHead(Head head) {
this.head = head;
}
public Head getHead() {
return head;
}
public void setBody(Body body) {
this.body = body;
}
public Body getBody() {
return body;
}
}

View File

@ -0,0 +1,39 @@
/**
* Copyright 2024 bejson.com
*/
package shkd.fi.fi.common.dzpzk.guidangquery.req;
import java.util.Date;
/**
* Auto-generated: 2024-08-06 20:51:49
*
* @author bejson.com (i@bejson.com)
* @website http://www.bejson.com/java2pojo/
*/
public class Head {
private String requestNo;
private String requestTime;
private String sourceSys;
public void setRequestNo(String requestNo) {
this.requestNo = requestNo;
}
public String getRequestNo() {
return requestNo;
}
public void setRequestTime(String requestTime) {
this.requestTime = requestTime;
}
public String getRequestTime() {
return requestTime;
}
public void setSourceSys(String sourceSys) {
this.sourceSys = sourceSys;
}
public String getSourceSys() {
return sourceSys;
}
}

View File

@ -0,0 +1,175 @@
/**
* Copyright 2024 bejson.com
*/
package shkd.fi.fi.common.dzpzk.guidangquery.res;
import java.util.Date;
/**
* Auto-generated: 2024-08-06 20:54:33
*
* @author bejson.com (i@bejson.com)
* @website http://www.bejson.com/java2pojo/
*/
public class Attr {
private String companyCode;
private double taxExcludedAmount;
private String companyName;
private String journalSummary;
private String sellerName;
private String accountYear;
private Date accountPeriod;
private Date invoiceDate;
private String buyerName;
private String invoiceCode;
private String buyerTin;
private String invoiceNumber;
private String invoiceType;
private String journalNumber;
private double taxAmount;
private String sourceDocNumber;
private double taxIncludedAmount;
private String sourceDocCategory;
private String remarks;
private String sellerTin;
public void setCompanyCode(String companyCode) {
this.companyCode = companyCode;
}
public String getCompanyCode() {
return companyCode;
}
public void setTaxExcludedAmount(double taxExcludedAmount) {
this.taxExcludedAmount = taxExcludedAmount;
}
public double getTaxExcludedAmount() {
return taxExcludedAmount;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public String getCompanyName() {
return companyName;
}
public void setJournalSummary(String journalSummary) {
this.journalSummary = journalSummary;
}
public String getJournalSummary() {
return journalSummary;
}
public void setSellerName(String sellerName) {
this.sellerName = sellerName;
}
public String getSellerName() {
return sellerName;
}
public void setAccountYear(String accountYear) {
this.accountYear = accountYear;
}
public String getAccountYear() {
return accountYear;
}
public void setAccountPeriod(Date accountPeriod) {
this.accountPeriod = accountPeriod;
}
public Date getAccountPeriod() {
return accountPeriod;
}
public void setInvoiceDate(Date invoiceDate) {
this.invoiceDate = invoiceDate;
}
public Date getInvoiceDate() {
return invoiceDate;
}
public void setBuyerName(String buyerName) {
this.buyerName = buyerName;
}
public String getBuyerName() {
return buyerName;
}
public void setInvoiceCode(String invoiceCode) {
this.invoiceCode = invoiceCode;
}
public String getInvoiceCode() {
return invoiceCode;
}
public void setBuyerTin(String buyerTin) {
this.buyerTin = buyerTin;
}
public String getBuyerTin() {
return buyerTin;
}
public void setInvoiceNumber(String invoiceNumber) {
this.invoiceNumber = invoiceNumber;
}
public String getInvoiceNumber() {
return invoiceNumber;
}
public void setInvoiceType(String invoiceType) {
this.invoiceType = invoiceType;
}
public String getInvoiceType() {
return invoiceType;
}
public void setJournalNumber(String journalNumber) {
this.journalNumber = journalNumber;
}
public String getJournalNumber() {
return journalNumber;
}
public void setTaxAmount(double taxAmount) {
this.taxAmount = taxAmount;
}
public double getTaxAmount() {
return taxAmount;
}
public void setSourceDocNumber(String sourceDocNumber) {
this.sourceDocNumber = sourceDocNumber;
}
public String getSourceDocNumber() {
return sourceDocNumber;
}
public void setTaxIncludedAmount(double taxIncludedAmount) {
this.taxIncludedAmount = taxIncludedAmount;
}
public double getTaxIncludedAmount() {
return taxIncludedAmount;
}
public void setSourceDocCategory(String sourceDocCategory) {
this.sourceDocCategory = sourceDocCategory;
}
public String getSourceDocCategory() {
return sourceDocCategory;
}
public void setRemarks(String remarks) {
this.remarks = remarks;
}
public String getRemarks() {
return remarks;
}
public void setSellerTin(String sellerTin) {
this.sellerTin = sellerTin;
}
public String getSellerTin() {
return sellerTin;
}
}

View File

@ -0,0 +1,62 @@
/**
* Copyright 2024 bejson.com
*/
package shkd.fi.fi.common.dzpzk.guidangquery.res;
/**
* Auto-generated: 2024-08-06 20:54:33
*
* @author bejson.com (i@bejson.com)
* @website http://www.bejson.com/java2pojo/
*/
public class GuidangQueryResBean {
private int processingResult;
private String elementTypeCode;
private int retryCount;
private int sameAttachFileNameHandlerMode;
private String errorMessage;
private Attr attr;
public void setProcessingResult(int processingResult) {
this.processingResult = processingResult;
}
public int getProcessingResult() {
return processingResult;
}
public void setElementTypeCode(String elementTypeCode) {
this.elementTypeCode = elementTypeCode;
}
public String getElementTypeCode() {
return elementTypeCode;
}
public void setRetryCount(int retryCount) {
this.retryCount = retryCount;
}
public int getRetryCount() {
return retryCount;
}
public void setSameAttachFileNameHandlerMode(int sameAttachFileNameHandlerMode) {
this.sameAttachFileNameHandlerMode = sameAttachFileNameHandlerMode;
}
public int getSameAttachFileNameHandlerMode() {
return sameAttachFileNameHandlerMode;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public String getErrorMessage() {
return errorMessage;
}
public void setAttr(Attr attr) {
this.attr = attr;
}
public Attr getAttr() {
return attr;
}
}

View File

@ -95,6 +95,12 @@ public class UploadAttachmentsFormPlugin extends AbstractFormPlugin {
String orgName = formShowParameter.getCustomParam("orgName");
//财务应付单
DynamicObject ap_finapbill = BusinessDataServiceHelper.loadSingle(id, "ap_finapbill");
DynamicObject org = ap_finapbill.getDynamicObject("org");
String uniformsocialcreditcode = org.getString("uniformsocialcreditcode");//统一社会信用代码
if(StringUtils.isEmpty(uniformsocialcreditcode)){
this.getView().showMessage("当前结算组织未维护统一社会信用代码,请先维护");
return;
}
OperateOption option = OperateOption.create();
option.setVariableValue(OperateOptionConst.ISHASRIGHT, "true");
@ -177,7 +183,7 @@ public class UploadAttachmentsFormPlugin extends AbstractFormPlugin {
}
//1.3.组装OCR发票识别接口请求体
ocrScannerBody.put("serialNo", billno + System.currentTimeMillis());
ocrScannerBody.put("taxNo", "91310115607321695H");//先传固定值后续修改
ocrScannerBody.put("taxNo", uniformsocialcreditcode);
ocrScannerBody.put("operatorAccount", "");
ocrScannerBody.put("systemName", System.getProperty("systemName"));//SH-INVSYS
ocrScannerBody.put("serviceMode", "0");

View File

@ -2,30 +2,34 @@ 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 com.alibaba.fastjson.JSONObject;
import kd.bos.cache.CacheFactory;
import kd.bos.cache.DistributeSessionlessCache;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.operate.result.OperateErrorInfo;
import kd.bos.entity.botp.runtime.BFRow;
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.AttachmentServiceHelper;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.QueryServiceHelper;
import kd.bos.servicehelper.botp.BFTrackerServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.bos.util.HttpClientUtils;
import kd.bos.util.StringUtils;
import shkd.fi.fi.common.AppflgConstant;
import shkd.fi.fi.sap.requst.docuentif.*;
import shkd.fi.fi.common.dzpzk.guidang.req.*;
import shkd.fi.fi.common.dzpzk.guidang.res.GuidangResponseBean;
import shkd.fi.fi.common.dzpzk.guidangquery.req.GuidangQueryReqBean;
import shkd.fi.fi.common.dzpzk.guidangquery.res.GuidangQueryResBean;
import shkd.fi.fi.common.dzpzk.token.DzpzTokenBean;
import shkd.fi.fi.sap.result.docuentif.Item;
import shkd.fi.fi.sap.result.docuentif.MTDocumentIFRet;
import shkd.fi.fi.util.HttpUtils;
import shkd.fi.fi.util.DateUtils;
import shkd.fi.fi.util.FileUtils;
import shkd.fi.fi.util.LogBillUtils;
import shkd.fi.fi.util.XmlUtils;
import javax.xml.bind.JAXBException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.io.IOException;
import java.util.*;
/**
@ -34,6 +38,16 @@ import java.util.*;
*/
public class DzpzkOPPlugin extends AbstractOperationServicePlugIn {
private static final Log log = LogFactory.getLog(DzpzkOPPlugin.class);
DistributeSessionlessCache cache = CacheFactory.getCommonCacheFactory().getDistributeSessionlessCache(AppflgConstant.DZPZK_TOKEN);
/**
* 采购入库单
*/
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);
@ -42,8 +56,13 @@ public class DzpzkOPPlugin extends AbstractOperationServicePlugIn {
case "shkd_dzpzk_guidang":
synGuidang(e);
break;
case "shkd_dzpzk_guidang_res":
queryGuidangResult(e);
break;
case "shkd_dzpzk_biz":
break;
case "shkd_dzpzk_biz_res":
break;
default:
break;
}
@ -55,9 +74,79 @@ public class DzpzkOPPlugin extends AbstractOperationServicePlugIn {
StringBuffer errStr = new StringBuffer();
DynamicObject[] dataEntities = e.getDataEntities();
for (DynamicObject glvoucher : dataEntities) {
DynamicObject voucher = BusinessDataServiceHelper.loadSingle(glvoucher.getPkValue(), "gl_voucher");
for (DynamicObject voucher : dataEntities) {
// DynamicObject voucher = BusinessDataServiceHelper.loadSingle(glvoucher.getPkValue(), "gl_voucher");
String voucherNo = voucher.getString("billno");//凭证号
//校验1.单据是否已审核2.是否已同步到SAP
if("C".equals(voucher.getString("billstatus"))){
errStr.append("凭证号:").append(voucherNo).append("不满足同步条件,原因:");
errStr.append(" 凭证未审核").append("\r");
this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(false);
this.operationResult.setMessage("数据校验不通过:"+errStr.toString());
break;
}
if("1".equals(voucher.getString("shkd_zstatus"))){
errStr.append("凭证号:").append(voucherNo).append("不满足同步条件,原因:");
errStr.append(" 凭证未同步到SAP ").append("\r");
this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(false);
this.operationResult.setMessage("数据校验不通过:"+errStr.toString());
break;
}
//DAP关系
QFilter filter = new QFilter("voucherid",QCP.equals,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)});
if(null==ai_daptrackers||ai_daptrackers.length<=0){
errStr.append("凭证号:").append(voucherNo).append(" 来源单据不是采购入库单或财务应付单,无需同步电子凭证库系统");
errStr.append("\r");
this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(false);
this.operationResult.setMessage("数据校验不通过:"+errStr.toString());
break;
}else{
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 = down(im_purinbill, sourcebillid);
DynamicObject[] ap_finapbillObjects = BusinessDataServiceHelper.load(apBillIdList.toArray(), dynamicObject.getDynamicObjectType());
for (DynamicObject apBillObj : ap_finapbillObjects) {
DynamicObjectCollection inventry = apBillObj.getDynamicObjectCollection("inventry");
if(inventry.size()<=0){
errStr.append("凭证号:").append(voucherNo).append(" 来源单据财务应付单 ").append(apBillObj.getString("billno"));
errStr.append("无发票附件,无需同步电子凭证库系统").append("\r");
this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(false);
this.operationResult.setMessage("数据校验不通过:"+errStr.toString());
break;
}
}
}else if(ap_finapbill.equals(number)){//来源单据是财务应付单
DynamicObject[] ap_finapbillObjects = BusinessDataServiceHelper.load(new Long[]{sourcebillid}, dynamicObject.getDynamicObjectType());
for (DynamicObject apBillObj : ap_finapbillObjects) {
DynamicObjectCollection inventry = apBillObj.getDynamicObjectCollection("inventry");
if(inventry.size()<=0){
errStr.append("凭证号:").append(voucherNo).append(" 来源单据财务应付单 ").append(apBillObj.getString("billno"));
errStr.append("无发票附件,无需同步电子凭证库系统").append("\r");
this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(false);
this.operationResult.setMessage("数据校验不通过:"+errStr.toString());
break;
}
}
}
}
}
//1.1.校验公司是否已映射SAP编码
DynamicObject org = voucher.getDynamicObject("org");
String org_shkd_sap_number = org.getString("shkd_sap_number");
@ -105,12 +194,284 @@ public class DzpzkOPPlugin extends AbstractOperationServicePlugIn {
}
Integer integer = 0;
//2.组装转换参数
for (DynamicObject dataEntity : voucherColl) {
String requstTime = DateUtils.formatDate(new Date(), DateUtils.PATTERN_CLASSICAL);
String requstNo = DateUtils.formatDate(new Date(), DateUtils.COMPACT_TIME);
Random random = new Random();
int randomNumber = 1000 + random.nextInt(9000); // 生成1000到9999之间的随机数
requstNo = AppflgConstant.SYS_NUMBER+requstNo+randomNumber;
for (DynamicObject voucher : voucherColl) {
DynamicObject org = voucher.getDynamicObject("org");
String org_shkd_sap_number = org.getString("shkd_sap_number");
GuidangRequestBean guidangVo = new GuidangRequestBean();
Head head = new Head();
head.setSourceSys(AppflgConstant.SYS_NUMBER);
head.setRequestTime(requstTime);
head.setRequestNo(requstNo);
guidangVo.setHead(head);
Body body = new Body();
Elements elements = new Elements();
elements.setElementTypeCode("INVOICE");
elements.setPaperFlag(0);
elements.setPartyAttachMode("MULTI");
//DAP关系
QFilter filter = new QFilter("voucherid",QCP.equals,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)});
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 = down(im_purinbill, sourcebillid);
buildElements(BusinessDataServiceHelper.load(apBillIdList.toArray(), dynamicObject.getDynamicObjectType()), org_shkd_sap_number, org, voucher, elements);
}else if(ap_finapbill.equals(number)){//来源单据是财务应付单
buildElements(BusinessDataServiceHelper.load(new Long[]{sourcebillid}, dynamicObject.getDynamicObjectType()), org_shkd_sap_number, org, voucher, elements);
}
}
List<Elements> elementsList = new ArrayList<>();
elementsList.add(elements);
body.setElements(elementsList);
guidangVo.setBody(body);
//同步
//1.缓存有token 则取缓存里的token
String token ="";
if (cache.contains(AppflgConstant.DZPZK_TOKEN)) {
token = cache.get(AppflgConstant.DZPZK_TOKEN);
} else {
//2.缓存无token,通过接口调用获取token
//1.1.请求头
//1.3.通过接口调用获取token
try {
String getTokenResult = HttpClientUtils.post(AppflgConstant.getDzpzkTokenURL(), null, null);
LogBillUtils.SaveLogBill(AppflgConstant.getDzpzkTokenURL(), getTokenResult, AppflgConstant.DZPZK_TOKE_URL_NAME, "");
if (StringUtils.isEmpty(getTokenResult)) {
this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(false);
this.operationResult.setMessage("同步失败:获取电子凭证库系统token失败");
return;
}
DzpzTokenBean dzpzTokenBean = JSONObject.parseObject(getTokenResult, DzpzTokenBean.class);
token = dzpzTokenBean.getAccess_token();
int expires_in = dzpzTokenBean.getExpires_in();
cache.put(AppflgConstant.DZPZK_TOKEN, token, expires_in);//将自定义参数加入缓存
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
try {
String guidangUrl = System.getProperty(AppflgConstant.DZPZK_GUIDANG_URL);
Map<String, String> header = new HashMap<String, String>();
header.put("Authorization","Bearer "+token);
String jsonBody = JSONObject.toJSONString(guidangVo);
String postjson = HttpClientUtils.postjson(guidangUrl, header, jsonBody);
LogBillUtils.SaveLogBill(guidangUrl, postjson, AppflgConstant.DZPZK_GUIDANG_URL_NAME, jsonBody);
GuidangResponseBean guidangResponseBean = JSONObject.parseObject(postjson, GuidangResponseBean.class);
if("success".equals(guidangResponseBean.getCode())){
this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(true);
this.operationResult.setMessage("同步成功");
voucher.set("shkd_gd_reqno",requstNo);
voucher.set("shkd_dzpzkstatus","0");
SaveServiceHelper.save(new DynamicObject[]{voucher});
}else {
this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(false);
this.operationResult.setMessage("同步失败");
voucher.set("shkd_gd_reqno",requstNo);
voucher.set("shkd_dzpzkstatus","2");
SaveServiceHelper.save(new DynamicObject[]{voucher});
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
System.out.println(integer);
}
private static Elements buildElements(DynamicObject[] sourcebillid, String org_shkd_sap_number, DynamicObject org, DynamicObject voucher, Elements elements) {
DynamicObject[] ap_finapbillObjects = sourcebillid;
for (DynamicObject apBillObj : ap_finapbillObjects) {
DynamicObjectCollection inventry = apBillObj.getDynamicObjectCollection("inventry");
for (DynamicObject apInvoice: inventry) {
Attr attr = new Attr();
DynamicObject invoiceBill = apInvoice.getDynamicObject("shkd_invoicereceipt");//发票识别单
attr.setInvoiceCode(invoiceBill.getString("shkd_invoicecode"));
attr.setInvoiceNumber(invoiceBill.getString("shkd_invoiceno"));
attr.setInvoiceType("");
attr.setInvoiceDate(DateUtils.format(invoiceBill.getDate("shkd_invoicedate"),DateUtils.COMPACT_YY_MM_DD));
attr.setTaxExcludedAmount(invoiceBill.getBigDecimal("shkd_amount").doubleValue());//发票不含税金额
attr.setTaxAmount(invoiceBill.getBigDecimal("shkd_tax").doubleValue());//发票税额
attr.setTaxIncludedAmount(invoiceBill.getBigDecimal("shkd_pricetaxtotal").doubleValue());//发票总金额
attr.setBuyerTin("");
attr.setBuyerName("");
attr.setSellerTin("");
attr.setSellerName("");
attr.setCompanyCode(org_shkd_sap_number);
attr.setCompanyName(org.getString("name"));
attr.setSourceDocNumber(voucher.getLong("id")+"_"+ voucher.getString("billno"));
attr.setSourceDocCategory(voucher.getString("billno"));
attr.setRemarks("");
attr.setAccountPeriod(DateUtils.format(voucher.getDate("bookeddate"),DateUtils.COMPACT_YY_MM));
attr.setAccountYear(DateUtils.format(voucher.getDate("bookeddate"),DateUtils.COMPACT_YEAR));
attr.setJournalNumber(voucher.getString("shkd_belnr"));//SAP凭证号
elements.setAttr(attr);
List<PartyAttachmentList> partyAttachmentList = new ArrayList<PartyAttachmentList>();
// DynamicObjectCollection attachmentpanel = shkd_invoicereceipt.getDynamicObjectCollection("attachmentpanel");
List<Map<String, Object>> attachments = AttachmentServiceHelper.getAttachments("shkd_invoicereceipt", invoiceBill.getPkValue(), "attachmentpanel");
for (Map<String,Object> attach:attachments) {
PartyAttachmentList fileVo = new PartyAttachmentList();
String url = (String)attach.get("url");
String fileHexString = FileUtils.fileToHex(url);
String name = (String)attach.get("name");
Integer size = (Integer)attach.get("size");
fileVo.setFileName(name);
fileVo.setFileSize(size);
fileVo.setNumeration("HEX");
fileVo.setFileHexString(fileHexString);
partyAttachmentList.add(fileVo);
}
elements.setPartyAttachmentList(partyAttachmentList);
}
}
return elements;
}
public void queryGuidangResult(AfterOperationArgs e){
//1.校验不满足条件的凭证移除不传输
DynamicObjectCollection voucherColl = new DynamicObjectCollection();
StringBuffer errStr = new StringBuffer();
DynamicObject[] dataEntities = e.getDataEntities();
for (DynamicObject voucher : dataEntities) {
String voucherNo = voucher.getString("billno");//凭证号
if("C".equals(voucher.getString("billstatus"))){
errStr.append("凭证号:").append(voucherNo).append("不满足同步条件,原因:");
errStr.append(" 凭证未审核").append("\r");
this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(false);
this.operationResult.setMessage("数据校验不通过:"+errStr.toString());
break;
}
if("0".equals(voucher.getString("shkd_dzpzkstatus"))){
errStr.append("凭证号:").append(voucherNo).append("不满足查询条件,原因:");
errStr.append(" 凭证归档状态不是 附件已归档待处理").append("\r");
this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(false);
this.operationResult.setMessage("数据校验不通过:"+errStr.toString());
break;
}
if(StringUtils.isEmpty(voucher.getString("shkd_gd_reqno"))){
errStr.append("凭证号:").append(voucherNo).append("不满足查询条件,原因:");
errStr.append(" 附件归档请求编号为空").append("\r");
this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(false);
this.operationResult.setMessage("数据校验不通过:"+errStr.toString());
break;
}
}
//数据校验不通过则不进行同步
if(StringUtils.isNotEmpty(errStr.toString())){
this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(false);
this.operationResult.setMessage("数据校验不通过:"+errStr.toString());
return;
}
//2.组装转换参数
for (DynamicObject voucher : voucherColl) {
DynamicObject org = voucher.getDynamicObject("org");
String shkd_gd_reqno = org.getString("shkd_gd_reqno");
//同步
//1.缓存有token 则取缓存里的token
String token ="";
if (cache.contains(AppflgConstant.DZPZK_TOKEN)) {
token = cache.get(AppflgConstant.DZPZK_TOKEN);
} else {
//2.缓存无token,通过接口调用获取token
//1.1.请求头
//1.3.通过接口调用获取token
try {
String getTokenResult = HttpClientUtils.post(AppflgConstant.getDzpzkTokenURL(), null, null);
LogBillUtils.SaveLogBill(AppflgConstant.getDzpzkTokenURL(), getTokenResult, AppflgConstant.DZPZK_TOKE_URL_NAME, "");
if (StringUtils.isEmpty(getTokenResult)) {
this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(false);
this.operationResult.setMessage("同步失败:获取电子凭证库系统token失败");
return;
}
DzpzTokenBean dzpzTokenBean = JSONObject.parseObject(getTokenResult, DzpzTokenBean.class);
token = dzpzTokenBean.getAccess_token();
int expires_in = dzpzTokenBean.getExpires_in();
cache.put(AppflgConstant.DZPZK_TOKEN, token, expires_in);//将自定义参数加入缓存
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
try {
String guidangUrl = System.getProperty(AppflgConstant.DZPZK_GUIDANG_RES_URL);
Map<String, String> header = new HashMap<String, String>();
header.put("Authorization","Bearer "+token);
GuidangQueryReqBean guidangQueryReqBean = new GuidangQueryReqBean();
shkd.fi.fi.common.dzpzk.guidangquery.req.Head head = new shkd.fi.fi.common.dzpzk.guidangquery.req.Head();
String requstTime = DateUtils.formatDate(new Date(), DateUtils.PATTERN_CLASSICAL);
String requstNo = DateUtils.formatDate(new Date(), DateUtils.COMPACT_TIME);
Random random = new Random();
int randomNumber = 1000 + random.nextInt(9000); // 生成1000到9999之间的随机数
requstNo = AppflgConstant.SYS_NUMBER+requstNo+randomNumber;
head.setRequestNo(requstNo);
head.setRequestTime(requstTime);
head.setSourceSys(AppflgConstant.SYS_NUMBER);
guidangQueryReqBean.setHead(head);
shkd.fi.fi.common.dzpzk.guidangquery.req.Body body = new shkd.fi.fi.common.dzpzk.guidangquery.req.Body();
body.setLinkRequestNo(shkd_gd_reqno);
guidangQueryReqBean.setBody(body);
String jsonBody = JSONObject.toJSONString(guidangQueryReqBean);
String postjson = HttpClientUtils.postjson(guidangUrl, header, jsonBody);
LogBillUtils.SaveLogBill(guidangUrl, postjson, AppflgConstant.DZPZK_GUIDANG_RES_URL_NAME, jsonBody);
GuidangQueryResBean guidangResponseBean = JSONObject.parseObject(postjson, GuidangQueryResBean.class);
if("1".equals(guidangResponseBean.getProcessingResult())){
this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(true);
this.operationResult.setMessage("同步成功");
voucher.set("shkd_dzpzkstatus","1");
SaveServiceHelper.save(new DynamicObject[]{voucher});
}else {
this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(false);
this.operationResult.setMessage("同步失败");
voucher.set("shkd_dzpzkstatus","2");
SaveServiceHelper.save(new DynamicObject[]{voucher});
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
public void synBizData(AfterOperationArgs e){
//1.校验不满足条件的凭证移除不传输
DynamicObjectCollection voucherColl = new DynamicObjectCollection();
@ -195,10 +556,30 @@ public class DzpzkOPPlugin extends AbstractOperationServicePlugIn {
SaveServiceHelper.save(new DynamicObject[]{voucher});
}
public static void updateVoucher (DynamicObject voucher,String resultStr) {
voucher.set("zstatus","0");
voucher.set("promsg",resultStr);
voucher.set("shkd_gd_reqno","0");
voucher.set("shkd_dzpzkstatus",resultStr);
SaveServiceHelper.save(new DynamicObject[]{voucher});
}
/**
* 单据下插
* @param entity 当前单据标识
* @param billId 当前单据ID
* @return 下游单据id集合
*/
private 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);
if(bfRows!=null){
for (int i = 0; i < bfRows.size(); i++) {
BFRow bfRow = bfRows.get(i);
Long id = bfRow.getId().getBillId();
idList.add(id);
}
}
return idList;
}
}

View File

@ -25,6 +25,8 @@ public class DateUtils extends org.apache.commons.lang.time.DateUtils {
public static final String COMPACT_YEAR_MONTH = "yyyyMM";
public static final String COMPACT_YEAR = "yyyy";
public static final String COMPACT_DATE = "yyyyMMdd";
public static final String COMPACT_YY_MM_DD = "yyyy-MM-dd";
public static final String COMPACT_YY_MM = "yyyy-MM";
public static final String COMPACT_TIME = "yyyyMMddHHmmss";
public static final String COMPACT_YYYY_MM_TIME = "yyyy年MM月";