using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.Common.Extension;
using JNPF.Common.Filter;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using JNPF.LinqBuilder;
using JNPF.Systems.Entitys.Dto.System.PrintLog;
using JNPF.Systems.Entitys.Entity.System;
using JNPF.Systems.Entitys.Permission;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
namespace JNPF.Systems.System;
///
/// 打印模板日志
/// 版 本:V3.2
/// 版 权:引迈信息技术有限公司(https://www.jnpfsoft.com)
/// 作 者:JNPF开发平台组
/// 日 期:2021-06-01.
///
[ApiDescriptionSettings(Tag = "System", Name = "PrintLog", Order = 200)]
[Route("api/system/[controller]")]
public class PrintLogService : IDynamicApiController, ITransient
{
///
/// 服务基础仓储.
///
private readonly ISqlSugarRepository _repository;
///
/// 用户管理.
///
private readonly IUserManager _userManager;
///
/// 初始化一个类型的新实例.
///
public PrintLogService(
ISqlSugarRepository repository,
IUserManager userManager)
{
_repository = repository;
_userManager = userManager;
}
#region Get
///
/// 列表(分页).
///
/// 请求参数.
///
[HttpGet("{id}")]
public async Task GetList(string id, [FromQuery] PrintLogQuery input)
{
var whereLambda = LinqExpression.And();
whereLambda = whereLambda.And(x => x.PrintId == id);
var start = new DateTime();
var end = new DateTime();
if (input.endTime != null && input.startTime != null)
{
start = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd 00:00:00}", input.startTime?.TimeStampToDateTime()));
end = Convert.ToDateTime(string.Format("{0:yyyy-MM-dd 23:59:59}", input.endTime?.TimeStampToDateTime()));
whereLambda = whereLambda.And(x => SqlFunc.Between(x.PrintTime, start, end));
}
if (!string.IsNullOrEmpty(input.keyword))
whereLambda = whereLambda.And(m => m.PrintTitle.Contains(input.keyword));
var list = await _repository.AsQueryable().Where(whereLambda).OrderBy(x => x.PrintTime, OrderByType.Desc)
.Select(a => new PrintLogOutuut
{
id = a.Id,
printId = a.PrintId,
printMan = SqlFunc.Subqueryable().Where(u => u.Id == a.PrintMan).Select(u => SqlFunc.MergeString(u.RealName, "/", u.Account)),
printNum = a.PrintNum,
printTime = a.PrintTime,
printTitle = a.PrintTitle
})
.ToPagedListAsync(input.currentPage, input.pageSize);
return PageResult.SqlSugarPageResult(list);
}
#endregion
#region Post
///
/// 新增.
///
/// 请求参数.
///
[HttpPost("save")]
public async Task Delete([FromBody] PrintLogOutuut input)
{
var entity = input.Adapt();
entity.Id = SnowflakeIdHelper.NextId();
entity.PrintMan = _userManager.UserId;
entity.PrintTime = DateTime.Now;
var isOk = await _repository.AsInsertable(entity).ExecuteCommandAsync();
if (isOk < 1)
throw Oops.Oh(ErrorCode.COM1000);
}
#endregion
}