Forráskód Böngészése

完成随手拍积分统计

qinchaoyue 3 napja
szülő
commit
890bce81d3

+ 9 - 0
src/Hotline.Api/Controllers/Snapshot/BiSnapshotController.cs

@@ -327,4 +327,13 @@ public class BiSnapshotController : BaseController
     [HttpGet("re_transact-statistics-detail")]
     public async Task<PagedDto<ReTransactStatisticsDetailsOutDto>> GetReTransactStatisticsDetailAsync([FromQuery] ReTransactStatisticsDetailsInDto dto)
         => (await _biSnapshotApplication.GetReTransactStatisticsDetail(dto).ToPagedListAsync(dto)).ToPaged();
+
+    /// <summary>
+    /// 随手拍区域积分统计
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+    [HttpGet("county_points")]
+    public async Task<IList<SnapshotCountyPointsStatisticsOutDto>> Get([FromQuery] SnapshotCountyPointsStatisticsInDto dto)
+        => await _biSnapshotApplication.GetAreaPointsStatistics(dto).ToListAsync(HttpContext.RequestAborted);
 }

+ 24 - 2
src/Hotline.Application/Snapshot/BiSnapshotApplication.cs

@@ -5,6 +5,7 @@ using Hotline.Settings;
 using Hotline.Settings.Hotspots;
 using Hotline.Share.Attributes;
 using Hotline.Share.Dtos.Snapshot;
+using Hotline.Share.Enums.CallCenter;
 using Hotline.Share.Enums.FlowEngine;
 using Hotline.Share.Enums.Order;
 using Hotline.Share.Enums.Snapshot;
@@ -36,8 +37,9 @@ public class BiSnapshotApplication : IBiSnapshotApplication, IScopeDependency
     private readonly ICommunityInfoRepository _communityInfoRepository;
     private readonly IRepository<SystemArea> _systemAreaRepository;
     private readonly IOptionsSnapshot<AppConfiguration> _appOptions;
+    private readonly ISnapshotPointsRecordRepository _snapshotPointsRecordRepository;
 
-    public BiSnapshotApplication(IOrderSnapshotRepository orderSnapshotRepository, IRedPackRecordRepository redPackRecordRepository, IIndustryRepository industryRepository, IIndustryCaseRepository industryCaseRepository, IRedPackAuditRepository redPackAuditRepository, IRepository<Hotspot> hotspotTypeRepository, ISessionContext sessionContext, IOrderRepository orderRepository, ICommunityInfoRepository communityInfoRepository, IRepository<SystemArea> systemAreaRepository, IOptionsSnapshot<AppConfiguration> appOptions)
+    public BiSnapshotApplication(IOrderSnapshotRepository orderSnapshotRepository, IRedPackRecordRepository redPackRecordRepository, IIndustryRepository industryRepository, IIndustryCaseRepository industryCaseRepository, IRedPackAuditRepository redPackAuditRepository, IRepository<Hotspot> hotspotTypeRepository, ISessionContext sessionContext, IOrderRepository orderRepository, ICommunityInfoRepository communityInfoRepository, IRepository<SystemArea> systemAreaRepository, IOptionsSnapshot<AppConfiguration> appOptions, ISnapshotPointsRecordRepository snapshotPointsRecordRepository)
     {
         _orderSnapshotRepository = orderSnapshotRepository;
         _redPackRecordRepository = redPackRecordRepository;
@@ -50,6 +52,7 @@ public class BiSnapshotApplication : IBiSnapshotApplication, IScopeDependency
         _communityInfoRepository = communityInfoRepository;
         _systemAreaRepository = systemAreaRepository;
         _appOptions = appOptions;
+        _snapshotPointsRecordRepository = snapshotPointsRecordRepository;
     }
 
     public ISugarQueryable<HotspotStatisticsOutDto> GetHotspotStatistics(HotspotStatisticsInDto dto)
@@ -734,7 +737,7 @@ public class BiSnapshotApplication : IBiSnapshotApplication, IScopeDependency
             .LeftJoin<OrderSendBackAudit>((snapshot, order, back) => snapshot.Id == back.OrderId && back.State == ESendBackAuditState.End)
             .LeftJoin<OrderVisit>((snapshot, order, back, visit) => snapshot.Id == visit.OrderId && visit.VisitState == EVisitState.Visited)
             .LeftJoin<OrderSecondaryHandling>((snapshot, order, back, visit, second) => snapshot.Id == second.OrderId && second.State == ESecondaryHandlingState.End)
-            .Where((snapshot, order) => snapshot.CreationTime >= dto.StartTime && snapshot.CreationTime <= dto.EndTime 
+            .Where((snapshot, order) => snapshot.CreationTime >= dto.StartTime && snapshot.CreationTime <= dto.EndTime
             && order.ActualHandleOrgCode != null && order.ActualHandleOrgCode != "001")
             .GroupBy((snapshot, order) => new
             {
@@ -972,4 +975,23 @@ public class BiSnapshotApplication : IBiSnapshotApplication, IScopeDependency
             .Select((snapshot, order) => new IndustryStatisticsDetailsOutDto(), true);
         return query;
     }
+
+    public ISugarQueryable<SnapshotCountyPointsStatisticsOutDto> GetAreaPointsStatistics(SnapshotCountyPointsStatisticsInDto dto)
+    {
+        var query = _snapshotPointsRecordRepository.Queryable(includeDeleted: true)
+            .LeftJoin<Order>((points, order) => points.OrderId == order.Id)
+            .Where((points, order) => order.CreationTime >= dto.StartTime && order.CreationTime <= dto.EndTime && order.County != "" && order.County != null)
+            .GroupBy((points, order) => order.County)
+            .Select((points, order) => new SnapshotCountyPointsStatisticsOutDto
+            {
+                CountyName = order.County,
+                Points = SqlFunc.AggregateSum(SqlFunc.IIF(points.Direction == EPointsDirection.In, points.Points, 0)),
+                ExchangePoints = SqlFunc.AggregateSum(SqlFunc.IIF(points.Source == EPointsSource.Exchange, points.Points, 0)),
+            });
+#if DEBUG
+        var sql = query.ToSqlString();
+#endif
+        return query;
+    }
+
 }

+ 7 - 0
src/Hotline.Application/Snapshot/Contracts/IBiSnapshotApplication.cs

@@ -111,4 +111,11 @@ public interface IBiSnapshotApplication
     /// <param name="dto"></param>
     /// <returns></returns>
     ISugarQueryable<IndustryStatisticsDetailsOutDto> GetIndustryStatisticsDetails(IndustryStatisticsDetailsInDto dto);
+
+    /// <summary>
+    /// 区域积分统计
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+    ISugarQueryable<SnapshotCountyPointsStatisticsOutDto> GetAreaPointsStatistics(SnapshotCountyPointsStatisticsInDto dto);
 }

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

@@ -8,6 +8,7 @@ using Hotline.Share.Attributes;
 using Hotline.Share.Dtos.Article;
 using Hotline.Share.Dtos.Snapshot;
 using Hotline.Share.Enums.Article;
+using Hotline.Share.Enums.Snapshot;
 using Hotline.Share.Tools;
 using Hotline.Snapshot;
 using Hotline.Snapshot.Contracts;
@@ -102,6 +103,10 @@ public class SnapshotBulletinApplication : ISnapshotBulletinApplication, IScopeD
                     {
                         var inDto = bulletion.Adapt<AddNotifyInDto>();
                         inDto.UserIds = citizenIds;
+                        if (bulletion.VideoPath.NotNullOrEmpty())
+                        {
+                            inDto.NotifyType = ENotificationType.Video;
+                        }
                         await _notificationDomainService.AddNotifyAsync(inDto, token);
                     });
             });

+ 3 - 0
src/Hotline.Application/Snapshot/SnapshotPointsApplication.cs

@@ -30,7 +30,10 @@ public class SnapshotPointsApplication : ISnapshotPointsApplication, IScopeDepen
     {
         var query = _snapshotPointsRecordRepository.Queryable()
             .LeftJoin<Citizen>((points, citizen) => points.UserId == citizen.Id)
+            .LeftJoin<Order>((points, citizen, order) => order.Id == points.OrderId)
             .WhereIF(dto.PhoneNumber.NotNullOrEmpty(), (points, citizen) => citizen.PhoneNumber.Contains(dto.PhoneNumber!))
+            .WhereIF(dto.County.NotNullOrEmpty(), (points, citizen, order) => order.County == dto.County)
+            .WhereIF(dto.StartTime != null && dto.EndTime != null, (points, citizen) => points.CreationTime >= dto.StartTime && points.CreationTime <= dto.EndTime)
             .Where((points, citizen) => points.CreationTime >= dto.StartTime && points.CreationTime <= dto.EndTime)
             .GroupBy((points, citizen) => new { points.UserId, citizen.IsSecurityMax, citizen.Name, citizen.PhoneNumber })
             .Select((points, citizen) => new PointsItemsOutDto

+ 9 - 0
src/Hotline.Share/Dtos/Snapshot/PointsDto.cs

@@ -38,6 +38,15 @@ public record PointsItemsInDto : PagedKeywordRequest
     /// 联系方式
     /// </summary>
     public string? PhoneNumber { get; set; }
+
+    /// <summary>
+    /// 区域名称
+    /// </summary>
+    public string? County { get; set; }
+
+    public DateTime? StartTime { get; set; }
+
+    public DateTime? EndTime { get; set; }
 }
 
 public class PointsItemsOutDto

+ 28 - 0
src/Hotline.Share/Dtos/Snapshot/StatisticsDto.cs

@@ -3113,3 +3113,31 @@ public class IndustryStatisticsDetailsOutDto
     public string FileOpinion { get; set; }
 
 }
+
+public class SnapshotCountyPointsStatisticsInDto
+{
+    [Required]
+    public DateTime StartTime { get; set; }
+
+    [Required]
+    public DateTime EndTime { get; set; }
+
+}
+
+public class SnapshotCountyPointsStatisticsOutDto
+{
+    /// <summary>
+    /// 区域名称
+    /// </summary>
+    public string CountyName { get; set; }
+
+    /// <summary>
+    /// 积分
+    /// </summary>
+    public long Points { get; set; }
+
+    /// <summary>
+    /// 兑换积分
+    /// </summary>
+    public long ExchangePoints { get; set; }
+}

+ 9 - 0
test/Hotline.Tests/Application/BiSnapshotApplicationTest.cs

@@ -13,6 +13,7 @@ using Mapster;
 using Microsoft.AspNetCore.Http;
 using Microsoft.Extensions.DependencyInjection;
 using Shouldly;
+using SqlSugar;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -110,6 +111,14 @@ public class BiSnapshotApplicationTest : TestBase
 
         var e = _biSnapshotApplication.GetIndustryStatistics(inDto.Adapt<IndustryStatisticsInDto>());
         e.ShouldNotBeNull();
+
+        var areaPointsInDto = new SnapshotCountyPointsStatisticsInDto
+        {
+            StartTime = DateTime.Now.AddDays(-30),
+            EndTime = DateTime.Now,
+        };
+        var areaPointsOutDto = _biSnapshotApplication.GetAreaPointsStatistics(areaPointsInDto).ToList();
+        areaPointsOutDto.ShouldNotBeNull();
     }
 
     [Fact]

+ 10 - 1
test/Hotline.Tests/Application/SnapshotBulletionApplicationTest.cs

@@ -34,8 +34,9 @@ public class SnapshotBulletionApplicationTest : TestBase
     private readonly ISnapshotUserApplication _snapshotUserApplication;
     private readonly ISessionContext _sessionContext;
     private readonly ISnapshotApplication _snapshotApplication;
+    private readonly ISnapshotBulletinRepository _bulletinRepository;
 
-    public SnapshotBulletionApplicationTest(IAccountRepository accountRepository, IRepository<Role> roleRepository, UserController userController, IServiceScopeFactory scopeFactory, IRepository<User> userRepository, IHttpContextAccessor httpContextAccessor, IThirdIdentiyService thirdIdentiyService, IThirdAccountRepository thirdAccountRepository, ITypedCache<SystemSetting> cacheSettingData, ThirdAccounSupplierFactory thirdAccountDomainFactory, IServiceProvider serviceProvider, ISnapshotBulletinApplication snapshotBulletinApplication, ISystemDicDataCacheManager systemDicDataCacheManager, ISafetyTypeRepository safetyTypeRepository, ISnapshotUserApplication snapshotUserApplication, ISessionContext sessionContext, ISnapshotApplication snapshotApplication) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdIdentiyService, thirdAccountRepository, cacheSettingData, thirdAccountDomainFactory, serviceProvider)
+    public SnapshotBulletionApplicationTest(IAccountRepository accountRepository, IRepository<Role> roleRepository, UserController userController, IServiceScopeFactory scopeFactory, IRepository<User> userRepository, IHttpContextAccessor httpContextAccessor, IThirdIdentiyService thirdIdentiyService, IThirdAccountRepository thirdAccountRepository, ITypedCache<SystemSetting> cacheSettingData, ThirdAccounSupplierFactory thirdAccountDomainFactory, IServiceProvider serviceProvider, ISnapshotBulletinApplication snapshotBulletinApplication, ISystemDicDataCacheManager systemDicDataCacheManager, ISafetyTypeRepository safetyTypeRepository, ISnapshotUserApplication snapshotUserApplication, ISessionContext sessionContext, ISnapshotApplication snapshotApplication, ISnapshotBulletinRepository bulletinRepository) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdIdentiyService, thirdAccountRepository, cacheSettingData, thirdAccountDomainFactory, serviceProvider)
     {
         _snapshotBulletinApplication = snapshotBulletinApplication;
         _systemDicDataCacheManager = systemDicDataCacheManager;
@@ -43,6 +44,7 @@ public class SnapshotBulletionApplicationTest : TestBase
         _snapshotUserApplication = snapshotUserApplication;
         _sessionContext = sessionContext;
         _snapshotApplication = snapshotApplication;
+        _bulletinRepository = bulletinRepository;
     }
 
     [Fact]
@@ -62,8 +64,15 @@ public class SnapshotBulletionApplicationTest : TestBase
             BulletinTypeId = bulletinType.DicDataValue,
             BulletinTypeName = bulletinType.DicDataName,
             SafetyTypeId = safetyType.Id,
+            VideoCoverImgUrl = "222222",
+            VideoPath = "333333"
         };
         var bulletinId = await _snapshotBulletinApplication.AddBulletinAsync(inDto, CancellationToken.None);
+        var bulletin = await _bulletinRepository.GetAsync(bulletinId);
+        bulletin.IsSnapshot.ShouldBe(true);
+        bulletin.SafetyTypeId.ShouldBe(safetyType.Id);
+        bulletin.VideoPath.ShouldBe(inDto.VideoPath);
+        bulletin.VideoCoverImgUrl.ShouldBe(inDto.VideoCoverImgUrl);
         await _snapshotBulletinApplication.CommitBulletinAsync(bulletinId, CancellationToken.None);
         var examineDto = new ExamineBulletinDto
         {