mahao
1 year ago
5 changed files with 229 additions and 0 deletions
@ -0,0 +1,67 @@ |
|||||
|
using Magicodes.ExporterAndImporter.Core; |
||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
using Win.Sfs.Shared.DtoBase; |
||||
|
|
||||
|
namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 采购价格单
|
||||
|
/// </summary>
|
||||
|
public class PURCHASE_PRICE_DTO |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 零件号
|
||||
|
/// </summary>
|
||||
|
[Display(Name = "零件号")] |
||||
|
public string LU { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 价格
|
||||
|
/// </summary>
|
||||
|
[Display(Name = "价格")] |
||||
|
public decimal Price { get; set; } |
||||
|
} |
||||
|
|
||||
|
public class PURCHASE_PRICE_IMPORT_DTO |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 零件号
|
||||
|
/// </summary>
|
||||
|
[Display(Name = "零件号")] |
||||
|
[ImporterHeader(Name = "零件号")] |
||||
|
public string LU { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 价格
|
||||
|
/// </summary>
|
||||
|
[Display(Name = "价格")] |
||||
|
[ImporterHeader(Name = "价格")] |
||||
|
public decimal Price { get; set; } |
||||
|
} |
||||
|
|
||||
|
public class PURCHASE_PRICE_REQUEST_DTO : RequestDtoBase |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 导出
|
||||
|
/// </summary>
|
||||
|
public class PURCHASE_PRICE_EXPORT_DTO |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 零件号
|
||||
|
/// </summary>
|
||||
|
[Display(Name = "零件号")] |
||||
|
[ExporterHeader(DisplayName = "零件号")] |
||||
|
public string LU { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 价格
|
||||
|
/// </summary>
|
||||
|
[Display(Name = "价格")] |
||||
|
[ExporterHeader(DisplayName = "价格")] |
||||
|
public decimal Price { get; set; } |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,8 @@ |
|||||
|
using Win.Sfs.Shared.DtoBase; |
||||
|
|
||||
|
namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos |
||||
|
{ |
||||
|
public class RequestDto : RequestDtoBase |
||||
|
{ |
||||
|
} |
||||
|
} |
@ -0,0 +1,131 @@ |
|||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using SettleAccount.Domain.BQ; |
||||
|
using Shouldly; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.Caching; |
||||
|
using Win.Abp.Snowflakes; |
||||
|
using Win.Sfs.BaseData.ImportExcelCommon; |
||||
|
using Win.Sfs.SettleAccount.CommonManagers; |
||||
|
using Win.Sfs.SettleAccount.Constant; |
||||
|
using Win.Sfs.SettleAccount.Entities.BQ.Dtos; |
||||
|
using Win.Sfs.SettleAccount.ExcelImporter; |
||||
|
using Win.Sfs.SettleAccount.ExportReports; |
||||
|
using Win.Sfs.SettleAccount.MaterialRelationships; |
||||
|
using Win.Sfs.Shared.DtoBase; |
||||
|
using Win.Sfs.Shared.RepositoryBase; |
||||
|
|
||||
|
namespace Win.Sfs.SettleAccount.Entities.BQ |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 采购价格单
|
||||
|
/// </summary>
|
||||
|
[AllowAnonymous] |
||||
|
[Route("api/settleaccount/PURCHASE_PRICE_SERVICE")] |
||||
|
public class PURCHASE_PRICE_SERVICE : SettleAccountApplicationBase<PURCHASE_PRICE> |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 采购价格单仓储
|
||||
|
/// </summary>
|
||||
|
private readonly INormalEfCoreRepository<PURCHASE_PRICE, Guid> _repository; |
||||
|
|
||||
|
public PURCHASE_PRICE_SERVICE( |
||||
|
INormalEfCoreRepository<PURCHASE_PRICE, Guid> repository, |
||||
|
IDistributedCache<PURCHASE_PRICE> cache, |
||||
|
IExcelImportAppService excelImportService, |
||||
|
ISnowflakeIdGenerator snowflakeIdGenerator, |
||||
|
ICommonManager commonManager |
||||
|
) : base(cache, excelImportService, snowflakeIdGenerator, commonManager) |
||||
|
{ |
||||
|
_repository = repository; |
||||
|
} |
||||
|
|
||||
|
#region 导入、导出
|
||||
|
/// <summary>
|
||||
|
/// 导入
|
||||
|
/// </summary>
|
||||
|
[HttpPost] |
||||
|
[Route("Import")] |
||||
|
public async Task<string> ImportAsync([FromForm] IFormFileCollection files) |
||||
|
{ |
||||
|
ExportImporter _exportImporter = new ExportImporter(); |
||||
|
var result = await _exportImporter.UploadExcelImport<PURCHASE_PRICE_IMPORT_DTO>(files, _excelImportService); |
||||
|
var _ls = ObjectMapper.Map<List<PURCHASE_PRICE_IMPORT_DTO>, List<PURCHASE_PRICE>>(result); |
||||
|
List<string> _errorList = new List<string>(); |
||||
|
var checkList = new List<ErrorExportDto>(); |
||||
|
|
||||
|
if (_ls.Count > 0) |
||||
|
{ |
||||
|
var query = from arc in _ls |
||||
|
group arc by new { arc.LU } |
||||
|
into g |
||||
|
where g.Count() > 1 |
||||
|
|
||||
|
select g; |
||||
|
foreach (var itm in query) |
||||
|
{ |
||||
|
checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Format("物料号{0}有重复", itm.Key.LU), string.Empty)); |
||||
|
} |
||||
|
} |
||||
|
foreach (var itm in _ls) |
||||
|
{ |
||||
|
var _first = _repository.FirstOrDefault(p => p.LU == itm.LU); |
||||
|
if (_first != null) |
||||
|
{ |
||||
|
_first.Update(itm.Price); |
||||
|
await _repository.UpdateAsync(_first); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
await _repository.InsertAsync(itm); |
||||
|
} |
||||
|
} |
||||
|
if (checkList.Count > 0) |
||||
|
{ |
||||
|
return await ExportErrorReportAsync(checkList); |
||||
|
} |
||||
|
return ApplicationConsts.SuccessStr; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 导出
|
||||
|
/// </summary>
|
||||
|
[HttpPost] |
||||
|
[Route("Export")] |
||||
|
public async Task<string> ExportAsync(RequestDto input) |
||||
|
{ |
||||
|
string fileName = $"采购价格单_{Guid.NewGuid()}.xlsx"; |
||||
|
var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true); |
||||
|
var dtos = ObjectMapper.Map<List<PURCHASE_PRICE>, List<PURCHASE_PRICE_EXPORT_DTO>>(entities); |
||||
|
|
||||
|
ExportImporter _exportImporter = new ExportImporter(); |
||||
|
var result = await _exportImporter.ExcelExporter(dtos); |
||||
|
result.ShouldNotBeNull(); |
||||
|
|
||||
|
await _excelImportService.SaveBlobAsync(new SaveExcelImportInputDto { Name = fileName, Content = result }); |
||||
|
return fileName; |
||||
|
} |
||||
|
#endregion
|
||||
|
|
||||
|
#region CURD
|
||||
|
/// <summary>
|
||||
|
/// 获取列表
|
||||
|
/// </summary>
|
||||
|
[HttpPost] |
||||
|
[Route("list")] |
||||
|
public async Task<PagedResultDto<PURCHASE_PRICE_DTO>> GetListAsync(RequestDto input) |
||||
|
{ |
||||
|
var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true); |
||||
|
var totalCount = await _repository.GetCountByFilterAsync(input.Filters); |
||||
|
var dtos = ObjectMapper.Map<List<PURCHASE_PRICE>, List<PURCHASE_PRICE_DTO>>(entities); |
||||
|
return new PagedResultDto<PURCHASE_PRICE_DTO>(totalCount, dtos); |
||||
|
} |
||||
|
#endregion
|
||||
|
|
||||
|
} |
||||
|
} |
Loading…
Reference in new issue