报表抽取

parent ebbfab54
......@@ -154,6 +154,9 @@
<member name="P:Performance.EntityModels.PerformanceDbContext.rep_selection">
<summary> 条件表 </summary>
</member>
<member name="P:Performance.EntityModels.PerformanceDbContext.rep_importconfig">
<summary> 导入报表SQL配置 </summary>
</member>
<member name="P:Performance.EntityModels.PerformanceDbContext.res_account">
<summary> 科室核算结果 </summary>
</member>
......@@ -2545,6 +2548,51 @@
</summary>
</member>
<member name="T:Performance.EntityModels.rep_importconfig">
<summary>
导入报表SQL配置
</summary>
</member>
<member name="P:Performance.EntityModels.rep_importconfig.ID">
<summary>
</summary>
</member>
<member name="P:Performance.EntityModels.rep_importconfig.TableName">
<summary>
</summary>
</member>
<member name="P:Performance.EntityModels.rep_importconfig.ImportScript">
<summary>
</summary>
</member>
<member name="P:Performance.EntityModels.rep_importconfig.DeleteScript">
<summary>
</summary>
</member>
<member name="P:Performance.EntityModels.rep_importconfig.ConfigId">
<summary>
数据库地址,仅在HIS抽取时使用
</summary>
</member>
<member name="P:Performance.EntityModels.rep_importconfig.ScriptType">
<summary>
脚本类型 1 HIS抽取 2 EXCEL抽取
</summary>
</member>
<member name="P:Performance.EntityModels.rep_importconfig.TimeRange">
<summary>
时间范围 1 当前 2 同期 3 上期
</summary>
</member>
<member name="P:Performance.EntityModels.rep_importconfig.IsEnable">
<summary>
是否有效 1 有效 0 无效
</summary>
</member>
<member name="T:Performance.EntityModels.rep_report">
<summary>
报表配置表
......
......@@ -112,6 +112,8 @@ public PerformanceDbContext(DbContextOptions<PerformanceDbContext> options)
public virtual DbSet<rep_group_selection> rep_group_selection { get; set; }
/// <summary> 条件表 </summary>
public virtual DbSet<rep_selection> rep_selection { get; set; }
/// <summary> 导入报表SQL配置 </summary>
public virtual DbSet<rep_importconfig> rep_importconfig { get; set; }
/// <summary> 科室核算结果 </summary>
public virtual DbSet<res_account> res_account { get; set; }
/// <summary> 医生科室核算结果 </summary>
......
//-----------------------------------------------------------------------
// <copyright file=" rep_importconfig.cs">
// * FileName: 导入报表SQL配置.cs
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Performance.EntityModels
{
/// <summary>
/// 导入报表SQL配置
/// </summary>
[Table("rep_importconfig")]
public class rep_importconfig
{
/// <summary>
///
/// </summary>
[Key]
public int ID { get; set; }
/// <summary>
///
/// </summary>
public string TableName { get; set; }
/// <summary>
///
/// </summary>
public string ImportScript { get; set; }
/// <summary>
///
/// </summary>
public string DeleteScript { get; set; }
/// <summary>
/// 数据库地址,仅在HIS抽取时使用
/// </summary>
public Nullable<int> ConfigId { get; set; }
/// <summary>
/// 脚本类型 1 HIS抽取 2 EXCEL抽取
/// </summary>
public int ScriptType { get; set; }
/// <summary>
/// 时间范围 1 当前 2 同期 3 上期
/// </summary>
public int TimeRange { get; set; }
/// <summary>
/// 是否有效 1 有效 0 无效
/// </summary>
public int IsEnable { get; set; }
}
}
......@@ -12,7 +12,7 @@ namespace Performance.Repository
public abstract class BaseRepository<TEntity>
where TEntity : class, new()
{
private DbContext context;
protected DbContext context;
public BaseRepository(DbContext context)
{
......
......@@ -4,8 +4,14 @@
// * history : Created by T4 2019-03-06 16:43:31
// </copyright>
//-----------------------------------------------------------------------
using Dapper;
using Microsoft.EntityFrameworkCore;
using Performance.EntityModels;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
namespace Performance.Repository
{
......@@ -22,33 +28,64 @@ public bool UpdateAllotStates(int allotId, int states, string remark)
return Update(allot);
}
public int ImportData(int allotId)
/// <summary>
/// 只支持EXCEL抽取报表数据
/// </summary>
/// <param name="import"></param>
/// <param name="pairs"></param>
/// <returns></returns>
public bool ImportData(rep_importconfig import, Dictionary<string, object> pairs)
{
string sql = @"
delete from report_allot_summary where allotid=@allotId;
insert into report_allot_summary(allotid,year,month,hospitalid,realgivefee)
select allotid,year,month,hospitalid,realgivefee from view_report_allot_summary where allotid=@allotId;
delete from report_original_income where allotid=@allotId;
insert into report_original_income(allotid,year,month,hospitalid,sourcetype,department,typename,cellvalue)
select distinct allotid,year,month,hospitalid,sourcetype,department,typename,cellvalue from view_report_original_income where allotid=@allotId;";
return Execute(sql, new { allotId });
using (var connection = context.Database.GetDbConnection())
{
var data = connection.Query(import.ImportScript, new DynamicParameters(pairs), commandTimeout: 60 * 60);
ImportData(import, pairs, data);
}
return true;
}
/// <summary>
///
/// 指定数据源插入MYSQL
/// </summary>
/// <param name="allotId"></param>
/// <param name="import"></param>
/// <param name="pairs"></param>
/// <param name="data"></param>
/// <returns></returns>
public int SupplyData(int allotId)
public bool ImportData(rep_importconfig import, Dictionary<string, object> pairs, IEnumerable<dynamic> data)
{
string sql = @"
insert into cof_drugtype(charge,allotid) select distinct id.typename charge,
@allotId allotid from im_data id
inner join per_sheet ps on id.sheetid = ps.id
where id.allotid = @allotId and ps.sheettype = 3 and ifnull(id.typename, '') != ''
and id.typename not in (select charge from cof_drugtype where allotid = @allotId);";
return Execute(sql, new { allotId });
if (data != null && data.Any())
{
using (var connection = context.Database.GetDbConnection())
{
if (connection.State != ConnectionState.Open) connection.Open();
using (var transaction = connection.BeginTransaction())
{
try
{
connection.Execute(import.DeleteScript, new DynamicParameters(pairs), commandTimeout: 60 * 60, transaction: transaction);
List<string> columns = new List<string>();
foreach (KeyValuePair<string, object> col in data.First())
{
columns.Add(col.Key);
}
var c1 = string.Join(",", columns.Select(w => $"`{w}`"));
var c2 = string.Join(",", columns.Select(w => $"@{w}"));
string insert = $"insert into {import.TableName}({c1}) values({c2})";
connection.Execute(insert, data, commandTimeout: 60 * 60, transaction: transaction);
transaction.Commit();
}
catch (Exception ex)
{
transaction.Rollback();
throw ex;
}
}
}
}
return true;
}
}
}
//-----------------------------------------------------------------------
// <copyright file=" rep_importconfig.cs">
// * FileName: rep_importconfig.cs
// </copyright>
//-----------------------------------------------------------------------
using System;
using Performance.EntityModels;
namespace Performance.Repository
{
/// <summary>
/// rep_importconfig Repository
/// </summary>
public partial class PerforRepimportconfigRepository : PerforRepository<rep_importconfig>
{
public PerforRepimportconfigRepository(PerformanceDbContext context) : base(context)
{
}
}
}
......@@ -216,7 +216,7 @@ public void UpdateAllotStates(int allotId, int states, string remark)
{
_allotRepository.UpdateAllotStates(allotId, states, remark);
}
/// <summary>
/// 生成绩效
/// </summary>
......@@ -305,7 +305,7 @@ public void Generate(per_allot allot, string mail)
UpdateAllotStates(allot.ID, (int)AllotStates.GenerateSucceed, EnumHelper.GetDescription(AllotStates.GenerateSucceed));
logManageService.WriteMsg("正在生成报表数据", "正在生成报表数据", 1, allot.ID, "ReceiveMessage", true);
var res = reportService.ImportData(allot.ID);
var res = reportService.ImportData(allot);
logManageService.WriteMsg("正在生成报表数据", $"报表数据生成完成;受影响:{res}行", 1, allot.ID, "ReceiveMessage", true);
//发送邮件
......
using Microsoft.AspNetCore.Hosting;
using Dapper;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using NPOI.HSSF.UserModel;
......@@ -12,6 +13,7 @@
using Performance.Repository;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
......@@ -37,6 +39,7 @@ public class ExtractService : IAutoInjection
private readonly PerforExtractRepository perforExtractRepository;
private readonly PerforPerfirstRepository perforPerfirstRepository;
private readonly PerforPerallotRepository perforPerallotRepository;
private readonly PerforRepimportconfigRepository repimportconfigRepository;
private readonly PerforHospitalconfigRepository perforHospitalconfigRepository;
public ExtractService(ILogger<ExtractService> logger,
......@@ -52,6 +55,7 @@ public class ExtractService : IAutoInjection
PerforExtractRepository perforExtractRepository,
PerforPerfirstRepository perforPerfirstRepository,
PerforPerallotRepository perforPerallotRepository,
PerforRepimportconfigRepository repimportconfigRepository,
PerforHospitalconfigRepository perforHospitalconfigRepository)
{
this.logger = logger;
......@@ -67,6 +71,7 @@ public class ExtractService : IAutoInjection
this.perforExtractRepository = perforExtractRepository;
this.perforPerfirstRepository = perforPerfirstRepository;
this.perforPerallotRepository = perforPerallotRepository;
this.repimportconfigRepository = repimportconfigRepository;
this.perforHospitalconfigRepository = perforHospitalconfigRepository;
}
......@@ -160,11 +165,11 @@ public string ExtractData(int allotId, string mail, sys_hospital hospital, strin
if (WriteExcel(path, originalPath, sheetList, hospitalConfig, hospital.ID, allotList.First(t => t.ID == allotId), out filepath))
{
logger.LogInformation($"提取绩效数据 基础数据提取完成,文件保存成功{filepath}", "");
//var allot = allotList.First(t => t.ID == allotId);
var allot = allotList.First(t => t.ID == allotId);
//allot.ExtractPath = filepath;
//if (!string.IsNullOrEmpty(filepath))
// perforPerallotRepository.Update(allot);
ImportData(allot, configList);
SendEmail(mail, filepath, $"{hospital.HosName}HIS数据提取成功", $"{hospital.HosName}{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}成功提取。");
}
}
......@@ -191,6 +196,54 @@ public string ExtractData(int allotId, string mail, sys_hospital hospital, strin
}
/// <summary>
/// 从HIS抽取报表数据
/// </summary>
/// <param name="allot"></param>
/// <param name="configs"></param>
public void ImportData(per_allot allot, List<sys_hospitalconfig> configs)
{
Dictionary<string, object> pairs = new Dictionary<string, object>
{
{ "@allotid", allot.ID },
{ "@hospitalid", allot.HospitalId },
};
var imports = repimportconfigRepository.GetEntities(w => w.ScriptType == 1);
foreach (var import in imports)
{
var conf = configs.FirstOrDefault(w => w.HospitalId == allot.HospitalId && w.Id == import.ConfigId);
if (conf != null)
{
if (import.TimeRange == 1)
{
pairs.Add("@year", allot.Year);
pairs.Add("@month", allot.Month);
}
else if (import.TimeRange == 2)
{
pairs.Add("@year", allot.Year - 1);
pairs.Add("@month", allot.Month);
}
else if (import.TimeRange == 3)
{
pairs.Add("@year", allot.Year);
pairs.Add("@month", allot.Month - 1);
}
try
{
DatabaseType type = (DatabaseType)conf.DataBaseType;
var connection = ConnectionBuilder.Create(type, conf.DbSource, conf.DbName, conf.DbUser, conf.DbPassword);
var data = connection.Query(import.ImportScript, new DynamicParameters(pairs), commandTimeout: 60 * 60);
perforPerallotRepository.ImportData(import, pairs, data);
}
catch (Exception ex)
{
logger.LogError(ex.ToString());
}
}
}
}
/// <summary>
/// 发送邮件
/// </summary>
/// <param name="path"></param>
......
using Performance.DtoModels;
using Microsoft.Extensions.Logging;
using Performance.DtoModels;
using Performance.EntityModels;
using Performance.Repository;
using System;
......@@ -11,26 +12,30 @@ namespace Performance.Services
{
public class ReportService : IAutoInjection
{
private readonly ILogger<ReportService> logger;
private PerforReportRepository perforReportRepository;
private PerforPerallotRepository perforPerallotRepository;
private PerforResbaiscnormRepository perforResbaiscnormRepository;
private PerforHospersonfeeRepository perforHospersonfeeRepository;
private PerforResaccountRepository perforResaccountRepository;
//private PerforResaccountnurseRepository perforResaccountnurseRepository;
private PerforRepimportconfigRepository repimportconfigRepository;
public ReportService(PerforReportRepository perforReportRepository,
public ReportService(
ILogger<ReportService> logger,
PerforReportRepository perforReportRepository,
PerforPerallotRepository perforPerallotRepository,
PerforResbaiscnormRepository perforResbaiscnormRepository,
PerforHospersonfeeRepository perforHospersonfeeRepository,
//PerforResaccountdoctorRepository perforResaccountdoctorRepository,
PerforRepimportconfigRepository repimportconfigRepository,
PerforResaccountRepository perforResaccountRepository)
{
this.logger = logger;
this.perforReportRepository = perforReportRepository;
this.perforPerallotRepository = perforPerallotRepository;
this.perforResbaiscnormRepository = perforResbaiscnormRepository;
this.perforHospersonfeeRepository = perforHospersonfeeRepository;
this.perforResaccountRepository = perforResaccountRepository;
//this.perforResaccountnurseRepository = perforResaccountnurseRepository;
this.repimportconfigRepository = repimportconfigRepository;
}
/// <summary>
......@@ -224,14 +229,30 @@ public List<PerReport> Income(int hospitalId, int isIndex)
return perforReportRepository.Income(hospitalId, date);
}
internal int ImportData(int allotId)
/// <summary>
/// 只支持EXCEL抽取报表数据
/// </summary>
/// <param name="allot"></param>
/// <returns></returns>
internal int ImportData(per_allot allot)
{
try
Dictionary<string, object> pairs = new Dictionary<string, object>
{
{ "@allotid", allot.ID },
{ "@hospitalid", allot.HospitalId },
};
var imports = repimportconfigRepository.GetEntities(w => w.ScriptType == 2);
foreach (var item in imports)
{
var flag = perforPerallotRepository.SupplyData(allotId);
return perforPerallotRepository.ImportData(allotId);
try
{
var flag = perforPerallotRepository.ImportData(item, pairs);
}
catch (Exception ex)
{
logger.LogError(ex.ToString());
}
}
catch { }
return 0;
}
......
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