106 lines
3.4 KiB
C#
106 lines
3.4 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.OutStock;
|
|
using WMS.Web.Core.Help;
|
|
using WMS.Web.Domain.Entitys;
|
|
using WMS.Web.Domain.Infrastructure;
|
|
using WMS.Web.Repositories.Configuration;
|
|
|
|
namespace WMS.Web.Repositories
|
|
{
|
|
public class OutStockRepositories: IOutStockRepositories
|
|
{
|
|
private readonly IMapper _mapper;
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private readonly RepositoryDbContext _context;
|
|
|
|
|
|
public OutStockRepositories(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<OutStock> Add(OutStock entity, bool isTransaction = true)
|
|
{
|
|
IDbContextTransaction _transaction = null;
|
|
if (isTransaction)
|
|
_transaction = _context.Database.BeginTransaction();
|
|
try
|
|
{
|
|
await _context.OutStock.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<OutStockQueryInfoResponse> list, int total)> GetListAsync(OutStockQueryRequest dto)
|
|
{
|
|
var query = _context.OutStock
|
|
.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 OutStockQueryInfoResponse()
|
|
{
|
|
#region dto组装
|
|
Id = 0,
|
|
Status = "",
|
|
Type = "",
|
|
Creator = "",
|
|
CreateTime=s.CreateTime.DateToStringSeconds(),
|
|
SuccessSync = s.SuccessSync,
|
|
Stock = "",
|
|
SourceBillNo="",
|
|
SaleBillNo = "",
|
|
DeliveryOrg = "",
|
|
ReceiptCustomer = "",
|
|
MaterialName = "",
|
|
MaterialNumber = "",
|
|
Specifications = "",
|
|
Qty=0
|
|
#endregion
|
|
|
|
}).Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync();
|
|
return (list, total);
|
|
}
|
|
}
|
|
}
|