public GraphicMessage GetGraphicById(int id) { var dao = new GraphicMessageDao(ConfigurationManager.AppSettings["mysqlConnStr"]); var msg = dao.GetById(id.ToString()); return(msg); }
public ResponseEntity <long> AddGraphicMessage(GraphicMessage msg) { //msg.pic01 = string.IsNullOrEmpty(msg.pic01) ? string.Empty : ConfigurationManager.AppSettings["UploadUrl"] + msg.pic01; //msg.pic02 = string.IsNullOrEmpty(msg.pic02) ? string.Empty : ConfigurationManager.AppSettings["UploadUrl"] + msg.pic02; //msg.pic03 = string.IsNullOrEmpty(msg.pic03) ? string.Empty : ConfigurationManager.AppSettings["UploadUrl"] + msg.pic03; //msg.pic04 = string.IsNullOrEmpty(msg.pic04) ? string.Empty : ConfigurationManager.AppSettings["UploadUrl"] + msg.pic04; //msg.pic05 = string.IsNullOrEmpty(msg.pic05) ? string.Empty : ConfigurationManager.AppSettings["UploadUrl"] + msg.pic05; //msg.pic06 = string.IsNullOrEmpty(msg.pic06) ? string.Empty : ConfigurationManager.AppSettings["UploadUrl"] + msg.pic06; if (!string.IsNullOrEmpty(msg.poster) && msg.poster.IndexOf("base64,") > -1) { try { var img = Utils.GetImageFromBase64(msg.poster.Substring(msg.poster.IndexOf("base64,") + 7)); string fileName = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".jpg"; string fullPath = ConfigurationManager.AppSettings["UploadFolderPath"] + fileName; img.Save(fullPath); msg.poster = fileName; } catch (Exception ex) { logger.Error(ex.Message); } } ResponseEntity <long> response = new ResponseEntity <long>(); var dao = new GraphicMessageDao(ConfigurationManager.AppSettings["mysqlConnStr"]); bool success = true; long id = 0; if (msg.id > 0) { dao.UpdateGraphicMessage(msg); id = msg.id; } else { id = (long)dao.AddGraphicMessage(msg); } if (success) { response = new ResponseEntity <long>(true, "添加图文成功", id); } else { response = new ResponseEntity <long>(true, "添加图文失败", id); } return(response); }
public ResponseEntity <bool> UnsetTop(int id) { ResponseEntity <bool> response = new ResponseEntity <bool>(); try { var dao = new GraphicMessageDao(ConfigurationManager.AppSettings["mysqlConnStr"]); dao.UnsetTop(id); } catch (Exception ex) { logger.Error(ex.Message); } return(response); }
public List <GraphicMessage> GetMessageList() { var dao = new GraphicMessageDao(ConfigurationManager.AppSettings["mysqlConnStr"]); var messages = dao.GetList(" order by isTop desc, id desc "); //messages.ForEach(msg => //{ // if (!string.IsNullOrEmpty(msg.poster)) // { // Bitmap bitmap = new Bitmap(ConfigurationManager.AppSettings["UploadFolderPath"] + msg.poster); // msg.poster = Utils.ConvertBitmap2Base64(bitmap); // } //}); return(messages); }
public ResponseEntity <string> DeleteGraphicMessage(int id) { ResponseEntity <string> response = new ResponseEntity <string>(); var dao = new GraphicMessageDao(ConfigurationManager.AppSettings["mysqlConnStr"]); bool success = dao.DeleteById(id); if (success) { response = new ResponseEntity <string>(true, "删除图文成功", "删除图文成功"); } else { response = new ResponseEntity <string>(true, "删除图文失败", "删除图文失败"); } return(response); }
public List <GraphicMessageExt> GetMyMessageList(string openId) { var dao = new GraphicMessageDao(ConfigurationManager.AppSettings["mysqlConnStr"]); var messages = dao.GetListExt(filter: $" and g.openid='{openId}'", count: int.MaxValue, endId: int.MaxValue); messages.ForEach(msg => { msg.itemType = "graphic"; }); //messages.ForEach(msg => //{ // if (!string.IsNullOrEmpty(msg.poster)) // { // Bitmap bitmap = new Bitmap(ConfigurationManager.AppSettings["UploadFolderPath"] + msg.poster); // msg.poster = Utils.ConvertBitmap2Base64(bitmap); // } //}); return(messages); }
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 }); } } }
public ResponseEntity <long> AddWeChatNews(GraphicMessage msg) { msg.isTop = false; if (!string.IsNullOrEmpty(msg.poster) && msg.poster.IndexOf("base64,") > -1) { try { var img = Utils.GetImageFromBase64(msg.poster.Substring(msg.poster.IndexOf("base64,") + 7)); string fileName = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".jpg"; string fullPath = ConfigurationManager.AppSettings["UploadFolderPath"] + fileName; img.Save(fullPath); msg.poster = fileName; } catch (Exception ex) { logger.Error(ex.Message); } } ResponseEntity <long> response = new ResponseEntity <long>(); var dao = new GraphicMessageDao(ConfigurationManager.AppSettings["mysqlConnStr"]); bool isExists = dao.MediaIdExist(msg.wechatMediaId); if (isExists) { response = new ResponseEntity <long>(true, "图文已存在", 0); } else { response = new ResponseEntity <long>(true, "图文导入成功", 0); dao.AddGraphicMessage(msg); } return(response); }
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); }
public ClubItem GetPostById(string postId) { ClubItem result = new ClubItem(); var dao = new GraphicMessageDao(ConfigurationManager.AppSettings["mysqlConnStr"]); var msg = dao.GetById(postId); 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); } result = new ClubItem() { postId = msg.id, openId = msg.openId, author = msg.author, 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 }; return(result); }
public List <ClubItem> GetClubList() { List <ClubItem> results = new List <ClubItem>(); var dao = new GraphicMessageDao(ConfigurationManager.AppSettings["mysqlConnStr"]); var messages = dao.GetListExt(count: 4, endId: int.MaxValue); 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 = !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; }); return(results); }
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 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); }
public static void UpdateRandomIDs() { var dao = new GraphicMessageDao(ConfigurationManager.AppSettings["mysqlConnStr"]); allIDs = dao.GetAllIds(); }