SnapshotBulletinApplication.cs 3.8 KB

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