Files
tnb.server/system/Tnb.Systems/System/PrintLogService.cs
2024-04-23 10:16:16 +08:00

106 lines
3.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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;
/// <summary>
/// 打印模板日志
/// 版 本V3.2
/// 版 权引迈信息技术有限公司https://www.jnpfsoft.com
/// 作 者JNPF开发平台组
/// 日 期2021-06-01.
/// </summary>
[ApiDescriptionSettings(Tag = "System", Name = "PrintLog", Order = 200)]
[Route("api/system/[controller]")]
public class PrintLogService : IDynamicApiController, ITransient
{
/// <summary>
/// 服务基础仓储.
/// </summary>
private readonly ISqlSugarRepository<PrintLogEntity> _repository;
/// <summary>
/// 用户管理.
/// </summary>
private readonly IUserManager _userManager;
/// <summary>
/// 初始化一个<see cref="PrintDevService"/>类型的新实例.
/// </summary>
public PrintLogService(
ISqlSugarRepository<PrintLogEntity> repository,
IUserManager userManager)
{
_repository = repository;
_userManager = userManager;
}
#region Get
/// <summary>
/// 列表(分页).
/// </summary>
/// <param name="input">请求参数.</param>
/// <returns></returns>
[HttpGet("{id}")]
public async Task<dynamic> GetList(string id, [FromQuery] PrintLogQuery input)
{
var whereLambda = LinqExpression.And<PrintLogEntity>();
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<UserEntity>().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<PrintLogOutuut>.SqlSugarPageResult(list);
}
#endregion
#region Post
/// <summary>
/// 新增.
/// </summary>
/// <param name="input">请求参数.</param>
/// <returns></returns>
[HttpPost("save")]
public async Task Delete([FromBody] PrintLogOutuut input)
{
var entity = input.Adapt<PrintLogEntity>();
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
}