using Rhea.Common; using Tiger.Model.Minsun; 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; namespace Tiger.Business.WMS.Transaction { /// /// 生产领料事务 /// public class ItemQuery : WMSTransactionBase, IItemQuery { public IItemQuery 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 List Suggests { get; set; } = new(); public List Vitem { get; set; } = new(); public List CurPoolList => Suggests.Where(q => !q.poolItem.IsNullOrEmpty()).Select(q => q.poolItem).ToList(); public Inventory CurInv { get; set; } public BIZ_ERP_PROD_OUT req { get; set; } public ReqType CurReqType { get; set; } public List dtls { get; set; } = new(); public bool isExceed { get; set; } public ProductionPickToMes toMes { get; set; } public bool his_isComplete { get; set; } public bool isCutting { get; set; } public decimal cutQty { get; set; } public BIZ_WMS_TRANSFER transferH = null; public BIZ_WMS_TRANSFER cTransferH = null; public BIZ_WMS_TRANSFER_DTL transferDtl = null; public BIZ_WMS_TRANSFER_SN transferSn = null; #endregion #region Functions /// /// 物料汇总查询 /// /// /// public QueryItemView QueryItemSum(QueryItemInput input) { var barcode = new Barcode(input.SN); var ItemCode = Biz.Db.Queryable().ByAuth(input.AuthOption).Where(q => q.SN == barcode.SN).First()?.ITEM_CODE ?? (input.IsK.IsNullOrEmpty() ? input.SN : ((((bool)input.IsK && !barcode.ItemCode.IsNullOrEmpty(input.SN).StartsWith("K")) ? "K" : "") + barcode.ItemCode.IsNullOrEmpty(input.SN))); //Suggests[0].Item.ITEM_CODE = ItemCode; var itemInfo = Biz.Db.Queryable().Where(q => q.ITEM_CODE == ItemCode).First(); if (!itemInfo.IsNullOrEmpty()) { var sumInfo = Biz.Db.Queryable().Where(q => q.ITEM_CODE == ItemCode && q.STATUS == WMS_ITEM.STATUSs.InStore.GetValue()) .ByAuth(input.AuthOption).GroupBy(q => new { q.WH_CODE, q.ITEM_CODE }).Select(q => new { WH_CODE = q.WH_CODE, SumQty = SqlFunc.AggregateSum(q.QTY) }).ToList(); var items = Biz.Db.Queryable().Where(q => q.ITEM_CODE == ItemCode && q.STATUS == WMS_ITEM.STATUSs.InStore.GetValue()) .ByAuth(input.AuthOption).ToList(); QueryItemView view = new() { ItemCode = ItemCode, ItemName = itemInfo?.ITEM_NAME, SumInfo = $"{string.Join("\r\n", sumInfo.Select(q => $"{q.WH_CODE} 总库存: {(double)q.SumQty} 盘数:{items.Count}"))}" }; Vitem = items; return view; } else { throw new Exception("物料编码不存在"); } } /// /// 物料汇总明细查询 /// /// /// public ApiAction> GetQueryItemSumDtl(BasePageInput input) { var action = new ApiAction>(); //var query = Biz.Db.Queryable().ByAuth(input.AuthOption).Where(q => q.ITEM_CODE == Vitem.Select(q=>q.ITEM_CODE).FirstOrDefault()&&q.STATUS==WMS_ITEM.STATUSs.InStore.GetValue()).OrderByDescending(o=>o.LOCATION_CODE).ToPage(input.pageIndex, input.pageSize); action.Data = new PageAble(); action.Data.pageSize = input.pageSize; action.Data.pageIndex=input.pageIndex; action.Data.totals = Vitem.Count; action.Data.data = Vitem.Skip((input.pageIndex-1)*input.pageSize).Take(input.pageSize).ToList(); //action.Data = query; return action; } /// /// 领料单推荐所有物料亮灯 /// /// /// public async Task> LightAll(LightEntityInput light) { var action = new ApiAction(); try { light.Color= light.Color == LedColor.NoColor ? LedColor.Blue : light.Color; var list = Vitem.Where(q => q.SHELF_TYPE == WMS_SHELF.SHELF_TYPEs.Smart.GetValue() || q.SHELF_TYPE == WMS_SHELF.SHELF_TYPEs.QRCode.GetValue()); if (list.Any()) { foreach (var item in Vitem.Select(s=>s.SHELF_CODE).Distinct()) { await Share.Shelf.LightMulti(TransID, light.Color,item, list.Where(q=>q.SHELF_CODE==item).Select(x => x.LEDID).ToList()); action.LocaleMsg = Biz.L("亮灯成功,亮灯颜色[{0}]", light.Color.GetDesc()); } } else { action.LocaleMsg = Biz.L($"无需亮灯,推荐的物料不在智能货架上"); } } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"亮灯异常"); } return action; } /// /// 灭灯 /// /// public async Task CloseLight() { var action = new ApiAction(); try { //灭灯 var list = Vitem.Where(q => q.SHELF_TYPE == WMS_SHELF.SHELF_TYPEs.Smart.GetValue() || q.SHELF_TYPE == WMS_SHELF.SHELF_TYPEs.QRCode.GetValue()); if (list.Any()) { foreach (var item in Vitem.Select(s => s.SHELF_CODE).Distinct()) { await Share.Shelf.DownMulti(TransID, item, list.Where(q => q.SHELF_CODE == item).Select(x => x.LEDID).ToList()); action.LocaleMsg = Biz.L("灭灯成功"); } } } catch (Exception ex) { action.CatchExceptionWithLog(ex, $"亮灯异常"); } return action; } #endregion public override bool Close(bool needSaveHistoryLog = false) { needSaveHistoryLog = true; CloseLight().Wait(); if (!(req?.BILLCODE ?? "").IsNullOrEmpty()) { Biz.Db.Deleteable().Where(x => x.TRANS_NO == req.BILLCODE).ExecuteCommand(); } Biz.Db.Deleteable().Where(q => CurPoolList.Select(q => q.SN).Contains(q.SN)).ExecuteCommand(); //保存操作日志 this.IsFinished = true; return IsFinished ? base.Close(needSaveHistoryLog) : IsFinished; } }//endClass }