123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- 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;
- using GxPress.Result.Reply;
- using Newtonsoft.Json;
- namespace GxPress.Service.Implement.Reply
- {
- /// <summary>
- /// 回复笔记或者话题
- /// </summary>
- public partial class ReplyService
- {
- /// <summary>
- /// 获取回复我的笔记或者话题
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- public async Task<IEnumerable<ReplyResult>> GetReplyNoteOrTopicResults(ReplyRequest request)
- {
- var noteConstValue = AllTypeConst.Note.GetHashCode();
- string sqlStr = string.Empty;
- if (!string.IsNullOrEmpty(request.KeyWord))
- {
- sqlStr = $@"AND (a.Content LIKE '%{request.KeyWord}%'
- OR b.Title LIKE '%{request.KeyWord}%'
- OR b.Content LIKE '%{request.KeyWord}%' or c.Name like '%{request.KeyWord}%')";
- }
- if (request.TypeValue == 0)
- sqlStr = $@" and b.UserId = {request.UserId}";
- else
- sqlStr = $@" and a.UserId = {request.UserId}";
- string sql = $@"
- SELECT
- a.Id,
- a.UserId,
- a.ArticleId as SourceId,
- a.Content as CommentContent,
- a.Pid,
- a.TypeValue,
- b.Title,
- b.Content,
- b.CreatedDate,
- b.IsTopic,
- c.Name,
- c.AvatarUrl,
- d.Name
- FROM
- tede_comment a
- INNER JOIN
- tede_note b ON a.ArticleId = b.Id
- INNER JOIN
- tede_user c ON c.Id = a.UserId
- INNER JOIN
- tede_user d ON d.Id = b.UserId
- WHERE
- 1=1 AND a.TypeValue ={noteConstValue}
- AND b.IsDelete = 0
- {sqlStr}
- ORDER BY a.CreatedDate DESC
- ";
- var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
- var connection = database.GetConnection();
- return await connection.QueryAsync<ReplyResult, Entity.Note.Note, Entity.User, Entity.User, ReplyResult>(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");
- }
- public string GetTitleText(string content)
- {
- var data = JsonConvert.DeserializeObject<List<CollectionContentJsonData>>(content);
- int i = 0;
- foreach (var item in data)
- {
- if (item.Type == AllTypeConst.Text.GetHashCode() && i == 0)
- return item.Text;
- else if (item.Type == AllTypeConst.Image.GetHashCode())
- return "[图片]";
- else if (item.Type == AllTypeConst.File.GetHashCode())
- return "[附件]";
- else
- return "[附件]";
- }
- return string.Empty;
- }
- }
- }
|