model

package
v0.0.0-...-b3ea26e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReserveReviewPending = 0
	ReserveReviewSuccess = 1
)

Variables

View Source
var (
	ErrChan     = make(chan error, 1)
	PingChan    = make(chan error, 1)
	SuccessChan = make(chan bool, 1)
)

Functions

func AddOpen

func AddOpen(record ReserveRecord) map[string]interface{}

SubmitOpenJob 向neu提交开放预约申请,有可能会失败,故使用Chan作为为队列 2019.08.31 废弃队列,改为事物,只提交一次,提交失败 就是失败

func AddWhiteList

func AddWhiteList(uid uint64) error

func DeleteOpen

func DeleteOpen(uid string, openid int) map[string]interface{}

func GetReserveCount

func GetReserveCount(status int) int

GetReserveCount return count of reserves

func GetUserCount

func GetUserCount() int

func InitSelfDB

func InitSelfDB() *gorm.DB

InitSelfDB used for cli

func IsExistsReserveRecord

func IsExistsReserveRecord(uid string, lid, day, time string) bool

func IsWhiteList

func IsWhiteList(id uint64) bool

func Migrations

func Migrations(v ...interface{})

Migrations auto migrate struct

func RemoveWhiteList

func RemoveWhiteList(uid uint64) error

func UpdateOpen

func UpdateOpen(record ReserveRecord) map[string]interface{}

Types

type BaseModel

type BaseModel struct {
	Id        uint64     `gorm:"primary_key;AUTO_INCREMENT;column:id" json:"-"`
	CreatedAt time.Time  `gorm:"column:createdAt" json:"-"`
	UpdatedAt time.Time  `gorm:"column:updatedAt" json:"-"`
	DeletedAt *time.Time `gorm:"column:deletedAt" sql:"index" json:"-"`
}

type Database

type Database struct {
	Self *gorm.DB
}

Database [TODO] many db

var DB *Database

DB instance

func (*Database) Close

func (db *Database) Close()

Close db

func (*Database) Drop

func (db *Database) Drop()

Drop drop all db

func (*Database) Init

func (db *Database) Init()

Init init database

func (*Database) Ping

func (db *Database) Ping()

type Lab

type Lab struct {
	CreatedAt    time.Time  `gorm:"column:createdAt" json:"-"`
	DeletedAt    *time.Time `gorm:"column:deletedAt" sql:"index" json:"-"`
	LabID        string     `gorm:"primary_key;unique_index" uri:"labid" json:"lab_id"`
	LabName      string     `json:"lab_name"`
	SeatNum      int        `json:"seat_num"`
	LabTypeID    int        `json:"lab_type_id"`
	S            int        `json:"s"`
	Detail       *LabDetail `json:"detail"`
	Userid       string     `json:"userid"`
	UserName     string     `json:"user_name"`
	Tel          string     `json:"tel"`
	DeviceNumber string     `json:"device_number"`
}

Lab S mean lock

func GetLab

func GetLab(id string) (*Lab, error)

GetLab GetLab

func GetLabWithDoorId

func GetLabWithDoorId(deviceNumber string) (Lab, error)

func GetLabsWithType

func GetLabsWithType(id int) ([]Lab, error)

GetLabsWithType GetLabsWithType

func (*Lab) Create

func (lab *Lab) Create() error

Create lab Create and create detail

func (*Lab) Delete

func (lab *Lab) Delete() error

Delete lab

func (*Lab) GetLabDetail

func (lab *Lab) GetLabDetail() error

GetLabDetail GetLabDetail

func (*Lab) Save

func (lab *Lab) Save() error

Save lab

type LabClass

type LabClass struct {
	Id      uint64 `gorm:"primary_key;AUTO_INCREMENT;column:id" json:"-"`
	LabID   string
	Lab     Lab
	Class   string
	Day     string `gorm:"type:char(10)"`
	Time    string `gorm:"type:char(1)"`
	Teacher string
	Other   string
}

LabClass 归类于独占教室的目的,当有记录,此实验室这个时间段内不在开放预约

func (*LabClass) Save

func (class *LabClass) Save() error

Save LabClass

type LabDetail

type LabDetail struct {
	LabID        string   `gorm:"primary_key;unique_index" uri:"labid" json:"-"`
	Context      string   `gorm:"type:text" json:"context"`
	ImagesString string   `gorm:"type:text" json:"-"`
	Images       []string `gorm:"-" json:"images"`
	Info         string   `json:"info"`
}

func (*LabDetail) DeleteImage

func (ld *LabDetail) DeleteImage(path string) error

func (*LabDetail) GetNextImageFileName

func (ld *LabDetail) GetNextImageFileName() string

func (*LabDetail) InsertImage

func (ld *LabDetail) InsertImage(path string) error

func (*LabDetail) Save

func (ld *LabDetail) Save() error

type LabType

type LabType struct {
	Id   int    `gorm:"primary_key;AUTO_INCREMENT;column:id" json:"id"`
	Name string `gorm:"type:varchar(30);unique_index" json:"name"`
}

func GetAllLabType

func GetAllLabType() ([]LabType, error)

GetAllLabType GetAllLabType

func GetOneLabType

func GetOneLabType(id int) (*LabType, error)

func (*LabType) Create

func (lt *LabType) Create() error

Create LabType create

type ReserveInfo

type ReserveInfo struct {
	Day  string
	Time string
	S    int
}

func GetLabClassInfo

func GetLabClassInfo(labid, day string) ([]ReserveInfo, error)

GetLabClassInfo 返回某月某实验室的所有课程

func GetLabUserNumInfo

func GetLabUserNumInfo(labid, day string) ([]ReserveInfo, error)

GetLabUserNumInfo 返回某月某实验室的所有预约座位数

func GetLabUserReserveInfo

func GetLabUserReserveInfo(uid string, labid, day string) ([]ReserveInfo, error)

GetLabUserReserveInfo 返回某月某实验室某用户的所有的预约情况

type ReserveRecord

type ReserveRecord struct {
	Id           uint64     `gorm:"primary_key;AUTO_INCREMENT;column:id" json:"id"`
	CreatedAt    time.Time  `gorm:"column:createdAt" json:"created_at"`
	UpdatedAt    time.Time  `gorm:"column:updatedAt" json:"updated_at"`
	DeletedAt    *time.Time `gorm:"column:deletedAt" sql:"index" json:"-"`
	Uid          string     `gorm:"index" json:"uid"` // 2019-07-03 改为用户的userid
	LabID        string     `json:"lab_id"`
	Status       int        `gorm:"index;default:0" json:"status"`
	Content      string     `gorm:"type:varchar(100)" json:"content" binding:"exists"`      // 项目名称
	Explain      string     `gorm:"type:varchar(100)" json:"explain" binding:"exists"`      // 项目说明
	OpentypeID   string     `json:"opentype_id" binding:"required"`                         // 项目类型
	UserNum      int        `json:"user_num" binding:"required"`                            // 人数
	GuideTeacher string     `gorm:"type:varchar(20)" json:"guide_teacher" binding:"exists"` // 指导教师
	Remarks      string     `gorm:"type:varchar(255)" json:"remarks" binding:"exists"`      // 备注
	Expend       int        `json:"expend" binding:"exists"`                                // 是否需要消耗品
	Mobile       string     `gorm:"type:varchar(11)" json:"mobile" binding:"required"`      // 手机

	OpenId int    `gorm:"column:openid" json:"openid"` // neu返回的openid
	Note   string `json:"note"`                        // neu 预约失败返回的字段

	Details []ReserveRecordDetail `json:"-"`
	Lab     *Lab                  `gorm:"-" json:"lab_info"`
	Records map[string][]int      `gorm:"-" json:"records" binding:"required"`
}

ReserveRecord : status : 0 pending review

1 success review
3 failed  review

OpentypeID: 1 大创/竞赛项目 2 毕业设计项目 3 课程实验项目 4 教师科研项目 5 其他 TODO

func GetReserveRecord

func GetReserveRecord(id uint64) (*ReserveRecord, error)

GetReserveRecord GetReserveRecord

func GetReserveRecordWithOpenId

func GetReserveRecordWithOpenId(openid int) (*ReserveRecord, error)

GetReserveRecord GetReserveRecord

func GetReserveWithStatus

func GetReserveWithStatus(status, pageNum, pageLimit int) ([]*ReserveRecord, error)

GetReserveWithStatus GetReserveWithStatus

func GetUserReserve

func GetUserReserve(uid string, pageNum, pageLimit int, params ...interface{}) ([]*ReserveRecord, error)

func (*ReserveRecord) Create

func (oo *ReserveRecord) Create() error

Create ReserveRecord Create

func (*ReserveRecord) Delete

func (oo *ReserveRecord) Delete(syncNeu bool) error

Delete will soft delete record and real delete detail

func (*ReserveRecord) DeleteDetail

func (oo *ReserveRecord) DeleteDetail() error

DeleteDetail deleteDetail

func (*ReserveRecord) Detail2Records

func (oo *ReserveRecord) Detail2Records()

Detail2Records convert detail to records

func (*ReserveRecord) GetDetail

func (oo *ReserveRecord) GetDetail() []ReserveRecordDetail

GetDetail GetDetail

func (*ReserveRecord) GetLab

func (oo *ReserveRecord) GetLab()

DeleteDetail deleteDetail

func (*ReserveRecord) Records2Detail

func (oo *ReserveRecord) Records2Detail()

Records2Detail convert records to detail

func (*ReserveRecord) Review

func (oo *ReserveRecord) Review(status int) error

Review the status code only support switch 0 -> 1 or 0 -> -1 or 1 > 0 or 1 > -1

func (*ReserveRecord) SaveNoSafe

func (oo *ReserveRecord) SaveNoSafe(syncNeu bool) error

SaveNoSafe This method will delete all the original reserve info. Replace new apply info

type ReserveRecordDetail

type ReserveRecordDetail struct {
	Id              uint64 `gorm:"primary_key;AUTO_INCREMENT;column:id" json:"-"`
	ReserveRecordID uint64 `gorm:"index" json:"-"`
	Day             string `gorm:"type:char(10)"`
	Time            string `gorm:"type:char(1)"`
	Uid             string `json:"-"` // 2019-07-03 改为用户的userid
	Lid             string `json:"-"`
	Effective       int    `gorm:"index" json:"-"`
	UserNum         int    `json:"-"`
}

ReserveRecordDetail : `effective` is a special field, if its value is 1 means ReserveRecord success review, all sql statement where include `where effective = 1`. 在审核中或者审核成功时不能出现同一个时间同一实验室的预约记录, 审核不通过时可以出现 已有20190501 1 1 1 0/1,则 20190501 1 1 1 x x为任何值都不被允许

type Token

type Token struct {
	Token string `json:"token"`
}

Token represents a JSON web token.

type User

type User struct {
	Id        uint64     `gorm:"primary_key;AUTO_INCREMENT;column:id" json:"id"`
	CreatedAt time.Time  `gorm:"column:createdAt" json:"created_at"`
	UpdatedAt time.Time  `gorm:"column:updatedAt" json:"updated_at"`
	DeletedAt *time.Time `gorm:"column:deletedAt" sql:"index" json:"-"`
	Openid    string     `gorm:"unique_index" json:"openid"`
	Role      uint       `json:"role"`
	Un        string     `json:"-"`
	Pa        string     `json:"-"`

	Info *UserInfo `gorm:"-" json:"info"`
}

func CheckPass

func CheckPass(username, password string) (*User, error)

func GetAllUser

func GetAllUser(pageNum, pageLimit int) ([]*User, error)

func GetUser

func GetUser(openid string) (*User, error)

func GetUserWithId

func GetUserWithId(id uint64) (*User, error)

func (*User) Create

func (u *User) Create() error

func (*User) Delete

func (u *User) Delete() error

func (*User) GetStuInfo

func (u *User) GetStuInfo()

func (*User) Save

func (u *User) Save() error

func (*User) Update

func (u *User) Update() error

type UserInfo

type UserInfo struct {
	UserId         string `gorm:"primary_key" json:"user_id"`
	UserPass       string `gorm:"default:123456" json:"-"`
	UserName       string `json:"user_name"`
	UserDepartment string `json:"user_department"`
	Consuserid     string `json:"-"`
	UserRole       string `json:"user_role"`
	Uid            uint64 `gorm:"index" json:"uid"`
}

func CheckPassStu

func CheckPassStu(userid, userpwd string) (*UserInfo, bool)

func CheckPassStuV2

func CheckPassStuV2(userid, userpwd string) (*UserInfo, bool)

func GetAllStuInfo

func GetAllStuInfo(pageNum, pageLimit int) []*UserInfo

func GetAllUserInfo

func GetAllUserInfo() []*UserInfo

func (*UserInfo) Create

func (s *UserInfo) Create() error

func (*UserInfo) Delete

func (s *UserInfo) Delete() error

func (*UserInfo) Save

func (s *UserInfo) Save() error

type WhiteList

type WhiteList struct {
	Id        uint64    `gorm:"primary_key;AUTO_INCREMENT;column:id" json:"id"`
	CreatedAt time.Time `gorm:"column:createdAt" json:"created_at"`
	Uid       uint64    `gorm:"index" json:"uid"`
}

func GetAllWhiteList

func GetAllWhiteList() []*WhiteList

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL