@ -1595,7 +1595,7 @@ public class CommonService : ICommonService
/// <typeparam name="T"></typeparam>
/// <typeparam name="T"></typeparam>
/// <param name="tenantDb"></param>
/// <param name="tenantDb"></param>
/// <returns></returns>
/// <returns></returns>
public async Task < ( ISugarQueryable< T > queryable , string? ruleScope , List < IConditionalModel > ? c ontidions) > GetSpecialVisibleDataRuleFilter < T > ( ISugarQueryable < T > queryable , SqlSugarScopeProvider tenantDb )
public async Task < ( List< IConditionalModel > ? contidions , string? ruleScope , List < IConditionalModel > ? otherC ontidions) > GetSpecialVisibleDataRuleFilter < T > ( ISugarQueryable < T > queryable , SqlSugarScopeProvider tenantDb )
{
{
// 因为TaskBaseAllocation不能继承IOrgId, 所以在这里根据条件, 在需要的时候手动添加IOrgId查询筛选器
// 因为TaskBaseAllocation不能继承IOrgId, 所以在这里根据条件, 在需要的时候手动添加IOrgId查询筛选器
bool isTask = typeof ( T ) = = typeof ( TaskBaseAllocation ) ;
bool isTask = typeof ( T ) = = typeof ( TaskBaseAllocation ) ;
@ -1606,7 +1606,7 @@ public class CommonService : ICommonService
{
{
if ( isTask ) queryable . Filter ( typeof ( IOrgId ) ) ;
if ( isTask ) queryable . Filter ( typeof ( IOrgId ) ) ;
return ( queryable , "all" , otherContidions ) ; //超级管理员特权
return ( contidions , "all" , otherContidions ) ; //超级管理员特权
}
}
var moduleName = typeof ( T ) . Name . ToLower ( ) ;
var moduleName = typeof ( T ) . Name . ToLower ( ) ;
@ -1615,7 +1615,7 @@ public class CommonService : ICommonService
. First ( u = > u . UserId = = long . Parse ( user . UserId ) & & u . PermissionEntity . ToLower ( ) = = moduleName & & u . Status = = StatusEnum . Enable ) ;
. First ( u = > u . UserId = = long . Parse ( user . UserId ) & & u . PermissionEntity . ToLower ( ) = = moduleName & & u . Status = = StatusEnum . Enable ) ;
if ( rule . IsNull ( ) )
if ( rule . IsNull ( ) )
{
{
return ( queryable , null , otherContidions ) ; //默认查询
return ( contidions , null , otherContidions ) ; //默认查询
}
}
else
else
{
{
@ -1624,18 +1624,18 @@ public class CommonService : ICommonService
if ( ( long ) rule . VisibleTemplateId = = 0 )
if ( ( long ) rule . VisibleTemplateId = = 0 )
{
{
contidions . Add ( new ConditionalModel { FieldName = "CreateBy" , ConditionalType = ConditionalType . Equal , FieldValue = user . UserId } ) ;
contidions . Add ( new ConditionalModel { FieldName = "CreateBy" , ConditionalType = ConditionalType . Equal , FieldValue = user . UserId } ) ;
return ( queryable. Where ( contidions) , "self" , otherContidions ) ; //查询自身
return ( contidions, "self" , otherContidions ) ; //查询自身
}
}
var ruleInfo = tenantDb . Queryable < CodeDataRuleTemplate > ( ) . First ( x = > x . Id = = ( long ) rule . VisibleTemplateId ) ;
var ruleInfo = tenantDb . Queryable < CodeDataRuleTemplate > ( ) . First ( x = > x . Id = = ( long ) rule . VisibleTemplateId ) ;
if ( ruleInfo . RuleScope = = "all" )
if ( ruleInfo . RuleScope = = "all" )
{
{
return ( queryable. ClearFilter < IOrgId > ( ) . ClearFilter < ISharedOrgId > ( ) , ruleInfo . RuleScope , otherContidions ) ; //查询全部
return ( contidions , ruleInfo . RuleScope , otherContidions ) ; //查询全部
}
}
else if ( ruleInfo . RuleScope = = "none" )
else if ( ruleInfo . RuleScope = = "none" )
{
{
if ( isTask )
if ( isTask )
{ return ( queryable , ruleInfo . RuleScope , otherContidions ) ; }
{ return ( contidions , ruleInfo . RuleScope , otherContidions ) ; }
else
else
{
{
SqlSugar . Check . ExceptionEasy ( "NO Operation" , "没有数据查看权限!" ) ; //返回提示
SqlSugar . Check . ExceptionEasy ( "NO Operation" , "没有数据查看权限!" ) ; //返回提示
@ -1648,11 +1648,11 @@ public class CommonService : ICommonService
var additions = ConvertConditionalModel ( ruleInfo . AdditionDataRules ) ;
var additions = ConvertConditionalModel ( ruleInfo . AdditionDataRules ) ;
if ( conditionalModels . Count > 0 )
if ( conditionalModels . Count > 0 )
{
{
return ( queryable. Where ( conditionalModels) , ruleInfo . RuleScope , additions ) ; //自定义查询
return ( conditionalModels, ruleInfo . RuleScope , additions ) ; //自定义查询
}
}
else
else
{
{
return ( queryable. Where ( contidions) , ruleInfo . RuleScope , otherContidions ) ; //默认查询
return ( contidions, ruleInfo . RuleScope , otherContidions ) ; //默认查询
}
}
}
}
else if ( ruleInfo . RuleScope = = "self_org_with_child" ) // 当前机构及下属机构
else if ( ruleInfo . RuleScope = = "self_org_with_child" ) // 当前机构及下属机构
@ -1661,7 +1661,7 @@ public class CommonService : ICommonService
IEnumerable < long > orgIdList = orgList . Select ( x = > x . Id ) ;
IEnumerable < long > orgIdList = orgList . Select ( x = > x . Id ) ;
contidions . Add ( new ConditionalModel { FieldName = "OrgId" , ConditionalType = ConditionalType . In , FieldValue = string . Join ( "," , orgIdList ) } ) ;
contidions . Add ( new ConditionalModel { FieldName = "OrgId" , ConditionalType = ConditionalType . In , FieldValue = string . Join ( "," , orgIdList ) } ) ;
return ( queryable. Where ( contidions) , ruleInfo . RuleScope , otherContidions ) ;
return ( contidions, ruleInfo . RuleScope , otherContidions ) ;
}
}
else if ( ruleInfo . RuleScope = = "self" )
else if ( ruleInfo . RuleScope = = "self" )
{
{
@ -1669,12 +1669,12 @@ public class CommonService : ICommonService
var additions = ConvertConditionalModel ( ruleInfo . AdditionDataRules ) ;
var additions = ConvertConditionalModel ( ruleInfo . AdditionDataRules ) ;
if ( conditionalModels . Count > 0 )
if ( conditionalModels . Count > 0 )
{
{
return ( queryable. Where ( conditionalModels) , ruleInfo . RuleScope , additions ) ; //自定义查询
return ( conditionalModels, ruleInfo . RuleScope , additions ) ; //自定义查询
}
}
else
else
{
{
contidions . Add ( new ConditionalModel { FieldName = "CreateBy" , ConditionalType = ConditionalType . Equal , FieldValue = user . UserId } ) ;
contidions . Add ( new ConditionalModel { FieldName = "CreateBy" , ConditionalType = ConditionalType . Equal , FieldValue = user . UserId } ) ;
return ( queryable. Where ( contidions) , ruleInfo . RuleScope , otherContidions ) ; //查询创建人自身信息
return ( contidions, ruleInfo . RuleScope , otherContidions ) ; //查询创建人自身信息
}
}
}
}
@ -1691,13 +1691,13 @@ public class CommonService : ICommonService
var additions = ConvertConditionalModel ( ruleInfo . AdditionDataRules ) ;
var additions = ConvertConditionalModel ( ruleInfo . AdditionDataRules ) ;
if ( conditionalModels . Count > 0 )
if ( conditionalModels . Count > 0 )
{
{
return ( queryable. Where ( conditionalModels) , ruleInfo . RuleScope , additions ) ; //自定义查询
return ( conditionalModels, ruleInfo . RuleScope , additions ) ; //自定义查询
}
}
else
else
{
{
var deptUsers = db . Queryable < SysUser > ( ) . Where ( x = > x . DeptId = = userInfo . DeptId ) . Select ( x = > x . Id ) . ToList ( ) ;
var deptUsers = db . Queryable < SysUser > ( ) . Where ( x = > x . DeptId = = userInfo . DeptId ) . Select ( x = > x . Id ) . ToList ( ) ;
contidions . Add ( new ConditionalModel { FieldName = "CreateBy" , ConditionalType = ConditionalType . In , FieldValue = string . Join ( "," , deptUsers ) } ) ;
contidions . Add ( new ConditionalModel { FieldName = "CreateBy" , ConditionalType = ConditionalType . In , FieldValue = string . Join ( "," , deptUsers ) } ) ;
return ( queryable. Where ( contidions) , ruleInfo . RuleScope , additions ) ; //查询本部门
return ( contidions, ruleInfo . RuleScope , additions ) ; //查询本部门
}
}
}
}
else if ( ruleInfo . RuleScope = = "select_org" )
else if ( ruleInfo . RuleScope = = "select_org" )
@ -1708,14 +1708,14 @@ public class CommonService : ICommonService
// db.ConfigQuery.Context.Utilities.JsonToConditionalModels(
// db.ConfigQuery.Context.Utilities.JsonToConditionalModels(
// JsonConvert.SerializeObject(conditions));
// JsonConvert.SerializeObject(conditions));
var additions = ConvertConditionalModel ( ruleInfo . AdditionDataRules ) ;
var additions = ConvertConditionalModel ( ruleInfo . AdditionDataRules ) ;
return ( queryable. ClearFilter < IOrgId > ( ) . ClearFilter < ISharedOrgId > ( ) . Where ( conditionalModels) , ruleInfo . RuleScope , additions ) ; //查询指定机构
return ( conditionalModels, ruleInfo . RuleScope , additions ) ; //查询指定机构
}
}
else if ( ruleInfo . RuleScope = = "select_user" )
else if ( ruleInfo . RuleScope = = "select_user" )
{
{
//var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
//var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
var conditionalModels = ConvertConditionalModel ( ruleInfo . DataRules ) ;
var conditionalModels = ConvertConditionalModel ( ruleInfo . DataRules ) ;
var additions = ConvertConditionalModel ( ruleInfo . AdditionDataRules ) ;
var additions = ConvertConditionalModel ( ruleInfo . AdditionDataRules ) ;
return ( queryable. ClearFilter < IOrgId > ( ) . ClearFilter < ISharedOrgId > ( ) . Where ( conditionalModels) , ruleInfo . RuleScope , additions ) ; //查询指定人员
return ( conditionalModels, ruleInfo . RuleScope , additions ) ; //查询指定人员
}
}
else if ( ruleInfo . RuleScope = = "customize" )
else if ( ruleInfo . RuleScope = = "customize" )
@ -1723,15 +1723,15 @@ public class CommonService : ICommonService
//var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
//var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
var conditionalModels = ConvertConditionalModel ( ruleInfo . DataRules ) ;
var conditionalModels = ConvertConditionalModel ( ruleInfo . DataRules ) ;
var additions = ConvertConditionalModel ( ruleInfo . AdditionDataRules ) ;
var additions = ConvertConditionalModel ( ruleInfo . AdditionDataRules ) ;
return ( queryable. Where ( conditionalModels) , ruleInfo . RuleScope , additions ) ; //自定义查询
return ( conditionalModels, ruleInfo . RuleScope , additions ) ; //自定义查询
}
}
else if ( ruleInfo . DataRules . IsNull ( ) )
else if ( ruleInfo . DataRules . IsNull ( ) )
{
{
contidions . Add ( new ConditionalModel { FieldName = "CreateBy" , ConditionalType = ConditionalType . Equal , FieldValue = user . UserId } ) ;
contidions . Add ( new ConditionalModel { FieldName = "CreateBy" , ConditionalType = ConditionalType . Equal , FieldValue = user . UserId } ) ;
return ( queryable. Where ( contidions) , ruleInfo . RuleScope , otherContidions ) ; //没有设置数据规则,那么视为该资源允许被创建人查看
return ( contidions, ruleInfo . RuleScope , otherContidions ) ; //没有设置数据规则,那么视为该资源允许被创建人查看
}
}
return ( queryable , ruleInfo . RuleScope , otherContidions ) ;
return ( contidions , ruleInfo . RuleScope , otherContidions ) ;
# endregion
# endregion
}
}