Compare commits

..

4 Commits

Author SHA1 Message Date
SHM
38cd3d7e77 Extract 2026-03-09 09:37:41 +09:00
SHM
aaf0b9f0f7 [성현모] TL 수정 2026-02-11 12:05:56 +09:00
SHM
122d84bc01 [성현모] Extract 프로젝트 추가 2026-02-11 10:44:06 +09:00
SHM
580257fff2 [성현모] TRA Extract 2026-02-10 13:16:41 +09:00
10 changed files with 486 additions and 3 deletions

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>

View File

@ -0,0 +1,29 @@
 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 CPXV2Database { 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; }
}
}

View File

@ -0,0 +1,215 @@
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
{
public class DBService
{
public string CPXV2ConnectionString { get; set; }
public string ConnectionString { get; set; }
public List<TestList> GetTestList(Config config)
{
List<TestList> result = new List<TestList>();
// 1. 연결 생성
using (SqlConnection conn = new SqlConnection(CPXV2ConnectionString))
{
try
{
// 2. 실행할 쿼리 작성 (JOIN 포함)
string sql = $@"SELECT [No]
,[TestListFileNo]
,[StepID]
,[StepVersion]
,[StepDesc]
,[SpecMin]
,[SpecMax]
,[Dim]
FROM [{config.CPXV2Database}].[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 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);
}
}
}
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 = $"";
// 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}";
string sql = $@"SELECT
Summary.*,
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 [{config.CPXV2Database}].[dbo].[VRFY_TestListFileRelease]
WHERE StepVersion <= Summary.StepVersion and StepDesc = '{config.MO}'
ORDER BY StepVersion DESC
) AS TL";
//TestDT
DateTime endDate = Convert.ToDateTime(config.EndDate).AddDays(1);
sql += $" where '{config.StartDate}' <= Summary.TestDT and Summary.TestDT < '{endDate.ToString("yyyy-MM-dd")}'";
//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}'";
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 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)
{
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)
{
string result = null;
byte[] buffer = Convert.FromBase64String(compressedDataStr);
using (MemoryStream stream = new MemoryStream(buffer))
{
using (GZipStream stream2 = new GZipStream(stream, CompressionMode.Decompress))
{
using (StreamReader streamReader = new StreamReader(stream2))
{
result = streamReader.ReadToEnd();
}
}
}
return result;
}
}
}

View File

@ -0,0 +1,89 @@
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
{
internal class Program
{
static void Main(string[] args)
{
bool isError = false;
var config = JsonConvert.DeserializeObject<Config>(File.ReadAllText("Config.json"));
DBService dbS = new DBService();
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);
}
}
}

View File

@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해
// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면
// 이러한 특성 값을 변경하세요.
[assembly: AssemblyTitle("SystemX.Product.CP.TRA.Extract")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SystemX.Product.CP.TRA.Extract")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에
// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요.
[assembly: ComVisible(false)]
// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
[assembly: Guid("59074fb3-4828-42de-afb0-77b1cb629511")]
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 버전
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{59074FB3-4828-42DE-AFB0-77B1CB629511}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>SystemX.Product.CP.TRA.Extract</RootNamespace>
<AssemblyName>SystemX.Product.CP.TRA.Extract</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<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" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<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>

View 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; }
}
}

View 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; }
}
}

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net481" />
</packages>

View File

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.33027.164
# Visual Studio Version 17
VisualStudioVersion = 17.14.36301.6 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{18C1E9B6-823D-49DB-8253-ED32EEA21DB1}"
EndProject
@ -12,6 +12,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SystemX.Product.CP.TRA", "S
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SystemX.Product.CP.TRA.BaseView", "SystemX.Product.CP.TRA.BaseView\SystemX.Product.CP.TRA.BaseView.csproj", "{910BB092-A5F3-4ACE-BBF8-C19434F1FA8E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SystemX.Product.CP.TRA.Extract", "SystemX.Product.CP.TRA.Extract\SystemX.Product.CP.TRA.Extract.csproj", "{59074FB3-4828-42DE-AFB0-77B1CB629511}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -36,12 +38,20 @@ Global
{910BB092-A5F3-4ACE-BBF8-C19434F1FA8E}.Release|Any CPU.Build.0 = Release|Any CPU
{910BB092-A5F3-4ACE-BBF8-C19434F1FA8E}.Release|x64.ActiveCfg = Release|Any CPU
{910BB092-A5F3-4ACE-BBF8-C19434F1FA8E}.Release|x64.Build.0 = Release|Any CPU
{59074FB3-4828-42DE-AFB0-77B1CB629511}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{59074FB3-4828-42DE-AFB0-77B1CB629511}.Debug|Any CPU.Build.0 = Debug|Any CPU
{59074FB3-4828-42DE-AFB0-77B1CB629511}.Debug|x64.ActiveCfg = Debug|Any CPU
{59074FB3-4828-42DE-AFB0-77B1CB629511}.Debug|x64.Build.0 = Debug|Any CPU
{59074FB3-4828-42DE-AFB0-77B1CB629511}.Release|Any CPU.ActiveCfg = Release|Any CPU
{59074FB3-4828-42DE-AFB0-77B1CB629511}.Release|Any CPU.Build.0 = Release|Any CPU
{59074FB3-4828-42DE-AFB0-77B1CB629511}.Release|x64.ActiveCfg = Release|Any CPU
{59074FB3-4828-42DE-AFB0-77B1CB629511}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
VisualSVNWorkingCopyRoot = .
SolutionGuid = {34BF09E0-D510-452D-8E8B-B0D1C6FE25BF}
VisualSVNWorkingCopyRoot = .
EndGlobalSection
EndGlobal