Commit 932753f9 by lcx

获取workbook

parent 8e449b8b
......@@ -12,12 +12,14 @@ namespace Performance.Services.ExtractExcelService
{
public class ExtractHelper
{
public static (string template, string filepath) GetExtractFile(int hospitalId, string allotFilePath = "")
public static string GetExtractFile(int hospitalId, ref string newFilePath, string allotFilePath = "")
{
string originalPath = string.IsNullOrEmpty(allotFilePath)
? Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Template", "医院绩效模板.xls")
: allotFilePath;
return CopyOriginalFile(hospitalId, originalPath);
var (tempPath, filePath) = CopyOriginalFile(hospitalId, originalPath);
newFilePath = filePath;
return tempPath;
}
private static (string TempPath, string FilePath) CopyOriginalFile(int hospitalId, string originalPath)
......@@ -28,7 +30,6 @@ private static (string TempPath, string FilePath) CopyOriginalFile(int hospitalI
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);
}
......
......@@ -177,7 +177,7 @@ public static string HasValue(params string[] list)
}
/// <summary> 住院核算单元 </summary>
private readonly Dictionary<string, Func<ExtractTransDto, string>> fieldInpat = new Dictionary<string, Func<ExtractTransDto, string>>
private static readonly Dictionary<string, Func<ExtractTransDto, string>> fieldInpat = new Dictionary<string, Func<ExtractTransDto, string>>
{
{ "科室名称", (dto) => dto.Department },
{ "核算单元(医生组)", (dto) => new string []{ dto.InpatDoctorAccounting, dto.OutDoctorAccounting }.FirstOrDefault(t => !string.IsNullOrEmpty(t)) },
......@@ -186,7 +186,7 @@ public static string HasValue(params string[] list)
};
/// <summary> 门诊核算单元 </summary>
private readonly Dictionary<string, Func<ExtractTransDto, string>> fieldOut = new Dictionary<string, Func<ExtractTransDto, string>>
private static readonly Dictionary<string, Func<ExtractTransDto, string>> fieldOut = new Dictionary<string, Func<ExtractTransDto, string>>
{
{ "科室名称", (dto) => dto.Department },
{ "核算单元(医生组)", (dto) => new string []{ dto.OutDoctorAccounting, dto.InpatDoctorAccounting }.FirstOrDefault(t => !string.IsNullOrEmpty(t)) },
......@@ -195,7 +195,7 @@ public static string HasValue(params string[] list)
};
/// <summary> 医生工作量 </summary>
private readonly Dictionary<string, Func<ExtractTransDto, string>> fieldDoctor = new Dictionary<string, Func<ExtractTransDto, string>>
private static readonly Dictionary<string, Func<ExtractTransDto, string>> fieldDoctor = new Dictionary<string, Func<ExtractTransDto, string>>
{
{ "科室名称", (dto) => dto.Department },
{ "核算单元", (dto) =>
......@@ -208,7 +208,7 @@ public static string HasValue(params string[] list)
};
/// <summary> 护理工作量 </summary>
private readonly Dictionary<string, Func<ExtractTransDto, string>> fieldNurse = new Dictionary<string, Func<ExtractTransDto, string>>
private static readonly Dictionary<string, Func<ExtractTransDto, string>> fieldNurse = new Dictionary<string, Func<ExtractTransDto, string>>
{
{ "科室名称", (dto) => dto.Department },
{ "核算单元", (dto) => new string []{ dto.OutNurseAccounting, dto.InpatNurseAccounting }.FirstOrDefault(t => !string.IsNullOrEmpty(t)) },
......
using Microsoft.Extensions.Logging;
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;
......@@ -70,7 +72,8 @@ public string Main(int allotId, int hospitalId, string email, string groupName =
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) ? "" : "";
//extractFilePath = lastAllot != null && !string.IsNullOrEmpty(filePath) ? "" : "";
var templateFilePath = ExtractHelper.GetExtractFile(hospitalId, ref extractFilePath, filePath);
}
catch (Exception ex)
{
......@@ -84,17 +87,42 @@ public string Main(int allotId, int hospitalId, string email, string groupName =
return extractFilePath;
}
private void WriteDataToFile(string templateFile, string extractFile)
{
if (!FileHelper.IsExistFile(templateFile) || !FileHelper.IsExistFile(extractFile))
throw new PerformanceException("");
private void WriteToTemplate()
{
var workbook = ExcelHelper.GetWorkbook(templateFile);
if (workbook == null) throw new PerformanceException("文件读取失败");
ExtractHelper.CreateNotExistSheet(new List<ex_module>(), workbook);
WriteDataFactory factory = new WriteDataFactory();
for (int sheetIndex = 0; sheetIndex < workbook.NumberOfSheets; sheetIndex++)
{
var sheet = workbook.GetSheetAt(sheetIndex);
var sheetType = perSheetService.GetSheetType(sheet.SheetName);
var reader = PerSheetDataFactory.GetDataRead(sheetType)?.Point;
var customer = factory.GetWriteData(sheetType);
customer.GetType();
}
using (FileStream file = new FileStream(extractFile, FileMode.OpenOrCreate))
{
workbook.Write(file);
}
}
private void WriteToTemplate()
{
}
private void WriteToAllotFile()
{
{
}
/// <summary>
......
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.Services.ExtractExcelService.SheetDataWrite
{
class ExpendDataWrite : ISheetDataWrite
{
}
}
using System;
using NPOI.SS.UserModel;
using Performance.DtoModels;
using Performance.EntityModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Performance.Services.ExtractExcelService.SheetDataWrite
{
class IncomeDataWrite : ISheetDataWrite
public class IncomeDataWrite : ISheetDataWrite
{
public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetType, object data, List<ex_module> modules, List<ex_item> items)
{
var module = modules.FirstOrDefault(t => t.SheetType == (int)sheetType);
if (module == null) return;
var modelItems = items.Where(t => t.ModuleId == module.Id);
if (modelItems == null || !modelItems.Any()) return;
var headers = modelItems.Select(t => new ExcelHeader
{
ColumnName = t.ItemName,
DoctorFactor = t.FactorValue1 ?? 0,
NurseFactor = t.FactorValue2 ?? 0,
TechnicianFactor = t.FactorValue3 ?? 0
}).ToList();
WriteDataHelper.WriteSheetHeader(sheet, point, sheetType, headers);
if (data is List<ExtractTransDto> extractDto && extractDto.Any())
{
var columns = headers.Select(t => t.ColumnName).ToList();
WriteDataHelper.WriteSheetData(sheet, point, sheetType, columns, extractDto);
}
}
}
}
using System;
using NPOI.SS.UserModel;
using Performance.DtoModels;
using Performance.EntityModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Performance.Services.ExtractExcelService.SheetDataWrite
{
class WorkloadDataWrite : ISheetDataWrite
public class WorkloadDataWrite : ISheetDataWrite
{
public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetType, object data, List<ex_module> modules, List<ex_item> items)
{
var module = modules.FirstOrDefault(t => t.SheetType == (int)sheetType);
if (module == null) return;
var modelItems = items.Where(t => t.ModuleId == module.Id);
if (modelItems == null || !modelItems.Any()) return;
var headers = modelItems.Select(t => new ExcelHeader
{
ColumnName = t.ItemName,
WorkloadFactor = t.FactorValue1 ?? 0
}).ToList();
WriteDataHelper.WriteSheetHeader(sheet, point, sheetType, headers);
if (data is List<ExtractTransDto> extractDto && extractDto.Any())
{
var columns = headers.Select(t => t.ColumnName).Intersect(extractDto.Select(t => t.Category))?.ToList();
WriteDataHelper.WriteSheetData(sheet, point, sheetType, columns, extractDto);
}
}
}
}
......@@ -8,7 +8,6 @@ namespace Performance.Services.ExtractExcelService
{
public class WriteDataFactory
{
public ISheetDataWrite GetWriteData(SheetType sheetType)
{
ISheetDataWrite factory;
......
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