You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
4.5 KiB
137 lines
4.5 KiB
5 months ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.ComponentModel.DataAnnotations;
|
||
|
using System.Linq.Expressions;
|
||
|
using System.Threading;
|
||
|
using System.Threading.Tasks;
|
||
|
|
||
|
using Microsoft.AspNetCore.Authorization;
|
||
|
using Microsoft.AspNetCore.Mvc;
|
||
|
using Volo.Abp.Application.Dtos;
|
||
|
using Volo.Abp.Caching;
|
||
|
using Volo.Abp.Domain.Repositories;
|
||
|
using Volo.Abp.Validation;
|
||
|
using Win_in.Sfs.Basedata.Application.Contracts;
|
||
|
using Win_in.Sfs.Basedata.Domain;
|
||
|
using Win_in.Sfs.Basedata.Domain.Shared;
|
||
|
using Win_in.Sfs.Shared.Domain.Shared;
|
||
|
using Win_in.Sfs.Shared.Domain;
|
||
|
using Volo.Abp.ObjectMapping;
|
||
|
using Win_in.Sfs.Shared.Application.Contracts;
|
||
|
using Volo.Abp;
|
||
|
|
||
|
namespace Win_in.Sfs.Basedata.Application;
|
||
|
|
||
|
[Authorize]
|
||
|
[Route($"{BasedataConsts.RootPath}PostionLocation")]
|
||
|
|
||
|
public class PostionLocationAppService
|
||
|
: SfsBaseDataWithCodeAppServiceBase<PostionLocation, PostionLocationDTO, SfsBaseDataRequestInputBase, PostionLocationEditInput, PostionLocationImportInput>
|
||
|
|
||
|
, IPostionLocationAppService
|
||
|
{
|
||
|
|
||
|
private readonly IPostionLocationManager _manager;
|
||
|
private readonly IPostionLocationRepository _repository;
|
||
|
private readonly ILocationAppService _locationAppService;
|
||
|
|
||
|
|
||
|
public PostionLocationAppService(
|
||
|
IPostionLocationRepository repository,
|
||
|
IPostionLocationManager manager
|
||
|
, IDistributedCache<PostionLocationDTO> cache
|
||
|
|
||
|
, ILocationAppService locationAppService
|
||
|
|
||
|
|
||
|
|
||
|
) : base(repository, cache)
|
||
|
{
|
||
|
_locationAppService = locationAppService;
|
||
|
_manager = manager;
|
||
|
_repository = repository;
|
||
|
|
||
|
|
||
|
//_PostionLocationCapacityAppService = PostionLocationCapacityAppService;
|
||
|
|
||
|
base.CreatePolicyName = PostionLocationPermissions.Create;
|
||
|
base.UpdatePolicyName = PostionLocationPermissions.Update;
|
||
|
base.DeletePolicyName = PostionLocationPermissions.Delete;
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
[HttpPost("list")]
|
||
|
public override async Task<PagedResultDto<PostionLocationDTO>> GetPagedListByFilterAsync(
|
||
|
SfsBaseDataRequestInputBase sfsRequestInput,
|
||
|
bool includeDetails = false,
|
||
|
CancellationToken cancellationToken = default)
|
||
|
{
|
||
|
Expression<Func<PostionLocation, bool>> expression = sfsRequestInput.Condition.Filters?.Count > 0
|
||
|
? sfsRequestInput.Condition.Filters.ToLambda<PostionLocation>()
|
||
|
: p => true;
|
||
|
var pageResult = await GetPagedListAsync(
|
||
|
expression,
|
||
|
sfsRequestInput.SkipCount,
|
||
|
sfsRequestInput.MaxResultCount,
|
||
|
sfsRequestInput.Sorting,
|
||
|
includeDetails,
|
||
|
cancellationToken).ConfigureAwait(false);
|
||
|
|
||
|
//foreach (var item in pageResult.Items)
|
||
|
//{
|
||
|
// item.ItemCategoryDictionary = await GetItemCategory(item.Code).ConfigureAwait(false);
|
||
|
//}
|
||
|
|
||
|
return pageResult;
|
||
|
}
|
||
|
|
||
|
[HttpPost("get-or-add")]
|
||
|
public virtual async Task<PostionLocationDTO> GetOrAddAsync(PostionLocationEditInput input)
|
||
|
{
|
||
|
await CheckLocationCode(input.LocationCode).ConfigureAwait(false);
|
||
|
var result = await _repository.FirstOrDefaultAsync(p => p.Code == input.Code).ConfigureAwait(false);
|
||
|
if (result == null)
|
||
|
{
|
||
|
var entity = ObjectMapper.Map<PostionLocationEditInput, PostionLocation>(input);
|
||
|
result = await _repository.InsertAsync(entity, true).ConfigureAwait(false);
|
||
|
}
|
||
|
var dto = ObjectMapper.Map<PostionLocation, PostionLocationDTO>(result);
|
||
|
return dto;
|
||
|
}
|
||
|
[HttpPost("upsert")]
|
||
|
public async Task UpsertAsync(PostionLocationEditInput input)
|
||
|
{
|
||
|
var entity= await _repository.GetAsync(p=>p.Code == input.Code).ConfigureAwait(false);
|
||
|
|
||
|
if (entity != null)
|
||
|
{
|
||
|
entity.Name = input.Name;
|
||
|
entity.LocationCode = input.LocationCode;
|
||
|
await _repository.UpdateAsync(entity).ConfigureAwait(false);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
entity.Code = input.Code;
|
||
|
entity.LocationCode = input.LocationCode;
|
||
|
entity.Name=input.Name;
|
||
|
await _repository.InsertAsync(entity, true).ConfigureAwait(false);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
private async Task CheckLocationCode(string p_location)
|
||
|
{
|
||
|
|
||
|
var list = await _locationAppService.GetByCodeAsync(p_location).ConfigureAwait(false);
|
||
|
if (list == null )
|
||
|
{
|
||
|
throw new UserFriendlyException($"{p_location}库位编码不存在,请查看库位信息!");
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|