From b5fec530b535bdf887be0114ca778eef77d43324 Mon Sep 17 00:00:00 2001 From: Kai Date: Tue, 31 Aug 2021 10:21:06 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=9B=BB=E7=AB=99?= =?UTF-8?q?=E6=8A=93=E5=8F=96=E6=96=B9=E5=BC=8F=20step1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Models/MyBaseModel.cs | 6 ++ SolarPower/Quartz/Jobs/CalcPowerStationJob.cs | 2 +- .../Implement/PowerStationRepository.cs | 101 +++++++++++++++--- .../Implement/MyPowerStationService.cs | 10 +- 4 files changed, 99 insertions(+), 20 deletions(-) diff --git a/SolarPower/Models/MyBaseModel.cs b/SolarPower/Models/MyBaseModel.cs index 95569ae..1c8c3ba 100644 --- a/SolarPower/Models/MyBaseModel.cs +++ b/SolarPower/Models/MyBaseModel.cs @@ -107,4 +107,10 @@ namespace SolarPower.Models public int Value { get; set; } //通常放id public string Name { get; set; } } + + public class OrderBy + { + public string Col { get; set; } + public string Sort { get; set; } + } } diff --git a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs index 2a0de14..91006ed 100644 --- a/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs +++ b/SolarPower/Quartz/Jobs/CalcPowerStationJob.cs @@ -103,7 +103,7 @@ namespace SolarPower.Quartz.Jobs if (string.IsNullOrEmpty(exist)) { - logger.LogError("【CalcPowerStationJob】【查無電站[0]的s{0}01_station資料表】", powerStation.Code); + logger.LogError("【CalcPowerStationJob】【查無電站[{0}]的s{0}01_station資料表】", powerStation.Code); } else { diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index 88a8412..3d0ed9c 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -23,16 +23,15 @@ namespace SolarPower.Repository.Implement tableName = "power_station"; } - - public List GetMyPowerStationSummary(MyUser myUser, string filter = "") + public List GetMyPowerStationSummary(MyUser myUser, List wheres = null, List orderBy = null) { - List results = new List(); + var results = new List(); using (IDbConnection conn = this._databaseHelper.GetConnection()) { try { - var sql = @"SELECT ps.Id, ps.CityId, c.Name AS CityName, ps.Name + var sql = @"SELECT ps.*, c.Name AS CityName FROM power_station ps LEFT JOIN city c ON ps.CityId = c.Id"; @@ -43,19 +42,28 @@ namespace SolarPower.Repository.Implement else if (myUser.Role.Layer == (int)RoleLayerEnum.PlatformUser || myUser.Role.Layer == (int)RoleLayerEnum.CompanyUser) { sql += @" LEFT JOIN power_station_operation_personnel op ON ps.Id = op.PowerStationId - WHERE ps.Deleted = 0 AND op.Deleted = 0 AND op.UserId = @UserId "; + WHERE ps.Deleted = 0 AND op.Deleted = 0 AND op.UserId = @UserId "; } else { sql += @" WHERE ps.Deleted = 0"; } - if (!string.IsNullOrEmpty(filter)) + if (wheres != null && wheres.Count > 0) { - sql += @" AND ps.Name LIKE CONCAT('%', @Filter, '%')"; + var temp_where = ""; + temp_where = string.Join(" AND ", wheres); + sql += string.Join(" AND ", wheres); } - sql += " ORDER BY c.Priority"; + if (orderBy != null && orderBy.Count > 0) + { + var temp_order = ""; + temp_order = string.Join(" , ", orderBy); + sql += $" ORDER BY c.Priority, {temp_order}"; + } + + var myPowerStationInfos = conn.Query(sql, new { CompanyId = myUser.CompanyId, UserId = myUser.Id, Filter = filter }).ToList(); @@ -88,6 +96,71 @@ namespace SolarPower.Repository.Implement } } + + //public List GetMyPowerStationSummary(MyUser myUser, string filter = "") + //{ + // List results = new List(); + + // using (IDbConnection conn = this._databaseHelper.GetConnection()) + // { + // try + // { + // var sql = @"SELECT ps.Id, ps.CityId, c.Name AS CityName, ps.Name + // FROM power_station ps + // LEFT JOIN city c ON ps.CityId = c.Id"; + + // if (myUser.Role.Layer == (int)RoleLayerEnum.CompanyAdmin) + // { //公司管理員 + // sql += @" WHERE ps.Deleted = 0 AND ps.CompanyId = @CompanyId"; + // } + // else if (myUser.Role.Layer == (int)RoleLayerEnum.PlatformUser || myUser.Role.Layer == (int)RoleLayerEnum.CompanyUser) + // { + // sql += @" LEFT JOIN power_station_operation_personnel op ON ps.Id = op.PowerStationId + // WHERE ps.Deleted = 0 AND op.Deleted = 0 AND op.UserId = @UserId "; + // } + // else + // { + // sql += @" WHERE ps.Deleted = 0"; + // } + + // if (!string.IsNullOrEmpty(filter)) + // { + // sql += @" AND ps.Name LIKE CONCAT('%', @Filter, '%')"; + // } + + // sql += " ORDER BY c.Priority"; + + // var myPowerStationInfos = conn.Query(sql, new { CompanyId = myUser.CompanyId, UserId = myUser.Id, Filter = filter }).ToList(); + + // var myPowerStationInfos_group = myPowerStationInfos.GroupBy(x => x.CityId); + + // foreach (var myPowerStationInfo in myPowerStationInfos_group) + // { + // MyPowerStationSummary myPowerStationSummary = new MyPowerStationSummary(); + // myPowerStationSummary.CityName = myPowerStationInfo.First().CityName; + // myPowerStationSummary.Amount = myPowerStationInfo.Count(); + // myPowerStationSummary.MyPowerStations = new List(); + // foreach (var info in myPowerStationInfo) + // { + // MyPowerStation myPowerStation = new MyPowerStation(); + // myPowerStation.PowerStationId = info.Id; + // myPowerStation.PowerStationName = info.Name; + + // myPowerStationSummary.MyPowerStations.Add(myPowerStation); + // } + + // results.Add(myPowerStationSummary); + // } + + // } + // catch (Exception exception) + // { + // throw exception; + // } + // return results; + // } + //} + /// /// 查詢縣市列表 /// @@ -4798,7 +4871,7 @@ namespace SolarPower.Repository.Implement try { var purge_sql = $"DELETE FROM power_station_history_hour WHERE DATE_FORMAT(TIMESTAMP, '%Y-%m-%d') BETWEEN @StartDate AND @EndDate"; - await conn.ExecuteAsync(purge_sql, new { StartDate = startDate, EndDate = endDate}, trans); + await conn.ExecuteAsync(purge_sql, new { StartDate = startDate, EndDate = endDate }, trans); var insert_sql = GenerateInsertQueryWithCustomTable(properties, "power_station_history_hour"); count = await conn.ExecuteAsync(insert_sql, entity, trans); @@ -4991,7 +5064,7 @@ namespace SolarPower.Repository.Implement try { var table_name = "inverter_history_15min"; - + var purge_sql = $"DELETE FROM {table_name} WHERE DATE_FORMAT(TIMESTAMP, '%Y-%m-%d') BETWEEN @StartDate AND @EndDate"; await conn.ExecuteAsync(purge_sql, new { StartDate = startDate, EndDate = endDate }, trans); @@ -5121,7 +5194,7 @@ namespace SolarPower.Repository.Implement } } - public async Task> GetAllInverterInfo(List post,string site_table, string site_db) + public async Task> GetAllInverterInfo(List post, string site_table, string site_db) { List result; using (IDbConnection conn = this._databaseHelper.GetConnection()) @@ -5149,7 +5222,7 @@ namespace SolarPower.Repository.Implement } - public async Task GetInverterInfoModal (int Id, string Time,string DB ,string Table) + public async Task GetInverterInfoModal(int Id, string Time, string DB, string Table) { InverterDetailModal result; using (IDbConnection conn = this._databaseHelper.GetConnection()) @@ -5233,7 +5306,7 @@ namespace SolarPower.Repository.Implement } - public async Task> GetApicallItemList(int powerStationId,string dbname) + public async Task> GetApicallItemList(int powerStationId, string dbname) { List result; using (IDbConnection conn = this._databaseHelper.GetConnection()) @@ -5265,7 +5338,7 @@ namespace SolarPower.Repository.Implement } } - public async Task> GetApicallList(int PowerStationId,string Type) + public async Task> GetApicallList(int PowerStationId, string Type) { List result; using (IDbConnection conn = this._databaseHelper.GetConnection()) diff --git a/SolarPower/Services/Implement/MyPowerStationService.cs b/SolarPower/Services/Implement/MyPowerStationService.cs index 59c110a..90b1ce2 100644 --- a/SolarPower/Services/Implement/MyPowerStationService.cs +++ b/SolarPower/Services/Implement/MyPowerStationService.cs @@ -17,10 +17,10 @@ namespace SolarPower.Services.Implement this.powerStationRepository = powerStationRepository; } - //public List GetMyPowerStations(MyUser myUser, List CityIds = null, List Where = null, List Order_by = null) - //{ - // List powerStations = new List(); - // return powerStations; - //} + public List GetMyPowerStations(MyUser myUser, List CityIds = null, List wheres = null, List orderBy = null) + { + List powerStations = new List(); + return powerStations; + } } } From e84c23b61697e53974ea69eb5fbabbabbf016614 Mon Sep 17 00:00:00 2001 From: Kai Date: Wed, 1 Sep 2021 10:41:16 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=9B=BB=E7=AB=99?= =?UTF-8?q?=E6=8A=93=E5=8F=96=E6=96=B9=E5=BC=8F=20part2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/MapOverviewController.cs | 35 +++++---- SolarPower/Controllers/MyBaseController.cs | 15 ++-- .../Controllers/StationOverviewController.cs | 10 ++- SolarPower/DBSchema/solar_power_schema.sql | 13 ++++ SolarPower/Models/MyBaseModel.cs | 22 ++++-- .../Implement/PowerStationRepository.cs | 33 +++----- .../Interface/IPowerStationRepository.cs | 3 +- .../Implement/MyPowerStationService.cs | 78 ++++++++++++++++++- SolarPower/Views/Shared/_Layout.cshtml | 18 ++--- 9 files changed, 161 insertions(+), 66 deletions(-) diff --git a/SolarPower/Controllers/MapOverviewController.cs b/SolarPower/Controllers/MapOverviewController.cs index d69950c..e4bfb98 100644 --- a/SolarPower/Controllers/MapOverviewController.cs +++ b/SolarPower/Controllers/MapOverviewController.cs @@ -4,6 +4,7 @@ using SolarPower.Models; using SolarPower.Models.PowerStation; using SolarPower.Models.Role; using SolarPower.Repository.Interface; +using SolarPower.Services.Implement; using System; using System.Collections.Generic; using System.IO; @@ -41,20 +42,25 @@ namespace SolarPower.Controllers MapOverview mapOverview = new MapOverview(); try { + MyPowerStationService myPowerStationService = new MyPowerStationService(powerStationRepository); + var myPowerStations = myPowerStationService.GetMyPowerStations(myUser); - //List powerStationIds = await powerStationRepository.GetPowerStationIdsByUserRole(myUser); - List powerStationIds = myUser.PowerStationSummaries.SelectMany(x => x.MyPowerStations.Select(y=> y.PowerStationId)).ToList(); - var overview = await overviewRepository.GetOverviewByPowerStationIds(powerStationIds); - mapOverview.Today_kwh = overview.Today_kwh; - mapOverview.Total_kwh = overview.Total_kwh; - mapOverview.Today_irradiance = overview.Today_irradiance; - mapOverview.Avg_irradiance = overview.Avg_irradiance; - mapOverview.Today_PR = overview.Today_PR; - mapOverview.Avg_PR = overview.Avg_PR; - mapOverview.Today_kwhkwp = overview.Today_kwhkwp; - mapOverview.Avg_kwhkwp = overview.Avg_kwhkwp; - mapOverview.Today_carbon = overview.Today_carbon; - mapOverview.Total_carbon = overview.Total_carbon; + List powerStationIds = myPowerStations.SelectMany(x => x.MyPowerStations.Select(y => y.Id)).ToList(); + + var powerStations = myPowerStations.SelectMany(x => x.MyPowerStations).ToList(); + var powerStationSummary = myPowerStationService.GetMyPowerStationsSummary(powerStations); + + //var overview = await overviewRepository.GetOverviewByPowerStationIds(powerStationIds); + mapOverview.Today_kwh = powerStationSummary.Today_kwh; + mapOverview.Total_kwh = powerStationSummary.Total_kwh; + mapOverview.Today_irradiance = powerStationSummary.Today_irradiance; + mapOverview.Avg_irradiance = powerStationSummary.Avg_irradiance; + mapOverview.Today_PR = powerStationSummary.Today_PR; + mapOverview.Avg_PR = powerStationSummary.Avg_PR; + mapOverview.Today_kwhkwp = powerStationSummary.Today_kwhkwp; + mapOverview.Avg_kwhkwp = powerStationSummary.Avg_kwhkwp; + mapOverview.Today_carbon = powerStationSummary.Today_carbon; + mapOverview.Total_carbon = powerStationSummary.Total_carbon; mapOverview.CapacityDataTables = await overviewRepository.GetCapacityDataTableByPowerStationIds(powerStationIds); @@ -70,7 +76,8 @@ namespace SolarPower.Controllers mapOverview.TotalPowerStationCount = totalPowerStationCount; mapOverview.TotalCapacity = totalCapacity / 1000; // kWp -> MWp - mapOverview.PowerStations = await overviewRepository.GetListPowerStationByPowerStationIds(powerStationIds); + //mapOverview.PowerStations = await overviewRepository.GetListPowerStationByPowerStationIds(powerStationIds); + mapOverview.PowerStations = powerStations; mapOverview.UpdatedAt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); diff --git a/SolarPower/Controllers/MyBaseController.cs b/SolarPower/Controllers/MyBaseController.cs index e481f88..69cfbef 100644 --- a/SolarPower/Controllers/MyBaseController.cs +++ b/SolarPower/Controllers/MyBaseController.cs @@ -22,6 +22,7 @@ using Newtonsoft.Json; using SolarPower.Models.Company; using SolarPower.Models.Role; using Microsoft.AspNetCore.Routing; +using SolarPower.Services.Implement; namespace SolarPower.Controllers { @@ -131,9 +132,11 @@ namespace SolarPower.Controllers //取得當前使用者可以查看的電站 - var myPowerStationSummaries = powerStationRepository.GetMyPowerStationSummary(myUser); - myUser.PowerStationSummaries = myPowerStationSummaries; - ViewBag.myPowerStationSummaries = myPowerStationSummaries; + MyPowerStationService myPowerStationService = new MyPowerStationService(powerStationRepository); + var myPowerStations = myPowerStationService.GetMyPowerStations(myUser); + //var myPowerStationSummaries = powerStationRepository.GetMyPowerStationSummary(myUser); + myUser.myPowerStationGroupByCities = myPowerStations; + ViewBag.myPowerStationGroupByCities = myPowerStations; if (controllerName == "PowerStation" && actionName == "Edit") { @@ -146,16 +149,16 @@ namespace SolarPower.Controllers { var hasSubTagNum = false; int i = 0; - foreach(var myPowerStationSummary in myPowerStationSummaries) + foreach (var myPowerStation in myPowerStations) { if (hasSubTagNum) { break; } int j = 0; - foreach(var myPowerStation in myPowerStationSummary.MyPowerStations) + foreach (var station in myPowerStation.MyPowerStations) { - if(myPowerStation.PowerStationId == stationId) + if (station.Id == stationId) { ViewData["SubNum"] = i; ViewData["TagNum"] = j; diff --git a/SolarPower/Controllers/StationOverviewController.cs b/SolarPower/Controllers/StationOverviewController.cs index 414d049..fea1d53 100644 --- a/SolarPower/Controllers/StationOverviewController.cs +++ b/SolarPower/Controllers/StationOverviewController.cs @@ -93,15 +93,17 @@ namespace SolarPower.Controllers } [HttpPost] - public ApiResult> GetPowerStationCollapse(string filter) + public ApiResult> GetPowerStationCollapse(string filter) { - ApiResult> apiResult = new ApiResult>(); + ApiResult> apiResult = new ApiResult>(); try { apiResult.Code = "0000"; - var powerStationSummary = powerStationRepository.GetMyPowerStationSummary(myUser, filter); + //var powerStationSummary = powerStationRepository.GetMyPowerStationSummary(myUser); - apiResult.Data = powerStationSummary; + //TODO + //apiResult.Data = powerStationSummary; + apiResult.Data = null; } catch (Exception exception) { diff --git a/SolarPower/DBSchema/solar_power_schema.sql b/SolarPower/DBSchema/solar_power_schema.sql index 2657926..fb525eb 100644 --- a/SolarPower/DBSchema/solar_power_schema.sql +++ b/SolarPower/DBSchema/solar_power_schema.sql @@ -2178,6 +2178,19 @@ COLLATE='utf8mb4_unicode_ci' ENGINE=InnoDB ; +-- 修改電站資料型態 20210901 +ALTER TABLE `power_station` + CHANGE COLUMN `today_kwhkwp` `today_kwhkwp` DECIMAL(10,3) UNSIGNED NOT NULL DEFAULT '0.000' COMMENT '今日kwhkwp' AFTER `Total_kwh`, + CHANGE COLUMN `avg_kwhkwp` `avg_kwhkwp` DECIMAL(10,3) UNSIGNED NOT NULL DEFAULT '0.000' COMMENT '30天平均kwhkwp' AFTER `today_kwhkwp`, + CHANGE COLUMN `today_money` `today_money` DECIMAL(10,2) UNSIGNED NOT NULL DEFAULT '0.00' COMMENT '今日金額' AFTER `avg_kwhkwp`, + CHANGE COLUMN `total_money` `total_money` DECIMAL(10,2) UNSIGNED NOT NULL DEFAULT '0.00' COMMENT '總金額' AFTER `today_money`, + CHANGE COLUMN `today_PR` `today_PR` DECIMAL(5,2) UNSIGNED NOT NULL DEFAULT '0.00' COMMENT '電站Pr值' AFTER `total_money`, + CHANGE COLUMN `avg_PR` `avg_PR` DECIMAL(5,2) UNSIGNED NOT NULL DEFAULT '0.00' COMMENT '平均Pr值' AFTER `today_PR`, + CHANGE COLUMN `today_carbon` `today_carbon` DECIMAL(10,2) UNSIGNED NOT NULL DEFAULT '0.00' COMMENT '今日減碳量' AFTER `avg_PR`, + CHANGE COLUMN `total_carbon` `total_carbon` DECIMAL(10,2) UNSIGNED NOT NULL DEFAULT '0.00' COMMENT '總減碳量' AFTER `today_carbon`, + CHANGE COLUMN `today_irradiance` `today_irradiance` DECIMAL(5,2) UNSIGNED NOT NULL DEFAULT '0.00' COMMENT '今日日照度' AFTER `total_carbon`, + CHANGE COLUMN `avg_irradiance` `avg_irradiance` DECIMAL(5,2) UNSIGNED NOT NULL DEFAULT '0.00' COMMENT '平均日照度' AFTER `today_irradiance`; + /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; diff --git a/SolarPower/Models/MyBaseModel.cs b/SolarPower/Models/MyBaseModel.cs index 1c8c3ba..9789881 100644 --- a/SolarPower/Models/MyBaseModel.cs +++ b/SolarPower/Models/MyBaseModel.cs @@ -51,7 +51,7 @@ namespace SolarPower.Models public string Email { get; set; } public MyCompany Company { get; set; } //公司資訊 public MyRole Role { get; set; } //角色資訊 - public List PowerStationSummaries { get; set; } + public List myPowerStationGroupByCities { get; set; } } /// @@ -83,11 +83,11 @@ namespace SolarPower.Models public string Name { get; set; } } - public class MyPowerStationSummary + public class MyPowerStationGroupByCity { public string CityName { get; set; } public int Amount { get; set; } - public List MyPowerStations { get; set; } + public List MyPowerStations { get; set; } } public class MyPowerStation @@ -108,9 +108,19 @@ namespace SolarPower.Models public string Name { get; set; } } - public class OrderBy + public class PowerStationsSummary { - public string Col { get; set; } - public string Sort { get; set; } + public double Today_kwh { get; set; } //今日總發電量 + public double Total_kwh { get; set; } //累計總發電量 + public double Today_irradiance { get; set; } //即時平均日照度 + public double Avg_irradiance { get; set; } //平均日照度(30天) + public double Today_PR { get; set; } //即時平均 PR 值 + public double Avg_PR { get; set; } //平均 PR 值(30天) + public double Today_kwhkwp { get; set; } //即時平均 kWh / kWp + public double Avg_kwhkwp { get; set; } //平均 kWh / kWp (30天) + public double Today_money { get; set; } //今日金額 + public double Total_money { get; set; } //總金額 + public double Today_carbon { get; set; } //今日減碳量 + public double Total_carbon { get; set; } //累積減碳量 } } diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index 3d0ed9c..5eb89f1 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -23,7 +23,7 @@ namespace SolarPower.Repository.Implement tableName = "power_station"; } - public List GetMyPowerStationSummary(MyUser myUser, List wheres = null, List orderBy = null) + public List GetMyPowerStationList(MyUser myUser, List cityIds, List wheres = null, List orderBy = null) { var results = new List(); @@ -49,6 +49,11 @@ namespace SolarPower.Repository.Implement sql += @" WHERE ps.Deleted = 0"; } + if(cityIds != null && cityIds.Count > 0) + { + sql += @" AND c.Id IN @CityIds"; + } + if (wheres != null && wheres.Count > 0) { var temp_where = ""; @@ -62,31 +67,13 @@ namespace SolarPower.Repository.Implement temp_order = string.Join(" , ", orderBy); sql += $" ORDER BY c.Priority, {temp_order}"; } - - - - var myPowerStationInfos = conn.Query(sql, new { CompanyId = myUser.CompanyId, UserId = myUser.Id, Filter = filter }).ToList(); - - var myPowerStationInfos_group = myPowerStationInfos.GroupBy(x => x.CityId); - - foreach (var myPowerStationInfo in myPowerStationInfos_group) + else { - MyPowerStationSummary myPowerStationSummary = new MyPowerStationSummary(); - myPowerStationSummary.CityName = myPowerStationInfo.First().CityName; - myPowerStationSummary.Amount = myPowerStationInfo.Count(); - myPowerStationSummary.MyPowerStations = new List(); - foreach (var info in myPowerStationInfo) - { - MyPowerStation myPowerStation = new MyPowerStation(); - myPowerStation.PowerStationId = info.Id; - myPowerStation.PowerStationName = info.Name; - - myPowerStationSummary.MyPowerStations.Add(myPowerStation); - } - - results.Add(myPowerStationSummary); + sql += $" ORDER BY c.Priority"; } + results = conn.Query(sql, new { CompanyId = myUser.CompanyId, UserId = myUser.Id, CityIds = cityIds }).ToList(); + } catch (Exception exception) { diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index 757aa6c..26396f7 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -17,7 +17,8 @@ namespace SolarPower.Repository.Interface /// /// /// - List GetMyPowerStationSummary(MyUser myUser, string filter = ""); + //List GetMyPowerStationSummary(MyUser myUser, string filter = ""); + List GetMyPowerStationList(MyUser myUser, List cityIds = null, List wheres = null, List orderBy = null); /// /// 查詢縣市列表 diff --git a/SolarPower/Services/Implement/MyPowerStationService.cs b/SolarPower/Services/Implement/MyPowerStationService.cs index 90b1ce2..848e274 100644 --- a/SolarPower/Services/Implement/MyPowerStationService.cs +++ b/SolarPower/Services/Implement/MyPowerStationService.cs @@ -17,10 +17,82 @@ namespace SolarPower.Services.Implement this.powerStationRepository = powerStationRepository; } - public List GetMyPowerStations(MyUser myUser, List CityIds = null, List wheres = null, List orderBy = null) + public List GetMyPowerStations(MyUser myUser, List cityIds = null, List wheres = null, List orderBy = null) { List powerStations = new List(); - return powerStations; + + powerStations = powerStationRepository.GetMyPowerStationList(myUser, cityIds, wheres, orderBy); + + var myPowerStations_group = powerStations.GroupBy(x => x.CityId); + + List myPowerStationGroupByCities = new List(); + foreach (var powerStations_group_item in myPowerStations_group) + { + MyPowerStationGroupByCity myPowerStationGroupByCity = new MyPowerStationGroupByCity(); + myPowerStationGroupByCity.CityName = powerStations_group_item.First().CityName; + myPowerStationGroupByCity.Amount = powerStations_group_item.Count(); + myPowerStationGroupByCity.MyPowerStations = powerStations_group_item.ToList(); + + myPowerStationGroupByCities.Add(myPowerStationGroupByCity); + } + + return myPowerStationGroupByCities; + } + + public PowerStationsSummary GetMyPowerStationsSummary(List powerStations) + { + PowerStationsSummary powerStationsSummary = new PowerStationsSummary(); + + if(powerStations.Count() <= 0) + { + return powerStationsSummary; + } + + var sum_Today_kwh = 0.0; + var sum_Total_kwh = 0.0; + var sum_Today_irradiance = 0.0; + var sum_Avg_irradiance = 0.0; + var sum_Today_PR = 0.0; + var sum_Avg_PR = 0.0; + var sum_Today_kwhkwp = 0.0; + var sum_Avg_kwhkwp = 0.0; + var sum_Today_money = 0.0; + var sum_Total_money = 0.0; + var sum_Today_carbon = 0.0; + var sum_Total_carbon = 0.0; + + var count_powerStation = powerStations.Count(); + + foreach (var powerStation in powerStations) + { + sum_Today_kwh += powerStation.Today_kWh; + sum_Total_kwh += powerStation.Total_kWh; + sum_Today_irradiance += powerStation.Today_irradiance; + sum_Avg_irradiance += powerStation.Avg_irradiance; + sum_Today_PR += powerStation.Today_PR; + sum_Avg_PR += powerStation.Avg_PR; + sum_Today_kwhkwp += powerStation.Today_kwhkwp; + sum_Avg_kwhkwp += powerStation.Avg_kwhkwp; + sum_Today_money += powerStation.Today_Money; + sum_Total_money += powerStation.Total_Money; + sum_Today_carbon += powerStation.Today_Carbon; + sum_Total_carbon += powerStation.Total_Carbon; + } + + powerStationsSummary.Today_kwh = sum_Today_kwh; + powerStationsSummary.Total_kwh = sum_Total_kwh; + powerStationsSummary.Today_irradiance = sum_Today_irradiance / count_powerStation; + powerStationsSummary.Avg_irradiance = sum_Avg_irradiance / count_powerStation; + powerStationsSummary.Today_PR = sum_Today_PR / count_powerStation; + powerStationsSummary.Avg_PR = sum_Avg_PR / count_powerStation; + powerStationsSummary.Today_kwhkwp = sum_Today_kwhkwp / count_powerStation; + powerStationsSummary.Avg_kwhkwp = sum_Avg_kwhkwp / count_powerStation; + powerStationsSummary.Today_money = sum_Today_money; + powerStationsSummary.Total_money = sum_Total_money; + powerStationsSummary.Today_carbon = sum_Today_carbon; + powerStationsSummary.Total_carbon = sum_Total_carbon; + + return powerStationsSummary; } - } +} } diff --git a/SolarPower/Views/Shared/_Layout.cshtml b/SolarPower/Views/Shared/_Layout.cshtml index c7f2e3d..f039a68 100644 --- a/SolarPower/Views/Shared/_Layout.cshtml +++ b/SolarPower/Views/Shared/_Layout.cshtml @@ -199,23 +199,23 @@ 電站資訊
    - @foreach (var myPowerStationSummary in ViewBag.myPowerStationSummaries) + @foreach (var MyPowerStationGroupByCity in ViewBag.myPowerStationGroupByCities) {
  • + ViewData["SubNum"].ToString() == ViewBag.myPowerStationGroupByCities.IndexOf(MyPowerStationGroupByCity).ToString() ? "active open" : "")"> - @myPowerStationSummary.CityName - @myPowerStationSummary.Amount + @MyPowerStationGroupByCity.CityName + @MyPowerStationGroupByCity.Amount
      - @foreach (var myPowerStation in myPowerStationSummary.MyPowerStations) + @foreach (var myPowerStation in MyPowerStationGroupByCity.MyPowerStations) {
    • - - @myPowerStation.PowerStationName + ViewData["SubNum"].ToString() == ViewBag.myPowerStationGroupByCities.IndexOf(MyPowerStationGroupByCity).ToString() && + ViewData["TagNum"].ToString() == MyPowerStationGroupByCity.MyPowerStations.IndexOf(myPowerStation).ToString() ? "active" : "")"> + + @myPowerStation.Name
    • From bb3bd49bc2a49476be92ebd07e4f15e9380bdbd5 Mon Sep 17 00:00:00 2001 From: Kai Date: Wed, 1 Sep 2021 16:02:31 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=9B=BB=E7=AB=99?= =?UTF-8?q?=E6=8A=93=E5=8F=96=E6=96=B9=E5=BC=8F=20part3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/MapOverviewController.cs | 3 +- SolarPower/Controllers/MyBaseController.cs | 5 +- .../Controllers/StationOverviewController.cs | 197 ++++++++++++++---- SolarPower/Models/MyBaseModel.cs | 8 + SolarPower/Models/Overview.cs | 9 + .../Implement/PowerStationRepository.cs | 44 +++- .../Interface/IPowerStationRepository.cs | 6 + .../Implement/MyPowerStationService.cs | 19 +- SolarPower/Views/StationOverview/Index.cshtml | 99 +++++++-- 9 files changed, 324 insertions(+), 66 deletions(-) diff --git a/SolarPower/Controllers/MapOverviewController.cs b/SolarPower/Controllers/MapOverviewController.cs index e4bfb98..d6c4d74 100644 --- a/SolarPower/Controllers/MapOverviewController.cs +++ b/SolarPower/Controllers/MapOverviewController.cs @@ -42,8 +42,7 @@ namespace SolarPower.Controllers MapOverview mapOverview = new MapOverview(); try { - MyPowerStationService myPowerStationService = new MyPowerStationService(powerStationRepository); - var myPowerStations = myPowerStationService.GetMyPowerStations(myUser); + var myPowerStations = myPowerStationService.GetMyPowerStationsGroupByCity(myUser); List powerStationIds = myPowerStations.SelectMany(x => x.MyPowerStations.Select(y => y.Id)).ToList(); diff --git a/SolarPower/Controllers/MyBaseController.cs b/SolarPower/Controllers/MyBaseController.cs index 69cfbef..64f4ef6 100644 --- a/SolarPower/Controllers/MyBaseController.cs +++ b/SolarPower/Controllers/MyBaseController.cs @@ -43,6 +43,7 @@ namespace SolarPower.Controllers public string baseURL => HttpContext?.Request.Scheme + "://" + HttpContext?.Request.Host + "/"; public ErrorCode errorCode = new ErrorCode(); + public MyPowerStationService myPowerStationService; public MyBaseController() { @@ -52,6 +53,8 @@ namespace SolarPower.Controllers { //base.OnActionExecuting(filterContext); + this.myPowerStationService = new MyPowerStationService(powerStationRepository); + EDFunction edFunction = new EDFunction(); var myAccount = edFunction.AESDecrypt(HttpContext.Session.GetString("MyAccount")); //取得登入後,該位使用者的Account @@ -133,7 +136,7 @@ namespace SolarPower.Controllers //取得當前使用者可以查看的電站 MyPowerStationService myPowerStationService = new MyPowerStationService(powerStationRepository); - var myPowerStations = myPowerStationService.GetMyPowerStations(myUser); + var myPowerStations = myPowerStationService.GetMyPowerStationsGroupByCity(myUser); //var myPowerStationSummaries = powerStationRepository.GetMyPowerStationSummary(myUser); myUser.myPowerStationGroupByCities = myPowerStations; ViewBag.myPowerStationGroupByCities = myPowerStations; diff --git a/SolarPower/Controllers/StationOverviewController.cs b/SolarPower/Controllers/StationOverviewController.cs index fea1d53..0cec799 100644 --- a/SolarPower/Controllers/StationOverviewController.cs +++ b/SolarPower/Controllers/StationOverviewController.cs @@ -4,6 +4,7 @@ using Newtonsoft.Json; using SolarPower.Models; using SolarPower.Models.PowerStation; using SolarPower.Repository.Interface; +using SolarPower.Services.Implement; using System; using System.Collections.Generic; using System.Globalization; @@ -36,52 +37,13 @@ namespace SolarPower.Controllers return View("~/Views/StationOverview/StationOverviewInfo.cshtml"); } - /// - /// 取得該使用者可看的所有電站分佈縣市以及各縣市電站數量 - /// - /// - [HttpPost] - public async Task>> GetSolarByCity(UseStatusCityGetPowerStation post) + public ApiResult> GetMyCities() { - ApiResult> apiResult = new ApiResult>(); - List solaramount = new List(); + ApiResult> apiResult = new ApiResult>(); try { apiResult.Code = "0000"; - solaramount = await overviewRepository.GetSolarByCity(myUser, post); - - foreach (var solar in solaramount) - { - //判斷該檔案是否存在 - if (!string.IsNullOrEmpty(solar.MainDisplay)) - { - var fullFilePath = Directory.GetCurrentDirectory() + "/wwwroot" + Path.Combine(stationImageFilePath, solar.Id.ToString()) + "/" + solar.MainDisplay; - if (System.IO.File.Exists(fullFilePath)) - { - solar.MainDisplay = Path.Combine(stationImageFilePath, solar.Id.ToString()) + "/" + solar.MainDisplay; - } - else - { - solar.MainDisplay = Path.Combine("img", "blank.gif"); - } - } - else - { - solar.MainDisplay = Path.Combine("img", "blank.gif"); - } - - - if (myUser.Role.Auths.Contains("ShowMoney")) - { - } - else - { - solar.Total_Money = 0; - solar.Today_Money = 0; - } - } - - apiResult.Data = solaramount; + apiResult.Data = myPowerStationService.GetMyCities(myUser); } catch (Exception exception) { @@ -92,6 +54,157 @@ namespace SolarPower.Controllers return apiResult; } + public ApiResult GetPowerStationByFilter(GetPowerStationsByFilter filter) + { + ApiResult apiResult = new ApiResult(); + StationOverview stationOverview = new StationOverview(); + try + { + var temp_status_where = $@" ps.HealthStatus IN ({string.Join(",", filter.Status)})"; + List where = new List(); + where.Add(temp_status_where); + + List order = new List(); + var temp_kwh_order_by = ""; + if (filter.KwhOrderBy == 0) + { + temp_kwh_order_by = @"Today_kwh DESC"; + } + else + { + temp_kwh_order_by = @"Today_kwh"; + } + order.Add(temp_kwh_order_by); + + var temp_pr_order_by = ""; + if (filter.PrOrderBy == 0) + { + temp_pr_order_by = @"today_PR DESC"; + } + else + { + temp_pr_order_by = @"today_PR"; + } + order.Add(temp_pr_order_by); + + var myPowerStations = myPowerStationService.GetMyPowerStations(myUser, filter.CityIds, where, order); + + foreach(var powerStation in myPowerStations) + { + //判斷該檔案是否存在 + if (!string.IsNullOrEmpty(powerStation.MainDisplay)) + { + var fullFilePath = Directory.GetCurrentDirectory() + "/wwwroot" + Path.Combine(stationImageFilePath, powerStation.Id.ToString()) + "/" + powerStation.MainDisplay; + if (System.IO.File.Exists(fullFilePath)) + { + powerStation.MainDisplay = Path.Combine(stationImageFilePath, powerStation.Id.ToString()) + "/" + powerStation.MainDisplay; + } + else + { + powerStation.MainDisplay = Path.Combine("img", "blank.gif"); + } + } + else + { + powerStation.MainDisplay = Path.Combine("img", "blank.gif"); + } + } + + stationOverview.PowerStations = myPowerStations; + + var temp_PowerStationsSummary = myPowerStationService.GetMyPowerStationsSummary(myPowerStations); + stationOverview.Today_kwh = temp_PowerStationsSummary.Today_kwh; + stationOverview.Total_kwh = temp_PowerStationsSummary.Total_kwh; + stationOverview.Today_irradiance = temp_PowerStationsSummary.Today_irradiance; + stationOverview.Avg_irradiance = temp_PowerStationsSummary.Avg_irradiance; + stationOverview.Today_PR = temp_PowerStationsSummary.Today_PR; + stationOverview.Avg_PR = temp_PowerStationsSummary.Avg_PR; + stationOverview.Today_kwhkwp = temp_PowerStationsSummary.Today_kwhkwp; + stationOverview.Avg_kwhkwp = temp_PowerStationsSummary.Avg_kwhkwp; + if (myUser.Role.Auths.Contains("ShowMoney")) + { + stationOverview.IsShowMoney = 1; + stationOverview.Today_money = temp_PowerStationsSummary.Today_money; + stationOverview.Total_money = temp_PowerStationsSummary.Total_money; + } + else + { + stationOverview.IsShowMoney = 0; + stationOverview.Today_money = 0; + stationOverview.Total_money = 0; + } + + stationOverview.Today_carbon = temp_PowerStationsSummary.Today_carbon; + stationOverview.Total_carbon = temp_PowerStationsSummary.Total_carbon; + + apiResult.Code = "0000"; + apiResult.Data = stationOverview; + } + catch(Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = exception.ToString(); + } + + return apiResult; + } + + /// + /// 取得該使用者可看的所有電站分佈縣市以及各縣市電站數量(old:改為統一Function 取得電站資訊而註解) + /// + /// + //[HttpPost] + //public async Task>> GetSolarByCity(UseStatusCityGetPowerStation post) + //{ + // ApiResult> apiResult = new ApiResult>(); + // List solaramount = new List(); + // try + // { + // apiResult.Code = "0000"; + // solaramount = await overviewRepository.GetSolarByCity(myUser, post); + + // foreach (var solar in solaramount) + // { + // //判斷該檔案是否存在 + // if (!string.IsNullOrEmpty(solar.MainDisplay)) + // { + // var fullFilePath = Directory.GetCurrentDirectory() + "/wwwroot" + Path.Combine(stationImageFilePath, solar.Id.ToString()) + "/" + solar.MainDisplay; + // if (System.IO.File.Exists(fullFilePath)) + // { + // solar.MainDisplay = Path.Combine(stationImageFilePath, solar.Id.ToString()) + "/" + solar.MainDisplay; + // } + // else + // { + // solar.MainDisplay = Path.Combine("img", "blank.gif"); + // } + // } + // else + // { + // solar.MainDisplay = Path.Combine("img", "blank.gif"); + // } + + + // if (myUser.Role.Auths.Contains("ShowMoney")) + // { + // } + // else + // { + // solar.Total_Money = 0; + // solar.Today_Money = 0; + // } + // } + + // apiResult.Data = solaramount; + // } + // catch (Exception exception) + // { + // apiResult.Code = "9999"; + // apiResult.Msg = exception.ToString(); + // } + + // return apiResult; + //} + [HttpPost] public ApiResult> GetPowerStationCollapse(string filter) { diff --git a/SolarPower/Models/MyBaseModel.cs b/SolarPower/Models/MyBaseModel.cs index 9789881..400ba06 100644 --- a/SolarPower/Models/MyBaseModel.cs +++ b/SolarPower/Models/MyBaseModel.cs @@ -83,6 +83,14 @@ namespace SolarPower.Models public string Name { get; set; } } + public class MyCity + { + public int CityId { get; set; } + public string CityName { get; set; } + public int Amount { get; set; } + + } + public class MyPowerStationGroupByCity { public string CityName { get; set; } diff --git a/SolarPower/Models/Overview.cs b/SolarPower/Models/Overview.cs index fd8ac40..c066e52 100644 --- a/SolarPower/Models/Overview.cs +++ b/SolarPower/Models/Overview.cs @@ -47,6 +47,14 @@ namespace SolarPower.Models public int PrOrder { get; set; } } + public class GetPowerStationsByFilter + { + public List CityIds { get; set; } + public List Status { get; set; } //狀態 + public int KwhOrderBy { get; set; } + public int PrOrderBy { get; set; } + } + public class StationIds { public List Ids { get; set; } @@ -63,6 +71,7 @@ namespace SolarPower.Models public string StationName { get; set; } public string CityName { get; set; } public byte HealthStatus { get; set; } + public List PowerStations { get; set; } } public class ChartUptoDate diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index 1964837..0d0e994 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -23,6 +23,45 @@ namespace SolarPower.Repository.Implement tableName = "power_station"; } + public List GetMyCities(MyUser myUser) + { + var results = new List(); + + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + try + { + var sql = @"SELECT c.Id AS CityId, c.Name AS CityName, COUNT(*) AS Amount + FROM power_station ps + LEFT JOIN city c ON ps.CityId = c.Id"; + + if (myUser.Role.Layer == (int)RoleLayerEnum.CompanyAdmin) + { //公司管理員 + sql += @" WHERE ps.Deleted = 0 AND ps.CompanyId = @CompanyId"; + } + else if (myUser.Role.Layer == (int)RoleLayerEnum.PlatformUser || myUser.Role.Layer == (int)RoleLayerEnum.CompanyUser) + { + sql += @" LEFT JOIN power_station_operation_personnel op ON ps.Id = op.PowerStationId + WHERE ps.Deleted = 0 AND op.Deleted = 0 AND op.UserId = @UserId "; + } + else + { + sql += @" WHERE ps.Deleted = 0"; + } + + sql += @" GROUP BY c.Id ORDER BY c.Priority"; + + results = conn.Query(sql, new { CompanyId = myUser.CompanyId, UserId = myUser.Id }).ToList(); + + } + catch (Exception exception) + { + throw exception; + } + return results; + } + } + public List GetMyPowerStationList(MyUser myUser, List cityIds, List wheres = null, List orderBy = null) { var results = new List(); @@ -58,14 +97,14 @@ namespace SolarPower.Repository.Implement { var temp_where = ""; temp_where = string.Join(" AND ", wheres); - sql += string.Join(" AND ", wheres); + sql += " AND " + string.Join(" AND ", wheres); } if (orderBy != null && orderBy.Count > 0) { var temp_order = ""; temp_order = string.Join(" , ", orderBy); - sql += $" ORDER BY c.Priority, {temp_order}"; + sql += $" ORDER BY {temp_order}"; } else { @@ -83,7 +122,6 @@ namespace SolarPower.Repository.Implement } } - //public List GetMyPowerStationSummary(MyUser myUser, string filter = "") //{ // List results = new List(); diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index 26396f7..1e6a5fc 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -11,6 +11,12 @@ namespace SolarPower.Repository.Interface { public interface IPowerStationRepository : IRepositoryBase { + /// + /// 取得當前使用者可操作電站的縣市 + /// + /// + /// + List GetMyCities(MyUser myUser); /// /// 取得當前使用者可操作的電站 diff --git a/SolarPower/Services/Implement/MyPowerStationService.cs b/SolarPower/Services/Implement/MyPowerStationService.cs index 848e274..6cba7a0 100644 --- a/SolarPower/Services/Implement/MyPowerStationService.cs +++ b/SolarPower/Services/Implement/MyPowerStationService.cs @@ -17,7 +17,24 @@ namespace SolarPower.Services.Implement this.powerStationRepository = powerStationRepository; } - public List GetMyPowerStations(MyUser myUser, List cityIds = null, List wheres = null, List orderBy = null) + public List GetMyCities(MyUser myUser) + { + List myCities = new List(); + + myCities = powerStationRepository.GetMyCities(myUser); + + return myCities; + } + + public List GetMyPowerStations(MyUser myUser, List cityIds = null, List wheres = null, List orderBy = null) + { + List powerStations = new List(); + powerStations = powerStationRepository.GetMyPowerStationList(myUser, cityIds, wheres, orderBy); + + return powerStations; + } + + public List GetMyPowerStationsGroupByCity(MyUser myUser, List cityIds = null, List wheres = null, List orderBy = null) { List powerStations = new List(); diff --git a/SolarPower/Views/StationOverview/Index.cshtml b/SolarPower/Views/StationOverview/Index.cshtml index 6f82410..44db5c6 100644 --- a/SolarPower/Views/StationOverview/Index.cshtml +++ b/SolarPower/Views/StationOverview/Index.cshtml @@ -39,15 +39,15 @@
      - +
      - +
      - +
      @@ -93,6 +93,22 @@
      +
      +
      +

      發電金額

      +
      NTD
      +
      +
      +
      +

      總發金額

      +

      0.00

      +
      +
      +

      今日發電金額

      +

      0.00

      +
      +
      +

      日照度

      @@ -189,7 +205,7 @@
      @if (ViewBag.myUser.Role.Auths.Contains("ShowMoney")) { -

      發電金額

      +

      發電金額

      2,5840 NT

      }

      65

      @@ -310,7 +326,29 @@ $(function () { status123 = []; - var Nurl = "/PowerStation/GetSolarCitySummary"; + var city_url = "/StationOverview/GetMyCities"; + $.post(city_url, function (rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + return; + } + + $('#citytest').empty(); + for (var i = 0; i < rel.data.length; i++) { + $('#citytest').append(""); + ids.push(rel.data[i].cityId); + Allids.push(rel.data[i].cityId); + } + + getStation(ids); + }, 'json'); + + + + @*var Nurl = "/PowerStation/GetSolarCitySummary"; $.post(Nurl, function (rel) { if (rel.code != "0000") { toast_error(rel.msg); @@ -329,7 +367,7 @@ status123.push(2); status123.push(3); getStation(ids); - }, 'json'); + }, 'json');*@ }); @@ -350,19 +388,31 @@ }) function getStation(ids) { - var kwh = $('#kwh_order').val(); + @*var kwh = $('#kwh_order').val(); var pr = $('#pr_order').val(); var send_data = { cityid: ids, status: status123, kwhOrder: kwh, prOrder: pr - }; - ids.sort(function (a, b) { + };*@ + + var selectedStatus = $("input[name='powerStationStatus[]']:checked").map(function () { + return $(this).val(); + }).get(); + + var send_data = { + cityIds: ids, + status: selectedStatus, + kwhOrderBy: $('#kwh_order').val(), + prOrderBy: $('#pr_order').val() + } + + @*ids.sort(function (a, b) { return a - b; }); - ids.sort(); - if (ids.length == 0 || status123.length == 0) { + ids.sort();*@ + if (ids.length == 0 || selectedStatus.length == 0) { $('#areaCard').empty(); $('#solarTable').find('tbody').empty(); $("#today_kwh").html(0); @@ -379,7 +429,7 @@ $("#update_at").html(0); } else { - var Nurl = "/StationOverview/GetSolarByCity"; + var Nurl = "/StationOverview/GetPowerStationByFilter"; $.post(Nurl, send_data, function (rel) { if (rel.code != "0000") { toast_error(rel.msg); @@ -388,7 +438,7 @@ $('#areaCard').empty(); $('#solarTable').find('tbody').empty(); powerids = []; - $.each(rel.data, function (index, val) { + $.each(rel.data.powerStations, function (index, val) { $('#templateCard').find('.col-xl-3').clone().attr('id', 'card_' + val.id).appendTo($('#areaCard')); var statusicon; switch (val.healthStatus) { @@ -462,13 +512,13 @@ ''); }); - GetStationCard(); + GetStationCard(rel.data); }, 'json'); } } - function GetStationCard() { - var send_data = { + function GetStationCard(powerStationSummary) { + @*var send_data = { ids: powerids }; var url = "/StationOverview/GetStationCard"; @@ -490,7 +540,22 @@ $("#total_power_station_count").html(mapOverview.totalPowerStationCount); $("#total_capacity").html(mapOverview.totalCapacity.toFixed(2)); $("#update_at").html(mapOverview.updatedAt); - }); + });*@ + + + $("#today_kwh").html(powerStationSummary.today_kwh.toFixed(2)); + $("#total_kwh").html(powerStationSummary.total_kwh.toFixed(2)); + $("#today_irradiance").html(powerStationSummary.today_irradiance.toFixed(2)); + $("#avg_irradiance").html(powerStationSummary.avg_irradiance.toFixed(2)); + $("#today_PR").html(powerStationSummary.today_PR.toFixed(2)); + $("#avg_PR").html(powerStationSummary.avg_PR.toFixed(2)); + $("#today_kwhkwp").html(powerStationSummary.today_kwhkwp.toFixed(2)); + $("#avg_kwhkwp").html(powerStationSummary.avg_kwhkwp.toFixed(2)); + $("#today_carbon").html(powerStationSummary.today_carbon.toFixed(2)); + $("#total_carbon").html(powerStationSummary.total_carbon.toFixed(2)); + $("#today_carbon").html(powerStationSummary.today_carbon.toFixed(2)); + $("#total_carbon").html(powerStationSummary.total_carbon.toFixed(2)); + $("#update_at").html(powerStationSummary.updatedAt); } //#region 選擇狀態checkbox From e958ebf91865dec53209f79668bc22d3fecd0a5f Mon Sep 17 00:00:00 2001 From: Kai Date: Wed, 1 Sep 2021 17:19:20 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=9B=BB=E7=AB=99?= =?UTF-8?q?=E6=8A=93=E5=8F=96=E6=96=B9=E5=BC=8F=20part4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SolarPower/Views/StationOverview/Index.cshtml | 175 ++++++++---------- 1 file changed, 82 insertions(+), 93 deletions(-) diff --git a/SolarPower/Views/StationOverview/Index.cshtml b/SolarPower/Views/StationOverview/Index.cshtml index 44db5c6..6957402 100644 --- a/SolarPower/Views/StationOverview/Index.cshtml +++ b/SolarPower/Views/StationOverview/Index.cshtml @@ -34,7 +34,7 @@
      - +
      @@ -74,103 +74,85 @@
      -
      -
      -
      -
      -
      -

      發電量

      -
      kW h
      +
      +
      +
      +
      +

      發電量

      +
      kW h
      +
      +
      +
      +

      今日發電量

      +

      0.00

      -
      -
      -

      今日發電量

      -

      0.00

      -
      -
      -

      累積發電量

      -

      0.00

      -
      +
      +

      累積發電量

      +

      0.00

      -
      -
      -

      發電金額

      -
      NTD
      +
      +
      +
      +

      日照度

      +
      k W/㎡
      +
      +
      +
      +

      即時平均日照度

      +

      0.00

      -
      -
      -

      總發金額

      -

      0.00

      -
      -
      -

      今日發電金額

      -

      0.00

      -
      +
      +

      平均日照度(30天)

      +

      0.00

      -
      -
      -

      日照度

      -
      k W/㎡
      +
      +
      +
      +

      PR值

      +
      %
      +
      +
      +
      +

      即時平均 PR 值

      +

      0.00

      -
      -
      -

      即時平均日照度

      -

      0.00

      -
      -
      -

      平均日照度(30天)

      -

      0.00

      -
      +
      +

      平均 PR 值(30天)

      +

      0.00

      -
      -
      -

      PR值

      -
      %
      +
      +
      +
      +

      有效日照時數

      +
      hr
      +
      +
      +
      +

      即時平均有效日照時數

      +

      0.00

      -
      -
      -

      即時平均 PR 值

      -

      0.00

      -
      -
      -

      平均 PR 值(30天)

      -

      0.00

      -
      +
      +

      平均有效日照時數(30天)

      +

      0.00

      -
      -
      -

      有效日照時數

      -
      hr
      -
      -
      -
      -

      即時平均有效日照時數

      -

      0.00

      -
      -
      -

      平均有效日照時數(30天)

      -

      0.00

      -
      -
      +
      +
      +
      +

      減碳量

      +
      kG
      -
      -
      -

      減碳量

      -
      kG
      +
      +
      +

      今日減碳量

      +

      0.00

      -
      -
      -

      今日減碳量

      -

      0.00

      -
      -
      -

      累積減碳量

      -

      0.00

      -
      +
      +

      累積減碳量

      +

      0.00

      @@ -346,7 +328,7 @@ getStation(ids); }, 'json'); - + @*var Nurl = "/PowerStation/GetSolarCitySummary"; $.post(Nurl, function (rel) { @@ -542,7 +524,6 @@ $("#update_at").html(mapOverview.updatedAt); });*@ - $("#today_kwh").html(powerStationSummary.today_kwh.toFixed(2)); $("#total_kwh").html(powerStationSummary.total_kwh.toFixed(2)); $("#today_irradiance").html(powerStationSummary.today_irradiance.toFixed(2)); @@ -553,14 +534,12 @@ $("#avg_kwhkwp").html(powerStationSummary.avg_kwhkwp.toFixed(2)); $("#today_carbon").html(powerStationSummary.today_carbon.toFixed(2)); $("#total_carbon").html(powerStationSummary.total_carbon.toFixed(2)); - $("#today_carbon").html(powerStationSummary.today_carbon.toFixed(2)); - $("#total_carbon").html(powerStationSummary.total_carbon.toFixed(2)); $("#update_at").html(powerStationSummary.updatedAt); } //#region 選擇狀態checkbox $('#CheckStatus').on("click", "input", function () { - var clickid = $(this).attr('id'); + @*var clickid = $(this).attr('id'); var classid = clickid.split("_"); var job = document.getElementById(clickid); if (job.checked == true) { @@ -568,7 +547,7 @@ } else { status123.remove(Number(classid[1])); - } + }*@ getStation(ids); }) //#endregion @@ -606,8 +585,8 @@ //#endregion //#region 狀態全選 - function AllStatus() { - status123 = []; + $("#status-all-check").click(function (e) { + @* status123 =[]; if (StatusType) { for (var i = 1; i <= 3; i++) { @@ -620,9 +599,19 @@ status123.push(i); } StatusType = true; + }*@ + + var checked = $(this).attr("data-checked"); + if (checked) { + $(this).attr("data-checked", false); + $("input[name='powerStationStatus[]']").prop('checked', false); + } + else { + $(this).attr("data-checked", true); + $("input[name='powerStationStatus[]']").prop('checked', true); } getStation(ids); - } + }); //#endregion function CardDisplay() { From 7fa16df8fe265801421624cd8d2b1209eb4d1168 Mon Sep 17 00:00:00 2001 From: Kai Date: Thu, 2 Sep 2021 14:30:46 +0800 Subject: [PATCH 5/5] =?UTF-8?q?1.=20=E4=BF=AE=E6=94=B9=E9=9B=BB=E7=AB=99?= =?UTF-8?q?=E6=8A=93=E5=8F=96=E6=96=B9=E5=BC=8F=20part4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AnalysisInverterController.cs | 10 +- .../AnalysisStationCombineController.cs | 44 +- .../AnalysisStationInfoController.cs | 10 +- .../Controllers/ExceptionRecordController.cs | 39 ++ SolarPower/Controllers/MyBaseController.cs | 9 +- SolarPower/Controllers/OperationController.cs | 37 ++ .../Controllers/PowerGenerationController.cs | 44 ++ .../Controllers/StationOverviewController.cs | 2 +- .../Controllers/StationReportController.cs | 66 +-- .../Implement/OperationRepository.cs | 52 ++- .../Implement/PowerStationRepository.cs | 139 +++--- .../Interface/IPowerStationRepository.cs | 4 +- .../Implement/MyPowerStationService.cs | 8 +- .../Views/AnalysisStationCombine/Index.cshtml | 35 +- .../Views/ElectricitySoldRecord/Index.cshtml | 10 +- SolarPower/Views/ExceptionRecord/Index.cshtml | 433 ++++++++++-------- SolarPower/Views/NoticeSchedule/Index.cshtml | 10 +- SolarPower/Views/Operation/Index.cshtml | 102 ++++- .../Views/Operation/OperationRecord.cshtml | 127 ++++- SolarPower/Views/PowerGeneration/Index.cshtml | 10 +- SolarPower/Views/StationReport/Index.cshtml | 10 +- 21 files changed, 737 insertions(+), 464 deletions(-) diff --git a/SolarPower/Controllers/AnalysisInverterController.cs b/SolarPower/Controllers/AnalysisInverterController.cs index 6590fe8..5676990 100644 --- a/SolarPower/Controllers/AnalysisInverterController.cs +++ b/SolarPower/Controllers/AnalysisInverterController.cs @@ -32,14 +32,8 @@ namespace SolarPower.Controllers try { var powerStations = new List(); - if (IsPlatformLayer(myUser.Role.Layer)) - { - powerStations = await powerStationRepository.GetAllAsync(); - } - else - { - powerStations = await powerStationRepository.GetPowerStationsByCompanyId(myUser); - } + + powerStations = myPowerStationService.GetMyPowerStations(myUser); var siteDBNamePowerStationId = new Dictionary>(); diff --git a/SolarPower/Controllers/AnalysisStationCombineController.cs b/SolarPower/Controllers/AnalysisStationCombineController.cs index 39277ca..9d5e7e4 100644 --- a/SolarPower/Controllers/AnalysisStationCombineController.cs +++ b/SolarPower/Controllers/AnalysisStationCombineController.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using SolarPower.Models; +using SolarPower.Models.PowerStation; using SolarPower.Repository.Interface; using System; using System.Collections.Generic; @@ -27,6 +28,45 @@ namespace SolarPower.Controllers return View(); } + public ApiResult>> GetPowerStationCollapse(string filter) + { + ApiResult>> apiResult = new ApiResult>>(); + + try + { + List where = new List(); + Dictionary where_entities = new Dictionary(); + if (!string.IsNullOrEmpty(filter)) + { + var temp_psname_where = $@" ps.Name LIKE CONCAT('%', @Filter, '%')"; + where.Add(temp_psname_where); + + where_entities.Add("Filter", filter); + } + + var myPowerStations = myPowerStationService.GetMyPowerStationsGroupByCity(myUser, null, where, where_entities); + + var siteDBNamePowerStationId = new Dictionary>(); + foreach (var powerStation in myPowerStations) + { + siteDBNamePowerStationId.Add(powerStation.CityName, powerStation.MyPowerStations.ToList()); + } + + apiResult.Code = "0000"; + + apiResult.Data = siteDBNamePowerStationId; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + Logger.LogError("【" + controllerName + "/" + actionName + "】"); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + public async Task> GetStationsCard(ChartInput post) { ApiResult apiResult = new ApiResult(); @@ -44,14 +84,14 @@ namespace SolarPower.Controllers apiResult.Msg = errorCode.GetString(apiResult.Code); } - + return apiResult; } public async Task>> GetChart(ChartInput post) { ApiResult> apiResult = new ApiResult>(); - + try { var GetCharts = new List(); diff --git a/SolarPower/Controllers/AnalysisStationInfoController.cs b/SolarPower/Controllers/AnalysisStationInfoController.cs index ddc85fa..0937a73 100644 --- a/SolarPower/Controllers/AnalysisStationInfoController.cs +++ b/SolarPower/Controllers/AnalysisStationInfoController.cs @@ -32,14 +32,8 @@ namespace SolarPower.Controllers try { var powerStations = new List(); - if (myUser.Role.Layer == (int)RoleLayerEnum.PlatformAdmin) - { - powerStations = await powerStationRepository.GetAllAsync(); - } - else - { - powerStations = await powerStationRepository.GetPowerStationsByCompanyId(myUser); - } + + powerStations = myPowerStationService.GetMyPowerStations(myUser); var siteDBNamePowerStationId = new Dictionary>(); diff --git a/SolarPower/Controllers/ExceptionRecordController.cs b/SolarPower/Controllers/ExceptionRecordController.cs index 34fc682..0fbcc82 100644 --- a/SolarPower/Controllers/ExceptionRecordController.cs +++ b/SolarPower/Controllers/ExceptionRecordController.cs @@ -1,4 +1,6 @@ using Microsoft.AspNetCore.Mvc; +using SolarPower.Models; +using SolarPower.Models.PowerStation; using System; using System.Collections.Generic; using System.Linq; @@ -12,5 +14,42 @@ namespace SolarPower.Controllers { return View(); } + + public ApiResult> GetMyCities() + { + ApiResult> apiResult = new ApiResult>(); + try + { + apiResult.Code = "0000"; + apiResult.Data = myPowerStationService.GetMyCities(myUser); + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = exception.ToString(); + } + + return apiResult; + } + + public ApiResult> GetPowerStationByFilter(List cityIds) + { + ApiResult> apiResult = new ApiResult>(); + try + { + + var myPowerStations = myPowerStationService.GetMyPowerStations(myUser, cityIds); + + apiResult.Code = "0000"; + apiResult.Data = myPowerStations; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = exception.ToString(); + } + + return apiResult; + } } } diff --git a/SolarPower/Controllers/MyBaseController.cs b/SolarPower/Controllers/MyBaseController.cs index 64f4ef6..8804bb1 100644 --- a/SolarPower/Controllers/MyBaseController.cs +++ b/SolarPower/Controllers/MyBaseController.cs @@ -60,7 +60,7 @@ namespace SolarPower.Controllers controllerName = ControllerContext.RouteData.Values["controller"].ToString(); //controller名稱 actionName = ControllerContext.RouteData.Values["action"].ToString(); //action名稱 - + bool isAjaxCall = filterContext.HttpContext.Request.Headers["x-requested-with"] == "XMLHttpRequest"; if (string.IsNullOrEmpty(myAccount)) @@ -110,14 +110,17 @@ namespace SolarPower.Controllers } } - if (myUser.Role.Layer != (int)RoleLayerEnum.PlatformAdmin && !auth_arr.Contains(controllerName)) + //只排除畫面的情況 + var judgeActionName = new List() { "Index", "Info", "Record", "Edit" }; + + if (myUser.Role.Layer != (int)RoleLayerEnum.PlatformAdmin && !auth_arr.Contains(controllerName) && judgeActionName.Contains(actionName)) { //排除條件 if (auth_arr.Contains("StationOverview") && !auth_arr.Contains("PowerStation")) { //只有電站總覽 且未包含 電站管理 } - else if(controllerName == "User" && (actionName == "ChangePassword" || actionName == "GetPersonalInfo" || actionName == "SavePersonalInfo")) + else if (controllerName == "User" && (actionName == "ChangePassword" || actionName == "GetPersonalInfo" || actionName == "SavePersonalInfo")) { //查詢個人 資訊 及密碼 } diff --git a/SolarPower/Controllers/OperationController.cs b/SolarPower/Controllers/OperationController.cs index b3150f6..9028842 100644 --- a/SolarPower/Controllers/OperationController.cs +++ b/SolarPower/Controllers/OperationController.cs @@ -44,6 +44,43 @@ namespace SolarPower.Controllers return View("~/Views/Operation/OperationRecord.cshtml"); } + public ApiResult> GetMyCities() + { + ApiResult> apiResult = new ApiResult>(); + try + { + apiResult.Code = "0000"; + apiResult.Data = myPowerStationService.GetMyCities(myUser); + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = exception.ToString(); + } + + return apiResult; + } + + public ApiResult> GetPowerStationByFilter(List cityIds) + { + ApiResult> apiResult = new ApiResult>(); + try + { + + var myPowerStations = myPowerStationService.GetMyPowerStations(myUser, cityIds); + + apiResult.Code = "0000"; + apiResult.Data = myPowerStations; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = exception.ToString(); + } + + return apiResult; + } + /// /// 取得電站Option /// diff --git a/SolarPower/Controllers/PowerGenerationController.cs b/SolarPower/Controllers/PowerGenerationController.cs index 4260536..ee21639 100644 --- a/SolarPower/Controllers/PowerGenerationController.cs +++ b/SolarPower/Controllers/PowerGenerationController.cs @@ -31,6 +31,50 @@ namespace SolarPower.Controllers return View(); } + [HttpPost] + public ApiResult>> GetPowerStationCollapse(string filter) + { + ApiResult>> apiResult = new ApiResult>>(); + try + { + List where = new List(); + Dictionary where_entities = new Dictionary(); + if (!string.IsNullOrEmpty(filter)) + { + var temp_psname_where = $@" ps.Name LIKE CONCAT('%', @Filter, '%')"; + where.Add(temp_psname_where); + + where_entities.Add("Filter", filter); + } + + var temp_solartype_where = @" ps.SolarType = 0"; + where.Add(temp_solartype_where); + + var powerStations = myPowerStationService.GetMyPowerStations(myUser, null, where, where_entities); + + var siteDBNamePowerStationId = new Dictionary>(); + + var powerStation_Group = powerStations.GroupBy(x => x.CityName).ToList(); + foreach (var stations in powerStation_Group) + { + siteDBNamePowerStationId.Add(stations.Key, stations.ToList()); + } + + apiResult.Code = "0000"; + + apiResult.Data = siteDBNamePowerStationId; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + Logger.LogError("【" + controllerName + "/" + actionName + "】"); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + [HttpPost] public async Task>> GetGenerationList (SearchGeneration post) { diff --git a/SolarPower/Controllers/StationOverviewController.cs b/SolarPower/Controllers/StationOverviewController.cs index 0cec799..e601e24 100644 --- a/SolarPower/Controllers/StationOverviewController.cs +++ b/SolarPower/Controllers/StationOverviewController.cs @@ -87,7 +87,7 @@ namespace SolarPower.Controllers } order.Add(temp_pr_order_by); - var myPowerStations = myPowerStationService.GetMyPowerStations(myUser, filter.CityIds, where, order); + var myPowerStations = myPowerStationService.GetMyPowerStations(myUser, filter.CityIds, where, null, order); foreach(var powerStation in myPowerStations) { diff --git a/SolarPower/Controllers/StationReportController.cs b/SolarPower/Controllers/StationReportController.cs index 23895fc..c4ea28b 100644 --- a/SolarPower/Controllers/StationReportController.cs +++ b/SolarPower/Controllers/StationReportController.cs @@ -36,25 +36,25 @@ namespace SolarPower.Controllers return View(); } - - [HttpPost] - public async Task>>> GetPowerStationNameList(string filter) + public ApiResult>> GetPowerStationCollapse(string filter) { - ApiResult>> apiResult = new ApiResult>>(); + ApiResult>> apiResult = new ApiResult>>(); try { - var powerStations = new List(); - if (IsPlatformLayer(myUser.Role.Layer)) + List where = new List(); + Dictionary where_entities = new Dictionary(); + if (!string.IsNullOrEmpty(filter)) { - powerStations = await powerStationRepository.GetPowerStationsAllWithfilter(filter); - } - else - { - powerStations = await powerStationRepository.GetPowerStationsByCompanyIdWithfilter(myUser,filter); + var temp_psname_where = $@" ps.Name LIKE CONCAT('%', @Filter, '%')"; + where.Add(temp_psname_where); + + where_entities.Add("Filter", filter); } - var siteDBNamePowerStationId = new Dictionary>(); + var powerStations = myPowerStationService.GetMyPowerStations(myUser, null, where, where_entities); + + var siteDBNamePowerStationId = new Dictionary>(); var powerStation_Group = powerStations.GroupBy(x => x.CityName).ToList(); foreach (var stations in powerStation_Group) @@ -77,48 +77,6 @@ namespace SolarPower.Controllers return apiResult; } - - [HttpPost] - public async Task>>> GetPowerStationNameListForGeneration(string filter) - { - ApiResult>> apiResult = new ApiResult>>(); - try - { - var powerStations = new List(); - if (IsPlatformLayer(myUser.Role.Layer)) - { - powerStations = await powerStationRepository.GetPowerStationsAllWithfilterForGeneration(filter); - } - else - { - powerStations = await powerStationRepository.GetPowerStationsByCompanyIdWithfilterForGeneration(myUser, filter); - } - - var siteDBNamePowerStationId = new Dictionary>(); - - var powerStation_Group = powerStations.GroupBy(x => x.CityName).ToList(); - foreach (var stations in powerStation_Group) - { - siteDBNamePowerStationId.Add(stations.Key, stations.ToList()); - } - - apiResult.Code = "0000"; - - apiResult.Data = siteDBNamePowerStationId; - } - catch (Exception exception) - { - apiResult.Code = "9999"; - Logger.LogError("【" + controllerName + "/" + actionName + "】"); - Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); - } - - apiResult.Msg = errorCode.GetString(apiResult.Code); - return apiResult; - } - - - public async Task> GetTableHead(Select_table post) { ApiResult apiResult = new ApiResult(); diff --git a/SolarPower/Repository/Implement/OperationRepository.cs b/SolarPower/Repository/Implement/OperationRepository.cs index 17e4b7b..c752ecf 100644 --- a/SolarPower/Repository/Implement/OperationRepository.cs +++ b/SolarPower/Repository/Implement/OperationRepository.cs @@ -60,29 +60,41 @@ namespace SolarPower.Repository.Implement } public async Task> OperationPlanTable(List id, int Type) { - List result; + List result = new List(); var count = 0; - string Wheresql = "oc.PowerStationId = "; - if (id.Count > 0) + + string Wheresql = ""; + if (id.Count() <= 0) { - foreach (int too in id) - { - - if (count == id.Count - 1) - { - Wheresql += too.ToString(); - } - else - { - Wheresql += too.ToString() + " OR oc.PowerStationId = "; - } - count++; - } - + return result; } - else + //if (id.Count > 0) + //{ + // foreach (int too in id) + // { + + // if (count == id.Count - 1) + // { + // Wheresql += too.ToString(); + // } + // else + // { + // Wheresql += too.ToString() + " OR oc.PowerStationId = "; + // } + // count++; + // } + + //} + //else + //{ + // Wheresql += "0"; + //} + + + if (id.Count() > 0) { - Wheresql += "0"; + var temp_sql = string.Join(',', id); + Wheresql = $"oc.PowerStationId IN ({temp_sql}) "; } using (IDbConnection conn = this._databaseHelper.GetConnection()) @@ -206,7 +218,7 @@ namespace SolarPower.Repository.Implement try { string where = ""; - if(filter.Status == 2 ) + if (filter.Status == 2) { where = $"opr.Deleted = 1 "; } diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index 65b0380..268d804 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -62,7 +62,7 @@ namespace SolarPower.Repository.Implement } } - public List GetMyPowerStationList(MyUser myUser, List cityIds, List wheres = null, List orderBy = null) + public List GetMyPowerStationList(MyUser myUser, List cityIds, List wheres = null, Dictionary where_entities = null, List orderBy = null) { var results = new List(); @@ -88,7 +88,7 @@ namespace SolarPower.Repository.Implement sql += @" WHERE ps.Deleted = 0"; } - if(cityIds != null && cityIds.Count > 0) + if (cityIds != null) { sql += @" AND c.Id IN @CityIds"; } @@ -111,7 +111,20 @@ namespace SolarPower.Repository.Implement sql += $" ORDER BY c.Priority"; } - results = conn.Query(sql, new { CompanyId = myUser.CompanyId, UserId = myUser.Id, CityIds = cityIds }).ToList(); + Dictionary pairs = new Dictionary(); + pairs.Add("CompanyId", myUser.CompanyId); + pairs.Add("UserId", myUser.Id); + pairs.Add("CityIds", cityIds); + + if (where_entities != null && where_entities.Count() > 0) + { + foreach (var entity in where_entities) + { + pairs.Add(entity.Key, entity.Value); + } + } + + results = conn.Query(sql, pairs).ToList(); } catch (Exception exception) @@ -2654,20 +2667,37 @@ namespace SolarPower.Repository.Implement { try { - var sql = $@"SELECT - PowerStationId, - DATE_FORMAT(p.TIMESTAMP, '%Y-%m-%d') AS TIMESTAMP, - AVG(p.Irradiance) AS Irradiance, - AVG(p.Temperature) AS Temperature, - AVG(p.EnvTemperature) AS EnvTemperature, - AVG(p.Humidity) AS Humidity, - AVG(p.Vane) AS Vane, - AVG(p.Dust) AS Dust - FROM sensor_history_hour p - WHERE DATE_FORMAT(p.TIMESTAMP, '%Y-%m-%d') = @NowDay - AND PowerStationId = @PowerStationId - GROUP BY DATE_FORMAT(p.TIMESTAMP, '%Y-%m-%d') - "; + //var sql = $@"SELECT + // PowerStationId, + // DATE_FORMAT(p.TIMESTAMP, '%Y-%m-%d') AS TIMESTAMP, + // AVG(p.Irradiance) AS Irradiance, + // AVG(p.Temperature) AS Temperature, + // AVG(p.EnvTemperature) AS EnvTemperature, + // AVG(p.Humidity) AS Humidity, + // AVG(p.Vane) AS Vane, + // AVG(p.Dust) AS Dust + // FROM sensor_history_hour p + // WHERE DATE_FORMAT(p.TIMESTAMP, '%Y-%m-%d') = @NowDay + // AND PowerStationId = @PowerStationId + // GROUP BY DATE_FORMAT(p.TIMESTAMP, '%Y-%m-%d') + // "; + + //TODO + var sql = $@" select a.powerstationID, a.reportdate, ifnull(b.Irradiance, 0) irrAvg, a.Temperature, a.envTemperature, a.humidity, a.Vane, a.Dust from + ( + select powerStationID , concat(DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d'), ' 00:00') reportdate, round(avg(Temperature), 6) Temperature, + envTemperature, humidity, Vane, Dust + from solar_master.sensor_history_hour + where PowerStationId = @PowerStationId and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @NowDay + group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') + ) a left join + ( -- 日照計 + select concat(DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d'), ' 00:00') reportdate, round(avg(Irradiance), 2) Irradiance + from solar_master.sensor_history_hour + where PowerStationId = @PowerStationId + and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @NowDay and Irradiance <> 0 #需要過濾 0 的數值 + group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') + )b on a.reportdate = b.reportdate"; result = await conn.QueryFirstOrDefaultAsync(sql, new { NowDay = nowDay, PowerStationId = powerStationId }); } @@ -3115,7 +3145,7 @@ namespace SolarPower.Repository.Implement AVG(inv.DC5A) AS DC5A, AVG(inv.DC5W) AS DC5W, AVG(inv.DC5WH) AS DC5WH, - AVG(inv.PR) AS PR, + MAX(inv.PR) AS PR, AVG(inv.RA1) AS RA1, AVG(inv.RA2) AS RA2, AVG(inv.RA3) AS RA3, @@ -3123,7 +3153,8 @@ namespace SolarPower.Repository.Implement AVG(inv.RA5) AS RA5, SUM(inv.KWH) AS KWH, MAX(inv.TODAYKWH) AS TODAYKWH, - MAX(inv.TODAYKWH) / i.Capacity AS KWHKWP + MAX(inv.TOTALKWH) AS TOTALKWH, + SUM(inv.KWH) / i.Capacity AS KWHKWP FROM inverter_history_hour inv LEFT JOIN {db_name}.inverter i ON CONCAT('s', inv.INVERTERID) = i.InverterId WHERE DATE_FORMAT(inv.TIMESTAMP, '%Y-%m-%d') = @NowDay @@ -3251,8 +3282,9 @@ namespace SolarPower.Repository.Implement AVG(inv.RA4) AS RA4, AVG(inv.RA5) AS RA5, SUM(inv.KWH) AS KWH, - SUM(inv.TODAYKWH) AS TODAYKWH, - SUM(inv.TODAYKWH) / i.Capacity AS KWHKWP + AVG(inv.TODAYKWH) AS TODAYKWH, + MAX(inv.TOTALKWH) AS TOTALKWH + SUM(inv.KWH) / i.Capacity AS KWHKWP FROM inverter_history_day inv LEFT JOIN {db_name}.inverter i ON CONCAT('s', inv.INVERTERID) = i.InverterId WHERE DATE_FORMAT(inv.TIMESTAMP, '%Y-%m') = @Month @@ -5274,71 +5306,6 @@ namespace SolarPower.Repository.Implement } } - - public async Task> GetPowerStationsAllWithfilterForGeneration(string filter) - { - List result; - using (IDbConnection conn = this._databaseHelper.GetConnection()) - { - try - { - var sql = @$"SELECT ps.Id AS PowerStationId , ps.`Name` AS PowerStationName,city.Name AS CityName FROM {tableName} ps - LEFT JOIN city ON city.Id = ps.CityId WHERE ps.Deleted = 0 AND SolarType = 0"; - - - if (!string.IsNullOrEmpty(filter)) - { - sql += @" AND ps.Name LIKE CONCAT('%', @Filter, '%')"; - } - - sql += @" ORDER BY city.Priority"; - result = (await conn.QueryAsync(sql, new { Filter = filter })).ToList(); - } - catch (Exception exception) - { - throw exception; - } - return result; - } - } - - public async Task> GetPowerStationsByCompanyIdWithfilterForGeneration(MyUser myUser, string filter) - { - List result; - using (IDbConnection conn = this._databaseHelper.GetConnection()) - { - try - { - var sql = $@"SELECT ps.Id AS PowerStationId , ps.`Name` AS PowerStationName,city.Name AS CityName FROM {tableName} ps - LEFT JOIN city ON city.Id = ps.CityId"; - - if (myUser.Role.Layer == 2) - { - sql += " WHERE ps.Deleted = 0 AND ps.CompanyId = @CompanyId AND SolarType = 0 "; - } - else - { - sql += @" LEFT JOIN power_station_operation_personnel op ON ps.Id = op.PowerStationId - WHERE ps.Deleted = 0 AND op.Deleted = 0 AND op.UserId = @UserId AND SolarType = 0 "; - } - - if (!string.IsNullOrEmpty(filter)) - { - sql += @" AND ps.Name LIKE CONCAT('%', @Filter, '%')"; - } - - sql += @" ORDER BY city.Priority"; - result = (await conn.QueryAsync(sql, new { CompanyId = myUser.CompanyId, UserId = myUser.Id, Filter = filter })).ToList(); - } - catch (Exception exception) - { - throw exception; - } - return result; - } - } - - public async Task> GetApicallItemList(int powerStationId, string dbname) { List result; diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index 1e6a5fc..3eb22b5 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -24,7 +24,7 @@ namespace SolarPower.Repository.Interface /// /// //List GetMyPowerStationSummary(MyUser myUser, string filter = ""); - List GetMyPowerStationList(MyUser myUser, List cityIds = null, List wheres = null, List orderBy = null); + List GetMyPowerStationList(MyUser myUser, List cityIds = null, List wheres = null, Dictionary where_entities = null, List orderBy = null); /// /// 查詢縣市列表 @@ -598,8 +598,6 @@ namespace SolarPower.Repository.Interface Task> GetAllInverterRowData(string date, string table_name); Task> GetAllInverterInfo(List post, string site_table, string site_db); Task GetInverterInfoModal(int Id, string Time, string DB, string Table); - Task> GetPowerStationsAllWithfilterForGeneration(string filter); - Task> GetPowerStationsByCompanyIdWithfilterForGeneration(MyUser myUser, string filter); Task> GetApicallItemList(int powerStationId, string dbname); Task> GetApicallList(int PowerStationId, string Type); } diff --git a/SolarPower/Services/Implement/MyPowerStationService.cs b/SolarPower/Services/Implement/MyPowerStationService.cs index 6cba7a0..0522503 100644 --- a/SolarPower/Services/Implement/MyPowerStationService.cs +++ b/SolarPower/Services/Implement/MyPowerStationService.cs @@ -26,19 +26,19 @@ namespace SolarPower.Services.Implement return myCities; } - public List GetMyPowerStations(MyUser myUser, List cityIds = null, List wheres = null, List orderBy = null) + public List GetMyPowerStations(MyUser myUser, List cityIds = null, List wheres = null, Dictionary where_entities = null, List orderBy = null) { List powerStations = new List(); - powerStations = powerStationRepository.GetMyPowerStationList(myUser, cityIds, wheres, orderBy); + powerStations = powerStationRepository.GetMyPowerStationList(myUser, cityIds, wheres, where_entities, orderBy); return powerStations; } - public List GetMyPowerStationsGroupByCity(MyUser myUser, List cityIds = null, List wheres = null, List orderBy = null) + public List GetMyPowerStationsGroupByCity(MyUser myUser, List cityIds = null, List wheres = null, Dictionary where_entities = null, List orderBy = null) { List powerStations = new List(); - powerStations = powerStationRepository.GetMyPowerStationList(myUser, cityIds, wheres, orderBy); + powerStations = powerStationRepository.GetMyPowerStationList(myUser, cityIds, wheres, where_entities, orderBy); var myPowerStations_group = powerStations.GroupBy(x => x.CityId); diff --git a/SolarPower/Views/AnalysisStationCombine/Index.cshtml b/SolarPower/Views/AnalysisStationCombine/Index.cshtml index e1efa34..dc3444e 100644 --- a/SolarPower/Views/AnalysisStationCombine/Index.cshtml +++ b/SolarPower/Views/AnalysisStationCombine/Index.cshtml @@ -48,34 +48,6 @@
      - @*
      -
      - -
      -
      - -
      - -
      -
      -
      - -
      -
      - -
      -
      -
      - -
      -
      -
      *@ -
      @@ -618,7 +590,8 @@ function GetPowerStationCollapse(filter) { - var url = "/StationReport/GetPowerStationNameList" + @*var url = "/StationReport/GetPowerStationNameList"*@ + var url = "/AnalysisStationCombine/GetPowerStationCollapse" var send_data = { Filter: filter @@ -659,9 +632,9 @@ str += '
    • ' + '
      ' + '
      ' + - '' + + '' + '
      ' + - '
      ' + powerStation.powerStationName + '
      ' + + '
      ' + powerStation.name + '
      ' + '
      ' + '
    • '; }); diff --git a/SolarPower/Views/ElectricitySoldRecord/Index.cshtml b/SolarPower/Views/ElectricitySoldRecord/Index.cshtml index c26f100..91bb98b 100644 --- a/SolarPower/Views/ElectricitySoldRecord/Index.cshtml +++ b/SolarPower/Views/ElectricitySoldRecord/Index.cshtml @@ -341,7 +341,7 @@ function GetPowerStationCollapse(filter) { - var url = "/StationReport/GetPowerStationNameList" + var url = "/StationReport/GetPowerStationCollapse" var send_data = { Filter: filter @@ -396,9 +396,9 @@ str += '
    • ' + '
      ' + '
      ' + - '' + + '' + '
      ' + - '
      ' + inverter.powerStationName + '
      ' + + '
      ' + inverter.name + '
      ' + '
      ' + '
    • '; } @@ -406,9 +406,9 @@ str += '
    • ' + '
      ' + '
      ' + - '' + + '' + '
      ' + - '
      ' + inverter.powerStationName + '
      ' + + '
      ' + inverter.name + '
      ' + '
      ' + '
    • '; } diff --git a/SolarPower/Views/ExceptionRecord/Index.cshtml b/SolarPower/Views/ExceptionRecord/Index.cshtml index ff79f8a..5591231 100644 --- a/SolarPower/Views/ExceptionRecord/Index.cshtml +++ b/SolarPower/Views/ExceptionRecord/Index.cshtml @@ -274,7 +274,28 @@ //#endregion //#region 預設載入該使用者可以選擇的電站 - var Nurl = "/PowerStation/GetSolarCitySummary"; + var city_url = "/Operation/GetMyCities"; + $.post(city_url, function (rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + return; + } + + $('#city').empty(); + for (var i = 0; i < rel.data.length; i++) { + $('#city').append(""); + ids.push(rel.data[i].cityId); + Allids.push(rel.data[i].cityId); + } + + getPowerStationCheckBox(); + }, 'json'); + + + @*var Nurl = "/PowerStation/GetSolarCitySummary"; $.post(Nurl, function (rel) { if (rel.code != "0000") { toast_error(rel.msg); @@ -309,192 +330,10 @@ datatable(); //operationRecordTable.ajax.reload(); }) - }) + })*@ //#endregion - - }) - - //#region 改變項目 - function ChangeType(type) { - Type = type; - for (var i = 0; i < 2; i++) { - var name = "button" + i; - document.getElementById(name).setAttribute("class", "btn btn-secondary waves-effect waves-themed"); - } - document.getElementById("button" + type).setAttribute("class", "btn btn-success waves-effect waves-themed"); - ExceptionTable.ajax.reload(); - - } - //#endregion - - //#region 改變日期 - $('#date-range').on('change', function () { - ExceptionTable.ajax.reload(); - }); - //#endregion - - //#region 縣市全選 - function Allcity() { - var Newpowerids = new Array(0); - ids = []; - $.each(Allids, function (index, val) { - var cityid = 'cityID_' + val; - document.getElementById(cityid).setAttribute("class", 'btn btn-success waves-effect waves-themed ml-2'); - if (AllidsType) { - document.getElementById(cityid).setAttribute("class", 'btn btn-outline-success waves-effect waves-themed ml-2'); - ids = []; - powerids = []; - } - else { - document.getElementById(cityid).setAttribute("class", 'btn btn-success waves-effect waves-themed ml-2'); - ids.push(val); - } - }); - if (AllidsType) { - AllidsType = false; - AllpoweridsType = false; - } else { - AllidsType = true; - } - var send_data = { - cityid: ids - } - var Nurl = "/PowerStation/GetSolarByCity"; - $.post(Nurl, send_data, function (rel) { - if (rel.code != "0000") { - toast_error(rel.msg); - return; - } - $('#CheckPowerStation').empty(); - Allpowerids = []; - $.each(rel.data, function (index, val) { - if (powerids.includes(String(val.id))) { - $('#CheckPowerStation').append("
      "); - $('#station_' + val.id).append(""); - $('#station_' + val.id).append(""); - Newpowerids.push(String(val.id)); - } - else { - $('#CheckPowerStation').append("
      "); - $('#station_' + val.id).append(""); - $('#station_' + val.id).append(""); - } - Allpowerids.push(String(val.id)); - }); - powerids = []; - powerids = Newpowerids; - }) - ExceptionTable.ajax.reload(); - } - //#endregion - - //#region 查詢近30天 - function ChangeDate30() { - var today = new Date(); - var dateLimit = new Date(new Date().setDate(today.getDate() - 30)); - - var today_format = today.toISOString().slice(0, 10).replace(/-/g, "/"); - var dateLimit_format = dateLimit.toISOString().slice(0, 10).replace(/-/g, "/"); - - datepicker.data('daterangepicker').setStartDate(dateLimit_format); - datepicker.data('daterangepicker').setEndDate(today_format); - - $('#date-range').val(dateLimit_format + ' - ' + today_format); - $('#date-range').trigger('change'); - } - //#endregion - - //#region 電站全選 - function Allpowerstation() { - if (AllpoweridsType) { - AllpoweridsType = false; - } else { - AllpoweridsType = true; - } - - powerids = []; - $.each(Allpowerids, function (index, val) { - if (AllpoweridsType) { - $('#check_' + val).prop("checked", true); - powerids.push(val); - } else { - $('#check_' + val).prop("checked", false); - powerids = []; - } - }) - ExceptionTable.ajax.reload(); - } - //#endregion - - //#region 選擇縣市 - $('#city').on("click", "button", function () { - var clickid = $(this).attr('id'); - var classid = clickid.split("_"); - var Newpowerids = new Array(0); - var value = document.getElementById(clickid).className; - ids.sort(function (a, b) { - return a - b; - }); - var send_data = { - cityid: ids - } - if (value == 'btn btn-outline-success waves-effect waves-themed ml-2') { //選擇 - document.getElementById(clickid).setAttribute("class", 'btn btn-success waves-effect waves-themed ml-2'); - ids.push(classid[1]); - } - else { //取消 - document.getElementById(clickid).setAttribute("class", 'btn btn-outline-success waves-effect waves-themed ml-2'); - ids.remove(classid[1]); - } - ids.sort(); - var Nurl = "/PowerStation/GetSolarByCity"; - $.post(Nurl, send_data, function (rel) { - if (rel.code != "0000") { - toast_error(rel.msg); - return; - } - $('#CheckPowerStation').empty(); - Allpowerids = []; - $.each(rel.data, function (index, val) { - if (powerids.includes(String(val.id))) { - $('#CheckPowerStation').append("
      "); - $('#station_' + val.id).append(""); - $('#station_' + val.id).append(""); - Newpowerids.push(String(val.id)); - } - else { - $('#CheckPowerStation').append("
      "); - $('#station_' + val.id).append(""); - $('#station_' + val.id).append(""); - } - Allpowerids.push(String(val.id)); - }); - powerids = []; - powerids = Newpowerids; - }) - ExceptionTable.ajax.reload(); - }) - //#endregion - - //#region 選擇電站checkbox - $('#CheckPowerStation').on("click", "input", function () { - var clickid = $(this).attr('id'); - var classid = clickid.split("_"); - var job = document.getElementById(clickid); - if (job.checked == true) { - powerids.push(classid[1]); - } - else { - powerids.remove(classid[1]); - } - ExceptionTable.ajax.reload(); - }) - - //#endregion - - //#region DataTable - function datatable() { + //#region DataTable ExceptionTable = $("#Exception_Table").DataTable({ "pageLength": 20, "paging": true, @@ -555,8 +394,8 @@ "type": "POST", "data": function (d) { d.id = powerids, - d.status = Type, - d.range = $('#date-range').val() + d.status = Type, + d.range = $('#date-range').val() }, "dataSrc": function (rel) { if (rel.data.code == "9999") { @@ -574,9 +413,223 @@ console.log(xhr); } }); + //#endregion + }) + + //#region 改變項目 + function ChangeType(type) { + Type = type; + for (var i = 0; i < 2; i++) { + var name = "button" + i; + document.getElementById(name).setAttribute("class", "btn btn-secondary waves-effect waves-themed"); + } + document.getElementById("button" + type).setAttribute("class", "btn btn-success waves-effect waves-themed"); + ExceptionTable.ajax.reload(); + } //#endregion + //#region 改變日期 + $('#date-range').on('change', function () { + ExceptionTable.ajax.reload(); + }); + //#endregion + + //#region 縣市全選 + function Allcity() { + var Newpowerids = new Array(0); + ids = []; + $.each(Allids, function (index, val) { + var cityid = 'cityID_' + val; + document.getElementById(cityid).setAttribute("class", 'btn btn-success waves-effect waves-themed ml-2'); + if (AllidsType) { + document.getElementById(cityid).setAttribute("class", 'btn btn-outline-success waves-effect waves-themed ml-2'); + ids = []; + powerids = []; + } + else { + document.getElementById(cityid).setAttribute("class", 'btn btn-success waves-effect waves-themed ml-2'); + ids.push(val); + } + }); + if (AllidsType) { + AllidsType = false; + AllpoweridsType = false; + } else { + AllidsType = true; + } + + getPowerStationCheckBox(); + @*var Nurl = "/PowerStation/GetSolarByCity"; + $.post(Nurl, send_data, function (rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + return; + } + $('#CheckPowerStation').empty(); + Allpowerids = []; + $.each(rel.data, function (index, val) { + if (powerids.includes(String(val.id))) { + $('#CheckPowerStation').append("
      "); + $('#station_' + val.id).append(""); + $('#station_' + val.id).append(""); + Newpowerids.push(String(val.id)); + } + else { + $('#CheckPowerStation').append("
      "); + $('#station_' + val.id).append(""); + $('#station_' + val.id).append(""); + } + Allpowerids.push(String(val.id)); + }); + powerids = []; + powerids = Newpowerids; + })*@ + ExceptionTable.ajax.reload(); + } + //#endregion + + //#region 查詢近30天 + function ChangeDate30() { + var today = new Date(); + var dateLimit = new Date(new Date().setDate(today.getDate() - 30)); + + var today_format = today.toISOString().slice(0, 10).replace(/-/g, "/"); + var dateLimit_format = dateLimit.toISOString().slice(0, 10).replace(/-/g, "/"); + + datepicker.data('daterangepicker').setStartDate(dateLimit_format); + datepicker.data('daterangepicker').setEndDate(today_format); + + $('#date-range').val(dateLimit_format + ' - ' + today_format); + $('#date-range').trigger('change'); + } + //#endregion + + //#region 電站全選 + function Allpowerstation() { + if (AllpoweridsType) { + AllpoweridsType = false; + } else { + AllpoweridsType = true; + } + + powerids = []; + $.each(Allpowerids, function (index, val) { + if (AllpoweridsType) { + $('#check_' + val).prop("checked", true); + powerids.push(val); + } else { + $('#check_' + val).prop("checked", false); + powerids = []; + } + }) + ExceptionTable.ajax.reload(); + } + //#endregion + + //#region 選擇縣市 + $('#city').on("click", "button", function () { + var clickid = $(this).attr('id'); + var classid = clickid.split("_"); + var Newpowerids = new Array(0); + var value = document.getElementById(clickid).className; + + if (value == 'btn btn-outline-success waves-effect waves-themed ml-2') { //選擇 + document.getElementById(clickid).setAttribute("class", 'btn btn-success waves-effect waves-themed ml-2'); + if ($.inArray(parseInt(classid[1]), ids) < 0 ) { + ids.push(parseInt(classid[1])); + } + } + else { //取消 + document.getElementById(clickid).setAttribute("class", 'btn btn-outline-success waves-effect waves-themed ml-2'); + if ($.inArray(parseInt(classid[1]), ids) > -1) { + ids.splice($.inArray(parseInt(classid[1]), ids), 1); + } + } + + getPowerStationCheckBox(); + + @*ids.sort(); + var Nurl = "/PowerStation/GetSolarByCity"; + $.post(Nurl, send_data, function (rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + return; + } + $('#CheckPowerStation').empty(); + Allpowerids = []; + $.each(rel.data, function (index, val) { + if (powerids.includes(String(val.id))) { + $('#CheckPowerStation').append("
      "); + $('#station_' + val.id).append(""); + $('#station_' + val.id).append(""); + Newpowerids.push(String(val.id)); + } + else { + $('#CheckPowerStation').append("
      "); + $('#station_' + val.id).append(""); + $('#station_' + val.id).append(""); + } + Allpowerids.push(String(val.id)); + }); + powerids = []; + powerids = Newpowerids; + })*@ + ExceptionTable.ajax.reload(); + }) + //#endregion + + //#region 選擇電站checkbox + $('#CheckPowerStation').on("click", "input", function () { + var clickid = $(this).attr('id'); + var classid = clickid.split("_"); + var job = document.getElementById(clickid); + if (job.checked == true) { + powerids.push(classid[1]); + } + else { + powerids.remove(classid[1]); + } + ExceptionTable.ajax.reload(); + }) + + //#endregion + + function getPowerStationCheckBox() { + var send_data = { + cityIds: ids + } + + var Nurl = "/ExceptionRecord/GetPowerStationByFilter"; + $.post(Nurl, send_data, function (rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + return; + } + $('#CheckPowerStation').empty(); + powerids = []; + $.each(rel.data, function (index, val) { + if ($.inArray(parseInt(val.cityId), ids) > -1) { + $('#CheckPowerStation').append("
      "); + $('#station_' + val.id).append(""); + $('#station_' + val.id).append(""); + powerids.push(String(val.id)); + } else { + $('#CheckPowerStation').append("
      "); + $('#station_' + val.id).append(""); + $('#station_' + val.id).append(""); + + if ($.inArray(parseInt(val.id), powerids) > -1) { + powerids.splice($.inArray(parseInt(val.id), powerids), 1); + } + } + Allpowerids.push(String(val.id)); + }); + + ExceptionTable.ajax.reload(); + }) + } + //#region 派工新增表單(異常) $('#Exception_Table').on("click", "a.add-btn", function () { powerStationData_name = $(this).parents('tr').attr('data-name'); @@ -616,7 +669,7 @@ $("#exception-form-modal").modal(); }); //#endregion - + }); //#endregion @@ -697,7 +750,7 @@ $("#exception-form-modal").modal(); }); //#endregion - + }, 'json'); }); //#endregion @@ -823,7 +876,7 @@ dom.append(str); } //#endregion - + } \ No newline at end of file diff --git a/SolarPower/Views/NoticeSchedule/Index.cshtml b/SolarPower/Views/NoticeSchedule/Index.cshtml index f7e9f1e..817165e 100644 --- a/SolarPower/Views/NoticeSchedule/Index.cshtml +++ b/SolarPower/Views/NoticeSchedule/Index.cshtml @@ -449,7 +449,7 @@ function GetPowerStationCollapse(filter) { - var url = "/StationReport/GetPowerStationNameList" + var url = "/StationReport/GetPowerStationCollapse" var send_data = { Filter: filter @@ -500,9 +500,9 @@ str += '
    • ' + '
      ' + '
      ' + - '' + + '' + '
      ' + - '
      ' + inverter.powerStationName + '
      ' + + '
      ' + inverter.name + '
      ' + '
      ' + '
    • '; } @@ -510,9 +510,9 @@ str += '
    • ' + '
      ' + '
      ' + - '' + + '' + '
      ' + - '
      ' + inverter.powerStationName + '
      ' + + '
      ' + inverter.name + '
      ' + '
      ' + '
    • '; } diff --git a/SolarPower/Views/Operation/Index.cshtml b/SolarPower/Views/Operation/Index.cshtml index 8a3d197..0fd6d3f 100644 --- a/SolarPower/Views/Operation/Index.cshtml +++ b/SolarPower/Views/Operation/Index.cshtml @@ -238,13 +238,35 @@ if (index > -1) { this.splice(index, 1); } - }; + }; //#endregion $(function () { //#region 載入縣市 - var Nurl = "/PowerStation/GetSolarCitySummary"; + var city_url = "/Operation/GetMyCities"; + $.post(city_url, function (rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + return; + } + + $('#city').empty(); + for (var i = 0; i < rel.data.length; i++) { + $('#city').append(""); + ids.push(rel.data[i].cityId); + Allids.push(rel.data[i].cityId); + } + + $('#Allcity').trigger("click"); + + getPowerStationCheckBox(); + }, 'json'); + + @*var Nurl = "/PowerStation/GetSolarCitySummary"; $.post(Nurl, function (rel) { if (rel.code != "0000") { toast_error(rel.msg); @@ -282,9 +304,9 @@ Allpowerids.push(String(val.id)); }); OperationPlanTable.ajax.reload(); - + }) - }) + })*@ //#endregion //#region 定時計畫列表 DataTable @@ -370,7 +392,7 @@ }); //#endregion - + }) //#region 縣市全選 @@ -389,7 +411,7 @@ else { document.getElementById(cityid).setAttribute("class", 'btn btn-success waves-effect waves-themed ml-2'); ids.push(val); - + } }); if (AllidsType) { @@ -398,7 +420,10 @@ } else { AllidsType = true; } - var send_data = { + + getPowerStationCheckBox() + + @*var send_data = { cityid: ids } var Nurl = "/PowerStation/GetSolarByCity"; @@ -426,7 +451,7 @@ powerids = []; powerids = Newpowerids; }) - OperationPlanTable.ajax.reload(); + OperationPlanTable.ajax.reload();*@ } //#endregion @@ -458,19 +483,22 @@ var classid = clickid.split("_"); var Newpowerids = new Array(0); var value = document.getElementById(clickid).className; - ids.sort(function (a, b) { - return a - b; - }); - + if (value == 'btn btn-outline-success waves-effect waves-themed ml-2') { //選擇 document.getElementById(clickid).setAttribute("class", 'btn btn-success waves-effect waves-themed ml-2'); - ids.push(classid[1]); + if ($.inArray(parseInt(classid[1]), ids) < 0) { + ids.push(parseInt(classid[1])); + } } else { //取消 document.getElementById(clickid).setAttribute("class", 'btn btn-outline-success waves-effect waves-themed ml-2'); - ids.remove(classid[1]); + if ($.inArray(parseInt(classid[1]), ids) > -1) { + ids.splice($.inArray(parseInt(classid[1]), ids), 1); + } } - ids.sort(); + + getPowerStationCheckBox(); + @*ids.sort(); var send_data = { cityid: ids } @@ -500,10 +528,50 @@ powerids = []; powerids = Newpowerids; }) - OperationPlanTable.ajax.reload(); + OperationPlanTable.ajax.reload();*@ }) //#endregion + function getPowerStationCheckBox() { + var send_data = { + cityIds: ids + } + + var Nurl = "/Operation/GetPowerStationByFilter"; + $.post(Nurl, send_data, function (rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + return; + } + $('#CheckPowerStation').empty(); + powerids = []; + $.each(rel.data, function (index, val) { + $("#operation_powerStationselect_modal").empty(); + $.each(rel.data, function (index, val) { + $("#operation_powerStationselect_modal").append($("