|
@@ -1,34 +1,35 @@
|
|
|
package dao
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
|
|
|
type User struct {
|
|
|
- ID int64 `gorm:"primary_key;type:bigint" json:"id"`
|
|
|
- TenantId int `gorm:"type:int" 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:datetime" json:"birthday"`
|
|
|
- Sex int `gorm:"type:smallint" json:"sex"`
|
|
|
- RoleId int64 `gorm:"type:bigint" json:"roleId"`
|
|
|
- CreateUser int64 `gorm:"type:bigint" json:"createUser"`
|
|
|
- CreateDept int64 `gorm:"type:bigint" json:"createDept"`
|
|
|
- CreateTime time.Time `gorm:"type:datetime" json:"createTime"`
|
|
|
- UpdateUser int64 `gorm:"type:bigint" json:"updateUser"`
|
|
|
- UpdateTime time.Time `gorm:"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"`
|
|
|
+ ID int64 `gorm:"primary_key;type:bigint" json:"id"`
|
|
|
+ TenantId int `gorm:"type:int" 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 int64 `gorm:"type:bigint" json:"roleId"`
|
|
|
+ CreateUser int64 `gorm:"type:bigint" json:"createUser"`
|
|
|
+ CreateDept int64 `gorm:"type:bigint" json:"createDept"`
|
|
|
+ CreateTime time.Time `gorm:"autoCreateTime;column:create_time;type:datetime;" json:"createTime"`
|
|
|
+ UpdateUser int64 `gorm:"type:bigint" 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
|
|
|
|
|
@@ -41,7 +42,7 @@ func (User) TableName() string {
|
|
|
}
|
|
|
|
|
|
func (c *User) GetUser() error {
|
|
|
- return Db.Debug().Model(&c).Where("id = ? and is_deleted = 0", c.ID).Find(&c).Error
|
|
|
+ return Db.Debug().Model(&c).Where(" is_deleted = 0").Find(&c).Error
|
|
|
}
|
|
|
|
|
|
func (c *User) GetUserByTenantId() error {
|
|
@@ -52,9 +53,12 @@ func (c *User) GetUserByPwd() error {
|
|
|
return Db.Debug().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, error) {
|
|
|
+func (c User) GetUsers(offset, limit int) ([]User, int64, error) {
|
|
|
var users []User
|
|
|
+ var counts int64
|
|
|
db := Db.Debug().Model(&c)
|
|
|
+ db.Count(&counts)
|
|
|
+
|
|
|
if c.Account != "" {
|
|
|
db = db.Where("account like ?", "%"+c.Account+"%")
|
|
|
}
|
|
@@ -62,7 +66,8 @@ func (c User) GetUsers(offset, limit int) ([]User, error) {
|
|
|
db = db.Where("real_name like ?", "%"+c.RealName+"%")
|
|
|
}
|
|
|
err := db.Where("is_deleted = 0").Offset(offset).Limit(limit).Find(&users).Error
|
|
|
- return users, err
|
|
|
+
|
|
|
+ return users, counts, err
|
|
|
}
|
|
|
|
|
|
func (c *User) Save() error {
|
|
@@ -91,3 +96,11 @@ func (c *User) UpdateRoles(userIds []string, roleIds string) error {
|
|
|
err := Db.Debug().Model(&c).Where("id in ?", userIds).Updates(map[string]interface{}{"role_id": roleIds}).Error
|
|
|
return err
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+func (c *User) IsExist() bool {
|
|
|
+ var s string
|
|
|
+ r := Db.Debug().Model(&c).Select("account").Where("account = ?", c.Account).First(&s).Error
|
|
|
+ fmt.Printf("ERROR:%v\n account:%v\n return:%v\n", r, s, s != "")
|
|
|
+ return s != ""
|
|
|
+}
|