98 lines
3.2 KiB
C#
98 lines
3.2 KiB
C#
using AutoMapper;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Storage;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using WMS.Web.Core.Dto.MoveBoxRecord;
|
|
using WMS.Web.Domain.Entitys;
|
|
using WMS.Web.Domain.Infrastructure;
|
|
using WMS.Web.Repositories.Configuration;
|
|
|
|
namespace WMS.Web.Repositories
|
|
{
|
|
public class MoveBoxRecordRepositories: IMoveBoxRecordRepositories
|
|
{
|
|
private readonly IMapper _mapper;
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private readonly RepositoryDbContext _context;
|
|
|
|
|
|
public MoveBoxRecordRepositories(RepositoryDbContext context, IMapper mapper, IServiceProvider serviceProvider)
|
|
{
|
|
_context = context;
|
|
_mapper = mapper;
|
|
_serviceProvider = serviceProvider;
|
|
}
|
|
/// <summary>
|
|
/// 新增
|
|
/// </summary>
|
|
/// <param name="entity"></param>
|
|
/// <param name="isTransaction"></param>
|
|
/// <returns></returns>
|
|
public async Task<MoveBoxRecord> Add(MoveBoxRecord entity, bool isTransaction = true)
|
|
{
|
|
IDbContextTransaction _transaction = null;
|
|
if (isTransaction)
|
|
_transaction = _context.Database.BeginTransaction();
|
|
try
|
|
{
|
|
await _context.MoveBoxRecord.AddAsync(entity);
|
|
await _context.SaveChangesAsync();
|
|
|
|
//if (string.IsNullOrEmpty(entity.OutSourcFeedNo))
|
|
//{
|
|
// entity.GenerateNo();
|
|
// await _context.SaveChangesAsync();
|
|
//}
|
|
|
|
if (_transaction != null)
|
|
_transaction.Commit();
|
|
return entity;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (_transaction != null)
|
|
_transaction.Rollback();
|
|
return null;
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 列表
|
|
/// </summary>
|
|
/// <param name="dto"></param>
|
|
/// <returns></returns>
|
|
public async Task<(List<MoveBoxRecordQueryInfoResponse> list, int total)> GetListAsync(MoveBoxRecordQueryRequest dto)
|
|
{
|
|
var query = _context.MoveBoxRecord
|
|
.OrderByDescending(o => o.Id)
|
|
.Where(adv => 1 == 1);
|
|
|
|
if (dto.CreateBeginDate != null)
|
|
query = query.Where(w => w.CreateTime >= dto.CreateBeginDate);
|
|
if (dto.CreateEndDate != null)
|
|
query = query.Where(w => w.CreateTime <= dto.CreateEndDate);
|
|
//组装
|
|
int total = await query.CountAsync();
|
|
var list = await query.Select(s => new MoveBoxRecordQueryInfoResponse()
|
|
{
|
|
#region dto组装
|
|
Box = "",
|
|
SrcSubStock = "",
|
|
Specifications = "",
|
|
DestSubStock = "",
|
|
Qty = 0,
|
|
Type = "",
|
|
Creator = "",
|
|
CreateTime = s.CreateTime
|
|
#endregion
|
|
|
|
}).Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync();
|
|
return (list, total);
|
|
}
|
|
}
|
|
}
|