NoticeService.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using Lazy.SlideCaptcha.Core.Resources;
  2. using Microsoft.AspNetCore.Mvc;
  3. using NPOI.SS.Formula.PTG;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Text.RegularExpressions;
  9. using System.Threading.Tasks;
  10. using ZhonTai.Admin.Core.Attributes;
  11. using ZhonTai.Admin.Core.Consts;
  12. using ZhonTai.Admin.Core.Dto;
  13. using ZhonTai.Admin.Repositories.Notice;
  14. using ZhonTai.Admin.Services.DiTuiAPI.Dto;
  15. using ZhonTai.DynamicApi;
  16. using ZhonTai.DynamicApi.Attributes;
  17. #region <<版本注释>>
  18. /* ---------------------------
  19. * 版权所有 (c) 2023 Frank 保留所有权利。
  20. * CLR版本:4.0.30319.42000
  21. * 机器名称:FRANK-WIN
  22. * 命名空间:ZhonTai.Admin.Services.DiTuiAPI
  23. * 唯一标识:2de10604-3043-4cef-b46f-96757f867b17
  24. *
  25. * 创建者:Frank
  26. * 电子邮箱: cfrank227@gmail.com
  27. * 创建时间:2023/5/25 9:11:42
  28. --------------------------*/
  29. #endregion <<版本注释>>
  30. namespace ZhonTai.Admin.Services.DiTuiAPI
  31. {
  32. /// <summary>
  33. /// 通知公告
  34. /// </summary>
  35. [DynamicApi(Area = AdminConsts.DiTuiName)]
  36. public class NoticeService : BaseService, INoticeService, IDynamicApi
  37. {
  38. private NoticeRepository _noticeRepository;
  39. public NoticeService(NoticeRepository noticeRepository)
  40. {
  41. _noticeRepository = noticeRepository;
  42. }
  43. /// <summary>
  44. /// 公告列表
  45. /// </summary>
  46. /// <returns></returns>
  47. [HttpGet]
  48. [NoOprationLog]
  49. public async Task<PageOutput<NoticeOutput>> IndexAsync(PageInput input)
  50. {
  51. var uId = User?.Id;
  52. var tenantId = User.TenantId;
  53. //List<Notices> notices = new List<Notices>();
  54. // 公告
  55. //notices.Add(new Notices("最新","平台悬赏任务、游戏试玩任务上线通知…","11"));
  56. //notices.Add(new Notices("重要", "快手极速版直推版价格政策调整通知", "22"));
  57. //notices.Add(new Notices("最新", "12月平台项目重要通知请注意查看!12月平台项目重要通知请注意查看!", "33"));
  58. var notices = _noticeRepository.Select.DisableGlobalFilter(FilterNames.Tenant)
  59. .Where(a => a.IsAlter == 0)
  60. .OrderByDescending(m => m.Rank)
  61. .Page(input.CurrentPage, input.PageSize)
  62. .ToList(m => new NoticeOutput()
  63. {
  64. Id = m.Id,
  65. Title = m.Title,
  66. Desc = m.Desc,
  67. //Desc = System.Text.RegularExpressions.Regex.Replace(System.Text.RegularExpressions.Regex.Replace(m.Content, "<[^>]+>", ""), "&[^;]+;", ""),
  68. //Desc = Regex.Replace(m.Content, "<.*?>", string.Empty),
  69. CreateTime = string.Format("{0:yyyy-MM-dd HH:mm:ss}", m.CreatedTime),
  70. Unread = "1"
  71. });
  72. foreach(var item in notices)
  73. {
  74. }
  75. var data = new PageOutput<NoticeOutput>()
  76. {
  77. List = notices,
  78. Total = notices.Count()
  79. };
  80. return data;
  81. }
  82. /// <summary>
  83. /// 公告详情
  84. /// </summary>
  85. /// <param name="id"></param>
  86. /// <returns></returns>
  87. [HttpGet]
  88. [NoOprationLog]
  89. public async Task<NoticeDetailOutput> GetDetailAsync(long id = 0)
  90. {
  91. if(id == 0)
  92. {
  93. throw ResultOutput.Exception("ID不可为空");
  94. }
  95. var noticeDetail = await _noticeRepository.Select.DisableGlobalFilter(FilterNames.Tenant).FirstAsync(a => new NoticeDetailOutput() {
  96. Id = a.Id,
  97. Title = a.Title,
  98. Content = a.Content,
  99. CreateTime = string.Format("{0:yyyy-MM-dd HH:mm:ss}", a.CreatedTime),
  100. });
  101. return noticeDetail;
  102. }
  103. }
  104. }