This commit is contained in:
SHM
2026-03-09 09:37:41 +09:00
parent aaf0b9f0f7
commit 38cd3d7e77
2 changed files with 67 additions and 61 deletions

View File

@ -36,7 +36,7 @@ namespace SystemX.Product.CP.TRA.Extract
,[SpecMin]
,[SpecMax]
,[Dim]
FROM [CPXV2].[dbo].[VRFY_TestListFileRelease] WITH(NOLOCK) where StepDesc = '{config.MO}'";
FROM [{config.CPXV2Database}].[dbo].[VRFY_TestListFileRelease] WITH(NOLOCK) where StepDesc = '{config.MO}'";
SqlCommand cmd = new SqlCommand(sql, conn);
// 타임아웃 설정 (600만 건은 시간이 걸릴 수 있으므로 0(무제한) 또는 넉넉하게 설정)
@ -78,79 +78,83 @@ namespace SystemX.Product.CP.TRA.Extract
int rowCount = 0;
int fileNo = 0;
string fileName = $"";
foreach (var tl in testList)
// 1. 연결 생성
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
Console.WriteLine($"진행중 테스트리스트(MO:{config.MO}): TestListFileNo:{tl.TestListFileNo}, StepVersion:{tl.StepVersion}");
// 1. 연결 생성
using (SqlConnection conn = new SqlConnection(ConnectionString))
try
{
try
{
// 2. 실행할 쿼리 작성 (JOIN 포함)
//string sql = $@"SELECT * FROM {config.SummaryTable} as Summary WITH(NOLOCK)
//JOIN {config.ResultTable} as Result WITH(NOLOCK) ON Summary.No = Result.No
//WHERE TestListFileNo = {tl.TestListFileNo} and StepVersion={tl.StepVersion}";
// 2. 실행할 쿼리 작성 (JOIN 포함)
//string sql = $@"SELECT * FROM {config.SummaryTable} as Summary WITH(NOLOCK)
//JOIN {config.ResultTable} as Result WITH(NOLOCK) ON Summary.No = Result.No
//WHERE TestListFileNo = {tl.TestListFileNo} and StepVersion={tl.StepVersion}";
string sql = $@"SELECT
string sql = $@"SELECT
Summary.*,
Result.*,
Result.LogData,
TL.StepVersion AS Matched_StepVersion
FROM [{config.DataBase}].[dbo].[{config.SummaryTable}] AS Summary WITH(NOLOCK)
JOIN [{config.DataBase}].[dbo].[{config.ResultTable}] AS Result WITH(NOLOCK)
ON Summary.No = Result.No
OUTER APPLY (
SELECT TOP 1 *
FROM [CPXV2].[dbo].[VRFY_TestListFileRelease]
WHERE StepVersion <= Summary.StepVersion and TestListFileNo = {tl.TestListFileNo} and StepDesc = '{config.MO}'
FROM [{config.CPXV2Database}].[dbo].[VRFY_TestListFileRelease]
WHERE StepVersion <= Summary.StepVersion and StepDesc = '{config.MO}'
ORDER BY StepVersion DESC
) AS TL
WHERE Summary.TestListFileNo = {tl.TestListFileNo} and StepVersion=TL.StepVersion";
) AS TL";
//test code
if(string.IsNullOrEmpty(config.TestCode) == false)
sql += $" and TestCode = '{config.TestCode}'";
//TestDT
DateTime endDate = Convert.ToDateTime(config.EndDate).AddDays(1);
sql += $" where '{config.StartDate}' <= Summary.TestDT and Summary.TestDT < '{endDate.ToString("yyyy-MM-dd")}'";
//productNo
if(string.IsNullOrEmpty(config.ProductNo) == false)
sql += $" and ProdNo_C = '{config.ProductNo}'";
//test code
if (string.IsNullOrEmpty(config.TestCode) == false)
sql += $" and TestCode = '{config.TestCode}'";
//TestDT
DateTime endDate = Convert.ToDateTime(config.EndDate).AddDays(1);
sql += $" and '{config.StartDate}' <= Summary.TestDT and Summary.TestDT < '{endDate.ToString("yyyy-MM-dd")}'";
//productNo
if (string.IsNullOrEmpty(config.ProductNo) == false)
sql += $" and ProdNo_C = '{config.ProductNo}'";
SqlCommand cmd = new SqlCommand(sql, conn);
// 타임아웃 설정 (600만 건은 시간이 걸릴 수 있으므로 0(무제한) 또는 넉넉하게 설정)
cmd.CommandTimeout = 0;
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
// 타임아웃 설정 (600만 건은 시간이 걸릴 수 있으므로 0(무제한) 또는 넉넉하게 설정)
cmd.CommandTimeout = 0;
conn.Open();
// 3. DataReader로 데이터 읽기
using (SqlDataReader reader = cmd.ExecuteReader())
// 3. DataReader로 데이터 읽기
using (SqlDataReader reader = cmd.ExecuteReader())
{
bool queryLog = false;
while (reader.Read())
{
bool queryLog = false;
while (reader.Read())
if (queryLog == false)
{
if (queryLog == false)
{
Console.ForegroundColor = ConsoleColor.DarkYellow;
Thread.Sleep(10);
Console.WriteLine($"Query: {sql}");
Console.ForegroundColor = ConsoleColor.White;
queryLog = true;
}
// 예: 데이터 처리 로직
var val = Decompression(reader["LogData"].ToString());
var date = Convert.ToDateTime(reader["TestDT"]);
Console.ForegroundColor = ConsoleColor.DarkYellow;
Thread.Sleep(10);
Console.WriteLine($"Query: {sql}");
Console.ForegroundColor = ConsoleColor.White;
queryLog = true;
}
var productNo = reader["ProdNo_C"].ToString();
var testCode = reader["TestCode"].ToString();
var host = reader["HostID"].ToString();
var productID = reader["ProductID"].ToString();
var r = JsonConvert.DeserializeObject<List<TestResult>>(val);
// 예: 데이터 처리 로직
var val = Decompression(reader["LogData"].ToString());
var date = Convert.ToDateTime(reader["TestDT"]);
var testListFileNo = Convert.ToInt32(reader["TestListFileNo"]);
var stepVersion = Convert.ToInt32(reader["Matched_StepVersion"]);
var no = Convert.ToInt32(reader["No"]);
var productNo = reader["ProdNo_C"].ToString();
var testCode = reader["TestCode"].ToString();
var host = reader["HostID"].ToString();
var productID = reader["ProductID"].ToString();
var r = JsonConvert.DeserializeObject<List<TestResult>>(val);
var tl = testList.Find(x => x.TestListFileNo == testListFileNo && x.StepVersion == stepVersion);
if(tl != null)
{
//Console.WriteLine($"Current No:{no}");
var findStep = r.Find(x => x.StepID == tl.StepID);
if (rowCount % config.RowCount == 0)
@ -164,7 +168,7 @@ namespace SystemX.Product.CP.TRA.Extract
if (string.IsNullOrEmpty(config.TestCode) == false)
fileName += $"_{testCode}";
if(string.IsNullOrEmpty(config.ProductNo) == false)
if (string.IsNullOrEmpty(config.ProductNo) == false)
fileName += $"_{productNo}";
fileName += $"_{config.StartDate}_{config.EndDate}";
@ -177,14 +181,15 @@ namespace SystemX.Product.CP.TRA.Extract
{
File.AppendAllText($"./{fileName}_{fileNo}.csv", $"{productNo},{testCode},{date.ToString("yyyy-MM-dd HH:mm:ss")},{tl.StepDesc},{findStep.MeasVal},{findStep.MeasValStr},{host},{productID}\n");
rowCount += 1;
}
}
}
}
}
catch (SqlException ex)
{
Console.WriteLine("DB 오류 발생: " + ex.Message);
}
}
catch (SqlException ex)
{
Console.WriteLine("DB 오류 발생: " + ex.Message);
}
}
}