修改当前用户OrgId取值方式

usertest
zhangxiaofeng 4 months ago
parent f2b7df4f2c
commit e70578b528

@ -179,7 +179,7 @@ public class SaasDbService : ISaasDbService
//全局过滤租户Id
dbProvider.QueryFilter.AddTableFilter<ITenantId>(m => m.TenantId ==long.Parse(user.TenantId));
//全局过滤机构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);
}

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

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

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

@ -95,7 +95,7 @@ namespace DS.WMS.Core.Fee.Method
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;

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

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

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

@ -232,6 +232,14 @@ namespace DS.WMS.Core.TaskPlat.Method
logger.LogInformation("批次={no} 接收到创建任务报文 报文={msg}", batchNo, JsonConvert.SerializeObject(info));
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;
@ -1763,6 +1771,8 @@ namespace DS.WMS.Core.TaskPlat.Method
bc.PRICE_CALCULATION_DATE
})
.Distinct().ToQueryPageAsync(querySearch.PageCondition);
//var sql = queryable.ToSqlString();
return result;
}
case TaskBaseTypeEnum.SI_FEEDBACK:
@ -2119,6 +2129,8 @@ namespace DS.WMS.Core.TaskPlat.Method
/// <returns>返回回执</returns>
public async Task<DataResult<TaskUserStatResultInfo>> GetCurrentTotalStat(bool isReCalc)
{
TaskUserStatResultInfo resultInfo = new TaskUserStatResultInfo
{
LevelTop = new List<TaskUserStatItem>(),
@ -2150,6 +2162,15 @@ namespace DS.WMS.Core.TaskPlat.Method
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();
var userId = long.Parse(user.UserId);
@ -2168,6 +2189,8 @@ namespace DS.WMS.Core.TaskPlat.Method
IsPublic = t.IS_PUBLIC
}).ToListAsync();
//var sql = tenantDb.Queryable<TaskBaseInfo>()
// .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)))

Loading…
Cancel
Save