+ xiang.table.QuickSave
This commit is contained in:
parent
5e6739cd09
commit
17b8432390
5 changed files with 87 additions and 1 deletions
|
|
@ -1,7 +1,7 @@
|
|||
package share
|
||||
|
||||
// VERSION 版本号
|
||||
const VERSION = "0.9.11"
|
||||
const VERSION = "0.9.12"
|
||||
|
||||
// DOMAIN 许可域(废弃)
|
||||
const DOMAIN = "*.iqka.com"
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ func init() {
|
|||
gou.RegisterProcessHandler("xiang.table.Insert", ProcessInsert)
|
||||
gou.RegisterProcessHandler("xiang.table.UpdateWhere", ProcessUpdateWhere)
|
||||
gou.RegisterProcessHandler("xiang.table.DeleteWhere", ProcessDeleteWhere)
|
||||
gou.RegisterProcessHandler("xiang.table.QuickSave", ProcessQuickSave)
|
||||
gou.RegisterProcessHandler("xiang.table.UpdateIn", ProcessUpdateIn)
|
||||
gou.RegisterProcessHandler("xiang.table.DeleteIn", ProcessDeleteIn)
|
||||
gou.RegisterProcessHandler("xiang.table.Setting", ProcessSetting)
|
||||
|
|
@ -234,3 +235,31 @@ func ProcessSetting(process *gou.Process) interface{} {
|
|||
|
||||
return gou.NewProcess(api.Process, fields).Run()
|
||||
}
|
||||
|
||||
// ProcessQuickSave xiang.table.QuickSave
|
||||
// 保存多条记录。如数据记录中包含主键字段则更新,不包含主键字段则创建记录;返回创建或更新的记录主键值
|
||||
func ProcessQuickSave(process *gou.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
name := process.ArgsString(0)
|
||||
table := Select(name)
|
||||
api := table.APIs["quicksave"].ValidateLoop("xiang.table.quicksave")
|
||||
if process.NumOfArgsIs(3) && api.IsAllow(process.Args[2]) {
|
||||
return nil
|
||||
}
|
||||
|
||||
args := []interface{}{}
|
||||
payload := process.ArgsMap(1)
|
||||
ids := []int{}
|
||||
if payload.Has("delete") {
|
||||
if v, ok := payload["delete"].([]int); ok {
|
||||
ids = v
|
||||
}
|
||||
}
|
||||
args = append(args, ids)
|
||||
args = append(args, payload.Get("data"))
|
||||
if payload.Has("query") {
|
||||
args = append(args, payload.Get("query"))
|
||||
}
|
||||
|
||||
return gou.NewProcess(api.Process, args...).Run()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -312,3 +312,49 @@ func TestTableProcessSettingListEdit(t *testing.T) {
|
|||
assert.True(t, res.Has("edit.layout"))
|
||||
assert.True(t, res.Has("edit.primary"))
|
||||
}
|
||||
|
||||
func TestTableProcessQuickSave(t *testing.T) {
|
||||
args := []interface{}{
|
||||
"service",
|
||||
map[string]interface{}{
|
||||
"name": "腾讯黑岩云主机",
|
||||
"short_name": "高性能云主机",
|
||||
"kind_id": 3,
|
||||
"manu_id": 1,
|
||||
"price_options": []string{"按月订阅"},
|
||||
},
|
||||
}
|
||||
process := gou.NewProcess("xiang.table.Save", args...)
|
||||
response := ProcessSave(process)
|
||||
assert.NotNil(t, response)
|
||||
assert.True(t, any.Of(response).IsInt())
|
||||
|
||||
id := any.Of(response).CInt()
|
||||
args = []interface{}{
|
||||
"service",
|
||||
id,
|
||||
}
|
||||
|
||||
process = gou.NewProcess("xiang.table.QuickSave",
|
||||
"service",
|
||||
map[string]interface{}{
|
||||
"delete": []int{id},
|
||||
"data": []map[string]interface{}{
|
||||
{
|
||||
"name": "腾讯黑岩云主机2",
|
||||
"short_name": "高性能云主机2",
|
||||
"kind_id": 3,
|
||||
"manu_id": 1,
|
||||
"price_options": []string{"按月订阅"},
|
||||
},
|
||||
},
|
||||
"query": map[string]interface{}{"manu_id": 1},
|
||||
})
|
||||
res := process.Run()
|
||||
newID, ok := res.([]int)
|
||||
assert.True(t, ok)
|
||||
assert.NotEqual(t, id, newID[0])
|
||||
|
||||
// 清空数据
|
||||
capsule.Query().Table("service").WhereIn("id", []int{id, newID[0]}).Delete()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,6 +140,7 @@ func getDefaultAPIs(bind Bind) map[string]share.API {
|
|||
"delete-where": apiDefaultWhere(model, bind.Withs, "delete-where", "DeleteWhere"),
|
||||
"update-in": apiDefault(model, "update-in", "UpdateWhere"),
|
||||
"update-where": apiDefaultWhere(model, bind.Withs, "update-where", "UpdateWhere"),
|
||||
"quicksave": apiDefault(model, "quicksave", "EachSaveAfterDelete"),
|
||||
}
|
||||
|
||||
return apis
|
||||
|
|
|
|||
|
|
@ -35,6 +35,16 @@
|
|||
"type": "application/json"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/:name/quicksave",
|
||||
"method": "POST",
|
||||
"process": "xiang.table.QuickSave",
|
||||
"in": ["$param.name", ":payload"],
|
||||
"out": {
|
||||
"status": 200,
|
||||
"type": "application/json"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/:name/delete/:id",
|
||||
"method": "POST",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue