From dbda14f31f10b053fea3a514c982dbe1cd130207 Mon Sep 17 00:00:00 2001 From: cjy Date: Tue, 22 Oct 2024 18:12:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E5=B9=B2=E7=B3=BB=E4=BA=BA?= =?UTF-8?q?=E6=9D=83=E9=99=90=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Info/Method/ClientInfoService.cs | 21 ++++++--- .../Sys/Interface/ICommonService.cs | 2 +- .../Sys/Method/ClientCommonService.cs | 47 +++++++++++++------ .../DS.WMS.Core/Sys/Method/CommonService.cs | 36 +++++++------- 4 files changed, 66 insertions(+), 40 deletions(-) diff --git a/ds-wms-service/DS.WMS.Core/Info/Method/ClientInfoService.cs b/ds-wms-service/DS.WMS.Core/Info/Method/ClientInfoService.cs index 253d13db..65c1a043 100644 --- a/ds-wms-service/DS.WMS.Core/Info/Method/ClientInfoService.cs +++ b/ds-wms-service/DS.WMS.Core/Info/Method/ClientInfoService.cs @@ -21,6 +21,7 @@ using Mapster; using Masuit.Tools.Systems; using Microsoft.Extensions.DependencyInjection; using SqlSugar; +using static AnyDiff.DifferenceLines; namespace DS.WMS.Core.Info.Method; @@ -426,14 +427,15 @@ public class ClientInfoService : ServiceBase, IClientInfoService //序列化查询条件 var whereList = request.GetConditionalModels(Db); #region 数据权限 - var queryData = TenantDb.Queryable(); + var queryData = TenantDb.Queryable().Where(c => c.Status == StatusEnum.Enable.ToEnumInt()); var conditions = new List(); + var otherConditions = new List(); var scope = string.Empty; - (queryData, scope, conditions) = await commonService.GetSpecialVisibleDataRuleFilter(queryData, TenantDb); + (conditions, scope, otherConditions) = await commonService.GetSpecialVisibleDataRuleFilter(queryData, TenantDb); var userids = new List(); - if (conditions.Count > 0) + if (otherConditions.Count > 0) { - foreach (ConditionalTree item in conditions) + foreach (ConditionalTree item in otherConditions) { Console.WriteLine(item.ConditionalList); if (item.ConditionalList.Count > 0) @@ -454,8 +456,15 @@ public class ClientInfoService : ServiceBase, IClientInfoService userids.Add(User.UserId); } #endregion - - var query = queryData.Where(c => c.Status == StatusEnum.Enable.ToEnumInt() || SqlFunc.Subqueryable().Where("SYSDATE() BETWEEN StartDate and EndDate").Where(c0 => userids.Contains(c.CreateBy.ToString())).Any())//TenantDb.Queryable() + //干系人合集 + var exp = Expressionable.Create(); + exp = exp.Or(c => SqlFunc.Subqueryable().Where("SYSDATE() BETWEEN StartDate and EndDate").Where(c0 => userids.Contains(c0.CreateBy.ToString())).Any()); + + var queryData1 = TenantDb.Queryable().ClearFilter().Where(c => c.Status == StatusEnum.Enable.ToEnumInt()).Where(exp.ToExpression()); + + var queryData0 = TenantDb.UnionAll(queryData, queryData1); + + var query = queryData0//.Where(c => c.Status == StatusEnum.Enable.ToEnumInt())//TenantDb.Queryable() .LeftJoin((c, c1) => c.Id == c1.ClientId) .LeftJoin((c, c1, c2) => c.Id == c2.ClientId) .InnerJoinIF(request.OtherQueryCondition?.ClientTag != null, (c, c1, c2, ct) => c.Id == ct.ClientId) diff --git a/ds-wms-service/DS.WMS.Core/Sys/Interface/ICommonService.cs b/ds-wms-service/DS.WMS.Core/Sys/Interface/ICommonService.cs index 89b5323b..fb730ce7 100644 --- a/ds-wms-service/DS.WMS.Core/Sys/Interface/ICommonService.cs +++ b/ds-wms-service/DS.WMS.Core/Sys/Interface/ICommonService.cs @@ -310,6 +310,6 @@ public interface ICommonService /// /// /// - public Task<(ISugarQueryable queryable, string? ruleScope, List? contidions)> GetSpecialVisibleDataRuleFilter(ISugarQueryable queryable, SqlSugarScopeProvider tenantDb); + public Task<(List? contidions, string? ruleScope, List? otherContidions)> GetSpecialVisibleDataRuleFilter(ISugarQueryable queryable, SqlSugarScopeProvider tenantDb); } \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/Sys/Method/ClientCommonService.cs b/ds-wms-service/DS.WMS.Core/Sys/Method/ClientCommonService.cs index ccd06874..30c093d0 100644 --- a/ds-wms-service/DS.WMS.Core/Sys/Method/ClientCommonService.cs +++ b/ds-wms-service/DS.WMS.Core/Sys/Method/ClientCommonService.cs @@ -12,6 +12,7 @@ using DS.WMS.Core.Fee.Dtos; using DS.WMS.Core.Fee.Entity; using DS.WMS.Core.Info.Dtos; using DS.WMS.Core.Info.Entity; +using DS.WMS.Core.Invoice.Dtos; using DS.WMS.Core.Op.Dtos; using DS.WMS.Core.Op.Entity; using DS.WMS.Core.Op.Method; @@ -193,20 +194,21 @@ public class ClientCommonService : IClientCommonService var contacts = await tenantDb.Queryable().Where(x => x.Status == StatusEnum.Enable && x.IsDefault == true) .Select().ToListAsync(); var conditions = new List(); - - var query = tenantDb.Queryable().ClearFilter(); - (query, _, conditions) = await commonService.GetSpecialVisibleDataRuleFilter(query, tenantDb); + var otherConditions = new List(); + var queryData = tenantDb.Queryable().ClearFilter().Where(c => c.Status == StatusEnum.Enable.ToEnumInt()); + //var query = tenantDb.Queryable().ClearFilter(); + var scope = string.Empty; + (conditions, scope, otherConditions) = await commonService.GetSpecialVisibleDataRuleFilter(queryData, tenantDb); var userids = new List(); - if (conditions.Count>0) + if (otherConditions.Count > 0) { - foreach (ConditionalTree item in conditions) + foreach (ConditionalTree item in otherConditions) { Console.WriteLine(item.ConditionalList); - if (item.ConditionalList.Count>0 ) + if (item.ConditionalList.Count > 0) { foreach (var item1 in item.ConditionalList) { - //Console.WriteLine(item1.Value as); var temp = item1.Value as SqlSugar.ConditionalModel; if (temp.FieldName == "Stakeholders") { @@ -216,13 +218,19 @@ public class ClientCommonService : IClientCommonService } } } - if (userids.Count==0) + if (userids.Count == 0) { userids.Add(user.UserId); } + //干系人合集 + var exp = Expressionable.Create(); + exp = exp.Or(c => SqlFunc.Subqueryable().Where("SYSDATE() BETWEEN StartDate and EndDate").Where(c0 => userids.Contains(c0.CreateBy.ToString())).Any()); + var queryData1 = tenantDb.Queryable().ClearFilter().Where(c => c.Status == StatusEnum.Enable.ToEnumInt()).Where(exp.ToExpression()); - var data = await query// tenantDb.Queryable().Includes(a=>a.Stakeholders) + var queryData0 = tenantDb.UnionAll(queryData, queryData1); + //code = code.ToLower(); + var data = await queryData0 .InnerJoin((a, b) => a.Id == b.ClientId) .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsController == true || SqlFunc.Subqueryable().Where("SYSDATE() BETWEEN StartDate and EndDate").Where(c => c.ClientId == a.Id && userids.Contains(c.CreateBy.ToString())).Any()) //&& c.CreateBy == long.Parse(user.UserId) && c.StartDate <= DateTime.Now && c.EndDate >= DateTime.Now @@ -1270,13 +1278,15 @@ public class ClientCommonService : IClientCommonService { var tenantDb = saasService.GetBizDbScopeById(user.TenantId); var conditions = new List(); - - var query = tenantDb.Queryable().ClearFilter(); - (query, _, conditions) = await commonService.GetSpecialVisibleDataRuleFilter(query, tenantDb); + var otherConditions = new List(); + var queryData = tenantDb.Queryable().ClearFilter().Where(c => c.Status == StatusEnum.Enable.ToEnumInt()); + //var query = tenantDb.Queryable().ClearFilter(); + var scope = string.Empty; + (conditions, scope, otherConditions) = await commonService.GetSpecialVisibleDataRuleFilter(queryData, tenantDb); var userids = new List(); - if (conditions.Count > 0) + if (otherConditions.Count > 0) { - foreach (ConditionalTree item in conditions) + foreach (ConditionalTree item in otherConditions) { Console.WriteLine(item.ConditionalList); if (item.ConditionalList.Count > 0) @@ -1296,8 +1306,15 @@ public class ClientCommonService : IClientCommonService { userids.Add(user.UserId); } + //干系人合集 + var exp = Expressionable.Create(); + exp = exp.Or(c => SqlFunc.Subqueryable().Where("SYSDATE() BETWEEN StartDate and EndDate").Where(c0 => userids.Contains(c0.CreateBy.ToString())).Any()); + + var queryData1 = tenantDb.Queryable().ClearFilter().Where(c => c.Status == StatusEnum.Enable.ToEnumInt()).Where(exp.ToExpression()); + + var queryData0 = tenantDb.UnionAll(queryData, queryData1); //code = code.ToLower(); - var data = await query//tenantDb.Queryable()//.Where(a=> tenantDb.Ado.SqlQuery(sql, new SugarParameter($"@ClientId", a.Id)).Contains(user.UserId)) + var data = await queryData0//tenantDb.Queryable()//.Where(a=> tenantDb.Ado.SqlQuery(sql, new SugarParameter($"@ClientId", a.Id)).Contains(user.UserId)) .InnerJoin((a, b) => a.Id == b.ClientId) .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() || SqlFunc.Subqueryable().Where("SYSDATE() BETWEEN StartDate and EndDate").Where(c => c.ClientId == a.Id && userids.Contains(c.CreateBy.ToString())).Any()) .WhereIF(!string.IsNullOrEmpty(code) && code == "carrier", (a, b) => b.IsCarrier == true) diff --git a/ds-wms-service/DS.WMS.Core/Sys/Method/CommonService.cs b/ds-wms-service/DS.WMS.Core/Sys/Method/CommonService.cs index da95d75e..cd894bf2 100644 --- a/ds-wms-service/DS.WMS.Core/Sys/Method/CommonService.cs +++ b/ds-wms-service/DS.WMS.Core/Sys/Method/CommonService.cs @@ -1595,7 +1595,7 @@ public class CommonService : ICommonService /// /// /// - public async Task<(ISugarQueryable queryable, string? ruleScope, List? contidions)> GetSpecialVisibleDataRuleFilter(ISugarQueryable queryable,SqlSugarScopeProvider tenantDb) + public async Task<(List? contidions, string? ruleScope, List? otherContidions)> GetSpecialVisibleDataRuleFilter(ISugarQueryable queryable,SqlSugarScopeProvider tenantDb) { // 因为TaskBaseAllocation不能继承IOrgId,所以在这里根据条件,在需要的时候手动添加IOrgId查询筛选器 bool isTask = typeof(T) == typeof(TaskBaseAllocation); @@ -1606,7 +1606,7 @@ public class CommonService : ICommonService { if (isTask) queryable.Filter(typeof(IOrgId)); - return (queryable, "all", otherContidions); //超级管理员特权 + return (contidions, "all", otherContidions); //超级管理员特权 } var moduleName = typeof(T).Name.ToLower(); @@ -1615,7 +1615,7 @@ public class CommonService : ICommonService .First(u => u.UserId == long.Parse(user.UserId) && u.PermissionEntity.ToLower() == moduleName && u.Status == StatusEnum.Enable); if (rule.IsNull()) { - return (queryable, null, otherContidions); //默认查询 + return (contidions, null, otherContidions); //默认查询 } else { @@ -1624,18 +1624,18 @@ public class CommonService : ICommonService if ((long)rule.VisibleTemplateId == 0) { contidions.Add(new ConditionalModel { FieldName = "CreateBy", ConditionalType = ConditionalType.Equal, FieldValue = user.UserId }); - return (queryable.Where(contidions), "self", otherContidions); //查询自身 + return (contidions, "self", otherContidions); //查询自身 } var ruleInfo = tenantDb.Queryable().First(x => x.Id == (long)rule.VisibleTemplateId); if (ruleInfo.RuleScope == "all") { - return (queryable.ClearFilter().ClearFilter(), ruleInfo.RuleScope, otherContidions); //查询全部 + return (contidions, ruleInfo.RuleScope, otherContidions); //查询全部 } else if (ruleInfo.RuleScope == "none") { if (isTask) - { return (queryable, ruleInfo.RuleScope, otherContidions); } + { return (contidions, ruleInfo.RuleScope, otherContidions); } else { SqlSugar.Check.ExceptionEasy("NO Operation", "没有数据查看权限!");//返回提示 @@ -1648,11 +1648,11 @@ public class CommonService : ICommonService var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules); if (conditionalModels.Count > 0) { - return (queryable.Where(conditionalModels), ruleInfo.RuleScope, additions);//自定义查询 + return (conditionalModels, ruleInfo.RuleScope, additions);//自定义查询 } else { - return (queryable.Where(contidions), ruleInfo.RuleScope, otherContidions);//默认查询 + return (contidions, ruleInfo.RuleScope, otherContidions);//默认查询 } } else if (ruleInfo.RuleScope == "self_org_with_child") // 当前机构及下属机构 @@ -1661,7 +1661,7 @@ public class CommonService : ICommonService IEnumerable 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, otherContidions); + return (contidions, ruleInfo.RuleScope, otherContidions); } else if (ruleInfo.RuleScope == "self") { @@ -1669,12 +1669,12 @@ public class CommonService : ICommonService var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules); if (conditionalModels.Count > 0) { - return (queryable.Where(conditionalModels), ruleInfo.RuleScope, additions);//自定义查询 + return (conditionalModels, ruleInfo.RuleScope, additions);//自定义查询 } else { contidions.Add(new ConditionalModel { FieldName = "CreateBy", ConditionalType = ConditionalType.Equal, FieldValue = user.UserId }); - return (queryable.Where(contidions), ruleInfo.RuleScope, otherContidions); //查询创建人自身信息 + return (contidions, ruleInfo.RuleScope, otherContidions); //查询创建人自身信息 } } @@ -1691,13 +1691,13 @@ public class CommonService : ICommonService var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules); if (conditionalModels.Count > 0) { - return (queryable.Where(conditionalModels), ruleInfo.RuleScope, additions);//自定义查询 + return (conditionalModels, ruleInfo.RuleScope, additions);//自定义查询 } else { var deptUsers = db.Queryable().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, additions); //查询本部门 + return (contidions, ruleInfo.RuleScope, additions); //查询本部门 } } else if (ruleInfo.RuleScope == "select_org") @@ -1708,14 +1708,14 @@ public class CommonService : ICommonService // db.ConfigQuery.Context.Utilities.JsonToConditionalModels( // JsonConvert.SerializeObject(conditions)); var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules); - return (queryable.ClearFilter().ClearFilter().Where(conditionalModels), ruleInfo.RuleScope, additions); //查询指定机构 + return (conditionalModels, ruleInfo.RuleScope, additions); //查询指定机构 } else if (ruleInfo.RuleScope == "select_user") { //var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules); var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules); var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules); - return (queryable.ClearFilter().ClearFilter().Where(conditionalModels), ruleInfo.RuleScope, additions);//查询指定人员 + return (conditionalModels, ruleInfo.RuleScope, additions);//查询指定人员 } else if (ruleInfo.RuleScope == "customize") @@ -1723,15 +1723,15 @@ public class CommonService : ICommonService //var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules); var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules); var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules); - return (queryable.Where(conditionalModels), ruleInfo.RuleScope, additions);//自定义查询 + return (conditionalModels, ruleInfo.RuleScope, additions);//自定义查询 } else if (ruleInfo.DataRules.IsNull()) { contidions.Add(new ConditionalModel { FieldName = "CreateBy", ConditionalType = ConditionalType.Equal, FieldValue = user.UserId }); - return (queryable.Where(contidions), ruleInfo.RuleScope, otherContidions); //没有设置数据规则,那么视为该资源允许被创建人查看 + return (contidions, ruleInfo.RuleScope, otherContidions); //没有设置数据规则,那么视为该资源允许被创建人查看 } - return (queryable, ruleInfo.RuleScope, otherContidions); + return (contidions, ruleInfo.RuleScope, otherContidions); #endregion }