private bool CheckTag(GetAppInfoResult appInfo, IList <int> selectedTagIds, IEnumerable <string> allAssignedUsers, CheckResult checkResult) { if (!selectedTagIds.Any()) { return(true); } var needTags = selectedTagIds.Select(selectedTagId => new TagEntity { TagId = selectedTagId, TagMember = WeChatCommonService.GetTagMembers(selectedTagId, int.Parse(appInfo.agentid)) }).ToList(); //needTags.Select(x => new { TagId = x.Key, TagMember = x.Value }).ToList(); var needUsers = needTags.SelectMany(x => x.TagMember.userlist.Select(y => y.userid)).ToList(); var needParties = WeChatCommonService.GetSubDepartments(needTags.SelectMany(x => x.TagMember.partylist).ToList()).ToList(); needUsers.AddRange(WeChatCommonService.lstUser.Where(x => needParties.Any(y => x.department.Any(z => z == y.id))).Select(x => x.userid).ToList()); var errorUsers = needUsers.Where(x => allAssignedUsers.Any(y => x == y)).ToList(); var errorTags = needTags.Where(x => errorUsers.Any(y => x.TagMember.userlist.Any(z => z.userid == y))).Select(x => x.TagId).ToList(); if (!errorTags.Any()) { return(true); } checkResult.ErrorTags = GetErrorTags(errorTags); return(false); }
private static bool CheckUser(IEnumerable <string> allAssignedUsers, IList <string> selectedLillyIds, CheckResult checkResult) { if (!selectedLillyIds.Any()) { return(true); } var errorUsers = selectedLillyIds.Where(id => allAssignedUsers.All(assignedUserId => string.Compare(id, assignedUserId, StringComparison.CurrentCultureIgnoreCase) != 0) || WeChatCommonService.lstUser.First(x => string.Compare(x.userid, id, StringComparison.CurrentCultureIgnoreCase) == 0).status == 4).ToList(); if (!errorUsers.Any()) { return(true); } checkResult.ErrorUsers = errorUsers; return(false); }
private bool CheckDepartment(GetAppInfoResult appInfo, IList <int> selectedDepartmentIds, CheckResult checkResult) { //直接分配给应用 var assignedDepartmentIds = appInfo.allow_partys.partyid.ToList(); var underTagDepartmentIDs = _tagMemberdDictionary.Select(x => x.Value).SelectMany(x => x.partylist).ToList(); assignedDepartmentIds.AddRange(underTagDepartmentIDs); //TODO:调整 if (!assignedDepartmentIds.Any()) { if (!selectedDepartmentIds.Any()) { return(true); } checkResult.ErrorDepartments = GetErrorDepartments(selectedDepartmentIds); return(false); } var departments = WeChatCommonService.GetSubDepartments(assignedDepartmentIds.Distinct().ToList()).ToList(); #region hiddlen //var allowUsers = WeChatCommonService.lstUser.Where(x => x.department.Any(y => departments.Any(z => z.id == y))).ToList(); //var needUsers = WeChatCommonService.lstUser.Where(x => x.department.Any(y => selectedDepartmentIds.Any(s => s == y))).ToList(); //var errorUsers = needUsers.Where(x => allowUsers.All(u => x.userid != u.userid)).ToList(); //if (!errorUsers.Any()) //{ // return true; //} //var errorDepartments = WeChatCommonService.lstDepartment.Where(x => errorUsers.SelectMany(y => y.department).Any(z => z == x.id)).ToList(); //var errorDepartmentIds = selectedDepartmentIds.Where(x => WeChatCommonService.GetSubDepartments(x).Any(y => errorDepartments.Any(z => z.id == y.id))).ToList(); //if (!errorDepartmentIds.Any()) return true; #endregion var errorDepartmentIds = selectedDepartmentIds.Where(x => departments.All(y => x != y.id)).ToList(); if (!errorDepartmentIds.Any()) { return(true); } checkResult.ErrorDepartments = GetErrorDepartments(errorDepartmentIds); return(false); }