Commit 50089301 by lcx

no message

parent 237dfe08
......@@ -4,6 +4,7 @@
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using Performance.EntityModels;
namespace Performance.Repository
......@@ -13,8 +14,28 @@ namespace Performance.Repository
/// </summary>
public partial class PerforPerdeptdicRepository : PerforRepository<per_dept_dic>
{
public PerforPerdeptdicRepository(PerformanceDbContext context) : base(context)
public PerforPerdeptdicRepository(PerformanceDbContext context) : base(context)
{
}
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 });
}
}
}
......@@ -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,22 +121,22 @@ 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, SheetType.AccountBasic };
......@@ -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;
......@@ -168,15 +171,15 @@ private void WriteDataToFile(IWorkbook workbook, int allotId, Dictionary<ExDataD
{
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)
{
......@@ -185,7 +188,7 @@ private object GetDataBySheetType(SheetType sheetType, List<ExtractTransDto> ext
return employeeDict;
case SheetType.AccountBasic:
return new List<im_accountbasic>();
return perdeptdicRepository.GetAccountBasicAccountingUnit(hospitalId);
default:
return extractDto;
......
......@@ -8,50 +8,76 @@
namespace Performance.Services.ExtractExcelService.SheetDataWrite
{
internal class AccountBasicDataWrite : ISheetDataWrite
public class AccountBasicDataWrite : ISheetDataWrite
{
public void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, List<collect_data> collects)
{
if (collects == null || !collects.Any(t => !string.IsNullOrEmpty(t.TypeName))) return;
var headerRow = sheet.GetRow(point.HeaderFirstRowNum ?? 1);
var columns = headerRow.GetCellValues();
if (columns == null || !columns.Any()) return;
}
collects.ForEach(t =>
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())
{
t.UnitType = t.UnitType.NoBlank();
t.AccountingUnitDoctor = t.AccountingUnitDoctor.NoBlank();
t.TypeName = t.TypeName.NoBlank();
});
int dataFirstRowNum = point.DataFirstRowNum.Value;
var rownumbers = collects.Select(t => t.RowNumber).Distinct().OrderBy(t => t).ToList();
var accountingUnits = departments.Select(t => new
{
UnitType = t.UnitType.NoBlank(),
AccountingUnit = t.AccountingUnit.NoBlank()
}).ToList();
for (int i = point.DataFirstRowNum.Value; i < sheet.LastRowNum + 1; i++)
{
var row = sheet.GetRow(i);
if (row != null)
var tuples = new List<Account>();
for (int i = point.DataFirstRowNum.Value; i < sheet.LastRowNum + 1; i++)
{
string unittype = row.GetCell(point.DataFirstCellNum.Value - 2).GetDecodeEscapes();
string accountingunit = row.GetCell(point.DataFirstCellNum.Value - 1).GetDecodeEscapes();
int cellIndex = point.DataFirstCellNum.Value;
foreach (var column in columns)
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 - 2).GetDecodeEscapes();
if (!tuples.Any())
tuples.Add(new Account(unittype, i, i));
else
{
var data = collects.FirstOrDefault(t => t.UnitType == unittype && t.AccountingUnitDoctor == accountingunit && t.TypeName == column);
if (data != null)
{
var cell = row.GetCell(cellIndex);
if (cell != null) cell.SetCellValue<decimal>(data.CellValue);
collects.Remove(data);
}
cellIndex++;
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);
}
if (accountingUnits == null || !accountingUnits.Any()) return;
int number = 0;
foreach (var unitType in tuples.Select(t => t.UnitType).Distinct())
{
}
}
}
}
public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, object data, Dictionary<ExDataDict, object> exdict = null)
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 int BeginIndex { get; set; }
public int EndIndex { get; set; }
}
}
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