@@ -53,7 +53,7 @@ namespace Tnb.WarehouseMgr
/// </summary>
[OverideVisualDev(ModuleConsts.MODULE_WMSMATERIALTRANSFER_ID)]
[ServiceModule(BizTypeId)]
public class WmsMaterialTransferService : BaseWareHouseService
public class WmsMaterialTransferService : BaseWareHouseService , IWmsMaterialTransferService
{
private const string BizTypeId = WmsWareHouseConst . BIZTYPE_WMSMATERIALTRANSFER_ID ;
private readonly ISqlSugarClient _db ;
@@ -1027,7 +1027,7 @@ namespace Tnb.WarehouseMgr
if ( input . wmsDistaskH . task_type = = WmsWareHouseConst . WMS_PRETASK_INSTOCK_TYPE_ID )
{
List < WmsMaterialTransferD > wmsMaterialTransferDs = _db . Queryable < WmsMaterialTransferD > ( )
. Where ( a = > a . bill_id = = wmsMaterialTransferd . bill_id & & a . yxfqty_rk < = a . yzqty_rk ) . ToList ( ) ;
. Where ( a = > a . bill_id = = wmsMaterialTransferd . bill_id & & a . yxfqty_rk < a . yzqty_rk ) . ToList ( ) ;
if ( wmsMaterialTransferDs . Count = = 0 )
{
isOk2 = await _db . Updateable < WmsMaterialTransfer > ( ) . SetColumns ( it = > new WmsMaterialTransfer { status = WmsWareHouseConst . BILLSTATUS_COMPLETE_ID } )
@@ -1038,7 +1038,7 @@ namespace Tnb.WarehouseMgr
else
{
List < WmsMaterialTransferD > wmsMaterialTransferDs = _db . Queryable < WmsMaterialTransferD > ( )
. Where ( a = > a . bill_id = = wmsMaterialTransferd . bill_id & & a . yzqty < = a . qty ) . ToList ( ) ;
. Where ( a = > a . bill_id = = wmsMaterialTransferd . bill_id & & a . yzqty < a . qty ) . ToList ( ) ;
if ( wmsMaterialTransferDs . Count = = 0 )
{
isOk2 = await _db . Updateable < WmsMaterialTransfer > ( ) . SetColumns ( it = > new WmsMaterialTransfer { status = WmsWareHouseConst . BILLSTATUS_COMPLETE_ID } )
@@ -1436,6 +1436,131 @@ namespace Tnb.WarehouseMgr
return await ToApiResult ( HttpStatusCode . OK , "成功" ) ;
}
/// <summary>
/// 中储仓下发到二楼暂存仓(明细下发)
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="AppFriendlyException"></exception>
[HttpPost, NonUnify, AllowAnonymous]
public async Task < Entities . Dto . Outputs . Result > DistributeDetailToZCC ( MaterialTransferDDistributeToZCCInput input )
{
await _s_taskExecuteSemaphore_F1ZCCOutstock . WaitAsync ( ) ;
var db = input . dbConn ;
if ( input . dbConn = = null )
db = _db ;
Logger . LogInformation ( $"中储仓下发到二楼暂存仓" ) ;
try
{
WmsMaterialTransferD wmsMaterialTransferD = db . Queryable < WmsMaterialTransferD > ( ) . Where ( r = > r . id = = input . source_id ) . First ( ) ;
if ( wmsMaterialTransferD = = null )
{
Logger . LogWarning ( $"不存在id为{input.source_id}的转库单明细!" ) ;
throw new AppFriendlyException ( $"不存在id为{input.source_id}的转库单明细!" , 500 ) ;
}
if ( wmsMaterialTransferD . yxfqty + input . xf_qty > wmsMaterialTransferD . qty )
{
Logger . LogWarning ( $@"转库单明细{wmsMaterialTransferD.id},下发数量{input.xf_qty}已超过可转库数量{wmsMaterialTransferD.qty - wmsMaterialTransferD.yxfqty}! " ) ;
throw new AppFriendlyException ( $@"转库单明细{wmsMaterialTransferD.id},下发数量{input.xf_qty}已超过可转库数量{wmsMaterialTransferD.qty - wmsMaterialTransferD.yxfqty}" , 500 ) ;
}
// 转库单载具子表
List < WmsMaterialTransferCarry > wmsMaterialTransferCarrys = new List < WmsMaterialTransferCarry > ( ) ;
// 需要转库数量
decimal? needOut = input . xf_qty ;
//出库取起点,获取所有符合输入的载具规格的载具
OutStockStrategyZCC2Floor2Query OutStockStrategyInput = new ( )
{
warehouse_id = "2" ,
material_id = wmsMaterialTransferD . material_id ,
code_batch = wmsMaterialTransferD . code_batch ,
needOut = needOut ,
material_code = wmsMaterialTransferD . material_code ,
endlocations = new string [ 2 ] { WmsWareHouseConst . ZZCSSX121009 , WmsWareHouseConst . ZZCSSX121010 }
} ;
List < Tuple < WmsCarryH , decimal , BasLocation > > ? carrys = await _wareHouseService . OutStockStrategyZCC2Floor2 ( OutStockStrategyInput ) ;
foreach ( var item in carrys )
{
WmsCarryH wmsCarryH = item . Item1 ;
decimal codeqty = item . Item2 ;
BasLocation endlocation_ssx = item . Item3 ;
// 转库单载具子表
WmsMaterialTransferCarry wmsMaterialTransferCarry = new WmsMaterialTransferCarry ( ) ;
wmsMaterialTransferCarry . bill_id = input . source_id ;
wmsMaterialTransferCarry . carry_id = wmsCarryH . id ;
wmsMaterialTransferCarry . carry_code = wmsCarryH . carry_code ;
wmsMaterialTransferCarry . create_id = input . create_id ;
wmsMaterialTransferCarry . create_time = DateTime . Now ;
wmsMaterialTransferCarry . endlocation_id = endlocation_ssx . id ;
wmsMaterialTransferCarry . endlocation_code = endlocation_ssx . location_code ;
wmsMaterialTransferCarry . startlocation_id = wmsCarryH . location_id ;
wmsMaterialTransferCarry . startlocation_code = wmsCarryH . location_code ;
wmsMaterialTransferCarry . mat_bill_id = wmsMaterialTransferD . id ;
wmsMaterialTransferCarry . qty = codeqty ;
wmsMaterialTransferCarrys . Add ( wmsMaterialTransferCarry ) ;
}
await db . Ado . BeginTranAsync ( ) ;
WmsMaterialTransfer wmsMaterialTransfer = await db . Queryable < WmsMaterialTransfer > ( ) . Where ( r = > r . id = = wmsMaterialTransferD . bill_id ) . FirstAsync ( ) ;
await db . Updateable < WmsMaterialTransfer > ( ) . SetColumns ( r = > new WmsMaterialTransfer
{
status = WmsWareHouseConst . BILLSTATUS_ON_ID ,
carry_count = wmsMaterialTransferCarrys . Count ,
remainbindracknum = wmsMaterialTransferCarrys . Count
} ) . Where ( r = > r . id = = input . source_id ) . ExecuteCommandAsync ( ) ;
Logger . LogInformation ( $"【DistributeToZCC】更新转库单{wmsMaterialTransfer.bill_code}主表的数据" ) ;
await db . Insertable ( wmsMaterialTransferCarrys ) . ExecuteCommandAsync ( ) ;
Logger . LogInformation ( $"【DistributeToZCC】插入转库单{wmsMaterialTransfer.bill_code}载具表的数据" ) ;
foreach ( WmsMaterialTransferCarry wmsMaterialTransferCarry in wmsMaterialTransferCarrys )
{
CommonCreatePretaskInput commonCreatePretaskInput = new CommonCreatePretaskInput ( ) ;
commonCreatePretaskInput . startlocation_id = wmsMaterialTransferCarry . startlocation_id ;
commonCreatePretaskInput . endlocation_id = wmsMaterialTransferCarry . endlocation_id ;
commonCreatePretaskInput . carry_id = wmsMaterialTransferCarry . carry_id ;
commonCreatePretaskInput . carry_code = wmsMaterialTransferCarry . carry_code ;
commonCreatePretaskInput . task_type = WmsWareHouseConst . WMS_PRETASK_OUTSTOCK_TYPE_ID ;
commonCreatePretaskInput . biz_type = WmsWareHouseConst . BIZTYPE_WMSMATERIALTRANSFER_ID ;
commonCreatePretaskInput . source_id = wmsMaterialTransferCarry . mat_bill_id ;
commonCreatePretaskInput . isExcuteMission = false ;
var res = await _wareHouseService . CommonCreatePretask ( commonCreatePretaskInput ) ;
if ( res . code ! = JNPF . Common . Enums . HttpStatusCode . OK )
{
Logger . LogInformation ( $"【DistributeToZCC生成预任务失败 载具 {wmsMaterialTransferCarry.carry_code}" ) ;
throw new AppFriendlyException ( $"生成预任务失败 载具 {wmsMaterialTransferCarry.carry_code}" , 500 ) ;
}
await db . Updateable < WmsMaterialTransferD > ( ) . SetColumns ( r = > r . yxfqty = = r . yxfqty + wmsMaterialTransferCarry . qty ) . Where ( r = > r . id = = wmsMaterialTransferCarry . mat_bill_id ) . ExecuteCommandAsync ( ) ;
}
Logger . LogInformation ( $"转库单{wmsMaterialTransfer.bill_code}预任务{wmsMaterialTransferCarrys.Count}条全部生成成功" ) ;
await db . Ado . CommitTranAsync ( ) ;
}
catch ( Exception ex )
{
await db . Ado . RollbackTranAsync ( ) ;
Logger . LogError ( "【DistributeToZCC】" + ex . Message ) ;
Logger . LogError ( "【DistributeToZCC】" + ex . StackTrace ) ;
return await ToApiResult ( HttpStatusCode . InternalServerError , ex . Message ) ;
}
finally
{
_s_taskExecuteSemaphore_F1ZCCOutstock . Release ( ) ;
InvokeGenPretaskExcute ( ) ;
}
return await ToApiResult ( HttpStatusCode . OK , "成功" ) ;
}
/// <summary>
/// 中储仓退料到原材料仓
/// </summary>