| | |
| | | using Tiger.Model; |
| | | using Tiger.Model.Sharetronic.Shelf; |
| | | using System.ComponentModel; |
| | | using Tiger.Model.Entitys.MES.U9C; |
| | | using ProdInBatch = Tiger.Model.ProdInBatch; |
| | | using Org.BouncyCastle.Ocsp; |
| | | using Tiger.Model.Entitys.MES.BizPrintInstoreDoc; |
| | | using System.Drawing.Printing; |
| | | using Tiger.Model.Entitys.MES.Position; |
| | | |
| | | namespace Tiger.Business.MES.Transaction |
| | | { |
| | |
| | | public class InStoreOrderNo : MESTransactionBase, IInStoreOrderNo |
| | | { |
| | | private readonly IMES_U9C _IMES_U9C = DI.Resolve<IMES_U9C>(); |
| | | public IInStoreOrderNo Init(string id, string userCode, string apiHost, string orgCode) |
| | | private readonly IBIZ_MES_WO _IBIZ_MES_WO = DI.Resolve<IBIZ_MES_WO>(); |
| | | public IInStoreOrderNo Init(string id, string apiHost, InstoreDocInput input) |
| | | { |
| | | TransID = id; |
| | | UserCode = userCode; |
| | | UserCode = input.UserCode; |
| | | ApiHost = apiHost; |
| | | OrgCode = orgCode; |
| | | OrgCode = input.OrgCode; |
| | | pageSize = input.pageSize; |
| | | Logger.Console.Info($"Start {this.GetType().Name} Transaction[ID: {TransID}]"); |
| | | return this; |
| | | } |
| | |
| | | public string UserCode { get; set; } |
| | | public long UserId { get; set; } |
| | | public string OrgCode { get; set; } |
| | | public string CurSmtCode { get; set; } |
| | | public string CurrSlotNo { get; set; } |
| | | public string CurSN { get; set; } |
| | | public int pageSize { get; set; } |
| | | public RcvRptDocCreateInput RcvRptInput { get; set; } = new RcvRptDocCreateInput(); |
| | | public List<ProdInBatch> ProdInBatchs { get; set; } = new List<ProdInBatch>(); |
| | | public List<BIZ_ERP_PROD_IN_BTH> ErpProdInBths { get; set; } = new List<BIZ_ERP_PROD_IN_BTH>(); |
| | | /// <summary> |
| | | /// 扫描列表 |
| | | /// </summary> |
| | | public List<InStoreScanInfo> InStoreScanInfos { get; set; } = new List<InStoreScanInfo>(); |
| | | public List<BIZ_ERP_PROD_IN_SN> ErpProdInSns { get; set; } = new List<BIZ_ERP_PROD_IN_SN>(); |
| | | |
| | | #endregion Propertys & Variables |
| | | |
| | | #region Functions |
| | | |
| | | /// <summary> |
| | | /// 扫描条码上料 |
| | | /// 扫描条码 |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <param name="code"></param> |
| | | /// <returns></returns> |
| | | public async Task<ApiAction<SmtLoadingReturn>> ScanItem(SmtLoadingInput input) |
| | | public async Task<ApiAction<InStoreInfos>> Submit(string code) |
| | | { |
| | | var action = new ApiAction<SmtLoadingReturn>(); |
| | | var action = new ApiAction<InStoreInfos>(); |
| | | try |
| | | { |
| | | if (input.Code.IsNullOrEmpty()) |
| | | if (code.IsNullOrEmpty()) |
| | | { |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = Biz.L($"{EnumHelper.GetEnum<Step_Types>(input.Step).GetDesc()}不能为空"); |
| | | action.LocaleMsg = Biz.L($"条码不能为空"); |
| | | return action; |
| | | } |
| | | var apiAction = await _IBIZ_MES_WO.GetErpProdInBth(code); |
| | | if (!apiAction.IsSuccessed) |
| | | { |
| | | return action; |
| | | } |
| | | CurSN = code.Split('|')[0]; |
| | | InStoreInfo Info = apiAction.Data; |
| | | //要存入的批次入库单数据 |
| | | int n = InStoreScanInfos.Where(q => q.WORK_ORDER == Info.ErpProdInBth.WORK_ORDER).Count(); |
| | | if (!ErpProdInBths.Any(q => q.WORK_ORDER == Info.ErpProdInBth.WORK_ORDER)) |
| | | { |
| | | Info.ErpProdInBth.AUTH_ORG = OrgCode; |
| | | Info.ErpProdInBth.CREATE_USER = UserCode; |
| | | Info.ErpProdInBth.CREATE_TIME = DateTime.Now; |
| | | Info.ErpProdInBth.SCANED_DATE = DateTime.Now; |
| | | Info.ErpProdInBth.HANDLED_DATE = DateTime.Now; |
| | | Info.ErpProdInBth.IS_SCANED = "Y"; |
| | | Info.ErpProdInBth.ORDER_NO = UserCode; |
| | | Info.ErpProdInBth.IS_HANDLED = "N"; |
| | | Info.ErpProdInBth.CartonQty = n == 0 ? 1 : n; |
| | | ErpProdInBths.Add(Info.ErpProdInBth); |
| | | } |
| | | else |
| | | { |
| | | if (!InStoreScanInfos.Any(q => q.WORK_ORDER == Info?.ErpProdInBth.WORK_ORDER && q.SN == CurSN)) |
| | | { |
| | | var erpbth = ErpProdInBths.Where(q => q.WORK_ORDER == Info.ErpProdInBth.WORK_ORDER).FirstOrDefault(); |
| | | if (!erpbth.IsNullOrEmpty()) |
| | | { |
| | | erpbth.SCAN_QTY += Info.InStoreScanInfo.SCAN_QTY.ToDouble(); |
| | | Info.ErpProdInBth.CartonQty++; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | //生成打印实体 |
| | | if (RcvRptInput.PrintJsons.Count == 0) |
| | | { |
| | | RcvRptInput.PrintJsons.Add(new() |
| | | { |
| | | ID = Guid.NewGuid().ToString("N"), |
| | | Items = new() { |
| | | Info.ErpProdInBth |
| | | } |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | //拼分页 |
| | | bool isAdded = false; |
| | | foreach (var item in RcvRptInput.PrintJsons) |
| | | { |
| | | if (!item.Items.Any(q => q.WORK_ORDER == Info.ErpProdInBth.WORK_ORDER)) |
| | | { |
| | | if (item.Items.Count < pageSize) |
| | | { |
| | | item.Items.Add(Info.ErpProdInBth); |
| | | isAdded = true; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | isAdded = true; |
| | | } |
| | | } |
| | | if (isAdded) |
| | | { |
| | | RcvRptInput.PrintJsons.Add(new() |
| | | { |
| | | ID = Guid.NewGuid().ToString("N"), |
| | | Items = new() { |
| | | Info.ErpProdInBth |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | //暂存扫码数据 |
| | | if (!InStoreScanInfos.Any(q => q.WORK_ORDER == Info?.ErpProdInBth.WORK_ORDER && q.SN == CurSN)) |
| | | { |
| | | InStoreScanInfos.Add(Info.InStoreScanInfo); |
| | | } |
| | | var wipPkgs = Biz.Db.Ado.UseStoredProcedure().SqlQuery<MES_WIP_PKG>("SP_MES_GET_ITEM_PKG", new SugarParameter("root", CurSN)); |
| | | int maxLevel = wipPkgs.Max(p => p.LEVEL); |
| | | foreach (var item in wipPkgs.Where(q=> q.LEVEL == maxLevel)) |
| | | { |
| | | var scanResult = new BIZ_ERP_PROD_IN_SN |
| | | { |
| | | ID = Guid.NewGuid().ToString(), |
| | | CARTONNO = CurSN, |
| | | SN = item.SN, |
| | | BUSINESSCODE = UserCode, |
| | | ITEM_CODE = item.ITEM_CODE, |
| | | Qty = item.QTY.ToDecimal(), |
| | | SOURCECODE = Info?.ErpProdInBth.WORK_ORDER, |
| | | STATUS = WMS_ITEM.STATUSs.Counted.GetValue(), |
| | | CREATE_USER = UserCode, |
| | | CREATE_TIME = DateTime.Now, |
| | | UPDATE_USER = UserCode, |
| | | UPDATE_TIME = DateTime.Now, |
| | | }; |
| | | ErpProdInSns.Add(scanResult); |
| | | } |
| | | |
| | | //保存数据库 |
| | | var db = Business.Biz.Db; |
| | | var dbTran = db.UseTran(() => |
| | | { |
| | | var x = db.Storageable(ErpProdInBths, $"InStoreOrderNo_{UserCode}") |
| | | .WhereColumns(t => new { t.ORDER_NO, t.WORK_ORDER, t.GHOST_ROW }) |
| | | .ToStorage(); |
| | | x.AsInsertable.ExecuteCommand(); |
| | | x.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); |
| | | |
| | | var s = db.Storageable(ErpProdInSns, $"InStoreOrderNo_{UserCode}") |
| | | .WhereColumns(t => new { t.CARTONNO, t.SN, t.GHOST_ROW }) |
| | | .ToStorage(); |
| | | s.AsInsertable.ExecuteCommand(); |
| | | s.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); |
| | | }); |
| | | if (!dbTran.IsSuccess) |
| | | { |
| | | Logger.Default.Fatal(dbTran.ErrorException, "Database transaction save exception"); |
| | | this.Close(!dbTran.IsSuccess); |
| | | throw dbTran.ErrorException; |
| | | } |
| | | action.Data = new() { |
| | | ErpProdInBths = ErpProdInBths, |
| | | InStoreScanInfos = InStoreScanInfos, |
| | | }; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | action.CatchExceptionWithLog(ex, $"扫描物料[{input.Code}]复核异常"); |
| | | action.CatchExceptionWithLog(ex, $"扫描条码[{code}]复核异常"); |
| | | } |
| | | return action; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 调用U9C接口生成入库单 |
| | | /// </summary> |
| | | /// <param name="code"></param> |
| | | /// <returns></returns> |
| | | public async Task<ApiAction<RcvRptDocCreateInput>> GenerateInStoreOrder(RcvRptDocCreateInput input) |
| | | { |
| | | var action = new ApiAction<RcvRptDocCreateInput>(); |
| | | try |
| | | { |
| | | //input.RcvRptDocBases = new() |
| | | //{ |
| | | // new(){ |
| | | // WorkOrder = item.WORK_ORDER, |
| | | // ItemCode = item.ITEM_CODE, |
| | | // WhCode = "10105", |
| | | // PkgQty = item.SCAN_QTY, |
| | | // CompleteQty = item.SCAN_QTY, |
| | | // OutputType = 0, |
| | | // StorageType = 4, |
| | | // DocState = 1, |
| | | // Status = "N" |
| | | // } |
| | | //}; |
| | | action = await _IMES_U9C.RcvRptDocCreate(input); |
| | | |
| | | //保存数据库 |
| | | var db = Business.Biz.Db; |
| | | var dbTran = db.UseTran(() => |
| | | { |
| | | //var x = db.Storageable(ErpProdInBths, $"InStoreOrderNo_{UserCode}") |
| | | // .WhereColumns(t => new { t.ORDER_NO, t.WORK_ORDER, t.GHOST_ROW }) |
| | | // .ToStorage(); |
| | | //x.AsInsertable.ExecuteCommand(); |
| | | //x.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); |
| | | |
| | | //var s = db.Storageable(ErpProdInSns, $"InStoreOrderNo_{UserCode}") |
| | | // .WhereColumns(t => new { t.CARTONNO, t.SN, t.GHOST_ROW }) |
| | | // .ToStorage(); |
| | | //s.AsInsertable.ExecuteCommand(); |
| | | //s.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); |
| | | }); |
| | | if (!dbTran.IsSuccess) |
| | | { |
| | | Logger.Default.Fatal(dbTran.ErrorException, "Database transaction save exception"); |
| | | this.Close(!dbTran.IsSuccess); |
| | | throw dbTran.ErrorException; |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | action.CatchExceptionWithLog(ex, $"调用U9C接口生成入库单异常"); |
| | | } |
| | | return action; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 查询对应的条码 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public async Task<ApiAction<RcvRptDocCreateInput>> GetScannedBarcodes() |
| | | { |
| | | var action = new ApiAction<RcvRptDocCreateInput>(); |
| | | try |
| | | { |
| | | //var query = await Biz.Db.Queryable<BIZ_ERP_RECEIPT_SN, BAS_ITEM>((t, m) => |
| | | // new JoinQueryInfos( |
| | | // JoinType.Left, t.ITEM_CODE == m.ITEM_CODE |
| | | // )) |
| | | // .Where((t, m) => t.CREATE_USER == UserCode |
| | | // //&& t.WAREHOUSECODE.ToUpper() == WarehouseCode.ToUpper() |
| | | // && t.STATUS == WMS_ITEM.STATUSs.Counted.GetValue() |
| | | // && t.ITEM_CODE.ToUpper() == MaterialCode.ToUpper() |
| | | // && t.BILLCODE == UserCode |
| | | // && t.AUTH_ORG == OrgCode) |
| | | // .Select((t, m) => new Model.Minsun.CustSupplyCheckDetail |
| | | // { |
| | | // Barcode = t.SN, |
| | | // BarcodeQty = t.SCANQTY, |
| | | // Unit = m.UNIT |
| | | // }) |
| | | // .ToListAsync(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | action.CatchExceptionWithLog(ex, $"查询对应的条码异常"); |
| | | } |
| | | return action; |
| | | } |
| | | |
| | | #endregion Functions |
| | | |