mirror of
https://shylinux.com/x/community
synced 2025-05-11 07:58:10 +08:00
108 lines
3.7 KiB
Go
108 lines
3.7 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
|
|
user user
|
|
apply apply
|
|
event event
|
|
portal Portal
|
|
order string `data:"503"`
|
|
role string `data:"creator"`
|
|
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("role allow process", "权限审批 请处理"))
|
|
}
|
|
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, "left join users on applies.user_uid = users.uid").FieldsWithCreatedAT(m, s.apply,
|
|
s.AS(s.Key(s, model.UID), model.ALLOW_UID), model.ALLOW_STATUS, s.AS(s.Key(s.apply, model.ROLE), s.Keys(s.UserPlace, model.ROLE)),
|
|
model.BEGIN_TIME, model.END_TIME, s.Key(s, model.PLACE_UID), s.Key(s.apply, model.USER_UID),
|
|
)
|
|
if len(arg) == 1 {
|
|
s.Select(m, s.Key(s, model.USER_UID), m.Option(model.USER_UID), s.Key(s, model.PLACE_UID), arg[0])
|
|
} else if len(arg) == 2 {
|
|
s.SelectDetail(m, s.Key(s, model.USER_UID), m.Option(model.USER_UID), s.Key(s, model.PLACE_UID), arg[0], s.Key(s.apply, model.UID), arg[1])
|
|
} else {
|
|
return
|
|
}
|
|
if m.Length() == 0 {
|
|
m.Cmdy(s.Prefix(m, qrcode{}), s.ApplyQRCode, arg)
|
|
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.DoneMessage(m)
|
|
}
|
|
}).Action(s.ApplyQRCode)
|
|
s.RenameAppend(m, model.PLACE_UID, s.Keys(s.Place, model.UID))
|
|
s.SelectJoin(m, s.Place, model.NAME, model.TYPE)
|
|
s.SelectJoinUser(m)
|
|
s.DisplayBase(m, "")
|
|
}
|
|
func (s allow) Reject(m *ice.Message, arg ...string) {
|
|
s.process(m, AllowCreate, AllowRejected, "❌", m.Trans("role allow rejected", "权限审批 已驳回"))
|
|
}
|
|
func (s allow) Approve(m *ice.Message, arg ...string) {
|
|
s.process(m, AllowCreate, AllowApproved, "✅", m.Trans("role allow approved", "权限审批 已通过"))
|
|
}
|
|
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()
|
|
s.RecordEvent(m, kit.JoinWord(icon, title, kit.Cut(m.Option(model.UID), 6), s.TransRole(m), m.Option(model.USER_NAME)), m.Option(model.UID))
|
|
s.DoneMessage(m)
|
|
}
|
|
|
|
func init() { ice.TeamCtxCmd(allow{Table: newTable()}) }
|
|
|
|
func (s allow) changeStatus(m *ice.Message, from, todo 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.UID)) {
|
|
if status := AllowStatus(kit.Int(msg.Append(model.STATUS))); !m.WarnNotValid(status != from, status.String()) {
|
|
s.Update(m, kit.Dict(model.STATUS, todo), model.UID, m.Option(model.ALLOW_UID))
|
|
}
|
|
}
|
|
return msg
|
|
}
|
|
func (s allow) sendTemplate(m *ice.Message, info string) *ice.Message {
|
|
s.SendTemplate(m, m.Option(model.USER_NAME), m.Append(model.USER_UID), info)
|
|
return m
|
|
}
|
|
|
|
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] }
|