@ -1128,15 +1128,14 @@ select * from
/// 将M100转换成MenBanPackingList主子表
/// </summary>
/// <param name="input"></param>
/// <param name="pageIdx"></param>
/// <param name="maxSN"></param>
/// <param name="billLst"></param>
/// <param name="maxSN">最大顺序号加一</param>
/// <param name="pageBillLst">当前页的记录</param>
/// <param name="reportSort">报表分类,对应DicItemSort4</param>
/// <param name="partLargeTypeLst">零件大类字典项</param>
/// <param name="partLargeTypeLst">零件大类字典项(已经排序)</param>
/// <param name="sortId">本次打印的sortId相同</param>
/// <returns></returns>
private MenBanPackingList DoMBPrint ( MenBanPrintInputDto input , int pageIdx , double maxSN , List < BillM100 > b illLst, string reportSort , List < DicItem > partLargeTypeLst , Guid sortId )
private MenBanPackingList DoMBPrint ( MenBanPrintInputDto input , double maxSN , List < BillM100 > pageB illLst, string reportSort , List < DicItem > partLargeTypeLst , Guid sortId )
{
const int _ colNumberPerPage = 1 2 ; //??临时的,等
var partLargeTypeObj = partLargeTypeLst . FirstOrDefault ( itm = > itm . DicItemCode = = reportSort ) ;
if ( partLargeTypeObj = = null )
{
@ -1150,10 +1149,6 @@ select * from
{
idx = 0 ;
}
//取当前页内容
List < BillM100 > curPageLst = billLst . Skip ( pageIdx * _ colNumberPerPage ) . Take ( _ colNumberPerPage ) . ToList ( ) ;
//var vmLst = curPageLst.Select(itm => itm.VehicleModelCode).Distinct().JoinAsString(","); //取车型
string ymd = ServerHelper . CurrentDateTime . ToString ( "yyyyMMdd" ) ;
string serialNum = maxSN . ToString ( ) . PadLeft ( 3 , '0' ) ; //075
@ -1167,10 +1162,10 @@ select * from
packingMain . VehicleModel_Disp = partLargeTypeObj . DicItemSort6 ; //车型(报表显示的)
packingMain . PrintDate = ServerHelper . CurrentDateTime ;
packingMain . PartType = partLargeTypeObj . DicItemCode ; //零件大类
packingMain . ProductLine = b illLst[ 0 ] . ProductLine ;
packingMain . ProductLine = pageB illLst[ 0 ] . ProductLine ;
packingMain . SortId = sortId ;
var tempLst = curPage Lst. Where ( itm = > string . IsNullOrEmpty ( itm . VIN ) = = false ) . OrderBy ( itm = > itm . OnlineTime ) . ThenBy ( itm = > itm . HostSN ) . ToList ( ) ;
var tempLst = pageBill Lst. Where ( itm = > string . IsNullOrEmpty ( itm . VIN ) = = false ) . OrderBy ( itm = > itm . OnlineTime ) . ThenBy ( itm = > itm . HostSN ) . ToList ( ) ;
if ( tempLst . Count > 0 )
{
packingMain . BeginVin = tempLst [ 0 ] . VIN ;
@ -1181,7 +1176,7 @@ select * from
packingMain . MinOnlineTime = tempLst . Min ( itm = > itm . OnlineTime ) ; //本单据最早的上线时间
//明细
int sn = 1 ;
foreach ( BillM100 billObj in curPage Lst)
foreach ( BillM100 billObj in pageBill Lst)
{
MenBanPackingRec packingDetail = new MenBanPackingRec ( ) ;
packingDetail . SetId ( GuidGenerator . Create ( ) ) ;
@ -2407,10 +2402,51 @@ select * from
}
}
}
//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 ;
}
}
[UnitOfWork(false)]
[HttpPost]
[Route("check-already-print")]
public virtual async Task < ListResultDto < string > > CheckAlreadyPrint ( MenBanPrintInputDto input )
{
List < string > retLst = new List < string > ( ) ;
try
{
ListResultDto < BillM100 > tempLst = await GetMBReportDetailList ( input , false ) ;
List < BillM100 > billLst = tempLst . Item ;
if ( retLst . Count = = 0 & & billLst . Count < input . EndHostSN - input . BeginHostSN + 1 )
{
retLst . Add ( $"本车装箱单不满架!" ) ;
}
var m100Obj = billLst [ 0 ] ;
if ( m100Obj . PrintBillNum . HasValue ( ) )
{
var alreadyPrintLst = billLst . Where ( itm = > string . IsNullOrEmpty ( itm . PrintBillNum ) = = false ) . ToList ( ) ;
var sortId = await GetPackingListByM100Id ( input . ProductLine , m100Obj . Id ) ;
if ( sortId ! = null )
{
var allMBLst = await _ menBanPackingListRepository . GetListAsync ( itm = > itm . SortId = = sortId ) ;
string billNumStr = allMBLst . OrderBy ( itm = > itm . BillNum ) . JoinAsString ( "," ) ;
retLst . Add ( $"从{alreadyPrintLst[0].HostSN}到{alreadyPrintLst[alreadyPrintLst.Count - 1].HostSN}的大众顺序号已经打印,打印对应的单号是{billNumStr}" ) ;
}
}
return new ListResultDto < string > ( retLst ) ;
}
@ -2418,12 +2454,26 @@ select * from
{
ListResultDto < string > ret = new ListResultDto < string > ( ) ;
ret . Status = false ;
ret . Message = _ errorMessagePrefix + "打印前检查大众顺序号是否断号ChecMBkHostSNBreakNum 执行出错:" + ex . Message ;
ret . Message = _ errorMessagePrefix + "CheckIsAlreadyPrint 执行出错:" + ex . Message ;
_l ogger . LogError ( ret . Message ) ;
return ret ;
}
}
/// <summary>
/// 根据M100的Id取打印主表
/// </summary>
/// <param name="m100Id"></param>
/// <returns></returns>
private async Task < Guid ? > GetPackingListByM100Id ( string productLine , Guid m100Id , bool isTrans = false )
{
string sql = $ @ "
select top 1 SortId from FisMenBanPackingList where ProductLine = ' { productLine } '
and Id in ( select MenBanPackingListId from FisMenBanPackingRec where M100BillId = ' { m100Id } ' )
";
var sortIdLst = await _ newJitDapperRepository . GetListBySqlAsync < Guid ? > ( sql , isTrans ) ;
return sortIdLst . Count > 0 ? sortIdLst [ 0 ] : null ;
}
/// <summary>
/// 打印前检查大众顺序号是否断号
@ -2511,36 +2561,36 @@ select * from
int? beginHostSN = null ;
try
{
if ( isZhuHuBan = = "1" ) //是柱护板, 根据PrintBillNum非空判断是柱护板
{
//string minSNStr = await _billM100Repository.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 } '
)
// if (isZhuHuBan = = "1") //是柱护板, 根据PrintBillNum非空判断是柱护板
// {
// //string minSNStr = await _billM100Repository.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 FisBillM100 a left join d on a . VIN = d . VIN
//select min(SerialNumStr) from FisBillM100 a left join d on a.VIN=d.VIN
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 ";
// 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 ) ;
// sql = string.Format(sql, productLine, GroupName);
// var minSNStr = await _newJitDapperRepository.GetSingleBySqlAsync<string>(sql);
beginHostSN = await _ billM100Repository . Where ( itm = >
itm . ProductLine = = productLine //指定生产线
& & itm . CanNotPrint ! = true //能打印
& & string . IsNullOrEmpty ( itm . PrintBillNum ) = = true //等于 未打印
& & itm . SerialNumStr = = minSNStr
) . MinAsync ( itm = > itm . HostSN ) ;
}
else //---------------门板-----------------------------------------------------------------------------------
// beginHostSN = await _billM100Repository.Where(itm = >
// itm.ProductLine = = productLine //指定生产线
// && itm.CanNotPrint != true //能打印
// && string.IsNullOrEmpty(itm.PrintBillNum) = = true //等于 未打印
// && itm.SerialNumStr = = minSNStr
// ).MinAsync(itm = > itm.HostSN);
// }
// else //---------------门板-----------------------------------------------------------------------------------
{
string minSNStr2 = await _ billM100Repository . Where ( itm = >
itm . ProductLine = = productLine //指定生产线
@ -3705,12 +3755,6 @@ select min(SerialNumStr) from FisBillM100 a left join d on a.VIN=d.VIN
ret . Status = false ;
return ret ;
}
//_logger.LogWarning($"SaveMenBanReport读取数据 - {sw.ElapsedMilliseconds}毫秒");
int pageCnt = ( int ) Math . Ceiling ( billLst . Count / 1 2.0 ) ; //每页打印12列,取打印页数
//过滤产线(DicItemSort2),按“报表分类”(DicItemSort4)分组,分组后按DicItemSort7排序
Dictionary < string , List < DicItem > > reportSortDic = partLargeTypeLst
. Where ( itm = > itm . DicItemSort2 = = input . ProductLine & & string . IsNullOrEmpty ( itm . DicItemSort4 ) = = false )
@ -3719,41 +3763,36 @@ select min(SerialNumStr) from FisBillM100 a left join d on a.VIN=d.VIN
Guid sortId = GuidGenerator . Create ( ) ; //每次打印所有记录的SortId是相同的
for ( int pageIdx = 0 ; pageIdx < pageCnt ; pageIdx + + )
foreach ( var reportSortItem in reportSortDic ) //先按分组(01产线有C8扶手、C8头枕两个分组)、然后按分页
{
foreach ( var reportSortItem in reportSortDic )
DicItem dicItem = reportSortItem . Value [ 0 ] ;
int pageSize = dicItem . DicItemSort9 . TryToInt ( ) ? ? 2 4 ; //每页记录数
int pageCount = ( int ) Math . Ceiling ( billLst . Count / ( decimal ) pageSize ) ; //页数
for ( int pageIdx = 0 ; pageIdx < pageCount ; pageIdx + + )
{
//生成顺序号:按生产线分组,取当前生产线的最大流水号:001至999往复循环
double maxSN = await _l ineSNDomianService . GetMaxSN ( ProductTypeEnum . 门 板 , input . ProductLine , string . Empty ) ;
double maxSN = await _l ineSNDomianService . GetMaxSN ( ProductTypeEnum . 门 板 , input . ProductLine , reportSortItem . Key ) ;
//取当前页内容
List < BillM100 > pageBillLst = billLst . Skip ( pageIdx * pageSize ) . Take ( pageSize ) . ToList ( ) ;
MenBanPackingList packingObj = DoMBPrint ( input , pageIdx , maxSN , billLst , reportSortItem . Key , reportSortItem . Value , sortId ) ;
MenBanPackingList packingObj = DoMBPrint ( input , maxSN , pageB illLst, reportSortItem . Key , reportSortItem . Value , sortId ) ;
reportMainLst . Add ( packingObj ) ;
}
}
//_logger.LogWarning($"SaveMenBanReport转换数据 - {sw.ElapsedMilliseconds}毫秒");
//插入门板打印记录表
await _ menBanPackingListRepository . InsertManyAsync ( reportMainLst , true ) ;
retLst . AddRange ( reportMainLst . Select ( itm = > itm . Id ) ) ;
//_logger.LogWarning($"SaveMenBanReport插入门板打印记录表 - {sw.ElapsedMilliseconds}毫秒");
//调用派格版库存接口
//await SaveMiddleTable_MB(reportMainLst);
//_logger.LogWarning($"SaveMenBanReport插入中间表 - {sw.ElapsedMilliseconds}毫秒");
//更新M100的门板打印标志:BillStatus=3
foreach ( BillM100 billObj in billLst )
{
if ( billObj . BillStatus = = BillStatusEnum . Match )
{
billObj . SetBillStatus ( BillStatusEnum . Publish ) ;
//billObj.SetBillStatus(BillStatusEnum.Publish);
billObj . PrintTime = ServerHelper . CurrentDateTime ;
billObj . PrintBillNum = "已打印" ;
billObj . NeedReplenishPrint = 0 ; //不需要补打
await _ billM100Repository . UpdateAsync ( billObj , true ) ;
}
@ -3764,17 +3803,27 @@ select min(SerialNumStr) from FisBillM100 a left join d on a.VIN=d.VIN
// await _billM100Repository.UpdateAsync(billObj, true);
//}
}
//_logger.LogWarning($"SaveMenBanReport更新M100的门板打印标志 - {sw.ElapsedMilliseconds}毫秒");
//4.校验1 - 4张单据都没有扫描提交,可以重复打印1 - 4张单据,或者打印1 - 5,
//5.重复打印后,原单据作废,原单据即使扫描也无法提交
var m100Id = billLst [ 0 ] . Id ;
var sortId2 = await GetPackingListByM100Id ( input . ProductLine , m100Id , true ) ;
if ( sortId2 ! = null )
{
var allMBLst = await _ menBanPackingListRepository . GetListAsync ( itm = > itm . SortId = = sortId2 ) ;
foreach ( var mbObj in allMBLst )
{
mbObj . IsScrap = true ;
}
await _ menBanPackingListRepository . UpdateManyAsync ( allMBLst ) ;
}
} //if 正常打印
//else if (input.PrintType == PrintTypeEnum.重新打印) //和正常打印单据完全一样,可以打印部分单据
//{
// throw new BusinessException("请调用LoadMenBanReport方法!");
//}
await uow . CompleteAsync ( ) ;
ret . Status = true ;
ret . Item = retLst ;
ret . Item = repor tMain Lst . Select ( itm = > itm . Id ) . ToList ( ) ;
return ret ;
}
catch ( Exception ex )
@ -3874,7 +3923,7 @@ select min(SerialNumStr) from FisBillM100 a left join d on a.VIN=d.VIN
MenBanPackingListResultDto ret = new MenBanPackingListResultDto ( ) ;
try
{
List < MenBanPackingListDto > reportLst = await LoadMenBanReport ( input ) ;
List < MenBanPackingListDto > reportLst = await LoadMenBanReport ( input ) ; //例如:包含两条C8扶手、两条C8头枕
List < DicItem > partLargeTypeLst = await _d icItemRepository . GetListAsync ( itm = > itm . DicTypeCode = = "零件大类" ) ;
foreach ( MenBanPackingListDto report in reportLst )
@ -3886,17 +3935,29 @@ select min(SerialNumStr) from FisBillM100 a left join d on a.VIN=d.VIN
}
}
reportLst = reportLst . OrderBy ( itm = > itm . SN ) . ToList ( ) ;
if ( reportLst . Count > 0 )
var partTypeLst = reportLst . Select ( itm = > itm . PartType ) . Distinct ( ) . ToList ( ) ;
if ( partTypeLst . Count > 0 )
{
var mainLst1 = reportLst . Where ( itm = > itm . PartType = = partTypeLst [ 0 ] ) . OrderBy ( itm = > itm . SN ) . ToList ( ) ;
var detailLst1 = mainLst1 . SelectMany ( itm = > itm . Details ) . OrderBy ( itm = > itm . SN ) . ToList ( ) ;
foreach ( var item in mainLst1 )
{
ret . MainList1 . Add ( reportLst [ 0 ] ) ;
ret . DetailList1 . AddRange ( reportLst [ 0 ] . Details ) ;
reportLst [ 0 ] . Details = null ;
item . Details = null ;
}
ret . MainList1 = mainLst1 ;
ret . DetailList1 = detailLst1 ;
}
if ( reportLst . Count > 1 )
if ( partType Lst. Count > 1 )
{
ret . MainList2 . Add ( reportLst [ 1 ] ) ;
ret . DetailList2 . AddRange ( reportLst [ 1 ] . Details ) ;
reportLst [ 1 ] . Details = null ;
var mainLst2 = reportLst . Where ( itm = > itm . PartType = = partTypeLst [ 1 ] ) . OrderBy ( itm = > itm . SN ) . ToList ( ) ;
var detailLst2 = mainLst2 . SelectMany ( itm = > itm . Details ) . OrderBy ( itm = > itm . SN ) . ToList ( ) ;
foreach ( var item in mainLst2 )
{
item . Details = null ;
}
ret . MainList2 = mainLst2 ;
ret . DetailList2 = detailLst2 ;
}
return ret ;
}