/// <summary> /// 根据用户名查询购物车ID /// </summary> public async Task <GetShopCarResponse> GetShopCarAsync([FromBody] GetShopCarRequest request) { GetShopCarResponse response = new GetShopCarResponse(); try { var customer = _context.CustomerEntitys.FirstOrDefault(a => a.CustomerPhone == request.UserName); if (customer != null) { var shopCar = await _context.ShopCarEntitys.SingleOrDefaultAsync(a => a.UserId == customer.CustomerID); if (shopCar == null) { shopCar = new ShopCarEntity { UserId = customer.CustomerID }; _context.Add(shopCar); await _context.SaveChangesAsync(); } shopCar = await _context.ShopCarEntitys.SingleOrDefaultAsync(a => a.UserId == customer.CustomerID); response.UserId = customer.CustomerID; response.CarId = shopCar.PKID; } } catch (Exception ex) { response.Successful = false; response.Message = ex.Message; logger.LogError(ex, $"GetShopCarAsync 方法报错 Message:{JsonConvert.SerializeObject(request)}"); } return(response); }
public async Task <RoutingKeyRegisterResponse> RoutingKeyRegisterAsync([FromBody] RoutingKeyRegisterRequest request) { RoutingKeyRegisterResponse response = new RoutingKeyRegisterResponse(); try { if (string.IsNullOrEmpty(request.RoutingKey) || string.IsNullOrEmpty(request.ApiUrl)) { response.Successful = false; response.Message = "RoutingKey与ApiUrl不能为空!"; } if (string.IsNullOrEmpty(request.QueueName)) { request.QueueName = Configuration["SubscriptionClientName"]; } var isExistsRoutingKey = _context.RabbitMqRegisterInfo.Any(a => a.RoutingKey == request.RoutingKey); if (isExistsRoutingKey) { response.Successful = false; response.Message = "对应的RoutingKey已存在!"; return(response); } var rabbitMqRegister = new RabbitMQRegisterInfo { RoutingKey = request.RoutingKey, QueueName = request.QueueName, ApiUrl = request.ApiUrl, CreateTime = DateTime.Now, UpdateTime = DateTime.Now }; _context.Add(rabbitMqRegister); _context.SaveChanges(); //绑定RoutingKey和队列 _eventBus.Subscribe(request.QueueName, request.RoutingKey); } catch (Exception ex) { response.Successful = false; response.Message = ex.Message; } return(response); }