瀏覽代碼

组织架构

kobe6258 7 月之前
父節點
當前提交
2f7e87fef2
共有 3 個文件被更改,包括 20 次插入10 次删除
  1. 14 4
      controllers/sys_user.go
  2. 3 3
      models/sys_department.go
  3. 3 3
      services/sys_user.go

+ 14 - 4
controllers/sys_user.go

@@ -330,20 +330,30 @@ func (this *SysUserController) List() {
 	pageSize, _ := this.GetInt("PageSize")
 	currentIndex, _ := this.GetInt("CurrentIndex")
 	roleId, _ := this.GetInt("RoleId")
+	//Type := this.GetString("Type")
+	Level, _ := this.GetInt("Level")
 	departmentId, _ := this.GetInt("DepartmentId")
 	keyWord := this.GetString("KeyWord")
 
 	var condition string
 	var pars []interface{}
-
+	if Level > 4 || Level < 1 {
+		br.Msg = "获取失败"
+		br.ErrMsg = fmt.Sprintf("获取失败,组织架构等级错误,不能小于1级或者超过4级,当前等级:%d", Level)
+		return
+	}
 	if roleId > 0 {
 		condition += ` AND sys_role_id=? `
 		pars = append(pars, roleId)
 	}
-
 	if departmentId > 0 {
-		condition += ` AND (sys_department_id1=? OR sys_department_id2=? OR sys_department_id3=?  OR sys_department_id4=?) `
-		pars = append(pars, departmentId, departmentId, departmentId, departmentId)
+		if Level == 1 {
+			condition += ` AND (sys_department_id1=?) `
+		} else {
+			queryDepartment := fmt.Sprintf("sys_department_id%d", Level)
+			condition += fmt.Sprintf(` AND %s=?`, queryDepartment)
+		}
+		pars = append(pars, departmentId)
 	}
 
 	if keyWord != "" {

+ 3 - 3
models/sys_department.go

@@ -40,10 +40,10 @@ func (s *SysDepartment) Update(cols []string) (err error) {
 type SysDepartmentList struct {
 	SysDepartmentId   int                  `description:"部门id"`
 	SysDepartmentName string               `description:"部门名称"`
-	OutId             int                  `gorm:"column:out_id;type:int(11);not null" json:"out_id"`
-	Type              DepartmentType       `gorm:"column:type;type:varchar(50);not null" json:"type"`
+	OutId             int                  `gorm:"column:outId;type:int(11);not null" `
+	Type              DepartmentType       `gorm:"column:type;type:varchar(50);not null"`
 	Child             []*SysDepartmentList `description:"分组"`
-	Level             int                  `description:"1:部门, 2|3:分组"`
+	Level             int                  `description:"1:部门, 2|3|4:分组"`
 	ParentId          int                  `description:"父目录id"`
 }
 

+ 3 - 3
services/sys_user.go

@@ -35,9 +35,9 @@ func GetSysUserList(condition string, pars []interface{}, startSize, pageSize in
 				SysRoleName:        user.SysRoleName,
 				SysDepartmentId:    user.SysDepartmentId,
 				SysDepartmentName1: departmentIdToName[models.SubCompany][user.SysDepartmentId1],
-				SysDepartmentName2: departmentIdToName[models.SubCompany][user.SysDepartmentId2],
-				SysDepartmentName3: departmentIdToName[models.SubCompany][user.SysDepartmentId3],
-				SysDepartmentName4: departmentIdToName[models.SubCompany][user.SysDepartmentId4],
+				SysDepartmentName2: departmentIdToName[models.Department][user.SysDepartmentId2],
+				SysDepartmentName3: departmentIdToName[models.Department][user.SysDepartmentId3],
+				SysDepartmentName4: departmentIdToName[models.Department][user.SysDepartmentId4],
 				Province:           user.Province,
 				City:               user.City,
 				PositionName:       user.PositionName,