From 94ff952398b88cf1d9429169b07392ceffe727c4 Mon Sep 17 00:00:00 2001 From: "sosuke.iwabuchi" Date: Wed, 11 Aug 2021 13:54:04 +0900 Subject: [PATCH] =?UTF-8?q?=E7=B4=90=E3=81=A5=E3=81=91=E5=A4=B1=E6=95=97?= =?UTF-8?q?=E9=A7=90=E8=BB=8A=E5=A0=B4=E3=82=92=E3=82=B5=E3=83=BC=E3=83=90?= =?UTF-8?q?=E3=81=AB=E7=99=BB=E9=8C=B2=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Exceptions/SpotNameNotMatchException.cs | 20 +++ CSVDownloader/Program.cs | 43 +++++-- ...ParkingCreditCardAgenciesSpotIDErrorDAO.cs | 118 ++++++++++++++++++ CSVDownloader/Web/DaitoController.cs | 20 ++- CSVDownloader/Web/HelloTechnoController.cs | 18 ++- CSVDownloader/Web/ItecController.cs | 20 ++- CSVDownloader/Web/ZeusController.cs | 18 ++- 7 files changed, 229 insertions(+), 28 deletions(-) create mode 100644 CSVDownloader/Exceptions/SpotNameNotMatchException.cs create mode 100644 CSVDownloader/Store/ParkingCreditCardAgenciesSpotIDErrorDAO.cs diff --git a/CSVDownloader/Exceptions/SpotNameNotMatchException.cs b/CSVDownloader/Exceptions/SpotNameNotMatchException.cs new file mode 100644 index 0000000..734fcf1 --- /dev/null +++ b/CSVDownloader/Exceptions/SpotNameNotMatchException.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Text; + + +using CSVDownloader.Store; +namespace CSVDownloader.Exceptions { + class SpotNameNotMatchException : Exception { + + private List error_list_; + public SpotNameNotMatchException(List error_list) { + error_list_ = error_list; + } + + public List GetList() { + return new List(error_list_); + + } + } +} diff --git a/CSVDownloader/Program.cs b/CSVDownloader/Program.cs index 3145dac..0856ddb 100644 --- a/CSVDownloader/Program.cs +++ b/CSVDownloader/Program.cs @@ -14,6 +14,7 @@ using CSVDownloader.Store; using CSVDownloader.Store.CreditCSVData; using CSVDownloader.Store.QRCSVData; using CSVDownloader.Web; +using CSVDownloader.Exceptions; using MySql.Data.MySqlClient; @@ -67,6 +68,8 @@ namespace CSVDownloader { private DaitoQRDataStore daito_qr_store_; + private ParkingCreditCardAgenciesSpotIDErrorDAO parking_credit_card_agencies_spotID_error_dao_; + private IConfigReader config_; private ChromeDriver driver_; @@ -110,6 +113,7 @@ namespace CSVDownloader { parking_credit_card_agencies_spotID_dao_ = new ParkingCreditCardAgenciesSpotIDDAO(conn_); + parking_credit_card_agencies_spotID_error_dao_ = new ParkingCreditCardAgenciesSpotIDErrorDAO(conn_); daito_credit_store_ = new DaitoCreitDataStore(conn_); zeus_credit_store_ = new ZeusCreditDataStore(conn_); itec_credit_store_ = new ItecCreditDataStore(conn_); @@ -122,6 +126,9 @@ namespace CSVDownloader { return "DBへのコネクト失敗"; } + // エラーリストを初期化する(全削除) + parking_credit_card_agencies_spotID_error_dao_.DeleteAll(); + // サイトごとにコントローラーを用意する。 MakeConttollers(); @@ -232,11 +239,6 @@ namespace CSVDownloader { } logger_.Info("ログアウト成功"); - // データ保存 - int delete_count_credit = 0; - int delete_count_qr = 0; - transaction_ = conn_.BeginTransaction(); - // ロード画面の表示 var load_html_path = Path.GetFullPath(@"static\html\load.html"); @@ -244,8 +246,35 @@ namespace CSVDownloader { // データリストの取得 - var credit_info_list = web_controller.GetCreditCSVDataList(); - var qr_info_list = web_controller.GetQRCSVDataList(); + // 取得に失敗したものはエラーリストとして登録する。 + bool list_get_success = true; + List credit_info_list = null; + List qr_info_list = null; + + try { + credit_info_list = web_controller.GetCreditCSVDataList(); + } catch (SpotNameNotMatchException e) { + + list_get_success = false; + parking_credit_card_agencies_spotID_error_dao_.Save(e.GetList()); + } + + try { + qr_info_list = web_controller.GetQRCSVDataList(); + } catch (SpotNameNotMatchException e) { + list_get_success = false; + parking_credit_card_agencies_spotID_error_dao_.Save(e.GetList()); + } + + + if (!list_get_success) { + throw new Exception("データリスト取得失敗"); + } + + // データ保存 + int delete_count_credit = 0; + int delete_count_qr = 0; + transaction_ = conn_.BeginTransaction(); // クレジット if (0 < credit_info_list.Count) { diff --git a/CSVDownloader/Store/ParkingCreditCardAgenciesSpotIDErrorDAO.cs b/CSVDownloader/Store/ParkingCreditCardAgenciesSpotIDErrorDAO.cs new file mode 100644 index 0000000..4f5df25 --- /dev/null +++ b/CSVDownloader/Store/ParkingCreditCardAgenciesSpotIDErrorDAO.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Data; + +using MySql.Data.MySqlClient; + +namespace CSVDownloader.Store { + + + class ParkingCreditCardAgenciesSpotIDError { + + public string creditcard_agencies_id = ""; + public string creditcard_agencies_spot_name = ""; + public DateTime upd_date = DateTime.Now; + public string upd_staff = "auto_tool"; + public DateTime reg_date = DateTime.Now; + public string reg_staff = "auto_tool"; + + public enum ColName { + CreditcardAgenciesID, + CreditcardAgenciesSpotName, + UpdDate, + UpdStaff, + RegDate, + RegStaff + }; + } + + class ParkingCreditCardAgenciesSpotIDErrorDAO : MySQL { + + + private static readonly string table_name_ = "parking_creditcard_agencies_spotid_error"; + public ParkingCreditCardAgenciesSpotIDErrorDAO(MySqlConnection conn) : base(conn) { + + } + + public void Save(List list) { + Code.ResultCode ret; + var table = new DataTable(); + + table.Columns.Add(ParkingCreditCardAgenciesSpotIDError.ColName.CreditcardAgenciesID.ToString()); + table.Columns.Add(ParkingCreditCardAgenciesSpotIDError.ColName.CreditcardAgenciesSpotName.ToString()); + table.Columns.Add(ParkingCreditCardAgenciesSpotIDError.ColName.UpdStaff.ToString()); + table.Columns.Add(ParkingCreditCardAgenciesSpotIDError.ColName.RegStaff.ToString()); + + foreach (ParkingCreditCardAgenciesSpotIDError data in list) { + var row = table.NewRow(); + row[ParkingCreditCardAgenciesSpotIDError.ColName.CreditcardAgenciesID.ToString()] = data.creditcard_agencies_id; + row[ParkingCreditCardAgenciesSpotIDError.ColName.CreditcardAgenciesSpotName.ToString()] = data.creditcard_agencies_spot_name; + row[ParkingCreditCardAgenciesSpotIDError.ColName.UpdStaff.ToString()] = data.upd_staff; + row[ParkingCreditCardAgenciesSpotIDError.ColName.RegStaff.ToString()] = data.reg_staff; + + table.Rows.Add(row); + } + + + ret = BulkInsertData(table_name_, table); + + if (ret != Code.ResultCode.OK) { + throw new Exception("登録失敗 紐づけエラー"); + } + + } + + public bool Exists(Code.CreditAgent agent, String spot_name) { + + string code = Code.CreditAgenciesMap.GetID(agent); + + var tbl = new DataTable(); + + string replace_id = "@id"; + string replace_spot_name = "@spot_name"; + string sql = $"select count(*) from {table_name_} " + + $"where CreditcardAgenciesID = {replace_id} ;" + + $"CreditcardAgenciesSpotName = {replace_spot_name};"; + + using (var adpt = new MySqlDataAdapter(sql, conn_)) { + + adpt.SelectCommand.Parameters.AddWithValue(replace_id, code); + adpt.SelectCommand.Parameters.AddWithValue(replace_spot_name, spot_name); + adpt.SelectCommand.Prepare(); + adpt.Fill(tbl); + } + + + return 0 < int.Parse(tbl.Rows[0][0].ToString()); + + } + + + public int DeleteAll() { + var bind_list = new List<(string, object)>(); + string sql = $"delete from {table_name_} "; + return DeleteData(sql, bind_list); + + } + public int Delete(Code.CreditAgent agent, String spot_name) { + + + string code = Code.CreditAgenciesMap.GetID(agent); + + var bind_list = new List<(string, object)>(); + + string replace_id = "@id"; + string replace_spot_name = "@spot_name"; + string sql = $"delete from {table_name_} " + + $"where CreditcardAgenciesID = {replace_id} ;" + + $"CreditcardAgenciesSpotName = {replace_spot_name};"; + + bind_list.Add((replace_id, code)); + bind_list.Add((replace_spot_name, spot_name)); + + return DeleteData(sql, bind_list); + } + } + +} \ No newline at end of file diff --git a/CSVDownloader/Web/DaitoController.cs b/CSVDownloader/Web/DaitoController.cs index bfb5ac7..5e4efb9 100644 --- a/CSVDownloader/Web/DaitoController.cs +++ b/CSVDownloader/Web/DaitoController.cs @@ -8,6 +8,7 @@ using OpenQA.Selenium.Chrome; using CSVDownloader.Code; using CSVDownloader.Store.CreditCSVData; using CSVDownloader.Store.QRCSVData; +using CSVDownloader.Exceptions; using ExpectedConditions = OpenQA.Selenium.Support.UI.ExpectedConditions; @@ -159,16 +160,20 @@ namespace CSVDownloader.Web { } if (failed_flg) { + var error_list = new List(); logger_.Error("失敗駐車場名"); - foreach (var ele in failed_parking_name_hs_table) { + error_list.Add(new Store.ParkingCreditCardAgenciesSpotIDError() { + creditcard_agencies_id = CreditAgenciesMap.GetID(agent_), + creditcard_agencies_spot_name = ele + }); logger_.Error($"駐車場 \"{ele}\""); } - throw new Exception("データ作成失敗"); - + throw new SpotNameNotMatchException(error_list); } + return result_list; } @@ -206,13 +211,18 @@ namespace CSVDownloader.Web { } if (failed_flg) { - logger_.Error("失敗駐車場名"); + var error_list = new List(); + logger_.Error("失敗駐車場名"); foreach (var ele in failed_parking_name_hs_table) { + error_list.Add(new Store.ParkingCreditCardAgenciesSpotIDError() { + creditcard_agencies_id = CreditAgenciesMap.GetID(agent_), + creditcard_agencies_spot_name = ele + }); logger_.Error($"駐車場 \"{ele}\""); } - throw new Exception("データ作成失敗"); + throw new SpotNameNotMatchException(error_list); } diff --git a/CSVDownloader/Web/HelloTechnoController.cs b/CSVDownloader/Web/HelloTechnoController.cs index 93b5ab6..6def3d0 100644 --- a/CSVDownloader/Web/HelloTechnoController.cs +++ b/CSVDownloader/Web/HelloTechnoController.cs @@ -7,6 +7,8 @@ using OpenQA.Selenium.Chrome; using CSVDownloader.Code; using CSVDownloader.Store.CreditCSVData; +using CSVDownloader.Exceptions; + using ExpectedConditions = OpenQA.Selenium.Support.UI.ExpectedConditions; namespace CSVDownloader.Web { @@ -201,14 +203,20 @@ namespace CSVDownloader.Web { if (failed_flg) { - logger_.Error("失敗駐車場名"); + if (failed_flg) { + var error_list = new List(); + logger_.Error("失敗駐車場名"); + foreach (var ele in failed_parking_name_hs_table) { + error_list.Add(new Store.ParkingCreditCardAgenciesSpotIDError() { + creditcard_agencies_id = CreditAgenciesMap.GetID(agent_), + creditcard_agencies_spot_name = ele + }); + logger_.Error($"駐車場 \"{ele}\""); + } - foreach (var ele in failed_parking_name_hs_table) { - logger_.Error($"駐車場 \"{ele}\""); + throw new SpotNameNotMatchException(error_list); } - throw new Exception("データ作成失敗"); - } } diff --git a/CSVDownloader/Web/ItecController.cs b/CSVDownloader/Web/ItecController.cs index 16bd4e2..34448ce 100644 --- a/CSVDownloader/Web/ItecController.cs +++ b/CSVDownloader/Web/ItecController.cs @@ -7,6 +7,8 @@ using OpenQA.Selenium.Chrome; using CSVDownloader.Code; using CSVDownloader.Store.CreditCSVData; +using CSVDownloader.Exceptions; + using ExpectedConditions = OpenQA.Selenium.Support.UI.ExpectedConditions; namespace CSVDownloader.Web { @@ -175,14 +177,20 @@ namespace CSVDownloader.Web { } if (failed_flg) { - logger_.Error("失敗駐車場名"); - - foreach (var ele in failed_parking_name_hs_table) { - logger_.Error($"駐車場 \"{ele}\""); + if (failed_flg) { + var error_list = new List(); + logger_.Error("失敗駐車場名"); + foreach (var ele in failed_parking_name_hs_table) { + error_list.Add(new Store.ParkingCreditCardAgenciesSpotIDError() { + creditcard_agencies_id = CreditAgenciesMap.GetID(agent_), + creditcard_agencies_spot_name = ele + }); + logger_.Error($"駐車場 \"{ele}\""); + } + + throw new SpotNameNotMatchException(error_list); } - throw new Exception("データ作成失敗"); - } return result_list; diff --git a/CSVDownloader/Web/ZeusController.cs b/CSVDownloader/Web/ZeusController.cs index ed6a526..c07862c 100644 --- a/CSVDownloader/Web/ZeusController.cs +++ b/CSVDownloader/Web/ZeusController.cs @@ -7,6 +7,8 @@ using OpenQA.Selenium.Chrome; using CSVDownloader.Code; using CSVDownloader.Store.CreditCSVData; +using CSVDownloader.Exceptions; + using ExpectedConditions = OpenQA.Selenium.Support.UI.ExpectedConditions; namespace CSVDownloader.Web { @@ -226,14 +228,20 @@ namespace CSVDownloader.Web { if (failed_flg) { - logger_.Error("失敗駐車場名"); + if (failed_flg) { + var error_list = new List(); + logger_.Error("失敗駐車場名"); + foreach (var ele in failed_parking_name_hs_table) { + error_list.Add(new Store.ParkingCreditCardAgenciesSpotIDError() { + creditcard_agencies_id = CreditAgenciesMap.GetID(agent_), + creditcard_agencies_spot_name = ele + }); + logger_.Error($"駐車場 \"{ele}\""); + } - foreach (var ele in failed_parking_name_hs_table) { - logger_.Error($"駐車場 \"{ele}\""); + throw new SpotNameNotMatchException(error_list); } - throw new Exception("データ作成失敗"); - } }