parent
5d0c6c0c6e
commit
0b696202e7
|
@ -277,7 +277,7 @@ func (u *User) Save() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func UserTotal(ids []int64, query string) (int64, error) {
|
func UserTotal(ids []int64, where string, args ...interface{}) (int64, error) {
|
||||||
session := DB["rdb"].NewSession()
|
session := DB["rdb"].NewSession()
|
||||||
defer session.Close()
|
defer session.Close()
|
||||||
|
|
||||||
|
@ -285,23 +285,21 @@ func UserTotal(ids []int64, query string) (int64, error) {
|
||||||
session = session.In("id", ids)
|
session = session.In("id", ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
if query != "" {
|
if where != "" {
|
||||||
q := "%" + query + "%"
|
session = session.Where(where, args...)
|
||||||
return session.Where("username like ? or dispname like ? or phone like ? or email like ?", q, q, q, q).Count(new(User))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return session.Count(new(User))
|
return session.Count(new(User))
|
||||||
}
|
}
|
||||||
|
|
||||||
func UserGets(ids []int64, query string, limit, offset int) ([]User, error) {
|
func UserGets(ids []int64, limit, offset int, where string, args ...interface{}) ([]User, error) {
|
||||||
session := DB["rdb"].Limit(limit, offset).OrderBy("username")
|
session := DB["rdb"].Limit(limit, offset).OrderBy("username")
|
||||||
if len(ids) > 0 {
|
if len(ids) > 0 {
|
||||||
session = session.In("id", ids)
|
session = session.In("id", ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
if query != "" {
|
if where != "" {
|
||||||
q := "%" + query + "%"
|
session = session.Where(where, args...)
|
||||||
session = session.Where("username like ? or dispname like ? or phone like ? or email like ?", q, q, q, q)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var users []User
|
var users []User
|
||||||
|
|
|
@ -140,3 +140,30 @@ func UsernameCandoNodeOp(username, operation string, nodeId int64) (bool, error)
|
||||||
|
|
||||||
return user.HasPermByNode(node, operation)
|
return user.HasPermByNode(node, operation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UserAndTotalGets(query, org string, limit, offset int, ids []int64) ([]User, int64, error) {
|
||||||
|
where := "1 = 1"
|
||||||
|
param := []interface{}{}
|
||||||
|
|
||||||
|
if query != "" {
|
||||||
|
q := "%" + query + "%"
|
||||||
|
where += " and (username like ? or dispname like ? or phone like ? or email like ?)"
|
||||||
|
param = append(param, q, q, q, q)
|
||||||
|
}
|
||||||
|
|
||||||
|
if org != "" {
|
||||||
|
q := "%" + org + "%"
|
||||||
|
where += " and organization like ?"
|
||||||
|
param = append(param, q)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
total, err := UserTotal(ids, where, param...)
|
||||||
|
if err != nil {
|
||||||
|
return []User{}, total, err
|
||||||
|
}
|
||||||
|
|
||||||
|
list, err := UserGets(ids, limit, offset, where, param...)
|
||||||
|
|
||||||
|
return list, total, err
|
||||||
|
}
|
||||||
|
|
|
@ -174,7 +174,7 @@ func Config(r *gin.Engine) {
|
||||||
v1.GET("/get-teams-by-ids", v1TeamGetByIds)
|
v1.GET("/get-teams-by-ids", v1TeamGetByIds)
|
||||||
v1.GET("/get-user-ids-by-team-ids", v1UserIdsGetByTeamIds)
|
v1.GET("/get-user-ids-by-team-ids", v1UserIdsGetByTeamIds)
|
||||||
|
|
||||||
v1.GET("/users", userListGet)
|
v1.GET("/users", v1UserListGet)
|
||||||
|
|
||||||
v1.POST("/login", v1Login)
|
v1.POST("/login", v1Login)
|
||||||
v1.POST("/send-login-code-by-sms", v1SendLoginCodeBySms)
|
v1.POST("/send-login-code-by-sms", v1SendLoginCodeBySms)
|
||||||
|
|
|
@ -15,12 +15,10 @@ import (
|
||||||
func userListGet(c *gin.Context) {
|
func userListGet(c *gin.Context) {
|
||||||
limit := queryInt(c, "limit", 20)
|
limit := queryInt(c, "limit", 20)
|
||||||
query := queryStr(c, "query", "")
|
query := queryStr(c, "query", "")
|
||||||
|
org := queryStr(c, "org", "")
|
||||||
ids := str.IdsInt64(queryStr(c, "ids", ""))
|
ids := str.IdsInt64(queryStr(c, "ids", ""))
|
||||||
|
|
||||||
total, err := models.UserTotal(ids, query)
|
list, total, err := models.UserAndTotalGets(query, org, limit, offset(c, limit), ids)
|
||||||
dangerous(err)
|
|
||||||
|
|
||||||
list, err := models.UserGets(ids, query, limit, offset(c, limit))
|
|
||||||
dangerous(err)
|
dangerous(err)
|
||||||
|
|
||||||
for i := 0; i < len(list); i++ {
|
for i := 0; i < len(list); i++ {
|
||||||
|
@ -33,17 +31,32 @@ func userListGet(c *gin.Context) {
|
||||||
}, nil)
|
}, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func v1UserListGet(c *gin.Context) {
|
||||||
|
limit := queryInt(c, "limit", 20)
|
||||||
|
query := queryStr(c, "query", "")
|
||||||
|
org := queryStr(c, "org", "")
|
||||||
|
ids := str.IdsInt64(queryStr(c, "ids", ""))
|
||||||
|
|
||||||
|
list, total, err := models.UserAndTotalGets(query, org, limit, offset(c, limit), ids)
|
||||||
|
|
||||||
|
renderData(c, gin.H{
|
||||||
|
"list": list,
|
||||||
|
"total": total,
|
||||||
|
}, err)
|
||||||
|
}
|
||||||
|
|
||||||
type userProfileForm struct {
|
type userProfileForm struct {
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
Dispname string `json:"dispname"`
|
Dispname string `json:"dispname"`
|
||||||
Phone string `json:"phone"`
|
Phone string `json:"phone"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Im string `json:"im"`
|
Im string `json:"im"`
|
||||||
IsRoot int `json:"is_root"`
|
IsRoot int `json:"is_root"`
|
||||||
LeaderId int64 `json:"leader_id"`
|
LeaderId int64 `json:"leader_id"`
|
||||||
Typ int `json:"typ"`
|
Typ int `json:"typ"`
|
||||||
Status int `json:"status"`
|
Status int `json:"status"`
|
||||||
|
Organization string `json:"organization"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func userAddPost(c *gin.Context) {
|
func userAddPost(c *gin.Context) {
|
||||||
|
@ -141,7 +154,17 @@ func userProfilePut(c *gin.Context) {
|
||||||
target.Status = f.Status
|
target.Status = f.Status
|
||||||
}
|
}
|
||||||
|
|
||||||
err := target.Update("dispname", "phone", "email", "im", "is_root", "leader_id", "leader_name", "typ", "status")
|
if f.Status != target.Status {
|
||||||
|
arr = append(arr, fmt.Sprintf("typ: %s -> %s", target.Status, f.Status))
|
||||||
|
target.Status = f.Status
|
||||||
|
}
|
||||||
|
|
||||||
|
if f.Organization != target.Organization {
|
||||||
|
arr = append(arr, fmt.Sprintf("organization: %s -> %s", target.Organization, f.Organization))
|
||||||
|
target.Organization = f.Organization
|
||||||
|
}
|
||||||
|
|
||||||
|
err := target.Update("dispname", "phone", "email", "im", "is_root", "leader_id", "leader_name", "typ", "status", "organization")
|
||||||
if err == nil && len(arr) > 0 {
|
if err == nil && len(arr) > 0 {
|
||||||
content := strings.Join(arr, ",")
|
content := strings.Join(arr, ",")
|
||||||
go models.OperationLogNew(root.Username, "user", target.Id, fmt.Sprintf("UserModify %s %s", target.Username, content))
|
go models.OperationLogNew(root.Username, "user", target.Id, fmt.Sprintf("UserModify %s %s", target.Username, content))
|
||||||
|
|
Loading…
Reference in New Issue