164 lines
5.9 KiB
C#
164 lines
5.9 KiB
C#
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<UserFeedback> _feedbackRepo;
|
||
|
|
|
||
|
|
public FeedbackManageController(IUserFeedbackService feedbackService, IMongoBaseRepository<UserFeedback> feedbackRepo)
|
||
|
|
{
|
||
|
|
_feedbackService = feedbackService;
|
||
|
|
_feedbackRepo = feedbackRepo;
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpPost("List")]
|
||
|
|
public async Task<PageResponse<FeedbackDto>> 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<BaseResponse<FeedbackDetailDto>> GetDetail(string id)
|
||
|
|
{
|
||
|
|
var feedback = await _feedbackRepo.FindOneAsync(x => x.Id == id);
|
||
|
|
if (feedback == null)
|
||
|
|
return this.ToFailResult<FeedbackDetailDto>("反馈不存在");
|
||
|
|
|
||
|
|
return this.ToResult(MapToDetailDto(feedback));
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpPost("Reply")]
|
||
|
|
public async Task<BaseResponse<string>> Reply([FromBody] ReplyFeedbackParam param)
|
||
|
|
{
|
||
|
|
var feedback = await _feedbackRepo.FindOneAsync(x => x.Id == param.Id);
|
||
|
|
if (feedback == null)
|
||
|
|
return this.ToFailResult<string>("反馈不存在");
|
||
|
|
|
||
|
|
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<string>("回复失败");
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpPost("Delete")]
|
||
|
|
public async Task<BaseResponse<string>> Delete(string id)
|
||
|
|
{
|
||
|
|
var result = await _feedbackRepo.DeleteByIdAsync(id);
|
||
|
|
if (result.ok)
|
||
|
|
return this.ToResult("删除成功");
|
||
|
|
else
|
||
|
|
return this.ToFailResult<string>("删除失败");
|
||
|
|
}
|
||
|
|
|
||
|
|
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<string>() : 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<string>() : 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<string> Images { get; set; }
|
||
|
|
/// <summary>
|
||
|
|
/// QQ
|
||
|
|
/// </summary>
|
||
|
|
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<string> Images { get; set; }
|
||
|
|
/// <summary>
|
||
|
|
/// QQ
|
||
|
|
/// </summary>
|
||
|
|
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; }
|
||
|
|
}
|
||
|
|
}
|