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"
)
type Class struct {
Table
school school
}
type Class struct { Table }
func (s Class) Inputs(m *ice.Message, arg ...string) {
switch arg[0] {
@ -32,3 +29,29 @@ func (s Class) Inputs(m *ice.Message, arg ...string) {
}
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"
kit "shylinux.com/x/toolkits"
"shylinux.com/x/education/src/jiaowuxitong/model"
"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) {
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 {
Table
Class Class
user gonganxitong.User
portal string `data:"true"`
create string `name:"create content*" role:"void"`

View File

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

View File

@ -4,6 +4,7 @@ import (
"shylinux.com/x/ice"
"shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/web"
kit "shylinux.com/x/toolkits"
"shylinux.com/x/community/src/gonganxitong"
@ -17,7 +18,6 @@ type portal struct {
userClass userClass
class Class
school school
inputs string `name:"inputs" 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"`
classRemove string `name:"classRemove class_uid*" role:"void"`
@ -32,8 +32,10 @@ func (s portal) List(m *ice.Message, arg ...string) {
return
}
if len(arg) == 0 {
m.Cmdy(s.userClass, m.Option(model.USER_UID)).PushAction(s.ClassRemove).Action(s.ClassCreate)
kit.If(!m.IsErr() && m.Length() == 0, func() { m.EchoInfoButton(m.Trans("Please Create Your Class", "请创建班级"), 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, s.ScanQRCode)
})
} else if len(arg) == 2 {
msg := m.Cmd(s.class, s.class.Select, model.UID, arg[0])
m.Option(model.CLASS_NAME, msg.Append(model.NAME))
@ -51,20 +53,35 @@ func (s portal) ClassCreate(m *ice.Message, arg ...string) {
if s.school.FindOrCreateByName(m, arg...); m.IsErr() {
return
}
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())
m.Cmdy(s.userClass, s.userClass.Create, args)
m.ProcessRefresh()
if m.Cmdy(s.class, s.class.Create, arg[2:]).IsErr() {
return
}
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) {
defer m.ToastProcess()()
args := m.OptionSimple(model.USER_UID, model.CLASS_UID)
msg := m.Cmd(s.userClass, s.userClass.Select, args)
if !m.WarnNotFound(msg.Length() == 0, "class") {
m.Cmdy(s.userClass, s.userClass.Delete, args)
m.Cmdy(s.class, s.class.Delete, model.UID, m.Option(model.CLASS_UID))
m.ProcessRefresh()
if m.WarnNotFound(msg.Length() == 0, "class") {
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.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)
}
}
}

View File

@ -1,13 +1,14 @@
{
"user": "用户",
"class": "班级",
"school": "学校",
"homework": "家庭作业",
"portal": "教务系统",
"scanQRCode": "扫码添加",
"classCreate": "创建班级",
"classRemove": "删除班级",
"portal": "教务系统",
"qrcode": "班级码",
"homework": "家庭作业",
"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": {
"classRemove": "danger"
@ -26,7 +27,7 @@
"city_name": "城市名称"
},
"value": {
}
}
}

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"
)
type school struct {
Table
create string `name:"create city_uid* name info"`
}
func init() { ice.TeamCtxCmd(school{}) }
type school struct{ Table }
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 {
@ -21,3 +16,5 @@ func (s school) FindOrCreateByName(m *ice.Message, arg ...string) {
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 {
Table
Class Class
class Class
school school
create string `name:"create user_uid* class_uid*"`
}
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.Select(m, model.USER_UID, arg[0])
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,
).Orders(m, s.Desc(model.CREATED_AT)).Select(m, model.USER_UID, arg[0])
}
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

@ -8,4 +8,4 @@ import (
func main() { print(ice.Run()) }
func init() { ice.Info.Titles = "云教育" }
func init() { ice.Info.Titles = "云教育" }

View File

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