| | |
| | | using System.Diagnostics; |
| | | using static Microsoft.CodeAnalysis.CSharp.SyntaxTokenParser; |
| | | using Tiger.Model.Entitys.MES.U9C; |
| | | using Tiger.Model.Entitys.MES.BizPrintInstoreDoc; |
| | | using Tiger.Model.Entitys.MES.Position; |
| | | using IronPython.Runtime.Operations; |
| | | |
| | | namespace Tiger.Business.WMS.Transaction |
| | | { |
| | |
| | | public class In_SemiProd : WMSTransactionBase, IIn_SemiProd |
| | | { |
| | | private readonly IMES_U9C _IMES_U9C = DI.Resolve<IMES_U9C>(); |
| | | public IIn_SemiProd Init(string id, string userCode, string apiHost, string orgCode) |
| | | public IIn_SemiProd Init(string id, string apiHost, InstoreDocInput input) |
| | | { |
| | | TransID = id; |
| | | UserCode = userCode; |
| | | UserCode = input.UserCode; |
| | | ApiHost = apiHost; |
| | | OrgCode = orgCode; |
| | | OrgCode = input.OrgCode; |
| | | pageSize = input.pageSize; |
| | | _GetScannedList(); |
| | | Logger.Console.Info($"Start {this.GetType().Name} Transaction[ID: {TransID}]"); |
| | | return this; |
| | | } |
| | |
| | | /// <summary> |
| | | /// 扫描入口 |
| | | /// </summary> |
| | | public async Task<ApiAction<ScanOutput>> Scan(BaseInput input) |
| | | public async Task<ApiAction<ScanOutput>> Submit(BaseInput input) |
| | | { |
| | | var action = new ApiAction<ScanOutput>(new ScanOutput()); |
| | | try |
| | |
| | | { |
| | | action.IsSuccessed = false; |
| | | action.LocaleMsg = Biz.L("WMS.InSemiProd.ScanItem.WoEmptyFailure", input.SN); // $"工单[{input.SN}]不存在" |
| | | return action; |
| | | return SetOutPutMqttMsg(action, input.Locale); |
| | | } |
| | | |
| | | |
| | | var semiTemplateQty = (input.Data ?? "").JsonToObject<SemiTemplateQty>() ?? new SemiTemplateQty(); |
| | | |
| | | InStoreInfo Info = new() |
| | | { |
| | | ErpProdInBth = new() |
| | |
| | | ITEM_CODE = wo.ITEM_CODE, |
| | | ITEM_NAME = wo.ItemInfo?.ITEM_DESC, |
| | | SapCode = wo.ItemInfo?.ExtInfo?.SapCode, |
| | | SCAN_QTY = input.Data.ToInt32(), |
| | | SCAN_QTY = semiTemplateQty.PackQty, |
| | | CompleteQty = semiTemplateQty.CompleteQty, |
| | | IS_HANDLED = "N" //Y-已生成,N-未生成,F-失败 |
| | | }, |
| | | InStoreScanInfo = new() |
| | |
| | | SALES_ORDER = wo.SALES_ORDER, |
| | | WORK_ORDER = wo.ORDER_NO, |
| | | BATCH_NO = "", |
| | | SCAN_QTY = input.Data.ToInt32() |
| | | SCAN_QTY = semiTemplateQty.PackQty.ToDouble() |
| | | } |
| | | }; |
| | | |
| | |
| | | }; |
| | | |
| | | action.Data.Data = inStoreInfos; |
| | | action.LocaleMsg = Biz.L("WMS.InSemiProd.ScanItem.ScanSuccessed"); //$"工单条码[{input.SN}]扫描成功,请填入工单数量后点提交" |
| | | action.Data.Command = ""; |
| | | action.LocaleMsg = Biz.L("WMS.InSemiProd.ScanItem.ScanSuccessed", input.SN); //$"工单条码[{input.SN}]扫描成功,请填入工单数量后点提交" |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | return SetOutPutMqttMsg(action, input.Locale); |
| | | } |
| | | |
| | | public async Task<ApiAction<ScanOutput>> ScanItem(BaseInput input) |
| | | public ApiAction<InStoreInfos> GetInStoreInfos() |
| | | { |
| | | var action = new ApiAction<ScanOutput>(new ScanOutput()); |
| | | return new() { Data = inStoreInfos }; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 查询已扫描列表 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public async Task<ApiAction<InStoreInfos>> GetScannedList() |
| | | { |
| | | var action = new ApiAction<InStoreInfos>(); |
| | | try |
| | | { |
| | | |
| | | _GetScannedList(); |
| | | action.Data = inStoreInfos; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | action.CatchExceptionWithLog(ex, Biz.L("半成品入库失败")); |
| | | action.CatchExceptionWithLog(ex, $"查询已扫描列表异常"); |
| | | } |
| | | return action; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 从数据库读回操作者原本操作的记录 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | private RcvRptDocCreateInput _GetScannedList() |
| | | { |
| | | RcvRptInput.RcvRptDocBases = new(); |
| | | RcvRptInput.ErpProdInBths = new(); |
| | | RcvRptInput.PrintJsons = new(); |
| | | RcvRptInput.labels = new(); |
| | | RcvRptInput.userId = UserCode; |
| | | ErpProdInSns.Clear(); |
| | | ErpProdIns.Clear(); |
| | | ErpProdInBths.Clear(); |
| | | InStoreScanInfos.Clear(); |
| | | RcvRptInput.ErpProdInBths = Biz.Db.Queryable<BIZ_ERP_PROD_IN_BTH>() |
| | | .Where(q => q.BATCH_NO == SqlFunc.Subqueryable<BIZ_ERP_PROD_IN_BTH>().Where(s => s.ORDER_NO == UserCode && s.GHOST_ROW == false).Select(s => s.BATCH_NO) && q.IS_HANDLED == "N") |
| | | .IncludesAllFirstLayer().ToList(); |
| | | foreach (var item in RcvRptInput.ErpProdInBths) |
| | | { |
| | | var values = item.ProdInSns.GroupBy(x => x.CARTONNO) |
| | | .Select(g => new InStoreScanInfo() { SN = g.Key, SALES_ORDER = item.SALES_ORDER, BATCH_NO = item.BATCH_NO, WORK_ORDER = item.WORK_ORDER, SCAN_QTY = g.Sum(x => x.Qty).ToDouble() }); |
| | | foreach (var t in values) |
| | | { |
| | | InStoreScanInfos.Add(t); |
| | | } |
| | | item.CartonQty = values.Count(); |
| | | |
| | | ErpProdIns.Add(new() |
| | | { |
| | | AUTH_ORG = OrgCode, |
| | | BILLCODE = UserCode, |
| | | BILLDATE = DateTime.Now, |
| | | STATUS = 0, |
| | | HANDLED = -1, |
| | | WAREHOUSECODE = "", |
| | | SOURCECODE = item.WORK_ORDER, |
| | | HANDLED_DATE = DateTime.Now, |
| | | }); |
| | | ErpProdInSns.AddRange(item.ProdInSns); |
| | | |
| | | //生成打印实体 |
| | | if (RcvRptInput.PrintJsons.Count == 0) |
| | | { |
| | | RcvRptInput.PrintJsons.Add(new() |
| | | { |
| | | ID = Guid.NewGuid().ToString("N"), |
| | | Items = new() { |
| | | item |
| | | } |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | //拼分页 |
| | | bool isAdded = false; |
| | | foreach (var p in RcvRptInput.PrintJsons) |
| | | { |
| | | if (!p.Items.Any(q => q.WORK_ORDER == item.WORK_ORDER)) |
| | | { |
| | | if (p.Items.Count < pageSize) |
| | | { |
| | | p.Items.Add(item); |
| | | isAdded = true; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | isAdded = true; |
| | | } |
| | | } |
| | | if (!isAdded) |
| | | { |
| | | RcvRptInput.PrintJsons.Add(new() |
| | | { |
| | | ID = Guid.NewGuid().ToString("N"), |
| | | Items = new() { |
| | | item |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | ErpProdInBths = RcvRptInput.ErpProdInBths; |
| | | |
| | | inStoreInfos = new() |
| | | { |
| | | ErpProdInBths = ErpProdInBths, |
| | | InStoreScanInfos = InStoreScanInfos, |
| | | }; |
| | | return RcvRptInput; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 调用U9C接口生成入库单 |
| | |
| | | if (!RcvRptInput.ErpProdInBths.Any(q => q.IS_HANDLED == "N")) |
| | | { |
| | | action.IsSuccessed = false; |
| | | action.LocaleMsg = Biz.L($"没有要入库的产品数据,请扫描包装完成的箱二维码重新生成入库单据!"); |
| | | action.LocaleMsg = Biz.L($"没有要入库的产品数据,请扫描工单重新生成入库单据!"); |
| | | return action; |
| | | } |
| | | if (RcvRptInput.RcvRptDocBases.IsNullOrEmpty() || RcvRptInput.RcvRptDocBases.Count == 0) |
| | |
| | | WorkOrder = item.WORK_ORDER, |
| | | ItemCode = item.ITEM_CODE, |
| | | WhCode = "10105", |
| | | PkgQty = item.SCAN_QTY.ToInt32(), |
| | | CompleteQty = item.SCAN_QTY.ToInt32(), |
| | | PkgQty = item.SCAN_QTY, |
| | | CompleteQty = item.CompleteQty, |
| | | OutputType = 0, |
| | | StorageType = 4, |
| | | DocState = 1, |
| | |
| | | return action; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 清除 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public async Task<ApiAction> Clear() |
| | | { |
| | | var action = new ApiAction(); |
| | | try |
| | | { |
| | | RcvRptInput = new(); |
| | | ProdInBatchs = new() { }; |
| | | ErpProdInBths = new() { }; |
| | | ErpProdIns = new(); |
| | | /// <summary> |
| | | /// 扫描列表 |
| | | /// </summary> |
| | | InStoreScanInfos = new() { }; |
| | | ErpProdInSns = new(); |
| | | inStoreInfos = new() { }; |
| | | |
| | | //临时代码,测试用 |
| | | //DbClient _db = Biz.DataSource["YadaU9C"].Client; |
| | | //var items = Biz.Db.Queryable<WMS_ITEM>().Where(q => SqlFunc.IsNullOrEmpty(q.SUPP_LOTNO)).ToList(); |
| | | //var snlist = items.Select(q => q.SN).ToList(); |
| | | ////var list = _db.Ado.SqlQuery<mes_MaterialBarCodeByBin>($"select *,cast('{DateTime.Now.ToString("yyyy-MM-dd")}' as DATETIME) as PROD_DATE,'' as Unit,'' as LotNo from mes_MaterialBarCodeByBin where Code in ({string.Join(',', snlist.Select(x=> $"'{x}'"))})"); |
| | | //var list = _db.Queryable<mes_MaterialBarCode>().Where(q => snlist.Contains(q.Code)).ToList(); |
| | | //foreach (var item in list) |
| | | //{ |
| | | // var wmsitem = items.Where(q => q.SN == item.Code).FirstOrDefault(); |
| | | // if (!wmsitem.IsNullOrEmpty()) |
| | | // { |
| | | // wmsitem.SUPP_LOTNO = item.Segment7; |
| | | // } |
| | | //} |
| | | |
| | | |
| | | ////保存数据库 |
| | | //var db = Business.Biz.Db; |
| | | //var dbTran = db.UseTran(() => |
| | | //{ |
| | | // db.Updateable(items).UpdateColumns(q => new { q.SUPP_LOTNO }).ExecuteCommand(); |
| | | //}); |
| | | //if (!dbTran.IsSuccess) |
| | | //{ |
| | | // Logger.Default.Fatal(dbTran.ErrorException, "Database transaction save exception"); |
| | | // this.Close(!dbTran.IsSuccess); |
| | | // throw dbTran.ErrorException; |
| | | //} |
| | | |
| | | //保存数据库 |
| | | var db = Business.Biz.Db; |
| | | var dbTran = db.UseTran(() => |
| | | { |
| | | db.Deleteable<BIZ_ERP_PROD_IN_BTH>().Where(x => x.ORDER_NO == UserCode && x.IS_HANDLED == "N").ExecuteCommand(); |
| | | db.Deleteable<BIZ_ERP_PROD_IN_SN>().Where(x => x.BUSINESSCODE == UserCode).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, $"查询已扫描列表异常"); |
| | | } |
| | | return action; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | public override bool Close(bool needSaveHistoryLog = false) |