Commit 11ad72b5 by lcx

操作提取sql配置

parent b8cb60f9
......@@ -1199,7 +1199,7 @@
</member>
<member name="M:Performance.Api.Controllers.EmployeeController.GetGatherHands(System.Int32,Performance.DtoModels.GatherRequest)">
<summary>
手工录入
手工录入 - 录入界面
</summary>
<param name="allotId"></param>
<param name="request"></param>
......@@ -1215,7 +1215,15 @@
</member>
<member name="M:Performance.Api.Controllers.EmployeeController.GetGather(System.Int32,Performance.DtoModels.PersonParamsRequest)">
<summary>
手工录入列表
手工录入列表 - 明细
</summary>
<param name="allotId"></param>
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.EmployeeController.GetGatherTotal(System.Int32,Performance.DtoModels.PersonParamsRequest)">
<summary>
手工录入列表 - 汇总
</summary>
<param name="allotId"></param>
<param name="request"></param>
......
......@@ -3619,6 +3619,16 @@
创建时间
</summary>
</member>
<member name="P:Performance.EntityModels.ex_result_gather.Remark">
<summary>
备注
</summary>
</member>
<member name="P:Performance.EntityModels.ex_result_gather.States">
<summary>
1 未通过 2 通过
</summary>
</member>
<member name="T:Performance.EntityModels.ex_script">
<summary>
......@@ -3649,6 +3659,21 @@
是否可用 1 可用 2 不可用
</summary>
</member>
<member name="P:Performance.EntityModels.ex_script.IsExecSuccess">
<summary>
是否执行通过
</summary>
</member>
<member name="P:Performance.EntityModels.ex_script.ErrorMessage">
<summary>
执行错误信息
</summary>
</member>
<member name="P:Performance.EntityModels.ex_script.TimeConsuming">
<summary>
语句执行完成所需时间
</summary>
</member>
<member name="T:Performance.EntityModels.ex_special">
<summary>
......@@ -8315,14 +8340,14 @@
</summary>
</member>
<member name="P:Performance.EntityModels.sys_hospitalconfig.Type">
<member name="P:Performance.EntityModels.sys_hospitalconfig.DataBaseType">
<summary>
1 标准库 2 绩效库
1、Sql Server 2、Orcale
</summary>
</member>
<member name="P:Performance.EntityModels.sys_hospitalconfig.DataBaseType">
<member name="P:Performance.EntityModels.sys_hospitalconfig.IsConnectioned">
<summary>
1、Sql Server 2、Orcale
</summary>
</member>
<member name="T:Performance.EntityModels.sys_menu">
......
......@@ -2,10 +2,7 @@
using Performance.DtoModels.Request;
using Performance.EntityModels;
using Performance.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Performance.DtoModels.AutoMapper
{
......@@ -255,6 +252,14 @@ public AutoMapperConfigs()
CreateMap<ex_result, ex_result_gather>()
.ReverseMap();
CreateMap<ex_type, ExtractConfigResponse>()
.ForMember(dest => dest.TypeId, opt => opt.MapFrom(src => src.Id))
.ReverseMap();
CreateMap<ex_script, ExtractScriptConfig>()
.ForMember(dest => dest.ExScriptId, opt => opt.MapFrom(src => src.Id))
.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; }
}
}
namespace Performance.DtoModels
{
public class ExTypeRequest
{
public int HospitalId { get; set; }
public int? SheetType { get; set; }
public string Search { get; set; }
public int PageNumber { get; set; }
public int PageSize { get; set; }
}
}
using System.Collections.Generic;
namespace Performance.DtoModels
{
public class ExtractConfigResponse
{
public int TypeId { get; set; }
public string EName { get; set; }
public string Description { get; set; }
public int Source { get; set; }
public string SheetType { get; set; }
public decimal TotalTime { get; set; }
public List<ExtractScriptConfig> Children { get; set; } = new List<ExtractScriptConfig>();
}
public class ExtractScriptConfig
{
public int ExScriptId { get; set; }
public string ExecScript { get; set; }
public int ConfigId { get; set; }
public string ConfigName { get; set; }
public int IsEnable { get; set; }
public int IsExecSuccess { get; set; }
public string ErrorMessage { get; set; }
public decimal TimeConsuming { get; set; }
}
}
......@@ -39,5 +39,20 @@ public class ex_script
/// 是否可用 1 可用 2 不可用
/// </summary>
public int IsEnable { get; set; }
/// <summary>
/// 是否执行通过
/// </summary>
public int IsExecSuccess { get; set; }
/// <summary>
/// 执行错误信息
/// </summary>
public string ErrorMessage { get; set; }
/// <summary>
/// 语句执行完成所需时间
/// </summary>
public decimal TimeConsuming { get; set; } = 0;
}
}
using Performance.EntityModels;
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()
{
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
/// </summary>
public partial class PerforExtypeRepository : PerforRepository<ex_type>
{
private readonly PerformanceDbContext _context;
public PerforExtypeRepository(PerformanceDbContext context) : base(context)
{
_context = context;
}
}
}
......@@ -3,9 +3,11 @@
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
......@@ -22,6 +24,8 @@ public class ExtractPreConfigService : IAutoInjection
private readonly PerforExitemRepository exitemRepository;
private readonly PerforExspecialRepository exspecialRepository;
private readonly QueryService queryService;
public ExtractPreConfigService(
ILogger<ExtractPreConfigService> logger,
IMapper mapper,
......@@ -31,7 +35,8 @@ public class ExtractPreConfigService : IAutoInjection
PerforExscriptRepository exscriptRepository,
PerforExmoduleRepository exmoduleRepository,
PerforExitemRepository exitemRepository,
PerforExspecialRepository exspecialRepository)
PerforExspecialRepository exspecialRepository,
QueryService queryService)
{
this.logger = logger;
this.mapper = mapper;
......@@ -42,6 +47,7 @@ public class ExtractPreConfigService : IAutoInjection
this.exmoduleRepository = exmoduleRepository;
this.exitemRepository = exitemRepository;
this.exspecialRepository = exspecialRepository;
this.queryService = queryService;
}
#region HospitalConfig
......@@ -132,15 +138,232 @@ public bool TestConnectionCleared(int hospitalconfigId)
#endregion
public List<ex_type> GetExtractTypeAndScript(int hospitalId, int sheetType, string search, int pageNumber, int pageSize)
#region Extract Scripts
public PageList<ExtractConfigResponse> GetExtractTypeAndScript(ExTypeRequest request)
{
var hospital = hospitalRepository.GetEntity(w => w.ID == hospitalId);
var hospital = hospitalRepository.GetEntity(w => w.ID == request.HospitalId);
if (hospital == null) throw new PerformanceException("医院信息错误");
var data = extypeRepository.GetEntities(w => w.HospitalId == hospitalId);
var data = extypeRepository.GetPagingData(request.HospitalId, request.SheetType, request.Search, request.PageNumber, request.PageSize);
if (data == null || !data.Any())
return new PageList<ExtractConfigResponse>(new List<ExtractConfigResponse>(), 0, request.PageNumber, request.PageSize);
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 == request.HospitalId) ?? new List<sys_hospitalconfig>();
var sheettypes = GetSheettypes();
foreach (var item in list)
{
item.SheetType = sheettypes.FirstOrDefault(w => w.Value == item.Source)?.Title;
var itemScripts = scripts.Where(w => w.TypeId == item.TypeId);
if (itemScripts == null || !itemScripts.Any()) continue;
item.TotalTime = itemScripts.Sum(t => t.TimeConsuming);
item.Children = mapper.Map<List<ExtractScriptConfig>>(itemScripts);
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;
});
}
return new PageList<ExtractConfigResponse>(list, data.TotalCount, request.PageNumber, request.PageSize);
}
public ExtractConfigResponse GetExtractTypeAndScriptById(int typeId)
{
var type = extypeRepository.GetEntity(w => w.Id == typeId);
if (type == null) throw new PerformanceException("参数无效");
var data = mapper.Map<ExtractConfigResponse>(type);
var sheettypes = GetSheettypes();
data.SheetType = sheettypes.FirstOrDefault(w => w.Value == data.Source)?.Title;
var scripts = exscriptRepository.GetEntities(w => w.TypeId == typeId) ?? new List<ex_script>();
if (scripts != null && scripts.Any())
{
var configs = hospitalconfigRepository.GetEntities(w => scripts.Select(s => s.ConfigId).Contains(w.Id)) ?? new List<sys_hospitalconfig>();
data.TotalTime = scripts.Sum(t => t.TimeConsuming);
data.Children = mapper.Map<List<ExtractScriptConfig>>(scripts);
data.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;
});
}
return data;
}
public bool DeleteExtractTypeAndScript(int typeId)
{
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()) return true;
if (!exscriptRepository.RemoveRange(scripts.ToArray()))
if (extype == null) throw new PerformanceException("提取语句删除失败");
return extypeRepository.Remove(extype);
}
public bool EditExtractTypeAndScript(int hospitalId, ExtractConfigResponse request)
{
if (request == null) throw new ArgumentNullException(nameof(request));
if (request.TypeId == 0)
{
var entity = mapper.Map<ex_type>(request);
entity.HospitalId = hospitalId;
if (!extypeRepository.Add(entity)) return false;
if (request.Children != null && request.Children.Any())
{
var scripts = mapper.Map<List<ex_script>>(request.Children);
scripts.ForEach(t => t.TypeId = entity.Id);
exscriptRepository.AddRange(scripts.ToArray());
}
}
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;
var scripts = exscriptRepository.GetEntities(w => w.TypeId == request.TypeId);
/* 添加不存在的数据 */
if (request.Children != null && request.Children.Any(w => w.ExScriptId == 0))
{
var list = mapper.Map<List<ex_script>>(request.Children);
return exscriptRepository.AddRange(list.ToArray());
}
/* 删除、修改存在的数据 */
if (scripts != null && scripts.Any())
{
var existIds = request.Children?.Select(w => w.ExScriptId) ?? new List<int>();
var delScripts = scripts.Where(w => !existIds.Contains(w.Id));
if (delScripts != null && delScripts.Any())
exscriptRepository.RemoveRange(delScripts.ToArray());
var updScripts = scripts.Where(w => existIds.Contains(w.Id));
if (updScripts != null && updScripts.Any())
{
foreach (var item in updScripts)
{
var model = request.Children.FirstOrDefault(w => w.ExScriptId == item.Id);
if (model == null) continue;
item.ExecScript = model.ExecScript;
item.ConfigId = model.ConfigId;
item.IsEnable = model.IsEnable;
}
exscriptRepository.UpdateRange(updScripts.ToArray());
}
}
}
return true;
}
public decimal CheckExecsqlConsumeTime(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("参数无效");
try
{
if (request.Month == 0 || request.Year == 0)
{
request.Month = DateTime.Now.Month;
request.Year = DateTime.Now.Year;
}
var param = new
{
beginDate = $"{(request.Month == 1 ? request.Year - 1 : request.Year)}-{(request.Month == 1 ? 12 : request.Month - 1).ToString().PadLeft(2, '0')}",
endDate = $"{request.Year}-{request.Month.ToString().PadLeft(2, '0')}"
};
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
var data = queryService.QueryData<dynamic>(config, request.ExecScript, param);
stopwatch.Stop();
var timing = Math.Ceiling(stopwatch.ElapsedMilliseconds / 1000m);
if (script == null) return timing;
script.TimeConsuming = timing;
script.IsExecSuccess = 1;
}
catch (Exception ex)
{
if (script == null) throw new PerformanceException("");
script.IsExecSuccess = 0;
script.ErrorMessage = ex.Message;
}
exscriptRepository.Update(script);
return script.TimeConsuming;
}
#endregion
#region Model Item Special
public void CreateDefaultModeul(int hospitalId)
{
var moduleList = new List<ex_module>
{
new ex_module{ ModuleName = "1.0.1 额外收入", SheetType = (int)SheetType.OtherIncome, ReadOnly = 0 },
new ex_module{ ModuleName = "1.1.1 门诊开单收入", SheetType = (int)SheetType.Income, ReadOnly = 1 },
new ex_module{ ModuleName = "1.1.2 门诊执行收入", SheetType = (int)SheetType.Income, ReadOnly = 1 },
new ex_module{ ModuleName = "1.2.1 住院开单收入", SheetType = (int)SheetType.Income, ReadOnly = 1 },
new ex_module{ ModuleName = "1.2.2 住院执行收入", SheetType = (int)SheetType.Income, ReadOnly = 1 },
new ex_module{ ModuleName = "2.1 成本支出统计表", SheetType = (int)SheetType.Expend, ReadOnly = 0 },
new ex_module{ ModuleName = "3.1 医生组工作量绩效测算表", SheetType = (int)SheetType.Workload, ReadOnly = 0 },
new ex_module{ ModuleName = "3.2 护理组工作量绩效测算表", SheetType = (int)SheetType.Workload, ReadOnly = 0 },
};
var data = exmoduleRepository.GetEntities(t => t.HospitalId == hospitalId);
var inexistence = data == null ? moduleList : moduleList.Where(t => !data.Any(w => w.ModuleName.StartsWith(t.ModuleName.Split(' ')[0])))?.ToList();
if (inexistence != null && inexistence.Any())
{
inexistence.ForEach(t =>
{
t.HospitalId = hospitalId;
});
exmoduleRepository.AddRange(inexistence.ToArray());
}
}
public List<ex_module> GetExModelList(int hospitalId)
{
return new List<ex_module>();
}
#endregion
#region 字典
public List<TitleValue<int>> GetDatatypes()
......
......@@ -442,6 +442,26 @@ public IEnumerable<T> QueryData<T>(sys_hospitalconfig config, string execsql, pe
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
}
}
......@@ -50,7 +50,7 @@ public List<HospitalResponse> GetUserHopital(int userid)
var hosList = _hospitalRepository.GetEntities(t => joinList.Select(j => j.HospitalID).Contains(t.ID));
var hosId = hosList?.Select(item => item.ID).ToList();
//获取存在数据记录的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
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