public ActionResult GetTaskGroupList(string projectSeriesGuid) { return(ActionUtils.Json(() => { var projectSeries = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid); var project = projectSeries.CurrentProject.Instance; CheckPermission(PermissionObjectType.Project, project.ProjectGuid, PermissionType.Read); var taskGroups = projectSeries.CurrentProject.TaskGroups; var allPermissionUid = m_dbAdapter.Permission.GetObjectUids(CurrentUserName, PermissionObjectType.TaskGroup, PermissionType.Read).ToDictionary(x => x); var hasPermissionTaskGroups = taskGroups.Where(x => allPermissionUid.ContainsKey(x.Instance.Guid)).ToList(); var result = hasPermissionTaskGroups.ConvertAll(x => new { guid = x.Instance.Guid, name = x.Instance.Name, projectGuid = projectSeries.CurrentProject.Instance.ProjectGuid, description = x.Instance.Description, sequence = x.Instance.Sequence, percentCompleted = CommUtils.Percent(x.Tasks.Count(task => task.TaskStatus == TaskStatus.Finished), x.Tasks.Count, 0), finishedTaskCount = x.Tasks.Count(task => task.TaskStatus == TaskStatus.Finished), taskCount = x.Tasks.Count, createUserName = x.Instance.CreateUserName, createTimeStamp = Toolkit.DateTimeToString(x.Instance.CreateTime) }); return ActionUtils.Success(result); })); }
public ActionResult ResetSequence(string projectSeriesGuid, string orderedTaskGroupGuids) { return(ActionUtils.Json(() => { var projectSeries = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid); var project = projectSeries.CurrentProject.Instance; CheckPermission(PermissionObjectType.Project, project.ProjectGuid, PermissionType.Write); var taskGroups = projectSeries.CurrentProject.TaskGroups; var oldGuids = taskGroups.Select(x => x.Instance.Guid).ToArray(); var newGuids = CommUtils.Split(orderedTaskGroupGuids); CommUtils.Assert(CommUtils.IsEqual(oldGuids, newGuids), "当前工作组和服务器上不一致,请刷新后再试"); var oldSequences = taskGroups.Select(x => x.Instance.Sequence.Value).ToList(); taskGroups.ForEach(x => x.Instance.Sequence = oldSequences[Array.IndexOf(newGuids, x.Instance.Guid)]); var newTaskGroups = new List <TaskGroup>(); for (int i = 0; i < taskGroups.Count(); i++) { var taskGroup = taskGroups[i].Instance; if (taskGroup.Sequence != oldSequences[i]) { CheckPermission(PermissionObjectType.TaskGroup, taskGroup.Guid, PermissionType.Write); newTaskGroups.Add(taskGroups[i].Instance); } } newTaskGroups.ForEach(x => m_dbAdapter.TaskGroup.UpdateTaskGroup(x)); return ActionUtils.Success(1); })); }
public ActionResult GetRelatedUsers() { return(ActionUtils.Json(() => { var projectSeriesGuidsOfCurrentUserName = m_dbAdapter.Permission.GetObjectUids(CurrentUserName, PermissionObjectType.ProjectSeries, PermissionType.Read); var projectSeries = m_dbAdapter.ProjectSeries.GetByGuids(projectSeriesGuidsOfCurrentUserName); List <string> usernameList = new List <string>(); foreach (var singleProjectSeries in projectSeries) { var singleProjectSeriesLogicModel = new ProjectSeriesLogicModel(CurrentUserName, singleProjectSeries); var projectSeriesInstance = singleProjectSeriesLogicModel.Instance; var project = singleProjectSeriesLogicModel.CurrentProject.Instance; usernameList.Add(projectSeriesInstance.PersonInCharge); usernameList.Add(projectSeriesInstance.CreateUserName); var teamMembers = m_dbAdapter.TeamMember.GetByProjectId(project.ProjectId); var teamMemberUsernames = teamMembers.Select(x => x.UserName).ToList(); usernameList.AddRange(teamMemberUsernames); } usernameList = usernameList.Distinct(StringComparer.OrdinalIgnoreCase).ToList(); Platform.UserProfile.Precache(usernameList); var result = usernameList.ConvertAll(x => new { userName = Platform.UserProfile.Get(x).UserName, realName = Platform.UserProfile.Get(x).RealName, }); return ActionUtils.Success(result); })); }
public ActionResult GetOneProjectSeriesInfo(string projectSeriesGuid) { return(ActionUtils.Json(() => { var projectSeriesLogicModel = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid); var projectSeries = projectSeriesLogicModel.Instance; var project = projectSeriesLogicModel.CurrentProject.Instance; CommUtils.Assert(IsCurrentUser(projectSeries.CreateUserName) || IsCurrentUser(projectSeries.PersonInCharge) || m_dbAdapter.TeamAdmin.IsTeamAdmin(project.ProjectId, CurrentUserName), "当前用户[{0}]不是项目[{1}]的管理员/创建者/负责人", CurrentUserName, projectSeries.Name); CheckPermission(PermissionObjectType.ProjectSeries, projectSeriesGuid, PermissionType.Write); var result = new { Name = projectSeries.Name, Type = projectSeries.Type.ToString(), StartTime = projectSeries.CreateTime.ToString("yyyy-MM-dd"), EndTime = projectSeries.EstimatedFinishTime.HasValue?projectSeries.EstimatedFinishTime.Value.ToString("yyyy-MM-dd"):"", PersonInCharge = Platform.UserProfile.Get(projectSeries.PersonInCharge).UserName, Email = projectSeries.Email, }; return ActionUtils.Success(result); })); }
public ActionResult GetPersonInCharges(string projectSeriesGuid) { return(ActionUtils.Json(() => { var projectSeriesLogicModel = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid); var projectSeries = projectSeriesLogicModel.Instance; var projectId = projectSeriesLogicModel.CurrentProject.Instance.ProjectId; CheckPermission(PermissionObjectType.ProjectSeries, projectSeriesGuid, PermissionType.Read); var adminUserNames = projectSeriesLogicModel.CurrentProject.Team.Chiefs.Select(x => x.UserName).ToList(); var teamMembers = m_dbAdapter.TeamMember.GetByProjectId(projectId); var teamMemberUserNames = teamMembers.Select(x => x.UserName).ToList(); var teamAdmins = m_dbAdapter.TeamAdmin.GetByProjectId(projectId); var teamAdminUserNames = teamAdmins.Select(x => x.UserName).ToList(); var allUserNames = new List <string>(); allUserNames.AddRange(adminUserNames); allUserNames.AddRange(teamAdminUserNames); allUserNames.AddRange(teamMemberUserNames); allUserNames = allUserNames.Distinct(StringComparer.OrdinalIgnoreCase).ToList(); Platform.UserProfile.Precache(allUserNames); var result = allUserNames.ConvertAll(x => new { UserInfo = Platform.UserProfile.Get(x), }); return ActionUtils.Success(result); })); }
private bool IsTeamAdmin(string projectSeriesGuid, string username) { var projectSeriesLogicModel = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid); var project = projectSeriesLogicModel.CurrentProject.Instance; var teamAdmins = m_dbAdapter.TeamAdmin.GetByProjectId(project.ProjectId); return(teamAdmins.Any(x => x.UserName == username)); }
public ActionResult CreateProjectSeries(string name, string projectSeriesType, string personInCharge, string createTime, string estimatedFinishTime, string email) { return(ActionUtils.Json(() => { var logicModel = new ProjectSeriesLogicModel(CurrentUserName); logicModel.NewProjectSeries(name, projectSeriesType, personInCharge, createTime, estimatedFinishTime, email); return ActionUtils.Success(1); })); }
public ActionResult ModifyTaskGroup(string projectSeriesGuid, string taskGroupGuid, string name, string description) { return(ActionUtils.Json(() => { CheckPermission(PermissionObjectType.TaskGroup, taskGroupGuid, PermissionType.Write); var projectSeries = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid); projectSeries.CurrentProject.ModifyTaskGroup(taskGroupGuid, name, description); return ActionUtils.Success(1); })); }
public ActionResult NewTaskGroup(string projectSeriesGuid, string name, string description) { return(ActionUtils.Json(() => { var projectSeries = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid); var project = projectSeries.CurrentProject.Instance; CheckPermission(PermissionObjectType.Project, project.ProjectGuid, PermissionType.Write); var newTaskGroup = projectSeries.CurrentProject.NewTaskGroup(projectSeriesGuid, name, description).Instance; return ActionUtils.Success(newTaskGroup.Guid); })); }
public ActionResult ExitProjectSeries(string projectSeriesGuid) { return(ActionUtils.Json(() => { CheckPermission(PermissionObjectType.ProjectSeries, projectSeriesGuid, PermissionType.Read); var projectSeriesLogicModel = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid); var projectSeries = projectSeriesLogicModel.Instance; CommUtils.Assert(!IsCurrentUser(projectSeries.CreateUserName), "当前用户[{0}]是项目[{1}]的创建者,不能退出项目", CurrentUserName, projectSeries.Name); var projectLogicModel = projectSeriesLogicModel.CurrentProject; var project = projectLogicModel.Instance; var permissionLogicModel = new PermissionLogicModel(CurrentUserName, projectSeries); if (IsCurrentUser(projectSeries.PersonInCharge)) { projectSeries.PersonInCharge = projectSeries.CreateUserName; permissionLogicModel.RemoveUserPermissionByProjectSeries(new List <string>() { CurrentUserName }); } else if (m_dbAdapter.TeamAdmin.IsTeamAdmin(project.ProjectId, CurrentUserName)) { var teamAdmins = m_dbAdapter.TeamAdmin.GetByProjectId(project.ProjectId); var teamAdmin = teamAdmins.FirstOrDefault(x => x.UserName.Equals(CurrentUserName, StringComparison.CurrentCultureIgnoreCase)); m_dbAdapter.TeamAdmin.Delete(teamAdmin); permissionLogicModel.RemoveUserPermissionByProjectSeries(new List <string>() { CurrentUserName }); } else if (m_dbAdapter.TeamMember.IsTeamMember(project.ProjectId, CurrentUserName)) { var teamMembers = m_dbAdapter.TeamMember.GetByProjectId(project.ProjectId); var teamMember = teamMembers.FirstOrDefault(x => x.UserName.Equals(CurrentUserName, StringComparison.CurrentCultureIgnoreCase)); m_dbAdapter.TeamMember.Remove(teamMember); permissionLogicModel.RemoveUserPermissionByProjectSeries(new List <string>() { CurrentUserName }); } return ActionUtils.Success(1); })); }
public ActionResult GetTeamMembersOfUserGroup(string projectSeriesGuid, string userGroupGuid) { return(ActionUtils.Json(() => { var projectSeriesLogicModel = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid); var projectSeries = projectSeriesLogicModel.Instance; var projectId = projectSeriesLogicModel.CurrentProject.Instance.ProjectId; CommUtils.Assert(IsAdmin(projectSeriesLogicModel.Instance, CurrentUserName) || m_dbAdapter.TeamAdmin.IsTeamAdmin(projectId, CurrentUserName), "当前用户[{0}]不是项目[{1}]的创建者/负责人/管理员", Platform.UserProfile.GetDisplayRealNameAndUserName(CurrentUserName), projectSeriesLogicModel.Instance.Name); var userGroup = m_dbAdapter.UserGroup.GetByGuid(userGroupGuid); CommUtils.Assert(IsCurrentUser(userGroup.Owner), "当前用户[{0}]不是[{1}]的创建者", CurrentUserName, userGroup.Name); var teamAdmins = m_dbAdapter.TeamAdmin.GetByProjectId(projectId); var teamAdminUserNames = teamAdmins.Select(x => x.UserName).ToList(); var teamMembers = m_dbAdapter.TeamMember.GetByProjectId(projectId); var teamMemberUserNames = teamMembers.Select(x => x.UserName).ToList(); var userGroupMaps = m_dbAdapter.UserGroupMap.GetByUserGroupGuid(userGroupGuid); var userGroupMapUserNames = userGroupMaps.Select(x => x.UserName).ToList(); var teamMembersOfUserGroup = teamMemberUserNames.Intersect(userGroupMapUserNames).ToList(); Platform.UserProfile.Precache(userGroupMapUserNames); var result = new { UserGroupUsers = userGroupMapUserNames.ConvertAll(x => new { UserName = Platform.UserProfile.Get(x).UserName, RealName = Platform.UserProfile.Get(x).RealName, IsTeamMemberOfUserGroup = teamMembersOfUserGroup.Contains(x) ? true : false, IsCreator = projectSeries.CreateUserName.Equals(x, StringComparison.CurrentCultureIgnoreCase) ? true : false, IsPersonInCharge = projectSeries.PersonInCharge.Equals(x, StringComparison.CurrentCultureIgnoreCase) ? true : false, IsTeamAdmin = teamAdminUserNames.Contains(x) ? true : false, }).ToList(), StatisticInfo = new { TotalUserGroupUser = userGroupMapUserNames.Count(), TotalteamMemberOfUserGroup = teamMembersOfUserGroup.Count() } }; return ActionUtils.Success(result); })); }
public ActionResult GetProjectSeriesProcessInfo(string username) { return(ActionUtils.Json(() => { var projectSeriesGuidsOfCurrentUserName = m_dbAdapter.Permission.GetObjectUids(CurrentUserName, PermissionObjectType.ProjectSeries, PermissionType.Read); var projectSeriesGuidsOfUsername = m_dbAdapter.ProjectSeries.GetByPersonInCharge(username).Select(x => x.Guid).ToList(); var projectSeries = m_dbAdapter.ProjectSeries.GetByGuids(projectSeriesGuidsOfCurrentUserName.Intersect(projectSeriesGuidsOfUsername)); List <SingleProjectSeriesProcessInfo> singleProjectSeriesProcessInfoList = new List <SingleProjectSeriesProcessInfo>(); foreach (var singleProjectSeries in projectSeries) { var singleProjectSeriesLogicModel = new ProjectSeriesLogicModel(CurrentUserName, singleProjectSeries); var projectSeriesInstance = singleProjectSeriesLogicModel.Instance; var project = singleProjectSeriesLogicModel.CurrentProject.Instance; var tasksOfSingleprojectSeries = m_dbAdapter.Task.GetTasksByProjectId(project.ProjectId); var finishedTasksOfSingleprojectSeries = tasksOfSingleprojectSeries.Where(x => x.TaskStatus == TaskStatus.Finished).ToList(); singleProjectSeriesProcessInfoList.Add(new SingleProjectSeriesProcessInfo { Name = projectSeriesInstance.Name, Guid = projectSeriesInstance.Guid, TotalTaskCount = tasksOfSingleprojectSeries.Count, FinishedTaskCount = finishedTasksOfSingleprojectSeries.Count, TaskPercentCompleted = CommUtils.Percent(finishedTasksOfSingleprojectSeries.Count, tasksOfSingleprojectSeries.Count) }); } var finishedProjectSeriesCount = singleProjectSeriesProcessInfoList.Count(x => double.Parse(x.TaskPercentCompleted.Replace("%", "")) == 100); var result = new { SingleProjectSeriesProcessInfoList = singleProjectSeriesProcessInfoList, ProjectSeriesStatisticInfo = new { TotalProjectSeriesCount = singleProjectSeriesProcessInfoList.Count, FinishedProjectSeriesCount = finishedProjectSeriesCount, ProjectSeriesPercentCompleted = CommUtils.Percent(finishedProjectSeriesCount, singleProjectSeriesProcessInfoList.Count) } }; return ActionUtils.Success(result); })); }
public ActionResult GetProjectSeriesProcessInfo(string projectSeriesGuid) { return(ActionUtils.Json(() => { var projectSeriesLogicModel = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid); CheckPermission(PermissionObjectType.ProjectSeries, projectSeriesGuid, PermissionType.Read); var tasks = m_dbAdapter.Task.GetTasksByProjectId(projectSeriesLogicModel.CurrentProject.Instance.ProjectId); var finishedTaskCount = tasks.Count(x => x.TaskStatus == TaskStatus.Finished); var percentCompleted = CommUtils.Percent(finishedTaskCount, tasks.Count); var projectSeries = projectSeriesLogicModel.Instance; var personInChargeInfo = Platform.UserProfile.Get(projectSeries.PersonInCharge); var createUserInfo = Platform.UserProfile.Get(projectSeries.CreateUserName); var result = new { name = projectSeries.Name, personInCharge = new { userName = personInChargeInfo.UserName, realName = personInChargeInfo.RealName }, createUser = new { userName = createUserInfo.UserName, realName = createUserInfo.RealName }, createTimeStamp = projectSeries.CreateTime.ToString("yyyy-MM-dd"), estimatedFinishTime = Toolkit.DateToString(projectSeries.EstimatedFinishTime), remainingDayCount = projectSeries.EstimatedFinishTime.HasValue ? ((int)(projectSeries.EstimatedFinishTime.Value - DateTime.Today).TotalDays).ToString() : "-", stage = projectSeries.Stage.ToString(), taskCount = tasks.Count, finishedTaskCount = finishedTaskCount, percentCompleted = percentCompleted, projectType = projectSeries.Type.ToString(), email = string.IsNullOrWhiteSpace(projectSeries.Email)? null:projectSeries.Email, }; return ActionUtils.Success(result); })); }
private List <string> GetPersonInCharges(ProjectSeriesLogicModel projectSeriesLogicModel, int projectId) { var adminUserNames = projectSeriesLogicModel.CurrentProject.Team.Chiefs.Select(x => x.UserName).ToList(); var teamMembers = m_dbAdapter.TeamMember.GetByProjectId(projectId); var teamMemberUserNames = teamMembers.Select(x => x.UserName).ToList(); var teamAdmins = m_dbAdapter.TeamAdmin.GetByProjectId(projectId); var teamAdminUserNames = teamAdmins.Select(x => x.UserName).ToList(); var allUserNames = new List <string>(); allUserNames.AddRange(adminUserNames); allUserNames.AddRange(teamAdminUserNames); allUserNames.AddRange(teamMemberUserNames); allUserNames = allUserNames.Distinct(StringComparer.OrdinalIgnoreCase).ToList(); return(allUserNames); }
public ActionResult RemoveTeamMembers(string projectSeriesGuid, string userNames) { return(ActionUtils.Json(() => { var projectSeriesLogicModel = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid); var project = projectSeriesLogicModel.CurrentProject.Instance; CommUtils.Assert(IsAdmin(projectSeriesLogicModel.Instance, CurrentUserName) || m_dbAdapter.TeamAdmin.IsTeamAdmin(project.ProjectId, CurrentUserName), "当前用户[{0}]不是项目[{1}]的创建者/负责人/管理员", Platform.UserProfile.GetDisplayRealNameAndUserName(CurrentUserName), projectSeriesLogicModel.Instance.Name); var teamMembers = m_dbAdapter.TeamMember.GetByProjectId(project.ProjectId); var userNameList = CommUtils.Split(userNames).ToList(); foreach (var userName in userNameList) { CommUtils.Assert(teamMembers.Any(x => x.UserName.Equals(userName, StringComparison.CurrentCultureIgnoreCase)), "查找项目成员[{0}]失败", userName); CommUtils.Assert((!IsAdmin(projectSeriesLogicModel.Instance, userName)) && (!m_dbAdapter.TeamAdmin.IsTeamAdmin(project.ProjectId, userName)), "检测到[{0}]是产品创建者/负责人,移除项目成员失败", userName); } var projectActivityLogicModel = projectSeriesLogicModel.CurrentProject.Activity; teamMembers = teamMembers.Where(x => userNameList.Contains(x.UserName)).ToList(); foreach (var teamMember in teamMembers) { m_dbAdapter.TeamMember.Remove(teamMember); projectActivityLogicModel.Add(project.ProjectId, ActivityObjectType.TeamMember, teamMember.Guid, "删除项目成员:" + Platform.UserProfile.Get(teamMember.UserName).RealName); } var permissionLogicModel = new PermissionLogicModel(CurrentUserName, projectSeriesLogicModel.Instance); permissionLogicModel.RemoveUserPermissionByProjectSeries(userNameList); return ActionUtils.Success(1); })); }
public ActionResult GetTeamMembers(string projectSeriesGuid) { return(ActionUtils.Json(() => { var projectSeriesLogicModel = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid); var projectSeries = projectSeriesLogicModel.Instance; var project = projectSeriesLogicModel.CurrentProject.Instance; CheckPermission(PermissionObjectType.Project, project.ProjectGuid, PermissionType.Read); var logicModel = projectSeriesLogicModel.CurrentProject; var adminUserNames = logicModel.Team.Chiefs.Select(x => x.UserName).ToList(); var projectId = project.ProjectId; var teamAdmins = m_dbAdapter.TeamAdmin.GetByProjectId(projectId); var teamAdminUserNames = teamAdmins.Select(x => x.UserName).ToList(); var teamMembers = m_dbAdapter.TeamMember.GetByProjectId(projectId); var teamMemberUserNames = teamMembers.Select(x => x.UserName).ToList(); var allUserNames = new List <string>(); allUserNames.AddRange(adminUserNames); allUserNames.AddRange(teamAdminUserNames); allUserNames.AddRange(teamMemberUserNames); allUserNames = allUserNames.Distinct(StringComparer.OrdinalIgnoreCase).ToList(); Platform.UserProfile.Precache(allUserNames); //管理员的权限从数据库中取得 var dictPermissions = m_dbAdapter.Permission.GetAllPermission(adminUserNames, projectSeriesGuid); var dictTeamAdminPermissions = m_dbAdapter.Permission.GetAllPermission(teamAdminUserNames, projectSeriesGuid); var result = new TeamMemberListViewModel(); var personInCharge = Platform.UserProfile.Get(projectSeries.PersonInCharge); if (personInCharge != null) { result.PersonInCharge = new TeamMemberViewModel(personInCharge); if (IsAdmin(projectSeries)) { result.PersonInCharge.Permission.Set(dictPermissions[result.PersonInCharge.UserName.ToLower()]); } } var creator = Platform.UserProfile.Get(projectSeries.CreateUserName); if (creator != null) { result.Creator = new TeamMemberViewModel(creator); if (IsAdmin(projectSeries)) { result.Creator.Permission.Set(dictPermissions[result.Creator.UserName.ToLower()]); } } result.TeamMembers = teamMembers.ConvertAll(x => { var teamMember = new TeamMemberViewModel(Platform.UserProfile.Get(x.UserName)); teamMember.Permission.Set(x.Read, x.Write, x.Execute); return teamMember; }).OrderBy(x => x.RealName, CommUtils.StringComparerCN).ThenBy(x => x.UserName).ToList(); result.TeamAdmins = teamAdmins.ConvertAll(x => { var teamMember = new TeamMemberViewModel(Platform.UserProfile.Get(x.UserName)); teamMember.Permission.Set(dictTeamAdminPermissions[teamMember.UserName.ToLower()]); return teamMember; }).OrderBy(x => x.RealName, CommUtils.StringComparerCN).ThenBy(x => x.UserName).ToList(); return ActionUtils.Success(result); })); }
public ActionResult ModifyProjectSeriesInfo(string projectSeriesGuid, string name, string projectSeriesType, string personInCharge, string createTime, string estimatedFinishTime, string email) { return(ActionUtils.Json(() => { ValidateUtils.Name(name, "项目名称"); CommUtils.Assert(email.Length <= 38, "名称不能超过38个字符数"); CommUtils.AssertHasContent(personInCharge, "[项目负责人]不能为空"); CommUtils.Assert(m_dbAdapter.Authority.IsUserExist(personInCharge), "[用户]不存在"); CommUtils.AssertHasContent(createTime, "[立项日期]不能为空"); CommUtils.AssertHasContent(estimatedFinishTime, "[计划完成日期]不能为空"); var valStartTime = DateTime.Parse(createTime); var valEstimatedFinishTime = DateTime.Parse(estimatedFinishTime); CommUtils.Assert(valEstimatedFinishTime >= valStartTime, "计划完成日期[{0}]必须大于等于立项日期[{1}]", valEstimatedFinishTime, valStartTime); var type = CommUtils.ParseEnum <ProjectSeriesType>(projectSeriesType); var projectSeriesLogicModel = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid); var projectSeries = projectSeriesLogicModel.Instance; var project = projectSeriesLogicModel.CurrentProject.Instance; CommUtils.Assert(IsCurrentUser(projectSeries.CreateUserName) || IsCurrentUser(projectSeries.PersonInCharge) || m_dbAdapter.TeamAdmin.IsTeamAdmin(project.ProjectId, CurrentUserName), "当前用户[{0}]不是项目[{1}]的管理员/创建者/负责人,无法进行修改", CurrentUserName, projectSeries.Name); CommUtils.Assert(!m_dbAdapter.TeamAdmin.IsTeamAdmin(project.ProjectId, CurrentUserName) || personInCharge == projectSeries.PersonInCharge, "当前用户[{0}]是项目[{1}]的管理员,无法修改负责人", CurrentUserName, projectSeries.Name); var isAdmin = projectSeries.CreateUserName.Equals(personInCharge, StringComparison.CurrentCultureIgnoreCase) || projectSeries.PersonInCharge.Equals(personInCharge, StringComparison.CurrentCultureIgnoreCase); ////////////// var permissionLogicModel = new PermissionLogicModel(CurrentUserName, projectSeries); var teamAdmins = m_dbAdapter.TeamAdmin.GetByProjectId(project.ProjectId); var teamMembers = m_dbAdapter.TeamMember.GetByProjectId(project.ProjectId); var teamMember = new TeamMember { UserName = projectSeries.PersonInCharge, ProjectId = project.ProjectId, Read = true, Write = false, Execute = false }; if (!isAdmin) { if (!projectSeries.CreateUserName.Equals(projectSeries.PersonInCharge, StringComparison.CurrentCultureIgnoreCase)) { //删除原有负责人的所有权限,将其添加为项目成员 permissionLogicModel.RemoveUserPermissionByProjectSeries(new List <string> { projectSeries.PersonInCharge }); m_dbAdapter.TeamMember.Add(teamMember); permissionLogicModel.AddUserPermissionByProjectSeries(new List <TeamMember> { teamMember }, new List <TeamAdmin>(), new List <string>()); } foreach (var item in teamMembers) { //如果新的负责人为原有的项目成员,则在项目成员里移除 if (item.UserName.Equals(personInCharge, StringComparison.CurrentCultureIgnoreCase)) { m_dbAdapter.TeamMember.Remove(item); permissionLogicModel.RemoveUserPermissionByProjectSeries(new List <string> { personInCharge }); } } foreach (var item in teamAdmins) { //如果新的负责人为原有的项目管理员,则在项目管理员里移除 if (item.UserName.Equals(personInCharge, StringComparison.CurrentCultureIgnoreCase)) { m_dbAdapter.TeamAdmin.Delete(item); permissionLogicModel.RemoveUserPermissionByProjectSeries(new List <string> { personInCharge }); } } permissionLogicModel.AddUserPermissionByProjectSeries(new List <TeamMember>(), new List <TeamAdmin>(), new List <string> { personInCharge }); } else { if (!projectSeries.PersonInCharge.Equals(personInCharge, StringComparison.CurrentCultureIgnoreCase)) { //删除原有负责人的所有权限,将其添加为项目成员 permissionLogicModel.RemoveUserPermissionByProjectSeries(new List <string> { projectSeries.PersonInCharge }); m_dbAdapter.TeamMember.Add(teamMember); permissionLogicModel.AddUserPermissionByProjectSeries(new List <TeamMember> { teamMember }, new List <TeamAdmin>(), new List <string>()); } } //同步产品系列名字与产品名字一致 if (projectSeries.Name != name) { project.Name = name; m_dbAdapter.Project.Update(project); } projectSeries.Name = name; projectSeries.Type = type; projectSeries.CreateTime = valStartTime; projectSeries.EstimatedFinishTime = valEstimatedFinishTime; projectSeries.PersonInCharge = personInCharge; projectSeries.Email = email; m_dbAdapter.ProjectSeries.UpdateProjectSeries(projectSeries); return ActionUtils.Success(1); })); }
public ActionResult GetProjectSeriesList(int filterByCreatedDays = -1, string filterByStage = "") { return(ActionUtils.Json(() => { //Check param filterByStage var stages = new List <ProjectSeriesStage>(); if (!string.IsNullOrEmpty(filterByStage)) { stages = filterByStage.Split('|').ToList().ConvertAll(x => CommUtils.ParseEnum <ProjectSeriesStage>(x)); } var uids = m_dbAdapter.Permission.GetObjectUids(CurrentUserName, PermissionObjectType.ProjectSeries, PermissionType.Read); var projectSeriesList = m_dbAdapter.ProjectSeries.GetByGuids(uids); projectSeriesList = projectSeriesList.OrderBy(x => x.EstimatedFinishTime).ThenBy(x => x.CreateTime).ToList(); var projectSeriesLogicModelList = projectSeriesList.Where(x => { if (filterByCreatedDays >= 0 && (DateTime.Now - x.CreateTime).TotalDays > filterByCreatedDays) { return false; } if (!string.IsNullOrEmpty(filterByStage)) { return stages.Contains(x.Stage); } return true; }).ToList().ConvertAll(x => new ProjectSeriesLogicModel(CurrentUserName, x)); var dict = new Dictionary <string, string>(); var dictStatus = new Dictionary <string, string>(); //已完成工作数,未完成工作数,成员数(包含创建者、负责人) var dictTaskCount = new Dictionary <string, Tuple <int, int> >(); var dictPersonCount = new Dictionary <string, int>(); foreach (var projectSeriesLogicModel in projectSeriesLogicModelList) { var projectSeries = projectSeriesLogicModel.Instance; dictStatus[projectSeries.Guid] = "准备"; dict[projectSeries.Guid] = "0.00%"; dictTaskCount[projectSeries.Guid] = new Tuple <int, int>(0, 0); var allMembers = new List <string>(); if (projectSeriesLogicModel.CurrentProject != null) { projectSeriesLogicModel.CurrentProject.Team.Chiefs.Select(x => x.UserName).ToList(); } var logicModel = new ProjectSeriesLogicModel(CurrentUserName, projectSeries); if (logicModel.CurrentProject != null) { var project = logicModel.CurrentProject.Instance; var teamMembers = m_dbAdapter.TeamMember.GetByProjectId(project.ProjectId); var teamMemberUserNames = teamMembers.Select(x => x.UserName).ToList(); var teamAdmins = m_dbAdapter.TeamAdmin.GetByProjectId(project.ProjectId); var teamAdminUserNames = teamAdmins.Select(x => x.UserName).ToList(); allMembers.AddRange(teamMemberUserNames); allMembers.AddRange(teamAdminUserNames); var tasks = m_dbAdapter.Task.GetTasksByProjectId(project.ProjectId); var finishedTaskCount = tasks.Count(x => x.TaskStatus == TaskStatus.Finished); if (tasks.Count != 0) { dict[projectSeries.Guid] = CommUtils.Percent(finishedTaskCount, tasks.Count); dictStatus[projectSeries.Guid] = finishedTaskCount == 0 ? "准备" : (finishedTaskCount == tasks.Count ? "完成" : "进行中"); dictTaskCount[projectSeries.Guid] = new Tuple <int, int>(finishedTaskCount, tasks.Count); } } allMembers = allMembers.Distinct(StringComparer.OrdinalIgnoreCase).ToList(); dictPersonCount[projectSeries.Guid] = allMembers.Count; } var allUserNames = projectSeriesLogicModelList.Select(x => x.Instance.PersonInCharge) .Concat(projectSeriesLogicModelList.Select(x => x.Instance.CreateUserName)).Distinct(StringComparer.OrdinalIgnoreCase).ToArray(); var nicknames = UserService.GetNicknames(allUserNames); var result = projectSeriesLogicModelList.ConvertAll(logicModel => { var x = logicModel.Instance; return new { name = x.Name, guid = x.Guid, type = x.Type.ToString(), personInCharge = new { userName = x.PersonInCharge, realName = nicknames.ContainsKey(x.Name) ? nicknames[x.Name] : x.Name, }, createUser = new { userName = x.CreateUserName, realName = nicknames.ContainsKey(x.Name) ? nicknames[x.Name] : x.Name, }, isCreator = IsCurrentUser(x.CreateUserName), createTimeStamp = x.CreateTime.ToString("yyyy-MM-dd"), estimatedFinishTime = Toolkit.DateToString(x.EstimatedFinishTime), remainingDayCount = x.EstimatedFinishTime.HasValue ? ((int)(x.EstimatedFinishTime.Value - DateTime.Today).TotalDays).ToString() : "-", percentCompleted = dict[x.Guid], finishedTaskCount = dictTaskCount[x.Guid].Item1, taskCount = dictTaskCount[x.Guid].Item2, status = dictStatus[x.Guid], stage = x.Stage.ToString(), currentProjectGuid = (logicModel.CurrentProject == null ? "" : logicModel.CurrentProject.Instance.ProjectGuid), permission = new { write = m_dbAdapter.Permission.HasPermission(CurrentUserName, x.Guid, PermissionType.Write) }, personCount = dictPersonCount[x.Guid], }; }); return ActionUtils.Success(result); })); }
public ActionResult AddTeamAdmins(string projectSeriesGuid, string userNames) { return(ActionUtils.Json(() => { //判断操作者权限 var projectSeriesLogicModel = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid); CommUtils.Assert(IsAdmin(projectSeriesLogicModel.Instance, CurrentUserName), "当前用户[{0}]不是项目[{1}]的创建者/负责人", Platform.UserProfile.GetDisplayRealNameAndUserName(CurrentUserName), projectSeriesLogicModel.Instance.Name); //判断传入userName是否有效 var userNameList = CommUtils.Split(userNames); foreach (var userName in userNameList) { CommUtils.Assert(m_dbAdapter.Authority.IsUserExist(userName), "用户[{0}]不存在", userName); CommUtils.Assert(!IsAdmin(projectSeriesLogicModel.Instance, userName), "用户[{0}]是产品创建者/负责人,无法增加至项目管理员", userName); } //判断项目管理员是否已经添加 var project = projectSeriesLogicModel.CurrentProject.Instance; var teamAdmins = m_dbAdapter.TeamAdmin.GetByProjectId(project.ProjectId); foreach (var teamAdmin in teamAdmins) { CommUtils.Assert(!userNameList.Contains(teamAdmin.UserName), "项目管理员中已经存在用户[{0}]", teamAdmin.UserName); } var projectActivityLogicModel = projectSeriesLogicModel.CurrentProject.Activity; //添加项目管理员 var teamMemberList = m_dbAdapter.TeamMember.GetByProjectId(project.ProjectId); var teamMemberDic = teamMemberList.ToDictionary(x => x.UserName); var teamMembeUserNames = teamMemberList.Select(x => x.UserName).ToList(); foreach (var userName in userNameList) { var teamAdmin = new TeamAdmin { UserName = userName, ProjectId = project.ProjectId }; m_dbAdapter.TeamAdmin.New(teamAdmin); projectActivityLogicModel.Add(project.ProjectId, ActivityObjectType.TeamAdmin, teamAdmin.Guid, "增加项目管理员:" + Platform.UserProfile.Get(teamAdmin.UserName).RealName); if (teamMembeUserNames.Contains(userName)) { m_dbAdapter.TeamMember.Remove(teamMemberDic[userName]); } } var teamMembers = new List <TeamMember>(); teamAdmins = m_dbAdapter.TeamAdmin.GetByProjectId(project.ProjectId); var newTeamAdmins = teamAdmins.Where(x => userNameList.Contains(x.UserName)).ToList(); var adminUserNames = new List <string>(); var permissionLogicModel = new PermissionLogicModel(CurrentUserName, projectSeriesLogicModel.Instance); permissionLogicModel.AddUserPermissionByProjectSeries(teamMembers, newTeamAdmins, adminUserNames); return ActionUtils.Success(1); })); }
public ActionResult ImportTable(string projectSeriesGuid) { return(ActionUtils.Json(() => { var projectSeriesLogicModel = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid); var project = projectSeriesLogicModel.CurrentProject.Instance; CheckPermission(PermissionObjectType.Project, project.ProjectGuid, PermissionType.Write); var file = Request.Files[0]; byte[] bytes = new byte[file.InputStream.Length]; file.InputStream.Read(bytes, 0, bytes.Length); file.InputStream.Seek(0, SeekOrigin.Begin); Stream newStream = new MemoryStream(bytes); var tableHeaderRowsCount = ExcelUtils.GetTableHeaderRowsCount(newStream, 0, 0, tableHeader); var table = ExcelUtils.ParseExcel(file.InputStream, 0, tableHeaderRowsCount, 0, 9); var validation = new ExcelValidation(); validation.Add(CellRange.Column(0), new CellTextValidation(1, 30)); validation.Add(CellRange.Column(1), new CellTextValidation(1, 500)); validation.Add(CellRange.Column(2), new CellTextValidation(1, 30)); validation.Add(CellRange.Column(3), new CellDateValidation()); validation.Add(CellRange.Column(4), new CellDateValidation(false)); //检查工作状态 Func <string, string> checkTaskStatus = (cellText) => { if (!string.IsNullOrWhiteSpace(cellText) && cellText != "-" && cellText != TranslateUtils.ToCnString(TaskStatus.Waitting) && cellText != TranslateUtils.ToCnString(TaskStatus.Overdue)) { return "导入工作的工作状态只能为空、[等待]或[逾期]"; } return string.Empty; }; validation.Add(CellRange.Column(5), new CellCustomValidation(checkTaskStatus)); //检查负责人 int projectId = project.ProjectId; var personInCharges = GetPersonInCharges(projectSeriesLogicModel, projectId); Func <List <string>, string, string> checkPersonInCharge = (personInChargeList, cellText) => { var userName = GetPersonInCharge(cellText); if (!personInChargeList.Contains(userName)) { return "负责人[" + cellText + "]不存在"; } return string.Empty; }; validation.Add(CellRange.Column(6), new CellCustomValidation(checkPersonInCharge, personInCharges)); //不检查只有taskGroup列,其他列均为空的行 var columns = new List <CellRange>() { CellRange.Column(2), CellRange.Column(3), CellRange.Column(4), CellRange.Column(5), CellRange.Column(6), CellRange.Column(7), CellRange.Column(8) }; Func <string, bool> ExceptCondition = (x) => { return x != string.Empty; }; validation.JudgeColumn = new ColumnJudge(columns, ExceptCondition); //检查开始时间是否大于截止时间 Func <object, object, string> lessThanOrEqualTo = (left, right) => { var leftText = left.ToString(); var rightText = right.ToString(); if (!string.IsNullOrWhiteSpace(leftText) && leftText != "-") { var startTime = DateTime.Parse(leftText); var endTime = DateTime.Parse(rightText); if (startTime > endTime) { return "开始时间[" + leftText + "]不能大于结束时间[" + rightText + "]"; } } return string.Empty; }; validation.CompareColumn = new ColumnComparison(CellRange.Column(3), CellRange.Column(4), lessThanOrEqualTo); validation.Check(table, tableHeaderRowsCount); //创建taskGroups List <TaskGroup> newTaskGroups = new List <TaskGroup>(); for (int iRow = 0; iRow < table.Count; iRow++) { var row = table[iRow]; var taskGroup = ParseTaskGroups(newTaskGroups, row, iRow, projectId); if (taskGroup != null) { newTaskGroups.Add(taskGroup); } } var projectLogicModel = new ProjectLogicModel(CurrentUserName, project); var permissionLogicModel = new PermissionLogicModel(projectLogicModel); var projectSeries = projectSeriesLogicModel.Instance; newTaskGroups.ForEach(x => { var taskGroup = m_dbAdapter.TaskGroup.NewTaskGroup(x.ProjectId, x.Name, x.Description); permissionLogicModel.SetPermission(projectSeries, project, taskGroup.Guid, PermissionObjectType.TaskGroup); projectLogicModel.Activity.Add(x.ProjectId, ActivityObjectType.TaskGroup, taskGroup.Guid, "新建工作组:" + taskGroup.Name); }); //创建tasks var taskGroups = m_dbAdapter.TaskGroup.GetByProjectId(projectId); var dicTaskGroups = taskGroups.ToDictionary(x => x.Name); List <Task> tasks = new List <Task>(); for (int iRow = 0; iRow < table.Count; iRow++) { var row = table[iRow].ToList(); if (row.Count > 2 && (!string.IsNullOrWhiteSpace(row[2].ToString())) && row[2].ToString() != "-") { var taskGroup = dicTaskGroups[row[0].ToString()]; tasks.Add(ParseTasks(row, iRow, taskGroup.Id, project)); } } tasks.ForEach(x => m_dbAdapter.Task.NewTask(x)); Dictionary <string, string> msgDic = new Dictionary <string, string>(); foreach (var task in tasks) { var msg = string.Format("创建task:shortCode={0};name={1};startTime={2};endTime={3};personInCharge={4};" + "taskStatus={5};taskTarget={6};taskDetail={7};projectId={8};projectName={9};taskGroupId={10}", task.ShortCode, task.Description, task.StartTime, task.EndTime, task.PersonInCharge, task.TaskStatus, task.TaskTarget, task.TaskDetail, task.ProjectId, task.ProjectName, task.TaskGroupId); msgDic[task.ShortCode] = msg; } tasks.ForEach(x => { permissionLogicModel.SetPermission(projectSeries, project, x.ShortCode, PermissionObjectType.Task); projectLogicModel.Activity.Add(projectId, ActivityObjectType.Task, x.ShortCode, "创建工作:" + x.Description); m_dbAdapter.Project.NewEditProductLog(EditProductType.CreateTask, x.ProjectId, msgDic[x.ShortCode], ""); }); var result = new { taskGroupCount = newTaskGroups.Count, taskCount = tasks.Count }; return ActionUtils.Success(result); })); }
public ActionResult ResetAllTeamMemberPermission(string projectSeriesGuid) { return(ActionUtils.Json(() => { //获取所有有读取权限的用户 var projectSeriesLogicModel = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid); var project = projectSeriesLogicModel.CurrentProject.Instance; CommUtils.Assert(IsAdmin(projectSeriesLogicModel.Instance, CurrentUserName) || m_dbAdapter.TeamAdmin.IsTeamAdmin(project.ProjectId, CurrentUserName), "当前用户[{0}]不是项目[{1}]的创建者/负责人/管理员", Platform.UserProfile.GetDisplayRealNameAndUserName(CurrentUserName), projectSeriesLogicModel.Instance.Name); //只保留项目成员 var projectSeries = projectSeriesLogicModel.Instance; var permissionList = m_dbAdapter.Permission.GetByObjectUid(projectSeriesGuid, PermissionObjectType.ProjectSeries, PermissionType.Read); var userNames = permissionList.Select(x => x.UserName).Distinct(StringComparer.OrdinalIgnoreCase).ToList(); userNames.RemoveAll(x => IsAdmin(projectSeries, x) || m_dbAdapter.TeamAdmin.IsTeamAdmin(project.ProjectId, x)); //从TeamMember表中移除没有读取权限的成员 var teamMembers = m_dbAdapter.TeamMember.GetByProjectId(project.ProjectId); foreach (var teamMember in teamMembers) { if (!userNames.Contains(teamMember.UserName)) { m_dbAdapter.TeamMember.Remove(teamMember); } } //增加有读取权限的成员到TeamMember中 foreach (var userName in userNames) { if (!teamMembers.Any(x => x.UserName.Equals(userName, StringComparison.CurrentCultureIgnoreCase))) { var teamMember = new TeamMember { UserName = userName, ProjectId = project.ProjectId, Read = true, Write = false, Execute = false }; m_dbAdapter.TeamMember.Add(teamMember); } } //获取管理员(负责人 + 创建者) var adminUserNames = new List <string> { projectSeries.CreateUserName, projectSeries.PersonInCharge }; adminUserNames = adminUserNames.Distinct(StringComparer.OrdinalIgnoreCase).ToList(); //获取所有项目成员 teamMembers = m_dbAdapter.TeamMember.GetByProjectId(project.ProjectId); var teamAdmins = m_dbAdapter.TeamAdmin.GetByProjectId(project.ProjectId); var permissionLogicModel = new PermissionLogicModel(CurrentUserName, projectSeriesLogicModel.Instance); permissionLogicModel.AddUserPermissionByProjectSeries(teamMembers, teamAdmins, adminUserNames); return ActionUtils.Success(1); })); }
public ActionResult AddTeamMembers(string projectSeriesGuid, string userNames, string permissions) { return(ActionUtils.Json(() => { CommUtils.Assert(!string.IsNullOrWhiteSpace(permissions), "权限类型不能为空"); var permissionList = CommUtils.ParseEnumList <PermissionType>(permissions, true); CommUtils.Assert(permissionList.Any(x => x == PermissionType.Read), "增加项目成员时,只读权限必须勾选"); //判断操作者权限 var projectSeriesLogicModel = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid); var project = projectSeriesLogicModel.CurrentProject.Instance; CommUtils.Assert(IsAdmin(projectSeriesLogicModel.Instance, CurrentUserName) || m_dbAdapter.TeamAdmin.IsTeamAdmin(project.ProjectId, CurrentUserName), "当前用户[{0}]不是项目[{1}]的创建者/负责人/管理员", Platform.UserProfile.GetDisplayRealNameAndUserName(CurrentUserName), projectSeriesLogicModel.Instance.Name); //判断传入userName是否有效 var userNameList = CommUtils.Split(userNames); foreach (var userName in userNameList) { CommUtils.Assert(m_dbAdapter.Authority.IsUserExist(userName), "用户[{0}]不存在", userName); CommUtils.Assert((!IsAdmin(projectSeriesLogicModel.Instance, userName)) && (!m_dbAdapter.TeamAdmin.IsTeamAdmin(project.ProjectId, userName)), "用户[{0}]是产品创建者/负责人/管理员,无法增加至项目成员", userName); } //判断项目成员是否已经添加 var teamMembers = m_dbAdapter.TeamMember.GetByProjectId(project.ProjectId); foreach (var teamMember in teamMembers) { CommUtils.Assert(!userNameList.Contains(teamMember.UserName), "项目成员中已经存在用户[{0}]", teamMember.UserName); } var projectActivityLogicModel = projectSeriesLogicModel.CurrentProject.Activity; //添加项目成员 foreach (var userName in userNameList) { var teamMember = new TeamMember { UserName = userName, ProjectId = project.ProjectId, Read = permissionList.Any(x => x == PermissionType.Read), Write = permissionList.Any(x => x == PermissionType.Write), Execute = permissionList.Any(x => x == PermissionType.Execute) }; m_dbAdapter.TeamMember.Add(teamMember); projectActivityLogicModel.Add(project.ProjectId, ActivityObjectType.TeamMember, teamMember.Guid, "增加项目成员:" + Platform.UserProfile.Get(teamMember.UserName).RealName); } teamMembers = m_dbAdapter.TeamMember.GetByProjectId(project.ProjectId); var newTeamMembers = teamMembers.Where(x => userNameList.Contains(x.UserName)).ToList(); var adminUserNames = new List <string>(); var teamAdmins = new List <TeamAdmin>(); var permissionLogicModel = new PermissionLogicModel(CurrentUserName, projectSeriesLogicModel.Instance); permissionLogicModel.AddUserPermissionByProjectSeries(newTeamMembers, teamAdmins, adminUserNames); return ActionUtils.Success(1); })); }
public ActionResult ExportTable(string projectSeriesGuid) { return(ActionUtils.Json(() => { var projectSeries = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid); var project = projectSeries.CurrentProject.Instance; CheckPermission(PermissionObjectType.Project, project.ProjectGuid, PermissionType.Read); var taskGroups = projectSeries.CurrentProject.TaskGroups; var allPermissionTaskGroupUid = m_dbAdapter.Permission.GetObjectUids(CurrentUserName, PermissionObjectType.TaskGroup, PermissionType.Read).ToDictionary(x => x); var hasPermissionTaskGroups = taskGroups.Where(x => allPermissionTaskGroupUid.ContainsKey(x.Instance.Guid)).ToList(); var tableDic = new Dictionary <TaskGroup, List <Task> >(); var tasks = new List <Task>(); var projectLogicModel = new ProjectLogicModel(CurrentUserName, project); hasPermissionTaskGroups.ForEach(x => { var taskGroupLogicModel = projectLogicModel.TaskGroups.Single(y => y.Instance.Guid == x.Instance.Guid); var allPermissionTaskUid = m_dbAdapter.Permission.GetObjectUids(CurrentUserName, PermissionObjectType.Task, PermissionType.Read).ToDictionary(y => y); var hasPermissionTasks = taskGroupLogicModel.Tasks.Where(y => allPermissionTaskUid.ContainsKey(y.ShortCode)).ToList(); tableDic.Add(x.Instance, hasPermissionTasks); tasks.AddRange(hasPermissionTasks); }); var personInCharges = tasks.Where(x => !string.IsNullOrWhiteSpace(x.PersonInCharge)).Select(x => x.PersonInCharge); Platform.UserProfile.Precache(personInCharges); var table = new DataTable(); table.Columns.Add("工作组名称", typeof(System.String)); table.Columns.Add("工作组描述", typeof(System.String)); table.Columns.Add("工作名称", typeof(System.String)); table.Columns.Add("开始时间", typeof(System.String)); table.Columns.Add("截止时间", typeof(System.String)); table.Columns.Add("工作状态", typeof(System.String)); table.Columns.Add("负责人", typeof(System.String)); table.Columns.Add("工作目标", typeof(System.String)); table.Columns.Add("工作描述", typeof(System.String)); foreach (var taskGroupName in tableDic.Keys) { if (tableDic[taskGroupName].Count == 0) { var row = table.NewRow(); row["工作组名称"] = taskGroupName.Name; row["工作组描述"] = taskGroupName.Description; row["工作名称"] = string.Empty; row["开始时间"] = string.Empty; row["截止时间"] = string.Empty; row["工作状态"] = string.Empty; row["负责人"] = string.Empty; row["工作目标"] = string.Empty; row["工作描述"] = string.Empty; table.Rows.Add(row); } else { foreach (var task in tableDic[taskGroupName]) { var row = table.NewRow(); row["工作组名称"] = taskGroupName.Name; row["工作组描述"] = taskGroupName.Description; row["工作名称"] = task.Description; row["开始时间"] = Toolkit.DateToString(task.StartTime); row["截止时间"] = Toolkit.DateToString(task.EndTime); row["工作状态"] = string.IsNullOrWhiteSpace(task.TaskStatus.ToString()) || task.TaskStatus.ToString() == "-"? task.TaskStatus.ToString() : TranslateUtils.ToCnString(CommUtils.ParseEnum <TaskStatus>(task.TaskStatus.ToString())); row["负责人"] = string.IsNullOrWhiteSpace(task.PersonInCharge) ? string.Empty : Platform.UserProfile.Get(task.PersonInCharge).RealName + "(" + Platform.UserProfile.Get(task.PersonInCharge).UserName + ")"; row["工作目标"] = task.TaskTarget; row["工作描述"] = task.TaskDetail; table.Rows.Add(row); } } } var taskStatusIndex = table.Columns.IndexOf("工作状态"); var sheet = new Sheet("TaskGroupTable", table); sheet.SheetStyle.Add(new CellRangeStyle() { Range = CellRange.Column(taskStatusIndex), Style = new CellRangeStyleTaskStatus(), Rule = CellRangeRule.IgnoreEmptyCell }); var workbook = new Workbook("TaskGroupTable", sheet); var resource = workbook.ToExcel(CurrentUserName); return ActionUtils.Success(resource.Guid); })); }