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.
222 lines
8.0 KiB
222 lines
8.0 KiB
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}postion-location")]
|
|
|
|
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("")]
|
|
public override async Task<PostionLocationDTO> CreateAsync(PostionLocationEditInput input)
|
|
{
|
|
var isexist= _repository.WithDetails().Where(p => p.Code == input.Code && p.LocationCode == input.LocationCode);
|
|
if (isexist.Any())
|
|
{
|
|
throw new UserFriendlyException($"工作站编号{input.Code}库位编码{input.LocationCode}已存在!");
|
|
}
|
|
await CheckLocationCode(input.LocationCode).ConfigureAwait(false);
|
|
|
|
return await base.CreateAsync(input).ConfigureAwait(false);
|
|
}
|
|
|
|
[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}库位编码不存在,请查看库位信息!");
|
|
}
|
|
|
|
|
|
}
|
|
|
|
[HttpPost("get-list-by-location")]
|
|
public async Task<List<PostionLocationDTO>> GetByLocationCodeAsync(string locationCode)
|
|
{
|
|
var result=await _repository.GetListAsync(p => p.LocationCode == locationCode).ConfigureAwait(false);
|
|
|
|
return ObjectMapper.Map<List<PostionLocation>, List<PostionLocationDTO>>(result);
|
|
}
|
|
|
|
|
|
[HttpPost("get-all-list")]
|
|
public async Task<List<PostionLocationAgvDTO>> GetAllListAsync()
|
|
{
|
|
var result =await base.GetAllListByFilterAsync(new SfsBaseDataRequestInputBase()).ConfigureAwait(false);
|
|
List<PostionLocationAgvDTO> list = new List<PostionLocationAgvDTO>();
|
|
foreach (var item in result)
|
|
{
|
|
PostionLocationAgvDTO dto = new PostionLocationAgvDTO();
|
|
dto.LocationCode = item.LocationCode;
|
|
dto.Code= item.Code;
|
|
list.Add(dto);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
|
|
//private async Task CheckLocationCode(string p_location)
|
|
//{
|
|
|
|
// var list = await _locationAppService.GetByCodeAsync(p_location).ConfigureAwait(false);
|
|
// if (list == null)
|
|
// {
|
|
// throw new UserFriendlyException($"{p_location}库位编码不存在,请查看库位信息!");
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
}
|
|
|