Files
tnb.server/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptycarryInstockLogService.cs
2024-07-18 10:29:56 +08:00

124 lines
4.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JNPF.Common.Core.Manager;
using JNPF.Common.Dtos.VisualDev;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using Tnb.Common.Utils;
using Tnb.QcMgr.Entities.Enums;
using Tnb.QcMgr.Entities;
using Tnb.WarehouseMgr.Entities;
using Tnb.WarehouseMgr.Entities.Dto;
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
using Tnb.WarehouseMgr.Interfaces;
using Tnb.QcMgr.Interfaces;
using Tnb.WarehouseMgr.Entities.Consts;
using JNPF.Common.Enums;
using JNPF.FriendlyException;
using Microsoft.Extensions.Logging;
using Tnb.ProductionMgr.Entities;
using Tnb.WarehouseMgr.Entities.Entity;
using Npgsql;
using Tnb.WarehouseMgr.Entities.Enums;
using Tnb.ProductionMgr.Entities.Dto;
using JNPF.VisualDev;
using System.Runtime.InteropServices;
using Tnb.BasicData.Entities;
using Microsoft.AspNetCore.Authorization;
namespace Tnb.WarehouseMgr
{
[OverideVisualDev(ModuleConsts.MODULE_WMSEMPTYCARRYINSTOCK_ID)]
public class WmsEmptycarryInstockLogService : BaseWareHouseService,IWmsEmptycarryInstockLogService
{
private readonly ISqlSugarClient _db;
public WmsEmptycarryInstockLogService(ISqlSugarRepository<WmsEmptycarryInstockLog> repository)
{
_db = repository.AsSugarClient();
}
/// <summary>
/// 人工空托盘入库
/// </summary>
/// <param name="input">
///
/// </param>
/// <returns></returns>
[HttpPost, NonUnify, AllowAnonymous]
public async Task<Tnb.WarehouseMgr.Entities.Dto.Outputs.Result> Instock(WmsEmptycarryInstockServiceInstockInput input)
{
try
{
if (string.IsNullOrEmpty(input.location_code))
{
throw new Exception("请扫描入库库位");
}
if (string.IsNullOrEmpty(input.carry_code))
{
throw new Exception("请扫描载具");
}
await _db.Ado.BeginTranAsync();
WmsCarryH wmsCarryH = await _db.Queryable<WmsCarryH>().Where(r => r.carry_code == input.carry_code).FirstAsync();
BasLocation basLocation = await _db.Queryable<BasLocation>().Where(r => r.location_code == input.location_code).FirstAsync();
if (wmsCarryH.is_lock == 1)
{
throw new Exception($"载具{wmsCarryH.carry_code}已锁定");
}
//if (wmsCarryH.carry_status == "1")
//{
// throw new Exception($"载具{wmsCarryH.carry_code}已占用");
//}
if (basLocation.is_lock == 1)
{
throw new Exception($"库位{basLocation.location_code}已锁定");
}
if (basLocation.is_use == "1")
{
throw new Exception($"库位{basLocation.location_code}已占用");
}
BasWarehouse basWarehouse = await _db.Queryable<BasWarehouse>().Where(r => r.id == basLocation.wh_id).FirstAsync();
wmsCarryH.location_id = basLocation.id;
wmsCarryH.location_code = basLocation.location_code;
basLocation.is_use = "1";
await _db.Updateable(wmsCarryH).UpdateColumns(r => new { r.location_id , r.location_code}).ExecuteCommandAsync();
await _db.Updateable(basLocation).UpdateColumns(r => new { r.is_use }).ExecuteCommandAsync();
WmsEmptycarryInstockLog wmsEmptycarryInstockLog = new WmsEmptycarryInstockLog();
wmsEmptycarryInstockLog.carry_id = wmsCarryH.id;
wmsEmptycarryInstockLog.carry_code = wmsCarryH.carry_code;
wmsEmptycarryInstockLog.location_id = basLocation.id;
wmsEmptycarryInstockLog.location_code = basLocation.location_code;
wmsEmptycarryInstockLog.org_id = input.org_id;
wmsEmptycarryInstockLog.create_id =input.create_id;
wmsEmptycarryInstockLog.create_time = DateTime.Now;
wmsEmptycarryInstockLog.wh_id = basWarehouse.id;
wmsEmptycarryInstockLog.wh_name = basWarehouse.whname;
await _db.Insertable(wmsEmptycarryInstockLog).ExecuteCommandAsync();
await _db.Ado.CommitTranAsync();
return await ToApiResult(HttpStatusCode.OK, "成功");
}
catch (Exception ex)
{
Logger.LogInformation("【WmsEmptycarryInstockService-Instock】" + ex.Message);
Logger.LogInformation("【WmsEmptycarryInstockService-Instock】" + ex.StackTrace);
await _db.Ado.RollbackTranAsync();
return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message);
}
}
}
}