李昊 4 years ago
parent
commit
12d4ed11e2

+ 1 - 0
gx_api/GxPress/Model/GxPress.Mappings/DepartmentMapping.cs

@@ -9,6 +9,7 @@ namespace GxPress.Mappings
         public DepartmentMapping()
         {
             CreateMap<Department, DepartmentTreeResult>();
+            CreateMap<Department, DepartmentResult>();
         }
     }
 }

+ 39 - 0
gx_api/GxPress/Model/GxPress.Result/Department/DepartmentResult.cs

@@ -0,0 +1,39 @@
+namespace GxPress.Result.Department
+{
+    /// <summary>
+    /// 部门
+    /// </summary>
+    public class DepartmentResult
+    {
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <value></value>
+        public int Id { get; set; }
+        /// <summary>
+        /// 部门名称
+        /// </summary>
+        public string Name { get; set; }
+        /// <summary>
+        /// 父级部门id
+        /// </summary>
+        public int ParentId { get; set; }
+        /// <summary>
+        /// 部门主管id
+        /// </summary>
+        public int LeaderId { get; set; }
+        /// <summary>
+        /// 排序
+        /// </summary>
+        public int Sort { get; set; }
+        /// <summary>
+        /// 用户成员
+        /// </summary>
+        /// <value></value>
+        public int UserCount { get; set; }
+
+        public int TypeId{get;set;}
+
+        public int TypeValue{get;set;}
+    }
+}

+ 3 - 2
gx_api/GxPress/Model/GxPress.Result/Department/DepartmentUserResult.cs

@@ -1,4 +1,5 @@
 using System.Collections.Generic;
+using GxPress.Result.User;
 
 namespace GxPress.Result.Department
 {
@@ -10,10 +11,10 @@ namespace GxPress.Result.Department
         /// <summary>
         /// 下级部门
         /// </summary>
-        public IEnumerable<Entity.Department> Departments { get; set; }
+        public IEnumerable<DepartmentResult> Departments { get; set; }
         /// <summary>
         /// 成员
         /// </summary>
-        public List<Entity.User> Users { get; set; }
+        public List<UserInfoResult> Users { get; set; }
     }
 }

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

@@ -209,5 +209,6 @@ namespace GxPress.Result.User
         /// <value></value>
 
         public bool IsFreeze { get; set; }
+
     }
 }

+ 14 - 8
gx_api/GxPress/Repository/GxPress.Repository.Implement/DepartmentRepository.cs

@@ -12,6 +12,7 @@ using GxPress.Request.Department;
 using GxPress.Result.Department;
 using Microsoft.Extensions.Options;
 using Datory;
+using GxPress.Result.User;
 
 namespace GxPress.Repository.Implement
 {
@@ -104,9 +105,9 @@ namespace GxPress.Repository.Implement
             return await _repository.UpdateAsync(department);
         }
 
-        public async Task<IEnumerable<Department>> GetListAsync(int parentId)
+        public async Task<IEnumerable<DepartmentResult>> GetListAsync(int parentId)
         {
-            return await _repository.GetAllAsync(Q.Where(nameof(Department.ParentId), parentId)
+            return await _repository.GetAllAsync<DepartmentResult>(Q.Where(nameof(Department.ParentId), parentId)
                 .OrderBy(nameof(Department.Sort)));
         }
 
@@ -115,9 +116,9 @@ namespace GxPress.Repository.Implement
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-        public async Task<IEnumerable<Department>> GetListAsync(DepartmentUserRequest request)
+        public async Task<IEnumerable<DepartmentResult>> GetListAsync(DepartmentUserRequest request)
         {
-            return await _repository.GetAllAsync(Q.Where(nameof(Department.ParentId), request.DepartmentId)
+            return await _repository.GetAllAsync<DepartmentResult>(Q.Where(nameof(Department.ParentId), request.DepartmentId)
                 .WhereNot(nameof(Department.Id), request.SourceDepartmentId));
         }
 
@@ -221,8 +222,13 @@ namespace GxPress.Repository.Implement
             result.Departments = departments;
             //获取用户ID
             var departmentUsers = await departmentUserRepository.GetAllAsync<int>(Q.Where(nameof(Entity.DepartmentUser.DepartmentId), request.DepartmentId).Select(nameof(Entity.DepartmentUser.UserId)));
-            var users = await _userRepository.GetAllAsync(Q.WhereIn(nameof(User.Id), departmentUsers));
+            var users = await _userRepository.GetAllAsync<UserInfoResult>(Q.WhereIn(nameof(User.Id), departmentUsers));
             result.Users = users.ToList();
+            foreach (var item in result.Users)
+            {
+                item.TypeId = 0;
+                item.TypeValue = 0;
+            }
             for (int i = 0; i < result.Users.Count(); i++)
             {
                 if (!request.IsShow)
@@ -243,13 +249,13 @@ namespace GxPress.Repository.Implement
         /// <param name="id"></param>
         /// <param name="departments"></param>
         /// <returns></returns>
-        public async Task<List<Department>> GetDepartmentById(int id, List<Department> departments)
+        public async Task<List<DepartmentResult>> GetDepartmentById(int id, List<DepartmentResult> departments)
         {
-            var department = await _repository.GetAsync(id);
+            var department = await _repository.GetAsync<DepartmentResult>(Q.Where(nameof(Entity.Department.Id), id));
             if (department != null)
             {
                 departments.Add(department);
-                var list = await _repository.GetAllAsync(Q.Where(nameof(Entity.Department.ParentId), department.Id));
+                var list = await _repository.GetAllAsync<DepartmentResult>(Q.Where(nameof(Entity.Department.ParentId), department.Id));
                 foreach (var item in list)
                 {
                     departments.Add(item);

+ 1 - 1
gx_api/GxPress/Repository/GxPress.Repository.Implement/Note/NoteRepository.cs

@@ -116,7 +116,7 @@ namespace GxPress.Repository.Implement.Note
                                 INNER JOIN
                             tede_user b ON a.UserId = b.Id
                         WHERE
-                            a.UserId ={request.UserId} AND a.IsDraft = 1 and a.IsTopic={ request.TypeValue}
+                            a.UserId ={request.UserId} AND a.IsDraft = 1 and a.IsTopic={request.TypeValue}
                             {sqlStr} limit {(request.Page - 1) * request.PerPage},{request.PerPage}";
             var result =
                 await connection

+ 2 - 2
gx_api/GxPress/Repository/GxPress.Repository.Interface/IDepartmentRepository.cs

@@ -20,7 +20,7 @@ namespace GxPress.Repository.Interface
 
         Task<bool> UpdateAsync(Department department);
 
-        Task<IEnumerable<Department>> GetListAsync(int parentId);
+        Task<IEnumerable<DepartmentResult>> GetListAsync(int parentId);
 
         /// <summary>
         /// 添加
@@ -74,7 +74,7 @@ namespace GxPress.Repository.Interface
         /// <param name="id"></param>
         /// <param name="departments"></param>
         /// <returns></returns>
-        Task<List<Department>> GetDepartmentById(int id, List<Department> departments);
+        Task<List<DepartmentResult>> GetDepartmentById(int id, List<DepartmentResult> departments);
 
         Task<string> GetDepartmentFullPathAsync(int departmentId, string departmentName);
 

+ 4 - 3
gx_api/GxPress/Service/GxPress.Service.Implement/Department/DepartmentService.Delete.cs

@@ -2,6 +2,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
 using GxPress.Entity;
+using GxPress.Result.Department;
 using SqlKata;
 
 namespace GxPress.Service.Implement.Department
@@ -15,11 +16,11 @@ namespace GxPress.Service.Implement.Department
         /// <returns></returns>
         public async Task<bool> DeleteAsync(int id)
         {
-            var departments = new List<Entity.Department>();
+            var departments = new List<DepartmentResult>();
             var department = await _departmentRepository.GetAsync(id);
-            departments.Add(department);
+            departments.Add(_mapper.Map<DepartmentResult>(department));
             //获取下级部门
-            departments = await _departmentRepository.GetDepartmentById(id, departments);
+            departments = await _departmentRepository.GetDepartmentById(id, departments.Select(n => _mapper.Map<DepartmentResult>(n)).ToList());
             foreach (var item in departments)
             {
                 var users = await _userRepository.GetUserByDepartmentIdAsync(item.Id);

+ 4 - 2
gx_api/GxPress/Service/GxPress.Service.Implement/Department/DepartmentService.cs

@@ -9,6 +9,7 @@ using GxPress.Service.Interface.Department;
 using GxPress.Repository.Interface.DepartmentUser;
 using System.Linq;
 using Datory;
+using GxPress.EnumConst;
 
 namespace GxPress.Service.Implement.Department
 {
@@ -45,11 +46,12 @@ namespace GxPress.Service.Implement.Department
             {
                 foreach (var item in result.Departments)
                 {
+                    item.TypeId = UserlinkConst.Work.GetHashCode();
                     //获取部门
-                    var departments = new List<Entity.Department>();
+                    var departments = new List<DepartmentResult>();
                     await _departmentRepository.GetDepartmentById(item.Id, departments);
                     var userIds = await departmentUserRepository.GetUserIdsByDepartmentIdsAsync(departments.Select(n => n.Id));
-                    item.UserCount =await _userRepository.CountAsync(Q.WhereIn(nameof(Entity.User.Id),userIds));
+                    item.UserCount = await _userRepository.CountAsync(Q.WhereIn(nameof(Entity.User.Id), userIds));
                 }
 
             }

+ 3 - 2
gx_api/GxPress/Service/GxPress.Service.Implement/Topic/TopicService.cs

@@ -23,6 +23,7 @@ using GxPress.Service.Interface.Analyze;
 using GxPress.Repository.Interface.DepartmentUser;
 using GxPress.EnumConst;
 using GxPress.Repository.Interface.Note;
+using GxPress.Result.Department;
 
 namespace GxPress.Service.Implement.Topic
 {
@@ -364,7 +365,7 @@ namespace GxPress.Service.Implement.Topic
                     if (request.UserId > 0)
                     {
                         var departmentIds = await departmentUserRepository.GetDepartmentIdsAsync(request.UserId);
-                        var departments = new List<Entity.Department>();
+                        var departments = new List<DepartmentResult>();
                         foreach (var departmentId in departmentIds)
                         {
                             await _departmentRepository.GetDepartmentById(departmentId, departments);
@@ -470,7 +471,7 @@ namespace GxPress.Service.Implement.Topic
                     if (request.UserId > 0)
                     {
                         var departmentIds = await departmentUserRepository.GetDepartmentIdsAsync(request.UserId);
-                        var departments = new List<Entity.Department>();
+                        var departments = new List<DepartmentResult>();
                         foreach (var departmentId in departmentIds)
                         {
                             await _departmentRepository.GetDepartmentById(departmentId, departments);

+ 2 - 1
gx_api/GxPress/Service/GxPress.Service.Implement/UserMiddle/UserMiddleService.cs

@@ -10,6 +10,7 @@ using System.Linq;
 using GxPress.EnumConst;
 using GxPress.Repository.Interface.DepartmentUser;
 using GxPress.Repository.Interface.Friends;
+using GxPress.Result.Department;
 
 namespace GxPress.Service.Implement.UserMiddle
 {
@@ -117,7 +118,7 @@ namespace GxPress.Service.Implement.UserMiddle
                         else
                         {
                             //递归获取部门
-                            var departments = new List<Entity.Department>();
+                            var departments = new List<DepartmentResult>();
                             departments = await _departmentRepository.GetDepartmentById(userMiddle.SourceId, departments);
                             //获取部门用户
                             userIds.AddRange(await departmentUserRepository.GetUserIdsByDepartmentIdsAsync(departments.Select(n => n.Id)));

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

@@ -25,6 +25,7 @@ using GxPress.Request.AddressBookGroup;
 using GxPress.Repository.Interface.DepartmentUser;
 using GxPress.Repository.Interface.Friends;
 using GxPress.EnumConst;
+using GxPress.Result.Department;
 
 namespace GxPress.Service.Implement
 {
@@ -600,7 +601,7 @@ namespace GxPress.Service.Implement
         /// <returns></returns>
         public async Task<IEnumerable<UserInfoResult>> GetUserInfoByDepartentResult(int departentId)
         {
-            var departentList = new List<Entity.Department>();
+            var departentList = new List<DepartmentResult>();
             var departent = await _departmentRepository.GetDepartmentById(departentId, departentList);
             var userIds = await departmentUserRepository.GetUserIdsAsync(departent.Select(n => n.Id));
             var result = await _userRepository.GetUserInfoResultsAsync(userIds);