123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- package dao
- import (
- "time"
- )
- type User struct {
- ID int `gorm:"primary_key;type:int" json:"id"`
- TenantId string `gorm:"type:varchar(12)" json:"tenantId"`
- Code string `gorm:"type:varchar(12)" json:"code"`
- Account string `gorm:"type:varchar(45)" json:"account"`
- Password string `gorm:"type:varchar(45)" json:"password"`
- Name string `gorm:"type:varchar(20)" json:"name"`
- RealName string `gorm:"type:varchar(12)" json:"realName"`
- Avatar string `gorm:"type:varchar(500)" json:"avatar"`
- Email string `gorm:"type:varchar(45)" json:"email"`
- Phone string `gorm:"type:varchar(45)" json:"phone"`
- Birthday string `gorm:"type:string" json:"birthday"`
- Sex int `gorm:"type:smallint" json:"sex"`
- RoleId int `gorm:"type:bigint" json:"roleId"`
- CreateUser int `gorm:"type:int" json:"createUser"`
- CreateDept int `gorm:"type:int" json:"createDept"`
- CreateTime time.Time `gorm:"autoCreateTime;column:create_time;type:datetime;" json:"createTime"`
- UpdateUser int `gorm:"type:int" json:"updateUser"`
- UpdateTime time.Time `gorm:"autoUpdateTime;column:update_time;type:datetime;" json:"updateTime"`
- Status int `gorm:"type:int " json:"status"`
- IsDeleted int `gorm:"type:int" json:"isDeleted"`
- GroupId int `gorm:"type:int" json:"groupId"`
- BigScreenIndexCameraIds string `gorm:"type:varchar(255)" json:"bigScreenIndexCameraIds"`
- SecuritySixScreen string `gorm:"type:varchar(255)" json:"securitySixScreen"`
- }
- type JsonInt64 int64
- func (ji *JsonInt64) UnmarshalJSON() {
- }
- func (*User) TableName() string {
- return "user"
- }
- func (c *User) GetUser() error {
- return Db.Model(&c).Where(" is_deleted = 0").Find(&c).Error
- }
- func (c *User) GetUserByTenantId() error {
- return Db.Model(&c).Where("tenant_id = ? and is_deleted = 0", c.TenantId).Find(&c).Error
- }
- func (c *User) GetUserByPwd() error {
- return Db.Model(&c).Where("tenant_id = ? and account = ? and password = ? and is_deleted = 0", c.TenantId, c.Account, c.Password).First(&c).Error
- }
- func (c *User) GetUsers(offset, limit int) ([]User, int, error) {
- var users []User
- var counts int64
- db := Db.Model(&c)
- if c.Account != "" {
- db = db.Where("account like ?", "%"+c.Account+"%")
- }
- if c.RealName != "" {
- db = db.Where("real_name like ?", "%"+c.RealName+"%")
- }
- err := db.Where("is_deleted = 0").Offset(offset).Limit(limit).Find(&users).Error
- db1 := Db.Model(&c)
- db1.Where("is_deleted = 0").Count(&counts)
- return users, int(counts), err
- }
- func (c *User) Save() error {
- return Db.Model(&c).Save(&c).Error
- }
- func (c *User) Update() error {
- return Db.Model(&c).Where(" id = ? ", c.ID).Updates(&c).Error
- }
- func (c *User) Remove() error {
- return Db.Model(&c).Where("id = ?", c.ID).Updates(map[string]interface{}{"update_time": c.UpdateTime, "update_user": c.UpdateUser, "is_deleted": c.IsDeleted}).Error
- }
- func (c *User) UpdatePwd(pwd string) error {
- return Db.Model(&c).Where(" id = ? ", c.ID).Updates(map[string]interface{}{"password": pwd}).Error
- }
- func (c *User) GetAll() ([]User, error) {
- var users []User
- err := Db.Model(&c).Where("is_deleted = 0").Find(&users).Error
- return users, err
- }
- func (c *User) UpdateRoles(userIds []string, roleIds string) error {
- err := Db.Model(&c).Where("id in ?", userIds).Updates(map[string]interface{}{"role_id": roleIds}).Error
- return err
- }
- func (c *User) IsExist() bool {
- var s string
- Db.Model(&c).Select("account").Where("account = ?", c.Account).First(&s)
- return s != ""
- }
- func (c *User) GetAvatar() {
- tx := Db.Model(&c)
- tx.Select("avatar").Where("tenant_id = ?", c.TenantId).Find(&c)
- }
|