6 changed files with 1061 additions and 23 deletions
@ -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 |
|||
{ |
|||
/// <summary>
|
|||
/// 报文校验领域服务实现
|
|||
/// </summary>
|
|||
public class M110CheckDomainService : DomainService |
|||
{ |
|||
|
|||
/// <summary>
|
|||
/// M110单据
|
|||
/// </summary>
|
|||
private readonly IRepository<BillM110, Guid> _billM110Repository; |
|||
|
|||
/// <summary>
|
|||
/// 日志
|
|||
/// </summary>
|
|||
private ILogger<M110CheckDomainService> _logger; |
|||
|
|||
/// <summary>
|
|||
/// 日志提醒
|
|||
/// </summary>
|
|||
private readonly LogRemindDomainService _logRemindDomainService; |
|||
|
|||
/// <summary>
|
|||
/// 对象映射
|
|||
/// </summary>
|
|||
private readonly IObjectMapper _objectMapper; |
|||
|
|||
/// <summary>
|
|||
/// 重复M110
|
|||
/// </summary>
|
|||
private readonly IRepository<RepeatM110, Guid> _repeatM110Repository; |
|||
|
|||
/// <summary>
|
|||
/// 排除零件配置
|
|||
/// </summary>
|
|||
private readonly IRepository<ExcludePartCfg, Guid> _excludePartCfgRepository; |
|||
|
|||
/// <summary>
|
|||
/// 未知总成维护
|
|||
/// </summary>
|
|||
private readonly IRepository<UnknownAssembly, Guid> _unknownAssemblyRepository; |
|||
|
|||
/// <summary>
|
|||
/// 配置文件
|
|||
/// </summary>
|
|||
private readonly Microsoft.Extensions.Configuration.IConfiguration _configuration; |
|||
|
|||
/// <summary>
|
|||
/// Dapper仓储
|
|||
/// </summary>
|
|||
private readonly INewJitDapperRepository _newJitDapperRepository; |
|||
|
|||
/// <summary>
|
|||
/// 整车总成配置仓库
|
|||
/// </summary>
|
|||
private readonly IRepository<AssemblyCfgVehicle, Guid> _assemblyCfgVehicleRepository; |
|||
|
|||
/// <summary>
|
|||
/// 零件配置
|
|||
/// </summary>
|
|||
private readonly IRepository<PartCfg, Guid> _partCfgRepository; |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 错误信息前缀
|
|||
/// </summary>
|
|||
private string _errorMessagePrefix |
|||
{ |
|||
get |
|||
{ |
|||
return System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "."; |
|||
} |
|||
} |
|||
|
|||
int? _hostSN = 0; |
|||
/// <summary>
|
|||
/// 单据号,写日志时用(R100时是KNR,M110是时VIN)
|
|||
/// </summary>
|
|||
private string _billNumber = ""; |
|||
string _fileName = ""; |
|||
|
|||
private int _parseAssemblyCycleCount = 0; |
|||
|
|||
/// <summary>
|
|||
/// 解析Erp总成时的循环数量
|
|||
/// </summary>
|
|||
public int ParseAssemblyCycleCount |
|||
{ |
|||
get |
|||
{ |
|||
if (_parseAssemblyCycleCount == 0) |
|||
{ |
|||
_parseAssemblyCycleCount = _configuration["ConfigDic:ParseAssemblyCycleCount"].TryToInt() ?? 4; |
|||
} |
|||
return _parseAssemblyCycleCount; |
|||
|
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 整车总成Id列表
|
|||
/// </summary>
|
|||
static List<VehicleAssemblyMainList> _vehicleAssemblyIdList = new List<VehicleAssemblyMainList>(); |
|||
|
|||
/// <summary>
|
|||
/// 整车vs零件列表
|
|||
/// </summary>
|
|||
//static List<AssemblyCfgVehicle2Part> _vehicle2partList = new List<AssemblyCfgVehicle2Part>();
|
|||
|
|||
static Dictionary<Guid, List<AssemblyCfgVehicle2Part>> _vehicle2partDict |
|||
= new Dictionary<Guid, List<AssemblyCfgVehicle2Part>>(); |
|||
|
|||
/// <summary>
|
|||
/// Erp总成Id列表
|
|||
/// </summary>
|
|||
static List<ErpAssemblyMain> _erpAssemblyMainList = new List<ErpAssemblyMain>(); |
|||
|
|||
/// <summary>
|
|||
/// Erp总成vs零件列表
|
|||
/// </summary>
|
|||
static List<AssemblyCfgErp2Part> _erp2partList = new List<AssemblyCfgErp2Part>(); |
|||
|
|||
/// <summary>
|
|||
/// 结算件切换列表
|
|||
/// </summary>
|
|||
static List<PartSwitch> _partSwitchList = new List<PartSwitch>(); |
|||
|
|||
/// <summary>
|
|||
/// 切换目标零件编码
|
|||
/// </summary>
|
|||
static List<string> _switchTargetPartCodeList = new List<string>(); |
|||
|
|||
|
|||
public M110CheckDomainService() |
|||
{ } |
|||
|
|||
/// <summary>
|
|||
/// 构造函数
|
|||
/// </summary>
|
|||
public M110CheckDomainService( |
|||
IRepository<BillM110, Guid> billM110Repository, |
|||
ILogger<M110CheckDomainService> logger, |
|||
LogRemindDomainService logRemindDomainService, |
|||
IObjectMapper objectMapper, |
|||
IRepository<RepeatM110, Guid> repeatM110Repository, |
|||
IRepository<ExcludePartCfg, Guid> excludePartCfgRepository, |
|||
IRepository<UnknownAssembly, Guid> unknownAssemblyRepository, |
|||
Microsoft.Extensions.Configuration.IConfiguration configuration, |
|||
INewJitDapperRepository newJitDapperRepository, |
|||
IRepository<AssemblyCfgVehicle, Guid> assemblyCfgVehicleRepository, |
|||
IRepository<PartCfg, Guid> 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<VehicleAssemblyMainList> vehicleAssemblyIdList, List<AssemblyCfgVehicle2Part> vehicle2partList, List<ErpAssemblyMain> erpAssemblyMainList, List<AssemblyCfgErp2Part> erp2partList, List<PartSwitch> 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(); //切换目标零件编码,判断单据是否存在切换零件时使用
|
|||
} |
|||
|
|||
/// <summary>
|
|||
/// M110报文解析-正常入口
|
|||
/// </summary>
|
|||
/// <param name="msgReceiveObj"></param>
|
|||
/// <param name="m110Bill"></param>
|
|||
/// <returns></returns>
|
|||
/// <exception cref="Exception"></exception>
|
|||
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<BillM110> 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; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 总成比较
|
|||
/// </summary>
|
|||
/// <param name="m110Bill"></param>
|
|||
/// <param name="isBillSaved"></param>
|
|||
/// <returns></returns>
|
|||
//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<string> billPartCodeLst01 = m110Bill.BillM110Parts.Select(itm => itm.PartCode).ToList();
|
|||
// List<PartSwitch> 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);
|
|||
// }
|
|||
//}
|
|||
|
|||
/// <summary>
|
|||
/// 整车总成比较
|
|||
/// </summary>
|
|||
/// <param name="m110Bill"></param>
|
|||
/// <returns>整车总成ID</returns>
|
|||
//private CompareVehicleAssemblyResult CompareVehicleAssembly(BillM110 m110Bill, List<PartSwitch> partSwitchListByBillFilter = null)
|
|||
//{
|
|||
// try
|
|||
// {
|
|||
// CompareVehicleAssemblyResult ret = new CompareVehicleAssemblyResult();
|
|||
// //取切换源零件列表
|
|||
// List<string> switchSourcePartCodeLst = new List<string>();
|
|||
// if (partSwitchListByBillFilter != null)
|
|||
// {
|
|||
// switchSourcePartCodeLst = partSwitchListByBillFilter.Select(itm => itm.SourcePartCode).ToList();
|
|||
// }
|
|||
|
|||
// #region 单据子零件转换成PartBase(排除柱护板)
|
|||
// List<PartBase> billPartBaseLst = new List<PartBase>();
|
|||
// List<BillM110Part> 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<AssemblyCfgVehicle2Part> vehicle2PartLst))
|
|||
// {
|
|||
// continue;
|
|||
// }
|
|||
// //先判断数量是否一致
|
|||
// if (vehicle2PartLst.Count != billPartBaseLst.Count) continue;
|
|||
|
|||
// #region 整车总成零件转换成PartBase
|
|||
// List<PartBase> vehiclePartBaseLst = new List<PartBase>();
|
|||
// 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);
|
|||
// }
|
|||
//}
|
|||
|
|||
/// <summary>
|
|||
/// ERP总成比较【派格版】
|
|||
/// </summary>
|
|||
/// <param name="m110Bill"></param>
|
|||
/// <returns>匹配的若干个Erp总成ID</returns>
|
|||
//private CompareErpAssemblyResult CompareErpAssembly_PaiGe(BillM110 m110Bill, List<PartSwitch> partSwitchListByBillFilter = null)
|
|||
//{
|
|||
// try
|
|||
// {
|
|||
// CompareErpAssemblyResult ret = new CompareErpAssemblyResult();
|
|||
|
|||
// #region 单据零件转换成PartBase
|
|||
// List<PartBase> billPartBaseLst = new List<PartBase>();
|
|||
|
|||
// //排除柱护板
|
|||
// List<BillM110Part> 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<AssemblyCfgGroup> assGroupLst = _newJitDapperRepository.GetListBySql<AssemblyCfgGroup>(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<PartBase> erpPartBaseLst = new List<PartBase>();
|
|||
|
|||
// 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<AssemblyCfgVehicle2Part> vehicle2PartLst = new List<AssemblyCfgVehicle2Part>();
|
|||
// 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);
|
|||
// }
|
|||
//}
|
|||
|
|||
|
|||
/// <summary>
|
|||
/// 不匹配时,插入未知总成,写提醒日志
|
|||
/// </summary>
|
|||
/// <param name="bill"></param>
|
|||
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
|
|||
|
|||
} |
|||
|
Loading…
Reference in new issue