diff --git a/ZR.Admin.WebApi/Controllers/mes/wms/WmPolishInventoryController.cs b/ZR.Admin.WebApi/Controllers/mes/wms/WmPolishInventoryController.cs index c910227a..48637a6e 100644 --- a/ZR.Admin.WebApi/Controllers/mes/wms/WmPolishInventoryController.cs +++ b/ZR.Admin.WebApi/Controllers/mes/wms/WmPolishInventoryController.cs @@ -1,9 +1,11 @@ using Microsoft.AspNetCore.Mvc; +using MiniExcelLibs; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; using ZR.Model; using ZR.Model.MES.wms; using ZR.Model.MES.wms.Dto; +using ZR.Model.System; using ZR.Model.System.Dto; using ZR.Service.mes.wms; using ZR.Service.mes.wms.IService; @@ -216,5 +218,38 @@ namespace ZR.Admin.WebApi.Controllers var response = _WmPolishInventoryService.GetPartNumber(); return SUCCESS(response); } + + + /// + /// 抛光导入模板下载 + /// + /// + [HttpGet("importTemplate")] + [Log(Title = "抛光模板", BusinessType = BusinessType.EXPORT, IsSaveRequestData = true, IsSaveResponseData = false)] + [AllowAnonymous] + public IActionResult ImportTemplateExcel() + { + (string, string) result = DownloadImportTemplate("抛光仓库盘点模板"); + return ExportExcel(result.Item2, result.Item1); + } + + /// + /// 导入 + /// + /// 使用IFromFile必须使用name属性否则获取不到文件 + /// + [HttpPost("importData")] + [Log(Title = "抛光盘点导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = true)] + [AllowAnonymous] + public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile) + { + List importList = new(); + using (var stream = formFile.OpenReadStream()) + { + importList = stream.Query(startCell: "A1").ToList(); + } + + return SUCCESS(_WmPolishInventoryService.ImportExcel(importList)); + } } } diff --git a/ZR.Model/MES/wms/Dto/WmOneTimeInventoryDto.cs b/ZR.Model/MES/wms/Dto/WmOneTimeInventoryDto.cs index 470a1217..9b50798b 100644 --- a/ZR.Model/MES/wms/Dto/WmOneTimeInventoryDto.cs +++ b/ZR.Model/MES/wms/Dto/WmOneTimeInventoryDto.cs @@ -36,6 +36,8 @@ namespace ZR.Model.MES.wms.Dto public int? Quantity { get; set; } + public int RealQuantity { get; set; } + public int? MaxNum { get; set; } public int? MinNum { get; set; } diff --git a/ZR.Model/MES/wms/Dto/WmPolishInventoryDto.cs b/ZR.Model/MES/wms/Dto/WmPolishInventoryDto.cs index 0c028a95..81b1f6f4 100644 --- a/ZR.Model/MES/wms/Dto/WmPolishInventoryDto.cs +++ b/ZR.Model/MES/wms/Dto/WmPolishInventoryDto.cs @@ -1,3 +1,5 @@ +using MiniExcelLibs.Attributes; + namespace ZR.Model.MES.wms.Dto { /// @@ -59,20 +61,19 @@ namespace ZR.Model.MES.wms.Dto public DateTime? UpdatedTime { get; set; } } - + [SugarTable("wm_polish_inventory", "抛光表")] public class WmPolishInventoryExportDto { + [SugarColumn(ColumnName = "partnumber")] public string 零件号 { get; set; } - public string 颜色 { get; set; } - public string 规格 { get; set; } - public string 描述 { get; set; } - + [SugarColumn(ColumnName = "quantity")] public int 盘点数 { get; set; } = 0; - public int 现有库存 { get; set; } = 0; + [SugarColumn(ColumnName = "CREATED_TIME")] + public DateTime? 盘点时间 { get; set; } } } diff --git a/ZR.Service/mes/qc/CommonFQCService.cs b/ZR.Service/mes/qc/CommonFQCService.cs index 3add81be..87fee779 100644 --- a/ZR.Service/mes/qc/CommonFQCService.cs +++ b/ZR.Service/mes/qc/CommonFQCService.cs @@ -1289,16 +1289,14 @@ namespace ZR.Service.mes.qc boardData.StockOneTimeWarehouseCount = oneTimeWarehouseTotal; // 产线合格 int productQualifiedTotal = - ( - Context - .Queryable() - .WhereIF( - !string.IsNullOrEmpty(query.Partnumber), - it => it.FinishedPartNumber == query.Partnumber - ) - .Where(it => it.StartTime >= boardData.OneTimeStockTime) - .Sum(it => it.QualifiedNumber) ?? 0 - ) / 3; + Context + .Queryable() + .WhereIF( + !string.IsNullOrEmpty(query.Partnumber), + it => it.FinishedPartNumber == query.Partnumber + ) + .Where(it => it.StartTime >= boardData.OneTimeStockTime) + .Sum(it => it.QualifiedNumber) ?? 0; // 倒车雷达 string[] checkStrArray2 = { "倒车雷达" }; var ParkingSensorPartNumberCheck = Expressionable.Create(); @@ -1306,7 +1304,7 @@ namespace ZR.Service.mes.qc { ParkingSensorPartNumberCheck.Or(it => it.Description.Contains(checkStr)); } - ; + ; ParkingSensorPartNumberCheck.And(it => it.Type == 1).And(it => it.Status == 1); List ParkingSensorPartNumberList = Context .Queryable() @@ -1325,9 +1323,9 @@ namespace ZR.Service.mes.qc .Queryable() .Where(predicateParkingSensor) .Sum(it => it.QualifiedNumber) ?? 0; - productParkingSensorbQualifiedTotal = productParkingSensorbQualifiedTotal / 3; // 产线合格 - 倒车雷达 - productQualifiedTotal -= productParkingSensorbQualifiedTotal; + productQualifiedTotal = + (productQualifiedTotal - productParkingSensorbQualifiedTotal) / 3; // 抛光合格 int polishQualifiedTotal = @@ -1350,13 +1348,14 @@ namespace ZR.Service.mes.qc .Where(it => it.StartTime >= boardData.OneTimeStockTime) .Sum(it => it.RequireNumber) ?? 0; // 后道直接出库 - int afterPolishOutTotal = Context + int afterPolishOutTotal = + Context .Queryable() .WhereIF( !string.IsNullOrEmpty(query.Partnumber), it => it.Partnumber == query.Partnumber ) - .Where(it =>it.Type == 1) + .Where(it => it.Type == 1) .Where(it => it.StartTime >= boardData.OneTimeStockTime) .Sum(it => it.RequireNumber) ?? 0; diff --git a/ZR.Service/mes/wms/IService/IWmPolishInventoryService.cs b/ZR.Service/mes/wms/IService/IWmPolishInventoryService.cs index 664309df..df2c1f1a 100644 --- a/ZR.Service/mes/wms/IService/IWmPolishInventoryService.cs +++ b/ZR.Service/mes/wms/IService/IWmPolishInventoryService.cs @@ -57,5 +57,11 @@ namespace ZR.Service.mes.wms.IService /// /// public int GetPartNumber(); + /// + /// 导入Excel + /// + /// + /// + public (string, object, object) ImportExcel(List users); } } diff --git a/ZR.Service/mes/wms/WmOneTimeInventoryService.cs b/ZR.Service/mes/wms/WmOneTimeInventoryService.cs index f72c704c..fe78cbd7 100644 --- a/ZR.Service/mes/wms/WmOneTimeInventoryService.cs +++ b/ZR.Service/mes/wms/WmOneTimeInventoryService.cs @@ -75,6 +75,12 @@ namespace ZR.Service.mes.wms item.Description = !string.IsNullOrEmpty(material.Description) ? material.Description : material.ProductName; + + // 获取实际库存 + List partnumbers = new List(); + partnumbers.Add(item.Partnumber); + Dictionary dict = GetBatchOneTimeRealPartNum(partnumbers); + item.RealQuantity = dict.TryGetValue(item.Partnumber, out int value) ? value : 0; } } return response; @@ -481,7 +487,7 @@ namespace ZR.Service.mes.wms .ToDictionary(g => g.Partnumber, g => SqlFunc.AggregateSum(g.Quantity) ?? 0); } - // Util 获取指定抛光库零件加报表后库存 + // Util 获取指定一次合格库零件加报表后库存 public Dictionary GetBatchOneTimeRealPartNum(List partnumbers) { try diff --git a/ZR.Service/mes/wms/WmPolishInventoryService.cs b/ZR.Service/mes/wms/WmPolishInventoryService.cs index d6d81ba4..e1366fce 100644 --- a/ZR.Service/mes/wms/WmPolishInventoryService.cs +++ b/ZR.Service/mes/wms/WmPolishInventoryService.cs @@ -2,15 +2,19 @@ using System; using System.Linq; using System.Threading.Tasks; using Aliyun.OSS; +using Infrastructure; using Infrastructure.Attribute; using Infrastructure.Extensions; +using JinianNet.JNTemplate; using Microsoft.AspNetCore.DataProtection.KeyManagement; using Newtonsoft.Json.Linq; using SqlSugar; +using ZR.Common; using ZR.Model; using ZR.Model.MES.qc.DTO; using ZR.Model.MES.wms; using ZR.Model.MES.wms.Dto; +using ZR.Model.System; using ZR.Repository; using ZR.Service.mes.qc; using ZR.Service.mes.wms.IService; @@ -83,6 +87,12 @@ namespace ZR.Service.mes.wms item.Description = !string.IsNullOrEmpty(material.Description) ? material.Description : material.ProductName; + // 获取实际库存 + + List partnumbers = new List(); + partnumbers.Add(item.Partnumber); + Dictionary dict = GetBatchPolishRealPartNum(partnumbers); + item.RealQuantity = dict.TryGetValue(item.Partnumber, out int value)? value : 0; } } return response; @@ -518,6 +528,9 @@ namespace ZR.Service.mes.wms Dictionary stockNumbers = GetBatchPolishStockPartNum(partnumbers); Dictionary realNumbers = GetBatchPolishRealPartNum(partnumbers); + // 更新盘点时间 + DateTime dateTime = DateTime.Now.ToLocalTime(); + // 构建导出数据 List exportDto = materials .Select(it => @@ -532,6 +545,7 @@ namespace ZR.Service.mes.wms 颜色 = it.Color, 规格 = it.Specification, 描述 = it.Description, + 盘点时间 = dateTime, 盘点数 = stockNumber, 现有库存 = found2 ? realNumber : 0, }; @@ -576,5 +590,57 @@ namespace ZR.Service.mes.wms throw; } } + + /// + /// 导入数据 + /// + /// + /// + public (string, object, object) ImportExcel(List importList) + { + List wmPolishInventorylist = importList.Select(it => new WmPolishInventory { + Id = SnowFlakeSingle.Instance.NextId().ToString(), + Type = 1, + Status = 1, + MaxNum = 0, + MinNum = 0, + WarnNum = 0, + CreatedBy = "页面导入", + Remark = "EXCEL 盘点导入", + CreatedTime = it.盘点时间 ?? DateTime.Now.ToLocalTime(), + Partnumber = it.零件号, + Quantity = it.盘点数 + }).ToList(); + var x = Context.Storageable(wmPolishInventorylist) + .SplitError(x => x.Item.Partnumber.IsEmpty(), "零件号不能为空") + .SplitError(x => x.Item.Quantity.IsEmpty(), "盘点数不能为空") + .SplitUpdate(it => it.Any()) // 数据库存在更新 + .SplitDelete(it => it.Item.Quantity == 0) //盘点数为0的不导入 + .SplitInsert(it => true) // 其余插入 + .WhereColumns(it => it.Partnumber)//如果不是主键可以这样实现(多字段it=>new{it.x1,it.x2}) + .ToStorage(); + + // 清空全部 + var result = x.AsInsertable.ExecuteCommand();//不存在则插入; + var result2 = x.AsUpdateable.IgnoreColumns(it => new { it.Id }).ExecuteCommand();//存在则修改; + var result3 = x.AsDeleteable.ExecuteCommand(); //盘点数为0的删除; + string msg = string.Format(" 插入{0} 更新{1} 错误数据{2} 不计算数据{3} 删除数据{4} 总共{5}", + x.InsertList.Count, + x.UpdateList.Count, + x.ErrorList.Count, + x.IgnoreList.Count, + x.DeleteList.Count, + x.TotalList.Count); + //输出统计 + Console.WriteLine(msg); + + //输出错误信息 + foreach (var item in x.ErrorList) + { + Console.WriteLine("零件异常:" + item.Item.Partnumber + " : " + item.StorageMessage); + } + + return (msg, x.ErrorList, x.IgnoreList); + } } }