修改当前用户OrgId取值方式

usertest
zhangxiaofeng 4 months ago
parent f2b7df4f2c
commit e70578b528

@ -179,7 +179,7 @@ public class SaasDbService : ISaasDbService
//全局过滤租户Id //全局过滤租户Id
dbProvider.QueryFilter.AddTableFilter<ITenantId>(m => m.TenantId ==long.Parse(user.TenantId)); dbProvider.QueryFilter.AddTableFilter<ITenantId>(m => m.TenantId ==long.Parse(user.TenantId));
//全局过滤机构Id //全局过滤机构Id
dbProvider.QueryFilter.AddTableFilter<IOrgId>(m => m.OrgId == user.GetOrgId()); dbProvider.QueryFilter.AddTableFilter<IOrgId>(m => m.OrgId == user.OrgId);
//全局软删除过滤 //全局软删除过滤
dbProvider.QueryFilter.AddTableFilter<IDeleted>(m => m.Deleted == false); dbProvider.QueryFilter.AddTableFilter<IDeleted>(m => m.Deleted == false);
} }

@ -92,7 +92,7 @@ public static class SqlsugarInstall
UserId = "1288018625843826688", UserId = "1288018625843826688",
TenantId = "1288018625843826688", TenantId = "1288018625843826688",
CompanyId = "1288018625843826688", CompanyId = "1288018625843826688",
OrgId = "1288018625843826688" OrgId = 1288018625843826688
}; };
} }

@ -79,22 +79,14 @@ public class AspNetUser : IUser
} }
public long GetTenantId() public long GetTenantId()
{ {
var token = GetToken();
if (string.IsNullOrEmpty(token))
{
return 0;
}
var jwtHandler = new JwtSecurityTokenHandler(); if (string.IsNullOrEmpty(_tenantId))
if (!jwtHandler.CanReadToken(token))
{ {
return 0; var claimValue = GetClaimValueByType("TenantId").FirstOrDefault();
_tenantId = claimValue != null ? claimValue : "0";
} }
return long.Parse(_tenantId);
JwtSecurityToken jwtToken = jwtHandler.ReadJwtToken(token);
var tenantIdClaim = jwtToken.Claims.FirstOrDefault(x => x.Type == "TenantId");
return tenantIdClaim != null ? Convert.ToInt64(tenantIdClaim.Value) : 0;
} }
//public long GetTenantId() //public long GetTenantId()
@ -119,22 +111,12 @@ public class AspNetUser : IUser
public long GetOrgId() public long GetOrgId()
{ {
var token = GetToken(); if (_orgId == 0)
if (string.IsNullOrEmpty(token))
{ {
return 0; var claimValue = GetClaimValueByType("OrgId").FirstOrDefault();
_orgId = claimValue != null ? long.Parse(claimValue) : 0;
} }
return _orgId;
var jwtHandler = new JwtSecurityTokenHandler();
if (!jwtHandler.CanReadToken(token))
{
return 0;
}
JwtSecurityToken jwtToken = jwtHandler.ReadJwtToken(token);
var orgIdClaim = jwtToken.Claims.FirstOrDefault(x => x.Type == "OrgId");
return orgIdClaim != null ? Convert.ToInt64(orgIdClaim.Value) : 0;
} }
//public long GetOrgId() //public long GetOrgId()
@ -236,16 +218,16 @@ public class AspNetUser : IUser
} }
// public string OrgId => GetClaimValueByType("OrgId").FirstOrDefault().ObjToString(); // public string OrgId => GetClaimValueByType("OrgId").FirstOrDefault().ObjToString();
private string _orgId; private long _orgId;
public string OrgId public long OrgId
{ {
get get
{ {
if (_orgId == null) if (_orgId == 0)
{ {
var orgIdClaim = GetClaimValueByType("OrgId").FirstOrDefault(); var orgIdClaim = GetClaimValueByType("OrgId").FirstOrDefault();
_orgId = orgIdClaim != null ? orgIdClaim.ObjToString() : "0"; _orgId = orgIdClaim != null ? long.Parse(orgIdClaim) : 0;
} }
return _orgId; return _orgId;
} }

@ -38,7 +38,7 @@ public interface IUser
/// <summary> /// <summary>
/// 机构ID /// 机构ID
/// </summary> /// </summary>
string OrgId { get; } long OrgId { get; }
/// <summary> /// <summary>
/// 获取机构ID /// 获取机构ID
/// </summary> /// </summary>

@ -95,7 +95,7 @@ namespace DS.WMS.Core.Fee.Method
return DataResult<ExchangeRate>.Success(exchange); return DataResult<ExchangeRate>.Success(exchange);
} }
long id = long.Parse(User.OrgId); long id = User.OrgId;
//获取本位币,默认=人民币 //获取本位币,默认=人民币
string localCurrency = Db.Queryable<SysOrg>().Where(x => x.Id == id).Select(x => x.LocalCurrency).First() ?? RMB_CODE; string localCurrency = Db.Queryable<SysOrg>().Where(x => x.Id == id).Select(x => x.LocalCurrency).First() ?? RMB_CODE;

@ -31,7 +31,7 @@ public class ClientInfoService : ServiceBase, IClientInfoService
/// <returns></returns> /// <returns></returns>
public DataResult<List<ClientInfoRes>> GetListByPage(PageRequest request) public DataResult<List<ClientInfoRes>> GetListByPage(PageRequest request)
{ {
long orgId = long.Parse(User.OrgId); long orgId = User.OrgId;
//序列化查询条件 //序列化查询条件
var whereList = request.GetConditionalModels(Db); var whereList = request.GetConditionalModels(Db);
var data = TenantDb.Queryable<InfoClient>() var data = TenantDb.Queryable<InfoClient>()

@ -1501,7 +1501,7 @@ namespace DS.WMS.Core.Op.Method
FileSize = fileSize, FileSize = fileSize,
FileType = Path.GetExtension(fileName), FileType = Path.GetExtension(fileName),
Extension = Path.GetExtension(fileName), Extension = Path.GetExtension(fileName),
OrgId = long.Parse(user.OrgId) OrgId = user.OrgId
}; };
await tenantDb.Insertable<OpFile>(newFile).ExecuteCommandAsync(); await tenantDb.Insertable<OpFile>(newFile).ExecuteCommandAsync();

@ -1460,7 +1460,7 @@ namespace DS.WMS.Core.TaskPlat.Method
FileSize = fileSize, FileSize = fileSize,
FileType = Path.GetExtension(fileName), FileType = Path.GetExtension(fileName),
Extension = Path.GetExtension(fileName), Extension = Path.GetExtension(fileName),
OrgId = long.Parse(user.OrgId) OrgId = user.OrgId
}; };
await tenantDb.Insertable<OpFile>(bookFile).ExecuteCommandAsync(); await tenantDb.Insertable<OpFile>(bookFile).ExecuteCommandAsync();

@ -232,6 +232,14 @@ namespace DS.WMS.Core.TaskPlat.Method
logger.LogInformation("批次={no} 接收到创建任务报文 报文={msg}", batchNo, JsonConvert.SerializeObject(info)); logger.LogInformation("批次={no} 接收到创建任务报文 报文={msg}", batchNo, JsonConvert.SerializeObject(info));
SqlSugarScopeProvider tenantDb = saasDbService.GetBizDbScopeById(user.TenantId); SqlSugarScopeProvider tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
//var sql = tenantDb.Queryable<SeaExport>().Where(x => x.Id > 232 ).ToSqlString();
//var a = user.UserId;
//var aa = user.TenantId;
//var a343 = user.GetTenantId();
//var sfdfd = user.TenantName;
//var b = user.GetOrgId();
//var b232 = user.OrgId;
TaskBaseInfo taskInfo = null; TaskBaseInfo taskInfo = null;
@ -1763,6 +1771,8 @@ namespace DS.WMS.Core.TaskPlat.Method
bc.PRICE_CALCULATION_DATE bc.PRICE_CALCULATION_DATE
}) })
.Distinct().ToQueryPageAsync(querySearch.PageCondition); .Distinct().ToQueryPageAsync(querySearch.PageCondition);
//var sql = queryable.ToSqlString();
return result; return result;
} }
case TaskBaseTypeEnum.SI_FEEDBACK: case TaskBaseTypeEnum.SI_FEEDBACK:
@ -2119,6 +2129,8 @@ namespace DS.WMS.Core.TaskPlat.Method
/// <returns>返回回执</returns> /// <returns>返回回执</returns>
public async Task<DataResult<TaskUserStatResultInfo>> GetCurrentTotalStat(bool isReCalc) public async Task<DataResult<TaskUserStatResultInfo>> GetCurrentTotalStat(bool isReCalc)
{ {
TaskUserStatResultInfo resultInfo = new TaskUserStatResultInfo TaskUserStatResultInfo resultInfo = new TaskUserStatResultInfo
{ {
LevelTop = new List<TaskUserStatItem>(), LevelTop = new List<TaskUserStatItem>(),
@ -2150,6 +2162,15 @@ namespace DS.WMS.Core.TaskPlat.Method
var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId); var tenantDb = saasDbService.GetBizDbScopeById(user.TenantId);
//var sql = tenantDb.Queryable<SeaExport>().Where(x => x.Id > 232).ToSqlString();
//var a = user.UserId;
//var aa = user.TenantId;
//var a343 = user.GetTenantId();
//var sfdfd = user.TenantName;
//var b = user.GetOrgId();
//var b232 = user.OrgId;
//await MatchTask(); //await MatchTask();
var userId = long.Parse(user.UserId); var userId = long.Parse(user.UserId);
@ -2168,6 +2189,8 @@ namespace DS.WMS.Core.TaskPlat.Method
IsPublic = t.IS_PUBLIC IsPublic = t.IS_PUBLIC
}).ToListAsync(); }).ToListAsync();
//var sql = tenantDb.Queryable<TaskBaseInfo>() //var sql = tenantDb.Queryable<TaskBaseInfo>()
// .LeftJoin<TaskBaseAllocation>((t, a) => t.Id == a.TaskId) // .LeftJoin<TaskBaseAllocation>((t, a) => t.Id == a.TaskId)
// .Where((t, a) => t.IS_PUBLIC == 1 || (t.IS_PUBLIC == 0 && a.Status != null && (t.CreateBy == userId || a.UserId == userId))) // .Where((t, a) => t.IS_PUBLIC == 1 || (t.IS_PUBLIC == 0 && a.Status != null && (t.CreateBy == userId || a.UserId == userId)))

Loading…
Cancel
Save