Commit 48e76c05 by ruyun.zhang@suvalue.com

Merge branch '二次绩效历史人员' into custom_script

parents ccc41e80 80cfbc09
......@@ -21,15 +21,19 @@ public class SecondAllotController : ControllerBase
private readonly ClaimService claimService;
private readonly SecondAllotService secondAllotService;
private readonly ResultComputeService resultComputeService;
private readonly SecondAllotDetails secondAllotDetails;
public SecondAllotController(
ClaimService claimService,
SecondAllotService secondAllotService,
ResultComputeService resultComputeService)
ResultComputeService resultComputeService,
SecondAllotDetails secondAllotDetails
)
{
this.claimService = claimService;
this.secondAllotService = secondAllotService;
this.resultComputeService = resultComputeService;
this.secondAllotDetails = secondAllotDetails;
}
#region 二次绩效列表、录入数据展示,保存数据
......@@ -120,7 +124,8 @@ public ApiResponse SaveCompute([FromBody] List<ag_compute> request)
[HttpPost]
public ApiResponse SecondDetail([CustomizeValidator(RuleSet = "Refresh"), FromBody] UseTempRequest request)
{
var result = secondAllotService.GetSecondDetail(request, claimService.GetUserId());
//var result = secondAllotService.GetSecondDetail(request, claimService.GetUserId());
var result = secondAllotDetails.GetSecondDetails(claimService.GetUserId(), request.SecondId, request.HospitalId, request.IsArchive, request.EmployeeSource);
return new ApiResponse(ResponseType.OK, result);
}
......@@ -396,7 +401,8 @@ public ApiResponse NursingDeptAuditResult([FromBody] SecondAuditRequest request)
[HttpPost]
public ApiResponse OtherList([FromBody] AgOtherRequest request)
{
var result = secondAllotService.OtherList(request.SecondId, claimService.GetUserId());
//var result = secondAllotService.OtherList(request.SecondId, claimService.GetUserId());
var result = secondAllotDetails.GetOtherTempDetails(claimService.GetUserId(), request.SecondId, request.IsArchive, request.EmployeeSource);
var obj = new
{
header = secondAllotService.OtherListHeader(request.SecondId, result?.Sum(t => t.RealAmount)),
......@@ -444,4 +450,4 @@ public ApiResponse DeptComputeDetail(int allotId)
return new ApiResponse(ResponseType.OK, new { isShowManage, data });
}
}
}
\ No newline at end of file
}
......@@ -2247,6 +2247,9 @@
<member name="P:Performance.DtoModels.UseTempRequest.IsArchive">
<summary> 是否归档 </summary>
</member>
<member name="P:Performance.DtoModels.UseTempRequest.EmployeeSource">
<summary> 人员信息来源 </summary>
</member>
<member name="P:Performance.DtoModels.WorkItemRequest.Item">
<summary>
工作量绩效项
......
......@@ -9,6 +9,10 @@ public class AgOtherRequest
{
public int SecondId { get; set; }
public int IsArchive { get; set; }
public int EmployeeSource { get; set; }
public List<ag_othersource> Othersources { get; set; }
}
}
......@@ -19,7 +19,11 @@ public class UseTempRequest
/// <summary> 是否归档 </summary>
public int IsArchive { get; set; }
/// <summary> 人员信息来源 </summary>
public int EmployeeSource { get; set; }
}
public class UseTempRequestValidator : AbstractValidator<UseTempRequest>
{
public UseTempRequestValidator()
......
......@@ -18,10 +18,13 @@ public class HeadItem : ICloneable
public int Type { get; set; }
public decimal FactorValue { get; set; }
public int SourceType { get; set; }
/// <summary> 1 带出历史数据 2不带出 </summary>
public Nullable<int> IsBring { get; set; }
/// <summary> 1 value相加值为1 </summary>
public Nullable<int> SpecialAttr { get; set; }
public Nullable<int> WorkType { get; set; }
public object Clone()
......@@ -34,5 +37,22 @@ public class BodyItem : HeadItem
{
public int RowNumber { get; set; }
public string Value { get; set; }
public BodyItem()
{
}
public BodyItem(HeadItem headItem)
{
FiledId = headItem.FiledId;
FiledName = headItem.FiledName;
Sort = headItem.Sort;
Type = headItem.Type;
FactorValue = headItem.FactorValue;
SourceType = headItem.SourceType;
IsBring = headItem.IsBring;
SpecialAttr = headItem.SpecialAttr;
WorkType = headItem.WorkType;
}
}
}
using AutoMapper;
using Performance.DtoModels;
using Performance.EntityModels;
using Performance.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Performance.Services
{
public class SecondAllotDetails : IAutoInjection
{
private readonly PerforAgsecondallotRepository agsecondallotRepository;
private readonly PerforAgusetempRepository agusetempRepository;
private readonly PerforAgtempitemRepository agtempitemRepository;
private readonly PerforAgworkloadRepository agworkloadRepository;
private readonly PerforAgworkloadtypeRepository agworkloadtypeRepository;
private readonly PerforAgfixatitemRepository agfixatitemRepository;
private readonly PerforAgothersourceRepository agothersourceRepository;
private readonly PerforPerallotRepository perallotRepository;
private readonly PerforCofagainRepository cofagainRepository;
private readonly PerforPerapramountRepository perapramountRepository;
private readonly PerforRescomputeRepository rescomputeRepository;
private readonly PersonService personService;
public SecondAllotDetails(
PerforAgsecondallotRepository agsecondallotRepository,
PerforAgusetempRepository agusetempRepository,
PerforAgtempitemRepository agtempitemRepository,
PerforAgworkloadRepository agworkloadRepository,
PerforAgworkloadtypeRepository agworkloadtypeRepository,
PerforAgfixatitemRepository agfixatitemRepository,
PerforAgothersourceRepository agothersourceRepository,
PerforPerallotRepository perallotRepository,
PerforCofagainRepository cofagainRepository,
PerforPerapramountRepository perapramountRepository,
PerforRescomputeRepository rescomputeRepository,
PersonService personService
)
{
this.agsecondallotRepository = agsecondallotRepository;
this.agusetempRepository = agusetempRepository;
this.agtempitemRepository = agtempitemRepository;
this.agworkloadRepository = agworkloadRepository;
this.agworkloadtypeRepository = agworkloadtypeRepository;
this.agfixatitemRepository = agfixatitemRepository;
this.agothersourceRepository = agothersourceRepository;
this.perallotRepository = perallotRepository;
this.cofagainRepository = cofagainRepository;
this.perapramountRepository = perapramountRepository;
this.rescomputeRepository = rescomputeRepository;
this.personService = personService;
}
#region 横向纵向模板详情
/// <summary>
/// 二次绩效详情
/// </summary>
/// <param name="userId"></param>
/// <param name="secondId"></param>
/// <param name="hospitalId"></param>
/// <param name="isArchive"></param>
/// <returns></returns>
public SecondResponse GetSecondDetails(int userId, int secondId, int hospitalId, int isArchive, int employeeSource)
{
var secondAllot = agsecondallotRepository.GetEntity(w => w.Id == secondId);
if (secondAllot == null) throw new PerformanceException("未查询到二次绩效信息");
var prevSecondAllot = GetPreviousSecondAllot(hospitalId, secondAllot);
int tempId = (int)Temp.other;
var userTemp = agusetempRepository.GetEntity(w => w.HospitalId == hospitalId && w.Department == secondAllot.Department && w.UnitType == secondAllot.UnitType);
if (userTemp != null) tempId = userTemp.UseTempId ?? (int)Temp.other;
if (tempId == (int)Temp.other) return new SecondResponse();
if (isArchive == 1 || new List<int> { (int)SecondAllotStatus.WaitReview, (int)SecondAllotStatus.PassAudit }.Contains(secondAllot.Status ?? (int)SecondAllotStatus.Uncommitted))
employeeSource = (int)EmployeeSource.Initial;
// 历史保存过的数据
var savedDataList = agfixatitemRepository.GetEntities(w => w.SecondId == secondAllot.Id);
var header = GetHeadItems(hospitalId, tempId, secondAllot);
var body = GetBodyItems(userId, employeeSource, secondAllot, prevSecondAllot, header, savedDataList);
var result = new SecondResponse { HeadItems = header, BodyItems = body };
SupplyHeaderByWorkItem(hospitalId, result, secondAllot, savedDataList);
result.HeadItems = result.HeadItems.OrderBy(t => t.Type).ThenBy(t => t.WorkType).ThenBy(t => t.Sort).ThenBy(t => t.FiledName).ToList();
result.BodyItems = result.BodyItems.OrderBy(t => t.RowNumber).ThenBy(t => t.Type).ThenBy(t => t.Sort).ToList();
return result;
}
/// <summary>
/// 获取显示列
/// </summary>
/// <param name="hospitalId"></param>
/// <param name="tempId"></param>
/// <param name="secondAllot"></param>
/// <returns></returns>
public List<HeadItem> GetHeadItems(int hospitalId, int tempId, ag_secondallot secondAllot)
{
// 数据库配置固定的列
var fixedHeaders = agtempitemRepository.GetEntities(w => w.TempId == tempId);
// 用户自定义的工作量、单项奖励
var configHeaders = agworkloadRepository.GetEntities(w => w.HospitalId == hospitalId && w.Department == secondAllot.Department && w.UnitType == secondAllot.UnitType);
// 初始化固定列
var headItems = Mapper.Map<List<HeadItem>>(fixedHeaders) ?? new List<HeadItem>();
//获取工作量、单项奖励列
if (configHeaders != null && configHeaders.Any())
{
var workDtos = Mapper.Map<List<HeadItem>>(configHeaders.Where(t => t.WorkTypeId == (int)AgWorkloadType.Workload));
workDtos.ForEach(t => { t.Type = (int)TempColumnType.WorkloadColumns; });
headItems.AddRange(workDtos);
workDtos = Mapper.Map<List<HeadItem>>(configHeaders.Where(t => t.WorkTypeId == (int)AgWorkloadType.SingleAwards));
workDtos.ForEach(t => { t.Type = (int)TempColumnType.SingleAwardsColumns; });
headItems.AddRange(workDtos);
}
if (headItems != null && headItems.Any())
headItems = headItems.OrderBy(s => s.Type).ThenBy(s => s.Sort).ToList();
return headItems;
}
/// <summary>
/// 获取显示的数据
/// </summary>
/// <param name="userId"></param>
/// <param name="employeeSource"></param>
/// <param name="secondAllot"></param>
/// <param name="prevSecondAllot"></param>
/// <param name="headItems"></param>
/// <returns></returns>
public List<BodyItem> GetBodyItems(int userId, int employeeSource, ag_secondallot secondAllot, ag_secondallot prevSecondAllot, List<HeadItem> headItems, List<ag_fixatitem> savedDataList)
{
var bodyItems = new List<BodyItem>();
if (headItems == null || !headItems.Any()) return bodyItems;
var topFixedColumns = headItems.Where(w => w.Type == (int)TempColumnType.TopFixedColumns)?.ToList();
if (topFixedColumns != null && savedDataList != null && savedDataList.Any(w => w.RowNumber == -1 && w.Type == (int)TempColumnType.TopFixedColumns))
{
var topFixedDataList = new List<BodyItem>();
foreach (var column in topFixedColumns)
{
var topFixedData = new BodyItem(column);
var savedData = savedDataList.FirstOrDefault(w => w.RowNumber == -1 && w.Type == (int)TempColumnType.TopFixedColumns && w.ItemName == column.FiledName);
if (savedData != null)
{
topFixedData.Value = savedData.ItemValue;
topFixedData.RowNumber = -1;
}
topFixedDataList.Add(topFixedData);
}
SupplementFixedData(secondAllot, topFixedDataList);
bodyItems.AddRange(topFixedDataList);
}
var otherShowColumns = headItems.Where(w => w.Type != (int)TempColumnType.TopFixedColumns)?.ToList();
if (otherShowColumns != null)
{
if (employeeSource == (int)EmployeeSource.Initial)
{
// 保存过数据,从保存的数据中心带出信息
// 未保存过数据,带入初始数据(首次填写二次绩效,人员信息来自人员字典,有历史二次绩效记录时,人员信息来自上次二次绩效填写记录)
if (savedDataList == null)
{
employeeSource = prevSecondAllot == null ? (int)EmployeeSource.EmployeeDict : (int)EmployeeSource.PrevSecondAllot;
}
}
var tableFixedDataList = GetBodyItemsByEmployeeSource(userId, employeeSource, secondAllot, prevSecondAllot, savedDataList, otherShowColumns);
bodyItems.AddRange(tableFixedDataList);
}
return bodyItems;
}
private List<BodyItem> GetBodyItemsByEmployeeSource(int userId, int employeeSource, ag_secondallot secondAllot, ag_secondallot prevSecondAllot,
List<ag_fixatitem> savedDataList, List<HeadItem> otherShowColumns)
{
switch (employeeSource)
{
case (int)EmployeeSource.Initial:
return GetEmployeeFromSavedData(secondAllot, savedDataList, otherShowColumns);
case (int)EmployeeSource.EmployeeDict:
return GetEmployeeFromEmployeeDict(userId, secondAllot, otherShowColumns);
case (int)EmployeeSource.PrevSecondAllot:
return GetEmployeeFromPrevData(userId, secondAllot, prevSecondAllot, otherShowColumns);
default:
return new List<BodyItem>();
}
}
/// <summary>
/// 从保存过的数据中获取人员信息
/// </summary>
/// <param name="savedDataList"></param>
/// <param name="otherShowColumns"></param>
/// <returns></returns>
public List<BodyItem> GetEmployeeFromSavedData(ag_secondallot secondAllot, List<ag_fixatitem> savedDataList, List<HeadItem> otherShowColumns)
{
var tableFixedDataList = new List<BodyItem>();
if (otherShowColumns == null || savedDataList == null || !savedDataList.Any(w => w.RowNumber.HasValue && w.RowNumber > -1))
return tableFixedDataList;
var rowNumberList = savedDataList.Where(w => w.RowNumber.HasValue && w.RowNumber > -1)?.Select(w => w.RowNumber.Value).Distinct().OrderBy(t => t).ToList();
if (rowNumberList != null && rowNumberList.Any())
{
foreach (var rowNumber in rowNumberList)
{
foreach (var column in otherShowColumns)
{
var tableFixedData = new BodyItem(column);
var savedData = savedDataList.FirstOrDefault(w => w.RowNumber == rowNumber && w.Type == column.Type && w.ItemName == column.FiledName);
if (savedData != null)
{
tableFixedData.Value = savedData.ItemValue;
tableFixedData.RowNumber = rowNumber;
}
tableFixedDataList.Add(tableFixedData);
}
}
SupplementOtherPerfor(secondAllot, tableFixedDataList);
}
return tableFixedDataList;
}
/// <summary>
/// 从人员字典中获取人员信息
/// </summary>
/// <param name="userId"></param>
/// <param name="secondAllot"></param>
/// <param name="otherShowColumns"></param>
/// <returns></returns>
public List<BodyItem> GetEmployeeFromEmployeeDict(int userId, ag_secondallot secondAllot, List<HeadItem> otherShowColumns)
{
var tableFixedDataList = new List<BodyItem>();
if (otherShowColumns == null || !otherShowColumns.Any()) return tableFixedDataList;
var employeeList = personService.GetPersons(secondAllot.AllotId.Value, userId);
if (employeeList == null || !employeeList.Any()) return tableFixedDataList;
//var perapramounts = perapramountRepository.GetEntities(t => t.AllotId == secondAllot.AllotId && t.Status == 3);
//Func<per_employee, decimal?> getAprAmount = (t) => perapramounts
// ?.Where(w => w.AccountingUnit?.Trim() == secondAllot.Department?.Trim() && w.DoctorName?.Trim() == t.DoctorName?.Trim() && w.PersonnelNumber?.Trim() == t.JobNumber?.Trim())
// ?.Sum(w => w.Amount);
var employeeColumns = new List<Tuple<string, string, Func<per_employee, object>>>
{
new Tuple<string, string, Func<per_employee, object>>("人员工号", "PersonnelNumber", (t) => t.JobNumber),
new Tuple<string, string, Func<per_employee, object>>("姓名", "FullName", (t) => t.DoctorName),
new Tuple<string, string, Func<per_employee, object>>(
"岗位", "Post",
(t) => !string.IsNullOrEmpty(t.Duty) && (t.Duty.IndexOf("主任") > -1 || t.Duty.IndexOf("护士长") > -1) ? "主任" : "其他"),
new Tuple<string, string, Func<per_employee, object>>("出勤", "ActualAttendance", (t) => t.AttendanceDay),
new Tuple<string, string, Func<per_employee, object>>("职称", "JobTitle", (t) => t.JobTitle),
new Tuple<string, string, Func<per_employee, object>>("预留比例", "ReservedRatio", (t) => t.ReservedRatio),
new Tuple<string, string, Func<per_employee, object>>("医院其他绩效", "OtherPerformance", (t) => 0)
};
int rowNumber = 0;
foreach (var employee in employeeList)
{
foreach (var column in employeeColumns)
{
var headItem = otherShowColumns.FirstOrDefault(w => w.FiledName == column.Item1 && w.FiledId == column.Item2 && w.Type == (int)TempColumnType.TableFixedColumns);
if (headItem == null) continue;
var tableFixedData = new BodyItem(headItem);
var value = column.Item3.Invoke(employee);
tableFixedData.Value = value?.ToString();
tableFixedData.RowNumber = rowNumber;
tableFixedDataList.Add(tableFixedData);
}
rowNumber++;
}
SupplementOtherPerfor(secondAllot, tableFixedDataList);
return tableFixedDataList;
}
/// <summary>
/// 从上一次的保存信息中获取人员信息
/// </summary>
/// <param name="prevSecondAllot"></param>
/// <param name="otherShowColumns"></param>
/// <returns></returns>
public List<BodyItem> GetEmployeeFromPrevData(int userId, ag_secondallot secondAllot, ag_secondallot prevSecondAllot, List<HeadItem> otherShowColumns)
{
var tableFixedDataList = new List<BodyItem>();
if (prevSecondAllot == null || otherShowColumns == null || !otherShowColumns.Any()) return tableFixedDataList;
var savedDataList = agfixatitemRepository.GetEntities(w => w.SecondId == prevSecondAllot.Id && w.RowNumber.HasValue && w.RowNumber > -1);
if (savedDataList == null || !savedDataList.Any()) return tableFixedDataList;
var employeeList = personService.GetPersons(secondAllot.AllotId.Value, userId);
var employeeColumns = new List<Tuple<string, string>>
{
new Tuple<string, string>("人员工号", "PersonnelNumber"),
new Tuple<string, string>("姓名", "FullName"),
new Tuple<string, string>("岗位", "Post"),
new Tuple<string, string>("人员系数", "StaffCoefficient"),
new Tuple<string, string>("职称", "JobTitle"),
new Tuple<string, string>("职称系数", "TitleCoefficient")
};
var rowNumberList = savedDataList.Select(w => w.RowNumber.Value).Distinct().OrderBy(t => t).ToList();
if (rowNumberList != null && rowNumberList.Any())
{
foreach (var rowNumber in rowNumberList)
{
foreach (var column in employeeColumns)
{
var headItem = otherShowColumns.FirstOrDefault(w => w.FiledName == column.Item1 && w.FiledId == column.Item2 && w.Type == (int)TempColumnType.TableFixedColumns);
if (headItem == null) continue;
var tableFixedData = new BodyItem(headItem);
var savedData = savedDataList.FirstOrDefault(w => w.RowNumber == rowNumber && w.Type == (int)TempColumnType.TableFixedColumns && w.ItemName == column.Item1);
if (savedData != null)
{
tableFixedData.Value = savedData.ItemValue;
tableFixedData.RowNumber = rowNumber;
}
tableFixedDataList.Add(tableFixedData);
}
#region 获取人员字典中录入的出勤
var attenItem = otherShowColumns.FirstOrDefault(w => w.FiledName == "出勤" && w.FiledId == "ActualAttendance" && w.Type == (int)TempColumnType.TableFixedColumns);
if (attenItem == null) continue;
var attendance = new BodyItem(attenItem);
var jobNumber = savedDataList.FirstOrDefault(w => w.RowNumber == rowNumber && w.ItemName == "人员工号")?.ItemValue;
var personName = savedDataList.FirstOrDefault(w => w.RowNumber == rowNumber && w.ItemName == "姓名")?.ItemValue;
var employeeAttendance = employeeList.FirstOrDefault(w => w.JobNumber == jobNumber && w.DoctorName == personName)?.AttendanceDay.ToString();
attendance.Value = employeeAttendance;
attendance.RowNumber = rowNumber;
tableFixedDataList.Add(attendance);
#endregion 获取人员字典中录入的出勤
}
SupplementOtherPerfor(secondAllot, tableFixedDataList);
}
return tableFixedDataList;
}
/// <summary>
/// 补充顶部数据中的固定信息
/// </summary>
/// <param name="secondAllot"></param>
/// <param name="bodyItems"></param>
private void SupplementFixedData(ag_secondallot secondAllot, List<BodyItem> bodyItems)
{
if (bodyItems == null || !bodyItems.Any(w => w.RowNumber == -1)) return;
var keyValue = new Dictionary<string, string>
{
{ "发放月份", $"{secondAllot.Year}{secondAllot.Month.ToString().PadLeft(2, '0')}月" },
{ "可分配绩效", secondAllot.RealGiveFee.ToString() },
{ "满勤天数", DateTime.DaysInMonth(secondAllot.Year.Value, secondAllot.Month.Value).ToString() },
};
var configs = cofagainRepository.GetEntities(t => t.AllotID == secondAllot.AllotId);
if (configs != null && configs.Any())
{
var pairs = new Dictionary<string, string>
{
{ "职称绩效", "年资职称绩效占比" },
{ "工作量绩效", "工作量绩效占比" },
};
foreach (var config in configs)
{
var key = pairs.ContainsKey(config.TypeName) ? pairs[config.TypeName] : config.TypeName;
if (!keyValue.Keys.Contains(key)) keyValue.Add(key, config.Value.ToString());
}
}
foreach (var item in keyValue)
{
var field = bodyItems.FirstOrDefault(w => w.RowNumber == -1 && w.FiledName == item.Key);
if (field != null && !string.IsNullOrEmpty(item.Value)) field.Value = item.Value;
}
}
/// <summary>
/// 补充 医院其他绩效
/// </summary>
/// <param name="result"></param>
private void SupplementOtherPerfor(ag_secondallot secondAllot, List<BodyItem> bodyItems)
{
if (bodyItems == null || !bodyItems.Any(w => w.RowNumber > -1)) return;
var perapramounts = perapramountRepository.GetEntities(t => t.AllotId == secondAllot.AllotId && t.Status == 3);
var rowNumberList = bodyItems.Where(w => w.RowNumber > -1).Select(w => w.RowNumber).Distinct().OrderBy(t => t).ToList();
foreach (var rownum in rowNumberList)
{
var rowData = bodyItems.Where(w => w.RowNumber == rownum);
var personnelNumber = rowData.FirstOrDefault(w => w.FiledId == "PersonnelNumber")?.Value;
var fullName = rowData.FirstOrDefault(w => w.FiledId == "FullName")?.Value;
var amount = perapramounts
?.Where(w => w.AccountingUnit?.Trim() == secondAllot.Department?.Trim() && w.PersonnelNumber?.Trim() == personnelNumber?.Trim())
?.Sum(w => w.Amount);
var otherPerfor = rowData.FirstOrDefault(w => w.FiledId == "OtherPerformance");
if (otherPerfor != null)
otherPerfor.Value = amount?.ToString();
}
}
/// <summary>
/// 根绝添加工作量类型判断是否添加
/// </summary>
/// <param name="hospitalId"></param>
/// <param name="result"></param>
/// <param name="secondAllot"></param>
/// <param name="fixatitems"></param>
private void SupplyHeaderByWorkItem(int hospitalId, SecondResponse result, ag_secondallot secondAllot, List<ag_fixatitem> fixatitems)
{
//不包含工作量绩效
if (!result.HeadItems.Select(t => t.FiledId).Contains("PerformanceShareTheWorkload")) return;
var maxSortValue = result.HeadItems.Where(t => t.Type == 1).Max(t => t.Sort);
var headers = new HeadItem[]
{
new HeadItem { FiledId = "ThePerformanceOf", Type = 1, SourceType = 1, IsBring = 2, SpecialAttr = 1 },
new HeadItem { FiledId = "ThePerformanceAmountOf", Type = 1, SourceType = 1, IsBring = 2, SpecialAttr = 2 }
};
var headerItems = new List<HeadItem>();
var unit = secondAllot.UnitType == UnitType.医技组.ToString() ? UnitType.医生组.ToString() : secondAllot.UnitType;
var deptHeader = agworkloadtypeRepository.GetEntities(t => t.HospitalId == hospitalId && t.Department == secondAllot.Department && t.UnitType == unit);
if (deptHeader != null && deptHeader.Any())
{
int sortindex = 1;
foreach (var item in deptHeader)
{
if (item.HospitalId == 0) continue;
for (int i = 0; i < headers.Length; i++)
{
var headItem = (HeadItem)headers[i].Clone();
headItem.FiledName = (i % 2 == 0) ? item.TypeName : item.TypeName.Replace("占比", "金额");
if (i % 2 != 0 && !headItem.FiledName.EndsWith("金额"))
headItem.FiledName += "金额";
headItem.FiledId += item.Id;
headItem.Sort = maxSortValue + sortindex;
headItem.WorkType = item.Id;
headerItems.Add(headItem);
sortindex++;
}
}
}
var defauleHeader = new List<ag_workload_type>
{
new ag_workload_type { Id = 2, TypeName = "工作量绩效占比", },
new ag_workload_type { Id = 2, TypeName = "工作量分配绩效金额" },
};
foreach (var item in defauleHeader)
{
result.HeadItems.Where(t => t.FiledName == item.TypeName).ToList()?.ForEach(t =>
{
t.WorkType = item.Id;
t.SpecialAttr = item.TypeName.IndexOf("占比") > -1 ? 1 : 2;
});
result.BodyItems.Where(t => t.FiledName == item.TypeName).ToList()?.ForEach(t =>
{
t.WorkType = item.Id;
t.SpecialAttr = item.TypeName.IndexOf("占比") > -1 ? 1 : 2;
});
}
var rownumber = result.BodyItems.Any(t => t.RowNumber == -1) ? -1 : 0;
foreach (var item in headerItems)
{
if (!result.HeadItems.Select(t => t.FiledId).Contains(item.FiledId))
{
result.HeadItems.Add(item);
var body = Mapper.Map<BodyItem>(item);
body.RowNumber = rownumber;
if (fixatitems != null && fixatitems.Any(t => t.ItemName == item.FiledName))
body.Value = fixatitems.FirstOrDefault(t => t.ItemName == item.FiledName).ItemValue;
result.BodyItems.Add(body);
}
}
}
#endregion 横向纵向模板详情
#region 其他模板详情
public List<ag_othersource> GetOtherTempDetails(int userId, int secondId, int isArchive, int employeeSource)
{
var secondAllot = agsecondallotRepository.GetEntity(t => t.Id == secondId);
if (secondAllot == null) throw new PerformanceException("二次绩效信息无效!");
var allot = perallotRepository.GetEntity(w => w.ID == secondAllot.AllotId);
if (allot == null) throw new PerformanceException("未查询到匹配的绩效信息");
var prevSecondAllot = GetPreviousSecondAllot(allot.HospitalId, secondAllot);
var result = new List<ag_othersource>();
var savedDataList = agothersourceRepository.GetEntities(t => t.SecondId == secondId);
var isSupplementTitlePerformance = savedDataList == null || !savedDataList.Any();
if (employeeSource == (int)EmployeeSource.Initial)
{
employeeSource = (savedDataList == null || !savedDataList.Any()) && prevSecondAllot == null
? (int)EmployeeSource.EmployeeDict
: (int)EmployeeSource.PrevSecondAllot;
}
if (isArchive == 1 || new List<int> { (int)SecondAllotStatus.WaitReview, (int)SecondAllotStatus.PassAudit }.Contains(secondAllot.Status ?? (int)SecondAllotStatus.Uncommitted))
employeeSource = (int)EmployeeSource.Initial;
var employees = personService.GetPersons(secondAllot.AllotId.Value, userId)?.Where(t => t.UnitType == secondAllot.UnitType).ToList();
switch (employeeSource)
{
case (int)EmployeeSource.Initial:
result = savedDataList.OrderBy(t => t.Id).ToList();
break;
case (int)EmployeeSource.EmployeeDict:
if (employees == null || !employees.Any()) return new List<ag_othersource>();
result = employees.Select(t => new ag_othersource
{
SecondId = secondId,
WorkNumber = t.JobNumber ?? t.PersonnelNumber,
Name = t.DoctorName,
Department = t.Department,
WorkPost = t.JobTitle,
}).ToList();
break;
case (int)EmployeeSource.PrevSecondAllot:
var prevSavedDataList = agothersourceRepository.GetEntities(t => t.SecondId == prevSecondAllot.Id);
isSupplementTitlePerformance = prevSavedDataList == null || !prevSavedDataList.Any();
if (prevSavedDataList != null && prevSavedDataList.Any())
{
result = prevSavedDataList.OrderBy(t => t.Id)
.Select(t => new ag_othersource
{
SecondId = secondId,
WorkNumber = t.WorkNumber,
Name = t.Name,
Department = t.Department,
WorkPost = t.WorkPost,
}).ToList();
}
break;
default:
break;
}
SupplementSecondDetail(secondAllot, employees, result, isSupplementTitlePerformance);
return result;
}
/// <summary>
/// 补充二次分配 人员明细
/// </summary>
/// <param name="second"></param>
/// <param name="employees"></param>
/// <param name="result"></param>
/// <param name="isTitlePerformance">是否补全职称绩效</param>
private void SupplementSecondDetail(ag_secondallot second, List<per_employee> employees, List<ag_othersource> result, bool isTitlePerformance = true)
{
if (employees == null || !employees.Any(t => t.UnitType == second.UnitType))
return;
// 补充医院其他绩效 及 预留比例
var perapramounts = perapramountRepository.GetEntities(t => t.AllotId == second.AllotId && t.Status == 3);
Func<per_employee, decimal?> getAprAmount = (t) => perapramounts
?.Where(w => w.AccountingUnit?.Trim() == second.Department?.Trim() && w.DoctorName?.Trim() == t.DoctorName?.Trim() && w.PersonnelNumber?.Trim() == t.PersonnelNumber?.Trim())
?.Sum(w => w.Amount);
var distPerformance = rescomputeRepository.GetEntities(t => t.AllotID == second.AllotId && employees.Select(s => s.DoctorName).Contains(t.EmployeeName));
Func<per_employee, decimal?> getDistPerformance = (t) => 0;
if (second.UnitType == UnitType.行政后勤.ToString())
getDistPerformance = (t) => distPerformance
?.Where(w => w.AccountingUnit?.Trim() == second.Department?.Trim() && w.EmployeeName?.Trim() == t.DoctorName?.Trim() && w.JobNumber?.Trim() == t.PersonnelNumber?.Trim())
?.Sum(w => w.GiveFee);
foreach (var item in result)
{
var empl = employees.FirstOrDefault(w => w.PersonnelNumber?.Trim() == item.WorkNumber?.Trim() && w.DoctorName?.Trim() == item.Name?.Trim());
if (empl != null)
{
item.ReservedRatio = empl.ReservedRatio;
item.OtherPerformance = getAprAmount(empl);
if (isTitlePerformance)
item.TitlePerformance = getDistPerformance(empl);
}
}
}
#endregion 其他模板详情
/// <summary>
/// 获取上一次的二次绩效
/// </summary>
/// <param name="hospitalId"></param>
/// <param name="secondAllot"></param>
/// <returns></returns>
private ag_secondallot GetPreviousSecondAllot(int hospitalId, ag_secondallot secondAllot)
{
// 历史删除绩效时,未删除对应的二次绩效记录
var allotList = perallotRepository.GetEntities(w => w.HospitalId == hospitalId)?.OrderBy(s => s.Year).ThenBy(s => s.Month).ToList();
if (allotList == null || !allotList.Any()) throw new PerformanceException("未查询到符合的绩效记录");
var allot = allotList.FirstOrDefault(w => w.ID == secondAllot.AllotId);
if (allot == null) throw new PerformanceException("未查询到符合的绩效记录");
var index = allotList.IndexOf(allot);
if (index == 0) return null;
var prevAllot = allotList[index - 1];
var prevSecondAllot = agsecondallotRepository.GetEntity(w => w.AllotId == prevAllot.ID && w.UnitType == secondAllot.UnitType && w.Department == secondAllot.Department);
return prevSecondAllot;
}
}
/// <summary>
/// 二次绩效模板
/// </summary>
public enum Temp
{
/// <summary>
/// 临床科室二次分配_其他来源
/// </summary>
other = 6,
/// <summary>
/// 二次分配_横向
/// </summary>
crosswise = 7,
/// <summary>
/// 二次分配_纵向
/// </summary>
lengthways = 8
}
/// <summary>
/// 模板中显示项类型
/// </summary>
public enum TempColumnType
{
/// <summary>
/// 顶部固定列
/// </summary>
TopFixedColumns = 1,
/// <summary>
/// 表格固定显示列
/// </summary>
TableFixedColumns = 2,
/// <summary>
/// 工作量配置列
/// </summary>
WorkloadColumns = 3,
/// <summary>
/// 单项奖励配置列
/// </summary>
SingleAwardsColumns = 4,
}
/// <summary>
/// 人员信息来源
/// </summary>
public enum EmployeeSource
{
/// <summary>
/// 初始化(用户保存后的数据)
/// </summary>
Initial = 0,
/// <summary>
/// 上一个二次绩效记录
/// </summary>
PrevSecondAllot = 1,
/// <summary>
/// 人员字典
/// </summary>
EmployeeDict = 2
}
/// <summary>
/// 二次绩效状态
/// 1 未提交 2 等待审核 3 审核通过 4 驳回
/// </summary>
public enum SecondAllotStatus
{
Uncommitted = 1,
WaitReview = 2,
PassAudit = 3,
Reject = 4
}
}
......@@ -419,6 +419,7 @@ private List<BodyItem> GetEmployees(List<per_employee> employees, int allotId, i
{ ("姓名", "FullName"), (t) => t.DoctorName },
{ ("岗位", "Post"), (t) => !string.IsNullOrEmpty(t.Duty) && (t.Duty.IndexOf("主任") > -1 || t.Duty.IndexOf("护士长") > -1) ? "主任" : "其他" },
{ ("出勤", "ActualAttendance"), (t) => t.AttendanceDay },
{ ("职称", "JobTitle"), (t) => t.JobTitle },
{ ("预留比例", "ReservedRatio"), (t) => t.ReservedRatio },
{ ("医院其他绩效","OtherPerformance"), (t) => getAprAmount(t)},
};
......
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