原材料仓退料 退料单同步等
This commit is contained in:
@@ -90,6 +90,10 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
return await Return_到缓存仓(input, wmsCarryH, wmsPrdReturnH);
|
||||
}
|
||||
else if (wmsCarryH.carrystd_id == "26032423715365")
|
||||
{
|
||||
return await Return_到原材料仓(input, wmsCarryH, wmsPrdReturnH);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogError($"【PrdReturn】当前载具的规格id是{wmsCarryH.carrystd_id} 无法处理此类型的载具!");
|
||||
@@ -340,6 +344,145 @@ namespace Tnb.WarehouseMgr
|
||||
return await ToApiResult(HttpStatusCode.OK, "成功");
|
||||
}
|
||||
|
||||
async Task<Result> Return_到原材料仓(PrdReturnInput input, WmsCarryH wmsCarryH, WmsPrdReturnH wmsPrdReturnH)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _wareHouseService.s_taskExecuteSemaphore_YCLInstock.WaitAsync();
|
||||
BasLocation startlocation = _db.Queryable<BasLocation>().Where(r => r.id == input.startlocation_id).First();
|
||||
if (startlocation == null)
|
||||
{
|
||||
Logger.LogWarning($"【PrdReturn】不存在id为{input.startlocation_id}的库位!");
|
||||
throw new AppFriendlyException($"【PrdReturn】不存在id为{input.startlocation_id}的库位!", 500);
|
||||
}
|
||||
if (string.IsNullOrEmpty(input.carry_code))
|
||||
{
|
||||
Logger.LogWarning($"【PrdReturn】托盘不能为空!{input.carry_code}");
|
||||
throw new AppFriendlyException($"【PrdReturn】托盘不能为空!{input.carry_code}!", 500);
|
||||
}
|
||||
|
||||
InStockStrategyQuery inStockStrategyInput = new() { warehouse_id = "1", Size = 1, AvoidBusyPassage = true, Region_id = WmsWareHouseConst.REGION_YCLCache_ID };
|
||||
List<BasLocation> endLocations = await _wareHouseService.InStockStrategy(inStockStrategyInput);
|
||||
if (endLocations.Count == 0)
|
||||
{
|
||||
throw new AppFriendlyException("没有可以回库的库位", 500);
|
||||
}
|
||||
|
||||
if (endLocations.Count() == 0)
|
||||
{
|
||||
Logger.LogWarning($"【PrdReturn】没有可用的终点库位");
|
||||
throw new AppFriendlyException($"【PrdReturn】没有可用的终点库位!", 500);
|
||||
}
|
||||
|
||||
BasLocation endlocation = endLocations.First();
|
||||
|
||||
CarryMaterialBindInput carryMaterialBindInput = new CarryMaterialBindInput();
|
||||
carryMaterialBindInput.carrycode = wmsCarryH.carry_code;
|
||||
carryMaterialBindInput.create_id = input.create_id;
|
||||
|
||||
List<CarryMaterialDetail> carryMaterialDetails = new List<CarryMaterialDetail>();
|
||||
|
||||
|
||||
List<WmsTempCode> wmsTempCodes = await _db.Queryable<WmsTempCode>().Where(r => input.matdetails.Select(x => x.barcode).Contains(r.barcode)).ToListAsync();
|
||||
|
||||
await _db.Ado.BeginTranAsync();
|
||||
|
||||
foreach (PrdReturnMatDetail prdReturnMatDetail in input.matdetails)
|
||||
{
|
||||
WmsTempCode wmsTempCode = _db.Queryable<WmsTempCode>().Where(r => r.barcode == prdReturnMatDetail.barcode).First();
|
||||
if (wmsTempCode == null)
|
||||
{
|
||||
throw new AppFriendlyException($"【PrdReturn】条码{prdReturnMatDetail.barcode}!", 500);
|
||||
}
|
||||
CarryMaterialDetail carryMaterialDetail = new CarryMaterialDetail();
|
||||
carryMaterialDetail.material_id = wmsTempCode.material_id;
|
||||
carryMaterialDetail.material_code = wmsTempCode.material_code;
|
||||
carryMaterialDetail.codeqty = prdReturnMatDetail.qty;
|
||||
wmsTempCode.codeqty = prdReturnMatDetail.qty;
|
||||
carryMaterialDetail.code_batch = wmsTempCode.code_batch;
|
||||
carryMaterialDetail.barcode = wmsTempCode.barcode;
|
||||
carryMaterialDetail.unit_id = wmsTempCode.unit_id;
|
||||
carryMaterialDetails.Add(carryMaterialDetail);
|
||||
}
|
||||
carryMaterialBindInput.details = carryMaterialDetails;
|
||||
await _wmsCarryBindService.CarryMaterialBind(carryMaterialBindInput, _db);
|
||||
|
||||
await _db.Updateable(wmsTempCodes).ExecuteCommandAsync();
|
||||
|
||||
var memberCarryCodes = _db.Queryable<WmsCarryH>()
|
||||
.InnerJoin<WmsCarryCode>((a, b) => a.id == b.carry_id)
|
||||
.Where((a, b) => a.id == wmsCarryH.id).Select((a, b) => new
|
||||
{
|
||||
carry_code = a.carry_code,
|
||||
barcode = b.barcode,
|
||||
material_id = b.material_id,
|
||||
material_code = b.material_code,
|
||||
}).ToList();
|
||||
|
||||
List<string> matIds = memberCarryCodes.Select(r => r.material_id).Distinct().ToList();
|
||||
|
||||
// 匹配生产退料单明细的物料种类
|
||||
List<string> existsMatIds = _db.Queryable<WmsPrdReturnD>().Where(r => r.bill_id == input.source_id).Select(r => r.material_id).Distinct().ToList();
|
||||
List<string> notExistsMatIds = matIds.Where(r => !existsMatIds.Contains(r)).ToList();
|
||||
|
||||
if (notExistsMatIds.Count() > 0)
|
||||
{
|
||||
var existsMat = memberCarryCodes.Where(r => notExistsMatIds.Contains(r.material_id)).Select(r => new
|
||||
{
|
||||
carry_code = r.carry_code,
|
||||
barcode = r.barcode,
|
||||
});
|
||||
|
||||
string msg = "";
|
||||
foreach (var row in existsMat)
|
||||
{
|
||||
msg += $",托盘{row.carry_code} 条码{row.barcode}";
|
||||
}
|
||||
Logger.LogWarning($"【PrdReturn】存在装有与生产退料单明细不匹配物料的托盘,请检查! {msg.Trim(',')}");
|
||||
throw new AppFriendlyException($"存在装有与生产退料单明细不匹配物料的托盘,请检查!{msg.Trim(',')}", 500);
|
||||
}
|
||||
|
||||
WmsPretaskH wmsPretaskH = _db.Queryable<WmsPretaskH>().Where(r => r.carry_code == wmsCarryH.carry_code && r.status != WmsWareHouseConst.PRETASK_BILL_STATUS_COMPLE_ID && r.status != WmsWareHouseConst.PRETASK_BILL_STATUS_CANCEL_ID).First();
|
||||
if (wmsPretaskH != null)
|
||||
{
|
||||
Logger.LogWarning($"【PrdReturn】此托盘{wmsCarryH.carry_code}存在未完成的预任务{wmsPretaskH.bill_code}!");
|
||||
throw new AppFriendlyException($"此托盘{wmsCarryH.carry_code}存在未完成的预任务{wmsPretaskH.bill_code}!", 500);
|
||||
}
|
||||
|
||||
|
||||
Logger.LogInformation($"【PrdReturn】开始生成预任务");
|
||||
CommonCreatePretaskInput commonCreatePretaskInput = new();
|
||||
commonCreatePretaskInput.startlocation_id = startlocation.id;
|
||||
commonCreatePretaskInput.endlocation_id = endlocation.id;
|
||||
commonCreatePretaskInput.source_id = input.source_id;
|
||||
commonCreatePretaskInput.carry_id = wmsCarryH.id;
|
||||
commonCreatePretaskInput.carry_code = input.carry_code;
|
||||
commonCreatePretaskInput.task_type = "";
|
||||
commonCreatePretaskInput.biz_type = WmsWareHouseConst.BIZTYPE_PRDRETURN_ID;
|
||||
|
||||
var res = await _wareHouseService.CommonCreatePretask(commonCreatePretaskInput);
|
||||
if (res.code != JNPF.Common.Enums.HttpStatusCode.OK)
|
||||
{
|
||||
Logger.LogInformation($"【PrdReturn】生成预任务失败 载具 {input.carry_code}");
|
||||
throw new AppFriendlyException($"生成预任务失败 载具 {input.carry_code}", 500);
|
||||
}
|
||||
Logger.LogWarning($"【PrdReturn】生成预任务成功");
|
||||
await _db.Ado.CommitTranAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError("【PrdReturn】" + ex.Message);
|
||||
Logger.LogError("【PrdReturn】" + ex.StackTrace);
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_wareHouseService.s_taskExecuteSemaphore_YCLInstock.Release();
|
||||
}
|
||||
return await ToApiResult(HttpStatusCode.OK, "成功");
|
||||
}
|
||||
|
||||
public override async Task ModifyAsync(WareHouseUpInput input)
|
||||
{
|
||||
if (input == null)
|
||||
|
||||
Reference in New Issue
Block a user