当前位置: 首页 > news >正文

金蝶云星空插件开发记录(一)

实现目的:

新增供应商保存后,触发钉钉审批流程,并根据钉钉审批结果回写是否合格供应商。

实现思路:

通过BOS平台供在应商管理界面新增两个复选框字段:是否钉钉审批、是否合格供应商,若在新建供应商档案时勾选是否钉钉审批,在保存供应商信息的时候调用二开插件传递钉钉审批,同时启动子线程定时任务,定时获取钉钉审批结果,若钉钉审批通过则需要自动回写合格供应商。

实现过程:

1、新建.net framework项目,引入金蝶插件,引入钉钉插件(TopSdk)。

2、新建钉钉帮助类,用于获取token、userid等信息:

using DingTalk.Api;
using DingTalk.Api.Request;
using DingTalk.Api.Response;
using System.Collections.Generic;namespace K3Cloud.BasicData.Supply.SupplySendDing
{public class DingtalkHelper{public static string GetToken() {DefaultDingTalkClient defaultDingTalkClient = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");OapiGettokenRequest OapiGettokenRequest = new OapiGettokenRequest();OapiGettokenRequest.Appkey = "你的appkey";OapiGettokenRequest.Appsecret = "你的appsecret";OapiGettokenRequest.SetHttpMethod("GET");OapiGettokenResponse oapiGettokenResponse = defaultDingTalkClient.Execute(OapiGettokenRequest);return oapiGettokenResponse.AccessToken;}public static string GetUserId(string token,string name) {DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/simplelist");OapiUserSimplelistRequest req = new OapiUserSimplelistRequest();req.Lang = "zh_CN";req.DepartmentId = 51236588;//采购部门id,在钉钉后台查看req.SetHttpMethod("GET");OapiUserSimplelistResponse rsp = client.Execute(req, token);Dictionary<string, string> map = new Dictionary<string, string>();rsp.Userlist.ForEach(x =>{map[x.Name] = x.Userid;});return map[name];}}
}

3、新建钉钉流程创建操作类:

using DingTalk.Api.Request;
using DingTalk.Api.Response;
using DingTalk.Api;
using System;
using System.Collections.Generic;namespace K3Cloud.BasicData.Supply.SupplySendDing
{public class DingtalkStart{public static string StartSupplyNew(string token,string userId,string code,string name,string supplyCate,string address) {DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/processinstance/create");OapiProcessinstanceCreateRequest req = new OapiProcessinstanceCreateRequest();req.AgentId = 39568215863;req.ProcessCode = "表单code";req.OriginatorUserId = userId;req.DeptId = 50212358; //采购部id//单行输入框List<OapiProcessinstanceCreateRequest.FormComponentValueVoDomain> formComponentValueVoList = new List<OapiProcessinstanceCreateRequest.FormComponentValueVoDomain>();OapiProcessinstanceCreateRequest.FormComponentValueVoDomain formComponentValueVo = new OapiProcessinstanceCreateRequest.FormComponentValueVoDomain();formComponentValueVoList.Add(formComponentValueVo);formComponentValueVo.Name = "编码";formComponentValueVo.Value = code;OapiProcessinstanceCreateRequest.FormComponentValueVoDomain formComponentValueVo1 = new OapiProcessinstanceCreateRequest.FormComponentValueVoDomain();formComponentValueVoList.Add(formComponentValueVo1);formComponentValueVo1.Name = "名称";formComponentValueVo1.Value = name;OapiProcessinstanceCreateRequest.FormComponentValueVoDomain formComponentValueVo2 = new OapiProcessinstanceCreateRequest.FormComponentValueVoDomain();formComponentValueVoList.Add(formComponentValueVo2);formComponentValueVo2.Name = "日期";formComponentValueVo2.Value = DateTime.Now.ToString("yyyy-MM-dd");OapiProcessinstanceCreateRequest.FormComponentValueVoDomain formComponentValueVo3 = new OapiProcessinstanceCreateRequest.FormComponentValueVoDomain();formComponentValueVoList.Add(formComponentValueVo3);formComponentValueVo3.Name = "供应商分组";formComponentValueVo3.Value = supplyCate;OapiProcessinstanceCreateRequest.FormComponentValueVoDomain formComponentValueVo4 = new OapiProcessinstanceCreateRequest.FormComponentValueVoDomain();formComponentValueVoList.Add(formComponentValueVo4);formComponentValueVo4.Name = "注册地址";formComponentValueVo4.Value = address;req.FormComponentValues_ = formComponentValueVoList;OapiProcessinstanceCreateResponse rsp = client.Execute(req, token);return rsp.ProcessInstanceId;}}
}

4、封装获取钉钉审批状态类:

using DingTalk.Api.Request;
using DingTalk.Api.Response;
using DingTalk.Api;namespace K3Cloud.BasicData.Supply.SupplySendDing
{public class DingtalkGet{public static string GetSupplyNewField(string processId) {DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/processinstance/get");OapiProcessinstanceGetRequest req = new OapiProcessinstanceGetRequest();req.ProcessInstanceId = processId;OapiProcessinstanceGetResponse rsp = client.Execute(req, DingtalkHelper.GetToken());if (rsp.ProcessInstance.Status == "TERMINATED" || rsp.ProcessInstance.Status == "CANCELED") {return "否";}if (rsp.ProcessInstance.Result == "refuse"){return "否";}if (rsp.ProcessInstance.Status == "COMPLETED" && rsp.ProcessInstance.Result == "agree"){foreach (var item in rsp.ProcessInstance.FormComponentValues){if (item.Name == "是否转批产"){return item.Value;}}}return null;}}
}

5、金蝶插件开发:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.Bill.PlugIn.Args;
using Kingdee.BOS.Util;
using Kingdee.BOS.Log;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.App.Data;
using Kingdee.BOS;
using System.Timers;namespace K3Cloud.BasicData.Supply.SupplySendDing
{/// <summary>/// 新增供应商触发钉钉审批/// </summary>[Description("新增供应商触发钉钉审批")][HotUpdate]public class SupplySendDingAfterSaveEventBillPlugIn : AbstractBillPlugIn{private string token;private string instanceId;private System.Timers.Timer timer;private string isOk;private string supplierCode; // 保存供应商编码用于线程中使用public override void AfterSave(AfterSaveEventArgs e){base.AfterSave(e);//是否发送钉钉审批var IsSend = this.Model.DataObject["F_UNW_CheckBox_qtr"].ToString();if (IsSend == "True"){//供应商编码supplierCode = this.Model.GetValue("FNUMBER").ToString();//供应商名称var name = this.Model.GetValue("FName").ToString();//创建人姓名DynamicObject creatorId = (DynamicObject)this.Model.GetValue("FCREATORID");var createtorName = creatorId["NAME"].ToString();//供应商分组var fGroup = (DynamicObject)this.Model.DataObject["FGroup"];var fGroupId = fGroup["ID"];var sql = "SELECT FNAME FROM T_BD_SUPPLIERGROUP_L WHERE FID= @fid";var sqlParam = new SqlParam("@fid", KDDbType.Int64, Convert.ToInt64(fGroupId));string fGroupName = "";using (var fReader = DBUtils.ExecuteReader(this.Context, sql, sqlParam)){while (fReader.Read()){fGroupName = fReader["FNAME"].ToString();}}//注册地址var subEntity = this.View.BillBusinessInfo.GetEntity("FBaseInfo");var subObjs = this.Model.GetEntityDataObject(subEntity);var address = subObjs[0]["RegisterAddress"].ToString();token = DingtalkHelper.GetToken();string uid = DingtalkHelper.GetUserId(token, createtorName);//触发钉钉流程instanceId = DingtalkStart.StartSupplyNew(token, uid, supplierCode, name, fGroupName, address);Logger.Error("TEST", "钉钉流程发送成功!", new Exception("无错误"));//启动新线程执行定时任务Thread timerThread = new Thread(StartTimerTask);timerThread.IsBackground = true; // 设置为后台线程timerThread.Start();}}/// <summary>/// 在新线程中启动定时任务/// </summary>private void StartTimerTask(){try{//1分钟检查一次timer = new System.Timers.Timer(60000);timer.Elapsed += TimerElapsed;timer.AutoReset = true;timer.Enabled = true;//循环等待审批结果while (string.IsNullOrEmpty(isOk)){Thread.Sleep(1000); // 减少CPU占用}//处理审批结果if (isOk == "是"){var usql = "UPDATE T_BD_SUPPLIER SET F_UNW_CHECKBOX_83G='1' WHERE FNUMBER=@FNo";var sqlParameterList = new List<SqlParam>{new SqlParam("@FNo", KDDbType.AnsiString, supplierCode)};DBUtils.Execute(this.Context, usql, sqlParameterList);}//清理定时器timer.Stop();timer.Dispose();}catch (Exception ex){Logger.Error("定时任务处理异常", ex.Message, ex);}}private void TimerElapsed(object sender, ElapsedEventArgs e){try{var res = DingtalkGet.GetSupplyNewField(instanceId);if (!string.IsNullOrEmpty(res)){isOk = res;}}catch (Exception ex){Logger.Error("获取审批结果异常", ex.Message, ex);isOk = "异常"; // 标记异常状态,退出循环}}}
}

6、将上述代码编译成dll文件,并在bos平台进行注册,重启IIS服务。


文章转载自:

http://Pjd37ddK.srjgz.cn
http://iF7X3aUm.srjgz.cn
http://eR85ChlE.srjgz.cn
http://N9FecEky.srjgz.cn
http://zIpsiCYB.srjgz.cn
http://owG38gOZ.srjgz.cn
http://wLX6fkNK.srjgz.cn
http://SXVIDY0S.srjgz.cn
http://tqDOvlpD.srjgz.cn
http://vk2lQANX.srjgz.cn
http://BHyasKUq.srjgz.cn
http://7GmvTams.srjgz.cn
http://H43X02Nl.srjgz.cn
http://QxScMCEk.srjgz.cn
http://xz8LCZXE.srjgz.cn
http://XcavHBhF.srjgz.cn
http://FmLmHGY1.srjgz.cn
http://ykp0MVJv.srjgz.cn
http://s1C4coPQ.srjgz.cn
http://OB5Uecau.srjgz.cn
http://D0bq5JYK.srjgz.cn
http://WeeerzOQ.srjgz.cn
http://Ni0l616F.srjgz.cn
http://Gb1QK0FN.srjgz.cn
http://3WaaYs7f.srjgz.cn
http://hP62JPPX.srjgz.cn
http://4oMTXUxX.srjgz.cn
http://lmGba8Kn.srjgz.cn
http://AlBL6QQN.srjgz.cn
http://PgJ8M6z6.srjgz.cn
http://www.dtcms.com/a/379806.html

相关文章:

  • Knockout-ES5 入门教程
  • 基于 Art_DAQ、InfluxDB 和 PyQt 的传感器数据采集、存储与可视化
  • 【图像处理基石】图像压缩有哪些经典算法?
  • C语言实战:简单易懂通讯录
  • youte-agent部署(windows)
  • Python实现点云法向量各种方向设定
  • Linnux IPC通信和RPC通信实现的方式
  • apache实现LAMP+apache(URL重定向)
  • MongoDB 与 GraphQL 结合:现代 API 开发新范式
  • k8s-临时容器学习
  • uni-app 根据用户不同身份显示不同的tabBar
  • ubuntu18.04安装PCL1.14
  • Ubuntu 系统下 Anaconda 完整安装与环境配置指南(附常见问题解决)
  • 网络链路分析笔记mtr/traceroute
  • 在 Ubuntu 系统中利用 conda 创建虚拟环境安装 sglang 大模型引擎的完整步骤、版本查看方法、启动指令及验证方式
  • 基带与射频的区别与联系
  • 《企业安全运营周报》模板 (极简实用版)​
  • opencv基于SIFT特征匹配的简单指纹识别系统实现
  • Node.js 操作 Elasticsearch (ES) 的指南
  • 使用tree命令导出文件夹/文件的目录树( Windows 和 macOS)
  • Spring缓存(二):解决缓存雪崩、击穿、穿透问题
  • LabVIEW加载 STL 模型至 3D 场景 源码见附件
  • Tessent_ijtag_ug——第 4 章 ICL 提取(2)
  • 前端WebSocket实时通信实现
  • 2025年- H133-Lc131. 反转字符串(字符串)--Java版
  • 萨顿四条原则
  • NumPy 2.x 完全指南【三十八】伪随机数生成器
  • GitHub 热榜项目 - 日榜(2025-09-12)
  • O3.3 opencv指纹识别
  • 在线会议系统是一个基于Vue3 + Spring Boot的现代化在线会议管理平台,集成了视频会议、实时聊天、AI智能助手等多项先进技术。