From e42fbc7f76d8b58ae99a91ea1f06fba44225fcf1 Mon Sep 17 00:00:00 2001 From: Kai Date: Thu, 22 Jul 2021 19:28:43 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E9=80=86=E8=AE=8A=E5=99=A8=E9=81=B8?= =?UTF-8?q?=E5=96=AE=E5=88=97=E8=A1=A8=202.=20=E4=BF=AE=E6=94=B9=20?= =?UTF-8?q?=E9=80=86=E8=AE=8A=E5=99=A8=20=E6=8A=93KWH=20=E8=A8=88=E7=AE=97?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AnalysisInverterController.cs | 60 ++++++++ SolarPower/DBSchema/solar_power_schema.sql | 7 +- SolarPower/Models/AnalysisInverter.cs | 9 +- .../Quartz/Jobs/CalcInverter15minJob.cs | 13 +- .../Repository/Implement/CompanyRepository.cs | 140 +++++++++-------- .../Implement/OverviewRepository.cs | 6 +- .../Implement/PowerStationRepository.cs | 74 ++++++++- .../Interface/IPowerStationRepository.cs | 2 + .../Views/AnalysisInverter/Index.cshtml | 144 ++++++++++++++---- SolarPower/Views/Shared/_Layout.cshtml | 2 +- .../StationOverviewInfo.cshtml | 2 +- .../wwwroot/css/themes/cust-theme-15.css.map | 1 - .../wwwroot/css/themes/cust-theme-15.css.map_ | 1 - 13 files changed, 343 insertions(+), 118 deletions(-) delete mode 100644 SolarPower/wwwroot/css/themes/cust-theme-15.css.map delete mode 100644 SolarPower/wwwroot/css/themes/cust-theme-15.css.map_ diff --git a/SolarPower/Controllers/AnalysisInverterController.cs b/SolarPower/Controllers/AnalysisInverterController.cs index daade95..2cb44ba 100644 --- a/SolarPower/Controllers/AnalysisInverterController.cs +++ b/SolarPower/Controllers/AnalysisInverterController.cs @@ -1,5 +1,7 @@ using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; using SolarPower.Models; +using SolarPower.Models.PowerStation; using SolarPower.Repository.Interface; using System; using System.Collections.Generic; @@ -23,6 +25,64 @@ namespace SolarPower.Controllers return View(); } + [HttpPost] + public async Task>>>> GetInverterCollapse(string filter) + { + ApiResult>>> apiResult = new ApiResult>>>(); + try + { + var powerStations = new List(); + if (IsPlatformLayer(myUser.Role.Layer)) + { + powerStations = await powerStationRepository.GetAllAsync(); + } + else + { + powerStations = await powerStationRepository.GetPowerStationsByCompanyId(myUser.CompanyId); + } + var siteDBNamePowerStationId = new Dictionary>(); + + var powerStation_Group = powerStations.GroupBy(x => x.SiteDB).ToList(); + foreach(var stations in powerStation_Group) + { + var powerStationIds = stations.Select(x => x.Id).ToList(); + siteDBNamePowerStationId.Add(stations.Key, powerStationIds); + } + + var powerStationInverters = await powerStationRepository.GetPowerStationInverter(siteDBNamePowerStationId, filter); + + powerStationInverters = powerStationInverters.Where(x => x.InverterId != null).ToList(); + + var powerStationInverter_Group = powerStationInverters.GroupBy(x => x.CityName).ToList(); + + var inverterCollapse = new Dictionary>>(); + foreach (var powerStationInverter in powerStationInverter_Group) + { + var inverter_Group = powerStationInverter.GroupBy(x => x.PowerStationName).ToList(); + + var inverterDic = new Dictionary>(); + foreach (var inverter in inverter_Group) + { + inverterDic.Add(inverter.Key, inverter.ToList()); + } + + inverterCollapse.Add(powerStationInverter.Key, inverterDic); + } + + apiResult.Code = "0000"; + + apiResult.Data = inverterCollapse; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + Logger.LogError("【" + controllerName + "/" + actionName + "】"); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } } } diff --git a/SolarPower/DBSchema/solar_power_schema.sql b/SolarPower/DBSchema/solar_power_schema.sql index ff09e60..372db9f 100644 --- a/SolarPower/DBSchema/solar_power_schema.sql +++ b/SolarPower/DBSchema/solar_power_schema.sql @@ -1963,9 +1963,14 @@ CREATE TABLE `sensoravg_history_month` ( COMMENT='各電站每月的sensor avg 歷史資料' COLLATE='utf8mb4_unicode_ci' ENGINE=InnoDB -AUTO_INCREMENT=2 ; +-- 新增電站欄位 20210721 +ALTER TABLE `power_station` + ADD COLUMN `line_token` VARCHAR(255) NULL AFTER `RateOfRain`, + ADD COLUMN `Estimate_kwh` DECIMAL(10,2) NULL DEFAULT '0.00' COMMENT '預估發電度數' AFTER `line_token`, + ADD COLUMN `EstimateEfficacy` DECIMAL(10,2) NULL DEFAULT '0.00' COMMENT '預估發電效能' AFTER `Estimate_kwh`; + /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; diff --git a/SolarPower/Models/AnalysisInverter.cs b/SolarPower/Models/AnalysisInverter.cs index 9c761e1..757e5c5 100644 --- a/SolarPower/Models/AnalysisInverter.cs +++ b/SolarPower/Models/AnalysisInverter.cs @@ -5,7 +5,14 @@ using System.Threading.Tasks; namespace SolarPower.Models { - + public class PowerStationInverter + { + public int PowerStationId { get; set; } + public string CityName { get; set; } + public string PowerStationName { get; set; } + public string InverterName { get; set; } + public string InverterId { get; set; } + } public class AnalysisInverter { diff --git a/SolarPower/Quartz/Jobs/CalcInverter15minJob.cs b/SolarPower/Quartz/Jobs/CalcInverter15minJob.cs index 3cd16f9..1cf372f 100644 --- a/SolarPower/Quartz/Jobs/CalcInverter15minJob.cs +++ b/SolarPower/Quartz/Jobs/CalcInverter15minJob.cs @@ -26,7 +26,7 @@ namespace SolarPower.Quartz.Jobs try { //var day_array = new string[] { "15", "16", "17", "18", "19" }; - ////var day_array = new string[] { "15" }; + //var day_array = new string[] { "22" }; //var time_array = new string[] { "00:02", "00:17", "00:32", "00:47", // "01:02", "01:17", "01:32", "01:47", // "02:02", "02:17", "02:32", "02:47", @@ -71,14 +71,13 @@ namespace SolarPower.Quartz.Jobs //{ // for (var j = 0; j < time_array.Count(); j++) // { - //var dateNowTime = string.Format("2021-07-{0} {1}", day_array[i], time_array[j]); + //var dateNowTime = string.Format("2021-07-{0} {1}", day_array[i], time_array[j]); + #region step2. 從電站的DB及電站編號找出該電站的控制器 foreach (var powerStation in powerStations) { - - //取得所有該電站的逆變器 logger.LogInformation("【CalcInverter15minJob】【開始取得電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateNowTime); var controllers = await powerStationRepository.GetAllDeviceControllerId(powerStation.Id, powerStation.SiteDB); @@ -97,7 +96,8 @@ namespace SolarPower.Quartz.Jobs { logger.LogInformation("【CalcInverter15minJob】【開始計算電站[{0}]在{1}的每15分鐘逆變器資訊】", powerStation.Code, dateNowTime); calcInverter15mins = await powerStationRepository.CalcInverterHisyort15minData(dateNowTime, powerStation.SiteDB, full_table_name, inverterIds); - logger.LogInformation("【CalcInverter15minJob】【計算完成電站[{0}]在{1}的每15分鐘逆變器資訊】", powerStation.Code, dateNowTime); + logger.LogInformation("【CalcInverter15minJob】【計算完成電站[{0}]在{1}的每15分鐘逆變器資訊】", powerStation.Code, dateNowTime); + logger.LogInformation("【CalcInverter15minJob】【計算結果】 - {0}", System.Text.Json.JsonSerializer.Serialize(calcInverter15mins)); if (calcInverter15mins.Count() > 0) { foreach (var inverterHistory in calcInverter15mins) @@ -130,9 +130,6 @@ namespace SolarPower.Quartz.Jobs #endregion // } //} - - - } catch (Exception exception) { diff --git a/SolarPower/Repository/Implement/CompanyRepository.cs b/SolarPower/Repository/Implement/CompanyRepository.cs index 942b5d2..8fa362b 100644 --- a/SolarPower/Repository/Implement/CompanyRepository.cs +++ b/SolarPower/Repository/Implement/CompanyRepository.cs @@ -429,7 +429,7 @@ namespace SolarPower.Repository.Implement { var sql = @$" -- 傾印 子資料庫結構 - CREATE DATABASE IF NOT EXISTS `{db_name}`; + CREATE DATABASE IF NOT EXISTS `{db_name}` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */; USE `{db_name}`; -- 傾印 資料表 controller 結構 @@ -437,8 +437,8 @@ namespace SolarPower.Repository.Implement `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, `Deleted` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否刪除, 0:否 1:是', `PowerStationId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '所屬電站編號', - `ControllerId` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '控制器編號', - `SerialNumber` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '控制器各電站流水號', + `ControllerId` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '控制器編號', + `SerialNumber` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '控制器各電站流水號', `CreatedBy` int(10) unsigned NOT NULL, `CreatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `UpdatedBy` int(10) unsigned DEFAULT NULL, @@ -481,7 +481,7 @@ namespace SolarPower.Repository.Implement `Enabled` tinyint(4) DEFAULT '0' COMMENT '是否啟用,0:未啟用 1:啟用', `Status` tinyint(4) DEFAULT '0' COMMENT '狀態,0:未啟用 1:正常 2:異常', `InstallDate` timestamp NULL DEFAULT NULL COMMENT '安裝日期', - `SerialNumber` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '逆變器流水號(用控制器排序)', + `SerialNumber` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '逆變器流水號(用控制器排序)', `InverterName` varchar(50) DEFAULT NULL COMMENT '逆變器名稱', `InverterId` varchar(50) DEFAULT NULL COMMENT '逆變器UID', `ControllerId` int(10) DEFAULT NULL COMMENT '所屬控制器', @@ -535,71 +535,77 @@ namespace SolarPower.Repository.Implement ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='運維廠商'; -- 傾印 資料表 power_station 結構 - CREATE TABLE IF NOT EXISTS `power_station` ( - `Id` int(10) unsigned NOT NULL DEFAULT '0', - `Deleted` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '是否刪除, 0:否 1:是', - `CompanyId` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '公司編號', - `CityId` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '電站縣市', - `AreaId` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '電站區域', - `HealthStatus` TINYINT(4) UNSIGNED NOT NULL DEFAULT '1' COMMENT '1:設備正常 2:設備斷線 3:設備異常', - `Address` VARCHAR(100) NULL DEFAULT NULL COMMENT '電站詳細地址' COLLATE 'utf8mb4_unicode_ci', - `Name` VARCHAR(50) NULL DEFAULT NULL COMMENT '名稱' COLLATE 'utf8mb4_unicode_ci', - `MainDisplay` VARCHAR(50) NULL DEFAULT NULL COMMENT '主要顯示圖片' COLLATE 'utf8mb4_unicode_ci', - `Code` VARCHAR(50) NULL DEFAULT NULL COMMENT '電站代碼,縣市+區域+四碼流水號' COLLATE 'utf8mb4_unicode_ci', - `SerialNumber` VARCHAR(4) NULL DEFAULT NULL COMMENT '四碼流水號' COLLATE 'utf8mb4_unicode_ci', - `IsEscrow` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '是否為代管,0:否 1:是', - `EscrowName` VARCHAR(50) NULL DEFAULT NULL COMMENT '代管名稱' COLLATE 'utf8mb4_unicode_ci', - `ElectricityMeterAt` TIMESTAMP NULL DEFAULT NULL COMMENT '台電掛錶日', - `EstimatedRecoveryTime` VARCHAR(10) NULL DEFAULT NULL COMMENT '預估回收時間' COLLATE 'utf8mb4_unicode_ci', - `GeneratingCapacity` DECIMAL(10,1) NOT NULL DEFAULT '0.0' COMMENT '電廠發電容量,單位(千瓦)', - `PowerRate` DECIMAL(10,3) NOT NULL DEFAULT '0.000' COMMENT '受電費率', - `Coordinate` VARCHAR(50) NULL DEFAULT NULL COMMENT '座標' COLLATE 'utf8mb4_unicode_ci', - `InverterBrand` VARCHAR(50) NULL DEFAULT NULL COMMENT '逆變器廠牌' COLLATE 'utf8mb4_unicode_ci', - `InverterProductModel` VARCHAR(50) NULL DEFAULT NULL COMMENT '逆變器型號' COLLATE 'utf8mb4_unicode_ci', - `InverterAmount` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '逆變器數量', - `PhotovoltaicPanelBrand` VARCHAR(50) NULL DEFAULT NULL COMMENT '光電板廠牌' COLLATE 'utf8mb4_unicode_ci', - `PhotovoltaicPanelProductModel` VARCHAR(50) NULL DEFAULT NULL COMMENT '光電板型號' COLLATE 'utf8mb4_unicode_ci', - `PhotovoltaicPanelSpecification` VARCHAR(100) NULL DEFAULT NULL COMMENT '光電板規格' COLLATE 'utf8mb4_unicode_ci', - `PhotovoltaicPanelAmount` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '光電板數量', - `BoEFileName` VARCHAR(255) NULL DEFAULT NULL COMMENT '能源局原檔案名' COLLATE 'utf8mb4_unicode_ci', - `BoEFile` VARCHAR(255) NULL DEFAULT NULL COMMENT '能源局檔案' COLLATE 'utf8mb4_unicode_ci', - `BoEDiscountRate` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '能源局折扣率', - `BoEDeviceRegisterNumber` VARCHAR(50) NULL DEFAULT NULL COMMENT '能源局設備登記編號' COLLATE 'utf8mb4_unicode_ci', - `BoERentRatio` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '能源局租金比率,單位(%)', - `TPCContractNumber` VARCHAR(50) NULL DEFAULT NULL COMMENT '台電契約編號' COLLATE 'utf8mb4_unicode_ci', - `TPCContractAt` TIMESTAMP NULL DEFAULT NULL COMMENT '台電簽約日期', - `TPCSellDeadline` INT(10) UNSIGNED NULL DEFAULT '0' COMMENT '台電售電期限,單位(年)', - `TPCMeterReading` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '台電每期抄錶日', - `TPCPurchaseElectricityAt` TIMESTAMP NULL DEFAULT NULL COMMENT '台電正式購電日', - `TPCSellElectricityAt` TIMESTAMP NULL DEFAULT NULL COMMENT '台電正式售電日', - `SolarType` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '電站類型', - `kwh` DECIMAL(10,3) UNSIGNED NOT NULL DEFAULT '0.000', - `Today_kwh` DECIMAL(10,3) UNSIGNED NOT NULL DEFAULT '0.000' COMMENT '今日發電量', - `Total_kwh` DECIMAL(10,3) UNSIGNED NOT NULL DEFAULT '0.000' COMMENT '總發電量', - `today_kwhkwp` DECIMAL(10,3) NULL DEFAULT NULL COMMENT '今日kwhkwp', - `avg_kwhkwp` DECIMAL(10,3) NULL DEFAULT NULL COMMENT '30天平均kwhkwp', - `today_money` DECIMAL(10,2) NULL DEFAULT NULL COMMENT '今日金額', - `total_money` DECIMAL(10,2) NULL DEFAULT NULL COMMENT '總金額', - `today_PR` DECIMAL(5,2) NULL DEFAULT NULL COMMENT '電站Pr值', - `avg_PR` DECIMAL(5,2) NULL DEFAULT NULL COMMENT '平均Pr值', - `today_carbon` DECIMAL(10,2) NULL DEFAULT NULL COMMENT '今日減碳量', - `total_carbon` DECIMAL(10,2) NULL DEFAULT NULL COMMENT '總減碳量', - `today_irradiance` DECIMAL(5,2) NULL DEFAULT NULL COMMENT '今日日照度', - `avg_irradiance` DECIMAL(5,2) NULL DEFAULT NULL COMMENT '平均日照度', - `SolarHour` DECIMAL(5,2) UNSIGNED NOT NULL DEFAULT '0.00' COMMENT '總運轉小時', - `SiteDB` VARCHAR(20) NULL DEFAULT NULL COMMENT '電站 DB name: solar_com' COLLATE 'utf8mb4_unicode_ci', - `TodayWeather` VARCHAR(20) NULL DEFAULT NULL COMMENT '今日天氣' COLLATE 'utf8mb4_unicode_ci', - `TodayWeatherTemp` DECIMAL(5,2) UNSIGNED NOT NULL DEFAULT '0.00' COMMENT '今日溫度', - `CreatedBy` INT(10) UNSIGNED NOT NULL COMMENT '建立者', - `CreatedAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '建立時間', - `UpdatedBy` INT(10) UNSIGNED NULL DEFAULT NULL COMMENT '修改者', - `UpdatedAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改時間', - PRIMARY KEY (`Id`), - KEY `IDX_01` (`Deleted`), - KEY `IDX_02` (`CompanyId`), - KEY `IDX_03` (`CityId`,`AreaId`) + CREATE TABLE IF NOT EXISTS `power_station` ( + `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `Deleted` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否刪除, 0:否 1:是', + `CompanyId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '公司編號', + `CityId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '電站縣市', + `AreaId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '電站區域', + `HealthStatus` tinyint(4) unsigned NOT NULL DEFAULT '1' COMMENT '1:設備正常 2:設備斷線 3:設備異常', + `Address` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '電站詳細地址', + `Name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '名稱', + `MainDisplay` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '主要顯示圖片', + `Code` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '電站代碼,縣市+區域+四碼流水號', + `SerialNumber` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '四碼流水號', + `IsEscrow` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否為代管,0:否 1:是', + `EscrowName` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '代管名稱', + `ElectricityMeterAt` timestamp NULL DEFAULT NULL COMMENT '台電掛錶日', + `EstimatedRecoveryTime` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '預估回收時間', + `GeneratingCapacity` decimal(10,1) NOT NULL DEFAULT '0.0' COMMENT '電廠發電容量,單位(千瓦)', + `PowerRate` decimal(10,3) NOT NULL DEFAULT '0.000' COMMENT '受電費率', + `Coordinate` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '座標', + `InverterBrand` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '逆變器廠牌', + `InverterProductModel` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '逆變器型號', + `InverterAmount` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '逆變器數量', + `PhotovoltaicPanelBrand` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '光電板廠牌', + `PhotovoltaicPanelProductModel` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '光電板型號', + `PhotovoltaicPanelSpecification` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '光電板規格', + `PhotovoltaicPanelAmount` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '光電板數量', + `BoEFileName` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '能源局原檔案名', + `BoEFile` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '能源局檔案', + `BoEDiscountRate` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '能源局折扣率', + `BoEDeviceRegisterNumber` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '能源局設備登記編號', + `BoERentRatio` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '能源局租金比率,單位(%)', + `TPCContractNumber` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '台電契約編號', + `TPCContractAt` timestamp NULL DEFAULT NULL COMMENT '台電簽約日期', + `TPCSellDeadline` int(10) unsigned DEFAULT '0' COMMENT '台電售電期限,單位(年)', + `TPCMeterReading` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '台電每期抄錶日', + `TPCPurchaseElectricityAt` timestamp NULL DEFAULT NULL COMMENT '台電正式購電日', + `TPCSellElectricityAt` timestamp NULL DEFAULT NULL COMMENT '台電正式售電日', + `SolarType` tinyint(4) NOT NULL DEFAULT '0' COMMENT '電站類型', + `kwh` decimal(10,3) unsigned NOT NULL DEFAULT '0.000', + `Today_kwh` decimal(10,3) unsigned NOT NULL DEFAULT '0.000' COMMENT '今日發電量', + `Total_kwh` decimal(10,3) unsigned NOT NULL DEFAULT '0.000' COMMENT '總發電量', + `today_kwhkwp` decimal(10,3) DEFAULT NULL COMMENT '今日kwhkwp', + `avg_kwhkwp` decimal(10,3) DEFAULT NULL COMMENT '30天平均kwhkwp', + `today_money` decimal(10,2) DEFAULT NULL COMMENT '今日金額', + `total_money` decimal(10,2) DEFAULT NULL COMMENT '總金額', + `today_PR` decimal(5,2) DEFAULT NULL COMMENT '電站Pr值', + `avg_PR` decimal(5,2) DEFAULT NULL COMMENT '平均Pr值', + `today_carbon` decimal(10,2) DEFAULT NULL COMMENT '今日減碳量', + `total_carbon` decimal(10,2) DEFAULT NULL COMMENT '總減碳量', + `today_irradiance` decimal(5,2) DEFAULT NULL COMMENT '今日日照度', + `avg_irradiance` decimal(5,2) DEFAULT NULL COMMENT '平均日照度', + `SolarHour` decimal(5,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '總運轉小時', + `SiteDB` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '電站 DB name: solar_com', + `TodayWeather` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '今日天氣', + `TodayWeatherTemp` decimal(5,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '今日溫度', + `WeathersStationId` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '氣象站編號', + `RateOfRain` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '今日降雨率', + `line_token` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `Estimate_kwh` decimal(10,2) DEFAULT '0.00' COMMENT '預估發電度數', + `EstimateEfficacy` decimal(10,2) DEFAULT '0.00' COMMENT '預估發電效能', + `CreatedBy` int(10) unsigned NOT NULL COMMENT '建立者', + `CreatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '建立時間', + `UpdatedBy` int(10) unsigned DEFAULT NULL COMMENT '修改者', + `UpdatedAt` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改時間', + PRIMARY KEY (`Id`) USING BTREE, + KEY `IDX_01` (`Deleted`) USING BTREE, + KEY `IDX_02` (`CompanyId`) USING BTREE, + KEY `IDX_03` (`CityId`,`AreaId`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='電站資料'; + -- 傾印 資料表 power_station_exception 結構 CREATE TABLE IF NOT EXISTS `power_station_exception` ( `Id` int(10) unsigned NOT NULL AUTO_INCREMENT, diff --git a/SolarPower/Repository/Implement/OverviewRepository.cs b/SolarPower/Repository/Implement/OverviewRepository.cs index 7540613..c08a9e9 100644 --- a/SolarPower/Repository/Implement/OverviewRepository.cs +++ b/SolarPower/Repository/Implement/OverviewRepository.cs @@ -202,7 +202,7 @@ namespace SolarPower.Repository.Implement FROM power_station_history_hour ps LEFT JOIN sensor_history_hour pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d %H') = DATE_FORMAT(pyr.timestamp, '%Y-%m-%d %H') WHERE ps.PowerStationId = @PowerStationId - AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = @NowDay"; + AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = @NowDay ORDER BY ps.timestamp"; result = (await conn.QueryAsync(sql_power, new { PowerStationId = powerStationId, NowDay = nowDay })).ToList(); } @@ -226,7 +226,7 @@ namespace SolarPower.Repository.Implement FROM power_station_history_day ps LEFT JOIN sensor_history_day pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = DATE_FORMAT(pyr.timestamp, '%Y-%m-%d') WHERE ps.PowerStationId = @PowerStationId - AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') BETWEEN @StartDay AND @NowDay"; + AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') BETWEEN @StartDay AND @NowDay ORDER BY ps.timestamp"; result = (await conn.QueryAsync(sql_power, new { PowerStationId = powerStationId, StartDay = startDay, NowDay = nowDay })).ToList(); } @@ -319,7 +319,7 @@ namespace SolarPower.Repository.Implement //var endDataTime = dateTime + " 19:00"; //var sql = @$"SELECT * FROM inverter_history_15min WHERE PowerStationId = @PowerStationId AND DATE_FORMAT(TIMESTAMP, '%Y-%m-%d %H:%i') BETWEEN @StartDateTime AND @EndDateTime"; - var sql = @$"SELECT * FROM inverter_history_15min WHERE PowerStationId = @PowerStationId AND DATE_FORMAT(TIMESTAMP, '%Y-%m-%d') = @DateTime"; + var sql = @$"SELECT * FROM inverter_history_15min WHERE PowerStationId = @PowerStationId AND DATE_FORMAT(TIMESTAMP, '%Y-%m-%d') = @DateTime ORDER BY TIMESTAMP"; result = (await conn.QueryAsync(sql, new { PowerStationId = powerStationId, DateTime = dateTime })).ToList(); } diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index 06dbca2..85ceebc 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -2618,7 +2618,7 @@ namespace SolarPower.Repository.Implement a.KWH, s.TODAYKWH, i.Capacity, - (a.KWH/i.Capacity) AS KWHKWP + a.KWH/(i.Capacity/4) AS KWHKWP FROM (SELECT MAX(FROM_UNIXTIME(sub_inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i')) AS TIMESTAMP, sub_inv.INVERTERID, @@ -2630,7 +2630,7 @@ namespace SolarPower.Repository.Implement LEFT JOIN ( SELECT MAX(FROM_UNIXTIME(sub_inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i')) AS TIMESTAMP, sub_inv.INVERTERID, - AVG(sub_inv.WH)/1000 AS KWH + SUM(sub_inv.WH)/1000 AS KWH FROM {table_name} sub_inv WHERE FROM_UNIXTIME(sub_inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i') BETWEEN @StartDateTime AND @EndDateTime AND sub_inv.INVERTERID IN @InverterIds @@ -2738,7 +2738,7 @@ namespace SolarPower.Repository.Implement SELECT FROM_UNIXTIME(inv.TIMESTAMP/1000, '%Y-%m-%d %H') AS TIMESTAMP, inv.INVERTERID, - AVG(inv.WH)/1000 AS KWH + SUM(inv.WH)/1000 AS KWH FROM {table_name} inv WHERE DATE_FORMAT(FROM_UNIXTIME(inv.TIMESTAMP/1000), '%Y-%m-%d %H') = @DateTime AND inv.INVERTERID IN @InverterIds @@ -2860,7 +2860,7 @@ namespace SolarPower.Repository.Implement AVG(inv.RA3) AS RA3, AVG(inv.RA4) AS RA4, AVG(inv.RA5) AS RA5, - AVG(inv.KWH) AS KWH, + SUM(inv.KWH) AS KWH, MAX(inv.TODAYKWH) AS TODAYKWH, MAX(inv.TODAYKWH) / i.Capacity AS KWHKWP FROM inverter_history_hour inv @@ -2981,7 +2981,7 @@ namespace SolarPower.Repository.Implement AVG(inv.RA3) AS RA3, AVG(inv.RA4) AS RA4, AVG(inv.RA5) AS RA5, - AVG(inv.KWH) AS KWH, + SUM(inv.KWH) AS KWH, SUM(inv.TODAYKWH) AS TODAYKWH, SUM(inv.TODAYKWH) / i.Capacity AS KWHKWP FROM inverter_history_day inv @@ -3608,5 +3608,69 @@ namespace SolarPower.Repository.Implement return count; } } + + public async Task> GetPowerStationsByCompanyId(int companyId) + { + List result; + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + try + { + var sql = $"SELECT * FROM {tableName} WHERE Deleted = 0 AND CompanyId = @CompanyId"; + + result = (await conn.QueryAsync(sql, new { CompanyId = companyId })).ToList(); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } + + public async Task> GetPowerStationInverter(Dictionary> dic, string filter) + { + List result; + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + try + { + List sql_perSiteDB = new List(); + var sql = ""; + foreach(var powerStationDic in dic) + { + var powerStationIds = string.Join(",", powerStationDic.Value); + + var temp_sql = @$"SELECT ps.Id AS PowerStationId, + c.Name AS CityName, + ps.Name AS PowerStationName, + inv.InverterName AS InverterName, + inv.InverterId AS InverterId + FROM power_station ps + LEFT JOIN `city` c ON ps.CityId = c.Id + LEFT JOIN {powerStationDic.Key}.controller con ON ps.Id = con.PowerStationId + LEFT JOIN {powerStationDic.Key}.inverter inv ON con.Id = inv.ControllerId + WHERE ps.Deleted = 0 + AND ps.Id IN ({powerStationIds})"; + if (!string.IsNullOrEmpty(filter)) + { + temp_sql += " AND inv.InverterName LIKE CONCAT('%', @Filter, '%')"; + } + + sql_perSiteDB.Add(temp_sql); + } + + sql = string.Join(" UNION ", sql_perSiteDB); + + result = (await conn.QueryAsync(sql, new { Filter = filter})).ToList(); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } + } } diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index e289083..e6a1f3c 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -546,5 +546,7 @@ namespace SolarPower.Repository.Interface Task CalcSensorAvgHistoryMonthDataByPowerStationId(string month, int powerStationId); Task AddSensorAvgHistoryMonthList(List entity, List properties); Task UpdateSensorAvgHistoryMonthList(List entity); + Task> GetPowerStationsByCompanyId(int companyId); + Task> GetPowerStationInverter(Dictionary> dic, string filter); } } diff --git a/SolarPower/Views/AnalysisInverter/Index.cshtml b/SolarPower/Views/AnalysisInverter/Index.cshtml index 9b42293..e1c2152 100644 --- a/SolarPower/Views/AnalysisInverter/Index.cshtml +++ b/SolarPower/Views/AnalysisInverter/Index.cshtml @@ -212,35 +212,6 @@
- - - -
-
-
總結
- - - - - - - - - - - - - - - - - - - - - -
時間發電量(kWh)發電小時日射量(kWh/m2)PR(%)溫度修正PR(%)
2021-05126,121.7119.04140.3984.891.9
-
@@ -290,6 +261,7 @@ var searchType = 0;//搜尋條件(日,日區間,月,年) var datepicker; var timerange;//選取時間 + var selecterd_invert = []; $(function () { //#region 預設初始值 @@ -300,6 +272,9 @@ timerange = $('#DateGet').val(); //#endregion + //#region 載入左邊選單列表 + GetPowerStationCollapse(""); + //#endregion }) function myfunc(div) { @@ -454,5 +429,116 @@ timerange = $('#DateGettext').val(); }); //#endregion + + $("#js_list_accordion_filter").change(function (e) { + GetPowerStationCollapse($(this).val()); + }); + + $('#js_list_accordion').on("change", 'input[name="selectedInverterId[]"]', function (event) { + if (this.checked) { + if ($.inArray(this.value, selecterd_invert) < 0) { + selecterd_invert.push(this.value); + } + } else { + if ($.inArray(this.value, selecterd_invert) > -1) { + selecterd_invert.slice($.inArray(this.value, selecterd_invert), 1); + } + } + + console.log(selecterd_invert); + }); + + $('#js_list_accordion').on("change", 'input[name="selectedInverterLayer2[]"]', function (event) { + if (this.checked) { + $(this).parents(".list-group-item").find('input[name="selectedInverterId[]"]').prop("checked", true).trigger("change"); + } else { + $(this).parents(".list-group-item").find('input[name="selectedInverterId[]"]').prop("checked", false).trigger("change"); + } + }); + + function GetPowerStationCollapse(filter) { + var url = "/AnalysisInverter/GetInverterCollapse" + + var send_data = { + Filter: filter + } + + $.post(url, send_data, function (rel) { + if (rel.code != "0000") { + toast_error(rel.data.msg); + return; + } + + var inverterCollapse = rel.data; + + + + $('#js_list_accordion').empty(); + + if (inverterCollapse.length <= 0) { + $('#js_list_accordion').append("
查無結果
"); + } + + var str = ""; + + Object.keys(inverterCollapse).map(function (key, index) { + str += '
' + + '' + + '
' + + '
' + + '
    '; + Object.keys(inverterCollapse[key]).map(function (powerStationkey, index) { + str += '
  • ' + + '
    ' + + '

    ' + powerStationkey + '

    ' + + '
    ' + + '' + + '
    ' + + '
    ' + + '
      '; + $.each(inverterCollapse[key][powerStationkey], function (index, inverter) { + str += '
    • ' + + ' ' + inverter.inverterName + '' + + '
      ' + '
      ' + '
    • '; + }); + str += '
    ' + + '
  • '; + }); + + str += '
'; + str += '
'; + str += '
'; + + }); + + $('#js_list_accordion').append(str); + $('#js_list_accordion').find('.card').first().addClass(" border-top-left-radius-0 border-top-right-radius-0"); + + if (selecterd_invert.length <= 0) { + + var first_val = Object.values(inverterCollapse)[0]; + var child_val = Object.values(Object.values(inverterCollapse)[0])[0]; + selecterd_invert.push(Object.values(Object.values(inverterCollapse)[0])[0][0].inverterId) + } + + $('input[name="selectedInverterId[]"]').each(function () { + if ($.inArray(this.value, selecterd_invert) > -1) { + $(this).prop('checked', true); + } + }); + + + }, 'json'); + } } diff --git a/SolarPower/Views/Shared/_Layout.cshtml b/SolarPower/Views/Shared/_Layout.cshtml index 3c5bbba..0fe8801 100644 --- a/SolarPower/Views/Shared/_Layout.cshtml +++ b/SolarPower/Views/Shared/_Layout.cshtml @@ -108,7 +108,7 @@