钉钉开放平台-服务端API-发起审批实例
官方API: https://ding-doc.dingtalk.com/doc#/serverapi2/cmct1a
需要做的事项:
1、进入钉钉后台管理-工作台-审批-创建新审批-自定义模板
2、按界面拖控件定义好您需要的模板
API调用方式:指定审批人模式。
实现代码:
/// <summary>
/// 智能工作流-发起审批实例
/// </summary>
/// <returns></returns>
public async Task<OapiCreateProcessInstanceResult> CreateProcessInstanceAsync(CreateProcessInstanceRequestInfo requestInfo)
{
await StaffsCheckedAsync();
requestInfo.TaskActionType = requestInfo.TaskActionType ?? "AND";
requestInfo.CCPosition = requestInfo.CCPosition ?? "START";
var originatorStaffInfo = _staffs.FirstOrDefault(m => m.StaffNumber.Equals(requestInfo.OriginatorStaffNumber));
if (originatorStaffInfo == null) return null;
var approverUserids = new List<string>();
foreach(var staffNumber in requestInfo.Approvers)
{
var staffInfo = _staffs.FirstOrDefault(m => m.StaffNumber.Equals(staffNumber, StringComparison.OrdinalIgnoreCase));
if (staffInfo != null) approverUserids.Add(staffInfo.Id);
}
var copyUserids = _staffs.Where(m => requestInfo.CopyPersons.Contains(m.StaffNumber)).Select(m => m.Id);
var cclist = (copyUserids == null || !copyUserids.Any()) ? null : string.Join(",", copyUserids);
var ccposition = !string.IsNullOrEmpty(cclist) ? requestInfo.CCPosition : null;
List<OapiProcessInstanceApproverVo> approvers = null;
if (requestInfo.TaskActionType.Equals("OR", StringComparison.OrdinalIgnoreCase) && (approverUserids