Ver código fonte

随手拍通知公告功能

qinchaoyue 3 dias atrás
pai
commit
60a5151a6c

+ 8 - 4
src/Hotline.Api/Controllers/Snapshot/SnapshotBulletinController.cs

@@ -15,6 +15,7 @@ using Hotline.Share.Tools;
 using XF.Utility.EnumExtensions;
 using Hotline.Snapshot.IRepository;
 using Hotline.Application.Snapshot.Contracts;
+using Hotline.Share.Dtos.Settings;
 
 namespace Hotline.Api.Controllers.Snapshot;
 
@@ -22,18 +23,17 @@ public class SnapshotBulletinController : BaseController
 {
     private readonly ISnapshotBulletinRepository _bulletinRepository;
     private readonly ISnapshotBulletinApplication _bulletinApplication;
-    private readonly ISessionContext _sessionContext;
     private readonly ISystemDicDataCacheManager _systemDicDataCacheManager;
     private readonly ISystemOrganizeRepository _organizeRepository;
-    private readonly INotificationApplication _notificationApplication;
+    private readonly ISafetyTypeRepository _safetyTypeRepository;
 
-    public SnapshotBulletinController(ISnapshotBulletinRepository bulletinRepository, ISessionContext sessionContext, ISystemDicDataCacheManager systemDicDataCacheManager, ISystemOrganizeRepository organizeRepository, ISnapshotBulletinApplication bulletinApplication)
+    public SnapshotBulletinController(ISnapshotBulletinRepository bulletinRepository, ISystemDicDataCacheManager systemDicDataCacheManager, ISystemOrganizeRepository organizeRepository, ISnapshotBulletinApplication bulletinApplication, ISafetyTypeRepository safetyTypeRepository)
     {
         _bulletinRepository = bulletinRepository;
-        _sessionContext = sessionContext;
         _systemDicDataCacheManager = systemDicDataCacheManager;
         _organizeRepository = organizeRepository;
         _bulletinApplication = bulletinApplication;
+        _safetyTypeRepository = safetyTypeRepository;
     }
 
     #region 公告
@@ -179,11 +179,15 @@ public class SnapshotBulletinController : BaseController
     [HttpGet("bulletin/addbasedata")]
     public async Task<object> BulletinAddBaseData()
     {
+        var safetyTypes = await _safetyTypeRepository.Queryable()
+            .Select(m => new SystemDicDataOutDto { Id =  m.Id, DicDataName = m.Name , DicDataValue = m.Id})
+            .ToListAsync(HttpContext.RequestAborted);
         var rsp = new
         {
             BulletinType = _systemDicDataCacheManager.SnapshotBulletinType,
             BulletinSource = _systemDicDataCacheManager.SnapshotBulletinSource,
             OrgsOptions = await _organizeRepository.GetOrgJson(),
+            SafetyTypes = safetyTypes
         };
         return rsp;
     }

+ 7 - 1
src/Hotline.Api/Controllers/Snapshot/SnapshotUserController.cs

@@ -63,6 +63,12 @@ public class SnapshotUserController : BaseController
     public async Task DeleteCitizenRelationSafetyType([FromBody] DeleteCitizenRelationSafetyTypeInDto dto)
         => await _snapshotUserApplication.DeleteCitizenRelationSafetyAsync(dto);
 
+    /// <summary>
+    /// 搜索安全志愿者
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
     [HttpGet("citizen")]
-    public
+    public async Task<PagedDto<GetThirdCitizenOutDto>> GetThirdCitizenAsync([FromQuery] GetThirdCitizenInDto dto)
+        => (await _snapshotUserApplication.GetThirdCitizenAsync(dto).ToPagedListAsync(dto)).ToPaged();
 }

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

@@ -21,4 +21,11 @@ public interface ISnapshotUserApplication
     /// <param name="dto"></param>
     /// <returns></returns>
     Task DeleteCitizenRelationSafetyAsync(DeleteCitizenRelationSafetyTypeInDto dto);
+
+    /// <summary>
+    /// 获取第三方市民列表
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+    ISugarQueryable<GetThirdCitizenOutDto> GetThirdCitizenAsync(GetThirdCitizenInDto dto);
 }

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

@@ -91,6 +91,7 @@ public class SnapshotBulletinApplication : ISnapshotBulletinApplication, IScopeD
         await _bulletinRepository.GetAsync(bullutionId, token)
             .Then(async bulletion =>
             {
+                if (bulletion!.IsSnapshot == false) return;
                 await _safetyTypeRepository.Queryable()
                     .LeftJoin<CitizenRelationSafetyType>((safety, relation) => safety.Id == relation.SafetyTypeId)
                     .LeftJoin<Citizen>((safety, relation, citizen) => relation.CitizenId == citizen.Id)

+ 14 - 0
src/Hotline.Application/Snapshot/SnapshotUserApplication.cs

@@ -10,6 +10,7 @@ using Hotline.Snapshot.IRepository;
 using Hotline.ThirdAccountDomainServices;
 using Hotline.Tools;
 using Mapster;
+using NPOI.POIFS.Properties;
 using SqlSugar;
 using System;
 using System.Collections.Generic;
@@ -88,4 +89,17 @@ public class SnapshotUserApplication : ISnapshotUserApplication, IScopeDependenc
                 .ExecuteCommand();
         }
     }
+
+    public ISugarQueryable<GetThirdCitizenOutDto> GetThirdCitizenAsync(GetThirdCitizenInDto dto)
+    {
+        var query = _citizenRepository.Queryable(includeDeleted: true)
+            .LeftJoin<ThirdAccount>((citizen, third) => citizen.Id == third.ExternalId)
+            .WhereIF(dto.PhoneNumber.NotNullOrEmpty(), (citizen, third) => citizen.PhoneNumber.Contains(dto.PhoneNumber))
+            .Select((citizen, third) => new GetThirdCitizenOutDto(), true);
+#if DEBUG
+        var sql = query.ToSqlString();
+#endif
+
+        return query;
+    }
 }

+ 26 - 0
src/Hotline.Share/Dtos/Snapshot/SnapshotUserInfoDto.cs

@@ -124,3 +124,29 @@ public class CitizenIdRelationSafetyTypeId
     /// </summary>
     public string SafetyTypeId { get; set; }
 }
+
+public record GetThirdCitizenInDto : PagedRequest
+{
+    /// <summary>
+    /// 电话号码
+    /// </summary>
+    public string? PhoneNumber { get; set; }
+}
+
+public class GetThirdCitizenOutDto
+{
+    /// <summary>
+    /// Id
+    /// </summary>
+    public string CitizenId { get; set; }
+
+    /// <summary>
+    /// Name
+    /// </summary>
+    public string Name { get; set; }
+
+    /// <summary>
+    /// 电话
+    /// </summary>
+    public string PhoneNumber { get; set; }
+}

+ 7 - 0
test/Hotline.Tests/Application/SnapshotUserApplicationTest.cs

@@ -37,6 +37,13 @@ public class SnapshotUserApplicationTest : TestBase
     [Fact]
     public async Task SnapshotUserApplication_Test()
     {
+        var searchInDto = new GetThirdCitizenInDto
+        {
+            PhoneNumber = "33"
+        };
+        var citizenSearchItems = await _snapshotUserApplication.GetThirdCitizenAsync(searchInDto).ToListAsync();
+        citizenSearchItems.ShouldNotBeNull();
+        citizenSearchItems.Count.ShouldNotBe(0);
         var newSafetyType = new SafetyType { Name = "安全卫士" };
         var safetyType = await _safetyTypeRepository.Queryable().Where(m => m.Name == newSafetyType.Name).FirstAsync();
         safetyType ??= new SafetyType