示例#1
0
        /// <summary>
        /// 发起审批实例
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="processinstance">审批示例表单</param>
        /// <param name="form"></param>
        /// <returns></returns>
        public static string Create(string accessToken, Processinstance processinstance)
        {
            try
            {
                DefaultDingTalkClient            client  = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/processinstance/create");
                OapiProcessinstanceCreateRequest request = new OapiProcessinstanceCreateRequest();
                //request.AgentId = 41605932L;                              //企业应用标识(ISV调用必须设置)
                request.ProcessCode = processinstance.ProcessCode;          //审批流的唯一码,process_code就在审批流编辑的页面URL中:"PROC-BY6LI83V-4R8T1CHNUX58O0Z6C55M3-DTQJJGEJ-1"
                List <OapiProcessinstanceCreateRequest.FormComponentValueVoDomain> formComponentValues = new List <OapiProcessinstanceCreateRequest.FormComponentValueVoDomain>();
                OapiProcessinstanceCreateRequest.FormComponentValueVoDomain        vo = new OapiProcessinstanceCreateRequest.FormComponentValueVoDomain();

                foreach (FormComponentValue item  in processinstance.FormComponentValues)
                {
                    switch (item.FieldType)
                    {
                    case FormField.singletext:
                    case FormField.multipletext:
                        vo.Name  = item.Name;
                        vo.Value = item.Value.ToString();
                        formComponentValues.Add(vo);
                        break;

                    case FormField.image:
                        vo.Name  = item.Name;
                        vo.Value = item.Value.ToString();
                        formComponentValues.Add(vo);
                        break;

                    case FormField.attach:
                        vo.Name  = item.Name;
                        vo.Value = item.Value.ToString();
                        formComponentValues.Add(vo);
                        break;

                    case FormField.detail:
                        vo.Name = item.Name;
                        var data = item.Value.ToString();
                        formComponentValues.Add(vo);
                        break;
                    }
                }

                request.FormComponentValues_ = formComponentValues;
                request.Approvers            = processinstance.Approvers;           //审批人userid列表,最大列表长度:20。多个审批人用逗号分隔,按传入的顺序依次审批
                request.OriginatorUserId     = processinstance.OriginatorUserId;    //审批实例发起人的userid
                request.DeptId     = processinstance.OriginatorDeptId;              //发起人所在的部门,如果发起人属于根部门,传-1
                request.CcList     = Utils.List2String(processinstance.CcUserids);  //(可选)抄送人userid列表,最大列表长度:20。多个抄送人用逗号分隔
                request.CcPosition = processinstance.CcPosition;                    //(可选)抄送时间,分为(START, FINISH, START_FINISH)
                OapiProcessinstanceCreateResponse response = client.Execute(request, accessToken);
                if (response.Errcode == 0)
                {
                    return(response.ProcessInstanceId);
                }
                else
                {
                    throw new Exception(response.Errcode.ToString());
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
示例#2
0
        /// <summary>
        /// 获取单个审批实例
        /// </summary>
        /// <param name="accessToken">accessToken</param>
        /// <param name="process_instance_id">审批实例id</param>
        /// <returns></returns>
        public static Processinstance GetListIds(string accessToken, string process_instance_id)
        {
            try
            {
                DefaultDingTalkClient         client  = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/processinstance/get");
                OapiProcessinstanceGetRequest request = new OapiProcessinstanceGetRequest();
                request.ProcessInstanceId = process_instance_id;
                OapiProcessinstanceGetResponse response = client.Execute(request, accessToken);
                if (response.Errcode == 0)
                {
                    Processinstance processinstance = new Processinstance();
                    processinstance.Title               = response.ProcessInstance.Title;
                    processinstance.CreateTime          = response.ProcessInstance.CreateTime;
                    processinstance.FinishTime          = response.ProcessInstance.FinishTime;
                    processinstance.OriginatorUserId    = response.ProcessInstance.OriginatorUserid;
                    processinstance.OriginatorDeptId    = Convert.ToInt32(response.ProcessInstance.OriginatorDeptId);
                    processinstance.Status              = response.ProcessInstance.Status;
                    processinstance.CcUserids           = response.ProcessInstance.CcUserids;
                    processinstance.Result              = response.ProcessInstance.Result;
                    processinstance.BizAction           = response.ProcessInstance.BizAction;
                    processinstance.BusinessId          = response.ProcessInstance.BusinessId;
                    processinstance.OriginatorDeptName  = response.ProcessInstance.OriginatorDeptName;
                    processinstance.FormComponentValues = new List <FormComponentValue>();
                    foreach (OapiProcessinstanceGetResponse.FormComponentValueVoDomain item in response.ProcessInstance.FormComponentValues)
                    {
                        FormComponentValue form = new FormComponentValue();
                        form.Name     = item.Name;
                        form.Value    = item.Value;
                        form.ExtValue = item.ExtValue;
                        processinstance.FormComponentValues.Add(form);
                    }

                    foreach (OapiProcessinstanceGetResponse.OperationRecordsVoDomain item in response.ProcessInstance.OperationRecords)
                    {
                        OperationRecord model = new OperationRecord();
                        model.UserId          = item.Userid;
                        model.Date            = Convert.ToDateTime(item.Date);;
                        model.OperationType   = item.OperationType;
                        model.OperationResult = item.OperationResult;
                        model.Remark          = item.Remark;
                        processinstance.OperationRecords.Add(model);
                    }
                    foreach (OapiProcessinstanceGetResponse.TaskTopVoDomain item in response.ProcessInstance.Tasks)
                    {
                        Task model = new Task();
                        model.UserId     = item.Userid;
                        model.TaskStatus = item.TaskStatus;
                        model.TaskResult = item.TaskResult;
                        model.CreateTime = Convert.ToDateTime(item.CreateTime);
                        model.FinishTime = Convert.ToDateTime(item.FinishTime);
                        processinstance.Tasks.Add(model);
                    }
                    return(processinstance);
                }
                else
                {
                    throw new Exception(response.Errcode.ToString());
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }