177 lines
8.2 KiB
C#
177 lines
8.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Aop.Api.Domain;
|
|
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Dtos.VisualDev;
|
|
using JNPF.Common.Enums;
|
|
using JNPF.FriendlyException;
|
|
using JNPF.Systems.Interfaces.System;
|
|
using JNPF.VisualDev;
|
|
using JNPF.VisualDev.Interfaces;
|
|
using Mapster;
|
|
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.Inputs;
|
|
using Tnb.WarehouseMgr.Entities.Entity;
|
|
using Tnb.WarehouseMgr.Interfaces;
|
|
|
|
namespace Tnb.WarehouseMgr
|
|
{
|
|
/// <summary>
|
|
/// 人工扫码入库记录
|
|
/// </summary>
|
|
[OverideVisualDev(ModuleConsts.MODULE_WmsArtificialInstock_ID)]
|
|
public class WmsArtificialInstockService : BaseWareHouseService
|
|
{
|
|
private readonly ISqlSugarClient _db;
|
|
private readonly IUserManager _userManager;
|
|
private readonly IBillRullService _billRullService;
|
|
private readonly IRunService _runService;
|
|
private readonly IVisualDevService _visualDevService;
|
|
private readonly IWmsPDAScanInStockService _wmsPDAScanInStock;
|
|
private readonly IWareHouseService _wareHouseService;
|
|
public WmsArtificialInstockService(
|
|
ISqlSugarRepository<WmsCarryH> repository,
|
|
IUserManager userManager,
|
|
IBillRullService billRullService,
|
|
IRunService runService,
|
|
IVisualDevService visualDevService,
|
|
IWmsPDAScanInStockService wmsPDAScanInStock,
|
|
IWareHouseService wareHouseService)
|
|
{
|
|
_db = repository.AsSugarClient();
|
|
_userManager = userManager;
|
|
_billRullService = billRullService;
|
|
_runService = runService;
|
|
_visualDevService = visualDevService;
|
|
_wmsPDAScanInStock = wmsPDAScanInStock;
|
|
_wareHouseService = wareHouseService;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 人工扫码入库
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
/// <exception cref="AppFriendlyException"></exception>
|
|
[HttpPost]
|
|
public async Task ArtificialInstock(ArtificialInstockInput input)
|
|
{
|
|
try
|
|
{
|
|
if (input == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(input));
|
|
}
|
|
|
|
await _db.Ado.BeginTranAsync();
|
|
|
|
BasLocation startlocationn = await _db.Queryable<BasLocation>().Where(r => r.location_code == input.startlocation_code).FirstAsync();
|
|
if (startlocationn == null)
|
|
{
|
|
throw new AppFriendlyException($"【ArtificialInstock】库位{input.startlocation_code}不存在", 500);
|
|
}
|
|
if (startlocationn.is_lock == 1)
|
|
{
|
|
throw new AppFriendlyException($"【ArtificialInstock】库位{input.startlocation_code}已锁定", 500);
|
|
}
|
|
WmsCarryH wmsCarryH = await _db.Queryable<WmsCarryH>().Where(r => r.carry_code == input.carry_code).FirstAsync();
|
|
if (wmsCarryH == null)
|
|
{
|
|
throw new AppFriendlyException($"【ArtificialInstock】载具{input.carry_code}不存在", 500);
|
|
}
|
|
if (wmsCarryH.is_lock == 1)
|
|
{
|
|
throw new AppFriendlyException($"【ArtificialInstock】载具{input.carry_code}已锁定", 500);
|
|
}
|
|
if (wmsCarryH.carry_status != "1")
|
|
{
|
|
throw new AppFriendlyException($"【ArtificialInstock】载具{input.carry_code}未绑定物料,托盘状态不是占用状态", 500);
|
|
}
|
|
|
|
BasLocation carryLoc = await _db.Queryable<BasLocation>().Where(r => r.id == wmsCarryH.location_id).FirstAsync();
|
|
if (carryLoc != null && carryLoc.is_type == "0")
|
|
{
|
|
throw new Exception($"托盘{wmsCarryH.carry_code}在存储库位中,不能绑定!");
|
|
}
|
|
|
|
switch (carryLoc.wh_id)
|
|
{
|
|
case WmsWareHouseConst.WAREHOUSE_YCL_ID:
|
|
{
|
|
await _wareHouseService.s_taskExecuteSemaphore_YCLInstock.WaitAsync();
|
|
try
|
|
{
|
|
|
|
var WmsCarryCode = _db.Queryable<WmsCarryCode>().Where(it => it.carry_id == wmsCarryH.id).OrderByDescending(it => it.id).First();
|
|
|
|
if (WmsCarryCode != null)
|
|
{
|
|
VisualDevModelDataCrInput input2 = new VisualDevModelDataCrInput();
|
|
input2.data = new Dictionary<string, object>();
|
|
input2.data.Add("barcode", input.carry_code);
|
|
input2.data.Add("codeqty", WmsCarryCode.codeqty);//条码数量
|
|
input2.data.Add("material_code", WmsCarryCode.material_code);
|
|
input2.data.Add("extras", input.startlocation_code);//location_code
|
|
input2.data.Add("warehouse_id", "1");//TEST
|
|
input2.data.Add("bill_code", "");//采购收货单号
|
|
input2.data.Add("code_batch", WmsCarryCode.code_batch!);//批次
|
|
input2.data.Add("material_specification", WmsCarryCode.material_specification!);//规格型号
|
|
input2.data.Add("container_no", WmsCarryCode.container_no!);//箱号
|
|
input2.data.Add("material_id", WmsCarryCode.material_id);
|
|
input2.data.Add("物料条码", WmsCarryCode.barcode);
|
|
input2.data.Add("id", null);
|
|
_wmsPDAScanInStock.ScanInStockByRedis(input2, _db).Wait();
|
|
|
|
WmsArtificialInstock wmsArtificialInstock = new WmsArtificialInstock();
|
|
wmsArtificialInstock.carry_id = wmsCarryH.id;
|
|
wmsArtificialInstock.carry_code = wmsCarryH.carry_code;
|
|
wmsArtificialInstock.org_id = input.org;
|
|
wmsArtificialInstock.create_id = input.create_id;
|
|
wmsArtificialInstock.create_time = DateTime.Now;
|
|
wmsArtificialInstock.location_id = startlocationn.id;
|
|
wmsArtificialInstock.location_code = startlocationn.location_code;
|
|
wmsArtificialInstock.warehouse_id = carryLoc.wh_id;
|
|
await _db.Insertable(wmsArtificialInstock).ExecuteCommandAsync();
|
|
}
|
|
else
|
|
{
|
|
throw new AppFriendlyException($"【ArtificialInstock】载具 {input.carry_code} 未绑定物料条码!", 500);
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
finally
|
|
{
|
|
_wareHouseService.s_taskExecuteSemaphore_YCLInstock.Release();
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
await _db.Ado.CommitTranAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.LogError($"【ArtificialInstock】 {ex.Message}");
|
|
Logger.LogError($"【ArtificialInstock】 {ex.StackTrace}");
|
|
await _db.Ado.RollbackTranAsync();
|
|
throw new AppFriendlyException($"【ArtificialInstock】人工扫码入库失败 {ex.Message}", 500);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|