From 558da06c8c4db59eb605ee0043c753ddc00fe205 Mon Sep 17 00:00:00 2001 From: liuyunfeng Date: Tue, 16 Jan 2024 17:39:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=A5=E6=96=87=E5=AF=BC=E5=85=A5-=E5=88=9D?= =?UTF-8?q?=E6=AD=A5=E6=B5=8B=E8=AF=95=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Interfaces/IImportRecordAppService.cs | 9 +- .../WY.NewJit.Application.Contracts.xml | 5 +- .../EdiReceive/ImportRecordAppService.cs | 95 +++---- .../WY.NewJit.Application.xml | 5 +- .../Common/ServerHelper.cs | 2 +- .../EdiReceive/Entitys/LastImportHostSN.cs | 4 + .../Services/EdiParseDomainService.cs | 243 ++++++++++-------- .../Services/HQ_CacheManagerDomainService.cs | 16 +- .../Services/LastImportHostSNDomainService.cs | 35 ++- 9 files changed, 228 insertions(+), 186 deletions(-) diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/EdiReceive/Interfaces/IImportRecordAppService.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/EdiReceive/Interfaces/IImportRecordAppService.cs index 60aa61a..2217244 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/EdiReceive/Interfaces/IImportRecordAppService.cs +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application.Contracts/EdiReceive/Interfaces/IImportRecordAppService.cs @@ -6,9 +6,7 @@ using System.Text; using System.Threading.Tasks; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; -using Volo.Abp.Uow; using WY.NewJit.EdiReceive.Dtos; -using WY.NewJit.MsgCheck; namespace WY.NewJit.EdiReceive.Interfaces { @@ -62,11 +60,10 @@ namespace WY.NewJit.EdiReceive.Interfaces /// /// 导入信息 /// - /// 导入文件流 + /// 导入文件流 + /// 是否强制执行 /// 执行成功返回真 - Task ImportAsync([FromForm] IFormFileCollection files); - [HttpPost, Route("print-timeout-remind"), UnitOfWork] - Task PrintTimeoutRemind(TimeOutRemindInputDto input); + Task ImportAsync([FromForm] IFormFileCollection files, bool forceExecute = false); #endregion } 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..d5ef880 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 @@ -556,11 +556,12 @@ 导出查询条件 执行成功返回真 - + 导入信息 - 导入文件流 + 导入文件流 + 是否强制执行 执行成功返回真 diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/EdiReceive/ImportRecordAppService.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/EdiReceive/ImportRecordAppService.cs index 3e55b0f..b95d960 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/EdiReceive/ImportRecordAppService.cs +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/EdiReceive/ImportRecordAppService.cs @@ -20,9 +20,9 @@ using WY.NewJit.Common; using WY.NewJit.EdiReceive.Dtos; using WY.NewJit.EdiReceive.Entitys; using WY.NewJit.EdiReceive.Interfaces; +using WY.NewJit.EdiReceive.Services; using WY.NewJit.EntityFrameworkCore; using WY.NewJit.MsgBaseData; -using WY.NewJit.MsgCheck; namespace WY.NewJit.EdiReceive { @@ -58,10 +58,8 @@ namespace WY.NewJit.EdiReceive /// 字典领域服务 /// private readonly DicDomainService _dicDomainService; - /// - /// 配置 - /// - private readonly Microsoft.Extensions.Configuration.IConfiguration _configuration; + + private readonly EdiParseDomainService _ediParseDomainService; /// /// 错误信息前缀 @@ -86,15 +84,14 @@ namespace WY.NewJit.EdiReceive NewJitDapperRepository newJitDapperRepository, IBlobContainer blobContainer, DicDomainService dicDomainService, - Microsoft.Extensions.Configuration.IConfiguration configuration - ) + EdiParseDomainService ediParseDomainService) { _importRecordRepository = importRecordRepository; _logger = logger; _newJitDapperRepository = newJitDapperRepository; _blobContainer = blobContainer; _dicDomainService = dicDomainService; - _configuration = configuration; + _ediParseDomainService = ediParseDomainService; } #region 私有方法 @@ -264,8 +261,6 @@ namespace WY.NewJit.EdiReceive } } - - /// /// 按主键获取唯一实体 /// @@ -418,11 +413,13 @@ namespace WY.NewJit.EdiReceive /// 导入 /// /// 导入文件 + /// 校验出错时,是否强制执行 /// 执行成功返回真 + [UnitOfWork] [HttpPost] [Route("import")] [DisableRequestSizeLimit] - public virtual async Task ImportAsync([FromForm] IFormFileCollection files) + public virtual async Task ImportAsync([FromForm] IFormFileCollection files, bool forceExecute = false) { _logger.LogDebug(_errorMessagePrefix + "ImportAsync 进入"); @@ -439,34 +436,44 @@ namespace WY.NewJit.EdiReceive //StreamReader sr = new StreamReader(memoryStream, Encoding.Default); IImporter importer = new ExcelImporter(); impResult = await importer.Import(memoryStream); - if (impResult.HasError) + } + + 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 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; + 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; } + var srcLst = impResult.Data.AsEnumerable().ToList(); var tarLst = ObjectMapper.Map, List>(srcLst); foreach (var tar in tarLst) { - tar.CreatePerson = "导入"; + //tar.CreatePerson = "导入"; tar.CreateTime = ServerHelper.CurrentDateTime; } - //插入“导入记录表” - await _importRecordRepository.InsertManyAsync(tarLst); + //报文解析 + ObjectResultDto ret2 = await _ediParseDomainService.ParseEdi(tarLst, forceExecute); + if (ret2.Status == false) + { + return ret2; + } + if (ret2.Status == true && ret2.Message.HasValue()) + { + return ret2; + } ret.Status = true; return ret; } @@ -479,33 +486,5 @@ namespace WY.NewJit.EdiReceive } } #endregion - - - /// - /// 打印时间提醒 - /// - /// - /// - [UnitOfWork] - [HttpPost] - [Route("print-timeout-remind")] - public virtual async Task PrintTimeoutRemind(TimeOutRemindInputDto input) - { - TimeOutRemindResultDto retObj = new TimeOutRemindResultDto(); - retObj.ConfigMinutes = _configuration[$"ConfigDic:ProductLineTimeoutRemind_New:{"Record"}"].TryToInt() ?? 40; - var qry =await _importRecordRepository.MaxAsync(itm => itm.CreateTime); - retObj.LastReceiveTime = qry != null ? Convert.ToDateTime(qry) : ServerHelper.CurrentDateTime; - retObj.TimeoutMinutes = MinuteDiff(retObj.LastReceiveTime, ServerHelper.CurrentDateTime); - return retObj; - } - - private int MinuteDiff(DateTime beginTime, DateTime endTime) - { - TimeSpan beginSpan = new TimeSpan(beginTime.Ticks); - TimeSpan endSpan = new TimeSpan(endTime.Ticks); - TimeSpan diffSpan = endSpan.Subtract(beginSpan).Duration(); - return (int)(diffSpan.TotalMinutes); - } - } } 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..8d3a481 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 @@ -44,7 +44,7 @@ 错误信息前缀 - + 构造函数 @@ -117,11 +117,12 @@ 导出查询条件 执行成功返回真 - + 导入 导入文件 + 校验出错时,是否强制执行 执行成功返回真 diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain.Shared/Common/ServerHelper.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain.Shared/Common/ServerHelper.cs index 0282148..c9e3bc8 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain.Shared/Common/ServerHelper.cs +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain.Shared/Common/ServerHelper.cs @@ -146,7 +146,7 @@ namespace WY.NewJit { throw new Exception("ToSerialNumStr大众顺序号不能为空!"); } - return ((DateTime)onlineTime).ToString("yyyyMMddHHmm") + "00" + hostSN.ToString().PadLeft(5, '0'); + return ((DateTime)onlineTime).ToString("yyyyMMddHHmmss") + hostSN.ToString().PadLeft(5, '0'); } /// diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/EdiReceive/Entitys/LastImportHostSN.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/EdiReceive/Entitys/LastImportHostSN.cs index 8038136..549a1ba 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/EdiReceive/Entitys/LastImportHostSN.cs +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/EdiReceive/Entitys/LastImportHostSN.cs @@ -13,5 +13,9 @@ namespace WY.NewJit.EdiReceive.Entitys public int HostSN { get; set; } + public LastImportHostSN(Guid id) + :base(id) + { + } } } diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/EdiReceive/Services/EdiParseDomainService.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/EdiReceive/Services/EdiParseDomainService.cs index f8508dc..959d1ab 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/EdiReceive/Services/EdiParseDomainService.cs +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/EdiReceive/Services/EdiParseDomainService.cs @@ -39,7 +39,7 @@ namespace WY.NewJit.EdiReceive.Services private readonly DicDomainService _dicDomainService; /// - /// 零件仓储 + /// 导入记录仓储 /// private readonly IRepository _importRecordRepository; @@ -51,32 +51,40 @@ namespace WY.NewJit.EdiReceive.Services /// /// ERP总成分组仓库 /// - private readonly IRepository _assemblyCfgGroupRepository; + //private readonly IRepository _assemblyCfgGroupRepository; /// /// ERP总成仓储 /// - private readonly IRepository _assemblyCfgErpRepository; + //private readonly IRepository _assemblyCfgErpRepository; /// /// 整车总成配置仓库 /// private readonly IRepository _assemblyCfgVehicleRepository; - + /// + /// 导入最大流水号 领域服务 + /// private readonly LastImportHostSNDomainService _lastImportHostSNDomainService; + /// + /// 缓存管理 领域服务 + /// private readonly HQ_CacheManagerDomainService _hqCacheManagerDomainService; + /// + /// 插入M100、未打印表 领域服务 + /// private readonly HQ_M100DomainService _hqM100DomainServie; /// - /// 重复M100 + /// 重复报文仓库 /// private readonly IRepository _repeatM100Repository; /// - /// 未知总成维护 + /// 未知总成仓库 /// private readonly IRepository _unknownAssemblyRepository; @@ -84,12 +92,12 @@ namespace WY.NewJit.EdiReceive.Services /// /// 报文车型对应零件生产工厂车型 /// - private static List _msgToPaiGeVehicleModelList = new List(); + //private static List _msgToPaiGeVehicleModelList = new List(); /// /// M100零件生产工厂车型对应生产线 /// - private static List _m100VehicleModelProductLineList = new List(); + //private static List _m100VehicleModelProductLineList = new List(); /// /// 根据车型代码中的前两位(HS),过滤属于派格的订单;只针对派格的订单进行报文解析 @@ -118,12 +126,11 @@ namespace WY.NewJit.EdiReceive.Services _billM100Repository = billM100Repository; _lastImportHostSNDomainService = lastImportHostSNDomainService; - _msgToPaiGeVehicleModelList = _dicDomainService.GetDicItems(DicTypeName.报文车型对应派格车型); - _m100VehicleModelProductLineList = _dicDomainService.GetDicItems(DicTypeName.M100派格车型对应生产线); - _assemblyCfgGroupRepository = assemblyCfgGroupRepository; - _assemblyCfgErpRepository = assemblyCfgErpRepository; + //_msgToPaiGeVehicleModelList = _dicDomainService.GetDicItems(DicTypeName.报文车型对应派格车型); + //_m100VehicleModelProductLineList = _dicDomainService.GetDicItems(DicTypeName.M100派格车型对应生产线); + //_assemblyCfgGroupRepository = assemblyCfgGroupRepository; + //_assemblyCfgErpRepository = assemblyCfgErpRepository; _assemblyCfgVehicleRepository = assemblyCfgVehicleRepository; - _hqCacheManagerDomainService = hqCacheManagerDomainService; _hqM100DomainServie = hqM100DomainServie; _repeatM100Repository = repeatM100Repository; @@ -132,43 +139,39 @@ namespace WY.NewJit.EdiReceive.Services /// /// 解析报文 + /// 一、导入记录表 + /// 1. 从客户网站导出EXCEL格式的订单列表 + /// 2. 校验 本次导入的最小HostSN必须<= 上次导入的最大HostSN + 1 (上次是10, 本次可以是 9 10 11,不能是12) + /// 3. 根据VIN和HostSN,扣除重复导入的记录 + /// 4. 断号提醒:导入Excel时,如果系统中的流水号不能顺序连接,需要给出提醒,是否继续导入,如果选择继续导入,仍可以导入到系统中 + /// 5. 最后导入到本系统中 impRecLst + /// + /// 二、插入M100 + /// 1. 根据车型代码中的前两位(HS),过滤属于派格的订单;只针对派格的订单进行报文解析 + /// 2. 根据VIN判断是否重复报文,将重复报文放到“重复报文表” + /// 3. 通过车型描述中的颜色(条件一)和规格说明(条件二)两个字段能够定位到该底盘对应哪个总成组(4个总成一组)。如果匹配将订单和总成组进行绑定;如果不匹配将订单放入未知总成 + /// 4. 插入M100 (更新派格车型、 生产线) + /// 5. 插入WaitPrint /// - /// + /// 导入Excel内容 + /// 校验不通过时,是否强制执行通过 public async Task ParseEdi(List input, bool forceExecute = false) { ObjectResultDto ret = new ObjectResultDto(); - //取本次导入的最小HostSN - int minHostSN = input.Min(itm => itm.HostSN); - //上次导入的最大HostSN - int lastHostSN = await _lastImportHostSNDomainService.GetLastImportHostSN(); - string betweenBreakNumMsg = ""; - if (minHostSN <= lastHostSN + 1) - { - } - else - { - if (forceExecute == false) - { - //两次导入断号提醒 - betweenBreakNumMsg = $"两次导入断号提醒:本次导入的最小流水号是:{minHostSN},上次导入的最大流水号是:{lastHostSN}"; - } - } + //扣除重复导入的订单 List notRepeatOrder = await GetNotRepeatOrder(input); - - #region 断号提醒 - string breakNumMsg = ""; - notRepeatOrder = notRepeatOrder.OrderBy(itm => itm.HostSN).ToList(); - for (int curIdx = 1; curIdx < notRepeatOrder.Count; curIdx++) + if (notRepeatOrder.Count == 0) { - int curVal = notRepeatOrder[curIdx].HostSN; - int priorIdx = curIdx - 1; - int priorVal = notRepeatOrder[priorIdx].HostSN; - if (curVal - priorVal != 1) - { - breakNumMsg += $"流水号{priorVal}和{curVal}之间存在断号\r\n"; - } + ret.Status = true; + ret.Message = "根据Vin和HostSN,排除在数据库中重复的Excel订单后,已经没有不重复的订单!"; + return ret; } + #region 断号提醒 + //校验两次导入之间是否断号 + string betweenBreakNumMsg = await CheckBetweenBreakNum(input); + //校验本次导入数据是否断号 + string breakNumMsg = CheckBreakNum(ref notRepeatOrder); if (betweenBreakNumMsg.HasValue() || breakNumMsg.HasValue()) { if (forceExecute == false) @@ -179,48 +182,25 @@ namespace WY.NewJit.EdiReceive.Services return ret; } } - #endregion - //批量插入 导入记录 - await _importRecordRepository.InsertManyAsync(notRepeatOrder); + #endregion //初始化缓存 _hqCacheManagerDomainService.InitLoadCache(); - //过滤掉其它订单,只取派格订单 - var paigeOrderLst = notRepeatOrder.Where(itm => itm.VehicleModelCode.Substring(0, 2) == _vehicleModelPrefix).OrderBy(itm => itm.HostSN).ToList(); + //批量插入 导入记录 + await _importRecordRepository.InsertManyAsync(notRepeatOrder); + + //过滤掉其它厂家的订单,只取派格订单 + var paigeOrderLst = notRepeatOrder.Where(itm => itm.VehicleModelCode.Substring(0, 2) == _vehicleModelPrefix).OrderBy(itm => itm.HostSN).ToList(); foreach (ImportRecord orderItem in paigeOrderLst) { - #region 构建M100实体 - BillM100 m100Obj = new BillM100(GuidGenerator.Create()); - m100Obj.MessageFileReceiveID = orderItem.Id; - m100Obj.SerialNum = ServerHelper.VinToSN(orderItem.Vin); - m100Obj.SerialNumStr = ServerHelper.ToSerialNumStr(orderItem.OnlineTime, orderItem.HostSN); - m100Obj.HostSN = orderItem.HostSN; - m100Obj.HostSN2 = orderItem.HostSN; //流水号 - m100Obj.KNR = orderItem.VehicleBodyCode; - m100Obj.VIN = orderItem.Vin; - m100Obj.AssemblyID = null; - m100Obj.OnlineTime = orderItem.OnlineTime; - m100Obj.VehicleModelCode = orderItem.VehicleBodyCode; - m100Obj.ProductLine = ""; - m100Obj.Version = ""; - m100Obj.ReceiveTime = ServerHelper.CurrentDateTime; - m100Obj.BillStatus = BillStatusEnum.NotMatch; - m100Obj.Description = ""; - //m100Obj.OperationType = operationType; - //m100Obj.Operator = @operator; - //m100Obj.OperationTime = operationTime; - m100Obj.CanNotPrint = false; - m100Obj.NeedReplenishPrint = 0; - m100Obj.IsPartSwitch = false; - #endregion - + //构建M100实体 + BillM100 m100Obj = BuildM100Entity(orderItem); + //更新车型、产线 UpdateProductLine(m100Obj); - string snStr = ServerHelper.ToSerialNumStr(m100Obj.OnlineTime, m100Obj.HostSN); - m100Obj.SetSerialNumStr(snStr); //重复报文 - bool isRepeat = _billM100Repository.Any(itm => itm.HostSN == orderItem.HostSN && itm.VIN == orderItem.Vin); + bool isRepeat = await _billM100Repository.AnyAsync(itm => itm.HostSN == orderItem.HostSN && itm.VIN == orderItem.Vin); if (isRepeat == true) { #region 重复报文 @@ -233,13 +213,12 @@ namespace WY.NewJit.EdiReceive.Services //绑定总成分组 string colorExplain = orderItem.VehicleModelDesc.Trim().Right(7); - Group_Assembly groupAssemblyObj = HQ_CacheManagerDomainService._groupAssemblyList.FirstOrDefault(itm => itm.SpecExplain == orderItem.SpecDesc && itm.ColorExplain == colorExplain); if (groupAssemblyObj != null) { #region 插入整车总成 Guid vehicleAssemblyId = GuidGenerator.Create(); - AssemblyCfgVehicle vehicleAssemblyCfgObj = new AssemblyCfgVehicle(vehicleAssemblyId, null, "", null, true); + AssemblyCfgVehicle vehicleAssemblyCfgObj = new AssemblyCfgVehicle(vehicleAssemblyId, null, m100Obj.VehicleModelCode, null, true); foreach (OnlyAssemblyInfo assemblyItem in groupAssemblyObj.AssemblyDetails) //插入子表 { vehicleAssemblyCfgObj.AddChildObj(GuidGenerator.Create(), assemblyItem.Id); @@ -253,6 +232,7 @@ namespace WY.NewJit.EdiReceive.Services //插入M100、未打印表 m100Obj.SetAssemblyID(vehicleAssemblyResu.Id); + m100Obj.SetBillStatus(BillStatusEnum.Match); var insM100Ret = await _hqM100DomainServie.InsertM100(m100Obj, true); } else @@ -270,27 +250,91 @@ namespace WY.NewJit.EdiReceive.Services ret.Status = (succObj1 != null && succObj2 != null); } - } + } //foreach - /* - 一、导入记录表 - 1. 从客户网站导出EXCEL格式的订单列表 - 2. 校验 本次导入的最小HostSN必须<= 上次导入的最大HostSN + 1 (上次是10, 本次可以是 9 10 11,不能是12) - 3. 根据VIN和HostSN,扣除重复导入的记录 - 4. 断号提醒:导入Excel时,如果系统中的流水号不能顺序连接,需要给出提醒,是否继续导入,如果选择继续导入,仍可以导入到系统中 - 5. 最后导入到本系统中 impRecLst - - 二、插入M100 - 1. 根据车型代码中的前两位(HS),过滤属于派格的订单;只针对派格的订单进行报文解析 - 2. 根据VIN判断是否重复报文,将重复报文放到“重复报文表” - 3. 通过车型描述中的颜色(条件一)和规格说明(条件二)两个字段能够定位到该底盘对应哪个总成组(4个总成一组)。如果匹配将订单和总成组进行绑定;如果不匹配将订单放入未知总成 - 4. 插入M100 (更新派格车型、 生产线) - 5. 插入WaitPrint - */ + //更新本次导入的最大HostSN + int curMaxHostSN = input.Max(itm => itm.HostSN); + await _lastImportHostSNDomainService.SetCurrentImportMaxHostSN(curMaxHostSN); ret.Status = true; return ret; } + /// + /// 上次导入和本次导入之间的流水号是否连续 + /// + /// + /// + private async Task CheckBetweenBreakNum(List input) + { + string ret = ""; + //取本次导入的最小HostSN + int curMinHostSN = input.Min(itm => itm.HostSN); + //上次导入的最大HostSN + int priorMaxHostSN = await _lastImportHostSNDomainService.GetLastImportMaxHostSN(); + if (priorMaxHostSN > 0) //第一次导入时(priorMaxHostSN = 0),不需要校验两次导入之间的断号 + { + if (curMinHostSN <= priorMaxHostSN + 1) + { + } + else + { + //两次导入断号提醒 + ret = $"两次导入断号提醒:本次导入的最小流水号是:{curMinHostSN},上次导入的最大流水号是:{priorMaxHostSN},两者不连续\r\n"; + } + } + + return ret; + } + + private BillM100 BuildM100Entity(ImportRecord orderItem) + { + BillM100 m100Obj = new BillM100(GuidGenerator.Create()); + m100Obj.MessageFileReceiveID = orderItem.Id; + m100Obj.SerialNum = ServerHelper.VinToSN(orderItem.Vin); + m100Obj.SerialNumStr = ServerHelper.ToSerialNumStr(orderItem.OnlineTime, orderItem.HostSN); + m100Obj.HostSN = orderItem.HostSN; + m100Obj.HostSN2 = orderItem.HostSN; //流水号 + m100Obj.KNR = orderItem.VehicleBodyCode; + m100Obj.VIN = orderItem.Vin; + m100Obj.AssemblyID = null; + m100Obj.OnlineTime = orderItem.OnlineTime; + m100Obj.VehicleModelCode = orderItem.VehicleModelCode.Substring(0, 2); + m100Obj.ProductLine = null; + m100Obj.Version = ""; + m100Obj.ReceiveTime = ServerHelper.CurrentDateTime; + m100Obj.BillStatus = BillStatusEnum.NotMatch; + m100Obj.Description = ""; + //m100Obj.OperationType = operationType; + //m100Obj.Operator = @operator; + //m100Obj.OperationTime = operationTime; + m100Obj.CanNotPrint = false; + m100Obj.NeedReplenishPrint = 0; + m100Obj.IsPartSwitch = false; + return m100Obj; + } + + /// + /// 校验本次导入数据断号 + /// + /// + /// + private static string CheckBreakNum(ref List notRepeatOrder) + { + StringBuilder sb = new StringBuilder(); + notRepeatOrder = notRepeatOrder.OrderBy(itm => itm.HostSN).ToList(); + for (int curIdx = 1; curIdx < notRepeatOrder.Count; curIdx++) + { + int curVal = notRepeatOrder[curIdx].HostSN; + int priorIdx = curIdx - 1; + int priorVal = notRepeatOrder[priorIdx].HostSN; + if (curVal - priorVal != 1) + { + sb.AppendLine($"流水号{priorVal}和{curVal}之间存在断号"); + } + } + return sb.ToString(); + } + /// /// 根据流水号、VIN 扣除重复导入的订单 /// @@ -299,11 +343,8 @@ namespace WY.NewJit.EdiReceive.Services private async Task> GetNotRepeatOrder(List input) { List notRepeatLst = new List(); + List importHistoryLst = await _importRecordRepository.GetPagedListAsync(0, 10000, "HostSN desc"); - List importHistoryLst = await _importRecordRepository.AsQueryable() - .OrderBy(itm => itm.HostSN) - .TakeLast(10000) - .ToListAsync(); foreach (ImportRecord item in input) { bool hasData = importHistoryLst.Any(itm => itm.HostSN == item.HostSN && itm.Vin == item.Vin); @@ -326,7 +367,7 @@ namespace WY.NewJit.EdiReceive.Services { string ediVehicleModel = bill.VehicleModelCode; //报文车型 //车型转换:3H 转 CC - var obj1 = _msgToPaiGeVehicleModelList.FirstOrDefault(itm => itm.DicItemCode == ediVehicleModel); + var obj1 = HQ_CacheManagerDomainService._msgToPaiGeVehicleModelList.FirstOrDefault(itm => itm.DicItemCode == ediVehicleModel); if (obj1 != null) { string paigeVehicleModel = obj1.DicItemName; // CC @@ -336,7 +377,7 @@ namespace WY.NewJit.EdiReceive.Services } bill.SetVehicleModelCode(paigeVehicleModel); //根据车型取对应生产线 - var obj2 = _m100VehicleModelProductLineList.FirstOrDefault(itm => itm.DicItemCode == paigeVehicleModel); + var obj2 = HQ_CacheManagerDomainService._m100VehicleModelProductLineList.FirstOrDefault(itm => itm.DicItemCode == paigeVehicleModel); if (obj2 != null) { string productLine = obj2.DicItemName; @@ -355,7 +396,7 @@ namespace WY.NewJit.EdiReceive.Services } } - private RepeatM100 InsertM100RepeatBill(ImportRecord impordRec, BillM100 m100Bill) //, int? maxSerialNum + private async Task InsertM100RepeatBill(ImportRecord impordRec, BillM100 m100Bill) { RepeatM100 ret = null; int newSN = ServerHelper.VinToSN(m100Bill.VIN); @@ -381,7 +422,7 @@ namespace WY.NewJit.EdiReceive.Services repeatBill.AddChildObj(GuidGenerator.Create(), m100Part.PartCode, m100Part.PartNum, m100Part.Description); } //插入重复单据 - ret = _repeatM100Repository.InsertAsync(repeatBill, true).GetAwaiter().GetResult(); + ret = await _repeatM100Repository.InsertAsync(repeatBill, true); return ret; } diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/EdiReceive/Services/HQ_CacheManagerDomainService.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/EdiReceive/Services/HQ_CacheManagerDomainService.cs index fb14158..7314114 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/EdiReceive/Services/HQ_CacheManagerDomainService.cs +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/EdiReceive/Services/HQ_CacheManagerDomainService.cs @@ -50,12 +50,6 @@ namespace WY.NewJit.EdiReceive.Services #endregion #region 缓存 - public static List _erpAssemblyMainList = new List(); - - /// - /// 分组VS总成关系 - /// - //public static List _group2assemblyList = new List(); /// /// 分组对应多个总成 清单- @@ -192,22 +186,18 @@ namespace WY.NewJit.EdiReceive.Services /// public void DoInitLoadCache() { - //取ERP总成主表 - string erpMainSql = "select Id, VehicleModel from FisAssemblyCfgErp where NewVersionId is null order by ErpAssemblyVersion, CreationTime desc"; - _erpAssemblyMainList = _newJitDapperRepository.GetListBySql(erpMainSql, true); - //取ERP总成的零件 string group2assemblySql = @" - select g.Id as GroupId, g.GroupCode, g.VehicleModel, e.Id as ErpAssemblyId, e.ErpAssemblyCode, + select g.Id as GroupId, g.GroupCode, g.VehicleModel, e.Id as ErpAssemblyId, e.ErpAssemblyCode, e.ErpAssemblyName, g.SpecExplain, g.ColorExplain from FisAssemblyCfgGroup g join FisAssemblyCfgErp e on g.Id = e.GroupId - where IsDeleted = 0 and g.IsDisable = 0 + where g.IsDisable = 0 and g.IsDeleted = 0 order by g.CreationTime desc "; var group2assemblyList = _newJitDapperRepository.GetListBySql(group2assemblySql, true); //转换成分组、总成 两层结构 - List _groupAssemblyList = group2assemblyList.GroupBy(itm => itm.GroupId).Select(itm => new Group_Assembly + _groupAssemblyList = group2assemblyList.GroupBy(itm => itm.GroupId).Select(itm => new Group_Assembly { Id = itm.Key, GroupCode = itm.ElementAt(0).GroupCode, diff --git a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/EdiReceive/Services/LastImportHostSNDomainService.cs b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/EdiReceive/Services/LastImportHostSNDomainService.cs index 17c519c..078379d 100644 --- a/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/EdiReceive/Services/LastImportHostSNDomainService.cs +++ b/src/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/EdiReceive/Services/LastImportHostSNDomainService.cs @@ -55,7 +55,12 @@ namespace WY.NewJit.EdiReceive.Services _lastImportHostSNRepository = lastImportHostSNRepository; } - public async Task GetLastImportHostSN() + /// + /// 假设:产线之间的流水号都是唯一的 + /// + /// + /// + public async Task GetLastImportMaxHostSN() { var lst = await _lastImportHostSNRepository.GetListAsync(); if (lst.Count > 0) @@ -64,8 +69,32 @@ namespace WY.NewJit.EdiReceive.Services } else { - int maxSN = await _lastImportHostSNRepository.MaxAsync(itm => itm.HostSN); - return maxSN; + bool hasData = await _importRecordRepository.AnyAsync(); + if (hasData) + { + int maxSN = await _importRecordRepository.MaxAsync(itm => itm.HostSN); + return maxSN; + } + else + { + return 0; + } + } + } + + public async Task SetCurrentImportMaxHostSN(int maxHostSN) + { + var obj = await _lastImportHostSNRepository.FirstOrDefaultAsync(); + if (obj != null) + { + obj.HostSN = maxHostSN; + await _lastImportHostSNRepository.UpdateAsync(obj, true); + } + else + { + LastImportHostSN newObj = new LastImportHostSN(GuidGenerator.Create()); + newObj.HostSN = maxHostSN; + var insRet = await _lastImportHostSNRepository.InsertAsync(obj); } }