调整出库任务单结构

This commit is contained in:
18942506660
2023-11-16 11:03:07 +08:00
parent be659f01ad
commit d7b2c9bbb2
12 changed files with 199 additions and 138 deletions

View File

@@ -125,21 +125,16 @@ namespace WMS.Web.Repositories.Configuration
ent.ToTable("t_erp_outstock_task_details");
ent.HasKey(x => x.Id);
ent.Property(f => f.SourceBillNos).HasConversion(
v => JsonConvert.SerializeObject(v),
v => JsonConvert.DeserializeObject<List<string>>(v));
ent.HasMany(p => p.ErpDetails)
.WithOne()
.HasForeignKey(p => p.DetailId)
.OnDelete(DeleteBehavior.Cascade);
});
ent.Property(f => f.SaleBillNos).HasConversion(
v => JsonConvert.SerializeObject(v),
v => JsonConvert.DeserializeObject<List<string>>(v));
ent.Property(f => f.AccruedQty_Dic).HasConversion(
v => JsonConvert.SerializeObject(v),
v => JsonConvert.DeserializeObject<Dictionary<string, decimal>>(v));
ent.Property(f => f.RealityQty_Dic).HasConversion(
v => JsonConvert.SerializeObject(v),
v => JsonConvert.DeserializeObject<Dictionary<string, decimal>>(v));
builder.Entity<OutStockTaskErpDetails>(ent =>
{
ent.ToTable("t_erp_outstock_task_erp_details");
ent.HasKey(x => x.Id);
});
#endregion
@@ -298,6 +293,7 @@ namespace WMS.Web.Repositories.Configuration
public DbSet<TakeStock> TakeStock { get; set; }
public DbSet<OutStockDetails> OutStockDetails { get; set; }
public DbSet<OutStockTaskDetails> OutStockTaskDetails { get; set; }
public DbSet<OutStockTaskErpDetails> OutStockTaskErpDetails { get; set; }
public DbSet<TakeStockDetails> TakeStockDetails { get; set; }
public DbSet<InStock> Instock { get; set; }
public DbSet<InStockDetails> InStockDetails { get; set; }

View File

@@ -188,12 +188,13 @@ namespace WMS.Web.Repositories
try
{
var res = await _context.OutStockTask
.Include(s => s.Details)
.Include(s => s.Details).ThenInclude(s => s.ErpDetails)
.FirstOrDefaultAsync(f => f.Id == entity.Id);
if (res == null) return null;
_mapper.Map(entity, res);
_mapper.ToMapList(entity.Details, res.Details);
_mapper.ToMapList(entity.Details.SelectMany(s => s.ErpDetails).ToList(), res.Details.SelectMany(s => s.ErpDetails).ToList());
await _context.SaveChangesAsync();
if (_transaction != null)
@@ -216,17 +217,13 @@ namespace WMS.Web.Repositories
/// <returns></returns>
public async Task<(List<OutStockTaskQueryInfoResponse> list, int total)> GetListAsync(OutStockTaskQueryRequest dto)
{
List<int> ids = new List<int>();
if (!string.IsNullOrEmpty(dto.SourceBillNo))
ids = await _context.OutStockTaskDetails.FromSqlRaw($"SELECT Id FROM t_erp_outstock_task_details WHERE SourceBillNo like '%{dto.SourceBillNo}%'").Select(s => s.Id).ToListAsync();
#region erp基础资料
List<int> mIds = new List<int>();
var materials_result = await _erpService.BillQueryForMaterial();
if (!materials_result.IsSuccess)
return (new List<OutStockTaskQueryInfoResponse>(), 0);
var materials = materials_result.Data.ToList();
//var materials =new List<ErpMaterialDto>();
//物料集合;模糊查询后的物料集合
if (!string.IsNullOrEmpty(dto.MaterialNumber))
{
@@ -247,7 +244,7 @@ namespace WMS.Web.Repositories
#endregion
var query = _context.OutStockTaskDetails
var query = _context.OutStockTaskDetails.Include(x => x.ErpDetails)
.GroupJoin(_context.OutStockTask, detail => detail.Fid, order => order.Id, (detail, orders) => new { detail, orders })
.SelectMany(x => x.orders.DefaultIfEmpty(), (p, order) => new { p.detail, order })
.OrderByDescending(o => o.order.Id)
@@ -267,8 +264,8 @@ namespace WMS.Web.Repositories
query = query.Where(w => mIds.Contains(w.detail.MaterialId));
if (dto.Ids.Count() > 0)
query = query.Where(w => dto.Ids.Contains(w.detail.Id));
if (ids.Count() != 0)
query = query.Where(w => ids.Contains(w.detail.Id));
if (!string.IsNullOrEmpty(dto.SourceBillNo))
query = query.Where(w => w.detail.ErpDetails.Where(wd => EF.Functions.Like(wd.SourceBillNo, "%" + dto.SourceBillNo + "%")).Select(s => s.DetailId).Contains(w.detail.Id));
if (dto.Type != null)
query = query.Where(w => w.order.Type == (OutStockType)dto.Type);
if (dto.Status != null)
@@ -295,8 +292,8 @@ namespace WMS.Web.Repositories
OutStockBeginTime = s.detail.OutStockBeginTime.DateToStringSeconds(),
OutStockEndTime = s.detail.OutStockEndTime.DateToStringSeconds(),
Stock = _singleDataService.GetSingleData(SingleAction.Stocks, _loginRepositories.CompanyId, s.detail.StockCode),
SourceBillNo = string.Join(",", s.detail.SourceBillNos),
SaleBillNo = string.Join(",", s.detail.SaleBillNos),
SourceBillNo = string.Join(",", s.detail.ErpDetails.Select(s => s.SourceBillNo)),
SaleBillNo = string.Join(",", s.detail.ErpDetails.Select(s => s.SaleBillNo)),
DeliveryOrg = _erpBasicDataExtendService.GetOrgName(orgs, s.order.DeliveryOrgId),
ReceiptCustomer = s.order.Type == OutStockType.Sal
? _erpBasicDataExtendService.GetCustomerName(customers, s.order.ReceiptCustomerId)
@@ -321,13 +318,12 @@ namespace WMS.Web.Repositories
if (!materials_result.IsSuccess)
return new List<GetOutStockTaskByNoResponse>();
var materials = materials_result.Data.ToList();
List<int> ids = new List<int>();
ids = await _context.OutStockTaskDetails.FromSqlRaw($"SELECT Fid FROM t_erp_outstock_task_details WHERE SourceBillNo like '%{billNo}%'").Select(s => s.Id).ToListAsync();
var list = await _context.OutStockTask.Include(x => x.Details)
var list = await _context.OutStockTask.Include(x => x.Details).ThenInclude(s => s.ErpDetails)
.Where(f => (EF.Functions.Like(f.BillNo, "%" + billNo + "%") ||
ids.Contains(f.Id)) &&
f.Details.SelectMany(s => s.ErpDetails).Where(w => EF.Functions.Like(w.SourceBillNo, "%" + billNo + "%")).Any()) &&
(f.Status == OutStockStatus.Part || f.Status == OutStockStatus.Wait))
.OrderByDescending(o => o.Id)
.ToListAsync();
@@ -354,7 +350,7 @@ namespace WMS.Web.Repositories
return new GetOutStockTaskByNoResponse();
var materials = materials_result.Data.ToList();
var entity = await _context.OutStockTask.Include(x => x.Details)
var entity = await _context.OutStockTask.Include(x => x.Details).ThenInclude(s => s.ErpDetails)
.FirstOrDefaultAsync(f => f.BillNo.Equals(billNo) &&
(f.Status == OutStockStatus.Part || f.Status == OutStockStatus.Wait));
@@ -372,26 +368,15 @@ namespace WMS.Web.Repositories
}
/// <summary>
/// 单号搜索
/// 单号精确匹配
/// </summary>
/// <param name="sourceBillNos"></param>
/// <returns></returns>
public async Task<List<OutStockTask>> GetListBySourceBillNo(List<string> sourcebillNos)
{
List<int> ids = new List<int>();
string str=$"SELECT Fid FROM t_erp_outstock_task_details WHERE ";
for (int i=0;i<sourcebillNos.Count();i++)
{
if (i == 0)
str += $" SourceBillNo like '%{sourcebillNos[i]}%'";
else
str += $" or SourceBillNo like '%{sourcebillNos[i]}%'";
}
ids = await _context.OutStockTaskDetails.FromSqlRaw(str).Select(s => s.Id).ToListAsync();
var entitys = await _context.OutStockTask
.Include(s => s.Details)
.Where(w => ids.Contains(w.Id))
.Include(s => s.Details).ThenInclude(s => s.ErpDetails)
.Where(w => w.Details.SelectMany(s => s.ErpDetails).Where(wd => sourcebillNos.Contains(wd.SourceBillNo)).Any())
.OrderByDescending(o => o.Id)
.ToListAsync();
@@ -436,12 +421,9 @@ namespace WMS.Web.Repositories
public async Task<List<string>> GetOutStockTaskNosByNo(string billNo)
{
List<int> ids = new List<int>();
ids = await _context.OutStockTaskDetails.FromSqlRaw($"SELECT Fid FROM t_erp_outstock_task_details WHERE SourceBillNo like '%{billNo}%'").Select(s => s.Id).ToListAsync();
return await _context.OutStockTask.Include(x => x.Details)
return await _context.OutStockTask.Include(x => x.Details).ThenInclude(s => s.ErpDetails)
.Where(f => (EF.Functions.Like(f.BillNo, "%" + billNo + "%") ||
ids.Contains(f.Id)) &&
f.Details.SelectMany(s => s.ErpDetails).Where(w => EF.Functions.Like(w.SourceBillNo, "%" + billNo + "%")).Any()) &&
(f.Status == OutStockStatus.Part || f.Status == OutStockStatus.Wait))
.OrderByDescending(o => o.Id)
.Select(s => s.BillNo)
@@ -458,11 +440,16 @@ namespace WMS.Web.Repositories
{
return await GetListAsync(dto);
}
/// <summary>
/// 根据订单号精确搜索
/// </summary>
/// <param name="billNos"></param>
/// <returns></returns>
public async Task<List<OutStockTask>> GetListByBillNo(List<string> billNos)
{
var entitys = await _context.OutStockTask
.Include(s => s.Details)
.ThenInclude(s => s.ErpDetails)
.Where(w => billNos.Contains(w.BillNo))
.OrderByDescending(o => o.Id)
.ToListAsync();