104 lines
5.4 KiB
C#
104 lines
5.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Dynamic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Filter;
|
|
using JNPF.Common.Security;
|
|
using JNPF.VisualDev;
|
|
using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
|
|
using Mapster;
|
|
using MimeKit.Cryptography;
|
|
using SqlSugar;
|
|
using Tnb.BasicData.Entities;
|
|
using Tnb.WarehouseMgr.Entities;
|
|
using Tnb.WarehouseMgr.Entities.Enums;
|
|
|
|
namespace Tnb.WarehouseMgr
|
|
{
|
|
/// <summary>
|
|
/// 库存报表服务类
|
|
/// </summary>
|
|
[OverideVisualDev(ModuleConsts.MODULE_WMSSTOCKREPORT_ID)]
|
|
public class WmsStockReportService : BaseWareHouseService
|
|
{
|
|
private readonly ISqlSugarClient _db;
|
|
private readonly IUserManager _userManager;
|
|
|
|
public WmsStockReportService(ISqlSugarRepository<WmsCarryCode> repository, IUserManager userManager)
|
|
{
|
|
_db = repository.AsSugarClient();
|
|
_userManager = userManager;
|
|
OverideFuncs.GetListAsync = GetListAsync;
|
|
}
|
|
|
|
private async Task<dynamic> GetListAsync(VisualDevModelListQueryInput input)
|
|
{
|
|
var items = await _db.Queryable<WmsCarryCode>().InnerJoin<BasMaterial>((a, b) => a.material_id == b.id)
|
|
.InnerJoin<BasMaterialSendWarehouse>((a, b, c) => b.id == c.material_id)
|
|
.InnerJoin<WmsCarryH>((a, b, c, d) => a.carry_id == d.id)
|
|
.InnerJoin<BasLocation>((a, b, c, d, e) => d.location_id == e.id)
|
|
.Where((a, b, c, d, e) => e.is_type == ((int)EnumLocationType.存储库位).ToString())
|
|
.Select((a, b, c, d, e) => new WmsStockReportH
|
|
{
|
|
warehouse_id = a.warehouse_id,
|
|
mater_name = b.name,
|
|
create_time = a.create_time,
|
|
create_id = a.create_id,
|
|
}, true)
|
|
.ToListAsync();
|
|
var carryCodes = await _db.Queryable<WmsCarryCode>().ToListAsync();
|
|
var result = items.GroupBy(g => new { g.warehouse_id, g.material_id }).Select(itGroup =>
|
|
{
|
|
WmsStockReportH stockReport = new();
|
|
stockReport.material_code = items.Find(x => x.warehouse_id == itGroup.Key.warehouse_id && x.material_id == itGroup.Key.material_id)?.material_code;
|
|
stockReport.mater_name = items.Find(x => x.warehouse_id == itGroup.Key.warehouse_id && x.material_id == itGroup.Key.material_id)?.mater_name ?? string.Empty;
|
|
stockReport.existing_stock_qty = itGroup.Sum(d => d.codeqty);
|
|
stockReport.max_stock = items.Find(t => t.warehouse_id == itGroup.Key.warehouse_id && t.material_id == itGroup.Key.material_id)?.max_stock;
|
|
stockReport.safe_stock = items.Find(t => t.warehouse_id == itGroup.Key.warehouse_id && t.material_id == itGroup.Key.material_id)?.safe_stock;
|
|
stockReport.min_stock = items.Find(t => t.warehouse_id == itGroup.Key.warehouse_id && t.material_id == itGroup.Key.material_id)?.min_stock;
|
|
stockReport.min_stock = items.Find(t => t.warehouse_id == itGroup.Key.warehouse_id && t.material_id == itGroup.Key.material_id)?.min_stock;
|
|
stockReport.storage_valid_day = items.Find(t => t.material_id == itGroup.Key.material_id)?.storage_valid_day;
|
|
stockReport.early_warn_day = items.Find(t => t.material_id == itGroup.Key.material_id)?.early_warn_day;
|
|
stockReport.create_id = _userManager.UserId;
|
|
stockReport.create_time = DateTime.Now;
|
|
if (stockReport.storage_valid_day.HasValue)
|
|
{
|
|
decimal expired_warning_qty = 0;
|
|
foreach (var item in itGroup)
|
|
{
|
|
if (DateTime.Now.Subtract(item.create_time.Value).TotalDays >= (item.storage_valid_day - item.early_warn_day))
|
|
{
|
|
expired_warning_qty += item.codeqty;
|
|
}
|
|
}
|
|
stockReport.expired_warning_qty = expired_warning_qty;
|
|
}
|
|
var curCarryCodes = carryCodes.FindAll(x => x.warehouse_id == itGroup.Key.warehouse_id && x.material_id == itGroup.Key.material_id);
|
|
stockReport.Details = curCarryCodes.Adapt<List<WmsStockReportCode>>();
|
|
stockReport.Details.ForEach(x =>
|
|
{
|
|
x.id = SnowflakeIdHelper.NextId();
|
|
x.report_id = stockReport.id;
|
|
});
|
|
return stockReport;
|
|
});
|
|
|
|
var pages = result.Skip(input.currentPage * input.pageSize).Take(input.pageSize).ToList();
|
|
SqlSugarPagedList<WmsStockReportH> pagedList = new()
|
|
{
|
|
list = pages,
|
|
pagination = new()
|
|
{
|
|
CurrentPage = input.currentPage,
|
|
PageSize = input.pageSize,
|
|
Total = result.Count()
|
|
}
|
|
};
|
|
return PageResult<WmsStockReportH>.SqlSugarPageResult(pagedList);
|
|
}
|
|
}
|
|
}
|