发起审批前,要知道是发起审批的哪一个模板,需要模板的ID,下面是获取方法:
在设计界面的URL里面获取。我是多个模板的ID统一保存到后台的,所以有一个类
namespace ReviewOrderEntity
{
public class ExaminnationEntity
{
private string _exa001;
private string _exa002;
/// <summary>
/// 审批表单名
/// </summary>
public string EXA001
{
get
{
return _exa001;
}
set
{
_exa001 = value;
}
}
/// <summary>
/// 审批ID
/// </summary>
public string EXA002
{
get
{
return _exa002;
}
set
{
_exa002 = value;
}
}
}
}
发起审批的结果怎样,需要根据审批结果判断是否成功
namespace DDHelper
{
public class ApprovalResult
{
/// <summary>
/// 接口开启或关闭状态
/// </summary>
public int ding_open_errcode
{
get;
set;
} = 0;
/// <summary>
/// 发送审批消息是否成功
/// </summary>
public bool is_success
{
get;
set;
} = false;
/// <summary>
/// 审批实例id
/// </summary>
public string process_instance_id
{
get;
set;
}
/// <summary>
///
/// </summary>
public string request_id
{
get;
set;
}
}
}
/// <summary>
/// 消息送审,并得到送审的消息
/// </summary>
void getOrderForPara ( string accessToken )
{
try
{
if ( string . IsNullOrEmpty ( AppSetting . corpid ) )
return;
if ( modelExa == null )
return;
//获取审批人、终审人等
if ( getUserData ( ) == false )
return;
appResult = new List<ApprovalResult> ( );
//headerList 发起审批的表单实体
foreach ( OrderHeaderEntity header in headerList )
{
if ( header . PRO009 != null || header . PRO009 != string . Empty )
{
UserEntity user = userList . Find ( ( k ) =>
{
return k . DBB005 == header . PRO009;
} );
if ( user != null )
{
#region 送审
IDingTalkClient client = new DefaultDingTalkClient ( Urls . get_Examination_and_approval );
SmartworkBpmsProcessinstanceCreateRequest req = new SmartworkBpmsProcessinstanceCreateRequest ( );
//审批ID
req . AgentId = string . IsNullOrEmpty ( AppSetting . Approvers ) == true ? 0 : Convert . ToInt64 ( AppSetting . Approvers );
//审批表单ID
req . ProcessCode = modelExa . EXA002;
//发起人ID
req . OriginatorUserId = user . DBB001;
//发起人所在部门ID
req . DeptId = string . IsNullOrEmpty ( user . DBB003 ) == true ? 0 : Convert . ToInt64 ( user . DBB003 );
//审批人 多人用逗号隔开 按顺序审批
req . Approvers = getUserForAppro ( header . PRO001 );
List<SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain> list = new List<SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain> ( );
//审批单头内容
SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain obj1 = new SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain ( );
obj1 . Name = "ERP单号";
obj1 . Value = header . PRO001;
list . Add ( obj1 );
SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain obj2 = new SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain ( );
obj2 . Name = "项目名称";
obj2 . Value = header . PRO002;
list . Add ( obj2 );
SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain obj3 = new SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain ( );
obj3 . Name = "填表日期";
obj3 . Value = header . PRO003;
list . Add ( obj3 );
SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain obj4 = new SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain ( );
obj4 . Name = "签订单位";
obj4 . Value = header . PRO004;
list . Add ( obj4 );
SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain obj5 = new SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain ( );
obj5 . Name = "申请人";
obj5 . Value = header . PRO005;
list . Add ( obj5 );
SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain obj6 = new SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain ( );
obj6 . Name = "备注";
obj6 . Value = header . PRO006;
list . Add ( obj6 );
SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain obj7 = new SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain ( );
obj7 . Name = "交货日期";
obj7 . Value = header . PRO007;
list . Add ( obj7 );
object [ ] obj = new object [ bodyList . FindAll ( ( k ) =>
{
return k . PRP001 == header . PRO001;
} ) . Count ];
int l = 0;
//审批单身内容
foreach ( OrderBodyEntity body in bodyList . FindAll ( ( k ) =>
{
return k . PRP001 == header . PRO001;
} ) )
{
SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain obj9 = new SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain ( );
obj9 . Name = "生产设备名称";
obj9 . Value = body . PRP003;
SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain obj10 = new SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain ( );
obj10 . Name = "型号";
obj10 . Value = body . PRP004;
SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain obj11 = new SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain ( );
obj11 . Name = "数量";
obj11 . Value = body . PRP005 . ToString ( );
SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain obj12 = new SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain ( );
obj12 . Name = "生产类型";
obj12 . Value = body . PRP006;
SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain obj13 = new SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain ( );
obj13 . Name = "方向";
obj13 . Value = body . PRP007;
obj [ l ] = new object [ ] { obj9 ,obj10 ,obj11 ,obj12 ,obj13 };
l++;
}
SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain obj14 = new SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain ( );
obj14 . Name = "序号:00";
obj14 . Value = FastJSON . JSON . ToJSON ( obj );
list . Add ( obj14 );
req . FormComponentValues_ = list;
SmartworkBpmsProcessinstanceCreateResponse rsp = client . Execute ( req ,accessToken );
ApprovalResult result = XmlUtil . ReadXmlToApprovalResult ( rsp . Body );
result . request_id = header . PRO001;
appResult . Add ( result );
#endregion
}
}
}
}
catch ( Exception ex )
{
Utility . LogHelper . WriteException ( "错误:" + ex . StackTrace + "警告:" + ex . Message ,ex );
throw new Exception ( ex . Message );
}
}
注意:里面
SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain obj1 = new SmartworkBpmsProcessinstanceCreateRequest . FormComponentValueVoDomain ( );
obj1 . Name = "ERP单号";
obj1 . Value = header . PRO001;
list . Add ( obj1 );
中的obj1 . Name = "ERP单号"; 就是你设计表单的栏位名子
obj1 . Value = header . PRO001;是具体的值
到此处,钉钉送审就算完成了。后面就是根据回调函数,获取审批结果,会写数据库单据状态。由于本人学识有限,回调一直调试不通,所以通过循环获取单据状态的办法完成此步骤,此处就不写了,如果有详细的说明博客,帮忙推荐,谢谢。