public void TestTime() { List <long> idlist = new List <long>(); Stopwatch www = new Stopwatch(); for (int i = 0; i < 5; i++) { www.Restart(); www.Start(); SpecialDetailView sv1 = GetUserAlbumVideoViews1(144); www.Stop(); idlist.Add(www.ElapsedMilliseconds); PageIndex++; } //www.Restart(); //www.Start(); //SpecialView sv2 = GetUserAlbumsViews(); //www.Stop(); //long ttt2 = www.ElapsedMilliseconds; }
public SpecialDetailView GetUserAlbumVideoViews1(int albumId) { var sdv = new SpecialDetailView() { SpecialVideoList = new List <SpecialVideoView>(), Title = "", VideoCount = 0, PageCount = 0 }; var userSpecial = this._userSpecialRepository.GetEntity(ConditionEqualId(albumId)); var vidoes = (from ussl in this._userSpecialSonRepository.GetEntityList(CondtionEqualSpecialId(userSpecial.Id)) .OrderByDescending(o => o.CreateTime) join video in this._videoRepository.GetEntityList(CondtionEqualState()).Where(p => p.VideoState == 3) on (long) ussl.VideoId equals video.Id select new SpecialVideoView { Id = video.Id, CommentCount = video.CommentCount, SmallPicturePath = video.SmallPicturePath, Title = video.Title, PlayCount = video.PlayCount, About = video.About, //CreateTime = video.CreateTime.ToString("yyyy-MM-dd" ) }); sdv.VideoCount = vidoes.Count(); sdv.PageCount = GetPageCountToDataCount(sdv.VideoCount); sdv.CommentCount = vidoes.Sum(o => o.CommentCount); sdv.PlayCount = vidoes.Sum(o => o.PlayCount); sdv.Title = userSpecial.Title; sdv.Remark = userSpecial.Remark; sdv.CreateTime = userSpecial.CreateTime.ToString("yyyy-MM-dd HH:mm"); sdv.SpecialVideoList = vidoes.Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList(); return(sdv); }
/// <summary> /// 获取用户创建的专辑,过滤已添加到空间专辑 /// </summary> /// <param name="userId"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="escapeStatestate"></param> /// <returns></returns> public SpecialView GetUserAlbumsViews(int userId, int pageIndex, int pageSize) { var sv = new SpecialView() { SpecialVideoList = new List <SpecialDetailView>(), SpecialCount = 0 }; var userSpecial = (from urc in _userSpecialRepository.GetEntityList(CondtionEqualCreateUserId(userId)) where !(from userroomchoose in this._userRoomChooseRepository.GetEntityList(CondtionEqualUserId(userId)) where userroomchoose.TypeId == 1 select new { userroomchoose.ModuleId }).Contains(new { ModuleId = urc.Id }) select urc ).AsQueryable(); List <UserSpecial> list = userSpecial.ToList <UserSpecial>(); List <SpecialDetailView> sdvList = new List <SpecialDetailView>(); SpecialDetailView sdv = null; List <SpecialVideoView> svvList = new List <SpecialVideoView>(); SpecialVideoView svv = null; List <Video> videoList = null; foreach (UserSpecial item in list) { sdv = new SpecialDetailView(); sdv.Id = item.Id; sdv.Title = item.Title; var vidoes = (from ussl in this._userSpecialSonRepository.GetEntityList(CondtionEqualSpecialId(item.Id)) join video in this._videoRepository.GetEntityList(CondtionEqualState()) on(long) ussl.VideoId equals video.Id where video.VideoState == 3 //TODO update 刘强2015-11-06 过滤审核状态 select video ).AsQueryable(); videoList = vidoes.ToList <Video>(); foreach (Video v in videoList) { svv = new SpecialVideoView(); svv.Id = v.Id; svv.SmallPicturePath = v.SmallPicturePath; svv.Title = v.Title; svv.PlayCount = v.PlayCount; svv.CommentCount = v.CommentCount; svv.TimeLength = ConvertUtil.ToInt(v.TimeLength, 0); svvList.Add(svv); } sdv.SpecialVideoList = svvList; sdvList.Add(sdv); } sv.SpecialVideoList = sdvList; if (list.Count <= 0) { return(sv); } sv.SpecialCount = list.Count; sv.PageCount = sv.SpecialCount % pageSize == 0 ? sv.SpecialCount / pageSize : sv.SpecialCount / pageSize + 1; sv.SpecialVideoList = sv.SpecialVideoList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); return(sv); }
/// <summary> /// 默认排序查询个人空间-专辑推荐视图 /// </summary> /// <param name="userId">用户id</param> /// <param name="dataNum">专辑数</param> /// <param name="videoNum">视频数</param> /// <returns></returns> public SpecialView GetUserRoomSpecialData(int userId, int dataNum, int videoNum = 0) { CheckIdNotNull(userId); SpecialView sv = new SpecialView(); var userSpecial = (from urc in GetUserRoomChooseList(userId) join special in this._userSpecialRepository.GetEntityList(CondtionEqualState()) on urc.ModuleId equals special.Id where urc.TypeId == 1 orderby urc.SortNum, urc.CreateTime select special ).AsQueryable().Take(dataNum); List <UserSpecial> list = userSpecial.ToList <UserSpecial>(); List <SpecialDetailView> sdvList = new List <SpecialDetailView>(); SpecialDetailView sdv = null; List <SpecialVideoView> svvList = null; SpecialVideoView svv = null; List <Video> videoList = null; foreach (UserSpecial item in list) { sdv = new SpecialDetailView(); sdv.Id = item.Id; sdv.Title = item.Title; var vidoes = (from ussl in GetUserSpecialSonList(item.Id) join video in this._videoRepository.GetEntityList(CondtionEqualState()).Where(p => p.VideoState == 3) on(long) ussl.VideoId equals video.Id select video ).OrderByDescending(p => p.UpdateTime ?? p.CreateTime).AsQueryable(); if (videoNum > 0) { vidoes = vidoes.Take(videoNum); } videoList = vidoes.ToList <Video>(); svvList = new List <SpecialVideoView>(); foreach (Video v in videoList) { svv = new SpecialVideoView(); svv.Id = v.Id; svv.SmallPicturePath = v.SmallPicturePath; svv.Title = v.Title; svv.PlayCount = v.PlayCount; svv.CommentCount = v.CommentCount; svv.TimeLength = ConvertUtil.ToInt(v.TimeLength); svvList.Add(svv); } sdv.SpecialVideoList = svvList; sdvList.Add(sdv); } sv.SpecialCount = list.Count; sv.SpecialVideoList = sdvList; return(sv); }
public SpecialView GetUserAlbumsViews() { int UserId = 42; int albumId = 144; var sv = new SpecialView() { SpecialVideoList = new List <SpecialDetailView>(), SpecialCount = 0 }; var userSpecial = (from urc in _userSpecialRepository.GetEntityList(CondtionEqualCreateUserId(UserId)) orderby urc.CreateTime descending select urc ).AsQueryable(); List <UserSpecial> list = userSpecial.ToList <UserSpecial>(); List <SpecialDetailView> sdvList = new List <SpecialDetailView>(); SpecialDetailView sdv = null; List <SpecialVideoView> svvList = null; SpecialVideoView svv = null; List <Video> videoList = null; string thumbnail = ""; foreach (UserSpecial item in list) { sdv = new SpecialDetailView(); sdv.Id = item.Id; sdv.Title = item.Title; sdv.CreateTime = item.CreateTime.ToString("yyyy-MM-dd HH:mm"); thumbnail = item.Image; var vidoes = (from ussl in this._userSpecialSonRepository.GetEntityList(CondtionEqualSpecialId(item.Id)) join video in this._videoRepository.GetEntityList(CondtionEqualState()) on(long) ussl.VideoId equals video.Id where video.VideoState == 3 //todo 刘强2015-11-06添加审核通过的过滤条件 orderby ussl.CreateTime select video ).AsQueryable(); videoList = vidoes.ToList <Video>(); sdv.VideoCount = videoList.Count;//专辑下视频总数 if (videoList != null && videoList.Count > 0 && string.IsNullOrEmpty(thumbnail)) { thumbnail = videoList[videoList.Count - 1].SmallPicturePath; } //如果专辑图片和视频都没有,则赋值默认图片 //if (string.IsNullOrEmpty(thumbnail)) //thumbnail = ServerHelper.RootPath + "/Content/images/per_acc_v02.png"; sdv.Thumbnail = thumbnail;//赋值专辑缩略图 svvList = new List <SpecialVideoView>(); int playCount = 0;//获取专辑下视频播放总数 foreach (Video v in videoList) { svv = new SpecialVideoView(); svv.Id = v.Id; svv.SmallPicturePath = v.SmallPicturePath; svv.Title = v.Title; svv.PlayCount = v.PlayCount; svv.CommentCount += v.CommentCount; svv.TimeLength = ConvertUtil.ToInt(v.TimeLength, 0); svvList.Add(svv); playCount += v.PlayCount; } sdv.PlayCount = playCount; //获取专辑下视频播放总数 sdv.SpecialVideoList = svvList; //专辑下视频集合 sdvList.Add(sdv); } sv.SpecialVideoList = sdvList; if (list.Count <= 0) { return(sv); } sv.SpecialCount = list.Count; sv.PageCount = GetPageCountToDataCount(sv.SpecialCount); sv.SpecialVideoList = sv.SpecialVideoList.Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList(); return(sv); }
public SpecialDetailView GetUserAlbumVideoViews(int albumId) { User user; UserSpecial us; CheckAlbumId(albumId); //CheckUserId(UserId, out user); CheckAlbumId(albumId, out us); var sdv = new SpecialDetailView() { SpecialVideoList = new List <SpecialVideoView>(), Title = "", VideoCount = 0, PageCount = 0 }; var userSpecial = (from usr in this._userSpecialRepository.GetEntityList(ConditionEqualId(us.Id)) select usr ).AsQueryable().FirstOrDefault(); string thumbnail = ""; if (userSpecial != null) { sdv.Id = userSpecial.Id; sdv.Title = userSpecial.Title; sdv.Thumbnail = userSpecial.Image; sdv.CreateTime = userSpecial.CreateTime.ToString("yyyy-MM-dd HH:mm"); sdv.Remark = userSpecial.Remark; } List <SpecialVideoView> svvList = null; SpecialVideoView svv = null; List <Video> videoList = null; var vidoes = (from ussl in this._userSpecialSonRepository.GetEntityList(CondtionEqualSpecialId(sdv.Id)) join video in this._videoRepository.GetEntityList(CondtionEqualState()).Where(p => p.VideoState == 3) on(long) ussl.VideoId equals video.Id orderby ussl.CreateTime select video ).AsQueryable(); videoList = vidoes.ToList <Video>(); if (videoList.Count <= 0) { return(sdv); } sdv.VideoCount = videoList.Count;//专辑下视频总数 if (videoList != null && videoList.Count > 0 && string.IsNullOrEmpty(thumbnail)) { thumbnail = videoList[videoList.Count - 1].SmallPicturePath; } //如果专辑图片和视频都没有,则赋值默认图片 //if (string.IsNullOrEmpty(thumbnail)) //thumbnail = ServerHelper.RootPath + "/Content/images/per_acc_v02.png"; sdv.Thumbnail = thumbnail;//赋值专辑缩略图 svvList = new List <SpecialVideoView>(); int playCount = 0;//获取专辑下视频播放总数 int commentCount = 0; int order = 1; foreach (Video v in videoList) { svv = new SpecialVideoView(); svv.orderId = order; svv.Id = v.Id; svv.SmallPicturePath = v.SmallPicturePath; svv.Title = v.Title; svv.PlayCount = v.PlayCount; svv.CommentCount = v.CommentCount; commentCount += v.CommentCount; svv.TimeLength = ConvertUtil.ToInt(v.TimeLength, 0); svv.CreateTime = v.CreateTime.ToString("yyyy-MM-dd"); svv.UpdateTime = ((DateTime)v.UpdateTime).ToString("yyyy-MM-dd"); svvList.Add(svv); playCount += v.PlayCount; order++; } sdv.CommentCount = commentCount; //评论总数 sdv.PlayCount = playCount; //获取专辑下视频播放总数 sdv.SpecialVideoList = svvList; //专辑下视频集合 sdv.VideoCount = videoList.Count; sdv.PageCount = GetPageCountToDataCount(sdv.VideoCount); sdv.SpecialVideoList = sdv.SpecialVideoList.Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList(); return(sdv); }