| | |
| | | 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.Shared; |
| | | using CMS.Plugin.HIAWms.Domain.Shared.Util; |
| | | using CMS.Plugin.HIAWms.Domain.Shared.WmsMaterials; |
| | | using CMS.Plugin.HIAWms.Domain.WmsMaterials; |
| | | using CmsQueryExtensions; |
| | | using CmsQueryExtensions.Extension; |
| | | using System.Linq.Expressions; |
| | | using Volo.Abp; |
| | | using Volo.Abp.Application.Dtos; |
| | | using Volo.Abp.Data; |
| | |
| | | } |
| | | |
| | | /// <inheritdoc /> |
| | | public virtual async Task<PagedResultDto<WmsMaterialDto>> GetListAsync(GetWmsMaterialsInput input) |
| | | public virtual async Task<PagedResultDto<WmsMaterialDto>> GetListAsync(GetWmsMaterialInput input) |
| | | { |
| | | Check.NotNull(input, nameof(input)); |
| | | |
| | |
| | | input.Sorting = nameof(WmsMaterial.Sort); |
| | | } |
| | | |
| | | var specification = new WmsMaterialSpecification(input.Name); |
| | | var material = ObjectMapper.Map<GetWmsMaterialsInput, WmsMaterial>(input); |
| | | var count = await _wmsmaterialRepository.GetCountAsync(material,input.Filter, specification); |
| | | #region 动态构造查询条件 |
| | | |
| | | var list = await _wmsmaterialRepository.GetListAsync(material,input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter, specification); |
| | | //动态构造查询条件 |
| | | var whereConditions = DynamicGetQueryParams(input); |
| | | |
| | | #endregion |
| | | |
| | | var count = await _wmsmaterialRepository.GetCountAsync(whereConditions); |
| | | var list = await _wmsmaterialRepository.GetListAsync(whereConditions, input.Sorting, input.MaxResultCount, input.SkipCount); |
| | | |
| | | return new PagedResultDto<WmsMaterialDto>(count, ObjectMapper.Map<List<WmsMaterial>, List<WmsMaterialDto>>(list)); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 动态构造查询条件 |
| | | /// </summary> |
| | | /// <param name="input">输入参数</param> |
| | | /// <returns></returns> |
| | | private FunReturnResultModel<Expression<Func<WmsMaterial, bool>>> DynamicGetQueryParams(GetWmsMaterialInput input) |
| | | { |
| | | //动态构造查询条件 |
| | | var whereConditions = WhereConditionsExtensions.GetWhereConditions<WmsMaterial, GetWmsMaterialInput>(input); |
| | | if (!whereConditions.IsSuccess) |
| | | { |
| | | throw new Exception("动态构造查询条件失败:" + whereConditions.ErrMsg); |
| | | } |
| | | |
| | | //也可再次自定义构建查询条件 |
| | | Expression<Func<WmsMaterial, bool>> extendExpression = a => a.IsDeleted == false; |
| | | // 使用 System.Linq.PredicateBuilder 的 And |
| | | var pres = (System.Linq.Expressions.Expression<Func<WmsMaterial, bool>>)(whereConditions.data); |
| | | whereConditions.data = System.Linq.PredicateBuilder.And(pres, extendExpression); |
| | | |
| | | return whereConditions; |
| | | } |
| | | |
| | | /// <inheritdoc /> |
| | |
| | | { |
| | | 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(); |
| | |
| | | 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); |
| | |
| | | |
| | | wmsmaterial.MaterialName = input.MaterialName; |
| | | wmsmaterial.PurchaseType = input.PurchaseType; |
| | | wmsmaterial.MaterialType = input.MaterialType; |
| | | wmsmaterial.MaterialTypeCode = input.MaterialTypeCode; |
| | | wmsmaterial.PrimaryUnit = input.PrimaryUnit; |
| | | wmsmaterial.Standard = input.Standard; |
| | | wmsmaterial.OuterDiameter = input.OuterDiameter; |
| | |
| | | } |
| | | |
| | | /// <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, |
| | | MaterialTypeCode = wmsmaterial.MaterialTypeCode, |
| | | PrimaryUnit = wmsmaterial.PrimaryUnit, |
| | | Standard = wmsmaterial.Standard, |
| | | OuterDiameter = wmsmaterial.OuterDiameter, |
| | |
| | | { |
| | | var wmsmaterialCreateDto = new WmsMaterialCreateDto |
| | | { |
| | | MaterialCode = wmsmaterial.MaterialCode, |
| | | MaterialNo = wmsmaterial.MaterialNo, |
| | | MaterialName = wmsmaterial.MaterialName, |
| | | PurchaseType = wmsmaterial.PurchaseType, |
| | | MaterialType = wmsmaterial.MaterialType, |
| | | MaterialTypeCode = wmsmaterial.MaterialTypeCode, |
| | | PrimaryUnit = wmsmaterial.PrimaryUnit, |
| | | Standard = wmsmaterial.Standard, |
| | | OuterDiameter = wmsmaterial.OuterDiameter, |
| | |
| | | } |
| | | } |
| | | |
| | | /// <inheritdoc /> |
| | | public async Task<(Dictionary<string, object> Sheets, string FileName)> ExportAsync(GetWmsMaterialsInput input) |
| | | /// <summary> |
| | | /// 导出物料基础信息 |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | public async Task<(Dictionary<string, object> Sheets, string FileName)> ExportAsync(GetWmsMaterialInput input) |
| | | { |
| | | Check.NotNull(input, nameof(input)); |
| | | |
| | |
| | | input.Sorting = nameof(WmsMaterial.Sort); |
| | | } |
| | | |
| | | var specification = new WmsMaterialSpecification(input.Name); |
| | | #region 动态构造查询条件 |
| | | |
| | | var material = ObjectMapper.Map<GetWmsMaterialsInput, WmsMaterial>(input); |
| | | var list = await _wmsmaterialRepository.GetListAsync(material,input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter, specification, includeDetails: true); |
| | | //动态构造查询条件 |
| | | var whereConditions = DynamicGetQueryParams(input); |
| | | |
| | | #endregion |
| | | |
| | | |
| | | |
| | | var list = await _wmsmaterialRepository.GetListAsync(whereConditions, input.Sorting, input.MaxResultCount, input.SkipCount, includeDetails: true); |
| | | var result = ObjectMapper.Map<List<WmsMaterial>, List<WmsMaterialDto>>(list); |
| | | |
| | | var sheets = new Dictionary<string, object> |
| | |
| | | ["配置"] = ExportHelper.ConvertListToExportData(result), |
| | | }; |
| | | |
| | | var fileName = result.Count > 1 ? "WmsMaterial列表" : result.Count == 1 ? result[0]?.MaterialCode : "WmsMaterial模版"; |
| | | var fileName = "物料基础"; |
| | | 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; |