zhaoxinyu 5 months ago
parent
commit
99e6e30f58
  1. 4
      code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/Startup.cs
  2. 176
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/NopiDataToExcel.cs
  3. 20
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs
  4. 7
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Jobs/TaskJobService.cs
  5. 2
      code/src/Modules/SettleAccount/src/SettleAccount.Domain.Shared/Enums/EnumWMSSend.cs
  6. 52
      code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisBBACSaSeEdiCompareExportService.cs
  7. 18
      code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisBBACSeEdiCompareExportService.cs
  8. 59
      code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisHBPOSaSeEdiCompareExportService.cs
  9. 18
      code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisHBPOSeEdiCompareExportService.cs
  10. 313
      code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/NopiDataToExcel.cs
  11. 108
      code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SaSeEdiCompareExportBaseService.cs
  12. 76
      code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SeEdiCompareExportBaseService.cs
  13. 1
      code/src/Modules/SettleAccount/src/SettleAccount.Job/SettleAccount.Job.csproj

4
code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/Startup.cs

@ -87,8 +87,8 @@ namespace Win.Sfs.SettleAccount
app.UseEndpoints(endpoints => endpoints.MapHub<PageHub>("/api/hub"));
app.ApplicationServices.UseScheduler(scheduler =>
{
scheduler.Schedule<JisBBACSeEdiCompareAppService>().EveryMinute();
scheduler.Schedule<JisHBPOSeEdiCompareAppService>().EveryMinute();
scheduler.Schedule<JisBBACSeEdiCompareAppService>().EveryThirtyMinutes();
scheduler.Schedule<JisHBPOSeEdiCompareAppService>().EveryThirtyMinutes();
scheduler.Schedule<InvoiceSyncQadInvocable>().EveryMinute();
});
var contentTypeProvider = new FileExtensionContentTypeProvider();

176
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/NopiDataToExcel.cs

@ -1,13 +1,187 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO.Compression;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Magicodes.ExporterAndImporter.Core;
using Minio;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using SettleAccount.Bases;
using System.Diagnostics;
using Magicodes.ExporterAndImporter.Core.Extension;
namespace Win.Sfs.SettleAccount.Entities.BQ
{
public class NopiDataToExcel
public class NopiExtendExcel<T> where T : class, new()
{
static ConcurrentBag<FileInfoGroup> excelFiles = new ConcurrentBag<FileInfoGroup>();
public static string EndPoint { get; set; }
public static string AccessKey { get; set; }
public static string SecretKey { get; set; }
public static string BucketName { get; set; }
public static bool WithSSL { get; set; }
/// <summary>
///
/// </summary>
/// <param name="sheetName">页签名称</param>
/// <param name="data">数据</param>
/// <param name="chunkSize">缓存文件行数</param>
public static async Task<string> WriteDataToExcelInParallel(string sheetName, List<T> data, int chunkSize)
{
Stopwatch sw = Stopwatch.StartNew();
var count = data.Count / 1000000 + ((data.Count % 1000000) > 0 ? 1 : 0);
for (var i = 1; i <= count; i++)
{
var datas = data.Skip((i - 1) * 1000000).Take(1000000).ToList();
var chunks = datas.ChunkBy(chunkSize);
Parallel.ForEach(chunks, chunk =>
{
var fileName = $"{sheetName}_{i - 1}_{Guid.NewGuid()}.xlsx";
var fileinfogroup = new FileInfoGroup((fileName), $"{sheetName}_{i - 1}");
WriteDataToExcel(chunk.ToList(), fileName);
excelFiles.Add(fileinfogroup);
});
}
string[] filePaths = excelFiles.Select(x => x.FileName).ToArray();
string zipPath = $"{sheetName}_{Guid.NewGuid()}.zip";
using (var archive = ZipFile.Open(zipPath, ZipArchiveMode.Create))
{
foreach (var file in filePaths)
{
archive.CreateEntryFromFile(file, Path.GetFileName(file));
}
}
//for (var i = 0; i < count; i++)
//{
// var filelist = excelFiles.Where(p => p.Grpup == $"{sheetName}_{i}").Select(p => p.FileName).ToList();
// //MergeExcelFiles(filelist.ToArray(), $"{sheetName}.xlsx",filelist.First());
// //foreach (var file in filelist)
// //{
// // File.Delete(file);
// //}
//}
sw.Stop();
using (FileStream fileStream = new FileStream(zipPath, FileMode.Open))
{
var minioClient = new MinioClient(EndPoint, AccessKey, SecretKey, "");
try
{
await minioClient.PutObjectAsync(BucketName, zipPath, fileStream, fileStream.Length, "application/zip").ConfigureAwait(false);
}
catch (Exception ex)
{
// Console.WriteLine($"上传文件到 MinIO 时发生错误: {ex.Message}");
}
}
Thread.Sleep(10000);
return zipPath;
//using (FileStream fileStream = new FileStream(zipPath, FileMode.Open))
//{
// return fileStream.GetAllBytes();
//}
}
public static void WriteDataToExcel(List<T> data, string fileName)
{
IWorkbook workbook = new XSSFWorkbook();
ISheet sheet = workbook.CreateSheet("Sheet1");
var firist = data.FirstOrDefault();
var properties = typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty)
.Where(o => o.GetAttributes<ExporterHeaderAttribute>().Any() || o.GetAttributes<DisplayAttribute>().Any())
.ToDictionary(o => o.GetAttribute<ExporterHeaderAttribute>()?.DisplayName ?? o.GetAttribute<DisplayAttribute>()?.Name, o => o);
int columnCellIndex = 0;
int rowIndex = 1;
IRow headerRow = sheet.CreateRow(0);
foreach (var property in properties)
{
headerRow.CreateCell(columnCellIndex).SetCellValue(property.Key);
columnCellIndex++;
}
foreach (var item in data)
{
IRow row = sheet.CreateRow(rowIndex++);
int cellIndex = 0;
foreach (var property in item.GetType().GetProperties())
{
ICell cell = row.CreateCell(cellIndex++);
cell.SetCellValue(property.GetValue(item)?.ToString());
}
}
using (FileStream fileStream = new FileStream(fileName, FileMode.Create))
{
workbook.Write(fileStream);
}
}
public static void MergeExcelFiles(string[] filePaths, string outputFilePath, string sheetName)
{
IWorkbook workbook = new XSSFWorkbook();
ISheet sheet = workbook.CreateSheet(sheetName);
int rowIndex = 0;
foreach (string filePath in filePaths)
{
using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
{
IWorkbook sourceWorkbook = new XSSFWorkbook(fileStream);
ISheet sourceSheet = sourceWorkbook.GetSheetAt(0);
int sourceRowCount = sourceSheet.LastRowNum;
for (int i = 0; i <= sourceRowCount; i++)
{
IRow sourceRow = sourceSheet.GetRow(i);
if (sourceRow != null)
{
IRow targetRow = sheet.CreateRow(rowIndex++);
int cellCount = sourceRow.LastCellNum;
for (int j = 0; j < cellCount; j++)
{
ICell sourceCell = sourceRow.GetCell(j);
if (sourceCell != null)
{
ICell targetCell = targetRow.CreateCell(j);
targetCell.SetCellValue(sourceCell.ToString());
}
}
}
}
}
}
if (File.Exists(outputFilePath))
{
using (FileStream fileStream = new FileStream(outputFilePath, FileMode.Open, FileAccess.ReadWrite))
{
workbook.Write(fileStream);
}
}
else
{
using (FileStream fileStream = new FileStream(outputFilePath, FileMode.Create))
{
workbook.Write(fileStream);
}
}
}
}
}

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

@ -304,22 +304,22 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
var dtos = _maper.Map<List<VmiBalanceSumDetail>, List<VmiBalanceSumDetailDto>>(entities);
dtos = dtos.OrderByDescending(p => p.BillTime).ToList();
var fileName = $"库存余额_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.xlsx";
//ExportImporter _exportImporter = new ExportImporter();
//var result = await _exportImporter.ExcelExporter(dtos).ConfigureAwait(false);
//result.ShouldNotBeNull();
//await _excelImportService.SaveBlobAsync(new SaveExcelImportInputDto { Name = fileName, Content = result }).ConfigureAwait(false);
ExportImporter _exportImporter = new ExportImporter();
var result = await _exportImporter.ExcelExporter(dtos).ConfigureAwait(false);
result.ShouldNotBeNull();
await _excelImportService.SaveBlobAsync(new SaveExcelImportInputDto { Name = fileName, Content = result }).ConfigureAwait(false);
ExtendExcel<VmiBalanceSumDetailDto>.BucketName = _cfg.GetValue("MinIO:BucketName", "default");
//ExtendExcel<VmiBalanceSumDetailDto>.BucketName = _cfg.GetValue("MinIO:BucketName", "default");
ExtendExcel<VmiBalanceSumDetailDto>.AccessKey = _cfg.GetValue("MinIO:AccessKey", "g0GKnhRGEQHI0uiGBYre");
//ExtendExcel<VmiBalanceSumDetailDto>.AccessKey = _cfg.GetValue("MinIO:AccessKey", "g0GKnhRGEQHI0uiGBYre");
ExtendExcel<VmiBalanceSumDetailDto>.SecretKey = _cfg.GetValue("MinIO:SecretKey", "iKGlLz6UBzci3xrERw5Zz1gI77enT5u9agFemHPv");
//ExtendExcel<VmiBalanceSumDetailDto>.SecretKey = _cfg.GetValue("MinIO:SecretKey", "iKGlLz6UBzci3xrERw5Zz1gI77enT5u9agFemHPv");
ExtendExcel<VmiBalanceSumDetailDto>.EndPoint = _cfg.GetValue("MinIO:EndPoint", "localhost:10684/host");
//ExtendExcel<VmiBalanceSumDetailDto>.EndPoint = _cfg.GetValue("MinIO:EndPoint", "localhost:10684/host");
return await ExtendExcel<VmiBalanceSumDetailDto>.WriteDataToExcelInParallel("库存余额", dtos, 500000).ConfigureAwait(false);
//return await ExtendExcel<VmiBalanceSumDetailDto>.WriteDataToExcelInParallel("库存余额", dtos, 500000).ConfigureAwait(false);
//return fileName;
return fileName;
}
/// <summary>

7
code/src/Modules/SettleAccount/src/SettleAccount.Application/Jobs/TaskJobService.cs

@ -215,7 +215,14 @@ namespace Win.Sfs.SettleAccount.Entities.TaskJobs
str = string.Format("{0}_{1}.{2}", currentApplicationName, Guid.NewGuid().ToString(), "cvs");
break;
case ExportExtentsion.Excel:
if(currentApplicationName == "JisBBACEDI与发运数据对比" || currentApplicationName == "JisHBPOEDI与发运数据对比" || currentApplicationName == "JisBBAC结算与发运数据对比" || currentApplicationName == "JisHBPO结算与发运数据对比")
{
str = string.Format("{0}_{1}.{2}", currentApplicationName, Guid.NewGuid().ToString(), "zip");
}
else
{
str = string.Format("{0}_{1}.{2}", currentApplicationName, Guid.NewGuid().ToString(), "xlsx");
}
break;
}
var _serviceName = moudle.FullName;

2
code/src/Modules/SettleAccount/src/SettleAccount.Domain.Shared/Enums/EnumWMSSend.cs

@ -10,7 +10,7 @@ namespace Win.Sfs.SettleAccount.Enums
/// <summary>
/// 未定义
/// </summary>
[Display(Name = "未定义")]
[Display(Name = "")]
None = 0,
/// <summary>
/// WMS多发

52
code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisBBACSaSeEdiCompareExportService.cs

@ -3,9 +3,12 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading;
using Magicodes.ExporterAndImporter.Excel;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Configuration;
using Microsoft.OpenApi.Extensions;
using Minio.DataModel;
using SettleAccount.Domain.BQ;
using SettleAccount.Job.SignalR;
using Shouldly;
@ -18,6 +21,7 @@ using Win.Sfs.BaseData.ImportExcelCommon;
using Win.Sfs.SettleAccount;
using Win.Sfs.SettleAccount.Entities.BQ;
using Win.Sfs.SettleAccount.Reports;
using Win.Sfs.Shared.DomainBase;
namespace SettleAccount.Job.Services.Report
{
@ -49,8 +53,9 @@ namespace SettleAccount.Job.Services.Report
public JisBBACSaSeEdiCompareExportService(
IHubContext<PageHub> hubContext,
IBlobContainer<MyFileContainer> fileContainer,
IConfiguration cfg,
IObjectMapper objectMapper,
SettleAccountDbContext settleAccountDbContext) : base(hubContext, settleAccountDbContext)
SettleAccountDbContext settleAccountDbContext) : base(hubContext, settleAccountDbContext, cfg)
{
_fileContainer = fileContainer;
_objectMapper = objectMapper;
@ -115,12 +120,13 @@ namespace SettleAccount.Job.Services.Report
var excelExporter = new ExcelExporter();
var items = _objectMapper.Map<List<SaSeEdiCompareDiff>, List<SaSeEdiCompareDetailReportJisBBAC>>(saSeEdiCompareDiffs);
excelExporter = BindExcelExporter<SaSeEdiCompareDetailReportJisBBAC>(items, businessTypeDisplayName);
//excelExporter = BindExcelExporter<SaSeEdiCompareDetailReportJisBBAC>(items, businessTypeDisplayName);
var result = excelExporter.ExportAppendDataAsByteArray();
result.ShouldNotBeNull();
_fileContainer.SaveAsync(filename, result.Result, true);
//var result = excelExporter.ExportAppendDataAsByteArray();
//result.ShouldNotBeNull();
//_fileContainer.SaveAsync(filename, result.Result, true);
BindExcelExporter<SaSeEdiCompareDetailReportJisBBAC>(items, businessTypeDisplayName,filename);
//比对完成后更新状态
var pubSaEntityList = _settleAccountDbContext.Set<BBAC_SA>().Where(t => t.Version == version && t.BusinessType == businessType).ToList();
foreach (var item in pubSaEntityList)
@ -130,6 +136,7 @@ namespace SettleAccount.Job.Services.Report
_settleAccountDbContext.SaveChanges();
Thread.Sleep(30000);
Notify();
return id.ToString();
}
@ -162,7 +169,7 @@ namespace SettleAccount.Job.Services.Report
// Price = groupItem.Max(t => t.Price),
// };
var saGroup = from sa in _settleAccountDbContext.Set<BBAC_SA_DETAIL>()
where sa.BusinessType == businessType
where sa.BusinessType == businessType && sa.Version == version
group sa by new { sa.PN, sa.CustomerPartCodeNoSpace } into groupItem
select new
{
@ -193,7 +200,7 @@ namespace SettleAccount.Job.Services.Report
// ErpToLoc = groupItem.Max(t => t.ErpToLoc)
// }).Where(t => t.Qty != 0M);
var seGroup = (from se in _settleAccountDbContext.Set<BBAC_SE_DETAIL>()
where se.BusinessType == businessType
where se.BusinessType == businessType && se.State == 0 && se.IsDeleted == false
group se by new { se.PN, se.CustomerPartCodeNoSpace } into groupItem
select new
{
@ -221,7 +228,7 @@ namespace SettleAccount.Job.Services.Report
// LU = groupItem.Max(t => t.LU)
// };
var ediGroup = from edi in _settleAccountDbContext.Set<BBAC_SE_EDI>()
where edi.IsDeleted == false
where edi.IsDeleted == false && edi.State == 0
group edi by new { edi.PN, edi.CustomerPartCodeNoSpace } into groupItem
select new
{
@ -310,18 +317,31 @@ namespace SettleAccount.Job.Services.Report
};
var saSeCompareFullJoin = saSeCompareLeft.Union(saSeCompareRight).ToList();
var ediCheck = ediGroup.ToList();
foreach (var item in saSeCompareFullJoin)
{
if (!string.IsNullOrEmpty(item.SaCustomerPartCode) && string.IsNullOrEmpty(item.SeCustomerPartCode))
//优化
var haveSaNotSe = saSeCompareFullJoin.Where(p => !string.IsNullOrEmpty(p.SaCustomerPartCode) && string.IsNullOrEmpty(p.SeCustomerPartCode)).ToList();
var ediCheck = ediGroup.ToList().ToDictionary(item=>item.PN+item.LU,item=>item.Qty);
foreach (var item in haveSaNotSe)
{
var ediEntity = ediCheck.FirstOrDefault(p => p.PN == item.PN && p.CustomerPartCodeNoSpace == item.SaCustomerPartCode);
if (ediEntity != null)
//var ediEntity = ediCheck.FirstOrDefault(p => p.PN == item.PN && p.CustomerPartCodeNoSpace == item.SaCustomerPartCode);
//if (ediEntity != null)
//{
// item.EdiCustomerPartCode = item.SaCustomerPartCode;
// item.EdiQty = ediEntity.Qty;
//}
if(ediCheck.TryGetValue(item.PN + item.SaCustomerPartCode,out var v))
{
item.EdiCustomerPartCode = item.SaCustomerPartCode;
item.EdiQty = ediEntity.Qty;
}
item.EdiQty = v;
}
//var ediHave = ediCheck.ContainsKey(item.PN + item.SaCustomerPartCode);
//if (ediHave)
//{
// item.EdiCustomerPartCode = item.SaCustomerPartCode;
// item.EdiQty = ediCheck.FirstOrDefault(p=>p.Key==item.PN + item.SaCustomerPartCode).Value;
//}
}

18
code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisBBACSeEdiCompareExportService.cs

@ -2,7 +2,9 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Configuration;
using SettleAccount.Domain.BQ;
using SettleAccount.Job.SignalR;
using Shouldly;
@ -32,9 +34,9 @@ namespace SettleAccount.Job.Services.Report
/// </summary>
public JisBBACSeEdiCompareExportService(
IHubContext<PageHub> hubContext,
IBlobContainer<MyFileContainer> fileContainer,
IBlobContainer<MyFileContainer> fileContainer, IConfiguration cfg,
IObjectMapper objectMapper,
SettleAccountDbContext settleAccountDbContext) : base(settleAccountDbContext, hubContext)
SettleAccountDbContext settleAccountDbContext) : base(settleAccountDbContext, hubContext, cfg)
{
_fileContainer = fileContainer;
}
@ -54,10 +56,14 @@ namespace SettleAccount.Job.Services.Report
var seEndDateTime = DateTime.Parse(strSeEndDateTime);
var filename = exportName.FirstOrDefault();
var excelExporter = GetSeEdiCompareData<BBAC_SE_DETAIL, BBAC_SE_EDI, SeEidCompareReportJisBBAC>(seStartDateTime, seEndDateTime, EnumBusinessType.JisBBAC);
var result = excelExporter.ExportAppendDataAsByteArray();
result.ShouldNotBeNull();
_fileContainer.SaveAsync(filename, result.Result, true);
//var excelExporter = GetSeEdiCompareData<BBAC_SE_DETAIL, BBAC_SE_EDI, SeEidCompareReportJisBBAC>(seStartDateTime, seEndDateTime, EnumBusinessType.JisBBAC);
//var result = excelExporter.ExportAppendDataAsByteArray();
//result.ShouldNotBeNull();
//_fileContainer.SaveAsync(filename, result.Result, true);
GetSeEdiCompareData<BBAC_SE_DETAIL, BBAC_SE_EDI, SeEidCompareReportJisBBAC>(seStartDateTime, seEndDateTime, EnumBusinessType.JisBBAC, filename);
Thread.Sleep(30000);
Notify();
return id.ToString();

59
code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisHBPOSaSeEdiCompareExportService.cs

@ -3,8 +3,10 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Threading;
using Magicodes.ExporterAndImporter.Excel;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Configuration;
using Microsoft.OpenApi.Extensions;
using NPOI.HPSF;
using NPOI.SS.UserModel;
@ -53,8 +55,9 @@ namespace SettleAccount.Job.Services.Report
public JisHBPOSaSeEdiCompareExportService(
IHubContext<PageHub> hubContext,
IBlobContainer<MyFileContainer> fileContainer,
IConfiguration cfg,
IObjectMapper objectMapper,
SettleAccountDbContext settleAccountDbContext) : base(hubContext, settleAccountDbContext)
SettleAccountDbContext settleAccountDbContext) : base(hubContext, settleAccountDbContext,cfg)
{
_fileContainer = fileContainer;
_objectMapper = objectMapper;
@ -114,19 +117,13 @@ namespace SettleAccount.Job.Services.Report
var excelExporter = new ExcelExporter();
var items = _objectMapper.Map<List<SaSeEdiCompareDiff>, List<SaSeEdiCompareDetailReportJisHBPO>>(saSeEdiCompareDiffs);
//excelExporter = BindExcelExporter<SaSeEdiCompareDetailReportJisHBPO>(items, businessTypeDisplayName);
//var result = excelExporter.ExportAppendDataAsByteArray();
//result.ShouldNotBeNull();
//_fileContainer.SaveAsync(filename, result.Result, true);
excelExporter = BindExcelExporter<SaSeEdiCompareDetailReportJisHBPO>(items, businessTypeDisplayName);
var result = excelExporter.ExportAppendDataAsByteArray();
result.ShouldNotBeNull();
_fileContainer.SaveAsync(filename, result.Result, true);
BindExcelExporter<SaSeEdiCompareDetailReportJisHBPO>(items, businessTypeDisplayName,filename);
//比对完成后更新状态
var pubSaEntityList = _settleAccountDbContext.Set<HBPO_SA>().Where(t => t.Version == version && t.BusinessType == businessType).ToList();
foreach (var item in pubSaEntityList)
@ -136,6 +133,7 @@ namespace SettleAccount.Job.Services.Report
_settleAccountDbContext.SaveChanges();
Thread.Sleep(30000);
Notify();
return id.ToString();
}
@ -196,7 +194,7 @@ namespace SettleAccount.Job.Services.Report
// };
var saGroup = from sa in _settleAccountDbContext.Set<HBPO_SA_DETAIL>()
where sa.BusinessType == businessType
where sa.BusinessType == businessType && sa.Version == version
group sa by new { sa.PN, sa.CustomerPartCodeNoSpace } into groupItem
select new
{
@ -229,7 +227,7 @@ namespace SettleAccount.Job.Services.Report
// }).Where(t => t.Qty != 0M);
var seGroup = (from se in _settleAccountDbContext.Set<HBPO_SE_DETAIL>()
where se.BusinessType == businessType
where se.BusinessType == businessType && se.State == 0 && se.IsDeleted == false
group se by new { se.PN, se.CustomerPartCodeNoSpace } into groupItem
select new
{
@ -258,7 +256,7 @@ namespace SettleAccount.Job.Services.Report
// LU = groupItem.Max(t => t.LU)
// };
var ediGroup = from edi in _settleAccountDbContext.Set<HBPO_SE_EDI>()
where edi.IsDeleted == false
where edi.IsDeleted == false && edi.State == 0
group edi by new { edi.PN, edi.CustomerPartCodeNoSpace } into groupItem
select new
{
@ -391,20 +389,35 @@ namespace SettleAccount.Job.Services.Report
};
var saSeCompareFullJoin = saSeCompareLeft.Union(saSeCompareRight).ToList();
var ediCheck= ediGroup.ToList();
foreach (var item in saSeCompareFullJoin.Where(p=>p.SaCustomerPartCode!=null && p.SeCustomerPartCode==null))
{
if(!string.IsNullOrEmpty(item.SaCustomerPartCode)&& string.IsNullOrEmpty(item.SeCustomerPartCode))
//var ediCheck= ediGroup.ToList();
//foreach (var item in saSeCompareFullJoin.Where(p=>p.SaCustomerPartCode!=null && p.SeCustomerPartCode==null))
//{
// if(!string.IsNullOrEmpty(item.SaCustomerPartCode)&& string.IsNullOrEmpty(item.SeCustomerPartCode))
// {
// var ediEntity= ediCheck.FirstOrDefault(p=>p.PN== item.PN &&p.CustomerPartCodeNoSpace== item.SaCustomerPartCode);
// if(ediEntity!=null)
// {
// item.EdiCustomerPartCode = item.SaCustomerPartCode;
// item.EdiQty = ediEntity.Qty;
// }
// }
//}
//优化
var haveSaNotSe = saSeCompareFullJoin.Where(p => !string.IsNullOrEmpty(p.SaCustomerPartCode) && string.IsNullOrEmpty(p.SeCustomerPartCode)).ToList();
var ediCheck = ediGroup.ToList().ToDictionary(item => item.PN + item.LU, item => item.Qty);
foreach (var item in haveSaNotSe)
{
var ediEntity= ediCheck.FirstOrDefault(p=>p.PN== item.PN &&p.CustomerPartCodeNoSpace== item.SaCustomerPartCode);
if(ediEntity!=null)
if (ediCheck.TryGetValue(item.PN + item.SaCustomerPartCode, out var v))
{
item.EdiCustomerPartCode = item.SaCustomerPartCode;
item.EdiQty = ediEntity.Qty;
}
item.EdiQty = v;
}
}
return saSeCompareFullJoin;
}
#endregion

18
code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/JisHBPOSeEdiCompareExportService.cs

@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Configuration;
using SettleAccount.Domain.BQ;
using SettleAccount.Job.SignalR;
using Shouldly;
@ -30,8 +32,8 @@ namespace SettleAccount.Job.Services.Report
/// </summary>
public JisHBPOSeEdiCompareExportService(
IHubContext<PageHub> hubContext,
IBlobContainer<MyFileContainer> fileContainer,
SettleAccountDbContext settleAccountDbContext) : base(settleAccountDbContext, hubContext)
IBlobContainer<MyFileContainer> fileContainer, IConfiguration cfg,
SettleAccountDbContext settleAccountDbContext) : base(settleAccountDbContext, hubContext, cfg)
{
_fileContainer = fileContainer;
}
@ -51,10 +53,14 @@ namespace SettleAccount.Job.Services.Report
var seEndDateTime = DateTime.Parse(strSeEndDateTime);
var filename = exportName.FirstOrDefault();
var excelExporter = GetSeEdiCompareData<HBPO_SE_DETAIL, HBPO_SE_EDI, SeEidCompareReportJisHBPO>(seStartDateTime, seEndDateTime, EnumBusinessType.JisHBPO);
var result = excelExporter.ExportAppendDataAsByteArray();
result.ShouldNotBeNull();
_fileContainer.SaveAsync(filename, result.Result, true);
//var excelExporter = GetSeEdiCompareData<HBPO_SE_DETAIL, HBPO_SE_EDI, SeEidCompareReportJisHBPO>(seStartDateTime, seEndDateTime, EnumBusinessType.JisHBPO);
//var result = excelExporter.ExportAppendDataAsByteArray();
//result.ShouldNotBeNull();
//_fileContainer.SaveAsync(filename, result.Result, true);
GetSeEdiCompareData<HBPO_SE_DETAIL, HBPO_SE_EDI, SeEidCompareReportJisHBPO>(seStartDateTime, seEndDateTime, EnumBusinessType.JisHBPO, filename);
Thread.Sleep(30000);
Notify();
return id.ToString();

313
code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/NopiDataToExcel.cs

@ -0,0 +1,313 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.IO.Compression;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Magicodes.ExporterAndImporter.Core.Extension;
using Magicodes.ExporterAndImporter.Core;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using SettleAccount.Bases;
using Minio;
using Win.Sfs.SettleAccount.Reports;
using NPOI.XWPF.UserModel;
namespace SettleAccount.Job.Services.Report
{
public class NopiExtendExcel<T> where T : class, new()
{
ConcurrentBag<FileInfoGroup> excelFiles = new ConcurrentBag<FileInfoGroup>();
public string EndPoint { get; set; }
public string AccessKey { get; set; }
public string SecretKey { get; set; }
public string BucketName { get; set; }
public bool WithSSL { get; set; }
/// <summary>
///
/// </summary>
/// <param name="sheetName">页签名称</param>
/// <param name="data">数据</param>
/// <param name="chunkSize">缓存文件行数</param>
public async Task<string> WriteDataToExcelInParallel(string sheetName, List<T> data, int chunkSize,string zipFileName, List<SaSeEdiCompareSumReport> sumdata)
{
var count = data.Count / 1000000 + ((data.Count % 1000000) > 0 ? 1 : 0);
for (var i = 1; i <= count; i++)
{
var datas = data.Skip((i - 1) * 1000000).Take(1000000).ToList();
var chunks = datas.ChunkBy(chunkSize);
Parallel.ForEach(chunks, chunk =>
{
var fileName = $"{sheetName}_{Guid.NewGuid()}.xlsx";
var fileinfogroup = new FileInfoGroup((fileName), $"{sheetName}_{i}");
WriteDataToExcel(chunk.ToList(), fileName);
excelFiles.Add(fileinfogroup);
});
}
if(sumdata!=null)
{
var sumFileName = $"{sheetName}_汇总_{Guid.NewGuid()}.xlsx";
var fileinfogroup = new FileInfoGroup((sumFileName), $"{sheetName}_汇总");
WriteSumDataToExcel(sumdata, sumFileName);
excelFiles.Add(fileinfogroup);
}
string[] filePaths = excelFiles.Select(x => x.FileName).ToArray();
string zipPath = zipFileName;
using (var archive = ZipFile.Open(zipPath, ZipArchiveMode.Create))
{
foreach (var file in filePaths)
{
archive.CreateEntryFromFile(file, Path.GetFileName(file));
}
}
for (var i = 0; i < count; i++)
{
var filelist = excelFiles.Select(p => p.FileName).ToList();
foreach (var file in filelist)
{
File.Delete(file);
}
}
using (FileStream fileStream = new FileStream(zipPath, FileMode.Open))
{
var minioClient = new MinioClient(EndPoint, AccessKey, SecretKey, "");
try
{
await minioClient.PutObjectAsync(BucketName, "host/"+zipPath, fileStream, fileStream.Length, "application/zip").ConfigureAwait(false);
}
catch (Exception ex)
{
Console.WriteLine($"上传文件到 MinIO 时发生错误: {ex.Message}");
}
finally
{
if (fileStream != null)
{
fileStream.Close();
File.Delete(zipPath);
}
}
}
//using (FileStream fileStream = new FileStream(zipPath, FileMode.Open))
//{
// return fileStream.GetAllBytes();
//}
return zipFileName;
}
public void WriteDataToExcel(List<T> data, string fileName)
{
// 每列列宽字典
var dic = new Dictionary<int, int>();
IWorkbook workbook = new XSSFWorkbook();
ISheet sheet = workbook.CreateSheet("数据");
var firist = data.FirstOrDefault();
var properties = typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty)
.Where(o => o.GetAttributes<ExporterHeaderAttribute>().Any() || o.GetAttributes<DisplayAttribute>().Any())
.ToDictionary(o => o.GetAttribute<ExporterHeaderAttribute>()?.DisplayName ?? o.GetAttribute<DisplayAttribute>()?.Name, o => o);
int columnCellIndex = 0;
int rowIndex = 1;
IRow headerRow = sheet.CreateRow(0);
foreach (var property in properties)
{
headerRow.CreateCell(columnCellIndex).SetCellValue(property.Key);
//sheet.AutoSizeColumn(columnCellIndex);
dic.Add(columnCellIndex, Encoding.Default.GetBytes(headerRow.GetCell(columnCellIndex).StringCellValue).Length * 256 + 200);
columnCellIndex++;
}
foreach (var item in data)
{
IRow row = sheet.CreateRow(rowIndex++);
int cellIndex = 0;
foreach (var property in item.GetType().GetProperties())
{
NPOI.SS.UserModel.ICell cell = row.CreateCell(cellIndex);
var propertyType = property.PropertyType;
if (propertyType == typeof(bool))
{
cell.SetCellValue((bool)property.GetValue(item)! ? "是" : "否");
}
else if (propertyType.IsEnum)
{
var value = property.GetValue(item)?.ToString()?.Trim();
var enumValue = (System.Enum.Parse(propertyType, value) as System.Enum);
var type = enumValue.GetType();
var field = type.GetField(enumValue.ToString());
cell.SetCellValue(field.GetCustomAttribute<DisplayAttribute>()?.Name ?? field.Name);
}
else
{
cell.SetCellValue(property.GetValue(item)?.ToString());
}
int length = Encoding.Default.GetBytes(cell.StringCellValue).Length * 256 + 200;
length = length > 15000 ? 15000 : length;
// 若比已存在列宽更宽则替换,Excel限制最大宽度为15000
try
{
if (dic[cellIndex] < length)
{
dic[cellIndex] = length;
}
}
catch(Exception ex)
{
}
cellIndex++;
}
}
for (int i = 0; i < dic.Count; i++)
{
sheet.SetColumnWidth(i, dic[i]);
}
using (FileStream fileStream = new FileStream(fileName, FileMode.Create))
{
workbook.Write(fileStream);
}
}
public void WriteSumDataToExcel(List<SaSeEdiCompareSumReport> data, string fileName)
{
try
{
// 每列列宽字典
var dic = new Dictionary<int, int>();
IWorkbook workbook = new XSSFWorkbook();
ISheet sheet = workbook.CreateSheet("数据");
var firist = data.FirstOrDefault();
var properties = typeof(SaSeEdiCompareSumReport).GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty)
.Where(o => o.GetAttributes<ExporterHeaderAttribute>().Any() || o.GetAttributes<DisplayAttribute>().Any())
.ToDictionary(o => o.GetAttribute<ExporterHeaderAttribute>()?.DisplayName ?? o.GetAttribute<DisplayAttribute>()?.Name, o => o);
int columnCellIndex = 0;
int rowIndex = 1;
IRow headerRow = sheet.CreateRow(0);
foreach (var property in properties)
{
headerRow.CreateCell(columnCellIndex).SetCellValue(property.Key);
//sheet.AutoSizeColumn(columnCellIndex);
dic.Add(columnCellIndex, Encoding.Default.GetBytes(headerRow.GetCell(columnCellIndex).StringCellValue).Length * 256 + 200);
columnCellIndex++;
}
foreach (var item in data)
{
IRow row = sheet.CreateRow(rowIndex++);
int cellIndex = 0;
foreach (var property in item.GetType().GetProperties())
{
NPOI.SS.UserModel.ICell cell = row.CreateCell(cellIndex);
var propertyType = property.PropertyType;
if (propertyType == typeof(bool))
{
cell.SetCellValue((bool)property.GetValue(item)! ? "是" : "否");
}
else if (propertyType.IsEnum)
{
var value = property.GetValue(item)?.ToString()?.Trim();
var enumValue = (System.Enum.Parse(propertyType, value) as System.Enum);
var type = enumValue.GetType();
var field = type.GetField(enumValue.ToString());
cell.SetCellValue(field.GetCustomAttribute<DisplayAttribute>()?.Name ?? field.Name);
}
else if (propertyType.IsValueType)
{
try
{
cell.SetCellValue(double.Parse(property.GetValue(item)?.ToString()));
}
catch
{
cell.SetCellValue(property.GetValue(item)?.ToString());
}
}
else
{
cell.SetCellValue(property.GetValue(item)?.ToString());
}
try
{
int length = Encoding.Default.GetBytes(cell.StringCellValue).Length * 256 + 200;
length = length > 15000 ? 15000 : length;
// 若比已存在列宽更宽则替换,Excel限制最大宽度为15000
if (dic[cellIndex] < length)
{
dic[cellIndex] = length;
}
}
catch (Exception ex)
{
}
cellIndex++;
}
}
for (int i = 0; i < dic.Count; i++)
{
sheet.SetColumnWidth(i, dic[i]);
}
using (FileStream fileStream = new FileStream(fileName, FileMode.Create))
{
workbook.Write(fileStream);
}
}
catch(Exception ex)
{
}
}
}
public class FileInfoGroup
{
public FileInfoGroup(string fileName, string grpup)
{
FileName = fileName;
Grpup = grpup;
}
public string FileName { get; set; }
public string Grpup { get; set; }
}
}

108
code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SaSeEdiCompareExportBaseService.cs

@ -5,6 +5,8 @@ using EFCore.BulkExtensions;
using Magicodes.ExporterAndImporter.Core.Extension;
using Magicodes.ExporterAndImporter.Excel;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Configuration;
using NPOI.HPSF;
using SettleAccount.Bases;
using SettleAccount.Domain.BQ;
using SettleAccount.Job.SignalR;
@ -29,10 +31,13 @@ namespace SettleAccount.Job.Services.Report
/// </summary>
private readonly SettleAccountDbContext _settleAccountDbContext;
public SaSeEdiCompareExportBaseService(IHubContext<PageHub> hubContext, SettleAccountDbContext settleAccountDbContext)
private readonly IConfiguration _cfg;
public SaSeEdiCompareExportBaseService(IHubContext<PageHub> hubContext, SettleAccountDbContext settleAccountDbContext, IConfiguration cfg)
{
_hubContext = hubContext;
_settleAccountDbContext = settleAccountDbContext;
this._cfg = cfg;
}
/// <summary>
@ -170,6 +175,7 @@ namespace SettleAccount.Job.Services.Report
{
o.ErpLoc = i.ToErpLocCode;
o.RealPartCode = i.ReplaceFactoryPartCode;
o.PartCode = i.ReplaceFactoryPartCode;
return o;
}).ToList();
_settleAccountDbContext.BulkUpdate(canSaDetailsUpdate);
@ -185,6 +191,7 @@ namespace SettleAccount.Job.Services.Report
{
o.ErpLoc = i.ToErpLocCode;
o.RealPartCode = i.ReplaceFactoryPartCode;
o.PartCode = i.ReplaceFactoryPartCode;
return o;
}).ToList();
_settleAccountDbContext.BulkUpdate(notSaDetailsUpdate);
@ -233,7 +240,7 @@ namespace SettleAccount.Job.Services.Report
/// <remarks>
/// 根据单Sheel最大行数配置分Sheel页导出
/// </remarks>
public ExcelExporter BindExcelExporter<T>(List<T> saSeEdiCompareDetailExports, string businessTypeDisplayName) where T : SaSeEdiCompareDetailReport, new()
public string BindExcelExporter<T>(List<T> saSeEdiCompareDetailExports, string businessTypeDisplayName,string fileName) where T : SaSeEdiCompareDetailReport, new()
{
//详情Sheet行数
var detailMaxRowNumberOnASheet = AppConst.DefaultRowNumberOnASheet;
@ -299,60 +306,65 @@ namespace SettleAccount.Job.Services.Report
EdiQty = p.Sum(t => t.EdiQty)
}).ToList();
var excelExporter = new ExcelExporter();
//有结算无发运
excelExporter.Append(haveSaNotHaveSeExport.Take(detailMaxRowNumberOnASheet).ToList(), $"{businessTypeDisplayName}有结算无发运");
for (var i = 1; i < haveSaNotHaveSeExport.Count / detailMaxRowNumberOnASheet + ((haveSaNotHaveSeExport.Count % detailMaxRowNumberOnASheet) > 0 ? 1 : 0); i++)
{
var sheetDataItems = haveSaNotHaveSeExport.Skip(i * detailMaxRowNumberOnASheet).Take(detailMaxRowNumberOnASheet).ToList();
excelExporter.Append(sheetDataItems, $"{businessTypeDisplayName}有结算无发运-{i}");
}
//无结算有发运
excelExporter.Append(notHaveSaHaveSeExports.Take(detailMaxRowNumberOnASheet).ToList(), $"{businessTypeDisplayName}无结算有发运");
for (var i = 1; i < notHaveSaHaveSeExports.Count / detailMaxRowNumberOnASheet + ((notHaveSaHaveSeExports.Count % detailMaxRowNumberOnASheet) > 0 ? 1 : 0); i++)
{
var sheetDataItems = notHaveSaHaveSeExports.Skip(i * detailMaxRowNumberOnASheet).Take(detailMaxRowNumberOnASheet).ToList();
excelExporter.Append(sheetDataItems, $"{businessTypeDisplayName}无结算有发运-{i}");
}
////结算核对汇总输出
//excelExporter.Append(saSeEdiCompareSumExports.Take(sumMaxRowNumberOnASheet).ToList(), $"{businessTypeDisplayName}结算核对汇总输出");
//for (var i = 1; i < saSeEdiCompareSumExports.Count / sumMaxRowNumberOnASheet + ((saSeEdiCompareSumExports.Count % sumMaxRowNumberOnASheet) > 0 ? 1 : 0); i++)
#region 多线程生成Excel
haveSaNotHaveSeExport.AddRange(notHaveSaHaveSeExports);
haveSaNotHaveSeExport.AddRange(haveSaHaveSeExport);
NopiExtendExcel<T> nopiExcel = new NopiExtendExcel<T>();
nopiExcel.BucketName = _cfg.GetValue("MinIO:BucketName", "default");
nopiExcel.AccessKey = _cfg.GetValue("MinIO:AccessKey", "g0GKnhRGEQHI0uiGBYre");
nopiExcel.SecretKey = _cfg.GetValue("MinIO:SecretKey", "iKGlLz6UBzci3xrERw5Zz1gI77enT5u9agFemHPv");
nopiExcel.EndPoint = _cfg.GetValue("MinIO:EndPoint", "localhost:10684");
var uploadResult = nopiExcel.WriteDataToExcelInParallel($"{businessTypeDisplayName}结算数据和发货对比", haveSaNotHaveSeExport, 500000, fileName, haveSaHaveSeSumExports).ConfigureAwait(false);
return fileName;
#endregion
#region 单线程生成Excel
//var excelExporter = new ExcelExporter();
////有结算无发运
//excelExporter.Append(haveSaNotHaveSeExport.Take(detailMaxRowNumberOnASheet).ToList(), $"{businessTypeDisplayName}有结算无发运");
//for (var i = 1; i < haveSaNotHaveSeExport.Count / detailMaxRowNumberOnASheet + ((haveSaNotHaveSeExport.Count % detailMaxRowNumberOnASheet) > 0 ? 1 : 0); i++)
//{
// var sheetDataItems = saSeEdiCompareSumExports.Skip(i * sumMaxRowNumberOnASheet).Take(sumMaxRowNumberOnASheet).ToList(); ;
// excelExporter.Append(sheetDataItems, $"{businessTypeDisplayName}结算核对汇总输出-{i}");
// var sheetDataItems = haveSaNotHaveSeExport.Skip(i * detailMaxRowNumberOnASheet).Take(detailMaxRowNumberOnASheet).ToList();
// excelExporter.Append(sheetDataItems, $"{businessTypeDisplayName}有结算无发运-{i}");
//}
////无结算有发运
//excelExporter.Append(notHaveSaHaveSeExports.Take(detailMaxRowNumberOnASheet).ToList(), $"{businessTypeDisplayName}无结算有发运");
//for (var i = 1; i < notHaveSaHaveSeExports.Count / detailMaxRowNumberOnASheet + ((notHaveSaHaveSeExports.Count % detailMaxRowNumberOnASheet) > 0 ? 1 : 0); i++)
//{
// var sheetDataItems = notHaveSaHaveSeExports.Skip(i * detailMaxRowNumberOnASheet).Take(detailMaxRowNumberOnASheet).ToList();
// excelExporter.Append(sheetDataItems, $"{businessTypeDisplayName}无结算有发运-{i}");
//}
//有结算有发货明细输出
excelExporter.Append(haveSaHaveSeExport.Take(detailMaxRowNumberOnASheet).ToList(), $"{businessTypeDisplayName}有结算有发货明细输出");
for (var i = 1; i < haveSaHaveSeExport.Count / detailMaxRowNumberOnASheet + ((haveSaHaveSeExport.Count % detailMaxRowNumberOnASheet) > 0 ? 1 : 0); i++)
{
var sheetDataItems = haveSaHaveSeExport.Skip(i * detailMaxRowNumberOnASheet).Take(detailMaxRowNumberOnASheet).ToList();
excelExporter.Append(sheetDataItems, $"{businessTypeDisplayName}有结算有发货明细输出-{i}");
}
//有结算有发货汇总输出
excelExporter.Append(haveSaHaveSeSumExports.Take(sumMaxRowNumberOnASheet).ToList(), $"{businessTypeDisplayName}有结算有发货汇总输出");
for (var i = 1; i < haveSaHaveSeSumExports.Count / sumMaxRowNumberOnASheet + ((haveSaHaveSeSumExports.Count % sumMaxRowNumberOnASheet) > 0 ? 1 : 0); i++)
{
var sheetDataItems = haveSaHaveSeSumExports.Skip(i * sumMaxRowNumberOnASheet).Take(sumMaxRowNumberOnASheet).ToList();
excelExporter.Append(sheetDataItems, $"{businessTypeDisplayName}有结算有发货汇总输出-{i}");
}
////有结算无发货明细输出
//excelExporter.Append(haveSaNotHaveSeExports.Take(detailMaxRowNumberOnASheet).ToList(), $"{businessTypeDisplayName}有结算无发货明细输出");
//for (var i = 1; i < haveSaNotHaveSeExports.Count / detailMaxRowNumberOnASheet + ((haveSaNotHaveSeExports.Count % detailMaxRowNumberOnASheet) > 0 ? 1 : 0); i++)
////有结算有发货明细输出
//excelExporter.Append(haveSaHaveSeExport.Take(detailMaxRowNumberOnASheet).ToList(), $"{businessTypeDisplayName}有结算有发货明细输出");
//for (var i = 1; i < haveSaHaveSeExport.Count / detailMaxRowNumberOnASheet + ((haveSaHaveSeExport.Count % detailMaxRowNumberOnASheet) > 0 ? 1 : 0); i++)
//{
// var sheetDataItems = haveSaNotHaveSeExports.Skip(i * detailMaxRowNumberOnASheet).Take(detailMaxRowNumberOnASheet).ToList();
// excelExporter.Append(sheetDataItems, $"{businessTypeDisplayName}有结算发货明细输出-{i}");
// var sheetDataItems = haveSaHaveSeExport.Skip(i * detailMaxRowNumberOnASheet).Take(detailMaxRowNumberOnASheet).ToList();
// excelExporter.Append(sheetDataItems, $"{businessTypeDisplayName}有结算有发货明细输出-{i}");
//}
////有结算发货汇总输出
//excelExporter.Append(haveSaNotHaveSeSumExports.Take(sumMaxRowNumberOnASheet).ToList(), $"{businessTypeDisplayName}有结算发货汇总输出");
//for (var i = 1; i < haveSaNotHaveSeSumExports.Count / sumMaxRowNumberOnASheet + ((haveSaNotHaveSeSumExports.Count % sumMaxRowNumberOnASheet) > 0 ? 1 : 0); i++)
////有结算有发货汇总输出
//excelExporter.Append(haveSaHaveSeSumExports.Take(sumMaxRowNumberOnASheet).ToList(), $"{businessTypeDisplayName}有结算有发货汇总输出");
//for (var i = 1; i < haveSaHaveSeSumExports.Count / sumMaxRowNumberOnASheet + ((haveSaHaveSeSumExports.Count % sumMaxRowNumberOnASheet) > 0 ? 1 : 0); i++)
//{
// var sheetDataItems = haveSaNotHaveSeSumExports.Skip(i * sumMaxRowNumberOnASheet).Take(sumMaxRowNumberOnASheet).ToList();
// excelExporter.Append(sheetDataItems, $"{businessTypeDisplayName}有结算发货汇总输出-{i}");
// var sheetDataItems = haveSaHaveSeSumExports.Skip(i * sumMaxRowNumberOnASheet).Take(sumMaxRowNumberOnASheet).ToList();
// excelExporter.Append(sheetDataItems, $"{businessTypeDisplayName}有结算有发货汇总输出-{i}");
//}
return excelExporter;
//return excelExporter;
#endregion
}
/// <summary>

76
code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SeEdiCompareExportBaseService.cs

@ -23,6 +23,11 @@ using Win.Sfs.SettleAccount;
using Win.Sfs.SettleAccount.Consts;
using Win.Sfs.SettleAccount.Entities.BQ.Syncs;
using Win.Sfs.SettleAccount.Reports;
using NPOI.POIFS.Properties;
using Shouldly;
using Win.Sfs.BaseData.ImportExcelCommon;
using static Microsoft.Extensions.Logging.EventSource.LoggingEventSource;
using Microsoft.Extensions.Configuration;
namespace SettleAccount.Job.Services.Report
{
@ -40,10 +45,13 @@ namespace SettleAccount.Job.Services.Report
/// </summary>
private readonly IHubContext<PageHub> _hubContext;
public SeEdiCompareExportBaseService(SettleAccountDbContext settleAccountDbContext, IHubContext<PageHub> hubContext)
private readonly IConfiguration _cfg;
public SeEdiCompareExportBaseService(SettleAccountDbContext settleAccountDbContext, IHubContext<PageHub> hubContext, IConfiguration cfg)
{
_settleAccountDbContext = settleAccountDbContext;
_hubContext = hubContext;
this._cfg = cfg;
}
#region 方法
@ -56,7 +64,7 @@ namespace SettleAccount.Job.Services.Report
/// 检索时间段内有Edi有发运的数据
/// 根据导出Excel配置的最大行数分Sheel
/// </remarks>
public ExcelExporter GetSeEdiCompareData<TSe, TEdi, TCompareReport>(DateTime seStartDateTime, DateTime seEndDateTime, EnumBusinessType businessType)
public string GetSeEdiCompareData<TSe, TEdi, TCompareReport>(DateTime seStartDateTime, DateTime seEndDateTime, EnumBusinessType businessType,string fileName)
where TSe : JisSeBase
where TEdi : SE_EDI
where TCompareReport : SeEidCompareReport, new()
@ -208,21 +216,45 @@ namespace SettleAccount.Job.Services.Report
//生成对比Excel文件
var excelExporter = new ExcelExporter();
// EDI数据和发货对比
excelExporter.Append(haveEdiNotHaveSeList.Take(maxRowNumberOnASheet).ToList(), $"{businessTypeDisplayName}EDI数据和发货对比");
for (var i = 1; i < haveEdiNotHaveSeList.Count / maxRowNumberOnASheet + ((haveEdiNotHaveSeList.Count % maxRowNumberOnASheet) > 0 ? 1 : 0); i++)
{
var sheetDataItems = haveEdiNotHaveSeList.Skip(i * maxRowNumberOnASheet).Take(maxRowNumberOnASheet).ToList();
excelExporter.Append(sheetDataItems, $"{businessTypeDisplayName}EDI数据和发货对比-{i}");
}
// 发货和EDI数据对比
excelExporter.Append(notHaveEdiHaveSeList.Take(maxRowNumberOnASheet).ToList(), $"{businessTypeDisplayName}发货和EDI数据对比");
for (var i = 1; i < notHaveEdiHaveSeList.Count / maxRowNumberOnASheet + ((haveEdiNotHaveSeList.Count % maxRowNumberOnASheet) > 0 ? 1 : 0); i++)
{
var sheetDataItems = notHaveEdiHaveSeList.Skip(i * maxRowNumberOnASheet).Take(maxRowNumberOnASheet).ToList();
excelExporter.Append(sheetDataItems, $"{businessTypeDisplayName}发货和EDI数据对比-{i}");
}
return excelExporter;
#region 多线程生成Excel
//var pageCount = CalculatePageCount(haveEdiNotHaveSeList.Count, maxRowNumberOnASheet);
haveEdiNotHaveSeList.AddRange(notHaveEdiHaveSeList);
NopiExtendExcel<TCompareReport> nopiExcelHaveEdiNotHaveSe = new NopiExtendExcel<TCompareReport>();
nopiExcelHaveEdiNotHaveSe.BucketName = _cfg.GetValue("MinIO:BucketName", "default");
nopiExcelHaveEdiNotHaveSe.AccessKey = _cfg.GetValue("MinIO:AccessKey", "g0GKnhRGEQHI0uiGBYre");
nopiExcelHaveEdiNotHaveSe.SecretKey = _cfg.GetValue("MinIO:SecretKey", "iKGlLz6UBzci3xrERw5Zz1gI77enT5u9agFemHPv");
nopiExcelHaveEdiNotHaveSe.EndPoint = _cfg.GetValue("MinIO:EndPoint", "localhost:10684");
var uploadResult = nopiExcelHaveEdiNotHaveSe.WriteDataToExcelInParallel($"{businessTypeDisplayName}EDI数据和发货对比", haveEdiNotHaveSeList, 500000,fileName,null).ConfigureAwait(false);
return fileName;
#endregion
//// EDI数据和发货对比
//excelExporter.Append(haveEdiNotHaveSeList.Take(maxRowNumberOnASheet).ToList(), $"{businessTypeDisplayName}EDI数据和发货对比");
//for (var i = 1; i < haveEdiNotHaveSeList.Count / maxRowNumberOnASheet + ((haveEdiNotHaveSeList.Count % maxRowNumberOnASheet) > 0 ? 1 : 0); i++)
//{
// var sheetDataItems = haveEdiNotHaveSeList.Skip(i * maxRowNumberOnASheet).Take(maxRowNumberOnASheet).ToList();
// excelExporter.Append(sheetDataItems, $"{businessTypeDisplayName}EDI数据和发货对比-{i}");
//}
//// 发货和EDI数据对比
//excelExporter.Append(notHaveEdiHaveSeList.Take(maxRowNumberOnASheet).ToList(), $"{businessTypeDisplayName}发货和EDI数据对比");
//for (var i = 1; i < notHaveEdiHaveSeList.Count / maxRowNumberOnASheet + ((haveEdiNotHaveSeList.Count % maxRowNumberOnASheet) > 0 ? 1 : 0); i++)
//{
// var sheetDataItems = notHaveEdiHaveSeList.Skip(i * maxRowNumberOnASheet).Take(maxRowNumberOnASheet).ToList();
// excelExporter.Append(sheetDataItems, $"{businessTypeDisplayName}发货和EDI数据对比-{i}");
//}
//return excelExporter;
}
/// <summary>
@ -233,6 +265,16 @@ namespace SettleAccount.Job.Services.Report
_hubContext.Clients.All.ServerToClient("SaSeCompare", "refresh", "");
}
private int CalculatePageCount(int totalCount, int pageSize)
{
int pageCount = totalCount / pageSize;
if (totalCount % pageSize != 0)
{
pageCount += 1;
}
return pageCount;
}
/// <summary>
/// 获取生产码日期
/// </summary>

1
code/src/Modules/SettleAccount/src/SettleAccount.Job/SettleAccount.Job.csproj

@ -16,6 +16,7 @@
<PackageReference Include="Volo.Abp.BackgroundWorkers" Version="4.3.3" />
<PackageReference Include="Volo.Abp.BlobStoring" Version="4.3.3" />
<PackageReference Include="Volo.Abp.BlobStoring.FileSystem" Version="4.3.3" />
<PackageReference Include="Volo.Abp.BlobStoring.Minio" Version="4.3.3" />
<PackageReference Include="Volo.Abp.Emailing" Version="4.3.3" />
</ItemGroup>

Loading…
Cancel
Save