| | |
| | | using CMS.Plugin.HIAWms.Application.Contracts.Dtos.WmsMaterials; |
| | | using CMS.Plugin.HIAWms.Application.Contracts.Dtos.WmsMaterial; |
| | | using CMS.Plugin.HIAWms.Application.Contracts.Services; |
| | | using CMS.Plugin.HIAWms.Domain.WmsMaterials; |
| | | using CMS.Plugin.HIAWms.Domain.Shared; |
| | | using CMS.Plugin.HIAWms.Domain.Shared.WmsMaterials; |
| | | using CMS.Plugin.HIAWms.Domain.WmsMaterials; |
| | | using CmsQueryExtensions; |
| | | using Volo.Abp; |
| | | using Volo.Abp.Application.Dtos; |
| | | using Volo.Abp.Data; |
| | | using Volo.Abp.ObjectExtending; |
| | | using Volo.Abp.ObjectMapping; |
| | | |
| | | namespace CMS.Plugin.HIAWms.Application.Implements; |
| | | |
| | |
| | | } |
| | | |
| | | /// <inheritdoc /> |
| | | public virtual async Task<PagedResultDto<WmsMaterialDto>> GetListAsync(GetWmsMaterialsInput input) |
| | | public virtual async Task<PagedResultDto<WmsMaterialDto>> GetListAsync(GetWmsMaterialInput input) |
| | | { |
| | | Check.NotNull(input, nameof(input)); |
| | | |
| | |
| | | } |
| | | |
| | | var specification = new WmsMaterialSpecification(input.Name); |
| | | var count = await _wmsmaterialRepository.GetCountAsync(input.Filter, specification); |
| | | var list = await _wmsmaterialRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter, specification); |
| | | var material = ObjectMapper.Map<GetWmsMaterialInput, WmsMaterial>(input); |
| | | var count = await _wmsmaterialRepository.GetCountAsync(material,input.Filter, specification); |
| | | |
| | | var list = await _wmsmaterialRepository.GetListAsync(material,input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter, specification); |
| | | |
| | | return new PagedResultDto<WmsMaterialDto>(count, ObjectMapper.Map<List<WmsMaterial>, List<WmsMaterialDto>>(list)); |
| | | } |
| | |
| | | { |
| | | await CheckCreateOrUpdateDtoAsync(input); |
| | | |
| | | var exist = await _wmsmaterialRepository.NameExistAsync(input.MaterialCode); |
| | | var exist = await _wmsmaterialRepository.NameExistAsync(input.MaterialNo); |
| | | if (exist) |
| | | { |
| | | throw new UserFriendlyException(L[CMSPluginDomainErrorCodes.NameAlreadyExists, input.MaterialCode]); |
| | | throw new UserFriendlyException(L[CMSPluginDomainErrorCodes.NameAlreadyExists, input.MaterialNo]); |
| | | } |
| | | |
| | | var maxSort = await _wmsmaterialRepository.GetMaxSortAsync(); |
| | | var sort = input.Sort ?? maxSort; |
| | | var wmsmaterial = new WmsMaterial |
| | | { |
| | | |
| | | }; |
| | | var wmsmaterial = ObjectMapper.Map<WmsMaterialCreateDto, WmsMaterial>(input); |
| | | wmsmaterial.Sort = sort; |
| | | input.MapExtraPropertiesTo(wmsmaterial, MappingPropertyDefinitionChecks.None); |
| | | |
| | | await _wmsmaterialRepository.InsertAsync(wmsmaterial); |
| | |
| | | await CheckCreateOrUpdateDtoAsync(input); |
| | | |
| | | var wmsmaterial = await _wmsmaterialRepository.GetAsync(id); |
| | | var exist = await _wmsmaterialRepository.NameExistAsync(input.MaterialCode, wmsmaterial.Id); |
| | | var exist = await _wmsmaterialRepository.NameExistAsync(input.MaterialNo, wmsmaterial.Id); |
| | | if (exist) |
| | | { |
| | | throw new UserFriendlyException(L[CMSPluginDomainErrorCodes.NameAlreadyExists, input.MaterialCode]); |
| | | throw new UserFriendlyException(L[CMSPluginDomainErrorCodes.NameAlreadyExists, input.MaterialNo]); |
| | | } |
| | | |
| | | wmsmaterial.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp); |
| | | input.MapExtraPropertiesTo(wmsmaterial, MappingPropertyDefinitionChecks.None); |
| | | |
| | | wmsmaterial.MaterialCode = input.MaterialCode; |
| | | wmsmaterial.MaterialName = input.MaterialName; |
| | | wmsmaterial.PurchaseType = input.PurchaseType; |
| | | wmsmaterial.MaterialType = input.MaterialType; |
| | | wmsmaterial.PrimaryUnit = input.PrimaryUnit; |
| | | wmsmaterial.Standard = input.Standard; |
| | | wmsmaterial.OuterDiameter = input.OuterDiameter; |
| | | wmsmaterial.WallThickness = input.WallThickness; |
| | | wmsmaterial.MaterialQuality = input.MaterialQuality; |
| | | wmsmaterial.Length = input.Length; |
| | | wmsmaterial.IsMainBranch = input.IsMainBranch; |
| | | wmsmaterial.Factory = input.Factory; |
| | | wmsmaterial.MaterialModel = input.MaterialModel; |
| | | wmsmaterial.Certification = input.Certification; |
| | | |
| | | await _wmsmaterialRepository.UpdateAsync(wmsmaterial); |
| | | |
| | |
| | | /// <inheritdoc /> |
| | | public virtual async Task AdjustSortAsync(Guid id, int sort) |
| | | { |
| | | var list = await _wmsmaterialRepository.GetListAsync(nameof(WmsMaterial.Sort)); |
| | | var list = await _wmsmaterialRepository.GetListAsync(null, nameof(WmsMaterial.Sort)); |
| | | if (list != null && list.Any()) |
| | | { |
| | | var initSort = 1; |
| | |
| | | } |
| | | |
| | | /// <inheritdoc /> |
| | | public async Task ImportAsync(WmsMaterialsImportModel input) |
| | | public async Task ImportAsync(WmsMaterialImportModels input) |
| | | { |
| | | Check.NotNull(input, nameof(input)); |
| | | |
| | |
| | | #region 导入校验 |
| | | |
| | | // 判断名称是否重复,并输出第几行重复 |
| | | var duplicateWmsMaterials = wmsmaterials.GroupBy(x => x.MaterialCode).Where(x => x.Count() > 1).ToList(); |
| | | var duplicateWmsMaterials = wmsmaterials.GroupBy(x => x.MaterialNo).Where(x => x.Count() > 1).ToList(); |
| | | if (duplicateWmsMaterials?.Any() == true) |
| | | { |
| | | var duplicateWmsMaterialMsgs = duplicateWmsMaterials.Select(x => $"第 {string.Join(",", x.Select(x => x.RowIndex))} 行:{x.Key} 名称重复"); |
| | |
| | | |
| | | foreach (var wmsmaterial in wmsmaterials) |
| | | { |
| | | if (wmsmaterial.MaterialCode.IsNullOrWhiteSpace() && wmsmaterial.MaterialName.IsNullOrWhiteSpace()) |
| | | if (wmsmaterial.MaterialNo.IsNullOrWhiteSpace() && wmsmaterial.MaterialName.IsNullOrWhiteSpace()) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | if (wmsmaterial.MaterialCode.IsNullOrWhiteSpace()) |
| | | if (wmsmaterial.MaterialNo.IsNullOrWhiteSpace()) |
| | | { |
| | | var errorMsg = $"导入失败!配置,第{wmsmaterial.RowIndex}行:WmsMaterial名称不能为空"; |
| | | throw new UserFriendlyException(errorMsg); |
| | | } |
| | | |
| | | var oldWmsMaterial = await _wmsmaterialRepository.FindByNameAsync(wmsmaterial.MaterialCode); |
| | | var oldWmsMaterial = await _wmsmaterialRepository.FindByNameAsync(wmsmaterial.MaterialNo); |
| | | if (oldWmsMaterial != null) |
| | | { |
| | | var wmsmaterialUpdateDto = new WmsMaterialUpdateDto |
| | | { |
| | | MaterialCode = wmsmaterial.MaterialCode, |
| | | MaterialNo = wmsmaterial.MaterialNo, |
| | | MaterialName = wmsmaterial.MaterialName, |
| | | PurchaseType = wmsmaterial.PurchaseType, |
| | | MaterialType = wmsmaterial.MaterialType, |
| | | PrimaryUnit = wmsmaterial.PrimaryUnit, |
| | | Standard = wmsmaterial.Standard, |
| | | OuterDiameter = wmsmaterial.OuterDiameter, |
| | | WallThickness = wmsmaterial.WallThickness, |
| | | MaterialQuality = wmsmaterial.MaterialQuality, |
| | | Length = wmsmaterial.Length, |
| | | IsMainBranch = wmsmaterial.IsMainBranch, |
| | | Factory = wmsmaterial.Factory, |
| | | Certification = wmsmaterial.Certification, |
| | | Remark = wmsmaterial.Remark, |
| | | }; |
| | | |
| | |
| | | { |
| | | var wmsmaterialCreateDto = new WmsMaterialCreateDto |
| | | { |
| | | MaterialCode = wmsmaterial.MaterialCode, |
| | | MaterialNo = wmsmaterial.MaterialNo, |
| | | MaterialName = wmsmaterial.MaterialName, |
| | | PurchaseType = wmsmaterial.PurchaseType, |
| | | MaterialType = wmsmaterial.MaterialType, |
| | | PrimaryUnit = wmsmaterial.PrimaryUnit, |
| | | Standard = wmsmaterial.Standard, |
| | | OuterDiameter = wmsmaterial.OuterDiameter, |
| | | WallThickness = wmsmaterial.WallThickness, |
| | | MaterialQuality = wmsmaterial.MaterialQuality, |
| | | Length = wmsmaterial.Length, |
| | | IsMainBranch = wmsmaterial.IsMainBranch, |
| | | Factory = wmsmaterial.Factory, |
| | | Certification = wmsmaterial.Certification, |
| | | Remark = wmsmaterial.Remark, |
| | | }; |
| | | |
| | |
| | | } |
| | | |
| | | /// <inheritdoc /> |
| | | public async Task<(Dictionary<string, object> Sheets, string FileName)> ExportAsync(GetWmsMaterialsInput input) |
| | | public async Task<(Dictionary<string, object> Sheets, string FileName)> ExportAsync(GetWmsMaterialInput input) |
| | | { |
| | | Check.NotNull(input, nameof(input)); |
| | | |
| | |
| | | } |
| | | |
| | | var specification = new WmsMaterialSpecification(input.Name); |
| | | var list = await _wmsmaterialRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter, specification, includeDetails: true); |
| | | |
| | | var material = ObjectMapper.Map<GetWmsMaterialInput, WmsMaterial>(input); |
| | | var list = await _wmsmaterialRepository.GetListAsync(material,input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter, specification, includeDetails: true); |
| | | var result = ObjectMapper.Map<List<WmsMaterial>, List<WmsMaterialDto>>(list); |
| | | |
| | | var sheets = new Dictionary<string, object> |
| | | { |
| | | ["配置"] = result.Select(x => x.GetExportData()).ToList(), |
| | | ["配置"] = ExportHelper.ConvertListToExportData(result), |
| | | }; |
| | | |
| | | var fileName = result.Count > 1 ? "WmsMaterial列表" : result.Count == 1 ? result.First()?.MaterialCode : "WmsMaterial模版"; |
| | | var fileName = result.Count > 1 ? "WmsMaterial列表" : result.Count == 1 ? result[0]?.MaterialNo : "WmsMaterial模版"; |
| | | return (sheets, fileName); |
| | | } |
| | | |
| | |
| | | protected Task CheckCreateOrUpdateDtoAsync(WmsMaterialCreateOrUpdateDtoBase input) |
| | | { |
| | | Check.NotNull(input, nameof(input)); |
| | | Check.NotNullOrWhiteSpace(input.MaterialCode, "编号", WmsMaterialConsts.MaxCodeLength); |
| | | Check.NotNullOrWhiteSpace(input.MaterialNo, "编号", WmsMaterialConsts.MaxCodeLength); |
| | | Check.NotNullOrWhiteSpace(input.MaterialName, "名称", WmsMaterialConsts.MaxNameLength); |
| | | Check.Length(input.Remark, "备注", WmsMaterialConsts.MaxRemarkLength); |
| | | return Task.CompletedTask; |