From 162338d3e98ed4c67a9d9d1e3b59bfd93d4a7008 Mon Sep 17 00:00:00 2001 From: "wanling040@gmail.com" Date: Thu, 21 Jul 2022 18:29:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=A3=9D=E7=BD=AE=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E3=80=81=E6=96=B0=E5=A2=9E=E8=A3=9D=E7=BD=AE=E5=AD=90?= =?UTF-8?q?=E9=A0=85=E7=9B=AE=E6=96=B0=E5=A2=9E=E6=9F=A5=E8=A9=A2=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=20=E8=A3=9D=E7=BD=AE=E8=A8=AD=E5=AE=9A:=20=E8=A3=9D?= =?UTF-8?q?=E7=BD=AE=E9=A1=9E=E5=9E=8B=E9=81=B8=E6=93=87=E6=94=B9=E7=82=BA?= =?UTF-8?q?=E8=AE=80=E5=8F=96sensorType=E8=B3=87=E6=96=99=E8=A1=A8=20?= =?UTF-8?q?=E9=9B=BB=E7=AB=99=E4=BA=A4=E5=8F=89=E5=88=86=E6=9E=90:=20?= =?UTF-8?q?=E9=81=B8=E6=93=87=E6=AF=94=E8=BC=83=E6=AC=84=E4=BD=8D(?= =?UTF-8?q?=E4=BB=A5sensorTypeDetail=E5=81=9A=E6=9B=B4=E6=96=B0)=20PowerSt?= =?UTF-8?q?ationRepository.cs=20->=20=E5=88=AA=E9=99=A4=E5=B7=B2=E4=B8=8D?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84=E8=B3=87=E6=96=99=E8=A1=A8=E5=88=A4?= =?UTF-8?q?=E6=96=B7=20debug=20->=20=E9=9B=BB=E7=AB=99=E4=BA=A4=E5=8F=89?= =?UTF-8?q?=E5=88=86=E6=9E=90=E4=B8=AD=20=E8=A8=AD=E5=82=99=E6=9C=89?= =?UTF-8?q?=E5=85=A9=E5=80=8B=E5=B0=8E=E8=87=B4=E6=9F=A5=E8=A9=A2=E4=B8=8D?= =?UTF-8?q?=E4=BA=86=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=9F=A5=E8=A9=A2=E5=88=A4?= =?UTF-8?q?=E6=96=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AnalysisStationInfoController.cs | 134 +++- .../Controllers/SensorTypeController.cs | 408 +++++++++++- SolarPower/Models/AnalysisStationInfo.cs | 2 + SolarPower/Models/SensorDetail.cs | 31 + SolarPower/Models/SensorType.cs | 30 +- .../Implement/PowerStationRepository.cs | 34 +- .../Implement/SensorDetailRepository.cs | 105 ++++ .../Implement/SensorTypeRepository.cs | 55 +- .../Interface/ISensorDetailRepository.cs | 36 ++ .../Interface/ISensorTypeRepository.cs | 12 +- SolarPower/Startup.cs | 1 + .../Views/AnalysisStationInfo/Index.cshtml | 106 +++- SolarPower/Views/SensorType/Index.cshtml | 593 ++++++++++++++---- SolarPower/Views/Shared/_Layout.cshtml | 4 +- 14 files changed, 1317 insertions(+), 234 deletions(-) create mode 100644 SolarPower/Models/SensorDetail.cs create mode 100644 SolarPower/Repository/Implement/SensorDetailRepository.cs create mode 100644 SolarPower/Repository/Interface/ISensorDetailRepository.cs diff --git a/SolarPower/Controllers/AnalysisStationInfoController.cs b/SolarPower/Controllers/AnalysisStationInfoController.cs index 34ef549..8e18bde 100644 --- a/SolarPower/Controllers/AnalysisStationInfoController.cs +++ b/SolarPower/Controllers/AnalysisStationInfoController.cs @@ -3,6 +3,8 @@ using Microsoft.Extensions.Logging; using SolarPower.Models; using SolarPower.Models.PowerStation; using SolarPower.Models.Role; +using SolarPower.Models.SensorType; +using SolarPower.Models.SensorDetail; using SolarPower.Repository.Interface; using System; using System.Collections.Generic; @@ -14,10 +16,14 @@ namespace SolarPower.Controllers public class AnalysisStationInfoController : MyBaseController { private readonly IPowerStationRepository powerStationRepository; + private readonly ISensorTypeRepository sensorTypeRepository; + private readonly ISensorDetailRepository sensorDetailRepository; - public AnalysisStationInfoController(IPowerStationRepository powerStationRepository) : base() + public AnalysisStationInfoController(IPowerStationRepository powerStationRepository, ISensorTypeRepository sensorTypeRepository, ISensorDetailRepository sensorDetailRepository) : base() { this.powerStationRepository = powerStationRepository; + this.sensorTypeRepository = sensorTypeRepository; + this.sensorDetailRepository = sensorDetailRepository; } public IActionResult Index() @@ -67,7 +73,9 @@ namespace SolarPower.Controllers PowerStationId = psName_Group.First().PowerStationId, DeviceName = "電站總覽", DeviceType = "PWS", - DeviceId = psName_Group.First().PowerStationId.ToString() + DeviceId = psName_Group.First().PowerStationId.ToString(), + SensorTypeId = psName_Group.First().SensorTypeId, + SensorTypeDetailId = psName_Group.First().SensorTypeDetailId }; var temp = new List(); @@ -153,7 +161,7 @@ namespace SolarPower.Controllers { "KWH", "發電量"}, { "IrrDay", "累計日照度"}, { "Irradiance", "日照度"}, - { "KWHKWP", "發電小時"}, + { "KWHKWP", "日均發電度數"}, { "PR", "PR %"}, { "SolarHour", "日照小時"}, { "Temperature", "模組溫度"}, @@ -552,7 +560,7 @@ namespace SolarPower.Controllers var YaxesKey = ""; switch (device.Type) { - case "TPY": //日照計 + case "TPY": //累積日照計 suffix = analysisDevice.MultipleYaxes["IrrDay"]; YaxesKey = "IrrDay"; break; @@ -572,7 +580,7 @@ namespace SolarPower.Controllers suffix = analysisDevice.MultipleYaxes["Vane"]; YaxesKey = "Vane"; break; - case "FOM": //落塵計 + case "DST": //落塵計 FOM suffix = analysisDevice.MultipleYaxes["Dust"]; YaxesKey = "Dust"; break; @@ -618,5 +626,121 @@ namespace SolarPower.Controllers apiResult.Msg = errorCode.GetString(apiResult.Code); return apiResult; } + + /// + /// 取得 裝置項目 + /// + /// + /// + [HttpPost] + public async Task> GetOneSensorDetail(int id) + { + ApiResult apiResult = new ApiResult(); + + SensorDetail sensorDetails = null; + + try + { + sensorDetails = await sensorDetailRepository.GetOneSensorDetailAsync(id); + + if (sensorDetails == null) + { + apiResult.Code = "9988"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + apiResult.Code = "0000"; + apiResult.Data = sensorDetails; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + } + + //[HttpPost] + //public async Task>> GetSensorCollapse(string filter) + //{ + // //ApiResult>>> apiResult = new ApiResult>>>(); + // ApiResult> apiResult = new ApiResult>(); + // try + // { + // var powerStations = new List(); + + // powerStations = myPowerStationService.GetMyPowerStations(myUser); + + // var siteDBNamePowerStationId = new Dictionary>(); + + // var powerStation_siteDB_Group = powerStations.GroupBy(x => x.SiteDB).ToList(); + // foreach (var siteDB_Group in powerStation_siteDB_Group) + // { + // var powerStationIds = siteDB_Group.Select(x => x.Id).ToList(); + // siteDBNamePowerStationId.Add(siteDB_Group.Key, powerStationIds); + // } + + // var powerStationDevices = await powerStationRepository.GetPowerStationDevice(siteDBNamePowerStationId, filter); + + // //powerStationDevices = powerStationDevices.Where(x => x.DeviceId != null).ToList(); + + // var powerStationDevice_cityName_Group = powerStationDevices.GroupBy(x => x.CityName).ToList(); + + // var deviceCollapse = new Dictionary>>(); + // foreach (var cityName_Group in powerStationDevice_cityName_Group) + // { + // var device_psName_Group = cityName_Group.GroupBy(x => x.PowerStationName).ToList(); + + // var deviceDic = new Dictionary>(); + + // foreach (var psName_Group in device_psName_Group) + // { + // //電站總覽 + // PowerStationDevice powerStation = new PowerStationDevice() + // { + // CityName = cityName_Group.Key, + // PowerStationName = psName_Group.Key, + // PowerStationId = psName_Group.First().PowerStationId, + // DeviceName = "電站總覽", + // DeviceType = "PWS", + // DeviceId = psName_Group.First().PowerStationId.ToString(), + // SensorTypeId = psName_Group.First().SensorTypeId, + // SensorTypeDetailId = psName_Group.First().SensorTypeDetailId + // }; + + // var temp = new List(); + // temp.Add(powerStation); + // foreach (var device in psName_Group) + // { + // if (!string.IsNullOrEmpty(device.DeviceId)) + // { + // temp.Add(device); + // } + // } + // deviceDic.Add(psName_Group.Key, temp); + // } + + // deviceCollapse.Add(cityName_Group.Key, deviceDic); + // } + + // apiResult.Code = "0000"; + + // apiResult.Data = deviceCollapse; + // } + // catch (Exception exception) + // { + // apiResult.Code = "9999"; + // Logger.LogError("【" + controllerName + "/" + actionName + "】"); + // Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + // } + + // apiResult.Msg = errorCode.GetString(apiResult.Code); + // return apiResult; + //} + } } diff --git a/SolarPower/Controllers/SensorTypeController.cs b/SolarPower/Controllers/SensorTypeController.cs index fb7d95e..860b3b2 100644 --- a/SolarPower/Controllers/SensorTypeController.cs +++ b/SolarPower/Controllers/SensorTypeController.cs @@ -9,26 +9,26 @@ using SolarPower.Services.Interface; using System.IO; using SolarPower.Models; using SolarPower.Models.SensorType; +using SolarPower.Models.SensorDetail; namespace SolarPower.Controllers { public class SensorTypeController : MyBaseController { - private readonly ISensorTypeRepository sensorRepository; - private string boeFilePath = "/upload/power_station/boe_file/"; - private string stationImageFilePath = "/upload/power_station/"; - private string powerSationSaveAsPath = ""; + private readonly ISensorTypeRepository sensorTypeRepository; + private readonly ISensorDetailRepository sensorDetailRepository; + private string sensorTypeSaveAsPath = ""; - public SensorTypeController(ISensorTypeRepository sensorRepository) : base() + public SensorTypeController(ISensorTypeRepository sensorTypeRepository, ISensorDetailRepository sensorDetailRepository) : base() { - this.sensorRepository = sensorRepository; + this.sensorTypeRepository = sensorTypeRepository; + this.sensorDetailRepository = sensorDetailRepository; - powerSationSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "power_station"); + sensorTypeSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "sensor_type"); } public IActionResult Index() { - sensorRepository.GetAllSensorAsync(); return View(); } @@ -39,15 +39,16 @@ namespace SolarPower.Controllers /// /// [HttpPost] - public async Task> SaveSensorType(SensorTypeInfo post) + public async Task> SaveSensorType(SensorType post) { ApiResult apiResult = new ApiResult(); SensorType sensor = null; + string nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); try { - sensor = await sensorRepository.GetOneAsync(post.Id); + sensor = await sensorTypeRepository.GetOneAsync(post.Id); if (sensor == null) { @@ -62,23 +63,25 @@ namespace SolarPower.Controllers #region 新增設備 sensor = new SensorType() { - UId = post.UId, + Deleted = 0, Enabled = post.Enabled, SensorName = post.SensorName, - SensorNameEn = post.SensorNameEn, + SensorEName = post.SensorEName, CreatedBy = myUser.Id, + CreatedAt = nowTime, }; List properties = new List() { - "UId", + "Deleted", "Enabled", "SensorName", - "SensorNameEn", + "SensorEName", "CreatedBy", + "CreatedAt" }; - var id = await sensorRepository.AddOneAsync(sensor, properties); + var id = await sensorTypeRepository.AddOneAsync(sensor, properties); //var website_url = await powerStationRepository.GetOneVariableByName("WebSiteUrl"); @@ -97,8 +100,9 @@ namespace SolarPower.Controllers Id = sensor.Id, Enabled = post.Enabled, SensorName = post.SensorName, - SensorNameEn = post.SensorNameEn, - UpdatedBy = myUser.Id + SensorEName = post.SensorEName, + UpdatedBy = myUser.Id, + UpdatedAt = nowTime, }; @@ -107,11 +111,13 @@ namespace SolarPower.Controllers "Id", "Enabled", "SensorName", - "SensorNameEn", + "SensorEName", "UpdatedBy", + "UpdatedAt" }; + - await sensorRepository.UpdateSensorInfo(update, properties); + await sensorTypeRepository.UpdateSensorInfo(update, properties); apiResult.Code = "0000"; apiResult.Msg = "儲存成功"; #endregion @@ -128,5 +134,369 @@ namespace SolarPower.Controllers return apiResult; } + /// + /// 控制器DataTable + /// + /// + /// + public async Task SensorTypeDeviceTable() + { + ApiResult> apiResult = new ApiResult>(); + List sensorTypes = null; + + try + { + sensorTypes = await sensorTypeRepository.GetAllSensorAsync(); + foreach (SensorType a in sensorTypes) + { + switch (a.Enabled) + { + case 0: + a.EnabledName = "未啟用"; + break; + case 1: + a.EnabledName = "啟用"; + break; + default: + a.EnabledName = "無資料"; + break; + } + } + apiResult.Code = "0000"; + apiResult.Data = sensorTypes; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + apiResult.Msg = errorCode.GetString(apiResult.Code); + var result = Json(new + { + data = apiResult + }); + + return result; + } + + /// + /// 軟刪除單一裝置類型 + /// + /// + /// + [HttpPost] + public async Task> DeleteOneSensorType(int id) + { + ApiResult apiResult = new ApiResult(); + + SensorType sensor = null; + + try + { + sensor = await sensorTypeRepository.GetOneSensorType(id); + + if (sensor == null) + { + apiResult.Code = "9998"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + await sensorTypeRepository.DeleteOne(sensor.Id); + + apiResult.Code = "0000"; + apiResult.Msg = "刪除成功"; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + } + + /// + /// 取得單一裝置類型 + /// + /// + /// + [HttpPost] + public async Task> GetOneSensorType(int id) + { + ApiResult apiResult = new ApiResult(); + + SensorType simpleSensorType = null; + + try + { + simpleSensorType = await sensorTypeRepository.GetOneSensorType(id); + + if (simpleSensorType == null) + { + apiResult.Code = "9998"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + apiResult.Code = "0000"; + apiResult.Data = simpleSensorType; + + } + catch (Exception exception) + { + apiResult.Code = "9999"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + /// + /// 新增 / 修改 設備-細項資料 + /// + /// + /// + [HttpPost] + public async Task> SaveSensorDetail(SensorDetail post) + { + ApiResult apiResult = new ApiResult(); + + SensorDetail sensorDetail = null; + + string nowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + + try + { + sensorDetail = await sensorDetailRepository.GetOneAsync(post.Id); + + if (sensorDetail == null) + { + + if (post.Id != 0) + { + apiResult.Code = "9998";//待定 + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + #region 新增設備-細項 + sensorDetail = new SensorDetail() + { + Deleted = 0, + SensorTypeId = post.SensorTypeId, + ItemName = post.ItemName, + ItemEName = post.ItemEName, + HourType = post.HourType, + DayType = post.DayType, + MonthType = post.MonthType, + WarningURL = post.WarningURL, + UpperValue = post.UpperValue, + LowerValue = post.LowerValue, + CreatedBy = myUser.Id, + CreatedAt = nowTime + }; + + List properties = new List() + { + "Deleted", + "SensorTypeId", + "ItemName", + "ItemEName", + "HourType", + "DayType", + "MonthType", + "WarningURL", + "UpperValue", + "LowerValue", + "CreatedBy", + "CreatedAt" + }; + + var id = await sensorDetailRepository.AddOneAsync(sensorDetail, properties); + + apiResult.Code = "0000"; + apiResult.Msg = "儲存成功"; + #endregion + } + else + { + #region 修改設備-細項 + SensorDetail update = new SensorDetail() + { + Id = sensorDetail.Id, + SensorTypeId = post.SensorTypeId, + ItemName = post.ItemName, + ItemEName = post.ItemEName, + HourType = post.HourType, + DayType = post.DayType, + MonthType = post.MonthType, + WarningURL = post.WarningURL, + UpperValue = post.UpperValue, + LowerValue = post.LowerValue, + UpdatedBy = myUser.Id, + UpdatedAt = nowTime + }; + + + List properties = new List() + { + "Id", + "SensorTypeId", + "ItemName", + "ItemEName", + "HourType", + "DayType", + "MonthType", + "WarningURL", + "UpperValue", + "LowerValue", + "UpdatedBy", + "UpdatedAt" + }; + + await sensorDetailRepository.UpdateSensorDetailInfo(update, properties); + apiResult.Code = "0000"; + apiResult.Msg = "儲存成功"; + #endregion + } + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + string json = System.Text.Json.JsonSerializer.Serialize(post); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + json); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + return apiResult; + } + + [HttpPost] + public async Task>> GetSensorDetail(int id) + { + ApiResult> apiResult = new ApiResult>(); + + List sensorDetails = null; + + try + { + sensorDetails = await sensorDetailRepository.GetAllSensorDetailAsync(id); + foreach (SensorDetail a in sensorDetails) + { + switch (a.HourType) + { + case "Sum": + a.HourTypeName = "總數"; + break; + case "Max": + a.HourTypeName = "最大值"; + break; + case "Min": + a.HourTypeName = "最小值"; + break; + case "Avg": + a.HourTypeName = "平均值"; + break; + default: + a.HourTypeName = "無資料"; + break; + } + switch (a.DayType) + { + case "Sum": + a.DayTypeName = "總數"; + break; + case "Max": + a.DayTypeName = "最大值"; + break; + case "Min": + a.DayTypeName = "最小值"; + break; + case "Avg": + a.DayTypeName = "平均值"; + break; + default: + a.DayTypeName = "無資料"; + break; + } + switch (a.MonthType) + { + case "Sum": + a.MonthTypeName = "總數"; + break; + case "Max": + a.MonthTypeName = "最大值"; + break; + case "Min": + a.MonthTypeName = "最小值"; + break; + case "Avg": + a.MonthTypeName = "平均值"; + break; + default: + a.MonthTypeName = "無資料"; + break; + } + } + + if (sensorDetails == null) + { + apiResult.Code = "9988"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + apiResult.Code = "0000"; + apiResult.Data = sensorDetails; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + } + + [HttpPost] + public async Task> DeleteOneSensorDetail(int id) + { + ApiResult apiResult = new ApiResult(); + + try + { + var userPowerStation = sensorDetailRepository.GetOneAsync(id); + + if (userPowerStation == null) + { + apiResult.Code = "9988"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + await sensorDetailRepository.DeleteOne(id); + + apiResult.Code = "0000"; + apiResult.Msg = "刪除成功"; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + } + } } diff --git a/SolarPower/Models/AnalysisStationInfo.cs b/SolarPower/Models/AnalysisStationInfo.cs index 72cd744..0635a0a 100644 --- a/SolarPower/Models/AnalysisStationInfo.cs +++ b/SolarPower/Models/AnalysisStationInfo.cs @@ -17,6 +17,8 @@ namespace SolarPower.Models public string DeviceName { get; set; } public string DeviceType { get; set; } public string DeviceId { get; set; } + public string SensorTypeId { get; set; } + public string SensorTypeDetailId { get; set; } } public class PostAnalysisStation diff --git a/SolarPower/Models/SensorDetail.cs b/SolarPower/Models/SensorDetail.cs new file mode 100644 index 0000000..29c6d9d --- /dev/null +++ b/SolarPower/Models/SensorDetail.cs @@ -0,0 +1,31 @@ +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace SolarPower.Models.SensorDetail +{ + public class SensorDetail : Created + { + public int Id { get; set; } //編號 + public int SensorTypeId { get; set; } //裝置類別編號 + public int Deleted { get; set; } //是否刪除 + public string ItemName { get; set; } //項目名稱 + public string ItemEName { get; set; } //英文簡稱 + public string HourType { get; set; } //小時數值類別 + public string DayType { get; set; } //日數值類別 + public string MonthType { get; set; } //月數值類別 + public string WarningURL { get; set; } //警告網址 + public int UpperValue { get; set; } //上限 + public int LowerValue { get; set; } //下限 + public string HourTypeName { get; set; } //小時數值類別的名稱 + public string DayTypeName { get; set; } //日數值類別的名稱 + public string MonthTypeName { get; set; } //月數值類別的名稱 + + private string updatedAt; + public int UpdatedBy { get; set; } //修改者 + public string UpdatedAt { get { return Convert.ToDateTime(updatedAt).ToString("yyyy-MM-dd HH:mm:ss"); } set { updatedAt = value; } } //修改時間 + } + +} diff --git a/SolarPower/Models/SensorType.cs b/SolarPower/Models/SensorType.cs index 3508bc3..507212f 100644 --- a/SolarPower/Models/SensorType.cs +++ b/SolarPower/Models/SensorType.cs @@ -7,25 +7,25 @@ using System.Threading.Tasks; namespace SolarPower.Models.SensorType { //Base Class。如由其餘需求,使用繼承 - public class SensorType : SensorTypeInfo + public class SensorType : Created { - //public int Id { get; set; } //編號 - public byte Deleted { get; set; } //是否刪除 - //public int UId { get; set; } //設備編號 - //public int Enabled { get; set; } //啟用 - //public string SensorName { get; set; } //sensor名稱 - //public string SensorNameEn { get; set; } //sensor英文名稱 + public int Id { get; set; } //編號 + public int Deleted { get; set; } //是否刪除 + public int Enabled { get; set; } //啟用 + public string SensorName { get; set; } //sensor名稱 + public string SensorEName { get; set; } //sensor英文名稱 + public string EnabledName { get; set; }//啟用 + private string updatedAt; + public int UpdatedBy { get; set; } //修改者 + public string UpdatedAt { get { return Convert.ToDateTime(updatedAt).ToString("yyyy-MM-dd HH:mm:ss"); } set { updatedAt = value; } } //修改時間 } - /// - /// 設備 - /// - public class SensorTypeInfo : UserInfo + public class SensorTypeWithDetail { - public int UId { get; set; }//設備編號 - public string SensorName { get; set; }//傳感器名稱 - public string SensorNameEn { get; set; }//傳感器英文名稱 - public int Enabled { get; set; }//啟用 + public string SensorName { get; set; } //sensor名稱 + public string SensorEName { get; set; } //sensor英文名稱 + public string ItemName { get; set; } //子項目名稱 + public string ItemEName { get; set; } //子項目英文名稱 } } diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index a9609f1..88baca7 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -13,6 +13,7 @@ using System.Text.Json; using SolarPower.Models; using SolarPower.Models.Role; using SolarPower.Models.Company; +using SolarPower.Models.SensorType; using MySql.Data.MySqlClient; namespace SolarPower.Repository.Implement @@ -967,15 +968,25 @@ namespace SolarPower.Repository.Implement var trans = conn.BeginTransaction(); try { - string sql = @$"SELECT * FROM variable WHERE name = @name"; - var json = await conn.QueryFirstOrDefaultAsync(sql, new { name = "Type" }); - Root jsonfor = JsonSerializer.Deserialize(json.value); - foreach (Models.PowerStation.Type a in jsonfor.Type) + var sql = @$"SELECT + st.*, + std.SensorTypeId AS SensorTypeId, std.Deleted AS ItemDeleted, std.ItemName AS ItemName, std.ItemEName AS ItemEName + FROM sensor_type st + LEFT JOIN sensor_type_detail std ON st.Id = std.SensorTypeId AND std.Deleted = 0 + WHERE st.Deleted = 0 "; + + var json3 = (await conn.QueryAsync(sql)).ToList(); + foreach (SensorTypeWithDetail a in json3) { + string subName = ""; + if (a.ItemName != null) + { + subName = " - " + a.ItemName; + } UserSelectItemList KeyValue = new UserSelectItemList { - Value = a.EName, - Text = a.Name + Value = a.SensorEName, + Text = a.SensorName + subName }; result.Add(KeyValue); } @@ -992,6 +1003,7 @@ namespace SolarPower.Repository.Implement } return result; } + /// /// 新增裝置資料 /// @@ -4457,7 +4469,9 @@ namespace SolarPower.Repository.Implement ps.Name AS PowerStationName, d.Name AS DeviceName, d.`Type` AS DeviceType, - d.UID AS DeviceId + d.UID AS DeviceId, + d.SensorTypeId AS SensorTypeId, + d.SensorTypeDetailId AS SensorTypeDetailId FROM power_station ps LEFT JOIN `city` c ON ps.CityId = c.Id LEFT JOIN {powerStationDic.Key}.device d ON ps.Id = d.PowerStationId AND d.Deleted = 0 AND d.Enabled = 1 AND d.Status = 1 @@ -4750,7 +4764,7 @@ namespace SolarPower.Repository.Implement try { var sql = @$"SELECT * FROM {db_name}.device d - WHERE d.PowerStationId = @PowerStationId AND UID IN @UID"; + WHERE d.PowerStationId = @PowerStationId AND UID IN @UID AND Deleted = 0 AND Enabled = 1"; result = (await conn.QueryAsync(sql, new { PowerStationId = powerStationId, UID = deviceIds })).ToList(); @@ -5855,7 +5869,6 @@ namespace SolarPower.Repository.Implement { "inv", "station", - "sensor", "sensoravg", }; // tables.Add("meter"); @@ -6149,8 +6162,7 @@ namespace SolarPower.Repository.Implement var sql = $@"SELECT * FROM (SELECT count(*) ctAvg, a.SITEID AS Avg FROM {dbname}.s{code}01_sensoravg a ORDER BY a.ID DESC LIMIT 1) a, (SELECT count(*) ctInv_site, a.SITEID AS Inv_site,a.INVERTERID as Inv_inveter FROM {dbname}.s{code}01_inv a ORDER BY a.ID DESC LIMIT 1) b, - (SELECT count(*) ctStation, a.SITEID AS Station FROM {dbname}.s{code}01_station a ORDER BY a.ID DESC LIMIT 1) c, - (SELECT count(*) ctSensor, a.SITEID AS Sensor FROM {dbname}.s{code}01_sensor a ORDER BY a.ID DESC LIMIT 1) d + (SELECT count(*) ctStation, a.SITEID AS Station FROM {dbname}.s{code}01_station a ORDER BY a.ID DESC LIMIT 1) c "; resule = await conn.QueryFirstOrDefaultAsync(sql); diff --git a/SolarPower/Repository/Implement/SensorDetailRepository.cs b/SolarPower/Repository/Implement/SensorDetailRepository.cs new file mode 100644 index 0000000..97f9fd5 --- /dev/null +++ b/SolarPower/Repository/Implement/SensorDetailRepository.cs @@ -0,0 +1,105 @@ +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using SolarPower.Models; +using SolarPower.Models.SensorDetail; +using SolarPower.Repository.Interface; +using Dapper; +using SolarPower.Helper; +using System.Data; + +namespace SolarPower.Repository.Implement +{ + public class SensorDetailRepository : RepositoryBase, ISensorDetailRepository + { + public SensorDetailRepository(IDatabaseHelper databaseHelper) : base(databaseHelper) + { + tableName = "sensor_type_detail"; + } + + /// + /// 修改設備-細項資料 + /// + /// + /// + public async Task UpdateSensorDetailInfo(SensorDetail entity, List properties) + { + GetProperties = typeof(SensorDetail).GetProperties(); + using (IDbConnection conn = _databaseHelper.GetConnection()) + { + conn.Open(); + using (var trans = conn.BeginTransaction()) + { + try + { + var sql = GenerateUpdateQuery(properties); + + await conn.ExecuteAsync(sql, entity, trans); + + trans.Commit(); + } + catch (Exception exception) + { + trans.Rollback(); + throw exception; + } + finally + { + conn.Close(); + } + } + } + } + + /// + /// 取得設備-細項資料 + /// + /// + /// + public async Task> GetAllSensorDetailAsync(int sensorTypeId) + { + List result; + using (IDbConnection conn = _databaseHelper.GetConnection()) + { + try//tableName + { + var sql = $"SELECT * FROM {tableName} WHERE deleted = 0 AND sensorTypeId = @SensorTypeId"; + + result = (await conn.QueryAsync(sql, new { SensorTypeId = sensorTypeId })).ToList(); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } + + /// + /// 取得設備-細項資料 + /// + /// + /// + public async Task GetOneSensorDetailAsync(int id) + { + SensorDetail result; + using (IDbConnection conn = _databaseHelper.GetConnection()) + { + try//tableName + { + var sql = $"SELECT * FROM {tableName} WHERE deleted = 0 AND id = @Id"; + + result = await conn.QueryFirstOrDefaultAsync(sql, new { Id = id }); + } + catch (Exception exception) + { + throw exception; + } + return result; + } + } + + } +} diff --git a/SolarPower/Repository/Implement/SensorTypeRepository.cs b/SolarPower/Repository/Implement/SensorTypeRepository.cs index 0a616c6..f08e1eb 100644 --- a/SolarPower/Repository/Implement/SensorTypeRepository.cs +++ b/SolarPower/Repository/Implement/SensorTypeRepository.cs @@ -23,11 +23,11 @@ namespace SolarPower.Repository.Implement List result; using (IDbConnection conn = this._databaseHelper.GetConnection()) { - try + try//tableName { - var sql = $"SELECT Id, Deleted, Enabled, UID, SensorName, SensorNameEn FROM solar_master.sensor_type WHERE deleted = 0"; + var sql = $"SELECT * FROM {tableName} WHERE deleted = 0"; - result = (await conn.QueryAsync(sql)).ToList(); + result = (await conn.QueryAsync(sql)).ToList(); } catch (Exception exception) { @@ -48,23 +48,13 @@ namespace SolarPower.Repository.Implement using (IDbConnection conn = _databaseHelper.GetConnection()) { conn.Open(); - //var trans = conn.BeginTransaction(); using (var trans = conn.BeginTransaction()) { try { - //string sql = GenerateInsertQueryWithCustomDBNameAndTable(properties, db_name, "device"); - //await conn.ExecuteAsync(sql, DeviceInfo); - //trans.Commit(); - - //var sql2 = GenerateUpdateQuery(properties); var sql = GenerateInsertQueryWithCustomTable(properties, "sensor_type"); await conn.ExecuteAsync(sql, sensorInfo, trans); trans.Commit(); - - //string sql = $"INSERT INTO company_auth_page (CompanyId, AuthCode, CreatedBy) VALUES (@CompanyId, @AuthCode, @CreatedBy)"; - //await conn.ExecuteAsync(sql, trans); - //trans.Commit(); } catch (Exception exception) { @@ -81,20 +71,20 @@ namespace SolarPower.Repository.Implement } /// - /// 透過sensorNameEn,取得單一筆資料 + /// 透過sensorEName,取得單一筆資料 /// - /// + /// /// - public async Task GetOneByEnglishNameAsync(string sensorNameEn) + public async Task GetOneByEnglishNameAsync(string sensorEName) { SensorType result; using (IDbConnection conn = _databaseHelper.GetConnection()) { try { - var sql = $"SELECT * FROM solar_master.sensor_type WHERE deleted = 0 AND sensorNameEn = @SensorNameEn"; + var sql = $"SELECT * FROM {tableName} WHERE deleted = 0 AND sensorEName = @SensorEName"; - result = await conn.QueryFirstOrDefaultAsync(sql, new { SensorName_En = sensorNameEn }); + result = await conn.QueryFirstOrDefaultAsync(sql, new { SensorEName = sensorEName }); } catch (Exception exception) { @@ -138,5 +128,34 @@ namespace SolarPower.Repository.Implement } } + /// + /// 取得設備類型 透過id + /// + /// + /// + public async Task GetOneSensorType(int id) + { + SensorType result; + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + conn.Open(); + try + { + var sql = @$"SELECT * FROM {tableName} WHERE Deleted = 0 AND Id = @Id"; + + result = await conn.QueryFirstOrDefaultAsync(sql, new { Id = id }); + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + return result; + } + } + } } diff --git a/SolarPower/Repository/Interface/ISensorDetailRepository.cs b/SolarPower/Repository/Interface/ISensorDetailRepository.cs new file mode 100644 index 0000000..671ea6d --- /dev/null +++ b/SolarPower/Repository/Interface/ISensorDetailRepository.cs @@ -0,0 +1,36 @@ +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using SolarPower.Models; +using SolarPower.Models.SensorDetail; +using SolarPower.Repository.Interface; + +namespace SolarPower.Repository.Interface +{ + public interface ISensorDetailRepository : IRepositoryBase + { + /// + /// 修改設備-細項資料 + /// + /// + /// + /// + Task UpdateSensorDetailInfo(SensorDetail entity, List properties); + + /// + /// 取得設備-細項資料 + /// + /// + /// + Task> GetAllSensorDetailAsync(int sensorTypeId); + /// + /// 取得設備-單一細項資料 + /// + /// + /// + Task GetOneSensorDetailAsync(int id); + + } +} diff --git a/SolarPower/Repository/Interface/ISensorTypeRepository.cs b/SolarPower/Repository/Interface/ISensorTypeRepository.cs index 2f6ec21..73ae4f2 100644 --- a/SolarPower/Repository/Interface/ISensorTypeRepository.cs +++ b/SolarPower/Repository/Interface/ISensorTypeRepository.cs @@ -21,11 +21,11 @@ namespace SolarPower.Repository.Interface Task AddSensor(SensorType SensorInfo, List properties); /// - /// 透過sensorNameEn,取得單一筆資料 + /// 透過sensorEName,取得單一筆資料 /// - /// + /// /// - Task GetOneByEnglishNameAsync(string sensorNameEn); + Task GetOneByEnglishNameAsync(string sensorEName); /// /// 修改設備資料 @@ -35,6 +35,12 @@ namespace SolarPower.Repository.Interface /// Task UpdateSensorInfo(SensorType entity, List properties); + /// + /// 取得單一設備類型 透過 id + /// + /// + /// + Task GetOneSensorType(int id); } } diff --git a/SolarPower/Startup.cs b/SolarPower/Startup.cs index 7706b29..80f04ad 100644 --- a/SolarPower/Startup.cs +++ b/SolarPower/Startup.cs @@ -83,6 +83,7 @@ namespace SolarPower services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); #endregion double loginExpireMinute = this.Configuration.GetValue("LoginExpireMinute"); diff --git a/SolarPower/Views/AnalysisStationInfo/Index.cshtml b/SolarPower/Views/AnalysisStationInfo/Index.cshtml index 271b1f7..b0eaa0d 100644 --- a/SolarPower/Views/AnalysisStationInfo/Index.cshtml +++ b/SolarPower/Views/AnalysisStationInfo/Index.cshtml @@ -142,16 +142,20 @@ { key: "F", title: "頻率(Hz)", default: false } ] var PYR_compare_col = [{ key: "Irradiance", title: "日照度", default: true }]; + var TPY_compare_col = [{ key: "IrrDay", title: "累積日照度", default: true }]; var ETR_compare_col = [{ key: "EnvTemperature", title: "環境溫度計", default: true }]; var MTR_compare_col = [{ key: "Temperature", title: "模組溫度", default: true }]; var EMM_compare_col = [{ key: "Humidity", title: "濕度", default: true }]; var VAN_compare_col = [{ key: "Vane", title: "風速", default: true }]; - var FOM_compare_col = [{ key: "Dust", title: "落塵%", default: true }]; + var DST_compare_col = [{ key: "Dust", title: "落塵%", default: true }]; + var WIN_compare_col = [{ key: "Win", title: "風向", default: true }]; var current_compare_col = []; var default_compare_col = []; var selected_YAxis = []; var analysisStationInfo; var chart; + //Dictionary sensor_type_detail_dictionary { get; set; }; + var sensor_type_detail_dictionary; $(function () { $('#collapse').trigger("click"); @@ -334,11 +338,13 @@ var temp_obj = { powerStationId: $(this).attr("data-power-station-id"), deviceType: type, - deviceId: this.value + deviceId: this.value, + sensorTypeId: $(this).attr("data-sensor-type-id"), + sensorTypeDetailId: $(this).attr("data-sensor-type-detail-id") } selected_device.push(temp_obj); - + GetItemInfo(temp_obj.sensorTypeDetailId); switch (type) { case 'PWS': PushSpecifyCurrentCompareCol(PWS_compare_col); @@ -346,24 +352,30 @@ case 'PWR': //電錶 PushSpecifyCurrentCompareCol(PWR_compare_col); break; - case 'PYR': //日照計 - PushSpecifyCurrentCompareCol(PYR_compare_col); - break; - case 'ETR': //環境溫度計 - PushSpecifyCurrentCompareCol(ETR_compare_col); - break; - case 'MTR': //模組溫度計 - PushSpecifyCurrentCompareCol(MTR_compare_col); - break; - case 'VAN': //風速計 - PushSpecifyCurrentCompareCol(VAN_compare_col); - break; - case 'FOM': //落塵計 - PushSpecifyCurrentCompareCol(FOM_compare_col); - break; - case 'EMM': //環境濕度計 - PushSpecifyCurrentCompareCol(EMM_compare_col); - break; + // case 'PYR': //日照計 + // PushSpecifyCurrentCompareCol(PYR_compare_col); + // break; + // case 'TPY': //累積日照 + // PushSpecifyCurrentCompareCol(TPY_compare_col); + // break; + // case 'ETR': //環境溫度計 + // PushSpecifyCurrentCompareCol(ETR_compare_col); + // break; + // case 'MTR': //模組溫度計 + // PushSpecifyCurrentCompareCol(MTR_compare_col); + // break; + // case 'VAN': //風速計 + // PushSpecifyCurrentCompareCol(VAN_compare_col); + // break; + // case 'DST': //落塵計 FOM + // PushSpecifyCurrentCompareCol(DST_compare_col); + // break; + // case 'EMM': //環境濕度計 + // PushSpecifyCurrentCompareCol(EMM_compare_col); + // break; + // case 'WIN': //風向計 + // PushSpecifyCurrentCompareCol(WIN_compare_col); + // break; } } } else { @@ -392,6 +404,9 @@ case 'PYR': //日照計 RemoveSpecifyCurrentCompareCol(PYR_compare_col); break; + case 'TPY': //累積日照 + RemoveSpecifyCurrentCompareCol(TPY_compare_col); + break; case 'ETR': //環境溫度計 RemoveSpecifyCurrentCompareCol(ETR_compare_col); break; @@ -401,19 +416,22 @@ case 'VAN': //風速計 RemoveSpecifyCurrentCompareCol(VAN_compare_col); break; - case 'FOM': //落塵計 - RemoveSpecifyCurrentCompareCol(VAN_compare_col); + case 'DST': //落塵計 FOM + RemoveSpecifyCurrentCompareCol(DST_compare_col); break; case 'EMM': //環境濕度計 RemoveSpecifyCurrentCompareCol(EMM_compare_col); break; + case 'WIN': //風向計 + RemoveSpecifyCurrentCompareCol(WIN_compare_col); + break; } current_compare_col = current_compare_col.filter(x => x.count > 0); } } - ChangeCompareSelectOption() + ChangeCompareSelectOption(); }); $('#js_list_accordion').on("change", 'input[name="selectedDeviceLayer2[]"]', function (event) { @@ -516,9 +534,18 @@ device_icon = ''; break; }*@ + + switch (device.sensorTypeDetailId) { + + } + + + + + str += '
  • ' + '
    ' + - '' + + '' + '
    ' + '' + device_icon + device.deviceName + '' + '
  • '; @@ -552,6 +579,35 @@ }, 'json'); } + //在剛開始就在 sensor_type_detail 資料表中 取得ItemName + //#region + function GetItemInfo(itemId) { + + //sensor_type_detail_dictionary = {''} + //my_dict = { 'first_name': 'eddie', 'last_name': 'kao', 'age': 30 } + + var url = "/AnalysisStationInfo/GetOneSensorDetail/"; + + var send_data = { + id: itemId + } + + $.post(url, send_data, function (rel) { + if (rel.code == "9999") { + toast_error(rel.msg); + return; + } + else if (rel.code == "9998") { + toast_error(rel.msg); + return; + } + var nowCompare_col = [{ key: rel.data.itemEName, title: rel.data.itemName, default: true }]; + PushSpecifyCurrentCompareCol(nowCompare_col); + ChangeCompareSelectOption(); + }, 'json'); + } + //#endregion + //#region 加入已勾選的設備所要顯示得比較欄位 function PushSpecifyCurrentCompareCol(compare_col) { $.each(compare_col, function (index, item) { diff --git a/SolarPower/Views/SensorType/Index.cshtml b/SolarPower/Views/SensorType/Index.cshtml index 8def1b3..69065ef 100644 --- a/SolarPower/Views/SensorType/Index.cshtml +++ b/SolarPower/Views/SensorType/Index.cshtml @@ -36,10 +36,10 @@ - + - - + + @@ -71,20 +71,16 @@
    - - + +
    - - -
    -
    - - + +
    - - @@ -100,150 +96,475 @@
    + + + +
    設備編號裝置編號 啟用Sensor名稱Sensor英文名稱裝置名稱英文簡稱 建立時間 功能
    + + + + + + + + + + + + + + + +
    項目名稱英文簡稱小時的數值類別天的數值類別月的數值類別警告URL上限下限功能
    + @**@ + + + + + + @section Scripts { } \ No newline at end of file diff --git a/SolarPower/Views/Shared/_Layout.cshtml b/SolarPower/Views/Shared/_Layout.cshtml index b769f2d..809dced 100644 --- a/SolarPower/Views/Shared/_Layout.cshtml +++ b/SolarPower/Views/Shared/_Layout.cshtml @@ -418,14 +418,14 @@ } - @*@if (ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin || ViewBag.auths.Contains("SensorType")) + @if (ViewBag.myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin || ViewBag.auths.Contains("SensorType")) {
  • 裝置管理
  • - }*@ + } @*@if (ViewBag.auths.Contains("User")) {