绩效BUG修复

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