Sfoglia il codice sorgente

Merge branch 'feature/snapshot' into test

qinchaoyue 1 mese fa
parent
commit
3d1ca1aa6b

+ 1 - 1
src/Hotline.Api/Controllers/Snapshot/IndustryController.cs

@@ -67,7 +67,7 @@ public class IndustryController : BaseController
     /// <returns></returns>
     [HttpGet("{id}")]
     public async Task<IndustryDetailOutDto> GetIndustryDetailAsync(string id)
-        => await _industryApplication.GetIndustryDetailAsync(id);
+        => await _industryApplication.GetIndustryDetailAsync(id, HttpContext.RequestAborted);
 
     /// <summary>
     /// 获取行业集合

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

@@ -28,7 +28,7 @@ public interface IIndustryApplication
     /// </summary>
     /// <param name="id"></param>
     /// <returns></returns>
-    Task<IndustryDetailOutDto> GetIndustryDetailAsync(string id);
+    Task<IndustryDetailOutDto> GetIndustryDetailAsync(string id, CancellationToken token);
 
     /// <summary>
     /// 修改行业

+ 3 - 2
src/Hotline.Application/Snapshot/IndustryApplication.cs

@@ -58,6 +58,7 @@ public class IndustryApplication : IIndustryApplication, IScopeDependency
     /// <exception cref="NotImplementedException"></exception>
     public async Task<string> AddIndustryAsync(AddIndustryDto dto, CancellationToken cancellationToken)
     {
+        dto.ValidateObject();
         if (dto.ApproveOrgId.NotNullOrEmpty() && dto.ApproveOrgName.IsNullOrEmpty())
         {
             await _systemOrganizeRepository.GetAsync(dto.ApproveOrgId, cancellationToken)
@@ -87,12 +88,12 @@ public class IndustryApplication : IIndustryApplication, IScopeDependency
         return query;
     }
 
-    public async Task<IndustryDetailOutDto> GetIndustryDetailAsync(string id)
+    public async Task<IndustryDetailOutDto> GetIndustryDetailAsync(string id, CancellationToken token)
     {
         var fileServiceUrl = _sysSetting.FileServerUrl;
         var fileDownloadApi = fileServiceUrl + _sysSetting.FileDownloadApi;
         var industry = await _industryRepository.GetAsync(id);
-        var files = await _fileRepository.GetByKeyAsync(id, CancellationToken.None);
+        var files = await _fileRepository.GetByKeyAsync(id, token);
         var outDto = industry.Adapt<IndustryDetailOutDto>();
         outDto.Files = files.Adapt<IList<IndustryFileDto>>();
         return outDto;

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

@@ -189,7 +189,7 @@ public class SnapshotStartWorkFlow : INotificationHandler<StartWorkflowNotify>
         try
         {
             if (_sysSetting.Snapshot == false && notification.Workflow.ModuleCode != WorkflowModuleConsts.OrderHandle) return;
-            await _snapshotPointsDomainService.AddPointsAsync(notification.Workflow.ExternalId, EPointsSource.Report, ERedPackAuditStatus.Agree);
+            await _snapshotPointsDomainService.AddPointsAsync(notification.Workflow.ExternalId, EPointsSource.Report, ERedPackAuditStatus.Agree, 0);
         }
         catch (Exception e)
         {

+ 2 - 2
src/Hotline.Application/Snapshot/RedPackApplication.cs

@@ -120,8 +120,8 @@ public class RedPackApplication : IRedPackApplication, IScopeDependency
                 entity.Amount = redPackAudit.ApprovedAmount.Value;
             await _redPackRecordRepository.AddAsync(entity);
         }
-        await _redPackAuditRepository.UpdateAsync(redPackAudit);
-        await _snapshotPointsDomainService.AddPointsAsync(order.Id, EPointsSource.Audit, status);
+        await _redPackAuditRepository.UpdateAsync(redPackAudit, token);
+        await _snapshotPointsDomainService.AddPointsAsync(order.Id, EPointsSource.Audit, status, dto.ExtraDeductedPoints);
         if (dto.IsSendSms)
         {
             var smsTemplate = await _snapshotSMSTemplateRepository.GetAsync(dto.SMSTemplateId);

+ 5 - 0
src/Hotline.Repository.SqlSugar/Snapshot/SnapshotPointsRecordRepository.cs

@@ -16,4 +16,9 @@ public class SnapshotPointsRecordRepository : BaseRepository<SnapshotPointsRecor
     public SnapshotPointsRecordRepository(ISugarUnitOfWork<HotlineDbContext> uow, IDataPermissionFilterBuilder dataPermissionFilterBuilder, IServiceProvider serviceProvider) : base(uow, dataPermissionFilterBuilder, serviceProvider)
     {
     }
+
+    public async Task<IList<SnapshotPointsRecord>> GetByOrderIdAsync(string orderId, CancellationToken token)
+    {
+        return await Queryable().Where(m => m.OrderId == orderId).ToListAsync(token);
+    }
 }

+ 45 - 0
src/Hotline.Share/Dtos/Snapshot/IndustryDto.cs

@@ -168,6 +168,27 @@ public class IndustryOutDto
     /// 关怀页面Url
     /// </summary>
     public string? PageCareUrl { get; set; }
+
+    /// <summary>
+    /// 上报积分
+    /// </summary>
+    public int ReportPoints { get; set; }
+
+    /// <summary>
+    /// 审核同意积分
+    /// </summary>
+    public int ArgeePoints { get; set; }
+
+    /// <summary>
+    /// 审核不同意扣除积分
+    /// </summary>
+    public int RefusePoints { get; set; }
+
+    /// <summary>
+    /// 额外扣除积分
+    /// </summary>
+    public int ExtraDeductedPoints { get; set; }
+
 }
 
 /// <summary>
@@ -375,6 +396,30 @@ public class AddIndustryDto
     /// 附件集合(小程序上面可以下载的 doc 文件)
     /// </summary>
     public IList<IndustryFileDto> Files { get; set; }
+
+    /// <summary>
+    /// 上报积分
+    /// </summary>
+    [Required]
+    public int ReportPoints { get; set; }
+
+    /// <summary>
+    /// 审核同意积分
+    /// </summary>
+    [Required]
+    public int ArgeePoints { get; set; }
+
+    /// <summary>
+    /// 审核不同意扣除积分
+    /// </summary>
+    [Required]
+    public int RefusePoints { get; set; }
+
+    /// <summary>
+    /// 额外扣除积分
+    /// </summary>
+    [Required]
+    public int ExtraDeductedPoints { get; set; }
 }
 
 public class IndustryCaseItemOutDto : AddIndustryCaseDto

+ 1 - 1
src/Hotline/FlowEngine/Workflows/WorkflowDomainService.cs

@@ -274,7 +274,7 @@ namespace Hotline.FlowEngine.Workflows
 
             //publish
             await _publisher.PublishAsync(new StartWorkflowNotify(workflow, dto, startTrace),
-                PublishStrategy.ParallelWhenAll, cancellationToken);
+                PublishStrategy.SyncContinueOnException, cancellationToken);
 
             return (workflow, startStep);
         }

+ 1 - 1
src/Hotline/Snapshot/Contracts/ISnapshotPointsDomainService.cs

@@ -12,5 +12,5 @@ namespace Hotline.Snapshot.Contracts;
 /// </summary>
 public interface ISnapshotPointsDomainService
 {
-    Task AddPointsAsync(string orderId, EPointsSource source, ERedPackAuditStatus status);
+    Task AddPointsAsync(string orderId, EPointsSource source, ERedPackAuditStatus status, int? extraDeductedPoints);
 }

+ 2 - 1
src/Hotline/Snapshot/IRepository/ISnapshotPointsRecordRepository.cs

@@ -7,6 +7,7 @@ using XF.Domain.Repository;
 
 namespace Hotline.Snapshot.IRepository;
 
-public interface ISnapshotPointsRecordRepository: IRepository<SnapshotPointsRecord>
+public interface ISnapshotPointsRecordRepository : IRepository<SnapshotPointsRecord>
 {
+    Task<IList<SnapshotPointsRecord>> GetByOrderIdAsync(string orderId, CancellationToken none);
 }

+ 6 - 4
src/Hotline/Snapshot/Services/SnapshotPointsDomainService.cs

@@ -22,12 +22,12 @@ public class SnapshotPointsDomainService : ISnapshotPointsDomainService, IScopeD
         _pointsRecordRepository = snapshotPointsRecordRepository;
     }
 
-    public async Task AddPointsAsync(string orderId, EPointsSource source, ERedPackAuditStatus status)
+    public async Task AddPointsAsync(string orderId, EPointsSource source, ERedPackAuditStatus status, int? extraDeductedPoints)
     {
         var order = await _orderSnapshotRepository.Queryable()
             .LeftJoin<Industry>((snapshot, industry) => snapshot.IndustryId == industry.Id)
             .Where((snapshot, industry) => snapshot.Id == orderId)
-            .Select((snapshot, industry) => new { snapshot.Id, industry.ReportPoints , industry.ArgeePoints ,  industry.Name})
+            .Select((snapshot, industry) => new { snapshot.Id, industry.ReportPoints , industry.ArgeePoints , industry.RefusePoints,  industry.Name})
             .FirstAsync() ?? throw new UserFriendlyException($"{orderId} 工单不存在");
         if (order.ReportPoints.HasValue == false)
             throw new UserFriendlyException($"{order.Name} 行业未配置积分");
@@ -35,8 +35,10 @@ public class SnapshotPointsDomainService : ISnapshotPointsDomainService, IScopeD
         var point = 0;
         if (source == EPointsSource.Report)
             point = order.ReportPoints.Value;
-        if (source == EPointsSource.Audit)
-            point = order.ArgeePoints.Value;
+        if (source == EPointsSource.Audit && status == ERedPackAuditStatus.Agree)
+            point = order.ArgeePoints ?? 0;
+        if (source == EPointsSource.Audit && status == ERedPackAuditStatus.Refuse)
+            point = order.RefusePoints ?? 0 + extraDeductedPoints ?? 0;
         await _pointsRecordRepository.AddAsync(new SnapshotPointsRecord
         {
             OrderId = orderId,

+ 1 - 1
test/Hotline.Tests/Application/IndustryApplicationTest.cs

@@ -59,7 +59,7 @@ public class IndustryApplicationTest : TestBase
         industry.ApproveOrgId = orgs.First().Key;
         industry.ApproveOrgName = null;
         await _industryApplication.UpdateIndustryAsync(industry, CancellationToken.None);
-        var updateIndustry = await _industryApplication.GetIndustryDetailAsync(item.Id);
+        var updateIndustry = await _industryApplication.GetIndustryDetailAsync(item.Id, CancellationToken.None);
         updateIndustry.ForeachClassProperties(async (industry, property, name, value) =>
         {
             industry.GetType().GetProperty(name).GetValue(industry).ShouldBe(value);

+ 15 - 1
test/Hotline.Tests/Application/OrderSnapshotApplicationTest.cs

@@ -12,6 +12,7 @@ using Hotline.Share.Dtos.Snapshot;
 using Hotline.Share.Enums.Snapshot;
 using Hotline.Share.Requests;
 using Hotline.Share.Tools;
+using Hotline.Snapshot;
 using Hotline.Snapshot.IRepository;
 using Hotline.Tests.Mock;
 using Hotline.ThirdAccountDomainServices;
@@ -45,8 +46,10 @@ public class OrderSnapshotApplicationTest : TestBase
     private readonly IRedPackApplication _redPackApplication;
     private readonly IOrderRepository _orderRepository;
     private readonly IIndustryCaseRepository _industryCaseRepository;
+    private readonly ISnapshotPointsRecordRepository _pointsRecordRepository;
+    private readonly IIndustryRepository _industryRepository;
 
-    public OrderSnapshotApplicationTest(IAccountRepository accountRepository, IRepository<Role> roleRepository, UserController userController, IServiceScopeFactory scopeFactory, IRepository<User> userRepository, IHttpContextAccessor httpContextAccessor, IThirdIdentiyService thirdIdentiyService, IThirdAccountRepository thirdAccountRepository, OrderServiceMock orderServiceMock, ISystemDicDataCacheManager systemDicDataCacheManager, IOrderSnapshotRepository orderSnapshotRepository, IOrderSnapshotApplication orderSnapshotApplication, ISnapshotApplication snapshotApplication, IIndustryLogRepository industryLogRepository, ICommunityInfoRepository communityInfoRepository, IRedPackAuditRepository redPackAuditRepository, IRedPackRecordRepository redPackRecordRepository, ISnapshotLabelLogRepository snapshotLabelLogRepository, ITypedCache<SystemSetting> cacheSettingData, IRedPackApplication redPackApplication, IOrderRepository orderRepository, ThirdAccounSupplierFactory thirdAccountDomainFactory, IIndustryCaseRepository industryCaseRepository) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdIdentiyService, thirdAccountRepository, cacheSettingData, thirdAccountDomainFactory)
+    public OrderSnapshotApplicationTest(IAccountRepository accountRepository, IRepository<Role> roleRepository, UserController userController, IServiceScopeFactory scopeFactory, IRepository<User> userRepository, IHttpContextAccessor httpContextAccessor, IThirdIdentiyService thirdIdentiyService, IThirdAccountRepository thirdAccountRepository, OrderServiceMock orderServiceMock, ISystemDicDataCacheManager systemDicDataCacheManager, IOrderSnapshotRepository orderSnapshotRepository, IOrderSnapshotApplication orderSnapshotApplication, ISnapshotApplication snapshotApplication, IIndustryLogRepository industryLogRepository, ICommunityInfoRepository communityInfoRepository, IRedPackAuditRepository redPackAuditRepository, IRedPackRecordRepository redPackRecordRepository, ISnapshotLabelLogRepository snapshotLabelLogRepository, ITypedCache<SystemSetting> cacheSettingData, IRedPackApplication redPackApplication, IOrderRepository orderRepository, ThirdAccounSupplierFactory thirdAccountDomainFactory, IIndustryCaseRepository industryCaseRepository, ISnapshotPointsRecordRepository pointsRecordRepository, IIndustryRepository industryRepository) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdIdentiyService, thirdAccountRepository, cacheSettingData, thirdAccountDomainFactory)
     {
         _orderServiceMock = orderServiceMock;
         _systemDicDataCacheManager = systemDicDataCacheManager;
@@ -61,6 +64,8 @@ public class OrderSnapshotApplicationTest : TestBase
         _redPackApplication = redPackApplication;
         _orderRepository = orderRepository;
         _industryCaseRepository = industryCaseRepository;
+        _pointsRecordRepository = pointsRecordRepository;
+        _industryRepository = industryRepository;
     }
 
     /// <summary>
@@ -106,6 +111,15 @@ public class OrderSnapshotApplicationTest : TestBase
             .办理到网格员(SetZuoXi)
             .StepHandle(async (order, mock) =>
             {
+                var industry = await _industryRepository.Queryable()
+                .LeftJoin<OrderSnapshot>((industry, snapshot) => industry.Id == snapshot.IndustryId)
+                .Where((industry, snapshot) => snapshot.Id == order.Id)
+                .Select((industry, snapshot) => new Industry(), true)
+                .FirstAsync();
+                var pointsRecord = await _pointsRecordRepository.Queryable().Where(m => m.OrderId == order.Id && m.Source == EPointsSource.Report).FirstAsync();
+                pointsRecord.ShouldNotBeNull();
+                pointsRecord.Points.ShouldBe(industry.ReportPoints!.Value);
+
                 await _snapshotApplication.PostOrderGuiderSystemAsync(order.Id, CancellationToken.None);
                 var orderSnapshot = await _orderSnapshotRepository.GetAsync(order.Id);
                 orderSnapshot.IndustryName = "修改行业名称";

+ 6 - 1
test/Hotline.Tests/Application/RedPackApplicationTest.cs

@@ -34,8 +34,9 @@ public class RedPackApplicationTest : TestBase
     private readonly ISystemDicDataCacheManager _systemDicDataCacheManager;
     private readonly IIndustryRepository _industryRepository;
     private readonly ISpecialRedPackAuditRepository _specialRedPackAuditRepository;
+    private readonly ISnapshotPointsRecordRepository _pointsRecordRepository;
 
-    public RedPackApplicationTest(IAccountRepository accountRepository, IRepository<Role> roleRepository, UserController userController, IServiceScopeFactory scopeFactory, IRepository<User> userRepository, IHttpContextAccessor httpContextAccessor, IThirdIdentiyService thirdIdentiyService, IThirdAccountRepository thirdAccountRepository, IRedPackApplication redPackApplication, IRedPackRecordRepository redPackRecordRepository, ITypedCache<SystemSetting> cacheSettingData, OrderServiceMock orderServiceMock, ISystemDicDataCacheManager systemDicDataCacheManager, IIndustryRepository industryRepository, ISpecialRedPackAuditRepository specialRedPackAuditRepository, ThirdAccounSupplierFactory thirdAccountDomainFactory) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdIdentiyService, thirdAccountRepository, cacheSettingData, thirdAccountDomainFactory)
+    public RedPackApplicationTest(IAccountRepository accountRepository, IRepository<Role> roleRepository, UserController userController, IServiceScopeFactory scopeFactory, IRepository<User> userRepository, IHttpContextAccessor httpContextAccessor, IThirdIdentiyService thirdIdentiyService, IThirdAccountRepository thirdAccountRepository, IRedPackApplication redPackApplication, IRedPackRecordRepository redPackRecordRepository, ITypedCache<SystemSetting> cacheSettingData, OrderServiceMock orderServiceMock, ISystemDicDataCacheManager systemDicDataCacheManager, IIndustryRepository industryRepository, ISpecialRedPackAuditRepository specialRedPackAuditRepository, ThirdAccounSupplierFactory thirdAccountDomainFactory, ISnapshotPointsRecordRepository pointsRecordRepository) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdIdentiyService, thirdAccountRepository, cacheSettingData, thirdAccountDomainFactory)
     {
         _redPackApplication = redPackApplication;
         _redPackRecordRepository = redPackRecordRepository;
@@ -43,6 +44,7 @@ public class RedPackApplicationTest : TestBase
         _systemDicDataCacheManager = systemDicDataCacheManager;
         _industryRepository = industryRepository;
         _specialRedPackAuditRepository = specialRedPackAuditRepository;
+        _pointsRecordRepository = pointsRecordRepository;
     }
 
     /// <summary>
@@ -121,6 +123,9 @@ public class RedPackApplicationTest : TestBase
             RedPackAuditId = audit.Id,
         };
         await _redPackApplication.AuditRedPackAuditAsync(inDto, CancellationToken.None);
+
+        var pointRecord = await _pointsRecordRepository.GetByOrderIdAsync(audit.OrderId, CancellationToken.None);
+        pointRecord.Where(m => m.Source == EPointsSource.Audit).Count().ShouldBe(1);
         var suInDto = new UpdateRedPackRecordInDto
         {
             RedPackAuditId = audit.Id,

+ 11 - 1
test/Hotline.Tests/Application/SnapshotApplicationTest.cs

@@ -435,6 +435,7 @@ public class SnapshotApplicationTest : TestBase
     [Fact]
     public async Task Industry_Test()
     {
+        SetZuoXi();
         var industry = new AddIndustryDto
         {
             Name = "测试行业",
@@ -455,12 +456,21 @@ public class SnapshotApplicationTest : TestBase
                     FileName ="测试文件" + DateTime.Now.ToShortDateString()  + ".doc",
                     AdditionId = DateTime.Now.ToLongDateString()
                 }
-            }
+            },
+            ArgeePoints = 3,
+            ExtraDeductedPoints = 2,
+            RefusePoints = 1,
+            ReportPoints = 4
         };
         var industryId = await _industryApplication.AddIndustryAsync(industry, CancellationToken.None);
         var pageDto = await _snapshotApplication.GetIndustryBaseAsync(industryId, CancellationToken.None);
+        var industryOut = await _industryApplication.GetIndustryDetailAsync(industryId, CancellationToken.None);
         try
         {
+            industryOut.ArgeePoints.ShouldBe(industry.ArgeePoints);
+            industryOut.ExtraDeductedPoints.ShouldBe(industry.ExtraDeductedPoints);
+            industryOut.RefusePoints.ShouldBe(industry.RefusePoints);
+            industryOut.ReportPoints.ShouldBe(industry.ReportPoints);
             pageDto.ShouldNotBeNull();
             pageDto.Files.ShouldNotBeNull();
             foreach (var file in pageDto.Files)