From a56620286a84be8591269a15f5f17c608e3321b3 Mon Sep 17 00:00:00 2001 From: "wanling040@gmail.com" Date: Mon, 15 Aug 2022 14:23:58 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9B=BB=E7=AB=99=E7=AE=A1=E7=90=86-=E8=A3=9D?= =?UTF-8?q?=E7=BD=AE=E8=A8=AD=E5=AE=9A:=20=E5=8A=A0=E4=B8=8AsensorTypeId?= =?UTF-8?q?=E5=92=8CsensorTypeDetailId=E7=9A=84=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Controllers/PowerStationController.cs | 8 ++++++-- SolarPower/Models/PowerStation.cs | 2 ++ .../Repository/Implement/PowerStationRepository.cs | 9 +++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index c857286..cd3e674 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -1177,7 +1177,9 @@ namespace SolarPower.Controllers "Status", "Enabled", "InstallDate", - "BrandNum" + "BrandNum", + "SensorTypeId", + "SensorTypeDetailId" }; if (Device.WarrantyDate != "0001-01-01") { @@ -1246,7 +1248,9 @@ namespace SolarPower.Controllers "Status", "Enabled", "InstallDate", - "BrandNum" + "BrandNum", + "SensorTypeId", + "SensorTypeDetailId" }; if (Device.WarrantyDate != "0001-01-01") { diff --git a/SolarPower/Models/PowerStation.cs b/SolarPower/Models/PowerStation.cs index 13e84ab..08bf78f 100644 --- a/SolarPower/Models/PowerStation.cs +++ b/SolarPower/Models/PowerStation.cs @@ -442,6 +442,8 @@ namespace SolarPower.Models.PowerStation public string InstallDate { get { return Convert.ToDateTime(installDate).ToString("yyyy-MM-dd"); } set { installDate = value; } } //安裝日期 public string BrandNum { get; set; }//廠商序號 public string WarrantyDate { get { return Convert.ToDateTime(warrantyDate).ToString("yyyy-MM-dd"); } set { warrantyDate = value; } } //保固日期 + public int SensorTypeId { get; set; } + public int SensorTypeDetailId { get; set; } } public class Device : DeviceInfo diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index e9a5697..5d1a34b 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -1018,6 +1018,10 @@ namespace SolarPower.Repository.Implement var trans = conn.BeginTransaction(); try { + string getSensorTypeId = $@"SELECT id from sensor_type + WHERE SensorEName = '{DeviceInfo.Type}' AND Deleted = 0"; + DeviceInfo.SensorTypeId = await conn.QueryFirstOrDefaultAsync(getSensorTypeId); + DeviceInfo.SensorTypeDetailId = DeviceInfo.SensorTypeId; string sql = GenerateInsertQueryWithCustomDBNameAndTable(properties, db_name, "device"); await conn.ExecuteAsync(sql, DeviceInfo); @@ -1050,6 +1054,11 @@ namespace SolarPower.Repository.Implement var trans = conn.BeginTransaction(); try { + string getSensorTypeId = $@"SELECT id from sensor_type + WHERE SensorEName = '{DeviceInfo.Type}' AND Deleted = 0"; + DeviceInfo.SensorTypeId = await conn.QueryFirstOrDefaultAsync(getSensorTypeId); + DeviceInfo.SensorTypeDetailId = DeviceInfo.SensorTypeId; + var updateQuery = GenerateUpdateQueryWithCustomDBNameAndTable(properties, db_name, "device"); await conn.ExecuteAsync(updateQuery.ToString(), DeviceInfo, trans); trans.Commit();