2025-05-04 08:48:49 +08:00

84 lines
2.4 KiB
Go

package renzhengshouquan
import (
"strconv"
"shylinux.com/x/ice"
"shylinux.com/x/icebergs/base/aaa"
kit "shylinux.com/x/toolkits"
"shylinux.com/x/community/src/api"
"shylinux.com/x/community/src/renzhengshouquan/model"
"shylinux.com/x/enterprise/src/guanlixitong"
)
type Table struct {
guanlixitong.Table
list string `name:"list auth_uid uid auto" role:"void"`
}
func (s Table) Inputs(m *ice.Message, arg ...string) {
switch arg[0] {
case model.USER_AUTH_ROLE:
s.InputsListRole(m, UserAuthRoleList, arg...)
case model.AUTH_TYPE:
s.InputsListSkip(m, AuthTypeList, kit.Select("0", "-1", m.IsTech()), arg...)
case model.AUTH_STATUS:
s.InputsList(m, AuthStatusList, arg...)
case model.FROM_UID:
if AuthType(kit.Int(m.Option(model.AUTH_TYPE))) == AuthRoot {
m.Push(arg[0], aaa.ROOT)
}
default:
s.Table.Inputs(m, arg...)
}
}
func (s Table) Config(m *ice.Message, arg ...string) {
}
func (s Table) AuthList(m *ice.Message, auth_uid string, cb func(value ice.Maps, auth bool)) {
m.Cmdy(api.RENZHENGSHOUQUAN_AUTH, auth_uid).Table(func(value ice.Maps) {
if value[model.AUTH_STATUS] == AuthIssued.String() {
cb(value, true)
} else {
cb(value, false)
}
})
}
func (s Table) authSort(m *ice.Message, arg ...string) {
s.RewriteAppend(m)
m.Sort("auth_status,auth_type,score,created_at", []string{"issued"},
[]string{"personal", "root", "city", "street", "school", "company", "service"}, ice.INT_R, ice.STR_R)
}
func (s Table) RewriteAppend(m *ice.Message, arg ...string) *ice.Message {
m.RewriteAppend(func(value, key string, index int) string {
if _, e := strconv.ParseInt(value, 10, 64); e != nil {
return value
}
switch key {
case model.USER_AUTH_ROLE:
value = UserAuthRole(kit.Int(value)).String()
case model.AUTH_TYPE:
value = AuthType(kit.Int(value)).String()
case model.AUTH_STATUS:
value = AuthStatus(kit.Int(value)).String()
case model.CERT_STATUS:
value = CertStatus(kit.Int(value)).String()
}
return value
})
return s.Table.RewriteAppend(m)
}
func (s Table) GetAuthUID(m *ice.Message, arg ...string) string {
// auth_uid := m.Cmdx(ctx.CONFIG, api.RENZHENGSHOUQUAN_PORTAL, kit.Keym(model.AUTH_UID))
// m.Info("default auth_uid %v", auth_uid)
// return auth_uid
msg := m.Cmd(Auth{}, s.Select, model.TYPE, AuthRoot)
m.Info("default auth_uid %v", msg.Append(model.UID))
return msg.Append(model.UID)
}
type Tables struct{ Table }
func (s Tables) BeforeMigrate(m *ice.Message, arg ...string) {}