init commit
This commit is contained in:
64
20220330_Vote/Ewide.Core/Service/Notice/Dto/NoticeBase.cs
Normal file
64
20220330_Vote/Ewide.Core/Service/Notice/Dto/NoticeBase.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
|
||||
namespace Ewide.Core.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 通知公告参数
|
||||
/// </summary>
|
||||
public class NoticeBase
|
||||
{
|
||||
/// <summary>
|
||||
/// ID
|
||||
/// </summary>
|
||||
public string Id { set; get; }
|
||||
/// <summary>
|
||||
/// 标题
|
||||
/// </summary>
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 内容
|
||||
/// </summary>
|
||||
public string Content { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 类型(字典 1通知 2公告)
|
||||
/// </summary>
|
||||
public int Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 发布人Id
|
||||
/// </summary>
|
||||
public string PublicUserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 发布人姓名
|
||||
/// </summary>
|
||||
public string PublicUserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 发布机构Id
|
||||
/// </summary>
|
||||
public string PublicOrgId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 发布机构名称
|
||||
/// </summary>
|
||||
public string PublicOrgName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 发布时间
|
||||
/// </summary>
|
||||
public DateTime PublicTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 撤回时间
|
||||
/// </summary>
|
||||
public DateTime CancelTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 状态(字典 0草稿 1发布 2撤回 3删除)
|
||||
/// </summary>
|
||||
public int Status { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ewide.Core.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 系统通知公告详情参数
|
||||
/// </summary>
|
||||
public class NoticeDetailOutput : NoticeBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 通知到的用户Id集合
|
||||
/// </summary>
|
||||
public List<string> NoticeUserIdList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 通知到的用户阅读信息集合
|
||||
/// </summary>
|
||||
public List<NoticeUserRead> NoticeUserReadInfoList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上传文件Id集合
|
||||
/// </summary>
|
||||
public string Attachments { set; get; }
|
||||
}
|
||||
|
||||
public class NoticeUserRead
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户Id
|
||||
/// </summary>
|
||||
public string UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户名称
|
||||
/// </summary>
|
||||
public string UserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 状态(字典 0未读 1已读)
|
||||
/// </summary>
|
||||
public int ReadStatus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 阅读时间
|
||||
/// </summary>
|
||||
public DateTime? ReadTime { get; set; }
|
||||
}
|
||||
}
|
||||
106
20220330_Vote/Ewide.Core/Service/Notice/Dto/NoticeInput.cs
Normal file
106
20220330_Vote/Ewide.Core/Service/Notice/Dto/NoticeInput.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Ewide.Core.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 通知公告参数
|
||||
/// </summary>
|
||||
public class NoticeInput : PageInputBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 标题
|
||||
/// </summary>
|
||||
public virtual string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 内容
|
||||
/// </summary>
|
||||
public virtual string Content { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 类型(字典 1通知 2公告)
|
||||
/// </summary>
|
||||
public virtual int Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 状态(字典 0草稿 1发布 2撤回 3删除)
|
||||
/// </summary>
|
||||
public virtual int Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 通知到的人
|
||||
/// </summary>
|
||||
public virtual List<string> NoticeUserIdList { get; set; }
|
||||
}
|
||||
|
||||
public class AddNoticeInput : NoticeInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 标题
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "标题不能为空")]
|
||||
public override string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 内容
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "内容不能为空")]
|
||||
public override string Content { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 类型(字典 1通知 2公告)
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "类型不能为空")]
|
||||
public override int Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 状态(字典 0草稿 1发布 2撤回 3删除)
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "状态不能为空")]
|
||||
public override int Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 通知到的人
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "通知到的人不能为空")]
|
||||
public override List<string> NoticeUserIdList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上传文件集合
|
||||
/// </summary>
|
||||
public List<string> Attachments { set; get; }
|
||||
}
|
||||
|
||||
public class DeleteNoticeInput
|
||||
{
|
||||
/// <summary>
|
||||
/// Id
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "通知公告Id不能为空")]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateNoticeInput : AddNoticeInput
|
||||
{
|
||||
/// <summary>
|
||||
/// Id
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "通知公告Id不能为空")]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
public class QueryNoticeInput : DeleteNoticeInput
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class ChangeStatusNoticeInput : DeleteNoticeInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 状态(字典 0草稿 1发布 2撤回 3删除)
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "状态不能为空")]
|
||||
public int Status { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
|
||||
namespace Ewide.Core.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 通知公告接收参数
|
||||
/// </summary>
|
||||
public class NoticeReceiveOutput : NoticeBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 阅读状态(字典 0未读 1已读)
|
||||
/// </summary>
|
||||
public int ReadStatus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 阅读时间
|
||||
/// </summary>
|
||||
public DateTime ReadTime { get; set; }
|
||||
|
||||
public string Avatar { get; set; }
|
||||
}
|
||||
}
|
||||
16
20220330_Vote/Ewide.Core/Service/Notice/ISysNoticeService.cs
Normal file
16
20220330_Vote/Ewide.Core/Service/Notice/ISysNoticeService.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Core.Service.Notice
|
||||
{
|
||||
public interface ISysNoticeService
|
||||
{
|
||||
Task AddNotice(AddNoticeInput input);
|
||||
Task ChangeStatus(ChangeStatusNoticeInput input);
|
||||
Task DeleteNotice(DeleteNoticeInput input);
|
||||
Task<NoticeDetailOutput> GetNotice([FromQuery] QueryNoticeInput input);
|
||||
Task<dynamic> QueryNoticePageList([FromQuery] NoticeInput input);
|
||||
Task<dynamic> ReceivedNoticePageList([FromQuery] NoticeInput input);
|
||||
Task UpdateNotice(UpdateNoticeInput input);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Core.Service.Notice
|
||||
{
|
||||
public interface ISysNoticeUserService
|
||||
{
|
||||
Task Add(string noticeId, List<string> noticeUserIdList, int noticeUserStatus);
|
||||
Task<List<SysNoticeUser>> GetNoticeUserListByNoticeId(string noticeId);
|
||||
Task Read(string noticeId, string userId, int status);
|
||||
Task Update(string noticeId, List<string> noticeUserIdList, int noticeUserStatus);
|
||||
}
|
||||
}
|
||||
277
20220330_Vote/Ewide.Core/Service/Notice/SysNoticeService.cs
Normal file
277
20220330_Vote/Ewide.Core/Service/Notice/SysNoticeService.cs
Normal file
@@ -0,0 +1,277 @@
|
||||
using Dapper;
|
||||
using Ewide.Core.Extension;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Furion.FriendlyException;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Core.Service.Notice
|
||||
{
|
||||
/// <summary>
|
||||
/// 通知公告服务
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Name = "Notice", Order = 100)]
|
||||
public class SysNoticeService : ISysNoticeService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IRepository<SysNotice> _sysNoticeRep; // 通知公告表仓储
|
||||
private readonly IRepository<SysNoticeUser> _sysNoticeUserRep; // 通知公告用户表仓储
|
||||
|
||||
private readonly IUserManager _userManager;
|
||||
|
||||
private readonly ISysNoticeUserService _sysNoticeUserService;
|
||||
|
||||
private readonly IDapperRepository _dapperRepository;
|
||||
|
||||
|
||||
public SysNoticeService(IRepository<SysNotice> sysNoticeRep,
|
||||
IRepository<SysNoticeUser> sysNoticeUserRep,
|
||||
IUserManager userManager,
|
||||
ISysNoticeUserService sysNoticeUserService, IDapperRepository dapperRepository)
|
||||
{
|
||||
_sysNoticeRep = sysNoticeRep;
|
||||
_sysNoticeUserRep = sysNoticeUserRep;
|
||||
_userManager = userManager;
|
||||
_sysNoticeUserService = sysNoticeUserService;
|
||||
|
||||
_dapperRepository = dapperRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询通知公告
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/sysNotice/page")]
|
||||
public async Task<dynamic> QueryNoticePageList([FromBody] NoticeInput input)
|
||||
{
|
||||
var searchValue = !string.IsNullOrEmpty(input.SearchValue?.Trim());
|
||||
var notices = await _sysNoticeRep.DetachedEntities
|
||||
.Where(searchValue, u => EF.Functions.Like(u.Title, $"%{input.SearchValue.Trim()}%") ||
|
||||
EF.Functions.Like(u.Content, $"%{input.SearchValue.Trim()}%"))
|
||||
.Where(input.Type > 0, u => u.Type == input.Type)
|
||||
.Where(u => u.Status != (int)NoticeStatus.DELETED)
|
||||
.ToPagedListAsync(input.PageIndex, input.PageSize);
|
||||
return PageDataResult<SysNotice>.PageResult(notices);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加通知公告
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/sysNotice/add")]
|
||||
[UnitOfWork]
|
||||
public async Task AddNotice(AddNoticeInput input)
|
||||
{
|
||||
_sysNoticeRep.EnsureTransaction();
|
||||
if (input.Status != (int)NoticeStatus.DRAFT && input.Status != (int)NoticeStatus.PUBLIC)
|
||||
throw Oops.Oh(ErrorCode.D7000);
|
||||
|
||||
var config = new TypeAdapterConfig().ForType<AddNoticeInput, SysNotice>()
|
||||
.Map(target => target.Attachments, src => String.Join(",", src.Attachments))
|
||||
.Config;
|
||||
var notice = input.Adapt<SysNotice>(config);
|
||||
var id = System.Guid.NewGuid().ToString().ToLower();
|
||||
notice.Id = id;
|
||||
await UpdatePublicInfo(notice);
|
||||
// 如果是发布,则设置发布时间
|
||||
if (input.Status == (int)NoticeStatus.PUBLIC)
|
||||
notice.PublicTime = DateTime.Now;
|
||||
await notice.InsertAsync();
|
||||
|
||||
// 通知到的人
|
||||
var noticeUserIdList = input.NoticeUserIdList;
|
||||
var noticeUserStatus = (int)NoticeUserStatus.UNREAD;
|
||||
await _sysNoticeUserService.Add(id, noticeUserIdList, noticeUserStatus);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除通知公告
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/sysNotice/delete")]
|
||||
public async Task DeleteNotice(DeleteNoticeInput input)
|
||||
{
|
||||
var notice = await _sysNoticeRep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
||||
if (notice.Status != (int)NoticeStatus.DRAFT && notice.Status != (int)NoticeStatus.CANCEL) // 只能删除草稿和撤回的
|
||||
throw Oops.Oh(ErrorCode.D7001);
|
||||
|
||||
//notice.Status = (int)NoticeStatus.DELETED;
|
||||
await notice.DeleteAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新通知公告
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/sysNotice/edit")]
|
||||
public async Task UpdateNotice(UpdateNoticeInput input)
|
||||
{
|
||||
if (input.Status != (int)NoticeStatus.DRAFT && input.Status != (int)NoticeStatus.PUBLIC)
|
||||
throw Oops.Oh(ErrorCode.D7000);
|
||||
|
||||
// 非草稿状态
|
||||
if (input.Status != (int)NoticeStatus.DRAFT)
|
||||
throw Oops.Oh(ErrorCode.D7002);
|
||||
|
||||
var notice = input.Adapt<SysNotice>();
|
||||
if (input.Attachments != null)
|
||||
notice.Attachments = string.Join(",", input.Attachments);
|
||||
if (input.Status == (int)NoticeStatus.PUBLIC)
|
||||
{
|
||||
notice.PublicTime = DateTime.Now;
|
||||
await UpdatePublicInfo(notice);
|
||||
}
|
||||
await notice.UpdateAsync(true);
|
||||
|
||||
// 通知到的人
|
||||
var noticeUserIdList = input.NoticeUserIdList;
|
||||
var noticeUserStatus = (int)NoticeUserStatus.UNREAD;
|
||||
await _sysNoticeUserService.Update(input.Id, noticeUserIdList, noticeUserStatus);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取通知公告详情
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/sysNotice/detail")]
|
||||
public async Task<NoticeDetailOutput> GetNotice([FromQuery] QueryNoticeInput input)
|
||||
{
|
||||
var notice = await _sysNoticeRep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
||||
|
||||
// 获取通知到的用户
|
||||
var noticeUserList = await _sysNoticeUserService.GetNoticeUserListByNoticeId(input.Id);
|
||||
var noticeUserIdList = new List<string>();
|
||||
var noticeUserReadInfoList = new List<NoticeUserRead>();
|
||||
if (noticeUserList != null)
|
||||
{
|
||||
noticeUserList.ForEach(u =>
|
||||
{
|
||||
noticeUserIdList.Add(u.UserId.ToString());
|
||||
var noticeUserRead = new NoticeUserRead
|
||||
{
|
||||
UserId = u.UserId,
|
||||
ReadStatus = u.ReadStatus,
|
||||
ReadTime = u.ReadTime
|
||||
};
|
||||
noticeUserReadInfoList.Add(noticeUserRead);
|
||||
});
|
||||
}
|
||||
var noticeResult = notice.Adapt<NoticeDetailOutput>();
|
||||
if (_userManager.SuperAdmin)
|
||||
{
|
||||
noticeResult.NoticeUserIdList = noticeUserIdList;
|
||||
noticeResult.NoticeUserReadInfoList = noticeUserReadInfoList;
|
||||
}
|
||||
// 如果该条通知公告为已发布,则将当前用户的该条通知公告设置为已读
|
||||
if (notice.Status == (int)NoticeStatus.PUBLIC)
|
||||
await _sysNoticeUserService.Read(notice.Id, _userManager.UserId, (int)NoticeUserStatus.READ);
|
||||
return noticeResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改通知公告状态
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/sysNotice/changeStatus")]
|
||||
public async Task ChangeStatus(ChangeStatusNoticeInput input)
|
||||
{
|
||||
// 状态应为撤回或删除或发布
|
||||
if (input.Status != (int)NoticeStatus.CANCEL && input.Status != (int)NoticeStatus.DELETED && input.Status != (int)NoticeStatus.PUBLIC)
|
||||
throw Oops.Oh(ErrorCode.D7000);
|
||||
|
||||
var notice = await _sysNoticeRep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
||||
notice.Status = input.Status;
|
||||
|
||||
if (input.Status == (int)NoticeStatus.CANCEL)
|
||||
{
|
||||
notice.CancelTime = DateTime.Now;
|
||||
}
|
||||
else if (input.Status == (int)NoticeStatus.PUBLIC)
|
||||
{
|
||||
notice.PublicTime = DateTime.Now;
|
||||
}
|
||||
await notice.UpdateAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取接收的通知公告
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/sysNotice/received")]
|
||||
public async Task<dynamic> ReceivedNoticePageList([FromBody] NoticeInput input)
|
||||
{
|
||||
var sql = @"SELECT
|
||||
SN.*,
|
||||
SU.Avatar,
|
||||
SNU.ReadStatus,
|
||||
SNU.ReadTime
|
||||
FROM sys_notice SN
|
||||
LEFT JOIN sys_notice_user SNU ON SN.Id = SNU.NoticeId
|
||||
LEFT JOIN sys_user SU ON SN.PublicUserId = SU.Id
|
||||
WHERE SNU.UserId = @UserId AND SN.Status = @Status";
|
||||
|
||||
var data = await _dapperRepository.QueryPageDataDynamic(
|
||||
sql,
|
||||
input,
|
||||
new
|
||||
{
|
||||
_userManager.UserId,
|
||||
Status = (int)NoticeStatus.PUBLIC
|
||||
},
|
||||
new[] { "Type", "Title", "ReadStatus" }
|
||||
);
|
||||
|
||||
data.Items = data.Items.Select(p =>
|
||||
{
|
||||
var r = p.Adapt<NoticeReceiveOutput>();
|
||||
var content = Regex.Replace(r.Content, @"<\/?.+?\/?>|[\r\n]", "");
|
||||
r.Content = content.Substring(0, content.Length > 50 ? 50 : content.Length);
|
||||
return r;
|
||||
});
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取接收到的通知公告总数
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/sysNotice/unread")]
|
||||
public async Task<int> GetUnreadCount()
|
||||
{
|
||||
//删除 或者 草稿 未发布 都不让显示
|
||||
var noticeList = await _sysNoticeRep.Where(u => u.Status == (int)NoticeStatus.PUBLIC).Select(s => s.Id).ToListAsync();
|
||||
return await _sysNoticeUserRep.Where(u => u.UserId == _userManager.UserId && noticeList.Contains(u.NoticeId) && u.ReadStatus == (int)NoticeUserStatus.UNREAD).CountAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新发布信息
|
||||
/// </summary>
|
||||
/// <param name="notice"></param>
|
||||
[NonAction]
|
||||
private async Task UpdatePublicInfo(SysNotice notice)
|
||||
{
|
||||
var emp = await _userManager.GetUserEmpInfo(_userManager.UserId);
|
||||
notice.PublicUserId = _userManager.UserId;
|
||||
notice.PublicUserName = _userManager.Name;
|
||||
notice.PublicOrgId = emp.OrgId;
|
||||
notice.PublicOrgName = emp.OrgName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Core.Service.Notice
|
||||
{
|
||||
/// <summary>
|
||||
/// 通知公告用户
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Name = "NoticeUser", Order = 100)]
|
||||
public class SysNoticeUserService : ISysNoticeUserService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IRepository<SysNoticeUser> _sysNoticeUserRep; // 通知公告用户表仓储
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly IRepository<SysNotice> _sysNoticeRep;
|
||||
public SysNoticeUserService(IRepository<SysNoticeUser> sysNoticeUserRep, IUserManager userManager, IRepository<SysNotice> sysNoticeRep)
|
||||
{
|
||||
_sysNoticeUserRep = sysNoticeUserRep;
|
||||
_userManager = userManager;
|
||||
_sysNoticeRep = sysNoticeRep;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加
|
||||
/// </summary>
|
||||
/// <param name="noticeId"></param>
|
||||
/// <param name="noticeUserIdList"></param>
|
||||
/// <param name="noticeUserStatus"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
public async Task Add(string noticeId, List<string> noticeUserIdList, int noticeUserStatus)
|
||||
{
|
||||
foreach (var u in noticeUserIdList)
|
||||
{
|
||||
await new SysNoticeUser
|
||||
{
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
NoticeId = noticeId,
|
||||
UserId = u,
|
||||
ReadStatus = noticeUserStatus
|
||||
}.InsertAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新
|
||||
/// </summary>
|
||||
/// <param name="noticeId"></param>
|
||||
/// <param name="noticeUserIdList"></param>
|
||||
/// <param name="noticeUserStatus"></param>
|
||||
/// <returns></returns>
|
||||
public async Task Update(string noticeId, List<string> noticeUserIdList, int noticeUserStatus)
|
||||
{
|
||||
var noticeUsers = await _sysNoticeUserRep.Where(u => u.NoticeId == noticeId).ToListAsync();
|
||||
noticeUsers.ForEach(u =>
|
||||
{
|
||||
u.Delete();
|
||||
});
|
||||
|
||||
await Add(noticeId, noticeUserIdList, noticeUserStatus);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取通知公告用户列表
|
||||
/// </summary>
|
||||
/// <param name="noticeId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<SysNoticeUser>> GetNoticeUserListByNoticeId(string noticeId)
|
||||
{
|
||||
return await _sysNoticeUserRep.Where(u => u.NoticeId == noticeId).ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置通知公告读取状态
|
||||
/// </summary>
|
||||
/// <param name="noticeId"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="status"></param>
|
||||
/// <returns></returns>
|
||||
public async Task Read(string noticeId, string userId, int status)
|
||||
{
|
||||
var noticeUser = await _sysNoticeUserRep.FirstOrDefaultAsync(u => u.NoticeId == noticeId && u.UserId == userId);
|
||||
if (noticeUser != null)
|
||||
{
|
||||
noticeUser.ReadStatus = status;
|
||||
noticeUser.ReadTime = DateTime.Now;
|
||||
await noticeUser.UpdateAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user