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