diff --git a/DOAN.Service/MES/Product/IService/IProWorkorderMaterialService.cs b/DOAN.Service/MES/Product/IService/IProWorkorderMaterialService.cs index cb72f8f..ac01f40 100644 --- a/DOAN.Service/MES/Product/IService/IProWorkorderMaterialService.cs +++ b/DOAN.Service/MES/Product/IService/IProWorkorderMaterialService.cs @@ -10,21 +10,21 @@ namespace DOAN.Service.MES.product.IService public interface IProWorkorderMaterialService { /// - /// 根据工单号查询领料清单 + /// 根据工单号查询已领料清单 /// /// 工单号 /// 领料清单数据 List GetMaterialTakeList(string workorder); /// - /// 根据工单号查询成品入库清单 + /// 根据工单号查询已成品入库清单 /// /// 工单号 /// 成品入库清单数据 List GetProductStorageList(string workorder); /// - /// 根据工单号查询出货清单 + /// 根据工单号查询已出货清单 /// /// 工单号 /// 出货清单数据 @@ -34,8 +34,35 @@ namespace DOAN.Service.MES.product.IService /// 根据工单号查询物料库存接口 /// /// 工单号 + /// 是否隐藏为0记录 + /// 查询范围 1-物料库 2-转用库 /// 物料库存信息列表 - List GetMaterialInventoryList(string workorder); + List GetMaterialInventoryList(string workorder, bool isHideZero, int searchType); + + /// + /// 根据工单号获取可领料工单清单 + /// + /// 工单号 + /// 是否隐藏为0记录 + /// 查询范围 1-物料库 2-转用库 + /// 可领料工单清单 + List GetPickableWorkordersByWorkorder(string workorder, bool isHideZero, int searchType); + + /// + /// 根据工单号查询成品库存 + /// + /// 工单号 + /// 是否隐藏为0记录 + /// 成品库存信息列表 + List GetProductInventoryList(string workorder, bool isHideZero); + + /// + /// 根据工单号获取可出货订单清单 + /// + /// 工单号 + /// 是否隐藏为0记录 + /// 可出货订单清单 + List GetShippableOrdersByWorkorder(string workorder, bool isHideZero); /// /// 根据工单领料 @@ -58,25 +85,6 @@ namespace DOAN.Service.MES.product.IService /// 操作结果 bool ShipProduct(ShipmentRequestDto request); - /// - /// 根据工单号获取可领料工单清单 - /// - /// 工单号 - /// 可领料工单清单 - List GetPickableWorkordersByWorkorder(string workorder); - /// - /// 根据工单号获取可出货订单清单 - /// - /// 工单号 - /// 可出货订单清单 - List GetShippableOrdersByWorkorder(string workorder); - - /// - /// 根据工单号查询成品库存 - /// - /// 工单号 - /// 成品库存信息列表 - List GetProductInventoryList(string workorder); } } diff --git a/DOAN.Service/MES/Product/ProWorkorderImportService.cs b/DOAN.Service/MES/Product/ProWorkorderImportService.cs index 383dd8d..e781f2c 100644 --- a/DOAN.Service/MES/Product/ProWorkorderImportService.cs +++ b/DOAN.Service/MES/Product/ProWorkorderImportService.cs @@ -108,6 +108,32 @@ namespace DOAN.Service.MES.product return workorderNumbers.Count > 0 ? workorderNumbers.Max() : 0; } + /// + /// 获取当天所有工单的最大编号索引 + /// + /// 日期值 + /// 最大编号索引 + private int GetMaxWorkorderIndex(DateTime dateValue) + { + var workorderNumbers = Context + .Queryable() + .Where(it => it.WorkorderDate == dateValue.Date) + .Select(it => it.Workorder) + .ToList() + .Where(w => w.StartsWith(dateValue.ToString("yyyyMMdd"))) + .Select(w => + { + var parts = w.Split('_'); + if (parts.Length >= 4 && int.TryParse(parts[3], out int index)) + return index; + return 0; + }) + .ToList(); + + // 如果没有找到记录,返回0 + return workorderNumbers.Count > 0 ? workorderNumbers.Max() : 0; + } + /// /// 从Excel文件读取工单数据 /// @@ -419,17 +445,16 @@ namespace DOAN.Service.MES.product workorderList = ReadWorkordersFromExcel(formFile, username, out dateValue); Logger.Info($"读取到 {workorderList.Count} 条工单数据"); - // 按productionCode分组并顺序编号 - // 先按productionCode分组,确保同一产品的工单连续排序 - var productionCodeGroups = workorderList - .GroupBy(w => w.productionCode) - .ToList(); + // 获取当天所有工单的最大编号索引,用于后续编号 + int maxIndex = GetMaxWorkorderIndex(dateValue); + // 从最大编号+1开始顺序编号 + int currentIndex = maxIndex + 1; + Logger.Info($"当天所有工单最大编号索引: {maxIndex},开始编号: {currentIndex}"); // 获取所有工单的最大sort值,用于后续排序 var maxSortNullable = Context .Queryable() .Where(it => it.WorkorderDate == dateValue.Date) - //.Select(it => it.Sort) .Max(it => it.Sort); // 如果没有找到记录,设置默认值0 @@ -438,33 +463,24 @@ namespace DOAN.Service.MES.product // 从maxSort + 10开始,确保sort值按10、20、30...递增 int currentSort = (maxSort / 10) * 10 + 10; - foreach (var group in productionCodeGroups) + // 直接按照Excel导入顺序生成工单号 + foreach (var workorder in workorderList) { - Logger.Info($"处理产品代码: {group.Key},共 {group.Count()} 条工单"); - // 获取当前productionCode当天已有的最大编号 - int maxIndex = GetMaxWorkorderIndex(group.Key, dateValue); - // 从最大编号+1开始顺序编号 - int currentIndex = maxIndex + 1; - Logger.Info($"产品代码: {group.Key},当前最大编号索引: {maxIndex},开始编号: {currentIndex}"); + string nickCode = mmMaterials + .Where(it => it.MaterialCode == workorder.productionCode) + .Select(it => it.Type) + .FirstOrDefault(); - foreach (var workorder in group) - { - string nickCode = mmMaterials - .Where(it => it.MaterialCode == workorder.productionCode) - .Select(it => it.Type) - .FirstOrDefault(); + // 生成唯一的工单编号 + var generateResult = GenerateUniqueWorkorderNo(workorder, dateValue, currentIndex, nickCode); + workorder.Workorder = generateResult.Item1; + // 使用连续的sort值,不受编号冲突影响 + workorder.Sort = currentSort; - // 生成唯一的工单编号 - var generateResult = GenerateUniqueWorkorderNo(workorder, dateValue, currentIndex, nickCode); - workorder.Workorder = generateResult.Item1; - // 使用连续的sort值,不受编号冲突影响 - workorder.Sort = currentSort; - - Logger.Info($"生成工单编号: {workorder.Workorder},产品: {workorder.productionName},sort: {currentSort}"); - currentIndex = generateResult.Item2 + 1; - // 增加sort值,确保下一个工单的sort值为当前值+10 - currentSort += 10; - } + Logger.Info($"生成工单编号: {workorder.Workorder},产品: {workorder.productionName},sort: {currentSort}"); + currentIndex = generateResult.Item2 + 1; + // 增加sort值,确保下一个工单的sort值为当前值+10 + currentSort += 10; } UseTran2(() => @@ -511,14 +527,16 @@ namespace DOAN.Service.MES.product workorderList = ReadWorkordersFromExcel(formFile, username, out dateValue); Logger.Info($"读取到 {workorderList.Count} 条工单数据"); - // 按productionCode分组并顺序编号 - var productionCodeGroups = workorderList.GroupBy(w => w.productionCode).ToList(); + // 获取当天所有工单的最大编号索引,用于后续编号 + int maxIndex = GetMaxWorkorderIndex(dateValue); + // 从最大编号+1开始顺序编号 + int currentIndex = maxIndex + 1; + Logger.Info($"当天所有工单最大编号索引: {maxIndex},开始编号: {currentIndex}"); // 获取所有工单的最大sort值,用于后续排序 var maxSortNullable = Context .Queryable() .Where(it => it.WorkorderDate == dateValue.Date) - //.Select(it => it.Sort) .Max(it => it.Sort); // 如果没有找到记录,设置默认值0 @@ -527,33 +545,24 @@ namespace DOAN.Service.MES.product // 从maxSort + 10开始,确保sort值按10、20、30...递增 int currentSort = (maxSort / 10) * 10 + 10; - foreach (var group in productionCodeGroups) + // 直接按照Excel导入顺序生成工单号 + foreach (var workorder in workorderList) { - Logger.Info($"处理产品代码: {group.Key},共 {group.Count()} 条工单"); - // 获取当前productionCode当天已有的最大编号 - int maxIndex = GetMaxWorkorderIndex(group.Key, dateValue); - // 从最大编号+1开始顺序编号 - int currentIndex = maxIndex + 1; - Logger.Info($"产品代码: {group.Key},当前最大编号索引: {maxIndex},开始编号: {currentIndex}"); + string nickCode = mmMaterials + .Where(it => it.MaterialCode == workorder.productionCode) + .Select(it => it.Type) + .FirstOrDefault(); - foreach (var workorder in group) - { - string nickCode = mmMaterials - .Where(it => it.MaterialCode == workorder.productionCode) - .Select(it => it.Type) - .FirstOrDefault(); + // 生成唯一的工单编号 + var generateResult = GenerateUniqueWorkorderNo(workorder, dateValue, currentIndex, nickCode); + workorder.Workorder = generateResult.Item1; + // 使用连续的sort值,不受编号冲突影响 + workorder.Sort = currentSort; - // 生成唯一的工单编号 - var generateResult = GenerateUniqueWorkorderNo(workorder, dateValue, currentIndex, nickCode); - workorder.Workorder = generateResult.Item1; - // 使用连续的sort值,不受编号冲突影响 - workorder.Sort = currentSort; - - Logger.Info($"生成工单编号: {workorder.Workorder},产品: {workorder.productionName},sort: {currentSort}"); - currentIndex = generateResult.Item2 + 1; - // 增加sort值,确保下一个工单的sort值为当前值+10 - currentSort += 10; - } + Logger.Info($"生成工单编号: {workorder.Workorder},产品: {workorder.productionName},sort: {currentSort}"); + currentIndex = generateResult.Item2 + 1; + // 增加sort值,确保下一个工单的sort值为当前值+10 + currentSort += 10; } UseTran2(() => diff --git a/DOAN.Service/MES/Product/ProWorkorderMaterialService.cs b/DOAN.Service/MES/Product/ProWorkorderMaterialService.cs index 710e8f0..e4e8d6f 100644 --- a/DOAN.Service/MES/Product/ProWorkorderMaterialService.cs +++ b/DOAN.Service/MES/Product/ProWorkorderMaterialService.cs @@ -37,6 +37,7 @@ namespace DOAN.Service.MES.product .Where(it => it.Workorder == workorder) .Where(it => it.TransactionType == "领料出库") .Where(it => it.Remarks != "已撤销") + //.WhereIF(isHideZero, it => it != "已撤销") .Select(it => new MaterialTakeDto { Id = it.Id, @@ -78,6 +79,7 @@ namespace DOAN.Service.MES.product /// 根据工单号查询工单已成品入库清单 /// /// 工单号 + /// 是否隐藏0库存 /// 成品入库清单数据 public List GetProductStorageList(string workorder) { @@ -108,6 +110,7 @@ namespace DOAN.Service.MES.product /// 根据工单号查询工单已出货清单 /// /// 工单号 + /// 是否隐藏0库存 /// 出货清单数据 public List GetShipmentList(string workorder) { @@ -138,9 +141,11 @@ namespace DOAN.Service.MES.product /// /// 根据工单查询物料库存接口 /// - /// 工单号 + /// 工单号 + /// 是否隐藏0 + /// 查询范围 1-物料库 2-转用库 /// 物料库存信息列表 - public List GetMaterialInventoryList(string workorder) + public List GetMaterialInventoryList(string workorder, bool isHideZero = true, int searchType = 1) { try { @@ -166,7 +171,7 @@ namespace DOAN.Service.MES.product .Queryable() .Where(it => it.MaterialCode == materialCode) .Where(it => it.LocationCode == "YCL001") - .Where(it => it.CurrentQty > 0) + .WhereIF(isHideZero, it => it.CurrentQty > 0) .Select(it => new MaterialInventoryDto { MaterialId = it.Id, @@ -196,7 +201,7 @@ namespace DOAN.Service.MES.product .Where(it => it.MaterialCode == mmMaterial.MaterialCode) .Where(it => it.SupplierCode == mmMaterial.SupplierCode) .Where(it => it.LocationCode == "YCL001" || it.LocationCode == "CP001") - .Where(it => it.CurrentQty > 0) + .WhereIF(isHideZero, it => it.CurrentQty > 0) .Select(it => new MaterialInventoryDto { MaterialId = it.Id, @@ -225,6 +230,187 @@ namespace DOAN.Service.MES.product } } + + + /// + /// 根据工单号获取可领料工单清单(产成品领取半成品) + /// + /// 工单号 + /// 是否隐藏0记录 + /// 查询范围 1-物料库 2-转用库 + /// 可领料工单清单 + public List GetPickableWorkordersByWorkorder(string workorder, bool isHideZero = true, int searchType = 1) + { + try + { + // 参数验证 + if (string.IsNullOrEmpty(workorder)) + { + throw new ArgumentNullException(nameof(workorder), "工单号不能为空"); + } + + var workorderInfo = Context + .Queryable() + .First(it => it.Workorder == workorder); + if (workorderInfo == null) + { + throw new ArgumentException("工单不存在", nameof(workorder)); + } + // 需要领取半成品 + if (workorderInfo.RouteCode == "10") + { + return Context + .Queryable() + .LeftJoin((mri,pro)=>mri.Workorder == pro.Workorder) + .Where((mri, pro) => mri.MaterialCode == workorderInfo.MaterialCode) + .Where((mri, pro) => mri.TransactionType == "生产入库") + .Where((mri, pro) => mri.Remarks != "已撤销") + //.Where((mri, pro) => pro.ShipmentNum < pro.PlanNum) + .OrderByDescending((mri, pro) => mri.Workorder) + .Select( + (mri, pro) => new ProWorkorderDto + { + Id = pro.Id, + Workorder = mri.Workorder, + productionName = mri.MaterialCode, + productionCode = mri.MaterialName, + MaterialCode = mri.MaterialCode, + MaterialName = mri.MaterialName, + ShipmentNum = pro.ShipmentNum, + PlanNum = pro.PlanNum, + Remark01 = mri.Remarks + }, + true + ) + .Take(30) + .ToList(); + } + else + { + // 非10线则返回库存 + + // 示例返回空列表 + return new List(); + } + } + catch (Exception ex) + { + // 集成现有系统的日志记录 + // Log.Error("获取可领料工单清单失败", ex); + throw; + } + } + + /// + /// 根据工单号查询成品库存 + /// + /// 工单号 + /// 是否隐藏为0记录 + /// 成品库存信息列表 + public List GetProductInventoryList(string workorder, bool isHideZero = true) + { + try + { + // 参数验证 + if (string.IsNullOrEmpty(workorder)) + { + throw new ArgumentNullException(nameof(workorder), "工单号不能为空"); + } + + var workorderInfo = Context + .Queryable() + .First(it => it.Workorder == workorder); + if (workorderInfo == null) + { + throw new ArgumentException("工单不存在", nameof(workorder)); + } + var result = Context + .Queryable() + .Where(it => it.MaterialCode == workorderInfo.productionCode) + .Where(it => it.LocationCode == "CP001") + .WhereIF(isHideZero, it => it.CurrentQty > 0) + .Select(it => new MaterialInventoryDto + { + MaterialId = it.Id, + MaterialCode = it.MaterialCode, + MaterialName = it.MaterialName, + CurrentQuantity = it.CurrentQty, + SupplierCode = it.SupplierCode, + SupplierName = it.SupplierName, + Unit = it.Unit, + BatchNo = it.BatchNo, + }) + .OrderByDescending(it => it.BatchNo) + .Take(10) + .ToList(); + + return result; + } + catch (Exception ex) + { + // 集成现有系统的日志记录 + // Log.Error("查询成品库存失败", ex); + throw; + } + } + + /// + /// 根据工单号获取可出货订单清单 + /// + /// 工单号 + /// 是否隐藏为0记录 + /// 可出货订单清单 + public List GetShippableOrdersByWorkorder(string workorder, bool isHideZero = true) + { + try + { + // 参数验证 + if (string.IsNullOrEmpty(workorder)) + { + throw new ArgumentNullException(nameof(workorder), "工单号不能为空"); + } + + var workorderInfo = Context + .Queryable() + .First(it => it.Workorder == workorder); + if (workorderInfo == null) + { + throw new ArgumentException("工单不存在", nameof(workorder)); + } + var orderPurchaseList = Context + .Queryable() + .Where(o => o.MaterialCode == workorderInfo.productionCode) + .Where(it => it.Orderindicator != 1) + //.Where(it => it.Orderindicator != -1) + .OrderBy(it => it.DeliveryDate) + .Select( + o => new OrderPurchaseDto + { + Id = o.Id, + OrderNoMes = o.OrderNoMes, + MaterialCode = o.MaterialCode, + MaterialName = o.MaterialName, + DemandQuantity = o.DemandQuantity, + DeliveryQuantity = o.DeliveryQuantity, + DeliveryDate = o.DeliveryDate, + }, + true + ) + .ToList(); + + // 示例返回空列表 + return orderPurchaseList; + } + catch (Exception ex) + { + // 集成现有系统的日志记录 + // Log.Error("获取可出货订单清单失败", ex); + throw; + } + } + + + /// /// 工单领料接口 /// @@ -423,178 +609,5 @@ namespace DOAN.Service.MES.product throw new Exception(ex.Message); } } - - /// - /// 根据工单号获取可领料工单清单(产成品领取半成品) - /// - /// 工单号 - /// 可领料工单清单 - public List GetPickableWorkordersByWorkorder(string workorder) - { - try - { - // 参数验证 - if (string.IsNullOrEmpty(workorder)) - { - throw new ArgumentNullException(nameof(workorder), "工单号不能为空"); - } - - var workorderInfo = Context - .Queryable() - .First(it => it.Workorder == workorder); - if (workorderInfo == null) - { - throw new ArgumentException("工单不存在", nameof(workorder)); - } - // 需要领取半成品 - if (workorderInfo.RouteCode == "10") - { - return Context - .Queryable() - .LeftJoin((mri,pro)=>mri.Workorder == pro.Workorder) - .Where((mri, pro) => mri.MaterialCode == workorderInfo.MaterialCode) - .Where((mri, pro) => mri.TransactionType == "生产入库") - .Where((mri, pro) => mri.Remarks != "已撤销") - //.Where((mri, pro) => pro.ShipmentNum < pro.PlanNum) - .OrderByDescending((mri, pro) => mri.Workorder) - .Select( - (mri, pro) => new ProWorkorderDto - { - Id = pro.Id, - Workorder = mri.Workorder, - productionName = mri.MaterialCode, - productionCode = mri.MaterialName, - MaterialCode = mri.MaterialCode, - MaterialName = mri.MaterialName, - ShipmentNum = pro.ShipmentNum, - PlanNum = pro.PlanNum, - Remark01 = mri.Remarks - }, - true - ) - .Take(30) - .ToList(); - } - else - { - // 非10线则返回库存 - - // 示例返回空列表 - return new List(); - } - } - catch (Exception ex) - { - // 集成现有系统的日志记录 - // Log.Error("获取可领料工单清单失败", ex); - throw; - } - } - - /// - /// 根据工单号获取可出货订单清单 - /// - /// 工单号 - /// 可出货订单清单 - public List GetShippableOrdersByWorkorder(string workorder) - { - try - { - // 参数验证 - if (string.IsNullOrEmpty(workorder)) - { - throw new ArgumentNullException(nameof(workorder), "工单号不能为空"); - } - - var workorderInfo = Context - .Queryable() - .First(it => it.Workorder == workorder); - if (workorderInfo == null) - { - throw new ArgumentException("工单不存在", nameof(workorder)); - } - var orderPurchaseList = Context - .Queryable() - .Where(o => o.MaterialCode == workorderInfo.productionCode) - .Where(it => it.Orderindicator != 1) - //.Where(it => it.Orderindicator != -1) - .OrderBy(it => it.DeliveryDate) - .Select( - o => new OrderPurchaseDto - { - Id = o.Id, - OrderNoMes = o.OrderNoMes, - MaterialCode = o.MaterialCode, - MaterialName = o.MaterialName, - DemandQuantity = o.DemandQuantity, - DeliveryQuantity = o.DeliveryQuantity, - DeliveryDate = o.DeliveryDate, - }, - true - ) - .ToList(); - - // 示例返回空列表 - return orderPurchaseList; - } - catch (Exception ex) - { - // 集成现有系统的日志记录 - // Log.Error("获取可出货订单清单失败", ex); - throw; - } - } - - /// - /// 根据工单号查询成品库存 - /// - /// 工单号 - /// 成品库存信息列表 - public List GetProductInventoryList(string workorder) - { - try - { - // 参数验证 - if (string.IsNullOrEmpty(workorder)) - { - throw new ArgumentNullException(nameof(workorder), "工单号不能为空"); - } - - var workorderInfo = Context - .Queryable() - .First(it => it.Workorder == workorder); - if (workorderInfo == null) - { - throw new ArgumentException("工单不存在", nameof(workorder)); - } - var result = Context - .Queryable() - .Where(it => it.MaterialCode == workorderInfo.productionCode) - .Where(it => it.LocationCode == "CP001") - //.Where(it => it.CurrentQty > 0) - .Select(it => new MaterialInventoryDto - { - MaterialId = it.Id, - MaterialCode = it.MaterialCode, - MaterialName = it.MaterialName, - CurrentQuantity = it.CurrentQty, - SupplierCode = it.SupplierCode, - SupplierName = it.SupplierName, - Unit = it.Unit, - BatchNo = it.BatchNo, - }) - .OrderByDescending(it => it.BatchNo) - .Take(10) - .ToList(); - - return result; - } - catch (Exception ex) - { - // 集成现有系统的日志记录 - // Log.Error("查询成品库存失败", ex); - throw; - } - } } } diff --git a/DOAN.Service/MES/Quality/IPQC/QcScrapRecordsService.cs b/DOAN.Service/MES/Quality/IPQC/QcScrapRecordsService.cs index 4941f96..7a5da6a 100644 --- a/DOAN.Service/MES/Quality/IPQC/QcScrapRecordsService.cs +++ b/DOAN.Service/MES/Quality/IPQC/QcScrapRecordsService.cs @@ -335,7 +335,7 @@ namespace DOAN.Service.BZFM { ReceiptType = 1, MaterialCode = record.ProductCode, - BatchNo = "000", + BatchNo = record.BatchNo, LocationCode = "BL001", WarehouseCode = "WH007", SupplierCode = record.SupplierCode, diff --git a/DOAN.Service/Mobile/ReportFlowService.cs b/DOAN.Service/Mobile/ReportFlowService.cs index 213d8ed..ab531cf 100644 --- a/DOAN.Service/Mobile/ReportFlowService.cs +++ b/DOAN.Service/Mobile/ReportFlowService.cs @@ -397,7 +397,7 @@ public class ReportFlowService : BaseService, IReportFlowServic { ReceiptType = 1, MaterialCode = proWorkorder.productionCode, - BatchNo = "000", + BatchNo = proWorkorder.FeedOrder ?? "000", LocationCode = "CP001", WarehouseCode = "WH001", SupplierCode = mmMaterial.SupplierCode, @@ -546,7 +546,7 @@ public class ReportFlowService : BaseService, IReportFlowServic { ReceiptType = 1, MaterialCode = workorderInfo.productionCode, - BatchNo = "000", + BatchNo = workorderInfo.FeedOrder ?? "000", LocationCode = "CP001", WarehouseCode = "WH001", OrderNo = customer_order,