123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Dapper;
- using Datory;
- using GxPress.Common.Tools;
- using GxPress.EnumConst;
- using GxPress.Request.Reply;
- using GxPress.Result.Reply;
- namespace GxPress.Service.Implement.Reply
- {
- /// <summary>
- /// 获取我收到的或者我回复的评论
- /// </summary>
- public partial class ReplyService
- {
- /// <summary>
- /// 获取我收到的评论
- /// </summary>
- /// <returns></returns>
- public async Task<IEnumerable<ReplyResult>> GetReceiptCommentResult(ReplyRequest request)
- {
- string sqlStr = string.Empty;
- if (!string.IsNullOrEmpty(request.KeyWord))
- sqlStr += $" and (a.Content like '%{request.KeyWord}%' or b.Name like '%request.KeyWord%')";
- //获取回复我的
- string sql = $@"SELECT
- a.Id,
- a.ArticleId AS SourceId,
- a.Content AS CommentContent,
- a.TypeValue,
- a.CreatedDate,
- a.Pid,
- b.Id AS UserId,
- b.Name as UserName
- FROM
- tede_comment a
- INNER JOIN
- tede_user b ON a.UserId = b.Id
- WHERE
- a.Pid IN (SELECT
- id
- FROM
- tede_comment
- WHERE
- id IN (SELECT
- Pid
- FROM
- tede_comment
- WHERE
- pid > 0)
- AND userId = {request.UserId}) {sqlStr}";
- var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
- var connection = database.GetConnection();
- var receipt = await connection.QueryAsync<ReplyResult>(sql);
- sql = $@"SELECT
- a.Id,
- a.ArticleId AS SourceId,
- a.Content AS CommentContent,
- a.TypeValue,
- a.CreatedDate,
- a.Pid,
- b.Id AS UserId,
- b.Name
- FROM
- tede_comment a
- INNER JOIN
- tede_user b ON a.UserId = b.Id
- WHERE
- a.id IN (SELECT
- Pid
- FROM
- tede_comment
- WHERE
- pid > 0)
- AND userId = {request.UserId}";
- var my = await connection.QueryAsync<ReplyResult>(sql);
- foreach (var item in receipt)
- {
- if (item.Pid > 0)
- {
- ReplyResult replyResult1 = my.FirstOrDefault(n => n.Id == item.Pid);
- ReplyResult replyResult = replyResult1;
- item.Title = replyResult.CommentContent;
- item.Name = replyResult.Name;
- }
- item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
- item.Remark = ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
- item.IsComment = true;
- }
- return receipt;
- }
- /// <summary>
- /// 获取我回复的评论
- /// </summary>
- /// <returns></returns>
- public async Task<IEnumerable<ReplyResult>> GetMyReceiptCommentResult(ReplyRequest request)
- {
- string sqlStr = string.Empty;
- if (!string.IsNullOrEmpty(request.KeyWord))
- sqlStr += $" and (a.Content like '%{request.KeyWord}%' or b.Name like '%request.KeyWord%')";
- //获取回复我的
- string sql = $@"SELECT
- a.Id,
- a.ArticleId AS SourceId,
- a.Content AS CommentContent,
- a.TypeValue,
- a.CreatedDate,
- a.Pid,
- b.Id AS UserId,
- b.Name AS UserName
- FROM
- tede_comment a
- INNER JOIN
- tede_user b ON a.UserId = b.Id
- WHERE
- a.pid > 0 AND a.userId = {request.UserId} {sqlStr}";
- var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
- var connection = database.GetConnection();
- var receipt = await connection.QueryAsync<ReplyResult>(sql);
- sql = $@"SELECT
- a.Id,
- a.ArticleId AS SourceId,
- a.Content AS CommentContent,
- a.TypeValue,
- a.CreatedDate,
- a.Pid,
- b.Id AS UserId,
- b.Name
- FROM
- tede_comment a
- INNER JOIN
- tede_user b ON a.UserId = b.Id
- WHERE
- a.id IN (SELECT
- a.Pid
- FROM
- tede_comment a
- INNER JOIN
- tede_user b ON a.UserId = b.Id
- WHERE
- a.pid > 0 AND a.userId = {request.UserId})";
- var my = await connection.QueryAsync<ReplyResult>(sql);
- foreach (var item in receipt)
- {
- if (item.Pid > 0)
- {
- ReplyResult replyResult1 = my.FirstOrDefault(n => n.Id == item.Pid);
- if (replyResult1 != null)
- {
- ReplyResult replyResult = replyResult1;
- item.Title = replyResult.CommentContent;
- item.Name = replyResult.Name;
- }
- }
- item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
- item.Remark = ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
- item.IsComment = true;
- }
- return receipt;
- }
- }
- }
|