|
|
@@ -1,5 +1,6 @@
|
|
|
package system
|
|
|
|
|
|
+import "C"
|
|
|
import (
|
|
|
"fmt"
|
|
|
"xorm.io/xorm"
|
|
|
@@ -49,7 +50,7 @@ func (d *UserRepo) GetById(ocId int64, userId int64)(*viewmodels.UserInfo, error
|
|
|
LEFT JOIN s_group AS G ON ( G.oc_id = F.oc_id AND G.group_id = F.grant_group_id )
|
|
|
LEFT JOIN s_position AS H ON ( A.oc_id = E.oc_id AND H.position_id = E.position_id ) `
|
|
|
sqlWhere := ` WHERE B.deleted_flag = 0 AND A.oc_id = ` + fmt.Sprintf("%d", ocId)
|
|
|
- sqlWhere += ` AND A.account_id = ` + fmt.Sprintf("%d", userId)
|
|
|
+ sqlWhere += ` AND A.account_id = ` + fmt.Sprintf("%d", userId)
|
|
|
|
|
|
data := &viewmodels.UserInfo{}
|
|
|
has, err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).Limit(1).Get(data)
|
|
|
@@ -61,11 +62,8 @@ func (d *UserRepo) GetById(ocId int64, userId int64)(*viewmodels.UserInfo, error
|
|
|
|
|
|
func (d *UserRepo) GetPage(m map[string]interface{})(*viewmodels.PageResult, error){
|
|
|
ocId := m["ocId"].(int64)
|
|
|
- keywords := m["keywords"].(string)
|
|
|
limit := m["limit"].(int)
|
|
|
page := m["page"].(int)
|
|
|
- nodeLeft := m["nodeLeft"].(int64)
|
|
|
- nodeRight := m["nodeRight"].(int64)
|
|
|
|
|
|
sqlSelect := `SELECT
|
|
|
DISTINCT(A.account_id),
|
|
|
@@ -115,14 +113,16 @@ func (d *UserRepo) GetPage(m map[string]interface{})(*viewmodels.PageResult, err
|
|
|
) AS D ON (A.oc_id = D.oc_id AND A.account_id = D.account_id AND A.group_id = D.group_id) `
|
|
|
sqlWhere := ` WHERE B.deleted_flag = 0 AND A.oc_id = ` + fmt.Sprintf("%d", ocId)
|
|
|
|
|
|
- if keywords != "" {
|
|
|
- sqlWhere+= ` AND ( B.account_real_name LIKE ` + "'%"+keywords+"%'"
|
|
|
- sqlWhere+= ` OR B.account_name LIKE ` + "'%"+keywords+"%'"
|
|
|
- sqlWhere+= ` OR B.account_phone LIKE ` + "'%"+keywords+"%'"
|
|
|
- sqlWhere+= ` OR D.position_name LIKE ` + "'%"+keywords+"%'"
|
|
|
+ if keywords, ok := m["keywords"]; ok {
|
|
|
+ sqlWhere+= " AND ( B.account_real_name LIKE '%" + fmt.Sprintf("%s",keywords) + "%' "
|
|
|
+ sqlWhere+= " OR B.account_name LIKE '%" + fmt.Sprintf("%s",keywords) + "%' "
|
|
|
+ sqlWhere+= " OR B.account_phone LIKE '%" + fmt.Sprintf("%s",keywords) + "%' "
|
|
|
+ sqlWhere+= " OR D.position_name LIKE '%" + fmt.Sprintf("%s",keywords) + "%' )"
|
|
|
}
|
|
|
|
|
|
- if nodeLeft > 0 && nodeRight > 0 {
|
|
|
+ nodeLeft, ok1 := m["nodeLeft"]
|
|
|
+ nodeRight, ok2 := m["nodeRight"]
|
|
|
+ if ok1 && ok2 {
|
|
|
sqlWhere+= ` AND C.node_left >= ` + fmt.Sprintf("%d", nodeLeft)
|
|
|
sqlWhere+= ` AND C.node_right <= ` + fmt.Sprintf("%d", nodeRight)
|
|
|
}
|
|
|
@@ -134,8 +134,8 @@ func (d *UserRepo) GetPage(m map[string]interface{})(*viewmodels.PageResult, err
|
|
|
}
|
|
|
|
|
|
sqlOrderBy := " ORDER BY A.account_id, A.group_id "
|
|
|
- pageStart := (page - 1) * limit
|
|
|
- sqlLimit := fmt.Sprintf(" LIMIT %d OFFSET %d ", limit, pageStart)
|
|
|
+ pageStart := (page - 1) * limit
|
|
|
+ sqlLimit := fmt.Sprintf(" LIMIT %d OFFSET %d ", limit, pageStart)
|
|
|
|
|
|
datalist := make([]viewmodels.UserInfo, 0)
|
|
|
err = d.engine.SQL(sqlSelect + sqlFrom + sqlWhere + sqlOrderBy + sqlLimit).Find(&datalist)
|
|
|
@@ -144,9 +144,83 @@ func (d *UserRepo) GetPage(m map[string]interface{})(*viewmodels.PageResult, err
|
|
|
}
|
|
|
|
|
|
pageResult := &viewmodels.PageResult{}
|
|
|
- pageResult.Data = datalist
|
|
|
- pageResult.Total = total
|
|
|
+ pageResult.Data = datalist
|
|
|
+ pageResult.Total = total
|
|
|
pageResult.PageSize = limit
|
|
|
- pageResult.Page = page
|
|
|
+ pageResult.Page = page
|
|
|
return pageResult, nil
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+func (d *UserRepo) GetList(m map[string]interface{})([]viewmodels.UserInfo, error){
|
|
|
+ ocId := m["ocId"].(int64)
|
|
|
+ sqlSelect := `SELECT
|
|
|
+ DISTINCT(A.account_id),
|
|
|
+ A.gm_id,
|
|
|
+ A.oc_id,
|
|
|
+ A.group_id,
|
|
|
+ B.account_name,
|
|
|
+ B.account_real_name,
|
|
|
+ B.account_phone,
|
|
|
+ B.account_staff_no,
|
|
|
+ B.account_avatar,
|
|
|
+ B.status,
|
|
|
+ B.is_fixed,
|
|
|
+ C.group_name,
|
|
|
+ C.node_left,
|
|
|
+ C.node_right,
|
|
|
+ D.gmp_id,
|
|
|
+ D.position_id,
|
|
|
+ D.position_name,
|
|
|
+ E.gmpg_id,
|
|
|
+ E.grant_group_id,
|
|
|
+ F.group_name as grant_group_name `
|
|
|
+ sqlFrom := `FROM s_group_member AS A
|
|
|
+ LEFT JOIN account AS B ON (A.oc_id = B.oc_id AND A.account_id = B.account_id)
|
|
|
+ LEFT JOIN s_group AS C ON (A.oc_id = C.oc_id AND A.group_id = C.group_id)
|
|
|
+ LEFT JOIN s_group_member_position_grant AS E ON (B.oc_id = E.oc_id AND B.account_id = E.account_id)
|
|
|
+ LEFT JOIN s_group AS F ON (E.oc_id = F.oc_id AND E.grant_group_id = F.group_id)
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT
|
|
|
+ M.oc_id,
|
|
|
+ M.account_id,
|
|
|
+ M.gmp_id,
|
|
|
+ M.group_id,
|
|
|
+ M.position_id,
|
|
|
+ P.position_name,
|
|
|
+ N.gmpg_id,
|
|
|
+ N.grant_group_id,
|
|
|
+ GP.group_name as grant_group_name
|
|
|
+ FROM s_group_member_position AS M
|
|
|
+ LEFT JOIN s_group_member_position_grant AS N ON (
|
|
|
+ M.oc_id = N.oc_id
|
|
|
+ AND M.account_id = N.account_id
|
|
|
+ AND M.group_id = N.group_id
|
|
|
+ AND M.position_id = N.position_id )
|
|
|
+ LEFT JOIN s_position AS P ON(M.oc_id = P.oc_id AND M.position_id = P.position_id)
|
|
|
+ LEFT JOIN s_group AS GP ON(M.oc_id = GP.oc_id AND N.grant_group_id = GP.group_id)
|
|
|
+ ) AS D ON (A.oc_id = D.oc_id AND A.account_id = D.account_id AND A.group_id = D.group_id) `
|
|
|
+ sqlWhere := ` WHERE B.deleted_flag = 0 AND A.oc_id = ` + fmt.Sprintf("%d", ocId)
|
|
|
+
|
|
|
+ if keywords, ok := m["keywords"]; ok {
|
|
|
+ sqlWhere+= " AND ( B.account_real_name LIKE '%" + fmt.Sprintf("%s",keywords) + "%' "
|
|
|
+ sqlWhere+= " OR B.account_name LIKE '%" + fmt.Sprintf("%s",keywords) + "%' "
|
|
|
+ sqlWhere+= " OR B.account_phone LIKE '%" + fmt.Sprintf("%s",keywords) + "%' "
|
|
|
+ sqlWhere+= " OR D.position_name LIKE '%" + fmt.Sprintf("%s",keywords) + "%' )"
|
|
|
+ }
|
|
|
+ nodeLeft, ok1 := m["nodeLeft"]
|
|
|
+ nodeRight, ok2 := m["nodeRight"]
|
|
|
+ if ok1 && ok2 {
|
|
|
+ sqlWhere+= ` AND C.node_left >= ` + fmt.Sprintf("%d", nodeLeft)
|
|
|
+ sqlWhere+= ` AND C.node_right <= ` + fmt.Sprintf("%d", nodeRight)
|
|
|
+ }
|
|
|
+ sqlOrderBy := " ORDER BY A.account_id, A.group_id "
|
|
|
+
|
|
|
+ datalist := make([]viewmodels.UserInfo, 0)
|
|
|
+ err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere + sqlOrderBy).Find(&datalist)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return datalist, nil
|
|
|
+}
|