diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index 6a7d616..2bce9d5 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -3254,7 +3254,7 @@ namespace SolarPower.Controllers try { var powerStation = await powerStationRepository.GetOneAsync(Id); - status = await powerStationRepository.CheckStationStatus(powerStation.Code, powerStation.SiteDB, powerStation.Id.ToString()); + status = await powerStationRepository.CheckStationStatus_v2(powerStation.Code, powerStation.SiteDB, powerStation.Id.ToString()); if(status.Count > 0) { apiResult.Code = "0099"; diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index 16c6d03..1d7d758 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -5582,7 +5582,7 @@ namespace SolarPower.Repository.Implement // execute stmt ;"; sql2 += @$"#檢查是否存在設備({device.Text})# set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) - select ', siteID ,', ''device'', ''device_Type_{device.Value}'', + select ', ''{code}01'' ,', ''device'', ''device_Type_{device.Value}'', case when count(*) > 0 then 0 else 1 end isError, now(), case when count(*) > 0 then Null else ''電站無正常啟用{device.Text}'' end error_reason @@ -5607,7 +5607,7 @@ namespace SolarPower.Repository.Implement { sql3 += @$"# 檢查資料表_{table}是否存在# set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) - select ', siteID ,', ''{table}'', ''{table}_Table'', + select ', ''{code}01'' ,', ''{table}'', ''{table}_Table'', case when count(*) > 0 then 0 else 1 end isError, now(), case when count(*) > 0 then Null else ''_{table}原始資料表不存在'' end error_reason @@ -5635,133 +5635,126 @@ namespace SolarPower.Repository.Implement execute stmt ; #檢查電站缺少的欄位(住址)# SET @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) - select ', siteID ,', ''station'', ''address_isnull'', case when ISNULL(a.Address) = 0 then 0 else 1 end isError, now() ,case when ISNULL(a.Address) = 0 then Null else ''電站住址為空'' end error_reason + select ', ''{code}01'' ,', ''station'', ''address_isnull'', case when ISNULL(a.Address) = 0 then 0 else 1 end isError, now() ,case when ISNULL(a.Address) = 0 then Null else ''電站住址為空'' end error_reason from power_station a - where a.`Code` = ', siteID ); + where a.`Code` = ', ''{code}01'' ); prepare stmt from @qry1 ; execute stmt ; #檢查電站缺少的欄位(名稱)# set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) - select ', siteID ,', ''station'', ''name_isnull'', case when ISNULL(a.Name) = 0 then 0 else 1 end isError, now(),case when ISNULL(a.Name) = 0 then Null else ''電站名稱為空'' end error_reason + select ', ''{code}01'' ,', ''station'', ''name_isnull'', case when ISNULL(a.Name) = 0 then 0 else 1 end isError, now(),case when ISNULL(a.Name) = 0 then Null else ''電站名稱為空'' end error_reason from power_station a - where a.`Code` = ', siteID ); + where a.`Code` = ', ''{code}01'' ); prepare stmt from @qry1 ; execute stmt ; #檢查電站缺少的欄位(編號)# set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) - select ', siteID ,', ''station'', ''code_isnull'', case when ISNULL(a.Code) = 0 then 0 else 1 end isError, now(),case when ISNULL(a.Code) = 0 then Null else ''電站編號為空'' end error_reason + select ', ''{code}01'' ,', ''station'', ''code_isnull'', case when ISNULL(a.Code) = 0 then 0 else 1 end isError, now(),case when ISNULL(a.Code) = 0 then Null else ''電站編號為空'' end error_reason from power_station a - where a.`Code` = ', siteID ); + where a.`Code` = ', ''{code}01'' ); prepare stmt from @qry1 ; execute stmt ; #檢查電站缺少的欄位(裝置容量-不得為 0)# set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) - select ', siteID ,', ''station'', ''generatingCapacity_isnullorempty'', case when a.GeneratingCapacity > 0 and ISNULL(a.GeneratingCapacity) = 0 then 0 else 1 end isError, now(),case when a.GeneratingCapacity > 0 and ISNULL(a.GeneratingCapacity) = 0 then Null else ''裝置容量為 0 或 不存在'' end error_reason + select ', ''{code}01'' ,', ''station'', ''generatingCapacity_isnullorempty'', case when a.GeneratingCapacity > 0 and ISNULL(a.GeneratingCapacity) = 0 then 0 else 1 end isError, now(),case when a.GeneratingCapacity > 0 and ISNULL(a.GeneratingCapacity) = 0 then Null else ''裝置容量為 0 或 不存在'' end error_reason from power_station a - where a.`Code` = ', siteID ); + where a.`Code` = ', ''{code}01'' ); prepare stmt from @qry1 ; - execute stmt ; - - -- #檢查子資料庫是否存在電站# - -- set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) - -- select ', siteID ,', ''station'', ''subStation_isnull'', case when count(*) > 0 then 0 else 1 end isError, now(),case when count(*) > 0 then Null else ''子資料庫電站不存在'' end error_reason - -- from {DBname}.power_station a - -- where a.`Code` = ', siteID ); - -- prepare stmt from @qry1 ; - -- execute stmt ; + execute stmt ; + #檢查電站缺少的欄位(座標)# set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) - select ', siteID ,', ''station'', ''coordinate_isnull'', case when ISNULL(a.Coordinate) = 0 then 0 else 1 end isError, now(),case when ISNULL(a.Coordinate) = 0 then Null else ''電站座標為空'' end error_reason + select ', '{code}01' ,', ''station'', ''coordinate_isnull'', case when ISNULL(a.Coordinate) = 0 then 0 else 1 end isError, now(),case when ISNULL(a.Coordinate) = 0 then Null else ''電站座標為空'' end error_reason from power_station a - where a.`Code` = ', siteID ); + where a.`Code` = ', '{code}01' ); prepare stmt from @qry1 ; execute stmt ; #檢查電站歸屬公司狀態(刪除)# set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) - select ', siteID ,', ''company'', ''company_deleted'', + select ', ''{code}01'' ,', ''company'', ''company_deleted'', case when b.Deleted = 0 then 0 else 1 end isError, now(), case when b.Deleted = 0 then Null else ''公司已被刪除'' end error_reason from power_station a join company b on a.CompanyId = b.Id - where a.`Code` = ', siteID ); + where a.`Code` = ', ''{code}01'' ); prepare stmt from @qry1 ; execute stmt ; #檢查電站歸屬公司狀態(凍結)# set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) - select ', siteID ,', ''company'', ''company_status'', + select ', ''{code}01'' ,', ''company'', ''company_status'', case when b.Status = 1 then 0 else 1 end isError, now(), case when b.Status = 1 then Null else ''公司已被凍結'' end error_reason from power_station a join company b on a.CompanyId = b.Id - where a.`Code` = ', siteID ); + where a.`Code` = ', ''{code}01'' ); prepare stmt from @qry1 ; execute stmt ; #檢查電站歸屬公司狀態(存在)# set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) - select ', siteID ,', ''company'', ''company_isnull'', + select ', ''{code}01'' ,', ''company'', ''company_isnull'', case when count(*) > 0 then 0 else 1 end isError, now(), case when count(*) > 0 then Null else ''公司不存在'' end error_reason from power_station a join company b on a.CompanyId = b.Id - where a.`Code` = ', siteID ); + where a.`Code` = ', ''{code}01'' ); prepare stmt from @qry1 ; execute stmt ; #檢查電站有無運維人員# set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) - select ', siteID ,', ''station'', ''operation_personnel_count'', + select ', ''{code}01'' ,', ''station'', ''operation_personnel_count'', case when count(*) > 0 then 0 else 1 end isError, now(), case when count(*) > 0 then Null else ''電站無運維人員'' end error_reason from power_station_operation_personnel b join power_station a on a.Id = b.PowerStationId - where b.Deleted = 0 and a.`Code` = ', siteID ); + where b.Deleted = 0 and a.`Code` = ', ''{code}01'' ); prepare stmt from @qry1 ; execute stmt ; " + sql2 + $@" #檢查設備DBName是否填寫# set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) - select ', siteID ,', ''device'', ''device_DBName'', + select ', ''{code}01'' ,', ''device'', ''device_DBName'', case when count(*) > 0 then 1 else 0 end isError, now(), case when count(*) > 0 then ''有設備DBName欄位未填寫'' else Null end error_reason from {DBname}.device b join power_station a on a.Id = b.PowerStationId - where b.Deleted = 0 and b.Enabled = 1 and b.Status = 1 and b.DBName Is Null and a.`Code` = ', siteID ); + where b.Deleted = 0 and b.Enabled = 1 and b.Status = 1 and b.DBName Is Null and a.`Code` = ', ''{code}01'' ); prepare stmt from @qry1 ; execute stmt ; #檢查設備TableName是否填寫# set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) - select ', siteID ,', ''device'', ''device_TableName'', + select ', ''{code}01'' ,', ''device'', ''device_TableName'', case when count(*) > 0 then 1 else 0 end isError, now(), case when count(*) > 0 then ''有設備TableName欄位未填寫'' else Null end error_reason from {DBname}.device b join power_station a on a.Id = b.PowerStationId - where b.Deleted = 0 and b.Enabled = 1 and b.Status = 1 and b.TableName Is Null and a.`Code` = ', siteID ); + where b.Deleted = 0 and b.Enabled = 1 and b.Status = 1 and b.TableName Is Null and a.`Code` = ', ''{code}01'' ); prepare stmt from @qry1 ; execute stmt ; #檢查設備ColName是否填寫# set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) - select ', siteID ,', ''device'', ''device_ColName'', + select ', ''{code}01'' ,', ''device'', ''device_ColName'', case when count(*) > 0 then 1 else 0 end isError, now(), case when count(*) > 0 then ''有設備ColName欄位未填寫'' else Null end error_reason from {DBname}.device b join power_station a on a.Id = b.PowerStationId - where b.Deleted = 0 and b.Enabled = 1 and b.Status = 1 and b.ColName Is Null and a.`Code` = ', siteID ); + where b.Deleted = 0 and b.Enabled = 1 and b.Status = 1 and b.ColName Is Null and a.`Code` = ', ''{code}01'' ); prepare stmt from @qry1 ; execute stmt ; @@ -5769,33 +5762,33 @@ namespace SolarPower.Repository.Implement # 檢查是否有控制器# set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) - select ', siteID ,', ''controller'', ''controller_isnull'', + select ', ''{code}01'' ,', ''controller'', ''controller_isnull'', case when count(*) > 0 then 0 else 1 end isError, now(), case when count(*) > 0 then Null else ''電站無控制器'' end error_reason from {DBname}.power_station a join {DBname}.controller b on a.id = b.PowerStationId - where a.`Code` = ', siteID, ' and b.Deleted = 0' ); + where a.`Code` = ', ''{code}01'', ' and b.Deleted = 0' ); prepare stmt from @qry1; execute stmt; # 檢查是否有逆變器# set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) - select ', siteID ,', ''inverter'', ''inverter_isnull'', + select ', ''{code}01'' ,', ''inverter'', ''inverter_isnull'', case when count(*) > 0 then 0 else 1 end isError, now(), case when count(*) > 0 then Null else ''電站無逆變器'' end error_reason from {DBname}.power_station a join {DBname}.controller b on a.id = b.PowerStationId join {DBname}.inverter c on b.id = c.ControllerId - where a.`Code` = ', siteID, ' and c.Deleted = 0 and c.Enabled = 1 and c.Status = 1' ); + where a.`Code` = ', ''{code}01'', ' and c.Deleted = 0 and c.Enabled = 1 and c.Status = 1' ); prepare stmt from @qry1; execute stmt; # 回傳結果 set @qry1:= concat('select error_reason from power_station_enable_check - where siteID = ', siteID ,' and isError = 1'); + where siteID = ', ''{code}01'' ,' and isError = 1'); prepare stmt from @qry1 ; execute stmt; @@ -5814,6 +5807,236 @@ namespace SolarPower.Repository.Implement } } + public async Task> CheckStationStatus_v2(string code, string DBname, string powerStationID) + { + List result; + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + try + { + List devices = new List + { + new PowerstationOption{Text="日照計",Value="PYR"}, + new PowerstationOption{Text="模組溫度計",Value="MTR"}, + new PowerstationOption{Text="累計日照計",Value="TPY"} + }; + // devices.Add(new PowerstationOption { Text = "電表", Value = "PWR" }); + // clear check result + var sql = $@" delete from power_station_enable_check where `siteID` = '{code}' "; + await conn.ExecuteAsync(sql); + + var sql2 = ""; + foreach (var device in devices) + { + //sql2 += @$"#檢查是否存在設備({device.Text})# + // set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) + // select ', siteID ,', ''device'', ''device_Type_{device.Value}'', + // case when count(*) > 0 then 0 else 1 end isError, + // now(), + // case when count(*) > 0 then Null else ''電站無正常啟用{device.Text}'' end error_reason + // from {DBname}.device b + // join power_station a on a.Id = b.PowerStationId + // where b.Deleted = 0 and b.Enabled = 1 and b.Status = 1 and b.Type = ''{device.Value}'' and a.`Code` = ', siteID ); + // prepare stmt from @qry1 ; + // execute stmt ;"; + //#檢查是否存在設備({device.Text})# + sql2 += @$"insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) + select '{code}', 'device', 'device_Type_{device.Value}', + case when count(*) > 0 then 0 else 1 end isError, + now(), + case when count(*) > 0 then Null else '電站無正常啟用{device.Text}' end error_reason + from {DBname}.device b left join {DBname}.sharedevice c on b.id = c.DeviceId + where (b.PowerStationId = {powerStationID} or c.PowerStationId = {powerStationID}) + and b.Deleted = 0 and b.Enabled = 1 and b.Status = 1 and b.Type = '{device.Value}' ; "; + } + await conn.ExecuteAsync(sql2); + + List tables = new List + { + "inv", + "station", + "sensor", + "sensoravg", + }; + // tables.Add("meter"); + var sql3 = ""; + //檢查資料表_{table}是否存在# + foreach (var table in tables) + { + sql3 += @$" insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) + select '{code}', '{table}', '{table}_Table', + case when count(*) > 0 then 0 else 1 end isError, + now(), + case when count(*) > 0 then Null else '_{table}原始資料表不存在' end error_reason + from information_schema.SCHEMATA,information_schema.TABLES + where SCHEMA_NAME = '{DBname}' AND Table_schema = '{DBname}' AND TABLE_NAME = 's{code}01_{table}';"; + } + await conn.ExecuteAsync(sql3); + + + + //# 檢查電站缺少的欄位(住址)# + sql = $@"insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) + select '{code}' , 'station', 'address_isnull', case when ISNULL(a.Address) = 0 then 0 else 1 end isError, now() ,case when ISNULL(a.Address) = 0 then Null else '電站住址為空' end error_reason + from power_station a + where a.`Code` = '{code}' ;"; + + + // # 檢查電站缺少的欄位(名稱)# + sql += $@"insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) + select '{code}' , 'station', 'name_isnull', + case when ISNULL(a.Name) = 0 then 0 else 1 end isError, now(), + case when ISNULL(a.Name) = 0 then Null else '電站名稱為空' end error_reason + from power_station a + where a.`Code` = '{code}' ;"; + await conn.ExecuteAsync(sql); + + // # 檢查電站缺少的欄位(編號)# + sql = $@"insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) + select '{code}' , 'station', 'code_isnull', + case when ISNULL(a.Code) = 0 then 0 else 1 end isError, now(), + case when ISNULL(a.Code) = 0 then Null else '電站編號為空' end error_reason + from power_station a + where a.`Code` = '{code}' ;"; + + + // #檢查電站缺少的欄位(裝置容量-不得為 0)# + sql += $@"insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) + select '{code}' , 'station', 'generatingCapacity_isnullorempty', + case when a.GeneratingCapacity > 0 and ISNULL(a.GeneratingCapacity) = 0 then 0 else 1 end isError, now(), + case when a.GeneratingCapacity > 0 and ISNULL(a.GeneratingCapacity) = 0 then Null else '裝置容量為 0 或 不存在' end error_reason + from power_station a + where a.`Code` = '{code}' ;"; + + //# 檢查電站缺少的欄位(座標)# + sql += $@"insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) + select '{code}' , 'station', 'coordinate_isnull', + case when ISNULL(a.Coordinate) = 0 then 0 else 1 end isError, now(), + case when ISNULL(a.Coordinate) = 0 then Null else '電站座標為空' end error_reason + from power_station a + where a.`Code` = '{code}' ;"; + await conn.ExecuteAsync(sql); + + // #檢查電站歸屬公司狀態(刪除)# + sql = $@"insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) + select '{code}' , 'company', 'company_deleted', + case when b.Deleted = 0 then 0 else 1 end isError, + now(), + case when b.Deleted = 0 then Null else '公司已被刪除' end error_reason + from power_station a + join company b on a.CompanyId = b.Id + where a.`Code` = '{code}' ;"; + + + // #檢查電站歸屬公司狀態(凍結)# + sql += $@"insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) + select '{code}' , 'company', 'company_deleted', + case when b.Deleted = 0 then 0 else 1 end isError, + now(), + case when b.Deleted = 0 then Null else '公司已被刪除' end error_reason + from power_station a + join company b on a.CompanyId = b.Id + where a.`Code` = '{code}' ;"; + + + sql += $@"insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) + select '{code}' , 'company', 'company_status', + case when b.Status = 1 then 0 else 1 end isError, + now(), + case when b.Status = 1 then Null else '公司已被凍結' end error_reason + from power_station a + join company b on a.CompanyId = b.Id + where a.`Code` = '{code}' ;"; + await conn.ExecuteAsync(sql); + + // #檢查電站歸屬公司狀態(存在)# + sql = $@"insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) + select '{code}' , 'company', 'company_isnull', + case when count(*) > 0 then 0 else 1 end isError, + now(), + case when count(*) > 0 then Null else '公司不存在' end error_reason + from power_station a + join company b on a.CompanyId = b.Id + where a.`Code` = '{code}' ;"; + + // #檢查電站有無運維人員# + sql += $@"insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) + select '{code}' , 'station', 'operation_personnel_count', + case when count(*) > 0 then 0 else 1 end isError, + now(), + case when count(*) > 0 then Null else '電站無運維人員' end error_reason + from power_station_operation_personnel b + join power_station a on a.Id = b.PowerStationId + where b.Deleted = 0 and a.`Code` = '{code}' ;"; + await conn.ExecuteAsync(sql); + + // #檢查設備DBName是否填寫# + sql = $@" insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) + select '{code}' , 'device', 'device_DBName', + case when count(*) > 0 then 1 else 0 end isError, + now(), + case when count(*) > 0 then '有設備DBName欄位未填寫' else Null end error_reason + from {DBname}.device b + join power_station a on a.Id = b.PowerStationId + where b.Deleted = 0 and b.Enabled = 1 and b.Status = 1 and b.DBName Is Null and a.`Code` = '{code}' ;"; + + // #檢查設備TableName是否填寫# + sql += $@" insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) + select '{code}' , 'device', 'device_TableName', + case when count(*) > 0 then 1 else 0 end isError, + now(), + case when count(*) > 0 then '有設備TableName欄位未填寫' else Null end error_reason + from {DBname}.device b + join power_station a on a.Id = b.PowerStationId + where b.Deleted = 0 and b.Enabled = 1 and b.Status = 1 and b.TableName Is Null and a.`Code` = '{code}' "; + await conn.ExecuteAsync(sql); + + // #檢查設備ColName是否填寫# + sql = $@" insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) + select '{code}' , 'device', 'device_ColName', + case when count(*) > 0 then 1 else 0 end isError, + now(), + case when count(*) > 0 then '有設備ColName欄位未填寫' else Null end error_reason + from {DBname}.device b + join power_station a on a.Id = b.PowerStationId + where b.Deleted = 0 and b.Enabled = 1 and b.Status = 1 and b.ColName Is Null and a.`Code` = '{code}' ;"; + + // # 檢查是否有控制器# + sql += $@" insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) + select '{code}' , 'controller', 'controller_isnull', + case when count(*) > 0 then 0 else 1 end isError, + now(), + case when count(*) > 0 then Null else '電站無控制器' end error_reason + from {DBname}.power_station a + join {DBname}.controller b on a.id = b.PowerStationId + where a.`Code` = '{code}' and b.Deleted = 0 ;"; + + // # 檢查是否有逆變器# + sql += $@" insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason) + select '{code}' , 'inverter', 'inverter_isnull', + case when count(*) > 0 then 0 else 1 end isError, + now(), + case when count(*) > 0 then Null else '電站無逆變器' end error_reason + from {DBname}.power_station a + join {DBname}.controller b on a.id = b.PowerStationId + join {DBname}.inverter c on b.id = c.ControllerId + where a.`Code` = '{code}' and c.Deleted = 0 and c.Enabled = 1 and c.Status = 1 ;"; + await conn.ExecuteAsync(sql); + + // # 回傳結果 + sql = $@" select error_reason from power_station_enable_check + where siteID = '{code}' and isError = 1;"; + result = (await conn.QueryAsync(sql)).ToList(); + + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } + public async Task StationStatus(int stationId, int status, string subDB = "") { using (IDbConnection conn = this._databaseHelper.GetConnection()) diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index 80598d8..5ee5bc1 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -611,6 +611,14 @@ namespace SolarPower.Repository.Interface Task DropShareDevice(int powerstationId, string DBname); Task DeleteALLPowerStationOperationPersonnel(int stationId); Task> CheckStationStatus(string code, string DBname, string powerStationID); + /// + /// 電站啟用檢查 + /// + /// + /// + /// + /// + Task> CheckStationStatus_v2(string code, string DBname, string powerStationID); 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/Startup.cs b/SolarPower/Startup.cs index ff674bd..1dd5028 100644 --- a/SolarPower/Startup.cs +++ b/SolarPower/Startup.cs @@ -33,9 +33,11 @@ namespace SolarPower { public IConfiguration Configuration { get; } public DBConfig dBConfig = new DBConfig(); + private IWebHostEnvironment CurrentEnvironment { get; set; } - public Startup(IConfiguration configuration) + public Startup(IWebHostEnvironment env, IConfiguration configuration) { + CurrentEnvironment = env; Configuration = configuration; dBConfig.Server = Configuration.GetValue("DBConfig:Server"); @@ -49,7 +51,7 @@ namespace SolarPower public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); - + string envName = CurrentEnvironment.EnvironmentName; //oثe Development, Staging, Production services.AddLogging( builder => { @@ -88,59 +90,62 @@ namespace SolarPower options.IdleTimeout = TimeSpan.FromMinutes(loginExpireMinute); }); - //#region [JI + + #region [JI //services.AddHostedService(); + if (envName == "Production") + { + ////K[QuartzA + services.AddSingleton(); + services.AddSingleton(); + ////K[Job + //#region wpe + services.AddSingleton(); + services.AddSingleton( + new JobSchedule(jobType: typeof(OperationScheduleJob), cronExpression: Configuration.GetValue("BackgroundServiceCron:OperationScheduleJob")) + ); + //#endregion - ////K[QuartzA - services.AddSingleton(); - services.AddSingleton(); - ////K[Job - //#region wpe - services.AddSingleton(); - services.AddSingleton( - new JobSchedule(jobType: typeof(OperationScheduleJob), cronExpression: Configuration.GetValue("BackgroundServiceCron:OperationScheduleJob")) - ); - //#endregion + //#region pqfܾT(CI2}l15@Ӵ`) + services.AddSingleton(); + services.AddSingleton( + new JobSchedule(jobType: typeof(CalcInverter15minJob), cronExpression: Configuration.GetValue("BackgroundServiceCron:CalcInverter15minJob")) + ); + //#endregion - //#region pqfܾT(CI2}l15@Ӵ`) - services.AddSingleton(); - services.AddSingleton( - new JobSchedule(jobType: typeof(CalcInverter15minJob), cronExpression: Configuration.GetValue("BackgroundServiceCron:CalcInverter15minJob")) - ); - //#endregion + //#region pqoqqT(CI5) + services.AddSingleton(); + services.AddSingleton( + new JobSchedule(jobType: typeof(CalcPowerStationJob), cronExpression: Configuration.GetValue("BackgroundServiceCron:CalcPowerStationJob")) + //new JobSchedule(jobType: typeof(CalcPowerStationJob), cronExpression: "0/10 * * * * ?") + ); + //#endregion - //#region pqoqqT(CI5) - services.AddSingleton(); - services.AddSingleton( - new JobSchedule(jobType: typeof(CalcPowerStationJob), cronExpression: Configuration.GetValue("BackgroundServiceCron:CalcPowerStationJob")) - //new JobSchedule(jobType: typeof(CalcPowerStationJob), cronExpression: "0/10 * * * * ?") - ); - //#endregion + //#region pqӶqBPRBkWP 30饭B(Cѭ2I) + services.AddSingleton(); + services.AddSingleton( + new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: Configuration.GetValue("BackgroundServiceCron:CalcAvgPowerStationJob")) + //new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: "0 03 7 ? * * *") + ); + //#endregion - //#region pqӶqBPRBkWP 30饭B(Cѭ2I) - services.AddSingleton(); - services.AddSingleton( - new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: Configuration.GetValue("BackgroundServiceCron:CalcAvgPowerStationJob")) - //new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: "0 03 7 ? * * *") - ); - //#endregion + //#region HeEmail(Cѭ2I) + services.AddSingleton(); + services.AddSingleton( + new JobSchedule(jobType: typeof(SendEmailJob), cronExpression: Configuration.GetValue("BackgroundServiceCron:SendEmailJob")) + ); + //#endregion - //#region HeEmail(Cѭ2I) - services.AddSingleton(); - services.AddSingleton( - new JobSchedule(jobType: typeof(SendEmailJob), cronExpression: Configuration.GetValue("BackgroundServiceCron:SendEmailJob")) - ); - //#endregion + //#region d߲`sWEmail + services.AddSingleton(); + services.AddSingleton( + new JobSchedule(jobType: typeof(ExceptionSchedule), cronExpression: Configuration.GetValue("BackgroundServiceCron:ExceptionSchedule")) + ); + //#endregion - //#region d߲`sWEmail - services.AddSingleton(); - services.AddSingleton( - new JobSchedule(jobType: typeof(ExceptionSchedule), cronExpression: Configuration.GetValue("BackgroundServiceCron:ExceptionSchedule")) - ); - //#endregion - - services.AddHostedService(); - //#endregion + services.AddHostedService(); + } + #endregion services.AddApplicationInsightsTelemetry(); }