/// <summary> /// 用户退出 /// </summary> /// <param name="openId">信令</param> /// <param name="createOpenId">重新生成令牌</param> /// <returns>影响行数</returns> public bool SignOut(string openId, bool createOpenId = true, string systemCode = "Base", string ipAddress = null, string macAddress = null) { int result = 0; // 应该进行一次日志记录 // 从缓存读取、效率高 string id = string.Empty; if (!string.IsNullOrWhiteSpace(openId)) { BaseUserEntity userEntity = BaseUserManager.GetObjectByOpenIdByCache(openId); if (userEntity != null && !string.IsNullOrEmpty(userEntity.Id)) { string ipAddressName = string.Empty; if (!string.IsNullOrEmpty(ipAddress)) { ipAddressName = IpHelper.GetInstance().FindName(ipAddress); } BaseLoginLogManager.AddLog(systemCode, userEntity, ipAddress, ipAddressName, macAddress, Status.SignOut.ToDescription()); // 是否更新访问日期信息 if (!BaseSystemInfo.UpdateVisit) { return(result > 0); } string sqlQuery = string.Empty; // 最后一次登录时间 sqlQuery = " UPDATE " + BaseUserLogOnEntity.TableName + " SET " + BaseUserLogOnEntity.FieldPreviousVisit + " = " + BaseUserLogOnEntity.FieldLastVisit; if (createOpenId) { // sqlQuery += " , " + BaseUserLogOnEntity.FieldOpenId + " = '" + System.Guid.NewGuid().ToString("N") + "'"; } sqlQuery += " , " + BaseUserLogOnEntity.FieldUserOnLine + " = 0 " + " , " + BaseUserLogOnEntity.FieldLastVisit + " = " + this.DbHelper.GetDbNow(); sqlQuery += " WHERE " + BaseUserLogOnEntity.FieldId + " = " + DbHelper.GetParameter(BaseUserEntity.FieldId); List <IDbDataParameter> dbParameters = new List <IDbDataParameter>(); dbParameters.Add(DbHelper.MakeParameter(BaseUserEntity.FieldId, userEntity.Id)); result = this.DbHelper.ExecuteNonQuery(sqlQuery, dbParameters.ToArray()); } } return(result > 0); }