Commit 0e46ff0b by tangzhongyang

1

parent 272deee2
<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": "*"
}
...@@ -215,7 +215,7 @@ public IActionResult Update(DATAEXTRACT dataExtract) ...@@ -215,7 +215,7 @@ public IActionResult Update(DATAEXTRACT dataExtract)
//网站拉取json //网站拉取json
[HttpPost("Ybyp")] [HttpPost("Ybyp")]
[AllowAnonymous] [AllowAnonymous]
public async Task<IActionResult> Ybyp( int dqy,int zys) public async Task<IActionResult> Ybyp(int dqy, int zys)
{ {
for (long i = dqy; i <= zys; i++) for (long i = dqy; i <= zys; i++)
{ {
...@@ -312,6 +312,16 @@ public IActionResult ceshi() ...@@ -312,6 +312,16 @@ public IActionResult ceshi()
return Ok(_homeQueries.ceshi()); return Ok(_homeQueries.ceshi());
} }
}
[HttpPost("Cursor")]
[AllowAnonymous]
public string Cursor([FromBody] CursorModel Sql)
{
return _homeQueries.Cursor(Sql);
}
}
} }
\ No newline at end of file
...@@ -103,6 +103,27 @@ public class SYS_YIYUAN ...@@ -103,6 +103,27 @@ public class SYS_YIYUAN
public long hosid { get; set; } public long hosid { get; set; }
public string hosname { get; set; } public string hosname { get; set; }
} }
public class CursorModel
{
/// <summary>
/// 地区
/// </summary>
public string City { get; set; }
/// <summary>
/// 医院等级
/// </summary>
public string HosLevel { get; set; }
/// <summary>
/// 医院类型
/// </summary>
public string HosType { get; set; }
/// <summary>
/// 执行sql
/// </summary>
public string ExecuteSql { get; set; }
}
public class DATAEXTRACT public class DATAEXTRACT
{ {
public long HOS_ID { get; set; } public long HOS_ID { get; set; }
......
...@@ -1413,6 +1413,46 @@ public List<string> ceshi() ...@@ -1413,6 +1413,46 @@ public List<string> ceshi()
} }
/// <summary>
/// 游标
/// </summary>
/// <returns></returns>
public string Cursor(CursorModel model)
{
var dbs = "SELECT * FROM [DB_SV_Data_Config].[dbo].[SYS_Hospital] where isnull([ExecOpenLink],'')!='' and isnull([ExecDatabase],'')!=''";
string Return = @"执行结束";
string condition = "";
if (string.IsNullOrEmpty(model.ExecuteSql))
{
Return = "请填写全!";
return Return;
}
if (!string.IsNullOrEmpty(model.City))
{
dbs = dbs + $" and City like '%{model.City}%'";
condition = "医院区域:" + model.City;
}
if (!string.IsNullOrEmpty(model.HosLevel))
{
dbs = dbs + $" and HosLevel like '%{model.HosLevel}%'";
condition = condition+(string.IsNullOrEmpty(condition)?("医院等级:" + model.City): (@"
医院等级:" + model.HosLevel));
}
if (!string.IsNullOrEmpty(model.HosType))
{
condition = condition+(string.IsNullOrEmpty(condition) ? ("医院类型:" + model.HosType) : (@"
医院类型:" + model.HosType));
}
return condition+Return;
}
} }
......
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