using Furion.DependencyInjection;
using Myshipping.Core.Entity;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Myshipping.Core.Service;
///
/// 通知公告用户
///
public class SysNoticeUserService : ISysNoticeUserService, ITransient
{
private readonly SqlSugarRepository _sysNoticeUserRep; // 通知公告用户表仓储
public SysNoticeUserService(SqlSugarRepository sysNoticeUserRep)
{
_sysNoticeUserRep = sysNoticeUserRep;
}
///
/// 增加
///
///
///
///
///
public async Task Add(long noticeId, List noticeUserIdList, NoticeUserStatus noticeUserStatus)
{
List list = new List();
noticeUserIdList.ForEach(u =>
{
list.Add(new SysNoticeUser
{
NoticeId = noticeId,
UserId = u,
ReadStatus = noticeUserStatus
});
});
await _sysNoticeUserRep.InsertAsync(list);
}
///
/// 更新
///
///
///
///
///
public async Task Update(long noticeId, List noticeUserIdList, NoticeUserStatus noticeUserStatus)
{
await _sysNoticeUserRep.DeleteAsync(u => u.NoticeId == noticeId);
await Add(noticeId, noticeUserIdList, noticeUserStatus);
}
///
/// 获取通知公告用户列表
///
///
///
public async Task> GetNoticeUserListByNoticeId(long noticeId)
{
return await _sysNoticeUserRep.Where(u => u.NoticeId == noticeId).ToListAsync();
}
///
/// 设置通知公告读取状态
///
///
///
///
///
public async Task Read(long noticeId, long userId, NoticeUserStatus status)
{
await _sysNoticeUserRep.UpdateAsync(m => m.NoticeId == noticeId && m.UserId == userId, m => new SysNoticeUser
{
ReadStatus = status,
ReadTime = DateTime.Now
});
}
}