452424
This commit is contained in:
@@ -44,5 +44,12 @@ public interface IUnitUserAttrService
|
||||
Task<bool> UpdateOnLineTime(string userId, string code, int time);
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 药品栏
|
||||
|
||||
Task<unit_user_drug> GetUserDrug(string userId);
|
||||
Task<bool> UpdateUserDrug(unit_user_drug data);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -201,5 +201,12 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
|
||||
return data;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 药品
|
||||
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -351,5 +351,48 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 药品栏
|
||||
|
||||
public async Task<unit_user_drug> GetUserDrug(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "UserTool", "DrugColumn");
|
||||
if (await redis.HExistsHashAsync(key, userId))
|
||||
{
|
||||
return await redis.GetHashAsync<unit_user_drug>(key, userId);
|
||||
}
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_drug>();
|
||||
var data = await db.Queryable<unit_user_drug>().Where(it => it.userId == userId).SingleAsync();
|
||||
if (data == null)
|
||||
{
|
||||
data = new unit_user_drug();
|
||||
data.userId = userId;
|
||||
data.drug = new List<UserDrugModel>();
|
||||
await db.Insertable(data).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
await redis.AddHashAsync(key, userId, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateUserDrug(unit_user_drug data)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_drug>();
|
||||
bool result = await db.Updateable<unit_user_drug>(data).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await ClearUserDrug(data. userId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task ClearUserDrug(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "UserTool", "DrugColumn");
|
||||
await redis.DelHashAsync(key, userId);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user