lihao 4 years ago
parent
commit
ee0891027e

+ 7 - 1
gx_api/GxPress/Model/GxPress.Entity/GroupUser.cs

@@ -1,5 +1,6 @@
 using GxPress.EnumConst;
 using Datory.Annotations;
+using System;
 
 namespace GxPress.Entity
 {
@@ -32,6 +33,11 @@ namespace GxPress.Entity
         /// </summary>
         [DataColumn]
         public bool IsUDisturb { get; set; }
-
+        /// <summary>
+        /// 用户阅读时间
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public DateTime ReadDate { get; set; }
     }
 }

+ 6 - 7
gx_api/GxPress/Repository/GxPress.Repository.Implement/GroupRepository.cs

@@ -185,16 +185,15 @@ namespace GxPress.Repository.Implement
                                 (SELECT 
                                         COUNT(1)
                                     FROM
-                                        tede_topic_addressee
+                                        tede_topic
                                     WHERE
-                                        TopicId IN (SELECT 
-                                                Id
+                                        groupId = b.Id
+                                            AND LastModifiedDate > (SELECT 
+                                                ReadDate
                                             FROM
-                                                tede_topic
+                                                tede_group_user
                                             WHERE
-                                                GroupId = a.MiddleId)
-                                            AND UserId = {request.UserId}
-                                            AND IsRead = 0) AS UReadTopicCount,
+                                                groupId =  b.Id AND userId = {request.UserId})) AS UReadTopicCount,
                                 (SELECT 
                                         FolderName
                                     FROM

+ 17 - 3
gx_api/GxPress/Repository/GxPress.Repository.Implement/GroupUserRepository.cs

@@ -84,7 +84,7 @@ namespace GxPress.Repository.Implement
         /// <returns></returns>
         public async Task<int> InsertAsync(int userId, int groupId, GroupUserRoleTyeConst groupUserRoleId)
         {
-            GroupUser groupUser = new GroupUser { GroupId = groupId, UserId = userId, GroupUserRoleId = groupUserRoleId, IsUDisturb = false };
+            GroupUser groupUser = new GroupUser { GroupId = groupId, UserId = userId, GroupUserRoleId = groupUserRoleId, IsUDisturb = false, ReadDate = DateTime.Now };
             return await _repository.InsertAsync(groupUser);
         }
 
@@ -120,7 +120,7 @@ namespace GxPress.Repository.Implement
                                                             `GroupId`,
                                                             `UserId`,
                                                             `GroupUserRoleId`,
-                                                            `IsUDisturb`)
+                                                            `IsUDisturb`,`ReadDate`)
                                                             VALUES";
             if (groupUsers.Count == 0)
                 return false;
@@ -129,7 +129,7 @@ namespace GxPress.Repository.Implement
                 var guId = Guid.NewGuid().ToString();
                 var createdDate = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                 var IsUDisturb = item.IsUDisturb ? 1 : 0;
-                sql += $@"('{guId}','{createdDate}','{createdDate}',{item.GroupId},{item.UserId},{item.GroupUserRoleId.GetHashCode()},{IsUDisturb}),";
+                sql += $@"('{guId}','{createdDate}','{createdDate}',{item.GroupId},{item.UserId},{item.GroupUserRoleId.GetHashCode()},{IsUDisturb},'{createdDate}'),";
             }
             sql = sql.Remove(sql.Length - 1, 1);
             var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
@@ -208,5 +208,19 @@ namespace GxPress.Repository.Implement
             query.Where(nameof(Entity.GroupUser.UserId), userId);
             return await _repository.ExistsAsync(query);
         }
+        /// <summary>
+        /// 修改用户阅读时间
+        /// </summary>
+        /// <param name="userId"></param>
+        /// <param name="groupId"></param>
+        /// <returns></returns>
+        public async Task<bool> UpdateGroupUserReadDateAsync(int userId, int groupId)
+        {
+            var query = Q.NewQuery();
+            query.Where(nameof(Entity.GroupUser.GroupId), groupId);
+            query.Where(nameof(Entity.GroupUser.UserId), userId);
+            query.Set(nameof(Entity.GroupUser.ReadDate), DateTime.Now.ToString());
+            return await _repository.UpdateAsync(query) > 0;
+        }
     }
 }

+ 2 - 2
gx_api/GxPress/Repository/GxPress.Repository.Implement/RecordFolder/RecordFolderRepository.cs

@@ -78,8 +78,8 @@ namespace GxPress.Repository.Implement.RecordFolder
             query.Where(nameof(Entity.RecordFolder.RecordFolder.FolderId), folderId);
             var recordFolder = await _repository.GetAsync(query);
             var middle = await _middleRepository.GetAsync(folderId);
-            if (middle == null)
-                return true;
+            // if (middle == null)
+            //     return true;
             // if (middle.RoleId == 2)
             //     throw new Common.Exceptions.BusinessException("文件夹私有");
             if (recordFolder == null)

+ 3 - 6
gx_api/GxPress/Repository/GxPress.Repository.Implement/TopicRepository.cs

@@ -474,7 +474,7 @@ namespace GxPress.Repository.Implement
                             WHERE
                                 a.GroupId > 0 
                                     {sqlStr}
-                            ORDER BY a.CreatedDate DESC limit @page,@pageSize";
+                            ORDER BY a.CreatedDate DESC limit {(request.Page - 1) * request.PerPage},{request.Page * request.PerPage}";
             string countSql = $@"SELECT 
                                 count(1)
                             FROM
@@ -485,14 +485,11 @@ namespace GxPress.Repository.Implement
                                 tede_user c ON c.Id = a.UserId
                             WHERE
                                 a.GroupId > 0  
-                                   {sqlStr}
-                            ORDER BY a.CreatedDate DESC";
+                                   {sqlStr}";
             var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
             var database = new Database(databaseType, _connectionString);
             var connection = database.GetConnection();
-            result.Items =
-                 await connection
-                      .QueryAsync<TopicListPageResult>(sql, new { page = (request.Page - 1) * request.PerPage, pageSize = request.PerPage });
+            result.Items = await connection.QueryAsync<TopicListPageResult>(sql);
             foreach (var item in result.Items)
             {
                 item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);

+ 1 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/IGroupUserRepository.cs

@@ -59,5 +59,6 @@ namespace GxPress.Repository.Interface
         /// <param name="groupId"></param>
         /// <returns></returns>
         Task<bool> ExistsAsync(int userId, int groupId);
+        Task<bool> UpdateGroupUserReadDateAsync(int userId, int groupId);
     }
 }

+ 1 - 1
gx_api/GxPress/Service/GxPress.Service.Implement/Group/GroupService.cs

@@ -147,7 +147,7 @@ namespace GxPress.Service.Implement.Group
                 Code = 200,
                 Success = true,
                 Msg = "",
-                Data=null
+                Data = null
             };
             request.UserIds = request.UserIds.Distinct().ToList();
             //获取当前小组

+ 4 - 0
gx_api/GxPress/Service/GxPress.Service.Implement/Topic/TopicService.cs

@@ -118,7 +118,11 @@ namespace GxPress.Service.Implement.Topic
                 result = await _topicRepository.GetGroupTopicPageAsync(request);
             //判断是否小组成员
             if (request.GroupIds.Count == 1)
+            {
                 result.IsUser = await _groupUserRepository.ExistsAsync(request.UserId, request.GroupIds[0]);
+                //修改用户阅读小组
+                await _groupUserRepository.UpdateGroupUserReadDateAsync(request.UserId, request.GroupIds[0]);
+            }
             //获取数量
             // result.Total = 10;
             foreach (var item in result.Items)