mirror of
https://shylinux.com/x/community
synced 2025-05-08 14:48:11 +08:00
104 lines
3.5 KiB
Go
104 lines
3.5 KiB
Go
package gonganxitong
|
|
|
|
import (
|
|
"shylinux.com/x/ice"
|
|
kit "shylinux.com/x/toolkits"
|
|
|
|
"shylinux.com/x/community/src/gonganxitong/model"
|
|
)
|
|
|
|
type allow struct {
|
|
Table
|
|
apply apply
|
|
order string `data:"503"`
|
|
role string `data:"leader"`
|
|
create string `name:"create apply_uid* place_uid* user_uid* status*"`
|
|
reject string `name:"reject" role:"void"`
|
|
approve string `name:"approve" role:"void"`
|
|
applyQRCode string `name:"applyQRCode" role:"void"`
|
|
}
|
|
|
|
func (s allow) Create(m *ice.Message, arg ...string) {
|
|
s.Insert(m.Spawn(), arg...)
|
|
s.GetCommandUID(m)
|
|
s.SendMessage(m, m.Option(model.FROM_USER_UID), "")
|
|
s.SendTemplate(m, "", "", m.Trans("please allow", "权限审批 请处理"))
|
|
}
|
|
func (s allow) ApplyQRCode(m *ice.Message, arg ...string) {
|
|
m.Cmdy(s.Prefix(m, qrcode{}), m.ActionKey(), arg)
|
|
}
|
|
func (s allow) List(m *ice.Message, arg ...string) {
|
|
s.Tables(m, s.apply).FieldsWithCreatedAT(m, s.apply,
|
|
s.Key(s.apply, model.USER_UID),
|
|
s.AS(s.Key(s.apply, model.ROLE), s.Keys(s.UserPlace, model.ROLE)), model.BEGIN_TIME, model.END_TIME,
|
|
s.AS(s.Key(s, model.UID), model.ALLOW_UID), model.ALLOW_STATUS,
|
|
)
|
|
if len(arg) == 1 {
|
|
s.Select(m, s.Key(s, model.PLACE_UID), arg[0], s.Key(s, model.USER_UID), m.Option(model.USER_UID)).Action(s.ApplyQRCode)
|
|
if m.Length() == 0 {
|
|
m.Cmdy(s.Prefix(m, qrcode{}), s.ApplyQRCode, arg)
|
|
return
|
|
}
|
|
} else if len(arg) == 2 {
|
|
s.SelectDetail(m, s.Key(s, model.PLACE_UID), arg[0], s.Key(s, model.USER_UID), m.Option(model.USER_UID), s.Key(s.apply, model.UID), arg[1])
|
|
m.Table(func(value ice.Maps) {
|
|
if AllowStatus(kit.Int(value[model.ALLOW_STATUS])) != AllowCreate {
|
|
s.DoneMessage(m)
|
|
}
|
|
})
|
|
} else {
|
|
return
|
|
}
|
|
m.Table(func(value ice.Maps) {
|
|
if AllowStatus(kit.Int(value[model.ALLOW_STATUS])) == AllowCreate {
|
|
m.PushButton(s.Reject, s.Approve)
|
|
} else {
|
|
m.PushButton()
|
|
}
|
|
})
|
|
s.SelectJoinUser(m)
|
|
s.DisplayBase(m, "")
|
|
}
|
|
func (s allow) Reject(m *ice.Message, arg ...string) {
|
|
s.process(m, AllowCreate, AllowRejected, "❌", m.Trans("allow rejected", "权限审批 已驳回"))
|
|
}
|
|
func (s allow) Approve(m *ice.Message, arg ...string) {
|
|
s.process(m, AllowCreate, AllowApproved, "✅", m.Trans("allow approved", "权限审批 已通过"))
|
|
}
|
|
func init() { ice.TeamCtxCmd(allow{Table: newTable()}) }
|
|
|
|
func (s allow) process(m *ice.Message, from, to AllowStatus, icon string, title string) {
|
|
if s.changeStatus(m, from, to); m.IsErr() {
|
|
return
|
|
}
|
|
m.Cmdy(s.Prefix(m, s.apply), m.ActionKey(), m.Option(model.UID)).ProcessRefresh()
|
|
style := kit.Select("notice", "danger", kit.Int(m.Option(model.ROLE)) == 2)
|
|
s.RecordEvent(m, kit.JoinWord(icon, title, kit.Cut(m.Option(model.UID), 6), s.TransRole(m, "", style), m.Option(model.USER_NAME)), m.Option(model.UID))
|
|
s.DoneMessage(m)
|
|
}
|
|
func (s allow) changeStatus(m *ice.Message, from, to AllowStatus, arg ...string) *ice.Message {
|
|
msg := s.Select(m.Spawn(), model.UID, m.Option(model.ALLOW_UID), model.USER_UID, m.Option(model.USER_UID))
|
|
if !m.WarnNotFound(msg.Length() == 0, m.Option(model.ALLOW_UID)) {
|
|
if status := AllowStatus(kit.Int(msg.Append(model.STATUS))); !m.WarnNotValid(status != from, status.String()) {
|
|
s.Update(m, kit.Dict(model.STATUS, to), model.UID, m.Option(model.ALLOW_UID), model.USER_UID, m.Option(model.USER_UID))
|
|
}
|
|
}
|
|
return msg
|
|
}
|
|
|
|
type AllowStatus int
|
|
|
|
const (
|
|
AllowCreate AllowStatus = iota
|
|
AllowRejected
|
|
AllowApproved
|
|
)
|
|
|
|
var AllowStatusList = map[AllowStatus]string{
|
|
AllowCreate: "create",
|
|
AllowRejected: "rejected",
|
|
AllowApproved: "approved",
|
|
}
|
|
|
|
func (s AllowStatus) String() string { return AllowStatusList[s] }
|