Commit f0a35d36 by 李承祥

保底绩效接口修改

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