ArticleController.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using GxPress.Auth;
  5. using GxPress.Common.Page;
  6. using GxPress.Repository.Interface;
  7. using GxPress.Request.Article;
  8. using GxPress.Request.BlacklistArticle;
  9. using GxPress.Result.Article;
  10. using GxPress.Service.Interface;
  11. using GxPress.Service.Interface.Article;
  12. using Microsoft.AspNetCore.Authorization;
  13. using Microsoft.AspNetCore.Mvc;
  14. using GxPress.Repository.Interface.WorkFlow;
  15. using GxPress.Request.App.Flow;
  16. using GxPress.Service.Interface.Visit;
  17. namespace GxPress.Api.AppControllers
  18. {
  19. /// <summary>
  20. /// 审批文章/通知
  21. /// </summary>
  22. [Route("api/app/article")]
  23. [ApiController]
  24. [Authorize]
  25. public class ArticleController : ControllerBase
  26. {
  27. private readonly IArticleRepository _articleRepository;
  28. private readonly IBlacklistArticleRepository _blacklistArticleRepository;
  29. private readonly IArticleService _articleService;
  30. private readonly ILoginContext _loginContext;
  31. private readonly IFlowService _flowService;
  32. private readonly IUserRepository _userRepository;
  33. private readonly IFlowFieldValueRepository _flowFieldValueRepository;
  34. private readonly IVisitService _visitService;
  35. public ArticleController(IArticleRepository articleRepository, IBlacklistArticleRepository blacklistArticleRepository,
  36. ILoginContext loginContext, IArticleService articleService, IFlowService flowService, IUserRepository userRepository, IFlowFieldValueRepository flowFieldValueRepository, IVisitService visitService)
  37. {
  38. _articleRepository = articleRepository;
  39. _blacklistArticleRepository = blacklistArticleRepository;
  40. _loginContext = loginContext;
  41. _articleService = articleService;
  42. _flowService = flowService;
  43. _userRepository = userRepository;
  44. _flowFieldValueRepository = flowFieldValueRepository;
  45. _visitService = visitService;
  46. }
  47. /// <summary>
  48. /// 列表
  49. /// </summary>
  50. /// <returns></returns>
  51. [HttpPost("user-article-list")]
  52. public async Task<PagedList<ArticleResult>> GetUserList([FromBody] ArticleSearchRequest request)
  53. {
  54. request.UserId = _loginContext.AccountId;
  55. //屏蔽文章查询文章
  56. var blacklistArticleSearchRequest = new BlacklistArticleSearchRequest { UserId = request.UserId };
  57. var blacklistArticles = await _blacklistArticleRepository.GetListAsync(blacklistArticleSearchRequest);
  58. var pagedList = await _articleRepository.GetUserListAsync(request, blacklistArticles);
  59. foreach (var item in pagedList.Items)
  60. item.ReadCount = await _visitService.GetCountAsync(1, item.Id);
  61. var resultList = new List<Result.Article.ArticleResult>();
  62. if (!string.IsNullOrWhiteSpace(request.Keyword))
  63. {
  64. //获取代办事项
  65. var userId = _loginContext.AccountId;
  66. var flowListRequest = new FlowListRequest();
  67. flowListRequest.Page = request.Page;
  68. flowListRequest.PerPage = request.PerPage;
  69. flowListRequest.Keyword = request.Keyword;
  70. var flowTodoList = await _flowService.ListMyCheckingAsync(userId, flowListRequest, nameof(GxPress.EnumConst.FlowListTypeConst.MyChecking));
  71. foreach (var flowTodo in flowTodoList.Items)
  72. {
  73. var result = new Result.Article.ArticleResult
  74. {
  75. Id = flowTodo.Id,
  76. ProcessId = flowTodo.ProcessId,
  77. FlowId = flowTodo.Id,
  78. UserId = flowTodo.UserId,
  79. Type = nameof(GxPress.EnumConst.TodoTypeConst.ApproverCheck),
  80. State = flowTodo.State,
  81. IsDone = false,
  82. CreatedDate = flowTodo.CreatedDate
  83. };
  84. result.Title = flowTodo.Title;
  85. result.AvatarUrl = flowTodo.AvatarUrl;
  86. result.Summaries = flowTodo.Summaries;
  87. result.SourceType = 1;
  88. resultList.Add(result);
  89. }
  90. }
  91. resultList.AddRange(pagedList.Items);
  92. pagedList.Total = resultList.Count();
  93. pagedList.Items = resultList;
  94. return pagedList;
  95. }
  96. /// <summary>
  97. /// 文章详情
  98. /// </summary>
  99. /// <returns></returns>
  100. [HttpGet("detail/{id}")]
  101. public async Task<ArticleResult> Get(int id)
  102. {
  103. var article = await _articleService.GetAsync(id, _loginContext.AccountId);
  104. return article;
  105. }
  106. /// <summary>
  107. /// 文章详情 web页面
  108. /// </summary>
  109. /// <returns></returns>
  110. [HttpGet("web-detail/{id}")]
  111. [AllowAnonymous]
  112. public async Task<ArticleResult> GetWeb(int id)
  113. {
  114. var article = await _articleService.GetAsync(id, 0);
  115. return article;
  116. }
  117. }
  118. }