public async Task <ActionResult <ResourceGroupResponse> > GetEmployeeResourceGroup(string id) { try { if (string.IsNullOrWhiteSpace(id)) { this.logger.LogWarning("Request id parsed as null or empty."); return(this.NotFound("Request id cannot be null or empty.")); } var groupEntity = await this.employeeResourceGroupRepository.GetAsync(Constants.ResourceGroupTablePartitionKey, id); if (groupEntity == null) { this.logger.LogInformation($"No record found for provided resource Id: {id}"); return(this.NotFound($"No record found for provided resource Id : {id}")); } var resourceGroupResponse = new ResourceGroupResponse { GroupType = groupEntity.GroupType, GroupId = groupEntity.GroupId, GroupName = groupEntity.GroupName, GroupDescription = groupEntity.GroupDescription, GroupLink = groupEntity.GroupLink, ImageLink = groupEntity.ImageLink, Tags = JsonConvert.DeserializeObject <List <string> >(groupEntity.Tags), Location = groupEntity.Location, IncludeInSearchResults = groupEntity.IncludeInSearchResults, MatchingFrequency = groupEntity.MatchingFrequency, IsProfileMatchingEnabled = groupEntity.IsProfileMatchingEnabled, }; return(this.Ok(resourceGroupResponse)); } catch (Exception ex) { this.logger.LogError(ex, "Error while fetching employee resource group."); throw; } }
/// <summary> /// 查询用户分组 /// </summary> /// <param name="customer">customerid</param> /// <param name="customerToken">token</param> /// <param name="ResourceGroup">返回数据 分组</param> /// <returns></returns> public ResponseBaseDto GetGroupByCustomerId(string customerToken, ref IList <ResourceGroupResponse> resourceGroupResponse) { ResponseBaseDto dto = new ResponseBaseDto(); UserTokenCache utc = UserTokenCache.GetInstance(); TokenCacheProperty tcp = new TokenCacheProperty(); if (utc.IsValid(customerToken) == false) { dto.Code = (int)CodeEnum.ServerNoToken; dto.Message = "用户token已失效,请重新登录后继续"; } else { try { dto = bllHelper.CheckCustomer(dto, customerToken, ref tcp); if (dto.Code != 0) { return(dto); } else { Customer customer = new Customer(); customer.CustomerId = tcp.CustomerId; int primaryCustomerId = tcp.CustomerId; IList <ResourceGroup> resourceGroup = new List <ResourceGroup>(); bool isPrimaryCustomer = true;// 主用户 is true IList <Customer> customerFlag = customerServer.SelectCustomerByCustomerId(customer); if (customerFlag[0].ParentId != 0 && customerFlag[0].SignInType == (int)CustomerSignInTypeEnum.SubCustomer) { //子账户将查询主用户的分组信息 primaryCustomerId = customerFlag[0].ParentId; isPrimaryCustomer = false; } //子用户起来后添加权限逻辑 var allResourceGroup = resourceGroupServer.SelectResourceGorupByCustomerId(primaryCustomerId); // 主账号直接返回 if (isPrimaryCustomer == true) { resourceGroup = allResourceGroup; } else { // 子账号要过滤掉没有镜头的空分组 IList <ResourceGroup> validResourceGroup = resourceGroupServer.GetResourceGroupBySubCustomerId(tcp.CustomerId, primaryCustomerId); // 返回的resourceGroup个数至少是validResourceGroup, // 所以先复制出来 foreach (var it in validResourceGroup) { resourceGroup.Add(it); } // 遍历validResourceGroup, 把其节点中,父节点不在resourceGroup内的,加进去。 foreach (var it in validResourceGroup) { CheckAndCopy(allResourceGroup, ref resourceGroup, it); } } //加载分组是否有下一级 for (int i = 0; i < resourceGroup.Count; i++) { var result = from rs in resourceGroup where resourceGroup[i].ResourceGroupId == rs.ParentResourceGroupId select rs; ResourceGroupResponse rg = new ResourceGroupResponse(); if (result.Count() != 0) { rg.IsNext = 1; } rg.CustomerId = resourceGroup[i].CustomerId; rg.ResourceGroupId = resourceGroup[i].ResourceGroupId; rg.ResourceGroupName = resourceGroup[i].ResourceGroupName; rg.ParentResourceGroupId = resourceGroup[i].ParentResourceGroupId; resourceGroupResponse.Add(rg); } } dto.Code = (int)CodeEnum.Success; dto.Message = "分组数据获取完成"; } catch (Exception ex) { dto.Code = (int)CodeEnum.ApplicationErr; dto.Message = "网络异常,请刷新页面后继续"; myLog.WarnFormat("GetGroupByCustomerId方法异常,用户Id:{0}", ex, tcp.CustomerId); } } return(dto); }