电梯控制bug处理 包材出库逻辑变更
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Aspose.Cells;
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Dtos.VisualDev;
|
||||
using JNPF.Common.Enums;
|
||||
@@ -11,6 +13,7 @@ using JNPF.VisualDev.Entitys;
|
||||
using JNPF.VisualDev.Interfaces;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NPOI.POIFS.Storage;
|
||||
@@ -31,7 +34,7 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
[OverideVisualDev(ModuleConsts.MODULE_WMSPACKOUTSTOCK_ID)]
|
||||
[ServiceModule(BizTypeId)]
|
||||
public class WmsPackOutstockService : BaseWareHouseService, IWmsPrdReturnService
|
||||
public class WmsPackOutstockService : BaseWareHouseService, IWmsPackOutstockService
|
||||
{
|
||||
private const string BizTypeId = WmsWareHouseConst.BIZTYPE_WMSPACKOUTSTOCK_ID;
|
||||
private readonly ISqlSugarClient _db;
|
||||
@@ -72,78 +75,16 @@ namespace Tnb.WarehouseMgr
|
||||
|
||||
try
|
||||
{
|
||||
// TODO 二楼工位放货完成后更新出库明细的实际出库数量
|
||||
//if (input.wmsDistaskH.start_floor == 2 && input.wmsDistaskH.end_floor == 2)
|
||||
{
|
||||
WmsCarryCode wmsCarryCode = await _db.Queryable<WmsCarryCode>().Where(r => r.carry_id == input.wmsDistaskH.carry_id).FirstAsync();
|
||||
await _db.Updateable<WmsPackOutstockD>().SetColumns(r => r.prqty == r.prqty + wmsCarryCode.codeqty).Where(r => r.id == input.wmsDistaskH.require_id).ExecuteCommandAsync();
|
||||
|
||||
CarryCodeUnbindInput carryCodeUnbindInput = new CarryCodeUnbindInput();
|
||||
carryCodeUnbindInput.carry_id = input.wmsDistaskH.carry_id;
|
||||
await _wmsCarryUnbindService.CarryCodeUnbind(carryCodeUnbindInput, _db);
|
||||
}
|
||||
|
||||
await _db.Ado.CommitTranAsync();
|
||||
await _db.Updateable<WmsPackOutstockD>().SetColumns(r => r.line_status == WmsWareHouseConst.TASK_BILL_STATUS_COMPLE_ID).Where(r => r.id == input.wmsDistaskH.require_id).ExecuteCommandAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError("【WmsPackOutStockService ModifyAsync】" + ex.Message);
|
||||
Logger.LogError("【WmsPackOutStockService ModifyAsync】" + ex.StackTrace);
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <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 inStockStrategyInput = new()
|
||||
{
|
||||
warehouse_id = WmsWareHouseConst.WAREHOUSE_BCK_ID,
|
||||
material_id = input.material_id,
|
||||
code_batch = input.code_batch,
|
||||
Size = input.palletCount
|
||||
};
|
||||
List<WmsCarryH> items = await _wareHouseService.OutStockStrategyYCL(inStockStrategyInput);
|
||||
|
||||
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>
|
||||
@@ -151,90 +92,102 @@ namespace Tnb.WarehouseMgr
|
||||
/// <returns></returns>
|
||||
/// <exception cref="AppFriendlyException"></exception>
|
||||
[HttpPost, NonUnify, AllowAnonymous]
|
||||
public async Task<Tnb.WarehouseMgr.Entities.Dto.Outputs.Result> Distribute(MaterialTransferDistributeInput input)
|
||||
public async Task<bool> Distribute()
|
||||
{
|
||||
Logger.LogInformation($"【Distribute】 包材出库下发");
|
||||
Logger.LogInformation($"【WmsPackOutstockService-Distribute】 包材出库自动下发");
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(input.source_id))
|
||||
OutStockStrategyQuery outStockStrategyInput = new()
|
||||
{
|
||||
throw new AppFriendlyException("来源单据id不可为空", 500);
|
||||
}
|
||||
if (input.palletCount <= 0)
|
||||
warehouse_id = WmsWareHouseConst.WAREHOUSE_BCK_ID
|
||||
};
|
||||
List<WmsCarryH> carrys = await _wareHouseService.OutStockStrategyYCL(outStockStrategyInput);
|
||||
if (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 Exception("【WmsPackOutstockService-Distribute】四楼包材库没有可用的托盘");
|
||||
}
|
||||
|
||||
WmsPackOutstockD wmsPackOutstockD = await _db.Queryable<WmsPackOutstockD>().FirstAsync(it => it.id == input.source_id);
|
||||
WmsPackOutstockH wmsPackOutstockH = await _db.Queryable<WmsPackOutstockH>().FirstAsync(it => it.id == wmsPackOutstockD.bill_id);
|
||||
|
||||
if (wmsPackOutstockD.prqty == wmsPackOutstockD.qty)
|
||||
InStockStrategyQuery inStockStrategyInput = new() { warehouse_id = WmsWareHouseConst.WAREHOUSE_F2BCQ_ID, Size = carrys.Count };
|
||||
List<BasLocation> endLocations = await _wareHouseService.BCKF2InStockStrategy(inStockStrategyInput);
|
||||
if (endLocations.Count == 0)
|
||||
{
|
||||
throw new AppFriendlyException("已下发数量已达到出库数量", 500);
|
||||
throw new AppFriendlyException("【WmsPackOutstockService-Distribute】没有可用的入库库位", 500);
|
||||
}
|
||||
|
||||
int 可移转托数 = carrys.Count;
|
||||
// 如果四楼包材库的可出库托数大于二楼包材库的可入库库位数量,则只入库二楼包材库的可入库库位数量
|
||||
if (carrys.Count > endLocations.Count)
|
||||
{
|
||||
可移转托数 = endLocations.Count;
|
||||
}
|
||||
|
||||
Logger.Information($"【WmsPackOutstockService-Distribute】 四楼包材库的可出库托数为 {carrys.Count} 二楼包材库的可入库库位数量为 {endLocations.Count} 可移转托数为{可移转托数}");
|
||||
|
||||
// 生成包材出库记录
|
||||
|
||||
carrys = carrys.Take(可移转托数).ToList();
|
||||
|
||||
string bill_code = await _billRullService.GetBillNumber(WmsWareHouseConst.WMS_PACKOUTSTOCK_H_ENCODE);
|
||||
|
||||
WmsPackOutstockH wmsPackOutstockH = new WmsPackOutstockH();
|
||||
List<WmsCarryCode> wmsCarryCodes = _db.Queryable<WmsCarryCode>().Where(r => carrys.Select(r => r.id).Contains(r.carry_id)).ToList();
|
||||
|
||||
wmsPackOutstockH.org_id = WmsWareHouseConst.AdministratorOrgId;
|
||||
wmsPackOutstockH.bill_code = bill_code;
|
||||
wmsPackOutstockH.warehouse_id = WmsWareHouseConst.WAREHOUSE_BCK_ID;
|
||||
wmsPackOutstockH.create_id = WmsWareHouseConst.AdministratorUserId;
|
||||
wmsPackOutstockH.create_time = DateTime.Now;
|
||||
|
||||
await s_packOutstockSemaphore.WaitAsync();
|
||||
await _db.Ado.BeginTranAsync();
|
||||
|
||||
//入库取终点 //出库起点
|
||||
OutStockStrategyQuery outStockStrategyInput = new() { warehouse_id = WmsWareHouseConst.WAREHOUSE_BCK_ID, material_id = wmsPackOutstockD.material_id, code_batch = input.code_batch, Size = input.palletCount };
|
||||
List<WmsCarryH> items = await _wareHouseService.OutStockStrategyYCL(outStockStrategyInput);
|
||||
List<WmsPackOutstockD> wmsPackOutstockDs = new List<WmsPackOutstockD>();
|
||||
|
||||
if (items.Count == 0)
|
||||
await _db.Insertable(wmsPackOutstockH).ExecuteCommandAsync();
|
||||
|
||||
int locationIndex = 0;
|
||||
for (int i = 0; i < 可移转托数; i++)
|
||||
{
|
||||
throw new AppFriendlyException($@"没有可以出库的载具", 500);
|
||||
}
|
||||
|
||||
decimal qty = _db.Queryable<WmsCarryCode>().Where(r => items.Select(a => a.id).Contains(r.carry_id) && r.material_id == wmsPackOutstockD.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);
|
||||
}
|
||||
|
||||
InStockStrategyQuery inStockStrategyInput = new() { warehouse_id = WmsWareHouseConst.WAREHOUSE_F2BCQ_ID, Size = input.palletCount };
|
||||
List<BasLocation> endLocations = await _wareHouseService.InStockStrategy(inStockStrategyInput);
|
||||
if (endLocations.Count == 0)
|
||||
{
|
||||
throw new AppFriendlyException("没有可用的入库库位", 500);
|
||||
}
|
||||
|
||||
if (endLocations.Count() < input.palletCount)
|
||||
{
|
||||
throw new AppFriendlyException($@"可用的终点库位数量为{endLocations.Count()}个 下发数量为{input.palletCount}个 请检查终点库位的锁定和占用状态", 500);
|
||||
}
|
||||
|
||||
foreach (var wmsCarryH in items)
|
||||
{
|
||||
WmsCarryCode wmsCarryCode = await _db.Queryable<WmsCarryCode>().Where(r => r.carry_id == wmsCarryH.id).FirstAsync();
|
||||
BasLocation startLocation = await _db.Queryable<BasLocation>().Where(r => r.id == wmsCarryH.location_id).FirstAsync();
|
||||
|
||||
InStockStrategyQuery _inStockStrategyInput = new() { warehouse_id = WmsWareHouseConst.WAREHOUSE_F2BCQ_ID, Size = 1 };
|
||||
List<BasLocation> _endLocations = await _wareHouseService.InStockStrategy(_inStockStrategyInput);
|
||||
|
||||
BasLocation endLocation = _endLocations.First();
|
||||
if (endLocation == null)
|
||||
WmsCarryH wmsCarryH = carrys[i];
|
||||
WmsCarryCode wmsCarryCode = wmsCarryCodes.Where(r => r.carry_id == wmsCarryH.id).First();
|
||||
if (wmsCarryCode == null)
|
||||
{
|
||||
throw new AppFriendlyException($@"没有可用的终点库位!请检查终点库位的锁定和占用状态", 500);
|
||||
Logger.Information($"【WmsPackOutstockService-Distribute】载具{wmsCarryH.carry_code}没有绑定物料");
|
||||
continue;
|
||||
}
|
||||
WmsPackOutstockD wmsPackOutstockD = new WmsPackOutstockD();
|
||||
wmsPackOutstockD.bill_id = wmsPackOutstockH.id;
|
||||
wmsPackOutstockD.line_status = WmsWareHouseConst.BILLSTATUS_ON_ID;
|
||||
wmsPackOutstockD.material_id = wmsCarryCode.material_id;
|
||||
wmsPackOutstockD.material_code = wmsCarryCode.material_code;
|
||||
wmsPackOutstockD.material_specification = wmsCarryCode.material_specification;
|
||||
wmsPackOutstockD.unit_id = wmsCarryCode.unit_id;
|
||||
wmsPackOutstockD.qty = wmsCarryCode.codeqty;
|
||||
wmsPackOutstockD.code_batch = wmsCarryCode.code_batch;
|
||||
wmsPackOutstockD.carry_id = wmsCarryH.id;
|
||||
wmsPackOutstockD.carry_code = wmsCarryH.carry_code;
|
||||
wmsPackOutstockD.startlocation_id = wmsCarryH.location_id;
|
||||
wmsPackOutstockD.startlocation_code = wmsCarryH.location_code;
|
||||
wmsPackOutstockD.endlocation_id = endLocations[locationIndex].id;
|
||||
wmsPackOutstockD.endlocation_code = endLocations[locationIndex].location_code;
|
||||
locationIndex++;
|
||||
|
||||
wmsPackOutstockDs.Add(wmsPackOutstockD);
|
||||
}
|
||||
await _db.Insertable(wmsPackOutstockDs).ExecuteCommandAsync();
|
||||
|
||||
|
||||
foreach (WmsPackOutstockD wmsPackOutstockD in wmsPackOutstockDs)
|
||||
{
|
||||
CommonCreatePretaskInput commonCreatePretaskInput = new CommonCreatePretaskInput();
|
||||
commonCreatePretaskInput.startlocation_id = startLocation.id;
|
||||
commonCreatePretaskInput.endlocation_id = endLocation.id;
|
||||
commonCreatePretaskInput.startlocation_id = wmsPackOutstockD.startlocation_id;
|
||||
commonCreatePretaskInput.endlocation_id = wmsPackOutstockD.endlocation_id;
|
||||
commonCreatePretaskInput.task_type = WmsWareHouseConst.WMS_PRETASK_OUTSTOCK_TYPE_ID;
|
||||
commonCreatePretaskInput.biz_type = WmsWareHouseConst.BIZTYPE_WMSPACKOUTSTOCK_ID;
|
||||
commonCreatePretaskInput.require_id = input.source_id;
|
||||
commonCreatePretaskInput.carry_id = wmsCarryH.id;
|
||||
commonCreatePretaskInput.carry_code = wmsCarryH.carry_code;
|
||||
commonCreatePretaskInput.require_id = wmsPackOutstockD.id;
|
||||
commonCreatePretaskInput.carry_id = wmsPackOutstockD.carry_id;
|
||||
commonCreatePretaskInput.carry_code = wmsPackOutstockD.carry_code;
|
||||
commonCreatePretaskInput.isExcuteMission = false;
|
||||
|
||||
Entities.Dto.Outputs.Result res = await _wareHouseService.CommonCreatePretask(commonCreatePretaskInput, _db);
|
||||
@@ -246,18 +199,15 @@ namespace Tnb.WarehouseMgr
|
||||
}
|
||||
}
|
||||
|
||||
// 更新子表已下发数量
|
||||
await _db.Updateable<WmsPackOutstockD>().SetColumns(r => r.sendqty == r.sendqty + input.qty).Where(r => r.id == input.source_id).ExecuteCommandAsync();
|
||||
|
||||
await _db.Ado.CommitTranAsync();
|
||||
Logger.LogInformation($"【Distribute】 包材出库下发完成");
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -265,7 +215,8 @@ namespace Tnb.WarehouseMgr
|
||||
InvokeGenPretaskExcute();
|
||||
}
|
||||
|
||||
return await ToApiResult(HttpStatusCode.OK, "成功");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user