222
This commit is contained in:
@@ -1,27 +1,18 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameMapService : IGameMapService, ITransient
|
||||
public class GameMapService (ISqlSugarClient DbClient, IRedisCache redis): IGameMapService, ITransient
|
||||
{
|
||||
private readonly ISqlSugarClient _dbClient;
|
||||
private readonly IRedisCache _redisClient;
|
||||
|
||||
public GameMapService(ISqlSugarClient dbClient, IRedisCache redisClient)
|
||||
{
|
||||
_dbClient = dbClient;
|
||||
_redisClient = redisClient;
|
||||
}
|
||||
|
||||
#region 城市地图数据
|
||||
|
||||
public async Task<game_city> GetCityInfo(int cityId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapCityData", "CityData");
|
||||
var data = await _redisClient.GetHashAsync<game_city>(key, cityId.ToString());
|
||||
var data = await redis.GetHashAsync<game_city>(key, cityId.ToString());
|
||||
if (data == null)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_city>();
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city>();
|
||||
data = await db.Queryable<game_city>().Where(it => it.cityId == cityId).SingleAsync();
|
||||
await _redisClient.AddHashAsync(key, cityId.ToString(), data);
|
||||
await redis.AddHashAsync(key, cityId.ToString(), data);
|
||||
}
|
||||
|
||||
return data;
|
||||
@@ -30,17 +21,28 @@ public class GameMapService : IGameMapService, ITransient
|
||||
public async Task<game_city_map> GetMapInfo(string mapId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapCityData", "MapData");
|
||||
var data = await _redisClient.GetHashAsync<game_city_map>(key, mapId);
|
||||
var data = await redis.GetHashAsync<game_city_map>(key, mapId);
|
||||
if (data == null)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_city_map>();
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_map>();
|
||||
data = await db.Queryable<game_city_map>().Where(it => it.mapId == mapId).SingleAsync();
|
||||
await _redisClient.AddHashAsync(key, mapId, data);
|
||||
await redis.AddHashAsync(key, mapId, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<List<game_city_map>> GetMapCity(int cityId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapCityData", "CityShowMap");
|
||||
var data = await redis.GetHashAsync<List<game_city_map>>(key, cityId.ToString());
|
||||
if (data == null)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_map>();
|
||||
data = await db.Queryable<game_city_map>().Where(it => it.cityId == cityId && it.show == 1).ToListAsync();
|
||||
await redis.AddHashAsync(key, cityId.ToString(), data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
public async Task<int> GetMapCityByMapId(string mapId)
|
||||
{
|
||||
var data = await GetMapInfo(mapId);
|
||||
@@ -57,12 +59,12 @@ public class GameMapService : IGameMapService, ITransient
|
||||
public async Task<List<game_city_npc>> GetMapNpc(string mapId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapCityData", "NpcData");
|
||||
var data = await _redisClient.GetHashAsync<List<game_city_npc>>(key, mapId);
|
||||
var data = await redis.GetHashAsync<List<game_city_npc>>(key, mapId);
|
||||
if (data == null)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_city_npc>();
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_npc>();
|
||||
data = await db.Queryable<game_city_npc>().Where(it => it.mapId == mapId && it.status == 1).ToListAsync();
|
||||
await _redisClient.AddHashAsync(key, mapId, data);
|
||||
await redis.AddHashAsync(key, mapId, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
@@ -70,12 +72,12 @@ public class GameMapService : IGameMapService, ITransient
|
||||
public async Task<game_city_npc> GetNpcInfo(int npcId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapCityData", "NpcInfo");
|
||||
var data = await _redisClient.GetHashAsync<game_city_npc>(key, npcId.ToString());
|
||||
var data = await redis.GetHashAsync<game_city_npc>(key, npcId.ToString());
|
||||
if (data == null)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_city_npc>();
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_city_npc>();
|
||||
data = await db.Queryable<game_city_npc>().Where(it => it.npcId == npcId).SingleAsync();
|
||||
await _redisClient.AddHashAsync(key, npcId.ToString(),data);
|
||||
await redis.AddHashAsync(key, npcId.ToString(),data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
@@ -98,14 +100,14 @@ public class GameMapService : IGameMapService, ITransient
|
||||
public async Task<unit_user_online> GetUserOnMap(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKey, "UserOnline");
|
||||
if (await _redisClient.HExistsHashAsync(key, userId))
|
||||
if (await redis.HExistsHashAsync(key, userId))
|
||||
{
|
||||
return await _redisClient.GetHashAsync<unit_user_online>(key, userId);
|
||||
return await redis.GetHashAsync<unit_user_online>(key, userId);
|
||||
}
|
||||
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user_online>();
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_online>();
|
||||
var data = await db.Queryable<unit_user_online>().Where(it => it.userId == userId).SingleAsync();
|
||||
await _redisClient.AddHashAsync(key, userId, data);
|
||||
await redis.AddHashAsync(key, userId, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -117,9 +119,9 @@ public class GameMapService : IGameMapService, ITransient
|
||||
onLine.ip = ip;
|
||||
onLine.upTime = TimeAssist.GetTimeStampNum;
|
||||
string key = string.Format(UserCache.BaseCacheKey, "UserOnline");
|
||||
if (await _redisClient.AddHashAsync(key, userId, onLine))
|
||||
if (await redis.AddHashAsync(key, userId, onLine))
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user_online>();
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_online>();
|
||||
await db.Updateable<unit_user_online>(onLine).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user