|
@@ -1,9 +1,16 @@
|
|
|
-using Hotline.Application.Snapshot.Contracts;
|
|
|
+using DotNetCore.CAP;
|
|
|
+using Hotline.Application.Snapshot.Contracts;
|
|
|
using Hotline.Caching.Interfaces;
|
|
|
using Hotline.Settings;
|
|
|
using Hotline.Share.Attributes;
|
|
|
+using Hotline.Share.Dtos.Article;
|
|
|
using Hotline.Share.Dtos.Snapshot;
|
|
|
+using Hotline.Share.Enums.Article;
|
|
|
+using Hotline.Share.Tools;
|
|
|
+using Hotline.Snapshot;
|
|
|
+using Hotline.Snapshot.Contracts;
|
|
|
using Hotline.Snapshot.IRepository;
|
|
|
+using Mapster;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using SqlSugar;
|
|
|
using System;
|
|
@@ -12,7 +19,9 @@ using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Text.RegularExpressions;
|
|
|
using System.Threading.Tasks;
|
|
|
+using XF.Domain.Authentications;
|
|
|
using XF.Domain.Dependency;
|
|
|
+using XF.Domain.Exceptions;
|
|
|
|
|
|
namespace Hotline.Application.Snapshot;
|
|
|
public class SnapshotBulletinApplication : ISnapshotBulletinApplication, IScopeDependency
|
|
@@ -20,11 +29,74 @@ public class SnapshotBulletinApplication : ISnapshotBulletinApplication, IScopeD
|
|
|
|
|
|
private readonly ISystemSettingCacheManager _systemSettingCacheManager;
|
|
|
private readonly ISnapshotBulletinRepository _bulletinRepository;
|
|
|
+ private readonly INotificationDomainService _notificationDomainService;
|
|
|
+ private readonly ISessionContext _sessionContext;
|
|
|
+ private readonly ISafetyTypeRepository _safetyTypeRepository;
|
|
|
+ private readonly ICapPublisher _capPublisher;
|
|
|
|
|
|
- public SnapshotBulletinApplication(ISystemSettingCacheManager systemSettingCacheManager, ISnapshotBulletinRepository bulletinRepository)
|
|
|
+ public SnapshotBulletinApplication(ISystemSettingCacheManager systemSettingCacheManager, ISnapshotBulletinRepository bulletinRepository, INotificationDomainService notificationDomainService, ISessionContext sessionContext, ISafetyTypeRepository safetyTypeRepository, ICapPublisher capPublisher)
|
|
|
{
|
|
|
_systemSettingCacheManager = systemSettingCacheManager;
|
|
|
_bulletinRepository = bulletinRepository;
|
|
|
+ _notificationDomainService = notificationDomainService;
|
|
|
+ _sessionContext = sessionContext;
|
|
|
+ _safetyTypeRepository = safetyTypeRepository;
|
|
|
+ _capPublisher = capPublisher;
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task ExamineBulletinAsync(ExamineBulletinDto dto, CancellationToken token)
|
|
|
+ {
|
|
|
+ var bulletin = await _bulletinRepository.GetAsync(dto.Id, token)
|
|
|
+ ?? throw UserFriendlyException.SameMessage("无效数据");
|
|
|
+ if (bulletin.BulletinState != EBulletinState.InReview)
|
|
|
+ throw UserFriendlyException.SameMessage("当前状态不能审核");
|
|
|
+
|
|
|
+ if (dto.IsPass == false)
|
|
|
+ {
|
|
|
+ bulletin.ExaminOpinion = dto.Reason;
|
|
|
+ bulletin.ExaminTime = DateTime.Now;
|
|
|
+ bulletin.ExaminManId = _sessionContext.RequiredUserId;
|
|
|
+ bulletin.BulletinState = EBulletinState.ReviewNoPass;
|
|
|
+ await _bulletinRepository.UpdateAsync(bulletin, token);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ bulletin.BulletinState = EBulletinState.ReviewPass;
|
|
|
+ bulletin.BulletinTime = DateTime.Now;
|
|
|
+ bulletin.ExaminOpinion = dto.Reason;
|
|
|
+ bulletin.ExaminTime = DateTime.Now;
|
|
|
+ bulletin.ExaminManId = _sessionContext.RequiredUserId;
|
|
|
+ await _bulletinRepository.UpdateAsync(bulletin, token);
|
|
|
+
|
|
|
+ var citizens = await _safetyTypeRepository.Queryable()
|
|
|
+ .Includes(m => m.Citizens.Select(c => c.Id))
|
|
|
+ .Where(m => m.Id == bulletin.SafetyTypeId)
|
|
|
+ .ToListAsync(token);
|
|
|
+
|
|
|
+ await _capPublisher.PublishAsync(Share.Mq.EventNames.BulletinIsPass, bulletin.Id, cancellationToken: token);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 发送通知公告
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="bullutionId"></param>
|
|
|
+ /// <param name="token"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public async Task NotifyUserAsync(string bullutionId, CancellationToken token)
|
|
|
+ {
|
|
|
+ await _bulletinRepository.GetAsync(bullutionId, token)
|
|
|
+ .Then(async bulletion => {
|
|
|
+ await _safetyTypeRepository.Queryable().Where(m => m.Id == bulletion.SafetyTypeId)
|
|
|
+ .Includes(m => m.Citizens.Select(c => c.Id))
|
|
|
+ .FirstAsync(token)
|
|
|
+ .Then(async safetyType =>
|
|
|
+ {
|
|
|
+ var inDto = bulletion.Adapt<AddNotifyInDto>();
|
|
|
+ inDto.UserIds = [.. safetyType.Citizens.Select(m => m.Id)];
|
|
|
+ await _notificationDomainService.AddNotifyAsync(inDto, token);
|
|
|
+ });
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -88,4 +160,13 @@ public class SnapshotBulletinApplication : ISnapshotBulletinApplication, IScopeD
|
|
|
.Select<SnapshotBulletinItemsOutDto>();
|
|
|
return query;
|
|
|
}
|
|
|
+
|
|
|
+ public async Task<string> AddBulletinAsync(AddSnapshotBulletinInDto dto, CancellationToken token)
|
|
|
+ {
|
|
|
+ var model = dto.Adapt<SnapshotBulletin>();
|
|
|
+ model.BulletinState = Share.Enums.Article.EBulletinState.Draft;
|
|
|
+ model.ReadedNum = 0;
|
|
|
+ if (model.BulletinTime.HasValue == false) model.BulletinTime = DateTime.Now;
|
|
|
+ return await _bulletinRepository.AddAsync(model, token);
|
|
|
+ }
|
|
|
}
|