From bbb117e58ae1ae54da4d63ddd5f8258cd055580e Mon Sep 17 00:00:00 2001 From: seuuung0 Date: Wed, 29 Jul 2026 09:22:12 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BB=A4=EB=B0=8B=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/LotEngravingService.cs | 104 ------------------ 1 file changed, 104 deletions(-) delete mode 100644 leak_test_project/Services/LotEngravingService.cs diff --git a/leak_test_project/Services/LotEngravingService.cs b/leak_test_project/Services/LotEngravingService.cs deleted file mode 100644 index 2590ae9..0000000 --- a/leak_test_project/Services/LotEngravingService.cs +++ /dev/null @@ -1,104 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text.Json; - -namespace leak_test_project.Services -{ - /// - /// 로트번호(Lot No)별 각인 순번을 저장하고 관리하는 서비스. - /// DB COUNT(*) 의존성을 제거하고, Lot No별로 검사할 때마다 무조건 +1씩 증가하며, - /// Lot No 변경 시 1부터 시작하고, 기존 Lot No로 복귀 시 이전 진행 번호부터 이어받아 증가합니다. - /// - public class LotEngravingService - { - private static readonly object _fileLock = new object(); - private static LotEngravingService _instance; - public static LotEngravingService Instance => _instance ??= new LotEngravingService(); - - private readonly string _filePath; - private readonly Dictionary _sequences = new Dictionary(StringComparer.OrdinalIgnoreCase); - - public LotEngravingService() - { - string appDir = AppDomain.CurrentDomain.BaseDirectory; - _filePath = Path.Combine(appDir, "lot_sequences.json"); - LoadSequences(); - } - - private void LoadSequences() - { - lock (_fileLock) - { - try - { - if (File.Exists(_filePath)) - { - string json = File.ReadAllText(_filePath); - var data = JsonSerializer.Deserialize>(json); - if (data != null) - { - _sequences.Clear(); - foreach (var kvp in data) - { - _sequences[kvp.Key] = kvp.Value; - } - } - } - } - catch (Exception ex) - { - System.Diagnostics.Debug.WriteLine($"[LotEngravingService] LoadSequences Error: {ex.Message}"); - } - } - } - - private void SaveSequences() - { - lock (_fileLock) - { - try - { - string json = JsonSerializer.Serialize(_sequences, new JsonSerializerOptions { WriteIndented = true }); - File.WriteAllText(_filePath, json); - } - catch (Exception ex) - { - System.Diagnostics.Debug.WriteLine($"[LotEngravingService] SaveSequences Error: {ex.Message}"); - } - } - } - - /// - /// 지정한 Lot No의 현재 마지막 각인 순번을 조회합니다. (없을 경우 0) - /// - public int GetLastSequence(string lotNo) - { - if (string.IsNullOrWhiteSpace(lotNo)) return 0; - string key = lotNo.Trim(); - - lock (_fileLock) - { - return _sequences.TryGetValue(key, out int seq) ? seq : 0; - } - } - - /// - /// 지정한 Lot No의 다음 각인 순번을 가져오고, 카운터를 +1 증가시켜 영구 저장합니다. - /// - public int GetNextSequence(string lotNo) - { - if (string.IsNullOrWhiteSpace(lotNo)) lotNo = "DEFAULT"; - string key = lotNo.Trim(); - - lock (_fileLock) - { - int current = _sequences.TryGetValue(key, out int seq) ? seq : 0; - int next = current + 1; - _sequences[key] = next; - SaveSequences(); - return next; - } - } - } -}