Commit 50ad63fe by 李承祥

保底配置修改-过滤重复数据

parent 6f0778d7
......@@ -70,12 +70,15 @@ public List<GuaranteeResponse> GuaranTree(int allotId)
/// <returns></returns>
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 && t.UnitType == request.UnitType);
if (list != null)
{
var config = list.FirstOrDefault(t => t.Priority == request.Priority && t.UnitType == request.UnitType && t.Target != request.Target);
var config = list.FirstOrDefault(t => t.Priority == request.Priority);
if (list.FirstOrDefault(t => t.Priority == request.Priority) != null || list.FirstOrDefault(t => t.Target == request.Target) != null)
throw new PerformanceException($"[{((UnitType)request.UnitType).ToString()}]已存在优先级\"{config.Target}({request.Priority})\",请重新选择");
config = list.FirstOrDefault(t => t.Target == request.Target);
if (config != null)
throw new PerformanceException("优先级无效,已存在");
throw new PerformanceException($"[{((UnitType)request.UnitType).ToString()}]已存在优先级\"{request.Target}({config.Priority})\",请重新选择");
}
var guaranteeList = new List<cof_guarantee>();
guaranteeList.AddRange(request.Source.Select(t => new cof_guarantee { Source = t.GValue }));
......@@ -102,15 +105,53 @@ public List<cof_guarantee> GuarantUpdate(GuaranteeRequest request)
var guaranteeList = perforCofguaranteeRepository.GetEntities(t => t.AllotId == guarantee.AllotId && t.UnitType == guarantee.UnitType && t.Target == guarantee.Target);
if (guaranteeList == null)
throw new PerformanceException("提交数据无效");
#region 添加
//a合并到b集合 过滤b集合中已存在的Source
var filterList = perforCofguaranteeRepository.GetEntities(t => t.AllotId == guarantee.AllotId && t.UnitType == request.UnitType && t.Target == request.Target);
if (request.UnitType != guarantee.UnitType && filterList != null && filterList.Count > 0)
throw new PerformanceException($"[{((UnitType)request.UnitType).ToString()}]已存在\"{request.Target}\",请重新选择");
if(request.UnitType != guarantee.UnitType && filterList != null && filterList.Count > 0)
throw new PerformanceException($"{((UnitType)request.UnitType).ToString()}已存在{request.Target},请重新选择");
#region 修改优先级
if (request.AllotId == guarantee.AllotId && request.Target == guarantee.Target && request.UnitType == guarantee.UnitType && request.Priority != guarantee.Priority)
{
int flag = guaranteeList.FirstOrDefault().Priority.Value;
if (flag > request.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 (flag < request.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 (flag == request.Priority)
{
if (filterList != null && filterList.Any())
{
filterList?.ForEach(t => { t.Priority = t.Priority + 1; });
perforCofguaranteeRepository.UpdateRange(filterList.ToArray());
}
}
}
else
{
if (filterList != null && filterList.Any())
{
filterList?.ForEach(t => { t.Priority = request.Priority; });
perforCofguaranteeRepository.UpdateRange(filterList.ToArray());
}
}
#endregion
var insertList = request.Source.Where(t => t.GId.HasValue && t.GId == 0 && !filterList.Select(g => g.Source).Contains(t.GValue)).Select(t => new cof_guarantee { Source = t.GValue }).ToList();
#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;
......@@ -126,11 +167,11 @@ public List<cof_guarantee> GuarantUpdate(GuaranteeRequest request)
var exist = request.Source.Where(t => t.GId.HasValue && t.GId != 0).Select(t => t.GId);
guaranteeList.ForEach(t =>
{
if (exist.Contains(t.Id))
if (exist.Contains(t.Id) && !filterList.Select(s => s.Source).Contains(t.Source))
t.Source = request.Source.FirstOrDefault(s => s.GId == t.Id).GValue;
else
delItem.Add(t.Id);
//t.Priority = request.Priority;
t.Priority = request.Priority;
t.UnitType = request.UnitType;
t.Target = request.Target;
});
......@@ -142,36 +183,6 @@ public List<cof_guarantee> GuarantUpdate(GuaranteeRequest request)
perforCofguaranteeRepository.RemoveRange(guaranteeList.Where(t => delItem.Contains(t.Id)).ToArray());
#endregion
#region 修改优先级
int flag = guaranteeList.FirstOrDefault().Priority.Value;
if (flag > request.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 (flag < request.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 (flag == request.Priority)
{
if (filterList != null && filterList.Any())
{
filterList?.ForEach(t => { t.Priority = t.Priority + 1; });
perforCofguaranteeRepository.UpdateRange(filterList.ToArray());
}
}
#endregion
guaranteeList.AddRange(insertList);
return guaranteeList.Where(t => !delItem.Contains(t.Id))?.ToList();
}
......
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