优化wareHouseService 不分函数,提取冗余不分代码增加代码可读性,维护性
This commit is contained in:
@@ -9,7 +9,7 @@ namespace Tnb.WarehouseMgr.Entities;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 入库申请条码表
|
/// 入库申请条码表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class WmsInstockCode
|
public partial class WmsInstockCode : IInOutStockCode
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace Tnb.WarehouseMgr.Entities;
|
|||||||
/// 出库申请条码表
|
/// 出库申请条码表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarTable("wms_outstock_code")]
|
[SugarTable("wms_outstock_code")]
|
||||||
public partial class WmsOutstockCode : BaseEntity<string>, IInOutStockCode
|
public partial class WmsOutstockCode : BaseEntity<string>
|
||||||
{
|
{
|
||||||
public WmsOutstockCode()
|
public WmsOutstockCode()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -102,44 +102,34 @@ namespace Tnb.WarehouseMgr
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task ApplyFor(InOutStockApplyforUpInput input)
|
public async Task ApplyFor(InOutStockApplyforUpInput input)
|
||||||
{
|
{
|
||||||
// bill_line,location_id,delivery_date,carry_id,carry_code
|
|
||||||
if (input == null) throw new ArgumentNullException("input");
|
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 instockD = input.Adapt<TMaster>();
|
||||||
var wmsInstockD = input.Adapt<WmsInstockD>();
|
var stockCodes = input.InstockCodes?.Adapt<List<TSlave>>();
|
||||||
var wmsInstockCodes = input.InstockCodes?.Adapt<List<WmsInstockCode>>();
|
if (stockCodes?.Count > 0)
|
||||||
if (wmsInstockCodes?.Count > 0)
|
{
|
||||||
|
stockCodes.ForEach(x =>
|
||||||
{
|
{
|
||||||
wmsInstockCodes.ForEach(x =>
|
if (x.id.IsNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
if (x.id.IsNullOrWhiteSpace())
|
x.id = SnowflakeIdHelper.NextId();
|
||||||
{
|
}
|
||||||
x.id = SnowflakeIdHelper.NextId();
|
x.bill_d_id = instockD.id;
|
||||||
}
|
});
|
||||||
x.bill_d_id = wmsInstockD.id;
|
}
|
||||||
});
|
return await _update(instockD, stockCodes!);
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
if (!isOk) throw Oops.Oh(ErrorCode.COM1001);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -166,17 +156,13 @@ namespace Tnb.WarehouseMgr
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
dynamic? result = null;
|
dynamic? result = input.inoutStockType switch
|
||||||
switch (input.inoutStockType)
|
|
||||||
{
|
{
|
||||||
case EnumInOutStockType.In:
|
EnumInOutStockType.In => await _fetchInOutStockCodesById<WmsInstockD, InStockDetailOutput, WmsInstockCode>(input.bill_d_id),
|
||||||
result = await _fetchInOutStockCodesById<WmsInstockD, InStockDetailOutput, WmsInstockCode>(input.bill_d_id);
|
EnumInOutStockType.Out => await _fetchInOutStockCodesById<WmsOutstockD, OutStockDetailOutput, WmsOutstockCode>(input.bill_d_id),
|
||||||
break;
|
_ => throw new ArgumentOutOfRangeException(nameof(input.inoutStockType), $"Not expected EnumInOutStockType value: {input.inoutStockType}"),
|
||||||
case EnumInOutStockType.Out:
|
};
|
||||||
result = await _fetchInOutStockCodesById<WmsOutstockD, OutStockDetailOutput, WmsOutstockCode>(input.bill_d_id);
|
return result ?? Enumerable.Empty<dynamic>();
|
||||||
break;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 入库策略
|
/// 入库策略
|
||||||
|
|||||||
Reference in New Issue
Block a user