Compare commits

...

2 Commits

Author SHA1 Message Date
刘鹏 b7f3a037fc 1.全电发票业务场景处理;
2.企微单点登录;
2024-08-23 20:13:41 +08:00
刘鹏 003fb6c7f6 add dzpzk code 2024-08-13 14:16:06 +08:00
9 changed files with 529 additions and 66 deletions

View File

@ -146,5 +146,9 @@ public class AppflgConstant {
map.get(AppflgConstant.DZPZK_PASSWORD); map.get(AppflgConstant.DZPZK_PASSWORD);
} }
/**
* 系统主机端口
*/
public static final String KINGDEE_HOST = "kingdee_host";
} }

View File

@ -0,0 +1,31 @@
package shkd.fi.fi.common.orc;
public class FullElecInvoiceBean {
private String fileName;
private String invoiceNo;
private String fileType;
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getInvoiceNo() {
return invoiceNo;
}
public void setInvoiceNo(String invoiceNo) {
this.invoiceNo = invoiceNo;
}
public String getFileType() {
return fileType;
}
public void setFileType(String fileType) {
this.fileType = fileType;
}
}

View File

@ -0,0 +1,26 @@
package shkd.fi.fi.common.orc;
import kd.bos.dataentity.entity.DynamicObject;
import java.util.Map;
public class InvoiceDyobjDataBean {
private DynamicObject shkd_invoicereceipt;
private Map<String, Object> attachmentDatum;
public DynamicObject getShkd_invoicereceipt() {
return shkd_invoicereceipt;
}
public void setShkd_invoicereceipt(DynamicObject shkd_invoicereceipt) {
this.shkd_invoicereceipt = shkd_invoicereceipt;
}
public Map<String, Object> getAttachmentDatum() {
return attachmentDatum;
}
public void setAttachmentDatum(Map<String, Object> attachmentDatum) {
this.attachmentDatum = attachmentDatum;
}
}

View File

@ -33,10 +33,7 @@ import kd.bos.util.FileNameUtils;
import kd.bos.util.HttpClientUtils; import kd.bos.util.HttpClientUtils;
import kd.bos.util.StringUtils; import kd.bos.util.StringUtils;
import shkd.fi.fi.common.AppflgConstant; import shkd.fi.fi.common.AppflgConstant;
import shkd.fi.fi.common.orc.DetailList; import shkd.fi.fi.common.orc.*;
import shkd.fi.fi.common.orc.ErrorResponse;
import shkd.fi.fi.common.orc.OCRRetureData;
import shkd.fi.fi.common.orc.Response;
import shkd.fi.fi.util.LogBillUtils; import shkd.fi.fi.util.LogBillUtils;
import shkd.fi.fi.util.ParamsUtils; import shkd.fi.fi.util.ParamsUtils;
@ -77,14 +74,13 @@ public class UploadAttachmentsFormPlugin extends AbstractFormPlugin {
public void click(EventObject evt) { public void click(EventObject evt) {
super.click(evt); super.click(evt);
Button source = (Button) evt.getSource(); Button source = (Button) evt.getSource();
if (Objects.equals("btnok", source.getKey())) {
this.getView().close();
}
//获取上传附件信息 //获取上传附件信息
AttachmentPanel shkd_attachmentpanelap = this.getView().getControl("shkd_attachmentpanelap"); AttachmentPanel shkd_attachmentpanelap = this.getView().getControl("shkd_attachmentpanelap");
List<Map<String, Object>> attachmentData = shkd_attachmentpanelap.getAttachmentData(); List<Map<String, Object>> attachmentData = shkd_attachmentpanelap.getAttachmentData();
if (attachmentData.isEmpty()) { if (attachmentData.isEmpty()) {
this.getView().showMessage("请上传附件"); this.getView().showMessage("请上传附件");
return;
} }
FormShowParameter formShowParameter = this.getView().getFormShowParameter(); FormShowParameter formShowParameter = this.getView().getFormShowParameter();
//财务应付单 id //财务应付单 id
@ -146,8 +142,12 @@ public class UploadAttachmentsFormPlugin extends AbstractFormPlugin {
log.info(e.getMessage()); log.info(e.getMessage());
throw new RuntimeException(e); throw new RuntimeException(e);
} }
Map<String, FullElecInvoiceBean> fullElecFileContisXmlMap = new HashMap<String,FullElecInvoiceBean>();
List<DynamicObject> returnDataList = new ArrayList<>();
List<DynamicObject> returnDataList = new ArrayList<DynamicObject>();
List<InvoiceDyobjDataBean> invoiceDyobjDataBeanList = new ArrayList<InvoiceDyobjDataBean>();
//循环遍历附件信息 //循环遍历附件信息
for (Map<String, Object> attachmentDatum : attachmentData) { for (Map<String, Object> attachmentDatum : attachmentData) {
//1.1.OCR发票识别接口请求头 //1.1.OCR发票识别接口请求头
@ -158,8 +158,10 @@ public class UploadAttachmentsFormPlugin extends AbstractFormPlugin {
JSONObject ocrScannerBody = new JSONObject(); JSONObject ocrScannerBody = new JSONObject();
//临时附件url //临时附件url
String attachmentUrl = (String) attachmentDatum.get("url"); String attachmentUrl = (String) attachmentDatum.get("url");
String fileName = (String)attachmentDatum.get("name");//附件名称
//文件服务器 附件url //文件服务器 附件url
String url = uploadTempfile(attachmentUrl, (String) attachmentDatum.get("name")); String url = uploadTempfile(attachmentUrl, fileName);
attachmentDatum.put("url", url); attachmentDatum.put("url", url);
attachmentDatum.put("modifytime", new Date().getTime()); attachmentDatum.put("modifytime", new Date().getTime());
@ -200,6 +202,7 @@ public class UploadAttachmentsFormPlugin extends AbstractFormPlugin {
LogBillUtils.SaveLogBill(ocr_invoicescanner_url, postjson, "OCR识别接口", ocrScannerBody.toString()); LogBillUtils.SaveLogBill(ocr_invoicescanner_url, postjson, "OCR识别接口", ocrScannerBody.toString());
if (StringUtils.isEmpty(postjson)) { if (StringUtils.isEmpty(postjson)) {
this.getView().showMessage("OCR接口识别失败"); this.getView().showMessage("OCR接口识别失败");
return;
} }
OCRRetureData ocrRetureData = JSONObject.parseObject(postjson, OCRRetureData.class); OCRRetureData ocrRetureData = JSONObject.parseObject(postjson, OCRRetureData.class);
@ -222,6 +225,23 @@ public class UploadAttachmentsFormPlugin extends AbstractFormPlugin {
this.getView().showMessage("发票收票公司和当前应付单结算组织不匹配"); this.getView().showMessage("发票收票公司和当前应付单结算组织不匹配");
return; return;
} }
//add 处理接口 start 0822 1.识别2.处理3.验真
String invoiceNo = response.getInvoiceNo();
String fileType = fileName.substring(fileName.lastIndexOf(".")+1);
if(invoiceNo.length()==20){//全电票发票号码为20位长度
FullElecInvoiceBean fullElecInvoiceBean = fullElecFileContisXmlMap.get(invoiceNo);
if(fullElecInvoiceBean==null){
fullElecInvoiceBean = new FullElecInvoiceBean();
}
fullElecInvoiceBean.setInvoiceNo(invoiceNo);
fullElecInvoiceBean.setFileName(fileName);
if(fileType.toUpperCase().equals("XML")){
fullElecInvoiceBean.setFileType(fileType);
}
fullElecFileContisXmlMap.put(invoiceNo,fullElecInvoiceBean);
}
//add 处理接口 end 0822 1.识别2.处理3.验真
List<DetailList> detailList = response.getDetailList(); List<DetailList> detailList = response.getDetailList();
BigDecimal shkd_tax = BigDecimal.ZERO;//税额 BigDecimal shkd_tax = BigDecimal.ZERO;//税额
BigDecimal shkd_amount = BigDecimal.ZERO;//金额 BigDecimal shkd_amount = BigDecimal.ZERO;//金额
@ -271,7 +291,8 @@ public class UploadAttachmentsFormPlugin extends AbstractFormPlugin {
this.getView().showMessage(message); this.getView().showMessage(message);
return; return;
} }
this.getView().showMessage("发票已识别验真通过,生成发票明细成功");
//2.5.发票合规查验接口调用成功 生成发票识别单据 //2.5.发票合规查验接口调用成功 生成发票识别单据
DynamicObject shkd_invoicereceipt = BusinessDataServiceHelper.newDynamicObject("shkd_invoicereceipt"); DynamicObject shkd_invoicereceipt = BusinessDataServiceHelper.newDynamicObject("shkd_invoicereceipt");
shkd_invoicereceipt.set("billno", String.valueOf(System.currentTimeMillis())); shkd_invoicereceipt.set("billno", String.valueOf(System.currentTimeMillis()));
@ -315,20 +336,56 @@ public class UploadAttachmentsFormPlugin extends AbstractFormPlugin {
shkd_invoicereceipt.set("billstatus", "C"); shkd_invoicereceipt.set("billstatus", "C");
shkd_invoicereceipt.set("creator", RequestContext.get().getCurrUserId()); shkd_invoicereceipt.set("creator", RequestContext.get().getCurrUserId());
// option.setVariableValue(OperateOptionConst.ORM_SAVEOP_REMOVECACHE, "true"); // option.setVariableValue(OperateOptionConst.ORM_SAVEOP_REMOVECACHE, "true");
//保存发票识别单据并上传发票附件到发票识别单据 //保存发票识别单据并上传发票附件到发票识别单据
// SaveServiceHelper.save(new DynamicObject[]{shkd_invoicereceipt}, option);
// List<Map<String, Object>> attachmentDataList = new ArrayList<>();
// attachmentDataList.add(attachmentDatum);
// AttachmentServiceHelper.upload("shkd_invoicereceipt", shkd_invoicereceipt.getPkValue(),
// "attachmentpanel", attachmentDataList);
//先把附件放这里
InvoiceDyobjDataBean invoiceDyobjDataBean = new InvoiceDyobjDataBean();
invoiceDyobjDataBean.setShkd_invoicereceipt(shkd_invoicereceipt);
invoiceDyobjDataBean.setAttachmentDatum(attachmentDatum);
invoiceDyobjDataBeanList.add(invoiceDyobjDataBean);
} catch (IOException e) {
log.info(e.getMessage());
throw new RuntimeException(e);
}
}
StringBuffer error = new StringBuffer();
if(null!=fullElecFileContisXmlMap&&fullElecFileContisXmlMap.size()>0){
Set<Map.Entry<String, FullElecInvoiceBean>> entries = fullElecFileContisXmlMap.entrySet();
for(Map.Entry<String, FullElecInvoiceBean> fullElecInvoiceBean : entries) {
FullElecInvoiceBean value = fullElecInvoiceBean.getValue();
if(StringUtils.isEmpty(value.getFileType())){
error.append("全电票发票号码:").append(value.getInvoiceNo()).append("附件名称:").append(value.getFileName()).append(" 未上传XML格式附件").append("\r\n");
}
}
}
if(!"".equals(error.toString())){
this.getView().showMessage(error.append("请上传对应XML格式附件").toString());
return;
}
//生成发票识别单
for (int i = 0; i < invoiceDyobjDataBeanList.size(); i++) {
InvoiceDyobjDataBean invoiceDyobjDataBean = invoiceDyobjDataBeanList.get(i);
DynamicObject shkd_invoicereceipt = invoiceDyobjDataBean.getShkd_invoicereceipt();
Map<String, Object> attachmentDatum = invoiceDyobjDataBean.getAttachmentDatum();
//保存发票识别单据并上传发票附件到发票识别单据
SaveServiceHelper.save(new DynamicObject[]{shkd_invoicereceipt}, option); SaveServiceHelper.save(new DynamicObject[]{shkd_invoicereceipt}, option);
List<Map<String, Object>> attachmentDataList = new ArrayList<>(); List<Map<String, Object>> attachmentDataList = new ArrayList<>();
attachmentDataList.add(attachmentDatum); attachmentDataList.add(attachmentDatum);
AttachmentServiceHelper.upload("shkd_invoicereceipt", shkd_invoicereceipt.getPkValue(), AttachmentServiceHelper.upload("shkd_invoicereceipt", shkd_invoicereceipt.getPkValue(),
"attachmentpanel", attachmentDataList); "attachmentpanel", attachmentDataList);
returnDataList.add(shkd_invoicereceipt); returnDataList.add(shkd_invoicereceipt);
} catch (IOException e) {
log.info(e.getMessage());
throw new RuntimeException(e);
}
} }
//回写发票信息到财务应付单发票明细 //回写发票信息到财务应付单发票明细
@ -382,8 +439,12 @@ public class UploadAttachmentsFormPlugin extends AbstractFormPlugin {
} }
} }
//刷新财务应付单 //刷新财务应付单
this.getView().showMessage("发票已识别验真通过,生成发票明细成功");
parentView.invokeOperation("refresh"); parentView.invokeOperation("refresh");
this.getView().sendFormAction(parentView); this.getView().sendFormAction(parentView);
// if (Objects.equals("btnok", source.getKey())) {
this.getView().close();
// }
} }
} }

View File

@ -2,7 +2,9 @@ package shkd.fi.fi.opplugin;
import com.alibaba.druid.support.logging.Log; import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory; import com.alibaba.druid.support.logging.LogFactory;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.grapecity.documents.excel.J;
import kd.bos.cache.CacheFactory; import kd.bos.cache.CacheFactory;
import kd.bos.cache.DistributeSessionlessCache; import kd.bos.cache.DistributeSessionlessCache;
import kd.bos.cache.TempFileCache; import kd.bos.cache.TempFileCache;
@ -84,18 +86,10 @@ public class DzpzkOPPlugin extends AbstractOperationServicePlugIn {
StringBuffer errStr = new StringBuffer(); StringBuffer errStr = new StringBuffer();
DynamicObject[] dataEntities = e.getDataEntities(); DynamicObject[] dataEntities = e.getDataEntities();
for (DynamicObject voucher : dataEntities) { for (DynamicObject glvoucher : dataEntities) {
// DynamicObject voucher = BusinessDataServiceHelper.loadSingle(glvoucher.getPkValue(), "gl_voucher"); DynamicObject voucher = BusinessDataServiceHelper.loadSingle(glvoucher.getPkValue(), "gl_voucher");
String voucherNo = voucher.getString("billno");//凭证号 String voucherNo = voucher.getString("billno");//凭证号
//校验1.单据是否已审核2.是否已同步到SAP //校验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"))){ if(!"1".equals(voucher.getString("shkd_zstatus"))){
errStr.append("凭证号:").append(voucherNo).append("不满足同步条件,原因:"); errStr.append("凭证号:").append(voucherNo).append("不满足同步条件,原因:");
errStr.append(" 凭证未同步到SAP ").append("\r"); errStr.append(" 凭证未同步到SAP ").append("\r");
@ -535,19 +529,21 @@ public class DzpzkOPPlugin extends AbstractOperationServicePlugIn {
String jsonBody = JSONObject.toJSONString(guidangQueryReqBean); String jsonBody = JSONObject.toJSONString(guidangQueryReqBean);
String postjson = HttpClientUtils.postjson(guidangUrl, header, jsonBody); String postjson = HttpClientUtils.postjson(guidangUrl, header, jsonBody);
LogBillUtils.SaveLogBill(guidangUrl, postjson, AppflgConstant.DZPZK_GUIDANG_RES_URL_NAME, jsonBody); LogBillUtils.SaveLogBill(guidangUrl, postjson, AppflgConstant.DZPZK_GUIDANG_RES_URL_NAME, jsonBody);
GuidangQueryResBean guidangResponseBean = JSONObject.parseObject(postjson, GuidangQueryResBean.class); List<GuidangQueryResBean> guidangQueryResBeans = JSONArray.parseArray(postjson, GuidangQueryResBean.class);
if(null!=guidangResponseBean){
if("1".equals(guidangResponseBean.getProcessingResult())){ if(null!=guidangQueryResBeans&&guidangQueryResBeans.size()>0){
GuidangQueryResBean guidangResponseBean = guidangQueryResBeans.get(0);
if(1==guidangResponseBean.getProcessingResult()){
this.operationResult.setShowMessage(true); this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(true); this.operationResult.setSuccess(true);
this.operationResult.setMessage("同步成功,成功生成了归档元素"); this.operationResult.setMessage("同步成功,成功生成了归档元素");
voucher.set("shkd_dzpzkstatus","1");//附件归档成功 voucher.set("shkd_dzpzkstatus","1");//附件归档成功
SaveServiceHelper.save(new DynamicObject[]{voucher}); SaveServiceHelper.save(new DynamicObject[]{voucher});
}else if("0".equals(guidangResponseBean.getProcessingResult())) { }else if(0==guidangResponseBean.getProcessingResult()) {
this.operationResult.setShowMessage(true); this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(true); this.operationResult.setSuccess(true);
this.operationResult.setMessage("电子凭证库系统附件归档结果暂未处理,请稍等查询"); this.operationResult.setMessage("电子凭证库系统附件归档结果暂未处理,请稍等查询");
} else if ("-1".equals(guidangResponseBean.getProcessingResult())) { } else if (-1==guidangResponseBean.getProcessingResult()) {
this.operationResult.setShowMessage(true); this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(false); this.operationResult.setSuccess(false);
this.operationResult.setMessage("电子凭证库系统附件归档结果未生成:"+guidangResponseBean.getErrorMessage()); this.operationResult.setMessage("电子凭证库系统附件归档结果未生成:"+guidangResponseBean.getErrorMessage());
@ -811,7 +807,7 @@ public class DzpzkOPPlugin extends AbstractOperationServicePlugIn {
for (DynamicObject voucher : voucherColl) { for (DynamicObject voucher : voucherColl) {
DynamicObject org = voucher.getDynamicObject("org"); DynamicObject org = voucher.getDynamicObject("org");
String shkd_gd_reqno = voucher.getString("shkd_gd_reqno"); String shkd_pz_reqno = voucher.getString("shkd_pz_reqno");
//同步 //同步
try { try {
String url = AppflgConstant.SHKD_DZPZK_BIZ_RES_URL(paramsMap); String url = AppflgConstant.SHKD_DZPZK_BIZ_RES_URL(paramsMap);
@ -830,31 +826,37 @@ public class DzpzkOPPlugin extends AbstractOperationServicePlugIn {
head.setSourceSys(AppflgConstant.SYS_NUMBER); head.setSourceSys(AppflgConstant.SYS_NUMBER);
guidangQueryReqBean.setHead(head); guidangQueryReqBean.setHead(head);
shkd.fi.fi.common.dzpzk.guidangquery.req.Body body = new shkd.fi.fi.common.dzpzk.guidangquery.req.Body(); shkd.fi.fi.common.dzpzk.guidangquery.req.Body body = new shkd.fi.fi.common.dzpzk.guidangquery.req.Body();
body.setLinkRequestNo(shkd_gd_reqno); body.setLinkRequestNo(shkd_pz_reqno);
guidangQueryReqBean.setBody(body); guidangQueryReqBean.setBody(body);
String jsonBody = JSONObject.toJSONString(guidangQueryReqBean); String jsonBody = JSONObject.toJSONString(guidangQueryReqBean);
String postjson = HttpClientUtils.postjson(url, header, jsonBody); String postjson = HttpClientUtils.postjson(url, header, jsonBody);
LogBillUtils.SaveLogBill(url, postjson, AppflgConstant.SHKD_DZPZK_BIZ_RES_URL_NAME, jsonBody); LogBillUtils.SaveLogBill(url, postjson, AppflgConstant.SHKD_DZPZK_BIZ_RES_URL_NAME, jsonBody);
BizdataQueryResBean bizdataQueryResBean = JSONObject.parseObject(postjson, BizdataQueryResBean.class); // BizdataQueryResBean bizdataQueryResBean = JSONObject.parseObject(postjson, BizdataQueryResBean.class);
if(null==bizdataQueryResBean){ List<BizdataQueryResBean> bizdataQueryResBeans = JSONArray.parseArray(postjson, BizdataQueryResBean.class);
this.operationResult.setShowMessage(true); if(null!=bizdataQueryResBeans&&bizdataQueryResBeans.size()>0){
this.operationResult.setSuccess(false); BizdataQueryResBean bizdataQueryResBean = bizdataQueryResBeans.get(0);
this.operationResult.setMessage("同步失败,电子凭证库系统凭证业务数据归档接口返回结果为空");
}else {
if ("S".equals(bizdataQueryResBean.getProcessingResult())) { if ("S".equals(bizdataQueryResBean.getProcessingResult())) {
this.operationResult.setShowMessage(true); this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(true); this.operationResult.setSuccess(true);
this.operationResult.setMessage("凭证归档同步成功"); this.operationResult.setMessage("凭证归档同步成功");
voucher.set("shkd_dzpzkstatus", "4"); voucher.set("shkd_dzpzkstatus", "4");
SaveServiceHelper.save(new DynamicObject[]{voucher}); SaveServiceHelper.save(new DynamicObject[]{voucher});
} else if("N".equals(bizdataQueryResBean.getProcessingResult())){
this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(true);
this.operationResult.setMessage("电子凭证库系统凭证业务数据归档接口返回结果为:还未处理,请稍后查询");
}else{ }else{
this.operationResult.setShowMessage(true); this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(false); this.operationResult.setSuccess(false);
this.operationResult.setMessage("凭证归档同步失败:"+bizdataQueryResBean.getErrorMessage()); this.operationResult.setMessage("电子凭证库系统凭证业务数据归档接口返回结果为E处理错误请联系管理员");
voucher.set("shkd_dzpzkstatus", "5"); voucher.set("shkd_dzpzkstatus", "5");
SaveServiceHelper.save(new DynamicObject[]{voucher}); SaveServiceHelper.save(new DynamicObject[]{voucher});
} }
}else {
this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(false);
this.operationResult.setMessage("同步失败,电子凭证库系统凭证业务数据归档接口返回结果为空");
} }
} catch (IOException ex) { } catch (IOException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);

View File

@ -14,6 +14,7 @@ import kd.bos.util.StringUtils;
import shkd.fi.fi.common.AppflgConstant; import shkd.fi.fi.common.AppflgConstant;
import shkd.fi.fi.util.DateUtils; import shkd.fi.fi.util.DateUtils;
import shkd.fi.fi.util.HttpUtils; import shkd.fi.fi.util.HttpUtils;
import shkd.fi.fi.util.LogBillUtils;
import shkd.fi.fi.util.ParamsUtils; import shkd.fi.fi.util.ParamsUtils;
import java.util.*; import java.util.*;
@ -49,6 +50,7 @@ public class SynOAInvoiceOPPlugin extends AbstractOperationServicePlugIn {
//1.校验不满足冲销条件的凭证移除不传输校验是否满足冲销条件必须是已同步过SAP的凭证才允许冲销 //1.校验不满足冲销条件的凭证移除不传输校验是否满足冲销条件必须是已同步过SAP的凭证才允许冲销
DynamicObjectCollection voucherColl = new DynamicObjectCollection(); DynamicObjectCollection voucherColl = new DynamicObjectCollection();
StringBuffer errStr = new StringBuffer(); StringBuffer errStr = new StringBuffer();
DynamicObject[] dataEntities = e.getDataEntities();
for (DynamicObject glvoucher : dataEntities) { for (DynamicObject glvoucher : dataEntities) {
DynamicObject voucher = BusinessDataServiceHelper.loadSingle(glvoucher.getPkValue(), "gl_voucher"); DynamicObject voucher = BusinessDataServiceHelper.loadSingle(glvoucher.getPkValue(), "gl_voucher");
String voucherNo = voucher.getString("billno");//凭证号 String voucherNo = voucher.getString("billno");//凭证号
@ -64,13 +66,7 @@ public class SynOAInvoiceOPPlugin extends AbstractOperationServicePlugIn {
this.operationResult.setMessage("数据校验不通过:"+errStr.toString()); this.operationResult.setMessage("数据校验不通过:"+errStr.toString());
break; break;
} }
String shkd_zstatus = voucher.getString("shkd_zstatus");
String shkd_belnr = voucher.getString("shkd_belnr");
if(StringUtils.isEmpty(shkd_zstatus)||StringUtils.isEmpty(shkd_belnr)||!"1".equals(shkd_belnr)){
errStr.append("凭证号:").append(voucherNo).append("不满足冲销条件,原因:");
errStr.append("凭证未同步到SAP ").append("\r");
break;
}
voucherColl.add(voucher); voucherColl.add(voucher);
} }
//数据校验不通过则不进行同步 //数据校验不通过则不进行同步
@ -86,17 +82,14 @@ public class SynOAInvoiceOPPlugin extends AbstractOperationServicePlugIn {
Map<String, String> paramsMap = ParamsUtils.getParamsMap(); Map<String, String> paramsMap = ParamsUtils.getParamsMap();
String oaurl = AppflgConstant.OA_INV_URL(paramsMap); String oaurl = AppflgConstant.OA_INV_URL(paramsMap);
String crdate = DateUtils.formatDate(new Date(),DateUtils.COMPACT_TIME);
Random random = new Random();
int randomNumber = 1000 + random.nextInt(9000); // 生成1000到9999之间的随机数
String time_random = crdate+""+ randomNumber;
for (DynamicObject gl_voucher : voucherColl) { for (DynamicObject gl_voucher : voucherColl) {
DynamicObject org = gl_voucher.getDynamicObject("org"); DynamicObject voucher = BusinessDataServiceHelper.loadSingle(gl_voucher.getPkValue(), "gl_voucher");
DynamicObject org = voucher.getDynamicObject("org");
String shkd_oa_orgid = org.getString("shkd_oa_orgid"); String shkd_oa_orgid = org.getString("shkd_oa_orgid");
String shkd_belnr = gl_voucher.getString("shkd_belnr");//sap凭证号 String shkd_belnr = voucher.getString("shkd_belnr");//sap凭证号
//DAP关系 //DAP关系
QFilter filter = new QFilter("voucherid", QCP.equals,gl_voucher.getPkValue()); QFilter filter = new QFilter("voucherid", QCP.equals,voucher.getPkValue());
List<String> billTypeList = new ArrayList<String>(); List<String> billTypeList = new ArrayList<String>();
billTypeList.add(im_purinbill); billTypeList.add(im_purinbill);
billTypeList.add(ap_finapbill); billTypeList.add(ap_finapbill);
@ -112,10 +105,10 @@ public class SynOAInvoiceOPPlugin extends AbstractOperationServicePlugIn {
if(im_purinbill.equals(number)){//来源单据是采购入库单需查询下游单据财务应付单 if(im_purinbill.equals(number)){//来源单据是采购入库单需查询下游单据财务应付单
List<Long> apBillIdList = DzpzkOPPlugin.down(im_purinbill, sourcebillid); List<Long> apBillIdList = DzpzkOPPlugin.down(im_purinbill, sourcebillid);
DynamicObject[] ap_invoices = BusinessDataServiceHelper.load(apBillIdList.toArray(), dynamicObject.getDynamicObjectType()); DynamicObject[] ap_invoices = BusinessDataServiceHelper.load(apBillIdList.toArray(), dynamicObject.getDynamicObjectType());
getSynData(oaurl,ap_invoices, shkd_belnr,shkd_oa_orgid,gl_voucher); getSynData(oaurl,ap_invoices, shkd_belnr,shkd_oa_orgid,voucher);
}else if(ap_finapbill.equals(number)){//来源单据是财务应付单 }else if(ap_finapbill.equals(number)){//来源单据是财务应付单
DynamicObject[] ap_invoices = BusinessDataServiceHelper.load(new Long[]{sourcebillid}, dynamicObject.getDynamicObjectType()); DynamicObject[] ap_invoices = BusinessDataServiceHelper.load(new Long[]{sourcebillid}, dynamicObject.getDynamicObjectType());
getSynData(oaurl,ap_invoices, shkd_belnr,shkd_oa_orgid,gl_voucher); getSynData(oaurl,ap_invoices, shkd_belnr,shkd_oa_orgid,voucher);
} }
} }
@ -219,7 +212,10 @@ public class SynOAInvoiceOPPlugin extends AbstractOperationServicePlugIn {
xml.append("</soapenv:Envelope>"); xml.append("</soapenv:Envelope>");
log.info("OA接口入参"+xml.toString());
String s = HttpUtils.sendPostToOA(oaurl, xml.toString()); String s = HttpUtils.sendPostToOA(oaurl, xml.toString());
log.info("OA接口返回结果"+s);
LogBillUtils.SaveLogBill(oaurl,s,AppflgConstant.OA_INV_URL_NAME,xml.toString());
if (s.contains("id&gt;") && s.contains("&lt;/id")) { if (s.contains("id&gt;") && s.contains("&lt;/id")) {
String id = s.substring(s.indexOf("id&gt;") + 6, s.indexOf("&lt;/id")); String id = s.substring(s.indexOf("id&gt;") + 6, s.indexOf("&lt;/id"));
try { try {
@ -233,18 +229,18 @@ public class SynOAInvoiceOPPlugin extends AbstractOperationServicePlugIn {
} else { } else {
this.operationResult.setShowMessage(true); this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(false); this.operationResult.setSuccess(false);
this.operationResult.setMessage("同步失败:" + xml.toString()); this.operationResult.setMessage("同步失败:" + s);
} }
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
this.operationResult.setShowMessage(true); this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(false); this.operationResult.setSuccess(false);
this.operationResult.setMessage("同步失败:" + xml.toString()); this.operationResult.setMessage("同步失败:" + s);
} }
} else { } else {
this.operationResult.setShowMessage(true); this.operationResult.setShowMessage(true);
this.operationResult.setSuccess(false); this.operationResult.setSuccess(false);
this.operationResult.setMessage("同步失败:" + xml.toString()); this.operationResult.setMessage("同步失败:" + s);
} }
} }

View File

@ -2,7 +2,6 @@ package shkd.fi.fi.opplugin;
import com.alibaba.druid.support.logging.Log; import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory; import com.alibaba.druid.support.logging.LogFactory;
import com.alibaba.fastjson.JSONObject;
import com.sap.db.jdbc.packet.ErrorLevel; import com.sap.db.jdbc.packet.ErrorLevel;
import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.dataentity.entity.DynamicObjectCollection;
@ -16,9 +15,7 @@ import kd.bos.servicehelper.QueryServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper; import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.bos.util.StringUtils; import kd.bos.util.StringUtils;
import shkd.fi.fi.common.AppflgConstant; import shkd.fi.fi.common.AppflgConstant;
import shkd.fi.fi.sap.*;
import shkd.fi.fi.sap.requst.docuentif.*; import shkd.fi.fi.sap.requst.docuentif.*;
import shkd.fi.fi.sap.result.docuentif.Data;
import shkd.fi.fi.sap.result.docuentif.Item; import shkd.fi.fi.sap.result.docuentif.Item;
import shkd.fi.fi.sap.result.docuentif.MTDocumentIFRet; import shkd.fi.fi.sap.result.docuentif.MTDocumentIFRet;
import shkd.fi.fi.util.HttpUtils; import shkd.fi.fi.util.HttpUtils;
@ -27,7 +24,6 @@ import shkd.fi.fi.util.ParamsUtils;
import shkd.fi.fi.util.XmlUtils; import shkd.fi.fi.util.XmlUtils;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -253,7 +249,7 @@ public class SynchronizaSapOPPlugin extends AbstractOperationServicePlugIn {
} }
//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 = AppflgConstant.SYS_NUMBER(paramsMap) + date.getTime(); String packgid = AppflgConstant.SYS_NUMBER(paramsMap) + date.getTime();
//6.数据状态T测试运行P正式运行(ZFLAG)--固定传T //6.数据状态T测试运行P正式运行(ZFLAG)--固定传T
@ -284,7 +280,7 @@ public class SynchronizaSapOPPlugin extends AbstractOperationServicePlugIn {
//19.按本位币计的金额(DMBTR)----原币金额(oriamount) //19.按本位币计的金额(DMBTR)----原币金额(oriamount)
//20.项目文本(SGTXT)----凭证行摘要(edescription) //20.项目文本(SGTXT)----凭证行摘要(edescription)
//21.成本中心(KOSTL)----金蝶核算维度成本中心SAP编码() //21.成本中心(KOSTL)----金蝶核算维度成本中心SAP编码()
List<DT_DOCUMENT_IF_SRCDATAIT_ITEM> itemsList = new ArrayList<>(); List<DT_DOCUMENT_IF_SRCDATAIT_ITEM> itemsList = new ArrayList<DT_DOCUMENT_IF_SRCDATAIT_ITEM>();
for (DynamicObject entry : entries) { for (DynamicObject entry : entries) {
DT_DOCUMENT_IF_SRCDATAIT_ITEM items1 = new DT_DOCUMENT_IF_SRCDATAIT_ITEM(); DT_DOCUMENT_IF_SRCDATAIT_ITEM items1 = new DT_DOCUMENT_IF_SRCDATAIT_ITEM();

View File

@ -0,0 +1,193 @@
package shkd.fi.fi.sso;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.utils.ObjectUtils;
import kd.bos.dc.api.model.Account;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.login.thirdauth.ThirdSSOAuthHandler;
import kd.bos.login.thirdauth.UserAuthResult;
import kd.bos.login.thirdauth.UserProperType;
import kd.bos.login.thirdauth.app.UserType;
import kd.bos.login.thirdauth.app.tencent.WxqyhUtils;
import kd.bos.login.utils.StringUtils;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import static kd.bos.login.thirdauth.UserProperType.Email;
import static kd.bos.login.thirdauth.UserProperType.WorkerNumber;
/**
* @ClassName OtherSysSSOAuth
* @Author zb
* @Description TODO
* @Date 2022/2/21 15:09
**/
public class OtherSysSSOAuth implements ThirdSSOAuthHandler {
private static Log logger = LogFactory.getLog(OtherSysSSOAuth.class);
private static String ERROR_USER = "errorUser";
/**
* @Author zb
* @Description 该方法是用户没有登录的时候插件需要转移到正确的登录地址
* @Date 15:10 2022/2/21
* @Param [request, response, s]
* @return void
**/
@Override
public void callTrdSSOLogin(HttpServletRequest request, HttpServletResponse response, String s) {
//用户需要登录的地址
String requestURL = URLEncoder.encode(request.getRequestURL().toString()) ;
String loginUrl = "http://10.13.11.210/ierp/login.html?redirect="+requestURL;
try {
response.sendRedirect(loginUrl);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* @Author zb
* @Description 该方法实现第三发插件认证及认证结果的返回
* @Date 15:10 2022/2/21
* @Param [httpServletRequest, httpServletResponse]
* @return kd.bos.login.thirdauth.UserAuthResult
**/
@Override
public UserAuthResult getTrdSSOAuth(HttpServletRequest request, HttpServletResponse response) {
UserAuthResult result = new UserAuthResult();
result.setSucess(false);
logger.info("getTrdSSOAuth apptype:"+request.getRequestURL());
String app_type = request.getParameter("apptype");
logger.info("getTrdSSOAuth apptype:"+app_type);
if (StringUtils.isEmpty(app_type)) {
logger.error("##1:wxqyh login: url not have params apptype !");
return result;
} else {
String code = request.getParameter("code");
logger.info("getTrdSSOAuth code:"+code);
if (StringUtils.isEmpty(code)) {
logger.error("##2:wxqyh login: url not have params code !");
return result;
} else {
String corpId = request.getParameter("corpid");
logger.info("getTrdSSOAuth corpId:"+corpId);
if (StringUtils.isEmpty(corpId)) {
corpId = request.getParameter("eid");
logger.info("getTrdSSOAuth eid:"+corpId);
if (StringUtils.isEmpty(corpId)) {
logger.error("##3:wxqyh login: url not have params corpId !");
return result;
}
}
String agentId = request.getParameter("agentid");
logger.info("getTrdSSOAuth agentId:"+agentId);
if (StringUtils.isEmpty(agentId)) {
logger.error("##4:wxqyh login: url not have params agentId !");
return result;
} else {
logger.info("wxqyhcorpId is " + corpId);
logger.info("wxqyhagentId is " + agentId);
String corpSecret = StringUtils.getTrimedBlank(this.getCorpSecret(corpId, agentId));
if (StringUtils.isEmpty(corpSecret)) {
logger.error("##5:wxqyh login: corpSecret is null !");
return result;
} else {
corpSecret = corpSecret.trim();
String accessToken = WxqyhUtils.getAccess_token(corpId, corpSecret, null);
if (StringUtils.isEmpty(accessToken)) {
logger.error("##6:wxqyh login: access_token is null !");
return result;
} else {
logger.info("wxqyh: code is : " + code);
String userId = null;
Map<String, Object> wxUserByCode = null;
if (app_type.equalsIgnoreCase("wxqyh")) {
wxUserByCode = WxqyhUtils.getUserByCode(accessToken, code, null);
if(null==wxUserByCode){
logger.error("##7:wxqyh login: WxqyhUtils.getUserByCode return null ");
}
userId = WxqyhUtils.getUserId(wxUserByCode);
} else if (app_type.equalsIgnoreCase("wxqyhxcx")) {
userId = WxqyhUtils.getUserIdByMicroWx(accessToken, code, null);
}
if (StringUtils.isEmpty(userId)) {
logger.info("##8:wxqyh login: userId is null !");
return result;
} else {
String userTicket = null;
HashMap<String, Object> userMap = null;
if (wxUserByCode != null && wxUserByCode.size() > 0) {
userTicket = WxqyhUtils.getUserTicket(wxUserByCode);
logger.info("##9:wxqyh login: userTicket is null !");
}
if (StringUtils.isNotEmpty(userTicket)) {
logger.info("##10:wxqyh login: userTicket is not null ,to WxqyhUtils.getUserInfoByTicket !");
userMap = WxqyhUtils.getUserInfoByTicket(accessToken, userTicket);
} else {
logger.info("##11:wxqyh login: userTicket is null ,to WxqyhUtils.getUserInfo !");
userMap = WxqyhUtils.getUserInfo(accessToken, userId, null);
}
// if(StringUtils.isEmpty(userTicket)){
// userMap = WxqyhUtils.getUserInfoByTicket(accessToken, userTicket);
// }
if (null == userMap) {
logger.info("##11:wxqyh loginget user info is error");
return result;
} else if (userMap.get("errcode") != null && !userMap.get("errcode").toString().equals("0")) {
logger.info("##12:wxqyh loginget user info is error " + userMap.get("errmsg"));
return result;
} else {
// Object mobile = userMap.get("mobile");
Object email = userMap.get("email");
logger.info("##13:wxqyh loginfrom userMap to get email:"+email);
// Object qywxhUserid = userMap.get("userid");
// logger.info("##14:wxqyh loginfrom userMap to get qywxhUserid:"+qywxhUserid);
// String wxqyhMode = request.getParameter("wxqyhMode");
if (ObjectUtils.isEmpty(email)) {
logger.info("##16:wxqyh loginemail is null !");
return result;
}
result.setUserType(Email);
result.setUser(email.toString());
result.setSucess(true);
return result;
}
}
}
}
}
}
}
}
private String getCorpSecret(String corpId, String agentId) {
DynamicObject[] load = BusinessDataServiceHelper.load("cts_wxqyh", "corpsecret", new QFilter[]{new QFilter("corpid", "=", corpId), new QFilter("agentid", "=", agentId)});
if (null != load && load.length > 0) {
DynamicObject dynamicObject = load[0];
return dynamicObject.getString("corpsecret");
} else {
return null;
}
}
}

View File

@ -0,0 +1,154 @@
package shkd.fi.fi.sso;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.utils.ObjectUtils;
import kd.bos.dc.api.model.Account;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.login.thirdauth.app.AppAuthResult;
import kd.bos.login.thirdauth.app.ThirdAppAuthtication;
import kd.bos.login.thirdauth.app.UserType;
import kd.bos.login.thirdauth.app.tencent.WxqyhUtils;
import kd.bos.login.utils.StringUtils;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
public class WxqyhAuthtication extends ThirdAppAuthtication {
private static final String ERRMSG = "errmsg";
private static Log logger = LogFactory.getLog(WxqyhAuthtication.class);
private static final Integer QYWX_TIME_OUT = 120;
public WxqyhAuthtication() {
}
public boolean isNeedHandle(HttpServletRequest request, Account currentCenter) {
String app_type = request.getParameter("apptype");
if (StringUtils.isEmpty(app_type)) {
return false;
} else {
return app_type.equalsIgnoreCase("wxqyh") || app_type.equalsIgnoreCase("wxqyhxcx") ;
}
}
public AppAuthResult appAuthtication(HttpServletRequest request, Account currentCenter) {
AppAuthResult result = new AppAuthResult();
result.setSucceed(false);
String app_type = request.getParameter("apptype");
if (StringUtils.isEmpty(app_type)) {
return result;
} else {
String code = request.getParameter("code");
if (StringUtils.isEmpty(code)) {
return result;
} else {
String corpId = request.getParameter("corpid");
if (StringUtils.isEmpty(corpId)) {
corpId = request.getParameter("eid");
if (StringUtils.isEmpty(corpId)) {
logger.error("wxqyh login: not corpId !");
return result;
}
}
String agentId = request.getParameter("agentid");
if (StringUtils.isEmpty(agentId)) {
logger.error("wxqyh login: not agentId !");
return result;
} else {
logger.info("wxqyhcorpId is " + corpId);
logger.info("wxqyhagentId is " + agentId);
String corpSecret = StringUtils.getTrimedBlank(this.getCorpSecret(corpId, agentId, currentCenter));
if (StringUtils.isEmpty(corpSecret)) {
logger.error("wxqyh login: corpSecret is null !");
return result;
} else {
corpSecret = corpSecret.trim();
String accessToken = WxqyhUtils.getAccess_token(corpId, corpSecret, currentCenter);
if (StringUtils.isEmpty(accessToken)) {
logger.info("wxqyhaccess_token is null !");
result.setErrorMessage("wxqyhaccess_token is null !");
return result;
} else {
logger.info("wxqyh: code is : " + code);
String userId = null;
Map<String, Object> wxUserByCode = null;
if (app_type.equalsIgnoreCase("wxqyh")) {
wxUserByCode = WxqyhUtils.getUserByCode(accessToken, code, currentCenter);
userId = WxqyhUtils.getUserId(wxUserByCode);
} else if (app_type.equalsIgnoreCase("wxqyhxcx")) {
userId = WxqyhUtils.getUserIdByMicroWx(accessToken, code, currentCenter);
}
if (StringUtils.isEmpty(userId)) {
logger.info("wxqyhuserId is null !");
result.setErrorMessage("userId is null !");
return result;
} else {
String userTicket = null;
HashMap<String, Object> userMap = null;
if (wxUserByCode != null && wxUserByCode.size() > 0) {
userTicket = WxqyhUtils.getUserTicket(wxUserByCode);
}
if (StringUtils.isNotEmpty(userTicket)) {
userMap = WxqyhUtils.getUserInfoByTicket(accessToken, userTicket);
} else {
userMap = WxqyhUtils.getUserInfo(accessToken, userId, currentCenter);
}
if (null == userMap) {
logger.info("wxqyhget user info is error");
result.setErrorMessage("wxqyhget user info is error");
return result;
} else if (userMap.get("errcode") != null && !userMap.get("errcode").toString().equals("0")) {
logger.info("wxqyhget user info is error " + userMap.get("errmsg"));
result.setErrorMessage("wxqyhget user info is error, " + userMap.get("errmsg"));
return result;
} else {
String userFlag = "";
Object mobile = userMap.get("mobile");
Object qywxhUserid = userMap.get("userid");
String wxqyhMode = request.getParameter("wxqyhMode");
if (ObjectUtils.isEmpty(mobile) && !ObjectUtils.isEmpty(qywxhUserid)) {
result.setErrorMessage("wxqyh用户手机号不正确 !");
return result;
} else {
userFlag = mobile.toString();
result.setUserType(UserType.MOBILE_PHONE);
}
if (StringUtils.isEmpty(userFlag)) {
logger.info("wxqyhuser userFlag is null ! ");
result.setErrorMessage("wxqyhuser userFlag is null !");
return result;
} else {
result.setSucceed(true);
result.setAppType(request.getParameter("apptype"));
result.setUserFlag(userFlag);
return result;
}
}
}
}
}
}
}
}
}
private String getCorpSecret(String corpId, String agentId, Account currentCenter) {
DynamicObject[] load = BusinessDataServiceHelper.load("cts_wxqyh", "corpsecret", new QFilter[]{new QFilter("corpid", "=", corpId), new QFilter("agentid", "=", agentId)});
if (null != load && load.length > 0) {
DynamicObject dynamicObject = load[0];
return dynamicObject.getString("corpsecret");
} else {
return null;
}
}
}