|
@@ -1,9 +1,19 @@
|
|
|
-using Hotline.Application.Snapshot.Contracts;
|
|
|
+using DocumentFormat.OpenXml.Vml.Office;
|
|
|
+using DotNetCore.CAP;
|
|
|
+using Hotline.Application.Snapshot.Contracts;
|
|
|
using Hotline.Caching.Interfaces;
|
|
|
+using Hotline.Orders;
|
|
|
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.Enums.Snapshot;
|
|
|
+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 +22,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 +32,81 @@ 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);
|
|
|
+
|
|
|
+ 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 =>
|
|
|
+ {
|
|
|
+ if (bulletion!.IsSnapshot == false) return;
|
|
|
+ if (bulletion!.SafetyTypeId!.IsNullOrEmpty()) return;
|
|
|
+ foreach (var safetyTypeId in bulletion!.SafetyTypeId!)
|
|
|
+ {
|
|
|
+ await _safetyTypeRepository.Queryable()
|
|
|
+ .LeftJoin<CitizenRelationSafetyType>((safety, relation) => safety.Id == relation.SafetyTypeId)
|
|
|
+ .LeftJoin<Citizen>((safety, relation, citizen) => relation.CitizenId == citizen.Id)
|
|
|
+ .Where((safety, relation, citizen) => safety.Id == safetyTypeId)
|
|
|
+ .Select((safety, relation, citizen) => relation.CitizenId)
|
|
|
+ .ToListAsync(token)
|
|
|
+ .Then(async citizenIds =>
|
|
|
+ {
|
|
|
+ var inDto = bulletion.Adapt<AddNotifyInDto>();
|
|
|
+ inDto.UserIds = citizenIds;
|
|
|
+ if (bulletion.VideoPath.NotNullOrEmpty())
|
|
|
+ {
|
|
|
+ inDto.NotifyType = ENotificationType.Video;
|
|
|
+ }
|
|
|
+ await _notificationDomainService.AddNotifyAsync(inDto, token);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -88,4 +170,29 @@ public class SnapshotBulletinApplication : ISnapshotBulletinApplication, IScopeD
|
|
|
.Select<SnapshotBulletinItemsOutDto>();
|
|
|
return query;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ public async Task CommitBulletinAsync(string id, CancellationToken requestAborted)
|
|
|
+ {
|
|
|
+ var bulletin = await _bulletinRepository.GetAsync(id, requestAborted);
|
|
|
+ if (bulletin == null)
|
|
|
+ throw UserFriendlyException.SameMessage("无效数据");
|
|
|
+
|
|
|
+ if (bulletin.BulletinState != EBulletinState.Draft && bulletin.BulletinState != EBulletinState.ReviewNoPass)
|
|
|
+ throw UserFriendlyException.SameMessage("当前状态不能提交");
|
|
|
+
|
|
|
+ bulletin.BulletinState = EBulletinState.InReview;
|
|
|
+ bulletin.CommitTime = DateTime.Now;
|
|
|
+ await _bulletinRepository.UpdateAsync(bulletin, requestAborted);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public async Task<string> AddBulletinAsync(AddSnapshotBulletinInDto dto, CancellationToken token)
|
|
|
+ {
|
|
|
+ var model = dto.Adapt<SnapshotBulletin>();
|
|
|
+ model.BulletinState = EBulletinState.Draft;
|
|
|
+ model.ReadedNum = 0;
|
|
|
+ if (model.BulletinTime.HasValue == false) model.BulletinTime = DateTime.Now;
|
|
|
+ return await _bulletinRepository.AddAsync(model, token);
|
|
|
+ }
|
|
|
}
|