客户干系人权限修改

dev
cjy 1 month ago
parent 5305f19fc6
commit dbda14f31f

@ -21,6 +21,7 @@ using Mapster;
using Masuit.Tools.Systems; using Masuit.Tools.Systems;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using SqlSugar; using SqlSugar;
using static AnyDiff.DifferenceLines;
namespace DS.WMS.Core.Info.Method; namespace DS.WMS.Core.Info.Method;
@ -426,14 +427,15 @@ public class ClientInfoService : ServiceBase, IClientInfoService
//序列化查询条件 //序列化查询条件
var whereList = request.GetConditionalModels(Db); var whereList = request.GetConditionalModels(Db);
#region 数据权限 #region 数据权限
var queryData = TenantDb.Queryable<InfoClient>(); var queryData = TenantDb.Queryable<InfoClient>().Where(c => c.Status == StatusEnum.Enable.ToEnumInt());
var conditions = new List<IConditionalModel>(); var conditions = new List<IConditionalModel>();
var otherConditions = new List<IConditionalModel>();
var scope = string.Empty; var scope = string.Empty;
(queryData, scope, conditions) = await commonService.GetSpecialVisibleDataRuleFilter<InfoClient>(queryData, TenantDb); (conditions, scope, otherConditions) = await commonService.GetSpecialVisibleDataRuleFilter<InfoClient>(queryData, TenantDb);
var userids = new List<string>(); var userids = new List<string>();
if (conditions.Count > 0) if (otherConditions.Count > 0)
{ {
foreach (ConditionalTree item in conditions) foreach (ConditionalTree item in otherConditions)
{ {
Console.WriteLine(item.ConditionalList); Console.WriteLine(item.ConditionalList);
if (item.ConditionalList.Count > 0) if (item.ConditionalList.Count > 0)
@ -454,8 +456,15 @@ public class ClientInfoService : ServiceBase, IClientInfoService
userids.Add(User.UserId); userids.Add(User.UserId);
} }
#endregion #endregion
//干系人合集
var exp = Expressionable.Create<InfoClient>();
exp = exp.Or(c => SqlFunc.Subqueryable<InfoClientStakeholder>().Where("SYSDATE() BETWEEN StartDate and EndDate").Where(c0 => userids.Contains(c0.CreateBy.ToString())).Any());
var query = queryData.Where(c => c.Status == StatusEnum.Enable.ToEnumInt() || SqlFunc.Subqueryable<InfoClientStakeholder>().Where("SYSDATE() BETWEEN StartDate and EndDate").Where(c0 => userids.Contains(c.CreateBy.ToString())).Any())//TenantDb.Queryable<InfoClient>() var queryData1 = TenantDb.Queryable<InfoClient>().ClearFilter<ISharedOrgId>().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<InfoClient>()
.LeftJoin<InfoClientContact>((c, c1) => c.Id == c1.ClientId) .LeftJoin<InfoClientContact>((c, c1) => c.Id == c1.ClientId)
.LeftJoin<InfoClientContract>((c, c1, c2) => c.Id == c2.ClientId) .LeftJoin<InfoClientContract>((c, c1, c2) => c.Id == c2.ClientId)
.InnerJoinIF<InfoClientTag>(request.OtherQueryCondition?.ClientTag != null, (c, c1, c2, ct) => c.Id == ct.ClientId) .InnerJoinIF<InfoClientTag>(request.OtherQueryCondition?.ClientTag != null, (c, c1, c2, ct) => c.Id == ct.ClientId)

@ -310,6 +310,6 @@ public interface ICommonService
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <param name="tenantDb"></param> /// <param name="tenantDb"></param>
/// <returns></returns> /// <returns></returns>
public Task<(ISugarQueryable<T> queryable, string? ruleScope, List<IConditionalModel>? contidions)> GetSpecialVisibleDataRuleFilter<T>(ISugarQueryable<T> queryable, SqlSugarScopeProvider tenantDb); public Task<(List<IConditionalModel>? contidions, string? ruleScope, List<IConditionalModel>? otherContidions)> GetSpecialVisibleDataRuleFilter<T>(ISugarQueryable<T> queryable, SqlSugarScopeProvider tenantDb);
} }

@ -12,6 +12,7 @@ using DS.WMS.Core.Fee.Dtos;
using DS.WMS.Core.Fee.Entity; using DS.WMS.Core.Fee.Entity;
using DS.WMS.Core.Info.Dtos; using DS.WMS.Core.Info.Dtos;
using DS.WMS.Core.Info.Entity; using DS.WMS.Core.Info.Entity;
using DS.WMS.Core.Invoice.Dtos;
using DS.WMS.Core.Op.Dtos; using DS.WMS.Core.Op.Dtos;
using DS.WMS.Core.Op.Entity; using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Op.Method; using DS.WMS.Core.Op.Method;
@ -193,20 +194,21 @@ public class ClientCommonService : IClientCommonService
var contacts = await tenantDb.Queryable<InfoClientContact>().Where(x => x.Status == StatusEnum.Enable && x.IsDefault == true) var contacts = await tenantDb.Queryable<InfoClientContact>().Where(x => x.Status == StatusEnum.Enable && x.IsDefault == true)
.Select<ClientContactRes>().ToListAsync(); .Select<ClientContactRes>().ToListAsync();
var conditions = new List<IConditionalModel>(); var conditions = new List<IConditionalModel>();
var otherConditions = new List<IConditionalModel>();
var query = tenantDb.Queryable<InfoClient>().ClearFilter<ISharedOrgId>(); var queryData = tenantDb.Queryable<InfoClient>().ClearFilter<ISharedOrgId>().Where(c => c.Status == StatusEnum.Enable.ToEnumInt());
(query, _, conditions) = await commonService.GetSpecialVisibleDataRuleFilter<InfoClient>(query, tenantDb); //var query = tenantDb.Queryable<InfoClient>().ClearFilter<ISharedOrgId>();
var scope = string.Empty;
(conditions, scope, otherConditions) = await commonService.GetSpecialVisibleDataRuleFilter<InfoClient>(queryData, tenantDb);
var userids = new List<string>(); var userids = new List<string>();
if (conditions.Count>0) if (otherConditions.Count > 0)
{ {
foreach (ConditionalTree item in conditions) foreach (ConditionalTree item in otherConditions)
{ {
Console.WriteLine(item.ConditionalList); Console.WriteLine(item.ConditionalList);
if (item.ConditionalList.Count > 0) if (item.ConditionalList.Count > 0)
{ {
foreach (var item1 in item.ConditionalList) foreach (var item1 in item.ConditionalList)
{ {
//Console.WriteLine(item1.Value as);
var temp = item1.Value as SqlSugar.ConditionalModel; var temp = item1.Value as SqlSugar.ConditionalModel;
if (temp.FieldName == "Stakeholders") if (temp.FieldName == "Stakeholders")
{ {
@ -220,9 +222,15 @@ public class ClientCommonService : IClientCommonService
{ {
userids.Add(user.UserId); userids.Add(user.UserId);
} }
//干系人合集
var exp = Expressionable.Create<InfoClient>();
exp = exp.Or(c => SqlFunc.Subqueryable<InfoClientStakeholder>().Where("SYSDATE() BETWEEN StartDate and EndDate").Where(c0 => userids.Contains(c0.CreateBy.ToString())).Any());
var queryData1 = tenantDb.Queryable<InfoClient>().ClearFilter<ISharedOrgId>().Where(c => c.Status == StatusEnum.Enable.ToEnumInt()).Where(exp.ToExpression());
var data = await query// tenantDb.Queryable<InfoClient>().Includes(a=>a.Stakeholders) var queryData0 = tenantDb.UnionAll(queryData, queryData1);
//code = code.ToLower();
var data = await queryData0
.InnerJoin<InfoClientTag>((a, b) => a.Id == b.ClientId) .InnerJoin<InfoClientTag>((a, b) => a.Id == b.ClientId)
.Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsController == true || SqlFunc.Subqueryable<InfoClientStakeholder>().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 .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() && b.IsController == true || SqlFunc.Subqueryable<InfoClientStakeholder>().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 tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var conditions = new List<IConditionalModel>(); var conditions = new List<IConditionalModel>();
var otherConditions = new List<IConditionalModel>();
var query = tenantDb.Queryable<InfoClient>().ClearFilter<ISharedOrgId>(); var queryData = tenantDb.Queryable<InfoClient>().ClearFilter<ISharedOrgId>().Where(c => c.Status == StatusEnum.Enable.ToEnumInt());
(query, _, conditions) = await commonService.GetSpecialVisibleDataRuleFilter<InfoClient>(query, tenantDb); //var query = tenantDb.Queryable<InfoClient>().ClearFilter<ISharedOrgId>();
var scope = string.Empty;
(conditions, scope, otherConditions) = await commonService.GetSpecialVisibleDataRuleFilter<InfoClient>(queryData, tenantDb);
var userids = new List<string>(); var userids = new List<string>();
if (conditions.Count > 0) if (otherConditions.Count > 0)
{ {
foreach (ConditionalTree item in conditions) foreach (ConditionalTree item in otherConditions)
{ {
Console.WriteLine(item.ConditionalList); Console.WriteLine(item.ConditionalList);
if (item.ConditionalList.Count > 0) if (item.ConditionalList.Count > 0)
@ -1296,8 +1306,15 @@ public class ClientCommonService : IClientCommonService
{ {
userids.Add(user.UserId); userids.Add(user.UserId);
} }
//干系人合集
var exp = Expressionable.Create<InfoClient>();
exp = exp.Or(c => SqlFunc.Subqueryable<InfoClientStakeholder>().Where("SYSDATE() BETWEEN StartDate and EndDate").Where(c0 => userids.Contains(c0.CreateBy.ToString())).Any());
var queryData1 = tenantDb.Queryable<InfoClient>().ClearFilter<ISharedOrgId>().Where(c => c.Status == StatusEnum.Enable.ToEnumInt()).Where(exp.ToExpression());
var queryData0 = tenantDb.UnionAll(queryData, queryData1);
//code = code.ToLower(); //code = code.ToLower();
var data = await query//tenantDb.Queryable<InfoClient>()//.Where(a=> tenantDb.Ado.SqlQuery<dynamic>(sql, new SugarParameter($"@ClientId", a.Id)).Contains(user.UserId)) var data = await queryData0//tenantDb.Queryable<InfoClient>()//.Where(a=> tenantDb.Ado.SqlQuery<dynamic>(sql, new SugarParameter($"@ClientId", a.Id)).Contains(user.UserId))
.InnerJoin<InfoClientTag>((a, b) => a.Id == b.ClientId) .InnerJoin<InfoClientTag>((a, b) => a.Id == b.ClientId)
.Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() || SqlFunc.Subqueryable<InfoClientStakeholder>().Where("SYSDATE() BETWEEN StartDate and EndDate").Where(c => c.ClientId == a.Id && userids.Contains(c.CreateBy.ToString())).Any()) .Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt() || SqlFunc.Subqueryable<InfoClientStakeholder>().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) .WhereIF(!string.IsNullOrEmpty(code) && code == "carrier", (a, b) => b.IsCarrier == true)

@ -1595,7 +1595,7 @@ public class CommonService : ICommonService
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <param name="tenantDb"></param> /// <param name="tenantDb"></param>
/// <returns></returns> /// <returns></returns>
public async Task<(ISugarQueryable<T> queryable, string? ruleScope, List<IConditionalModel>? contidions)> GetSpecialVisibleDataRuleFilter<T>(ISugarQueryable<T> queryable,SqlSugarScopeProvider tenantDb) public async Task<(List<IConditionalModel>? contidions, string? ruleScope, List<IConditionalModel>? otherContidions)> GetSpecialVisibleDataRuleFilter<T>(ISugarQueryable<T> queryable,SqlSugarScopeProvider tenantDb)
{ {
// 因为TaskBaseAllocation不能继承IOrgId所以在这里根据条件在需要的时候手动添加IOrgId查询筛选器 // 因为TaskBaseAllocation不能继承IOrgId所以在这里根据条件在需要的时候手动添加IOrgId查询筛选器
bool isTask = typeof(T) == typeof(TaskBaseAllocation); bool isTask = typeof(T) == typeof(TaskBaseAllocation);
@ -1606,7 +1606,7 @@ public class CommonService : ICommonService
{ {
if (isTask) queryable.Filter(typeof(IOrgId)); if (isTask) queryable.Filter(typeof(IOrgId));
return (queryable, "all", otherContidions); //超级管理员特权 return (contidions, "all", otherContidions); //超级管理员特权
} }
var moduleName = typeof(T).Name.ToLower(); 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); .First(u => u.UserId == long.Parse(user.UserId) && u.PermissionEntity.ToLower() == moduleName && u.Status == StatusEnum.Enable);
if (rule.IsNull()) if (rule.IsNull())
{ {
return (queryable, null, otherContidions); //默认查询 return (contidions, null, otherContidions); //默认查询
} }
else else
{ {
@ -1624,18 +1624,18 @@ public class CommonService : ICommonService
if ((long)rule.VisibleTemplateId == 0) if ((long)rule.VisibleTemplateId == 0)
{ {
contidions.Add(new ConditionalModel { FieldName = "CreateBy", ConditionalType = ConditionalType.Equal, FieldValue = user.UserId }); 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<CodeDataRuleTemplate>().First(x => x.Id == (long)rule.VisibleTemplateId); var ruleInfo = tenantDb.Queryable<CodeDataRuleTemplate>().First(x => x.Id == (long)rule.VisibleTemplateId);
if (ruleInfo.RuleScope == "all") if (ruleInfo.RuleScope == "all")
{ {
return (queryable.ClearFilter<IOrgId>().ClearFilter<ISharedOrgId>(), ruleInfo.RuleScope, otherContidions); //查询全部 return (contidions, ruleInfo.RuleScope, otherContidions); //查询全部
} }
else if (ruleInfo.RuleScope == "none") else if (ruleInfo.RuleScope == "none")
{ {
if (isTask) if (isTask)
{ return (queryable, ruleInfo.RuleScope, otherContidions); } { return (contidions, ruleInfo.RuleScope, otherContidions); }
else else
{ {
SqlSugar.Check.ExceptionEasy("NO Operation", "没有数据查看权限!");//返回提示 SqlSugar.Check.ExceptionEasy("NO Operation", "没有数据查看权限!");//返回提示
@ -1648,11 +1648,11 @@ public class CommonService : ICommonService
var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules); var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules);
if (conditionalModels.Count > 0) if (conditionalModels.Count > 0)
{ {
return (queryable.Where(conditionalModels), ruleInfo.RuleScope, additions);//自定义查询 return (conditionalModels, ruleInfo.RuleScope, additions);//自定义查询
} }
else else
{ {
return (queryable.Where(contidions), ruleInfo.RuleScope, otherContidions);//默认查询 return (contidions, ruleInfo.RuleScope, otherContidions);//默认查询
} }
} }
else if (ruleInfo.RuleScope == "self_org_with_child") // 当前机构及下属机构 else if (ruleInfo.RuleScope == "self_org_with_child") // 当前机构及下属机构
@ -1661,7 +1661,7 @@ public class CommonService : ICommonService
IEnumerable<long> orgIdList = orgList.Select(x => x.Id); IEnumerable<long> orgIdList = orgList.Select(x => x.Id);
contidions.Add(new ConditionalModel { FieldName = "OrgId", ConditionalType = ConditionalType.In, FieldValue = string.Join(",", orgIdList) }); 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") else if (ruleInfo.RuleScope == "self")
{ {
@ -1669,12 +1669,12 @@ public class CommonService : ICommonService
var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules); var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules);
if (conditionalModels.Count > 0) if (conditionalModels.Count > 0)
{ {
return (queryable.Where(conditionalModels), ruleInfo.RuleScope, additions);//自定义查询 return (conditionalModels, ruleInfo.RuleScope, additions);//自定义查询
} }
else else
{ {
contidions.Add(new ConditionalModel { FieldName = "CreateBy", ConditionalType = ConditionalType.Equal, FieldValue = user.UserId }); 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); var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules);
if (conditionalModels.Count > 0) if (conditionalModels.Count > 0)
{ {
return (queryable.Where(conditionalModels), ruleInfo.RuleScope, additions);//自定义查询 return (conditionalModels, ruleInfo.RuleScope, additions);//自定义查询
} }
else else
{ {
var deptUsers = db.Queryable<SysUser>().Where(x => x.DeptId == userInfo.DeptId).Select(x => x.Id).ToList(); 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) }); 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") else if (ruleInfo.RuleScope == "select_org")
@ -1708,14 +1708,14 @@ public class CommonService : ICommonService
// db.ConfigQuery.Context.Utilities.JsonToConditionalModels( // db.ConfigQuery.Context.Utilities.JsonToConditionalModels(
// JsonConvert.SerializeObject(conditions)); // JsonConvert.SerializeObject(conditions));
var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules); var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules);
return (queryable.ClearFilter<IOrgId>().ClearFilter<ISharedOrgId>().Where(conditionalModels), ruleInfo.RuleScope, additions); //查询指定机构 return (conditionalModels, ruleInfo.RuleScope, additions); //查询指定机构
} }
else if (ruleInfo.RuleScope == "select_user") else if (ruleInfo.RuleScope == "select_user")
{ {
//var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules); //var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules); var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules); var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules);
return (queryable.ClearFilter<IOrgId>().ClearFilter<ISharedOrgId>().Where(conditionalModels), ruleInfo.RuleScope, additions);//查询指定人员 return (conditionalModels, ruleInfo.RuleScope, additions);//查询指定人员
} }
else if (ruleInfo.RuleScope == "customize") else if (ruleInfo.RuleScope == "customize")
@ -1723,15 +1723,15 @@ public class CommonService : ICommonService
//var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules); //var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules); var conditionalModels = ConvertConditionalModel(ruleInfo.DataRules);
var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules); var additions = ConvertConditionalModel(ruleInfo.AdditionDataRules);
return (queryable.Where(conditionalModels), ruleInfo.RuleScope, additions);//自定义查询 return (conditionalModels, ruleInfo.RuleScope, additions);//自定义查询
} }
else if (ruleInfo.DataRules.IsNull()) else if (ruleInfo.DataRules.IsNull())
{ {
contidions.Add(new ConditionalModel { FieldName = "CreateBy", ConditionalType = ConditionalType.Equal, FieldValue = user.UserId }); 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 #endregion
} }

Loading…
Cancel
Save