# 流程列表常见SQL

# 一、开启统一待办版本

## 1.1、待办流程

```sql
select t1.id,
       t1.requestid,
       t1.workflowtype,
       t1.workflowid,
       t1.nodeid,
       t1.userid,
       t1.showorder,
       t1.receivedatetime,
       case
         when t1.operatedatetime is null then t1.receivedatetime
         else t1.operatedatetime end       operatedatetime,
       t1.isprocessed,
       t1.needwfback,
       t1.isbereject,
       t1.isremark,
       t1.preisremark,
       t1.viewdatetime,
       t1.supervisionstatus,
       t1.requestlogid,
       t1.overtimedatetime,
       t1.forwardright,
       t1.cid,
       t1.creater,
       t1.status,
       t1.requestname,
       t1.requestnamehtml,
       t1.requestmark,
       t1.requestlevel,
       t1.seclevel,
       t1.requestnametitle,
       t1.lastfeedbackoperator,
       t1.lastfeedbackdatetime,
       t1.flowstatus,
       t1.createdatetime,
       t1.finishdatetime,
       t1.creatorcode,
       t1.creatorsubcom,
       t1.creatordept,
       t1.creatorjob,
       t1.beagentuserid,
       t1.datasrc,
       t1.module,
       t1.create_time,
       t1.update_time,
       t1.creator,
       t1.delete_type,
       t1.tenant_key,
       t1.last_comment_time,
       t1.minovertime,
       t1.firstviewdatetime,
       (case
          when t1.requestnametitle is null then t1.requestname
          else t1.requestnametitle end) as requestnameorder,
       t1.user_master_id,
       t1.trigger_source,
       currentnodeid,
       t1.planfinishdatetime,
       workflow_code,
       current_nodename,
       sys_code,
       request_code,
       sys_id,
       viewtype
from (select t1.id,
             t1.requestid,
             t1.workflowtype,
             t1.workflowid,
             t1.nodeid,
             t1.userid,
             t1.showorder,
             t1.receivedatetime,
             case
               when t1.operatedatetime is null then t1.receivedatetime
               else t1.operatedatetime end       operatedatetime,
             t1.isprocessed,
             t1.needwfback,
             t1.isbereject,
             t1.isremark,
             t1.preisremark,
             t1.viewdatetime,
             t1.supervisionstatus,
             t1.requestlogid,
             t1.overtimedatetime,
             t1.forwardright,
             t1.cid,
             t1.creater,
             t1.status,
             t1.requestname,
             t1.requestnamehtml,
             t1.requestmark,
             t1.requestlevel,
             t1.seclevel,
             t1.requestnametitle,
             t1.lastfeedbackoperator,
             t1.lastfeedbackdatetime,
             t1.flowstatus,
             t1.createdatetime,
             t1.finishdatetime,
             t1.creatorcode,
             t1.creatorsubcom,
             t1.creatordept,
             t1.creatorjob,
             t1.beagentuserid,
             t1.datasrc,
             t1.module,
             t1.create_time,
             t1.update_time,
             t1.creator,
             t1.delete_type,
             t1.tenant_key,
             t1.last_comment_time,
             t1.minovertime,
             t1.firstviewdatetime,
             (case
                when t1.requestnametitle is null then t1.requestname
                else t1.requestnametitle end) as requestnameorder,
             t1.trigger_source,
             t1.user_master_id,
             -1                               as currentnodeid,
             ''                               as workflow_code,
             ''                               as current_nodename,
             ''                               as sys_code,
             ''                               as request_code,
             -1                               as sys_id,
             -1                               as viewtype,
             t1.planfinishdatetime
      from wfc_operate_todo t1
      WHERE ((t1.flowstatus <> 0 or (t1.flowstatus = 0 and
                                     (t1.trigger_source in (1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 104, 108) or
                                      t1.isremark in (40, 41, 80, 81, 20, 21, 60, 61)))) AND t1.tenant_key = {租户key} AND
             t1.module = 0 AND t1.delete_type = 0 AND
             t1.user_master_id = {用户ID} AND t1.no_disturb_flag = 0 AND (1 = 1) AND (1 = 1))
      union all select reqbase.request_id  as     id,
                       reqbase.request_id  as     requestid,
                       reqbase.sys_id      as     workflowtype,
                       reqbase.workflow_id as     workflowid,
                       -1                  as     nodeid,
                       iutdata.userid,
                       0                   as     showorder,
                       receivedatetime,
                       case
                         when operatedatetime is null then receivedatetime
                         else operatedatetime end operatedatetime,
                       0                   as     isprocessed,
                       0                   as     needwfback,
                       isbereject,
                       isremark,
                       preisremark,
                       null                as     viewdatetime,
                       0                   as     supervisionstatus,
                       -1                  as     requestlogid,
                       null                as     overtimedatetime,
                       0                   as     forwardright,
                       -1                  as     cid,
                       creater,
                       current_status      as     status,
                       request_name        as     requestname,
                       request_name        as     requestnamehtml,
                       request_mark        as     requestmark,
                       request_level       as     requestlevel,
                       -1                  as     seclevel,
                       request_name        as     requestnametitle,
                       -1                  as     lastfeedbackoperator,
                       null                as     lastfeedbackdatetime,
                       flowstatus,
                       createdatetime,
                       finishdatetime,
                       creatorcode,
                       creatorsubcom,
                       creatordept,
                       creatorjob,
                       -1                  as     beagentuserid,
                       3                   as     datasrc,
                       reqbase.sdk_module  as     module,
                       iutdata.create_time,
                       iutdata.update_time,
                       iutdata.creator,
                       iutdata.delete_type,
                       iutdata.tenant_key,
                       null                as     last_comment_time,
                       null                as     minovertime,
                       null                as     firstviewdatetime,
                       request_name        as     requestnameorder,
                       -1                  as     trigger_source,
                       iutdata.user_master_id,
                       -1                  as     currentnodeid,
                       iutdata.workflow_code,
                       current_nodename,
                       iutdata.sys_code,
                       iutdata.request_code,
                       reqbase.sys_id,
                       viewtype,
                       null                as     planfinishdatetime
                from wfl_iut_todo_data iutdata
                       inner join wfl_iut_request_base reqbase on iutdata.request_id = reqbase.request_id
                WHERE (iutdata.tenant_key = {租户key} AND iutdata.delete_type = 0 AND iutdata.workflow_id > 0 AND
                       iutdata.request_id > 0 AND iutdata.sys_id > 0 AND reqbase.tenant_key = {租户key} AND
                       reqbase.delete_type = 0 AND reqbase.workflow_id > 0 AND reqbase.request_id > 0 AND
                       reqbase.sys_id > 0 AND iutdata.user_master_id = {用户ID} AND
                       reqbase.flowstatus <> 0 AND 1 = 1 AND iutdata.sys_id in (select distinct sys_id
                                                                                from wfl_iut_sysinfo
                                                                                where tenant_key = {租户key}
                                                                                  and delete_type = 0
                                                                                  and show_pc = 1) AND (1 = 1) AND
                       reqbase.sdk_module IN (0))) t1
ORDER BY last_comment_time DESC, creater, requestid DESC
```

## 1.2、已办流程
```sql
select t1.id,
       t1.requestid,
       t1.workflowtype,
       t1.workflowid,
       t1.nodeid,
       t1.userid,
       t1.showorder,
       t1.receivedatetime,
       case
         when t1.operatedatetime is null then t1.receivedatetime
         else t1.operatedatetime end       operatedatetime,
       t1.isprocessed,
       t1.needwfback,
       t1.isbereject,
       t1.isremark,
       t1.preisremark,
       t1.viewdatetime,
       t1.supervisionstatus,
       t1.requestlogid,
       t1.overtimedatetime,
       t1.forwardright,
       t1.cid,
       t1.creater,
       t1.status,
       t1.requestname,
       t1.requestnamehtml,
       t1.requestmark,
       t1.requestlevel,
       t1.seclevel,
       t1.requestnametitle,
       t1.lastfeedbackoperator,
       t1.lastfeedbackdatetime,
       t1.flowstatus,
       t1.createdatetime,
       t1.finishdatetime,
       t1.creatorcode,
       t1.creatorsubcom,
       t1.creatordept,
       t1.creatorjob,
       t1.beagentuserid,
       t1.datasrc,
       t1.module,
       t1.create_time,
       t1.update_time,
       t1.creator,
       t1.delete_type,
       t1.tenant_key,
       t1.last_comment_time,
       t1.minovertime,
       t1.firstviewdatetime,
       (case
          when t1.requestnametitle is null then t1.requestname
          else t1.requestnametitle end) as requestnameorder,
       t1.user_master_id,
       t1.trigger_source,
       currentnodeid,
       workflow_code,
       current_nodename,
       sys_code,
       request_code,
       sys_id,
       viewtype
from (select t1.id,
             t1.requestid,
             t1.workflowtype,
             t1.workflowid,
             t1.nodeid,
             t1.userid,
             t1.showorder,
             t1.receivedatetime,
             case
               when t1.operatedatetime is null then t1.receivedatetime
               else t1.operatedatetime end       operatedatetime,
             t1.isprocessed,
             t1.needwfback,
             t1.isbereject,
             t1.isremark,
             t1.preisremark,
             t1.viewdatetime,
             t1.supervisionstatus,
             t1.requestlogid,
             t1.overtimedatetime,
             t1.forwardright,
             t1.cid,
             t1.creater,
             t1.status,
             t1.requestname,
             t1.requestnamehtml,
             t1.requestmark,
             t1.requestlevel,
             t1.seclevel,
             t1.requestnametitle,
             t1.lastfeedbackoperator,
             t1.lastfeedbackdatetime,
             t1.flowstatus,
             t1.createdatetime,
             t1.finishdatetime,
             t1.creatorcode,
             t1.creatorsubcom,
             t1.creatordept,
             t1.creatorjob,
             t1.beagentuserid,
             t1.datasrc,
             t1.module,
             t1.create_time,
             t1.update_time,
             t1.creator,
             t1.delete_type,
             t1.tenant_key,
             t1.last_comment_time,
             t1.minovertime,
             t1.firstviewdatetime,
             (case
                when t1.requestnametitle is null then t1.requestname
                else t1.requestnametitle end) as requestnameorder,
             t1.trigger_source,
             t1.user_master_id,
             -1                               as currentnodeid,
             ''                               as workflow_code,
             ''                               as current_nodename,
             ''                               as sys_code,
             ''                               as request_code,
             -1                               as sys_id,
             -1                               as viewtype
      from wfc_operate_done t1
      WHERE (t1.tenant_key = {租户key} AND t1.module = 0 AND t1.delete_type = 0 AND 
             t1.user_master_id = {用户ID} AND (1 = 1) AND (1 = 1))
      union all select reqbase.request_id  as     id,
                       reqbase.request_id  as     requestid,
                       reqbase.sys_id      as     workflowtype,
                       reqbase.workflow_id as     workflowid,
                       -1                  as     nodeid,
                       iutdata.userid,
                       0                   as     showorder,
                       receivedatetime,
                       case
                         when operatedatetime is null then receivedatetime
                         else operatedatetime end operatedatetime,
                       0                   as     isprocessed,
                       0                   as     needwfback,
                       isbereject,
                       isremark,
                       preisremark,
                       null                as     viewdatetime,
                       0                   as     supervisionstatus,
                       -1                  as     requestlogid,
                       null                as     overtimedatetime,
                       0                   as     forwardright,
                       -1                  as     cid,
                       creater,
                       current_status      as     status,
                       request_name        as     requestname,
                       request_name        as     requestnamehtml,
                       request_mark        as     requestmark,
                       request_level       as     requestlevel,
                       -1                  as     seclevel,
                       request_name        as     requestnametitle,
                       -1                  as     lastfeedbackoperator,
                       null                as     lastfeedbackdatetime,
                       flowstatus,
                       createdatetime,
                       finishdatetime,
                       creatorcode,
                       creatorsubcom,
                       creatordept,
                       creatorjob,
                       -1                  as     beagentuserid,
                       3                   as     datasrc,
                       reqbase.sdk_module  as     module,
                       iutdata.create_time,
                       iutdata.update_time,
                       iutdata.creator,
                       iutdata.delete_type,
                       iutdata.tenant_key,
                       null                as     last_comment_time,
                       null                as     minovertime,
                       null                as     firstviewdatetime,
                       request_name        as     requestnameorder,
                       -1                  as     trigger_source,
                       iutdata.user_master_id,
                       -1                  as     currentnodeid,
                       iutdata.workflow_code,
                       current_nodename,
                       iutdata.sys_code,
                       iutdata.request_code,
                       reqbase.sys_id,
                       viewtype
                from wfl_iut_done_data iutdata
                       inner join wfl_iut_request_base reqbase on iutdata.request_id = reqbase.request_id
                WHERE (iutdata.tenant_key = {租户key} AND iutdata.delete_type = 0 AND iutdata.workflow_id > 0 AND
                       iutdata.request_id > 0 AND iutdata.sys_id > 0 AND reqbase.tenant_key = {租户key} AND
                       reqbase.delete_type = 0 AND reqbase.workflow_id > 0 AND reqbase.request_id > 0 AND
                       reqbase.sys_id > 0 AND iutdata.user_master_id = {用户ID} AND 1 = 1 AND
                       iutdata.sys_id in (select distinct sys_id
                                          from wfl_iut_sysinfo
                                          where tenant_key = {租户key}
                                            and delete_type = 0
                                            and show_pc = 1) AND (1 = 1) AND reqbase.sdk_module IN (0))) t1
ORDER BY last_comment_time DESC, requestid DESC
```

## 1.3、草稿流程
```sql
select t1.id,
       t1.requestid,
       t1.workflowtype,
       t1.workflowid,
       t1.nodeid,
       t1.userid,
       t1.showorder,
       t1.receivedatetime,
       case
         when t1.operatedatetime is null then t1.receivedatetime
         else t1.operatedatetime end       operatedatetime,
       t1.isprocessed,
       t1.needwfback,
       t1.isbereject,
       t1.isremark,
       t1.preisremark,
       t1.viewdatetime,
       t1.supervisionstatus,
       t1.requestlogid,
       t1.overtimedatetime,
       t1.forwardright,
       t1.cid,
       t1.creater,
       t1.status,
       t1.requestname,
       t1.requestnamehtml,
       t1.requestmark,
       t1.requestlevel,
       t1.seclevel,
       t1.requestnametitle,
       t1.lastfeedbackoperator,
       t1.lastfeedbackdatetime,
       t1.flowstatus,
       t1.createdatetime,
       t1.finishdatetime,
       t1.creatorcode,
       t1.creatorsubcom,
       t1.creatordept,
       t1.creatorjob,
       t1.beagentuserid,
       t1.datasrc,
       t1.module,
       t1.create_time,
       t1.update_time,
       t1.creator,
       t1.delete_type,
       t1.tenant_key,
       t1.last_comment_time,
       t1.minovertime,
       t1.firstviewdatetime,
       (case
          when t1.requestnametitle is null then t1.requestname
          else t1.requestnametitle end) as requestnameorder,
       t1.user_master_id,
       t1.trigger_source,
       currentnodeid,
       t1.planfinishdatetime,
       workflow_code,
       current_nodename,
       sys_code,
       request_code,
       sys_id,
       viewtype
from (select t1.id,
             t1.requestid,
             t1.workflowtype,
             t1.workflowid,
             t1.nodeid,
             t1.userid,
             t1.showorder,
             t1.receivedatetime,
             case
               when t1.operatedatetime is null then t1.receivedatetime
               else t1.operatedatetime end       operatedatetime,
             t1.isprocessed,
             t1.needwfback,
             t1.isbereject,
             t1.isremark,
             t1.preisremark,
             t1.viewdatetime,
             t1.supervisionstatus,
             t1.requestlogid,
             t1.overtimedatetime,
             t1.forwardright,
             t1.cid,
             t1.creater,
             t1.status,
             t1.requestname,
             t1.requestnamehtml,
             t1.requestmark,
             t1.requestlevel,
             t1.seclevel,
             t1.requestnametitle,
             t1.lastfeedbackoperator,
             t1.lastfeedbackdatetime,
             t1.flowstatus,
             t1.createdatetime,
             t1.finishdatetime,
             t1.creatorcode,
             t1.creatorsubcom,
             t1.creatordept,
             t1.creatorjob,
             t1.beagentuserid,
             t1.datasrc,
             t1.module,
             t1.create_time,
             t1.update_time,
             t1.creator,
             t1.delete_type,
             t1.tenant_key,
             t1.last_comment_time,
             t1.minovertime,
             t1.firstviewdatetime,
             (case
                when t1.requestnametitle is null then t1.requestname
                else t1.requestnametitle end) as requestnameorder,
             t1.trigger_source,
             t1.user_master_id,
             -1                               as currentnodeid,
             ''                               as workflow_code,
             ''                               as current_nodename,
             ''                               as sys_code,
             ''                               as request_code,
             -1                               as sys_id,
             -1                               as viewtype,
             t1.planfinishdatetime
      from wfc_operate_todo t1
      WHERE (t1.flowstatus = 0 and t1.trigger_source in (0, 11, 101, 102, 103, 105, 109, 110, 111) and
             t1.isremark not in (40, 41, 80, 81, 20, 21, 60, 61) AND t1.tenant_key = {租户key} AND t1.module = 0 AND
             t1.delete_type = 0 AND t1.user_master_id = {用户ID})
      union all select reqbase.request_id  as     id,
                       reqbase.request_id  as     requestid,
                       reqbase.sys_id      as     workflowtype,
                       reqbase.workflow_id as     workflowid,
                       -1                  as     nodeid,
                       iutdata.userid,
                       0                   as     showorder,
                       receivedatetime,
                       case
                         when operatedatetime is null then receivedatetime
                         else operatedatetime end operatedatetime,
                       0                   as     isprocessed,
                       0                   as     needwfback,
                       isbereject,
                       isremark,
                       preisremark,
                       null                as     viewdatetime,
                       0                   as     supervisionstatus,
                       -1                  as     requestlogid,
                       null                as     overtimedatetime,
                       0                   as     forwardright,
                       -1                  as     cid,
                       creater,
                       current_status      as     status,
                       request_name        as     requestname,
                       request_name        as     requestnamehtml,
                       request_mark        as     requestmark,
                       request_level       as     requestlevel,
                       -1                  as     seclevel,
                       request_name        as     requestnametitle,
                       -1                  as     lastfeedbackoperator,
                       null                as     lastfeedbackdatetime,
                       flowstatus,
                       createdatetime,
                       finishdatetime,
                       creatorcode,
                       creatorsubcom,
                       creatordept,
                       creatorjob,
                       -1                  as     beagentuserid,
                       3                   as     datasrc,
                       reqbase.sdk_module  as     module,
                       iutdata.create_time,
                       iutdata.update_time,
                       iutdata.creator,
                       iutdata.delete_type,
                       iutdata.tenant_key,
                       null                as     last_comment_time,
                       null                as     minovertime,
                       null                as     firstviewdatetime,
                       request_name        as     requestnameorder,
                       -1                  as     trigger_source,
                       iutdata.user_master_id,
                       -1                  as     currentnodeid,
                       iutdata.workflow_code,
                       current_nodename,
                       iutdata.sys_code,
                       iutdata.request_code,
                       reqbase.sys_id,
                       viewtype,
                       null                as     planfinishdatetime
                from wfl_iut_todo_data iutdata
                       inner join wfl_iut_request_base reqbase on iutdata.request_id = reqbase.request_id
                WHERE (iutdata.tenant_key = {租户key} AND iutdata.delete_type = 0 AND iutdata.workflow_id > 0 AND
                       iutdata.request_id > 0 AND iutdata.sys_id > 0 AND reqbase.tenant_key = {租户key} AND
                       reqbase.delete_type = 0 AND reqbase.workflow_id > 0 AND reqbase.request_id > 0 AND
                       reqbase.sys_id > 0 AND iutdata.user_master_id = {用户ID} AND
                       reqbase.flowstatus = 0 AND 1 = 1 AND iutdata.sys_id in (select distinct sys_id
                                                                               from wfl_iut_sysinfo
                                                                               where tenant_key = {租户key}
                                                                                 and delete_type = 0
                                                                                 and show_pc = 1) AND (1 = 1) AND
                       reqbase.sdk_module IN (0))) t1
ORDER BY last_comment_time DESC, requestid DESC
```

## 1.4、我发起的
```sql
select t1.id,
       t1.requestid,
       t1.workflowtype,
       t1.workflowid,
       t1.nodeid,
       t1.userid,
       t1.showorder,
       t1.receivedatetime,
       case
         when t1.operatedatetime is null then t1.receivedatetime
         else t1.operatedatetime end       operatedatetime,
       t1.isprocessed,
       t1.needwfback,
       t1.isbereject,
       t1.isremark,
       t1.preisremark,
       t1.viewdatetime,
       t1.supervisionstatus,
       t1.requestlogid,
       t1.overtimedatetime,
       t1.forwardright,
       t1.cid,
       t1.creater,
       t1.status,
       t1.requestname,
       t1.requestnamehtml,
       t1.requestmark,
       t1.requestlevel,
       t1.seclevel,
       t1.requestnametitle,
       t1.lastfeedbackoperator,
       t1.lastfeedbackdatetime,
       t1.flowstatus,
       t1.createdatetime,
       t1.finishdatetime,
       t1.creatorcode,
       t1.creatorsubcom,
       t1.creatordept,
       t1.creatorjob,
       t1.beagentuserid,
       t1.datasrc,
       t1.module,
       t1.create_time,
       t1.update_time,
       t1.creator,
       t1.delete_type,
       t1.tenant_key,
       t1.last_comment_time,
       t1.minovertime,
       t1.firstviewdatetime,
       (case
          when t1.requestnametitle is null then t1.requestname
          else t1.requestnametitle end) as requestnameorder,
       t1.user_master_id,
       t1.trigger_source,
       currentnodeid,
       workflow_code,
       current_nodename,
       sys_code,
       request_code,
       sys_id,
       viewtype
from (select t1.id,
             t1.requestid,
             t1.workflowtype,
             t1.workflowid,
             t1.nodeid,
             t1.userid,
             t1.showorder,
             t1.receivedatetime,
             case
               when t1.operatedatetime is null then t1.receivedatetime
               else t1.operatedatetime end       operatedatetime,
             t1.isprocessed,
             t1.needwfback,
             t1.isbereject,
             t1.isremark,
             t1.preisremark,
             t1.viewdatetime,
             t1.supervisionstatus,
             t1.requestlogid,
             t1.overtimedatetime,
             t1.forwardright,
             t1.cid,
             t1.creater,
             t1.status,
             t1.requestname,
             t1.requestnamehtml,
             t1.requestmark,
             t1.requestlevel,
             t1.seclevel,
             t1.requestnametitle,
             t1.lastfeedbackoperator,
             t1.lastfeedbackdatetime,
             t1.flowstatus,
             t1.createdatetime,
             t1.finishdatetime,
             t1.creatorcode,
             t1.creatorsubcom,
             t1.creatordept,
             t1.creatorjob,
             t1.beagentuserid,
             t1.datasrc,
             t1.module,
             t1.create_time,
             t1.update_time,
             t1.creator,
             t1.delete_type,
             t1.tenant_key,
             t1.last_comment_time,
             t1.minovertime,
             t1.firstviewdatetime,
             (case
                when t1.requestnametitle is null then t1.requestname
                else t1.requestnametitle end) as requestnameorder,
             t1.trigger_source,
             t1.user_master_id,
             -1                               as currentnodeid,
             ''                               as workflow_code,
             ''                               as current_nodename,
             ''                               as sys_code,
             ''                               as request_code,
             -1                               as sys_id,
             -1                               as viewtype
      from wfc_operate_todo t1
      WHERE ((1 = 1)and t1.creator_master_id = {用户ID} AND t1.tenant_key = {租户key} AND t1.module = 0 AND
             t1.delete_type = 0 AND t1.user_master_id = {用户ID} AND (1 = 1) AND
             (1 = 1))
      union select t1.id,
                   t1.requestid,
                   t1.workflowtype,
                   t1.workflowid,
                   t1.nodeid,
                   t1.userid,
                   t1.showorder,
                   t1.receivedatetime,
                   case
                     when t1.operatedatetime is null then t1.receivedatetime
                     else t1.operatedatetime end       operatedatetime,
                   t1.isprocessed,
                   t1.needwfback,
                   t1.isbereject,
                   t1.isremark,
                   t1.preisremark,
                   t1.viewdatetime,
                   t1.supervisionstatus,
                   t1.requestlogid,
                   t1.overtimedatetime,
                   t1.forwardright,
                   t1.cid,
                   t1.creater,
                   t1.status,
                   t1.requestname,
                   t1.requestnamehtml,
                   t1.requestmark,
                   t1.requestlevel,
                   t1.seclevel,
                   t1.requestnametitle,
                   t1.lastfeedbackoperator,
                   t1.lastfeedbackdatetime,
                   t1.flowstatus,
                   t1.createdatetime,
                   t1.finishdatetime,
                   t1.creatorcode,
                   t1.creatorsubcom,
                   t1.creatordept,
                   t1.creatorjob,
                   t1.beagentuserid,
                   t1.datasrc,
                   t1.module,
                   t1.create_time,
                   t1.update_time,
                   t1.creator,
                   t1.delete_type,
                   t1.tenant_key,
                   t1.last_comment_time,
                   t1.minovertime,
                   t1.firstviewdatetime,
                   (case
                      when t1.requestnametitle is null then t1.requestname
                      else t1.requestnametitle end) as requestnameorder,
                   t1.trigger_source,
                   t1.user_master_id,
                   -1                               as currentnodeid,
                   ''                               as workflow_code,
                   ''                               as current_nodename,
                   ''                               as sys_code,
                   ''                               as request_code,
                   -1                               as sys_id,
                   -1                               as viewtype
            from wfc_operate_done t1
            WHERE ((1 = 1)and t1.creator_master_id = {用户ID} AND t1.tenant_key = {租户key} AND t1.module = 0 AND
                   t1.delete_type = 0 AND t1.user_master_id = {用户ID} AND
                   (1 = 1) AND (1 = 1))
      union all select reqbase.request_id  as     id,
                       reqbase.request_id  as     requestid,
                       reqbase.sys_id      as     workflowtype,
                       reqbase.workflow_id as     workflowid,
                       -1                  as     nodeid,
                       iutdata.userid,
                       0                   as     showorder,
                       receivedatetime,
                       case
                         when operatedatetime is null then receivedatetime
                         else operatedatetime end operatedatetime,
                       0                   as     isprocessed,
                       0                   as     needwfback,
                       isbereject,
                       isremark,
                       preisremark,
                       null                as     viewdatetime,
                       0                   as     supervisionstatus,
                       -1                  as     requestlogid,
                       null                as     overtimedatetime,
                       0                   as     forwardright,
                       -1                  as     cid,
                       creater,
                       current_status      as     status,
                       request_name        as     requestname,
                       request_name        as     requestnamehtml,
                       request_mark        as     requestmark,
                       request_level       as     requestlevel,
                       -1                  as     seclevel,
                       request_name        as     requestnametitle,
                       -1                  as     lastfeedbackoperator,
                       null                as     lastfeedbackdatetime,
                       flowstatus,
                       createdatetime,
                       finishdatetime,
                       creatorcode,
                       creatorsubcom,
                       creatordept,
                       creatorjob,
                       -1                  as     beagentuserid,
                       3                   as     datasrc,
                       reqbase.sdk_module  as     module,
                       iutdata.create_time,
                       iutdata.update_time,
                       iutdata.creator,
                       iutdata.delete_type,
                       iutdata.tenant_key,
                       null                as     last_comment_time,
                       null                as     minovertime,
                       null                as     firstviewdatetime,
                       request_name        as     requestnameorder,
                       -1                  as     trigger_source,
                       iutdata.user_master_id,
                       -1                  as     currentnodeid,
                       iutdata.workflow_code,
                       current_nodename,
                       iutdata.sys_code,
                       iutdata.request_code,
                       reqbase.sys_id,
                       viewtype
                from wfl_iut_todo_data iutdata
                       inner join wfl_iut_request_base reqbase on iutdata.request_id = reqbase.request_id
                WHERE (iutdata.tenant_key = {租户key} AND iutdata.delete_type = 0 AND iutdata.workflow_id > 0 AND
                       iutdata.request_id > 0 AND iutdata.sys_id > 0 AND reqbase.tenant_key = {租户key} AND
                       reqbase.delete_type = 0 AND reqbase.workflow_id > 0 AND reqbase.request_id > 0 AND
                       reqbase.sys_id > 0 AND iutdata.user_master_id = {用户ID} AND
                       reqbase.creator_master_id = {用户ID} AND 1 = 1 AND iutdata.sys_id in
                                                                                     (select distinct sys_id
                                                                                      from wfl_iut_sysinfo
                                                                                      where tenant_key = {租户key}
                                                                                        and delete_type = 0
                                                                                        and show_pc = 1) AND (1 = 1) AND
                       reqbase.sdk_module IN (0))
      union all select reqbase.request_id  as     id,
                       reqbase.request_id  as     requestid,
                       reqbase.sys_id      as     workflowtype,
                       reqbase.workflow_id as     workflowid,
                       -1                  as     nodeid,
                       iutdata.userid,
                       0                   as     showorder,
                       receivedatetime,
                       case
                         when operatedatetime is null then receivedatetime
                         else operatedatetime end operatedatetime,
                       0                   as     isprocessed,
                       0                   as     needwfback,
                       isbereject,
                       isremark,
                       preisremark,
                       null                as     viewdatetime,
                       0                   as     supervisionstatus,
                       -1                  as     requestlogid,
                       null                as     overtimedatetime,
                       0                   as     forwardright,
                       -1                  as     cid,
                       creater,
                       current_status      as     status,
                       request_name        as     requestname,
                       request_name        as     requestnamehtml,
                       request_mark        as     requestmark,
                       request_level       as     requestlevel,
                       -1                  as     seclevel,
                       request_name        as     requestnametitle,
                       -1                  as     lastfeedbackoperator,
                       null                as     lastfeedbackdatetime,
                       flowstatus,
                       createdatetime,
                       finishdatetime,
                       creatorcode,
                       creatorsubcom,
                       creatordept,
                       creatorjob,
                       -1                  as     beagentuserid,
                       3                   as     datasrc,
                       reqbase.sdk_module  as     module,
                       iutdata.create_time,
                       iutdata.update_time,
                       iutdata.creator,
                       iutdata.delete_type,
                       iutdata.tenant_key,
                       null                as     last_comment_time,
                       null                as     minovertime,
                       null                as     firstviewdatetime,
                       request_name        as     requestnameorder,
                       -1                  as     trigger_source,
                       iutdata.user_master_id,
                       -1                  as     currentnodeid,
                       iutdata.workflow_code,
                       current_nodename,
                       iutdata.sys_code,
                       iutdata.request_code,
                       reqbase.sys_id,
                       viewtype
                from wfl_iut_done_data iutdata
                       inner join wfl_iut_request_base reqbase on iutdata.request_id = reqbase.request_id
                WHERE (iutdata.tenant_key = {租户key} AND iutdata.delete_type = 0 AND iutdata.workflow_id > 0 AND
                       iutdata.request_id > 0 AND iutdata.sys_id > 0 AND reqbase.tenant_key = {租户key} AND
                       reqbase.delete_type = 0 AND reqbase.workflow_id > 0 AND reqbase.request_id > 0 AND
                       reqbase.sys_id > 0 AND iutdata.user_master_id = {用户ID} AND
                       reqbase.creator_master_id = {用户ID} AND 1 = 1 AND iutdata.sys_id in
                                                                                     (select distinct sys_id
                                                                                      from wfl_iut_sysinfo
                                                                                      where tenant_key = {租户key}
                                                                                        and delete_type = 0
                                                                                        and show_pc = 1) AND (1 = 1) AND
                       reqbase.sdk_module IN (0))) t1
ORDER BY last_comment_time DESC, requestid DESC
```


## 1.5、我直接参与的
```sql
select t1.id,
       t1.requestid,
       t1.workflowtype,
       t1.workflowid,
       t1.nodeid,
       t1.userid,
       t1.showorder,
       t1.receivedatetime,
       case
         when t1.operatedatetime is null then t1.receivedatetime
         else t1.operatedatetime end       operatedatetime,
       t1.isprocessed,
       t1.needwfback,
       t1.isbereject,
       t1.isremark,
       t1.preisremark,
       t1.viewdatetime,
       t1.supervisionstatus,
       t1.requestlogid,
       t1.overtimedatetime,
       t1.forwardright,
       t1.cid,
       t1.creater,
       t1.status,
       t1.requestname,
       t1.requestnamehtml,
       t1.requestmark,
       t1.requestlevel,
       t1.seclevel,
       t1.requestnametitle,
       t1.lastfeedbackoperator,
       t1.lastfeedbackdatetime,
       t1.flowstatus,
       t1.createdatetime,
       t1.finishdatetime,
       t1.creatorcode,
       t1.creatorsubcom,
       t1.creatordept,
       t1.creatorjob,
       t1.beagentuserid,
       t1.datasrc,
       t1.module,
       t1.create_time,
       t1.update_time,
       t1.creator,
       t1.delete_type,
       t1.tenant_key,
       t1.last_comment_time,
       t1.minovertime,
       t1.firstviewdatetime,
       (case
          when t1.requestnametitle is null then t1.requestname
          else t1.requestnametitle end) as requestnameorder,
       t1.user_master_id,
       t1.trigger_source,
       currentnodeid,
       workflow_code,
       current_nodename,
       sys_code,
       request_code,
       sys_id,
       viewtype
from (select t1.id,
             t1.requestid,
             t1.workflowtype,
             t1.workflowid,
             t1.nodeid,
             t1.userid,
             t1.showorder,
             t1.receivedatetime,
             case
               when t1.operatedatetime is null then t1.receivedatetime
               else t1.operatedatetime end       operatedatetime,
             t1.isprocessed,
             t1.needwfback,
             t1.isbereject,
             t1.isremark,
             t1.preisremark,
             t1.viewdatetime,
             t1.supervisionstatus,
             t1.requestlogid,
             t1.overtimedatetime,
             t1.forwardright,
             t1.cid,
             t1.creater,
             t1.status,
             t1.requestname,
             t1.requestnamehtml,
             t1.requestmark,
             t1.requestlevel,
             t1.seclevel,
             t1.requestnametitle,
             t1.lastfeedbackoperator,
             t1.lastfeedbackdatetime,
             t1.flowstatus,
             t1.createdatetime,
             t1.finishdatetime,
             t1.creatorcode,
             t1.creatorsubcom,
             t1.creatordept,
             t1.creatorjob,
             t1.beagentuserid,
             t1.datasrc,
             t1.module,
             t1.create_time,
             t1.update_time,
             t1.creator,
             t1.delete_type,
             t1.tenant_key,
             t1.last_comment_time,
             t1.minovertime,
             t1.firstviewdatetime,
             (case
                when t1.requestnametitle is null then t1.requestname
                else t1.requestnametitle end) as requestnameorder,
             t1.trigger_source,
             t1.user_master_id,
             -1                               as currentnodeid,
             ''                               as workflow_code,
             ''                               as current_nodename,
             ''                               as sys_code,
             ''                               as request_code,
             -1                               as sys_id,
             -1                               as viewtype
      from wfc_operate_todo t1
      WHERE ((t1.flowstatus not in (7, 8) or (t1.flowstatus = 7 and t1.creater = {用户ID})) AND
             t1.tenant_key = {租户key} AND t1.module = 0 AND t1.delete_type = 0 AND
             (1 = 1) AND (1 = 1))
        and t1.user_master_id = {用户ID}
      union select t1.id,
                   t1.requestid,
                   t1.workflowtype,
                   t1.workflowid,
                   t1.nodeid,
                   t1.userid,
                   t1.showorder,
                   t1.receivedatetime,
                   case
                     when t1.operatedatetime is null then t1.receivedatetime
                     else t1.operatedatetime end       operatedatetime,
                   t1.isprocessed,
                   t1.needwfback,
                   t1.isbereject,
                   t1.isremark,
                   t1.preisremark,
                   t1.viewdatetime,
                   t1.supervisionstatus,
                   t1.requestlogid,
                   t1.overtimedatetime,
                   t1.forwardright,
                   t1.cid,
                   t1.creater,
                   t1.status,
                   t1.requestname,
                   t1.requestnamehtml,
                   t1.requestmark,
                   t1.requestlevel,
                   t1.seclevel,
                   t1.requestnametitle,
                   t1.lastfeedbackoperator,
                   t1.lastfeedbackdatetime,
                   t1.flowstatus,
                   t1.createdatetime,
                   t1.finishdatetime,
                   t1.creatorcode,
                   t1.creatorsubcom,
                   t1.creatordept,
                   t1.creatorjob,
                   t1.beagentuserid,
                   t1.datasrc,
                   t1.module,
                   t1.create_time,
                   t1.update_time,
                   t1.creator,
                   t1.delete_type,
                   t1.tenant_key,
                   t1.last_comment_time,
                   t1.minovertime,
                   t1.firstviewdatetime,
                   (case
                      when t1.requestnametitle is null then t1.requestname
                      else t1.requestnametitle end) as requestnameorder,
                   t1.trigger_source,
                   t1.user_master_id,
                   -1                               as currentnodeid,
                   ''                               as workflow_code,
                   ''                               as current_nodename,
                   ''                               as sys_code,
                   ''                               as request_code,
                   -1                               as sys_id,
                   -1                               as viewtype
            from wfc_operate_done t1
            WHERE ((t1.flowstatus not in (7, 8) or (t1.flowstatus = 7 and t1.creater = {用户ID})) AND
                   t1.tenant_key = {租户key} AND t1.module = 0 AND t1.delete_type = 0 AND (1 = 1) AND (1 = 1))
              and t1.user_master_id = {用户ID}
      union all select reqbase.request_id  as     id,
                       reqbase.request_id  as     requestid,
                       reqbase.sys_id      as     workflowtype,
                       reqbase.workflow_id as     workflowid,
                       -1                  as     nodeid,
                       iutdata.userid,
                       0                   as     showorder,
                       receivedatetime,
                       case
                         when operatedatetime is null then receivedatetime
                         else operatedatetime end operatedatetime,
                       0                   as     isprocessed,
                       0                   as     needwfback,
                       isbereject,
                       isremark,
                       preisremark,
                       null                as     viewdatetime,
                       0                   as     supervisionstatus,
                       -1                  as     requestlogid,
                       null                as     overtimedatetime,
                       0                   as     forwardright,
                       -1                  as     cid,
                       creater,
                       current_status      as     status,
                       request_name        as     requestname,
                       request_name        as     requestnamehtml,
                       request_mark        as     requestmark,
                       request_level       as     requestlevel,
                       -1                  as     seclevel,
                       request_name        as     requestnametitle,
                       -1                  as     lastfeedbackoperator,
                       null                as     lastfeedbackdatetime,
                       flowstatus,
                       createdatetime,
                       finishdatetime,
                       creatorcode,
                       creatorsubcom,
                       creatordept,
                       creatorjob,
                       -1                  as     beagentuserid,
                       3                   as     datasrc,
                       reqbase.sdk_module  as     module,
                       iutdata.create_time,
                       iutdata.update_time,
                       iutdata.creator,
                       iutdata.delete_type,
                       iutdata.tenant_key,
                       null                as     last_comment_time,
                       null                as     minovertime,
                       null                as     firstviewdatetime,
                       request_name        as     requestnameorder,
                       -1                  as     trigger_source,
                       iutdata.user_master_id,
                       -1                  as     currentnodeid,
                       iutdata.workflow_code,
                       current_nodename,
                       iutdata.sys_code,
                       iutdata.request_code,
                       reqbase.sys_id,
                       viewtype
                from wfl_iut_todo_data iutdata
                       inner join wfl_iut_request_base reqbase on iutdata.request_id = reqbase.request_id
                WHERE (iutdata.tenant_key = {租户key} AND iutdata.delete_type = 0 AND iutdata.workflow_id > 0 AND
                       iutdata.request_id > 0 AND iutdata.sys_id > 0 AND reqbase.tenant_key = {租户key} AND
                       reqbase.delete_type = 0 AND reqbase.workflow_id > 0 AND reqbase.request_id > 0 AND
                       reqbase.sys_id > 0 AND 1 = 1 AND iutdata.sys_id in (select distinct sys_id
                                                                           from wfl_iut_sysinfo
                                                                           where tenant_key = {租户key}
                                                                             and delete_type = 0
                                                                             and show_pc = 1) AND (1 = 1) AND
                       reqbase.sdk_module IN (2, 4, 0))
                  and iutdata.user_master_id = {用户ID}
      union all select reqbase.request_id  as     id,
                       reqbase.request_id  as     requestid,
                       reqbase.sys_id      as     workflowtype,
                       reqbase.workflow_id as     workflowid,
                       -1                  as     nodeid,
                       iutdata.userid,
                       0                   as     showorder,
                       receivedatetime,
                       case
                         when operatedatetime is null then receivedatetime
                         else operatedatetime end operatedatetime,
                       0                   as     isprocessed,
                       0                   as     needwfback,
                       isbereject,
                       isremark,
                       preisremark,
                       null                as     viewdatetime,
                       0                   as     supervisionstatus,
                       -1                  as     requestlogid,
                       null                as     overtimedatetime,
                       0                   as     forwardright,
                       -1                  as     cid,
                       creater,
                       current_status      as     status,
                       request_name        as     requestname,
                       request_name        as     requestnamehtml,
                       request_mark        as     requestmark,
                       request_level       as     requestlevel,
                       -1                  as     seclevel,
                       request_name        as     requestnametitle,
                       -1                  as     lastfeedbackoperator,
                       null                as     lastfeedbackdatetime,
                       flowstatus,
                       createdatetime,
                       finishdatetime,
                       creatorcode,
                       creatorsubcom,
                       creatordept,
                       creatorjob,
                       -1                  as     beagentuserid,
                       3                   as     datasrc,
                       reqbase.sdk_module  as     module,
                       iutdata.create_time,
                       iutdata.update_time,
                       iutdata.creator,
                       iutdata.delete_type,
                       iutdata.tenant_key,
                       null                as     last_comment_time,
                       null                as     minovertime,
                       null                as     firstviewdatetime,
                       request_name        as     requestnameorder,
                       -1                  as     trigger_source,
                       iutdata.user_master_id,
                       -1                  as     currentnodeid,
                       iutdata.workflow_code,
                       current_nodename,
                       iutdata.sys_code,
                       iutdata.request_code,
                       reqbase.sys_id,
                       viewtype
                from wfl_iut_done_data iutdata
                       inner join wfl_iut_request_base reqbase on iutdata.request_id = reqbase.request_id
                WHERE (iutdata.tenant_key = {租户key} AND iutdata.delete_type = 0 AND iutdata.workflow_id > 0 AND
                       iutdata.request_id > 0 AND iutdata.sys_id > 0 AND reqbase.tenant_key = {租户key} AND
                       reqbase.delete_type = 0 AND reqbase.workflow_id > 0 AND reqbase.request_id > 0 AND
                       reqbase.sys_id > 0 AND 1 = 1 AND iutdata.sys_id in (select distinct sys_id
                                                                           from wfl_iut_sysinfo
                                                                           where tenant_key = {租户key}
                                                                             and delete_type = 0
                                                                             and show_pc = 1) AND (1 = 1) AND
                       reqbase.sdk_module IN (2, 4, 0))
                  and iutdata.user_master_id = {用户ID}) t1
ORDER BY createdatetime DESC, requestid DESC
```

## 1.6、全部流程
```sql
select distinct requestid as id,
                requestid,
                workflowtype,
                workflowid,
                creater,
                status,
                requestname,
                requestnamehtml,
                requestnametitle,
                requestmark,
                requestlevel,
                seclevel,
                lastfeedbackoperator,
                lastfeedbackdatetime,
                flowstatus,
                createdatetime,
                finishdatetime,
                creatorcode,
                creatorsubcom,
                creatordept,
                creatorjob,
                datasrc,
                module,
                create_time,
                update_time,
                creator,
                delete_type,
                tenant_key,
                last_comment_time,
                minovertime,
                requestnameorder,
                receivedatetime,
                currentnodeid,
                trigger_source,
                ''        as workflow_code,
                ''        as current_nodename,
                ''        as sys_code,
                ''        as request_code,
                -1        as sys_id,
                -1        as viewtype
from (select t1.requestid                  as id,
             t1.requestid,
             workflowtype,
             t1.workflowid,
             userid                        as creater,
             status,
             requestname,
             requestnamehtml,
             requestnametitle,
             requestmark,
             requestlevel,
             seclevel,
             lastfeedbackoperator,
             lastfeedbackdatetime,
             flowstatus,
             createdatetime,
             finishdatetime,
             creatorcode,
             creatorsubcom,
             creatordept,
             creatorjob,
             t1.datasrc,
             t1.module,
             t1.create_time,
             t1.update_time,
             t1.creator,
             t1.delete_type,
             t1.tenant_key,
             last_comment_time,
             minovertime,
             (case
                when requestnametitle is null then requestname
                else requestnametitle end) as requestnameorder,
             trigger_source,
             -1                            as currentnodeid,
             ''                            as workflow_code,
             ''                            as current_nodename,
             ''                            as sys_code,
             ''                            as request_code,
             -1                            as sys_id,
             -1                            as viewtype,
             null                          as receivedatetime
      from wfc_requestbase t1,
           (select t1.requestid
            from wfc_operate_todo t1
            WHERE ((t1.flowstatus not in (7, 8) or (t1.flowstatus = 7 and t1.creater = {用户ID})) AND
                   t1.tenant_key = {租户key} AND t1.module = 0 AND t1.delete_type = 0 AND (1 = 1) AND (1 = 1))
              and t1.user_master_id in ({用户下属集合、助理下属集合、权限开放用户集合、用户自身})
            union all select t1.requestid
                      from wfc_operate_done t1
                      WHERE ((t1.flowstatus not in (7, 8) or
                              (t1.flowstatus = 7 and t1.creater = {用户ID})) AND t1.tenant_key = {租户key} AND
                             t1.module = 0 AND t1.delete_type = 0 AND
                             (1 = 1) AND (1 = 1))
                        and t1.user_master_id = {用户ID}) t2
      where t1.requestid = t2.requestid
      union SELECT t1.requestid                     AS id,
                   t1.requestid,
                   t1.workflowtype,
                   t1.workflowid,
                   t1.userid                        AS creater,
                   t1.status,
                   t1.requestname,
                   t1.requestnamehtml,
                   t1.requestnametitle,
                   t1.requestmark,
                   t1.requestlevel,
                   t1.seclevel,
                   t1.lastfeedbackoperator,
                   t1.lastfeedbackdatetime,
                   t1.flowstatus,
                   t1.createdatetime,
                   t1.finishdatetime,
                   t1.creatorcode,
                   t1.creatorsubcom,
                   t1.creatordept,
                   t1.creatorjob,
                   t1.datasrc,
                   t1.module,
                   t1.create_time,
                   t1.update_time,
                   t1.creator,
                   t1.delete_type,
                   t1.tenant_key,
                   t1.last_comment_time,
                   t1.minovertime,
                   (CASE
                      WHEN t1.requestnametitle IS NULL THEN t1.requestname
                      ELSE t1.requestnametitle END) AS requestnameorder,
                   t1.trigger_source,
                   -1                               AS currentnodeid,
                   ''                               AS workflow_code,
                   ''                               AS current_nodename,
                   ''                               AS sys_code,
                   ''                               AS request_code,
                   -1                               AS sys_id,
                   -1                               AS viewtype,
                   NULL                             AS receivedatetime
            FROM wfc_requestbase t1
            WHERE ((t1.flowstatus NOT IN (7, 8) OR (t1.flowstatus = 7 AND t1.creater = {用户ID})) AND
                   t1.tenant_key = {租户key} AND t1.module = 0 AND t1.delete_type = 0 AND (1 = 1) AND (1 = 1))
              AND t1.istest = 0
              AND 1 = 1
              AND t1.requestid in (select wpws.source_id
                                   from wfc_requestbase_ph_wfc_share wpws
                                   where wpws.tenant_key = {租户key}
                                     and (wpws.delete_type = 0 OR wpws.delete_type IS NULL)
                                     and wpws.source_type = 1
                                     AND ((wpws.target_id in ({用户所有身份ID}) and
                                           wpws.target_type = 1) OR
                                          (wpws.target_id in ({类型ID}) and wpws.target_type = {对应类型})))
      union all select reqbase.request_id  as id,
                       reqbase.request_id  as requestid,
                       reqbase.sys_id      as workflowtype,
                       reqbase.workflow_id as workflowid,
                       reqbase.userid      as creater,
                       current_status      as status,
                       request_name        as requestname,
                       request_name        as requestnamehtml,
                       request_name        as requestnametitle,
                       request_mark        as requestmark,
                       request_level       as requestlevel,
                       -1                  as seclevel,
                       -1                  as lastfeedbackoperator,
                       null                as lastfeedbackdatetime,
                       flowstatus,
                       createdatetime,
                       finishdatetime,
                       creatorcode,
                       creatorsubcom,
                       creatordept,
                       creatorjob,
                       3                   as datasrc,
                       reqbase.sdk_module  as module,
                       reqbase.create_time,
                       reqbase.update_time,
                       reqbase.creator,
                       iutdata.delete_type,
                       iutdata.tenant_key,
                       null                as last_comment_time,
                       null                as minovertime,
                       request_name        as requestnameorder,
                       -1                  as trigger_source,
                       -1                  as currentnodeid,
                       reqbase.workflow_code,
                       current_nodename,
                       reqbase.sys_code,
                       reqbase.request_code,
                       reqbase.sys_id,
                       viewtype,
                       receivedatetime
                from wfl_iut_request_base reqbase
                       inner join (select distinct request_id,
                                                   workflow_id,
                                                   sys_id,
                                                   tenant_key,
                                                   delete_type,
                                                   creater,
                                                   receivedatetime,
                                                   userid,
                                                   operatedatetime,
                                                   viewtype,
                                                   user_master_id
                                   from wfl_iut_todo_data
                                   where tenant_key = {租户key}
                                     and user_master_id = {用户ID}
                                     and sdk_module = 0
                                   union all select distinct request_id,
                                                             workflow_id,
                                                             sys_id,
                                                             tenant_key,
                                                             delete_type,
                                                             creater,
                                                             receivedatetime,
                                                             userid,
                                                             operatedatetime,
                                                             viewtype,
                                                             user_master_id
                                             from wfl_iut_todo_data
                                             where tenant_key = {租户key}
                                               and userid in ({用户下属集合、助理下属集合、权限开放用户集合、用户自身})
                                   union all select distinct request_id,
                                                             workflow_id,
                                                             sys_id,
                                                             tenant_key,
                                                             delete_type,
                                                             creater,
                                                             receivedatetime,
                                                             userid,
                                                             operatedatetime,
                                                             viewtype,
                                                             user_master_id
                                             from wfl_iut_done_data
                                             where user_master_id = {用户ID}
                                               and tenant_key = {租户key}) iutdata
                         on reqbase.request_id = iutdata.request_id
                WHERE (iutdata.tenant_key = {租户key} AND iutdata.delete_type = 0 AND iutdata.workflow_id > 0 AND
                       iutdata.request_id > 0 AND iutdata.sys_id > 0 AND reqbase.tenant_key = {租户key} AND
                       reqbase.delete_type = 0 AND reqbase.workflow_id > 0 AND reqbase.request_id > 0 AND
                       reqbase.sys_id > 0 AND 1 = 1 AND
                       iutdata.sys_id in (select distinct sys_id from wfl_iut_sysinfo where tenant_key = {租户key}
                                                                                        and delete_type = 0
                                                                                        and show_pc = 1) AND (1 = 1) AND
                       reqbase.sdk_module IN (2, 4, 0))) t1
ORDER BY createdatetime DESC, requestid DESC
```



# 二、未开启统一待办版本
## 2.1 待办流程
```sql
select t1.id,
       t1.requestid,
       t1.workflowtype,
       t1.workflowid,
       t1.nodeid,
       t1.userid,
       t1.showorder,
       t1.receivedatetime,
       case
         when t1.operatedatetime is null then t1.receivedatetime
         else t1.operatedatetime end       operatedatetime,
       t1.isprocessed,
       t1.needwfback,
       t1.isbereject,
       t1.isremark,
       t1.preisremark,
       t1.viewdatetime,
       t1.supervisionstatus,
       t1.requestlogid,
       t1.overtimedatetime,
       t1.forwardright,
       t1.cid,
       t1.creater,
       t1.status,
       t1.requestname,
       t1.requestnamehtml,
       t1.requestmark,
       t1.requestlevel,
       t1.seclevel,
       t1.requestnametitle,
       t1.lastfeedbackoperator,
       t1.lastfeedbackdatetime,
       t1.flowstatus,
       t1.createdatetime,
       t1.finishdatetime,
       t1.creatorcode,
       t1.creatorsubcom,
       t1.creatordept,
       t1.creatorjob,
       t1.beagentuserid,
       t1.datasrc,
       t1.module,
       t1.create_time,
       t1.update_time,
       t1.creator,
       t1.delete_type,
       t1.tenant_key,
       t1.last_comment_time,
       t1.minovertime,
       t1.firstviewdatetime,
       (case
          when t1.requestnametitle is null then t1.requestname
          else t1.requestnametitle end) as requestnameorder,
       t1.user_master_id,
       t1.trigger_source,
       currentnodeid,
       t1.planfinishdatetime
from (select t1.id,
             t1.requestid,
             t1.workflowtype,
             t1.workflowid,
             t1.nodeid,
             t1.userid,
             t1.showorder,
             t1.receivedatetime,
             case
               when t1.operatedatetime is null then t1.receivedatetime
               else t1.operatedatetime end       operatedatetime,
             t1.isprocessed,
             t1.needwfback,
             t1.isbereject,
             t1.isremark,
             t1.preisremark,
             t1.viewdatetime,
             t1.supervisionstatus,
             t1.requestlogid,
             t1.overtimedatetime,
             t1.forwardright,
             t1.cid,
             t1.creater,
             t1.status,
             t1.requestname,
             t1.requestnamehtml,
             t1.requestmark,
             t1.requestlevel,
             t1.seclevel,
             t1.requestnametitle,
             t1.lastfeedbackoperator,
             t1.lastfeedbackdatetime,
             t1.flowstatus,
             t1.createdatetime,
             t1.finishdatetime,
             t1.creatorcode,
             t1.creatorsubcom,
             t1.creatordept,
             t1.creatorjob,
             t1.beagentuserid,
             t1.datasrc,
             t1.module,
             t1.create_time,
             t1.update_time,
             t1.creator,
             t1.delete_type,
             t1.tenant_key,
             t1.last_comment_time,
             t1.minovertime,
             t1.firstviewdatetime,
             (case
                when t1.requestnametitle is null then t1.requestname
                else t1.requestnametitle end) as requestnameorder,
             t1.trigger_source,
             t1.user_master_id,
             -1                               as currentnodeid,
             t1.planfinishdatetime
      from wfc_operate_todo t1
      WHERE ((t1.flowstatus <> 0 or (t1.flowstatus = 0 and
                                     (t1.trigger_source in (1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 104, 108) or
                                      t1.isremark in (40, 41, 80, 81, 20, 21, 60, 61)))) AND t1.tenant_key = {租户key} AND
             t1.module = 0 AND t1.delete_type = 0 AND
             t1.user_master_id = {用户ID} AND t1.no_disturb_flag = 0)) t1
ORDER BY last_comment_time DESC, creater, requestid DESC
```

## 2.2 已办流程
```sql
select t1.id,
       t1.requestid,
       t1.workflowtype,
       t1.workflowid,
       t1.nodeid,
       t1.userid,
       t1.showorder,
       t1.receivedatetime,
       case
         when t1.operatedatetime is null then t1.receivedatetime
         else t1.operatedatetime end       operatedatetime,
       t1.isprocessed,
       t1.needwfback,
       t1.isbereject,
       t1.isremark,
       t1.preisremark,
       t1.viewdatetime,
       t1.supervisionstatus,
       t1.requestlogid,
       t1.overtimedatetime,
       t1.forwardright,
       t1.cid,
       t1.creater,
       t1.status,
       t1.requestname,
       t1.requestnamehtml,
       t1.requestmark,
       t1.requestlevel,
       t1.seclevel,
       t1.requestnametitle,
       t1.lastfeedbackoperator,
       t1.lastfeedbackdatetime,
       t1.flowstatus,
       t1.createdatetime,
       t1.finishdatetime,
       t1.creatorcode,
       t1.creatorsubcom,
       t1.creatordept,
       t1.creatorjob,
       t1.beagentuserid,
       t1.datasrc,
       t1.module,
       t1.create_time,
       t1.update_time,
       t1.creator,
       t1.delete_type,
       t1.tenant_key,
       t1.last_comment_time,
       t1.minovertime,
       t1.firstviewdatetime,
       (case
          when t1.requestnametitle is null then t1.requestname
          else t1.requestnametitle end) as requestnameorder,
       t1.user_master_id,
       t1.trigger_source,
       currentnodeid
from (select t1.id,
             t1.requestid,
             t1.workflowtype,
             t1.workflowid,
             t1.nodeid,
             t1.userid,
             t1.showorder,
             t1.receivedatetime,
             case
               when t1.operatedatetime is null then t1.receivedatetime
               else t1.operatedatetime end       operatedatetime,
             t1.isprocessed,
             t1.needwfback,
             t1.isbereject,
             t1.isremark,
             t1.preisremark,
             t1.viewdatetime,
             t1.supervisionstatus,
             t1.requestlogid,
             t1.overtimedatetime,
             t1.forwardright,
             t1.cid,
             t1.creater,
             t1.status,
             t1.requestname,
             t1.requestnamehtml,
             t1.requestmark,
             t1.requestlevel,
             t1.seclevel,
             t1.requestnametitle,
             t1.lastfeedbackoperator,
             t1.lastfeedbackdatetime,
             t1.flowstatus,
             t1.createdatetime,
             t1.finishdatetime,
             t1.creatorcode,
             t1.creatorsubcom,
             t1.creatordept,
             t1.creatorjob,
             t1.beagentuserid,
             t1.datasrc,
             t1.module,
             t1.create_time,
             t1.update_time,
             t1.creator,
             t1.delete_type,
             t1.tenant_key,
             t1.last_comment_time,
             t1.minovertime,
             t1.firstviewdatetime,
             (case
                when t1.requestnametitle is null then t1.requestname
                else t1.requestnametitle end) as requestnameorder,
             t1.trigger_source,
             t1.user_master_id,
             -1                               as currentnodeid
      from wfc_operate_done t1
      WHERE (t1.tenant_key = {租户key} AND t1.module = 0 AND t1.delete_type = 0 AND
             t1.user_master_id = {用户ID})) t1
ORDER BY last_comment_time DESC, requestid DESC
```

## 2.3、草稿流程
```sql
select t1.id,
       t1.requestid,
       t1.workflowtype,
       t1.workflowid,
       t1.nodeid,
       t1.userid,
       t1.showorder,
       t1.receivedatetime,
       case
         when t1.operatedatetime is null then t1.receivedatetime
         else t1.operatedatetime end       operatedatetime,
       t1.isprocessed,
       t1.needwfback,
       t1.isbereject,
       t1.isremark,
       t1.preisremark,
       t1.viewdatetime,
       t1.supervisionstatus,
       t1.requestlogid,
       t1.overtimedatetime,
       t1.forwardright,
       t1.cid,
       t1.creater,
       t1.status,
       t1.requestname,
       t1.requestnamehtml,
       t1.requestmark,
       t1.requestlevel,
       t1.seclevel,
       t1.requestnametitle,
       t1.lastfeedbackoperator,
       t1.lastfeedbackdatetime,
       t1.flowstatus,
       t1.createdatetime,
       t1.finishdatetime,
       t1.creatorcode,
       t1.creatorsubcom,
       t1.creatordept,
       t1.creatorjob,
       t1.beagentuserid,
       t1.datasrc,
       t1.module,
       t1.create_time,
       t1.update_time,
       t1.creator,
       t1.delete_type,
       t1.tenant_key,
       t1.last_comment_time,
       t1.minovertime,
       t1.firstviewdatetime,
       (case
          when t1.requestnametitle is null then t1.requestname
          else t1.requestnametitle end) as requestnameorder,
       t1.user_master_id,
       t1.trigger_source,
       currentnodeid,
       t1.planfinishdatetime
from (select t1.id,
             t1.requestid,
             t1.workflowtype,
             t1.workflowid,
             t1.nodeid,
             t1.userid,
             t1.showorder,
             t1.receivedatetime,
             case
               when t1.operatedatetime is null then t1.receivedatetime
               else t1.operatedatetime end       operatedatetime,
             t1.isprocessed,
             t1.needwfback,
             t1.isbereject,
             t1.isremark,
             t1.preisremark,
             t1.viewdatetime,
             t1.supervisionstatus,
             t1.requestlogid,
             t1.overtimedatetime,
             t1.forwardright,
             t1.cid,
             t1.creater,
             t1.status,
             t1.requestname,
             t1.requestnamehtml,
             t1.requestmark,
             t1.requestlevel,
             t1.seclevel,
             t1.requestnametitle,
             t1.lastfeedbackoperator,
             t1.lastfeedbackdatetime,
             t1.flowstatus,
             t1.createdatetime,
             t1.finishdatetime,
             t1.creatorcode,
             t1.creatorsubcom,
             t1.creatordept,
             t1.creatorjob,
             t1.beagentuserid,
             t1.datasrc,
             t1.module,
             t1.create_time,
             t1.update_time,
             t1.creator,
             t1.delete_type,
             t1.tenant_key,
             t1.last_comment_time,
             t1.minovertime,
             t1.firstviewdatetime,
             (case
                when t1.requestnametitle is null then t1.requestname
                else t1.requestnametitle end) as requestnameorder,
             t1.trigger_source,
             t1.user_master_id,
             -1                               as currentnodeid,
             t1.planfinishdatetime
      from wfc_operate_todo t1
      WHERE (t1.flowstatus = 0 and t1.trigger_source in (0, 11, 101, 102, 103, 105, 109, 110, 111) and
             t1.isremark not in (40, 41, 80, 81, 20, 21, 60, 61) AND t1.tenant_key = {租户key} AND t1.module = 0 AND
             t1.delete_type = 0 AND t1.user_master_id = {用户ID})) t1
ORDER BY last_comment_time DESC, requestid DESC
```

## 2.4、我发起的流程
```sql
select t1.id,
       t1.requestid,
       t1.workflowtype,
       t1.workflowid,
       t1.nodeid,
       t1.userid,
       t1.showorder,
       t1.receivedatetime,
       case
         when t1.operatedatetime is null then t1.receivedatetime
         else t1.operatedatetime end       operatedatetime,
       t1.isprocessed,
       t1.needwfback,
       t1.isbereject,
       t1.isremark,
       t1.preisremark,
       t1.viewdatetime,
       t1.supervisionstatus,
       t1.requestlogid,
       t1.overtimedatetime,
       t1.forwardright,
       t1.cid,
       t1.creater,
       t1.status,
       t1.requestname,
       t1.requestnamehtml,
       t1.requestmark,
       t1.requestlevel,
       t1.seclevel,
       t1.requestnametitle,
       t1.lastfeedbackoperator,
       t1.lastfeedbackdatetime,
       t1.flowstatus,
       t1.createdatetime,
       t1.finishdatetime,
       t1.creatorcode,
       t1.creatorsubcom,
       t1.creatordept,
       t1.creatorjob,
       t1.beagentuserid,
       t1.datasrc,
       t1.module,
       t1.create_time,
       t1.update_time,
       t1.creator,
       t1.delete_type,
       t1.tenant_key,
       t1.last_comment_time,
       t1.minovertime,
       t1.firstviewdatetime,
       (case
          when t1.requestnametitle is null then t1.requestname
          else t1.requestnametitle end) as requestnameorder,
       t1.user_master_id,
       t1.trigger_source,
       currentnodeid
from (select t1.id,
             t1.requestid,
             t1.workflowtype,
             t1.workflowid,
             t1.nodeid,
             t1.userid,
             t1.showorder,
             t1.receivedatetime,
             case
               when t1.operatedatetime is null then t1.receivedatetime
               else t1.operatedatetime end       operatedatetime,
             t1.isprocessed,
             t1.needwfback,
             t1.isbereject,
             t1.isremark,
             t1.preisremark,
             t1.viewdatetime,
             t1.supervisionstatus,
             t1.requestlogid,
             t1.overtimedatetime,
             t1.forwardright,
             t1.cid,
             t1.creater,
             t1.status,
             t1.requestname,
             t1.requestnamehtml,
             t1.requestmark,
             t1.requestlevel,
             t1.seclevel,
             t1.requestnametitle,
             t1.lastfeedbackoperator,
             t1.lastfeedbackdatetime,
             t1.flowstatus,
             t1.createdatetime,
             t1.finishdatetime,
             t1.creatorcode,
             t1.creatorsubcom,
             t1.creatordept,
             t1.creatorjob,
             t1.beagentuserid,
             t1.datasrc,
             t1.module,
             t1.create_time,
             t1.update_time,
             t1.creator,
             t1.delete_type,
             t1.tenant_key,
             t1.last_comment_time,
             t1.minovertime,
             t1.firstviewdatetime,
             (case
                when t1.requestnametitle is null then t1.requestname
                else t1.requestnametitle end) as requestnameorder,
             t1.trigger_source,
             t1.user_master_id,
             -1                               as currentnodeid
      from wfc_operate_todo t1
      WHERE ((1 = 1)and t1.creator_master_id = {用户ID} AND t1.tenant_key = {租户key} AND t1.module = 0 AND
             t1.delete_type = 0 AND t1.user_master_id = {用户ID} AND (1 = 1) AND
             (1 = 1))
      union select t1.id,
                   t1.requestid,
                   t1.workflowtype,
                   t1.workflowid,
                   t1.nodeid,
                   t1.userid,
                   t1.showorder,
                   t1.receivedatetime,
                   case
                     when t1.operatedatetime is null then t1.receivedatetime
                     else t1.operatedatetime end       operatedatetime,
                   t1.isprocessed,
                   t1.needwfback,
                   t1.isbereject,
                   t1.isremark,
                   t1.preisremark,
                   t1.viewdatetime,
                   t1.supervisionstatus,
                   t1.requestlogid,
                   t1.overtimedatetime,
                   t1.forwardright,
                   t1.cid,
                   t1.creater,
                   t1.status,
                   t1.requestname,
                   t1.requestnamehtml,
                   t1.requestmark,
                   t1.requestlevel,
                   t1.seclevel,
                   t1.requestnametitle,
                   t1.lastfeedbackoperator,
                   t1.lastfeedbackdatetime,
                   t1.flowstatus,
                   t1.createdatetime,
                   t1.finishdatetime,
                   t1.creatorcode,
                   t1.creatorsubcom,
                   t1.creatordept,
                   t1.creatorjob,
                   t1.beagentuserid,
                   t1.datasrc,
                   t1.module,
                   t1.create_time,
                   t1.update_time,
                   t1.creator,
                   t1.delete_type,
                   t1.tenant_key,
                   t1.last_comment_time,
                   t1.minovertime,
                   t1.firstviewdatetime,
                   (case
                      when t1.requestnametitle is null then t1.requestname
                      else t1.requestnametitle end) as requestnameorder,
                   t1.trigger_source,
                   t1.user_master_id,
                   -1                               as currentnodeid
            from wfc_operate_done t1
            WHERE ((1 = 1)and t1.creator_master_id = {用户ID} AND t1.tenant_key = {租户key} AND t1.module = 0 AND
                   t1.delete_type = 0 AND t1.user_master_id = {用户ID} AND
                   (1 = 1) AND (1 = 1))) t1
ORDER BY last_comment_time DESC, requestid DESC
```

## 2.5、共享给我的流程
```sql
SELECT t1.requestid                  AS id,
       t1.requestid,
       workflowtype,
       t1.workflowid,
       userid                        AS creater,
       status,
       requestname,
       requestnamehtml,
       requestnametitle,
       requestmark,
       requestlevel,
       seclevel,
       lastfeedbackoperator,
       lastfeedbackdatetime,
       flowstatus,
       createdatetime,
       finishdatetime,
       creatorcode,
       creatorsubcom,
       creatordept,
       creatorjob,
       t1.datasrc,
       t1.module,
       t1.create_time,
       t1.update_time,
       t1.creator,
       t1.delete_type,
       t1.tenant_key,
       last_comment_time,
       minovertime,
       (CASE
          WHEN requestnametitle IS NULL THEN requestname
          ELSE requestnametitle END) AS requestnameorder,
       trigger_source,
       -1                            AS currentnodeid,
       NULL                          AS receivedatetime
FROM wfc_requestbase t1
WHERE ((t1.flowstatus NOT IN (7, 8) OR (t1.flowstatus = 7 AND t1.creater = {用户ID})) AND
       t1.delete_type = 0 AND t1.tenant_key = {租户key} AND t1.module = 0 AND t1.delete_type = 0 AND t1.istest = 0)
  AND t1.requestid IN (select wpws.source_id
                       from wfc_requestbase_ph_wfc_share_3 wpws
                       where wpws.source_type = 1
                         and (wpws.delete_type = 0 OR wpws.delete_type IS NULL)
                         and wpws.tenant_key = {租户key}
                         AND ((wpws.target_id in ({用户ID}) and
                                           wpws.target_type = 1) OR
                                          (wpws.target_id in ({类型ID}) and wpws.target_type = {对应类型})))
ORDER BY last_comment_time DESC, requestid DESC
```
## 2.6、我关注的流程
```sql
select distinct t1.requestid                  as id,
                t1.requestid,
                workflowtype,
                t1.workflowid,
                userid                        as creater,
                status,
                requestname,
                requestnamehtml,
                requestnametitle,
                requestmark,
                requestlevel,
                seclevel,
                lastfeedbackoperator,
                lastfeedbackdatetime,
                flowstatus,
                createdatetime,
                finishdatetime,
                creatorcode,
                creatorsubcom,
                creatordept,
                creatorjob,
                t1.datasrc,
                t1.module,
                t1.create_time,
                t1.update_time,
                t1.creator,
                t1.delete_type,
                t1.tenant_key,
                last_comment_time,
                minovertime,
                (case
                   when requestnametitle is null then requestname
                   else requestnametitle end) as requestnameorder,
                trigger_source,
                -1                            as currentnodeid,
                null                          as receivedatetime,
                watch.add_time                as attentionTime
from wfc_requestbase t1
       inner join eteams.watch watch on t1.requestid = watch.target_id
WHERE ((t1.flowstatus not in (7, 8) or (t1.flowstatus = 7 and t1.creater = {用户ID}))and
       t1.delete_type = 0 AND t1.tenant_key = {租户key} AND t1.module = 0 AND t1.delete_type = 0)
  and watch.watcher = {用户ID}
  and watch.module = 'workflow'
  and watch.tenant_key = {租户key}
  and watch.delete_type = 0
  and t1.istest = 0
ORDER BY last_comment_time DESC, requestid DESC
```

## 2.7、下属待办的流程
```sql
select distinct requestid as id,
                requestid,
                workflowtype,
                workflowid,
                creater,
                status,
                requestname,
                requestnamehtml,
                requestnametitle,
                requestmark,
                requestlevel,
                seclevel,
                lastfeedbackoperator,
                lastfeedbackdatetime,
                flowstatus,
                createdatetime,
                finishdatetime,
                creatorcode,
                creatorsubcom,
                creatordept,
                creatorjob,
                datasrc,
                module,
                create_time,
                update_time,
                creator,
                delete_type,
                tenant_key,
                last_comment_time,
                minovertime,
                requestnameorder,
                receivedatetime,
                currentnodeid,
                trigger_source
from (select t1.requestid                  as id,
             t1.requestid,
             workflowtype,
             t1.workflowid,
             userid                        as creater,
             status,
             requestname,
             requestnamehtml,
             requestnametitle,
             requestmark,
             requestlevel,
             seclevel,
             lastfeedbackoperator,
             lastfeedbackdatetime,
             flowstatus,
             createdatetime,
             finishdatetime,
             creatorcode,
             creatorsubcom,
             creatordept,
             creatorjob,
             t1.datasrc,
             t1.module,
             t1.create_time,
             t1.update_time,
             t1.creator,
             t1.delete_type,
             t1.tenant_key,
             last_comment_time,
             minovertime,
             (case
                when requestnametitle is null then requestname
                else requestnametitle end) as requestnameorder,
             trigger_source,
             -1                            as currentnodeid,
             null                          as receivedatetime
      from wfc_requestbase t1
             inner join (select requestid, user_master_id
                         from wfc_operate_todo t1
                         WHERE ((t1.flowstatus not in (0, 7, 8) or (t1.flowstatus = 0 and
                                                                    (t1.trigger_source in (1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 104, 108) or
                                                                     t1.isremark in (40,
                                                                                     41,
                                                                                     80,
                                                                                     81,
                                                                                     20,
                                                                                     21,
                                                                                     60,
                                                                                     61)))) AND t1.tenant_key = {租户key} AND
                                t1.module = 0 AND t1.delete_type = 0 AND 
                                t1.userid IN ({下属id集合}) AND (1 = 1) AND (1 = 1))) allUserData
               on t1.requestid = allUserData.requestid
      where istest = 0) allData
ORDER BY last_comment_time DESC, requestid DESC
```

## 2.8、直接参与的流程
```sql
select t1.id,
       t1.requestid,
       t1.workflowtype,
       t1.workflowid,
       t1.nodeid,
       t1.userid,
       t1.showorder,
       t1.receivedatetime,
       case
         when t1.operatedatetime is null then t1.receivedatetime
         else t1.operatedatetime end       operatedatetime,
       t1.isprocessed,
       t1.needwfback,
       t1.isbereject,
       t1.isremark,
       t1.preisremark,
       t1.viewdatetime,
       t1.supervisionstatus,
       t1.requestlogid,
       t1.overtimedatetime,
       t1.forwardright,
       t1.cid,
       t1.creater,
       t1.status,
       t1.requestname,
       t1.requestnamehtml,
       t1.requestmark,
       t1.requestlevel,
       t1.seclevel,
       t1.requestnametitle,
       t1.lastfeedbackoperator,
       t1.lastfeedbackdatetime,
       t1.flowstatus,
       t1.createdatetime,
       t1.finishdatetime,
       t1.creatorcode,
       t1.creatorsubcom,
       t1.creatordept,
       t1.creatorjob,
       t1.beagentuserid,
       t1.datasrc,
       t1.module,
       t1.create_time,
       t1.update_time,
       t1.creator,
       t1.delete_type,
       t1.tenant_key,
       t1.last_comment_time,
       t1.minovertime,
       t1.firstviewdatetime,
       (case
          when t1.requestnametitle is null then t1.requestname
          else t1.requestnametitle end) as requestnameorder,
       t1.user_master_id,
       t1.trigger_source,
       currentnodeid
from (select t1.id,
             t1.requestid,
             t1.workflowtype,
             t1.workflowid,
             t1.nodeid,
             t1.userid,
             t1.showorder,
             t1.receivedatetime,
             case
               when t1.operatedatetime is null then t1.receivedatetime
               else t1.operatedatetime end       operatedatetime,
             t1.isprocessed,
             t1.needwfback,
             t1.isbereject,
             t1.isremark,
             t1.preisremark,
             t1.viewdatetime,
             t1.supervisionstatus,
             t1.requestlogid,
             t1.overtimedatetime,
             t1.forwardright,
             t1.cid,
             t1.creater,
             t1.status,
             t1.requestname,
             t1.requestnamehtml,
             t1.requestmark,
             t1.requestlevel,
             t1.seclevel,
             t1.requestnametitle,
             t1.lastfeedbackoperator,
             t1.lastfeedbackdatetime,
             t1.flowstatus,
             t1.createdatetime,
             t1.finishdatetime,
             t1.creatorcode,
             t1.creatorsubcom,
             t1.creatordept,
             t1.creatorjob,
             t1.beagentuserid,
             t1.datasrc,
             t1.module,
             t1.create_time,
             t1.update_time,
             t1.creator,
             t1.delete_type,
             t1.tenant_key,
             t1.last_comment_time,
             t1.minovertime,
             t1.firstviewdatetime,
             (case
                when t1.requestnametitle is null then t1.requestname
                else t1.requestnametitle end) as requestnameorder,
             t1.trigger_source,
             t1.user_master_id,
             -1                               as currentnodeid
      from wfc_operate_todo t1
      WHERE ((t1.flowstatus not in (7, 8) or (t1.flowstatus = 7 and t1.creater = {用户ID})) AND
             t1.tenant_key = {租户key} AND t1.module = 0 AND t1.delete_type = 0 AND 
             (1 = 1) AND (1 = 1))
        and t1.user_master_id = {用户ID}
      union select t1.id,
                   t1.requestid,
                   t1.workflowtype,
                   t1.workflowid,
                   t1.nodeid,
                   t1.userid,
                   t1.showorder,
                   t1.receivedatetime,
                   case
                     when t1.operatedatetime is null then t1.receivedatetime
                     else t1.operatedatetime end       operatedatetime,
                   t1.isprocessed,
                   t1.needwfback,
                   t1.isbereject,
                   t1.isremark,
                   t1.preisremark,
                   t1.viewdatetime,
                   t1.supervisionstatus,
                   t1.requestlogid,
                   t1.overtimedatetime,
                   t1.forwardright,
                   t1.cid,
                   t1.creater,
                   t1.status,
                   t1.requestname,
                   t1.requestnamehtml,
                   t1.requestmark,
                   t1.requestlevel,
                   t1.seclevel,
                   t1.requestnametitle,
                   t1.lastfeedbackoperator,
                   t1.lastfeedbackdatetime,
                   t1.flowstatus,
                   t1.createdatetime,
                   t1.finishdatetime,
                   t1.creatorcode,
                   t1.creatorsubcom,
                   t1.creatordept,
                   t1.creatorjob,
                   t1.beagentuserid,
                   t1.datasrc,
                   t1.module,
                   t1.create_time,
                   t1.update_time,
                   t1.creator,
                   t1.delete_type,
                   t1.tenant_key,
                   t1.last_comment_time,
                   t1.minovertime,
                   t1.firstviewdatetime,
                   (case
                      when t1.requestnametitle is null then t1.requestname
                      else t1.requestnametitle end) as requestnameorder,
                   t1.trigger_source,
                   t1.user_master_id,
                   -1                               as currentnodeid
            from wfc_operate_done t1
            WHERE ((t1.flowstatus not in (7, 8) or (t1.flowstatus = 7 and t1.creater = {用户ID})) AND
                   t1.tenant_key = {租户key} AND t1.module = 0 AND t1.delete_type = 0 AND
                   (1 = 1) AND (1 = 1))
              and t1.user_master_id = {用户ID}) t1
ORDER BY createdatetime DESC, requestid DESC
```

## 2.9、全部流程
```sql
select distinct requestid as id,
                requestid,
                workflowtype,
                workflowid,
                creater,
                status,
                requestname,
                requestnamehtml,
                requestnametitle,
                requestmark,
                requestlevel,
                seclevel,
                lastfeedbackoperator,
                lastfeedbackdatetime,
                flowstatus,
                createdatetime,
                finishdatetime,
                creatorcode,
                creatorsubcom,
                creatordept,
                creatorjob,
                datasrc,
                module,
                create_time,
                update_time,
                creator,
                delete_type,
                tenant_key,
                last_comment_time,
                minovertime,
                requestnameorder,
                receivedatetime,
                currentnodeid,
                trigger_source,
                ''        as workflow_code,
                ''        as current_nodename,
                ''        as sys_code,
                ''        as request_code,
                -1        as sys_id,
                -1        as viewtype
from (select t1.requestid                  as id,
             t1.requestid,
             workflowtype,
             t1.workflowid,
             userid                        as creater,
             status,
             requestname,
             requestnamehtml,
             requestnametitle,
             requestmark,
             requestlevel,
             seclevel,
             lastfeedbackoperator,
             lastfeedbackdatetime,
             flowstatus,
             createdatetime,
             finishdatetime,
             creatorcode,
             creatorsubcom,
             creatordept,
             creatorjob,
             t1.datasrc,
             t1.module,
             t1.create_time,
             t1.update_time,
             t1.creator,
             t1.delete_type,
             t1.tenant_key,
             last_comment_time,
             minovertime,
             (case
                when requestnametitle is null then requestname
                else requestnametitle end) as requestnameorder,
             trigger_source,
             -1                            as currentnodeid,
             ''                            as workflow_code,
             ''                            as current_nodename,
             ''                            as sys_code,
             ''                            as request_code,
             -1                            as sys_id,
             -1                            as viewtype,
             null                          as receivedatetime
      from wfc_requestbase t1,
           (select t1.requestid
            from wfc_operate_todo t1
            WHERE ((t1.flowstatus not in (7, 8) or (t1.flowstatus = 7 and t1.creater = {用户ID})) AND
                   t1.tenant_key = {租户key} AND t1.module = 0 AND t1.delete_type = 0 AND
                   (1 = 1) AND (1 = 1))
              and t1.user_master_id in ({用户下属集合、助理下属集合、权限开放用户集合、用户自身})
            union all select t1.requestid
                      from wfc_operate_done t1
                      WHERE ((t1.flowstatus not in (7, 8) or
                              (t1.flowstatus = 7 and t1.creater = {用户ID})) AND t1.tenant_key = {租户key} AND
                             t1.module = 0 AND t1.delete_type = 0 AND 
                             (1 = 1) AND (1 = 1))
                        and t1.user_master_id = {用户ID}) t2
      where t1.requestid = t2.requestid
      union SELECT t1.requestid                     AS id,
                   t1.requestid,
                   t1.workflowtype,
                   t1.workflowid,
                   t1.userid                        AS creater,
                   t1.status,
                   t1.requestname,
                   t1.requestnamehtml,
                   t1.requestnametitle,
                   t1.requestmark,
                   t1.requestlevel,
                   t1.seclevel,
                   t1.lastfeedbackoperator,
                   t1.lastfeedbackdatetime,
                   t1.flowstatus,
                   t1.createdatetime,
                   t1.finishdatetime,
                   t1.creatorcode,
                   t1.creatorsubcom,
                   t1.creatordept,
                   t1.creatorjob,
                   t1.datasrc,
                   t1.module,
                   t1.create_time,
                   t1.update_time,
                   t1.creator,
                   t1.delete_type,
                   t1.tenant_key,
                   t1.last_comment_time,
                   t1.minovertime,
                   (CASE
                      WHEN t1.requestnametitle IS NULL THEN t1.requestname
                      ELSE t1.requestnametitle END) AS requestnameorder,
                   t1.trigger_source,
                   -1                               AS currentnodeid,
                   ''                               AS workflow_code,
                   ''                               AS current_nodename,
                   ''                               AS sys_code,
                   ''                               AS request_code,
                   -1                               AS sys_id,
                   -1                               AS viewtype,
                   NULL                             AS receivedatetime
            FROM wfc_requestbase t1
            WHERE ((t1.flowstatus NOT IN (7, 8) OR (t1.flowstatus = 7 AND t1.creater = {用户ID})) AND
                   t1.tenant_key = {租户key} AND t1.module = 0 AND t1.delete_type = 0 AND
                   (1 = 1) AND (1 = 1))
              AND t1.istest = 0
              AND 1 = 1
              AND t1.requestid in (select wpws.source_id
                                   from wfc_requestbase_ph_wfc_share wpws
                                   where wpws.tenant_key = {租户key}
                                     and (wpws.delete_type = 0 OR wpws.delete_type IS NULL)
                                     and wpws.source_type = 1
                                     AND ((wpws.target_id in ({用户所有身份ID}) and
                                           wpws.target_type = 1) OR
                                          (wpws.target_id in ({类型ID}) and wpws.target_type = {对应类型})
                                             ))) t1
ORDER BY createdatetime DESC, requestid DESC
```