优化wareHouseService 不分函数,提取冗余不分代码增加代码可读性,维护性

This commit is contained in:
alex
2023-07-06 14:04:00 +08:00
parent c6e46b4ad9
commit 8eb5f3ece2
4 changed files with 45 additions and 46 deletions

View File

@@ -9,7 +9,7 @@ namespace Tnb.WarehouseMgr.Entities;
/// <summary>
/// 入库申请条码表
/// </summary>
public partial class WmsInstockCode
public partial class WmsInstockCode : IInOutStockCode
{
}

View File

@@ -8,7 +8,7 @@ namespace Tnb.WarehouseMgr.Entities;
/// 出库申请条码表
/// </summary>
[SugarTable("wms_outstock_code")]
public partial class WmsOutstockCode : BaseEntity<string>, IInOutStockCode
public partial class WmsOutstockCode : BaseEntity<string>
{
public WmsOutstockCode()
{

View File

@@ -0,0 +1,13 @@
using JNPF.Common.Contracts;
using JNPF.Common.Security;
using SqlSugar;
namespace Tnb.WarehouseMgr.Entities;
/// <summary>
/// 出库申请条码表
/// </summary>
public partial class WmsOutstockCode : IInOutStockCode
{
}

View File

@@ -102,44 +102,34 @@ namespace Tnb.WarehouseMgr
[HttpPost]
public async Task ApplyFor(InOutStockApplyforUpInput input)
{
// bill_line,location_id,delivery_date,carry_id,carry_code
if (input == null) throw new ArgumentNullException("input");
var isOk = false;
switch (input.inoutStockType)
async Task<bool> _updateLocalFunc<TMaster, TSlave>(InOutStockApplyforUpInput input)
where TMaster : BaseEntity<string>, new()
where TSlave : BaseEntity<string>, IInOutStockCode, new()
{
case EnumInOutStockType.In:
var wmsInstockD = input.Adapt<WmsInstockD>();
var wmsInstockCodes = input.InstockCodes?.Adapt<List<WmsInstockCode>>();
if (wmsInstockCodes?.Count > 0)
var instockD = input.Adapt<TMaster>();
var stockCodes = input.InstockCodes?.Adapt<List<TSlave>>();
if (stockCodes?.Count > 0)
{
stockCodes.ForEach(x =>
{
wmsInstockCodes.ForEach(x =>
if (x.id.IsNullOrWhiteSpace())
{
if (x.id.IsNullOrWhiteSpace())
{
x.id = SnowflakeIdHelper.NextId();
}
x.bill_d_id = wmsInstockD.id;
});
}
isOk = await _update(wmsInstockD, wmsInstockCodes!);
break;
case EnumInOutStockType.Out:
var wmsOutstockD = input.Adapt<WmsOutstockD>();
var wmsOutstockCodes = input.InstockCodes?.Adapt<List<WmsOutstockCode>>();
if (wmsOutstockCodes?.Count > 0)
{
wmsOutstockCodes.ForEach(x =>
{
if (x.id.IsNullOrWhiteSpace())
{
x.id = SnowflakeIdHelper.NextId();
}
x.bill_d_id = wmsOutstockD.id;
});
}
isOk = await _update(wmsOutstockD, wmsOutstockCodes!);
break;
x.id = SnowflakeIdHelper.NextId();
}
x.bill_d_id = instockD.id;
});
}
return await _update(instockD, stockCodes!);
}
var isOk = input.inoutStockType switch
{
EnumInOutStockType.In => await _updateLocalFunc<WmsInstockD, WmsInstockCode>(input),
EnumInOutStockType.Out => await _updateLocalFunc<WmsOutstockD, WmsOutstockCode>(input),
_ => throw new ArgumentOutOfRangeException(nameof(input.inoutStockType), $"Not expected EnumInOutStockType value: {input.inoutStockType}"),
};
if (!isOk) throw Oops.Oh(ErrorCode.COM1001);
}
/// <summary>
@@ -166,17 +156,13 @@ namespace Tnb.WarehouseMgr
return data;
}
dynamic? result = null;
switch (input.inoutStockType)
dynamic? result = input.inoutStockType switch
{
case EnumInOutStockType.In:
result = await _fetchInOutStockCodesById<WmsInstockD, InStockDetailOutput, WmsInstockCode>(input.bill_d_id);
break;
case EnumInOutStockType.Out:
result = await _fetchInOutStockCodesById<WmsOutstockD, OutStockDetailOutput, WmsOutstockCode>(input.bill_d_id);
break;
}
return result;
EnumInOutStockType.In => await _fetchInOutStockCodesById<WmsInstockD, InStockDetailOutput, WmsInstockCode>(input.bill_d_id),
EnumInOutStockType.Out => await _fetchInOutStockCodesById<WmsOutstockD, OutStockDetailOutput, WmsOutstockCode>(input.bill_d_id),
_ => throw new ArgumentOutOfRangeException(nameof(input.inoutStockType), $"Not expected EnumInOutStockType value: {input.inoutStockType}"),
};
return result ?? Enumerable.Empty<dynamic>();
}
/// <summary>
/// 入库策略