SnapshotBulletinApplication.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using Hotline.Caching.Interfaces;
  2. using Hotline.Settings;
  3. using Hotline.Share.Attributes;
  4. using Hotline.Share.Dtos.Snapshot;
  5. using Hotline.Snapshot.Interfaces;
  6. using Microsoft.AspNetCore.Http;
  7. using SqlSugar;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Text.RegularExpressions;
  13. using System.Threading.Tasks;
  14. using XF.Domain.Dependency;
  15. namespace Hotline.Application.Snapshot;
  16. public class SnapshotBulletinApplication : ISnapshotBulletinApplication, IScopeDependency
  17. {
  18. private readonly ISystemSettingCacheManager _systemSettingCacheManager;
  19. private readonly ISnapshotBulletinRepository _bulletinRepository;
  20. public SnapshotBulletinApplication(ISystemSettingCacheManager systemSettingCacheManager, ISnapshotBulletinRepository bulletinRepository)
  21. {
  22. _systemSettingCacheManager = systemSettingCacheManager;
  23. _bulletinRepository = bulletinRepository;
  24. }
  25. /// <summary>
  26. /// 处理通知公告图片附件路径
  27. /// </summary>
  28. /// <param name="sHtmlText"></param>
  29. /// <returns></returns>
  30. public string GetSiteUrls(string sHtmlText)
  31. {
  32. sHtmlText = sHtmlText.Replace("&lt;", "<").Replace("&gt;", ">");
  33. //临时内容
  34. System.Text.StringBuilder sb = new StringBuilder();
  35. sb.Append(sHtmlText);
  36. // 定义正则表达式用来匹配 img 标签
  37. Regex regImg = new Regex(@"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase);
  38. // 搜索匹配的字符串
  39. MatchCollection matches = regImg.Matches(sHtmlText);
  40. // 定义正则表达式用来匹配 video 标签
  41. Regex regvideo = new Regex(@"<video\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase);
  42. // 搜索匹配的字符串
  43. MatchCollection matchesvideo = regvideo.Matches(sHtmlText);
  44. var strSiteUrl = _systemSettingCacheManager.GetSetting(SettingConstants.OldFilesUrls)?.SettingValue[0];
  45. // 取得匹配项列表 视频
  46. foreach (Match match in matchesvideo)
  47. {
  48. if (-1 == match.Groups["imgUrl"].Value.IndexOf("http"))
  49. {
  50. sb.Replace(match.Groups["imgUrl"].Value, strSiteUrl + match.Groups["imgUrl"].Value);
  51. sb.Replace(strSiteUrl + strSiteUrl + match.Groups["imgUrl"].Value, strSiteUrl + match.Groups["imgUrl"].Value);
  52. }
  53. }
  54. // 取得匹配项列表
  55. foreach (Match match in matches)
  56. {
  57. if (-1 == match.Groups["imgUrl"].Value.IndexOf("http"))
  58. {
  59. sb.Replace(match.Groups["imgUrl"].Value, strSiteUrl + match.Groups["imgUrl"].Value);
  60. sb.Replace(strSiteUrl + strSiteUrl + match.Groups["imgUrl"].Value, strSiteUrl + match.Groups["imgUrl"].Value);
  61. }
  62. }
  63. return sb.ToString();
  64. }
  65. [ExportExcel("随手拍公告")]
  66. public ISugarQueryable<SnapshotBulletinItemsOutDto> QueryBulletinItems(SnapshotBulletinItemsInDto dto)
  67. {
  68. var query = _bulletinRepository.Queryable()
  69. .Includes(x => x.ExaminMan)
  70. .WhereIF(!string.IsNullOrEmpty(dto.SnapshotBulletinTypeName), d => d.SnapshotBulletinTypeName.Contains(dto.SnapshotBulletinTypeName))
  71. .WhereIF(!string.IsNullOrEmpty(dto.Title), d => d.Title.Contains(dto.Title))
  72. .WhereIF(dto.BeginCreationTime.HasValue, d => d.BulletinTime >= dto.BeginCreationTime)
  73. .WhereIF(dto.EndCreationTime.HasValue, d => d.BulletinTime <= dto.EndCreationTime)
  74. .WhereIF(dto.State.HasValue, d => d.BulletinState == dto.State)
  75. .OrderByDescending(d => d.CreationTime)
  76. .Select<SnapshotBulletinItemsOutDto>();
  77. return query;
  78. }
  79. }