@ -801,6 +801,11 @@ namespace CK.SCP.GrupUniApi.Controller
var FATCTORY = wdb . TB_FACTORY . FirstOrDefault ( ) ;
DataTable b = PoBillNumcontroller . GetInvBatchStock ( a , FATCTORY . FactoryId ) ;
List < PURStockBill > list = ChangKeTec . Utils . ListHelper . DataTableToList < PURStockBill > ( b ) ;
if ( list . Count ( ) = = 0 )
{
Console . WriteLine ( "更新 ERP采购订单 数据:" + "无数据" ) ;
return ;
}
var wmsPoList = new List < TB_PO > ( ) ;
var wmsPoDetailList = new List < TB_PO_DETAIL > ( ) ;
var wmsAskList = new List < TB_ASK > ( ) ;
@ -1637,7 +1642,7 @@ namespace CK.SCP.GrupUniApi.Controller
{
try
{
DateTime time = DateTime . Now . AddYear s ( - 1 ) ;
DateTime time = DateTime . Now . AddMonth s ( - 1 2 ) ;
var hisList = idb . xxDiMaxes_Order . Where ( q = > q . CREATEDDATE > time ) . ToList ( ) ;
// 读取一年内 所有审批完的一般材料订单
DataTable b = GetGeneralMaterialOrder ( ) ;
@ -1650,33 +1655,34 @@ namespace CK.SCP.GrupUniApi.Controller
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_Order > ( ) ;
var emails = new List < TS_Email > ( ) ;
var Dlist = list . Where ( p = > p . CTYPE = = "D" ) ;
var Ilist = list . Where ( p = > p . CTYPE = = "I" ) . GroupBy ( p = > p . PURDOCNO ) . Distinct ( ) ;
var _D list = Dlist . GroupBy ( p = > p . PURDOCNO ) . Distinct ( ) ;
var Dlist = list . Where ( p = > p . DI_OPERTYPE = = "D" ) . GroupBy ( p = > p . PURDOCNO ) . Distinct ( ) ; // 按照订单号分组去重
var Ilist = list . Where ( p = > p . DI_OPERTYPE = = "I" ) . GroupBy ( p = > p . PURDOCNO ) . Distinct ( ) ; // 按照订单号分组去重
string wwadres = sdb . TA_CONFIG . FirstOrDefault ( q = > q . ParamName = = "接口邮件网址" ) . ParamValue ;
foreach ( var DeleteItem in _D list )
// 作废
foreach ( var DeleteItem in Dlist )
{
var _l ist = DeleteItem . ToList ( ) ;
var _ entity = _l ist . First ( ) ;
var MATERIALORDERDETAILList = sdb . TB_MATERIALORDERS_DETAIL . Where ( q = > q . PurdocNO = = _ entity . PURDOCNO ) . ToList ( ) ;
foreach ( var Ditem in _l ist )
{
var MATERIALORDERDETAILList = sdb . TB_MATERIALORDERS_DETAIL . Where ( q = > q . PurdocNO = = Ditem . PURDOCNO ) . ToList ( ) ;
if ( MATERIALORDERDETAILList . Count ( ) = = 0 )
{
continue ;
}
// 根据行号 将子表数据变为作废状态
MATERIALORDERDETAILList . ForEach ( p = >
{
if ( p . PURDOCITEMNO = = Ditem . PURDOCITEMNO )
@ -1684,7 +1690,34 @@ namespace CK.SCP.GrupUniApi.Controller
p . Ctype = Ditem . CTYPE ;
p . AcceptStatus = ( int ) GeneralMaterialOrderState . Cancel ;
PoDetailList . Add ( p ) ;
#region
// 添加发邮件数据
TS_Email email = new TS_Email ( ) ;
email . EmailToUser = Ditem . VENDORDESC ;
string mailbody = "" ;
mailbody + = "尊敬的 供应商<br>" ;
mailbody + = "你好!<br><br>" ;
mailbody + = "一般材料订单 <b>" + Ditem . PURDOCNO + "</b>" + "<b> 行号" + p . PURDOCITEMNO + "</b> 进行了物料行作废的操作,请登录供应商协同网站进行订单查看。<br>" ;
mailbody + = "登录账号:<b>" + Ditem . VENDORNO + "@W21" + "</b><br>" ;
mailbody + = "登录地址:" + wwadres + "<br><br>" ;
mailbody + = "<br><br><br><br>日期:" + DateTime . Now ;
email . EmailString = mailbody ;
var user = authdb . Users . FirstOrDefault ( q = > q . Name . Contains ( Ditem . VENDORNO ) ) ;
if ( user = = null )
{
email . EmailSendState = 2 ;
email . EmailSendFailReason = "该供应商邮箱未维护" ;
}
else
{
email . EmailAddress = user . Email ;
email . EmailSendState = 0 ;
}
emails . Add ( email ) ;
#endregion
}
} ) ;
var valueType = MATERIALORDERDETAILList . Select ( q = > q . Ctype ) . Distinct ( ) . ToList ( ) ;
var type = valueType . FirstOrDefault ( ) ;
@ -1744,10 +1777,19 @@ namespace CK.SCP.GrupUniApi.Controller
} ;
xxMaxbath . Add ( maxlist1 ) ;
}
var itemnolist = _l ist . Select ( q = > q . PURDOCITEMNO ) . ToList ( ) ;
foreach ( var Mitem in MATERIALORDERDETAILList )
{
//子表不包含的变成新建状态
if ( ! itemnolist . Contains ( Mitem . PURDOCITEMNO ) )
{
Mitem . Ctype = "N" ;
Mitem . AcceptStatus = ( int ) GeneralMaterialOrderState . New ;
PoDetailList . Add ( Mitem ) ;
}
}
}
// 新增
foreach ( var InsertItem in Ilist )
{
var inlist = InsertItem . ToList ( ) ;
@ -1832,22 +1874,25 @@ namespace CK.SCP.GrupUniApi.Controller
sdb . BulkInsert ( emails ) ; // 添加一般材料订单的邮件
sdb . BulkInsert ( InPoList ) ; // 添加插入的数据
sdb . BulkInsert ( InPoDetailList ) ; // 添加明细
item . Remark = ( ( int ) UniApiState . 成 功 ) . ToString ( ) ;
item . MaxdibatchNO = item . MaxdibatchNO + list . Count ;
idb . xxDiMaxes_Order . AddOrUpdate ( xxMaxbath . ToArray ( ) ) ;
// 更新
sdb . TB_MATERIALORDERS . BulkUpdate ( PoList ) ;
sdb . TB_MATERIALORDERS_DETAIL . BulkUpdate ( PoDetailList ) ;
Console . WriteLine ( $"更新 一般材料订单 数据:{list.Count}" ) ;
idb . BulkInsert ( xxMaxbath ) ;
if ( PoList . Count ( ) > 0 )
{
sdb . TB_MATERIALORDERS . AddOrUpdate ( q = > q . UID , PoList . ToArray ( ) ) ;
}
if ( PoDetailList . Count ( ) > 0 )
{
sdb . TB_MATERIALORDERS_DETAIL . AddOrUpdate ( q = > q . UID , PoDetailList . ToArray ( ) ) ;
}
Console . WriteLine ( $"更新 一般材料订单 数据:{Dlist.Count()+Ilist.Count()}" ) ;
}
catch ( Exception ex )
{
Console . WriteLine ( ex . Message ) ;
if ( ex . InnerException ! = null )
{
Console . WriteLine ( ex . InnerException . Message ) ;
}
}
}
}
}