|
|
@ -25,6 +25,7 @@ using DS.WMS.Core.Flow.Dtos;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
using DS.Module.Core.Constants;
|
|
|
|
using DS.Module.Core.Constants;
|
|
|
|
using DS.WMS.Core.Op.Entity;
|
|
|
|
using DS.WMS.Core.Op.Entity;
|
|
|
|
|
|
|
|
using DS.Module.Core.Data;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Sys.Method;
|
|
|
|
namespace DS.WMS.Core.Sys.Method;
|
|
|
|
|
|
|
|
|
|
|
@ -1434,6 +1435,82 @@ public class CommonService : ICommonService
|
|
|
|
return conditionalModels;
|
|
|
|
return conditionalModels;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 获取当前用户的可视权限范围
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
|
|
|
/// <param name="tenantDb"></param>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
public ISugarQueryable<T> GetVisibleDataRuleFilter<T>(SqlSugarScopeProvider tenantDb)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var userInfo = db.Queryable<SysUser>().First(x => x.Id == long.Parse(user.UserId));
|
|
|
|
|
|
|
|
if (userInfo.UserType == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return db.Queryable<T>(); //超级管理员特权
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (rule == null) return db.Queryable<T>(); //没有设置数据规则,那么视为该资源允许被任何主体查看
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 可视权限
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((long)rule.VisibleTemplateId == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return db.Queryable<T>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ruleInfo = tenantDb.Queryable<CodeDataRuleTemplate>().First(x => x.Id == (long)rule.VisibleTemplateId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ruleInfo.DataRules.IsNull())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return db.Queryable<T>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ruleInfo.RuleScope == "all")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return db.Queryable<T>().ClearFilter<IOrgId>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ruleInfo.RuleScope == "none")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
SqlSugar.Check.ExceptionEasy("NO Operation", "没有数据查看权限!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ruleInfo.RuleScope == "self")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ruleInfo.DataRules = ruleInfo.DataRules.Replace(DataRuleConst.LoginUser, user.UserId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ruleInfo.RuleScope == "self_org")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ruleInfo.DataRules = ruleInfo.DataRules.Replace(DataRuleConst.LoginOrg, userInfo.DefaultOrgId.ToString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ruleInfo.RuleScope == "self_dept")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var deptUsers = db.Queryable<SysUser>().Where(x => x.DeptId == userInfo.DeptId).Select(x => x.Id).ToList();
|
|
|
|
|
|
|
|
ruleInfo.DataRules = ruleInfo.DataRules.Replace(DataRuleConst.LoginDept, string.Join(",", deptUsers));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ruleInfo.RuleScope == "select_org")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var orgUsers = db.Queryable<SysUser>().Where(x => x.DefaultOrgId == userInfo.DefaultOrgId).Select(x => x.Id).ToList();
|
|
|
|
|
|
|
|
ruleInfo.DataRules = ruleInfo.DataRules.Replace(DataRuleConst.LoginDept, string.Join(",", orgUsers));
|
|
|
|
|
|
|
|
var conditions1 = ruleInfo.DataRules.ConvertSqlSugarExpression();
|
|
|
|
|
|
|
|
var conditionalModels1 =
|
|
|
|
|
|
|
|
db.ConfigQuery.Context.Utilities.JsonToConditionalModels(
|
|
|
|
|
|
|
|
JsonConvert.SerializeObject(conditions1));
|
|
|
|
|
|
|
|
return db.Queryable<T>().ClearFilter<IOrgId>().Where(conditionalModels1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var conditions = ruleInfo.DataRules.ConvertSqlSugarExpression();
|
|
|
|
|
|
|
|
var conditionalModels =
|
|
|
|
|
|
|
|
db.ConfigQuery.Context.Utilities.JsonToConditionalModels(
|
|
|
|
|
|
|
|
JsonConvert.SerializeObject(conditions));
|
|
|
|
|
|
|
|
return db.Queryable<T>().Where(conditionalModels);
|
|
|
|
|
|
|
|
}
|
|
|
|
#region 获取数据库表及字段属性
|
|
|
|
#region 获取数据库表及字段属性
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|