工作流保存数据排重
This commit is contained in:
parent
d8f71ec6ef
commit
30799d5c30
7 changed files with 56 additions and 7 deletions
|
|
@ -114,6 +114,20 @@ func ArrayPluck(columns []string, pluck map[string]interface{}) []map[string]int
|
|||
return res
|
||||
}
|
||||
|
||||
// ArrayUnique 数组排重
|
||||
func ArrayUnique(columns []interface{}) []interface{} {
|
||||
res := []interface{}{}
|
||||
m := make(map[string]bool)
|
||||
for _, val := range columns {
|
||||
key := fmt.Sprintf("%v", val)
|
||||
if _, ok := m[key]; !ok {
|
||||
m[key] = true
|
||||
res = append(res, val)
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// OfArrayPluckValue Any 转 ArrayPluckValue
|
||||
func OfArrayPluckValue(any interface{}) ArrayPluckValue {
|
||||
content, err := jsoniter.Marshal(any)
|
||||
|
|
|
|||
|
|
@ -45,3 +45,12 @@ func ProcessArrayTree(process *gou.Process) interface{} {
|
|||
setting := process.ArgsMap(1)
|
||||
return ArrayTree(records, setting)
|
||||
}
|
||||
|
||||
// ProcessArrayUnique xiang.helper.ArrayUnique 数组排重
|
||||
func ProcessArrayUnique(process *gou.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
if arr, ok := process.Args[0].([]interface{}); ok {
|
||||
return ArrayUnique(arr)
|
||||
}
|
||||
return process.Args[0]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,3 +154,15 @@ func TestProcessArraySplit(t *testing.T) {
|
|||
assert.Equal(t, 2, len(value))
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcessArrayUnique(t *testing.T) {
|
||||
args := []interface{}{
|
||||
[]interface{}{1, 2, 3, 3},
|
||||
}
|
||||
process := gou.NewProcess("xiang.helper.ArrayUnique", args...)
|
||||
response := process.Run()
|
||||
assert.NotNil(t, response)
|
||||
res, ok := response.([]interface{})
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, []interface{}{1, 2, 3}, res)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ func init() {
|
|||
gou.RegisterProcessHandler("xiang.helper.ArrayColumn", ProcessArrayColumn)
|
||||
gou.RegisterProcessHandler("xiang.helper.ArrayKeep", ProcessArrayKeep)
|
||||
gou.RegisterProcessHandler("xiang.helper.ArrayTree", ProcessArrayTree)
|
||||
gou.RegisterProcessHandler("xiang.helper.ArrayUnique", ProcessArrayUnique)
|
||||
|
||||
gou.RegisterProcessHandler("xiang.helper.MapKeys", ProcessMapKeys)
|
||||
gou.RegisterProcessHandler("xiang.helper.MapValues", ProcessMapValues)
|
||||
|
|
|
|||
|
|
@ -7,8 +7,10 @@ import (
|
|||
"github.com/yaoapp/gou"
|
||||
"github.com/yaoapp/kun/exception"
|
||||
"github.com/yaoapp/xiang/config"
|
||||
"github.com/yaoapp/xiang/helper"
|
||||
"github.com/yaoapp/xiang/share"
|
||||
"github.com/yaoapp/xiang/xlog"
|
||||
"github.com/yaoapp/xun/dbal"
|
||||
)
|
||||
|
||||
// WorkFlows 工作流列表
|
||||
|
|
@ -120,14 +122,16 @@ func (workflow *WorkFlow) Get(uid int, name string, id interface{}) map[string]i
|
|||
// Save 保存工作流节点数据
|
||||
func (workflow *WorkFlow) Save(uid int, name string, id interface{}, input Input) map[string]interface{} {
|
||||
wflow := gou.Select("xiang.workflow")
|
||||
hasUser := dbal.Raw(fmt.Sprintf("JSON_CONTAINS(users, '%d', '$')", uid))
|
||||
params := gou.QueryParam{
|
||||
Select: []interface{}{"id", "input"},
|
||||
Select: []interface{}{"id", "input", "users"},
|
||||
Wheres: []gou.QueryWhere{
|
||||
{Column: "name", Value: workflow.Name},
|
||||
{Column: "data_id", Value: id},
|
||||
{Column: "user_id", Value: uid},
|
||||
{Column: hasUser},
|
||||
{Column: "status", Value: "进行中"},
|
||||
},
|
||||
Limit: 1,
|
||||
}
|
||||
|
||||
rows := wflow.MustGet(params)
|
||||
|
|
@ -139,19 +143,27 @@ func (workflow *WorkFlow) Save(uid int, name string, id interface{}, input Input
|
|||
}
|
||||
if len(rows) > 0 {
|
||||
nodeInput := map[string]interface{}{}
|
||||
users := []interface{}{uid}
|
||||
if history, ok := rows[0].Get("input").(map[string]interface{}); ok {
|
||||
nodeInput = history
|
||||
}
|
||||
if last, ok := rows[0].Get("users").([]interface{}); ok {
|
||||
users = last
|
||||
users = append(users, uid)
|
||||
users = helper.ArrayUnique(users)
|
||||
}
|
||||
nodeInput[name] = input
|
||||
data["id"] = rows[0].Get("id")
|
||||
data["input"] = nodeInput
|
||||
data["users"] = users
|
||||
} else {
|
||||
|
||||
nodeInput := map[string]interface{}{}
|
||||
users := []interface{}{uid}
|
||||
nodeInput[name] = input
|
||||
data["status"] = "进行中"
|
||||
data["node_status"] = "进行中"
|
||||
data["input"] = nodeInput
|
||||
data["users"] = users
|
||||
}
|
||||
|
||||
id = wflow.MustSave(data)
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ func TestSave(t *testing.T) {
|
|||
Data: map[string]interface{}{"id": 1, "name": "云主机"},
|
||||
Form: map[string]interface{}{"biz_id": 1, "name": "张良明"},
|
||||
})
|
||||
|
||||
data := maps.Of(wflow).Dot()
|
||||
assert.Equal(t, int64(1), data.Get("id"))
|
||||
assert.Equal(t, "选择商务负责人", data.Get("node_name"))
|
||||
|
|
@ -54,12 +55,12 @@ func TestSave(t *testing.T) {
|
|||
|
||||
func TestSaveUpdate(t *testing.T) {
|
||||
assignFlow := Select("assign")
|
||||
assignFlow.Save(1, "选择商务负责人", 1, Input{
|
||||
wflow := assignFlow.Save(1, "选择商务负责人", 1, Input{
|
||||
Data: map[string]interface{}{"id": 1, "name": "云主机"},
|
||||
Form: map[string]interface{}{"biz_id": 1, "name": "张良明"},
|
||||
})
|
||||
|
||||
wflow := assignFlow.Save(1, "选择商务负责人", 1, Input{
|
||||
wflow = assignFlow.Save(1, "选择商务负责人", 1, Input{
|
||||
Data: map[string]interface{}{"id": 1, "name": "云存储"},
|
||||
Form: map[string]interface{}{"biz_id": 1, "name": "李明博"},
|
||||
})
|
||||
|
|
|
|||
|
|
@ -70,8 +70,8 @@
|
|||
},
|
||||
{
|
||||
"label": "处理人",
|
||||
"comment": "处理人选取条件",
|
||||
"name": "user",
|
||||
"comment": "关联处理人",
|
||||
"name": "users",
|
||||
"type": "json",
|
||||
"nullable": true
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue