Commit 8f91a75c by lcx

sys_hospitalconfig增删改

parent 3bacd8be
......@@ -8,7 +8,7 @@
},
"AppConnection": {
//"PerformanceConnectionString": "server=112.124.13.17;database=db_performance;uid=suvalue;pwd=suvalue2016;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;",
"PerformanceConnectionString": "server=192.168.18.166;database=db_performance_screen;uid=root;pwd=1234qwer;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;",
"PerformanceConnectionString": "server=192.168.18.166;database=db_performance_intro;uid=root;pwd=1234qwer;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;",
"HangfireConnectionString": "server=192.168.18.166;database=db_hangfire;uid=root;pwd=1234qwer;port=3306;allow user variables=true;",
"RedisConnectionString": "116.62.245.55:6379,defaultDatabase=2"
},
......
......@@ -24,7 +24,7 @@ public class sys_hospitalconfig
/// <summary>
///
/// </summary>
public Nullable<int> HospitalId { get; set; }
public int HospitalId { get; set; }
/// <summary>
///
......@@ -52,13 +52,13 @@ public class sys_hospitalconfig
public string DbPassword { get; set; }
/// <summary>
/// 1 标准库 2 绩效库
/// 1、Sql Server 2、Orcale
/// </summary>
public Nullable<int> Type { get; set; }
public int DataBaseType { get; set; }
/// <summary>
/// 1、Sql Server 2、Orcale
///
/// </summary>
public int DataBaseType { get; set; }
public bool IsConnectioned { get; set; }
}
}
using AutoMapper;
using Microsoft.Extensions.Logging;
using Performance.DtoModels;
using Performance.EntityModels;
using Performance.Infrastructure;
using Performance.Repository;
using System;
using System.Collections.Generic;
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;
public ExtractPreConfigService(
ILogger<ExtractPreConfigService> logger,
IMapper mapper,
PerforHospitalRepository hospitalRepository,
PerforHospitalconfigRepository hospitalconfigRepository,
PerforExtypeRepository extypeRepository,
PerforExscriptRepository exscriptRepository,
PerforExmoduleRepository exmoduleRepository,
PerforExitemRepository exitemRepository,
PerforExspecialRepository exspecialRepository)
{
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;
}
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);
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("医院信息错误");
return hospitalconfigRepository.Add(hospitalconfig);
}
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 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;
}
public List<ex_type> GetExtractTypeAndScript(int hospitalId)
{
var hospital = hospitalRepository.GetEntity(w => w.ID == hospitalId);
if (hospital == null) throw new PerformanceException("医院信息错误");
var data = extypeRepository.GetEntities(w => w.HospitalId == hospitalId);
return data;
}
#region 字典
public List<TitleValue<int>> GetDatatypes()
{
return EnumHelper.GetItems<DatabaseType>().Select(t => new TitleValue<int>
{
Title = t.Name,
Value = t.Value
}).ToList();
}
public List<TitleValue<int>> GetSheettypes()
{
var showItems = new int[]
{
(int)SheetType.Employee,
(int)SheetType.OtherIncome,
(int)SheetType.Income,
(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();
}
#endregion
}
}
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