Commit cd4ce271 authored by liudong1993's avatar liudong1993

OKR获取直属下级调整

parent 8f4aefd9
......@@ -1980,31 +1980,7 @@ namespace Edu.Module.OKR
/// <returns></returns>
public ApiResult GetOKRObjectiveAuditList(int PeriodId, int userId, UserInfo userInfo)
{
List<int> UserIdList = new List<int>();
#region 我的直属下级
var deptModel = departmentRepository.GetEntity(userInfo.DeptId);
var emList = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, DirectSupervisor = userInfo.Id });
if (emList.Any())
{
foreach (var item in emList)
{
UserIdList.Add(item.Id);
}
}
//如果是部门主管 需要将部门下除自己其他人加入
//查询部门负责人 负责的所有部门
var xjdlist = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, ManagerIds = userInfo.Id.ToString() });
if (xjdlist.Any())
{
//查询该部门下所有人
var em1List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, QDeptIds = string.Join(",", xjdlist.Select(x => x.DeptId)) });
em1List = em1List.Where(x => !UserIdList.Contains(x.Id)).ToList();//排序 已存在的直接关系
foreach (var item in em1List)
{
UserIdList.Add(item.Id);
}
}
#endregion
List<int> UserIdList = GetMyUnderlingUserIdList(userInfo);
if (!UserIdList.Contains(userId))
{
return ApiResult.Failed("该用户不是直属下级,无法审核");
......@@ -2913,16 +2889,27 @@ namespace Edu.Module.OKR
else
{
//根据部门查询
var deptModel = departmentRepository.GetEntity(userInfo.DeptId);
string ManagerIds = "";
if (("," + deptModel.ManagerIds + ",").Contains("," + userInfo.Id + ","))
var sjdlist = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, ManagerIds = userInfo.Id.ToString() });
if (sjdlist.Any())
{
//说明自己是当前部门的主管 再查上级部门主管
var deptpModel = departmentRepository.GetEntity(deptModel.ParentId);
ManagerIds = deptpModel?.ManagerIds ?? "";
//说明是部门主管
foreach (var ditem in sjdlist.Where(x => x.ParentId > 0))
{
var deptpModel = departmentRepository.GetEntity(ditem.ParentId);
if (!string.IsNullOrEmpty(deptpModel?.ManagerIds ?? ""))
{
ManagerIds += (deptpModel?.ManagerIds ?? "") + ",";
}
if (!string.IsNullOrEmpty(ManagerIds))
{
break;
}
}
}
else
{
var deptModel = departmentRepository.GetEntity(userInfo.DeptId);
ManagerIds = deptModel.ManagerIds;
}
if (!string.IsNullOrEmpty(ManagerIds))
......@@ -4150,6 +4137,8 @@ namespace Edu.Module.OKR
List<int> UserIdList = new List<int>();
List<int> ParentIdList = new List<int>();
#region 我的直属上级
List<Model.ViewModel.User.RB_Department_ViewModel> sjdlist = new List<Model.ViewModel.User.RB_Department_ViewModel>();
bool sjdlistSelect = false;
List<Model.ViewModel.User.Employee_ViewModel> ZSList = new List<Model.ViewModel.User.Employee_ViewModel>();
var accountModel = accountRepository.GetEntity(userInfo.Id);
if (accountModel.DirectSupervisor > 0)
......@@ -4168,15 +4157,28 @@ namespace Edu.Module.OKR
else {
//根据部门查询
string ManagerIds = "";
if (("," + deptModel.ManagerIds + ",").Contains("," + userInfo.Id + ","))
sjdlist = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, ManagerIds = userInfo.Id.ToString() });
sjdlistSelect = true;
if (sjdlist.Any())
{
//说明自己是当前部门的主管 再查上级部门主管
var deptpModel = departmentRepository.GetEntity(deptModel.ParentId);
ManagerIds = deptpModel?.ManagerIds ?? "";
//说明是部门主管
foreach (var ditem in sjdlist.Where(x => x.ParentId > 0))
{
var deptpModel = departmentRepository.GetEntity(ditem.ParentId);
if (!string.IsNullOrEmpty(deptpModel?.ManagerIds ?? ""))
{
ManagerIds += (deptpModel?.ManagerIds ?? "") + ",";
}
}
if (!string.IsNullOrEmpty(ManagerIds))
{
ManagerIds = ManagerIds[0..^1];
}
}
else {
ManagerIds = deptModel.ManagerIds;
}
if (!string.IsNullOrEmpty(ManagerIds)) {
var list = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { QIds = ManagerIds });
foreach (var item in list) {
......@@ -4212,18 +4214,48 @@ namespace Edu.Module.OKR
//查询部门负责人 负责的所有部门
var xjdlist = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, ManagerIds = userInfo.Id.ToString() });
if (xjdlist.Any()) {
//查询该部门下所有人
//查询该部门下所有人 (需排除所有的部门负责人)
var em1List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, QDeptIds = string.Join(",", xjdlist.Select(x => x.DeptId)) });
em1List = em1List.Where(x => !UserIdList.Contains(x.Id) && x.DirectSupervisor == 0).ToList();//排序 已存在的直接关系
foreach (var item in em1List)
if (em1List.Any())
{
ChildList.Add(new Model.ViewModel.User.Employee_ViewModel()
//查询全部负责人
string AllManagerIds = departmentRepository.GetAllDepartmentManagerIds(userInfo.Group_Id);
List<int> AllDeptManageId = new List<int>();
if (!string.IsNullOrEmpty(AllManagerIds))
{
Id = item.Id,
EmployeeName = item.EmployeeName,
UserIcon = item.UserIcon
});
UserIdList.Add(item.Id);
AllDeptManageId = JsonHelper.DeserializeObject<List<int>>(AllManagerIds);
}
//对 em1List 排除负责人
foreach (var item in em1List.Where(x => !AllDeptManageId.Contains(x.Id)))
{
ChildList.Add(new Model.ViewModel.User.Employee_ViewModel()
{
Id = item.Id,
EmployeeName = item.EmployeeName,
UserIcon = item.UserIcon
});
UserIdList.Add(item.Id);
}
}
//上级部门下所有子部门的负责人
var d2list = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, QParentIds = string.Join(",", xjdlist.Select(x => x.DeptId)) });
string ManagerIds = string.Join(",", d2list.Where(x => !string.IsNullOrEmpty(x.ManagerIds)).Select(x => x.ManagerIds));
if (!string.IsNullOrEmpty(ManagerIds))
{
em1List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, QIds = ManagerIds });
em1List = em1List.Where(x => !UserIdList.Contains(x.Id) && x.Id != userInfo.Id && x.DirectSupervisor == 0).ToList();//排序 已存在的直接关系
foreach (var item in em1List)
{
ChildList.Add(new Model.ViewModel.User.Employee_ViewModel()
{
Id = item.Id,
EmployeeName = item.EmployeeName,
UserIcon = item.UserIcon
});
UserIdList.Add(item.Id);
}
}
}
#endregion
......@@ -4244,12 +4276,29 @@ namespace Edu.Module.OKR
UserIdList.Add(item.Id);
}
//查询部门负责人 负责的所有部门
//查询部门负责人 负责的所1有部门
var dlist = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, ManagerIds = string.Join(",", ParentIdList) });
if (dlist.Any()) {
if (!("," + deptModel.ManagerIds + ",").Contains("," + userInfo.Id + ","))
//上级所在部门下 所有的普通成员
var em1List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, QDeptIds = string.Join(",", dlist.Select(x => x.DeptId)) });
em1List = em1List.Where(x => !UserIdList.Contains(x.Id) && x.Id != userInfo.Id && x.DirectSupervisor == 0).ToList();//排序 已存在的直接关系
foreach (var item in em1List)
{
var em1List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, QDeptIds = string.Join(",", dlist.Select(x => x.DeptId)) });
SiblingList.Add(new Model.ViewModel.User.Employee_ViewModel()
{
Id = item.Id,
EmployeeName = item.EmployeeName,
UserIcon = item.UserIcon
});
UserIdList.Add(item.Id);
}
//上级部门下所有子部门的负责人
var d2list = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, QParentIds = string.Join(",", ZSList.Select(x => x.Dept_Id)) });
string ManagerIds = string.Join(",", d2list.Where(x => !string.IsNullOrEmpty(x.ManagerIds)).Select(x => x.ManagerIds));
if (!string.IsNullOrEmpty(ManagerIds))
{
em1List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, QIds = ManagerIds });
em1List = em1List.Where(x => !UserIdList.Contains(x.Id) && x.Id != userInfo.Id && x.DirectSupervisor == 0).ToList();//排序 已存在的直接关系
foreach (var item in em1List)
{
......@@ -4262,32 +4311,15 @@ namespace Edu.Module.OKR
UserIdList.Add(item.Id);
}
}
else {
//表示自己也是部门负责人 上级所在部门下的所有部门的负责人
var d2list = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, QParentIds = string.Join(",", ZSList.Select(x => x.Dept_Id)) });
string ManagerIds = string.Join(",", d2list.Where(x => !string.IsNullOrEmpty(x.ManagerIds)).Select(x => x.ManagerIds));
if (!string.IsNullOrEmpty(ManagerIds))
{
var em1List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, QIds = ManagerIds });
em1List = em1List.Where(x => !UserIdList.Contains(x.Id) && x.Id != userInfo.Id && x.DirectSupervisor == 0).ToList();//排序 已存在的直接关系
foreach (var item in em1List)
{
SiblingList.Add(new Model.ViewModel.User.Employee_ViewModel()
{
Id = item.Id,
EmployeeName = item.EmployeeName,
UserIcon = item.UserIcon
});
UserIdList.Add(item.Id);
}
}
}
}
}
else
{
if (sjdlistSelect == false) {
sjdlist = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, ManagerIds = userInfo.Id.ToString() });
}
//继续查询同部门的 也算同级
if (!("," + deptModel.ManagerIds + ",").Contains("," + userInfo.Id + ","))
if (!sjdlist.Any())
{
var em1List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, Dept_Id = userInfo.DeptId });
em1List = em1List.Where(x => !UserIdList.Contains(x.Id) && x.Id != userInfo.Id && x.DirectSupervisor == 0).ToList();//排序 已存在的直接关系
......@@ -4381,18 +4413,11 @@ namespace Edu.Module.OKR
public List<int> GetMyUnderlingUserIdList(UserInfo userInfo) {
List<int> UserIdList = new List<int>();
#region 我的直属下级
List<Model.ViewModel.User.Employee_ViewModel> ChildList = new List<Model.ViewModel.User.Employee_ViewModel>();
var emList = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, DirectSupervisor = userInfo.Id });
if (emList.Any())
{
foreach (var item in emList)
{
ChildList.Add(new Model.ViewModel.User.Employee_ViewModel()
{
Id = item.Id,
EmployeeName = item.EmployeeName,
UserIcon = item.UserIcon
});
UserIdList.Add(item.Id);
}
}
......@@ -4404,15 +4429,33 @@ namespace Edu.Module.OKR
//查询该部门下所有人
var em1List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, QDeptIds = string.Join(",", xjdlist.Select(x => x.DeptId)) });
em1List = em1List.Where(x => !UserIdList.Contains(x.Id) && x.DirectSupervisor == 0).ToList();//排序 已存在的直接关系
foreach (var item in em1List)
if (em1List.Any())
{
ChildList.Add(new Model.ViewModel.User.Employee_ViewModel()
//查询全部负责人
string AllManagerIds = departmentRepository.GetAllDepartmentManagerIds(userInfo.Group_Id);
List<int> AllDeptManageId = new List<int>();
if (!string.IsNullOrEmpty(AllManagerIds))
{
Id = item.Id,
EmployeeName = item.EmployeeName,
UserIcon = item.UserIcon
});
UserIdList.Add(item.Id);
AllDeptManageId = JsonHelper.DeserializeObject<List<int>>(AllManagerIds);
}
//对 em1List 排除负责人
foreach (var item in em1List.Where(x => !AllDeptManageId.Contains(x.Id)))
{
UserIdList.Add(item.Id);
}
}
//上级部门下所有子部门的负责人
var d2list = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, QParentIds = string.Join(",", xjdlist.Select(x => x.DeptId)) });
string ManagerIds = string.Join(",", d2list.Where(x => !string.IsNullOrEmpty(x.ManagerIds)).Select(x => x.ManagerIds));
if (!string.IsNullOrEmpty(ManagerIds))
{
em1List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, QIds = ManagerIds });
em1List = em1List.Where(x => !UserIdList.Contains(x.Id) && x.Id != userInfo.Id && x.DirectSupervisor == 0).ToList();//排序 已存在的直接关系
foreach (var item in em1List)
{
UserIdList.Add(item.Id);
}
}
}
#endregion
......@@ -4427,31 +4470,8 @@ namespace Edu.Module.OKR
/// <returns></returns>
public object GetOKRMyEmployeeAuditList(int periodId, UserInfo userInfo)
{
var deptModel = departmentRepository.GetEntity(userInfo.DeptId);
#region 我的直属下级
List<int> ChildIdList = new List<int>();
var emList = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, DirectSupervisor = userInfo.Id });
if (emList.Any())
{
foreach (var item in emList)
{
ChildIdList.Add(item.Id);
}
}
//如果是部门主管 需要将部门下除自己其他人加入
//查询部门负责人 负责的所有部门
var xjdlist = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, ManagerIds = userInfo.Id.ToString() });
if (xjdlist.Any())
{
//查询该部门下所有人
var em1List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, QDeptIds = string.Join(",", xjdlist.Select(x => x.DeptId)) });
em1List = em1List.Where(x => !ChildIdList.Contains(x.Id) && x.DirectSupervisor == 0).ToList();//排序 已存在的直接关系
foreach (var item in em1List)
{
ChildIdList.Add(item.Id);
}
}
#endregion
List<int> ChildIdList = GetMyUnderlingUserIdList(userInfo);
#region 我的审批
List<object> AuditList = new List<object>();
//直接拿直属下级 待审核的
......@@ -4611,31 +4631,7 @@ namespace Edu.Module.OKR
var model = oKR_ObjectiveRepository.GetEntity(objectiveId);
if (model == null) { return "目标不存在"; }
if (model.Status != 1) { return "非待审核状态,无法审核"; }
List<int> UserIdList = new List<int>();
#region 我的直属下级
var deptModel = departmentRepository.GetEntity(userInfo.DeptId);
var emList = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, DirectSupervisor = userInfo.Id });
if (emList.Any())
{
foreach (var item in emList)
{
UserIdList.Add(item.Id);
}
}
//如果是部门主管 需要将部门下除自己其他人加入
//查询部门负责人 负责的所有部门
var xjdlist = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, ManagerIds = userInfo.Id.ToString() });
if (xjdlist.Any())
{
//查询该部门下所有人
var em1List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, QDeptIds = string.Join(",", xjdlist.Select(x => x.DeptId)) });
em1List = em1List.Where(x => !UserIdList.Contains(x.Id)).ToList();//排序 已存在的直接关系
foreach (var item in em1List)
{
UserIdList.Add(item.Id);
}
}
#endregion
List<int> UserIdList = GetMyUnderlingUserIdList(userInfo);
if (!UserIdList.Contains(model.CreateBy))
{
return "该目标不是直属下级目标,无法审核";
......@@ -4777,11 +4773,22 @@ namespace Edu.Module.OKR
{
//根据部门查询
string ManagerIds = "";
if (("," + deptModel.ManagerIds + ",").Contains("," + userInfo.Id + ","))
var sjdlist = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, ManagerIds = userInfo.Id.ToString() });
if (sjdlist.Any())
{
//说明自己是当前部门的主管 再查上级部门主管
var deptpModel = departmentRepository.GetEntity(deptModel.ParentId);
ManagerIds = deptpModel?.ManagerIds ?? "";
//说明是部门主管
foreach (var ditem in sjdlist.Where(x => x.ParentId > 0))
{
var deptpModel = departmentRepository.GetEntity(ditem.ParentId);
if (!string.IsNullOrEmpty(deptpModel?.ManagerIds ?? ""))
{
ManagerIds += (deptpModel?.ManagerIds ?? "") + ",";
}
}
if (!string.IsNullOrEmpty(ManagerIds))
{
ManagerIds = ManagerIds[0..^1];
}
}
else
{
......@@ -4815,7 +4822,7 @@ namespace Edu.Module.OKR
}
}
//如果是部门主管 需要将部门下除自己其他人加入
//查询部门负责人 负责的所有部门
//查询部门负责人 负责的所1有部门
var xjdlist = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, ManagerIds = userInfo.Id.ToString() });
if (xjdlist.Any())
{
......@@ -4838,7 +4845,7 @@ namespace Edu.Module.OKR
UserIdList.Add(item.Id);
}
//查询部门负责人 负责的所有部门
//查询部门负责人 负责的所1有部门
var dlist = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, ManagerIds = string.Join(",", ParentIdList) });
if (dlist.Any())
{
......
using Edu.Common.Enum;
using Edu.Model.Entity.User;
using Edu.Model.ViewModel.User;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
......@@ -220,5 +221,17 @@ WHERE 1=1
parameters.Add("QDeptIds", DeptId, direction: ParameterDirection.Input);
return Get<RB_Department_ViewModel>(procName, parameters, commandType: CommandType.StoredProcedure).ToList();
}
/// <summary>
/// 获取所有部门负责人
/// </summary>
/// <param name="group_Id"></param>
/// <returns></returns>
public string GetAllDepartmentManagerIds(int group_Id)
{
string sql = $" SELECT GROUP_CONCAT(ManagerIds) AS ManagerIds FROM rb_department WHERE `Status`=0 and Group_Id ={group_Id} and ManagerIds <> '' ";
var obj = ExecuteScalar(sql);
return obj == null ? "" : obj.ToString();
}
}
}
\ No newline at end of file
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