using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Aspose.Cells.Drawing; using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Extension; using JNPF.DependencyInjection; using JNPF.DynamicApiController; using JNPF.FriendlyException; using JNPF.VisualDev; using JNPF.VisualDev.Entitys; using JNPF.VisualDev.Interfaces; using Microsoft.AspNetCore.Mvc; using SqlSugar; using Tnb.BasicData.Entities; using Tnb.BasicData.Interfaces; using Tnb.WarehouseMgr.Entities; using Tnb.WarehouseMgr.Entities.Enums; using Tnb.WarehouseMgr.Interfaces; namespace Tnb.WarehouseMgr { /// /// 配送申请服务 /// [ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)] [Route("api/[area]/[controller]/[action]")] public class WmsDeliveryService : IOverideVisualDevService, IWmsDeliveryService, IDynamicApiController, ITransient { private const string ModuleId = "26126388337189"; private readonly ISqlSugarClient _db; private readonly IRunService _runService; private readonly IVisualDevService _visualDevService; private readonly IBasLocationService _basLocationService; public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); public WmsDeliveryService( ISqlSugarRepository repository, IRunService runService, IVisualDevService visualDevService, IBasLocationService basLocationService ) { _db = repository.AsSugarClient(); _runService = runService; _visualDevService = visualDevService; _basLocationService = basLocationService; //OverideFuncs.CreateAsync = Create; } /// /// 根据载具编号获取起始库位点 /// /// /// [HttpGet] public async Task GetUnStoreLocationListByCarryId([FromRoute] string carryId) { var items = await _db.Queryable().LeftJoin((a, b) => a.location_id == b.id) .Where(a => a.id == carryId) .Select((a, b) => new { carry_code = a.carry_code, location_code = b.location_code, }) .ToListAsync(); return items; } private async Task Create(VisualDevModelDataCrInput input) { try { //startlocation_id //endlocation_id string startLocationId = "", endLocationId = ""; if (input.data.ContainsKey(nameof(WmsDelivery.startlocation_id))) { startLocationId = input.data[nameof(WmsDelivery.startlocation_id)]?.ToString()!; } if (input.data.ContainsKey(nameof(WmsDelivery.endlocation_id))) { endLocationId = input.data[nameof(WmsDelivery.endlocation_id)]?.ToString()!; } var locIds = new[] { startLocationId, endLocationId }; var locs = await _basLocationService.GetLocationInfobyIds(locIds); if (locs?.Count > 0) { var isStoreLoc = locs.Where(x => !x.IsNullOrEmpty()).Select(x => x.is_type.ParseToInt()).Any(x => x == (int)EnumLocationType.存储库位); if (isStoreLoc) throw new AppFriendlyException("起始库位不能为存储库位", 500); } VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true); await _runService.Create(templateEntity, input); } catch (Exception) { return await Task.FromResult(false); } return await Task.FromResult(true); } } }