This commit is contained in:
Putoo
2026-07-17 18:12:08 +08:00
parent c80841880c
commit e4d39f3f2f
9 changed files with 223 additions and 26 deletions

View File

@@ -0,0 +1,11 @@
namespace Application.Domain;
public interface IGameEscortService
{
Task<List<game_escort>> GetEscortData();
Task<game_escort> GetEscortInfo(int esId);
Task<unit_user_escort> GetUserEscort(string userId);
Task<bool> ClearUserEscort(string userId);
Task<bool> UpdateUserEscort(string userId, int esId, string name);
Task<bool> UpdateUserEscort(unit_user_escort data);
}

View File

@@ -0,0 +1,101 @@
namespace Application.Domain;
public class GameEscortService(ISqlSugarClient DbClient, IRedisCache redis) : IGameEscortService, ITransient
{
public async Task<List<game_escort>> GetEscortData()
{
string key = string.Format(BaseCache.BaseCacheKeys, "Escort", "Data");
if (await redis.ExistsAsync(key))
{
return await redis.GetAsync<List<game_escort>>(key);
}
var db = DbClient.AsTenant().GetConnectionWithAttr<game_escort>();
var data = await db.Queryable<game_escort>().ToListAsync();
await redis.SetAsync(key, data);
return data;
}
public async Task<game_escort> GetEscortInfo(int esId)
{
string key = string.Format(BaseCache.BaseCacheKeys, "Escort", "Info");
if (await redis.HExistsHashAsync(key, esId.ToString()))
{
return await redis.GetHashAsync<game_escort>(key, esId.ToString());
}
var db = DbClient.AsTenant().GetConnectionWithAttr<game_escort>();
var data = await db.Queryable<game_escort>().Where(it => it.esId == esId).SingleAsync();
await redis.AddHashAsync(key, esId.ToString(), data);
return data;
}
public async Task<unit_user_escort> GetUserEscort(string userId)
{
string key = string.Format(UserCache.BaseCacheKey, "UserEscort");
if (await redis.HExistsHashAsync(key, userId))
{
return await redis.GetHashAsync<unit_user_escort>(key, userId);
}
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_escort>();
var data = await db.Queryable<unit_user_escort>().Where(it => it.userId == userId).SingleAsync();
if (data == null)
{
data = new unit_user_escort()
{
userId = userId,
esId = 0,
name = "",
state = 0,
endTime = TimeExtend.GetTimeStampSeconds
};
await db.Insertable(data).ExecuteCommandAsync();
}
await redis.AddHashAsync(key, userId, data);
return data;
}
public async Task<bool> ClearUserEscort(string userId)
{
unit_user_escort data = new unit_user_escort()
{
userId = userId,
esId = 0,
name = "",
isUse = 0,
state = 0,
endTime = TimeExtend.GetTimeStampSeconds
};
return await UpdateUserEscort(data);
}
public async Task<bool> UpdateUserEscort(string userId, int esId, string name)
{
long time = TimeExtend.GetTimeStampSeconds + 300;
unit_user_escort data = data = new unit_user_escort()
{
userId = userId,
esId = esId,
name = name,
state = 1,
isUse = 0,
endTime = time
};
return await UpdateUserEscort(data);
}
public async Task<bool> UpdateUserEscort(unit_user_escort data)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_escort>();
var result = await db.Insertable(data).ExecuteCommandAsync() > 0;
if (result)
{
string key = string.Format(UserCache.BaseCacheKey, "UserEscort");
await redis.DelHashAsync(key, data.userId);
}
return result;
}
}

View File

@@ -434,16 +434,12 @@ public class GameTaskService(ISqlSugarClient DbClient, IRedisCache redis) : IGam
var taskInfo = await GetTaskInfo(taskId);
if (taskInfo != null)
{
if (taskInfo.time == 0)
result = TimeExtend.GetTimeStampSecondsByCode(taskInfo.timeSpan, DateTime.Now.AddYears(20));
if (result == 0)
{
result += 3650 * 24 * 60 * 60;
}
else
{
result += (int)taskInfo.time * 60;
result = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddYears(20));
}
}
return result;
}