1.啟用電站 - 設備檢查 - 含共用設備

2.啟用電站 - 設備檢查 - 含累計日照計檢查
This commit is contained in:
cesar liu 2022-06-06 23:43:38 +08:00
parent 0bd4791496
commit 5c58b583d7
5 changed files with 33 additions and 10 deletions

View File

@ -1,5 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {}
"tools": {
"dotnet-ef": {
"version": "6.0.5",
"commands": [
"dotnet-ef"
]
}
}
}

View File

@ -3254,7 +3254,7 @@ namespace SolarPower.Controllers
try
{
var powerStation = await powerStationRepository.GetOneAsync(Id);
status = await powerStationRepository.CheckStationStatus(powerStation.Code, powerStation.SiteDB);
status = await powerStationRepository.CheckStationStatus(powerStation.Code, powerStation.SiteDB, powerStation.Id.ToString());
if(status.Count > 0)
{
apiResult.Code = "0099";

View File

@ -5552,7 +5552,7 @@ namespace SolarPower.Repository.Implement
}
}
public async Task<List<string>> CheckStationStatus(string code, string DBname)
public async Task<List<string>> CheckStationStatus(string code, string DBname, string powerStationID)
{
List<string> result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
@ -5562,12 +5562,24 @@ namespace SolarPower.Repository.Implement
List<PowerstationOption> devices = new List<PowerstationOption>
{
new PowerstationOption{Text="日照計",Value="PYR"},
new PowerstationOption{Text="模組溫度計",Value="MTR"}
new PowerstationOption{Text="模組溫度計",Value="MTR"},
new PowerstationOption{Text="累計日照計",Value="TPY"}
};
// devices.Add(new PowerstationOption { Text = "電表", Value = "PWR" });
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 ;";
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}'',
@ -5575,8 +5587,9 @@ namespace SolarPower.Repository.Implement
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 );
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}'' );
prepare stmt from @qry1 ;
execute stmt ;";
}

View File

@ -610,7 +610,7 @@ namespace SolarPower.Repository.Interface
Task<List<string>> GetShareDevicePowerstationName(int Id, string DBname);
Task DropShareDevice(int powerstationId, string DBname);
Task DeleteALLPowerStationOperationPersonnel(int stationId);
Task<List<string>> CheckStationStatus(string code, string DBname);
Task<List<string>> CheckStationStatus(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);

View File

@ -175,9 +175,12 @@ namespace solarApp.Service
#region Sensor
//沒有被刪除、啟用中、狀態正常的 才可列入計算
sql = @"select a.id, CONCAT( left(UID, 9) ,'01') SiteID, a.`name` sensorName, type, DBName, TableName, colname
from " + _siteDB + @".device a
where left(UID, 11) = @siteID and deleted = 0 and enabled = 1 and `status` = 1 ";
//sql = @"select a.id, CONCAT( left(UID, 9) ,'01') SiteID, a.`name` sensorName, type, DBName, TableName, colname
// from " + _siteDB + @".device a
// where left(UID, 11) = @siteID and deleted = 0 and enabled = 1 and `status` = 1 ";
sql = @$"select a.id, CONCAT( {_siteID} ,'01') SiteID, a.`name` sensorName, type, DBName, TableName, colname
from {_siteDB}.device a join {_siteDB}.sharedevice b on a.id = b.deviceID
where (left(UID, 11) = @siteID or b.PowerStationID = {_powerStationID}) and deleted = 0 and enabled = 1 and `status` = 1 ";
List<sensor_model> ds_sensor = conn.Query<sensor_model>(sql, new { siteID = _siteID01 }).AsList<sensor_model>();
//欄位處理