ArticleCategoryService.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using Infrastructure.Attribute;
  2. using Infrastructure.Extensions;
  3. using Mapster;
  4. using ZR.Model.Content;
  5. using ZR.Model.Content.Dto;
  6. using ZR.Repository;
  7. using ZR.Service.Content.IService;
  8. namespace ZR.Service.Content
  9. {
  10. /// <summary>
  11. /// 文章目录Service业务层处理
  12. /// </summary>
  13. [AppService(ServiceType = typeof(IArticleCategoryService), ServiceLifetime = LifeTime.Transient)]
  14. public class ArticleCategoryService : BaseService<ArticleCategory>, IArticleCategoryService
  15. {
  16. /// <summary>
  17. /// 查询文章目录列表
  18. /// </summary>
  19. /// <param name="parm"></param>
  20. /// <returns></returns>
  21. public PagedInfo<ArticleCategoryDto> GetList(ArticleCategoryQueryDto parm)
  22. {
  23. var predicate = Expressionable.Create<ArticleCategory>();
  24. predicate.AndIF(parm.CategoryType != null, m => m.CategoryType == parm.CategoryType);
  25. predicate.AndIF(parm.ParentId != null, m => m.ParentId == parm.ParentId);
  26. var response = Queryable()
  27. .Where(predicate.ToExpression())
  28. .WithCache(60 * 5)
  29. .ToPage<ArticleCategory, ArticleCategoryDto>(parm);
  30. return response;
  31. }
  32. /// <summary>
  33. /// 查询文章目录树列表
  34. /// </summary>
  35. /// <param name="parm"></param>
  36. /// <returns></returns>
  37. public List<ArticleCategoryDto> GetTreeList(ArticleCategoryQueryDto parm)
  38. {
  39. var predicate = Expressionable.Create<ArticleCategory>();
  40. predicate.AndIF(parm.CategoryType != null, m => m.CategoryType == parm.CategoryType);
  41. var response = Queryable()
  42. .Where(predicate.ToExpression());
  43. if (parm.Sort.IsNotEmpty())
  44. {
  45. response = response.OrderByPropertyName(parm.Sort, parm.SortType.Contains("desc") ? OrderByType.Desc : OrderByType.Asc);
  46. }
  47. var treeList = response.ToTree(it => it.Children, it => it.ParentId, 0);
  48. return treeList.Adapt<List<ArticleCategoryDto>>();
  49. }
  50. /// <summary>
  51. /// 添加文章目录
  52. /// </summary>
  53. /// <param name="parm"></param>
  54. /// <returns></returns>
  55. public int AddArticleCategory(ArticleCategory parm)
  56. {
  57. var response = Add(parm);
  58. return response;
  59. }
  60. /// <summary>
  61. /// 增加加入圈子人数
  62. /// </summary>
  63. /// <param name="categoryId"></param>
  64. /// <returns></returns>
  65. public int PlusJoinNum(int categoryId)
  66. {
  67. return Update(w => w.CategoryId == categoryId, w => new ArticleCategory() { JoinNum = w.JoinNum +1 });
  68. }
  69. /// <summary>
  70. /// 减少加入圈子人数
  71. /// </summary>
  72. /// <param name="categoryId"></param>
  73. /// <returns></returns>
  74. public int ReduceJoinNum(int categoryId)
  75. {
  76. return Update(w => w.CategoryId == categoryId, w => new ArticleCategory() { JoinNum = w.JoinNum - 1 });
  77. }
  78. }
  79. }