using Rhea.Common;
using Microsoft.AspNetCore.Http;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Tiger.Model;
using Apache.NMS;
using System.Drawing.Drawing2D;
using Tiger.Model.Sharetronic.Shelf;
using Tiger.IBusiness;
using Tiger.Model.MES.Yada;
using Apache.NMS.ActiveMQ.Commands;
using System.Diagnostics;
namespace Tiger.Business.WMS.Transaction
{
///
/// 半成品入库打印标签事务
///
public class In_SemiProd : WMSTransactionBase, IIn_SemiProd
{
public IIn_SemiProd Init(string id, string userCode, string apiHost, string orgCode)
{
TransID = id;
UserCode = userCode;
ApiHost = apiHost;
OrgCode = orgCode;
Logger.Console.Info($"Start {this.GetType().Name} Transaction[ID: {TransID}]");
return this;
}
#region Propertys & Variables
public string UserCode { get; set; }
public long UserId { get; set; }
public string OrgCode { get; set; }
public string LocationCode { get; set; }
public List Vitem { get; set; } = new();
public ScanShelfInfo CurScanShelf { get; set; }
#endregion
#region Functions
///
/// 扫描入口
///
public async Task> Scan(BaseInput input)
{
var action = new ApiAction(new ScanOutput());
try
{
if (input.SN.IsNullOrEmpty())
{
action.IsSuccessed = false;
action.LocaleMsg = Biz.L("WMS.RePrint.ScanItem.SnEmptyFailure");
return SetOutPutMqttMsg(action, input.Locale);
}
var LotNos = Biz.DataSource["YadaU9C"].Client.Ado.SqlQuery($"select *,'' as ID from mes_WhLotCodeQtyInfo where Bin = '{input.SN}'");
//Biz.DataSource["YadaU9C"].Client.Queryable().Where(t => t.Bin == input.SN).ToList();
CurScanShelf = new ScanShelfInfo();
// 查询货架信息
var whUnit = await Biz.Db.Queryable().Where(t => (t.SHELF_CODE.ToUpper() == input.SN || t.LOCATION_CODE.ToUpper() == input.SN) && t.AUTH_ORG == OrgCode).IncludesAllFirstLayer().FirstAsync();
if (!whUnit.IsNullOrEmpty() && whUnit.LOCATION_CODE == input.SN)
{
if (whUnit.IS_ACTIVE == "N")
{
action.IsSuccessed = false;
//action.LocaleMsg = Biz.L("扫描的储位[{0}]未启用");
action.LocaleMsg = Biz.L("WMS.Default.ScanShelf.ShelfOrLocationDisabled", input.SN);
return action;
}
if (whUnit.Shelf.IsLightShelf || whUnit.Location.IS_SINGLE == "Y")
{
var locationData = Biz.Db.Queryable().Where(q => q.LOCATION_ID == whUnit.LOCATION_ID && q.AUTH_ORG == OrgCode).First();
if (!locationData.IsNullOrEmpty())
{
action.IsSuccessed = false;
//action.LocaleMsg = Biz.L("储位[{0}]已存有物料[{1}],请检查系统库存信息");
action.LocaleMsg = Biz.L($"WMS.Default.ScanShelf.ItemAlreadyExistsInLocation", input.SN, locationData.SN);
return action;
}
}
CurScanShelf.Shelf = whUnit.Shelf;
CurScanShelf.Location = whUnit.Location;
CurScanShelf.WarehouseCode = whUnit.WH_CODE;
CurScanShelf.RegionCode = whUnit.REGION_CODE;
CurScanShelf.ShelfCode = whUnit.SHELF_CODE;
CurScanShelf.LocationCode = whUnit.LOCATION_CODE;
CurScanShelf.IsSmartRack = false;
LocationCode = whUnit.LOCATION_CODE;
}
else {
action.IsSuccessed = false;
//action.LocaleMsg = Biz.L("请输入或扫描有效的货架/储位码");
action.LocaleMsg = Biz.L("WMS.Default.ScanShelf.ShelfCanNotEmpty");
return action;
}
var temps = new List();
foreach (var item in LotNos)
{
var temp = new TemplateInput
{
custCode="",
itemCode= item.ItemCode,
itemDesc= item.Description,
sapItemCode= item.SapCode,
WoBatch = item.LotCode,
batchQty= item.StoreQty,
qrCode="",
};
temps.Add(temp);
}
var y = Biz.Db.Storageable(LotNos, UserCode)
.WhereColumns(t => new { t.ItemCode, t.LotCode })
.ToStorage();
y.AsInsertable.ExecuteCommand();
y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
action.Data.Data = temps;
action.LocaleMsg = Biz.L("WMS.RePrint.ScanItem.ScanSuccessed");
}
catch (Exception ex)
{
//action.CatchExceptionWithLog(ex, $"扫描[{input.SN}]异常");
action.CatchExceptionWithLog(ex, Biz.L("WMS.RePrint.Scan.ScanException", input.SN));
}
return SetOutPutMqttMsg(action, input.Locale);
}
public async Task> ScanItem(BaseInput input)
{
var action = new ApiAction(new ScanOutput());
try
{
}
catch (Exception ex)
{
action.CatchExceptionWithLog(ex, Biz.L("半成品入库失败"));
}
return action;
}
#endregion
public override bool Close(bool needSaveHistoryLog = false)
{
needSaveHistoryLog = true;
//保存操作日志
this.IsFinished = true;
return IsFinished ? base.Close(needSaveHistoryLog) : IsFinished;
}
}//endClass
}