@ -19,6 +19,7 @@ using WY.NewJit.MsgCheck;
using WY.NewJit.MsgConversion ;
using WY.NewJit.MsgTransmission ;
using Microsoft.EntityFrameworkCore ;
using WY.NewJit.Extends ;
namespace WY.NewJit.Job.ConsoleApp.Messages
@ -147,6 +148,11 @@ namespace WY.NewJit.Job.ConsoleApp.Messages
/// </summary>
private static List < PartCfg > _ partCfgList = new List < PartCfg > ( ) ;
/// <summary>
/// 零件大类
/// </summary>
private static List < PartLargeType > _ partLargeTypeList = new List < PartLargeType > ( ) ;
#endregion
#region 变量
@ -208,7 +214,7 @@ namespace WY.NewJit.Job.ConsoleApp.Messages
private DateTime _l astRefreshCacheTime = DateTime . Now ;
#endregion
private static string errorHeader = "" ; //错误头
private static string errorHeader = "" ; //错误头
#region 构造函数
/// <summary>
@ -260,7 +266,7 @@ namespace WY.NewJit.Job.ConsoleApp.Messages
#region 公共方法
/// <summary>
/// 报文转换,BOM解析
/// 报文转换,BOM解析(根入口)
/// </summary>
/// <returns></returns>
[UnitOfWork]
@ -274,8 +280,6 @@ namespace WY.NewJit.Job.ConsoleApp.Messages
string fileName = "" ;
try
{
//PathConfigInfo cfgInfo = ReadConfig();
int countPerTime = _ configuration [ "ConfigDic:TransferFileCountPerTime" ] . TryToInt ( ) ? ? 1 0 ;
InitLoadCache ( ) ;
@ -438,7 +442,7 @@ namespace WY.NewJit.Job.ConsoleApp.Messages
}
#region 无法缓存的
//结算件信息列表,库存系统同步过来,无法缓存
string partCfgSql = @"select Id, PartCode, PartName, PartType, Description, PartType2, PartType3, RelationKey from FisPartCfg where 1=1" ; //,DaXiaoLiangGang,DoorPlankCode,MaterialDescription,SAPMaterialNum
string partCfgSql = @"select Id, PartCode, PartName, PartType, Description, PartType2, PartType3, RelationKey from FisPartCfg where 1=1 and IsDeleted = 0 " ; //,DaXiaoLiangGang,DoorPlankCode,MaterialDescription,SAPMaterialNum
_ partCfgList = _ newJitDapperRepository . GetListBySql < PartCfg > ( partCfgSql , true ) ;
#endregion
@ -455,67 +459,83 @@ namespace WY.NewJit.Job.ConsoleApp.Messages
/// </summary>
private void DoInitLoadCache ( )
{
//取整车总成主表
string vehicleSql = "select Id, VehicleModelCode as VehicleModel from FisAssemblyCfgVehicle v where NewVersionId is null order by CreationTime desc" ;
List < VehicleAssemblyMainList > vehicleAssemblyIdList = _ newJitDapperRepository . GetListBySql < VehicleAssemblyMainList > ( vehicleSql , true ) ;
//取整车总成的零件:按整车总成Id、零件编码分组汇总数量
const string vehicle2PartSql = @ "
select v . Id as VehicleAssemblyId , ep . PartCode , sum ( ep . PartNum ) as PartNum
from FisAssemblyCfgVehicle v
join FisAssemblyCfgVehicleChild vc on v . Id = vc . AssemblyCfgVehicleId
join FisAssemblyCfgErp e on vc . ErpAssemblyId = e . Id
join FisAssemblyCfgPart ep on e . Id = ep . AssemblyCfgErpId
where 1 = 1 and not exists ( select PartCode from FisPartCfg pc where IsDisable = 1 and ep . PartCode = pc . PartCode )
and v . NewVersionId is null
and ep . PartCode is not null
group by v . Id , ep . PartCode
order by v . Id , ep . PartCode
";
var vehicle2partList = _ newJitDapperRepository . GetListBySql < AssemblyCfgVehicle2Part > ( vehicle2PartSql , true ) ;
//取ERP总成主表
string erpMainSql = "select Id, VehicleModel from FisAssemblyCfgErp where NewVersionId is null order by ErpAssemblyVersion, CreationTime desc" ;
List < ErpAssemblyMain > erpAssemblyMainList = _ newJitDapperRepository . GetListBySql < ErpAssemblyMain > ( erpMainSql , true ) ;
//取ERP总成的零件
List < AssemblyCfgErp2Part > erp2partList = new List < AssemblyCfgErp2Part > ( ) ;
if ( ConfigDic . CurrentVersion = = ConfigDicVersionOption . 派 格 )
{
//取所有零件(IsDisable = 1时表示不参与解析BOM)(派格版本根据长描述分组过滤,不过滤NewVersionId)
string erp2partSql = @ "
select e . GroupId , e . Id as ErpAssemblyId , e . ErpAssemblyCode , ep . Id as PartId , ep . PartCode , ep . PartNum , ep . IsKey
from FisAssemblyCfgErp e
join FisAssemblyCfgPart ep on e . Id = ep . AssemblyCfgErpId
where ep . PartCode is not null
and not exists ( select PartCode from FisPartCfg pc where IsDisable = 1 and ep . PartCode = pc . PartCode )
/*and ep.PartCode in (select distinct RelationKey from FisMaterialExt where MaterialGroup like '72%')*/
";
erp2partList = _ newJitDapperRepository . GetListBySql < AssemblyCfgErp2Part > ( erp2partSql , true ) ;
//结算件切换列表
string partSwitchSql = "select SourcePartCode, TargetPartCode, ActiveBeginTime, ActiveEndTime from FisPartSwitch" ;
_ partSwitchList = _ newJitDapperRepository . GetListBySql < PartSwitch > ( partSwitchSql , true ) ;
}
else
////取整车总成主表
//string vehicleSql = "select Id, VehicleModelCode as VehicleModel from FisAssemblyCfgVehicle v where NewVersionId is null order by CreationTime desc";
//List<VehicleAssemblyMainList> vehicleAssemblyIdList = _newJitDapperRepository.GetListBySql<VehicleAssemblyMainList>(vehicleSql, true);
////取整车总成的零件:按整车总成Id、零件编码分组汇总数量
//const string vehicle2PartSql = @"
// select v.Id as VehicleAssemblyId, ep.PartCode, sum(ep.PartNum) as PartNum
// from FisAssemblyCfgVehicle v
// join FisAssemblyCfgVehicleChild vc on v.Id = vc.AssemblyCfgVehicleId
// join FisAssemblyCfgErp e on vc.ErpAssemblyId = e.Id
// join FisAssemblyCfgPart ep on e.Id = ep.AssemblyCfgErpId
// where 1=1 and not exists (select PartCode from FisPartCfg pc where IsDisable = 1 and ep.PartCode = pc.PartCode)
// and v.NewVersionId is null
// and ep.PartCode is not null
// group by v.Id, ep.PartCode
// order by v.Id, ep.PartCode
// ";
//var vehicle2partList = _newJitDapperRepository.GetListBySql<AssemblyCfgVehicle2Part>(vehicle2PartSql, true);
////取ERP总成主表
//string erpMainSql = "select Id, VehicleModel from FisAssemblyCfgErp where NewVersionId is null order by ErpAssemblyVersion, CreationTime desc";
//List<ErpAssemblyMain> erpAssemblyMainList = _newJitDapperRepository.GetListBySql<ErpAssemblyMain>(erpMainSql, true);
////取ERP总成的零件
//List<AssemblyCfgErp2Part> erp2partList = new List<AssemblyCfgErp2Part>();
//if (ConfigDic.CurrentVersion == ConfigDicVersionOption.派格)
//{
// //取所有零件(IsDisable = 1时表示不参与解析BOM)(派格版本根据长描述分组过滤,不过滤NewVersionId)
// string erp2partSql = @"
// select e.GroupId, e.Id as ErpAssemblyId, e.ErpAssemblyCode, ep.Id as PartId, ep.PartCode, ep.PartNum, ep.IsKey
// from FisAssemblyCfgErp e
// join FisAssemblyCfgPart ep on e.Id = ep.AssemblyCfgErpId
// where ep.PartCode is not null
// and not exists (select PartCode from FisPartCfg pc where IsDisable = 1 and ep.PartCode = pc.PartCode)
// /*and ep.PartCode in (select distinct RelationKey from FisMaterialExt where MaterialGroup like '72%')*/
// ";
// erp2partList = _newJitDapperRepository.GetListBySql<AssemblyCfgErp2Part>(erp2partSql, true);
// //结算件切换列表
// string partSwitchSql = "select SourcePartCode, TargetPartCode, ActiveBeginTime, ActiveEndTime from FisPartSwitch";
// _partSwitchList = _newJitDapperRepository.GetListBySql<PartSwitch>(partSwitchSql, true);
//}
//else
//{
// //取所有零件(IsDisable = 1时表示不需要解析BOM)
// string erp2partSql = @"
// select e.Id as ErpAssemblyId, e.ErpAssemblyCode, ep.Id as PartId, ep.PartCode, ep.PartNum, ep.IsKey
// from FisAssemblyCfgErp e
// join FisAssemblyCfgPart ep on e.Id = ep.AssemblyCfgErpId
// where e.NewVersionId is null
// and ep.PartCode is not null
// and not exists (select PartCode from FisPartCfg pc where IsDisable = 1 and ep.PartCode = pc.PartCode)
// ";
// erp2partList = _newJitDapperRepository.GetListBySql<AssemblyCfgErp2Part>(erp2partSql, true);
//}
//_r100CheckDomainSrv.InitPub(vehicleAssemblyIdList, vehicle2partList, erpAssemblyMainList, erp2partList, _partSwitchList); //整车总成内存及时刷新, ERP总成增删改时触发刷新标志
//_m100CheckDomainService.InitPub(vehicleAssemblyIdList, vehicle2partList, erpAssemblyMainList, erp2partList, _partSwitchList);
_ msgToPaiGeVehicleModelList = _d icDomainService . GetDicItems ( DicTypeName . 报 文 车 型 对 应 格 拉 默 车 型 ) ;
//_r100VehicleModelProductLineList = _dicDomainService.GetDicItems(DicTypeName.R100格拉默车型对应生产线);
//_m100VehicleModelProductLineList = _dicDomainService.GetDicItems(DicTypeName.M100格拉默车型对应生产线);
#region 加载零件大类
_ partLargeTypeList = new List < PartLargeType > ( ) ;
var largeTypeDic = _d icDomainService . GetDicItems ( DicTypeName . 零 件 大 类 ) ;
foreach ( var item in largeTypeDic )
{
//取所有零件(IsDisable = 1时表示不需要解析BOM)
string erp2partSql = @ "
select e . Id as ErpAssemblyId , e . ErpAssemblyCode , ep . Id as PartId , ep . PartCode , ep . PartNum , ep . IsKey
from FisAssemblyCfgErp e
join FisAssemblyCfgPart ep on e . Id = ep . AssemblyCfgErpId
where e . NewVersionId is null
and ep . PartCode is not null
and not exists ( select PartCode from FisPartCfg pc where IsDisable = 1 and ep . PartCode = pc . PartCode )
";
erp2partList = _ newJitDapperRepository . GetListBySql < AssemblyCfgErp2Part > ( erp2partSql , true ) ;
PartLargeType partLargeType = new PartLargeType ( ) ;
partLargeType . LargeTypeCode = item . DicItemCode ; //零件大类
partLargeType . LargeTypeName = item . DicItemName ;
partLargeType . Group = item . DicItemSort1 ; //分组
partLargeType . ProductLine = item . DicItemSort2 ; //产线
partLargeType . VehicleModel = item . DicItemSort3 ; //车型
_ partLargeTypeList . Add ( partLargeType ) ;
}
#endregion
_ r100CheckDomainSrv . InitPub ( vehicleAssemblyIdList , vehicle2partList , erpAssemblyMainList , erp2partList , _ partSwitchList ) ; //整车总成内存及时刷新, ERP总成增删改时触发刷新标志
_ m100CheckDomainService . InitPub ( vehicleAssemblyIdList , vehicle2partList , erpAssemblyMainList , erp2partList , _ partSwitchList ) ;
_ msgToPaiGeVehicleModelList = _d icDomainService . GetDicItems ( DicTypeName . 报 文 车 型 对 应 格 拉 默 车 型 ) ;
_ r100VehicleModelProductLineList = _d icDomainService . GetDicItems ( DicTypeName . R100格拉默车型对应生产线 ) ;
_ m100VehicleModelProductLineList = _d icDomainService . GetDicItems ( DicTypeName . M100格拉默车型对应生产线 ) ;
_l ogger . LogDebug ( "重新刷新报文解析缓存!" ) ;
}
@ -532,13 +552,12 @@ namespace WY.NewJit.Job.ConsoleApp.Messages
string billType = null ;
try
{
#region 报文转换
fileName = msgReceiveObj . MessageFileName ;
text = msgReceiveObj . MessageContent ;
errorHeader = "报文校验" ;
string errorMsg = CheckEdiFile ( text , fileName , out billType ) ;
if ( string . IsNullOrEmpty ( errorMsg ) = = false )
if ( errorMsg . HasValue ( ) ) //Edi报表格式错误
{
MessageReceiveArchive msgReceArv2 = new MessageReceiveArchive ( GuidGenerator . Create ( ) , msgReceiveObj . MessageFileName , msgReceiveObj . MessageContent , ReceiveStatusEnum . ArchiveFailed , msgReceiveObj . ReceiveTime , msgReceiveObj . LastUpdateTime , msgReceiveObj . Id , "M110" ) ;
var succObj2 = _ messageReceiveArchiveRepository . InsertAsync ( msgReceArv2 ) . GetAwaiter ( ) . GetResult ( ) ;
@ -552,66 +571,109 @@ namespace WY.NewJit.Job.ConsoleApp.Messages
//将报文内容转换成BillR100或BillM100
var billResObj = ConvertToBill ( msgReceiveObj , billType ) ; //------------
//更新车型、生产线
UpdateProductLine ( billResObj ) ;
#region 更新SerialNumStr
if ( billResObj . M100Bill ! = null )
# region 重复报文
if ( billResObj . R100Bill ! = null )
{
var m100 = billResObj . M100Bill ;
string snStr = ServerHelper . ToSerialNumStr ( m100 . OnlineTime , m100 . HostSN , "m100" , m100 . ProductLine ) ;
billResObj . M100Bill . SetSerialNumStr ( snStr ) ;
var r100Bill = billResObj . R100Bill ;
bool isRepeat = _ billR100Repos . Any ( itm = > itm . HostSN = = r100Bill . HostSN & & itm . KNR = = r100Bill . KNR & & itm . MessageFileReceiveID ! = msgReceiveObj . Id ) ;
if ( isRepeat = = true )
{
var succObj = _ r100CheckDomainSrv . InsertR100Repeat ( msgReceiveObj , r100Bill ) ;
_l ogger . LogDebug ( _ errorMessagePrefix + $"是重复报文:{msgReceiveObj.MessageFileName}" ) ;
return ;
}
}
if ( billResObj . R100Bill ! = null )
else if ( billResObj . M 100Bill ! = null )
{
var r100 = billResObj . R100Bill ;
string snStr = ServerHelper . ToSerialNumStr ( r100 . OnlineTime , r100 . HostSN , "r100" , r100 . ProductLine ) ;
billResObj . R100Bill . SetSerialNumStr ( snStr ) ;
var m100Bill = billResObj . M100Bill ;
bool isRepeat = _ billM100Repository . Any ( itm = > itm . HostSN = = m100Bill . HostSN & & itm . VIN = = m100Bill . VIN & & itm . MessageFileReceiveID ! = msgReceiveObj . Id ) ;
if ( isRepeat = = true )
{
var succObj = _ m100CheckDomainService . InsertM100RepeatBill ( msgReceiveObj , m100Bill ) ;
_l ogger . LogDebug ( _ errorMessagePrefix + $"是重复报文:{msgReceiveObj.MessageFileName}" ) ;
return ;
}
}
#endregion
//区分门板和柱护板
DifferenceMenBan_ZhuHuBan ( billResObj ) ;
//KNR前缀加两位年、预批量
UpdatePrebatch ( billResObj ) ;
#region 更新三个零件类别,有不识别零件时直接中断程序
string unknowPartCode = UpdatePartLargeType ( billResObj ) ;
if ( unknowPartCode . HasValue ( ) ) //有不识别零件
{
throw new Exception ( $"存在不识别的零件{unknowPartCode}:{msgReceiveObj.MessageFileName}" ) ; //零件大类没有维护时,直接返回解析失败,程序执行中断,报警(不进入未知总成)
}
#endregion
#region BOM解析
errorHeader = "文件解析" ;
DateTime ? billOnlineTime = null ;
int? billHostSN = null ;
bool isSucc = false ;
//根据 产线、分组,将一个报文拆分成若干R100或M100记录(同时更新生产线,单据状态是已匹配)
List < BillResult > billResultLst = SplitBillByGroup ( billResObj ) ;
if ( billType = = "R100" )
{
var resu = _ r100CheckDomainSrv . DoCheckR100 ( msgReceiveObj , billResObj . R100Bill ) ;
billOnlineTime = billResObj . R100Bill . OnlineTime ;
billHostSN = billResObj . R100Bill . HostSN ;
isSucc = resu . Status ;
}
else if ( billType = = "M100" )
foreach ( var billResultObj in billResultLst ) //遍历多个成品件
{
var resu = _ m100CheckDomainService . DoCheckM100Bill ( msgReceiveObj , billResObj . M100Bill ) ;
billOnlineTime = billResObj . M100Bill . OnlineTime ;
billHostSN = billResObj . M100Bill . HostSN ;
isSucc = resu . Status ;
}
if ( isSucc )
{
MessageReceiveArchive msgReceArv = new MessageReceiveArchive ( GuidGenerator . Create ( ) , msgReceiveObj . MessageFileName , msgReceiveObj . MessageContent ,
ReceiveStatusEnum . Archived , msgReceiveObj . ReceiveTime , msgReceiveObj . LastUpdateTime , msgReceiveObj . Id , billType , billOnlineTime , billHostSN ) ;
var succObj = _ messageReceiveArchiveRepository . InsertAsync ( msgReceArv ) . GetAwaiter ( ) . GetResult ( ) ;
if ( succObj ! = null )
//更新车型
UpdateVehicleModel ( billResultObj ) ;
#region 更新SerialNumStr
if ( billResultObj . M100Bill ! = null )
{
_ messageReceiveRepository . DeleteAsync ( msgReceiveObj . Id ) . GetAwaiter ( ) . GetResult ( ) ;
var m100 = billResultObj . M100Bill ;
string snStr = ServerHelper . ToSerialNumStr ( m100 . OnlineTime , m100 . HostSN , "m100" , m100 . ProductLine ) ;
billResultObj . M100Bill . SetSerialNumStr ( snStr ) ;
}
else
if ( billResultObj . R100Bill ! = null )
{
throw new Exception ( "解析报文失败:" + msgReceiveObj . MessageFileName ) ;
var r100 = billResultObj . R100Bill ;
string snStr = ServerHelper . ToSerialNumStr ( r100 . OnlineTime , r100 . HostSN , "r100" , r100 . ProductLine ) ;
billResultObj . R100Bill . SetSerialNumStr ( snStr ) ;
}
}
#endregion
#endregion
//区分门板和柱护板
//DifferenceMenBan_ZhuHuBan(billResultObj);
//KNR前缀加两位年、预批量
UpdatePrebatch ( billResultObj ) ;
#region BOM解析
errorHeader = "文件解析" ;
DateTime ? billOnlineTime = null ;
int? billHostSN = null ;
bool isSucc = false ;
if ( billType = = "R100" )
{
var resu = _ r100CheckDomainSrv . DoCheckR100 ( msgReceiveObj , billResultObj . R100Bill ) ;
billOnlineTime = billResultObj . R100Bill . OnlineTime ;
billHostSN = billResultObj . R100Bill . HostSN ;
isSucc = resu . Status ;
}
else if ( billType = = "M100" )
{
var resu = _ m100CheckDomainService . DoCheckM100Bill ( msgReceiveObj , billResultObj . M100Bill ) ;
billOnlineTime = billResultObj . M100Bill . OnlineTime ;
billHostSN = billResultObj . M100Bill . HostSN ;
isSucc = resu . Status ;
}
if ( isSucc )
{
MessageReceiveArchive msgReceArv = new MessageReceiveArchive ( GuidGenerator . Create ( ) , msgReceiveObj . MessageFileName , msgReceiveObj . MessageContent ,
ReceiveStatusEnum . Archived , msgReceiveObj . ReceiveTime , msgReceiveObj . LastUpdateTime , msgReceiveObj . Id , billType , billOnlineTime , billHostSN ) ;
var succObj = _ messageReceiveArchiveRepository . InsertAsync ( msgReceArv ) . GetAwaiter ( ) . GetResult ( ) ;
if ( succObj ! = null )
{
_ messageReceiveRepository . DeleteAsync ( msgReceiveObj . Id ) . GetAwaiter ( ) . GetResult ( ) ;
}
else
{
throw new Exception ( "解析报文失败:" + msgReceiveObj . MessageFileName ) ;
}
}
#endregion
} //遍历多个成品件
}
catch ( Exception ex0 )
{
@ -627,6 +689,147 @@ namespace WY.NewJit.Job.ConsoleApp.Messages
}
}
/// <summary>
/// 根据 产线、分组,将一个报文拆分成若干R100或M100记录(更新主表:生产线,单据状态是已匹配)
/// </summary>
/// <param name="billResObj"></param>
/// <returns></returns>
private List < BillResult > SplitBillByGroup ( BillResult billResObj )
{
List < BillResult > billResultLst = new List < BillResult > ( ) ;
//按成品件拆分
if ( billResObj . R100Bill ! = null )
{
var r100Bill = billResObj . R100Bill ;
var billPartLst = billResObj . R100Bill . BillR100Parts ; //包含多个成品件
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 = BillR100 . Clone ( r100Bill ) ;
newBill . SetId ( GuidGenerator . Create ( ) ) ;
newBill . ProductLine = item . ProductLine ;
newBill . SetBillStatus ( BillStatusEnum . Match ) ;
newBill . BillR100Parts . Clear ( ) ;
newBill . BillR100Parts . AddRange ( item . PartList ) ;
billResultLst . Add ( new BillResult ( newBill , null ) ) ;
}
}
else if ( billResObj . M100Bill ! = null )
{
var m100bill = billResObj . M100Bill ;
var billPartLst = billResObj . M100Bill . BillM100Parts ; //包含多个成品件
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 = BillM100 . Clone ( m100bill ) ;
newBill . SetId ( GuidGenerator . Create ( ) ) ;
newBill . ProductLine = item . ProductLine ;
newBill . SetBillStatus ( BillStatusEnum . Match ) ;
newBill . BillM100Parts . Clear ( ) ;
newBill . BillM100Parts . AddRange ( item . PartList ) ;
billResultLst . Add ( new BillResult ( null , newBill ) ) ;
}
}
return billResultLst ;
}
/// <summary>
/// 更新R100或M100子表的三个零件类型(分别更新为产线,分组,零件大类)
/// </summary>
/// <param name="billResObj"></param>
/// <returns>存在没有识别的,返回该子件号</returns>
private string UpdatePartLargeType ( BillResult billResObj )
{
string ret = "" ;
if ( billResObj . R100Bill ! = null )
{
var billPartLst = billResObj . R100Bill . BillR100Parts ; //包含多个成品件
foreach ( var billPart in billPartLst )
{
string partLargeType = billPart . PartCode . Substring ( 6 , 3 ) ; //取客户零件代码的7-9位,是零件大类
var partCfgObj = _ partLargeTypeList . FirstOrDefault ( itm = > itm . LargeTypeCode = = partLargeType ) ; //是否加车型过滤//??
if ( partCfgObj ! = null )
{
billPart . PartType = partCfgObj . ProductLine ;
billPart . PartType2 = partCfgObj . Group ;
billPart . PartType3 = partCfgObj . LargeTypeCode ;
}
else
{
ret = billPart . PartCode ;
break ;
}
}
}
else if ( billResObj . M100Bill ! = null )
{
var billPartLst = billResObj . M100Bill . BillM100Parts ; //包含多个成品件
foreach ( var billPart in billPartLst )
{
string partLargeType = billPart . PartCode . Substring ( 6 , 3 ) ; //取客户零件代码的7-9位,是零件大类
var partCfgObj = _ partLargeTypeList . FirstOrDefault ( itm = > itm . LargeTypeCode = = partLargeType ) ; //是否加车型过滤//??
if ( partCfgObj ! = null )
{
billPart . PartType = partCfgObj . ProductLine ;
billPart . PartType2 = partCfgObj . Group ;
billPart . PartType3 = partCfgObj . LargeTypeCode ;
}
else
{
ret = billPart . PartCode ;
break ;
}
}
}
return ret ;
}
/// <summary>
/// 插入未知总成
/// </summary>
/// <param name="billResObj"></param>
/// <returns></returns>
//private bool InsertUnAssembly(BillResult billResObj)
//{
// if (billResObj.R100Bill != null)
// {
// var r100Bill = billResObj.R100Bill;
// r100Bill.SetAssemblyID(null);
// r100Bill.SetBillStatus(BillStatusEnum.NotMatch);
// var succObj1 = _billR100Repos.InsertAsync(r100Bill).GetAwaiter().GetResult();
// var succObj = _r100CheckDomainSrv.InsertUnknownAssembly(r100Bill);
// _logger.LogDebug(_errorMessagePrefix + $"部分零件不识别,进入未知总成:{r100Bill.KNR}-{r100Bill.HostSN}");
// }
// else if (billResObj.M100Bill != null)
// {
// var m100Bill = billResObj.M100Bill;
// m100Bill.SetAssemblyID(null);
// m100Bill.SetBillStatus(BillStatusEnum.NotMatch);
// var succObj1 = _billM100Repository.InsertAsync(m100Bill).GetAwaiter().GetResult();
// var succObj = _m100CheckDomainService.InsertUnknownAssembly(m100Bill);
// _logger.LogDebug(_errorMessagePrefix + $"部分零件不识别,进入未知总成:{m100Bill.VIN}-{m100Bill.HostSN}");
// }
// return true;
//}
/// <summary>
/// 校验报文(出错时返回)
/// </summary>
@ -845,91 +1048,91 @@ namespace WY.NewJit.Job.ConsoleApp.Messages
}
/// <summary>
/// 更新车型、生产线
/// 更新车型
/// </summary>
/// <param name="billResObj"></param>
private void UpdateProductLine ( BillResult billResObj )
private void UpdateVehicleModel ( BillResult billResObj )
{
if ( ConfigDic . CurrentVersion = = ConfigDicVersionOption . 派 格 )
if ( billResObj . R100Bill ! = null )
{
if ( billResObj . R100Bill ! = null )
var bill = billResObj . R100Bill ;
string ediVehicleModel = bill . VehicleModelCode ; //报文车型
//报文车型转换为零件生产工厂车型:3H 转 CC;FY 转 Q5
var obj1 = _ msgToPaiGeVehicleModelList . FirstOrDefault ( itm = > itm . DicItemCode = = ediVehicleModel ) ;
if ( obj1 ! = null )
{
var bill = billResObj . R100Bill ;
string ediVehicleModel = bill . VehicleModelCode ; //报文车型
//报文车型转换为零件生产工厂车型:3H 转 CC;FY 转 Q5
var obj1 = _ msgToPaiGeVehicleModelList . FirstOrDefault ( itm = > itm . DicItemCode = = ediVehicleModel ) ;
if ( obj1 ! = null )
string paigeVehicleModel = obj1 . DicItemName ; // CC
if ( paigeVehicleModel . Contains ( '-' ) ) //去掉B8L-PHEV中的-PHEV
{
string paigeVehicleModel = obj1 . DicItemName ; // CC
if ( paigeVehicleModel . Contains ( '-' ) ) //去掉B8L-PHEV中的-PHEV
{
paigeVehicleModel = paigeVehicleModel . Split ( '-' ) [ 0 ] ;
}
bill . SetVehicleModelCode ( paigeVehicleModel ) ;
//根据车型取对应生产线
var obj2 = _ r100VehicleModelProductLineList . FirstOrDefault ( itm = > itm . DicItemCode = = paigeVehicleModel ) ;
if ( obj2 ! = null )
{
string productLine = obj2 . DicItemName ;
bill . SetProductLine ( productLine ) ;
}
else
{
SetProductLineByExcept ( bill ) ;
string errorMsg = $"零件生产工厂车型{paigeVehicleModel}没有对应的生产线!" ;
//throw new Exception(errorMsg);
_l ogRemindDomainService . WriteLogRemind ( "报文格式转换" , errorMsg , LogTypeEnum . R100 ) ;
_l ogger . LogError ( errorMsg ) ;
}
}
else
{
SetProductLineByExcept ( bill ) ;
string errorMsg = $"报文车型{ediVehicleModel}没有对应的零件生产工厂车型!!KNR={bill.KNR}【不终止错误】" ;
//throw new Exception(errorMsg);
_l ogRemindDomainService . WriteLogRemind ( "报文格式转换" , errorMsg , LogTypeEnum . R100 ) ;
_l ogger . LogError ( errorMsg ) ;
paigeVehicleModel = paigeVehicleModel . Split ( '-' ) [ 0 ] ;
}
bill . SetVehicleModelCode ( paigeVehicleModel ) ;
//string partType2 = bill.BillR100Parts.Count > 0 ? bill.BillR100Parts[0].PartType2 : "";
////根据车型、产成品 取对应生产线
//var obj2 = _r100VehicleModelProductLineList.FirstOrDefault(itm => itm.DicItemCode == paigeVehicleModel && itm.DicItemSort1 == partType2);
//if (obj2 != null)
//{
// string productLine = obj2.DicItemName;
// bill.SetProductLine(productLine);
//}
//else
//{
// SetProductLineByExcept(bill);
// string errorMsg = $"零件生产工厂车型{paigeVehicleModel}和成品件{partType2}没有对应的生产线!";
// //throw new Exception(errorMsg);
// _logRemindDomainService.WriteLogRemind("报文格式转换", errorMsg, LogTypeEnum.R100);
// _logger.LogError(errorMsg);
//}
}
else if ( billResObj . M100Bill ! = null )
else
{
var bill = billResObj . M100Bill ;
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 ) ;
//根据车型取对应生产线
var obj2 = _ m100VehicleModelProductLineList . FirstOrDefault ( itm = > itm . DicItemCode = = paigeVehicleModel ) ;
if ( obj2 ! = null )
{
string productLine = obj2 . DicItemName ;
bill . SetProductLine ( productLine ) ;
}
else
{
SetProductLineByExcept ( bill ) ;
string errorMsg = $"零件生产工厂车型{paigeVehicleModel}没有对应的生产线!" ;
//throw new Exception(errorMsg);
_l ogRemindDomainService . WriteLogRemind ( "报文格式转换" , errorMsg , LogTypeEnum . M100 ) ;
_l ogger . LogError ( errorMsg ) ;
}
}
else //报文车型 没有对应的 格拉默车型
//SetProductLineByExcept(bill);
//string errorMsg = $"报文车型{ediVehicleModel}没有对应的零件生产工厂车型!!KNR={bill.KNR}【不终止错误】";
//_logRemindDomainService.WriteLogRemind("报文格式转换", errorMsg, LogTypeEnum.R100);
//_logger.LogError(errorMsg);
}
}
else if ( billResObj . M100Bill ! = null )
{
var bill = billResObj . M100Bill ;
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
{
SetProductLineByExcept ( bill ) ;
string errorMsg = $"报文车型{ediVehicleModel}没有对应的零件生产工厂车型!" ;
//throw new Exception(errorMsg);
_l ogRemindDomainService . WriteLogRemind ( "报文格式转换" , errorMsg , LogTypeEnum . M100 ) ;
_l ogger . LogError ( errorMsg ) ;
paigeVehicleModel = paigeVehicleModel . Split ( '-' ) [ 0 ] ;
}
bill . SetVehicleModelCode ( paigeVehicleModel ) ;
//string partType2 = bill.BillM100Parts.Count > 0 ? bill.BillM100Parts[0].PartType2 : "";
////根据车型、产成品 取对应生产线
//var obj2 = _m100VehicleModelProductLineList.FirstOrDefault(itm => itm.DicItemCode == paigeVehicleModel && itm.DicItemSort1 == partType2);
//if (obj2 != null)
//{
// string productLine = obj2.DicItemName;
// bill.SetProductLine(productLine);
//}
//else
//{
// SetProductLineByExcept(bill);
// string errorMsg = $"零件生产工厂车型{paigeVehicleModel}和成品件{partType2}没有对应的生产线!";
// //throw new Exception(errorMsg);
// _logRemindDomainService.WriteLogRemind("报文格式转换", errorMsg, LogTypeEnum.M100);
// _logger.LogError(errorMsg);
//}
}
else //报文车型 没有对应的 格拉默车型
{
//SetProductLineByExcept(bill);
//string errorMsg = $"报文车型{ediVehicleModel}没有对应的零件生产工厂车型!";
//_logRemindDomainService.WriteLogRemind("报文格式转换", errorMsg, LogTypeEnum.M100);
//_logger.LogError(errorMsg);
}
}
}
@ -956,79 +1159,79 @@ namespace WY.NewJit.Job.ConsoleApp.Messages
/// //区分门板和柱护板
/// </summary>
/// <param name="billResObj"></param>
private void DifferenceMenBan_ZhuHuBan ( BillResult billResObj )
{
//根据物料组区分门板、柱护板, 柱护板不参与匹配,但是参与发货
if ( ConfigDic . CurrentVersion = = ConfigDicVersionOption . 派 格 )
{
if ( billResObj . R100Bill ! = null )
{
if ( billResObj . R100Bill . VehicleModelCode = = "Q5" )
{
foreach ( BillR100Part billPart in billResObj . R100Bill . BillR100Parts )
{
PartCfg partObj = _ partCfgList . FirstOrDefault ( itm = > itm . PartCode = = billPart . PartCode ) ;
if ( partObj ! = null )
{
billPart . PartType = partObj . PartType ;
billPart . Description = partObj . PartType = = "2" ? "柱护板" : "控制件" ;
billPart . PartType2 = partObj . PartType2 ;
}
else
{
billPart . PartType = "1" ;
billPart . Description = "控制件" ;
string errorMsg = $"R100结算件{billPart.PartCode}在结算件信息表中不存在!KNR={billResObj.R100Bill.KNR}" ;
//throw new Exception(errorMsg); ////???? 此处需要优化,不触发异常,直接入库
_l ogRemindDomainService . WriteLogRemind ( "报文解析" , errorMsg , LogTypeEnum . R100 ) ;
_l ogger . LogError ( errorMsg ) ;
}
}
}
else //除Q5,其它车型没有柱护板
{
foreach ( BillR100Part partItm in billResObj . R100Bill . BillR100Parts )
{
partItm . PartType = "1" ;
partItm . Description = "控制件" ;
}
}
}
else if ( billResObj . M100Bill ! = null )
{
if ( billResObj . M100Bill . VehicleModelCode = = "Q5" )
{
foreach ( BillM100Part billPart in billResObj . M100Bill . BillM100Parts )
{
PartCfg partObj = _ partCfgList . FirstOrDefault ( itm = > itm . PartCode = = billPart . PartCode ) ;
if ( partObj ! = null )
{
billPart . PartType = partObj . PartType ;
billPart . Description = partObj . PartType = = "2" ? "柱护板" : "控制件" ;
billPart . PartType2 = partObj . PartType2 ;
}
else
{
billPart . PartType = "1" ;
billPart . Description = "控制件" ;
string errorMsg = $"M100结算件{billPart.PartCode}在结算件信息表中不存在!VIN={billResObj.M100Bill.VIN}" ;
_l ogRemindDomainService . WriteLogRemind ( "报文解析" , errorMsg , LogTypeEnum . M100 ) ;
_l ogger . LogError ( errorMsg ) ;
//throw new Exception(errorMsg);
}
}
}
else
{
foreach ( BillM100Part partItm in billResObj . M100Bill . BillM100Parts )
{
partItm . PartType = "1" ;
partItm . Description = "控制件" ;
}
}
}
}
}
//private void DifferenceMenBan_ZhuHuBan(BillResult billResObj)
//{
// //根据物料组区分门板、柱护板, 柱护板不参与匹配,但是参与发货
// if (ConfigDic.CurrentVersion == ConfigDicVersionOption.派格)
// {
// if (billResObj.R100Bill != null)
// {
// if (billResObj.R100Bill.VehicleModelCode == "Q5")
// {
// foreach (BillR100Part billPart in billResObj.R100Bill.BillR100Parts)
// {
// PartCfg partObj = _partCfgList.FirstOrDefault(itm = > itm.PartCode = = billPart.PartCode);
// if (partObj != null)
// {
// billPart.PartType = partObj.PartType;
// billPart.Description = partObj.PartType = = "2" ? "柱护板" : "控制件";
// billPart.PartType2 = partObj.PartType2;
// }
// else
// {
// billPart.PartType = "1";
// billPart.Description = "控制件";
// string errorMsg = $"R100结算件{billPart.PartCode}在结算件信息表中不存在!KNR={billResObj.R100Bill.KNR}";
// //throw new Exception(errorMsg); ////???? 此处需要优化,不触发异常,直接入库
// _logRemindDomainService.WriteLogRemind("报文解析", errorMsg, LogTypeEnum.R100);
// _logger.LogError(errorMsg);
// }
// }
// }
// else //除Q5,其它车型没有柱护板
// {
// foreach (BillR100Part partItm in billResObj.R100Bill.BillR100Parts)
// {
// partItm.PartType = "1";
// partItm.Description = "控制件";
// }
// }
// }
// else if (billResObj.M100Bill != null)
// {
// if (billResObj.M100Bill.VehicleModelCode == "Q5")
// {
// foreach (BillM100Part billPart in billResObj.M100Bill.BillM100Parts)
// {
// PartCfg partObj = _partCfgList.FirstOrDefault(itm = > itm.PartCode = = billPart.PartCode);
// if (partObj != null)
// {
// billPart.PartType = partObj.PartType;
// billPart.Description = partObj.PartType = = "2" ? "柱护板" : "控制件";
// billPart.PartType2 = partObj.PartType2;
// }
// else
// {
// billPart.PartType = "1";
// billPart.Description = "控制件";
// string errorMsg = $"M100结算件{billPart.PartCode}在结算件信息表中不存在!VIN={billResObj.M100Bill.VIN}";
// _logRemindDomainService.WriteLogRemind("报文解析", errorMsg, LogTypeEnum.M100);
// _logger.LogError(errorMsg);
// //throw new Exception(errorMsg);
// }
// }
// }
// else
// {
// foreach (BillM100Part partItm in billResObj.M100Bill.BillM100Parts)
// {
// partItm.PartType = "1";
// partItm.Description = "控制件";
// }
// }
// }
// }
//}
/// <summary>
/// KNR前缀加两位年、预批量
@ -1070,11 +1273,53 @@ namespace WY.NewJit.Job.ConsoleApp.Messages
#endregion
}
public class BillResult
{
public BillR100 R100Bill { get ; set ; }
public BillM100 M100Bill { get ; set ; }
public BillResult ( )
{
}
public BillResult ( BillR100 r100Bill , BillM100 m100Bill )
{
R100Bill = r100Bill ;
M100Bill = m100Bill ;
}
}
/// <summary>
/// 零件大类
/// </summary>
public class PartLargeType
{
/// <summary>
/// 零件大类
/// </summary>
public string LargeTypeCode { get ; set ; }
/// <summary>
/// 大类名称
/// </summary>
public string LargeTypeName { get ; set ; }
/// <summary>
/// 分组
/// </summary>
public string Group { get ; set ; }
/// <summary>
/// 产线
/// </summary>
public string ProductLine { get ; set ; }
/// <summary>
/// 车型
/// </summary>
public string VehicleModel { get ; set ; }
}