添加客户列表及下拉选择客户数据权限

dev
cjy 1 month ago
parent fa4e26d8d8
commit ca5b6058ff

@ -384,6 +384,22 @@ public class SaasDbService : ISaasDbService
}
};
//dbProvider.Aop.OnExecutingChangeSql = (s, p) =>
//{
// foreach (var item in p)
// {
// if (item.ParameterName.Contains("'("))
// {
// var oldName = item.ParameterName;
// //重点看这儿,把参数名变成正常的名字
// item.ParameterName = item.ParameterName
// .Replace("'(", "(")
// .Replace(")'", ")");
// s = s.Replace(oldName, item.ParameterName);
// };
// }
// return new KeyValuePair<string, SugarParameter[]>(s, p);
//};
//var templist = dbProvider.QueryFilter.GeFilterList;
//Console.WriteLine("当前过滤器:"+ JsonConvert.SerializeObject(templist));
//全局过滤租户Id

@ -11,10 +11,13 @@ using DS.WMS.Core.Flow.Interface;
using DS.WMS.Core.Info.Dtos;
using DS.WMS.Core.Info.Entity;
using DS.WMS.Core.Info.Interface;
using DS.WMS.Core.Invoice.Dtos;
using DS.WMS.Core.Op.Dtos.TaskInteraction;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Op.Interface.TaskInteraction;
using DS.WMS.Core.Sys.Entity;
using DS.WMS.Core.Sys.Interface;
using DS.WMS.Core.Sys.Method;
using Fasterflect;
using Mapster;
using Masuit.Tools.Systems;
@ -32,6 +35,7 @@ public class ClientInfoService : ServiceBase, IClientInfoService
Lazy<IClientFlowInstanceService> flowService;
Lazy<ITaskService> taskService;
private readonly ICommonService commonService;
/// <summary>
/// 初始化
@ -41,6 +45,7 @@ public class ClientInfoService : ServiceBase, IClientInfoService
{
flowService = new Lazy<IClientFlowInstanceService>(serviceProvider.GetRequiredService<IClientFlowInstanceService>());
taskService = new Lazy<ITaskService>(serviceProvider.GetRequiredService<ITaskService>());
commonService = serviceProvider.GetRequiredService<ICommonService>();
}
#region 审核
@ -408,7 +413,37 @@ public class ClientInfoService : ServiceBase, IClientInfoService
{
//序列化查询条件
var whereList = request.GetConditionalModels(Db);
var query = TenantDb.Queryable<InfoClient>()
#region 数据权限
var queryData = TenantDb.Queryable<InfoClient>();
var conditions = new List<IConditionalModel>();
var scope = string.Empty;
(queryData, scope, conditions) = await commonService.GetSpecialVisibleDataRuleFilter<InfoClient>(queryData, TenantDb);
var userids = new List<string>();
if (conditions.Count > 0)
{
foreach (ConditionalTree item in conditions)
{
Console.WriteLine(item.ConditionalList);
if (item.ConditionalList.Count > 0)
{
foreach (var item1 in item.ConditionalList)
{
var temp = item1.Value as SqlSugar.ConditionalModel;
if (temp.FieldName == "Stakeholders")
{
userids = temp.FieldValue.Split(',').ToList();
}
}
}
}
}
if (userids.Count == 0)
{
userids.Add(User.UserId);
}
#endregion
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>()
.LeftJoin<InfoClientContact>((c, c1) => c.Id == c1.ClientId)
.LeftJoin<InfoClientContract>((c, c1, c2) => c.Id == c2.ClientId)
.InnerJoinIF<InfoClientTag>(request.OtherQueryCondition?.ClientTag != null, (c, c1, c2, ct) => c.Id == ct.ClientId)

@ -760,7 +760,7 @@ public partial class SeaExportService : ISeaExportService
CustomerId = seaExport.ForwarderId,
CustomerName = seaExport.Forwarder,
CustomerType = "booking",
CustomerTypeName = "订舱公司",
CustomerTypeName = "订舱",
Name = defaultContact.Name,
Mobile = defaultContact.Mobile,
Tel = defaultContact.Tel,

@ -195,9 +195,7 @@ public class ClientCommonService : IClientCommonService
var conditions = new List<IConditionalModel>();
var query = tenantDb.Queryable<InfoClient>();
(query, _, conditions) = await commonService.GetSpecialVisibleDataRuleFilter<InfoClient>(query, tenantDb);
//new List<ConditionalCollections>()
(query, _, conditions) = await commonService.GetSpecialVisibleDataRuleFilter<InfoClient>(query, tenantDb);
var userids = new List<string>();
if (conditions.Count>0)
{
@ -1271,10 +1269,37 @@ public class ClientCommonService : IClientCommonService
public async Task<DataResult<List<ClientSelectRes>>> GetClientListByCode(string code = "", string queryKey = "")
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var conditions = new List<IConditionalModel>();
var query = tenantDb.Queryable<InfoClient>();
(query, _, conditions) = await commonService.GetSpecialVisibleDataRuleFilter<InfoClient>(query, tenantDb);
var userids = new List<string>();
if (conditions.Count > 0)
{
foreach (ConditionalTree item in conditions)
{
Console.WriteLine(item.ConditionalList);
if (item.ConditionalList.Count > 0)
{
foreach (var item1 in item.ConditionalList)
{
var temp = item1.Value as SqlSugar.ConditionalModel;
if (temp.FieldName == "Stakeholders")
{
userids = temp.FieldValue.Split(',').ToList();
}
}
}
}
}
if (userids.Count == 0)
{
userids.Add(user.UserId);
}
//code = code.ToLower();
var data = await tenantDb.Queryable<InfoClient>()//.Where(a=> tenantDb.Ado.SqlQuery<dynamic>(sql, new SugarParameter($"@ClientId", a.Id)).Contains(user.UserId))
var data = await query//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)
.Where((a, b) => a.Status == StatusEnum.Enable.ToEnumInt())
.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 == "yard", (a, b) => b.IsYard == true)
.WhereIF(!string.IsNullOrEmpty(code) && code == "booking", (a, b) => b.IsBooking == true)
@ -1310,7 +1335,7 @@ public class ClientCommonService : IClientCommonService
.MergeTable()
.Mapper(it =>
{
it.UserIds = tenantDb.Queryable<InfoClientStakeholder>().Where(c => c.StartDate <= DateTime.Now && c.EndDate >= DateTime.Now && c.ClientId == it.Id).Select(n => n.CreateBy).ToList();
//it.UserIds = tenantDb.Queryable<InfoClientStakeholder>().Where(c => c.StartDate <= DateTime.Now && c.EndDate >= DateTime.Now && c.ClientId == it.Id).Select(n => n.CreateBy).ToList();
})
.OrderBy(x => x.CodeName).Take(20).WithCache($"{SqlSugarCacheConst.InfoClient}{user.TenantId}", SqlSugarCacheConst.CacheDurationInSeconds).ToListAsync();

@ -1754,10 +1754,11 @@ public class CommonService : ICommonService
{
var userInfo = db.Queryable<SysUser>().First(x => x.Id == long.Parse(user.UserId));
var deptUsers = db.Queryable<SysUser>().Where(x => x.DeptId == userInfo.DeptId).Select(n=>n.Id).ToList();
var deptUsers = db.Queryable<SysUser>().Where(x => x.DeptId == userInfo.DeptId).Select(n=>n.Id).ToArray();
//rules = rules.Replace(DataRuleConst.LoginDept, deptUsers.ToString());
//rules = rules.Replace(DataRuleConst.LoginDept, "(" + string.Join(",", deptUsers) + ")");
//rules = rules.Replace(DataRuleConst.LoginDept, userInfo.DeptId.ToString());
rules = rules.Replace(DataRuleConst.LoginDept, string.Join(", ", deptUsers));
rules = rules.Replace(DataRuleConst.LoginDept, string.Join(",", deptUsers));
}
var conditions = rules.ConvertSqlSugarExpression();

Loading…
Cancel
Save