public async Task <InitWorkFlowOutput> Create(CreateEmployeeAdjustPostInput input) { var user = await base.GetCurrentUserAsync(); var userPost = _userPostRepository.FirstOrDefault(x => x.UserId == user.Id); if (userPost == null) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "当前登录账户没有部门和岗位信息,无法发起调岗申请。"); } if ((await _repository.CountAsync(x => !x.IsDeleted && x.CreatorUserId == user.Id && x.Status != -1 && x.Status != -2)) > 0) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "你尚有其他调岗申请未结束,无法发起新的调岗申请。"); } if (await _organizationUnitPostsRepository.CountAsync(x => x.Id == input.AdjustPostId) == 0) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "没有找到您选择的岗位。"); } var nowpost = _userPostRepository.GetAll().FirstOrDefault(ite => ite.UserId == user.Id && ite.OrgPostId == input.AdjustPostId); if (nowpost != null) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "你已经在该岗位了,不能再次调入哦。"); } var newmodel = new EmployeeAdjustPost() { Remark = input.Remark, OriginalDepId = userPost.OrgId, OriginalPostId = userPost.PostId, WorkflowAdjsutDepId = input.AdjustDepId, AdjustDepId = Convert.ToInt32(MemberPerfix.RemovePrefix(input.AdjustDepId)?.Split(',')[0]), AdjustPostId = input.AdjustPostId }; if (await _organizeRepository.CountAsync(x => x.Id == newmodel.AdjustDepId) == 0) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "没有找到您选择的部门。"); } //input.AdjustDepId //input.AdjustPostId await _repository.InsertAsync(newmodel); return(new InitWorkFlowOutput() { InStanceId = newmodel.Id.ToString() }); }
/// <summary> /// 修改一个EmployeeAdjustPost /// </summary> /// <param name="input">实体</param> /// <returns></returns> public async Task Update(UpdateEmployeeAdjustPostInput input) { if (input.Id != Guid.Empty) { var dbmodel = await _repository.FirstOrDefaultAsync(x => x.Id == input.Id); if (dbmodel == null) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "该数据不存在。"); } var logModel = new EmployeeAdjustPost(); if (input.IsUpdateForChange) { logModel = dbmodel.DeepClone <EmployeeAdjustPost>(); } var AdjustDepId = Convert.ToInt32(MemberPerfix.RemovePrefix(input.AdjustDepId)?.Split(',')[0]); if (await _organizeRepository.CountAsync(x => x.Id == AdjustDepId) == 0) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "没有找到您选择的岗位。"); } dbmodel.Remark = input.Remark; dbmodel.WorkflowAdjsutDepId = input.AdjustDepId; dbmodel.AdjustDepId = Convert.ToInt32(MemberPerfix.RemovePrefix(input.AdjustDepId)?.Split(',')[0]); dbmodel.AdjustPostId = input.AdjustPostId; await _repository.UpdateAsync(dbmodel); if (input.IsUpdateForChange) { var flowModel = _workFlowCacheManager.GetWorkFlowModelFromCache(input.FlowId); if (flowModel == null) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "流程不存在"); } var logs = GetChangeModel(logModel).GetColumnAllLogs(GetChangeModel(dbmodel)); await _projectAuditManager.InsertAsync(logs, input.Id.ToString(), flowModel.TitleField.Table); } } else { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "该数据不存在。"); } }
/// <summary> /// 根据条件分页获取列表 /// </summary> /// <param name="page">查询实体</param> /// <returns></returns> public async Task <PagedResultDto <TrainUserExperienceListOutputDto> > GetListByUser(GetTrainUserExperienceListInput input) { var users = new List <long>(); var organizeManager = Abp.AbpBootstrapper.Create <Abp.Modules.AbpModule>().IocManager.IocContainer.Resolve <WorkFlowOrganizationUnitsManager>(); var train = _trainRepository.GetAll().FirstOrDefault(x => x.Id == input.TrainId); var arr = train.JoinUser.Split(','); foreach (var item in arr) { var userId = Convert.ToInt64(item.Replace("u_", "")); var organUser = organizeManager.GetChargeLeader(userId); var lId = !string.IsNullOrEmpty(organUser) ? MemberPerfix.RemovePrefix(organUser).ToLong() : 0; if (lId == AbpSession.UserId.Value) { users.Add(userId); } } var query = from a in _repository.GetAll().Where(x => !x.IsDeleted && x.TrainId == input.TrainId && x.Type == TrainExperienceType.Train && users.Contains(x.UserId)) join b in _userRepository.GetAll() on a.UserId equals b.Id select new TrainUserExperienceListOutputDto() { Id = a.Id, UserId = a.UserId, UserName = b.Name, TrainId = a.TrainId, Experience = a.Experience, Approval = a.Approval, CreationTime = a.CreationTime }; var toalCount = await query.CountAsync(); var ret = await query.OrderByDescending(r => r.CreationTime).PageBy(input).ToListAsync(); return(new PagedResultDto <TrainUserExperienceListOutputDto>(toalCount, ret)); }
/// <summary> /// 新增或编辑工程评审人员 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task CreateProjectAuditMembersV2(CreateProjectAuditMemberV2Input input) { var baseinfo = _projectBaseRepository.Get(input.ProjectId); baseinfo.HasFinancialReview = input.HasFinancialReview; //原来的 var oldaudit = _projectAuditMemberRepository.GetAll().Where(ite => ite.ProjectBaseId == input.ProjectId && (ite.UserAuditRole == (int)AuditRoleEnum.工程评审 || ite.UserAuditRole == (int)AuditRoleEnum.汇总人员)).ToList(); var shouldadd = input.Members.Where(r => !r.Id.HasValue && (r.AuditRoleId == (int)AuditRoleEnum.工程评审 || r.AuditRoleId == (int)AuditRoleEnum.汇总人员)).ToList(); var shouldupdate = input.Members.Where(r => r.Id.HasValue && (r.AuditRoleId == (int)AuditRoleEnum.工程评审 || r.AuditRoleId == (int)AuditRoleEnum.汇总人员)).ToList(); var shoulddel_Ids = oldaudit.Select(r => r.Id).ToList().Except(shouldupdate.Select(r => r.Id.Value).ToList()).ToList(); //删除 shoulddel_Ids.ForEach(ite => { var deleModel = oldaudit.FirstOrDefault(r => r.Id == ite); _projectAuditMemberRepository.Delete(deleModel); if (deleModel.UserAuditRole == (int)AuditRoleEnum.工程评审) { var finishsAllots = _projectPersentFinishAllotRepository.GetAll().Where(r => r.AuditMembeId == deleModel.Id); if (finishsAllots.Count() > 0) { finishsAllots.ForEachAsync(r => { _projectPersentFinishAllotRepository.Delete(r); _projectPersentFinishRepository.Delete(r.FinishId); }); } } }); //更新 shouldupdate.ForEach(ite => { var a = oldaudit.First(it => it.Id == ite.Id); //a.FinishItems = ite.FinishItems; a.WorkDays = ite.WorkDays; a.WorkDes = ite.WorkDes; a.Percentes = ite.Percentes; a.Des = ite.Des; _projectAuditMemberRepository.Update(a); }); //新增 shouldadd.ForEach(ite => { var newMember = new ProjectAuditMember() { Id = Guid.NewGuid(), UserAuditRole = ite.AuditRoleId, ProjectBaseId = input.ProjectId, UserId = ite.UserId, WorkDays = ite.WorkDays, WorkDes = ite.WorkDes, Percentes = ite.Percentes, Des = ite.Des }; _projectAuditMemberRepository.Insert(newMember); if (ite.AuditRoleId == (int)AuditRoleEnum.工程评审) { var finishId = Guid.NewGuid(); var finishModel = new ProjectPersentFinish() { Id = finishId, ProjectId = input.ProjectId }; var finishAllotModel = new ProjectPersentFinishAllot() { Id = Guid.NewGuid(), FinishId = finishId, AuditMembeId = newMember.Id, ProjectId = input.ProjectId, IsMain = true }; _projectPersentFinishRepository.Insert(finishModel); _projectPersentFinishAllotRepository.Insert(finishAllotModel); } }); #region 对财务评审人员的更新 var inputgroupMemberList = new List <CreateOrUpdateProjectAuditMembersInput>(); if (input.HasFinancialReview) { if (input.OrgFinancial1 == 0 || input.OrgFinancial2 == 0) { throw new UserFriendlyException((int)ErrorCode.CodeValErr, "财务评审人员未指定"); } var orgmodel = _workFlowOrganizationUnitsRepository.Get(input.OrgFinancial1); if (orgmodel.ChargeLeader.IsNullOrWhiteSpace()) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "财务初审部门未指定分管领导"); } var chargeleader = MemberPerfix.RemovePrefix(orgmodel.ChargeLeader).ToLong(); var exit_Financial1Member = await _projectAuditMemberRepository.FirstOrDefaultAsync(r => r.ProjectBaseId == input.ProjectId && r.UserAuditRole == (int)AuditRoleEnum.财务初审); if (exit_Financial1Member != null) { exit_Financial1Member.FlowId = input.OrgFinancial1.ToString(); exit_Financial1Member.UserId = chargeleader; } else { var entity = new CreateOrUpdateProjectAuditMembersInput() { UserAuditRole = (int)AuditRoleEnum.财务初审, UserId = chargeleader, FlowId = input.OrgFinancial1.ToString(), ProjectBaseId = input.ProjectId }; inputgroupMemberList.Add(entity); } var orgmodel2 = _workFlowOrganizationUnitsRepository.Get(input.OrgFinancial2); if (orgmodel2.ChargeLeader.IsNullOrWhiteSpace()) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "财务终审部门未指定分管领导"); } var chargeleader2 = MemberPerfix.RemovePrefix(orgmodel2.ChargeLeader).ToLong(); var exit_Financial2Member = await _projectAuditMemberRepository.FirstOrDefaultAsync(r => r.ProjectBaseId == input.ProjectId && r.UserAuditRole == (int)AuditRoleEnum.财务评审); if (exit_Financial2Member != null) { exit_Financial2Member.FlowId = input.OrgFinancial2.ToString(); exit_Financial2Member.UserId = chargeleader2; } else { var entity = new CreateOrUpdateProjectAuditMembersInput() { UserAuditRole = (int)AuditRoleEnum.财务评审, UserId = chargeleader2, FlowId = input.OrgFinancial2.ToString(), ProjectBaseId = input.ProjectId }; inputgroupMemberList.Add(entity); } } else { if (await _projectAuditMemberRepository.GetAll().AnyAsync(r => r.ProjectBaseId == input.ProjectId && r.UserAuditRole == (int)AuditRoleEnum.财务初审)) { await _projectAuditMemberRepository.DeleteAsync(r => r.ProjectBaseId == input.ProjectId && r.UserAuditRole == (int)AuditRoleEnum.财务初审); } if (await _projectAuditMemberRepository.GetAll().AnyAsync(r => r.ProjectBaseId == input.ProjectId && r.UserAuditRole == (int)AuditRoleEnum.财务评审)) { await _projectAuditMemberRepository.DeleteAsync(r => r.ProjectBaseId == input.ProjectId && r.UserAuditRole == (int)AuditRoleEnum.财务评审); } } foreach (var item in inputgroupMemberList) { _projectAuditMemberRepository.Insert(item.MapTo <ProjectAuditMember>()); } #endregion }
/// <summary> /// 根据条件分页获取列表 /// </summary> /// <param name="page">查询实体</param> /// <returns></returns> public async Task <PagedResultDto <EmployeeProposalListOutputDto> > GetList(GetEmployeeProposalListInput input) { var user = await base.GetCurrentUserAsync(); var userId = user.Id.ToString(); var queryBase = from a in _repository.GetAll().Where(x => !x.IsDeleted) select a; if (input.Type != null) { queryBase = queryBase.Where(x => x.Type == input.Type); } var query = from a in queryBase.Where(x => x.CreatorUserId == user.Id ) let openModel = (from c in _workFlowTaskRepository.GetAll().Where(x => x.FlowID == input.FlowId && x.InstanceID == a.Id.ToString() && x.ReceiveID == AbpSession.UserId.Value) select c) select new EmployeeProposalListOutputDto() { Id = a.Id, Title = a.Title, CreationTime = a.CreationTime, ParticipateUser = a.ParticipateUser, Status = a.Status ?? 0, OpenModel = openModel.Count(y => y.Type != 6 && (y.Status == 1 || y.Status == 0)) > 0 ? 1 : 2 }; if (input.showMyCase == 1) { query = from a in queryBase.Where(x => (x.DealWithUsers.GetStrContainsArray(userId) || x.CopyForUsers.GetStrContainsArray(userId)) ) let openModel = (from c in _workFlowTaskRepository.GetAll().Where(x => x.FlowID == input.FlowId && x.InstanceID == a.Id.ToString() && x.ReceiveID == AbpSession.UserId.Value) select c) select new EmployeeProposalListOutputDto() { Id = a.Id, // DepartmentInfos = post, Title = a.Title, CreationTime = a.CreationTime, Status = a.Status ?? 0, OpenModel = a.Status > -1 && openModel.Count(y => y.Type != 6 && (y.Status == 1 || y.Status == 0)) > 0 ? 1 : 2 }; } var toalCount = await query.CountAsync(); var ret = await query.OrderBy(r => r.OpenModel).ThenByDescending(r => r.CreationTime).PageBy(input).ToListAsync(); var result = ret.MapTo <List <EmployeeProposalListOutputDto> >(); foreach (var item in result) { item.InstanceId = item.Id.ToString(); _workFlowBusinessTaskManager.SupplementWorkFlowBusinessList(input.FlowId, item); if (input.showMyCase == 0) { if (!string.IsNullOrEmpty(item.ParticipateUser)) { //默认取第一个收件人 var Postuser = Convert.ToInt32(MemberPerfix.RemovePrefix(item.ParticipateUser)?.Split(',')[0]); item.UserName = _workFlowOrganizationUnitsManager.GetNames(item.ParticipateUser); var userOrgModel = await _unitsAppService.GetUserPostInfo( new NullableIdDto <long>() { Id = Postuser, }, new NullableIdDto <long>() { Id = null }); if (userOrgModel != null) { item.DepartmentName = userOrgModel.OrgId_Name; item.PostName = userOrgModel.UserPosts.FirstOrDefault()?.PostName; } } } else { var a = _repository.FirstOrDefault(x => x.Id == item.Id); var departinfo = ( from b in UserManager.Users.Where(x => x.Id == a.CreatorUserId) join c1 in _userOrganizeRepository.GetAll().DefaultIfEmpty() on b.Id equals c1.UserId into tmp1 from c in tmp1.DefaultIfEmpty() join e1 in _organizeRepository.GetAll().DefaultIfEmpty() on c.OrganizationUnitId equals e1.Id into tmp3 from e in tmp3.DefaultIfEmpty() join d1 in _userPostRepository.GetAll().DefaultIfEmpty() on b.Id equals d1.UserId into tmp2 from d in tmp2.DefaultIfEmpty() join f1 in _postRepository.GetAll().DefaultIfEmpty() on d.PostId equals f1.Id into tmp4 from f in tmp4.DefaultIfEmpty() select new DepartmentInfo { WorkNumber = b.WorkNumber, Name = b.Name, PhoneNumber = b.PhoneNumber, DepartmentName = e == null ? "" : e.DisplayName, PostName = f == null ? "" : f.Name } ).ToList(); item.DepartmentName = departinfo.FirstOrDefault()?.DepartmentName; item.PostName = departinfo.FirstOrDefault()?.PostName; item.WorkNumber = departinfo.FirstOrDefault()?.WorkNumber; item.UserName = departinfo.FirstOrDefault()?.Name; item.PhoneNumber = departinfo.FirstOrDefault()?.PhoneNumber; } } return(new PagedResultDto <EmployeeProposalListOutputDto>(toalCount, result)); }
public async Task UpdateAsync(CreateOrUpdateProjectMemberInput input) { var singleProjectModel = await _singleProjectRepository.GetAsync(input.ProjectId); if (singleProjectModel == null) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "项目不存在"); } var exit_allot = await _projectPersentFinishAllotRepository.GetAll().Where(r => r.ProjectId == input.ProjectId).ToListAsync(); foreach (var item in exit_allot) { await _projectPersentFinishAllotRepository.DeleteAsync(item); } var exit_Finishs = await _projectPersentFinishRepository.GetAll().Where(r => r.ProjectId == input.ProjectId).ToListAsync(); foreach (var item in exit_Finishs) { await _projectPersentFinishRepository.DeleteAsync(item); } var exit_memebers = await _projectAuditMemberRepository.GetAll().Where(r => r.ProjectBaseId == input.ProjectId && r.UserAuditRole == 2).ToListAsync(); foreach (var item in exit_memebers) { await _projectAuditMemberRepository.DeleteAsync(item); } foreach (var item in input.Members) { var entity = new ProjectAuditMember(); entity.UserAuditRole = item.AuditRoleId; entity.Id = Guid.NewGuid(); entity.ProjectBaseId = input.ProjectId; entity.UserId = item.UserId; await _projectAuditMemberRepository.InsertAsync(entity); item.Id = entity.Id; } var auditUsers = input.Members.Where(r => r.AuditRoleId == (int)AuditRoleEnum.工程评审); var allfinishmerber = new List <long>();//所有事项的参与人 foreach (var item in input.Finishs) { allfinishmerber = allfinishmerber.Union(item.FinishMembers.Select(ite => ite.UserId)).ToList(); var entity = new ProjectPersentFinish(); entity.Id = Guid.NewGuid(); entity.Name = item.Name; entity.ProjectId = input.ProjectId; entity.Industry = ""; entity.Persent = item.Persent; entity.WorkDay = item.WorkDay; await _projectPersentFinishRepository.InsertAsync(entity); foreach (var entity_user in item.FinishMembers) { var allot = new ProjectPersentFinishAllot(); allot.Id = Guid.NewGuid(); allot.FinishId = entity.Id; allot.IsMain = entity_user.IsMain; allot.ProjectId = input.ProjectId; var auditMember = auditUsers.FirstOrDefault(r => r.UserId == entity_user.UserId); if (auditMember == null) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "评审事务人员分派异常"); } allot.AuditMembeId = auditMember.Id.Value; await _projectPersentFinishAllotRepository.InsertAsync(allot); } } var re = auditUsers.Select(ite => ite.UserId).Except(allfinishmerber);//验证分派的评审人员必须都分派有事项。 if (re != null && re.Count() > 0) { var unames = new List <string>(); foreach (var u in re) { unames.Add(_userRepository.Get(u).Name); } var str = string.Join("、", unames); throw new UserFriendlyException((int)ErrorCode.DataAccessErr, $"【工程评审】人员“{str}”还未安排事项。"); } CurrentUnitOfWork.SaveChanges(); #region 对财务评审人员的更新 singleProjectModel.HasFinancialReview = input.HasFinancialReview; var inputgroupMemberList = new List <CreateOrUpdateProjectAuditMembersInput>(); if (input.HasFinancialReview) { if (input.OrgFinancial1 == 0 || input.OrgFinancial2 == 0) { throw new UserFriendlyException((int)ErrorCode.CodeValErr, "财务评审人员未指定"); } var orgmodel = _workFlowOrganizationUnitsRepository.Get(input.OrgFinancial1); if (orgmodel.ChargeLeader.IsNullOrWhiteSpace()) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "财务初审部门未指定分管领导"); } var t = orgmodel.ChargeLeader.Split(",", StringSplitOptions.RemoveEmptyEntries);//部门领导可能有多个 foreach (var x in t) { var chargeleader = MemberPerfix.RemovePrefix(x).ToLong(); var exit_Financial1Member = await _projectAuditMemberRepository.FirstOrDefaultAsync(r => r.ProjectBaseId == input.ProjectId && r.UserAuditRole == (int)AuditRoleEnum.财务初审); if (exit_Financial1Member != null) { exit_Financial1Member.FlowId = input.OrgFinancial1.ToString(); exit_Financial1Member.UserId = chargeleader; } else { var entity = new CreateOrUpdateProjectAuditMembersInput() { UserAuditRole = (int)AuditRoleEnum.财务初审, UserId = chargeleader, FlowId = input.OrgFinancial1.ToString(), ProjectBaseId = input.ProjectId }; inputgroupMemberList.Add(entity); } } var orgmodel2 = _workFlowOrganizationUnitsRepository.Get(input.OrgFinancial2); if (orgmodel2.ChargeLeader.IsNullOrWhiteSpace()) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "财务终审部门未指定分管领导"); } var t2 = orgmodel2.ChargeLeader.Split(",", StringSplitOptions.RemoveEmptyEntries);//部门领导可能有多个 foreach (var x in t2) { var chargeleader2 = MemberPerfix.RemovePrefix(x).ToLong(); var exit_Financial2Member = await _projectAuditMemberRepository.FirstOrDefaultAsync(r => r.ProjectBaseId == input.ProjectId && r.UserAuditRole == (int)AuditRoleEnum.财务评审); if (exit_Financial2Member != null) { exit_Financial2Member.FlowId = input.OrgFinancial2.ToString(); exit_Financial2Member.UserId = chargeleader2; } else { var entity = new CreateOrUpdateProjectAuditMembersInput() { UserAuditRole = (int)AuditRoleEnum.财务评审, UserId = chargeleader2, FlowId = input.OrgFinancial2.ToString(), ProjectBaseId = input.ProjectId }; inputgroupMemberList.Add(entity); } } } else { if (await _projectAuditMemberRepository.GetAll().AnyAsync(r => r.ProjectBaseId == input.ProjectId && r.UserAuditRole == (int)AuditRoleEnum.财务初审)) { await _projectAuditMemberRepository.DeleteAsync(r => r.ProjectBaseId == input.ProjectId && r.UserAuditRole == (int)AuditRoleEnum.财务初审); } if (await _projectAuditMemberRepository.GetAll().AnyAsync(r => r.ProjectBaseId == input.ProjectId && r.UserAuditRole == (int)AuditRoleEnum.财务评审)) { await _projectAuditMemberRepository.DeleteAsync(r => r.ProjectBaseId == input.ProjectId && r.UserAuditRole == (int)AuditRoleEnum.财务评审); } } foreach (var item in inputgroupMemberList) { _projectAuditMemberRepository.Insert(item.MapTo <ProjectAuditMember>()); } #endregion }
public async Task UpdateProjectAuditMembers(ManagerProjectAuditMembersInput input) { var baseinfo = _projectBaseRepository.Get(input.ProjectId); var inputgroupMemberList = new List <CreateOrUpdateProjectAuditMembersInput>(); var inputgroup = input.ProjectAuditMembersInput.FirstOrDefault(r => r.IsGroup); if (inputgroup != null) { var groupService = Abp.AbpBootstrapper.Create <Abp.Modules.AbpModule>() .IocManager.IocContainer.Resolve <IProjectAuditGroupAppService>(); var groupModel = await groupService.GetProjectAuditGroupForEdit(new NullableIdDto <Guid>() { Id = inputgroup.GroupId }); if (groupModel != null) { var groupUserCharge = groupModel.Users.FirstOrDefault(r => r.UserRole == (int)ProjectAuditGroupRoleEnum.项目负责人); if (groupUserCharge != null) { var entity = new CreateOrUpdateProjectAuditMembersInput() { UserAuditRole = 1, IsGroup = true, UserId = groupUserCharge.UserId, GroupId = groupUserCharge.GroupId, ProjectBaseId = input.ProjectId }; var entityFH2 = new CreateOrUpdateProjectAuditMembersInput() { UserAuditRole = (int)AuditRoleEnum.核人三, IsGroup = true, UserId = groupUserCharge.UserId, GroupId = groupUserCharge.GroupId, ProjectBaseId = input.ProjectId }; inputgroupMemberList.Add(entity); inputgroupMemberList.Add(entityFH2); } var groupUserContact1 = groupModel.Users.FirstOrDefault(r => r.UserRole == (int)ProjectAuditGroupRoleEnum.联系人一); if (groupUserContact1 != null) { var entity = new CreateOrUpdateProjectAuditMembersInput() { UserAuditRole = (int)AuditRoleEnum.联系人一, IsGroup = true, UserId = groupUserContact1.UserId, GroupId = groupUserContact1.GroupId, ProjectBaseId = input.ProjectId }; inputgroupMemberList.Add(entity); } var groupUserContact2 = groupModel.Users.FirstOrDefault(r => r.UserRole == (int)ProjectAuditGroupRoleEnum.联系人二); if (groupUserContact2 != null) { var entity = new CreateOrUpdateProjectAuditMembersInput() { UserAuditRole = (int)AuditRoleEnum.联系人二, IsGroup = true, UserId = groupUserContact2.UserId, GroupId = groupUserContact2.GroupId, ProjectBaseId = input.ProjectId }; inputgroupMemberList.Add(entity); } input.ProjectAuditMembersInput.Remove(inputgroup); input.ProjectAuditMembersInput.AddRange(inputgroupMemberList); } } //原来的 var oldaudit = _projectAuditMemberRepository.GetAll().Where(ite => ite.ProjectBaseId == input.ProjectId).ToList(); var shouldadd = input.ProjectAuditMembersInput.Where(r => !r.Id.HasValue).ToList(); var shouldupdate = input.ProjectAuditMembersInput.Where(r => r.Id.HasValue).ToList(); var shoulddel_Ids = oldaudit.Select(r => r.Id).ToList().Except(shouldupdate.Select(r => r.Id.Value).ToList()).ToList(); //删除 shoulddel_Ids.ForEach(ite => { var deleModel = oldaudit.FirstOrDefault(r => r.Id == ite); _projectAuditMemberRepository.Delete(deleModel); if (deleModel.UserAuditRole == (int)AuditRoleEnum.工程评审 || deleModel.UserAuditRole == (int)AuditRoleEnum.财务评审) { var finishsAllots = _projectPersentFinishAllotRepository.GetAll().Where(r => r.AuditMembeId == deleModel.Id); if (finishsAllots.Count() > 0) { finishsAllots.ForEachAsync(r => { _projectPersentFinishAllotRepository.Delete(r); _projectPersentFinishRepository.Delete(r.FinishId); }); } } }); //更新 shouldupdate.ForEach(ite => { var a = oldaudit.First(it => it.Id == ite.Id); a.AappraisalFileTypes = ite.AappraisalFileTypes; //a.FinishItems = ite.FinishItems; a.WorkDays = ite.WorkDays; a.WorkDes = ite.WorkDes; a.GroupId = ite.GroupId; if (a.UserAuditRole == (int)AuditRoleEnum.财务初审) ///财务初审 通过orgid 找到部门的分管领导的userid; orgidxieru flowid { var orgmodel = _workFlowOrganizationUnitsRepository.Get(ite.UserId); if (orgmodel.ChargeLeader.IsNullOrWhiteSpace()) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "财务初审部门未指定分管领导"); } var chargeleader = MemberPerfix.RemovePrefix(orgmodel.ChargeLeader).ToLong(); ite.UserId = chargeleader; ite.FlowId = orgmodel.Id.ToString(); } _projectAuditMemberRepository.Update(a); //if (string.IsNullOrWhiteSpace(ite.FinishItems) == false) //{ // //var ids = ite.FinishItems.Split(','); // var ids = Array.ConvertAll(ite.FinishItems.Split(','), new Converter<string, Guid>(Guid.Parse)); // var items = _projectPersentFinishRepository.GetAll().Where(it => ids.Contains(it.Id)).ToList(); // var allpersent = items.Sum(it => it.Persent); // foreach (var id in ids) // { // var finishitem = _projectPersentFinishRepository.Get(id); // if (finishitem != null && finishitem.Name == "熟悉图纸") // { // double day = (double)(finishitem.Persent / allpersent) * ite.WorkDays.Value; // _projectNoticeRepository.Insert(new ProjectNotice() // { // Content = "", // FinishTime = DateTime.Now.AddDays(day), // FinishId = id, // ProjectId = input.BaseId.Value, // UserId = ite.UserId // }); // _backgroundWorkJobProjectPersentFinish.CreateJobForProjectPersentFinishSubmit( // input.BaseId.Value, id); // } // } //} }); //新增 shouldadd.ForEach(ite => { ite.Id = Guid.NewGuid(); ite.ProjectBaseId = input.ProjectId; if (ite.UserAuditRole == (int)AuditRoleEnum.工程评审) { var finishId = Guid.NewGuid(); var finishModel = new ProjectPersentFinish() { Id = finishId, ProjectId = input.ProjectId }; var finishAllotModel = new ProjectPersentFinishAllot() { Id = Guid.NewGuid(), FinishId = finishId, AuditMembeId = ite.Id.Value, ProjectId = input.ProjectId, IsMain = true }; _projectPersentFinishRepository.Insert(finishModel); _projectPersentFinishAllotRepository.Insert(finishAllotModel); } else if (ite.UserAuditRole == (int)AuditRoleEnum.财务初审) ///财务初审 通过orgid 找到部门的分管领导的userid; orgidxieru flowid { var orgmodel = _workFlowOrganizationUnitsRepository.Get(ite.UserId); if (orgmodel.ChargeLeader.IsNullOrWhiteSpace()) { throw new UserFriendlyException((int)ErrorCode.DataAccessErr, "财务初审部门未指定分管领导"); } var chargeleader = MemberPerfix.RemovePrefix(orgmodel.ChargeLeader).ToLong(); ite.UserId = chargeleader; ite.FlowId = orgmodel.Id.ToString(); } _projectAuditMemberRepository.Insert(ite.MapTo <ProjectAuditMember>()); }); if (input.ProjectAuditMembersInput.Any(r => r.UserAuditRole == (int)AuditRoleEnum.财务评审)) { baseinfo.HasFinancialReview = true; //await _projectBaseRepository.UpdateAsync(baseinfo); } //baseinfo.ProjectStatus = ProjectStatus.在审; }