ReplyService.Note.Topic.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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.Title = string.IsNullOrEmpty(note.Title) ? GetTitleText(note.Content) : note.Title; ;
  74. //result.Content = note.Content;
  75. result.CreatedDate = note.CreatedDate;
  76. result.Content = string.Empty;
  77. result.Name = userModel.Name;
  78. result.Remark = result.TypeValue == AllTypeConst.Note.GetHashCode() ? AllTypeConst.Topic.GetDescriptionOriginal() : AllTypeConst.Note.GetDescriptionOriginal();
  79. return result;
  80. }, splitOn: "Id,Title,Name,Name");
  81. }
  82. /// <summary>
  83. /// 获取回复我的小组话题
  84. /// </summary>
  85. /// <param name="request"></param>
  86. /// <returns></returns>
  87. public async Task<IEnumerable<ReplyResult>> GetReplyGroupTopicResults(ReplyRequest request)
  88. {
  89. var topicConstValue = AllTypeConst.Topic.GetHashCode();
  90. string sqlStr = string.Empty;
  91. if (!string.IsNullOrEmpty(request.KeyWord))
  92. {
  93. sqlStr = $@" AND (c.Name LIKE '%{request.KeyWord}%'
  94. OR a.Content LIKE '%{request.KeyWord}%'
  95. OR b.Title LIKE '%{request.KeyWord}%'
  96. OR b.Content LIKE '%{request.KeyWord}%')";
  97. }
  98. if (request.TypeValue == 0)
  99. sqlStr = $@" and b.UserId = {request.UserId}";
  100. else
  101. sqlStr = $@" and a.UserId = {request.UserId}";
  102. string sql = $@"
  103. SELECT
  104. a.Id,
  105. a.UserId,
  106. a.ArticleId AS SourceId,
  107. a.Content AS CommentContent,
  108. a.Pid,
  109. a.TypeValue,
  110. b.Title,
  111. b.Content,
  112. b.CreatedDate,
  113. b.GroupId,
  114. c.Name AS UserName,
  115. c.AvatarUrl,
  116. d.Name,
  117. g.Id AS GroupId,
  118. g.Name AS GroupName
  119. FROM
  120. tede_comment a
  121. INNER JOIN
  122. tede_topic b ON a.ArticleId = b.Id
  123. INNER JOIN
  124. tede_user c ON c.Id = a.UserId
  125. INNER JOIN
  126. tede_user d ON d.Id = b.UserId
  127. INNER JOIN
  128. tede_middle e ON e.MiddleId = b.Id
  129. INNER JOIN
  130. tede_group g ON g.id = b.GroupId
  131. WHERE
  132. 1 = 1 AND a.TypeValue = {topicConstValue}
  133. AND b.GroupId > 0
  134. AND e.IsDelete = 0
  135. AND a.Content <> ''
  136. {sqlStr}
  137. ORDER BY a.CreatedDate DESC
  138. ";
  139. var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
  140. var connection = database.GetConnection();
  141. var result = await connection.QueryAsync<ReplyResult>(sql);
  142. foreach (var item in result)
  143. {
  144. item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
  145. item.Title = string.IsNullOrEmpty(item.Title) ? GetTitleText(item.Content) : item.Title; ;
  146. //result.Content = note.Content;
  147. item.Remark = item.GroupName;
  148. item.Content = string.Empty;
  149. item.IsGroup = true;
  150. }
  151. return result;
  152. }
  153. public string GetTitleText(string content)
  154. {
  155. var data = JsonConvert.DeserializeObject<List<CollectionContentJsonData>>(content);
  156. int i = 0;
  157. foreach (var item in data)
  158. {
  159. if (item.Type == AllTypeConst.Text.GetHashCode() && i == 0)
  160. return item.Text;
  161. else if (item.Type == AllTypeConst.Image.GetHashCode())
  162. return "[图片]";
  163. else if (item.Type == AllTypeConst.File.GetHashCode())
  164. return "[附件]";
  165. else
  166. return "[附件]";
  167. }
  168. return string.Empty;
  169. }
  170. /// <summary>
  171. /// 获取回复我的通知站内信
  172. /// </summary>
  173. /// <param name="request"></param>
  174. /// <returns></returns>
  175. public async Task<IEnumerable<ReplyResult>> GetReplyNoticeTopicResults(ReplyRequest request)
  176. {
  177. var topicConstValue = AllTypeConst.Topic.GetHashCode();
  178. string sqlStr = string.Empty;
  179. if (!string.IsNullOrEmpty(request.KeyWord))
  180. {
  181. sqlStr = $@" AND (c.Name LIKE '%{request.KeyWord}%'
  182. OR a.Content LIKE '%{request.KeyWord}%'
  183. OR b.Title LIKE '%{request.KeyWord}%'
  184. OR b.Content LIKE '%{request.KeyWord}%')";
  185. }
  186. if (request.TypeValue == 0)
  187. sqlStr = $@" and b.UserId = {request.UserId}";
  188. else
  189. sqlStr = $@" and a.UserId = {request.UserId}";
  190. string sql = $@"
  191. SELECT
  192. a.Id,
  193. a.UserId,
  194. a.ArticleId AS SourceId,
  195. a.Content AS CommentContent,
  196. a.Pid,
  197. a.TypeValue,
  198. b.Title,
  199. b.Content,
  200. b.CreatedDate,
  201. c.Name AS UserName,
  202. c.AvatarUrl,
  203. d.Name
  204. FROM
  205. tede_comment a
  206. INNER JOIN
  207. tede_notice b ON a.ArticleId = b.Id
  208. INNER JOIN
  209. tede_user c ON c.Id = a.UserId
  210. INNER JOIN
  211. tede_user d ON d.Id = b.UserId
  212. INNER JOIN
  213. tede_middle e ON e.MiddleId = b.Id
  214. WHERE
  215. 1 = 1
  216. AND e.IsDelete = 0 and e.UserId=b.UserId
  217. AND a.Content <> '' and a.TypeValue in(5,6)
  218. {sqlStr}
  219. ORDER BY a.CreatedDate DESC
  220. ";
  221. var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
  222. var connection = database.GetConnection();
  223. var result = await connection.QueryAsync<ReplyResult>(sql);
  224. foreach (var item in result)
  225. {
  226. item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
  227. item.Title = string.IsNullOrEmpty(item.Title) ? GetTitleText(item.Content) : item.Title; ;
  228. //result.Content = note.Content;
  229. item.Remark = ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
  230. item.Content = string.Empty;
  231. }
  232. return result;
  233. }
  234. }
  235. }