Commit f0a35d36 by 李承祥

保底绩效接口修改

parent c0e36e2c
......@@ -41,12 +41,13 @@ public ApiResponse<List<GuaranteeResponse>> Guarantee([CustomizeValidator(RuleSe
/// <returns></returns>
[Route("insert")]
[HttpPost]
public ApiResponse<cof_guarantee> GuarantInsert([CustomizeValidator(RuleSet = "Insert"), FromBody]GuaranteeRequest request)
public ApiResponse<List<cof_guarantee>> GuarantInsert([CustomizeValidator(RuleSet = "Insert"), FromBody]GuaranteeRequest request)
{
var entity = guaranteeService.GuarantInsert(request);
if (entity.Id > 0)
return new ApiResponse<cof_guarantee>(ResponseType.OK, "新增配置成功", entity);
return new ApiResponse<cof_guarantee>(ResponseType.Fail, "新增配置失败", entity);
if (request.Source == null || request.Source.Count == 0)
return new ApiResponse<List<cof_guarantee>>(ResponseType.ParameterError, "保底来源科室 无效");
var list = guaranteeService.GuarantInsert(request);
return new ApiResponse<List<cof_guarantee>>(ResponseType.OK, "新增配置成功", list);
}
/// <summary>
......@@ -56,10 +57,13 @@ public ApiResponse<cof_guarantee> GuarantInsert([CustomizeValidator(RuleSet = "I
/// <returns></returns>
[Route("update")]
[HttpPost]
public ApiResponse<cof_guarantee> GuarantUpdate([CustomizeValidator(RuleSet = "Update"), FromBody]GuaranteeRequest request)
public ApiResponse<List<cof_guarantee>> GuarantUpdate([CustomizeValidator(RuleSet = "Update"), FromBody]GuaranteeRequest request)
{
if (request.Source == null || request.Source.Count == 0)
return new ApiResponse<List<cof_guarantee>>(ResponseType.ParameterError, "保底来源科室 无效");
var result = guaranteeService.GuarantUpdate(request);
return new ApiResponse<cof_guarantee>(ResponseType.OK, "修改配置成功", result);
return new ApiResponse<List<cof_guarantee>>(ResponseType.OK, "修改配置成功", result);
}
/// <summary>
......
......@@ -23,7 +23,7 @@ public class GuaranteeRequest
public string Target { get; set; }
/// <summary> 保底来源科室 </summary>
public string Source { get; set; }
public List<GuaranItems> Source { get; set; }
}
......
......@@ -34,7 +34,7 @@ public class GuaranteeResponse
public class GuaranItems
{
public int GId { get; set; }
public Nullable<int> GId { get; set; }
public string GValue { get; set; }
}
......
......@@ -68,7 +68,7 @@ public List<GuaranteeResponse> GuaranTree(int allotId)
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public cof_guarantee GuarantInsert(GuaranteeRequest request)
public List<cof_guarantee> GuarantInsert(GuaranteeRequest request)
{
var list = perforCofguaranteeRepository.GetEntities(t => t.AllotId == request.AllotId);
if (list != null)
......@@ -77,10 +77,18 @@ public cof_guarantee GuarantInsert(GuaranteeRequest request)
if (config != null)
throw new PerformanceException("优先级无效,已存在");
}
var guaranteeList = new List<cof_guarantee>();
guaranteeList.AddRange(request.Source.Select(t => new cof_guarantee { Source = t.GValue }));
guaranteeList.ForEach(t =>
{
t.AllotId = request.AllotId;
t.Priority = request.Priority;
t.UnitType = request.UnitType;
t.Target = request.Target;
});
var guarantee = Mapper.Map<cof_guarantee>(request);
perforCofguaranteeRepository.Add(guarantee);
return guarantee;
perforCofguaranteeRepository.AddRange(guaranteeList.ToArray());
return guaranteeList;
}
/// <summary>
......@@ -88,38 +96,69 @@ public cof_guarantee GuarantInsert(GuaranteeRequest request)
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public cof_guarantee GuarantUpdate(GuaranteeRequest request)
public List<cof_guarantee> GuarantUpdate(GuaranteeRequest request)
{
var guarantee = perforCofguaranteeRepository.GetEntity(t => t.Id == request.Id);
if (guarantee == null)
var guaranteeList = perforCofguaranteeRepository.GetEntities(t => t.UnitType == request.UnitType && t.Target == request.Target);
if (guaranteeList == null)
throw new PerformanceException("request.Id 参数错误");
if (guarantee.Priority > request.Priority)
#region 修改优先级
int flag = guaranteeList.FirstOrDefault().Priority.Value;
if (flag > request.Priority)
{
var list = perforCofguaranteeRepository.GetEntities(t => t.AllotId == guarantee.AllotId && t.UnitType == request.UnitType && t.Priority >= request.Priority && t.Priority < guarantee.Priority);
var list = perforCofguaranteeRepository.GetEntities(t => t.AllotId == request.AllotId && t.UnitType == request.UnitType && t.Priority >= request.Priority && t.Priority < flag);
if (list != null && list.Any())
{
list?.ForEach(t => { t.Priority = t.Priority + 1; });
perforCofguaranteeRepository.UpdateRange(list.ToArray());
}
}
else if (guarantee.Priority < request.Priority)
else if (flag < request.Priority)
{
var list = perforCofguaranteeRepository.GetEntities(t => t.AllotId == guarantee.AllotId && t.UnitType == request.UnitType && t.Priority <= request.Priority && t.Priority > guarantee.Priority);
var list = perforCofguaranteeRepository.GetEntities(t => t.AllotId == request.AllotId && t.UnitType == request.UnitType && t.Priority <= request.Priority && t.Priority > flag);
if (list != null && list.Any())
{
list.ForEach(t => { t.Priority = t.Priority - 1; });
perforCofguaranteeRepository.UpdateRange(list.ToArray());
}
}
#endregion
#region 添加
var insertList = request.Source.Where(t => t.GId.HasValue && t.GId == 0).Select(t => new cof_guarantee { Source = t.GValue }).ToList();
insertList.ForEach(t =>
{
t.AllotId = request.AllotId;
t.Priority = request.Priority;
t.UnitType = request.UnitType;
t.Target = request.Target;
});
perforCofguaranteeRepository.AddRange(insertList.ToArray());
#endregion
guarantee.Priority = request.Priority;
guarantee.UnitType = request.UnitType;
guarantee.Target = request.Target;
guarantee.Source = request.Source;
if (!perforCofguaranteeRepository.Update(guarantee))
#region 修改、删除
var delItem = new List<int>();
var exist = request.Source.Where(t => t.GId.HasValue && t.GId != 0).Select(t => t.GId);
guaranteeList.ForEach(t =>
{
if (exist.Contains(t.Id))
t.Source = request.Source.FirstOrDefault(s => s.GId == t.Id).GValue;
else
delItem.Add(t.Id);
t.Priority = request.Priority;
t.UnitType = request.UnitType;
t.Target = request.Target;
});
if (!perforCofguaranteeRepository.UpdateRange(guaranteeList.ToArray()))
throw new PerformanceException("保存失败");
return Mapper.Map<cof_guarantee>(request);
if (exist != null && exist.Count() > 0)
perforCofguaranteeRepository.RemoveRange(guaranteeList.Where(t => delItem.Contains(t.Id)).ToArray());
#endregion
guaranteeList.AddRange(insertList);
return guaranteeList.Where(t => !delItem.Contains(t.Id))?.ToList();
}
/// <summary>
......
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