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.TopicNote.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. and b.IsTopic=1
  64. {sqlStr}
  65. ORDER BY a.CreatedDate DESC
  66. ";
  67. var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
  68. var connection = database.GetConnection();
  69. return await connection.QueryAsync<ReplyResult, Entity.Note.Note, Entity.User, Entity.User, ReplyResult>(sql,
  70. (result, note, user, userModel) =>
  71. {
  72. result.UserName = user != null ? user.Name : "";
  73. result.AvatarUrl = StringUtils.AddDomainMin(user.AvatarUrl);
  74. result.Title = string.IsNullOrEmpty(note.Title) ? GetTitleText(note.Content) : note.Title; ;
  75. //result.Content = note.Content;
  76. result.CreatedDate = note.CreatedDate;
  77. result.Content = string.Empty;
  78. result.Name = userModel.Name;
  79. result.Remark =((AllTypeConst)result.TypeValue).GetDescriptionOriginal();
  80. return result;
  81. }, splitOn: "Id,Title,Name,Name");
  82. }
  83. /// <summary>
  84. /// 获取回复我的小组话题
  85. /// </summary>
  86. /// <param name="request"></param>
  87. /// <returns></returns>
  88. public async Task<IEnumerable<ReplyResult>> GetReplyGroupTopicResults(ReplyRequest request)
  89. {
  90. var topicConstValue = AllTypeConst.Topic.GetHashCode();
  91. string sqlStr = string.Empty;
  92. if (!string.IsNullOrEmpty(request.KeyWord))
  93. {
  94. sqlStr = $@" AND (c.Name LIKE '%{request.KeyWord}%'
  95. OR a.Content LIKE '%{request.KeyWord}%'
  96. OR b.Title LIKE '%{request.KeyWord}%'
  97. OR b.Content LIKE '%{request.KeyWord}%')";
  98. }
  99. if (request.TypeValue == 0)
  100. sqlStr = $@" and b.UserId = {request.UserId}";
  101. else
  102. sqlStr = $@" and a.UserId = {request.UserId}";
  103. string sql = $@"
  104. SELECT
  105. a.Id,
  106. a.UserId,
  107. a.ArticleId AS SourceId,
  108. a.Content AS CommentContent,
  109. a.Pid,
  110. a.TypeValue,
  111. b.Title,
  112. b.Content,
  113. b.CreatedDate,
  114. b.GroupId,
  115. c.Name AS UserName,
  116. c.AvatarUrl,
  117. d.Name,
  118. g.Id AS GroupId,
  119. g.Name AS GroupName
  120. FROM
  121. tede_comment a
  122. INNER JOIN
  123. tede_topic b ON a.ArticleId = b.Id
  124. INNER JOIN
  125. tede_user c ON c.Id = a.UserId
  126. INNER JOIN
  127. tede_user d ON d.Id = b.UserId
  128. INNER JOIN
  129. tede_middle e ON e.MiddleId = b.Id
  130. INNER JOIN
  131. tede_group g ON g.id = b.GroupId
  132. WHERE
  133. 1 = 1 AND a.TypeValue = {topicConstValue}
  134. AND b.GroupId > 0
  135. AND e.IsDelete = 0
  136. AND a.Content <> ''
  137. {sqlStr}
  138. ORDER BY a.CreatedDate DESC
  139. ";
  140. var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
  141. var connection = database.GetConnection();
  142. var result = await connection.QueryAsync<ReplyResult>(sql);
  143. foreach (var item in result)
  144. {
  145. item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
  146. item.Title = string.IsNullOrEmpty(item.Title) ? GetTitleText(item.Content) : item.Title; ;
  147. //result.Content = note.Content;
  148. item.Remark = item.GroupName;
  149. item.Content = string.Empty;
  150. item.IsGroup = true;
  151. }
  152. return result;
  153. }
  154. public string GetTitleText(string content)
  155. {
  156. var data = JsonConvert.DeserializeObject<List<CollectionContentJsonData>>(content);
  157. int i = 0;
  158. foreach (var item in data)
  159. {
  160. if (item.Type == AllTypeConst.Text.GetHashCode() && i == 0)
  161. return item.Text;
  162. else if (item.Type == AllTypeConst.Image.GetHashCode())
  163. return "[图片]";
  164. else if (item.Type == AllTypeConst.File.GetHashCode())
  165. return "[附件]";
  166. else
  167. return "[附件]";
  168. }
  169. return string.Empty;
  170. }
  171. /// <summary>
  172. /// 获取回复我的通知站内信
  173. /// </summary>
  174. /// <param name="request"></param>
  175. /// <returns></returns>
  176. public async Task<IEnumerable<ReplyResult>> GetReplyNoticeTopicResults(ReplyRequest request)
  177. {
  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. }