Commit 9031d6a1 authored by 吴春's avatar 吴春

解决冲突

parents 5b726456 dc4ef83f
...@@ -104,8 +104,7 @@ namespace Edu.Module.OKR ...@@ -104,8 +104,7 @@ namespace Edu.Module.OKR
} }
}; };
bool flag = oKR_PeriodConfigRepository.Update(keyValues, wheres); bool flag = oKR_PeriodConfigRepository.Update(keyValues, wheres);
if (flag) if (flag) {
{
//记录日志 //记录日志
changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
{ {
...@@ -121,17 +120,14 @@ namespace Edu.Module.OKR ...@@ -121,17 +120,14 @@ namespace Edu.Module.OKR
} }
return flag ? "" : "失败了,请联系管理"; return flag ? "" : "失败了,请联系管理";
} }
else else {
{
//验证是否存在 //验证是否存在
var model = oKR_PeriodConfigRepository.GetList(new RB_OKR_PeriodConfig_ViewModel() { Group_Id = userInfo.Group_Id }).FirstOrDefault(); var model = oKR_PeriodConfigRepository.GetList(new RB_OKR_PeriodConfig_ViewModel() { Group_Id = userInfo.Group_Id }).FirstOrDefault();
if (model != null) if (model != null) {
{
return "已存在配置"; return "已存在配置";
} }
bool flag = oKR_PeriodConfigRepository.Insert(dmodel) > 0; bool flag = oKR_PeriodConfigRepository.Insert(dmodel) > 0;
if (flag) if (flag) {
{
//生成对应期数 //生成对应期数
oKR_PeriodRepository.Insert(new Model.Entity.OKR.RB_OKR_Period() oKR_PeriodRepository.Insert(new Model.Entity.OKR.RB_OKR_Period()
{ {
...@@ -148,8 +144,7 @@ namespace Edu.Module.OKR ...@@ -148,8 +144,7 @@ namespace Edu.Module.OKR
UpdateBy = dmodel.UpdateBy, UpdateBy = dmodel.UpdateBy,
UpdateTime = DateTime.Now UpdateTime = DateTime.Now
}); });
if (dmodel.YearOKR == 1) if (dmodel.YearOKR == 1) {
{
//今年 //今年
oKR_PeriodRepository.Insert(new Model.Entity.OKR.RB_OKR_Period() oKR_PeriodRepository.Insert(new Model.Entity.OKR.RB_OKR_Period()
{ {
...@@ -208,11 +203,9 @@ namespace Edu.Module.OKR ...@@ -208,11 +203,9 @@ namespace Edu.Module.OKR
public List<RB_OKR_Remind_ViewModel> GetOKRRemindList(int group_Id) public List<RB_OKR_Remind_ViewModel> GetOKRRemindList(int group_Id)
{ {
var list = oKR_RemindRepository.GetList(new RB_OKR_Remind_ViewModel() { Group_Id = group_Id }); var list = oKR_RemindRepository.GetList(new RB_OKR_Remind_ViewModel() { Group_Id = group_Id });
for (var i = 1; i <= 4; i++) for (var i = 1; i <= 4; i++) {
{
var model = list.Where(x => x.Type == i).FirstOrDefault(); var model = list.Where(x => x.Type == i).FirstOrDefault();
if (model == null) if (model == null) {
{
list.Add(new RB_OKR_Remind_ViewModel() list.Add(new RB_OKR_Remind_ViewModel()
{ {
Days = "", Days = "",
...@@ -253,8 +246,7 @@ namespace Edu.Module.OKR ...@@ -253,8 +246,7 @@ namespace Edu.Module.OKR
} }
return flag ? "" : "出错啦,请联系管理员"; return flag ? "" : "出错啦,请联系管理员";
} }
else else {
{
Dictionary<string, object> keyValues = new Dictionary<string, object>() { Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_OKR_Remind_ViewModel.Days),dmodel.Days}, { nameof(RB_OKR_Remind_ViewModel.Days),dmodel.Days},
{ nameof(RB_OKR_Remind_ViewModel.Time),dmodel.Time}, { nameof(RB_OKR_Remind_ViewModel.Time),dmodel.Time},
...@@ -269,8 +261,7 @@ namespace Edu.Module.OKR ...@@ -269,8 +261,7 @@ namespace Edu.Module.OKR
} }
}; };
bool flag = oKR_RemindRepository.Update(keyValues, wheres); bool flag = oKR_RemindRepository.Update(keyValues, wheres);
if (flag) if (flag) {
{
//记录日志 //记录日志
changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
{ {
...@@ -301,8 +292,7 @@ namespace Edu.Module.OKR ...@@ -301,8 +292,7 @@ namespace Edu.Module.OKR
{ {
return false; return false;
} }
else else {
{
Dictionary<string, object> keyValues = new Dictionary<string, object>() { Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_OKR_Remind_ViewModel.Enable),model.Enable == 1 ? 2 : 1} { nameof(RB_OKR_Remind_ViewModel.Enable),model.Enable == 1 ? 2 : 1}
}; };
...@@ -344,17 +334,15 @@ namespace Edu.Module.OKR ...@@ -344,17 +334,15 @@ namespace Edu.Module.OKR
public List<RB_OKR_Score_ViewModel> GetOKRScoreConfigPageList(int pageIndex, int pageSize, out long count, RB_OKR_Score_ViewModel dmodel) public List<RB_OKR_Score_ViewModel> GetOKRScoreConfigPageList(int pageIndex, int pageSize, out long count, RB_OKR_Score_ViewModel dmodel)
{ {
var list = oKR_ScoreRepository.GetPageList(pageIndex, pageSize, out count, dmodel); var list = oKR_ScoreRepository.GetPageList(pageIndex, pageSize, out count, dmodel);
if (list.Any()) if (list.Any()) {
{
string ids = string.Join(",", list.Select(x => x.Id)); string ids = string.Join(",", list.Select(x => x.Id));
var dlist = oKR_ScoreDetailRepository.GetList(new RB_OKR_ScoreDetail_ViewModel() { ScoreIds = ids }); var dlist = oKR_ScoreDetailRepository.GetList(new RB_OKR_ScoreDetail_ViewModel() { ScoreIds = ids });
foreach (var item in list) foreach (var item in list) {
{
item.DetailList = dlist.Where(x => x.ScoreId == item.Id).ToList(); item.DetailList = dlist.Where(x => x.ScoreId == item.Id).ToList();
} }
} }
return list; return list;
} }
/// <summary> /// <summary>
/// 保存分数配置 /// 保存分数配置
...@@ -377,8 +365,7 @@ namespace Edu.Module.OKR ...@@ -377,8 +365,7 @@ namespace Edu.Module.OKR
} }
}; };
bool flag = oKR_ScoreRepository.Update(keyValues, wheres); bool flag = oKR_ScoreRepository.Update(keyValues, wheres);
if (flag) if (flag) {
{
var list = oKR_ScoreDetailRepository.GetList(new RB_OKR_ScoreDetail_ViewModel() { ScoreId = dmodel.Id }); var list = oKR_ScoreDetailRepository.GetList(new RB_OKR_ScoreDetail_ViewModel() { ScoreId = dmodel.Id });
//删除后 再新增 //删除后 再新增
oKR_ScoreDetailRepository.DeleteBatch(list); oKR_ScoreDetailRepository.DeleteBatch(list);
...@@ -402,18 +389,16 @@ namespace Edu.Module.OKR ...@@ -402,18 +389,16 @@ namespace Edu.Module.OKR
CreateBy = userInfo.Id, CreateBy = userInfo.Id,
CreateTime = DateTime.Now, CreateTime = DateTime.Now,
Group_Id = userInfo.Group_Id, Group_Id = userInfo.Group_Id,
LogContent = "修改OKR分数配置【" + dmodel.Id + "】", LogContent = "修改OKR分数配置【"+dmodel.Id+"】",
School_Id = userInfo.School_Id, School_Id = userInfo.School_Id,
SourceId = 0 SourceId = 0
}); });
} }
return flag ? "" : "出错了,请联系管理员"; return flag ? "" : "出错了,请联系管理员";
} }
else else {
{
int Id = oKR_ScoreRepository.Insert(dmodel); int Id = oKR_ScoreRepository.Insert(dmodel);
if (Id > 0) if (Id > 0) {
{
//增加明细 //增加明细
foreach (var item in dmodel.DetailList) foreach (var item in dmodel.DetailList)
{ {
...@@ -435,14 +420,14 @@ namespace Edu.Module.OKR ...@@ -435,14 +420,14 @@ namespace Edu.Module.OKR
CreateBy = userInfo.Id, CreateBy = userInfo.Id,
CreateTime = DateTime.Now, CreateTime = DateTime.Now,
Group_Id = userInfo.Group_Id, Group_Id = userInfo.Group_Id,
LogContent = "新增OKR分数配置【" + Id + "】", LogContent = "新增OKR分数配置【"+Id+"】",
School_Id = userInfo.School_Id, School_Id = userInfo.School_Id,
SourceId = 0 SourceId = 0
}); });
} }
return Id > 0 ? "" : "出错了,请联系管理员"; return Id > 0 ? "" : "出错了,请联系管理员";
} }
} }
/// <summary> /// <summary>
/// 设置分数配置状态 /// 设置分数配置状态
...@@ -513,8 +498,7 @@ namespace Edu.Module.OKR ...@@ -513,8 +498,7 @@ namespace Edu.Module.OKR
} }
return flag ? "" : "出错了,请联系管理员"; return flag ? "" : "出错了,请联系管理员";
} }
else else {
{
return "类型不正确"; return "类型不正确";
} }
} }
...@@ -533,8 +517,7 @@ namespace Edu.Module.OKR ...@@ -533,8 +517,7 @@ namespace Edu.Module.OKR
foreach (var item in list) foreach (var item in list)
{ {
item.IsCurrent = 2; item.IsCurrent = 2;
if (item.StartDate <= DateTime.Now && item.EndDate >= DateTime.Now) if (item.StartDate <= DateTime.Now && item.EndDate >= DateTime.Now) {
{
item.IsCurrent = 1; item.IsCurrent = 1;
} }
} }
...@@ -550,8 +533,7 @@ namespace Edu.Module.OKR ...@@ -550,8 +533,7 @@ namespace Edu.Module.OKR
public object GetOKRMyObjectiveList(int PeriodId, UserInfo userInfo) 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 }); var list = oKR_ObjectiveRepository.GetList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, CreateBy = userInfo.Id });
if (list.Any()) if (list.Any()) {
{
string objectiveIds = string.Join(",", list.Select(x => x.Id)); 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 sdqlist = oKR_ObjectiveRepository.GetParentList(new RB_OKR_Objective_ViewModel() { Group_Id = userInfo.Group_Id, PeriodId = PeriodId, ObjectiveIds = objectiveIds });
...@@ -610,8 +592,7 @@ namespace Edu.Module.OKR ...@@ -610,8 +592,7 @@ namespace Edu.Module.OKR
item.IsLock = 1; item.IsLock = 1;
} }
} }
foreach (var item in list) foreach (var item in list) {
{
item.IsLock = 2; item.IsLock = 2;
if (pList.Where(x => x.ObjectiveId == item.Id).Any()) if (pList.Where(x => x.ObjectiveId == item.Id).Any())
{ {
...@@ -619,8 +600,7 @@ namespace Edu.Module.OKR ...@@ -619,8 +600,7 @@ namespace Edu.Module.OKR
} }
//结果列表 //结果列表
item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList(); item.KeyResultList = krList.Where(x => x.ObjectiveId == item.Id).ToList();
if (item.IsDefaultState == 1) if (item.IsDefaultState == 1) {
{
item.ProgressState = item.KeyResultList.Max(x => x.ProgressState); item.ProgressState = item.KeyResultList.Max(x => x.ProgressState);
} }
...@@ -628,8 +608,7 @@ namespace Edu.Module.OKR ...@@ -628,8 +608,7 @@ namespace Edu.Module.OKR
var sdqclist = sdqlist.Where(x => x.ObjectiveId == item.Id).ToList(); var sdqclist = sdqlist.Where(x => x.ObjectiveId == item.Id).ToList();
List<int> EmIdList = sdqclist.Select(x => x.CreateBy).Distinct().ToList(); List<int> EmIdList = sdqclist.Select(x => x.CreateBy).Distinct().ToList();
item.ParentList = new List<ObjectiveEmployeeModel>(); item.ParentList = new List<ObjectiveEmployeeModel>();
foreach (var qitem in EmIdList) foreach (var qitem in EmIdList) {
{
item.ParentList.Add(new ObjectiveEmployeeModel() item.ParentList.Add(new ObjectiveEmployeeModel()
{ {
AccountId = qitem, AccountId = qitem,
...@@ -769,8 +748,7 @@ namespace Edu.Module.OKR ...@@ -769,8 +748,7 @@ namespace Edu.Module.OKR
} }
}; };
bool flag = oKR_ObjectiveRepository.Update(keyValues, wheres); bool flag = oKR_ObjectiveRepository.Update(keyValues, wheres);
if (flag) if (flag) {
{
changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
{ {
Id = 0, Id = 0,
...@@ -785,8 +763,7 @@ namespace Edu.Module.OKR ...@@ -785,8 +763,7 @@ namespace Edu.Module.OKR
} }
return flag ? "" : "出错了,请联系管理员"; return flag ? "" : "出错了,请联系管理员";
} }
else else {
{
dmodel.Status = 4; dmodel.Status = 4;
dmodel.Sort = oKR_ObjectiveRepository.GetObjectiveMaxSort(userInfo.Group_Id, dmodel.PeriodId, userInfo.Id) + 1;//获取 当前最大的 dmodel.Sort = oKR_ObjectiveRepository.GetObjectiveMaxSort(userInfo.Group_Id, dmodel.PeriodId, userInfo.Id) + 1;//获取 当前最大的
dmodel.ScoreRuleId = 0;//获取 是否有默认 dmodel.ScoreRuleId = 0;//获取 是否有默认
...@@ -809,8 +786,7 @@ namespace Edu.Module.OKR ...@@ -809,8 +786,7 @@ namespace Edu.Module.OKR
dmodel.UpdateTime = DateTime.Now; dmodel.UpdateTime = DateTime.Now;
int Id = oKR_ObjectiveRepository.Insert(dmodel); int Id = oKR_ObjectiveRepository.Insert(dmodel);
if (Id > 0) if (Id > 0) {
{
changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
{ {
Id = 0, Id = 0,
...@@ -852,8 +828,7 @@ namespace Edu.Module.OKR ...@@ -852,8 +828,7 @@ namespace Edu.Module.OKR
} }
}; };
bool flag = oKR_KeyResultRepository.Update(keyValues, wheres); bool flag = oKR_KeyResultRepository.Update(keyValues, wheres);
if (flag) if (flag) {
{
changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
{ {
Id = 0, Id = 0,
...@@ -868,22 +843,19 @@ namespace Edu.Module.OKR ...@@ -868,22 +843,19 @@ namespace Edu.Module.OKR
} }
return flag ? "" : "出错了,请联系管理员"; return flag ? "" : "出错了,请联系管理员";
} }
else else {
{
int Sort = oKR_KeyResultRepository.GetKeyResultMaxSort(objectiveId); int Sort = oKR_KeyResultRepository.GetKeyResultMaxSort(objectiveId);
int Weight = 100; decimal Weight = 100;
bool IsUpdate = false; bool IsUpdate = false;
var list = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveId = objectiveId }); var list = oKR_KeyResultRepository.GetList(new RB_OKR_KeyResult_ViewModel() { Group_Id = userInfo.Group_Id, ObjectiveId = objectiveId });
if (list.Any()) if (list.Any()) {
{
if (list.Select(x => x.Weight).Distinct().Count() == 1) if (list.Select(x => x.Weight).Distinct().Count() == 1)
{ {
//说明权重一致 平摊到每个结果里 //说明权重一致 平摊到每个结果里
Weight = 100 / (list.Count() + 1); Weight = Convert.ToDecimal((int)((Convert.ToDecimal(100) / (list.Count() + 1)) * 10)) / 10;
IsUpdate = true; IsUpdate = true;
} }
else else {
{
Weight = 0; Weight = 0;
} }
} }
...@@ -909,15 +881,18 @@ namespace Edu.Module.OKR ...@@ -909,15 +881,18 @@ namespace Edu.Module.OKR
UpdateTime = DateTime.Now, UpdateTime = DateTime.Now,
Weight = Weight Weight = Weight
}); });
if (Id > 0) if (Id > 0) {
{ if (IsUpdate) {
if (IsUpdate) decimal diff = 0;
{ int MaxSort = 0;
foreach (var item in list) if (list.Count() * Weight != 100) {
{ diff = 100 - list.Count() * Weight;
//修改每个结果的权重 MaxSort = list.Max(x => x.Sort);
}
foreach (var item in list) {
//修改每个结果的权重
Dictionary<string, object> keyValues = new Dictionary<string, object>() { Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_OKR_KeyResult_ViewModel.Weight),Weight} { nameof(RB_OKR_KeyResult_ViewModel.Weight),(diff > 0 && MaxSort == item.Sort)? Weight + diff : Weight}
}; };
List<WhereHelper> wheres = new List<WhereHelper>() { List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){ new WhereHelper(){
...@@ -1013,8 +988,7 @@ namespace Edu.Module.OKR ...@@ -1013,8 +988,7 @@ namespace Edu.Module.OKR
} }
}; };
bool flag = oKR_ObjectiveRepository.Update(keyValues, wheres); bool flag = oKR_ObjectiveRepository.Update(keyValues, wheres);
if (flag) if (flag) {
{
//在这个范围里面的 Sort+1 //在这个范围里面的 Sort+1
oKR_ObjectiveRepository.UpdateOtherSort(objectModel1.PeriodId, objectModel1.CreateBy, objectModel1.Id, objectModel2.Sort, objectModel1.Sort); oKR_ObjectiveRepository.UpdateOtherSort(objectModel1.PeriodId, objectModel1.CreateBy, objectModel1.Id, objectModel2.Sort, objectModel1.Sort);
changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
...@@ -1217,8 +1191,7 @@ namespace Edu.Module.OKR ...@@ -1217,8 +1191,7 @@ namespace Edu.Module.OKR
keyValues.Add(nameof(RB_OKR_Objective_ViewModel.UpdateTime), DateTime.Now); keyValues.Add(nameof(RB_OKR_Objective_ViewModel.UpdateTime), DateTime.Now);
LogContent = "删除OKR目标【" + objectiveId + "】"; LogContent = "删除OKR目标【" + objectiveId + "】";
} }
else else {
{
return "类型不正确"; return "类型不正确";
} }
List<WhereHelper> wheres = new List<WhereHelper>() { List<WhereHelper> wheres = new List<WhereHelper>() {
...@@ -1229,8 +1202,7 @@ namespace Edu.Module.OKR ...@@ -1229,8 +1202,7 @@ namespace Edu.Module.OKR
} }
}; };
bool flag = oKR_ObjectiveRepository.Update(keyValues, wheres); bool flag = oKR_ObjectiveRepository.Update(keyValues, wheres);
if (flag) if (flag) {
{
changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog() changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
{ {
Id = 0, Id = 0,
...@@ -1286,8 +1258,7 @@ namespace Edu.Module.OKR ...@@ -1286,8 +1258,7 @@ namespace Edu.Module.OKR
keyValues.Add(nameof(RB_OKR_KeyResult_ViewModel.UpdateTime), DateTime.Now); keyValues.Add(nameof(RB_OKR_KeyResult_ViewModel.UpdateTime), DateTime.Now);
LogContent = "修改OKR目标关键结果进度为高级模式【" + keyResultId + "】"; LogContent = "修改OKR目标关键结果进度为高级模式【" + keyResultId + "】";
} }
else else {
{
return "类型不正确"; return "类型不正确";
} }
List<WhereHelper> wheres = new List<WhereHelper>() { List<WhereHelper> wheres = new List<WhereHelper>() {
...@@ -1328,69 +1299,384 @@ namespace Edu.Module.OKR ...@@ -1328,69 +1299,384 @@ namespace Edu.Module.OKR
/// <returns></returns> /// <returns></returns>
public ApiResult SgetOKRMyKeyResultProgress(int keyResultId, int type, int progress, decimal startValue, decimal endValue, decimal currentValue, UserInfo userInfo) public ApiResult SgetOKRMyKeyResultProgress(int keyResultId, int type, int progress, decimal startValue, decimal endValue, decimal currentValue, UserInfo userInfo)
{ {
var model = oKR_KeyResultRepository.GetEntity(keyResultId);
if (model == null || model.Status == 1) {
return ApiResult.Failed("关键结果不存在");
}
if (type == 1) if (type == 1)
{ {
//根据进度 求高级的当前值
currentValue = Math.Round((model.EndValue - model.StartValue) * progress / 100, 2, MidpointRounding.AwayFromZero) + model.StartValue;
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_OKR_KeyResult_ViewModel.Progress),progress},
{ nameof(RB_OKR_KeyResult_ViewModel.CurrentValue),currentValue},
};
List<WhereHelper> wheres = new List<WhereHelper>() {
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 TProgress = list.Sum(x => x.Progress * x.Weight / 100);
Dictionary<string, object> keyValues1 = new Dictionary<string, object>() {
{ nameof(RB_OKR_Objective_ViewModel.Progress),(int)TProgress}
};
List<WhereHelper> wheres1 = new List<WhereHelper>() {
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 + "】",
School_Id = userInfo.School_Id,
SourceId = 0
});
return ApiResult.Success("", new
{
TProgress =(int)TProgress,
CProgress = progress,
model.StartValue,
model.EndValue,
currentValue
});
}
} }
else {
//根据当前值 求进度
progress = (int)(((currentValue - startValue) / (endValue - startValue)) * 100);
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ 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<WhereHelper> wheres = new List<WhereHelper>() {
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 TProgress = list.Sum(x => x.Progress * x.Weight / 100);
Dictionary<string, object> keyValues1 = new Dictionary<string, object>() {
{ nameof(RB_OKR_Objective_ViewModel.Progress),(int)TProgress}
};
List<WhereHelper> wheres1 = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_OKR_Objective_ViewModel.Id),
FiledValue=model.ObjectiveId,
OperatorEnum=OperatorEnum.Equal
}
};
oKR_ObjectiveRepository.Update(keyValues1, wheres1);
return ApiResult.Success(); changeLogRepository.Insert(new Model.Entity.Log.RB_User_ChangeLog()
} {
Id = 0,
#endregion 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 = (int)TProgress,
CProgress = progress,
model.StartValue,
model.EndValue,
currentValue
});
}
}
#region okr 任务评论 return ApiResult.Failed();
}
/// <summary> /// <summary>
/// 获取评论分页列表 /// 设置结果权重
/// </summary> /// </summary>
/// <param name="pageIndex"></param> /// <param name="keyResultId"></param>
/// <param name="pageSize"></param> /// <param name="weight"></param>
/// <param name="rowsCount"></param> /// <param name="userInfo"></param>
/// <param name="demodel"></param>
/// <returns></returns> /// <returns></returns>
public List<RB_OKR_Comment_ViewModel> GetCommentPageList(int pageIndex, int pageSize, out long rowsCount, RB_OKR_Comment_ViewModel demodel) public ApiResult SgetOKRMyKeyResultWeight(int keyResultId, decimal weight, UserInfo userInfo)
{ {
return oKR_CommentRepository.GetPageList(pageIndex, pageSize, out rowsCount, demodel); 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();
if (model.Sort == MaxSort) {
return ApiResult.Failed("最后一个KeyResult无法修改权重");
}
if (weight - model.Weight > MaxModel.Weight){
return ApiResult.Failed("总权重不能超过100%");
}
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_OKR_KeyResult_ViewModel.Weight),weight}
};
List<WhereHelper> wheres = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_OKR_KeyResult_ViewModel.Id),
FiledValue=keyResultId,
OperatorEnum=OperatorEnum.Equal
}
};
bool flag = oKR_KeyResultRepository.Update(keyValues, wheres);
if (flag) {
//更新最后一个KeyResult权重
Dictionary<string, object> keyValues1 = new Dictionary<string, object>() {
{ nameof(RB_OKR_KeyResult_ViewModel.Weight), MaxModel.Weight - (weight - model.Weight)}
};
List<WhereHelper> wheres1 = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_OKR_KeyResult_ViewModel.Id),
FiledValue=MaxModel.Id,
OperatorEnum=OperatorEnum.Equal
}
};
oKR_KeyResultRepository.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 + "】",
School_Id = userInfo.School_Id,
SourceId = 0
});
return ApiResult.Success("", new
{
Weight = weight,
LastWeight = MaxModel.Weight - (weight - model.Weight)
});
}
return ApiResult.Failed();
} }
/// <summary> /// <summary>
/// 获取评论列表 /// 设置结果分数
/// </summary> /// </summary>
/// <param name="demodel"></param> /// <param name="keyResultId"></param>
/// <param name="score"></param>
/// <param name="userInfo"></param>
/// <returns></returns> /// <returns></returns>
public List<RB_OKR_Comment_ViewModel> GetCommentList(RB_OKR_Comment_ViewModel demodel) public ApiResult SgetOKRMyKeyResultScore(int keyResultId, decimal score, UserInfo userInfo)
{ {
return oKR_CommentRepository.GetList(demodel); var model = oKR_KeyResultRepository.GetEntity(keyResultId);
} if (model == null || model.Status == 1){
return ApiResult.Failed("关键结果不存在");
}
if (model.Score == score){
return ApiResult.Success();
}
Dictionary<string, object> keyValues = new Dictionary<string, object>() {
{ nameof(RB_OKR_KeyResult_ViewModel.Score),score}
};
List<WhereHelper> wheres = new List<WhereHelper>() {
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 = list.Sum(x => x.Score * x.Weight / 100);
Dictionary<string, object> keyValues1 = new Dictionary<string, object>() {
{ nameof(RB_OKR_Objective_ViewModel.Score),(int)TScore}
};
List<WhereHelper> wheres1 = new List<WhereHelper>() {
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 + "】",
School_Id = userInfo.School_Id,
SourceId = 0
});
return ApiResult.Success("", new
{
Score = score,
TScore
});
}
return ApiResult.Failed();
}
/// <summary> /// <summary>
/// 新增/修改ork评论 /// 删除结果
/// </summary> /// </summary>
/// <param name="model"></param> /// <param name="keyResultId"></param>
/// <param name="userInfo"></param>
/// <returns></returns> /// <returns></returns>
public bool SetOKRComment(RB_OKR_Comment_ViewModel model) public ApiResult SgetOKRMyKeyResultDel(int keyResultId, UserInfo userInfo)
{ {
if (model.Id == 0) var model = oKR_KeyResultRepository.GetEntity(keyResultId);
{ if (model == null || model.Status == 1){
return oKR_CommentRepository.Insert(model) > 0; return ApiResult.Failed("关键结果不存在");
} }
else 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<string, object> keyValues = new Dictionary<string, object>
{ {
Dictionary<string, object> keyValues = new Dictionary<string, object>() { { nameof(RB_OKR_KeyResult_ViewModel.Status), 1 },
{ nameof(RB_OKR_Comment_ViewModel.State),model.State}, { nameof(RB_OKR_KeyResult_ViewModel.UpdateBy), userInfo.Id },
{ nameof(RB_OKR_Comment_ViewModel.UpdateBy),model.UpdateBy}, { nameof(RB_OKR_KeyResult_ViewModel.UpdateTime), DateTime.Now }
{ nameof(RB_OKR_Comment_ViewModel.UpdateTime),DateTime.Now}, };
}; List<WhereHelper> wheres = new List<WhereHelper>() {
List<WhereHelper> wheres = new List<WhereHelper>() { new WhereHelper(){
new WhereHelper(){ FiledName= nameof(RB_OKR_KeyResult_ViewModel.Id),
FiledName=nameof(RB_OKR_Comment_ViewModel.Id), FiledValue=keyResultId,
FiledValue=model.Id, OperatorEnum=OperatorEnum.Equal
OperatorEnum=OperatorEnum.Equal }
};
bool flag = oKR_KeyResultRepository.Update(keyValues, wheres);
if (flag)
{
//删除 需要重新分配权重,目标进度,目标评分
decimal Progress = 0;
decimal Score = 0;
decimal Weight = 0;
if (list.Count() == 1)
{
//删完了,直接初始化 目标
Dictionary<string, object> keyValues1 = new Dictionary<string, object>() {
{ nameof(RB_OKR_Objective_ViewModel.Progress),Progress},
{ nameof(RB_OKR_Objective_ViewModel.Score),Score}
};
List<WhereHelper> wheres1 = new List<WhereHelper>() {
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<string, object> keyValues1 = new Dictionary<string, object>() {
{ nameof(RB_OKR_Objective_ViewModel.Progress),(int)Progress},
{ nameof(RB_OKR_Objective_ViewModel.Score),Score}
};
List<WhereHelper> wheres1 = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_OKR_Objective_ViewModel.Id),
FiledValue=model.ObjectiveId,
OperatorEnum=OperatorEnum.Equal
}
};
oKR_ObjectiveRepository.Update(keyValues1, wheres1);
#endregion
//删除的如果是最后一个 权重转移至倒数第二个
//删除的弱国不是最后一个 权重转移至最后一个
if (model.Sort == MaxSort)
{
//查询倒数第二个
var TwoModel = list.Where(x => x.Sort != MaxSort).OrderByDescending(x => x.Sort).FirstOrDefault();
Weight = TwoModel.Weight + model.Weight;
Dictionary<string, object> keyValues2 = new Dictionary<string, object>() {
{ nameof(RB_OKR_KeyResult_ViewModel.Weight), Weight}
};
List<WhereHelper> wheres2 = new List<WhereHelper>() {
new WhereHelper(){
FiledName=nameof(RB_OKR_KeyResult_ViewModel.Id),
FiledValue=TwoModel.Id,
OperatorEnum=OperatorEnum.Equal
}
};
oKR_KeyResultRepository.Update(keyValues2, wheres2);
} }
}; else {
return oKR_CommentRepository.Update(keyValues, wheres); var LastModel = list.Where(x => x.Sort == MaxSort).FirstOrDefault();
Weight = LastModel.Weight + model.Weight;
Dictionary<string, object> keyValues2 = new Dictionary<string, object>() {
{ nameof(RB_OKR_KeyResult_ViewModel.Weight), Weight}
};
List<WhereHelper> wheres2 = new List<WhereHelper>() {
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,
LastWeight = Weight
});
} }
return ApiResult.Failed();
} }
#endregion #endregion
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment