72 lines
2.5 KiB
C#
72 lines
2.5 KiB
C#
|
|
using langguanApi.Extensions.AutoDI;
|
|||
|
|
using langguanApi.Model;
|
|||
|
|
using langguanApi.Model.Entity;
|
|||
|
|
using Mapster;
|
|||
|
|
using MathNet.Numerics.Distributions;
|
|||
|
|
using Npoi.Mapper;
|
|||
|
|
using Org.BouncyCastle.Asn1.IsisMtt.X509;
|
|||
|
|
using System.Linq.Expressions;
|
|||
|
|
|
|||
|
|
namespace langguanApi.Service
|
|||
|
|
{
|
|||
|
|
[ServiceInjection(InjectionType.Transient)]
|
|||
|
|
/// <summary>
|
|||
|
|
/// Ledger service
|
|||
|
|
/// </summary>
|
|||
|
|
public class LedgerService : BaseService<Ledger>
|
|||
|
|
{
|
|||
|
|
public LedgerService(IConfiguration config) : base(config, nameof(Ledger))
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 新增数据
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="input"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public async Task AddLedger(LedgerDTO input)
|
|||
|
|
{
|
|||
|
|
var enity = input.Adapt<Ledger>();
|
|||
|
|
await base.CreateAsync(enity);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 导出数据
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="start"></param>
|
|||
|
|
/// <param name="end"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public async Task<byte[]> Export(DateTime start, DateTime end)
|
|||
|
|
{
|
|||
|
|
Expression<Func<Ledger, bool>> exp = filter =>
|
|||
|
|
filter.CreateDateTime >= start && filter.CreateDateTime <= end && filter.IsDelete == false;
|
|||
|
|
var list = await base.GetListWithExp(exp);
|
|||
|
|
var mapper = new Mapper();
|
|||
|
|
mapper.Map<Ledger>("进场时间", s => s.InTime)
|
|||
|
|
.Map<Ledger>("车牌号", s => s.CarNum)
|
|||
|
|
.Map<Ledger>("车型", s => s.CarModel)
|
|||
|
|
.Map<Ledger>("新能源", s => s.NewCar ? "是" : "否")
|
|||
|
|
.Map<Ledger>("燃油车", s => s.Emissions)
|
|||
|
|
.Map<Ledger>("出厂日间 ", s => s.OutTime)
|
|||
|
|
.Format<Ledger>("yyyy-MM-dd HH:mm:ss", s => s.InTime)
|
|||
|
|
.Format<Ledger>("yyyy-MM-dd HH:mm:ss", s => s.OutTime);
|
|||
|
|
MemoryStream stream = new MemoryStream();
|
|||
|
|
mapper.Save(stream, list.ToList(), sheetName: "sheet1", leaveOpen: true);
|
|||
|
|
return stream.ToArray();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 分页取数据
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="input"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public async Task<object> GetPage(reqpage input)
|
|||
|
|
{
|
|||
|
|
Expression<Func<Ledger, bool>> exp = filter => filter.IsDelete == false;
|
|||
|
|
return await base.GetPager(new ReqPaing()
|
|||
|
|
{
|
|||
|
|
pageSize = input.pageSize,
|
|||
|
|
current = input.current
|
|||
|
|
}, exp);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|