Commit bce59136 by tangzhongyang

1

parent 5ba5fc12
...@@ -319,7 +319,7 @@ public IActionResult ceshi() ...@@ -319,7 +319,7 @@ public IActionResult ceshi()
[HttpPost("Cursor")] [HttpPost("Cursor")]
[AllowAnonymous] [AllowAnonymous]
public string Cursor([FromBody] CursorModel Sql) public List<string> Cursor([FromBody] CursorModel Sql)
{ {
return _homeQueries.Cursor(Sql); return _homeQueries.Cursor(Sql);
} }
......
...@@ -30,7 +30,7 @@ protected override void Load(ContainerBuilder builder) ...@@ -30,7 +30,7 @@ protected override void Load(ContainerBuilder builder)
builder.Register(c => new UserQueries(configConnectionString)).InstancePerLifetimeScope(); builder.Register(c => new UserQueries(configConnectionString)).InstancePerLifetimeScope();
builder.Register(c => new ResourceQueries(Connection156, configConnectionString)).InstancePerLifetimeScope(); builder.Register(c => new ResourceQueries(Connection156, configConnectionString)).InstancePerLifetimeScope();
builder.Register(c => new DrugqueryQueries(Connection156, configConnectionString)).InstancePerLifetimeScope(); builder.Register(c => new DrugqueryQueries(Connection156, configConnectionString)).InstancePerLifetimeScope();
builder.Register(c => new HomeQueries(configConnectionString)).InstancePerLifetimeScope(); builder.Register(c => new HomeQueries(configConnectionString, Connection156)).InstancePerLifetimeScope();
builder.Register(c => new AnalysisQueries(Connection156, configConnectionString)).InstancePerLifetimeScope(); builder.Register(c => new AnalysisQueries(Connection156, configConnectionString)).InstancePerLifetimeScope();
} }
} }
......
...@@ -107,6 +107,8 @@ public class SYS_YIYUAN ...@@ -107,6 +107,8 @@ public class SYS_YIYUAN
public class CursorModel public class CursorModel
{ {
///
public string TableName { get; set; }
/// <summary> /// <summary>
/// 地区 /// 地区
/// </summary> /// </summary>
......
...@@ -261,7 +261,7 @@ UNION ALL ...@@ -261,7 +261,7 @@ UNION ALL
catch (Exception ex) catch (Exception ex)
{ {
configConnection.Execute(@$"update [SV_QueryPlatform_].[dbo].[MEDIC_SEARCH_RECORD] set COMPLETE_MARK = 23,END_TIME=getdate(),log='{sql2.Replace("'", "''")}' where COMPLETE_MARK != 22 and id= " + Indexs); configConnection.Execute(@$"update [SV_QueryPlatform_].[dbo].[MEDIC_SEARCH_RECORD] set COMPLETE_MARK = 23,END_TIME=getdate(),log='{sql2.Replace("'", "''")}' where COMPLETE_MARK != 22 and id= " + Indexs);
HomeQueries home = new HomeQueries(_configConnectionString); HomeQueries home = new HomeQueries(_configConnectionString,_Connection156);
home.SendMail(@$"药品/疾病/材料平台提醒", @$"疾病拉取失败 {icd_or_diseaseCondition} 错误日志:{ex.ToString().Replace("'", "''")}", "唐仲阳"); home.SendMail(@$"药品/疾病/材料平台提醒", @$"疾病拉取失败 {icd_or_diseaseCondition} 错误日志:{ex.ToString().Replace("'", "''")}", "唐仲阳");
} }
...@@ -410,7 +410,7 @@ UNION ALL ...@@ -410,7 +410,7 @@ UNION ALL
catch (Exception ex) catch (Exception ex)
{ {
configConnection.Execute($"update [SV_QueryPlatform_].[dbo].[MEDIC_SEARCH_RECORD] set COMPLETE_MARK = 23,END_TIME=getdate(),log='ex:{ex.ToString()}sql:{sql2.Replace("'", "''")}' where COMPLETE_MARK != 22 and id= " + Indexs); configConnection.Execute($"update [SV_QueryPlatform_].[dbo].[MEDIC_SEARCH_RECORD] set COMPLETE_MARK = 23,END_TIME=getdate(),log='ex:{ex.ToString()}sql:{sql2.Replace("'", "''")}' where COMPLETE_MARK != 22 and id= " + Indexs);
HomeQueries home = new HomeQueries(_configConnectionString); HomeQueries home = new HomeQueries(_configConnectionString, _Connection156);
home.SendMail(@$"药品/疾病/材料平台提醒", @$"药品拉取失败{string.Join(",", drugName)} 错误日志:{ex.ToString().Replace("'", "''")}", zxr); home.SendMail(@$"药品/疾病/材料平台提醒", @$"药品拉取失败{string.Join(",", drugName)} 错误日志:{ex.ToString().Replace("'", "''")}", zxr);
} }
} }
...@@ -567,7 +567,7 @@ UNION ALL ...@@ -567,7 +567,7 @@ UNION ALL
catch (Exception ex) catch (Exception ex)
{ {
configConnection.Execute($"update [SV_QueryPlatform_].[dbo].[MEDIC_SEARCH_RECORD] set COMPLETE_MARK = 23,END_TIME=getdate(),log='{sql2.Replace("'", "''")}' where COMPLETE_MARK != 22 and id= " + Indexs); configConnection.Execute($"update [SV_QueryPlatform_].[dbo].[MEDIC_SEARCH_RECORD] set COMPLETE_MARK = 23,END_TIME=getdate(),log='{sql2.Replace("'", "''")}' where COMPLETE_MARK != 22 and id= " + Indexs);
HomeQueries home = new HomeQueries(_configConnectionString); HomeQueries home = new HomeQueries(_configConnectionString, _Connection156);
home.SendMail(@$"药品/疾病/材料平台提醒", @$"材料拉取失败 {string.Join(",", drugName)} 错误日志:{ex.ToString().Replace("'", "''")}", zxr); home.SendMail(@$"药品/疾病/材料平台提醒", @$"材料拉取失败 {string.Join(",", drugName)} 错误日志:{ex.ToString().Replace("'", "''")}", zxr);
} }
} }
...@@ -765,7 +765,7 @@ public int indexsId(int indexs) ...@@ -765,7 +765,7 @@ public int indexsId(int indexs)
{ {
var sql = $"update [SV_QueryPlatform_].[dbo].[MEDIC_SEARCH_RECORD_ASSAY] set COMPLETE_MARK = 23,END_TIME=getdate(),log='步骤{bz} 错误:{ex.ToString().Replace("'", "''").Distinct()}' where id={id}"; var sql = $"update [SV_QueryPlatform_].[dbo].[MEDIC_SEARCH_RECORD_ASSAY] set COMPLETE_MARK = 23,END_TIME=getdate(),log='步骤{bz} 错误:{ex.ToString().Replace("'", "''").Distinct()}' where id={id}";
configConnection.Execute(sql); configConnection.Execute(sql);
HomeQueries home = new HomeQueries(_configConnectionString); HomeQueries home = new HomeQueries(_configConnectionString, _Connection156);
home.SendMail(@$"化验拉取提醒", @$"{(type == 1 ? "化验" : "检查")} 拉取失败! indexs:{indexs} id:{id} 报错步骤:{bz} 错误日志:{ex.ToString().Replace("'", "''")}", zxr); home.SendMail(@$"化验拉取提醒", @$"{(type == 1 ? "化验" : "检查")} 拉取失败! indexs:{indexs} id:{id} 报错步骤:{bz} 错误日志:{ex.ToString().Replace("'", "''")}", zxr);
throw; throw;
} }
......
...@@ -6,10 +6,13 @@ ...@@ -6,10 +6,13 @@
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using Microsoft.Data.SqlClient; using Microsoft.Data.SqlClient;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NPoco.Expressions;
using NPOI.HSSF.UserModel; using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel; using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel; using NPOI.XSSF.UserModel;
using QueryPlatform.Api.Infrastructure.Modules; using QueryPlatform.Api.Infrastructure.Modules;
using StackExchange.Profiling.Internal;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
...@@ -26,15 +29,29 @@ namespace QueryPlatform.Api.Infrastructure.Queries ...@@ -26,15 +29,29 @@ namespace QueryPlatform.Api.Infrastructure.Queries
public class HomeQueries public class HomeQueries
{ {
private readonly string _Connection156;
private readonly string _configConnectionString; private readonly string _configConnectionString;
public HomeQueries(string configConnectionString) public HomeQueries(string configConnectionString, string Connection156)
{ {
_configConnectionString = configConnectionString; _configConnectionString = configConnectionString;
_Connection156 = Connection156;
} }
private DbConnection Connection() private DbConnection Connection()
{ {
return new SqlConnection(_configConnectionString); return new SqlConnection(_configConnectionString);
} }
public DbConnection Connection(long ip, string y = "", string t = "")
{
if (ip == 156)
{
return new SqlConnection((y == "") ? _Connection156 : _Connection156.Replace(y, t));
}
if (ip == 181)
{
return new SqlConnection((y == "") ? _configConnectionString : _configConnectionString.Replace(y, t));
}
return new SqlConnection();
}
#region 存储函数添加查询 #region 存储函数添加查询
public void FuncaConfiguration(COMMONLYUSED commonly) public void FuncaConfiguration(COMMONLYUSED commonly)
{ {
...@@ -1417,42 +1434,65 @@ public List<string> ceshi() ...@@ -1417,42 +1434,65 @@ public List<string> ceshi()
/// 游标 /// 游标
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public string Cursor(CursorModel model) public List<string> Cursor(CursorModel model)
{ {
var dbs = "SELECT ExecOpenLink ,ExecDatabase FROM [DB_SV_Data_Config].[dbo].[SYS_Hospital] where isnull([ExecOpenLink],'')!='' and isnull([ExecDatabase],'')!=''"; var dbs = "SELECT ExecOpenLink ,ExecDatabase FROM [DB_SV_Data_Config].[dbo].[SYS_Hospital] where isnull([ExecOpenLink],'')!='' and isnull([ExecDatabase],'')!=''";
string Return = @"执行结束"; List<string> Return = new List<string>();
string condition = ""; if (string.IsNullOrEmpty(model.ExecuteSql) || string.IsNullOrEmpty(model.TableName))
if (string.IsNullOrEmpty(model.ExecuteSql)) Return.Add("请填写流水库表名和待执行sql!");
{ Return.Add("医院区域:" + (string.IsNullOrEmpty(model.City) ? "全部" : model.City));
Return = "请填写全!"; Return.Add("医院等级:" + (string.IsNullOrEmpty(model.HosLevel) ? "全部" : model.HosLevel));
return Return; Return.Add("医院类型:" + (string.IsNullOrEmpty(model.HosType) ? "全部" : model.HosType));
}
if (!string.IsNullOrEmpty(model.City)) if (!string.IsNullOrEmpty(model.City))
{
dbs = dbs + $" and City like '%{model.City}%'"; dbs = dbs + $" and City like '%{model.City}%'";
condition = "医院区域:" + model.City; if (!string.IsNullOrEmpty(model.HosLevel))
}
if (!string.IsNullOrEmpty(model.HosLevel))
{
dbs = dbs + $" and HosLevel like '%{model.HosLevel}%'"; dbs = dbs + $" and HosLevel like '%{model.HosLevel}%'";
condition = condition+(string.IsNullOrEmpty(condition)?("医院等级:" + model.City): (@" if (!string.IsNullOrEmpty(model.HosType))
医院等级:" + model.HosLevel)); dbs = dbs + $" and HosType like '%{model.HosType}%'";
} Return.Add("ExecuteSql:" + model.ExecuteSql);
if (!string.IsNullOrEmpty(model.HosType)) var hoss = Connection(156).Query<SYS_Hospital>(dbs);
Return.Add("需执行医院数:" + hoss.Count());
//建表
var _sys = hoss.FirstOrDefault();
服务器 fwq = Connection(181).Query<服务器>($"SELECT [服务器ip],[数据库账号],[数据库密码] FROM [SV_QueryPlatform].[dbo].[服务器] where[服务器ip] ='{_sys.ExecOpenLink}'").FirstOrDefault();
var msConnectionString = string.Format("Server={0};Database={1};User ID={2};Password={3};Trusted_Connection=False;", _sys.ExecOpenLink, _sys.ExecDatabase, fwq.数据库账号, fwq.数据库密码);
var json = new SqlConnection(msConnectionString).Query(model.ExecuteSql.Replace("@Name", _sys.ExecDatabase)).ToJson();
JArray jsonArray = JArray.Parse(json);
var CreateTable = $"CREATE TABLE [SV_Cursor].[dbo].[{model.TableName}](";
var insertInto = $"insert into [192.168.18.181].[SV_Cursor].[dbo].[{model.TableName}](";
if (jsonArray.Count > 0)
{ {
condition = condition+(string.IsNullOrEmpty(condition) ? ("医院类型:" + model.HosType) : (@" JObject jsonObject = (JObject)jsonArray[0];
医院类型:" + model.HosType)); List<string> propertyNames = new List<string>();
foreach (JProperty property in jsonObject.Properties())
{
CreateTable = CreateTable + property.Name + $" [nvarchar](max) NULL,";
insertInto = insertInto + property.Name + $",";
}
CreateTable = CreateTable + ")";
insertInto = insertInto.Substring(0, insertInto.Length - 1) + ")";
Connection(181).Execute(CreateTable);
} }
//执行
foreach (var hos in hoss)
{
var ExecSql = "";
fwq = Connection(181).Query<服务器>($"SELECT [服务器ip],[数据库账号],[数据库密码] FROM [SV_QueryPlatform].[dbo].[服务器] where[服务器ip] ='{hos.ExecOpenLink}'").FirstOrDefault();
return condition+Return; msConnectionString = string.Format("Server={0};Database={1};User ID={2};Password={3};Trusted_Connection=False;", hos.ExecOpenLink, hos.ExecDatabase, fwq.数据库账号, fwq.数据库密码);
try
{
ExecSql = insertInto + model.ExecuteSql.Replace("@Name", hos.ExecDatabase);
new SqlConnection(msConnectionString).Execute(ExecSql);
}
catch (Exception)
{
Return.Add($"执行状态:执行失败,服务器地址:{hos.ExecOpenLink},数据库名称:{hos.ExecDatabase},ExecuteSql:{ExecSql}");
}
}
Return.Add("执行结束");
return Return;
} }
} }
......
...@@ -389,6 +389,12 @@ ...@@ -389,6 +389,12 @@
<param name="dt">Datatable对象</param> <param name="dt">Datatable对象</param>
<returns>Json字符串</returns> <returns>Json字符串</returns>
</member> </member>
<member name="M:QueryPlatform.Api.Infrastructure.Queries.HomeQueries.Cursor(QueryPlatform.Api.Infrastructure.Modules.CursorModel)">
<summary>
游标
</summary>
<returns></returns>
</member>
<member name="M:QueryPlatform.Api.Infrastructure.Queries.ResourceQueries.ItemQuery(System.String,System.Int64)"> <member name="M:QueryPlatform.Api.Infrastructure.Queries.ResourceQueries.ItemQuery(System.String,System.Int64)">
<summary> <summary>
查询所有项目 查询所有项目
...@@ -563,6 +569,29 @@ ...@@ -563,6 +569,29 @@
备注 备注
</summary> </summary>
</member> </member>
<member name="P:QueryPlatform.Api.Infrastructure.Modules.CursorModel.TableName">
</member>
<member name="P:QueryPlatform.Api.Infrastructure.Modules.CursorModel.City">
<summary>
地区
</summary>
</member>
<member name="P:QueryPlatform.Api.Infrastructure.Modules.CursorModel.HosLevel">
<summary>
医院等级
</summary>
</member>
<member name="P:QueryPlatform.Api.Infrastructure.Modules.CursorModel.HosType">
<summary>
医院类型
</summary>
</member>
<member name="P:QueryPlatform.Api.Infrastructure.Modules.CursorModel.ExecuteSql">
<summary>
执行sql
</summary>
</member>
<member name="P:QueryPlatform.Api.Infrastructure.Modules.DATAEXTRACT.START_TIME"> <member name="P:QueryPlatform.Api.Infrastructure.Modules.DATAEXTRACT.START_TIME">
<summary> <summary>
开始时间 开始时间
......
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