示例#1
0
        public override bool StepExecute(int operatorUserID, string param, ref long offset, ref int totalCount, ref int finishedCount, out string title, out bool isLastStep)
        {
            FeedSearchFilter filter = FeedSearchFilter.Parse(param);

            int stepCount;

            if (FeedBO.Instance.DeleteSearchFeeds(operatorUserID, filter, stepDeleteCount, out stepCount)) // .DeleteDoingsBySearch(filter, 200);
            {
                finishedCount += stepCount;

                isLastStep = stepCount < stepDeleteCount;

                title = "正在删除动态,总数 " + totalCount + ",已删 " + finishedCount;

                return(true);
            }
            else
            {
                isLastStep = false;

                title = "发生错误";

                return(false);
            }
        }
示例#2
0
        private void DeleteAllSearch()
        {
            FeedSearchFilter filter = FeedSearchFilter.GetFromFilter("filter");

            if (TaskManager.BeginTask(MyUserID, new DeleteFeedTask(), filter.ToString()))
            {
            }
        }
示例#3
0
        public override void AfterExecute(int operatorUserID, string param, bool success, int totalCount, int finishedCount, out string title)
        {
            if (success)
            {
                title = "删除动态成功,共删除 " + finishedCount + " 个动态";

                FeedSearchFilter filter = FeedSearchFilter.Parse(param);

                User operatorUser = UserBO.Instance.GetUser(operatorUserID, GetUserOption.WithAll);

                Logs.LogManager.LogOperation(
                    new Feed_DeleteFeedBySearch(operatorUserID, operatorUser.Name, IPUtil.GetCurrentIP(), filter, finishedCount)
                    );
            }
            else
            {
                title = "删除动态失败";
            }
        }
示例#4
0
        public override bool BeforeExecute(int operatorUserID, string param, ref long offset, ref int totalCount, out string title)
        {
            FeedSearchFilter filter = FeedSearchFilter.Parse(param);

            int            tempTotalCount;
            FeedCollection feeds = FeedBO.Instance.SearchFeeds(1, filter, out tempTotalCount);

            if (feeds == null || feeds.Count == 0)
            {
                title = "没有数据可以删除";
                return(false);
            }

            totalCount = tempTotalCount;

            title = "将删除 " + totalCount + " 条动态";

            return(true);
        }
示例#5
0
        public void FeedSearchList(string filter, int page, int defaultPageSize
                                   , FeedSearchListHeadFootTemplate head
                                   , FeedSearchListHeadFootTemplate foot
                                   , FeedSearchListItemTemplate item)
        {
            FeedSearchFilter feedSearchFilter = FeedSearchFilter.GetFromFilter(filter);
            int            totalCount;
            FeedCollection feeds = new FeedCollection();
            //int pageSize;

            FeedSearchFilter tempFilter;

            if (feedSearchFilter.IsNull)
            {
                tempFilter          = new FeedSearchFilter();
                tempFilter.PageSize = defaultPageSize;
                tempFilter.Order    = FeedSearchFilter.OrderBy.ID;
                tempFilter.IsDesc   = true;
            }
            else
            {
                tempFilter = feedSearchFilter;
            }

            feeds = FeedBO.Instance.SearchFeeds(page, tempFilter, out totalCount);

            head(feedSearchFilter, totalCount > 0, totalCount, tempFilter.PageSize);

            int loginUserID = UserBO.Instance.GetCurrentUserID();
            int i           = 0;

            float timeDiffrence = UserBO.Instance.GetUserTimeDiffrence(User.Current);


            foreach (Feed feed in feeds)
            {
                string title       = FeedBO.Instance.FormatFeedTitle(loginUserID, timeDiffrence, FeedType.AllUserFeed, feed);
                string description = FeedBO.Instance.FormatFeedDescription(loginUserID, feed);
                item(i++, feed, title, description, true);
            }

            foot(feedSearchFilter, totalCount > 0, totalCount, tempFilter.PageSize);
        }
示例#6
0
        public void FeedSearchList(string filter, int page, int defaultPageSize
            , FeedSearchListHeadFootTemplate head
            , FeedSearchListHeadFootTemplate foot
            , FeedSearchListItemTemplate item)
        {
            FeedSearchFilter feedSearchFilter = FeedSearchFilter.GetFromFilter(filter);
            int totalCount;
            FeedCollection feeds = new FeedCollection();
            //int pageSize;

            FeedSearchFilter tempFilter;
            if (feedSearchFilter.IsNull)
            {
                tempFilter = new FeedSearchFilter();
                tempFilter.PageSize = defaultPageSize;
                tempFilter.Order = FeedSearchFilter.OrderBy.ID;
                tempFilter.IsDesc = true;
            }
            else
                tempFilter = feedSearchFilter;
            
            feeds = FeedBO.Instance.SearchFeeds(page, tempFilter, out totalCount);

            head(feedSearchFilter, totalCount > 0, totalCount, tempFilter.PageSize);

            int loginUserID = UserBO.Instance.GetCurrentUserID();
            int i = 0;

            float timeDiffrence = UserBO.Instance.GetUserTimeDiffrence(User.Current);


            foreach (Feed feed in feeds)
            {
                string title = FeedBO.Instance.FormatFeedTitle(loginUserID, timeDiffrence, FeedType.AllUserFeed, feed);
                string description = FeedBO.Instance.FormatFeedDescription(loginUserID, feed);
                item(i++, feed, title, description, true);
            }

            foot(feedSearchFilter, totalCount > 0, totalCount, tempFilter.PageSize);
        }
示例#7
0
 public abstract void DeleteSearchFeeds(FeedSearchFilter filter, int deleteTopCount, out int deletedCount);
示例#8
0
 public abstract FeedCollection SearchFeeds(int pageNumber, FeedSearchFilter filter, ref int totalCount);
示例#9
0
        private void SearchFeeds()
        {
            FeedSearchFilter filter = FeedSearchFilter.GetFromForm();

            filter.Apply("filter", "page");
        }
示例#10
0
        public override void DeleteSearchFeeds(FeedSearchFilter filter, int deleteTopCount, out int deletedCount)
        {
            string order;

            if (filter.Order == FeedSearchFilter.OrderBy.ID)
            {
                if (filter.IsDesc)
                    order = " ORDER BY [ID] DESC ";
                else
                    order = " ORDER BY [ID] ASC ";
            }
            else
            {
                if (filter.IsDesc)
                    order = " ORDER BY [CreateDate] DESC ";
                else
                    order = " ORDER BY [CreateDate] ASC ";
            }

            if (filter.UserID != null)
            {
                string condition = @" UserID = @UserID "
                            + (filter.AppID == null ? "" : (@" AND [FeedID] IN(SELECT [ID] FROM [bx_Feeds] WHERE [AppID]=@AppID "
                            + (filter.AppActionType == null ? "" : (" AND [ActionType] = @ActionType)"))))
                            + (filter.BeginDate == null ? "" : (" AND [CreateDate] > @BeginDate"))
                            + (filter.EndDate == null ? "" : (" AND [CreateDate] < @EndDate"));




                using (SqlQuery query = new SqlQuery())
                {
                    query.CommandText = @"
DELETE [bx_UserFeeds] WHERE [ID] IN (SELECT TOP (@TopCount) [ID] FROM [bx_UserFeeds] WHERE " + condition + order + @" );
SELECT @@ROWCOUNT;
DELETE [bx_Feeds] WHERE [ID] NOT IN(SELECT DISTINCT [FeedID] FROM [bx_UserFeeds]);
--以下是删除 类似加好友的动态 
DECLARE @T TABLE(UserCount int,FeedID int);
DECLARE @FeedIDs TABLE(FeedID int);
INSERT INTO @T SELECT COUNT(*),[FeedID] FROM bx_UserFeeds GROUP BY [FeedID];
INSERT INTO @FeedIDs SELECT [FeedID] FROM bx_UserFeeds UF INNER JOIN bx_Feeds F ON UF.[FeedID]=F.[ID] WHERE F.[ID] IN(SELECT [FeedID] FROM @T WHERE [UserCount]=1) AND UF.[UserID]=F.[TargetUserID];
DELETE [bx_Feeds] WHERE [ID] IN(SELECT [FeedID] FROM @FeedIDs);
";
                    query.CreateTopParameter("@TopCount", deleteTopCount);
                    query.CreateParameter<int?>("@UserID", filter.UserID, SqlDbType.Int);
                    query.CreateParameter<Guid?>("@AppID", filter.AppID, SqlDbType.UniqueIdentifier);
                    query.CreateParameter<int?>("@ActionType", filter.AppActionType, SqlDbType.Int);
                    query.CreateParameter<DateTime?>("@BeginDate", filter.BeginDate, SqlDbType.DateTime);
                    query.CreateParameter<DateTime?>("@EndDate", filter.EndDate, SqlDbType.DateTime);


                    deletedCount = 0;
                    using (XSqlDataReader reader = query.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            deletedCount = reader.Get<int>(0);
                        }
                    }
                }
            }
            else
            {
                string condition = @" 1 = 1 "
                            + (filter.AppID == null ? "" : (@" AND [AppID]=@AppID ")
                            + (filter.AppActionType == null ? "" : (" AND [ActionType] = @ActionType")))
                            + (filter.BeginDate == null ? "" : (" AND [CreateDate] > @BeginDate"))
                            + (filter.EndDate == null ? "" : (" AND [CreateDate] < @EndDate"));
                using (SqlQuery query = new SqlQuery())
                {
                    query.CommandText = "DELETE [bx_Feeds] WHERE [ID] IN (SELECT TOP (@TopCount) [ID] FROM [bx_Feeds] WHERE " + condition + order + ")";

                    query.CreateTopParameter("@TopCount", deleteTopCount);
                    query.CreateParameter<Guid?>("@AppID", filter.AppID, SqlDbType.UniqueIdentifier);
                    query.CreateParameter<int?>("@ActionType", filter.AppActionType, SqlDbType.Int);
                    query.CreateParameter<DateTime?>("@BeginDate", filter.BeginDate, SqlDbType.DateTime);
                    query.CreateParameter<DateTime?>("@EndDate", filter.EndDate, SqlDbType.DateTime);

                    deletedCount = 0;
                    using (XSqlDataReader reader = query.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            deletedCount = reader.Get<int>(0);
                        }
                    }
                }

            }
        }
示例#11
0
        public override FeedCollection SearchFeeds(int pageNumber, FeedSearchFilter filter, ref int totalCount)
        {

            using (SqlSession db = new SqlSession())
            {
                List<int> feedIDs = new List<int>();
                using (SqlQuery query = db.CreateQuery())
                {
                    query.Pager.IsDesc = filter.IsDesc;
                    if (filter.UserID != null)
                    {
                        query.Pager.ResultFields = "[FeedID]";
                        if (filter.Order == FeedSearchFilter.OrderBy.ID)
                            query.Pager.SortField = "[ID]";
                        else
                        {
                            query.Pager.SortField = "[CreateDate]";
                            query.Pager.PrimaryKey = "[ID]";
                        }
                        query.Pager.TableName = "[bx_UserFeeds]";
                        query.Pager.Condition = @" UserID = @UserID "
                            + (filter.AppID == null ? "" : (@" AND [FeedID] IN(SELECT [ID] FROM [bx_Feeds] WHERE [AppID]=@AppID "
                            + (filter.AppActionType == null ? "" : (" AND [ActionType] = @ActionType)"))))
                            + (filter.BeginDate == null ? "" : (" AND [CreateDate] > @BeginDate"))
                            + (filter.EndDate == null ? "" : (" AND [CreateDate] < @EndDate"));
                    }
                    else
                    {
                        query.Pager.ResultFields = "[ID]";
                        if (filter.Order == FeedSearchFilter.OrderBy.ID)
                            query.Pager.SortField = "[ID]";
                        else
                        {
                            query.Pager.SortField = "[CreateDate]";
                            query.Pager.PrimaryKey = "[ID]";
                        }

                        query.Pager.TableName = "[bx_Feeds]";
                        query.Pager.Condition = @" 1 = 1 "
                            + (filter.AppID == null ? "" : (@" AND [AppID]=@AppID ")
                            + (filter.AppActionType == null ? "" : (" AND [ActionType] = @ActionType")))
                            + (filter.BeginDate == null ? "" : (" AND [CreateDate] > @BeginDate"))
                            + (filter.EndDate == null ? "" : (" AND [CreateDate] < @EndDate"));
                    }
                    query.Pager.PageNumber = pageNumber;
                    query.Pager.PageSize = filter.PageSize;

                    query.Pager.TotalRecords = totalCount;
                    query.Pager.SelectCount = true;

                    query.CreateParameter<int?>("@UserID", filter.UserID, SqlDbType.Int);
                    query.CreateParameter<Guid?>("@AppID", filter.AppID, SqlDbType.UniqueIdentifier);
                    query.CreateParameter<int?>("@ActionType", filter.AppActionType, SqlDbType.Int);
                    query.CreateParameter<DateTime?>("@BeginDate", filter.BeginDate, SqlDbType.DateTime);
                    query.CreateParameter<DateTime?>("@EndDate", filter.EndDate, SqlDbType.DateTime);


                    using (XSqlDataReader reader = query.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            feedIDs.Add(reader.GetInt32(0));
                        }
                        if (reader.NextResult())
                        {
                            while (reader.Read())
                            {
                                totalCount = reader.GetInt32(0);
                            }
                        }
                    }
                }

                if (feedIDs.Count == 0)
                    return new FeedCollection();


                string sql;
                string sortField = (filter.Order == FeedSearchFilter.OrderBy.ID ? "[ID]" : "[CreateDate]");
                string order = (filter.IsDesc ? " DESC " : " ASC ");
                if (filter.UserID == null)
                {
                    sql = @"
                    SELECT * FROM [bx_Feeds] WHERE [ID] IN(@FeedIDs) ORDER BY " + sortField + order + @";
                    SELECT * FROM [bx_UserFeeds] WHERE [FeedID] IN(@FeedIDs) ORDER BY [FeedID] DESC,[CreateDate] DESC;
";
                }
                else
                {
                    sql = @"
                    SELECT * FROM [bx_Feeds] WHERE [ID] IN(@FeedIDs) ORDER BY " + sortField + order + @";
                    SELECT * FROM [bx_UserFeeds] WHERE [FeedID] IN(@FeedIDs) ORDER BY [FeedID] DESC,[CreateDate] DESC;
                    SELECT * FROM [bx_UserFeeds] WHERE [FeedID] IN(SELECT [FeedID] FROM [bx_UserFeeds] UF INNER JOIN [bx_Feeds] F ON UF.[FeedID]=F.[ID] WHERE F.[ID] IN(@FeedIDs) AND UF.[UserID]=F.[TargetUserID] AND F.[TargetUserID]=@UserID) ORDER BY [CreateDate] DESC;
";
                }


                using (SqlQuery query = db.CreateQuery())
                {
                    query.CommandText = sql;

                    query.CreateParameter<int?>("@UserID", filter.UserID, SqlDbType.Int);

                    query.CreateInParameter<int>("@FeedIDs", feedIDs);
                    using (XSqlDataReader reader = query.ExecuteReader())
                    {
                        FeedCollection feeds = new FeedCollection(reader);

                        if (reader.NextResult())
                        {
                            Feed currentFeed = null;

                            while (reader.Read())
                            {
                                UserFeed userFeed = new UserFeed(reader);

                                currentFeed = ProcessFeed(feeds, currentFeed, userFeed, false);
                            }
                        }

                        if (reader.NextResult())// 这一组是特殊的 处理类似加好友的 如果TargetUserID 是好友 需要把UserFeeds 表里与该动态有关的用户都取出来
                        {
                            Feed currentFeed = null;

                            while (reader.Read())
                            {
                                UserFeed userFeed = new UserFeed(reader);

                                currentFeed = ProcessFeed(feeds, currentFeed, userFeed, true);
                            }
                        }
                        return feeds;
                    }
                }

            }
        }