using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using System; using System.Threading.Tasks; using ZhonTai.Common.Configs; using ZhonTai.Common.Helpers; using ZhonTai.Common.Domain.Dto; using ZhonTai.Plate.Admin.Service.Document; using ZhonTai.Plate.Admin.Service.Document.Input; namespace ZhonTai.Plate.Admin.HttpApi { /// /// 文档管理 /// public class DocumentController : AreaController { private readonly IDocumentService _documentService; private readonly UploadConfig _uploadConfig; private readonly UploadHelper _uploadHelper; public DocumentController( UploadHelper uploadHelper, IOptionsMonitor uploadConfig, IDocumentService documentService ) { _uploadHelper = uploadHelper; _uploadConfig = uploadConfig.CurrentValue; _documentService = documentService; } /// /// 查询文档列表 /// /// /// /// /// [HttpGet] public async Task GetList(string key, DateTime? start, DateTime? end) { return await _documentService.GetListAsync(key, start, end); } /// /// 查询文档图片列表 /// /// /// [HttpGet] public async Task GetImageList(long id) { return await _documentService.GetImageListAsync(id); } /// /// 查询单条分组 /// /// /// [HttpGet] public async Task GetGroup(long id) { return await _documentService.GetGroupAsync(id); } /// /// 查询单条菜单 /// /// /// [HttpGet] public async Task GetMenu(long id) { return await _documentService.GetMenuAsync(id); } /// /// 查询单条文档内容 /// /// /// [HttpGet] public async Task GetContent(long id) { return await _documentService.GetContentAsync(id); } /// /// 查询精简文档列表 /// /// [HttpGet] public async Task GetPlainList() { return await _documentService.GetPlainListAsync(); } /// /// 新增分组 /// /// /// [HttpPost] public async Task AddGroup(DocumentAddGroupInput input) { return await _documentService.AddGroupAsync(input); } /// /// 新增菜单 /// /// /// [HttpPost] public async Task AddMenu(DocumentAddMenuInput input) { return await _documentService.AddMenuAsync(input); } /// /// 修改分组 /// /// /// [HttpPut] public async Task UpdateGroup(DocumentUpdateGroupInput input) { return await _documentService.UpdateGroupAsync(input); } /// /// 修改菜单 /// /// /// [HttpPut] public async Task UpdateMenu(DocumentUpdateMenuInput input) { return await _documentService.UpdateMenuAsync(input); } /// /// 修改文档内容 /// /// /// [HttpPut] public async Task UpdateContent(DocumentUpdateContentInput input) { return await _documentService.UpdateContentAsync(input); } /// /// 删除文档 /// /// /// [HttpDelete] public async Task SoftDelete(long id) { return await _documentService.SoftDeleteAsync(id); } /// /// 删除图片 /// /// /// /// [HttpDelete] public async Task DeleteImage(long documentId, string url) { return await _documentService.DeleteImageAsync(documentId, url); } /// /// 上传文档图片 /// /// /// [HttpPost] public async Task UploadImage([FromForm] DocumentUploadImageInput input) { var config = _uploadConfig.Document; var res = await _uploadHelper.UploadAsync(input.File, config, new { input.Id }); if (res.Success) { //保存文档图片 var r = await _documentService.AddImageAsync( new DocumentAddImageInput { DocumentId = input.Id, Url = res.Data.FileRequestPath }); if (r.Success) { return ResponseOutput.Ok(res.Data.FileRequestPath); } } return ResponseOutput.NotOk("上传失败!"); } } }