ReplyService.Note.Topic.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using Dapper;
  4. using Datory;
  5. using GxPress.Common.Tools;
  6. using GxPress.EnumConst;
  7. using GxPress.Request.Reply;
  8. using GxPress.Result;
  9. using GxPress.Result.Reply;
  10. using Newtonsoft.Json;
  11. namespace GxPress.Service.Implement.Reply
  12. {
  13. /// <summary>
  14. /// 回复笔记或者话题
  15. /// </summary>
  16. public partial class ReplyService
  17. {
  18. /// <summary>
  19. /// 获取回复我的笔记或者话题
  20. /// </summary>
  21. /// <param name="request"></param>
  22. /// <returns></returns>
  23. public async Task<IEnumerable<ReplyResult>> GetReplyNoteOrTopicResults(ReplyRequest request)
  24. {
  25. var noteConstValue = AllTypeConst.Note.GetHashCode();
  26. string sqlStr = string.Empty;
  27. if (!string.IsNullOrEmpty(request.KeyWord))
  28. {
  29. sqlStr = $@"AND (a.Content LIKE '%{request.KeyWord}%'
  30. OR b.Title LIKE '%{request.KeyWord}%'
  31. OR b.Content LIKE '%{request.KeyWord}%' or c.Name like '%{request.KeyWord}%')";
  32. }
  33. if (request.TypeValue == 0)
  34. sqlStr = $@" and b.UserId = {request.UserId}";
  35. else
  36. sqlStr = $@" and a.UserId = {request.UserId}";
  37. string sql = $@"
  38. SELECT
  39. a.Id,
  40. a.UserId,
  41. a.ArticleId as SourceId,
  42. a.Content as CommentContent,
  43. a.Pid,
  44. a.TypeValue,
  45. b.Title,
  46. b.Content,
  47. b.CreatedDate,
  48. b.IsTopic,
  49. c.Name,
  50. c.AvatarUrl,
  51. d.Name
  52. FROM
  53. tede_comment a
  54. INNER JOIN
  55. tede_note b ON a.ArticleId = b.Id
  56. INNER JOIN
  57. tede_user c ON c.Id = a.UserId
  58. INNER JOIN
  59. tede_user d ON d.Id = b.UserId
  60. WHERE
  61. 1=1 AND a.TypeValue ={noteConstValue}
  62. AND b.IsDelete = 0
  63. {sqlStr}
  64. ORDER BY a.CreatedDate DESC
  65. ";
  66. var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
  67. var connection = database.GetConnection();
  68. return await connection.QueryAsync<ReplyResult, Entity.Note.Note, Entity.User, Entity.User, ReplyResult>(sql,
  69. (result, note, user, userModel) =>
  70. {
  71. result.UserName = user != null ? user.Name : "";
  72. result.AvatarUrl = StringUtils.AddDomainMin(user.AvatarUrl);
  73. result.IsTopic = note.IsTop;
  74. result.Title = string.IsNullOrEmpty(note.Title) ? GetTitleText(note.Content) : note.Title; ;
  75. //result.Content = note.Content;
  76. result.CreatedDate = note.CreatedDate;
  77. result.Name = userModel.Name;
  78. result.Remark = result.IsTopic ? AllTypeConst.Topic.GetDescriptionOriginal() : AllTypeConst.Note.GetDescriptionOriginal();
  79. return result;
  80. }, splitOn: "Id,Title,Name,Name");
  81. }
  82. public string GetTitleText(string content)
  83. {
  84. var data = JsonConvert.DeserializeObject<List<CollectionContentJsonData>>(content);
  85. int i = 0;
  86. foreach (var item in data)
  87. {
  88. if (item.Type == AllTypeConst.Text.GetHashCode() && i == 0)
  89. return item.Text;
  90. else if (item.Type == AllTypeConst.Image.GetHashCode())
  91. return "[图片]";
  92. else if (item.Type == AllTypeConst.File.GetHashCode())
  93. return "[附件]";
  94. else
  95. return "[附件]";
  96. }
  97. return string.Empty;
  98. }
  99. }
  100. }