提交代码

This commit is contained in:
zpc 2024-11-08 19:55:03 +08:00
parent 7f5b0651d4
commit 2e9d387be6
9 changed files with 192 additions and 20 deletions

View File

@ -48,5 +48,31 @@ namespace CloudGaming.Api.Controllers
GameBLL gamebll = new GameBLL(this.ServiceProvider);
return await gamebll.GetGameListAsync(typeId);
}
/// <summary>
/// 获取游戏详情
/// </summary>
/// <param name="gameId"></param>
/// <returns></returns>
[HttpGet]
[RedisCache(2, 2, 0)]
public GameInfoDto GetGameInfo([FromQuery] string gameId)
{
GameBLL gamebll = new GameBLL(this.ServiceProvider);
return gamebll.GetGameInfo(gameId);
}
/// <summary>
/// 根据游戏类型Id 获取游戏列表
/// </summary>
/// <param name="typeId"></param>
/// <returns></returns>
[HttpGet]
[RedisCache(0, 5, 0)]
public List<GameListDto> GameRecommendations([FromQuery] string? gameId)
{
GameBLL gamebll = new GameBLL(this.ServiceProvider);
return gamebll.GameRecommendations(gameId);
}
}
}

View File

@ -1,5 +1,8 @@
using AutoMapper;
using Bogus;
using CloudGaming.Code.Config;
using CloudGaming.Code.DataAccess;
using CloudGaming.DtoModel.Game;
using CloudGaming.GameModel.Db.Db_Game;
@ -38,7 +41,20 @@ namespace CloudGaming.Code.Cache.Special
var gameTypesDict = dao.DaoGame.Context.T_Game_Types.AsNoTracking().ToDictionary(type => type.TypeId);
var gameTagsDict = dao.DaoGame.Context.T_Game_Tags.AsNoTracking().ToDictionary(tag => tag.TagId);
//游戏分享头像
var gameUserShare = dao.DaoGame.Context.T_Game_UserShare.AsNoTracking().GroupBy(it => it.GameId).ToDictionary(it => it.Key, it => it.Last().NickName);
var appConfig = dao.DaoExt.Context.T_App_Config.AsNoTracking().Where(it => it.ConfigType == 3).ToList();
var config = appConfig.GetAppConfig(3, 1, null);
var defaultConsumeDiamondNumHour = 0;
if (!string.IsNullOrEmpty(config?.ConfigValue))
{
int.TryParse(config?.ConfigValue, out defaultConsumeDiamondNumHour);
}
//var lorem = new Bogus.DataSets.Lorem(locale: "zh_CN");
var faker = new Faker("zh_CN");
//f.r
//lorem.
var gameInfos = gameCbtList
.Where(gameCbt => gameListDict.ContainsKey(gameCbt.GameId))
.Select(gameCbt =>
@ -48,6 +64,27 @@ namespace CloudGaming.Code.Cache.Special
game.ToGameInfo(gameInfo);
gameInfo.GameType = GetGameExtendedAttributes(gameChildList, gameCbt.GameId, 1, gameTypesDict);
gameInfo.GameTags = GetGameExtendedAttributes(gameChildList, gameCbt.GameId, 2, gameTagsDict);
if (!gameUserShare.TryGetValue(gameCbt.GameId, out string NickName))
{
string chineseName = faker.Internet.UserName();
NickName = chineseName;
}
gameInfo.GameShare = $"此游戏由{NickName}分享。";
gameInfo.GameShareUserIcon = 90001;
if (gameInfo.ConsumeDiamondNumHour == 0)
{
gameInfo.ConsumeDiamondNumHour = defaultConsumeDiamondNumHour;
}
if (gameInfo.ConsumeDiamondNumHour > 0)
{
gameInfo.GameDetailsofCharges = $"游戏资费:游玩按分钟计费,{gameInfo.ConsumeDiamondNumHour}钻石/小时。";
}
else
{
gameInfo.GameDetailsofCharges = $"游戏免费";
}
return gameInfo;
})
.ToList();
@ -104,6 +141,14 @@ namespace CloudGaming.Code.Cache.Special
}
}
//public Task<List<GameInfo>> DataListAsync
//{
// get
// {
// return new List<GameInfo>();
// }
//}
private Dictionary<string, GameInfo> gameInfoDic;
/// <summary>
/// 游戏详情

View File

@ -11,6 +11,7 @@
<ItemGroup>
<PackageReference Include="AgileConfig.Client" Version="1.7.3" />
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="Bogus" Version="35.6.1" />
<PackageReference Include="FastMember" Version="1.5.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.10" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />

View File

@ -46,9 +46,9 @@ public static class AppConfigBLLExtend
/// <param name="cfgId"></param>
/// <param name="appRequestInfo"></param>
/// <returns></returns>
public static T_App_Config GetAppConfig(this List<T_App_Config> app_Configs, int cfgType, int cfgId, AppRequestConfig appRequestInfo)
public static T_App_Config GetAppConfig(this List<T_App_Config> app_Configs, int cfgType, int cfgId, AppRequestConfig? appRequestInfo)
{
var list = GetAppCfgList(app_Configs, cfgType, cfgId, appRequestInfo.Channel, appRequestInfo.Platform, appRequestInfo.Continent, appRequestInfo.CountryName);
var list = GetAppCfgList(app_Configs, cfgType, cfgId, appRequestInfo?.Channel, appRequestInfo?.Platform, appRequestInfo?.Continent, appRequestInfo?.CountryName);
return list.FirstOrDefault();
}

View File

@ -60,5 +60,50 @@ namespace CloudGaming.Code.Game
return gameListDto;
}
/// <summary>
/// 获取游戏详情
/// </summary>
/// <param name="gameId"></param>
/// <returns></returns>
public GameInfoDto GetGameInfo(string gameId)
{
if (string.IsNullOrEmpty(gameId))
{
return null;
}
var game = Cache.GameEntityCache[gameId];
if (game == null)
{
return null;
}
var gameInfo = Mapper.Map<GameInfoDto>(game);
return gameInfo;
}
/// <summary>
/// 游戏推荐
/// </summary>
/// <param name="gameId"></param>
/// <returns></returns>
public List<GameListDto> GameRecommendations(string gameId)
{
List<GameInfo>? gameInfos = null;
if (!string.IsNullOrEmpty(gameId))
{
var game = Cache.GameEntityCache[gameId];
if (game != null)
{
var gameTagIds = game.GameTags.Select(it => it.Id);
gameInfos = Cache.GameInfos.Where(it => it.GameTags.Any(tag => gameTagIds.Contains(tag.Id))).OrderBy(it => Guid.NewGuid()).Take(3).ToList();
}
}
if (gameInfos == null || gameInfos.Count == 0)
{
gameInfos = Cache.GameInfos.OrderBy(it => Guid.NewGuid()).Take(3).ToList();
}
var gameList = gameInfos?.Select(it => new GameListDto(it)).ToList();
return gameList ?? new List<GameListDto>();
}
}
}

View File

@ -42,6 +42,10 @@ namespace CloudGaming.DtoModel.Game
#endregion
/// <summary>
/// 游戏资费明细
/// </summary>
public string GameDetailsofCharges { get; set; }
/// <summary>
/// 游戏标签
/// </summary>
@ -53,6 +57,15 @@ namespace CloudGaming.DtoModel.Game
public List<GameExtendedAttribute> GameType { get; set; }
#region
/// <summary>
/// 游戏分享
/// </summary>
public string GameShare { get; set; }
/// <summary>
/// 游戏分享人员的Id
/// </summary>
public int GameShareUserIcon { get; set; }
/// <summary>
/// 游戏人数
/// </summary>

View File

@ -1,3 +1,6 @@
using AutoMapper;
using AutoMapper.Configuration.Annotations;
using HuanMeng.DotNetCore.AttributeExtend;
using System;
@ -8,25 +11,45 @@ using System.Threading.Tasks;
namespace CloudGaming.DtoModel.Game
{
/// <summary>
/// 游戏详情
/// </summary>
[AutoMap(typeof(GameInfo))]
public class GameInfoDto
{
public GameInfoDto() { }
/// <summary>
/// 游戏Id
/// </summary>
public virtual string GameId { get; set; } = null!;
public string GameId { get; set; }
/// <summary>
/// 游戏名称
/// </summary>
public virtual string? GameName { get; set; }
/// <summary>
/// 副标题
/// </summary>
[SourceMember(nameof(GameInfo.Title2))]
public virtual string? Subtitle { get; set; }
/// <summary>
/// 游戏资费明细
/// </summary>
public string GameDetailsofCharges { get; set; }
/// <summary>
/// 游戏icon
/// </summary>
[Images("ImageIcon")]
public virtual int ImageIcon { get; set; }
[Images]
[SourceMember(nameof(GameInfo.ImageIconId))]
public int GameIcon { get; set; }
/// <summary>
///
/// 游戏背景图
/// </summary>
[Images("GameBgImage")]
public virtual int GameBgImage { get; set; }
[Images]
[SourceMember(nameof(GameInfo.GameBgImgId))]
public int GameBg { get; set; }
/// <summary>
/// 游戏标签
/// </summary>
@ -36,5 +59,31 @@ namespace CloudGaming.DtoModel.Game
/// 游戏列表
/// </summary>
public List<GameExtendedAttribute> GameType { get; set; }
/// <summary>
/// 评分
/// </summary>
public string? Score { get; set; }
/// <summary>
/// Loading时间
/// </summary>
public int GameLoadTime { get; set; }
/// <summary>
/// 游戏介绍
/// </summary>
public virtual string? GameIntroduce { get; set; }
/// <summary>
/// 游戏分享
/// </summary>
public string GameShare { get; set; }
/// <summary>
/// 游戏分享人员头像
/// </summary>
[Images]
public int GameShareUserIcon { get; set; }
}
}

View File

@ -41,6 +41,7 @@ namespace CloudGaming.DtoModel.Game
gameInfo.SteamId = gameList.SteamId;
gameInfo.GameDifficulty = gameList.GameDifficulty;
gameInfo.GameOperationModel = gameList.GameOperationModel;
return gameInfo;
}

View File

@ -24,7 +24,7 @@ public static class ObjectExtensions
/// <summary>
/// 缓存每个属性是否具有 ImagesAttribute 特性。
/// </summary>
public static readonly ConcurrentDictionary<PropertyInfo, ImagesAttribute?> _PropertyCache = new();
public static readonly ConcurrentDictionary<PropertyInfo, bool> _PropertyCache = new();
/// <summary>
/// 判断对象是否为原始类型或字符串类型。
@ -112,7 +112,7 @@ public static class ObjectExtensions
// 否则,如果是集合类型,则递归转换
keyValuePairs[accessor.PropertyName] = accessor.HasImagesAttribute
? imageFunc?.Invoke((int)propertyValue) ?? ""
: IsCollectionType(propertyValue) ? ToDictionaryOrList(propertyValue, propertyPath, imageFunc) : propertyValue;
: ToDictionaryOrList(propertyValue, propertyPath, imageFunc); // IsCollectionType(propertyValue) ?: propertyValue;
}
return keyValuePairs;
@ -131,16 +131,8 @@ public static class ObjectExtensions
// 创建用于访问属性值的委托
var getter = CreatePropertyGetter(type, property);
// 检查属性是否具有 ImagesAttribute并将结果存储在缓存中
var imagesAttribute = _PropertyCache.GetOrAdd(property, p => p.GetCustomAttribute<ImagesAttribute>());
if (imagesAttribute != null)
{
if (!string.IsNullOrEmpty(imagesAttribute.FieldName))
{
return new PropertyAccessor(imagesAttribute.FieldName, getter, true);
}
return new PropertyAccessor(property.Name, getter, true);
}
return new PropertyAccessor(property.Name, getter, false);
var isImagesAttribute = _PropertyCache.GetOrAdd(property, p => p.GetCustomAttribute<ImagesAttribute>() != null);
return new PropertyAccessor(property.Name, getter, isImagesAttribute);
}).ToArray();
}