ArticleCategoryController.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using Microsoft.AspNetCore.Mvc;
  2. using ZR.Model.Content;
  3. using ZR.Model.Content.Dto;
  4. using ZR.Service.Content.IService;
  5. namespace ZR.Admin.WebApi.Controllers
  6. {
  7. /// <summary>
  8. /// 文章目录Controller
  9. /// </summary>
  10. [Route("article/ArticleCategory")]
  11. [ApiExplorerSettings(GroupName = "article")]
  12. public class ArticleCategoryController : BaseController
  13. {
  14. /// <summary>
  15. /// 文章目录接口
  16. /// </summary>
  17. private readonly IArticleCategoryService _ArticleCategoryService;
  18. public ArticleCategoryController(IArticleCategoryService ArticleCategoryService)
  19. {
  20. _ArticleCategoryService = ArticleCategoryService;
  21. }
  22. /// <summary>
  23. /// 查询文章目录列表
  24. /// </summary>
  25. /// <param name="parm"></param>
  26. /// <returns></returns>
  27. [HttpGet("list")]
  28. [AllowAnonymous]
  29. public IActionResult QueryArticleCategory([FromQuery] ArticleCategoryQueryDto parm)
  30. {
  31. var response = _ArticleCategoryService.GetList(parm);
  32. return SUCCESS(response);
  33. }
  34. /// <summary>
  35. /// 查询文章目录列表树
  36. /// </summary>
  37. /// <param name="parm"></param>
  38. /// <returns></returns>
  39. [HttpGet("treeList")]
  40. [AllowAnonymous]
  41. public IActionResult QueryTreeArticleCategory([FromQuery] ArticleCategoryQueryDto parm)
  42. {
  43. var response = _ArticleCategoryService.GetTreeList(parm);
  44. return SUCCESS(response);
  45. }
  46. /// <summary>
  47. /// 查询文章目录详情
  48. /// </summary>
  49. /// <param name="CategoryId"></param>
  50. /// <returns></returns>
  51. [HttpGet("{CategoryId}")]
  52. [AllowAnonymous]
  53. //[ActionPermissionFilter(Permission = "articlecategory:query")]
  54. public IActionResult GetArticleCategory(int CategoryId)
  55. {
  56. var response = _ArticleCategoryService.GetFirst(x => x.CategoryId == CategoryId);
  57. return SUCCESS(response);
  58. }
  59. /// <summary>
  60. /// 查询目录分类
  61. /// </summary>
  62. /// <param name="categoryType"></param>
  63. /// <returns></returns>
  64. [HttpGet("type{categoryType}")]
  65. //[ActionPermissionFilter(Permission = "articlecategory:query")]
  66. public IActionResult GetArticleCategoryByType(int categoryType)
  67. {
  68. var response = _ArticleCategoryService.GetFirst(x => x.CategoryType == categoryType);
  69. return SUCCESS(response);
  70. }
  71. /// <summary>
  72. /// 添加文章目录
  73. /// </summary>
  74. /// <returns></returns>
  75. [HttpPost]
  76. [ActionPermissionFilter(Permission = "articlecategory:add")]
  77. [Log(Title = "文章目录", BusinessType = BusinessType.INSERT)]
  78. public IActionResult AddArticleCategory([FromBody] ArticleCategoryDto parm)
  79. {
  80. var modal = parm.Adapt<ArticleCategory>().ToCreate(HttpContext);
  81. var response = _ArticleCategoryService.AddArticleCategory(modal);
  82. return ToResponse(response);
  83. }
  84. /// <summary>
  85. /// 更新文章目录
  86. /// </summary>
  87. /// <returns></returns>
  88. [HttpPut]
  89. [ActionPermissionFilter(Permission = "articlecategory:edit")]
  90. [Log(Title = "文章目录", BusinessType = BusinessType.UPDATE)]
  91. public IActionResult UpdateArticleCategory([FromBody] ArticleCategoryDto parm)
  92. {
  93. var modal = parm.Adapt<ArticleCategory>().ToUpdate(HttpContext);
  94. var response = _ArticleCategoryService.Update(modal);
  95. return ToResponse(response);
  96. }
  97. /// <summary>
  98. /// 删除文章目录
  99. /// </summary>
  100. /// <returns></returns>
  101. [HttpDelete("{ids}")]
  102. [ActionPermissionFilter(Permission = "articlecategory:delete")]
  103. [Log(Title = "文章目录", BusinessType = BusinessType.DELETE)]
  104. public IActionResult DeleteArticleCategory(string ids)
  105. {
  106. int[] idsArr = Tools.SpitIntArrary(ids);
  107. if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
  108. var response = _ArticleCategoryService.Delete(idsArr);
  109. return ToResponse(response);
  110. }
  111. /// <summary>
  112. /// 导出文章目录
  113. /// </summary>
  114. /// <returns></returns>
  115. [Log(Title = "文章目录", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
  116. [HttpGet("export")]
  117. [ActionPermissionFilter(Permission = "articlecategory:export")]
  118. public IActionResult Export([FromQuery] ArticleCategoryQueryDto parm)
  119. {
  120. parm.PageSize = 10000;
  121. var list = _ArticleCategoryService.GetList(parm).Result;
  122. string sFileName = ExportExcel(list, "ArticleCategory", "文章目录");
  123. return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName });
  124. }
  125. /// <summary>
  126. /// 获取文章目录
  127. /// </summary>
  128. /// <returns></returns>
  129. [HttpGet("CategoryList")]
  130. public IActionResult CategoryList()
  131. {
  132. var response = _ArticleCategoryService.GetAll();
  133. return SUCCESS(response);
  134. }
  135. /// <summary>
  136. /// 保存排序
  137. /// </summary>
  138. /// <param name="id"></param>
  139. /// <param name="value"></param>
  140. /// <returns></returns>
  141. [ActionPermissionFilter(Permission = "articlecategory:edit")]
  142. [HttpGet("ChangeSort")]
  143. [Log(Title = "保存排序", BusinessType = BusinessType.UPDATE)]
  144. public IActionResult ChangeSort(int id = 0, int value = 0)
  145. {
  146. if (id <= 0) { return ToResponse(ApiResult.Error(101, "请求参数错误")); }
  147. var response = _ArticleCategoryService.Update(w => w.CategoryId == id, it => new ArticleCategory ()
  148. {
  149. CategoryId = id,
  150. OrderNum = value
  151. });
  152. return ToResponse(response);
  153. }
  154. }
  155. }