Commit c319529e authored by liudong1993's avatar liudong1993

OKR

parent c6b4c45a
......@@ -845,14 +845,14 @@ namespace Edu.Module.OKR
}
else {
int Sort = oKR_KeyResultRepository.GetKeyResultMaxSort(objectiveId);
int Weight = 100;
decimal Weight = 100;
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 = 100 / (list.Count() + 1);
Weight = Convert.ToDecimal((int)((Convert.ToDecimal(100) / (list.Count() + 1)) * 10)) / 10;
IsUpdate = true;
}
else {
......@@ -883,10 +883,16 @@ namespace Edu.Module.OKR
});
if (Id > 0) {
if (IsUpdate) {
decimal diff = 0;
int MaxSort = 0;
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>() {
{ 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>() {
new WhereHelper(){
......@@ -1293,13 +1299,385 @@ namespace Edu.Module.OKR
/// <returns></returns>
public ApiResult SgetOKRMyKeyResultProgress(int keyResultId, int type, int progress, decimal startValue, decimal endValue, decimal currentValue, UserInfo userInfo)
{
if (type == 1) {
var model = oKR_KeyResultRepository.GetEntity(keyResultId);
if (model == null || model.Status == 1) {
return ApiResult.Failed("关键结果不存在");
}
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);
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
});
}
}
return ApiResult.Failed();
}
/// <summary>
/// 设置结果权重
/// </summary>
/// <param name="keyResultId"></param>
/// <param name="weight"></param>
/// <param name="userInfo"></param>
/// <returns></returns>
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();
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();
}
return ApiResult.Success();
/// <summary>
/// 设置结果分数
/// </summary>
/// <param name="keyResultId"></param>
/// <param name="score"></param>
/// <param name="userInfo"></param>
/// <returns></returns>
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<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>
/// <param name="keyResultId"></param>
/// <param name="userInfo"></param>
/// <returns></returns>
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<string, object> keyValues = new Dictionary<string, object>
{
{ nameof(RB_OKR_KeyResult_ViewModel.Status), 1 },
{ nameof(RB_OKR_KeyResult_ViewModel.UpdateBy), userInfo.Id },
{ nameof(RB_OKR_KeyResult_ViewModel.UpdateTime), DateTime.Now }
};
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)
{
//删除 需要重新分配权重,目标进度,目标评分
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 {
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
}
......
......@@ -372,6 +372,15 @@ namespace Edu.WebApi.Controllers.OKR
return ApiResult.Success("", list);
}
/// <summary>
/// 获取单个我的目标
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetOKRMyObjectiveInfo() {
}
/// <summary>
/// 新增修改目标
/// </summary>
......@@ -530,7 +539,7 @@ namespace Edu.WebApi.Controllers.OKR
var userInfo = base.UserInfo;
JObject parms = JObject.Parse(RequestParm.Msg.ToString());
int KeyResultId = parms.GetInt("KeyResultId", 0);
int Type = parms.GetInt("Type", 0);// 类型 1自定义状态 2删除 3切换为简单模式 4切换为高级模式
int Type = parms.GetInt("Type", 0);// 类型 1自定义状态 2删除(作废) 3切换为简单模式 4切换为高级模式
string ProgressState = parms.GetStringValue("ProgressState");
if (KeyResultId <= 0)
{
......@@ -567,9 +576,75 @@ namespace Edu.WebApi.Controllers.OKR
{
return ApiResult.ParamIsNull();
}
if (Progress < 0 || StartValue < 0 || EndValue < 0 || CurrentValue < 0)
{
return ApiResult.ParamIsNull("不能小于0");
}
return okrPeriodModule.SgetOKRMyKeyResultProgress(KeyResultId, Type, Progress, StartValue, EndValue, CurrentValue, userInfo);
}
/// <summary>
/// 修改目标关键结果权重
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult SgetOKRMyKeyResultWeight() {
var userInfo = base.UserInfo;
JObject parms = JObject.Parse(RequestParm.Msg.ToString());
int KeyResultId = parms.GetInt("KeyResultId", 0);
decimal Weight = parms.GetDecimal("Weight");
if (KeyResultId <= 0) {
return ApiResult.ParamIsNull("请传递结果Id");
}
if (Weight < 0 || Weight > 100) {
return ApiResult.ParamIsNull("权重值有误");
}
return okrPeriodModule.SgetOKRMyKeyResultWeight(KeyResultId, Weight, userInfo);
}
/// <summary>
/// 修改目标关键结果分数
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult SgetOKRMyKeyResultScore() {
var userInfo = base.UserInfo;
JObject parms = JObject.Parse(RequestParm.Msg.ToString());
int KeyResultId = parms.GetInt("KeyResultId", 0);
decimal Score = parms.GetDecimal("Score");
if (KeyResultId <= 0)
{
return ApiResult.ParamIsNull("请传递结果Id");
}
if (Score < 0 || Score > 1)
{
return ApiResult.ParamIsNull("分值有误");
}
return okrPeriodModule.SgetOKRMyKeyResultScore(KeyResultId, Score, userInfo);
}
/// <summary>
/// 删除关键结果状态
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult SgetOKRMyKeyResultDel()
{
var userInfo = base.UserInfo;
JObject parms = JObject.Parse(RequestParm.Msg.ToString());
int KeyResultId = parms.GetInt("KeyResultId", 0);
if (KeyResultId <= 0)
{
return ApiResult.ParamIsNull();
}
return okrPeriodModule.SgetOKRMyKeyResultDel(KeyResultId, userInfo);
}
//权限 添加对齐 审核 评论 左边人员列表 对齐视图 数据看板 (管理员版 对齐视图 数据看板)
#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