Commit 057fcc9e by lcx

Merge branch 'feature/自定义模板抽取' into develop

parents 907b19fb 52915361
...@@ -836,6 +836,9 @@ ...@@ -836,6 +836,9 @@
<member name="F:Performance.DtoModels.SheetType.Assess"> <member name="F:Performance.DtoModels.SheetType.Assess">
<summary> 考核 </summary> <summary> 考核 </summary>
</member> </member>
<member name="F:Performance.DtoModels.SheetType.Custom">
<summary> 自定义抽取模板 </summary>
</member>
<member name="T:Performance.DtoModels.AccountUnitType"> <member name="T:Performance.DtoModels.AccountUnitType">
<summary> <summary>
核算单元类型 核算单元类型
......
...@@ -187,6 +187,14 @@ public enum SheetType ...@@ -187,6 +187,14 @@ public enum SheetType
/// <summary> 考核 </summary> /// <summary> 考核 </summary>
[Description("考核")] [Description("考核")]
Assess = 38, //该参数作用类似于 其他工作量 Assess = 38, //该参数作用类似于 其他工作量
/// <summary> 医生收入 </summary>
[Description("医生收入")]
DoctorIncome = 100,
/// <summary> 自定义抽取模板 </summary>
[Description("自定义抽取模板")]
Custom = 101,
} }
/// <summary> /// <summary>
......
...@@ -267,7 +267,7 @@ public IEnumerable<dynamic> QueryData(sys_hospitalconfig config, string execsql, ...@@ -267,7 +267,7 @@ public IEnumerable<dynamic> QueryData(sys_hospitalconfig config, string execsql,
/// </summary> /// </summary>
/// <param name="allot"></param> /// <param name="allot"></param>
/// <returns></returns> /// <returns></returns>
private Dictionary<string, string> GetParameters(per_allot allot) public Dictionary<string, string> GetParameters(per_allot allot)
{ {
DateTime beginTime = new DateTime(allot.Year, allot.Month, 1); DateTime beginTime = new DateTime(allot.Year, allot.Month, 1);
......
...@@ -552,7 +552,8 @@ public List<TitleValue> FeeType() ...@@ -552,7 +552,8 @@ public List<TitleValue> FeeType()
(int)SheetType.Expend, (int)SheetType.Expend,
(int)SheetType.Workload, (int)SheetType.Workload,
(int)SheetType.SpecialUnit, (int)SheetType.SpecialUnit,
(int)SheetType.OtherWorkload (int)SheetType.OtherWorkload,
(int)SheetType.Custom
}.Contains(t.Value)); }.Contains(t.Value));
if (type != null && type.Any()) if (type != null && type.Any())
{ {
......
...@@ -150,7 +150,7 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s ...@@ -150,7 +150,7 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s
var value = deptData.FirstOrDefault(t => t.Category.NoBlank() == column)?.Value; var value = deptData.FirstOrDefault(t => t.Category.NoBlank() == column)?.Value;
//数据为空,且单元格值不为空,不写入数据(保留原始值) //数据为空,且单元格值不为空,不写入数据(保留原始值)
var notWrite = !value.HasValue && !string.IsNullOrEmpty(cell.ToString()); var notWrite = !value.HasValue && !string.IsNullOrEmpty(cell.ToString());
if (cell.CellType != CellType.Formula && !notWrite) if (/*cell.CellType != CellType.Formula && */!notWrite)
{ {
cell.SetCellValue<decimal>(value); cell.SetCellValue<decimal>(value);
if (headers != null && headers.Contains(column)) if (headers != null && headers.Contains(column))
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
using Performance.EntityModels; using Performance.EntityModels;
using Performance.Infrastructure; using Performance.Infrastructure;
using Performance.Repository; using Performance.Repository;
using Performance.Services.ExtractExcelService.SheetDataWrite;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
...@@ -19,6 +20,7 @@ public class ExtractService : IAutoInjection ...@@ -19,6 +20,7 @@ public class ExtractService : IAutoInjection
private readonly PersonService personService; private readonly PersonService personService;
private readonly PerSheetService perSheetService; private readonly PerSheetService perSheetService;
private readonly DictionaryService dictionaryService; private readonly DictionaryService dictionaryService;
private readonly CustomDataWrite customDataWrite;
private readonly PerforPerallotRepository perallotRepository; private readonly PerforPerallotRepository perallotRepository;
private readonly PerforCollectdataRepository collectdataRepository; private readonly PerforCollectdataRepository collectdataRepository;
private readonly PerforPeremployeeRepository peremployeeRepository; private readonly PerforPeremployeeRepository peremployeeRepository;
...@@ -31,6 +33,7 @@ public class ExtractService : IAutoInjection ...@@ -31,6 +33,7 @@ public class ExtractService : IAutoInjection
PersonService personService, PersonService personService,
PerSheetService perSheetService, PerSheetService perSheetService,
DictionaryService dictionaryService, DictionaryService dictionaryService,
CustomDataWrite customDataWrite,
PerforPerallotRepository perallotRepository, PerforPerallotRepository perallotRepository,
PerforCollectdataRepository collectdataRepository, PerforCollectdataRepository collectdataRepository,
PerforPeremployeeRepository peremployeeRepository, PerforPeremployeeRepository peremployeeRepository,
...@@ -43,6 +46,7 @@ PerforPerdeptdicRepository perdeptdicRepository ...@@ -43,6 +46,7 @@ PerforPerdeptdicRepository perdeptdicRepository
this.personService = personService; this.personService = personService;
this.perSheetService = perSheetService; this.perSheetService = perSheetService;
this.dictionaryService = dictionaryService; this.dictionaryService = dictionaryService;
this.customDataWrite = customDataWrite;
this.perallotRepository = perallotRepository; this.perallotRepository = perallotRepository;
this.collectdataRepository = collectdataRepository; this.collectdataRepository = collectdataRepository;
this.peremployeeRepository = peremployeeRepository; this.peremployeeRepository = peremployeeRepository;
...@@ -142,19 +146,19 @@ private void WriteDataToFile(IWorkbook workbook, per_allot allot, Dictionary<ExD ...@@ -142,19 +146,19 @@ private void WriteDataToFile(IWorkbook workbook, per_allot allot, Dictionary<ExD
var types = new List<SheetType> { SheetType.OtherIncome, SheetType.Income, SheetType.Expend, SheetType.Workload, SheetType.OtherWorkload/*, SheetType.AccountBasic*/ }; var types = new List<SheetType> { SheetType.OtherIncome, SheetType.Income, SheetType.Expend, SheetType.Workload, SheetType.OtherWorkload/*, SheetType.AccountBasic*/ };
decimal ratio = 60m; decimal ratio = 60m;
string accountBasicSheetName = ""; //string accountBasicSheetName = "";
for (int sheetIndex = 0; sheetIndex < workbook.NumberOfSheets; sheetIndex++) //for (int sheetIndex = 0; sheetIndex < workbook.NumberOfSheets; sheetIndex++)
{ //{
var sheetName = workbook.GetSheetAt(sheetIndex).SheetName; // var sheetName = workbook.GetSheetAt(sheetIndex).SheetName;
if (!sheetName.StartsWith("4.1")) // if (!sheetName.StartsWith("4.1"))
continue; // continue;
accountBasicSheetName = sheetName; // accountBasicSheetName = sheetName;
break; // break;
} //}
var accountBasicSheet = workbook.GetSheet(accountBasicSheetName); //var accountBasicSheet = workbook.GetSheet(accountBasicSheetName);
HandleSheet(workbook, allot, exdict, extractDto, groupName, isSingle, accountBasicSheet, ratio, types, factory, style, employeeDict, collectData); //HandleSheet(workbook, allot, exdict, extractDto, groupName, isSingle, accountBasicSheet, ratio, types, factory, style, employeeDict, collectData);
for (int sheetIndex = 0; sheetIndex < workbook.NumberOfSheets; sheetIndex++) for (int sheetIndex = 0; sheetIndex < workbook.NumberOfSheets; sheetIndex++)
{ {
...@@ -162,6 +166,8 @@ private void WriteDataToFile(IWorkbook workbook, per_allot allot, Dictionary<ExD ...@@ -162,6 +166,8 @@ private void WriteDataToFile(IWorkbook workbook, per_allot allot, Dictionary<ExD
HandleSheet(workbook, allot, exdict, extractDto, groupName, isSingle, sheet, ratio, types, factory, style, employeeDict, collectData); HandleSheet(workbook, allot, exdict, extractDto, groupName, isSingle, sheet, ratio, types, factory, style, employeeDict, collectData);
} }
customDataWrite.WriteDataToCustom(workbook, allot, style);
} }
private void HandleSheet(IWorkbook workbook, per_allot allot, Dictionary<ExDataDict, object> exdict, List<ExtractTransDto> extractDto, string groupName, bool isSingle, private void HandleSheet(IWorkbook workbook, per_allot allot, Dictionary<ExDataDict, object> exdict, List<ExtractTransDto> extractDto, string groupName, bool isSingle,
......
...@@ -125,7 +125,7 @@ private List<int> GetQueryScriptIds(int hospitalId, ref Dictionary<ExDataDict, o ...@@ -125,7 +125,7 @@ private List<int> GetQueryScriptIds(int hospitalId, ref Dictionary<ExDataDict, o
{ {
var extypeIds = new List<int>(); var extypeIds = new List<int>();
var modules = exmoduleRepository.GetEntities(t => t.HospitalId == hospitalId); var modules = exmoduleRepository.GetEntities(t => t.HospitalId == hospitalId && t.SheetType != (int)SheetType.Custom);
var items = new List<ex_item>(); var items = new List<ex_item>();
if (modules != null && modules.Any()) if (modules != null && modules.Any())
{ {
......
using Microsoft.Extensions.Logging;
using NPOI.SS.UserModel;
using Performance.DtoModels;
using Performance.EntityModels;
using Performance.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Performance.Services.ExtractExcelService.SheetDataWrite
{
public class CustomDataWrite : IAutoInjection
{
private readonly ILogger<CustomDataWrite> logger;
private readonly PerforHospitalconfigRepository hospitalconfigRepository;
private readonly PerforExmoduleRepository exmoduleRepository;
private readonly PerforExscriptRepository exscriptRepository;
private readonly CustomExtractService customExtractService;
public CustomDataWrite(
ILogger<CustomDataWrite> logger,
PerforHospitalconfigRepository hospitalconfigRepository,
PerforExmoduleRepository exmoduleRepository,
PerforExscriptRepository exscriptRepository,
CustomExtractService customExtractService
)
{
this.logger = logger;
this.hospitalconfigRepository = hospitalconfigRepository;
this.exmoduleRepository = exmoduleRepository;
this.exscriptRepository = exscriptRepository;
this.customExtractService = customExtractService;
}
public PerSheetPoint Point => new PerSheetPoint
{
HeaderFirstRowNum = 1,
HeaderFirstCellNum = 6,
DataFirstRowNum = 2,
DataFirstCellNum = 6,
};
public void WriteDataToCustom(IWorkbook workbook, per_allot allot, ExcelStyle style)
{
var modules = exmoduleRepository.GetEntities(t => t.SheetType == (int)SheetType.Custom)?.OrderBy(t => t.ModuleName);
if (modules == null || !modules.Any()) return;
var exscripts = exscriptRepository.GetEntities(t => modules.Select(s => s.TypeId).Contains(t.TypeId));
if (exscripts == null || !exscripts.Any()) return;
var configs = hospitalconfigRepository.GetEntities(t => t.HospitalId == allot.HospitalId);
if (configs == null || !configs.Any()) throw new Exception("医院未配置绩效抽取信息");
var parameters = customExtractService.GetParameters(allot);
var headerStyle = style.SetBgkColorAndFormat(style.GetCellStyle(), StyleType.列头);
var cellStyle = style.SetBgkColorAndFormat(style.GetCellStyle(), StyleType.数据);
foreach (var module in modules)
{
var sheet = workbook.GetSheet(module.ModuleName) ?? workbook.GetSheet(module.ModuleName.NoBlank());
if (sheet == null)
{
sheet = workbook.CreateSheet(module.ModuleName);
workbook.SetSheetOrder(sheet.SheetName, workbook.NumberOfSheets - 1);
}
var exscript = exscripts.FirstOrDefault(t => t.TypeId == module.TypeId);
if (exscript == null) continue;
var conf = configs.FirstOrDefault(w => w.Id == (module.ConfigId ?? exscript.ConfigId));
if (conf == null) continue;
var execsql = exscript.ExecScript;
var dynamics = customExtractService.QueryData(conf, execsql, parameters);
try
{
// 没数据跳过
if (dynamics == null || dynamics.Count() == 0)
continue;
var first = (IDictionary<string, object>)dynamics.ElementAt(0);
var header = sheet.GetOrCreate(Point.HeaderFirstRowNum.Value);
if (header != null)
{
var cellindex = Point.HeaderFirstCellNum.Value;
foreach (var item in first)
{
var cell = header.GetOrCreate(cellindex);
cell.SetCellOValue(item.Key);
cell.CellStyle = headerStyle;
cellindex++;
}
}
var rowindex = Point.DataFirstRowNum.Value;
for (int r = 0; r < dynamics.Count(); r++)
{
var temp = (IDictionary<string, object>)dynamics.ElementAt(r); // 行数据
var row = sheet.GetOrCreate(rowindex);
var cellindex = Point.DataFirstCellNum.Value;
foreach (var item in temp)
{
var cell = row.GetOrCreate(cellindex);
cell.SetCellOValue(item.Value);
cell.CellStyle = cellStyle;
cellindex++;
}
rowindex++;
}
}
catch (Exception ex)
{
logger.LogError($"自定义模板 - {sheet.SheetName}抽取异常:" + ex);
}
}
}
}
}
...@@ -71,7 +71,7 @@ public string Execture(int allotId) ...@@ -71,7 +71,7 @@ public string Execture(int allotId)
var configs = hospitalconfigRepository.GetEntities(t => t.HospitalId == allot.HospitalId); var configs = hospitalconfigRepository.GetEntities(t => t.HospitalId == allot.HospitalId);
if (configs == null || !configs.Any()) throw new PerformanceException("未添加医院提取配置"); if (configs == null || !configs.Any()) throw new PerformanceException("未添加医院提取配置");
var types = extypeRepository.GetEntities(t => t.Source == 100); var types = extypeRepository.GetEntities(t => t.Source == (int)SheetType.DoctorIncome);
if (types == null || !types.Any()) throw new PerformanceException("未配置数据提取内容"); if (types == null || !types.Any()) throw new PerformanceException("未配置数据提取内容");
Dictionary<string, List<IncomeDataDto>> pairs = new Dictionary<string, List<IncomeDataDto>>(); Dictionary<string, List<IncomeDataDto>> pairs = new Dictionary<string, List<IncomeDataDto>>();
......
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