add dzpzk bizdata interface
This commit is contained in:
parent
ef4dd86c90
commit
d2e407cca3
|
@ -21,7 +21,7 @@ public class Attr {
|
|||
private String entryAccountFlag;
|
||||
private String usedFlag;
|
||||
private String usedConfirmation;
|
||||
private Date usedPeriod;
|
||||
private String usedPeriod;
|
||||
private String paidFlag;
|
||||
private String bankElectronicReceipt;
|
||||
private String transferFlag;
|
||||
|
@ -93,10 +93,10 @@ public class Attr {
|
|||
return usedConfirmation;
|
||||
}
|
||||
|
||||
public void setUsedPeriod(Date usedPeriod) {
|
||||
public void setUsedPeriod(String usedPeriod) {
|
||||
this.usedPeriod = usedPeriod;
|
||||
}
|
||||
public Date getUsedPeriod() {
|
||||
public String getUsedPeriod() {
|
||||
return usedPeriod;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,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 +22,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;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
* Copyright 2024 bejson.com
|
||||
*/
|
||||
package shkd.fi.fi.common.dzpzk.bizdata.req;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2024-08-03 17:26:28
|
||||
|
@ -14,8 +13,8 @@ public class JournalHeads {
|
|||
|
||||
private String accEntityCode;
|
||||
private String journalNumber;
|
||||
private Date accountDate;
|
||||
private Date accountPeriod;
|
||||
private String accountDate;
|
||||
private String accountPeriod;
|
||||
private String accountYear;
|
||||
private String journalSummary;
|
||||
public void setAccEntityCode(String accEntityCode) {
|
||||
|
@ -32,17 +31,17 @@ public class JournalHeads {
|
|||
return journalNumber;
|
||||
}
|
||||
|
||||
public void setAccountDate(Date accountDate) {
|
||||
public void setAccountDate(String accountDate) {
|
||||
this.accountDate = accountDate;
|
||||
}
|
||||
public Date getAccountDate() {
|
||||
public String getAccountDate() {
|
||||
return accountDate;
|
||||
}
|
||||
|
||||
public void setAccountPeriod(Date accountPeriod) {
|
||||
public void setAccountPeriod(String accountPeriod) {
|
||||
this.accountPeriod = accountPeriod;
|
||||
}
|
||||
public Date getAccountPeriod() {
|
||||
public String getAccountPeriod() {
|
||||
return accountPeriod;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ package shkd.fi.fi.common.dzpzk.guidangquery.res;
|
|||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2024-08-06 20:54:33
|
||||
* Auto-generated: 2024-08-08 18:3:44
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
|
@ -15,21 +15,20 @@ public class Attr {
|
|||
private String companyCode;
|
||||
private double taxExcludedAmount;
|
||||
private String companyName;
|
||||
private String journalSummary;
|
||||
private String sellerName;
|
||||
private String accountYear;
|
||||
private String sellerName;
|
||||
private Date accountPeriod;
|
||||
private Date invoiceDate;
|
||||
private String buyerName;
|
||||
private String invoiceCode;
|
||||
private Date invoiceDate;
|
||||
private String buyerTin;
|
||||
private String invoiceCode;
|
||||
private String invoiceNumber;
|
||||
private String invoiceType;
|
||||
private String journalNumber;
|
||||
private double taxAmount;
|
||||
private String sourceDocNumber;
|
||||
private double taxIncludedAmount;
|
||||
private double taxAmount;
|
||||
private String sourceDocCategory;
|
||||
private double taxIncludedAmount;
|
||||
private String remarks;
|
||||
private String sellerTin;
|
||||
public void setCompanyCode(String companyCode) {
|
||||
|
@ -53,11 +52,11 @@ public class Attr {
|
|||
return companyName;
|
||||
}
|
||||
|
||||
public void setJournalSummary(String journalSummary) {
|
||||
this.journalSummary = journalSummary;
|
||||
public void setAccountYear(String accountYear) {
|
||||
this.accountYear = accountYear;
|
||||
}
|
||||
public String getJournalSummary() {
|
||||
return journalSummary;
|
||||
public String getAccountYear() {
|
||||
return accountYear;
|
||||
}
|
||||
|
||||
public void setSellerName(String sellerName) {
|
||||
|
@ -67,13 +66,6 @@ public class Attr {
|
|||
return sellerName;
|
||||
}
|
||||
|
||||
public void setAccountYear(String accountYear) {
|
||||
this.accountYear = accountYear;
|
||||
}
|
||||
public String getAccountYear() {
|
||||
return accountYear;
|
||||
}
|
||||
|
||||
public void setAccountPeriod(Date accountPeriod) {
|
||||
this.accountPeriod = accountPeriod;
|
||||
}
|
||||
|
@ -81,13 +73,6 @@ public class Attr {
|
|||
return accountPeriod;
|
||||
}
|
||||
|
||||
public void setInvoiceDate(Date invoiceDate) {
|
||||
this.invoiceDate = invoiceDate;
|
||||
}
|
||||
public Date getInvoiceDate() {
|
||||
return invoiceDate;
|
||||
}
|
||||
|
||||
public void setBuyerName(String buyerName) {
|
||||
this.buyerName = buyerName;
|
||||
}
|
||||
|
@ -95,11 +80,11 @@ public class Attr {
|
|||
return buyerName;
|
||||
}
|
||||
|
||||
public void setInvoiceCode(String invoiceCode) {
|
||||
this.invoiceCode = invoiceCode;
|
||||
public void setInvoiceDate(Date invoiceDate) {
|
||||
this.invoiceDate = invoiceDate;
|
||||
}
|
||||
public String getInvoiceCode() {
|
||||
return invoiceCode;
|
||||
public Date getInvoiceDate() {
|
||||
return invoiceDate;
|
||||
}
|
||||
|
||||
public void setBuyerTin(String buyerTin) {
|
||||
|
@ -109,6 +94,13 @@ public class Attr {
|
|||
return buyerTin;
|
||||
}
|
||||
|
||||
public void setInvoiceCode(String invoiceCode) {
|
||||
this.invoiceCode = invoiceCode;
|
||||
}
|
||||
public String getInvoiceCode() {
|
||||
return invoiceCode;
|
||||
}
|
||||
|
||||
public void setInvoiceNumber(String invoiceNumber) {
|
||||
this.invoiceNumber = invoiceNumber;
|
||||
}
|
||||
|
@ -130,13 +122,6 @@ public class Attr {
|
|||
return journalNumber;
|
||||
}
|
||||
|
||||
public void setTaxAmount(double taxAmount) {
|
||||
this.taxAmount = taxAmount;
|
||||
}
|
||||
public double getTaxAmount() {
|
||||
return taxAmount;
|
||||
}
|
||||
|
||||
public void setSourceDocNumber(String sourceDocNumber) {
|
||||
this.sourceDocNumber = sourceDocNumber;
|
||||
}
|
||||
|
@ -144,11 +129,11 @@ public class Attr {
|
|||
return sourceDocNumber;
|
||||
}
|
||||
|
||||
public void setTaxIncludedAmount(double taxIncludedAmount) {
|
||||
this.taxIncludedAmount = taxIncludedAmount;
|
||||
public void setTaxAmount(double taxAmount) {
|
||||
this.taxAmount = taxAmount;
|
||||
}
|
||||
public double getTaxIncludedAmount() {
|
||||
return taxIncludedAmount;
|
||||
public double getTaxAmount() {
|
||||
return taxAmount;
|
||||
}
|
||||
|
||||
public void setSourceDocCategory(String sourceDocCategory) {
|
||||
|
@ -158,6 +143,13 @@ public class Attr {
|
|||
return sourceDocCategory;
|
||||
}
|
||||
|
||||
public void setTaxIncludedAmount(double taxIncludedAmount) {
|
||||
this.taxIncludedAmount = taxIncludedAmount;
|
||||
}
|
||||
public double getTaxIncludedAmount() {
|
||||
return taxIncludedAmount;
|
||||
}
|
||||
|
||||
public void setRemarks(String remarks) {
|
||||
this.remarks = remarks;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
package shkd.fi.fi.common.dzpzk.guidangquery.res;
|
||||
|
||||
/**
|
||||
* Auto-generated: 2024-08-06 20:54:33
|
||||
* Auto-generated: 2024-08-08 18:3:44
|
||||
*
|
||||
* @author bejson.com (i@bejson.com)
|
||||
* @website http://www.bejson.com/java2pojo/
|
||||
|
|
|
@ -22,6 +22,9 @@ 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.common.dzpzk.bizdata.req.DzpzBizDataBean;
|
||||
import shkd.fi.fi.common.dzpzk.bizdata.req.Evouchers;
|
||||
import shkd.fi.fi.common.dzpzk.bizdata.req.JournalHeads;
|
||||
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;
|
||||
|
@ -63,6 +66,7 @@ public class DzpzkOPPlugin extends AbstractOperationServicePlugIn {
|
|||
queryGuidangResult(e);
|
||||
break;
|
||||
case "shkd_dzpzk_biz":
|
||||
synBizData(e);
|
||||
break;
|
||||
case "shkd_dzpzk_biz_res":
|
||||
break;
|
||||
|
@ -351,24 +355,11 @@ public class DzpzkOPPlugin extends AbstractOperationServicePlugIn {
|
|||
String fileHexString = "";
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
FileServiceFactory.getAttachmentFileService().download(url,out,null);
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(out.toByteArray());
|
||||
|
||||
try {
|
||||
byte[] data = new byte[bis.available()];
|
||||
bis.read(data);
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (byte b : data) {
|
||||
String hex = Integer.toHexString(0xff & b);
|
||||
if (hex.length() == 1) {
|
||||
hexString.append('0');
|
||||
}
|
||||
hexString.append(hex);
|
||||
}
|
||||
fileHexString = hexString.toString();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
// ByteArrayInputStream bis = new ByteArrayInputStream(out.toByteArray());
|
||||
// byte[] data = new byte[bis.available()];
|
||||
// bis.read(data);
|
||||
byte[] bytes = out.toByteArray();
|
||||
fileHexString = FileUtils.byteArrToHexString(bytes);
|
||||
// String fileHexString = FileUtils.fileToHex((FileInputStream)inputStream);
|
||||
String name = (String)attach.get("name");
|
||||
Long size = (Long)attach.get("size");
|
||||
|
@ -385,6 +376,65 @@ public class DzpzkOPPlugin extends AbstractOperationServicePlugIn {
|
|||
}
|
||||
return elements;
|
||||
}
|
||||
private static List<Evouchers> buildBizDataElements(DynamicObject[] sourcebillid, String org_shkd_sap_number, DynamicObject org, DynamicObject voucher, List<Evouchers> evouchers) {
|
||||
DynamicObject[] ap_finapbillObjects = sourcebillid;
|
||||
for (DynamicObject apBillObj : ap_finapbillObjects) {
|
||||
DynamicObjectCollection inventry = apBillObj.getDynamicObjectCollection("shkd_inventry");
|
||||
for (DynamicObject apInvoice: inventry) {
|
||||
Evouchers evoucher = new Evouchers();
|
||||
evoucher.setEvcTypeCode("EINV");
|
||||
shkd.fi.fi.common.dzpzk.bizdata.req.Attr attr = new shkd.fi.fi.common.dzpzk.bizdata.req.Attr();
|
||||
|
||||
DynamicObject shkd_invoicereceipt = apInvoice.getDynamicObject("shkd_invoicereceipt");//发票识别单
|
||||
DynamicObject invoiceBill = BusinessDataServiceHelper.loadSingle(shkd_invoicereceipt.getPkValue(), "shkd_invoicereceipt");
|
||||
|
||||
attr.setInvoiceNumber(invoiceBill.getString("shkd_invoiceno"));
|
||||
attr.setInvoiceType("");
|
||||
attr.setContractNumber("");
|
||||
attr.setAssetsDepreciationMethod("");
|
||||
attr.setSecurityFlag("");
|
||||
attr.setEntryAccountFlag("1");
|
||||
attr.setUsedFlag("1");
|
||||
// attr.setUsedConfirmation();
|
||||
attr.setUsedPeriod(DateUtils.format(invoiceBill.getDate("shkd_invoicedate"),DateUtils.COMPACT_YY_MM));//2024-07
|
||||
|
||||
attr.setPaidFlag("");
|
||||
attr.setBankElectronicReceipt("");
|
||||
attr.setTransferFlag("0");
|
||||
attr.setTransferAmount("0");
|
||||
attr.setIncomeTaxDeduct("");
|
||||
attr.setIncomeTaxYearFrom("");
|
||||
attr.setIncomeTaxYearTo("");
|
||||
attr.setExpensePeriodFrom("");
|
||||
attr.setExpensePeriodTo("");
|
||||
attr.setInvoiceType("02");
|
||||
attr.setPurchaserName("");
|
||||
attr.setPurchaserTaxNumber("");
|
||||
|
||||
attr.setCompanyCode(org_shkd_sap_number);
|
||||
attr.setSysDocNumber(voucher.getString("billno"));
|
||||
|
||||
|
||||
List<JournalHeads> journalHeads = new ArrayList<JournalHeads>();
|
||||
JournalHeads jh = new JournalHeads();
|
||||
jh.setAccEntityCode(org_shkd_sap_number);
|
||||
jh.setJournalNumber(voucher.getString("shkd_belnr"));
|
||||
jh.setAccountDate(DateUtils.format(voucher.getDate("bookeddate"),DateUtils.COMPACT_YY_MM_DD));
|
||||
jh.setAccountPeriod(DateUtils.format(voucher.getDate("bookeddate"),DateUtils.COMPACT_YY_MM));
|
||||
jh.setAccountYear(DateUtils.format(voucher.getDate("bookeddate"),DateUtils.COMPACT_YEAR));
|
||||
jh.setJournalSummary("");
|
||||
journalHeads.add(jh);
|
||||
attr.setJournalHeads(journalHeads);
|
||||
|
||||
evoucher.setAttr(attr);
|
||||
evouchers.add(evoucher);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return evouchers;
|
||||
}
|
||||
|
||||
public void queryGuidangResult(AfterOperationArgs e){
|
||||
//1.校验,不满足条件的凭证,移除,不传输
|
||||
|
@ -564,12 +614,233 @@ 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");
|
||||
|
||||
DzpzBizDataBean bizDataBean = new DzpzBizDataBean();
|
||||
shkd.fi.fi.common.dzpzk.bizdata.req.Head head = new shkd.fi.fi.common.dzpzk.bizdata.req.Head();
|
||||
head.setRequestNo(requstNo);
|
||||
head.setRequestTime(requstTime);
|
||||
head.setSourceSys(AppflgConstant.SYS_NUMBER);
|
||||
bizDataBean.setHead(head);
|
||||
|
||||
shkd.fi.fi.common.dzpzk.bizdata.req.Body body = new shkd.fi.fi.common.dzpzk.bizdata.req.Body();
|
||||
List<Evouchers> evouchers = new ArrayList<>();
|
||||
|
||||
//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);
|
||||
buildBizDataElements(BusinessDataServiceHelper.load(apBillIdList.toArray(), dynamicObject.getDynamicObjectType()), org_shkd_sap_number, org, voucher, evouchers);
|
||||
}else if(ap_finapbill.equals(number)){//来源单据是财务应付单
|
||||
buildBizDataElements(BusinessDataServiceHelper.load(new Long[]{sourcebillid}, dynamicObject.getDynamicObjectType()), org_shkd_sap_number, org, voucher, evouchers);
|
||||
}
|
||||
}
|
||||
|
||||
body.setEvouchers(evouchers);
|
||||
bizDataBean.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 {
|
||||
Map<String, String> hd = new HashMap<>();
|
||||
Map<String, Object> bd = new HashMap<>();
|
||||
String dzpzkTokenURL = AppflgConstant.getDzpzkTokenURL();
|
||||
String getTokenResult = HttpClientUtils.post(dzpzkTokenURL, hd,bd);
|
||||
LogBillUtils.SaveLogBill(dzpzkTokenURL, 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 url = System.getProperty(AppflgConstant.SHKD_DZPZK_BIZ_URL);
|
||||
Map<String, String> header = new HashMap<String, String>();
|
||||
header.put("Authorization","Bearer "+token);
|
||||
String jsonBody = JSONObject.toJSONString(bizDataBean);
|
||||
String postjson = HttpClientUtils.postjson(url, header, jsonBody);
|
||||
LogBillUtils.SaveLogBill(url, 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);
|
||||
}
|
||||
|
||||
public void queryBizDataResult(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;
|
||||
}
|
||||
voucherColl.add(voucher);
|
||||
}
|
||||
//数据校验不通过,则不进行同步
|
||||
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 = voucher.getString("shkd_gd_reqno");
|
||||
//同步
|
||||
//1.缓存有token 则取缓存里的token
|
||||
//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 {
|
||||
Map<String, String> hd = new HashMap<>();
|
||||
Map<String, Object> bd = new HashMap<>();
|
||||
String dzpzkTokenURL = AppflgConstant.getDzpzkTokenURL();
|
||||
String getTokenResult = HttpClientUtils.post(dzpzkTokenURL, hd,bd);
|
||||
LogBillUtils.SaveLogBill(dzpzkTokenURL, 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 url = System.getProperty(AppflgConstant.SHKD_DZPZK_BIZ_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(url, header, jsonBody);
|
||||
LogBillUtils.SaveLogBill(url, postjson, AppflgConstant.SHKD_DZPZK_BIZ_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 static void updateVoucher (DynamicObject voucher,Item item) {
|
||||
String zstatus = item.getZstatus();
|
||||
String packgid = item.getPackgid();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
package shkd.fi.fi.util;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -60,4 +61,31 @@ public class FileUtils {
|
|||
}
|
||||
return hexString;
|
||||
}
|
||||
|
||||
|
||||
// 将字节转换为16进制字符串
|
||||
private static String bytesToHex(byte[] bytes) {
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (byte b : bytes) {
|
||||
String hex = Integer.toHexString(0xff & b);
|
||||
if (hex.length() == 1) {
|
||||
hexString.append('0');
|
||||
}
|
||||
hexString.append(hex);
|
||||
}
|
||||
return hexString.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 字节数组转16进制字符串
|
||||
* @param b
|
||||
* @return
|
||||
*/
|
||||
public static String byteArrToHexString(byte[] b){
|
||||
String result="";
|
||||
for (int i=0; i < b.length; i++) {
|
||||
result += Integer.toString( ( b[i] & 0xff ) + 0x100, 16).substring(1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue