using Admin.NET.Core.Service;
|
using Admin.NET.Application.Entity;
|
using Microsoft.AspNetCore.Http;
|
using System.Data;
|
using System.Web;
|
using System.Text;
|
using DocumentFormat.OpenXml.Office.CustomUI;
|
using Microsoft.CodeAnalysis.Operations;
|
using Admin.NET.Application.Service.WmsTask.WmsRbLineTask.Dto;
|
using Furion.DatabaseAccessor;
|
|
namespace Admin.NET.Application;
|
/// <summary>
|
/// 操作任务服务
|
/// </summary>
|
[ApiDescriptionSettings(ApplicationConst.WmsTaskGroupName, Order = 100)]
|
public class WmsOperationTaskService : IDynamicApiController, ITransient
|
{
|
private readonly SqlSugarRepository<WmsRbLineTask> _rep;
|
private readonly SqlSugarRepository<WmsStockQuan> _wmsStockQuanRep;
|
private readonly SqlSugarRepository<Mes_Package_Gather> _mesPackageGatherRep;
|
private readonly SqlSugarRepository<SysConfig> _sysConfigRep;
|
private readonly SqlSugarRepository<Mes_BatchOrderUPI_New> _mesBatchOrderUpiRep;
|
private readonly SqlSugarRepository<Mes_Order_Gather> _mesOrderGatherRep;
|
private readonly SqlSugarRepository<WmsRecordUpiProcess> _wmsRecordUpiProcessRep;
|
private readonly SqlSugarRepository<WmsRecordPackageProcess> _wmsRecordPackageProcessRep;
|
private readonly SqlSugarRepository<Mes_Upi_LineQueue> _mes_Upi_LineQueueRep;
|
|
public WmsOperationTaskService(
|
SqlSugarRepository<Mes_Upi_LineQueue> mes_Upi_LineQueueRep,
|
SqlSugarRepository<WmsRbLineTask> rep, SqlSugarRepository<WmsStockQuan> wmsStockQuanRep
|
, SqlSugarRepository<Mes_Package_Gather> mesPackageGatherRep
|
, SqlSugarRepository<SysConfig> sysConfigRep
|
, SqlSugarRepository<Mes_BatchOrderUPI_New> mesBatchOrderUpiRep
|
, SqlSugarRepository<Mes_Order_Gather> mesOrderGatherRep
|
, SqlSugarRepository<WmsRecordUpiProcess> wmsRecordUpiProcessRep
|
, SqlSugarRepository<WmsRecordPackageProcess> wmsRecordPackageProcessRep
|
)
|
{
|
_sysConfigRep = sysConfigRep;
|
_mesPackageGatherRep = mesPackageGatherRep;
|
_rep = rep;
|
_wmsStockQuanRep = wmsStockQuanRep;
|
_mesBatchOrderUpiRep = mesBatchOrderUpiRep;
|
_mesOrderGatherRep = mesOrderGatherRep;
|
_wmsRecordUpiProcessRep = wmsRecordUpiProcessRep;
|
_wmsRecordPackageProcessRep = wmsRecordPackageProcessRep;
|
_mes_Upi_LineQueueRep = mes_Upi_LineQueueRep;
|
}
|
|
|
|
/// <summary>
|
/// 强制出库
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[ApiDescriptionSettings(Name = "ForceOutbound")]
|
[Description("WmsOperationTask/ForceOutbound")]
|
[UnitOfWork]
|
public async Task ForceOutbound(ForceOutboundInput input)
|
{
|
if (input == null || input.PackageCodeList?.Count == 0)
|
{
|
throw Oops.Oh("参数不能为空");
|
}
|
List<WmsStockQuan> updateQuanList = new List<WmsStockQuan>();
|
foreach (var item in input.PackageCodeList)
|
{
|
var quanList = await _wmsStockQuanRep.AsQueryable().Where(x => x.PackageCode == item).ToListAsync();
|
var isExist = quanList.Where(x => x.StockStatus == StockStatusEnum.齐包待出库).Count();
|
if (isExist > 0)
|
{
|
throw Oops.Oh($"包{item}中其中有板状态是'{StockStatusEnum.齐包待出库.ToString()}',不允许强制出库");
|
}
|
|
//更新状态
|
foreach (var quan in quanList)
|
{
|
quan.StockStatus = StockStatusEnum.人工强制待出库;
|
quan.StockStatusName = StockStatusEnum.人工强制待出库.ToString();
|
quan.UpdateTime = DateTime.Now;
|
quan.OperReason = "人工强制待出库";
|
}
|
updateQuanList.AddRange(quanList);
|
}
|
|
await _wmsStockQuanRep.UpdateRangeAsync(updateQuanList);
|
|
}
|
|
/// <summary>
|
/// 判断齐套
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[ApiDescriptionSettings(Name = "ValdateQiTao")]
|
[Description("WmsOperationTask/ValdateQiTao")]
|
[UnitOfWork]
|
public async Task<ValidateQiTaoOutput> ValdateQiTao(ValidateQiTaoInput input)
|
{
|
ValidateQiTaoOutput output = new ValidateQiTaoOutput();
|
if (input == null || input.PackageCode == null)
|
{
|
throw Oops.Oh("参数不能为空");
|
}
|
|
var package = await _mesPackageGatherRep.AsQueryable().Where(x => x.PackageCode == input.PackageCode).FirstAsync();
|
if (package == null)
|
{
|
throw Oops.Oh($"没有找到包号{input.PackageCode}的汇总数据");
|
}
|
|
|
|
var sysConfig = await _sysConfigRep.GetFirstAsync(x => x.Code == CommonConst.WmsBZ30_QiTao);
|
if (sysConfig == null)
|
{
|
throw Oops.Oh($"没有配置 判断齐套 值");
|
}
|
if (!string.IsNullOrEmpty(sysConfig.Value) && sysConfig.Value.Trim() != "无")
|
{
|
throw Oops.Oh($"判断齐套值已经存在值{sysConfig.Value},不允许操作");
|
}
|
|
//记录工作时间和工作人
|
var curUserName = App.User.FindFirst(ClaimConst.RealName)?.Value;
|
|
var setValue = "";
|
var _QiTaoReuslt = "";
|
var other_orderList = await _mesPackageGatherRep.AsQueryable().Where(x => x.Info5 == package.Info5 && x.PackageCode != input.PackageCode).ToListAsync();
|
var num = other_orderList.Where(x => x.UpiStatus == UpiStatusEnum.初始 || x.UpiStatus == UpiStatusEnum.不齐包).Count();
|
if (num > 0)
|
{
|
//不齐套
|
setValue = $"{input.PackageCode}|不齐套|" + curUserName;
|
_QiTaoReuslt = "不齐套";
|
}
|
else
|
{
|
setValue = $"{input.PackageCode}|齐套|" + curUserName;
|
_QiTaoReuslt = "齐套";
|
}
|
|
|
sysConfig.Value = setValue;
|
await _sysConfigRep.UpdateAsync(sysConfig);
|
//*/
|
|
|
var sysConfig_wms_unline_oper = await _sysConfigRep.GetFirstAsync(x => x.Code == CommonConst.wms_unline_oper);
|
if (sysConfig_wms_unline_oper == null)
|
{
|
throw Oops.Oh($"没有配置 包装下线操作人 值");
|
}
|
if (sysConfig_wms_unline_oper.Value != curUserName)
|
{
|
sysConfig_wms_unline_oper.Value = curUserName;
|
await _sysConfigRep.UpdateAsync(sysConfig_wms_unline_oper);
|
|
var sysConfig_wms_unline_time = await _sysConfigRep.GetFirstAsync(x => x.Code == CommonConst.wms_unline_time);
|
if (sysConfig_wms_unline_time == null)
|
{
|
throw Oops.Oh($"没有配置 包装下线登陆时间 值");
|
}
|
sysConfig_wms_unline_time.Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
await _sysConfigRep.UpdateAsync(sysConfig_wms_unline_time);
|
}
|
|
|
output = package.Adapt<ValidateQiTaoOutput>();
|
output.QiTaoReuslt = _QiTaoReuslt;
|
return output;
|
}
|
|
|
/// <summary>
|
/// 核对标签
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[ApiDescriptionSettings(Name = "ValdateLabel")]
|
[Description("WmsOperationTask/ValdateLabel")]
|
[UnitOfWork]
|
public async Task<Mes_Package_Gather> ValdateLabel(ValidateLabelInput input)
|
{
|
if (input == null || input.PackageCode == null || input.Upi == null)
|
{
|
throw Oops.Oh("参数不能为空");
|
}
|
|
var singleUpi = await _mesBatchOrderUpiRep.AsQueryable().Where(x => x.UPI == input.Upi).FirstAsync();
|
if (singleUpi == null)
|
{
|
throw Oops.Oh($"没有找到部件条码{input.Upi}的数据");
|
}
|
if (singleUpi.PackageCode != input.PackageCode)
|
{
|
throw Oops.Oh($"部件条码{input.Upi}所属包是{singleUpi.PackageCode},跟扫描的包号{input.PackageCode}不符");
|
}
|
|
var singlePackage = await _mesPackageGatherRep.AsQueryable().Where(x => x.PackageCode == input.PackageCode).FirstAsync();
|
if (singlePackage == null)
|
{
|
throw Oops.Oh($"没有找到包号{input.PackageCode}的汇总数据");
|
}
|
|
WmsRecordPackageProcess wmsRecordPackage = new WmsRecordPackageProcess();
|
wmsRecordPackage = singlePackage.Adapt<WmsRecordPackageProcess>();
|
wmsRecordPackage.CreateTime = DateTime.Now;
|
wmsRecordPackage.Location = "BZ29";
|
wmsRecordPackage.OperRemark = "核对标签";
|
await _wmsRecordPackageProcessRep.InsertAsync(wmsRecordPackage);
|
|
WmsRecordUpiProcess wmsRecordUpi = new WmsRecordUpiProcess();
|
wmsRecordUpi = singleUpi.Adapt<WmsRecordUpiProcess>();
|
wmsRecordUpi.CreateTime = DateTime.Now;
|
wmsRecordUpi.Location = "BZ29";
|
wmsRecordUpi.OperRemark = "核对标签";
|
await _wmsRecordUpiProcessRep.InsertAsync(wmsRecordUpi);
|
|
return singlePackage;
|
}
|
|
|
/// <summary>
|
/// NG包下线
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[ApiDescriptionSettings(Name = "UnlineForNGPackage")]
|
[Description("WmsOperationTask/UnlineForNGPackage")]
|
[UnitOfWork]
|
public async Task UnlineForNGPackage(UnlineForNGPackageInput input)
|
{
|
if (input == null)
|
{
|
throw Oops.Oh("参数不能为空");
|
}
|
if (string.IsNullOrEmpty(input.PackageCode))
|
{
|
throw Oops.Oh("包号不能为空");
|
}
|
if (string.IsNullOrEmpty(input.Reason))
|
{
|
throw Oops.Oh("原因不能为空");
|
}
|
|
var singlePackage = await _mesPackageGatherRep.AsQueryable().Where(x => x.PackageCode == input.PackageCode).FirstAsync();
|
if (singlePackage == null)
|
{
|
throw Oops.Oh($"没有找到包号{input.PackageCode}的汇总数据");
|
}
|
|
singlePackage.UpiFlag = UpiFlagEnum.NG;
|
singlePackage.UpdateTime = DateTime.Now;
|
singlePackage.UpiStatus = UpiStatusEnum.已下线;
|
singlePackage.AreaCode = AreaCodeEnum.下线区域;
|
|
var upiLineQueueList = await _mes_Upi_LineQueueRep.AsQueryable().Where(x => x.PackageCode == input.PackageCode).ToListAsync();
|
if (upiLineQueueList?.Count > 0)
|
{
|
await _mes_Upi_LineQueueRep.DeleteAsync(upiLineQueueList);
|
}
|
|
var upiList = await _mesBatchOrderUpiRep.AsQueryable().Where(x => x.PackageCode == input.PackageCode).ToListAsync();
|
if (upiList == null)
|
{
|
throw Oops.Oh($"没有找到包号{input.PackageCode}的板件数据");
|
}
|
foreach (var item in upiList)
|
{
|
item.UpiFlag = UpiFlagEnum.NG;
|
item.UpdateTime = DateTime.Now;
|
item.UpiStatus = UpiStatusEnum.已下线;
|
item.AreaCode = AreaCodeEnum.下线区域;
|
|
WmsRecordUpiProcess wmsRecordUpi = new WmsRecordUpiProcess();
|
wmsRecordUpi = item.Adapt<WmsRecordUpiProcess>();
|
wmsRecordUpi.CreateTime = DateTime.Now;
|
wmsRecordUpi.Location = "";
|
wmsRecordUpi.OperRemark = "NG下线";
|
await _wmsRecordUpiProcessRep.InsertAsync(wmsRecordUpi);
|
}
|
|
|
WmsRecordPackageProcess wmsRecordPackage = new WmsRecordPackageProcess();
|
wmsRecordPackage = singlePackage.Adapt<WmsRecordPackageProcess>();
|
wmsRecordPackage.Location = "";
|
wmsRecordPackage.OperRemark = "NG下线";
|
await _wmsRecordPackageProcessRep.InsertAsync(wmsRecordPackage);
|
|
|
await _mesPackageGatherRep.UpdateAsync(singlePackage);
|
await _mesBatchOrderUpiRep.UpdateRangeAsync(upiList);
|
|
}
|
|
}
|