ReplyService.Praise.cs 22 KB

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