Exemple #1
0
 /// <summary>
 /// 添加, 这里可以人工干预,提高程序的性能
 /// </summary>
 /// <param name="entity">实体</param>
 /// <param name="identity">自增量方式,表主键是否采用自增的策略</param>
 /// <param name="returnId">返回主键,不返回程序允许速度会快,主要是为了主细表批量插入数据优化用的</param>
 /// <returns>主键</returns>
 public string Add(BaseOrganizationScopeEntity entity, bool identity = true, bool returnId = true)
 {
     Identity  = identity;
     ReturnId  = returnId;
     entity.Id = AddEntity(entity).ToInt();
     return(entity.Id.ToString());
 }
        /// <summary>
        /// 设置组织范围
        /// </summary>
        /// <param name="systemCode">系统编码</param>
        /// <param name="userId"></param>
        /// <param name="permissionScope"></param>
        /// <param name="permissionCode">权限编码</param>
        /// <param name="containChild"></param>
        /// <returns></returns>
        public string SetUserOrganizationScope(string systemCode, string userId, PermissionOrganizationScope permissionScope, string permissionCode = "Resource.AccessPermission", bool containChild = false)
        {
            var result = string.Empty;

            var permissionId = new BaseModuleManager().GetIdByCodeByCache(systemCode, permissionCode);

            if (!string.IsNullOrEmpty(permissionId))
            {
                var tableName = BaseOrganizationScopeEntity.CurrentTableName;
                if (!string.IsNullOrEmpty(systemCode))
                {
                    tableName = systemCode + "OrganizationScope";
                }

                var organizationScopeManager = new BaseOrganizationScopeManager(DbHelper, UserInfo, tableName);
                var parameters = new List <KeyValuePair <string, object> >
                {
                    new KeyValuePair <string, object>(BaseOrganizationScopeEntity.FieldResourceCategory, BaseUserEntity.CurrentTableName),
                    new KeyValuePair <string, object>(BaseOrganizationScopeEntity.FieldResourceId, userId),
                    new KeyValuePair <string, object>(BaseOrganizationScopeEntity.FieldPermissionId, permissionId)
                };
                result = organizationScopeManager.GetId(parameters);
                BaseOrganizationScopeEntity organizationScopeEntity = null;
                if (string.IsNullOrEmpty(result))
                {
                    organizationScopeEntity = new BaseOrganizationScopeEntity();
                }
                else
                {
                    organizationScopeEntity = organizationScopeManager.GetEntity(result);
                }
                organizationScopeEntity.AllData           = (permissionScope == PermissionOrganizationScope.AllData ? 1 : 0);
                organizationScopeEntity.Province          = (permissionScope == PermissionOrganizationScope.Province ? 1 : 0);
                organizationScopeEntity.City              = (permissionScope == PermissionOrganizationScope.City ? 1 : 0);
                organizationScopeEntity.District          = (permissionScope == PermissionOrganizationScope.District ? 1 : 0);
                organizationScopeEntity.UserCompany       = (permissionScope == PermissionOrganizationScope.UserCompany ? 1 : 0);
                organizationScopeEntity.UserSubCompany    = (permissionScope == PermissionOrganizationScope.UserSubCompany ? 1 : 0);
                organizationScopeEntity.UserDepartment    = (permissionScope == PermissionOrganizationScope.UserDepartment ? 1 : 0);
                organizationScopeEntity.UserSubDepartment = (permissionScope == PermissionOrganizationScope.UserSubDepartment ? 1 : 0);
                organizationScopeEntity.UserWorkgroup     = (permissionScope == PermissionOrganizationScope.UserWorkgroup ? 1 : 0);
                organizationScopeEntity.OnlyOwnData       = (permissionScope == PermissionOrganizationScope.OnlyOwnData ? 1 : 0);
                organizationScopeEntity.ByDetails         = (permissionScope == PermissionOrganizationScope.ByDetails ? 1 : 0);
                organizationScopeEntity.NotAllowed        = (permissionScope == PermissionOrganizationScope.NotAllowed ? 1 : 0);
                organizationScopeEntity.Enabled           = 1;
                organizationScopeEntity.Deleted           = 0;
                organizationScopeEntity.ContainChild      = containChild ? 1 : 0;
                organizationScopeEntity.PermissionId      = int.Parse(permissionId);
                organizationScopeEntity.ResourceCategory  = BaseUserEntity.CurrentTableName;
                organizationScopeEntity.ResourceId        = userId.ToString();
                if (string.IsNullOrEmpty(result))
                {
                    result = organizationScopeManager.Add(organizationScopeEntity);
                }
                else
                {
                    organizationScopeManager.Update(organizationScopeEntity);
                }
            }
            return(result);
        }
Exemple #3
0
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="sqlBuilder">Sql语句生成器</param>
 /// <param name="entity">实体</param>
 private void SetEntity(SqlBuilder sqlBuilder, BaseOrganizationScopeEntity entity)
 {
     SetEntityExtend(sqlBuilder, entity);
     sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldResourceCategory, entity.ResourceCategory);
     sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldResourceId, entity.ResourceId);
     sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldPermissionId, entity.PermissionId);
     sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldAllData, entity.AllData);
     sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldProvince, entity.Province);
     sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldCity, entity.City);
     sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldDistrict, entity.District);
     sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldStreet, entity.Street);
     sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldUserCompany, entity.UserCompany);
     sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldUserSubCompany, entity.UserSubCompany);
     sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldUserDepartment, entity.UserDepartment);
     sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldUserSubDepartment, entity.UserSubDepartment);
     sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldUserWorkgroup, entity.UserWorkgroup);
     sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldOnlyOwnData, entity.OnlyOwnData);
     sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldNotAllowed, entity.NotAllowed);
     sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldByDetails, entity.ByDetails);
     sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldContainChild, entity.ContainChild);
     sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldDescription, entity.Description);
     sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldSortCode, entity.SortCode);
     sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldDeleted, entity.Deleted);
     sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldEnabled, entity.Enabled);
 }
Exemple #4
0
 /// <summary>
 /// 添加或更新(主键是否为0)
 /// </summary>
 /// <param name="entity">实体</param>
 /// <param name="identity">自增量方式,表主键是否采用自增的策略</param>
 /// <param name="returnId">返回主键,不返回程序允许速度会快,主要是为了主细表批量插入数据优化用的</param>
 /// <returns>主键</returns>
 public string AddOrUpdate(BaseOrganizationScopeEntity entity, bool identity = true, bool returnId = true)
 {
     Identity = identity;
     ReturnId = returnId;
     if (entity.Id == 0)
     {
         entity.Id = AddEntity(entity).ToInt();
         return(entity.Id.ToString());
     }
     else
     {
         return(UpdateEntity(entity) > 0 ? entity.Id.ToString() : string.Empty);
     }
 }
Exemple #5
0
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">实体</param>
        public int UpdateEntity(BaseOrganizationScopeEntity entity)
        {
            var sqlBuilder = new SqlBuilder(DbHelper);

            sqlBuilder.BeginUpdate(CurrentTableName);
            SetEntity(sqlBuilder, entity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldUpdateUserId, UserInfo.UserId);
                sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldUpdateUserName, UserInfo.UserName);
                sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldUpdateBy, UserInfo.RealName);
            }
            sqlBuilder.SetDbNow(BaseOrganizationScopeEntity.FieldUpdateTime);
            sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldUpdateIp, Utils.GetIp());
            sqlBuilder.SetWhere(PrimaryKey, entity.Id);
            //return sqlBuilder.EndUpdate();
            var result = sqlBuilder.EndUpdate();

            if (result > 0)
            {
                RemoveCache(entity.Id);
            }
            return(result);
        }
        /*
         * public List<BaseOrganizationScopeEntity> GetUserOrganizationScopes(string userId, string permissionCode = "Resource.AccessPermission")
         * {
         *  List<BaseOrganizationScopeEntity> result = null;
         *  string result = this.GetPermissionIdByCode(permissionCode);
         *  if (!string.IsNullOrEmpty(result))
         *  {
         *      BaseOrganizationScopeManager organizationScopeManager = new BaseOrganizationScopeManager(this.DbHelper, this.UserInfo);
         *      List<KeyValuePair<string, object>> parameters = new List<KeyValuePair<string, object>>();
         *      parameters.Add(new KeyValuePair<string, object>(BaseOrganizationScopeEntity.FieldResourceCategory, BaseUserEntity.CurrentTableName));
         *      parameters.Add(new KeyValuePair<string, object>(BaseOrganizationScopeEntity.FieldResourceId, userId));
         *      parameters.Add(new KeyValuePair<string, object>(BaseOrganizationScopeEntity.FieldPermissionId, result));
         *      result = organizationScopeManager.GetList<BaseOrganizationScopeEntity>(parameters);
         *  }
         *  return result;
         * }
         */

        /// <summary>
        /// 获取用户组织范围
        /// </summary>
        /// <param name="systemCode">系统编码</param>
        /// <param name="userId"></param>
        /// <param name="containChild"></param>
        /// <param name="permissionCode">权限编码</param>
        /// <returns></returns>
        public PermissionOrganizationScope GetUserOrganizationScope(string systemCode, string userId, out bool containChild, string permissionCode = "Resource.AccessPermission")
        {
            containChild = false;
            var permissionScope = PermissionOrganizationScope.UserCompany;

            BaseOrganizationScopeEntity organizationScopeEntity = null;
            var permissionId = new BaseModuleManager().GetIdByCodeByCache(systemCode, permissionCode);

            if (!string.IsNullOrEmpty(permissionId))
            {
                var tableName = BaseOrganizationScopeEntity.CurrentTableName;
                if (!string.IsNullOrEmpty(systemCode))
                {
                    tableName = systemCode + "OrganizationScope";
                }

                var organizationScopeManager = new BaseOrganizationScopeManager(DbHelper, UserInfo, tableName);
                var parameters = new List <KeyValuePair <string, object> >
                {
                    new KeyValuePair <string, object>(BaseOrganizationScopeEntity.FieldResourceCategory, BaseUserEntity.CurrentTableName),
                    new KeyValuePair <string, object>(BaseOrganizationScopeEntity.FieldResourceId, userId),
                    new KeyValuePair <string, object>(BaseOrganizationScopeEntity.FieldPermissionId, permissionId)
                };
                var dt = organizationScopeManager.GetDataTable(parameters);
                if (dt != null && dt.Rows.Count > 0)
                {
                    organizationScopeEntity = BaseEntity.Create <BaseOrganizationScopeEntity>(dt);
                }
            }

            if (organizationScopeEntity != null)
            {
                if (organizationScopeEntity.ContainChild == 1)
                {
                    containChild = true;
                }
                if (organizationScopeEntity.AllData == 1)
                {
                    permissionScope = PermissionOrganizationScope.AllData;
                }
                if (organizationScopeEntity.Province == 1)
                {
                    permissionScope = PermissionOrganizationScope.Province;
                }
                if (organizationScopeEntity.City == 1)
                {
                    permissionScope = PermissionOrganizationScope.City;
                }
                if (organizationScopeEntity.District == 1)
                {
                    permissionScope = PermissionOrganizationScope.District;
                }
                if (organizationScopeEntity.ByDetails == 1)
                {
                    permissionScope = PermissionOrganizationScope.ByDetails;
                }
                if (organizationScopeEntity.NotAllowed == 1)
                {
                    permissionScope = PermissionOrganizationScope.NotAllowed;
                }
                if (organizationScopeEntity.OnlyOwnData == 1)
                {
                    permissionScope = PermissionOrganizationScope.OnlyOwnData;
                }
                if (organizationScopeEntity.UserCompany == 1)
                {
                    permissionScope = PermissionOrganizationScope.UserCompany;
                }
                if (organizationScopeEntity.UserSubCompany == 1)
                {
                    permissionScope = PermissionOrganizationScope.UserSubCompany;
                }
                if (organizationScopeEntity.UserDepartment == 1)
                {
                    permissionScope = PermissionOrganizationScope.UserDepartment;
                }
                if (organizationScopeEntity.UserSubDepartment == 1)
                {
                    permissionScope = PermissionOrganizationScope.UserSubDepartment;
                }
                if (organizationScopeEntity.UserWorkgroup == 1)
                {
                    permissionScope = PermissionOrganizationScope.UserWorkgroup;
                }
            }
            return(permissionScope);
        }
Exemple #7
0
 // 这个是声明扩展方法
 partial void SetEntityExtend(SqlBuilder sqlBuilder, BaseOrganizationScopeEntity entity);
Exemple #8
0
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="entity">实体</param>
        public string AddEntity(BaseOrganizationScopeEntity entity)
        {
            var key = string.Empty;

            if (entity.SortCode == 0)
            {
                var managerSequence = new BaseSequenceManager(DbHelper, Identity);
                if (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.Db2)
                {
                    key = managerSequence.Increment($"SC_{CurrentTableName}_SEQ");
                }
                else
                {
                    key = managerSequence.Increment(CurrentTableName);
                }
                entity.SortCode = key.ToInt();
            }
            var sqlBuilder = new SqlBuilder(DbHelper, Identity, ReturnId);

            sqlBuilder.BeginInsert(CurrentTableName, PrimaryKey);
            if (!Identity)
            {
                // 这里已经是指定了主键了,所以不需要返回主键了
                sqlBuilder.ReturnId = false;
                sqlBuilder.SetValue(PrimaryKey, entity.Id);
            }
            else
            {
                if (!ReturnId && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.Db2))
                {
                    if (DbHelper.CurrentDbType == CurrentDbType.Oracle)
                    {
                        sqlBuilder.SetFormula(PrimaryKey, $"{CurrentTableName}_SEQ.NEXTVAL");
                    }
                    if (DbHelper.CurrentDbType == CurrentDbType.Db2)
                    {
                        sqlBuilder.SetFormula(PrimaryKey, $"NEXT VALUE FOR {CurrentTableName}_SEQ");
                    }
                }
                else
                {
                    if (Identity && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.Db2))
                    {
                        var managerSequence = new BaseSequenceManager(DbHelper);
                        entity.Id = managerSequence.Increment($"{CurrentTableName}_SEQ").ToInt();
                        sqlBuilder.SetValue(PrimaryKey, entity.Id);
                    }
                }
            }
            SetEntity(sqlBuilder, entity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldCreateUserId, UserInfo.UserId);
                sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldCreateUserName, UserInfo.UserName);
                sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldCreateBy, UserInfo.RealName);
            }
            else
            {
                sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldCreateBy, entity.CreateBy);
                sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldCreateUserName, entity.CreateUserName);
            }
            sqlBuilder.SetDbNow(BaseOrganizationScopeEntity.FieldCreateTime);
            sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldCreateIp, Utils.GetIp());
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldUpdateUserId, UserInfo.UserId);
                sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldUpdateUserName, UserInfo.UserName);
                sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldUpdateBy, UserInfo.RealName);
            }
            sqlBuilder.SetDbNow(BaseOrganizationScopeEntity.FieldUpdateTime);
            sqlBuilder.SetValue(BaseOrganizationScopeEntity.FieldUpdateIp, Utils.GetIp());
            if (Identity && (DbHelper.CurrentDbType == CurrentDbType.SqlServer || DbHelper.CurrentDbType == CurrentDbType.Access))
            {
                key = sqlBuilder.EndInsert().ToString();
            }
            else
            {
                sqlBuilder.EndInsert();
            }
            if (Identity && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.Db2))
            {
                key = entity.Id.ToString();
            }
            if (!string.IsNullOrWhiteSpace(key))
            {
                RemoveCache();
            }
            return(key);
        }
Exemple #9
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="entity">实体</param>
 public int Update(BaseOrganizationScopeEntity entity)
 {
     return(UpdateEntity(entity));
 }