去掉用户管理里的trycatch
This commit is contained in:
		
							parent
							
								
									27732189fd
								
							
						
					
					
						commit
						5297e85067
					
				| 
						 | 
				
			
			@ -72,7 +72,7 @@ namespace langguanApi.Service
 | 
			
		|||
        /// <returns></returns>
 | 
			
		||||
        public async Task<List<MenuTreeDto>> GetChildList(string parentId)
 | 
			
		||||
        {
 | 
			
		||||
            Expression<Func<Menu, bool>> exp = filter => filter.IsDelete == false&& filter.ParentId == parentId;
 | 
			
		||||
            Expression<Func<Menu, bool>> exp = filter => filter.IsDelete == false && filter.ParentId == parentId;
 | 
			
		||||
            var list = (await GetListWithExp(exp))
 | 
			
		||||
                .OrderBy(x => x.Sort)
 | 
			
		||||
                .ToList().Adapt<List<MenuTreeDto>>();
 | 
			
		||||
| 
						 | 
				
			
			@ -93,30 +93,13 @@ namespace langguanApi.Service
 | 
			
		|||
        /// <returns></returns>
 | 
			
		||||
        public async Task<ApiResult> DeleteMenu(string id)
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            var entity = await base.GetAsync(id);
 | 
			
		||||
            if (entity == null)
 | 
			
		||||
            {
 | 
			
		||||
                var entity = await base.GetAsync(id);
 | 
			
		||||
                if (entity == null)
 | 
			
		||||
                {
 | 
			
		||||
                    return new ApiResult() { code = 0, data = false, msg = "删除菜单失败,Id不存在" };
 | 
			
		||||
                }
 | 
			
		||||
                entity.IsDelete = true;
 | 
			
		||||
                await base.UpdateAsync(id, entity);
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
            {
 | 
			
		||||
 | 
			
		||||
                _logger.LogError($"删除菜单出现异常,请求参数:{Newtonsoft.Json.JsonConvert.SerializeObject(id)}," +
 | 
			
		||||
                                $"请求接口:'api/Menu/DeleteMenu'," +
 | 
			
		||||
                                $"异常信息:{ex.Message}," +
 | 
			
		||||
                                $"异常位置:{ex.StackTrace}"
 | 
			
		||||
                                );
 | 
			
		||||
                return new ApiResult { code = 1, msg = "删除菜单失败", data = false };
 | 
			
		||||
            }
 | 
			
		||||
            finally
 | 
			
		||||
            {
 | 
			
		||||
                _logger.LogInformation($"删除菜单参数:menuId:{id}");
 | 
			
		||||
                return new ApiResult() { code = 0, data = false, msg = "删除菜单失败,Id不存在" };
 | 
			
		||||
            }
 | 
			
		||||
            entity.IsDelete = true;
 | 
			
		||||
            await base.UpdateAsync(id, entity);
 | 
			
		||||
            return new ApiResult() { code = 0, data = true, msg = "删除菜单成功" };
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -118,55 +118,40 @@ namespace langguanApi.Service
 | 
			
		|||
        public async Task<ApiResult> GetUserList(UserQueryDto input)
 | 
			
		||||
        {
 | 
			
		||||
            List<UserDetailDto> list = new List<UserDetailDto>();
 | 
			
		||||
            try
 | 
			
		||||
 | 
			
		||||
            #region 组织查询条件
 | 
			
		||||
            Expression<Func<UserEntity, bool>> exp = filter => filter.IsDelete == false;
 | 
			
		||||
            if (!string.IsNullOrEmpty(input.key))
 | 
			
		||||
            {
 | 
			
		||||
                #region 组织查询条件
 | 
			
		||||
                Expression<Func<UserEntity, bool>> exp = filter => filter.IsDelete == false;
 | 
			
		||||
                if (!string.IsNullOrEmpty(input.key))
 | 
			
		||||
                {
 | 
			
		||||
                    exp = filter => filter.Username.Contains(input.key) || filter.Phone.Contains(input.key) || filter.Email.Contains(input.key);
 | 
			
		||||
                }
 | 
			
		||||
                #endregion
 | 
			
		||||
                #region 获取数据
 | 
			
		||||
                var result = await base.GetListWithExp(exp);//获取人员信息
 | 
			
		||||
                if (result.Count() > 0)
 | 
			
		||||
                {
 | 
			
		||||
                    result = result.Skip((input.PageIndex - 1) * input.PageSize).Take(input.PageSize);
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    return new ApiResult { code = 0, data = null, msg = "没有用户信息" };
 | 
			
		||||
                }
 | 
			
		||||
                var roleList = await _roleService.GetRoleListByIds(result.Select(s => s.RoleId).ToList());//根据角色Id获取角色信息
 | 
			
		||||
                #endregion
 | 
			
		||||
                #region 组装返回数据
 | 
			
		||||
                foreach (var item in result)
 | 
			
		||||
                {
 | 
			
		||||
                    list.Add(new UserDetailDto
 | 
			
		||||
                    {
 | 
			
		||||
                        UserId = item.Id,
 | 
			
		||||
                        Username = item.Username,
 | 
			
		||||
                        Email = item.Email,
 | 
			
		||||
                        RoleId = item.RoleId,
 | 
			
		||||
                        RoleName = roleList.FirstOrDefault(s => s.Id == item.RoleId)?.RoleName,
 | 
			
		||||
                        Tel = item.Phone,
 | 
			
		||||
                    });
 | 
			
		||||
                }
 | 
			
		||||
                #endregion
 | 
			
		||||
                exp = filter => filter.Username.Contains(input.key) || filter.Phone.Contains(input.key) || filter.Email.Contains(input.key);
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
            #endregion
 | 
			
		||||
            #region 获取数据
 | 
			
		||||
            var result = await base.GetListWithExp(exp);//获取人员信息
 | 
			
		||||
            if (result.Count() > 0)
 | 
			
		||||
            {
 | 
			
		||||
                _logger.LogError($"获取用户列表出现异常,请求参数:userQuery:{Newtonsoft.Json.JsonConvert.SerializeObject(input)}," +
 | 
			
		||||
                                 $"请求接口:'api/User/GetUserList'," +
 | 
			
		||||
                                 $"异常信息:{ex.Message}," +
 | 
			
		||||
                                 $"异常位置:{ex.StackTrace}"
 | 
			
		||||
                                 );
 | 
			
		||||
                return new ApiResult { code = 1, msg = "获取用户列表失败" };
 | 
			
		||||
                result = result.Skip((input.PageIndex - 1) * input.PageSize).Take(input.PageSize);
 | 
			
		||||
            }
 | 
			
		||||
            finally
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                _logger.LogInformation($"获取用户列表参数:userQuery:{Newtonsoft.Json.JsonConvert.SerializeObject(input)}");
 | 
			
		||||
                return new ApiResult { code = 0, data = null, msg = "没有用户信息" };
 | 
			
		||||
            }
 | 
			
		||||
            var roleList = await _roleService.GetRoleListByIds(result.Select(s => s.RoleId).ToList());//根据角色Id获取角色信息
 | 
			
		||||
            #endregion
 | 
			
		||||
            #region 组装返回数据
 | 
			
		||||
            foreach (var item in result)
 | 
			
		||||
            {
 | 
			
		||||
                list.Add(new UserDetailDto
 | 
			
		||||
                {
 | 
			
		||||
                    UserId = item.Id,
 | 
			
		||||
                    Username = item.Username,
 | 
			
		||||
                    Email = item.Email,
 | 
			
		||||
                    RoleId = item.RoleId,
 | 
			
		||||
                    RoleName = roleList.FirstOrDefault(s => s.Id == item.RoleId)?.RoleName,
 | 
			
		||||
                    Tel = item.Phone,
 | 
			
		||||
                });
 | 
			
		||||
            }
 | 
			
		||||
            #endregion
 | 
			
		||||
            return new ApiResult { code = 0, data = list, msg = "获取信息成功" };
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -178,51 +163,36 @@ namespace langguanApi.Service
 | 
			
		|||
        public async Task<ApiResult> GetUserById(string userId)
 | 
			
		||||
        {
 | 
			
		||||
            UserDetailDto userDetail = null;
 | 
			
		||||
            try
 | 
			
		||||
 | 
			
		||||
            #region 校验数据
 | 
			
		||||
            if (string.IsNullOrEmpty(userId))
 | 
			
		||||
            {
 | 
			
		||||
                #region 校验数据
 | 
			
		||||
                if (string.IsNullOrEmpty(userId))
 | 
			
		||||
                {
 | 
			
		||||
                    return new ApiResult { code = 1, msg = "获取用户信息失败,userId非空" };
 | 
			
		||||
                }
 | 
			
		||||
                #endregion
 | 
			
		||||
                #region 获取数据
 | 
			
		||||
                var user = await base.GetAsync(userId);//根据userId获取用户信息
 | 
			
		||||
                if (user == null)
 | 
			
		||||
                {
 | 
			
		||||
                    return new ApiResult { code = 1, msg = "用户不存在" };
 | 
			
		||||
                }
 | 
			
		||||
                var role = await _roleService.GetRoleById(user.RoleId);//根据角色Id获取角色信息
 | 
			
		||||
                if (role == null)
 | 
			
		||||
                {
 | 
			
		||||
                    return new ApiResult { code = 1, msg = "角色不存在" };
 | 
			
		||||
                }
 | 
			
		||||
                #endregion
 | 
			
		||||
                #region 组织需要展示的数据
 | 
			
		||||
                userDetail = new UserDetailDto
 | 
			
		||||
                {
 | 
			
		||||
                    UserId = user.Id,
 | 
			
		||||
                    Username = user.Username,
 | 
			
		||||
                    Email = user.Email,
 | 
			
		||||
                    RoleId = user.RoleId,
 | 
			
		||||
                    RoleName = role.RoleName,
 | 
			
		||||
                    Tel = user.Phone
 | 
			
		||||
                };
 | 
			
		||||
                #endregion
 | 
			
		||||
                return new ApiResult { code = 1, msg = "获取用户信息失败,userId非空" };
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
            #endregion
 | 
			
		||||
            #region 获取数据
 | 
			
		||||
            var user = await base.GetAsync(userId);//根据userId获取用户信息
 | 
			
		||||
            if (user == null)
 | 
			
		||||
            {
 | 
			
		||||
                _logger.LogError($"获取用户信息出现异常,请求参数:userId:{userId}," +
 | 
			
		||||
                $"请求接口:'api/User/GetUserById'," +
 | 
			
		||||
                $"异常信息:{ex.Message}," +
 | 
			
		||||
                $"异常位置:{ex.StackTrace}"
 | 
			
		||||
                );
 | 
			
		||||
                return new ApiResult { code = 1, msg = "获取用户信息失败" };
 | 
			
		||||
                return new ApiResult { code = 1, msg = "用户不存在" };
 | 
			
		||||
            }
 | 
			
		||||
            finally
 | 
			
		||||
            var role = await _roleService.GetRoleById(user.RoleId);//根据角色Id获取角色信息
 | 
			
		||||
            if (role == null)
 | 
			
		||||
            {
 | 
			
		||||
                _logger.LogInformation($"获取用户信息参数:userId:{userId}");
 | 
			
		||||
                return new ApiResult { code = 1, msg = "角色不存在" };
 | 
			
		||||
            }
 | 
			
		||||
            #endregion
 | 
			
		||||
            #region 组织需要展示的数据
 | 
			
		||||
            userDetail = new UserDetailDto
 | 
			
		||||
            {
 | 
			
		||||
                UserId = user.Id,
 | 
			
		||||
                Username = user.Username,
 | 
			
		||||
                Email = user.Email,
 | 
			
		||||
                RoleId = user.RoleId,
 | 
			
		||||
                RoleName = role.RoleName,
 | 
			
		||||
                Tel = user.Phone
 | 
			
		||||
            };
 | 
			
		||||
            #endregion
 | 
			
		||||
            return new ApiResult { code = 0, data = userDetail };
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -230,55 +200,40 @@ namespace langguanApi.Service
 | 
			
		|||
        //更新用户信息方法
 | 
			
		||||
        public async Task<ApiResult> UpdateUser(UserDto input)
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
 | 
			
		||||
            #region 校验参数
 | 
			
		||||
            if (string.IsNullOrEmpty(input.Id))
 | 
			
		||||
            {
 | 
			
		||||
                #region 校验参数
 | 
			
		||||
                if (string.IsNullOrEmpty(input.Id))
 | 
			
		||||
                {
 | 
			
		||||
                    return new ApiResult { code = 1, msg = "用户Id不能为空" };
 | 
			
		||||
                }
 | 
			
		||||
                if (string.IsNullOrEmpty(input.Username))
 | 
			
		||||
                {
 | 
			
		||||
                    return new ApiResult { code = 1, msg = "用户名不能为空" };
 | 
			
		||||
                }
 | 
			
		||||
                if (string.IsNullOrEmpty(input.Tel))
 | 
			
		||||
                {
 | 
			
		||||
                    return new ApiResult { code = 1, msg = "手机号不能为空" };
 | 
			
		||||
                }
 | 
			
		||||
                if (string.IsNullOrEmpty(input.Email))
 | 
			
		||||
                {
 | 
			
		||||
                    return new ApiResult { code = 1, msg = "邮箱不能为空" };
 | 
			
		||||
                }
 | 
			
		||||
                if (string.IsNullOrEmpty(input.RoleId))
 | 
			
		||||
                {
 | 
			
		||||
                    return new ApiResult { code = 1, msg = "角色不能为空" };
 | 
			
		||||
                }
 | 
			
		||||
                #endregion
 | 
			
		||||
                #region 组织数据
 | 
			
		||||
                var userEntity = input.Adapt<UserEntity>();
 | 
			
		||||
                userEntity.Phone = input.Tel;
 | 
			
		||||
                if (!string.IsNullOrEmpty(input.Password))
 | 
			
		||||
                {
 | 
			
		||||
                    userEntity.Password = StringHelper.MD5Encrypt32(input.Password);
 | 
			
		||||
                }
 | 
			
		||||
                #endregion
 | 
			
		||||
                #region 更新数据
 | 
			
		||||
                await base.UpdateAsync(input.Id, userEntity);//更新用户信息
 | 
			
		||||
                #endregion
 | 
			
		||||
                return new ApiResult { code = 1, msg = "用户Id不能为空" };
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
            if (string.IsNullOrEmpty(input.Username))
 | 
			
		||||
            {
 | 
			
		||||
                _logger.LogError($"更新用户信息出现异常,请求参数:user:{Newtonsoft.Json.JsonConvert.SerializeObject(input)}," +
 | 
			
		||||
                                 $"请求接口:'api/User/UpdateUser'," +
 | 
			
		||||
                                 $"异常信息:{ex.Message}," +
 | 
			
		||||
                                 $"异常位置:{ex.StackTrace}"
 | 
			
		||||
                                 );
 | 
			
		||||
                return new ApiResult { code = 1, msg = "更新用户信息失败" };
 | 
			
		||||
                return new ApiResult { code = 1, msg = "用户名不能为空" };
 | 
			
		||||
            }
 | 
			
		||||
            finally
 | 
			
		||||
            if (string.IsNullOrEmpty(input.Tel))
 | 
			
		||||
            {
 | 
			
		||||
                _logger.LogInformation($"更新用户信息参数:user:{Newtonsoft.Json.JsonConvert.SerializeObject(input)}");
 | 
			
		||||
                return new ApiResult { code = 1, msg = "手机号不能为空" };
 | 
			
		||||
            }
 | 
			
		||||
            if (string.IsNullOrEmpty(input.Email))
 | 
			
		||||
            {
 | 
			
		||||
                return new ApiResult { code = 1, msg = "邮箱不能为空" };
 | 
			
		||||
            }
 | 
			
		||||
            if (string.IsNullOrEmpty(input.RoleId))
 | 
			
		||||
            {
 | 
			
		||||
                return new ApiResult { code = 1, msg = "角色不能为空" };
 | 
			
		||||
            }
 | 
			
		||||
            #endregion
 | 
			
		||||
            #region 组织数据
 | 
			
		||||
            var userEntity = input.Adapt<UserEntity>();
 | 
			
		||||
            userEntity.Phone = input.Tel;
 | 
			
		||||
            if (!string.IsNullOrEmpty(input.Password))
 | 
			
		||||
            {
 | 
			
		||||
                userEntity.Password = StringHelper.MD5Encrypt32(input.Password);
 | 
			
		||||
            }
 | 
			
		||||
            #endregion
 | 
			
		||||
            #region 更新数据
 | 
			
		||||
            await base.UpdateAsync(input.Id, userEntity);//更新用户信息
 | 
			
		||||
            #endregion
 | 
			
		||||
            return new ApiResult { code = 0, msg = "更新用户信息成功" };
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -289,37 +244,22 @@ namespace langguanApi.Service
 | 
			
		|||
        /// <returns></returns>
 | 
			
		||||
        public async Task<ApiResult> DeleteUser(string userId)
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
 | 
			
		||||
            #region 校验数据
 | 
			
		||||
            if (string.IsNullOrEmpty(userId))
 | 
			
		||||
            {
 | 
			
		||||
                #region 校验数据
 | 
			
		||||
                if (string.IsNullOrEmpty(userId))
 | 
			
		||||
                {
 | 
			
		||||
                    return new ApiResult { code = 1, msg = "用户Id不能为空" };
 | 
			
		||||
                }
 | 
			
		||||
                #endregion
 | 
			
		||||
                #region 更新数据
 | 
			
		||||
                var user = await base.GetAsync(userId);//根据userId获取用户信息
 | 
			
		||||
                if (user == null)
 | 
			
		||||
                {
 | 
			
		||||
                    return new ApiResult { code = 1, msg = "用户不存在" };
 | 
			
		||||
                }
 | 
			
		||||
                user.IsDelete = true;
 | 
			
		||||
                await base.UpdateAsync(userId, user);//更新用户信息
 | 
			
		||||
                #endregion
 | 
			
		||||
                return new ApiResult { code = 1, msg = "用户Id不能为空" };
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
            #endregion
 | 
			
		||||
            #region 更新数据
 | 
			
		||||
            var user = await base.GetAsync(userId);//根据userId获取用户信息
 | 
			
		||||
            if (user == null)
 | 
			
		||||
            {
 | 
			
		||||
                _logger.LogError($"删除用户信息出现异常,请求参数:userId:{userId}," +
 | 
			
		||||
                                 $"请求接口:'api/User/DeleteUser'," +
 | 
			
		||||
                                 $"异常信息:{ex.Message}," +
 | 
			
		||||
                                 $"异常位置:{ex.StackTrace}"
 | 
			
		||||
                                 );
 | 
			
		||||
                return new ApiResult { code = 1, msg = "删除用户信息失败" };
 | 
			
		||||
            }
 | 
			
		||||
            finally
 | 
			
		||||
            {
 | 
			
		||||
                _logger.LogInformation($"删除用户信息参数:userId:{userId}");
 | 
			
		||||
                return new ApiResult { code = 1, msg = "用户不存在" };
 | 
			
		||||
            }
 | 
			
		||||
            user.IsDelete = true;
 | 
			
		||||
            await base.UpdateAsync(userId, user);//更新用户信息
 | 
			
		||||
            #endregion
 | 
			
		||||
            return new ApiResult { code = 0, msg = "删除用户信息成功" };
 | 
			
		||||
        }
 | 
			
		||||
        #endregion
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue