优化详情
This commit is contained in:
@@ -157,195 +157,49 @@ namespace WMS.Web.Repositories
|
||||
|
||||
var entity = await _context.InStockTask.Include(x => x.Details).Where(x => x.Id == id).FirstOrDefaultAsync();
|
||||
|
||||
if (entity != null)
|
||||
if (entity == null)
|
||||
return null;
|
||||
|
||||
var response = new InStockTaskInfoDto()
|
||||
{
|
||||
var response = new InStockTaskInfoDto()
|
||||
{
|
||||
Id = entity.Id,
|
||||
BillNo = entity.BillNo,
|
||||
SaleBillNo = (string.Join(",", entity.Details.Select(x => x.SaleBillNo).ToList()).TrimEnd(',')),
|
||||
SourceBillNo = entity.SourceBillNo,
|
||||
Status = entity.Status.GetRemark(),
|
||||
Type = entity.Type.GetRemark(),
|
||||
Supplier = _erpBasicDataExtendService.GetSupplierName(suppliers, entity.SupplierId ?? 0),
|
||||
Org = _erpBasicDataExtendService.GetOrgName(orgs, entity.OrgCode),
|
||||
CreateTime = entity.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
|
||||
};
|
||||
if (entity.Type == InstockType.Purchase)
|
||||
{
|
||||
//采购任务的箱明细
|
||||
var boxList = await _context.InStockTaskBoxDetails
|
||||
.GroupJoin(_context.InstockTaskBox, boxde => boxde.Fid, ts => ts.Id, (detail, ts) => new { detail, ts })
|
||||
.SelectMany(x => x.ts.DefaultIfEmpty(), (p, box) => new { p.detail, box })
|
||||
.GroupJoin(_context.InStockTaskDetails, p => p.box.TaskDetailId, ts => ts.Id, (p, ts) => new { p.detail, p.box, ts })
|
||||
.SelectMany(x => x.ts.DefaultIfEmpty(), (p, taskDet) => new { p.detail, p.box, taskDet })
|
||||
.Where(x => x.box.TaskId == entity.Id).Select(x => new InStockTaskBoxInfoDto()
|
||||
{
|
||||
BoxId = x.box.BoxId,
|
||||
BoxBillNo = x.box.BoxBillNo,
|
||||
SaleBillNo = x.taskDet.SaleBillNo,
|
||||
Method = InventoryInOutMethod.Box.GetRemark(),
|
||||
MaterialNumber = x.detail.MaterialNumber,
|
||||
Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, x.detail.MaterialNumber),
|
||||
ReceiveTime = x.box.CreateTime.HasValue ? x.box.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : "",
|
||||
Receiver = x.box.ReceiverId.HasValue ? _singleDataService.GetSingleData(SingleAction.Staffs, companyId, x.box.ReceiverId.Value) : "",
|
||||
Qty = x.detail.ReceiveQty,
|
||||
ReceiveQty = x.detail.ReceiveQty,
|
||||
SerialNumbers = x.detail.SerialNumbers != null && x.detail.SerialNumbers.Count() > 0 ? (string.Join(",", x.detail.SerialNumbers).TrimEnd(',')) : "",
|
||||
}).ToListAsync();
|
||||
Id = entity.Id,
|
||||
BillNo = entity.BillNo,
|
||||
SaleBillNo = (string.Join(",", entity.Details.Select(x => x.SaleBillNo).ToList()).TrimEnd(',')),
|
||||
SourceBillNo = entity.SourceBillNo,
|
||||
Status = entity.Status.GetRemark(),
|
||||
Type = entity.Type.GetRemark(),
|
||||
Supplier = _erpBasicDataExtendService.GetSupplierName(suppliers, entity.SupplierId ?? 0),
|
||||
Org = _erpBasicDataExtendService.GetOrgName(orgs, entity.OrgCode),
|
||||
CreateTime = entity.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
|
||||
};
|
||||
var boxList = await _context.InStockDetails
|
||||
.GroupJoin(_context.Instock, det => det.Fid, ts => ts.Id, (detail, ts) => new { detail, ts })
|
||||
.SelectMany(x => x.ts.DefaultIfEmpty(), (p, order) => new { p.detail, order })
|
||||
.GroupJoin(_context.Box, p => p.detail.BoxId, ts => ts.Id, (p, ts) => new { p.detail, p.order, ts })
|
||||
.SelectMany(x => x.ts.DefaultIfEmpty(), (p, box) => new { p.detail, p.order, box })
|
||||
.GroupJoin(_context.InStockTaskDetails, p => p.detail.TaskDetailId, ts => ts.Id, (p, ts) => new { p.detail, p.order, p.box, ts })
|
||||
.SelectMany(x => x.ts.DefaultIfEmpty(), (p, taskDet) => new { p.detail, p.order, p.box, taskDet })
|
||||
.Where(x => x.detail.TaskId == entity.Id).Select(x => new InStockTaskBoxInfoDto()
|
||||
{
|
||||
BoxId = x.box.Id,
|
||||
BoxBillNo = x.box.BoxBillNo,
|
||||
Method = x.order.Method.GetRemark(),
|
||||
MethodForInt = (int)x.order.Method,
|
||||
MaterialNumber = x.detail.MaterialNumber,
|
||||
Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, x.detail.MaterialNumber),
|
||||
SaleBillNo = x.taskDet.SaleBillNo,
|
||||
Qty = x.detail.Qty,
|
||||
RealityQty = x.detail.Qty,
|
||||
ReceiveQty = x.detail.Qty,
|
||||
ShelfTime = x.order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
Shelfer = _singleDataService.GetSingleData(SingleAction.Staffs, companyId, x.order.CreatorId),
|
||||
Receiver = _singleDataService.GetSingleData(SingleAction.Staffs, companyId, x.order.CreatorId),
|
||||
ReceiveTime = x.order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
SerialNumbers = (string.Join(",", x.detail.SerialNumbers).TrimEnd(','))
|
||||
|
||||
if (boxList != null && boxList.Count != 0)
|
||||
{
|
||||
//采购入库明细
|
||||
var boxInstockList_details = await _context.InStockDetails.Where(x => x.TaskId == entity.Id).ToListAsync();
|
||||
|
||||
if (boxInstockList_details != null && boxInstockList_details.Count != 0)
|
||||
{
|
||||
var instockOrder_ids = boxInstockList_details.GroupBy(x => x.Fid).Select(x => x.Key).ToList();
|
||||
var instockOrder = await _context.Instock.Where(x => instockOrder_ids.Contains(x.Id)).ToListAsync();
|
||||
boxList.ForEach(x =>
|
||||
{
|
||||
var currentInstock = boxInstockList_details.Where(t => t.BoxId == x.BoxId && t.MaterialNumber == x.MaterialNumber).FirstOrDefault();
|
||||
if (currentInstock != null)
|
||||
{
|
||||
var order = instockOrder.Where(o => o.Id == currentInstock.Fid).FirstOrDefault();
|
||||
x.RealityQty = currentInstock.Qty;
|
||||
x.Shelfer = _singleDataService.GetSingleData(SingleAction.Staffs, companyId, (order == null ? 0 : order.CreatorId));
|
||||
x.ShelfTime = order == null ? "" : order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
boxList = await _context.InStockDetails
|
||||
.GroupJoin(_context.Instock, det => det.Fid, ts => ts.Id, (detail, ts) => new { detail, ts })
|
||||
.SelectMany(x => x.ts.DefaultIfEmpty(), (p, order) => new { p.detail, order })
|
||||
.GroupJoin(_context.Box, p => p.detail.BoxId, ts => ts.Id, (p, ts) => new { p.detail, p.order, ts })
|
||||
.SelectMany(x => x.ts.DefaultIfEmpty(), (p, box) => new { p.detail, p.order, box })
|
||||
.GroupJoin(_context.InStockTaskDetails, p => p.detail.TaskDetailId, ts => ts.Id, (p, ts) => new { p.detail, p.order, p.box, ts })
|
||||
.SelectMany(x => x.ts.DefaultIfEmpty(), (p, taskDet) => new { p.detail, p.order, p.box, taskDet })
|
||||
.Where(x => x.detail.TaskId == entity.Id).Select(x => new InStockTaskBoxInfoDto()
|
||||
{
|
||||
BoxId = x.box.Id,
|
||||
BoxBillNo = x.box.BoxBillNo,
|
||||
Method = x.order.Method.GetRemark(),
|
||||
MethodForInt = (int)x.order.Method,
|
||||
MaterialNumber = x.detail.MaterialNumber,
|
||||
Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, x.detail.MaterialNumber),
|
||||
SaleBillNo = x.taskDet.SaleBillNo,
|
||||
Qty = 0,
|
||||
RealityQty = x.detail.Qty,
|
||||
ShelfTime = x.order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
Shelfer = _singleDataService.GetSingleData(SingleAction.Staffs, companyId, x.order.CreatorId),
|
||||
ReceiveQty = x.detail.Qty,
|
||||
Receiver = _singleDataService.GetSingleData(SingleAction.Staffs, companyId, x.order.CreatorId),
|
||||
ReceiveTime = x.order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
SerialNumbers = (string.Join(",", x.detail.SerialNumbers).TrimEnd(','))
|
||||
|
||||
}).ToListAsync();
|
||||
if (boxList != null && boxList.Count != 0)
|
||||
{
|
||||
var boxIds = boxList.GroupBy(x => x.BoxId).Select(x => x.Key).ToList();
|
||||
|
||||
var boxdetails = await _context.BoxDetails
|
||||
.GroupJoin(_context.Box, det => det.Fid, ts => ts.Id, (detail, ts) => new { detail, ts })
|
||||
.SelectMany(x => x.ts.DefaultIfEmpty(), (p, box) => new { p.detail, box })
|
||||
.Where(x => boxIds.Contains(x.box.Id)).Select(x => new
|
||||
{
|
||||
BoxId = x.box.Id,
|
||||
MaterialNumber = x.detail.MaterialNumber,
|
||||
Qty = x.detail.Qty
|
||||
}).ToListAsync();
|
||||
|
||||
if (boxdetails != null && boxdetails.Count != 0)
|
||||
{
|
||||
boxList.ForEach(x =>
|
||||
{
|
||||
var method = (InventoryInOutMethod)x.MethodForInt;
|
||||
if (method == InventoryInOutMethod.Box)
|
||||
{
|
||||
var currentBoxDet = boxdetails.Where(t => t.BoxId == x.BoxId && t.MaterialNumber == x.MaterialNumber).FirstOrDefault();
|
||||
if (currentBoxDet != null)
|
||||
{
|
||||
x.Qty = currentBoxDet.Qty;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
response.Boxs = boxList;
|
||||
}
|
||||
else
|
||||
{
|
||||
var boxList = await _context.InStockDetails
|
||||
.GroupJoin(_context.Instock, det => det.Fid, ts => ts.Id, (detail, ts) => new { detail, ts })
|
||||
.SelectMany(x => x.ts.DefaultIfEmpty(), (p, order) => new { p.detail, order })
|
||||
.GroupJoin(_context.Box, p => p.detail.BoxId, ts => ts.Id, (p, ts) => new { p.detail, p.order, ts })
|
||||
.SelectMany(x => x.ts.DefaultIfEmpty(), (p, box) => new { p.detail, p.order, box })
|
||||
.GroupJoin(_context.InStockTaskDetails, p => p.detail.TaskDetailId, ts => ts.Id, (p, ts) => new { p.detail, p.order, p.box, ts })
|
||||
.SelectMany(x => x.ts.DefaultIfEmpty(), (p, taskDet) => new { p.detail, p.order, p.box, taskDet })
|
||||
.Where(x => x.detail.TaskId == entity.Id).Select(x => new InStockTaskBoxInfoDto()
|
||||
{
|
||||
BoxId = x.box.Id,
|
||||
BoxBillNo = x.box.BoxBillNo,
|
||||
Method = x.order.Method.GetRemark(),
|
||||
MethodForInt = (int)x.order.Method,
|
||||
MaterialNumber = x.detail.MaterialNumber,
|
||||
Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, x.detail.MaterialNumber),
|
||||
SaleBillNo = x.taskDet.SaleBillNo,
|
||||
Qty = 0,
|
||||
RealityQty = x.detail.Qty,
|
||||
ShelfTime = x.order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
Shelfer = _singleDataService.GetSingleData(SingleAction.Staffs, companyId, x.order.CreatorId),
|
||||
|
||||
ReceiveQty = x.detail.Qty,
|
||||
Receiver = _singleDataService.GetSingleData(SingleAction.Staffs, companyId, x.order.CreatorId),
|
||||
ReceiveTime = x.order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
|
||||
SerialNumbers = (string.Join(",", x.detail.SerialNumbers).TrimEnd(','))
|
||||
|
||||
}).ToListAsync();
|
||||
|
||||
if (boxList != null && boxList.Count != 0)
|
||||
{
|
||||
var boxIds = boxList.GroupBy(x => x.BoxId).Select(x => x.Key).ToList();
|
||||
|
||||
var boxdetails = await _context.BoxDetails
|
||||
.GroupJoin(_context.Box, det => det.Fid, ts => ts.Id, (detail, ts) => new { detail, ts })
|
||||
.SelectMany(x => x.ts.DefaultIfEmpty(), (p, box) => new { p.detail, box })
|
||||
.Where(x => boxIds.Contains(x.box.Id)).Select(x => new
|
||||
{
|
||||
BoxId = x.box.Id,
|
||||
MaterialNumber = x.detail.MaterialNumber,
|
||||
Qty = x.detail.Qty
|
||||
}).ToListAsync();
|
||||
|
||||
if (boxdetails != null && boxdetails.Count != 0)
|
||||
{
|
||||
boxList.ForEach(x =>
|
||||
{
|
||||
var method = (InventoryInOutMethod)x.MethodForInt;
|
||||
if (method == InventoryInOutMethod.Box)
|
||||
{
|
||||
var currentBoxDet = boxdetails.Where(t => t.BoxId == x.BoxId && t.MaterialNumber == x.MaterialNumber).FirstOrDefault();
|
||||
if (currentBoxDet != null)
|
||||
{
|
||||
x.Qty = currentBoxDet.Qty;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
response.Boxs = boxList;
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
return null;
|
||||
}).ToListAsync();
|
||||
response.Boxs = boxList;
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user