Commit 173a1b4c by lcx

二次绩效添加日志,同项目配置抽取

parent e75d6f96
......@@ -13,6 +13,7 @@
using Performance.EntityModels;
using Performance.Infrastructure;
using Performance.Services;
using Performance.Services.ExtractExcelService;
using System;
using System.Collections.Generic;
using System.IO;
......@@ -26,6 +27,7 @@ public class TemplateController : Controller
private readonly TemplateService templateService;
private readonly DFExtractService extractService;
private readonly ExtractIncomeService extractIncomeService;
private readonly ExtractService extractEService;
private HospitalService hospitalService;
private IHostingEnvironment env;
private ClaimService claim;
......@@ -39,6 +41,7 @@ public class TemplateController : Controller
HospitalService hospitalService,
DFExtractService extractService,
ExtractIncomeService extractIncomeService,
ExtractService extractEService,
IHostingEnvironment env,
ClaimService claim,
IOptions<Application> options,
......@@ -50,6 +53,7 @@ public class TemplateController : Controller
this.templateService = templateService;
this.extractService = extractService;
this.extractIncomeService = extractIncomeService;
this.extractEService = extractEService;
this.hospitalService = hospitalService;
this.env = env;
this.claim = claim;
......@@ -232,7 +236,8 @@ public ApiResponse NewExtractData([CustomizeValidator, FromBody] ExtractRequest
// 判断是那种抽取
try
{
string message = extractService.Judge(request.AllotId, request.HospitalId, request.UseScheme, out string filePath);
bool isSingle = false;
string message = extractService.Judge(request.AllotId, request.HospitalId, request.UseScheme, ref isSingle, out string filePath);
if (!string.IsNullOrEmpty(message))
return new ApiResponse(ResponseType.Fail, message);
......@@ -241,15 +246,20 @@ public ApiResponse NewExtractData([CustomizeValidator, FromBody] ExtractRequest
return new ApiResponse(ResponseType.OK, "正在提取数据,请稍等!", new { IsExtracting = true });
allot.IsExtracting = 1;
allotService.Update(allot);
string email = claim.GetUserClaim(JwtClaimTypes.Mail);
//request.Email = claim.GetUserClaim(JwtClaimTypes.Mail);
logger.LogInformation("提取绩效数据请求路径:" + url.HttpPost + "/extract/extract");
//HttpHelper.HttpPostNoRequest(url.HttpPost + "/extract/extract", JsonHelper.Serialize(request), true);
if (string.IsNullOrEmpty(filePath))
HttpHelper.HttpPostNoRequest(url.HttpPost + $"/extract/extract?allotId={request.AllotId}&hospitalId={request.HospitalId}&email={claim.GetUserClaim(JwtClaimTypes.Mail)}&userId={claim.GetUserId()}", "");
if (isSingle)
{
extractEService.Main(allot.ID, allot.HospitalId, email, "User" + claim.GetUserId(), filePath, true);
}
else
HttpHelper.HttpClient(url.HttpPost + $"/extract/extract?allotId={request.AllotId}&hospitalId={request.HospitalId}&email={claim.GetUserClaim(JwtClaimTypes.Mail)}&userId={claim.GetUserId()}", filePath, true);
{
logger.LogInformation("提取绩效数据请求路径:" + url.HttpPost + "/extract/extract");
if (string.IsNullOrEmpty(filePath))
HttpHelper.HttpPostNoRequest(url.HttpPost + $"/extract/extract?allotId={request.AllotId}&hospitalId={request.HospitalId}&email={email}&userId={claim.GetUserId()}", "");
else
HttpHelper.HttpClient(url.HttpPost + $"/extract/extract?allotId={request.AllotId}&hospitalId={request.HospitalId}&email={email}&userId={claim.GetUserId()}", filePath, true);
}
return new ApiResponse(ResponseType.OK, "HIS绩效数据提取任务正在执行,稍后我们将以邮件的通知您!", new { IsExtracting = false });
}
......
......@@ -105,5 +105,10 @@ public class sys_hospital
/// 是否开启行政后勤二次绩效分配 1 启用 2 禁用
/// </summary>
public Nullable<int> IsOpenLogisticsSecondAllot { get; set; }
/// <summary>
/// 抽取项目是否在同一环境 1 是 2 否
/// </summary>
public Nullable<int> IsSingleProject { get; set; }
}
}
......@@ -153,8 +153,8 @@ public void ExtractData([FromForm] IFormCollection form, int allotId, int hospit
#endregion
//string filePath = newExtractService.ExtractData(allotId, request.Email, hospitalId);
string filePath = extractService.ExtractData(allotId, email, hospitalId, "User" + userId, path); //抽取
//string filePath = extractService1.Main(allotId, hospitalId, email, "User" + userId, path);
//string filePath = extractService.ExtractData(allotId, email, hospitalId, "User" + userId, path); //抽取
string filePath = extractService1.Main(allotId, hospitalId, email, "User" + userId, path);
#region 保存文件到网站下
......
......@@ -77,7 +77,8 @@ public IEnumerable<CollectPermission> GetCollectContent(int hospitalId, int user
var types = new[] { (int)SheetType.Employee, (int)SheetType.OtherIncome, (int)SheetType.Expend, (int)SheetType.Workload,
(int)SheetType.ClinicEmployee, (int)SheetType.AccountExtra, (int)SheetType.PersonExtra, (int)SheetType.LogisticsEmployee,
(int)SheetType.AccountDrugAssess, (int)SheetType.AccountMaterialsAssess};
(int)SheetType.AccountDrugAssess, (int)SheetType.AccountMaterialsAssess, (int)SheetType.AccountScoreAverage,
(int)SheetType.BudgetRatio, (int)SheetType.AssessBeforeOtherFee };
var sheets = perforPersheetRepository.GetEntities(w => w.AllotID == allot.ID && types.Contains((w.SheetType ?? 0)));
var headers = perforImheaderRepository.GetEntities(w => w.AllotID == allot.ID);
......
......@@ -2443,7 +2443,7 @@ public void OutToExcelCell<T>(ICell cell, object obj, T defaultValue = default)
/// <param name="allotId"></param>
/// <param name="hospitalId"></param>
/// <param name="useTemplate"></param>
public string Judge(int allotId, int hospitalId, int useTemplate, out string filePath)
public string Judge(int allotId, int hospitalId, int useTemplate, ref bool isSingle, out string filePath)
{
string result = null;
filePath = "";
......@@ -2457,6 +2457,7 @@ public string Judge(int allotId, int hospitalId, int useTemplate, out string fil
var hospital = perforHospitalRepository.GetEntity(t => t.ID == hospitalId);
if (hospital == null)
throw new PerformanceException("医院ID错误");
isSingle = (hospital.IsSingleProject ?? 2) == 1;
// 获取医院配置信息
var hospitalConfigList = perforHospitalconfigRepository.GetEntities(t => t.HospitalId == hospitalId);
if (hospitalConfigList == null || hospitalConfigList.Count == 0)
......
......@@ -376,7 +376,7 @@ public bool Audit(int allotId)
public List<per_apr_amount> GetAprList(int allotId)
{
var list = perapramountRepository.GetEntities(t => t.AllotId == allotId && t.Amount != 0);
var list = perapramountRepository.GetEntities(t => t.AllotId == allotId && (t.Amount ?? 0) != 0);
if (list != null && list.Any())
list = list.OrderBy(t => t.DoctorName).ToList();
......@@ -385,7 +385,7 @@ public List<per_apr_amount> GetAprList(int allotId)
public List<per_apr_amount> GetAprList(int allotId, string accountingUnit, string department)
{
var list = perapramountRepository.GetEntities(t => t.AllotId == allotId && t.Amount != 0 && (t.AccountingUnit ?? "") == accountingUnit && (t.TypeInDepartment ?? "") == department);
var list = perapramountRepository.GetEntities(t => t.AllotId == allotId && (t.Amount ?? 0) != 0 && (t.AccountingUnit ?? "") == accountingUnit && (t.TypeInDepartment ?? "") == department);
if (list != null && list.Any())
list = list.OrderBy(t => t.DoctorName).ToList();
......
......@@ -55,42 +55,48 @@ PerforPeremployeeRepository peremployeeRepository
/// <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)
/// <param name="isSingle">抽取是否在同一项目</param>
public string Main(int allotId, int hospitalId, string email, string groupName, string filePath = null, bool isSingle = false)
{
string extractFilePath = "";
IWorkbook workbook = null;
try
{
logService.ClearExtractLog(allotId);
logService.ReturnTheLog(allotId, groupName, 2, "等待提取", $"确认配置信息是否可完成数据提取...", 1, isSingle);
var hospital = hospitalRepository.GetEntity(t => t.ID == hospitalId);
logService.ClearExtractLog(allotId);
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 dict = new Dictionary<ExDataDict, object>();
var data = queryService.Handler(hospitalId, allot, ref dict);
logService.ReturnTheLog(allotId, groupName, 3, "", 5, 1, isSingle);
var data = queryService.Handler(hospitalId, allot, groupName, isSingle, ref dict);
var standData = StandDataFormat(hospitalId, data);
var statesArray = new int[] { (int)AllotStates.GenerateSucceed, (int)AllotStates.Archive };
var templateFilePath = ExtractHelper.GetExtractFile(hospitalId, ref extractFilePath, filePath);
logService.ReturnTheLog(allotId, groupName, 2, "创建文件", $"模板文件: {templateFilePath}", 1, isSingle);
if (!FileHelper.IsExistFile(templateFilePath)) throw new PerformanceException("抽取文件创建失败");
workbook = ExcelHelper.GetWorkbook(templateFilePath);
if (workbook == null) throw new PerformanceException("文件读取失败");
WriteDataToFile(workbook, allotId, dict, standData);
WriteDataToFile(workbook, allotId, dict, standData, groupName, isSingle);
logService.ReturnTheLog(allotId, groupName, 2, "提取完成", $"绩效数据提取成功", 5, isSingle);
}
catch (Exception ex)
{
logService.ReturnTheLog(allotId, groupName, 2, "提取完成", $"绩效数据提取失败", 4, isSingle);
logger.LogError("提取数据中发生异常: " + ex.ToString());
}
finally
{
logService.ReturnTheLog(allotId, groupName, 3, "", 100, 5, isSingle);
using (FileStream file = new FileStream(extractFilePath, FileMode.OpenOrCreate))
{
workbook.Write(file);
......@@ -100,7 +106,7 @@ public string Main(int allotId, int hospitalId, string email, string groupName =
return extractFilePath;
}
private void WriteDataToFile(IWorkbook workbook, int allotId, Dictionary<ExDataDict, object> exdict, List<ExtractTransDto> extractDto)
private void WriteDataToFile(IWorkbook workbook, int allotId, Dictionary<ExDataDict, object> exdict, List<ExtractTransDto> extractDto, string groupName, bool isSingle)
{
ExcelStyle style = new ExcelStyle(workbook);
......@@ -111,15 +117,22 @@ private void WriteDataToFile(IWorkbook workbook, int allotId, Dictionary<ExDataD
var collectData = collectdataRepository.GetEntities(t => t.AllotID == allotId);
WriteDataFactory factory = new WriteDataFactory();
var types = new List<SheetType> { SheetType.OtherIncome, SheetType.Income, SheetType.Expend, SheetType.Workload };
var types = new List<SheetType> { SheetType.OtherIncome, SheetType.Income, SheetType.Expend, SheetType.Workload, SheetType.OtherWorkload };
decimal ratio = 60m;
for (int sheetIndex = 0; sheetIndex < workbook.NumberOfSheets; sheetIndex++)
{
var sheet = workbook.GetSheetAt(sheetIndex);
ratio += 40m / workbook.NumberOfSheets;
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);
var point = PerSheetDataFactory.GetDataRead(sheetType)?.Point;
if (sheetType == SheetType.OtherWorkload) point = PerSheetDataFactory.GetDataRead(SheetType.Workload)?.Point;
if (types.Contains(sheetType) && point != null && point.DataFirstCellNum.HasValue)
ExtractHelper.ClearSheetPartialData(sheet, point, sheetType);
......@@ -135,6 +148,8 @@ private void WriteDataToFile(IWorkbook workbook, int allotId, Dictionary<ExDataD
var data = GetDataBySheetType(sheetType, exdata, employeeDict);
customer.WriteSheetData(sheet, point, sheetType, style, data, exdict);
}
logService.ReturnTheLog(allotId, groupName, 2, "写入数据", $"sheet“{sheet.SheetName}”已完成数据写入", 1, isSingle);
}
}
......@@ -215,22 +230,5 @@ private List<ExtractTransDto> StandDataFormat(int hospitalId, List<ex_result> re
return groupdata.ToList();
}
//public void ProgressBar(int allotId, decimal ratio, int level = 1)
//{
// if (!string.IsNullOrEmpty(GroupName))
// {
// logService.ReturnTheLog(allotId, GroupName, 3, "", Math.Round(ratio, 2, MidpointRounding.AwayFromZero), level);
// }
//}
//public void Message(int allotId, string tag, string message, int level = 1)
//{
// if (!string.IsNullOrEmpty(GroupName))
// {
// logService.ReturnTheLog(allotId, GroupName, 2, tag, message, level);
// }
//}
}
}
......@@ -21,6 +21,7 @@ public enum ExDataDict
public class QueryService : IAutoInjection
{
private readonly ILogger logger;
private readonly LogManageService logService;
private readonly PerforExmoduleRepository exmoduleRepository;
private readonly PerforExitemRepository exitemRepository;
private readonly PerforExspecialRepository exspecialRepository;
......@@ -31,6 +32,7 @@ public class QueryService : IAutoInjection
public QueryService(
ILogger<QueryService> logger,
LogManageService logService,
PerforExmoduleRepository exmoduleRepository,
PerforExitemRepository exitemRepository,
PerforExspecialRepository exspecialRepository,
......@@ -41,6 +43,7 @@ PerforPerallotRepository perallotRepository
)
{
this.logger = logger;
this.logService = logService;
this.exmoduleRepository = exmoduleRepository;
this.exitemRepository = exitemRepository;
this.exspecialRepository = exspecialRepository;
......@@ -58,7 +61,7 @@ PerforPerallotRepository perallotRepository
/// <param name="hospitalId"></param>
/// <param name="allot"></param>
/// <returns></returns>
public List<ex_result> Handler(int hospitalId, per_allot allot, ref Dictionary<ExDataDict, object> dict)
public List<ex_result> Handler(int hospitalId, per_allot allot, string groupName, bool isSingle, ref Dictionary<ExDataDict, object> dict)
{
try
{
......@@ -73,9 +76,12 @@ public List<ex_result> Handler(int hospitalId, per_allot allot, ref Dictionary<E
};
var extypeIds = GetQueryScriptIds(hospitalId, ref dict);
ClearHistoryData(allot.ID);
ClearHistoryData(allot.ID, groupName, isSingle);
var data = new List<ex_result>();
logService.ReturnTheLog(allot.ID, groupName, 2, "提取数据", $"开始提取数据");
var scripts = exscriptRepository.GetEntities(t => extypeIds.Contains(t.TypeId));
if (scripts != null && scripts.Any())
{
......@@ -86,13 +92,13 @@ public List<ex_result> Handler(int hospitalId, per_allot allot, ref Dictionary<E
switch (pair.Key)
{
case ExDataDict.ExModule:
data.AddRange(ExtractModuleData(allot, scripts, configs, pair.Value));
data.AddRange(ExtractModuleData(allot, groupName, isSingle, scripts, configs, pair.Value));
break;
case ExDataDict.ExItem:
data.AddRange(ExtractItemData(allot, scripts, configs, allmodules, pair.Value));
data.AddRange(ExtractItemData(allot, groupName, isSingle, scripts, configs, allmodules, pair.Value));
break;
case ExDataDict.ExSpecial:
data.AddRange(ExtractSpecialData(allot, scripts, configs, pair.Value));
data.AddRange(ExtractSpecialData(allot, groupName, isSingle, scripts, configs, pair.Value));
break;
}
}
......@@ -148,13 +154,11 @@ private List<int> GetQueryScriptIds(int hospitalId, ref Dictionary<ExDataDict, o
/// 清除历史抽取数据
/// </summary>
/// <param name="allotId"></param>
private void ClearHistoryData(int allotId)
private void ClearHistoryData(int allotId, string groupName, bool isSingle)
{
logger.LogInformation($"开始清除历史提取数据");
logService.ReturnTheLog(allotId, groupName, 2, "清除数据", $"开始清除历史提取数据", 1, isSingle);
perallotRepository.ClearResultData(allotId);
logger.LogInformation($"清除历史提取数据已完成");
logService.ReturnTheLog(allotId, groupName, 2, "清除数据", $"清除历史提取数据已完成", 1, isSingle);
}
#region ExResultData
......@@ -167,18 +171,24 @@ private void ClearHistoryData(int allotId)
/// <param name="configs"></param>
/// <param name="dictValue"></param>
/// <returns></returns>
private List<ex_result> ExtractModuleData(per_allot allot, List<ex_script> scripts, List<sys_hospitalconfig> configs, object dictValue)
private List<ex_result> ExtractModuleData(per_allot allot, string groupName, bool isSingle, List<ex_script> scripts, List<sys_hospitalconfig> configs, object dictValue)
{
var data = new List<ex_result>();
if (dictValue is List<ex_module> modules && modules != null && modules.Any(t => t.TypeId.HasValue && t.TypeId > 0))
{
var typeIds = modules.Where(t => t.TypeId.HasValue && t.TypeId > 0).Select(t => t.TypeId.Value).Distinct().ToList();
if (typeIds == null || typeIds.Count == 0) return new List<ex_result>();
var typeIds = modules.Where(t => t.TypeId.HasValue && t.TypeId > 0)?.Select(t => t.TypeId.Value).Distinct().ToList();
if (typeIds == null || typeIds.Count == 0) return data;
decimal ratio = 5m;
foreach (var typeId in typeIds)
{
var thisModules = modules.Where(t => t.TypeId == typeId).ToList();
ratio += 15m / typeIds.Count();
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);
foreach (var script in scripts.Where(t => t.TypeId == typeId))
{
var config = configs.FirstOrDefault(t => t.Id == script.ConfigId) ?? configs.FirstOrDefault(t => t.DataBaseType == script.DatabaseType);
......@@ -187,8 +197,6 @@ private List<ex_result> ExtractModuleData(per_allot allot, List<ex_script> scrip
var querydata = QueryData(config, allot, script.ExecScript);
if (querydata != null && querydata.Any())
{
var thisModules = modules.Where(t => t.TypeId == typeId).ToList();
thisModules.ForEach(f =>
{
var result = querydata.Select(t => new ex_result
......@@ -209,6 +217,8 @@ private List<ex_result> ExtractModuleData(per_allot allot, List<ex_script> scrip
});
}
}
logService.ReturnTheLog(allot.ID, groupName, 2, "提取数据", $"模块“{string.Join("、", thisModules.Select(t => t.ModuleName))}”的数据已完成提取", 1, isSingle);
}
}
......@@ -224,16 +234,25 @@ private List<ex_result> ExtractModuleData(per_allot allot, List<ex_script> scrip
/// <param name="modules"></param>
/// <param name="dictValue"></param>
/// <returns></returns>
private List<ex_result> ExtractItemData(per_allot allot, List<ex_script> scripts, List<sys_hospitalconfig> configs, List<ex_module> modules, object dictValue)
private List<ex_result> ExtractItemData(per_allot allot, string groupName, bool isSingle, List<ex_script> scripts, List<sys_hospitalconfig> configs, List<ex_module> modules, object dictValue)
{
var data = new List<ex_result>();
if (dictValue is List<ex_item> items && items != null && items.Any(t => t.TypeId.HasValue && t.TypeId > 0))
{
var typeIds = items.Where(t => t.TypeId.HasValue && t.TypeId > 0).Select(t => t.TypeId.Value).Distinct().ToList();
var typeIds = items.Where(t => t.TypeId.HasValue && t.TypeId > 0)?.Select(t => t.TypeId.Value).Distinct().ToList();
if (typeIds == null || typeIds.Count == 0) return data;
decimal ratio = 20m;
foreach (var typeId in typeIds)
{
var thisItems = items.Where(t => t.TypeId == typeId).ToList();
var modulename = modules.FirstOrDefault(t => t.Id == thisItems.First().ModuleId)?.ModuleName;
ratio += 30m / typeIds.Count();
logService.ReturnTheLog(allot.ID, groupName, 3, "", ratio > 50 ? 50 : ratio, 1, isSingle);
logService.ReturnTheLog(allot.ID, groupName, 2, "提取数据", $"开始提取项目“{string.Join("、", thisItems.Select(t => t.ItemName))}”的数据", 1, isSingle);
foreach (var script in scripts.Where(t => t.TypeId == typeId))
{
var config = configs.FirstOrDefault(t => t.Id == script.ConfigId);
......@@ -242,9 +261,6 @@ private List<ex_result> ExtractItemData(per_allot allot, List<ex_script> scripts
var querydata = QueryData(config, allot, script.ExecScript);
if (querydata != null && querydata.Any())
{
var thisItems = items.Where(t => t.TypeId == typeId).ToList();
var modulename = modules.FirstOrDefault(t => t.Id == thisItems.First().ModuleId)?.ModuleName;
thisItems.ForEach(f =>
{
var result = querydata.Select(t => new ex_result
......@@ -265,6 +281,8 @@ private List<ex_result> ExtractItemData(per_allot allot, List<ex_script> scripts
});
}
}
logService.ReturnTheLog(allot.ID, groupName, 2, "提取数据", $"项目“{string.Join("、", thisItems.Select(t => t.ItemName))}”的数据已完成提取", 1, isSingle);
}
}
......@@ -279,16 +297,24 @@ private List<ex_result> ExtractItemData(per_allot allot, List<ex_script> scripts
/// <param name="configs"></param>
/// <param name="dictValue"></param>
/// <returns></returns>
private List<ex_result> ExtractSpecialData(per_allot allot, List<ex_script> scripts, List<sys_hospitalconfig> configs, object dictValue)
private List<ex_result> ExtractSpecialData(per_allot allot, string groupName, bool isSingle, List<ex_script> scripts, List<sys_hospitalconfig> configs, object dictValue)
{
var data = new List<ex_result>();
if (dictValue is List<ex_special> specials && specials != null && specials.Any(t => t.TypeId.HasValue && t.TypeId > 0))
{
var typeIds = specials.Where(t => t.TypeId.HasValue && t.TypeId > 0).Select(t => t.TypeId.Value).Distinct().ToList();
var typeIds = specials.Where(t => t.TypeId.HasValue && t.TypeId > 0)?.Select(t => t.TypeId.Value).Distinct().ToList();
if (typeIds == null || typeIds.Count == 0) return data;
decimal ratio = 50m;
foreach (var typeId in typeIds)
{
var thisSpecials = specials.Where(t => t.TypeId == typeId).ToList();
ratio += 10m / typeIds.Count();
logService.ReturnTheLog(allot.ID, groupName, 3, "", ratio > 60 ? 60 : ratio, 1, isSingle);
logService.ReturnTheLog(allot.ID, groupName, 2, "提取数据", $"开始提取项目“{string.Join("、", thisSpecials.Select(t => t.Target))}”的数据", 1, isSingle);
foreach (var script in scripts.Where(t => t.TypeId == typeId))
{
var config = configs.FirstOrDefault(t => t.Id == script.ConfigId);
......@@ -297,8 +323,6 @@ private List<ex_result> ExtractSpecialData(per_allot allot, List<ex_script> scri
var querydata = QueryData(config, allot, script.ExecScript);
if (querydata != null && querydata.Any())
{
var thisSpecials = specials.Where(t => t.TypeId == typeId).ToList();
thisSpecials.ForEach(f =>
{
var result = querydata.Select(t => new ex_result
......@@ -319,6 +343,8 @@ private List<ex_result> ExtractSpecialData(per_allot allot, List<ex_script> scri
});
}
}
logService.ReturnTheLog(allot.ID, groupName, 2, "提取数据", $"项目“{string.Join("、", thisSpecials.Select(t => t.Target))}”的数据已完成提取", 1, isSingle);
}
}
......
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
{
public class OtherWorkloadDataWrite : 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 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.Trim(),
DoctorFactor = 0,
NurseFactor = 0,
TechnicianFactor = 0
}).ToList();
WriteDataHelper.WriteSheetHeader(sheet, point, sheetType, style, headers);
WriteDataHelper.WriteCollectData(sheet, point, sheetType, style, columns, collects);
}
public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetType, ExcelStyle style, object data, Dictionary<ExDataDict, object> exdict = null)
{
var modules = exdict[ExDataDict.ExModule] as List<ex_module>;
var module = modules?.FirstOrDefault(t => t.SheetType == (int)sheetType && t.ModuleName.NoBlank() == sheet.SheetName.NoBlank());
if (module == null) return;
var items = exdict[ExDataDict.ExItem] as List<ex_item>;
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, style, 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, style, columns, extractDto);
}
}
}
}
......@@ -54,12 +54,6 @@ public void WriteMsg(string tag, string message, int level, int allotId, string
/// <param name="success"></param>
public void Schedule(string groupName, decimal ratio, int level)
{
ratio = Math.Round(ratio);
if (level != 5 && ratio > 100) ratio = 99;
if (level == 5 && ratio != 100) ratio = 100;
hubContext.Clients.Group(groupName).SendAsync("Schedule", ratio, level);
}
......@@ -72,18 +66,45 @@ public void Schedule(string groupName, decimal ratio, int level)
/// <param name="level">等级1、信息(info)2、警告(warn)3、错误(error)4、异常(exception)5、成功(success)</param>
public void ExtractLog(string groupName, string tag, string message, int level)
{
hubContext.Clients.Group(groupName).SendAsync("ExtractLog", tag, message, level);
}
public void ReturnTheLog(int allotId, string groupName, int type, string tag, object message, int level = 1)
/// <summary>
///
/// </summary>
/// <param name="allotId"></param>
/// <param name="groupName"></param>
/// <param name="type">1、绩效生成日志 2、绩效提取日志 3、绩效提取进度</param>
/// <param name="tag"></param>
/// <param name="message"></param>
/// <param name="level">1、信息(info)2、警告(warn)3、错误(error)4、异常(exception)5、成功(success)</param>
/// <param name="isSingle"></param>
public void ReturnTheLog(int allotId, string groupName, int type, string tag, object message, int level = 1, bool isSingle = false)
{
try
{
var http = url.ImportFile + $"/template/returnlog?type={type}&tag={tag}&message={message}&level={level}&groupName={groupName}";
//logger.LogInformation("发送日志:" + http);
logdbug.Add(allotId, tag, message.ToString(), level, type);
HttpHelper.HttpPost(http);
string content = ""; decimal ratio = 0;
if (type == 2)
{
ratio = Math.Round(Convert.ToDecimal(message), 2, MidpointRounding.AwayFromZero);
if (level != 5 && ratio > 100) ratio = 99;
if (level == 5 && ratio != 100) ratio = 100;
content = ratio.ToString();
if (isSingle) hubContext.Clients.Group(groupName).SendAsync("Schedule", ratio, level);
}
else if (type == 3)
{
content = message.ToString();
logger.LogInformation(content);
if (isSingle) hubContext.Clients.Group(groupName).SendAsync("ExtractLog", tag, content, level);
}
logdbug.Add(allotId, tag, content, level, type);
if (!isSingle)
{
var http = url.ImportFile + $"/template/returnlog?type={type}&tag={tag}&message={content}&level={level}&groupName={groupName}";
HttpHelper.HttpPost(http);
}
}
catch (Exception ex)
{
......
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