From 55c68df95edc067cefe3d74120d28daebdd00649 Mon Sep 17 00:00:00 2001 From: me Date: Fri, 1 Aug 2025 17:41:45 +0800 Subject: [PATCH] =?UTF-8?q?M110=E6=8A=A5=E6=96=87=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=EF=BC=8C=20=E5=8C=85=E5=90=ABM110=E6=97=A5=E5=B8=B8=E6=89=93?= =?UTF-8?q?=E5=8D=B0=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MsgCheck/BillM100s/BillM100AppService.cs | 175 ++++- .../WY.NewJit.Application.xml | 2 +- .../MsgBaseData/LogTypeEnum.cs | 8 +- .../MsgCheck/Entitys/BillM100.cs | 4 + .../Services/M110CheckDomainService.cs | 704 ++++++++++++++++++ .../Messages/MsgTransmissionService.cs | 191 ++++- 6 files changed, 1061 insertions(+), 23 deletions(-) create mode 100644 Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/MsgCheck/Services/M110CheckDomainService.cs diff --git a/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/MsgCheck/BillM100s/BillM100AppService.cs b/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/MsgCheck/BillM100s/BillM100AppService.cs index 17c828c..8971068 100644 --- a/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/MsgCheck/BillM100s/BillM100AppService.cs +++ b/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/MsgCheck/BillM100s/BillM100AppService.cs @@ -42,6 +42,8 @@ namespace WY.NewJit.MsgCheck /// private readonly IRepository _billM100Repository; + private readonly IRepository _billM110_Repository; + private readonly IRepository _billM100PartRepository; private readonly IRepository _printTemplateConfigurationRepository; @@ -183,11 +185,10 @@ namespace WY.NewJit.MsgCheck IRepository tsSortDetailRepository, IRepository tbBillHisRepository, IRepository tsSortDetailHisRepository, - IRepository printTemplateConfigurationRepository, + IRepository printTemplateConfigurationRepository, IRepository zHBPrintStatusRepository, - IRepository dicItemRepository - - + IRepository dicItemRepository, + IRepository billM110_Repository ) { _billM100Repository = BillM100Repository; @@ -216,6 +217,7 @@ namespace WY.NewJit.MsgCheck _zHBPrintStatusRepository = zHBPrintStatusRepository; _topBoxPositionNumPrefix = _configuration["ConfigDic:TopBoxPositionNumPrefix"]; _dicItemRepository = dicItemRepository; + _billM110_Repository = billM110_Repository; } #endregion @@ -237,7 +239,7 @@ with d as ) , r as ( - select rr.KNR, aa.AssemblyName, rr.OnlineTime from FisBillR100 rr left join FisAssemblyCfgVehicle aa on rr.AssemblyID = aa.Id + select rr.KNR, '' as AssemblyName, rr.OnlineTime from FisBillR100 rr left join FisAssemblyCfgVehicle aa on rr.AssemblyID = aa.Id ) select * from ( @@ -257,7 +259,7 @@ with d as ) , r as ( - select rr.KNR, aa.AssemblyName, rr.OnlineTime from FisBillR100 rr left join FisAssemblyCfgVehicle aa on rr.AssemblyID = aa.Id + select rr.KNR, '' as AssemblyName, rr.OnlineTime from FisBillR100 rr left join FisAssemblyCfgVehicle aa on rr.AssemblyID = aa.Id ) select * from ( @@ -270,11 +272,11 @@ select * from where 1=1 {0} ) t where row_number between {1} and {2} order by SerialNumStr "; - if (input.IsQueryArchive == true) - { - sqlCnt = sqlCnt.Replace("FisBillM100", "FisBillM100_His"); - sql = sql.Replace("FisBillM100", "FisBillM100_His"); - } + //if (input.IsQueryArchive == true) + //{ + // sqlCnt = sqlCnt.Replace("FisBillM100", "FisBillM100_His"); + // sql = sql.Replace("FisBillM100", "FisBillM100_His"); + //} string where = ""; @@ -3009,6 +3011,143 @@ select min(SerialNumStr) from FisBillM100 a left join d on a.VIN=d.VIN } } + + [HttpGet] + [UnitOfWork(false)] + [Route("list2")] + public virtual async Task GetList2Async(QueryBillM100Dto input) + { + _logger.LogDebug(_errorMessagePrefix + "GetList2Async 进入"); + M100_M110_Result ret = new M100_M110_Result(); + try + { + var query = await _billM100Repository.GetQueryableAsync(); + var includeQry = query.Include(itm => itm.BillM100Parts); + var m100Query = includeQry.Where(itm => itm.IsReceiveM110 == false || itm.IsReceiveM110 == null); + + if (input.SerialNumBegin != null) + { + m100Query = m100Query.Where(itm => itm.SerialNum >= input.SerialNumBegin); + } + if (input.SerialNumEnd != null) + { + m100Query = m100Query.Where(itm => itm.SerialNum <= input.SerialNumBegin); + } + if (input.HostSNBegin != null) + { + m100Query = m100Query.Where(itm => itm.HostSN >= input.HostSNBegin); + } + if (input.HostSNEnd != null) + { + m100Query = m100Query.Where(itm => itm.HostSN <= input.HostSNEnd); + } + if (!string.IsNullOrEmpty(input.KNRBegin)) + { + m100Query = m100Query.Where(itm => itm.KNR.CompareTo(input.KNRBegin) >= 0); + } + if (!string.IsNullOrEmpty(input.KNREnd)) + { + m100Query = m100Query.Where(itm => itm.KNR.CompareTo(input.KNREnd) <= 0); + } + if (!string.IsNullOrEmpty(input.VINBegin)) + { + m100Query = m100Query.Where(itm => itm.VIN.CompareTo(input.VINBegin) >= 0); + } + if (!string.IsNullOrEmpty(input.VINEnd)) + { + m100Query = m100Query.Where(itm => itm.VIN.CompareTo(input.VINEnd) <= 0); + } + if (input.AssemblyID != null) + { + m100Query = m100Query.Where(itm => itm.AssemblyID != null); + } + if (input.OnlineTimeBegin != null) + { + m100Query = m100Query.Where(itm => itm.OnlineTime >= input.OnlineTimeBegin); + } + if (input.OnlineTimeEnd != null) + { + m100Query = m100Query.Where(itm => itm.OnlineTime <= input.OnlineTimeEnd); + } + if (input.VehicleModelCode != null) + { + m100Query = m100Query.Where(itm => itm.VehicleModelCode == input.VehicleModelCode); + } + if (input.ProductLine != null) + { + m100Query = m100Query.Where(itm => itm.ProductLine == input.ProductLine); + } + if (input.Version != null) + { + m100Query = m100Query.Where(itm => itm.Version == input.Version); + } + if (input.ReceiveTimeBegin != null) + { + m100Query = m100Query.Where(itm => itm.ReceiveTime >= input.ReceiveTimeBegin); + } + if (input.ReceiveTimeEnd != null) + { + m100Query = m100Query.Where(itm => itm.ReceiveTime <= input.ReceiveTimeEnd); + } + //if (input.IsBillMaintenance == true) //M100单据信息维护模块使用 + //{ + // where += " and b.Operator is not null"; + //} + if (input.CanNotPrint == true) + { + m100Query = m100Query.Where(itm => itm.CanNotPrint == true); + } + else if (input.CanNotPrint == false) + { + m100Query = m100Query.Where(itm => itm.CanNotPrint == false || itm.CanNotPrint == null); + } + + if (input.ZHBBillStatus != null && input.ZHBBillStatus != ZHBBillStatusEnum.None) + { + if (input.ZHBBillStatus == ZHBBillStatusEnum.Print) //柱护板已打印 + { + m100Query = m100Query.Where(itm => itm.PrintBillNum != "" && itm.PrintBillNum != null); + } + else if (input.ZHBBillStatus == ZHBBillStatusEnum.NotPrint) //柱护板未打印 + { + m100Query = m100Query.Where(itm => itm.PrintBillNum == "" || itm.PrintBillNum == null); + } + } + else if (input.BillStatus != null && input.BillStatus != BillStatusEnum.None) + { + m100Query = m100Query.Where(itm => itm.BillStatus == input.BillStatus); + } + else + { + //m100Query = m100Query.Where(itm => itm.BillStatus == BillStatusEnum.Match || itm.BillStatus == BillStatusEnum.Publish); //单据状态是已匹配、已打印 + } + + if (input.IsNeedReplenishPrint == true) //只显示需要补打的记录 + { + m100Query = m100Query.Where(itm => itm.NeedReplenishPrint == 1); + } + //M100 + var m100Lst = m100Query.OrderBy(itm => itm.SerialNumStr).Skip(input.SkipCount).Take(input.MaxResultCount).OrderByDescending(itm => itm.SerialNumStr).ToList(); + ret.M100_TotalCount = await m100Query.CountAsync(); + ret.BillM100s = m100Lst; + //M110 + string serialNumStr = await _billM110_Repository.Where(itm => itm.ProductLine == input.ProductLine).MaxAsync(itm => itm.SerialNumStr); + var m110_Lst = await _billM110_Repository.GetListAsync(itm => itm.SerialNumStr == serialNumStr, true); + ret.Bill_M110s = m110_Lst; + + return ret; + } + catch (Exception ex) + { + string errMsg = _errorMessagePrefix + "GetList2Async 执行出错:" + ex.Message; + _logger.LogError(errMsg); + return ret; + } + } + + + + /// /// 按主键获取唯一实体 /// @@ -5085,4 +5224,18 @@ select min(SerialNumStr) from FisBillM100 a left join d on a.VIN=d.VIN //} } + public class M100_M110_Result + { + public List BillM100s { get; set; } + public List Bill_M110s { get; set; } + + public int M100_TotalCount { get; set; } + + public M100_M110_Result() + { + BillM100s = new List(); + Bill_M110s = new List(); + } + } + } diff --git a/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/WY.NewJit.Application.xml b/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/WY.NewJit.Application.xml index f216a6a..0af46ef 100644 --- a/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/WY.NewJit.Application.xml +++ b/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Application/WY.NewJit.Application.xml @@ -988,7 +988,7 @@ 柱护板缓存列表(打印柱护板时用到) - + 构造函数 diff --git a/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain.Shared/MsgBaseData/LogTypeEnum.cs b/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain.Shared/MsgBaseData/LogTypeEnum.cs index 61308cd..a133c87 100644 --- a/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain.Shared/MsgBaseData/LogTypeEnum.cs +++ b/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain.Shared/MsgBaseData/LogTypeEnum.cs @@ -25,9 +25,13 @@ namespace WY.NewJit.MsgBaseData /// 总成接口 /// [Description("总成接口")] - AssemblyInterface = 3 - + AssemblyInterface = 3, + /// + /// M100 + /// + [Description("M100")] + M110 = 4, } public enum LogStatusEnum diff --git a/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/MsgCheck/Entitys/BillM100.cs b/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/MsgCheck/Entitys/BillM100.cs index 12a1bd2..d73462d 100644 --- a/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/MsgCheck/Entitys/BillM100.cs +++ b/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/MsgCheck/Entitys/BillM100.cs @@ -134,6 +134,10 @@ namespace WY.NewJit.MsgCheck /// public virtual bool? IsPartSwitch { get; set; } + /// + /// 是否接收到M110 + /// + public virtual bool? IsReceiveM110 { get; set; } public BillM100() { diff --git a/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/MsgCheck/Services/M110CheckDomainService.cs b/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/MsgCheck/Services/M110CheckDomainService.cs new file mode 100644 index 0000000..9855cca --- /dev/null +++ b/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Domain/MsgCheck/Services/M110CheckDomainService.cs @@ -0,0 +1,704 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json.Linq; +using NPOI.SS.Formula.Functions; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Linq.Dynamic.Core; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.Domain.Services; +using Volo.Abp.ObjectMapping; +using Volo.Abp.Uow; +using WY.NewJit.Common; +using WY.NewJit.IRepositories; +using WY.NewJit.MsgBaseData; +using WY.NewJit.MsgCheck; +using WY.NewJit.MsgConversion; +using WY.NewJit.MsgTransmission; + + +namespace WY.NewJit.MsgCheck +{ + /// + /// 报文校验领域服务实现 + /// + public class M110CheckDomainService : DomainService + { + + /// + /// M110单据 + /// + private readonly IRepository _billM110Repository; + + /// + /// 日志 + /// + private ILogger _logger; + + /// + /// 日志提醒 + /// + private readonly LogRemindDomainService _logRemindDomainService; + + /// + /// 对象映射 + /// + private readonly IObjectMapper _objectMapper; + + /// + /// 重复M110 + /// + private readonly IRepository _repeatM110Repository; + + /// + /// 排除零件配置 + /// + private readonly IRepository _excludePartCfgRepository; + + /// + /// 未知总成维护 + /// + private readonly IRepository _unknownAssemblyRepository; + + /// + /// 配置文件 + /// + private readonly Microsoft.Extensions.Configuration.IConfiguration _configuration; + + /// + /// Dapper仓储 + /// + private readonly INewJitDapperRepository _newJitDapperRepository; + + /// + /// 整车总成配置仓库 + /// + private readonly IRepository _assemblyCfgVehicleRepository; + + /// + /// 零件配置 + /// + private readonly IRepository _partCfgRepository; + + + /// + /// 错误信息前缀 + /// + private string _errorMessagePrefix + { + get + { + return System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "."; + } + } + + int? _hostSN = 0; + /// + /// 单据号,写日志时用(R100时是KNR,M110是时VIN) + /// + private string _billNumber = ""; + string _fileName = ""; + + private int _parseAssemblyCycleCount = 0; + + /// + /// 解析Erp总成时的循环数量 + /// + public int ParseAssemblyCycleCount + { + get + { + if (_parseAssemblyCycleCount == 0) + { + _parseAssemblyCycleCount = _configuration["ConfigDic:ParseAssemblyCycleCount"].TryToInt() ?? 4; + } + return _parseAssemblyCycleCount; + + } + } + + /// + /// 整车总成Id列表 + /// + static List _vehicleAssemblyIdList = new List(); + + /// + /// 整车vs零件列表 + /// + //static List _vehicle2partList = new List(); + + static Dictionary> _vehicle2partDict + = new Dictionary>(); + + /// + /// Erp总成Id列表 + /// + static List _erpAssemblyMainList = new List(); + + /// + /// Erp总成vs零件列表 + /// + static List _erp2partList = new List(); + + /// + /// 结算件切换列表 + /// + static List _partSwitchList = new List(); + + /// + /// 切换目标零件编码 + /// + static List _switchTargetPartCodeList = new List(); + + + public M110CheckDomainService() + { } + + /// + /// 构造函数 + /// + public M110CheckDomainService( + IRepository billM110Repository, + ILogger logger, + LogRemindDomainService logRemindDomainService, + IObjectMapper objectMapper, + IRepository repeatM110Repository, + IRepository excludePartCfgRepository, + IRepository unknownAssemblyRepository, + Microsoft.Extensions.Configuration.IConfiguration configuration, + INewJitDapperRepository newJitDapperRepository, + IRepository assemblyCfgVehicleRepository, + IRepository partCfgRepository + ) + { + _billM110Repository = billM110Repository; + _logger = logger; + _logRemindDomainService = logRemindDomainService; + _objectMapper = objectMapper; + _repeatM110Repository = repeatM110Repository; + _excludePartCfgRepository = excludePartCfgRepository; + _unknownAssemblyRepository = unknownAssemblyRepository; + _configuration = configuration; + _newJitDapperRepository = newJitDapperRepository; + _assemblyCfgVehicleRepository = assemblyCfgVehicleRepository; + _partCfgRepository = partCfgRepository; + } + + #region 公共方法 + + public virtual void InitPub(List vehicleAssemblyIdList, List vehicle2partList, List erpAssemblyMainList, List erp2partList, List partSwitchList) + { + _vehicleAssemblyIdList = vehicleAssemblyIdList; + //_vehicle2partList = vehicle2partList; + _vehicle2partDict = vehicle2partList.GroupBy(p => p.VehicleAssemblyId).ToDictionary(p => p.Key, p => p.ToList()); + _erpAssemblyMainList = erpAssemblyMainList; + _erp2partList = erp2partList; + _partSwitchList = partSwitchList; + _switchTargetPartCodeList = partSwitchList.Select(itm => itm.TargetPartCode).ToList(); //切换目标零件编码,判断单据是否存在切换零件时使用 + } + + /// + /// M110报文解析-正常入口 + /// + /// + /// + /// + /// + public ObjectResultDto DoCheckM110Bill(MessageReceive msgReceiveObj, BillM110 m110Bill) + { + ObjectResultDto ret = new ObjectResultDto(false, null); + _hostSN = m110Bill.HostSN; + _billNumber = m110Bill.VIN; + _fileName = msgReceiveObj.MessageFileName; + try + { + #region 更新不可打印标志 + List canNotPrintLst = _billM110Repository.Where(itm => + itm.ProductLine == m110Bill.ProductLine + && itm.HostSN == m110Bill.HostSN + && (itm.CanNotPrint == null || itm.CanNotPrint == false)).ToList(); + foreach (BillM110 canNotPrintObj in canNotPrintLst) + { + canNotPrintObj.CanNotPrint = true; + _billM110Repository.UpdateAsync(canNotPrintObj, true).GetAwaiter().GetResult(); + } + #endregion + + + bool isMatch = DoMatchAssembly(m110Bill); //仅仅插入或更新M110主子表 + if (isMatch) + { + #region 判断是否断号 + //断号判断规则:大众顺序号生成规则是1至1999的重复循环,重复循环到1时判断之前最近的相同车型的VIN和当前VIN是否连续,如果不连续则表示断号 + //断号判断:大众顺序号按生产线分类判断;VIN按车型分类判断 + string curProductLine = m110Bill.ProductLine; + string curSerialNumStr = m110Bill.SerialNumStr; //排序依据 + int curHostSN = m110Bill.HostSN ?? 0; + string curVehicleModel = m110Bill.VehicleModelCode; + int curVinNum = m110Bill.SerialNum ?? 0; //VIN后六位 + //取当前生产线最近一条SerialNumStr + string priorSerialNumStr = _billM110Repository.Where(itm => + itm.ProductLine == curProductLine + && itm.SerialNumStr.CompareTo(curSerialNumStr) < 0 + ).Max(itm => itm.SerialNumStr); + if (priorSerialNumStr != null) + { + //取当前生产线最近一条 + int priorHostSN = _billM110Repository.FirstOrDefault(itm => itm.ProductLine == curProductLine && itm.SerialNumStr == priorSerialNumStr).HostSN ?? 0; + if (curHostSN == priorHostSN + 1) + { + //不断号 + } + else + { + //取当前生产线、相同车型、最近一条SerialNumStr + string priorSerialNumStr2 = _billM110Repository.Where(itm => + itm.ProductLine == curProductLine + && itm.VehicleModelCode == curVehicleModel + && itm.SerialNumStr.CompareTo(curSerialNumStr) < 0 + ).Max(itm => itm.SerialNumStr); + if (priorSerialNumStr2 != null) + { + int priorVinNum = _billM110Repository.FirstOrDefault(itm => itm.SerialNumStr == priorSerialNumStr2).SerialNum ?? 0; + if (curVinNum == priorVinNum + 1) + { + //不断号 + } + else + { + //断号提醒 + string errorMsg = $"{curProductLine}生产线M110报文出现断号,当前VIN:{curVinNum}:{curHostSN},上一VIN:{priorVinNum}:{priorHostSN}。可以操作M110单据信息维护模块进行补号!"; + _logger.LogError(errorMsg); + _logRemindDomainService.WriteLogRemind(_billNumber, errorMsg, LogTypeEnum.M110); + } + } + } + } + #endregion + + ret.Status = true; + } + return ret; + } + catch (Exception ex) + { + string errorMsg = "调用报文解析及校验方法DoCheckM110Bill出错:" + ex.Message; + _logRemindDomainService.WriteLogRemind(_billNumber, errorMsg, LogTypeEnum.M110); + _logger.LogError(errorMsg); + throw new Exception(errorMsg); + } + } + + public bool DoMatchAssembly(BillM110 m110Bill, bool isBillUpdate = false, bool isUnknowAssembly = false) + { + bool ret = false; + try + { + #region 更新单据表 + m110Bill.SetAssemblyID(Guid.Parse("00000000-0000-0000-0000-000000000000")); + m110Bill.SetBillStatus(BillStatusEnum.Match); + BillM110 succObj; + if (isBillUpdate == true) //未知总成模块-重新解析时修改R100单据(单据已经存在) + { + if (isUnknowAssembly) + { + succObj = _billM110Repository.UpdateAsync(m110Bill).GetAwaiter().GetResult(); + } + else + { + succObj = _billM110Repository.UpdateAsync(m110Bill, true).GetAwaiter().GetResult(); + } + } + else + { + succObj = _billM110Repository.InsertAsync(m110Bill, true).GetAwaiter().GetResult(); + } + + if (succObj == null) + { + throw new Exception("插入或更新M110整车总成ID返回结果为空InsertAsync!!"); + } + #endregion + + ret = true; + return ret; + } + catch (Exception ex) + { + throw new Exception(ex.Message); + } + + } + + #endregion + + #region 私有方法 + + public RepeatM110 InsertM110RepeatBill(MessageReceive msgReceiveObj, BillM110 m110Bill) //, int? maxSerialNum + { + RepeatM110 ret = null; + int newSN = ServerHelper.VinToSN(m110Bill.VIN); + RepeatM110 repeatBill = new RepeatM110( + GuidGenerator.Create(), + msgReceiveObj.Id, + newSN, //maxSerialNum, + m110Bill.HostSN, + m110Bill.KNR, + m110Bill.VIN, + null, + m110Bill.OnlineTime, + ServerHelper.CurrentDateTime, + m110Bill.VehicleModelCode, + m110Bill.ProductLine, + ((DateTime)m110Bill.OnlineTime).ToString("yyyyMM"), + BillStatusEnum.None + ); + + //零件子表赋值 + foreach (BillM110Part m110Part in m110Bill.BillM110Parts) + { + repeatBill.AddChildObj(GuidGenerator.Create(), m110Part.PartCode, m110Part.PartNum, m110Part.Description); + } + //插入重复单据 + ret = _repeatM110Repository.InsertAsync(repeatBill, true).GetAwaiter().GetResult(); + return ret; + } + + /// + /// 总成比较 + /// + /// + /// + /// + //private CompareAssemblyResult IsMatchAssembly(BillM110 m110Bill, bool isBillSaved = false) + //{ + // CompareAssemblyResult ret = new CompareAssemblyResult(); + // try + // { + // #region 先进行整车总成匹配 + // CompareVehicleAssemblyResult vehicleResult = CompareVehicleAssembly(m110Bill); + // if (vehicleResult.IsMatch == true) + // { + // ret.VehicleAssemblyResult = vehicleResult; + // ret.VehicleModel = m110Bill.VehicleModelCode; + // return ret; + // } + // #endregion + + // #region 再进行Erp总成匹配 + // if (ConfigDic.CurrentVersion == ConfigDicVersionOption.派格) + // { + // CompareErpAssemblyResult erpResult = CompareErpAssembly_PaiGe(m110Bill); + // if (erpResult.IsMatch == true) + // { + // ret.ErpAssemblyResult = erpResult; + // ret.VehicleModel = m110Bill.VehicleModelCode; + // return ret; + // } + // } + // else + // { + // //CompareErpAssemblyResult erpResult = CompareErpAssembly(m110Bill); + // //if (erpResult.IsMatch == true) + // //{ + // // ret.ErpAssemblyResult = erpResult; + // // ret.VehicleModel = m110Bill.VehicleModelCode; + // // return ret; + // //} + // } + // #endregion + + // #region 零件切换 + // if (ConfigDic.CurrentVersion == ConfigDicVersionOption.派格) + // { + // bool isSwitch = m110Bill.BillM110Parts.Any(itm => _switchTargetPartCodeList.Contains(itm.PartCode)); + // if (isSwitch == true) //存在零件切换情况 + // { + // List billPartCodeLst01 = m110Bill.BillM110Parts.Select(itm => itm.PartCode).ToList(); + // List partSwitchLstByBill = _partSwitchList.Where(itm => billPartCodeLst01.Contains(itm.TargetPartCode) == true).ToList(); //根据单据零件数据,从零件切换表中取要切换的零件 + + + // #region 先进行整车总成匹配 + // CompareVehicleAssemblyResult vehicleResult22 = CompareVehicleAssembly(m110Bill, partSwitchLstByBill); + // if (vehicleResult22.IsMatch == true) + // { + // ret.VehicleAssemblyResult = vehicleResult22; + // ret.VehicleModel = m110Bill.VehicleModelCode; + // ret.IsPartSwitch = true; + // return ret; + // } + // #endregion + + // #region 再进行Erp总成匹配 + // CompareErpAssemblyResult erpResult = CompareErpAssembly_PaiGe(m110Bill, partSwitchLstByBill); + // if (erpResult.IsMatch == true) + // { + // ret.ErpAssemblyResult = erpResult; + // ret.VehicleModel = m110Bill.VehicleModelCode; + // ret.IsPartSwitch = true; + // return ret; + // } + // #endregion + // } + // } + // #endregion + + // _logger.LogDebug(_errorMessagePrefix + "未匹配Erp总成:" + _billNumber); + + // return ret; + // } + // catch (Exception ex) + // { + // throw new Exception($"-MatchAssembly子方法-{_billNumber}-" + ex.Message); + // } + //} + + /// + /// 整车总成比较 + /// + /// + /// 整车总成ID + //private CompareVehicleAssemblyResult CompareVehicleAssembly(BillM110 m110Bill, List partSwitchListByBillFilter = null) + //{ + // try + // { + // CompareVehicleAssemblyResult ret = new CompareVehicleAssemblyResult(); + // //取切换源零件列表 + // List switchSourcePartCodeLst = new List(); + // if (partSwitchListByBillFilter != null) + // { + // switchSourcePartCodeLst = partSwitchListByBillFilter.Select(itm => itm.SourcePartCode).ToList(); + // } + + // #region 单据子零件转换成PartBase(排除柱护板) + // List billPartBaseLst = new List(); + // List tempPartLst = m110Bill.BillM110Parts; + // if (ConfigDic.CurrentVersion == ConfigDicVersionOption.派格) + // { + // tempPartLst = m110Bill.BillM110Parts.Where(itm => itm.PartType != "2").ToList(); //不等于柱护板 + // } + // foreach (BillM110Part obj in tempPartLst) + // { + // PartBase tempObj = new PartBase(obj.PartCode, obj.PartNum); + // billPartBaseLst.Add(tempObj); + // } + // #endregion + + // //遍历所有整车总成 + // var vaLst = _vehicleAssemblyIdList.Where(itm => itm.VehicleModel == m110Bill.VehicleModelCode || string.IsNullOrEmpty(itm.VehicleModel) == true).Select(itm => itm.Id); + // foreach (Guid vehicleId in vaLst) + // { + // if (!_vehicle2partDict.TryGetValue(vehicleId, out List vehicle2PartLst)) + // { + // continue; + // } + // //先判断数量是否一致 + // if (vehicle2PartLst.Count != billPartBaseLst.Count) continue; + + // #region 整车总成零件转换成PartBase + // List vehiclePartBaseLst = new List(); + // if (partSwitchListByBillFilter == null) + // { + // foreach (AssemblyCfgVehicle2Part v2pItm in vehicle2PartLst) + // { + // PartBase tempObj = new PartBase(v2pItm.PartCode, v2pItm.PartNum); + // vehiclePartBaseLst.Add(tempObj); + // } + // } + // else //执行零件切换 + // { + // bool isAssemblyContainsSwitch = vehicle2PartLst.Any(itm => switchSourcePartCodeLst.Contains(itm.PartCode)); + // if (isAssemblyContainsSwitch == false) //整车总成中不包含切换零件,直接跳过 + // { + // //continue; + // } + // else + // { + // foreach (AssemblyCfgVehicle2Part v2pItm in vehicle2PartLst) + // { + // PartSwitch psObj = partSwitchListByBillFilter.FirstOrDefault(itm => itm.SourcePartCode == v2pItm.PartCode); + // if (psObj != null) + // { + // PartBase tempObj = new PartBase(psObj.TargetPartCode, v2pItm.PartNum); + // vehiclePartBaseLst.Add(tempObj); + // } + // else + // { + // PartBase tempObj = new PartBase(v2pItm.PartCode, v2pItm.PartNum); + // vehiclePartBaseLst.Add(tempObj); + // } + // } + // } + // } + // #endregion + + // //集合比较 + // bool isSame = ServerHelper.CompareTwoCollection(billPartBaseLst, vehiclePartBaseLst); + // if (isSame) //已匹配 + // { + // ret.VehicleId = vehicleId; //整车总成ID + // ret.IsMatch = true; + // return ret; + // } + // } + // //不匹配 + // ret.IsMatch = false; + // return ret; + // } + // catch (Exception ex) + // { + // throw new Exception($"-CompareVehicleAssembly子方法-{_billNumber}-" + ex.Message); + // } + //} + + /// + /// ERP总成比较【派格版】 + /// + /// + /// 匹配的若干个Erp总成ID + //private CompareErpAssemblyResult CompareErpAssembly_PaiGe(BillM110 m110Bill, List partSwitchListByBillFilter = null) + //{ + // try + // { + // CompareErpAssemblyResult ret = new CompareErpAssemblyResult(); + + // #region 单据零件转换成PartBase + // List billPartBaseLst = new List(); + + // //排除柱护板 + // List tempBillPartLst = m110Bill.BillM110Parts; + // if (ConfigDic.CurrentVersion == ConfigDicVersionOption.派格) + // { + // tempBillPartLst = m110Bill.BillM110Parts.Where(itm => itm.PartType != "2").ToList(); //不等于柱护板 + // } + // //按PartCode分组汇总PartNum + // var qry2 = from item in tempBillPartLst + // group item by item.PartCode into g + // select new + // { + // PartCode = g.Key, + // PartNum = g.Sum(itm => itm.PartNum) + // }; + // foreach (var item in qry2) + // { + // PartBase obj = new PartBase(item.PartCode, item.PartNum); + // billPartBaseLst.Add(obj); + // } + // #endregion + + // //取ERP总成分组 + // string assGroupSql = $"select Id, GroupCode, VehicleModel from FisAssemblyCfgGroup where IsDeleted = 0 and IsDisable <> 1 and (VehicleModel = '{m110Bill.VehicleModelCode}' or VehicleModel is null)"; + // List assGroupLst = _newJitDapperRepository.GetListBySql(assGroupSql, true); + // //遍历ERP总成分组 + // foreach (AssemblyCfgGroup assGroupObj in assGroupLst) + // { + // #region ERP总成子零件转换成PartBase + + // var query = from item in _erp2partList + // where item.GroupId == assGroupObj.Id + // group item by item.PartCode into g + // select new + // { + // PartCode = g.Key, + // PartNum = g.Sum(itm => itm.PartNum) + // }; + // List erpPartBaseLst = new List(); + + // if (partSwitchListByBillFilter == null) + // { + // foreach (var item in query) + // { + // PartBase obj = new PartBase(item.PartCode, item.PartNum); + // erpPartBaseLst.Add(obj); + // } + // } + // else //执行零件切换 + // { + // //foreach (var item in query) + // //{ + // // PartSwitch psObj = partSwitchListByBillFilter.FirstOrDefault(itm => itm.SourcePartCode == item.PartCode); + // // if (psObj != null) + // // { + // // PartBase obj = new PartBase(psObj.TargetPartCode, item.PartNum); //根据切换关系表,将总成的零件,从源零件替换成目标零件 + // // erpPartBaseLst.Add(obj); + // // } + // // else + // // { + // // PartBase obj = new PartBase(item.PartCode, item.PartNum); + // // erpPartBaseLst.Add(obj); + // // } + // //} + // } + // #endregion + + // bool isSame = ServerHelper.CompareTwoCollection(billPartBaseLst, erpPartBaseLst); + // if (isSame) //已匹配 + // { + // ret.ErpAssemblyIdList = _erp2partList.Where(itm => itm.GroupId == assGroupObj.Id).Select(itm => itm.ErpAssemblyId).Distinct().ToList(); + // //为了在调用方法中将整车总成添加到内存 + // List vehicle2PartLst = new List(); + // foreach (var erpPart in erpPartBaseLst) + // { + // AssemblyCfgVehicle2Part vehicle2PartObj = new AssemblyCfgVehicle2Part(); + // vehicle2PartObj.PartCode = erpPart.PartCode; + // vehicle2PartObj.PartNum = erpPart.PartNum; + // vehicle2PartLst.Add(vehicle2PartObj); + // } + // ret.Vehicle2PartList = vehicle2PartLst; + // ret.IsMatch = true; + // return ret; + // } + // } //foreach + + // ret.IsMatch = false; + // return ret; + // } + // catch (Exception ex) + // { + // throw new Exception($"-CompareErpAssembly子方法-{_billNumber}-" + ex.Message); + // } + //} + + + /// + /// 不匹配时,插入未知总成,写提醒日志 + /// + /// + public UnknownAssembly InsertUnknownAssembly(BillM110 bill) + { + UnknownAssembly ret = null; + try + { + //插入未知总成 + UnknownAssembly unknownAssemblyObj = new UnknownAssembly(GuidGenerator.Create(), bill.Id, "M110"); + //预批量赋值 + unknownAssemblyObj.Description = bill.Description; //描述字段保存预批量信息 + + foreach (BillM110Part billPart in bill.BillM110Parts) + { + unknownAssemblyObj.AddChildObj(GuidGenerator.Create(), billPart.PartCode, billPart.PartNum, billPart.Description); + } + var partNumSum = unknownAssemblyObj.UnknownAssemblyParts.Sum(itm => (int)itm.PartNum); + unknownAssemblyObj.SetPartNum(partNumSum); + ret = _unknownAssemblyRepository.InsertAsync(unknownAssemblyObj, true).GetAwaiter().GetResult(); + return ret; + } + catch (Exception ex) + { + throw new Exception($"-InsertUnknownAssembly子方法-{_billNumber}-" + ex.Message); + } + } + + + #endregion + + }//class + +} + diff --git a/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Job.ConsoleApp/Messages/MsgTransmissionService.cs b/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Job.ConsoleApp/Messages/MsgTransmissionService.cs index dbb2065..101b4af 100644 --- a/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Job.ConsoleApp/Messages/MsgTransmissionService.cs +++ b/Modules/新版JIT或JIS系统服务端/src/WY.NewJit.Job.ConsoleApp/Messages/MsgTransmissionService.cs @@ -53,8 +53,10 @@ namespace WY.NewJit.Job.ConsoleApp.Messages /// private readonly M100CheckDomainService _m100CheckDomainService; + private readonly M110CheckDomainService _m110_CheckDomainService; + //private readonly CacheManagerDomainService _cacheManagerDomainService; - + /// /// 日志 @@ -76,6 +78,9 @@ namespace WY.NewJit.Job.ConsoleApp.Messages /// private readonly IRepository _billM100Repository; + private readonly IRepository _billM110_Repository; + + /// /// 重复R100 /// @@ -86,6 +91,8 @@ namespace WY.NewJit.Job.ConsoleApp.Messages /// private readonly IRepository _repeatM100Repository; + private readonly IRepository _repeatM110_Repository; + /// /// 排除零件配置 /// @@ -238,7 +245,10 @@ namespace WY.NewJit.Job.ConsoleApp.Messages DicDomainService dicDomainService, IGuidGenerator guidGenerator, GlobalSettingsDomainService globalSettingsDomainService, - IRepository messageReceiveArchiveRepository + IRepository messageReceiveArchiveRepository, + IRepository billM110_Repository, + IRepository repeatM110_Repository, + M110CheckDomainService m110_CheckDomainService //CacheManagerDomainService cacheManagerDomainService ) { @@ -260,6 +270,9 @@ namespace WY.NewJit.Job.ConsoleApp.Messages GuidGenerator = guidGenerator; _globalSettingsDomainService = globalSettingsDomainService; _messageReceiveArchiveRepository = messageReceiveArchiveRepository; + _billM110_Repository = billM110_Repository; + _repeatM110_Repository = repeatM110_Repository; + _m110_CheckDomainService = m110_CheckDomainService; //_cacheManagerDomainService = cacheManagerDomainService; } #endregion @@ -596,6 +609,18 @@ namespace WY.NewJit.Job.ConsoleApp.Messages throw new Exception(msg3); } } + else if (billResObj.M110_Bill != null) + { + var m110Bill = billResObj.M110_Bill; + bool isRepeat = _billM110_Repository.Any(itm => itm.HostSN == m110Bill.HostSN && itm.VIN == m110Bill.VIN && itm.MessageFileReceiveID != msgReceiveObj.Id); + if (isRepeat == true) + { + var succObj = _m110_CheckDomainService.InsertM110RepeatBill(msgReceiveObj, m110Bill); + string msg3 = _errorMessagePrefix + $"M110是重复报文:{msgReceiveObj.MessageFileName}"; + _logger.LogDebug(msg3); + throw new Exception(msg3); + } + } #endregion UpdateVehicleModel(msgReceiveObj, billResObj); //更新车型 @@ -630,6 +655,12 @@ namespace WY.NewJit.Job.ConsoleApp.Messages string snStr = ServerHelper.ToSerialNumStr(r100.OnlineTime, r100.HostSN, "r100", r100.ProductLine); billResultObj.R100Bill.SetSerialNumStr(snStr); } + else if (billResultObj.M110_Bill != null) + { + var m110 = billResultObj.M110_Bill; + string snStr = ServerHelper.ToSerialNumStr(m110.OnlineTime, m110.HostSN, "m110", m110.ProductLine); + billResultObj.M110_Bill.SetSerialNumStr(snStr); + } #endregion //区分门板和柱护板 @@ -658,6 +689,25 @@ namespace WY.NewJit.Job.ConsoleApp.Messages billHostSN = billResultObj.M100Bill.HostSN; isSucc = resu.Status; } + else if (billType == "M110") + { + var resu = _m110_CheckDomainService.DoCheckM110Bill(msgReceiveObj, billResultObj.M110_Bill); + billOnlineTime = billResultObj.M110_Bill.OnlineTime; + billHostSN = billResultObj.M110_Bill.HostSN; + isSucc = resu.Status; + + #region 接收M110时,更新M100的“接收M110状态” + string vin = billResultObj.M110_Bill.VIN; + var m100Query = _billM100Repository.GetQueryableAsync().GetAwaiter().GetResult(); + BillM100 m100Obj = m100Query.FirstOrDefault(itm => itm.VIN == vin); + if (m100Obj != null) + { + m100Obj.IsReceiveM110 = true; + _billM100Repository.UpdateAsync(m100Obj).GetAwaiter().GetResult(); + } + #endregion + } + if (isSucc) { MessageReceiveArchive msgReceArv = new MessageReceiveArchive(GuidGenerator.Create(), msgReceiveObj.MessageFileName, msgReceiveObj.MessageContent, @@ -675,10 +725,6 @@ namespace WY.NewJit.Job.ConsoleApp.Messages #endregion } //遍历多个成品件 - - - - } catch (Exception ex0) { @@ -722,7 +768,7 @@ namespace WY.NewJit.Job.ConsoleApp.Messages newBill.SetBillStatus(BillStatusEnum.Match); newBill.BillR100Parts.Clear(); newBill.BillR100Parts.AddRange(item.PartList); - billResultLst.Add(new BillResult(newBill, null)); + billResultLst.Add(new BillResult(newBill, null, null)); } } @@ -744,7 +790,28 @@ namespace WY.NewJit.Job.ConsoleApp.Messages newBill.SetBillStatus(BillStatusEnum.Match); newBill.BillM100Parts.Clear(); newBill.BillM100Parts.AddRange(item.PartList); - billResultLst.Add(new BillResult(null, newBill)); + billResultLst.Add(new BillResult(null, newBill, null)); + } + } + else if (billResObj.M110_Bill != null) + { + var m110bill = billResObj.M110_Bill; + var billPartLst = billResObj.M110_Bill.BillM110Parts; //包含多个成品件 + var partGroups = billPartLst.GroupBy(itm => new { itm.PartType, itm.PartType2 }).Select(itm => new + { + ProductLine = itm.Key.PartType, + Group = itm.Key.PartType2, + PartList = itm.ToList() + }).ToList(); + foreach (var item in partGroups) + { + var newBill = BillM110.Clone(m110bill); + newBill.SetId(GuidGenerator.Create()); + newBill.ProductLine = item.ProductLine; + newBill.SetBillStatus(BillStatusEnum.Match); + newBill.BillM110Parts.Clear(); + newBill.BillM110Parts.AddRange(item.PartList); + billResultLst.Add(new BillResult(null, null, newBill)); } } return billResultLst; @@ -800,6 +867,27 @@ namespace WY.NewJit.Job.ConsoleApp.Messages } } } + else if (billResObj.M110_Bill != null) + { + var bill = billResObj.M110_Bill; + var billPartLst = billResObj.M110_Bill.BillM110Parts; //包含多个成品件 + foreach (var billPart in billPartLst) + { + string partLargeType = billPart.PartCode.Substring(6, 3); //取客户零件代码的7-9位,是零件大类 + var partCfgObj = _partLargeTypeList.FirstOrDefault(itm => itm.LargeTypeCode == partLargeType && itm.VehicleModel == bill.VehicleModelCode); //是否加车型过滤//?? + if (partCfgObj != null) + { + billPart.PartType = partCfgObj.ProductLine; + billPart.PartType2 = partCfgObj.Group; + billPart.PartType3 = partCfgObj.LargeTypeCode; + } + else + { + ret = $"根据车型{bill.VehicleModelCode}和零件大类{partLargeType}在零件大类字典中没有取到数据:{billPart.PartCode}"; + break; + } + } + } return ret; } @@ -1044,6 +1132,51 @@ namespace WY.NewJit.Job.ConsoleApp.Messages } ret.M100Bill = m100Obj; } + else if (billType == "M110") + { + DateTime onlineTimeDT = onlineTime.yyyyMMddHHmmssToDateTime(); + string serialNumStr = ServerHelper.ToSerialNumStr(onlineTimeDT, hostSN.TryToIntZero()); + + BillM110 m110_Obj = new BillM110( + GuidGenerator.Create(), + msgReceObj.Id, //报文接收ID + ServerHelper.VinToSN(vinCode), //流水号 maxSN + 1 流水号改成底盘后六位,这样同一生产线中不会重复、并且连续 + serialNumStr, + hostSN.TryToInt(), + orderNumberKNR, + vinCode, //底牌号 + null, //总成ID + onlineTimeDT, //上线时间 + vehicleModel, //车型代码(取通用字典) + onlineTimeDT.Year.ToString(), + msgReceObj.ReceiveTime, + BillStatusEnum.None + ); + + for (int i = 0; i < partCodeList.Count; i++) + { + if (vehicleModel == "3C") //3C => B8L + { + string partCode = partCodeList[i]; + int partNum = qtyList[i] ?? 0; + if (m110_Obj.BillM110Parts.Any(itm => itm.PartCode == partCode && itm.PartNum == partNum)) + { + //B8L零件重复,待处理 + } + else + { + m110_Obj.AddChildObj(GuidGenerator.Create(), partCodeList[i], qtyList[i] ?? 0); + } + } + else + { + m110_Obj.AddChildObj(GuidGenerator.Create(), partCodeList[i], qtyList[i] ?? 0); + } + + } + ret.M110_Bill = m110_Obj; + } + return ret; } catch (Exception ex) @@ -1150,6 +1283,30 @@ namespace WY.NewJit.Job.ConsoleApp.Messages } } + else if (billResObj.M110_Bill != null) + { + var bill = billResObj.M110_Bill; + string ediVehicleModel = bill.VehicleModelCode; //报文车型 + //车型转换:3H 转 CC + var obj1 = _msgToPaiGeVehicleModelList.FirstOrDefault(itm => itm.DicItemCode == ediVehicleModel); + if (obj1 != null) + { + string paigeVehicleModel = obj1.DicItemName; // CC + if (paigeVehicleModel.Contains('-')) //去掉B8L-PHEV中的-PHEV + { + paigeVehicleModel = paigeVehicleModel.Split('-')[0]; + } + bill.SetVehicleModelCode(paigeVehicleModel); + + } + else //报文车型 没有对应的 格拉默车型 + { + msgReceObj.ErrorCount = 4; + string errorMsg = $"报文车型{ediVehicleModel}没有对应的零件生产工厂车型:{msgReceObj.MessageFileName}"; + throw new Exception(errorMsg); //车型不存在,直接返回解析失败,程序执行中断,报警(不进入未知总成) + + } + } } private static void SetProductLineByExcept(BillR100 bill) @@ -1283,6 +1440,19 @@ namespace WY.NewJit.Job.ConsoleApp.Messages billObj.Description = "预批量"; } } + else if (billResObj.M110_Bill != null) + { + var billObj = billResObj.M110_Bill; + if (billObj.KNR.Length == 8) + { + string yy = ((DateTime)billObj.OnlineTime).ToString("yy"); + billObj.KNR = yy + billObj.KNR; + } + if (billObj.KNR.Length == 10 && billObj.KNR.Substring(4, 1) == "7") + { + billObj.Description = "预批量"; + } + } } } #endregion @@ -1295,14 +1465,17 @@ namespace WY.NewJit.Job.ConsoleApp.Messages public BillR100 R100Bill { get; set; } public BillM100 M100Bill { get; set; } + public BillM110 M110_Bill { get; set; } + public BillResult() { } - public BillResult(BillR100 r100Bill, BillM100 m100Bill) + public BillResult(BillR100 r100Bill, BillM100 m100Bill, BillM110 m110Bill) { R100Bill = r100Bill; M100Bill = m100Bill; + M110_Bill = m110Bill; } }