diff --git a/ZR.Service/mes/wms/WmGoodsActionService.cs b/ZR.Service/mes/wms/WmGoodsActionService.cs index 847808fe..8d60fdbf 100644 --- a/ZR.Service/mes/wms/WmGoodsActionService.cs +++ b/ZR.Service/mes/wms/WmGoodsActionService.cs @@ -80,18 +80,46 @@ namespace ZR.Service.Business // 短批次 string shortPatchCode = mainPackage.PatchCode.Split('_')[0]; // 该批次最后一个拼箱记录 - WmGoodsNowProduction lastConsolidationPackage = Context.Queryable().Where(it => it.PackageCodeClient.Contains(shortPatchCode + "_4")).OrderBy(it => it.PackageCodeClient, OrderByType.Desc).First(); + WmGoodsNowProduction lastConsolidationPackage = Context.Queryable() + .Where(it => it.PackageCodeClient.Contains(shortPatchCode + "_4")) + .OrderBy(it => it.PackageCodeClient, OrderByType.Desc) + .First(); string newPatchCode = shortPatchCode; int lastCode = 400; - if (lastConsolidationPackage == null) + // 检测包装是否已打印4XX标签 + // 该工单标签最大一个 + var packingrecordExp = Expressionable.Create() + .And(it => it.WorkOrderNum == mainPackage.WorkoderID) + .And(it => it.Machine == "4") + .And(it => !it.PackingCode.Contains("Iminate")) + .ToExpression(); + WmPackingrecord lastPackingrecord = Context.Queryable() + .Where(packingrecordExp) + .OrderBy(it=>it.PackingCode, OrderByType.Desc) + .First(); + if (lastConsolidationPackage == null && lastPackingrecord == null) { newPatchCode += "_401"; } else { + int lastPackingrecordCode = 0; + // 优先处理箱打印有历史数据情况 + if (lastPackingrecord != null) + { + int subIndex = lastPackingrecord.PackingCode.Length - 5; + // XXX 此代码中 AsSpan 方法 .NET Framework 4.7.2 不支持需要更高版本 或替换为 Substring + if (int.TryParse(lastPackingrecord.PackingCode.AsSpan(subIndex).TrimStart('0'), out lastPackingrecordCode)) + { + } + } if (int.TryParse(lastConsolidationPackage.PackageCodeClient.Split('_')[1], out lastCode)) { - + // 取最大值 + if (lastPackingrecordCode > lastCode) + { + lastCode = lastPackingrecordCode; + } if (lastCode > 400) { newPatchCode += "_" + (lastCode + 1); @@ -141,6 +169,8 @@ namespace ZR.Service.Business nowProduction.Remark = "拼箱整箱"; // 修改主箱 Context.Updateable(nowProduction).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); + // 添加记录 要有newPatchCode + AddPackingrecord(nowProduction,mainPackage.WorkoderID, true); // 次箱操作 if (isDelete) { @@ -190,16 +220,41 @@ namespace ZR.Service.Business WmGoodsNowProduction lastConsolidationPackage = Context.Queryable().Where(it => it.PackageCodeClient.Contains(shortPatchCode + "_4")).OrderBy(it => it.PackageCodeClient, OrderByType.Desc).First(); string newPatchCode1 = shortPatchCode; string newPatchCode2 = shortPatchCode; + // 检测包装是否已打印4XX标签 + // 该工单标签最大一个 + var packingrecordExp = Expressionable.Create() + .And(it => it.WorkOrderNum == mainPackage.WorkoderID) + .And(it => it.Machine == "4") + .And(it => !it.PackingCode.Contains("Iminate")) + .ToExpression(); + WmPackingrecord lastPackingrecord = Context.Queryable() + .Where(packingrecordExp) + .OrderBy(it => it.PackingCode, OrderByType.Desc) + .First(); int lastCode = 400; - if (lastConsolidationPackage == null) + if (lastConsolidationPackage == null && lastPackingrecord == null) { newPatchCode1 += "_401"; newPatchCode2 += "_402"; } else { + int lastPackingrecordCode = 0; + // 优先处理箱打印有历史数据情况 + if (lastPackingrecord != null) + { + int subIndex = lastPackingrecord.PackingCode.Length - 5; + // XXX 此代码中 AsSpan 方法 .NET Framework 4.7.2 不支持需要更高版本 或替换为 Substring + if (int.TryParse(lastPackingrecord.PackingCode.AsSpan(subIndex).TrimStart('0'), out lastPackingrecordCode)) + { + } + } if (int.TryParse(lastConsolidationPackage.PackageCodeClient.Split('_')[1], out lastCode)) { + if(lastPackingrecordCode > lastCode) + { + lastCode = lastPackingrecordCode; + } if (lastCode > 400) { newPatchCode1 += "_" + (lastCode + 1); @@ -256,6 +311,8 @@ namespace ZR.Service.Business newPackage1.Remark = "拆箱"; // 修改主箱 Context.Updateable(newPackage1).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); + // 添加记录 要有newPatchCode + AddPackingrecord(newPackage1, mainPackage.WorkoderID, false); // 2.添加一个分箱 WmGoodsNowProduction newPackage2 = mainNowProduction; newPackage2.CreatedBy = parm.CreateBy; @@ -269,10 +326,42 @@ namespace ZR.Service.Business newPackage2.GoodsNumAction = secondNum; newPackage2.Remark = "拆箱"; newPackage2.Id = SnowFlakeSingle.Instance.NextId().ToString(); - // 修改主箱 - Context.Insertable(newPackage1).ExecuteCommand(); + // 添加分箱 + Context.Insertable(newPackage2).ExecuteCommand(); + // 添加记录 要有newPatchCode + AddPackingrecord(newPackage2, mainPackage.WorkoderID, false); // TODO修改打印记录 return log; } + // 添加包装箱标签记录 + public void AddPackingrecord(WmGoodsNowProduction production,string workOrderId, bool isFill = false) + { + try + { + if(int.TryParse(production.PackageCodeClient.Split('_')[1], out int packageNum)) { + WmPackingrecord packingrecord = new() + { + PartNum = production.Partnumber, + Machine = "4", + ProductCode = "Iminate_P_0", + PackingCode = workOrderId + packageNum.ToString("00000"), + ScannerContent = production.PackageCodeOriginal, + WorkOrderNum = workOrderId, + BFilled = isFill, + CreateTime = DateTime.Now, + }; + Context.Insertable(packingrecord).ExecuteCommand(); + } + else + { + throw new Exception("包装箱标签批次号数量解析失败!"); + } + + } + catch (Exception ex) + { + throw new Exception("包装箱标签插入失败!" + ex); + } + } } } \ No newline at end of file