コード例 #1
0
ファイル: ActivityRepository.cs プロジェクト: yaotyl/spb4mono
        /// <summary>
        /// 在用户动态收件箱追溯OwnerId的动态
        /// </summary>
        /// <remarks>
        /// 关注用户/加入群组、取消屏蔽用户/取消屏蔽群组时使用
        /// </remarks>
        /// <param name="userId">UserId</param>
        /// <param name="ownerId">动态拥有者Id</param>
        /// <param name="ownerType">动态拥有者类型</param>
        /// <param name="traceBackNumber">追溯OwnerId的动态数</param>
        public void TraceBackInboxAboutOwner(long userId, long ownerId, int ownerType, int traceBackNumber)
        {
            //缓存需要即时
            //1、仅追溯traceBackNumber条非私有的动态;

            PetaPocoDatabase dao = CreateDAO();

            dao.OpenSharedConnection();

            Sql sql = Sql.Builder
                      .Select("ActivityId")
                      .From("tn_Activities")
                      .Where("OwnerId=@0", ownerId)
                      .Where("OwnerType=@0", ownerType)
                      .Where("IsPrivate=0")
                      .OrderBy("LastModified desc");
            IEnumerable <object> activityIds = dao.FetchTopPrimaryKeys <Activity>(traceBackNumber, sql);
            List <Sql>           sqls        = new List <Sql>();

            foreach (var activityId in activityIds.Cast <long>())
            {
                sql = Sql.Builder.Select("count(*)").From("tn_ActivityUserInbox").Where("ActivityId = @0", activityId).Where("UserId = @0", userId);
                if (dao.FirstOrDefault <long>(sql) > 0)
                {
                    continue;  //已经存在
                }
                sql = Sql.Builder.Append("insert tn_ActivityUserInbox (UserId,ActivityId) values(@0,@1)", userId, activityId);
                sqls.Add(sql);
            }
            int affectCount = dao.Execute(sqls);

            dao.CloseSharedConnection();

            if (affectCount > 0)
            {
                RealTimeCacheHelper.IncreaseAreaVersion("UserId", userId);
            }
        }