Merge remote-tracking branch 'origin/master'

This commit is contained in:
yuxueliang0813 2024-09-18 14:34:38 +08:00
commit d6284cb8a6
5 changed files with 571 additions and 133 deletions

View File

@ -13,14 +13,17 @@ import kd.bos.openapi.common.result.CustomApiResult;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.QueryServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.bos.util.StringUtils;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* @author weiyunlong
* @date Created 2024/8/30 14:22
* @description合同签署流程回调接口(e签宝接口文档 3.6.2.1)
* 合同签署流程回调接口(e签宝接口文档 3.6.2.1)
*/
@ -33,6 +36,7 @@ public class SignTechnologCallbackController implements Serializable {
CustomApiResult customApiResult = new CustomApiResult();
JSONObject jsonObject = JSONObject.parseObject(str);
//回调通知数据体
JSONObject callBackProcessVO = (JSONObject)jsonObject.get("callBackProcessVO");
if (null != callBackProcessVO) {

View File

@ -3,27 +3,42 @@ package shkd.repc.recon.formplugin;
import com.grapecity.documents.excel.D;
import kd.bos.bill.BillShowParameter;
import kd.bos.bill.OperationStatus;
import kd.bos.cache.CacheFactory;
import kd.bos.cache.TempFileCache;
import kd.bos.coderule.api.CodeRuleInfo;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.fileservice.FileServiceFactory;
import kd.bos.form.CloseCallBack;
import kd.bos.form.ShowType;
import kd.bos.form.control.Control;
import kd.bos.form.control.EntryGrid;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.form.operate.FormOperate;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.AttachmentDto;
import kd.bos.servicehelper.AttachmentServiceHelper;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.coderule.CodeRuleServiceHelper;
import kd.bos.servicehelper.operation.DeleteServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import java.math.BigDecimal;
import java.io.*;
import java.util.List;
import java.util.Map;
/**
* 付款申请单表单插件
* qeug_recon_payreqbill_ext
* 付款申请单 || 费用登记单 插件
* 发票识别,发票验真验重
* qeug_recon_payreqbill_ext && qeug_recon_connotextb_ext
*/
public class ReconPayreqFormPlugin extends AbstractFormPlugin {
@ -31,13 +46,14 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin {
public void afterDoOperation(AfterDoOperationEventArgs args) {
super.afterDoOperation(args);
DynamicObject dataEntity = this.getView().getModel().getDataEntity();
String billtype = dataEntity.getDynamicObjectType().getName();
String operateKey = args.getOperateKey();
switch (operateKey){
//发票识别
case "qeug_invoicedistinguish":
DynamicObject dataEntity = this.getView().getModel().getDataEntity();
List<Map<String, Object>> attachments = AttachmentServiceHelper.getAttachments("recon_payreqbill",
List<Map<String, Object>> attachments = AttachmentServiceHelper.getAttachments(billtype,
dataEntity.getPkValue(), "qeug_attachmentpanelap");
if (attachments.size() <= 0) {
this.getView().showTipNotification("请先上传发票附件");
@ -53,8 +69,29 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin {
boolean b = true;
//成功--新增分录行
if (b) {
for (Map<String, Object> fileMap : attachments) {
AttachmentDto attachmentDto = AttachmentServiceHelper.getAttachmentInfoByAttPk(fileMap.get("attPkId"));
String fileUrl = attachmentDto.getResourcePath();
try {
FileInputStream in = new FileInputStream(fileUrl);
Workbook workbook = WorkbookFactory.create(in);
Sheet sheet = workbook.getSheetAt(0);
for (int j = 1; j < 5; j++) {
Row row = sheet.getRow(j);
String billno = row.getCell(0).toString();
}
System.out.println("");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
//发票信息分录
for (int i = 0; i < attachments.size(); i++) {
invoiceentry.addNew();
//todo:模仿标品新增字段,为接口返回数据反写分录做准备
this.getModel().setValue("qeug_invoicecode", "FKHM-0904-0001",i);//发票代码
@ -65,6 +102,7 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin {
}
this.getView().updateView("invoiceentry");
this.getView().showSuccessNotification("发票识别成功");
SaveServiceHelper.save(new DynamicObject[]{this.getView().getModel().getDataEntity()});
}else {
//失败--提示失败信息
this.getView().showTipNotification("发票识别失败:请上传有效发票");
@ -74,72 +112,123 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin {
case "qeug_invoicecheck":
//todo: 发票验真验重接口
// 根据接口情况打包分录数据去OA验真验重---遍历调取接口还是汇总集合调取接口
//发票信息分录
DynamicObjectCollection invoiceens = this.getView().getModel().getEntryEntity("invoiceentry");
if (invoiceens.size() == 0) {
this.getView().showTipNotification("请先进行发票识别后,再进行验真验重");
return;
}
boolean bb = true;
//成功--新增分录行
if (bb) {
this.getView().showSuccessNotification("发票验真验重接口");
//验真验重接口调通--生成发票登记单据(recon_invoicebill)
DynamicObject recon_invoicebill1 = BusinessDataServiceHelper.newDynamicObject("recon_invoicebill");
DynamicObject recon_invoicebill = BusinessDataServiceHelper.loadSingle("2031274535679975424", "recon_invoicebill");
recon_invoicebill.set("billstatus","A");//单据状态
//所属组织
DynamicObject org = BusinessDataServiceHelper.loadSingle("bos_org", new QFilter[]{new QFilter("number", QCP.equals, "DOBE")});
if (null != org) {
recon_invoicebill.set("org",org);
}
//发票号码 invoiceno
// recon_invoicebill.set("invoiceno",System.currentTimeMillis());//----编码规则待维护
recon_invoicebill.set("invoiceno","FKHM-0904-0001");//----编码规则待维护
//发票编码
recon_invoicebill.set("billno","测试数据勿删!!");//----编码规则待维护
//todo 遍历发票信息明细,批量生成发票登记单(再次点击发票验真验重,只选择未完成验真验重的数据)
for (DynamicObject invoiceen : invoiceens) {
String qeug_invoicestatus = invoiceen.getString("qeug_invoicestatus");//验真/--状态
//未完成
if ("0".equals(qeug_invoicestatus)) {
//付款申请单 payreqentrys
DynamicObjectCollection payreqentrys = recon_invoicebill.getDynamicObjectCollection("payreqentrys");
payreqentrys.clear();
DynamicObject payreqentry = payreqentrys.addNew();
payreqentry.set("fbasedataid", this.getView().getModel().getDataEntity());
DynamicObject recon_invoicebill = BusinessDataServiceHelper.newDynamicObject("recon_invoicebill");
// DynamicObject recon_invoicebill1 = BusinessDataServiceHelper.loadSingle("2031274535679975424", "recon_invoicebill");
recon_invoicebill.set("billstatus","A");//单据状态
//所属组织
DynamicObject org = BusinessDataServiceHelper.loadSingle("bos_org", new QFilter[]{new QFilter("number", QCP.equals, "DOBE")});
if (null != org) {
recon_invoicebill.set("org",org);
}
//发票号码 invoiceno
// recon_invoicebill.set("invoiceno",System.currentTimeMillis());
recon_invoicebill.set("invoiceno",invoiceen.getString("qeug_invoiceno"));//分录中的发票号码//todo----编码规则待维护
//发票编码
recon_invoicebill.set("billno","测试数据勿删!!");//----编码规则待维护
//todo:若接口返回汇总
//发票_明细
DynamicObjectCollection invoiceentrs = recon_invoicebill.getDynamicObjectCollection("invoiceentry");
invoiceentrs.clear();
DynamicObject invoiceentr = invoiceentrs.addNew();
invoiceentr.set("entry_notaxamt",100000);
//todo:若接口返回明细--遍历新增发票明细分录
//付款申请单 payreqentrys
DynamicObjectCollection payreqentrys = recon_invoicebill.getDynamicObjectCollection("payreqentrys");
payreqentrys.clear();
DynamicObject payreqentry = payreqentrys.addNew();
payreqentry.set("fbasedataid", this.getView().getModel().getDataEntity());
Object[] save = SaveServiceHelper.save(new DynamicObject[]{recon_invoicebill});
//如果 成功生成发票登记的单子,反写分录状态为完成
if (save.length > 0) {
//发票信息分录
DynamicObjectCollection invoiceentrys = this.getView().getModel().getEntryEntity("invoiceentry");
if (invoiceentrys.size() > 0) {
for (DynamicObject invoiceent : invoiceentrys) {
//根据发票号码进行过滤
String qeug_invoiceno = invoiceent.getString("qeug_invoiceno");//分录中的发票号码
//todo:付款申请单发票信息分录行的发票号码 == 发票登记单头发票号码
if (qeug_invoiceno.equals(recon_invoicebill.getString("invoiceno"))) {
System.out.println();
invoiceent.set("qeug_invoicestatus",1);//发票状态(验真/)--------已完成
//todo:若接口返回汇总
//发票_明细
DynamicObjectCollection invoiceentrs = recon_invoicebill.getDynamicObjectCollection("invoiceentry");
invoiceentrs.clear();
DynamicObject invoiceentr = invoiceentrs.addNew();
invoiceentr.set("entry_notaxamt",100000);
//todo:若接口返回明细--遍历新增发票明细分录
Object[] save = SaveServiceHelper.save(new DynamicObject[]{recon_invoicebill});
//如果 成功生成发票登记的单子,反写分录状态为完成
if (save.length > 0) {
//发票信息分录
DynamicObjectCollection invoiceentrys = this.getView().getModel().getEntryEntity("invoiceentry");
if (invoiceentrys.size() > 0) {
for (DynamicObject invoiceent : invoiceentrys) {
//根据发票号码进行过滤
String qeug_invoiceno = invoiceent.getString("qeug_invoiceno");//分录中的发票号码
//todo:付款申请单发票信息分录行的发票号码 == 发票登记单头发票号码
if (qeug_invoiceno.equals(recon_invoicebill.getString("invoiceno"))) {
System.out.println();
invoiceent.set("qeug_invoicestatus",1);//发票状态(验真/)--------已完成
}
}
this.getView().updateView("invoiceentry");
// SaveServiceHelper.save(new DynamicObject[]{this.getView().getModel().getDataEntity()});
}
}
this.getView().updateView("invoiceentry");
// SaveServiceHelper.save(new DynamicObject[]{this.getView().getModel().getDataEntity()});
}
}
System.out.println("");
}else {
//失败--提示失败信息
this.getView().showTipNotification("发票验真验重失败:请检查发票明细信息是否正确");
}
break;
case "deleteinvoiceentry":
//用户在删除发票明细时如果当前发票已经生成发票登记单一并删除掉
//
//付款申请单发票信息明细删除行后进行保存
SaveServiceHelper.save(new DynamicObject[]{this.getView().getModel().getDataEntity()});
this.getView().showSuccessNotification("同步删除发票登记成功");
break;
default:
break;
}
}
@Override
public void beforeDoOperation(BeforeDoOperationEventArgs args) {
super.beforeDoOperation(args);
FormOperate source = (FormOperate) args.getSource();
String operateKey = source.getOperateKey();
switch (operateKey) {
//发票识别
case "deleteinvoiceentry":
//用户在删除发票明细时如果当前发票已经生成发票登记单一并删除掉
//删除后--未保存前,遍历发票信息分录 删除满足(明细"发票号码" == 发票登记单头"发票号码")的发票登记单
//获得"发票信息明细"选中行
EntryGrid assetsentry = (EntryGrid)this.getView().getControl("invoiceentry");
int[] selectRows = assetsentry.getSelectRows();
if (selectRows.length > 0) {
for (int i = 0; i < selectRows.length; i++) {
int selectRow = selectRows[i];
String qeug_invoiceno = (String)this.getModel().getValue("qeug_invoiceno",selectRow);//分录中的发票号码
QFilter q = new QFilter("invoiceno", QCP.equals, qeug_invoiceno);
DynamicObject recon_invoicebill = BusinessDataServiceHelper.loadSingle("recon_invoicebill", new QFilter[]{q});
if (null != recon_invoicebill) {
int recon_invoicebill1 = DeleteServiceHelper.delete("recon_invoicebill", new QFilter[]{q});
//失败
if (1 != recon_invoicebill1) {
this.getView().showTipNotification("删除失败:请检查发票登记单的单据状态");
args.setCancel(true);
return;
}
}
}
}
break;
default:
break;
}
}
}
// CodeRuleInfo codeRule = CodeRuleServiceHelper.getCodeRule("recon_invoicebill", recon_invoicebill, null);

View File

@ -1,20 +1,29 @@
package shkd.repc.recon.opplugin;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.operate.result.OperateErrorInfo;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.entity.validate.ErrorLevel;
import kd.bos.framework.lifecycle.Service;
import kd.bos.framework.lifecycle.SystemServiceConfig;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.util.HttpClientUtils;
import kd.bos.util.StringUtils;
import org.apache.commons.net.util.Base64;
//import java.util.Base64;
import shkd.utils.OAUtils;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.*;
/**
@ -23,6 +32,8 @@ public class TestOPPlugin extends AbstractOperationServicePlugIn {
private static final Log logger = LogFactory.getLog(TestOPPlugin.class);
private static final String RESM_OFFICIAL_SUPPLIER = "resm_official_supplier";//正式供应商
@Override
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
super.afterExecuteOperationTransaction(e);
@ -32,94 +43,126 @@ public class TestOPPlugin extends AbstractOperationServicePlugIn {
for (DynamicObject dataEntity : e.getDataEntities()) {
// String url = System.getProperty("efms.infcompany.url.ip");
// logger.info("url");
/*
---------------------生成上传文件链接----------------------------
*/
try {
String linkUrl = "http://172.31.254.241:8869/file/v1/generateUploadUrl";
//TODO: .请求头(2.2.1) .requestID
Service[] allServices = SystemServiceConfig.getAllServices();
//获取token
String oaToken = OAUtils.getOaToken();
//生成上传文件链接接口请求体
JSONObject linkBody = new JSONObject();
linkBody.put("expire",5);
linkBody.put("requestID", "4A6F3B4E5C2D1A9F8E7B6C5D4A3B2C1E");
linkBody.put("type", 1);
if (StringUtils.isNotEmpty(oaToken)) {
//ICS新增/更新OA客户租户接口
String customerUrl = "http://172.31.254.240:9090/seeyon/rest/ats/type/customer";
//获取上传链接类型0-上传文件并分割适用于100M以内的pdf文件1-上传文件适用于大于100M的pdf文件以及其他类型的文件ofddocdocxxlsxlsxjpgjpegpngziprar
Map<String, String> linkHeader = new HashMap<>();
//body,项目密钥进行加密(HmacSHA256进行数据加密)
String secret = linkBody.toJSONString();
String message ="B69RSfJJ5yJ6gizo";
Map<String, String> customerHeader = new HashMap<>();
customerHeader.put("Content-Type", "application/json");
customerHeader.put("token", oaToken);
// //import org.apache.commons.net.util.Base64;
// Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
// SecretKeySpec secretKey = new SecretKeySpec(secret.getBytes(),"HmacSHA256");
// sha256_HMAC.init(secretKey);
// byte[] hash = sha256_HMAC.doFinal(message.getBytes());
// String encodeStr = Base64.encodeBase64String(hash);//Ew6TnQg1i+e6GomCPBSoXfX+UFqmKy1AnP6gVKJrrQM=\r\n
//import java.util.Base64;
// SecretKeySpec secretKey = new SecretKeySpec(message.getBytes(),"HmacSHA256");
// sha256_HMAC.init(secretKey);
// byte[] hash = sha256_HMAC.doFinal(secret.getBytes());
// String encodeStr = Base64.getEncoder().encodeToString(hash);//a7FxNRJsu5q0quFSF84R0eOhAiXYXoKvrrPw2o/JwbM=
// String encodestr16 = byte2Hex(hash);//130e939d08358be7ba1a89823c14a85df5fe505aa62b2d409cfea054a26bad03 //6bb17135126cbb9ab4aae15217ce11d1e3a10225d85e82afaeb3f0da8fc9c1b3
String HMACsha256 = calculateHMACSHA256(secret, message);//130e939d08358be7ba1a89823c14a85df5fe505aa62b2d409cfea054a26bad03
String HMACsha256s = calculateHMACSHA256(message,secret );//6bb17135126cbb9ab4aae15217ce11d1e3a10225d85e82afaeb3f0da8fc9c1b3
linkHeader.put("Content-Type", "application/json");
linkHeader.put("x-timevale-project-id", "1000000");
linkHeader.put("x-timevale-signature", "4c45b39ebe42818aa90001849dffda622c9894454bc6d68c03aff67c55730661");
String linkPostjson = HttpClientUtils.postjson(linkUrl, linkHeader,linkBody.toJSONString());
if (StringUtils.isNotEmpty(linkPostjson)) {
JSONObject jsonObject = JSONObject.parseObject(linkPostjson);
String messages = jsonObject.getString("message");
OperateErrorInfo operateErrorInfo = new OperateErrorInfo();
operateErrorInfo.setMessage(messages);
operateErrorInfo.setErrorLevel(ErrorLevel.Error.name());
operateErrorInfo.setPkValue(dataEntity.getPkValue());
this.operationResult.addErrorInfo(operateErrorInfo);
// /*
// ---------------------上传文件----------------------------
// */
// //TODO:请求头 2.2.1
// Map<String, String> uploadHeader = new HashMap<>();
// linkHeader.put("Content-Type", "multipart/form-data");
// //生成上传文件链接接口请求体
// JSONObject uploadBody = new JSONObject();
// linkBody.put("file",new AttachmentModel());//附件
//
// String uploadPostjson = HttpClientUtils.postjson(linkPostjson, uploadHeader,uploadBody.toJSONString());
// switch (uploadPostjson) {
// case "success":
// //上传成功
// break;
// default:
// break;
//组装请求体
// DynamicObject supplier = dataEntity.getDynamicObject("supplier");
// if (null != supplier) {
// JSONObject customerBody = assembleBody(OAUtils.l(supplier.getPkValue()));
JSONObject customerBody = assembleBody(OAUtils.l(dataEntity.getPkValue()));
if (null != customerBody) {
String customerPostjson = null;
String str = null;
try {
customerPostjson = HttpClientUtils.postjson(customerUrl, customerHeader, customerBody.toJSONString());
logger.info("ICS新增/更新OA客户租户接口返回结果\n{}", customerPostjson);
} catch (Exception ex) {
logger.info(String.format("ICS新增/更新OA客户租户接口异常%s", ex.getMessage()));
throw new RuntimeException(ex);
}
}
// }
}
} catch (Exception ex) {
OperateErrorInfo operateErrorInfo = new OperateErrorInfo();
operateErrorInfo.setMessage(ex.getMessage());
operateErrorInfo.setErrorLevel(ErrorLevel.Error.name());
operateErrorInfo.setPkValue(dataEntity.getPkValue());
this.operationResult.addErrorInfo(operateErrorInfo);
}
}
}
}
/**
* 组装供应商入参
*/
private static JSONObject assembleBody(long supplierID){
JSONObject customerBody = null;
//获取正式供应商
// QFilter q = new QFilter("id", QCP.equals, supplierID);
QFilter q = new QFilter("number", QCP.equals, "111");//成都筑垒建筑工程有限公司
DynamicObject official_supplier = BusinessDataServiceHelper.loadSingle(RESM_OFFICIAL_SUPPLIER, new QFilter[]{q});
if (null != official_supplier) {
String code = official_supplier.getString("number");
String name = official_supplier.getString("name");
String taxpayerid = official_supplier.getString("tx_register_no");
String shortname = official_supplier.getString("simplename");
String legalbody = official_supplier.getString("artificialperson");
Date createTime = official_supplier.getDate("createtime");
Date updateTime = official_supplier.getDate("modifytime");
Object createtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(createTime);
Object updatetime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(updateTime);
//接口请求体
customerBody = new JSONObject();
customerBody.put("code", code);//"客户编码传递OA回执的code如果没有则为空OA判断新增后返回code",
customerBody.put("name", name);//"客户名称",
customerBody.put("taxpayerid", taxpayerid);//"纳税人登记号/身份证号 唯一值不可变",
customerBody.put("shortname", shortname);//"客户简称",
customerBody.put("custprop", "0");//"客户类型默认0",
customerBody.put("enablestate", "2");//"客户状态默认2",
customerBody.put("pk_custclass", "02");//"客户基本分类默认02",
customerBody.put("legalbody", legalbody);// "法人",
customerBody.put("createTime", createtime);// "创建时间例如2024-06-02 17:27:10",
customerBody.put("updateTime", updatetime);//"更新时间例如2024-06-02 17:27:10",
customerBody.put("def1", "租赁客户");//"客商类别:默认租赁客户",
JSONArray custBankaccMapBody = new JSONArray();
//银行信息
DynamicObjectCollection entry_banks = official_supplier.getDynamicObjectCollection("entry_bank");
for (DynamicObject entry_bank : entry_banks) {
JSONObject custBankaccBody = new JSONObject();
custBankaccBody.put("accnum", entry_bank.getString("bankaccount"));//"银行账号",
DynamicObject bank = entry_bank.getDynamicObject("bank");
if (null != bank) {
// "开户行名称:例如招商银行股份有限公司上海分行外高桥支行龙江支行"
custBankaccBody.put("pk_bankdoc", bank.getString("name"));
DynamicObject city = bank.getDynamicObject("city");
if (null != city) {
//"城市"
custBankaccBody.put("city", city.getString("name"));
}
}
custBankaccBody.put("accname", entry_bank.getString("accountname"));//"银行账号名称",
custBankaccBody.put("pk_banktype", "");//todo:"银行类别:例如招商银行",
String persontype = entry_bank.getString("persontype");//法人类型
//法人企业 LEGALENTERPRISE
//非法人企业 UNINCORPORATED
//非企业单位 NONENTERPRISE
//个人 PERSONAL
if (!"PERSONAL".equals(persontype)) {
custBankaccBody.put("psnOrCompany", "3397730183813155472");// "个人或公司公司3397730183813155472/个人:-7676950454987503991"
}else {
custBankaccBody.put("psnOrCompany", "-7676950454987503991");
}
custBankaccMapBody.add(custBankaccBody);
}
//无银行信息
if (entry_banks.size() == 0) {
JSONObject custBankaccBody = new JSONObject();
custBankaccBody.put("accnum","");//"银行账号",
custBankaccBody.put("pk_bankdoc", "");// "开户行名称:例如招商银行股份有限公司上海分行外高桥支行龙江支行"
custBankaccBody.put("city","");//"城市"
custBankaccBody.put("accname","");//"银行账号名称",
custBankaccBody.put("pk_banktype", "");//todo:"银行类别:例如招商银行",
custBankaccBody.put("psnOrCompany", "3397730183813155472");// "个人或公司公司3397730183813155472/个人:-7676950454987503991"
custBankaccMapBody.add(custBankaccBody);
}
customerBody.put("bankacc", custBankaccMapBody);
}
return customerBody;
}
private static String byte2Hex(byte[] bytes){
StringBuffer stringBuffer = new StringBuffer();
String temp = null;
@ -153,4 +196,85 @@ public class TestOPPlugin extends AbstractOperationServicePlugIn {
}
}
// String[] split = encodeStr.split("=", 4);
// String s = split[0];
// String s = split[0];
/*
---------------------生成上传文件链接----------------------------
*/
//import org.apache.commons.net.util.Base64;
//import java.util.Base64;
// try {
// String linkUrl = "http://172.31.254.241:8869/file/v1/generateUploadUrl";
// //TODO: .请求头(2.2.1) .requestID
//
// //生成上传文件链接接口请求体
// JSONObject linkBody = new JSONObject();
// linkBody.put("expire",5);
// linkBody.put("requestID", "4A6F3B4E5C2D1A9F8E7B6C5D4A3B2C1E");
// linkBody.put("type", 1);
//
// //获取上传链接类型0-上传文件并分割适用于100M以内的pdf文件1-上传文件适用于大于100M的pdf文件以及其他类型的文件ofddocdocxxlsxlsxjpgjpegpngziprar
// Map<String, String> linkHeader = new HashMap<>();
// //body,项目密钥进行加密(HmacSHA256进行数据加密)
// String secret = linkBody.toJSONString();
// String message ="B69RSfJJ5yJ6gizo";
// //import org.apache.commons.net.util.Base64;
// Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
// SecretKeySpec secretKey = new SecretKeySpec(secret.getBytes(),"HmacSHA256");
// sha256_HMAC.init(secretKey);
// byte[] hash = sha256_HMAC.doFinal(message.getBytes());
// String encodeStr = Base64.encodeBase64String(hash);//Ew6TnQg1i+e6GomCPBSoXfX+UFqmKy1AnP6gVKJrrQM=\r\n
//import java.util.Base64;
// SecretKeySpec secretKey = new SecretKeySpec(message.getBytes(),"HmacSHA256");
// sha256_HMAC.init(secretKey);
// byte[] hash = sha256_HMAC.doFinal(secret.getBytes());
// String encodeStr = Base64.getEncoder().encodeToString(hash);//a7FxNRJsu5q0quFSF84R0eOhAiXYXoKvrrPw2o/JwbM=
// String encodestr16 = byte2Hex(hash);//130e939d08358be7ba1a89823c14a85df5fe505aa62b2d409cfea054a26bad03 //6bb17135126cbb9ab4aae15217ce11d1e3a10225d85e82afaeb3f0da8fc9c1b3
// String HMACsha256 = calculateHMACSHA256(secret, message);//130e939d08358be7ba1a89823c14a85df5fe505aa62b2d409cfea054a26bad03
// String HMACsha256s = calculateHMACSHA256(message,secret );//6bb17135126cbb9ab4aae15217ce11d1e3a10225d85e82afaeb3f0da8fc9c1b3
//
//
// linkHeader.put("Content-Type", "application/json");
// linkHeader.put("x-timevale-project-id", "1000000");
// linkHeader.put("x-timevale-signature", "4c45b39ebe42818aa90001849dffda622c9894454bc6d68c03aff67c55730661");
//
//
//
// String linkPostjson = HttpClientUtils.postjson(linkUrl, linkHeader,linkBody.toJSONString());
// if (StringUtils.isNotEmpty(linkPostjson)) {
//
// JSONObject jsonObject = JSONObject.parseObject(linkPostjson);
// String messages = jsonObject.getString("message");
// /*
// ---------------------上传文件----------------------------
// */
// //TODO:请求头 2.2.1
// Map<String, String> uploadHeader = new HashMap<>();
// linkHeader.put("Content-Type", "multipart/form-data");
// //生成上传文件链接接口请求体
// JSONObject uploadBody = new JSONObject();
// linkBody.put("file",new AttachmentModel());//附件
//
// String uploadPostjson = HttpClientUtils.postjson(linkPostjson, uploadHeader,uploadBody.toJSONString());
// switch (uploadPostjson) {
// case "success":
// //上传成功
// break;
// default:
// break;
// }
// }
// } catch (Exception ex) {
// OperateErrorInfo operateErrorInfo = new OperateErrorInfo();
// operateErrorInfo.setMessage(ex.getMessage());
// operateErrorInfo.setErrorLevel(ErrorLevel.Error.name());
// operateErrorInfo.setPkValue(dataEntity.getPkValue());
// this.operationResult.addErrorInfo(operateErrorInfo);
// }
// }

View File

@ -0,0 +1,146 @@
package shkd.repc.resm.opplugin;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.operate.result.OperateErrorInfo;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.entity.validate.ErrorLevel;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.util.HttpClientUtils;
import kd.bos.util.StringUtils;
import shkd.repc.recon.opplugin.TestOPPlugin;
import shkd.utils.OAUtils;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* 推送OA供应商
*/
public class PushOASupplierOPPlugin extends AbstractOperationServicePlugIn {
private static final Log logger = LogFactory.getLog(PushOASupplierOPPlugin.class);
private static final String RESM_OFFICIAL_SUPPLIER = "resm_official_supplier";//正式供应商
@Override
public void afterExecuteOperationTransaction(AfterOperationArgs e){
super.afterExecuteOperationTransaction(e);
String operationKey = e.getOperationKey();
if ("pushoasupplier".equals(operationKey)) {
for (DynamicObject dataEntity : e.getDataEntities()) {
//String url = System.getProperty("efms.infcompany.url.ip");
//logger.info("url");
//获取token
String oaToken = OAUtils.getOaToken();
if (StringUtils.isNotEmpty(oaToken)) {
//ICS新增/更新OA客户租户接口
String customerUrl = "http://172.31.254.240:9090/seeyon/rest/ats/type/customer";
Map<String, String> customerHeader = new HashMap<>();
customerHeader.put("Content-Type", "application/json");
customerHeader.put("token", oaToken);
//组装请求体
DynamicObject supplier = dataEntity.getDynamicObject("supplier");
if (null != supplier) {
JSONObject customerBody = assembleBody(OAUtils.l(supplier.getPkValue()));
if (null != customerBody) {
String customerPostjson = null;
try {
customerPostjson = HttpClientUtils.postjson(customerUrl, customerHeader, customerBody.toJSONString());
logger.info("ICS新增/更新OA客户租户接口返回结果\n{}", customerPostjson);
} catch (Exception ex) {
logger.info(String.format("ICS新增/更新OA客户租户接口异常%s", ex.getMessage()));
throw new RuntimeException(ex);
}
}
}
}
}
}
}
/**
* 组装供应商入参
*/
private static JSONObject assembleBody(long supplierID){
JSONObject customerBody = null;
//获取正式供应商
// QFilter q = new QFilter("id", QCP.equals, supplierID);
QFilter q = new QFilter("number", QCP.equals, "111");//成都筑垒建筑工程有限公司
DynamicObject official_supplier = BusinessDataServiceHelper.loadSingle(RESM_OFFICIAL_SUPPLIER, new QFilter[]{q});
if (null != official_supplier) {
String code = official_supplier.getString("number");
String name = official_supplier.getString("name");
String taxpayerid = official_supplier.getString("tx_register_no");
String shortname = official_supplier.getString("simplename");
String legalbody = official_supplier.getString("artificialperson");
Date createTime = official_supplier.getDate("createtime");
Date updateTime = official_supplier.getDate("modifytime");
//接口请求体
customerBody = new JSONObject();
customerBody.put("code", code);//"客户编码传递OA回执的code如果没有则为空OA判断新增后返回code",
customerBody.put("name", name);//"客户名称",
customerBody.put("taxpayerid", taxpayerid);//"纳税人登记号/身份证号 唯一值不可变",
customerBody.put("shortname", shortname);//"客户简称",
customerBody.put("custprop", "0");//"客户类型默认0",
customerBody.put("enablestate", "2");//"客户状态默认2",
customerBody.put("pk_custclass", "02");//"客户基本分类默认02",
customerBody.put("legalbody", legalbody);// "法人",
customerBody.put("createTime", createTime);// "创建时间例如2024-06-02 17:27:10",
customerBody.put("updateTime", updateTime);//"更新时间例如2024-06-02 17:27:10",
customerBody.put("def1", "租赁客户");//"客商类别:默认租赁客户",
JSONArray custBankaccMapBody = new JSONArray();
//银行信息
DynamicObjectCollection entry_banks = official_supplier.getDynamicObjectCollection("entry_bank");
for (DynamicObject entry_bank : entry_banks) {
JSONObject custBankaccBody = new JSONObject();
custBankaccBody.put("accnum", entry_bank.getString("bankaccount"));//"银行账号",
DynamicObject bank = entry_bank.getDynamicObject("bank");
if (null != bank) {
// "开户行名称:例如招商银行股份有限公司上海分行外高桥支行龙江支行"
custBankaccBody.put("pk_bankdoc", bank.getString("name"));
DynamicObject city = bank.getDynamicObject("city");
if (null != city) {
//"城市"
custBankaccBody.put("city", city.getString("name"));
}
}
custBankaccBody.put("accname", entry_bank.getString("accountname"));//"银行账号名称",
custBankaccBody.put("pk_banktype", "");//todo:"银行类别:例如招商银行",
String persontype = entry_bank.getString("persontype");//法人类型
//法人企业 LEGALENTERPRISE
//非法人企业 UNINCORPORATED
//非企业单位 NONENTERPRISE
//个人 PERSONAL
if (!"PERSONAL".equals(persontype)) {
custBankaccBody.put("psnOrCompany", "3397730183813155472");// "个人或公司公司3397730183813155472/个人:-7676950454987503991"
}else {
custBankaccBody.put("psnOrCompany", "-7676950454987503991");
}
custBankaccMapBody.add(custBankaccBody);
}
customerBody.put("bankacc", custBankaccMapBody);
}
return customerBody;
}
}

View File

@ -0,0 +1,75 @@
package shkd.utils;
import com.alibaba.fastjson.JSONObject;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.util.HttpClientUtils;
import kd.bos.util.StringUtils;
import java.util.Date;
/**
* @author weiyunlong
* @date Created 2024/9/11 16:02
* @description致远OA集成工具类
*/
public class OAUtils {
private static final Log logger = LogFactory.getLog(OAUtils.class);
//致远服务前获取token接口
public static String getOaToken(){
//String url = System.getProperty("efms.infcompany.url.ip");
//logger.info("url");
//致远服务前获取token接口
String userName = "ICSTest";
String password = "8f72e360-268e-41ba-9886-af9a802e4de3";
String linkUrl = "http://172.31.254.240:9090/seeyon/rest/token";
//接口请求体
JSONObject linkBody = new JSONObject();
linkBody.put("userName", userName);
linkBody.put("password", password);
String token = "";
try {
String linkPostjson = HttpClientUtils.postjson(linkUrl, null, linkBody.toJSONString());
logger.info("获取OaToken接口返回结果\n{}", linkPostjson);
if (StringUtils.isNotEmpty(linkPostjson)) {
JSONObject jsonObject = JSONObject.parseObject(linkPostjson);
token = jsonObject.getString("id");
}
return token;
} catch (Exception e) {
logger.info(String.format("获取OaToken接口异常%s", e.getMessage()));
throw new RuntimeException(e);
}
}
/**
* model值转Long
*/
public static long l(Object value) {
if (value == null) {
return 0L;
} else if (value instanceof Long) {
return (Long)value;
} else if (value instanceof Number) {
return ((Number)value).longValue();
} else if (value instanceof Boolean) {
return ((Boolean)value).booleanValue() ? 1L : 0L;
} else if (value instanceof Date) {
return ((Date)value).getTime();
} else {
String s = value.toString().trim();
if (s.length() == 0) {
return 0L;
} else {
return Long.parseLong(s);
}
}
}
}