@ -1998,83 +1998,83 @@ select * from
/// </summary>
/// <param name="input"></param>
/// <returns>断号时Item不为空</returns>
[UnitOfWork(false)]
[HttpPost]
[Route("check-mb-hostsn-break-num")]
public virtual async Task < ListResultDto < string > > CheckMBHostSNBreakNum ( MenBanPrintInputDto input )
{
List < string > retLst = new List < string > ( ) ;
try
{
int lastNum = await GetMenBanLastPrintNum ( input ) ; //从M110中取当前产线、已经打印的最大大众顺序号
if ( lastNum > 0 )
{
if ( ( lastNum % 1 0 0 0 0 ) = = 1 9 9 9 )
{
if ( ( input . BeginHostSN % 1 0 0 0 0 ) ! = 1 )
{
string msg = $"单据之间断号,上次打印的最后大众顺序号为【{lastNum}】,与本次打印开始号【{input.BeginHostSN}】中间存在断号!" ;
retLst . Add ( msg ) ;
_l ogger . LogDebug ( msg ) ;
}
}
else
{
if ( lastNum + 1 ! = input . BeginHostSN )
{
string msg = $"单据之间断号,上次打印的最后大众顺序号为【{lastNum}】,与本次打印开始号【{input.BeginHostSN}】中间存在断号!" ;
retLst . Add ( msg ) ;
_l ogger . LogDebug ( msg ) ;
}
}
}
//[UnitOfWork(false)]
//[HttpPost]
//[Route("check-mb-hostsn-break-num")]
//public virtual async Task<ListResultDto<string>> CheckMBHostSNBreakNum(MenBanPrintInputDto input)
//{
// List<string> retLst = new List<string>();
// try
// {
// int lastNum = await GetMenBanLastPrintNum(input); //从M110中取当前产线、已经打印的最大大众顺序号
// if (lastNum > 0)
// {
// if ((lastNum % 10000) == 1999)
// {
// if ((input.BeginHostSN % 10000) != 1)
// {
// string msg = $"单据之间断号,上次打印的最后大众顺序号为【{lastNum}】,与本次打印开始号【{input.BeginHostSN}】中间存在断号!";
// retLst.Add(msg);
// _logger.LogDebug(msg);
// }
// }
// else
// {
// if (lastNum + 1 != input.BeginHostSN)
// {
// string msg = $"单据之间断号,上次打印的最后大众顺序号为【{lastNum}】,与本次打印开始号【{input.BeginHostSN}】中间存在断号!";
// retLst.Add(msg);
// _logger.LogDebug(msg);
// }
// }
// }
ListResultDto < BillM110 > tempLst = await GetMBReportDetailList ( input , false ) ;
List < BillM110 > billLst = tempLst . Item ;
if ( billLst . Count < 2 )
{
return new ListResultDto < string > ( retLst ) ;
}
for ( int i = 1 ; i < billLst . Count ; i + + )
{
BillM110 priorObj = billLst [ i - 1 ] ;
BillM110 curObj = billLst [ i ] ;
int priorHostSN = ( int ) billLst [ i - 1 ] . HostSN ;
int curHostSN = ( int ) billLst [ i ] . HostSN ;
// ListResultDto<BillM110> tempLst = await GetMBReportDetailList(input, false);
// List<BillM110> billLst = tempLst.Item;
// if (billLst.Count < 2)
// {
// return new ListResultDto<string>(retLst);
// }
// for (int i = 1; i < billLst.Count; i++)
// {
// BillM110 priorObj = billLst[i - 1];
// BillM110 curObj = billLst[i];
// int priorHostSN = (int)billLst[i - 1].HostSN;
// int curHostSN = (int)billLst[i].HostSN;
if ( curHostSN > priorHostSN ) //0005、0006
{
if ( curHostSN > priorHostSN + 1 ) //0005、0008时,补号 0006、0007
{
retLst . Add ( $"大众顺序号{priorObj.HostSN}与{curObj.HostSN}之间存在断号情况!" ) ;
}
}
else if ( curHostSN < priorHostSN ) //1999到0001的情况
{
if ( curHostSN + _ hostSNMaxVal > priorHostSN + 1 ) //0005、0008时,补号 0006、0007
{
retLst . Add ( $"大众顺序号{priorObj.HostSN}与{curObj.HostSN}之间存在断号情况!" ) ;
}
}
}
if ( retLst . Count = = 0 & & billLst . Count < input . EndHostSN - input . BeginHostSN + 1 )
{
retLst . Add ( $"本车装箱单不满架!" ) ;
}
// if (curHostSN > priorHostSN) //0005、0006
// {
// if (curHostSN > priorHostSN + 1) //0005、0008时,补号 0006、0007
// {
// retLst.Add($"大众顺序号{priorObj.HostSN}与{curObj.HostSN}之间存在断号情况!");
// }
// }
// else if (curHostSN < priorHostSN) //1999到0001的情况
// {
// if (curHostSN + _hostSNMaxVal > priorHostSN + 1) //0005、0008时,补号 0006、0007
// {
// retLst.Add($"大众顺序号{priorObj.HostSN}与{curObj.HostSN}之间存在断号情况!");
// }
// }
// }
// if (retLst.Count == 0 && billLst.Count < input.EndHostSN - input.BeginHostSN + 1)
// {
// retLst.Add($"本车装箱单不满架!");
// }
return new ListResultDto < string > ( retLst ) ;
}
catch ( Exception ex )
{
ListResultDto < string > ret = new ListResultDto < string > ( ) ;
ret . Status = false ;
ret . Message = _ errorMessagePrefix + "打印前检查大众顺序号是否断号ChecMBkHostSNBreakNum 执行出错:" + ex . Message ;
_l ogger . LogError ( ret . Message ) ;
return ret ;
}
// return new ListResultDto<string>(retLst);
// }
// catch (Exception ex)
// {
// ListResultDto<string> ret = new ListResultDto<string>();
// ret.Status = false;
// ret.Message = _errorMessagePrefix + "打印前检查大众顺序号是否断号ChecMBkHostSNBreakNum 执行出错:" + ex.Message;
// _logger.LogError(ret.Message);
// return ret;
// }
}
//}
/// <summary>
/// 打印前检查大众顺序号是否断号
@ -2154,72 +2154,72 @@ select * from
/// <param name="isZhuHuBan">柱护板是1 门板是非1</param>
/// <param name="groupName">柱护板分组类型</param>
/// <returns>起始大众顺序号</returns>
[UnitOfWork]
[HttpGet]
[Route("get-print-start-hostsn2")]
public virtual async Task < ObjectResultDto < int? > > GetPrintStartHostSN2 ( string productLine , string isZhuHuBan , string GroupName = null )
{
int? beginHostSN = null ;
try
{
if ( isZhuHuBan = = "1" ) //是柱护板, 根据PrintBillNum非空判断是柱护板
{
//string minSNStr = await _billM110Repository.Where(itm =>
// itm.ProductLine == productLine //指定生产线
// && itm.CanNotPrint != true //能打印
// && string.IsNullOrEmpty(itm.PrintBillNum) == true //等于 未打印
// && itm.NeedReplenishPrint != 1 //排除补打
// ).MinAsync(itm => itm.SerialNumStr);
string sql = @ "
with d as
(
select * from [ dbo ] . [ FisZHBPrintStatus ] where groupName = ' { 1 } '
)
select min ( SerialNumStr ) from FisBillM110 a left join d on a . VIN = d . VIN
// [UnitOfWork]
// [HttpGet]
// [Route("get-print-start-hostsn2")]
// public virtual async Task<ObjectResultDto<int?>> GetPrintStartHostSN2(string productLine, string isZhuHuBan,string GroupName=null)
// {
// int? beginHostSN = null;
// try
// {
// if (isZhuHuBan == "1") //是柱护板, 根据PrintBillNum非空判断是柱护板
// {
// //string minSNStr = await _billM110Repository.Where(itm =>
// // itm.ProductLine == productLine //指定生产线
// // && itm.CanNotPrint != true //能打印
// // && string.IsNullOrEmpty(itm.PrintBillNum) == true //等于 未打印
// // && itm.NeedReplenishPrint != 1 //排除补打
// // ).MinAsync(itm => itm.SerialNumStr);
// string sql = @"
//with d as
//(
// select *from [dbo].[FisZHBPrintStatus] where groupName='{1}'
//)
where ProductLine = ' { 0 } ' and ( CanNotPrint ! = 1 or CanNotPrint is null ) and ( PrintBillNum is null or PrintBillNum = ' ' ) and ( NeedReplenishPrint ! = 1 or NeedReplenishPrint is null ) and d . BillStatus is null ";
//select min(SerialNumStr) from FisBillM110 a left join d on a.VIN=d.VIN
sql = string . Format ( sql , productLine , GroupName ) ;
var minSNStr = await _ newJitDapperRepository . GetSingleBySqlAsync < string > ( sql ) ;
// where ProductLine='{0}' and (CanNotPrint !=1 or CanNotPrint is null) and (PrintBillNum is null or PrintBillNum ='') and (NeedReplenishPrint!=1 or NeedReplenishPrint is null) and d.BillStatus is null";
// sql = string.Format(sql, productLine, GroupName);
// var minSNStr = await _newJitDapperRepository.GetSingleBySqlAsync<string>(sql);
beginHostSN = await _ billM110Repository . Where ( itm = >
itm . ProductLine = = productLine //指定生产线
& & itm . CanNotPrint ! = true //能打印
& & string . IsNullOrEmpty ( itm . PrintBillNum ) = = true //等于 未打印
& & itm . SerialNumStr = = minSNStr
) . MinAsync ( itm = > itm . HostSN ) ;
}
else //---------------门板-----------------------------------------------------------------------------------
{
string minSNStr2 = await _ billM110Repository . Where ( itm = >
itm . ProductLine = = productLine //指定生产线
& & itm . CanNotPrint ! = true //能打印
//&& itm.BillStatus == BillStatusEnum.Match //等于 未打印(和M110上线信息匹配)
& & itm . BillStatus ! = BillStatusEnum . Publish //未知总成也显示在装箱单
& & itm . NeedReplenishPrint ! = 1 //排除补打
) . MinAsync ( itm = > itm . SerialNumStr ) ;
beginHostSN = await _ billM110Repository . Where ( itm = >
itm . ProductLine = = productLine //指定生产线
& & itm . CanNotPrint ! = true //能打印
//&& itm.BillStatus == BillStatusEnum.Match //等于 未打印
& & itm . BillStatus ! = BillStatusEnum . Publish //未知总成也显示在装箱单
& & itm . SerialNumStr = = minSNStr2
) . MinAsync ( itm = > itm . HostSN ) ;
}
return new ObjectResultDto < int? > ( beginHostSN ) ;
}
catch ( Exception ex )
{
ObjectResultDto < int? > ret = new ObjectResultDto < int? > ( ) ;
ret . Status = false ;
ret . Message = _ errorMessagePrefix + "GetPrintStartHostSN2 执行出错:" + ex . Message ;
_l ogger . LogError ( ret . Message ) ;
return ret ;
}
}
// beginHostSN = await _billM110Repository.Where(itm =>
// itm.ProductLine == productLine //指定生产线
// && itm.CanNotPrint != true //能打印
// && string.IsNullOrEmpty(itm.PrintBillNum) == true //等于 未打印
// && itm.SerialNumStr == minSNStr
// ).MinAsync(itm => itm.HostSN);
// }
// else //---------------门板-----------------------------------------------------------------------------------
// {
// string minSNStr2 = await _billM110Repository.Where(itm =>
// itm.ProductLine == productLine //指定生产线
// && itm.CanNotPrint != true //能打印
// //&& itm.BillStatus == BillStatusEnum.Match //等于 未打印(和M110上线信息匹配)
// && itm.BillStatus != BillStatusEnum.Publish //未知总成也显示在装箱单
// && itm.NeedReplenishPrint != 1 //排除补打
// ).MinAsync(itm => itm.SerialNumStr);
// beginHostSN = await _billM110Repository.Where(itm =>
// itm.ProductLine == productLine //指定生产线
// && itm.CanNotPrint != true //能打印
// //&& itm.BillStatus == BillStatusEnum.Match //等于 未打印
// && itm.BillStatus != BillStatusEnum.Publish //未知总成也显示在装箱单
// && itm.SerialNumStr == minSNStr2
// ).MinAsync(itm => itm.HostSN);
// }
// return new ObjectResultDto<int?>(beginHostSN);
// }
// catch (Exception ex)
// {
// ObjectResultDto<int?> ret = new ObjectResultDto<int?>();
// ret.Status = false;
// ret.Message = _errorMessagePrefix + "GetPrintStartHostSN2 执行出错:" + ex.Message;
// _logger.LogError(ret.Message);
// return ret;
// }
// }
/// <summary>
/// 打印门板装箱单
@ -3209,334 +3209,334 @@ select min(SerialNumStr) from FisBillM110 a left join d on a.VIN=d.VIN
/// </summary>
/// <param name="input">生产线编号列表</param>
/// <returns>生产线超时情况</returns>
[UnitOfWork]
[HttpPost]
[Route("product-line-timeout-remind")]
public virtual async Task < ListResultDto < TimeOutRemindResultDto > > ProductLineTimeoutRemind ( TimeOutRemindInputDto input )
{
List < TimeOutRemindResultDto > retLst = new List < TimeOutRemindResultDto > ( ) ;
foreach ( string plStr in input . ProductLineList )
{
TimeOutRemindResultDto retObj = new TimeOutRemindResultDto ( ) ;
retObj . ProductLine = plStr ;
retObj . ConfigMinutes = _ configuration [ $"ConfigDic:ProductLineTimeoutRemind:{plStr}" ] . TryToInt ( ) ? ? 3 0 ;
//[UnitOfWork]
//[HttpPost]
//[Route("product-line-timeout-remind")]
//public virtual async Task<ListResultDto<TimeOutRemindResultDto>> ProductLineTimeoutRemind(TimeOutRemindInputDto input)
//{
// List<TimeOutRemindResultDto> retLst = new List<TimeOutRemindResultDto>();
// foreach (string plStr in input.ProductLineList)
// {
// TimeOutRemindResultDto retObj = new TimeOutRemindResultDto();
// retObj.ProductLine = plStr;
// retObj.ConfigMinutes = _configuration[ $"ConfigDic:ProductLineTimeoutRemind:{plStr}"].TryToInt() ?? 30;
string maxSNStr = await _ billM110Repository . Where ( itm = > itm . ProductLine = = plStr ) . MaxAsync ( itm = > itm . SerialNumStr ) ;
BillM110 lastBill = await _ billM110Repository . FirstOrDefaultAsync ( itm = > itm . ProductLine = = plStr & & itm . SerialNumStr = = maxSNStr ) ;
if ( lastBill ! = null )
{
retObj . LastReceiveTime = lastBill . ReceiveTime ? ? ServerHelper . CurrentDateTime ;
retObj . TimeoutMinutes = MinuteDiff ( retObj . LastReceiveTime , ServerHelper . CurrentDateTime ) ;
}
retLst . Add ( retObj ) ;
}
return new ListResultDto < TimeOutRemindResultDto > ( retLst ) ;
}
// string maxSNStr = await _billM110Repository.Where(itm => itm.ProductLine == plStr).MaxAsync(itm => itm.SerialNumStr);
// BillM110 lastBill = await _billM110Repository.FirstOrDefaultAsync(itm => itm.ProductLine == plStr && itm.SerialNumStr == maxSNStr);
// if (lastBill != null)
// {
// retObj.LastReceiveTime = lastBill.ReceiveTime ?? ServerHelper.CurrentDateTime;
// retObj.TimeoutMinutes = MinuteDiff(retObj.LastReceiveTime, ServerHelper.CurrentDateTime);
// }
// retLst.Add(retObj);
// }
// return new ListResultDto<TimeOutRemindResultDto>(retLst);
//}
private int MinuteDiff ( DateTime beginTime , DateTime endTime )
{
TimeSpan beginSpan = new TimeSpan ( beginTime . Ticks ) ;
TimeSpan endSpan = new TimeSpan ( endTime . Ticks ) ;
TimeSpan diffSpan = endSpan . Subtract ( beginSpan ) . Duration ( ) ;
return ( int ) ( diffSpan . TotalMinutes ) ;
}
//private int MinuteDiff(DateTime beginTime, DateTime endTime)
//{
// TimeSpan beginSpan = new TimeSpan(beginTime.Ticks);
// TimeSpan endSpan = new TimeSpan(endTime.Ticks);
// TimeSpan diffSpan = endSpan.Subtract(beginSpan).Duration();
// return (int)(diffSpan.TotalMinutes);
//}
#endregion
#region 保存报表、加载打印报表分离
//[UnitOfWork]
[UnitOfWork(IsDisabled = true)]
[HttpPost]
[Route("save-menban-report")]
public virtual async Task < ObjectResultDto < List < Guid > > > SaveMenBanReport ( MenBanPrintInputDto input )
{
Stopwatch sw = new Stopwatch ( ) ;
//[UnitOfWork(IsDisabled = true)]
//[HttpPost]
//[Route("save-menban-report")]
//public virtual async Task<ObjectResultDto<List<Guid>>> SaveMenBanReport(MenBanPrintInputDto input)
//{
// Stopwatch sw = new Stopwatch();
_l ogger . LogDebug ( _ errorMessagePrefix + "SaveMenBanReport 进入" ) ;
// _logger.LogDebug(_errorMessagePrefix + "SaveMenBanReport 进入");
List < Guid > retLst = new List < Guid > ( ) ;
ObjectResultDto < List < Guid > > ret = new ObjectResultDto < List < Guid > > ( ) ;
ret . Status = false ;
// List<Guid> retLst = new List<Guid>();
// ObjectResultDto<List<Guid>> ret = new ObjectResultDto<List<Guid>>();
// ret.Status = false;
using ( var uow = _ unitOfWorkManager . Begin ( requiresNew : true , isTransactional : true , isolationLevel : System . Data . IsolationLevel . Unspecified ) )
{
try
{
List < MenBanPackingList > reportMainLst = new List < MenBanPackingList > ( ) ;
// using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: true, isolationLevel: System.Data.IsolationLevel.Unspecified))
// {
// try
// {
// List<MenBanPackingList> reportMainLst = new List<MenBanPackingList>();
if ( input . PrintType = = PrintTypeEnum . 正 常 打 印 )
{
if ( input . BeginHostSN ! = 0 & & input . EndHostSN ! = 0 )
{
if ( input . BeginHostSN > input . EndHostSN )
{
ret . Message = "止大众顺序号必须大于等于起大众顺序号!" ;
ret . Status = false ;
return ret ;
}
}
ListResultDto < BillM110 > tempLst = await GetMBReportDetailList ( input , true ) ; //-----------------------------
List < BillM110 > billLst = tempLst . Item ;
if ( tempLst . Status = = false )
{
ret . Message = tempLst . Message ;
ret . Status = false ;
return ret ;
}
// if (input.PrintType == PrintTypeEnum.正常打印)
// {
// if (input.BeginHostSN != 0 && input.EndHostSN != 0)
// {
// if (input.BeginHostSN > input.EndHostSN)
// {
// ret.Message = "止大众顺序号必须大于等于起大众顺序号!";
// ret.Status = false;
// return ret;
// }
// }
// ListResultDto<BillM110> tempLst = await GetMBReportDetailList(input, true); //-----------------------------
// List<BillM110> billLst = tempLst.Item;
// if (tempLst.Status = = false)
// {
// ret.Message = tempLst.Message;
// ret.Status = false;
// return ret;
// }
_l ogger . LogWarning ( $"SaveMenBanReport读取数据 - {sw.ElapsedMilliseconds}毫秒" ) ;
// _logger.LogWarning($"SaveMenBanReport读取数据 - {sw.ElapsedMilliseconds}毫秒");
int pageCnt = ( int ) Math . Ceiling ( billLst . Count / 1 2.0 ) ; //每页打印12列,取打印页数
// int pageCnt = (int)Math.Ceiling(billLst.Count / 12.0); //每页打印12列,取打印页数
//double maxBillNum = 0;
// //double maxBillNum = 0;
//DateTime printTime = ServerHelper.CurrentDateTime;
// //DateTime printTime = ServerHelper.CurrentDateTime;
var reportSortDic = _d icItemRepository
. Where ( itm = > itm . DicTypeCode = = "零件大类" & & itm . DicItemSort2 = = input . ProductLine )
. ToList ( )
. GroupBy ( itm = > itm . DicItemSort4 )
. ToDictionary ( itm = > itm . Key , it2 = > it2 . Select ( itm = > itm . DicItemCode ) . ToArray ( ) ) ;
// var reportSortDic = _dicItemRepository
// .Where(itm = > itm.DicTypeCode = = "零件大类" && itm.DicItemSort2 = = input.ProductLine)
// .ToList()
// .GroupBy(itm = > itm.DicItemSort4)
// .ToDictionary(itm = > itm.Key, it2 => it2.Select(itm = > itm.DicItemCode).ToArray());
for ( int pageIdx = 0 ; pageIdx < pageCnt ; pageIdx + + )
{
// for (int pageIdx = 0; pageIdx < pageCnt; pageIdx++)
// {
foreach ( var reportSortItem in reportSortDic )
{
//生成顺序号:按生产线分组,取当前生产线的最大流水号:001至999往复循环
double maxSN = await _l ineSNDomianService . GetMaxSN ( ProductTypeEnum . 门 板 , input . ProductLine , string . Empty ) ;
// foreach (var reportSortItem in reportSortDic)
// {
// //生成顺序号:按生产线分组,取当前生产线的最大流水号:001至999往复循环
// double maxSN = await _lineSNDomianService.GetMaxSN(ProductTypeEnum.门板, input.ProductLine, string.Empty);
MenBanPackingList packingObj = DoMBPrint ( input , pageIdx , maxSN , billLst , reportSortItem . Key , reportSortItem . Value ) ;
reportMainLst . Add ( packingObj ) ;
}
}
// MenBanPackingList packingObj = DoMBPrint(input, pageIdx, maxSN, billLst, reportSortItem.Key, reportSortItem.Value);
// reportMainLst.Add(packingObj);
// }
// }
_l ogger . LogWarning ( $"SaveMenBanReport转换数据 - {sw.ElapsedMilliseconds}毫秒" ) ;
// _logger.LogWarning($"SaveMenBanReport转换数据 - {sw.ElapsedMilliseconds}毫秒");
//插入门板打印记录表
await _ menBanPackingListRepository . InsertManyAsync ( reportMainLst , true ) ;
retLst . AddRange ( reportMainLst . Select ( itm = > itm . Id ) ) ;
// //插入门板打印记录表
// await _menBanPackingListRepository.InsertManyAsync(reportMainLst, true);
// retLst.AddRange(reportMainLst.Select(itm = > itm.Id));
_l ogger . LogWarning ( $"SaveMenBanReport插入门板打印记录表 - {sw.ElapsedMilliseconds}毫秒" ) ;
// _logger.LogWarning($"SaveMenBanReport插入门板打印记录表 - {sw.ElapsedMilliseconds}毫秒");
//调用派格版库存接口
//await SaveMiddleTable_MB(reportMainLst);
// //调用派格版库存接口
// //await SaveMiddleTable_MB(reportMainLst);
_l ogger . LogWarning ( $"SaveMenBanReport插入中间表 - {sw.ElapsedMilliseconds}毫秒" ) ;
// _logger.LogWarning($"SaveMenBanReport插入中间表 - {sw.ElapsedMilliseconds}毫秒");
//更新M110的门板打印标志:BillStatus=3
foreach ( BillM110 billObj in billLst )
{
if ( billObj . BillStatus = = BillStatusEnum . Match )
{
billObj . SetBillStatus ( BillStatusEnum . Publish ) ;
billObj . PrintTime = ServerHelper . CurrentDateTime ;
billObj . NeedReplenishPrint = 0 ; //不需要补打
await _ billM110Repository . UpdateAsync ( billObj , true ) ;
}
else if ( billObj . BillStatus = = BillStatusEnum . NotMatch )
{
//billObj.PrintTime = ServerHelper.CurrentDateTime;
billObj . NeedReplenishPrint = 1 ; //需要补打
await _ billM110Repository . UpdateAsync ( billObj , true ) ;
}
}
// //更新M110的门板打印标志:BillStatus=3
// foreach (BillM110 billObj in billLst)
// {
// if (billObj.BillStatus = = BillStatusEnum.Match)
// {
// billObj.SetBillStatus(BillStatusEnum.Publish);
// billObj.PrintTime = ServerHelper.CurrentDateTime;
// billObj.NeedReplenishPrint = 0; //不需要补打
// await _billM110Repository.UpdateAsync(billObj, true);
// }
// else if (billObj.BillStatus = = BillStatusEnum.NotMatch)
// {
// //billObj.PrintTime = ServerHelper.CurrentDateTime;
// billObj.NeedReplenishPrint = 1; //需要补打
// await _billM110Repository.UpdateAsync(billObj, true);
// }
// }
_l ogger . LogWarning ( $"SaveMenBanReport更新M110的门板打印标志 - {sw.ElapsedMilliseconds}毫秒" ) ;
// _logger.LogWarning($"SaveMenBanReport更新M110的门板打印标志 - {sw.ElapsedMilliseconds}毫秒");
}
//else if (input.PrintType == PrintTypeEnum.重新打印) //和正常打印单据完全一样,可以打印部分单据
//{
// throw new BusinessException("请调用LoadMenBanReport方法!");
//}
//else if (input.PrintType == PrintTypeEnum.补打)
//{
// List<BillM110> billLst = _billM110Repository.Where(itm => input.M110IdList.Contains(itm.Id)).OrderBy(itm => itm.SerialNumStr).ToList();
// if (billLst.Count == 0)
// }
// //else if (input.PrintType == PrintTypeEnum.重新打印) //和正常打印单据完全一样,可以打印部分单据
// //{
// // throw new BusinessException("请调用LoadMenBanReport方法!");
// //}
// //else if (input.PrintType == PrintTypeEnum.补打)
// //{
// // List<BillM110> billLst = _billM110Repository.Where(itm => input.M110IdList.Contains(itm.Id)).OrderBy(itm => itm.SerialNumStr).ToList();
// // if (billLst.Count == 0)
// // {
// // ret.Message = "没有补打的单据,请先选择要补打的单据!";
// // ret.Status = false;
// // return ret;
// // }
// // int pageCnt = (int)Math.Ceiling(billLst.Count / 12.0); //每页打印12列,取打印页数
// // double maxBillNum = 0;
// // DateTime printTime = ServerHelper.CurrentDateTime;
// // for (int pageIdx = 0; pageIdx < pageCnt; pageIdx++)
// // {
// // //取右上角顺序号:按生产线分组,取当前生产线的最大流水号:01至99循环,例如01左、01右
// // double maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.门板, input.ProductLine, string.Empty);
// // // 先打印两张:左后左前,再打印两张:右后右前
// // List<MenBanPackingList> leftLst = DoMBPrint(input, pageIdx, ref maxBillNum, maxSN, printTime, billLst, "左");
// // List<MenBanPackingList> rightLst = DoMBPrint(input, pageIdx, ref maxBillNum, maxSN, printTime, billLst, "右");
// // //作废时需要同时作废相同VIN的左右两页,SortId相同表示是同一组左右
// // Guid sortId = GuidGenerator.Create();
// // foreach (var leftItm in leftLst)
// // {
// // leftItm.SortId = sortId;
// // }
// // foreach (var rightItm in rightLst)
// // {
// // rightItm.SortId = sortId;
// // }
// // reportMainLst.AddRange(rightLst);
// // reportMainLst.AddRange(leftLst);
// // }
// // //校验底盘号、零件是否重复打印
// // string checkVinPartRepeatSql = @"
// // select top 1 a.BillNum from FisMenBanPackingList a join FisMenBanPackingRec b
// // on a.Id = b.MenBanPackingListId
// // where a.ReportStatus = 0
// // and b.VIN = '{0}' and (TopSAPMaterialNum = '{1}' or BelowSAPMaterialNum = '{1}')
// // ";
// // foreach (MenBanPackingList reportMainObj in reportMainLst)
// // {
// // foreach (MenBanPackingRec reportRecObj in reportMainObj.Details)
// // {
// // string sql1 = string.Format(checkVinPartRepeatSql, reportRecObj.VIN, reportRecObj.PartCode2);
// // string checkVinPartRepeatBillNum1 = _newJitDapperRepository.GetSingleBySql<string>(sql1, true);
// // if (string.IsNullOrEmpty(checkVinPartRepeatBillNum1) == false)
// // {
// // throw new BusinessException("1001", $"与装箱单号{checkVinPartRepeatBillNum1}中的底盘号{reportRecObj.VIN}、零件号{reportRecObj.PartCode2}之间重复!");
// // }
// // string sql2 = string.Format(checkVinPartRepeatSql, reportRecObj.VIN, reportRecObj.PartCode4);
// // string checkVinPartRepeatBillNum2 = _newJitDapperRepository.GetSingleBySql<string>(sql2, true);
// // if (string.IsNullOrEmpty(checkVinPartRepeatBillNum2) == false)
// // {
// // throw new BusinessException("1001", $"与装箱单号{checkVinPartRepeatBillNum2}中的底盘号{reportRecObj.VIN}、零件号{reportRecObj.PartCode4}之间重复!");
// // }
// // }
// // }
// // //调用派格版库存接口
// // await SaveMiddleTable_MB(reportMainLst);
// // //插入门板打印记录表
// // //await _menBanPackingListRepository.InsertManyAsync(reportMainLst);
// // foreach (var reportMainObj in reportMainLst)
// // {
// // var insObj = await _menBanPackingListRepository.InsertAsync(reportMainObj, true);
// // if (insObj != null)
// // {
// // retLst.Add(insObj.Id);
// // }
// // }
// // //更新M110的门板打印标志:BillStatus=3
// // foreach (BillM110 billObj in billLst)
// // {
// // if (billObj.BillStatus == BillStatusEnum.Match)
// // {
// // billObj.SetBillStatus(BillStatusEnum.Publish);
// // billObj.PrintTime = ServerHelper.CurrentDateTime;
// // await _billM110Repository.UpdateAsync(billObj);
// // }
// // }
// //} //补打if
// await uow.CompleteAsync();
// ret.Status = true;
// ret.Item = retLst;
// return ret;
// }
// catch (Exception ex)
// {
// ret.Message = "没有补打的单据,请先选择要补打的单据!";
// await uow.RollbackAsync();
// string errorMsg = _errorMessagePrefix + "SaveMenBanReport 执行出错:" + ex.Message;
// _logger.LogError(errorMsg);
// ret.Status = false;
// ret.Message = ex.Message;
// return ret;
// }
// } //事务
//}
// int pageCnt = (int)Math.Ceiling(billLst.Count / 12.0); //每页打印12列,取打印页数
// double maxBillNum = 0;
// DateTime printTime = ServerHelper.CurrentDateTime;
//[UnitOfWork]
//[HttpPost]
//[Route("load-menban-report")]
//public virtual async Task<List<MenBanPackingListDto>> LoadMenBanReport(List<Guid> input)
//{
// _logger.LogDebug(_errorMessagePrefix + "LoadMenBanReport 进入");
// for (int pageIdx = 0; pageIdx < pageCnt; pageIdx++)
// try
// {
// //取右上角顺序号:按生产线分组,取当前生产线的最大流水号:01至99循环,例如01左、01右
// double maxSN = 0; // await _lineSNDomianService.GetMaxSN(ProductTypeEnum.门板, input.ProductLine, string.Empty);
// // 先打印两张:左后左前,再打印两张:右后右前
// List<MenBanPackingList> leftLst = DoMBPrint(input, pageIdx, ref maxBillNum, maxSN, printTime, billLst, "左");
// List<MenBanPackingList> rightLst = DoMBPrint(input, pageIdx, ref maxBillNum, maxSN, printTime, billLst, "右");
// List<MenBanPackingList> reportMainLst = new List<MenBanPackingList>();
// //作废时需要同时作废相同VIN的左右两页,SortId相同表示是同一组左右
// Guid sortId = GuidGenerator.Create();
// foreach (var leftItm in leftLst)
// {
// leftItm.SortId = sortId;
// }
// foreach (var rightItm in rightLst)
// reportMainLst = await _menBanPackingListRepository.GetListAsync(itm => input.Contains(itm.Id) == true, true);
// //按大众顺序号排序
// foreach (var reportMainObj in reportMainLst)
// {
// rightItm.SortId = sortId;
// }
// List<MenBanPackingRec> recLst = reportMainObj.Details;
// if (recLst == null)
// continue;
// reportMainLst.AddRange(rightLst);
// reportMainLst.AddRange(leftLst);
// }
// //校验底盘号、零件是否重复打印
// string checkVinPartRepeatSql = @"
// select top 1 a.BillNum from FisMenBanPackingList a join FisMenBanPackingRec b
// on a.Id = b.MenBanPackingListId
// where a.ReportStatus = 0
// and b.VIN = '{0}' and (TopSAPMaterialNum = '{1}' or BelowSAPMaterialNum = '{1}')
// ";
// foreach (MenBanPackingList reportMainObj in reportMainLst)
// {
// foreach (MenBanPackingRec reportRecObj in reportMainObj.Details)
// {
// string sql1 = string.Format(checkVinPartRepeatSql, reportRecObj.VIN, reportRecObj.PartCode2);
// string checkVinPartRepeatBillNum1 = _newJitDapperRepository.GetSingleBySql<string>(sql1, true);
// if (string.IsNullOrEmpty(checkVinPartRepeatBillNum1) == false)
// bool has1999 = recLst.Any(itm => itm.HostSN.Contains("1999") || itm.HostSN.Contains("1998") || itm.HostSN.Contains("1997")
// || itm.HostSN.Contains("1996") || itm.HostSN.Contains("1995") || itm.HostSN.Contains("1994")
// || itm.HostSN.Contains("1993") || itm.HostSN.Contains("1992") || itm.HostSN.Contains("1991")
// || itm.HostSN.Contains("1990") || itm.HostSN.Contains("1989") || itm.HostSN.Contains("1988")
// || itm.HostSN.Contains("1987") || itm.HostSN.Contains("1986") || itm.HostSN.Contains("1985")
// || itm.HostSN.Contains("1984") || itm.HostSN.Contains("1983") || itm.HostSN.Contains("1982")
// || itm.HostSN.Contains("1981") || itm.HostSN.Contains("1980") || itm.HostSN.Contains("1979")
// || itm.HostSN.Contains("1978") || itm.HostSN.Contains("1977") || itm.HostSN.Contains("1976")
// );
// bool has0001 = recLst.Any(itm => itm.HostSN.Contains("0001") || itm.HostSN.Contains("0002") || itm.HostSN.Contains("0003")
// || itm.HostSN.Contains("0004") || itm.HostSN.Contains("0005") || itm.HostSN.Contains("0006")
// || itm.HostSN.Contains("0007") || itm.HostSN.Contains("0008") || itm.HostSN.Contains("0009")
// || itm.HostSN.Contains("0010") || itm.HostSN.Contains("0011") || itm.HostSN.Contains("0012")
// || itm.HostSN.Contains("0013") || itm.HostSN.Contains("0014") || itm.HostSN.Contains("0015")
// || itm.HostSN.Contains("0016") || itm.HostSN.Contains("0017") || itm.HostSN.Contains("0018")
// || itm.HostSN.Contains("0019") || itm.HostSN.Contains("0020") || itm.HostSN.Contains("0021")
// || itm.HostSN.Contains("0022") || itm.HostSN.Contains("0023") || itm.HostSN.Contains("0024")
// );
// if (has1999 && has0001)
// {
// throw new BusinessException("1001", $"与装箱单号{checkVinPartRepeatBillNum1}中的底盘号{reportRecObj.VIN}、零件号{reportRecObj.PartCode2}之间重复!");
// reportMainObj.Details = recLst.OrderBy(itm => (itm.HostSN.TryToIntZero() % 10000) < 240 ? (itm.HostSN.TryToIntZero() % 10000 + 1999) : (itm.HostSN.TryToIntZero() % 10000)).ToList( );
// }
// string sql2 = string.Format(checkVinPartRepeatSql, reportRecObj.VIN, reportRecObj.PartCode4);
// string checkVinPartRepeatBillNum2 = _newJitDapperRepository.GetSingleBySql<string>(sql2, true);
// if (string.IsNullOrEmpty(checkVinPartRepeatBillNum2) == false)
// else
// {
// throw new BusinessException("1001", $"与装箱单号{checkVinPartRepeatBillNum2}中的底盘号{reportRecObj.VIN}、零件号{reportRecObj.PartCode4}之间重复!");
// }
// reportMainObj.Details = recLst.OrderBy(itm => itm.HostSN).ToList();
// }
// }
// //调用派格版库存接口
// await SaveMiddleTable_MB(reportMainLst);
// #region 格式转换
// //实体 转 DTO
// List<MenBanPackingListDto> targetLst = ObjectMapper.Map<List<MenBanPackingList>, List<MenBanPackingListDto>>(reportMainLst);
// targetLst = targetLst.OrderBy(itm => itm.BillNum).ToList();
// //插入门板打印记录表
// //await _menBanPackingListRepository.InsertManyAsync(reportMainLst);
// foreach (var reportMainObj in reportMainLst)
// //子表BillNum赋值, BillNum填充空格
// foreach (var masterObj in targetLst)
// {
// var insObj = await _menBanPackingListRepository.InsertAsync(reportMainObj, true);
// if (insObj != null)
// masterObj.BillNum = GetTrueString(masterObj.BillNum);
// int sn = 1;
// foreach (var detailObj in masterObj.Details)
// {
// retLst.Add(insObj.Id);
// detailObj.BillNum = masterObj.BillNum;
// detailObj.KNR = GetTrueString(detailObj.KNR);
// detailObj.SN = (sn++).ToString();
// detailObj.VIN = detailObj.VIN.TryToRight(6); //底盘号返回后六位
// }
// }
// //更新M110的门板打印标志:BillStatus=3
// foreach (BillM110 billObj in billLst)
// {
// if (billObj.BillStatus == BillStatusEnum.Match)
// {
// billObj.SetBillStatus(BillStatusEnum.Publish);
// billObj.PrintTime = ServerHelper.CurrentDateTime;
// await _billM110Repository.UpdateAsync(billObj);
// #endregion
// return targetLst;
// }
// catch (Exception ex)
// {
// string errorMsg = _errorMessagePrefix + "LoadMenBanReport 执行出错:" + ex.Message;
// _logger.LogError(errorMsg);
// throw new UserFriendlyException(errorMsg);
// }
//} //补打if
await uow . CompleteAsync ( ) ;
ret . Status = true ;
ret . Item = retLst ;
return ret ;
}
catch ( Exception ex )
{
await uow . RollbackAsync ( ) ;
string errorMsg = _ errorMessagePrefix + "SaveMenBanReport 执行出错:" + ex . Message ;
_l ogger . LogError ( errorMsg ) ;
ret . Status = false ;
ret . Message = ex . Message ;
return ret ;
}
} //事务
}
[UnitOfWork]
[HttpPost]
[Route("load-menban-report")]
public virtual async Task < List < MenBanPackingListDto > > LoadMenBanReport ( List < Guid > input )
{
_l ogger . LogDebug ( _ errorMessagePrefix + "LoadMenBanReport 进入" ) ;
try
{
List < MenBanPackingList > reportMainLst = new List < MenBanPackingList > ( ) ;
reportMainLst = await _ menBanPackingListRepository . GetListAsync ( itm = > input . Contains ( itm . Id ) = = true , true ) ;
//按大众顺序号排序
foreach ( var reportMainObj in reportMainLst )
{
List < MenBanPackingRec > recLst = reportMainObj . Details ;
if ( recLst = = null )
continue ;
bool has1999 = recLst . Any ( itm = > itm . HostSN . Contains ( "1999" ) | | itm . HostSN . Contains ( "1998" ) | | itm . HostSN . Contains ( "1997" )
| | itm . HostSN . Contains ( "1996" ) | | itm . HostSN . Contains ( "1995" ) | | itm . HostSN . Contains ( "1994" )
| | itm . HostSN . Contains ( "1993" ) | | itm . HostSN . Contains ( "1992" ) | | itm . HostSN . Contains ( "1991" )
| | itm . HostSN . Contains ( "1990" ) | | itm . HostSN . Contains ( "1989" ) | | itm . HostSN . Contains ( "1988" )
| | itm . HostSN . Contains ( "1987" ) | | itm . HostSN . Contains ( "1986" ) | | itm . HostSN . Contains ( "1985" )
| | itm . HostSN . Contains ( "1984" ) | | itm . HostSN . Contains ( "1983" ) | | itm . HostSN . Contains ( "1982" )
| | itm . HostSN . Contains ( "1981" ) | | itm . HostSN . Contains ( "1980" ) | | itm . HostSN . Contains ( "1979" )
| | itm . HostSN . Contains ( "1978" ) | | itm . HostSN . Contains ( "1977" ) | | itm . HostSN . Contains ( "1976" )
) ;
bool has0001 = recLst . Any ( itm = > itm . HostSN . Contains ( "0001" ) | | itm . HostSN . Contains ( "0002" ) | | itm . HostSN . Contains ( "0003" )
| | itm . HostSN . Contains ( "0004" ) | | itm . HostSN . Contains ( "0005" ) | | itm . HostSN . Contains ( "0006" )
| | itm . HostSN . Contains ( "0007" ) | | itm . HostSN . Contains ( "0008" ) | | itm . HostSN . Contains ( "0009" )
| | itm . HostSN . Contains ( "0010" ) | | itm . HostSN . Contains ( "0011" ) | | itm . HostSN . Contains ( "0012" )
| | itm . HostSN . Contains ( "0013" ) | | itm . HostSN . Contains ( "0014" ) | | itm . HostSN . Contains ( "0015" )
| | itm . HostSN . Contains ( "0016" ) | | itm . HostSN . Contains ( "0017" ) | | itm . HostSN . Contains ( "0018" )
| | itm . HostSN . Contains ( "0019" ) | | itm . HostSN . Contains ( "0020" ) | | itm . HostSN . Contains ( "0021" )
| | itm . HostSN . Contains ( "0022" ) | | itm . HostSN . Contains ( "0023" ) | | itm . HostSN . Contains ( "0024" )
) ;
if ( has1999 & & has0001 )
{
reportMainObj . Details = recLst . OrderBy ( itm = > ( itm . HostSN . TryToIntZero ( ) % 1 0 0 0 0 ) < 2 4 0 ? ( itm . HostSN . TryToIntZero ( ) % 1 0 0 0 0 + 1 9 9 9 ) : ( itm . HostSN . TryToIntZero ( ) % 1 0 0 0 0 ) ) . ToList ( ) ;
}
else
{
reportMainObj . Details = recLst . OrderBy ( itm = > itm . HostSN ) . ToList ( ) ;
}
}
#region 格式转换
//实体 转 DTO
List < MenBanPackingListDto > targetLst = ObjectMapper . Map < List < MenBanPackingList > , List < MenBanPackingListDto > > ( reportMainLst ) ;
targetLst = targetLst . OrderBy ( itm = > itm . BillNum ) . ToList ( ) ;
//子表BillNum赋值, BillNum填充空格
foreach ( var masterObj in targetLst )
{
masterObj . BillNum = GetTrueString ( masterObj . BillNum ) ;
int sn = 1 ;
foreach ( var detailObj in masterObj . Details )
{
detailObj . BillNum = masterObj . BillNum ;
detailObj . KNR = GetTrueString ( detailObj . KNR ) ;
detailObj . SN = ( sn + + ) . ToString ( ) ;
detailObj . VIN = detailObj . VIN . TryToRight ( 6 ) ; //底盘号返回后六位
}
}
#endregion
return targetLst ;
}
catch ( Exception ex )
{
string errorMsg = _ errorMessagePrefix + "LoadMenBanReport 执行出错:" + ex . Message ;
_l ogger . LogError ( errorMsg ) ;
throw new UserFriendlyException ( errorMsg ) ;
}
}
//}
private static string GetTrueString ( string str )
{
return str = = null ? " " : str . Trim ( ) ; ;
}
//private static string GetTrueString(string str)
//{
// return str == null ? " " : str.Trim(); ;
//}
/// <summary>
/// 打印柱护板装箱单