Commit e02f61cb by 李承祥

应用最新的模板、获取二次绩效详情

parent 701d1f21
......@@ -103,10 +103,10 @@ public ApiResponse SaveCompute([FromBody]List<ag_compute> request)
/// <returns></returns>
[Route("api/temp/usetemp")]
[HttpPost]
public ApiResponse UseTemp(UseTempRequest request)
public ApiResponse UseTemp([CustomizeValidator(RuleSet = "Use"), FromBody]UseTempRequest request)
{
var result = secondAllotService.UseTemp(request);
return new ApiResponse(ResponseType.OK);
return result ? new ApiResponse(ResponseType.OK, "添加成功") : new ApiResponse(ResponseType.Fail, "添加失败");
}
/// <summary>
......@@ -115,8 +115,9 @@ public ApiResponse UseTemp(UseTempRequest request)
/// <returns></returns>
[Route("api/second/refreshtemp")]
[HttpPost]
public ApiResponse RefreshTemp()
public ApiResponse RefreshTemp([CustomizeValidator(RuleSet = "Refresh"), FromBody]UseTempRequest request)
{
secondAllotService.RefreshTemp(request);
return new ApiResponse(ResponseType.OK);
}
......@@ -181,5 +182,16 @@ public ApiResponse Temp()
return new ApiResponse(ResponseType.OK, result);
}
/// <summary>
/// 二次绩效详情
/// </summary>
/// <returns></returns>
[Route("api/second/detail")]
[HttpPost]
public ApiResponse SecondDetail([CustomizeValidator(RuleSet = "Refresh"), FromBody]UseTempRequest request)
{
var result = secondAllotService.GetSecondDetail(request);
return new ApiResponse(ResponseType.OK, result);
}
}
}
\ No newline at end of file
......@@ -182,6 +182,15 @@ public AutoMapperConfigs()
CreateMap<UseTempRequest, ag_usetemp>()
.ForMember(dest => dest.UseTempId, opt => opt.MapFrom(src => src.TempId))
.ReverseMap();
CreateMap<ag_tempitem, HeadItem>();
CreateMap<ag_workload, HeadItem>()
.ForMember(dest => dest.FiledId, opt => opt.MapFrom(src => src.ItemId))
.ForMember(dest => dest.FiledName, opt => opt.MapFrom(src => src.ItemName))
.ForMember(dest => dest.Type, opt => opt.NullSubstitute(3));
CreateMap<ag_fixatitem, BodyItem>()
.ForMember(dest => dest.FiledName, opt => opt.MapFrom(src => src.ItemName))
.ForMember(dest => dest.Value, opt => opt.MapFrom(src => src.ItemValue));
}
}
}
......@@ -14,12 +14,25 @@ public class UseTempRequest
public string Department { get; set; }
public string UnitType { get; set; }
public int SecondId { get; set; }
}
public class UseTempRequestValidator : AbstractValidator<UseTempRequest>
{
public UseTempRequestValidator()
{
RuleFor(x => x.TempId).NotNull().GreaterThan(0);
RuleSet("Use", () =>
{
RuleFor(x => x.TempId).NotNull().GreaterThan(0);
});
RuleSet("Refresh", () =>
{
RuleFor(x => x.HospitalId).NotNull().GreaterThan(0);
RuleFor(x => x.Department).NotNull().NotEmpty();
RuleFor(x => x.UnitType).NotNull().NotEmpty();
RuleFor(x => x.SecondId).NotNull().GreaterThan(0);
});
}
}
}
......@@ -16,7 +16,7 @@ public class HeadItem
public string FiledName { get; set; }
public decimal Sort { get; set; }
public int Type { get; set; }
public int FactorValue { get; set; }
public decimal FactorValue { get; set; }
public int SourceType { get; set; }
}
......
......@@ -150,13 +150,51 @@ public bool UseTemp(UseTempRequest request)
/// 应用模板
/// </summary>
/// <returns></returns>
public void RefreshTemp(int secondId)
public void RefreshTemp(UseTempRequest request)
{
var fixatList = perforAgfixatitemRepository.GetEntities(t => t.SecondId == secondId);
var usetemp = perforAgusetempRepository.GetEntity(t => t.HospitalId == request.HospitalId && t.Department == request.Department && t.UnitType == request.UnitType);
if (usetemp == null)
throw new PerformanceException("参数usetempId 无效");
//获取工作量列头
var workItem = perforAgworkloadRepository.GetEntities(t => t.HospitalId == usetemp.HospitalId && t.Department == usetemp.Department && t.UnitType == usetemp.UnitType);
//获取固定模板列头
var tempItem = perforAgtempitemRepository.GetEntities(t => t.TempId == usetemp.UseTempId);
var tempHeader = workItem == null ? tempItem.Select(t => t.FiledName) : tempItem.Select(t => t.FiledName).Union(workItem?.Select(t => t.ItemName));
//获取数据
var fixatList = perforAgfixatitemRepository.GetEntities(t => t.SecondId == request.SecondId);
if (fixatList == null || fixatList.Count == 0)
throw new PerformanceException("参数secondId 无效");
throw new PerformanceException("未录入数据");
throw new NotImplementedException();
//更新系数、排序
fixatList.ForEach(t =>
{
t.Sort = workItem?.FirstOrDefault(w => w.ItemName == t.ItemName)?.Sort;
t.FactorValue = workItem?.FirstOrDefault(w => w.ItemName == t.ItemName)?.FactorValue;
});
perforAgfixatitemRepository.UpdateRange(fixatList.ToArray());
//删除 列 不存在的数据
var header = fixatList.Select(t => t.ItemName).Distinct();
var delItems = header.Except(tempHeader);
if (delItems != null && delItems.Count() > 0)
perforAgfixatitemRepository.RemoveRange(fixatList.Where(t => delItems.Contains(t.ItemName)).ToArray());
//添加 新增列 的数据
var addItems = new List<ag_fixatitem>();
fixatList.Select(t => t.RowNumber).Distinct().ToList().ForEach(t =>
{
addItems.AddRange(tempHeader.Except(header)?.Select(s => new ag_fixatitem
{
ItemName = s,
RowNumber = t,
AllotId = fixatList.First().AllotId,
SecondId = fixatList.First().SecondId,
UnitType = fixatList.First().UnitType,
Sort = tempItem?.FirstOrDefault(w => w.FiledName == s)?.Sort ?? workItem?.FirstOrDefault(w => w.ItemName == s)?.Sort,
FactorValue = workItem?.FirstOrDefault(w => w.ItemName == s)?.FactorValue,
}));
});
if (addItems != null && addItems.Count() > 0)
perforAgfixatitemRepository.AddRange(addItems.ToArray());
}
/// <summary>
......@@ -295,62 +333,52 @@ public bool WorkloadDelete(int id)
return perforAgworkloadRepository.Remove(workload);
}
public void GetHeader()
{
}
public void SaveValue(FixatItemRequest request)
/// <summary>
/// 二次绩效详情
/// </summary>
/// <returns></returns>
public SecondResponse GetSecondDetail(UseTempRequest request)
{
if (request.FixatItems == null || request.FixatItems.Count == 0)
throw new PerformanceException("保存的内容为空");
#region 添加新的值
var addItem = request.FixatItems.Where(t => t.FixatId == 0).ToList();
if (addItem != null && addItem.Count() > 0)
{
var newFixat = addItem.Select(t => new ag_fixatitem
{
AllotId = request.AllotId,
SecondId = request.SecondId,
UnitType = request.UnitType,
RowNumber = request.RowNumber,
ItemName = t.ItemName,
ItemValue = t.ItemValue,
FactorValue = t.FactorValue,
Sort = t.Sort,
Type = t.Type,
SourceType = t.SourceType
});
if (newFixat != null && newFixat.Count() > 0)
perforAgfixatitemRepository.AddRange(newFixat.ToArray());
}
#endregion
#region 更新原始值
var updateItme = request.FixatItems.Where(t => t.FixatId >= 0).ToList();
if (updateItme != null && updateItme.Count() > 0)
var usetemp = perforAgusetempRepository.GetEntity(t => t.HospitalId == request.HospitalId && t.Department == request.Department && t.UnitType == request.UnitType);
if (usetemp == null)
throw new PerformanceException("参数usetempId 无效");
//获取固定模板列头
var tempItem = perforAgtempitemRepository.GetEntities(t => t.TempId == usetemp.UseTempId);
var headItems = Mapper.Map<List<HeadItem>>(tempItem);
//获取工作量列头
var workItem = perforAgworkloadRepository.GetEntities(t => t.HospitalId == usetemp.HospitalId && t.Department == usetemp.Department && t.UnitType == usetemp.UnitType);
if (workItem != null && workItem.Count > 0)
headItems.AddRange(Mapper.Map<List<HeadItem>>(workItem));
var result = new SecondResponse { HeadItems = headItems };
//获取数据
var fixatList = perforAgfixatitemRepository.GetEntities(t => t.SecondId == request.SecondId);
if (fixatList != null || fixatList.Count > 0)
{
var fixatIds = updateItme.Select(t => t.FixatId);
var oldFixat = perforAgfixatitemRepository.GetEntities(t => fixatIds.Contains(t.Id));
if (oldFixat != null && oldFixat.Count > 0)
//补充数据
var groupList = fixatList.GroupBy(t => t.RowNumber);
foreach (var item in groupList)
{
oldFixat.ForEach(t =>
var newItem = headItems.Select(t => t.FiledName).Except(item?.Select(i => i.ItemName));
if (newItem != null && newItem.Count() > 0)
{
var fixat = updateItme.Where(s => s.FixatId == t.Id).FirstOrDefault();
t.ItemName = fixat.ItemName;
t.ItemValue = fixat.ItemValue;
t.FactorValue = fixat.FactorValue;
t.Sort = fixat.Sort;
t.Type = fixat.Type;
t.SourceType = fixat.SourceType;
});
perforAgfixatitemRepository.AddRange(oldFixat.ToArray());
fixatList.AddRange(newItem.Select(t => new ag_fixatitem
{
ItemName = t,
ItemValue = 0,
RowNumber = item.Key,
AllotId = fixatList.First().AllotId,
SecondId = fixatList.First().SecondId,
UnitType = fixatList.First().UnitType,
Sort = headItems?.FirstOrDefault(s => s.FiledName == t)?.Sort,
FactorValue = headItems?.FirstOrDefault(s => s.FiledName == t)?.FactorValue,
}));
}
}
result.BodyItems = Mapper.Map<List<BodyItem>>(fixatList);
}
#endregion
return result;
}
}
}
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