using Edu.Cache.User; using Edu.Common.API; using Edu.Common.Plugin; using Edu.Model.CacheModel; using Edu.Model.ViewModel.OKR; using Edu.Repository.Log; using Edu.Repository.OKR; using Edu.Repository.User; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using VT.FW.DB; using System.Threading; using System.Threading.Tasks; using Edu.Model.ViewModel.User; namespace Edu.Module.OKR { /// /// OKR处理类 /// public class OKRPeriodModule { /// /// 评论 /// private readonly RB_OKR_CommentRepository oKR_CommentRepository = new RB_OKR_CommentRepository(); /// /// 结果 /// private readonly RB_OKR_KeyResultRepository oKR_KeyResultRepository = new RB_OKR_KeyResultRepository(); /// /// 目标 /// private readonly RB_OKR_ObjectiveRepository oKR_ObjectiveRepository = new RB_OKR_ObjectiveRepository(); /// /// 对齐 /// private readonly RB_OKR_ObjectiveRelationRepository oKR_ObjectiveRelationRepository = new RB_OKR_ObjectiveRelationRepository(); /// /// 周期配置 /// private readonly RB_OKR_PeriodConfigRepository oKR_PeriodConfigRepository = new RB_OKR_PeriodConfigRepository(); /// /// 周期 /// private readonly RB_OKR_PeriodRepository oKR_PeriodRepository = new RB_OKR_PeriodRepository(); /// /// 周期权限 /// private readonly RB_OKR_PermissionRepository oKR_PermissionRepository = new RB_OKR_PermissionRepository(); /// /// 提醒 /// private readonly RB_OKR_RemindRepository oKR_RemindRepository = new RB_OKR_RemindRepository(); /// /// 评分明细 /// private readonly RB_OKR_ScoreDetailRepository oKR_ScoreDetailRepository = new RB_OKR_ScoreDetailRepository(); /// /// 评分 /// private readonly RB_OKR_ScoreRepository oKR_ScoreRepository = new RB_OKR_ScoreRepository(); /// /// 关注 /// private readonly RB_OKR_AttentionRepository oKR_AttentionRepository = new RB_OKR_AttentionRepository(); /// /// 用户日志 /// private readonly RB_User_ChangeLogRepository changeLogRepository = new RB_User_ChangeLogRepository(); /// /// 更新通知 /// private readonly RB_OKR_UpdateNotificationRepository oKR_UpdateNotificationRepository = new RB_OKR_UpdateNotificationRepository(); /// /// 账户 /// private readonly RB_AccountRepository accountRepository = new RB_AccountRepository(); /// /// 部门 /// private readonly RB_DepartmentRepository departmentRepository = new RB_DepartmentRepository(); /// /// 岗位 /// private readonly RB_PostRepository postRepository = new RB_PostRepository(); /// /// 规则 /// private readonly RB_OKR_RuleRepository oKR_RuleRepository = new RB_OKR_RuleRepository(); /// /// 规则关联 /// private readonly RB_OKR_RuleRelationRepository oKR_RuleRelationRepository = new RB_OKR_RuleRelationRepository(); /// /// 修改历史 /// private readonly RB_OKR_UpdateHistoryRepository oKR_UpdateHistoryRepository = new RB_OKR_UpdateHistoryRepository(); /// /// 周期默认所有人可见权限 /// private readonly RB_OKR_PeriodPermissionRepository oKR_PeriodPermissionRepository = new RB_OKR_PeriodPermissionRepository(); /// /// 关注事项 /// private readonly RB_OKR_MatterRepository oKR_MatterRepository = new RB_OKR_MatterRepository(); /// /// 用户最后更新进度时间 /// private readonly RB_OKR_UpdateProgressRepository oKR_UpdateProgressRepository = new RB_OKR_UpdateProgressRepository(); #region 基础配置 /// /// 获取周期配置 /// /// /// public RB_OKR_PeriodConfig_ViewModel GetOKRPeriodConfigInfo(int group_Id) { return oKR_PeriodConfigRepository.GetList(new RB_OKR_PeriodConfig_ViewModel() { Group_Id = group_Id }).FirstOrDefault() ?? new RB_OKR_PeriodConfig_ViewModel(); } /// /// 获取周期配置列表 /// /// public List GetOKRPeriodConfigList() { return oKR_PeriodConfigRepository.GetList(new RB_OKR_PeriodConfig_ViewModel() { }); } /// /// 保存OKR周期配置 /// /// /// /// public string SetOKRPeriodConfigInfo(RB_OKR_PeriodConfig_ViewModel dmodel, UserInfo userInfo) { if (dmodel.Id > 0) { var model = oKR_PeriodConfigRepository.GetEntity(dmodel.Id); Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_PeriodConfig_ViewModel.PeriodMonth), dmodel.PeriodMonth}, { nameof(RB_OKR_PeriodConfig_ViewModel.StartDate), dmodel.StartDate}, { nameof(RB_OKR_PeriodConfig_ViewModel.EndDate), dmodel.EndDate}, { nameof(RB_OKR_PeriodConfig_ViewModel.BeforeNum), dmodel.BeforeNum}, { nameof(RB_OKR_PeriodConfig_ViewModel.BeforeType), dmodel.BeforeType}, { nameof(RB_OKR_PeriodConfig_ViewModel.YearOKR), dmodel.YearOKR}, { nameof(RB_OKR_PeriodConfig_ViewModel.DirectorAudit), dmodel.DirectorAudit}, { nameof(RB_OKR_PeriodConfig_ViewModel.UpdateBy), dmodel.UpdateBy}, { nameof(RB_OKR_PeriodConfig_ViewModel.UpdateTime), dmodel.UpdateTime}, }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_PeriodConfig_ViewModel.Id), FiledValue=dmodel.Id, OperatorEnum=OperatorEnum.Equal }, new WhereHelper(){ FiledName=nameof(RB_OKR_PeriodConfig_ViewModel.Group_Id), FiledValue=userInfo.Group_Id, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_PeriodConfigRepository.Update(keyValues, wheres); if (flag) { #region 是否需要重新生成周期 if (model.PeriodMonth != dmodel.PeriodMonth || model.StartDate != dmodel.StartDate || model.EndDate != dmodel.EndDate) { //更新所有历史周期 oKR_PeriodRepository.SetPeriodHistory(userInfo.Group_Id); var nlist = oKR_PeriodRepository.GetList(new RB_OKR_Period_ViewModel() { Group_Id = dmodel.Group_Id, Name = dmodel.StartDate.Value.ToString("yyyy年MM月") + "-" + dmodel.EndDate.Value.ToString("yyyy年MM月") }); if (nlist.Any()) { var nmodel = nlist.FirstOrDefault(); Dictionary keyValues1 = new Dictionary() { { nameof(RB_OKR_Period_ViewModel.IsNormal),1} }; List wheres1 = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Period_ViewModel.Id), FiledValue=nmodel.Id, OperatorEnum=OperatorEnum.Equal } }; oKR_PeriodRepository.Update(keyValues1, wheres1); } else { //生成对应期数 oKR_PeriodRepository.Insert(new Model.Entity.OKR.RB_OKR_Period() { Id = 0, IsYear = 2, Status = 0, Name = dmodel.StartDate.Value.ToString("yyyy年MM月") + "-" + dmodel.EndDate.Value.ToString("yyyy年MM月"), StartDate = dmodel.StartDate.Value, EndDate = dmodel.EndDate.Value, Group_Id = dmodel.Group_Id, School_Id = dmodel.School_Id, CreateBy = dmodel.CreateBy, CreateTime = DateTime.Now, UpdateBy = dmodel.UpdateBy, UpdateTime = DateTime.Now, IsNormal = 1 }); } } if (dmodel.YearOKR == 1) { //今年 var nlist = oKR_PeriodRepository.GetList(new RB_OKR_Period_ViewModel() { Group_Id = dmodel.Group_Id, Name = dmodel.StartDate.Value.Year + "年度OKR" }); if (!nlist.Any()) { oKR_PeriodRepository.Insert(new Model.Entity.OKR.RB_OKR_Period() { Id = 0, IsYear = 1, Status = 0, Name = dmodel.StartDate.Value.Year + "年度OKR", StartDate = Convert.ToDateTime(dmodel.StartDate.Value.Year + "-01-01"), EndDate = Convert.ToDateTime(dmodel.StartDate.Value.Year + "-01-01 23:59:59").AddYears(1).AddDays(-1), Group_Id = dmodel.Group_Id, School_Id = dmodel.School_Id, CreateBy = dmodel.CreateBy, CreateTime = DateTime.Now, UpdateBy = dmodel.UpdateBy, UpdateTime = DateTime.Now, IsNormal = 1 }); } if (dmodel.StartDate.Value.Year != dmodel.EndDate.Value.Year) { //明年 var nextlist = oKR_PeriodRepository.GetList(new RB_OKR_Period_ViewModel() { Group_Id = dmodel.Group_Id, Name = dmodel.StartDate.Value.Year + "年度OKR" }); if (!nextlist.Any()) { oKR_PeriodRepository.Insert(new Model.Entity.OKR.RB_OKR_Period() { Id = 0, IsYear = 1, Status = 0, Name = dmodel.EndDate.Value.Year + "年度OKR", StartDate = Convert.ToDateTime(dmodel.EndDate.Value.Year + "-01-01"), EndDate = Convert.ToDateTime(dmodel.EndDate.Value.Year + "-01-01 23:59:59").AddYears(1).AddDays(-1), Group_Id = dmodel.Group_Id, School_Id = dmodel.School_Id, CreateBy = dmodel.CreateBy, CreateTime = DateTime.Now, UpdateBy = dmodel.UpdateBy, UpdateTime = DateTime.Now, IsNormal = 1 }); } } } //看最新的天数 是否满足生成下一周期 if (dmodel.BeforeType == 1) { //天 var ds = dmodel.EndDate.Value - DateTime.Now; if (ds.TotalDays < dmodel.BeforeNum) { //生成下一个周期 CreatePeriodNext(dmodel); } } else { //月 var ds = DateTime.Now.AddMonths(dmodel.BeforeNum); if (ds > dmodel.EndDate) { //生成下一个周期 CreatePeriodNext(dmodel); } } #endregion //记录日志 changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "修改OKR周期配置", School_Id = userInfo.School_Id, SourceId = 0 }); } return flag ? "" : "失败了,请联系管理"; } else { //验证是否存在 var model = oKR_PeriodConfigRepository.GetList(new RB_OKR_PeriodConfig_ViewModel() { Group_Id = userInfo.Group_Id }).FirstOrDefault(); if (model != null) { return "已存在配置"; } bool flag = oKR_PeriodConfigRepository.Insert(dmodel) > 0; if (flag) { //生成对应期数 oKR_PeriodRepository.Insert(new Model.Entity.OKR.RB_OKR_Period() { Id = 0, IsYear = 2, Status = 0, Name = dmodel.StartDate.Value.ToString("yyyy年MM月") + "-" + dmodel.EndDate.Value.ToString("yyyy年MM月"), StartDate = dmodel.StartDate.Value, EndDate = dmodel.EndDate.Value, Group_Id = dmodel.Group_Id, School_Id = dmodel.School_Id, CreateBy = dmodel.CreateBy, CreateTime = DateTime.Now, UpdateBy = dmodel.UpdateBy, UpdateTime = DateTime.Now, IsNormal = 1 }); if (dmodel.YearOKR == 1) { //今年 string YearName = dmodel.StartDate.Value.Year + "年度OKR"; if (!oKR_PeriodRepository.GetList(new RB_OKR_Period_ViewModel() { Group_Id = dmodel.Group_Id, IsNormal = 1, Name = YearName }).Any()) { oKR_PeriodRepository.Insert(new Model.Entity.OKR.RB_OKR_Period() { Id = 0, IsYear = 1, Status = 0, Name = YearName, StartDate = Convert.ToDateTime(dmodel.StartDate.Value.Year + "-01-01"), EndDate = Convert.ToDateTime(dmodel.StartDate.Value.Year + "-01-01 23:59:59").AddYears(1).AddDays(-1), Group_Id = dmodel.Group_Id, School_Id = dmodel.School_Id, CreateBy = dmodel.CreateBy, CreateTime = DateTime.Now, UpdateBy = dmodel.UpdateBy, UpdateTime = DateTime.Now, IsNormal = 1 }); } if (dmodel.StartDate.Value.Year != dmodel.EndDate.Value.Year) { //明年 string YearName1 = dmodel.EndDate.Value.Year + "年度OKR"; if (!oKR_PeriodRepository.GetList(new RB_OKR_Period_ViewModel() { Group_Id = dmodel.Group_Id, IsNormal = 1, Name = YearName1 }).Any()) { oKR_PeriodRepository.Insert(new Model.Entity.OKR.RB_OKR_Period() { Id = 0, IsYear = 1, Status = 0, Name = YearName1, StartDate = Convert.ToDateTime(dmodel.EndDate.Value.Year + "-01-01"), EndDate = Convert.ToDateTime(dmodel.EndDate.Value.Year + "-01-01 23:59:59").AddYears(1).AddDays(-1), Group_Id = dmodel.Group_Id, School_Id = dmodel.School_Id, CreateBy = dmodel.CreateBy, CreateTime = DateTime.Now, UpdateBy = dmodel.UpdateBy, UpdateTime = DateTime.Now, IsNormal = 1 }); } } } //看最新的天数 是否满足生成下一周期 if (dmodel.BeforeType == 1) { //天 var ds = dmodel.EndDate.Value - DateTime.Now; if (ds.TotalDays < dmodel.BeforeNum) { //生成下一个周期 CreatePeriodNext(dmodel); } } else { //月 var ds = DateTime.Now.AddMonths(dmodel.BeforeNum); if (ds > dmodel.EndDate) { //生成下一个周期 CreatePeriodNext(dmodel); } } //记录日志 changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "新增OKR周期配置", School_Id = userInfo.School_Id, SourceId = 0 }); } return flag ? "" : "失败了,请联系管理"; } } /// /// 创建下一个周期 /// /// public void CreatePeriodNext(RB_OKR_PeriodConfig_ViewModel dmodel, bool IsCreateYear = false) { DateTime STime = Convert.ToDateTime(dmodel.EndDate.Value.AddDays(1).ToString("yyyy-MM-dd")); DateTime ETime = Convert.ToDateTime(STime.AddMonths((int)dmodel.PeriodMonth).AddDays(-1).ToString("yyyy-MM-dd") + " 23:59:59"); //验证一下 当前时间周期是否存在 string Name = STime.ToString("yyyy年MM月") + "-" + ETime.ToString("yyyy年MM月"); if (!oKR_PeriodRepository.GetList(new RB_OKR_Period_ViewModel() { Group_Id = dmodel.Group_Id, IsNormal = 1, Name = Name }).Any()) { bool flag = oKR_PeriodRepository.Insert(new Model.Entity.OKR.RB_OKR_Period() { Id = 0, IsYear = 2, Status = 0, Name = Name, StartDate = STime, EndDate = ETime, Group_Id = dmodel.Group_Id, School_Id = dmodel.School_Id, CreateBy = dmodel.CreateBy, CreateTime = DateTime.Now, UpdateBy = dmodel.UpdateBy, UpdateTime = DateTime.Now, IsNormal = 1 }) > 0; if (flag && IsCreateYear && dmodel.YearOKR == 1) { DateTime YearStart = Convert.ToDateTime(ETime.Year + "-01-01"); if (STime <= YearStart && YearStart < ETime) { string YearName = YearStart.Year + "年度OKR"; if (!oKR_PeriodRepository.GetList(new RB_OKR_Period_ViewModel() { Group_Id = dmodel.Group_Id, IsNormal = 1, Name = YearName }).Any()) { //跨年了 直接新增该年 年度周期 oKR_PeriodRepository.Insert(new Model.Entity.OKR.RB_OKR_Period() { Id = 0, IsYear = 1, Status = 0, Name = YearName, StartDate = YearStart, EndDate = Convert.ToDateTime(YearStart.Year + "-01-01 23:59:59").AddYears(1).AddDays(-1), Group_Id = dmodel.Group_Id, School_Id = dmodel.School_Id, CreateBy = dmodel.CreateBy, CreateTime = DateTime.Now, UpdateBy = dmodel.UpdateBy, UpdateTime = DateTime.Now, IsNormal = 1 }); } } } } } /// /// 获取提醒设置列表 /// /// /// public List GetOKRRemindList(int group_Id) { var list = oKR_RemindRepository.GetList(new RB_OKR_Remind_ViewModel() { Group_Id = group_Id }); for (var i = 1; i <= 4; i++) { var model = list.Where(x => x.Type == i).FirstOrDefault(); if (model == null) { list.Add(new RB_OKR_Remind_ViewModel() { Days = "", Time = "", Type = i }); } } return list.OrderBy(x => x.Type).ToList(); } /// /// 设置OKR提现 /// /// /// /// public string SetOKRRemindInfo(RB_OKR_Remind_ViewModel dmodel, UserInfo userInfo) { var model = oKR_RemindRepository.GetList(new RB_OKR_Remind_ViewModel() { Group_Id = userInfo.Group_Id, Type = dmodel.Type }).FirstOrDefault(); if (model == null) { bool flag = oKR_RemindRepository.Insert(dmodel) > 0; if (flag) { //记录日志 changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "新增OKR提醒设置", School_Id = userInfo.School_Id, SourceId = 0 }); } return flag ? "" : "出错啦,请联系管理员"; } else { Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_Remind_ViewModel.Days),dmodel.Days}, { nameof(RB_OKR_Remind_ViewModel.Time),dmodel.Time}, { nameof(RB_OKR_Remind_ViewModel.UpdateBy),dmodel.UpdateBy}, { nameof(RB_OKR_Remind_ViewModel.UpdateTime),dmodel.UpdateTime} }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Remind_ViewModel.Id), FiledValue= model.Id, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_RemindRepository.Update(keyValues, wheres); if (flag) { //记录日志 changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "修改OKR提醒设置", School_Id = userInfo.School_Id, SourceId = 0 }); } return flag ? "" : "出错啦,请联系管理员"; } } /// /// 设置提醒状态 /// /// /// /// public bool SetOKRRemindEnable(int type, UserInfo userInfo) { var model = oKR_RemindRepository.GetList(new RB_OKR_Remind_ViewModel() { Group_Id = userInfo.Group_Id, Type = type }).FirstOrDefault(); if (model == null) { return false; } else { Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_Remind_ViewModel.Enable),model.Enable == 1 ? 2 : 1} }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Remind_ViewModel.Id), FiledValue= model.Id, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_RemindRepository.Update(keyValues, wheres); if (flag) { //记录日志 changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "修改OKR提醒启用禁用", School_Id = userInfo.School_Id, SourceId = 0 }); } return flag; } } /// /// 获取分数配置 /// /// /// /// /// /// public List GetOKRScoreConfigPageList(int pageIndex, int pageSize, out long count, RB_OKR_Score_ViewModel dmodel) { var list = oKR_ScoreRepository.GetPageList(pageIndex, pageSize, out count, dmodel); if (list.Any()) { string ids = string.Join(",", list.Select(x => x.Id)); var dlist = oKR_ScoreDetailRepository.GetList(new RB_OKR_ScoreDetail_ViewModel() { ScoreIds = ids }); foreach (var item in list) { item.DetailList = dlist.Where(x => x.ScoreId == item.Id).ToList(); } } return list; } /// /// 保存分数配置 /// /// /// /// public string SetOKRScoreConfigInfo(RB_OKR_Score_ViewModel dmodel, UserInfo userInfo) { if (dmodel.Id > 0) { Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_Score_ViewModel.Name),dmodel.Name} }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Score_ViewModel.Id), FiledValue=dmodel.Id, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_ScoreRepository.Update(keyValues, wheres); if (flag) { var list = oKR_ScoreDetailRepository.GetList(new RB_OKR_ScoreDetail_ViewModel() { ScoreId = dmodel.Id }); //删除后 再新增 oKR_ScoreDetailRepository.DeleteBatch(list); foreach (var item in dmodel.DetailList) { oKR_ScoreDetailRepository.Insert(new Model.Entity.OKR.RB_OKR_ScoreDetail() { Id = 0, Color = item.Color, Name = item.Name, ScoreId = dmodel.Id, ScoreMax = item.ScoreMax, ScoreMin = item.ScoreMin }); } //日志记录 changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "修改OKR分数配置【" + dmodel.Id + "】", School_Id = userInfo.School_Id, SourceId = 0 }); } return flag ? "" : "出错了,请联系管理员"; } else { int Id = oKR_ScoreRepository.Insert(dmodel); if (Id > 0) { //增加明细 foreach (var item in dmodel.DetailList) { oKR_ScoreDetailRepository.Insert(new Model.Entity.OKR.RB_OKR_ScoreDetail() { Id = 0, Color = item.Color, Name = item.Name, ScoreId = Id, ScoreMax = item.ScoreMax, ScoreMin = item.ScoreMin }); } //日志记录 changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "新增OKR分数配置【" + Id + "】", School_Id = userInfo.School_Id, SourceId = 0 }); } return Id > 0 ? "" : "出错了,请联系管理员"; } } /// /// 设置分数配置状态 /// /// /// /// /// public string SetOKRScoreConfigState(int scoreId, int type, UserInfo userInfo) { if (type == 1) { var model = oKR_ScoreRepository.GetEntity(scoreId); if (model == null) { return "分数规则不存在"; } Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_Score_ViewModel.IsDefault),model.IsDefault==1?2:1} }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Score_ViewModel.Id), FiledValue=scoreId, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_ScoreRepository.Update(keyValues, wheres); if (flag) { changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "修改OKR分数配置【" + scoreId + "】默认状态", School_Id = userInfo.School_Id, SourceId = 0 }); } return flag ? "" : "出错了,请联系管理员"; } else if (type == 2) { Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_Score_ViewModel.Status),1} }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Score_ViewModel.Id), FiledValue=scoreId, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_ScoreRepository.Update(keyValues, wheres); if (flag) { changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "删除OKR分数配置【" + scoreId + "】", School_Id = userInfo.School_Id, SourceId = 0 }); } return flag ? "" : "出错了,请联系管理员"; } else { return "类型不正确"; } } /// /// 获取更新历史分页列表 /// /// /// /// /// /// public List GetOKRObjectiveUpdateHistoryList(int pageIndex, int pageSize, out long count, RB_OKR_UpdateHistory_ViewModel dmodel) { return oKR_UpdateHistoryRepository.GetPageList(pageIndex, pageSize, out count, dmodel); } #endregion #region 规则管理 /// /// 获取规则分页列表 /// /// /// /// /// /// public List GetOKRRulePageList(int pageIndex, int pageSize, out long count, RB_OKR_Rule_ViewModel dmodel) { return oKR_RuleRepository.GetPageList(pageIndex, pageSize, out count, dmodel); } /// /// 获取规则信息 /// /// /// public RB_OKR_Rule_ViewModel GetOKRRuleModel(int RuleId) { return oKR_RuleRepository.GetEntity(RuleId); } /// /// 获取列表 /// /// /// public List GetOKRRuleDownLoadList(RB_OKR_Rule_ViewModel dmodel) { return oKR_RuleRepository.GetList(dmodel); } /// /// 新增修改规则 /// /// /// /// public bool SetOKRRuleInfo(RB_OKR_Rule_ViewModel dmodel, UserInfo userInfo) { if (dmodel.Id > 0) { Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_Rule_ViewModel.RuleName),dmodel.RuleName }, { nameof(RB_OKR_Rule_ViewModel.DataBase),dmodel.DataBase }, { nameof(RB_OKR_Rule_ViewModel.Table),dmodel.Table }, { nameof(RB_OKR_Rule_ViewModel.Field),dmodel.Field }, { nameof(RB_OKR_Rule_ViewModel.Way),dmodel.Way }, { nameof(RB_OKR_Rule_ViewModel.State),dmodel.State }, { nameof(RB_OKR_Rule_ViewModel.Identity),dmodel.Identity }, { nameof(RB_OKR_Rule_ViewModel.Time),dmodel.Time }, { nameof(RB_OKR_Rule_ViewModel.Remark),dmodel.Remark }, }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Rule_ViewModel.Id), FiledValue=dmodel.Id, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_RuleRepository.Update(keyValues, wheres); if (flag) { changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "修改OKR结果规则【" + dmodel.Id + "】", School_Id = userInfo.School_Id, SourceId = 0 }); } return flag; } else { dmodel.Enable = dmodel.Enable == 0 ? 1 : dmodel.Enable; int id = oKR_RuleRepository.Insert(dmodel); bool flag = id > 0; if (flag) { changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "新增OKR结果规则【" + id + "】", School_Id = userInfo.School_Id, SourceId = 0 }); } return flag; } } /// /// 设置规则状态 /// /// /// /// /// public string SetOKRRuleState(int ruleId, int type, UserInfo userInfo) { Dictionary keyValues = new Dictionary() { }; if (type == 1) { keyValues.Add(nameof(RB_OKR_Rule_ViewModel.Enable), 1); } else if (type == 2) { keyValues.Add(nameof(RB_OKR_Rule_ViewModel.Enable), 2); } else if (type == 3) { keyValues.Add(nameof(RB_OKR_Rule_ViewModel.Status), 1); } else { return "状态不正确"; } List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Rule_ViewModel.Id), FiledValue=ruleId, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_RuleRepository.Update(keyValues, wheres); if (flag) { changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "修改OKR结果规则状态【" + ruleId + "】" + (type == 1 ? "启用" : type == 2 ? "禁用" : "删除"), School_Id = userInfo.School_Id, SourceId = 0 }); return ""; } return "出错了,请联系管理员"; } /// /// 关键结果绑定规则 /// /// /// /// public string SetOKRKeyResultUseRule(RB_OKR_KeyResult_ViewModel dmodel, UserInfo userInfo) { var ruleModel = oKR_RuleRepository.GetEntity(dmodel.RuleId); if (ruleModel == null) { return "规则不存在"; } if (ruleModel.Status == 1 || ruleModel.Enable == 2) { return "规则状态不正确"; } Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_KeyResult_ViewModel.RuleId),dmodel.RuleId}, { nameof(RB_OKR_KeyResult_ViewModel.RuleSTime),dmodel.RuleSTime}, { nameof(RB_OKR_KeyResult_ViewModel.RuleETime),dmodel.RuleETime}, { nameof(RB_OKR_KeyResult_ViewModel.StartValue),dmodel.StartValue}, { nameof(RB_OKR_KeyResult_ViewModel.EndValue),dmodel.EndValue}, { nameof(RB_OKR_KeyResult_ViewModel.IsEasyMode),2}, }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_KeyResult_ViewModel.Id), FiledValue=dmodel.Id, OperatorEnum=OperatorEnum.Equal } }; var trans = oKR_KeyResultRepository.DbTransaction; try { bool flag = oKR_KeyResultRepository.Update(keyValues, wheres, trans); if (flag) { //关联表信息 var list = oKR_RuleRelationRepository.GetList(new RB_OKR_RuleRelation_ViewModel() { KeyResultId = dmodel.Id }); if (list.Any()) { var deptList = dmodel.RelationList.Where(x => x.Type == 1).ToList(); var empList = dmodel.RelationList.Where(x => x.Type == 2).ToList(); var hdeptList = list.Where(x => x.Type == 1).ToList(); var hempList = list.Where(x => x.Type == 2).ToList(); var deptInsert = deptList.Where(y => !hdeptList.Select(x => x.RelationId).Contains(y.RelationId)).ToList(); var deptDelete = hdeptList.Where(y => !deptList.Select(x => x.RelationId).Contains(y.RelationId)).ToList(); foreach (var item in deptInsert) { oKR_RuleRelationRepository.Insert(new Model.Entity.OKR.RB_OKR_RuleRelation() { Id = 0, KeyResultId = dmodel.Id, RelationId = item.RelationId, Type = item.Type }, trans); } foreach (var item in deptDelete) { oKR_RuleRelationRepository.Delete(item, trans); } var empInsert = empList.Where(y => !hempList.Select(x => x.RelationId).Contains(y.RelationId)).ToList(); var empDelete = hempList.Where(y => !empList.Select(x => x.RelationId).Contains(y.RelationId)).ToList(); foreach (var item in empInsert) { oKR_RuleRelationRepository.Insert(new Model.Entity.OKR.RB_OKR_RuleRelation() { Id = 0, KeyResultId = dmodel.Id, RelationId = item.RelationId, Type = item.Type }, trans); } foreach (var item in empDelete) { oKR_RuleRelationRepository.Delete(item, trans); } } else { //直接新增 foreach (var item in dmodel.RelationList) { oKR_RuleRelationRepository.Insert(new Model.Entity.OKR.RB_OKR_RuleRelation() { Id = 0, KeyResultId = dmodel.Id, RelationId = item.RelationId, Type = item.Type }, trans); } } changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "修改OKR结果使用规则【" + dmodel.Id + "】", School_Id = userInfo.School_Id, SourceId = 0 }); } oKR_KeyResultRepository.DBSession.Commit(); return flag ? "" : "出错了,请联系管理员"; } catch (Exception ex) { LogHelper.Write(ex, "SetOKRKeyResultUseRule"); oKR_KeyResultRepository.DBSession.Rollback(); return "出错了,请联系管理员"; } } /// /// 获取关键结果关联部门/人员 /// /// /// /// public List GetOKRKeyResultRuleReList(int keyResultId, UserInfo userInfo) { var list = oKR_RuleRelationRepository.GetList(new RB_OKR_RuleRelation_ViewModel() { KeyResultId = keyResultId }); if (list.Any()) { var dlist = list.Where(x => x.Type == 1).ToList(); var elist = list.Where(x => x.Type == 2).ToList(); if (dlist.Any()) { string deptIds = string.Join(",", dlist.Select(x => x.RelationId)); var d2list = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, School_Id = userInfo.School_Id, QDeptIds = deptIds }); foreach (var item in dlist) { item.RelationName = d2list.Where(x => x.DeptId == item.RelationId).FirstOrDefault()?.DeptName ?? ""; } } if (elist.Any()) { string empIds = string.Join(",", elist.Select(x => x.RelationId)); var e2list = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { QIds = empIds, IsLeave = 1 }); foreach (var item in elist) { var emModel = e2list.Where(x => x.Id == item.RelationId).FirstOrDefault(); item.RelationName = emModel?.EmployeeName ?? ""; item.UserIcon = emModel?.UserIcon ?? ""; item.PostName = emModel?.PostName ?? ""; item.DeptName = emModel?.DeptName ?? ""; } } } return list; } /// /// 获取关键结果关联部门/人员 /// /// /// public List GetOKRKeyResultRuleReList(int keyResultId) { var list = oKR_RuleRelationRepository.GetList(new RB_OKR_RuleRelation_ViewModel() { KeyResultId = keyResultId }); return list; } /// /// 获取我负责的部门列表 /// /// /// public object GetOKRMyManageDepartment(UserInfo userInfo) { var RList = new List(); var list = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, ManagerIds = userInfo.Id.ToString() }); foreach (var item in list) { var dlist = departmentRepository.GetCurrentAndChildDepartmentListRepository(item.DeptId); foreach (var qitem in dlist) { RList.Add(new { qitem.DeptId, qitem.DeptName }); } } return RList; } /// /// 获取我负责的部门 树形 /// /// /// public object GetOKRMyManageDepartment_V2(UserInfo userInfo) { var RList = new List(); var list = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, ManagerIds = userInfo.Id.ToString() }); foreach (var item in list) { var dlist = departmentRepository.GetCurrentAndChildDepartmentListRepository(item.DeptId); RList.AddRange(GetChildDepartment(item, dlist)); } return RList; } /// /// 递归获取所有子集部门 /// /// /// /// public List GetChildDepartment(Model.ViewModel.User.RB_Department_ViewModel dmodel, List list) { var ChildList = new List(); var clist = list.Where(x => x.ParentId == dmodel.DeptId).ToList(); foreach (var item in clist) { ChildList.AddRange(GetChildDepartment(item, list)); } return new List() { new { dmodel.DeptId, dmodel.DeptName, ChildList } }; } /// /// 获取我的直属下级人员 /// /// /// public object GetOKRMyChildEmployeeList(UserInfo userInfo) { var UserIdList = GetMyUnderlingUserIdList(userInfo); var list = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { QIds = string.Join(",", UserIdList), IsLeave = 1 }); return list.Select(x => new { x.Id, x.EmployeeName, x.UserIcon, x.DeptName, x.PostName }); } /// /// 取消关键结果使用规则 /// /// /// /// public string CancelOKRKeyResultUseRule(int keyResultId, UserInfo userInfo) { Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_KeyResult_ViewModel.RuleId),0}, { nameof(RB_OKR_KeyResult_ViewModel.RuleSTime),null}, { nameof(RB_OKR_KeyResult_ViewModel.RuleETime),null} }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_KeyResult_ViewModel.Id), FiledValue=keyResultId, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_KeyResultRepository.Update(keyValues, wheres); if (flag) { changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "取消OKR结果使用规则【" + keyResultId + "】", School_Id = userInfo.School_Id, SourceId = 0 }); } return flag ? "" : "出错了,请联系管理员"; } /// /// 更新适配规则的结果进度 /// /// /// public bool UpdateOKRKeyresultRuleProgress(RB_OKR_KeyResult_ViewModel dmodel) { //查询结果适配部门/人员列表 List empIdList = new List() { dmodel.CreateBy }; var reList = GetOKRKeyResultRuleReList(dmodel.Id); foreach (var qitem in reList.Where(x => x.Type == 2)) { empIdList.Add(qitem.RelationId); } //根据部门 获取部门下所有的人员 if (reList.Where(x => x.Type == 1).Any()) { var em1List = GetDepartmentEmployeeList(dmodel.Group_Id, string.Join(",", reList.Where(x => x.Type == 1).Select(x => x.RelationId))); foreach (var qitem in em1List) { empIdList.Add(qitem.Id); } } empIdList = empIdList.Distinct().ToList(); //根据规则 查询当前结果的进度 if (empIdList.Any()) { var ruleModel = GetOKRRuleModel(dmodel.RuleId); string way = ""; switch (ruleModel.Way) { case Edu.Common.Enum.OKR.RuleTypeEnum.Avg: way = "Avg"; break; case Edu.Common.Enum.OKR.RuleTypeEnum.Count: way = "Count"; break; case Edu.Common.Enum.OKR.RuleTypeEnum.Max: way = "Max"; break; case Edu.Common.Enum.OKR.RuleTypeEnum.Min: way = "Min"; break; case Edu.Common.Enum.OKR.RuleTypeEnum.Sum: way = "Sum"; break; } //组装sql语句 string sql = $@" select {way}({ruleModel.Field}) from {ruleModel.DataBase}.{ruleModel.Table} where {ruleModel.State} and {ruleModel.Identity} in({string.Join(",", empIdList)}) and {ruleModel.Time} >='{dmodel.RuleSTime.Value:yyyy-MM-dd}' and {ruleModel.Time} <='{dmodel.RuleETime.Value:yyyy-MM-dd HH:mm:ss}'"; //查询sql值 var obj = oKR_RuleRepository.ExecuteScalar(sql); decimal CurrentValue = obj == null ? 0 : Convert.ToDecimal(obj); CurrentValue += dmodel.StartValue; //重新更新进度,以及目标进度 SgetOKRMyKeyResultProgress(0, 2, 0, dmodel.StartValue, dmodel.EndValue, CurrentValue, new UserInfo() { Group_Id = dmodel.Group_Id }, dmodel); } return true; } #endregion #region 目标管理 /// /// 获取周期列表 /// /// /// public List GetOKRPeriodList(int group_Id) { var list = oKR_PeriodRepository.GetList(new RB_OKR_Period_ViewModel() { Group_Id = group_Id }); foreach (var item in list) { item.IsCurrent = 2; if (item.StartDate <= DateTime.Now && item.EndDate >= DateTime.Now && item.IsNormal == 1 && item.IsYear == 2) { item.IsCurrent = 1; } } return list; } /// /// 获取当前周期 /// /// /// public List GetCurrentPeriodList(int GroupId) { return oKR_PeriodRepository.GetList(new RB_OKR_Period_ViewModel() { Group_Id = GroupId, IsCurrent = 1, IsNormal = 1, IsYear = 2 }); } /// /// 获取我的目标列表 /// /// /// /// public object GetOKRMyObjectiveList(int PeriodId, UserInfo userInfo) { var list = oKR_ObjectiveRepository.GetList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, CreateBy = userInfo.Id }); if (list.Any()) { List MyUnderlingList = GetMyUnderlingUserIdList(userInfo); string objectiveIds = string.Join(",", list.Select(x => x.Id)); //查询向上对齐 var sdqlist = oKR_ObjectiveRepository.GetParentList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, ObjectiveIds = objectiveIds }); //查询向下对齐 var xdqlist = oKR_ObjectiveRepository.GetParentList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, ParentIds = objectiveIds }); string jObjectiveIds = objectiveIds; if (sdqlist.Any()) { jObjectiveIds += "," + string.Join(",", sdqlist.Select(x => x.Id)); } if (xdqlist.Any()) { jObjectiveIds += "," + string.Join(",", xdqlist.Select(x => x.Id)); } //查询结果列表 var krList = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveIds = jObjectiveIds }); //查询是否有权限 var pList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 2, ObjectiveIds = jObjectiveIds }); var pkrList = new List(); if (krList.Any()) { string krIds = string.Join(",", krList.Select(x => x.Id)); pkrList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 3, ObjectiveIds = krIds }); } //查询分数规则 string scoreRuleIds = string.Join(",", list.Where(x => x.ScoreRuleId > 0).Select(x => x.ScoreRuleId)); var ScoreRuleList = new List(); if (!string.IsNullOrEmpty(scoreRuleIds)) { ScoreRuleList = oKR_ScoreDetailRepository.GetList(new RB_OKR_ScoreDetail_ViewModel() { ScoreIds = scoreRuleIds }); } //查询规则名称 string ruleIds = string.Join(",", krList.Where(x => x.RuleId > 0).Select(x => x.RuleId).Distinct()); var krRuleList = new List(); if (!string.IsNullOrEmpty(ruleIds)) { krRuleList = oKR_RuleRepository.GetList(new RB_OKR_Rule_ViewModel() { RuleIds = ruleIds }); } foreach (var item in sdqlist) { item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); GetDQListLookPermission(userInfo, MyUnderlingList, pList, pkrList, item); } foreach (var item in xdqlist) { item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); GetDQListLookPermission(userInfo, MyUnderlingList, pList, pkrList, item); } foreach (var item in list) { item.IsLock = 2; if (item.IsDefaultPermission == 2 || pList.Where(x => x.TargetId == item.Id).Any()) { item.IsLock = 1; } //结果列表 item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); foreach (var qitem in item.KeyResultList) { qitem.IsLock = 2; if (qitem.IsDefaultPermission == 2 || pkrList.Where(x => x.TargetId == qitem.Id).Any()) { qitem.IsLock = 1; } if (qitem.RuleId > 0) { qitem.RuleName = krRuleList.Where(x => x.Id == qitem.RuleId).FirstOrDefault()?.RuleName ?? ""; } } if (item.IsDefaultState == 1 && item.KeyResultList.Any()) { item.ProgressState = item.KeyResultList.Max(x => x.ProgressState); } #region 对齐列表 var sdqclist = sdqlist.Where(x => x.ObjectiveId == item.Id).ToList(); List EmIdList = sdqclist.Select(x => x.CreateBy).Distinct().ToList(); item.ParentList = new List(); foreach (var qitem in EmIdList) { item.ParentList.Add(new ObjectiveEmployeeModel() { AccountId = qitem, AccountName = sdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmName, Icon = sdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmPhoto, AlignList = sdqclist.Where(x => x.CreateBy == qitem).ToList() }); } var xdqclist = xdqlist.Where(x => x.ParentId == item.Id).ToList(); List EmIdList2 = xdqclist.Select(x => x.CreateBy).Distinct().ToList(); item.ChildList = new List(); foreach (var qitem in EmIdList2) { item.ChildList.Add(new ObjectiveEmployeeModel() { AccountId = qitem, AccountName = xdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmName, Icon = xdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmPhoto, AlignList = xdqclist.Where(x => x.CreateBy == qitem).ToList() }); } #endregion #region 分数显示 item.ScoreName = ""; item.ScoreColor = ""; if (item.ScoreRuleId > 0) { var scoreRuleModel = ScoreRuleList.Where(x => x.ScoreId == item.ScoreRuleId && x.ScoreMin <= item.Score && x.ScoreMax >= item.Score).FirstOrDefault(); item.ScoreName = scoreRuleModel?.Name ?? ""; item.ScoreColor = scoreRuleModel?.Color ?? ""; foreach (var qitem in item.KeyResultList) { var qscoreRuleModel = ScoreRuleList.Where(x => x.ScoreId == item.ScoreRuleId && x.ScoreMin <= qitem.Score && x.ScoreMax >= qitem.Score).FirstOrDefault(); qitem.ScoreName = qscoreRuleModel?.Name ?? ""; qitem.ScoreColor = qscoreRuleModel?.Color ?? ""; } } #endregion } } return list.Select(x => new { x.Id, x.Title, x.Sort, x.Progress, x.Weight, x.Score, x.ProgressRemark, x.IsDefaultState, x.ProgressState, ProgressStateName = x.ProgressState.ToName(), x.Status, x.IsLock, x.IsNotLook, x.ScoreName, x.ScoreColor, CreateTime = x.CreateTime.ToString("MM-dd"), KeyResultList = x.KeyResultList.Select(z => new { z.Id, z.Name, z.Sort, z.Progress, z.Weight, z.Score, z.ProgressState, ProgressStateName = z.ProgressState.ToName(), z.StartValue, z.EndValue, z.CurrentValue, z.IsEasyMode, z.IsLock, z.IsNotLook, z.ScoreName, z.ScoreColor, z.RuleId, z.RuleName, RuleSTime = z.RuleSTime.HasValue ? z.RuleSTime.Value.ToString("yyyy-MM-dd") : "", RuleETime = z.RuleETime.HasValue ? z.RuleETime.Value.ToString("yyyy-MM-dd") : "" }), ParentList = x.ParentList.Select(y => new { y.AccountId, y.AccountName, y.Icon, AlignList = y.AlignList.Select(q => new { q.Id, Title = q.IsNotLook == 1 ? "" : q.Title, q.Sort, q.IsLock, q.IsNotLook, KeyResultList = q.KeyResultList.OrderBy(q => q.Sort).Select(z => new { z.Id, Name = z.IsNotLook == 1 ? "" : z.Name, z.Sort, z.IsLock, z.IsNotLook }), }) }), ChildList = x.ChildList.Select(y => new { y.AccountId, y.AccountName, y.Icon, AlignList = y.AlignList.Select(q => new { q.Id, Title = q.IsNotLook == 1 ? "" : q.Title, q.Sort, q.IsLock, q.IsNotLook, KeyResultList = q.KeyResultList.OrderBy(q => q.Sort).Select(z => new { z.Id, Name = z.IsNotLook == 1 ? "" : z.Name, z.Sort, z.IsLock, z.IsNotLook }), }) }), x.AuditRemark, AuditTime = Common.ConvertHelper.FormatTime(x.AuditTime), x.AuditUserId, AuditUserName = UserReidsCache.GetUserLoginInfo((x.AuditUserId > 0 ? x.AuditUserId : 0))?.AccountName ?? "", UserIcon = UserReidsCache.GetUserLoginInfo((x.AuditUserId > 0 ? x.AuditUserId : 0))?.UserIcon ?? "", }); } /// /// 获取目标/结果的对应用户权限 /// /// /// /// /// /// private static void GetDQListLookPermission(UserInfo userInfo, List MyUnderlingList, List pList, List pkrList, RB_OKR_Objective_ViewModel item) { item.IsLock = 2; item.IsNotLook = 2; if (pList.Where(x => x.TargetId == item.Id).Any()) { item.IsLock = 1; if (!MyUnderlingList.Contains(item.CreateBy)) { var NotLookList = pList.Where(x => x.TargetId == item.Id && x.State == 2).ToList(); var LookList = pList.Where(x => x.TargetId == item.Id && x.State == 1).ToList(); if (NotLookList.Any()) { //有不可看的 if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any()) { item.IsNotLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any()) { item.IsNotLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { item.IsNotLook = 1; } } if (item.IsNotLook == 2 && item.IsDefaultPermission == 2) { if (LookList.Any()) { if (LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { //OK } else { item.IsNotLook = 1; } } } } } else { if (item.IsDefaultPermission == 2) { item.IsLock = 1; if (!MyUnderlingList.Contains(item.CreateBy)) { item.IsNotLook = 1; } } } foreach (var qitem in item.KeyResultList) { qitem.IsLock = 2; qitem.IsNotLook = 2; if (pkrList.Where(x => x.TargetId == qitem.Id).Any()) { qitem.IsLock = 1; if (!MyUnderlingList.Contains(item.CreateBy)) { var NotLookList = pkrList.Where(x => x.TargetId == qitem.Id && x.State == 2).ToList(); var LookList = pkrList.Where(x => x.TargetId == qitem.Id && x.State == 1).ToList(); if (NotLookList.Any()) { //有不可看的 if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any()) { qitem.IsNotLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any()) { qitem.IsNotLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { qitem.IsNotLook = 1; } } if (qitem.IsNotLook == 2 && qitem.IsDefaultPermission == 2) { if (LookList.Any()) { if (LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { //OK } else { qitem.IsNotLook = 1; } } } } } else { if (qitem.IsDefaultPermission == 2) { qitem.IsLock = 1; if (!MyUnderlingList.Contains(item.CreateBy)) { qitem.IsNotLook = 1; } } } } } /// /// 获取他人的目标列表 /// /// /// /// /// public object GetOKROthersObjectiveList(int PeriodId, int userId, UserInfo userInfo) { List MyUnderlingList = GetMyUnderlingUserIdList(userInfo); if (!MyUnderlingList.Contains(userId)) { var pplist = oKR_PeriodPermissionRepository.GetList(new Model.Entity.OKR.RB_OKR_PeriodPermission() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, CreateBy = userId }); //查询是否有权限 var zpList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 1, TargetId = PeriodId, CreateBy = userId }); if (zpList.Any()) { var NotLookList = zpList.Where(x => x.State == 2).ToList(); var LookList = zpList.Where(x => x.State == 1).ToList(); if (NotLookList.Any()) { //有不可看的 if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any()) { return new { Status = 2, Msg = "没有权限查询" }; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any()) { return new { Status = 2, Msg = "没有权限查询" }; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { return new { Status = 2, Msg = "没有权限查询" }; } } if (LookList.Any() && pplist.Any()) { if (LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { //OK } else { return new { Status = 2, Msg = "没有权限查询" }; } } } else { if (pplist.Any()) { return new { Status = 2, Msg = "没有权限查询" }; } } } // var list = oKR_ObjectiveRepository.GetList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, CreateBy = userId, Status = 2 }); var list = oKR_ObjectiveRepository.GetList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, CreateBy = userId, selectStatus = 1 }); if (list.Any()) { string objectiveIds = string.Join(",", list.Select(x => x.Id)); //查询向上对齐 var sdqlist = oKR_ObjectiveRepository.GetParentList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, ObjectiveIds = objectiveIds }); //查询向下对齐 var xdqlist = oKR_ObjectiveRepository.GetParentList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, ParentIds = objectiveIds }); string jObjectiveIds = objectiveIds; if (sdqlist.Any()) { jObjectiveIds += "," + string.Join(",", sdqlist.Select(x => x.Id)); } if (xdqlist.Any()) { jObjectiveIds += "," + string.Join(",", xdqlist.Select(x => x.Id)); } //查询结果列表 var krList = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveIds = jObjectiveIds }); //查询是否有权限 var pList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 2, ObjectiveIds = jObjectiveIds }); var pkrList = new List(); if (krList.Any()) { string krIds = string.Join(",", krList.Select(x => x.Id)); pkrList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 3, ObjectiveIds = krIds }); } string scoreRuleIds = string.Join(",", list.Where(x => x.ScoreRuleId > 0).Select(x => x.ScoreRuleId)); var ScoreRuleList = new List(); if (!string.IsNullOrEmpty(scoreRuleIds)) { ScoreRuleList = oKR_ScoreDetailRepository.GetList(new RB_OKR_ScoreDetail_ViewModel() { ScoreIds = scoreRuleIds }); } //查询规则名称 string ruleIds = string.Join(",", krList.Where(x => x.RuleId > 0).Select(x => x.RuleId).Distinct()); var krRuleList = new List(); if (!string.IsNullOrEmpty(ruleIds)) { krRuleList = oKR_RuleRepository.GetList(new RB_OKR_Rule_ViewModel() { RuleIds = ruleIds }); } foreach (var item in sdqlist) { item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); GetDQListLookPermission_V2(userInfo, MyUnderlingList, pList, pkrList, item); } foreach (var item in xdqlist) { item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); GetDQListLookPermission_V2(userInfo, MyUnderlingList, pList, pkrList, item); } foreach (var item in list) { item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); GetDQListLookPermission_V2(userInfo, MyUnderlingList, pList, pkrList, item); foreach (var qitem in item.KeyResultList) { if (qitem.RuleId > 0) { qitem.RuleName = krRuleList.Where(x => x.Id == qitem.RuleId).FirstOrDefault()?.RuleName ?? ""; } } if (item.IsDefaultState == 1 && item.KeyResultList.Any()) { item.ProgressState = item.KeyResultList.Max(x => x.ProgressState); } #region 对齐列表 var sdqclist = sdqlist.Where(x => x.ObjectiveId == item.Id).ToList(); List EmIdList = sdqclist.Select(x => x.CreateBy).Distinct().ToList(); item.ParentList = new List(); foreach (var qitem in EmIdList) { item.ParentList.Add(new ObjectiveEmployeeModel() { AccountId = qitem, AccountName = sdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmName, Icon = sdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmPhoto, AlignList = sdqclist.Where(x => x.CreateBy == qitem).ToList() }); } var xdqclist = xdqlist.Where(x => x.ParentId == item.Id).ToList(); List EmIdList2 = xdqclist.Select(x => x.CreateBy).Distinct().ToList(); item.ChildList = new List(); foreach (var qitem in EmIdList2) { item.ChildList.Add(new ObjectiveEmployeeModel() { AccountId = qitem, AccountName = xdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmName, Icon = xdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmPhoto, AlignList = xdqclist.Where(x => x.CreateBy == qitem).ToList() }); } #endregion #region 分数显示 item.ScoreName = ""; item.ScoreColor = ""; if (item.ScoreRuleId > 0) { var scoreRuleModel = ScoreRuleList.Where(x => x.ScoreId == item.ScoreRuleId && x.ScoreMin <= item.Score && x.ScoreMax >= item.Score).FirstOrDefault(); item.ScoreName = scoreRuleModel?.Name ?? ""; item.ScoreColor = scoreRuleModel?.Color ?? ""; foreach (var qitem in item.KeyResultList) { var qscoreRuleModel = ScoreRuleList.Where(x => x.ScoreId == item.ScoreRuleId && x.ScoreMin <= qitem.Score && x.ScoreMax >= qitem.Score).FirstOrDefault(); qitem.ScoreName = qscoreRuleModel?.Name ?? ""; qitem.ScoreColor = qscoreRuleModel?.Color ?? ""; } } #endregion } } return new { Status = 1, List = list.Where(x => x.IsNotLook == 2).Select(x => new { x.Title, x.Id, x.Sort, x.Progress, x.Weight, x.Score, x.ProgressRemark, x.IsDefaultState, x.ProgressState, ProgressStateName = x.ProgressState.ToName(), x.Status, x.IsLock, x.IsNotLook, x.ScoreName, x.ScoreColor, CreateTime = x.CreateTime.ToString("MM-dd"), KeyResultList = x.KeyResultList.Where(x => x.IsNotLook == 2).Select(z => new { z.Id, z.Name, z.Sort, z.Progress, z.Weight, z.Score, z.ProgressState, ProgressStateName = z.ProgressState.ToName(), z.StartValue, z.EndValue, z.CurrentValue, z.IsEasyMode, z.IsLock, z.IsNotLook, z.ScoreName, z.ScoreColor, z.RuleId, z.RuleName, RuleSTime = z.RuleSTime.HasValue ? z.RuleSTime.Value.ToString("yyyy-MM-dd") : "", RuleETime = z.RuleETime.HasValue ? z.RuleETime.Value.ToString("yyyy-MM-dd") : "" }), ParentList = x.ParentList.Select(y => new { y.AccountId, y.AccountName, y.Icon, AlignList = y.AlignList.Select(q => new { q.Id, Title = q.IsNotLook == 1 ? "" : q.Title, q.Sort, q.IsLock, q.IsNotLook, KeyResultList = q.KeyResultList.OrderBy(q => q.Sort).Select(z => new { z.Id, Name = z.IsNotLook == 1 ? "" : z.Name, z.Sort, z.IsLock, z.IsNotLook }), }) }), ChildList = x.ChildList.Select(y => new { y.AccountId, y.AccountName, y.Icon, AlignList = y.AlignList.Select(q => new { q.Id, Title = q.IsNotLook == 1 ? "" : q.Title, q.Sort, q.IsLock, q.IsNotLook, KeyResultList = q.KeyResultList.OrderBy(q => q.Sort).Select(z => new { z.Id, Name = z.IsNotLook == 1 ? "" : z.Name, z.Sort, z.IsLock, z.IsNotLook }), }) }), x.AuditRemark, AuditTime = Common.ConvertHelper.FormatTime(x.AuditTime), x.AuditUserId, AuditUserName = UserReidsCache.GetUserLoginInfo((x.AuditUserId > 0 ? x.AuditUserId : 0))?.AccountName ?? "", UserIcon = UserReidsCache.GetUserLoginInfo((x.AuditUserId > 0 ? x.AuditUserId : 0))?.UserIcon ?? "", }) }; } /// /// 获取他人单个目标 /// /// /// /// public object GetOKROthersObjectiveInfo(int PeriodId, int userId, int objectiveId, UserInfo userInfo) { List MyUnderlingList = GetMyUnderlingUserIdList(userInfo); if (!MyUnderlingList.Contains(userId)) { var pplist = oKR_PeriodPermissionRepository.GetList(new Model.Entity.OKR.RB_OKR_PeriodPermission() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, CreateBy = userId }); //查询是否有权限 var zpList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 1, TargetId = PeriodId, CreateBy = userId }); if (zpList.Any()) { var NotLookList = zpList.Where(x => x.State == 2).ToList(); var LookList = zpList.Where(x => x.State == 1).ToList(); if (NotLookList.Any()) { //有不可看的 if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any()) { return new { Status = 2, Msg = "没有权限查询" }; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any()) { return new { Status = 2, Msg = "没有权限查询" }; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { return new { Status = 2, Msg = "没有权限查询" }; } } if (LookList.Any() && pplist.Any()) { if (LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { //OK } else { return new { Status = 2, Msg = "没有权限查询" }; } } } else { if (pplist.Any()) { return new { Status = 2, Msg = "没有权限查询" }; } } } var list = oKR_ObjectiveRepository.GetList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, Id = objectiveId, PeriodId = PeriodId, CreateBy = userId, Status = 2 }); if (list.Any()) { string objectiveIds = string.Join(",", list.Select(x => x.Id)); //查询向上对齐 var sdqlist = oKR_ObjectiveRepository.GetParentList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, ObjectiveIds = objectiveIds }); //查询向下对齐 var xdqlist = oKR_ObjectiveRepository.GetParentList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, ParentIds = objectiveIds }); string jObjectiveIds = objectiveIds; if (sdqlist.Any()) { jObjectiveIds += "," + string.Join(",", sdqlist.Select(x => x.Id)); } if (xdqlist.Any()) { jObjectiveIds += "," + string.Join(",", xdqlist.Select(x => x.Id)); } //查询结果列表 var krList = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveIds = jObjectiveIds }); //查询是否有权限 var pList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 2, ObjectiveIds = jObjectiveIds }); var pkrList = new List(); if (krList.Any()) { string krIds = string.Join(",", krList.Select(x => x.Id)); pkrList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 3, ObjectiveIds = krIds }); } string scoreRuleIds = string.Join(",", list.Where(x => x.ScoreRuleId > 0).Select(x => x.ScoreRuleId)); var ScoreRuleList = new List(); if (!string.IsNullOrEmpty(scoreRuleIds)) { ScoreRuleList = oKR_ScoreDetailRepository.GetList(new RB_OKR_ScoreDetail_ViewModel() { ScoreIds = scoreRuleIds }); } //查询规则名称 string ruleIds = string.Join(",", krList.Where(x => x.RuleId > 0).Select(x => x.RuleId).Distinct()); var krRuleList = new List(); if (!string.IsNullOrEmpty(ruleIds)) { krRuleList = oKR_RuleRepository.GetList(new RB_OKR_Rule_ViewModel() { RuleIds = ruleIds }); } foreach (var item in sdqlist) { item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); GetDQListLookPermission_V2(userInfo, MyUnderlingList, pList, pkrList, item); } foreach (var item in xdqlist) { item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); GetDQListLookPermission_V2(userInfo, MyUnderlingList, pList, pkrList, item); } foreach (var item in list) { item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); GetDQListLookPermission_V2(userInfo, MyUnderlingList, pList, pkrList, item); foreach (var qitem in item.KeyResultList) { if (qitem.RuleId > 0) { qitem.RuleName = krRuleList.Where(x => x.Id == qitem.RuleId).FirstOrDefault()?.RuleName ?? ""; } } if (item.IsDefaultState == 1 && item.KeyResultList.Any()) { item.ProgressState = item.KeyResultList.Max(x => x.ProgressState); } #region 对齐列表 var sdqclist = sdqlist.Where(x => x.ObjectiveId == item.Id).ToList(); List EmIdList = sdqclist.Select(x => x.CreateBy).Distinct().ToList(); item.ParentList = new List(); foreach (var qitem in EmIdList) { item.ParentList.Add(new ObjectiveEmployeeModel() { AccountId = qitem, AccountName = sdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmName, Icon = sdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmPhoto, AlignList = sdqclist.Where(x => x.CreateBy == qitem).ToList() }); } var xdqclist = xdqlist.Where(x => x.ParentId == item.Id).ToList(); List EmIdList2 = xdqclist.Select(x => x.CreateBy).Distinct().ToList(); item.ChildList = new List(); foreach (var qitem in EmIdList2) { item.ChildList.Add(new ObjectiveEmployeeModel() { AccountId = qitem, AccountName = xdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmName, Icon = xdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmPhoto, AlignList = xdqclist.Where(x => x.CreateBy == qitem).ToList() }); } #endregion #region 分数显示 item.ScoreName = ""; item.ScoreColor = ""; if (item.ScoreRuleId > 0) { var scoreRuleModel = ScoreRuleList.Where(x => x.ScoreId == item.ScoreRuleId && x.ScoreMin <= item.Score && x.ScoreMax >= item.Score).FirstOrDefault(); item.ScoreName = scoreRuleModel?.Name ?? ""; item.ScoreColor = scoreRuleModel?.Color ?? ""; foreach (var qitem in item.KeyResultList) { var qscoreRuleModel = ScoreRuleList.Where(x => x.ScoreId == item.ScoreRuleId && x.ScoreMin <= qitem.Score && x.ScoreMax >= qitem.Score).FirstOrDefault(); qitem.ScoreName = qscoreRuleModel?.Name ?? ""; qitem.ScoreColor = qscoreRuleModel?.Color ?? ""; } } #endregion } } var x = list.Where(x => x.IsNotLook == 2).FirstOrDefault(); if (x == null) { return new { Status = 2, Msg = "没有权限查询" }; } return new { x.Id, x.Title, x.Sort, x.Progress, x.Weight, x.Score, x.ProgressRemark, x.IsDefaultState, x.ProgressState, ProgressStateName = x.ProgressState.ToName(), x.Status, x.IsLock, x.IsNotLook, x.ScoreName, x.ScoreColor, KeyResultList = x.KeyResultList.Where(x => x.IsNotLook == 2).Select(z => new { z.Id, z.Name, z.Sort, z.Progress, z.Weight, z.Score, z.ProgressState, ProgressStateName = z.ProgressState.ToName(), z.StartValue, z.EndValue, z.CurrentValue, z.IsEasyMode, z.IsLock, z.IsNotLook, z.ScoreName, z.ScoreColor, z.RuleId, z.RuleName, RuleSTime = z.RuleSTime.HasValue ? z.RuleSTime.Value.ToString("yyyy-MM-dd") : "", RuleETime = z.RuleETime.HasValue ? z.RuleETime.Value.ToString("yyyy-MM-dd") : "" }), ParentList = x.ParentList.Select(y => new { y.AccountId, y.AccountName, y.Icon, AlignList = y.AlignList.Select(q => new { q.Id, Title = q.IsNotLook == 1 ? "" : q.Title, q.Sort, q.IsLock, q.IsNotLook, KeyResultList = q.KeyResultList.OrderBy(q => q.Sort).Select(z => new { z.Id, Name = z.IsNotLook == 1 ? "" : z.Name, z.Sort, z.IsLock, z.IsNotLook }), }) }), ChildList = x.ChildList.Select(y => new { y.AccountId, y.AccountName, y.Icon, AlignList = y.AlignList.Select(q => new { q.Id, Title = q.IsNotLook == 1 ? "" : q.Title, q.Sort, q.IsLock, q.IsNotLook, KeyResultList = q.KeyResultList.OrderBy(q => q.Sort).Select(z => new { z.Id, Name = z.IsNotLook == 1 ? "" : z.Name, z.Sort, z.IsLock, z.IsNotLook }), }) }), x.AuditRemark, AuditTime = Common.ConvertHelper.FormatTime(x.AuditTime), x.AuditUserId, AuditUserName = UserReidsCache.GetUserLoginInfo((x.AuditUserId > 0 ? x.AuditUserId : 0))?.AccountName ?? "", UserIcon = UserReidsCache.GetUserLoginInfo((x.AuditUserId > 0 ? x.AuditUserId : 0))?.UserIcon ?? "", }; } private static void GetDQListLookPermission_V2(UserInfo userInfo, List MyUnderlingList, List pList, List pkrList, RB_OKR_Objective_ViewModel item) { item.IsLock = 2; item.IsNotLook = 2; if (pList.Where(x => x.TargetId == item.Id).Any()) { item.IsLock = 1; if (!MyUnderlingList.Contains(item.CreateBy) && item.CreateBy != userInfo.Id) { var NotLookList = pList.Where(x => x.TargetId == item.Id && x.State == 2).ToList(); var LookList = pList.Where(x => x.TargetId == item.Id && x.State == 1).ToList(); if (NotLookList.Any()) { //有不可看的 if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any()) { item.IsNotLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any()) { item.IsNotLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { item.IsNotLook = 1; } } if (item.IsNotLook == 2 && item.IsDefaultPermission == 2) { if (LookList.Any()) { if (LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { //OK } else { item.IsNotLook = 1; } } } } } else { if (item.IsDefaultPermission == 2) { item.IsLock = 1; if (!MyUnderlingList.Contains(item.CreateBy) && item.CreateBy != userInfo.Id) { item.IsNotLook = 1; } } } foreach (var qitem in item.KeyResultList) { qitem.IsLock = 2; qitem.IsNotLook = 2; if (pkrList.Where(x => x.TargetId == qitem.Id).Any()) { qitem.IsLock = 1; if (!MyUnderlingList.Contains(item.CreateBy) && item.CreateBy != userInfo.Id) { var NotLookList = pkrList.Where(x => x.TargetId == qitem.Id && x.State == 2).ToList(); var LookList = pkrList.Where(x => x.TargetId == qitem.Id && x.State == 1).ToList(); if (NotLookList.Any()) { //有不可看的 if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any()) { qitem.IsNotLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any()) { qitem.IsNotLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { qitem.IsNotLook = 1; } } if (qitem.IsNotLook == 2 && qitem.IsDefaultPermission == 2) { if (LookList.Any()) { if (LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { //OK } else { qitem.IsNotLook = 1; } } } } } else { if (qitem.IsDefaultPermission == 2) { qitem.IsLock = 1; if (!MyUnderlingList.Contains(item.CreateBy) && item.CreateBy != userInfo.Id) { qitem.IsNotLook = 1; } } } } } /// /// 获取待我审核列表 /// /// /// /// /// public ApiResult GetOKRObjectiveAuditList(int PeriodId, int userId, UserInfo userInfo) { List UserIdList = GetMyUnderlingUserIdList(userInfo); if (!UserIdList.Contains(userId)) { return ApiResult.Failed("该用户不是直属下级,无法审核"); } var list = oKR_ObjectiveRepository.GetList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, CreateBy = userId, Status = 1 }); if (list.Any()) { string objectiveIds = string.Join(",", list.Select(x => x.Id)); //查询向上对齐 var sdqlist = oKR_ObjectiveRepository.GetParentList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, ObjectiveIds = objectiveIds }); //查询向下对齐 var xdqlist = oKR_ObjectiveRepository.GetParentList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, ParentIds = objectiveIds }); string jObjectiveIds = objectiveIds; if (sdqlist.Any()) { jObjectiveIds += "," + string.Join(",", sdqlist.Select(x => x.Id)); } if (xdqlist.Any()) { jObjectiveIds += "," + string.Join(",", xdqlist.Select(x => x.Id)); } //查询结果列表 var krList = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveIds = jObjectiveIds }); //查询是否有权限 var pList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 2, ObjectiveIds = jObjectiveIds }); var pkrList = new List(); if (krList.Any()) { string krIds = string.Join(",", krList.Select(x => x.Id)); pkrList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 3, ObjectiveIds = krIds }); } string scoreRuleIds = string.Join(",", list.Where(x => x.ScoreRuleId > 0).Select(x => x.ScoreRuleId)); var ScoreRuleList = new List(); if (!string.IsNullOrEmpty(scoreRuleIds)) { ScoreRuleList = oKR_ScoreDetailRepository.GetList(new RB_OKR_ScoreDetail_ViewModel() { ScoreIds = scoreRuleIds }); } foreach (var item in krList) { item.IsLock = 2; if (pkrList.Where(x => x.TargetId == item.Id).Any()) { item.IsLock = 1; } } foreach (var item in sdqlist) { item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); item.IsLock = 2; if (pList.Where(x => x.TargetId == item.Id).Any()) { item.IsLock = 1; } } foreach (var item in xdqlist) { item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); item.IsLock = 2; if (pList.Where(x => x.TargetId == item.Id).Any()) { item.IsLock = 1; } } foreach (var item in list) { item.IsLock = 2; if (pList.Where(x => x.TargetId == item.Id).Any()) { item.IsLock = 1; } //结果列表 item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); if (item.IsDefaultState == 1 && item.KeyResultList.Any()) { item.ProgressState = item.KeyResultList.Max(x => x.ProgressState); } #region 对齐列表 var sdqclist = sdqlist.Where(x => x.ObjectiveId == item.Id).ToList(); List EmIdList = sdqclist.Select(x => x.CreateBy).Distinct().ToList(); item.ParentList = new List(); foreach (var qitem in EmIdList) { item.ParentList.Add(new ObjectiveEmployeeModel() { AccountId = qitem, AccountName = sdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmName, Icon = sdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmPhoto, AlignList = sdqclist.Where(x => x.CreateBy == qitem).ToList() }); } var xdqclist = xdqlist.Where(x => x.ParentId == item.Id).ToList(); List EmIdList2 = xdqclist.Select(x => x.CreateBy).Distinct().ToList(); item.ChildList = new List(); foreach (var qitem in EmIdList2) { item.ChildList.Add(new ObjectiveEmployeeModel() { AccountId = qitem, AccountName = xdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmName, Icon = xdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmPhoto, AlignList = xdqclist.Where(x => x.CreateBy == qitem).ToList() }); } #endregion #region 分数显示 item.ScoreName = ""; item.ScoreColor = ""; if (item.ScoreRuleId > 0) { var scoreRuleModel = ScoreRuleList.Where(x => x.ScoreId == item.ScoreRuleId && x.ScoreMin <= item.Score && x.ScoreMax >= item.Score).FirstOrDefault(); item.ScoreName = scoreRuleModel?.Name ?? ""; item.ScoreColor = scoreRuleModel?.Color ?? ""; foreach (var qitem in item.KeyResultList) { var qscoreRuleModel = ScoreRuleList.Where(x => x.ScoreId == item.ScoreRuleId && x.ScoreMin <= qitem.Score && x.ScoreMax >= qitem.Score).FirstOrDefault(); qitem.ScoreName = qscoreRuleModel?.Name ?? ""; qitem.ScoreColor = qscoreRuleModel?.Color ?? ""; } } #endregion } } return ApiResult.Success("", list.Select(x => new { x.Id, x.Title, x.Sort, x.Progress, x.Weight, x.Score, x.ProgressRemark, x.IsDefaultState, x.ProgressState, ProgressStateName = x.ProgressState.ToName(), x.Status, x.IsLock, x.ScoreName, x.ScoreColor, KeyResultList = x.KeyResultList.Select(z => new { z.Id, z.Name, z.Sort, z.Progress, z.Weight, z.Score, z.ProgressState, ProgressStateName = z.ProgressState.ToName(), z.StartValue, z.EndValue, z.CurrentValue, z.IsEasyMode, z.IsLock, z.ScoreName, z.ScoreColor }), ParentList = x.ParentList.Select(y => new { y.AccountId, y.AccountName, y.Icon, AlignList = y.AlignList.Select(q => new { q.Id, q.Title, q.Sort, q.IsLock, KeyResultList = x.KeyResultList.Select(z => new { z.Id, z.Name, z.Sort, z.IsLock }), }) }), ChildList = x.ChildList.Select(y => new { y.AccountId, y.AccountName, y.Icon, AlignList = y.AlignList.Select(q => new { q.Id, q.Title, q.Sort, q.IsLock, KeyResultList = x.KeyResultList.Select(z => new { z.Id, z.Name, z.Sort, z.IsLock }), }) }), }) ); } /// /// 获取他人的目标下拉列表 /// /// /// /// /// /// public object GetOKROthersObjectiveDropList(int periodId, int objectiveId, int userId, UserInfo userInfo) { List MyUnderlingList = GetMyUnderlingUserIdList(userInfo); if (!MyUnderlingList.Contains(userId)) { var pplist = oKR_PeriodPermissionRepository.GetList(new Model.Entity.OKR.RB_OKR_PeriodPermission() { Group_Id = userInfo.Group_Id, PeriodId = periodId, CreateBy = userId }); //查询是否有权限 var zpList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 1, TargetId = periodId, CreateBy = userId }); if (zpList.Any()) { var NotLookList = zpList.Where(x => x.State == 2).ToList(); var LookList = zpList.Where(x => x.State == 1).ToList(); if (NotLookList.Any()) { //有不可看的 if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any()) { return new { Status = 2, Msg = "没有权限查询" }; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any()) { return new { Status = 2, Msg = "没有权限查询" }; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { return new { Status = 2, Msg = "没有权限查询" }; } } if (LookList.Any() && pplist.Any()) { if (LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { //OK } else { return new { Status = 2, Msg = "没有权限查询" }; } } } else { if (pplist.Any()) { return new { Status = 2, Msg = "没有权限查询" }; } } } var list = oKR_ObjectiveRepository.GetList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = periodId, CreateBy = userId, Status = 2 }); if (list.Any()) { string objectiveIds = string.Join(",", list.Select(x => x.Id)); //查询结果列表 var krList = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveIds = objectiveIds }); //查询是否有权限 var pList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 2, ObjectiveIds = objectiveIds }); var pkrList = new List(); if (krList.Any()) { string krIds = string.Join(",", krList.Select(x => x.Id)); pkrList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 3, ObjectiveIds = krIds }); } #region 查询已对齐目标 //查询向上对齐 var sdqList = oKR_ObjectiveRelationRepository.GetList(new Model.Entity.OKR.RB_OKR_ObjectiveRelation() { ObjectiveId = objectiveId }); #endregion foreach (var item in list) { item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); GetDQListLookPermission(userInfo, MyUnderlingList, pList, pkrList, item); if (item.IsDefaultState == 1 && item.KeyResultList.Any()) { item.ProgressState = item.KeyResultList.Max(x => x.ProgressState); } item.IsParent = 2; if (sdqList.Where(x => x.ParentId == item.Id).Any()) { item.IsParent = 1; } } } list = list.Where(x => x.IsNotLook == 2).ToList(); return new { Status = 1, List = list.Select(x => new { x.Id, x.Title, x.Sort, x.Progress, x.ProgressState, ProgressStateName = x.ProgressState.ToName(), x.IsParent, x.IsLock, x.IsNotLook, KeyResultList = x.KeyResultList.Where(x => x.IsNotLook == 2).Select(z => new { z.Id, z.Name, z.Sort, z.Progress, z.ProgressState, ProgressStateName = z.ProgressState.ToName(), x.IsLock, x.IsNotLook }) }) }; } /// /// 根据姓名查询 /// /// /// /// /// /// public object GetOKROthersObjectiveDropListByName(int periodId, int objectiveId, string userName, UserInfo userInfo) { List MyUnderlingList = GetMyUnderlingUserIdList(userInfo); //查询所有用户 var emList = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, EmployeeName = userName }); emList = emList.Where(x => x.Id != userInfo.Id).ToList();//排除自己查询 var DQUserId = emList.Select(x => x.Id).ToList(); //用户周期权限 List UserLookList = new List(); if (DQUserId.Any()) { DQUserId = DQUserId.Distinct().ToList(); //查询是否有权限 var zpList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 1, TargetId = periodId, CreateByIds = string.Join(",", DQUserId) }); if (zpList.Any()) { var pplist = oKR_PeriodPermissionRepository.GetList(new Model.Entity.OKR.RB_OKR_PeriodPermission() { Group_Id = userInfo.Group_Id, PeriodId = periodId }, string.Join(",", DQUserId)); foreach (var UserId in DQUserId) { int IsLook = 2; if (zpList.Where(x => x.CreateBy == UserId).Any()) { var NotLookList = zpList.Where(x => x.CreateBy == UserId && x.State == 2).ToList(); var LookList = zpList.Where(x => x.CreateBy == UserId && x.State == 1).ToList(); if (NotLookList.Any()) { //有不可看的 if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any()) { IsLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any()) { IsLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { IsLook = 1; } } if (LookList.Any() && pplist.Where(x => x.CreateBy == UserId).Any()) { if (LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { //OK } else { IsLook = 1; } } } else { if (pplist.Where(x => x.CreateBy == UserId).Any()) { IsLook = 1; } } UserLookList.Add(new RB_OKR_Objective_ViewModel() { CreateBy = UserId, IsLock = IsLook }); } } } var list = oKR_ObjectiveRepository.GetList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = periodId, CreateByIds = string.Join(",", DQUserId), Status = 2 }); if (list.Any()) { string objectiveIds = string.Join(",", list.Select(x => x.Id)); //查询结果列表 var krList = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveIds = objectiveIds }); //查询是否有权限 var pList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 2, ObjectiveIds = objectiveIds }); var pkrList = new List(); if (krList.Any()) { string krIds = string.Join(",", krList.Select(x => x.Id)); pkrList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 3, ObjectiveIds = krIds }); } #region 查询已对齐目标 //查询向上对齐 var sdqList = oKR_ObjectiveRelationRepository.GetList(new Model.Entity.OKR.RB_OKR_ObjectiveRelation() { ObjectiveId = objectiveId }); #endregion foreach (var item in list) { item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); GetDQListLookPermission(userInfo, MyUnderlingList, pList, pkrList, item); if (item.IsDefaultState == 1 && item.KeyResultList.Any()) { item.ProgressState = item.KeyResultList.Max(x => x.ProgressState); } item.IsParent = 2; if (sdqList.Where(x => x.ParentId == item.Id).Any()) { item.IsParent = 1; } } } list = list.Where(x => x.IsNotLook == 2).ToList(); List RList = new List(); foreach (var item in DQUserId) { var emModel = emList.Where(x => x.Id == item).FirstOrDefault(); if ((UserLookList.Where(x => x.CreateBy == item).FirstOrDefault()?.IsLock ?? 0) == 1) { RList.Add(new { IsNotLook = 1, UserId = emModel.Id, UserName = emModel.EmployeeName, UserPhoto = emModel.UserIcon, emModel.DeptName, emModel.PostName, List = new List() }); } else { RList.Add(new { IsNotLook = 2, UserId = emModel.Id, UserName = emModel.EmployeeName, UserPhoto = emModel.UserIcon, emModel.DeptName, emModel.PostName, List = list.Where(x => x.CreateBy == item).Select(x => new { x.Id, x.Title, x.Sort, x.Progress, x.ProgressState, ProgressStateName = x.ProgressState.ToName(), x.IsParent, x.IsLock, x.IsNotLook, KeyResultList = x.KeyResultList.Where(x => x.IsNotLook == 2).Select(z => new { z.Id, z.Name, z.Sort, z.Progress, z.ProgressState, ProgressStateName = z.ProgressState.ToName(), x.IsLock, x.IsNotLook }) }) }); } } return RList; } /// /// 获取我的单个目标 /// /// /// /// public object GetOKRMyObjectiveInfo(int objectiveId, UserInfo userInfo) { var list = oKR_ObjectiveRepository.GetList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, Id = objectiveId, CreateBy = userInfo.Id }); if (list.Any()) { List MyUnderlingList = GetMyUnderlingUserIdList(userInfo); var mdoel = list.FirstOrDefault(); string objectiveIds = string.Join(",", list.Select(x => x.Id)); //查询向上对齐 var sdqlist = oKR_ObjectiveRepository.GetParentList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = mdoel.PeriodId, ObjectiveIds = objectiveIds }); //查询向下对齐 var xdqlist = oKR_ObjectiveRepository.GetParentList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = mdoel.PeriodId, ParentIds = objectiveIds }); string jObjectiveIds = objectiveIds; if (sdqlist.Any()) { jObjectiveIds += "," + string.Join(",", sdqlist.Select(x => x.Id)); } if (xdqlist.Any()) { jObjectiveIds += "," + string.Join(",", xdqlist.Select(x => x.Id)); } //查询结果列表 var krList = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveIds = jObjectiveIds }); //查询是否有权限 var pList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 2, ObjectiveIds = jObjectiveIds }); var pkrList = new List(); if (krList.Any()) { string krIds = string.Join(",", krList.Select(x => x.Id)); pkrList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 3, ObjectiveIds = krIds }); } string scoreRuleIds = string.Join(",", list.Where(x => x.ScoreRuleId > 0).Select(x => x.ScoreRuleId)); var ScoreRuleList = new List(); if (!string.IsNullOrEmpty(scoreRuleIds)) { ScoreRuleList = oKR_ScoreDetailRepository.GetList(new RB_OKR_ScoreDetail_ViewModel() { ScoreIds = scoreRuleIds }); } //查询规则名称 string ruleIds = string.Join(",", krList.Where(x => x.RuleId > 0).Select(x => x.RuleId).Distinct()); var krRuleList = new List(); if (!string.IsNullOrEmpty(ruleIds)) { krRuleList = oKR_RuleRepository.GetList(new RB_OKR_Rule_ViewModel() { RuleIds = ruleIds }); } foreach (var item in sdqlist) { item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); GetDQListLookPermission(userInfo, MyUnderlingList, pList, pkrList, item); } foreach (var item in xdqlist) { item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); GetDQListLookPermission(userInfo, MyUnderlingList, pList, pkrList, item); } foreach (var item in list) { item.IsLock = 2; item.IsNotLook = 2; if (item.IsDefaultPermission == 2 || pList.Where(x => x.TargetId == item.Id).Any()) { item.IsLock = 1; } //结果列表 item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); foreach (var qitem in item.KeyResultList) { qitem.IsLock = 2; if (qitem.IsDefaultPermission == 2 || pkrList.Where(x => x.TargetId == qitem.Id).Any()) { qitem.IsLock = 1; } if (qitem.RuleId > 0) { qitem.RuleName = krRuleList.Where(x => x.Id == qitem.RuleId).FirstOrDefault()?.RuleName ?? ""; } } if (item.IsDefaultState == 1 && item.KeyResultList.Any()) { item.ProgressState = item.KeyResultList.Max(x => x.ProgressState); } #region 对齐列表 var sdqclist = sdqlist.Where(x => x.ObjectiveId == item.Id).ToList(); List EmIdList = sdqclist.Select(x => x.CreateBy).Distinct().ToList(); item.ParentList = new List(); foreach (var qitem in EmIdList) { item.ParentList.Add(new ObjectiveEmployeeModel() { AccountId = qitem, AccountName = sdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmName, Icon = sdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmPhoto, AlignList = sdqclist.Where(x => x.CreateBy == qitem).ToList() }); } var xdqclist = xdqlist.Where(x => x.ParentId == item.Id).ToList(); List EmIdList2 = xdqclist.Select(x => x.CreateBy).Distinct().ToList(); item.ChildList = new List(); foreach (var qitem in EmIdList2) { item.ChildList.Add(new ObjectiveEmployeeModel() { AccountId = qitem, AccountName = xdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmName, Icon = xdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmPhoto, AlignList = xdqclist.Where(x => x.CreateBy == qitem).ToList() }); } #endregion #region 分数显示 item.ScoreName = ""; item.ScoreColor = ""; if (item.ScoreRuleId > 0) { var scoreRuleModel = ScoreRuleList.Where(x => x.ScoreId == item.ScoreRuleId && x.ScoreMin <= item.Score && x.ScoreMax >= item.Score).FirstOrDefault(); item.ScoreName = scoreRuleModel?.Name ?? ""; item.ScoreColor = scoreRuleModel?.Color ?? ""; foreach (var qitem in item.KeyResultList) { var qscoreRuleModel = ScoreRuleList.Where(x => x.ScoreId == item.ScoreRuleId && x.ScoreMin <= qitem.Score && x.ScoreMax >= qitem.Score).FirstOrDefault(); qitem.ScoreName = qscoreRuleModel?.Name ?? ""; qitem.ScoreColor = qscoreRuleModel?.Color ?? ""; } } #endregion } } var x = list.FirstOrDefault(); if (x == null) { return null; } return new { x.Id, x.Title, x.Sort, x.Progress, x.Weight, x.Score, x.ProgressRemark, x.IsDefaultState, x.ProgressState, ProgressStateName = x.ProgressState.ToName(), x.Status, x.IsLock, x.IsNotLook, x.ScoreName, x.ScoreColor, KeyResultList = x.KeyResultList.Select(z => new { z.Id, z.Name, z.Sort, z.Progress, z.Weight, z.Score, z.ProgressState, ProgressStateName = z.ProgressState.ToName(), z.StartValue, z.EndValue, z.CurrentValue, z.IsEasyMode, z.IsLock, z.IsNotLook, z.ScoreName, z.ScoreColor, z.RuleId, z.RuleName, RuleSTime = z.RuleSTime.HasValue ? z.RuleSTime.Value.ToString("yyyy-MM-dd") : "", RuleETime = z.RuleETime.HasValue ? z.RuleETime.Value.ToString("yyyy-MM-dd") : "" }), ParentList = x.ParentList.Select(y => new { y.AccountId, y.AccountName, y.Icon, AlignList = y.AlignList.Select(q => new { q.Id, Title = q.IsNotLook == 1 ? "" : q.Title, q.Sort, q.IsLock, q.IsNotLook, KeyResultList = q.KeyResultList.OrderBy(q => q.Sort).Select(z => new { z.Id, Name = z.IsNotLook == 1 ? "" : z.Name, z.Sort, z.IsLock, z.IsNotLook }), }) }), ChildList = x.ChildList.Select(y => new { y.AccountId, y.AccountName, y.Icon, AlignList = y.AlignList.Select(q => new { q.Id, Title = q.IsNotLook == 1 ? "" : q.Title, q.Sort, q.IsLock, q.IsNotLook, KeyResultList = q.KeyResultList.OrderBy(q => q.Sort).Select(z => new { z.Id, Name = z.IsNotLook == 1 ? "" : z.Name, z.Sort, z.IsLock, z.IsNotLook }), }) }), x.AuditRemark, AuditTime = Common.ConvertHelper.FormatTime(x.AuditTime), x.AuditUserId, AuditUserName = UserReidsCache.GetUserLoginInfo((x.AuditUserId > 0 ? x.AuditUserId : 0))?.AccountName ?? "", UserIcon = UserReidsCache.GetUserLoginInfo((x.AuditUserId > 0 ? x.AuditUserId : 0))?.UserIcon ?? "", }; } /// /// 保存目标 /// /// /// /// public string SetOKRMyObjectiveInfo(RB_OKR_Objective_ViewModel dmodel, UserInfo userInfo, out int ObjectiveId) { ObjectiveId = 0; if (dmodel.Id > 0) { ObjectiveId = dmodel.Id; var hmodel = oKR_ObjectiveRepository.GetEntity(dmodel.Id); if (hmodel.ProgressRemark == dmodel.ProgressRemark && hmodel.Title == dmodel.Title) { return ""; } Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_Objective_ViewModel.Title),dmodel.Title}, { nameof(RB_OKR_Objective_ViewModel.ProgressRemark),dmodel.ProgressRemark}, { nameof(RB_OKR_Objective_ViewModel.UpdateBy),userInfo.Id}, { nameof(RB_OKR_Objective_ViewModel.UpdateTime),DateTime.Now}, }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Objective_ViewModel.Id), FiledValue=dmodel.Id, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_ObjectiveRepository.Update(keyValues, wheres); if (flag) { changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "修改OKR目标标题【" + dmodel.Id + "】", School_Id = userInfo.School_Id, SourceId = 0 }); if (hmodel.ProgressRemark != dmodel.ProgressRemark) { oKR_UpdateHistoryRepository.Insert(new Model.Entity.OKR.RB_OKR_UpdateHistory() { Id = 0, Type = 3, SourceId = dmodel.Id, Content = dmodel.ProgressRemark, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id }); } if (hmodel.Title == dmodel.Title) { oKR_UpdateHistoryRepository.Insert(new Model.Entity.OKR.RB_OKR_UpdateHistory() { Id = 0, Type = 1, SourceId = dmodel.Id, Content = dmodel.Title, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id }); } //更新提示 //Task.Run(() => AddMyEmployeeUpdateNotification(dmodel.PeriodId, userInfo)); } return flag ? "" : "出错了,请联系管理员"; } else { var configModel = oKR_PeriodConfigRepository.GetList(new RB_OKR_PeriodConfig_ViewModel() { Group_Id = userInfo.Group_Id }).FirstOrDefault(); if (configModel != null && configModel.DirectorAudit == 1) { dmodel.Status = 2; #region 查询是否有直属上级,没有的话 无需审核 var accountModel = accountRepository.GetEntity(userInfo.Id); if (accountModel.DirectSupervisor > 0) { dmodel.Status = 4; } else { //根据部门查询 string ManagerIds = ""; var sjdlist = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, ManagerIds = userInfo.Id.ToString() }); if (sjdlist.Any()) { //说明是部门主管 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)) { dmodel.Status = 4; } } #endregion } else { dmodel.Status = 2; } dmodel.Sort = oKR_ObjectiveRepository.GetObjectiveMaxSort(userInfo.Group_Id, dmodel.PeriodId, userInfo.Id) + 1;//获取 当前最大的 dmodel.ScoreRuleId = 0;//获取 是否有默认 var scoreRuleModel = oKR_ScoreRepository.GetList(new RB_OKR_Score_ViewModel() { Group_Id = userInfo.Group_Id, IsDefault = 1 }).FirstOrDefault(); if (scoreRuleModel != null) { dmodel.ScoreRuleId = scoreRuleModel.Id; } dmodel.Progress = 0; dmodel.Weight = 100; dmodel.Score = 0; dmodel.IsDefaultState = 1; dmodel.ProgressState = Common.Enum.OKR.ProgressStateEnum.Normal; dmodel.Group_Id = userInfo.Group_Id; dmodel.School_Id = userInfo.School_Id; dmodel.CreateBy = userInfo.Id; dmodel.CreateTime = DateTime.Now; dmodel.UpdateBy = userInfo.Id; dmodel.UpdateTime = DateTime.Now; dmodel.IsDefaultPermission = 1; dmodel.IsUpdated = 2; int Id = oKR_ObjectiveRepository.Insert(dmodel); ObjectiveId = Id; if (Id > 0) { changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "新增OKR目标【" + Id + "】", School_Id = userInfo.School_Id, SourceId = 0 }); oKR_UpdateHistoryRepository.Insert(new Model.Entity.OKR.RB_OKR_UpdateHistory() { Id = 0, Type = 1, SourceId = Id, Content = dmodel.Title, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id }); //更新提示 //Task.Run(() => AddMyEmployeeUpdateNotification(dmodel.PeriodId, userInfo)); } return Id > 0 ? "" : "出错了,请联系管理员"; } } /// /// 保存关键结果 /// /// /// /// /// /// public string SetOKRMyKeyResultInfo(int keyResultId, int objectiveId, string name, UserInfo userInfo, out int RKeyResultId) { RKeyResultId = 0; if (keyResultId > 0) { RKeyResultId = keyResultId; var hmodel = oKR_KeyResultRepository.GetEntity(keyResultId); if (hmodel.Name == name) { return ""; } Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_KeyResult_ViewModel.Name),name}, { nameof(RB_OKR_KeyResult_ViewModel.UpdateBy),userInfo.Id}, { nameof(RB_OKR_KeyResult_ViewModel.UpdateTime),DateTime.Now}, }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_KeyResult_ViewModel.Id), FiledValue=keyResultId, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_KeyResultRepository.Update(keyValues, wheres); if (flag) { changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "修改OKR目标关键结果【" + keyResultId + "】", School_Id = userInfo.School_Id, SourceId = 0 }); oKR_UpdateHistoryRepository.Insert(new Model.Entity.OKR.RB_OKR_UpdateHistory() { Id = 0, Type = 2, SourceId = keyResultId, Content = name, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id }); //更新提示 //Task.Run(() => AddMyEmployeeUpdateNotification_V2(objectiveId, userInfo)); } return flag ? "" : "出错了,请联系管理员"; } else { int Sort = oKR_KeyResultRepository.GetKeyResultMaxSort(objectiveId); decimal Weight = 100; decimal NowWeight = Weight; bool IsUpdate = false; var list = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveId = objectiveId }); if (list.Any()) { if (list.Select(x => x.Weight).Distinct().Count() == 1) { //说明权重一致 平摊到每个结果里 Weight = Convert.ToDecimal((int)((Convert.ToDecimal(100) / (list.Count() + 1)) * 10)) / 10; IsUpdate = true; } else if (list.Select(x => x.Weight).Distinct().Count() == 2) { if ((list.Max(x => x.Weight) - list.Min(x => x.Weight)) == (decimal)0.1) { //相差0.1 特殊情况 可以分摊 Weight = Convert.ToDecimal((int)((Convert.ToDecimal(100) / (list.Count() + 1)) * 10)) / 10; IsUpdate = true; } else { Weight = 0; } } else { Weight = 0; } decimal diff = 0; if (Weight > 0 && (list.Count() + 1) * Weight != 100) { diff = 100 - (list.Count() + 1) * Weight; } NowWeight = Weight + diff; } int Id = oKR_KeyResultRepository.Insert(new Model.Entity.OKR.RB_OKR_KeyResult() { Id = 0, CreateBy = userInfo.Id, CreateTime = DateTime.Now, CurrentValue = 0, EndValue = 100, Group_Id = userInfo.Group_Id, IsEasyMode = 1, Name = name, ObjectiveId = objectiveId, Progress = 0, ProgressState = Common.Enum.OKR.ProgressStateEnum.Normal, School_Id = userInfo.School_Id, Score = 0, Sort = Sort + 1, StartValue = 0, Status = 0, UpdateBy = userInfo.Id, UpdateTime = DateTime.Now, Weight = NowWeight, IsDefaultPermission = 1 }); RKeyResultId = Id; if (Id > 0) { if (IsUpdate) { foreach (var item in list) { //修改每个结果的权重 Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_KeyResult_ViewModel.Weight), Weight} }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_KeyResult_ViewModel.Id), FiledValue=item.Id, OperatorEnum=OperatorEnum.Equal } }; oKR_KeyResultRepository.Update(keyValues, wheres); } } changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "新增OKR目标关键结果【" + Id + "】", School_Id = userInfo.School_Id, SourceId = 0 }); oKR_UpdateHistoryRepository.Insert(new Model.Entity.OKR.RB_OKR_UpdateHistory() { Id = 0, Type = 2, SourceId = Id, Content = name, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id }); //更新提示 //Task.Run(() => AddMyEmployeeUpdateNotification_V2(objectiveId, userInfo)); } return Id > 0 ? "" : "出错了,请联系管理员"; } } /// /// 获取关键结果列表 /// /// /// public List GetOKRKeyResultList(RB_OKR_KeyResult_ViewModel dmodel) { return oKR_KeyResultRepository.GetList(dmodel); } /// /// 设置目标排序 /// /// /// /// /// public string SetOKRMyObjectiveSort(int objectiveId1, int objectiveId2, UserInfo userInfo) { if (objectiveId2 == 0) { var objectModel1 = oKR_ObjectiveRepository.GetEntity(objectiveId1); //移动到第一个 Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_Objective_ViewModel.Sort),1}, }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Objective_ViewModel.Id), FiledValue=objectModel1.Id, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_ObjectiveRepository.Update(keyValues, wheres); if (flag) { //其他的Sort 对应+1 oKR_ObjectiveRepository.UpdateOtherSort(objectModel1.PeriodId, objectModel1.CreateBy, objectModel1.Id, 0, objectModel1.Sort); changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = $"修改OKR目标排序【排序由{objectModel1.Sort}改为{1}】", School_Id = userInfo.School_Id, SourceId = 0 }); } return flag ? "" : "出错了,请联系管理员"; } else { var objectModel1 = oKR_ObjectiveRepository.GetEntity(objectiveId1); var objectModel2 = oKR_ObjectiveRepository.GetEntity(objectiveId2); if (objectModel1.CreateBy != objectModel2.CreateBy) { return "不是同一用户目标,无法排序"; } if (objectModel1.PeriodId != objectModel2.PeriodId) { return "不是同一周期目标,无法排序"; } if (objectModel1.Sort > objectModel2.Sort) { //原在这个后面 往前移 移到这个的屁股后面 Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_Objective_ViewModel.Sort),objectModel2.Sort + 1}, }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Objective_ViewModel.Id), FiledValue=objectModel1.Id, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_ObjectiveRepository.Update(keyValues, wheres); if (flag) { //在这个范围里面的 Sort+1 oKR_ObjectiveRepository.UpdateOtherSort(objectModel1.PeriodId, objectModel1.CreateBy, objectModel1.Id, objectModel2.Sort, objectModel1.Sort); changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = $"修改OKR目标排序【排序由{objectModel1.Sort}改为{objectModel2.Sort + 1}】", School_Id = userInfo.School_Id, SourceId = 0 }); } return flag ? "" : "出错了,请联系管理员"; } else { //原在这个前面 往后移 移到这个的屁股后面 Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_Objective_ViewModel.Sort),objectModel2.Sort}, }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Objective_ViewModel.Id), FiledValue=objectModel1.Id, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_ObjectiveRepository.Update(keyValues, wheres); if (flag) { //在这个范围里面的 Sort+1 oKR_ObjectiveRepository.UpdateOtherSortDesc(objectModel1.PeriodId, objectModel1.CreateBy, objectModel1.Id, objectModel1.Sort, objectModel2.Sort); changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = $"修改OKR目标排序【排序由{objectModel1.Sort}改为{objectModel2.Sort}】", School_Id = userInfo.School_Id, SourceId = 0 }); } return flag ? "" : "出错了,请联系管理员"; } } } /// /// 设置目标关键结果排序 /// /// /// /// /// public string SetgetOKRMyKeyResultSort(int keyResult1, int keyResult2, UserInfo userInfo) { if (keyResult2 == 0) { var keyResultModel1 = oKR_KeyResultRepository.GetEntity(keyResult1); //移动到第一个 Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_KeyResult_ViewModel.Sort),1}, }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_KeyResult_ViewModel.Id), FiledValue=keyResultModel1.Id, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_KeyResultRepository.Update(keyValues, wheres); if (flag) { //其他的Sort 对应+1 oKR_KeyResultRepository.UpdateOtherSort(keyResultModel1.ObjectiveId, keyResultModel1.Id, 0, keyResultModel1.Sort); changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = $"修改OKR目标关键结果排序【排序由{keyResultModel1.Sort}改为{1}】", School_Id = userInfo.School_Id, SourceId = 0 }); } return flag ? "" : "出错了,请联系管理员"; } else { var keyResultModel1 = oKR_KeyResultRepository.GetEntity(keyResult1); var keyResultModel2 = oKR_KeyResultRepository.GetEntity(keyResult2); if (keyResultModel1.ObjectiveId != keyResultModel2.ObjectiveId) { return "不是同一周期目标,无法排序"; } if (keyResultModel1.Sort > keyResultModel2.Sort) { //原在这个后面 往前移 移到这个的屁股后面 Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_KeyResult_ViewModel.Sort),keyResultModel2.Sort + 1}, }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_KeyResult_ViewModel.Id), FiledValue=keyResultModel1.Id, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_KeyResultRepository.Update(keyValues, wheres); if (flag) { //在这个范围里面的 Sort+1 oKR_KeyResultRepository.UpdateOtherSort(keyResultModel1.ObjectiveId, keyResultModel1.Id, keyResultModel2.Sort, keyResultModel1.Sort); changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = $"修改OKR目标排序【排序由{keyResultModel1.Sort}改为{keyResultModel2.Sort + 1}】", School_Id = userInfo.School_Id, SourceId = 0 }); } return flag ? "" : "出错了,请联系管理员"; } else { //原在这个前面 往后移 移到这个的屁股后面 Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_KeyResult_ViewModel.Sort),keyResultModel2.Sort}, }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_KeyResult_ViewModel.Id), FiledValue=keyResultModel1.Id, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_KeyResultRepository.Update(keyValues, wheres); if (flag) { //在这个范围里面的 Sort+1 oKR_KeyResultRepository.UpdateOtherSortDesc(keyResultModel1.ObjectiveId, keyResultModel1.Id, keyResultModel1.Sort, keyResultModel2.Sort); changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = $"修改OKR目标排序【排序由{keyResultModel1.Sort}改为{keyResultModel2.Sort}】", School_Id = userInfo.School_Id, SourceId = 0 }); } return flag ? "" : "出错了,请联系管理员"; } } } /// /// 保存目标状态 /// /// /// /// /// /// public string SetOKRMyObjectiveState(int objectiveId, int type, int progressState, out int outProgressState, UserInfo userInfo) { outProgressState = 0; Dictionary keyValues = new Dictionary(); string LogContent = ""; if (type == 1) { keyValues.Add(nameof(RB_OKR_Objective_ViewModel.IsDefaultState), 1); keyValues.Add(nameof(RB_OKR_Objective_ViewModel.IsUpdated), 1); keyValues.Add(nameof(RB_OKR_Objective_ViewModel.UpdateBy), userInfo.Id); keyValues.Add(nameof(RB_OKR_Objective_ViewModel.UpdateTime), DateTime.Now); LogContent = "修改OKR目标默认风险最高的 Key Result 状态【" + objectiveId + "】"; outProgressState = oKR_KeyResultRepository.GetKeyResultMaxProgressState(objectiveId); } else if (type == 2) { keyValues.Add(nameof(RB_OKR_Objective_ViewModel.IsDefaultState), 2); keyValues.Add(nameof(RB_OKR_Objective_ViewModel.IsUpdated), 1); keyValues.Add(nameof(RB_OKR_Objective_ViewModel.ProgressState), progressState); keyValues.Add(nameof(RB_OKR_Objective_ViewModel.UpdateBy), userInfo.Id); keyValues.Add(nameof(RB_OKR_Objective_ViewModel.UpdateTime), DateTime.Now); LogContent = "修改OKR目标自定义进度状态【" + objectiveId + "】"; outProgressState = progressState; } else if (type == 3) { keyValues.Add(nameof(RB_OKR_Objective_ViewModel.Status), 5); keyValues.Add(nameof(RB_OKR_Objective_ViewModel.UpdateBy), userInfo.Id); keyValues.Add(nameof(RB_OKR_Objective_ViewModel.UpdateTime), DateTime.Now); LogContent = "删除OKR目标【" + objectiveId + "】"; } else { return "类型不正确"; } List wheres = new List() { new WhereHelper(){ FiledName= nameof(RB_OKR_Objective_ViewModel.Id), FiledValue=objectiveId, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_ObjectiveRepository.Update(keyValues, wheres); if (flag) { if (type == 1 || type == 2) { Task.Run(() => RecordUpdateProgress(0, objectiveId, userInfo.Group_Id, userInfo.Id)); } changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = LogContent, School_Id = userInfo.School_Id, SourceId = 0 }); } return flag ? "" : "出错了,请联系管理员"; } /// /// 设置关键结果状态 /// /// /// /// /// /// public string SgetOKRMyKeyResultState(int keyResultId, int type, string progressState, UserInfo userInfo) { Dictionary keyValues = new Dictionary(); string LogContent = ""; if (type == 1) { keyValues.Add(nameof(RB_OKR_KeyResult_ViewModel.ProgressState), progressState); keyValues.Add(nameof(RB_OKR_KeyResult_ViewModel.UpdateBy), userInfo.Id); keyValues.Add(nameof(RB_OKR_KeyResult_ViewModel.UpdateTime), DateTime.Now); LogContent = "修改OKR目标关键结果进度状态【" + keyResultId + "】"; } else if (type == 2) { keyValues.Add(nameof(RB_OKR_KeyResult_ViewModel.Status), 1); keyValues.Add(nameof(RB_OKR_KeyResult_ViewModel.UpdateBy), userInfo.Id); keyValues.Add(nameof(RB_OKR_KeyResult_ViewModel.UpdateTime), DateTime.Now); LogContent = "删除OKR目标关键结果【" + keyResultId + "】"; } else if (type == 3) { keyValues.Add(nameof(RB_OKR_KeyResult_ViewModel.IsEasyMode), 1); keyValues.Add(nameof(RB_OKR_KeyResult_ViewModel.UpdateBy), userInfo.Id); keyValues.Add(nameof(RB_OKR_KeyResult_ViewModel.UpdateTime), DateTime.Now); LogContent = "修改OKR目标关键结果进度为简单模式【" + keyResultId + "】"; } else if (type == 4) { keyValues.Add(nameof(RB_OKR_KeyResult_ViewModel.IsEasyMode), 2); keyValues.Add(nameof(RB_OKR_KeyResult_ViewModel.UpdateBy), userInfo.Id); keyValues.Add(nameof(RB_OKR_KeyResult_ViewModel.UpdateTime), DateTime.Now); LogContent = "修改OKR目标关键结果进度为高级模式【" + keyResultId + "】"; } else { return "类型不正确"; } List wheres = new List() { new WhereHelper(){ FiledName= nameof(RB_OKR_KeyResult_ViewModel.Id), FiledValue=keyResultId, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_KeyResultRepository.Update(keyValues, wheres); if (flag) { if (type == 1) { var kmodel = oKR_KeyResultRepository.GetEntity(keyResultId); Dictionary keyValues1 = new Dictionary() { { nameof(RB_OKR_Objective_ViewModel.IsUpdated),1} }; List wheres1 = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Objective_ViewModel.Id), FiledValue=kmodel.ObjectiveId, OperatorEnum=OperatorEnum.Equal } }; oKR_ObjectiveRepository.Update(keyValues1, wheres1); //记录最后更新进度时间 Task.Run(() => RecordUpdateProgress(0, kmodel.ObjectiveId, userInfo.Group_Id, userInfo.Id)); } changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = LogContent, School_Id = userInfo.School_Id, SourceId = 0 }); } return flag ? "" : "出错了,请联系管理员"; } /// /// 设置结果进度 /// /// /// /// /// /// /// /// /// public ApiResult SgetOKRMyKeyResultProgress(int keyResultId, int type, int progress, decimal startValue, decimal endValue, decimal currentValue, UserInfo userInfo, RB_OKR_KeyResult_ViewModel model = null) { if (model == null) { model = oKR_KeyResultRepository.GetEntity(keyResultId); } if (model == null || model.Status == 1) { return ApiResult.Failed("关键结果不存在"); } if (keyResultId > 0 && model.RuleId > 0) { return ApiResult.Failed("关键结果已设置规则,无法手动调整进度"); } if (type == 1) { //根据进度 求高级的当前值 currentValue = Math.Round((model.EndValue - model.StartValue) * progress / 100, 2, MidpointRounding.AwayFromZero) + model.StartValue; Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_KeyResult_ViewModel.Progress),progress}, { nameof(RB_OKR_KeyResult_ViewModel.CurrentValue),currentValue}, }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_KeyResult_ViewModel.Id), FiledValue=model.Id, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_KeyResultRepository.Update(keyValues, wheres); if (flag) { //更新目标的进度百分比 var list = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveId = model.ObjectiveId }); decimal TProgress = list.Sum(x => x.Progress * x.Weight / 100); Dictionary keyValues1 = new Dictionary() { { nameof(RB_OKR_Objective_ViewModel.Progress),(int)TProgress}, { nameof(RB_OKR_Objective_ViewModel.IsUpdated),1} }; List wheres1 = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Objective_ViewModel.Id), FiledValue=model.ObjectiveId, OperatorEnum=OperatorEnum.Equal } }; oKR_ObjectiveRepository.Update(keyValues1, wheres1); if (keyResultId > 0) { changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "修改OKR目标关键结果【" + model.Id + "】进度为【" + progress + "】", School_Id = userInfo.School_Id, SourceId = 0 }); } Task.Run(() => RecordUpdateProgress(0, keyResultId, userInfo.Group_Id, userInfo.Id)); return ApiResult.Success("", new { TProgress = (int)TProgress, CProgress = progress, model.StartValue, model.EndValue, currentValue }); } } else { //根据当前值 求进度 progress = (int)(((currentValue - startValue) / (endValue - startValue)) * 100); Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_KeyResult_ViewModel.Progress),progress}, { nameof(RB_OKR_KeyResult_ViewModel.CurrentValue),currentValue}, { nameof(RB_OKR_KeyResult_ViewModel.StartValue),startValue}, { nameof(RB_OKR_KeyResult_ViewModel.EndValue),endValue} }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_KeyResult_ViewModel.Id), FiledValue=model.Id, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_KeyResultRepository.Update(keyValues, wheres); if (flag) { //更新目标的进度百分比 var list = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveId = model.ObjectiveId }); decimal TProgress = list.Sum(x => x.Progress * x.Weight / 100); Dictionary keyValues1 = new Dictionary() { { nameof(RB_OKR_Objective_ViewModel.Progress),(int)TProgress}, { nameof(RB_OKR_Objective_ViewModel.IsUpdated),1} }; List wheres1 = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Objective_ViewModel.Id), FiledValue=model.ObjectiveId, OperatorEnum=OperatorEnum.Equal } }; oKR_ObjectiveRepository.Update(keyValues1, wheres1); if (keyResultId > 0) { changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "修改OKR目标关键结果【" + model.Id + "】进度为【" + progress + "】", School_Id = userInfo.School_Id, SourceId = 0 }); } Task.Run(() => RecordUpdateProgress(0, model.ObjectiveId, userInfo.Group_Id, userInfo.Id)); return ApiResult.Success("", new { TProgress = (int)TProgress, CProgress = progress, model.StartValue, model.EndValue, currentValue }); } } return ApiResult.Failed(); } /// /// 记录最后更新进度时间 /// /// /// /// /// private void RecordUpdateProgress(int periodId, int objectiveId, int group_Id, int userId) { if (periodId == 0 && objectiveId > 0) { var model = oKR_ObjectiveRepository.GetEntity(objectiveId); periodId = model?.PeriodId ?? 0; } if (periodId == 0) { return; } var list = oKR_UpdateProgressRepository.GetList(new Model.Entity.OKR.RB_OKR_UpdateProgress() { Group_Id = group_Id, PeriodId = periodId, UserId = userId }); if (list.Any()) { var model = list.FirstOrDefault(); Dictionary keyValues = new Dictionary() { { nameof(Model.Entity.OKR.RB_OKR_UpdateProgress.UpdateTime),DateTime.Now} }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(Model.Entity.OKR.RB_OKR_UpdateProgress.Id), FiledValue=model.Id, OperatorEnum=OperatorEnum.Equal } }; oKR_UpdateProgressRepository.Update(keyValues, wheres); } else { oKR_UpdateProgressRepository.Insert(new Model.Entity.OKR.RB_OKR_UpdateProgress() { Id = 0, Group_Id = group_Id, PeriodId = periodId, UserId = userId, UpdateTime = DateTime.Now }); } } /// /// 设置结果权重 /// /// /// /// /// public ApiResult SgetOKRMyKeyResultWeight(int keyResultId, decimal weight, UserInfo userInfo) { var model = oKR_KeyResultRepository.GetEntity(keyResultId); if (model == null || model.Status == 1) { return ApiResult.Failed("关键结果不存在"); } if (model.Weight == weight) { return ApiResult.Success(); } var list = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveId = model.ObjectiveId }); if (list.Count() == 1) { return ApiResult.Failed("只有一个结果,无法修改权重"); } int MaxSort = list.Max(x => x.Sort); var MaxModel = list.Where(x => x.Sort == MaxSort).FirstOrDefault(); var CurrentModel = list.Where(x => x.Id == keyResultId).FirstOrDefault(); if (model.Sort == MaxSort) { return ApiResult.Failed("最后一个KeyResult无法修改权重"); } if (weight - model.Weight > MaxModel.Weight) { return ApiResult.Failed("总权重不能超过100%"); } CurrentModel.Weight = weight; Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_KeyResult_ViewModel.Weight),weight} }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_KeyResult_ViewModel.Id), FiledValue=keyResultId, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_KeyResultRepository.Update(keyValues, wheres); if (flag) { MaxModel.Weight -= (weight - model.Weight); //更新最后一个KeyResult权重 Dictionary keyValues1 = new Dictionary() { { nameof(RB_OKR_KeyResult_ViewModel.Weight), MaxModel.Weight} }; List wheres1 = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_KeyResult_ViewModel.Id), FiledValue=MaxModel.Id, OperatorEnum=OperatorEnum.Equal } }; oKR_KeyResultRepository.Update(keyValues1, wheres1); #region 更新目标进度+评分 //list = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveId = model.ObjectiveId }); decimal TProgress = list.Sum(x => x.Progress * x.Weight / 100); decimal TScore = Convert.ToDecimal((int)(list.Sum(x => x.Score * x.Weight / 100) * 10)) / 10; Dictionary keyValues2 = new Dictionary() { { nameof(RB_OKR_Objective_ViewModel.Progress),(int)TProgress}, { nameof(RB_OKR_Objective_ViewModel.Score),TScore} }; List wheres2 = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Objective_ViewModel.Id), FiledValue=model.ObjectiveId, OperatorEnum=OperatorEnum.Equal } }; oKR_ObjectiveRepository.Update(keyValues2, wheres2); #endregion changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "修改OKR关键结果权重【" + keyResultId + "】", School_Id = userInfo.School_Id, SourceId = 0 }); return ApiResult.Success("", new { Weight = weight, LastWeight = MaxModel.Weight, TProgress = (int)TProgress, TScore }); } return ApiResult.Failed(); } /// /// 设置结果分数 /// /// /// /// /// public ApiResult SgetOKRMyKeyResultScore(int keyResultId, decimal score, UserInfo userInfo) { var model = oKR_KeyResultRepository.GetEntity(keyResultId); if (model == null || model.Status == 1) { return ApiResult.Failed("关键结果不存在"); } if (model.Score == score) { return ApiResult.Success(); } Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_KeyResult_ViewModel.Score),score} }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_KeyResult_ViewModel.Id), FiledValue=keyResultId, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_KeyResultRepository.Update(keyValues, wheres); if (flag) { //更新目标的进度百分比 var list = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveId = model.ObjectiveId }); decimal TScore = Convert.ToDecimal((int)(list.Sum(x => x.Score * x.Weight / 100) * 10)) / 10; Dictionary keyValues1 = new Dictionary() { { nameof(RB_OKR_Objective_ViewModel.Score),TScore} }; List wheres1 = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Objective_ViewModel.Id), FiledValue=model.ObjectiveId, OperatorEnum=OperatorEnum.Equal } }; oKR_ObjectiveRepository.Update(keyValues1, wheres1); changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "修改OKR关键结果【" + keyResultId + "】得分为【" + score + "】", School_Id = userInfo.School_Id, SourceId = 0 }); return ApiResult.Success("", new { Score = score, TScore }); } return ApiResult.Failed(); } /// /// 删除结果 /// /// /// /// public ApiResult SgetOKRMyKeyResultDel(int keyResultId, UserInfo userInfo) { var model = oKR_KeyResultRepository.GetEntity(keyResultId); if (model == null || model.Status == 1) { return ApiResult.Failed("关键结果不存在"); } var list = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveId = model.ObjectiveId }); int MaxSort = list.Max(x => x.Sort); Dictionary keyValues = new Dictionary { { nameof(RB_OKR_KeyResult_ViewModel.Status), 1 }, { nameof(RB_OKR_KeyResult_ViewModel.UpdateBy), userInfo.Id }, { nameof(RB_OKR_KeyResult_ViewModel.UpdateTime), DateTime.Now } }; List wheres = new List() { new WhereHelper(){ FiledName= nameof(RB_OKR_KeyResult_ViewModel.Id), FiledValue=keyResultId, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_KeyResultRepository.Update(keyValues, wheres); bool IsUpdate = false; decimal diff = 0; if (flag) { //删除 需要重新分配权重,目标进度,目标评分 decimal Progress = 0; decimal Score = 0; decimal Weight = 0; if (list.Count() == 1) { //删完了,直接初始化 目标 Dictionary keyValues1 = new Dictionary() { { nameof(RB_OKR_Objective_ViewModel.Progress),Progress}, { nameof(RB_OKR_Objective_ViewModel.Score),Score} }; List wheres1 = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Objective_ViewModel.Id), FiledValue=model.ObjectiveId, OperatorEnum=OperatorEnum.Equal } }; oKR_ObjectiveRepository.Update(keyValues1, wheres1); Weight = -1; } else { #region 查询进度 分数 Progress = list.Where(x => x.Id != model.Id).Sum(x => x.Progress * x.Weight / 100); Score = list.Where(x => x.Id != model.Id).Sum(x => x.Score * x.Weight / 100); Dictionary keyValues1 = new Dictionary() { { nameof(RB_OKR_Objective_ViewModel.Progress),(int)Progress}, { nameof(RB_OKR_Objective_ViewModel.Score),Score} }; List wheres1 = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Objective_ViewModel.Id), FiledValue=model.ObjectiveId, OperatorEnum=OperatorEnum.Equal } }; oKR_ObjectiveRepository.Update(keyValues1, wheres1); #endregion if (list.Select(x => x.Weight).Distinct().Count() == 1) { //说明权重一致 平摊到每个结果里 Weight = Convert.ToDecimal((int)((Convert.ToDecimal(100) / (list.Count() - 1)) * 10)) / 10; IsUpdate = true; } else if (list.Select(x => x.Weight).Distinct().Count() == 2) { if ((list.Max(x => x.Weight) - list.Min(x => x.Weight)) == (decimal)0.1) { //相差0.1 特殊情况 可以分摊 Weight = Convert.ToDecimal((int)((Convert.ToDecimal(100) / (list.Count() - 1)) * 10)) / 10; IsUpdate = true; } } if (IsUpdate) { //平摊 if (Weight > 0 && (list.Count() - 1) * Weight != 100) { diff = 100 - (list.Count() - 1) * Weight; } decimal NowWeight = Weight + diff; int MaxSort1 = list.Where(x => x.Id != model.Id).Max(x => x.Sort); foreach (var item in list.Where(x => x.Id != model.Id)) { Dictionary keyValues2 = new Dictionary() { { nameof(RB_OKR_KeyResult_ViewModel.Weight), (diff > 0 && MaxSort1 == item.Sort ) ? Weight + diff : Weight} }; List wheres2 = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_KeyResult_ViewModel.Id), FiledValue=item.Id, OperatorEnum=OperatorEnum.Equal } }; oKR_KeyResultRepository.Update(keyValues2, wheres2); } } else { //删除的如果是最后一个 权重转移至倒数第二个 //删除的如果不是最后一个 权重转移至最后一个 if (model.Sort == MaxSort) { //查询倒数第二个 var TwoModel = list.Where(x => x.Sort != MaxSort).OrderByDescending(x => x.Sort).FirstOrDefault(); Weight = TwoModel.Weight + model.Weight; Dictionary keyValues2 = new Dictionary() { { nameof(RB_OKR_KeyResult_ViewModel.Weight), Weight} }; List wheres2 = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_KeyResult_ViewModel.Id), FiledValue=TwoModel.Id, OperatorEnum=OperatorEnum.Equal } }; oKR_KeyResultRepository.Update(keyValues2, wheres2); } else { var LastModel = list.Where(x => x.Sort == MaxSort).FirstOrDefault(); Weight = LastModel.Weight + model.Weight; Dictionary keyValues2 = new Dictionary() { { nameof(RB_OKR_KeyResult_ViewModel.Weight), Weight} }; List wheres2 = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_KeyResult_ViewModel.Id), FiledValue=LastModel.Id, OperatorEnum=OperatorEnum.Equal } }; oKR_KeyResultRepository.Update(keyValues2, wheres2); } } } changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "删除OKR目标关键结果【" + keyResultId + "】", School_Id = userInfo.School_Id, SourceId = 0 }); return ApiResult.Success("", new { TProgress = Progress, TScore = Score, IsApportion = IsUpdate, Diff = diff, LastWeight = Weight, }); } return ApiResult.Failed(); } /// /// 设置对齐 /// /// /// /// /// public string SetOKRMyObjectiveParent(int objectiveId, int parentId, UserInfo userInfo) { var vlist = oKR_ObjectiveRelationRepository.GetList(new Model.Entity.OKR.RB_OKR_ObjectiveRelation() { ObjectiveId = objectiveId, ParentId = parentId }); if (vlist.Any()) { return "已向该 Objective对齐,无法再次对齐"; } var omodel = oKR_ObjectiveRepository.GetEntity(objectiveId); var pmodel = oKR_ObjectiveRepository.GetEntity(parentId); if (omodel == null) { return "目标不存在"; } if (omodel.Status != 2) { return "未审核通过,无法对齐"; } if (omodel.CreateBy != userInfo.Id) { return "不是自己目标,无法对齐"; } if (pmodel == null) { return "对齐目标不存在"; } if (pmodel.Status != 2) { return "未审核目标,无法对齐"; } //验证是否会出现循环对齐 父级继续向上找/当前向下找;看是否有交集 string childIds = oKR_ObjectiveRelationRepository.GetObjectiveChildIds(objectiveId); if (childIds.Split(',').Contains(parentId.ToString())) { return "对齐失败,该 Objective 已向你对齐"; } int Id = oKR_ObjectiveRelationRepository.Insert(new Model.Entity.OKR.RB_OKR_ObjectiveRelation() { Id = 0, ObjectiveId = objectiveId, ParentId = parentId }); if (Id > 0) { //记录日志 changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "新增OKR对齐,由【" + objectiveId + "】向【" + parentId + "】对齐", School_Id = userInfo.School_Id, SourceId = 0 }); } return Id > 0 ? "" : "出错了,请联系管理员"; } /// /// 取消对齐 /// /// /// /// /// public string SgetOKRMyObjectiveParentCancel(int objectiveId, int parentId, UserInfo userInfo) { var omodel = oKR_ObjectiveRepository.GetEntity(objectiveId); if (omodel == null) { return "目标不存在"; } if (omodel.CreateBy != userInfo.Id) { return "不是自己目标,无法取消对齐"; } var vlist = oKR_ObjectiveRelationRepository.GetList(new Model.Entity.OKR.RB_OKR_ObjectiveRelation() { ObjectiveId = objectiveId, ParentId = parentId }); if (vlist.Any()) { foreach (var item in vlist) { oKR_ObjectiveRelationRepository.Delete(item); } //记录日志 changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "取消OKR对齐,取消由【" + objectiveId + "】向【" + parentId + "】对齐", School_Id = userInfo.School_Id, SourceId = 0 }); return ""; } else { return ""; } } /// /// 获取权限列表 /// /// /// /// /// public List GetOKRPermissionList(int targetId, int type, UserInfo userInfo) { var list = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = type, TargetId = targetId, CreateBy = userInfo.Id }); if (list.Any()) { //人员 部门 岗位查询 string rids = string.Join(",", list.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee).Select(x => x.SourceId)); string bids = string.Join(",", list.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department).Select(x => x.SourceId)); string gids = string.Join(",", list.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post).Select(x => x.SourceId)); var peopleList = new List(); if (!string.IsNullOrEmpty(rids)) { peopleList = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { QIds = rids, IsLeave = 1 }); } var departmentList = new List(); if (!string.IsNullOrEmpty(bids)) { departmentList = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { QDeptIds = bids }); } var postList = new List(); if (!string.IsNullOrEmpty(gids)) { postList = postRepository.GetPostListRepository(new Model.ViewModel.User.RB_Post_ViewModel() { QPostIds = gids }); } foreach (var item in list) { if (item.Type == Common.Enum.OKR.PermissionTypeEnum.Employee) { item.SourceName = peopleList.Where(x => x.Id == item.SourceId).FirstOrDefault()?.EmployeeName ?? ""; } else if (item.Type == Common.Enum.OKR.PermissionTypeEnum.Department) { item.SourceName = departmentList.Where(x => x.DeptId == item.SourceId).FirstOrDefault()?.DeptName ?? ""; } else if (item.Type == Common.Enum.OKR.PermissionTypeEnum.Post) { item.SourceName = postList.Where(x => x.PostId == item.SourceId).FirstOrDefault()?.PostName ?? ""; } } } return list; } /// /// 保存权限 /// /// /// /// /// /// public string SgetOKRPermissionInfo(int permissionType, int targetId, List list, UserInfo userInfo) { //查询该用户是否已有该权限 var plist = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = permissionType, TargetId = targetId, CreateBy = userInfo.Id }); var trans = oKR_PermissionRepository.DbTransaction; try { if (list.Any()) { //没有新增 多的删除 foreach (var item in list) { var model = plist.Where(x => x.Type == item.Type && x.SourceId == item.SourceId).FirstOrDefault(); if (model == null) { //新增 oKR_PermissionRepository.Insert(item); } else if (model.State != item.State) { //修改 Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_Permission_ViewModel.State),item.State}, { nameof(RB_OKR_Permission_ViewModel.UpdateBy),userInfo.Id}, { nameof(RB_OKR_Permission_ViewModel.UpdateTime),DateTime.Now}, }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Permission_ViewModel.Id), FiledValue=model.Id, OperatorEnum=OperatorEnum.Equal } }; oKR_PermissionRepository.Update(keyValues, wheres, trans); } } foreach (var item in plist) { if (!list.Where(x => x.Type == item.Type && x.SourceId == item.SourceId).Any()) { oKR_PermissionRepository.Delete(item, trans); } } } else { //删除所有权限 oKR_PermissionRepository.DeleteBatch(plist, trans); } oKR_PermissionRepository.DBSession.Commit(); changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "修改OKR权限,类型" + permissionType + " 目标" + targetId + "的权限", School_Id = userInfo.School_Id, SourceId = 0 }); return ""; } catch (Exception ex) { oKR_PermissionRepository.DBSession.Rollback(); LogHelper.Write(ex, "SgetOKRPermissionInfo"); return "出错了,请联系管理员"; } } /// /// 获取周期/目标/结果 默认所有人可见权限 /// /// /// /// /// public object GetOKRDefaultPermissionInfo(int permissionType, int targetId, UserInfo userInfo) { if (permissionType == 1) { if (oKR_PeriodPermissionRepository.GetList(new Model.Entity.OKR.RB_OKR_PeriodPermission() { Group_Id = userInfo.Group_Id, PeriodId = targetId, CreateBy = userInfo.Id }).Any()) { return 2; } else { return 1; } } else if (permissionType == 2) { return oKR_ObjectiveRepository.GetEntity(targetId)?.IsDefaultPermission ?? 1; } else { return oKR_KeyResultRepository.GetEntity(targetId)?.IsDefaultPermission ?? 1; } } /// /// 设置周期/目标/结果 默认所有人可见权限 /// /// /// /// /// /// public bool SgetOKRDefaultPermissionInfo(int permissionType, int targetId, int permission, UserInfo userInfo) { if (permissionType == 1) { var list = oKR_PeriodPermissionRepository.GetList(new Model.Entity.OKR.RB_OKR_PeriodPermission() { Group_Id = userInfo.Group_Id, PeriodId = targetId, CreateBy = userInfo.Id }); if (permission == 1) { foreach (var item in list) { oKR_PeriodPermissionRepository.Delete(item); } } else { if (!list.Any()) { oKR_PeriodPermissionRepository.Insert(new Model.Entity.OKR.RB_OKR_PeriodPermission() { Id = 0, Group_Id = userInfo.Group_Id, PeriodId = targetId, IsDefaultPermission = 2, CreateBy = userInfo.Id, CreateTime = DateTime.Now }); } } return true; } else if (permissionType == 2) { Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_Objective_ViewModel.IsDefaultPermission),permission} }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Objective_ViewModel.Id), FiledValue=targetId, OperatorEnum=OperatorEnum.Equal } }; return oKR_ObjectiveRepository.Update(keyValues, wheres); } else { Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_KeyResult_ViewModel.IsDefaultPermission),permission} }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_KeyResult_ViewModel.Id), FiledValue=targetId, OperatorEnum=OperatorEnum.Equal } }; return oKR_KeyResultRepository.Update(keyValues, wheres); } } /// /// 获取左边人员列表 /// /// /// public object GetOKRMyEmployeeList(UserInfo userInfo) { try { var deptModel = departmentRepository.GetEntity(userInfo.DeptId); List UserIdList = new List(); List ParentIdList = new List(); #region 我的直属上级 List sjdlist = new List(); bool sjdlistSelect = false; List ZSList = new List(); var accountModel = accountRepository.GetEntity(userInfo.Id); if (accountModel.DirectSupervisor > 0) { var directModel = accountRepository.GetEmployeeInfo(accountModel.DirectSupervisor); ZSList.Add(new Model.ViewModel.User.Employee_ViewModel { Id = directModel.Id, EmployeeName = directModel.EmployeeName, UserIcon = directModel.UserIcon, Dept_Id = directModel.Dept_Id }); UserIdList.Add(directModel.Id); ParentIdList.Add(directModel.Id); } else { //根据部门查询 string ManagerIds = ""; sjdlist = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, ManagerIds = userInfo.Id.ToString() }); sjdlistSelect = true; if (sjdlist.Any()) { //说明是部门主管 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, IsLeave = 1 }); foreach (var item in list) { ZSList.Add(new Model.ViewModel.User.Employee_ViewModel() { Id = item.Id, EmployeeName = item.EmployeeName, UserIcon = item.UserIcon, Dept_Id = item.Dept_Id }); UserIdList.Add(item.Id); ParentIdList.Add(item.Id); } } } #endregion #region 我的直属下级 List ChildList = new List(); var emList = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, 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); } } //如果是部门主管 需要将部门下除自己其他人加入 //查询部门负责人 负责的所有部门 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, IsLeave = 1, QDeptIds = string.Join(",", xjdlist.Select(x => x.DeptId)) }); em1List = em1List.Where(x => !UserIdList.Contains(x.Id) && x.DirectSupervisor == 0).ToList();//排序 已存在的直接关系 if (em1List.Any()) { //查询全部负责人 string AllManagerIds = departmentRepository.GetAllDepartmentManagerIds(userInfo.Group_Id); List AllDeptManageId = new List(); if (!string.IsNullOrEmpty(AllManagerIds)) { AllDeptManageId = JsonHelper.DeserializeObject>("[" + 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, IsLeave = 1, 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 #region 我的同级 List SiblingList = new List(); if (ParentIdList.Any()) { var em2List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, DirectSupervisorIds = string.Join(",", ParentIdList) }); em2List = em2List.Where(x => x.Id != userInfo.Id && !UserIdList.Contains(x.Id)).ToList(); foreach (var item in em2List) { SiblingList.Add(new Model.ViewModel.User.Employee_ViewModel() { Id = item.Id, EmployeeName = item.EmployeeName, UserIcon = item.UserIcon }); 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()) { //上级所在部门下 所有的普通成员 var em1List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, 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) { 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, IsLeave = 1, 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 (!sjdlist.Any()) { var em1List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, Dept_Id = userInfo.DeptId }); 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); } } } #endregion #region 我的关注 List AttentionList = new List(); var alist = oKR_AttentionRepository.GetList(new RB_OKR_Attention_ViewModel() { Group_Id = userInfo.Group_Id, AccountId = userInfo.Id }); if (alist.Any()) { string aids = string.Join(",", alist.Select(x => x.AttentionId)); var em3List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { QIds = aids, IsLeave = 1 }); foreach (var item in em3List) { AttentionList.Add(new Model.ViewModel.User.Employee_ViewModel() { Id = item.Id, EmployeeName = item.EmployeeName, UserIcon = item.UserIcon }); UserIdList.Add(item.Id); } } #endregion //还差了个 是否有最新消息返回------------------------------------------------------ if (UserIdList.Any()) { var list = oKR_UpdateNotificationRepository.GetList(new RB_OKR_UpdateNotification_ViewModel() { ReceiveId = userInfo.Id, UpdateByIds = string.Join(",", UserIdList), State = 2 }); var UserUpdateList = list.Select(x => x.UpdateBy).ToList(); ZSList.Where(x => UserUpdateList.Contains(x.Id)).ToList().ForEach(x => { x.IsBirth = 1; }); ChildList.Where(x => UserUpdateList.Contains(x.Id)).ToList().ForEach(x => { x.IsBirth = 1; }); SiblingList.Where(x => UserUpdateList.Contains(x.Id)).ToList().ForEach(x => { x.IsBirth = 1; }); AttentionList.Where(x => UserUpdateList.Contains(x.Id)).ToList().ForEach(x => { x.IsBirth = 1; }); } return new { ParentList = ZSList.Select(x => new { x.Id, x.EmployeeName, x.UserIcon, IsHaveUpdate = x.IsBirth }), ChildList = ChildList.Select(x => new { x.Id, x.EmployeeName, x.UserIcon, IsHaveUpdate = x.IsBirth }), SiblingList = SiblingList.Select(x => new { x.Id, x.EmployeeName, x.UserIcon, IsHaveUpdate = x.IsBirth }), AttentionList = AttentionList.Select(x => new { x.Id, x.EmployeeName, x.UserIcon, IsHaveUpdate = x.IsBirth }) }; } catch (Exception ex) { Common.Plugin.LogHelper.Write(ex, "GetOKRMyEmployeeList:userInfo" + Common.Plugin.JsonHelper.Serialize(userInfo)); } return new object(); } /// /// 根据部门获取部门下所有人员 /// /// /// /// public List GetDepartmentEmployeeList(int Group_Id, string QDeptIds) { var em1List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = Group_Id, IsLeave = 1, QDeptIds = QDeptIds }); return em1List; } /// /// 获取我的直属下级 /// /// /// public List GetMyUnderlingUserIdList(UserInfo userInfo, int DeptId = 0, int PostId = 0, int leaveStatus = 0, string userName ="") { List UserIdList = new List(); #region 我的直属下级 var emList = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, EmployeeName = userName, IsLeave = 1, DirectSupervisor = userInfo.Id, Dept_Id = DeptId, Post_Id = PostId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); if (emList.Any()) { foreach (var item in emList) { UserIdList.Add(item.Id); } } //如果是部门主管 需要将部门下除自己其他人加入 //查询部门负责人 负责的所有部门 var xjdlist = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { DeptId = DeptId, 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, EmployeeName = userName, IsLeave = 1, QDeptIds = string.Join(",", xjdlist.Select(x => x.DeptId)), Post_Id = PostId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); em1List = em1List.Where(x => !UserIdList.Contains(x.Id) && x.DirectSupervisor == 0).ToList();//排序 已存在的直接关系 if (em1List.Any()) { //查询全部负责人 string AllManagerIds = departmentRepository.GetAllDepartmentManagerIds(userInfo.Group_Id); List AllDeptManageId = new List(); if (!string.IsNullOrEmpty(AllManagerIds)) { AllDeptManageId = JsonHelper.DeserializeObject>("[" + 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, EmployeeName = userName, IsLeave = 1, QIds = ManagerIds, Post_Id = PostId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); 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 return UserIdList; } /// /// 获取我所有下级 /// /// /// public List GetMyAllDownlineUserIdList(UserInfo userInfo, int DeptId = 0, int PostId = 0, int leaveStatus = 0, string userName ="") { List UserIdList = new List() { userInfo.Id }; #region 我的所有下级(部门层级所有人+直属人) //如果是部门主管 需要将部门下除自己其他人加入 //查询部门负责人 负责的所有部门 var xjdlist = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { DeptId = DeptId, Group_Id = userInfo.Group_Id, ManagerIds = userInfo.Id.ToString() }); if (xjdlist.Any()) { List DeptIdList = new List(); foreach (var item in xjdlist) { //查询出所有的部门 string DeptIds = departmentRepository.GetCurrentAndChildDepartmentIdsRepository(item.DeptId); if (!string.IsNullOrEmpty(DeptIds)) { DeptIdList.AddRange(JsonHelper.DeserializeObject>("[" + DeptIds + "]")); } } //查询该部门下所有人 var em1List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, EmployeeName = userName, IsLeave = 1, QDeptIds = string.Join(",", DeptIdList.Distinct()), Post_Id = PostId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); em1List = em1List.Where(x => x.DirectSupervisor == 0).ToList();//排序 已存在的直接关系 foreach (var item in em1List) { UserIdList.Add(item.Id); } //上级部门下所有子部门的负责人 var d2list = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, QDeptIds = string.Join(",", DeptIdList.Distinct()) }); 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, EmployeeName = userName, IsLeave = 1, QIds = ManagerIds, Post_Id = PostId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); 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); } } UserIdList = UserIdList.Distinct().ToList(); //查询这些人的直属人 var emList = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, EmployeeName = userName, IsLeave = 1, DirectSupervisorIds = string.Join(",", UserIdList), Dept_Id = DeptId, Post_Id = PostId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); if (emList.Any()) { foreach (var item in emList) { UserIdList.Add(item.Id); } } } else { //非部门负责人 直接查直属 var emList = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, EmployeeName = userName, IsLeave = 1, DirectSupervisor = userInfo.Id, Dept_Id = DeptId, Post_Id = PostId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); if (emList.Any()) { foreach (var item in emList) { UserIdList.Add(item.Id); } } } #endregion return UserIdList.Distinct().ToList(); } /// /// 获取我的审核人员列表 /// /// /// /// public object GetOKRMyEmployeeAuditList(int periodId, UserInfo userInfo) { List ChildIdList = GetMyUnderlingUserIdList(userInfo); #region 我的审批 List AuditList = new List(); //直接拿直属下级 待审核的 if (ChildIdList.Any()) { var list = oKR_ObjectiveRepository.GetOKRMyEmployeeAuditList(userInfo.Group_Id, periodId, string.Join(",", ChildIdList)); if (list.Any()) { string emIds = string.Join(",", list.Select(x => x.CreateBy)); var emlist = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { QIds = emIds, IsLeave = 1 }); foreach (var item in emlist) { AuditList.Add(new { item.Id, item.EmployeeName, item.UserIcon, PeriodIds = list?.Where(qitem => qitem.CreateBy == item.Id)?.FirstOrDefault()?.PeriodIds ?? "" }); } } } #endregion return AuditList; } /// /// 获取我的对齐 /// /// /// /// public object GetOKRMyEmployeeAlignList(int periodId, UserInfo userInfo) { //查询当期目标所有对齐 , 对齐目标的所有用户 List AlignList = new List(); var list = oKR_ObjectiveRepository.GetOKRMyEmployeeAlignList(userInfo.Group_Id, periodId, userInfo.Id); if (list.Any()) { string emIds = string.Join(",", list.Select(x => x.CreateBy)); var unlist = oKR_UpdateNotificationRepository.GetList(new RB_OKR_UpdateNotification_ViewModel() { ReceiveId = userInfo.Id, UpdateByIds = emIds, State = 2 }); var emlist = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { QIds = emIds, IsLeave = 1 }); foreach (var item in emlist) { AlignList.Add(new { item.Id, item.EmployeeName, item.UserIcon, IsHaveUpdate = unlist.Where(x => x.UpdateBy == item.Id).Any() ? 1 : 0 }); } } return AlignList; } /// /// 获取人员关注 /// /// /// /// public ApiResult GetOKREmployeeAttention(int userId, UserInfo userInfo) { bool Attention = false; var list = oKR_AttentionRepository.GetList(new RB_OKR_Attention_ViewModel() { Group_Id = userInfo.Group_Id, AccountId = userInfo.Id, AttentionId = userId }); if (list.Any()) { Attention = true; } return ApiResult.Success("", Attention); } /// /// 设置关注 /// /// /// /// /// public string SgetOKREmployeeAttention(int userId, int type, UserInfo userInfo) { var list = oKR_AttentionRepository.GetList(new RB_OKR_Attention_ViewModel() { Group_Id = userInfo.Group_Id, AccountId = userInfo.Id, AttentionId = userId }); if (type == 1) { if (list.Any()) { return "已经关注,无法再次关注"; } bool flag = oKR_AttentionRepository.Insert(new Model.Entity.OKR.RB_OKR_Attention() { AccountId = userInfo.Id, Id = 0, AttentionId = userId, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, School_Id = userInfo.School_Id, Status = 0, UpdateBy = userInfo.Id, UpdateTime = DateTime.Now }) > 0; if (flag) { //记录日志 changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "OKR关注用户【" + (UserReidsCache.GetUserLoginInfo(userId)?.AccountName ?? "") + "】", School_Id = userInfo.School_Id, SourceId = 0 }); } return flag ? "" : "出错了,请联系管理员"; } else { if (!list.Any()) { return "尚未关注,无法取消关注"; } Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_Attention_ViewModel.Status),1} }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Attention_ViewModel.Id), FiledValue=list.FirstOrDefault().Id, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_AttentionRepository.Update(keyValues, wheres); if (flag) { //记录日志 changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "OKR取消关注用户【" + (UserReidsCache.GetUserLoginInfo(userId)?.AccountName ?? "") + "】", School_Id = userInfo.School_Id, SourceId = 0 }); } return flag ? "" : "出错了,请联系管理员"; } } /// /// 目标审核 /// /// /// /// /// /// public string SetOKRObjectiveAudit(int objectiveId, int type, string remark, UserInfo userInfo) { var model = oKR_ObjectiveRepository.GetEntity(objectiveId); if (model == null) { return "目标不存在"; } if (model.Status != 1) { return "非待审核状态,无法审核"; } List UserIdList = GetMyUnderlingUserIdList(userInfo); if (!UserIdList.Contains(model.CreateBy)) { return "该目标不是直属下级目标,无法审核"; } Dictionary keyValues = new Dictionary(); if (type == 1) { keyValues.Add(nameof(RB_OKR_Objective_ViewModel.Status), 2); } else { keyValues.Add(nameof(RB_OKR_Objective_ViewModel.Status), 3); } keyValues.Add(nameof(RB_OKR_Objective_ViewModel.AuditUserId), userInfo.Id); keyValues.Add(nameof(RB_OKR_Objective_ViewModel.AuditTime), DateTime.Now); keyValues.Add(nameof(RB_OKR_Objective_ViewModel.AuditRemark), remark); List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Objective_ViewModel.Id), FiledValue=objectiveId, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_ObjectiveRepository.Update(keyValues, wheres); if (flag) { //记录日志 changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "OKR审核目标【" + model.Title + "】", School_Id = userInfo.School_Id, SourceId = 0 }); } return flag ? "" : "出错了,请联系管理员"; } /// /// 目标重新发起审核 /// /// /// /// public string SetOKRObjectiveAuditAgain(int objectiveId, UserInfo userInfo) { var model = oKR_ObjectiveRepository.GetEntity(objectiveId); if (model == null) { return "目标不存在"; } // HK 03-01注释 //if (model.Status != 3 && model.Status != 4) { // return "非暂存/审核驳回状态,无法发起审核"; //} Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_Objective_ViewModel.Status), 1} }; List wheres = new List() { new WhereHelper() { FiledName=nameof(RB_OKR_Objective_ViewModel.Id), FiledValue=objectiveId, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_ObjectiveRepository.Update(keyValues, wheres); if (flag) { //记录日志 changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() { Id = 0, Type = 1, CreateBy = userInfo.Id, CreateTime = DateTime.Now, Group_Id = userInfo.Group_Id, LogContent = "OKR重新发起审核目标【" + model.Id + "】", School_Id = userInfo.School_Id, SourceId = 0 }); } return flag ? "" : "出错了,请联系管理员"; } /// /// 清除用户更新提示 /// /// /// /// public string ClearMyEmployeeUpdateNotification(int userId, UserInfo userInfo) { var model = oKR_UpdateNotificationRepository.GetList(new RB_OKR_UpdateNotification_ViewModel() { Group_Id = userInfo.Group_Id, ReceiveId = userInfo.Id, UpdateBy = userId, State = 2 }).FirstOrDefault(); if (model == null) { return ""; } Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_UpdateNotification_ViewModel.State),1 }, { nameof(RB_OKR_UpdateNotification_ViewModel.UpdateBy),userInfo.Id }, { nameof(RB_OKR_UpdateNotification_ViewModel.UpdateTime),DateTime.Now } }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_UpdateNotification_ViewModel.Id), FiledValue=model.Id, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_UpdateNotificationRepository.Update(keyValues, wheres); return flag ? "" : "出错了,请联系管理员"; } /// /// 新增用户更新提示 /// /// /// /// public bool AddMyEmployeeUpdateNotification(int periodId, UserInfo userInfo) { try { var deptModel = departmentRepository.GetEntity(userInfo.DeptId); List UserIdList = new List(); List ParentIdList = new List(); #region 我的直属上级 List ZSList = new List(); var accountModel = accountRepository.GetEntity(userInfo.Id); if (accountModel.DirectSupervisor > 0) { var directModel = accountRepository.GetEmployeeInfo(accountModel.DirectSupervisor); ZSList.Add(new Model.ViewModel.User.Employee_ViewModel { Id = directModel.Id, EmployeeName = directModel.EmployeeName, UserIcon = directModel.UserIcon, Dept_Id = directModel.Dept_Id }); UserIdList.Add(directModel.Id); ParentIdList.Add(directModel.Id); } else { //根据部门查询 string ManagerIds = ""; var sjdlist = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, ManagerIds = userInfo.Id.ToString() }); if (sjdlist.Any()) { //说明是部门主管 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, IsLeave = 1 }); foreach (var item in list) { ZSList.Add(new Model.ViewModel.User.Employee_ViewModel() { Id = item.Id, EmployeeName = item.EmployeeName, UserIcon = item.UserIcon, Dept_Id = item.Dept_Id }); UserIdList.Add(item.Id); ParentIdList.Add(item.Id); } } } #endregion #region 我的直属下级 var emList = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, DirectSupervisor = userInfo.Id }); if (emList.Any()) { foreach (var item in emList) { UserIdList.Add(item.Id); } } //如果是部门主管 需要将部门下除自己其他人加入 //查询部门负责人 负责的所1有部门 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, IsLeave = 1, 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) { UserIdList.Add(item.Id); } } #endregion #region 我的同级 if (ParentIdList.Any()) { var em2List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, DirectSupervisorIds = string.Join(",", ParentIdList) }); em2List = em2List.Where(x => x.Id != userInfo.Id && !UserIdList.Contains(x.Id)).ToList(); foreach (var item in em2List) { 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, IsLeave = 1, 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) { 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, IsLeave = 1, 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); } } } } } else { //继续查询同部门的 也算同级 if (!("," + deptModel.ManagerIds + ",").Contains("," + userInfo.Id + ",")) { var em1List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, Dept_Id = userInfo.DeptId }); em1List = em1List.Where(x => !UserIdList.Contains(x.Id) && x.Id != userInfo.Id).ToList();//排序 已存在的直接关系 foreach (var item in em1List) { UserIdList.Add(item.Id); } } } #endregion #region 我的关注 var alist = oKR_AttentionRepository.GetList(new RB_OKR_Attention_ViewModel() { Group_Id = userInfo.Group_Id, AccountId = userInfo.Id }); if (alist.Any()) { string aids = string.Join(",", alist.Select(x => x.AttentionId)); var em3List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { QIds = aids, IsLeave = 1 }); foreach (var item in em3List) { UserIdList.Add(item.Id); } } #endregion #region 我的对齐 List AlignList = new List(); var list2 = oKR_ObjectiveRepository.GetOKRMyEmployeeAlignList(userInfo.Group_Id, periodId, userInfo.Id); string emIds = string.Join(",", list2.Select(x => x.CreateBy)); var emlist = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { QIds = emIds, IsLeave = 1 }); foreach (var item in emlist) { UserIdList.Add(item.Id); } #endregion if (UserIdList.Any()) { UserIdList = UserIdList.Distinct().ToList(); var unList = oKR_UpdateNotificationRepository.GetList(new RB_OKR_UpdateNotification_ViewModel() { Group_Id = userInfo.Group_Id, ReceiveIds = string.Join(",", UserIdList), UpdateBy = userInfo.Id }); foreach (var item in UserIdList) { var model = unList.Where(x => x.ReceiveId == item).FirstOrDefault(); if (model != null) { if (model.State == 1) { Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_UpdateNotification_ViewModel.State),2}, { nameof(RB_OKR_UpdateNotification_ViewModel.UpdateTime),DateTime.Now}, }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_UpdateNotification_ViewModel.Id), FiledValue=model.Id, OperatorEnum=OperatorEnum.Equal } }; oKR_UpdateNotificationRepository.Update(keyValues, wheres); } } else { //新增 oKR_UpdateNotificationRepository.Insert(new Model.Entity.OKR.RB_OKR_UpdateNotification() { Id = 0, Group_Id = userInfo.Group_Id, State = 2, ReceiveId = item, UpdateBy = userInfo.Id, UpdateTime = DateTime.Now }); } } } return true; } catch (Exception ex) { LogHelper.Write(ex, "AddMyEmployeeUpdateNotification"); return false; } } /// /// 新增用户更新提示 /// /// /// /// public bool AddMyEmployeeUpdateNotification_V2(int objectiveId, UserInfo userInfo) { var model = oKR_ObjectiveRepository.GetEntity(objectiveId); if (model != null) { return AddMyEmployeeUpdateNotification(model.PeriodId, userInfo); } return false; } /// /// 前端调用更新提示 /// /// /// /// public bool SetMyUserUpdateNotification(List UserIdList, UserInfo userInfo) { if (UserIdList.Any()) { UserIdList = UserIdList.Distinct().ToList(); var unList = oKR_UpdateNotificationRepository.GetList(new RB_OKR_UpdateNotification_ViewModel() { Group_Id = userInfo.Group_Id, ReceiveIds = string.Join(",", UserIdList), UpdateBy = userInfo.Id }); foreach (var item in UserIdList) { var model = unList.Where(x => x.ReceiveId == item).FirstOrDefault(); if (model != null) { if (model.State == 1) { Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_UpdateNotification_ViewModel.State),2}, { nameof(RB_OKR_UpdateNotification_ViewModel.UpdateTime),DateTime.Now}, }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_UpdateNotification_ViewModel.Id), FiledValue=model.Id, OperatorEnum=OperatorEnum.Equal } }; oKR_UpdateNotificationRepository.Update(keyValues, wheres); } } else { //新增 oKR_UpdateNotificationRepository.Insert(new Model.Entity.OKR.RB_OKR_UpdateNotification() { Id = 0, Group_Id = userInfo.Group_Id, State = 2, ReceiveId = item, UpdateBy = userInfo.Id, UpdateTime = DateTime.Now }); } } } return true; } #endregion #region 提醒通知 /// /// 发送提醒通知 /// /// /// public bool SendOKRRemid() { var rlist = oKR_RemindRepository.GetList(new RB_OKR_Remind_ViewModel() { Enable = 1 }); if (rlist.Any()) { var groupIdList = rlist.Select(x => x.Group_Id).Distinct().ToList(); foreach (var GroupId in groupIdList) { try { //获取当前周期 var currentModel = oKR_PeriodRepository.GetList(new RB_OKR_Period_ViewModel() { Group_Id = GroupId, IsCurrent = 1, IsNormal = 1, IsYear = 2 }).FirstOrDefault(); if (currentModel == null) { return false; } var r1Model = rlist.Where(x => x.Type == 1).FirstOrDefault(); var r2Model = rlist.Where(x => x.Type == 2).FirstOrDefault(); var r3Model = rlist.Where(x => x.Type == 3).FirstOrDefault(); var r4Model = rlist.Where(x => x.Type == 4).FirstOrDefault(); if (r1Model != null && !string.IsNullOrEmpty(r1Model.Days)) { int Days = (DateTime.Now - currentModel.StartDate).Days + 1; if (("," + r1Model.Days + ",").Contains("," + Days + ",")) { //查询该员工未填写OKR / 未提交审核OKR var nlist = accountRepository.GetOKRUserNotObjectiveList(GroupId); foreach (var item in nlist) { //发送通知 看通知接口 是否支持定时发送 } } } if (r2Model != null && !string.IsNullOrEmpty(r2Model.Days)) { int Days = (currentModel.EndDate - DateTime.Now).Days + 1; if (("," + r2Model.Days + ",").Contains("," + Days + ",")) { //查询员工有未打分的目标 var nlist = accountRepository.GetOKRUserNotScoreList(GroupId); foreach (var item in nlist) { //发送通知 } } } if (r3Model != null && !string.IsNullOrEmpty(r3Model.Days)) { int Days = (DateTime.Now - currentModel.StartDate).Days + 1; if (("," + r1Model.Days + ",").Contains("," + Days + ",")) { //查询该员工未填写OKR / 未提交审核OKR var nlist = accountRepository.GetOKRUserNotObjectiveList(GroupId); foreach (var item in nlist) { //查找其上级 var amodel = accountRepository.GetEntity(item.EmployeeId); if (amodel.DirectSupervisor > 0) { //有直属上级 直接给直属上级推 } else { //看其是否是部门主管 var dlist = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = item.RB_Group_id, ManagerIds = item.EmployeeId.ToString() }); if (dlist.Any()) { //是部门主管 查找其上级部门负责人 foreach (var qitem in dlist) { var dmodel = departmentRepository.GetEntity(qitem.ParentId); if (!string.IsNullOrEmpty(dmodel.ManagerIds)) { //给上级部门负责人推送 } } } else { //查询其当前部门负责人 var dmodel = departmentRepository.GetEntity(item.RB_Department_Id); if (!string.IsNullOrEmpty(dmodel.ManagerIds)) { //给部门负责人推送 } } } } } } if (r4Model != null && !string.IsNullOrEmpty(r4Model.Days)) { int Days = (currentModel.EndDate - DateTime.Now).Days + 1; if (("," + r2Model.Days + ",").Contains("," + Days + ",")) { //查询员工有未打分的目标 var nlist = accountRepository.GetOKRUserNotScoreList(GroupId); foreach (var item in nlist) { //查找其上级 var amodel = accountRepository.GetEntity(item.EmployeeId); if (amodel.DirectSupervisor > 0) { //有直属上级 直接给直属上级推 } else { //看其是否是部门主管 var dlist = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = item.RB_Group_id, ManagerIds = item.EmployeeId.ToString() }); if (dlist.Any()) { //是部门主管 查找其上级部门负责人 foreach (var qitem in dlist) { var dmodel = departmentRepository.GetEntity(qitem.ParentId); if (!string.IsNullOrEmpty(dmodel.ManagerIds)) { //给上级部门负责人推送 } } } else { //查询其当前部门负责人 var dmodel = departmentRepository.GetEntity(item.RB_Department_Id); if (!string.IsNullOrEmpty(dmodel.ManagerIds)) { //给部门负责人推送 } } } } } } } catch (Exception ex) { LogHelper.Write(ex, "SendOKRRemid【" + GroupId + "】"); } } } return true; } #endregion #region 统计模块 /// /// 获取我的对齐视图 /// /// /// /// public object GetOKRMyAlignView(int PeriodId, UserInfo userInfo) { var list = oKR_ObjectiveRepository.GetListForEmName(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, CreateBy = userInfo.Id }); if (list.Any()) { List MyUnderlingList = GetMyUnderlingUserIdList(userInfo); string objectiveIds = string.Join(",", list.Select(x => x.Id)); //查询向上对齐 var sdqlist = oKR_ObjectiveRepository.GetParentList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, ObjectiveIds = objectiveIds }); if (sdqlist.Any()) { //查询上对齐数量 var rlist = oKR_ObjectiveRelationRepository.GetParentAlignNum(string.Join(",", sdqlist.Select(x => x.Id))); foreach (var item in sdqlist) { item.ParentNum = rlist.Where(x => x.ObjectiveId == item.Id).FirstOrDefault()?.ParentId ?? 0; } } //查询向下对齐 var xdqlist = oKR_ObjectiveRepository.GetParentList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, ParentIds = objectiveIds }); if (xdqlist.Any()) { //查询下对齐数量 var rlist = oKR_ObjectiveRelationRepository.GetChildAlignNum(string.Join(",", xdqlist.Select(x => x.Id))); foreach (var item in xdqlist) { item.ChildNum = rlist.Where(x => x.ParentId == item.Id).FirstOrDefault()?.ObjectiveId ?? 0; } } List DQUserId = new List(); string jObjectiveIds = objectiveIds; if (sdqlist.Any()) { jObjectiveIds += "," + string.Join(",", sdqlist.Select(x => x.Id)); DQUserId.AddRange(sdqlist.Select(x => x.CreateBy)); } if (xdqlist.Any()) { jObjectiveIds += "," + string.Join(",", xdqlist.Select(x => x.Id)); DQUserId.AddRange(xdqlist.Select(x => x.CreateBy)); } //查询结果列表 var krList = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveIds = jObjectiveIds }); //查询是否有权限 var pList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 2, ObjectiveIds = jObjectiveIds }); //用户周期权限 List UserLookList = new List(); if (DQUserId.Any()) { DQUserId = DQUserId.Distinct().ToList(); //查询是否有权限 var zpList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 1, TargetId = PeriodId, CreateByIds = string.Join(",", DQUserId) }); if (zpList.Any()) { var pplist = oKR_PeriodPermissionRepository.GetList(new Model.Entity.OKR.RB_OKR_PeriodPermission() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId }, string.Join(",", DQUserId)); foreach (var UserId in DQUserId) { int IsLook = 2; if (zpList.Where(x => x.CreateBy == UserId).Any()) { var NotLookList = zpList.Where(x => x.CreateBy == UserId && x.State == 2).ToList(); var LookList = zpList.Where(x => x.CreateBy == UserId && x.State == 1).ToList(); if (NotLookList.Any()) { //有不可看的 if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any()) { IsLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any()) { IsLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { IsLook = 1; } } if (LookList.Any() && pplist.Where(x => x.CreateBy == UserId).Any()) { if (LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { //OK } else { IsLook = 1; } } } else { if (pplist.Where(x => x.CreateBy == UserId).Any()) { IsLook = 1; } } UserLookList.Add(new RB_OKR_Objective_ViewModel() { CreateBy = UserId, IsLock = IsLook }); } } } foreach (var item in sdqlist) { //结果列表 item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); if (item.IsDefaultState == 1 && item.KeyResultList.Any()) { item.ProgressState = item.KeyResultList.Max(x => x.ProgressState); } item.IsLock = 2; item.IsNotLook = 2; if (pList.Where(x => x.TargetId == item.Id).Any()) { item.IsLock = 1; if (!MyUnderlingList.Contains(item.CreateBy) && item.CreateBy != userInfo.Id) { if ((UserLookList.Where(x => x.CreateBy == item.CreateBy).FirstOrDefault()?.IsLock ?? 0) == 1) { item.IsNotLook = 1; } else { var NotLookList = pList.Where(x => x.TargetId == item.Id && x.State == 2).ToList(); var LookList = pList.Where(x => x.TargetId == item.Id && x.State == 1).ToList(); if (NotLookList.Any()) { //有不可看的 if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any()) { item.IsNotLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any()) { item.IsNotLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { item.IsNotLook = 1; } } if (item.IsNotLook == 2 && item.IsDefaultPermission == 2) { if (LookList.Any()) { if (LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { //OK } else { item.IsNotLook = 1; } } } } } } else { if (!MyUnderlingList.Contains(item.CreateBy) && item.CreateBy != userInfo.Id) { if ((UserLookList.Where(x => x.CreateBy == item.CreateBy).FirstOrDefault()?.IsLock ?? 0) == 1) { item.IsNotLook = 1; } } if (item.IsDefaultPermission == 2) { item.IsLock = 1; if (!MyUnderlingList.Contains(item.CreateBy) && item.CreateBy != userInfo.Id) { item.IsNotLook = 1; } } } } foreach (var item in xdqlist) { //结果列表 item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); if (item.IsDefaultState == 1 && item.KeyResultList.Any()) { item.ProgressState = item.KeyResultList.Max(x => x.ProgressState); } item.IsLock = 2; item.IsNotLook = 2; if (pList.Where(x => x.TargetId == item.Id).Any()) { item.IsLock = 1; if (!MyUnderlingList.Contains(item.CreateBy) && item.CreateBy != userInfo.Id) { if ((UserLookList.Where(x => x.CreateBy == item.CreateBy).FirstOrDefault()?.IsLock ?? 0) == 1) { item.IsNotLook = 1; } else { var NotLookList = pList.Where(x => x.TargetId == item.Id && x.State == 2).ToList(); var LookList = pList.Where(x => x.TargetId == item.Id && x.State == 1).ToList(); if (NotLookList.Any()) { //有不可看的 if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any()) { item.IsNotLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any()) { item.IsNotLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { item.IsNotLook = 1; } } if (item.IsNotLook == 2 && item.IsDefaultPermission == 2) { if (LookList.Any()) { if (LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { //OK } else { item.IsNotLook = 1; } } } } } } else { if (!MyUnderlingList.Contains(item.CreateBy) && item.CreateBy != userInfo.Id) { if ((UserLookList.Where(x => x.CreateBy == item.CreateBy).FirstOrDefault()?.IsLock ?? 0) == 1) { item.IsNotLook = 1; } } if (item.IsDefaultPermission == 2) { item.IsLock = 1; if (!MyUnderlingList.Contains(item.CreateBy) && item.CreateBy != userInfo.Id) { item.IsNotLook = 1; } } } } foreach (var item in list) { //结果列表 item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); if (item.IsDefaultState == 1 && item.KeyResultList.Any()) { item.ProgressState = item.KeyResultList.Max(x => x.ProgressState); } #region 对齐列表 item.ParentSingleList = sdqlist.Where(x => x.ObjectiveId == item.Id).ToList(); item.ChildSingleList = xdqlist.Where(x => x.ParentId == item.Id).ToList(); #endregion } } return list.Select(x => new { x.Id, x.Title, x.Sort, x.Progress, x.ProgressState, ProgressStateName = x.ProgressState.ToName(), x.Status, x.EmName, x.EmPhoto, UserId = x.CreateBy, ParentList = x.ParentSingleList.Select(y => new { y.Id, Title = y.IsNotLook == 1 ? "" : y.Title, y.Sort, y.Progress, y.IsLock, y.IsNotLook, y.ProgressState, ProgressStateName = y.ProgressState.ToName(), y.ParentNum, UserId = y.CreateBy, y.EmName, y.EmPhoto }), ChildList = x.ChildSingleList.Select(y => new { y.Id, Title = y.IsNotLook == 1 ? "" : y.Title, y.Sort, y.Progress, y.IsLock, y.IsNotLook, y.ProgressState, ProgressStateName = y.ProgressState.ToName(), y.ChildNum, UserId = y.CreateBy, y.EmName, y.EmPhoto }), }); } /// /// 获取我的对齐视图 再下一级 /// /// /// /// /// /// public object GetOKRMyAlignViewNext(int PeriodId, int objectiveId, int type, UserInfo userInfo) { if (type == 1) { List MyUnderlingList = GetMyUnderlingUserIdList(userInfo); //查询向上对齐 var sdqlist = oKR_ObjectiveRepository.GetParentList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, ObjectiveIds = objectiveId.ToString() }); if (sdqlist.Any()) { //查询上对齐数量 var rlist = oKR_ObjectiveRelationRepository.GetParentAlignNum(string.Join(",", sdqlist.Select(x => x.Id))); foreach (var item in sdqlist) { item.ParentNum = rlist.Where(x => x.ObjectiveId == item.Id).FirstOrDefault()?.ParentId ?? 0; } } else { return new List(); } List DQUserId = new List(); string jObjectiveIds = string.Join(",", sdqlist.Select(x => x.Id)); DQUserId.AddRange(sdqlist.Select(x => x.CreateBy)); //查询结果列表 var krList = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveIds = jObjectiveIds }); //查询是否有权限 var pList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 2, ObjectiveIds = jObjectiveIds }); //用户周期权限 List UserLookList = new List(); if (DQUserId.Any()) { DQUserId = DQUserId.Distinct().ToList(); //查询是否有权限 var zpList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 1, TargetId = PeriodId, CreateByIds = string.Join(",", DQUserId) }); if (zpList.Any()) { var pplist = oKR_PeriodPermissionRepository.GetList(new Model.Entity.OKR.RB_OKR_PeriodPermission() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId }, string.Join(",", DQUserId)); foreach (var UserId in DQUserId) { int IsLook = 2; if (zpList.Where(x => x.CreateBy == UserId).Any()) { var NotLookList = zpList.Where(x => x.CreateBy == UserId && x.State == 2).ToList(); var LookList = zpList.Where(x => x.CreateBy == UserId && x.State == 1).ToList(); if (NotLookList.Any()) { //有不可看的 if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any()) { IsLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any()) { IsLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { IsLook = 1; } } if (LookList.Any() && pplist.Where(x => x.CreateBy == UserId).Any()) { if (LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { //OK } else { IsLook = 1; } } } else { if (pplist.Where(x => x.CreateBy == UserId).Any()) { IsLook = 1; } } UserLookList.Add(new RB_OKR_Objective_ViewModel() { CreateBy = UserId, IsLock = IsLook }); } } } foreach (var item in sdqlist) { //结果列表 item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); if (item.IsDefaultState == 1 && item.KeyResultList.Any()) { item.ProgressState = item.KeyResultList.Max(x => x.ProgressState); } item.IsLock = 2; item.IsNotLook = 2; if (pList.Where(x => x.TargetId == item.Id).Any()) { item.IsLock = 1; if (!MyUnderlingList.Contains(item.CreateBy) && item.CreateBy != userInfo.Id) { if ((UserLookList.Where(x => x.CreateBy == item.CreateBy).FirstOrDefault()?.IsLock ?? 0) == 1) { item.IsNotLook = 1; } else { var NotLookList = pList.Where(x => x.TargetId == item.Id && x.State == 2).ToList(); var LookList = pList.Where(x => x.TargetId == item.Id && x.State == 1).ToList(); if (NotLookList.Any()) { //有不可看的 if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any()) { item.IsNotLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any()) { item.IsNotLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { item.IsNotLook = 1; } } if (item.IsNotLook == 2 && item.IsDefaultPermission == 2) { if (LookList.Any()) { if (LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { //OK } else { item.IsNotLook = 1; } } } } } } else { if (!MyUnderlingList.Contains(item.CreateBy) && item.CreateBy != userInfo.Id) { if ((UserLookList.Where(x => x.CreateBy == item.CreateBy).FirstOrDefault()?.IsLock ?? 0) == 1) { item.IsNotLook = 1; } } if (item.IsDefaultPermission == 2) { item.IsLock = 1; if (!MyUnderlingList.Contains(item.CreateBy) && item.CreateBy != userInfo.Id) { item.IsNotLook = 1; } } } } return sdqlist.Select(y => new { y.Id, Title = y.IsNotLook == 1 ? "" : y.Title, y.Sort, y.Progress, y.IsLock, y.IsNotLook, y.ProgressState, ProgressStateName = y.ProgressState.ToName(), y.ParentNum, UserId = y.CreateBy, y.EmName, y.EmPhoto }); } else { List MyUnderlingList = GetMyUnderlingUserIdList(userInfo); //查询向下对齐 var xdqlist = oKR_ObjectiveRepository.GetParentList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, ParentIds = objectiveId.ToString() }); if (xdqlist.Any()) { //查询下对齐数量 var rlist = oKR_ObjectiveRelationRepository.GetChildAlignNum(string.Join(",", xdqlist.Select(x => x.Id))); foreach (var item in xdqlist) { item.ChildNum = rlist.Where(x => x.ParentId == item.Id).FirstOrDefault()?.ObjectiveId ?? 0; } } else { return new List(); } List DQUserId = new List(); string jObjectiveIds = string.Join(",", xdqlist.Select(x => x.Id)); DQUserId.AddRange(xdqlist.Select(x => x.CreateBy)); //查询结果列表 var krList = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveIds = jObjectiveIds }); //查询是否有权限 var pList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 2, ObjectiveIds = jObjectiveIds }); //用户周期权限 List UserLookList = new List(); if (DQUserId.Any()) { DQUserId = DQUserId.Distinct().ToList(); //查询是否有权限 var zpList = oKR_PermissionRepository.GetList(new RB_OKR_Permission_ViewModel() { Group_Id = userInfo.Group_Id, PermissionType = 1, TargetId = PeriodId, CreateByIds = string.Join(",", DQUserId) }); if (zpList.Any()) { var pplist = oKR_PeriodPermissionRepository.GetList(new Model.Entity.OKR.RB_OKR_PeriodPermission() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId }, string.Join(",", DQUserId)); foreach (var UserId in DQUserId) { int IsLook = 2; if (zpList.Where(x => x.CreateBy == UserId).Any()) { var NotLookList = zpList.Where(x => x.CreateBy == UserId && x.State == 2).ToList(); var LookList = zpList.Where(x => x.CreateBy == UserId && x.State == 1).ToList(); if (NotLookList.Any()) { //有不可看的 if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any()) { IsLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any()) { IsLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { IsLook = 1; } } if (LookList.Any() && pplist.Where(x => x.CreateBy == UserId).Any()) { if (LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { //OK } else { IsLook = 1; } } } else { if (pplist.Where(x => x.CreateBy == UserId).Any()) { IsLook = 1; } } UserLookList.Add(new RB_OKR_Objective_ViewModel() { CreateBy = UserId, IsLock = IsLook }); } } } foreach (var item in xdqlist) { //结果列表 item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); if (item.IsDefaultState == 1 && item.KeyResultList.Any()) { item.ProgressState = item.KeyResultList.Max(x => x.ProgressState); } item.IsLock = 2; item.IsNotLook = 2; if (pList.Where(x => x.TargetId == item.Id).Any()) { item.IsLock = 1; if (!MyUnderlingList.Contains(item.CreateBy) && item.CreateBy != userInfo.Id) { if ((UserLookList.Where(x => x.CreateBy == item.CreateBy).FirstOrDefault()?.IsLock ?? 0) == 1) { item.IsNotLook = 1; } else { var NotLookList = pList.Where(x => x.TargetId == item.Id && x.State == 2).ToList(); var LookList = pList.Where(x => x.TargetId == item.Id && x.State == 1).ToList(); if (NotLookList.Any()) { //有不可看的 if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any()) { item.IsNotLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any()) { item.IsNotLook = 1; } if (NotLookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { item.IsNotLook = 1; } } if (item.IsNotLook == 2 && item.IsDefaultPermission == 2) { if (LookList.Any()) { if (LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Employee && x.SourceId == userInfo.Id).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Post && x.SourceId == userInfo.PostId).Any() || LookList.Where(x => x.Type == Common.Enum.OKR.PermissionTypeEnum.Department && x.SourceId == userInfo.DeptId).Any()) { //OK } else { item.IsNotLook = 1; } } } } } } else { if (!MyUnderlingList.Contains(item.CreateBy) && item.CreateBy != userInfo.Id) { if ((UserLookList.Where(x => x.CreateBy == item.CreateBy).FirstOrDefault()?.IsLock ?? 0) == 1) { item.IsNotLook = 1; } } if (item.IsDefaultPermission == 2) { item.IsLock = 1; if (!MyUnderlingList.Contains(item.CreateBy) && item.CreateBy != userInfo.Id) { item.IsNotLook = 1; } } } } return xdqlist.Select(y => new { y.Id, Title = y.IsNotLook == 1 ? "" : y.Title, y.Sort, y.Progress, y.IsLock, y.IsNotLook, y.ProgressState, ProgressStateName = y.ProgressState.ToName(), y.ChildNum, UserId = y.CreateBy, y.EmName, y.EmPhoto }); } } /// /// 获取管理端 对齐视图 /// /// /// /// /// public object GetOKRAdminAlignView(int PeriodId, int UserId, UserInfo userInfo) { var list = oKR_ObjectiveRepository.GetListForEmName(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, Status = 2, CreateBy = UserId }); if (list.Any()) { string objectiveIds = string.Join(",", list.Select(x => x.Id)); //查询向上对齐 var sdqlist = oKR_ObjectiveRepository.GetParentList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, ObjectiveIds = objectiveIds }); if (sdqlist.Any()) { //查询上对齐数量 var rlist = oKR_ObjectiveRelationRepository.GetParentAlignNum(string.Join(",", sdqlist.Select(x => x.Id))); foreach (var item in sdqlist) { item.ParentNum = rlist.Where(x => x.ObjectiveId == item.Id).FirstOrDefault()?.ParentId ?? 0; } } //查询向下对齐 var xdqlist = oKR_ObjectiveRepository.GetParentList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, ParentIds = objectiveIds }); if (xdqlist.Any()) { //查询下对齐数量 var rlist = oKR_ObjectiveRelationRepository.GetChildAlignNum(string.Join(",", xdqlist.Select(x => x.Id))); foreach (var item in xdqlist) { item.ChildNum = rlist.Where(x => x.ParentId == item.Id).FirstOrDefault()?.ObjectiveId ?? 0; } } List DQUserId = new List(); string jObjectiveIds = objectiveIds; if (sdqlist.Any()) { jObjectiveIds += "," + string.Join(",", sdqlist.Select(x => x.Id)); DQUserId.AddRange(sdqlist.Select(x => x.CreateBy)); } if (xdqlist.Any()) { jObjectiveIds += "," + string.Join(",", xdqlist.Select(x => x.Id)); DQUserId.AddRange(xdqlist.Select(x => x.CreateBy)); } //查询结果列表 var krList = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveIds = jObjectiveIds }); foreach (var item in sdqlist) { //结果列表 item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); if (item.IsDefaultState == 1 && item.KeyResultList.Any()) { item.ProgressState = item.KeyResultList.Max(x => x.ProgressState); } } foreach (var item in xdqlist) { //结果列表 item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); if (item.IsDefaultState == 1 && item.KeyResultList.Any()) { item.ProgressState = item.KeyResultList.Max(x => x.ProgressState); } } foreach (var item in list) { //结果列表 item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); if (item.IsDefaultState == 1 && item.KeyResultList.Any()) { item.ProgressState = item.KeyResultList.Max(x => x.ProgressState); } #region 对齐列表 item.ParentSingleList = sdqlist.Where(x => x.ObjectiveId == item.Id).ToList(); item.ChildSingleList = xdqlist.Where(x => x.ParentId == item.Id).ToList(); #endregion } } return list.Select(x => new { x.Id, x.Title, x.Sort, x.Progress, x.ProgressState, ProgressStateName = x.ProgressState.ToName(), x.Status, UserId = x.CreateBy, x.EmName, x.EmPhoto, ParentList = x.ParentSingleList.Select(y => new { y.Id, y.Title, y.Sort, y.Progress, y.ProgressState, IsLock = 2, IsNotLook = 2, ProgressStateName = y.ProgressState.ToName(), y.ParentNum, UserId = y.CreateBy, y.EmName, y.EmPhoto }), ChildList = x.ChildSingleList.Select(y => new { y.Id, y.Title, y.Sort, y.Progress, y.ProgressState, IsLock = 2, IsNotLook = 2, ProgressStateName = y.ProgressState.ToName(), y.ChildNum, UserId = y.CreateBy, y.EmName, y.EmPhoto }), }); } /// /// 获取我的对齐视图 再下一级 /// /// /// /// /// /// public object GetOKRAdminAlignViewNext(int PeriodId, int objectiveId, int type, UserInfo userInfo) { if (type == 1) { //查询向上对齐 var sdqlist = oKR_ObjectiveRepository.GetParentList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, ObjectiveIds = objectiveId.ToString() }); if (sdqlist.Any()) { //查询上对齐数量 var rlist = oKR_ObjectiveRelationRepository.GetParentAlignNum(string.Join(",", sdqlist.Select(x => x.Id))); foreach (var item in sdqlist) { item.ParentNum = rlist.Where(x => x.ObjectiveId == item.Id).FirstOrDefault()?.ParentId ?? 0; } } else { return new List(); } string jObjectiveIds = string.Join(",", sdqlist.Select(x => x.Id)); //查询结果列表 var krList = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveIds = jObjectiveIds }); foreach (var item in sdqlist) { //结果列表 item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); if (item.IsDefaultState == 1 && item.KeyResultList.Any()) { item.ProgressState = item.KeyResultList.Max(x => x.ProgressState); } } return sdqlist.Select(y => new { y.Id, y.Title, y.Sort, y.Progress, y.ProgressState, IsLock = 2, IsNotLook = 2, ProgressStateName = y.ProgressState.ToName(), y.ParentNum, UserId = y.CreateBy, y.EmName, y.EmPhoto }); } else { //查询向下对齐 var xdqlist = oKR_ObjectiveRepository.GetParentList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, ParentIds = objectiveId.ToString() }); if (xdqlist.Any()) { //查询下对齐数量 var rlist = oKR_ObjectiveRelationRepository.GetChildAlignNum(string.Join(",", xdqlist.Select(x => x.Id))); foreach (var item in xdqlist) { item.ChildNum = rlist.Where(x => x.ParentId == item.Id).FirstOrDefault()?.ObjectiveId ?? 0; } } else { return new List(); } string jObjectiveIds = string.Join(",", xdqlist.Select(x => x.Id)); //查询结果列表 var krList = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveIds = jObjectiveIds }); foreach (var item in xdqlist) { //结果列表 item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); if (item.IsDefaultState == 1 && item.KeyResultList.Any()) { item.ProgressState = item.KeyResultList.Max(x => x.ProgressState); } } return xdqlist.Select(y => new { y.Id, y.Title, y.Sort, y.Progress, y.ProgressState, IsLock = 2, IsNotLook = 2, ProgressStateName = y.ProgressState.ToName(), y.ChildNum, UserId = y.CreateBy, y.EmName, y.EmPhoto }); } } /// /// 获取管理员查看单个目标 /// /// /// /// public object GetOKRAdminLookObjectiveInfo(int objectiveId, UserInfo userInfo) { var list = oKR_ObjectiveRepository.GetList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, Id = objectiveId }); if (list.Any()) { var mdoel = list.FirstOrDefault(); string objectiveIds = string.Join(",", list.Select(x => x.Id)); //查询向上对齐 var sdqlist = oKR_ObjectiveRepository.GetParentList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = mdoel.PeriodId, ObjectiveIds = objectiveIds }); //查询向下对齐 var xdqlist = oKR_ObjectiveRepository.GetParentList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = mdoel.PeriodId, ParentIds = objectiveIds }); string jObjectiveIds = objectiveIds; if (sdqlist.Any()) { jObjectiveIds += "," + string.Join(",", sdqlist.Select(x => x.Id)); } if (xdqlist.Any()) { jObjectiveIds += "," + string.Join(",", xdqlist.Select(x => x.Id)); } //查询结果列表 var krList = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveIds = jObjectiveIds }); string scoreRuleIds = string.Join(",", list.Where(x => x.ScoreRuleId > 0).Select(x => x.ScoreRuleId)); var ScoreRuleList = new List(); if (!string.IsNullOrEmpty(scoreRuleIds)) { ScoreRuleList = oKR_ScoreDetailRepository.GetList(new RB_OKR_ScoreDetail_ViewModel() { ScoreIds = scoreRuleIds }); } foreach (var item in sdqlist) { item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); } foreach (var item in xdqlist) { item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); } foreach (var item in list) { //结果列表 item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); if (item.IsDefaultState == 1 && item.KeyResultList.Any()) { item.ProgressState = item.KeyResultList.Max(x => x.ProgressState); } #region 对齐列表 var sdqclist = sdqlist.Where(x => x.ObjectiveId == item.Id).ToList(); List EmIdList = sdqclist.Select(x => x.CreateBy).Distinct().ToList(); item.ParentList = new List(); foreach (var qitem in EmIdList) { item.ParentList.Add(new ObjectiveEmployeeModel() { AccountId = qitem, AccountName = sdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmName, Icon = sdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmPhoto, AlignList = sdqclist.Where(x => x.CreateBy == qitem).ToList() }); } var xdqclist = xdqlist.Where(x => x.ParentId == item.Id).ToList(); List EmIdList2 = xdqclist.Select(x => x.CreateBy).Distinct().ToList(); item.ChildList = new List(); foreach (var qitem in EmIdList2) { item.ChildList.Add(new ObjectiveEmployeeModel() { AccountId = qitem, AccountName = xdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmName, Icon = xdqclist.Where(x => x.CreateBy == qitem).FirstOrDefault().EmPhoto, AlignList = xdqclist.Where(x => x.CreateBy == qitem).ToList() }); } #endregion #region 分数显示 item.ScoreName = ""; item.ScoreColor = ""; if (item.ScoreRuleId > 0) { var scoreRuleModel = ScoreRuleList.Where(x => x.ScoreId == item.ScoreRuleId && x.ScoreMin <= item.Score && x.ScoreMax >= item.Score).FirstOrDefault(); item.ScoreName = scoreRuleModel?.Name ?? ""; item.ScoreColor = scoreRuleModel?.Color ?? ""; foreach (var qitem in item.KeyResultList) { var qscoreRuleModel = ScoreRuleList.Where(x => x.ScoreId == item.ScoreRuleId && x.ScoreMin <= qitem.Score && x.ScoreMax >= qitem.Score).FirstOrDefault(); qitem.ScoreName = qscoreRuleModel?.Name ?? ""; qitem.ScoreColor = qscoreRuleModel?.Color ?? ""; } } #endregion } } var x = list.FirstOrDefault(); if (x == null) { return null; } return new { x.Id, x.Title, x.Sort, x.Progress, x.Weight, x.Score, x.ProgressRemark, x.IsDefaultState, x.ProgressState, ProgressStateName = x.ProgressState.ToName(), x.Status, IsLock = 2, IsNotLook = 2, x.ScoreName, x.ScoreColor, KeyResultList = x.KeyResultList.Select(z => new { z.Id, z.Name, z.Sort, z.Progress, z.Weight, z.Score, z.ProgressState, ProgressStateName = z.ProgressState.ToName(), z.StartValue, z.EndValue, z.CurrentValue, z.IsEasyMode, IsLock = 2, IsNotLook = 2, z.ScoreName, z.ScoreColor }), ParentList = x.ParentList.Select(y => new { y.AccountId, y.AccountName, y.Icon, AlignList = y.AlignList.Select(q => new { q.Id, q.Title, q.Sort, IsLock = 2, IsNotLook = 2, KeyResultList = x.KeyResultList.Select(z => new { z.Id, z.Name, z.Sort, IsLock = 2, IsNotLook = 2, }), }) }), ChildList = x.ChildList.Select(y => new { y.AccountId, y.AccountName, y.Icon, AlignList = y.AlignList.Select(q => new { q.Id, q.Title, q.Sort, IsLock = 2, IsNotLook = 2, KeyResultList = x.KeyResultList.Select(z => new { z.Id, z.Name, z.Sort, IsLock = 2, IsNotLook = 2, }), }) }), }; } #endregion #region okr 任务评论 /// /// 获取评论分页列表 /// /// /// /// /// /// public List GetCommentPageList(int pageIndex, int pageSize, out long rowsCount, RB_OKR_Comment_ViewModel demodel) { return oKR_CommentRepository.GetPageList(pageIndex, pageSize, out rowsCount, demodel); } /// /// 获取评论列表 /// /// /// public List GetCommentList(RB_OKR_Comment_ViewModel demodel) { return oKR_CommentRepository.GetList(demodel); } /// /// 新增/修改ork评论 /// /// /// public bool SetOKRComment(RB_OKR_Comment_ViewModel model) { if (model.Id == 0) { return oKR_CommentRepository.Insert(model) > 0; } else { Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_Comment_ViewModel.Content),model.Content}, { nameof(RB_OKR_Comment_ViewModel.UpdateBy),model.UpdateBy}, { nameof(RB_OKR_Comment_ViewModel.UpdateTime),DateTime.Now}, }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Comment_ViewModel.Id), FiledValue=model.Id, OperatorEnum=OperatorEnum.Equal } }; return oKR_CommentRepository.Update(keyValues, wheres); } } /// /// 设置评论状态 /// /// /// public bool SetCommentStatus(RB_OKR_Comment_ViewModel model) { var omodel = oKR_CommentRepository.GetEntity(model.Id); Dictionary keyValues = new Dictionary() { { nameof(RB_OKR_Comment_ViewModel.State),model.State}, { nameof(RB_OKR_Comment_ViewModel.UpdateBy),model.UpdateBy}, { nameof(RB_OKR_Comment_ViewModel.UpdateTime),DateTime.Now}, }; List wheres = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Comment_ViewModel.Id), FiledValue=model.Id, OperatorEnum=OperatorEnum.Equal } }; bool flag = oKR_CommentRepository.Update(keyValues, wheres); if (flag) { if (omodel.ParentId > 0 && model.State == 3) { //查询该父级下是否还有未删除的评论 没有的话删除该父级评论 var list = oKR_CommentRepository.GetList(new RB_OKR_Comment_ViewModel() { Group_Id = omodel.Group_Id, ParentId = omodel.ParentId }); if (!list.Any()) { Dictionary keyValues1 = new Dictionary() { { nameof(RB_OKR_Comment_ViewModel.State),3}, { nameof(RB_OKR_Comment_ViewModel.UpdateBy),model.UpdateBy}, { nameof(RB_OKR_Comment_ViewModel.UpdateTime),DateTime.Now}, }; List wheres1 = new List() { new WhereHelper(){ FiledName=nameof(RB_OKR_Comment_ViewModel.Id), FiledValue=omodel.ParentId, OperatorEnum=OperatorEnum.Equal } }; oKR_CommentRepository.Update(keyValues1, wheres1); } } } return flag; } /// /// 设置目标/结果选择评论 /// /// /// public bool SetOKRCheckedComment(RB_OKR_Comment_ViewModel extModel, out int CommentId) { //先新增主标题 int Id = oKR_CommentRepository.Insert(new Model.Entity.OKR.RB_OKR_Comment() { Id = extModel.Id, Type = extModel.Type, AccountId = extModel.AccountId, Content = extModel.CheckedName, CreateBy = extModel.CreateBy, CreateTime = extModel.CreateTime, Group_Id = extModel.Group_Id, Identify = extModel.Identify, ParentId = 0, PeriodId = extModel.PeriodId, School_Id = extModel.School_Id, State = 1, TargetId = extModel.TargetId, UpdateBy = extModel.UpdateBy, UpdateTime = extModel.UpdateTime }); //增加子评论 if (Id > 0) { oKR_CommentRepository.Insert(new Model.Entity.OKR.RB_OKR_Comment() { Id = extModel.Id, Type = extModel.Type, AccountId = extModel.AccountId, Content = extModel.Content, CreateBy = extModel.CreateBy, CreateTime = extModel.CreateTime, Group_Id = extModel.Group_Id, Identify = "", ParentId = Id, PeriodId = extModel.PeriodId, School_Id = extModel.School_Id, State = 1, TargetId = 0, UpdateBy = extModel.UpdateBy, UpdateTime = extModel.UpdateTime }); } CommentId = Id; return Id > 0; } /// /// 获取评论分页列表 /// /// /// /// /// /// public List GetCommentPageList_V2(int pageIndex, int pageSize, out long rowsCount, RB_OKR_Comment_ViewModel query) { var list = oKR_CommentRepository.GetCommentPageList_V2(pageIndex, pageSize, out rowsCount, query); if (list.Any()) { //非周期评论的 都需要查询下级评论 string cids = string.Join(",", list.Where(x => x.Type != 4).Select(x => x.Id)); List ChildList = new List(); if (!string.IsNullOrEmpty(cids)) { ChildList = oKR_CommentRepository.GetList_V2(new RB_OKR_Comment_ViewModel() { Group_Id = query.Group_Id, ParentIds = cids }); } foreach (var item in list) { item.ChildList = new List(); if (item.Type == 4) { //组装成新数据 item.ChildList.Add(new RB_OKR_Comment_ViewModel() { Id = item.Id, Type = item.Type, Content = item.Content, CreateByName = item.CreateByName, CreateByIco = item.CreateByIco, CreateTime = item.CreateTime }); item.Content = "评论"; } else { item.ChildList = ChildList.Where(x => x.ParentId == item.Id).ToList(); } } } return list; } #endregion #region 数据分布 /// /// 获取个人数据分布 /// /// /// /// public object GetOKRGRDateDistribution(int periodId, int rangeType, string departId, int postId, int leaveStatus, UserInfo userInfo, bool IsAdmin = false) { var userIdList = new List(); if (IsAdmin == false) { if (rangeType == 1) { //查询该用户下所有的下级用户 userIdList = GetMyAllDownlineUserIdList(userInfo, 0, postId, leaveStatus); } else { //首先查询用户的所有直属下级 userIdList = GetMyUnderlingUserIdList(userInfo, 0, postId, leaveStatus); } } else { var accountList = accountRepository.GetAccountListExtRepository(new Model.ViewModel.User.RB_Account_ViewModel() { Group_Id = userInfo.Group_Id, DeptIds = departId, Post_Id = postId, LeaveStatus = leaveStatus, IsSelectLevelNor = 1 }); userIdList = accountList.Select(x => x.Id).ToList(); } //直接查询所有的objective var olist = oKR_ObjectiveRepository.GetList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = periodId, CreateByIds = string.Join(",", userIdList), Status = 2 }); //查询出每个人的objective的数量 var objectiveNumList = new List(); foreach (var item in userIdList) { objectiveNumList.Add(new RB_OKR_Objective_ViewModel() { CreateBy = item, ObjectiveNum = olist.Where(x => x.CreateBy == item).Count() }); } List ObjectiveNum = new List(); List Group = new List() { 0, 1, 3, 6, 9 }; for (var i = 0; i < Group.Count(); i++) { int ONum = 0; if (i == Group.Count() - 1) { int StartV = Group[i]; int EndV = -1; ONum = objectiveNumList.Where(x => x.ObjectiveNum >= StartV).Count(); ObjectiveNum.Add(new { Start = StartV, End = EndV, Number = ONum }); } else { int StartV = Group[i]; int EndV = Group[i + 1] - 1; if (StartV == 0) { ONum = objectiveNumList.Where(x => x.ObjectiveNum == 0).Count(); } else { ONum = objectiveNumList.Where(x => x.ObjectiveNum >= StartV && x.ObjectiveNum <= EndV).Count(); } ObjectiveNum.Add(new { Start = StartV, End = EndV, Number = ONum }); } } //查询目标状态 List ObjectiveState = new List { new { ProgressState = 0, Name = "未更新", Number = olist.Where(x => x.IsUpdated != 1).Count() } }; var ProgressStateList = EnumHelper.EnumToList(typeof(Common.Enum.OKR.ProgressStateEnum)); foreach (var item in ProgressStateList) { ObjectiveState.Add(new { ProgressState = item.Id, item.Name, Number = olist.Where(x => x.IsUpdated == 1 && x.ProgressState == (Common.Enum.OKR.ProgressStateEnum)item.Id).Count() }); } //查询目标进度 List ObjectiveProgress = new List(); List Progress = new List() { 0, 1, 31, 61, 91 }; for (var i = 0; i < Progress.Count(); i++) { int ONum = 0; if (i == Progress.Count() - 1) { int StartV = Progress[i]; int EndV = -1; ONum = olist.Where(x => x.Progress >= StartV).Count(); ObjectiveProgress.Add(new { Start = StartV > 0 ? (StartV - 1) : StartV, End = EndV, Number = ONum }); } else { int StartV = Progress[i]; int EndV = Progress[i + 1] - 1; if (StartV == 0) { ONum = olist.Where(x => x.Progress == 0).Count(); } else { ONum = olist.Where(x => x.Progress >= StartV && x.Progress <= EndV).Count(); } ObjectiveProgress.Add(new { Start = StartV > 0 ? (StartV - 1) : StartV, End = EndV, Number = ONum }); } } //查询目标分数 List ObjectiveScore = new List(); List Score = new List() { 0, 0.01, 0.31, 0.61, 0.91 }; for (var i = 0; i < Score.Count(); i++) { int ONum = 0; if (i == Score.Count() - 1) { decimal StartV = Convert.ToDecimal(Score[i]); int EndV = -1; ONum = olist.Where(x => x.Score >= StartV).Count(); double StartV1 = Convert.ToDouble(StartV > 0 ? (StartV - Convert.ToDecimal(0.01)) : StartV); ObjectiveScore.Add(new { Start = StartV1, End = EndV, Number = ONum }); } else { decimal StartV = Convert.ToDecimal(Score[i]); decimal EndV = Convert.ToDecimal(Score[i + 1] - 0.01); if (StartV == 0) { ONum = olist.Where(x => x.Score == 0).Count(); } else { ONum = olist.Where(x => x.Score >= StartV && x.Score <= EndV).Count(); } double StartV1 = Convert.ToDouble(StartV > 0 ? (StartV - Convert.ToDecimal(0.01)) : StartV); ObjectiveScore.Add(new { Start = StartV1, End = EndV, Number = ONum }); } } return new { ObjectiveNum, ObjectiveState, ObjectiveProgress, ObjectiveScore }; } /// /// 获取个人数据分布明细 /// /// /// /// /// /// /// /// /// /// /// /// public List GetOKRGRDateDistributionDetail(int pageIndex, int pageSize, out long count, int periodId, int type, int startValue, int endValue, int orderBy, int rangeType, int departId, int postId, int leaveStatus, UserInfo userInfo, bool IsAdmin = false) { count = 0; var userIdList = new List(); if (IsAdmin == false) { if (rangeType == 1) { //查询该用户下所有的下级用户 userIdList = GetMyAllDownlineUserIdList(userInfo, departId, postId, leaveStatus); } else { //首先查询用户的所有直属下级 userIdList = GetMyUnderlingUserIdList(userInfo, departId, postId, leaveStatus); } } else { var accountList = accountRepository.GetAccountListExtRepository(new Model.ViewModel.User.RB_Account_ViewModel() { Group_Id = userInfo.Group_Id, Dept_Id = departId, IsSelectLevelNor = 1 }); userIdList = accountList.Select(x => x.Id).ToList(); } string userIds = string.Join(",", userIdList.Distinct()); List RList = new List(); switch (type) { case 1: //数量 RList = oKR_ObjectiveRepository.GetObjectiveNumPageList(pageIndex, pageSize, out count, periodId, startValue, endValue, orderBy, userIds, userInfo.Group_Id); break; case 2: //状态 RList = oKR_ObjectiveRepository.GetObjectiveStatePageList(pageIndex, pageSize, out count, periodId, startValue, orderBy, userIds, userInfo.Group_Id); break; case 3: //进度 RList = oKR_ObjectiveRepository.GetObjectiveProgressPageList(pageIndex, pageSize, out count, periodId, startValue, endValue, orderBy, userIds, userInfo.Group_Id); break; case 4: //打分 RList = oKR_ObjectiveRepository.GetObjectiveScorePageList(pageIndex, pageSize, out count, periodId, startValue, endValue, orderBy, userIds, userInfo.Group_Id); break; } return RList; } /// /// 获取个人数据分布明细 - 员工 /// /// /// /// /// /// /// /// /// /// /// /// public object GetOKRGRDateDistributionDetail_V2(int pageIndex, int pageSize, out long count, int periodId, string userName, int type, int orderBy, int orderByNum, int rangeType, string departId, int postId, int leaveStatus, UserInfo userInfo, bool IsAdmin = false) { count = 0; var userIdList = new List(); if (IsAdmin == false) { if (rangeType == 1) { //查询该用户下所有的下级用户 userIdList = GetMyAllDownlineUserIdList(userInfo, 0, postId, leaveStatus, userName); } else { //首先查询用户的所有直属下级 userIdList = GetMyUnderlingUserIdList(userInfo, 0, postId, leaveStatus, userName); } } else { var accountList = accountRepository.GetAccountListExtRepository(new Model.ViewModel.User.RB_Account_ViewModel() { Group_Id = userInfo.Group_Id, AccountName = userName, DeptIds = departId, Post_Id = postId, LeaveStatus = leaveStatus, IsSelectLevelNor = 1 }); userIdList = accountList.Select(x => x.Id).ToList(); } string userIds = string.Join(",", userIdList.Distinct()); List RList = new List(); switch (type) { case 1: //数量 RList = oKR_ObjectiveRepository.GetObjectiveNumPageList(pageIndex, pageSize, out count, periodId, 0, 0, orderBy, userIds, userInfo.Group_Id); return RList.Select(x => new { x.CreateBy, x.EmName, x.EmPhoto, x.DeptName, x.PostName, ObjectiveNumList = new List() { x.ObjectiveNum } }); case 2: //状态 RList = oKR_ObjectiveRepository.GetObjectiveStatePageList_V2(pageIndex, pageSize, out count, periodId, orderBy, orderByNum, userIds, userInfo.Group_Id); return RList.Select(x => new { x.CreateBy, x.EmName, x.EmPhoto, x.DeptName, x.PostName, ObjectiveNumList = new List() { x.ObjectiveNum1, x.ObjectiveNum2, x.ObjectiveNum3, x.ObjectiveNum4 } }); case 3: //进度 RList = oKR_ObjectiveRepository.GetObjectiveProgressPageList_V2(pageIndex, pageSize, out count, periodId, orderBy, orderByNum, userIds, userInfo.Group_Id); return RList.Select(x => new { x.CreateBy, x.EmName, x.EmPhoto, x.DeptName, x.PostName, ObjectiveNumList = new List() { x.ObjectiveNum1, x.ObjectiveNum2, x.ObjectiveNum3, x.ObjectiveNum4, x.ObjectiveNum5 } }); case 4: //打分 RList = oKR_ObjectiveRepository.GetObjectiveScorePageList_V2(pageIndex, pageSize, out count, periodId, orderBy, orderByNum, userIds, userInfo.Group_Id); return RList.Select(x => new { x.CreateBy, x.EmName, x.EmPhoto, x.DeptName, x.PostName, ObjectiveNumList = new List() { x.ObjectiveNum1, x.ObjectiveNum2, x.ObjectiveNum3, x.ObjectiveNum4, x.ObjectiveNum5 } }); } return RList; } /// /// 获取个人数据分布明细 - 部门统计 /// /// /// /// /// /// /// /// /// /// /// /// /// public object GetOKRGRDateDistributionForDepartment(int periodId, int type, int orderBy, int orderByNum, string departId, int postId, int leaveStatus, UserInfo userInfo, bool IsAdmin) { List Rlist = new List(); if (IsAdmin == false) { var xjdlist = departmentRepository.GetDepartmentListRepository(new RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, ManagerIds = userInfo.Id.ToString() }); if (xjdlist.Any()) { List DeptIdList = new List(); foreach (var item in xjdlist) { //查询出所有的部门 string DeptIds = departmentRepository.GetCurrentAndChildDepartmentIdsRepository(item.DeptId); if (!string.IsNullOrEmpty(DeptIds)) { DeptIdList.AddRange(JsonHelper.DeserializeObject>("[" + DeptIds + "]")); } } string DeptIdStr = string.Join(",", DeptIdList.Distinct()); //上级部门下所有子部门的负责人 var d2list = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, QDeptIds = DeptIdStr }); string ManagerIds = string.Join(",", d2list.Where(x => !string.IsNullOrEmpty(x.ManagerIds)).Select(x => x.ManagerIds)); List ManagerList = new List(); if (!string.IsNullOrEmpty(ManagerIds)) { ManagerList = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, QIds = ManagerIds, Post_Id = postId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); } List RList = new List(); switch (type) { case 1: //数量 RList = oKR_ObjectiveRepository.GetObjectiveNumListForDept(periodId, DeptIdStr, userInfo.Group_Id); break; case 2: //状态 RList = oKR_ObjectiveRepository.GetObjectiveStateListForDept(periodId, DeptIdStr, userInfo.Group_Id); break; case 3: //进度 RList = oKR_ObjectiveRepository.GetObjectiveProgressListForDept(periodId, DeptIdStr, userInfo.Group_Id); break; case 4: //打分 RList = oKR_ObjectiveRepository.GetObjectiveScoreListForDept(periodId, DeptIdStr, userInfo.Group_Id); break; } //返回部门树形结构 foreach (var item in xjdlist) { List ManagerList1 = new List(); if (!string.IsNullOrEmpty(item.ManagerIds)) { List ManagerIdList = JsonHelper.DeserializeObject>("[" + item.ManagerIds + "]"); ManagerList1 = ManagerList.Where(x => ManagerIdList.Contains(x.Id)).ToList(); } var rmodel = RList.Where(x => x.RB_Department_Id == item.DeptId).FirstOrDefault() ?? new RB_OKR_Objective_ViewModel(); int Number = type == 1 ? rmodel.ObjectiveNum : (rmodel.ObjectiveNum1 + rmodel.ObjectiveNum2 + rmodel.ObjectiveNum3 + rmodel.ObjectiveNum4 + rmodel.ObjectiveNum5); List ObjectiveNumList = new List { rmodel.ObjectiveNum1, rmodel.ObjectiveNum2, rmodel.ObjectiveNum3, rmodel.ObjectiveNum4 }; if (type == 3 || type == 4) { ObjectiveNumList.Add(rmodel.ObjectiveNum5); } Rlist.Add(new { item.DeptId, item.DeptName, ManagerList = ManagerList1.Select(x => new { x.Id, x.EmployeeName, x.UserIcon }), Number, ObjectiveNumList, ChildList = GetChildDepartmentForDateDistribution(item, d2list, ManagerList, RList, type, orderBy, orderByNum) }); } } else { //只查询自己部门 var dlist = departmentRepository.GetDepartmentListRepository(new RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, DeptId = userInfo.DeptId }); string DeptIdStr = userInfo.DeptId.ToString(); string ManagerIds = string.Join(",", dlist.Where(x => !string.IsNullOrEmpty(x.ManagerIds)).Select(x => x.ManagerIds)); List ManagerList = new List(); if (!string.IsNullOrEmpty(ManagerIds)) { ManagerList = accountRepository.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, QIds = ManagerIds, Post_Id = postId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); } List RList = new List(); switch (type) { case 1: //数量 RList = oKR_ObjectiveRepository.GetObjectiveNumListForDept(periodId, DeptIdStr, userInfo.Group_Id); break; case 2: //状态 RList = oKR_ObjectiveRepository.GetObjectiveStateListForDept(periodId, DeptIdStr, userInfo.Group_Id); break; case 3: //进度 RList = oKR_ObjectiveRepository.GetObjectiveProgressListForDept(periodId, DeptIdStr, userInfo.Group_Id); break; case 4: //打分 RList = oKR_ObjectiveRepository.GetObjectiveScoreListForDept(periodId, DeptIdStr, userInfo.Group_Id); break; } //返回部门树形结构 foreach (var item in dlist) { List ManagerList1 = new List(); if (!string.IsNullOrEmpty(item.ManagerIds)) { List ManagerIdList = JsonHelper.DeserializeObject>("[" + item.ManagerIds + "]"); ManagerList1 = ManagerList.Where(x => ManagerIdList.Contains(x.Id)).ToList(); } var rmodel = RList.Where(x => x.RB_Department_Id == item.DeptId).FirstOrDefault() ?? new RB_OKR_Objective_ViewModel(); int Number = type == 1 ? rmodel.ObjectiveNum : (rmodel.ObjectiveNum1 + rmodel.ObjectiveNum2 + rmodel.ObjectiveNum3 + rmodel.ObjectiveNum4 + rmodel.ObjectiveNum5); List ObjectiveNumList = new List { rmodel.ObjectiveNum1, rmodel.ObjectiveNum2, rmodel.ObjectiveNum3, rmodel.ObjectiveNum4 }; if (type == 3 || type == 4) { ObjectiveNumList.Add(rmodel.ObjectiveNum5); } Rlist.Add(new { item.DeptId, item.DeptName, ManagerList = ManagerList1.Select(x => new { x.Id, x.EmployeeName, x.UserIcon }), Number, ObjectiveNumList, ChildList = GetChildDepartmentForDateDistribution(item, dlist, ManagerList, RList, type, orderBy, orderByNum) }); } } } else { if (!string.IsNullOrEmpty(departId)) { var dlist = departmentRepository.GetDepartmentListRepository(new RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, QDeptIds = departId }); string DeptIdStr = departId.ToString(); string ManagerIds = string.Join(",", dlist.Where(x => !string.IsNullOrEmpty(x.ManagerIds)).Select(x => x.ManagerIds)); List ManagerList = new List(); if (!string.IsNullOrEmpty(ManagerIds)) { ManagerList = accountRepository.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, QIds = ManagerIds, Post_Id = postId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); } List RList = new List(); switch (type) { case 1: //数量 RList = oKR_ObjectiveRepository.GetObjectiveNumListForDept(periodId, DeptIdStr, userInfo.Group_Id); break; case 2: //状态 RList = oKR_ObjectiveRepository.GetObjectiveStateListForDept(periodId, DeptIdStr, userInfo.Group_Id); break; case 3: //进度 RList = oKR_ObjectiveRepository.GetObjectiveProgressListForDept(periodId, DeptIdStr, userInfo.Group_Id); break; case 4: //打分 RList = oKR_ObjectiveRepository.GetObjectiveScoreListForDept(periodId, DeptIdStr, userInfo.Group_Id); break; } //返回部门树形结构 foreach (var item in dlist) { List ManagerList1 = new List(); if (!string.IsNullOrEmpty(item.ManagerIds)) { List ManagerIdList = JsonHelper.DeserializeObject>("[" + item.ManagerIds + "]"); ManagerList1 = ManagerList.Where(x => ManagerIdList.Contains(x.Id)).ToList(); } var rmodel = RList.Where(x => x.RB_Department_Id == item.DeptId).FirstOrDefault() ?? new RB_OKR_Objective_ViewModel(); int Number = type == 1 ? rmodel.ObjectiveNum : (rmodel.ObjectiveNum1 + rmodel.ObjectiveNum2 + rmodel.ObjectiveNum3 + rmodel.ObjectiveNum4 + rmodel.ObjectiveNum5); List ObjectiveNumList = new List { rmodel.ObjectiveNum1, rmodel.ObjectiveNum2, rmodel.ObjectiveNum3, rmodel.ObjectiveNum4 }; if (type == 3 || type == 4) { ObjectiveNumList.Add(rmodel.ObjectiveNum5); } Rlist.Add(new { item.DeptId, item.DeptName, ManagerList = ManagerList1.Select(x => new { x.Id, x.EmployeeName, x.UserIcon }), Number, ObjectiveNumList, ChildList = GetChildDepartmentForDateDistribution(item, dlist, ManagerList, RList, type, orderBy, orderByNum) }); } } else { //直接查询所有部门 var dlist = departmentRepository.GetDepartmentListRepository(new RB_Department_ViewModel() { Group_Id = userInfo.Group_Id }); if (dlist.Any()) { string DeptIdStr = string.Join(",", dlist.Select(x => x.DeptId)); //上级部门下所有子部门的负责人 string ManagerIds = string.Join(",", dlist.Where(x => !string.IsNullOrEmpty(x.ManagerIds)).Select(x => x.ManagerIds)); List ManagerList = new List(); if (!string.IsNullOrEmpty(ManagerIds)) { ManagerList = accountRepository.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, QIds = ManagerIds, Post_Id = postId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); } List RList = new List(); switch (type) { case 1: //数量 RList = oKR_ObjectiveRepository.GetObjectiveNumListForDept(periodId, DeptIdStr, userInfo.Group_Id); break; case 2: //状态 RList = oKR_ObjectiveRepository.GetObjectiveStateListForDept(periodId, DeptIdStr, userInfo.Group_Id); break; case 3: //进度 RList = oKR_ObjectiveRepository.GetObjectiveProgressListForDept(periodId, DeptIdStr, userInfo.Group_Id); break; case 4: //打分 RList = oKR_ObjectiveRepository.GetObjectiveScoreListForDept(periodId, DeptIdStr, userInfo.Group_Id); break; } //返回部门树形结构 var firstList = dlist.Where(x => x.ParentId == 0).ToList(); foreach (var item in firstList) { List ManagerList1 = new List(); if (!string.IsNullOrEmpty(item.ManagerIds)) { List ManagerIdList = JsonHelper.DeserializeObject>("[" + item.ManagerIds + "]"); ManagerList1 = ManagerList.Where(x => ManagerIdList.Contains(x.Id)).ToList(); } var rmodel = RList.Where(x => x.RB_Department_Id == item.DeptId).FirstOrDefault() ?? new RB_OKR_Objective_ViewModel(); int Number = type == 1 ? rmodel.ObjectiveNum : (rmodel.ObjectiveNum1 + rmodel.ObjectiveNum2 + rmodel.ObjectiveNum3 + rmodel.ObjectiveNum4 + rmodel.ObjectiveNum5); List ObjectiveNumList = new List { rmodel.ObjectiveNum1, rmodel.ObjectiveNum2, rmodel.ObjectiveNum3, rmodel.ObjectiveNum4 }; if (type == 3 || type == 4) { ObjectiveNumList.Add(rmodel.ObjectiveNum5); } Rlist.Add(new { item.DeptId, item.DeptName, ManagerList = ManagerList1.Select(x => new { x.Id, x.EmployeeName, x.UserIcon }), Number, ObjectiveNumList, ChildList = GetChildDepartmentForDateDistribution(item, dlist, ManagerList, RList, type, orderBy, orderByNum) }); } } } } return Rlist; } /// /// 获取部门子集 /// /// /// /// /// /// /// /// /// private object GetChildDepartmentForDateDistribution(RB_Department_ViewModel model, List d2list, List ManagerList, List RList, int type, int orderBy, int orderByNum) { List Rlist = new List(); var clist = d2list.Where(x => x.ParentId == model.DeptId).ToList(); foreach (var item in clist) { List ManagerList1 = new List(); if (!string.IsNullOrEmpty(item.ManagerIds)) { List ManagerIdList = JsonHelper.DeserializeObject>("[" + item.ManagerIds + "]"); ManagerList1 = ManagerList.Where(x => ManagerIdList.Contains(x.Id)).ToList(); } var rmodel = RList.Where(x => x.RB_Department_Id == item.DeptId).FirstOrDefault() ?? new RB_OKR_Objective_ViewModel(); int Number = type == 1 ? rmodel.ObjectiveNum : (rmodel.ObjectiveNum1 + rmodel.ObjectiveNum2 + rmodel.ObjectiveNum3 + rmodel.ObjectiveNum4 + rmodel.ObjectiveNum5); List ObjectiveNumList = new List { rmodel.ObjectiveNum1, rmodel.ObjectiveNum2, rmodel.ObjectiveNum3, rmodel.ObjectiveNum4 }; if (type == 3 || type == 4) { ObjectiveNumList.Add(rmodel.ObjectiveNum5); } Rlist.Add(new { item.DeptId, item.DeptName, ManagerList = ManagerList1.Select(x => new { x.Id, x.EmployeeName, x.UserIcon }), Number, ObjectiveNumList, ChildList = GetChildDepartmentForDateDistribution(item, d2list, ManagerList, RList, type, orderBy, orderByNum) }); } return Rlist; } /// /// 获取关注事项统计 /// /// /// /// /// /// /// /// public object GetOKRMatterList(int periodId, string departId, int postId, int leaveStatus, UserInfo userInfo, bool IsAdmin) { List RList = new List(); var pmodel = oKR_PeriodRepository.GetEntity(periodId); if (pmodel == null) { return RList; } int SDays = 0, EDays = 0; if (DateTime.Now > pmodel.StartDate) { SDays = (DateTime.Now - pmodel.StartDate).Days; } if (DateTime.Now < pmodel.EndDate) { EDays = (pmodel.EndDate - DateTime.Now).Days; } int Num = 1; var list = oKR_MatterRepository.GetList(new Model.Entity.OKR.RB_OKR_Matter() { Group_Id = userInfo.Group_Id, PeriodId = periodId, UserId = userInfo.Id }); if (IsAdmin == false) { var userIdList = GetMyUnderlingUserIdList(userInfo, 0, postId, leaveStatus); if (userIdList.Any()) { userIdList = userIdList.Distinct().ToList(); int TotalNum = userIdList.Count(); string userIds = string.Join(",", userIdList); string OKRMatterValue = Common.Config.OKRMatterValue; int SValue = 0, EValue = 0; if (!string.IsNullOrEmpty(OKRMatterValue)) { var matterArr = OKRMatterValue.Split(','); SValue = Convert.ToInt32(matterArr[0]); EValue = Convert.ToInt32(matterArr[1]); } if (!list.Where(x => x.Type == Common.Enum.OKR.MatterTypeEnum.NotFilled).Any() && (SValue == 0 || (SValue > 0 && SDays >= SValue))) { //查询未填写 int Number = oKR_ObjectiveRepository.GetNotFilledList(userInfo.Group_Id, periodId, userIds); if (TotalNum - Number > 0) { RList.Add(new { Id = Num, Days = SDays, TotalNum, PeopleNum = TotalNum - Number, Type = Common.Enum.OKR.MatterTypeEnum.NotFilled, TypeName = Common.Enum.OKR.MatterTypeEnum.NotFilled.ToName(), SelectType = 1, }); Num++; } } if (!list.Where(x => x.Type == Common.Enum.OKR.MatterTypeEnum.NotAlign).Any() && (SValue == 0 || (SValue > 0 && SDays >= SValue))) { //查询未对齐 int Number = oKR_ObjectiveRepository.GetAlignPeopleNum(userInfo.Group_Id, periodId, userIds); if (TotalNum - Number > 0) { RList.Add(new { Id = Num, Days = SDays, TotalNum, PeopleNum = TotalNum - Number, Type = Common.Enum.OKR.MatterTypeEnum.NotAlign, TypeName = Common.Enum.OKR.MatterTypeEnum.NotAlign.ToName(), SelectType = 2, }); Num++; } } if (!list.Where(x => x.Type == Common.Enum.OKR.MatterTypeEnum.NotUpdated).Any() && (EValue == 0 || (EValue > 0 && EDays <= EValue))) { //查询未更新 //int Number = oKR_ObjectiveRepository.GetNotUpdatedList(userInfo.Group_Id, periodId, userIds); //RList.Add(new //{ // Id = Num, // Days = EDays, // PeopleNum = Number, // Type = Common.Enum.OKR.MatterTypeEnum.NotUpdated, // TypeName = Common.Enum.OKR.MatterTypeEnum.NotUpdated.ToName(), // SelectType = 3, //}); //Num++; } if (!list.Where(x => x.Type == Common.Enum.OKR.MatterTypeEnum.NotScore).Any() && (EValue == 0 || (EValue > 0 && EDays <= EValue))) { //查询未打分 int Number = oKR_ObjectiveRepository.GetNotScoreList(userInfo.Group_Id, periodId, userIds, 2); if (TotalNum - Number > 0) { RList.Add(new { Id = Num, Days = EDays, TotalNum, PeopleNum = TotalNum - Number, Type = Common.Enum.OKR.MatterTypeEnum.NotScore, TypeName = Common.Enum.OKR.MatterTypeEnum.NotScore.ToName(), SelectType = 4, }); Num++; } } } } else { //管理端 主查询对齐率这些 int lastPeriodId = 0; if (periodId > 0) { //查询上一个周期id var model = oKR_PeriodRepository.GetEntity(periodId); if (model != null && model.IsNormal == 1) { lastPeriodId = oKR_PeriodRepository.GetLastPeriodId(model.Id, model.IsYear, userInfo.Group_Id); } } if (lastPeriodId > 0) { var accountList = accountRepository.GetAccountListExtRepository(new RB_Account_ViewModel() { Group_Id = userInfo.Group_Id, DeptIds = departId, Post_Id = postId, LeaveStatus = leaveStatus, IsSelectLevelNor = 1 }); var userIdList = accountList.Select(x => x.Id).Distinct().ToList(); if (userIdList.Any()) { int TotalPeopleNum = userIdList.Count(); string userIds = string.Join(",", userIdList); string OKRMatterValue = Common.Config.OKRMatterValue; int EValue = 0; if (!string.IsNullOrEmpty(OKRMatterValue)) { var matterArr = OKRMatterValue.Split(','); EValue = Convert.ToInt32(matterArr[2]); } if (!list.Where(x => x.Type == Common.Enum.OKR.MatterTypeEnum.Write).Any() && (EValue == 0 || (EValue > 0 && EDays <= EValue))) { //查询填写 int OKPNum = oKR_ObjectiveRepository.GetNotFilledList(userInfo.Group_Id, periodId, userIds); int LastPNum = 0; if (lastPeriodId > 0) { LastPNum = oKR_ObjectiveRepository.GetNotFilledList(userInfo.Group_Id, lastPeriodId, userIds); } #region 计算概率 decimal nowRate = 0; if (TotalPeopleNum > 0) { nowRate = Math.Round(Convert.ToDecimal(OKPNum) / TotalPeopleNum, 3, MidpointRounding.AwayFromZero) * 100; } decimal lastRate = 0; if (TotalPeopleNum > 0) { lastRate = Math.Round(Convert.ToDecimal(LastPNum) / TotalPeopleNum, 3, MidpointRounding.AwayFromZero) * 100; } //只查询同比下降的 decimal UpRate = 0; if (nowRate < lastRate) { if (nowRate == 0) { UpRate = 100; } else { UpRate = Math.Round((lastRate - nowRate) / lastRate, 3, MidpointRounding.AwayFromZero) * 100; } RList.Add(new { Id = Num, Days = EDays, TotalNum = TotalPeopleNum, PeopleNum = OKPNum, UpRate, Type = Common.Enum.OKR.MatterTypeEnum.Write, TypeName = Common.Enum.OKR.MatterTypeEnum.Write.ToName(), SelectType = 1, }); Num++; } #endregion } if (!list.Where(x => x.Type == Common.Enum.OKR.MatterTypeEnum.Align).Any() && (EValue == 0 || (EValue > 0 && EDays <= EValue))) { //查询对齐 int OKPNum = oKR_ObjectiveRepository.GetAlignPeopleNum(userInfo.Group_Id, periodId, userIds); int LastPNum = 0; if (lastPeriodId > 0) { LastPNum = oKR_ObjectiveRepository.GetAlignPeopleNum(userInfo.Group_Id, lastPeriodId, userIds); } #region 计算概率 decimal nowRate = 0; if (TotalPeopleNum > 0) { nowRate = Math.Round(Convert.ToDecimal(OKPNum) / TotalPeopleNum, 3, MidpointRounding.AwayFromZero) * 100; } decimal lastRate = 0; if (TotalPeopleNum > 0) { lastRate = Math.Round(Convert.ToDecimal(LastPNum) / TotalPeopleNum, 3, MidpointRounding.AwayFromZero) * 100; } //只查询同比下降的 decimal UpRate = 0; if (nowRate < lastRate) { if (nowRate == 0) { UpRate = 100; } else { UpRate = Math.Round((lastRate - nowRate) / lastRate, 3, MidpointRounding.AwayFromZero) * 100; } RList.Add(new { Id = Num, Days = EDays, TotalNum = TotalPeopleNum, PeopleNum = OKPNum, UpRate, Type = Common.Enum.OKR.MatterTypeEnum.Align, TypeName = Common.Enum.OKR.MatterTypeEnum.Align.ToName(), SelectType = 2, }); Num++; } #endregion } if (!list.Where(x => x.Type == Common.Enum.OKR.MatterTypeEnum.Score).Any() && (EValue == 0 || (EValue > 0 && EDays <= EValue))) { //查询打分 int OKPNum = oKR_ObjectiveRepository.GetNotScoreList(userInfo.Group_Id, periodId, userIds, 2); int LastPNum = 0; if (lastPeriodId > 0) { LastPNum = oKR_ObjectiveRepository.GetNotScoreList(userInfo.Group_Id, lastPeriodId, userIds, 2); } #region 计算概率 decimal nowRate = 0; if (TotalPeopleNum > 0) { nowRate = Math.Round(Convert.ToDecimal(OKPNum) / TotalPeopleNum, 3, MidpointRounding.AwayFromZero) * 100; } decimal lastRate = 0; if (TotalPeopleNum > 0) { lastRate = Math.Round(Convert.ToDecimal(LastPNum) / TotalPeopleNum, 3, MidpointRounding.AwayFromZero) * 100; } //只查询同比下降的 decimal UpRate = 0; if (nowRate < lastRate) { if (nowRate == 0) { UpRate = 100; } else { UpRate = Math.Round((lastRate - nowRate) / lastRate, 3, MidpointRounding.AwayFromZero) * 100; } RList.Add(new { Id = Num, Days = EDays, TotalNum = TotalPeopleNum, PeopleNum = OKPNum, UpRate, Type = Common.Enum.OKR.MatterTypeEnum.Score, TypeName = Common.Enum.OKR.MatterTypeEnum.Score.ToName(), SelectType = 4, }); Num++; } #endregion } } } } return RList; } /// /// 设置关注事项忽略 /// /// /// /// /// public bool SetOKRMatterIgnore(int periodId, int type, UserInfo userInfo) { var list = oKR_MatterRepository.GetList(new Model.Entity.OKR.RB_OKR_Matter() { Group_Id = userInfo.Group_Id, PeriodId = periodId, Type = (Common.Enum.OKR.MatterTypeEnum)type }); if (list.Any()) { return true; } return oKR_MatterRepository.Insert(new Model.Entity.OKR.RB_OKR_Matter() { Id = 0, PeriodId = periodId, UserId = userInfo.Id, Type = (Common.Enum.OKR.MatterTypeEnum)type, Status = 0, School_Id = userInfo.School_Id, Group_Id = userInfo.Group_Id, CreateTime = DateTime.Now }) > 0; } /// /// 获取关注事项详情 /// /// /// /// /// /// /// /// /// /// /// public List GetOKRMatterDetailPageList(int pageIndex, int pageSize, out long count, int periodId, int type, int departId, int postId, int leaveStatus, UserInfo userInfo) { count = 0; List Rlist = new List(); var userIdList = GetMyUnderlingUserIdList(userInfo, departId, postId, leaveStatus); if (userIdList.Any()) { userIdList = userIdList.Distinct().ToList(); string userIds = string.Join(",", userIdList); if (type == (int)Common.Enum.OKR.MatterTypeEnum.NotFilled) { //查询未填写 Rlist = oKR_ObjectiveRepository.GetNotFilledPageList(pageIndex, pageSize, out count, userInfo.Group_Id, periodId, userIds); } else if (type == (int)Common.Enum.OKR.MatterTypeEnum.NotUpdated) { //查询未更新 Rlist = oKR_ObjectiveRepository.GetNotpdatedPageList(pageIndex, pageSize, out count, userInfo.Group_Id, periodId, userIds); } if (type == (int)Common.Enum.OKR.MatterTypeEnum.NotScore) { //查询未打分 Rlist = oKR_ObjectiveRepository.GetNotScorePageList(pageIndex, pageSize, out count, userInfo.Group_Id, periodId, userIds); } } return Rlist; } /// /// 获取概率统计 /// /// /// /// /// /// /// /// /// public object GetOKRProbabilityInfo(int periodId, int rangeType, string departId, int postId, int leaveStatus, UserInfo userInfo, bool IsAdmin) { var userIdList = new List(); if (IsAdmin == false) { if (rangeType == 1) { //查询该用户下所有的下级用户 userIdList = GetMyAllDownlineUserIdList(userInfo, 0, postId, leaveStatus); } else { //首先查询用户的所有直属下级 userIdList = GetMyUnderlingUserIdList(userInfo, 0, postId, leaveStatus); } } else { var accountList = accountRepository.GetAccountListExtRepository(new Model.ViewModel.User.RB_Account_ViewModel() { Group_Id = userInfo.Group_Id, DeptIds = departId, Post_Id = postId, LeaveStatus = leaveStatus, IsSelectLevelNor = 1 }); userIdList = accountList.Select(x => x.Id).ToList(); } int BranchTNum = accountRepository.GetAccountTotalNum(new RB_Account_ViewModel() { Group_Id = userInfo.Group_Id, IsSelectLevelNor = 1 }); int TWriteNum = 0, TAlignNum = 0, TScoreNum = 0, TUpdateNum = 0; if (BranchTNum > 0) { //填写人数查询 TWriteNum = oKR_ObjectiveRepository.GetNotFilledList(userInfo.Group_Id, periodId, ""); //对齐率查询 TAlignNum = oKR_ObjectiveRepository.GetAlignPeopleNum(userInfo.Group_Id, periodId, ""); //打分率查询 TScoreNum = oKR_ObjectiveRepository.GetNotScoreList(userInfo.Group_Id, periodId, "", 2); //最近7天更新率 string dateStr = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd"); TUpdateNum = oKR_ObjectiveRepository.GetRecently7DayPeopleNum(userInfo.Group_Id, periodId, "", dateStr); } int TotalNum = 0, WriteNum = 0, AlignNum = 0, ScoreNum = 0, UpdateNum = 0; if (userIdList.Any()) { userIdList = userIdList.Distinct().ToList(); TotalNum = userIdList.Count(); string userIds = string.Join(",", userIdList); //填写人数查询 WriteNum = oKR_ObjectiveRepository.GetNotFilledList(userInfo.Group_Id, periodId, userIds); //对齐率查询 AlignNum = oKR_ObjectiveRepository.GetAlignPeopleNum(userInfo.Group_Id, periodId, userIds); //打分率查询 ScoreNum = oKR_ObjectiveRepository.GetNotScoreList(userInfo.Group_Id, periodId, userIds, 2); //最近7天更新率 string dateStr = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd"); UpdateNum = oKR_ObjectiveRepository.GetRecently7DayPeopleNum(userInfo.Group_Id, periodId, userIds, dateStr); } return new { TotalPeopleNum = TotalNum, WriteNum, WriteRate = (Math.Round(Convert.ToDecimal(WriteNum) / TotalNum, 3, MidpointRounding.AwayFromZero) * 100).ToString("#0.0"), AlignNum, AlignRate = (Math.Round(Convert.ToDecimal(AlignNum) / TotalNum, 3, MidpointRounding.AwayFromZero) * 100).ToString("#0.0"), ScoreNum, ScoreRate = (Math.Round(Convert.ToDecimal(ScoreNum) / TotalNum, 3, MidpointRounding.AwayFromZero) * 100).ToString("#0.0"), UpdateNum, UpdateRate = (Math.Round(Convert.ToDecimal(UpdateNum) / TotalNum, 3, MidpointRounding.AwayFromZero) * 100).ToString("#0.0"), TWriteRate = BranchTNum > 0 ? (Math.Round(Convert.ToDecimal(TWriteNum) / BranchTNum, 3, MidpointRounding.AwayFromZero) * 100).ToString("#0.0") : "0.0", TAlignRate = BranchTNum > 0 ? (Math.Round(Convert.ToDecimal(TAlignNum) / BranchTNum, 3, MidpointRounding.AwayFromZero) * 100).ToString("#0.0") : "0.0", TScoreRate = BranchTNum > 0 ? (Math.Round(Convert.ToDecimal(TScoreNum) / BranchTNum, 3, MidpointRounding.AwayFromZero) * 100).ToString("#0.0") : "0.0", TUpdateRate = BranchTNum > 0 ? (Math.Round(Convert.ToDecimal(TUpdateNum) / BranchTNum, 3, MidpointRounding.AwayFromZero) * 100).ToString("#0.0") : "0.0" }; } /// /// 获取概率明细分页列表 - 人员 /// /// /// /// /// /// /// /// /// /// /// /// /// public List GetOKRProbabilityPageListForEmp(int pageIndex, int pageSize, out long count, int periodId,int orderBy, int type, string userName, int rangeType, string departId, int postId, int leaveStatus, UserInfo userInfo, bool IsAdmin) { count = 0; List Rlist = new List(); var userIdList = new List(); if (IsAdmin == false) { if (rangeType == 1) { //查询该用户下所有的下级用户 userIdList = GetMyAllDownlineUserIdList(userInfo, 0, postId, leaveStatus); } else { //首先查询用户的所有直属下级 userIdList = GetMyUnderlingUserIdList(userInfo, 0, postId, leaveStatus); } } else { var accountList = accountRepository.GetAccountListExtRepository(new Model.ViewModel.User.RB_Account_ViewModel() { Group_Id = userInfo.Group_Id, AccountName = userName, DeptIds = departId, Post_Id = postId, LeaveStatus = leaveStatus, IsSelectLevelNor = 1 }); userIdList = accountList.Select(x => x.Id).ToList(); } if (userIdList.Any()) { userIdList = userIdList.Distinct().ToList(); string userIds = string.Join(",", userIdList); if (type == (int)Common.Enum.OKR.MatterTypeEnum.NotFilled) { //查询填写 Rlist = oKR_ObjectiveRepository.GetWritePageList(pageIndex, pageSize, out count, userInfo.Group_Id, periodId, userIds, orderBy); } else if (type == (int)Common.Enum.OKR.MatterTypeEnum.NotAlign) { //查询对齐 Rlist = oKR_ObjectiveRepository.GetAlignPageList(pageIndex, pageSize, out count, userInfo.Group_Id, periodId, userIds, orderBy); } else if (type == (int)Common.Enum.OKR.MatterTypeEnum.NotUpdated) { //查询更新 string dateStr = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd"); Rlist = oKR_ObjectiveRepository.GetUpdatePageList(pageIndex, pageSize, out count, userInfo.Group_Id, periodId, userIds, dateStr, orderBy); } if (type == (int)Common.Enum.OKR.MatterTypeEnum.NotScore) { //查询打分 Rlist = oKR_ObjectiveRepository.GetScorePageList(pageIndex, pageSize, out count, userInfo.Group_Id, periodId, userIds, orderBy); } } return Rlist; } /// /// 获取概率明细分页列表 - 部门 /// /// /// /// /// /// /// /// /// public object GetOKRProbabilityPageListForDept(int periodId, int selectType, string departId, int postId, int leaveStatus, UserInfo userInfo, bool IsAdmin) { int lastPeriodId = 0; if (periodId > 0) { //查询上一个周期id var model = oKR_PeriodRepository.GetEntity(periodId); if (model != null && model.IsNormal == 1) { lastPeriodId = oKR_PeriodRepository.GetLastPeriodId(model.Id, model.IsYear, userInfo.Group_Id); } } List Rlist = new List(); if (IsAdmin == false) { var xjdlist = departmentRepository.GetDepartmentListRepository(new RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, ManagerIds = userInfo.Id.ToString() }); if (xjdlist.Any()) { List DeptIdList = new List(); foreach (var item in xjdlist) { //查询出所有的部门 string DeptIds = departmentRepository.GetCurrentAndChildDepartmentIdsRepository(item.DeptId); if (!string.IsNullOrEmpty(DeptIds)) { DeptIdList.AddRange(JsonHelper.DeserializeObject>("[" + DeptIds + "]")); } } string DeptIdStr = string.Join(",", DeptIdList.Distinct()); //上级部门下所有子部门的负责人 var d2list = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, QDeptIds = DeptIdStr }); string ManagerIds = string.Join(",", d2list.Where(x => !string.IsNullOrEmpty(x.ManagerIds)).Select(x => x.ManagerIds)); List ManagerList = new List(); if (!string.IsNullOrEmpty(ManagerIds)) { ManagerList = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, QIds = ManagerIds, Post_Id = postId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); } List RList = new List(); List LastRList = new List(); GetProbabilityListData(periodId, selectType, userInfo, lastPeriodId, DeptIdStr, ref RList, ref LastRList); //返回部门树形结构 foreach (var item in xjdlist) { List ManagerList1 = new List(); if (!string.IsNullOrEmpty(item.ManagerIds)) { List ManagerIdList = JsonHelper.DeserializeObject>("[" + item.ManagerIds + "]"); ManagerList1 = ManagerList.Where(x => ManagerIdList.Contains(x.Id)).ToList(); } GetProbabilityDeptRate(RList, LastRList, item, selectType, out int PeopleNum, out decimal nowRate, out decimal lastRate, out int Type, out decimal UpRate); Rlist.Add(new { item.DeptId, item.DeptName, ManagerList = ManagerList1.Select(x => new { x.Id, x.EmployeeName, x.UserIcon }), PeopleNum, NowRate = nowRate, LastRate = lastRate, Type, UpRate, ChildList = GetChildProbabilityDept(item, selectType, d2list, ManagerList, RList, LastRList) }); } } else { //只查询自己部门 var dlist = departmentRepository.GetDepartmentListRepository(new RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, DeptId = userInfo.DeptId }); string DeptIdStr = userInfo.DeptId.ToString(); string ManagerIds = string.Join(",", dlist.Where(x => !string.IsNullOrEmpty(x.ManagerIds)).Select(x => x.ManagerIds)); List ManagerList = new List(); if (!string.IsNullOrEmpty(ManagerIds)) { ManagerList = accountRepository.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, QIds = ManagerIds, Post_Id = postId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); } List RList = new List(); List LastRList = new List(); GetProbabilityListData(periodId, selectType, userInfo, lastPeriodId, DeptIdStr, ref RList, ref LastRList); //返回部门树形结构 foreach (var item in dlist) { List ManagerList1 = new List(); if (!string.IsNullOrEmpty(item.ManagerIds)) { List ManagerIdList = JsonHelper.DeserializeObject>("[" + item.ManagerIds + "]"); ManagerList1 = ManagerList.Where(x => ManagerIdList.Contains(x.Id)).ToList(); } GetProbabilityDeptRate(RList, LastRList, item, selectType, out int PeopleNum, out decimal nowRate, out decimal lastRate, out int Type, out decimal UpRate); Rlist.Add(new { item.DeptId, item.DeptName, ManagerList = ManagerList1.Select(x => new { x.Id, x.EmployeeName, x.UserIcon }), PeopleNum, NowRate = nowRate, LastRate = lastRate, Type, UpRate, ChildList = GetChildProbabilityDept(item, selectType, dlist, ManagerList, RList, LastRList) }); } } } else { if (!string.IsNullOrEmpty(departId)) { var dlist = departmentRepository.GetDepartmentListRepository(new RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, QDeptIds = departId }); string DeptIdStr = departId.ToString(); string ManagerIds = string.Join(",", dlist.Where(x => !string.IsNullOrEmpty(x.ManagerIds)).Select(x => x.ManagerIds)); List ManagerList = new List(); if (!string.IsNullOrEmpty(ManagerIds)) { ManagerList = accountRepository.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, QIds = ManagerIds, Post_Id = postId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); } List RList = new List(); List LastRList = new List(); GetProbabilityListData(periodId, selectType, userInfo, lastPeriodId, DeptIdStr, ref RList, ref LastRList); //返回部门树形结构 foreach (var item in dlist) { List ManagerList1 = new List(); if (!string.IsNullOrEmpty(item.ManagerIds)) { List ManagerIdList = JsonHelper.DeserializeObject>("[" + item.ManagerIds + "]"); ManagerList1 = ManagerList.Where(x => ManagerIdList.Contains(x.Id)).ToList(); } GetProbabilityDeptRate(RList, LastRList, item, selectType, out int PeopleNum, out decimal nowRate, out decimal lastRate, out int Type, out decimal UpRate); Rlist.Add(new { item.DeptId, item.DeptName, ManagerList = ManagerList1.Select(x => new { x.Id, x.EmployeeName, x.UserIcon }), PeopleNum, NowRate = nowRate, LastRate = lastRate, Type, UpRate, ChildList = GetChildProbabilityDept(item, selectType, dlist, ManagerList, RList, LastRList) }); } } else { //直接查询所有部门 var dlist = departmentRepository.GetDepartmentListRepository(new RB_Department_ViewModel() { Group_Id = userInfo.Group_Id }); if (dlist.Any()) { string DeptIdStr = string.Join(",", dlist.Select(x => x.DeptId)); //上级部门下所有子部门的负责人 string ManagerIds = string.Join(",", dlist.Where(x => !string.IsNullOrEmpty(x.ManagerIds)).Select(x => x.ManagerIds)); List ManagerList = new List(); if (!string.IsNullOrEmpty(ManagerIds)) { ManagerList = accountRepository.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, QIds = ManagerIds, Post_Id = postId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); } List RList = new List(); List LastRList = new List(); GetProbabilityListData(periodId, selectType, userInfo, lastPeriodId, DeptIdStr, ref RList, ref LastRList); //返回部门树形结构 var firstList = dlist.Where(x => x.ParentId == 0).ToList(); foreach (var item in firstList) { List ManagerList1 = new List(); if (!string.IsNullOrEmpty(item.ManagerIds)) { List ManagerIdList = JsonHelper.DeserializeObject>("[" + item.ManagerIds + "]"); ManagerList1 = ManagerList.Where(x => ManagerIdList.Contains(x.Id)).ToList(); } GetProbabilityDeptRate(RList, LastRList, item, selectType, out int PeopleNum, out decimal nowRate, out decimal lastRate, out int Type, out decimal UpRate); Rlist.Add(new { item.DeptId, item.DeptName, ManagerList = ManagerList1.Select(x => new { x.Id, x.EmployeeName, x.UserIcon }), PeopleNum, NowRate = nowRate, LastRate = lastRate, Type, UpRate, ChildList = GetChildProbabilityDept(item, selectType, dlist, ManagerList, RList, LastRList) }); } } } } return Rlist; } /// /// 获取概率明细树形子集列表 /// /// /// /// /// /// private object GetChildProbabilityDept(RB_Department_ViewModel model, int selectType, List d2list, List ManagerList, List RList, List LastRList) { List Rlist = new List(); var clist = d2list.Where(x => x.ParentId == model.DeptId).ToList(); foreach (var item in clist) { List ManagerList1 = new List(); if (!string.IsNullOrEmpty(item.ManagerIds)) { List ManagerIdList = JsonHelper.DeserializeObject>("[" + item.ManagerIds + "]"); ManagerList1 = ManagerList.Where(x => ManagerIdList.Contains(x.Id)).ToList(); } GetProbabilityDeptRate(RList, LastRList, item, selectType, out int PeopleNum, out decimal nowRate, out decimal lastRate, out int Type, out decimal UpRate); Rlist.Add(new { item.DeptId, item.DeptName, ManagerList = ManagerList1.Select(x => new { x.Id, x.EmployeeName, x.UserIcon }), PeopleNum, NowRate = nowRate, LastRate = lastRate, Type, UpRate, ChildList = GetChildProbabilityDept(item, selectType, d2list, ManagerList, RList, LastRList) }); } return Rlist; } /// /// 获取概率数据 /// /// /// /// /// /// /// /// private void GetProbabilityListData(int periodId, int selectType, UserInfo userInfo, int lastPeriodId, string DeptIdStr, ref List RList, ref List LastRList) { if (selectType == (int)Common.Enum.OKR.MatterTypeEnum.NotFilled) { //查询填写 RList = oKR_ObjectiveRepository.GetWriteList(userInfo.Group_Id, periodId, DeptIdStr); if (lastPeriodId > 0) { LastRList = oKR_ObjectiveRepository.GetWriteList(userInfo.Group_Id, lastPeriodId, DeptIdStr); } } else if (selectType == (int)Common.Enum.OKR.MatterTypeEnum.NotAlign) { //查询对齐 RList = oKR_ObjectiveRepository.GetAlignList(userInfo.Group_Id, periodId, DeptIdStr); if (lastPeriodId > 0) { LastRList = oKR_ObjectiveRepository.GetAlignList(userInfo.Group_Id, lastPeriodId, DeptIdStr); } } else if (selectType == (int)Common.Enum.OKR.MatterTypeEnum.NotUpdated) { //查询更新 string dateStr = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd"); RList = oKR_ObjectiveRepository.GetUpdateList(userInfo.Group_Id, periodId, DeptIdStr, dateStr); } if (selectType == (int)Common.Enum.OKR.MatterTypeEnum.NotScore) { //查询打分 RList = oKR_ObjectiveRepository.GetScoreList(userInfo.Group_Id, periodId, DeptIdStr); if (lastPeriodId > 0) { LastRList = oKR_ObjectiveRepository.GetScoreList(userInfo.Group_Id, lastPeriodId, DeptIdStr); } } } /// /// 获取概率 /// /// /// /// /// /// /// /// /// private static void GetProbabilityDeptRate(List RList, List LastRList, RB_Department_ViewModel item, int selectType, out int PeopleNum, out decimal nowRate, out decimal lastRate, out int Type, out decimal UpRate) { var nowList = RList.Where(x => x.RB_Department_Id == item.DeptId).ToList(); PeopleNum = nowList.Count(); nowRate = 0; if (PeopleNum > 0) { nowRate = Math.Round(Convert.ToDecimal(nowList.Where(x => x.Status == 1).Count()) / PeopleNum, 3, MidpointRounding.AwayFromZero) * 100; } var lastList = LastRList.Where(x => x.RB_Department_Id == item.DeptId).ToList(); int lPeopleNum = lastList.Count(); lastRate = 0; if (lPeopleNum > 0) { lastRate = Math.Round(Convert.ToDecimal(lastList.Where(x => x.Status == 1).Count()) / lPeopleNum, 3, MidpointRounding.AwayFromZero) * 100; } Type = 1; UpRate = 0; if (selectType == 3) { Type = 0; } else { if (nowRate > lastRate) { if (lastRate == 0) { UpRate = 100; } else { UpRate = Math.Round((nowRate - lastRate) / lastRate, 3, MidpointRounding.AwayFromZero) * 100; } } else if (nowRate < lastRate) { Type = 2; if (nowRate == 0) { UpRate = 100; } else { UpRate = Math.Round((lastRate - nowRate) / lastRate, 3, MidpointRounding.AwayFromZero) * 100; } } else { Type = 0; } } } #endregion #region 春姐 统计 /// /// 获取个人数据分布明细 /// /// /// /// /// /// /// /// /// /// /// /// public List GetOKRGRDateDistributionPage(int pageIndex, int pageSize, out long count,string EmployeeName, int periodId, int type, int startValue, int endValue, int orderBy, int rangeType, string departIds, int postId, int leaveStatus, UserInfo userInfo, bool IsAdmin = false) { count = 0; var userIdList = new List(); if (IsAdmin == false) { if (rangeType == 1) { //查询该用户下所有的下级用户 userIdList = GetMyAllDownlineUserIdList(userInfo, 0, postId, leaveStatus); } else { //首先查询用户的所有直属下级 userIdList = GetMyUnderlingUserIdList(userInfo, 0, postId, leaveStatus); } } else { var accountList = accountRepository.GetAccountListExtRepository(new Model.ViewModel.User.RB_Account_ViewModel() { Group_Id = userInfo.Group_Id, DeptIds = departIds, Post_Id = postId, LeaveStatus = leaveStatus, IsSelectLevelNor = 1 }); userIdList = accountList.Select(x => x.Id).ToList(); } string userIds = string.Join(",", userIdList.Distinct()); List RList = oKR_ObjectiveRepository.GetOKRGRDateDistributionPage(pageIndex, pageSize, out count, EmployeeName, periodId, startValue, endValue, orderBy, userIds, userInfo.Group_Id); return RList; } /// /// 获取个人数据分布明细 - 部门统计 /// /// /// /// /// /// /// /// /// /// /// /// /// public object GetOKRGRDateDistributionForDept(int periodId, int type, int orderBy, int orderByNum, string departId, int postId, int leaveStatus, UserInfo userInfo, bool IsAdmin) { List Rlist = new List(); if (IsAdmin == false) { var xjdlist = departmentRepository.GetDepartmentListRepository(new RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, ManagerIds = userInfo.Id.ToString() }); if (xjdlist.Any()) { List DeptIdList = new List(); foreach (var item in xjdlist) { //查询出所有的部门 string DeptIds = departmentRepository.GetCurrentAndChildDepartmentIdsRepository(item.DeptId); if (!string.IsNullOrEmpty(DeptIds)) { DeptIdList.AddRange(JsonHelper.DeserializeObject>("[" + DeptIds + "]")); } } string DeptIdStr = string.Join(",", DeptIdList.Distinct()); //上级部门下所有子部门的负责人 var d2list = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, QDeptIds = DeptIdStr }); string ManagerIds = string.Join(",", d2list.Where(x => !string.IsNullOrEmpty(x.ManagerIds)).Select(x => x.ManagerIds)); List ManagerList = new List(); if (!string.IsNullOrEmpty(ManagerIds)) { ManagerList = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, QIds = ManagerIds, Post_Id = postId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); } List RList = oKR_ObjectiveRepository.GetOKRGRDateDistributionDept(periodId, DeptIdStr, userInfo.Group_Id); //返回部门树形结构 foreach (var item in xjdlist) { List ManagerList1 = new List(); if (!string.IsNullOrEmpty(item.ManagerIds)) { List ManagerIdList = JsonHelper.DeserializeObject>("[" + item.ManagerIds + "]"); ManagerList1 = ManagerList.Where(x => ManagerIdList.Contains(x.Id)).ToList(); } var PeopleNum = RList.Where(x => x.Dept_Id == item.DeptId).Count(); var ObjectiveNCount = RList.Where(x => x.Dept_Id == item.DeptId && x.ObjectiveNCount > 0).Count(); var ScoreCount = RList.Where(x => x.Dept_Id == item.DeptId && x.ScoreCount > 0).Count(); var OBjectiveRelation = RList.Where(x => x.Dept_Id == item.DeptId&&x.OBjectiveRelation>0).Count(); var DayNum = RList.Where(x => x.Dept_Id == item.DeptId && x.DayNum > -1).Count(); Rlist.Add(new { item.DeptId, item.DeptName, ManagerList = ManagerList1.Select(x => new { x.Id, x.EmployeeName, x.UserIcon }), PeopleNum,//总人数部门 ObjectiveNCount, ScoreCount, OBjectiveRelation, DayNum, ChildList = GetChildDeptForDateDistribution(item, d2list, ManagerList, RList, type, orderBy, orderByNum) }); } } else { //只查询自己部门 var dlist = departmentRepository.GetDepartmentListRepository(new RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, DeptId = userInfo.DeptId }); string DeptIdStr = userInfo.DeptId.ToString(); string ManagerIds = string.Join(",", dlist.Where(x => !string.IsNullOrEmpty(x.ManagerIds)).Select(x => x.ManagerIds)); List ManagerList = new List(); if (!string.IsNullOrEmpty(ManagerIds)) { ManagerList = accountRepository.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, QIds = ManagerIds, Post_Id = postId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); } List RList = oKR_ObjectiveRepository.GetOKRGRDateDistributionDept(periodId, DeptIdStr, userInfo.Group_Id); //返回部门树形结构 foreach (var item in dlist) { List ManagerList1 = new List(); if (!string.IsNullOrEmpty(item.ManagerIds)) { List ManagerIdList = JsonHelper.DeserializeObject>("[" + item.ManagerIds + "]"); ManagerList1 = ManagerList.Where(x => ManagerIdList.Contains(x.Id)).ToList(); } var PeopleNum = RList.Where(x => x.Dept_Id == item.DeptId).Count(); var ObjectiveNCount = RList.Where(x => x.Dept_Id == item.DeptId && x.ObjectiveNCount > 0).Count(); var ScoreCount = RList.Where(x => x.Dept_Id == item.DeptId && x.ScoreCount > 0).Count(); var OBjectiveRelation = RList.Where(x => x.Dept_Id == item.DeptId && x.OBjectiveRelation > 0).Count(); var DayNum = RList.Where(x => x.Dept_Id == item.DeptId && x.DayNum > -1).Count(); Rlist.Add(new { item.DeptId, item.DeptName, ManagerList = ManagerList1.Select(x => new { x.Id, x.EmployeeName, x.UserIcon }), PeopleNum,//总人数部门 ObjectiveNCount, ScoreCount, OBjectiveRelation, DayNum, ChildList = GetChildDeptForDateDistribution(item, dlist, ManagerList, RList, type, orderBy, orderByNum) }); } } } else { if (!string.IsNullOrEmpty(departId)) { var dlist = departmentRepository.GetDepartmentListRepository(new RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, QDeptIds = departId }); string DeptIdStr = departId.ToString(); string ManagerIds = string.Join(",", dlist.Where(x => !string.IsNullOrEmpty(x.ManagerIds)).Select(x => x.ManagerIds)); List ManagerList = new List(); if (!string.IsNullOrEmpty(ManagerIds)) { ManagerList = accountRepository.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, QIds = ManagerIds, Post_Id = postId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); } List RList = oKR_ObjectiveRepository.GetOKRGRDateDistributionDept(periodId, DeptIdStr, userInfo.Group_Id); //返回部门树形结构 foreach (var item in dlist) { List ManagerList1 = new List(); if (!string.IsNullOrEmpty(item.ManagerIds)) { List ManagerIdList = JsonHelper.DeserializeObject>("[" + item.ManagerIds + "]"); ManagerList1 = ManagerList.Where(x => ManagerIdList.Contains(x.Id)).ToList(); } var PeopleNum = RList.Where(x => x.Dept_Id == item.DeptId).Count(); var ObjectiveNCount = RList.Where(x => x.Dept_Id == item.DeptId && x.ObjectiveNCount > 0).Count(); var ScoreCount = RList.Where(x => x.Dept_Id == item.DeptId && x.ScoreCount > 0).Count(); var OBjectiveRelation = RList.Where(x => x.Dept_Id == item.DeptId && x.OBjectiveRelation > 0).Count(); var DayNum = RList.Where(x => x.Dept_Id == item.DeptId && x.DayNum > -1).Count(); Rlist.Add(new { item.DeptId, item.DeptName, ManagerList = ManagerList1.Select(x => new { x.Id, x.EmployeeName, x.UserIcon }), PeopleNum,//总人数部门 ObjectiveNCount, ScoreCount, OBjectiveRelation, DayNum, ChildList = GetChildDeptForDateDistribution(item, dlist, ManagerList, RList, type, orderBy, orderByNum) }); } } else { //直接查询所有部门 var dlist = departmentRepository.GetDepartmentListRepository(new RB_Department_ViewModel() { Group_Id = userInfo.Group_Id }); if (dlist.Any()) { string DeptIdStr = string.Join(",", dlist.Select(x => x.DeptId)); //上级部门下所有子部门的负责人 string ManagerIds = string.Join(",", dlist.Where(x => !string.IsNullOrEmpty(x.ManagerIds)).Select(x => x.ManagerIds)); List ManagerList = new List(); if (!string.IsNullOrEmpty(ManagerIds)) { ManagerList = accountRepository.GetEmployeeListRepository(new Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, QIds = ManagerIds, Post_Id = postId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); } List RList = oKR_ObjectiveRepository.GetOKRGRDateDistributionDept(periodId, DeptIdStr, userInfo.Group_Id); //返回部门树形结构 var firstList = dlist.Where(x => x.ParentId == 0).ToList(); foreach (var item in firstList) { List ManagerList1 = new List(); if (!string.IsNullOrEmpty(item.ManagerIds)) { List ManagerIdList = JsonHelper.DeserializeObject>("[" + item.ManagerIds + "]"); ManagerList1 = ManagerList.Where(x => ManagerIdList.Contains(x.Id)).ToList(); } var PeopleNum = RList.Where(x => x.Dept_Id == item.DeptId).Count(); var ObjectiveNCount = RList.Where(x => x.Dept_Id == item.DeptId && x.ObjectiveNCount > 0).Count(); var ScoreCount = RList.Where(x => x.Dept_Id == item.DeptId && x.ScoreCount > 0).Count(); var OBjectiveRelation = RList.Where(x => x.Dept_Id == item.DeptId && x.OBjectiveRelation > 0).Count(); var DayNum = RList.Where(x => x.Dept_Id == item.DeptId && x.DayNum > -1).Count(); Rlist.Add(new { item.DeptId, item.DeptName, ManagerList = ManagerList1.Select(x => new { x.Id, x.EmployeeName, x.UserIcon }), PeopleNum,//总人数部门 ObjectiveNCount, ScoreCount, OBjectiveRelation, DayNum, ChildList = GetChildDeptForDateDistribution(item, dlist, ManagerList, RList, type, orderBy, orderByNum) }); } } } } return Rlist; } /// /// 获取部门子集 /// /// /// /// /// /// /// /// /// private object GetChildDeptForDateDistribution(RB_Department_ViewModel model, List d2list, List ManagerList, List RList, int type, int orderBy, int orderByNum) { List Rlist = new List(); var clist = d2list.Where(x => x.ParentId == model.DeptId).ToList(); foreach (var item in clist) { List ManagerList1 = new List(); if (!string.IsNullOrEmpty(item.ManagerIds)) { List ManagerIdList = JsonHelper.DeserializeObject>("[" + item.ManagerIds + "]"); ManagerList1 = ManagerList.Where(x => ManagerIdList.Contains(x.Id)).ToList(); } var PeopleNum = RList.Where(x => x.Dept_Id == item.DeptId).Count(); var ObjectiveNCount = RList.Where(x => x.Dept_Id == item.DeptId && x.ObjectiveNCount > 0).Count(); var ScoreCount = RList.Where(x => x.Dept_Id == item.DeptId && x.ScoreCount > 0).Count(); var OBjectiveRelation = RList.Where(x => x.Dept_Id == item.DeptId && x.OBjectiveRelation > 0).Count(); var DayNum = RList.Where(x => x.Dept_Id == item.DeptId && x.DayNum > -1).Count(); Rlist.Add(new { item.DeptId, item.DeptName, ManagerList = ManagerList1.Select(x => new { x.Id, x.EmployeeName, x.UserIcon }), PeopleNum,//总人数部门 ObjectiveNCount, ScoreCount, OBjectiveRelation, DayNum, ChildList = GetChildDeptForDateDistribution(item, d2list, ManagerList, RList, type, orderBy, orderByNum) }); } return Rlist; } /// /// 获取个人维度打分以及目标量 /// /// /// /// /// public List GetOKRPersonalAlignList(int group_Id, int periodId, string CreateBys) { return oKR_ObjectiveRepository.GetOKRPersonalAlignList(group_Id, periodId, CreateBys); } /// /// 获取个人维度对齐量 /// /// /// /// /// public List GetOKRPersonalRelationAlignList(int group_Id, int periodId, string CreateBys, int id) { return oKR_ObjectiveRepository.GetOKRPersonalRelationAlignList(group_Id, periodId, CreateBys, id); } /// /// 获取个人维度对齐量 /// /// /// /// /// public List GetOKRPersonalRelationAlignList_V2(int group_Id, int periodId, string CreateBys) { return oKR_ObjectiveRepository.GetOKRPersonalRelationAlignList_V2(group_Id, periodId, CreateBys); } /// /// 获取我的直属下级 /// /// /// public List GetOKRPersonalDimensionList(int Group_Id, int Id, int DeptId = 0) { List UserIdList = new List(); List allList = new List(); #region 我的直属下级 var emList = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = Group_Id, IsLeave = 1, DirectSupervisor = Id, Dept_Id = DeptId }); if (emList.Any()) { foreach (var item in emList) { allList.Add(new OKRPersonalDimension() { Id = item.Id, EmployeeName = item.EmployeeName, UserIcon = item.UserIcon, Dept_Id = item.Dept_Id, Type = 2 }); UserIdList.Add(item.Id); } } //如果是部门主管 需要将部门下除自己其他人加入 //查询部门负责人 负责的所有部门 var xjdlist = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { DeptId = DeptId, Group_Id = Group_Id, ManagerIds = Id.ToString() }); if (xjdlist.Any()) { //查询该部门下所有人 var em1List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = Group_Id, IsLeave = 1, QDeptIds = string.Join(",", xjdlist.Select(x => x.DeptId)) }); em1List = em1List.Where(x => !UserIdList.Contains(x.Id) && x.DirectSupervisor == 0).ToList();//排序 已存在的直接关系 if (em1List.Any()) { //查询全部负责人 string AllManagerIds = departmentRepository.GetAllDepartmentManagerIds(Group_Id); List AllDeptManageId = new List(); if (!string.IsNullOrEmpty(AllManagerIds)) { AllDeptManageId = JsonHelper.DeserializeObject>("[" + AllManagerIds + "]"); } //对 em1List 排除负责人 foreach (var item in em1List.Where(x => !AllDeptManageId.Contains(x.Id))) { allList.Add(new OKRPersonalDimension() { Id = item.Id, EmployeeName = item.EmployeeName, UserIcon = item.UserIcon, Dept_Id = item.Dept_Id, Type = 2 }); UserIdList.Add(item.Id); } } //上级部门下所有子部门的负责人 var d2list = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = 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 = Group_Id, IsLeave = 1, QIds = ManagerIds }); em1List = em1List.Where(x => !UserIdList.Contains(x.Id) && x.Id != Id && x.DirectSupervisor == 0).ToList();//排序 已存在的直接关系 foreach (var item in em1List) { allList.Add(new OKRPersonalDimension() { Id = item.Id, EmployeeName = item.EmployeeName, UserIcon = item.UserIcon, Dept_Id = item.Dept_Id, Type = 2 }); UserIdList.Add(item.Id); } } } #endregion return allList; } /// /// 我的直属下级 /// /// /// /// /// public List GetOKRPersonalDimensionListModule(int Group_Id, int Id, int DeptId = 0) { List UserIdList = new List(); List allList = new List(); #region 我的直属下级 var emList = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = Group_Id, IsLeave = 1, DirectSupervisor = Id, Dept_Id = DeptId }); if (emList.Any()) { foreach (var item in emList) { UserIdList.Add(item.Id); } } //如果是部门主管 需要将部门下除自己其他人加入 //查询部门负责人 负责的所有部门 var xjdlist = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { DeptId = DeptId, Group_Id = Group_Id, ManagerIds = Id.ToString() }); if (xjdlist.Any()) { //查询该部门下所有人 var em1List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = Group_Id, IsLeave = 1, QDeptIds = string.Join(",", xjdlist.Select(x => x.DeptId)) }); em1List = em1List.Where(x => !UserIdList.Contains(x.Id) && x.DirectSupervisor == 0).ToList();//排序 已存在的直接关系 if (em1List.Any()) { //查询全部负责人 string AllManagerIds = departmentRepository.GetAllDepartmentManagerIds(Group_Id); List AllDeptManageId = new List(); if (!string.IsNullOrEmpty(AllManagerIds)) { AllDeptManageId = JsonHelper.DeserializeObject>("[" + AllManagerIds + "]"); } //对 em1List 排除负责人 foreach (var item in em1List.Where(x => !AllDeptManageId.Contains(x.Id))) { allList.Add(new { Id = item.Id, EmployeeName = item.EmployeeName, UserIcon = item.UserIcon, Dept_Id = item.Dept_Id, Type = 2 }); UserIdList.Add(item.Id); } } //上级部门下所有子部门的负责人 var d2list = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = 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 = Group_Id, IsLeave = 1, QIds = ManagerIds }); em1List = em1List.Where(x => !UserIdList.Contains(x.Id) && x.Id != Id && x.DirectSupervisor == 0).ToList();//排序 已存在的直接关系 foreach (var item in em1List) { allList.Add(new { Id = item.Id, EmployeeName = item.EmployeeName, UserIcon = item.UserIcon, Dept_Id = item.Dept_Id, Type = 2 }); UserIdList.Add(item.Id); } } } #endregion return allList; } /// /// 获取我所有下级 /// /// /// public List GetOKRMyAllDownlineUserIdList(UserInfo userInfo, int DeptId = 0, int PostId = 0, int leaveStatus = 0) { List UserIdList = new List() { userInfo.Id }; List allList = new List(); #region 我的所有下级(部门层级所有人+直属人) //如果是部门主管 需要将部门下除自己其他人加入 //查询部门负责人 负责的所有部门 var xjdlist = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { DeptId = DeptId, Group_Id = userInfo.Group_Id, ManagerIds = userInfo.Id.ToString() }); if (xjdlist.Any()) { List DeptIdList = new List(); foreach (var item in xjdlist) { //查询出所有的部门 string DeptIds = departmentRepository.GetCurrentAndChildDepartmentIdsRepository(item.DeptId); if (!string.IsNullOrEmpty(DeptIds)) { DeptIdList.AddRange(JsonHelper.DeserializeObject>("[" + DeptIds + "]")); } } //查询该部门下所有人 var em1List = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, QDeptIds = string.Join(",", DeptIdList.Distinct()), Post_Id = PostId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); em1List = em1List.Where(x => x.DirectSupervisor == 0).ToList();//排序 已存在的直接关系 foreach (var item in em1List) { allList.Add(new OKRPersonalDimension() { Id = item.Id, EmployeeName = item.EmployeeName, UserIcon = item.UserIcon, Dept_Id = item.Dept_Id, Type = 2 }); UserIdList.Add(item.Id); } //上级部门下所有子部门的负责人 var d2list = departmentRepository.GetDepartmentListRepository(new Model.ViewModel.User.RB_Department_ViewModel() { Group_Id = userInfo.Group_Id, QDeptIds = string.Join(",", DeptIdList.Distinct()) }); 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, IsLeave = 1, QIds = ManagerIds, Post_Id = PostId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); em1List = em1List.Where(x => !UserIdList.Contains(x.Id) && x.Id != userInfo.Id && x.DirectSupervisor == 0).ToList();//排序 已存在的直接关系 foreach (var item in em1List) { allList.Add(new OKRPersonalDimension() { Id = item.Id, EmployeeName = item.EmployeeName, UserIcon = item.UserIcon, Dept_Id = item.Dept_Id, Type = 2 }); UserIdList.Add(item.Id); } } UserIdList = UserIdList.Distinct().ToList(); //查询这些人的直属人 var emList = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, DirectSupervisorIds = string.Join(",", UserIdList), Dept_Id = DeptId, Post_Id = PostId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); if (emList.Any()) { foreach (var item in emList) { allList.Add(new OKRPersonalDimension() { Id = item.Id, EmployeeName = item.EmployeeName, UserIcon = item.UserIcon, Dept_Id = item.Dept_Id, Type = 2 }); UserIdList.Add(item.Id); } } } else { //非部门负责人 直接查直属 var emList = accountRepository.GetEmployeeListRepository(new Model.ViewModel.User.Employee_ViewModel() { Group_Id = userInfo.Group_Id, IsLeave = 1, DirectSupervisor = userInfo.Id, Dept_Id = DeptId, Post_Id = PostId, LeaveStatus = (Common.Enum.User.LeaveStatusEnum)leaveStatus }); if (emList.Any()) { foreach (var item in emList) { allList.Add(new OKRPersonalDimension() { Id = item.Id, EmployeeName = item.EmployeeName, UserIcon = item.UserIcon, Dept_Id = item.Dept_Id, Type = 2 }); UserIdList.Add(item.Id); } } } #endregion return allList.Distinct().ToList(); } /// /// 获取员工okr列表 /// /// /// /// /// /// public List GetAllEmployeeOKRPPageRepository(int pageIndex, int pageSize, out long rowsCount, OKRPersonalDimension query) { return oKR_ObjectiveRepository.GetAllEmployeeOKRPPageRepository(pageIndex, pageSize, out rowsCount, query); } /// /// 获取员工okr列表 /// /// /// /// /// /// public List GetAllEmployeeOKRPList(OKRPersonalDimension query) { return oKR_ObjectiveRepository.GetAllEmployeeOKRPList(query); } #endregion } }