Commit f4080e41 by lcx

Merge branch 'develop' into 手工录入

parents ff0a869f 6b4bcb05
diff a/performance/Performance.Api/Controllers/EmployeeController.cs b/performance/Performance.Api/Controllers/EmployeeController.cs (rejected hunks)
@@ -824,6 +824,7 @@
if (allotId <= 0)
return new ApiResponse(ResponseType.Fail, "参数错误", "allotid无效");
+ var result = employeeService.GetGatherTotal(allotId, request);
return new ApiResponse(ResponseType.OK, result);
}
......@@ -13,6 +13,7 @@
using Performance.Infrastructure;
using Performance.Services;
using Performance.Services.ExtractExcelService;
using Performance.Services.Queues;
using System;
using System.Collections.Generic;
using System.IO;
......@@ -37,6 +38,8 @@ public class TemplateController : Controller
private readonly AllotService allotService;
private readonly LogManageService logService;
private readonly IServiceScopeFactory serviceScopeFactory;
private readonly IBackgroundTaskQueue _backgroundTaskQueue;
private readonly ExtractService extractService;
public TemplateController(
ILogger<ExceptionsFilter> logger,
......@@ -50,7 +53,9 @@ public class TemplateController : Controller
HospitalService hospitalService,
AllotService allotService,
LogManageService logService,
IServiceScopeFactory serviceScopeFactory)
IBackgroundTaskQueue backgroundTaskQueue,
IServiceScopeFactory serviceScopeFactory,
ExtractService extractService)
{
this.logger = logger;
this.env = env;
......@@ -64,6 +69,8 @@ public class TemplateController : Controller
this.allotService = allotService;
this.logService = logService;
this.serviceScopeFactory = serviceScopeFactory;
_backgroundTaskQueue = backgroundTaskQueue;
this.extractService = extractService;
}
/// <summary>
......@@ -226,22 +233,22 @@ public ApiResponse NewExtractData([CustomizeValidator, FromBody] ExtractRequest
allot.IsExtracting = 1;
allot.ExtractTime = DateTime.Now;
allotService.Update(allot);
string email = claim.GetUserClaim(JwtClaimTypes.Mail);
// string email = claim.GetUserClaim(JwtClaimTypes.Mail);
string email = "";
if (isSingle)
{
logger.LogInformation("同一项目中进行提取");
Task.Run(() =>
_backgroundTaskQueue.QueueBackgroundWorkItem(async token =>
{
using (var scope = serviceScopeFactory.CreateScope())
{
var scopedServices = scope.ServiceProvider.GetRequiredService<ExtractService>();
logger.LogInformation("提取绩效数据参数:" + JsonHelper.Serialize(new { allotId = allot.ID, hospitalId = allot.HospitalId, userId = claim.GetUserId() }));
string extractFilePath = scopedServices.Main(allot.ID, allot.HospitalId, email, "User" + claim.GetUserId(), filePath, isSingle);
logger.LogInformation("提取绩效数据参数:" + JsonHelper.Serialize(new { allotId = allot.ID, hospitalId = allot.HospitalId }));
string extractFilePath = scopedServices.Main(allot.ID, allot.HospitalId, email, allot.ID.ToString(), filePath, isSingle);
}
});
Thread.Sleep(1000);
}
else
{
......@@ -252,8 +259,7 @@ public ApiResponse NewExtractData([CustomizeValidator, FromBody] ExtractRequest
{
AllotId = request.AllotId,
HospitalId = request.HospitalId,
Email = email,
UserId = claim.GetUserId()
Email = email
};
string json = JsonHelper.Serialize(obj);
......@@ -284,6 +290,12 @@ public ApiResponse NewExtractData([CustomizeValidator, FromBody] ExtractRequest
// B 使用配置作为模板
}
[HttpPost("extract/allot/file")]
public ApiResponse ExtractAllotFile(ExtractRequest request)
{
extractService.Main(request.AllotId, request.HospitalId, request.Email, request.AllotId.ToString(), "", true);
return new ApiResponse(ResponseType.OK);
}
/// <summary>
/// 提取日志
......
using Microsoft.Data.SqlClient;
using MySql.Data.MySqlClient;
using MySql.Data.MySqlClient;
using Oracle.ManagedDataAccess.Client;
using System;
using System.Data;
using System.Data.SqlClient;
namespace Performance.Repository
{
......
......@@ -10,6 +10,7 @@
using Performance.Repository;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
......@@ -124,7 +125,10 @@ public Comparison CheckAccountingUnitRealGiveFeeDiff(int allotId, string searchQ
TotalCount = DapperQuery<int>(queryCount, new { allotId, searchQuery, parm = $"%{searchQuery}%" })?.FirstOrDefault() ?? 0,
};
}
}
public IDbConnection GetDbConnection()
{
return context.Database.GetDbConnection();
}
}
}
......@@ -5,8 +5,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.0.0" />
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="3.21.4" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
</ItemGroup>
......
......@@ -75,13 +75,13 @@ private PerExcel Import(per_allot allot)
Version = FileHelper.GetExtension(path) == ".xlsx" ? ExcelVersion.xlsx : ExcelVersion.xls,
PerSheet = new List<PerSheet>()
};
_logManageService.WriteMsg("读取文件", $"文件读取中...当前操作需要一点时间,请耐心等待", 1, allot.ID, "ReceiveMessage", true);
using (FileStream fs = new FileStream(path, FileMode.Open))
{
IWorkbook workbook = (excel.Version == ExcelVersion.xlsx)
? (IWorkbook)(new XSSFWorkbook(fs))
: (IWorkbook)(new HSSFWorkbook(fs));
IWorkbook workbook = (excel.Version == ExcelVersion.xlsx) ? new XSSFWorkbook(fs) : new HSSFWorkbook(fs);
bool isnew = false;
var tasks = new List<Task>();
for (int i = 0; i < workbook.NumberOfSheets; i++)
{
var sheet = workbook.GetSheetAt(i);
......@@ -89,30 +89,28 @@ private PerExcel Import(per_allot allot)
if (SheetType.Unidentifiable != sheetType)
_logManageService.WriteMsg("准备读取文件", $"正在准备读取“{sheet.SheetName}”", 1, allot.ID, "ReceiveMessage", true);
//else
//_logManageService.WriteMsg("准备读取文件", $"忽略文件“{sheet.SheetName}”", 1, allot.ID, "ReceiveMessage", true);
//_logManageService.WriteMsg("准备读取文件", $"忽略文件“{sheet.SheetName}”", 1, allot.ID, "ReceiveMessage", true);
try
{
tasks.Add(Task.Factory.StartNew(() =>
// 保留临床科室测算表全部结构,用作展示,不做其他用途
if (sheetType == SheetType.AccountBasic)
{
var st = _perSheetService.SheetAccountBasicSpecial(sheet, isnew);
excel.PerSheet.Add(st);
}
if (SheetType.Unidentifiable != sheetType)
{
// 保留临床科室测算表全部结构,用作展示,不做其他用途
if (sheetType == SheetType.AccountBasic)
{
var st = _perSheetService.SheetAccountBasicSpecial(sheet, isnew);
excel.PerSheet.Add(st);
}
if (SheetType.Unidentifiable != sheetType)
{
var st = _perSheetService.Sheet(sheet, isnew);
excel.PerSheet.Add(st);
}
else
{
if (sheet.SheetName.Contains("开单医院"))
isnew = true;
}
}));
var st = _perSheetService.Sheet(sheet, isnew);
excel.PerSheet.Add(st);
}
else
{
if (sheet.SheetName.Contains("开单医院"))
isnew = true;
}
}
catch (Exception ex)
{
......@@ -121,9 +119,6 @@ private PerExcel Import(per_allot allot)
}
}
_logManageService.WriteMsg("读取文件", $"文件读取中...当前操作需要一点时间,请耐心等待", 1, allot.ID, "ReceiveMessage", true);
Task.WaitAll(tasks.ToArray());
_logManageService.WriteMsg("读取文件", $"EXCEL文件基础数据读取完成!", 1, allot.ID, "ReceiveMessage", true);
return excel;
......
......@@ -673,7 +673,7 @@ public List<IssuedPromptResponse> IssuedPrompt(per_allot allot, AllotRequest req
{
var second = secondList?.FirstOrDefault(f => f.UnitType == item.UnitType && f.Department == item.Department);
var isDiffer = (item.RealGiveFee ?? 0) > 0 && (item.PreRealGiveFee ?? 0) > 0 && ((item.RealGiveFee ?? 0) != (item.PreRealGiveFee ?? 0));
var isDiffer = (item.RealGiveFee ?? 0) != (item.PreRealGiveFee ?? 0);
if ((item.RealGiveFee ?? 0) == 0 && (item.PreRealGiveFee ?? 0) > 0)
{
......
......@@ -206,7 +206,8 @@ public List<ResComputeResponse> GetCompute(int allotId, int type)
}
else
{
var compute = _perforRescomputeRepository.GetEntities(t => t.AllotID == allotId && t.AccountType == items.FirstOrDefault(p => p.Value == type).Name);
var name = items.FirstOrDefault(p => p.Value == type)?.Name ?? "";
var compute = _perforRescomputeRepository.GetEntities(t => t.AllotID == allotId && t.AccountType == name);
if (type == (int)AccountUnitType.行政工勤)
compute = compute?.Where(w => w.NeedSecondAllot == "否")?.ToList();
......@@ -2000,20 +2001,19 @@ private decimal GetDecimal(decimal? value, decimal _ = 0)
/// <returns></returns>
public List<cof_alias> CustomColumnHeaders(int hospitalId, string route)
{
var alias = cofaliasRepository.GetEntities(t => t.HospitalId == hospitalId && t.Route.Equals(route, StringComparison.OrdinalIgnoreCase));
var init = new List<cof_alias>();
var alias = cofaliasRepository.GetEntities(t => t.HospitalId == hospitalId) ?? new List<cof_alias>();
alias = alias.Where(t => t.Route.Equals(route, StringComparison.OrdinalIgnoreCase)).OrderBy(w => w.Id).ToList() ?? new List<cof_alias>();
var pairs = new Dictionary<string, List<cof_alias>>
if (alias == null || alias.Count == 0)
{
{ "/result/compute" , ComputeConfig.AllComputeView },
{ "/result/wholehospital" , ComputeConfig.AllComputePersonView },
{ "/result/print/compute" , ComputeConfig.AllComputeDepartmentView },
};
var init = pairs.ContainsKey(route.ToLower()) ? pairs[route.ToLower()] : new List<cof_alias>();
foreach (var item in init)
{
item.HospitalId = hospitalId;
item.Route = route;
item.OriginalName = item.Alias;
var pairs = new Dictionary<string, List<cof_alias>>
{
{ "/result/compute" , ComputeConfig.AllComputeView },
{ "/result/wholehospital" , ComputeConfig.AllComputePersonView },
{ "/result/print/compute" , ComputeConfig.AllComputeDepartmentView },
};
init = pairs.ContainsKey(route.ToLower()) ? pairs[route.ToLower()] : new List<cof_alias>();
}
if (alias != null && alias.Count > 0)
......
......@@ -868,7 +868,7 @@ public bool BatchSaveAccounting(int allotId, SaveCollectData request)
{
var json = JsonHelper.Serialize(item);
var data = JsonHelper.Deserialize<cof_accounting>(json);
data.AllotId = allotId;
if (!unitType.Contains(data?.UnitType) && !string.IsNullOrEmpty(data?.UnitType)) return false;
if (getAccounts != null)
if (getAccounts.Any(t => t.AccountingUnit == data?.AccountingUnit && t.UnitType == data?.UnitType)) continue;
......
......@@ -624,7 +624,7 @@ public string LastAllotFilePath(int allotId)
var statesArray = new int[] { (int)AllotStates.GenerateSucceed, (int)AllotStates.Archive };
var allotList = perallotRepository.GetEntities(t => t.HospitalId == allot.HospitalId && statesArray.Contains(t.States));
var allotLast = allotList?.OrderByDescending(t => t.Year).ThenByDescending(t => t.Month).First();
var allotLast = allotList?.OrderByDescending(t => t.Year).ThenByDescending(t => t.Month).FirstOrDefault();
if (allotLast != null)
return allotLast.Path;
......@@ -659,7 +659,7 @@ public string Judge(int allotId, int hospitalId, int useTemplate, ref bool isSin
// 获取最近一次绩效
var statesArray = new int[] { (int)AllotStates.GenerateSucceed, (int)AllotStates.Archive };
var allotList = perallotRepository.GetEntities(t => t.HospitalId == hospitalId && statesArray.Contains(t.States));
var allotLast = allotList?.OrderByDescending(t => t.Year).ThenByDescending(t => t.Month).First();
var allotLast = allotList?.OrderByDescending(t => t.Year).ThenByDescending(t => t.Month).FirstOrDefault();
if (allotLast != null)
filePath = allotLast.Path;
// 获取当前医院模版信息
......@@ -775,7 +775,7 @@ public string Judge(int allotId, int hospitalId, int useTemplate, ref bool isSin
if (conf == null)
continue;
var data = queryService.QueryData(conf, allot, scr.ExecScript);
var data = queryService.QueryData<ExtractDto>(conf, scr.ExecScript, allot, false);
if (data == null || !data.Any()) continue;
foreach (var module in moduleSheet.Where(t => t.CheckScriptId == scr.Id))
......
......@@ -71,7 +71,7 @@ public void Handler(int hospitalId, per_allot allot, string groupName, bool isSi
var typeIds = types.Where(t => t.Source == (int)SheetType.Employee).Select(t => t.Id);
var script = scripts.Where(t => typeIds.Contains(t.TypeId));
if (script != null)
Employee(allot, configs, scripts);
Employee(allot, configs, scripts, isSingle);
}
if (types.Any(t => t.Source == (int)SheetType.OnlyExtract)) //不写入Excel的提取数据
{
......@@ -84,7 +84,7 @@ public void Handler(int hospitalId, per_allot allot, string groupName, bool isSi
foreach (var script in thisTypeScripts)
{
logger.LogInformation($"提取sql: {script.ExecScript}");
ExResult(allot, configs.FirstOrDefault(t => t.Id == script.ConfigId), script.ExecScript, type.EName);
ExResult(allot, configs.FirstOrDefault(t => t.Id == script.ConfigId), script.ExecScript, type.EName, isSingle);
}
}
}
......@@ -96,7 +96,7 @@ public void Handler(int hospitalId, per_allot allot, string groupName, bool isSi
foreach (var item in hisScrips)
{
logService.ReturnTheLog(allot.ID, groupName, 2, "提取数据", $"提取{item.SourceType} - {item.Category}数据", isSingle: isSingle);
HisData(allot, configs.FirstOrDefault(t => t.Id == item.ConfigId), item);
HisData(allot, configs.FirstOrDefault(t => t.Id == item.ConfigId), item, isSingle);
}
}
catch (Exception)
......@@ -106,7 +106,7 @@ public void Handler(int hospitalId, per_allot allot, string groupName, bool isSi
}
}
private void Employee(per_allot allot, List<sys_hospitalconfig> configs, IEnumerable<ex_script> scripts)
private void Employee(per_allot allot, List<sys_hospitalconfig> configs, IEnumerable<ex_script> scripts, bool isSingle)
{
try
{
......@@ -116,12 +116,12 @@ private void Employee(per_allot allot, List<sys_hospitalconfig> configs, IEnumer
var sql = script.ExecScript;
if (config == null || string.IsNullOrEmpty(sql)) return;
var limitData = queryService.QueryData<dynamic>(config, allot, sql);
var limitData = queryService.QueryData<dynamic>(config, sql, allot, isSingle);
if (limitData == null || !limitData.Any()) return;
var columns = ((IDictionary<string, object>)limitData.ElementAt(0)).Select(t => t.Key.ToLower()).ToList();
var data = queryService.QueryData<per_employee>(config, allot, sql).ToList();
var data = queryService.QueryData<per_employee>(config, sql, allot, isSingle).ToList();
data.ForEach(t =>
{
t.AllotId = allot.ID;
......@@ -223,13 +223,13 @@ private void JudgeDataEqual(List<string> columns, List<per_employee> emps, List<
}
}
private void HisData(per_allot allot, sys_hospitalconfig config, his_script script)
private void HisData(per_allot allot, sys_hospitalconfig config, his_script script, bool isSingle)
{
try
{
if (config == null || string.IsNullOrEmpty(script.ExecScript)) return;
var data = queryService.QueryData<HisData>(config, allot, script.ExecScript);
var data = queryService.QueryData<HisData>(config, script.ExecScript, allot, isSingle);
if (data == null || !data.Any()) return;
var hisdata = hisdataRepository.GetEntities(t => t.AllotId == allot.ID && t.SourceType == script.SourceType && t.Category == script.Category);
......@@ -265,13 +265,13 @@ private void Department()
{
}
private void ExResult(per_allot allot, sys_hospitalconfig config, string sql, string enmae)
private void ExResult(per_allot allot, sys_hospitalconfig config, string sql, string enmae, bool isSingle)
{
try
{
if (config == null || string.IsNullOrEmpty(sql)) return;
var data = queryService.QueryData(config, allot, sql);
var data = queryService.QueryData<ExtractDto>(config, sql, allot, isSingle);
if (data == null || !data.Any()) return;
var createTime = DateTime.Now;
......
......@@ -52,40 +52,43 @@ public static void CreateNotExistSheet(List<ex_module> modulesList, IWorkbook wo
pairs.Add(workbook.GetSheetAt(i).SheetName, i);
}
foreach (var module in modulesList.Where(t => t.SheetType == (int)SheetType.Income)?.OrderBy(t => t.ModuleName))
try
{
var sheet = workbook.GetSheet(module.ModuleName) ?? workbook.GetSheet(module.ModuleName.NoBlank());
if (sheet == null)
foreach (var module in modulesList.Where(t => t.SheetType == (int)SheetType.Income)?.OrderBy(t => t.ModuleName))
{
var sheet = workbook.GetSheet(module.ModuleName) ?? workbook.GetSheet(module.ModuleName.NoBlank());
if (sheet == null)
{
string[] keyArray = new string[] { "开单", "就诊", "执行" };
if (keyArray.Any(key => module.ModuleName.Contains(key)))
{
var item = pairs.Where(t => t.Key.ToString().NoBlank().StartsWith("1.")).OrderByDescending(t => t.Key).First();
var copysheet = workbook.GetSheet(item.Key);
if (copysheet == null) continue;
var newSheet = copysheet.CopySheet(module.ModuleName, true);
workbook.SetSheetOrder(newSheet.SheetName, workbook.NumberOfSheets - 1);
}
}
}
foreach (var module in modulesList.Where(t => new int[] { (int)SheetType.OtherWorkload, (int)SheetType.Assess }.Contains(t.SheetType.Value))?.OrderBy(t => t.ModuleName))
{
string[] keyArray = new string[] { "开单", "就诊", "执行" };
if (keyArray.Any(key => module.ModuleName.Contains(key)))
var sheet = workbook.GetSheet(module.ModuleName) ?? workbook.GetSheet(module.ModuleName.NoBlank());
if (sheet == null)
{
var item = pairs.Where(t => t.Key.StartsWith("1.")).OrderByDescending(t => t.Key).First();
var item = pairs.Where(t => t.Key.ToString().NoBlank().StartsWith("3.")).OrderByDescending(t => t.Key).First();
var copysheet = workbook.GetSheet(item.Key);
if (copysheet == null) continue;
var newSheet = copysheet.CopySheet(module.ModuleName, true);
workbook.SetSheetOrder(newSheet.SheetName, workbook.NumberOfSheets - 1);
var point = PerSheetDataFactory.GetDataRead(SheetType.Workload)?.Point;
ClearSheetTemplate(newSheet, point, (SheetType)module.SheetType);
}
}
}
foreach (var module in modulesList.Where(t => new int[] { (int)SheetType.OtherWorkload, (int)SheetType.Assess }
.Contains(t.SheetType.Value))?.OrderBy(t => t.ModuleName))
catch
{
var sheet = workbook.GetSheet(module.ModuleName) ?? workbook.GetSheet(module.ModuleName.NoBlank());
if (sheet == null)
{
//string key = "工作量";
//if (module.ModuleName.Contains(key))
//{
var item = pairs.Where(t => t.Key.StartsWith("3.")).OrderByDescending(t => t.Key).First();
var copysheet = workbook.GetSheet(item.Key);
var newSheet = copysheet.CopySheet(module.ModuleName, true);
workbook.SetSheetOrder(newSheet.SheetName, workbook.NumberOfSheets - 1);
var point = PerSheetDataFactory.GetDataRead(SheetType.Workload)?.Point;
ClearSheetTemplate(newSheet, point, (SheetType)module.SheetType);
//}
}
}
}
......
using Microsoft.Extensions.Logging;
using Dapper;
using Microsoft.Extensions.Logging;
using NPOI.SS.UserModel;
using Performance.DtoModels;
using Performance.EntityModels;
......@@ -7,6 +8,7 @@
using Performance.Services.ExtractExcelService.SheetDataWrite;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
......@@ -79,9 +81,11 @@ PerforExresultRepository exresultRepository
/// <param name="isSingle">抽取是否在同一项目</param>
public string Main(int allotId, int hospitalId, string email, string groupName, string filePath = null, bool isSingle = false)
{
groupName = allotId.ToString();
string extractFilePath = "";
per_allot allot = null;
IWorkbook workbook = null;
IDbConnection connection = peremployeeRepository.GetDbConnection();
try
{
logService.ClearExtractLog(allotId);
......@@ -123,6 +127,11 @@ public string Main(int allotId, int hospitalId, string email, string groupName,
allot.ExtractPath = extractFilePath;
workbook.EvaluateAll();
using (FileStream file = new FileStream(extractFilePath, FileMode.OpenOrCreate))
{
workbook.Write(file);
}
workbook.Close();
}
catch (Exception ex)
{
......@@ -133,12 +142,7 @@ public string Main(int allotId, int hospitalId, string email, string groupName,
finally
{
logService.ReturnTheLog(allotId, groupName, 3, "", 100, 5, isSingle);
using (FileStream file = new FileStream(extractFilePath, FileMode.OpenOrCreate))
{
workbook.Write(file);
}
workbook.Close();
perallotRepository.Update(allot);
UpdateAllot(connection, allot);
}
return extractFilePath;
}
......@@ -329,19 +333,38 @@ private List<ExtractTransDto> StandDataFormat(int hospitalId, List<ex_result> re
Department = t.Key.Department,
Category = t.Key.Category,
Value = t.Sum(group => group.Value) == 0 ? null : t.Sum(group => group.Value),
OutDoctorAccounting = t.First().OutDoctorAccounting,
OutNurseAccounting = t.First().OutNurseAccounting,
OutTechnicAccounting = t.First().OutTechnicAccounting,
InpatDoctorAccounting = t.First().InpatDoctorAccounting,
InpatNurseAccounting = t.First().InpatNurseAccounting,
InpatTechnicAccounting = t.First().InpatTechnicAccounting,
SpecialAccounting = t.First().SpecialAccounting,
EName = t.FirstOrDefault(w => !string.IsNullOrEmpty(w.EName)).EName
OutDoctorAccounting = t.FirstOrDefault()?.OutDoctorAccounting,
OutNurseAccounting = t.FirstOrDefault()?.OutNurseAccounting,
OutTechnicAccounting = t.FirstOrDefault()?.OutTechnicAccounting,
InpatDoctorAccounting = t.FirstOrDefault()?.InpatDoctorAccounting,
InpatNurseAccounting = t.FirstOrDefault()?.InpatNurseAccounting,
InpatTechnicAccounting = t.FirstOrDefault()?.InpatTechnicAccounting,
SpecialAccounting = t.FirstOrDefault()?.SpecialAccounting,
EName = t.FirstOrDefault(w => !string.IsNullOrEmpty(w.EName))?.EName
});
return groupdata.ToList();
}
private void UpdateAllot(IDbConnection connection, per_allot allot)
{
try
{
string sql = "update per_allot set isextracting = @isextracting, extractpath = @extractpath where id = @id";
if (connection == null) return;
if (connection.State == ConnectionState.Closed)
connection.Open();
connection.Execute(sql, allot);
}
catch (Exception ex)
{
logger.LogError(ex.Message);
}
}
private readonly List<SheetType> OtherConfigSheet = new List<SheetType>
{
SheetType.AccountExtra,
......
......@@ -59,6 +59,7 @@ PerforPerallotRepository perallotRepository
}
private readonly DateTime CreateTime = DateTime.Now;
private static Dictionary<int, IDbConnection> pools = new Dictionary<int, IDbConnection>();
/// <summary>
/// 获取抽取数据
......@@ -194,8 +195,6 @@ private List<ex_result> ExtractModuleData(per_allot allot, string groupName, boo
logService.ReturnTheLog(allot.ID, groupName, 3, "", ratio > 20 ? 20 : ratio, 1, isSingle);
logService.ReturnTheLog(allot.ID, groupName, 2, "提取数据", $"开始提取模块“{string.Join("、", thisModules.Select(t => t.ModuleName))}”的数据", 1, isSingle);
Dictionary<int, IDbConnection> pools = new Dictionary<int, IDbConnection>();
foreach (var script in scripts.Where(t => t.TypeId == typeId))
{
var config = configs.FirstOrDefault(t => t.Id == script.ConfigId);
......@@ -203,20 +202,7 @@ private List<ex_result> ExtractModuleData(per_allot allot, string groupName, boo
try
{
try
{
if (!pools.ContainsKey(config.Id))
pools.Add(config.Id, ConnectionBuilder.Create((DatabaseType)config.DataBaseType, config.DbSource, config.DbName, config.DbUser, config.DbPassword));
}
catch
{
logService.ReturnTheLog(allot.ID, groupName, 2, "数据库连接", $"数据库“{config.DbName}”连接失败", 3, isSingle);
}
IDbConnection connection = pools[config.Id];
var parameters = GetParameters(allot);
var querydata = QueryData(connection, parameters, script.ExecScript);
var querydata = QueryData<ExtractDto>(config, script.ExecScript, allot, isSingle);
if (querydata != null && querydata.Any())
{
......@@ -287,7 +273,7 @@ private List<ex_result> ExtractItemData(per_allot allot, string groupName, bool
var config = configs.FirstOrDefault(t => t.Id == script.ConfigId);
if (config == null) continue;
var querydata = QueryData(config, allot, script.ExecScript);
var querydata = QueryData<ExtractDto>(config, script.ExecScript, allot, isSingle);
if (querydata != null && querydata.Any())
{
thisItems.ForEach(f =>
......@@ -351,7 +337,7 @@ private List<ex_result> ExtractSpecialData(per_allot allot, string groupName, bo
var config = configs.FirstOrDefault(t => t.Id == script.ConfigId);
if (config == null) continue;
var querydata = QueryData(config, allot, script.ExecScript);
var querydata = QueryData<ExtractDto>(config, script.ExecScript, allot, isSingle);
if (querydata != null && querydata.Any())
{
thisSpecials.ForEach(f =>
......@@ -396,62 +382,36 @@ private List<ex_result> ExtractSpecialData(per_allot allot, string groupName, bo
/// <param name="source"></param>
/// <param name="category"></param>
/// <returns></returns>
public IEnumerable<ExtractDto> QueryData(sys_hospitalconfig config, per_allot allot, string execsql)
public IEnumerable<T> QueryData<T>(sys_hospitalconfig config, string execsql, per_allot allot, bool isSingle)
{
var parameters = GetParameters(allot);
using (var connection = ConnectionBuilder.Create((DatabaseType)config.DataBaseType, config.DbSource, config.DbName, config.DbUser, config.DbPassword))
{
return QueryData(connection, parameters, execsql);
}
}
/// <summary>
/// 查询数据
/// </summary>
/// <param name="config"></param>
/// <param name="allot"></param>
/// <param name="execsql"></param>
/// <param name="source"></param>
/// <param name="category"></param>
/// <returns></returns>
public IEnumerable<ExtractDto> QueryData(IDbConnection connection, Dictionary<string, string> parameters, string execsql)
{
foreach (var item in parameters)
{
execsql = Regex.Replace(execsql, item.Key, item.Value, RegexOptions.IgnoreCase);
}
logger.LogInformation($"提取绩效数据SQL脚本{execsql}");
var result = connection.Query<ExtractDto>(execsql, commandTimeout: 20000);
logger.LogInformation($"提取绩效数据执行脚本获取数据{result?.Count() ?? 0}条记录");
IDbConnection connection = null;
try
{
if (!pools.ContainsKey(config.Id))
pools.Add(config.Id, ConnectionBuilder.Create((DatabaseType)config.DataBaseType, config.DbSource, config.DbName, config.DbUser, config.DbPassword));
connection = pools[config.Id];
return result;
}
if (connection == null) return Enumerable.Empty<T>();
/// <summary>
/// 查询数据
/// </summary>
/// <param name="config"></param>
/// <param name="allot"></param>
/// <param name="execsql"></param>
/// <param name="source"></param>
/// <param name="category"></param>
/// <returns></returns>
public IEnumerable<T> QueryData<T>(sys_hospitalconfig config, per_allot allot, string execsql)
{
var parameters = GetParameters(allot);
using (var connection = ConnectionBuilder.Create((DatabaseType)config.DataBaseType, config.DbSource, config.DbName, config.DbUser, config.DbPassword))
if (connection.State == ConnectionState.Closed)
connection.Open();
}
catch
{
foreach (var item in parameters)
{
execsql = Regex.Replace(execsql, item.Key, item.Value, RegexOptions.IgnoreCase);
}
logService.ReturnTheLog(allot.ID, allot.ID.ToString(), 2, "数据库连接", $"数据库“{config.DbName}”连接失败", 3, isSingle);
}
logger.LogInformation($"提取绩效数据SQL脚本{execsql}");
var result = connection.Query<T>(execsql, commandTimeout: 20000);
logger.LogInformation($"提取绩效数据执行脚本获取数据{result?.Count() ?? 0}条记录");
logger.LogInformation($"提取绩效数据SQL脚本{execsql}");
var result = connection.Query<T>(execsql, commandTimeout: 20000);
logger.LogInformation($"提取绩效数据执行脚本获取数据{result?.Count() ?? 0}条记录");
return result;
}
return result;
}
/// <summary>
......
......@@ -63,7 +63,7 @@ public void WriteDataToCustom(IWorkbook workbook, per_allot allot, ExcelStyle st
sheet = workbook.CreateSheet(module.ModuleName);
workbook.SetSheetOrder(sheet.SheetName, workbook.NumberOfSheets - 1);
}
ClearSheetData(sheet);
var exscript = exscripts.FirstOrDefault(t => t.TypeId == module.TypeId);
if (exscript == null) continue;
......@@ -116,5 +116,35 @@ public void WriteDataToCustom(IWorkbook workbook, per_allot allot, ExcelStyle st
}
}
}
private void ClearSheetData(ISheet sheet)
{
try
{
for (int i = Point.DataFirstRowNum.Value; i < sheet.LastRowNum + 1; i++)
{
var row = sheet.GetRow(i);
if (row != null)
{
row.ZeroHeight = false; //取消隐藏行
int dataFirstCellRowNum = Point.DataFirstCellNum.Value;
//跳过核算单元和科室
for (int j = dataFirstCellRowNum; j < row.LastCellNum; j++)
{
var cell = row.GetCell(j);
if (cell != null && cell.CellType != CellType.Formula)
{
cell.RemoveCellComment();
row.RemoveCell(cell);
}
}
}
}
}
catch (Exception ex)
{
logger.LogError(ex.Message);
}
}
}
}
......@@ -91,8 +91,8 @@ public SecondDetailDto Load(int secondId, ComputeMode computeMode, EmployeeSourc
var allot = _perallotRepository.GetEntity(t => t.ID == second.AllotId);
if (allot == null) throw new PerformanceException("绩效记录不存在!");
// 填报模板带出 行政工勤 绩效
var computes = _rescomputeRepository.GetEntities(w => w.AllotID == allot.ID && UnitTypeUtil.IsOffice(w.AccountType));
// 填报模板带出 行政工勤 绩效
var computes = _rescomputeRepository.GetEntities(w => w.AllotID == allot.ID && UnitTypeUtil.Office.Contains(w.AccountType));
var loads = GetWorkLoads(allot.HospitalId, second.UnitType, second.Department);
var employees = _peremployeeRepository.GetEntities(w => w.AllotId == second.AllotId);
......
......@@ -511,44 +511,50 @@ public void SaveSecondAllotHeadData(int secondId, string json)
List<ag_worktype_source> insertData = new List<ag_worktype_source>();
var worktypeSources = agworktypesourceRepository.GetEntities(t => t.SecondId == secondId);
if (worktypeSources == null || !worktypeSources.Any())
//多工作量
var workTypes = agworkloadtypeRepository.GetEntities();
var workValue = new List<int>();
foreach (var item in keys)
{
var workTypes = agworkloadtypeRepository.GetEntities();
var workValue = new List<int>();
foreach (var item in keys)
{
var value = item.Replace("workload_ratio_", "").Replace("workload_amount_", "");
if (!Regex.IsMatch(value, @"^\d")) continue;
workValue.Add(Convert.ToInt32(value));
}
if (workValue == null || !workValue.Any())
return;
var value = item.Replace("workload_ratio_", "").Replace("workload_amount_", "");
if (!Regex.IsMatch(value, @"^\d")) continue;
workValue.Add(Convert.ToInt32(value));
}
if (workValue == null || !workValue.Any())
return;
foreach (var value in workValue)
foreach (var value in workValue)
{
for (int i = 0; i < prefix.Length; i++)
{
for (int i = 0; i < prefix.Length; i++)
var fieldId = prefix[i] + $"{value}";
var typeName = workTypes?.FirstOrDefault(t => t.Id == value)?.TypeName;
var source = new ag_worktype_source
{
var fieldId = prefix[i] + $"{value}";
var typeName = workTypes?.FirstOrDefault(t => t.Id == value)?.TypeName;
var source = new ag_worktype_source
{
WorkTypeId = value,
SecondId = secondId,
FieldId = fieldId,
FieldName = i == 0 ? typeName + "占比" : typeName + "金额",
Value = prefix[i].StartsWith(prefix[0]) ? (decimal?)Convert.ToDecimal(dict[fieldId.ToLower()]) : null,
};
insertData.Add(source);
WorkTypeId = value,
SecondId = secondId,
FieldId = fieldId,
FieldName = i == 0 ? typeName + "占比" : typeName + "金额",
Value = prefix[i].StartsWith(prefix[0]) ? (decimal?)Convert.ToDecimal(dict[fieldId.ToLower()]) : null,
};
insertData.Add(source);
}
}
agworktypesourceRepository.AddRange(insertData.ToArray());
}
foreach (var k in worktypeSources.Select(t => t.FieldId))
{
var remove = insertData.FirstOrDefault(t => t.FieldId.EqualsIgnoreCase(k));
if (remove != null)
{
insertData.Remove(remove);
}
}
agworktypesourceRepository.AddRange(insertData.ToArray());
worktypeSources = agworktypesourceRepository.GetEntities(t => t.SecondId == secondId);
foreach (var key in keys)
{
var update = worktypeSources.FirstOrDefault(t => t.FieldId.EqualsIgnoreCase(key));
......
......@@ -8,6 +8,8 @@ namespace Performance.Services
{
public class UnitTypeUtil
{
public static string[] Office = new string[] { "行政后勤", "行政工勤" };
/// <summary>
/// 是否是行政后勤/工勤
/// </summary>
......@@ -17,6 +19,7 @@ public static bool IsOffice(int? unit)
{
return unit == (int)UnitType.行政后勤;
}
/// <summary>
/// 是否是行政后勤/工勤
/// </summary>
......@@ -24,7 +27,7 @@ public static bool IsOffice(int? unit)
/// <returns></returns>
public static bool IsOffice(string unit)
{
return !string.IsNullOrEmpty(unit) && (unit == "行政后勤" || unit == "行政工勤");
return !string.IsNullOrEmpty(unit) && Office.Contains(unit);
}
/// <summary>
......@@ -47,7 +50,7 @@ public static bool Is(string unit, params UnitType[] types)
public class AccountTypeUnit
{
private static string[] dic = new string[] { "科主任", "护士长" };
/// <summary>
/// 自动识别职称文本
/// </summary>
......
......@@ -782,6 +782,9 @@ public string SaveUserHandsFlat(UserCollectData request)
{
if (item == null) return "必填项为空";
var HospitalId = hospitals.FirstOrDefault(w => w.HosName == item)?.ID;
if (HospitalId == null) return "未找到分配医院";
var allot = _perallotRepository.GetEntities(t => t.HospitalId == HospitalId);
var accountingUnits = accounts?.Join(allot, t => t.AllotId, w => w.ID, (t, w) => t.AccountingUnit).Distinct().ToList();
res.Add(item, accountingUnits);
......
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