2024-09-14 00:36:22 +08:00

77 lines
2.7 KiB
Go

package renzhengshouquan
import (
"shylinux.com/x/ice"
"shylinux.com/x/icebergs/base/aaa"
kit "shylinux.com/x/toolkits"
"shylinux.com/x/community/src/gonganxitong"
"shylinux.com/x/community/src/renzhengshouquan/model"
"shylinux.com/x/enterprise/src/guanlixitong"
)
type Portal struct {
guanlixitong.Portal
placeCreate string `name:"placeCreate city_name* company_name* auth_name* auth_type*:select" role:"void"`
}
func (s Portal) List(m *ice.Message, arg ...string) {
s.Portal.List(m, arg...)
kit.If(len(arg) == 0 && m.Length() > 0, func() { m.PushAction(s.PlaceRemove) })
}
func (s Portal) PlaceCreate(m *ice.Message, arg ...string) {
if m.Option(model.AUTH_TYPE) == ice.AUTO {
arg = append(arg, model.AUTH_TYPE, m.Option(model.AUTH_TYPE, AuthService))
}
from := ""
switch AuthType(kit.Int(m.Option(model.AUTH_TYPE))) {
case AuthRoot:
from = aaa.ROOT
case AuthCity:
from = s.findAuthFrom(m, AuthRoot)
case AuthCompany, AuthPersonal:
from = s.findAuthFrom(m, AuthCity, model.NAME, m.Option(model.CITY_NAME))
case AuthService:
if city_uid := s.findAuthFrom(m, AuthCity, model.NAME, m.Option(model.CITY_NAME)); city_uid != "" {
from = s.findAuthFrom(m, AuthCompany, model.NAME, m.Option(model.COMPANY_NAME), model.FROM_UID, city_uid)
}
}
if from == "" {
return
}
arg = append(arg, model.FROM_UID, m.Option(model.FROM_UID, from))
if m.WarnNotRight(AuthType(kit.Int(m.Option(model.AUTH_TYPE))) == AuthRoot && !m.IsTech()) {
return
}
if AuthType(kit.Int(m.Option(model.AUTH_TYPE))) == AuthRoot && m.IsTech() {
arg = append(arg, model.STATUS, kit.Format(AuthIssued))
}
s.Portal.PlaceCreate(m, arg...)
}
func (s Portal) PlaceList(m *ice.Message, arg ...string) *ice.Message {
s.Tables(m, "left join auths on user_auths.auth_uid = auths.uid").FieldsWithCreatedAT(m, s.UserPlace,
s.Keys(s.Place, model.NAME), s.Keys(s.Place, model.TYPE), s.Keys(s.Place, model.STATUS), s.Keys(s.UserPlace, model.ROLE),
s.AS(s.Key(s.Place, model.UID), s.Keys(s.Place, model.UID)), s.Keys(s.Street, model.UID),
)
if len(arg) == 1 {
m.Cmdy(s.UserPlace, s.Table.Select, model.USER_UID, arg[0])
} else if len(arg) == 2 {
m.FieldsSetDetail().Cmdy(s.UserPlace, s.Table.Select, model.USER_UID, arg[0], s.Key(s.UserPlace, s.Keys(s.Place, model.UID)), arg[1])
} else {
return m
}
s.SelectJoin(m, s.Street, model.NAME, model.CITY_UID)
s.SelectJoinCity(m)
return m
}
func init() { gonganxitong.PortalCmd(Portal{Portal: guanlixitong.NewPortal(userAuth{}, auth{})}) }
func (s Portal) findAuthFrom(m *ice.Message, authType AuthType, arg ...string) string {
msg := m.Cmd(auth{}, s.Table.Select, model.TYPE, authType, arg)
if m.WarnNotFound(msg.Length() == 0, authType.String()) {
return ""
}
return msg.Append(model.UID)
}