按照这个帖子https://vip.kingdee.com/article/39631
做了调整后,我根据assginid进行审批流的后台操作,正向操作都正常,
(我设置的审批流是两级审核)
但是再二级审核节点通过插件代码反向驳回时,上级审核人没有接受到消息,而且待办消息中也不存在需要代办的消息,单据处于审核中状态,再次点击审核后,单据直接被审核了。
代码如下:
[code]/************************************************************
* 功能描述(Description): 后台审批流
* 作者(Author): 倪斌斌
* 日期(Create Date): 2019/3/18 14:48:57
*
* 修改记录(Revision History):
* R1:
* 修改人:
* 修改日期:
* 修改事项:
* **********************************************************/
using Kingdee.BOS;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Orm;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceFacade.KDServiceFx;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.WebApi.ServicesStub;
using Kingdee.BOS.Workflow.Assignment;
using Kingdee.BOS.Workflow.Interface;
using Kingdee.BOS.Workflow.Models.ApprovalAssignment;
using Kingdee.BOS.Workflow.Models.EnumStatus;
using Kingdee.BOS.Workflow.ServiceHelper;
using Kingdee.BOS.WorkflowMember;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
namespace Unicre.wx.ApiServices.WorkFlow
{
public class WorkFlowService: AbstractWebApiBusinessService
{
public WorkFlowService(KDServiceContext context)
: base(context)
{ }
///
/// 审批单据,actionName为空时,自动寻找第一个同意审批项;
/// 有多个类型为通过的审批项时,可用actionName指定审批项,如actionName="审批通过"
///
/// 待审批项标识
/// 审批意见
/// 是否为审批流
public string ApproveBillByAssignId(string assignId,string disposition, bool isApprovalFlow = false)
{
string _approvalItemId = AssignmentServiceHelper.OpenApprovalItem(this.KDContext.Session.AppContext, this.KDContext.Session.AppContext.UserId, assignId, false);
var _approvalItem = AssignmentServiceHelper.GetApprovalItemById(this.KDContext.Session.AppContext, _approvalItemId);
List
AssignResult approvalAssignResults = assignResults.FirstOrDefault(r => r.ApprovalType == AssignResultApprovalType.Forward);
if (approvalAssignResults == null) throw new Exception("未找到审批项。");
return SubmitWorkflow(assignId, approvalAssignResults.Id, disposition, isApprovalFlow);
}
///
/// 驳回单据,actionName为空时,自动寻找一个驳回审批项;
/// 有多个类型为驳回的审批项时(如驳回、打回发起人),可用actionName指定审批项,如actionName="打回发起人"
///
public string RejectBillByAssignId(string assignId, string disposition, bool isApprovalFlow = false, string actionName = null)
{
string _approvalItemId = AssignmentServiceHelper.OpenApprovalItem(this.KDContext.Session.AppContext, this.KDContext.Session.AppContext.UserId, assignId, false);
var _approvalItem = AssignmentServiceHelper.GetApprovalItemById(this.KDContext.Session.AppContext, _approvalItemId);
List
if (!string.IsNullOrEmpty(actionName))
assignResults = assignResults.Where(r => r.Name.Any(p => p.Value == actionName)).ToList();
else
assignResults = assignResults.OrderBy(r => r.Name.Any(p => p.Value == "打回发起人")).ToList();
AssignResult rejectAssignResults = assignResults.FirstOrDefault(r => r.ApprovalType == AssignResultApprovalType.Reject);
if (rejectAssignResults == null) throw new Exception("未找到驳回审批项。");
return SubmitWorkflow(assignId, rejectAssignResults.Id, disposition, isApprovalFlow,true);
}
private string SubmitWorkflow(string assignId, string actionResult, string disposition, bool isApprovalFlow, bool isRejectAssign = false)
{
DataSet ds = DBUtils.ExecuteDataSet(this.KDContext.Session.AppContext,
@"select b.FASSIGNID,b.FAPPROVALASSIGNID,a.FACTINSTID,b.FObjectTypeId,b.FKeyValue
from t_wf_assign a
join T_WF_APPROVALASSIGN b on a.fassignid=b.fassignid
where a.fassignid = @assignid and a.FSTATUS=0",
new List
{
new SqlParam("@assignid", KDDbType.String, assignId)
});
DataRow row = ds.Tables[0].Rows.Cast
//if (row == null) throw new Exception("未找到待办任务");
if (row == null)
return "未找到待办任务";
string approvalAssignId = row["FAPPROVALASSIGNID"].ToString();
string formId= row["FObjectTypeId"].ToString();
string pKValue= row["FKeyValue"].ToString();
string _approvalItemId = AssignmentServiceHelper.OpenApprovalItem(this.KDContext.Session.AppContext, this.KDContext.Session.AppContext.UserId, assignId, false);
FormMetadata formMetadata = MetaDataServiceHelper.GetFormMetaData(this.KDContext.Session.AppContext, formId);
DynamicObject ObjData = BusinessDataServiceHelper.LoadSingle(this.KDContext.Session.AppContext, pKValue, formMetadata.BusinessInfo.GetDynamicObjectType());
BusinessInfo businessInfo = formMetadata.BusinessInfo;
var _approvalItem = AssignmentServiceHelper.GetApprovalItemById(this.KDContext.Session.AppContext, _approvalItemId);
//if (_approvalItem == null) throw new Exception("待办任务所在的流程实例不在运行中,不能进行处理!");
if (_approvalItem == null)
return "待办任务所在的流程实例不在运行中,不能进行处理!";
_approvalItem.ObjData = ObjData;
_approvalItem.ReceiverPostId = 0;
_approvalItem.ActionResult = actionResult;
_approvalItem.Disposition = disposition.ToString();
AssignResult assignResult = _approvalItem.Actions != null ? _approvalItem.Actions.FirstOrDefault(i => i.Id == actionResult) : null;
AssignResultApprovalType approvalType = assignResult != null ? assignResult.ApprovalType : AssignResultApprovalType.None;
_approvalItem.ActionResultType = approvalType;
_approvalItem.Status = ApprovalItemStatus.Completed;
DateTime timeNow = TimeServiceHelper.GetSystemDateTime(this.KDContext.Session.AppContext);
_approvalItem.CompletedTime = timeNow;
ObjectActivityInstance _activityInstance = AssignmentServiceHelper.ConvertActivityModel(
this.KDContext.Session.AppContext, businessInfo, approvalAssignId, _approvalItem);
var option = OperateOption.Create();
if (isApprovalFlow)
{
ApprovalAssignmentContext assignCtx = new ApprovalAssignmentContext()
{
ApprovalItems = new List
Info = businessInfo,
Option = option
};
assignCtx.NextActHandler = null;
assignCtx.RejectReturn = false;
assignCtx.ActivityInstance = _activityInstance;
if (actionResult == AssignResultApprovalType.Reject.ToString())
{
string actInstId = row["FACTINSTID"].ToString();
Kingdee.BOS.Workflow.App.Core.ProcInstService procInstService = new Kingdee.BOS.Workflow.App.Core.ProcInstService();
var rejectActivityIds = procInstService.GetBackActInstList(this.KDContext.Session.AppContext, actInstId, true).Select(r => r.ActivityId);
//if (!rejectActivityIds.Any()) throw new Exception("无驳回节点");
if (!rejectActivityIds.Any())
return "无驳回节点";
assignCtx.Target = rejectActivityIds.FirstOrDefault();
}
ApprovalAssignmentServiceHelper.SubmitApprovalItem(this.KDContext.Session.AppContext, assignCtx);
return "ok";
}
else
{
ApprovalAssignmentContext assignCtx = new ApprovalAssignmentContext()
{
ApprovalItems = new List
Info = businessInfo,
Option = option
};
assignCtx.NextActHandler = null;
assignCtx.RejectReturn = isRejectAssign;
assignCtx.ActivityInstance = _activityInstance;
if (actionResult == AssignResultApprovalType.Reject.ToString())
{
string actInstId = row["FACTINSTID"].ToString();
Kingdee.BOS.Workflow.App.Core.ProcInstService procInstService = new Kingdee.BOS.Workflow.App.Core.ProcInstService();
var rejectActivityIds = procInstService.GetBackActInstList(this.KDContext.Session.AppContext, actInstId, true).Select(r => r.ActivityId);
//if (!rejectActivityIds.Any()) throw new Exception("无驳回节点");
if (!rejectActivityIds.Any())
return "无驳回节点";
assignCtx.Target = rejectActivityIds.FirstOrDefault();
//var userlists= procInstService.GetBackActInstList(this.KDContext.Session.AppContext, actInstId, true).Select(r => r.UserList);
//if (!userlists.Any())
// return "无驳回处理人";
//var nextact = new Dictionary
//nextact.Add(0, userlists.FirstOrDefault());
//assignCtx.NextActHandler = nextact;
}
IOperationResult result = new OperationResult
{
IsSuccess = false
};
result = AssignmentServiceHelper.SubmitApprovalItem(this.KDContext.Session.AppContext, assignCtx);
return result.IsSuccess.ToString();
}
}
}
}
[/code]审批通过调用代码:
[code]string update_result = InvokeHelper.AbstractWebApiBusinessService("Unicre.wx.ApiServices.WorkFlow.WorkFlowService.ApproveBillByAssignId,Unicre.wx.ApiServices", new List
Log.writeLog("审批通过:" + pKValue + "\r\n返回结果:" + update_result.ToString());
}[/code]审批驳回调用代码:
[code]string update_result = InvokeHelper.AbstractWebApiBusinessService("Unicre.wx.ApiServices.WorkFlow.WorkFlowService.RejectBillByAssignId,Unicre.wx.ApiServices", new List
Log.writeLog("审批驳回:" + pKValue + "\r\n返回结果:" + update_result.ToString());
}[/code]哪位大神救救急啊~~~~~
推荐阅读