diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PURCHASE_PRICE_DTO.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PURCHASE_PRICE_DTO.cs new file mode 100644 index 00000000..2ae8e495 --- /dev/null +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PURCHASE_PRICE_DTO.cs @@ -0,0 +1,67 @@ +using Magicodes.ExporterAndImporter.Core; +using System.ComponentModel.DataAnnotations; +using Win.Sfs.Shared.DtoBase; + +namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos +{ + /// + /// 采购价格单 + /// + public class PURCHASE_PRICE_DTO + { + /// + /// 零件号 + /// + [Display(Name = "零件号")] + public string LU { get; set; } + + /// + /// 价格 + /// + [Display(Name = "价格")] + public decimal Price { get; set; } + } + + public class PURCHASE_PRICE_IMPORT_DTO + { + /// + /// 零件号 + /// + [Display(Name = "零件号")] + [ImporterHeader(Name = "零件号")] + public string LU { get; set; } + + /// + /// 价格 + /// + [Display(Name = "价格")] + [ImporterHeader(Name = "价格")] + public decimal Price { get; set; } + } + + public class PURCHASE_PRICE_REQUEST_DTO : RequestDtoBase + { + + } + + /// + /// 导出 + /// + public class PURCHASE_PRICE_EXPORT_DTO + { + /// + /// 零件号 + /// + [Display(Name = "零件号")] + [ExporterHeader(DisplayName = "零件号")] + public string LU { get; set; } + + /// + /// 价格 + /// + [Display(Name = "价格")] + [ExporterHeader(DisplayName = "价格")] + public decimal Price { get; set; } + } + +} diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/RequestDto.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/RequestDto.cs new file mode 100644 index 00000000..d01a0557 --- /dev/null +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/RequestDto.cs @@ -0,0 +1,8 @@ +using Win.Sfs.Shared.DtoBase; + +namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos +{ + public class RequestDto : RequestDtoBase + { + } +} diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PURCHASE_PRICE_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PURCHASE_PRICE_SERVICE.cs new file mode 100644 index 00000000..64e2d8e1 --- /dev/null +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PURCHASE_PRICE_SERVICE.cs @@ -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 +{ + /// + /// 采购价格单 + /// + [AllowAnonymous] + [Route("api/settleaccount/PURCHASE_PRICE_SERVICE")] + public class PURCHASE_PRICE_SERVICE : SettleAccountApplicationBase + { + /// + /// 采购价格单仓储 + /// + private readonly INormalEfCoreRepository _repository; + + public PURCHASE_PRICE_SERVICE( + INormalEfCoreRepository repository, + IDistributedCache cache, + IExcelImportAppService excelImportService, + ISnowflakeIdGenerator snowflakeIdGenerator, + ICommonManager commonManager + ) : base(cache, excelImportService, snowflakeIdGenerator, commonManager) + { + _repository = repository; + } + + #region 导入、导出 + /// + /// 导入 + /// + [HttpPost] + [Route("Import")] + public async Task ImportAsync([FromForm] IFormFileCollection files) + { + ExportImporter _exportImporter = new ExportImporter(); + var result = await _exportImporter.UploadExcelImport(files, _excelImportService); + var _ls = ObjectMapper.Map, List>(result); + List _errorList = new List(); + var checkList = new List(); + + 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; + } + + /// + /// 导出 + /// + [HttpPost] + [Route("Export")] + public async Task 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>(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 + /// + /// 获取列表 + /// + [HttpPost] + [Route("list")] + public async Task> 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>(entities); + return new PagedResultDto(totalCount, dtos); + } + #endregion + + } +} diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs index 7306d226..cf9c34db 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs @@ -54,6 +54,8 @@ using Win.Sfs.SettleAccount.Entities.UnHQSettleAccounts; using Win.Sfs.SettleAccount.Entities.Wms.WmsSumOutput; using Win.Sfs.SettleAccount.Errors; using Win.Sfs.SettleAccount.Entities.Errors; +using Win.Sfs.SettleAccount.Entities.BQ.Dtos; +using SettleAccount.Domain.BQ; namespace Win.Sfs.SettleAccount { @@ -132,6 +134,7 @@ namespace Win.Sfs.SettleAccount #endregion + CreateMapPURCHASE_PRICE(); } #region 北汽 @@ -732,5 +735,16 @@ namespace Win.Sfs.SettleAccount } #endregion + + /// + /// 采购价格单 + /// + private void CreateMapPURCHASE_PRICE() + { + CreateMap(); + CreateMap(); + CreateMap(); + } + } } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/PURCHASE_PRICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/PURCHASE_PRICE.cs index 968bed7d..c5f01d9e 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/PURCHASE_PRICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/PURCHASE_PRICE.cs @@ -21,4 +21,13 @@ public class PURCHASE_PRICE : FullAuditedAggregateRoot /// [Display(Name = "价格")] public decimal Price { get; set; } + + /// + /// 更新 + /// + public void Update(decimal price) + { + Price = price; + } + }