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.
112 lines
4.3 KiB
112 lines
4.3 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Volo.Abp;
|
|
using Volo.Abp.Caching;
|
|
using Volo.Abp.Domain.Repositories;
|
|
using Volo.Abp.ObjectMapping;
|
|
using Volo.Abp.Uow;
|
|
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;
|
|
|
|
namespace Win_in.Sfs.Basedata.Application;
|
|
|
|
[Authorize]
|
|
[Route($"{BasedataConsts.RootPath}erplocation-item")]
|
|
|
|
public class ErpLocationItemAppService
|
|
: SfsBaseDataAppServiceBase<ErpLocationItem, ErpLocationItemDTO, SfsBaseDataRequestInputBase, ErpLocationItemEditInput, ErpLocationItemImportInput>
|
|
, IErpLocationItemAppService
|
|
{
|
|
private readonly IErpLocationItemManager _manager;
|
|
private new readonly IErpLocationItemRepository _repository;
|
|
|
|
public ErpLocationItemAppService(
|
|
IErpLocationItemRepository repository
|
|
, IDistributedCache<ErpLocationItemDTO> cache
|
|
, IErpLocationItemManager manager
|
|
, IItemBasicAppService itemBasicAppService) : base(repository, cache)
|
|
{
|
|
base.CreatePolicyName = ErpLocationItemPermissions.Create;
|
|
base.UpdatePolicyName = ErpLocationItemPermissions.Update;
|
|
base.DeletePolicyName = ErpLocationItemPermissions.Delete;
|
|
_repository = repository;
|
|
_manager = manager;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 用来重写 新增实体
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="UserFriendlyException"></exception>
|
|
[HttpPost("")]
|
|
[UnitOfWork]
|
|
public override async Task<ErpLocationItemDTO> CreateAsync(ErpLocationItemEditInput input)
|
|
{
|
|
var itemBasic = await ItemBasicAppService.GetByCodeAsync(input.ItemCode).ConfigureAwait(false);
|
|
Check.NotNull(itemBasic, "ERP料号", $"物品 {input.ItemCode} 不存在");
|
|
|
|
var erpLocation = await ErpLocationAppService.GetByCodeAsync(input.ErpLocationCode).ConfigureAwait(false);
|
|
Check.NotNull(erpLocation, "储位代码", $"储位 {input.ErpLocationCode} 不存在");
|
|
|
|
var entity = await _repository.FirstOrDefaultAsync(p => p.ItemCode == input.ItemCode && p.ErpLocationCode == input.ErpLocationCode).ConfigureAwait(false);
|
|
|
|
if(entity != null)
|
|
{
|
|
throw new UserFriendlyException($"物品 {input.ItemCode} 和储位 {input.ErpLocationCode} 对应关系已存在");
|
|
}
|
|
|
|
return await base.CreateAsync(input).ConfigureAwait(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检查物料和储位对应关系是否存在
|
|
/// </summary>
|
|
/// <param name="itemCode"></param>
|
|
/// <param name="erpLocationCode"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("check-item-erplocation-is-available")]
|
|
public virtual async Task<ErpLocationItemDTO> CheckItemErpLocationIsAvailable(string itemCode,string erpLocationCode)
|
|
{
|
|
var entity = await _repository.FirstOrDefaultAsync(p => p.ItemCode == itemCode && p.ErpLocationCode== erpLocationCode).ConfigureAwait(false);
|
|
|
|
if (entity == null)
|
|
{
|
|
if (erpLocationCode=="无"||await SettingManager.IsTrueAsync(BasedataSettings.ErpLocationItem.NotFoundReturnInfinity).ConfigureAwait(false))
|
|
{
|
|
entity = new ErpLocationItem()
|
|
{
|
|
ItemCode = itemCode,
|
|
ErpLocationCode= erpLocationCode
|
|
};
|
|
|
|
}
|
|
}
|
|
var dto = ObjectMapper.Map<ErpLocationItem, ErpLocationItemDTO>(entity);
|
|
return dto;
|
|
}
|
|
|
|
[HttpPost("upsert")]
|
|
public virtual async Task UpsertAsync(ErpLocationItemEditInput input)
|
|
{
|
|
var entity = ObjectMapper.Map<ErpLocationItemEditInput, ErpLocationItem>(input);
|
|
await _repository.UpsertAsync(entity).ConfigureAwait(false);
|
|
}
|
|
|
|
[HttpGet("list/by-item")]
|
|
public virtual async Task<List<ErpLocationItemDTO>> GetListByItemCodeAsync(string itemCode)
|
|
{
|
|
var entities = await _repository.GetListAsync(c => c.ItemCode == itemCode).ConfigureAwait(false);
|
|
var dtos = ObjectMapper.Map<List<ErpLocationItem>, List<ErpLocationItemDTO>>(entities);
|
|
return dtos;
|
|
}
|
|
|
|
}
|
|
|