|
|
@ -1594,49 +1594,47 @@ 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)> GetVisibleDataRuleFilter<T>(ISugarQueryable<T> queryable,SqlSugarScopeProvider tenantDb)
|
|
|
|
public async Task<(ISugarQueryable<T> queryable, string? ruleScope, List<IConditionalModel>? contidions)> 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);
|
|
|
|
|
|
|
|
var contidions = new List<IConditionalModel>();
|
|
|
|
|
|
|
|
var otherContidions = new List<IConditionalModel>();
|
|
|
|
var userInfo = db.Queryable<SysUser>().First(x => x.Id == long.Parse(user.UserId));
|
|
|
|
var userInfo = db.Queryable<SysUser>().First(x => x.Id == long.Parse(user.UserId));
|
|
|
|
if (userInfo.UserType == 0)
|
|
|
|
if (userInfo.UserType == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (isTask) queryable.Filter(typeof(IOrgId));
|
|
|
|
if (isTask) queryable.Filter(typeof(IOrgId));
|
|
|
|
|
|
|
|
|
|
|
|
return (queryable, "all"); //超级管理员特权
|
|
|
|
return (queryable, "all", otherContidions); //超级管理员特权
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var moduleName = typeof(T).Name.ToLower();
|
|
|
|
var moduleName = typeof(T).Name.ToLower();
|
|
|
|
|
|
|
|
|
|
|
|
//var rule = tenantDb.Queryable<CodeDataRule>()
|
|
|
|
|
|
|
|
// .First(u => u.UserId == long.Parse(user.UserId) && u.PermissionEntity.ToLower() == moduleName && u.Status == StatusEnum.Enable);
|
|
|
|
|
|
|
|
var rule = tenantDb.Queryable<CodeDataRule>()
|
|
|
|
var rule = tenantDb.Queryable<CodeDataRule>()
|
|
|
|
.First(u => u.UserId == long.Parse(user.UserId) && u.PermissionEntity.ToLower() == "infoclient" && 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); //默认查询
|
|
|
|
return (queryable, null, otherContidions); //默认查询
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var contidions = new List<IConditionalModel>();
|
|
|
|
|
|
|
|
#region 可视权限
|
|
|
|
#region 可视权限
|
|
|
|
|
|
|
|
|
|
|
|
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"); //查询自身
|
|
|
|
return (queryable.Where(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>(), ruleInfo.RuleScope); //查询全部
|
|
|
|
return (queryable.ClearFilter<IOrgId>(), ruleInfo.RuleScope, otherContidions); //查询全部
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ruleInfo.RuleScope == "none")
|
|
|
|
else if (ruleInfo.RuleScope == "none")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (isTask)
|
|
|
|
if (isTask)
|
|
|
|
{ return (queryable, ruleInfo.RuleScope); }
|
|
|
|
{ return (queryable, ruleInfo.RuleScope, otherContidions); }
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SqlSugar.Check.ExceptionEasy("NO Operation", "没有数据查看权限!");//返回提示
|
|
|
|
SqlSugar.Check.ExceptionEasy("NO Operation", "没有数据查看权限!");//返回提示
|
|
|
@ -1646,13 +1644,14 @@ public class CommonService : ICommonService
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (isTask) queryable.Filter(typeof(IOrgId));
|
|
|
|
if (isTask) queryable.Filter(typeof(IOrgId));
|
|
|
|
var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
|
|
|
|
var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
|
|
|
|
|
|
|
|
var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules);
|
|
|
|
if (conditionalModels.Count > 0)
|
|
|
|
if (conditionalModels.Count > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return (queryable.Where(conditionalModels), ruleInfo.RuleScope);//自定义查询
|
|
|
|
return (queryable.Where(conditionalModels), ruleInfo.RuleScope, additions);//自定义查询
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return (queryable, ruleInfo.RuleScope);//默认查询
|
|
|
|
return (queryable.Where(contidions), ruleInfo.RuleScope, otherContidions);//默认查询
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ruleInfo.RuleScope == "self_org_with_child") // 当前机构及下属机构
|
|
|
|
else if (ruleInfo.RuleScope == "self_org_with_child") // 当前机构及下属机构
|
|
|
@ -1661,19 +1660,20 @@ 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);
|
|
|
|
return (queryable.Where(contidions), ruleInfo.RuleScope, otherContidions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ruleInfo.RuleScope == "self")
|
|
|
|
else if (ruleInfo.RuleScope == "self")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
|
|
|
|
var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
|
|
|
|
|
|
|
|
var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules);
|
|
|
|
if (conditionalModels.Count > 0)
|
|
|
|
if (conditionalModels.Count > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return (queryable.Where(conditionalModels), ruleInfo.RuleScope);//自定义查询
|
|
|
|
return (queryable.Where(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); //查询创建人自身信息
|
|
|
|
return (queryable.Where(contidions), ruleInfo.RuleScope, otherContidions); //查询创建人自身信息
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1687,15 +1687,16 @@ public class CommonService : ICommonService
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
|
|
|
|
var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
|
|
|
|
|
|
|
|
var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules);
|
|
|
|
if (conditionalModels.Count > 0)
|
|
|
|
if (conditionalModels.Count > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return (queryable.Where(conditionalModels), ruleInfo.RuleScope);//自定义查询
|
|
|
|
return (queryable.Where(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); //查询本部门
|
|
|
|
return (queryable.Where(contidions), ruleInfo.RuleScope, contidions); //查询本部门
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ruleInfo.RuleScope == "select_org")
|
|
|
|
else if (ruleInfo.RuleScope == "select_org")
|
|
|
@ -1705,28 +1706,31 @@ public class CommonService : ICommonService
|
|
|
|
//var conditionalModels =
|
|
|
|
//var conditionalModels =
|
|
|
|
// db.ConfigQuery.Context.Utilities.JsonToConditionalModels(
|
|
|
|
// db.ConfigQuery.Context.Utilities.JsonToConditionalModels(
|
|
|
|
// JsonConvert.SerializeObject(conditions));
|
|
|
|
// JsonConvert.SerializeObject(conditions));
|
|
|
|
return (queryable.ClearFilter<IOrgId>().Where(conditionalModels), ruleInfo.RuleScope); //查询指定机构
|
|
|
|
var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules);
|
|
|
|
|
|
|
|
return (queryable.ClearFilter<IOrgId>().Where(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);
|
|
|
|
return (queryable.ClearFilter<IOrgId>().Where(conditionalModels), ruleInfo.RuleScope);//查询指定人员
|
|
|
|
var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules);
|
|
|
|
|
|
|
|
return (queryable.ClearFilter<IOrgId>().Where(conditionalModels), ruleInfo.RuleScope, additions);//查询指定人员
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
else if (ruleInfo.RuleScope == "customize")
|
|
|
|
else if (ruleInfo.RuleScope == "customize")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
|
|
|
|
//var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
|
|
|
|
var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
|
|
|
|
var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
|
|
|
|
return (queryable.Where(conditionalModels), ruleInfo.RuleScope);//自定义查询
|
|
|
|
var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules);
|
|
|
|
|
|
|
|
return (queryable.Where(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); //没有设置数据规则,那么视为该资源允许被创建人查看
|
|
|
|
return (queryable.Where(contidions), ruleInfo.RuleScope, otherContidions); //没有设置数据规则,那么视为该资源允许被创建人查看
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (queryable, ruleInfo.RuleScope);
|
|
|
|
return (queryable, ruleInfo.RuleScope, otherContidions);
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|
|
|
|