2026-10-12 16:22:04 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Common;
|
|
|
|
|
using CommonDomain;
|
|
|
|
|
using CommonInfrastructure;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using AdminService.Faq;
|
|
|
|
|
|
|
|
|
|
namespace AdminApi.Faq
|
|
|
|
|
{
|
|
|
|
|
[ApiController, Route("adminapi/[controller]")]
|
|
|
|
|
public class FaqController : BaseController
|
|
|
|
|
{
|
|
|
|
|
private readonly IFaqService _faqService;
|
|
|
|
|
|
|
|
|
|
public FaqController(IFaqService faqService)
|
|
|
|
|
{
|
|
|
|
|
_faqService = faqService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2026-10-19 00:44:00 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 获取所有板块
|
|
|
|
|
/// </summary>
|
2026-10-12 16:22:04 +08:00
|
|
|
[HttpGet("Categories")]
|
|
|
|
|
public async Task<BaseCommonResponse> GetCategories()
|
|
|
|
|
{
|
|
|
|
|
var list = await _faqService.GetAllCategories();
|
|
|
|
|
if (list == null)
|
|
|
|
|
return new ListResponse<FaqCategoryDto> { Code = CommonResponseCodeEnum.Success, Data = new List<FaqCategoryDto>() };
|
|
|
|
|
var dtos = list.Select(MapToCategoryDto).ToList();
|
|
|
|
|
return new ListResponse<FaqCategoryDto>
|
|
|
|
|
{
|
|
|
|
|
Code = CommonResponseCodeEnum.Success,
|
|
|
|
|
Info = "获取成功",
|
|
|
|
|
Data = dtos
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-19 00:44:00 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 获取板块树形结构
|
|
|
|
|
/// </summary>
|
2026-10-12 16:22:04 +08:00
|
|
|
[HttpGet("CategoryTree")]
|
|
|
|
|
public async Task<BaseCommonResponse> GetCategoryTree()
|
|
|
|
|
{
|
|
|
|
|
var tree = await _faqService.GetCategoryTree();
|
|
|
|
|
var dtos = tree.Select(MapToTreeNodeDto).ToList();
|
|
|
|
|
return new ListResponse<FaqCategoryTreeNodeDto>
|
|
|
|
|
{
|
|
|
|
|
Code = CommonResponseCodeEnum.Success,
|
|
|
|
|
Info = "获取成功",
|
|
|
|
|
Data = dtos
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-19 00:44:00 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 获取板块详情
|
|
|
|
|
/// </summary>
|
2026-10-12 16:22:04 +08:00
|
|
|
[HttpGet("CategoryDetail")]
|
|
|
|
|
public async Task<BaseResponse<FaqCategoryDto>> GetCategoryDetail(string id)
|
|
|
|
|
{
|
|
|
|
|
var category = await _faqService.GetCategoryById(id);
|
|
|
|
|
if (category == null)
|
|
|
|
|
return this.ToFailResult<FaqCategoryDto>("板块不存在");
|
|
|
|
|
|
|
|
|
|
return this.ToResult(MapToCategoryDto(category));
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-19 00:44:00 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 添加板块
|
|
|
|
|
/// </summary>
|
2026-10-12 16:22:04 +08:00
|
|
|
[HttpPost("AddCategory")]
|
|
|
|
|
public async Task<BaseResponse<string>> AddCategory([FromBody] FaqCategory category)
|
|
|
|
|
{
|
|
|
|
|
var result = await _faqService.AddCategory(category);
|
|
|
|
|
if (result.ok)
|
|
|
|
|
return this.ToResult(result.msg);
|
|
|
|
|
else
|
|
|
|
|
return this.ToFailResult<string>(result.msg);
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-19 00:44:00 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 更新板块
|
|
|
|
|
/// </summary>
|
2026-10-12 16:22:04 +08:00
|
|
|
[HttpPost("UpdateCategory")]
|
|
|
|
|
public async Task<BaseResponse<string>> UpdateCategory([FromBody] FaqCategory category)
|
|
|
|
|
{
|
|
|
|
|
var result = await _faqService.UpdateCategory(category);
|
|
|
|
|
if (result.ok)
|
|
|
|
|
return this.ToResult(result.msg);
|
|
|
|
|
else
|
|
|
|
|
return this.ToFailResult<string>(result.msg);
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-19 00:44:00 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 删除板块
|
|
|
|
|
/// </summary>
|
2026-10-12 16:22:04 +08:00
|
|
|
[HttpPost("DeleteCategory")]
|
|
|
|
|
public async Task<BaseResponse<string>> DeleteCategory(string id)
|
|
|
|
|
{
|
|
|
|
|
var result = await _faqService.DeleteCategory(id);
|
|
|
|
|
if (result.ok)
|
|
|
|
|
return this.ToResult(result.msg);
|
|
|
|
|
else
|
|
|
|
|
return this.ToFailResult<string>(result.msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2026-10-19 00:44:00 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 获取板块下的问题列表
|
|
|
|
|
/// </summary>
|
2026-10-12 16:22:04 +08:00
|
|
|
[HttpGet("Questions")]
|
|
|
|
|
public async Task<BaseCommonResponse> GetQuestions(string categoryId)
|
|
|
|
|
{
|
|
|
|
|
var list = await _faqService.GetQuestionsByCategory(categoryId);
|
|
|
|
|
if (list == null)
|
|
|
|
|
return new ListResponse<FaqQuestionDto> { Code = CommonResponseCodeEnum.Success, Data = new List<FaqQuestionDto>() };
|
|
|
|
|
var dtos = list.Select(MapToQuestionDto).ToList();
|
|
|
|
|
return new ListResponse<FaqQuestionDto>
|
|
|
|
|
{
|
|
|
|
|
Code = CommonResponseCodeEnum.Success,
|
|
|
|
|
Info = "获取成功",
|
|
|
|
|
Data = dtos
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-19 00:44:00 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 分页查询问题
|
|
|
|
|
/// </summary>
|
2026-10-12 16:22:04 +08:00
|
|
|
[HttpPost("QuestionList")]
|
|
|
|
|
public async Task<BaseCommonResponse> GetQuestionList([FromBody] FaqQueryParam param)
|
|
|
|
|
{
|
|
|
|
|
var result = await _faqService.QueryQuestions(param.CategoryId, param.PageIndex, param.PageSize);
|
|
|
|
|
var dtos = result.list.Select(MapToQuestionDto).ToList();
|
|
|
|
|
return new PageDataResponse<FaqQuestionDto>
|
|
|
|
|
{
|
|
|
|
|
Code = CommonResponseCodeEnum.Success,
|
|
|
|
|
Info = "获取成功",
|
|
|
|
|
Data = dtos,
|
|
|
|
|
Count = (int)result.count
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-19 00:44:00 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 获取问题详情
|
|
|
|
|
/// </summary>
|
2026-10-12 16:22:04 +08:00
|
|
|
[HttpGet("QuestionDetail")]
|
|
|
|
|
public async Task<BaseResponse<FaqQuestionDto>> GetQuestionDetail(string id)
|
|
|
|
|
{
|
|
|
|
|
var question = await _faqService.GetQuestionById(id);
|
|
|
|
|
if (question == null)
|
|
|
|
|
return this.ToFailResult<FaqQuestionDto>("问题不存在");
|
|
|
|
|
|
|
|
|
|
return this.ToResult(MapToQuestionDto(question));
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-19 00:44:00 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 添加问题
|
|
|
|
|
/// </summary>
|
2026-10-12 16:22:04 +08:00
|
|
|
[HttpPost("AddQuestion")]
|
|
|
|
|
public async Task<BaseResponse<string>> AddQuestion([FromBody] FaqQuestion question)
|
|
|
|
|
{
|
|
|
|
|
var result = await _faqService.AddQuestion(question);
|
|
|
|
|
if (result.ok)
|
|
|
|
|
return this.ToResult(result.msg);
|
|
|
|
|
else
|
|
|
|
|
return this.ToFailResult<string>(result.msg);
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-19 00:44:00 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 更新问题
|
|
|
|
|
/// </summary>
|
2026-10-12 16:22:04 +08:00
|
|
|
[HttpPost("UpdateQuestion")]
|
|
|
|
|
public async Task<BaseResponse<string>> UpdateQuestion([FromBody] FaqQuestion question)
|
|
|
|
|
{
|
|
|
|
|
var result = await _faqService.UpdateQuestion(question);
|
|
|
|
|
if (result.ok)
|
|
|
|
|
return this.ToResult(result.msg);
|
|
|
|
|
else
|
|
|
|
|
return this.ToFailResult<string>(result.msg);
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-19 00:44:00 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 删除问题
|
|
|
|
|
/// </summary>
|
2026-10-12 16:22:04 +08:00
|
|
|
[HttpPost("DeleteQuestion")]
|
|
|
|
|
public async Task<BaseResponse<string>> DeleteQuestion(string id)
|
|
|
|
|
{
|
|
|
|
|
var result = await _faqService.DeleteQuestion(id);
|
|
|
|
|
if (result.ok)
|
|
|
|
|
return this.ToResult(result.msg);
|
|
|
|
|
else
|
|
|
|
|
return this.ToFailResult<string>(result.msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static FaqCategoryDto MapToCategoryDto(FaqCategory entity)
|
|
|
|
|
{
|
|
|
|
|
if (entity == null) return new FaqCategoryDto();
|
|
|
|
|
return new FaqCategoryDto
|
|
|
|
|
{
|
|
|
|
|
Id = entity.Id ?? "",
|
|
|
|
|
ParentId = entity.ParentId ?? "",
|
|
|
|
|
Name = entity.Name ?? "",
|
|
|
|
|
Icon = entity.Icon ?? "",
|
|
|
|
|
Sort = entity.Sort,
|
|
|
|
|
IsEnable = entity.IsEnable
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static FaqCategoryTreeNodeDto MapToTreeNodeDto(FaqCategoryTreeNode entity)
|
|
|
|
|
{
|
|
|
|
|
if (entity == null) return new FaqCategoryTreeNodeDto();
|
|
|
|
|
return new FaqCategoryTreeNodeDto
|
|
|
|
|
{
|
|
|
|
|
Id = entity.Id ?? "",
|
|
|
|
|
Name = entity.Name ?? "",
|
|
|
|
|
Icon = entity.Icon ?? "",
|
|
|
|
|
Sort = entity.Sort,
|
|
|
|
|
IsEnable = entity.IsEnable,
|
|
|
|
|
Children = entity.Children?.Select(MapToTreeNodeDto).ToList() ?? new List<FaqCategoryTreeNodeDto>(),
|
|
|
|
|
QuestionCount = entity.QuestionCount
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static FaqQuestionDto MapToQuestionDto(FaqQuestion entity)
|
|
|
|
|
{
|
|
|
|
|
if (entity == null) return new FaqQuestionDto();
|
|
|
|
|
return new FaqQuestionDto
|
|
|
|
|
{
|
|
|
|
|
Id = entity.Id ?? "",
|
|
|
|
|
CategoryId = entity.CategoryId ?? "",
|
|
|
|
|
Title = entity.Title ?? "",
|
|
|
|
|
Content = entity.Content ?? "",
|
|
|
|
|
Sort = entity.Sort,
|
|
|
|
|
IsEnable = entity.IsEnable,
|
|
|
|
|
CreateTime = entity.CreateTime
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class FaqCategoryDto
|
|
|
|
|
{
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
public string ParentId { get; set; }
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public string Icon { get; set; }
|
|
|
|
|
public int Sort { get; set; }
|
|
|
|
|
public bool IsEnable { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class FaqCategoryTreeNodeDto
|
|
|
|
|
{
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public string Icon { get; set; }
|
|
|
|
|
public int Sort { get; set; }
|
|
|
|
|
public bool IsEnable { get; set; }
|
|
|
|
|
public List<FaqCategoryTreeNodeDto> Children { get; set; } = new();
|
|
|
|
|
public int QuestionCount { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class FaqQuestionDto
|
|
|
|
|
{
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
public string CategoryId { get; set; }
|
|
|
|
|
public string Title { get; set; }
|
|
|
|
|
public string Content { get; set; }
|
|
|
|
|
public int Sort { get; set; }
|
|
|
|
|
public bool IsEnable { get; set; }
|
|
|
|
|
public DateTime CreateTime { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class FaqQueryParam
|
|
|
|
|
{
|
|
|
|
|
public string? CategoryId { get; set; }
|
|
|
|
|
public int PageIndex { get; set; } = 1;
|
|
|
|
|
public int PageSize { get; set; } = 10;
|
|
|
|
|
}
|
|
|
|
|
}
|