提交代码
This commit is contained in:
parent
7f5b0651d4
commit
2e9d387be6
|
|
@ -48,5 +48,31 @@ namespace CloudGaming.Api.Controllers
|
||||||
GameBLL gamebll = new GameBLL(this.ServiceProvider);
|
GameBLL gamebll = new GameBLL(this.ServiceProvider);
|
||||||
return await gamebll.GetGameListAsync(typeId);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
|
|
||||||
|
using Bogus;
|
||||||
|
|
||||||
|
using CloudGaming.Code.Config;
|
||||||
using CloudGaming.Code.DataAccess;
|
using CloudGaming.Code.DataAccess;
|
||||||
using CloudGaming.DtoModel.Game;
|
using CloudGaming.DtoModel.Game;
|
||||||
using CloudGaming.GameModel.Db.Db_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 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 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
|
var gameInfos = gameCbtList
|
||||||
.Where(gameCbt => gameListDict.ContainsKey(gameCbt.GameId))
|
.Where(gameCbt => gameListDict.ContainsKey(gameCbt.GameId))
|
||||||
.Select(gameCbt =>
|
.Select(gameCbt =>
|
||||||
|
|
@ -48,6 +64,27 @@ namespace CloudGaming.Code.Cache.Special
|
||||||
game.ToGameInfo(gameInfo);
|
game.ToGameInfo(gameInfo);
|
||||||
gameInfo.GameType = GetGameExtendedAttributes(gameChildList, gameCbt.GameId, 1, gameTypesDict);
|
gameInfo.GameType = GetGameExtendedAttributes(gameChildList, gameCbt.GameId, 1, gameTypesDict);
|
||||||
gameInfo.GameTags = GetGameExtendedAttributes(gameChildList, gameCbt.GameId, 2, gameTagsDict);
|
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;
|
return gameInfo;
|
||||||
})
|
})
|
||||||
.ToList();
|
.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;
|
private Dictionary<string, GameInfo> gameInfoDic;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 游戏详情
|
/// 游戏详情
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AgileConfig.Client" Version="1.7.3" />
|
<PackageReference Include="AgileConfig.Client" Version="1.7.3" />
|
||||||
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
||||||
|
<PackageReference Include="Bogus" Version="35.6.1" />
|
||||||
<PackageReference Include="FastMember" Version="1.5.0" />
|
<PackageReference Include="FastMember" Version="1.5.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.10" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.10" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.1" />
|
||||||
|
|
|
||||||
|
|
@ -46,9 +46,9 @@ public static class AppConfigBLLExtend
|
||||||
/// <param name="cfgId"></param>
|
/// <param name="cfgId"></param>
|
||||||
/// <param name="appRequestInfo"></param>
|
/// <param name="appRequestInfo"></param>
|
||||||
/// <returns></returns>
|
/// <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();
|
return list.FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,5 +60,50 @@ namespace CloudGaming.Code.Game
|
||||||
return gameListDto;
|
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>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,10 @@ namespace CloudGaming.DtoModel.Game
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 游戏资费明细
|
||||||
|
/// </summary>
|
||||||
|
public string GameDetailsofCharges { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 游戏标签
|
/// 游戏标签
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -53,6 +57,15 @@ namespace CloudGaming.DtoModel.Game
|
||||||
public List<GameExtendedAttribute> GameType { get; set; }
|
public List<GameExtendedAttribute> GameType { get; set; }
|
||||||
|
|
||||||
#region 游戏列表数据
|
#region 游戏列表数据
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 游戏分享
|
||||||
|
/// </summary>
|
||||||
|
public string GameShare { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 游戏分享人员的Id
|
||||||
|
/// </summary>
|
||||||
|
public int GameShareUserIcon { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 游戏人数
|
/// 游戏人数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
using AutoMapper;
|
||||||
|
using AutoMapper.Configuration.Annotations;
|
||||||
|
|
||||||
using HuanMeng.DotNetCore.AttributeExtend;
|
using HuanMeng.DotNetCore.AttributeExtend;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
@ -8,25 +11,45 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace CloudGaming.DtoModel.Game
|
namespace CloudGaming.DtoModel.Game
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 游戏详情
|
||||||
|
/// </summary>
|
||||||
|
[AutoMap(typeof(GameInfo))]
|
||||||
public class GameInfoDto
|
public class GameInfoDto
|
||||||
{
|
{
|
||||||
|
public GameInfoDto() { }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 游戏Id
|
/// 游戏Id
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// 游戏icon
|
/// 游戏icon
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Images("ImageIcon")]
|
[Images]
|
||||||
public virtual int ImageIcon { get; set; }
|
[SourceMember(nameof(GameInfo.ImageIconId))]
|
||||||
|
public int GameIcon { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// 游戏背景图
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Images("GameBgImage")]
|
[Images]
|
||||||
public virtual int GameBgImage { get; set; }
|
[SourceMember(nameof(GameInfo.GameBgImgId))]
|
||||||
|
public int GameBg { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 游戏标签
|
/// 游戏标签
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -36,5 +59,31 @@ namespace CloudGaming.DtoModel.Game
|
||||||
/// 游戏列表
|
/// 游戏列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<GameExtendedAttribute> GameType { get; set; }
|
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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ namespace CloudGaming.DtoModel.Game
|
||||||
gameInfo.SteamId = gameList.SteamId;
|
gameInfo.SteamId = gameList.SteamId;
|
||||||
gameInfo.GameDifficulty = gameList.GameDifficulty;
|
gameInfo.GameDifficulty = gameList.GameDifficulty;
|
||||||
gameInfo.GameOperationModel = gameList.GameOperationModel;
|
gameInfo.GameOperationModel = gameList.GameOperationModel;
|
||||||
|
|
||||||
return gameInfo;
|
return gameInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ public static class ObjectExtensions
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 缓存每个属性是否具有 ImagesAttribute 特性。
|
/// 缓存每个属性是否具有 ImagesAttribute 特性。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly ConcurrentDictionary<PropertyInfo, ImagesAttribute?> _PropertyCache = new();
|
public static readonly ConcurrentDictionary<PropertyInfo, bool> _PropertyCache = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 判断对象是否为原始类型或字符串类型。
|
/// 判断对象是否为原始类型或字符串类型。
|
||||||
|
|
@ -112,7 +112,7 @@ public static class ObjectExtensions
|
||||||
// 否则,如果是集合类型,则递归转换
|
// 否则,如果是集合类型,则递归转换
|
||||||
keyValuePairs[accessor.PropertyName] = accessor.HasImagesAttribute
|
keyValuePairs[accessor.PropertyName] = accessor.HasImagesAttribute
|
||||||
? imageFunc?.Invoke((int)propertyValue) ?? ""
|
? imageFunc?.Invoke((int)propertyValue) ?? ""
|
||||||
: IsCollectionType(propertyValue) ? ToDictionaryOrList(propertyValue, propertyPath, imageFunc) : propertyValue;
|
: ToDictionaryOrList(propertyValue, propertyPath, imageFunc); // IsCollectionType(propertyValue) ?: propertyValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return keyValuePairs;
|
return keyValuePairs;
|
||||||
|
|
@ -131,16 +131,8 @@ public static class ObjectExtensions
|
||||||
// 创建用于访问属性值的委托
|
// 创建用于访问属性值的委托
|
||||||
var getter = CreatePropertyGetter(type, property);
|
var getter = CreatePropertyGetter(type, property);
|
||||||
// 检查属性是否具有 ImagesAttribute,并将结果存储在缓存中
|
// 检查属性是否具有 ImagesAttribute,并将结果存储在缓存中
|
||||||
var imagesAttribute = _PropertyCache.GetOrAdd(property, p => p.GetCustomAttribute<ImagesAttribute>());
|
var isImagesAttribute = _PropertyCache.GetOrAdd(property, p => p.GetCustomAttribute<ImagesAttribute>() != null);
|
||||||
if (imagesAttribute != null)
|
return new PropertyAccessor(property.Name, getter, isImagesAttribute);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}).ToArray();
|
}).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user