mahao
1 year ago
9 changed files with 515 additions and 6 deletions
@ -0,0 +1,50 @@ |
|||
using Magicodes.ExporterAndImporter.Core; |
|||
using Magicodes.ExporterAndImporter.Excel; |
|||
|
|||
namespace Win.Sfs.SettleAccount.Reports; |
|||
|
|||
[ExcelExporter(MaxRowNumberOnASheet = 900000)] |
|||
public class PubSaSeCompareDiff |
|||
{ |
|||
/// <summary>
|
|||
/// 零件号
|
|||
/// </summary>
|
|||
[ExporterHeader(DisplayName = "零件号")] |
|||
public string SeLU { set; get; } |
|||
|
|||
/// <summary>
|
|||
/// 生产号
|
|||
/// </summary>
|
|||
[ExporterHeader(DisplayName = "生产号")] |
|||
public string SePN { set; get; } |
|||
|
|||
/// <summary>
|
|||
/// 零件号
|
|||
/// </summary>
|
|||
[ExporterHeader(DisplayName = "零件号")] |
|||
public string SaLU { set; get; } |
|||
|
|||
/// <summary>
|
|||
/// 生产号
|
|||
/// </summary>
|
|||
[ExporterHeader(DisplayName = "生产号")] |
|||
public string SaPN { set; get; } |
|||
|
|||
/// <summary>
|
|||
/// 结算数量
|
|||
/// </summary>
|
|||
[ExporterHeader(DisplayName = "结算数量")] |
|||
public decimal SaQty { set; get; } |
|||
|
|||
/// <summary>
|
|||
/// 发运数量
|
|||
/// </summary>
|
|||
[ExporterHeader(DisplayName = "发运数量")] |
|||
public decimal SeQty { set; get; } |
|||
|
|||
/// <summary>
|
|||
/// 差异数量
|
|||
/// </summary>
|
|||
[ExporterHeader(DisplayName = "差异数量")] |
|||
public decimal DiffQty { set; get; } |
|||
} |
@ -0,0 +1,162 @@ |
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Dapper; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Repositories.Dapper; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Win.Sfs.SettleAccount.Entities; |
|||
using Win.Sfs.SettleAccount.Reports; |
|||
using Win.Sfs.SettleAccount.Reports.InvoiceSettledDiffs; |
|||
|
|||
namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report; |
|||
|
|||
/// <summary>
|
|||
/// Pub结算与发运对比Dapper仓储
|
|||
/// </summary>
|
|||
public class PubSaSeCompareDapperRepository : DapperRepository<SettleAccountDbContext>, ITransientDependency |
|||
{ |
|||
public PubSaSeCompareDapperRepository(IDbContextProvider<SettleAccountDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 获取差异
|
|||
/// </summary>
|
|||
public virtual List<PubSaSeCompareDiff> GetDetailDiffReportList(string version, string businessType) |
|||
{ |
|||
string strSqlText = @$"
|
|||
SELECT |
|||
A.LU SeLU, |
|||
A.PN SePN, |
|||
SeQty, |
|||
B.LU SaLU, |
|||
B.PN SaPN, |
|||
SaQty, |
|||
(SaQty - SeQty) DiffQty |
|||
FROM |
|||
(SELECT SUM(QTY) SeQty, LU, PN FROM Set_PUB_SE_DETAIL WHERE GROUP BY LU, PN) A |
|||
FULL JOIN (SELECT SUM(QTY) SaQty, LU, PN FROM Set_PUB_SA_DETAIL GROUP BY LU, PN) B ON A.LU= B.LU AND A.PN= B.PN |
|||
";
|
|||
return DbConnection.Query<PubSaSeCompareDiff>(strSqlText, null, null, true, 1200, null).ToList(); |
|||
} |
|||
|
|||
public virtual List<InvoiceSettledDetailDiff> GetInvoiceSettledDetailDiffReportList(string version, string materialCode, string begin, string end, string cp7begin, string cp7end, string kennCode, string chassisNumber, string materialGroup) |
|||
{ |
|||
List<InvoiceSettledDetailDiff> _list = new List<InvoiceSettledDetailDiff>(); |
|||
|
|||
if (CacheManager.CacheMaterials != null && CacheManager.CacheInvoiceSettledDetailDiff.Count(p => p.Version == version) > 0) |
|||
{ |
|||
_list = CacheManager.CacheInvoiceSettledDetailDiff.Where(p => p.Version == version).ToList(); |
|||
_list = _list.GroupBy(p => new { p.ChassisNumber, p.MaterialCode, p.ParentSapMaterialCode }).Select(p => p.FirstOrDefault()).ToList(); |
|||
} |
|||
else |
|||
{ |
|||
|
|||
//string isExistSql = string.Format("SELECT count(1) lincount FROM [Set_Settle_RAM] WITH(SNAPSHOT) where Version = '{0}'", version);
|
|||
//int _count = DbConnection.ExecuteScalar<int>(isExistSql);
|
|||
int _count = 0; |
|||
|
|||
string condition = " where 1=1 "; |
|||
if (!string.IsNullOrEmpty(begin)) |
|||
{ |
|||
condition += string.Format(" and a.BeginTime>='{0}' ", begin); |
|||
} |
|||
if (!string.IsNullOrEmpty(end)) |
|||
{ |
|||
condition += string.Format(" and a.BeginTime<='{0}' ", end); |
|||
} |
|||
if (!string.IsNullOrEmpty(cp7begin)) |
|||
{ |
|||
condition += string.Format(" and B.cp7>='{0}' ", cp7begin); |
|||
} |
|||
if (!string.IsNullOrEmpty(cp7end)) |
|||
{ |
|||
condition += string.Format(" and B.cp7<='{0}' ", cp7end); |
|||
} |
|||
|
|||
|
|||
string tablestr = (_count == 0) ? |
|||
" ( SELECT * FROM Set_Settle b WHERE b.Version = '{0}' ) b\n" : |
|||
|
|||
" (SELECT * FROM [Set_Settle_RAM] WITH(SNAPSHOT) where Version = '{0}') b \n"; |
|||
string str = |
|||
"SELECT\n" + |
|||
string.Format(" '{0}' version ,\n", version) + |
|||
" temp1.*,\n" + |
|||
" TEMP2.Price,(\n" + |
|||
" Isnull( temp2.Price, 0 ) * isnull( temp1.Qty, 0 )) Amt \n" + |
|||
"FROM\n" + |
|||
" (\n" + |
|||
" SELECT\n" + |
|||
" b.YEAR,\n" + |
|||
" a.OrderBillNum Kenncode,\n" + |
|||
" b.MaterialCode,\n" + |
|||
" b.Model,\n" + |
|||
" a.ChassisNumber,\n" + |
|||
" a.Qty,\n" + |
|||
" a.BeginTime CP5Time,\n" + |
|||
" a.ChassisNumber2,\n" + |
|||
" B.CP7 CP7Time,\n" + |
|||
" a.QTY SettledQty,\n" + |
|||
" a.ErpMaterialCode ParentSapMaterialCode,\n" + |
|||
" a.WMSState,\n" + |
|||
" a.WMSBillNum,\n" + |
|||
" d.MaterialCode SapMaterialCode,\n" + |
|||
" d.MaterialDesc MaterialDesc,\n" + |
|||
" d.EstimateTypeDesc MaterialGroup,\n" + |
|||
" e.MaterialDesc ParentMaterialDesc,\n" + |
|||
" c.InvoicePrice,\n" + |
|||
" Round( c.InvoicePrice * a.qty,2 ) InvoiceAmt,\n" + |
|||
" Round( c.InvoicePrice * a.Qty,2 ) SettleAmt,\n" + |
|||
" 0 DiffSettleFisQty,\n" + |
|||
" 0 DiffSettleInvQty, \n" + |
|||
" a.Qty InvoiceQty ,\n" + |
|||
" IsNull( B.Qty, 0 ) SettleReadyQty, \n" + |
|||
" a.UnSettleVersion \n" + |
|||
" FROM\n" + |
|||
tablestr + |
|||
|
|||
" INNER JOIN Set_fis a ON b.ChassisNumber = a.ChassisNumber2 \n" + |
|||
" AND b.KENNCode = a.KENNCode \n" + |
|||
" AND b.MaterialCode = a.ItemCode\n" + |
|||
" LEFT JOIN ( SELECT SUM( amt )/ SUM( Qty ) InvoicePrice, MaterialCode FROM set_invoice WHERE version = '{0}' GROUP BY materialcode ) c ON a.ItemCode = c.MaterialCode\n" + |
|||
" LEFT JOIN set_material d ON a.ItemCode = d.CustomerPartCode\n" + |
|||
" LEFT JOIN (select max(Id) Id,MaterialCode,MaterialDesc from Set_material group by MaterialCode,MaterialDesc) e ON a.ErpMaterialCode = e.MaterialCode {1} \n" + |
|||
" ) TEMP1\n" + |
|||
" LEFT JOIN (\n" + |
|||
" SELECT\n" + |
|||
" Price,\n" + |
|||
" MaterialCode \n" + |
|||
" FROM\n" + |
|||
" Set_PriceList \n" + |
|||
" WHERE\n" + |
|||
" version = ( SELECT Max( Version ) FROM Set_PriceList ) and type=10 ) TEMP2 ON TEMP1.SapMaterialCode = TEMP2.MaterialCode"; |
|||
var _sql = string.Format(str, version, condition); |
|||
|
|||
var _query = DbConnection.Query<InvoiceSettledDetailDiff>(_sql, null, null, true, 1200, null); |
|||
|
|||
_list = _query.ToList(); |
|||
|
|||
if (CacheManager.CacheMaterials != null && CacheManager.CacheInvoiceSettledDetailDiff.Count(p => p.Version == version) > 0) |
|||
{ |
|||
_list = CacheManager.CacheInvoiceSettledDetailDiff.Where(p => p.Version == version).ToList(); |
|||
_list = _list.GroupBy(p => new { p.ChassisNumber, p.MaterialCode, p.ParentSapMaterialCode }).Select(p => p.FirstOrDefault()).ToList(); |
|||
} |
|||
else |
|||
{ |
|||
if (CacheManager.CacheInvoiceSettledDetailDiff == null) |
|||
{ |
|||
CacheManager.CacheInvoiceSettledDetailDiff = new List<InvoiceSettledDetailDiff>(); |
|||
} |
|||
CacheManager.CacheInvoiceSettledDetailDiff.AddRange(_list); |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
return _list; |
|||
|
|||
} |
|||
} |
Loading…
Reference in new issue