diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index b77e4d3..e4648fe 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -2602,5 +2602,61 @@ namespace SolarPower.Controllers return apiResult; } + + [HttpPost] + public async Task>> GetAllPowerStationsALLImage(List powerStationId) + { + ApiResult> apiResult = new ApiResult>(); + + List powerStationImages = null; + List ALLpowerStationImages = new List(); + try + { + foreach(var ones in powerStationId) + { + var powerStation = await powerStationRepository.GetOneAsync(ones); + + if (powerStation == null) + { + apiResult.Code = "9992"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + else + { + + if (!IsPlatformLayer(myUser.Role.Layer) && powerStation.CompanyId != myUser.CompanyId) + { + apiResult.Code = "9993"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + powerStationImages = await powerStationRepository.GetAllPowerStationImageAsync(ones, powerStation.SiteDB); + + foreach (var stationImage in powerStationImages) + { + stationImage.Image = Path.Combine(stationImageFilePath, powerStation.Id.ToString()) + "/" + stationImage.Image; + } + ALLpowerStationImages = ALLpowerStationImages.Concat(powerStationImages).ToList(); + } + } + + apiResult.Code = "0000"; + apiResult.Data = ALLpowerStationImages; + + + + } + catch (Exception exception) + { + apiResult.Code = "9999"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + "PowerStationId=" + powerStationId); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } } } diff --git a/SolarPower/Models/AnalysisStationCombine.cs b/SolarPower/Models/AnalysisStationCombine.cs index d54fdfb..af269c8 100644 --- a/SolarPower/Models/AnalysisStationCombine.cs +++ b/SolarPower/Models/AnalysisStationCombine.cs @@ -22,5 +22,6 @@ namespace SolarPower.Models { public List StationIds { get; set; } public string Timerange { get; set; } + public int SeacrhType { get; set; } } } diff --git a/SolarPower/Repository/Implement/AnalysisStationCombineRepository.cs b/SolarPower/Repository/Implement/AnalysisStationCombineRepository.cs index 6ff9f1a..b9fe66c 100644 --- a/SolarPower/Repository/Implement/AnalysisStationCombineRepository.cs +++ b/SolarPower/Repository/Implement/AnalysisStationCombineRepository.cs @@ -27,15 +27,113 @@ namespace SolarPower.Repository.Implement { try { - string sql = @"SELECT AVG(KWHKWP),TOTALMONEY,TOTALKWH,TOTALCARBON,PR"; + string sql = ""; + switch(post.SeacrhType) + { + case 0: + string timerange = Convert.ToDateTime(post.Timerange).ToString("yyyy-MM-dd"); + sql = $@"SELECT m.*,n.* FROM + ( + SELECT AVG(KWHKWP) AS All_KWH_KWP ,SUM(TOTALMONEY) AS All_money, + SUM(TOTALKWH) AS All_kwh,SUM(TOTALCARBON) AS All_Carbon, + AVG(PR) AS All_PR + from power_station_history_month + WHERE PowerStationId IN @ids + ) + AS m, + ( + SELECT + SUM(b.TODAYKWH) AS Now_kwh, + SUM(b.TODAYMONEY) AS Now_money, + AVG(b.KWHKWP) AS Now_KWH_KWP , + AVG(b.PR) AS Now_PR, + SUM(b.TODAYCARBON) AS Now_Carbon + FROM (SELECT MAX(a.`TIMESTAMP`) AS maxTIMESTAMP FROM + (SELECT * FROM power_station_history_hour hr WHERE DATE_FORMAT(hr.`TIMESTAMP`,'%Y-%m-%d') = '{timerange}') a ) c + LEFT JOIN + (SELECT * FROM power_station_history_hour hr WHERE DATE_FORMAT(hr.`TIMESTAMP`,'%Y-%m-%d') = '{timerange}' ) b + ON c.maxTIMESTAMP = b.`TIMESTAMP` + WHERE PowerStationId IN @ids + ) + AS n"; + break; + case 1: + var time = post.Timerange.Split('-'); + sql = $@"SELECT m.*,n.* FROM + ( + SELECT AVG(KWHKWP) AS All_KWH_KWP, SUM(TOTALMONEY) AS All_money, + SUM(TOTALKWH) AS All_kwh, SUM(TOTALCARBON) AS All_Carbon, + AVG(PR) AS All_PR + from power_station_history_month + WHERE PowerStationId IN @ids + ) + AS m, + ( + SELECT + SUM(b.TODAYKWH) AS Now_kwh, + SUM(b.MONEY) AS Now_money, + AVG(b.KWHKWP) AS Now_KWH_KWP, + AVG(b.PR) AS Now_PR, + SUM(b.CARBON) AS Now_Carbon + FROM power_station_history_day b + WHERE PowerStationId IN @ids AND TIMESTAMP BETWEEN '{time[0]}' AND '{time[1]}' + ) + AS n"; + break; + case 2: + sql = $@"SELECT m.*,n.* FROM + ( + SELECT + AVG(KWHKWP) AS All_KWH_KWP, + SUM(TOTALMONEY) AS All_money, + SUM(TOTALKWH) AS All_kwh, + SUM(TOTALCARBON) AS All_Carbon, + AVG(PR) AS All_PR + from power_station_history_month + WHERE PowerStationId IN @ids + ) + AS m, + ( + SELECT + SUM(b.TODAYKWH) AS Now_kwh, + SUM(b.MONEY) AS Now_money, + AVG(b.KWHKWP) AS Now_KWH_KWP, + AVG(b.PR) AS Now_PR, + SUM(b.CARBON) AS Now_Carbon + FROM power_station_history_day b + WHERE PowerStationId IN @ids AND DATE_FORMAT(TIMESTAMP, '%Y-%m') = '{post.Timerange}' + ) + AS n"; + break; + case 3: + sql = $@"SELECT m.*,n.* FROM + ( + SELECT AVG(KWHKWP) AS All_KWH_KWP, SUM(TOTALMONEY) AS All_money, + SUM(TOTALKWH) AS All_kwh, SUM(TOTALCARBON) AS All_Carbon, + AVG(PR) AS All_PR + from power_station_history_month + WHERE PowerStationId IN @ids + ) + AS m, + ( + SELECT - a = await conn.QueryFirstOrDefaultAsync(sql); + SUM(b.MONTHKWH) AS Now_kwh, + SUM(b.MONEY) AS Now_money, + AVG(b.KWHKWP) AS Now_KWH_KWP, + AVG(b.PR) AS Now_PR, + SUM(b.CARBON) AS Now_Carbon + FROM power_station_history_month b + WHERE PowerStationId IN @ids AND DATE_FORMAT(TIMESTAMP, '%Y') = '{post.Timerange}' + ) + AS n"; + break; + } - trans.Commit(); + a = await conn.QueryFirstOrDefaultAsync(sql,new { ids = post.StationIds}); } catch (Exception exception) { - trans.Rollback(); throw exception; } finally diff --git a/SolarPower/Views/AnalysisStationCombine/Index.cshtml b/SolarPower/Views/AnalysisStationCombine/Index.cshtml index cac04bc..b2ff6ee 100644 --- a/SolarPower/Views/AnalysisStationCombine/Index.cshtml +++ b/SolarPower/Views/AnalysisStationCombine/Index.cshtml @@ -78,28 +78,29 @@
+

發電量

kwh
-
+

總發電量

-

126,161.72

+

126,161.72

今日發電量

-

4,069.73

+

4,069.73

-
+

發電金額

NTD
-
+

總發金額

126,161.72

@@ -110,6 +111,7 @@
+

kWh / kWp

@@ -117,11 +119,11 @@

平均 kWh / kWp

-

140.39

+

140.39

今日 kWh / kWp

-

4.53

+

4.53

@@ -129,14 +131,14 @@

PR值

-
+

平均 PR 值

-

119.04

+

119.04

今日PR值

-

3.84

+

3.84

@@ -146,14 +148,14 @@

減碳量

kG
-
+

總減碳量

-

6,091.78

+

6,091.78

今日減碳量

-

985.98

+

985.98

@@ -277,20 +279,11 @@ powerids.push(String(val.id)); Allpowerids.push(String(val.id)); }); - //GetStationsCard(); - //modal 電站 下拉式選單 - //$("#power_station_select_modal").empty(); - //$.each(rel.data, function (index, val) { - // $("#power_station_select_modal").append($("