Эх сурвалжийг харах

修复随手拍通知, 审核自动上架. 下架后不在微信用户通知中显示,修复通知按最新发布时间排序.

qinchaoyue 4 өдөр өмнө
parent
commit
eb03b808de

+ 9 - 4
src/Hotline.Application/Snapshot/SnapshotApplicationBase.cs

@@ -401,12 +401,17 @@ public abstract class SnapshotApplicationBase
     public async Task<IList<GetNotifyOutDto>> GetNotificationAsync(GetNotifyInDto dto, CancellationToken requestAborted)
     {
         var items = await _notificationReceiverRepository.Queryable()
-            .LeftJoin<Notification>((m , notify) => m.NotificationId == notify.Id)
-            .Where((m, notify) => m.ReceiverId == _sessionContext.UserId && dto.NotifyType == notify.NotifyType)
-            .Select((m, notify) => new GetNotifyOutDto 
+            .LeftJoin<Notification>((m, notify) => m.NotificationId == notify.Id)
+            .LeftJoin<SnapshotBulletin>((m, notify, bulletin) => bulletin.Id == notify.ExternalId)
+            .Where((m, notify, bulletin) => m.ReceiverId == _sessionContext.UserId
+            && dto.NotifyType == notify.NotifyType
+            && bulletin.Id != null
+            && bulletin.IsArrive == true)
+            .OrderByDescending((m, notify, bulletin) => m.CreationTime)
+            .Select((m, notify, bulletin) => new GetNotifyOutDto
             {
                 NotificationId = m.NotificationId,
-                Title = notify.Title ,
+                Title = notify.Title,
                 CreationTime = m.CreationTime,
                 IsRead = m.IsRead
             }, true)

+ 42 - 19
src/Hotline.Application/Snapshot/SnapshotBulletinApplication.cs

@@ -2,6 +2,7 @@
 using Hotline.Application.Snapshot.Contracts;
 using Hotline.Caching.Interfaces;
 using Hotline.Orders;
+using Hotline.Repository.SqlSugar.Orders;
 using Hotline.Settings;
 using Hotline.Share.Attributes;
 using Hotline.Share.Dtos.Article;
@@ -12,7 +13,9 @@ using Hotline.Share.Tools;
 using Hotline.Snapshot;
 using Hotline.Snapshot.Contracts;
 using Hotline.Snapshot.IRepository;
+using Hotline.ThirdAccountDomainServices;
 using Mapster;
+using Microsoft.Extensions.Logging;
 using SqlSugar;
 using System.Text;
 using System.Text.RegularExpressions;
@@ -30,8 +33,10 @@ public class SnapshotBulletinApplication : ISnapshotBulletinApplication, IScopeD
     private readonly ISessionContext _sessionContext;
     private readonly ISafetyTypeRepository _safetyTypeRepository;
     private readonly ICapPublisher _capPublisher;
+    private readonly ICitizenRepository _citizenRepository;
+    private readonly ILogger<SnapshotBulletinApplication> _logger;
 
-    public SnapshotBulletinApplication(ISystemSettingCacheManager systemSettingCacheManager, ISnapshotBulletinRepository bulletinRepository, INotificationDomainService notificationDomainService, ISessionContext sessionContext, ISafetyTypeRepository safetyTypeRepository, ICapPublisher capPublisher)
+    public SnapshotBulletinApplication(ISystemSettingCacheManager systemSettingCacheManager, ISnapshotBulletinRepository bulletinRepository, INotificationDomainService notificationDomainService, ISessionContext sessionContext, ISafetyTypeRepository safetyTypeRepository, ICapPublisher capPublisher, ICitizenRepository citizenRepository, ILogger<SnapshotBulletinApplication> logger)
     {
         _systemSettingCacheManager = systemSettingCacheManager;
         _bulletinRepository = bulletinRepository;
@@ -39,6 +44,8 @@ public class SnapshotBulletinApplication : ISnapshotBulletinApplication, IScopeD
         _sessionContext = sessionContext;
         _safetyTypeRepository = safetyTypeRepository;
         _capPublisher = capPublisher;
+        _citizenRepository = citizenRepository;
+        _logger = logger;
     }
 
     public async Task ExamineBulletinAsync(ExamineBulletinDto dto, CancellationToken token)
@@ -83,27 +90,43 @@ public class SnapshotBulletinApplication : ISnapshotBulletinApplication, IScopeD
                 if (bulletion!.SafetyTypeId!.IsNullOrEmpty()) return;
                 foreach (var safetyTypeId in bulletion!.SafetyTypeId!)
                 {
-                    await _safetyTypeRepository.Queryable()
-                        .LeftJoin<CitizenRelationSafetyType>((safety, relation) => safety.Id == relation.SafetyTypeId)
-                        .LeftJoin<Citizen>((safety, relation, citizen) => relation.CitizenId == citizen.Id)
-                        .Where((safety, relation, citizen) => safety.Id == safetyTypeId)
-                        .Select((safety, relation, citizen) => relation.CitizenId)
-                        .ToListAsync(token)
-                        .Then(async citizenIds =>
-                        {
-                            var inDto = bulletion.Adapt<AddNotifyInDto>();
-                            inDto.UserIds = citizenIds;
-                            if (bulletion.Shape != null && bulletion.Shape == EBulletinShape.Video)
-                            {
-                                inDto.NotifyType = ENotificationType.Video;
-                            }
-                            inDto.ExternalId = bulletion.Id;
-                            await _notificationDomainService.AddNotifyAsync(inDto, token);
-                        });
+                    var safetyType = await _safetyTypeRepository.GetAsync(safetyTypeId, token);
+                    if (safetyType == null)
+                    {
+                        _logger.LogError($"安全员分类不存在: {safetyTypeId}");
+                        continue;
+                    }
+                    var citizenIds = new List<string>();
+                    if (safetyType.Flags == ESafeTypeFlags.All)
+                    {
+                        citizenIds = await _citizenRepository.Queryable()
+                            .LeftJoin<ThirdAccount>((citizen, third) => citizen.Id == third.ExternalId)
+                            .Where((citizen, third) => third.Id != null)
+                            .Select((citizen, third) => citizen.Id)
+                            .ToListAsync(token);
+                    }
+                    else
+                    {
+                        citizenIds = await _safetyTypeRepository.Queryable()
+                            .LeftJoin<CitizenRelationSafetyType>((safety, relation) => safety.Id == relation.SafetyTypeId)
+                            .LeftJoin<Citizen>((safety, relation, citizen) => relation.CitizenId == citizen.Id)
+                            .Where((safety, relation, citizen) => safety.Id == safetyTypeId)
+                            .Select((safety, relation, citizen) => relation.CitizenId)
+                            .ToListAsync(token);
+                    }
+                    if (citizenIds.IsNullOrEmpty()) continue;
+
+                    var inDto = bulletion.Adapt<AddNotifyInDto>();
+                    inDto.UserIds = citizenIds;
+                    if (bulletion.Shape != null && bulletion.Shape == EBulletinShape.Video)
+                    {
+                        inDto.NotifyType = ENotificationType.Video;
+                    }
+                    inDto.ExternalId = bulletion.Id;
+                    await _notificationDomainService.AddNotifyAsync(inDto, token);
                 }
             });
     }
-
     /// <summary>
     /// 处理通知公告图片附件路径
     /// </summary>

+ 29 - 0
src/Hotline.Share/Enums/Snapshot/ESnapshotFlags.cs

@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Hotline.Share.Enums.Snapshot;
+
+[Flags]
+public enum ESnapshotFlags
+{
+    None = 0,
+
+    /// <summary>
+    /// 工单是否自动标注
+    /// </summary>
+    [Description("工单是否自动标注")]
+    AutoMarked = 1 << 0,
+}
+
+[Flags]
+public enum ESafeTypeFlags
+{
+    None = 0,
+
+    [Description("给所有用户发送通知")]
+    All = 1 << 0,
+}

+ 7 - 0
src/Hotline/Snapshot/SafetyType.cs

@@ -1,5 +1,6 @@
 using Hotline.Identity.Accounts;
 using Hotline.Orders;
+using Hotline.Share.Enums.Snapshot;
 using SqlSugar;
 using System.ComponentModel;
 using XF.Domain.Repository;
@@ -20,4 +21,10 @@ public class SafetyType : CreationSoftDeleteEntity
 
     [Navigate(typeof(CitizenRelationSafetyType), nameof(CitizenRelationSafetyType.SafetyTypeId), nameof(CitizenRelationSafetyType.CitizenId))]
     public List<Citizen> Citizens { get; set; }
+
+    /// <summary>
+    /// 是否给所有人发送通知|
+    /// </summary>
+    [SugarColumn(ColumnDescription = "是否给所有人发送通知|", ColumnDataType = "int", DefaultValue = "0")]
+    public ESafeTypeFlags Flags { get; set; }
 }