浏览代码

修复积分排行榜

qinchaoyue 1 天之前
父节点
当前提交
8bb3172c39

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

@@ -1016,6 +1016,14 @@ public abstract class SnapshotApplicationBase
             .LeftJoin<Notification>((receiver, notify) => notify.Id == receiver.NotificationId)
             .LeftJoin<SnapshotBulletin>((receiver, notify, bulletin) => bulletin.Id == notify.ExternalId)
             .Where((receiver, notify) => receiver.ReceiverId == _sessionContext.UserId)
+            .GroupBy((receiver, notify, bulletin) => new 
+            {
+                notify.Title,
+                notify.ExternalId,
+                bulletin.SnapshotBulletinTypeName,
+                bulletin.VideoCoverImgUrl,
+                notify.CreationTime
+            })
             .OrderByDescending((receiver, notify) => notify.CreationTime)
             .Select((receiver, notify, bulletin) => new VideoBulletinOutDto
             {
@@ -1026,15 +1034,21 @@ public abstract class SnapshotApplicationBase
                 VideoCoverImgUrl = bulletin.VideoCoverImgUrl,
             }).FirstAsync();
 
-        outDto.Bulletins = await _notificationReceiverRepository.Queryable()
-            .LeftJoin<Notification>((receiver, notify) => notify.Id == receiver.NotificationId)
-            .Select((receiver, notify) => new PointsBulletinOutDto 
-            {
-                BulletinId = notify.ExternalId,
-                Title = notify.Title,
-            }, true)
-            .Take(2)
-            .ToListAsync();
+        outDto.Bulletins = new PointsBulletinOutDto
+        {
+            Items = await _notificationReceiverRepository.Queryable()
+                .LeftJoin<Notification>((receiver, notify) => notify.Id == receiver.NotificationId)
+                .Select((receiver, notify) => new PointsBulletinItemsOutDto
+                {
+                    BulletinId = notify.ExternalId,
+                    Title = notify.Title,
+                }, true)
+                .Take(2)
+                .ToListAsync(),
+            UnReadCount = await _notificationReceiverRepository.Queryable()
+            .Where(m => m.IsRead == false && m.ReceiverId == _sessionContext.UserId)
+            .CountAsync()
+        };
 
         return outDto;
     }

+ 3 - 1
src/Hotline.Share/Dtos/Snapshot/NotifyDto.cs

@@ -40,7 +40,9 @@ public class AddNotifyInDto
 public class GetNotifyInDto : QueryFixedDto
 {
     /// <summary>
-    /// 消息类型
+    /// 消息类型:
+    /// 0: 通知公告
+    /// 1: 宣传视频
     /// </summary>
     public ENotificationType NotifyType { get; set; }
 }

+ 14 - 1
src/Hotline.Share/Dtos/Snapshot/PointsDto.cs

@@ -124,10 +124,23 @@ public class PointsRankOutDto
     /// <summary>
     /// 通知公告
     /// </summary>
-    public IList<PointsBulletinOutDto> Bulletins { get; set; }
+    public PointsBulletinOutDto Bulletins { get; set; }
 }
 
 public class PointsBulletinOutDto
+{
+    /// <summary>
+    /// 未读个数
+    /// </summary>
+    public int UnReadCount { get; set; }
+
+    /// <summary>
+    /// Summary
+    /// </summary>
+    public IList<PointsBulletinItemsOutDto> Items { get; set; }
+}
+
+public class PointsBulletinItemsOutDto
 {
     /// <summary>
     /// Id

+ 6 - 0
src/Hotline.Share/Enums/Snapshot/ENotificationType.cs

@@ -9,9 +9,15 @@ namespace Hotline.Share.Enums.Snapshot;
 
 public enum ENotificationType
 {
+    /// <summary>
+    /// 通知公告
+    /// </summary>
     [Description("消息")]
     Message = 0,
 
+    /// <summary>
+    /// 宣传视频
+    /// </summary>
     [Description("视频")]
     Video = 1
 }

+ 5 - 4
test/Hotline.Tests/Application/PointsRecordApplicationTest.cs

@@ -5,6 +5,7 @@ using Hotline.Identity.Roles;
 using Hotline.Orders;
 using Hotline.Settings;
 using Hotline.Share.Dtos.Snapshot;
+using Hotline.Share.Tools;
 using Hotline.Snapshot.IRepository;
 using Hotline.ThirdAccountDomainServices;
 using Hotline.ThirdAccountDomainServices.Interfaces;
@@ -80,11 +81,11 @@ public class PointsRecordApplicationTest : TestBase
     [Fact]
     public async Task GetPointsRank_Test()
     {
+        SetWeiXin();
         var item = await _snapshotApplication.GetPointsRankAsync();
         item.ShouldNotBeNull();
-        foreach (var a in item.Ranks)
-        {
-            var s = a.PhoneNumber;
-        }
+        item.Bulletins.Items.Any(m => m.Title.IsNullOrEmpty()).ShouldBeFalse();
+        item.Bulletins.Items.Any(m => m.BulletinId.IsNullOrEmpty()).ShouldBeFalse();
+        item.VideoBulletin.ShouldNotBeNull();
     }
 }

+ 2 - 2
test/Hotline.Tests/Application/SnapshotBulletionApplicationTest.cs

@@ -81,11 +81,11 @@ public class SnapshotBulletionApplicationTest : TestBase
             Reason = "审核通过"
         };
         await _snapshotBulletinApplication.ExamineBulletinAsync(examineDto, CancellationToken.None);
-        Thread.Sleep(5 * 1000);
+        Thread.Sleep(10 * 1000);
         //await _snapshotBulletinApplication.NotifyUserAsync(bulletinId, CancellationToken.None);
 
 
-        var notifyItems = await _snapshotApplication.GetNotificationAsync(new GetNotifyInDto(), CancellationToken.None);
+        var notifyItems = await _snapshotApplication.GetNotificationAsync(new GetNotifyInDto { NotifyType = Share.Enums.Snapshot.ENotificationType.Video}, CancellationToken.None);
         notifyItems.Any(m => m.Title == inDto.Title).ShouldBeTrue();
     }
 }