Explorar o código

Merge branch 'feature/snapshot' into dev

qinchaoyue hai 4 meses
pai
achega
9fd267a823

+ 251 - 0
src/Hotline.Api/Controllers/Snapshot/SnapshotBulletinController.cs

@@ -0,0 +1,251 @@
+using Hotline.Share.Dtos;
+using Hotline.Share.Dtos.Article;
+using Hotline.Snapshot.Interfaces;
+using Microsoft.AspNetCore.Mvc;
+using Hotline.Repository.SqlSugar.Extensions;
+using Mapster;
+using Hotline.Application.Snapshot;
+using XF.Domain.Exceptions;
+using Hotline.Share.Enums.Article;
+using XF.Domain.Authentications;
+using Hotline.Caching.Interfaces;
+using Hotline.Settings;
+using Hotline.Article;
+using Hotline.Snapshot;
+
+namespace Hotline.Api.Controllers.Snapshot;
+
+public class SnapshotBulletinController : BaseController
+{
+    private readonly ISnapshotBulletinRepository _bulletinRepository;
+    private readonly ISnapshotBulletinApplication _bulletinApplication;
+    private readonly ISessionContext _sessionContext;
+    private readonly ISystemDicDataCacheManager _systemDicDataCacheManager;
+    private readonly ISystemOrganizeRepository _organizeRepository;
+
+    public SnapshotBulletinController(ISnapshotBulletinRepository bulletinRepository, ISessionContext sessionContext, ISystemDicDataCacheManager systemDicDataCacheManager, ISystemOrganizeRepository organizeRepository)
+    {
+        _bulletinRepository = bulletinRepository;
+        _sessionContext = sessionContext;
+        _systemDicDataCacheManager = systemDicDataCacheManager;
+        _organizeRepository = organizeRepository;
+    }
+
+    #region 公告
+
+    /// <summary>
+    /// 查询公告列表
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+    [HttpGet("bulletin/query")]
+    public async Task<PagedDto<BulletinDto>> QueryBulletinList([FromQuery] QueryBulletinListRequestDto dto)
+    {
+        var (total, items) = await _bulletinRepository.Queryable()
+            .Includes(x => x.ExaminMan)
+            .WhereIF(!string.IsNullOrEmpty(dto.BulletinTypeId), d => d.SnapshotBulletinTypeId == dto.BulletinTypeId)
+            .WhereIF(!string.IsNullOrEmpty(dto.Title), d => d.Title.Contains(dto.Title))
+            .WhereIF(dto.BulletinTimeStart.HasValue, d => d.BulletinTime >= dto.BulletinTimeStart)
+            .WhereIF(dto.BulletinTimeEnd.HasValue, d => d.BulletinTime <= dto.BulletinTimeEnd)
+            .WhereIF(dto.BulletinState != null, d => d.BulletinState == dto.BulletinState)
+            .OrderByDescending(d => d.CreationTime)
+            .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
+
+        return new PagedDto<BulletinDto>(total, items.Adapt<IReadOnlyList<BulletinDto>>());
+    }
+
+    /// <summary>
+    /// 公告详情(内部)
+    /// </summary>
+    /// <param name="id"></param>
+    /// <returns></returns>
+    [HttpGet("bulletin/entity/{id}")]
+    public async Task<BulletinDto> BulletinEntity(string id)
+    {
+        var model = await _bulletinRepository.Queryable()
+            .Includes(x => x.ExaminMan)
+            .FirstAsync(x => x.Id == id, HttpContext.RequestAborted);
+
+        if (model != null && !string.IsNullOrEmpty(model.Content))
+            model.Content = _bulletinApplication.GetSiteUrls(model.Content);
+
+        return model.Adapt<BulletinDto>();
+    }
+
+    /// <summary>
+    /// 公告审核
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+    [HttpPost("bulletin/examine")]
+    public async Task ExamineBulletin([FromBody] ExamineBulletinDto dto)
+    {
+        var bulletin = await _bulletinRepository.GetAsync(dto.Id, HttpContext.RequestAborted);
+        if (bulletin == null)
+            throw UserFriendlyException.SameMessage("无效数据");
+
+        if (bulletin.BulletinState != EBulletinState.InReview)
+            throw UserFriendlyException.SameMessage("当前状态不能审核");
+
+        if (dto.IsPass)
+        {
+            bulletin.BulletinState = Share.Enums.Article.EBulletinState.ReviewPass;
+            bulletin.BulletinTime = DateTime.Now;
+            bulletin.ExaminOpinion = dto.Reason;
+            bulletin.ExaminTime = DateTime.Now;
+            bulletin.ExaminManId = _sessionContext.RequiredUserId;
+            await _bulletinRepository.UpdateAsync(bulletin, HttpContext.RequestAborted);
+            var publishBulletin = bulletin.Adapt<PublishBulletinDto>();
+
+            //await _capPublisher.PublishAsync(Hotline.Share.Mq.EventNames.HotlinePushBulletin, publishBulletin, cancellationToken: HttpContext.RequestAborted);
+
+            //todo await _bulletinService.PushBulletin(publishBulletin, HttpContext.RequestAborted);
+        }
+        else
+        {
+            bulletin.ExaminOpinion = dto.Reason;
+            bulletin.ExaminTime = DateTime.Now;
+            bulletin.ExaminManId = _sessionContext.RequiredUserId;
+            bulletin.BulletinState = Share.Enums.Article.EBulletinState.ReviewNoPass;
+            await _bulletinRepository.UpdateAsync(bulletin, HttpContext.RequestAborted);
+        }
+    }
+
+    /// <summary>
+    /// 提交公告
+    /// </summary>
+    /// <param name="id"></param>
+    /// <returns></returns>
+    [HttpGet("bulletin/commit")]
+    public async Task CommitBulletin(string id)
+    {
+        var bulletin = await _bulletinRepository.GetAsync(id, HttpContext.RequestAborted);
+        if (bulletin == null)
+            throw UserFriendlyException.SameMessage("无效数据");
+
+        if (bulletin.BulletinState != EBulletinState.Draft && bulletin.BulletinState != EBulletinState.ReviewNoPass)
+            throw UserFriendlyException.SameMessage("当前状态不能提交");
+
+        bulletin.BulletinState = EBulletinState.InReview;
+        bulletin.CommitTime = DateTime.Now;
+        await _bulletinRepository.UpdateAsync(bulletin, HttpContext.RequestAborted);
+    }
+
+    /// <summary>
+    /// 修改公告
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+    [HttpPost("bulletin/update")]
+    public async Task UpdateBulletin([FromBody] UpdateBulletinDto dto)
+    {
+        var bulletin = await _bulletinRepository.GetAsync(dto.Id, HttpContext.RequestAborted);
+        if (bulletin == null)
+            throw UserFriendlyException.SameMessage("无效数据");
+
+        if (bulletin.BulletinState != EBulletinState.Draft && bulletin.BulletinState != EBulletinState.ReviewNoPass)
+            throw UserFriendlyException.SameMessage("当前状态不能修改");
+
+        bulletin.Title = dto.Title;
+        bulletin.Content = dto.Content;
+        bulletin.SnapshotBulletinTypeId = dto.BulletinTypeId;
+        bulletin.SnapshotBulletinTypeName = dto.BulletinTypeName;
+        await _bulletinRepository.UpdateAsync(bulletin, HttpContext.RequestAborted);
+    }
+
+    /// <summary>
+    /// 删除公告
+    /// </summary>
+    /// <param name="id"></param>
+    /// <returns></returns>
+    [HttpGet("bulletin/del/{id}")]
+    public async Task DelBulletin(string id)
+    {
+        var bulletin = await _bulletinRepository.GetAsync(id, HttpContext.RequestAborted);
+        if (bulletin == null)
+            throw UserFriendlyException.SameMessage("无效数据");
+
+        if (bulletin.BulletinState != EBulletinState.Draft)
+            throw UserFriendlyException.SameMessage("当前状态不能删除");
+
+        await _bulletinRepository.RemoveAsync(x => x.Id == id, false, HttpContext.RequestAborted);
+    }
+
+
+    /// <summary>
+    /// 新增公告
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+    [HttpPost("bulletin/add")]
+    public async Task AddBulletin([FromBody] AddBulletinDto dto)
+    {
+        var model = dto.Adapt<SnapshotBulletin>();
+        model.BulletinState = Share.Enums.Article.EBulletinState.Draft;
+        model.ReadedNum = 0;
+        model.IsArrive = false;
+        await _bulletinRepository.AddAsync(model, HttpContext.RequestAborted);
+    }
+
+    /// <summary>
+    /// 公告上架或者下架
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+    [HttpPost("bulletin-arrive")]
+    public async Task BulletinArrive([FromBody] BulletinArriveDto dto)
+    {
+        var bulletin = await _bulletinRepository.GetAsync(dto.Id, HttpContext.RequestAborted);
+        if (bulletin == null)
+            throw UserFriendlyException.SameMessage("无效数据");
+
+        if (bulletin.BulletinState != EBulletinState.ReviewPass)
+            throw UserFriendlyException.SameMessage("当前状态不能操作上架或下架");
+
+        bulletin.IsArrive = dto.IsArrive;
+        if (bulletin.IsArrive == false)
+        {
+            bulletin.ExaminTime = null;
+            bulletin.ExaminManId = null;
+            bulletin.ExaminOpinion = null;
+            bulletin.CommitTime = null;
+            bulletin.BulletinState = EBulletinState.Draft;
+        }
+        await _bulletinRepository.UpdateAsync(bulletin, HttpContext.RequestAborted);
+    }
+
+    /// <summary>
+    /// 列表页面基础数据
+    /// </summary>
+    /// <returns></returns>
+    [HttpGet("bulletin/listbasedata")]
+    public async Task<object> BulletinListBaseData()
+    {
+        var rsp = new
+        {
+            BulletinType = _systemDicDataCacheManager.GetSysDicDataCache(SysDicTypeConsts.BulletinType)
+        };
+        return rsp;
+    }
+
+
+    /// <summary>
+    /// 新增页面基础数据
+    /// </summary>
+    /// <returns></returns>
+    [HttpGet("bulletin/addbasedata")]
+    public async Task<object> BulletinAddBaseData()
+    {
+        var rsp = new
+        {
+            BulletinType = _systemDicDataCacheManager.GetSysDicDataCache(SysDicTypeConsts.BulletinType),
+            BulletinDisplayLocation = _systemDicDataCacheManager.GetSysDicDataCache(SysDicTypeConsts.BulletinDisplayLocation),
+            PushRanges = _systemDicDataCacheManager.GetSysDicDataCache(SysDicTypeConsts.BulletinPushRange),
+            OrgsOptions = await _organizeRepository.GetOrgJson(),
+        };
+        return rsp;
+    }
+
+
+    #endregion
+}

+ 17 - 0
src/Hotline.Application/Snapshot/ISnapshotBulletinApplication.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Hotline.Application.Snapshot;
+public interface ISnapshotBulletinApplication
+{
+
+    /// <summary>
+    /// 处理通知公告图片附件路径
+    /// </summary>
+    /// <param name="sHtmlText"></param>
+    /// <returns></returns>
+    string GetSiteUrls(string sHtmlText);
+}

+ 2 - 1
src/Hotline.Application/Snapshot/Notifications/SnapshotHandler.cs

@@ -55,6 +55,7 @@ public class SnapshotHandler : ICapSubscribe, IScopeDependency
 /// <summary>
 /// 网格员办结事件处理
 /// 把网格员信息回填到系统中, 和小程序账号绑定
+/// 同步社区信息
 /// </summary>
 public class GuiderSystemFieldNotificationHandler : INotificationHandler<GuiderSystemFieldNotification>
 {
@@ -67,7 +68,7 @@ public class GuiderSystemFieldNotificationHandler : INotificationHandler<GuiderS
 
     public async Task Handle(GuiderSystemFieldNotification notification, CancellationToken cancellationToken)
     {
-        await _snapshotApplication.SyncGuiderInfoAsync(notification.OrderId, cancellationToken);
+        await _snapshotApplication.SyncGuiderInfoAsync(notification.OrderSnapshot.Id, cancellationToken);
         await _snapshotApplication.SyncCommunityInfoAsync(notification.CommunityInfo, cancellationToken);
     }
 }

+ 1 - 1
src/Hotline.Application/Snapshot/SnapshotApplicationBase.cs

@@ -603,7 +603,7 @@ public abstract class SnapshotApplicationBase
         // 网格员办结
         if (orderSnapshot.ReplyResultType == EGuiderSystemReplyType.Field)
         {
-            await _publisher.PublishAsync(new GuiderSystemFieldNotification(orderSnapshot.Id, dto.Adapt<CommunityInfo>()), token);
+            await _publisher.PublishAsync(new GuiderSystemFieldNotification(orderSnapshot, dto.Adapt<CommunityInfo>()), token);
         }
         // 网格员超时未回复退回
         if (orderSnapshot.ReplyResultType == EGuiderSystemReplyType.Returned)

+ 67 - 0
src/Hotline.Application/Snapshot/SnapshotBulletinApplication.cs

@@ -0,0 +1,67 @@
+using Hotline.Caching.Interfaces;
+using Hotline.Settings;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+
+namespace Hotline.Application.Snapshot;
+public class SnapshotBulletinApplication : ISnapshotBulletinApplication
+{
+
+    private readonly ISystemSettingCacheManager _systemSettingCacheManager;
+
+    public SnapshotBulletinApplication(ISystemSettingCacheManager systemSettingCacheManager)
+    {
+        _systemSettingCacheManager = systemSettingCacheManager;
+    }
+
+    /// <summary>
+    /// 处理通知公告图片附件路径
+    /// </summary>
+    /// <param name="sHtmlText"></param>
+    /// <returns></returns>
+    public string GetSiteUrls(string sHtmlText)
+    {
+        sHtmlText = sHtmlText.Replace("&lt;", "<").Replace("&gt;", ">");
+
+        //临时内容
+        System.Text.StringBuilder sb = new StringBuilder();
+        sb.Append(sHtmlText);
+        // 定义正则表达式用来匹配 img 标签
+        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);
+        // 搜索匹配的字符串
+        MatchCollection matches = regImg.Matches(sHtmlText);
+
+        // 定义正则表达式用来匹配 video 标签
+        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);
+        // 搜索匹配的字符串
+        MatchCollection matchesvideo = regvideo.Matches(sHtmlText);
+
+        var strSiteUrl = _systemSettingCacheManager.GetSetting(SettingConstants.OldFilesUrls)?.SettingValue[0];
+
+        // 取得匹配项列表 视频
+        foreach (Match match in matchesvideo)
+        {
+            if (-1 == match.Groups["imgUrl"].Value.IndexOf("http"))
+            {
+                sb.Replace(match.Groups["imgUrl"].Value, strSiteUrl + match.Groups["imgUrl"].Value);
+                sb.Replace(strSiteUrl + strSiteUrl + match.Groups["imgUrl"].Value, strSiteUrl + match.Groups["imgUrl"].Value);
+            }
+        }
+
+        // 取得匹配项列表
+        foreach (Match match in matches)
+        {
+            if (-1 == match.Groups["imgUrl"].Value.IndexOf("http"))
+            {
+                sb.Replace(match.Groups["imgUrl"].Value, strSiteUrl + match.Groups["imgUrl"].Value);
+                sb.Replace(strSiteUrl + strSiteUrl + match.Groups["imgUrl"].Value, strSiteUrl + match.Groups["imgUrl"].Value);
+            }
+        }
+
+        return sb.ToString();
+    }
+}

+ 1 - 1
src/Hotline/Snapshot/Notifications/PostGuiderSystemNotification.cs

@@ -35,4 +35,4 @@ public record GuiderSystemTimeOutBackNotification(string OrderId) : INotificatio
 /// 网格员系统办结
 /// </summary>
 /// <param name="OrderId"></param>
-public record GuiderSystemFieldNotification(string OrderId, CommunityInfo CommunityInfo) : INotification;
+public record GuiderSystemFieldNotification(OrderSnapshot OrderSnapshot, CommunityInfo CommunityInfo) : INotification;