diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs index 13510c91..79fc3bb0 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs @@ -10,12 +10,15 @@ using System.Linq.Dynamic.Core; using System.Reflection; using System.Text.Json; using System.Threading.Tasks; +using AutoMapper; using ClosedXML.Excel; using DocumentFormat.OpenXml; using EFCore.BulkExtensions; using LinqToDB.EntityFrameworkCore; using Magicodes.ExporterAndImporter.Core; using Magicodes.ExporterAndImporter.Core.Extension; +using Magicodes.ExporterAndImporter.Csv; +using Magicodes.ExporterAndImporter.Excel; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -26,7 +29,9 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Omu.ValueInjecter; using RestSharp.Extensions; +using SettleAccount.Domain.BQ; using SettleAccount.Job.SignalR; +using Shouldly; using SqlSugar; using Volo.Abp; using Volo.Abp.Application.Dtos; @@ -37,8 +42,11 @@ using Volo.Abp.Guids; using Volo.Abp.Users; using Volo.Abp.Validation; using Win.Sfs.BaseData.ImportExcelCommon; +using Win.Sfs.SettleAccount.Constant; using Win.Sfs.SettleAccount.Entities.BQ.Dtos; using Win.Sfs.SettleAccount.Entities.BQ.Vmi; +using Win.Sfs.SettleAccount.ExcelImporter; +using Win.Sfs.SettleAccount.ExportReports; using Win.Sfs.Shared; using Win.Sfs.Shared.Filter; using Win.Sfs.Shared.RepositoryBase; @@ -59,7 +67,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ private readonly IHubContext _hubContext; private readonly ICurrentUser _currentUser; private readonly ILogger _logger; - + protected readonly IExcelImportAppService _excelImportService; public VmiAppService(IConfiguration cfg, IServiceProvider serviceProvider, IGuidGenerator guidGenerator, @@ -68,7 +76,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ IBlobContainer fileContainer, IHubContext hubContext, ICurrentUser currentUser, - ILogger logger) + ILogger logger, + IExcelImportAppService excelImportService) { this._cfg = cfg; this._guidGenerator = guidGenerator; @@ -80,6 +89,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ this._currentUser = currentUser; this._logger = logger; LinqToDBForEFTools.Initialize(); + _excelImportService = excelImportService; } /// @@ -403,7 +413,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ //var entities = await _logRepository.GetListByFilterAsync(inputTemp.Filters,null,3,0).ConfigureAwait(false); var beginDate= DateTime.Parse(input.startBillTime).ToString("yyyy/MM/dd") + " 00:00:00 "; - var endDate = DateTime.Parse(input.startBillTime).ToString("yyyy/MM/dd") + " 23:59:59 "; + 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); @@ -415,7 +425,97 @@ namespace Win.Sfs.SettleAccount.Entities.BQ await _fileContainer.SaveAsync(fileName, content, true).ConfigureAwait(false); return fileName; } - + + /// + /// 补货数据导出 + /// + [HttpPost] + public async Task ReplenishedExport1Async(ARequestDto input) + { + RequestDto inputTemp = new RequestDto(); + //inputTemp.Filters.Add(new FilterCondition("BillTime", input.startBillTime, EnumFilterAction.BiggerThanOrEqual, EnumFilterLogic.And)); + //inputTemp.Filters.Add(new FilterCondition("BillTime", input.endBillTime, EnumFilterAction.SmallThanOrEqual, EnumFilterLogic.And)); + + //var entities = await _logRepository.GetListByFilterAsync(inputTemp.Filters,null,3,0).ConfigureAwait(false); + var beginDate = DateTime.Parse(input.startBillTime).ToString("yyyy/MM/dd") + " 00:00:00 "; + 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); + + var entities = await _logRepository.Where(p => p.BillTime >= DateTime.Parse(beginDate) && p.BillTime <= DateTime.Parse(endDate)).ToListAsync(); + //IQueryable query = _logRepository.WhereIf(input.Filters?.Count != 0, input.Filters.ToLambda()); + + + IExporter _csv = new CsvExporter(); + IExporter _excel = new ExcelExporter(); + + + byte[] result = null; + + + result = await _excel.ExportAsByteArray(entities).ConfigureAwait(false); + + result.ShouldNotBeNull(); + + string _fileName = $"导出文件_{Guid.NewGuid().ToString()}.xlsx"; + + + //保存导出文件到服务器存成二进制 + await _excelImportService.SaveBlobAsync( + new SaveExcelImportInputDto + { + Name = _fileName, + Content = result + } + ).ConfigureAwait(false); + return _fileName; + + } + ///// + ///// 输出报错信息 + ///// + ///// + ///// + ///// + //protected async Task ExportErrorReportAsync(List errorList, string fileName = "") + //{ + // //没有信息返回成功 + // if (errorList == null || errorList.Count == 0) + // { + // return ApplicationConsts.SuccessStr; + // } + // if (string.IsNullOrEmpty(fileName)) + // { + // //导出文件名称 + // fileName = CommonMethod.GetExcelFileNameByUserID(ApplicationConsts.CheckErroFileName, _snowflakeIdGenerator.Create().ToString(), ApplicationConsts.FileExtension); + // } + // errorList = errorList.Distinct().OrderBy(p => p.Type).ThenBy(p => p.Model).ThenBy(p => p.ItemCode).ToList(); + // //声明导出容器 + // ExportImporter _exportImporter = new ExportImporter(); + + // var result = await _exportImporter.ExcelExporter(errorList).ConfigureAwait(false); + + // result.ShouldNotBeNull(); + + // //保存导出文件到服务器存成二进制 + // await _excelImportService.SaveBlobAsync( + // new SaveExcelImportInputDto + // { + // Name = fileName, + // Content = result + // } + // ).ConfigureAwait(false); + // return fileName; + //} + + + + + + + + /// /// 4.寄售库存调整 @@ -779,7 +879,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ } } var results = new List(); - Validator.TryValidateObject(model, new ValidationContext(model, null, null), results); + Validator.TryValidateObject(model, new System.ComponentModel.DataAnnotations.ValidationContext (model, null, null), results); list.Add(new Tuple>(model, results)); } return list;