using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Common; using CommonInfrastructure; using Microsoft.AspNetCore.Mvc; using MongoRepository; using UserDomain; using UserDomain.Entity; using UserDomain.Param; namespace AdminApi.Feedbacks { [ApiController, Route("adminapi/[controller]")] public class FeedbackManageController : BaseController { private readonly IUserFeedbackService _feedbackService; private readonly IMongoBaseRepository _feedbackRepo; public FeedbackManageController(IUserFeedbackService feedbackService, IMongoBaseRepository feedbackRepo) { _feedbackService = feedbackService; _feedbackRepo = feedbackRepo; } /// /// 分页查询反馈列表 /// [HttpPost("List")] public async Task> GetList([FromBody] FeedbackQueryParam param) { var result = await _feedbackService.QueryPage(param); var dtos = result.list.Select(MapToDto); return this.ToPageResult(dtos, (int)result.count); } /// /// 获取反馈详情 /// [HttpGet("Detail")] public async Task> GetDetail(string id) { var feedback = await _feedbackRepo.FindOneAsync(x => x.Id == id); if (feedback == null) return this.ToFailResult("反馈不存在"); return this.ToResult(MapToDetailDto(feedback)); } /// /// 回复反馈 /// [HttpPost("Reply")] public async Task> Reply([FromBody] ReplyFeedbackParam param) { var feedback = await _feedbackRepo.FindOneAsync(x => x.Id == param.Id); if (feedback == null) return this.ToFailResult("反馈不存在"); feedback.Reply = param.Reply; feedback.Status = param.Status; feedback.ReplyTime = DateTime.Now; feedback.ReplyAdminId = loginUser.UserId; feedback.ReplyAdminName = loginUser.UserName; var result = await _feedbackRepo.ReplaceOneAsync(feedback); if (result.ok) return this.ToResult("回复成功"); else return this.ToFailResult("回复失败"); } /// /// 删除反馈 /// [HttpPost("Delete")] public async Task> Delete(string id) { var result = await _feedbackRepo.DeleteByIdAsync(id); if (result.ok) return this.ToResult("删除成功"); else return this.ToFailResult("删除失败"); } private static FeedbackDto MapToDto(UserFeedback entity) { return new FeedbackDto { Id = entity.Id, UserId = entity.UserId ?? "", UserNumber = entity.UserNumber ?? "", UserName = entity.UserName ?? "", Type = entity.Type, Title = entity.Title ?? "", Content = entity.Content ?? "", Images = string.IsNullOrEmpty(entity.Images) ? new List() : entity.Images.Split(',').ToList(), QQ = entity.QQ ?? "", Contact = entity.Contact ?? "", Status = entity.Status, Reply = entity.Reply ?? "", ReplyTime = entity.ReplyTime, SubmitTime = entity.SubmitTime }; } private static FeedbackDetailDto MapToDetailDto(UserFeedback entity) { return new FeedbackDetailDto { Id = entity.Id, UserId = entity.UserId ?? "", UserNumber = entity.UserNumber ?? "", UserName = entity.UserName ?? "", Type = entity.Type, Title = entity.Title ?? "", Content = entity.Content ?? "", Images = string.IsNullOrEmpty(entity.Images) ? new List() : entity.Images.Split(',').ToList(), QQ = entity.QQ ?? "", Contact = entity.Contact ?? "", Status = entity.Status, Reply = entity.Reply ?? "", ReplyTime = entity.ReplyTime, ReplyAdminId = entity.ReplyAdminId ?? "", ReplyAdminName = entity.ReplyAdminName ?? "", SubmitTime = entity.SubmitTime }; } } public class FeedbackDto { public string Id { get; set; } public string UserId { get; set; } public string UserNumber { get; set; } public string UserName { get; set; } public int Type { get; set; } public string Title { get; set; } public string Content { get; set; } public List Images { get; set; } /// /// QQ /// public string QQ { get; set; } public string Contact { get; set; } public int Status { get; set; } public string Reply { get; set; } public DateTime? ReplyTime { get; set; } public DateTime SubmitTime { get; set; } } public class FeedbackDetailDto { public string Id { get; set; } public string UserId { get; set; } public string UserNumber { get; set; } public string UserName { get; set; } public int Type { get; set; } public string Title { get; set; } public string Content { get; set; } public List Images { get; set; } /// /// QQ /// public string QQ { get; set; } public string Contact { get; set; } public int Status { get; set; } public string Reply { get; set; } public DateTime? ReplyTime { get; set; } public string ReplyAdminId { get; set; } public string ReplyAdminName { get; set; } public DateTime SubmitTime { get; set; } } }