1212121
This commit is contained in:
@@ -13,6 +13,7 @@ public interface IGameEquService
|
||||
RefAsync<int> Total, bool isRemOn = false);
|
||||
|
||||
Task<List<unit_user_equ>> GetUserEquData(string userId, int equId);
|
||||
Task<List<unit_user_equ>> GetUserEquData(string userId, string code, List<string> noUeId);
|
||||
Task<unit_user_equ> GetUserEquInfo(string ueId);
|
||||
Task<int> GetUserEquByEquIdCount(string userId, int equId);
|
||||
Task<List<unit_user_equ>> GetUserEquByEquId(string userId, int equId);
|
||||
@@ -28,6 +29,7 @@ public interface IGameEquService
|
||||
|
||||
Task<List<unit_user_equ>> GetUserOnEqu(string userId);
|
||||
Task<bool> EquOnOrDown(unit_user_equ data, int state);
|
||||
Task<List<UserEquSuit>> GetUserEquSuit(string userId);
|
||||
#endregion
|
||||
|
||||
#region 辅助
|
||||
|
||||
@@ -56,11 +56,18 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
|
||||
public async Task<List<unit_user_equ>> GetUserEquData(string userId, int equId)
|
||||
{
|
||||
long onTime = TimeExtend.GetTimeStampSeconds;
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
|
||||
return await db.Queryable<unit_user_equ>().Where(it => it.userId == userId && it.equId == equId).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<unit_user_equ>> GetUserEquData(string userId, string code, List<string> noUeId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
|
||||
return await db.Queryable<unit_user_equ>().Where(it => it.userId == userId && it.code == code)
|
||||
.WhereIF(noUeId.Count > 0, it => !noUeId.Contains(it.ueId))
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<unit_user_equ> GetUserEquInfo(string ueId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
|
||||
@@ -325,6 +332,15 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ClearUserOnEqu(string userId)
|
||||
{
|
||||
var key = string.Format(UserCache.BaseCacheKeys, "EquData", "UserOnEqu");
|
||||
await redis.DelHashAsync(key, userId);
|
||||
//清理套装缓存
|
||||
key = string.Format(UserCache.BaseCacheKeys, "EquData:UserEquSuit", userId);
|
||||
await redis.DelAsync(key);
|
||||
}
|
||||
|
||||
public async Task<bool> EquOnOrDown(unit_user_equ data, int state)
|
||||
{
|
||||
data.isOn = state;
|
||||
@@ -334,21 +350,84 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
var equInfo = await GetEquInfo((int)data.equId);
|
||||
if (equInfo.useTime > 0)
|
||||
{
|
||||
data.useEndTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddDays((int)equInfo.useTime)) ;
|
||||
data.useEndTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddDays((int)equInfo.useTime));
|
||||
}
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
|
||||
bool result = await db.Updateable(data).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await ClearUserOnEqu(data.userId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取个人套装
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<UserEquSuit>> GetUserEquSuit(string userId)
|
||||
{
|
||||
List<UserEquSuit> result = new List<UserEquSuit>();
|
||||
long time = TimeExtend.GetTimeStampSeconds;
|
||||
var key = string.Format(UserCache.BaseCacheKeys, "EquData:UserEquSuit", userId);
|
||||
if (await redis.ExistsAsync(key))
|
||||
{
|
||||
result = await redis.GetAsync<List<UserEquSuit>>(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<string> opSuit = new List<string>();
|
||||
var onEquData = await GetUserOnEqu(userId);
|
||||
string[] onEqu = onEquData.Select(it => it.equId.ToString()).ToArray();
|
||||
onEquData = onEquData.FindAll(it => it.useEndTime > time && it.durability > 0);
|
||||
foreach (var item in onEquData)
|
||||
{
|
||||
if (item.suitCode != "0" && !string.IsNullOrEmpty(item.suitCode))
|
||||
{
|
||||
if (!opSuit.Contains(item.suitCode))
|
||||
{
|
||||
opSuit.Add(item.suitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var suit in opSuit)
|
||||
{
|
||||
UserEquSuit temp = new UserEquSuit();
|
||||
var suitInfo = await GetEuqSuitInfo(suit);
|
||||
if (suitInfo != null)
|
||||
{
|
||||
temp.suitCode = suitInfo.suitCode;
|
||||
temp.suitName = suitInfo.suitName;
|
||||
temp.SuitAttr = new List<EquSuitAttr>();
|
||||
foreach (var item in suitInfo.attr)
|
||||
{
|
||||
if (item.NeedType == nameof(EquEnum.SuitAttrNeedType.ON_EQU))
|
||||
{
|
||||
bool same = item.NeedData.All(item => onEqu.Contains(item));
|
||||
if (same)
|
||||
{
|
||||
temp.SuitAttr.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (temp.SuitAttr.Count > 0) //存在满足条件得属性
|
||||
{
|
||||
result.Add(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await redis.SetAsync(key, result, 300);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user