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