public async Task Initialize() { YummyOnlineManager manager = new YummyOnlineManager(); waitingForVerificationClients = new WaitingForVerificationClients(log, send); systemClient = new SystemClient(log, send, GetTcpServerStatus); newDineInformClients = new NewDineInformClients(log, send, await manager.GetGuids()); printerClients = new PrinterClients(log, send, await manager.GetHotels()); log($"Binding {ip}:{port}", Log.LogLevel.Info); tcp.StartListening(IPAddress.Parse(ip), port, client => { TcpClientInfo clientInfo = new TcpClientInfo(client); waitingForVerificationClients.Add(clientInfo); log($"{clientInfo.OriginalRemotePoint} Connected, Waiting for verification", Log.LogLevel.Info); }); System.Timers.Timer timer = new System.Timers.Timer(10 * 1000); timer.Elapsed += (e, o) => { // 30秒之内已连接但是未发送身份信息的socket断开 waitingForVerificationClients.HandleTimeOut(); //60秒之内没有接收到心跳包的socket断开, 或发送心跳包失败的socket断开 systemClient.HandleTimeOut(); newDineInformClients.HandleTimeOut(); printerClients.HandleTimeOut(); }; timer.Start(); }
public async Task <JsonResult> GetDineDailyCount() { List <dynamic> list = new List <dynamic>(); List <Hotel> hotels = await YummyOnlineManager.GetHotels(); foreach (Hotel h in hotels) { if (h.ConnectionString == null) { continue; } List <dynamic> dailyCount = new List <dynamic>(); HotelManager hotelManager = new HotelManager(h.ConnectionString); for (int i = -30; i <= 0; i++) { DateTime t = DateTime.Now.AddDays(i); int count = await hotelManager.GetDineCount(t); dailyCount.Add(new { DateTime = t, Count = count }); } list.Add(new { HotelName = h.Name, DailyCount = dailyCount }); } return(Json(list)); }
public async Task <JsonResult> GetDbPartitionDetails() { var hotels = await YummyOnlineManager.GetHotels(); List <dynamic> partitionDetails = new List <dynamic>(); partitionDetails.Add(new { DbPartitionInfos = await new OriginSql(YummyOnlineManager.ConnectionString).GetDbPartitionInfos() }); foreach (Hotel h in hotels) { if (h.ConnectionString == null) { continue; } partitionDetails.Add(new { Hotel = new { h.Id, h.Name }, DbPartitionInfos = await new OriginSql(h.AdminConnectionString).GetDbPartitionInfos() }); } return(Json(partitionDetails)); }
public async Task <JsonResult> GetHotelNames() { List <Hotel> hotels = await YummyOnlineManager.GetHotels(); return(Json(hotels.Select(p => new { p.Id, p.Name, }))); }
protected virtual async Task <dynamic> getCustomerInfo() { string userId = User.Identity.GetUserId(); User user = await UserManager.FindByIdAsync(userId); if (user == null) { return(null); } List <CustomerInfo> customerInfos = new List <CustomerInfo>(); List <Hotel> hotels = await YummyOnlineManager.GetHotels(); foreach (Hotel h in hotels) { HotelManager hotelManager = new HotelManager(h.ConnectionString); HotelDAO.Models.Customer customer = await hotelManager.GetCustomer(userId); if (customer == null) { continue; } customerInfos.Add(new CustomerInfo { Hotel = new { h.Id, h.Name }, Points = customer.Points, VipLevel = customer.VipLevel == null ? null : new { customer.VipLevel.Id, customer.VipLevel.Name }, DinesCount = await hotelManager.GetHistoryDinesCount(userId) }); } return(new { user.Id, user.Email, user.PhoneNumber, user.UserName, CustomerInfos = customerInfos }); }
public async Task <JsonResult> GetDinePerHourCount(DateTime?dateTime) { DateTime dt = dateTime.HasValue ? dateTime.Value : DateTime.Now; List <dynamic> list = new List <dynamic>(); List <Hotel> hotels = await YummyOnlineManager.GetHotels(); foreach (Hotel h in hotels) { HotelManager hotelManager = new HotelManager(h.ConnectionString); list.Add(new { HotelName = h.Name, Counts = await hotelManager.GetDinePerHourCount(dt) }); } return(Json(list)); }
public virtual async Task <JsonResult> Signin(SigninViewModel model) { User user = await UserManager.FindByPhoneNumberAsync(model.PhoneNumber); if (user == null) { await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"User Signin: {model.PhoneNumber} No PhoneNumber, Host: {Request.UserHostAddress}"); return(Json(new JsonError("手机未注册"))); } if (!await UserManager.CheckPasswordAsync(user, model.Password)) { await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"User Signin: {model.PhoneNumber} Password Error, Host: {Request.UserHostAddress}", $"Password: {model.Password}"); return(Json(new JsonError("密码不正确"))); } if (User.Identity.IsAuthenticated) { User oldUser = await UserManager.FindByIdAsync(User.Identity.GetUserId()); if (oldUser != null && await UserManager.IsInRoleAsync(oldUser.Id, Role.Nemo)) { // 原来为匿名用户, 每个饭店该匿名用户点过的订单转移到登录的用户帐号下 List <Hotel> hotels = await YummyOnlineManager.GetHotels(); foreach (Hotel h in hotels) { HotelManager hotelManager = new HotelManager(h.ConnectionString); await hotelManager.TransferDines(oldUser.Id, user.Id); } await UserManager.TransferUserPrice(user, oldUser); await UserManager.DeleteAsync(oldUser); await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Warning, $"User Transfer: {oldUser.Id} -> {user.Id}"); } } SigninManager.Signin(user, true); await YummyOnlineManager.RecordLog(Log.LogProgram.Identity, Log.LogLevel.Success, $"User Signin: {user.Id} ({user.PhoneNumber}), Host: {Request.UserHostAddress}"); return(Json(new JsonSuccess())); }
public async Task <JsonResult> GetHotels() { List <Hotel> hotels = await YummyOnlineManager.GetHotels(); hotels.AddRange(await YummyOnlineManager.GetHotelReadyForConfirms()); if (User.IsInRole(nameof(Role.SuperAdmin))) { return(Json(hotels.Select(p => new { p.Id, p.Name, p.ConnectionString, p.AdminConnectionString, p.CssThemePath, p.OrderSystemStyle, p.CreateDate, p.Tel, p.Address, p.OpenTime, p.CloseTime, p.Usable }))); } return(Json(hotels.Select(p => new { p.Id, p.Name, p.ConnectionString, p.CssThemePath, p.OrderSystemStyle, p.CreateDate, p.Tel, p.Address, p.OpenTime, p.CloseTime, p.Usable }))); }