Commit 272deee2 by tangzhongyang

1

parent af0984c3
......@@ -71,12 +71,12 @@ public AnalysisController(IMemoryCache cache, AnalysisQueries aQueries, HomeQuer
}
if (sys_.num <= 5)
{
_aQueries.updateztZ(id, sys_.hosid, "--5匹配更新标准库 DIC_DRUG_ATC的标准字段");
_aQueries.updateztZ(id, sys_.hosid, "--5匹配更新标准库DIC_DRUG_ATC的标准字段");
_aQueries.JX_DIC_DRUG_ATC(id, sys_.hosid);//5匹配更新标准库 DIC_DRUG_ATC的标准字段
}
if (sys_.num <= 6)
{
_aQueries.updateztZ(id, sys_.hosid, "--6未匹配上的导入 [dbo].[DA_Drug] 做处理");
_aQueries.updateztZ(id, sys_.hosid, "--6未匹配上的导入DA_Drug 做处理");
_aQueries.JX_ADD_DA_Drug(id, sys_.hosid);//6未匹配上的导入 [dbo].[DA_Drug] 做处理
}
if (sys_.num <= 7)
......@@ -91,7 +91,7 @@ public AnalysisController(IMemoryCache cache, AnalysisQueries aQueries, HomeQuer
}
if (sys_.num <= 9)
{
_aQueries.updateztZ(id, sys_.hosid, "--9新导入的诊断跑权重,生成标准科室,标准一级诊断,标准二级诊断");
_aQueries.updateztZ(id, sys_.hosid, "--9新导入的诊断跑权重,生成标准科室,标准一级诊断,标准二级诊断");
_aQueries.JX_DIAGNOSIS_DATA_QZ(sys_.hosid);//9新导入的诊断跑权重,生成标准科室,标准一级诊断,标准二级诊断
}
if (sys_.num <= 10)
......@@ -111,7 +111,7 @@ public AnalysisController(IMemoryCache cache, AnalysisQueries aQueries, HomeQuer
}
if (sys_.num <= 13)
{
_aQueries.updateztZ(id, sys_.hosid, "--13医保(1--插入card_type表,2--更改SOURCE ,3--修改登记表i_card_type)");
_aQueries.updateztZ(id, sys_.hosid, "--13医保(1插入card_type表,2更改SOURCE,3修改登记表i_card_type)");
_aQueries.JX_REMOVE_CARD_TYPE(id, sys_.hosid);//13医保(1--插入card_type表,2--更改SOURCE ,3--修改登记表i_card_type)
}
if (sys_.num <= 14)
......@@ -136,10 +136,6 @@ public AnalysisController(IMemoryCache cache, AnalysisQueries aQueries, HomeQuer
{
semaphore.Release();
}
}
/// <summary>
/// 下拉框
......
......@@ -31,61 +31,92 @@ public DrugqueryController(DrugqueryQueries drugqueryQueries, HomeQueries homeQu
{
var icd_or_diseaseCondition = "";
var notdisease = "";
var notdrugs = "";
var notmaterialName = "";
long type = 0;
long num = 0;
var drugs = "";
var materialNames = "";
//icd 诊断
if (sYS_Drugquery.icd != null)
{
foreach (var icdname in sYS_Drugquery.icd)
{
if (!string.IsNullOrEmpty(icdname))
if (!string.IsNullOrEmpty(icdname) & !icdname.Contains("!") & !icdname.Contains("!"))
icd_or_diseaseCondition = icd_or_diseaseCondition + $"or icd like '%{icdname}%'";
if (!string.IsNullOrEmpty(icdname) & (icdname.Contains("!") || icdname.Contains("!")))
notdisease = notdisease + $"and icd not like '%{icdname.Replace("!", "").Replace("!", "")}%'";
}
}
if (sYS_Drugquery.diseaseName != null)
{
foreach (var disease in sYS_Drugquery.diseaseName)
{
if (!string.IsNullOrEmpty(disease)& !disease.Contains("!"))
if (!string.IsNullOrEmpty(disease) & !disease.Contains("!") & !disease.Contains("!"))
{
icd_or_diseaseCondition = icd_or_diseaseCondition + $"or DISEASE_NAME like '%{disease}%'";
if (!string.IsNullOrEmpty(disease) & disease.Contains("!"))
notdisease = notdisease + $"and DISEASE_NAME not like '%{disease.Replace("!","").Replace("!", "")}%'";
}
else
{
notdisease = notdisease + $"and DISEASE_NAME not like '%{disease.Replace("!", "").Replace("!", "")}%'";
}
}
}
if (icd_or_diseaseCondition.Length > 0)
{
icd_or_diseaseCondition = icd_or_diseaseCondition.Substring(2, icd_or_diseaseCondition.Length - 2);
if (notdisease.Length > 0)
icd_or_diseaseCondition = "(" + icd_or_diseaseCondition + ")" + notdisease;
}
//药品
if (sYS_Drugquery.drugName != null)
{
foreach (var drug in sYS_Drugquery.drugName)
{
if (!string.IsNullOrEmpty(drug))
if (!string.IsNullOrEmpty(drug) & !drug.Contains("!") & !drug.Contains("!"))
{
drugs = drugs + $"or item_name like '%{drug}%'";
}
else
{
notdrugs = notdrugs + $"and item_name not like '%{drug.Replace("!", "").Replace("!", "")}%'";
}
}
}
if (drugs.Length > 0)
{
drugs = drugs.Substring(2, drugs.Length - 2);
if (notdrugs.Length > 0)
drugs = "(" + drugs + ")" + notdrugs;
}
//材料
if (sYS_Drugquery.materialName != null)
{
foreach (var materialname in sYS_Drugquery.materialName)
{
if (!string.IsNullOrEmpty(materialname))
if (!string.IsNullOrEmpty(materialname) & !materialname.Contains("!") & !materialname.Contains("!"))
{
materialNames = materialNames + $"or item_name like '%{materialname}%'";
}
else
{
notmaterialName = notmaterialName + $"and item_name not like '%{materialname.Replace("!", "").Replace("!", "")}%'";
}
}
}
if (materialNames.Length > 0)
{
materialNames = materialNames.Substring(2, materialNames.Length - 2);
if (notmaterialName.Length > 0)
materialNames = "(" + materialNames + ")" + notmaterialName;
}
if (!string.IsNullOrEmpty(icd_or_diseaseCondition) && string.IsNullOrEmpty(drugs) && string.IsNullOrEmpty(materialNames))
{
type = 1;//1疾病
......
......@@ -8,6 +8,8 @@
using QueryPlatform.Api.Infrastructure.Queries;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
......@@ -211,33 +213,34 @@ public IActionResult Update(DATAEXTRACT dataExtract)
}
//网站拉取json
//[HttpPost("Ybyp")]
//[AllowAnonymous]
//public async Task<IActionResult> Ybyp()
//{
// for (long i = 1188; i <= 2104; i++)
// {
// var client = new HttpClient();
// var request = new HttpRequestMessage
// {
// Method = HttpMethod.Post,
// RequestUri = new Uri("https://code.nhsa.gov.cn/yp/getPublishGoodsDataInfo.html?companyNameSc=&registeredProductName=&approvalCode=&batchNumber=20220920&_search=false&nd=1663825733775&rows=100&page="+i+"&sidx=&sord=asc"),
// Content = new StringContent("{\r\n\"companyNameSc\":null,\r\n\"registeredProductName\": null,\r\n\"approvalCode\": null,\r\n\"batchNumber\": \"20220920\",\r\n\"_search\": false,\r\n\"nd\": \"1663825733775\",\r\n\"rows\": 100,\r\n\"page\": "+i+",\r\n\"sidx\":null,\r\n\"sord\": \"asc\",\r\n}")
// {
// Headers = { ContentType = new MediaTypeHeaderValue("text/plain") }
// }
// };
// using (var response = await client.SendAsync(request))
// {
// response.EnsureSuccessStatusCode();
// var body = await response.Content.ReadAsStringAsync();
[HttpPost("Ybyp")]
[AllowAnonymous]
public async Task<IActionResult> Ybyp( int dqy,int zys)
{
for (long i = dqy; i <= zys; i++)
{
var client = new HttpClient();
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("https://code.nhsa.gov.cn/yp/getPublishGoodsDataInfo.html?companyNameSc=&registeredProductName=&approvalCode=&batchNumber=20220920&_search=false&nd=1663825733775&rows=100&page=" + i + "&sidx=&sord=asc"),
Content = new StringContent("{\r\n\"companyNameSc\":null,\r\n\"registeredProductName\": null,\r\n\"approvalCode\": null,\r\n\"batchNumber\": \"20220920\",\r\n\"_search\": false,\r\n\"nd\": \"1663825733775\",\r\n\"rows\": 100,\r\n\"page\": " + i + ",\r\n\"sidx\":null,\r\n\"sord\": \"asc\",\r\n}")
{
Headers = { ContentType = new MediaTypeHeaderValue("text/plain") }
}
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync();
_homeQueries.Ybyp(body, i);
}
// _homeQueries.Ybyp(body, i);
// }
// }
// return Ok();
//}
}
return Ok();
}
/// <summary>
/// 邮箱推送
/// </summary>
......
......@@ -54,22 +54,36 @@ public IEnumerable<dynamic> JxLx()
{
where = where + " and id =" + hos_id;
}
IEnumerable<dynamic> sj = Connection(181).Query($@"select*FROM(
SELECT ROW_NUMBER() OVER(ORDER BY ts desc,解析 )AS id,* FROM(SELECT
A.[ID] 编号,[HosName] 医院名称,[HosLevel] 医院等级,[HosType] 医院类型,[ExecOpenLink] 服务器,[ExecDatabase] 数据库, Replace([Province],' ','') 省份,
Replace([Region],' ','') 市, Replace([City],' ','') 区, (SELECT concat('执行人:',czr,' 当前状态:',status,case when ts <>'' and ts is not null then concat(' 提示:',ts) else '' end ) FROM [dbo].[解析任务] where hos_id =a.id
and ksdate=(select max(ksdate ) from [dbo].[解析任务] where hos_id =a.id)) 解析日志 ,
case
when (SELECT status FROM [SV_QueryPlatform].[dbo].[解析任务] where hos_id =a.id and ksdate=(select max(ksdate ) from [dbo].[解析任务] where hos_id =a.id)) is null then 1
when (SELECT status FROM [SV_QueryPlatform].[dbo].[解析任务] where hos_id =a.id and ksdate=(select max(ksdate ) from [dbo].[解析任务] where hos_id =a.id))in ('执行完成','执行失败') then 1
else 0 end 解析,
case
when (SELECT ts FROM [SV_QueryPlatform].[dbo].[解析任务] where hos_id =a.id and ksdate=(select max(ksdate ) from [dbo].[解析任务] where hos_id =a.id)) like '%category未分类%' then 1
else 0 end ts
FROM [192.168.18.156].[DB_SV_Data_Config].[dbo].[SYS_Hospital] A
WHERE A.id<>1 and ExecOpenLink is not null and ExecDatabase is not null and
ExecOpenLink !='' and ExecDatabase !='' {where} )a )b WHERE id<={paseIndex}*10 and id>({paseIndex} - 1)*10 ").ToList();
IEnumerable<dynamic> sj = Connection(181).Query($@"
select*FROM(
SELECT ROW_NUMBER() OVER(ORDER BY ts desc,(select max(ksdate ) from [dbo].[解析任务] where hos_id =a.编号) desc,
医院等级,解析,Replace(Replace(医院名称,'新系统',''),'老系统','') desc )AS id,* FROM(
SELECT
[ID] 编号,
[HosName] 医院名称,
[HosLevel] 医院等级,
[HosType] 医院类型,
[ExecOpenLink] 服务器,
[ExecDatabase] 数据库,
Replace([Province],' ','') 省份,
Replace([Region],' ','') 市,
Replace([City],' ','') 区,
case when isnull([ExecOpenLink],'')!='' and isnull([ExecDatabase],'')!=''
then isnull(
(SELECT
concat('',status,
case when ts <>'' and ts is not null then concat(' 提示:',ts) else '' end
)FROM [dbo].[解析任务] where hos_id =a.id and ksdate=(select max(ksdate ) from [dbo].[解析任务] where hos_id =a.id)) ,'执行完成')
else null end 解析日志 ,
case
when (SELECT status FROM [SV_QueryPlatform].[dbo].[解析任务] where hos_id =a.id and ksdate=(select max(ksdate ) from [dbo].[解析任务] where hos_id =a.id)) is null then 1
when (SELECT status FROM [SV_QueryPlatform].[dbo].[解析任务] where hos_id =a.id and ksdate=(select max(ksdate ) from [dbo].[解析任务] where hos_id =a.id))in ('执行完成') then 1
else 0 end 解析,
case
when (SELECT ts FROM [SV_QueryPlatform].[dbo].[解析任务] where hos_id =a.id and ksdate=(select max(ksdate ) from [dbo].[解析任务] where hos_id =a.id)) like '%category未分类%' then 1
else 0 end ts
FROM [192.168.18.156].[DB_SV_Data_Config].[dbo].[SYS_Hospital] A WHERE A.id<>1 and isnull([ExecDatabase],'')!='' {where}
)a )b WHERE id<={paseIndex}*10 and id>({paseIndex} - 1)*10").ToList();
IEnumerable<dynamic> zon = Connection(181).Query($@" SELECT CAST(COUNT(*)AS MONEY)totalCount ,{paseIndex} paseIndex FROM(
SELECT DISTINCT *
FROM [192.168.18.156].[DB_SV_Data_Config].[dbo].[SYS_Hospital] WHERE id<>1 and ExecOpenLink is not null and ExecDatabase is not null and
......@@ -845,26 +859,26 @@ public void JX_INSERT_CATEGORY(int id, int hos_id)
hos = Connection(156, "DB_SV_Data_Config", "SV_DATA_CONFIG").Query<SYS_Hospital>(sql).FirstOrDefault();
服务器 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.数据库密码);
var fwqip = hos.ExecOpenLink == "192.168.18.156" ? "" : @$"[{hos.ExecOpenLink}].";
var fwqip = "192.168.18.156" ;
sql = $@"INSERT intO [DB_SV_Data_Config].[dbo].[DA_Hos_Category]
([category],[HospitalID])
SELECT t2.category,org_code
FROM [DB_SV_Data_Config].dbo.DA_Hos_Category t1
RIGHT JOIN (SELECT category,org_code
FROM {fwqip}[{hos.ExecDatabase}].[dbo].[OUT_FEE]
FROM [{hos.ExecOpenLink}].[{hos.ExecDatabase}].[dbo].[OUT_FEE]
GROUP BY category,org_code
UNION
SELECT category,org_code
FROM {fwqip}[{hos.ExecDatabase}].[dbo].INPAT_FEE
FROM [{hos.ExecOpenLink}].[{hos.ExecDatabase}].[dbo].INPAT_FEE
GROUP BY category,org_code) t2
ON t1.category = t2.category
WHERE t1.id IS NULL and t2.category is not null;";
updatezt(id, hos_id, sql.Replace("'", "''"), null);
int num = Connection(156, "DB_SV_Data_Config", "SV_DATA_CONFIG").Execute(sql, commandTimeout: 60 * 60 * 12);
int num = Connection(156, "DB_SV_Data_Config", "SV_DATA_CONFIG").Execute(hos.ExecOpenLink == "192.168.18.156"?sql.Replace("[192.168.18.156].",""):sql, commandTimeout: 60 * 60 * 12);
if (num > 0)
{
updatezt(id, hos_id, sql.Replace("'", "''"), "您有category未分类,请到156配置库下添加category!!!select*from [192.168.18.156].[DB_SV_Data_Config].[dbo].[DA_Hos_Category] where HospitalID=" + hos_id);
updatezt(id, hos_id, sql.Replace("'", "''"),@$"您有category未分类,请到156配置库下添加category!!!select*from [192.168.18.156].[DB_SV_Data_Config].[dbo].[DA_Hos_Category] where HospitalID={hos_id}");
}
sql = $@"UPDATE [dbo].[OUT_FEE]
SET I_TYPE_NAME = B.insurance_category
......@@ -887,7 +901,7 @@ public void JX_INSERT_CATEGORY(int id, int hos_id)
FROM [dbo].[INPAT_FEE] t LEFT JOIN [192.168.18.156].DB_SV_DATA_CONFIG.[dbo].[DA_Hos_Category] B
ON B.CATEGORY=t.CATEGORY
where I_TYPE_NAME = '挂号/诊查费' or I_TYPE_NAME = '手术/麻醉费' or I_TYPE_NAME = '床位/护理费'";
Connection(0, msConnectionString).Execute(sql, commandTimeout: 60 * 60 * 12);
Connection(0, msConnectionString).Execute(hos.ExecOpenLink == "192.168.18.156" ? sql.Replace("[192.168.18.156].", "") : sql, commandTimeout: 60 * 60 * 12);
}
}
}
......@@ -81,7 +81,7 @@ public long SqlAdd(SYS_Drugquery sYS_Drugquery, long type, string zxr)
DbConnection connection = new SqlConnection(_configConnectionString);
var sql = @$"INSERT into [SV_QueryPlatform_].[dbo].[MEDIC_SEARCH_RECORD]([HOS_TYPE],[PROJECT_NAME],[GENERIC_NAME],[COMMODITY_NAME],[DISEASE_NAME],[ICD],
[COMPLETE_MARK],[search_time],type ,[TYPE1_2],zxr )
VALUES(0,'{peojectName}','{ drugName}',null,'{diseaseName}',
VALUES(0,'{peojectName}','{drugName}',null,'{diseaseName}',
'{icd}',0,getdate(),'{lx}','{sYS_Drugquery.type1_2}','{zxr}')";
connection.Execute(sql, commandTimeout: 60 * 60 * 5);
......@@ -136,7 +136,7 @@ public void updateCOMPLETE_MARK(long Indexs, long COMPLETE_MARK)
{
configConnection.Execute(@$"
EXEC SV_QueryPlatform_.[dbo].[MEDIC_PERSON_INFORMATION处理] @indexs ={Indexs}
update [SV_QueryPlatform_].[dbo].[MEDIC_SEARCH_RECORD] set COMPLETE_MARK = 22,END_TIME=getdate() where COMPLETE_MARK != 22 and id= {Indexs}");
update [SV_QueryPlatform_].[dbo].[MEDIC_SEARCH_RECORD] set COMPLETE_MARK = 22,END_TIME=getdate() where COMPLETE_MARK != 22 and id= {Indexs}", commandTimeout: 60 * 60 * 5);
}
if (COMPLETE_MARK == 21)
{
......@@ -211,7 +211,7 @@ UNION ALL
{item.ExecDatabase}.[DBO].PUB_PATIENT C
WHERE A.REG_CODE=B.REG_CODE AND A.PERSON_CODE=C.PERSON_CODE";
conn.Execute(sql2, commandTimeout: 60 * 60 * 5);
sql2 = $@" insert into [SV_QueryPlatform_].[dbo].MEDIC_PERSON_INFORMATION_{Indexs }
sql2 = $@" insert into [SV_QueryPlatform_].[dbo].MEDIC_PERSON_INFORMATION_{Indexs}
( [HOS_ID],[MASTER_INDEX],[BIRTHDAY],[SEX],[PERSON_CODE],[PERSON_ID],[REG_CODE],[REG_ID],[REG_SOURCE],
[REG_TIME], AREA_ID,[INDEXS],[TYPE],[DEPT_NAME] )
SELECT [HOS_ID],[MASTER_INDEX],[BIRTHDAY],[SEX],[PERSON_CODE],[PERSON_ID],[REG_CODE],[REG_ID],[REG_SOURCE],
......@@ -349,7 +349,7 @@ public void Drugquery(long typefee, long type1_2, string drugs, string[] drugNam
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 {(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
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
......@@ -409,7 +409,7 @@ UNION ALL
}
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);
home.SendMail(@$"药品/疾病/材料平台提醒", @$"药品拉取失败{string.Join(",", drugName)} 错误日志:{ex.ToString().Replace("'", "''")}", zxr);
}
......@@ -566,7 +566,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);
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);
home.SendMail(@$"药品/疾病/材料平台提醒", @$"材料拉取失败 {string.Join(",", drugName)} 错误日志:{ex.ToString().Replace("'", "''")}", zxr);
}
......
......@@ -7,10 +7,12 @@
using QueryPlatform.Api.Infrastructure.Modules;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Document = DocumentFormat.OpenXml.Wordprocessing.Document;
using Vb = Microsoft.VisualBasic;
......@@ -403,6 +405,9 @@ UNION ALL
return (yearfb, dqfb, condition, PROJECT_NAME, ShowQuery3s, ShowQuery4s, null, ShowQuery5s);
}
/// <summary>
/// /
/// </summary>
......@@ -626,16 +631,9 @@ public void LOG(string LOG, string hos_code, long indexs, string type, string sq
/// </summary>
public string[] ShowSql(string TableName, long sqlint)
{
var sql = "";
using (DbConnection connection = new SqlConnection(_configConnectionString))
{
var lie = "";
if (sqlint == 1)
lie = "sql";
else
lie = "sql2";
sql = $@" SELECT {sql} sql FROM [SV_QueryPlatform].[dbo].[Execute_SQL] WHERE type=1 AND TableName ='{TableName}' ";
var sql = $@" SELECT sql FROM [SV_QueryPlatform].[dbo].[Execute_SQL] WHERE type=1 AND TableName ='{TableName}' ";
string[] A = connection.Query<string>(sql).ToArray();
return A;
}
......@@ -1262,6 +1260,7 @@ public DbConnection Connection(long ip, string configConnectionString)
/// </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(
......@@ -1280,6 +1279,8 @@ public void PullData(long indexs, string DatabaseName, string tableName, string
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);
......@@ -1291,8 +1292,8 @@ public void PullData(long indexs, string DatabaseName, string tableName, string
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
{
//try
//{
long rs = QueryPatient(tableName);
sql = ShowSql($"{biao}", 2)[0];
if (hos.ExecDatabase == "HOS_631337112")
......@@ -1307,17 +1308,138 @@ public void PullData(long indexs, string DatabaseName, string tableName, string
}
服务器 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, "执行中", "");
long num = Connection(0, msConnectionString).Execute(sql, commandTimeout: 60 * 60 * 60 * 5);
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);
}
catch (Exception e)
else
{
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 pullstate(long indexs, string tableName)
{
......@@ -1358,18 +1480,9 @@ public void PullData(long indexs, string DatabaseName, string tableName)
{
new List<string>{"PUB_PATIENT"},
new List<string>{"OUT_REG_INFO","INPAT_REG_INFO"},
new List<string>{"OUT_DIAG","OUT_PRES","INPAT_ORDER","INPAT_DIAG","OUT_FEE","INPAT_FEE","ASSAY_REPORT","EXEC_REPORT","OPS_INFO"},
};
if (rs > 100000)
{
data = new List<List<string>>
{
new List<string>{"PUB_PATIENT"},
new List<string>{"OUT_REG_INFO","INPAT_REG_INFO"},
new List<string>{"OUT_DIAG","INPAT_DIAG","EXEC_REPORT","OPS_INFO","ASSAY_REPORT"},
new List<string>{"OUT_PRES","INPAT_ORDER","OUT_FEE","INPAT_FEE"},
new List<string>{"OUT_DIAG","INPAT_DIAG","OPS_INFO","EXEC_REPORT"},
new List<string>{"INPAT_FEE","INPAT_ORDER","ASSAY_REPORT","OUT_PRES","OUT_FEE"},
};
}
var fwqdata = 标准库fwq().Select(s => s.服务器ip);
var tasks = new List<System.Threading.Tasks.Task>();
foreach (var item in data)
......@@ -1482,16 +1595,18 @@ 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 void PullData修复超时错误(long indexs)
{
DbConnection connection = new SqlConnection(_configConnectionString);
//读取错误日志
var sql = @$"select [ID], [INDEXS],SUBSTRING(hos_code,1,CHARINDEX('H',hos_code)-1)IP, REPLACE(hos_code,SUBSTRING(hos_code,1,CHARINDEX('H',hos_code)-1),'')HOS ,
[LOG], [CreateDate], [type], [错误sql] from (select [ID], [INDEXS], REPLACE(REPLACE(REPLACE( [hos_code] ,'].[',''),'[',''),']','') hos_code,[LOG],
var sql = @$"select [ID], [INDEXS], hos_code ,
[LOG], [CreateDate], [type], REPLACE( REPLACE([错误sql] ,'[192.168.18.181].',''),REPLACE(hos_code,SUBSTRING(hos_code,1,CHARINDEX('[H',hos_code)-1),''),hos_code) from (
select [ID], [INDEXS], [hos_code] ,[LOG],
[CreateDate], [type], REPLACE(left([错误sql],CHARINDEX('错误日志',[错误sql])-1),'报错sql:','')[错误sql] FROM [SV_QueryPlatform].[dbo].[SYS_LOG]
where indexs={indexs} and type='错误')a";
var log = connection.Query<SYS_LOG>(sql).ToList();
......@@ -1505,7 +1620,7 @@ UPDATE @DBName.dbo.ASSAY_REPORT
public void PullData修复超时错误(string ip, string hos, int id, string sql)
{
long num = Connection(181).Execute(sql, commandTimeout: 60 * 60 * 60 * 5);
if (num > 0) { Connection(181).Execute(@$"update [SV_QueryPlatform].[dbo].[SYS_LOG] set type='成功,返回行数:{num}' where id ={id}", commandTimeout: 60 * 60 * 60 * 5); }
if (num > 0) { Connection(181).Execute(@$"update [SV_QueryPlatform].[dbo].[SYS_LOG] set type='成功' where id ={id}", commandTimeout: 60 * 60 * 60 * 5); }
}
public long QueryPatient(string tableName)
{
......
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