From ccd68d6bf421104a3c4018b18a2e4cc0f78e2905 Mon Sep 17 00:00:00 2001 From: Kai Date: Tue, 14 Sep 2021 13:09:00 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=20=E5=8A=A0=E5=85=A5=20company=20viewer?= =?UTF-8?q?=20Modal=202.=20=E4=BF=AE=E6=94=B9=E9=9B=BB=E7=AB=99=E7=B8=BD?= =?UTF-8?q?=E8=A6=BD=20=E7=B4=85=E9=BB=83=E7=87=88=E5=90=8D=E8=A9=9E=203.?= =?UTF-8?q?=20=E6=AA=A2=E6=B8=AC=E9=80=86=E8=AE=8A=E5=99=A8=E7=8B=80?= =?UTF-8?q?=E6=85=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Models/PowerStation.cs | 7 ++ .../Quartz/Jobs/CalcInverter15minJob.cs | 55 +++++++++++-- .../Repository/Implement/CompanyRepository.cs | 2 +- .../Implement/PowerStationRepository.cs | 81 +++++++++++++++++-- .../Interface/IPowerStationRepository.cs | 2 + SolarPower/Views/StationOverview/Index.cshtml | 4 +- 6 files changed, 134 insertions(+), 17 deletions(-) diff --git a/SolarPower/Models/PowerStation.cs b/SolarPower/Models/PowerStation.cs index eb8b3b2..8815df8 100644 --- a/SolarPower/Models/PowerStation.cs +++ b/SolarPower/Models/PowerStation.cs @@ -1045,4 +1045,11 @@ namespace SolarPower.Models.PowerStation public string Item { get; set; } } + public class InvStatusErr + { + public string SiteDB { get; set; } + public string Site_id { get; set; } + public string InverterId { get; set; } + } + } diff --git a/SolarPower/Quartz/Jobs/CalcInverter15minJob.cs b/SolarPower/Quartz/Jobs/CalcInverter15minJob.cs index 20d3211..279746a 100644 --- a/SolarPower/Quartz/Jobs/CalcInverter15minJob.cs +++ b/SolarPower/Quartz/Jobs/CalcInverter15minJob.cs @@ -61,6 +61,7 @@ namespace SolarPower.Quartz.Jobs #endregion List calcInverter15mins = new List(); + List updateInvPowerStationDBName = new List(); var DateTimeNow = DateTime.Now; @@ -108,15 +109,15 @@ namespace SolarPower.Quartz.Jobs } } - - #endregion - - } - #endregion + #endregion - #region step3. 將 inverter INSERT 到 inverter_history_15min 資料表 - List inverter_history_properties = new List() + + } + #endregion + + #region step3. 將 inverter INSERT 到 inverter_history_15min 資料表 + List inverter_history_properties = new List() { "PowerStationId", "INVERTERID", @@ -127,9 +128,47 @@ namespace SolarPower.Quartz.Jobs }; await powerStationRepository.AddInverter15minHistory(calcInverter15mins, inverter_history_properties); - #endregion + #endregion // } //} + + try + { + logger.LogInformation("【CalcInverter15minJob】開始檢測逆變器狀態"); + var ps_groupby_SitDB = powerStations.GroupBy(x => x.SiteDB).ToList(); + + var updateInvStatusList = new Dictionary>(); + var psCodes = new List(); + + foreach (var ps in ps_groupby_SitDB) + { + //updateInvStatusList.Add(ps.Key, ps.Select(x => x.Code).ToList()); + await powerStationRepository.UpdateInvStatus(ps.Key, ps.Select(x => x.Code).ToList(), null, 1); + psCodes.AddRange(ps.Select(x => x.Code).ToList()); + } + + //foreach(var list in updateInvStatusList) + //{ + // await powerStationRepository.UpdateInvStatus(list.Key, list.Value, null, 1); + // psCodes.AddRange(list.Value); + //} + + var invStatusErr = await powerStationRepository.GetInvStatusErr(psCodes); + + var invStatusErr_Group = invStatusErr.GroupBy(x => x.SiteDB).ToList(); + + foreach (var update_invStatusErr in invStatusErr_Group) + { + await powerStationRepository.UpdateInvStatus(update_invStatusErr.Key, null, update_invStatusErr.Select(x => x.InverterId).ToList(), 2); + } + + logger.LogError("【CalcInverter15minJob】檢測完成逆變器狀態"); + } + catch(Exception exception) + { + logger.LogError("【CalcInverter15minJob】檢測逆變器狀態失敗 - [Exception] {0}", exception.Message); + } + } catch (Exception exception) { diff --git a/SolarPower/Repository/Implement/CompanyRepository.cs b/SolarPower/Repository/Implement/CompanyRepository.cs index 9b0bc6e..dbce5e7 100644 --- a/SolarPower/Repository/Implement/CompanyRepository.cs +++ b/SolarPower/Repository/Implement/CompanyRepository.cs @@ -732,7 +732,7 @@ namespace SolarPower.Repository.Implement { var sub_sql = $@"select '{db_name}' AS `dbName`,(`{db_name}`.`inverter`.`InverterId` collate utf8mb4_unicode_ci) AS `InverterId`, (`{db_name}`.`inverter`.`Brand` collate utf8mb4_unicode_ci) AS `Brand`,`{db_name}`.`inverter`.`Enabled` AS `enabled`, - `{db_name}`.`inverter`.`Status` AS status + `{db_name}`.`inverter`.`Status` AS status, (`{db_name}`.`inverter`.`Model` collate utf8mb4_unicode_ci) AS `Model` from `{db_name}`.`inverter`"; temp_sub_sql.Add(sub_sql); diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index e500016..5cfe027 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -34,7 +34,7 @@ namespace SolarPower.Repository.Implement { var show_enable_str = " AND ps.Status = 1"; - if(showEnable != 1) + if (showEnable != 1) { show_enable_str = ""; } @@ -5369,7 +5369,7 @@ namespace SolarPower.Repository.Implement } } - public async Task> GetShareDevicePowerstationName (int Id , string DBname) + public async Task> GetShareDevicePowerstationName(int Id, string DBname) { List result; using (IDbConnection conn = this._databaseHelper.GetConnection()) @@ -5391,7 +5391,7 @@ namespace SolarPower.Repository.Implement } } - public async Task DropShareDevice(int powerstationId ,string DBname) + public async Task DropShareDevice(int powerstationId, string DBname) { using (IDbConnection conn = this._databaseHelper.GetConnection()) { @@ -5449,14 +5449,14 @@ namespace SolarPower.Repository.Implement } } - public async Task> CheckStationStatus (string code , string DBname) + public async Task> CheckStationStatus(string code, string DBname) { List result; using (IDbConnection conn = this._databaseHelper.GetConnection()) { try { - List devices = new List + List devices = new List { new PowerstationOption{Text="日照計",Value="PYR"}, new PowerstationOption{Text="模組溫度計",Value="MTR"} @@ -5698,7 +5698,7 @@ namespace SolarPower.Repository.Implement } } - public async Task StationStatus(int stationId , int status , string subDB = "") + public async Task StationStatus(int stationId, int status, string subDB = "") { using (IDbConnection conn = this._databaseHelper.GetConnection()) { @@ -5728,6 +5728,75 @@ namespace SolarPower.Repository.Implement } } + public async Task UpdateInvStatus(string siteDB, List codes, List inverterIds = null, byte status = 0) + { + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + conn.Open(); + using (var trans = conn.BeginTransaction()) + { + try + { + + var sql = $@"UPDATE {siteDB}.inverter SET Status = {status} WHERE Enabled = 1 AND Deleted = 0 "; + + if(codes != null && codes.Count > 0) + { + sql += " AND LEFT(InverterId, 9) IN @Codes"; + } + + if(inverterIds != null && inverterIds.Count > 0) + { + sql += " AND InverterId IN @InverterIds"; + } + + await conn.ExecuteAsync(sql, new { Codes = codes, InverterIds = inverterIds }, trans); + + trans.Commit(); + } + catch (Exception exception) + { + trans.Rollback(); + throw exception; + } + finally + { + conn.Close(); + } + } + } + } + + public async Task> GetInvStatusErr(List codes) + { + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + conn.Open(); + + var resule = new List(); + try + { + + var sql = $@"select b.DBName AS SiteDB, site_id, INVERTERID + from err_main a join v_company_inv b on a.errDevice = b.INVERTERID + where site_id IN @Codes and sourceState = 1 + group by b.DBName, site_id, INVERTERID"; + resule = (await conn.QueryAsync(sql, new { Codes = codes })).ToList(); + + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + + return resule; + } + } + } } diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index aa3b968..8b585a9 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -605,5 +605,7 @@ namespace SolarPower.Repository.Interface Task DeleteALLPowerStationOperationPersonnel(int stationId); Task> CheckStationStatus(string code, string DBname); Task StationStatus(int stationId, int status, string subDB = ""); + Task UpdateInvStatus(string siteDB, List codes, List inverterIds = null, byte status = 0); + Task> GetInvStatusErr(List codes); } } diff --git a/SolarPower/Views/StationOverview/Index.cshtml b/SolarPower/Views/StationOverview/Index.cshtml index ff75ff4..3c2ed0a 100644 --- a/SolarPower/Views/StationOverview/Index.cshtml +++ b/SolarPower/Views/StationOverview/Index.cshtml @@ -39,11 +39,11 @@
- +
- +