1
0
forked from x/icebergs
icebergs/core/team/task.go
2022-10-17 08:15:39 +08:00

92 lines
2.6 KiB
Go

package team
import (
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/mdb"
kit "shylinux.com/x/toolkits"
)
func _task_action(m *ice.Message, status ice.Any, action ...string) string {
switch status {
case PREPARE:
action = append(action, BEGIN, CANCEL)
case PROCESS:
action = append(action, END, CANCEL)
case CANCEL:
action = append(action, BEGIN)
case FINISH:
}
return kit.Join(action)
}
func _task_modify(m *ice.Message, field, value string, arg ...string) {
if field == STATUS {
switch value {
case PROCESS:
arg = append(arg, BEGIN_TIME, m.Time())
case CANCEL, FINISH:
arg = append(arg, CLOSE_TIME, m.Time())
}
}
mdb.ZoneModify(m, field, value, arg)
}
const ( // type
ONCE = "once"
STEP = "step"
// WEEK = "week"
)
const ( // status
PREPARE = "prepare"
PROCESS = "process"
CANCEL = "cancel"
FINISH = "finish"
)
const ( // key
BEGIN_TIME = "begin_time"
CLOSE_TIME = "close_time"
STATUS = "status"
LEVEL = "level"
SCORE = "score"
)
const (
BEGIN = "begin"
END = "end"
)
const TASK = "task"
func init() {
Index.MergeCommands(ice.Commands{
TASK: {Name: "task zone id auto insert export import", Help: "任务", Actions: ice.MergeActions(ice.Actions{
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
switch arg[0] {
case mdb.STATUS:
m.Push(arg[0], PREPARE, PROCESS, CANCEL, FINISH)
case LEVEL, SCORE:
m.Push(arg[0], "1", "2", "3", "4", "5")
case mdb.TYPE:
m.Push(arg[0], ONCE, STEP, WEEK)
default:
mdb.HashInputs(m, arg)
}
}},
mdb.INSERT: {Name: "insert zone type=once,step,week name text begin_time@date close_time@date", Hand: func(m *ice.Message, arg ...string) {
mdb.ZoneInsert(m, arg[:2], BEGIN_TIME, m.Time(), STATUS, PREPARE, LEVEL, 3, SCORE, 3, arg[2:])
}},
mdb.MODIFY: {Hand: func(m *ice.Message, arg ...string) { _task_modify(m, arg[0], arg[1], arg[2:]...) }},
CANCEL: {Name: "cancal", Help: "取消", Hand: func(m *ice.Message, arg ...string) { _task_modify(m, STATUS, CANCEL) }},
BEGIN: {Name: "begin", Help: "开始", Hand: func(m *ice.Message, arg ...string) { _task_modify(m, STATUS, PROCESS) }},
END: {Name: "end", Help: "完成", Hand: func(m *ice.Message, arg ...string) { _task_modify(m, STATUS, FINISH) }},
}, mdb.ZoneAction(mdb.FIELD, "begin_time,close_time,id,status,level,score,type,name,text")), Hand: func(m *ice.Message, arg ...string) {
if mdb.ZoneSelect(m, arg...); len(arg) > 0 && arg[0] != "" {
status := map[string]int{}
m.Tables(func(value ice.Maps) {
m.PushButton(_task_action(m, value[STATUS]))
status[value[mdb.STATUS]]++
})
m.StatusTimeCount(status)
}
}},
})
}