Commit 13fb3b8a by tangzhongyang

更新

parent 8d6658a9
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
</ItemGroup>
</Project>
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Linq;
namespace DBHelper
{
public class DBHelpers
{
public static string ConectionString = "server=192.168.18.151;User Id=sa;Password=Suvalue2016;";
public DBHelpers() { }
/// <summary>
/// 执行循环的sql
/// </summary>
/// <param name="SQLString"></param>
/// <returns>表名集合</returns>
public static List<string> Query(string CirculateSql)
{
List<string> tableName = new List<string>();
using (SqlConnection connection = new SqlConnection(ConectionString))
{
using (SqlCommand cmd = new SqlCommand(CirculateSql, connection))
{
connection.Open();
SqlDataReader result = cmd.ExecuteReader();
while (result.Read())
{
tableName.Add(result["name"].ToString());
}
connection.Close();
return tableName;
}
}
}
/// <summary>
/// 遍历表名,并执行sql
/// </summary>
/// <param name="tableName"></param>
/// <returns>受影响的行数(-1:执行的sql为空 -2:未找到表)</returns>
public static int Add(List<string> tableName,string ExcuteSql){
int count=0;
if (ExcuteSql == "" || ExcuteSql == null)
{
count = -1;
return count;
}
else if (tableName.Count == 0)
{
count = -2;
return count;
}
using (SqlConnection connection = new SqlConnection(ConectionString))
{
connection.Open();
foreach (var name in tableName)
{
SqlCommand cmd = connection.CreateCommand();
cmd.CommandText = ExcuteSql.Replace("[@name]","["+name+"]");
count += cmd.ExecuteNonQuery();
ExcuteSql = ExcuteSql.Replace("[" + name + "]", "[@name]");
}
connection.Close();
}
return count;
}
}
}

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34018.315
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApplication1", "WebApplication1\WebApplication1.csproj", "{EF8E5F21-FE45-4812-B60F-5375F6C51C01}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DBHelper", "DBHelper\DBHelper.csproj", "{CB7F6E84-B3B5-46FA-80A2-88EC633828B3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EF8E5F21-FE45-4812-B60F-5375F6C51C01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EF8E5F21-FE45-4812-B60F-5375F6C51C01}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EF8E5F21-FE45-4812-B60F-5375F6C51C01}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EF8E5F21-FE45-4812-B60F-5375F6C51C01}.Release|Any CPU.Build.0 = Release|Any CPU
{CB7F6E84-B3B5-46FA-80A2-88EC633828B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CB7F6E84-B3B5-46FA-80A2-88EC633828B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB7F6E84-B3B5-46FA-80A2-88EC633828B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB7F6E84-B3B5-46FA-80A2-88EC633828B3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C360C5EB-C4AE-4FDF-9AAD-406E0050028B}
EndGlobalSection
EndGlobal
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
namespace WebApplication1.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class CursorController : ControllerBase
{
[HttpPost("Demo")]
public int Demo([FromBody]SqlModel Sql)
{
List<string> TableNames = DBHelper.DBHelpers.Query(Sql.CirculateSql);
return DBHelper.DBHelpers.Add(TableNames,Sql.ExecuteSql);
}
}
}
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebApplication1
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:41905",
"sslPort": 44327
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"WebApplication1": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
namespace WebApplication1
{
public class SqlModel
{
public string CirculateSql { get; set; }
public string ExecuteSql { get; set; }
}
}
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebApplication1
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "WebApplication1", Version = "v1" });
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebApplication1 v1"));
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
using System;
namespace WebApplication1
{
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string Summary { get; set; }
}
}
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DBHelper\DBHelper.csproj" />
</ItemGroup>
</Project>
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
},
"Connection": {
"ConnectionString": "Host=192.168.18.187;Port=5432;Username=postgres;Password=Suvalue2016;Database=db_healthcare_drgs_gongcheng;SearchPath=public;"
}
}
}
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
using Microsoft.AspNetCore.Authorization;
using com.sun.tools.javac.util;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using QueryPlatform.Api.Infrastructure.Modules;
using System;
......@@ -15,8 +16,10 @@ public class DrugqueryController : Controller
{
private readonly DrugqueryQueries _drugqueryQueries;
private readonly HomeQueries _homeQueries;
public DrugqueryController(DrugqueryQueries drugqueryQueries, HomeQueries homeQueries)
private readonly ResourceQueries _resourceQueries;
public DrugqueryController(DrugqueryQueries drugqueryQueries, HomeQueries homeQueries, ResourceQueries resourceQueries)
{
_resourceQueries= resourceQueries;
_drugqueryQueries = drugqueryQueries;
_homeQueries = homeQueries;
}
......@@ -135,6 +138,7 @@ public DrugqueryController(DrugqueryQueries drugqueryQueries, HomeQueries homeQu
await semaphore.WaitAsync();
try
{
_resourceQueries.LOG($"查询条件", "", num, "", $"{icd_or_diseaseCondition}{drugs}{materialNames}");
asynsDrugquery(sYS_Drugquery, icd_or_diseaseCondition, drugs, materialNames, num, type, zxr);
}
finally
......
......@@ -3,6 +3,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using NPoco;
using QueryPlatform.Api.Infrastructure.Hubs;
using QueryPlatform.Api.Infrastructure.Modules;
using QueryPlatform.Api.Infrastructure.Queries;
......@@ -315,7 +316,12 @@ public IActionResult ceshi()
[HttpPost("city_hosLevel_hosType")]
[AllowAnonymous]
public List<string> city_hosLevel_hosType(string type)
{
return _homeQueries.city_hosLevel_hosType(type);
}
[HttpPost("Cursor")]
[AllowAnonymous]
......
......@@ -152,13 +152,11 @@ public IEnumerable<dynamic> ShowLog(long indexs, string tableName)
/// 拉取流水库数据
/// </summary>
/// <returns></returns>
private static SemaphoreSlim semaphore = new SemaphoreSlim(1, 1);
[HttpPost("PullData")]
[AllowAnonymous]
public async Task PullDataAsync(long indexs, string DatabaseName, string tableName, string zxr)
public Task PullDataAsync(long indexs, string DatabaseName, string tableName, string zxr)
{
resourceQueries.pullstate(indexs, tableName);
await semaphore.WaitAsync();
try
{
resourceQueries.PullData(indexs, DatabaseName, tableName);
......@@ -167,13 +165,11 @@ public IEnumerable<dynamic> ShowLog(long indexs, string tableName)
catch (Exception e)
{
throw e;
}
finally
{
semaphore.Release();
}
}
resourceQueries.Connection(181).Execute($"UPDATE [SV_QueryPlatform].[dbo].[FlowReservoirStatus] SET DataPullTime=getdate() WHERE indexs={indexs} and tableName='{tableName}'");
return Task.CompletedTask;
}
/// <summary>
/// 操作人展示
/// </summary>
......
......@@ -24,11 +24,12 @@ protected override void Load(ContainerBuilder builder)
var Connection155 = configuration["ConnectionStrings:Connection155"];
var Connection156 = configuration["ConnectionStrings:Connection156"];
var Connection158 = configuration["ConnectionStrings:Connection158"];
var lskxc = configuration["ConnectionStrings:lskxc"];
builder.RegisterType<HubNotificationQueue>().SingleInstance();
builder.Register(c => new UserStorage(configConnectionString)).InstancePerLifetimeScope();
builder.Register(c => new UserQueries(configConnectionString)).InstancePerLifetimeScope();
builder.Register(c => new ResourceQueries(Connection156, configConnectionString)).InstancePerLifetimeScope();
builder.Register(c => new ResourceQueries(Connection156, configConnectionString, lskxc)).InstancePerLifetimeScope();
builder.Register(c => new DrugqueryQueries(Connection156, configConnectionString)).InstancePerLifetimeScope();
builder.Register(c => new HomeQueries(configConnectionString, Connection156)).InstancePerLifetimeScope();
builder.Register(c => new AnalysisQueries(Connection156, configConnectionString)).InstancePerLifetimeScope();
......
......@@ -29,9 +29,9 @@ public Job(ILogger<Job> logger, DrugqueryQueries drugqueryQueries, HomeQueries h
{
var day = DateTime.Now.Day;
var time = DateTime.Now.ToString("HH:mm:ss");
if (day == 8 && time == "09:39:01")
if (day == 1 && time == "00:00:01")
{
// _drugqueryQueries.定时执行();
_drugqueryQueries.定时执行();
_homeQueries.SendMail("定时任务", "人群检索表 化验检查检索表合并成功");
}
}
......
......@@ -54,6 +54,9 @@ public class SYS_Hospital
{
public int id { get; set; }
public string HosName { get; set; }
public string City { get; set; }
public string HosLevel { get; set; }
public string HosType { get; set; }
public string ExecOpenLink { get; set; }
public string ExecDatabase { get; set; }
public string DataLoginName { get; set; }
......@@ -447,9 +450,8 @@ public class SYS_LOG
public string 错误sql { get; set; }
}
public class DateExploration
{
public int id { get; set; }
public int Id { get; internal set; }
{
public int Id { get; set; }
public string Name1 { get; set; }
public string Name2 { get; set; }
public string Name3 { get; set; }
......
......@@ -261,7 +261,7 @@ UNION ALL
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);
HomeQueries home = new HomeQueries(_configConnectionString,_Connection156);
HomeQueries home = new HomeQueries(_configConnectionString, _Connection156);
home.SendMail(@$"药品/疾病/材料平台提醒", @$"疾病拉取失败 {icd_or_diseaseCondition} 错误日志:{ex.ToString().Replace("'", "''")}", "唐仲阳");
}
......@@ -342,14 +342,17 @@ public void Drugquery(long typefee, long type1_2, string drugs, string[] drugNam
}
if (Countnum($@"SELECT count(*) FROM [SV_QueryPlatform_].[dbo].[MEDIC_AREA_{Indexs}] where hos_id=cast(right('{item.ExecDatabase}',3)as int) and indexs={Indexs}", configConnection) > 0)
{
var sql3 = $@"IF EXISTS(SELECT * FROM [{item.ExecDatabase}].dbo.SYSOBJECTS WHERE NAME = 'MEDIC_PERSON_INFORMATION_{Indexs}')
var sql3 = "";
if (typefee == 1)
{
sql3 = $@"IF EXISTS(SELECT * FROM [{item.ExecDatabase}].dbo.SYSOBJECTS WHERE NAME = 'MEDIC_PERSON_INFORMATION_{Indexs}')
drop table [{item.ExecDatabase}].[dbo].MEDIC_PERSON_INFORMATION_{Indexs};
SELECT C.MASTER_INDEX,A.PERSON_CODE,A.PERSON_ID,A.REG_CODE,A.REG_ID,'1' REG_SOURCE,
A.REG_TIME,B.ID AREA_ID,{Indexs} INDEXS,cast( RIGHT ( '{item.ExecDatabase}', 3 ) AS int ) HOS_ID,
C.BIRTHDAY,C.SEX,1 TYPE,A.DEPT_NAME into [{item.ExecDatabase}].[dbo].MEDIC_PERSON_INFORMATION_{Indexs}
FROM {item.ExecDatabase}.[dbo].OUT_REG_INFO A
JOIN (SELECT DISTINCT REG_CODE,D.ID FROM {item.ExecDatabase}.[dbo].{mzb} E
join [192.168.18.181].[SV_QueryPlatform_].[dbo].[MEDIC_AREA_{Indexs}] D ON {(typefee == 1 ? "E.ITEM_NAME" : "REPLACE(REPLACE(E.MEDIC_GENERAL_NAME,E.MEDIC_SPEC,''),' ','')")} = D.ITEM_NAME AND ISNULL(E.MEDIC_AREA,'') = ISNULL(D.MEDIC_AREA,'') AND INDEXS={Indexs} AND HOS_ID = cast( RIGHT ( '{item.ExecDatabase}', 3 ) AS int ))B
join [192.168.18.181].[SV_QueryPlatform_].[dbo].[MEDIC_AREA_{Indexs}] D ON E.ITEM_NAME = D.ITEM_NAME AND ISNULL(E.MEDIC_AREA,'') = ISNULL(D.MEDIC_AREA,'') AND INDEXS={Indexs} AND HOS_ID = cast( RIGHT ( '{item.ExecDatabase}', 3 ) AS int ))B
ON A.REG_CODE = B.REG_CODE
JOIN {item.ExecDatabase}.[dbo].PUB_PATIENT C ON A.PERSON_CODE = C.PERSON_CODE
WHERE A.REG_CODE = B.REG_CODE AND A.PERSON_CODE = C.PERSON_CODE
......@@ -359,11 +362,41 @@ UNION ALL
C.BIRTHDAY,C.SEX,1 TYPE,A.OUT_DEPT_NAME
FROM {item.ExecDatabase}.[dbo].INPAT_REG_INFO A
JOIN(SELECT DISTINCT REG_CODE,D.ID FROM {item.ExecDatabase}.[dbo].{zyb} E
JOIN [192.168.18.181].[SV_QueryPlatform_].[dbo].[MEDIC_AREA_{Indexs}] D ON {(typefee == 1 ? "E.ITEM_NAME" : "REPLACE(REPLACE(E.ITEM_NAME,E.MEDIC_SPEC,''),' ','')")} = D.ITEM_NAME
AND ISNULL(E.MEDIC_AREA,'') = ISNULL(D.MEDIC_AREA,'') AND INDEXS={Indexs} AND HOS_ID = cast( RIGHT ( '{item.ExecDatabase}', 3 ) AS int ))B
JOIN [192.168.18.181].[SV_QueryPlatform_].[dbo].[MEDIC_AREA_{Indexs}] D ON E.ITEM_NAME = D.ITEM_NAME AND ISNULL(E.MEDIC_AREA,'') = ISNULL(D.MEDIC_AREA,'') AND INDEXS={Indexs} AND HOS_ID = cast( RIGHT ( '{item.ExecDatabase}', 3 ) AS int ))B
ON A.REG_CODE = B.REG_CODE
JOIN {item.ExecDatabase}.[dbo].PUB_PATIENT C ON A.PERSON_CODE = C.PERSON_CODE
WHERE A.REG_CODE = B.REG_CODE AND A.PERSON_CODE = C.PERSON_CODE";
}
else
{
var outwhere = "";
var inpatwhere = "";
foreach (var drug in drugName)
{
outwhere = outwhere + @$"{(!string.IsNullOrEmpty(outwhere)? " or ":"")} REPLACE(REPLACE(MEDIC_GENERAL_NAME,MEDIC_SPEC,''),' ','') like '%{drug}%'";
inpatwhere = inpatwhere + @$"{(!string.IsNullOrEmpty(inpatwhere) ? " or " : "")} REPLACE(REPLACE(ITEM_NAME,MEDI_SPEC,''),' ','') like '%{drug}%'";
}
sql3 = $@"IF EXISTS(SELECT * FROM [{item.ExecDatabase}].dbo.SYSOBJECTS WHERE NAME = 'MEDIC_PERSON_INFORMATION_{Indexs}')
drop table [{item.ExecDatabase}].[dbo].MEDIC_PERSON_INFORMATION_{Indexs};
SELECT C.MASTER_INDEX,A.PERSON_CODE,A.PERSON_ID,A.REG_CODE,A.REG_ID,'1' REG_SOURCE,
A.REG_TIME,null AREA_ID,{Indexs} INDEXS,cast( RIGHT ( '{item.ExecDatabase}', 3 ) AS int ) HOS_ID,
C.BIRTHDAY,C.SEX,1 TYPE,A.DEPT_NAME into [{item.ExecDatabase}].[dbo].MEDIC_PERSON_INFORMATION_{Indexs}
FROM {item.ExecDatabase}.[dbo].OUT_REG_INFO A
JOIN (SELECT DISTINCT REG_CODE FROM {item.ExecDatabase}.[dbo].{mzb} where {outwhere} )B
ON A.REG_CODE = B.REG_CODE
JOIN {item.ExecDatabase}.[dbo].PUB_PATIENT C ON A.PERSON_CODE = C.PERSON_CODE
WHERE A.REG_CODE = B.REG_CODE AND A.PERSON_CODE = C.PERSON_CODE
UNION
SELECT C.MASTER_INDEX,A.PERSON_CODE,A.PERSON_ID,A.REG_CODE,A.REG_ID,'2' REG_SOURCE,
A.INHOS_TIME,null AREA_ID,{Indexs} INDEXS,cast( RIGHT ( '{item.ExecDatabase}', 3 ) AS int ) HOS_ID,
C.BIRTHDAY,C.SEX,1 TYPE,A.OUT_DEPT_NAME
FROM {item.ExecDatabase}.[dbo].INPAT_REG_INFO A
JOIN(SELECT DISTINCT REG_CODE FROM {item.ExecDatabase}.[dbo].{zyb} where {inpatwhere})B
ON A.REG_CODE = B.REG_CODE
JOIN {item.ExecDatabase}.[dbo].PUB_PATIENT C ON A.PERSON_CODE = C.PERSON_CODE
WHERE A.REG_CODE = B.REG_CODE AND A.PERSON_CODE = C.PERSON_CODE";
}
num = num + conn.Execute(sql3, commandTimeout: 60 * 60 * 5);
......@@ -875,19 +908,19 @@ public void ASSAYREPORT(long index, int id, string item_name = "")
//第一层切割
var sql2 = $@"UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'
','&') prlong('将回车替换&') UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'[','')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,']','')PRlong('将]替换 ')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,' ','`') prlong('将空格替换`')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'`L','') prlong('将 `L 去除')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'`H','') prlong('将 `H 去除')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'`*','') prlong('将 `* 去除')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'`↑','')prlong('将 `↑去除')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'`高','')prlong('将 `高 去除')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'`↓','')prlong('将 `↓去除')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'`低','')prlong('将 `低 去除')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'>','') prlong('将 > 去除')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'<','') prlong('将 < 去除')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=RIGHT(RESULTS,LEN(RESULTS)-1) WHERE LEFT(RESULTS,1)='`' prlong('将第一个字符为 ` 的去除')
','&') print('将回车替换&') UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'[','')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,']','')print('将]替换 ')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,' ','`') print('将空格替换`')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'`L','') print('将 `L 去除')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'`H','') print('将 `H 去除')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'`*','') print('将 `* 去除')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'`↑','')print('将 `↑去除')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'`高','')print('将 `高 去除')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'`↓','')print('将 `↓去除')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'`低','')print('将 `低 去除')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'>','') print('将 > 去除')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'<','') print('将 < 去除')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=RIGHT(RESULTS,LEN(RESULTS)-1) WHERE LEFT(RESULTS,1)='`' print('将第一个字符为 ` 的去除')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'&0','&')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'&1','&') WHERE RESULTS NOT LIKE '&1`'
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'&1`','&')
......@@ -939,8 +972,8 @@ public void ASSAYREPORT(long index, int id, string item_name = "")
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'&47`','&')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'&48`','&')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'&49`','&')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'&50`','&') prlong('将 &1`/2`/3`/4`/5`..... 改为&')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'【互】','') prlong('将 【互】去除')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'&50`','&') print('将 &1`/2`/3`/4`/5`..... 改为&')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'【互】','') print('将 【互】去除')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'``','`') ---20次
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'``','`')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'``','`')
......@@ -961,7 +994,7 @@ public void ASSAYREPORT(long index, int id, string item_name = "")
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'``','`')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'``','`')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'``','`')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'``','`')prlong('将 多个连续``` 改为 `')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'``','`')print('将 多个连续``` 改为 `')
UPDATE dbo.ASSAY_REPORT_TEMP_{index}_{id} SET RESULTS=REPLACE(RESULTS,'&`','&')";
//函数分列,换行
......@@ -1102,7 +1135,7 @@ public void ASSAYREPORT(long index, int id, string item_name = "")
SELECT ORG_CODE,REPORT_ID,REG_CODE, [dbo].[fGetStrBySplit](RESULTS,50,'&')RESULTS FROM dbo.ASSAY_REPORT_TEMP_{index}_{id}
)a WHERE [dbo].[fGetStrBySplit](RESULTS,1,'`') NOT LIKE '%名称%'
AND [dbo].[fGetStrBySplit](RESULTS,1,'`') <>'' AND [dbo].[fGetStrBySplit](RESULTS,1,'`') IS NOT NULL
prlong('临时数据生成中')
print('临时数据生成中')
SELECT * into [dbo].[ASSAY_{index}_{id}] FROM (
SELECT*FROM [dbo].[ASSAY1_{index}_{id}]
......@@ -1122,7 +1155,7 @@ UNION ALL
AND a.ITEM_ENAME NOT LIKE '%审核%'
AND UNIT NOT LIKE '%备注%'
AND a.UNIT NOT LIKE '%标本%';
prlong('临时数据生成完成');";
print('临时数据生成完成');";
connection.Execute(sql, commandTimeout: 60 * 60 * 5);
connection.Execute(sql2, commandTimeout: 60 * 60 * 5);
connection.Execute(sql3, commandTimeout: 60 * 60 * 5);
......
......@@ -1430,6 +1430,25 @@ public List<string> ceshi()
}
public List<string> city_hosLevel_hosType(string type)
{
var dbs = "SELECT city,left(hosLevel,1)hosLevel,hosType FROM [DB_SV_Data_Config].[dbo].[SYS_Hospital] where isnull([ExecOpenLink],'')!='' and isnull([ExecDatabase],'')!=''";
var hoss = Connection(156).Query<SYS_Hospital>(dbs);
if (type == "city")
{
return hoss.Select(s => s.City.Replace(" ","")).Distinct().ToList();
}
else if (type == "hosLevel")
{
return hoss.Select(s => s.HosLevel.Replace(" ", "")).Distinct().ToList();
}
else if (type == "hosType")
{
return hoss.Select(s => s.HosType.Replace(" ", "")).Distinct().ToList();
}
return null;
}
/// <summary>
/// 游标
/// </summary>
......
......@@ -2,7 +2,12 @@
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using HtmlAgilityPack;
using java.sql;
using java.util.concurrent;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Configuration;
using OfficeOpenXml;
using PuppeteerSharp;
using QueryPlatform.Api.Infrastructure.Modules;
using System;
......@@ -22,10 +27,12 @@ public class ResourceQueries
{
private readonly string _Connection156;
private readonly string _configConnectionString;
public ResourceQueries(string Connection156, string configConnectionString)
private readonly string _lskxc;
public ResourceQueries(string Connection156, string configConnectionString, string lskxc)
{
_Connection156 = Connection156;
_configConnectionString = configConnectionString;
_lskxc = lskxc;
}
/// <summary>
/// 查询所有项目
......@@ -98,6 +105,7 @@ public IEnumerable<dynamic> ShowITEM_NAME(int id)
return sj;
}
#region 入参
public class nffb
{
public string n { get; set; }
......@@ -399,13 +407,13 @@ UNION ALL
if (xz == 1)
{
string aa = await ConvertToPdf(htmlContent, PROJECT_NAME);
string aa = await ConvertToExcl(htmlContent, PROJECT_NAME);
return (yearfb, dqfb, condition, PROJECT_NAME, ShowQuery3s, ShowQuery4s, aa, ShowQuery5s);
}
return (yearfb, dqfb, condition, PROJECT_NAME, ShowQuery3s, ShowQuery4s, null, ShowQuery5s);
}
#endregion
/// <summary>
......@@ -491,6 +499,7 @@ public string ConvertHtmlToPdf(string html, string xmname)
return outfilepath + "pdf";
}
public async System.Threading.Tasks.Task<string> ConvertToPdf(string html, string xmname)
{
......@@ -522,6 +531,88 @@ public string ConvertHtmlToPdf(string html, string xmname)
}
public async System.Threading.Tasks.Task<string> ConvertToExcl(string html, string xmname)
{
// 从HTML字符串获取数据表
DataTable dataTable = ConvertHtmlToDataTable(html);
// 将数据表保存为Excel文件
return await SaveDataTableToExcel(dataTable, $@"{fwq}{xmname}人群分布{DateTime.Now.ToString("yyyyMMddHHmmss") + new Random().Next(1000, 9999).ToString()}.xlsx");
}
static DataTable ConvertHtmlToDataTable(string html)
{
DataTable dataTable = new DataTable();
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);
// 从HTML中提取表格数据
var tableNodes = doc.DocumentNode.SelectNodes("//table");
if (tableNodes != null && tableNodes.Count > 0)
{
var headers = tableNodes[0].SelectNodes(".//th");
if (headers != null)
{
foreach (var header in headers)
{
string headerText = header.InnerText.Trim();
if (!string.IsNullOrEmpty(headerText))
{
dataTable.Columns.Add(headerText);
}
}
}
var rows = tableNodes[0].SelectNodes(".//tr");
foreach (var row in rows)
{
DataRow dataRow = dataTable.NewRow();
var cells = row.SelectNodes(".//td");
for (int i = 0; i < cells.Count; i++)
{
string cellText = cells[i].InnerText.Trim();
if (i < dataTable.Columns.Count)
{
dataRow[i] = cellText;
}
}
dataTable.Rows.Add(dataRow);
}
}
return dataTable;
}
public async System.Threading.Tasks.Task<string> SaveDataTableToExcel(DataTable dataTable, string filePath)
{
FileInfo fileInfo = new FileInfo(filePath);
using (ExcelPackage package = new ExcelPackage(fileInfo))
{
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Sheet1");
// 写入列标题
for (int i = 0; i < dataTable.Columns.Count; i++)
{
worksheet.Cells[1, i + 1].Value = dataTable.Columns[i].ColumnName;
}
// 写入行数据
for (int i = 0; i < dataTable.Rows.Count; i++)
{
for (int j = 0; j < dataTable.Columns.Count; j++)
{
worksheet.Cells[i + 2, j + 1].Value = dataTable.Rows[i][j];
}
}
package.Save();
}
string outfilepath = @$"https://lsk.suvalue.com/api/export/export/人群分布报告/{filePath.Replace($@"{fwq}", "")}";
return outfilepath + "xlsx";
}
/// <summary>
/// 创建流水表
/// </summary>
......@@ -1257,218 +1348,10 @@ public DbConnection Connection(long ip, string configConnectionString)
}
/// <summary>
/// 拉取病人表
/// </summary>
public void PullData(long indexs, string DatabaseName, string tableName, string biao, string ip)
{
//Console.WriteLine(ip+""+ biao);
var sql = "";
var where = @$"and ExecOpenLink in ('{ip}')";
sql = @$" select A.*from(
SELECT DISTINCT case when a.id>=112 and a.id<=138 then '112' else ID end 'id',
case when a.id>=112 and a.id<=138 then '192.168.18.152' else ExecOpenLink end 'ExecOpenLink',
case when a.id>=112 and a.id<=138 then 'HOS_631337112' else ExecDatabase end 'ExecDatabase'
FROM [DB_SV_Data_Config].[dbo].[SYS_Hospital] A
JOIN [192.168.18.181].[SV_QueryPlatform].[dbo].[{tableName}] B ON A.ID = B.HOS_ID
)A
LEFT JOIN ( SELECT * FROM [192.168.18.181].[SV_QueryPlatform].[dbo].[SYS_LOG] WHERE INDEXS = {indexs}
AND LOG = '{biao}' and type ='执行中'
) C ON A.ID = CAST(LEFT(RIGHT(C.hos_code, 4),3) AS int)
WHERE hos_code IS NULL {where};
";
List<SYS_Hospital> hospitals = Connection(156).Query<SYS_Hospital>(sql).ToList();
Dictionary<string, object> pairs = new Dictionary<string, object>();
foreach (var hos in hospitals)
{
Console.WriteLine("'" + ip + "','" + hos.ExecDatabase + "','" + biao + "'");
pairs.Clear();
// 存在 // 不存在
pairs.TryAdd($"@{nameof(hos.ExecOpenLink)}", hos.ExecOpenLink);
pairs.TryAdd($"@{nameof(hos.ExecDatabase)}", hos.ExecDatabase);
pairs.TryAdd($"@{nameof(indexs)}", indexs);
pairs.TryAdd($"@{nameof(DatabaseName)}", DatabaseName);
pairs.TryAdd($"@{nameof(tableName)}", tableName);
pairs.TryAdd($"@{nameof(biao)}", biao);
var ITEM = "[@ExecOpenLink].[@ExecDatabase]";
//拉取病人表
Connection(181).Execute($"UPDATE [SV_QueryPlatform].[dbo].[FlowReservoirStatus] SET state =2 ,DataPullTime=getdate() WHERE indexs={indexs} and tableName='{tableName.Replace(" ", "")}'");
//try
//{
long rs = QueryPatient(tableName);
sql = ShowSql($"{biao}", 2)[0];
if (hos.ExecDatabase == "HOS_631337112")
{
sql = sql.Replace("HOS_ID=CAST(RIGHT('@ExecDatabase',3)as int)", "HOS_ID>=112 and HOS_ID<=138");
sql = sql.Replace("ORG_CODE=CAST(RIGHT('@ExecDatabase',3)as int)", "ORG_CODE>=112 and ORG_CODE<=138");
}
foreach (var item1 in pairs)
{
ITEM = ITEM.Replace(item1.Key, item1.Value.ToString());
sql = sql.Replace(item1.Key, item1.Value.ToString());
}
服务器 fwq = Connection(181).Query<服务器>($"SELECT [服务器ip],[数据库账号],[数据库密码] FROM [SV_QueryPlatform].[dbo].[服务器] where[服务器ip] ='{hos.ExecOpenLink}'").FirstOrDefault();
var msConnectionString = string.Format("Server={0};Database={1};User ID={2};Password={3};Trusted_Connection=False;", hos.ExecOpenLink, hos.ExecDatabase, fwq.数据库账号, fwq.数据库密码);
zx(indexs, biao, sql, ITEM, msConnectionString);
//}
//catch (Exception e)
//{
// LOG($"{biao}", ITEM, indexs, "错误", $"报错sql:{sql}错误日志:{e}");
// PullData(indexs, DatabaseName, tableName, biao, ip);//跳过错误执行未执行的医院
//}
Connection(181).Execute($"UPDATE [SV_QueryPlatform].[dbo].[FlowReservoirStatus] SET DataPullTime=getdate() WHERE indexs={indexs} and tableName='{tableName}'");
}
}
public void PullDatalist(long indexs, string DatabaseName, string tableName, string biao, string ip)
{
var sql = "";
var where = @$"and ExecOpenLink in ('{ip}')";
sql = @$" select A.*from(
SELECT DISTINCT case when a.id>=112 and a.id<=138 then '112' else ID end 'id',
case when a.id>=112 and a.id<=138 then '192.168.18.152' else ExecOpenLink end 'ExecOpenLink',
case when a.id>=112 and a.id<=138 then 'HOS_631337112' else ExecDatabase end 'ExecDatabase'
FROM [DB_SV_Data_Config].[dbo].[SYS_Hospital] A
JOIN [192.168.18.181].[SV_QueryPlatform].[dbo].[{tableName}] B ON A.ID = B.HOS_ID
)A
LEFT JOIN ( SELECT * FROM [192.168.18.181].[SV_QueryPlatform].[dbo].[SYS_LOG] WHERE INDEXS = {indexs}
AND LOG = '{biao}' and type ='执行中'
) C ON A.ID = CAST(LEFT(RIGHT(C.hos_code, 4),3) AS int)
WHERE hos_code IS NULL {where};
";
List<SYS_Hospital> hospitals = Connection(156).Query<SYS_Hospital>(sql).ToList();
Dictionary<string, object> pairs = new Dictionary<string, object>();
// 连接字符串 - 源服务器
foreach (var hos in hospitals)
{
Console.WriteLine("'" + ip + "','" + hos.ExecDatabase + "','" + biao + "'");
服务器 fwq = Connection(181).Query<服务器>($"SELECT [服务器ip],[数据库账号],[数据库密码] FROM [SV_QueryPlatform].[dbo].[服务器] where[服务器ip] ='{hos.ExecOpenLink}'").FirstOrDefault();
var sourceConnectionString = string.Format("Server={0};Database={1};User ID={2};Password={3};Trusted_Connection=False;", $@"{hos.ExecOpenLink}", @$"{DatabaseName}", "sa", "Suvalue2016");
// 查询语句
string query = "SELECT Column1, Column2, Column3 FROM SourceTable";
// 存储数据的列表
List<DataRow> dataRows = new List<DataRow>();
using (SqlConnection sourceConnection = new SqlConnection(sourceConnectionString))
{
sourceConnection.Open();
using (SqlCommand command = new SqlCommand(query, sourceConnection))
{
using (SqlDataAdapter adapter = new SqlDataAdapter(command))
{
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
foreach (DataRow row in dataTable.Rows)
{
dataRows.Add(row);
}
}
}
}
using (SqlConnection targetConnection = new SqlConnection(string.Format("Server={0};Database={1};User ID={2};Password={3};Trusted_Connection=False;", "192.168.18.181", @$"{DatabaseName}", "sa", "Suvalue2016")))
{
targetConnection.Open();
using (SqlTransaction transaction = targetConnection.BeginTransaction())
{
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(targetConnection, SqlBulkCopyOptions.Default, transaction))
{
bulkCopy.DestinationTableName = "TargetTable";
// 设置列映射(如果源表和目标表列名不完全相同)
bulkCopy.ColumnMappings.Add("Column1", "Column1");
bulkCopy.ColumnMappings.Add("Column2", "Column2");
bulkCopy.ColumnMappings.Add("Column3", "Column3");
try
{
// 将数据逐行批量插入到目标表
bulkCopy.WriteToServer(dataRows.ToArray());
transaction.Commit();
Console.WriteLine("数据插入成功!");
}
catch (Exception ex)
{
transaction.Rollback();
Console.WriteLine("数据插入失败:" + ex.Message);
}
}
}
}
}
}
//控制每次执行sql条数
private static SemaphoreSlim semaphoreZX = new SemaphoreSlim(8, 8);
private void zx(long indexs, string biao, string sql, string ITEM, string msConnectionString)
{
semaphoreZX.WaitAsync();
long num = 0;
Exception e = null;
LOG($"{biao}", ITEM, indexs, "执行中", "");
try
{
num = Connection(0, msConnectionString).Execute(sql, commandTimeout: 60 * 60 * 60 * 5);
}
catch (Exception ex)
{
e = ex;
num = -1;
}
finally
{
semaphoreZX.Release();
}
if (num != -1)
{
LOG($"{biao}", ITEM, indexs, "成功", sql);
}
else
{
LOG($"{biao}", ITEM, indexs, "错误", $"报错sql:{sql}错误日志:{e}");
}
/// </summary>
}
public void pullstate(long indexs, string tableName)
{
Connection(181).Execute(@$"
delete [SV_QueryPlatform].[dbo].[SYS_LOG] from [SV_QueryPlatform].[dbo].[SYS_LOG] a
join
(
SELECT
a.INDEXS,a.hos_code, a.log, a.type
FROM (select *from [SV_QueryPlatform].[dbo].[SYS_LOG] where indexs ={indexs} and type='执行中')a
left join (select *from [SV_QueryPlatform].[dbo].[SYS_LOG] where indexs ={indexs} and type='成功 ') b on a.hos_code=b.hos_code and a.log=b.LOG
where b.type is null
) b on a.hos_code=b.hos_code and a.LOG=b.log and a.INDEXS=b.indexs
where a.indexs ={indexs} and a.type='执行中';
UPDATE [SV_QueryPlatform].[dbo].[FlowReservoirStatus] SET state =10 ,DataPullTime=getdate() WHERE indexs={indexs} and tableName='{tableName.Replace(" ", "")}'");
}
private void 执行加日志(long indexs, string biao, string sql, string ITEM)
{
Connection(181).Execute(sql, commandTimeout: 60 * 60 * 60 * 5);
LOG($"{biao}", ITEM, indexs, "成功", sql);
}
/// <summary>
/// 多线程拉取病人表
/// </summary>
/// <param name="indexs"></param>
/// <param name="DatabaseName"></param>
/// <param name="tableName"></param>
/// <returns></returns>
#region 拉取流水库
public void PullData(long indexs, string DatabaseName, string tableName)
{
//写一个 人群表查询人数
......@@ -1499,11 +1382,11 @@ public void PullData(long indexs, string DatabaseName, string tableName)
//修复执行错误方法
try
{
PullData修复超时错误(indexs);
// PullData修复超时错误(indexs);
}
catch (Exception e)
{
LOG($"修复超时错误", "修复超时错误", indexs, "修复失败", $"报错:{e}");
// LOG($"修复超时错误", "修复超时错误", indexs, "修复失败", $"报错:{e}");
}
finally
{
......@@ -1595,11 +1478,364 @@ UPDATE @DBName.dbo.ASSAY_REPORT
SET REG_ID = B.REG_ID
FROM @DBName.dbo.INPAT_REG_INFO B
WHERE @DBName.dbo.ASSAY_REPORT.REG_CODE = B.REG_CODE AND @DBName.dbo.ASSAY_REPORT.ORG_CODE = B.ORG_CODE AND REG_SOURCE = 2; ".Replace("@DBName", DatabaseName);
Connection(181).Execute(sql, commandTimeout: 60 * 60 * 60 * 5);//拉取完成
//Connection(181).Execute(sql, commandTimeout: 60 * 60 * 60 * 5);//拉取完成
}
Connection(181).Execute($"UPDATE [SV_QueryPlatform].[dbo].[FlowReservoirStatus] SET state =5 WHERE indexs={indexs} and tableName='{tableName.Replace(" ", "")}'");//拉取完成
}
public async void PullData(long indexs, string DatabaseName, string tableName, string biao, string ip)
{
//Console.WriteLine(ip+""+ biao);
var sql = "";
var where = @$"and ExecOpenLink in ('{ip}')";
sql = @$" select A.*from(
SELECT DISTINCT case when a.id>=112 and a.id<=138 then '112' else ID end 'id',
case when a.id>=112 and a.id<=138 then '192.168.18.152' else ExecOpenLink end 'ExecOpenLink',
case when a.id>=112 and a.id<=138 then 'HOS_631337112' else ExecDatabase end 'ExecDatabase'
FROM [DB_SV_Data_Config].[dbo].[SYS_Hospital] A
JOIN [192.168.18.181].[SV_QueryPlatform].[dbo].[{tableName}] B ON A.ID = B.HOS_ID
)A
LEFT JOIN ( SELECT * FROM [192.168.18.181].[SV_QueryPlatform].[dbo].[SYS_LOG] WHERE INDEXS = {indexs}
AND LOG = '{biao}' and type ='执行中'
) C ON A.ID = CAST(LEFT(RIGHT(C.hos_code, 4),3) AS int)
WHERE hos_code IS NULL {where};
";
List<SYS_Hospital> hospitals = Connection(156).Query<SYS_Hospital>(sql).ToList();
Dictionary<string, object> pairs = new Dictionary<string, object>();
foreach (var hos in hospitals)
{
//Console.WriteLine("'" + ip + "','" + hos.ExecDatabase + "','" + biao + "'");
pairs.Clear();
// 存在 // 不存在
pairs.TryAdd($"@{nameof(hos.ExecOpenLink)}", hos.ExecOpenLink);
pairs.TryAdd($"@{nameof(hos.ExecDatabase)}", hos.ExecDatabase);
pairs.TryAdd($"@{nameof(indexs)}", indexs);
pairs.TryAdd($"@{nameof(DatabaseName)}", DatabaseName);
pairs.TryAdd($"@{nameof(tableName)}", tableName);
pairs.TryAdd($"@{nameof(biao)}", biao);
var ITEM = "[@ExecOpenLink].[@ExecDatabase]";
//拉取病人表
Connection(181).Execute($"UPDATE [SV_QueryPlatform].[dbo].[FlowReservoirStatus] SET state =2 ,DataPullTime=getdate() WHERE indexs={indexs} and tableName='{tableName.Replace(" ", "")}'");
//try
//{
long rs = QueryPatient(tableName);
sql = ShowSql($"{biao}", 2)[0];
if (hos.ExecDatabase == "HOS_631337112")
{
sql = sql.Replace("HOS_ID=CAST(RIGHT('@ExecDatabase',3)as int)", "HOS_ID>=112 and HOS_ID<=138");
sql = sql.Replace("ORG_CODE=CAST(RIGHT('@ExecDatabase',3)as int)", "ORG_CODE>=112 and ORG_CODE<=138");
}
foreach (var item1 in pairs)
{
ITEM = ITEM.Replace(item1.Key, item1.Value.ToString());
sql = sql.Replace(item1.Key, item1.Value.ToString());
}
服务器 fwq = Connection(181).Query<服务器>($"SELECT [服务器ip],[数据库账号],[数据库密码] FROM [SV_QueryPlatform].[dbo].[服务器] where[服务器ip] ='{hos.ExecOpenLink}'").FirstOrDefault();
var msConnectionString = string.Format("Server={0};Database={1};User ID={2};Password={3};Trusted_Connection=False;", hos.ExecOpenLink, hos.ExecDatabase, fwq.数据库账号, fwq.数据库密码);
if (biao == "PUB_PATIENT") { 病人信息zx(indexs, biao, sql, ITEM, msConnectionString); }
if (biao == "OUT_REG_INFO") { 门诊登记zx(indexs, biao, sql, ITEM, msConnectionString); }
if (biao == "INPAT_REG_INFO") { 住院登记zx(indexs, biao, sql, ITEM, msConnectionString); }
if (biao == "OUT_DIAG") { 门诊诊断zx(indexs, biao, sql, ITEM, msConnectionString); }
if (biao == "INPAT_DIAG") { 住院诊断zx(indexs, biao, sql, ITEM, msConnectionString); }
if (biao == "OUT_FEE") { 门诊费用zx(indexs, biao, sql, ITEM, msConnectionString); }
if (biao == "INPAT_FEE") { 住院费用zx(indexs, biao, sql, ITEM, msConnectionString); }
if (biao == "OUT_PRES") { 门诊处方zx(indexs, biao, sql, ITEM, msConnectionString); }
if (biao == "INPAT_ORDER") { 住院医嘱zx(indexs, biao, sql, ITEM, msConnectionString); }
if (biao == "ASSAY_REPORT") { 化验zx(indexs, biao, sql, ITEM, msConnectionString); }
if (biao == "EXEC_REPORT") { 检查zx(indexs, biao, sql, ITEM, msConnectionString); }
if (biao == "OPS_INFO") { 手术zx(indexs, biao, sql, ITEM, msConnectionString); }
Connection(181).Execute($"UPDATE [SV_QueryPlatform].[dbo].[FlowReservoirStatus] SET DataPullTime=getdate() WHERE indexs={indexs} and tableName='{tableName}'");
}
}
//控制每次执行sql条数
private static SemaphoreSlim 病人信息 = new SemaphoreSlim(6);
private void 病人信息zx(long indexs, string biao, string sql, string ITEM, string msConnectionString)
{
病人信息.Wait();
try
{
Console.WriteLine(@$"正在执行{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "执行中", "");
Connection(0, msConnectionString).Execute(sql, commandTimeout: 60 * 60 * 60 * 5);
Console.WriteLine(@$"执行结数{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "成功", sql);
}
catch (Exception ex)
{
LOG($"{biao}", ITEM, indexs, "错误", $"报错sql:{sql}错误日志:{ex}");
}
finally
{
病人信息.Release();
}
}
private static SemaphoreSlim 门诊登记 = new SemaphoreSlim(4);
private void 门诊登记zx(long indexs, string biao, string sql, string ITEM, string msConnectionString)
{
门诊登记.Wait();
try
{
Console.WriteLine(@$"正在执行{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "执行中", "");
Connection(0, msConnectionString).Execute(sql, commandTimeout: 60 * 60 * 60 * 5);
Console.WriteLine(@$"执行结数{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "成功", sql);
}
catch (Exception ex)
{
LOG($"{biao}", ITEM, indexs, "错误", $"报错sql:{sql}错误日志:{ex}");
}
finally
{
门诊登记.Release();
}
}
private static SemaphoreSlim 住院登记 = new SemaphoreSlim(4);
private void 住院登记zx(long indexs, string biao, string sql, string ITEM, string msConnectionString)
{
住院登记.Wait();
try
{
Console.WriteLine(@$"正在执行{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "执行中", "");
Connection(0, msConnectionString).Execute(sql, commandTimeout: 60 * 60 * 60 * 5);
Console.WriteLine(@$"执行结数{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "成功", sql);
}
catch (Exception ex)
{
LOG($"{biao}", ITEM, indexs, "错误", $"报错sql:{sql}错误日志:{ex}");
}
finally
{
住院登记.Release();
}
}
private static SemaphoreSlim 门诊诊断 = new SemaphoreSlim(2);
private void 门诊诊断zx(long indexs, string biao, string sql, string ITEM, string msConnectionString)
{
门诊诊断.Wait();
try
{
Console.WriteLine(@$"正在执行{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "执行中", "");
Connection(0, msConnectionString).Execute(sql, commandTimeout: 60 * 60 * 60 * 5);
Console.WriteLine(@$"执行结数{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "成功", sql);
}
catch (Exception ex)
{
LOG($"{biao}", ITEM, indexs, "错误", $"报错sql:{sql}错误日志:{ex}");
}
finally
{
门诊诊断.Release();
}
}
private static SemaphoreSlim 住院诊断 = new SemaphoreSlim(3);
private void 住院诊断zx(long indexs, string biao, string sql, string ITEM, string msConnectionString)
{
住院诊断.Wait();
try
{
Console.WriteLine(@$"正在执行{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "执行中", "");
Connection(0, msConnectionString).Execute(sql, commandTimeout: 60 * 60 * 60 * 5);
Console.WriteLine(@$"执行结数{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "成功", sql);
}
catch (Exception ex)
{
LOG($"{biao}", ITEM, indexs, "错误", $"报错sql:{sql}错误日志:{ex}");
}
finally
{
住院诊断.Release();
}
}
private static SemaphoreSlim 门诊费用 = new SemaphoreSlim(2);
private void 门诊费用zx(long indexs, string biao, string sql, string ITEM, string msConnectionString)
{
门诊费用.Wait();
try
{
Console.WriteLine(@$"正在执行{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "执行中", "");
Connection(0, msConnectionString).Execute(sql, commandTimeout: 60 * 60 * 60 * 5);
Console.WriteLine(@$"执行结数{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "成功", sql);
}
catch (Exception ex)
{
LOG($"{biao}", ITEM, indexs, "错误", $"报错sql:{sql}错误日志:{ex}");
}
finally
{
门诊费用.Release();
}
}
private static SemaphoreSlim 住院费用 = new SemaphoreSlim(2);
private void 住院费用zx(long indexs, string biao, string sql, string ITEM, string msConnectionString)
{
住院费用.Wait();
try
{
Console.WriteLine(@$"正在执行{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "执行中", "");
Connection(0, msConnectionString).Execute(sql, commandTimeout: 60 * 60 * 60 * 5);
Console.WriteLine(@$"执行结数{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "成功", sql);
}
catch (Exception ex)
{
LOG($"{biao}", ITEM, indexs, "错误", $"报错sql:{sql}错误日志:{ex}");
}
finally
{
住院费用.Release();
}
}
private static SemaphoreSlim 门诊处方 = new SemaphoreSlim(2);
private void 门诊处方zx(long indexs, string biao, string sql, string ITEM, string msConnectionString)
{
门诊处方.Wait();
try
{
Console.WriteLine(@$"正在执行{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "执行中", "");
Connection(0, msConnectionString).Execute(sql, commandTimeout: 60 * 60 * 60 * 5);
Console.WriteLine(@$"执行结数{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "成功", sql);
}
catch (Exception ex)
{
LOG($"{biao}", ITEM, indexs, "错误", $"报错sql:{sql}错误日志:{ex}");
}
finally
{
门诊处方.Release();
}
}
private static SemaphoreSlim 住院医嘱 = new SemaphoreSlim(2);
private void 住院医嘱zx(long indexs, string biao, string sql, string ITEM, string msConnectionString)
{
住院医嘱.Wait();
try
{
Console.WriteLine(@$"正在执行{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "执行中", "");
Connection(0, msConnectionString).Execute(sql, commandTimeout: 60 * 60 * 60 * 5);
Console.WriteLine(@$"执行结数{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "成功", sql);
}
catch (Exception ex)
{
LOG($"{biao}", ITEM, indexs, "错误", $"报错sql:{sql}错误日志:{ex}");
}
finally
{
住院医嘱.Release();
}
}
private static SemaphoreSlim 化验 = new SemaphoreSlim(2);
private void 化验zx(long indexs, string biao, string sql, string ITEM, string msConnectionString)
{
化验.Wait();
try
{
Console.WriteLine(@$"正在执行{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "执行中", "");
Connection(0, msConnectionString).Execute(sql, commandTimeout: 60 * 60 * 60 * 5);
Console.WriteLine(@$"执行结数{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "成功", sql);
}
catch (Exception ex)
{
LOG($"{biao}", ITEM, indexs, "错误", $"报错sql:{sql}错误日志:{ex}");
}
finally
{
化验.Release();
}
}
private static SemaphoreSlim 检查 = new SemaphoreSlim(3);
private void 检查zx(long indexs, string biao, string sql, string ITEM, string msConnectionString)
{
检查.Wait();
try
{
Console.WriteLine(@$"正在执行{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "执行中", "");
Connection(0, msConnectionString).Execute(sql, commandTimeout: 60 * 60 * 60 * 5);
Console.WriteLine(@$"执行结数{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "成功", sql);
}
catch (Exception ex)
{
LOG($"{biao}", ITEM, indexs, "错误", $"报错sql:{sql}错误日志:{ex}");
}
finally
{
检查.Release();
}
}
private static SemaphoreSlim 手术 = new SemaphoreSlim(3);
private void 手术zx(long indexs, string biao, string sql, string ITEM, string msConnectionString)
{
手术.Wait();
try
{
Console.WriteLine(@$"正在执行{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "执行中", "");
Connection(0, msConnectionString).Execute(sql, commandTimeout: 60 * 60 * 60 * 5);
Console.WriteLine(@$"执行结数{ITEM}{biao}");
LOG($"{biao}", ITEM, indexs, "成功", sql);
}
catch (Exception ex)
{
LOG($"{biao}", ITEM, indexs, "错误", $"报错sql:{sql}错误日志:{ex}");
}
finally
{
手术.Release();
}
}
public void pullstate(long indexs, string tableName)
{
Connection(181).Execute(@$"
delete [SV_QueryPlatform].[dbo].[SYS_LOG] from [SV_QueryPlatform].[dbo].[SYS_LOG] a
join
(
SELECT
a.INDEXS,a.hos_code, a.log, a.type
FROM (select *from [SV_QueryPlatform].[dbo].[SYS_LOG] where indexs ={indexs} and type='执行中')a
left join (select *from [SV_QueryPlatform].[dbo].[SYS_LOG] where indexs ={indexs} and type='成功 ') b on a.hos_code=b.hos_code and a.log=b.LOG
where b.type is null
) b on a.hos_code=b.hos_code and a.LOG=b.log and a.INDEXS=b.indexs
where a.indexs ={indexs} and a.type='执行中';
UPDATE [SV_QueryPlatform].[dbo].[FlowReservoirStatus] SET state =10 ,DataPullTime=getdate() WHERE indexs={indexs} and tableName='{tableName.Replace(" ", "")}'");
}
#endregion
private void 执行加日志(long indexs, string biao, string sql, string ITEM)
{
Connection(181).Execute(sql, commandTimeout: 60 * 60 * 60 * 5);
LOG($"{biao}", ITEM, indexs, "成功", sql);
}
/// <summary>
/// 多线程拉取病人表
/// </summary>
/// <param name="indexs"></param>
/// <param name="DatabaseName"></param>
/// <param name="tableName"></param>
/// <returns></returns>
public void PullData修复超时错误(long indexs)
{
DbConnection connection = new SqlConnection(_configConnectionString);
......@@ -1631,7 +1867,7 @@ public long QueryPatient(string tableName)
public List<服务器> 标准库fwq()
{
DbConnection connection = new SqlConnection(_configConnectionString);
return connection.Query<服务器>($@"SELECT * FROM [SV_QueryPlatform].[dbo].[服务器] where type='标准库'").ToList();
return connection.Query<服务器>($@"SELECT * FROM [SV_QueryPlatform].[dbo].[服务器]").ToList();
}
}
......
......@@ -4,9 +4,9 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DeleteExistingFiles>True</DeleteExistingFiles>
<ExcludeApp_Data>False</ExcludeApp_Data>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<DeleteExistingFiles>true</DeleteExistingFiles>
<ExcludeApp_Data>false</ExcludeApp_Data>
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<PublishProvider>FileSystem</PublishProvider>
......@@ -15,6 +15,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<SiteUrlToLaunchAfterPublish />
<TargetFramework>netcoreapp3.1</TargetFramework>
<ProjectGuid>e9d630a1-10fd-4dcf-abc2-d827dd79d8d4</ProjectGuid>
<SelfContained>false</SelfContained>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -21,7 +21,8 @@
"Connection155": "Server=192.168.18.155;Database=DB_SV_Data_Config;User ID=sa;Password=Suvalue2016;Trusted_Connection=False;",
"Connection156": "Server=192.168.18.156;Database=DB_SV_Data_Config;User ID=sa;Password=srv@Ashersa;Trusted_Connection=False;",
"Connection158": "Server=192.168.18.158;Database=DB_SV_Data_Config;User ID=sa;Password=Suvalue2016;Trusted_Connection=False;",
"pg":"Host=192.168.18.185;Port=5432;Username=postgres;Password=Suvalue2016;Database=db_QueryPlatformcare_drgs;"
"pg": "Host=192.168.18.185;Port=5432;Username=postgres;Password=Suvalue2016;Database=db_QueryPlatformcare_drgs;",
"lskxc": "4"
}
}
......
......@@ -198,7 +198,7 @@
</summary>
<returns></returns>
</member>
<member name="F:QueryPlatform.Api.Controllers.ResourceController.semaphore">
<member name="M:QueryPlatform.Api.Controllers.ResourceController.PullDataAsync(System.Int64,System.String,System.String,System.String)">
<summary>
拉取流水库数据
</summary>
......@@ -442,7 +442,7 @@
创建流水库
</summary>
</member>
<member name="M:QueryPlatform.Api.Infrastructure.Queries.ResourceQueries.PullData(System.Int64,System.String,System.String,System.String,System.String)">
<member name="F:QueryPlatform.Api.Infrastructure.Queries.ResourceQueries.lskmaxxc">
<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