|
|
@ -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(); |
|
|
|
|
|
|
|