123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465 |
- 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;
- using System.Transactions;
- using System.Linq;
- namespace GxPress.Service.Implement.Reply
- {
- /// <summary>
- /// 点赞
- /// </summary>
- public partial class ReplyService
- {
- /// <summary>
- /// 获取 笔记话题本赞
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- public async Task<IEnumerable<ReplyResult>> GetNotePraiseAsync(ReplyRequest request)
- {
- var topicNoteConstValue = AllTypeConst.TopicNote.GetHashCode();
- 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,
- a.IsRead,
- b.Title,
- b.Content,
- c.Name as UserName,
- 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
- INNER JOIN
- tede_middle e ON e.MiddleId = b.Id
- WHERE
- a.TypeValue in ({topicNoteConstValue},{noteConstValue}) AND e.IsDelete = 0
- AND e.FolderType in({topicNoteConstValue},{noteConstValue})
- AND a.CommentId = 0
- AND e.UserId = b.UserId
- AND a.AnalyzeType = 1
- AND b.UserId ={request.UserId}
- And b.IsTopic=1
- {sqlStr}
- ORDER BY a.CreatedDate DESC
- ";
- var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
- var connection = database.GetConnection();
- var result = await connection.QueryAsync<ReplyResult>(sql);
- foreach (var item in result)
- {
- item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
- item.CommentContent = "点赞了你的" + ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
- item.Title = string.IsNullOrEmpty(item.Title) ? GetTitleText(item.Content) : item.Title;
- item.Remark = ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
- item.Content = string.Empty;
- }
- return result;
- }
- /// <summary>
- /// 获取评论点赞
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- public async Task<IEnumerable<ReplyResult>> GetCommentPraiseAsync(ReplyRequest request)
- {
- var sqlStr = string.Empty;
- if (!string.IsNullOrEmpty(request.KeyWord))
- {
- sqlStr = $@" AND (a.Content LIKE '%{request.KeyWord}%'
- OR c.Name LIKE '%{request.KeyWord}%')";
- }
- string sql = $@"
- SELECT
- a.Id,
- a.Content,
- a.TypeValue,
- b.IsRead,
- b.UserId,
- c.Name AS UserName,
- c.AvatarUrl,
- c.Id AS UserId,
- d.Name,
- b.CreatedDate
- FROM
- tede_comment a
- INNER JOIN
- tede_analyze b ON a.Id = b.CommentId
- INNER JOIN
- tede_user c ON c.Id = b.UserId
- INNER JOIN
- tede_user d ON d.Id = a.UserId
- WHERE
- a.TypeValue IN ({AllTypeConst.Topic.GetHashCode()},{AllTypeConst.Notice.GetHashCode()},{AllTypeConst.Note.GetHashCode()},{AllTypeConst.TopicNote.GetHashCode()})
- AND a.UserId = {request.UserId}
- {sqlStr}
- AND b.AnalyzeType = 2
- ORDER BY a.CreatedDate DESC";
- var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
- var connection = database.GetConnection();
- var result = await connection.QueryAsync<ReplyResult>(sql);
- foreach (var item in result)
- {
- item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
- item.CommentContent = "点赞了你的评论";
- item.Title = item.Content;
- item.IsComment = true;
- item.Remark = ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
- }
- return result;
- }
- /// <summary>
- /// 获取通知点赞
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- public async Task<IEnumerable<ReplyResult>> GetNoticePraiseAsync(ReplyRequest request)
- {
- var 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,
- a.IsRead,
- b.Title,
- b.Content,
- c.Name,
- c.AvatarUrl,
- b.CreatedDate,
- a.UserId,
- d.Name AS UserName
- FROM
- tede_analyze a
- INNER JOIN
- tede_notice 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
- INNER JOIN
- tede_middle e ON e.MiddleId = b.Id
- WHERE
- b.UserId = {request.UserId} AND e.UserId = b.UserId
- AND a.TypeValue ={AllTypeConst.Notice.GetHashCode()}
- AND e.IsDelete = 0
- AND a.CommentId = 0
- AND a.AnalyzeType = 1
- {sqlStr}
- ORDER BY a.CreatedDate DESC";
- var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
- var connection = database.GetConnection();
- var result = await connection.QueryAsync<ReplyResult>(sql);
- foreach (var item in result)
- {
- item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
- item.CommentContent = "点赞了你的" + ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
- item.Title = string.IsNullOrEmpty(item.Title) ? GetTitleText(item.Content) : item.Title;
- item.Remark = ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
- item.Content = string.Empty;
- }
- return result;
- }
- /// <summary>
- /// 获取话题点赞
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- public async Task<IEnumerable<ReplyResult>> GetTopicPraiseAsync(ReplyRequest request)
- {
- var 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,
- a.IsRead,
- b.Title,
- b.Content,
- c.Name as UserName,
- c.AvatarUrl,
- b.CreatedDate,
- a.UserId,
- d.Name,
- g.Id as GroupId,
- g.Name as GroupName
- FROM
- tede_analyze a
- INNER JOIN
- tede_topic 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
- INNER JOIN
- tede_middle e ON e.MiddleId = b.Id
- INNER JOIN
- tede_group g ON g.Id = b.GroupId
- WHERE
- a.TypeValue ={AllTypeConst.Topic.GetHashCode()} AND e.IsDelete = 0
- AND a.CommentId = 0
- AND e.UserId = b.UserId
- AND a.AnalyzeType = 1
- AND b.UserId = {request.UserId}
- {sqlStr}
- ORDER BY a.CreatedDate DESC";
- var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
- var connection = database.GetConnection();
- var result = await connection.QueryAsync<ReplyResult>(sql);
- foreach (var item in result)
- {
- item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
- item.CommentContent = "点赞了你的" + ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
- item.Title = string.IsNullOrEmpty(item.Title) ? GetTitleText(item.Content) : item.Title;
- item.Remark = ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
- item.IsGroup = true;
- item.Content = string.Empty;
- }
- return result;
- }
- /// <summary>
- /// 未读点赞数量
- /// </summary>
- /// <param name="userId"></param>
- /// <returns></returns>
- public async Task<int> GetUReadPraiseCountAsync(int userId)
- {
- //笔记话题本
- var sql = $@" SELECT
- COUNT(1)
- 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
- INNER JOIN
- tede_middle e ON e.MiddleId = b.Id
- WHERE
- a.TypeValue in({AllTypeConst.Note.GetHashCode()},{AllTypeConst.TopicNote.GetHashCode()}) AND e.IsDelete = 0
- AND a.CommentId = 0
- AND e.UserId = b.UserId
- AND a.AnalyzeType = 1
- AND b.UserId = {userId}
- AND a.IsRead = 0";
- var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
- var connection = database.GetConnection();
- var count = await connection.ExecuteScalarAsync<int>(sql);
- //评论
- sql = $@" SELECT
- count(1)
- FROM
- tede_comment a
- INNER JOIN
- tede_analyze b ON a.Id = b.CommentId
- INNER JOIN
- tede_user c ON c.Id = b.UserId
- INNER JOIN
- tede_user d ON d.Id = a.UserId
- WHERE
- a.TypeValue IN ({AllTypeConst.Topic.GetHashCode()},{AllTypeConst.Notice.GetHashCode()},{AllTypeConst.Note.GetHashCode()},{AllTypeConst.TopicNote.GetHashCode()})
- AND a.UserId ={userId}
- AND b.AnalyzeType = 2
- AND b.IsRead = 0";
- count += await connection.ExecuteScalarAsync<int>(sql);
- //通知
- sql = $@" SELECT
- COUNT(1)
- FROM
- tede_analyze a
- INNER JOIN
- tede_notice 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
- INNER JOIN
- tede_middle e ON e.MiddleId = b.Id
- WHERE
- b.UserId ={userId} AND e.UserId = b.UserId
- AND a.TypeValue ={AllTypeConst.Notice.GetHashCode()}
- AND e.IsDelete = 0
- AND a.CommentId = 0
- AND a.AnalyzeType = 1
- AND a.IsRead = 0
- ";
- count += await connection.ExecuteScalarAsync<int>(sql);
- //小组话题
- sql = $@" SELECT
- count(1)
- FROM
- tede_analyze a
- INNER JOIN
- tede_topic 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
- INNER JOIN
- tede_middle e ON e.MiddleId = b.Id
- INNER JOIN
- tede_group g ON g.Id = b.GroupId
- WHERE
- a.TypeValue = {AllTypeConst.Topic.GetHashCode()} AND e.IsDelete = 0
- AND a.CommentId = 0
- AND e.UserId = b.UserId
- AND a.AnalyzeType = 1
- AND b.UserId ={userId}
- AND a.IsRead = 0
- ";
- count += await connection.ExecuteScalarAsync<int>(sql);
- return count;
- }
- /// <summary>
- /// 修改未读点赞数量
- /// </summary>
- /// <param name="userId"></param>
- /// <returns></returns>
- public async Task<bool> UpdateUReadPraiseAsync(int userId)
- {
- try
- {
- using (var tran = new TransactionScope())
- {
- var intList = new List<int>();
- //话题本/笔记本点赞
- var sql = $@"SELECT
- a.Id
- 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
- INNER JOIN
- tede_middle e ON e.MiddleId = b.Id
- WHERE
- a.TypeValue in({AllTypeConst.Note.GetHashCode()},{AllTypeConst.TopicNote.GetHashCode()}) AND e.IsDelete = 0
- AND a.CommentId = 0
- AND e.UserId = b.UserId
- AND a.AnalyzeType = 1
- AND b.UserId = {userId}
- AND a.IsRead = 0";
- var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
- var connection = database.GetConnection();
- intList.AddRange(await connection.QueryAsync<int>(sql));
- //小组话题 通知 笔记 评论点赞
- sql = $@"
- SELECT
- b.Id
- FROM
- tede_comment a
- INNER JOIN
- tede_analyze b ON a.Id = b.CommentId
- INNER JOIN
- tede_user c ON c.Id = b.UserId
- INNER JOIN
- tede_user d ON d.Id = a.UserId
- WHERE
- a.TypeValue IN ({AllTypeConst.Topic.GetHashCode()},{AllTypeConst.Notice.GetHashCode()},{AllTypeConst.Note.GetHashCode()},{AllTypeConst.TopicNote.GetHashCode()})
- AND a.UserId ={userId}
- AND b.AnalyzeType = 2
- AND b.IsRead = 0";
- intList.AddRange(await connection.QueryAsync<int>(sql));
- //通知点赞
- sql = $@"
- SELECT
- a.Id
- FROM
- tede_analyze a
- INNER JOIN
- tede_notice 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
- INNER JOIN
- tede_middle e ON e.MiddleId = b.Id
- WHERE
- b.UserId ={userId} AND e.UserId = b.UserId
- AND a.TypeValue ={AllTypeConst.Notice.GetHashCode()}
- AND e.IsDelete = 0
- AND a.CommentId = 0
- AND a.AnalyzeType = 1";
- intList.AddRange(await connection.QueryAsync<int>(sql));
- sql = $@"
- SELECT
- a.Id
- FROM
- tede_analyze a
- INNER JOIN
- tede_topic 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
- INNER JOIN
- tede_middle e ON e.MiddleId = b.Id
- INNER JOIN
- tede_group g ON g.Id = b.GroupId
- WHERE
- a.TypeValue = {AllTypeConst.Topic.GetHashCode()} AND e.IsDelete = 0
- AND a.CommentId = 0
- AND e.UserId = b.UserId
- AND a.AnalyzeType = 1
- AND b.UserId ={userId}";
- intList.AddRange(await connection.QueryAsync<int>(sql));
- if (intList.Count() > 0)
- {
- var query = Q.NewQuery();
- query.Set(nameof(Entity.Analyze.Analyze.IsRead), true);
- query.WhereIn(nameof(Entity.Analyze.Analyze.Id), intList);
- var result = await analyzeRepository.UpdateAsync(query);
- }
- tran.Complete();
- }
- }
- catch
- {
- return false;
- }
- return true;
- }
- }
- }
|