You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

127 lines
4.3 KiB

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using Win_in.Sfs.Wms.Dashboard.Host.Models;
using Win_in.Sfs.Wms.Store.Application.Contracts;
namespace Win_in.Sfs.Wms.Dashboard.Host.Controllers;
using System.Linq;
using Win_in.Sfs.Basedata.Application.Contracts;
[ApiController]
[Route($"{PdaHostConst.ROOT_ROUTE}asn-time-window")]
public class AsnTimeWindowController : AbpController
{
private readonly ISupplierAsnAppService _supplierAsnApp;
private readonly IPurchaseReceiptNoteAppService _purchaseReceiptNoteApp;
private readonly ISupplierAppService _supplierApp;
public AsnTimeWindowController(ISupplierAsnAppService supplierAsnApp, IPurchaseReceiptNoteAppService purchaseReceiptNoteApp, ISupplierAppService supplierApp)
{
_supplierAsnApp = supplierAsnApp;
_purchaseReceiptNoteApp = purchaseReceiptNoteApp;
_supplierApp = supplierApp;
}
[HttpGet("asn-time-window")]
public virtual async Task<List<AsnTimeWindowDashboardDto>> GetAsnTimeWindowsAsync()
{
return await GetAsnTimeWindowDashboardsAsync().ConfigureAwait(false);
}
private async Task<List<AsnTimeWindowDashboardDto>> GetAsnTimeWindowDashboardsAsync()
{
var supplierAsns = await GetSupplierAsnsAsync().ConfigureAwait(false);
var supplierCodes = supplierAsns.Select(t => t.SupplierCode).Distinct();
var suppliers = await GetSuppliersAsync(supplierCodes).ConfigureAwait(false);
var asnNumbers = supplierAsns.Select(t => t.Number);
var purchaseReceiptNotes = await GetPurchaseReceiptNotesAsync(asnNumbers).ConfigureAwait(false);
return ConvertToAsnTimeWindowDashboards(
supplierAsns,
suppliers,
purchaseReceiptNotes);
}
private static List<AsnTimeWindowDashboardDto> ConvertToAsnTimeWindowDashboards(
List<SupplierAsnDTO> supplierAsns,
List<SupplierDTO> suppliers,
List<PurchaseReceiptNoteDTO> purchaseReceiptNotes)
{
var dtos = new List<AsnTimeWindowDashboardDto>();
for (var i = 0; i <= 23; i++)
{
var timeSpan = $"{i}:00";
foreach (var supplierAsn in supplierAsns)
{
if (supplierAsn.PlanArriveDate.Hour == i)
{
var supplierShortName = string.Empty;
var supplier = suppliers.FirstOrDefault(t => t.Code == supplierAsn.SupplierCode);
if (supplier == null)
{
continue;
}
supplierShortName = supplier.ShortName;
if (dtos.Exists(t => t.TimeSpan == timeSpan && t.SupplierShortName == supplierShortName))
{
continue;
}
var purchaseReceiptNote =
purchaseReceiptNotes.FirstOrDefault(t => t.AsnNumber == supplierAsn.Number);
var dto = new AsnTimeWindowDashboardDto();
dto.SupplierShortName = supplierShortName;
dto.TimeSpan = timeSpan;
dto.PlanArriveDate = supplierAsn.PlanArriveDate;
dto.ReceiptTime = purchaseReceiptNote?.ReceiveTime ?? DateTime.MinValue;
dtos.Add(dto);
}
}
}
return dtos;
}
private async Task<List<SupplierAsnDTO>> GetSupplierAsnsAsync()
{
var startTime = DateTime.Today.AddHours(DashboardConst.AsnReceiptTimeLimitHour);
var endTime = startTime.AddDays(1).AddSeconds(-1);
if (DateTime.Now.Hour < DashboardConst.AsnReceiptTimeLimitHour)
{
startTime.AddDays(-1);
endTime.AddDays(-1);
}
return await _supplierAsnApp.GetByStartTimeEndTimeAsync(startTime, endTime).ConfigureAwait(false);
}
private async Task<List<SupplierDTO>> GetSuppliersAsync(IEnumerable<string> codes)
{
return await _supplierApp.GetByCodesAsync(codes).ConfigureAwait(false);
}
private async Task<List<PurchaseReceiptNoteDTO>> GetPurchaseReceiptNotesAsync(IEnumerable<string> asnNumbers)
{
return await _purchaseReceiptNoteApp.GetListByAsnNumbers(asnNumbers).ConfigureAwait(false);
}
}