Example #1
0
        public int Add(AddMonthlyPlanInput input)
        {
            var userId = _authInfoProvider.GetCurrent().User.Id;

            if (!_projectHelper.HasPermission("项目计划负责人", input.ProjectId))//权限设置
            {
                throw new AppCoreException("月计划发布没有权限");
            }
            var plan = input.MapTo <MonthlyPlan>();

            if (plan.RecordDate == null)
            {
                throw new AppCoreException("传入数据的RecordTime不能为空");
            }
            if (plan.ProjectId == 0)
            {
                throw new AppCoreException("传入数据的ProjectId不能为空");
            }
            if (_planRepository.Count(u => u.ProjectId == plan.ProjectId && u.RecordDate == plan.RecordDate) > 0)
            {
                throw new EntityException("RecordDate", plan.RecordDate.ToString("y"), "InvestmentMonthlyPlan", "已存在");
            }
            _planRepository.Add(plan);
            return(plan.Id);
        }
Example #2
0
        public int Add(StartProcessInput <AddRecordInput> input)
        {
            NullableHelper.SetNull(input.Data);
            var variables = new Dictionary <string, object>();
            var userId    = _authInfoProvider.GetCurrent().User.Id;

            variables.Add("starter", userId.ToString());
            int processInstanceId = _runtimeProvider.StartProcessInstanceByName(
                input.ProcessDefinitionName,
                $"{input.ProcessDefinitionName}-{input.Data.RecordName}",
                variables);
            var tasks = _taskProvider.GetByProcessInstance(processInstanceId);

            if (tasks.Count == 0)
            {
                throw new AppCoreException("任务未创建成功!");
            }
            var record = input.Data.MapTo <Record>();

            record.ProcessInstanceId = processInstanceId;
            record.DataState         = DataState.Creating;
            record.Mid = null;
            _recordRepository.Add(record);
            var task = tasks[0];

            if (!input.PreventCommit)
            {
                _taskProvider.Complete(task.Id);
            }
            return(record.Id);
        }
Example #3
0
        public int Add(StartProcessInput <AddProjectInput> input)
        {
            NullableHelper.SetNull(input.Data);
            var variables = new Dictionary <string, object>();
            var userId    = _authInfoProvider.GetCurrent().User.Id;

            variables.Add("starter", userId.ToString());
            int processInstanceId = _runtimeProvider.StartProcessInstanceByName(
                input.ProcessDefinitionName,
                $"{input.ProcessDefinitionName}-{input.Data.Name}",
                variables);
            var tasks = _taskProvider.GetByProcessInstance(processInstanceId);

            if (tasks.Count == 0)
            {
                throw new AppCoreException("任务未创建成功!");
            }
            var project = input.Data.MapTo <Project>();
            var count   = ProjectContext.Instance.GetProjectBaseInfoNoCount(() => _projectRepository.Count(u => u.CreateTime.Value.Year == DateTime.Now.Year && (u.DataState == DataState.Stable || u.DataState == DataState.Creating)));

            project.ProcessInstanceId = processInstanceId;
            project.DataState         = DataState.Creating;
            project.No  = $"{DateTime.Now.Year}{count.ToString("0000")}";
            project.Mid = null;
            _projectRepository.Add(project);
            var task = tasks[0];

            if (!input.PreventCommit)
            {
                _taskProvider.Complete(task.Id);
            }
            return(project.Id);
        }
Example #4
0
        public bool HasPermission(string role, int projectId)
        {
            var userId = _authInfoProvider.GetCurrent().User.Id;
            var list   = _projectRepository.Get().Where(u => u.Id == projectId).SelectMany(u => u.Members).Where(u => u.ProjectRole == role).Select(u => u.UserId).ToList();

            if (!list.Contains(userId))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Example #5
0
        public PaginationData <GetProcessDefinitionListOutput> Get(int pageIndex, int pageSize, string keyword, Expression <Func <Wf_Re_ProcessDefinition, bool> > extraCondition)
        {
            var userId           = _authInfoProvider.GetCurrent().User.Id;
            var queryForUserRole = _userRepository.Get().Where(u => u.Id == userId).SelectMany(u => u.UserRoles);
            var queryForRolePf   = _roleProcessDefinitionRepository.Get().Where(u => queryForUserRole.Any(v => v.RoleId == u.RoleId));
            var query            = _processDefinitionRepository.Get().Where(u => u.CreatorId == userId || queryForRolePf.Any(v => v.ProcessDefinitionId == u.Id));

            if (!string.IsNullOrEmpty(keyword))
            {
                query = query.Where(u => u.Name.Contains(keyword) || u.Category.Contains(keyword) || u.Description.Contains(keyword));
            }
            if (extraCondition != null)
            {
                query = query.Where(extraCondition);
            }
            query = query.GroupBy(u => u.Name).Select(u => u.OrderByDescending(v => v.Version).First());
            var queryForRolePfAll = _roleProcessDefinitionRepository.Get();
            var queryJoinRole     = query.GroupJoin(queryForRolePfAll, u => u.Id, v => v.ProcessDefinitionId, (u, v) => new ProcessDefinitionWithRole {
                ProcessDefinition = u, RoleNames = v.Select(w => w.Role.Name)
            });

            return(PaginationDataHelper.WrapData(queryJoinRole, pageIndex, pageSize, u => u.ProcessDefinition.CreateTime).TransferTo <GetProcessDefinitionListOutput>(
                       u =>
            {
                var output = u.ProcessDefinition.MapTo <GetProcessDefinitionListOutput>();
                output.Remark = string.Join(",", u.RoleNames);
                return output;
            }
                       ));
        }
Example #6
0
        public int Add(StartProcessInput <AddConstructionUnitInput> input)
        {
            if (input.Data.Name == null)
            {
                throw new AppCoreException("单位名称不能为空");
            }
            var variables = new Dictionary <string, object>();
            var userId    = _authInfoProvider.GetCurrent().User.Id;

            variables.Add("starter", userId.ToString());
            int processInstanceId = _runtimeProvider.StartProcessInstanceByName(
                input.ProcessDefinitionName,
                $"{input.ProcessDefinitionName}-{input.Data.Name}",
                variables);
            var tasks = _taskProvider.GetByProcessInstance(processInstanceId);

            if (tasks.Count == 0)
            {
                throw new AppCoreException("任务未创建成功!");
            }
            var constructionUnit = input.Data.MapTo <ConstructionUnit>();

            // var count = AppSampleContext.Instance.GetSupplierNoCount(() => _supplierRepository.Count(u => u.CreateTime.Value.Year == DateTime.Now.Year && (u.State == DataState.Stable || u.State == DataState.Creating)));
            constructionUnit.ProcessInstanceId = processInstanceId;
            constructionUnit.State             = DataState.Creating;
            // constructionUnit.SupplierNo = $"{DateTime.Now.Year}{count.ToString("000000")}";
            constructionUnit.Mid = null;
            _constructionUnitRepository.Add(constructionUnit);
            var task = tasks[0];

            _taskProvider.Complete(task.Id);
            return(constructionUnit.Id);
        }
Example #7
0
        public int Add(StartProcessInput <AddWeeklyProgressInput> input)
        {
            NullableHelper.SetNull(input.Data);
            var variables = new Dictionary <string, object>();
            var userId    = _authInfoProvider.GetCurrent().User.Id;

            if (!_projectHelper.HasPermission("进度填报负责人", input.Data.ProjectId))
            {
                throw new AppCoreException("进度填报没有权限");
            }

            variables.Add("starter", userId.ToString());
            int processInstanceId = _runtimeProvider.StartProcessInstanceByName(
                input.ProcessDefinitionName,
                $"{input.ProcessDefinitionName}-{input.Data.AddDate}",
                variables);
            var tasks = _taskProvider.GetByProcessInstance(processInstanceId);

            if (tasks.Count == 0)
            {
                throw new AppCoreException("任务未创建成功!");
            }
            var progress = input.Data.MapTo <WeeklyProgress>();

            if (progress.ProjectId == 0)
            {
                throw new AppCoreException("传入数据的ProjectId不能为空");
            }
            //if(_progressRepository.Count(u=>u.ProjectId == progress.ProjectId && u.Week == progress.Week && u.Year == progress.Year) > 0)
            //{
            //    throw new EntityException("Week", progress.Week, "PmWeeklyReport", "已存在");
            //}
            progress.ProcessInstanceId = processInstanceId;
            progress.DataState         = DataState.Creating;
            progress.Mid = null;
            _progressRepository.Add(progress);
            var task = tasks[0];

            if (!input.PreventCommit)
            {
                _taskProvider.Complete(task.Id);
            }
            return(progress.Id);
        }
Example #8
0
        private string Build(int id, int version = 1, string controller = "files")
        {
            var uid  = Guid.NewGuid().ToString("N");
            var info = new StoreInfo {
                ObjectId = id, AuthInfo = _authInfoProvider.GetCurrent()
            };

            AppWebContext.Instance.Cache.Add(uid, info, PoorFff.Cache.ExpiredTimeType.FixedExpiration, new TimeSpan(5, 0, 0));
            return($"{AppWebContext.Instance.Domain}/api/v{version}/{controller}/{uid}/data");
        }
Example #9
0
        public int Add(StartProcessInput <AddContractPaymentInput> input)
        {
            if (input.Data.ContractId == 0)
            {
                throw new AppCoreException("合同id不能为0");
            }
            var variables = new Dictionary <string, object>();
            var userId    = _authInfoProvider.GetCurrent().User.Id;

            variables.Add("starter", userId.ToString());
            int processInstanceId = _runtimeProvider.StartProcessInstanceByName(
                input.ProcessDefinitionName,
                $"{input.ProcessDefinitionName}",//-{input.Data.Title}
                variables);
            var tasks = _taskProvider.GetByProcessInstance(processInstanceId);

            if (tasks.Count == 0)
            {
                throw new AppCoreException("任务未创建成功!");
            }

            var contractPayment = input.Data.MapTo <ContractPayment>();

            // var count = AppSampleContext.Instance.GetSupplierNoCount(() => _supplierRepository.Count(u => u.CreateTime.Value.Year == DateTime.Now.Year && (u.State == DataState.Stable || u.State == DataState.Creating)));
            contractPayment.ProcessInstanceId = processInstanceId;
            contractPayment.State             = DataState.Creating;
            // memorabiliaRecord.SupplierNo = $"{DateTime.Now.Year}{count.ToString("000000")}";
            var paymentNumberPrefix = $"CP{DateTime.Now.ToString("yyyyMMdd")}";
            var count = _contractPaymentRepository.Count(u => u.PaymentNumber.Contains(paymentNumberPrefix) && (u.State == DataState.Stable || u.State == DataState.Creating));

            contractPayment.PaymentNumber = $"{paymentNumberPrefix}{count.ToString("00")}";
            contractPayment.Mid           = null;
            _contractPaymentRepository.Add(contractPayment);
            var task = tasks[0];

            if (!input.PreventCommit)
            {
                _taskProvider.Complete(task.Id);
            }
            return(contractPayment.Id);
        }
Example #10
0
        public void CompleteTask(CompleteTaskInput input)
        {
            var authInfo = _authInfoProvider.GetCurrent();
            var userId   = authInfo?.User?.Id;
            var task     = _taskProvider.GetTask(input.Id);

            if (task.Assignee != userId.Value.ToString())
            {
                throw new AppCoreException($"id:为{userId.Value}的用户不是任务【{task.NodeName}】的委托人");
            }
            if (input.FormContents.Count > 0)
            {
                _taskProvider.SetFields(input.Id, input.FormContents);
            }
            if (!input.PreventCommit)
            {
                _taskProvider.Complete(input.Id, input.Comment);
            }
        }
Example #11
0
        public List <GetCalendarListOutput> Get()
        {
            var userId = _authInfoProvider.GetCurrent()?.User?.Id ?? 0;
            IQueryable <Calendar> query = null;
            var privilegedPersonIds     = _privilegedPersonRepository.Get().Where(u => u.ModuleName == "日程备忘录").Select(u => u.UserId).ToList(); //特权人列表

            if (privilegedPersonIds.Contains(userId))                                                                                           //当前用户是否特权人
            {
                query = _calendarRepository.Get();
            }
            else
            {
                query = _calendarRepository.Get().Where(u => u.CreatorId == userId);
            }
            return(query.MapToList <GetCalendarListOutput>());
        }
Example #12
0
        public int Add(StartProcessInput <AddHousekeepingProblemInput> input)
        {
            if (input.Data.ProjectId == 0)
            {
                throw new AppCoreException("文明施工所在项目不能为0");
            }
            var variables = new Dictionary <string, object>();
            var userId    = _authInfoProvider.GetCurrent().User.Id;

            // var list = _projectRepository.Get().Where(u => u.Id == input.Data.ProjectId).SelectMany(u => u.Members).Where(u => u.ProjectRole == "文明施工负责人").Select(u => u.UserId).ToList();
            if (!_projectHelper.HasPermission("文明施工负责人", input.Data.ProjectId))//权限设置
            {
                throw new AppCoreException("文明施工发布没有权限");
            }
            variables.Add("starter", userId.ToString());
            int processInstanceId = _runtimeProvider.StartProcessInstanceByName(
                input.ProcessDefinitionName,
                $"{input.ProcessDefinitionName}-{input.Data.Content}",
                variables);
            var tasks = _taskProvider.GetByProcessInstance(processInstanceId);

            if (tasks.Count == 0)
            {
                throw new AppCoreException("任务未创建成功!");
            }
            var problem = input.Data.MapTo <HousekeepingProblem>();

            // var count = AppSampleContext.Instance.GetSupplierNoCount(() => _supplierRepository.Count(u => u.CreateTime.Value.Year == DateTime.Now.Year && (u.State == DataState.Stable || u.State == DataState.Creating)));
            problem.ProcessInstanceId = processInstanceId;
            problem.State             = DataState.Creating;
            // memorabiliaRecord.SupplierNo = $"{DateTime.Now.Year}{count.ToString("000000")}";
            problem.Mid = null;
            _problemRepository.Add(problem);
            var task = tasks[0];

            if (!input.PreventCommit)
            {
                _taskProvider.Complete(task.Id);
            }
            return(problem.Id);
        }
Example #13
0
        public int Add(StartProcessInput <AddQualityProblemInput> input)
        {
            if (input.Data.Source == null)
            {
                throw new AppCoreException("质量问题来源不能为空");
            }
            var variables = new Dictionary <string, object>();
            var userId    = _authInfoProvider.GetCurrent().User.Id;

            if (!_projectHelper.HasPermission("质量信息负责人", input.Data.ProjectId))//权限设置
            {
                throw new AppCoreException("质量问题发布没有权限");
            }
            variables.Add("starter", userId.ToString());
            int processInstanceId = _runtimeProvider.StartProcessInstanceByName(
                input.ProcessDefinitionName,
                $"{input.ProcessDefinitionName}-{input.Data.Source}",
                variables);
            var tasks = _taskProvider.GetByProcessInstance(processInstanceId);

            if (tasks.Count == 0)
            {
                throw new AppCoreException("任务未创建成功!");
            }
            var qualityProblem = input.Data.MapTo <QualityProblem>();

            // var count = AppSampleContext.Instance.GetSupplierNoCount(() => _supplierRepository.Count(u => u.CreateTime.Value.Year == DateTime.Now.Year && (u.State == DataState.Stable || u.State == DataState.Creating)));
            qualityProblem.ProcessInstanceId = processInstanceId;
            qualityProblem.State             = DataState.Creating;
            // memorabiliaRecord.SupplierNo = $"{DateTime.Now.Year}{count.ToString("000000")}";
            qualityProblem.Mid = null;
            _problemRepository.Add(qualityProblem);
            var task = tasks[0];

            if (!input.PreventCommit)
            {
                _taskProvider.Complete(task.Id);
            }
            return(qualityProblem.Id);
        }
Example #14
0
        public void CompleteTask(CompleteProjectTaskInput input)
        {
            NullableHelper.SetNull(input);
            var projectTask = input.MapTo <ProjectTask>();
            var existing    = _projectTaskRepository.Get().Include(u => u.Attachments).Where(u => u.Id == input.Id).FirstOrDefault();

            if (existing.Assignee != _authInfoProvider.GetCurrent().User.Id)
            {
                throw new AppCoreException("当前用户不是节点负责人");
            }
            _projectTaskRepository.Update(projectTask, existing, new System.Linq.Expressions.Expression <Func <ProjectTask, object> >[] {
                u => u.SortNo,
                u => u.GanttId,
                u => u.Assignee,
                u => u.Name,
                u => u.StartDate,
                u => u.Content,
                u => u.Duration,
                u => u.Pid,
                u => u.Type,
            }, false);
        }
Example #15
0
        public int Add(StartProcessInput <AddEarlyStageInput> input)
        {
            if (input.Data.ReplyNumber == null)
            {
                throw new AppCoreException("批复文号不能为空");
            }
            var variables = new Dictionary <string, object>();
            var userId    = _authInfoProvider.GetCurrent().User.Id;

            variables.Add("starter", userId.ToString());
            int processInstanceId = _runtimeProvider.StartProcessInstanceByName(
                input.ProcessDefinitionName,
                $"{input.ProcessDefinitionName}-{input.Data.ReplyNumber}",
                variables);
            var tasks = _taskProvider.GetByProcessInstance(processInstanceId);

            if (tasks.Count == 0)
            {
                throw new AppCoreException("任务未创建成功!");
            }
            var earlyStage = input.Data.MapTo <EarlyStage>();

            // var count = AppSampleContext.Instance.GetSupplierNoCount(() => _supplierRepository.Count(u => u.CreateTime.Value.Year == DateTime.Now.Year && (u.State == DataState.Stable || u.State == DataState.Creating)));
            earlyStage.ProcessInstanceId = processInstanceId;
            earlyStage.State             = DataState.Creating;
            // memorabiliaRecord.SupplierNo = $"{DateTime.Now.Year}{count.ToString("000000")}";
            earlyStage.Mid = null;
            _earlyStageRepository.Add(earlyStage);
            var task = tasks[0];

            if (!input.PreventCommit)
            {
                _taskProvider.Complete(task.Id);
            }
            return(earlyStage.Id);
        }
Example #16
0
        public PaginationData <GetProjectStatisticsListOutput> Get(int pageIndex, int pageSize, string keyword, string sortField, string sortState)
        {
            //var qualityProblem = _problemRepository.Get()//质量问题
            //  .Where(u => u.State == DataState.Stable && u.RectificationState != RectificationState.Completed);

            //var safetyProblem = _safetyProblemRepository.Get()//安全问题
            //    .Where(u => u.State == DataState.Stable && u.RectificationState != App.Safety.SafetyProblemRectifications.RectificationState.Completed);

            var currentUserId      = _authInfoProvider.GetCurrent().User.Id;
            var currentUnitUserIds = _userUnitRepository.Get()
                                     .Where(v => _userUnitRepository.Get().Where(u => u.UserId == currentUserId).Any(u => u.OrganizationUnitId == v.OrganizationUnitId)).Select(u => u.UserId).ToList();
            var privilegedPersonIds = AuthorizationContext.Instance.GetPrivilegedPersonIds("项目信息");

            IQueryable <Project> query = _projectRepository.Get()
                                         .Include(u => u.Location)
                                         .Include(u => u.State)
                                         .Include(u => u.Type)
                                         .Include(u => u.ProjectNature)
                                         .Include(u => u.Members)
                                         .Where(u => u.DataState == DataState.Stable &&
                                                (u.Members.Any(v => v.UserId == currentUserId) || u.CreatorId == currentUserId || currentUnitUserIds.Contains(u.CreatorId) || privilegedPersonIds.Contains(currentUserId))
                                                );

            if (!string.IsNullOrEmpty(keyword))
            {
                query = query.Where(u => u.Name.Contains(keyword) || u.No.Contains(keyword));
            }

            ////sortState 1降序2升序0默认
            //if (!string.IsNullOrEmpty(sortField) && !string.IsNullOrEmpty(sortState))
            //{
            //    switch (sortField)
            //    {
            //        case "No"://项目编号
            //            query = sortState == "1" ? query.OrderByDescending(u => u.No) : sortState == "2" ? query.OrderBy(u => u.No) : query.OrderByDescending(u => u.CreateTime);
            //            break;
            //        case "Name"://项目名称
            //            query = sortState == "1" ? query.OrderByDescending(u => u.Name) : sortState == "2" ? query.OrderBy(u => u.Name) : query.OrderByDescending(u => u.CreateTime);
            //            break;
            //        case "TypeId"://项目类型
            //            query = sortState == "1" ? query.OrderByDescending(u => u.TypeId) : sortState == "2" ? query.OrderBy(u => u.TypeId) : query.OrderByDescending(u => u.CreateTime);
            //            break;
            //        case "ProjectNatureId"://项目性质
            //            query = sortState == "1" ? query.OrderByDescending(u => u.ProjectNatureId) : sortState == "2" ? query.OrderBy(u => u.ProjectNatureId) : query.OrderByDescending(u => u.CreateTime);
            //            break;
            //        case "StateId"://项目状态
            //            query = sortState == "1" ? query.OrderByDescending(u => u.StateId) : sortState == "2" ? query.OrderBy(u => u.StateId) : query.OrderByDescending(u => u.CreateTime);
            //            break;
            //        case "GeneralEstimate"://项目概算
            //            query = sortState == "1" ? query.OrderByDescending(u => u.GeneralEstimate) : sortState == "2" ? query.OrderBy(u => u.GeneralEstimate) : query.OrderByDescending(u => u.CreateTime);
            //            break;
            //        case "CommencementDate"://开工时间
            //            query = sortState == "1" ? query.OrderByDescending(u => u.CommencementDate) : sortState == "2" ? query.OrderBy(u => u.CommencementDate) : query.OrderByDescending(u => u.CreateTime);
            //            break;
            //        case "CreatorId"://发布人
            //            query = sortState == "1" ? query.OrderByDescending(u => u.CreatorId) : sortState == "2" ? query.OrderBy(u => u.CreatorId) : query.OrderByDescending(u => u.CreateTime);
            //            break;

            //        default:
            //            query = query.OrderByDescending(u => u.CreateTime);
            //            break;
            //    }

            //}
            //else
            //{
            //    query = query.OrderByDescending(u => u.CreateTime);
            //}
            //var paging = PaginationDataHelper.WrapData<Project, T>(query, pageIndex, pageSize).TransferTo<GetProjectStatisticsListOutput>();
            ////paging.Data.ForEach(u=>u.HasPermission = _projectHelper.HasPermission("项目负责人", u.Id));
            //paging.Data.ForEach(u => {
            //    u.HasPermission = u.CreatorId == _authInfoProvider.GetCurrent().User.Id;
            //    u.QualityProblemCount = qualityProblem.Count(s =>  s.ProjectId == u.Id);
            //    u.SafetyProblemCount = safetyProblem.Count(s => s.ProjectId == u.Id);
            //});
            //paging = paging.Data.Where(w=>w.QualityProblemCount!=0);//&& u.SafetyProblemCount != 0
            //return paging;
            var queryForProject                    = query;
            var queryForQuality                    = _qualityProblemRepository.Get().Where(u => u.State == DataState.Stable && u.RectificationState != RectificationState.Completed);
            var queryForSafety                     = _safetyProblemRepository.Get().Where(u => u.State == DataState.Stable && u.RectificationState != App.Safety.SafetyProblemRectifications.RectificationState.Completed);
            var queryForProjectAndQuality          = queryForProject.GroupJoin(queryForQuality, u => u.Id, v => v.ProjectId, (u, v) => new { Project = u, QualityProblems = v });
            var queryForProjectAndQualityAndSafety = queryForProjectAndQuality.GroupJoin(queryForSafety, u => u.Project.Id, v => v.ProjectId, (u, v) => new { Project = u.Project, QualityProblems = u.QualityProblems, SafetyProblems = v });

            queryForProjectAndQualityAndSafety = queryForProjectAndQualityAndSafety.Where(u => u.QualityProblems.Count() > 0 || u.SafetyProblems.Count() > 0);
            var paging = PaginationDataHelper.WrapData(queryForProjectAndQualityAndSafety, pageIndex, pageSize, u => u.Project.Id).TransferTo <GetProjectStatisticsListOutput>(u => {
                var project = u.Project;
                var output  = project.MapTo <GetProjectStatisticsListOutput>();
                output.QualityProblemCount = u.QualityProblems.Count(); //质量问题个数
                output.SafetyProblemCount  = u.SafetyProblems.Count();  //安全问题个数
                return(output);
            });

            return(paging);
        }
Example #17
0
 public PaginationData <GetMessageRecordOutput> GetMessages(int pageIndex, int pageSize, MessageType?type, bool?readState)
 {
     return(_messageService.Get(_authInfoProvider.GetCurrent().User.Id, pageIndex, pageSize, type, readState));
 }