Commit dd56fe37 by lcx

Merge branch '4.1write' into v2020morge

parents b9125776 93716191
//-----------------------------------------------------------------------
// <copyright file=" per_dept_dic.cs">
// * FileName: per_dept_dic.cs
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using Performance.EntityModels;
namespace Performance.Repository
{
/// <summary>
/// per_dept_dic Repository
/// </summary>
public partial class PerforPerdeptdicRepository : PerforRepository<per_dept_dic>
{
public IEnumerable<per_dept_dic> GetAccountBasicAccountingUnit(int hospitalId)
{
string sql = @"select * from
(
select distinct
unittype,
ifnull
(
max(case when source = '门诊' then accountingunit end),
max(case when source = '住院' then accountingunit end)
) accountingunit
from per_dept_dic
where hospitalid = @hospitalId
group by unittype,department,hisdeptname
) t
where ifnull(accountingunit, '无')<>'无'
order by unittype,accountingunit;";
return DapperQuery<per_dept_dic>(sql, new { hospitalId });
}
}
}
......@@ -4,6 +4,7 @@
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using Performance.EntityModels;
namespace Performance.Repository
......
......@@ -273,6 +273,7 @@ private IEnumerable<collect_permission> GetCollectSheetByAllot(int hospitalId, i
}
#region 加载采集内容
/// <summary>
/// 加载采集内容
/// </summary>
......@@ -320,7 +321,6 @@ public HandsonTable GetCollectData(int userId, int allotId, string sheetName)
if (permissions == null || !permissions.Any())
throw new PerformanceException("用户没有权限编辑当前SHEET页");
List<HandsonRowData> rowDatas = null;
var collectdata = perforcollectdataRepository.GetEntities(w => w.SheetName == sheet.SheetName && w.AllotID == allotId);
if (collectdata != null)
......@@ -336,6 +336,8 @@ public HandsonTable GetCollectData(int userId, int allotId, string sheetName)
config = CollectDataConfig.PersonExtra;
else if (sheet.SheetType == (int)SheetType.AccountBasic)
config = CollectDataConfig.AccountBasic;
else if (CollectDataConfig.AccountExrtaType.Contains(sheet.SheetType.Value))
config = CollectDataConfig.AccountExtra;
else
config = CollectDataConfig.Default;
......@@ -371,6 +373,9 @@ public HandsonTable GetCollectData(int userId, int allotId, string sheetName)
rowDatas = GetCommonData(sheet);
}
if (rowDatas == null || !rowDatas.Any())
rowDatas = GetAccountExtra(allot, sheet.SheetType.Value);
rowDatas?.RemoveAll(t => !t.CellData.Any(w => !string.IsNullOrEmpty(w.Value?.ToString())));
if (rowDatas != null && rowDatas.Any())
rowDatas = rowDatas.OrderBy(t => t.Row).ToList();
......@@ -397,20 +402,20 @@ private List<HandsonRowData> GetCommonData(per_sheet sheet)
var units = rowdata.Where(w => w.UnitType.HasValue).Select(w => new { w.UnitType, w.AccountingUnit }).Distinct();
foreach (var item in units)
{
if ((new[] {(int) UnitType.医生组, (int) UnitType.其他医生组}).Contains(item.UnitType.Value))
if ((new[] { (int)UnitType.医生组, (int)UnitType.其他医生组 }).Contains(item.UnitType.Value))
{
setdata.Add(new HandsonCellData("核算单元(医生组)", item.AccountingUnit));
GetUnitClassification(setdata,UnitType.医生组,sheet);
GetUnitClassification(setdata, UnitType.医生组, sheet);
}
else if ((new[] {(int) UnitType.医技组, (int) UnitType.其他医技组}).Contains(item.UnitType.Value))
else if ((new[] { (int)UnitType.医技组, (int)UnitType.其他医技组 }).Contains(item.UnitType.Value))
{
setdata.Add(new HandsonCellData("核算单元(医技组)", item.AccountingUnit));
GetUnitClassification(setdata,UnitType.医技组,sheet);
GetUnitClassification(setdata, UnitType.医技组, sheet);
}
else if ((new[] {(int) UnitType.护理组, (int) UnitType.其他护理组}).Contains(item.UnitType.Value))
else if ((new[] { (int)UnitType.护理组, (int)UnitType.其他护理组 }).Contains(item.UnitType.Value))
{
setdata.Add(new HandsonCellData("核算单元(护理组)", item.AccountingUnit));
GetUnitClassification(setdata,UnitType.护理组,sheet);
GetUnitClassification(setdata, UnitType.护理组, sheet);
}
setdata.Add(new HandsonCellData("核算单元", item.AccountingUnit));
}
......@@ -460,6 +465,45 @@ private List<HandsonRowData> GerEmployee(per_sheet sheet)
return new List<HandsonRowData>();
}
private List<HandsonRowData> GetAccountExtra(per_allot allot, int sheetType)
{
List<HandsonRowData> handsonRows = new List<HandsonRowData>();
if (!CollectDataConfig.AccountExrtaType.Contains(sheetType)) return handsonRows;
List<im_data> basicData = new List<im_data>();
var sheet = perforPersheetRepository.GetEntity(w => w.AllotID == allot.ID && w.SheetType == (int)SheetType.AccountBasic);
if (sheet != null)
{
basicData = perforImdataRepository.GetEntities(t => t.SheetID == sheet.ID);
}
else
{
var allotStates = new int[] { (int)AllotStates.Archive, (int)AllotStates.GenerateSucceed, (int)AllotStates.GenerateAccomplish };
var allots = perforPerallotRepository.GetEntities(t => t.HospitalId == allot.HospitalId && allotStates.Contains(t.States) && t.Year < allot.Year && t.Month < allot.Month);
var prevAllot = allots.LastOrDefault();
if (prevAllot == null) return handsonRows;
sheet = perforPersheetRepository.GetEntity(w => w.AllotID == prevAllot.ID && w.SheetType == (int)SheetType.AccountBasic);
basicData = perforImdataRepository.GetEntities(t => t.SheetID == sheet.ID);
}
if (basicData == null || !basicData.Any()) return handsonRows;
var data = basicData.Select(t => new { t.RowNumber, UnitType = ((UnitType)t.UnitType).ToString(), t.AccountingUnit }).ToDistinct().OrderBy(t => t.RowNumber);
foreach (var item in data)
{
List<HandsonCellData> handsonCells = new List<HandsonCellData>();
handsonCells.Add(new HandsonCellData("核算单元类型", item.UnitType));
handsonCells.Add(new HandsonCellData("核算单元", item.AccountingUnit));
handsonRows.Add(new HandsonRowData(item.RowNumber.Value, handsonCells));
}
return handsonRows;
}
private HandsonRowData CreateRowData(int row, ColumnInfo[] columns, SortedDictionary<string, object> dic)
{
......@@ -477,10 +521,10 @@ private List<HandsonRowData> GetAccountBasic(per_sheet sheet)
var groupAccount = perforImdataRepository.GetEntities(t => t.SheetID == sheet.ID); //.OrderBy(c=>c.RowNumber).GroupBy(c => c.RowNumber);
if (groupAccount != null && groupAccount.Any())
{
foreach (var rowNumber in groupAccount.Select(t=>t.RowNumber).Distinct())
foreach (var rowNumber in groupAccount.Select(t => t.RowNumber).Distinct())
{
var numberData = groupAccount.Where(t => t.RowNumber == rowNumber);
var accountUnit = new HandsonCellData("核算单元",numberData.First().AccountingUnit);
var accountUnit = new HandsonCellData("核算单元", numberData.First().AccountingUnit);
var data = numberData?.Select(t => new HandsonCellData(t.TypeName, t.CellValue)).ToList();
data.Add(accountUnit);
......@@ -490,23 +534,25 @@ private List<HandsonRowData> GetAccountBasic(per_sheet sheet)
var unitType = new HandsonCellData("核算单元类型", UnitType.医技组);
data.Add(unitType);
break;
case (int)UnitType.医生组:
unitType = new HandsonCellData("核算单元类型", UnitType.医生组);
data.Add(unitType);
break;
case (int)UnitType.护理组:
unitType = new HandsonCellData("核算单元类型", UnitType.护理组);
data.Add(unitType);
break;
case (int)UnitType.特殊核算组:
unitType = new HandsonCellData("核算单元类型", UnitType.特殊核算组);
data.Add(unitType);
break;
}
var rowData = new HandsonRowData(rowNumber.Value,data);
var rowData = new HandsonRowData(rowNumber.Value, data);
result.Add(rowData);
}
//var temps = accounts.Row.Select(item => new { row = item.Rownumber, dic = JsonHelper.Deserialize(item) });
......@@ -516,7 +562,7 @@ private List<HandsonRowData> GetAccountBasic(per_sheet sheet)
return result;
}
private void GetUnitClassification(List<HandsonCellData> setdata,UnitType unitType,per_sheet sheet)
private void GetUnitClassification(List<HandsonCellData> setdata, UnitType unitType, per_sheet sheet)
{
if (sheet.SheetType == (int)SheetType.AccountExtra)
setdata.Add(new HandsonCellData("核算组别", unitType));
......@@ -525,13 +571,16 @@ private void GetUnitClassification(List<HandsonCellData> setdata,UnitType unitTy
else if (sheet.SheetType == (int)SheetType.BudgetRatio)
setdata.Add(new HandsonCellData("核算单元类型", unitType));
}
#endregion
#endregion 加载采集内容
public void SaveCollectData(int allotId, SaveCollectData request)
{
var types = new[] { (int)SheetType.Employee, (int)SheetType.OtherIncome, (int)SheetType.Expend, (int)SheetType.Workload,
var types = new List<int> { (int)SheetType.Employee, (int)SheetType.OtherIncome, (int)SheetType.Expend, (int)SheetType.Workload,
(int)SheetType.ClinicEmployee, (int)SheetType.AccountExtra, (int)SheetType.PersonExtra, (int)SheetType.LogisticsEmployee};
types.AddRange(CollectDataConfig.AccountExrtaType);
if (!types.Contains(request.SheetType))
throw new PerformanceException("当前SHEET页信息错误");
......@@ -550,10 +599,11 @@ public void SaveCollectData(int allotId, SaveCollectData request)
config = CollectDataConfig.LogisticsEmployee;
else if (request.SheetType == (int)SheetType.PersonExtra)
config = CollectDataConfig.PersonExtra;
else if (CollectDataConfig.AccountExrtaType.Contains(request.SheetType))
config = CollectDataConfig.AccountExtra;
else
config = CollectDataConfig.Default;
var dicData = CreateDataRow(allotId, request, config);
List<collect_data> datas = new List<collect_data>();
foreach (var item in dicData)
......@@ -659,6 +709,15 @@ public class CollectDataConfig
{ nameof(collect_data.EmployeeName), "医生姓名" },
};
public static Dictionary<string, string> AccountExtra { get; } = new Dictionary<string, string>
{
{ nameof(collect_data.UnitType), "核算单元类型" },
{ nameof(collect_data.AccountingUnitDoctor), "核算单元" },
{ nameof(collect_data.Department), "核算单元" },
{ nameof(collect_data.JobNumber), "人员工号" },
{ nameof(collect_data.EmployeeName), "医生姓名" },
};
public static Dictionary<string, string> AccountBasic { get; } = new Dictionary<string, string>
{
{ nameof(collect_data.UnitType), "核算单元分类" },
......@@ -678,5 +737,19 @@ public class CollectDataConfig
{ nameof(collect_data.JobNumber), "人员工号" },
{ nameof(collect_data.EmployeeName), "医生姓名" },
};
public static List<int> AccountExrtaType = new List<int>
{
(int)SheetType.AccountExtra,
(int)SheetType.AccountDrugAssess,
(int)SheetType.AccountMaterialsAssess,
(int)SheetType.AccountScoreAverage,
(int)SheetType.BudgetRatio,
(int)SheetType.AssessBeforeOtherFee,
(int)SheetType.AccountAdjustLaterOtherFee,
(int)SheetType.WorkloadMedicineProp,
(int)SheetType.WorkloadCMI,
(int)SheetType.WorkloadIncline,
};
}
}
......@@ -203,11 +203,7 @@ public static string GetDecodeEscapes(this ICell cell)
if (cell == null) return "";
cell.SetCellType(CellType.String);
string value = cell.StringCellValue;
if (!string.IsNullOrEmpty(value))
value = value.Replace("\n", "").Replace("\r", "").Replace(" ", "").Trim();
return value;
return cell.StringCellValue.NoBlank();
}
catch
{
......
......@@ -38,7 +38,7 @@ private static (string TempPath, string FilePath) CopyOriginalFile(int hospitalI
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");
string filePath = Path.Combine(dpath, $"绩效提取数据{DateTime.Now.ToString("yyyyMMddHHmmssfff")}{ext}");
return (tempPath, filePath);
}
......
......@@ -22,6 +22,7 @@ public class ExtractService : IAutoInjection
private readonly PerforPerallotRepository perallotRepository;
private readonly PerforcollectdataRepository collectdataRepository;
private readonly PerforPeremployeeRepository peremployeeRepository;
private readonly PerforPerdeptdicRepository perdeptdicRepository;
public ExtractService(
ILogger<ExtractService> logger,
......@@ -32,7 +33,8 @@ public class ExtractService : IAutoInjection
DictionaryService dictionaryService,
PerforPerallotRepository perallotRepository,
PerforcollectdataRepository collectdataRepository,
PerforPeremployeeRepository peremployeeRepository
PerforPeremployeeRepository peremployeeRepository,
PerforPerdeptdicRepository perdeptdicRepository
)
{
this.logger = logger;
......@@ -44,6 +46,7 @@ PerforPeremployeeRepository peremployeeRepository
this.perallotRepository = perallotRepository;
this.collectdataRepository = collectdataRepository;
this.peremployeeRepository = peremployeeRepository;
this.perdeptdicRepository = perdeptdicRepository;
}
/// <summary>
......@@ -87,7 +90,7 @@ public string Main(int allotId, int hospitalId, string email, string groupName,
workbook = ExcelHelper.GetWorkbook(templateFilePath);
if (workbook == null) throw new PerformanceException("文件读取失败");
WriteDataToFile(workbook, allotId, dict, standData, groupName, isSingle);
WriteDataToFile(workbook, allot, dict, standData, groupName, isSingle);
logService.ReturnTheLog(allotId, groupName, 2, "提取完成", $"绩效数据提取成功", 5, isSingle);
allot.IsExtracting = isSingle ? 2 : 0;
......@@ -118,25 +121,25 @@ public string Main(int allotId, int hospitalId, string email, string groupName,
/// 数据写入
/// </summary>
/// <param name="workbook"></param>
/// <param name="allotId"></param>
/// <param name="allot"></param>
/// <param name="exdict"></param>
/// <param name="extractDto"></param>
/// <param name="groupName"></param>
/// <param name="isSingle"></param>
private void WriteDataToFile(IWorkbook workbook, int allotId, Dictionary<ExDataDict, object> exdict, List<ExtractTransDto> extractDto, string groupName, bool isSingle)
private void WriteDataToFile(IWorkbook workbook, per_allot allot, Dictionary<ExDataDict, object> exdict, List<ExtractTransDto> extractDto, string groupName, bool isSingle)
{
ExcelStyle style = new ExcelStyle(workbook);
var models = exdict[ExDataDict.ExModule] as List<ex_module>;
ExtractHelper.CreateNotExistSheet(models, workbook);
var employeeDict = peremployeeRepository.GetEntities(t => t.AllotId == allotId);
var collectData = collectdataRepository.GetEntities(t => t.AllotID == allotId);
var employeeDict = peremployeeRepository.GetEntities(t => t.AllotId == allot.ID);
var collectData = collectdataRepository.GetEntities(t => t.AllotID == allot.ID);
logger.LogInformation($"allotId: {allotId}: 总金额 - {extractDto?.Sum(s => s.Value ?? 0)}");
logger.LogInformation($"allotId: {allot.ID}: 总金额 - {extractDto?.Sum(s => s.Value ?? 0)}");
WriteDataFactory factory = new WriteDataFactory();
var types = new List<SheetType> { SheetType.OtherIncome, SheetType.Income, SheetType.Expend, SheetType.Workload, SheetType.OtherWorkload };
var types = new List<SheetType> { SheetType.OtherIncome, SheetType.Income, SheetType.Expend, SheetType.Workload, SheetType.OtherWorkload, SheetType.AccountBasic };
decimal ratio = 60m;
for (int sheetIndex = 0; sheetIndex < workbook.NumberOfSheets; sheetIndex++)
{
......@@ -146,8 +149,8 @@ private void WriteDataToFile(IWorkbook workbook, int allotId, Dictionary<ExDataD
var sheetType = perSheetService.GetSheetType(sheet.SheetName);
if (sheetType == SheetType.Unidentifiable) continue;
logService.ReturnTheLog(allotId, groupName, 3, "", ratio > 99 ? 99 : ratio, 1, isSingle);
logService.ReturnTheLog(allotId, groupName, 2, "写入数据", $"sheet“{sheet.SheetName}”开始写入数据", 1, isSingle);
logService.ReturnTheLog(allot.ID, groupName, 3, "", ratio > 99 ? 99 : ratio, 1, isSingle);
logService.ReturnTheLog(allot.ID, groupName, 2, "写入数据", $"sheet“{sheet.SheetName}”开始写入数据", 1, isSingle);
var point = PerSheetDataFactory.GetDataRead(sheetType)?.Point;
if (sheetType == SheetType.OtherWorkload) point = PerSheetDataFactory.GetDataRead(SheetType.Workload)?.Point;
......@@ -161,30 +164,32 @@ private void WriteDataToFile(IWorkbook workbook, int allotId, Dictionary<ExDataD
string sheetName = sheet.SheetName.NoBlank();
var collects = collectData?.Where(t => t.SheetName.NoBlank() == sheetName).ToList();
customer.WriteCollectData(sheet, point, sheetType, style, collects);
customer.WriteCollectData(sheet, point, sheetType, style, collects, exdict);
var exdata = extractDto.Where(t => t.SheetName.NoBlank() == sheetName)?.ToList();
if (exdata != null)
{
logger.LogInformation($"{sheetName}: 总金额 - {exdata.Sum(s => s.Value ?? 0)}; 科室 - {string.Join(",", exdata.Select(s => s.Department).Distinct())}");
}
var data = GetDataBySheetType(sheetType, exdata, employeeDict);
var data = GetDataBySheetType(allot.HospitalId, sheetType, exdata, employeeDict);
customer.WriteSheetData(sheet, point, sheetType, style, data, exdict);
}
logService.ReturnTheLog(allotId, groupName, 2, "写入数据", $"sheet“{sheet.SheetName}”已完成数据写入", 1, isSingle);
logService.ReturnTheLog(allot.ID, groupName, 2, "写入数据", $"sheet“{sheet.SheetName}”已完成数据写入", 1, isSingle);
}
}
private object GetDataBySheetType(SheetType sheetType, List<ExtractTransDto> extractDto, List<per_employee> employeeDict)
private object GetDataBySheetType(int hospitalId, SheetType sheetType, List<ExtractTransDto> extractDto, List<per_employee> employeeDict)
{
switch (sheetType)
{
case SheetType.Employee:
case SheetType.ClinicEmployee:
case SheetType.AccountBasic:
return employeeDict;
case SheetType.AccountBasic:
return perdeptdicRepository.GetAccountBasicAccountingUnit(hospitalId);
default:
return extractDto;
}
......
......@@ -16,6 +16,7 @@ public enum ExDataDict
ExModule = 1,
ExItem = 2,
ExSpecial = 3,
AccountingBasic = 4,
}
public class QueryService : IAutoInjection
......
using NPOI.SS.UserModel;
using Microsoft.Extensions.Logging;
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 AccountBasicDataWrite : ISheetDataWrite
public class AccountBasicDataWrite : ISheetDataWrite
{
public void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, List<collect_data> collects)
private readonly ILogger logger;
public AccountBasicDataWrite(ILogger logger)
{
this.logger = logger;
}
public void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, List<collect_data> collects, Dictionary<ExDataDict, object> exdict = null)
{
}
public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, object data, Dictionary<ExDataDict, object> exdict = null)
{
if (data is List<per_dept_dic> departments && departments.Any())
{
int dataFirstRowNum = point.DataFirstRowNum.Value;
var accountingUnits = departments.Select(t => new Account
{
UnitType = t.UnitType.NoBlank(),
AccountingUnit = t.AccountingUnit.NoBlank()
}).ToList();
var tuples = GetAccountingUnitDataNonexistent(sheet, point, accountingUnits);
if (accountingUnits == null || !accountingUnits.Any()) return;
WriteAccountingUnitDataNonexistent(sheet, point, style, accountingUnits, tuples);
var accountBasic = new List<Account>();
for (int i = point.DataFirstRowNum.Value; i < sheet.LastRowNum + accountingUnits.Count + 1; i++)
{
var row = sheet.GetRow(i);
if (row == null) continue;
accountBasic.Add(new Account
{
UnitType = row.GetCell(point.DataFirstCellNum.Value - 2).GetDecodeEscapes(),
AccountingUnit = row.GetCell(point.DataFirstCellNum.Value - 1).GetDecodeEscapes()
});
}
exdict.Add(ExDataDict.AccountingBasic, accountBasic);
}
}
private List<Account> GetAccountingUnitDataNonexistent(ISheet sheet, PerSheetPoint point, List<Account> accountingUnits)
{
var tuples = new List<Account>();
for (int i = point.DataFirstRowNum.Value; i < sheet.LastRowNum + 1; i++)
{
var row = sheet.GetRow(i);
if (row == null) continue;
var unittype = row.GetCell(point.DataFirstCellNum.Value - 2).GetDecodeEscapes();
var accountingunit = row.GetCell(point.DataFirstCellNum.Value - 1).GetDecodeEscapes();
if (!tuples.Any())
tuples.Add(new Account(unittype, i, i));
else
{
var last = tuples.Last();
if (last.UnitType == unittype)
last.EndIndex = i;
else
tuples.Add(new Account(unittype, i, i));
}
var account = accountingUnits.FirstOrDefault(t => t.AccountingUnit == accountingunit && t.UnitType == unittype);
if (account != null) accountingUnits.Remove(account);
}
return tuples;
}
private void WriteAccountingUnitDataNonexistent(ISheet sheet, PerSheetPoint point, ExcelStyle style, List<Account> accountingUnits, List<Account> tuples)
{
int number = 0;
var deptStyle = style.GetCellStyle();
foreach (var unitType in tuples.Select(t => t.UnitType).Distinct())
{
var accountingList = accountingUnits.Where(t => t.UnitType == unitType)?.ToList();
if (accountingList == null || !accountingList.Any()) continue;
var tuple = tuples.First(t => t.UnitType == unitType);
sheet.ShiftRows(tuple.EndIndex + 1 + number, sheet.LastRowNum + number, accountingList.Count);
int index = tuple.EndIndex + 1 + number;
foreach (var acccount in accountingList)
{
var row = sheet.GetOrCreate(index);
var unitTypeCell = row.GetOrCreate(point.DataFirstCellNum.Value - 2);
unitTypeCell.SetCellValue<string>(acccount.UnitType);
unitTypeCell.CellStyle = deptStyle;
var accountingUnitCell = row.GetOrCreate(point.DataFirstCellNum.Value - 1);
accountingUnitCell.SetCellValue<string>(acccount.AccountingUnit);
accountingUnitCell.CellStyle = deptStyle;
index++;
}
number += accountingList.Count;
}
}
}
public class Account
{
public Account()
{
}
public Account(string unitType, int beginIndex, int endIndex)
{
UnitType = unitType;
BeginIndex = beginIndex;
EndIndex = endIndex;
}
public string UnitType { get; set; }
public string AccountingUnit { get; set; }
public int BeginIndex { get; set; }
public int EndIndex { get; set; }
}
}
using Microsoft.Extensions.Logging;
using NPOI.SS.UserModel;
using Performance.DtoModels;
using Performance.EntityModels;
using Performance.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Performance.Services.ExtractExcelService.SheetDataWrite
{
public class AccountExtraDataWrite : ISheetDataWrite
{
private readonly ILogger logger;
public AccountExtraDataWrite(ILogger logger)
{
this.logger = logger;
}
public void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, List<collect_data> collects, Dictionary<ExDataDict, object> exdict = null)
{
point = new PerSheetPoint
{
HeaderFirstRowNum = 1,
HeaderFirstCellNum = 0,
DataFirstRowNum = 2,
DataFirstCellNum = 0
};
var accounts = new List<Account>();
if (exdict != null && exdict.ContainsKey(ExDataDict.AccountingBasic) && exdict[ExDataDict.AccountingBasic] != null)
accounts = exdict[ExDataDict.AccountingBasic] as List<Account> ?? new List<Account>();
ExtractHelper.ClearSheetPartialData(sheet, point, sheetType);
var columns = new List<string>();
if (collects != null && collects.Any(t => !string.IsNullOrEmpty(t.TypeName)))
{
columns = collects.Where(t => !string.IsNullOrEmpty(t.TypeName)).Select(t => t.TypeName).Distinct().OrderBy(t => t).ToList();
var headers = columns.Select(t => new ExcelHeader
{
ColumnName = t.NoBlank(),
DoctorFactor = 0,
NurseFactor = 0,
TechnicianFactor = 0
}).ToList();
WriteSheetHeader(sheet, point, sheetType, style, headers);
}
WriteCollectData(sheet, point, sheetType, style, columns, collects, accounts);
}
public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, object data, Dictionary<ExDataDict, object> exdict = null)
{
}
private void WriteSheetHeader(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, List<ExcelHeader> headers)
{
if (headers == null || !headers.Any()) return;
var columns = headers.Select(t => t).ToList();
// 费用类型
var columnHeader = sheet.GetOrCreate(point.HeaderFirstRowNum.Value);
// 去除excel中已存在的列
int headerFirstCellNum = point.DataFirstCellNum.Value;
if (columnHeader.LastCellNum > point.DataFirstCellNum.Value)
{
for (int index = point.DataFirstCellNum.Value; index < columnHeader.LastCellNum; index++)
{
var column = columnHeader.GetCell(index).GetDecodeEscapes();
if (string.IsNullOrEmpty(column)) continue;
if (index > headerFirstCellNum) headerFirstCellNum = index;
columns.RemoveAll(t => t.ColumnName.NoBlank() == column);
}
if (headerFirstCellNum > point.DataFirstCellNum.Value)
headerFirstCellNum += 1;
}
if (columns == null || !columns.Any()) return;
var columnStyle = style.SetBgkColorAndFormat(style.GetCellStyle(), StyleType.列头);
// 补充excel中不存在的列
foreach (var item in columns)
{
var columnCell = columnHeader.GetOrCreate(headerFirstCellNum);
columnCell.SetCellValue(item.ColumnName);
columnCell.CellStyle = columnStyle;
headerFirstCellNum++;
}
}
private void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, List<string> headers, List<collect_data> data, List<Account> accounts)
{
var columnHeader = sheet.GetOrCreate(point.HeaderFirstRowNum.Value);
int dataFirstRowNum = point.DataFirstRowNum.Value;
data = data ?? new List<collect_data>();
accounts = accounts.Any() ? accounts : data.Select(s => new Account { AccountingUnit = s.Department, UnitType = s.UnitType })
.Where(w => !string.IsNullOrEmpty(w.AccountingUnit)).ToDistinct().ToList();
var deptStyle = style.GetCellStyle();
var cellStyle = style.SetBgkColorAndFormat(style.GetCellStyle(), StyleType.数据);
headers = headers.Select(t => t.NoBlank()).ToList();
foreach (var account in accounts)
{
var deptData = data.Where(t => t.AccountingUnitDoctor == account.AccountingUnit && t.UnitType == account.UnitType);
var hasData = deptData != null && deptData.Any();
var row = sheet.GetOrCreate(dataFirstRowNum);
for (int cellIndex = point.HeaderFirstCellNum.Value; cellIndex < columnHeader.LastCellNum; cellIndex++)
{
var column = columnHeader.GetOrCreate(cellIndex).GetDecodeEscapes();
var cell = row.GetOrCreate(cellIndex);
if (collectExtra.ContainsKey(column))
{
cell.SetCellOValue(collectExtra[column]?.Invoke(account));
cell.CellStyle = deptStyle;
}
else if (hasData && headers != null && headers.Contains(column))
{
var value = deptData.FirstOrDefault(t => t.TypeName.NoBlank() == column)?.CellValue;
cell.SetCellValue<decimal>(value);
cell.CellStyle = cellStyle;
}
}
dataFirstRowNum++;
}
}
/// <summary> 收入固定列 </summary>
private static readonly Dictionary<string, Func<Account, string>> collectExtra = new Dictionary<string, Func<Account, string>>
{
{ "核算单元类型", (dto) => dto.UnitType },
{ "核算单元", (dto) => dto.AccountingUnit },
};
}
}
......@@ -7,16 +7,14 @@
namespace Performance.Services.ExtractExcelService.SheetDataWrite
{
class ClinicEmployeeDataWrite : ISheetDataWrite
internal class ClinicEmployeeDataWrite : ISheetDataWrite
{
public void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, List<collect_data> collects)
public void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, List<collect_data> collects, Dictionary<ExDataDict, object> exdict = null)
{
}
public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, object data, Dictionary<ExDataDict, object> exdict = null)
{
}
}
}
......@@ -18,7 +18,7 @@ public DepartmentDataWrite(ILogger logger)
this.logger = logger;
}
public void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, List<collect_data> collects)
public void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, List<collect_data> collects, Dictionary<ExDataDict, object> exdict = null)
{
if (collects == null || !collects.Any(t => !string.IsNullOrEmpty(t.TypeName))) return;
......@@ -26,7 +26,7 @@ public void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetT
var headers = columns.Select(t => new ExcelHeader
{
ColumnName = t.Trim(),
ColumnName = t.NoBlank(),
DoctorFactor = 0,
NurseFactor = 0,
TechnicianFactor = 0
......
......@@ -10,9 +10,8 @@ namespace Performance.Services.ExtractExcelService.SheetDataWrite
{
public class EmployeeDataWrite : ISheetDataWrite
{
public void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, List<collect_data> collects)
public void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, List<collect_data> collects, Dictionary<ExDataDict, object> exdict = null)
{
}
public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, object data, Dictionary<ExDataDict, object> exdict)
......@@ -68,7 +67,6 @@ private void ClearSheetPartialData(ISheet sheet, List<per_employee> employees, L
var employee = employees.FirstOrDefault(t => t.AccountingUnit == accountingUnit && t.PersonnelNumber == personnel && t.DoctorName == doctorName);
if (employee == null)
{
}
else
{
......
......@@ -17,7 +17,7 @@ public interface ISheetDataWrite
/// <param name="sheetType"></param>
/// <param name="style"></param>
/// <param name="collects">采集数据</param>
void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, List<collect_data> collects);
void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, List<collect_data> collects, Dictionary<ExDataDict, object> exdict = null);
/// <summary>
/// 写入抽取数据
......
......@@ -18,7 +18,7 @@ public IncomeDataWrite(ILogger logger)
this.logger = logger;
}
public void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, List<collect_data> collects)
public void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, List<collect_data> collects, Dictionary<ExDataDict, object> exdict = null)
{
if (collects == null || !collects.Any(t => !string.IsNullOrEmpty(t.TypeName))) return;
......
......@@ -18,7 +18,7 @@ public OtherIncomeDataWrite(ILogger logger)
this.logger = logger;
}
public void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, List<collect_data> collects)
public void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, List<collect_data> collects, Dictionary<ExDataDict, object> exdict = null)
{
if (collects == null || !collects.Any(t => !string.IsNullOrEmpty(t.TypeName))) return;
......
......@@ -20,7 +20,7 @@ public SpecialUnitDataWrite(ILogger logger)
this.logger = logger;
}
public void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, List<collect_data> collects)
public void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, List<collect_data> collects, Dictionary<ExDataDict, object> exdict = null)
{
}
......
......@@ -18,7 +18,7 @@ public WorkloadDataWrite(ILogger logger)
this.logger = logger;
}
public void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, List<collect_data> collects)
public void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, List<collect_data> collects, Dictionary<ExDataDict, object> exdict = null)
{
if (collects == null || !collects.Any(t => !string.IsNullOrEmpty(t.TypeName))) return;
......
......@@ -36,20 +36,33 @@ public ISheetDataWrite GetWriteData(SheetType sheetType, ILogger logger)
factory = new WorkloadDataWrite(logger);
break;
//case SheetType.AccountBasic:
// factory = new AccountBasicDataWrite();
// break;
case SheetType.AccountBasic:
factory = new AccountBasicDataWrite(logger);
break;
case SheetType.SpecialUnit:
factory = new SpecialUnitDataWrite(logger);
break;
//case SheetType.AccountExtra:
//case SheetType.PersonExtra:
//case SheetType.AccountScoreAverage:
//case SheetType.BudgetRatio:
//case SheetType.AssessBeforeOtherFee:
// factory = new DepartmentDataWrite(logger);
// break;
case SheetType.AccountExtra:
case SheetType.PersonExtra:
case SheetType.AccountDrugAssess:
case SheetType.AccountMaterialsAssess:
case SheetType.AccountScoreAverage:
case SheetType.BudgetRatio:
case SheetType.AssessBeforeOtherFee:
factory = new DepartmentDataWrite(logger);
case SheetType.AccountAdjustLaterOtherFee:
case SheetType.WorkloadMedicineProp:
case SheetType.WorkloadCMI:
case SheetType.WorkloadIncline:
factory = new AccountExtraDataWrite(logger);
break;
default:
......
......@@ -19,6 +19,7 @@ public class PerSheetDataReadDeptAccounting : IPerSheetDataRead
HeaderLastRowNum = 1,
HeaderFirstCellNum = 0,
DataFirstRowNum = 2,
DataFirstCellNum = 2,
};
public List<IPerData> ReadData(ISheet sheet, List<PerHeader> perHeader)
......
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