Commit 176f2807 authored by liudong1993's avatar liudong1993

Merge branch 'master' of http://gitlab.oytour.com/Kui2/education

parents 686af568 ce1e6c77
......@@ -132,16 +132,24 @@ namespace Edu.Module.User
/// 获取部门结构树
/// </summary>
/// <param name="query"></param>
/// <param name="query">是否查询员工</param>
/// <returns></returns>
public List<DepartmentTree_ViewModel> GetDepartmentTreeModule(RB_Department_ViewModel query)
public List<DepartmentTree_ViewModel> GetDepartmentTreeModule(RB_Department_ViewModel query,bool isQueryEmployee=false)
{
//树形结构列表
List<DepartmentTree_ViewModel> list = new List<DepartmentTree_ViewModel>();
//所有的部门列表
var deptList = GetDepartmentListModule(query);
var schoolList = schoolRepository.GetSchoolListRepository(new RB_School_ViewModel() { Group_Id = query.Group_Id });
var empList = new List<Employee_ViewModel>();
if (deptList == null)
{
deptList = new List<RB_Department_ViewModel>();
}
if(isQueryEmployee)
{
empList= accountRepository.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = query.Group_Id });
}
//校区部门
List<DepartmentTree_ViewModel> schoolDeptList = new List<DepartmentTree_ViewModel>();
if (schoolList != null)
......@@ -150,17 +158,37 @@ namespace Edu.Module.User
{
DepartmentTree_ViewModel tModel = new DepartmentTree_ViewModel()
{
DeptId = item.SId+item.Group_Id,
DeptId = item.SId,
DeptName = item.SName,
ParentId = item.Dept_Id,
ChildList = new List<DepartmentTree_ViewModel>()
};
tModel.ChildList = GetDeptTreeList(0, deptList.Where(qitem => qitem.School_Id > 0).ToList(), SchoolId:item.SId,null);
#region 添加员工信息
if (isQueryEmployee && item.ManagerId > 0)
{
var empModel = empList?.Where(qitem => qitem.Id == item.ManagerId)?.FirstOrDefault();
if (empModel!=null && !string.IsNullOrEmpty(empModel.EmployeeName))
{
tModel.ChildList.Add(new DepartmentTree_ViewModel()
{
DeptId = 0,
DeptName = empModel.EmployeeName,
ParentId = 0
});
}
}
#endregion
var currentSchoolDeptList = deptList.Where(qitem => qitem.School_Id ==item.SId).ToList();
if (currentSchoolDeptList != null && currentSchoolDeptList.Count > 0)
{
var currentSchoolDeptId = currentSchoolDeptList?.Min(qitem => qitem.ParentId) ?? 0;
tModel.ChildList = GetDeptTreeList(currentSchoolDeptId, currentSchoolDeptList, SchoolId: item.SId, schoolDeptList: null, empList: empList);
}
schoolDeptList.Add(tModel);
}
}
List<DepartmentTree_ViewModel> list = new List<DepartmentTree_ViewModel>();
if (deptList != null && deptList.Count > 0)
{
var firstList = deptList.Where(qitem => qitem.ParentId == 0 && qitem.School_Id==0).ToList();
......@@ -175,7 +203,28 @@ namespace Edu.Module.User
ParentId = fItem.ParentId,
ChildList = new List<DepartmentTree_ViewModel>()
};
tModel.ChildList = GetDeptTreeList(fItem.DeptId, deptList.Where(qitem=>qitem.School_Id==0).ToList(),SchoolId:0, schoolDeptList);
#region 添加员工信息
if (isQueryEmployee)
{
var tempEmpList = empList?.Where(qitem => qitem.Dept_Id == fItem.DeptId)?.ToList();
if (tempEmpList != null && tempEmpList.Count > 0)
{
foreach (var eItem in tempEmpList)
{
tModel.ChildList.Add(new DepartmentTree_ViewModel()
{
DeptId = 0,
DeptName = eItem.EmployeeName,
ParentId = 0,
ChildList = new List<DepartmentTree_ViewModel>()
});
}
}
}
#endregion
tModel.ChildList = GetDeptTreeList(fItem.DeptId, deptList.Where(qitem => qitem.School_Id == 0).ToList(), SchoolId: 0, schoolDeptList: schoolDeptList, empList: empList);
if (schoolDeptList != null)
{
var newSchoolDeptList = schoolDeptList.Where(qitem => qitem.DeptId == fItem.DeptId)?.ToList();
......@@ -191,18 +240,18 @@ namespace Edu.Module.User
return list;
}
/// <summary>
/// 递归生成树形结构
/// </summary>
/// <param name="parentId">父节点编号</param>
/// <param name="sourceList">数据源列表</param>
private List<DepartmentTree_ViewModel> GetDeptTreeList(int parentId, List<RB_Department_ViewModel> sourceList,int SchoolId=0, List<DepartmentTree_ViewModel> schoolDeptList=null)
/// <param name="SchoolId">学校编号</param>
/// <param name="schoolDeptList">学校部门列表</param>
/// <param name="empList">员工列表</param>
private List<DepartmentTree_ViewModel> GetDeptTreeList(int parentId, List<RB_Department_ViewModel> sourceList,int SchoolId=0, List<DepartmentTree_ViewModel> schoolDeptList=null, List<Employee_ViewModel> empList=null)
{
List<DepartmentTree_ViewModel> treeList = new List<DepartmentTree_ViewModel>();
foreach (var item in sourceList.Where(qitem => qitem.ParentId == parentId && qitem.School_Id== SchoolId))
{
DepartmentTree_ViewModel model = new DepartmentTree_ViewModel()
......@@ -212,6 +261,26 @@ namespace Edu.Module.User
ParentId = item.ParentId,
ChildList = new List<DepartmentTree_ViewModel>(),
};
#region 添加员工信息
if (empList != null && empList.Count > 0)
{
var tempEmpList = empList?.Where(qitem => qitem.Dept_Id == item.DeptId)?.ToList();
if (tempEmpList != null && tempEmpList.Count > 0)
{
foreach (var eItem in tempEmpList)
{
model.ChildList.Add(new DepartmentTree_ViewModel()
{
DeptId = 0,
DeptName = eItem.EmployeeName,
ParentId = 0,
ChildList = new List<DepartmentTree_ViewModel>()
});
}
}
}
#endregion
model.ChildList = GetDeptTreeList(item.DeptId, sourceList, SchoolId, schoolDeptList);
if (schoolDeptList != null)
{
......
using Edu.Model.Entity.User;
using Edu.Common.Enum;
using Edu.Model.Entity.User;
using Edu.Model.ViewModel.User;
using System.Collections.Generic;
using System.Data;
......@@ -86,6 +87,7 @@ SELECT A.*
FROM rb_department AS A
WHERE 1=1
");
builder.Append($" AND A.{nameof(RB_Department_ViewModel.Status)}={(int)DateStateEnum.Normal} ");
if (query != null)
{
if (query.Group_Id > 0)
......
......@@ -976,6 +976,21 @@ namespace Edu.WebApi.Controllers.User
qitem.PostName
}));
}
/// <summary>
/// 获取部门员工树形列表
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetEmployeeAddrBook()
{
var query= new RB_Department_ViewModel()
{
Group_Id=base.ParmJObj.GetInt("Group_Id"),
};
var list = departmentModule.GetDepartmentTreeModule(query, isQueryEmployee: true);
return ApiResult.Success(data: list);
}
#endregion
#region 枚举相列表
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment