ReplyService.Praise.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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.Reply;
  9. namespace GxPress.Service.Implement.Reply
  10. {
  11. /// <summary>
  12. /// 点赞
  13. /// </summary>
  14. public partial class ReplyService
  15. {
  16. /// <summary>
  17. /// 获取话题本赞
  18. /// </summary>
  19. /// <param name="request"></param>
  20. /// <returns></returns>
  21. public async Task<IEnumerable<ReplyResult>> GetNotePraiseAsync(ReplyRequest request)
  22. {
  23. var noteConstValue = AllTypeConst.Note.GetHashCode();
  24. string sqlStr = string.Empty;
  25. if (!string.IsNullOrEmpty(request.KeyWord))
  26. {
  27. sqlStr = $@" AND (
  28. b.Title LIKE '%{request.KeyWord}%'
  29. OR b.Content LIKE '%{request.KeyWord}%' or c.Name like '%{request.KeyWord}%')";
  30. }
  31. string sql = $@"
  32. SELECT
  33. a.Id,
  34. a.SourceId,
  35. a.TypeValue,
  36. a.IsRead,
  37. b.Title,
  38. b.Content,
  39. c.Name,
  40. c.AvatarUrl,
  41. b.CreatedDate,
  42. a.UserId,
  43. b.IsTopic,
  44. d.Name
  45. FROM
  46. tede_analyze a
  47. INNER JOIN
  48. tede_note b ON a.SourceId = b.Id
  49. INNER JOIN
  50. tede_user c ON c.Id = a.UserId
  51. INNER JOIN
  52. tede_user d ON d.Id = b.UserId
  53. INNER JOIN
  54. tede_middle e ON e.MiddleId = b.Id
  55. WHERE
  56. a.TypeValue = 4 AND e.IsDelete = 0
  57. AND a.CommentId = 0
  58. AND e.UserId = b.UserId
  59. AND a.AnalyzeType = 1 AND b.UserId ={request.UserId}
  60. {sqlStr}
  61. ORDER BY a.CreatedDate DESC
  62. ";
  63. var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
  64. var connection = database.GetConnection();
  65. var result = await connection.QueryAsync<ReplyResult>(sql);
  66. foreach (var item in result)
  67. {
  68. item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
  69. item.CommentContent = "点赞了你的" + ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
  70. item.Title = string.IsNullOrEmpty(item.Title) ? GetTitleText(item.Content) : item.Title;
  71. item.Remark = ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
  72. item.Content = string.Empty;
  73. }
  74. return result;
  75. }
  76. /// <summary>
  77. /// 获取评论点赞
  78. /// </summary>
  79. /// <param name="request"></param>
  80. /// <returns></returns>
  81. public async Task<IEnumerable<ReplyResult>> GetCommentPraiseAsync(ReplyRequest request)
  82. {
  83. var sqlStr = string.Empty;
  84. if (!string.IsNullOrEmpty(request.KeyWord))
  85. {
  86. sqlStr = $@" AND (a.Content LIKE '%{request.KeyWord}%'
  87. OR c.Name LIKE '%{request.KeyWord}%')";
  88. }
  89. string sql = $@"
  90. SELECT
  91. a.Id,
  92. a.Content,
  93. a.TypeValue,
  94. b.IsRead,
  95. b.UserId,
  96. c.Name AS UserName,
  97. c.AvatarUrl,
  98. c.Id AS UserId,
  99. d.Name,
  100. b.CreatedDate
  101. FROM
  102. tede_comment a
  103. INNER JOIN
  104. tede_analyze b ON a.Id = b.CommentId
  105. INNER JOIN
  106. tede_user c ON c.Id = b.UserId
  107. INNER JOIN
  108. tede_user d ON d.Id = a.UserId
  109. WHERE
  110. a.TypeValue IN ({AllTypeConst.Topic.GetHashCode()},{AllTypeConst.Notice.GetHashCode()},{AllTypeConst.Note.GetHashCode()})
  111. AND a.UserId = {request.UserId}
  112. {sqlStr}
  113. AND b.AnalyzeType = 2
  114. ORDER BY a.CreatedDate DESC";
  115. var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
  116. var connection = database.GetConnection();
  117. var result = await connection.QueryAsync<ReplyResult>(sql);
  118. foreach (var item in result)
  119. {
  120. item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
  121. item.CommentContent = "点赞了你的" + ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
  122. item.Title = item.Content;
  123. item.IsComment = true;
  124. item.Remark = ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
  125. }
  126. return result;
  127. }
  128. /// <summary>
  129. /// 获取通知点赞
  130. /// </summary>
  131. /// <param name="request"></param>
  132. /// <returns></returns>
  133. public async Task<IEnumerable<ReplyResult>> GetNoticePraiseAsync(ReplyRequest request)
  134. {
  135. var sqlStr = string.Empty;
  136. if (!string.IsNullOrEmpty(request.KeyWord))
  137. {
  138. sqlStr = $@" AND (b.Title LIKE '%{request.KeyWord}%'
  139. OR b.Content LIKE '%{request.KeyWord}%'
  140. OR c.Name LIKE '%{request.KeyWord}%')";
  141. }
  142. string sql = $@"
  143. SELECT
  144. a.Id,
  145. a.SourceId,
  146. a.TypeValue,
  147. a.IsRead,
  148. b.Title,
  149. b.Content,
  150. c.Name,
  151. c.AvatarUrl,
  152. b.CreatedDate,
  153. a.UserId,
  154. d.Name AS UserName
  155. FROM
  156. tede_analyze a
  157. INNER JOIN
  158. tede_notice b ON a.SourceId = b.Id
  159. INNER JOIN
  160. tede_user c ON c.Id = a.UserId
  161. INNER JOIN
  162. tede_user d ON d.Id = b.UserId
  163. INNER JOIN
  164. tede_middle e ON e.MiddleId = b.Id
  165. WHERE
  166. b.UserId = {request.UserId} AND e.UserId = b.UserId
  167. AND a.TypeValue ={AllTypeConst.Notice.GetHashCode()}
  168. AND e.IsDelete = 0
  169. AND a.CommentId = 0
  170. AND a.AnalyzeType = 1
  171. {sqlStr}
  172. ORDER BY a.CreatedDate DESC";
  173. var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
  174. var connection = database.GetConnection();
  175. var result = await connection.QueryAsync<ReplyResult>(sql);
  176. foreach (var item in result)
  177. {
  178. item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
  179. item.CommentContent = "点赞了你的" + ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
  180. item.Title = string.IsNullOrEmpty(item.Title) ? GetTitleText(item.Content) : item.Title;
  181. item.Remark = ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
  182. item.Content = string.Empty;
  183. }
  184. return result;
  185. }
  186. /// <summary>
  187. /// 获取话题点赞
  188. /// </summary>
  189. /// <param name="request"></param>
  190. /// <returns></returns>
  191. public async Task<IEnumerable<ReplyResult>> GetTopicPraiseAsync(ReplyRequest request)
  192. {
  193. var sqlStr = string.Empty;
  194. if (!string.IsNullOrEmpty(request.KeyWord))
  195. {
  196. sqlStr = $@" AND ( b.Title LIKE '%{request.KeyWord}%'
  197. OR b.Content LIKE '%{request.KeyWord}%'
  198. OR c.Name LIKE '%{request.KeyWord}%')";
  199. }
  200. string sql = $@"
  201. SELECT
  202. a.Id,
  203. a.SourceId,
  204. a.TypeValue,
  205. a.IsRead,
  206. b.Title,
  207. b.Content,
  208. c.Name as UserName,
  209. c.AvatarUrl,
  210. b.CreatedDate,
  211. a.UserId,
  212. d.Name,
  213. g.Id as GroupId,
  214. g.Name as GroupName
  215. FROM
  216. tede_analyze a
  217. INNER JOIN
  218. tede_topic b ON a.SourceId = b.Id
  219. INNER JOIN
  220. tede_user c ON c.Id = a.UserId
  221. INNER JOIN
  222. tede_user d ON d.Id = b.UserId
  223. INNER JOIN
  224. tede_middle e ON e.MiddleId = b.Id
  225. INNER JOIN
  226. tede_group g ON g.Id = b.GroupId
  227. WHERE
  228. a.TypeValue ={AllTypeConst.Topic.GetHashCode()} AND e.IsDelete = 0
  229. AND a.CommentId = 0
  230. AND e.UserId = b.UserId
  231. AND a.AnalyzeType = 1
  232. AND b.UserId = {request.UserId}
  233. {sqlStr}
  234. ORDER BY a.CreatedDate DESC";
  235. var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
  236. var connection = database.GetConnection();
  237. var result = await connection.QueryAsync<ReplyResult>(sql);
  238. foreach (var item in result)
  239. {
  240. item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
  241. item.CommentContent = "点赞了你的" + ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
  242. item.Title = string.IsNullOrEmpty(item.Title) ? GetTitleText(item.Content) : item.Title;
  243. item.Remark = ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
  244. item.IsGroup = true;
  245. item.Content = string.Empty;
  246. }
  247. return result;
  248. }
  249. /// <summary>
  250. /// 未读点赞数量
  251. /// </summary>
  252. /// <param name="userId"></param>
  253. /// <returns></returns>
  254. public async Task<int> GetUReadPraiseCountAsync(int userId)
  255. {
  256. var sql = $@" SELECT
  257. COUNT(1)
  258. FROM
  259. tede_analyze a
  260. INNER JOIN
  261. tede_note b ON a.SourceId = b.Id
  262. INNER JOIN
  263. tede_user c ON c.Id = a.UserId
  264. INNER JOIN
  265. tede_user d ON d.Id = b.UserId
  266. INNER JOIN
  267. tede_middle e ON e.MiddleId = b.Id
  268. WHERE
  269. a.TypeValue = 4 AND e.IsDelete = 0
  270. AND a.CommentId = 0
  271. AND e.UserId = b.UserId
  272. AND a.AnalyzeType = 1
  273. AND b.UserId = {userId}
  274. AND a.IsRead = 0";
  275. var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
  276. var connection = database.GetConnection();
  277. var count = await connection.ExecuteScalarAsync<int>(sql);
  278. sql = $@" SELECT
  279. count(1)
  280. FROM
  281. tede_comment a
  282. INNER JOIN
  283. tede_analyze b ON a.Id = b.CommentId
  284. INNER JOIN
  285. tede_user c ON c.Id = b.UserId
  286. INNER JOIN
  287. tede_user d ON d.Id = a.UserId
  288. WHERE
  289. a.TypeValue IN ({AllTypeConst.Topic.GetHashCode()},{AllTypeConst.Notice.GetHashCode()},{AllTypeConst.Note.GetHashCode()})
  290. AND a.UserId ={userId}
  291. AND b.AnalyzeType = 2
  292. AND b.IsRead = 0";
  293. count += await connection.ExecuteScalarAsync<int>(sql);
  294. sql = $@" SELECT
  295. COUNT(1)
  296. FROM
  297. tede_analyze a
  298. INNER JOIN
  299. tede_notice b ON a.SourceId = b.Id
  300. INNER JOIN
  301. tede_user c ON c.Id = a.UserId
  302. INNER JOIN
  303. tede_user d ON d.Id = b.UserId
  304. INNER JOIN
  305. tede_middle e ON e.MiddleId = b.Id
  306. WHERE
  307. b.UserId ={userId} AND e.UserId = b.UserId
  308. AND a.TypeValue ={AllTypeConst.Notice.GetHashCode()}
  309. AND e.IsDelete = 0
  310. AND a.CommentId = 0
  311. AND a.AnalyzeType = 1";
  312. count += await connection.ExecuteScalarAsync<int>(sql);
  313. sql = $@" SELECT
  314. count(1)
  315. FROM
  316. tede_analyze a
  317. INNER JOIN
  318. tede_topic b ON a.SourceId = b.Id
  319. INNER JOIN
  320. tede_user c ON c.Id = a.UserId
  321. INNER JOIN
  322. tede_user d ON d.Id = b.UserId
  323. INNER JOIN
  324. tede_middle e ON e.MiddleId = b.Id
  325. INNER JOIN
  326. tede_group g ON g.Id = b.GroupId
  327. WHERE
  328. a.TypeValue = {AllTypeConst.Topic.GetHashCode()} AND e.IsDelete = 0
  329. AND a.CommentId = 0
  330. AND e.UserId = b.UserId
  331. AND a.AnalyzeType = 1
  332. AND b.UserId ={userId}";
  333. count += await connection.ExecuteScalarAsync<int>(sql);
  334. return count;
  335. }
  336. /// <summary>
  337. /// 修改未读点赞数量
  338. /// </summary>
  339. /// <param name="userId"></param>
  340. /// <returns></returns>
  341. public async Task<int> UpdateUReadPraiseAsync(int userId)
  342. {
  343. var sql = $@" UPDATE tede_analyze
  344. SET
  345. IsRead = 1
  346. AND Id IN (
  347. SELECT
  348. a.Id
  349. FROM
  350. tede_analyze a
  351. INNER JOIN
  352. tede_note b ON a.SourceId = b.Id
  353. INNER JOIN
  354. tede_user c ON c.Id = a.UserId
  355. INNER JOIN
  356. tede_user d ON d.Id = b.UserId
  357. INNER JOIN
  358. tede_middle e ON e.MiddleId = b.Id
  359. WHERE
  360. a.TypeValue = 4 AND e.IsDelete = 0
  361. AND a.CommentId = 0
  362. AND e.UserId = b.UserId
  363. AND a.AnalyzeType = 1
  364. AND b.UserId = {userId}
  365. AND a.IsRead = 0";
  366. var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
  367. var connection = database.GetConnection();
  368. var count = await connection.ExecuteScalarAsync<int>(sql);
  369. sql = $@" UPDATE tede_analyze
  370. SET
  371. IsRead = 1
  372. AND Id IN (
  373. SELECT
  374. b.Id
  375. FROM
  376. tede_comment a
  377. INNER JOIN
  378. tede_analyze b ON a.Id = b.CommentId
  379. INNER JOIN
  380. tede_user c ON c.Id = b.UserId
  381. INNER JOIN
  382. tede_user d ON d.Id = a.UserId
  383. WHERE
  384. a.TypeValue IN ({AllTypeConst.Topic.GetHashCode()},{AllTypeConst.Notice.GetHashCode()},{AllTypeConst.Note.GetHashCode()})
  385. AND a.UserId ={userId}
  386. AND b.AnalyzeType = 2
  387. AND b.IsRead = 0) and id>0) and id>0";
  388. count += await connection.ExecuteScalarAsync<int>(sql);
  389. sql = $@"
  390. UPDATE tede_analyze
  391. SET
  392. IsRead = 1
  393. AND Id IN (
  394. SELECT
  395. a.Id
  396. FROM
  397. tede_analyze a
  398. INNER JOIN
  399. tede_notice b ON a.SourceId = b.Id
  400. INNER JOIN
  401. tede_user c ON c.Id = a.UserId
  402. INNER JOIN
  403. tede_user d ON d.Id = b.UserId
  404. INNER JOIN
  405. tede_middle e ON e.MiddleId = b.Id
  406. WHERE
  407. b.UserId ={userId} AND e.UserId = b.UserId
  408. AND a.TypeValue ={AllTypeConst.Notice.GetHashCode()}
  409. AND e.IsDelete = 0
  410. AND a.CommentId = 0
  411. AND a.AnalyzeType = 1) and id>0";
  412. count += await connection.ExecuteScalarAsync<int>(sql);
  413. sql = $@"
  414. UPDATE tede_analyze
  415. SET
  416. IsRead = 1
  417. AND Id IN (
  418. SELECT
  419. a.Id
  420. FROM
  421. tede_analyze a
  422. INNER JOIN
  423. tede_topic b ON a.SourceId = b.Id
  424. INNER JOIN
  425. tede_user c ON c.Id = a.UserId
  426. INNER JOIN
  427. tede_user d ON d.Id = b.UserId
  428. INNER JOIN
  429. tede_middle e ON e.MiddleId = b.Id
  430. INNER JOIN
  431. tede_group g ON g.Id = b.GroupId
  432. WHERE
  433. a.TypeValue = {AllTypeConst.Topic.GetHashCode()} AND e.IsDelete = 0
  434. AND a.CommentId = 0
  435. AND e.UserId = b.UserId
  436. AND a.AnalyzeType = 1
  437. AND b.UserId ={userId}) and id>0";
  438. count += await connection.ExecuteScalarAsync<int>(sql);
  439. return count;
  440. }
  441. }
  442. }