Browse Source

Merge branch 'develop' of http://132.232.92.186:3000/XinXiBu/OA2023 into develop

LEIYI 4 months ago
parent
commit
2bd6c88fa9

+ 101 - 0
OASystem/OASystem.Api/Controllers/AuthController.cs

@@ -152,6 +152,107 @@ namespace OASystem.API.Controllers
             return Ok(JsonView(view));
         }
 
+
+        /// <summary>
+        /// 移动端用户登录
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [Route("MobileLogin")]
+        [HttpPost]
+        [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> MobileLoginAsync(LoginDto dto)
+        {
+            if (string.IsNullOrWhiteSpace(dto.Number) || string.IsNullOrWhiteSpace(dto.Password))
+            {
+                return Ok(JsonView(false, "账号或密码不能为空!!"));
+            }
+
+            #region 校验用户信息 
+            var userData = _loginRep.Login(dto).Result;
+            if (userData.Code != 0) return Ok(JsonView(false, userData.Msg));
+
+            #endregion
+            Result authData = null;
+            string uName = string.Empty;
+            string role = string.Empty;
+            int uId = 0;
+            int unReadCount = 0;
+            int announcementUnReadCount = 0;
+            if (userData.Data != null)
+            {
+                uId = (userData.Data as UserLoginInfoView).UserId;
+                uName = (userData.Data as UserLoginInfoView).CnName;
+                role = (userData.Data as UserLoginInfoView).JobName;
+                authData = _SystemMenuPermissionRepository.MobileMenuLoad(uId, dto.PortType);
+                unReadCount = await _messageRep.GetUnReadCount(uId);
+                announcementUnReadCount = await _messageRep.GetAnnouncementUnReadCount(uId);
+            }
+
+            //_hubContext.Login(uId, uName);
+            var view = new LoginView
+            {
+                UserInfo = userData == null ? null : userData.Data,
+                AuthData = authData == null ? null : authData.Data,
+                UnReadCount = unReadCount,
+                AnnouncementUnReadCount = announcementUnReadCount
+            };
+
+
+            DateTime createZebraTime = DateTime.Now;
+            string authorId = dto.Number + "Token";
+            string authorToken = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>(authorId);//string 取
+            if (authorToken != null)
+            {
+                #region 解析出过期时间
+                var jwtHandler = new JwtSecurityTokenHandler();
+                JwtSecurityToken securityToken = jwtHandler.ReadJwtToken(authorToken);
+                DateTime expDt = (securityToken.Payload[JwtRegisteredClaimNames.Exp] ?? 0).GetInt().GetTimeSpmpToDate();
+                #endregion
+
+                if (expDt >= createZebraTime)  //超时重新获取token
+                {
+                    authorToken = await JwtHelper.IssueJwtAsync(new TokenModelJwt() { UserId = uId, UserName = uName, Role = role }); //
+                }
+
+                view.Expires = expDt;
+                view.Token = authorToken;
+            }
+            else
+            {
+                view.Expires = createZebraTime.AddMinutes(30);
+                //view.Token = await GeneralMethod.GetToken(_config, dto.Number, uId, uName, createZebraTime); //JwtHelper
+                view.Token = await JwtHelper.IssueJwtAsync(new TokenModelJwt() { UserId = uId, UserName = uName, Role = role }); //
+                TimeSpan ts = view.Expires.AddMinutes(-1) - createZebraTime; //设置redis 过期时间 比 jwt 时间 快一分钟
+                await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>(authorId, view.Token, ts);//string 存
+            }
+
+            //#region 添加登录用户上线信息
+            //_hubContext.SignalRLogin(uId);
+            //#endregion
+
+            #region 测试添加系统消息
+
+            //await _message.AddMsg(new MessageDto()
+            //{
+            //    Type = 1,
+            //    IssuerId = 208,
+            //    Title = "测试添加消息标题",
+            //    Content = "消息体测试",
+            //    ReleaseTime = DateTime.Now,
+            //    UIdList = new List<int> {
+            //        5,
+            //        208,
+            //        219
+            //    }
+            //});
+
+            #endregion
+
+            return Ok(JsonView(view));
+        }
+
+
         /// <summary>
         /// 申请注册 数据Data
         /// </summary>

+ 1 - 0
OASystem/OASystem.Api/Controllers/SystemController.cs

@@ -1879,6 +1879,7 @@ And u.UId = {0} And u.FId = 1 ", dto.UserId);
             _JobPostAuthorityRepository.CommitTran();
             return Ok(JsonView(200, "成功", new { }));
         }
+
         #endregion
 
         #region 页面配置

+ 78 - 0
OASystem/OASystem.Infrastructure/Repositories/System/SystemMenuPermissionRepository.cs

@@ -179,6 +179,84 @@ namespace OASystem.Infrastructure.Repositories.System
             return result;
         }
 
+        public Result MobileMenuLoad(int uid, int PortType)
+        {
+            Result result = new Result();
+            result.Data = new string[0];
+
+            if (uid != 0)
+            {
+                List<MenuLoadView> DBData = new List<MenuLoadView>();
+                string sql = $@"
+                     select a.UId,a.SmId,b.Id as Funid,b.FunctionName,b.FunctionCode,c.Id as modulid,
+                      c.Name as modulName,c.STid,d.Id as pageid ,d.Name as PageName,d.SystemMenuCode,d.webUrl,d.AndroidUrl,d.icon,
+                      d.IosUrl
+                      from Sys_UserAuthority a inner join Sys_PageFunctionPermission b on a.FId = b.Id 
+                      inner join Sys_SystemMenuPermission d on a.SmId = d.Id inner join Sys_SetData c on c.Id = d.Mid
+                      where uid = {uid} and a.IsDel= 0  and b.IsDel = 0 
+                      and b.IsEnable = 1 and c.IsDel = 0 and d.IsDel = 0   ";
+
+                if (PortType == 1)
+                {
+                    //只返回查看权限
+                    //sql += $@" and b.Id = 1 and d.IsEnable = 1  group by 
+                    //  a.UId,a.SmId,b.Id,b.FunctionName,b.FunctionCode,c.Id,
+                    //  c.Name,c.STid,d.Id,d.Name,d.SystemMenuCode,d.webUrl,d.AndroidUrl,d.icon,
+                    //  d.IosUrl";
+
+                    //返回所有权限
+                    sql += $@" and d.IsEnable = 1 group by 
+                      a.UId,a.SmId,b.Id,b.FunctionName,b.FunctionCode,c.Id,
+                      c.Name,c.STid,d.Id,d.Name,d.SystemMenuCode,d.webUrl,d.AndroidUrl,d.icon,
+                      d.IosUrl";
+                    DBData = _sqlSugar.SqlQueryable<MenuLoadView>(sql).ToList();
+                }
+                else if (PortType == 2)
+                {
+                    sql += $@" and d.phoneIsEnable = 1 group by 
+                      a.UId,a.SmId,b.Id,b.FunctionName,b.FunctionCode,c.Id,
+                      c.Name,c.STid,d.Id,d.Name,d.SystemMenuCode,d.webUrl,d.AndroidUrl,d.icon,
+                      d.IosUrl ";
+                    DBData = _sqlSugar.SqlQueryable<MenuLoadView>(sql).ToList();
+                }
+
+                result.Code = -1;
+                result.Msg = "暂无数据!";
+
+                if (DBData.Count > 0)
+                {
+                    result.Code = 0;
+                    result.Msg = "成功!";
+                    var arr = new ArrayList();
 
+                    var modelGroup = DBData.GroupBy(x => x.modulid);
+                    foreach (var item in modelGroup)
+                    {
+                        var modelData = new
+                        {
+                            modelId = item.Key,
+                            modelName = item.First().modulName,
+                            PageList = new ArrayList(),
+                        };
+
+                        var pageGroup = item.GroupBy(x => x.pageid);
+                        foreach (var page in pageGroup)
+                        {
+                            modelData.PageList.Add(new
+                            {
+                                pageId = page.Key,
+                                opList = page.Select(x => x.Funid)
+                            }) ;
+                        }
+
+                        arr.Add(modelData);
+                    }
+
+                    result.Data = arr;
+                }
+
+            }
+            return result;
+        }
     }
 }