From 7fa16df8fe265801421624cd8d2b1209eb4d1168 Mon Sep 17 00:00:00 2001 From: Kai Date: Thu, 2 Sep 2021 14:30:46 +0800 Subject: [PATCH] =?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($("