Commit e1d3a86d by 李承祥

保底绩效优先级

parent baa36331
......@@ -43,6 +43,14 @@ public List<cof_guarantee> Guarantee(int allotId)
/// <returns></returns>
public cof_guarantee GuarantInsert(GuaranteeRequest request)
{
var list = perforCofguaranteeRepository.GetEntities(t => t.AllotId == request.AllotId);
if (list != null)
{
var config = list.FirstOrDefault(t => t.Priority == request.Priority && t.UnitType == request.UnitType && t.Target != request.Target);
if (config != null)
throw new PerformanceException("优先级无效,已存在");
}
var guarantee = Mapper.Map<cof_guarantee>(request);
perforCofguaranteeRepository.Add(guarantee);
return guarantee;
......@@ -59,8 +67,27 @@ public cof_guarantee GuarantUpdate(GuaranteeRequest request)
if (guarantee == null)
throw new PerformanceException("request.Id 参数错误");
guarantee.UnitType = request.UnitType;
if (guarantee.Priority > request.Priority)
{
var list = perforCofguaranteeRepository.GetEntities(t => t.AllotId == guarantee.AllotId && t.UnitType == request.UnitType && t.Priority >= request.Priority && t.Priority < guarantee.Priority);
if (list != null && list.Any())
{
list?.ForEach(t => { t.Priority = t.Priority + 1; });
perforCofguaranteeRepository.UpdateRange(list.ToArray());
}
}
else if (guarantee.Priority < request.Priority)
{
var list = perforCofguaranteeRepository.GetEntities(t => t.AllotId == guarantee.AllotId && t.UnitType == request.UnitType && t.Priority <= request.Priority && t.Priority > guarantee.Priority);
if (list != null && list.Any())
{
list.ForEach(t => { t.Priority = t.Priority - 1; });
perforCofguaranteeRepository.UpdateRange(list.ToArray());
}
}
guarantee.Priority = request.Priority;
guarantee.UnitType = request.UnitType;
guarantee.Target = request.Target;
guarantee.Source = request.Source;
if (!perforCofguaranteeRepository.Update(guarantee))
......@@ -101,6 +128,16 @@ public List<TitleValue> Accounting(int allotId)
}
return result;
}
/// <summary>
/// 获取优先级
/// </summary>
/// <param name="allotId"></param>
/// <returns></returns>
public int Priority(int allotId, int unitType, string target)
{
return perforCofguaranteeRepository.GetEntity(t => t.AllotId == allotId && t.UnitType == unitType && t.Target == target)?.Priority ?? 0;
}
#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