From 830937f967e23cf942faf2a88a25da4e5b8b7e65 Mon Sep 17 00:00:00 2001 From: Kai Date: Wed, 14 Jul 2021 11:53:37 +0800 Subject: [PATCH] =?UTF-8?q?1.=20bug=20fix=202.=20=E8=83=8C=E6=99=AF?= =?UTF-8?q?=E5=9F=B7=E8=A1=8C=20=E6=99=82=E9=96=93=E8=A8=AD=E5=AE=9A=20?= =?UTF-8?q?=E6=8B=89=E5=87=BA=E8=87=B3config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Controllers/MyBaseController.cs | 17 +- .../Controllers/PowerStationController.cs | 31 +- SolarPower/Controllers/UserController.cs | 2 +- SolarPower/DBSchema/solar_power_schema.sql | 67 ++-- SolarPower/Helper/DatabaseHelper.cs | 1 - SolarPower/Models/Company.cs | 1 + SolarPower/Models/MyBaseModel.cs | 21 ++ SolarPower/Models/Role.cs | 2 + .../Quartz/Jobs/CalcAvgPowerStationJob.cs | 2 - SolarPower/Quartz/Jobs/CalcPowerStationJob.cs | 12 +- .../Repository/Implement/CompanyRepository.cs | 118 +++--- .../Implement/PowerStationRepository.cs | 70 +++- .../Repository/Implement/RoleRepository.cs | 17 +- .../Repository/Implement/UserRepository.cs | 16 +- .../Interface/IPowerStationRepository.cs | 7 + SolarPower/Startup.cs | 4 +- SolarPower/Views/Company/Index.cshtml | 5 +- SolarPower/Views/MapOverview/Index.cshtml | 21 +- .../PowerStation/PowerStationEdit.cshtml | 34 +- .../Views/PowerStation/_DeviceSetting.cshtml | 8 +- .../Views/PowerStation/_StationInfo.cshtml | 8 +- .../Views/PowerStation/_UploadImage.cshtml | 4 +- SolarPower/Views/Shared/_Layout.cshtml | 342 +++++++++++------- SolarPower/Views/StationOverview/Index.cshtml | 17 +- .../StationOverviewInfo.cshtml | 146 +++++--- SolarPower/Views/StationOverview/_Info.cshtml | 6 +- SolarPower/Views/User/Index.cshtml | 176 ++++----- SolarPower/Views/User/_RoleAuth.cshtml | 2 + SolarPower/appsettings.Development.json | 11 + SolarPower/appsettings.json | 17 +- 30 files changed, 731 insertions(+), 454 deletions(-) diff --git a/SolarPower/Controllers/MyBaseController.cs b/SolarPower/Controllers/MyBaseController.cs index bfd553d..3f93fd2 100644 --- a/SolarPower/Controllers/MyBaseController.cs +++ b/SolarPower/Controllers/MyBaseController.cs @@ -33,6 +33,7 @@ namespace SolarPower.Controllers private IUserRepository userRepository => HttpContext?.RequestServices.GetService(); private ICompanyRepository companyRepository => HttpContext?.RequestServices.GetService(); private IRoleRepository roleRepository => HttpContext?.RequestServices.GetService(); + private IPowerStationRepository powerStationRepository => HttpContext?.RequestServices.GetService(); private IOperatorLogRepository operatorLogRepository => HttpContext?.RequestServices.GetService(); protected MyUser myUser = null; @@ -83,9 +84,23 @@ namespace SolarPower.Controllers } } - ViewBag.auths = auth_arr; + if (myUser.Role.Layer != (int)RoleLayerEnum.PlatformAdmin && !auth_arr.Contains(controllerName)) + { + filterContext.Result = new RedirectToRouteResult( + new RouteValueDictionary + { + {"controller", "Login"}, + {"action", "Index"} + }); + return; + } + //取得當前使用者可以查看的電站 + ViewBag.myPowerStationSummaries = powerStationRepository.GetMyPowerStationSummary(myUser); + + ViewBag.auths = auth_arr; + ViewBag.myUser = myUser; #region 記錄人員操作記錄 diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index d205b3d..131c244 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -50,14 +50,13 @@ namespace SolarPower.Controllers /// /// [HttpGet] - public async Task>> GetUserSelectOptionListAsync() + public async Task>> GetUserSelectOptionListAsync(int powerStationId) { ApiResult> apiResult = new ApiResult>(); try { - EDFunction edFunction = new EDFunction(); - var companyId = Convert.ToInt32(edFunction.AESDecrypt(HttpContext.Session.GetString("CompanyId"))); //將公司id透過AES解密 - var userSelectItemLists = await userRepository.GetUserSelectOptionListAsync(companyId); + var powerStation = await powerStationRepository.GetOneAsync(powerStationId); + var userSelectItemLists = await userRepository.GetUserSelectOptionListAsync(powerStation.CompanyId); apiResult.Code = "0000"; apiResult.Data = userSelectItemLists; @@ -119,7 +118,7 @@ namespace SolarPower.Controllers } /// - /// 取得縣市選單 + /// 取得地區選單 /// /// [HttpPost] @@ -186,7 +185,7 @@ namespace SolarPower.Controllers apiResult.Msg = errorCode.GetString(apiResult.Code); return apiResult; } - else if (powerStation.CompanyId != myUser.CompanyId) + else if (!IsPlatformLayer(myUser.Role.Layer) && powerStation.CompanyId != myUser.CompanyId) { apiResult.Code = "9993"; apiResult.Msg = errorCode.GetString(apiResult.Code); @@ -364,7 +363,7 @@ namespace SolarPower.Controllers } else { - if (powerStation.CompanyId != myUser.CompanyId) + if (!IsPlatformLayer(myUser.Role.Layer) && powerStation.CompanyId != myUser.CompanyId) { apiResult.Code = "9993"; apiResult.Msg = errorCode.GetString(apiResult.Code); @@ -523,7 +522,7 @@ namespace SolarPower.Controllers } else { - if (powerStation.CompanyId != myUser.CompanyId) + if (!IsPlatformLayer(myUser.Role.Layer) && powerStation.CompanyId != myUser.CompanyId) { apiResult.Code = "9993"; apiResult.Msg = errorCode.GetString(apiResult.Code); @@ -636,7 +635,7 @@ namespace SolarPower.Controllers } else { - if (powerStation.CompanyId != myUser.CompanyId) + if (!IsPlatformLayer(myUser.Role.Layer) && powerStation.CompanyId != myUser.CompanyId) { apiResult.Code = "9993"; apiResult.Msg = errorCode.GetString(apiResult.Code); @@ -1453,7 +1452,7 @@ namespace SolarPower.Controllers else { - if(powerStation.CompanyId != myUser.CompanyId) + if(!IsPlatformLayer(myUser.Role.Layer) && powerStation.CompanyId != myUser.CompanyId) { apiResult.Code = "9993"; apiResult.Msg = errorCode.GetString(apiResult.Code); @@ -1506,7 +1505,7 @@ namespace SolarPower.Controllers } else { - if (powerStation.CompanyId != myUser.CompanyId) + if (!IsPlatformLayer(myUser.Role.Layer) && powerStation.CompanyId != myUser.CompanyId) { apiResult.Code = "9993"; apiResult.Msg = errorCode.GetString(apiResult.Code); @@ -1611,7 +1610,7 @@ namespace SolarPower.Controllers return apiResult; } - if (powerStation.CompanyId != myUser.CompanyId) + if (!IsPlatformLayer(myUser.Role.Layer) && powerStation.CompanyId != myUser.CompanyId) { apiResult.Code = "9993"; apiResult.Msg = errorCode.GetString(apiResult.Code); @@ -1659,7 +1658,7 @@ namespace SolarPower.Controllers return apiResult; } - if (powerStation.CompanyId != myUser.CompanyId) + if (!IsPlatformLayer(myUser.Role.Layer) && powerStation.CompanyId != myUser.CompanyId) { apiResult.Code = "9993"; apiResult.Msg = errorCode.GetString(apiResult.Code); @@ -1749,7 +1748,7 @@ namespace SolarPower.Controllers } else { - if (powerStation.CompanyId != myUser.CompanyId) + if (!IsPlatformLayer(myUser.Role.Layer) && powerStation.CompanyId != myUser.CompanyId) { apiResult.Code = "9993"; apiResult.Msg = errorCode.GetString(apiResult.Code); @@ -1802,7 +1801,7 @@ namespace SolarPower.Controllers } else { - if (powerStation.CompanyId != myUser.CompanyId) + if (!IsPlatformLayer(myUser.Role.Layer) && powerStation.CompanyId != myUser.CompanyId) { apiResult.Code = "9993"; apiResult.Msg = errorCode.GetString(apiResult.Code); @@ -1899,7 +1898,7 @@ namespace SolarPower.Controllers { powerStation = await powerStationRepository.GetOneAsync(post.PowerStationId); - if (powerStation.CompanyId != myUser.CompanyId) + if (!IsPlatformLayer(myUser.Role.Layer) && powerStation.CompanyId != myUser.CompanyId) { apiResult.Code = "9993"; apiResult.Msg = errorCode.GetString(apiResult.Code); diff --git a/SolarPower/Controllers/UserController.cs b/SolarPower/Controllers/UserController.cs index 3c3a518..72931e1 100644 --- a/SolarPower/Controllers/UserController.cs +++ b/SolarPower/Controllers/UserController.cs @@ -301,7 +301,7 @@ namespace SolarPower.Controllers #region 新增使用者 //判斷帳號 是否已存在 - var exist = userRepository.GetOneByAccountAsync(post.Account); + var exist = await userRepository.GetOneByAccountAsync(post.Account); if(exist != null) { apiResult.Code = "9986"; diff --git a/SolarPower/DBSchema/solar_power_schema.sql b/SolarPower/DBSchema/solar_power_schema.sql index 0ecb41a..35d7be7 100644 --- a/SolarPower/DBSchema/solar_power_schema.sql +++ b/SolarPower/DBSchema/solar_power_schema.sql @@ -401,30 +401,43 @@ INSERT INTO `area` (`Id`, `CityId`, `Name`, `ZipCode`) VALUES (368, 21, '烏坵鄉', '06'); /*!40000 ALTER TABLE `area` ENABLE KEYS */; --- 傾印 資料表 solar_power.auth_page 結構 +-- 傾印 資料表 auth_page 結構 CREATE TABLE IF NOT EXISTS `auth_page` ( - `AuthCode` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL, - `MainName` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '大項名稱', - `SubName` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '功能名稱', - `ControlName` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `AuthCode` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, + `MainName` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '大項名稱', + `SubName` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '功能名稱', + `TagName` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '細項功能名稱', + `ControlName` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL, PRIMARY KEY (`AuthCode`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='設定權限頁面'; --- 正在傾印表格 solar_power.auth_page 的資料:~-1 rows (近似值) +-- 正在傾印表格 auth_page 的資料 DELETE FROM `auth_page`; /*!40000 ALTER TABLE `auth_page` DISABLE KEYS */; -INSERT INTO `auth_page` (`AuthCode`, `MainName`, `SubName`, `ControlName`) VALUES - ('A', '系統管理', '帳號管理', 'User,Role'), - ('B', '系統管理', '公司管理', 'Company'), - ('C', '系統管理', '電站資料管理', 'AAA'), - ('D', '系統管理', '定時任務設定', 'Setting'), - ('E', '系統管理', '功能清單', 'ASDA'), - ('F', '總覽', '地圖總覽', 'BBB'), - ('G', '總攬', '電占總覽', 'CCC'), - ('H', '總覽', '運為總覽', 'HHH'), - ('J', '即時告警', '即時告警', 'JJJ'), - ('K', '交叉分析', '逆變器', 'KKK'), - ('L', '交叉分析', '電站運轉效率', 'LLL'); +INSERT INTO `auth_page` (`AuthCode`, `MainName`, `SubName`, `TagName`, `ControlName`) VALUES + ('A', '總覽', '地圖總覽', NULL, 'MapOverview'), + ('B', '總覽', '電站總覽', NULL, 'StationOverview'), + ('C', '總覽', '電站總覽', '即時資訊', 'StationOverview_UpToDate'), + ('D', '總覽', '電站總覽', '基本資料', 'StationOverview_Info'), + ('E', '總覽', '電站總覽', '歷史資料', 'StationOverview_History'), + ('F', '總覽', '電站總覽', '逆變器分析', 'StationOverview_Inverter'), + ('G', '總覽', '電站總覽', '異常記錄', 'StationOverview_Exception'), + ('H', '總覽', '電站總覽', '運維記錄', 'StationOverview_OperationRecord'), + ('J', '總覽', '電站總覽', '顯示發電金額', 'ShowMoney'), + ('K', '電站資訊', '電站管理', NULL, 'PowerStation'), + ('L', '交叉分析', '合併電站', NULL, 'Setting'), + ('M', '交叉分析', '電站交叉分析', NULL, 'ASDA'), + ('N', '交叉分析', '逆變器交叉分析', NULL, 'BBB'), + ('P', '報表查詢', '電站報表', NULL, 'CCC'), + ('Q', '報表查詢', '電廠發電效能統計', NULL, 'HHH'), + ('R', '報表查詢', '輸入台電售電紀錄', NULL, 'JJJ'), + ('S', '報表查詢', '報告發送設定', NULL, 'JJJ'), + ('T', '即時告警', '異常事件查詢', NULL, 'KKK'), + ('U', '運維管理', '定期計畫建立', NULL, 'Operation'), + ('V', '運維管理', '運維作業記錄', NULL, 'OperationRecord'), + ('W', '系統管理', '公司管理', NULL, 'Company'), + ('X', '系統管理', '帳號管理', NULL, 'User,Role'), + ('Y', '系統管理', '定時任務設定', NULL, 'LLL'); /*!40000 ALTER TABLE `auth_page` ENABLE KEYS */; -- 傾印 資料表 solar_power.city 結構 @@ -1024,24 +1037,6 @@ COMMENT='各電站每月日照度的平均值' COLLATE='utf8mb4_unicode_ci' ENGINE=InnoDB ; --- 子DB逆變器新增欄位 20210708 -ALTER TABLE `inverter` - ADD COLUMN `Enabled` tinyint(4) DEFAULT '0' COMMENT '是否啟用,0:未啟用 1:啟用' AFTER `Deleted`, - ADD COLUMN `Status` tinyint(4) DEFAULT '0' COMMENT '狀態,0:未啟用 1:正常 2:異常' AFTER `Enabled`, - ADD COLUMN `InstallDate` timestamp NULL DEFAULT NULL COMMENT '安裝日期' AFTER `Status`, - ADD COLUMN `InverterName` varchar(50) DEFAULT NULL COMMENT '逆變器名稱' AFTER `SerialNumber`, - ADD COLUMN `Brand` varchar(50) DEFAULT NULL COMMENT '廠牌' AFTER `ControllerId`, - ADD COLUMN `Model` varchar(50) DEFAULT NULL COMMENT '型號' AFTER `Brand`, - ADD COLUMN `Capacity` double(10,3) DEFAULT NULL COMMENT '裝置容量 kWp' AFTER `Model`, - ADD COLUMN `Pyrheliometer` int(10) DEFAULT NULL COMMENT '日照計設備流水號'AFTER `Capacity`; - --- 子DB裝置列表新增欄位 20210708 -ALTER TABLE `device` - ADD COLUMN `Enabled` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否啟用, 0:否 1:是' AFTER `PowerStationId`, - ADD COLUMN `Status` tinyint(4) DEFAULT '0' COMMENT '狀態,0:未啟用 1:正常 2:異常' AFTER `Enabled`, - ADD COLUMN `InstallDate` timestamp NULL DEFAULT NULL COMMENT '安裝日期' AFTER `ColName`, - DROP COLUMN `Remark`; - -- 各電站每天的逆變器歷史記錄 20210712 CREATE TABLE `inverter_history_day` ( diff --git a/SolarPower/Helper/DatabaseHelper.cs b/SolarPower/Helper/DatabaseHelper.cs index 7ce0dc2..bcd499f 100644 --- a/SolarPower/Helper/DatabaseHelper.cs +++ b/SolarPower/Helper/DatabaseHelper.cs @@ -38,7 +38,6 @@ namespace SolarPower.Helper var passwordStr = ed.AESDecrypt(dbConfig.Password); var connStr = $"server={serverStr};port={portStr};database={databaseStr};user={rootStr};password={passwordStr};charset=utf8;"; - //var connStr = @"server=210.61.91.43;port=10068;database=solar_power_test;user=idafenweb;password=P@ssw0rd;charset=utf8;"; this._connectionString = connStr; } diff --git a/SolarPower/Models/Company.cs b/SolarPower/Models/Company.cs index cda8470..65a7c79 100644 --- a/SolarPower/Models/Company.cs +++ b/SolarPower/Models/Company.cs @@ -93,6 +93,7 @@ namespace SolarPower.Models.Company public string AuthCode { get; set; } public string MainName { get; set; } public string SubName { get; set; } + public string TagName { get; set; } public string ControlName { get; set; } public byte CheckAuth { get; set; } } diff --git a/SolarPower/Models/MyBaseModel.cs b/SolarPower/Models/MyBaseModel.cs index 55e98b8..98ec112 100644 --- a/SolarPower/Models/MyBaseModel.cs +++ b/SolarPower/Models/MyBaseModel.cs @@ -74,6 +74,27 @@ namespace SolarPower.Models public List Auths { get; set; } //可操作頁面 } + public class MyPowerStationInfo + { + public int Id { get; set; } + public int CityId { get; set; } + public string CityName { get; set; } + public string Name { get; set; } + } + + public class MyPowerStationSummary + { + public string CityName { get; set; } + public int Amount { get; set; } + public List MyPowerStations { get; set; } + } + + public class MyPowerStation + { + public int PowerStationId { get; set; } + public string PowerStationName { get; set; } + } + public class Variable { public string Name { get; set; } diff --git a/SolarPower/Models/Role.cs b/SolarPower/Models/Role.cs index 15223d3..72c3970 100644 --- a/SolarPower/Models/Role.cs +++ b/SolarPower/Models/Role.cs @@ -89,6 +89,7 @@ namespace SolarPower.Models.Role public string CompanyName { get; set; } //公司名稱 public string RoleName { get; set; } //角色名稱 public string AuthPageSubName { get; set; } //權限功能名稱 + public string AuthPageTagName { get; set; } //權限功能細項名稱 public string CreatorName { get; set; } //建立者名稱 } @@ -106,6 +107,7 @@ namespace SolarPower.Models.Role public string AuthCode { get; set; } public string MainName { get; set; } public string SubName { get; set; } + public string TagName { get; set; } } public class PostRoleAuth diff --git a/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs index 045b46d..3d9da71 100644 --- a/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcAvgPowerStationJob.cs @@ -58,8 +58,6 @@ namespace SolarPower.Quartz.Jobs calcPowerStation.Id = powerStation.Id; var dateNowDay = DateTimeNow.AddDays(-1).ToString("yyyy-MM-dd"); - dateNowDay = "2021-07-08"; - #region step2-1. 計算該電站的30天平均資料 var table_name = String.Format("`{0}`.`{1}01_station`", powerStation.SiteDB, powerStation.Code); var history = await powerStationRepository.CalcAvgPowerStationHistory30day(dateNowDay, table_name); diff --git a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs index 98a3ea3..53b422c 100644 --- a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs @@ -29,6 +29,9 @@ namespace SolarPower.Quartz.Jobs { #region step1. 找出所有電站 var powerStations = await powerStationRepository.GetAllAsync(); + + string json = System.Text.Json.JsonSerializer.Serialize(powerStations); + logger.LogError("【{0}】{1}", "CalcPowerStationJob - step1", json); #endregion List powerStationHistoriesHour = new List(); @@ -54,12 +57,14 @@ namespace SolarPower.Quartz.Jobs var dateTime = DateTimeNow.AddHours(-1).ToString("yyyy-MM-dd HH"); - dateTime = "2021-07-08 12"; - #region step2-1. 取得該電站的當前這小時的歷史資料 var table_name = String.Format("`{0}`.{1}01_station", powerStation.SiteDB, powerStation.Code); + logger.LogError("【{0}】{1}", "CalcPowerStationJob - time & dataTable", dateTime + "======" + table_name); var history = await powerStationRepository.GetPowerStationHistoryPerHour(dateTime, table_name); + json = System.Text.Json.JsonSerializer.Serialize(history); + logger.LogError("【{0}】{1}", "CalcPowerStationJob - history", json); + if (history != null) { history.PowerStationId = powerStation.Id; @@ -208,6 +213,9 @@ namespace SolarPower.Quartz.Jobs "SolarHour" }; + json = System.Text.Json.JsonSerializer.Serialize(powerStationHistoriesHour); + logger.LogError("【{0}】{1}", "CalcPowerStationJob - step3", json); + await powerStationRepository.AddPowerStationHistory(powerStationHistoriesHour, history_properties); #endregion diff --git a/SolarPower/Repository/Implement/CompanyRepository.cs b/SolarPower/Repository/Implement/CompanyRepository.cs index 0d30095..f7263a4 100644 --- a/SolarPower/Repository/Implement/CompanyRepository.cs +++ b/SolarPower/Repository/Implement/CompanyRepository.cs @@ -34,12 +34,12 @@ namespace SolarPower.Repository.Implement { var sql = $"SELECT Id AS Value, Name AS Text FROM {tableName} WHERE Deleted = 0"; - if(companyId > 0) + if (companyId > 0) { sql += " AND Id = @SelectedCompanyId"; } - result = (await conn.QueryAsync(sql, new { SelectedCompanyId = companyId})).ToList(); + result = (await conn.QueryAsync(sql, new { SelectedCompanyId = companyId })).ToList(); } catch (Exception exception) { @@ -444,7 +444,7 @@ namespace SolarPower.Repository.Implement `UpdatedBy` int(10) unsigned DEFAULT NULL, `UpdatedAt` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`Id`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='控制器'; + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='控制器'; -- 傾印 資料表 device 結構 CREATE TABLE IF NOT EXISTS `device` ( @@ -494,7 +494,7 @@ namespace SolarPower.Repository.Implement `UpdatedBy` int(10) DEFAULT NULL, `UpdatedAt` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`Id`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='逆變器'; + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='逆變器'; -- 傾印 資料表 land_building 結構 CREATE TABLE IF NOT EXISTS `land_building` ( @@ -536,56 +536,64 @@ namespace SolarPower.Repository.Implement -- 傾印 資料表 power_station 結構 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 '電站區域', - `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 '總發電量', - `kwhkwp` decimal(10,3) unsigned NOT NULL DEFAULT '0.000', - `PR` decimal(5,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '電站Pr值', - `MP` decimal(5,2) unsigned NOT NULL DEFAULT '0.00', - `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 '今日溫度', - `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 NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '修改時間', + `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_monery` DECIMAL(10,2) NULL DEFAULT NULL COMMENT '今日金額', + `total_monery` 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`), @@ -644,7 +652,7 @@ namespace SolarPower.Repository.Implement `CreatedBy` int(10) unsigned NOT NULL, `CreatedAt` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`Id`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='共享設備'; + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='共享設備'; "; await conn.ExecuteAsync(sql, trans); diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index a6217e2..ba0dbee 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -22,6 +22,64 @@ namespace SolarPower.Repository.Implement tableName = "power_station"; } + + public List GetMyPowerStationSummary(MyUser myUser) + { + List results = new List(); + + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + try + { + var sql = @"SELECT ps.Id, ps.CityId, c.Name AS CityName, ps.Name + FROM power_station ps + LEFT JOIN city c ON ps.CityId = c.Id"; + + if(myUser.Role.Layer == 2) + { //公司管理員 + sql += @" WHERE ps.Deleted = 0 AND ps.CompanyId = @CompanyId"; + } + else if (myUser.Role.Layer == 3) + { + sql += @" LEFT JOIN power_station_operation_personnel ps.Id = op.PowerStationId + WHERE ps.Deleted = 0 AND op.Deleted = 0 AND op.UserId = @UserId "; + } + else + { + sql += @" WHERE ps.Deleted = 0"; + } + + var myPowerStationInfos = conn.Query(sql, new { CompanyId = myUser.CompanyId, UserId = myUser.Id }).ToList(); + + var myPowerStationInfos_group = myPowerStationInfos.GroupBy(x => x.CityId); + + foreach (var myPowerStationInfo in myPowerStationInfos_group) + { + MyPowerStationSummary myPowerStationSummary = new MyPowerStationSummary(); + myPowerStationSummary.CityName = myPowerStationInfo.First().CityName; + myPowerStationSummary.Amount = myPowerStationInfo.Count(); + myPowerStationSummary.MyPowerStations = new List(); + foreach (var info in myPowerStationInfo) + { + MyPowerStation myPowerStation = new MyPowerStation(); + myPowerStation.PowerStationId = info.Id; + myPowerStation.PowerStationName = info.Name; + + myPowerStationSummary.MyPowerStations.Add(myPowerStation); + } + + results.Add(myPowerStationSummary); + } + + } + catch (Exception exception) + { + throw exception; + } + return results; + } + } + /// /// 查詢縣市列表 /// @@ -2186,12 +2244,12 @@ namespace SolarPower.Repository.Implement { var sql = $@"SELECT * FROM {db_name}.device d - WHERE d.PowerStationId = @PowerStationId AND d.`Type` = 'PYR' AND d.Deleted = 0 + WHERE d.PowerStationId = @PowerStationId AND d.`Type` = 'PYR' AND d.Deleted = 0 AND d.Enabled = 1 AND d.Status != 0 UNION SELECT d.* FROM {db_name}.sharedevice sd LEFT JOIN {db_name}.device d ON sd.DeviceId = d.Id - WHERE sd.PowerStationId = @PowerStationId AND d.`Type` = 'PYR' AND d.Deleted = 0 + WHERE sd.PowerStationId = @PowerStationId AND d.`Type` = 'PYR' AND d.Deleted = 0 AND d.Enabled = 1 AND d.Status != 0 "; result = (await conn.QueryAsync(sql, new { PowerStationId = powerStationId })).ToList(); @@ -2213,12 +2271,12 @@ namespace SolarPower.Repository.Implement { var sql = $@"SELECT * FROM {db_name}.device d - WHERE d.PowerStationId = @PowerStationId AND d.`Type` = 'MTR' AND d.Deleted = 0 + WHERE d.PowerStationId = @PowerStationId AND d.`Type` = 'MTR' AND d.Deleted = 0 AND d.Enabled = 1 AND d.Status != 0 UNION SELECT d.* FROM {db_name}.sharedevice sd LEFT JOIN {db_name}.device d ON sd.DeviceId = d.Id - WHERE sd.PowerStationId = @PowerStationId AND d.`Type` = 'MTR' AND d.Deleted = 0 + WHERE sd.PowerStationId = @PowerStationId AND d.`Type` = 'MTR' AND d.Deleted = 0 AND d.Enabled = 1 AND d.Status != 0 "; result = (await conn.QueryAsync(sql, new { PowerStationId = powerStationId })).ToList(); @@ -2259,7 +2317,7 @@ namespace SolarPower.Repository.Implement sql_per_device.Add(str); } - var sql = @$"SELECT a.TIMESTAMP, AVG(a.SENSOR) AS {typename} FROM(" + string.Join(" UNION ", sql_per_device) + @") a GROUP BY TIMESTAMP"; + var sql = @$"SELECT a.TIMESTAMP, AVG(a.SENSOR) AS {typename} FROM(" + string.Join(" UNION ", sql_per_device) + @") a GROUP BY `TIMESTAMP`"; result = await conn.QueryFirstOrDefaultAsync(sql, new { DateTime = dateTime }); } @@ -2802,7 +2860,7 @@ namespace SolarPower.Repository.Implement if (myUser.Role.Layer == (int)RoleLayerEnum.CompanyAdmin) { - sql += @$"SELECT ps.Id FROM power_station ps WHERE ps.Deleted = 0 AND ComapnyId = @ComapnyId"; + sql += @$"SELECT ps.Id FROM power_station ps WHERE ps.Deleted = 0 AND ps.CompanyId = @CompanyId"; } else if (myUser.Role.Layer == (int)RoleLayerEnum.CompanyUser) { diff --git a/SolarPower/Repository/Implement/RoleRepository.cs b/SolarPower/Repository/Implement/RoleRepository.cs index 6e0a291..b59c0b6 100644 --- a/SolarPower/Repository/Implement/RoleRepository.cs +++ b/SolarPower/Repository/Implement/RoleRepository.cs @@ -30,7 +30,7 @@ namespace SolarPower.Repository.Implement { try { - var sql = $"SELECT Id AS Value, Name AS Text FROM {tableName} WHERE Deleted = 0 AND CompanyId = @CompanyId"; + var sql = $"SELECT Id AS Value, Name AS Text FROM `{tableName}` WHERE Deleted = 0 AND CompanyId = @CompanyId"; result = (await conn.QueryAsync(sql, new { CompanyId = companyId })).ToList(); } @@ -55,7 +55,7 @@ namespace SolarPower.Repository.Implement conn.Open(); try { - var sql = $"SELECT * FROM {tableName} WHERE Deleted = 0 AND Id = @Id"; + var sql = $"SELECT * FROM `{tableName}` WHERE Deleted = 0 AND Id = @Id"; result = conn.QueryFirstOrDefault(sql, new { Id = id }); @@ -91,7 +91,7 @@ namespace SolarPower.Repository.Implement conn.Open(); try { - var sql = $"SELECT * FROM {tableName} WHERE Deleted = 0 AND Id = @Id"; + var sql = $"SELECT * FROM `{tableName}` WHERE Deleted = 0 AND Id = @Id"; result = await conn.QueryFirstOrDefaultAsync(sql, new { Id = id }); } @@ -123,7 +123,7 @@ namespace SolarPower.Repository.Implement r.*, c.Name AS CompanyName, u.Name AS CreatorName - FROM {tableName} r + FROM `{tableName}` r LEFT JOIN company c ON r.CompanyId = c.Id LEFT JOIN user u ON r.CreatedBy = u.Id WHERE r.Deleted = 0 @@ -195,9 +195,10 @@ namespace SolarPower.Repository.Implement r.Name AS RoleName, c.Name AS CompanyName, u.Name AS CreatorName, - ap.SubName AS AuthPageSubName + ap.SubName AS AuthPageSubName, + ap.TagName AS AuthPageTagName FROM role_auth ra - LEFT JOIN role r ON ra.Id = r.Id + LEFT JOIN `role` r ON ra.Id = r.Id LEFT JOIN auth_page ap ON ra.AuthCode = ap.AuthCode LEFT JOIN user u ON ra.CreatedBy = u.Id LEFT JOIN company c ON r.CompanyId = c.Id @@ -257,10 +258,10 @@ namespace SolarPower.Repository.Implement { try { - var sql = @$"SELECT ap2.AuthCode, ap2.MainName, ap2.SubName + var sql = @$"SELECT ap2.AuthCode, ap2.MainName, ap2.SubName, ap2.TagName FROM ( - SELECT cap.CompanyId, cap.AuthCode, ap.MainName, ap.SubName, ap.ControlName + SELECT cap.CompanyId, cap.AuthCode, ap.MainName, ap.SubName, ap.TagName , ap.ControlName FROM company_auth_page cap LEFT JOIN auth_page ap ON cap.AuthCode = ap.AuthCode WHERE cap.CompanyId = @CompanyId diff --git a/SolarPower/Repository/Implement/UserRepository.cs b/SolarPower/Repository/Implement/UserRepository.cs index 8810432..1c560ea 100644 --- a/SolarPower/Repository/Implement/UserRepository.cs +++ b/SolarPower/Repository/Implement/UserRepository.cs @@ -30,7 +30,7 @@ namespace SolarPower.Repository.Implement { try { - var sql = $"SELECT * FROM {tableName} WHERE deleted = 0 AND status = @Status AND account = @Account"; + var sql = $"SELECT * FROM `{tableName}` WHERE deleted = 0 AND status = @Status AND account = @Account"; result = await conn.QueryFirstOrDefaultAsync(sql, new { Status = UserStatusEnum.Normal, Account = account }); } @@ -55,7 +55,7 @@ namespace SolarPower.Repository.Implement conn.Open(); try { - var sql = $"SELECT * FROM {tableName} WHERE deleted = 0 AND status = @Status AND email = @Email"; + var sql = $"SELECT * FROM `{tableName}` WHERE deleted = 0 AND status = @Status AND email = @Email"; result = await conn.QueryFirstOrDefaultAsync(sql, new { Status = UserStatusEnum.Normal, Email = email }); } @@ -86,7 +86,7 @@ namespace SolarPower.Repository.Implement { try { - var sql = $"UPDATE {tableName} SET password = @Password WHERE id = @Id"; + var sql = $"UPDATE `{tableName}` SET password = @Password WHERE id = @Id"; await conn.ExecuteAsync(sql, new { Password = password, Id = id }, trans); @@ -118,7 +118,7 @@ namespace SolarPower.Repository.Implement conn.Open(); try { - var sql = $"SELECT * FROM {tableName} WHERE deleted = 0 AND status = @Status AND account = @Account"; + var sql = $"SELECT * FROM `{tableName}` WHERE deleted = 0 AND status = @Status AND account = @Account"; result = conn.QueryFirstOrDefault(sql, new { Status = UserStatusEnum.Normal, Account = account }); } @@ -150,7 +150,7 @@ namespace SolarPower.Repository.Implement var sql = @$"SELECT u.*, c.Name AS CompanyName - FROM {tableName} u + FROM `{tableName}` u LEFT JOIN company c ON u.CompanyId = c.Id WHERE u.Deleted = 0 AND u.Id = @Id"; @@ -254,9 +254,9 @@ namespace SolarPower.Repository.Implement c.Name AS CompanyName, r.Name AS RoleName, opc.SPStationAmount - FROM {tableName} u + FROM `{tableName}` u LEFT JOIN company c ON u.CompanyId = c.Id - LEFT JOIN role r ON u.RoleId = r.Id + LEFT JOIN `role` r ON u.RoleId = r.Id LEFT JOIN (SELECT op.UserId, COUNT(*) AS SPStationAmount FROM power_station_operation_personnel op WHERE op.Deleted = 0 GROUP BY op.UserId) opc ON u.Id = opc.UserId WHERE u.Deleted = 0"; @@ -299,7 +299,7 @@ namespace SolarPower.Repository.Implement { try { - var sql = $"SELECT Id AS Value, Name AS Text FROM {tableName} WHERE Deleted = 0"; + var sql = $"SELECT Id AS Value, Name AS Text FROM `{tableName}` WHERE Deleted = 0"; if (companyId != 0) { sql += @" AND CompanyId=@companyId"; diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index 01c3538..aeab924 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -11,6 +11,13 @@ namespace SolarPower.Repository.Interface public interface IPowerStationRepository : IRepositoryBase { + /// + /// 取得當前使用者可操作的電站 + /// + /// + /// + List GetMyPowerStationSummary(MyUser myUser); + /// /// 查詢縣市列表 /// diff --git a/SolarPower/Startup.cs b/SolarPower/Startup.cs index 31d6e1c..d3bdb3f 100644 --- a/SolarPower/Startup.cs +++ b/SolarPower/Startup.cs @@ -101,7 +101,7 @@ namespace SolarPower #region pqoqqT(CI5) services.AddSingleton(); services.AddSingleton( - new JobSchedule(jobType: typeof(CalcPowerStationJob), cronExpression: "0 5 * * * ?") + new JobSchedule(jobType: typeof(CalcPowerStationJob), cronExpression: Configuration.GetValue("BackgroundServiceCron:CalcPowerStationJob")) //new JobSchedule(jobType: typeof(CalcPowerStationJob), cronExpression: "0/10 * * * * ?") ); #endregion @@ -109,7 +109,7 @@ namespace SolarPower #region pqӶqBPRBkWP 30饭B(Cѭ2I) services.AddSingleton(); services.AddSingleton( - new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: "0 0 2 * * ?") + new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: Configuration.GetValue("BackgroundServiceCron:CalcAvgPowerStationJob")) //new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: "0/10 * * * * ?") ); #endregion diff --git a/SolarPower/Views/Company/Index.cshtml b/SolarPower/Views/Company/Index.cshtml index d7d63c2..8ba9c90 100644 --- a/SolarPower/Views/Company/Index.cshtml +++ b/SolarPower/Views/Company/Index.cshtml @@ -168,6 +168,7 @@ @*編號*@ 功能大項 功能名稱 + 功能細項名稱 @@ -247,7 +248,7 @@ 'orderable': false, 'className': 'dt-body-center', 'render': function (data, type, full, meta) { - return ''; + return ''; } }], "language": { @@ -318,6 +319,8 @@ "data": "mainName" }, { "data": "subName" + }, { + "data": "tagName" }], "columnDefs": [{ 'targets': 0, diff --git a/SolarPower/Views/MapOverview/Index.cshtml b/SolarPower/Views/MapOverview/Index.cshtml index dc40e8b..e856523 100644 --- a/SolarPower/Views/MapOverview/Index.cshtml +++ b/SolarPower/Views/MapOverview/Index.cshtml @@ -16,51 +16,55 @@

發電量

+
kwh

總發電量

-

126,161.72 kWh

+

126,161.72

平均發電量

-

4,069.73 kWh

+

4,069.73

日照度

+
kw/m2

即時平均日照度

-

126,161.72 kW/m2

+

126,161.72

平均日照度(30天)

-

4,069.73 kW/m2

+

4,069.73

PR值

+
%

即時平均 PR 值

-

119.04 hr

+

119.04

平均 PR 值(30天)

-

3.84 hr

+

3.84

kWh / kWp

+
hr
@@ -76,15 +80,16 @@

減碳量

+
kG

今日減碳量

-

6,091.78 KG

+

6,091.78

總減碳量

-

985.98 KG

+

985.98

diff --git a/SolarPower/Views/PowerStation/PowerStationEdit.cshtml b/SolarPower/Views/PowerStation/PowerStationEdit.cshtml index 0351b2d..4c6cc82 100644 --- a/SolarPower/Views/PowerStation/PowerStationEdit.cshtml +++ b/SolarPower/Views/PowerStation/PowerStationEdit.cshtml @@ -33,27 +33,27 @@ @@ -708,7 +708,10 @@ //#region 預先載入運維人員下拉式選單select_option var url_user_select_option = "/PowerStation/GetUserSelectOptionList"; - $.get(url_user_select_option, function (rel) { + var send_data = { + powerStationId: stationId + } + $.get(url_user_select_option, send_data, function (rel) { if (rel.code != "0000") { toast_error(rel.msg); return; @@ -745,8 +748,10 @@ $.each(rel.data, function (index, val) { $("#ShareDevice_PowerStationId_modal").append($("