Commit 446b121e by lcx

新抽取方法调整

parent 67333612
...@@ -1805,6 +1805,11 @@ ...@@ -1805,6 +1805,11 @@
ExTypeId ExTypeId
</summary> </summary>
</member> </member>
<member name="P:Performance.EntityModels.ex_script.ConfigId">
<summary>
配置Id
</summary>
</member>
<member name="P:Performance.EntityModels.ex_script.IsEnable"> <member name="P:Performance.EntityModels.ex_script.IsEnable">
<summary> <summary>
是否可用 1 可用 2 不可用 是否可用 1 可用 2 不可用
......
...@@ -25,6 +25,10 @@ public class PerSheetPoint ...@@ -25,6 +25,10 @@ public class PerSheetPoint
/// 数据开始行 /// 数据开始行
/// </summary> /// </summary>
public int? DataFirstRowNum { get; set; } public int? DataFirstRowNum { get; set; }
/// <summary>
/// 数据开始列
/// </summary>
public int? DataFirstCellNum { get; set; }
public List<AccountingUnit> AccountingUnit { get; set; } public List<AccountingUnit> AccountingUnit { get; set; }
/// <summary> /// <summary>
......
...@@ -35,6 +35,11 @@ public class ex_script ...@@ -35,6 +35,11 @@ public class ex_script
/// ExTypeId /// ExTypeId
/// </summary> /// </summary>
public int TypeId { get; set; } public int TypeId { get; set; }
/// <summary>
/// 配置Id
/// </summary>
public int ConfigId { get; set; }
/// <summary> /// <summary>
/// 是否可用 1 可用 2 不可用 /// 是否可用 1 可用 2 不可用
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Performance.Services.ExtractExcelService.ExtractHelper namespace Performance.Services.ExtractExcelService
{ {
public static class ExcelHelper public static class ExcelHelper
{ {
......
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.Services.ExtractExcelService.ExtractHelper
{
class ExtractDataHelper
{
}
}
using NPOI.SS.UserModel;
using Performance.DtoModels;
using Performance.EntityModels;
using Performance.Infrastructure;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Performance.Services.ExtractExcelService
{
public class ExtractHelper
{
public static (string template, string filepath) GetExtractFile(int hospitalId, string allotFilePath = "")
{
string originalPath = string.IsNullOrEmpty(allotFilePath)
? Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Template", "医院绩效模板.xls")
: allotFilePath;
return CopyOriginalFile(hospitalId, originalPath);
}
private static (string TempPath, string FilePath) CopyOriginalFile(int hospitalId, string originalPath)
{
var ext = FileHelper.GetExtension(originalPath);
var dpath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Files", $"{hospitalId}", "autoextract");
FileHelper.CreateDirectory(dpath);
string tempPath = Path.Combine(dpath, $"Template{DateTime.Now.ToString("yyyyMMddHHmmssfff")}{ext}");
FileHelper.Copy(originalPath, tempPath);
string filePath = Path.Combine(dpath, $"绩效提取数据{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.xls");
return (tempPath, filePath);
}
public static void CreateNotExistSheet(List<ex_module> modulesList, IWorkbook workbook)
{
SortedDictionary<string, int> pairs = new SortedDictionary<string, int>();
for (int i = 0; i < workbook.NumberOfSheets; i++)
{
var sheetname = workbook.GetSheetAt(i).SheetName;
if (!pairs.Keys.Contains(sheetname))
pairs.Add(workbook.GetSheetAt(i).SheetName, i);
}
int sheetIndex = 0;
int newSheetCount = 0;
foreach (var module in modulesList.Where(t => t.SheetType == (int)SheetType.Income)?.OrderBy(t => t.ModuleName))
{
var sheet = workbook.GetSheet(module.ModuleName);
if (sheet == null)
{
string[] keyArray = new string[] { "开单", "执行" };
if (keyArray.Any(key => module.ModuleName.Contains(key)))
{
var item = pairs.Where(t => t.Key.StartsWith("1.")).OrderByDescending(t => t.Key).First();
if (sheetIndex == 0)
sheetIndex = item.Value + 1;
var copysheet = workbook.GetSheet(item.Key);
var newSheet = copysheet.CopySheet(item.Key + Guid.NewGuid().ToString("N"), true);
workbook.SetSheetOrder(newSheet.SheetName, sheetIndex);
workbook.SetSheetName(sheetIndex, module.ModuleName);
sheetIndex++; newSheetCount++;
}
}
}
sheetIndex = 0;
foreach (var module in modulesList.Where(t => t.SheetType == (int)SheetType.Workload)?.OrderBy(t => t.ModuleName))
{
var sheet = workbook.GetSheet(module.ModuleName);
if (sheet == null)
{
string key = "工作量";
if (module.ModuleName.Contains(key))
{
var item = pairs.Where(t => t.Key.StartsWith("3.")).OrderByDescending(t => t.Key).First();
if (sheetIndex == 0)
sheetIndex = item.Value + newSheetCount + 1;
var copysheet = workbook.GetSheet(item.Key);
var newSheet = copysheet.CopySheet(item.Key + Guid.NewGuid().ToString("N"), true);
workbook.SetSheetOrder(newSheet.SheetName, sheetIndex);
workbook.SetSheetName(sheetIndex, module.ModuleName);
sheetIndex++;
}
}
}
}
public static void ClearSheetPartialData(ISheet sheet, PerSheetPoint point, SheetType sheetType)
{
if (sheet == null)
return;
for (int i = point.DataFirstRowNum.Value; i < sheet.LastRowNum + 1; i++)
{
var row = sheet.GetRow(i);
if (row != null)
{
int dataFirstCellRowNum = point.DataFirstCellNum.Value;
//跳过核算单元和科室
for (int j = dataFirstCellRowNum; j < row.LastCellNum; j++)
{
var cell = row.GetCell(j);
if (cell != null && (cell.CellType != CellType.Formula || sheetType == SheetType.Income))
{
cell.RemoveCellComment();
row.RemoveCell(cell);
}
}
}
}
}
}
}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace Performance.Services.ExtractExcelService.ExtractHelper namespace Performance.Services.ExtractExcelService
{ {
public class WriteDataHelper public class WriteDataHelper
{ {
...@@ -16,7 +16,7 @@ public enum UnitType ...@@ -16,7 +16,7 @@ public enum UnitType
医技组 医技组
} }
public void WriteSheetHeader(ISheet sheet, PerSheetPoint point, SheetType sheetType, int fixedCount, List<ExcelHeader> headers) public void WriteSheetHeader(ISheet sheet, PerSheetPoint point, SheetType sheetType, List<ExcelHeader> headers)
{ {
if (headers == null || !headers.Any()) return; if (headers == null || !headers.Any()) return;
...@@ -32,8 +32,8 @@ public void WriteSheetHeader(ISheet sheet, PerSheetPoint point, SheetType sheetT ...@@ -32,8 +32,8 @@ public void WriteSheetHeader(ISheet sheet, PerSheetPoint point, SheetType sheetT
var workloadFactor = sheet.GetOrCreate(point.HeaderFirstRowNum.Value + 1); var workloadFactor = sheet.GetOrCreate(point.HeaderFirstRowNum.Value + 1);
// 去除excel中已存在的列 // 去除excel中已存在的列
int headerFirstCellNum = point.HeaderFirstCellNum.Value + fixedCount; int headerFirstCellNum = point.DataFirstCellNum.Value;
if (columnHeader.LastCellNum > point.HeaderFirstCellNum + fixedCount) if (columnHeader.LastCellNum > point.DataFirstCellNum)
{ {
for (int index = headerFirstCellNum; index < columnHeader.LastCellNum; index++) for (int index = headerFirstCellNum; index < columnHeader.LastCellNum; index++)
{ {
...@@ -75,37 +75,37 @@ public void WriteSheetHeader(ISheet sheet, PerSheetPoint point, SheetType sheetT ...@@ -75,37 +75,37 @@ public void WriteSheetHeader(ISheet sheet, PerSheetPoint point, SheetType sheetT
} }
} }
public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetType, int fixedCount, List<string> headers, List<ExtractTransDto> data) public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetType, List<string> headers, List<ExtractTransDto> data)
{ {
var columnHeader = sheet.GetOrCreate(point.HeaderFirstRowNum.Value); var columnHeader = sheet.GetOrCreate(point.HeaderFirstRowNum.Value);
int headerFirstRowNum = point.HeaderFirstRowNum.Value + 1; int headerFirstRowNum = point.HeaderFirstRowNum.Value + 1;
WriteSheetDataExistent(sheet, columnHeader, point, sheetType, fixedCount, headers, data, ref headerFirstRowNum); WriteSheetDataExistent(sheet, columnHeader, point, sheetType, headers, data, ref headerFirstRowNum);
if (data == null || !data.Any(t => !string.IsNullOrEmpty(t.Department))) return; if (data == null || !data.Any(t => !string.IsNullOrEmpty(t.Department))) return;
WriteSheetDataNonexistent(sheet, columnHeader, point, sheetType, fixedCount, headers, data, headerFirstRowNum); WriteSheetDataNonexistent(sheet, columnHeader, point, sheetType, headers, data, headerFirstRowNum);
} }
private void WriteSheetDataExistent(ISheet sheet, IRow columnHeader, PerSheetPoint point, SheetType sheetType, private void WriteSheetDataExistent(ISheet sheet, IRow columnHeader, PerSheetPoint point, SheetType sheetType,
int fixedCount, List<string> headers, List<ExtractTransDto> data, ref int headerFirstRowNum) List<string> headers, List<ExtractTransDto> data, ref int headerFirstRowNum)
{ {
if (sheet.LastRowNum > headerFirstRowNum) if (sheet.LastRowNum > headerFirstRowNum)
{ {
int headerFirstCellNum = point.HeaderFirstCellNum.Value + fixedCount; int dataFirstCellNum = point.DataFirstCellNum.Value;
for (int rowIndex = headerFirstRowNum; rowIndex < sheet.LastRowNum + 1; rowIndex++) for (int rowIndex = headerFirstRowNum; rowIndex < sheet.LastRowNum + 1; rowIndex++)
{ {
var row = sheet.GetRow(rowIndex); var row = sheet.GetRow(rowIndex);
if (row == null) continue; if (row == null) continue;
string department = row.GetOrCreate(headerFirstCellNum - 1).GetDecodeEscapes(); string department = row.GetOrCreate(dataFirstCellNum - 1).GetDecodeEscapes();
if (string.IsNullOrEmpty(department)) continue; if (string.IsNullOrEmpty(department)) continue;
var deptData = data.Where(t => t.Department == department); var deptData = data.Where(t => t.Department == department);
if (deptData == null || !deptData.Any()) continue; if (deptData == null || !deptData.Any()) continue;
for (int cellIndex = headerFirstCellNum; cellIndex < columnHeader.LastCellNum; cellIndex++) for (int cellIndex = dataFirstCellNum; cellIndex < columnHeader.LastCellNum; cellIndex++)
{ {
var column = columnHeader.GetOrCreate(cellIndex).GetDecodeEscapes(); var column = columnHeader.GetOrCreate(cellIndex).GetDecodeEscapes();
var cell = row.GetOrCreate(cellIndex); var cell = row.GetOrCreate(cellIndex);
...@@ -134,7 +134,7 @@ public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetTyp ...@@ -134,7 +134,7 @@ public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetTyp
} }
private void WriteSheetDataNonexistent(ISheet sheet, IRow columnHeader, PerSheetPoint point, SheetType sheetType, private void WriteSheetDataNonexistent(ISheet sheet, IRow columnHeader, PerSheetPoint point, SheetType sheetType,
int fixedCount, List<string> headers, List<ExtractTransDto> data, int headerFirstRowNum) List<string> headers, List<ExtractTransDto> data, int headerFirstRowNum)
{ {
var departments = data.Select(s => s.Department).Where(w => !string.IsNullOrEmpty(w)).Distinct().ToList(); var departments = data.Select(s => s.Department).Where(w => !string.IsNullOrEmpty(w)).Distinct().ToList();
...@@ -212,7 +212,7 @@ public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetTyp ...@@ -212,7 +212,7 @@ public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetTyp
/// </summary> /// </summary>
/// <param name="list"></param> /// <param name="list"></param>
/// <returns></returns> /// <returns></returns>
public string HasValue(params string[] list) public static string HasValue(params string[] list)
{ {
if (list == null || !list.Any()) return null; if (list == null || !list.Any()) return null;
......
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Performance.DtoModels; using Performance.DtoModels;
using Performance.EntityModels;
using Performance.Repository; using Performance.Repository;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
...@@ -12,6 +13,8 @@ public class ExtractService : IAutoInjection ...@@ -12,6 +13,8 @@ public class ExtractService : IAutoInjection
{ {
private readonly ILogger logger; private readonly ILogger logger;
private readonly LogManageService logService; private readonly LogManageService logService;
private readonly QueryService queryService;
private readonly PersonService personService;
private readonly PerSheetService perSheetService; private readonly PerSheetService perSheetService;
private readonly PerforHospitalRepository hospitalRepository; private readonly PerforHospitalRepository hospitalRepository;
private readonly PerforPerallotRepository perallotRepository; private readonly PerforPerallotRepository perallotRepository;
...@@ -20,6 +23,8 @@ public class ExtractService : IAutoInjection ...@@ -20,6 +23,8 @@ public class ExtractService : IAutoInjection
public ExtractService( public ExtractService(
ILogger<ExtractService> logger, ILogger<ExtractService> logger,
LogManageService logService, LogManageService logService,
QueryService queryService,
PersonService personService,
PerSheetService perSheetService, PerSheetService perSheetService,
PerforHospitalRepository hospitalRepository, PerforHospitalRepository hospitalRepository,
PerforPerallotRepository perallotRepository, PerforPerallotRepository perallotRepository,
...@@ -28,6 +33,8 @@ PerforcollectdataRepository perforcollectdataRepository ...@@ -28,6 +33,8 @@ PerforcollectdataRepository perforcollectdataRepository
{ {
this.logger = logger; this.logger = logger;
this.logService = logService; this.logService = logService;
this.queryService = queryService;
this.personService = personService;
this.perSheetService = perSheetService; this.perSheetService = perSheetService;
this.hospitalRepository = hospitalRepository; this.hospitalRepository = hospitalRepository;
this.perallotRepository = perallotRepository; this.perallotRepository = perallotRepository;
...@@ -55,6 +62,10 @@ public string Main(int allotId, int hospitalId, string email, string groupName = ...@@ -55,6 +62,10 @@ public string Main(int allotId, int hospitalId, string email, string groupName =
if (allots == null || !allots.Any(t => t.ID == allotId)) throw new Exception("绩效不存在"); if (allots == null || !allots.Any(t => t.ID == allotId)) throw new Exception("绩效不存在");
var allot = allots.First(t => t.ID == allotId); var allot = allots.First(t => t.ID == allotId);
var dict = new Dictionary<ExDataDict, object>();
var data = queryService.Handler(hospitalId, allot, ref dict);
var standData = StandDataFormat(hospitalId, data);
var statesArray = new int[] { (int)AllotStates.GenerateSucceed, (int)AllotStates.Archive }; var statesArray = new int[] { (int)AllotStates.GenerateSucceed, (int)AllotStates.Archive };
var lastAllot = allots.Where(t => statesArray.Contains(t.States))?.OrderByDescending(t => t.Year)?.ThenByDescending(t => t.Month)?.First(); var lastAllot = allots.Where(t => statesArray.Contains(t.States))?.OrderByDescending(t => t.Year)?.ThenByDescending(t => t.Month)?.First();
...@@ -72,5 +83,81 @@ public string Main(int allotId, int hospitalId, string email, string groupName = ...@@ -72,5 +83,81 @@ public string Main(int allotId, int hospitalId, string email, string groupName =
return extractFilePath; return extractFilePath;
} }
private void WriteToTemplate()
{ }
private void WriteToAllotFile()
{
}
/// <summary>
/// 标准数据格式, 匹配科室字典
/// </summary>
/// <param name="hospitalId"></param>
/// <param name="results"></param>
/// <returns></returns>
private List<ExtractTransDto> StandDataFormat(int hospitalId, List<ex_result> results)
{
if (results == null || !results.Any()) return new List<ExtractTransDto>();
var dict = personService.GetDepartments(hospitalId)?.ToList();
if (dict == null || !dict.Any())
return results.Select(t => new ExtractTransDto
{
SheetName = t.Source,
DoctorName = t.DoctorName,
PersonnelNumber = t.PersonnelNumber,
Department = t.Department,
Category = t.Category,
Value = (t.Fee ?? 0) == 0 ? null : t.Fee
}).ToList();
dict.ForEach(t =>
{
t.HISDeptName = WriteDataHelper.HasValue(t.HISDeptName, t.Department);
});
var data = results.GroupJoin(dict, outer => new { Department = outer.Department }, inner => new { Department = inner.HISDeptName }, (outer, inner) => new { outer, inner })
.Select(t =>
{
var dept = !string.IsNullOrEmpty(t.inner.FirstOrDefault()?.Department) ? t.inner.FirstOrDefault()?.Department : t.outer.Department;
return new ExtractTransDto
{
SheetName = t.outer.Source,
Department = dept,
Category = t.outer.Category,
DoctorName = t.outer.DoctorName,
PersonnelNumber = t.outer.PersonnelNumber,
Value = t.outer.Fee ?? 0,
OutDoctorAccounting = t.inner.FirstOrDefault(f => f.Department == dept)?.OutDoctorAccounting?.AccountingUnit,
OutNurseAccounting = t.inner.FirstOrDefault(f => f.Department == dept)?.OutNurseAccounting?.AccountingUnit,
OutTechnicAccounting = t.inner.FirstOrDefault(f => f.Department == dept)?.OutTechnicAccounting?.AccountingUnit,
InpatDoctorAccounting = t.inner.FirstOrDefault(f => f.Department == dept)?.InpatDoctorAccounting?.AccountingUnit,
InpatNurseAccounting = t.inner.FirstOrDefault(f => f.Department == dept)?.InpatNurseAccounting?.AccountingUnit,
InpatTechnicAccounting = t.inner.FirstOrDefault(f => f.Department == dept)?.InpatTechnicAccounting?.AccountingUnit,
};
});
var groupdata = data.GroupBy(t => new { t.Department, t.Category, t.SheetName }).Select(t => new ExtractTransDto
{
SheetName = t.Key.SheetName,
Department = t.Key.Department,
Category = t.Key.Category,
Value = t.Sum(group => group.Value) == 0 ? null : t.Sum(group => group.Value),
OutDoctorAccounting = t.First().OutDoctorAccounting,
OutNurseAccounting = t.First().OutNurseAccounting,
OutTechnicAccounting = t.First().OutTechnicAccounting,
InpatDoctorAccounting = t.First().InpatDoctorAccounting,
InpatNurseAccounting = t.First().InpatNurseAccounting,
InpatTechnicAccounting = t.First().InpatTechnicAccounting,
});
return groupdata.ToList();
}
} }
} }
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
namespace Performance.Services.ExtractExcelService.SheetDataWrite namespace Performance.Services.ExtractExcelService.SheetDataWrite
{ {
class ISheetDataWrite public interface ISheetDataWrite
{ {
void WriteSheetData();
} }
} }
...@@ -19,6 +19,7 @@ public class PerSheetDataReadIncome : IPerSheetDataRead ...@@ -19,6 +19,7 @@ public class PerSheetDataReadIncome : IPerSheetDataRead
HeaderLastRowNum = 4, HeaderLastRowNum = 4,
HeaderFirstCellNum = 3, HeaderFirstCellNum = 3,
DataFirstRowNum = 5, DataFirstRowNum = 5,
DataFirstCellNum = 7,
AccountingUnit = new List<AccountingUnit> AccountingUnit = new List<AccountingUnit>
{ {
//核算单元(医技组) //核算单元(医技组)
......
...@@ -19,6 +19,7 @@ public class PerSheetDataReadOtherIncome : IPerSheetDataRead ...@@ -19,6 +19,7 @@ public class PerSheetDataReadOtherIncome : IPerSheetDataRead
HeaderLastRowNum = 4, HeaderLastRowNum = 4,
HeaderFirstCellNum = 3, HeaderFirstCellNum = 3,
DataFirstRowNum = 5, DataFirstRowNum = 5,
DataFirstCellNum = 7,
AccountingUnit = new List<AccountingUnit> AccountingUnit = new List<AccountingUnit>
{ {
//核算单元(医技组) //核算单元(医技组)
......
...@@ -19,6 +19,7 @@ public class PerSheetDataReadWorkload : IPerSheetDataRead ...@@ -19,6 +19,7 @@ public class PerSheetDataReadWorkload : IPerSheetDataRead
HeaderLastRowNum = 1, HeaderLastRowNum = 1,
HeaderFirstCellNum = 1, HeaderFirstCellNum = 1,
DataFirstRowNum = 3, DataFirstRowNum = 3,
DataFirstCellNum = 3,
AccountingUnit = new List<AccountingUnit> AccountingUnit = new List<AccountingUnit>
{ {
new AccountingUnit new AccountingUnit
......
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