diff --git a/ds-wms-service/DS.Module.Core/Constants/DataRuleConst.cs b/ds-wms-service/DS.Module.Core/Constants/DataRuleConst.cs
new file mode 100644
index 00000000..c061b18e
--- /dev/null
+++ b/ds-wms-service/DS.Module.Core/Constants/DataRuleConst.cs
@@ -0,0 +1,22 @@
+using System.ComponentModel;
+
+namespace DS.Module.Core;
+
+///
+/// 数据权限常量
+///
+public static class DataRuleConst
+{
+ ///
+ /// 数据权限配置中,当前登录用户的key
+ ///
+ public const string LoginUser = "{loginUser}";
+ ///
+ /// 数据权限配置中,当前登录角色的key
+ ///
+ public const string LoginRole = "{loginRole}";
+ ///
+ /// 数据权限配置中,当前登录机构的key
+ ///
+ public const string LoginOrg = "{loginOrg}";
+}
\ No newline at end of file
diff --git a/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs b/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs
index 96671922..8b240937 100644
--- a/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs
+++ b/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs
@@ -70,6 +70,9 @@ public static class MultiLanguageConst
[Description("权限模块不存在")]
public const string PermissionNotExist = "Permission_NotExist";
+ [Description("数据权限已存在")]
+ public const string DataRuleExist = "Data_Rule_Exist";
+
///
/// 非法请求
///
diff --git a/ds-wms-service/DS.Module.Core/Data/DataGroupConditions.cs b/ds-wms-service/DS.Module.Core/Data/DataGroupConditions.cs
new file mode 100644
index 00000000..6ef6c02c
--- /dev/null
+++ b/ds-wms-service/DS.Module.Core/Data/DataGroupConditions.cs
@@ -0,0 +1,43 @@
+namespace DS.Module.Core.Data;
+
+///
+/// 数据条件组
+///
+public class DataGroupConditions
+{
+ ///
+ /// 逻辑操作符
+ ///
+ public string LogicalOperator { get; set; }
+
+ ///
+ /// 条件组
+ ///
+ public List Conditions { get; set; }
+
+ ///
+ /// 分组
+ ///
+ public List Groups { get; set; }
+}
+///
+/// 条件
+///
+public class DataConditions
+{
+ ///
+ /// 字段
+ ///
+ public string Field { get; set; }
+
+ ///
+ /// 操作符
+ ///
+ public string Operator { get; set; }
+
+ ///
+ /// 值
+ ///
+ public string Value { get; set; }
+
+}
\ No newline at end of file
diff --git a/ds-wms-service/DS.Module.Core/Extensions/QueryableExtensions.cs b/ds-wms-service/DS.Module.Core/Extensions/QueryableExtensions.cs
index 64fa30ee..4052b366 100644
--- a/ds-wms-service/DS.Module.Core/Extensions/QueryableExtensions.cs
+++ b/ds-wms-service/DS.Module.Core/Extensions/QueryableExtensions.cs
@@ -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
///
///
///
- public static DataResult> ToQueryPage(this ISugarQueryable source, PageCondition page)
+ public static DataResult> ToQueryPage(this ISugarQueryable 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>.PageList(total, list,MultiLanguageConst.DataQuerySuccess);
+ return DataResult>.PageList(total, list, MultiLanguageConst.DataQuerySuccess);
}
///
@@ -79,4 +82,191 @@ public static partial class Extensions
? source.ToPageList(pageIndex, pageSize, ref total)
: Enumerable.Empty().ToList(), total);
}
+ ///
+ /// 转换SqlSugar条件查询表达式
+ ///
+ ///
+ ///
+ public static List ConvertSqlSugarExpression(this string ruleStr)
+ {
+ var conditions = JsonConvert.DeserializeObject(ruleStr);
+ var conditionalCollections = new List();
+ if (conditions.LogicalOperator == "and")
+ {
+ var conditionList = new List>();
+ foreach (var item in conditions.Conditions)
+ {
+ conditionList.Add(new KeyValuePair
+ (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>();
+ foreach (var group in conditions.Groups)
+ {
+ if (group.LogicalOperator == "and")
+ {
+ foreach (var item1 in group.Conditions)
+ {
+ groupList.Add(new KeyValuePair
+ (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.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>();
+ foreach (var item in conditions.Conditions)
+ {
+ conditionList.Add(new KeyValuePair
+ (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>();
+ foreach (var group in conditions.Groups)
+ {
+ if (group.LogicalOperator == "and")
+ {
+ foreach (var item1 in group.Conditions)
+ {
+ groupList.Add(new KeyValuePair
+ (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.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;
+ }
+
+ ///
+ /// 转换SqlSugar 条件操作符
+ ///
+ ///
+ ///
+ 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;
+ }
+ }
}
\ No newline at end of file
diff --git a/ds-wms-service/DS.WMS.Core/Flow/Method/ClientFlowTemplateService.cs b/ds-wms-service/DS.WMS.Core/Flow/Method/ClientFlowTemplateService.cs
index 631e0005..1f14a1f8 100644
--- a/ds-wms-service/DS.WMS.Core/Flow/Method/ClientFlowTemplateService.cs
+++ b/ds-wms-service/DS.WMS.Core/Flow/Method/ClientFlowTemplateService.cs
@@ -80,7 +80,7 @@ public class ClientFlowTemplateService : IClientFlowTemplateService
}
var data = info.Adapt();
- db.Insertable(info).ExecuteCommand();
+ db.Insertable(data).ExecuteCommand();
return DataResult.Successed("引入成功!",MultiLanguageConst.DataImportSuccess);
}
diff --git a/ds-wms-service/DS.WMS.Core/Flow/Method/FlowInstanceService.cs b/ds-wms-service/DS.WMS.Core/Flow/Method/FlowInstanceService.cs
index 587125ac..d4d5d532 100644
--- a/ds-wms-service/DS.WMS.Core/Flow/Method/FlowInstanceService.cs
+++ b/ds-wms-service/DS.WMS.Core/Flow/Method/FlowInstanceService.cs
@@ -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());
diff --git a/ds-wms-service/DS.WMS.Core/Flow/Method/FlowRuntimeService.cs b/ds-wms-service/DS.WMS.Core/Flow/Method/FlowRuntimeService.cs
index d53b7530..23e3f96d 100644
--- a/ds-wms-service/DS.WMS.Core/Flow/Method/FlowRuntimeService.cs
+++ b/ds-wms-service/DS.WMS.Core/Flow/Method/FlowRuntimeService.cs
@@ -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;
}
-
+ ///
+ /// 转换SqlSugar 条件操作符
+ ///
+ ///
+ ///
+ 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;
+ }
+ }
///
/// 获取节点类型 0会签开始,1会签结束,2一般节点,3开始节点,4流程运行结束
///
diff --git a/ds-wms-service/DS.WMS.Core/System/Dtos/ClientPermissionRes.cs b/ds-wms-service/DS.WMS.Core/System/Dtos/ClientPermissionRes.cs
new file mode 100644
index 00000000..0bc0d396
--- /dev/null
+++ b/ds-wms-service/DS.WMS.Core/System/Dtos/ClientPermissionRes.cs
@@ -0,0 +1,22 @@
+namespace DS.WMS.Core.System.Dtos;
+
+///
+/// 客户权限返回
+///
+public class ClientPermissionRes
+{
+ ///
+ /// 主键Id
+ ///
+ public long Id { get; set; }
+
+ ///
+ /// 权限名称
+ ///
+ public string PermissionName { get; set; }
+
+ ///
+ /// 权限实体
+ ///
+ public string PermissionEntity { get; set; }
+}
\ No newline at end of file
diff --git a/ds-wms-service/DS.WMS.Core/System/Dtos/DataRuleReq.cs b/ds-wms-service/DS.WMS.Core/System/Dtos/DataRuleReq.cs
new file mode 100644
index 00000000..98cf2be1
--- /dev/null
+++ b/ds-wms-service/DS.WMS.Core/System/Dtos/DataRuleReq.cs
@@ -0,0 +1,59 @@
+using DS.Module.Core;
+using FluentValidation;
+
+namespace DS.WMS.Core.System.Dtos;
+
+///
+/// 数据权限请求实体
+///
+public class DataRuleReq
+{
+ ///
+ /// 主键Id
+ ///
+ public long Id { get; set; }
+ ///
+ /// 资源标识(权限ID)
+ ///
+ public long PermissionId { get; set; }
+ ///
+ /// 中文视图名
+ ///
+ public string ColumnView { get; set; }
+ ///
+ /// 权限规则
+ ///
+ public string DataRules { get; set; }
+
+ ///
+ /// 数据权限描述
+ ///
+ public string Description { get; set; }
+
+ ///
+ /// 状态 0 启用 1 禁用
+ ///
+ public StatusEnum? Status { get; set; } = StatusEnum.Enable;
+ ///
+ /// 备注
+ ///
+ public string Note { get; set; } = "";
+}
+
+
+///
+/// 验证
+///
+public class DataRuleReqValidator : AbstractValidator
+{
+ ///
+ /// 构造函数
+ ///
+ public DataRuleReqValidator()
+ {
+ this.RuleFor(o => o.PermissionId)
+ .NotEmpty().WithName("权限模块Id");
+ this.RuleFor(o => o.ColumnView)
+ .NotEmpty().WithName("中文视图名");
+ }
+}
\ No newline at end of file
diff --git a/ds-wms-service/DS.WMS.Core/System/Dtos/DataRuleRes.cs b/ds-wms-service/DS.WMS.Core/System/Dtos/DataRuleRes.cs
new file mode 100644
index 00000000..19b8e774
--- /dev/null
+++ b/ds-wms-service/DS.WMS.Core/System/Dtos/DataRuleRes.cs
@@ -0,0 +1,49 @@
+using DS.Module.Core;
+
+namespace DS.WMS.Core.System.Dtos;
+
+///
+/// 数据权限返回实体
+///
+public class DataRuleRes
+{
+ ///
+ /// 主键Id
+ ///
+ public long Id { get; set; }
+ ///
+ /// 资源标识(权限ID)
+ ///
+ public long PermissionId { get; set; }
+ ///
+ /// 中文视图名
+ ///
+ public string ColumnView { get; set; }
+ ///
+ /// 权限模块名称
+ ///
+ public string PermissionName { get; set; }
+ ///
+ /// 权限规则
+ ///
+ public string DataRules { get; set; }
+
+ ///
+ /// 数据权限描述
+ ///
+ public string Description { get; set; }
+
+ ///
+ /// 状态 0 启用 1 禁用
+ ///
+ public StatusEnum? Status { get; set; } = StatusEnum.Enable;
+ ///
+ /// 备注
+ ///
+ public string Note { get; set; } = "";
+
+ ///
+ /// 创建时间
+ ///
+ public DateTime CreateTime { get; set; }
+}
\ No newline at end of file
diff --git a/ds-wms-service/DS.WMS.Core/System/Entity/SysDataRule.cs b/ds-wms-service/DS.WMS.Core/System/Entity/SysDataRule.cs
index d2899db8..fad187bb 100644
--- a/ds-wms-service/DS.WMS.Core/System/Entity/SysDataRule.cs
+++ b/ds-wms-service/DS.WMS.Core/System/Entity/SysDataRule.cs
@@ -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
+[SqlSugar.SugarTable("sys_data_rule")]
+public class SysDataRule : BaseTenantModel
{
///
/// 资源标识(权限ID)
///
- public string PermissionId { get; set; }
-
+ public long PermissionId { get; set; }
+
///
- /// 模块名称
+ /// 权限实体
///
- public string PermissionName { get; set; }
-
+ public string PermissionEntity { get; set; }
///
- /// 是否可用
+ /// 状态
///
- public string Enable { get; set; }
-
+ [SqlSugar.SugarColumn(ColumnDescription = "状态")]
+ public StatusEnum? Status { get; set; } = StatusEnum.Enable;
+ ///
+ /// 中文视图名
+ ///
+ public string ColumnView { get; set; }
///
/// 权限规则
///
@@ -33,5 +37,5 @@ public class SysDataRule : BaseModel
///
/// 排序号
///
- public string SortNo { get; set; }
+ public string OrderNo { get; set; }
}
\ No newline at end of file
diff --git a/ds-wms-service/DS.WMS.Core/System/Entity/SysPermission.cs b/ds-wms-service/DS.WMS.Core/System/Entity/SysPermission.cs
index 5cc574d3..bd6613c2 100644
--- a/ds-wms-service/DS.WMS.Core/System/Entity/SysPermission.cs
+++ b/ds-wms-service/DS.WMS.Core/System/Entity/SysPermission.cs
@@ -118,7 +118,7 @@ public class SysPermission : BaseModel
#endregion 拓展字段
///
- ///权限实体
+ /// 权限实体
///
public string PermissionEntity { get; set; }
}
\ No newline at end of file
diff --git a/ds-wms-service/DS.WMS.Core/System/Interface/ICommonService.cs b/ds-wms-service/DS.WMS.Core/System/Interface/ICommonService.cs
index 0f3742fe..0fb1f62b 100644
--- a/ds-wms-service/DS.WMS.Core/System/Interface/ICommonService.cs
+++ b/ds-wms-service/DS.WMS.Core/System/Interface/ICommonService.cs
@@ -89,6 +89,11 @@ public interface ICommonService
///
DataResult> GetOrgList();
+ ///
+ /// 获取客户数据权限列表
+ ///
+ ///
+ public DataResult> GetClientPermissionList();
///
/// 修改密码
///
diff --git a/ds-wms-service/DS.WMS.Core/System/Interface/IDataRuleService.cs b/ds-wms-service/DS.WMS.Core/System/Interface/IDataRuleService.cs
index 5e4a0b13..948e957f 100644
--- a/ds-wms-service/DS.WMS.Core/System/Interface/IDataRuleService.cs
+++ b/ds-wms-service/DS.WMS.Core/System/Interface/IDataRuleService.cs
@@ -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> GetListByPage(PageRequest request);
+ ///
+ /// 列表
+ ///
+ ///
+ ///
+ DataResult> GetListByPage(PageRequest request);
+
+
+ ///
+ /// 编辑
+ ///
+ ///
+ ///
+ DataResult EditDataRule(DataRuleReq model);
+
+ ///
+ /// 获取详情
+ ///
+ ///
+ ///
+ DataResult GetDataRuleInfo(string id);
}
\ No newline at end of file
diff --git a/ds-wms-service/DS.WMS.Core/System/Method/CommonService.cs b/ds-wms-service/DS.WMS.Core/System/Method/CommonService.cs
index 7f8aa215..7cc2d909 100644
--- a/ds-wms-service/DS.WMS.Core/System/Method/CommonService.cs
+++ b/ds-wms-service/DS.WMS.Core/System/Method/CommonService.cs
@@ -781,6 +781,23 @@ public class CommonService : ICommonService
#endregion 获取机构下拉列表
+
+ #region 获取客户数据权限列表
+ ///
+ /// 获取客户数据权限列表
+ ///
+ ///
+ public DataResult> GetClientPermissionList()
+ {
+ var list = db.Queryable().Where(x=> x.MenuType == 2 && x.IsHidden == false &&
+ (x.PermissionType == 1 || x.PermissionType == 0) && x.Id!=1744968217220222976 )
+ .Select()
+ .ToList();
+ return DataResult>.Success("获取数据成功!", list);
+ }
+
+
+ #endregion
#region 修改密码
///
@@ -954,44 +971,40 @@ public class CommonService : ICommonService
return db.Queryable(); //超级管理员特权
}
- var moduleName = typeof(T).Name;
- var rule = db.Queryable().First(u => u.PermissionName == moduleName);
- if (rule == null) return db.Queryable(); //没有设置数据规则,那么视为该资源允许被任何主体查看
+ var moduleName = typeof(T).Name.ToLower();
+ var rule = db.Queryable().First(u => u.PermissionEntity.ToLower() == moduleName && u.Status == StatusEnum.Enable);
+ if (rule == null) return db.Queryable(); //没有设置数据规则,那么视为该资源允许被任何主体查看
- var ruleConditions = JsonConvert.DeserializeObject(rule.DataRules);
- if (ruleConditions.RoleCondition.Count > 0)
+ if (rule.DataRules.Contains(DataRuleConst.LoginUser))
{
- var roles = db.Queryable().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()
- .Where(ruleConditions.QueryCondition);
+ var roles = db.Queryable().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();
+ var orgs = db.Queryable().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().Where(conditionalModels);
}
+
+
#region 获取数据库表及字段属性
///
diff --git a/ds-wms-service/DS.WMS.Core/System/Method/DataRuleService.cs b/ds-wms-service/DS.WMS.Core/System/Method/DataRuleService.cs
index e1b85b60..67ba3695 100644
--- a/ds-wms-service/DS.WMS.Core/System/Method/DataRuleService.cs
+++ b/ds-wms-service/DS.WMS.Core/System/Method/DataRuleService.cs
@@ -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
}
///
- ///
+ /// 列表
///
///
///
- public DataResult> GetListByPage(PageRequest request)
+ public DataResult> GetListByPage(PageRequest request)
{
//序列化查询条件
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
var data = db.Queryable()
- .Where(whereList).ToQueryPage(request.PageCondition);
+ .LeftJoin((a, b) => a.PermissionId == b.Id)
+ .Where(whereList)
+ .Select().ToQueryPage(request.PageCondition);
return data;
}
+ ///
+ /// 编辑
+ ///
+ ///
+ ///
+ public DataResult EditDataRule(DataRuleReq req)
+ {
+ if (req.Id == 0)
+ {
+
+ if (db.Queryable().Where(x=>x.PermissionId == req.PermissionId).Any())
+ {
+ return DataResult.Failed("数据权限已存在!",MultiLanguageConst.DataRuleExist);
+ }
+
+ var data = req.Adapt();
+
+ var entity = db.Insertable(data).ExecuteReturnEntity();
+
+ return DataResult.Successed("添加成功!", entity.Id,MultiLanguageConst.DataCreateSuccess);
+ }
+ else
+ {
+ var info = db.Queryable().Where(x => x.Id == req.Id).First();
+
+ info = req.Adapt(info);
+
+ db.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
+ return DataResult.Successed("更新成功!",MultiLanguageConst.DataUpdateSuccess);
+ }
+ }
+ ///
+ /// 详情
+ ///
+ ///
+ ///
+ public DataResult GetDataRuleInfo(string id)
+ {
+ var data = db.Queryable()
+ .LeftJoin((a, b) => a.PermissionId == b.Id)
+ .Where(a => a.Id == long.Parse(id))
+ .Select()
+ .First();
+ return DataResult.Success(data,MultiLanguageConst.DataQuerySuccess);
+ }
}
\ No newline at end of file
diff --git a/ds-wms-service/DS.WMS.Core/System/Method/SysOrgService.cs b/ds-wms-service/DS.WMS.Core/System/Method/SysOrgService.cs
index 60b8e806..bf75e8ff 100644
--- a/ds-wms-service/DS.WMS.Core/System/Method/SysOrgService.cs
+++ b/ds-wms-service/DS.WMS.Core/System/Method/SysOrgService.cs
@@ -98,7 +98,7 @@ public class SysOrgService:ISysOrgService
ParentId = a.ParentId
}).ToList();
- var orgList = BulidTree(list);
+ var orgList = BuildTree(list);
return DataResult>.Success("获取数据成功!", orgList);
}
@@ -108,7 +108,7 @@ public class SysOrgService:ISysOrgService
///
///
///
- public static List BulidTree(List treeNodes)
+ public static List BuildTree(List treeNodes)
{
try
{
diff --git a/ds-wms-service/DS.WMS.MainApi/Controllers/CommonController.cs b/ds-wms-service/DS.WMS.MainApi/Controllers/CommonController.cs
index d405e8c2..6f86fc54 100644
--- a/ds-wms-service/DS.WMS.MainApi/Controllers/CommonController.cs
+++ b/ds-wms-service/DS.WMS.MainApi/Controllers/CommonController.cs
@@ -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;
}
-
+ ///
+ /// 获取客户数据权限列表
+ ///
+ ///
+ [HttpGet]
+ [Route("GetClientPermissionList")]
+ public DataResult> GetClientPermissionList()
+ {
+ var res = _invokeService.GetClientPermissionList();
+ return res;
+ }
///
/// 获取数据库表及视图名
///
@@ -209,4 +220,31 @@ public class CommonController : ApiController
var res = _invokeService.GetColumns(tableViewName);
return res;
}
+
+ ///
+ /// 获取用户字段设置
+ ///
+ ///
+ ///
+ [HttpGet]
+ [Route("GetUserFieldSet")]
+ public DataResult GetUserFieldSet([FromQuery] string permissionId)
+ {
+ var res = _invokeService.GetUserFieldSet(permissionId);
+ return res;
+ }
+
+
+ ///
+ /// 更新用户字段设置
+ ///
+ ///
+ ///
+ [HttpPost]
+ [Route("UpdateUserFieldSet")]
+ public DataResult UpdateUserFieldSet([FromBody] UserFieldSetUpdateReq req)
+ {
+ var res = _invokeService.UpdateUserFieldSet(req);
+ return res;
+ }
}
\ No newline at end of file
diff --git a/ds-wms-service/DS.WMS.MainApi/Controllers/DataRuleController.cs b/ds-wms-service/DS.WMS.MainApi/Controllers/DataRuleController.cs
new file mode 100644
index 00000000..d8b36bed
--- /dev/null
+++ b/ds-wms-service/DS.WMS.MainApi/Controllers/DataRuleController.cs
@@ -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;
+
+///
+/// 数据权限模块
+///
+public class DataRuleController : ApiController
+{
+ private readonly IDataRuleService _invokeService;
+
+ ///
+ /// 构造函数
+ ///
+ ///
+ public DataRuleController(IDataRuleService invokeService)
+ {
+ _invokeService = invokeService;
+ }
+
+ ///
+ /// 列表
+ ///
+ ///
+ ///
+ [HttpPost]
+ [Route("GetDataRuleList")]
+ public DataResult> GetDataRuleList([FromBody] PageRequest request)
+ {
+ var res = _invokeService.GetListByPage(request);
+ return res;
+ }
+
+ ///
+ /// 编辑
+ ///
+ ///
+ ///
+ [HttpPost]
+ [Route("EditDataRule")]
+ public DataResult EditDataRule([FromBody] DataRuleReq req)
+ {
+ var res = _invokeService.EditDataRule(req);
+ return res;
+ }
+
+ ///
+ /// 详情
+ ///
+ ///
+ ///
+ [HttpGet]
+ [Route("GetDataRuleInfo")]
+ public DataResult GetDataRuleInfo([FromQuery] string id)
+ {
+ var res = _invokeService.GetDataRuleInfo(id);
+ return res;
+ }
+}
\ No newline at end of file
diff --git a/ds-wms-service/DS.WMS.Test/Startup.cs b/ds-wms-service/DS.WMS.Test/Startup.cs
index 8e6ee9e1..8683c70d 100644
--- a/ds-wms-service/DS.WMS.Test/Startup.cs
+++ b/ds-wms-service/DS.WMS.Test/Startup.cs
@@ -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();
+ services.AddUserModuleInstall(); //用户服务
services.AddSqlsugarInstall();
+ services.AddSaasDbInstall();
}
///
diff --git a/ds-wms-service/DS.WMS.Test/UnitTest1.cs b/ds-wms-service/DS.WMS.Test/UnitTest1.cs
index e4b24d5f..43e66002 100644
--- a/ds-wms-service/DS.WMS.Test/UnitTest1.cs
+++ b/ds-wms-service/DS.WMS.Test/UnitTest1.cs
@@ -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();
+ // _commonService = _serviceProvider.GetRequiredService();
}
[Fact]
@@ -40,4 +42,25 @@ public class UnitTest1
ConstUtil.GetConstantField();
Assert.True(true);
}
+ [Fact]
+ public void DataRuleTest()
+ {
+ // var query = _commonService.GetDataRuleFilter();
+
+ var query = GetDataRuleFilter();
+ Assert.True(true);
+ }
+ public ISugarQueryable GetDataRuleFilter()
+ {
+ // var userInfo = db.Queryable().First(x => x.Id == long.Parse(user.UserId));
+ // if (userInfo.UserType == 0)
+ // {
+ // return db.Queryable(); //超级管理员特权
+ // }
+
+ var moduleName = typeof(T).Name;
+ // var rule = db.Queryable().First(u => u.PermissionName == moduleName);
+ // if (rule == null) return db.Queryable(); //没有设置数据规则,那么视为该资源允许被任何主体查看
+ return db.Queryable();
+ }
}
\ No newline at end of file