数据权限相关

master
ZR20090193-陈敬勇 9 months ago
parent 458ebe47c9
commit 4d45830b64

@ -0,0 +1,22 @@
using System.ComponentModel;
namespace DS.Module.Core;
/// <summary>
/// 数据权限常量
/// </summary>
public static class DataRuleConst
{
/// <summary>
/// 数据权限配置中当前登录用户的key
/// </summary>
public const string LoginUser = "{loginUser}";
/// <summary>
/// 数据权限配置中当前登录角色的key
/// </summary>
public const string LoginRole = "{loginRole}";
/// <summary>
/// 数据权限配置中当前登录机构的key
/// </summary>
public const string LoginOrg = "{loginOrg}";
}

@ -70,6 +70,9 @@ public static class MultiLanguageConst
[Description("权限模块不存在")]
public const string PermissionNotExist = "Permission_NotExist";
[Description("数据权限已存在")]
public const string DataRuleExist = "Data_Rule_Exist";
/// <summary>
/// 非法请求
/// </summary>

@ -0,0 +1,43 @@
namespace DS.Module.Core.Data;
/// <summary>
/// 数据条件组
/// </summary>
public class DataGroupConditions
{
/// <summary>
/// 逻辑操作符
/// </summary>
public string LogicalOperator { get; set; }
/// <summary>
/// 条件组
/// </summary>
public List<DataConditions> Conditions { get; set; }
/// <summary>
/// 分组
/// </summary>
public List<DataGroupConditions> Groups { get; set; }
}
/// <summary>
/// 条件
/// </summary>
public class DataConditions
{
/// <summary>
/// 字段
/// </summary>
public string Field { get; set; }
/// <summary>
/// 操作符
/// </summary>
public string Operator { get; set; }
/// <summary>
/// 值
/// </summary>
public string Value { get; set; }
}

@ -1,5 +1,7 @@
using SqlSugar;
using System.ComponentModel;
using DS.Module.Core.Data;
using Newtonsoft.Json;
namespace DS.Module.Core.Extensions;
@ -35,14 +37,15 @@ public static partial class Extensions
/// <param name="page"></param>
/// <typeparam name="TEntity"></typeparam>
/// <returns></returns>
public static DataResult<List<TEntity>> ToQueryPage<TEntity>(this ISugarQueryable<TEntity> source, PageCondition page)
public static DataResult<List<TEntity>> ToQueryPage<TEntity>(this ISugarQueryable<TEntity> source,
PageCondition page)
{
page.NotNull(nameof(page));
var result = source.WhereAsync(page.PageIndex, page.PageSize, page.SortConditions);
var list = result.data;
var total = result.totalNumber;
return DataResult<List<TEntity>>.PageList(total, list,MultiLanguageConst.DataQuerySuccess);
return DataResult<List<TEntity>>.PageList(total, list, MultiLanguageConst.DataQuerySuccess);
}
/// <summary>
@ -79,4 +82,191 @@ public static partial class Extensions
? source.ToPageList(pageIndex, pageSize, ref total)
: Enumerable.Empty<TEntity>().ToList(), total);
}
/// <summary>
/// 转换SqlSugar条件查询表达式
/// </summary>
/// <param name="ruleStr"></param>
/// <returns></returns>
public static List<ConditionalCollections> ConvertSqlSugarExpression(this string ruleStr)
{
var conditions = JsonConvert.DeserializeObject<DataGroupConditions>(ruleStr);
var conditionalCollections = new List<ConditionalCollections>();
if (conditions.LogicalOperator == "and")
{
var conditionList = new List<KeyValuePair<WhereType, ConditionalModel>>();
foreach (var item in conditions.Conditions)
{
conditionList.Add(new KeyValuePair<WhereType, ConditionalModel>
(WhereType.And,
new ConditionalModel
{
FieldName = item.Field, ConditionalType = GetConditionalType(item.Operator),
FieldValue = item.Value
})
);
}
if (conditionList.Count > 0)
{
conditionalCollections.Add(new ConditionalCollections
{
ConditionalList = conditionList
}
)
;
}
var groupList = new List<KeyValuePair<WhereType, ConditionalModel>>();
foreach (var group in conditions.Groups)
{
if (group.LogicalOperator == "and")
{
foreach (var item1 in group.Conditions)
{
groupList.Add(new KeyValuePair<WhereType, ConditionalModel>
(WhereType.And,
new ConditionalModel
{
FieldName = item1.Field, ConditionalType = GetConditionalType(item1.Operator),
FieldValue = item1.Value
})
);
}
}
else
{
foreach (var item1 in group.Conditions)
{
groupList.Add(new KeyValuePair<WhereType, ConditionalModel>
(WhereType.Or,
new ConditionalModel
{
FieldName = item1.Field, ConditionalType =GetConditionalType(item1.Operator),
FieldValue = item1.Value
})
);
}
}
}
if (groupList.Count > 0)
{
conditionalCollections.Add(new ConditionalCollections
{
ConditionalList = groupList
}
)
;
}
}
else
{
var conditionList = new List<KeyValuePair<WhereType, ConditionalModel>>();
foreach (var item in conditions.Conditions)
{
conditionList.Add(new KeyValuePair<WhereType, ConditionalModel>
(WhereType.Or,
new ConditionalModel
{
FieldName = item.Field, ConditionalType = GetConditionalType(item.Operator),
FieldValue = item.Value
})
);
}
if (conditionList.Count > 0)
{
conditionalCollections.Add(new ConditionalCollections
{
ConditionalList = conditionList
}
)
;
}
var groupList = new List<KeyValuePair<WhereType, ConditionalModel>>();
foreach (var group in conditions.Groups)
{
if (group.LogicalOperator == "and")
{
foreach (var item1 in group.Conditions)
{
groupList.Add(new KeyValuePair<WhereType, ConditionalModel>
(WhereType.And,
new ConditionalModel
{
FieldName = item1.Field, ConditionalType = GetConditionalType(item1.Operator),
FieldValue = item1.Value
})
);
}
}
else
{
foreach (var item1 in group.Conditions)
{
groupList.Add(new KeyValuePair<WhereType, ConditionalModel>
(WhereType.Or,
new ConditionalModel
{
FieldName = item1.Field, ConditionalType = GetConditionalType(item1.Operator),
FieldValue = item1.Value
})
);
}
}
}
if (groupList.Count > 0)
{
conditionalCollections.Add(new ConditionalCollections
{
ConditionalList = groupList
}
)
;
}
}
return conditionalCollections;
}
/// <summary>
/// 转换SqlSugar 条件操作符
/// </summary>
/// <param name="conditionalType"></param>
/// <returns></returns>
private static ConditionalType GetConditionalType(string conditionalType)
{
switch (conditionalType)
{
//等于
case "equal":
return ConditionalType.Equal;
//不等于
case "not_equal":
return ConditionalType.NoEqual;
//大于
case "GreaterThan":
return ConditionalType.GreaterThan;
//大于等于
case "GreaterThanOrEqual":
return ConditionalType.GreaterThanOrEqual;
//小于
case "LessThan":
return ConditionalType.LessThan;
//小于等于
case "LessThanOrEqual":
return ConditionalType.GreaterThanOrEqual;
//包含
case "contains":
return ConditionalType.In;
//不包含
case "not_contain":
return ConditionalType.NotIn;
//默认
default:
return ConditionalType.Equal;
}
}
}

@ -80,7 +80,7 @@ public class ClientFlowTemplateService : IClientFlowTemplateService
}
var data = info.Adapt<FlowTemplateTenant>();
db.Insertable(info).ExecuteCommand();
db.Insertable(data).ExecuteCommand();
return DataResult.Successed("引入成功!",MultiLanguageConst.DataImportSuccess);
}

@ -182,7 +182,7 @@ public class FlowInstanceService : IFlowInstanceService
instance.ActivityType = wfruntime.GetNodeType(startNodeId);
instance.ActivityName = wfruntime.ChildNodes.First(x => x.Id == startNodeId).Name;
instance.MakerList =
(wfruntime.GetNextNodeType() != 4 ? GetCurrentMakers(wfruntime) : "");
(wfruntime.GetNextNodeType() != 4 ? GetCurrentMakers(wfruntime) : "1");
instance.FlowStatus = FlowStatusEnum.Draft.ToEnumInt();
wfruntime.FlowInstanceId = instance.Id;
@ -243,7 +243,7 @@ public class FlowInstanceService : IFlowInstanceService
instance.ActivityName = wfruntime.NextNode.Name;
instance.PreviousId = wfruntime.CurrentNodeId;
instance.MakerList =
(wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : "");
(wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : "1");
instance.FlowStatus = (wfruntime.GetNextNodeType() == 4
? FlowStatusEnum.Approve.ToEnumInt()
: FlowStatusEnum.Running.ToEnumInt());
@ -318,7 +318,7 @@ public class FlowInstanceService : IFlowInstanceService
? FlowStatusEnum.Approve.ToEnumInt()
: FlowStatusEnum.Running.ToEnumInt());
instance.MakerList =
(wfruntime.NextNodeType == 4 ? "" : GetNextMakers(wfruntime));
(wfruntime.NextNodeType == 4 ? "1" : GetNextMakers(wfruntime));
// AddTransHistory(wfruntime);
}
@ -343,7 +343,7 @@ public class FlowInstanceService : IFlowInstanceService
instance.ActivityId = wfruntime.NextNodeId;
instance.ActivityType = wfruntime.NextNodeType;
instance.ActivityName = wfruntime.NextNode.Name;
instance.MakerList = wfruntime.NextNodeType == 4 ? "" : GetNextMakers(wfruntime);
instance.MakerList = wfruntime.NextNodeType == 4 ? "1" : GetNextMakers(wfruntime);
instance.FlowStatus = (wfruntime.NextNodeType == 4
? FlowStatusEnum.Approve.ToEnumInt()
: FlowStatusEnum.Running.ToEnumInt());

@ -245,7 +245,7 @@ public class FlowRuntimeService
(WhereType.And,
new ConditionalModel
{
FieldName = item.Field, ConditionalType = ConditionalType.Equal,
FieldName = item.Field, ConditionalType = GetConditionalType(item.Operator),
FieldValue = item.Value
})
);
@ -272,7 +272,7 @@ public class FlowRuntimeService
(WhereType.And,
new ConditionalModel
{
FieldName = item1.Field, ConditionalType = ConditionalType.Equal,
FieldName = item1.Field, ConditionalType = GetConditionalType(item1.Operator),
FieldValue = item1.Value
})
);
@ -286,7 +286,7 @@ public class FlowRuntimeService
(WhereType.Or,
new ConditionalModel
{
FieldName = item1.Field, ConditionalType = ConditionalType.Equal,
FieldName = item1.Field, ConditionalType = GetConditionalType(item1.Operator),
FieldValue = item1.Value
})
);
@ -313,7 +313,7 @@ public class FlowRuntimeService
(WhereType.Or,
new ConditionalModel
{
FieldName = item.Field, ConditionalType = ConditionalType.Equal,
FieldName = item.Field, ConditionalType = GetConditionalType(item.Operator),
FieldValue = item.Value
})
);
@ -340,7 +340,7 @@ public class FlowRuntimeService
(WhereType.And,
new ConditionalModel
{
FieldName = item1.Field, ConditionalType = ConditionalType.Equal,
FieldName = item1.Field, ConditionalType = GetConditionalType(item1.Operator),
FieldValue = item1.Value
})
);
@ -354,7 +354,7 @@ public class FlowRuntimeService
(WhereType.Or,
new ConditionalModel
{
FieldName = item1.Field, ConditionalType = ConditionalType.Equal,
FieldName = item1.Field, ConditionalType = GetConditionalType(item1.Operator),
FieldValue = item1.Value
})
);
@ -501,7 +501,44 @@ public class FlowRuntimeService
return -1;
}
/// <summary>
/// 转换SqlSugar 条件操作符
/// </summary>
/// <param name="conditionalType"></param>
/// <returns></returns>
private static ConditionalType GetConditionalType(string conditionalType)
{
switch (conditionalType)
{
//等于
case "equal":
return ConditionalType.Equal;
//不等于
case "not_equal":
return ConditionalType.NoEqual;
//大于
case "GreaterThan":
return ConditionalType.GreaterThan;
//大于等于
case "GreaterThanOrEqual":
return ConditionalType.GreaterThanOrEqual;
//小于
case "LessThan":
return ConditionalType.LessThan;
//小于等于
case "LessThanOrEqual":
return ConditionalType.GreaterThanOrEqual;
//包含
case "contains":
return ConditionalType.In;
//不包含
case "not_contain":
return ConditionalType.NotIn;
//默认
default:
return ConditionalType.Equal;
}
}
/// <summary>
/// 获取节点类型 0会签开始,1会签结束,2一般节点,3开始节点,4流程运行结束
/// </summary>

@ -0,0 +1,22 @@
namespace DS.WMS.Core.System.Dtos;
/// <summary>
/// 客户权限返回
/// </summary>
public class ClientPermissionRes
{
/// <summary>
/// 主键Id
/// </summary>
public long Id { get; set; }
/// <summary>
/// 权限名称
/// </summary>
public string PermissionName { get; set; }
/// <summary>
/// 权限实体
/// </summary>
public string PermissionEntity { get; set; }
}

@ -0,0 +1,59 @@
using DS.Module.Core;
using FluentValidation;
namespace DS.WMS.Core.System.Dtos;
/// <summary>
/// 数据权限请求实体
/// </summary>
public class DataRuleReq
{
/// <summary>
/// 主键Id
/// </summary>
public long Id { get; set; }
/// <summary>
/// 资源标识权限ID
/// </summary>
public long PermissionId { get; set; }
/// <summary>
/// 中文视图名
/// </summary>
public string ColumnView { get; set; }
/// <summary>
/// 权限规则
/// </summary>
public string DataRules { get; set; }
/// <summary>
/// 数据权限描述
/// </summary>
public string Description { get; set; }
/// <summary>
/// 状态 0 启用 1 禁用
/// </summary>
public StatusEnum? Status { get; set; } = StatusEnum.Enable;
/// <summary>
/// 备注
/// </summary>
public string Note { get; set; } = "";
}
/// <summary>
/// 验证
/// </summary>
public class DataRuleReqValidator : AbstractValidator<DataRuleReq>
{
/// <summary>
/// 构造函数
/// </summary>
public DataRuleReqValidator()
{
this.RuleFor(o => o.PermissionId)
.NotEmpty().WithName("权限模块Id");
this.RuleFor(o => o.ColumnView)
.NotEmpty().WithName("中文视图名");
}
}

@ -0,0 +1,49 @@
using DS.Module.Core;
namespace DS.WMS.Core.System.Dtos;
/// <summary>
/// 数据权限返回实体
/// </summary>
public class DataRuleRes
{
/// <summary>
/// 主键Id
/// </summary>
public long Id { get; set; }
/// <summary>
/// 资源标识权限ID
/// </summary>
public long PermissionId { get; set; }
/// <summary>
/// 中文视图名
/// </summary>
public string ColumnView { get; set; }
/// <summary>
/// 权限模块名称
/// </summary>
public string PermissionName { get; set; }
/// <summary>
/// 权限规则
/// </summary>
public string DataRules { get; set; }
/// <summary>
/// 数据权限描述
/// </summary>
public string Description { get; set; }
/// <summary>
/// 状态 0 启用 1 禁用
/// </summary>
public StatusEnum? Status { get; set; } = StatusEnum.Enable;
/// <summary>
/// 备注
/// </summary>
public string Note { get; set; } = "";
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreateTime { get; set; }
}

@ -1,25 +1,29 @@
using DS.Module.Core;
using DS.Module.Core.Data;
namespace DS.WMS.Core.System.Entity;
[SqlSugar.SugarTable("sys_datarule")]
public class SysDataRule : BaseModel<string>
[SqlSugar.SugarTable("sys_data_rule")]
public class SysDataRule : BaseTenantModel<long>
{
/// <summary>
/// 资源标识权限ID
/// </summary>
public string PermissionId { get; set; }
public long PermissionId { get; set; }
/// <summary>
/// 模块名称
/// 权限实体
/// </summary>
public string PermissionName { get; set; }
public string PermissionEntity { get; set; }
/// <summary>
/// 是否可用
/// 状态
/// </summary>
public string Enable { get; set; }
[SqlSugar.SugarColumn(ColumnDescription = "状态")]
public StatusEnum? Status { get; set; } = StatusEnum.Enable;
/// <summary>
/// 中文视图名
/// </summary>
public string ColumnView { get; set; }
/// <summary>
/// 权限规则
/// </summary>
@ -33,5 +37,5 @@ public class SysDataRule : BaseModel<string>
/// <summary>
/// 排序号
/// </summary>
public string SortNo { get; set; }
public string OrderNo { get; set; }
}

@ -118,7 +118,7 @@ public class SysPermission : BaseModel<long>
#endregion 拓展字段
/// <summary>
///权限实体
/// 权限实体
/// </summary>
public string PermissionEntity { get; set; }
}

@ -89,6 +89,11 @@ public interface ICommonService
/// <returns></returns>
DataResult<List<ApiSelectViewModel>> GetOrgList();
/// <summary>
/// 获取客户数据权限列表
/// </summary>
/// <returns></returns>
public DataResult<List<ClientPermissionRes>> GetClientPermissionList();
/// <summary>
/// 修改密码
/// </summary>

@ -1,9 +1,30 @@
using DS.Module.Core;
using DS.WMS.Core.System.Dtos;
using DS.WMS.Core.System.Entity;
namespace DS.WMS.Core.System.Interface;
public interface IDataRuleService
{
DataResult<List<SysDataRule>> GetListByPage(PageRequest request);
/// <summary>
/// 列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
DataResult<List<DataRuleRes>> GetListByPage(PageRequest request);
/// <summary>
/// 编辑
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
DataResult EditDataRule(DataRuleReq model);
/// <summary>
/// 获取详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
DataResult<DataRuleRes> GetDataRuleInfo(string id);
}

@ -781,6 +781,23 @@ public class CommonService : ICommonService
#endregion 获取机构下拉列表
#region 获取客户数据权限列表
/// <summary>
/// 获取客户数据权限列表
/// </summary>
/// <returns></returns>
public DataResult<List<ClientPermissionRes>> GetClientPermissionList()
{
var list = db.Queryable<SysPermission>().Where(x=> x.MenuType == 2 && x.IsHidden == false &&
(x.PermissionType == 1 || x.PermissionType == 0) && x.Id!=1744968217220222976 )
.Select<ClientPermissionRes>()
.ToList();
return DataResult<List<ClientPermissionRes>>.Success("获取数据成功!", list);
}
#endregion
#region 修改密码
/// <summary>
@ -954,44 +971,40 @@ public class CommonService : ICommonService
return db.Queryable<T>(); //超级管理员特权
}
var moduleName = typeof(T).Name;
var rule = db.Queryable<SysDataRule>().First(u => u.PermissionName == moduleName);
var moduleName = typeof(T).Name.ToLower();
var rule = db.Queryable<SysDataRule>().First(u => u.PermissionEntity.ToLower() == moduleName && u.Status == StatusEnum.Enable);
if (rule == null) return db.Queryable<T>(); //没有设置数据规则,那么视为该资源允许被任何主体查看
var ruleConditions = JsonConvert.DeserializeObject<DataRuleJson>(rule.DataRules);
if (ruleConditions.RoleCondition.Count > 0)
if (rule.DataRules.Contains(DataRuleConst.LoginUser))
{
var roles = db.Queryable<SysRoleUser>().Where(x => x.UserId == long.Parse(user.UserId))
.Select(u => u.RoleId.ToString()).ToList();
roles.Sort(); //按字母排序,这样可以进行like操作
var ruleCondition = ruleConditions.RoleCondition[0];
if (ruleCondition.ConditionalType == SqlSugar.ConditionalType.In)
{
var s = ruleCondition.FieldValue.Split(',');
var intersectArr = roles.Intersect(s);
if (intersectArr.Count() == 0)
{
throw new Exception("该用户角色无权限!");
}
}
//即把{loginUser} =='xxxxxxx'换为 user.UserId =='xxxxxxx'从而把当前登录的用户名与当时设计规则时选定的用户id对比
rule.DataRules = rule.DataRules.Replace(DataRuleConst.LoginUser, user.UserId);
}
if (ruleConditions.QueryCondition.Count > 0)
if (rule.DataRules.Contains(DataRuleConst.LoginRole))
{
return db.Queryable<T>()
.Where(ruleConditions.QueryCondition);
var roles = db.Queryable<SysRoleUser>().Where(x => x.UserId == long.Parse(user.UserId) ).Select(n => n.RoleId)
.ToList();
roles.Sort();
rule.DataRules = rule.DataRules.Replace(DataRuleConst.LoginRole, string.Join(',',roles));
}
else
if (rule.DataRules.Contains(DataRuleConst.LoginOrg))
{
return db.Queryable<T>();
var orgs = db.Queryable<SysOrgUser>().Where(x => x.UserId == long.Parse(user.UserId) ).Select(n => n.OrgId)
.ToList();
orgs.Sort();
rule.DataRules = rule.DataRules.Replace(DataRuleConst.LoginOrg, string.Join(',',orgs));
}
var conditions = rule.DataRules.ConvertSqlSugarExpression();
var conditionalModels =
db.ConfigQuery.Context.Utilities.JsonToConditionalModels(
JsonConvert.SerializeObject(conditions));
return db.Queryable<T>().Where(conditionalModels);
}
#region 获取数据库表及字段属性
/// <summary>

@ -1,8 +1,10 @@
using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.Module.UserModule;
using DS.WMS.Core.System.Dtos;
using DS.WMS.Core.System.Entity;
using DS.WMS.Core.System.Interface;
using Mapster;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
@ -26,16 +28,63 @@ public class DataRuleService : IDataRuleService
}
/// <summary>
///
/// 列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public DataResult<List<SysDataRule>> GetListByPage(PageRequest request)
public DataResult<List<DataRuleRes>> GetListByPage(PageRequest request)
{
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = db.Queryable<SysDataRule>()
.Where(whereList).ToQueryPage(request.PageCondition);
.LeftJoin<SysPermission>((a, b) => a.PermissionId == b.Id)
.Where(whereList)
.Select<DataRuleRes>().ToQueryPage(request.PageCondition);
return data;
}
/// <summary>
/// 编辑
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
public DataResult EditDataRule(DataRuleReq req)
{
if (req.Id == 0)
{
if (db.Queryable<SysDataRule>().Where(x=>x.PermissionId == req.PermissionId).Any())
{
return DataResult.Failed("数据权限已存在!",MultiLanguageConst.DataRuleExist);
}
var data = req.Adapt<SysDataRule>();
var entity = db.Insertable(data).ExecuteReturnEntity();
return DataResult.Successed("添加成功!", entity.Id,MultiLanguageConst.DataCreateSuccess);
}
else
{
var info = db.Queryable<SysDataRule>().Where(x => x.Id == req.Id).First();
info = req.Adapt(info);
db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
return DataResult.Successed("更新成功!",MultiLanguageConst.DataUpdateSuccess);
}
}
/// <summary>
/// 详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataResult<DataRuleRes> GetDataRuleInfo(string id)
{
var data = db.Queryable<SysDataRule>()
.LeftJoin<SysPermission>((a, b) => a.PermissionId == b.Id)
.Where(a => a.Id == long.Parse(id))
.Select<DataRuleRes>()
.First();
return DataResult<DataRuleRes>.Success(data,MultiLanguageConst.DataQuerySuccess);
}
}

@ -98,7 +98,7 @@ public class SysOrgService:ISysOrgService
ParentId = a.ParentId
}).ToList();
var orgList = BulidTree(list);
var orgList = BuildTree(list);
return DataResult<List<OrgTree>>.Success("获取数据成功!", orgList);
}
@ -108,7 +108,7 @@ public class SysOrgService:ISysOrgService
/// </summary>
/// <param name="treeNodes"></param>
/// <returns></returns>
public static List<OrgTree> BulidTree(List<OrgTree> treeNodes)
public static List<OrgTree> BuildTree(List<OrgTree> treeNodes)
{
try
{

@ -1,6 +1,7 @@
using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.WMS.Core.System.Dtos;
using DS.WMS.Core.System.Entity;
using DS.WMS.Core.System.Interface;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@ -185,7 +186,17 @@ public class CommonController : ApiController
return res;
}
/// <summary>
/// 获取客户数据权限列表
/// </summary>
/// <returns></returns>
[HttpGet]
[Route("GetClientPermissionList")]
public DataResult<List<ClientPermissionRes>> GetClientPermissionList()
{
var res = _invokeService.GetClientPermissionList();
return res;
}
/// <summary>
/// 获取数据库表及视图名
/// </summary>
@ -209,4 +220,31 @@ public class CommonController : ApiController
var res = _invokeService.GetColumns(tableViewName);
return res;
}
/// <summary>
/// 获取用户字段设置
/// </summary>
/// <param name="permissionId"></param>
/// <returns></returns>
[HttpGet]
[Route("GetUserFieldSet")]
public DataResult<SysUserFieldSet> GetUserFieldSet([FromQuery] string permissionId)
{
var res = _invokeService.GetUserFieldSet(permissionId);
return res;
}
/// <summary>
/// 更新用户字段设置
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
[HttpPost]
[Route("UpdateUserFieldSet")]
public DataResult UpdateUserFieldSet([FromBody] UserFieldSetUpdateReq req)
{
var res = _invokeService.UpdateUserFieldSet(req);
return res;
}
}

@ -0,0 +1,62 @@
using DS.Module.Core;
using DS.WMS.Core.System.Dtos;
using DS.WMS.Core.System.Interface;
using Microsoft.AspNetCore.Mvc;
namespace DS.WMS.MainApi.Controllers;
/// <summary>
/// 数据权限模块
/// </summary>
public class DataRuleController : ApiController
{
private readonly IDataRuleService _invokeService;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="invokeService"></param>
public DataRuleController(IDataRuleService invokeService)
{
_invokeService = invokeService;
}
/// <summary>
/// 列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost]
[Route("GetDataRuleList")]
public DataResult<List<DataRuleRes>> GetDataRuleList([FromBody] PageRequest request)
{
var res = _invokeService.GetListByPage(request);
return res;
}
/// <summary>
/// 编辑
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
[HttpPost]
[Route("EditDataRule")]
public DataResult EditDataRule([FromBody] DataRuleReq req)
{
var res = _invokeService.EditDataRule(req);
return res;
}
/// <summary>
/// 详情
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet]
[Route("GetDataRuleInfo")]
public DataResult<DataRuleRes> GetDataRuleInfo([FromQuery] string id)
{
var res = _invokeService.GetDataRuleInfo(id);
return res;
}
}

@ -2,6 +2,7 @@ using Autofac;
using Autofac.Extensions.DependencyInjection;
using DS.Module.AutofacModule;
using DS.Module.SqlSugar;
using DS.Module.UserModule;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
@ -48,7 +49,9 @@ public class Startup
public void ConfigureServices(IServiceCollection services, HostBuilderContext hostBuilderContext)
{
// services.AddTransient<ITestService, TestService>();
services.AddUserModuleInstall(); //用户服务
services.AddSqlsugarInstall();
services.AddSaasDbInstall();
}
/// <summary>

@ -1,6 +1,7 @@
using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.WMS.Core.System.Entity;
using DS.WMS.Core.System.Interface;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using Xunit;
@ -11,11 +12,12 @@ public class UnitTest1
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
// private readonly ICommonService _commonService;
public UnitTest1(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
// _commonService = _serviceProvider.GetRequiredService<ICommonService>();
}
[Fact]
@ -40,4 +42,25 @@ public class UnitTest1
ConstUtil.GetConstantField();
Assert.True(true);
}
[Fact]
public void DataRuleTest()
{
// var query = _commonService.GetDataRuleFilter<SysUser>();
var query = GetDataRuleFilter<SysUser>();
Assert.True(true);
}
public ISugarQueryable<T> GetDataRuleFilter<T>()
{
// 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;
// var rule = db.Queryable<SysDataRule>().First(u => u.PermissionName == moduleName);
// if (rule == null) return db.Queryable<T>(); //没有设置数据规则,那么视为该资源允许被任何主体查看
return db.Queryable<T>();
}
}
Loading…
Cancel
Save