[성현모] Extract 프로젝트 추가
This commit is contained in:
28
CPXV2 TRA JSON/SystemX.Product.CP.TRA.Extract/Config.cs
Normal file
28
CPXV2 TRA JSON/SystemX.Product.CP.TRA.Extract/Config.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SystemX.Product.CP.TRA.Extract
|
||||
{
|
||||
public class Config
|
||||
{
|
||||
public string CPXV2Server { get; set; }
|
||||
public string Server { get; set; }
|
||||
public string DataBase { get; set; }
|
||||
public string SummaryTable { get; set; }
|
||||
public string ResultTable { get; set; }
|
||||
public string User { get; set; }
|
||||
public string Passwd { get; set; }
|
||||
|
||||
|
||||
public string ProductNo { get; set; }
|
||||
public string TestCode { get; set; }
|
||||
public string StartDate { get; set; }
|
||||
public string EndDate { get; set; }
|
||||
public string MO { get; set; }
|
||||
|
||||
public int RowCount { get; set; }
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,13 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SystemX.Product.CP.TRA.Extract
|
||||
@ -12,47 +15,163 @@ namespace SystemX.Product.CP.TRA.Extract
|
||||
|
||||
public class DBService
|
||||
{
|
||||
private string connectionString = "Server=192.168.0.69;Database=CPXV2ShortTermLogJson;User Id=Alis;Password=Kefico!@34;";
|
||||
public string CPXV2ConnectionString { get; set; }
|
||||
public string ConnectionString { get; set; }
|
||||
|
||||
public void GetLargeData()
|
||||
public List<TestList> GetTestList(Config config)
|
||||
{
|
||||
List<TestList> result = new List<TestList>();
|
||||
|
||||
// 1. 연결 생성
|
||||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||||
using (SqlConnection conn = new SqlConnection(CPXV2ConnectionString))
|
||||
{
|
||||
try
|
||||
{
|
||||
// 2. 실행할 쿼리 작성 (JOIN 포함)
|
||||
string sql = @"SELECT [TestListFileNo]
|
||||
,[StepID]
|
||||
,[StepVersion]
|
||||
,[StepDesc]
|
||||
,[SpecMin]
|
||||
,[SpecMax]
|
||||
,[Dim]
|
||||
FROM [CPXV2].[dbo].[VRFY_TestListFileRelease] where StepDesc like 'an10_off' order by testlistfileno";
|
||||
string sql = $@"SELECT [No]
|
||||
,[TestListFileNo]
|
||||
,[StepID]
|
||||
,[StepVersion]
|
||||
,[StepDesc]
|
||||
,[SpecMin]
|
||||
,[SpecMax]
|
||||
,[Dim]
|
||||
FROM [CPXV2].[dbo].[VRFY_TestListFileRelease] WITH(NOLOCK) where StepDesc = '{config.MO}'";
|
||||
|
||||
SqlCommand cmd = new SqlCommand(sql, conn);
|
||||
// 타임아웃 설정 (600만 건은 시간이 걸릴 수 있으므로 0(무제한) 또는 넉넉하게 설정)
|
||||
cmd.CommandTimeout = 300;
|
||||
conn.Open();
|
||||
|
||||
|
||||
// 3. DataReader로 데이터 읽기
|
||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
// 예: 데이터 처리 로직
|
||||
var val = Decompression(reader["LogData"].ToString());
|
||||
var tl = new TestList
|
||||
{
|
||||
TestListFileNo = Convert.ToInt32(reader["TestListFileNo"]),
|
||||
StepID = Convert.ToInt32(reader["StepID"]),
|
||||
StepVersion = Convert.ToInt32(reader["StepVersion"]),
|
||||
StepDesc = reader["StepDesc"].ToString(),
|
||||
SpecMin = reader["SpecMin"].ToString(),
|
||||
SpecMax = reader["SpecMax"].ToString(),
|
||||
Dim = reader["Dim"].ToString(),
|
||||
};
|
||||
result.Add(tl);
|
||||
}
|
||||
}
|
||||
|
||||
//sql = @"SELECT * FROM HIST_LogSummary_2025 as Summary with(nolock) JOIN HIST_TestResult_2025 as Result with(nolock) ON Summary.No = Result.No";
|
||||
}
|
||||
catch (SqlException ex)
|
||||
{
|
||||
Console.WriteLine("DB 오류 발생: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"{config.MO} 포함 테스트리스트 개수: {result.Count}");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void GetLargeData(List<TestList> testList, Config config)
|
||||
{
|
||||
int rowCount = 0;
|
||||
int fileNo = 0;
|
||||
string fileName = $"";
|
||||
|
||||
foreach (var tl in testList)
|
||||
{
|
||||
Console.WriteLine($"진행중 테스트리스트(MO:{config.MO}): TestListFileNo:{tl.TestListFileNo}, StepVersion:{tl.StepVersion}");
|
||||
|
||||
// 1. 연결 생성
|
||||
using (SqlConnection conn = new SqlConnection(ConnectionString))
|
||||
{
|
||||
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}";
|
||||
|
||||
//test code
|
||||
if(string.IsNullOrEmpty(config.TestCode) == false)
|
||||
sql += $" and TestCode = '{config.TestCode}'";
|
||||
|
||||
//productNo
|
||||
if(string.IsNullOrEmpty(config.ProductNo) == false)
|
||||
sql += $" and ProdNo_C = '{config.ProductNo}'";
|
||||
|
||||
//TestDT
|
||||
DateTime endDate = Convert.ToDateTime(config.EndDate).AddDays(1);
|
||||
sql += $" and '{config.StartDate}' <= Summary.TestDT and Summary.TestDT < '{endDate.ToString("yyyy-MM-dd")}'";
|
||||
|
||||
SqlCommand cmd = new SqlCommand(sql, conn);
|
||||
// 타임아웃 설정 (600만 건은 시간이 걸릴 수 있으므로 0(무제한) 또는 넉넉하게 설정)
|
||||
cmd.CommandTimeout = 0;
|
||||
conn.Open();
|
||||
|
||||
// 3. DataReader로 데이터 읽기
|
||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
bool queryLog = false;
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
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"]);
|
||||
|
||||
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 findStep = r.Find(x => x.StepID == tl.StepID);
|
||||
|
||||
if (rowCount % config.RowCount == 0)
|
||||
{
|
||||
rowCount = 0;
|
||||
fileNo += 1;
|
||||
|
||||
fileName = $"{config.MO}";
|
||||
|
||||
//testcode
|
||||
if (string.IsNullOrEmpty(config.TestCode) == false)
|
||||
fileName += $"_{testCode}";
|
||||
|
||||
if(string.IsNullOrEmpty(config.ProductNo) == false)
|
||||
fileName += $"_{productNo}";
|
||||
|
||||
fileName += $"_{config.StartDate}_{config.EndDate}";
|
||||
|
||||
File.AppendAllText($"{fileName}_{fileNo}.csv", $"ProductNo,TestCode,TestDT,MO,MeasVal,MeasValStr,Host,ProductID\n");
|
||||
Console.WriteLine($"Create New File: {fileName}_{fileNo}.csv");
|
||||
}
|
||||
|
||||
if (findStep != null)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string Decompression(string compressedDataStr)
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SystemX.Product.CP.TRA.Extract
|
||||
@ -10,8 +14,76 @@ namespace SystemX.Product.CP.TRA.Extract
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
bool isError = false;
|
||||
|
||||
var config = JsonConvert.DeserializeObject<Config>(File.ReadAllText("Config.json"));
|
||||
DBService dbS = new DBService();
|
||||
dbS.GetLargeData();
|
||||
dbS.CPXV2ConnectionString = $"Server={config.CPXV2Server};Database=CPXV2;User Id={config.User};Password={config.Passwd};";
|
||||
dbS.ConnectionString = $"Server={config.Server};Database={config.DataBase};User Id={config.User};Password={config.Passwd};";
|
||||
|
||||
//db check
|
||||
try
|
||||
{
|
||||
using (SqlConnection conn = new SqlConnection(dbS.CPXV2ConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
Console.ForegroundColor = ConsoleColor.DarkGreen;
|
||||
Console.WriteLine("Config.json, CPXV2 server connect success.");
|
||||
}
|
||||
|
||||
using (SqlConnection conn = new SqlConnection(dbS.ConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
Console.ForegroundColor = ConsoleColor.DarkGreen;
|
||||
Console.WriteLine($"Config.json, {config.DataBase} server connect success.");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.DarkRed;
|
||||
Console.WriteLine("Config.json, Invalid Server Set.");
|
||||
isError = true;
|
||||
}
|
||||
Console.WriteLine("");
|
||||
Thread.Sleep(1000);
|
||||
|
||||
//mo check
|
||||
if (string.IsNullOrEmpty(config.MO) == true)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.DarkRed;
|
||||
Console.WriteLine("Config.json, MO Value is Empty");
|
||||
isError = true;
|
||||
}
|
||||
|
||||
//date check
|
||||
try
|
||||
{
|
||||
var start = Convert.ToDateTime(config.StartDate);
|
||||
var end = Convert.ToDateTime(config.EndDate);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.DarkRed;
|
||||
Console.WriteLine("Config.json, StartDate ~ EndDate are Invalid Format. Fix to yyyy-MM-dd");
|
||||
isError = true;
|
||||
}
|
||||
|
||||
if (isError == true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.DarkGreen;
|
||||
Console.WriteLine($"ProductNO:{config.ProductNo}, TestCode:{config.TestCode}");
|
||||
Console.WriteLine($"StartDate:{config.StartDate}, EndDate:{config.EndDate}");
|
||||
Console.WriteLine($"MO:{config.MO}");
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.WriteLine("");
|
||||
Thread.Sleep(1000);
|
||||
|
||||
var finsList = dbS.GetTestList(config);
|
||||
dbS.GetLargeData(finsList, config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,6 +33,9 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
@ -43,12 +46,16 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Config.cs" />
|
||||
<Compile Include="DBService.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="TestList.cs" />
|
||||
<Compile Include="TestResult.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
19
CPXV2 TRA JSON/SystemX.Product.CP.TRA.Extract/TestList.cs
Normal file
19
CPXV2 TRA JSON/SystemX.Product.CP.TRA.Extract/TestList.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SystemX.Product.CP.TRA.Extract
|
||||
{
|
||||
public class TestList
|
||||
{
|
||||
public int TestListFileNo { get; set; }
|
||||
public int StepID { get; set; }
|
||||
public int StepVersion { get; set; }
|
||||
public string StepDesc { get; set; }
|
||||
public string SpecMin { get; set; }
|
||||
public string SpecMax { get; set; }
|
||||
public string Dim { get; set; }
|
||||
}
|
||||
}
|
||||
16
CPXV2 TRA JSON/SystemX.Product.CP.TRA.Extract/TestResult.cs
Normal file
16
CPXV2 TRA JSON/SystemX.Product.CP.TRA.Extract/TestResult.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SystemX.Product.CP.TRA.Extract
|
||||
{
|
||||
public class TestResult
|
||||
{
|
||||
public int No { get; set; }
|
||||
public int StepID { get; set; }
|
||||
public double MeasVal { get; set; }
|
||||
public string MeasValStr { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net481" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user