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 , IErpLocationItemAppService { private readonly IErpLocationItemManager _manager; private new readonly IErpLocationItemRepository _repository; public ErpLocationItemAppService( IErpLocationItemRepository repository , IDistributedCache cache , IErpLocationItemManager manager , IItemBasicAppService itemBasicAppService) : base(repository, cache) { base.CreatePolicyName = ErpLocationItemPermissions.Create; base.UpdatePolicyName = ErpLocationItemPermissions.Update; base.DeletePolicyName = ErpLocationItemPermissions.Delete; _repository = repository; _manager = manager; } /// /// 用来重写 新增实体 /// /// /// /// [HttpPost("")] [UnitOfWork] public override async Task 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); } /// /// 检查物料和储位对应关系是否存在 /// /// /// /// [HttpGet("check-item-erplocation-is-available")] public virtual async Task 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(entity); return dto; } [HttpPost("upsert")] public virtual async Task UpsertAsync(ErpLocationItemEditInput input) { var entity = ObjectMapper.Map(input); await _repository.UpsertAsync(entity).ConfigureAwait(false); } [HttpGet("list/by-item")] public virtual async Task> GetListByItemCodeAsync(string itemCode) { var entities = await _repository.GetListAsync(c => c.ItemCode == itemCode).ConfigureAwait(false); var dtos = ObjectMapper.Map, List>(entities); return dtos; } }