diff --git a/src/0-core/HuanMeng.MiaoYu.Code/Category/CategoryBLL.cs b/src/0-core/HuanMeng.MiaoYu.Code/Category/CategoryBLL.cs index 31cfba9..440820d 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/Category/CategoryBLL.cs +++ b/src/0-core/HuanMeng.MiaoYu.Code/Category/CategoryBLL.cs @@ -1,6 +1,8 @@ using HuanMeng.DotNetCore.Base; using HuanMeng.MiaoYu.Model.Dto.Category; using HuanMeng.MiaoYu.Model.Dto.Character; +using HuanMeng.MiaoYu.Model.Dto.Find; +using HuanMeng.MiaoYu.Model.EnumModel.Find; using System; using System.Collections.Generic; @@ -57,5 +59,67 @@ namespace HuanMeng.MiaoYu.Code.Category }); return new BaseResponse>(ResonseCode.Success, "", rList) { }; } + + /// + /// 发现页面-推荐 + /// + /// + public BaseResponse>> GetRecommendList() + { + List> recommendDtos = new List>(); + #region 假数据 + RecommendDto banner = new RecommendDto(); + banner.Title = "Banner"; + banner.Type = RecommendTypeEnum.banner.ToString(); + banner.Data = new List(); + banner.Data.Add(new CommonRecommendData + { + ActionId = "", + ActionType = RecommendActionTypeEnum.Mall.ToString(), + ImageUrl = "", + }); + banner.Data.Add(new CommonRecommendData + { + ActionId = "", + ActionType = RecommendActionTypeEnum.Page.ToString(), + ImageUrl = "", + }); + banner.Data.Add(new CommonRecommendData + { + ActionId = "1", + ActionType = RecommendActionTypeEnum.Chat.ToString(), + ImageUrl = "", + }); + recommendDtos.Add(banner); + RecommendDto tuijian = new RecommendDto(); + tuijian.Title = "推荐"; + tuijian.Type = RecommendTypeEnum.tuijian.ToString(); + tuijian.Data = new List(); + + + RecommendDto xiaoshuo = new RecommendDto(); + xiaoshuo.Data = new List(); + xiaoshuo.Title = "小说"; + xiaoshuo.Type = RecommendTypeEnum.xiaoshuo.ToString(); + int index = 0; + MiaoYuCache.CharacterList.ForEach(x => + { + if (index > 5) + { + return; + } + var data = Mapper.Map(x); + data.ActionType = RecommendActionTypeEnum.Chat.ToString(); + data.ActionId = data.Id.ToString(); + data.ImageUrl = data.BgImage; + tuijian.Data.Add(data); + xiaoshuo.Data.Add(data); + index++; + }); + recommendDtos.Add(tuijian); + recommendDtos.Add(xiaoshuo); + #endregion + return new BaseResponse>>(ResonseCode.Success, "", recommendDtos); + } } } diff --git a/src/0-core/HuanMeng.MiaoYu.Model/Dto/Find/RecommendDto.cs b/src/0-core/HuanMeng.MiaoYu.Model/Dto/Find/RecommendDto.cs index 60f33cd..931a646 100644 --- a/src/0-core/HuanMeng.MiaoYu.Model/Dto/Find/RecommendDto.cs +++ b/src/0-core/HuanMeng.MiaoYu.Model/Dto/Find/RecommendDto.cs @@ -1,14 +1,26 @@ //using HuanMeng.MiaoYu.Model.Dto.Home; +using AutoMapper; + +using HuanMeng.DotNetCore.Base; +using HuanMeng.MiaoYu.Model.Dto.Character; using HuanMeng.MiaoYu.Model.Dto.Label; +using HuanMeng.MiaoYu.Model.EnumModel.Find; + using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; namespace HuanMeng.MiaoYu.Model.Dto.Find { - public class RecommendDto where T : class + + /// + /// 类别推荐 + /// + /// + public class RecommendDto where T : DataListBaseDto { /// /// 热门推荐、热门小说角色、Banner @@ -28,7 +40,7 @@ namespace HuanMeng.MiaoYu.Model.Dto.Find /// /// /// - public class DataListBaseDto + public abstract class DataListBaseDto { /// /// 图片地址 @@ -43,13 +55,33 @@ namespace HuanMeng.MiaoYu.Model.Dto.Find /// /// 行为id /// - public int ActionId { get; set; } + public string ActionId { get; set; } + } + + /// + /// 常用 + /// + public class CommonRecommendData : DataListBaseDto + { + } /// - /// + /// 数据列表 /// + [AutoMap(typeof(CharacterCache))] public class DataListDto : DataListBaseDto { + + /// + /// 人物id + /// + public int Id { get; set; } + + /// + /// 背景图片 + /// + public string BgImage { get; set; } + /// /// 角色名称 /// @@ -69,6 +101,6 @@ namespace HuanMeng.MiaoYu.Model.Dto.Find /// 人物标签 /// public List Label { get; set; } - + } } diff --git a/src/0-core/HuanMeng.MiaoYu.Model/EnumModel/Find/RecommendActionTypeEnum.cs b/src/0-core/HuanMeng.MiaoYu.Model/EnumModel/Find/RecommendActionTypeEnum.cs new file mode 100644 index 0000000..aebbf4b --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Model/EnumModel/Find/RecommendActionTypeEnum.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HuanMeng.MiaoYu.Model.EnumModel.Find +{ + /// + /// 推荐页面动作类型 + /// + public enum RecommendActionTypeEnum + { + /// + /// 跳转页面 + /// + Page, + /// + /// 跳转商城 + /// + Mall, + /// + /// 跳转聊天页 + /// + Chat + } +} diff --git a/src/0-core/HuanMeng.MiaoYu.Model/EnumModel/Find/RecommendTypeEnum.cs b/src/0-core/HuanMeng.MiaoYu.Model/EnumModel/Find/RecommendTypeEnum.cs new file mode 100644 index 0000000..ed6c578 --- /dev/null +++ b/src/0-core/HuanMeng.MiaoYu.Model/EnumModel/Find/RecommendTypeEnum.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HuanMeng.MiaoYu.Model.EnumModel.Find +{ + /// + /// 推荐页面类型 + /// + public enum RecommendTypeEnum + { + /// + /// Banner位 + /// + banner = 0, + /// + /// 推荐 + /// + tuijian = 1, + /// + /// 小说 + /// + xiaoshuo = 2 + } +} diff --git a/src/2-api/HuanMeng.MiaoYu.WebApi/Controllers/CategoryController.cs b/src/2-api/HuanMeng.MiaoYu.WebApi/Controllers/CategoryController.cs index ee0a2b2..ddc5729 100644 --- a/src/2-api/HuanMeng.MiaoYu.WebApi/Controllers/CategoryController.cs +++ b/src/2-api/HuanMeng.MiaoYu.WebApi/Controllers/CategoryController.cs @@ -3,11 +3,14 @@ using HuanMeng.MiaoYu.Code.Cache; using HuanMeng.MiaoYu.Code.Category; using HuanMeng.MiaoYu.Model.Dto.Category; using HuanMeng.MiaoYu.Model.Dto.Character; +using HuanMeng.MiaoYu.Model.Dto.Find; using HuanMeng.MiaoYu.WebApi.Base; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; + namespace HuanMeng.MiaoYu.WebApi.Controllers { /// @@ -44,5 +47,19 @@ namespace HuanMeng.MiaoYu.WebApi.Controllers CategoryBLL categoryBLL = new CategoryBLL(ServiceProvider); return categoryBLL.GetCategoryInfoList(CategoryId); } + + /// + /// 获取推荐页数据 + /// + /// + [HttpGet] + [AllowAnonymous] + public BaseResponse>> GetCategoryFindList() + { + CategoryBLL categoryBLL = new CategoryBLL(ServiceProvider); + //var x = categoryBLL.GetRecommendList(); + //var json = JsonConvert.SerializeObject(x); + return categoryBLL.GetRecommendList(); + } } } diff --git a/src/2-api/HuanMeng.MiaoYu.WebApi/HuanMeng.MiaoYu.WebApi.csproj b/src/2-api/HuanMeng.MiaoYu.WebApi/HuanMeng.MiaoYu.WebApi.csproj index 796cb4b..11ffe9c 100644 --- a/src/2-api/HuanMeng.MiaoYu.WebApi/HuanMeng.MiaoYu.WebApi.csproj +++ b/src/2-api/HuanMeng.MiaoYu.WebApi/HuanMeng.MiaoYu.WebApi.csproj @@ -9,6 +9,7 @@ + diff --git a/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs b/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs index 60d1fcb..bbe8739 100644 --- a/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs +++ b/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs @@ -16,6 +16,7 @@ using Serilog; using HuanMeng.MiaoYu.Model.Dto; using System.Text.Json.Serialization; using HuanMeng.DotNetCore.Json; +using Newtonsoft.Json.Serialization; var builder = WebApplication.CreateBuilder(args); //Log.Logger = new LoggerConfiguration() // .WriteTo.Console() @@ -48,12 +49,23 @@ if (type != null) builder.Services.AddAutoMapper(mapperDomain); #endregion -builder.Services.AddControllers().AddJsonOptions(options => +builder.Services.AddControllers().AddNewtonsoftJson(options => { - options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); - options.JsonSerializerOptions.PropertyNamingPolicy = null; - options.JsonSerializerOptions.Converters.Add(new CustomDateTimeConverter("yyyy-MM-dd HH:mm:ss")); + // 配置 Newtonsoft.Json 选项 + options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; // 忽略循环引用 + options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();// 首字母小写(驼峰样式) + options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";// 时间格式化 + //options.SerializerSettings.Converters.Add() + // 其他配置... }); +// .AddJsonOptions(options => +//{ +// //options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.Preserve; +// //options.JsonSerializerOptions.WriteIndented = true; +// options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); +// //options.JsonSerializerOptions.PropertyNamingPolicy = null; +// options.JsonSerializerOptions.Converters.Add(new CustomDateTimeConverter("yyyy-MM-dd HH:mm:ss")); +//}); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(c =>