From 8a5779d01d752bd0ce5615cc07768c34102918f5 Mon Sep 17 00:00:00 2001 From: ljh <1192263352@qq.com> Date: Tue, 16 Jul 2024 23:22:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=89=AB=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PrintCodeDetail/PrintCodeDetailService.cs | 9 + .../ProductRetrospectService.cs | 2 +- .../ReportDetailTableService.cs | 212 +++++++++++++----- .../component/editDialog.vue | 18 +- .../reportTable/component/codeDialog.vue | 39 +++- .../productionCenter/reportTable/index.vue | 2 +- 6 files changed, 209 insertions(+), 73 deletions(-) diff --git a/Admin.NET/Admin.NET.Application/Service/PrintCodeDetail/PrintCodeDetailService.cs b/Admin.NET/Admin.NET.Application/Service/PrintCodeDetail/PrintCodeDetailService.cs index a387e26..2fb4f71 100644 --- a/Admin.NET/Admin.NET.Application/Service/PrintCodeDetail/PrintCodeDetailService.cs +++ b/Admin.NET/Admin.NET.Application/Service/PrintCodeDetail/PrintCodeDetailService.cs @@ -176,6 +176,15 @@ public class PrintCodeDetailService : IDynamicApiController, ITransient return await _rep.AsQueryable().Where(a => !a.IsDelete && a.Code.Contains(productCode)).ToListAsync(); } + [HttpGet] + [ApiDescriptionSettings(Name = "GetByProductCodes2")] + public async Task> GetByProductCodes2(string? productCode) + { + return await _rep.AsQueryable().Where(a => !a.IsDelete && a.Code == productCode).ToListAsync(); + } + + + [HttpGet] [ApiDescriptionSettings(Name = "GetByReportTableId")] public async Task> GetByReportTableId(long? reportTableId) diff --git a/Admin.NET/Admin.NET.Application/Service/ProductRetrospect/ProductRetrospectService.cs b/Admin.NET/Admin.NET.Application/Service/ProductRetrospect/ProductRetrospectService.cs index e94dce9..8214f11 100644 --- a/Admin.NET/Admin.NET.Application/Service/ProductRetrospect/ProductRetrospectService.cs +++ b/Admin.NET/Admin.NET.Application/Service/ProductRetrospect/ProductRetrospectService.cs @@ -181,7 +181,7 @@ public class ProductRetrospectService : IDynamicApiController, ITransient state = 0; } var last = codeEnt.OrderBy(a => a.WarehousingDate).FirstOrDefault(); - var receipt = last.Receipt == null ? "" : last.Receipt; + var receipt = last?.Receipt == null ? "" : last.Receipt; if (receipt.Contains("汇报单")) { state = 1; diff --git a/Admin.NET/Admin.NET.Application/Service/ReportDetailTable/ReportDetailTableService.cs b/Admin.NET/Admin.NET.Application/Service/ReportDetailTable/ReportDetailTableService.cs index 8d85799..8b414e9 100644 --- a/Admin.NET/Admin.NET.Application/Service/ReportDetailTable/ReportDetailTableService.cs +++ b/Admin.NET/Admin.NET.Application/Service/ReportDetailTable/ReportDetailTableService.cs @@ -6,6 +6,7 @@ using Admin.NET.Application.Utils; using AngleSharp.Dom; using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; +using static Nest.JoinField; namespace Admin.NET.Application; /// @@ -170,7 +171,7 @@ public class ReportDetailTableService : IDynamicApiController, ITransient { throw Oops.Oh(ErrorCodeEnum.xg1002); } - + var reportDetailTable = await _rep.GetByIdAsync(input.WarehousingTableId); var repeatCodes = await _codeDetailService.GetRepeat(input.CodeDatas); var codesToKeep = new List(); foreach (var repeatCode in repeatCodes) @@ -188,7 +189,7 @@ public class ReportDetailTableService : IDynamicApiController, ITransient } } repeatCodes = codesToKeep; - if (repeatCodes != null && repeatCodes.Count > 0) + if (reportDetailTable.ProductType=="普通生产" && repeatCodes != null && repeatCodes.Count > 0) { var repeats = repeatCodes.ConvertAll(a => a.Code).Distinct(); throw Oops.Oh($"条码重复:{string.Join("、", repeats)}"); @@ -234,7 +235,8 @@ public class ReportDetailTableService : IDynamicApiController, ITransient EndDate = input.EndDt, SourceNumber = warehousing.SourceNumber, Unit = warehousing.Unit, - Remarks = warehousing.Remarks + Remarks = warehousing.Remarks, + }; reprotId = await _reportTableService.Add(newReport); } @@ -250,21 +252,7 @@ public class ReportDetailTableService : IDynamicApiController, ITransient var code = CodeHelper.GetCode(item.BarCode, item.QrCode); var codeType = string.IsNullOrEmpty(item.BarCode) ? "二维码" : "条码"; var unit = units.Find(a => a.Name == item.PackageName); - var upPrintCodeDetails = await _codeDetailService.GetByProductCodes(code); - foreach (var upPrintCodeDetail in upPrintCodeDetails.Where(t=>t.ReportTableId== reprotId)) - { - var reportTable = await _reportTableService.Detail(new QueryByIdReportTableInput { Id = upPrintCodeDetail.ReportTableId??0 }); - if (reportTable.ProductType.Equals("返工生产")) - { - var year = DateTime.Now.ToString("yy"); - var month = DateTime.Now.Month; - var day = DateTime.Now.Day; - int milliseconds = DateTime.Now.Millisecond; // 获取当前时间的毫秒部分(0-999) - upPrintCodeDetail.Code = "F"+ year + month + day + milliseconds + "#" + upPrintCodeDetail.Code; - await _codeDetailService.UpdateByEntity(upPrintCodeDetail); - } - } - + await ReplaceCode(code); var unitRate = Convert.ToDecimal(units.Where(t => t.Name == item.PackageName).FirstOrDefault()?.Rate); var productRate = Convert.ToDecimal(units.Where(t => t.Name == warehousing.Package).FirstOrDefault()?.Rate); decimal unitCount = Math.Round(unitRate / productRate, 2); @@ -276,13 +264,14 @@ public class ReportDetailTableService : IDynamicApiController, ITransient ChildCount = unit.ChildUnitCount, Count = 1, Unit = item.PackageName, - BaseCount = unitCount, + BaseCount = GetUnitCount(units, item.PackageName, warehousing.Package), BaseUnit = warehousing.Package, PrintCodeTime = DateTime.Now, CreateUserId = userId, CreateUserName = userName, ScanCodeTime = DateTime.Now, - ScanCodeName = userName + ScanCodeName = userName, + State = 1 }; var detailId = await _codeDetailService.Add(detail); list.Add(detail, detailId); @@ -291,7 +280,9 @@ public class ReportDetailTableService : IDynamicApiController, ITransient foreach (var child in childs) { var code2 = CodeHelper.GetCode(child.BarCode, child.QrCode); + await ReplaceCode(code2); var unit2 = units.Find(a => a.Name == child.PackageName); + var detail2 = new AddPrintCodeDetailInput() { ReportTableId = reprotId, @@ -300,7 +291,7 @@ public class ReportDetailTableService : IDynamicApiController, ITransient ChildCount = unit2.ChildUnitCount, Count = 1, Unit = child.PackageName, - BaseCount =1, + BaseCount = GetUnitCount(units, child.PackageName, warehousing.Package), BaseUnit = warehousing.Package, PrintCodeTime = DateTime.Now, CreateUserId = userId, @@ -308,15 +299,19 @@ public class ReportDetailTableService : IDynamicApiController, ITransient FatherCode = code, FatherId = detailId, ScanCodeTime = DateTime.Now, - ScanCodeName = userName + ScanCodeName = userName, + State = 1 }; var detailId2 = await _codeDetailService.Add(detail2); list.Add(detail2, detailId2); + + var childs3 = input.CodeDatas.FindAll(a => a.FatherCode == code2); foreach (var child3 in childs3) { var code3 = CodeHelper.GetCode(child3.BarCode, child3.QrCode); + await ReplaceCode(code3); var unit3 = units.Find(a => a.Name == child3.PackageName); var detail3 = new AddPrintCodeDetailInput() { @@ -324,9 +319,8 @@ public class ReportDetailTableService : IDynamicApiController, ITransient Code = code3, CodeName = codeType, ChildCount = unit3.ChildUnitCount, - Count = 1, + BaseCount = GetUnitCount(units, child3.PackageName, warehousing.Package), Unit = child3.PackageName, - BaseCount = 1, BaseUnit = warehousing.Package, PrintCodeTime = DateTime.Now, CreateUserId = userId, @@ -334,16 +328,21 @@ public class ReportDetailTableService : IDynamicApiController, ITransient FatherCode = code2, FatherId = detailId2, ScanCodeTime = DateTime.Now, - ScanCodeName = userName + ScanCodeName = userName, + Count = 1, + State = 1 }; var detailId3 = await _codeDetailService.Add(detail3); list.Add(detail3, detailId3); + + if (input.CodeDatas.Any(a => a.FatherCode == code3)) { var childs4 = input.CodeDatas.FindAll(a => a.FatherCode == code3); foreach (var child4 in childs4) { var code4 = CodeHelper.GetCode(child4.BarCode, child4.QrCode); + await ReplaceCode(code4); var unit4 = units.Find(a => a.Name == child4.PackageName); var detail4 = new AddPrintCodeDetailInput() { @@ -353,7 +352,7 @@ public class ReportDetailTableService : IDynamicApiController, ITransient ChildCount = unit4.ChildUnitCount, Count = 1, Unit = child4.PackageName, - BaseCount = 1, + BaseCount = GetUnitCount(units, child4.PackageName, warehousing.Package), BaseUnit = warehousing.Package, PrintCodeTime = DateTime.Now, CreateUserId = userId, @@ -361,16 +360,20 @@ public class ReportDetailTableService : IDynamicApiController, ITransient FatherCode = code3, FatherId = detailId3, ScanCodeTime = DateTime.Now, - ScanCodeName = userName + ScanCodeName = userName, + State = 1 }; var detailId4 = await _codeDetailService.Add(detail4); list.Add(detail4, detailId4); + + if (input.CodeDatas.Any(a => a.FatherCode == code4)) { var childs5 = input.CodeDatas.FindAll(a => a.FatherCode == code4); foreach (var child5 in childs5) { var code5 = CodeHelper.GetCode(child5.BarCode, child5.QrCode); + await ReplaceCode(code5); var unit5 = units.Find(a => a.Name == child5.PackageName); var detail5 = new AddPrintCodeDetailInput() { @@ -380,7 +383,7 @@ public class ReportDetailTableService : IDynamicApiController, ITransient ChildCount = unit5.ChildUnitCount, Count = 1, Unit = child5.PackageName, - BaseCount = 1, + BaseCount = GetUnitCount(units, child5.PackageName, warehousing.Package), BaseUnit = warehousing.Package, PrintCodeTime = DateTime.Now, CreateUserId = userId, @@ -388,10 +391,12 @@ public class ReportDetailTableService : IDynamicApiController, ITransient FatherCode = code4, FatherId = detailId4, ScanCodeTime = DateTime.Now, - ScanCodeName = userName + ScanCodeName = userName, + State = 1 }; var detailId5 = await _codeDetailService.Add(detail5); list.Add(detail5, detailId5); + } } } @@ -431,16 +436,100 @@ public class ReportDetailTableService : IDynamicApiController, ITransient var upReportTable = await _reportTableService.GetBySource(warehousing.Id); var printCodeDetails = await _codeDetailService.GetByReportTableId(upReportTable.Id); - var count = printCodeDetails.Where(a => !a.IsDelete && a.Unit == a.BaseUnit).Sum(t=>t.Count); - decimal unitSumCount = 0; - foreach (var item in printCodeDetails.Where(a => !a.IsDelete && a.Unit != a.BaseUnit)) + var printCodesNullFatherCode = printCodeDetails.Where(t=>t.Unit == warehousing.Package && string.IsNullOrWhiteSpace(t.FatherCode)); + var clonedList = new List(printCodeDetails); + foreach (var item in printCodesNullFatherCode) { - var unitRate = Convert.ToDecimal(units.Where(t => t.Name == item.Unit).FirstOrDefault()?.Rate); - var productRate = Convert.ToDecimal(units.Where(t => t.Name == item.BaseUnit).FirstOrDefault()?.Rate); - decimal unitCount = Math.Round(unitRate / productRate,2); - unitSumCount += unitCount; + var chilrens1 = printCodeDetails.Where(t => t.FatherCode == item.Code).ToList(); + foreach (var chilren1 in chilrens1) + { + clonedList.Remove(chilren1); + var chilrens2 = printCodeDetails.Where(t => t.FatherCode == chilren1.Code).ToList(); + foreach (var chilren2 in chilrens2) + { + clonedList.Remove(chilren2); + var chilrens3 = printCodeDetails.Where(t => t.FatherCode == chilren2.Code).ToList(); + foreach (var chilren3 in chilrens3) + { + clonedList.Remove(chilren3); + var chilrens4 = printCodeDetails.Where(t => t.FatherCode == chilren3.Code).ToList(); + foreach (var chilren4 in chilrens4) + { + clonedList.Remove(chilren4); + var chilrens5 = printCodeDetails.Where(t => t.FatherCode == chilren4.Code).ToList(); + foreach (var chilren5 in chilrens5) + { + clonedList.Remove(chilren5); + } + } + } + } + } } - upReportTable.BaseProductCount = unitSumCount + count; + var printCodesNotNullFatherCode = printCodeDetails.Where(t => t.Unit == warehousing.Package && !string.IsNullOrWhiteSpace(t.FatherCode)); + foreach (var item in printCodesNotNullFatherCode) + { + var parents1 = printCodeDetails.Where(t => t.Code == item.FatherCode).ToList(); + foreach (var parent1 in parents1) + { + clonedList.Remove(parent1); + var parents2 = printCodeDetails.Where(t => t.Code == parent1.FatherCode).ToList(); + foreach (var parent2 in parents2) + { + clonedList.Remove(parent2); + var parents3 = printCodeDetails.Where(t => t.Code == parent2.FatherCode).ToList(); + foreach (var parent3 in parents3) + { + clonedList.Remove(parent3); + var parents4 = printCodeDetails.Where(t => t.Code == parent3.FatherCode).ToList(); + foreach (var parent4 in parents4) + { + clonedList.Remove(parent4); + var parents5 = printCodeDetails.Where(t => t.Code == parent4.FatherCode).ToList(); + foreach (var parent5 in parents5) + { + clonedList.Remove(parent5); + } + } + } + } + } + + var chilrens1 = printCodeDetails.Where(t => t.FatherCode == item.Code).ToList(); + foreach (var chilren1 in chilrens1) + { + clonedList.Remove(chilren1); + var chilrens2 = printCodeDetails.Where(t => t.FatherCode == chilren1.Code).ToList(); + foreach (var chilren2 in chilrens2) + { + clonedList.Remove(chilren2); + var chilrens3 = printCodeDetails.Where(t => t.FatherCode == chilren2.Code).ToList(); + foreach (var chilren3 in chilrens3) + { + clonedList.Remove(chilren3); + var chilrens4 = printCodeDetails.Where(t => t.FatherCode == chilren3.Code).ToList(); + foreach (var chilren4 in chilrens4) + { + clonedList.Remove(chilren4); + var chilrens5 = printCodeDetails.Where(t => t.FatherCode == chilren4.Code).ToList(); + foreach (var chilren5 in chilrens5) + { + clonedList.Remove(chilren5); + } + } + } + } + } + } + + + decimal unitSumCount = (printCodesNullFatherCode.Sum(t=>t.BaseCount) ?? 0) + (printCodesNotNullFatherCode.Sum(t => t.BaseCount)??0); + //最大单位 + foreach (var item in clonedList.Where(t=>t.Unit!=warehousing.Package)) + { + unitSumCount += GetUnitCount(units,item.Unit,warehousing.Package); + } + upReportTable.BaseProductCount = unitSumCount; var updateReportTableInput = upReportTable.Adapt(); await _reportTableService.Update(updateReportTableInput); //upReportTable. @@ -470,6 +559,38 @@ public class ReportDetailTableService : IDynamicApiController, ITransient } + public async Task ReplaceCode(string code) + { + var upPrintCodeDetails = await _codeDetailService.GetByProductCodes2(code); + var printCodeDetails = await _codeDetailService.GetByReportTableId(upPrintCodeDetails.FirstOrDefault()?.ReportTableId); + foreach (var upPrintCodeDetail in upPrintCodeDetails) + { + var oldCode = upPrintCodeDetail.Code; + var year = DateTime.Now.ToString("yy"); + var month = DateTime.Now.Month; + var day = DateTime.Now.Day; + int milliseconds = DateTime.Now.Millisecond; // 获取当前时间的毫秒部分(0-999) + upPrintCodeDetail.Code = "F" + year + month + day + milliseconds + "#" + upPrintCodeDetail.Code; + await _codeDetailService.UpdateByEntity(upPrintCodeDetail); + var chilrens = printCodeDetails.Where(t => t.FatherCode == oldCode).ToList(); + foreach (var chilren in chilrens) + { + chilren.FatherCode = upPrintCodeDetail.Code; + await _codeDetailService.UpdateByEntity(chilren); + } + } + } + + public decimal GetUnitCount(List units,string packageName,string wareHousingPackage) + { + var unitRate = Convert.ToDecimal(units.Where(t => t.Name == packageName).FirstOrDefault()?.Rate); + var productRate = Convert.ToDecimal(units.Where(t => t.Name == wareHousingPackage).FirstOrDefault()?.Rate); + decimal unitCount = Math.Round(unitRate / productRate, 2); + return unitCount; + } + + + /// /// 删除汇报单详情 /// @@ -606,22 +727,7 @@ public class ReportDetailTableService : IDynamicApiController, ITransient var newCodeDetail = await _codeDetailService.GetByProductCode(input.NewCodeName); if (newCodeDetail != null) { - var reportTable = await _reportTableService.Detail(new QueryByIdReportTableInput { Id = newCodeDetail.ReportTableId ?? 0 }); - if (reportTable.ProductType.Equals("返工生产")) - { - var year = DateTime.Now.ToString("yy"); - var month = DateTime.Now.Month; - var day = DateTime.Now.Day; - int milliseconds = DateTime.Now.Millisecond; // 获取当前时间的毫秒部分(0-999) - newCodeDetail.Code = "F" + year + month + day + milliseconds + "#" + newCodeDetail.Code; - await _codeDetailService.UpdateByEntity(newCodeDetail); - codeDetail.Code = input.NewCodeName; - await _codeDetailService.UpdateByEntity(codeDetail); - } - else - { - throw Oops.Oh($"替换条码重复"); - } + throw Oops.Oh($"条码重复"); } else { diff --git a/Web/src/views/productionCenter/reportDetailTable/component/editDialog.vue b/Web/src/views/productionCenter/reportDetailTable/component/editDialog.vue index f2f4505..d2a8a60 100644 --- a/Web/src/views/productionCenter/reportDetailTable/component/editDialog.vue +++ b/Web/src/views/productionCenter/reportDetailTable/component/editDialog.vue @@ -7,17 +7,17 @@ - + - + - + @@ -25,7 +25,7 @@ - + @@ -49,17 +49,17 @@ - + - + - + @@ -67,7 +67,7 @@ - + @@ -75,7 +75,7 @@ - + diff --git a/Web/src/views/productionCenter/reportTable/component/codeDialog.vue b/Web/src/views/productionCenter/reportTable/component/codeDialog.vue index 7e71000..776336b 100644 --- a/Web/src/views/productionCenter/reportTable/component/codeDialog.vue +++ b/Web/src/views/productionCenter/reportTable/component/codeDialog.vue @@ -1,13 +1,19 @@