From a3a2b238a2626ef8744e7a135f9ca2e2fbb5184c Mon Sep 17 00:00:00 2001 From: schangxiang@126.com <schangxiang@126.com> Date: 周三, 21 5月 2025 10:17:36 +0800 Subject: [PATCH] 优化 --- HIAWms/server/src/CMS.Plugin.HIAWms.Application/Implements/WmsPlaceAppService.cs | 81 +++++++++++++++++++++++++++++++++------- 1 files changed, 66 insertions(+), 15 deletions(-) diff --git a/HIAWms/server/src/CMS.Plugin.HIAWms.Application/Implements/WmsPlaceAppService.cs b/HIAWms/server/src/CMS.Plugin.HIAWms.Application/Implements/WmsPlaceAppService.cs index 8d3b362..864e7c2 100644 --- a/HIAWms/server/src/CMS.Plugin.HIAWms.Application/Implements/WmsPlaceAppService.cs +++ b/HIAWms/server/src/CMS.Plugin.HIAWms.Application/Implements/WmsPlaceAppService.cs @@ -1,13 +1,16 @@ -using CMS.Plugin.HIAWms.Application.Contracts.Dtos.WmsPlaces; +using CMS.Plugin.HIAWms.Application.Contracts.Dtos.WmsPlace; using CMS.Plugin.HIAWms.Application.Contracts.Services; -using CMS.Plugin.HIAWms.Domain.WmsPlaces; using CMS.Plugin.HIAWms.Domain.Shared; using CMS.Plugin.HIAWms.Domain.Shared.WmsPlaces; +using CMS.Plugin.HIAWms.Domain.WmsPlaces; +using CmsQueryExtensions; +using CmsQueryExtensions.Extension; +using System.Linq.Expressions; +using System.Text.RegularExpressions; using Volo.Abp; using Volo.Abp.Application.Dtos; using Volo.Abp.Data; using Volo.Abp.ObjectExtending; -using CMS.Plugin.HIAWms.Domain.Shared.Util; namespace CMS.Plugin.HIAWms.Application.Implements; @@ -31,8 +34,12 @@ return ObjectMapper.Map<WmsPlace, WmsPlaceDto>(await _wmsplaceRepository.GetAsync(id)); } - /// <inheritdoc /> - public virtual async Task<PagedResultDto<WmsPlaceDto>> GetListAsync(GetWmsPlacesInput input) + /// <summary> + /// 鍒嗛〉鑾峰彇搴撲綅淇℃伅 + /// </summary> + /// <param name="input"></param> + /// <returns></returns> + public virtual async Task<PagedResultDto<WmsPlaceDto>> GetListAsync(GetWmsPlaceInput input) { Check.NotNull(input, nameof(input)); @@ -41,14 +48,41 @@ input.Sorting = nameof(WmsPlace.Sort); } - var specification = new WmsPlaceSpecification(input.Name); - var place = ObjectMapper.Map<GetWmsPlacesInput, WmsPlace>(input); - var count = await _wmsplaceRepository.GetCountAsync(place,input.Filter, specification); - var list = await _wmsplaceRepository.GetListAsync(place, input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter, specification); + #region 鍔ㄦ�佹瀯閫犳煡璇㈡潯浠� + + //鍔ㄦ�佹瀯閫犳煡璇㈡潯浠� + var whereConditions = DynamicGetQueryParams(input); + + #endregion + + var count = await _wmsplaceRepository.GetCountAsync(whereConditions); + var list = await _wmsplaceRepository.GetListAsync(whereConditions, input.Sorting, input.MaxResultCount, input.SkipCount); return new PagedResultDto<WmsPlaceDto>(count, ObjectMapper.Map<List<WmsPlace>, List<WmsPlaceDto>>(list)); } + /// <summary> + /// 鍔ㄦ�佹瀯閫犳煡璇㈡潯浠� + /// </summary> + /// <param name="input">杈撳叆鍙傛暟</param> + /// <returns></returns> + private FunReturnResultModel<Expression<Func<WmsPlace, bool>>> DynamicGetQueryParams(GetWmsPlaceInput input) + { + //鍔ㄦ�佹瀯閫犳煡璇㈡潯浠� + var whereConditions = WhereConditionsExtensions.GetWhereConditions<WmsPlace, GetWmsPlaceInput>(input); + if (!whereConditions.IsSuccess) + { + throw new Exception("鍔ㄦ�佹瀯閫犳煡璇㈡潯浠跺け璐�:" + whereConditions.ErrMsg); + } + + //涔熷彲鍐嶆鑷畾涔夋瀯寤烘煡璇㈡潯浠� + Expression<Func<WmsPlace, bool>> extendExpression = a => a.IsDeleted == false; + // 浣跨敤 System.Linq.PredicateBuilder 鐨� And + var pres = (System.Linq.Expressions.Expression<Func<WmsPlace, bool>>)(whereConditions.data); + whereConditions.data = System.Linq.PredicateBuilder.And(pres, extendExpression); + + return whereConditions; + } /// <inheritdoc /> public virtual async Task<WmsPlaceDto> CreateAsync(WmsPlaceCreateDto input) { @@ -103,6 +137,7 @@ wmsplace.RedundantField2 = input.RedundantField2; wmsplace.RedundantField3 = input.RedundantField3; wmsplace.Remark = input.Remark; + wmsplace.IsDisabled = input.IsDisabled; await _wmsplaceRepository.UpdateAsync(wmsplace); @@ -284,8 +319,12 @@ } } - /// <inheritdoc /> - public async Task<(Dictionary<string, object> Sheets, string FileName)> ExportAsync(GetWmsPlacesInput input) + /// <summary> + /// 瀵煎嚭搴撲綅淇℃伅 + /// </summary> + /// <param name="input"></param> + /// <returns></returns> + public async Task<(Dictionary<string, object> Sheets, string FileName)> ExportAsync(GetWmsPlaceInput input) { Check.NotNull(input, nameof(input)); @@ -294,9 +333,16 @@ input.Sorting = nameof(WmsPlace.Sort); } - var specification = new WmsPlaceSpecification(input.Name); - var place = ObjectMapper.Map<GetWmsPlacesInput, WmsPlace>(input); - var list = await _wmsplaceRepository.GetListAsync(place, input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter, specification, includeDetails: true); + #region 鍔ㄦ�佹瀯閫犳煡璇㈡潯浠� + + //鍔ㄦ�佹瀯閫犳煡璇㈡潯浠� + var whereConditions = DynamicGetQueryParams(input); + + #endregion + + + + var list = await _wmsplaceRepository.GetListAsync(whereConditions, input.Sorting, input.MaxResultCount, input.SkipCount, includeDetails: true); var result = ObjectMapper.Map<List<WmsPlace>, List<WmsPlaceDto>>(list); var sheets = new Dictionary<string, object> @@ -304,7 +350,7 @@ ["閰嶇疆"] = ExportHelper.ConvertListToExportData(result), }; - var fileName = result.Count > 1 ? "WmsPlace鍒楄〃" : result.Count == 1 ? result.First()?.PlaceNo : "WmsPlace妯$増"; + var fileName = "搴撲綅淇℃伅"; return (sheets, fileName); } @@ -316,6 +362,11 @@ { Check.NotNull(input, nameof(input)); Check.NotNullOrWhiteSpace(input.PlaceNo, "缂栧彿", WmsPlaceConsts.MaxCodeLength); + string pattern = @"^\d+-\d+$"; + if (input.StorageTypeNo == Domain.Shared.Enums.PlaceTypeEnum.YUANLIAOKUWEI && !Regex.IsMatch(input.PlaceNo, pattern)) + { + throw new UserFriendlyException("搴撲綅缂栧彿鏍煎紡閿欒"); + } Check.Length(input.Remark, "澶囨敞", WmsPlaceConsts.MaxRemarkLength); return Task.CompletedTask; } -- Gitblit v1.9.3