Пример #1
0
        public IActionResult AddMembers(Guid teamId, Guid[] userid)
        {
            if (userid.IsEmpty())
            {
                return(JError(T["notspecified_record"]));
            }
            var query = new QueryExpression("TeamMembership", CurrentUser.UserSettings.LanguageId);

            query.ColumnSet.AddColumns("systemuserid");
            query.Criteria.AddCondition("teamid", ConditionOperator.Equal, teamId);
            var members     = _dataFinder.RetrieveAll(query);
            var addEntities = new List <Entity>();

            foreach (var item in userid)
            {
                if (!members.Any(n => n.GetGuidValue("systemuserid") == item))
                {
                    Entity entity = new Entity("TeamMembership");
                    entity.SetAttributeValue("teamid", teamId);
                    entity.SetAttributeValue("systemuserid", item);
                    addEntities.Add(entity);
                }
            }
            if (addEntities.NotEmpty())
            {
                _dataCreater.CreateMany(addEntities);
            }
            return(JOk(T["added_success"]));
        }
Пример #2
0
        /// <summary>
        /// 删除记录
        /// </summary>
        /// <param name="entityId">关联实体id</param>
        /// <param name="objectId">关联记录id</param>
        /// <returns></returns>
        public virtual bool DeleteById(Guid entityId, Guid objectId)
        {
            //查询
            var query = new QueryExpression("attachment", _appContext.GetFeature <ICurrentUser>().UserSettings.LanguageId);

            query.ColumnSet.AddColumns("attachmentid", "cdnpath");
            query.Criteria.AddCondition("entityid", ConditionOperator.Equal, entityId);
            query.Criteria.AddCondition("objectid", ConditionOperator.Equal, objectId);
            var entities = _dataFinder.RetrieveAll(query);
            var result   = false;

            if (entities.NotEmpty())
            {
                result = _dataDeleter.Delete("attachment", entities.Select(x => x.GetIdValue()).ToList());
                if (result)
                {
                    //delete files
                    foreach (var item in entities)
                    {
                        var cdnPath = item.GetStringValue("cdnpath");
                        if (cdnPath.IsNotEmpty() && System.IO.File.Exists(_webHelper.MapPath(cdnPath)))
                        {
                            System.IO.File.Delete(_webHelper.MapPath(cdnPath));
                        }
                    }
                }
            }
            return(result);
        }
Пример #3
0
        public IActionResult Get(Guid?solutionId)
        {
            var entities = _entityFinder.QueryPaged(x => x
                                                    .Page(1, 25000)
                                                    .Where(f => f.OrganizationId == CurrentUser.OrganizationId)
                                                    .Select(n => new { n.EntityId, n.Name, n.LocalizedName, n.EntityGroups })
                                                    .Sort(n => n.SortAscending(f => f.LocalizedName)), solutionId.Value, true);
            var groups = _dataFinder.RetrieveAll("entitygroup", new List <string> {
                "name"
            }, new OrderExpression("name", OrderType.Ascending));

            if (entities.Items.Count(x => x.EntityGroups.IsEmpty()) > 0)
            {
                var nullGroup = new Xms.Core.Data.Entity("entitygroup");
                nullGroup.SetIdValue(Guid.Empty);
                nullGroup["name"] = "未分组";
                groups.Insert(0, nullGroup);
                foreach (var item in entities.Items.Where(x => x.EntityGroups.IsEmpty()))
                {
                    item.EntityGroups = Guid.Empty.ToString();
                }
            }
            List <dynamic> result = new List <dynamic>();

            foreach (var group in groups)
            {
                dynamic g = new ExpandoObject();
                g.label    = group["name"];
                g.id       = group.Id;
                g.children = entities.Items.Where(x => x.EntityGroups.IsNotEmpty() && x.EntityGroups.IndexOf(group.Id.ToString(), StringComparison.InvariantCultureIgnoreCase) >= 0)?.Select(x => new { id = x.EntityId, label = x.LocalizedName }).ToList();
                result.Add(g);;
            }

            return(JOk(result));
        }
Пример #4
0
        public IActionResult EditRoleEntityPermissions(Guid roleId)
        {
            if (roleId.IsEmpty())
            {
                return(NotFound());
            }
            var entityGroups = _dataFinder.RetrieveAll("entitygroup", new List <string> {
                "name"
            }, new OrderExpression {
                AttributeName = "name", OrderType = OrderType.Ascending
            });
            EditRoleEntityPermissionsModel model = new EditRoleEntityPermissionsModel
            {
                ResourceName     = DataAuthorizationDefaults.ModuleName,
                Role             = _roleService.FindById(roleId),
                RoleId           = roleId,
                RoleObjectAccess = _roleObjectAccessService.QueryRolePermissions(roleId, DataAuthorizationDefaults.ModuleName),

                EntityPermissions = _entityPermissionService.Query(x => x
                                                                   .Sort(n => n.SortAscending(s => s.Name))
                                                                   ),
                Entities = _entityFinder.Query(x => x.Where(n => n.AuthorizationEnabled == true)
                                               .Sort(n => n.SortAscending(s => s.Name))
                                               ),
                EntityGroups = entityGroups
            };

            return(DynamicResult(model, $"~/Views/Security/{WebContext.ActionName}.cshtml"));
        }
Пример #5
0
 public IActionResult AssignRolesToTeam(Guid[] teamId, Guid[] roleId)
 {
     if (!Arguments.HasValue(teamId) || !Arguments.HasValue(roleId))
     {
         return(NotSpecifiedRecord());
     }
     foreach (var tid in teamId)
     {
         List <Guid> needDeleted = new List <Guid>();
         var         query       = new QueryExpression("TeamRoles", CurrentUser.UserSettings.LanguageId);
         query.ColumnSet.AddColumns("teamid", "roleid");
         query.Criteria.AddCondition("teamid", ConditionOperator.Equal, tid);
         var datas       = _dataFinder.RetrieveAll(query);
         var addEntities = new List <Entity>();
         foreach (var item in roleId)
         {
             if (!datas.Any(n => n.GetGuidValue("roleid") == item))
             {
                 Entity entity = new Entity("TeamRoles");
                 entity.SetAttributeValue("teamid", teamId);
                 entity.SetAttributeValue("roleid", item);
                 addEntities.Add(entity);
             }
         }
         var b = datas.Where(n => !roleId.Contains(n.GetGuidValue("roleid"))).Select(n => n.GetGuidValue("teamroleid")).ToList();
         needDeleted.AddRange(b);
         if (needDeleted.NotEmpty())
         {
             //delete
             _dataDeleter.Delete("teamroles", needDeleted);
         }
         if (addEntities.NotEmpty())
         {
             _dataCreater.CreateMany(addEntities);
         }
     }
     return(SaveSuccess());
 }
Пример #6
0
        public IActionResult WorkFlowAttachments(Guid processId, bool preview = false)
        {
            QueryExpression query = new QueryExpression("attachment", CurrentUser.UserSettings.LanguageId);

            query.ColumnSet.AllColumns = true;
            query.Criteria.AddCondition("objectid", ConditionOperator.Equal, processId);
            var data = _dataFinder.RetrieveAll(query);

            if (data.IsEmpty())
            {
                return(NotFound());
            }
            return(Redirect("/" + WebContext.OrganizationUniqueName + "/file/download?id=" + data.First().GetIdValue() + "&sid=" + CurrentUser.SessionId + "&preview=" + preview));
        }
Пример #7
0
        public IActionResult RetrieveMultiple(RetrieveMultipleModel args)
        {
            if (args.Query.EntityName.IsEmpty())
            {
                return(JError("entityname is not specified"));
            }
            var entity = _entityFinder.FindByName(args.Query.EntityName);

            if (entity == null)
            {
                return(JError("entityname is not found"));
            }
            if (args.IsAll)
            {
                var result = _dataFinder.RetrieveAll(args.Query);
                return(JOk(result));
            }
            else
            {
                var result = _dataFinder.RetrieveMultiple(args.Query);
                return(JOk(result));
            }
        }
Пример #8
0
        public static List <Entity> RetrieveAll(this IDataFinder finder, string entityName, List <string> columns = null, OrderExpression order = null, bool ignorePermissions = false)
        {
            var q = new QueryExpression(entityName, LanguageCode.CHS);

            if (columns.NotEmpty())
            {
                q.ColumnSet.AddColumns(columns.ToArray());
            }
            else
            {
                q.ColumnSet.AllColumns = true;
            }
            if (order != null)
            {
                q.AddOrder(order.AttributeName, order.OrderType);
            }

            return(finder.RetrieveAll(q, ignorePermissions));
        }
Пример #9
0
        private Guid CreateFromMap_Copy(EntityMap entityMap, Guid sourceRecordId)
        {
            var headTargetEntityMeta = _entityFinder.FindById(entityMap.TargetEntityId);
            var headTargetAttributes = _attributeFinder.FindByEntityId(entityMap.TargetEntityId);
            //引用源实体的字段
            var headRelationShipMeta = _relationShipFinder.FindByName(entityMap.RelationShipName);
            var refAttr = headTargetAttributes.Find(n => n.AttributeId == headRelationShipMeta.ReferencingAttributeId);

            if (entityMap.MapType == MapType.CopyOne)
            {
                //查询是否已生成记录
                QueryExpression query_target = new QueryExpression(headTargetEntityMeta.Name, _languageId);
                query_target.ColumnSet.AddColumn(headTargetAttributes.Find(n => n.TypeIsPrimaryKey()).Name);
                query_target.Criteria.AddCondition(refAttr.Name, ConditionOperator.Equal, sourceRecordId);
                var existsRecord = _dataFinder.Retrieve(query_target);
                if (existsRecord.NotEmpty())
                {
                    OnException(_loc["entitymap_copyone_error"]);
                    return(Guid.Empty);
                }
            }
            Guid newId = Guid.Empty;
            //源记录
            var sourceRecord = _dataFinder.RetrieveById(entityMap.SourceEnttiyName, sourceRecordId);

            if (sourceRecord.IsEmpty())
            {
                OnException(_loc["notfound_record"]);
                return(Guid.Empty);
            }
            //单据头
            var attributeMaps = _attributeMapFinder.Query(n => n.Where(f => f.EntityMapId == entityMap.EntityMapId));

            if (attributeMaps.IsEmpty())
            {
                OnException(_loc["entitymap_emptyheadattributemap"]);
                return(Guid.Empty);
            }
            //单据体
            var childEntityMap = _entityMapFinder.FindByParentId(entityMap.EntityMapId);
            //单据头字段元数据
            var headSourceAttributes = _attributeFinder.FindByEntityId(entityMap.SourceEntityId);
            //新增单据头信息
            Entity headEntity = new Entity(entityMap.TargetEnttiyName);

            foreach (var attrMap in attributeMaps)
            {
                if (!headSourceAttributes.Exists(n => n.AttributeId == attrMap.SourceAttributeId) || !headTargetAttributes.Exists(n => n.AttributeId == attrMap.TargetAttributeId))
                {
                    continue;
                }
                var attr = headTargetAttributes.Find(n => n.AttributeId == attrMap.TargetAttributeId);
                if (attr == null)
                {
                    continue;
                }
                var value = sourceRecord[attrMap.SourceAttributeName];
                if (value == null && attrMap.DefaultValue.IsNotEmpty())
                {
                    value = attrMap.DefaultValue;
                }
                headEntity.SetAttributeValue(attr.Name, sourceRecord.WrapAttributeValue(_entityFinder, attr, value));
            }
            //关联来源单据ID
            headEntity.SetAttributeValue(refAttr.Name, sourceRecord.WrapAttributeValue(_entityFinder, refAttr, sourceRecord.GetIdValue()));
            try
            {
                _organizationDataProvider.BeginTransaction();
                InternalOnMap(sourceRecord, headEntity, OperationStage.PreOperation, headTargetEntityMeta, headTargetAttributes);
                newId = _dataCreater.Create(headEntity);
                //新增单据体信息
                if (childEntityMap != null)
                {
                    var childAttributeMaps = _attributeMapFinder.Query(n => n.Where(f => f.EntityMapId == childEntityMap.EntityMapId));
                    if (childAttributeMaps.NotEmpty())
                    {
                        var childTargetEntityMeta     = _entityFinder.FindById(childEntityMap.TargetEntityId);
                        var childTargetAttributesMeta = _attributeFinder.FindByEntityId(childEntityMap.TargetEntityId);
                        var childSourceAttributesMeta = _attributeFinder.FindByEntityId(childEntityMap.SourceEntityId);
                        var childRelationShips        = childEntityMap.RelationShipName.SplitSafe(",");
                        //源单据体与源单据头的关系
                        var childSourceRelationShipMeta = _relationShipFinder.FindByName(childRelationShips[0]);
                        //目标单据体与目标单据头的关系
                        var childTargetRelationShipMeta = _relationShipFinder.FindByName(childRelationShips[1]);
                        //源单据体数据
                        QueryExpression query_source = new QueryExpression(childEntityMap.SourceEnttiyName, _languageId);
                        query_source.ColumnSet.AllColumns = true;
                        var refKey = headSourceAttributes.Find(n => n.AttributeId == childSourceRelationShipMeta.ReferencedAttributeId).Name;
                        query_source.Criteria.AddCondition(refKey, ConditionOperator.Equal, sourceRecordId);
                        var childSourceRecords = _dataFinder.RetrieveAll(query_source);
                        if (childSourceRecords.NotEmpty())
                        {
                            //引用单据头的字段
                            var headRefAttr = childTargetAttributesMeta.Find(n => n.AttributeId == childTargetRelationShipMeta.ReferencingAttributeId);
                            //引用源单据体的字段
                            var refSourceAttr = childTargetAttributesMeta.Find(n => n.ReferencedEntityId.HasValue && n.ReferencedEntityId.Value == childEntityMap.SourceEntityId);
                            foreach (var item in childSourceRecords)
                            {
                                //目标单据体
                                Entity childTargetRecord = new Entity(childEntityMap.TargetEnttiyName);
                                foreach (var attrMap in childAttributeMaps)
                                {
                                    if (!childSourceAttributesMeta.Exists(n => n.AttributeId == attrMap.SourceAttributeId) || !childTargetAttributesMeta.Exists(n => n.AttributeId == attrMap.TargetAttributeId))
                                    {
                                        continue;
                                    }
                                    var attr = childTargetAttributesMeta.Find(n => n.AttributeId == attrMap.TargetAttributeId);
                                    if (attr == null)
                                    {
                                        continue;
                                    }
                                    var value = item[attrMap.SourceAttributeName];
                                    if (value == null && attrMap.DefaultValue.IsNotEmpty())
                                    {
                                        value = attrMap.DefaultValue;
                                    }
                                    childTargetRecord.SetAttributeValue(attrMap.TargetAttributeName, sourceRecord.WrapAttributeValue(_entityFinder, attr, value));
                                }
                                //关联来源单据体记录ID
                                if (refSourceAttr != null)
                                {
                                    childTargetRecord.SetAttributeValue(refSourceAttr.Name, sourceRecord.WrapAttributeValue(_entityFinder, refSourceAttr, item.GetIdValue()));
                                }
                                //单据头ID
                                childTargetRecord.SetAttributeValue(headRefAttr.Name, sourceRecord.WrapAttributeValue(_entityFinder, headRefAttr, newId));
                                _dataCreater.Create(childTargetRecord);
                            }
                        }
                    }
                }
                _organizationDataProvider.CommitTransaction();
                InternalOnMap(sourceRecord, headEntity, OperationStage.PostOperation, headTargetEntityMeta, headTargetAttributes);
            }
            catch (Exception e)
            {
                _organizationDataProvider.RollBackTransaction();
                newId = Guid.Empty;
                OnException(e);
            }
            return(newId);
        }
Пример #10
0
        /// <summary>
        /// 获取当前处理者列表
        /// </summary>
        /// <param name="instance"></param>
        /// <param name="handlerIdType"></param>
        /// <param name="handlers"></param>
        /// <param name="stepOrder"></param>
        /// <returns></returns>
        public List <Guid> GetCurrentHandlerId(WorkFlowInstance instance, WorkFlowProcess prevStep, int handlerIdType, string handlers)
        {
            var result = new List <Guid>();

            try
            {
                var applicantUser = _dataFinder.RetrieveById("systemuser", instance.ApplicantId, ignorePermissions: true);
                switch (handlerIdType)
                {
                case 1:    //所有成员

                    break;

                case 2:    //指定成员
                    if (handlers.IsNotEmpty())
                    {
                        List <WorkFlowStepHandler> handlerObjs = new List <WorkFlowStepHandler>().DeserializeFromJson(handlers);
                        foreach (var item in handlerObjs)
                        {
                            if (item.Type == WorkFlowStepHandlerType.SystemUser)
                            {
                                result.Add(item.Id);
                            }
                            else if (item.Type == WorkFlowStepHandlerType.Team)
                            {
                                var queryTeam = new QueryExpression("TeamMembership", _currentUser.UserSettings.LanguageId);
                                queryTeam.ColumnSet.AddColumn("SystemUserId");
                                queryTeam.Criteria.AddCondition("TeamId", ConditionOperator.Equal, item.Id);
                                var teamMembers = _dataFinder.RetrieveAll(queryTeam, true);
                                if (teamMembers.NotEmpty())
                                {
                                    result.AddRange(teamMembers.Select(n => n.GetGuidValue("SystemUserId")));
                                }
                            }
                            else if (item.Type == WorkFlowStepHandlerType.Roles)
                            {
                                QueryExpression query = new QueryExpression("SystemUserRoles");
                                query.AddColumns("SystemUserId");
                                query.Criteria.AddCondition("RoleId", ConditionOperator.Equal, item.Id);
                                var userRolesData = _dataFinder.RetrieveAll(query, true);
                                if (userRolesData.NotEmpty())
                                {
                                    result.AddRange(userRolesData.Select(n => n.GetGuidValue("SystemUserId")));
                                }
                            }
                            else if (item.Type == WorkFlowStepHandlerType.Post)
                            {
                                var queryTeam = new QueryExpression("SystemUser", _currentUser.UserSettings.LanguageId);
                                queryTeam.ColumnSet.AddColumn("SystemUserId");
                                queryTeam.Criteria.AddCondition("PostId", ConditionOperator.Equal, item.Id);
                                queryTeam.Criteria.AddCondition("statecode", ConditionOperator.Equal, 1);
                                var teamMembers = _dataFinder.RetrieveAll(queryTeam, true);
                                if (teamMembers.NotEmpty())
                                {
                                    result.AddRange(teamMembers.Select(n => n.GetGuidValue("SystemUserId")));
                                }
                            }
                        }
                    }
                    break;

                case 3:    //发起人领导
                    var parentUserId = applicantUser.GetGuidValue("parentsystemuserid");
                    if (!parentUserId.Equals(Guid.Empty))
                    {
                        result.Add(parentUserId);
                    }
                    break;

                case 4:    //发起人部门负责人
                    var bmanager   = _dataFinder.RetrieveById("businessunit", applicantUser.GetGuidValue("businessunitid"));
                    var bmanagerId = bmanager.GetGuidValue("managerid");
                    if (!bmanagerId.Equals(Guid.Empty))
                    {
                        result.Add(bmanagerId);
                    }
                    break;

                case 5:    //发起人公司负责人
                    var orgmanager   = _dataFinder.RetrieveById("organization", applicantUser.GetGuidValue("organizationid"), ignorePermissions: true);
                    var orgmanagerId = orgmanager.GetGuidValue("managerid");
                    if (!orgmanagerId.Equals(Guid.Empty))
                    {
                        result.Add(orgmanagerId);
                    }
                    break;

                case 6:    //上一环节审核人领导
                           //var prevStepOrder = stepOrder - 1;
                           //var prevStep = new WorkFlowStepService(this.User).Find(n => n.WorkFlowId == instance.WorkFlowId && n.StepOrder == prevStepOrder);
                    if (prevStep != null)
                    {
                        var prevHandlers = GetCurrentHandlerId(instance, null, prevStep.HandlerIdType, prevStep.Handlers);
                        foreach (var item in prevHandlers)
                        {
                            var prevHandledUsers = _dataFinder.RetrieveById("systemuser", item, ignorePermissions: true);
                            var parentUserId2    = prevHandledUsers.GetGuidValue("parentsystemuserid");
                            if (!parentUserId2.Equals(Guid.Empty))
                            {
                                result.Add(parentUserId2);
                            }
                        }
                    }
                    break;

                case 7:    //发起人
                    result.Add(instance.ApplicantId);
                    break;
                }
            }
            catch (Exception ex)
            {
                throw new XmsException(ex);
            }
            return(result.Distinct().ToList());
        }