|
|
|
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;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
namespace Win_in.Sfs.Basedata.Application;
|
|
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
[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;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override async Task ValidateImportModelAsync(PostionLocationImportInput importInput,
|
|
|
|
List<ValidationResult> validationRresult)
|
|
|
|
{
|
|
|
|
await base.ValidateImportModelAsync(importInput, validationRresult).ConfigureAwait(false);
|
|
|
|
await CheckLocationCodeAsync(importInput.LocationCode, validationRresult).ConfigureAwait(false);
|
|
|
|
await CheckSameItem(importInput.Code,importInput.LocationCode,validationRresult).ConfigureAwait(false);
|
|
|
|
//CheckProductionLineProdLineCodeJsonAsync(importInput.RawLocationCodeListJson, validationRresult);
|
|
|
|
//CheckProductionLineProdLineCodeJsonAsync(importInput.ProductLocationCodeListJson, validationRresult);
|
|
|
|
//CheckProductionLineProdLineCodeJsonAsync(importInput.WipLocationCodeListJson, validationRresult);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private async Task CheckLocationCodeAsync(string locationCode, List<ValidationResult> validationRresult)
|
|
|
|
{
|
|
|
|
var list = await _locationAppService.GetByCodeAsync(locationCode).ConfigureAwait(false);
|
|
|
|
if (list == null)
|
|
|
|
{
|
|
|
|
validationRresult.Add(new ValidationResult($"{locationCode}库位编码不存在,请查看库位信息!"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private async Task CheckSameItem(string code, string locationCode, List<ValidationResult> validationRresult)
|
|
|
|
{
|
|
|
|
var item = await _repository.FirstOrDefaultAsync(r => r.Code == code && r.LocationCode == locationCode).ConfigureAwait(false);
|
|
|
|
if (item != null)
|
|
|
|
{
|
|
|
|
validationRresult.Add(new ValidationResult($"工作站编码{code}库位编码{locationCode}已存在", new string[] { "工作站编码", "库位编码" }));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[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}库位编码不存在,请查看库位信息!");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|