绩效BUG修复

parent 87e757fc
......@@ -9,6 +9,7 @@
using Performance.EntityModels;
using Performance.Infrastructure;
using Performance.Services;
using Performance.Services.AllotCompute;
using System;
using System.Collections.Generic;
using System.IO;
......@@ -24,6 +25,7 @@ namespace Performance.Api.Controllers
public class AllotController : Controller
{
private AllotService _allotService;
private readonly ResultComputeService resultComputeService;
private HospitalService _hospitalService;
private ConfigService _configService;
private IHostingEnvironment _evn;
......@@ -32,11 +34,13 @@ public class AllotController : Controller
private readonly LogManageService logManageService;
public AllotController(AllotService allotService,
ResultComputeService resultComputeService,
HospitalService hospitalService, ConfigService configService,
ILogger<AllotController> logger, IHostingEnvironment evn,
ClaimService claim, LogManageService logManageService)
{
_allotService = allotService;
this.resultComputeService = resultComputeService;
_hospitalService = hospitalService;
_logger = logger;
_evn = evn;
......@@ -265,6 +269,8 @@ public ApiResponse Issued([FromBody] AllotRequest request)
if (null == allot)
throw new PerformanceException("当前绩效记录不存在");
_allotService.UpdateAllotStates(allot.ID, (int)AllotStates.GenerateSucceed, EnumHelper.GetDescription(AllotStates.GenerateSucceed));
// 科室下发
resultComputeService.GenerateSecondAllot(allot);
return new ApiResponse(ResponseType.OK);
}
......@@ -290,7 +296,7 @@ public ApiResponse UpdateAllotShowFormula([FromBody] AllotRequest request)
/// <returns></returns>
[Route("reserved")]
[HttpPost]
public ApiResponse Reserved([FromBody]ReservedRequest request)
public ApiResponse Reserved([FromBody] ReservedRequest request)
{
if (request.HospitalId < 1)
return new ApiResponse(ResponseType.ParameterError, "绩效信息无效");
......
......@@ -222,9 +222,10 @@ public ApiResponse AllComputeAvg([FromBody] ComputerRequest request)
avgs.Add(new res_baiscnorm
{
PositionName = "不含行政高层人均绩效",
TotelNumber = gc.Count(),
TotelNumber = gc.Select(w => new { w.JobNumber, w.EmployeeName }).Distinct().Count(),
TotelValue = Math.Round(gc.Sum(s => s.RealGiveFee) ?? 0),
AvgValue = gc.Count() == 0 ? 0 : Math.Round(gc.Sum(s => s.RealGiveFee) / gc.Count() ?? 0)
AvgValue = gc.Select(p => new { p.JobNumber, p.EmployeeName }).Distinct().Count() == 0
? 0 : Math.Round(gc.Sum(s => s.RealGiveFee) / gc.Select(p => new { p.JobNumber, p.EmployeeName }).Distinct().Count() ?? 0)
});
avgs.AddRange(
......@@ -233,7 +234,8 @@ public ApiResponse AllComputeAvg([FromBody] ComputerRequest request)
PositionName = $"{w.Key}人均绩效",
TotelNumber = w.Count(),
TotelValue = Math.Round(w.Sum(s => s.RealGiveFee) ?? 0),
AvgValue = w.Count() == 0 ? 0 : Math.Round(w.Sum(s => s.RealGiveFee) / w.Count() ?? 0)
AvgValue = gc.Select(p => new { p.JobNumber, p.EmployeeName }).Distinct().Count() == 0
? 0 : Math.Round(gc.Sum(s => s.RealGiveFee) / gc.Select(p => new { p.JobNumber, p.EmployeeName }).Distinct().Count() ?? 0)
}));
return new ApiResponse(ResponseType.OK, "ok", avgs.Select(w => new { w.PositionName, w.TotelNumber, w.TotelValue, w.AvgValue }));
......
......@@ -28,6 +28,7 @@ public class ResultComputeService : IAutoInjection
private readonly PerforResbaiscnormRepository perforResbaiscnormRepository;
private readonly PerforResspecialunitRepository perforResspecialunitRepository;
private readonly PerforImaccountbasicRepository perforImaccountbasicRepository;
private readonly PerforResaccountRepository perforResaccountRepository;
private readonly LogManageService logManageService;
private readonly PerforImemployeeclinicRepository perforImemployeeclinicRepository;
private readonly PerforImemployeelogisticsRepository perforImemployeelogisticsRepository;
......@@ -38,6 +39,7 @@ public class ResultComputeService : IAutoInjection
PerforResbaiscnormRepository perforResbaiscnormRepository,
PerforResspecialunitRepository perforResspecialunitRepository,
PerforImaccountbasicRepository perforImaccountbasicRepository,
PerforResaccountRepository perforResaccountRepository,
BaiscNormService baiscNormService, ComputeDirector computeDirector,
LogManageService logManageService, BudgetService budgetService,
PerforPeremployeeRepository perforPeremployeeRepository,
......@@ -55,6 +57,7 @@ public class ResultComputeService : IAutoInjection
this.perforResbaiscnormRepository = perforResbaiscnormRepository;
this.perforResspecialunitRepository = perforResspecialunitRepository;
this.perforImaccountbasicRepository = perforImaccountbasicRepository;
this.perforResaccountRepository = perforResaccountRepository;
this.logManageService = logManageService;
this.budgetService = budgetService;
this.perforPeremployeeRepository = perforPeremployeeRepository;
......@@ -474,5 +477,87 @@ private void ChangeRealGiveFee(res_reserved reserved, per_allot allot, decimal r
}
}
#endregion
/// <summary>
/// 创建科室二次分配
/// </summary>
/// <param name="allot"></param>
public void GenerateSecondAllot(per_allot allot)
{
List<ag_secondallot> tempSecond = new List<ag_secondallot>();
List<ag_secondallot> insSecond = new List<ag_secondallot>();
List<ag_secondallot> updSecond = new List<ag_secondallot>();
var types = new int[] { (int)UnitType.行政高层, (int)UnitType.行政中层 };
var accountUnit = perforResaccountRepository.GetEntities(t => t.AllotID == allot.ID && !types.Contains(t.UnitType.Value));
var specialList = perforResspecialunitRepository.GetEntities(t => t.AllotID == allot.ID);
if (accountUnit != null)
{
foreach (var item in accountUnit)
{
tempSecond.Add(new ag_secondallot
{
AllotId = allot.ID,
Year = allot.Year,
Month = allot.Month,
UnitType = ((UnitType)item.UnitType).ToString(),
Department = item.AccountingUnit,
RealGiveFee = item.RealGiveFee,
});
}
}
if (specialList != null)
{
foreach (var item in specialList)
{
tempSecond.Add(new ag_secondallot
{
AllotId = allot.ID,
Year = allot.Year,
Month = allot.Month,
UnitType = UnitType.特殊核算组.ToString(),
Department = item.AccountingUnit,
RealGiveFee = item.RealGiveFee,
});
}
}
var secondList = perforAgsecondallotRepository.GetEntities(t => t.AllotId == allot.ID && t.Year == allot.Year && t.Month == allot.Month);
foreach (var item in tempSecond)
{
var second = secondList?.FirstOrDefault(f => f.UnitType == item.UnitType && f.Department == item.Department);
if (second == null)
{
insSecond.Add(new ag_secondallot
{
AllotId = allot.ID,
Year = allot.Year,
Month = allot.Month,
UnitType = item.UnitType,
Department = item.Department,
RealGiveFee = item.RealGiveFee,
Status = 1,
});
}
else if (Math.Round((second.RealGiveFee ?? 0) - (item.RealGiveFee ?? 0)) >= 0.5m)
{
second.RealGiveFee = item.RealGiveFee;
if (second.Status > 1)
{
second.Status = 4;
second.Remark = "科室绩效结果发生变更,需要重新提交";
}
updSecond.Add(second);
}
}
if (insSecond.Any())
perforAgsecondallotRepository.AddRange(insSecond.ToArray());
if (updSecond.Any())
perforAgsecondallotRepository.UpdateRange(updSecond.ToArray());
}
}
}
......@@ -411,8 +411,8 @@ public void Generate(per_allot allot, string mail)
var flag = reportService.UpdateData(allot);
logManageService.WriteMsg("正在生成报表数据", $"报表数据生成完成;受影响:{res}行", 1, allot.ID, "ReceiveMessage", true);
//发送邮件
logManageService.WriteMsg("正在发送邮件", "正在发送邮件", 1, allot.ID, "ReceiveMessage", true);
////发送邮件
//logManageService.WriteMsg("正在发送邮件", "正在发送邮件", 1, allot.ID, "ReceiveMessage", true);
//SendEmail(allot, mail, 1, time);
//logdbug.Add(allot.ID, "绩效开始执行", "绩效生成成功");
logManageService.WriteMsg("绩效生成结束", "绩效生成成功", 5, allot.ID, "ReceiveMessage", true);
......
......@@ -1229,7 +1229,7 @@ public List<ag_secondallot> AuditList(int userId, int allotId)
var accountUnit = perforResaccountRepository.GetEntities(t => t.AllotID == allotId && !new int[] { (int)UnitType.行政高层, (int)UnitType.行政中层 }.Contains(t.UnitType.Value));
if (accountUnit == null || !accountUnit.Any()) return new List<ag_secondallot>();
var secondList = perforAgsecondallotRepository.GetEntities(t => t.AllotId == allot.ID && t.Year == allot.Year && t.Month == allot.Month && t.Status == 2);
var secondList = perforAgsecondallotRepository.GetEntities(t => t.AllotId == allot.ID && t.Year == allot.Year && t.Month == allot.Month);
var result = accountUnit.Select(t =>
{
var second = secondList?.FirstOrDefault(f => f.UnitType == ((UnitType)t.UnitType).ToString() && f.Department == t.AccountingUnit);
......@@ -1246,7 +1246,10 @@ public List<ag_secondallot> AuditList(int userId, int allotId)
};
});
var enums = EnumHelper.GetItems<UnitType>();
return result.OrderBy(t => enums.FirstOrDefault(f => f.Name == t.UnitType)?.Value).ThenBy(t => t.Department).ToList();
return result.OrderBy(t => t.Status == 4 ? 2 : t.Status)
.ThenBy(t => enums.FirstOrDefault(f => f.Name == t.UnitType)?.Value)
.ThenBy(t => t.Department)
.ToList();
}
/// <summary>
......@@ -1295,7 +1298,7 @@ public bool AuditSubmit(ag_secondallot second, int userId)
second.Status = 2;
second.SubmitType = temp.UseTempId == 6 ? 2 : 1;
second.SubmitTime = DateTime.Now;
second.Remark = "已提交审核,等待审核中";
//second.Remark = "已提交审核,等待审核中";
return perforAgsecondallotRepository.Update(second);
}
......@@ -1309,8 +1312,8 @@ public bool AuditSubmit(ag_secondallot second, int userId)
public bool ConfirmAudit(int userId, SecondAuditRequest request)
{
var second = perforAgsecondallotRepository.GetEntity(t => t.Id == request.SecondId);
if (second.Status != 2)
throw new PerformanceException("该绩效未提交至审核,请确认");
//if (second.Status != 2)
// throw new PerformanceException("该绩效未提交至审核,请确认");
if (request.IsPass == 1)
{
......@@ -1325,20 +1328,21 @@ public bool ConfirmAudit(int userId, SecondAuditRequest request)
second.AuditUser = userId;
second.AuditTime = DateTime.Now;
second.Remark = request.Remark;
if (string.IsNullOrEmpty(second.Remark))
{
second.Remark = request.IsPass == 1 ? "审核通过" : "驳回";
}
//if (string.IsNullOrEmpty(second.Remark))
//{
// second.Remark = request.IsPass == 1 ? "审核通过" : "驳回";
//}
var result = perforAgsecondallotRepository.Update(second);
#region 添加至二次绩效汇总
if (result && request.IsPass == 1)
{
// 无论驳回还是通过,都需要清空该科室历史数据
var histories = perforAgcomputeRepository.GetEntities(w => w.SecondId == request.SecondId);
if (histories != null && histories.Any())
perforAgcomputeRepository.RemoveRange(histories.ToArray());
#region 添加至二次绩效汇总
if (result && request.IsPass == 1)
{
var computes = new List<ag_compute>();
if (second.SubmitType == 1)
{
......
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