瀏覽代碼

Merge branch 'feature/snapshot' into test

qinchaoyue 4 天之前
父節點
當前提交
e3d38dfe68

+ 30 - 2
src/Hotline.Api/Controllers/Snapshot/SnapshotUserController.cs

@@ -3,6 +3,7 @@ using Hotline.Repository.SqlSugar.Extensions;
 using Hotline.Share.Dtos;
 using Hotline.Share.Dtos.Snapshot;
 using Hotline.Share.Tools;
+using Hotline.Snapshot.IRepository;
 using Microsoft.AspNetCore.Mvc;
 using System.ComponentModel;
 
@@ -12,10 +13,28 @@ namespace Hotline.Api.Controllers.Snapshot;
 public class SnapshotUserController : BaseController
 {
     private readonly ISnapshotUserApplication _snapshotUserApplication;
+    private readonly ISafetyTypeRepository _safetyTypeRepository;
 
-    public SnapshotUserController(ISnapshotUserApplication snapshotUserApplication)
+    public SnapshotUserController(ISnapshotUserApplication snapshotUserApplication, ISafetyTypeRepository safetyTypeRepository)
     {
         _snapshotUserApplication = snapshotUserApplication;
+        _safetyTypeRepository = safetyTypeRepository;
+    }
+
+    /// <summary>
+    /// 获取添加安全志愿者和安全员分类关系的基础数据
+    /// </summary>
+    /// <returns></returns>
+    [HttpGet("citizen_relation/basedata")]
+    public async Task<Dictionary<string, object>> GetCitizenRelationSafetyTypeBase()
+    {
+        var safetyTypes = await _safetyTypeRepository.Queryable()
+            .Select(m => new { m.Id, m.Name})
+            .ToListAsync(HttpContext.RequestAborted);
+        return new Dictionary<string, object>
+        {
+            { "safetyTypes", safetyTypes }
+        };
     }
 
     /// <summary>
@@ -27,11 +46,20 @@ public class SnapshotUserController : BaseController
         => (await _snapshotUserApplication.GetCitizenRelationSafetyType(dto).ToPagedListAsync(dto)).ToPaged();
 
     /// <summary>
-    /// 添加安全志愿者
+    /// 添加安全志愿者和安全员分类关系
     /// </summary>
     /// <param name="dto"></param>
     /// <returns></returns>
     [HttpPost("citizen_relation")]
     public async Task AddCitizenRelationSafetyTypeInDto([FromBody]AddCitizenRelationSafetyTypeInDto dto)
         => await _snapshotUserApplication.AddCitizenRelationSafetyType(dto, HttpContext.RequestAborted);
+
+    /// <summary>
+    /// 批量删除安全志愿者分类关系
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+    [HttpDelete("citizen_relation")]
+    public async Task DeleteCitizenRelationSafetyType([FromBody] DeleteCitizenRelationSafetyTypeInDto dto)
+        => await _snapshotUserApplication.DeleteCitizenRelationSafetyAsync(dto);
 }

+ 11 - 3
src/Hotline.Application/Snapshot/SnapshotUserApplication.cs

@@ -75,9 +75,17 @@ public class SnapshotUserApplication : ISnapshotUserApplication, IScopeDependenc
     {
         foreach (var item in dto.Items)
         {
-            await _citizenRepository.RemoveNav(m => m.Id == item.CitizenId)
-                .Include(m => m.SafetyTypes.Where(s => s.Id == item.SafetyTypeId).First())
-                .ExecuteCommandAsync();
+            var citizen = await _citizenRepository.Queryable()
+                .Includes(m => m.SafetyTypes)
+                .Where(m => m.Id == item.CitizenId)
+                .FirstAsync();
+            var deleteSafetyType = citizen.SafetyTypes.FirstOrDefault(m => m.Id == item.SafetyTypeId);
+            if (deleteSafetyType == null) continue;
+
+            citizen.SafetyTypes.Remove(deleteSafetyType);
+            _citizenRepository.UpdateNav(citizen)
+                .Include(m => m.SafetyTypes)
+                .ExecuteCommand();
         }
     }
 }

+ 11 - 1
src/Hotline.Share/Dtos/Snapshot/SnapshotBulletinDto.cs

@@ -255,6 +255,16 @@ public class AddSnapshotBulletinInDto
     /// </summary>
     public bool IsPopup { get; set; }
 
+    /// <summary>
+    /// 是否随手拍
+    /// </summary>
+    public bool? IsSnapshot { get; set; }
+
+    /// <summary>
+    /// 志愿者类型Id
+    /// </summary>
+    public string? SafetyTypeId { get; set; }
+
     /// <summary>
     /// 时间
     /// </summary>
@@ -268,5 +278,5 @@ public class AddSnapshotBulletinInDto
     /// <summary>
     /// 视频地址
     /// </summary>
-    public string VideoPath { get; set; }
+    public string? VideoPath { get; set; }
 }

+ 2 - 2
src/Hotline/Snapshot/CitizenRelationSafetyType.cs

@@ -14,13 +14,13 @@ public class CitizenRelationSafetyType : ITable, IEntity
     /// 市民Id
     /// <inheritdoc cref="Hotline.Orders.Citizen"/>
     /// </summary>
-    [SugarColumn(ColumnDescription = "市民Id", IsPrimaryKey = true)]
+    [SugarColumn(ColumnDescription = "市民Id")]
     public string CitizenId { get; set; }
 
     /// <summary>
     /// 安全员类型Id
     /// <inheritdoc cref="SafetyType"/>
     /// </summary>
-    [SugarColumn(ColumnDescription = "安全员类型Id", IsPrimaryKey = true)]
+    [SugarColumn(ColumnDescription = "安全员类型Id")]
     public string SafetyTypeId { get; set; }
 }

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

@@ -87,7 +87,7 @@ public class SnapshotUserApplicationTest : TestBase
             [
                 new() {
                     CitizenId = citizen.Id,
-                    SafetyTypeId = safetyTypeXuanChuan.Id
+                    SafetyTypeId = safetyType.Id
                 }
             ]
         };