/// <summary>
        /// 从数据库加载上来?缓存预热的机制
        /// </summary>
        /// <returns></returns>
        public static int CachePreheating()
        {
            int result = 0;
            // 把所有的数据都缓存起来的代码
            var manager = new BaseOrganizeLogOnManager();

            using (IDataReader dataReader = manager.ExecuteReader(0, BaseOrganizeLogOnEntity.FieldId))
            {
                while (dataReader.Read())
                {
                    var entity = BaseEntity.Create <BaseOrganizeLogOnEntity>(dataReader, false);
                    SetCache(entity);
                    result++;
                }
                dataReader.Close();
            }

            return(result);
        }
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">实体</param>
        public static int LogOnStatistics()
        {
            int result = 0;

            bool update = false;
            int  i      = 0;

            // 电脑登录系统、没有登记过的,全部登记上来。
            BaseOrganizeLogOnEntity organizeLogOnEntity = null;
            string sqlQuery = string.Empty;

            sqlQuery = @"SELECT u.companyid id
                                , MIN(l.firstvisit) firstvisit
                                , MAX(l.lastvisit) lastvisit 
                           FROM baseuserlogon l
                                , baseuser u 
                          WHERE l.id = u.id 
                          GROUP BY u.companyid";

            BaseOrganizeLogOnManager organizeLogOnManager = new BaseOrganizeLogOnManager();
            BaseOrganizeLogOnManager manager = new BaseOrganizeLogOnManager();

            using (IDataReader dataReader = manager.ExecuteReader(sqlQuery))
            {
                while (dataReader.Read())
                {
                    i++;
                    string id = BaseBusinessLogic.ConvertToString(dataReader[BaseOrganizeLogOnEntity.FieldId]);

                    DateTime?firstVisit = BaseBusinessLogic.ConvertToNullableDateTime(dataReader[BaseOrganizeLogOnEntity.FieldFirstVisit]);
                    DateTime?lastVisit  = BaseBusinessLogic.ConvertToNullableDateTime(dataReader[BaseOrganizeLogOnEntity.FieldLastVisit]);
                    organizeLogOnEntity = organizeLogOnManager.GetObject(id);
                    if (organizeLogOnEntity == null)
                    {
                        organizeLogOnEntity            = new BaseOrganizeLogOnEntity();
                        organizeLogOnEntity.Id         = id;
                        organizeLogOnEntity.FirstVisit = firstVisit;
                        organizeLogOnEntity.LastVisit  = lastVisit;
                        organizeLogOnManager.AddObject(organizeLogOnEntity);
                    }
                    else
                    {
                        update = false;
                        if (firstVisit.HasValue)
                        {
                            if (organizeLogOnEntity.FirstVisit == null || organizeLogOnEntity.FirstVisit > firstVisit)
                            {
                                organizeLogOnEntity.FirstVisit = firstVisit;
                                update = true;
                            }
                        }
                        if (lastVisit.HasValue)
                        {
                            if (organizeLogOnEntity.LastVisit == null || organizeLogOnEntity.LastVisit < lastVisit)
                            {
                                organizeLogOnEntity.LastVisit = lastVisit;
                                update = true;
                            }
                        }
                        if (update)
                        {
                            organizeLogOnManager.UpdateObject(organizeLogOnEntity);
                        }
                    }
                    if (update)
                    {
                        System.Console.WriteLine("第 " + i.ToString() + " companyid : " + id);
                    }
                    else
                    {
                        System.Console.WriteLine("第 " + i.ToString());
                    }
                }
                dataReader.Close();
            }

            // 巴枪登录系统、没有登记过的,全部登记上来。
            sqlQuery = @"SELECT u.companyid id
                                , MIN(l.firstvisit) firstvisit
                                , MAX(l.lastvisit) lastvisit 
                           FROM pdauserlogon l
                                , baseuser u 
                          WHERE l.id = u.id 
                          GROUP BY u.companyid";
            using (IDataReader dataReader = manager.ExecuteReader(sqlQuery))
            {
                i = 0;
                while (dataReader.Read())
                {
                    i++;
                    string   id         = BaseBusinessLogic.ConvertToString(dataReader[BaseOrganizeLogOnEntity.FieldId]);
                    DateTime?firstVisit = BaseBusinessLogic.ConvertToNullableDateTime(dataReader[BaseOrganizeLogOnEntity.FieldFirstVisit]);
                    DateTime?lastVisit  = BaseBusinessLogic.ConvertToNullableDateTime(dataReader[BaseOrganizeLogOnEntity.FieldLastVisit]);
                    organizeLogOnEntity = organizeLogOnManager.GetObject(id);
                    if (organizeLogOnEntity == null)
                    {
                        organizeLogOnEntity            = new BaseOrganizeLogOnEntity();
                        organizeLogOnEntity.Id         = id;
                        organizeLogOnEntity.FirstVisit = firstVisit;
                        organizeLogOnEntity.LastVisit  = lastVisit;
                        organizeLogOnManager.Add(organizeLogOnEntity);
                    }
                    else
                    {
                        update = false;
                        if (firstVisit.HasValue)
                        {
                            if (organizeLogOnEntity.FirstVisit == null || organizeLogOnEntity.FirstVisit > firstVisit)
                            {
                                organizeLogOnEntity.FirstVisit = firstVisit;
                                update = true;
                            }
                        }
                        if (lastVisit.HasValue)
                        {
                            if (organizeLogOnEntity.LastVisit == null || organizeLogOnEntity.LastVisit < lastVisit)
                            {
                                organizeLogOnEntity.LastVisit = lastVisit;
                                update = true;
                            }
                        }
                        organizeLogOnManager.UpdateObject(organizeLogOnEntity);
                    }

                    if (update)
                    {
                        System.Console.WriteLine("第 " + i.ToString() + " companyid : " + id);
                    }
                    else
                    {
                        System.Console.WriteLine("第 " + i.ToString());
                    }
                }
                dataReader.Close();
            }

            System.Console.WriteLine("公司整体登录状态已经更新完毕。");

            return(result);
        }