mirror of
https://shylinux.com/x/community
synced 2025-07-01 13:14:44 +08:00
78 lines
2.8 KiB
Go
78 lines
2.8 KiB
Go
package gonganxitong
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"shylinux.com/x/ice"
|
|
kit "shylinux.com/x/toolkits"
|
|
|
|
"shylinux.com/x/community/src/gonganxitong/model"
|
|
)
|
|
|
|
type clean struct {
|
|
Tables
|
|
list string `name:"list place_uid uid auto" help:"清理" role:"tech"`
|
|
}
|
|
|
|
func (s clean) List(m *ice.Message, arg ...string) {
|
|
if !m.IsTech() {
|
|
return
|
|
}
|
|
if len(arg) == 0 {
|
|
s.Tables.Tables(m, kit.Format("left join %s on %s = %s", s.TableNames(s.UserPlace), s.Key(s.UserPlace, s.Keys(s.Place, model.UID)), s.Key(s.Place, model.UID)))
|
|
s.Fields(m, s.Key(s.Place, model.UID), s.Key(s.Place, model.CREATED_AT), s.Key(s.Place, model.NAME), "count(*) AS count", s.Key(s.UserPlace, model.USER_UID)).Groups(m, s.Key(s.Place, model.UID))
|
|
s.Orders(m, model.COUNT, s.Key(s.Place, model.CREATED_AT)).Limit(m, 300)
|
|
m.Cmdy(s.Place, s.Select)
|
|
m.RenameAppend(model.UID, s.Keys(s.Place, model.UID))
|
|
m.PushAction(s.Open, s.Member).Action()
|
|
s.SelectJoinUser(m)
|
|
} else if len(arg) == 1 {
|
|
for k, h := range m.Target().Commands {
|
|
if c, ok := m.Target().Configs[k]; !ok || kit.Value(c.Value, "meta.model") == nil {
|
|
continue
|
|
}
|
|
// m.Push("cmd", k)
|
|
m.Push("uid", k)
|
|
m.Push("name", h.Name)
|
|
m.Push("help", h.Help)
|
|
m.Push("actions", len(h.Actions))
|
|
PLACE_UID := kit.Split(h.Name)[1]
|
|
s.Fields(m, "count(*) AS count")
|
|
msg := m.Cmd(m.Prefix(k), s.Select, PLACE_UID, arg[0])
|
|
m.Push("count", msg.Append("count"))
|
|
}
|
|
m.Action(s.Prune).SortIntR("count,cmd")
|
|
} else {
|
|
h := m.Target().Commands[arg[1]]
|
|
PLACE_UID := kit.Split(h.Name)[1]
|
|
if s.Fields(m, "*"); kit.TypeName(s.Place) == arg[1] {
|
|
m.Cmdy(m.Prefix(arg[1]), s.Select, model.UID, arg[0])
|
|
} else {
|
|
m.Cmdy(m.Prefix(arg[1]), s.Select, PLACE_UID, arg[0])
|
|
}
|
|
}
|
|
}
|
|
func (s clean) Prune(m *ice.Message, arg ...string) {
|
|
for k, h := range m.Target().Commands {
|
|
if k == "service" {
|
|
continue
|
|
}
|
|
if c, ok := m.Target().Configs[k]; !ok || kit.Value(c.Value, "meta.model") == nil {
|
|
continue
|
|
}
|
|
PLACE_UID := kit.Split(h.Name)[1]
|
|
kit.If(k == kit.TypeName(s.Place), func() { PLACE_UID = model.UID })
|
|
m.Cmd(m.Prefix(k), s.Exec, kit.Format("update %s set deleted_at = %q where %s = %q", s.TableName(k), m.Time(), PLACE_UID, arg[0]))
|
|
}
|
|
// m.Cmd(s.Prefix(m, s.Place), s.Exec, kit.Format("update %s set deleted_at = %q where %s = %q", s.TableNames(s.Place), m.Time(), model.UID, arg[0]))
|
|
}
|
|
func (s clean) Open(m *ice.Message, arg ...string) {
|
|
m.ProcessOpen(m.MergePodCmd("", s.PrefixPortal(m), m.OptionSimple(s.Keys(s.Place, model.UID))))
|
|
}
|
|
func (s clean) Member(m *ice.Message, arg ...string) {
|
|
m.ProcessOpen(m.MergePodCmd("", s.PrefixPortal(m), m.OptionSimple(s.Keys(s.Place, model.UID))) +
|
|
"#" + strings.Join([]string{m.Option(s.Keys(s.Place, model.UID)), s.Prefix(m, member{})}, ":"))
|
|
}
|
|
|
|
func init() { ice.TeamCtxCmd(clean{Tables: newTables()}) }
|