@ -53,6 +53,7 @@ using Volo.Abp;
using Volo.Abp.Application.Dtos ;
using Volo.Abp.Application.Dtos ;
using Volo.Abp.Application.Services ;
using Volo.Abp.Application.Services ;
using Volo.Abp.BlobStoring ;
using Volo.Abp.BlobStoring ;
using Volo.Abp.Data ;
using Volo.Abp.DependencyInjection ;
using Volo.Abp.DependencyInjection ;
using Volo.Abp.Domain.Entities ;
using Volo.Abp.Domain.Entities ;
using Volo.Abp.Guids ;
using Volo.Abp.Guids ;
@ -65,10 +66,12 @@ using Win.Sfs.SettleAccount.Entities.BQ.Dtos;
using Win.Sfs.SettleAccount.Entities.BQ.Syncs ;
using Win.Sfs.SettleAccount.Entities.BQ.Syncs ;
using Win.Sfs.SettleAccount.Entities.BQ.Vmi ;
using Win.Sfs.SettleAccount.Entities.BQ.Vmi ;
using Win.Sfs.SettleAccount.Entities.CodeSettings ;
using Win.Sfs.SettleAccount.Entities.CodeSettings ;
using Win.Sfs.SettleAccount.Entities.SecMatch ;
using Win.Sfs.SettleAccount.Entities.TaskJobs ;
using Win.Sfs.SettleAccount.Entities.TaskJobs ;
using Win.Sfs.SettleAccount.ExcelImporter ;
using Win.Sfs.SettleAccount.ExcelImporter ;
using Win.Sfs.SettleAccount.ExportReports ;
using Win.Sfs.SettleAccount.ExportReports ;
using Win.Sfs.Shared ;
using Win.Sfs.Shared ;
using Win.Sfs.Shared.DomainBase ;
using Win.Sfs.Shared.Filter ;
using Win.Sfs.Shared.Filter ;
using Win.Sfs.Shared.RepositoryBase ;
using Win.Sfs.Shared.RepositoryBase ;
@ -316,11 +319,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
return await ExtendExcel < VmiBalanceSumDetailDto > . WriteDataToExcelInParallel ( "库存余额" , dtos , 5 0 0 0 0 0 ) . ConfigureAwait ( false ) ;
return await ExtendExcel < VmiBalanceSumDetailDto > . WriteDataToExcelInParallel ( "库存余额" , dtos , 5 0 0 0 0 0 ) . ConfigureAwait ( false ) ;
//return fileName;
//return fileName;
}
}
@ -727,49 +725,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
log . ChangedBy = this . _ currentUser . UserName ;
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 )
private int GetVersionByBillTime ( DateTime p_billtime , string p_day )
{
{
@ -1273,7 +1229,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
{
{
itm . BillTime = DateTime . Now ;
itm . BillTime = DateTime . Now ;
itm . ChangedTime = 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 . ChangedQty = itm . Qty ;
itm . Version = GetVersionByBillTime ( itm . BillTime . Value , value ) ;
itm . Version = GetVersionByBillTime ( itm . BillTime . Value , value ) ;
}
}
@ -1430,279 +1386,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
logList . AsParallel ( ) . ForEach ( Update ) ;
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 connectionString = this . _ serviceProvider . GetRequiredService < IConfiguration > ( ) . GetConnectionString ( "SettleAccountService" ) ;
var options = new DbContextOptionsBuilder < SettleAccountDbContext > ( ) . UseSqlServer ( connectionString ) . Options ;
var options = new DbContextOptionsBuilder < SettleAccountDbContext > ( ) . UseSqlServer ( connectionString ) . Options ;
using var context = new SettleAccountDbContext ( options ) ;
using var context = new SettleAccountDbContext ( options ) ;
@ -1711,22 +1394,12 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
try
try
{
{
using var transaction = context . Database . BeginTransaction ( ) ;
using var transaction = context . Database . BeginTransaction ( ) ;
var value = _ codeRepository . FirstOrDefault ( p = > p . Project = = "库存账期" ) . Value ;
var value = _ codeRepository . FirstOrDefault ( p = > p . Project = = "库存账期" ) . Value ;
foreach ( var itm in logList )
foreach ( var itm in logList )
{
{
itm . Version = GetVersionByBillTime ( itm . BillTime . Value , value ) ;
itm . Version = GetVersionByBillTime ( itm . BillTime . Value , value ) ;
}
}
await context . BulkInsertAsync ( logList ) . ConfigureAwait ( false ) ;
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 ( ) ;
transaction . Commit ( ) ;
}
}
catch ( Exception ex )
catch ( Exception ex )
@ -1789,10 +1462,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
using var context = new SettleAccountDbContext ( options ) ;
using var context = new SettleAccountDbContext ( options ) ;
var st = new Stopwatch ( ) ;
var st = new Stopwatch ( ) ;
st . Start ( ) ;
st . Start ( ) ;
try
try
{
{
//导入日志和消息
//导入日志和消息
@ -1822,6 +1491,262 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
}
}
}
}
private async Task < List < ShipReceiveSum > > GetBusinessSum ( IServiceProvider serviceProvider , EnumBusinessType p_businessType , string sebegin , string seend , string sabegin , string saend )
{
List < ShipReceiveSum > ls = new List < ShipReceiveSum > ( ) ;
var connectionString = serviceProvider . GetRequiredService < IConfiguration > ( ) . GetConnectionString ( "SettleAccountService" ) ;
using var connection = new Microsoft . Data . SqlClient . SqlConnection ( connectionString ) ;
connection . Open ( ) ;
var command = connection . CreateCommand ( ) ;
string satablename = string . Empty ;
string setablename = string . Empty ;
string sanottablename = string . Empty ;
string businesstype = string . Empty ;
switch ( p_businessType )
{
case EnumBusinessType . JisBBAC :
satablename = "Set_BBAC_CAN_SA_DETAIL" ;
setablename = "Set_BBAC_SE_DETAIL" ;
sanottablename = "Set_BBAC_NOT_SA_DETAIL" ;
break ;
case EnumBusinessType . JisHBPO :
satablename = "Set_HBPO_CAN_SA_DETAIL" ;
setablename = "Set_HBPO_SE_DETAIL" ;
sanottablename = "Set_HBPO_NOT_SA_DETAIL" ;
break ;
case EnumBusinessType . MaiDanJianHBPO :
satablename = "Set_HBPO_CAN_SA_DETAIL" ;
setablename = "Set_HBPO_SE_DETAIL" ;
sanottablename = "Set_HBPO_NOT_SA_DETAIL" ;
break ;
case EnumBusinessType . MaiDanJianBBAC :
satablename = "Set_BBAC_CAN_SA_DETAIL" ;
setablename = "Set_BBAC_SE_DETAIL" ;
sanottablename = "Set_BBAC_NOT_SA_DETAIL" ;
break ;
default :
satablename = "Set_PUB_CAN_SA_DETAIL" ;
setablename = "Set_PUB_SE_DETAIL" ;
sanottablename = "Set_PUB_NOT_SA_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) 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,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 {sanottablename} 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" ;
command . CommandText = sql ;
command . CommandTimeout = 1 2 0 0 ;
var reader = command . ExecuteReader ( ) ;
while ( reader . Read ( ) )
{
ShipReceiveSum shipReceiveSum = new ShipReceiveSum ( ) ;
shipReceiveSum . LU = reader . GetString ( 0 ) ;
shipReceiveSum . PartCode = "" ;
shipReceiveSum . BusinessType = p_businessType . ToString ( ) ;
shipReceiveSum . BSEQty = reader . GetDecimal ( 1 ) . ToString ( ) ;
shipReceiveSum . BRETQty = reader . GetDecimal ( 2 ) . ToString ( ) ;
shipReceiveSum . SEQTY = reader . GetDecimal ( 3 ) . ToString ( ) ;
shipReceiveSum . RETQty = reader . GetDecimal ( 4 ) . ToString ( ) ;
shipReceiveSum . CANQty = reader . GetDecimal ( 5 ) . ToString ( ) ;
shipReceiveSum . NOTQty = reader . GetDecimal ( 6 ) . ToString ( ) ;
shipReceiveSum . SE_SA_CAN_QTY = reader . GetDecimal ( 7 ) . ToString ( ) ;
shipReceiveSum . SE_SA_NOT_QTY = reader . GetDecimal ( 8 ) . ToString ( ) ;
shipReceiveSum . ONLY_SE_QTY = reader . GetDecimal ( 9 ) . ToString ( ) ;
shipReceiveSum . ONLY_SA_QTY = reader . GetDecimal ( 1 0 ) . ToString ( ) ;
shipReceiveSum . INVQty = reader . GetDecimal ( 1 1 ) . ToString ( ) ;
ls . Add ( shipReceiveSum ) ;
// result += reader.GetString(0) + "," + reader.GetInt64(1) + "," + reader.GetInt64(2) + "," + reader.GetInt64(3) + "," + reader.GetInt64(4) + "," + reader.GetInt64(5) + "," + reader.GetInt64(6) + "," + reader.GetInt64(7) + "," + reader.GetInt64(8) + "," + reader.GetInt64(9) + "," + reader.GetInt64(10) + "," + reader.GetInt64(11) + "," + reader.GetInt64(12) + "," + reader.GetInt64(13) + "," + reader.GetInt64(14) + "\n";
}
reader . Close ( ) ;
connection . Close ( ) ;
return ls ;
}
[HttpPost]
public async Task < string > GetReceiveShipSum ( string sebegin , string seend , string sabegin , string saend )
{
ConcurrentBag < ShipReceiveSum > bagList = new ConcurrentBag < ShipReceiveSum > ( ) ;
List < EnumBusinessType > list = new List < EnumBusinessType > ( ) ;
list . Add ( EnumBusinessType . JisBBAC ) ;
list . Add ( EnumBusinessType . JisHBPO ) ;
list . Add ( EnumBusinessType . MaiDanJianHBPO ) ;
list . Add ( EnumBusinessType . MaiDanJianBBAC ) ;
list . Add ( EnumBusinessType . BeiJian ) ;
list . Add ( EnumBusinessType . ZhiGongJianHBPO ) ;
list . Add ( EnumBusinessType . ZhiGongJianBBAC ) ;
list . Add ( EnumBusinessType . YinDuJian ) ;
Parallel . ForEach ( list , async chunk = >
{
var ls = await GetBusinessSum ( this . _ serviceProvider , chunk , sebegin , seend , sabegin , saend ) . ConfigureAwait ( false ) ;
foreach ( var itm in ls )
{
bagList . Add ( itm ) ;
}
} ) ;
var entities = bagList . ToList < ShipReceiveSum > ( ) ;
IExporter _ csv = new CsvExporter ( ) ;
IExporter _ excel = new ExcelExporter ( ) ;
byte [ ] result = null ;
result = await _ excel . ExportAsByteArray ( entities ) . ConfigureAwait ( false ) ;
result . ShouldNotBeNull ( ) ;
string _f ileName = $"收发存汇总{DateTime.Now.ToString(" yyyyMMddHHmmss ")}.xlsx" ;
//保存导出文件到服务器存成二进制
await _ excelImportService . SaveBlobAsync (
new SaveExcelImportInputDto
{
Name = _f ileName ,
Content = result
}
) . ConfigureAwait ( false ) ;
return _f ileName ;
}
private async Task InvokeInternal ( IServiceProvider serviceProvider )
private async Task InvokeInternal ( IServiceProvider serviceProvider )
{
{
var batchSize = 1 0 0 0 0 ;
var batchSize = 1 0 0 0 0 ;
@ -2214,16 +2139,50 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
public string ErpToLoc { set ; get ; }
public string ErpToLoc { set ; get ; }
[Display(Name = "数量")]
[Display(Name = "数量")]
public decimal Qty { set ; get ; }
public decimal Qty { set ; get ; }
}
public class ShipReceiveSum
{
[Display(Name = "客户零件号")]
public string LU { set ; get ; }
[Display(Name = "厂内零件号")]
public string PartCode { set ; get ; }
[Display(Name = "业务类型")]
public string BusinessType { set ; get ; }
[Display(Name = "期初发货数量")]
public string BSEQty { set ; get ; }
[Display(Name = "期初退货数量")]
public string BRETQty { set ; get ; }
[Display(Name = "实际发货数量")]
public string SEQTY { set ; get ; }
[Display(Name = "实际退货数量")]
public string RETQty { set ; get ; }
[Display(Name = "可结数量")]
public string CANQty { set ; get ; }
[Display(Name = "不可结数量")]
public string NOTQty { set ; get ; }
[Display(Name = "有发有结有价格数量")]
public string SE_SA_CAN_QTY { set ; get ; }
[Display(Name = "有发有结无价格数量")]
public string SE_SA_NOT_QTY { set ; get ; }
[Display(Name = "有发运无结算数量")]
public string ONLY_SE_QTY { set ; get ; }
[Display(Name = "有结算无发运数量")]
public string ONLY_SA_QTY { set ; get ; }
[Display(Name = "已开票数量")]
public string INVQty { set ; get ; }
}
}
// 扩展方法类,用于为IEnumerable类型添加额外功能
// 扩展方法类,用于为IEnumerable类型添加额外功能
public class FileInfoGroup
public class FileInfoGroup