using System.Collections.Generic;
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
{
///
/// 点赞
///
public partial class ReplyService
{
///
/// 获取我收到的赞
///
///
///
public async Task> GetPraiseAsync(ReplyRequest request)
{
var noteConstValue = AllTypeConst.Note.GetHashCode();
string sqlStr = string.Empty;
if (!string.IsNullOrEmpty(request.KeyWord))
{
sqlStr = $@" AND (
b.Title LIKE '%{request.KeyWord}%'
OR b.Content LIKE '%{request.KeyWord}%' or c.Name like '%{request.KeyWord}%')";
}
string sql = $@"
SELECT
a.Id,
a.SourceId,
a.TypeValue,
b.Title,
b.Content,
c.Name,
c.AvatarUrl,
b.CreatedDate,
a.UserId,
b.IsTopic,
d.Name
FROM
tede_analyze a
INNER JOIN
tede_note b ON a.SourceId = b.Id
INNER JOIN
tede_user c ON c.Id = a.UserId
INNER JOIN
tede_user d ON d.Id = b.UserId
WHERE
b.UserId = {request.UserId} AND a.TypeValue ={noteConstValue}
AND b.IsDelete = 0 and a.AnalyzeType in(1,2) {sqlStr}
ORDER BY a.CreatedDate DESC
";
var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
var connection = database.GetConnection();
return await connection.QueryAsync(sql,
(result, note, user, userModel) =>
{
result.UserName = user != null ? user.Name : "";
result.AvatarUrl = StringUtils.AddDomainMin(user.AvatarUrl);
result.IsTopic = note.IsTop;
result.Title = string.IsNullOrEmpty(note.Title) ? GetTitleText(note.Content) : note.Title;
//result.Content = note.Content;
result.CreatedDate = note.CreatedDate;
result.Name = userModel.Name;
result.Remark = result.IsTopic ? AllTypeConst.Topic.GetDescriptionOriginal() : AllTypeConst.Note.GetDescriptionOriginal();
return result;
}, splitOn: "Id,Title,Name,Name");
}
}
}