package entity import ( "context" "github.com/gogf/gf/os/glog" ) type Role int // 枚举值作为结构体字段 const ( R_Guest Role = iota R_Student R_Teacher R_Manager R_Customr R_Admin ) // type User interface { StatisticsInfo() PushMessage(ctx context.Context,msg Msg) } var g_userMgr *UserManager type UserObject struct { UID int64 `json:"uid"` Username string `json:"uname"` Password string `json:"password"` Email string `json:"email"` UserType string `json:"userType"` SexOrType string `json:"sexOrType"` Department string `json:"department"` Telephone string `json:"telephone"` Cookie string `json:"cookie"` } func NewUser() UserObject{ return UserObject{} } func NewUserObject() *UserObject { return &UserObject{} } type Student struct { UserObject school string `json:"school"` classGrade string `json:"classGrade"` studentNum string `json:"studentNum"` courses []Course `json:"courses"` department string `json:"department"` } type Teacher struct { UserObject school string `json:"school"` courses []Course `json:"courses"` department string `json:"department"` } /*manager as a part*/ type Manager struct { parts []User } type Admin struct { UserObject } type CutomrService struct { UserObject } func (this *Student) StatisticsInfo() { } func (this *Student) PushMessage(ctx context.Context,msg Msg) { UserMgr().PushMessage(ctx,this,msg) } func (this *Teacher) PushMessage(ctx context.Context,msg Msg) { UserMgr().PushMessage(ctx,this,msg) } func (this *Teacher) pushByOffcialAccounts(ctx context.Context,args ...interface{}) { if len(args) != 1 { glog.Debug("Error: Expected exactly one argument") return } msg, ok := args[0].(Msg) if !ok { glog.Error("Error: Expected Message type argument") } w := NewWeChatOfficial("default") err := w.PushMessage(ctx,msg) if err != nil { return } /* */ } /*@func *push message to short note */ func (this *Teacher) pushByShortNote(args ...interface{}) { } func (this *Teacher) pushByPlatform(args ...interface{}) { } func (this *Teacher) courseStatistics(course *Course) { } func (this *Teacher) StatisticsInfo() { } func (this *Teacher) pushEveryOneByOfficial(){ } func (this *Manager) PushByOfficialAccounts() { } func (this *Manager) PushByShortNote() { } func (this *Manager) AddCourse() { } func (this *Manager) DepartmentStatistics() { } func (this *Manager) StatisticsInfo() { } func (this *Manager) PushMessage(ctx context.Context,msg Msg) { UserMgr().PushMessage(ctx ,this,msg) } func (this *Admin) SalesStatics() { } func (this *Admin) CreateAccount() (UserObject, error) { return UserObject{}, nil } func (this *Admin) GetAccount() { } func (this *Admin) ChangeAccount() { } func (this *Admin) DeleteAccount() { } func (this *Admin) GetAccountsByBelongOf() { } func (this *Admin) GetAccountsByCourse() { } func (this *Admin) StatisticsInfo() { } func (this *Admin) PushMessage(ctx context.Context,msg Msg) { UserMgr().PushMessage(ctx,this,msg) } func (this *CutomrService) StatisticsInfo(){ } func (this *CutomrService) SalesStatics() { } func (this *CutomrService) PushMessage(ctx context.Context,msg Msg) { UserMgr().PushMessage(ctx,this,msg) } func (this *CutomrService) OrderQuery() { } type UserManager struct { userRequestQueue *scheduleRunner } func (this *UserManager) PushMessage(ctx context.Context,user User,req Msg) { glog.Debug("push message") req.Do(ctx) } func (this *UserManager) QueryAccountsByDepartment(dept string) { } func (this *UserManager) QueryAccountsById(id string) { } /* delete */ func Run(fun func(...interface{}), args ...interface{}) { sf := ScheduleFunc{ Fn: fun, Args: args, } UserMgr().userRequestQueue.Run(sf) } /* delete */ func UserMgr() *UserManager { if g_userMgr == nil { g_userMgr = &UserManager{ userRequestQueue: Runner(), } } return g_userMgr }