Skip to content

Commit

Permalink
GetInstanceStartByUser、GetTaskToDoList、GetTaskFinishedList三个函数中可以传入空U…
Browse files Browse the repository at this point in the history
…serID,返回所有用户的实例、任务信息
  • Loading branch information
兔老三 committed Dec 27, 2023
1 parent addae39 commit 33febac
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 11 deletions.
35 changes: 35 additions & 0 deletions example/docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions example/docs/swagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"swagger": "2.0",
"info": {
"contact": {}
},
"paths": {}
}
4 changes: 4 additions & 0 deletions example/docs/swagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
info:
contact: {}
paths: {}
swagger: "2.0"
6 changes: 3 additions & 3 deletions workflow/engine/ProcessInstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func GetInstanceInfo(ProcessInstanceID int) (Instance, error) {
}

//获取起始人为特定用户的流程实例。参数说明:
//UserID:用户ID
//UserID:用户ID 传入空则获取所有用户的流程实例
//ProcessName:指定流程名称,传入""则为全部
//StartIndex:分页用,开始index
//MaxRows:分页用,最大返回行数
Expand All @@ -256,12 +256,12 @@ func GetInstanceStartByUser(UserID string,ProcessName string,StartIndex int,MaxR
"(SELECT id,proc_id,proc_version,business_id,starter,current_node_id,\n" +
"create_time,`status`\n" +
"FROM proc_inst \n" +
"WHERE starter=@userid\n" +
"WHERE CASE WHEN ''=@userid THEN TRUE ELSE starter=@userid END\n" +
"UNION ALL\n" +
"SELECT proc_inst_id AS id,proc_id,proc_version,business_id,starter,current_node_id,\n" +
"create_time,`status` \n" +
"FROM hist_proc_inst \n" +
"WHERE starter=@userid)\n" +
"WHERE CASE WHEN ''=@userid THEN TRUE ELSE starter=@userid END)\n" +

"SELECT a.id,a.proc_id,a.proc_version,a.business_id,\n" +
"a.starter,a.current_node_id,a.create_time,a.`status`,b.name\n" +
Expand Down
18 changes: 13 additions & 5 deletions workflow/engine/ProcessTask.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func GetTaskInfo(TaskID int) (Task, error) {
}

//获取特定用户待办任务列表。参数说明:
//UserID:用户ID
//UserID:用户ID 传入空则获取所有用户的待办任务
//ProcessName:指定流程名称,传入""则为全部
//SortByASC 返回数据是否按照任务生成时间升序排列(实际是按照TaskID排序。TaskID是int型自增字段,用其排序与用createtime效果一致)。若传入false,则会按照降序排列
//StartIndex:分页用,开始index
Expand All @@ -358,7 +358,7 @@ func GetTaskToDoList(UserID string, ProcessName string, SortByASC bool, StartInd
"a.finished_time\n" +
"FROM proc_task a\n" +
"JOIN `proc_def` b ON a.proc_id=b.id\n" +
"WHERE a.user_id=@userid\n" +
"WHERE CASE WHEN ''=@userid THEN TRUE ELSE a.user_id=@userid END\n" +
" AND a.is_finished=0 \n" +
"AND CASE WHEN ''=@procname THEN TRUE ELSE b.name=@procname END\n" +
"ORDER BY a.id\n" +
Expand All @@ -375,7 +375,8 @@ func GetTaskToDoList(UserID string, ProcessName string, SortByASC bool, StartInd
}

// 获取特定用户已完成任务列表。参数说明:
// UserID:用户ID
// UserID:用户ID 传入空则获取所有用户的已完成任务
///*注意,当传入UserID为空时,IgnoreStartByMe参数强制为False
// ProcessName:指定流程名称,传入""则为全部
// IgnoreStartByMe: 某些情况下只希望看到“别人提交由我审批完成的任务",而不希望看到"由我开启流程,而生成处理人是我自己的任务",则传True
// taps:"由我启动的流程"可使用GetInstanceStartByUser函数
Expand All @@ -393,14 +394,21 @@ func GetTaskFinishedList(UserID string, ProcessName string, IgnoreStartByMe bool
sortBy = "DESC"
}

//当传入UserID为空时,IgnoreStartByMe参数强制变为False
//因为sql语句的判断是这样的: AND CASE WHEN true=@ignorestartbyme THEN a.starter!=@userid ELSE TRUE END
//当UserID为空时,a.starter!=@userid永远成立,所以不需要做这个判断,直接pass掉
if UserID==""{
IgnoreStartByMe=false
}

sql := "WITH tmp_task AS\n" +
"(SELECT id,proc_id, proc_inst_id,business_id,starter,node_id,node_name,prev_node_id,is_cosigned,\n" +
"batch_code,user_id,`status` ,is_finished,`comment`,proc_inst_create_time,create_time,finished_time \n" +
"FROM proc_task WHERE user_id=@userid\n" +
"FROM proc_task WHERE CASE WHEN ''=@userid THEN TRUE ELSE user_id=@userid END\n" +
"UNION ALL\n" +
"SELECT task_id AS id,proc_id, proc_inst_id,business_id,starter,node_id,node_name,prev_node_id,is_cosigned,\n" +
"batch_code,user_id,`status` ,is_finished,`comment`,proc_inst_create_time,create_time,finished_time \n" +
"FROM hist_proc_task WHERE user_id=@userid\n" +
"FROM hist_proc_task WHERE CASE WHEN ''=@userid THEN TRUE ELSE user_id=@userid END\n" +
")\n\n" +
"SELECT a.id,a.proc_id,b.name,a.proc_inst_id,a.business_id,a.starter,a.node_id,a.node_name,a.prev_node_id,a.is_cosigned,\n" +
"a.batch_code,a.user_id,a.`status` ,a.is_finished,a.`comment`,\n" +
Expand Down
6 changes: 3 additions & 3 deletions workflow/web_api/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func ProcInst_TaskHistory(c *gin.Context) {
// @Description
// @Tags 流程实例
// @Produce json
// @Param userid query string true "用户ID" example("U001")
// @Param userid query string true "用户ID 传入空则获取所有用户的流程实例" example("U001")
// @Param procname query string false "指定流程名称,非必填" example("请假")
// @Param idx query int true "分页用,开始index" example(0)
// @Param rows query int true "分页用,最大返回行数" example(0)
Expand Down Expand Up @@ -311,7 +311,7 @@ func Task_Transfer(c *gin.Context) {
// @Description 返回的是任务数组
// @Tags 任务
// @Produce json
// @Param userid query string true "用户ID" example("U001")
// @Param userid query string true "用户ID 传入空则获取所有用户的待办任务" example("U001")
// @Param procname query string false "指定流程名称,非必填" example("请假")
// @Param asc query bool true "是否按照任务生成时间升序排列" example(true)
// @Param idx query int true "分页用,开始index" example(0)
Expand Down Expand Up @@ -349,7 +349,7 @@ func Task_ToDoList(c *gin.Context) {
// @Description 返回的是任务数组
// @Tags 任务
// @Produce json
// @Param userid query string true "用户ID" example("U001")
// @Param userid query string true "用户ID 传入空则获取所有用户的已完成任务(此时IgnoreStartByMe参数强制为False)" example("U001")
// @Param procname query string false "指定流程名称,非必填" example("请假")
// @Param ignorestartbyme query bool true "忽略由我开启流程,而生成处理人是我自己的任务" example("true")
// @Param asc query bool true "是否按照任务完成时间升序排列" example(true)
Expand Down

0 comments on commit 33febac

Please sign in to comment.