using System; using System.Collections.Generic; using System.Threading.Tasks; using Common; using Common.CommonModel; using CommonInfrastructure; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using UserDomain; using UserDomain.Entity; using UserDomain.Param; namespace UserApi.User { [ApiController, Route("api/[controller]")] [Authorize] public class FeedbackController : BaseController { private readonly IUserFeedbackService _feedbackService; public FeedbackController(IUserFeedbackService feedbackService) { _feedbackService = feedbackService; } [HttpPost("Submit")] public async Task> Submit([FromBody] AddFeedbackParam param) { var result = await _feedbackService.Submit(param, loginUser.UserId, loginUser.Number, loginUser.UserName); if (result) return this.ToResult("提交成功"); else return this.ToFailResult("提交失败"); } [HttpGet("MyList")] public async Task> GetMyList(int pageIndex = 1, int pageSize = 10) { var result = await _feedbackService.GetUserFeedbacks(loginUser.UserId, pageIndex, pageSize); var dtos = result.list.Select(f => new FeedbackDto { Id = f.Id, Type = f.Type, Title = f.Title, Content = f.Content, Images = string.IsNullOrEmpty(f.Images) ? new List() : f.Images.Split(',').ToList(), QQ = f.QQ ?? "", Contact = f.Contact ?? "", Status = f.Status, Reply = f.Reply ?? "", ReplyTime = f.ReplyTime.HasValue ? new DateTimeOffset(f.ReplyTime.Value).ToUnixTimeMilliseconds() : 0, SubmitTime = new DateTimeOffset(f.SubmitTime).ToUnixTimeMilliseconds() }); return this.ToPageResult(dtos, (int)result.count); } [HttpGet("Detail")] public async Task> GetDetail(string id) { var feedback = await _feedbackService.GetById(id, loginUser.UserId); if (feedback == null) return this.ToFailResult("反馈不存在"); var dto = new FeedbackDetailDto { Id = feedback.Id, Type = feedback.Type, Title = feedback.Title, Content = feedback.Content, Images = string.IsNullOrEmpty(feedback.Images) ? new List() : feedback.Images.Split(',').ToList(), QQ = feedback.QQ ?? "", Contact = feedback.Contact ?? "", Status = feedback.Status, Reply = feedback.Reply ?? "", ReplyTime = feedback.ReplyTime.HasValue ? new DateTimeOffset(feedback.ReplyTime.Value).ToUnixTimeMilliseconds() : 0, SubmitTime = new DateTimeOffset(feedback.SubmitTime).ToUnixTimeMilliseconds() }; return this.ToResult(dto); } } public class FeedbackDto { public string Id { get; set; } public int Type { get; set; } public string Title { get; set; } public string Content { get; set; } public List Images { get; set; } public string QQ { get; set; } public string Contact { get; set; } public int Status { get; set; } public string Reply { get; set; } public long ReplyTime { get; set; } public long SubmitTime { get; set; } } public class FeedbackDetailDto { public string Id { get; set; } public int Type { get; set; } public string Title { get; set; } public string Content { get; set; } public List Images { get; set; } public string QQ { get; set; } public string Contact { get; set; } public int Status { get; set; } public string Reply { get; set; } public long ReplyTime { get; set; } public long SubmitTime { get; set; } } }