Ejemplo n.º 1
0
        /// <summary>
        /// 按照一定的步长去消息。
        /// </summary>
        /// <param name="fromUuid"></param>
        /// <param name="toUuid"></param>
        /// <param name="sectionNo"></param>
        /// <returns></returns>
        public static async Task<List<string>> GetMessage(string fromUuid, string toUuid, int sectionNo,bool isNeedCleanUnred=true)
        {
            fromUuid = fromUuid.Trim().ToUpper();
            toUuid = toUuid.Trim().ToUpper();

            var config = BK.Configuration.BK_ConfigurationManager.GetConfig<UserBehaviorConfig>();
            int pageSize = Convert.ToInt32(config.GetMessageCount);
            int fromIndex = pageSize * sectionNo;
            string sessionid = await WeChatSendMQHelper.GetOrCreateSessionId(fromUuid, toUuid);

            //清空fromUuid的sessionid的未读消息
            if(isNeedCleanUnred)
                await MessageRedisOp.CleanUnreadScore(fromUuid, sessionid);

            if (sectionNo == 0)
            {
                return await GetMessagesFromRedis(fromUuid, toUuid);
            }

            using (MessageRepository r = new MessageRepository())
            {
                var list =  await r.GetLogRecordsAsync(fromIndex, pageSize, sessionid);
                if (list == null || list.Count == 0)
                    return null;
                List<string> ret = new List<string>();
                foreach(var l in list)
                {
                    double time = CommonLib.Util.CommonHelper.ToUnixTime(l.TimeStamp);
                    string from = l.From;
                    string message = from + ":" + time.ToString() + ":" + l.Message;
                    ret.Add(message);
                }
                return ret;
            }
        }