Beispiel #1
0
        /// <summary>
        /// 执行队列
        /// </summary>
        public void ExecQueue()
        {
            PetaPocoDatabase dao = CreateDAO();

            dao.OpenSharedConnection();
            var tempCreateVisitQueue = new Queue <long>(CreateVisitQueue);

            CreateVisitQueue.Clear();

            while (tempCreateVisitQueue.Count > 0)
            {
                Visit visit = Get(tempCreateVisitQueue.Dequeue());
                if (visit == null)
                {
                    continue;
                }
                dao.Insert(visit);
            }
            //将队列中的数据更新到数据库
            var tempUpdateVisitQueue = new Queue <long>(UpdateVisitQueue);

            UpdateVisitQueue.Clear();
            while (tempUpdateVisitQueue.Count > 0)
            {
                Visit visit = Get(tempUpdateVisitQueue.Dequeue());
                if (visit == null)
                {
                    continue;
                }
                dao.Update(visit);
            }
            dao.CloseSharedConnection();
        }
Beispiel #2
0
        /// <summary>
        /// 保存用户自定义风格
        /// </summary>
        /// <param name="presentAreaKey">呈现区域标识</param>
        /// <param name="ownerId">OwnerId</param>
        /// <param name="customStyle">自定义风格实体</param>
        public void Save(string presentAreaKey, long ownerId, CustomStyle customStyle)
        {
            PetaPocoDatabase database = CreateDAO();

            database.OpenSharedConnection();
            CustomStyleEntity entity         = Get(presentAreaKey, ownerId);
            string            customStyleXml = Serialize(customStyle);

            if (entity != null)
            {
                customStyle.LastModified     = DateTime.UtcNow;
                entity.CustomStyle           = customStyle;
                entity.SerializedCustomStyle = customStyleXml;
                entity.LastModified          = DateTime.UtcNow;
                database.Update(entity);
            }
            else
            {
                entity                       = CustomStyleEntity.New();
                entity.CustomStyle           = customStyle;
                entity.PresentAreaKey        = presentAreaKey;
                entity.OwnerId               = ownerId;
                entity.SerializedCustomStyle = customStyleXml;
                database.Insert(entity);
            }

            database.CloseSharedConnection();
            cacheService.Set(GetCacheKey_CustomStyleEntity(presentAreaKey, ownerId), entity, CachingExpirationType.UsualSingleObject);
        }
        /// <summary>
        /// 用户批量更新提醒设置
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="userReminderSettings">用户提醒设置集合</param>
        public void BatchUpdateUserReminderSettings(long userId, IEnumerable <UserReminderSettings> userReminderSettings)
        {
            PetaPocoDatabase dao = CreateDAO();

            dao.OpenSharedConnection();
            bool hasSetting = false;
            var  sql        = PetaPoco.Sql.Builder;

            sql.Select("Id")
            .From("tn_UserReminderSettings")
            .Where("userId=@0", userId);

            List <long> ids = dao.Fetch <long>(sql);

            IEnumerable <UserReminderSettings> oldUserReminderSettings = PopulateEntitiesByEntityIds(ids);

            foreach (var userReminderSetting in userReminderSettings)
            {
                foreach (var oldUserReminderSetting in oldUserReminderSettings)
                {
                    if (oldUserReminderSetting.ReminderInfoTypeId == userReminderSetting.ReminderInfoTypeId && oldUserReminderSetting.ReminderModeId == userReminderSetting.ReminderModeId)
                    {
                        hasSetting = true;
                        if (oldUserReminderSetting.ReminderThreshold == userReminderSetting.ReminderThreshold &&
                            oldUserReminderSetting.IsEnabled == userReminderSetting.IsEnabled &&
                            oldUserReminderSetting.IsRepeated == userReminderSetting.IsRepeated &&
                            oldUserReminderSetting.RepeatInterval == userReminderSetting.RepeatInterval)
                        {
                            break;
                        }
                        else
                        {
                            oldUserReminderSetting.IsEnabled         = userReminderSetting.IsEnabled;
                            oldUserReminderSetting.IsRepeated        = userReminderSetting.IsRepeated;
                            oldUserReminderSetting.ReminderThreshold = userReminderSetting.ReminderThreshold;
                            oldUserReminderSetting.RepeatInterval    = userReminderSetting.RepeatInterval;
                            dao.Update(oldUserReminderSetting);
                            break;
                        }
                    }
                }
                if (!hasSetting)
                {
                    dao.Insert(userReminderSetting);
                }
                hasSetting = false;
            }
            dao.CloseSharedConnection();

            RealTimeCacheHelper.IncreaseAreaVersion("UserId", userId);
        }
Beispiel #4
0
        /// <summary>
        /// 更新用户的隐私设置
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="userSettings"><remarks>key=itemKey,value=PrivacyStatus</remarks></param>
        public void UpdateUserPrivacySettings(long userId, Dictionary <string, PrivacyStatus> userSettings)
        {
            PetaPocoDatabase dao = CreateDAO();

            var sql = Sql.Builder;

            sql.Select("*")
            .From("tn_UserPrivacySettings")
            .Where("UserId = @0", userId);
            //done:zhangp,by zhengw:应该共享一个数据库连接
            //回复:已经修改
            dao.OpenSharedConnection();
            UserPrivacySetting        setting;
            List <UserPrivacySetting> settings = dao.Fetch <UserPrivacySetting>(sql);

            if (userSettings == null)
            {
                return;
            }
            foreach (var item in userSettings)
            {
                setting = settings.Find(n => n.ItemKey == item.Key);
                if (setting != null)
                {
                    var sqlDel = Sql.Builder;
                    sqlDel.Append("delete from tn_UserPrivacySpecifyObjects where UserPrivacySettingId in (select Id from tn_UserPrivacySettings where UserId = @0 and ItemKey = @1)", userId, item.Key);
                    dao.Execute(sqlDel);
                    EntityData.ForType(typeof(UserPrivacySpecifyObject)).RealTimeCacheHelper.IncreaseAreaVersion("UserId", userId);
                    setting.PrivacyStatus = item.Value;
                    dao.Update(setting);
                    OnUpdated(setting);
                }
                else
                {
                    setting               = new UserPrivacySetting();
                    setting.UserId        = userId;
                    setting.ItemKey       = item.Key;
                    setting.PrivacyStatus = item.Value;
                    base.Insert(setting);
                }
            }
            dao.CloseSharedConnection();
            RealTimeCacheHelper.IncreaseAreaVersion("UserId", userId);
        }
        /// <summary>
        /// 变更应用数据
        /// </summary>
        /// <param name="applicationId">应用Id</param>
        /// <param name="dataKey">数据标识</param>
        /// <param name="value">待变更的值</param>
        public void Change(int applicationId, string dataKey, string value)
        {
            PetaPocoDatabase dao             = CreateDAO();
            ApplicationData  applicationData = Get(applicationId, dataKey);

            if (applicationData == null)
            {
                applicationData = new ApplicationData();
                applicationData.ApplicationId = applicationId;
                applicationData.Datakey       = dataKey;
                applicationData.TenantTypeId  = string.Empty;
                applicationData.StringValue   = value;
                dao.Insert(applicationData);
            }
            else
            {
                applicationData.StringValue = value;
                dao.Update(applicationData);
            }
            RealTimeCacheHelper.IncreaseEntityCacheVersion(applicationData);
        }
        /// <summary>
        /// 变更系统数据
        /// </summary>
        /// <param name="dataKey">数据标识</param>
        /// <param name="number">待变更的数值</param>
        public void Change(string dataKey, long number)
        {
            //当DataKey不存在时,插入新数据

            PetaPocoDatabase dao        = CreateDAO();
            SystemData       systemData = Get(dataKey);

            if (systemData == null)
            {
                systemData           = new SystemData();
                systemData.Datakey   = dataKey;
                systemData.LongValue = number;
                dao.Insert(systemData);
            }
            else
            {
                systemData.LongValue += number;
                dao.Update(systemData);
            }
            RealTimeCacheHelper.IncreaseEntityCacheVersion(systemData);
        }
Beispiel #7
0
        /// <summary>
        /// 变更系统数据
        /// </summary>
        /// <param name="ownerId">ownerId</param>
        /// <param name="tenantTypeId">租户类型Id</param>
        /// <param name="dataKey">数据标识</param>
        /// <param name="value">待变更的数值</param>
        public void Change(long ownerId, string tenantTypeId, string dataKey, decimal value)
        {
            PetaPocoDatabase dao = CreateDAO();

            OwnerData ownerData = Get(ownerId, tenantTypeId, dataKey);

            if (ownerData == null || ownerData.Id == 0)
            {
                ownerData              = OwnerData.New();
                ownerData.OwnerId      = ownerId;
                ownerData.Datakey      = dataKey;
                ownerData.DecimalValue = value;
                ownerData.TenantTypeId = tenantTypeId;

                Sql sql = Sql.Builder;
                sql.Append("update tn_OwnerData set DecimalValue = @3 where DataKey = @0 and OwnerId = @1 and TenantTypeId = @2", dataKey, ownerId, tenantTypeId, value);

                int affectCount = dao.Execute(sql);
                if (affectCount == 0)
                {
                    dao.Insert(ownerData);
                }
            }
            else
            {
                ownerData.DecimalValue = ownerData.DecimalValue + value > 0 ? ownerData.DecimalValue + value : 0;
                dao.Update(ownerData);
            }

            //done:libsh,by zhengw: 同上
            //replay:已修改
            string    cacheKey       = GetCacheKey_GetOwnerData(ownerId, dataKey, tenantTypeId);
            OwnerData cacheOwnerdata = cacheService.Get <OwnerData>(cacheKey);

            if (cacheOwnerdata != null)
            {
                cacheService.Set(cacheKey, ownerData, CachingExpirationType.SingleObject);
            }
        }
Beispiel #8
0
        /// <summary>
        /// 更新积分统计
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="pointCategory2PointsDictionary"><remarks>key=PointCategory,value=Points</remarks>积分分类-积分字典</param>
        /// <returns>修订后应获取到的积分值</returns>
        public Dictionary <string, int> UpdateStatistic(long userId, Dictionary <PointCategory, int> pointCategory2PointsDictionary)
        {
            Dictionary <string, int> dictionary = new Dictionary <string, int>();

            RWLock.EnterWriteLock();

            PetaPocoDatabase dao = CreateDAO();

            try
            {
                dao.OpenSharedConnection();

                //1、检查当日积分统计是否存在,不存在创建
                //2、检查是否超过当日限额,如果未超过更新当日积分累计
                var sql = Sql.Builder;
                sql.Select("*")
                .From("tn_PointStatistics")
                .Where("UserId = @0", userId)
                .Where("StatisticalYear = @0", DateTime.UtcNow.Year)
                .Where("StatisticalMonth = @0", DateTime.UtcNow.Month)
                .Where("StatisticalDay = @0", DateTime.UtcNow.Day);

                IEnumerable <PointStatistic> pointStatistices = dao.Fetch <PointStatistic>(sql);

                //初始化
                foreach (var pair in pointCategory2PointsDictionary)
                {
                    dictionary[pair.Key.CategoryKey] = pair.Value;
                }

                //当日积分统计不存在
                if (pointStatistices == null || pointStatistices.Count() == 0)
                {
                    //创建当日积分统计
                    foreach (var pair in pointCategory2PointsDictionary)
                    {
                        if (pair.Key.QuotaPerDay <= 0)
                        {
                            continue;
                        }

                        var pointStatistic = PointStatistic.New();
                        pointStatistic.UserId           = userId;
                        pointStatistic.PointCategoryKey = pair.Key.CategoryKey;
                        pointStatistic.Points           = pair.Value;

                        dao.Insert(pointStatistic);
                    }
                }
                else
                {
                    //检查是积分限额,调整用户最终获取到的积分
                    foreach (var pair in pointCategory2PointsDictionary)
                    {
                        if (pair.Key.QuotaPerDay <= 0)
                        {
                            continue;
                        }
                        var category       = pair.Key;
                        var pointStatistic = pointStatistices.FirstOrDefault(n => n.PointCategoryKey == category.CategoryKey);
                        if (pointStatistic == null)
                        {
                            continue;
                        }
                        if (pair.Value > 0 && pointStatistic.Points + pair.Value > category.QuotaPerDay)//超过限额
                        {
                            dictionary[pair.Key.CategoryKey] = 0;
                        }
                        else
                        {
                            pointStatistic.Points += pair.Value;
                            dao.Update(pointStatistic);
                        }
                    }
                }
            }
            finally
            {
                dao.CloseSharedConnection();
                RWLock.ExitWriteLock();
            }

            //更新用户分区缓存
            RealTimeCacheHelper.IncreaseAreaVersion("UserId", userId);


            return(dictionary);
        }