diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 4354a73..745f082 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -2,7 +2,13 @@ "permissions": { "allow": [ "Bash(git add:*)", - "WebFetch(domain:jnelib.jne.go.kr)" + "WebFetch(domain:jnelib.jne.go.kr)", + "Bash(node:*)", + "Bash(npm --version)", + "Bash(echo $OS)", + "Bash(claude mcp:*)", + "WebSearch", + "WebSearch" ], "deny": [], "ask": [] diff --git a/ExcelTest/ExcelTest/obj/Debug/ExcelTest.csproj.AssemblyReference.cache b/ExcelTest/ExcelTest/obj/Debug/ExcelTest.csproj.AssemblyReference.cache index d756ce8..c066752 100644 Binary files a/ExcelTest/ExcelTest/obj/Debug/ExcelTest.csproj.AssemblyReference.cache and b/ExcelTest/ExcelTest/obj/Debug/ExcelTest.csproj.AssemblyReference.cache differ diff --git a/ExcelTest/ExcelTest/obj/Debug/ExcelTest.csproj.ResolveComReference.cache b/ExcelTest/ExcelTest/obj/Debug/ExcelTest.csproj.ResolveComReference.cache index c1808fa..5698e5e 100644 Binary files a/ExcelTest/ExcelTest/obj/Debug/ExcelTest.csproj.ResolveComReference.cache and b/ExcelTest/ExcelTest/obj/Debug/ExcelTest.csproj.ResolveComReference.cache differ diff --git a/pofalApi_tmp/obj/Debug/netcoreapp3.1/pofalApi_tmp.AssemblyInfo.cs b/pofalApi_tmp/obj/Debug/netcoreapp3.1/pofalApi_tmp.AssemblyInfo.cs index f55ecd2..3534421 100644 --- a/pofalApi_tmp/obj/Debug/netcoreapp3.1/pofalApi_tmp.AssemblyInfo.cs +++ b/pofalApi_tmp/obj/Debug/netcoreapp3.1/pofalApi_tmp.AssemblyInfo.cs @@ -14,7 +14,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("pofalApi_tmp")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8e7df6f68d424e8b9f20e24f017b877849125171")] [assembly: System.Reflection.AssemblyProductAttribute("pofalApi_tmp")] [assembly: System.Reflection.AssemblyTitleAttribute("pofalApi_tmp")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/pofalApi_tmp/obj/Debug/netcoreapp3.1/pofalApi_tmp.AssemblyInfoInputs.cache b/pofalApi_tmp/obj/Debug/netcoreapp3.1/pofalApi_tmp.AssemblyInfoInputs.cache index 62b5dc1..f4d92b1 100644 --- a/pofalApi_tmp/obj/Debug/netcoreapp3.1/pofalApi_tmp.AssemblyInfoInputs.cache +++ b/pofalApi_tmp/obj/Debug/netcoreapp3.1/pofalApi_tmp.AssemblyInfoInputs.cache @@ -1 +1 @@ -c13c9c2f2e12bc007cbcab6ccdb94397f9d2465a +1e22963f41eb10ec8b7d5cf0f11446afcd4c7c64669758c39d9d6d7a2dc5abbf diff --git a/pofalApi_tmp/obj/Debug/netcoreapp3.1/pofalApi_tmp.assets.cache b/pofalApi_tmp/obj/Debug/netcoreapp3.1/pofalApi_tmp.assets.cache index edc0738..9ef0e94 100644 Binary files a/pofalApi_tmp/obj/Debug/netcoreapp3.1/pofalApi_tmp.assets.cache and b/pofalApi_tmp/obj/Debug/netcoreapp3.1/pofalApi_tmp.assets.cache differ diff --git a/unimarc/unimarc/Properties/AssemblyInfo.cs b/unimarc/unimarc/Properties/AssemblyInfo.cs index 369fb3d..d620c5a 100644 --- a/unimarc/unimarc/Properties/AssemblyInfo.cs +++ b/unimarc/unimarc/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를 // 기본값으로 할 수 있습니다. // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2025.08.19.2250")] -[assembly: AssemblyFileVersion("2025.08.19.2250")] +[assembly: AssemblyVersion("2025.09.03.2030")] +[assembly: AssemblyFileVersion("2025.09.03.2030")] diff --git a/unimarc/unimarc/SearchModel/GochangLibSearcher.cs b/unimarc/unimarc/SearchModel/GochangLibSearcher.cs new file mode 100644 index 0000000..90fb781 --- /dev/null +++ b/unimarc/unimarc/SearchModel/GochangLibSearcher.cs @@ -0,0 +1,303 @@ +using System; +using System.Threading.Tasks; +using OpenQA.Selenium; +using OpenQA.Selenium.Chrome; +using OpenQA.Selenium.Support.UI; +using System.Text.RegularExpressions; +using WebDriverManager; +using WebDriverManager.DriverConfigs.Impl; +using System.IO; +using System.Runtime.InteropServices; +using System.Threading; +using UniMarc.마크; +using OpenQA.Selenium.Chromium; +using UniMarc.SearchModel; +using System.Runtime.CompilerServices; +using AR; + +namespace BokBonCheck +{ + public class GochangLibSearcher : ILibrarySearcher + { + public string AreaCode { get; set; } = string.Empty; + public string SiteName { get; protected set; } + public string SiteUrl => "https://libsearch.gochang.go.kr:8443/book/bookAdvancedSearch"; + public bool HttpApiMode { get; set; } = false; + + public int No { get; set; } + + private ChromiumDriver _driver; + + public GochangLibSearcher(int no, string areaCode, string areaName) + { + this.No = no; + this.AreaCode = areaCode; + this.SiteName = $"고창군립({areaName})"; + } + + public void StopDriver() + { + if (_driver != null) + { + _driver.Quit(); + _driver.Dispose(); + _driver = null; + } + } + + public async Task StartDriver(bool showdriver = false) + { + if (_driver == null) + { + try + { + if (SeleniumHelper.IsReady == false) await SeleniumHelper.Download(); + _driver = await SeleniumHelper.CreateDriver(ShowBrowser: showdriver); + Console.WriteLine("GochangLibSearcher Driver 초기화 완료"); + } + catch (Exception ex) + { + Console.WriteLine($"GochangLibSearcher Driver 초기화 실패: {ex.Message}"); + throw new InvalidOperationException($"GochangLibSearcher Driver 초기화에 실패했습니다: {ex.Message}", ex); + } + } + } + + virtual protected bool SelectLibrary(WebDriverWait wait) + { + try + { + if (!string.IsNullOrEmpty(AreaCode)) + { + var libSelect = wait.Until(d => d.FindElement(By.Id("MANAGE_CODE"))); + var selectElement = new SelectElement(libSelect); + selectElement.SelectByValue(AreaCode); + Thread.Sleep(300); + Console.WriteLine($"{AreaCode} 도서관으로 선택됨"); + } + else + { + Console.WriteLine("전체 도서관으로 검색"); + } + + return true; + } + catch (Exception ex) + { + Console.WriteLine($"도서관 선택 실패: {ex.Message}"); + return false; + } + } + + public async Task SearchAsync(string searchTerm) + { + var result = new BookSearchResult + { + SiteName = SiteName, + SearchTerm = searchTerm, + SearchTime = DateTime.Now + }; + + try + { + if (_driver == null) + { + await StartDriver(); + } + + var cururl = _driver.Url; + if (cururl.Equals(SiteUrl) == false) + _driver.Navigate().GoToUrl(SiteUrl); + + var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(15)); + + if (SelectLibrary(wait) == false) + { + result.ErrorMessage = "도서관선택실패"; + result.BookCount = -1; + result.IsSuccess = false; + return result; + } + + try + { + var titleInput = wait.Until(d => d.FindElement(By.Id("title"))); + titleInput.Clear(); + titleInput.SendKeys(searchTerm); + } + catch (Exception ex) + { + result.ErrorMessage = $"검색어입력실패({ex.Message})"; + result.BookCount = -1; + result.IsSuccess = false; + return result; + } + + try + { + var jsExecutor = (IJavaScriptExecutor)_driver; + jsExecutor.ExecuteScript("fn_openBookAdvancedSearch();"); + } + catch (Exception ex) + { + result.ErrorMessage = $"검색실행실패({ex.Message})"; + result.BookCount = -1; + result.IsSuccess = false; + return result; + } + + await WaitForPageChange(new WebDriverWait(_driver, TimeSpan.FromSeconds(15))); + + var resultCount = ExtractBookCount(_driver, searchTerm, out string ermsg); + if (resultCount == -1) + { + result.BookCount = 0; + result.IsSuccess = false; + result.ErrorMessage = ermsg; + } + else + { + result.BookCount = resultCount; + result.IsSuccess = true; + result.ErrorMessage = ermsg; + } + + } + catch (Exception ex) + { + result.IsSuccess = false; + result.ErrorMessage = ex.Message; + result.BookCount = 0; + } + + return result; + } + + private int ExtractBookCount(IWebDriver driver, string searchTerm, out string errmessage) + { + errmessage = string.Empty; + try + { + try + { + var noResultElement = driver.FindElement(By.XPath("//*[contains(text(), '검색된 도서가 없습니다') or contains(text(), '검색결과가 없습니다')]")); + if (noResultElement != null) + { + errmessage = "검색결과없음"; + return 0; + } + } + catch + { + } + + try + { + var resultElement = driver.FindElement(By.CssSelector(".subTapContWrap.on p")); + if (resultElement != null) + { + var resultText = resultElement.Text; + var match = Regex.Match(resultText, @"총\s*(\d+)건", RegexOptions.IgnoreCase); + if (match.Success) + { + if (int.TryParse(match.Groups[1].Value, out int count)) + { + if (count == 0) + { + errmessage = "검색결과없음"; + return 0; + } + errmessage = $"검색성공({count}권)"; + return count; + } + } + } + } + catch (Exception ex) + { + Console.WriteLine($"결과 요소 검색 중 오류: {ex.Message}"); + } + + var pageSource = driver.PageSource; + + if (pageSource.Contains("검색된 도서가 없습니다") || + pageSource.Contains("검색결과가 없습니다") || + pageSource.Contains("검색된 자료가 없습니다")) + { + errmessage = "검색결과없음"; + return 0; + } + + var htmlPatterns = new[] + { + @"]*class=""bluecolor""[^>]*>총\s*(\d+)건", + @"총\s*]*class=""bluecolor""[^>]*>(\d+)건", + @"총\s*(\d+)건" + }; + + foreach (var pattern in htmlPatterns) + { + var match = Regex.Match(pageSource, pattern, RegexOptions.IgnoreCase); + if (match.Success) + { + if (int.TryParse(match.Groups[1].Value, out int count)) + { + if (count == 0) + { + errmessage = "검색결과없음"; + return 0; + } + errmessage = $"검색성공({count}권)"; + return count; + } + } + } + + errmessage = "결과수량을찾을수없음"; + return -1; + + } + catch (Exception ex) + { + errmessage = ex.Message; + return -1; + } + } + + public async Task WaitForPageChange(WebDriverWait wait) + { + try + { + await Task.Delay(500); + + wait.Until(d => + { + var readyState = ((IJavaScriptExecutor)d).ExecuteScript("return document.readyState"); + return readyState.Equals("complete"); + }); + + wait.Until(d => + { + try + { + var pageSource = d.PageSource; + return pageSource.Contains("검색결과입니다") || + pageSource.Contains("총") || + pageSource.Contains("건") || + pageSource.Contains("검색된 도서가 없습니다"); + } + catch + { + return false; + } + }); + + } + catch (Exception ex) + { + await Task.Delay(3000); + Console.WriteLine($"페이지 변경 감지 실패: {ex.Message}"); + } + } + } +} \ No newline at end of file diff --git a/unimarc/unimarc/UniMarc.csproj b/unimarc/unimarc/UniMarc.csproj index 271bf07..7185567 100644 --- a/unimarc/unimarc/UniMarc.csproj +++ b/unimarc/unimarc/UniMarc.csproj @@ -236,6 +236,7 @@ Form + diff --git a/unimarc/unimarc/마크/Check_copyWD.cs b/unimarc/unimarc/마크/Check_copyWD.cs index bf7e7f9..b409359 100644 --- a/unimarc/unimarc/마크/Check_copyWD.cs +++ b/unimarc/unimarc/마크/Check_copyWD.cs @@ -11,6 +11,7 @@ using AR; using UniMarc.SearchModel; using System.Linq; using UniMarc; +using System.Globalization; namespace WindowsFormsApp1.Mac { @@ -28,7 +29,7 @@ namespace WindowsFormsApp1.Mac { get { - return (DateTime.Now <= new DateTime(2025, 09, 30)); + return (DateTime.Now <= new DateTime(2025, 12, 30)); } } @@ -49,7 +50,7 @@ namespace WindowsFormsApp1.Mac _searchService.AddSearcher(new NamguLibrarySearcher(idx++, "#libSW", "효천어울림도서관")); - if (GetDemoRunAuth == true) + { //광주시교육청통합도서관 _searchService.AddSearcher(new KwangjuCityEduLibrarySearcher(idx++, "MD", "중앙도서관")); @@ -405,6 +406,19 @@ namespace WindowsFormsApp1.Mac } + //고창도서관 추가 250903 + + _searchService.AddSearcher(new GochangLibSearcher(idx++, "MA", "고창군립도서관")); + _searchService.AddSearcher(new GochangLibSearcher(idx++, "MB", "선운산작은도서관")); + _searchService.AddSearcher(new GochangLibSearcher(idx++, "MC", "고수해마루작은도서관")); + _searchService.AddSearcher(new GochangLibSearcher(idx++, "MD", "고창군립성호도서관")); + _searchService.AddSearcher(new GochangLibSearcher(idx++, "ME", "대산큰별작은도서관")); + _searchService.AddSearcher(new GochangLibSearcher(idx++, "MF", "무장글샘작은도서관")); + _searchService.AddSearcher(new GochangLibSearcher(idx++, "MG", "글마루작은도서관")); + _searchService.AddSearcher(new GochangLibSearcher(idx++, "MH", "흥덕가온누리작은도서관")); + _searchService.AddSearcher(new GochangLibSearcher(idx++, "MI", "공음참나무골작은도서관")); + + this.tb_SearchTarget.Items.Clear(); // this.tb_SearchTarget.Items.Add("-- 검색대상을 선택하세요 --"); foreach (var item in _searchService.GetAvailableSites().OrderBy(t => t))