Administrator
3 years ago
9 changed files with 904 additions and 1 deletions
@ -0,0 +1,286 @@ |
|||||
|
using Magicodes.ExporterAndImporter.Core; |
||||
|
using Magicodes.ExporterAndImporter.Csv; |
||||
|
using Magicodes.ExporterAndImporter.Excel; |
||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using Shouldly; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
using Win.Sfs.BaseData.ImportExcelCommon; |
||||
|
using Win.Sfs.SettleAccount.Constant; |
||||
|
using Win.Sfs.SettleAccount.Entities.ImportMap; |
||||
|
using Win.Sfs.SettleAccount.ExcelImporter; |
||||
|
using Win.Sfs.Shared.Filter; |
||||
|
|
||||
|
namespace Win.Sfs.SettleAccount.Entities.Prices |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 标准价格单-相关应用服务
|
||||
|
/// </summary>
|
||||
|
[Authorize(SettleAccountPermissions.PriceLists.Default)] |
||||
|
[Route("api/SettleAccount/PriceList")] |
||||
|
public class PriceListAppServiceBJ : ApplicationService |
||||
|
/*, IPriceListAppService*/ |
||||
|
{ |
||||
|
private readonly PriceListManagerBJ _mng; |
||||
|
private readonly IExcelImportAppService _excelImportService; |
||||
|
private readonly ISettleAccountBranchEfCoreRepository<ImportColumnMap, Guid> _mapRepository; |
||||
|
public PriceListAppServiceBJ( |
||||
|
IExcelImportAppService excelImportService, |
||||
|
ISettleAccountBranchEfCoreRepository<ImportColumnMap, Guid> mapRepository, |
||||
|
PriceListManagerBJ mng |
||||
|
) |
||||
|
{ |
||||
|
_mapRepository = mapRepository; |
||||
|
_excelImportService = excelImportService; |
||||
|
_mng = mng; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 按ID获取唯一实体
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// 返回实体全部属性
|
||||
|
/// </remarks>
|
||||
|
/// <param name="id">ID</param>
|
||||
|
/// <returns>实体DTO</returns>
|
||||
|
|
||||
|
[HttpGet] |
||||
|
[Route("{id}")] |
||||
|
/// [Authorize(SettleAccountPermissions.PriceLists.Default)]
|
||||
|
virtual public async Task<PriceListBJDto> GetAsync(Guid id) |
||||
|
{ |
||||
|
var result = await _mng.GetAsync(id); ; |
||||
|
var dto = ObjectMapper.Map<PriceListBJ, PriceListBJDto>(result); |
||||
|
return dto; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 根据筛选条件获取实体列表
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// 请求条件包括:筛选条件列表,排序条件,数据数量,页码
|
||||
|
/// </remarks>
|
||||
|
/// <param name="input">请求条件</param>
|
||||
|
/// <returns>实体DTO列表</returns>
|
||||
|
[HttpPost] |
||||
|
[Route("list")] |
||||
|
//[Authorize(SettleAccountPermissions.PriceLists.Default)]
|
||||
|
virtual public async Task<PagedResultDto<PriceListBJDto>> GetListAsync(PriceListRequestDto input) |
||||
|
{ |
||||
|
|
||||
|
if (!string.IsNullOrEmpty(input.Version)) |
||||
|
{ |
||||
|
input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "Version", Logic = EnumFilterLogic.And, Value = input.Version }); |
||||
|
} |
||||
|
var entities = await _mng.GetListAsync(input.Filters, input.Sorting, input.MaxResultCount, |
||||
|
input.SkipCount); |
||||
|
var totalCount = await GetCountAsync(input); |
||||
|
var dtos = ObjectMapper.Map<List<PriceListBJ>, List<PriceListBJDto>>(entities); |
||||
|
return new PagedResultDto<PriceListBJDto>(totalCount, dtos); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 根据筛选条件获取实体列表
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// 请求条件包括:筛选条件列表,排序条件,数据数量,页码
|
||||
|
/// </remarks>
|
||||
|
/// <param name="input">请求条件</param>
|
||||
|
/// <returns>实体DTO列表</returns>
|
||||
|
[HttpPost] |
||||
|
[Route("versionlist")] |
||||
|
// [Authorize(SettleAccountPermissions.PriceLists.Default)]
|
||||
|
virtual public async Task<PagedResultDto<PriceListVersionBJDto>> GetVersionListAsync(PriceListRequestDto input) |
||||
|
{ |
||||
|
|
||||
|
|
||||
|
var entities = await _mng.GetVersionListAsync(input.Filters, input.Sorting, input.MaxResultCount,input.SkipCount); |
||||
|
var totalCount = await GetCountAsync(input); |
||||
|
var dtos = ObjectMapper.Map<List<PriceListVersionBJ>, List<PriceListVersionBJDto>>(entities); |
||||
|
return new PagedResultDto<PriceListVersionBJDto>(totalCount, dtos); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
private async Task<long> GetCountAsync(PriceListRequestDto input) |
||||
|
{ |
||||
|
return await _mng.GetCountAsync(input.Filters, GuidGenerator.Create()); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 获取实体总数
|
||||
|
/// </summary>
|
||||
|
/// <returns>实体总数</returns>
|
||||
|
[HttpGet] |
||||
|
[Route("count")] |
||||
|
//[Authorize(SettleAccountPermissions.PriceLists.Default)]
|
||||
|
virtual public async Task<long> GetTotalCountAsync(Guid branchId) |
||||
|
{ |
||||
|
return await _mng.GetCountAsync(new List<FilterCondition>(), branchId); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 获取全部实体列表
|
||||
|
/// </summary>
|
||||
|
/// <returns>实体DTO列表</returns>
|
||||
|
[HttpGet] |
||||
|
[Route("all")] |
||||
|
//[Authorize(SettleAccountPermissions.PriceLists.Default)]
|
||||
|
virtual public async Task<ListResultDto<PriceListBJDto>> GetAllAsync(Guid branchId) |
||||
|
{ |
||||
|
var entities = await _mng.GetAllAsync(branchId); |
||||
|
var dtos = ObjectMapper.Map<List<PriceListBJ>, List<PriceListBJDto>>(entities); |
||||
|
return new ListResultDto<PriceListBJDto>(dtos); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 批量导入实体列表
|
||||
|
/// </summary>
|
||||
|
/// <remarks>
|
||||
|
/// 以ID为依据,数据库中找不到ID的实体会新增,已有ID的实体会修改
|
||||
|
/// </remarks>
|
||||
|
/// <param name="entities">实体列表</param>
|
||||
|
/// <returns>是否导入成功</returns>
|
||||
|
[HttpPost] |
||||
|
[Route("ExcelImport-Map")] |
||||
|
[Authorize(SettleAccountPermissions.PriceLists.Create)] |
||||
|
virtual public async Task<string> ImportAsync([FromForm] IFormFileCollection files,string version) |
||||
|
{ |
||||
|
ExportImporter _exportImporter = new ExportImporter(); |
||||
|
|
||||
|
var result = await _exportImporter.UploadExcelImport<PriceListBJImportDto>(files, _excelImportService); |
||||
|
|
||||
|
var list=result.Where(p => p.Type == 20).ToList(); |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
var entityList = ObjectMapper.Map<List<PriceListBJImportDto>, List<PriceListBJ>>(result); |
||||
|
var _ls = entityList.Where(p=>p.EndDate.ToString().Contains("9999")).GroupBy(p => new { p.MaterialCode, p.CustomerCode,p.Type }).Select(p=>p.FirstOrDefault()); |
||||
|
|
||||
|
foreach (var itm in _ls) |
||||
|
{ |
||||
|
itm.Update(GuidGenerator.Create(),version); |
||||
|
} |
||||
|
await _mng.ImportAsync(_ls.ToList(), version); |
||||
|
return ApplicationConsts.SuccessStr; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 修改实体
|
||||
|
/// </summary>
|
||||
|
/// <param name="id">ID</param>
|
||||
|
/// <param name="input">修改实体DTO</param>
|
||||
|
/// <returns>实体DTO</returns>
|
||||
|
[HttpPut] |
||||
|
[Route("{id}")] |
||||
|
[Authorize(SettleAccountPermissions.PriceLists.Update)] |
||||
|
virtual public async Task<PriceListBJDto> UpdateAsync(Guid id, PriceListBJDto input) |
||||
|
{ |
||||
|
var entity = new PriceListBJ( |
||||
|
|
||||
|
); |
||||
|
|
||||
|
var _ent = await _mng.UpdateAsync(id, entity); |
||||
|
|
||||
|
|
||||
|
var dto = ObjectMapper.Map<PriceListBJ, PriceListBJDto>(_ent); |
||||
|
return dto; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 删除实体
|
||||
|
/// </summary>
|
||||
|
/// <param name="id">ID</param>
|
||||
|
/// <returns>无</returns>
|
||||
|
[HttpDelete] |
||||
|
[Route("{id}")] |
||||
|
//[Authorize(SettleAccountPermissions.PriceLists.Delete)]
|
||||
|
virtual public async Task DeleteAsync(Guid id) |
||||
|
{ |
||||
|
|
||||
|
await _mng.DeleteAsync(id); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 按IDs删除实体列表
|
||||
|
/// </summary>
|
||||
|
/// <param name="ids">ID列表</param>
|
||||
|
/// <returns>是否执行成功</returns>
|
||||
|
[HttpPost] |
||||
|
[Route("delete")] |
||||
|
//[Authorize(SettleAccountPermissions.PriceLists.Delete)]
|
||||
|
virtual public async Task<bool> DeleteListAsync(List<Guid> ids) |
||||
|
{ |
||||
|
|
||||
|
return await _mng.DeleteListAsync(ids); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 导出文件
|
||||
|
/// </summary>
|
||||
|
/// <param name="input"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost] |
||||
|
[Route("Export")] |
||||
|
//[Authorize(SettleAccountPermissions.PriceLists.Default)]
|
||||
|
virtual public async Task<string> ExportAsync(PriceListRequestDto input) |
||||
|
{ |
||||
|
|
||||
|
IExporter _csv = new CsvExporter(); |
||||
|
IExporter _excel = new ExcelExporter(); |
||||
|
var entities = await _mng.GetListAsync(input.Filters, input.Sorting, int.MaxValue, |
||||
|
0, true); |
||||
|
var dtoDetails = ObjectMapper.Map<List<PriceListBJ>, List<PriceListBJExportDto>>(entities); |
||||
|
|
||||
|
string _fileName = string.Empty; |
||||
|
//声明导出容器
|
||||
|
|
||||
|
byte[] result = null; |
||||
|
switch (input.FileType) |
||||
|
{ |
||||
|
case 0: |
||||
|
_fileName = string.Format("标准价格单_{0}.xlsx", Guid.NewGuid().ToString()); |
||||
|
result = await _csv.ExportAsByteArray(dtoDetails); |
||||
|
break; |
||||
|
case 1: |
||||
|
_fileName = string.Format("标准价格单_{0}.xlsx", Guid.NewGuid().ToString()); |
||||
|
result = await _excel.ExportAsByteArray(dtoDetails); |
||||
|
break; |
||||
|
} |
||||
|
result.ShouldNotBeNull(); |
||||
|
|
||||
|
//保存导出文件到服务器存成二进制
|
||||
|
await _excelImportService.SaveBlobAsync( |
||||
|
new SaveExcelImportInputDto |
||||
|
{ |
||||
|
Name = _fileName, |
||||
|
Content = result |
||||
|
} |
||||
|
); |
||||
|
return _fileName; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
Loading…
Reference in new issue