@ -64,6 +64,11 @@ namespace Win.Sfs.SettleAccount.Entities.SettleAccounts
private readonly ISettleAccountBranchEfCoreRepository < WmsKanbanOutPutDetial , Guid > _ wmsRepository ;
private readonly ISettleAccountBranchEfCoreRepository < WmsKanbanOutPut , Guid > _ wmsVersionRepository ;
private readonly ISettleAccountBranchEfCoreRepository < WmsWithOutKanbanOutPutDetial , Guid > _ wmsRepository1 ;
private readonly ISettleAccountBranchEfCoreRepository < WmsWithOutKanbanOutPut , Guid > _ wmsVersionRepository1 ;
private readonly WMSEfCoreRepository < WmsKanbanOutPutDetial > _ wmsefRespository ;
private readonly WMSEfCoreRepository < TB_BILL > _ wmstbRespository ;
@ -184,13 +189,14 @@ namespace Win.Sfs.SettleAccount.Entities.SettleAccounts
[Route("WmsWithOutKanbanOutPut")]
public async Task < string > WmsWithOutKanbanOutPut ( WmsJitRequestDto input )
{
var _ billNum = "KA" + DateTime . Now . ToString ( "yyyyMMddhhmmss" ) ;
var _ joblist = _ job . Where ( p = > input . Guids . Contains ( p . Id ) & & p . FileName = = "已确认" ) . ToList ( ) ;
if ( _ joblist . Count ( ) > 0 )
{
var fileList = _ joblist . Select ( p = > p . RealDownFileName ) . ToList ( ) ;
List < WmsKanbanOutPutDetial > _l st = new List < WmsKanbanOutPutDetial > ( ) ;
List < WmsWithOut KanbanOutPutDetial > _l st = new List < WmsWithOut KanbanOutPutDetial > ( ) ;
foreach ( var filename in fileList )
{
string fileSavePath = Environment . CurrentDirectory + @"\wwwroot\files\host\my-file-container\" + filename ;
@ -198,49 +204,61 @@ namespace Win.Sfs.SettleAccount.Entities.SettleAccounts
var _l ist = _ excelHelper . ExcelToList < SettleKBWithOutCode > ( ) ;
foreach ( var itm in _l ist )
{
var _ entity = new WmsKanbanOutPutDetial ( GuidGenerator . Create ( ) , string . Empty , string . Empty , itm . MaterialCode , itm . MaterialDesc
, itm . SapMaterialGroup , string . Empty , string . Empty , 0 , string . Empty , string . Empty , itm . Version , itm . SapMaterialCode ,
_ billNum , Guid . Empty , string . Empty , itm . InvoiceQty
var _ entity = new WmsWithOutKanbanOutPutDetial (
GuidGenerator . Create ( ) ,
string . Empty ,
string . Empty ,
itm . MaterialCode ,
itm . MaterialDesc ,
itm . SapMaterialGroup ,
string . Empty ,
string . Empty ,
0 ,
string . Empty ,
string . Empty ,
input . Version ,
itm . SapMaterialCode ,
_ billNum ,
Guid . Empty ,
string . Empty ,
itm . InvoiceQty
) ;
_l st . Add ( _ entity ) ;
}
}
}
var outPutDetail = await _ wmsRepository . Where ( p = > p . Version = = input . Version & & p . Kanban = = string . Empty ) . ToListAsync ( ) ;
//var error = from itm1 in outPutDetail
// join itm2 in _ls1 on
// new { itm1.MaterialCode, itm1.Kanban }
// equals
// new { itm2.MaterialCode, itm2.Kanban }
// select itm1;
//var errList = error.GroupBy(p => new { p.BillNum }).Select(p => new { BillNum = p.Key.BillNum, Number = p.Sum(itm => itm.Qty) });
//if (errList.Count() == 0)
//{
// var query = from itm1 in _ls1
// join itm2 in outPutDetail on
// new { itm1.MaterialCode, itm1.Kanban }
// equals
// new { itm2.MaterialCode, itm2.Kanban } into temp1
// from tm1 in temp1.DefaultIfEmpty()
// where tm1 = = null
// select itm1;
// var _wmslst = query.ToList();
// foreach (var itm in _lst)
// {
// itm.BillNum = _billNum;
// }
await _ wmsRepository . GetDbContext ( ) . BulkInsertAsync ( _l st , new BulkConfig ( ) { BulkCopyTimeout = 0 , BatchSize = 1 0 0 0 0 } ) ;
int _ count = _ wmsVersionRepository . Count ( p = > p . Version = = input . Version & & p . BillNum = = _ billNum ) ;
var outPutDetail = await _ wmsRepository1 . Where ( p = > p . Version = = input . Version & & p . Kanban = = string . Empty ) . ToListAsync ( ) ;
var error = from itm1 in outPutDetail
join itm2 in _l st on
new { itm1 . MaterialCode }
equals
new { itm2 . MaterialCode }
select itm1 ;
var errList = error . GroupBy ( p = > new { p . BillNum } ) . Select ( p = > new { BillNum = p . Key . BillNum , Number = p . Sum ( itm = > itm . Qty ) } ) ;
if ( errList . Count ( ) = = 0 )
{
var query = from itm1 in _l st
join itm2 in outPutDetail on
new { itm1 . MaterialCode }
equals
new { itm2 . MaterialCode } into temp1
from tm1 in temp1 . DefaultIfEmpty ( )
where tm1 = = null
select itm1 ;
var _ wmslst = query . ToList ( ) ;
foreach ( var itm in _l st )
{
itm . BillNum = _ billNum ;
}
await _ wmsRepository1 . GetDbContext ( ) . BulkInsertAsync ( _l st , new BulkConfig ( ) { BulkCopyTimeout = 0 , BatchSize = 1 0 0 0 0 } ) ;
int _ count = _ wmsVersionRepository1 . Count ( p = > p . Version = = input . Version & & p . BillNum = = _ billNum ) ;
if ( _ count = = 0 )
{
var _ version = new WmsKanbanOutPut ( GuidGenerator . Create ( ) , input . Version , _ billNum , CurrentUser . Email ) ;
var _ version = new WmsWithOut KanbanOutPut ( GuidGenerator . Create ( ) , input . Version , _ billNum , CurrentUser . Email ) ;
await _ wmsVersionRepository . InsertAsync ( _ version , true ) ;
await _ wmsVersionRepository1 . InsertAsync ( _ version , true ) ;
}
foreach ( var job in _ joblist )
@ -249,26 +267,26 @@ namespace Win.Sfs.SettleAccount.Entities.SettleAccounts
await _ job . UpdateAsync ( job ) ;
}
}
//else
//{
// StringBuilder _buffer = new StringBuilder();
// foreach (var itm in errList)
// {
// _buffer.AppendFormat("出库单号:{0}重复记录数:{1}条", itm.BillNum, itm.Number);
// }
// var _errinfo = _buffer.ToString();
// foreach (var job in _joblist)
// {
// job.FileName = _errinfo;
// await _job.UpdateAsync(job);
// }
//}
//}
//else
//{
// _billNum = string.Empty;
//}
else
{
StringBuilder _ buffer = new StringBuilder ( ) ;
foreach ( var itm in errList )
{
_ buffer . AppendFormat ( "出库单号:{0}重复记录数:{1}条" , itm . BillNum , itm . Number ) ;
}
var _ errinfo = _ buffer . ToString ( ) ;
foreach ( var job in _ joblist )
{
job . FileName = _ errinfo ;
await _ job . UpdateAsync ( job ) ;
}
}
}
else
{
_ billNum = string . Empty ;
}
return ApplicationConsts . SuccessStr ; ;
}