using JNPF.Common.Core.Manager;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.Message.Entitys;
using JNPF.Message.Interfaces.Message;
using JNPF.VisualDev.Entitys;
using JNPF.VisualDev.Entitys.Dto.Dashboard;
using JNPF.WorkFlow.Entitys.Entity;
using JNPF.WorkFlow.Interfaces.Repository;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
namespace JNPF.VisualDev;
///
/// 业务实现:主页显示.
///
[ApiDescriptionSettings(Tag = "VisualDev", Name = "Dashboard", Order = 174)]
[Route("api/visualdev/[controller]")]
public class DashboardService : IDynamicApiController, ITransient
{
private readonly ISqlSugarRepository _emailReceiveRepository;
///
/// 流程任务.
///
private readonly IFlowTaskRepository _flowTaskRepository;
///
/// 系统消息服务.
///
private readonly IMessageService _messageService;
///
/// 用户管理.
///
private readonly IUserManager _userManager;
///
/// 初始化一个类型的新实例.
///
public DashboardService(
ISqlSugarRepository emailReceiveRepository,
IFlowTaskRepository flowTaskRepository,
IMessageService messageService,
IUserManager userManager)
{
_emailReceiveRepository = emailReceiveRepository;
_flowTaskRepository = flowTaskRepository;
_messageService = messageService;
_userManager = userManager;
}
#region Get
///
/// 获取我的待办.
///
[HttpGet("FlowTodoCount")]
public async Task GetFlowTodoCount()
{
int flowCount = await _emailReceiveRepository.AsSugarClient().Queryable().Where(x => x.CreatorUserId == _userManager.UserId && x.DeleteMark == null).CountAsync();
List? waitList = await _flowTaskRepository.GetWaitList();
List? trialList = await _flowTaskRepository.GetTrialList();
return new FlowTodoCountOutput()
{
toBeReviewed = waitList.Count(),
entrust = flowCount,
flowDone = trialList.Count()
};
}
///
/// 获取通知公告.
///
[HttpGet("Notice")]
public async Task GetNotice()
{
List list = await _emailReceiveRepository.AsSugarClient().Queryable((a, b) => new JoinQueryInfos(JoinType.Left, a.Id == b.MessageId))
.Where((a, b) => a.Type == 1 && a.DeleteMark == null && b.UserId == _userManager.UserId)
.Select((a) => new NoticeOutput()
{
id = a.Id,
fullName = a.Title,
creatorTime = a.CreatorTime
}).ToListAsync();
return new { list = list };
}
///
/// 获取待办事项.
///
[HttpGet("FlowTodo")]
public async Task GetFlowTodo()
{
dynamic list = await _flowTaskRepository.GetPortalWaitList();
return new { list = list };
}
///
/// 获取我的待办事项.
///
[HttpGet("MyFlowTodo")]
public async Task GetMyFlowTodo()
{
List list = new List();
(await _flowTaskRepository.GetWaitList()).ForEach(l =>
{
list.Add(new FlowTodoOutput()
{
id = l.Id,
fullName = l.FlowName,
creatorTime = l.CreatorTime
});
});
return new { list = list };
}
///
/// 获取未读邮件.
///
[HttpGet("Email")]
public async Task GetEmail()
{
List? res = (await _emailReceiveRepository.AsQueryable().Where(x => x.Read == 0 && x.CreatorUserId == _userManager.UserId && x.DeleteMark == null)
.OrderBy(x => x.CreatorTime, OrderByType.Desc).ToListAsync()).Adapt>();
return new { list = res };
}
#endregion
}