原材料/成品调拨出库接口、采购收货添加是否赠品、单价、是否自制字段
This commit is contained in:
@@ -258,10 +258,18 @@
|
||||
/// </summary>
|
||||
public const string BIZTYPE_WMSEMPTYINSTOCK_ID = "26121986416677";
|
||||
/// <summary>
|
||||
/// 预任务生成业务类型-签收回库 todo
|
||||
/// </summary>
|
||||
public const string BIZTYPE_WmsMaterialSign_ID = "BIZTYPE_WmsMaterialSign_ID";
|
||||
/// <summary>
|
||||
/// 预任务生成业务类型-载具移入
|
||||
/// </summary>
|
||||
public const string BIZTYPE_CARRYMOVEINSTOCK_ID = "26121988909861";
|
||||
/// <summary>
|
||||
/// 预任务生成业务类型-成品调拨出库 todo
|
||||
/// </summary>
|
||||
public const string BIZTYPE_WmsTransferOutstock_ID = "BIZTYPE_WmsTransferOutstock_ID";
|
||||
/// <summary>
|
||||
/// 预任务生成业务类型-库内转移
|
||||
/// </summary>
|
||||
public const string BIZTYPE_WMSTRANSFER_ID = "26125644258853";
|
||||
@@ -310,6 +318,10 @@
|
||||
/// </summary>
|
||||
public const string BIZTYPE_WMSMATERIALTRANSFER_ID = "34354738929685";
|
||||
/// <summary>
|
||||
/// 预任务生成业务类型-调拨出库单(原材料)
|
||||
/// </summary>
|
||||
public const string BIZTYPE_WmsRawmatTransferoutstock_ID = "BIZTYPE_WmsRawmatTransferoutstock_ID";
|
||||
/// <summary>
|
||||
/// 预任务生成业务类型-生产退料单 todo
|
||||
/// </summary>
|
||||
public const string BIZTYPE_PRDRETURN_ID = "BIZTYPE_PRDRETURN_ID";
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Transactions;
|
||||
|
||||
namespace Tnb.WarehouseMgr.Entities.Dto.ErpInputs
|
||||
{
|
||||
@@ -43,6 +44,12 @@ namespace Tnb.WarehouseMgr.Entities.Dto.ErpInputs
|
||||
/// </summary>
|
||||
public string? erp_pk { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 交易类型
|
||||
/// </summary>
|
||||
public string? transaction_type { get; set; }
|
||||
|
||||
|
||||
public List<TransferOrderInputDetail> details { get; set; }
|
||||
}
|
||||
public class TransferOrderInputDetail
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace Tnb.WarehouseMgr.Entities.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// 库房业务更新输入参数
|
||||
/// </summary>
|
||||
public class CarryMaterialInventoryInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 仓库编码
|
||||
/// </summary>
|
||||
public string? warehouse_code { get; set; }
|
||||
/// <summary>
|
||||
/// 物料id
|
||||
/// </summary>
|
||||
public string? material_id { get; set; }
|
||||
/// <summary>
|
||||
/// 批次
|
||||
/// </summary>
|
||||
public string? code_batch { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using Tnb.WarehouseMgr.Entities.Consts;
|
||||
|
||||
namespace Tnb.WarehouseMgr.Entities.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// 库房业务更新输入参数
|
||||
/// </summary>
|
||||
public class RawmatTransferoutstockInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 组织ID
|
||||
/// </summary>
|
||||
public string org_id { get; set; } = WmsWareHouseConst.AdministratorOrgId;
|
||||
/// <summary>
|
||||
/// 创建用户
|
||||
/// </summary>
|
||||
public string create_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 来源单据id
|
||||
/// </summary>
|
||||
public string? source_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 载具
|
||||
/// </summary>
|
||||
public List<string> carrys { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace Tnb.WarehouseMgr.Entities.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// 库房业务更新输入参数
|
||||
/// </summary>
|
||||
public class WmsTransferOutstockInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 组织ID
|
||||
/// </summary>
|
||||
public string org_id { get; set; }
|
||||
/// <summary>
|
||||
/// 创建用户
|
||||
/// </summary>
|
||||
public string create_id { get; set; }
|
||||
/// <summary>
|
||||
/// 物料数量
|
||||
/// </summary>
|
||||
public decimal qty { get; set; }
|
||||
/// 来源单据id
|
||||
/// </summary>
|
||||
public string? source_id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -123,4 +123,14 @@ public partial class WmsPurchaseD : BaseEntity<string>
|
||||
/// 已绑定数量
|
||||
/// </summary>
|
||||
public decimal? bind_qty { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 单价
|
||||
/// </summary>
|
||||
public decimal? price { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否赠品
|
||||
/// </summary>
|
||||
public int? gift { get; set; }
|
||||
}
|
||||
|
||||
@@ -159,4 +159,9 @@ public partial class WmsPurchaseH : BaseEntity<string>, IPurchaseAndSaleAuitEnti
|
||||
/// erp到货单主表pk
|
||||
/// </summary>
|
||||
public string erp_arriveorder_pk { get;set; }
|
||||
|
||||
/// <summary>
|
||||
/// 来源
|
||||
/// </summary>
|
||||
public string create_origin { get; set; }
|
||||
}
|
||||
|
||||
@@ -79,4 +79,9 @@ public partial class WmsTransferOrderH : BaseEntity<string>
|
||||
/// </summary>
|
||||
public string? biller { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 交易类型
|
||||
/// </summary>
|
||||
public string? transaction_type { get; set; }
|
||||
|
||||
}
|
||||
|
||||
@@ -108,6 +108,13 @@ namespace Tnb.WarehouseMgr.Interfaces
|
||||
/// <returns></returns>
|
||||
string[] GetFloor1GLSGWOutstockLocation();
|
||||
|
||||
/// <summary>
|
||||
/// 是否为原材料调拨出库库位
|
||||
/// </summary>
|
||||
/// <param name="location_id"></param>
|
||||
/// <returns></returns>
|
||||
string[] GetFloor1YCLDBOutstockLocation();
|
||||
|
||||
/// <summary>
|
||||
/// 是否为外协三工位库位
|
||||
/// </summary>
|
||||
|
||||
@@ -1001,8 +1001,19 @@ namespace Tnb.WarehouseMgr
|
||||
wmsTransferOrderH.create_id = WmsWareHouseConst.ErpUserId;
|
||||
wmsTransferOrderH.create_time = DateTime.Now;
|
||||
wmsTransferOrderH.org_id = WmsWareHouseConst.AdministratorOrgId;
|
||||
await db.Insertable(wmsTransferOrderH).ExecuteCommandAsync();
|
||||
|
||||
var _erpExtendField = await db.Queryable<ErpExtendField>().InnerJoin<DictionaryDataEntity>((a, b) => a.table_id == b.Id)
|
||||
.Where((a, b) => a.transaction_type_id == input.transaction_type).Select((a, b) => b).FirstAsync();
|
||||
if (_erpExtendField != null)
|
||||
{
|
||||
wmsTransferOrderH.transaction_type = _erpExtendField.EnCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【TransferOrder】表头交易类型{input.transaction_type}在wms系统中未找到!");
|
||||
throw new AppFriendlyException($@"表头交易类型{input.transaction_type}在wms系统中未找到!", 500);
|
||||
}
|
||||
await db.Insertable(wmsTransferOrderH).ExecuteCommandAsync();
|
||||
|
||||
List<WmsTransferOrderD> wmsTransferOrderDs = new List<WmsTransferOrderD>();
|
||||
foreach (var detail in input.details)
|
||||
@@ -1047,7 +1058,7 @@ namespace Tnb.WarehouseMgr
|
||||
if (warehouse_outstock.id == WmsWareHouseConst.WAREHOUSE_YCL_ID)
|
||||
{
|
||||
WmsRawmatTransferoutstockH wmsRawmatTransferoutstockH = new WmsRawmatTransferoutstockH();
|
||||
string code = await _billRuleService.GetBillNumber("WmsRawmatTransferoutstockH");
|
||||
string code = await _billRuleService.GetBillNumber("RawmatTransferoutstock");
|
||||
wmsRawmatTransferoutstockH.bill_code = code;
|
||||
wmsRawmatTransferoutstockH.create_id = WmsWareHouseConst.ErpUserId;
|
||||
wmsRawmatTransferoutstockH.create_time = DateTime.Now;
|
||||
@@ -1056,6 +1067,9 @@ namespace Tnb.WarehouseMgr
|
||||
wmsRawmatTransferoutstockH.warehouse_code = warehouse_outstock.whcode;
|
||||
wmsRawmatTransferoutstockH.erp_pk = input.erp_pk;
|
||||
wmsRawmatTransferoutstockH.transfer_order_id = wmsTransferOrderH.bill_code;
|
||||
wmsRawmatTransferoutstockH.issuance_status = "0";
|
||||
wmsRawmatTransferoutstockH.transaction_type = _erpExtendField.EnCode;
|
||||
wmsRawmatTransferoutstockH.org_id = WmsWareHouseConst.AdministratorOrgId;
|
||||
List<WmsRawmatTransferoutstockD> wmsRawmatTransferoutstockDs = new List <WmsRawmatTransferoutstockD>();
|
||||
foreach (var detail in input.details)
|
||||
{
|
||||
@@ -1073,13 +1087,13 @@ namespace Tnb.WarehouseMgr
|
||||
throw new AppFriendlyException($@"表体明细中单位{detail.unit_code}在wms系统中未找到!", 500);
|
||||
}
|
||||
|
||||
|
||||
wmsRawmatTransferoutstockD.qty = detail.qty;
|
||||
wmsRawmatTransferoutstockD.code_batch = detail.code_batch;
|
||||
wmsRawmatTransferoutstockD.erp_line_pk = detail.erp_line_pk;
|
||||
wmsRawmatTransferoutstockD.create_id = WmsWareHouseConst.ErpUserId;
|
||||
wmsRawmatTransferoutstockD.create_time = DateTime.Now;
|
||||
wmsRawmatTransferoutstockD.lineno = detail.lineno;
|
||||
wmsRawmatTransferoutstockD.actual_qty = 0;
|
||||
|
||||
var material = await db.Queryable<BasMaterial>().Where(p => p.code == detail.material_code).FirstAsync();
|
||||
if (material != null)
|
||||
@@ -1098,15 +1112,53 @@ namespace Tnb.WarehouseMgr
|
||||
else if(warehouse_outstock.id == WmsWareHouseConst.WAREHOUSE_CP_ID)
|
||||
{
|
||||
WmsTransferOutstockH wmsTransferOutstockH = new WmsTransferOutstockH();
|
||||
string code = await _billRuleService.GetBillNumber("WmsTransferOutstockH");
|
||||
string code = await _billRuleService.GetBillNumber("WmsTransferOutstock");
|
||||
wmsTransferOutstockH.bill_code = code;
|
||||
wmsTransferOutstockH.create_id = WmsWareHouseConst.ErpUserId;
|
||||
wmsTransferOutstockH.create_time = DateTime.Now;
|
||||
wmsTransferOutstockH.warehouse_code = warehouse_outstock.whcode;
|
||||
wmsTransferOutstockH.erp_pk = input.erp_pk;
|
||||
wmsTransferOutstockH.transfer_order_id = wmsTransferOrderH.bill_code;
|
||||
wmsTransferOutstockH.issuance_status = "0";
|
||||
wmsTransferOutstockH.transaction_type = _erpExtendField.EnCode;
|
||||
wmsTransferOutstockH.org_id = WmsWareHouseConst.AdministratorOrgId;
|
||||
List<WmsTransferOutstockD> wmsTransferOutstockDs = new List<WmsTransferOutstockD>();
|
||||
foreach (var detail in input.details)
|
||||
{
|
||||
WmsTransferOutstockD wmsTransferOutstockD = new WmsTransferOutstockD();
|
||||
wmsTransferOutstockD.bill_id = wmsTransferOutstockH.id;
|
||||
var erpExtendField = await db.Queryable<ErpExtendField>().InnerJoin<DictionaryDataEntity>((a, b) => a.table_id == b.Id).Where((a, b) => a.cunitid == detail.unit_code).Select((a, b) => b).FirstAsync();
|
||||
if (erpExtendField != null)
|
||||
{
|
||||
wmsTransferOutstockD.unit_id = erpExtendField.Id;
|
||||
wmsTransferOutstockD.unit_code = erpExtendField.EnCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
_LoggerErp2Mes.LogWarning($@"【TransferOrder】表体明细中单位{detail.unit_code}在wms系统中未找到!");
|
||||
throw new AppFriendlyException($@"表体明细中单位{detail.unit_code}在wms系统中未找到!", 500);
|
||||
}
|
||||
|
||||
|
||||
wmsTransferOutstockD.pr_qty = detail.qty;
|
||||
wmsTransferOutstockD.xf_qty = 0;
|
||||
wmsTransferOutstockD.qty = 0;
|
||||
wmsTransferOutstockD.pi_code = detail.code_batch;
|
||||
wmsTransferOutstockD.erp_line_pk = detail.erp_line_pk;
|
||||
wmsTransferOutstockD.create_id = WmsWareHouseConst.ErpUserId;
|
||||
wmsTransferOutstockD.create_time = DateTime.Now;
|
||||
wmsTransferOutstockD.lineno = detail.lineno;
|
||||
|
||||
var material = await db.Queryable<BasMaterial>().Where(p => p.code == detail.material_code).FirstAsync();
|
||||
if (material != null)
|
||||
{
|
||||
wmsTransferOutstockD.material_id = material.id;
|
||||
wmsTransferOutstockD.material_code = material.code;
|
||||
wmsTransferOutstockD.material_desc = material.material_specification;
|
||||
}
|
||||
|
||||
wmsTransferOutstockDs.Add(wmsTransferOutstockD);
|
||||
}
|
||||
await db.Insertable(wmsTransferOutstockH).ExecuteCommandAsync();
|
||||
await db.Insertable(wmsTransferOutstockDs).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
@@ -395,6 +395,18 @@ namespace Tnb.WarehouseMgr
|
||||
, WmsWareHouseConst.Floor1GLSGWOutstockStation3, WmsWareHouseConst.Floor1GLSGWOutstockStation4, WmsWareHouseConst.Floor1GLSGWOutstockStation5 };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否为原材料调拨出库库位
|
||||
/// </summary>
|
||||
/// <param name="location_id"></param>
|
||||
/// <returns></returns>
|
||||
public string[] GetFloor1YCLDBOutstockLocation()
|
||||
{
|
||||
return new string[5] { WmsWareHouseConst.Floor1GLSGWOutstockStation1 , WmsWareHouseConst.Floor1GLSGWOutstockStation2
|
||||
, WmsWareHouseConst.Floor1GLSGWOutstockStation3, WmsWareHouseConst.Floor1GLSGWOutstockStation4, WmsWareHouseConst.Floor1GLSGWOutstockStation5 };
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否为外协三工位库位
|
||||
/// </summary>
|
||||
@@ -432,7 +444,6 @@ namespace Tnb.WarehouseMgr
|
||||
|
||||
SqlSugarClient cyDb = _db.CopyNew();
|
||||
|
||||
|
||||
List<Tuple<string, WmsCarryH, WmsCarryCode, BasLocation>> items = cyDb.Queryable<WmsCarryH>().LeftJoin<WmsCarryCode>((a, b) => a.id == b.carry_id)
|
||||
.LeftJoin<BasLocation>((a, b, c) => a.location_id == c.id)
|
||||
.Where(whereExpr)
|
||||
@@ -3655,8 +3666,8 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
Logger.LogInformation($"【CommonCreatePretask】 {ex.Message}");
|
||||
Logger.LogInformation($"【CommonCreatePretask】 {ex.StackTrace}");
|
||||
if (!db.Ado.Transaction.IsNull())
|
||||
await db.Ado.CommitTranAsync();
|
||||
//if (!db.Ado.Transaction.IsNull())
|
||||
// await db.Ado.CommitTranAsync();
|
||||
return await ToApiResult(JNPF.Common.Enums.HttpStatusCode.InternalServerError, ex.Message);
|
||||
}
|
||||
finally
|
||||
@@ -3669,6 +3680,105 @@ namespace Tnb.WarehouseMgr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 可下发载具查询
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="AppFriendlyException"></exception>
|
||||
[HttpPost, NonUnify, AllowAnonymous]
|
||||
public async Task<Tnb.WarehouseMgr.Entities.Dto.Outputs.Result> CarryMaterialInventory(CarryMaterialInventoryInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(input.warehouse_code))
|
||||
{
|
||||
throw new AppFriendlyException("出库仓库不可为空", 500);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(input.material_id))
|
||||
{
|
||||
throw new AppFriendlyException("物料id不可为空", 500);
|
||||
}
|
||||
if (string.IsNullOrEmpty(input.code_batch))
|
||||
{
|
||||
throw new AppFriendlyException("批号不可为空", 500);
|
||||
}
|
||||
|
||||
BasWarehouse basWarehouse = await _db.Queryable<BasWarehouse>().Where(r => r.whcode == input.warehouse_code).FirstAsync();
|
||||
|
||||
switch (basWarehouse.id)
|
||||
{
|
||||
case WmsWareHouseConst.WAREHOUSE_YCL_ID:
|
||||
{
|
||||
OutStockStrategyQuery outStockStrategyInput = new()
|
||||
{
|
||||
warehouse_id = WmsWareHouseConst.WAREHOUSE_YCL_ID,
|
||||
material_id = input.material_id,
|
||||
code_batch = input.code_batch,
|
||||
Size = 100,
|
||||
Region_id = WmsWareHouseConst.REGION_Purchase_ID,
|
||||
PolicyCode = WmsWareHouseConst.POLICY_YCLOUTSTOCK,
|
||||
AvoidBusyPassage = true
|
||||
};
|
||||
|
||||
List<WmsCarryH> items = await OutStockStrategy(outStockStrategyInput);
|
||||
|
||||
var wmsCarryCodes = await _db.Queryable<WmsCarryCode>()
|
||||
.InnerJoin<WmsCarryH>((a, b) => a.carry_id == b.id)
|
||||
.InnerJoin<BasMaterial>((a, b, c) => a.material_id == c.id)
|
||||
.Where((a, b, c) => items.Select(r => r.id).Contains(a.carry_id))
|
||||
.Select((a, b, c) => new
|
||||
{
|
||||
carry_id = a.carry_id,
|
||||
carry_code = b.carry_code,
|
||||
material_id = c.id,
|
||||
material_code = c.code,
|
||||
material_name = c.name,
|
||||
material_specification = c.material_specification,
|
||||
barcode = a.barcode,
|
||||
code_batch = a.code_batch,
|
||||
qty = a.codeqty
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
var wmsCarryCodesSum = wmsCarryCodes.GroupBy(r => new { r.carry_id, r.material_id, r.code_batch }).Select(g =>
|
||||
{
|
||||
var list = g.ToList();
|
||||
|
||||
var newg = new
|
||||
{
|
||||
carry_id = list[0].carry_id,
|
||||
carry_code = list[0].carry_code,
|
||||
material_id = list[0].material_id,
|
||||
material_code = list[0].material_code,
|
||||
material_name = list[0].material_name,
|
||||
material_specification = list[0].material_specification,
|
||||
barcode = list[0].barcode,
|
||||
code_batch = list[0].code_batch,
|
||||
qty = g.Sum(r => r.qty)
|
||||
};
|
||||
|
||||
return newg;
|
||||
});
|
||||
|
||||
return await ToApiResult(JNPF.Common.Enums.HttpStatusCode.OK, "成功", wmsCarryCodesSum);
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw new AppFriendlyException("此仓库业务未完善", 500);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
return await ToApiResult(JNPF.Common.Enums.HttpStatusCode.InternalServerError, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
@@ -250,6 +250,8 @@ namespace Tnb.WarehouseMgr
|
||||
|
||||
List<WmsCarrybindCode> wmsCarrybindCodes = new List<WmsCarrybindCode>();
|
||||
|
||||
List<WmsTempCode> wmsTempCodes = await _db.Queryable<WmsTempCode>().Where(r => input.details.Select(c => c.barcode).Contains(r.barcode)).ToListAsync();
|
||||
|
||||
foreach (var detail in input.details)
|
||||
{
|
||||
var WmsCarryCode = detail.Adapt<WmsCarryCode>();
|
||||
@@ -261,6 +263,12 @@ namespace Tnb.WarehouseMgr
|
||||
WmsCarryCode.create_time = DateTime.Now;
|
||||
WmsCarryCodes.Add(WmsCarryCode);
|
||||
|
||||
WmsTempCode wmsTempCode = wmsTempCodes.Where(r => r.barcode == detail.barcode).First();
|
||||
if (wmsTempCode == null)
|
||||
{
|
||||
throw new Exception($"条码{wmsTempCode.barcode}在系统中不存在");
|
||||
}
|
||||
wmsTempCode.codeqty = detail.codeqty;
|
||||
var wmsCarrybindCode = detail.Adapt<WmsCarrybindCode>();
|
||||
wmsCarrybindCode.carrybind_id = wmsCarrybindH.id;
|
||||
wmsCarrybindCodes.Add(wmsCarrybindCode);
|
||||
@@ -271,6 +279,7 @@ namespace Tnb.WarehouseMgr
|
||||
rows = await _db.Insertable(WmsCarryCodes).ExecuteCommandAsync();
|
||||
await _db.Insertable(wmsCarrybindH).ExecuteCommandAsync();
|
||||
await _db.Insertable(wmsCarrybindCodes).ExecuteCommandAsync();
|
||||
await _db.Updateable(wmsTempCodes).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -77,8 +77,6 @@ namespace Tnb.WarehouseMgr
|
||||
throw new ArgumentNullException(nameof(input));
|
||||
}
|
||||
|
||||
await _db.Ado.BeginTranAsync();
|
||||
|
||||
WmsCarryH wmsCarryH = await _db.Queryable<WmsCarryH>().Where(r => r.carry_code == input.carry_code).FirstAsync();
|
||||
if (wmsCarryH == null)
|
||||
{
|
||||
@@ -93,7 +91,7 @@ namespace Tnb.WarehouseMgr
|
||||
throw new AppFriendlyException($"【MaterialSign】载具{input.carry_code}未绑定物料", 500);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(wmsCarryH.location_id))
|
||||
if (string.IsNullOrEmpty(wmsCarryH.location_id))
|
||||
{
|
||||
throw new AppFriendlyException($"【MaterialSign】载具{input.carry_code}当前库位为空,无法签收", 500);
|
||||
}
|
||||
@@ -106,6 +104,7 @@ namespace Tnb.WarehouseMgr
|
||||
wmsMaterialSignH.carry_id = wmsCarryH.id;
|
||||
wmsMaterialSignH.carry_code = wmsCarryH.carry_code;
|
||||
List<WmsMaterialSignD> wmsMaterialSignDs = new List<WmsMaterialSignD>();
|
||||
await _db.Ado.BeginTranAsync();
|
||||
foreach (var item in input.details)
|
||||
{
|
||||
if (item.sign_qty < 0)
|
||||
@@ -147,11 +146,9 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
CarryCodeUnbindCodeInput carryCodeUnbindCodeInput = new CarryCodeUnbindCodeInput();
|
||||
await _wmsCarryUnbindService.CarryCodeUnbindCode(carryCodeUnbindCodeInput, _db);
|
||||
wmsCarryCodes.Remove(wmsCarryCode);
|
||||
|
||||
await _db.Updateable<WmsTempCode>().SetColumns(r => r.codeqty == wmsCarryCode.codeqty - item.sign_qty)
|
||||
.Where(r => r.barcode == wmsCarryCode.barcode).ExecuteCommandAsync();
|
||||
}
|
||||
await _db.Updateable<WmsTempCode>().SetColumns(r => r.codeqty == wmsCarryCode.codeqty)
|
||||
.Where(r => r.barcode == wmsCarryCode.barcode).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
BasLocation carryLoc = await _db.Queryable<BasLocation>().Where(r => r.id == wmsCarryH.location_id).FirstAsync();
|
||||
@@ -179,21 +176,19 @@ namespace Tnb.WarehouseMgr
|
||||
throw new AppFriendlyException("没有可以回库的库位", 500);
|
||||
}
|
||||
CommonCreatePretaskInput commonCreatePretaskInput = new CommonCreatePretaskInput();
|
||||
commonCreatePretaskInput.startlocation_id = carryLoc.location_code;
|
||||
commonCreatePretaskInput.startlocation_id = carryLoc.id;
|
||||
commonCreatePretaskInput.endlocation_id = endLocations[0].id;
|
||||
commonCreatePretaskInput.carry_id = wmsCarryH.id;
|
||||
commonCreatePretaskInput.carry_code = wmsCarryH.carry_code;
|
||||
commonCreatePretaskInput.task_type = WmsWareHouseConst.WMS_PRETASK_INSTOCK_TYPE_ID;
|
||||
commonCreatePretaskInput.biz_type = WmsWareHouseConst.BIZTYPE_WMSEMPTYINSTOCK_ID;
|
||||
commonCreatePretaskInput.isExcuteMission = false;
|
||||
commonCreatePretaskInput.moduleConsts = ModuleConsts.MODULE_WMSEMPTYINSTOCK_ID;
|
||||
commonCreatePretaskInput.biz_type = WmsWareHouseConst.BIZTYPE_WmsMaterialSign_ID;
|
||||
|
||||
Logger.LogInformation($"【MaterialSign】 开始生成原材料仓回库任务 起点{carryLoc.location_code} 终点{endLocations[0].location_code} 托盘 {wmsCarryH.carry_code}");
|
||||
|
||||
Entities.Dto.Outputs.Result res = await _wareHouseService.CommonCreatePretask(commonCreatePretaskInput, _db);
|
||||
if (res.code == HttpStatusCode.OK)
|
||||
if (res.code != HttpStatusCode.OK)
|
||||
{
|
||||
|
||||
throw new AppFriendlyException(res.msg, 500);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -210,8 +205,8 @@ namespace Tnb.WarehouseMgr
|
||||
}
|
||||
}
|
||||
|
||||
await _db.Updateable(wmsMaterialSignH).ExecuteCommandAsync();
|
||||
await _db.Updateable(wmsMaterialSignDs).ExecuteCommandAsync();
|
||||
await _db.Insertable(wmsMaterialSignH).ExecuteCommandAsync();
|
||||
await _db.Insertable(wmsMaterialSignDs).ExecuteCommandAsync();
|
||||
await _db.Ado.CommitTranAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -16,6 +16,7 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Senparc.Weixin.Work.AdvancedAPIs.OaDataOpen;
|
||||
using SqlSugar;
|
||||
using Tnb.BasicData.Entities;
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
@@ -69,58 +70,7 @@ namespace Tnb.WarehouseMgr
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取物料库存
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="AppFriendlyException"></exception>
|
||||
[HttpPost, NonUnify, AllowAnonymous]
|
||||
public async Task<Tnb.WarehouseMgr.Entities.Dto.Outputs.Result> MaterialInventory(MaterialTransferGetMaterialInventoryInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (input.palletCount <= 0)
|
||||
{
|
||||
throw new AppFriendlyException("托盘数必须大于0", 500);
|
||||
}
|
||||
if (string.IsNullOrEmpty(input.material_id))
|
||||
{
|
||||
throw new AppFriendlyException("物料id不可为空", 500);
|
||||
}
|
||||
if (string.IsNullOrEmpty(input.code_batch))
|
||||
{
|
||||
throw new AppFriendlyException("批号不可为空", 500);
|
||||
}
|
||||
|
||||
OutStockStrategyQuery outStockStrategyInput = new()
|
||||
{
|
||||
warehouse_id = WmsWareHouseConst.WAREHOUSE_YCL_ID,
|
||||
material_id = input.material_id,
|
||||
code_batch = input.code_batch,
|
||||
Size = input.palletCount,
|
||||
Region_id = WmsWareHouseConst.REGION_Purchase_ID,
|
||||
PolicyCode = WmsWareHouseConst.POLICY_YCLOUTSTOCK,
|
||||
AvoidBusyPassage = true
|
||||
};
|
||||
|
||||
List<WmsCarryH> items = await _wareHouseService.OutStockStrategy(outStockStrategyInput);
|
||||
|
||||
decimal qty = _db.Queryable<WmsCarryCode>().Where(r => items.Select(a => a.id).Contains(r.carry_id) && r.material_id == input.material_id && r.code_batch == input.code_batch).Sum(r => r.codeqty);
|
||||
|
||||
JObject keyValuePairs = new JObject();
|
||||
keyValuePairs["realPalletCount"] = items.Count;
|
||||
keyValuePairs["realInvQty"] = qty;
|
||||
|
||||
return await ToApiResult(HttpStatusCode.OK, "成功", keyValuePairs);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 按托下发(到集中供料或外协)
|
||||
/// </summary>
|
||||
@@ -128,7 +78,7 @@ namespace Tnb.WarehouseMgr
|
||||
/// <returns></returns>
|
||||
/// <exception cref="AppFriendlyException"></exception>
|
||||
[HttpPost, NonUnify, AllowAnonymous]
|
||||
public async Task<Entities.Dto.Outputs.Result> Distribute(MaterialTransferDistributeInput input)
|
||||
public async Task<Entities.Dto.Outputs.Result> Distribute(RawmatTransferoutstockInput input)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -137,73 +87,39 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
throw new AppFriendlyException("来源单据id不可为空", 500);
|
||||
}
|
||||
if (input.palletCount <= 0)
|
||||
if (input.carrys.Count == 0)
|
||||
{
|
||||
throw new AppFriendlyException("托盘数必须大于0", 500);
|
||||
}
|
||||
if (input.qty <= 0)
|
||||
{
|
||||
throw new AppFriendlyException("数量必须大于0", 500);
|
||||
}
|
||||
if (string.IsNullOrEmpty(input.code_batch))
|
||||
{
|
||||
throw new AppFriendlyException("批号不可为空", 500);
|
||||
throw new AppFriendlyException("至少选择一个载具", 500);
|
||||
}
|
||||
|
||||
WmsMaterialTransferD wmsMaterialTransferD = await _db.Queryable<WmsMaterialTransferD>().FirstAsync(it => it.id == input.source_id);
|
||||
WmsMaterialTransfer wmsMaterialTransfer = await _db.Queryable<WmsMaterialTransfer>().FirstAsync(it => it.id == wmsMaterialTransferD.bill_id);
|
||||
WmsRawmatTransferoutstockD wmsRawmatTransferoutstockD = await _db.Queryable<WmsRawmatTransferoutstockD>().FirstAsync(it => it.id == input.source_id);
|
||||
WmsRawmatTransferoutstockH wmsRawmatTransferoutstockH = await _db.Queryable<WmsRawmatTransferoutstockH>().FirstAsync(it => it.id == wmsRawmatTransferoutstockD.bill_id);
|
||||
|
||||
if (wmsMaterialTransferD.yxfqty >= wmsMaterialTransferD.qty)
|
||||
List<WmsCarryH> items = await _db.Queryable<WmsCarryH>().Where(r => input.carrys.Contains(r.carry_code)).ToListAsync();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
List<WmsCarryCode> wmsCarryCodes = await _db.Queryable<WmsCarryCode>().Where(r => items.Select(c => c.id).Contains(r.carry_id)
|
||||
&& r.material_id == wmsRawmatTransferoutstockD.matcode_id && r.code_batch == wmsRawmatTransferoutstockD.code_batch).ToListAsync();
|
||||
|
||||
decimal qty = wmsCarryCodes.Sum(c => c.codeqty);
|
||||
if (wmsRawmatTransferoutstockD.actual_qty + qty > wmsRawmatTransferoutstockD.qty)
|
||||
{
|
||||
throw new AppFriendlyException("已下发数量已达到转库数量", 500);
|
||||
throw new AppFriendlyException($"本次出库数量{qty}已超过可出库数量{wmsRawmatTransferoutstockD.qty - wmsRawmatTransferoutstockD.actual_qty}", 500);
|
||||
}
|
||||
|
||||
await _db.Ado.BeginTranAsync();
|
||||
|
||||
OutStockStrategyQuery outStockStrategyInput = new()
|
||||
{
|
||||
warehouse_id = WmsWareHouseConst.WAREHOUSE_YCL_ID,
|
||||
material_id = wmsMaterialTransferD.material_id,
|
||||
code_batch = input.code_batch,
|
||||
Size = input.palletCount,
|
||||
Region_id = WmsWareHouseConst.REGION_Purchase_ID,
|
||||
PolicyCode = WmsWareHouseConst.POLICY_YCLOUTSTOCK,
|
||||
AvoidBusyPassage = true
|
||||
};
|
||||
List<WmsCarryH> items = await _wareHouseService.OutStockStrategy(outStockStrategyInput);
|
||||
|
||||
if (items.Count == 0)
|
||||
{
|
||||
throw new AppFriendlyException($@"没有可以出库的载具", 500);
|
||||
}
|
||||
|
||||
decimal qty = _db.Queryable<WmsCarryCode>().Where(r => items.Select(a => a.id).Contains(r.carry_id) && r.material_id == wmsMaterialTransferD.material_id && r.code_batch == input.code_batch).Sum(r => r.codeqty);
|
||||
|
||||
// 暂定PDA上查询到的物料批次和库存数量与提交时获取的不一致时,需要前台重新获取库存接口
|
||||
if (input.palletCount != items.Count || input.qty != qty)
|
||||
{
|
||||
throw new AppFriendlyException($@"当前实际托盘数量为{input.palletCount} 实际库存数量为{qty},与前台数据不一致,请重新获取库存", HttpStatusCode.InternalServerError);
|
||||
}
|
||||
|
||||
List<BasLocation> endLocations = new List<BasLocation>();
|
||||
// 集中供料区三工位
|
||||
if (wmsMaterialTransfer.warehouse_instock == WmsWareHouseConst.WAREHOUSE_JZGL_ID)
|
||||
{
|
||||
// 根据三工位任务数平均分配任务 暂定
|
||||
endLocations = _db.Queryable<BasLocation>().Where(r => _wareHouseService.GetFloor1GLSGWOutstockLocation().Contains(r.id) && r.is_lock == 0 && r.is_use == "0")
|
||||
.OrderBy("is_lock, task_nums, location_code").ToList();
|
||||
}
|
||||
// 中储仓三工位
|
||||
else if (wmsMaterialTransfer.warehouse_instock == WmsWareHouseConst.WAREHOUSE_ZC_ID)
|
||||
{
|
||||
// 根据三工位任务数平均分配任务 暂定
|
||||
endLocations = _db.Queryable<BasLocation>().Where(r => _wareHouseService.GetFloor1WXSGWOutstockLocation().Contains(r.id) && r.is_lock == 0 && r.is_use == "0")
|
||||
.OrderBy("is_lock, task_nums, location_code").ToList();
|
||||
}
|
||||
|
||||
endLocations = _db.Queryable<BasLocation>().Where(r => _wareHouseService.GetFloor1YCLDBOutstockLocation().Contains(r.id) && r.is_lock == 0 && r.is_use == "0")
|
||||
.OrderBy("is_lock, task_nums, location_code").ToList();
|
||||
|
||||
if (endLocations.Count() < input.palletCount)
|
||||
if (endLocations.Count() < items.Count)
|
||||
{
|
||||
throw new AppFriendlyException($@"可用的终点库位数量为{endLocations.Count()}个 下发数量为{input.palletCount}个 请检查终点库位的锁定和占用状态", 500);
|
||||
throw new AppFriendlyException($@"可用的终点库位数量为{endLocations.Count()}个 下发数量为{items.Count}个 请检查终点库位的锁定和占用状态", 500);
|
||||
}
|
||||
|
||||
foreach (var wmsCarryH in items)
|
||||
@@ -211,19 +127,9 @@ namespace Tnb.WarehouseMgr
|
||||
BasLocation startLocation = await _db.Queryable<BasLocation>().Where(r => r.id == wmsCarryH.location_id).FirstAsync();
|
||||
|
||||
BasLocation endLocation = null;
|
||||
// 集中供料区三工位
|
||||
if (wmsMaterialTransfer.warehouse_instock == WmsWareHouseConst.WAREHOUSE_JZGL_ID)
|
||||
{
|
||||
// 根据三工位任务数平均分配任务 暂定
|
||||
endLocation = await _db.Queryable<BasLocation>().Where(r => _wareHouseService.GetFloor1GLSGWOutstockLocation().Contains(r.id) && r.is_lock == 0 && r.is_use == "0").OrderBy("is_lock, task_nums, location_code").FirstAsync();
|
||||
}
|
||||
// 中储仓三工位
|
||||
else if (wmsMaterialTransfer.warehouse_instock == WmsWareHouseConst.WAREHOUSE_ZC_ID)
|
||||
{
|
||||
// 根据三工位任务数平均分配任务 暂定
|
||||
endLocation = await _db.Queryable<BasLocation>().Where(r => _wareHouseService.GetFloor1WXSGWOutstockLocation().Contains(r.id) && r.is_lock == 0 && r.is_use == "0").OrderBy("is_lock, task_nums, location_code").FirstAsync();
|
||||
}
|
||||
|
||||
|
||||
endLocation = await _db.Queryable<BasLocation>().Where(r => _wareHouseService.GetFloor1YCLDBOutstockLocation().Contains(r.id) && r.is_lock == 0 && r.is_use == "0").OrderBy("is_lock, task_nums, location_code").FirstAsync();
|
||||
|
||||
if (endLocation == null)
|
||||
{
|
||||
throw new AppFriendlyException($@"没有可用的终点库位!请检查终点库位的锁定和占用状态", 500);
|
||||
@@ -233,7 +139,7 @@ namespace Tnb.WarehouseMgr
|
||||
commonCreatePretaskInput.startlocation_id = startLocation.id;
|
||||
commonCreatePretaskInput.endlocation_id = endLocation.id;
|
||||
commonCreatePretaskInput.task_type = WmsWareHouseConst.WMS_PRETASK_OUTSTOCK_TYPE_ID;
|
||||
commonCreatePretaskInput.biz_type = WmsWareHouseConst.BIZTYPE_WMSMATERIALTRANSFER_ID;
|
||||
commonCreatePretaskInput.biz_type = WmsWareHouseConst.BIZTYPE_WmsRawmatTransferoutstock_ID;
|
||||
commonCreatePretaskInput.source_id = input.source_id;
|
||||
commonCreatePretaskInput.carry_id = wmsCarryH.id;
|
||||
commonCreatePretaskInput.carry_code = wmsCarryH.carry_code;
|
||||
@@ -249,7 +155,7 @@ namespace Tnb.WarehouseMgr
|
||||
}
|
||||
|
||||
// 更新子表已下发数量
|
||||
await _db.Updateable<WmsMaterialTransferD>().SetColumns(r => r.yxfqty == r.yxfqty + input.qty).Where(r => r.id == input.source_id).ExecuteCommandAsync();
|
||||
await _db.Updateable<WmsRawmatTransferoutstockD>().SetColumns(r => r.actual_qty == r.actual_qty + qty).Where(r => r.id == input.source_id).ExecuteCommandAsync();
|
||||
|
||||
await _db.Ado.CommitTranAsync();
|
||||
}
|
||||
|
||||
@@ -4,12 +4,26 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Dtos.VisualDev;
|
||||
using JNPF.Common.Enums;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.FriendlyException;
|
||||
using JNPF.Systems.Interfaces.System;
|
||||
using JNPF.VisualDev;
|
||||
using JNPF.VisualDev.Entitys;
|
||||
using JNPF.VisualDev.Interfaces;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SqlSugar;
|
||||
using Tnb.BasicData.Entities;
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
using Tnb.WarehouseMgr.Entities.Consts;
|
||||
using Tnb.WarehouseMgr.Entities.Dto;
|
||||
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
||||
using Tnb.WarehouseMgr.Entities.Entity;
|
||||
using Tnb.WarehouseMgr.Entities.Enums;
|
||||
using Tnb.WarehouseMgr.Interfaces;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
@@ -52,10 +66,290 @@ namespace Tnb.WarehouseMgr
|
||||
throw new ArgumentNullException(nameof(input));
|
||||
}
|
||||
|
||||
//if (!isOk)
|
||||
//{
|
||||
// throw Oops.Oh(ErrorCode.COM1001);
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下发
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="AppFriendlyException"></exception>
|
||||
[HttpPost, NonUnify, AllowAnonymous]
|
||||
public async Task<Tnb.WarehouseMgr.Entities.Dto.Outputs.Result> Distribute(WmsTransferOutstockInput input)
|
||||
{
|
||||
Logger.LogInformation($"【Distribute】 成品调拨出库下发");
|
||||
try
|
||||
{
|
||||
if (input.qty <= 0)
|
||||
{
|
||||
throw new AppFriendlyException("数量必须大于0", 500);
|
||||
}
|
||||
if (string.IsNullOrEmpty(input.source_id))
|
||||
{
|
||||
throw new AppFriendlyException("来源单据id不可为空", 500);
|
||||
}
|
||||
|
||||
WmsTransferOutstockD wmsOutstockD = await _db.Queryable<WmsTransferOutstockD>().FirstAsync(it => it.id == input.source_id);
|
||||
await s_taskExecuteSemaphore.WaitAsync();
|
||||
await _db.Ado.BeginTranAsync();
|
||||
//入库取终点 //出库起点
|
||||
OutStockStrategyQuery inStockStrategyInput = new() { warehouse_id = WmsWareHouseConst.WAREHOUSE_CP_ID, material_id = wmsOutstockD.material_id, qty = input.qty, code_batch = wmsOutstockD.pi_code };
|
||||
List<Tuple<string, WmsCarryH, WmsCarryCode, BasLocation>> items = await _wareHouseService.OutStockStrategy_saleRelease(inStockStrategyInput);
|
||||
|
||||
decimal canOutstockQty = items.Sum(r => r.Item3.codeqty).ParseToDecimal();
|
||||
if (canOutstockQty < input.qty)
|
||||
{
|
||||
throw new AppFriendlyException($@"当前可出库数量只有 {canOutstockQty.ToString("G")}", 500);
|
||||
}
|
||||
|
||||
List<Tuple<string, WmsCarryH, WmsCarryCode, BasLocation>> items_sorttask = items.Where(r => r.Item1 == "分拣任务").ToList();
|
||||
List<Tuple<string, WmsCarryH, WmsCarryCode, BasLocation>> items_pretask = items.Where(r => r.Item1 == "预任务").ToList();
|
||||
|
||||
Logger.LogInformation($"【Distribute】 预计生成{items_pretask.Count}条预任务");
|
||||
|
||||
|
||||
List<BasLocation> endLocations = await _db.Queryable<BasLocation>().Where(r => _wareHouseService.GetFloor1OutstockLocation().Contains(r.id) && r.is_lock == 0 && r.is_use == "0").ToListAsync();
|
||||
|
||||
if (endLocations.Count < items_pretask.Count)
|
||||
{
|
||||
throw new AppFriendlyException("一楼没有足够的未锁定且空闲的出库工位", 500);
|
||||
}
|
||||
|
||||
|
||||
// 预任务逻辑
|
||||
foreach (Tuple<string, WmsCarryH, WmsCarryCode, BasLocation> item in items_pretask)
|
||||
{
|
||||
WmsCarryH carry = item.Item2;
|
||||
WmsCarryCode carryCode = item.Item3;
|
||||
BasLocation startLocation = item.Item4;
|
||||
// 根据一楼工位任务数平均分配任务 确定一楼工位
|
||||
BasLocation endLocation = await _db.Queryable<BasLocation>().Where(r => _wareHouseService.GetFloor1OutstockLocation().Contains(r.id) && r.is_lock == 0 && r.is_use == "0").OrderBy("is_lock, task_nums, location_code").FirstAsync();
|
||||
|
||||
if (endLocation == null)
|
||||
{
|
||||
throw new AppFriendlyException("一楼没有足够的未锁定且空闲的出库工位", 500);
|
||||
}
|
||||
WmsPointH sPoint = null!;
|
||||
WmsPointH ePoint = null!;
|
||||
|
||||
sPoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == startLocation.id);
|
||||
|
||||
bool isMatch = await IsCarryAndLocationMatchByCarryStd(carry, endLocation);
|
||||
if (!isMatch)
|
||||
{
|
||||
throw new AppFriendlyException("库位与载具规格不匹配", 500);
|
||||
}
|
||||
|
||||
ePoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == endLocation.id);
|
||||
|
||||
if (ePoint != null)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new AppFriendlyException($"库位{endLocation.location_code}未在点位表中维护对应点位", 500);
|
||||
}
|
||||
|
||||
|
||||
string endLocationId = endLocation.id;
|
||||
|
||||
// 在线开发
|
||||
//VisualDevEntity? templateEntity = await _visualDevService?.GetInfoById(ModuleConsts.MODULE_WMSDELIVERYPDA_ID, true)!;
|
||||
//await _runService.Create(templateEntity, input);
|
||||
|
||||
// 计算路径,插入预任务申请
|
||||
|
||||
if (sPoint != null && ePoint != null)
|
||||
{
|
||||
List<WmsPointH> points = new List<WmsPointH>();
|
||||
if (sPoint.area_code != ePoint.area_code)
|
||||
{
|
||||
points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id);
|
||||
if (points.Count <= 2)
|
||||
{
|
||||
throw new AppFriendlyException($"sPoint {sPoint.point_code} ePoint{ePoint.point_code}该路径不存在", 500);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
points.Add(sPoint);
|
||||
points.Add(ePoint);
|
||||
}
|
||||
|
||||
//根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序)
|
||||
if (points?.Count > 0)
|
||||
{
|
||||
List<WmsPretaskH> preTasks = points.Where(it => !it.location_id.IsNullOrEmpty()).GroupBy(g => g.area_code).Select(it =>
|
||||
{
|
||||
WmsPointH? sPoint = it.FirstOrDefault();
|
||||
WmsPointH? ePoint = it.LastOrDefault();
|
||||
|
||||
WmsPretaskH preTask = new()
|
||||
{
|
||||
org_id = _userManager!.User.OrganizeId,
|
||||
startlocation_id = sPoint?.location_id!,
|
||||
startlocation_code = sPoint?.location_code!,
|
||||
endlocation_id = ePoint?.location_id!,
|
||||
endlocation_code = ePoint?.location_code!,
|
||||
start_floor = sPoint?.floor.ToString(),
|
||||
end_floor = ePoint?.floor.ToString(),
|
||||
startpoint_id = sPoint?.id!,
|
||||
startpoint_code = sPoint?.point_code!,
|
||||
endpoint_id = ePoint?.id!,
|
||||
endpoint_code = ePoint?.point_code!,
|
||||
bill_code = _billRullService!.GetBillNumber(WmsWareHouseConst.WMS_PRETASK_H_ENCODE).GetAwaiter().GetResult(),
|
||||
status = WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID,
|
||||
biz_type = WmsWareHouseConst.BIZTYPE_WmsTransferOutstock_ID,
|
||||
task_type = WmsWareHouseConst.WMS_PRETASK_TRANSFER_TYPE_ID
|
||||
};
|
||||
preTask.carry_id = carry.id;
|
||||
preTask.carry_code = carry.carry_code;
|
||||
preTask.area_id = sPoint?.area_id!;
|
||||
preTask.area_code = it.Key;
|
||||
preTask.require_id = input.source_id;
|
||||
preTask.require_code = "";
|
||||
preTask.create_id = _userManager.UserId;
|
||||
preTask.create_time = DateTime.Now;
|
||||
return preTask;
|
||||
}).ToList();
|
||||
bool isOk = await _wareHouseService.GenPreTask(preTasks, null!, _db);
|
||||
if (isOk)
|
||||
{
|
||||
if (endLocationId != null)
|
||||
{
|
||||
//查询库位表
|
||||
BasLocation location = await _db.Queryable<BasLocation>().SingleAsync(it => it.id == startLocation.id);
|
||||
{
|
||||
//载具加锁,增加库位信息
|
||||
_ = await _db.Updateable<WmsCarryH>().SetColumns(it => new WmsCarryH
|
||||
{
|
||||
carry_status = ((int)EnumCarryStatus.占用).ToString(),
|
||||
is_lock = 1,
|
||||
location_id = startLocation.id,
|
||||
location_code = location.location_code
|
||||
}).Where(it => it.id == carry.id).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
//所有库位加锁
|
||||
string?[] ids = new[] { startLocation.id, preTasks[0].endlocation_id, endLocationId };
|
||||
_ = await _db.Updateable<BasLocation>().SetColumns(it => new BasLocation { is_lock = 1 }).Where(it => ids.Contains(it.id)).ExecuteCommandAsync();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Logger.LogInformation($"【Distribute】 预计生成{items_sorttask.Count}条分拣任务");
|
||||
// 分拣任务逻辑
|
||||
foreach (Tuple<string, WmsCarryH, WmsCarryCode, BasLocation> item in items_sorttask)
|
||||
{
|
||||
WmsCarryH carry = item.Item2;
|
||||
WmsCarryCode carryCode = item.Item3;
|
||||
BasLocation startLocation = item.Item4;
|
||||
|
||||
// 锁定分拣载具
|
||||
await _db.Updateable<WmsCarryH>().SetColumns(r => r.is_lock == 1).Where(r => r.id == carry.id).ExecuteCommandAsync();
|
||||
|
||||
Dictionary<string, object> dic = new()
|
||||
{
|
||||
[nameof(WmsSortingtask.id)] = SnowflakeIdHelper.NextId(),
|
||||
[nameof(WmsSortingtask.bill_code)] = await _billRullService.GetBillNumber(WmsWareHouseConst.WMS_SORTINGTASK_ENCODE),
|
||||
[nameof(WmsSortingtask.org_id)] = input.org_id ?? _userManager.User.OrganizeId,
|
||||
[nameof(WmsSortingtask.qty)] = carryCode.codeqty,
|
||||
[nameof(WmsSortingtask.carry_id)] = carry.id,
|
||||
[nameof(WmsSortingtask.carry_code)] = carry.carry_code,
|
||||
[nameof(WmsSortingtask.status)] = WmsWareHouseConst.TASK_BILL_STATUS_DZX_ID,
|
||||
[nameof(WmsSortingtask.location_id)] = startLocation.id,
|
||||
[nameof(WmsSortingtask.location_code)] = startLocation.location_code,
|
||||
[nameof(WmsSortingtask.create_id)] = input.create_id ?? _userManager.UserId,
|
||||
[nameof(WmsSortingtask.create_time)] = DateTime.Now,
|
||||
[nameof(WmsSortingtask.source_id)] = input.source_id
|
||||
};
|
||||
|
||||
VisualDevModelDataCrInput visualDevModelDataCrInput = new()
|
||||
{
|
||||
data = dic
|
||||
};
|
||||
|
||||
//在线开发
|
||||
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleConsts.MODULE_WMSSORTINGTASK_ID, false);
|
||||
await _runService.Create(templateEntity, visualDevModelDataCrInput);
|
||||
}
|
||||
|
||||
// 更新销售出库单子表已下发数量
|
||||
await _db.Updateable<WmsTransferOutstockD>().SetColumns(r => r.xf_qty == r.xf_qty + input.qty).Where(r => r.id == input.source_id).ExecuteCommandAsync();
|
||||
|
||||
await _db.Ado.CommitTranAsync();
|
||||
Logger.LogInformation($"【Distribute】 成品调拨出库下发完成");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
Logger.LogError($"【Distribute】 销售出库 {ex.Message}");
|
||||
Logger.LogError($"【Distribute】 销售出库 {ex.StackTrace}");
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_ = s_taskExecuteSemaphore.Release();
|
||||
await InvokeGenPretaskExcute();
|
||||
}
|
||||
|
||||
return await ToApiResult(HttpStatusCode.OK, "成功");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分拣
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost, NonUnify, AllowAnonymous]
|
||||
public async Task<Tnb.WarehouseMgr.Entities.Dto.Outputs.Result> Sort(FinishproductOutstockSortInput input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input.source_id))
|
||||
{
|
||||
throw new AppFriendlyException("分拣任务id不能为空", 500);
|
||||
}
|
||||
|
||||
await _db.Ado.BeginTranAsync();
|
||||
try
|
||||
{
|
||||
WmsSortingtask wmsSortingtask = await _db.Queryable<WmsSortingtask>().Where(r => r.id == input.source_id).FirstAsync();
|
||||
if (wmsSortingtask.status == WmsWareHouseConst.TASK_BILL_STATUS_COMPLE_ID)
|
||||
{
|
||||
throw new AppFriendlyException("此分拣任务已完成,不允许重复提交", 500);
|
||||
}
|
||||
// 解锁分拣载具
|
||||
await _db.Updateable<WmsCarryH>().SetColumns(r => r.is_lock == 0).Where(r => r.id == wmsSortingtask.carry_id).ExecuteCommandAsync();
|
||||
// 扣减载具物料库存
|
||||
await _db.Updateable<WmsCarryCode>().SetColumns(r => r.codeqty == r.codeqty - wmsSortingtask.qty).Where(r => r.carry_id == wmsSortingtask.carry_id).ExecuteCommandAsync();
|
||||
|
||||
await _db.Updateable<WmsSortingtask>().SetColumns(r => new WmsSortingtask
|
||||
{
|
||||
status = WmsWareHouseConst.TASK_BILL_STATUS_COMPLE_ID,
|
||||
complete_time = DateTime.Now
|
||||
}).Where(r => r.id == wmsSortingtask.id).ExecuteCommandAsync();
|
||||
|
||||
await _db.Updateable<WmsTransferOutstockD>().SetColumns(r => r.xf_qty == r.xf_qty + wmsSortingtask.qty).Where(r => r.id == wmsSortingtask.source_id).ExecuteCommandAsync();
|
||||
//await _db.Updateable<WmsCarryCode>().SetColumns(r => new WmsCarryCode
|
||||
//{
|
||||
// codeqty = input.qty,
|
||||
//}).Where(r => r.carry_id == input.carry_id).ExecuteCommandAsync();
|
||||
|
||||
await _db.Ado.CommitTranAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message);
|
||||
}
|
||||
|
||||
return await ToApiResult(HttpStatusCode.OK, "成功");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user