Commit 0de87fec by lcx

Merge branch 'feature/抽取配置优化' into develop

# Conflicts:
#	performance/Performance.Api/Controllers/ModExtractController.cs
parents f78291b1 74668ca7
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles; using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Performance.DtoModels; using Performance.DtoModels;
using Performance.EntityModels;
using Performance.Infrastructure; using Performance.Infrastructure;
using Performance.Services; using Performance.Services;
using Performance.Services.ExtractExcelService;
using Performance.Services.Queues; using Performance.Services.Queues;
using System; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Threading.Tasks;
namespace Performance.Api.Controllers namespace Performance.Api.Controllers
{ {
...@@ -23,6 +23,7 @@ public class ModExtractController : Controller ...@@ -23,6 +23,7 @@ public class ModExtractController : Controller
private readonly IServiceScopeFactory _serviceScopeFactory; private readonly IServiceScopeFactory _serviceScopeFactory;
//private readonly IBackgroundTaskQueue _backgroundTaskQueue; //private readonly IBackgroundTaskQueue _backgroundTaskQueue;
private readonly IHubNotificationQueue _notificationQueue; private readonly IHubNotificationQueue _notificationQueue;
private readonly ExtractPreConfigService _preConfigService;
public ModExtractController( public ModExtractController(
ClaimService claim, ClaimService claim,
...@@ -31,7 +32,9 @@ public class ModExtractController : Controller ...@@ -31,7 +32,9 @@ public class ModExtractController : Controller
CustomExtractService extractService, CustomExtractService extractService,
IServiceScopeFactory serviceScopeFactory, IServiceScopeFactory serviceScopeFactory,
//IBackgroundTaskQueue backgroundTaskQueue, //IBackgroundTaskQueue backgroundTaskQueue,
IHubNotificationQueue notificationQueue) IHubNotificationQueue notificationQueue,
ExtractPreConfigService preConfigService
)
{ {
_claim = claim; _claim = claim;
_allotService = allotService; _allotService = allotService;
...@@ -40,6 +43,7 @@ public class ModExtractController : Controller ...@@ -40,6 +43,7 @@ public class ModExtractController : Controller
_serviceScopeFactory = serviceScopeFactory; _serviceScopeFactory = serviceScopeFactory;
//_backgroundTaskQueue = backgroundTaskQueue; //_backgroundTaskQueue = backgroundTaskQueue;
_notificationQueue = notificationQueue; _notificationQueue = notificationQueue;
_preConfigService = preConfigService;
} }
[HttpPost("custom/{allotId}")] [HttpPost("custom/{allotId}")]
...@@ -105,5 +109,195 @@ public IActionResult DownFile(int allotId) ...@@ -105,5 +109,195 @@ public IActionResult DownFile(int allotId)
var memi = provider.Mappings[fileExt]; var memi = provider.Mappings[fileExt];
return File(memoryStream, memi, Path.GetFileName(allot.CustomExtractPath)); return File(memoryStream, memi, Path.GetFileName(allot.CustomExtractPath));
} }
#region 医院数据库配置
/// <summary>
/// 医院数据库配置列表
/// </summary>
/// <param name="hospitalId"></param>
/// <returns></returns>
[HttpGet("hospital/config/{hospitalId}")]
public ApiResponse<List<sys_hospitalconfig>> GetHospitalConfig([FromRoute] int hospitalId)
{
if (hospitalId == 0) return new ApiResponse<List<sys_hospitalconfig>>(ResponseType.ParameterError, "参数错误");
var list = _preConfigService.GetHospitalConfig(hospitalId);
return new ApiResponse<List<sys_hospitalconfig>>(ResponseType.OK, list);
}
/// <summary>
/// 创建医院数据库配置
/// </summary>
/// <param name="hospitalconfig"></param>
/// <returns></returns>
[HttpPost("hospital/config/create")]
public ApiResponse CreateHospitalConfig([FromBody] sys_hospitalconfig hospitalconfig)
{
if (hospitalconfig == null) return new ApiResponse(ResponseType.ParameterError, "参数错误");
var flag = _preConfigService.CreateHospitalConfig(hospitalconfig);
return flag
? new ApiResponse(ResponseType.OK, "添加成功")
: new ApiResponse(ResponseType.Fail, "添加失败");
}
/// <summary>
/// 修改医院数据库配置
/// </summary>
/// <param name="hospitalconfig"></param>
/// <returns></returns>
[HttpPost("hospital/config/update")]
public ApiResponse UpdateHospitalConfig([FromBody] sys_hospitalconfig hospitalconfig)
{
if (hospitalconfig == null) return new ApiResponse(ResponseType.ParameterError, "参数错误");
var flag = _preConfigService.UpdateHospitalConfig(hospitalconfig);
return flag
? new ApiResponse(ResponseType.OK, "添加成功")
: new ApiResponse(ResponseType.Fail, "添加失败");
}
/// <summary>
/// 删除医院数据库配置
/// </summary>
/// <param name="hospitalconfigId"></param>
/// <returns></returns>
[HttpPost("hospital/config/{hospitalconfigId}")]
public ApiResponse DeleteHospitalConfig([FromRoute] int hospitalconfigId)
{
if (hospitalconfigId == 0) return new ApiResponse(ResponseType.ParameterError, "参数错误");
var flag = _preConfigService.DeleteHospitalConfig(hospitalconfigId);
return flag
? new ApiResponse(ResponseType.OK, "添加成功")
: new ApiResponse(ResponseType.Fail, "添加失败");
}
/// <summary>
/// 测试连接
/// </summary>
/// <param name="hospitalconfigId"></param>
/// <returns></returns>
[HttpPost("hospital/connection/{hospitalconfigId}")]
public ApiResponse TestConnectionCleared([FromRoute] int hospitalconfigId)
{
if (hospitalconfigId == 0) return new ApiResponse(ResponseType.ParameterError, "参数错误");
var flag = _preConfigService.TestConnectionCleared(hospitalconfigId);
return flag
? new ApiResponse(ResponseType.OK, "连接成功")
: new ApiResponse(ResponseType.Fail, "连接失败");
}
#endregion
#region 提取script配置
/// <summary>
/// 数据提取信息列表
/// </summary>
/// <param name="hospitalId"></param>
/// <returns></returns>
[HttpGet("type/{hospitalId}")]
public ApiResponse GetExtractTypeAndScript([FromRoute] int hospitalId)
{
if (hospitalId == 0) return new ApiResponse(ResponseType.ParameterError, "参数错误");
var list = _preConfigService.GetExtractTypeAndScript(hospitalId);
return new ApiResponse(ResponseType.OK, list);
}
/// <summary>
/// 数据提取详情
/// </summary>
/// <param name="typeId"></param>
/// <param name="scriptId"></param>
/// <returns></returns>
[HttpGet("type/{typeId}/{scriptId}")]
public ApiResponse GetExtractTypeAndScriptById([FromRoute] int typeId, int scriptId)
{
if (typeId == 0) return new ApiResponse(ResponseType.ParameterError, "参数错误");
var data = _preConfigService.GetExtractTypeAndScriptById(typeId, scriptId);
return new ApiResponse(ResponseType.OK, data);
}
/// <summary>
/// 删除提取Sql
/// </summary>
/// <param name="typeId"></param>
/// <param name="scriptId"></param>
/// <returns></returns>
[HttpPost("type/{typeId}/{scriptId}")]
public ApiResponse DeleteExtractTypeAndScript([FromRoute] int typeId, int scriptId)
{
if (typeId == 0) return new ApiResponse(ResponseType.ParameterError, "参数错误");
var flag = _preConfigService.DeleteExtractTypeAndScript(typeId, scriptId);
return flag
? new ApiResponse(ResponseType.OK, "删除成功")
: new ApiResponse(ResponseType.Fail, "删除失败");
}
/// <summary>
/// 保存数据
/// </summary>
/// <param name="hospitalId"></param>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost("type/{hospitalId}/save")]
public ApiResponse EditExtractTypeAndScript([FromRoute] int hospitalId, [FromBody] ExtractConfigResponse request)
{
var flag = _preConfigService.EditExtractTypeAndScript(hospitalId, request);
return flag
? new ApiResponse(ResponseType.OK, "操作成功")
: new ApiResponse(ResponseType.Fail, "操作失败");
}
/// <summary>
/// 执行Sql
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost("type/{typeId}/execute")]
public ApiResponse ExecsqlAndGetResult([FromBody] ConsumeTimeRequest request)
{
if (request == null) return new ApiResponse(ResponseType.ParameterError, "参数错误");
var flag = _preConfigService.ExecsqlAndGetResult(request);
return new ApiResponse(ResponseType.OK, flag);
}
#endregion
#region 字典
/// <summary>
/// 数据库类型
/// </summary>
/// <returns></returns>
[HttpGet("database")]
public ApiResponse<List<TitleValue<int>>> GetDatatypes()
{
var list = ExtractPreConfigService.GetDatatypes();
return new ApiResponse<List<TitleValue<int>>>(ResponseType.OK, list);
}
/// <summary>
/// 来源类型
/// </summary>
/// <returns></returns>
[HttpGet("sheettype")]
public ApiResponse<List<TitleValue<int>>> GetSheettypes()
{
var list = ExtractPreConfigService.GetSheettypes();
return new ApiResponse<List<TitleValue<int>>>(ResponseType.OK, list);
}
/// <summary>
/// 医院数据库连接配置
/// </summary>
/// <param name="hospitalId"></param>
/// <returns></returns>
[HttpGet("config/{hospitalId}")]
public ApiResponse<List<TitleValue<int>>> GetConfigs([FromRoute] int hospitalId)
{
var list = _preConfigService.GetConfigs(hospitalId);
return new ApiResponse<List<TitleValue<int>>>(ResponseType.OK, list);
}
#endregion
} }
} }
\ No newline at end of file
...@@ -1441,6 +1441,98 @@ ...@@ -1441,6 +1441,98 @@
</summary> </summary>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Performance.Api.Controllers.ModExtractController.GetHospitalConfig(System.Int32)">
<summary>
医院数据库配置列表
</summary>
<param name="hospitalId"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ModExtractController.CreateHospitalConfig(Performance.EntityModels.sys_hospitalconfig)">
<summary>
创建医院数据库配置
</summary>
<param name="hospitalconfig"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ModExtractController.UpdateHospitalConfig(Performance.EntityModels.sys_hospitalconfig)">
<summary>
修改医院数据库配置
</summary>
<param name="hospitalconfig"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ModExtractController.DeleteHospitalConfig(System.Int32)">
<summary>
删除医院数据库配置
</summary>
<param name="hospitalconfigId"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ModExtractController.TestConnectionCleared(System.Int32)">
<summary>
测试连接
</summary>
<param name="hospitalconfigId"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ModExtractController.GetExtractTypeAndScript(System.Int32)">
<summary>
数据提取信息列表
</summary>
<param name="hospitalId"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ModExtractController.GetExtractTypeAndScriptById(System.Int32,System.Int32)">
<summary>
数据提取详情
</summary>
<param name="typeId"></param>
<param name="scriptId"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ModExtractController.DeleteExtractTypeAndScript(System.Int32,System.Int32)">
<summary>
删除提取Sql
</summary>
<param name="typeId"></param>
<param name="scriptId"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ModExtractController.EditExtractTypeAndScript(System.Int32,Performance.DtoModels.ExtractConfigResponse)">
<summary>
保存数据
</summary>
<param name="hospitalId"></param>
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ModExtractController.ExecsqlAndGetResult(Performance.DtoModels.ConsumeTimeRequest)">
<summary>
执行Sql
</summary>
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ModExtractController.GetDatatypes">
<summary>
数据库类型
</summary>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ModExtractController.GetSheettypes">
<summary>
来源类型
</summary>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.ModExtractController.GetConfigs(System.Int32)">
<summary>
医院数据库连接配置
</summary>
<param name="hospitalId"></param>
<returns></returns>
</member>
<member name="T:Performance.Api.Controllers.OriginalController"> <member name="T:Performance.Api.Controllers.OriginalController">
<summary> <summary>
原始数据修改 原始数据修改
......
...@@ -3644,6 +3644,11 @@ ...@@ -3644,6 +3644,11 @@
</summary> </summary>
</member> </member>
<member name="P:Performance.EntityModels.ex_script.Name">
<summary>
</summary>
</member>
<member name="P:Performance.EntityModels.ex_script.ExecScript"> <member name="P:Performance.EntityModels.ex_script.ExecScript">
<summary> <summary>
执行sql 执行sql
...@@ -3664,6 +3669,21 @@ ...@@ -3664,6 +3669,21 @@
是否可用 1 可用 2 不可用 是否可用 1 可用 2 不可用
</summary> </summary>
</member> </member>
<member name="P:Performance.EntityModels.ex_script.IsExecSuccess">
<summary>
是否执行通过 0 未执行 1 通过 2 失败
</summary>
</member>
<member name="P:Performance.EntityModels.ex_script.Description">
<summary>
执行错误信息
</summary>
</member>
<member name="P:Performance.EntityModels.ex_script.TimeConsuming">
<summary>
语句执行完成所需时间
</summary>
</member>
<member name="T:Performance.EntityModels.ex_special"> <member name="T:Performance.EntityModels.ex_special">
<summary> <summary>
...@@ -8330,14 +8350,14 @@ ...@@ -8330,14 +8350,14 @@
</summary> </summary>
</member> </member>
<member name="P:Performance.EntityModels.sys_hospitalconfig.Type"> <member name="P:Performance.EntityModels.sys_hospitalconfig.DataBaseType">
<summary> <summary>
1 标准库 2 绩效库 1、Sql Server 2、Orcale
</summary> </summary>
</member> </member>
<member name="P:Performance.EntityModels.sys_hospitalconfig.DataBaseType"> <member name="P:Performance.EntityModels.sys_hospitalconfig.IsConnectioned">
<summary> <summary>
1、Sql Server 2、Orcale
</summary> </summary>
</member> </member>
<member name="T:Performance.EntityModels.sys_menu"> <member name="T:Performance.EntityModels.sys_menu">
......
...@@ -2,10 +2,7 @@ ...@@ -2,10 +2,7 @@
using Performance.DtoModels.Request; using Performance.DtoModels.Request;
using Performance.EntityModels; using Performance.EntityModels;
using Performance.Infrastructure; using Performance.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
namespace Performance.DtoModels.AutoMapper namespace Performance.DtoModels.AutoMapper
{ {
...@@ -255,6 +252,23 @@ public AutoMapperConfigs() ...@@ -255,6 +252,23 @@ public AutoMapperConfigs()
CreateMap<ex_result, ex_result_gather>() CreateMap<ex_result, ex_result_gather>()
.ReverseMap(); .ReverseMap();
CreateMap<ex_type, ExtractConfigResponse>()
.ForMember(dest => dest.TypeId, opt => opt.MapFrom(src => src.Id))
.ForMember(dest => dest.Value, opt => opt.MapFrom(src => src.Id))
.ForMember(dest => dest.Title, opt => opt.MapFrom(src => src.EName));
CreateMap<ExtractConfigResponse, ex_type>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.TypeId));
CreateMap<ex_script, ExtractConfigResponse>()
.ForMember(dest => dest.ExScriptId, opt => opt.MapFrom(src => src.Id))
.ForMember(dest => dest.Value, opt => opt.MapFrom(src => src.Id))
.ForMember(dest => dest.Title, opt => opt.MapFrom(src => src.Name));
CreateMap<ExtractConfigResponse, ex_script>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.ExScriptId));
CreateMap<cof_workitem, WorkItemRequest>() CreateMap<cof_workitem, WorkItemRequest>()
.ReverseMap(); .ReverseMap();
} }
......
using System;
namespace Performance.DtoModels
{
public class ConsumeTimeRequest
{
public int Year { get; set; } = DateTime.Now.Year;
public int Month { get; set; } = DateTime.Now.Month;
public int ExScriptId { get; set; }
public int ConfigId { get; set; }
public string ExecScript { get; set; }
}
}
using System.Collections.Generic;
namespace Performance.DtoModels
{
public class ExtractConfigResponse
{
#region Public
public string Title { get; set; }
public int Value { get; set; }
#endregion
#region Type
public int TypeId { get; set; }
public string EName { get; set; }
public int Source { get; set; }
public string Description { get; set; }
public decimal TimeConsuming { get; set; }
#endregion
#region Script
public int ExScriptId { get; set; }
public string Name { get; set; }
public string ExecScript { get; set; }
public int ConfigId { get; set; }
public string ConfigName { get; set; }
public int IsExecSuccess { get; set; }
public int IsEnable { get; set; }
#endregion
public List<ExtractConfigResponse> Children { get; set; } = new List<ExtractConfigResponse>();
}
}
...@@ -21,6 +21,11 @@ public class ex_script ...@@ -21,6 +21,11 @@ public class ex_script
public int Id { get; set; } public int Id { get; set; }
/// <summary> /// <summary>
///
/// </summary>
public string Name { get; set; }
/// <summary>
/// 执行sql /// 执行sql
/// </summary> /// </summary>
public string ExecScript { get; set; } public string ExecScript { get; set; }
...@@ -39,5 +44,20 @@ public class ex_script ...@@ -39,5 +44,20 @@ public class ex_script
/// 是否可用 1 可用 2 不可用 /// 是否可用 1 可用 2 不可用
/// </summary> /// </summary>
public int IsEnable { get; set; } public int IsEnable { get; set; }
/// <summary>
/// 是否执行通过 0 未执行 1 通过 2 失败
/// </summary>
public int IsExecSuccess { get; set; }
/// <summary>
/// 执行错误信息
/// </summary>
public string Description { get; set; }
/// <summary>
/// 语句执行完成所需时间
/// </summary>
public decimal TimeConsuming { get; set; } = 0;
} }
} }
...@@ -24,7 +24,7 @@ public class sys_hospitalconfig ...@@ -24,7 +24,7 @@ public class sys_hospitalconfig
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public Nullable<int> HospitalId { get; set; } public int HospitalId { get; set; }
/// <summary> /// <summary>
/// ///
...@@ -52,13 +52,13 @@ public class sys_hospitalconfig ...@@ -52,13 +52,13 @@ public class sys_hospitalconfig
public string DbPassword { get; set; } public string DbPassword { get; set; }
/// <summary> /// <summary>
/// 1 标准库 2 绩效库 /// 1、Sql Server 2、Orcale
/// </summary> /// </summary>
public Nullable<int> Type { get; set; } public int DataBaseType { get; set; }
/// <summary> /// <summary>
/// 1、Sql Server 2、Orcale ///
/// </summary> /// </summary>
public int DataBaseType { get; set; } public bool IsConnectioned { get; set; }
} }
} }
using Microsoft.EntityFrameworkCore;
using Performance.EntityModels;
using Performance.Infrastructure.Models;
using System.Linq;
namespace Performance.Repository
{
public partial class PerforExtypeRepository
{
public PageList<ex_type> GetPagingData(int hospitalId, int? sheetType, string search, int pageNumber, int pageSize)
{
var query = _context.ex_type.AsNoTracking().Where(w => w.HospitalId == hospitalId);
if (sheetType.HasValue && sheetType.Value > 0)
{
query = query.Where(w => w.Source == sheetType);
}
if (!string.IsNullOrEmpty(search))
{
query = query.Where(w => w.EName.Contains(search));
}
return PageList<ex_type>.Create(query, pageNumber, pageSize);
}
}
}
...@@ -12,8 +12,11 @@ namespace Performance.Repository ...@@ -12,8 +12,11 @@ namespace Performance.Repository
/// </summary> /// </summary>
public partial class PerforExtypeRepository : PerforRepository<ex_type> public partial class PerforExtypeRepository : PerforRepository<ex_type>
{ {
private readonly PerformanceDbContext _context;
public PerforExtypeRepository(PerformanceDbContext context) : base(context) public PerforExtypeRepository(PerformanceDbContext context) : base(context)
{ {
_context = context;
} }
} }
} }
...@@ -78,38 +78,35 @@ public List<ex_module> QueryModule(int hospitalId) ...@@ -78,38 +78,35 @@ public List<ex_module> QueryModule(int hospitalId)
DefaultModules(hospitalId); DefaultModules(hospitalId);
var list = exmoduleRepository.GetEntities(t => t.HospitalId == hospitalId).OrderBy(t => t.ModuleName).ToList(); var list = exmoduleRepository.GetEntities(t => t.HospitalId == hospitalId).OrderBy(t => t.ModuleName).ToList();
list?.ForEach(t => t.ReadOnly = t.SheetType == (int)SheetType.Income ? 0 : 1);
return list; return list;
} }
public void DefaultModules(int hospitalId) public void DefaultModules(int hospitalId)
{ {
var moduleList = new ex_module[] var moduleList = new List<ex_module>
{ {
new ex_module{ ModuleName = "1.0.1 额外收入", SheetType = (int)SheetType.OtherIncome }, new ex_module{ ModuleName = "1.0.1 额外收入", SheetType = (int)SheetType.OtherIncome, ReadOnly = 0 },
new ex_module{ ModuleName = "1.1.1 门诊开单收入", SheetType = (int)SheetType.Income }, new ex_module{ ModuleName = "1.1.1 门诊开单收入", SheetType = (int)SheetType.Income, ReadOnly = 1 },
new ex_module{ ModuleName = "1.1.2 门诊执行收入", SheetType = (int)SheetType.Income }, new ex_module{ ModuleName = "1.1.2 门诊执行收入", SheetType = (int)SheetType.Income, ReadOnly = 1 },
new ex_module{ ModuleName = "1.2.1 住院开单收入", SheetType = (int)SheetType.Income }, new ex_module{ ModuleName = "1.2.1 住院开单收入", SheetType = (int)SheetType.Income, ReadOnly = 1 },
new ex_module{ ModuleName = "1.2.2 住院执行收入", SheetType = (int)SheetType.Income }, new ex_module{ ModuleName = "1.2.2 住院执行收入", SheetType = (int)SheetType.Income, ReadOnly = 1 },
new ex_module{ ModuleName = "2.1 成本支出统计表", SheetType = (int)SheetType.Expend }, new ex_module{ ModuleName = "2.1 成本支出统计表", SheetType = (int)SheetType.Expend, ReadOnly = 0 },
new ex_module{ ModuleName = "3.1 医生组工作量绩效测算表", SheetType = (int)SheetType.Workload }, new ex_module{ ModuleName = "3.1 医生组工作量绩效测算表", SheetType = (int)SheetType.Workload, ReadOnly = 0 },
new ex_module{ ModuleName = "3.2 护理组工作量绩效测算表", SheetType = (int)SheetType.Workload }, new ex_module{ ModuleName = "3.2 护理组工作量绩效测算表", SheetType = (int)SheetType.Workload, ReadOnly = 0 },
}; };
var data = exmoduleRepository.GetEntities(t => t.HospitalId == hospitalId); var data = exmoduleRepository.GetEntities(t => t.HospitalId == hospitalId);
var inexistence = (data == null || !data.Any()) ? moduleList : moduleList.Where(t => !data.Any(w => w.ModuleName.StartsWith(t.ModuleName.Split(' ')[0]))); var inexistence = (data == null || !data.Any())
? moduleList
: moduleList.Where(t => !data.Any(w => w.ModuleName.StartsWith(t.ModuleName.Split(' ')[0])))?.ToList();
if (inexistence != null && inexistence.Any()) if (inexistence != null && inexistence.Any())
{ {
var modules = inexistence.Select(t => new ex_module inexistence.ForEach(t =>
{ {
HospitalId = hospitalId, t.HospitalId = hospitalId;
ModuleName = t.ModuleName,
SheetType = (int)t.SheetType,
ReadOnly = t.SheetType == (int)SheetType.Income ? 0 : 1,
TypeId = null,
}); });
exmoduleRepository.AddRange(modules.ToArray()); exmoduleRepository.AddRange(inexistence.ToArray());
} }
} }
......
using AutoMapper;
using Microsoft.Extensions.Logging;
using Performance.DtoModels;
using Performance.EntityModels;
using Performance.Infrastructure;
using Performance.Infrastructure.Models;
using Performance.Repository;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace Performance.Services.ExtractExcelService
{
public class ExtractPreConfigService : IAutoInjection
{
private readonly ILogger logger;
private readonly IMapper mapper;
private readonly PerforHospitalRepository hospitalRepository;
private readonly PerforHospitalconfigRepository hospitalconfigRepository;
private readonly PerforExtypeRepository extypeRepository;
private readonly PerforExscriptRepository exscriptRepository;
private readonly PerforExmoduleRepository exmoduleRepository;
private readonly PerforExitemRepository exitemRepository;
private readonly PerforExspecialRepository exspecialRepository;
private readonly QueryService queryService;
public ExtractPreConfigService(
ILogger<ExtractPreConfigService> logger,
IMapper mapper,
PerforHospitalRepository hospitalRepository,
PerforHospitalconfigRepository hospitalconfigRepository,
PerforExtypeRepository extypeRepository,
PerforExscriptRepository exscriptRepository,
PerforExmoduleRepository exmoduleRepository,
PerforExitemRepository exitemRepository,
PerforExspecialRepository exspecialRepository,
QueryService queryService)
{
this.logger = logger;
this.mapper = mapper;
this.hospitalRepository = hospitalRepository;
this.hospitalconfigRepository = hospitalconfigRepository;
this.extypeRepository = extypeRepository;
this.exscriptRepository = exscriptRepository;
this.exmoduleRepository = exmoduleRepository;
this.exitemRepository = exitemRepository;
this.exspecialRepository = exspecialRepository;
this.queryService = queryService;
}
#region HospitalConfig
public List<sys_hospitalconfig> GetHospitalConfig(int hospitalId)
{
var hospital = hospitalRepository.GetEntity(w => w.ID == hospitalId);
if (hospital == null) throw new PerformanceException("医院信息错误");
var data = hospitalconfigRepository.GetEntities(w => w.HospitalId == hospitalId);
var dic = GetDatatypes();
return data;
}
public bool CreateHospitalConfig(sys_hospitalconfig hospitalconfig)
{
if (hospitalconfig.HospitalId == 0) throw new PerformanceException("参数hospitalid为空");
if (string.IsNullOrEmpty(hospitalconfig.DbSource) || string.IsNullOrEmpty(hospitalconfig.DbName)
|| string.IsNullOrEmpty(hospitalconfig.DbUser) || string.IsNullOrEmpty(hospitalconfig.DbPassword))
throw new PerformanceException("配置信息不可为空");
var databases = EnumHelper.GetItems<DatabaseType>();
if (!databases.Select(t => t.Value).Contains(hospitalconfig.DataBaseType))
throw new PerformanceException("数据库类型错误");
var hospital = hospitalRepository.GetEntity(w => w.ID == hospitalconfig.HospitalId);
if (hospital == null) throw new PerformanceException("医院信息错误");
var config = hospitalconfigRepository.GetEntity(w => w.ConfigName == hospitalconfig.ConfigName && w.HospitalId == hospitalconfig.HospitalId);
if (config != null) throw new PerformanceException("连接名称重复");
var result = hospitalconfigRepository.Add(hospitalconfig);
if (result)
TestConnectionCleared(hospitalconfig.Id);
return result;
}
public bool UpdateHospitalConfig(sys_hospitalconfig hospitalconfig)
{
if (string.IsNullOrEmpty(hospitalconfig.DbSource) || string.IsNullOrEmpty(hospitalconfig.DbName)
|| string.IsNullOrEmpty(hospitalconfig.DbUser) || string.IsNullOrEmpty(hospitalconfig.DbPassword))
throw new PerformanceException("配置信息不可为空");
var databases = EnumHelper.GetItems<DatabaseType>();
if (!databases.Select(t => t.Value).Contains(hospitalconfig.DataBaseType))
throw new PerformanceException("数据库类型错误");
var config = hospitalconfigRepository.GetEntity(w => w.ConfigName == hospitalconfig.ConfigName && w.HospitalId == hospitalconfig.HospitalId && w.Id != hospitalconfig.Id);
if (config != null) throw new PerformanceException("连接名称重复");
var entity = hospitalconfigRepository.GetEntity(w => w.Id == hospitalconfig.Id);
if (entity == null) throw new PerformanceException("医院配置信息为空");
entity.DataBaseType = hospitalconfig.DataBaseType;
entity.DbSource = hospitalconfig.DbSource;
entity.DbName = hospitalconfig.DbName;
entity.DbUser = hospitalconfig.DbUser;
entity.DbPassword = hospitalconfig.DbPassword;
return hospitalconfigRepository.Update(entity);
}
public bool DeleteHospitalConfig(int hospitalconfigId)
{
var entity = hospitalconfigRepository.GetEntity(w => w.Id == hospitalconfigId);
if (entity == null) throw new PerformanceException("医院配置信息为空");
return hospitalconfigRepository.Remove(entity);
}
public bool TestConnectionCleared(int hospitalconfigId)
{
var entity = hospitalconfigRepository.GetEntity(w => w.Id == hospitalconfigId);
if (entity == null) throw new PerformanceException("医院配置信息为空");
var result = false;
try
{
var connstr = ConnectionBuilder.GetConnectionString((DatabaseType)entity.DataBaseType, entity.DbSource, entity.DbName, entity.DbUser, entity.DbPassword);
if (string.IsNullOrEmpty(connstr)) return result;
var conn = ConnectionBuilder.Create((DatabaseType)entity.DataBaseType, connstr);
if (conn == null) return result;
conn.Open();
result = true;
entity.IsConnectioned = true;
hospitalconfigRepository.Update(entity);
}
catch (Exception ex)
{
logger.LogError(ex.Message);
}
return result;
}
#endregion
#region Extract Scripts
public List<ExtractConfigResponse> GetExtractTypeAndScript(int hospitalId)
{
var sheettypes = GetSheettypes();
var hospital = hospitalRepository.GetEntity(w => w.ID == hospitalId);
if (hospital == null) throw new PerformanceException("医院信息错误");
var data = extypeRepository.GetEntities(w => w.HospitalId == hospitalId);
if (data == null || !data.Any()) return new List<ExtractConfigResponse>();
var result = sheettypes.Where(w => data.Select(t => t.Source).Contains(w.Value))?
.Select(t => new ExtractConfigResponse
{
Value = t.Value,
Title = t.Title,
Source = t.Value
}).OrderBy(t => t.Source).ToList();
if (result == null || !result.Any()) return new List<ExtractConfigResponse>();
if (result.Any(t => t.Value == (int)SheetType.Employee)) result.First(w => w.Value == (int)SheetType.Employee).Title = "HRP人员";
var list = mapper.Map<List<ExtractConfigResponse>>(data);
var scripts = exscriptRepository.GetEntities(w => data.Select(x => x.Id).Contains(w.TypeId)) ?? new List<ex_script>();
var configs = hospitalconfigRepository.GetEntities(w => w.HospitalId == hospitalId) ?? new List<sys_hospitalconfig>();
foreach (var source in result)
{
var sourcelist = list.Where(w => w.Source == source.Source);
if (sourcelist == null || !sourcelist.Any()) continue;
foreach (var item in sourcelist)
{
var itemScripts = scripts.Where(w => w.TypeId == item.TypeId);
if (itemScripts == null || !itemScripts.Any()) continue;
item.TimeConsuming = itemScripts.Sum(t => t.TimeConsuming);
item.Children = mapper.Map<List<ExtractConfigResponse>>(itemScripts);
int index = 1;
item.Children.ForEach(x =>
{
var config = configs.FirstOrDefault(w => w.Id == x.ConfigId);
if (config != null)
x.ConfigName = string.IsNullOrEmpty(config.ConfigName) ? config.DbSource : config.ConfigName;
if (string.IsNullOrEmpty(x.Name))
{
x.Title = item.EName + index;
x.Name = item.EName + index;
index++;
}
});
}
source.Children = sourcelist.OrderBy(t => t.Name).ToList();
}
return result;
}
public ExtractConfigResponse GetExtractTypeAndScriptById(int typeId, int scriptId)
{
var type = extypeRepository.GetEntity(w => w.Id == typeId);
if (type == null) throw new PerformanceException("参数无效");
var data = mapper.Map<ExtractConfigResponse>(type);
var script = exscriptRepository.GetEntity(w => w.TypeId == typeId && w.Id == scriptId) ?? new ex_script();
if (script != null)
{
data.ExScriptId = script.Id;
data.Name = script.Name;
data.ExecScript = script.ExecScript;
data.ConfigId = script.ConfigId;
data.ConfigName = hospitalconfigRepository.GetEntity(w => w.Id == script.ConfigId)?.ConfigName;
data.TimeConsuming = script.TimeConsuming;
data.IsExecSuccess = script.IsExecSuccess;
data.IsEnable = script.IsEnable;
}
return data;
}
public bool DeleteExtractTypeAndScript(int typeId, int scriptId)
{
if (scriptId != 0)
{
var script = exscriptRepository.GetEntity(w => w.TypeId == typeId && w.Id == scriptId);
if (script == null) throw new PerformanceException("获取提取语句错误");
return exscriptRepository.Remove(script);
}
else
{
var extype = extypeRepository.GetEntity(w => w.Id == typeId);
if (extype == null) throw new PerformanceException("参数typeId无效");
var scripts = exscriptRepository.GetEntities(w => w.TypeId == typeId);
if (scripts != null && scripts.Any() && !exscriptRepository.RemoveRange(scripts.ToArray()))
throw new PerformanceException("提取语句删除失败");
return extypeRepository.Remove(extype);
}
}
public bool EditExtractTypeAndScript(int hospitalId, ExtractConfigResponse request)
{
if (request == null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.EName)) throw new PerformanceException("费用名称不可为空");
var sheettypes = GetSheettypes();
if (!sheettypes.Any(w => w.Value == request.Source)) throw new PerformanceException("暂不支持该类型");
var type = extypeRepository.GetEntity(w => w.EName == request.EName && w.HospitalId == hospitalId && w.Id != request.TypeId);
if (type != null) throw new PerformanceException("费用名称重复");
if (request.TypeId == 0)
{
var entity = mapper.Map<ex_type>(request);
entity.HospitalId = hospitalId;
if (!extypeRepository.Add(entity)) return false;
if (!string.IsNullOrEmpty(request.ExecScript))
{
var script = new ex_script
{
Name = request.Name,
ExecScript = request.ExecScript,
ConfigId = request.ConfigId,
IsEnable = request.IsEnable,
TypeId = entity.Id
};
exscriptRepository.Add(script);
}
}
else
{
var entity = extypeRepository.GetEntity(w => w.Id == request.TypeId);
entity.EName = request.EName;
entity.Description = request.Description;
entity.Source = request.Source;
if (!extypeRepository.Update(entity)) return false;
if (request.ExScriptId != 0)
{
var script = exscriptRepository.GetEntity(w => w.Id == request.ExScriptId);
if (script != null)
{
script.Name = request.Name;
script.ExecScript = request.ExecScript;
script.ConfigId = request.ConfigId;
script.IsEnable = request.IsEnable;
exscriptRepository.Update(script);
}
}
else
{
var script = new ex_script
{
Name = request.Name,
ExecScript = request.ExecScript,
ConfigId = request.ConfigId,
IsEnable = request.IsEnable,
TypeId = entity.Id
};
exscriptRepository.Add(script);
}
}
return true;
}
public dynamic ExecsqlAndGetResult(ConsumeTimeRequest request)
{
var config = hospitalconfigRepository.GetEntity(w => w.Id == request.ConfigId);
if (config == null) throw new PerformanceException("数据库配置资源无效");
var script = exscriptRepository.GetEntity(w => w.Id == request.ExScriptId);
if (request.ExScriptId != 0 && script == null) throw new PerformanceException("参数无效");
IEnumerable<dynamic> data = null;
try
{
var begindate = request.Month > 0 && request.Year > 0 ? new DateTime(request.Year, request.Month, 1) : DateTime.Now.AddMonths(-1);
var enddate = begindate.AddMonths(1);
var param = new
{
beginTime = $"{begindate.Year}-{begindate.Month.ToString().PadLeft(2, '0')}",
endTime = $"{enddate.Year}-{enddate.Month.ToString().PadLeft(2, '0')}"
};
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
data = queryService.QueryData<dynamic>(config, request.ExecScript, param);
stopwatch.Stop();
var timing = Math.Ceiling(stopwatch.ElapsedMilliseconds / 1000m);
if (script != null)
{
script.TimeConsuming = timing;
script.IsExecSuccess = 1;
}
}
catch (Exception ex)
{
if (script != null)
{
script.IsExecSuccess = 2;
script.Description = ex.Message;
}
throw new PerformanceException("查询语句时发生异常");
}
finally
{
if (script != null) exscriptRepository.Update(script);
}
if (data == null || !data.Any()) throw new PerformanceException("查询结果为空");
var header = ((IDictionary<string, object>)data.ElementAt(0)).Keys;
return new { header, data };
}
#endregion
#region 字典
public static List<TitleValue<int>> GetDatatypes()
{
return EnumHelper.GetItems<DatabaseType>().Select(t => new TitleValue<int>
{
Title = t.Name,
Value = t.Value
}).ToList();
}
public static List<TitleValue<int>> GetSheettypes()
{
var showItems = new int[]
{
(int)SheetType.Employee,
(int)SheetType.Income,
(int)SheetType.OtherIncome,
(int)SheetType.Expend,
(int)SheetType.Workload,
(int)SheetType.SpecialUnit,
(int)SheetType.OtherWorkload,
(int)SheetType.Assess,
(int)SheetType.DoctorIncome,
(int)SheetType.Custom,
(int)SheetType.OnlyExtract
};
var list = EnumHelper.GetItems<SheetType>().Where(w => showItems.Contains(w.Value));
return list.Select(t => new TitleValue<int>
{
Title = t.Description,
Value = t.Value
}).ToList();
}
public List<TitleValue<int>> GetExTypes(int hospitalId)
{
var hospital = hospitalRepository.GetEntity(w => w.ID == hospitalId);
if (hospital == null) throw new PerformanceException("医院信息错误");
var data = extypeRepository.GetEntities(w => w.HospitalId == hospitalId);
if (data == null || !data.Any())
return new List<TitleValue<int>>();
return data.Select(t => new TitleValue<int>
{
Title = t.EName,
Value = t.Id
}).ToList();
}
public List<TitleValue<int>> GetConfigs(int hospitalId)
{
var hospital = hospitalRepository.GetEntity(w => w.ID == hospitalId);
if (hospital == null) throw new PerformanceException("医院信息错误");
var data = hospitalconfigRepository.GetEntities(w => w.HospitalId == hospitalId);
if (data == null || !data.Any())
return new List<TitleValue<int>>();
return data.Select(t => new TitleValue<int>
{
Title = t.ConfigName,
Value = t.Id
}).ToList();
}
#endregion
}
}
...@@ -445,6 +445,26 @@ public IEnumerable<T> QueryData<T>(sys_hospitalconfig config, string execsql, pe ...@@ -445,6 +445,26 @@ public IEnumerable<T> QueryData<T>(sys_hospitalconfig config, string execsql, pe
return pairs; return pairs;
} }
/// <summary>
/// 查询数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="config"></param>
/// <param name="execsql"></param>
/// <param name="param"></param>
/// <returns></returns>
public IEnumerable<T> QueryData<T>(sys_hospitalconfig config, string execsql, object param)
{
var connection = ConnectionBuilder.Create((DatabaseType)config.DataBaseType, config.DbSource, config.DbName, config.DbUser, config.DbPassword);
if (connection == null) return new List<T>();
if (connection.State == ConnectionState.Closed)
connection.Open();
var result = connection.Query<T>(execsql, param, commandTimeout: 20000);
return result;
}
#endregion QueryData #endregion QueryData
} }
} }
...@@ -50,7 +50,7 @@ public List<HospitalResponse> GetUserHopital(int userid) ...@@ -50,7 +50,7 @@ public List<HospitalResponse> GetUserHopital(int userid)
var hosList = _hospitalRepository.GetEntities(t => joinList.Select(j => j.HospitalID).Contains(t.ID)); var hosList = _hospitalRepository.GetEntities(t => joinList.Select(j => j.HospitalID).Contains(t.ID));
var hosId = hosList?.Select(item => item.ID).ToList(); var hosId = hosList?.Select(item => item.ID).ToList();
//获取存在数据记录的hospital //获取存在数据记录的hospital
hosId = _hospitalconfigRepository.GetEntities(t => hosId.Contains(t.HospitalId.Value))?.Select(t => t.HospitalId.Value).ToList(); hosId = _hospitalconfigRepository.GetEntities(t => hosId.Contains(t.HospitalId))?.Select(t => t.HospitalId).ToList();
//获取已经上传过模板的hospital //获取已经上传过模板的hospital
var firstId = _perfirstRepository.GetEntities(t => hosId.Contains(t.HospitalId.Value))?.Select(t => t.HospitalId.Value).ToList(); var firstId = _perfirstRepository.GetEntities(t => hosId.Contains(t.HospitalId.Value))?.Select(t => t.HospitalId.Value).ToList();
......
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