From 03d69b1706c17efc8bb8eccf69e8e67e79ca6e17 Mon Sep 17 00:00:00 2001 From: "sosuke.iwabuchi" Date: Thu, 5 Aug 2021 18:03:31 +0900 Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86PC=E3=81=AB=E5=88=9D=E5=9B=9E?= =?UTF-8?q?=E3=83=AA=E3=83=AA=E3=83=BC=E3=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CSVDownloader/Program.cs | 74 ++++++++--- .../Store/CreditCSVData/CSVDataStore.cs | 2 +- .../CreditCSVData/DaitoCreitDataStore.cs | 94 ++++++-------- .../HelloTechnoCreditDataStore.cs | 114 ++++++++--------- .../CreditCSVData/ItecCreditDataStore.cs | 105 +++++++-------- .../CreditCSVData/ZeusCreditDataStore.cs | 121 ++++++++---------- CSVDownloader/Store/MySQL.cs | 42 +++++- .../Store/QRCSVData/DaitoQRDataStore.cs | 82 +++++------- .../Store/QRCSVData/QRCSVDataStore.cs | 2 +- CSVDownloader/Web/DaitoController.cs | 87 +++++++++---- CSVDownloader/Web/HelloTechnoController.cs | 67 +++++++--- CSVDownloader/Web/ItecController.cs | 50 ++++++-- CSVDownloader/Web/WebController.cs | 6 +- CSVDownloader/Web/ZeusController.cs | 79 ++++++++---- 14 files changed, 529 insertions(+), 396 deletions(-) diff --git a/CSVDownloader/Program.cs b/CSVDownloader/Program.cs index 3ce2790..534cf38 100644 --- a/CSVDownloader/Program.cs +++ b/CSVDownloader/Program.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Reflection; -using System.Threading; +using System.Linq; using OpenQA.Selenium; using OpenQA.Selenium.Chrome; @@ -23,6 +23,13 @@ namespace CSVDownloader { class Program { static void Main(string[] args) { + + + // 作業ディレクトリを実行ファイルに合わせる。 + var exe_path = Assembly.GetEntryAssembly().Location; + var exe_directory_path = Path.GetDirectoryName(exe_path); + Directory.SetCurrentDirectory(exe_directory_path); + var controller = new Controller(); String ret = controller.Start(); @@ -72,6 +79,7 @@ namespace CSVDownloader { private Dictionary qr_datastore_map_ = new Dictionary(); + private int save_chunk_num_ = 100; public String Start() { @@ -83,11 +91,11 @@ namespace CSVDownloader { history_dao_ = new HistoryDAO(); config_ = new ConfigReader("config/config.ini"); var mysql_param = new MySqlConnectionParameter() { - host = "192.168.1.17", + host = "192.168.0.28", port = 3306, - database = "yp", - user = "sosuke", - password = ".1Satellite" + database = "ypark", + user = "ypuser2", + password = "ypp@ssw0rd2" }; try { @@ -144,7 +152,6 @@ namespace CSVDownloader { qr_datastore_map_.Add(controller.GetCreditAgent(), daito_qr_store_); } - // Zeus { var controller = new ZeusController(driver_); @@ -153,7 +160,6 @@ namespace CSVDownloader { web_controller_list_.Add(controller); credit_datastore_map_.Add(controller.GetCreditAgent(), zeus_credit_store_); } - // Itec { var controller = new ItecController(driver_); @@ -223,22 +229,49 @@ namespace CSVDownloader { int delete_count_credit = 0; int delete_count_qr = 0; transaction_ = conn_.BeginTransaction(); - // クレジット + + + // ロード画面の表示 + var load_html_path = Path.GetFullPath(@"static\html\load.html"); + driver_.Navigate().GoToUrl($"file://{load_html_path}"); + + + // データリストの取得 var credit_info_list = web_controller.GetCreditCSVDataList(); + var qr_info_list = web_controller.GetQRCSVDataList(); + + // クレジット if (0 < credit_info_list.Count) { + ShowTotalCount(credit_info_list.Count); var store = credit_datastore_map_[agent]; delete_count_credit = store.Delete(from, to); - foreach (var credit_info in credit_info_list) { - store.Save(credit_info); + var current_count = 0; + ShowCurrentCount(current_count); + var chunk_data_list = credit_info_list.Select((CreditCSVData data, int index) => new { data, index }) + .GroupBy(x => x.index / save_chunk_num_) + .Select(g => g.Select(r => r.data)); + foreach (var data_list in chunk_data_list) { + var list = data_list.ToList(); + store.Save(list); + current_count += list.Count; + ShowCurrentCount(current_count); } } // QR - var qr_info_list = web_controller.GetQRCSVDataList(); if (0 < qr_info_list.Count) { + ShowTotalCount(qr_info_list.Count); var store = qr_datastore_map_[agent]; delete_count_qr = store.Delete(from, to); - foreach (var qr_info in qr_info_list) { - store.Save(qr_info); + var current_count = 0; + ShowCurrentCount(current_count); + var chunk_data_list = qr_info_list.Select((QRCSVData data, int index) => new { data, index }) + .GroupBy(x => x.index / save_chunk_num_) + .Select(g => g.Select(r => r.data)); + foreach (var data_list in chunk_data_list) { + var list = data_list.ToList(); + store.Save(list); + current_count += list.Count; + ShowCurrentCount(current_count); } } @@ -261,6 +294,7 @@ namespace CSVDownloader { if (transaction_ != null) { transaction_.Rollback(); } + transaction_ = null; return Code.ResultCode.NG; } @@ -289,10 +323,6 @@ namespace CSVDownloader { from = now_date.AddMonths(-1); to = now_date; - if (history.Count != 0) { - var prev_date = history[0].date; - from = prev_date.AddMonths(-1); - } } else { var now_date = DateTime.Now.Date; @@ -332,7 +362,7 @@ namespace CSVDownloader { } private String GetArchiveFilename(Code.CreditAgent agent, DateTime now) { - return $"{agent.ToString()}_{now.ToString("yyyyMMddHHmmss")}.zip"; + return $"{agent}_{now.ToString("yyyyMMddHHmmss")}.zip"; } private void CreanDirectries() { @@ -345,5 +375,13 @@ namespace CSVDownloader { file.Delete(); } } + + private void ShowTotalCount(int num) { + driver_.ExecuteScript($"setTotal({num})"); + } + + private void ShowCurrentCount(int num) { + driver_.ExecuteScript($"setCount({num})"); + } } } diff --git a/CSVDownloader/Store/CreditCSVData/CSVDataStore.cs b/CSVDownloader/Store/CreditCSVData/CSVDataStore.cs index 9fefa0e..826d1ec 100644 --- a/CSVDownloader/Store/CreditCSVData/CSVDataStore.cs +++ b/CSVDownloader/Store/CreditCSVData/CSVDataStore.cs @@ -19,7 +19,7 @@ namespace CSVDownloader.Store.CreditCSVData { } - abstract public void Save(CreditCSVData obj); + abstract public void Save(List list); abstract public int Delete(DateTime from, DateTime to); } diff --git a/CSVDownloader/Store/CreditCSVData/DaitoCreitDataStore.cs b/CSVDownloader/Store/CreditCSVData/DaitoCreitDataStore.cs index 07ea2d1..63c9788 100644 --- a/CSVDownloader/Store/CreditCSVData/DaitoCreitDataStore.cs +++ b/CSVDownloader/Store/CreditCSVData/DaitoCreitDataStore.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Text; +using System.Data; using MySql.Data.MySqlClient; @@ -43,40 +43,6 @@ namespace CSVDownloader.Store.CreditCSVData { class DaitoCreitDataStore : CreditCSVDataStore { private static readonly String table_name_ = "creditcard_download_data_daito"; - private static readonly String insert_sql = $"insert into {table_name_} (" + - $"{CreditCSVDataDaito.ColName.SpotID.ToString()}," + - $"{CreditCSVDataDaito.ColName.ParkingName.ToString()}," + - $"{CreditCSVDataDaito.ColName.Developer.ToString()}," + - $"{CreditCSVDataDaito.ColName.AdjustType.ToString()}," + - $"{CreditCSVDataDaito.ColName.FeeType.ToString()}," + - $"{CreditCSVDataDaito.ColName.ReceptionDatetime.ToString()}," + - $"{CreditCSVDataDaito.ColName.Amount.ToString()}," + - $"{CreditCSVDataDaito.ColName.ReceptionNo.ToString()}," + - $"{CreditCSVDataDaito.ColName.ResponseNo.ToString()}," + - $"{CreditCSVDataDaito.ColName.ErrorCode1.ToString()}," + - $"{CreditCSVDataDaito.ColName.ErrorCode2.ToString()}," + - //$"{CSVDataDaito.ColName.UpdDate.ToString()}," + - $"{CreditCSVDataDaito.ColName.UpdStaff.ToString()}," + - //$"{CSVDataDaito.ColName.RegDate.ToString()}," + - $"{CreditCSVDataDaito.ColName.RegStaff.ToString()}" + - $" ) values (" + - $"@{CreditCSVDataDaito.ColName.SpotID.ToString()}," + - $"@{CreditCSVDataDaito.ColName.ParkingName.ToString()}," + - $"@{CreditCSVDataDaito.ColName.Developer.ToString()}," + - $"@{CreditCSVDataDaito.ColName.AdjustType.ToString()}," + - $"@{CreditCSVDataDaito.ColName.FeeType.ToString()}," + - $"@{CreditCSVDataDaito.ColName.ReceptionDatetime.ToString()}," + - $"@{CreditCSVDataDaito.ColName.Amount.ToString()}," + - $"@{CreditCSVDataDaito.ColName.ReceptionNo.ToString()}," + - $"@{CreditCSVDataDaito.ColName.ResponseNo.ToString()}," + - $"@{CreditCSVDataDaito.ColName.ErrorCode1.ToString()}," + - $"@{CreditCSVDataDaito.ColName.ErrorCode2.ToString()}," + - //$"@{CSVDataDaito.ColName.UpdDate.ToString()}," + - $"@{CreditCSVDataDaito.ColName.UpdStaff.ToString()}," + - //$"@{CSVDataDaito.ColName.RegDate.ToString()}" + - $"@{CreditCSVDataDaito.ColName.RegStaff.ToString()}" + - $");"; - private String delete_sql_ = $"delete from {table_name_} where " + @@ -89,28 +55,48 @@ namespace CSVDownloader.Store.CreditCSVData { } - public override void Save(CreditCSVData obj) { - var data = (CreditCSVDataDaito)obj; + public override void Save(List list) { + Code.ResultCode ret; + var table = new DataTable(); + + table.Columns.Add($"{CreditCSVDataDaito.ColName.SpotID}"); + table.Columns.Add($"{CreditCSVDataDaito.ColName.ParkingName}"); + table.Columns.Add($"{CreditCSVDataDaito.ColName.Developer}"); + table.Columns.Add($"{CreditCSVDataDaito.ColName.AdjustType}"); + table.Columns.Add($"{CreditCSVDataDaito.ColName.FeeType}"); + table.Columns.Add($"{CreditCSVDataDaito.ColName.ReceptionDatetime}"); + table.Columns.Add($"{CreditCSVDataDaito.ColName.Amount}"); + table.Columns.Add($"{CreditCSVDataDaito.ColName.ReceptionNo}"); + table.Columns.Add($"{CreditCSVDataDaito.ColName.ResponseNo}"); + table.Columns.Add($"{CreditCSVDataDaito.ColName.ErrorCode1}"); + table.Columns.Add($"{CreditCSVDataDaito.ColName.ErrorCode2}"); + table.Columns.Add($"{CreditCSVDataDaito.ColName.UpdStaff}"); + table.Columns.Add($"{CreditCSVDataDaito.ColName.RegStaff}"); + + foreach (CreditCSVDataDaito data in list) { + var row = table.NewRow(); + row[$"{CreditCSVDataDaito.ColName.SpotID}"] = data.spot_id; + row[$"{CreditCSVDataDaito.ColName.ParkingName}"] = data.parking_name; + row[$"{CreditCSVDataDaito.ColName.Developer}"] = data.developer; + row[$"{CreditCSVDataDaito.ColName.AdjustType}"] = data.adjust_type; + row[$"{CreditCSVDataDaito.ColName.FeeType}"] = data.fee_type; + row[$"{CreditCSVDataDaito.ColName.ReceptionDatetime}"] = data.reception_datetime; + row[$"{CreditCSVDataDaito.ColName.Amount}"] = data.amount; + row[$"{CreditCSVDataDaito.ColName.ReceptionNo}"] = data.reception_no; + row[$"{CreditCSVDataDaito.ColName.ResponseNo}"] = data.response_no; + row[$"{CreditCSVDataDaito.ColName.ErrorCode1}"] = data.error_code1; + row[$"{CreditCSVDataDaito.ColName.ErrorCode2}"] = data.error_code2; + row[$"{CreditCSVDataDaito.ColName.UpdStaff}"] = data.upd_staff; + row[$"{CreditCSVDataDaito.ColName.RegStaff}"] = data.reg_staff; + + table.Rows.Add(row); + } - var bindlist = new List<(String, object)> { - (CreditCSVDataDaito.ColName.SpotID.ToString(), data.spot_id), - (CreditCSVDataDaito.ColName.ParkingName.ToString(), data.parking_name), - (CreditCSVDataDaito.ColName.Developer.ToString(), data.developer), - (CreditCSVDataDaito.ColName.AdjustType.ToString(), data.adjust_type), - (CreditCSVDataDaito.ColName.FeeType.ToString(), data.fee_type), - (CreditCSVDataDaito.ColName.ReceptionDatetime.ToString(), data.reception_datetime), - (CreditCSVDataDaito.ColName.Amount.ToString(), data.amount), - (CreditCSVDataDaito.ColName.ReceptionNo.ToString(), data.reception_no), - (CreditCSVDataDaito.ColName.ResponseNo.ToString(), data.response_no), - (CreditCSVDataDaito.ColName.ErrorCode1.ToString(), data.error_code1), - (CreditCSVDataDaito.ColName.ErrorCode2.ToString(), data.error_code2), - (CreditCSVDataDaito.ColName.UpdStaff.ToString(), data.upd_staff), - (CreditCSVDataDaito.ColName.RegStaff.ToString(), data.reg_staff) - }; - var ret = InsertData(insert_sql, bindlist); + ret = BulkInsertData(table_name_, table); + if (ret != Code.ResultCode.OK) { - throw new Exception("登録失敗 大都"); + throw new Exception("登録失敗 Daito"); } } diff --git a/CSVDownloader/Store/CreditCSVData/HelloTechnoCreditDataStore.cs b/CSVDownloader/Store/CreditCSVData/HelloTechnoCreditDataStore.cs index 59492b0..1d8ea9f 100644 --- a/CSVDownloader/Store/CreditCSVData/HelloTechnoCreditDataStore.cs +++ b/CSVDownloader/Store/CreditCSVData/HelloTechnoCreditDataStore.cs @@ -1,12 +1,13 @@ using System; using System.Collections.Generic; +using System.Data; using MySql.Data.MySqlClient; namespace CSVDownloader.Store.CreditCSVData { - class CSVDataHelloTechno : CreditCSVData { + class CreditCSVDataHelloTechno : CreditCSVData { public String spot_i_d = ""; public DateTime register_datetime = DateTime.Now; public String user_code = ""; @@ -44,86 +45,71 @@ namespace CSVDownloader.Store.CreditCSVData { } class HelloTechnoCreditDataStore : CreditCSVDataStore { private static readonly String table_name_ = "creditcard_download_data_hellotechno"; - private static readonly String insert_sql = $"insert into {table_name_} (" + - $"{CSVDataHelloTechno.ColName.SpotID}, " + - $"{CSVDataHelloTechno.ColName.RegisterDatetime}, " + - $"{CSVDataHelloTechno.ColName.UserCode}, " + - $"{CSVDataHelloTechno.ColName.ParkingCode}, " + - $"{CSVDataHelloTechno.ColName.DeviceNo}, " + - $"{CSVDataHelloTechno.ColName.AdjustNo}, " + - $"{CSVDataHelloTechno.ColName.Trade}, " + - $"{CSVDataHelloTechno.ColName.Amount}, " + - $"{CSVDataHelloTechno.ColName.CardCompanyName}, " + - $"{CSVDataHelloTechno.ColName.ApprovalNo}, " + - $"{CSVDataHelloTechno.ColName.ResponseNo}, " + - $"{CSVDataHelloTechno.ColName.CancelDate}, " + - $"{CSVDataHelloTechno.ColName.Error}, " + - //$"{CSVDataHelloTechno.ColName.UpdDate}, " + - $"{CSVDataHelloTechno.ColName.UpdStaff}, " + - //$"{CSVDataHelloTechno.ColName.RegDate}, " + - $"{CSVDataHelloTechno.ColName.RegStaff} " + - $" ) values (" + - $"@{CSVDataHelloTechno.ColName.SpotID}, " + - $"@{CSVDataHelloTechno.ColName.RegisterDatetime}, " + - $"@{CSVDataHelloTechno.ColName.UserCode}, " + - $"@{CSVDataHelloTechno.ColName.ParkingCode}, " + - $"@{CSVDataHelloTechno.ColName.DeviceNo}, " + - $"@{CSVDataHelloTechno.ColName.AdjustNo}, " + - $"@{CSVDataHelloTechno.ColName.Trade}, " + - $"@{CSVDataHelloTechno.ColName.Amount}, " + - $"@{CSVDataHelloTechno.ColName.CardCompanyName}, " + - $"@{CSVDataHelloTechno.ColName.ApprovalNo}, " + - $"@{CSVDataHelloTechno.ColName.ResponseNo}, " + - $"@{CSVDataHelloTechno.ColName.CancelDate}, " + - $"@{CSVDataHelloTechno.ColName.Error}, " + - //$"@{CSVDataHelloTechno.ColName.UpdDate}, " + - $"@{CSVDataHelloTechno.ColName.UpdStaff}, " + - //$"@{CSVDataHelloTechno.ColName.RegDate}, " + - $"@{CSVDataHelloTechno.ColName.RegStaff} " + - $");"; private String delete_sql_ = $"delete from {table_name_} where " + - $"{CSVDataHelloTechno.ColName.RegisterDatetime} between " + - $"@From{CSVDataHelloTechno.ColName.RegisterDatetime} and " + - $"@To{CSVDataHelloTechno.ColName.RegisterDatetime};"; + $"{CreditCSVDataHelloTechno.ColName.RegisterDatetime} between " + + $"@From{CreditCSVDataHelloTechno.ColName.RegisterDatetime} and " + + $"@To{CreditCSVDataHelloTechno.ColName.RegisterDatetime};"; public HelloTechnoCreditDataStore(MySqlConnection conn) : base(conn) { } - public override void Save(CreditCSVData obj) { - var data = (CSVDataHelloTechno)obj; - var bindlist = new List<(String, object)> { - (CSVDataHelloTechno.ColName.SpotID.ToString(), data.spot_id), - (CSVDataHelloTechno.ColName.RegisterDatetime.ToString(), data.register_datetime.ToString()), - (CSVDataHelloTechno.ColName.UserCode.ToString(), data.user_code), - (CSVDataHelloTechno.ColName.ParkingCode.ToString(), data.parking_code), - (CSVDataHelloTechno.ColName.DeviceNo.ToString(), data.device_no), - (CSVDataHelloTechno.ColName.AdjustNo.ToString(), data.adjust_no), - (CSVDataHelloTechno.ColName.Trade.ToString(), data.trade), - (CSVDataHelloTechno.ColName.Amount.ToString(), data.amount), - (CSVDataHelloTechno.ColName.CardCompanyName.ToString(), data.card_company_name), - (CSVDataHelloTechno.ColName.ApprovalNo.ToString(), data.approval_no), - (CSVDataHelloTechno.ColName.ResponseNo.ToString(), data.response_no), - (CSVDataHelloTechno.ColName.CancelDate.ToString(), data.cancel_date != null ? ((DateTime)data.cancel_date).ToString(): null), - (CSVDataHelloTechno.ColName.Error.ToString(), data.error), - (CSVDataHelloTechno.ColName.UpdStaff.ToString(), data.upd_staff), - (CSVDataHelloTechno.ColName.RegStaff.ToString(), data.reg_staff), + public override void Save(List list) { + Code.ResultCode ret; + var table = new DataTable(); + + table.Columns.Add($"{CreditCSVDataHelloTechno.ColName.SpotID}"); + table.Columns.Add($"{CreditCSVDataHelloTechno.ColName.RegisterDatetime}"); + table.Columns.Add($"{CreditCSVDataHelloTechno.ColName.UserCode}"); + table.Columns.Add($"{CreditCSVDataHelloTechno.ColName.ParkingCode}"); + table.Columns.Add($"{CreditCSVDataHelloTechno.ColName.DeviceNo}"); + table.Columns.Add($"{CreditCSVDataHelloTechno.ColName.AdjustNo}"); + table.Columns.Add($"{CreditCSVDataHelloTechno.ColName.Trade}"); + table.Columns.Add($"{CreditCSVDataHelloTechno.ColName.Amount}"); + table.Columns.Add($"{CreditCSVDataHelloTechno.ColName.CardCompanyName}"); + table.Columns.Add($"{CreditCSVDataHelloTechno.ColName.ApprovalNo}"); + table.Columns.Add($"{CreditCSVDataHelloTechno.ColName.ResponseNo}"); + table.Columns.Add($"{CreditCSVDataHelloTechno.ColName.CancelDate}"); + table.Columns.Add($"{CreditCSVDataHelloTechno.ColName.Error}"); + table.Columns.Add($"{CreditCSVDataHelloTechno.ColName.UpdStaff}"); + table.Columns.Add($"{CreditCSVDataHelloTechno.ColName.RegStaff}"); + + foreach (CreditCSVDataHelloTechno data in list) { + var row = table.NewRow(); + row[$"{CreditCSVDataHelloTechno.ColName.SpotID}"] = data.spot_id; + row[$"{CreditCSVDataHelloTechno.ColName.RegisterDatetime}"] = data.register_datetime; + row[$"{CreditCSVDataHelloTechno.ColName.UserCode}"] = data.user_code; + row[$"{CreditCSVDataHelloTechno.ColName.ParkingCode}"] = data.parking_code; + row[$"{CreditCSVDataHelloTechno.ColName.DeviceNo}"] = data.device_no; + row[$"{CreditCSVDataHelloTechno.ColName.AdjustNo}"] = data.adjust_no; + row[$"{CreditCSVDataHelloTechno.ColName.Trade}"] = data.trade; + row[$"{CreditCSVDataHelloTechno.ColName.Amount}"] = data.amount; + row[$"{CreditCSVDataHelloTechno.ColName.CardCompanyName}"] = data.card_company_name; + row[$"{CreditCSVDataHelloTechno.ColName.ApprovalNo}"] = data.approval_no; + row[$"{CreditCSVDataHelloTechno.ColName.ResponseNo}"] = data.response_no; + row[$"{CreditCSVDataHelloTechno.ColName.CancelDate}"] = data.cancel_date; + row[$"{CreditCSVDataHelloTechno.ColName.Error}"] = data.error; + row[$"{CreditCSVDataHelloTechno.ColName.UpdStaff}"] = data.upd_staff; + row[$"{CreditCSVDataHelloTechno.ColName.RegStaff}"] = data.reg_staff; + + table.Rows.Add(row); + } - }; - var ret = InsertData(insert_sql, bindlist); + ret = BulkInsertData(table_name_, table); + if (ret != Code.ResultCode.OK) { - throw new Exception("登録失敗 Zeus"); + throw new Exception("登録失敗 HelloTechno"); } } public override int Delete(DateTime from, DateTime to) { var bindlist = new List<(String, object)> { - ("From"+CSVDataHelloTechno.ColName.RegisterDatetime.ToString(), from.ToString("yyyy-MM-dd")), - ("To"+CSVDataHelloTechno.ColName.RegisterDatetime.ToString(), to.AddDays(1).ToString("yyyy-MM-dd")) + ("From"+CreditCSVDataHelloTechno.ColName.RegisterDatetime.ToString(), from.ToString("yyyy-MM-dd")), + ("To"+CreditCSVDataHelloTechno.ColName.RegisterDatetime.ToString(), to.AddDays(1).ToString("yyyy-MM-dd")) }; diff --git a/CSVDownloader/Store/CreditCSVData/ItecCreditDataStore.cs b/CSVDownloader/Store/CreditCSVData/ItecCreditDataStore.cs index d7eca6e..cd55acb 100644 --- a/CSVDownloader/Store/CreditCSVData/ItecCreditDataStore.cs +++ b/CSVDownloader/Store/CreditCSVData/ItecCreditDataStore.cs @@ -1,12 +1,13 @@ using System; using System.Collections.Generic; +using System.Data; using MySql.Data.MySqlClient; namespace CSVDownloader.Store.CreditCSVData { - class CSVDataItec : CreditCSVData { + class CreditCSVDataItec : CreditCSVData { public String code = ""; public String parking_name = ""; public String device_type = ""; @@ -38,79 +39,67 @@ namespace CSVDownloader.Store.CreditCSVData { } class ItecCreditDataStore : CreditCSVDataStore { private static readonly String table_name_ = "creditcard_download_data_itec"; - private static readonly String insert_sql = $"insert into {table_name_} (" + - $"{CSVDataItec.ColName.SpotID}," + - $"{CSVDataItec.ColName.Code}," + - $"{CSVDataItec.ColName.ParkingName}," + - $"{CSVDataItec.ColName.DeviceType}," + - $"{CSVDataItec.ColName.UseDatetime}," + - $"{CSVDataItec.ColName.Trade}," + - $"{CSVDataItec.ColName.CardCompanyName}," + - $"{CSVDataItec.ColName.Amount}," + - $"{CSVDataItec.ColName.TaxSendFee}," + - $"{CSVDataItec.ColName.TotalAmount}," + - $"{CSVDataItec.ColName.ErrorCode}," + - //$"{CSVDataItec.ColName.UpdDate}," + - $"{CSVDataItec.ColName.UpdStaff}," + - //$"{CSVDataItec.ColName.RegDate}," + - $"{CSVDataItec.ColName.RegStaff}" + - $" ) values (" + - $"@{CSVDataItec.ColName.SpotID}," + - $"@{CSVDataItec.ColName.Code}," + - $"@{CSVDataItec.ColName.ParkingName}," + - $"@{CSVDataItec.ColName.DeviceType}," + - $"@{CSVDataItec.ColName.UseDatetime}," + - $"@{CSVDataItec.ColName.Trade}," + - $"@{CSVDataItec.ColName.CardCompanyName}," + - $"@{CSVDataItec.ColName.Amount}," + - $"@{CSVDataItec.ColName.TaxSendFee}," + - $"@{CSVDataItec.ColName.TotalAmount}," + - $"@{CSVDataItec.ColName.ErrorCode}," + - //$"@{CSVDataItec.ColName.UpdDate}," + - $"@{CSVDataItec.ColName.UpdStaff}," + - //$"@{CSVDataItec.ColName.RegDate}," + - $"@{CSVDataItec.ColName.RegStaff}" + - $");"; private String delete_sql_ = $"delete from {table_name_} where " + - $"{CSVDataItec.ColName.UseDatetime} between " + - $"@From{CSVDataItec.ColName.UseDatetime} and " + - $"@To{CSVDataItec.ColName.UseDatetime};"; + $"{CreditCSVDataItec.ColName.UseDatetime} between " + + $"@From{CreditCSVDataItec.ColName.UseDatetime} and " + + $"@To{CreditCSVDataItec.ColName.UseDatetime};"; public ItecCreditDataStore(MySqlConnection conn) : base(conn) { } - public override void Save(CreditCSVData obj) { - var data = (CSVDataItec)obj; - var bindlist = new List<(String, object)> { - (CSVDataItec.ColName.SpotID.ToString(), data.spot_id), - (CSVDataItec.ColName.Code.ToString(), data.code), - (CSVDataItec.ColName.ParkingName.ToString(), data.parking_name), - (CSVDataItec.ColName.DeviceType.ToString(), data.device_type), - (CSVDataItec.ColName.UseDatetime.ToString(), data.use_datetime.ToString()), - (CSVDataItec.ColName.Trade.ToString(), data.trade), - (CSVDataItec.ColName.CardCompanyName.ToString(), data.card_company_name), - (CSVDataItec.ColName.Amount.ToString(), data.amount), - (CSVDataItec.ColName.TaxSendFee.ToString(), data.tax_send_fee), - (CSVDataItec.ColName.TotalAmount.ToString(), data.total_amount), - (CSVDataItec.ColName.ErrorCode.ToString(), data.error_code), - (CSVDataItec.ColName.UpdStaff.ToString(), data.upd_staff), - (CSVDataItec.ColName.RegStaff.ToString(), data.reg_staff) - }; + public override void Save(List list) { + Code.ResultCode ret; + var table = new DataTable(); + + table.Columns.Add($"{CreditCSVDataItec.ColName.SpotID}"); + table.Columns.Add($"{CreditCSVDataItec.ColName.Code}"); + table.Columns.Add($"{CreditCSVDataItec.ColName.ParkingName}"); + table.Columns.Add($"{CreditCSVDataItec.ColName.DeviceType}"); + table.Columns.Add($"{CreditCSVDataItec.ColName.UseDatetime}"); + table.Columns.Add($"{CreditCSVDataItec.ColName.Trade}"); + table.Columns.Add($"{CreditCSVDataItec.ColName.CardCompanyName}"); + table.Columns.Add($"{CreditCSVDataItec.ColName.Amount}"); + table.Columns.Add($"{CreditCSVDataItec.ColName.TaxSendFee}"); + table.Columns.Add($"{CreditCSVDataItec.ColName.TotalAmount}"); + table.Columns.Add($"{CreditCSVDataItec.ColName.ErrorCode}"); + table.Columns.Add($"{CreditCSVDataItec.ColName.UpdStaff}"); + table.Columns.Add($"{CreditCSVDataItec.ColName.RegStaff}"); + + foreach (CreditCSVDataItec data in list) { + var row = table.NewRow(); + row[$"{CreditCSVDataItec.ColName.SpotID}"] = data.spot_id; + row[$"{CreditCSVDataItec.ColName.Code}"] = data.code; + row[$"{CreditCSVDataItec.ColName.ParkingName}"] = data.parking_name; + row[$"{CreditCSVDataItec.ColName.DeviceType}"] = data.device_type; + row[$"{CreditCSVDataItec.ColName.UseDatetime}"] = data.use_datetime; + row[$"{CreditCSVDataItec.ColName.Trade}"] = data.trade; + row[$"{CreditCSVDataItec.ColName.CardCompanyName}"] = data.card_company_name; + row[$"{CreditCSVDataItec.ColName.Amount}"] = data.amount; + row[$"{CreditCSVDataItec.ColName.TaxSendFee}"] = data.tax_send_fee; + row[$"{CreditCSVDataItec.ColName.TotalAmount}"] = data.total_amount; + row[$"{CreditCSVDataItec.ColName.ErrorCode}"] = data.error_code; + row[$"{CreditCSVDataItec.ColName.UpdStaff}"] = data.upd_staff; + row[$"{CreditCSVDataItec.ColName.RegStaff}"] = data.reg_staff; + + table.Rows.Add(row); + } + + + ret = BulkInsertData(table_name_, table); - var ret = InsertData(insert_sql, bindlist); if (ret != Code.ResultCode.OK) { - throw new Exception("登録失敗 Zeus"); + throw new Exception("登録失敗 Itec"); } } public override int Delete(DateTime from, DateTime to) { var bindlist = new List<(String, object)> { - ("From"+CSVDataItec.ColName.UseDatetime.ToString(), from.ToString("yyyy-MM-dd")), - ("To"+CSVDataItec.ColName.UseDatetime.ToString(), to.AddDays(1).ToString("yyyy-MM-dd")) + ("From"+CreditCSVDataItec.ColName.UseDatetime.ToString(), from.ToString("yyyy-MM-dd")), + ("To"+CreditCSVDataItec.ColName.UseDatetime.ToString(), to.AddDays(1).ToString("yyyy-MM-dd")) }; var delete_count = DeleteData(delete_sql_, bindlist); diff --git a/CSVDownloader/Store/CreditCSVData/ZeusCreditDataStore.cs b/CSVDownloader/Store/CreditCSVData/ZeusCreditDataStore.cs index a79549d..12a7ca7 100644 --- a/CSVDownloader/Store/CreditCSVData/ZeusCreditDataStore.cs +++ b/CSVDownloader/Store/CreditCSVData/ZeusCreditDataStore.cs @@ -1,7 +1,8 @@ using System; using System.Collections.Generic; using System.Text; - +using System.Data; +using System.Linq; using MySql.Data.MySqlClient; @@ -54,52 +55,6 @@ namespace CSVDownloader.Store.CreditCSVData { class ZeusCreditDataStore : CreditCSVDataStore { private static readonly String table_name_ = "creditcard_download_data_zeus"; - private static readonly String insert_sql = $"insert into {table_name_} (" + - $"{CreditCSVDataZeus.ColName.SpotID}," + - $"{CreditCSVDataZeus.ColName.UseDatetime}," + - $"{CreditCSVDataZeus.ColName.IP}," + - $"{CreditCSVDataZeus.ColName.DeviceNo}," + - $"{CreditCSVDataZeus.ColName.ReceiptNo}," + - $"{CreditCSVDataZeus.ColName.CertificateNo}," + - $"{CreditCSVDataZeus.ColName.Status}," + - $"{CreditCSVDataZeus.ColName.ErrorMessage}," + - $"{CreditCSVDataZeus.ColName.Amount}," + - $"{CreditCSVDataZeus.ColName.CardNo}," + - $"{CreditCSVDataZeus.ColName.ExpirationDate}," + - $"{CreditCSVDataZeus.ColName.Brand}," + - $"{CreditCSVDataZeus.ColName.PaymentType}," + - $"{CreditCSVDataZeus.ColName.JISInfo}," + - $"{CreditCSVDataZeus.ColName.Test}," + - $"{CreditCSVDataZeus.ColName.OrderNo}," + - //$"{CSVDataZeus.ColName.UpdDate}," + - $"{CreditCSVDataZeus.ColName.UpdStaff}," + - //$"{CSVDataZeus.ColName.RegDate.ToString()}," + - $"{CreditCSVDataZeus.ColName.RegStaff}" + - $" ) values (" + - $"@{CreditCSVDataZeus.ColName.SpotID}," + - $"@{CreditCSVDataZeus.ColName.UseDatetime}," + - $"@{CreditCSVDataZeus.ColName.IP}," + - $"@{CreditCSVDataZeus.ColName.DeviceNo}," + - $"@{CreditCSVDataZeus.ColName.ReceiptNo}," + - $"@{CreditCSVDataZeus.ColName.CertificateNo}," + - $"@{CreditCSVDataZeus.ColName.Status}," + - $"@{CreditCSVDataZeus.ColName.ErrorMessage}," + - $"@{CreditCSVDataZeus.ColName.Amount}," + - $"@{CreditCSVDataZeus.ColName.CardNo}," + - $"@{CreditCSVDataZeus.ColName.ExpirationDate}," + - $"@{CreditCSVDataZeus.ColName.Brand}," + - $"@{CreditCSVDataZeus.ColName.PaymentType}," + - $"@{CreditCSVDataZeus.ColName.JISInfo}," + - $"@{CreditCSVDataZeus.ColName.Test}," + - $"@{CreditCSVDataZeus.ColName.OrderNo}," + - //$"{CSVDataZeus.ColName.UpdDate}," + - $"@{CreditCSVDataZeus.ColName.UpdStaff}," + - //$"{CSVDataZeus.ColName.RegDate}," + - $"@{CreditCSVDataZeus.ColName.RegStaff}" + - $");"; - - - private String delete_sql_ = $"delete from {table_name_} where " + $"{CreditCSVDataZeus.ColName.UseDatetime} between " + $"@From{CreditCSVDataZeus.ColName.UseDatetime} and " + @@ -110,34 +65,60 @@ namespace CSVDownloader.Store.CreditCSVData { } - public override void Save(CreditCSVData obj) { - var data = (CreditCSVDataZeus)obj; + public override void Save(List list) { + Code.ResultCode ret; + var table = new DataTable(); + + table.Columns.Add(CreditCSVDataZeus.ColName.SpotID.ToString()); + table.Columns.Add(CreditCSVDataZeus.ColName.UseDatetime.ToString()); + table.Columns.Add(CreditCSVDataZeus.ColName.IP.ToString()); + table.Columns.Add(CreditCSVDataZeus.ColName.DeviceNo.ToString()); + table.Columns.Add(CreditCSVDataZeus.ColName.ReceiptNo.ToString()); + table.Columns.Add(CreditCSVDataZeus.ColName.CertificateNo.ToString()); + table.Columns.Add(CreditCSVDataZeus.ColName.Status.ToString()); + table.Columns.Add(CreditCSVDataZeus.ColName.ErrorMessage.ToString()); + table.Columns.Add(CreditCSVDataZeus.ColName.Amount.ToString()); + table.Columns.Add(CreditCSVDataZeus.ColName.CardNo.ToString()); + table.Columns.Add(CreditCSVDataZeus.ColName.ExpirationDate.ToString()); + table.Columns.Add(CreditCSVDataZeus.ColName.Brand.ToString()); + table.Columns.Add(CreditCSVDataZeus.ColName.PaymentType.ToString()); + table.Columns.Add(CreditCSVDataZeus.ColName.JISInfo.ToString()); + table.Columns.Add(CreditCSVDataZeus.ColName.Test.ToString()); + table.Columns.Add(CreditCSVDataZeus.ColName.OrderNo.ToString()); + table.Columns.Add(CreditCSVDataZeus.ColName.UpdStaff.ToString()); + table.Columns.Add(CreditCSVDataZeus.ColName.RegStaff.ToString()); + + foreach (CreditCSVDataZeus data in list) { + var row = table.NewRow(); + row[CreditCSVDataZeus.ColName.SpotID.ToString()] = data.spot_id; + row[CreditCSVDataZeus.ColName.UseDatetime.ToString()] = data.use_datetime; + row[CreditCSVDataZeus.ColName.IP.ToString()] = data.ip; + row[CreditCSVDataZeus.ColName.DeviceNo.ToString()] = data.device_no; + row[CreditCSVDataZeus.ColName.ReceiptNo.ToString()] = data.receipt_no; + row[CreditCSVDataZeus.ColName.CertificateNo.ToString()] = data.certificate_no; + row[CreditCSVDataZeus.ColName.Status.ToString()] = data.status; + row[CreditCSVDataZeus.ColName.ErrorMessage.ToString()] = data.error_message; + row[CreditCSVDataZeus.ColName.Amount.ToString()] = data.amount; + row[CreditCSVDataZeus.ColName.CardNo.ToString()] = data.card_no; + row[CreditCSVDataZeus.ColName.ExpirationDate.ToString()] = data.expiration_date; + row[CreditCSVDataZeus.ColName.Brand.ToString()] = data.brand; + row[CreditCSVDataZeus.ColName.PaymentType.ToString()] = data.payment_type; + row[CreditCSVDataZeus.ColName.JISInfo.ToString()] = data.jis_info; + row[CreditCSVDataZeus.ColName.Test.ToString()] = data.test; + row[CreditCSVDataZeus.ColName.OrderNo.ToString()] = data.order_no; + row[CreditCSVDataZeus.ColName.UpdStaff.ToString()] = data.upd_staff; + row[CreditCSVDataZeus.ColName.RegStaff.ToString()] = data.reg_staff; + + table.Rows.Add(row); + } - var bindlist = new List<(String, object)> { - (CreditCSVDataZeus.ColName.SpotID.ToString(), data.spot_id), - (CreditCSVDataZeus.ColName.UseDatetime.ToString(), data.use_datetime.ToString()), - (CreditCSVDataZeus.ColName.IP.ToString(), data.ip), - (CreditCSVDataZeus.ColName.DeviceNo.ToString(), data.device_no), - (CreditCSVDataZeus.ColName.ReceiptNo.ToString(), data.receipt_no), - (CreditCSVDataZeus.ColName.CertificateNo.ToString(), data.certificate_no), - (CreditCSVDataZeus.ColName.Status.ToString(), data.status), - (CreditCSVDataZeus.ColName.ErrorMessage.ToString(), data.error_message), - (CreditCSVDataZeus.ColName.Amount.ToString(), data.amount), - (CreditCSVDataZeus.ColName.CardNo.ToString(), data.card_no), - (CreditCSVDataZeus.ColName.ExpirationDate.ToString(), data.expiration_date), - (CreditCSVDataZeus.ColName.Brand.ToString(), data.brand), - (CreditCSVDataZeus.ColName.PaymentType.ToString(), data.payment_type), - (CreditCSVDataZeus.ColName.JISInfo.ToString(), data.jis_info), - (CreditCSVDataZeus.ColName.Test.ToString(), data.test), - (CreditCSVDataZeus.ColName.OrderNo.ToString(), data.order_no), - (CreditCSVDataZeus.ColName.UpdStaff.ToString(), data.upd_staff), - (CreditCSVDataZeus.ColName.RegStaff.ToString(), data.reg_staff) - }; - var ret = InsertData(insert_sql, bindlist); + ret = BulkInsertData(table_name_, table); + if (ret != Code.ResultCode.OK) { throw new Exception("登録失敗 Zeus"); } + } public override int Delete(DateTime from, DateTime to) { diff --git a/CSVDownloader/Store/MySQL.cs b/CSVDownloader/Store/MySQL.cs index 66dacf4..13164c6 100644 --- a/CSVDownloader/Store/MySQL.cs +++ b/CSVDownloader/Store/MySQL.cs @@ -1,7 +1,10 @@ using System; using System.Collections.Generic; +using System.Data; using System.Text; using MySql.Data.MySqlClient; + + namespace CSVDownloader.Store { class MySqlConnectionParameter { @@ -47,9 +50,44 @@ namespace CSVDownloader.Store { return ret; } - protected Code.ResultCode InsertData(String sql, List<(String, object)> bindlist) { - var ret = ExecuteNonQuery(sql, bindlist); + + protected Code.ResultCode BulkInsertData(String tablename, DataTable table) { + + // SQL のビルド + var sql = new StringBuilder(); + var bind_list = new List<(String, object)>(); + sql.Append($"insert into {tablename} ("); + + for (int i = 0; i < table.Columns.Count; i++) { + if (i != 0) { + sql.Append(","); + } + sql.Append($"{table.Columns[i]}"); + } + sql.Append($") values "); + + + for (int row = 0; row < table.Rows.Count; row++) { + if (row != 0) { + sql.Append(","); + } + sql.Append("("); + for (int col = 0; col < table.Columns.Count; col++) { + if (col != 0) { + sql.Append(","); + } + String key = $"@{table.Columns[col]}{row}"; + sql.Append(key); + + + bind_list.Add((key, table.Rows[row][table.Columns[col]])); + } + sql.Append(")"); + } + + // 値のセット + var ret = ExecuteNonQuery(sql.ToString(), bind_list); if (ret == -1) { return Code.ResultCode.NG; } diff --git a/CSVDownloader/Store/QRCSVData/DaitoQRDataStore.cs b/CSVDownloader/Store/QRCSVData/DaitoQRDataStore.cs index 42375a4..83ccb2b 100644 --- a/CSVDownloader/Store/QRCSVData/DaitoQRDataStore.cs +++ b/CSVDownloader/Store/QRCSVData/DaitoQRDataStore.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Text; +using System.Data; using MySql.Data.MySqlClient; @@ -37,35 +37,6 @@ namespace CSVDownloader.Store.QRCSVData { class DaitoQRDataStore : QRCSVDataStore { private static readonly String table_name_ = "qrcode_download_data_daito"; - private static readonly String insert_sql = $"insert into {table_name_} (" + - $"{QRCSVDataDaito.ColName.SpotID.ToString()}," + - $"{QRCSVDataDaito.ColName.ParkingName.ToString()}," + - $"{QRCSVDataDaito.ColName.Developer.ToString()}," + - $"{QRCSVDataDaito.ColName.ReceptionDatetime.ToString()}," + - $"{QRCSVDataDaito.ColName.Company.ToString()}," + - $"{QRCSVDataDaito.ColName.Amount.ToString()}," + - $"{QRCSVDataDaito.ColName.AdjustNo.ToString()}," + - $"{QRCSVDataDaito.ColName.ErrorCode.ToString()}," + - //$"{CSVDataDaitoQR.ColName.UpdDate.ToString()}," + - $"{QRCSVDataDaito.ColName.UpdStaff.ToString()}," + - //$"{CSVDataDaitoQR.ColName.RegDate.ToString()}," + - $"{QRCSVDataDaito.ColName.RegStaff.ToString()}" + - $" ) values (" + - $"@{QRCSVDataDaito.ColName.SpotID.ToString()}," + - $"@{QRCSVDataDaito.ColName.ParkingName.ToString()}," + - $"@{QRCSVDataDaito.ColName.Developer.ToString()}," + - $"@{QRCSVDataDaito.ColName.ReceptionDatetime.ToString()}," + - $"@{QRCSVDataDaito.ColName.Company.ToString()}," + - $"@{QRCSVDataDaito.ColName.Amount.ToString()}," + - $"@{QRCSVDataDaito.ColName.AdjustNo.ToString()}," + - $"@{QRCSVDataDaito.ColName.ErrorCode.ToString()}," + - //$"@{CSVDataDaitoQR.ColName.UpdDate.ToString()}," + - $"@{QRCSVDataDaito.ColName.UpdStaff.ToString()}," + - //$"@{CSVDataDaitoQR.ColName.RegDate.ToString()}" + - $"@{QRCSVDataDaito.ColName.RegStaff.ToString()}" + - $");"; - - private String delete_sql_ = $"delete from {table_name_} where " + $"{QRCSVDataDaito.ColName.ReceptionDatetime.ToString()} between " + @@ -77,28 +48,45 @@ namespace CSVDownloader.Store.QRCSVData { } - public override void Save(QRCSVData obj) { - var data = (QRCSVDataDaito)obj; - var bindlist = new List<(String, object)> { - (QRCSVDataDaito.ColName.SpotID.ToString(), data.spot_id), - (QRCSVDataDaito.ColName.ParkingName.ToString(), data.parking_name), - (QRCSVDataDaito.ColName.Developer.ToString(), data.developer), - (QRCSVDataDaito.ColName.ReceptionDatetime.ToString(), data.reception_datetime), - (QRCSVDataDaito.ColName.Company.ToString(), data.company), - (QRCSVDataDaito.ColName.Amount.ToString(), data.amount), - (QRCSVDataDaito.ColName.AdjustNo.ToString(), data.adjust_no), - (QRCSVDataDaito.ColName.ErrorCode.ToString(), data.error_code), - (QRCSVDataDaito.ColName.UpdStaff.ToString(), data.upd_staff), - (QRCSVDataDaito.ColName.RegStaff.ToString(), data.reg_staff) - }; + public override void Save(List list) { + Code.ResultCode ret; + var table = new DataTable(); + + table.Columns.Add($"{QRCSVDataDaito.ColName.SpotID}"); + table.Columns.Add($"{QRCSVDataDaito.ColName.ParkingName}"); + table.Columns.Add($"{QRCSVDataDaito.ColName.Developer}"); + table.Columns.Add($"{QRCSVDataDaito.ColName.ReceptionDatetime}"); + table.Columns.Add($"{QRCSVDataDaito.ColName.Company}"); + table.Columns.Add($"{QRCSVDataDaito.ColName.Amount}"); + table.Columns.Add($"{QRCSVDataDaito.ColName.AdjustNo}"); + table.Columns.Add($"{QRCSVDataDaito.ColName.ErrorCode}"); + table.Columns.Add($"{QRCSVDataDaito.ColName.UpdStaff}"); + table.Columns.Add($"{QRCSVDataDaito.ColName.RegStaff}"); + + foreach (QRCSVDataDaito data in list) { + var row = table.NewRow(); + row[$"{QRCSVDataDaito.ColName.SpotID}"] = data.spot_id; + row[$"{QRCSVDataDaito.ColName.ParkingName}"] = data.parking_name; + row[$"{QRCSVDataDaito.ColName.Developer}"] = data.developer; + row[$"{QRCSVDataDaito.ColName.ReceptionDatetime}"] = data.reception_datetime; + row[$"{QRCSVDataDaito.ColName.Company}"] = data.company; + row[$"{QRCSVDataDaito.ColName.Amount}"] = data.amount; + row[$"{QRCSVDataDaito.ColName.AdjustNo}"] = data.adjust_no; + row[$"{QRCSVDataDaito.ColName.ErrorCode}"] = data.error_code; + row[$"{QRCSVDataDaito.ColName.UpdStaff}"] = data.upd_staff; + row[$"{QRCSVDataDaito.ColName.RegStaff}"] = data.reg_staff; + + table.Rows.Add(row); + } + + + ret = BulkInsertData(table_name_, table); - var ret = InsertData(insert_sql, bindlist); if (ret != Code.ResultCode.OK) { - throw new Exception("登録失敗 大都QR"); + throw new Exception("登録失敗 Daito QR"); } } - public override int Delete(DateTime from, DateTime to) { var bindlist = new List<(String, object)> { diff --git a/CSVDownloader/Store/QRCSVData/QRCSVDataStore.cs b/CSVDownloader/Store/QRCSVData/QRCSVDataStore.cs index affb714..e0be45f 100644 --- a/CSVDownloader/Store/QRCSVData/QRCSVDataStore.cs +++ b/CSVDownloader/Store/QRCSVData/QRCSVDataStore.cs @@ -19,7 +19,7 @@ namespace CSVDownloader.Store.QRCSVData { } - abstract public void Save(QRCSVData obj); + abstract public void Save(List list); abstract public int Delete(DateTime from, DateTime to); } diff --git a/CSVDownloader/Web/DaitoController.cs b/CSVDownloader/Web/DaitoController.cs index 970d1a8..bfb5ac7 100644 --- a/CSVDownloader/Web/DaitoController.cs +++ b/CSVDownloader/Web/DaitoController.cs @@ -130,24 +130,44 @@ namespace CSVDownloader.Web { var list = GetFileContents(filename_credit); + bool failed_flg = false; + var failed_parking_name_hs_table = new HashSet(); foreach (var line in list) { - result_list.Add(new CreditCSVDataDaito() { - spot_id = GetSpotID(line[(int)CreditCSVDataDaito.ColName.ParkingName]), - parking_name = line[(int)CreditCSVDataDaito.ColName.ParkingName], - developer = line[(int)CreditCSVDataDaito.ColName.Developer], - adjust_type = line[(int)CreditCSVDataDaito.ColName.AdjustType], - fee_type = line[(int)CreditCSVDataDaito.ColName.FeeType], - reception_datetime = DateTime.Parse(line[(int)CreditCSVDataDaito.ColName.ReceptionDatetime]), - amount = int.Parse(line[(int)CreditCSVDataDaito.ColName.Amount]), - reception_no = line[(int)CreditCSVDataDaito.ColName.ReceptionNo], - response_no = line[(int)CreditCSVDataDaito.ColName.ResponseNo], - error_code1 = line[(int)CreditCSVDataDaito.ColName.ErrorCode1], - error_code2 = line[(int)CreditCSVDataDaito.ColName.ErrorCode2] - }); + var parking_name = line[(int)CreditCSVDataDaito.ColName.ParkingName]; + try { + result_list.Add(new CreditCSVDataDaito() { + spot_id = GetSpotID(parking_name), + parking_name = parking_name, + developer = line[(int)CreditCSVDataDaito.ColName.Developer], + adjust_type = line[(int)CreditCSVDataDaito.ColName.AdjustType], + fee_type = line[(int)CreditCSVDataDaito.ColName.FeeType], + reception_datetime = DateTime.Parse(line[(int)CreditCSVDataDaito.ColName.ReceptionDatetime]), + amount = int.Parse(line[(int)CreditCSVDataDaito.ColName.Amount]), + reception_no = line[(int)CreditCSVDataDaito.ColName.ReceptionNo], + response_no = line[(int)CreditCSVDataDaito.ColName.ResponseNo], + error_code1 = line[(int)CreditCSVDataDaito.ColName.ErrorCode1], + error_code2 = line[(int)CreditCSVDataDaito.ColName.ErrorCode2] + }); + + } catch (ArgumentException) { + + failed_parking_name_hs_table.Add(parking_name); + failed_flg = true; + continue; + } } + if (failed_flg) { + logger_.Error("失敗駐車場名"); + + foreach (var ele in failed_parking_name_hs_table) { + logger_.Error($"駐車場 \"{ele}\""); + } + + throw new Exception("データ作成失敗"); + } return result_list; } @@ -159,21 +179,42 @@ namespace CSVDownloader.Web { var list = GetFileContents(filename_qr); + bool failed_flg = false; + var failed_parking_name_hs_table = new HashSet(); foreach (var line in list) { - result_list.Add(new QRCSVDataDaito() { - spot_id = GetSpotID(line[(int)QRCSVDataDaito.ColName.ParkingName]), - parking_name = line[(int)QRCSVDataDaito.ColName.ParkingName], - developer = line[(int)QRCSVDataDaito.ColName.Developer], - reception_datetime = DateTime.Parse(line[(int)QRCSVDataDaito.ColName.ReceptionDatetime]), - company = line[(int)QRCSVDataDaito.ColName.Company], - amount = int.Parse(line[(int)QRCSVDataDaito.ColName.Amount]), - adjust_no = line[(int)QRCSVDataDaito.ColName.AdjustNo], - error_code = line[(int)QRCSVDataDaito.ColName.ErrorCode], - }); + + var parking_name = line[(int)QRCSVDataDaito.ColName.ParkingName]; + try { + + result_list.Add(new QRCSVDataDaito() { + spot_id = GetSpotID(parking_name), + parking_name = parking_name, + developer = line[(int)QRCSVDataDaito.ColName.Developer], + reception_datetime = DateTime.Parse(line[(int)QRCSVDataDaito.ColName.ReceptionDatetime]), + company = line[(int)QRCSVDataDaito.ColName.Company], + amount = int.Parse(line[(int)QRCSVDataDaito.ColName.Amount]), + adjust_no = line[(int)QRCSVDataDaito.ColName.AdjustNo], + error_code = line[(int)QRCSVDataDaito.ColName.ErrorCode], + }); + } catch (ArgumentException) { + failed_parking_name_hs_table.Add(parking_name); + failed_flg = true; + continue; + } + } + if (failed_flg) { + logger_.Error("失敗駐車場名"); + + foreach (var ele in failed_parking_name_hs_table) { + logger_.Error($"駐車場 \"{ele}\""); + } + + throw new Exception("データ作成失敗"); + } return result_list; } diff --git a/CSVDownloader/Web/HelloTechnoController.cs b/CSVDownloader/Web/HelloTechnoController.cs index 7793157..93b5ab6 100644 --- a/CSVDownloader/Web/HelloTechnoController.cs +++ b/CSVDownloader/Web/HelloTechnoController.cs @@ -119,6 +119,9 @@ namespace CSVDownloader.Web { int page = 1; + bool failed_flg = false; + var failed_parking_name_hs_table = new HashSet(); + while (true) { @@ -127,36 +130,48 @@ namespace CSVDownloader.Web { var tag_tr = table.FindElements(By.TagName("tr")); + + // ヘッダー行はスキップしたうえで進める。 for (var i = 1; i < tag_tr.Count; i++) { var tag_td = tag_tr[i].FindElements(By.TagName("td")); if (tag_td.Count != 999) { //throw new Exception("想定外の行構成"); } - var data = new CSVDataHelloTechno() { - spot_id = GetSpotID(tag_td[(int)CSVDataHelloTechno.ColName.ParkingCode].Text), - register_datetime = DateTime.Parse(tag_td[(int)CSVDataHelloTechno.ColName.RegisterDatetime].Text), - user_code = tag_td[(int)CSVDataHelloTechno.ColName.UserCode].Text, - parking_code = tag_td[(int)CSVDataHelloTechno.ColName.ParkingCode].Text, - device_no = tag_td[(int)CSVDataHelloTechno.ColName.DeviceNo].Text, - adjust_no = tag_td[(int)CSVDataHelloTechno.ColName.AdjustNo].Text, - trade = tag_td[(int)CSVDataHelloTechno.ColName.Trade].Text, - amount = int.Parse(tag_td[(int)CSVDataHelloTechno.ColName.Amount].Text.Replace(",", "")), - card_company_name = tag_td[(int)CSVDataHelloTechno.ColName.CardCompanyName].Text, - approval_no = tag_td[(int)CSVDataHelloTechno.ColName.ApprovalNo].Text, - response_no = tag_td[(int)CSVDataHelloTechno.ColName.ResponseNo].Text, - error = tag_td[(int)CSVDataHelloTechno.ColName.Error].Text, - }; - - var cancel_date = tag_td[(int)CSVDataHelloTechno.ColName.CancelDate].Text; - if (cancel_date.Length != 0) { - data.cancel_date = DateTime.Parse(cancel_date); + + + var parking_name = tag_td[(int)CreditCSVDataHelloTechno.ColName.ParkingCode].Text; + try { + var data = new CreditCSVDataHelloTechno() { + spot_id = GetSpotID(parking_name), + register_datetime = DateTime.Parse(tag_td[(int)CreditCSVDataHelloTechno.ColName.RegisterDatetime].Text), + user_code = tag_td[(int)CreditCSVDataHelloTechno.ColName.UserCode].Text, + parking_code = parking_name, + device_no = tag_td[(int)CreditCSVDataHelloTechno.ColName.DeviceNo].Text, + adjust_no = tag_td[(int)CreditCSVDataHelloTechno.ColName.AdjustNo].Text, + trade = tag_td[(int)CreditCSVDataHelloTechno.ColName.Trade].Text, + amount = int.Parse(tag_td[(int)CreditCSVDataHelloTechno.ColName.Amount].Text.Replace(",", "")), + card_company_name = tag_td[(int)CreditCSVDataHelloTechno.ColName.CardCompanyName].Text, + approval_no = tag_td[(int)CreditCSVDataHelloTechno.ColName.ApprovalNo].Text, + response_no = tag_td[(int)CreditCSVDataHelloTechno.ColName.ResponseNo].Text, + error = tag_td[(int)CreditCSVDataHelloTechno.ColName.Error].Text, + }; + + var cancel_date = tag_td[(int)CreditCSVDataHelloTechno.ColName.CancelDate].Text; + if (cancel_date.Length != 0) { + data.cancel_date = DateTime.Parse(cancel_date); + } + + // リストに挿入する。 + csv_data_list_.Add(data); + } catch (ArgumentException) { + failed_parking_name_hs_table.Add(parking_name); + failed_flg = true; + continue; } - csv_data_list_.Add(data); } - // リストに挿入する。 // ページ操作 // 戻ると進むのボタンの組み合わせで操作を行う。 @@ -184,6 +199,18 @@ namespace CSVDownloader.Web { } + + if (failed_flg) { + logger_.Error("失敗駐車場名"); + + foreach (var ele in failed_parking_name_hs_table) { + logger_.Error($"駐車場 \"{ele}\""); + } + + throw new Exception("データ作成失敗"); + + } + } } diff --git a/CSVDownloader/Web/ItecController.cs b/CSVDownloader/Web/ItecController.cs index 8070b02..16bd4e2 100644 --- a/CSVDownloader/Web/ItecController.cs +++ b/CSVDownloader/Web/ItecController.cs @@ -133,8 +133,12 @@ namespace CSVDownloader.Web { list.AddRange(result); } + bool failed_flg = false; + var failed_parking_name_hs_table = new HashSet(); + foreach (var line in list) { + // 空の行はスキップする if (line.Length == 0) { continue; @@ -145,20 +149,42 @@ namespace CSVDownloader.Web { continue; } + var parking_name = line[(int)CreditCSVDataItec.ColName.ParkingName]; + + + try { + result_list.Add(new CreditCSVDataItec() { + spot_id = GetSpotID(parking_name), + code = line[(int)CreditCSVDataItec.ColName.Code], + parking_name = parking_name, + device_type = line[(int)CreditCSVDataItec.ColName.DeviceType], + use_datetime = DateTime.Parse(line[(int)CreditCSVDataItec.ColName.UseDatetime]), + trade = line[(int)CreditCSVDataItec.ColName.Trade], + card_company_name = line[(int)CreditCSVDataItec.ColName.CardCompanyName], + amount = int.Parse(line[(int)CreditCSVDataItec.ColName.Amount]), + tax_send_fee = int.Parse(line[(int)CreditCSVDataItec.ColName.TaxSendFee]), + total_amount = int.Parse(line[(int)CreditCSVDataItec.ColName.TotalAmount]), + error_code = line[(int)CreditCSVDataItec.ColName.ErrorCode], + }); + + } catch (ArgumentException) { + failed_parking_name_hs_table.Add(parking_name); + failed_flg = true; + continue; + } + } + + if (failed_flg) { + logger_.Error("失敗駐車場名"); + + foreach (var ele in failed_parking_name_hs_table) { + logger_.Error($"駐車場 \"{ele}\""); + } + + throw new Exception("データ作成失敗"); - result_list.Add(new CSVDataItec() { - spot_id = GetSpotID(line[(int)CSVDataItec.ColName.ParkingName]), - code = line[(int)CSVDataItec.ColName.Code], - device_type = line[(int)CSVDataItec.ColName.DeviceType], - use_datetime = DateTime.Parse(line[(int)CSVDataItec.ColName.UseDatetime]), - trade = line[(int)CSVDataItec.ColName.Trade], - card_company_name = line[(int)CSVDataItec.ColName.CardCompanyName], - amount = int.Parse(line[(int)CSVDataItec.ColName.Amount]), - tax_send_fee = int.Parse(line[(int)CSVDataItec.ColName.TaxSendFee]), - total_amount = int.Parse(line[(int)CSVDataItec.ColName.TotalAmount]), - error_code = line[(int)CSVDataItec.ColName.ErrorCode], - }); } + return result_list; } } diff --git a/CSVDownloader/Web/WebController.cs b/CSVDownloader/Web/WebController.cs index cb7cf68..1741ee0 100644 --- a/CSVDownloader/Web/WebController.cs +++ b/CSVDownloader/Web/WebController.cs @@ -57,6 +57,8 @@ namespace CSVDownloader.Web { public ResultCode Archive(String archive_filename) { + logger_.Info("アーカイブ開始"); + var dir_name = "archive"; if (!Directory.Exists(dir_name)) { Directory.CreateDirectory(dir_name); @@ -64,12 +66,14 @@ namespace CSVDownloader.Web { String target = @$"{dir_name}\{archive_filename}"; + logger_.Info($"{target}"); if (System.IO.File.Exists(target)) { logger_.Info($"上書き:{target}"); System.IO.File.Delete(target); } ZipFile.CreateFromDirectory("download", target); + logger_.Info("アーカイブ終了"); return ResultCode.OK; } @@ -190,7 +194,7 @@ namespace CSVDownloader.Web { protected String GetSpotID(String parking_name) { if (!dic_.ContainsKey(parking_name)) { - throw new Exception($"該当するマスタなし 駐車場名:\"{parking_name}\""); + throw new ArgumentException(); } return dic_[parking_name]; diff --git a/CSVDownloader/Web/ZeusController.cs b/CSVDownloader/Web/ZeusController.cs index 6d45436..ed6a526 100644 --- a/CSVDownloader/Web/ZeusController.cs +++ b/CSVDownloader/Web/ZeusController.cs @@ -67,6 +67,10 @@ namespace CSVDownloader.Web { dic_ = new Dictionary(); // IPコードと駐車場名を分離。プログラムではIPコードのみ利用する。 foreach (var ele in dic) { + if (ele.Key == "") { + logger_.Warn($"検索キーが空白のためスキップ {ele.Value}"); + continue; + } String parking_name = ele.Key.Split(" ")[0].Trim(); dic_.Add(parking_name, ele.Value); } @@ -103,11 +107,11 @@ namespace CSVDownloader.Web { SwitchToFrame(xpath_map_[XpathKey.FRAME_CONTENTS]); Click(xpath_map_[XpathKey.RADIO_TARGET_SPAN]); Select(xpath_map_[XpathKey.SELECT_TARGET_FROM_YYYY], from.ToString("yyyy")); - Select(xpath_map_[XpathKey.SELECT_TARGET_FROM_MM], from.ToString("MMM")); - Select(xpath_map_[XpathKey.SELECT_TARGET_FROM_DD], from.ToString("dd")); + Select(xpath_map_[XpathKey.SELECT_TARGET_FROM_MM], from.ToString("%M")); + Select(xpath_map_[XpathKey.SELECT_TARGET_FROM_DD], from.ToString("%d")); Select(xpath_map_[XpathKey.SELECT_TARGET_TO_YYYY], to.ToString("yyyy")); - Select(xpath_map_[XpathKey.SELECT_TARGET_TO_MM], to.ToString("MMM")); - Select(xpath_map_[XpathKey.SELECT_TARGET_TO_DD], to.ToString("dd")); + Select(xpath_map_[XpathKey.SELECT_TARGET_TO_MM], to.ToString("%M")); + Select(xpath_map_[XpathKey.SELECT_TARGET_TO_DD], to.ToString("%d")); // 駐車場一覧を取得 var parking_list = driver_.FindElementsByXPath(xpath_map_[XpathKey.CHECK_PARKING]); @@ -139,6 +143,7 @@ namespace CSVDownloader.Web { count++; tmp_list.Clear(); } + } if (tmp_list.Count != 0) { @@ -182,31 +187,55 @@ namespace CSVDownloader.Web { list.AddRange(result); } + + bool failed_flg = false; + var failed_parking_name_hs_table = new HashSet(); + foreach (var line in list) { // 決済金額は「-」でセットされている場合があるので // その際は0とする。 - int amount = 0; - int.TryParse(line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.Amount], out amount); - - result_list.Add(new Store.CreditCSVData.CreditCSVDataZeus() { - spot_id = GetSpotID(line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.IP]), - use_datetime = DateTime.Parse(line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.UseDatetime]), - ip = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.IP], - device_no = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.DeviceNo], - receipt_no = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.ReceiptNo], - certificate_no = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.CertificateNo], - status = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.Status], - error_message = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.ErrorMessage], - amount = amount, - card_no = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.CardNo], - expiration_date = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.ExpirationDate], - brand = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.Brand], - payment_type = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.PaymentType], - jis_info = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.JISInfo], - test = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.Test], - order_no = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.OrderNo], - }); + var parking_name = line[(int)CreditCSVDataZeus.ColName.IP]; + try { + int amount = 0; + int.TryParse(line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.Amount], out amount); + + result_list.Add(new Store.CreditCSVData.CreditCSVDataZeus() { + spot_id = GetSpotID(line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.IP]), + use_datetime = DateTime.Parse(line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.UseDatetime]), + ip = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.IP], + device_no = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.DeviceNo], + receipt_no = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.ReceiptNo], + certificate_no = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.CertificateNo], + status = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.Status], + error_message = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.ErrorMessage], + amount = amount, + card_no = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.CardNo], + expiration_date = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.ExpirationDate], + brand = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.Brand], + payment_type = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.PaymentType], + jis_info = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.JISInfo], + test = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.Test], + order_no = line[(int)Store.CreditCSVData.CreditCSVDataZeus.ColName.OrderNo], + }); + } catch (ArgumentException) { + failed_parking_name_hs_table.Add(parking_name); + failed_flg = true; + continue; + } + + + if (failed_flg) { + logger_.Error("失敗駐車場名"); + + foreach (var ele in failed_parking_name_hs_table) { + logger_.Error($"駐車場 \"{ele}\""); + } + + throw new Exception("データ作成失敗"); + + } + } return result_list; }