You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
348 lines
15 KiB
348 lines
15 KiB
|
3 months ago
|
using ATS.NonCustodial.Application.Base;
|
||
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Business.AppAnnouncements;
|
||
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Business.AppAnnouncements.Input;
|
||
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Business.AppAnnouncements.Output;
|
||
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Business.AppCaseManagements.AppCaseManagement.Output;
|
||
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Business.Apps.Output;
|
||
|
|
using ATS.NonCustodial.Application.Impl.Business.IM;
|
||
|
|
using ATS.NonCustodial.Domain.Entities.Business;
|
||
|
|
using ATS.NonCustodial.Domain.Entities.Business.CaseManagements;
|
||
|
|
using ATS.NonCustodial.Domain.Entities.Business.IM;
|
||
|
|
using ATS.NonCustodial.Domain.Shared.AggRootEntities.Dtos;
|
||
|
|
using ATS.NonCustodial.Domain.Shared.Enums;
|
||
|
|
using ATS.NonCustodial.Domain.Shared.OrmRepositories.Basic.EfCore;
|
||
|
|
using ATS.NonCustodial.DynamicApi;
|
||
|
|
using ATS.NonCustodial.DynamicApi.Attributes;
|
||
|
|
using ATS.NonCustodial.Shared.Common.UnifiedResults;
|
||
|
|
using ATS.NonCustodial.Shared.Configurations.Options;
|
||
|
|
using ATS.NonCustodial.Shared.Extensions;
|
||
|
|
using ATS.NonCustodial.Shared.Extensions.AdvancedQuery;
|
||
|
|
using ATS.NonCustodial.Shared.Extensions.Collection;
|
||
|
|
using AutoMapper.QueryableExtensions;
|
||
|
|
using Microsoft.AspNetCore.Authorization;
|
||
|
|
using Microsoft.AspNetCore.Http;
|
||
|
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
using Microsoft.AspNetCore.SignalR;
|
||
|
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
using Newtonsoft.Json;
|
||
|
|
using Yitter.IdGenerator;
|
||
|
|
|
||
|
|
namespace ATS.NonCustodial.Application.Impl.Business
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// 通知公告管理
|
||
|
|
/// </summary>
|
||
|
|
/// Author:mxg
|
||
|
|
/// CreatedTimed:2022-06-05 10:01 PM
|
||
|
|
[DynamicApi(Area = "admin")]
|
||
|
|
public class AppAnnouncementService : AdminAppServiceBase, IAppAnnouncementService, IDynamicApi
|
||
|
|
{
|
||
|
|
#region Identity
|
||
|
|
|
||
|
|
private readonly IEfRepository<AppAnnouncement, long> _appAnnouncementRepository;
|
||
|
|
private readonly IEfRepository<AppAnnouncementViewStatistics, long> _appAnnouncementViewStatisticsRepository;
|
||
|
|
private readonly IHubContext<NonCustodialHub> _hubContext;
|
||
|
|
protected readonly IEfRepository<AppCaseManagement, long> _appCaseManagementRepository;
|
||
|
|
protected readonly IEfRepository<AppCaseSupervisedPerson, long> _appSupervisedPersonRepository;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
///
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="appAnnouncementRepository"></param>
|
||
|
|
/// <param name="appAnnouncementViewStatisticsRepository"></param>
|
||
|
|
/// <param name="hubContext"></param>
|
||
|
|
/// <param name="appCaseManagementRepository"></param>
|
||
|
|
/// <param name="appSupervisedPersonRepository"></param>
|
||
|
|
public AppAnnouncementService(IEfRepository<AppAnnouncement, long> appAnnouncementRepository,
|
||
|
|
IEfRepository<AppAnnouncementViewStatistics, long> appAnnouncementViewStatisticsRepository,
|
||
|
|
IHubContext<NonCustodialHub> hubContext,
|
||
|
|
IEfRepository<AppCaseManagement, long> appCaseManagementRepository,
|
||
|
|
IEfRepository<AppCaseSupervisedPerson, long> appSupervisedPersonRepository)
|
||
|
|
{
|
||
|
|
_appAnnouncementRepository = appAnnouncementRepository;
|
||
|
|
_appAnnouncementViewStatisticsRepository = appAnnouncementViewStatisticsRepository;
|
||
|
|
_hubContext = hubContext;
|
||
|
|
_appCaseManagementRepository = appCaseManagementRepository;
|
||
|
|
_appSupervisedPersonRepository = appSupervisedPersonRepository;
|
||
|
|
}
|
||
|
|
|
||
|
|
#endregion Identity
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 查询公告明细
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="id"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
[AllowAnonymous]
|
||
|
|
public async Task<IResultOutput> Get(long id)
|
||
|
|
{
|
||
|
|
var appAnnouncement = await _appAnnouncementRepository.GetAsync(id);
|
||
|
|
|
||
|
|
var appAnnouncementViewStatistics = await _appAnnouncementViewStatisticsRepository
|
||
|
|
.AsQueryable(false, true)
|
||
|
|
.Where(w => w.AnnouncementId == id)
|
||
|
|
.ToListAsync();
|
||
|
|
|
||
|
|
var rtn = new AppAnnouncementGetDto()
|
||
|
|
{
|
||
|
|
Title = appAnnouncement.Title,
|
||
|
|
Content = appAnnouncement.Content,
|
||
|
|
AnnouncementTypeId = appAnnouncement.AnnouncementTypeId,
|
||
|
|
SupervisedPersonIds = appAnnouncementViewStatistics.Select(w => w.SupervisedPersonId).ToList()
|
||
|
|
};
|
||
|
|
|
||
|
|
//返回结果
|
||
|
|
return ResultOutput.Ok(rtn);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 分页查询
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="input"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
[HttpPost]
|
||
|
|
public async Task<IResultOutput> GetPageAsync(AppAnnouncementPageInput input)
|
||
|
|
{
|
||
|
|
var express = GetExpression(input, _appAnnouncementRepository.AsQueryable(false, true));
|
||
|
|
var rtn = await base.GetPageAsync<AppAnnouncement, AppAnnouncementPageInput, AppAnnouncementListDto>(input, express);
|
||
|
|
return ResultOutput.Ok(rtn);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 创建或者修改通知公告
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="input"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
public async Task<IResultOutput> CreateOrModify(AppAnnouncementCreateOrModifyInput input)
|
||
|
|
{
|
||
|
|
var announceValid = await base.Valid<AppAnnouncement, AppAnnouncementCreateOrModifyInput, long>(input, _appAnnouncementRepository, w =>
|
||
|
|
{
|
||
|
|
w = w.AndNotNull(w => w.Title.Equals(input.Title), input.Title.IsNotNullOrEmpty());
|
||
|
|
|
||
|
|
return (w, $"当前公告类型名字:{input.Title}已存在");
|
||
|
|
});
|
||
|
|
|
||
|
|
if (!announceValid.Success) return announceValid;
|
||
|
|
|
||
|
|
var announcementId = input.Id;
|
||
|
|
|
||
|
|
input.SenderId = User.Id;
|
||
|
|
|
||
|
|
//修改
|
||
|
|
if (input.Id > 0) await base.UpdateAsync(input, _appAnnouncementRepository);
|
||
|
|
else announcementId = (await base.AddWithDataAsync(input, _appAnnouncementRepository))?.Id;
|
||
|
|
|
||
|
|
//处理发送人
|
||
|
|
var personalIds = input.SupervisedPersonDtos!.Where(w => w.SupervisedPersonId > 0).Select(w => w.SupervisedPersonId);
|
||
|
|
|
||
|
|
//查出当前公告发送人在查阅表中
|
||
|
|
var senderIds = (await _appAnnouncementViewStatisticsRepository
|
||
|
|
.AsQueryable(false, true)
|
||
|
|
.Where(w => w.AnnouncementId == input.Id)
|
||
|
|
.ToListAsync())
|
||
|
|
.Select(w => w.SupervisedPersonId);
|
||
|
|
|
||
|
|
//新增的
|
||
|
|
var addIds = personalIds.Except(senderIds);
|
||
|
|
if (addIds.Any())
|
||
|
|
{
|
||
|
|
var spCaseList = await GetCurrentSupervisePersonProcessingCase(addIds);
|
||
|
|
|
||
|
|
var addAnnouncementViews = addIds.Select(spId =>
|
||
|
|
{
|
||
|
|
var currentSpCase = spCaseList.FirstOrDefault(w => w.SupervisedPersonId == spId);
|
||
|
|
return new AppAnnouncementViewStatistics()
|
||
|
|
{
|
||
|
|
AnnouncementId = announcementId!.Value,
|
||
|
|
Title = input.Title,
|
||
|
|
CaseId = currentSpCase?.CaseId,
|
||
|
|
CaseName = currentSpCase?.CaseName,
|
||
|
|
SupervisedPersonId = spId,
|
||
|
|
SupervisedPersonName = input.SupervisedPersonDtos!.FirstOrDefault(w => w.SupervisedPersonId == spId)?.SupervisedPersonName
|
||
|
|
};
|
||
|
|
});
|
||
|
|
|
||
|
|
await _appAnnouncementViewStatisticsRepository.InsertAsync(addAnnouncementViews);
|
||
|
|
}
|
||
|
|
|
||
|
|
//
|
||
|
|
//删除的
|
||
|
|
var removeIds = senderIds.Except(personalIds);
|
||
|
|
if (removeIds.Any()) await _appAnnouncementViewStatisticsRepository.DeleteAsync(w => removeIds.Contains(w.AnnouncementId));
|
||
|
|
|
||
|
|
#region 发送给目标signalR客户端连接对象(到时候app端直接on("NoticeAnnouncementToSupervisedPerson"))即可接收
|
||
|
|
|
||
|
|
var remindLis = _appAnnouncementViewStatisticsRepository
|
||
|
|
.Where(w => w.AnnouncementId == announcementId)
|
||
|
|
.Select(w => new AppRemindListDto()
|
||
|
|
{
|
||
|
|
Id = announcementId!.Value,
|
||
|
|
CreatedTime = w.CheckTime,
|
||
|
|
CreatedUserId = w.CreatedUserId,
|
||
|
|
CreatedUserName = w.CreatedUserName,
|
||
|
|
Title = input.Title,
|
||
|
|
Content = input.Content,
|
||
|
|
CheckStatus = w.CheckStatus,
|
||
|
|
CheckTime = w.CheckTime
|
||
|
|
}).ToList();
|
||
|
|
var receiveIds = input
|
||
|
|
.SupervisedPersonDtos!
|
||
|
|
.Select(w => w.SupervisedPersonId.ToString())
|
||
|
|
.ToList();
|
||
|
|
await _hubContext
|
||
|
|
.Clients
|
||
|
|
.Users(receiveIds)
|
||
|
|
.SendAsync(nameof(NonCustodialHub.NoticeAnnouncementToSupervisedPerson), JsonConvert.SerializeObject(remindLis));
|
||
|
|
|
||
|
|
#endregion 发送给目标signalR客户端连接对象(到时候app端直接on("NoticeAnnouncementToSupervisedPerson"))即可接收
|
||
|
|
|
||
|
|
//返回结果
|
||
|
|
return ResultOutput.Ok();
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 批量修改状态
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="input"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
public async Task<IResultOutput> BatchChangeDictionaryStatus(BatchChangeStatusInput input) => await base.BatchChangeStatus(input, _appAnnouncementRepository);
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 批量删除
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="input"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
[HttpDelete]
|
||
|
|
public async Task<IResultOutput> BatchDeleteAsync(BatchIdsInput input)
|
||
|
|
{
|
||
|
|
if (!input.Ids.Any()) return ResultOutput.NotOk("参数不能为空!");
|
||
|
|
|
||
|
|
await _appAnnouncementRepository.DeleteAsync(w => input.Ids.Contains(w.Id));
|
||
|
|
await _appAnnouncementViewStatisticsRepository.DeleteAsync(w => input.Ids.Contains(w.AnnouncementId));
|
||
|
|
return ResultOutput.Result(true);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 分页查询(公告查阅列表)
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="input"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
public async Task<IResultOutput> ViewStatistics(ViewStatisticsPageInput input)
|
||
|
|
{
|
||
|
|
var data = await _appAnnouncementViewStatisticsRepository
|
||
|
|
.AsQueryable(false, true)
|
||
|
|
.Where(w => w.AnnouncementId == input.Id)
|
||
|
|
.OrderByDescending(r => r.Id)
|
||
|
|
.ProjectTo<AppAnnouncementViewStatisticsListDto>(Mapper.ConfigurationProvider)
|
||
|
|
.PagedAsync(input)
|
||
|
|
.ConfigureAwait(false);
|
||
|
|
|
||
|
|
return ResultOutput.Ok(data);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 业务工作台==>最新5条公告
|
||
|
|
/// </summary>
|
||
|
|
/// <returns></returns>
|
||
|
|
public async Task<IResultOutput> AnnouncementBusinessWorkbench()
|
||
|
|
{
|
||
|
|
var dataList = await _appAnnouncementRepository.AsQueryable(false, true)
|
||
|
|
.OrderByDescending(w => w.CreatedTime)
|
||
|
|
.Skip(0)
|
||
|
|
.Take(5)
|
||
|
|
.ProjectTo<AppAnnouncementListDto>(Mapper.ConfigurationProvider)
|
||
|
|
.ToListAsync();
|
||
|
|
return ResultOutput.Ok(dataList);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 上传文件
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="file"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
public async Task<IResultOutput> UploadFile([FromForm] IFormFile file)
|
||
|
|
{
|
||
|
|
var uploadConfig = LazyGetRequiredService<UploadConfigConfiguration>();
|
||
|
|
|
||
|
|
return await base.CustomizedUpload(file, YitIdHelper.NextId(), uploadConfig.Announcement, null);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 批量设置是否查阅状态
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="input"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
public async Task<IResultOutput> BatchSetCheckStatus(BatchSetCheckStatusInput input)
|
||
|
|
{
|
||
|
|
if (_user?.Id > 0 || !input.AnnouncementIds.Any()) return ResultOutput.Ok();
|
||
|
|
|
||
|
|
//查询记录(根据公告Id和订阅者ID(被监管人Id))
|
||
|
|
var subAnnList = await _appAnnouncementViewStatisticsRepository
|
||
|
|
.Where(w => input.AnnouncementIds.Contains(w.AnnouncementId) && w.SupervisedPersonId == User.Id)
|
||
|
|
.ToListAsync();
|
||
|
|
|
||
|
|
subAnnList.ForEach(item =>
|
||
|
|
{
|
||
|
|
//如果已经是已读了就直接返回
|
||
|
|
if (item.CheckStatus == CheckStatusEnum.Checked) return;
|
||
|
|
|
||
|
|
item!.CheckStatus = input.CheckStatus;
|
||
|
|
|
||
|
|
if (input.CheckStatus == CheckStatusEnum.Checked)
|
||
|
|
{
|
||
|
|
item.CheckTime = DateTime.Now;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
item.CheckTime = null;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
//批量修改
|
||
|
|
await _appAnnouncementViewStatisticsRepository.UpdateAsync(subAnnList);
|
||
|
|
return ResultOutput.Ok();
|
||
|
|
}
|
||
|
|
|
||
|
|
#region Private
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 查询条件
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="pageInput"></param>
|
||
|
|
/// <param name="query"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
private IQueryable<AppAnnouncement> GetExpression(AppAnnouncementPageInput pageInput, IQueryable<AppAnnouncement?> query)
|
||
|
|
{
|
||
|
|
query = query
|
||
|
|
.WhereIf(pageInput.KeyWord.NotNull(), a => a.Title.Contains(pageInput.KeyWord))
|
||
|
|
.WhereIf(pageInput.AnnouncementTypeIds.IsNotNullOrEmpty(), w => pageInput.AnnouncementTypeIds.Contains(w.AnnouncementTypeId))
|
||
|
|
.WhereIf(pageInput.StatusSearch?.Content != null, w => w.DataStatus == pageInput.StatusSearch!.Content);
|
||
|
|
|
||
|
|
var express = base.GetExpression<AppAnnouncement, AppAnnouncementPageInput, long>(pageInput, query);
|
||
|
|
|
||
|
|
return express;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 获取当前被监管人正在进行的案件
|
||
|
|
/// </summary>
|
||
|
|
/// <returns></returns>
|
||
|
|
private async Task<List<SupervisedPersonByUserOutput>> GetCurrentSupervisePersonProcessingCase(IEnumerable<long> spIds)
|
||
|
|
{
|
||
|
|
var caseDto = await (from c in _appCaseManagementRepository.AsQueryable(false, true)
|
||
|
|
join cspr in _appSupervisedPersonRepository.AsQueryable(false, true) on c.Id equals cspr.CaseId
|
||
|
|
where spIds.Contains(cspr.SupervisedPersonId) && c.CaseProgress != CaseProgressEnum.Closed
|
||
|
|
select new SupervisedPersonByUserOutput()
|
||
|
|
{
|
||
|
|
CaseId = c.Id,
|
||
|
|
CaseName = c.Name,
|
||
|
|
SupervisedPersonId = cspr.SupervisedPersonId,
|
||
|
|
SupervisedPersonName = cspr.SupervisedPersonName
|
||
|
|
}).ToListAsync();
|
||
|
|
|
||
|
|
return caseDto.OrderBy(w => w.SupervisedPersonId).ToList();
|
||
|
|
}
|
||
|
|
|
||
|
|
#endregion Private
|
||
|
|
}
|
||
|
|
}
|