李昊 4 years ago
parent
commit
78638cfc74

+ 3 - 3
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminUserController.cs

@@ -34,7 +34,7 @@ namespace GxPress.Api.AdminControllers
         private readonly IUserRepository _userRepository;
         private readonly IDepartmentRepository _departmentRepository;
         private readonly IUserService _userService;
-     
+
         public AdminUserController(IUserRepository userRepository, IOptions<JwtOptions> jwtOptions,
             ILogger<AdminUserController> logger, IDepartmentRepository departmentRepository, IUserService userService)
         {
@@ -74,9 +74,9 @@ namespace GxPress.Api.AdminControllers
         /// <param name="id"></param>
         /// <returns></returns>
         [HttpGet("{id}")]
-        public async Task<User> GetDetail(int id)
+        public async Task<UserInfoResult> GetDetail(int id)
         {
-            return await _userRepository.GetAsync(id);
+            return await _userService.GetUserInfoAsync(id);
         }
 
         /// <summary>

+ 6 - 2
gx_api/GxPress/Model/GxPress.Result/User/UserDetail.cs

@@ -44,6 +44,10 @@ namespace GxPress.Result.User
         /// 部门id
         /// </summary>
         public int DepartmentId { get; set; }
+        /// <summary>
+        /// 部门id
+        /// </summary>
+        public int DepartmentIds { get; set; }
 
         /// <summary>
         /// 单位名称
@@ -203,14 +207,14 @@ namespace GxPress.Result.User
         /// <value></value>
         public bool IsFreeze { get; set; }
 
-         /// <summary>
+        /// <summary>
         /// 出版社
         /// </summary>
         /// <value></value>
 
         public string Press { get; set; }
 
-         /// <summary>
+        /// <summary>
         /// 历史头像
         /// </summary>
         /// <value></value>

+ 5 - 0
gx_api/GxPress/Model/GxPress.Result/User/UserInfoResult.cs

@@ -56,6 +56,11 @@ namespace GxPress.Result.User
         /// </summary>
 
         public int DepartmentId { get; set; }
+        /// <summary>
+        /// 部门ids
+        /// </summary>
+
+        public IEnumerable<int> DepartmentIds { get; set; }
 
         /// <summary>
         /// 职位

+ 10 - 5
gx_api/GxPress/Repository/GxPress.Repository.Implement/UserRepository.cs

@@ -96,11 +96,11 @@ namespace GxPress.Repository.Implement
             if (!string.IsNullOrEmpty(user.HistoryAvatarUrl))
                 user.HistoryAvatarUrl = StringUtils.AddDomain(user.HistoryAvatarUrl);
             var userDetail = _mapper.Map<UserDetail>(user);
-            if (user.DepartmentId > 0)
-            {
-                var department = await _departmentRepository.GetAsync(user.DepartmentId);
-                userDetail.DepartmentName = department.Name;
-            }
+            // if (user.DepartmentId > 0)
+            // {
+            //     var department = await _departmentRepository.GetAsync(user.DepartmentId);
+            //     userDetail.DepartmentName = department.Name;
+            // }
             return userDetail;
         }
 
@@ -113,6 +113,11 @@ namespace GxPress.Repository.Implement
             var user = await _repository.GetAsync(id);
             return user;
         }
+         public async Task<UserInfoResult> GetUserInfoAsync(int id)
+        {
+            var user = await _repository.GetAsync<UserInfoResult>(Q.Where(nameof(User.Id),id));
+            return user;
+        }
         public async Task<User> GetAsync(SqlKata.Query query)
         {
             var user = await _repository.GetAsync(query);

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

@@ -13,7 +13,8 @@ namespace GxPress.Repository.Interface
 {
     public interface IUserRepository : IRepository
     {
-         Task<IEnumerable<int>> GetAllIntsAsync(Query query);
+        Task<UserInfoResult> GetUserInfoAsync(int id);
+        Task<IEnumerable<int>> GetAllIntsAsync(Query query);
         Task<User> GetAsync(int id);
         Task<User> GetAsync(SqlKata.Query query);
         Task<UserDetail> GetDetailAsync(int id);

+ 12 - 5
gx_api/GxPress/Service/GxPress.Service.Implement/UserService.cs

@@ -132,11 +132,11 @@ namespace GxPress.Service.Implement
             }
 
             var userDetail = _mapper.Map<UserDetail>(user);
-            if (user.DepartmentId > 0)
-            {
-                var department = await _departmentRepository.GetAsync(user.DepartmentId);
-                userDetail.DepartmentName = department.Name;
-            }
+            // if (user.DepartmentId > 0)
+            // {
+            //     var department = await _departmentRepository.GetAsync(user.DepartmentId);
+            //     userDetail.DepartmentName = department.Name;
+            // }
             userDetail.AvatarUrl = StringUtils.AddDomainMin(userDetail.AvatarUrl);
             userDetail.HistoryAvatarUrl = StringUtils.AddDomainMin(userDetail.HistoryAvatarUrl);
             userDetail.IsBlack = await _blacklistUserRepository.FindUserIsBlack(userId, blackUserId);
@@ -468,5 +468,12 @@ namespace GxPress.Service.Implement
                 user.DisableTiem = Convert.ToDateTime(request.DisableTiem);
             return await _userRepository.UpdateAsync(user);
         }
+
+        public async Task<UserInfoResult> GetUserInfoAsync(int id)
+        {
+            var result = await _userRepository.GetUserInfoAsync(id);
+            result.DepartmentIds = await departmentUserRepository.GetDepartmentIdsAsync(id);
+            return result;
+        }
     }
 }

+ 1 - 0
gx_api/GxPress/Service/GxPress.Service.Interface/IUserService.cs

@@ -64,5 +64,6 @@ namespace GxPress.Service.Interface
         /// <param name="request"></param>
         /// <returns></returns>
         Task<bool> UpdateAsync(int id, UserInfoRequest request);
+         Task<UserInfoResult> GetUserInfoAsync(int id);
     }
 }