@ -927,7 +927,6 @@ namespace CK.SCP.GrupUniApi.Controller
var maxlist1 = new xxDiMaxes_Po
{
Di_Batchno = qadPoNbr . DI_BATCHNO ,
} ;
xxMaxbath . Add ( maxlist1 ) ;
@ -1638,50 +1637,64 @@ namespace CK.SCP.GrupUniApi.Controller
{
try
{
var max = idb . xxDiMaxes_Po . OrderByDescending ( r = > r . Di_Batchno ) . FirstOrDefault ( ) ;
int a = max . Di_Batchno ;
var FATCTORY = sdb . TB_FACTORY . FirstOrDefault ( ) ;
// 黍龰珨啜第蹋隆等
DataTable b = GetGeneralMaterialOrder ( a , FATCTORY . FactoryId ) ;
List < GeneralMaterialOrder > list = ChangKeTec . Utils . ListHelper . DataTableToList < GeneralMaterialOrder > ( b ) ;
// 读取一年内 所有审批完的一般材料订单
DataTable b = GetGeneralMaterialOrder ( ) ;
List < GeneralMaterialOrder > orderlist = ChangKeTec . Utils . ListHelper . DataTableToList < GeneralMaterialOrder > ( b ) ;
List < xxDiMaxes_Order > maxes_Orders = ChangKeTec . Utils . ListHelper . DataTableToList < xxDiMaxes_Order > ( b ) ;
DateTime time = DateTime . Now . AddYears ( - 1 ) ;
var hisList = idb . xxDiMaxes_Order . Where ( q = > q . CREATEDDATE > time ) . ToList ( ) ;
// 取历史表不存在的数据
var expectedList = maxes_Orders . Where ( x = > ! hisList . Any ( e = > e . DI_BATCHNO = = x . DI_BATCHNO & & e . PURDOCNO = = x . PURDOCNO & & e . PURDOCITEMNO = = x . PURDOCITEMNO ) ) . ToList ( ) ;
if ( expectedList . Count ( ) = = 0 )
{
return ;
}
List < GeneralMaterialOrder > list = new List < GeneralMaterialOrder > ( ) ;
foreach ( var exitem in expectedList )
{
var selectList = orderlist . Where ( q = > q . PURDOCNO = = exitem . PURDOCNO & & q . DI_BATCHNO = = exitem . DI_BATCHNO & & q . PURDOCITEMNO = = exitem . PURDOCITEMNO ) . ToList ( ) ;
list . AddRange ( selectList ) ;
}
var PoList = new List < TB_MATERIALORDERS > ( ) ;
var PoDetailList = new List < TB_MATERIALORDERS_DETAIL > ( ) ;
var InPoList = new List < TB_MATERIALORDERS > ( ) ;
var InPoDetailList = new List < TB_MATERIALORDERS_DETAIL > ( ) ;
var xxMaxbath = new List < xxDiMaxes_Po > ( ) ;
var xxMaxbath = new List < xxDiMaxes_Order > ( ) ;
var emails = new List < TS_Email > ( ) ;
var Dlist = list . Where ( p = > p . CTYPE = = "D" ) ;
var Ilist = list . Where ( p = > p . CTYPE ! = "D" ) . GroupBy ( p = > p . PURDOCNO ) . Distinct ( ) ;
var Ilist = list . Where ( p = > p . CTYPE = = "I ") . GroupBy ( p = > p . PURDOCNO ) . Distinct ( ) ;
var _D list = Dlist . GroupBy ( p = > p . PURDOCNO ) . Distinct ( ) ;
string wwadres = sdb . TA_CONFIG . FirstOrDefault ( q = > q . ParamName = = "接口邮件网址" ) . ParamValue ;
foreach ( var DeleteItem in _D list )
{
var _l ist = DeleteItem . ToList ( ) ;
var _ entity = _l ist . First ( ) ;
// 跦擂 隆等瘍釬煙
//var MATERIALORDERList = sdb.TB_MATERIALORDERS.Where(q => q.PurdocNO == _entity.PURDOCNO).ToList();
//MATERIALORDERList.ForEach(p =>
//{
// p.Ctype = "D" ;
// p.AcceptStatus = (int)GeneralMaterialOrderState.Cancel;
// PoList.Add(p);
//});
foreach ( var Ditem in _l ist )
{
var MATERIALORDERDETAILList = sdb . TB_MATERIALORDERS_DETAIL . Where ( q = > q . PurdocNO = = Ditem . PURDOCNO & & q . PURDOCITEMNO = = Ditem . PURDOCITEMNO ) . ToList ( ) ;
var MATERIALORDERDETAILList = sdb . TB_MATERIALORDERS_DETAIL . Where ( q = > q . PurdocNO = = Ditem . PURDOCNO ) . ToList ( ) ;
if ( MATERIALORDERDETAILList . Count ( ) = = 0 )
{
continue ;
}
MATERIALORDERDETAILList . ForEach ( p = >
{
p . Ctype = "D" ;
p . AcceptStatus = ( int ) GeneralMaterialOrderState . Cancel ;
PoDetailList . Add ( p ) ;
if ( p . PURDOCITEMNO = = Ditem . PURDOCITEMNO )
{
p . Ctype = Ditem . CTYPE ;
p . AcceptStatus = ( int ) GeneralMaterialOrderState . Cancel ;
PoDetailList . Add ( p ) ;
}
} ) ;
var valueType = MATERIALORDERDETAILList . Select ( q = > q . Ctype ) . Distinct ( ) . ToList ( ) ;
var type = valueType . FirstOrDefault ( ) ;
// 子表全是d并且唯一 更新主表
if ( valueType . Count ( ) = = 1 & & type = = "D" )
{
var MATERIALORDERList = sdb . TB_MATERIALORDERS . Where ( q = > q . PurdocNO = = Ditem . PURDOCNO ) . ToList ( ) ;
MATERIALORDERList . ForEach ( p = >
{
p . AcceptStatus = ( int ) GeneralMaterialOrderState . Cancel ;
p . Ctype = "D" ;
PoList . Add ( p ) ;
} ) ;
@ -1712,14 +1725,27 @@ namespace CK.SCP.GrupUniApi.Controller
emails . Add ( email ) ;
#endregion
}
else //否则将主表变成新建状态
{
var MATERIALORDERList = sdb . TB_MATERIALORDERS . Where ( q = > q . PurdocNO = = Ditem . PURDOCNO ) . ToList ( ) ;
MATERIALORDERList . ForEach ( p = >
{
p . Ctype = "N" ;
p . AcceptStatus = ( int ) GeneralMaterialOrderState . New ;
PoList . Add ( p ) ;
} ) ;
}
var maxlist1 = new xxDiMaxes_Order
{
DI_BATCHNO = Ditem . DI_BATCHNO ,
PURDOCNO = Ditem . PURDOCNO ,
PURDOCITEMNO = Ditem . PURDOCITEMNO ,
CREATEDDATE = Ditem . CREATEDDATE ,
} ;
xxMaxbath . Add ( maxlist1 ) ;
}
var maxlist1 = new xxDiMaxes_Po
{
Di_Batchno = _ entity . DI_BATCHNO ,
} ;
xxMaxbath . Add ( maxlist1 ) ;
}
foreach ( var InsertItem in Ilist )
@ -1766,6 +1792,14 @@ namespace CK.SCP.GrupUniApi.Controller
orderdetail . StoreLocation = initem . STORELOCATION ;
orderdetail . PURDOCITEMNO = initem . PURDOCITEMNO ;
InPoDetailList . Add ( orderdetail ) ;
var maxlist1 = new xxDiMaxes_Order
{
DI_BATCHNO = initem . DI_BATCHNO ,
PURDOCNO = initem . PURDOCNO ,
PURDOCITEMNO = initem . PURDOCITEMNO ,
CREATEDDATE = initem . CREATEDDATE ,
} ;
xxMaxbath . Add ( maxlist1 ) ;
}
#endregion
#region
@ -1793,19 +1827,14 @@ namespace CK.SCP.GrupUniApi.Controller
}
emails . Add ( email ) ;
#endregion
var maxlist1 = new xxDiMaxes_Po
{
Di_Batchno = inentity . DI_BATCHNO ,
} ;
xxMaxbath . Add ( maxlist1 ) ;
}
sdb . BulkInsert ( emails ) ; // 添加一般材料订单的邮件
sdb . BulkInsert ( InPoList ) ; // 添加插入的数据
sdb . BulkInsert ( InPoDetailList ) ; // 添加明细
item . Remark = ( ( int ) UniApiState . 成 功 ) . ToString ( ) ;
item . MaxdibatchNO = item . MaxdibatchNO + list . Count ;
idb . xxDiMaxes_Po . AddOrUpdate ( xxMaxbath . ToArray ( ) ) ;
idb . xxDiMaxes_Order . AddOrUpdate ( xxMaxbath . ToArray ( ) ) ;
// 更新
sdb . TB_MATERIALORDERS . BulkUpdate ( PoList ) ;
sdb . TB_MATERIALORDERS_DETAIL . BulkUpdate ( PoDetailList ) ;