下升降机扫码优化 八工位入库优化 库存报表
This commit is contained in:
@@ -5,10 +5,12 @@ using JNPF.Common.Security;
|
||||
using JNPF.VisualDev;
|
||||
using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SqlSugar;
|
||||
using Tnb.BasicData.Entities;
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
using Tnb.WarehouseMgr.Entities.Dto;
|
||||
using Tnb.WarehouseMgr.Entities.Enums;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
@@ -26,72 +28,125 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
_db = repository.AsSugarClient();
|
||||
_userManager = userManager;
|
||||
OverideFuncs.GetListAsync = GetListAsync;
|
||||
}
|
||||
|
||||
private async Task<dynamic> GetListAsync(VisualDevModelListQueryInput input)
|
||||
|
||||
[HttpPost]
|
||||
public async Task<dynamic> MaterialStock(VisualDevModelListQueryInput input)
|
||||
{
|
||||
var materialCode = "";
|
||||
var supplier_code = "";
|
||||
var code_batch = "";
|
||||
var material_specification = "";
|
||||
if (!input.queryJson.IsNullOrWhiteSpace())
|
||||
{
|
||||
materialCode = JObject.Parse(input.queryJson).Value<string>(nameof(WmsCarryCode.material_code));
|
||||
supplier_code = JObject.Parse(input.queryJson).Value<string>("supplier_code");
|
||||
code_batch = JObject.Parse(input.queryJson).Value<string>(nameof(WmsCarryCode.code_batch));
|
||||
material_specification = JObject.Parse(input.queryJson).Value<string>(nameof(WmsCarryCode.material_specification));
|
||||
}
|
||||
|
||||
List<WmsStockReportH> 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())
|
||||
.WhereIF(!string.IsNullOrEmpty(materialCode), (a, b, c, d, e) => a.material_code.Contains(materialCode))
|
||||
.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();
|
||||
List<WmsCarryCode> carryCodes = await _db.Queryable<WmsCarryCode>().ToListAsync();
|
||||
var storeMap = items.DistinctBy(x => new { x.warehouse_id, x.material_id }).ToDictionary(x => new { x.warehouse_id, x.material_id }, x => x);
|
||||
|
||||
IEnumerable<WmsStockReportH> result = items.GroupBy(g => new { g.warehouse_id, g.material_id }).Select(itGroup =>
|
||||
IEnumerable<WmsStockReportH?> result;
|
||||
if (string.IsNullOrEmpty(supplier_code))
|
||||
{
|
||||
_ = storeMap.TryGetValue(itGroup.Key, out WmsStockReportH? report);
|
||||
WmsStockReportH stockReport = new()
|
||||
List<WmsStockReportH> items = await _db.Queryable<WmsCarryCode>().InnerJoin<WmsCarryH>((a, b) => a.carry_id == b.id)
|
||||
.InnerJoin<BasLocation>((a, b, c) => b.location_id == c.id).InnerJoin<BasWarehouse>((a, b, c, d) => c.wh_id == d.id)
|
||||
.InnerJoin<WmsTempCode>((a, b, c, d, e) => e.barcode == a.barcode)
|
||||
.InnerJoin<BasMaterial>((a, b, c, d, e, f) => f.id == e.material_id)
|
||||
.LeftJoin<WmsPurchaseD>((a, b, c, d, e, f, g) => e.require_id == g.id)
|
||||
.LeftJoin<WmsPurchaseH>((a, b, c, d, e, f, g, h) => h.id == g.bill_id)
|
||||
.WhereIF(!string.IsNullOrEmpty(material_specification), (a, b, c, d, e, f) => f.material_specification.Contains(material_specification))
|
||||
.WhereIF(!string.IsNullOrEmpty(code_batch), (a, b, c, d, e, f) => a.code_batch.Contains(code_batch))
|
||||
.Select((a, b, c, d, e, f, g, h) => new WmsStockReportH
|
||||
{
|
||||
material_code = report?.material_code ?? "",
|
||||
mater_name = report?.mater_name ?? "",
|
||||
existing_stock_qty = itGroup.Sum(d => d.codeqty),
|
||||
max_stock = report?.max_stock ?? 0,
|
||||
safe_stock = report?.safe_stock ?? 0,
|
||||
min_stock = report?.min_stock ?? 0,
|
||||
storage_valid_day = items.Find(t => t.material_id == itGroup.Key.material_id)?.storage_valid_day,
|
||||
early_warn_day = items.Find(t => t.material_id == itGroup.Key.material_id)?.early_warn_day,
|
||||
create_id = _userManager.UserId,
|
||||
create_time = DateTime.Now
|
||||
};
|
||||
if (stockReport.storage_valid_day.HasValue)
|
||||
{
|
||||
decimal expired_warning_qty = 0;
|
||||
foreach (WmsStockReportH? 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;
|
||||
}
|
||||
List<WmsCarryCode> 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;
|
||||
});
|
||||
org_id = e.org_id,
|
||||
warehouse_id = a.warehouse_id,
|
||||
warehouse_code = d.whcode,
|
||||
warehouse_name = d.whname,
|
||||
material_name = f.name,
|
||||
material_specification = f.material_specification,
|
||||
container_no = f.container_no,
|
||||
create_time = a.create_time,
|
||||
create_id = a.create_id,
|
||||
code_batch = a.code_batch,
|
||||
supplier_code = "",
|
||||
supplier_name = "",
|
||||
}, true).ToListAsync();
|
||||
|
||||
List<WmsCarryCode> carryCodes = await _db.Queryable<WmsCarryCode>().ToListAsync();
|
||||
var storeMap = items.DistinctBy(x => new { x.warehouse_id, x.material_id, x.code_batch }).ToDictionary(x => new { x.warehouse_id, x.material_id, x.code_batch }, x => x);
|
||||
|
||||
result = items.GroupBy(g => new { g.warehouse_id, g.material_id, g.code_batch }).Select(itGroup =>
|
||||
{
|
||||
_ = storeMap.TryGetValue(itGroup.Key, out WmsStockReportH? stockReport);
|
||||
|
||||
List<WmsCarryCode> curCarryCodes = carryCodes.FindAll(x => x.warehouse_id == itGroup.Key.warehouse_id && x.material_id == itGroup.Key.material_id
|
||||
&& x.code_batch == itGroup.Key.code_batch);
|
||||
curCarryCodes.ForEach(x =>
|
||||
{
|
||||
stockReport.codeqty += x.codeqty;
|
||||
});
|
||||
|
||||
//stockReport.Details = curCarryCodes.Adapt<List<WmsStockReportCode>>();
|
||||
|
||||
//stockReport.codeqty = 0;
|
||||
//stockReport.Details.ForEach(x =>
|
||||
//{
|
||||
// x.id = SnowflakeIdHelper.NextId();
|
||||
// x.report_id = stockReport.id;
|
||||
// x.warehouse_id = stockReport.warehouse_id;
|
||||
// x.warehouse_code = stockReport.warehouse_code;
|
||||
// x.warehouse_name = stockReport.warehouse_name;
|
||||
// x.material_specification = stockReport.material_specification;
|
||||
// x.container_no = stockReport.container_no;
|
||||
|
||||
// stockReport.codeqty += x.codeqty;
|
||||
//});
|
||||
return stockReport;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
List<WmsStockReportH> items = await _db.Queryable<WmsCarryCode>().InnerJoin<WmsCarryH>((a, b) => a.carry_id == b.id)
|
||||
.InnerJoin<BasLocation>((a, b, c) => b.location_id == c.id).InnerJoin<BasWarehouse>((a, b, c, d) => c.wh_id == d.id)
|
||||
.InnerJoin<WmsTempCode>((a, b, c, d, e) => e.barcode == a.barcode)
|
||||
.InnerJoin<BasMaterial>((a, b, c, d, e, f) => f.id == e.material_id)
|
||||
.LeftJoin<WmsPurchaseD>((a, b, c, d, e, f, g) => e.require_id == g.id)
|
||||
.LeftJoin<WmsPurchaseH>((a, b, c, d, e, f, g, h) => h.id == g.bill_id)
|
||||
.WhereIF(!string.IsNullOrEmpty(material_specification), (a, b, c, d, e, f) => f.material_specification.Contains(material_specification))
|
||||
.WhereIF(!string.IsNullOrEmpty(code_batch), (a, b, c, d, e, f) => a.code_batch.Contains(code_batch))
|
||||
.WhereIF(!string.IsNullOrEmpty(supplier_code), (a, b, c, d, e, f, g, h) => h.supplier_code.Contains(supplier_code))
|
||||
.Select((a, b, c, d, e, f, g, h) => new WmsStockReportH
|
||||
{
|
||||
org_id = e.org_id,
|
||||
warehouse_id = a.warehouse_id,
|
||||
warehouse_code = d.whcode,
|
||||
warehouse_name = d.whname,
|
||||
material_name = f.name,
|
||||
material_specification = f.material_specification,
|
||||
container_no = f.container_no,
|
||||
create_time = a.create_time,
|
||||
create_id = a.create_id,
|
||||
code_batch = a.code_batch,
|
||||
supplier_code = h.supplier_code,
|
||||
supplier_name = h.supplier_name,
|
||||
}, true).ToListAsync();
|
||||
|
||||
List<WmsCarryCode> carryCodes = await _db.Queryable<WmsCarryCode>().ToListAsync();
|
||||
var storeMap = items.DistinctBy(x => new { x.warehouse_id, x.material_id, x.code_batch, x.supplier_code }).ToDictionary(x => new { x.warehouse_id, x.material_id, x.code_batch, x.supplier_code }, x => x);
|
||||
|
||||
result = items.GroupBy(g => new { g.warehouse_id, g.material_id, g.code_batch, g.supplier_code }).Select(itGroup =>
|
||||
{
|
||||
_ = storeMap.TryGetValue(itGroup.Key, out WmsStockReportH? stockReport);
|
||||
|
||||
List<WmsStockReportCode> curCarryCodes = carryCodes.Adapt<List<WmsStockReportCode>>().FindAll(x => x.warehouse_id == itGroup.Key.warehouse_id && x.material_id == itGroup.Key.material_id
|
||||
&& x.code_batch == itGroup.Key.code_batch && x.supplier_code == itGroup.Key.supplier_code);
|
||||
curCarryCodes.ForEach(x =>
|
||||
{
|
||||
stockReport.codeqty += x.codeqty;
|
||||
});
|
||||
return stockReport;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
List<WmsStockReportH> pages = result.Skip((input.currentPage - 1) * input.pageSize).Take(input.pageSize).ToList();
|
||||
SqlSugarPagedList<WmsStockReportH> pagedList = new()
|
||||
|
||||
Reference in New Issue
Block a user