| | |
| | | using CMS.Plugin.HIAWms.Application.Contracts.Dtos.WmsAreas; |
| | | using CMS.Plugin.HIAWms.Application.Contracts.Dtos.WmsArea; |
| | | using CMS.Plugin.HIAWms.Application.Contracts.Services; |
| | | using CMS.Plugin.HIAWms.Domain.WmsAreas; |
| | | using CMS.Plugin.HIAWms.Domain.Shared; |
| | |
| | | using Volo.Abp.Application.Dtos; |
| | | using Volo.Abp.Data; |
| | | using Volo.Abp.ObjectExtending; |
| | | using CMS.Plugin.HIAWms.Domain.WmsStores; |
| | | using CmsQueryExtensions; |
| | | using CmsQueryExtensions.Extension; |
| | | using System.Linq.Expressions; |
| | | |
| | | namespace CMS.Plugin.HIAWms.Application.Implements; |
| | | |
| | |
| | | public class WmsAreaAppService : CMSPluginAppService, IWmsAreaAppService |
| | | { |
| | | private readonly IWmsAreaRepository _wmsareaRepository; |
| | | private readonly IWmsStoreRepository _wmsstoreRepository; |
| | | |
| | | /// <summary> |
| | | /// Initializes a new instance of the <see cref="WmsAreaAppService"/> class. |
| | | /// </summary> |
| | | /// <param name="wmsareaRepository">The task job repository.</param> |
| | | public WmsAreaAppService(IWmsAreaRepository wmsareaRepository) |
| | | public WmsAreaAppService(IWmsAreaRepository wmsareaRepository, IWmsStoreRepository wmsstoreRepository) |
| | | { |
| | | _wmsareaRepository = wmsareaRepository; |
| | | _wmsstoreRepository = wmsstoreRepository; |
| | | } |
| | | |
| | | /// <inheritdoc /> |
| | |
| | | return ObjectMapper.Map<WmsArea, WmsAreaDto>(await _wmsareaRepository.GetAsync(id)); |
| | | } |
| | | |
| | | /// <inheritdoc /> |
| | | public virtual async Task<PagedResultDto<WmsAreaDto>> GetListAsync(GetWmsAreasInput input) |
| | | /// <summary> |
| | | /// 分页获取仓库信息 |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | public virtual async Task<PagedResultDto<WmsAreaDto>> GetListAsync(GetWmsAreaInput input) |
| | | { |
| | | Check.NotNull(input, nameof(input)); |
| | | |
| | |
| | | input.Sorting = nameof(WmsArea.Sort); |
| | | } |
| | | |
| | | var specification = new WmsAreaSpecification(input.Name); |
| | | var count = await _wmsareaRepository.GetCountAsync(input.Filter, specification); |
| | | var list = await _wmsareaRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter, specification); |
| | | #region 动态构造查询条件 |
| | | |
| | | //动态构造查询条件 |
| | | var whereConditions = DynamicGetQueryParams(input); |
| | | |
| | | #endregion |
| | | |
| | | var count = await _wmsareaRepository.GetCountAsync(whereConditions); |
| | | var list = await _wmsareaRepository.GetListAsync(whereConditions, input.Sorting, input.MaxResultCount, input.SkipCount); |
| | | |
| | | return new PagedResultDto<WmsAreaDto>(count, ObjectMapper.Map<List<WmsArea>, List<WmsAreaDto>>(list)); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 动态构造查询条件 |
| | | /// </summary> |
| | | /// <param name="input">输入参数</param> |
| | | /// <returns></returns> |
| | | private FunReturnResultModel<Expression<Func<WmsArea, bool>>> DynamicGetQueryParams(GetWmsAreaInput input) |
| | | { |
| | | //动态构造查询条件 |
| | | var whereConditions = WhereConditionsExtensions.GetWhereConditions<WmsArea, GetWmsAreaInput>(input); |
| | | if (!whereConditions.IsSuccess) |
| | | { |
| | | throw new Exception("动态构造查询条件失败:" + whereConditions.ErrMsg); |
| | | } |
| | | |
| | | //也可再次自定义构建查询条件 |
| | | Expression<Func<WmsArea, bool>> extendExpression = a => a.IsDeleted == false; |
| | | // 使用 System.Linq.PredicateBuilder 的 And |
| | | var pres = (System.Linq.Expressions.Expression<Func<WmsArea, bool>>)(whereConditions.data); |
| | | whereConditions.data = System.Linq.PredicateBuilder.And(pres, extendExpression); |
| | | |
| | | return whereConditions; |
| | | } |
| | | |
| | | /// <inheritdoc /> |
| | |
| | | |
| | | var maxSort = await _wmsareaRepository.GetMaxSortAsync(); |
| | | var sort = input.Sort ?? maxSort; |
| | | var wmsarea = new WmsArea |
| | | var wmsarea = ObjectMapper.Map<WmsAreaCreateDto, WmsArea>(input); |
| | | wmsarea.Sort = sort; |
| | | var store = await _wmsstoreRepository.FindByNameAsync(input.StoreCode); |
| | | if (store == null) |
| | | { |
| | | throw new UserFriendlyException("仓库信息不存"); |
| | | } |
| | | |
| | | }; |
| | | input.MapExtraPropertiesTo(wmsarea, MappingPropertyDefinitionChecks.None); |
| | | |
| | | wmsarea.StoreName = store.StoreName; |
| | | await _wmsareaRepository.InsertAsync(wmsarea); |
| | | |
| | | if (input.Sort.HasValue && wmsarea.Sort != maxSort) |
| | |
| | | |
| | | wmsarea.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp); |
| | | input.MapExtraPropertiesTo(wmsarea, MappingPropertyDefinitionChecks.None); |
| | | var store = await _wmsstoreRepository.FindByNameAsync(input.StoreCode); |
| | | if (store == null) |
| | | { |
| | | throw new UserFriendlyException("仓库信息不存"); |
| | | } |
| | | |
| | | wmsarea.AreaNo = input.AreaNo; |
| | | wmsarea.AreaName = input.AreaName; |
| | | wmsarea.AreaDesc = input.AreaDesc; |
| | | wmsarea.AreaStatus = input.AreaStatus; |
| | | wmsarea.AreaType = input.AreaType; |
| | | wmsarea.StoreCode = input.StoreCode; |
| | | wmsarea.StoreName = store.StoreName; |
| | | |
| | | await _wmsareaRepository.UpdateAsync(wmsarea); |
| | | |
| | |
| | | /// <inheritdoc /> |
| | | public virtual async Task AdjustSortAsync(Guid id, int sort) |
| | | { |
| | | var list = await _wmsareaRepository.GetListAsync(nameof(WmsArea.Sort)); |
| | | var list = await _wmsareaRepository.GetListAsync(null,nameof(WmsArea.Sort)); |
| | | if (list != null && list.Any()) |
| | | { |
| | | var initSort = 1; |
| | |
| | | throw new UserFriendlyException(errorMsg); |
| | | } |
| | | |
| | | var oldWmsArea = await _wmsareaRepository.FindByNameAsync(wmsarea.AreaName); |
| | | var oldWmsArea = await _wmsareaRepository.FindByNameAsync(wmsarea.AreaNo); |
| | | if (oldWmsArea != null) |
| | | { |
| | | var wmsareaUpdateDto = new WmsAreaUpdateDto |
| | | { |
| | | AreaNo = wmsarea.AreaNo, |
| | | AreaName = wmsarea.AreaName, |
| | | AreaDesc = wmsarea.AreaDesc, |
| | | AreaStatus = wmsarea.AreaStatus, |
| | | AreaType = wmsarea.AreaType, |
| | | StoreCode = wmsarea.StoreCode, |
| | | StoreName = wmsarea.StoreName, |
| | | Remark = wmsarea.Remark, |
| | | }; |
| | | |
| | |
| | | { |
| | | var wmsareaCreateDto = new WmsAreaCreateDto |
| | | { |
| | | AreaNo = wmsarea.AreaNo, |
| | | AreaName = wmsarea.AreaName, |
| | | AreaDesc = wmsarea.AreaDesc, |
| | | AreaStatus = wmsarea.AreaStatus, |
| | | AreaType = wmsarea.AreaType, |
| | | StoreCode = wmsarea.StoreCode, |
| | | StoreName = wmsarea.StoreName, |
| | | Remark = wmsarea.Remark, |
| | | }; |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /// <inheritdoc /> |
| | | public async Task<(Dictionary<string, object> Sheets, string FileName)> ExportAsync(GetWmsAreasInput input) |
| | | /// <summary> |
| | | /// 导出仓库库区信息 |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | public async Task<(Dictionary<string, object> Sheets, string FileName)> ExportAsync(GetWmsAreaInput input) |
| | | { |
| | | Check.NotNull(input, nameof(input)); |
| | | |
| | |
| | | input.Sorting = nameof(WmsArea.Sort); |
| | | } |
| | | |
| | | var specification = new WmsAreaSpecification(input.Name); |
| | | var list = await _wmsareaRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter, specification, includeDetails: true); |
| | | #region 动态构造查询条件 |
| | | |
| | | //动态构造查询条件 |
| | | var whereConditions = DynamicGetQueryParams(input); |
| | | |
| | | #endregion |
| | | |
| | | |
| | | |
| | | var list = await _wmsareaRepository.GetListAsync(whereConditions, input.Sorting, input.MaxResultCount, input.SkipCount, includeDetails: true); |
| | | var result = ObjectMapper.Map<List<WmsArea>, List<WmsAreaDto>>(list); |
| | | |
| | | var sheets = new Dictionary<string, object> |
| | | { |
| | | ["配置"] = result.Select(x => x.GetExportData()).ToList(), |
| | | ["配置"] = ExportHelper.ConvertListToExportData(result), |
| | | }; |
| | | |
| | | var fileName = result.Count > 1 ? "WmsArea列表" : result.Count == 1 ? result.First()?.AreaName : "WmsArea模版"; |
| | | var fileName = "库区信息"; |
| | | return (sheets, fileName); |
| | | } |
| | | |