|
|
|
@ -27,6 +27,8 @@ using DS.Module.Core.Constants;
|
|
|
|
|
using DS.WMS.Core.Op.Entity;
|
|
|
|
|
using DS.Module.Core.Data;
|
|
|
|
|
using DS.WMS.Core.TaskPlat.Entity;
|
|
|
|
|
using DS.WMS.Core.Invoice.Dtos;
|
|
|
|
|
using DS.WMS.Core.Op.Method;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Sys.Method;
|
|
|
|
|
|
|
|
|
@ -42,7 +44,6 @@ public class CommonService : ICommonService
|
|
|
|
|
private readonly IHttpContextAccessor IhttpContext;
|
|
|
|
|
private readonly IWebHostEnvironment _environment;
|
|
|
|
|
private readonly ILogger<CommonService> _logger;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 任务台基础表自定义列对应的Code
|
|
|
|
|
/// </summary>
|
|
|
|
@ -1582,6 +1583,151 @@ public class CommonService : ICommonService
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取当前用户的可视权限范围
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
/// <param name="tenantDb"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<(ISugarQueryable<T> queryable, string? ruleScope)> GetVisibleDataRuleFilter<T>(ISugarQueryable<T> queryable,SqlSugarScopeProvider tenantDb)
|
|
|
|
|
{
|
|
|
|
|
// 因为TaskBaseAllocation不能继承IOrgId,所以在这里根据条件,在需要的时候手动添加IOrgId查询筛选器
|
|
|
|
|
bool isTask = typeof(T) == typeof(TaskBaseAllocation);
|
|
|
|
|
|
|
|
|
|
var userInfo = db.Queryable<SysUser>().First(x => x.Id == long.Parse(user.UserId));
|
|
|
|
|
if (userInfo.UserType == 0)
|
|
|
|
|
{
|
|
|
|
|
if (isTask) queryable.Filter(typeof(IOrgId));
|
|
|
|
|
|
|
|
|
|
return (queryable, "all"); //超级管理员特权
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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>()
|
|
|
|
|
.First(u => u.UserId == long.Parse(user.UserId) && u.PermissionEntity.ToLower() == "infoclient" && u.Status == StatusEnum.Enable);
|
|
|
|
|
if (rule.IsNull())
|
|
|
|
|
{
|
|
|
|
|
return (queryable, null); //默认查询
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var contidions = new List<IConditionalModel>();
|
|
|
|
|
#region 可视权限
|
|
|
|
|
|
|
|
|
|
if ((long)rule.VisibleTemplateId == 0)
|
|
|
|
|
{
|
|
|
|
|
contidions.Add(new ConditionalModel { FieldName = "CreateBy", ConditionalType = ConditionalType.Equal, FieldValue = user.UserId });
|
|
|
|
|
return (queryable.Where(contidions), "self"); //查询自身
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ruleInfo = tenantDb.Queryable<CodeDataRuleTemplate>().First(x => x.Id == (long)rule.VisibleTemplateId);
|
|
|
|
|
if (ruleInfo.RuleScope == "all")
|
|
|
|
|
{
|
|
|
|
|
return (queryable.ClearFilter<IOrgId>(), ruleInfo.RuleScope); //查询全部
|
|
|
|
|
}
|
|
|
|
|
else if (ruleInfo.RuleScope == "none")
|
|
|
|
|
{
|
|
|
|
|
if (isTask)
|
|
|
|
|
{ return (queryable, ruleInfo.RuleScope); }
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SqlSugar.Check.ExceptionEasy("NO Operation", "没有数据查看权限!");//返回提示
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ruleInfo.RuleScope == "self_org")
|
|
|
|
|
{
|
|
|
|
|
if (isTask) queryable.Filter(typeof(IOrgId));
|
|
|
|
|
var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
|
|
|
|
|
if (conditionalModels.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
return (queryable.Where(conditionalModels), ruleInfo.RuleScope);//自定义查询
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return (queryable, ruleInfo.RuleScope);//默认查询
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ruleInfo.RuleScope == "self_org_with_child") // 当前机构及下属机构
|
|
|
|
|
{
|
|
|
|
|
List<SysOrg> orgList = await db.Queryable<SysOrg>().ToChildListAsync(s => s.ParentId, user.OrgId);
|
|
|
|
|
IEnumerable<long> orgIdList = orgList.Select(x => x.Id);
|
|
|
|
|
contidions.Add(new ConditionalModel { FieldName = "OrgId", ConditionalType = ConditionalType.In, FieldValue = string.Join(",", orgIdList) });
|
|
|
|
|
|
|
|
|
|
return (queryable.Where(contidions), ruleInfo.RuleScope);
|
|
|
|
|
}
|
|
|
|
|
else if (ruleInfo.RuleScope == "self")
|
|
|
|
|
{
|
|
|
|
|
var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
|
|
|
|
|
if (conditionalModels.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
return (queryable.Where(conditionalModels), ruleInfo.RuleScope);//自定义查询
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
contidions.Add(new ConditionalModel { FieldName = "CreateBy", ConditionalType = ConditionalType.Equal, FieldValue = user.UserId });
|
|
|
|
|
return (queryable.Where(contidions), ruleInfo.RuleScope); //查询创建人自身信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (ruleInfo.RuleScope == "self_dept")
|
|
|
|
|
{
|
|
|
|
|
if (String.IsNullOrEmpty(userInfo.DeptName))
|
|
|
|
|
{
|
|
|
|
|
if (!isTask)
|
|
|
|
|
{
|
|
|
|
|
SqlSugar.Check.ExceptionEasy("NO Operation", "当前员工没有默认归属部门!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
|
|
|
|
|
if (conditionalModels.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
return (queryable.Where(conditionalModels), ruleInfo.RuleScope);//自定义查询
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
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) });
|
|
|
|
|
return (queryable.Where(contidions), ruleInfo.RuleScope); //查询本部门
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ruleInfo.RuleScope == "select_org")
|
|
|
|
|
{
|
|
|
|
|
var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
|
|
|
|
|
//var conditions = ruleInfo.DataRules.ConvertSqlSugarExpression();
|
|
|
|
|
//var conditionalModels =
|
|
|
|
|
// db.ConfigQuery.Context.Utilities.JsonToConditionalModels(
|
|
|
|
|
// JsonConvert.SerializeObject(conditions));
|
|
|
|
|
return (queryable.ClearFilter<IOrgId>().Where(conditionalModels), ruleInfo.RuleScope); //查询指定机构
|
|
|
|
|
}
|
|
|
|
|
else if (ruleInfo.RuleScope == "select_user")
|
|
|
|
|
{
|
|
|
|
|
//var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
|
|
|
|
|
var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
|
|
|
|
|
return (queryable.ClearFilter<IOrgId>().Where(conditionalModels), ruleInfo.RuleScope);//查询指定人员
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (ruleInfo.RuleScope == "customize")
|
|
|
|
|
{
|
|
|
|
|
//var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
|
|
|
|
|
var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
|
|
|
|
|
return (queryable.Where(conditionalModels), ruleInfo.RuleScope);//自定义查询
|
|
|
|
|
}
|
|
|
|
|
else if (ruleInfo.DataRules.IsNull())
|
|
|
|
|
{
|
|
|
|
|
contidions.Add(new ConditionalModel { FieldName = "CreateBy", ConditionalType = ConditionalType.Equal, FieldValue = user.UserId });
|
|
|
|
|
return (queryable.Where(contidions), ruleInfo.RuleScope); //没有设置数据规则,那么视为该资源允许被创建人查看
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (queryable, ruleInfo.RuleScope);
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<IConditionalModel> ConvertConditionalModel(string rules)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|