收货-优化

This commit is contained in:
tongfei
2023-12-01 18:18:23 +08:00
parent c501aa2f8c
commit baf9ec4ec4
16 changed files with 350 additions and 160 deletions

View File

@@ -211,19 +211,24 @@ namespace WMS.Web.Repositories.Configuration
.WithOne()
.HasForeignKey(p => p.Fid)
.OnDelete(DeleteBehavior.Cascade);
ent.HasMany(p => p.Boxs)
.WithOne()
.HasForeignKey(p => p.TaskId)
.OnDelete(DeleteBehavior.Cascade);
});
builder.Entity<InStockTaskDetails>(ent =>
{
ent.ToTable("t_erp_instock_task_details");
ent.HasKey(x => x.Id);
});
builder.Entity<InStockTaskBox>(ent =>
{
ent.ToTable("t_erp_instock_task_box");
ent.HasKey(x => x.Id);
ent.HasMany(p => p.Details)
.WithOne()
.HasForeignKey(p => p.Fid)
.OnDelete(DeleteBehavior.Cascade);
});
builder.Entity<InStockTaskDetails>(ent =>
builder.Entity<InStockTaskBoxDetails>(ent =>
{
ent.ToTable("t_erp_instock_task_details");
ent.ToTable("t_erp_instock_task_box_details");
ent.HasKey(x => x.Id);
});
#endregion
@@ -332,6 +337,7 @@ namespace WMS.Web.Repositories.Configuration
public DbSet<InStockDetails> InStockDetails { get; set; }
public DbSet<InStockTask> InStockTask { get; set; }
public DbSet<InStockTaskBox> InstockTaskBox { get; set; }
public DbSet<InStockTaskBoxDetails> InStockTaskBoxDetails { get; set; }
public DbSet<InStockTaskDetails> InStockTaskDetails { get; set; }
public DbSet<BackRecord> BackRecord { get; set; }
public DbSet<BackRecordDetails> BackRecordDetails { get; set; }

View File

@@ -0,0 +1,104 @@
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.Domain.Entitys;
using WMS.Web.Domain.Infrastructure;
using WMS.Web.Domain.IService.Public;
using WMS.Web.Repositories.Configuration;
namespace WMS.Web.Repositories
{
/// <summary>
/// 箱与任务单绑定(收货)关系表-仓储
/// </summary>
public class InStockTaskBoxRepositories: IInStockTaskBoxRepositories
{
private readonly IMapper _mapper;
private readonly IServiceProvider _serviceProvider;
private readonly RepositoryDbContext _context;
private readonly ISingleDataService _singleDataService;
private readonly IBasicsRepositories _basicsRepositories;
private readonly ILoginRepositories _loginRepositories;
private readonly IErpService _erpService;
private readonly IErpBasicDataExtendService _erpBasicDataExtendService;
public InStockTaskBoxRepositories(RepositoryDbContext context,
IMapper mapper,
IErpService erpService,
IBasicsRepositories basicsRepositories,
IServiceProvider serviceProvider,
ISingleDataService singleDataService,
ILoginRepositories loginRepositories,
IErpBasicDataExtendService erpBasicDataExtendService)
{
_context = context;
_mapper = mapper;
_erpService = erpService;
_basicsRepositories = basicsRepositories;
_serviceProvider = serviceProvider;
_singleDataService = singleDataService;
_loginRepositories = loginRepositories;
_erpBasicDataExtendService = erpBasicDataExtendService;
}
/// <summary>
/// 集合任务ID
/// </summary>
/// <param name="taskId"></param>
/// <returns></returns>
public async Task<List<InStockTaskBox>> GetListBy(int taskId)
{
var entitys = await _context.InstockTaskBox
.Include(s => s.Details).Where(x => x.TaskId == taskId).ToListAsync();
return entitys;
}
/// <summary>
/// 实体箱号ID
/// </summary>
/// <param name="taskId"></param>
/// <returns></returns>
public async Task<InStockTaskBox> GetBy(string boxBillNo)
{
var entity = await _context.InstockTaskBox
.Include(s => s.Details).Where(x => x.BoxBillNo == boxBillNo).FirstOrDefaultAsync();
return entity;
}
/// <summary>
/// 批量添加
/// </summary>
/// <param name="entitys"></param>
/// <param name="isTransaction"></param>
/// <returns></returns>
public async Task<bool> AddRange(List<InStockTaskBox> entitys, bool isTransaction = true)
{
IDbContextTransaction _transaction = null;
if (isTransaction)
_transaction = _context.Database.BeginTransaction();
try
{
if (entitys != null && entitys.Count != 0)
{
await _context.InstockTaskBox.AddRangeAsync(entitys);
await _context.SaveChangesAsync();
}
if (_transaction != null)
_transaction.Commit();
return true;
}
catch
{
if (_transaction != null)
_transaction.Rollback();
return false;
}
}
}
}

View File

@@ -172,28 +172,11 @@ namespace WMS.Web.Repositories
public async Task<InStockTask> Get(int id)
{
var entity = await _context.InStockTask
.Include(x => x.Boxs)
.Include(s => s.Details)
.FirstOrDefaultAsync(f => f.Id == id);
return entity;
}
/// <summary>
/// 实体:根据箱号
/// </summary>
/// <param name="boxBillNo"></param>
/// <returns></returns>
public async Task<InStockTask> GetBy(string boxBillNo)
{
var entity = await _context.InStockTask
.Include(s => s.Boxs.Where(b => b.BoxBillNo == boxBillNo))
.Include(s => s.Details)
.Where(w => w.Boxs.Where(b => b.BoxBillNo == boxBillNo).Count() > 0).FirstOrDefaultAsync();
return entity;
}
/// <summary>
/// 实体:根据来源单号
/// </summary>
@@ -202,7 +185,6 @@ namespace WMS.Web.Repositories
public async Task<InStockTask> GetBySource(string sourceBillNo)
{
var entity = await _context.InStockTask
.Include(s => s.Boxs)
.Include(s => s.Details)
.Where(w => w.SourceBillNo == sourceBillNo).FirstOrDefaultAsync();
@@ -210,20 +192,6 @@ namespace WMS.Web.Repositories
}
/// <summary>
/// 箱号是否绑定了任务实体:待入库和部分入库状态中
/// </summary>
/// <param name="boxBillNo"></param>
/// <returns></returns>
public async Task<bool> IsExist(string boxBillNo)
{
return await _context.InStockTask
.AsNoTracking()
.Include(s => s.Boxs.Where(b => b.BoxBillNo == boxBillNo))
.Include(s => s.Details)
.Where(w => (w.Status == InstockStatus.Part || w.Status == InstockStatus.Wait) && w.Boxs.Where(b => b.BoxBillNo == boxBillNo).Count() > 0).AnyAsync();
}
/// <summary>
/// 列表
/// </summary>
@@ -468,7 +436,7 @@ namespace WMS.Web.Repositories
try
{
List<int> list = entitys.Select(s => s.Id).ToList();
var res = await _context.InStockTask.AsNoTracking().Include(x => x.Boxs).Include(x => x.Details).Where(f => list.Contains(f.Id)).ToListAsync();
var res = await _context.InStockTask.AsNoTracking().Include(x => x.Details).Where(f => list.Contains(f.Id)).ToListAsync();
_mapper.ToMapList(entitys, res);
await _context.SaveChangesAsync();
if (_transaction != null)
@@ -498,15 +466,12 @@ namespace WMS.Web.Repositories
{
var model = await _context.InStockTask
.AsNoTracking()
.Include(s => s.Boxs)
.Include(s => s.Details)
.FirstOrDefaultAsync(f => f.Id == entity.Id);
if (model == null)
return null;
_mapper.Map(entity, model);
//子集单独映射
_mapper.ToMapList(entity.Boxs, model.Boxs);
//子集单独映射
_mapper.ToMapList(entity.Details, model.Details);
await _context.SaveChangesAsync();
if (_transaction != null)