添加发现页面-推荐

This commit is contained in:
zpc 2024-07-16 06:30:08 +08:00
parent 7c0d61c43c
commit 81216434d3
7 changed files with 189 additions and 9 deletions

View File

@ -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<List<CharacterSummary>>(ResonseCode.Success, "", rList) { };
}
/// <summary>
/// 发现页面-推荐
/// </summary>
/// <returns></returns>
public BaseResponse<List<RecommendDto<DataListBaseDto>>> GetRecommendList()
{
List<RecommendDto<DataListBaseDto>> recommendDtos = new List<RecommendDto<DataListBaseDto>>();
#region
RecommendDto<DataListBaseDto> banner = new RecommendDto<DataListBaseDto>();
banner.Title = "Banner";
banner.Type = RecommendTypeEnum.banner.ToString();
banner.Data = new List<DataListBaseDto>();
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<DataListBaseDto> tuijian = new RecommendDto<DataListBaseDto>();
tuijian.Title = "推荐";
tuijian.Type = RecommendTypeEnum.tuijian.ToString();
tuijian.Data = new List<DataListBaseDto>();
RecommendDto<DataListBaseDto> xiaoshuo = new RecommendDto<DataListBaseDto>();
xiaoshuo.Data = new List<DataListBaseDto>();
xiaoshuo.Title = "小说";
xiaoshuo.Type = RecommendTypeEnum.xiaoshuo.ToString();
int index = 0;
MiaoYuCache.CharacterList.ForEach(x =>
{
if (index > 5)
{
return;
}
var data = Mapper.Map<DataListDto>(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<List<RecommendDto<DataListBaseDto>>>(ResonseCode.Success, "", recommendDtos);
}
}
}

View File

@ -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<T> where T : class
/// <summary>
/// 类别推荐
/// </summary>
/// <typeparam name="T"></typeparam>
public class RecommendDto<T> where T : DataListBaseDto
{
/// <summary>
/// 热门推荐、热门小说角色、Banner
@ -28,7 +40,7 @@ namespace HuanMeng.MiaoYu.Model.Dto.Find
/// <summary>
///
/// </summary>
public class DataListBaseDto
public abstract class DataListBaseDto
{
/// <summary>
/// 图片地址
@ -43,13 +55,33 @@ namespace HuanMeng.MiaoYu.Model.Dto.Find
/// <summary>
/// 行为id
/// </summary>
public int ActionId { get; set; }
public string ActionId { get; set; }
}
/// <summary>
/// 常用
/// </summary>
public class CommonRecommendData : DataListBaseDto
{
}
/// <summary>
///
/// 数据列表
/// </summary>
[AutoMap(typeof(CharacterCache))]
public class DataListDto : DataListBaseDto
{
/// <summary>
/// 人物id
/// </summary>
public int Id { get; set; }
/// <summary>
/// 背景图片
/// </summary>
public string BgImage { get; set; }
/// <summary>
/// 角色名称
/// </summary>
@ -69,6 +101,6 @@ namespace HuanMeng.MiaoYu.Model.Dto.Find
/// 人物标签
/// </summary>
public List<LabelDto> Label { get; set; }
}
}

View File

@ -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
{
/// <summary>
/// 推荐页面动作类型
/// </summary>
public enum RecommendActionTypeEnum
{
/// <summary>
/// 跳转页面
/// </summary>
Page,
/// <summary>
/// 跳转商城
/// </summary>
Mall,
/// <summary>
/// 跳转聊天页
/// </summary>
Chat
}
}

View File

@ -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
{
/// <summary>
/// 推荐页面类型
/// </summary>
public enum RecommendTypeEnum
{
/// <summary>
/// Banner位
/// </summary>
banner = 0,
/// <summary>
/// 推荐
/// </summary>
tuijian = 1,
/// <summary>
/// 小说
/// </summary>
xiaoshuo = 2
}
}

View File

@ -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
{
/// <summary>
@ -44,5 +47,19 @@ namespace HuanMeng.MiaoYu.WebApi.Controllers
CategoryBLL categoryBLL = new CategoryBLL(ServiceProvider);
return categoryBLL.GetCategoryInfoList(CategoryId);
}
/// <summary>
/// 获取推荐页数据
/// </summary>
/// <returns></returns>
[HttpGet]
[AllowAnonymous]
public BaseResponse<List<RecommendDto<DataListBaseDto>>> GetCategoryFindList()
{
CategoryBLL categoryBLL = new CategoryBLL(ServiceProvider);
//var x = categoryBLL.GetRecommendList();
//var json = JsonConvert.SerializeObject(x);
return categoryBLL.GetRecommendList();
}
}
}

View File

@ -9,6 +9,7 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6" />
<PackageReference Include="Serilog" Version="4.0.0" />

View File

@ -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 =>