Browse Source

修改库存事务条件查询,导出提示

master
学 赵 1 year ago
parent
commit
294f133447
  1. 3
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/PD_SERVICE.cs
  2. 132
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs
  3. 2
      code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationModule.cs
  4. 13
      code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Vmi/VmiLog.cs

3
code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/PD_SERVICE.cs

@ -96,7 +96,6 @@ namespace Win.Sfs.SettleAccount.Bases
var totalCount = await _detailRepository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false);
var dtos = ObjectMapper.Map<List<TEntityDetail>, List<TEntityDetailDto>>(entitys);
return new PagedResultDto<TEntityDetailDto>(totalCount, dtos);
}
/// <summary>
/// 导出
@ -272,6 +271,8 @@ namespace Win.Sfs.SettleAccount.Bases
await _repository.DbContext.BulkUpdateAsync(ls);
var _taskid = await p_service.ExportEnqueueAsync($"{first1.BusinessType.ToString()}待扣减任务", ExportExtentsion.Excel, DateTime.Now.ToString("yyyyMM"), string.Empty, CurrentUser, typeof(PendingDeductionService), customConditionList, (rs) =>
{
});
return _taskid;

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

@ -41,6 +41,7 @@ using Volo.Abp.Application.Services;
using Volo.Abp.BlobStoring;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Volo.Abp.ObjectMapping;
using Volo.Abp.Users;
using Volo.Abp.Validation;
using Win.Sfs.BaseData.ImportExcelCommon;
@ -420,61 +421,72 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
[HttpPost]
public async Task<PagedResultDto<VmiLog>> Log(LogRequestDto input)
{
if (input.UseHistory)
{
return await Log2(input).ConfigureAwait(false);
}
//按季度计算查询需要 union 的表名
var start = DateTime.Parse(input.Filters.FirstOrDefault(o => o.Column == "changedTime" && o.Action == EnumFilterAction.BiggerThanOrEqual).Value);
var end = DateTime.Parse(input.Filters.FirstOrDefault(o => o.Column == "changedTime" && o.Action == EnumFilterAction.SmallThan).Value);
var tables = new List<string>();
var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService");
using var connection = new SqlConnection(connectionString);
connection.Open();
for (var time = start; time <= end; time = time.AddMonths(1))
{
var tableName = $"Set_VmiLog_{time.Year}_{(time.Month - 1) / 3 + 1}";
if (!tables.Contains(tableName))
{
var command = connection.CreateCommand();
command.CommandText = $"select OBJECT_ID('{tableName}', 'U')";
var result = command.ExecuteScalar().ToString();
if (result != string.Empty)
{
tables.Add(tableName);
}
else
{
this._logger.LogInformation($"{tableName}不存在");
}
}
}
var options = new DbContextOptionsBuilder<SettleAccountDbContext>().UseSqlServer(connectionString).Options;
using var db = new SettleAccountDbContext(options);
var sql = string.Empty;
if (tables.Any())
{
//生成 union all 的 SQL使用 FromSqlRaw 查询,如果没有分表则使用原始表
sql = $"select * from {tables.First()} WITH(NOLOCK)";
tables.Skip(1).ForEach(o => sql += $" union all select * from {o} WITH(NOLOCK)");
}
else
{
sql = "select * from Set_VmiLog WITH(NOLOCK)";
}
var query = string.IsNullOrEmpty(sql) ? db.Set<VmiLog>().AsQueryable() : db.Set<VmiLog>().FromSqlRaw(sql);
var filters = input.Filters.ToLambda<VmiLog>();
if (input.Filters.Count > 0)
{
query = query.Where(input.Filters.ToLambda<VmiLog>());
}
if (input.LogTypes.Count > 0)
{
query = query.Where(o => input.LogTypes.Contains(o.LogType));
}
var totalCount = query.Count();
query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting);
var entities = await query.PageBy(input.SkipCount, input.MaxResultCount).ToListAsync().ConfigureAwait(false);
//if (input.UseHistory)
//{
// return await Log2(input).ConfigureAwait(false);
//}
////按季度计算查询需要 union 的表名
//var start = DateTime.Parse(input.Filters.FirstOrDefault(o => o.Column == "changedTime" && o.Action == EnumFilterAction.BiggerThanOrEqual).Value);
//var end = DateTime.Parse(input.Filters.FirstOrDefault(o => o.Column == "changedTime" && o.Action == EnumFilterAction.SmallThan).Value);
//var tables = new List<string>();
//var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService");
//using var connection = new SqlConnection(connectionString);
//connection.Open();
//for (var time = start; time <= end; time = time.AddMonths(1))
//{
// var tableName = $"Set_VmiLog_{time.Year}_{(time.Month - 1) / 3 + 1}";
// if (!tables.Contains(tableName))
// {
// var command = connection.CreateCommand();
// command.CommandText = $"select OBJECT_ID('{tableName}', 'U')";
// var result = command.ExecuteScalar().ToString();
// if (result != string.Empty)
// {
// tables.Add(tableName);
// }
// else
// {
// this._logger.LogInformation($"{tableName}不存在");
// }
// }
//}
//var options = new DbContextOptionsBuilder<SettleAccountDbContext>().UseSqlServer(connectionString).Options;
//using var db = new SettleAccountDbContext(options);
//var sql = string.Empty;
//if (tables.Any())
//{
// //生成 union all 的 SQL使用 FromSqlRaw 查询,如果没有分表则使用原始表
// sql = $"select * from {tables.First()} WITH(NOLOCK)";
// tables.Skip(1).ForEach(o => sql += $" union all select * from {o} WITH(NOLOCK)");
//}
//else
//{
// sql = "select * from Set_VmiLog WITH(NOLOCK)";
//}
//var query = string.IsNullOrEmpty(sql) ? db.Set<VmiLog>().AsQueryable() : db.Set<VmiLog>().FromSqlRaw(sql);
//var filters = input.Filters.ToLambda<VmiLog>();
//if (input.Filters.Count > 0)
//{
// query = query.Where(input.Filters.ToLambda<VmiLog>());
//}
//if (input.LogTypes.Count > 0)
//{
// query = query.Where(o => input.LogTypes.Contains(o.LogType));
//}
//var totalCount = query.Count();
//query = string.IsNullOrEmpty(input.Sorting) ? query : DynamicQueryableExtensions.OrderBy(query, input.Sorting);
//var entities = await query.PageBy(input.SkipCount, input.MaxResultCount).ToListAsync().ConfigureAwait(false);
var entities = await _logRepository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount).ConfigureAwait(false);
var totalCount = await _logRepository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false);
return new PagedResultDto<VmiLog>(totalCount, entities);
}
@ -513,6 +525,12 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
{
var entities = await _logRepository.GetListByFilterAsync(input.Filters, input.Sorting).ConfigureAwait(false);
var fileName = $"库存事务_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.xlsx";
if (entities.Count > 1000000)
{
throw new UserFriendlyException("导出行数超过100W不能导出,请重新录入查询条件导出","400");
}
var content = this.GetContent(entities, "库存事务_");
await _fileContainer.SaveAsync(fileName, content, true).ConfigureAwait(false);
return fileName;
@ -614,12 +632,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
var endDate = DateTime.Parse(input.endBillTime).ToString("yyyy/MM/dd") + " 23:59:59 ";
DateTimeFormatInfo dtFormat = new DateTimeFormatInfo();
dtFormat.ShortDatePattern = "yyyy/MM/dd HH:mm:ss";
//DateTime aa= DateTime.ParseExact(DateTime.Parse(input.startBillTime).ToString("yyyy/MM/dd"), "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);
//DateTime aa= DateTime.ParseExact(DateTime.Parse(input.startBillTime).ToString("yyyy/MM/dd"), "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture);
var entities = await _logRepository.Where(p => p.BillTime >= DateTime.Parse(beginDate) && p.BillTime <= DateTime.Parse(endDate)).ToListAsync();
//IQueryable<VmiLog> query = _logRepository.WhereIf(input.Filters?.Count != 0, input.Filters.ToLambda<VmiLog>());
IExporter _csv = new CsvExporter();
IExporter _excel = new ExcelExporter();

2
code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationModule.cs

@ -45,6 +45,8 @@ namespace Win.Sfs.SettleAccount
//context.Services.AddTransient(typeof(INormalEfCoreRepository<,>),
//typeof(SettleAccountNormalEfCoreRepository<,>));
context.Services.AddTransient<IEmailSender, SmtpEmailSender>();
context.Services.AddTransient(implementationFactory =>
{
Func<string, IExportJob> accesor = key =>

13
code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Vmi/VmiLog.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Magicodes.ExporterAndImporter.Core;
using SequentialGuid;
namespace Win.Sfs.SettleAccount.Entities.BQ.Vmi
@ -37,22 +38,22 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Vmi
yield return new ValidationResult("客户客户订单号不能为空", new string[] { nameof(this.OrderNum) });
}
}
[ExporterHeader(DisplayName = "库存事务分类")]
[Display(Name = "库存事务分类", Order = 0)]
public VmiLogType LogType { get; set; }
[ExporterHeader(DisplayName = "变动单号")]
[Display(Name = "变动单号", Order = 1)]
public string ChangedNumber { get; set; }
[ExporterHeader(DisplayName = "变动时间")]
[Display(Name = "变动时间", Order = 2)]
public DateTime ChangedTime { get; set; }
[ExporterHeader(DisplayName = "变动类型")]
[Display(Name = "变动类型", Order = 3)]
public VmiType ChangedType { get; set; }
[ExporterHeader(DisplayName = "变动人")]
[Display(Name = "变动人", Order = 4)]
public string ChangedBy { get; set; }
[ExporterHeader(DisplayName = "库存变动")]
[Display(Name = "库存变动", Order = 5)]
public decimal ChangedQty { get; set; }

Loading…
Cancel
Save