diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/MsgBaseData/AssemblyCfgs/Dtos/ImportErpAssemblyGroupDto.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/MsgBaseData/AssemblyCfgs/Dtos/ImportErpAssemblyGroupDto.cs new file mode 100644 index 0000000..280b57b --- /dev/null +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/MsgBaseData/AssemblyCfgs/Dtos/ImportErpAssemblyGroupDto.cs @@ -0,0 +1,39 @@ +using Magicodes.ExporterAndImporter.Core; +using Magicodes.ExporterAndImporter.Excel; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Text; + +namespace WY.NewJit.MsgBaseData +{ + /// + /// 总成组 + /// + [ExcelExporter(Name = "总成组表", AutoFitAllColumn = true, MaxRowNumberOnASheet = 50000)] //一个Sheet最大允许的行数,设置了之后将输出多个Sheet + [Serializable] + public class ImportErpAssemblyGroupDto + { + /// + /// 规格说明 + /// + [ExporterHeader(DisplayName = "规格说明")] + [ImporterHeader(Name = "规格说明")] + [Required(ErrorMessage = "{0}是必填项")] + public virtual string SpecExplain { get; set; } + /// + /// 颜色说明 + /// + [ExporterHeader(DisplayName = "颜色说明")] + [ImporterHeader(Name = "颜色说明")] + [Required(ErrorMessage = "{0}是必填项")] + public virtual string ColorExplain { get; set; } + /// + /// 物料号 + /// + [ExporterHeader(DisplayName = "物料号")] + [ImporterHeader(Name = "物料号")] + [Required(ErrorMessage = "{0}是必填项")] + public virtual string MaterialNum { get; set; } + } +} diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/WY.NewJit.Application.Contracts.xml b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/WY.NewJit.Application.Contracts.xml index 3c1b4a6..2d956da 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/WY.NewJit.Application.Contracts.xml +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/WY.NewJit.Application.Contracts.xml @@ -1402,6 +1402,26 @@ 创建时间 + + + 总成组 + + + + + 规格说明 + + + + + 颜色说明 + + + + + 物料号 + + ERP总成编码 diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/MsgBaseData/AssemblyCfgs/AssemblyCfgErpAppService.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/MsgBaseData/AssemblyCfgs/AssemblyCfgErpAppService.cs index ff04062..4dc9c26 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/MsgBaseData/AssemblyCfgs/AssemblyCfgErpAppService.cs +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/MsgBaseData/AssemblyCfgs/AssemblyCfgErpAppService.cs @@ -23,6 +23,7 @@ using System.Data; using Microsoft.AspNetCore.Authorization; using WY.NewJit.Extends.PaiGe; using Volo.Abp; +using Magicodes.ExporterAndImporter.Core.Models; namespace WY.NewJit.MsgBaseData { @@ -33,6 +34,10 @@ namespace WY.NewJit.MsgBaseData [ApiExplorerSettings(GroupName = SwaggerGroupConsts.基础数据)] public class AssemblyCfgErpAppService : ApplicationService, IAssemblyCfgErpAppService { + /// + /// 总成组 + /// + private readonly IRepository _assemblyCfgGroupRepository; /// /// ERP总成仓储 /// @@ -112,7 +117,8 @@ SELECT top 1 v.Id AssemblyDomainService assemblyDomainService, IRepository partCfgRepository, IRepository materialExtRepository, - GlobalSettingsDomainService globalSettingsDomainService + GlobalSettingsDomainService globalSettingsDomainService, + IRepository assemblyCfgGroupRepository ) { _assemblyCfgErpRepository = assemblyCfgErpRepository; @@ -124,6 +130,7 @@ SELECT top 1 v.Id _partCfgRepository = partCfgRepository; _materialExtRepository = materialExtRepository; _globalSettingsDomainService = globalSettingsDomainService; + _assemblyCfgGroupRepository = assemblyCfgGroupRepository; } @@ -668,11 +675,158 @@ SELECT top 1 v.Id } } + /// - /// 校验ERP总成:是否版本覆盖 + /// 导入 /// - /// - /// + /// 导入文件 + /// 执行成功返回真 + [HttpPost] + [Route("import-erp-assembly-group")] + [DisableRequestSizeLimit] + public virtual async Task ImportErpAssemblyGroupAsync([FromForm] IFormFileCollection files) + { + + _logger.LogDebug(_errorMessagePrefix + "ImportErpAssemblyGroupAsync 进入"); + ObjectResultDto ret = new ObjectResultDto(); + try + { + #region 导入文件处理 + ImportResult impResult; + using (var memoryStream = new MemoryStream()) + { + //保存到内存流 + IFormFile file = files[0]; + await file.CopyToAsync(memoryStream); + memoryStream.Seek(0, SeekOrigin.Begin); + //StreamReader sr = new StreamReader(memoryStream, Encoding.Default); + IImporter importer = new ExcelImporter(); + impResult = await importer.Import(memoryStream); + if (impResult.HasError) + { + string rowErrStr = ""; + foreach (var rowErr in impResult.RowErrors) + { + string fieldErr = string.Concat(rowErr.FieldErrors.Select(itm => $"字段:{itm.Key},错误信息:{itm.Value}")); + rowErrStr += $"行号:{rowErr.RowIndex},{fieldErr}\r\n"; + } + string templateErrStr = ""; + foreach (var templateErr in impResult.TemplateErrors) + { + string errorLevel = templateErr.ErrorLevel == ErrorLevels.Error ? "错误" : "警告"; + templateErrStr += $"错误等级:{errorLevel},列名:{templateErr.ColumnName},需要列:{templateErr.RequireColumnName},错误消息:{templateErr.Message}\r\n"; + } + ret.Message = rowErrStr + templateErrStr; + ret.Status = false; + return ret; + } + } + #endregion + #region 数据验证 + var srcLst = impResult.Data.AsEnumerable().ToList(); + List material3Lst = await _materialExtRepository.Where(itm => itm.MaterialType == "3").ToListAsync(); + + var error= CheckGroup(srcLst, material3Lst); + if (!string.IsNullOrEmpty(error)) + { + ret.Message = error; + ret.Status = false; + return ret; + } + #endregion + #region 插入数据 + List assemblyCfgGroups = new List(); + List deleteAssemblyCfgGroups = new List(); + List assemblyCfgErps = new List(); + var groups = srcLst.GroupBy(r => new { r.SpecExplain, r.ColorExplain }).ToList(); + foreach (var group in groups) + { + + var olditem= await _assemblyCfgGroupRepository.FirstOrDefaultAsync(r=>r.IsDisable==true&&r.SpecExplain== group.Key.SpecExplain.Trim()&& r.ColorExplain == group.Key.ColorExplain.Trim()); + if (olditem != null) + { + olditem.IsDisable = false; + deleteAssemblyCfgGroups.Add(olditem); + } + string groupCode = group.Key.SpecExplain + group.Key.ColorExplain; + AssemblyCfgGroup assemblyCfgGroup = new AssemblyCfgGroup(GuidGenerator.Create() , groupCode,"",true); + assemblyCfgGroup.SpecExplain = group.Key.SpecExplain.Trim(); + assemblyCfgGroup.ColorExplain = group.Key.ColorExplain.Trim(); + foreach (var item in group) + { + var material3 = material3Lst.FirstOrDefault(r => r.MaterialNum == item.MaterialNum.Trim()); + AssemblyCfgErp assemblyCfgErp = new AssemblyCfgErp(GuidGenerator.Create()); + assemblyCfgErp.ErpAssemblyCode = item.MaterialNum.Trim(); + assemblyCfgErp.ErpAssemblyName = material3.MaterialDescription; + assemblyCfgErp.ErpAssemblyVersion = 1; + assemblyCfgErp.GroupCode = groupCode; + assemblyCfgErp.GroupId = assemblyCfgGroup.Id; + assemblyCfgErp.SpecExplain = item.SpecExplain.Trim(); + assemblyCfgErp.ColorExplain = item.ColorExplain.Trim(); + assemblyCfgErps.Add(assemblyCfgErp); + } + assemblyCfgGroups.Add(assemblyCfgGroup); + } + + //插入“导入记录表” + await _assemblyCfgGroupRepository.UpdateManyAsync(deleteAssemblyCfgGroups);//更新总成组 + await _assemblyCfgGroupRepository.InsertManyAsync(assemblyCfgGroups); + await _assemblyCfgErpRepository.InsertManyAsync(assemblyCfgErps); + #endregion + ret.Status = true; + return ret; + } + catch (Exception ex) + { + ret.Status = false; + ret.Message = _errorMessagePrefix + "ImportErpAssemblyGroupAsync 执行出错:" + ex.Message; + _logger.LogError(ret.Message); + return ret; + } + } + + private string CheckGroup(List srcLst, List material3Lst) + { + //验证是否有重复项 + string error = ""; + var disitem = srcLst.Distinct(); + if (disitem.Count() != srcLst.Count()) + { + error = "导入数据有重复项,检查后在导入!"; + } + if (!string.IsNullOrEmpty(error)) return error; + + + #region 验证分组是否符合分组规 + + var checkGroups = srcLst.GroupBy(r => new { r.SpecExplain, r.ColorExplain }).Select(r => new { SpecExplain = r.Key.SpecExplain, ColorExplain = r.Key.ColorExplain, Count = r.Count() }); + var errorgroups = checkGroups.Where(r => r.Count != 4).ToList(); + foreach (var item in errorgroups) + { + error += $"规格说明【{item.SpecExplain}】,颜色说明【{item.ColorExplain}】,零件数【{item.Count}】不符合分组规则\r\n"; + } + if (!string.IsNullOrEmpty(error)) return error; + + #endregion + + #region 验证零件是否存在(门板) + + + var partdists = srcLst.Select(r => r.MaterialNum).Distinct(); + foreach (var material in partdists) + { + var material3 = material3Lst.FirstOrDefault(r => r.MaterialNum == material); + if (material3 == null) + { + error += $"零件编号【{material}】系统同不存在,请检查后再导入\r\n"; + } + } + + #endregion + return error; + } + + //[UnitOfWork] //[HttpPost] //[Route("check")] diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/WY.NewJit.Application.xml b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/WY.NewJit.Application.xml index 65ea879..635ee4e 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/WY.NewJit.Application.xml +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/WY.NewJit.Application.xml @@ -39,12 +39,17 @@ 字典领域服务 + + + 配置 + + 错误信息前缀 - + 构造函数 @@ -124,6 +129,13 @@ 导入文件 执行成功返回真 + + + 打印时间提醒 + + + + 生产线权限管理应用服务实现 @@ -264,6 +276,11 @@ 总成配置应用服务实现 + + + 总成组 + + ERP总成仓储 @@ -314,7 +331,7 @@ 错误信息前缀 - + 构造函数 @@ -389,6 +406,13 @@ 导入文件 执行成功返回真 + + + 导入 + + 导入文件 + 执行成功返回真 + 系统初始化时使用,去掉重复的ERP总成