|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Volo.Abp;
|
|
|
|
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;
|
|
|
|
using Win_in.Sfs.Shared.Domain.Shared;
|
|
|
|
|
|
|
|
namespace Win_in.Sfs.Basedata.Application;
|
|
|
|
|
|
|
|
[Authorize]
|
|
|
|
[Route($"{BasedataConsts.RootPath}item-basic")]
|
|
|
|
public class ItemBasicAppService
|
|
|
|
: SfsBaseDataWithCodeAppServiceBase<ItemBasic, ItemBasicDTO, SfsBaseDataRequestInputBase, ItemBasicEditInput, ItemBasicImportInput>
|
|
|
|
, IItemBasicAppService
|
|
|
|
{
|
|
|
|
private readonly ItemValidator _itemValidator;
|
|
|
|
private readonly IItemBasicManager _manager;
|
|
|
|
private new readonly IItemBasicRepository _repository;
|
|
|
|
|
|
|
|
public ItemBasicAppService(
|
|
|
|
IItemBasicRepository repository,
|
|
|
|
IDistributedCache<ItemBasicDTO> cache,
|
|
|
|
ItemValidator itemValidator,
|
|
|
|
IItemBasicManager manager)
|
|
|
|
: base(repository, cache)
|
|
|
|
{
|
|
|
|
_repository = repository;
|
|
|
|
_itemValidator = itemValidator;
|
|
|
|
_manager = manager;
|
|
|
|
base.CreatePolicyName = ItemBasicPermissions.Create;
|
|
|
|
base.UpdatePolicyName = ItemBasicPermissions.Update;
|
|
|
|
base.DeletePolicyName = ItemBasicPermissions.Delete;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected ICategoryAppService _categoryApp => LazyServiceProvider.LazyGetRequiredService<ICategoryAppService>();
|
|
|
|
protected IItemCategoryAppService _itemCategoryApp => LazyServiceProvider.LazyGetRequiredService<IItemCategoryAppService>();
|
|
|
|
|
|
|
|
[HttpPost("check")]
|
|
|
|
public virtual async Task CheckAsync(string code, ItemBasicCheckInput input)
|
|
|
|
{
|
|
|
|
var result = new AbpValidationResult();
|
|
|
|
_itemValidator.CheckFormat(code);
|
|
|
|
var dto = await GetByCodeAsync(code).ConfigureAwait(false);
|
|
|
|
var entity = ObjectMapper.Map<ItemBasicDTO, ItemBasic>(dto);
|
|
|
|
_itemValidator.CheckCanBuy(entity, input.CanBuy, result);
|
|
|
|
_itemValidator.CheckCanMake(entity, input.CanMake, result);
|
|
|
|
_itemValidator.CheckStatus(entity, input.Statuses, result);
|
|
|
|
_itemValidator.CheckProject(entity, input.Projects, result);
|
|
|
|
await _itemValidator.CheckCategoryAsync(entity, input.Categories, result).ConfigureAwait(false);
|
|
|
|
if (result.Errors.Count > 0)
|
|
|
|
{
|
|
|
|
throw new AbpValidationException(result.Errors);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 检物品状态 是否可用
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="itemCode"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
|
[HttpGet("check-item-is-available")]
|
|
|
|
public virtual async Task<bool> CheckItemIsAvailable(string itemCode)
|
|
|
|
{
|
|
|
|
var entity = await _repository.FindAsync(c => c.Code == itemCode).ConfigureAwait(false);
|
|
|
|
|
|
|
|
if (entity == null)
|
|
|
|
{
|
|
|
|
throw new UserFriendlyException($"未找到代码为 {itemCode} 的物品");
|
|
|
|
}
|
|
|
|
|
|
|
|
return entity.Status == EnumItemStatus.Active;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 检物品状态 是否可用(不查询数据库 直接根据对象判断)
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="itemBasicDTO"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet("check-item-is-available-no-select-sql")]
|
|
|
|
public void CheckItemIsAvailable(ItemBasicDTO itemBasicDTO)
|
|
|
|
{
|
|
|
|
if (itemBasicDTO != null && itemBasicDTO.Status != EnumItemStatus.Active)
|
|
|
|
{
|
|
|
|
throw new UserFriendlyException($"物料 {itemBasicDTO.Code} 状态为 {itemBasicDTO.Status} ,不是可用状态");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
public override async Task<ItemBasicDTO> GetAsync(Guid id)
|
|
|
|
{
|
|
|
|
var dto = await base.GetAsync(id).ConfigureAwait(false);
|
|
|
|
|
|
|
|
dto.ItemCategoryDictionary = await GetItemCategory(dto.Code).ConfigureAwait(false);
|
|
|
|
|
|
|
|
return dto;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="name"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
|
[HttpGet("list-by-name")]
|
|
|
|
public virtual async Task<List<ItemBasicDTO>> GetListByNameAsync(string name)
|
|
|
|
{
|
|
|
|
var entities = await _repository.GetListAsync(c => c.Name == name).ConfigureAwait(false);
|
|
|
|
var dtos = ObjectMapper.Map<List<ItemBasic>, List<ItemBasicDTO>>(entities);
|
|
|
|
return dtos;
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpGet("get-manage-type")]
|
|
|
|
public virtual async Task<EnumItemManageType> GetManageTypeAsync(string itemCode)
|
|
|
|
{
|
|
|
|
var entity = await GetByCodeAsync(itemCode).ConfigureAwait(false);
|
|
|
|
Check.NotNull(entity, "物品代码", $"物品 {itemCode} 不存在");
|
|
|
|
return entity.ManageType;
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpGet("get-manage-types")]
|
|
|
|
public virtual async Task<Dictionary<string, EnumItemManageType>> GetManageTypesAsync(List<string> itemCodes)
|
|
|
|
{
|
|
|
|
var dtos = await GetByCodesAsync(itemCodes).ConfigureAwait(false);
|
|
|
|
var itemManageTypes = dtos.ToDictionary(dto => dto.Code, dto => dto.ManageType);
|
|
|
|
return itemManageTypes;
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost("get-or-add")]
|
|
|
|
public virtual async Task<ItemBasicDTO> GetOrAddAsync(ItemBasicEditInput input)
|
|
|
|
{
|
|
|
|
var result = await _repository.FirstOrDefaultAsync(p => p.Code == input.Code).ConfigureAwait(false);
|
|
|
|
if (result == null)
|
|
|
|
{
|
|
|
|
var entity = ObjectMapper.Map<ItemBasicEditInput, ItemBasic>(input);
|
|
|
|
result = await _repository.InsertAsync(entity, true).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
var dto = ObjectMapper.Map<ItemBasic, ItemBasicDTO>(result);
|
|
|
|
return dto;
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost("list")]
|
|
|
|
public override async Task<PagedResultDto<ItemBasicDTO>> GetPagedListByFilterAsync(
|
|
|
|
SfsBaseDataRequestInputBase sfsRequestInput,
|
|
|
|
bool includeDetails = false,
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
Expression<Func<ItemBasic, bool>> expression = sfsRequestInput.Condition.Filters?.Count > 0
|
|
|
|
? sfsRequestInput.Condition.Filters.ToLambda<ItemBasic>()
|
|
|
|
: 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("upsert")]
|
|
|
|
public virtual async Task UpsertAsync(ItemBasicEditInput input)
|
|
|
|
{
|
|
|
|
var entity = ObjectMapper.Map<ItemBasicEditInput, ItemBasic>(input);
|
|
|
|
await _repository.UpsertAsync(entity).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
[HttpPost("upsert-interface")]
|
|
|
|
public virtual async Task UpsertAsyncByInterface(ItemBasicEditInput input)
|
|
|
|
{
|
|
|
|
var entity = ObjectMapper.Map<ItemBasicEditInput, ItemBasic>(input);
|
|
|
|
await _repository.UpsertAsyncByInterface(entity).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override Expression<Func<ItemBasic, bool>> BuildSearchExpression(string keyWord)
|
|
|
|
{
|
|
|
|
Expression<Func<ItemBasic, bool>> expression = p =>
|
|
|
|
p.Code.Contains(keyWord)
|
|
|
|
|| p.Name.Contains(keyWord)
|
|
|
|
|| p.Desc1.Contains(keyWord)
|
|
|
|
|| p.Desc2.Contains(keyWord)
|
|
|
|
|| p.AbcClass.Contains(keyWord)
|
|
|
|
|| p.BasicUom.Contains(keyWord)
|
|
|
|
|| p.Elevel.Contains(keyWord)
|
|
|
|
|| p.Project.Contains(keyWord)
|
|
|
|
|| p.Version.Contains(keyWord);
|
|
|
|
return expression;
|
|
|
|
}
|
|
|
|
|
|
|
|
private async Task<Dictionary<string, string>> GetItemCategory(string itemCode)
|
|
|
|
{
|
|
|
|
var itemCategorys = await this._itemCategoryApp.GetListByItemCode(itemCode).ConfigureAwait(false);
|
|
|
|
|
|
|
|
return itemCategorys.ToDictionary(x => x.CategoryCode, y => y.Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
#region 东阳
|
|
|
|
|
|
|
|
[HttpPut("upsert-stdpackqty")]
|
|
|
|
public virtual async Task UpsertStdPackQtyAsync(string itemCode, decimal stdpackqty)
|
|
|
|
{
|
|
|
|
var itemBasic = await _repository.GetAsync(p => p.Code == itemCode).ConfigureAwait(false);
|
|
|
|
itemBasic.StdPackQty = stdpackqty;
|
|
|
|
await _repository.UpdateAsync(itemBasic).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|