技术答疑.常用SQL.查询指定单据在指定用户下的待办任务
【应用场景】
查询指定单据在指定用户下的待办任务,查询结果可用于判断用户执行审核操作时,到底是走工作流审批还是传统审批。
【案例演示】
查询某张采购订单在demo用户下的待办任务信息,用于判断demo用户是否有权限进行审批操作,判断是用工作流审批还是传统审批。
<1>查询当前单据的待办任务。
如果能查到待办任务,表示接下来的审批操作将走工作流审批。
如果查不到待办任务,需进一步分析该单是个什么情况。
-- 查询用户内码 DECLARE @FUSERID INT; SELECT @FUSERID = FUSERID FROM T_SEC_USER WHERE FNAME = 'demo'; -- 查询单据内码 DECLARE @FKEYVALUE INT; SELECT @FKEYVALUE = FID FROM T_PUR_POORDER WHERE FBILLNO = 'CGDD002058'; -- 业务对象标识 DECLARE @FOBJECTTYPEID VARCHAR(36); SET @FOBJECTTYPEID = 'PUR_PurchaseOrder'; -- 查询指定单据是否存在指定用户的待办任务 -- 【注意】如果某个单据,既找不到某个用户的待办任务,又找不到某个用户不能处理的原因,该单将走传统审批。 SELECT APPROVAL.FKEYVALUE , ASSIGN.FASSIGNID FROM T_WF_PROCINST PROCINST INNER JOIN T_WF_ASSIGN ASSIGN ON ASSIGN.FPROCINSTID = PROCINST.FPROCINSTID INNER JOIN T_WF_ACTINST ACTINST ON ASSIGN.FACTINSTID = ACTINST.FACTINSTID INNER JOIN T_WF_APPROVALASSIGN APPROVAL ON APPROVAL.FASSIGNID = ASSIGN.FASSIGNID INNER JOIN T_WF_RECEIVER RECIVER ON RECIVER.FASSIGNID = ASSIGN.FASSIGNID LEFT JOIN T_WF_APPROVALITEM ITEM ON ITEM.FAPPROVALASSIGNID = APPROVAL.FAPPROVALASSIGNID AND ITEM.FRECEIVERID = RECIVER.FRECEIVERID WHERE --流程实例处于IDLE状态 PROCINST.FSTATUS = '2' AND --节点处于IDLE状态 ACTINST.FSTATUS = '2' AND --当前任务为未完成状态 ASSIGN.FSTATUS = '0' AND --当前任务没有锁定或者锁定人是当前用户 ( APPROVAL.FISLOCKED = '0' OR ( APPROVAL.FISLOCKED = '1' AND APPROVAL.FLOCKEDUSERID = @FUSERID ) ) AND ( RECIVER.FRECEIVERID = @FUSERID OR EXISTS ( SELECT 1 FROM T_WF_ENTRUSTRECEIVER C_ENTRUSTRECEIVER WHERE RECIVER.FID = C_ENTRUSTRECEIVER.FID AND FCONSIGNOR = @FUSERID ) ) AND ( ITEM.FSTATUS IS NULL OR ITEM.FSTATUS = '0' ) AND APPROVAL.FOBJECTTYPEID = @FOBJECTTYPEID AND APPROVAL.FKEYVALUE = @FKEYVALUE;
<2>查询当前单据的待办任务的当前状态和处理权限。
可能的情况有:
(1)流程挂起了。
(2)流程正在分配处理人。
(3)流程有其它用户正在处理中。
(4)当前用户不是当前单据在流程的当前节点的处理人,无权审批。
(5)查不到待办任务。
-- 查询用户内码 DECLARE @FUSERID INT; SELECT @FUSERID = FUSERID FROM T_SEC_USER WHERE FNAME = 'yh'; -- 查询单据内码 DECLARE @FKEYVALUE INT; SELECT @FKEYVALUE = FID FROM T_PUR_POORDER WHERE FBILLNO = 'CGDD002058'; -- 业务对象标识 DECLARE @FOBJECTTYPEID VARCHAR(36); SET @FOBJECTTYPEID = 'PUR_PurchaseOrder'; -- 查询指定单据的待办任务状态,以及指定用户是否是当前待办任务的处理人 -- 【注意】如果某个单据,既找不到某个用户的待办任务,又找不到某个用户不能处理的原因,该单将走传统审批。 SELECT FKEYVALUE , PROCINST.FSTATUS [流程状态(1完成2运行中3挂起4终止5暂停)] , CASE WHEN PROCINST.FSTATUS = 0 OR ASSIGN.FSTATUS = 1 THEN 1 ELSE 0 END AS 流程正在分配处理人 , APPROVAL.FISLOCKED 流程已有其他用户在处理 , RECIVER.FNOPERMISSION 您不是流程当前节点的处理人 FROM T_WF_PROCINST PROCINST INNER JOIN T_WF_PIBIMAP PIBIMAP ON PROCINST.FPROCINSTID = PIBIMAP.FPROCINSTID LEFT JOIN T_WF_ASSIGN ASSIGN ON PROCINST.FPROCINSTID = ASSIGN.FPROCINSTID AND ASSIGN.FSTATUS = 1 AND PROCINST.FSTATUS = 2 AND ASSIGN.FCOMPLETEDTIME IS NOT NULL AND ASSIGN.FCOMPLETEDTIME > PROCINST.FMODIFYTIME LEFT JOIN ( SELECT C_ASSIGN.FPROCINSTID , 1 FISLOCKED FROM T_WF_APPROVALASSIGN C_APPROVAL INNER JOIN T_WF_ASSIGN C_ASSIGN ON C_APPROVAL.FASSIGNID = C_ASSIGN.FASSIGNID INNER JOIN T_WF_RECEIVER C_RECIVER ON C_RECIVER.FASSIGNID = C_ASSIGN.FASSIGNID WHERE C_ASSIGN.FSTATUS = 0 AND ( C_RECIVER.FRECEIVERID = @FUSERID OR EXISTS ( SELECT 1 FROM T_WF_ENTRUSTRECEIVER C_ENTRUSTRECEIVER WHERE C_RECIVER.FID = C_ENTRUSTRECEIVER.FID AND FCONSIGNOR = @FUSERID ) ) AND C_APPROVAL.FISLOCKED = '1' AND C_APPROVAL.FLOCKEDUSERID <> @FUSERID ) APPROVAL ON PROCINST.FPROCINSTID = APPROVAL.FPROCINSTID LEFT JOIN ( SELECT C_ASSIGN.FPROCINSTID , 1 FNOPERMISSION FROM T_WF_ASSIGN C_ASSIGN WHERE C_ASSIGN.FSTATUS = 0 AND NOT EXISTS ( SELECT 1 FROM T_WF_RECEIVER C_RECIVER WHERE C_RECIVER.FASSIGNID = C_ASSIGN.FASSIGNID AND ( C_RECIVER.FRECEIVERID = @FUSERID OR EXISTS ( SELECT 1 FROM T_WF_ENTRUSTRECEIVER C_ENTRUSTRECEIVER WHERE C_RECIVER.FID = C_ENTRUSTRECEIVER.FID AND FCONSIGNOR = @FUSERID ) ) ) ) RECIVER ON PROCINST.FPROCINSTID = RECIVER.FPROCINSTID WHERE ( PROCINST.FSTATUS = 0 OR PROCINST.FSTATUS = 2 OR PROCINST.FSTATUS = 3 ) AND FOBJECTTYPEID = @FOBJECTTYPEID AND FKEYVALUE = @FKEYVALUE;
<3>查询当前单据是否存在运行中的流程实例。
只要单据有运行中的流程实例,就必须走工作流审批。
-- 查询单据内码 DECLARE @FKEYVALUE INT; SELECT @FKEYVALUE = FID FROM T_PUR_POORDER WHERE FBILLNO = 'CGDD002058'; -- 业务对象标识 DECLARE @FOBJECTTYPEID VARCHAR(36); SET @FOBJECTTYPEID = 'PUR_PurchaseOrder'; -- 查询指定单据是否存在运行中的流程实例 SELECT DISTINCT A.FKEYVALUE FROM T_WF_PIBIMAP A LEFT JOIN T_WF_PROCINST B ON A.FPROCINSTID = B.FPROCINSTID WHERE A.FKEYVALUE = @FKEYVALUE AND A.FOBJECTTYPEID = @FOBJECTTYPEID AND ( ISNULL(B.FSTATUS, '0') NOT IN ( '1', '4' ) );
---------------------------------------------------------------------------------------------------------
【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696
技术答疑.常用SQL.查询指定单据在指定用户下的待办任务
【应用场景】查询指定单据在指定用户下的待办任务,查询结果可用于判断用户执行审核操作时,到底是走工作流审批还是传统审批。【案例演示】...
点击下载文档
本文2024-09-23 03:57:47发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-162221.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章