protected override GetVipListNumRD ProcessRequest(DTO.Base.APIRequest <GetVipListNumRP> pRequest) { GetVipListNumRD rd = new GetVipListNumRD(); var items = new List <VipNumInfo>(); pRequest.CustomerID = ConfigurationManager.AppSettings["WiFiCustomerID"].Trim(); if (string.IsNullOrEmpty(pRequest.Parameters.UnitID)) { //门店ID,前期默认,可以不传(上海越洋广场店) pRequest.Parameters.UnitID = "9678d0e66d8d411baf8a6027c3e623f9"; } #region 获取表单列表 try { var bll = new WiFiUserVisitBLL(base.CurrentUserInfo); rd.VipNumNow = bll.GetVipNumAllOrNow(pRequest.Parameters.UnitID, true); rd.VipNumAll = bll.GetVipNumAllOrNow(pRequest.Parameters.UnitID, false); VipNumInfo info1 = new VipNumInfo(); info1.TypeName = "5分钟内"; info1.VipNum = bll.GetVipNum(pRequest.Parameters.UnitID, 0, 5); info1.Proportion = rd.VipNumAll > 0 ? info1.VipNum * 100 / rd.VipNumAll : 0; items.Add(info1); VipNumInfo info2 = new VipNumInfo(); info2.TypeName = "5-10分钟内"; info2.VipNum = bll.GetVipNum(pRequest.Parameters.UnitID, 5, 10); info2.Proportion = rd.VipNumAll > 0 ? info2.VipNum * 100 / rd.VipNumAll : 0; items.Add(info2); VipNumInfo info3 = new VipNumInfo(); info3.TypeName = "10分钟到1小时内"; info3.VipNum = bll.GetVipNum(pRequest.Parameters.UnitID, 10, 60); info3.Proportion = rd.VipNumAll > 0 ? info3.VipNum * 100 / rd.VipNumAll : 0; items.Add(info3); VipNumInfo info4 = new VipNumInfo(); info4.TypeName = "1小时以上"; info4.VipNum = bll.GetVipNum(pRequest.Parameters.UnitID, 60, -1); info4.Proportion = rd.VipNumAll > 0 ? info4.VipNum * 100 / rd.VipNumAll : 0; items.Add(info4); rd.Items = items.ToArray(); } catch (Exception) { throw new APIException("查询数据错误") { ErrorCode = ERROR_LNEWS_FAILURE }; } #endregion return(rd); }
protected override GetVipListRD ProcessRequest(DTO.Base.APIRequest <GetVipListRP> pRequest) { GetVipListRD rd = new GetVipListRD(); pRequest.CustomerID = ConfigurationManager.AppSettings["WiFiCustomerID"].Trim(); pRequest.Parameters.Validate(); if (string.IsNullOrEmpty(pRequest.Parameters.UnitID)) { //门店ID,前期默认,可以不传(上海越洋广场店) pRequest.Parameters.UnitID = "9678d0e66d8d411baf8a6027c3e623f9"; } #region 获取表单列表 try { var ds = new WiFiUserVisitBLL(base.CurrentUserInfo).GetVipListByPage(pRequest.Parameters.UnitID, pRequest.Parameters.PageIndex, pRequest.Parameters.PageSize); if (ds.Tables.Count > 0) { rd.TotalRow = Convert.ToInt32(ds.Tables[0].Rows[0][0]); if (ds.Tables[1].Rows.Count > 0) { IList <VipInfo> list = DataLoader.LoadFrom <VipInfo>(ds.Tables[1]); foreach (VipInfo item in list) { int minutes = int.Parse(item.VipTime); //格式化处理登录时间 int h = minutes / 60; int m = minutes % 60; if (h > 0) { item.VipTime = string.Format("{0}小时{1}分钟前", h, m); } else { item.VipTime = string.Format("{0}分钟前", m); } } rd.VipList = list.ToArray(); } } } catch (Exception) { throw new APIException("查询数据错误") { ErrorCode = ERROR_LNEWS_FAILURE }; } #endregion return(rd); }
protected override WifiSignRD ProcessRequest(DTO.Base.APIRequest <WifiSignRP> pRequest) { //调试日志1 Loggers.Debug(new DebugLogInfo { Message = "<1>VIP.WifiSign.WifiSign接口开始执行___" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }); WifiSignRD rd = new WifiSignRD(); pRequest.CustomerID = ConfigurationManager.AppSettings["WiFiCustomerID"].Trim(); pRequest.Parameters.Validate(); string wiFiUser = ConfigurationManager.AppSettings["WiFiUser"].Trim(); string userSession = ConfigurationManager.AppSettings["UserSession"].Trim(); string userLoginOk = ConfigurationManager.AppSettings["UserLoginOk"].Trim(); if (string.IsNullOrEmpty(pRequest.UserID)) { throw new Exception("UserID不能为空"); } if (string.IsNullOrEmpty(wiFiUser)) { throw new APIException("请配置WiFiUser对应的URL请求路径") { ErrorCode = ERROR_URL_ISNULL } } ; if (string.IsNullOrEmpty(userSession)) { throw new APIException("请配置UserSession对应的URL请求路径") { ErrorCode = ERROR_URL_ISNULL } } ; if (string.IsNullOrEmpty(userLoginOk)) { throw new APIException("请配置UserLoginOk对应的URL请求路径") { ErrorCode = ERROR_URL_ISNULL } } ; #region 获取表单列表 try { //调试日志2 Loggers.Debug(new DebugLogInfo { Message = "<2>获取SK参数值:" + pRequest.Parameters.DeviceID + ",获取用户ID参数值:" + pRequest.UserID + ",开始执行第三方接口___" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }); #region 调用第三方接口登录认证获取设备ID和连接时间 //调用第三方接口通知WiFiCenter登录成功 //RequestGet(string.Format(userLoginOk, pRequest.Parameters.deviceId)); //调试日志3 //Loggers.Debug(new DebugLogInfo //{ // Message = "<3>调用第三方接口通知WiFiCenter登录成功(" + string.Format(userLoginOk, pRequest.Parameters.deviceId) + "通过)___" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") //}); //调用第三方接口从WiFiCenter获取指定WiFiCenterSessionKey对应的用户信息 string json = RequestGet(string.Format(wiFiUser, pRequest.Parameters.DeviceID)); //调试日志4 Loggers.Debug(new DebugLogInfo { Message = "<4>调用第三方接口从WiFiCenter获取指定WiFiCenterSessionKey对应的用户信息(" + string.Format(wiFiUser, pRequest.Parameters.DeviceID) + "通过,返回值:" + json + ")___" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }); //调用第三方接口根据指定的WiFiCenterSessionKey获得用户会话信息 string json2 = RequestGet(string.Format(userSession, pRequest.Parameters.DeviceID)); //调试日志5 Loggers.Debug(new DebugLogInfo { Message = "<5>调用第三方接口根据指定的WiFiCenterSessionKey获得用户会话信息(" + string.Format(userSession, pRequest.Parameters.DeviceID) + "通过,返回值:" + json2 + ")___" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }); JavaScriptSerializer serializer = new JavaScriptSerializer(); WiFiUser info = serializer.Deserialize <WiFiUser>(json); WiFiUserSession info2 = serializer.Deserialize <WiFiUserSession>(json2); //调试日志6 Loggers.Debug(new DebugLogInfo { Message = "<6>反序列化通过,获取节点编号:" + info.NodeSn + ",连接时间:" + info2.TimeSessionCreated + "___" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }); //节点编号 string nodeSn = info.NodeSn; //连接时间 DateTime beginTime = info2.TimeSessionCreated; if (string.IsNullOrEmpty(nodeSn)) { throw new APIException("获取节点编号为空") { ErrorCode = ERROR_URL_ISNULL } } ; if (beginTime == null) { throw new APIException("获取会话时间为空") { ErrorCode = ERROR_URL_ISNULL } } ; #endregion #region 保存用户连接WiFi相关数据 //WiFi设备表 WiFiDeviceEntity wiFiInfo = new WiFiDeviceBLL(base.CurrentUserInfo).GetByNodeSn(nodeSn); if (wiFiInfo == null) { throw new Exception("无WiFi设备"); } if (wiFiInfo.DeviceID == null) { throw new Exception("无WiFi设备数据"); } //调试日志7 Loggers.Debug(new DebugLogInfo { Message = "<7>根据节点编号获取WiFi设备数据通过(设备ID:" + wiFiInfo.DeviceID == null ? "NULL" : wiFiInfo.DeviceID + "),开始执行插入数据___" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }); string where = string.Format(" and UnitID='{0}' and VIPID='{1}' ", wiFiInfo.UnitID, pRequest.UserID); var uvbll = new WiFiUserVisitBLL(base.CurrentUserInfo); if (uvbll.IsExists(where)) { //更新当前设备ID WiFiUserVisitEntity visitInfo = uvbll.GetByWhere(where); visitInfo.CurrentDeviceID = wiFiInfo.DeviceID; uvbll.Update(visitInfo); //扩展:更新或添加详细信息 } else { //用户连接WiFi表 WiFiUserVisitEntity visitInfo = new WiFiUserVisitEntity(); visitInfo.VisitID = Guid.NewGuid(); visitInfo.VIPID = pRequest.UserID; visitInfo.UnitID = wiFiInfo.UnitID; visitInfo.CurrentDeviceID = wiFiInfo.DeviceID; visitInfo.CurrentDate = DateTime.Now; visitInfo.BeginTime = DateTime.Parse(beginTime.ToString("yyyy-MM-dd HH:mm:ss.fff")); visitInfo.CustomerID = CurrentUserInfo.CurrentLoggingManager.Customer_Id; uvbll.Create(visitInfo); //调试日志8 Loggers.Debug(new DebugLogInfo { Message = "<8>用户连接WiFi表添加数据成功___" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }); //用户连接WiFi详细信息表 WiFiUserVisitDetailEntity visitDetailInfo = new WiFiUserVisitDetailEntity(); visitDetailInfo.VisitDetailID = Guid.NewGuid(); visitDetailInfo.VisitID = visitInfo.VisitID; visitDetailInfo.VIPID = pRequest.UserID; visitDetailInfo.DeviceID = wiFiInfo.DeviceID; visitDetailInfo.BeginTime = DateTime.Parse(beginTime.ToString("yyyy-MM-dd HH:mm:ss.fff")); visitDetailInfo.CustomerID = CurrentUserInfo.CurrentLoggingManager.Customer_Id; new WiFiUserVisitDetailBLL(base.CurrentUserInfo).Create(visitDetailInfo); //调试日志9 Loggers.Debug(new DebugLogInfo { Message = "<9>用户连接WiFi详细信息表添加数据成功___" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }); } #endregion #region 返回门店某个会员详细信息 StringBuilder strWhere = new StringBuilder(); if (!string.IsNullOrEmpty(pRequest.UserID) && !string.IsNullOrEmpty(pRequest.OpenID)) { strWhere.AppendFormat(" and (V.VIPID='{0}' or P.WeiXinUserId='{1}') ", pRequest.UserID, pRequest.OpenID); } else if (!string.IsNullOrEmpty(pRequest.UserID)) { strWhere.AppendFormat(" and V.VIPID='{0}' ", pRequest.UserID); } else if (!string.IsNullOrEmpty(pRequest.OpenID)) { strWhere.AppendFormat(" and P.WeiXinUserId='{0}' ", pRequest.OpenID); } if (!string.IsNullOrEmpty(wiFiInfo.DeviceID.ToString())) { strWhere.AppendFormat(" and V.CurrentDeviceID='{0}' ", wiFiInfo.DeviceID); } var ds = uvbll.GetVipDetailList(strWhere.ToString()); if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { rd.Items = DataLoader.LoadFrom <VipInfo>(ds.Tables[0]); } //调试日志10 Loggers.Debug(new DebugLogInfo { Message = "<10>VIP.WifiSign.WifiSign接口成功结束___" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }); #endregion } catch (Exception ex) { Loggers.Exception(new ExceptionLogInfo(ex)); //throw new APIException("查询数据错误") { ErrorCode = ERROR_FAILURE }; throw new APIException(ex.Message) { ErrorCode = ERROR_FAILURE }; } #endregion return(rd); }