Commit 2de004d6 by lcx

定时任务抽取、4.1写入跳过非核算

parent 8817e11d
......@@ -527,18 +527,17 @@ public ApiResponse DepttypeDelete([CustomizeValidator(RuleSet = "Delete"), FromB
/// <summary>
/// 获取cof_accounting列表
/// </summary>
/// <param name="allotId"></param>
/// <param name="type">1 返回accounting列表 2 返回核算单元类型 3 返回核算单元</param>
/// <param name="request"></param>
/// <returns></returns>
[Route("accountinglist/{allotId}/{type}")]
[HttpPost]
public ApiResponse GetAccountingList([FromRoute] int allotId, int type)
public ApiResponse GetAccountingList([FromBody] AccoungingRequest request)
{
if (allotId == 0 || !new int[] { 1, 2, 3 }.Contains(type))
if (request.AllotId == 0 || !new int[] { 1, 2, 3 }.Contains(request.Type))
return new ApiResponse(ResponseType.ParameterError);
var list = _configService.GetAccountingList(allotId) ?? new List<cof_accounting>();
switch (type)
var list = _configService.GetAccountingList(request) ?? new List<cof_accounting>();
switch (request.Type)
{
case 1:
default: //返回accounting列表
......
using FluentScheduler;
using Microsoft.Extensions.DependencyInjection;
using Performance.Services;
using Performance.Services.ExtractExcelService;
namespace Performance.Api
{
public class ExtractGenerateJob : IJob
{
private readonly ExtractJobService extractJobService;
public ExtractGenerateJob()
{
this.extractJobService = ServiceLocator.Instance.GetService<ExtractJobService>();
}
public void Execute()
{
extractJobService.ExportFile();
}
}
}
......@@ -7,7 +7,8 @@ public class JobRegistry : Registry
public JobRegistry()
{
//Schedule<ExtractDataJob>().ToRunNow().AndEvery(1).Days().At(23, 0);
Schedule<ExtractDataJob>().ToRunEvery(1).Days().At(23, 0);
//Schedule<ExtractDataJob>().ToRunEvery(1).Days().At(23, 0);
Schedule<ExtractGenerateJob>().ToRunEvery(1).Days().At(1, 0);
}
}
}
......@@ -612,7 +612,7 @@
获取cof_accounting列表
</summary>
<param name="allotId"></param>
<param name="type"></param>
<param name="type">1 返回accounting列表 2 返回核算单元类型 3 返回核算单元</param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ConfigController.AccountingInsert(Performance.EntityModels.cof_accounting)">
......
namespace Performance.DtoModels
{
public class AccoungingRequest
{
/// <summary>
/// 绩效Id
/// </summary>
public int AllotId { get; set; }
/// <summary>
/// 1 返回accounting列表 2 返回核算单元类型 3 返回核算单元
/// </summary>
public int Type { get; set; }
/// <summary>
/// 核算单元类型、核算组别
/// </summary>
public string UnitType { get; set; }
}
}
......@@ -183,13 +183,14 @@ public IEnumerable<report_original_workload> QueryWorkloadData(int allotid, stri
string unittype = unittypes.Any(t => !string.IsNullOrEmpty(t) && t.Contains("医生"))
? "医生组"
: unittypes.Any(t => !string.IsNullOrEmpty(t) && t.Contains("护理")) ? "护理组" : "其他组";
string clear = @"SELECT DISTINCT t3.AccountingUnit as Department,ifnull(t1.DoctorName, '未知') DoctorName,t1.PersonnelNumber,t1.Category,t1.Fee FROM ex_result t1
string clear = @"SELECT DISTINCT t3.AccountingUnit as Department,ifnull(t1.DoctorName, '未知') DoctorName,t1.PersonnelNumber,t1.Category,SUM(t1.Fee) Fee FROM ex_result t1
JOIN (select distinct AccountingUnit,HISDeptName,unittype from per_dept_dic where HospitalId = @hospitalid) t3 ON t1.Department = t3.HISDeptName
WHERE t1.allotid = @allotid
AND t3.unittype in @unittypes
AND t3.accountingunit = @accountingunit
AND t1.Source LIKE CONCAT('%',@unittype,'工作量%')
AND T1.IsDelete = 0
GROUP BY ifnull(t1.DoctorName, '未知'),t1.PersonnelNumber,t1.Category
ORDER BY t1.doctorname,t1.Category;";
return connection.Query<report_original_workload>(clear, new { allotid, accountingunit, unittypes, unittype, hospitalid }, commandTimeout: 60 * 60);
}
......@@ -211,13 +212,14 @@ public IEnumerable<ex_result> QueryIncomeData(int allotid, string source, string
if (connection.State != ConnectionState.Open) connection.Open();
try
{
string clear = $@"SELECT DISTINCT t3.AccountingUnit as Department,ifnull(t1.DoctorName, '未知') DoctorName,t1.PersonnelNumber,t1.Category,t1.Fee FROM ex_result t1
string clear = $@"SELECT DISTINCT t3.AccountingUnit as Department,ifnull(t1.DoctorName, '未知') DoctorName,t1.PersonnelNumber,t1.Category,SUM(t1.Fee) Fee FROM ex_result t1
JOIN (select distinct AccountingUnit,HISDeptName,unittype from per_dept_dic where HospitalId = @hospitalid) t3 ON t1.Department = t3.HISDeptName
WHERE t1.allotid = @allotid
AND t3.unittype in @unittype
AND t3.accountingunit = @accountingunit
AND (t1.Source like '%{source}开单%' OR t1.Source like '%{source}就诊%')
AND T1.IsDelete = 0
GROUP BY ifnull(t1.DoctorName, '未知'),t1.PersonnelNumber,t1.Category
ORDER BY t1.doctorname,t1.Category;";
return connection.Query<ex_result>(clear, new { allotid, accountingunit, unittype, hospitalid }, commandTimeout: 60 * 60);
}
......
......@@ -641,9 +641,10 @@ public bool AgainDelete(CofAgainRequest request)
/// 获取cof_accounting列表
/// </summary>
/// <returns></returns>
public List<cof_accounting> GetAccountingList(int allotId)
public List<cof_accounting> GetAccountingList(AccoungingRequest request)
{
var list = cofaccountingRepository.GetEntities(t => t.AllotId == allotId);
var list = request.Type != 2 ? cofaccountingRepository.GetEntities(t => t.AllotId == request.AllotId)
: cofaccountingRepository.GetEntities(t => t.AllotId == request.AllotId && t.UnitType == request.UnitType);
return list;
}
......
......@@ -126,11 +126,11 @@ public static void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType s
var row = sheet.GetRow(rowIndex);
if (row == null) continue;
if (rowIndex > dataFirstRowNum) dataFirstRowNum = rowIndex + 1;
string department = row.GetOrCreate(dataFirstCellNum - 1).GetDecodeEscapes();
if (string.IsNullOrEmpty(department)) continue;
if (rowIndex > dataFirstRowNum) dataFirstRowNum = rowIndex + 1;
var deptData = data.Where(t => t.Department == department);
if (deptData == null || !deptData.Any(t => t.Value.HasValue && t.Value != 0)) continue;
......@@ -348,11 +348,11 @@ public static void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType
var row = sheet.GetRow(rowIndex);
if (row == null) continue;
if (rowIndex > dataFirstRowNum) dataFirstRowNum = rowIndex + 1;
string department = row.GetOrCreate(dataFirstCellNum - 1).GetDecodeEscapes();
if (string.IsNullOrEmpty(department)) continue;
if (rowIndex > dataFirstRowNum) dataFirstRowNum = rowIndex + 1;
var deptData = data.Where(t => t.Department == department);
if (deptData == null || !deptData.Any(t => !string.IsNullOrEmpty(t.CellValue))) continue;
......
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
using Performance.DtoModels;
using Performance.EntityModels;
using Performance.Infrastructure;
using Performance.Repository;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Performance.Services.ExtractExcelService
......@@ -10,30 +14,36 @@ namespace Performance.Services.ExtractExcelService
public class ExtractJobService : IAutoInjection
{
private readonly ILogger logger;
private readonly IHostingEnvironment env;
private readonly AllotService allotService;
private readonly ConfigService configService;
private readonly DictionaryService dictionaryService;
private readonly QueryService queryService;
private readonly ExtractService extractService;
private readonly PerforUserRepository userRepository;
private readonly PerforHospitalRepository hospitalRepository;
private readonly PerforPerallotRepository perallotRepository;
public ExtractJobService(
ILogger<ExtractJobService> logger,
IHostingEnvironment env,
AllotService allotService,
ConfigService configService,
DictionaryService dictionaryService,
QueryService queryService,
ExtractService extractService,
PerforUserRepository userRepository,
PerforHospitalRepository hospitalRepository,
PerforPerallotRepository perallotRepository
)
{
this.logger = logger;
this.env = env;
this.allotService = allotService;
this.configService = configService;
this.dictionaryService = dictionaryService;
this.queryService = queryService;
this.extractService = extractService;
this.userRepository = userRepository;
this.hospitalRepository = hospitalRepository;
this.perallotRepository = perallotRepository;
......@@ -41,7 +51,7 @@ PerforPerallotRepository perallotRepository
public void Execute()
{
logger.LogInformation("Initial ExtractJobService");
logger.LogInformation($"Initial ExtractJobService start at {DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")};");
var hospitals = hospitalRepository.GetEntities(w => w.IsOpenTimedTasks == 1);
if (hospitals == null || !hospitals.Any()) return;
......@@ -79,6 +89,85 @@ public void Execute()
logger.LogError(ex.ToString());
}
}
logger.LogInformation($"Initial ExtractJobService end at {DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")};");
}
public void ExportFile()
{
logger.LogInformation($"Initial Extract ImportFile Generate start at {DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")};");
var hospitals = hospitalRepository.GetEntities(w => w.IsOpenTimedTasks == 1);
if (hospitals == null || !hospitals.Any()) return;
var userId = userRepository.GetEntity(t => t.Login.ToLower() == "admin" && t.States == 1 && t.IsDelete == 1)?.ID ?? 1;
var date = DateTime.Now;
var allots = perallotRepository.GetEntities(t => hospitals.Select(w => w.ID).Contains(t.HospitalId));
foreach (var hospital in hospitals)
{
try
{
var allot = allots?.FirstOrDefault(t => t.HospitalId == hospital.ID && t.Year == date.Year && t.Month == date.Month);
if (allot == null)
{
allot = allotService.InsertAllot(new AllotRequest
{
HospitalId = hospital.ID,
Year = date.Year,
Month = date.Month
}, userId);
configService.Copy(allot);
}
if (allot == null || allot.ID == 0) continue;
var dict = new Dictionary<ExDataDict, object>();
var isSingle = hospital.IsSingleProject == 1;
var prevAllot = allots?.Where(t => t.HospitalId == hospital.ID && new int[] { 6, 8 }.Contains(t.States)).OrderByDescending(t => t.Year).ThenByDescending(t => t.Month).First();
string filePath = prevAllot?.Path ?? "";
string extractFilePath = extractService.Main(allot.ID, allot.HospitalId, "", "User" + userId, filePath, isSingle);
if (string.IsNullOrEmpty(extractFilePath) || !FileHelper.IsExistFile(extractFilePath)) return;
ImportFile(allot, filePath);
allotService.Generate(allot);
}
catch (Exception ex)
{
logger.LogError(ex.ToString());
}
}
logger.LogInformation($"Initial Extract ImportFile Generate end at {DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")};");
}
private bool ImportFile(per_allot allot, string filePath)
{
var name = FileHelper.GetFileNameNoExtension(filePath) + DateTime.Now.ToString("yyyyMMddHHmmssfff");
var ext = FileHelper.GetExtension(filePath);
var dpath = Path.Combine(env.ContentRootPath, "Files", $"{allot.HospitalId}", $"{allot.Year}{allot.Month.ToString().PadLeft(2, '0')}");
FileHelper.CreateDirectory(dpath);
var path = Path.Combine(dpath, $"{name}{ext}");
using (var stream = new FileStream(filePath, FileMode.OpenOrCreate))
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
if (!FileHelper.CreateFile(path, bytes)) return false;
allot.Path = path;
allot.States = (int)AllotStates.FileUploaded;
allot.Remark = EnumHelper.GetDescription(AllotStates.FileUploaded);
allot.UploadDate = DateTime.Now;
allot.Generate = (int)AllotGenerate.Init;
if (!allotService.Update(allot)) return false;
}
configService.Clear(allot.ID);
return true;
}
}
}
......@@ -2,6 +2,7 @@
using NPOI.SS.UserModel;
using Performance.DtoModels;
using Performance.EntityModels;
using Performance.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
......@@ -24,7 +25,7 @@ public void WriteCollectData(ISheet sheet, PerSheetPoint point, SheetType sheetT
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())
if (data != null && data is List<per_dept_dic> departments && departments.Any())
{
int dataFirstRowNum = point.DataFirstRowNum.Value;
......@@ -36,8 +37,12 @@ public void WriteSheetData(ISheet sheet, PerSheetPoint point, SheetType sheetTyp
var tuples = GetAccountingUnitDataNonexistent(sheet, point, accountingUnits);
accountingUnits = accountingUnits.Where(t => !t.AccountingUnit.Contains("非核算"))?.ToList();
if (accountingUnits == null || !accountingUnits.Any()) return;
logger.LogInformation("4.1所有科室: " + JsonHelper.Serialize(accountingUnits));
WriteAccountingUnitDataNonexistent(sheet, point, style, accountingUnits, tuples);
var accountBasic = new List<Account>();
......
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