Commit 62702fe7 by lcx

抽取更改

parent 3fddbdd4
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.Services.ExtractExcelService
{
public class ExcelHeader
{
/// <summary>
/// Excel 列名
/// </summary>
public string ColumnName { get; set; }
/// <summary>
/// 护理组系数
/// </summary>
public decimal NurseFactor { get; set; }
/// <summary>
/// 医生组系数
/// </summary>
public decimal DoctorFactor { get; set; }
/// <summary>
/// 医技组系数
/// </summary>
public decimal TechnicianFactor { get; set; }
/// <summary>
/// 工作量系数
/// </summary>
public decimal WorkloadFactor { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.Services.ExtractExcelService
{
/// <summary>
/// 抽取结果(转换核算单元后)
/// </summary>
public class ExtractTransDto
{
/// <summary>
/// 医生姓名
/// </summary>
public string DoctorName { get; set; }
/// <summary>
/// 医生工号
/// </summary>
public string PersonnelNumber { get; set; }
/// <summary>
/// 科室
/// </summary>
public string Department { get; set; }
/// <summary>
/// 费用类别
/// </summary>
public string Category { get; set; }
/// <summary>
/// 费用
/// </summary>
public decimal? Value { get; set; }
/// <summary>
///
/// </summary>
public string SheetName { get; set; }
/// <summary>
/// 核算单元(门诊医生)
/// </summary>
public string OutDoctorAccounting { get; set; }
/// <summary>
/// 核算单元(门诊护理)
/// </summary>
public string OutNurseAccounting { get; set; }
/// <summary>
/// 核算单元(门诊医技)
/// </summary>
public string OutTechnicAccounting { get; set; }
/// <summary>
/// 核算单元(住院医生)
/// </summary>
public string InpatDoctorAccounting { get; set; }
/// <summary>
/// 核算单元(住院护理)
/// </summary>
public string InpatNurseAccounting { get; set; }
/// <summary>
/// 核算单元(住院医技)
/// </summary>
public string InpatTechnicAccounting { get; set; }
}
}
using NPOI.SS.UserModel;
using Performance.Infrastructure;
using System;
using System.Collections.Generic;
namespace Performance.Services.ExtractExcelService.ExtractHelper
{
public static class ExcelHelper
{
public static IRow GetOrCreate(this ISheet sheet, int index)
{
var row = sheet.GetRow(index);
if (row == null)
row = sheet.CreateRow(index);
return row;
}
public static ICell GetOrCreate(this IRow row, int index)
{
var cell = row.GetCell(index);
if (cell == null)
cell = row.CreateCell(index);
return cell;
}
public static void SetRowStyle(this IRow row, ICellStyle cellStyle)
{
List<ICell> cells = row.Cells;
foreach (var cell in cells)
{
cell.CellStyle = cellStyle;
}
}
public static void SetCellOValue(this ICell cell, object value)
{
if (cell == null) return;
if (value == null || string.IsNullOrWhiteSpace(value.ToString()))
cell.SetCellValue("");
try
{
string stringV = value.ToString();
var type = value.GetType();
switch (type.ToString())
{
#region SetValue
case "System.String"://字符串类型
cell.SetCellValue(stringV);
break;
case "System.DateTime"://日期类型
DateTime dateV;
DateTime.TryParse(stringV, out dateV);
cell.SetCellValue(dateV.ToString("yyyy/M/d"));
break;
case "System.Boolean"://布尔型
bool boolV = false;
bool.TryParse(stringV, out boolV);
cell.SetCellValue(boolV);
break;
case "System.Int16"://整型
case "System.Int32":
case "System.Int64":
case "System.Byte":
int intV = 0;
int.TryParse(stringV, out intV);
cell.SetCellValue(intV);
break;
case "System.Decimal"://浮点型
case "System.Double":
double doubV = 0;
double.TryParse(stringV, out doubV);
cell.SetCellValue(doubV);
break;
case "System.DBNull"://空值处理
cell.SetCellValue("");
break;
default:
cell.SetCellValue("");
break;
#endregion
}
}
catch
{
cell.SetCellValue("");
}
}
public static T GetCellValue<T>(this ICell cell)
{
try
{
cell.SetCellType(CellType.String);
string value = cell.StringCellValue;
return ConvertHelper.To<T>(value);
}
catch
{
return default;
}
}
/// <summary>
/// 获取去除转义后的字符
/// </summary>
/// <param name="cell"></param>
/// <returns></returns>
public static string GetDecodeEscapes(this ICell cell)
{
try
{
if (cell == null) return "";
cell.SetCellType(CellType.String);
string value = cell.StringCellValue;
if (!string.IsNullOrEmpty(value))
value = value.Replace("\n", "").Replace(" ", "").Trim();
return value;
}
catch
{
return "";
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.Services.ExtractExcelService.ExtractHelper
{
class ExtractDataHelper
{
}
}
using NPOI.SS.UserModel;
using Performance.DtoModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Performance.Services.ExtractExcelService.ExtractHelper
{
public class WriteDataHelper
{
public enum UnitType
{
护理组,
医生组,
医技组
}
public void WriteSheetHeader(ISheet sheet, PerSheetPoint point, SheetType sheetType, int fixedCount, List<ExcelHeader> headers)
{
// 收入支出系数
var nurseFactor = sheet.GetOrCreate(point.AccountingUnit.First(t => t.UnitType == UnitType.护理组.ToString()).FactorRow.Value);
var doctorFactor = sheet.GetRow(point.AccountingUnit.First(t => t.UnitType == UnitType.医生组.ToString()).FactorRow.Value);
var technicianFactor = sheet.GetRow(point.AccountingUnit.First(t => t.UnitType == UnitType.医技组.ToString()).FactorRow.Value);
// 费用类型
var columnHeader = sheet.GetOrCreate(point.HeaderFirstRowNum.Value);
// 工作量系数
var workloadFactor = sheet.GetOrCreate(point.HeaderFirstRowNum.Value + 1);
// 去除excel中已存在的列
int headerFirstCellNum = point.HeaderFirstCellNum.Value + fixedCount;
if (columnHeader.LastCellNum > point.HeaderFirstCellNum + fixedCount)
{
for (int index = headerFirstCellNum; index < columnHeader.LastCellNum; index++)
{
var column = columnHeader.GetCell(index).GetDecodeEscapes();
if (string.IsNullOrEmpty(column)) continue;
headers.RemoveAll(t => t.ColumnName == column);
if (index > headerFirstCellNum)
headerFirstCellNum = index + 1;
}
}
if (headers == null || !headers.Any()) return;
// 补充excel中不存在的列
foreach (var item in headers)
{
var columnCell = columnHeader.GetOrCreate(headerFirstCellNum);
columnCell.SetCellValue(item.ColumnName);
if (sheetType == SheetType.Workload)
{
var workloadCell = workloadFactor.GetOrCreate(headerFirstCellNum);
workloadCell.SetCellOValue(item.WorkloadFactor);
}
else
{
var doctorCell = doctorFactor.GetOrCreate(headerFirstCellNum);
doctorCell.SetCellOValue(item.DoctorFactor);
var nurseCell = nurseFactor.GetOrCreate(headerFirstCellNum);
nurseCell.SetCellOValue(item.NurseFactor);
var technicianCell = technicianFactor.GetOrCreate(headerFirstCellNum);
technicianCell.SetCellOValue(item.TechnicianFactor);
}
headerFirstCellNum++;
}
}
public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetType, int fixedCount, List<string> headers, List<ExtractTransDto> data)
{
var columnHeader = sheet.GetOrCreate(point.HeaderFirstRowNum.Value);
int headerFirstRowNum = point.HeaderFirstRowNum.Value + 1;
WriteSheetDataExistent(sheet, columnHeader, point, sheetType, fixedCount, headers, data, ref headerFirstRowNum);
if (data == null || !data.Any(t => !string.IsNullOrEmpty(t.Department))) return;
WriteSheetDataNonexistent(sheet, columnHeader, point, sheetType, fixedCount, headers, data, headerFirstRowNum);
}
private void WriteSheetDataExistent(ISheet sheet, IRow columnHeader, PerSheetPoint point, SheetType sheetType,
int fixedCount, List<string> headers, List<ExtractTransDto> data, ref int headerFirstRowNum)
{
if (sheet.LastRowNum > headerFirstRowNum)
{
int headerFirstCellNum = point.HeaderFirstCellNum.Value + fixedCount;
for (int rowIndex = headerFirstRowNum; rowIndex < sheet.LastRowNum + 1; rowIndex++)
{
var row = sheet.GetRow(rowIndex);
if (row == null) continue;
string department = row.GetOrCreate(headerFirstCellNum - 1).GetDecodeEscapes();
if (string.IsNullOrEmpty(department)) continue;
var deptData = data.Where(t => t.Department == department);
if (deptData == null || !deptData.Any()) continue;
for (int cellIndex = headerFirstCellNum; cellIndex < columnHeader.LastCellNum; cellIndex++)
{
var column = columnHeader.GetOrCreate(cellIndex).GetDecodeEscapes();
var cell = row.GetOrCreate(cellIndex);
var value = deptData.FirstOrDefault(t => t.Category == column)?.Value;
if (sheetType == SheetType.Income)
{
cell.SetCellOValue(value);
// 添加 style
}
else if (cell.CellType != CellType.Formula)
{
cell.SetCellOValue(value);
if (headers != null && headers.Contains(column))
{
// 是新增项,且该抽取数据在新增项中 添加style
}
}
}
data.RemoveAll(t => t.Department == department);
if (rowIndex > headerFirstRowNum) headerFirstRowNum = rowIndex + 1;
}
}
}
private void WriteSheetDataNonexistent(ISheet sheet, IRow columnHeader, PerSheetPoint point, SheetType sheetType,
int fixedCount, List<string> headers, List<ExtractTransDto> data, int headerFirstRowNum)
{
var departments = data.Select(s => s.Department).Where(w => !string.IsNullOrEmpty(w)).Distinct().ToList();
foreach (string department in departments)
{
}
}
public string HasValue(params string[] list)
{
if (list == null || !list.Any()) return null;
return list.FirstOrDefault(t => !string.IsNullOrEmpty(t));
}
}
}
using Microsoft.Extensions.Logging;
using Performance.DtoModels;
using Performance.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Performance.Services.ExtractExcelService
{
public class ExtractService : IAutoInjection
{
private readonly ILogger logger;
private readonly LogManageService logService;
private readonly PerSheetService perSheetService;
private readonly PerforHospitalRepository hospitalRepository;
private readonly PerforPerallotRepository perallotRepository;
private readonly PerforcollectdataRepository perforcollectdataRepository;
public ExtractService(
ILogger<ExtractService> logger,
LogManageService logService,
PerSheetService perSheetService,
PerforHospitalRepository hospitalRepository,
PerforPerallotRepository perallotRepository,
PerforcollectdataRepository perforcollectdataRepository
)
{
this.logger = logger;
this.logService = logService;
this.perSheetService = perSheetService;
this.hospitalRepository = hospitalRepository;
this.perallotRepository = perallotRepository;
this.perforcollectdataRepository = perforcollectdataRepository;
}
/// <summary>
/// 抽取绩效文件
/// </summary>
/// <param name="allotId">抽取绩效Id</param>
/// <param name="hospitalId">医院Id</param>
/// <param name="email">邮箱地址</param>
/// <param name="groupName">即时日志分组名称</param>
/// <param name="filePath">历史提交文件地址</param>
public string Main(int allotId, int hospitalId, string email, string groupName = null, string filePath = null)
{
string extractFilePath = "";
try
{
logService.ClearExtractLog(allotId);
var hospital = hospitalRepository.GetEntity(t => t.ID == hospitalId);
var allots = perallotRepository.GetEntities(t => t.HospitalId == hospitalId);
if (allots == null || !allots.Any(t => t.ID == allotId)) throw new Exception("绩效不存在");
var allot = allots.First(t => t.ID == allotId);
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();
extractFilePath = lastAllot != null && !string.IsNullOrEmpty(filePath) ? "" : "";
}
catch (Exception ex)
{
logger.LogError("提取数据中发生异常: " + ex.ToString());
}
finally
{
}
return extractFilePath;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.Services.ExtractExcelService.SheetDataWrite
{
class AccountBasicDataWrite
{
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.Services.ExtractExcelService.SheetDataWrite
{
class ClinicEmployeeDataWrite
{
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.Services.ExtractExcelService.SheetDataWrite
{
class EmployeeDataWrite
{
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.Services.ExtractExcelService.SheetDataWrite
{
class ExpendDataWrite
{
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.Services.ExtractExcelService.SheetDataWrite
{
class ISheetDataWrite
{
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.Services.ExtractExcelService.SheetDataWrite
{
class IncomeDataWrite
{
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.Services.ExtractExcelService.SheetDataWrite
{
class OtherIncomeDataWrite
{
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.Services.ExtractExcelService.SheetDataWrite
{
class SpecialUnitDataWrite
{
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.Services.ExtractExcelService.SheetDataWrite
{
class WorkloadDataWrite
{
}
}
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