1.自動判斷是否為正式環境,才允許啟動背景服務
2.電站啟用 debug
This commit is contained in:
parent
a30f54e1b0
commit
3a57ed7769
@ -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";
|
||||
|
||||
@ -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 ;
|
||||
|
||||
#檢查電站缺少的欄位(座標)#
|
||||
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<List<string>> CheckStationStatus_v2(string code, string DBname, string powerStationID)
|
||||
{
|
||||
List<string> result;
|
||||
using (IDbConnection conn = this._databaseHelper.GetConnection())
|
||||
{
|
||||
try
|
||||
{
|
||||
List<PowerstationOption> devices = new List<PowerstationOption>
|
||||
{
|
||||
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<string> tables = new List<string>
|
||||
{
|
||||
"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<string>(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())
|
||||
|
||||
@ -611,6 +611,14 @@ namespace SolarPower.Repository.Interface
|
||||
Task DropShareDevice(int powerstationId, string DBname);
|
||||
Task DeleteALLPowerStationOperationPersonnel(int stationId);
|
||||
Task<List<string>> CheckStationStatus(string code, string DBname, string powerStationID);
|
||||
/// <summary>
|
||||
/// 電站啟用檢查
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="DBname"></param>
|
||||
/// <param name="powerStationID"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<string>> CheckStationStatus_v2(string code, string DBname, string powerStationID);
|
||||
Task StationStatus(int stationId, int status, string subDB = "");
|
||||
Task UpdateInvStatus(string siteDB, List<string> codes, List<string> inverterIds = null, byte status = 0);
|
||||
Task<List<InvStatusErr>> GetInvStatusErr(List<string> codes);
|
||||
|
||||
@ -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<string>("DBConfig:Server");
|
||||
@ -49,7 +51,7 @@ namespace SolarPower
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddControllersWithViews();
|
||||
|
||||
string envName = CurrentEnvironment.EnvironmentName; //取得目前環境 Development, Staging, Production
|
||||
services.AddLogging(
|
||||
builder =>
|
||||
{
|
||||
@ -88,59 +90,62 @@ namespace SolarPower
|
||||
options.IdleTimeout = TimeSpan.FromMinutes(loginExpireMinute);
|
||||
});
|
||||
|
||||
//#region 加入背景執行
|
||||
|
||||
#region 加入背景執行
|
||||
//services.AddHostedService<OperationScheduleBackgroundService>();
|
||||
if (envName == "Production")
|
||||
{
|
||||
////添加Quartz服務
|
||||
services.AddSingleton<IJobFactory, SingletonJobFactory>();
|
||||
services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>();
|
||||
////添加Job
|
||||
//#region 定期計畫
|
||||
services.AddSingleton<OperationScheduleJob>();
|
||||
services.AddSingleton(
|
||||
new JobSchedule(jobType: typeof(OperationScheduleJob), cronExpression: Configuration.GetValue<string>("BackgroundServiceCron:OperationScheduleJob"))
|
||||
);
|
||||
//#endregion
|
||||
|
||||
////添加Quartz服務
|
||||
services.AddSingleton<IJobFactory, SingletonJobFactory>();
|
||||
services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>();
|
||||
////添加Job
|
||||
//#region 定期計畫
|
||||
services.AddSingleton<OperationScheduleJob>();
|
||||
services.AddSingleton(
|
||||
new JobSchedule(jobType: typeof(OperationScheduleJob), cronExpression: Configuration.GetValue<string>("BackgroundServiceCron:OperationScheduleJob"))
|
||||
);
|
||||
//#endregion
|
||||
//#region 計算電站逆變器資訊(每整點2分開始執行15分鐘一個循環)
|
||||
services.AddSingleton<CalcInverter15minJob>();
|
||||
services.AddSingleton(
|
||||
new JobSchedule(jobType: typeof(CalcInverter15minJob), cronExpression: Configuration.GetValue<string>("BackgroundServiceCron:CalcInverter15minJob"))
|
||||
);
|
||||
//#endregion
|
||||
|
||||
//#region 計算電站逆變器資訊(每整點2分開始執行15分鐘一個循環)
|
||||
services.AddSingleton<CalcInverter15minJob>();
|
||||
services.AddSingleton(
|
||||
new JobSchedule(jobType: typeof(CalcInverter15minJob), cronExpression: Configuration.GetValue<string>("BackgroundServiceCron:CalcInverter15minJob"))
|
||||
);
|
||||
//#endregion
|
||||
//#region 計算電站發電量等資訊(每整點5分執行)
|
||||
services.AddSingleton<CalcPowerStationJob>();
|
||||
services.AddSingleton(
|
||||
new JobSchedule(jobType: typeof(CalcPowerStationJob), cronExpression: Configuration.GetValue<string>("BackgroundServiceCron:CalcPowerStationJob"))
|
||||
//new JobSchedule(jobType: typeof(CalcPowerStationJob), cronExpression: "0/10 * * * * ?")
|
||||
);
|
||||
//#endregion
|
||||
|
||||
//#region 計算電站發電量等資訊(每整點5分執行)
|
||||
services.AddSingleton<CalcPowerStationJob>();
|
||||
services.AddSingleton(
|
||||
new JobSchedule(jobType: typeof(CalcPowerStationJob), cronExpression: Configuration.GetValue<string>("BackgroundServiceCron:CalcPowerStationJob"))
|
||||
//new JobSchedule(jobType: typeof(CalcPowerStationJob), cronExpression: "0/10 * * * * ?")
|
||||
);
|
||||
//#endregion
|
||||
//#region 計算電站日照量、PR、kWP 30日平均、(每天凌晨2點執行)
|
||||
services.AddSingleton<CalcAvgPowerStationJob>();
|
||||
services.AddSingleton(
|
||||
new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: Configuration.GetValue<string>("BackgroundServiceCron:CalcAvgPowerStationJob"))
|
||||
//new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: "0 03 7 ? * * *")
|
||||
);
|
||||
//#endregion
|
||||
|
||||
//#region 計算電站日照量、PR、kWP 30日平均、(每天凌晨2點執行)
|
||||
services.AddSingleton<CalcAvgPowerStationJob>();
|
||||
services.AddSingleton(
|
||||
new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: Configuration.GetValue<string>("BackgroundServiceCron:CalcAvgPowerStationJob"))
|
||||
//new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: "0 03 7 ? * * *")
|
||||
);
|
||||
//#endregion
|
||||
//#region 寄送Email(每天凌晨2點執行)
|
||||
services.AddSingleton<SendEmailJob>();
|
||||
services.AddSingleton(
|
||||
new JobSchedule(jobType: typeof(SendEmailJob), cronExpression: Configuration.GetValue<string>("BackgroundServiceCron:SendEmailJob"))
|
||||
);
|
||||
//#endregion
|
||||
|
||||
//#region 寄送Email(每天凌晨2點執行)
|
||||
services.AddSingleton<SendEmailJob>();
|
||||
services.AddSingleton(
|
||||
new JobSchedule(jobType: typeof(SendEmailJob), cronExpression: Configuration.GetValue<string>("BackgroundServiceCron:SendEmailJob"))
|
||||
);
|
||||
//#endregion
|
||||
//#region 查詢異常新增至Email
|
||||
services.AddSingleton<ExceptionSchedule>();
|
||||
services.AddSingleton(
|
||||
new JobSchedule(jobType: typeof(ExceptionSchedule), cronExpression: Configuration.GetValue<string>("BackgroundServiceCron:ExceptionSchedule"))
|
||||
);
|
||||
//#endregion
|
||||
|
||||
//#region 查詢異常新增至Email
|
||||
services.AddSingleton<ExceptionSchedule>();
|
||||
services.AddSingleton(
|
||||
new JobSchedule(jobType: typeof(ExceptionSchedule), cronExpression: Configuration.GetValue<string>("BackgroundServiceCron:ExceptionSchedule"))
|
||||
);
|
||||
//#endregion
|
||||
|
||||
services.AddHostedService<QuartzHostedService>();
|
||||
//#endregion
|
||||
services.AddHostedService<QuartzHostedService>();
|
||||
}
|
||||
#endregion
|
||||
|
||||
services.AddApplicationInsightsTelemetry();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user