Ejemplo n.º 1
0
        /// <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
        }
Ejemplo n.º 2
0
        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.在审;
        }