From 5c58b583d7db7045eacc959f4c2c0f44ca61ccc2 Mon Sep 17 00:00:00 2001 From: cesar liu Date: Mon, 6 Jun 2022 23:43:38 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=95=9F=E7=94=A8=E9=9B=BB=E7=AB=99=20-=20?= =?UTF-8?q?=E8=A8=AD=E5=82=99=E6=AA=A2=E6=9F=A5=20-=20=E5=90=AB=E5=85=B1?= =?UTF-8?q?=E7=94=A8=E8=A8=AD=E5=82=99=202.=E5=95=9F=E7=94=A8=E9=9B=BB?= =?UTF-8?q?=E7=AB=99=20-=20=E8=A8=AD=E5=82=99=E6=AA=A2=E6=9F=A5=20-=20?= =?UTF-8?q?=E5=90=AB=E7=B4=AF=E8=A8=88=E6=97=A5=E7=85=A7=E8=A8=88=E6=AA=A2?= =?UTF-8?q?=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/.config/dotnet-tools.json | 9 +++++++- .../Controllers/PowerStationController.cs | 2 +- .../Implement/PowerStationRepository.cs | 21 +++++++++++++++---- .../Interface/IPowerStationRepository.cs | 2 +- solarApp/Service/procSensorSvc.cs | 9 +++++--- 5 files changed, 33 insertions(+), 10 deletions(-) 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(); //欄位處理