Browse Source

更新版本

master
zhaoxinyu 11 months ago
parent
commit
fe41cb5b78
  1. 162
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs

162
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs

@ -72,6 +72,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
private readonly INormalEfCoreRepository<VmiBalance, Guid> _balanceRepository; private readonly INormalEfCoreRepository<VmiBalance, Guid> _balanceRepository;
private readonly INormalEfCoreRepository<VmiLog, Guid> _logRepository; private readonly INormalEfCoreRepository<VmiLog, Guid> _logRepository;
private readonly INormalEfCoreRepository<CodeSetting, Guid> _codeRepository; private readonly INormalEfCoreRepository<CodeSetting, Guid> _codeRepository;
private readonly INormalEfCoreRepository<VmiBalanceSumDetail, Guid> _vmiBalanceSumDetailRepository;
private readonly INormalEfCoreRepository<VmiBalanceSum, Guid> _vmiBalanceSumRepository;
private readonly IBlobContainer<MyFileContainer> _fileContainer; private readonly IBlobContainer<MyFileContainer> _fileContainer;
private readonly IHubContext<PageHub> _hubContext; private readonly IHubContext<PageHub> _hubContext;
private readonly ICurrentUser _currentUser; private readonly ICurrentUser _currentUser;
@ -83,9 +87,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
public VmiAppService(IConfiguration cfg, public VmiAppService(IConfiguration cfg,
IServiceProvider serviceProvider, IServiceProvider serviceProvider,
IGuidGenerator guidGenerator, IGuidGenerator guidGenerator,
INormalEfCoreRepository<VmiBalanceSum, Guid> vmiBalanceSumRepository,
INormalEfCoreRepository<VmiBalance, Guid> balanceRepository, INormalEfCoreRepository<VmiBalance, Guid> balanceRepository,
INormalEfCoreRepository<VmiLog, Guid> logRepository, INormalEfCoreRepository<VmiLog, Guid> logRepository,
INormalEfCoreRepository<CodeSetting, Guid> codeRepository, INormalEfCoreRepository<CodeSetting, Guid> codeRepository,
INormalEfCoreRepository<VmiBalanceSumDetail, Guid> vmiBalanceSumDetailRepository,
IBlobContainer<MyFileContainer> fileContainer, IBlobContainer<MyFileContainer> fileContainer,
Volo.Abp.ObjectMapping.IObjectMapper maper, Volo.Abp.ObjectMapping.IObjectMapper maper,
IHubContext<PageHub> hubContext, IHubContext<PageHub> hubContext,
@ -98,6 +104,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
) )
{ {
_vmiBalanceSumRepository = vmiBalanceSumRepository;
_vmiBalanceSumDetailRepository = vmiBalanceSumDetailRepository;
_maper = maper; _maper = maper;
this._codeRepository = codeRepository; this._codeRepository = codeRepository;
this._cfg = cfg; this._cfg = cfg;
@ -201,20 +209,24 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
public async Task<PagedResultDto<VmiBalanceSumDetailDto>> Balance(RequestDto input) public async Task<PagedResultDto<VmiBalanceSumDetailDto>> Balance(RequestDto input)
{ {
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 db = new SettleAccountDbContext(options); //using var db = new SettleAccountDbContext(options);
var query = db.Set<VmiBalanceSumDetail>().AsQueryable(); //var query = db.Set<VmiBalanceSumDetail>().AsQueryable();
var filters = input.Filters.ToLambda<VmiBalanceSumDetailDto>(); //var filters = input.Filters.ToLambda<VmiBalanceSumDetailDto>();
if (input.Filters.Count > 0) //if (input.Filters.Count > 0)
{ //{
query = query.Where(input.Filters.ToLambda<VmiBalanceSumDetailDto>()); // query =_vmiBalanceSumDetailRepository.Where(filters);
} //}
var totalCount = query.Count(); //var totalCount = query.Count();
var entities = await query.PageBy(input.SkipCount, input.MaxResultCount).ToListAsync().ConfigureAwait(false); //var entities = await query.PageBy(input.SkipCount, input.MaxResultCount).ToListAsync().ConfigureAwait(false);
// _maper.Map(VmiBalanceSumDetail,v) //// _maper.Map(VmiBalanceSumDetail,v)
///
var entities = await _vmiBalanceSumDetailRepository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true).ConfigureAwait(false);
var totalCount = await _vmiBalanceSumDetailRepository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false);
var dtos = _maper.Map<List<VmiBalanceSumDetail>, List<VmiBalanceSumDetailDto>>(entities); var dtos = _maper.Map<List<VmiBalanceSumDetail>, List<VmiBalanceSumDetailDto>>(entities);
@ -230,22 +242,28 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
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 db = new SettleAccountDbContext(options); //using var db = new SettleAccountDbContext(options);
var query = db.Set<VmiLog>().FromSqlRaw("select VinCode,ErpToLoc,RealPartCode,ChangedQty ,BillTime,LogType from Set_VmiLog"); //var query = db.Set<VmiLog>().FromSqlRaw("select VinCode,ErpToLoc,RealPartCode,ChangedQty ,BillTime,LogType from Set_VmiLog");
var filters = input.Filters.ToLambda<VmiLog>(); //var filters = input.Filters.ToLambda<VmiLog>();
if (input.Filters.Count > 0) //if (input.Filters.Count > 0)
{ //{
query = query.Where(input.Filters.ToLambda<VmiLog>()); // query = query.Where(input.Filters.ToLambda<VmiLog>());
} //}
query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting); //query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting);
var query2 = query.GroupBy(o => new { o.ErpToLoc, o.RealPartCode, o.VinCode, o.LogType }).Select(o => new VmiBalanceNewDto { VinCode = o.Key.VinCode, ErpToLoc = o.Key.ErpToLoc, RealPartCode = o.Key.RealPartCode, Qty = o.Sum(o => o.ChangedQty), BillTime = o.Max(o => o.BillTime),Se = o.Sum(o => o.LogType == VmiLogType.Type100 ? 1 : 0), ReturnGoods = o.Sum(o => o.LogType == VmiLogType.Type400 ? 1 : 0) }).Where(p => p.Qty != 0); //var query2 = query.GroupBy(o => new { o.ErpToLoc, o.RealPartCode, o.VinCode, o.LogType }).Select(o => new VmiBalanceNewDto { VinCode = o.Key.VinCode, ErpToLoc = o.Key.ErpToLoc, RealPartCode = o.Key.RealPartCode, Qty = o.Sum(o => o.ChangedQty), BillTime = o.Max(o => o.BillTime),Se = o.Sum(o => o.LogType == VmiLogType.Type100 ? 1 : 0), ReturnGoods = o.Sum(o => o.LogType == VmiLogType.Type400 ? 1 : 0) }).Where(p => p.Qty != 0);
var entities = query2.ToList(); //var entities = query2.ToList();
// var entities = await _balanceRepository.GetListByFilterAsync(input.Filters).ConfigureAwait(false); // var entities = await _balanceRepository.GetListByFilterAsync(input.Filters).ConfigureAwait(false);
var entities = await _vmiBalanceSumDetailRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount, true).ConfigureAwait(false);
//var totalCount = await _vmiBalanceSumDetailRepository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false);
var dtos = _maper.Map<List<VmiBalanceSumDetail>, List<VmiBalanceSumDetailDto>>(entities);
var fileName = $"库存余额_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.xlsx"; var fileName = $"库存余额_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.xlsx";
var content = this.GetContent(entities, "库存余额"); var content = this.GetContent(dtos, "库存余额");
await _fileContainer.SaveAsync(fileName, content, true).ConfigureAwait(false); await _fileContainer.SaveAsync(fileName, content, true).ConfigureAwait(false);
return fileName; return fileName;
} }
@ -259,56 +277,74 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
public async Task<PagedResultDto<VmiBalanceSumMainDto>> BalanceSum(RequestDto input) public async Task<PagedResultDto<VmiBalanceSumMainDto>> BalanceSum(RequestDto input)
{ {
var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService");
var options = new DbContextOptionsBuilder<SettleAccountDbContext>().UseSqlServer(connectionString).Options;
using var db = new SettleAccountDbContext(options);
var query = db.Set<VmiBalanceSum>().AsQueryable();
var filters = input.Filters.ToLambda<VmiBalanceSumMainDto>();
if (input.Filters.Count > 0)
{
query = query.Where(input.Filters.ToLambda<VmiBalanceSumMainDto>());
}
query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting);
var totalCount = query.Count();
//var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService"); var entities = await _vmiBalanceSumRepository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true).ConfigureAwait(false);
//var options = new DbContextOptionsBuilder<SettleAccountDbContext>().UseSqlServer(connectionString).Options; var totalCount = await _vmiBalanceSumRepository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false);
//using var db = new SettleAccountDbContext(options);
//var query = db.Set<VmiBalance>().FromSqlRaw("select * from Set_VmiBalance");
//var filters = input.Filters.ToLambda<VmiBalance>();
//if (input.Filters.Count > 0)
//{
// query = query.Where(input.Filters.ToLambda<VmiBalance>());
//}
//var query2 = query.GroupBy(o => new { o.ErpToLoc, o.RealPartCode }).Select(o => new VmiBalanceSumDto { ErpToLoc = o.Key.ErpToLoc, RealPartCode = o.Key.RealPartCode, Qty = o.Sum(o => o.Qty) });
//var totalCount = query2.Count();
//query2 = string.IsNullOrEmpty(input.Sorting) ? query2 : DynamicQueryableExtensions.OrderBy(query2, input.Sorting);
var entities = await query.PageBy(input.SkipCount, input.MaxResultCount).ToListAsync().ConfigureAwait(false);
var dtos = _maper.Map<List<VmiBalanceSum>, List<VmiBalanceSumMainDto>>(entities); var dtos = _maper.Map<List<VmiBalanceSum>, List<VmiBalanceSumMainDto>>(entities);
return new PagedResultDto<VmiBalanceSumMainDto>(totalCount, dtos); return new PagedResultDto<VmiBalanceSumMainDto>(totalCount, dtos);
} }
//var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService");
// var options = new DbContextOptionsBuilder<SettleAccountDbContext>().UseSqlServer(connectionString).Options;
// using var db = new SettleAccountDbContext(options);
// var query = db.Set<VmiBalanceSum>().AsQueryable();
// var filters = input.Filters.ToLambda<VmiBalanceSumMainDto>();
// if (input.Filters.Count > 0)
// {
// query = query.Where(input.Filters.ToLambda<VmiBalanceSumMainDto>());
// }
// query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting);
// var totalCount = query.Count();
// //var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService");
// //var options = new DbContextOptionsBuilder<SettleAccountDbContext>().UseSqlServer(connectionString).Options;
// //using var db = new SettleAccountDbContext(options);
// //var query = db.Set<VmiBalance>().FromSqlRaw("select * from Set_VmiBalance");
// //var filters = input.Filters.ToLambda<VmiBalance>();
// //if (input.Filters.Count > 0)
// //{
// // query = query.Where(input.Filters.ToLambda<VmiBalance>());
// //}
// //var query2 = query.GroupBy(o => new { o.ErpToLoc, o.RealPartCode }).Select(o => new VmiBalanceSumDto { ErpToLoc = o.Key.ErpToLoc, RealPartCode = o.Key.RealPartCode, Qty = o.Sum(o => o.Qty) });
// //var totalCount = query2.Count();
// //query2 = string.IsNullOrEmpty(input.Sorting) ? query2 : DynamicQueryableExtensions.OrderBy(query2, input.Sorting);
// var entities = await query.PageBy(input.SkipCount, input.MaxResultCount).ToListAsync().ConfigureAwait(false);
/// <summary> /// <summary>
/// 1.2库存余额汇总导出 /// 1.2库存余额汇总导出
/// </summary> /// </summary>
[HttpPost] [HttpPost]
public async Task<string> BalanceSumExport(RequestDto input) public async Task<string> BalanceSumExport(RequestDto input)
{ {
var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService"); var entities = await _vmiBalanceSumRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount, true).ConfigureAwait(false);
var options = new DbContextOptionsBuilder<SettleAccountDbContext>().UseSqlServer(connectionString).Options; // var totalCount = await _vmiBalanceSumRepository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false);
using var db = new SettleAccountDbContext(options);
var query = db.Set<VmiLog>().FromSqlRaw("select * from Set_VmiLog");
var filters = input.Filters.ToLambda<VmiLog>(); var dtos = _maper.Map<List<VmiBalanceSum>, List<VmiBalanceSumMainDto>>(entities);
if (input.Filters.Count > 0) //var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService");
{ //var options = new DbContextOptionsBuilder<SettleAccountDbContext>().UseSqlServer(connectionString).Options;
query = query.Where(input.Filters.ToLambda<VmiLog>()); //using var db = new SettleAccountDbContext(options);
} //var query = db.Set<VmiLog>().FromSqlRaw("select * from Set_VmiLog");
query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting); //var filters = input.Filters.ToLambda<VmiLog>();
var query2 = query.GroupBy(o => new { o.ErpToLoc, o.RealPartCode }).Select(o => new VmiBalanceSumDto { ErpToLoc = o.Key.ErpToLoc, RealPartCode = o.Key.RealPartCode, Qty = o.Sum(o => o.ChangedQty) }); //if (input.Filters.Count > 0)
var totalCount = query2.Count(); //{
var entities = await query2.ToListAsync().ConfigureAwait(false); var fileName = $"库存余额_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.xlsx"; // query = query.Where(input.Filters.ToLambda<VmiLog>());
var content = this.GetContent(entities, "库存汇总"); //}
//query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting);
//var query2 = query.GroupBy(o => new { o.ErpToLoc, o.RealPartCode }).Select(o => new VmiBalanceSumDto { ErpToLoc = o.Key.ErpToLoc, RealPartCode = o.Key.RealPartCode, Qty = o.Sum(o => o.ChangedQty) });
//var totalCount = query2.Count();
//var entities = await query2.ToListAsync().ConfigureAwait(false);
var fileName = $"库存余额_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.xlsx";
var content = this.GetContent(dtos, "库存汇总");
await _fileContainer.SaveAsync(fileName, content, true).ConfigureAwait(false); await _fileContainer.SaveAsync(fileName, content, true).ConfigureAwait(false);
return fileName; return fileName;

Loading…
Cancel
Save