学 赵
1 year ago
5 changed files with 334 additions and 42 deletions
@ -0,0 +1,121 @@ |
|||
using AutoMapper; |
|||
using Magicodes.ExporterAndImporter.Core; |
|||
using Magicodes.ExporterAndImporter.Csv; |
|||
using Magicodes.ExporterAndImporter.Excel; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using SettleAccount.Bases; |
|||
using Shouldly; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.Domain.Entities; |
|||
using Volo.Abp.ObjectMapping; |
|||
using Volo.Abp.TenantManagement.EntityFrameworkCore; |
|||
using Win.Sfs.BaseData.ImportExcelCommon; |
|||
using Win.Sfs.SettleAccount.Entities.BQ; |
|||
using Win.Sfs.SettleAccount.Entities.BQ.Dtos; |
|||
using Win.Sfs.Shared.RepositoryBase; |
|||
|
|||
namespace Win.Sfs.SettleAccount.Bases |
|||
{ |
|||
public class CAN_SA_SERVICE<TEntity, TEntityDto, TEntityDetail, TEntityDetailDto, TRequestMainInput, TRequestDetailInput, TEntityDetailExportDto> :ApplicationService |
|||
where TEntity : class, IEntity<Guid> |
|||
where TEntityDetail:SA_CAN_BASE |
|||
where TEntityDto : class, IEntityDto<Guid>, new() |
|||
where TEntityDetailDto : class, IEntityDto<Guid>, new() |
|||
where TRequestMainInput : RequestInputBase |
|||
where TRequestDetailInput : RequestInputBase |
|||
where TEntityDetailExportDto : class, new() |
|||
{ |
|||
|
|||
private readonly INormalEfCoreRepository<TEntity, Guid> _repository; |
|||
private readonly INormalEfCoreRepository<TEntityDetail, Guid> _detailRepository; |
|||
private readonly IExcelImportAppService _excelImportService; |
|||
|
|||
protected CAN_SA_SERVICE( |
|||
INormalEfCoreRepository<TEntity, Guid> repository, |
|||
IExcelImportAppService excelImportService, |
|||
INormalEfCoreRepository<TEntityDetail, Guid> detailRepository |
|||
|
|||
) |
|||
{ |
|||
_excelImportService = excelImportService; |
|||
_repository = repository; |
|||
_detailRepository = detailRepository; |
|||
|
|||
|
|||
} |
|||
|
|||
[HttpPost] |
|||
//[Route("detailquery")]
|
|||
public virtual async Task<PagedResultDto<TEntityDetailDto>> DetailQueryAsync(TRequestDetailInput input) |
|||
{ |
|||
|
|||
var entitys = await _detailRepository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount); |
|||
var totalCount = await _detailRepository.GetCountByFilterAsync(input.Filters); |
|||
var dtos = ObjectMapper.Map<List<TEntityDetail>, List<TEntityDetailDto>>(entitys); |
|||
return new PagedResultDto<TEntityDetailDto>(totalCount, dtos); |
|||
|
|||
} |
|||
[HttpPost] |
|||
//[Route("export")]
|
|||
public virtual async Task<string> ExportAsync(TRequestDetailInput input) |
|||
{ |
|||
IExporter _csv = new CsvExporter(); |
|||
IExporter _excel = new ExcelExporter(); |
|||
|
|||
var entities = await _detailRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true); |
|||
var dtoDetails = ObjectMapper.Map<List<TEntityDetail>, List<TEntityDetailExportDto>>(entities); |
|||
|
|||
var classDisplayName = typeof(TEntityDetailExportDto).GetCustomAttribute<DisplayAttribute>()?.Name ?? typeof(TEntityDetailExportDto).Name; |
|||
string _fileName = $"{classDisplayName}_{Guid.NewGuid().ToString()}.xlsx"; |
|||
byte[] result = null; |
|||
|
|||
switch (input.FileType) |
|||
{ |
|||
case 0: |
|||
result = await _csv.ExportAsByteArray(dtoDetails); |
|||
break; |
|||
case 1: |
|||
result = await _excel.ExportAsByteArray(dtoDetails); |
|||
break; |
|||
} |
|||
result.ShouldNotBeNull(); |
|||
|
|||
//保存导出文件到服务器存成二进制
|
|||
await _excelImportService.SaveBlobAsync( |
|||
new SaveExcelImportInputDto |
|||
{ |
|||
Name = _fileName, |
|||
Content = result |
|||
} |
|||
); |
|||
return _fileName; |
|||
} |
|||
[HttpPost] |
|||
//[Route("generateinvoice")]
|
|||
public Task<bool> GenerateInvoice(TRequestMainInput input) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
[HttpPost] |
|||
//[Route("mainquery")]
|
|||
public virtual async Task<PagedResultDto<TEntityDto>> MainQueryAsync(TRequestMainInput input) |
|||
{ |
|||
var entitys = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount); |
|||
var totalCount = await _repository.GetCountByFilterAsync(input.Filters); |
|||
var dtos = ObjectMapper.Map<List<TEntity>, List<TEntityDto>>(entitys); |
|||
return new PagedResultDto<TEntityDto>(totalCount, dtos); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
} |
@ -0,0 +1,107 @@ |
|||
using AutoMapper; |
|||
using Magicodes.ExporterAndImporter.Core; |
|||
using Magicodes.ExporterAndImporter.Csv; |
|||
using Magicodes.ExporterAndImporter.Excel; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using SettleAccount.Bases; |
|||
using Shouldly; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.Domain.Entities; |
|||
using Win.Sfs.BaseData.ImportExcelCommon; |
|||
using Win.Sfs.SettleAccount.Entities.BQ.Dtos; |
|||
using Win.Sfs.Shared.RepositoryBase; |
|||
|
|||
namespace Win.Sfs.SettleAccount.Bases |
|||
{ |
|||
internal class NOT_SA_SERVICE<TEntityDetail, TEntityDetailDto, TRequestDetailInput, TEntityDetailExportDto> : ApplicationService |
|||
|
|||
where TEntityDetail : SA_CAN_BASE |
|||
|
|||
where TEntityDetailDto : class, IEntityDto<Guid>, new() |
|||
|
|||
where TRequestDetailInput : RequestInputBase |
|||
where TEntityDetailExportDto : class, new() |
|||
{ |
|||
|
|||
|
|||
private readonly INormalEfCoreRepository<TEntityDetail, Guid> _detailRepository; |
|||
private readonly IExcelImportAppService _excelImportService; |
|||
|
|||
protected NOT_SA_SERVICE( |
|||
|
|||
IExcelImportAppService excelImportService, |
|||
INormalEfCoreRepository<TEntityDetail, Guid> detailRepository |
|||
|
|||
) |
|||
{ |
|||
_excelImportService = excelImportService; |
|||
_detailRepository = detailRepository; |
|||
} |
|||
|
|||
[HttpPost] |
|||
//[Route("detailquery")]
|
|||
public virtual async Task<PagedResultDto<TEntityDetailDto>> DetailQueryAsync(TRequestDetailInput input) |
|||
{ |
|||
|
|||
var entitys = await _detailRepository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount); |
|||
var totalCount = await _detailRepository.GetCountByFilterAsync(input.Filters); |
|||
var dtos = ObjectMapper.Map<List<TEntityDetail>, List<TEntityDetailDto>>(entitys); |
|||
return new PagedResultDto<TEntityDetailDto>(totalCount, dtos); |
|||
|
|||
} |
|||
[HttpPost] |
|||
//[Route("export")]
|
|||
public virtual async Task<string> ExportAsync(TRequestDetailInput input) |
|||
{ |
|||
IExporter _csv = new CsvExporter(); |
|||
IExporter _excel = new ExcelExporter(); |
|||
|
|||
var entities = await _detailRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true); |
|||
var dtoDetails = ObjectMapper.Map<List<TEntityDetail>, List<TEntityDetailExportDto>>(entities); |
|||
|
|||
var classDisplayName = typeof(TEntityDetailExportDto).GetCustomAttribute<DisplayAttribute>()?.Name ?? typeof(TEntityDetailExportDto).Name; |
|||
string _fileName = $"{classDisplayName}_{Guid.NewGuid().ToString()}.xlsx"; |
|||
byte[] result = null; |
|||
|
|||
switch (input.FileType) |
|||
{ |
|||
case 0: |
|||
result = await _csv.ExportAsByteArray(dtoDetails); |
|||
break; |
|||
case 1: |
|||
result = await _excel.ExportAsByteArray(dtoDetails); |
|||
break; |
|||
} |
|||
result.ShouldNotBeNull(); |
|||
|
|||
//保存导出文件到服务器存成二进制
|
|||
await _excelImportService.SaveBlobAsync( |
|||
new SaveExcelImportInputDto |
|||
{ |
|||
Name = _fileName, |
|||
Content = result |
|||
} |
|||
); |
|||
return _fileName; |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
@ -0,0 +1,37 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Win.Sfs.SettleAccount.Bases |
|||
{ |
|||
public class OrderNumberGenerator |
|||
{ |
|||
private static readonly object lockObject = new object(); |
|||
private static int sequence = 0; |
|||
|
|||
/// <summary>
|
|||
/// 如无类别
|
|||
/// </summary>
|
|||
/// <param name="p_OrderType"></param>
|
|||
/// <returns></returns>
|
|||
public static string GenerateOrderNumber(string p_OrderType) |
|||
{ |
|||
lock (lockObject) |
|||
{ |
|||
// 获取当前时间和日期部分
|
|||
string currentDate = DateTime.Now.ToString("yyMMddHHmmss"); |
|||
|
|||
// 获取序列号部分
|
|||
string sequenceNumber = Interlocked.Increment(ref sequence).ToString().PadLeft(6, '0'); |
|||
|
|||
// 拼接单号
|
|||
string orderNumber = $"{p_OrderType}-{currentDate}-{sequenceNumber}"; |
|||
|
|||
return orderNumber; |
|||
} |
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue