@ -65,6 +65,7 @@ using Win.Sfs.SettleAccount.Entities.BQ.Dtos;
using Win.Sfs.SettleAccount.Entities.BQ.Syncs ;
using Win.Sfs.SettleAccount.Entities.BQ.Vmi ;
using Win.Sfs.SettleAccount.Entities.CodeSettings ;
using Win.Sfs.SettleAccount.Entities.SecMatch ;
using Win.Sfs.SettleAccount.Entities.TaskJobs ;
using Win.Sfs.SettleAccount.ExcelImporter ;
using Win.Sfs.SettleAccount.ExportReports ;
@ -316,11 +317,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
return await ExtendExcel < VmiBalanceSumDetailDto > . WriteDataToExcelInParallel ( "库存余额" , dtos , 5 0 0 0 0 0 ) . ConfigureAwait ( false ) ;
//return fileName;
}
@ -727,49 +723,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
log . ChangedBy = this . _ currentUser . UserName ;
}
//private int GetVersionByTimeSpan(DateTime p_begintime,DateTime p_endtime, string p_day)
//{
// var before = p_billtime.Year;
// var last = before - 1;
// DateTime lastYear = DateTime.ParseExact(string.Format("{0}-12-{1} 08:00:00", last, p_day), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);//上期时间
// DateTime beforeYear = DateTime.ParseExact(string.Format("{0}-12-{1} 07:59:59", before, p_day), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);//这期时间
// //var result = seDetails
// // .Select(log =>
// // {
// string version = null;
// if (p_billtime >= lastYear && p_billtime <= lastYear.AddMonths(1))
// {
// version = $"{before.ToString()}01";
// }
// else if (p_billtime >= lastYear.AddMonths(1) && p_billtime <= lastYear.AddMonths(2))
// { version = $"{before.ToString()}02"; }
// else if (p_billtime >= lastYear.AddMonths(2) && p_billtime <= lastYear.AddMonths(3))
// { version = $"{before.ToString()}03"; }
// else if (p_billtime >= lastYear.AddMonths(3) && p_billtime <= lastYear.AddMonths(4))
// { version = $"{before.ToString()}04"; }
// else if (p_billtime >= lastYear.AddMonths(4) && p_billtime <= lastYear.AddMonths(5))
// { version = $"{before.ToString()}05"; }
// else if (p_billtime >= lastYear.AddMonths(5) && p_billtime <= lastYear.AddMonths(6))
// { version = $"{before.ToString()}06"; }
// else if (p_billtime >= lastYear.AddMonths(6) && p_billtime <= lastYear.AddMonths(7))
// { version = $"{before.ToString()}07"; }
// else if (p_billtime >= lastYear.AddMonths(7) && p_billtime <= lastYear.AddMonths(8))
// { version = $"{before.ToString()}08"; }
// else if (p_billtime >= lastYear.AddMonths(8) && p_billtime <= lastYear.AddMonths(9))
// { version = $"{before.ToString()}09"; }
// else if (p_billtime >= lastYear.AddMonths(9) && p_billtime <= lastYear.AddMonths(10))
// { version = $"{before.ToString()}10"; }
// else if (p_billtime >= lastYear.AddMonths(10) && p_billtime <= lastYear.AddMonths(11))
// { version = $"{before.ToString()}11"; }
// else if (p_billtime >= lastYear.AddMonths(11) && p_billtime <= beforeYear)
// { version = $"{before.ToString()}12"; }
// if (string.IsNullOrEmpty(version))
// {
// return 200802;//找不到的数据默认写到这个区间
// }
// return int.Parse(version);
//}
private int GetVersionByBillTime ( DateTime p_billtime , string p_day )
{
@ -1273,7 +1227,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
{
itm . BillTime = DateTime . Now ;
itm . ChangedTime = DateTime . Now ;
itm . LogType = itm . Qty > 0 ? VmiLogType . Type100 : VmiLogType . Type3 00 ;
itm . LogType = itm . Qty > 0 ? VmiLogType . Type100 : VmiLogType . Type4 00 ;
itm . ChangedQty = itm . Qty ;
itm . Version = GetVersionByBillTime ( itm . BillTime . Value , value ) ;
}
@ -1430,279 +1384,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
logList . AsParallel ( ) . ForEach ( Update ) ;
//List<BBAC_SE_DETAIL> seDetails = new List<BBAC_SE_DETAIL>();
//List<HBPO_SE_DETAIL> hbpo_seDetails=new List<HBPO_SE_DETAIL>();
//List<PUB_SE_DETAIL> pub_seDetails=new List<PUB_SE_DETAIL>();
//foreach (var item in logList)
//{
// if(item.DeliverBillType== EnumDeliverBjBmpBillType.JIS件&&item.DeliverSubBillType== EnumDeliverSubBillType.保险杠BBAC)
// {
// BBAC_SE_DETAIL seDetail = new BBAC_SE_DETAIL();
// seDetail.SetId(item.Id);
// seDetail.BeginDate = DateTime.Now;
// seDetail.CreationTime = DateTime.Now;
// seDetail.IsDeleted = false;
// seDetail.Version = int.Parse(DateTime.Now.ToString("yyyyMM"));
// seDetail.ShippingDate = (DateTime)DateTime.Now;
// seDetail.Qty = item.Qty;
// seDetail.IsHaveEdiData = false;
// seDetail.BusinessType = EnumBusinessType.JisBBAC;
// seDetail.AssembleData = (DateTime)item.AssembleData;
// seDetail.BillType = 0;
// seDetail.DeliverBillType = (EnumDeliverBjBmpBillType)item.DeliverBillType;
// seDetail.DeliverSubBillType = (EnumDeliverSubBillType)item.DeliverSubBillType;
// seDetail.ProType = 0;
// seDetail.State = 0;
// seDetail.SubBillType = 0;
// seDetail.TransType = EnumDelTransType.发货;
// seDetail.UID = 000;
// seDetail.FactoryPartCode = item.RealPartCode;
// seDetail.CustomerPartCodeNoSpace = item.RealPartCode.Replace("-", "");
// seDetail.ErpToLoc= item.ErpToLoc;
// seDetail.Qty=item.Qty;
// seDetail.VinCode= item.VinCode;
// seDetail.PN = item.VinCode;
// seDetail.LU = item.CustPartCode;
// seDetail.CustPartCode = item.CustPartCode;
// seDetail.BillTime= DateTime.Now;
// seDetail.Remark = "期初初始化";
// seDetails.Add(seDetail);
// }
// if (item.DeliverBillType == EnumDeliverBjBmpBillType.JIS件 && item.DeliverSubBillType == EnumDeliverSubBillType.买单件小件BBAC)
// {
// BBAC_SE_DETAIL seDetail = new BBAC_SE_DETAIL();
// seDetail.SetId(item.Id);
// seDetail.BeginDate = DateTime.Now;
// seDetail.CreationTime = DateTime.Now;
// seDetail.IsDeleted = false;
// seDetail.Version = int.Parse(DateTime.Now.ToString("yyyyMM"));
// seDetail.ShippingDate = (DateTime)DateTime.Now;
// seDetail.Qty = item.Qty;
// seDetail.IsHaveEdiData = false;
// seDetail.BusinessType = EnumBusinessType.MaiDanJianBBAC;
// seDetail.AssembleData = (DateTime)item.AssembleData;
// seDetail.BillType = 0;
// seDetail.DeliverBillType = (EnumDeliverBjBmpBillType)item.DeliverBillType;
// seDetail.DeliverSubBillType = (EnumDeliverSubBillType)item.DeliverSubBillType;
// seDetail.ProType = 0;
// seDetail.State = 0;
// seDetail.SubBillType = 0;
// seDetail.TransType = EnumDelTransType.发货;
// seDetail.UID = 000;
// seDetail.FactoryPartCode = item.RealPartCode;
// seDetail.CustomerPartCodeNoSpace = item.RealPartCode.Replace("-", "");
// seDetail.ErpToLoc = item.ErpToLoc;
// seDetail.Qty = item.Qty;
// seDetail.VinCode = item.VinCode;
// seDetail.PN = item.VinCode;
// seDetail.LU = item.CustPartCode;
// seDetail.CustPartCode = item.CustPartCode;
// seDetail.BillTime = DateTime.Now;
// seDetail.Remark = "期初初始化";
// seDetails.Add(seDetail);
// }
// if (item.DeliverBillType == EnumDeliverBjBmpBillType.JIS件 && item.DeliverSubBillType == EnumDeliverSubBillType.保险杠HBPO)
// {
// HBPO_SE_DETAIL seDetail = new HBPO_SE_DETAIL();
// seDetail.SetId(item.Id);
// seDetail.BeginDate = DateTime.Now;
// seDetail.CreationTime = DateTime.Now;
// seDetail.IsDeleted = false;
// seDetail.Version = int.Parse(DateTime.Now.ToString("yyyyMM"));
// seDetail.ShippingDate = (DateTime)DateTime.Now;
// seDetail.Qty = item.Qty;
// seDetail.IsHaveEdiData = false;
// seDetail.BusinessType = EnumBusinessType.JisHBPO;
// seDetail.AssembleData = (DateTime)item.AssembleData;
// seDetail.BillType = 0;
// seDetail.DeliverBillType = (EnumDeliverBjBmpBillType)item.DeliverBillType;
// seDetail.DeliverSubBillType = (EnumDeliverSubBillType)item.DeliverSubBillType;
// seDetail.ProType = 0;
// seDetail.State = 0;
// seDetail.SubBillType = 0;
// seDetail.TransType = EnumDelTransType.发货;
// seDetail.UID = 000;
// seDetail.FactoryPartCode = item.RealPartCode;
// seDetail.CustomerPartCodeNoSpace = item.RealPartCode.Replace("-", "");
// seDetail.ErpToLoc = item.ErpToLoc;
// seDetail.Qty = item.Qty;
// seDetail.VinCode = item.VinCode;
// seDetail.PN = item.VinCode;
// seDetail.LU = item.CustPartCode;
// seDetail.CustPartCode = item.CustPartCode;
// seDetail.BillTime = DateTime.Now;
// seDetail.Remark = "期初初始化";
// hbpo_seDetails.Add(seDetail);
// }
// if (item.DeliverBillType == EnumDeliverBjBmpBillType.JIS件 && item.DeliverSubBillType == EnumDeliverSubBillType.买单件小件HBPO)
// {
// HBPO_SE_DETAIL seDetail = new HBPO_SE_DETAIL();
// seDetail.SetId(item.Id);
// seDetail.BeginDate = DateTime.Now;
// seDetail.CreationTime = DateTime.Now;
// seDetail.IsDeleted = false;
// seDetail.Version = int.Parse(DateTime.Now.ToString("yyyyMM"));
// seDetail.ShippingDate = (DateTime)DateTime.Now;
// seDetail.Qty = item.Qty;
// seDetail.IsHaveEdiData = false;
// seDetail.BusinessType = EnumBusinessType.MaiDanJianHBPO;
// seDetail.AssembleData = (DateTime)item.AssembleData;
// seDetail.BillType = 0;
// seDetail.DeliverBillType = (EnumDeliverBjBmpBillType)item.DeliverBillType;
// seDetail.DeliverSubBillType = (EnumDeliverSubBillType)item.DeliverSubBillType;
// seDetail.ProType = 0;
// seDetail.State = 0;
// seDetail.SubBillType = 0;
// seDetail.TransType = EnumDelTransType.发货;
// seDetail.UID = 000;
// seDetail.FactoryPartCode = item.RealPartCode;
// seDetail.CustomerPartCodeNoSpace = item.RealPartCode.Replace("-", "");
// seDetail.ErpToLoc = item.ErpToLoc;
// seDetail.Qty = item.Qty;
// seDetail.VinCode = item.VinCode;
// seDetail.PN = item.VinCode;
// seDetail.LU = item.CustPartCode;
// seDetail.CustPartCode = item.CustPartCode;
// seDetail.BillTime = DateTime.Now;
// seDetail.Remark = "期初初始化";
// hbpo_seDetails.Add(seDetail);
// }
// if (item.DeliverBillType == EnumDeliverBjBmpBillType.JIT直供件 && item.DeliverSubBillType == EnumDeliverSubBillType.JIT直供件BBAC)
// {
// PUB_SE_DETAIL seDetail = new PUB_SE_DETAIL();
// seDetail.SetId(item.Id);
// seDetail.BeginDate = DateTime.Now;
// seDetail.CreationTime = DateTime.Now;
// seDetail.IsDeleted = false;
// seDetail.Version = int.Parse(DateTime.Now?.ToString("yyyyMM"));
// seDetail.ShippingDate = (DateTime)DateTime.Now;
// seDetail.Qty = item.Qty;
// //seDetail.IsHaveEdiData = false;
// seDetail.BusinessType = EnumBusinessType.ZhiGongJianBBAC;
// seDetail.AssembleData = (DateTime)item.AssembleData;
// seDetail.BillType = 0;
// seDetail.DeliverBillType = (EnumDeliverBjBmpBillType)item.DeliverBillType;
// seDetail.DeliverSubBillType = (EnumDeliverSubBillType)item.DeliverSubBillType;
// seDetail.ProType = 0;
// seDetail.State = 0;
// seDetail.SubBillType = 0;
// seDetail.TransType = EnumDelTransType.发货;
// seDetail.UID = 000;
// seDetail.FactoryPartCode = item.RealPartCode;
// seDetail.CustomerPartCodeNoSpace = item.RealPartCode.Replace("-", "");
// seDetail.ToErpLocCode = item.ErpToLoc;
// seDetail.Qty = item.Qty;
// //seDetail.VinCode = item.VinCode;
// seDetail.PN = item.VinCode;
// seDetail.LU = item.CustPartCode;
// seDetail.CustPartCode = item.CustPartCode;
// seDetail.BillTime = DateTime.Now;
// seDetail.Remark = "期初初始化";
// pub_seDetails.Add(seDetail);
// }
// if (item.DeliverBillType == EnumDeliverBjBmpBillType.JIT直供件 && item.DeliverSubBillType == EnumDeliverSubBillType.JIT直供件HBPO)
// {
// PUB_SE_DETAIL seDetail = new PUB_SE_DETAIL();
// seDetail.SetId(item.Id);
// seDetail.BeginDate = DateTime.Now;
// seDetail.CreationTime = DateTime.Now;
// seDetail.IsDeleted = false;
// seDetail.Version = int.Parse(DateTime.Now?.ToString("yyyyMM"));
// seDetail.ShippingDate = (DateTime)DateTime.Now;
// seDetail.Qty = item.Qty;
// //seDetail.IsHaveEdiData = false;
// seDetail.BusinessType = EnumBusinessType.ZhiGongJianHBPO;
// seDetail.AssembleData = (DateTime)item.AssembleData;
// seDetail.BillType = 0;
// seDetail.DeliverBillType = (EnumDeliverBjBmpBillType)item.DeliverBillType;
// seDetail.DeliverSubBillType = (EnumDeliverSubBillType)item.DeliverSubBillType;
// seDetail.ProType = 0;
// seDetail.State = 0;
// seDetail.SubBillType = 0;
// seDetail.TransType = EnumDelTransType.发货;
// seDetail.UID = 000;
// seDetail.FactoryPartCode = item.RealPartCode;
// seDetail.CustomerPartCodeNoSpace = item.RealPartCode.Replace("-", "");
// seDetail.ToErpLocCode = item.ErpToLoc;
// seDetail.Qty = item.Qty;
// //seDetail.VinCode = item.VinCode;
// seDetail.PN = item.VinCode;
// seDetail.LU = item.CustPartCode;
// seDetail.CustPartCode = item.CustPartCode;
// seDetail.BillTime = DateTime.Now;
// seDetail.Remark = "期初初始化";
// pub_seDetails.Add(seDetail);
// }
// if (item.DeliverBillType == EnumDeliverBjBmpBillType.北汽4S备件 && item.DeliverSubBillType == EnumDeliverSubBillType.北汽4S备件BBAC)
// {
// PUB_SE_DETAIL seDetail = new PUB_SE_DETAIL();
// seDetail.SetId(item.Id);
// seDetail.BeginDate = DateTime.Now;
// seDetail.CreationTime = DateTime.Now;
// seDetail.IsDeleted = false;
// seDetail.Version = int.Parse(DateTime.Now?.ToString("yyyyMM"));
// seDetail.ShippingDate = (DateTime)DateTime.Now;
// seDetail.Qty = item.Qty;
// //seDetail.IsHaveEdiData = false;
// seDetail.BusinessType = EnumBusinessType.BeiJian;
// seDetail.AssembleData = (DateTime)item.AssembleData;
// seDetail.BillType = 0;
// seDetail.DeliverBillType = (EnumDeliverBjBmpBillType)item.DeliverBillType;
// seDetail.DeliverSubBillType = (EnumDeliverSubBillType)item.DeliverSubBillType;
// seDetail.ProType = 0;
// seDetail.State = 0;
// seDetail.SubBillType = 0;
// seDetail.TransType = EnumDelTransType.发货;
// seDetail.UID = 000;
// seDetail.FactoryPartCode = item.RealPartCode;
// seDetail.CustomerPartCodeNoSpace = item.RealPartCode.Replace("-", "");
// seDetail.ToErpLocCode = item.ErpToLoc;
// seDetail.Qty = item.Qty;
// //seDetail.VinCode = item.VinCode;
// seDetail.PN = item.VinCode;
// seDetail.LU = item.CustPartCode;
// seDetail.CustPartCode = item.CustPartCode;
// seDetail.BillTime = DateTime.Now;
// seDetail.Remark = "期初初始化";
// pub_seDetails.Add(seDetail);
// }
// if (item.DeliverBillType == EnumDeliverBjBmpBillType.印度件 && item.DeliverSubBillType == EnumDeliverSubBillType.印度件BBAC)
// {
// PUB_SE_DETAIL seDetail = new PUB_SE_DETAIL();
// seDetail.SetId(item.Id);
// seDetail.BeginDate = DateTime.Now;
// seDetail.CreationTime = DateTime.Now;
// seDetail.IsDeleted = false;
// seDetail.Version = int.Parse(DateTime.Now?.ToString("yyyyMM"));
// seDetail.ShippingDate = (DateTime)DateTime.Now;
// seDetail.Qty = item.Qty;
// //seDetail.IsHaveEdiData = false;
// seDetail.BusinessType = EnumBusinessType.YinDuJian;
// seDetail.AssembleData = (DateTime)item.AssembleData;
// seDetail.BillType = 0;
// seDetail.DeliverBillType = (EnumDeliverBjBmpBillType)item.DeliverBillType;
// seDetail.DeliverSubBillType = (EnumDeliverSubBillType)item.DeliverSubBillType;
// seDetail.ProType = 0;
// seDetail.State = 0;
// seDetail.SubBillType = 0;
// seDetail.TransType = EnumDelTransType.发货;
// seDetail.UID = 000;
// seDetail.FactoryPartCode = item.RealPartCode;
// seDetail.CustomerPartCodeNoSpace = item.RealPartCode.Replace("-", "");
// seDetail.ToErpLocCode = item.ErpToLoc;
// seDetail.Qty = item.Qty;
// //seDetail.VinCode = item.VinCode;
// seDetail.PN = item.VinCode;
// seDetail.LU = item.CustPartCode;
// seDetail.CustPartCode = item.CustPartCode;
// seDetail.BillTime = DateTime.Now;
// seDetail.Remark = "期初初始化";
// pub_seDetails.Add(seDetail);
// }
//}
//var messageList = logList.Select(log => new VmiMessage { Message = JsonSerializer.Serialize(log) }).ToList();
var connectionString = this . _ serviceProvider . GetRequiredService < IConfiguration > ( ) . GetConnectionString ( "SettleAccountService" ) ;
var options = new DbContextOptionsBuilder < SettleAccountDbContext > ( ) . UseSqlServer ( connectionString ) . Options ;
using var context = new SettleAccountDbContext ( options ) ;
@ -1711,22 +1392,12 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
try
{
using var transaction = context . Database . BeginTransaction ( ) ;
var value = _ codeRepository . FirstOrDefault ( p = > p . Project = = "库存账期" ) . Value ;
foreach ( var itm in logList )
{
itm . Version = GetVersionByBillTime ( itm . BillTime . Value , value ) ;
}
await context . BulkInsertAsync ( logList ) . ConfigureAwait ( false ) ;
//await context.BulkInsertAsync(messageList).ConfigureAwait(false);
//await context.BulkInsertAsync(seDetails).ConfigureAwait(false);
//await context.BulkInsertAsync(hbpo_seDetails).ConfigureAwait(false);
//await context.BulkInsertAsync(pub_seDetails).ConfigureAwait(false);
transaction . Commit ( ) ;
}
catch ( Exception ex )
@ -1789,10 +1460,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
using var context = new SettleAccountDbContext ( options ) ;
var st = new Stopwatch ( ) ;
st . Start ( ) ;
try
{
//导入日志和消息
@ -1822,6 +1489,185 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
}
}
[HttpPost]
public async Task < string > GetMatchSummar ( EnumBusinessType p_businessType , string sebegin , string seend , string sabegin , string saend )
{
string satablename = string . Empty ;
string setablename = string . Empty ;
string businesstype = string . Empty ;
switch ( p_businessType )
{
case EnumBusinessType . JisBBAC :
satablename = "Set_BBAC_CAN_SA_DETAIL" ;
setablename = "Set_BBAC_SE_DETAIL" ;
break ;
case EnumBusinessType . JisHBPO :
satablename = "Set_HBPO_CAN_SA_DETAIL" ;
setablename = "Set_HBPO_SE_DETAIL" ;
break ;
case EnumBusinessType . MaiDanJianHBPO :
satablename = "Set_HBPO_CAN_SA_DETAIL" ;
setablename = "Set_HBPO_SE_DETAIL" ;
break ;
case EnumBusinessType . MaiDanJianBBAC :
satablename = "Set_BBAC_CAN_SA_DETAIL" ;
setablename = "Set_BBAC_SE_DETAIL" ;
break ;
default :
satablename = "Set_PUB_CAN_SA_DETAIL" ;
setablename = "Set_PUB_SE_DETAIL" ;
break ;
}
string sql =
"select lu,\n" +
"SUM(BSEQty) BSEQty\n" +
",SUM(BRETQty) BRETQty\n" +
",SUM(SEQTY) SEQTY\n" +
",SUM(RETQty) RETQty\n" +
",SUM(CANQty) CANQty\n" +
",SUM(NOTQty) NOTQty\n" +
",SUM(SE_SA_CAN_QTY) SE_SA_CAN_QTY\n" +
",SUM(SE_SA_NOT_QTY) SE_SA_NOT_QTY\n" +
",SUM(ONLY_SE_QTY) ONLY_SE_QTY\n" +
",SUM(ONLY_SA_QTY) ONLY_SA_QTY\n" +
",SUM(INVQty) INVQty\n" +
"FROM (\n" +
"select temp1.*,case WHEN ISNULL(TEMP2.InvbillNum,'')<>'' THEN isnull(temp2.Qty,0) ELSE 0 END invQty from (\n" +
"select LU,PN,\n" +
"ISNULL([10],0) BSEQty,\n" +
"ISNULL([20],0) BRETQty,\n" +
"isnull([100],0) SEQty ,\n" +
"isnull([150],0) RETQty,\n" +
"isnull([200],0) CANQty,\n" +
"isnull([800],0) NOTQty,\n" +
"case when ISNULL([10],0)+isnull([20],0)+isnull([100],0)+ISNULL([150],0)-ISNULL([200],0)=0 then ISNULL([100],0)\n" +
"ELSE 0 END SE_SA_CAN_QTY,\n" +
"case when ISNULL([10],0)+isnull([20],0)+isnull([100],0)+ISNULL([150],0)-ISNULL([800],0)=0 then ISNULL([100],0)\n" +
"ELSE 0 END SE_SA_NOT_QTY,\n" +
"case when ISNULL([10],0)+isnull([20],0)+isnull([100],0)+ISNULL([150],0)-ISNULL([200],0)-ISNULL([800],0)>0 then ISNULL([100],0)\n" +
"ElSE 0 END SE_SA_DIFF_QTY,\n" +
"case when ISNULL([10],0)+isnull([20],0)+isnull([100],0)+ISNULL([150],0)-ISNULL([200],0)-ISNULL([800],0)=isnull([100],0)+ISNULL([150],0) then \n" +
"ISNULL([10],0)+isnull([20],0)+isnull([100],0)+ISNULL([150],0)-ISNULL([200],0)-ISNULL([800],0)\n" +
"ElSE 0 END ONLY_SE_QTY,\n" +
"case when ISNULL([10],0)+isnull([20],0)+isnull([100],0)+ISNULL([150],0)-ISNULL([200],0)-ISNULL([800],0)=-ISNULL([200],0)-ISNULL([800],0) then \n" +
"ISNULL([200],0)+ISNULL([800],0) \n" +
"ElSE 0 END ONLY_SA_QTY \n" +
"from (\n" +
"SELECT LU,PN,BusinessType,Qty,10 Type \n" +
$"from {setablename} A WITH(NOLOCK) where BusinessType={(int)p_businessType} AND Qty>0 AND REMARK='期初初始化' \n" ;
if ( ! string . IsNullOrEmpty ( sebegin ) )
{
sql + = $" AND BillTime > '{sebegin}'\n" ;
}
if ( ! string . IsNullOrEmpty ( seend ) )
{
sql + = $" AND BillTime <'{seend}'\n" ;
}
sql + =
"UNION ALL\n" +
"SELECT LU,PN,BusinessType,Qty,20 Type\n" +
$"from {setablename} A WITH(NOLOCK) where BusinessType={(int)p_businessType} AND Qty<0 and Remark='期初初始化' \n" ;
if ( ! string . IsNullOrEmpty ( sebegin ) )
{
sql + = $" AND BillTime > '{sebegin}'\n" ;
}
if ( ! string . IsNullOrEmpty ( seend ) )
{
sql + = $" AND BillTime <'{seend}'\n" ;
}
sql + =
"UNION ALL\n" +
"SELECT LU,PN,BusinessType,Qty,100 Type\n" +
$"from {setablename} A WITH(NOLOCK) where BusinessType={(int)p_businessType} AND Qty>0 AND REMARK<>'期初初始化' \n" ;
if ( ! string . IsNullOrEmpty ( sebegin ) )
{
sql + = $" AND BillTime > '{sebegin}'\n" ;
}
if ( ! string . IsNullOrEmpty ( seend ) )
{
sql + = $" AND BillTime <'{seend}'\n" ;
}
sql + = "UNION ALL\n" +
"SELECT LU,PN,BusinessType,Qty,150 Type\n" +
$"from {setablename} A WITH(NOLOCK) whereBusinessType={(int)p_businessType} AND Qty<0 and Remark<>'期初初始化' \n" ;
if ( ! string . IsNullOrEmpty ( sebegin ) )
{
sql + = $" AND BillTime > '{sebegin}'\n" ;
}
if ( ! string . IsNullOrEmpty ( seend ) )
{
sql + = $" AND BillTime <'{seend}'\n" ;
}
sql + = "UNION ALL\n" +
"SELECT LU,PN,BusinessType,Qty,200 Type\n" +
$"from {satablename} A WITH(NOLOCK) WHERE BusinessType={(int)p_businessType} \n" ;
if ( ! string . IsNullOrEmpty ( sabegin ) )
{
sql + = $" AND SettleDate >'{sabegin}'\n" ;
}
if ( ! string . IsNullOrEmpty ( saend ) )
{
sql + = $" AND SettleDate<'{saend}'\n" ;
}
sql + = "UNION ALL\n" +
"SELECT LU,PN,BusinessType,Qty,800 Type\n" +
$"from {satablename} A WITH(NOLOCK) WHERE BusinessType={(int)p_businessType} \n" ;
if ( ! string . IsNullOrEmpty ( sabegin ) )
{
sql + = $" AND SettleDate >'{sabegin}'\n" ;
}
if ( ! string . IsNullOrEmpty ( saend ) )
{
sql + = $" AND SettleDate<'{saend}'\n" ;
}
sql + = ") a\n" +
"PIVOT (\n" +
"SUM(qty)\n" +
"FOR Type IN ([10],[20],[100],[150],[200],[800])\n" +
") AS piv\n" +
$") temp1 left join (select LU,PN,InvbillNum,Qty from {satablename} where BusinessType={(int)p_businessType} ) temp2 on temp1.PN=temp2.PN and temp1.LU=temp2.LU\n" +
") tempsum group by LU\n" ;
return sql ;
}
private async Task InvokeInternal ( IServiceProvider serviceProvider )
{
var batchSize = 1 0 0 0 0 ;