李昊 4 anni fa
parent
commit
f3281ad2a0

+ 199 - 0
gx_api/GxPress/Api/GxPress.Api/WebControllers/WebGroupChatController.cs

@@ -0,0 +1,199 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using GxPress.Auth;
+using GxPress.Entity;
+using GxPress.Repository.Interface;
+using GxPress.Request.App.IM;
+using GxPress.Request.GroupChat;
+using GxPress.Result.App.GroupChat;
+using GxPress.Service.Interface;
+using GxPress.Service.Interface.AdminVerify;
+using GxPress.Service.Interface.IM;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+
+namespace GxPress.Api.AppControllers
+{
+    /// <summary>
+    /// 群
+    /// </summary>
+    [Route("api/web/group-chat")]
+    [ApiController]
+    [Authorize]
+    public class WebGroupChatController : ControllerBase
+    {
+        private readonly IGroupChatRepository _groupChatRepository;
+        private readonly IGroupChatUserRepository _groupChatUserRepository;
+        private readonly IIMService _imService;
+        private readonly ILoginContext _loginContext;
+        private readonly IAdminVerifyService _adminVerifyService;
+        private readonly IGroupChatUserService _groupChatUserService;
+
+        public WebGroupChatController(IGroupChatRepository groupChatRepository, ILoginContext loginContext,
+            IIMService imService, IAdminVerifyService adminVerifyService,
+            IGroupChatUserRepository groupChatUserRepository, IGroupChatUserService groupChatUserService)
+        {
+            _groupChatRepository = groupChatRepository;
+            _imService = imService;
+            _loginContext = loginContext;
+            _adminVerifyService = adminVerifyService;
+            _groupChatUserRepository = groupChatUserRepository;
+            _groupChatUserService = groupChatUserService;
+        }
+        ///// <summary>
+        ///// 添加
+        ///// </summary>
+        ///// <param name="request"></param>
+        ///// <returns></returns>
+        //[HttpPost("add")]
+        //public async Task<bool> Insert(GroupChatInRequest request)
+        //{
+        //    request.UserId = _loginContext.AccountId;
+        //    return await _groupChatRepository.InsertAsync(request);
+        //}
+
+        /// <summary>
+        /// 修改
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("update")]
+        public async Task<bool> Update(GroupChatUpRequest request)
+        {
+            return await _groupChatRepository.UpdateAsync(request);
+        }
+
+        /// <summary>
+        /// 群组解散群
+        /// </summary>
+        /// <param name="groupChatImId"></param>
+        /// <returns></returns>
+        [HttpDelete("{groupChatImId}")]
+        public async Task<bool> DeleteGroupChat(string groupChatImId)
+        {
+            return await _imService.DeleteGroupChatAsync(groupChatImId, _loginContext.AccountId);
+        }
+        /// <summary>
+        /// 根据UserId查询群
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost("group-chat-search")]
+        public async Task<IEnumerable<GroupChat>> GetGroupChatByUserId()
+        {
+            var request = new GroupChatSearchRequest { UserId = _loginContext.AccountId };
+            return await _groupChatRepository.GetGroupChatByUserIdAsync(request);
+        }
+
+        /// <summary>
+        /// 是否管理员同意
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("up-is-admin")]
+        public async Task<bool> UpIsAdmin(GroupChatUpIsAdminRequest request)
+        {
+            return await _groupChatRepository.UpIsAdminAsync(request);
+        }
+
+        /// <summary>
+        /// 创建群
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("add")]
+        public async Task<GroupChatInfoResult> CreateGroupChat(GroupChatInRequest request)
+        {
+            request.UserId = _loginContext.AccountId;
+            //添加群成员
+            var insertGroupChatUsersRequest = new InsertGroupChatUsersRequest();
+            insertGroupChatUsersRequest.UserId = request.UserId;
+            insertGroupChatUsersRequest.UserIds = request.UserIds;
+            insertGroupChatUsersRequest.SourceType = 2;
+            //创建群
+            var result = await _imService.CreateGroupChatAsync(request);
+            if (result.Success)
+            {
+                insertGroupChatUsersRequest.GroupChatImId = result.GroupChatImId;
+                insertGroupChatUsersRequest.IsFound = true;
+                await _groupChatUserService.InsertAsync(insertGroupChatUsersRequest);
+                //获取群信息
+                return await _groupChatRepository.GetGroupChatInfoByImIdAsync(result.GroupChatImId);
+            }
+            return new GroupChatInfoResult();
+        }
+
+        /// <summary>
+        /// 添加群用户
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("add-users")]
+        public async Task<bool> InsertGroupChatUsers(InsertGroupChatUsersRequest request)
+        {
+            request.UserId = _loginContext.AccountId;
+            return await _groupChatUserService.InsertAsync(request);
+        }
+
+        /// <summary>
+        /// 群删除成员
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("remove-users")]
+        public async Task<bool> RemoveGroupChatUsers(InsertGroupChatUsersRequest request)
+        {
+            request.UserId = _loginContext.AccountId;
+            return await _imService.RemoveGroupChatUsersAsync(request);
+        }
+        /// <summary>
+        /// 禁言
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("in-mute")]
+        public async Task<bool> InMute(SetGroupChatMuteRequest request)
+        {
+            return await _imService.InMute(request.GroupChatImId);
+        }
+        /// <summary>
+        /// 解除禁言
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("remove-mute")]
+        public async Task<bool> RemoveMute(SetGroupChatMuteRequest request)
+        {
+            return await _imService.RemoveMute(request.GroupChatImId);
+        }
+        /// <summary>
+        /// 根据groupChatGuid获取群信息
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("guid")]
+        public async Task<GroupChat> GetGroupChatByGuid(GroupChatByGuidRequest request)
+        {
+            return await _groupChatRepository.GetGroupChatByGuidAsync(request.GroupChatGuid);
+        }
+
+        /// <summary>
+        /// set群是否开启
+        /// </summary>
+        /// <param name="groupChatImId"></param>
+        /// <returns></returns>
+        [HttpPut("{groupChatImId}")]
+        public async Task<bool> SetIsOpenQrCoder(string groupChatImId)
+        {
+            return await _groupChatRepository.SetIsOpenQrCoderAsync(groupChatImId, _loginContext.AccountId);
+        }
+        /// <summary>
+        /// 获取用户加入的群
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet("list")]
+        public async Task<IEnumerable<GroupChat>> GetGroupChatsAsync()
+        {
+            return await _groupChatRepository.GetGroupChatsAsync(_loginContext.AccountId);
+        }
+    }
+}

+ 26 - 2
gx_api/GxPress/Repository/GxPress.Repository.Implement/UserRepository.cs

@@ -1041,7 +1041,31 @@ namespace GxPress.Repository.Implement
                 item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
             return result;
         }
-
-
+        /// <summary>
+        /// 获取用户工作我的审批未读数量
+        /// </summary>
+        /// <param name="userId"></param>
+        /// <returns></returns>
+        public async Task<int> GetUserUReadFlowTodoCountAsync(int userId)
+        {
+            string sql = $@"SELECT 
+                            count(1)
+                        FROM
+                            tede_flow_todo
+                        WHERE
+                            FlowId IN (SELECT 
+                                    SonId
+                                FROM
+                                    tede_notice
+                                WHERE
+                                    userId ={userId} AND TypeValue = 15
+                                        AND IsDelete = 0)
+                                AND Type = 'ApproverCheck' and IsRead=0";
+            var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
+            var database = new Database(databaseType, _connectionString);
+            var connection = database.GetConnection();
+            var result = await connection.ExecuteScalarAsync<int>(sql);
+            return result;
+        }
     }
 }

+ 7 - 1
gx_api/GxPress/Repository/GxPress.Repository.Interface/IUserRepository.cs

@@ -248,7 +248,7 @@ namespace GxPress.Repository.Interface
         /// </summary>
         /// <param name="userIds"></param>
         /// <returns></returns>
-        Task<IEnumerable<UserInfoResult>> GetUserInfoResultsAsync(IEnumerable<int> userIds,string keyWord="");
+        Task<IEnumerable<UserInfoResult>> GetUserInfoResultsAsync(IEnumerable<int> userIds, string keyWord = "");
         /// <summary>
         /// 获取不是好友的用户 排除部门
         /// </summary>
@@ -263,5 +263,11 @@ namespace GxPress.Repository.Interface
         /// <param name="userIds"></param>
         /// <returns></returns>
         Task<IEnumerable<UserInfoResult>> GetSearchUserInfoResults(string keyword, IEnumerable<int> userIds);
+        /// <summary>
+        /// 获取用户工作我的审批未读数量
+        /// </summary>
+        /// <param name="userId"></param>
+        /// <returns></returns>
+        Task<int> GetUserUReadFlowTodoCountAsync(int userId);
     }
 }

+ 2 - 0
gx_api/GxPress/Service/GxPress.Service.Implement/Middle/MiddleService.cs

@@ -386,7 +386,9 @@ namespace GxPress.Service.Implement.Middle
                     await _groupRepository.DeleteAsync(Q.WhereIn(nameof(Entity.Group.Id), ids));
                 //删除收件箱
                 if (request.FolderType == AllTypeConst.Inbox.GetHashCode())
+                {
                     await _addresseeRepository.UpdateAsync(Q.Where(nameof(Entity.Addressee.UserId), request.UserId).WhereIn(nameof(Entity.Addressee.SourceId), ids).Set(nameof(Entity.Addressee.IsDelete), true).Set(nameof(Entity.Addressee.IsRead), true));
+                }
                 if (request.FolderType == AllTypeConst.Inbox.GetHashCode())
                 {
                     foreach (var item in middles)

+ 2 - 1
gx_api/GxPress/Service/GxPress.Service.Implement/UserService.cs

@@ -353,7 +353,8 @@ namespace GxPress.Service.Implement
             var result = await _userRepository.GetUserCountAsync(userId);
             //工作我的审批未操作数量
             var request = new FlowListRequest();
-            result.FlowAuditUReadCount = await _flowTodoRepository.CountAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.UserId), userId).Where(nameof(Entity.WorkFlow.FlowTodo.Type), "ApproverCheck").Where(nameof(Entity.WorkFlow.FlowTodo.IsRead), false));
+            // result.FlowAuditUReadCount = await _flowTodoRepository.CountAsync(Q.Where(nameof(Entity.WorkFlow.FlowTodo.UserId), userId).Where(nameof(Entity.WorkFlow.FlowTodo.Type), "ApproverCheck").Where(nameof(Entity.WorkFlow.FlowTodo.IsRead), false));
+            result.FlowAuditUReadCount = await _userRepository.GetUserUReadFlowTodoCountAsync(userId);
             // 工作我发起的已批复未读数量
             // var flowState = new List<string> { FlowState.Checked.GetValue(), FlowState.Denied.GetValue() };
             // result.FlowSendUReadCount = await _flowRepository.CountAsync(Q.Where(nameof(Entity.WorkFlow.Flow.UserId), userId).WhereIn(nameof(Entity.WorkFlow.Flow.State), flowState).Where(nameof(Entity.WorkFlow.Flow.IsRead), false).Where(nameof(Entity.WorkFlow.Flow.ProcessId), ">", 0));