This commit is contained in:
jingganjiaoyu 2024-08-03 09:20:09 +08:00
parent 921f638b8d
commit e4e1a032ba
11 changed files with 136 additions and 39 deletions

View File

@ -7,10 +7,7 @@ import (
"shylinux.com/x/education/src/jiaowuxitong/model" "shylinux.com/x/education/src/jiaowuxitong/model"
) )
type Class struct { type Class struct { Table }
Table
school school
}
func (s Class) Inputs(m *ice.Message, arg ...string) { func (s Class) Inputs(m *ice.Message, arg ...string) {
switch arg[0] { switch arg[0] {
@ -32,3 +29,29 @@ func (s Class) Inputs(m *ice.Message, arg ...string) {
} }
func init() { ice.TeamCtxCmd(Class{}) } func init() { ice.TeamCtxCmd(Class{}) }
type ClassType int
const (
ClassHouse ClassType = iota
ClassHotel
ClassStore
ClassPublic
ClassSchool
ClassOffice
ClassFactory
ClassHospital
)
var ClassTypeList = map[ClassType]string{
ClassHouse: "house",
ClassHotel: "hotel",
ClassStore: "store",
ClassPublic: "public",
ClassSchool: "school",
ClassOffice: "office",
ClassFactory: "factory",
ClassHospital: "hospital",
}
func (s ClassType) String() string { return ClassTypeList[s] }

View File

@ -5,6 +5,7 @@ import (
"shylinux.com/x/icebergs/base/web" "shylinux.com/x/icebergs/base/web"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
"shylinux.com/x/education/src/jiaowuxitong/model"
"shylinux.com/x/mysql-story/src/db" "shylinux.com/x/mysql-story/src/db"
) )
@ -20,3 +21,13 @@ func (s Table) Init(m *ice.Message, arg ...string) {
func (s Table) Inputs(m *ice.Message, arg ...string) { func (s Table) Inputs(m *ice.Message, arg ...string) {
s.Table.Inputs(m, arg...) s.Table.Inputs(m, arg...)
} }
func (s Table) List(m *ice.Message, arg ...string) *ice.Message {
if len(arg) == 0 || len(arg) == 1 {
if m.IsTech() {
s.Table.List(m)
}
} else if len(arg) == 2 {
s.Table.Select(m.FieldsSetDetail(), model.UID, arg[1])
}
return m
}

View File

@ -10,7 +10,6 @@ import (
type homework struct { type homework struct {
Table Table
Class Class
user gonganxitong.User user gonganxitong.User
portal string `data:"true"` portal string `data:"true"`
create string `name:"create content*" role:"void"` create string `name:"create content*" role:"void"`

View File

@ -5,6 +5,8 @@ import "shylinux.com/x/mysql-story/src/db"
const ( const (
UID = "uid" UID = "uid"
NAME = "name" NAME = "name"
TYPE = "type"
ROLE = "role"
GRADE = "grade" GRADE = "grade"
CREATED_AT = "created_at" CREATED_AT = "created_at"
USER_UID = "user_uid" USER_UID = "user_uid"
@ -12,12 +14,13 @@ const (
CLASS_NAME = "class_name" CLASS_NAME = "class_name"
SCHOOL_UID = "school_uid" SCHOOL_UID = "school_uid"
SCHOOL_NAME = "school_name" SCHOOL_NAME = "school_name"
CITY_NAME = "city_name"
) )
type UserClass struct { type UserClass struct {
db.Model db.Model
UserUID string `gorm:"type:char(32);index"` UserUID string `gorm:"type:char(32);index"`
ClassUID string `gorm:"type:char(32)";index` ClassUID string `gorm:"type:char(32);index"`
} }
type Class struct { type Class struct {
db.ModelWithUID db.ModelWithUID
@ -28,7 +31,7 @@ type Class struct {
type School struct { type School struct {
db.ModelWithUID db.ModelWithUID
CityUID string `gorm:"type:char(32);index"` CityUID string `gorm:"type:char(32);index"`
Name string `gorm:"type:varchar(256)"` Name string `gorm:"type:varchar(256);index"`
Info string Info string
} }
type Homework struct { type Homework struct {

View File

@ -4,6 +4,7 @@ import (
"shylinux.com/x/ice" "shylinux.com/x/ice"
"shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/web"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
"shylinux.com/x/community/src/gonganxitong" "shylinux.com/x/community/src/gonganxitong"
@ -17,7 +18,6 @@ type portal struct {
userClass userClass userClass userClass
class Class class Class
school school school school
inputs string `name:"inputs" role:"void"`
list string `name:"list class_uid index uid auto" role:"void"` list string `name:"list class_uid index uid auto" role:"void"`
classCreate string `name:"classCreate city_name* school_name* grade*:select name*" role:"void"` classCreate string `name:"classCreate city_name* school_name* grade*:select name*" role:"void"`
classRemove string `name:"classRemove class_uid*" role:"void"` classRemove string `name:"classRemove class_uid*" role:"void"`
@ -32,8 +32,10 @@ func (s portal) List(m *ice.Message, arg ...string) {
return return
} }
if len(arg) == 0 { if len(arg) == 0 {
m.Cmdy(s.userClass, m.Option(model.USER_UID)).PushAction(s.ClassRemove).Action(s.ClassCreate) m.Cmdy(s.userClass, m.Option(model.USER_UID)).PushAction(s.ClassRemove).Action(s.ClassCreate, s.ScanQRCode)
kit.If(!m.IsErr() && m.Length() == 0, func() { m.EchoInfoButton(m.Trans("Please Create Your Class", "请创建班级"), s.ClassCreate) }) kit.If(!m.IsErr() && m.Length() == 0, func() {
m.EchoInfoButton(m.Trans("Please Create Your Class", "请创建班级"), s.ClassCreate, s.ScanQRCode)
})
} else if len(arg) == 2 { } else if len(arg) == 2 {
msg := m.Cmd(s.class, s.class.Select, model.UID, arg[0]) msg := m.Cmd(s.class, s.class.Select, model.UID, arg[0])
m.Option(model.CLASS_NAME, msg.Append(model.NAME)) m.Option(model.CLASS_NAME, msg.Append(model.NAME))
@ -51,21 +53,36 @@ func (s portal) ClassCreate(m *ice.Message, arg ...string) {
if s.school.FindOrCreateByName(m, arg...); m.IsErr() { if s.school.FindOrCreateByName(m, arg...); m.IsErr() {
return return
} }
if !m.Cmdy(s.class, s.class.Create, arg[2:]).IsErr() { if m.Cmdy(s.class, s.class.Create, arg[2:]).IsErr() {
args := kit.Simple(model.USER_UID, m.Option(model.USER_UID), model.CLASS_UID, m.Result()) return
m.Cmdy(s.userClass, s.userClass.Create, args)
m.ProcessRefresh()
} }
args := kit.Simple(m.OptionSimple(model.USER_UID), model.CLASS_UID, m.Result())
m.Cmdy(s.userClass, s.userClass.Create, args).ProcessRefresh()
} }
func (s portal) ClassRemove(m *ice.Message, arg ...string) { func (s portal) ClassRemove(m *ice.Message, arg ...string) {
defer m.ToastProcess()() defer m.ToastProcess()()
args := m.OptionSimple(model.USER_UID, model.CLASS_UID) args := m.OptionSimple(model.USER_UID, model.CLASS_UID)
msg := m.Cmd(s.userClass, s.userClass.Select, args) msg := m.Cmd(s.userClass, s.userClass.Select, args)
if !m.WarnNotFound(msg.Length() == 0, "class") { if m.WarnNotFound(msg.Length() == 0, "class") {
m.Cmdy(s.userClass, s.userClass.Delete, args) return
}
m.Cmdy(s.userClass, s.userClass.Delete, msg.AppendSimple(model.UID))
m.Cmdy(s.class, s.class.Delete, model.UID, m.Option(model.CLASS_UID)) m.Cmdy(s.class, s.class.Delete, model.UID, m.Option(model.CLASS_UID))
m.ProcessRefresh() m.ProcessRefresh()
} }
func (s portal) ScanQRCode(m *ice.Message, arg ...string) {
defer m.ToastProcess()()
if m.Option(mdb.TYPE) == mdb.TEXT {
args := kit.Simple(m.OptionSimple(model.USER_UID), model.CLASS_UID, m.Option(mdb.TEXT))
m.Cmdy(s.userClass, s.userClass.Create, args, model.ROLE, UserClassVisitor)
}
if m.Option(mdb.TYPE) == web.LINK {
args := m.ParseURL(m.Option(mdb.TEXT))
if len(args) > 1 && args[1] == m.Prefix("apply") {
args := kit.Simple(m.OptionSimple(model.USER_UID), model.CLASS_UID, args[0])
m.Cmdy(s.userClass, s.userClass.Create, args, model.ROLE, UserClassVisitor)
}
}
} }
func init() { ice.TeamCtxCmd(portal{}) } func init() { ice.TeamCtxCmd(portal{}) }

View File

@ -1,13 +1,14 @@
{ {
"user": "用户", "portal": "教务系统",
"class": "班级", "scanQRCode": "扫码添加",
"school": "学校",
"homework": "家庭作业",
"classCreate": "创建班级", "classCreate": "创建班级",
"classRemove": "删除班级", "classRemove": "删除班级",
"portal": "教务系统", "qrcode": "班级码",
"homework": "家庭作业",
"icons": { "icons": {
"classCreate": "bi bi-plus-square-dotted" "scanQRCode": "bi bi-qr-code-scan",
"classCreate": "bi bi-plus-square-dotted",
"qrcode": "https://img.icons8.com/officel/80/qr-code.png"
}, },
"style": { "style": {
"classRemove": "danger" "classRemove": "danger"

View File

@ -0,0 +1,26 @@
package jiaowuxitong
import (
"shylinux.com/x/ice"
kit "shylinux.com/x/toolkits"
"shylinux.com/x/education/src/jiaowuxitong/model"
)
type qrcode struct {
portal portal
userClass userClass
list string `name:"list place_uid auto" role:"void"`
}
func (s qrcode) Init(m *ice.Message, arg ...string) {
s.portal.Show(m)
}
func (s qrcode) List(m *ice.Message, arg ...string) {
msg := m.Cmd(s.userClass, m.Option(model.USER_UID), arg[0])
m.FieldsSetDetail()
kit.For([]string{model.CITY_NAME, model.SCHOOL_NAME, model.CLASS_NAME}, func(key string) { m.Push(key, msg.Append(key)) })
m.EchoQRCode(s.portal.Link(m, arg[0], m.Prefix("apply")))
}
func init() { ice.TeamCtxCmd(qrcode{}) }

View File

@ -6,12 +6,7 @@ import (
"shylinux.com/x/education/src/jiaowuxitong/model" "shylinux.com/x/education/src/jiaowuxitong/model"
) )
type school struct { type school struct{ Table }
Table
create string `name:"create city_uid* name info"`
}
func init() { ice.TeamCtxCmd(school{}) }
func (s school) FindOrCreateByName(m *ice.Message, arg ...string) { func (s school) FindOrCreateByName(m *ice.Message, arg ...string) {
if msg := m.Cmd(s, s.Select, model.NAME, arg[3], arg[0], arg[1]); msg.Length() == 0 { if msg := m.Cmd(s, s.Select, model.NAME, arg[3], arg[0], arg[1]); msg.Length() == 0 {
@ -21,3 +16,5 @@ func (s school) FindOrCreateByName(m *ice.Message, arg ...string) {
arg[2], arg[3] = model.SCHOOL_UID, msg.Append(model.UID) arg[2], arg[3] = model.SCHOOL_UID, msg.Append(model.UID)
} }
} }
func init() { ice.TeamCtxCmd(school{}) }

View File

@ -8,14 +8,34 @@ import (
type userClass struct { type userClass struct {
Table Table
Class Class class Class
school school school school
create string `name:"create user_uid* class_uid*"`
} }
func (s userClass) List(m *ice.Message, arg ...string) { func (s userClass) List(m *ice.Message, arg ...string) {
s.Tables(m, s.Class, s.school).Fields(m, s.Key(s.Class, model.CREATED_AT), model.SCHOOL_NAME, model.GRADE, model.CLASS_NAME, model.CLASS_UID, model.SCHOOL_UID) s.Tables(m, s.class, s.school).Fields(m,
s.Select(m, model.USER_UID, arg[0]) s.Key(s.class, model.CREATED_AT), model.SCHOOL_NAME, model.GRADE, model.CLASS_NAME, model.CLASS_UID, model.SCHOOL_UID,
).Orders(m, s.Desc(model.CREATED_AT)).Select(m, model.USER_UID, arg[0])
} }
func init() { ice.TeamCtxCmd(userClass{}) } func init() { ice.TeamCtxCmd(userClass{}) }
type UserClassRole int
const (
UserClassCreator UserClassRole = iota
UserClassTeacher
UserClassStudent
UserClassParent
UserClassVisitor
)
var UserClassRoleList = map[UserClassRole]string{
UserClassCreator: "creator",
UserClassTeacher: "teacher",
UserClassStudent: "student",
UserClassParent: "parent",
UserClassVisitor: "visitor",
}
func (s UserClassRole) String() string { return UserClassRoleList[s] }

View File

@ -10,4 +10,4 @@ func (s {{.Option "name"}}) List(m *ice.Message, arg ...string) {
s.Table.List(m, arg...) s.Table.List(m, arg...)
} }
func init() { ice.Cmd(prefixKey(), {{.Option "name"}}{}) } func init() { ice.TeamCtxCmd({{.Option "name"}}{}) }