Parcourir la source

Merge branch 'feature/pool354_mobile_eta_department' into debug

kobe6258 il y a 1 mois
Parent
commit
625b4d3885
3 fichiers modifiés avec 73 ajouts et 1 suppressions
  1. 34 1
      controllers/user_login.go
  2. 6 0
      models/system/sys_group.go
  3. 33 0
      services/system.go

+ 34 - 1
controllers/user_login.go

@@ -12,6 +12,7 @@ import (
 	"github.com/mojocn/base64Captcha"
 	"image/color"
 	"strings"
+	"sync"
 	"time"
 )
 
@@ -490,6 +491,33 @@ func (this *UserLoginController) Login() {
 		}
 		sysUser = emailUser
 	}
+	var wg sync.WaitGroup
+	var FullGroupName string
+	nameChan := make(chan string, 1)
+	//需要对用户的分组展示优化为多级
+	if sysUser.GroupId > 0 {
+		wg.Add(1)
+		go func() {
+			defer wg.Done()
+			groupList, e := system.GetGroupByDepartmentId(sysUser.DepartmentId)
+			if e != nil {
+				nameChan <- ""
+				return
+			}
+			var root = new(system.GroupNode)
+			services.BuildGroupTree(root, groupList, 10, 0)
+			var find bool
+			var fullGroupName string
+			if root != nil {
+				find, fullGroupName = services.GetGroupName(root.Child, sysUser.GroupId)
+			}
+			if find {
+				nameChan <- fullGroupName
+			} else {
+				nameChan <- ""
+			}
+		}()
+	}
 
 	// 登录成功(无论哪种方式登录), 清除异常标记
 	abnormalCache := fmt.Sprint(utils.CACHE_ABNORMAL_LOGIN, sysUser.AdminName)
@@ -587,7 +615,12 @@ func (this *UserLoginController) Login() {
 		record.CreateTime = time.Now()
 		_ = system.AddSysUserLoginRecord(record)
 	}()
-
+	wg.Wait()
+	close(nameChan)
+	FullGroupName = <-nameChan
+	if FullGroupName != "" {
+		resp.GroupName = FullGroupName
+	}
 	br.Data = resp
 	br.Ret = 200
 	br.Success = true

+ 6 - 0
models/system/sys_group.go

@@ -192,6 +192,12 @@ func MultiUpdateGroupSort(items []*GroupSort) (err error) {
 	return
 }
 
+type GroupNode struct {
+	GroupId   int    `json:"groupId"`
+	GroupName string `json:"groupName"`
+	Child     []*GroupNode
+}
+
 func GetGroupByDepartmentId(departmentId int) (list []*SysFullGroup, err error) {
 	sql := `SELECT
 				s.*, g.group_name AS parent_group_name,

+ 33 - 0
services/system.go

@@ -3,6 +3,7 @@ package services
 import (
 	"eta/eta_mobile/models/company"
 	"eta/eta_mobile/models/system"
+	"fmt"
 )
 
 // CheckAdminIsSameBigGroup 判断是否两个系统用户是否同一个大组内
@@ -54,3 +55,35 @@ func CheckAdminIsSameBigGroup(adminInfo1, adminInfo2 *system.Admin) (isSame bool
 	}
 	return
 }
+
+func BuildGroupTree(rootNode *system.GroupNode, groupList []*system.SysFullGroup, depth, current int) {
+	if current >= depth {
+		return
+	}
+	for _, group := range groupList {
+		if group.ParentId == rootNode.GroupId {
+			childNode := &system.GroupNode{
+				GroupId:   group.GroupId,
+				GroupName: group.GroupName,
+			}
+			BuildGroupTree(childNode, groupList, depth, current+1)
+			rootNode.Child = append(rootNode.Child, childNode)
+		}
+	}
+}
+
+func GetGroupName(nodes []*system.GroupNode, groupId int) (find bool, groupName string) {
+	for _, child := range nodes {
+		if child.GroupId == groupId {
+			return true, child.GroupName
+		}
+		if len(child.Child) > 0 {
+			find, subGroupName := GetGroupName(child.Child, groupId)
+			if find {
+				groupName = fmt.Sprintf("%s/%s", child.GroupName, subGroupName)
+				return true, groupName
+			}
+		}
+	}
+	return false, ""
+}