public bool GetFollowed(string followeeOpenId, string followerOpenId)
        {
            var  dao        = new FollowDao(ConfigurationManager.AppSettings["mysqlConnStr"]);
            bool isFollowed = dao.GetFollowed(followeeOpenId, followerOpenId);

            return(isFollowed);
        }
        public ResponseEntity <string> Follow(Follow follow)
        {
            ResponseEntity <string> response = new ResponseEntity <string>();

            var  dao     = new FollowDao(ConfigurationManager.AppSettings["mysqlConnStr"]);
            bool success = dao.Add(follow);

            if (success)
            {
                response = new ResponseEntity <string>(true, "关注成功", "关注成功");
            }
            else
            {
                response = new ResponseEntity <string>(true, "关注失败", "关注失败");
            }
            return(response);
        }
        public AllFollows GetAllFollows(int pageIndex, int pageSize, string followerName)
        {
            AllFollows result = new AllFollows();

            var    followDao = new FollowDao(ConfigurationManager.AppSettings["mysqlConnStr"]);
            string filter    = string.Empty;

            if (!string.IsNullOrEmpty(followerName))
            {
                filter = $" and u2.nickName like '%{followerName}%' ";
            }
            var allFollows = followDao.GetFollows(pageIndex, pageSize, filter);
            var count      = followDao.GetFollowsCount(filter);

            result.follows = allFollows;
            result.count   = count;

            return(result);
        }
        public void FollowByPost(string postId, string followerId)
        {
            var graphicMessageDao = new GraphicMessageDao(ConfigurationManager.AppSettings["mysqlConnStr"]);
            var graphicMsg        = graphicMessageDao.GetById(postId);

            if (graphicMsg != null && !string.IsNullOrEmpty(graphicMsg.openId))
            {
                var followDao = new FollowDao(ConfigurationManager.AppSettings["mysqlConnStr"]);

                bool isFollowed = followDao.GetFollowed(graphicMsg.openId, followerId);

                if (!isFollowed)
                {
                    followDao.Add(new dataentity.Model.Follow()
                    {
                        followee = graphicMsg.openId, follower = followerId
                    });
                }
            }
        }
Ejemplo n.º 5
0
        public List <ClubItem> GetClubList(string openId, int count = 10, int endId = int.MaxValue, string filter = "")
        {
            List <ClubItem> results = new List <ClubItem>();

            var dao = new GraphicMessageDao(ConfigurationManager.AppSettings["mysqlConnStr"]);

            string nameFilter = "";

            if (!string.IsNullOrEmpty(filter))
            {
                nameFilter = $" and name like '%{filter}%' ";
            }

            var messages = dao.GetListExt(filter: $" and isTop=0 {nameFilter} ", count: count, endId: endId);

            if (messages.Count < count) //如果取出的数量不够,就从头再取,补足不够的数量
            {
                //简单起见,每次到头部的时候,就把置顶文章给带上
                var topMsgs = dao.GetTopExt(nameFilter);

                var compensateMsgs = dao.GetListExt(filter: $" and isTop=0 {nameFilter} ", count: count - messages.Count, endId: int.MaxValue);

                messages.AddRange(topMsgs);
                messages.AddRange(compensateMsgs);
            }

            if (messages != null)
            {
                messages.ForEach(msg =>
                {
                    List <string> pics = new List <string>();
                    if (!string.IsNullOrEmpty(msg.pic01))
                    {
                        pics.Add(msg.pic01);
                    }
                    if (!string.IsNullOrEmpty(msg.pic02))
                    {
                        pics.Add(msg.pic02);
                    }
                    if (!string.IsNullOrEmpty(msg.pic03))
                    {
                        pics.Add(msg.pic03);
                    }
                    if (!string.IsNullOrEmpty(msg.pic04))
                    {
                        pics.Add(msg.pic04);
                    }
                    if (!string.IsNullOrEmpty(msg.pic05))
                    {
                        pics.Add(msg.pic05);
                    }
                    if (!string.IsNullOrEmpty(msg.pic06))
                    {
                        pics.Add(msg.pic06);
                    }

                    List <string> audioes = new List <string>();
                    if (!string.IsNullOrEmpty(msg.audio01))
                    {
                        audioes.Add(msg.audio01);
                    }
                    if (!string.IsNullOrEmpty(msg.audio02))
                    {
                        audioes.Add(msg.audio02);
                    }
                    if (!string.IsNullOrEmpty(msg.audio03))
                    {
                        audioes.Add(msg.audio03);
                    }

                    results.Add(new ClubItem()
                    {
                        postId        = msg.id,
                        openId        = msg.openId,
                        author        = msg.author,
                        wechatUrl     = msg.wechatUrl,
                        authorHeadPic = msg.authorHeadPic,
                        name          = msg.name,
                        poster        = !string.IsNullOrEmpty(msg.poster)? msg.poster : msg.pic01,
                        pics          = pics,
                        audioes       = audioes,
                        itemType      = ClubItemType.Graphic,
                        text          = msg.text,
                        likeCount     = msg.likeCount,
                        commentCount  = msg.commentCount,
                        createdAt     = msg.createdAt
                    });
                });
            }

            //SQL里面已经有order by g.id desc,所以这里不用排序了
            //results = results.OrderByDescending(r => r.createdAt).ToList();


            int id = 0;

            results.ForEach(r => { r.id = ++id; });

            //如果传入了Follower的openId
            if (!string.IsNullOrEmpty(openId))
            {
                results.ForEach(r => {
                    var dao2        = new FollowDao(ConfigurationManager.AppSettings["mysqlConnStr"]);
                    bool isFollowed = dao2.GetFollowed(r.openId, openId);

                    r.followed = isFollowed;
                });
            }

            return(results);
        }
Ejemplo n.º 6
0
        public UserProfile GetUser(string openId)
        {
            var dao         = new UserDao(ConfigurationManager.AppSettings["mysqlConnStr"]);
            var user        = dao.GetUser(openId);
            var userProfile = JsonConvert.DeserializeObject <UserProfile>(JsonConvert.SerializeObject(user));

            userProfile.certs = new List <DoctorCert>();
            if (!string.IsNullOrEmpty(userProfile.certificate) || !string.IsNullOrEmpty(userProfile.certText))
            {
                userProfile.certs.Add(new DoctorCert()
                {
                    cert = userProfile.certificate, text = userProfile.certText
                });
            }

            if (!string.IsNullOrEmpty(userProfile.certificate1) || !string.IsNullOrEmpty(userProfile.cert1Text))
            {
                userProfile.certs.Add(new DoctorCert()
                {
                    cert = userProfile.certificate1, text = userProfile.cert1Text
                });
            }

            if (!string.IsNullOrEmpty(userProfile.certificate2) || !string.IsNullOrEmpty(userProfile.cert2Text))
            {
                userProfile.certs.Add(new DoctorCert()
                {
                    cert = userProfile.certificate2, text = userProfile.cert2Text
                });
            }

            if (!string.IsNullOrEmpty(userProfile.certificate3) || !string.IsNullOrEmpty(userProfile.cert3Text))
            {
                userProfile.certs.Add(new DoctorCert()
                {
                    cert = userProfile.certificate3, text = userProfile.cert3Text
                });
            }

            if (!string.IsNullOrEmpty(userProfile.certificate4) || !string.IsNullOrEmpty(userProfile.cert4Text))
            {
                userProfile.certs.Add(new DoctorCert()
                {
                    cert = userProfile.certificate4, text = userProfile.cert4Text
                });
            }

            if (!string.IsNullOrEmpty(userProfile.certificate5) || !string.IsNullOrEmpty(userProfile.cert5Text))
            {
                userProfile.certs.Add(new DoctorCert()
                {
                    cert = userProfile.certificate5, text = userProfile.cert5Text
                });
            }

            if (!string.IsNullOrEmpty(userProfile.certificate6) || !string.IsNullOrEmpty(userProfile.cert6Text))
            {
                userProfile.certs.Add(new DoctorCert()
                {
                    cert = userProfile.certificate6, text = userProfile.cert6Text
                });
            }

            if (!string.IsNullOrEmpty(userProfile.certificate7) || !string.IsNullOrEmpty(userProfile.cert7Text))
            {
                userProfile.certs.Add(new DoctorCert()
                {
                    cert = userProfile.certificate7, text = userProfile.cert7Text
                });
            }


            var likeDao   = new LikeDao(ConfigurationManager.AppSettings["mysqlConnStr"]);
            var followDao = new FollowDao(ConfigurationManager.AppSettings["mysqlConnStr"]);

            userProfile.likeCount     = likeDao.GetLikeCount(openId);
            userProfile.fansCount     = followDao.GetFollowerCount(openId);
            userProfile.followeeCount = followDao.GetFolloweeCount(openId);

            return(userProfile);
        }
        public List <ClubItem> GetFolloweePost(string followerOpenId)
        {
            logger.Info($"GetFolloweePost -> followerOpenId:{followerOpenId}");
            List <ClubItem> results = new List <ClubItem>();

            var followDao = new FollowDao(ConfigurationManager.AppSettings["mysqlConnStr"]);
            var followees = followDao.GetFolloweesList(followerOpenId);

            var           dao = new GraphicMessageDao(ConfigurationManager.AppSettings["mysqlConnStr"]);
            StringBuilder sb  = new StringBuilder();

            sb.Append(" and g.openid in (''");
            followees.ForEach(followeeOpenId =>
            {
                sb.Append($",'{followeeOpenId}'");
            });
            sb.Append(")");
            var messages = dao.GetListExt(sb.ToString(), count: int.MaxValue, endId: int.MaxValue);

            if (messages != null)
            {
                messages.ForEach(msg =>
                {
                    List <string> pics = new List <string>();
                    if (!string.IsNullOrEmpty(msg.pic01))
                    {
                        pics.Add(msg.pic01);
                    }
                    if (!string.IsNullOrEmpty(msg.pic02))
                    {
                        pics.Add(msg.pic02);
                    }
                    if (!string.IsNullOrEmpty(msg.pic03))
                    {
                        pics.Add(msg.pic03);
                    }
                    if (!string.IsNullOrEmpty(msg.pic04))
                    {
                        pics.Add(msg.pic04);
                    }
                    if (!string.IsNullOrEmpty(msg.pic05))
                    {
                        pics.Add(msg.pic05);
                    }
                    if (!string.IsNullOrEmpty(msg.pic06))
                    {
                        pics.Add(msg.pic06);
                    }

                    List <string> audioes = new List <string>();
                    if (!string.IsNullOrEmpty(msg.audio01))
                    {
                        audioes.Add(msg.audio01);
                    }
                    if (!string.IsNullOrEmpty(msg.audio02))
                    {
                        audioes.Add(msg.audio02);
                    }
                    if (!string.IsNullOrEmpty(msg.audio03))
                    {
                        audioes.Add(msg.audio03);
                    }

                    results.Add(new ClubItem()
                    {
                        postId        = msg.id,
                        openId        = msg.openId,
                        author        = msg.author,
                        authorHeadPic = msg.authorHeadPic,
                        name          = msg.name,
                        poster        = msg.poster,
                        pics          = pics,
                        audioes       = audioes,
                        itemType      = ClubItemType.Graphic,
                        text          = msg.text,
                        likeCount     = msg.likeCount,
                        commentCount  = msg.commentCount,
                        createdAt     = msg.createdAt
                    });
                });
            }

            results = results.OrderByDescending(r => r.createdAt).ToList();

            logger.Info($"GetFolloweePost -> return:{results.Count} items");
            return(results);
        }
        public void Unfollow(int followId)
        {
            var followDao = new FollowDao(ConfigurationManager.AppSettings["mysqlConnStr"]);

            followDao.UnFollow(followId);
        }
        public List <PostsByDoctor> GetFolloweePostV2(string followerOpenId)
        {
            List <PostsByDoctor> result = new List <PostsByDoctor>();

            var followDao = new FollowDao(ConfigurationManager.AppSettings["mysqlConnStr"]);
            var userDao   = new UserDao(ConfigurationManager.AppSettings["mysqlConnStr"]);
            var dao       = new GraphicMessageDao(ConfigurationManager.AppSettings["mysqlConnStr"]);

            var followees = followDao.GetFolloweesList(followerOpenId);

            followees.ForEach(followeeOpenId =>
            {
                PostsByDoctor post = new PostsByDoctor();
                var author         = userDao.GetUser(followeeOpenId);
                post.author        = author;

                StringBuilder sb = new StringBuilder();
                sb.Append($" and g.openid='{followeeOpenId}' ");
                var messages = dao.GetListExt(sb.ToString(), count: 2, endId: int.MaxValue); //每个作者只取前两个作品

                var clubItems = new List <ClubItem>();
                if (messages != null)
                {
                    messages.ForEach(msg =>
                    {
                        List <string> pics = new List <string>();
                        if (!string.IsNullOrEmpty(msg.pic01))
                        {
                            pics.Add(msg.pic01);
                        }
                        if (!string.IsNullOrEmpty(msg.pic02))
                        {
                            pics.Add(msg.pic02);
                        }
                        if (!string.IsNullOrEmpty(msg.pic03))
                        {
                            pics.Add(msg.pic03);
                        }
                        if (!string.IsNullOrEmpty(msg.pic04))
                        {
                            pics.Add(msg.pic04);
                        }
                        if (!string.IsNullOrEmpty(msg.pic05))
                        {
                            pics.Add(msg.pic05);
                        }
                        if (!string.IsNullOrEmpty(msg.pic06))
                        {
                            pics.Add(msg.pic06);
                        }

                        List <string> audioes = new List <string>();
                        if (!string.IsNullOrEmpty(msg.audio01))
                        {
                            audioes.Add(msg.audio01);
                        }
                        if (!string.IsNullOrEmpty(msg.audio02))
                        {
                            audioes.Add(msg.audio02);
                        }
                        if (!string.IsNullOrEmpty(msg.audio03))
                        {
                            audioes.Add(msg.audio03);
                        }

                        clubItems.Add(new ClubItem()
                        {
                            postId        = msg.id,
                            openId        = msg.openId,
                            author        = msg.author,
                            authorHeadPic = msg.authorHeadPic,
                            name          = msg.name,
                            poster        = msg.poster,
                            pics          = pics,
                            audioes       = audioes,
                            itemType      = ClubItemType.Graphic,
                            text          = msg.text,
                            likeCount     = msg.likeCount,
                            commentCount  = msg.commentCount,
                            createdAt     = msg.createdAt
                        });
                    });
                }

                post.posts = clubItems;

                result.Add(post);
            });

            return(result);
        }