学 赵 1 year ago
parent
commit
66617746ad
  1. 10
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_SE_EDI_Service.cs
  2. 2
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisBBACSeEdiCompareAppService.cs
  3. 2
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeEdiCompareAppService.cs
  4. 24
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeSyncBaseAppService.cs
  5. 79
      code/src/Modules/SettleAccount/src/SettleAccount.Application/ImportExcelCommon/ExportImporter.cs

10
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_SE_EDI_Service.cs

@ -48,14 +48,14 @@ public class BBAC_SE_EDI_SERVICE : ApplicationService
public async Task<string> ExportAsync(RequestDto input) public async Task<string> ExportAsync(RequestDto input)
{ {
string fileName = $"BBAC的EDI数据_{Guid.NewGuid()}.xlsx"; string fileName = $"BBAC的EDI数据_{Guid.NewGuid()}.xlsx";
var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true); var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true).ConfigureAwait(false); ;
var dtos = ObjectMapper.Map<List<BBAC_SE_EDI>, List<BBAC_SE_EDI_EXPORT_DTO>>(entities); var dtos = ObjectMapper.Map<List<BBAC_SE_EDI>, List<BBAC_SE_EDI_EXPORT_DTO>>(entities);
ExportImporter _exportImporter = new ExportImporter(); ExportImporter _exportImporter = new ExportImporter();
var result = await _exportImporter.ExcelExporter(dtos); var result = await _exportImporter.ExcelExporter(dtos).ConfigureAwait(false); ;
result.ShouldNotBeNull(); result.ShouldNotBeNull();
await _excelImportService.SaveBlobAsync(new SaveExcelImportInputDto { Name = fileName, Content = result }); await _excelImportService.SaveBlobAsync(new SaveExcelImportInputDto { Name = fileName, Content = result }).ConfigureAwait(false); ;
return fileName; return fileName;
} }
#endregion #endregion
@ -67,8 +67,8 @@ public class BBAC_SE_EDI_SERVICE : ApplicationService
[HttpPost] [HttpPost]
public async Task<PagedResultDto<BBAC_SE_EDI_DTO>> GetListAsync(RequestDto input) public async Task<PagedResultDto<BBAC_SE_EDI_DTO>> GetListAsync(RequestDto input)
{ {
var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true); var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true).ConfigureAwait(false);
var totalCount = await _repository.GetCountByFilterAsync(input.Filters); var totalCount = await _repository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false);
var dtos = ObjectMapper.Map<List<BBAC_SE_EDI>, List<BBAC_SE_EDI_DTO>>(entities); var dtos = ObjectMapper.Map<List<BBAC_SE_EDI>, List<BBAC_SE_EDI_DTO>>(entities);
return new PagedResultDto<BBAC_SE_EDI_DTO>(totalCount, dtos); return new PagedResultDto<BBAC_SE_EDI_DTO>(totalCount, dtos);
} }

2
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisBBACSeEdiCompareAppService.cs

@ -92,7 +92,7 @@ public class JisBBACSeEdiCompareAppService : ApplicationService, IInvocable
using var serviceScope = _serviceProvider.CreateScope(); using var serviceScope = _serviceProvider.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); var db = serviceScope.ServiceProvider.GetRequiredService<SettleAccountDbContext>();
//Edi 删除的数据(有发运数据) //Edi 删除的数据(有发运数据)
var ediDelKeyCodes = db.Set<BBAC_SE_EDI>().Where(t => t.IsDeleted == true && t.IsHaveSeData == true).Select(t => new { t.PN, t.LU }).Distinct(); var ediDelKeyCodes = db.Set<BBAC_SE_EDI>().Where(t => t.IsDeleted == true && t.IsHaveSeData == true).Select(t => new { t.PN, t.LU }).Distinct().ToList();
if (ediDelKeyCodes.Any()) if (ediDelKeyCodes.Any())
{ {

2
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeEdiCompareAppService.cs

@ -109,7 +109,7 @@ public class JisHBPOSeEdiCompareAppService : ApplicationService, IInvocable
using var serviceScope = _serviceProvider.CreateScope(); using var serviceScope = _serviceProvider.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); var db = serviceScope.ServiceProvider.GetRequiredService<SettleAccountDbContext>();
//Edi 删除的数据(有发运数据) //Edi 删除的数据(有发运数据)
var ediDelKeyCodes = db.Set<HBPO_SE_EDI>().Where(t => t.IsDeleted == true && t.IsHaveSeData == true).Select(t => new { t.PN, t.LU }).Distinct(); var ediDelKeyCodes = db.Set<HBPO_SE_EDI>().Where(t => t.IsDeleted == true && t.IsHaveSeData == true).Select(t => new { t.PN, t.LU }).Distinct().ToList();
if (ediDelKeyCodes.Any()) if (ediDelKeyCodes.Any())
{ {

24
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeSyncBaseAppService.cs

@ -85,7 +85,7 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable
return; return;
} }
await SyncJitRecordAsync().ConfigureAwait(false); await SyncJitRecordAsync().ConfigureAwait(false);
//await SyncJisRecordAsync().ConfigureAwait(false); await SyncJisRecordAsync().ConfigureAwait(false);
} }
/// <summary> /// <summary>
@ -194,7 +194,7 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable
if (luRePartCodes.Any()) if (luRePartCodes.Any())
{ {
var materialRelationships = luRePartCodes.Select(t => new MaterialRelationship(GuidGenerator.Create(), t.FactoryPartCode, "", t.LU, businessType)); var materialRelationships = luRePartCodes.Select(t => new MaterialRelationship(GuidGenerator.Create(), t.FactoryPartCode, "", t.LU, businessType));
await this.AddNewMaterialRelationships(materialRelationships).ConfigureAwait(false); await _syncExtendManager.AddNewMaterialRelationshipsAsync(materialRelationships).ConfigureAwait(false);
} }
jisSeDetails.ForEach(t => jisSeDetails.ForEach(t =>
@ -226,24 +226,4 @@ public class JisHBPOSeSyncBaseAppService : ApplicationService, IInvocable
} }
} }
} }
/// <summary>
/// 添加零件关系
/// </summary>
public async Task AddNewMaterialRelationships(IEnumerable<MaterialRelationship> materialRelationships)
{
//新客户零件号和厂内零件号
var noHaveLuRePartCodes = from item1 in materialRelationships
join item2 in _settleAccountDbContext.Set<MaterialRelationship>()
on new { item1.ErpMaterialCode, item1.SettleMaterialCode } equals new { item2.ErpMaterialCode, item2.SettleMaterialCode }
into temp
from item3 in temp.DefaultIfEmpty()
where item3 == null
select item1;
if (noHaveLuRePartCodes.Any())
{
await _settleAccountDbContext.BulkInsertAsync(noHaveLuRePartCodes.ToList()).ConfigureAwait(false);
}
}
} }

79
code/src/Modules/SettleAccount/src/SettleAccount.Application/ImportExcelCommon/ExportImporter.cs

@ -92,7 +92,7 @@ namespace Win.Sfs.SettleAccount.ExcelImporter
// Content = memoryStream.ToArray() // Content = memoryStream.ToArray()
// } // }
// ); // );
await fc.SaveAsync(FileOriginName, memoryStream.ToArray(),true).ConfigureAwait(false); await fc.SaveAsync(FileOriginName, memoryStream.ToArray(), true).ConfigureAwait(false);
} }
////读取文件保存的根目录 ////读取文件保存的根目录
//string fileSaveRootDir = ConfigDirHelper.GetAppSetting("App", "FileRootPath"); //string fileSaveRootDir = ConfigDirHelper.GetAppSetting("App", "FileRootPath");
@ -164,6 +164,8 @@ namespace Win.Sfs.SettleAccount.ExcelImporter
public virtual async Task<List<T>> UploadExcelImportByHeadDesc<T>([FromForm] IFormFileCollection files, IExcelImportAppService _excelImportService) public virtual async Task<List<T>> UploadExcelImportByHeadDesc<T>([FromForm] IFormFileCollection files, IExcelImportAppService _excelImportService)
where T : class, new() where T : class, new()
{ {
using var fs = ServiceProvider.CreateScope();
var fc = fs.ServiceProvider.GetRequiredService<IBlobContainer<MyFileContainer>>();
Type type = typeof(T); Type type = typeof(T);
var ImportList = new List<T>(); var ImportList = new List<T>();
ExcelImportResult returnResult = new ExcelImportResult(); ExcelImportResult returnResult = new ExcelImportResult();
@ -182,54 +184,52 @@ namespace Win.Sfs.SettleAccount.ExcelImporter
{ {
//保存成物理文件 //保存成物理文件
await file.CopyToAsync(memoryStream); await file.CopyToAsync(memoryStream);
await _excelImportService.SaveBlobAsync( //await _excelImportService.SaveBlobAsync(
new SaveExcelImportInputDto // new SaveExcelImportInputDto
{ // {
Name = Path.GetFileName(FileOriginName), // Name = Path.GetFileName(FileOriginName),
Content = memoryStream.ToArray() // Content = memoryStream.ToArray()
} // }
); // );
await fc.SaveAsync(FileOriginName, memoryStream.ToArray(), true).ConfigureAwait(false);
} }
//读取文件保存的根目录 ////读取文件保存的根目录
string fileSaveRootDir = ConfigDirHelper.GetAppSetting("App", "FileRootPath"); //string fileSaveRootDir = ConfigDirHelper.GetAppSetting("App", "FileRootPath");
//读取WMS文件保存的模块的根目录 ////读取WMS文件保存的模块的根目录
string fileSaveDir = ConfigDirHelper.GetAppSetting("App", "WMSFiles"); //string fileSaveDir = ConfigDirHelper.GetAppSetting("App", "WMSFiles");
//文件保存的相对文件夹(保存到wwwroot目录下) ////文件保存的相对文件夹(保存到wwwroot目录下)
string absoluteFileDir = fileSaveRootDir + @"\" + fileSaveDir; //string absoluteFileDir = fileSaveRootDir + @"\" + fileSaveDir;
//文件保存的路径(应用的工作目录+文件夹相对路径); ////文件保存的路径(应用的工作目录+文件夹相对路径);
string fileSavePath = Environment.CurrentDirectory + @"\wwwroot\files\host\my-file-container" + absoluteFileDir; //string fileSavePath = Environment.CurrentDirectory + @"\wwwroot\files\host\my-file-container" + absoluteFileDir;
var filePath = fileSavePath + getFileName;//获取到导入的excel //var filePath = fileSavePath + getFileName;//获取到导入的excel
//var import = await _importer.Import<T>(filePath); //var import = await _importer.Import<T>(filePath);
var import = new ImportResult<T>(); var import = new ImportResult<T>();
using (var importer = new ImportHelper<T>(filePath, null)) using (var stream = new MemoryStream())
{ {
import = await importer.Import(null); await file.CopyToAsync(stream).ConfigureAwait(false);
stream.Position = 0;
Stream Stream = new FileStream(filePath, FileMode.Open); IWorkbook wk = new XSSFWorkbook(stream);
using (Stream) //读取当前表数据
ISheet sheet = wk.GetSheetAt(0);
import = await _importer.Import<T>(await fc.GetAsync(FileOriginName).ConfigureAwait(false)).ConfigureAwait(false);
var excelImporterHeadDescAttributeProperties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty)
.Where(o => o.GetCustomAttribute<ExcelImporterHeadDescAttribute>(true) != null);
foreach (var item in excelImporterHeadDescAttributeProperties)
{ {
IWorkbook wk = new XSSFWorkbook(Stream); string propertyName = item.Name;
//读取当前表数据 var excelImporterHeadDesc = item.GetCustomAttribute<ExcelImporterHeadDescAttribute>();
ISheet sheet = wk.GetSheetAt(0); var row = excelImporterHeadDesc.Row;
var cell = excelImporterHeadDesc.Cell;
var value = sheet.GetRow(row).GetCell(cell).ToString();
var excelImporterHeadDescAttributeProperties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty) if (import.Data != null)
.Where(o => o.GetCustomAttribute<ExcelImporterHeadDescAttribute>(true) != null);
foreach (var item in excelImporterHeadDescAttributeProperties)
{ {
string propertyName = item.Name; foreach (var item2 in import.Data)
var excelImporterHeadDesc = item.GetCustomAttribute<ExcelImporterHeadDescAttribute>();
var row = excelImporterHeadDesc.Row;
var cell = excelImporterHeadDesc.Cell;
var value = sheet.GetRow(row).GetCell(cell).ToString();
if (import.Data != null)
{ {
foreach (var item2 in import.Data) item2.GetType().GetProperty(propertyName).SetValue(item2, value);
{
item2.GetType().GetProperty(propertyName).SetValue(item2, value);
}
} }
} }
} }
@ -291,6 +291,7 @@ namespace Win.Sfs.SettleAccount.ExcelImporter
} }
if (_errorList.Count > 0) if (_errorList.Count > 0)
{ {
throw new UserFriendlyException(string.Join("\r\n", _errorList), "400");
throw new BusinessException("8989", string.Join("\r\n", _errorList)); throw new BusinessException("8989", string.Join("\r\n", _errorList));
} }
return ImportList;//返回客户端 return ImportList;//返回客户端

Loading…
Cancel
Save