Эх сурвалжийг харах

fix: edit employee/search

jimmyyem 5 сар өмнө
parent
commit
98d5b03885

+ 22 - 15
internal/logic/employee/get_employee_search_logic.go

@@ -41,24 +41,31 @@ func (l *GetEmployeeSearchLogic) GetEmployeeSearch(req *types.EmployeeListReq, t
 		isLogin = false
 	}
 
-	userId := claims["userId"].(string)
-	departmentId := claims["deptId"].(float64)
-	organizationID := uint64(departmentId)
-	isLogin = true
+	var userId string
+	var departmentId float64
+	var organizationID uint64
+	if _, ok := claims["userId"]; ok {
+		userId = claims["userId"].(string)
+		departmentId = claims["deptId"].(float64)
+		organizationID = uint64(departmentId)
+		isLogin = true
+	}
 
 	employeeIds := make([]uint64, 0)
-	allocagent, err := l.svcCtx.DB.AllocAgent.Query().Where(
-		allocagent.Or(
-			allocagent.UserIDEQ(userId),
-			allocagent.OrganizationID(organizationID),
-		),
-	).Only(l.ctx)
-	if err != nil {
-		if !ent.IsNotFound(err) {
-			return nil, errorx.NewApiInternalError("获取智能体信息失败")
+	if isLogin {
+		allocagent, err := l.svcCtx.DB.AllocAgent.Query().Where(
+			allocagent.Or(
+				allocagent.UserIDEQ(userId),
+				allocagent.OrganizationID(organizationID),
+			),
+		).Only(l.ctx)
+		if err != nil {
+			if !ent.IsNotFound(err) {
+				return nil, errorx.NewApiInternalError("获取智能体信息失败")
+			}
+		} else {
+			employeeIds = append(employeeIds, allocagent.Agents...)
 		}
-	} else {
-		employeeIds = append(employeeIds, allocagent.Agents...)
 	}
 
 	var data *ent.EmployeePageList