第一次重构

parent a02bfe5f
...@@ -25,24 +25,22 @@ public class AllotController : Controller ...@@ -25,24 +25,22 @@ public class AllotController : Controller
{ {
private AllotService _allotService; private AllotService _allotService;
private HospitalService _hospitalService; private HospitalService _hospitalService;
private PerExcelService _perExcelService; private ConfigService _configService;
private IHostingEnvironment _evn; private IHostingEnvironment _evn;
private ILogger<AllotController> _logger; private ILogger<AllotController> _logger;
private ClaimService _claim; private ClaimService _claim;
public AllotController(AllotService allotService, public AllotController(AllotService allotService,
HospitalService hospitalService, HospitalService hospitalService, ConfigService configService,
PerExcelService perExcelService, ILogger<AllotController> logger, IHostingEnvironment evn,
ILogger<AllotController> logger,
IHostingEnvironment evn,
ClaimService claim) ClaimService claim)
{ {
_allotService = allotService; _allotService = allotService;
_hospitalService = hospitalService; _hospitalService = hospitalService;
_perExcelService = perExcelService;
_logger = logger; _logger = logger;
_evn = evn; _evn = evn;
_claim = claim; _claim = claim;
_configService = configService;
} }
/// <summary> /// <summary>
...@@ -138,8 +136,8 @@ public ApiResponse Import([FromForm] IFormCollection form) ...@@ -138,8 +136,8 @@ public ApiResponse Import([FromForm] IFormCollection form)
allot.UploadDate = DateTime.Now; allot.UploadDate = DateTime.Now;
if (!_allotService.Update(allot)) if (!_allotService.Update(allot))
return new ApiResponse(ResponseType.Fail, $"{file.FileName}上传成功,修改状态失败"); return new ApiResponse(ResponseType.Fail, $"{file.FileName}上传成功,修改状态失败");
_perExcelService.Clear(allot.ID); _configService.Clear(allot.ID);
_perExcelService.Copy(allot); _configService.Copy(allot);
} }
return new ApiResponse(ResponseType.OK); return new ApiResponse(ResponseType.OK);
...@@ -158,7 +156,7 @@ public ApiResponse Generate([CustomizeValidator(RuleSet = "Delete"), FromBody]Al ...@@ -158,7 +156,7 @@ public ApiResponse Generate([CustomizeValidator(RuleSet = "Delete"), FromBody]Al
if (null == allot || string.IsNullOrEmpty(allot.Path)) if (null == allot || string.IsNullOrEmpty(allot.Path))
throw new PerformanceException("当前绩效记录不存在或没有上传数据文件"); throw new PerformanceException("当前绩效记录不存在或没有上传数据文件");
//_perExcelService.Execute(allot); //_perExcelService.Execute(allot);
BackgroundJob.Enqueue(() => _perExcelService.Execute(allot)); BackgroundJob.Enqueue(() => _allotService.Generate(allot));
return new ApiResponse(ResponseType.OK); return new ApiResponse(ResponseType.OK);
} }
} }
......
...@@ -70,47 +70,6 @@ static void Main(string[] args) ...@@ -70,47 +70,6 @@ static void Main(string[] args)
options.UseMySQL(connection); options.UseMySQL(connection);
}); });
//PerHeaderService perHeaderService = new PerHeaderService();
//PerSheetService perSheetService = new PerSheetService(perHeaderService);
//PerExcelService perExcelService = new PerExcelService(perSheetService, perHeaderService);
//var excel = perExcelService.Import(@"E:\code_git\performance\performance\Performance.Api\Files\9\201911\医院绩效分配系统数据收集模板V120190307133444707.xlsx");
PerExcelService perExcelService = services.BuildServiceProvider().GetService<PerExcelService>();
// 拷贝配置信息
//perExcelService.Copy(allot.ID);
string path = @"E:\code_git\performance\performance\Performance.Api\Files\9\201911\医院绩效分配系统数据收集模板V120190307133444707.xlsx";
// 导出数据
var excel = perExcelService.Import(path);
var workbook1 = perExcelService.ExportCompute(excel.PerSheet);
using (FileStream file = new FileStream($@"F:\myworkbook\org_{DateTime.Now.ToString("yyyyMMddhhmmss")}.xlsx", FileMode.Create))
{
workbook1.Write(file);
}
// 保存数据
perExcelService.Save(excel.PerSheet, 2, 1);
// 计算合并数据
List<PerSheet> list = perExcelService.ProcessCompute(excel);
// 保存过程数据
perExcelService.Save(list, 2, 2);
// 生成结果excel
var workbook2 = perExcelService.ExportCompute(list);
using (FileStream file = new FileStream($@"F:\myworkbook\comp_{DateTime.Now.ToString("yyyyMMddhhmmss")}.xlsx", FileMode.Create))
{
workbook2.Write(file);
}
// 计算最总数据
//perExcelService.Compute(excel);
Console.ReadKey(); Console.ReadKey();
} }
} }
......
...@@ -30,7 +30,7 @@ public enum SheetType ...@@ -30,7 +30,7 @@ public enum SheetType
[Description("特殊核算单元")] [Description("特殊核算单元")]
SpecialUnit = 8, SpecialUnit = 8,
[Description("临床科室医护绩效测算基础")] [Description("临床科室医护绩效测算基础")]
DeptAccounting = 9, AccountBasic = 9,
[Description("科室经济核算汇总表")] [Description("科室经济核算汇总表")]
ComputeEconomic = 10, ComputeEconomic = 10,
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
// * history : Created by T4 2019-03-06 16:43:31 // * history : Created by T4 2019-03-06 16:43:31
// </copyright> // </copyright>
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
using System;
using Performance.EntityModels; using Performance.EntityModels;
using System;
namespace Performance.Repository namespace Performance.Repository
{ {
...@@ -14,8 +14,16 @@ namespace Performance.Repository ...@@ -14,8 +14,16 @@ namespace Performance.Repository
/// </summary> /// </summary>
public class PerforPerAllotRepository : PerforRepository<per_allot> public class PerforPerAllotRepository : PerforRepository<per_allot>
{ {
public PerforPerAllotRepository(PerformanceDbContext context) : base(context) public PerforPerAllotRepository(PerformanceDbContext context) : base(context)
{
}
public bool UpdateAllotStates(int allotId, int states, string remark)
{ {
var allot = GetEntity(t => t.ID == allotId);
allot.States = states;
allot.Remark = remark;
return Update(allot);
} }
} }
} }
using Performance.DtoModels;
using Performance.EntityModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Performance.Services.AllotCompute
{
/// <summary>
/// 绩效标准数据
/// </summary>
public class BaiscNormService : IAutoInjection
{
/// <summary>
/// 获取绩效标准基础值
/// </summary>
/// <param name="baiscnorms"></param>
/// <param name="type"></param>
/// <returns></returns>
public decimal? GetBaiscNorm(List<res_baiscnorm> baiscnorms, PerformanceType type)
{
decimal? result = null;
if (type == PerformanceType.ReferenceDirector)
{
result = baiscnorms.FirstOrDefault(t => t.PositionName == "临床科主任")?.AvgValue;
}
else if (type == PerformanceType.ReferenceDirectorAvg)
{
List<string> avgObjectList = new List<string> { "临床科主任", "临床科副主任", "医技科主任", "临床科护长" };
var baisc = baiscnorms.Where(t => avgObjectList.Contains(t.PositionName));
result = baisc.Sum(s => s.TotelValue) / baisc.Sum(s => s.TotelNumber);
}
else if (type == PerformanceType.ReferenceHeadNurse)
{
result = baiscnorms.FirstOrDefault(t => t.PositionName == "临床科护长")?.AvgValue;
}
else if (type == PerformanceType.ReferenceNurseAvg95)
{
result = baiscnorms.FirstOrDefault(t => t.PositionName == "临床护士")?.AvgValue * 0.95m;
}
if (result.HasValue)
result = Math.Round(result.Value, 4);
return result;
}
/// <summary>
/// 获取临床护士平均绩效
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
public res_baiscnorm NurseBaiscnorm(List<PerSheet> list)
{
var sheet = list.FirstOrDefault(t => t.SheetType == SheetType.ComputeNurseAccount);
var perdata = sheet.PerData.Select(t => (PerDataAccountNurse)t);
return new res_baiscnorm
{
PositionName = "临床护士",
TotelNumber = perdata.Sum(t => t.Number),
TotelValue = perdata.Sum(t => t.PerforTotal),
AvgValue = perdata.Sum(t => t.PerforTotal) / perdata.Sum(t => t.Number)
};
}
/// <summary>
/// 绩效标准计算
/// </summary>
/// <param name="computes"></param>
/// <returns></returns>
public List<res_baiscnorm> ComputeAvg(List<ComputeResult> computes)
{
var keyList = new[]
{
new { type = "临床科室", reference = "科室主任人均绩效", groupname = "临床科主任" },
new { type = "临床科室", reference = "科室副主任人均绩效", groupname = "临床科副主任" },
new { type = "医技科室", reference = "科室主任人均绩效", groupname = "医技科主任" },
new { type = "临床科室", reference = "科室护士长人均绩效", groupname = "临床科护长" },
};
var groupList = from cp in computes
join gp in keyList on new { type = cp.AccountType, reference = cp.FitPeople } equals new { gp.type, gp.reference }
select new { gp.groupname, cp };
var result = groupList.GroupBy(t => t.groupname)
.Select(s => new res_baiscnorm
{
PositionName = s.Key,
TotelNumber = s.Count(),
TotelValue = s.Sum(t => t.cp.GiveFee),
AvgValue = s.Sum(t => t.cp.GiveFee) / s.Count()
});
return result.ToList();
}
}
}
using Performance.DtoModels;
using Performance.EntityModels;
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.Services.AllotCompute
{
public class CheckDataService : IAutoInjection
{
internal bool Check(PerExcel excel, per_allot allot)
{
return true;
}
}
}
using AutoMapper;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using Performance.DtoModels;
using Performance.EntityModels;
using Performance.Infrastructure;
using Performance.Repository;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Performance.Services.AllotCompute
{
public class ImportDataService : IAutoInjection
{
private PerSheetService perSheetService;
private PerforPerSheetRepository perforPerSheetRepository;
private PerforImDataRepository perforImDataRepository;
private PerforImHeaderRepository perforImHeaderRepository;
private PerforImEmployeeRepository perforImEmployeeRepository;
private PerforImaccountbasicRepository perforImaccountbasicRepository;
private PerforImspecialunitRepository perforImspecialunitRepository;
public ImportDataService(PerSheetService perSheetService,
PerforPerSheetRepository perforPerSheetRepository,
PerforImDataRepository perforImDataRepository,
PerforImHeaderRepository perforImHeaderRepository,
PerforImEmployeeRepository perforImEmployeeRepository,
PerforImaccountbasicRepository perforImaccountbasicRepository,
PerforImspecialunitRepository perforImspecialunitRepository)
{
this.perSheetService = perSheetService;
this.perforPerSheetRepository = perforPerSheetRepository;
this.perforImDataRepository = perforImDataRepository;
this.perforImHeaderRepository = perforImHeaderRepository;
this.perforImEmployeeRepository = perforImEmployeeRepository;
this.perforImaccountbasicRepository = perforImaccountbasicRepository;
this.perforImspecialunitRepository = perforImspecialunitRepository;
}
/// <summary>
/// 读取excel并保存
/// </summary>
/// <param name="allot"></param>
/// <returns></returns>
public PerExcel ReadDataAndSave(per_allot allot)
{
var excel = Import(allot.Path);
Save(excel, allot.ID);
return excel;
}
/// <summary>
/// 导入excel数据
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
private PerExcel Import(string path)
{
PerExcel excel = new PerExcel
{
Path = path,
FileName = FileHelper.GetFileNameNoExtension(path),
Version = FileHelper.GetExtension(path) == ".xlsx" ? ExcelVersion.xlsx : ExcelVersion.xls,
PerSheet = new List<PerSheet>()
};
using (FileStream fs = new FileStream(path, FileMode.Open))
{
IWorkbook workbook = (excel.Version == ExcelVersion.xlsx)
? (IWorkbook)(new XSSFWorkbook(fs))
: (IWorkbook)(new HSSFWorkbook(fs));
for (int i = 0; i < workbook.NumberOfSheets; i++)
{
var sheet = workbook.GetSheetAt(i);
if (SheetType.Unidentifiable != perSheetService.GetSheetType(sheet.SheetName))
{
var st = perSheetService.Sheet(sheet);
excel.PerSheet.Add(st);
}
}
return excel;
}
}
/// <summary>
/// 保存医院人员
/// </summary>
/// <param name="sheet"></param>
/// <param name="allotId"></param>
/// <returns></returns>
private void SaveEmployee(PerSheet sheet, int allotId)
{
var imsheet = new per_sheet { AllotID = allotId, SheetName = sheet.SheetName, Source = 1, SheetType = (int)sheet.SheetType };
perforPerSheetRepository.Add(imsheet);
var dataList = sheet.PerData.Select(t => (PerDataEmployee)t);
List<im_employee> addList = new List<im_employee>();
foreach (var data in dataList)
{
var imdata = Mapper.Map<im_employee>(data);
imdata.SheetID = imsheet.ID;
imdata.AllotID = allotId;
addList.Add(imdata);
}
perforImEmployeeRepository.AddRange(addList.ToArray());
}
/// <summary>
/// 保存科室绩效基础表
/// </summary>
/// <param name="sheet"></param>
/// <param name="allotId"></param>
/// <returns></returns>
private void SaveAccountBasic(PerSheet sheet, int allotId)
{
var imsheet = new per_sheet { AllotID = allotId, SheetName = sheet.SheetName, Source = 1, SheetType = (int)sheet.SheetType };
perforPerSheetRepository.Add(imsheet);
var dataList = sheet.PerData.Select(t => (PerDataAccountBaisc)t);
List<im_accountbasic> addList = new List<im_accountbasic>();
foreach (var data in dataList)
{
var imdata = Mapper.Map<im_accountbasic>(data);
imdata.SheetID = imsheet.ID;
imdata.AllotID = allotId;
addList.Add(imdata);
}
perforImaccountbasicRepository.AddRange(addList.ToArray());
}
/// <summary>
/// 保存特殊科室
/// </summary>
/// <param name="sheet"></param>
/// <param name="allotId"></param>
/// <returns></returns>
private void SaveSpecialUnit(PerSheet sheet, int allotId)
{
var imsheet = new per_sheet { AllotID = allotId, SheetName = sheet.SheetName, Source = 1, SheetType = (int)sheet.SheetType };
perforPerSheetRepository.Add(imsheet);
var dataList = sheet.PerData.Select(t => (PerDataSpecialUnit)t);
List<im_specialunit> addList = new List<im_specialunit>();
foreach (var data in dataList)
{
var imdata = Mapper.Map<im_specialunit>(data);
imdata.SheetID = imsheet.ID;
imdata.AllotID = allotId;
addList.Add(imdata);
}
perforImspecialunitRepository.AddRange(addList.ToArray());
}
/// <summary>
/// 保存通用格式
/// </summary>
/// <param name="sheet"></param>
/// <param name="allotId"></param>
/// <returns></returns>
private void SaveCommon(PerSheet sheet, int allotId)
{
var imsheet = new per_sheet { AllotID = allotId, SheetName = sheet.SheetName, Source = 1, SheetType = (int)sheet.SheetType };
perforPerSheetRepository.Add(imsheet);
List<im_header> addHeadList = new List<im_header>();
foreach (var header in sheet.PerHeader)
{
var imheader = Mapper.Map<im_header>(header);
imheader.SheetID = imsheet.ID;
imheader.AllotID = allotId;
perforImHeaderRepository.Add(imheader);
if (header.IsHasChildren)
{
foreach (var child in header.Children)
{
var imheaderChild = Mapper.Map<im_header>(child);
imheaderChild.SheetID = imsheet.ID;
imheaderChild.ParentID = imheader.ID;
imheaderChild.AllotID = allotId;
addHeadList.Add(imheaderChild);
}
}
}
perforImHeaderRepository.AddRange(addHeadList.ToArray());
List<im_data> addDataList = new List<im_data>();
var dataList = sheet.PerData.Select(t => (PerData)t);
foreach (var data in dataList)
{
var imdata = Mapper.Map<im_data>(data);
imdata.SheetID = imsheet.ID;
imdata.AllotID = allotId;
addDataList.Add(imdata);
}
perforImDataRepository.AddRange(addDataList.ToArray());
}
private bool Save(PerExcel excel, int allotId)
{
foreach (var sheet in excel.PerSheet)
{
if (sheet.SheetType == SheetType.Employee)
{
SaveEmployee(sheet, allotId);
}
else if (sheet.SheetType == SheetType.AccountBasic)
{
SaveAccountBasic(sheet, allotId);
}
else if (sheet.SheetType == SheetType.SpecialUnit)
{
SaveSpecialUnit(sheet, allotId);
}
else
{
SaveCommon(sheet, allotId);
}
}
return true;
}
}
}
using AutoMapper;
using Performance.DtoModels;
using Performance.EntityModels;
using Performance.Infrastructure;
using Performance.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Performance.Services.AllotCompute
{
public class ResultComputeService : IAutoInjection
{
private ComputeDirector computeDirector;
private PerforImEmployeeRepository perforImEmployeeRepository;
private PerforCofworkyearRepository perforCofworkyearRepository;
private PerforCofdirectorRepository perforCofdirectorRepository;
private PerforResAccountdoctorRepository perforResAccountdoctorRepository;
private PerforResAccountnurseRepository perforResAccountnurseRepository;
private PerforRescomputeRepository perforRescomputeRepository;
private PerforResbaiscnormRepository perforResbaiscnormRepository;
private PerforResspecialunitRepository perforResspecialunitRepository;
public ResultComputeService(
PerforImEmployeeRepository perforImEmployeeRepository,
PerforCofworkyearRepository perforCofworkyearRepository,
PerforCofdirectorRepository perforCofdirectorRepository,
PerforResAccountdoctorRepository perforResAccountdoctorRepository,
PerforResAccountnurseRepository perforResAccountnurseRepository,
PerforRescomputeRepository perforRescomputeRepository,
PerforResbaiscnormRepository perforResbaiscnormRepository,
PerforResspecialunitRepository perforResspecialunitRepository,
ComputeDirector computeDirector)
{
this.computeDirector = computeDirector;
this.perforImEmployeeRepository = perforImEmployeeRepository;
this.perforCofworkyearRepository = perforCofworkyearRepository;
this.perforCofdirectorRepository = perforCofdirectorRepository;
this.perforResAccountdoctorRepository = perforResAccountdoctorRepository;
this.perforResAccountnurseRepository = perforResAccountnurseRepository;
this.perforRescomputeRepository = perforRescomputeRepository;
this.perforResbaiscnormRepository = perforResbaiscnormRepository;
this.perforResspecialunitRepository = perforResspecialunitRepository;
}
/// <summary>
/// 计算最终数据
/// </summary>
/// <param name="excel"></param>
public List<res_baiscnorm> Compute(per_allot allot, PerExcel excel, res_baiscnorm baiscnorm)
{
//取出人员信息
var empolyeeList = perforImEmployeeRepository.GetEntities(t => t.AllotID == allot.ID);
//年资系数
var workyearList = perforCofworkyearRepository.GetEntities(t => t.AllotID == allot.ID);
//规模绩效和效率绩效配置表
var directorList = perforCofdirectorRepository.GetEntities(t => t.AllotID == allot.ID);
//取出医生科室
var doctorList = perforResAccountdoctorRepository.GetEntities(t => t.AllotID == allot.ID);
//取出护士科室
var nurseList = perforResAccountnurseRepository.GetEntities(t => t.AllotID == allot.ID);
List<ComputeEmployee> computeEmployees = Mapper.Map<List<ComputeEmployee>>(empolyeeList);
List<ComputeSource> computeSources = new List<ComputeSource>();
computeSources.AddRange(Mapper.Map<List<ComputeSource>>(doctorList));
computeSources.AddRange(Mapper.Map<List<ComputeSource>>(nurseList));
var computResult = computeDirector.Compute(computeEmployees, computeSources, directorList);
var baiscnormList = computeDirector.ComputeAvg(computResult);
baiscnormList.Add(baiscnorm);
var computResult2 = computeDirector.Compute(computeEmployees, baiscnormList, workyearList);
var computes = Mapper.Map<List<res_compute>>(computResult);
computes.AddRange(Mapper.Map<List<res_compute>>(computResult2));
computes.ForEach(t => t.AllotID = allot.ID);
perforRescomputeRepository.AddRange(computes.ToArray());
baiscnormList.ForEach(t => t.AllotID = allot.ID);
perforResbaiscnormRepository.AddRange(baiscnormList.ToArray());
return baiscnormList;
}
/// <summary>
/// 特殊科室绩效计算
/// </summary>
/// <param name="excel"></param>
/// <param name="allot"></param>
public void SpecialUnitCompute(PerExcel excel, per_allot allot, List<res_baiscnorm> baiscnormList)
{
var specialUnit = excel.PerSheet.FirstOrDefault(t => t.SheetType == SheetType.SpecialUnit);
if (specialUnit == null || specialUnit.PerData.Count == 0)
return;
var dataList = specialUnit.PerData.Select(t => (PerDataSpecialUnit)t);
BaiscNormService baiscNormService = new BaiscNormService();
var typeList = EnumHelper.GetItems<PerformanceType>();
List<res_specialunit> resDataList = new List<res_specialunit>();
foreach (var t in dataList)
{
var type = typeList.FirstOrDefault(o => o.Description == t.QuantitativeIndicators);
if (type != null)
t.QuantitativeIndicatorsValue = baiscNormService.GetBaiscNorm(baiscnormList, (PerformanceType)type.Value);
var res = new res_specialunit
{
AllotID = allot.ID,
AccountingUnit = t.AccountingUnit,
Department = t.AccountingUnit,
Number = t.Number,
QuantitativeIndicators = t.QuantitativeIndicators,
Quantity = t.Quantity,
QuantitativeIndicatorsValue = t.QuantitativeIndicatorsValue,
ScoringAverage = t.ScoringAverage,
OtherPerfor = t.OtherPerfor,
Punishment = t.Punishment,
Adjust = t.Adjust,
Avg = t.Quantity * t.QuantitativeIndicatorsValue / t.Number,
ShouldFee = t.Quantity * t.QuantitativeIndicatorsValue,
GiveFee = (t.Quantity * t.QuantitativeIndicatorsValue + t.OtherPerfor + t.Punishment) * t.Adjust,
};
resDataList.Add(res);
}
perforResspecialunitRepository.AddRange(resDataList.ToArray());
}
}
}
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
using Performance.EntityModels; using Performance.EntityModels;
using Performance.Infrastructure; using Performance.Infrastructure;
using Performance.Repository; using Performance.Repository;
using Performance.Services.AllotCompute;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
...@@ -15,19 +16,35 @@ namespace Performance.Services ...@@ -15,19 +16,35 @@ namespace Performance.Services
{ {
public class AllotService : IAutoInjection public class AllotService : IAutoInjection
{ {
private PerforPerAllotRepository _allotRepository; private BaiscNormService baiscNormService;
private CheckDataService checkDataService;
private ImportDataService importDataService;
private ProcessComputService processComputService;
private ResultComputeService resultComputeService;
private IHostingEnvironment _evn; private IHostingEnvironment _evn;
private ILogger<AllotService> _logger; private ILogger<AllotService> _logger;
private PerforPerAllotRepository _allotRepository;
public AllotService(PerforPerAllotRepository allotRepository, public AllotService(PerforPerAllotRepository allotRepository,
IHostingEnvironment evn, BaiscNormService baiscNormService,
ILogger<AllotService> logger) CheckDataService checkDataService,
ImportDataService importDataService,
ProcessComputService processComputService,
ResultComputeService resultComputeService,
IHostingEnvironment evn, ILogger<AllotService> logger)
{ {
_allotRepository = allotRepository; _allotRepository = allotRepository;
_logger = logger; _logger = logger;
_evn = evn; _evn = evn;
this.baiscNormService = baiscNormService;
this.checkDataService = checkDataService;
this.importDataService = importDataService;
this.processComputService = processComputService;
this.resultComputeService = resultComputeService;
} }
#region 基础功能
/// <summary> /// <summary>
/// 绩效记录 /// 绩效记录
/// </summary> /// </summary>
...@@ -144,5 +161,36 @@ public bool Update(per_allot allot) ...@@ -144,5 +161,36 @@ public bool Update(per_allot allot)
{ {
return _allotRepository.Update(allot); return _allotRepository.Update(allot);
} }
#endregion
public void Generate(per_allot allot)
{
_allotRepository.UpdateAllotStates(allot.ID, (int)AllotStates.InCheckData, EnumHelper.GetDescription(AllotStates.InCheckData));
// 导出数据
var excel = importDataService.ReadDataAndSave(allot);
if (checkDataService.Check(excel, allot))
{
_allotRepository.UpdateAllotStates(allot.ID, (int)AllotStates.CheckFail, EnumHelper.GetDescription(AllotStates.CheckFail));
return;
}
_allotRepository.UpdateAllotStates(allot.ID, (int)AllotStates.InGenerate, EnumHelper.GetDescription(AllotStates.InGenerate));
// 计算合并数据
List<PerSheet> list = processComputService.MergeAndSave(excel, allot);
var baiscnorm = baiscNormService.NurseBaiscnorm(list);
// 计算最总数据
var baiscnormList = resultComputeService.Compute(allot, excel, baiscnorm);
resultComputeService.SpecialUnitCompute(excel, allot, baiscnormList);
_allotRepository.UpdateAllotStates(allot.ID, (int)AllotStates.GenerateSucceed, EnumHelper.GetDescription(AllotStates.GenerateSucceed));
//发送邮件
SendEmail(allot);
}
private void SendEmail(per_allot allot)
{
}
} }
} }
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
using Performance.Repository; using Performance.Repository;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
namespace Performance.Services namespace Performance.Services
...@@ -15,15 +16,18 @@ public class ConfigService : IAutoInjection ...@@ -15,15 +16,18 @@ public class ConfigService : IAutoInjection
private PerforCofdrugpropRepository _drugpropRepository; private PerforCofdrugpropRepository _drugpropRepository;
private PerforCofincomeRepository _incomeRepository; private PerforCofincomeRepository _incomeRepository;
private PerforCofworkyearRepository _workyearRepository; private PerforCofworkyearRepository _workyearRepository;
private PerforPerAllotRepository perforPerAllotRepository;
public ConfigService(PerforCofdirectorRepository cofdirectorRepository, public ConfigService(PerforCofdirectorRepository cofdirectorRepository,
PerforCofdrugpropRepository cofdrugpropRepository, PerforCofdrugpropRepository cofdrugpropRepository,
PerforCofincomeRepository cofincomeRepository, PerforCofincomeRepository cofincomeRepository,
PerforCofworkyearRepository cofworkyearRepository) PerforCofworkyearRepository cofworkyearRepository,
PerforPerAllotRepository perforPerAllotRepository)
{ {
this._directorRepository = cofdirectorRepository; this._directorRepository = cofdirectorRepository;
this._drugpropRepository = cofdrugpropRepository; this._drugpropRepository = cofdrugpropRepository;
this._incomeRepository = cofincomeRepository; this._incomeRepository = cofincomeRepository;
this._workyearRepository = cofworkyearRepository; this._workyearRepository = cofworkyearRepository;
this.perforPerAllotRepository = perforPerAllotRepository;
} }
#region cof_director #region cof_director
...@@ -261,5 +265,68 @@ public bool WorkDelete(WorkyearRequest request) ...@@ -261,5 +265,68 @@ public bool WorkDelete(WorkyearRequest request)
return _workyearRepository.Remove(workyear); return _workyearRepository.Remove(workyear);
} }
#endregion #endregion
/// <summary>
/// 清楚无效数据
/// </summary>
/// <param name="allotId"></param>
public void Clear(int allotId)
{
var director = _directorRepository.GetEntities(t => t.AllotID == allotId);
if (director != null)
_directorRepository.RemoveRange(director.ToArray());
var durgprop = _drugpropRepository.GetEntities(t => t.AllotID == allotId);
if (durgprop != null)
_drugpropRepository.RemoveRange(durgprop.ToArray());
var income = _incomeRepository.GetEntities(t => t.AllotID == allotId);
if (income != null)
_incomeRepository.RemoveRange(income.ToArray());
var workyear = _workyearRepository.GetEntities(t => t.AllotID == allotId);
if (workyear != null)
_workyearRepository.RemoveRange(workyear.ToArray());
}
/// <summary>
/// 复制报表基础配置
/// </summary>
/// <param name="iD"></param>
public void Copy(per_allot allot)
{
var list = perforPerAllotRepository.GetEntities(t => t.HospitalId == allot.HospitalId).OrderByDescending(t => t.Year).ThenBy(t => t.Month).ToList();
int allotId = 0;
for (int i = 0; i < list.Count; i++)
{
if (list[i].ID == allot.ID && (i - 1) >= 0)
allotId = list[i - 1].ID;
}
if (allotId > 0)
{
var director = _directorRepository.GetEntities(t => t.AllotID == allotId);
if (director != null)
{
var addData = director.Select(t => new cof_director { AllotID = allot.ID, JobTitle = t.JobTitle, TypeName = t.TypeName, Value = t.Value });
_directorRepository.AddRange(addData.ToArray());
}
var durgprop = _drugpropRepository.GetEntities(t => t.AllotID == allotId);
if (durgprop != null)
{
var addData = durgprop.Select(t => new cof_drugprop { AllotID = allot.ID, MaxRange = t.MaxRange, MinRange = t.MinRange, Value = t.Value });
_drugpropRepository.AddRange(addData.ToArray());
}
var income = _incomeRepository.GetEntities(t => t.AllotID == allotId);
if (income != null)
{
var addData = income.Select(t => new cof_income { AllotID = allot.ID, SheetNameKeyword = t.SheetNameKeyword, UnitName = t.UnitName, Value = t.Value });
_incomeRepository.AddRange(addData.ToArray());
}
var workyear = _workyearRepository.GetEntities(t => t.AllotID == allotId);
if (workyear != null)
{
var addData = workyear.Select(t => new cof_workyear { AllotID = allot.ID, MaxRange = t.MaxRange, MinRange = t.MinRange, Value = t.Value });
_workyearRepository.AddRange(addData.ToArray());
}
}
}
} }
} }
...@@ -11,7 +11,7 @@ public class BaiscNormService : IAutoInjection ...@@ -11,7 +11,7 @@ public class BaiscNormService : IAutoInjection
{ {
public decimal? GetBaiscNorm(List<res_baiscnorm> baiscnorms, PerformanceType type) public decimal? GetBaiscNorm(List<res_baiscnorm> baiscnorms, PerformanceType type)
{ {
decimal? result = null; decimal? result = null;
if (type == PerformanceType.ReferenceDirector) if (type == PerformanceType.ReferenceDirector)
{ {
result = baiscnorms.FirstOrDefault(t => t.PositionName == "临床科主任")?.AvgValue; result = baiscnorms.FirstOrDefault(t => t.PositionName == "临床科主任")?.AvgValue;
......
using Performance.DtoModels; using Performance.DtoModels;
using Performance.EntityModels; using Performance.EntityModels;
using Performance.Infrastructure; using Performance.Infrastructure;
using Performance.Services.AllotCompute;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
...@@ -13,6 +14,12 @@ namespace Performance.Services ...@@ -13,6 +14,12 @@ namespace Performance.Services
/// </summary> /// </summary>
public class ComputeDirector : IAutoInjection public class ComputeDirector : IAutoInjection
{ {
private BaiscNormService baiscNormService;
public ComputeDirector(BaiscNormService baiscNormService)
{
this.baiscNormService = baiscNormService;
}
/// <summary> /// <summary>
/// 临床科室主任、临床科室副主任、临床科室护士长 计算 /// 临床科室主任、临床科室副主任、临床科室护士长 计算
/// </summary> /// </summary>
...@@ -122,7 +129,6 @@ public List<ComputeResult> Compute(List<ComputeEmployee> empolyeeList, List<res_ ...@@ -122,7 +129,6 @@ public List<ComputeResult> Compute(List<ComputeEmployee> empolyeeList, List<res_
PerformanceType.ReferenceHeadNurse, PerformanceType.ReferenceHeadNurse,
PerformanceType.Null, PerformanceType.Null,
}; };
BaiscNormService baiscNormService = new BaiscNormService();
List<ComputeResult> computeList = new List<ComputeResult>(); List<ComputeResult> computeList = new List<ComputeResult>();
foreach (var type in types) foreach (var type in types)
......
...@@ -318,7 +318,7 @@ public void Save(List<PerSheet> perSheets, int allotId, int source) ...@@ -318,7 +318,7 @@ public void Save(List<PerSheet> perSheets, int allotId, int source)
_perforImEmployeeRepository.Add(imdata); _perforImEmployeeRepository.Add(imdata);
} }
} }
else if (sheet.SheetType == SheetType.DeptAccounting) else if (sheet.SheetType == SheetType.AccountBasic)
{ {
var dataList = sheet.PerData.Select(t => (PerDataAccountBaisc)t); var dataList = sheet.PerData.Select(t => (PerDataAccountBaisc)t);
List<im_accountbasic> addList = new List<im_accountbasic>(); List<im_accountbasic> addList = new List<im_accountbasic>();
...@@ -409,77 +409,6 @@ public void Save(List<PerSheet> perSheets, int allotId, int source) ...@@ -409,77 +409,6 @@ public void Save(List<PerSheet> perSheets, int allotId, int source)
//throw new NotImplementedException(); //throw new NotImplementedException();
} }
public IWorkbook ExportCompute(List<PerSheet> sheetList)
{
IWorkbook workbook = new XSSFWorkbook();
var cellstyle = workbook.CreateCellStyle();
cellstyle.VerticalAlignment = VerticalAlignment.Center;
cellstyle.Alignment = HorizontalAlignment.Center;
foreach (var sheet in sheetList)
{
ISheet exportSheet = workbook.CreateSheet(sheet.SheetName);
//创建列头行
IRow row = null, childRow = null;
foreach (var header in sheet.PerHeader.OrderBy(t => t.PointCell))
{
row = CreateRow(cellstyle, exportSheet, row, header);
//创建二级列头
if (header.IsHasChildren)
{
foreach (var child in header.Children.OrderBy(t => t.PointCell))
{
childRow = CreateRow(cellstyle, exportSheet, childRow, child);
}
}
}
//反转列头
var headList = _perHeaderService.GetPerHeaderReverse(sheet.PerHeader);
var dataList = sheet.PerData.Select(t => (PerData)t);
var maxrow = headList.Max(t => t.PointRow);
//循环核算单元 创建数据行
var accountingUnitList = dataList.OrderBy(t => t.RowNumber).Select(t => t.AccountingUnit).Distinct();
for (int i = 0; i < accountingUnitList.Count(); i++)
{
var accountingUnit = accountingUnitList.ElementAt(i);
IRow dataRow = exportSheet.CreateRow(i + maxrow + 2);
dataRow.CreateCell(0).SetCellValue(accountingUnit);
dataRow.GetCell(0).CellStyle = cellstyle;
foreach (var header in headList.OrderBy(t => t.PointCell))
{
var cellValue = dataList.FirstOrDefault(t => t.AccountingUnit == accountingUnit && t.TypeName == header.CellValue)?.CellValue;
if (cellValue.HasValue && cellValue.Value > 0)
{
dataRow.CreateCell(header.PointCell).SetCellValue(Convert.ToDouble(cellValue.Value));
dataRow.GetCell(header.PointCell).CellStyle = cellstyle;
}
}
}
}
return workbook;
}
/// <summary>
/// 创建行
/// </summary>
/// <param name="cellstyle"></param>
/// <param name="exportSheet"></param>
/// <param name="row"></param>
/// <param name="header"></param>
/// <returns></returns>
private IRow CreateRow(ICellStyle cellstyle, ISheet exportSheet, IRow row, PerHeader header)
{
if (header.IsMerge)
{
var cellRange = new CellRangeAddress(header.PointRow, header.PointRow + header.MergeRow - 1, header.PointCell, header.PointCell + header.MergeCell - 1);
exportSheet.AddMergedRegion(cellRange);
}
row = row ?? exportSheet.CreateRow(header.PointRow);
row.CreateCell(header.PointCell).SetCellValue(header.CellValue);
row.GetCell(header.PointCell).CellStyle = cellstyle;
return row;
}
/// <summary> /// <summary>
/// 计算最终数据 /// 计算最终数据
/// </summary> /// </summary>
......
...@@ -38,7 +38,7 @@ public static IPerSheetDataRead GetDataRead(SheetType sheetType) ...@@ -38,7 +38,7 @@ public static IPerSheetDataRead GetDataRead(SheetType sheetType)
case SheetType.Workload: case SheetType.Workload:
dataread = new PerSheetDataReadWorkload(); dataread = new PerSheetDataReadWorkload();
break; break;
case SheetType.DeptAccounting: case SheetType.AccountBasic:
dataread = new PerSheetDataReadDeptAccountingt(); dataread = new PerSheetDataReadDeptAccountingt();
break; break;
case SheetType.SpecialUnit: case SheetType.SpecialUnit:
......
...@@ -66,7 +66,7 @@ public SheetType GetSheetType(string sheetName) ...@@ -66,7 +66,7 @@ public SheetType GetSheetType(string sheetName)
else if (sheetName.StartsWith("3.")) else if (sheetName.StartsWith("3."))
return SheetType.Workload; return SheetType.Workload;
else if (sheetName.StartsWith("4.1")) else if (sheetName.StartsWith("4.1"))
return SheetType.DeptAccounting; return SheetType.AccountBasic;
else if (sheetName.StartsWith("4.2")) else if (sheetName.StartsWith("4.2"))
return SheetType.SpecialUnit; return SheetType.SpecialUnit;
return SheetType.Unidentifiable; return SheetType.Unidentifiable;
...@@ -114,7 +114,7 @@ internal List<PerSheet> ProcessCompute(PerExcel excel) ...@@ -114,7 +114,7 @@ internal List<PerSheet> ProcessCompute(PerExcel excel)
twiceWorkloadResult2.Sheet.SheetType = SheetType.ComputeNurseWorkload; twiceWorkloadResult2.Sheet.SheetType = SheetType.ComputeNurseWorkload;
perSheet.Add(twiceWorkloadResult2.Sheet); perSheet.Add(twiceWorkloadResult2.Sheet);
var deptAccounting = excel.PerSheet.FirstOrDefault(t => t.SheetType == SheetType.DeptAccounting); var deptAccounting = excel.PerSheet.FirstOrDefault(t => t.SheetType == SheetType.AccountBasic);
var dataList = deptAccounting.PerData.Select(t => (PerDataAccountBaisc)t); var dataList = deptAccounting.PerData.Select(t => (PerDataAccountBaisc)t);
PerSheet doctorSheet = new PerSheet("医生组临床科室单元核算表", "医生组临床科室单元核算表", SheetType.ComputeDoctorAccount, new List<PerHeader>(), new List<IPerData>()); PerSheet doctorSheet = new PerSheet("医生组临床科室单元核算表", "医生组临床科室单元核算表", SheetType.ComputeDoctorAccount, new List<PerHeader>(), new List<IPerData>());
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Remove="PerExcelService\ComputeEmpolyee\BaiscNormService.cs" />
<Compile Remove="PerExcelService\PerExcelService.cs" />
<Compile Remove="PerExcelService\SheetDataCompute\PerSheetDataComputeEconomicMerge.cs" /> <Compile Remove="PerExcelService\SheetDataCompute\PerSheetDataComputeEconomicMerge.cs" />
</ItemGroup> </ItemGroup>
......
...@@ -76,7 +76,7 @@ public SheetExportResponse SheetExport(int sheetID) ...@@ -76,7 +76,7 @@ public SheetExportResponse SheetExport(int sheetID)
{ {
EmployeeExport(sheetID, response); EmployeeExport(sheetID, response);
} }
else if (sheet.SheetType == (int)SheetType.DeptAccounting) else if (sheet.SheetType == (int)SheetType.AccountBasic)
{ {
AccountBaiscExport(sheetID, response); AccountBaiscExport(sheetID, response);
} }
......
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