public async Task <ApiData> SimulateRequest(RequestInfo requestInfo) { _logger.Information("正在模拟请求 {requestInfo}", requestInfo); await _eventBus.FireEventAsync(EventTypes.PreRequest, requestInfo); await _eventBus.FireEventAsync(EventTypes.Request, requestInfo); var op = await _opHelper.SaveOpAsync("{0}", requestInfo); _logger.Information("模拟请求成功"); return(this.Success()); }
public async Task <ApiData> Close(int id) { InboundOrder inboundOrder = await _session.GetAsync <InboundOrder>(id); if (inboundOrder == null) { throw new Exception("入库单不存在。"); } if (inboundOrder.Closed) { throw new InvalidOperationException($"入库单已关闭。{inboundOrder.InboundOrderCode}"); } inboundOrder.Closed = true; inboundOrder.ClosedAt = DateTime.Now; _session.Update(inboundOrder); await _opHelper.SaveOpAsync(inboundOrder.InboundOrderCode); await _session.UpdateAsync(inboundOrder); _logger.Information("已关闭入库单 {inboundOrder}", inboundOrder); await _simpleEventBus.FireEventAsync(EventTypes.InboundOrderClosed, inboundOrder); return(this.Success()); }
public async Task 一个处理程序注册两次会创建两个实例() { SimpleEventBus bus = new SimpleEventBus(new[] { new Lazy <IEventHandler, EventHandlerMeta>(() => new QuxHandler(), new EventHandlerMeta { EventType = "Qux" }), new Lazy <IEventHandler, EventHandlerMeta>(() => new QuxHandler(), new EventHandlerMeta { EventType = "Qux" }), }, NSubstitute.Substitute.For <Serilog.ILogger>()); QuxData data = new QuxData(); await bus.FireEventAsync("Qux", data); Assert.Equal(2, data.Handlers.Count); Assert.NotSame(data.Handlers[0], data.Handlers[1]); }
public async Task <ApiData> Close(int id) { OutboundOrder outboundOrder = await _session.GetAsync <OutboundOrder>(id); if (outboundOrder == null) { throw new InvalidOperationException("出库单不存在。"); } if (outboundOrder.Closed) { throw new InvalidOperationException($"出库单已关闭。"); } // 关闭前检查 await CheckOnCloseAsync(outboundOrder); outboundOrder.Closed = true; outboundOrder.ClosedAt = DateTime.Now; _session.Update(outboundOrder); await _opHelper.SaveOpAsync(outboundOrder.OutboundOrderCode); // 取消分配,以免关单后有未释放的货载 foreach (var u in outboundOrder.Unitloads.ToList()) { await _outboundOrderAllocator.DeallocateAsync(outboundOrder, u); } await _session.UpdateAsync(outboundOrder); _logger.Information("已关闭出库单 {outboundOrder}", outboundOrder); await _simpleEventBus.FireEventAsync(EventTypes.OutboundOrderClosed, outboundOrder); return(this.Success()); }
public async Task <ApiData> DisableInbound(string ids, DisableInboundArgs args) { List <int> list = ids .Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) .Select(x => int.Parse(x)) .ToList(); List <Location> locs = await _session.Query <Location>() .Where(x => list.Contains(x.LocationId)) .ToListAsync(); int affected = 0; foreach (var loc in locs) { if (loc.LocationType == LocationTypes.N) { // N 位置无法禁入禁出 _logger.Warning("不能禁用或启用 N 位置。"); continue; } if (loc.Cell != null) { foreach (var item in loc.Cell.Locations) { await DisableOneAsync(item); } } else { await DisableOneAsync(loc); } } var laneways = locs.Where(x => x.Rack != null).Select(x => x.Rack.Laneway).Distinct(); foreach (var laneway in laneways) { await _locHelper.RebuildLanewayStatAsync(laneway); } _ = await _opHelper.SaveOpAsync("将 {0} 个位置设为禁止入站", affected); return(this.Success()); async Task DisableOneAsync(Location loc) { if (loc.InboundDisabled == false) { loc.InboundDisabled = true; loc.InboundDisabledComment = args.Comment; await _session.UpdateAsync(loc); LocationOp op = new LocationOp { OpType = _opHelper.GetOperationType(), Comment = args.Comment, ctime = DateTime.Now, Location = loc }; await _session.SaveAsync(op); await _eventBus.FireEventAsync(EventTypes.LocationInboundDisabled, loc); affected++; } } }