@ -53,6 +53,7 @@ using Volo.Abp;
using Volo.Abp.Application.Dtos ;
using Volo.Abp.Application.Services ;
using Volo.Abp.BlobStoring ;
using Volo.Abp.Data ;
using Volo.Abp.DependencyInjection ;
using Volo.Abp.Domain.Entities ;
using Volo.Abp.Guids ;
@ -70,6 +71,7 @@ using Win.Sfs.SettleAccount.Entities.TaskJobs;
using Win.Sfs.SettleAccount.ExcelImporter ;
using Win.Sfs.SettleAccount.ExportReports ;
using Win.Sfs.Shared ;
using Win.Sfs.Shared.DomainBase ;
using Win.Sfs.Shared.Filter ;
using Win.Sfs.Shared.RepositoryBase ;
@ -1489,11 +1491,24 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
}
}
[HttpPost]
public async Task < string > GetMatchSummar ( EnumBusinessType p_businessType , string sebegin , string seend , string sabegin , string saend )
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 )
@ -1501,22 +1516,27 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
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 =
@ -1559,11 +1579,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
if ( ! string . IsNullOrEmpty ( sebegin ) )
{
sql + = $" AND BillTime > '{sebegin}'\n" ;
sql + = $" AND BillTime >= '{sebegin}'\n" ;
}
if ( ! string . IsNullOrEmpty ( seend ) )
{
sql + = $" AND BillTime <'{seend}'\n" ;
sql + = $" AND BillTime <= '{seend}'\n" ;
}
sql + =
@ -1573,11 +1593,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
if ( ! string . IsNullOrEmpty ( sebegin ) )
{
sql + = $" AND BillTime > '{sebegin}'\n" ;
sql + = $" AND BillTime >= '{sebegin}'\n" ;
}
if ( ! string . IsNullOrEmpty ( seend ) )
{
sql + = $" AND BillTime <'{seend}'\n" ;
sql + = $" AND BillTime <= '{seend}'\n" ;
}
sql + =
"UNION ALL\n" +
@ -1586,23 +1606,23 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
if ( ! string . IsNullOrEmpty ( sebegin ) )
{
sql + = $" AND BillTime > '{sebegin}'\n" ;
sql + = $" AND BillTime >= '{sebegin}'\n" ;
}
if ( ! string . IsNullOrEmpty ( seend ) )
{
sql + = $" AND BillTime <'{seend}'\n" ;
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" ;
$"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" ;
sql + = $" AND BillTime >= '{sebegin}'\n" ;
}
if ( ! string . IsNullOrEmpty ( seend ) )
{
sql + = $" AND BillTime <'{seend}'\n" ;
sql + = $" AND BillTime <= '{seend}'\n" ;
}
sql + = "UNION ALL\n" +
@ -1612,59 +1632,118 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
if ( ! string . IsNullOrEmpty ( sabegin ) )
{
sql + = $" AND SettleDate >'{sabegin}'\n" ;
sql + = $" AND SettleDate >= '{sabegin}'\n" ;
}
if ( ! string . IsNullOrEmpty ( saend ) )
{
sql + = $" AND SettleDate<'{saend}'\n" ;
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" ;
$"from {sanot tablename} A WITH(NOLOCK) WHERE BusinessType={(int)p_businessType} \n" ;
if ( ! string . IsNullOrEmpty ( sabegin ) )
{
sql + = $" AND SettleDate >'{sabegin}'\n" ;
sql + = $" AND SettleDate >= '{sabegin}'\n" ;
}
if ( ! string . IsNullOrEmpty ( saend ) )
{
sql + = $" AND SettleDate<'{saend}'\n" ;
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 ;
"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 ;
}
@ -2060,14 +2139,48 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
public string ErpToLoc { set ; get ; }
[Display(Name = "数量")]
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类型添加额外功能