Files
tnb.server/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAFeedingService.cs

125 lines
4.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using JNPF.Common.Core.Manager;
using JNPF.Common.Dtos.VisualDev;
using JNPF.Common.Enums;
using JNPF.FriendlyException;
using JNPF.Logging;
using JNPF.Systems.Interfaces.System;
using JNPF.VisualDev;
using JNPF.VisualDev.Entitys;
using JNPF.VisualDev.Interfaces;
using SqlSugar;
using Tnb.WarehouseMgr.Entities;
using Tnb.WarehouseMgr.Interfaces;
namespace Tnb.WarehouseMgr
{
/// <summary>
/// PDA投料记录
/// </summary>
[OverideVisualDev(ModuleConsts.MODULE_WMSFEEDINGRECORDPDA_ID)]
public class WmsPDAFeedingService : BaseWareHouseService, IPdaStroage
{
private readonly ISqlSugarClient _db;
private readonly IUserManager _userManager;
private readonly IBillRullService _billRullService;
private readonly IRunService _runService;
private readonly IVisualDevService _visualDevService;
private readonly IWmsCarryService _carryService;
public WmsPDAFeedingService(
ISqlSugarRepository<WmsCarryH> repository,
IUserManager userManager,
IBillRullService billRullService,
IRunService runService,
IVisualDevService visualDevService,
IWmsCarryService carryService)
{
_db = repository.AsSugarClient();
_userManager = userManager;
_billRullService = billRullService;
_runService = runService;
_visualDevService = visualDevService;
_carryService = carryService;
OverideFuncs.CreateAsync = WmsPDAFeedingRecord;
}
/// <summary>
/// PDA投料记录
/// </summary>
/// <param name="input">
/// 输入参数:
/// <br/>{
/// <br/> old_carry_id: 料箱ID
/// <br/> new_carry_id新载具ID
/// <br/>}
/// </param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
private async Task<dynamic> WmsPDAFeedingRecord(VisualDevModelDataCrInput input)
{
bool isOk = false;
try
{
await _db.Ado.BeginTranAsync();
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleConsts.MODULE_WMSFEEDINGRECORDPDA_ID, true);
await _runService.Create(templateEntity, input);
string? carryId = input.data.ContainsKey("carry_id") ? input.data["carry_id"]?.ToString() : "";
string? feedBoxCode = input.data.ContainsKey("feedbox_code") ? input.data["feedbox_code"]?.ToString() : "";
WmsCarryH carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.id == carryId);
WmsFeedbox? feedBox = await _db.Queryable<WmsFeedbox>().SingleAsync(it => it.feedbox_code == feedBoxCode);
WmsCarryMat? carryMaterial = await _db.Queryable<WmsCarryMat>().FirstAsync(it => it.carry_id == carryId);
List<WmsCarryCode> carryCodes = await _db.Queryable<WmsCarryCode>().Where(it => it.carry_id == carryId).ToListAsync();
if (carryMaterial != null && feedBox != null && carry != null)
{
//更新投料箱
feedBox.material_id = carryMaterial.material_id;
feedBox.material_code = carryMaterial.material_code;
feedBox.qty = carryMaterial.qty;
feedBox.batch = carryMaterial?.code_batch!;
feedBox.modify_id = _userManager.UserId;
feedBox.modify_time = DateTime.Now;
int row = await _db.Updateable(feedBox)
.UpdateColumns(it => new
{
it.material_id,
it.material_code,
it.qty,
it.batch,
it.modify_id,
it.modify_time
}).ExecuteCommandAsync();
//更新载具
row = await _carryService.UpdateNullCarry(carry).Unwrap();
isOk = row > 0;
if (!isOk)
{
throw Oops.Oh(ErrorCode.COM1001);
}
}
else
{
if (carryMaterial == null)
{
throw new AppFriendlyException("没有可用的载具", 500);
}
if (feedBox == null)
{
throw new AppFriendlyException("没有可用的投料箱", 500);
}
}
await _db.Ado.CommitTranAsync();
}
catch (Exception ex)
{
Log.Error("投料失败", ex);
await _db.Ado.RollbackTranAsync();
throw;
}
return isOk;
}
}
}