Notice Module Update
This commit is contained in:
@@ -59,13 +59,13 @@ namespace Ewide.Core
|
||||
/// 发布时间
|
||||
/// </summary>
|
||||
[Comment("发布时间")]
|
||||
public DateTime PublicTime { get; set; }
|
||||
public DateTime? PublicTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 撤回时间
|
||||
/// </summary>
|
||||
[Comment("撤回时间")]
|
||||
public DateTime CancelTime { get; set; }
|
||||
public DateTime? CancelTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 状态(字典 0草稿 1发布 2撤回 3删除)
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Ewide.Core
|
||||
/// </summary>
|
||||
[Table("sys_notice_user")]
|
||||
[Comment("通知公告用户表")]
|
||||
public class SysNoticeUser : IEntity, IEntityTypeBuilder<SysNoticeUser>
|
||||
public class SysNoticeUser : DEntityBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 通知公告Id
|
||||
@@ -31,7 +31,7 @@ namespace Ewide.Core
|
||||
/// 阅读时间
|
||||
/// </summary>
|
||||
[Comment("阅读时间")]
|
||||
public DateTime ReadTime { get; set; }
|
||||
public DateTime? ReadTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 状态(字典 0未读 1已读)
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Ewide.Core.Service
|
||||
/// <summary>
|
||||
/// 发布人Id
|
||||
/// </summary>
|
||||
public long PublicUserId { get; set; }
|
||||
public string PublicUserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 发布人姓名
|
||||
@@ -35,7 +35,7 @@ namespace Ewide.Core.Service
|
||||
/// <summary>
|
||||
/// 发布机构Id
|
||||
/// </summary>
|
||||
public long PublicOrgId { get; set; }
|
||||
public string PublicOrgId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 发布机构名称
|
||||
|
||||
@@ -39,6 +39,6 @@ namespace Ewide.Core.Service
|
||||
/// <summary>
|
||||
/// 阅读时间
|
||||
/// </summary>
|
||||
public DateTime ReadTime { get; set; }
|
||||
public DateTime? ReadTime { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,22 +61,26 @@ namespace Ewide.Core.Service.Notice
|
||||
/// <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 notice = input.Adapt<SysNotice>();
|
||||
var id = System.Guid.NewGuid().ToString().ToLower();
|
||||
notice.Id = id;
|
||||
await UpdatePublicInfo(notice);
|
||||
// 如果是发布,则设置发布时间
|
||||
if (input.Status == (int)NoticeStatus.PUBLIC)
|
||||
notice.PublicTime = DateTime.Now;
|
||||
var newItem = await notice.InsertNowAsync();
|
||||
var newItem = await notice.InsertAsync();
|
||||
|
||||
// 通知到的人
|
||||
var noticeUserIdList = input.NoticeUserIdList;
|
||||
var noticeUserStatus = (int)NoticeUserStatus.UNREAD;
|
||||
await _sysNoticeUserService.Add(newItem.Entity.Id, noticeUserIdList, noticeUserStatus);
|
||||
await _sysNoticeUserService.Add(id, noticeUserIdList, noticeUserStatus);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -161,7 +165,11 @@ namespace Ewide.Core.Service.Notice
|
||||
await _sysNoticeUserService.Read(notice.Id, _userManager.UserId, (int)NoticeUserStatus.READ);
|
||||
return noticeResult;
|
||||
}
|
||||
|
||||
[HttpGet("/sysNotice/detailById")]
|
||||
public async Task<SysNotice> GetNotice(string id)
|
||||
{
|
||||
return await _sysNoticeRep.FirstOrDefaultAsync(u => u.Id == id);
|
||||
}
|
||||
/// <summary>
|
||||
/// 修改通知公告状态
|
||||
/// </summary>
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
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
|
||||
@@ -11,13 +14,17 @@ namespace Ewide.Core.Service.Notice
|
||||
/// <summary>
|
||||
/// 通知公告用户
|
||||
/// </summary>
|
||||
public class SysNoticeUserService : ISysNoticeUserService, ITransient
|
||||
[ApiDescriptionSettings(Name = "NoticeUser", Order = 100)]
|
||||
public class SysNoticeUserService : ISysNoticeUserService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IRepository<SysNoticeUser> _sysNoticeUserRep; // 通知公告用户表仓储
|
||||
|
||||
public SysNoticeUserService(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>
|
||||
@@ -27,20 +34,32 @@ namespace Ewide.Core.Service.Notice
|
||||
/// <param name="noticeUserIdList"></param>
|
||||
/// <param name="noticeUserStatus"></param>
|
||||
/// <returns></returns>
|
||||
public Task Add(string noticeId, List<string> noticeUserIdList, int noticeUserStatus)
|
||||
|
||||
public async Task Add(string noticeId, List<string> noticeUserIdList, int noticeUserStatus)
|
||||
{
|
||||
noticeUserIdList.ForEach(u =>
|
||||
foreach (var u in noticeUserIdList)
|
||||
{
|
||||
new SysNoticeUser
|
||||
await new SysNoticeUser
|
||||
{
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
NoticeId = noticeId,
|
||||
UserId = u,
|
||||
ReadStatus = noticeUserStatus
|
||||
}.InsertAsync();
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
[HttpGet("/NoticeUser/getCount")]
|
||||
public async Task<int> GetCount()
|
||||
{
|
||||
return await _sysNoticeUserRep.Where(u => u.UserId == _userManager.UserId && u.ReadStatus == (int)NoticeUserStatus.UNREAD).CountAsync();
|
||||
}
|
||||
[HttpGet("/NoticeUser/GetNoticeInfo")]
|
||||
public async Task<List<SysNotice>> GetNoticeInfo()
|
||||
{
|
||||
var noticeIdList = await _sysNoticeUserRep.Where(u => u.UserId == _userManager.UserId && u.ReadStatus == (int)NoticeUserStatus.UNREAD).Select(p => p.NoticeId).ToListAsync();
|
||||
|
||||
return await _sysNoticeRep.Where(s => noticeIdList.Contains(s.Id)).ToListAsync();
|
||||
}
|
||||
/// <summary>
|
||||
/// 更新
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user