diff --git a/SolarPower/.config/dotnet-tools.json b/SolarPower/.config/dotnet-tools.json index b0e38ab..e80b80f 100644 --- a/SolarPower/.config/dotnet-tools.json +++ b/SolarPower/.config/dotnet-tools.json @@ -1,5 +1,12 @@ { "version": 1, "isRoot": true, - "tools": {} + "tools": { + "dotnet-ef": { + "version": "6.0.5", + "commands": [ + "dotnet-ef" + ] + } + } } \ No newline at end of file diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index 06597d9..6a7d616 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); + status = await powerStationRepository.CheckStationStatus(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 29da331..16c6d03 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -5552,7 +5552,7 @@ namespace SolarPower.Repository.Implement } } - public async Task> CheckStationStatus(string code, string DBname) + public async Task> CheckStationStatus(string code, string DBname, string powerStationID) { List result; using (IDbConnection conn = this._databaseHelper.GetConnection()) @@ -5562,12 +5562,24 @@ namespace SolarPower.Repository.Implement List devices = new List { 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 ;"; } diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index 0d97a40..80598d8 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -610,7 +610,7 @@ namespace SolarPower.Repository.Interface Task> GetShareDevicePowerstationName(int Id, string DBname); Task DropShareDevice(int powerstationId, string DBname); Task DeleteALLPowerStationOperationPersonnel(int stationId); - Task> CheckStationStatus(string code, string DBname); + Task> CheckStationStatus(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/solarApp/Service/procSensorSvc.cs b/solarApp/Service/procSensorSvc.cs index f0303ff..4116dd1 100644 --- a/solarApp/Service/procSensorSvc.cs +++ b/solarApp/Service/procSensorSvc.cs @@ -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 ds_sensor = conn.Query(sql, new { siteID = _siteID01 }).AsList(); //欄位處理