Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            articleId = Request["articleId"];
            if (articleId == null)
            {
                Response.End();
            }
            int articleIdint;

            if (!int.TryParse(articleId, out articleIdint))
            {
                Response.End();
            }
            currentUserInfo     = DataLoadTool.GetCurrUserModel();
            currWebSiteUserInfo = bll.Get <UserInfo>(string.Format("UserID='{0}'", DataLoadTool.GetWebsiteInfoModel().WebsiteOwner));//
            JuActivityInfo articleInfo = bll.Get <JuActivityInfo>(string.Format("JuActivityID={0}", articleIdint));

            if (articleInfo == null)
            {
                Response.End();
            }
            if (!currentUserInfo.UserType.Equals(1))
            {
                if (!articleInfo.WebsiteOwner.Equals(currentUserInfo.WebsiteOwner))
                {
                    Response.End();
                }
            }

            var    articleIdHex = Convert.ToString(articleIdint, 16);                                                                                                                                                                                                                                                                                                                       //文章活动ID十六进制
            string pageUrl      = string.Format("http://{0}/{1}/details.chtml", Request.Url.Host, articleIdHex);
            var    rootList     = bll.GetList <WebAccessLogsInfo>(string.Format("(Ex_PreSpreadUserID is null or Ex_PreSpreadUserID='') And (Ex_PreShareTimestamp is null or Ex_PreShareTimestamp='') And Ex_SpreadUserID !='' And Ex_SpreadUserID is not null  And Ex_ShareTimestamp !=''  And Ex_ShareTimestamp is not null  And PageUrl like '{0}%'  Order by AccessDate ASC", pageUrl)); //根节点


            if (rootList.Count > 0)
            {
                rootList = rootList.DistinctBy(p => p.Ex_ShareTimestamp).ToList();
                System.Text.StringBuilder sbRoot = new System.Text.StringBuilder();
                for (int i = 0; i < rootList.Count; i++)
                {
                    var item = rootList[i];

                    //int count = bll.GetCount<WebAccessLogsInfo>(string.Format("Ex_PreSpreadUserID='{0}' And Ex_PreShareTimestamp='{1}' Order by AccessDate ASC", item.Ex_SpreadUserID, item.Ex_ShareTimestamp));
                    var subList = bll.GetList <WebAccessLogsInfo>(string.Format("Ex_PreSpreadUserID='{0}' And Ex_PreShareTimestamp='{1}' Order by AccessDate ASC ", item.Ex_SpreadUserID, item.Ex_ShareTimestamp));
                    subList = subList.DistinctBy(p => p.Ex_ShareTimestamp).ToList();
                    int count    = subList.Count;
                    var isParent = false;
                    if (count > 0)
                    {
                        isParent = true;
                    }
                    string wxNickName = "无昵称";
                    string wxHeadImg  = "/zTree/css/zTreeStyle/img/diy/user.png";
                    string icon       = "/zTree/css/zTreeStyle/img/diy/user.png";
                    var    userInfo   = bll.Get <UserInfo>(string.Format("UserID='{0}'", item.Ex_SpreadUserID));
                    if (userInfo != null)
                    {
                        if (!string.IsNullOrEmpty(userInfo.WXNickname))
                        {
                            wxNickName = userInfo.WXNickname;
                        }
                        if (!string.IsNullOrEmpty(userInfo.WXHeadimgurlLocal))
                        {
                            wxHeadImg = userInfo.WXHeadimgurlLocal;
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(userInfo.WXOpenId))
                            {
                                //拉取用户信息并更新数据库

                                ZentCloud.BLLJIMP.Model.Weixin.WeixinUserInfo weixinInfo = bllWeixin.GetWeixinUserInfo(currWebSiteUserInfo.UserID, currWebSiteUserInfo.WeixinAppId, currWebSiteUserInfo.WeixinAppSecret, userInfo.WXOpenId);
                                if (weixinInfo != null)
                                {
                                    if (!string.IsNullOrEmpty(weixinInfo.NickName))
                                    {
                                        userInfo.WXNickname = weixinInfo.NickName;
                                    }
                                    if (!string.IsNullOrEmpty(weixinInfo.HeadImgUrl))
                                    {
                                        userInfo.WXHeadimgurl = weixinInfo.HeadImgUrl;
                                    }
                                    //bll.Update(userInfo);
                                }
                            }
                        }
                    }
                    string tip   = string.Format("<img src='{0}' align='absmiddle' width='100px' height='100px'/><br/>{1}<br/>被<span style='color:red;'>{2}</span>次转发", wxHeadImg, wxNickName, count);
                    var    title = string.Format("<span style='color:blue;'>{0}</span>  <span style='color:red;'>{1}</span>转发 [{2}]", wxNickName, count, string.Format("{0:f}", item.AccessDate));
                    sbRoot.Append("{");
                    sbRoot.AppendFormat("name: \"{0}\", id: \"{1}\", count:{2}, times: 1, isParent:\"{3}\",Ex_SpreadUserID:\"{4}\",Ex_ShareTimestamp:\"{5}\",icon:\"{6}\",tip:\"{7}\"", title, item.AutoID, "1", isParent.ToString().ToLower(), item.Ex_SpreadUserID, item.Ex_ShareTimestamp, icon, tip);
                    sbRoot.Append("}");

                    if (i < rootList.Count - 1)//追加分隔符
                    {
                        sbRoot.Append(",");
                    }
                }
                RootNodes = sbRoot.ToString();
            }
            else
            {
                RootNodes = "{ name: \"暂时没有转发记录\", id: \"0\", count: 0, times: 1, isParent: false }";
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 分享统计
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string GetShareCountStatistics(HttpContext context)
        {
            string preId = context.Request["preId"], //shareId,每次查询是取出传入shareId的子集
                   mid   = context.Request["mid"];

            bool          isRoot       = false;
            StringBuilder strShareInfo = new StringBuilder(" 1=1 ");

            if (string.IsNullOrWhiteSpace(preId))
            {
                //一级目录,返回一级分享和当前检测实体信息, 分享总数  阅读总数  成果总数
                strShareInfo.Append(" AND ( PreId = '' OR PreId IS NULL)");
                isRoot = true;
            }
            else
            {
                if (preId.IndexOf(',') > 0)
                {
                    var tmpList = preId.Split(',').ToList();
                    strShareInfo.AppendFormat(" AND PreId in ({0}) ", Common.StringHelper.ListToStr <string>(tmpList, "'", ","));
                }
                else
                {
                    strShareInfo.AppendFormat(" AND PreId = '{0}' ", preId);
                }
            }

            strShareInfo.AppendFormat(" AND MonitorId = {0} ", mid);

            var shareList = this.bll.GetList <ShareInfo>(strShareInfo.ToString());

            //share信息处理,按个人分享数归类到一块
            List <object> shareResultList = new List <object>();

            #region share信息处理

            if (shareList != null && shareList.Count > 0)
            {
                //取出分享人列表
                var               sharerList = shareList.GroupBy(p => p.UserId).ToList();
                BLLJIMP.BLLUser   userBll    = new BLLJIMP.BLLUser();
                BLLJIMP.BLLWeixin wxBll      = new BLLJIMP.BLLWeixin();

                foreach (var item in sharerList)
                {
                    //获取user信息
                    var userInfo = userBll.GetUserInfo(item.Key);

                    if (userInfo == null)
                    {
                        continue;
                    }

                    //TODO:如果没有头像和姓名  需要去接口取相关头像和姓名 并保存到数据库
                    try
                    {
                        if (string.IsNullOrWhiteSpace(userInfo.WXHeadimgurl))
                        {
                            string accesstoken   = wxBll.GetAccessToken(userInfo.WebsiteOwner);
                            var    newflowerInfo = wxBll.GetWeixinUserInfo(accesstoken, userInfo.WXOpenId);

                            userInfo.WXHeadimgurl = newflowerInfo.headimgurl;
                            userInfo.WXNickname   = newflowerInfo.nickname;

                            this.bll.Update(
                                new UserInfo(),
                                string.Format(" WXHeadimgurl='{0}',WXNickname='{1}' ", userInfo.WXHeadimgurl, userInfo.WXNickname),
                                string.Format(" UserID='{0}' ", userInfo.UserID)
                                );
                        }
                    }
                    catch { }//TODO:临时方案取用户信息,如果出现异常暂时不处理

                    //获取ShareIds
                    var userShareList = shareList.Where(p => (p.UserId != null && p.UserId.ToLower() == userInfo.UserID.ToLower())).Select(p => p.ShareId).ToList();

                    //获取子分享数(所有shareIds的子分享数)
                    var childShareCount = this.bll.GetCount <ShareInfo>(string.Format(" PreId in ({0}) ", Common.StringHelper.ListToStr <string>(userShareList, "'", ",")));

                    //获取阅读数(所有shareIds的阅读总数)
                    var readCount = this.bll.GetCount <ShareReaderInfo>(string.Format(" ShareId in ({0}) ", Common.StringHelper.ListToStr <string>(userShareList, "'", ",")));

                    //获取分享数(等于shareIds总数)
                    var shareCount = userShareList.Count;

                    //获取成果数(所有shareIds带来的报名数,目前统计的是校服对应的那个报名表来统计)
                    //var achievement = this.bll.GetCount<VoteObjectInfo>(string.Format(" ComeonShareId in ({0}) ", Common.StringHelper.ListToStr<string>(userShareList, "'", ",")));

                    //成果数改成活动报名数,取出分享的活动id,查询活动报名是来自哪个用户或者哪个分享id

                    //var achievement =
                    //    this.bll.GetCount<VoteObjectInfo>(string.Format(" ComeonShareId in ({0}) ", Common.StringHelper.ListToStr<string>(userShareList, "'", ",")));

                    var achievement =
                        this.bll.GetCount <ActivityDataInfo>(string.Format(" ShareID in ({0}) ", Common.StringHelper.ListToStr <string>(userShareList, "'", ",")));

                    shareResultList.Add(new
                    {
                        tmpDataKey = Guid.NewGuid().ToString(),
                        userInfo   = new
                        {
                            avatar   = userInfo.WXHeadimgurl,
                            userName = string.IsNullOrWhiteSpace(userInfo.WXNickname) ? "" : userInfo.WXNickname,
                            userId   = userInfo.UserID,
                            wxOpenId = userInfo.WXOpenId
                        },
                        shareIds        = userShareList,
                        preId           = preId,
                        childShareCount = childShareCount,
                        readCount       = readCount,
                        shareCount      = shareCount,
                        achievement     = achievement//成果
                    });
                }
            }
            #endregion

            object rootInfo = new object();

            #region rootInfo处理
            if (isRoot)
            {
                //当前检测实体信息, 分享总数  阅读总数  成果总数
                var monitor         = this.bll.Get <ShareMonitorInfo>(string.Format(" MonitorId = {0} ", mid));
                var shareTotalCount = this.bll.GetCount <ShareInfo>(string.Format(" MonitorId = {0} ", mid));

                //阅读总数= 分享的阅读总数 + 直接阅读总数(未分享)
                var readTotalCount = this.bll.GetCount <ShareReaderInfo>(string.Format(" MonitorId = {0} ", mid));

                //成果总数= 分享的成功总数
                var achievementTotalCount = 0;

                //取出所有分享id
                var allShareList = this.bll.GetList <ShareInfo>(string.Format(" MonitorId = {0} ", mid));
                if (allShareList != null && allShareList.Count > 0)
                {
                    var allShareIds = allShareList.Select(p => p.ShareId).ToList();
                    readTotalCount += this.bll.GetCount <ShareReaderInfo>(string.Format(" ShareId IN ({0}) ", Common.StringHelper.ListToStr <string>(allShareIds, "'", ",")));

                    achievementTotalCount = this.bll.GetCount <VoteObjectInfo>(string.Format(" ComeonShareId IN ({0}) ", Common.StringHelper.ListToStr <string>(allShareIds, "'", ",")));
                }
                rootInfo = new
                {
                    title                 = monitor.MonitorName,
                    shareTotalCount       = shareTotalCount,
                    readTotalCount        = readTotalCount,
                    achievementTotalCount = achievementTotalCount
                };
            }
            #endregion

            return(Common.JSONHelper.ObjectToJson(new
            {
                rootInfo = isRoot ? rootInfo : null,
                shareResultList = shareResultList
            }));
        }