diff --git a/SolarPower/Controllers/ElectricitySoldRecordController.cs b/SolarPower/Controllers/ElectricitySoldRecordController.cs index e209466..a256397 100644 --- a/SolarPower/Controllers/ElectricitySoldRecordController.cs +++ b/SolarPower/Controllers/ElectricitySoldRecordController.cs @@ -68,7 +68,6 @@ namespace SolarPower.Controllers UpdatedBy = myUser.Id, Kwh = post.Kwh, Money = post.Money, - PowerstationId = post.PowerstationId, StartAt = post.StartAt }; List properties = new List() @@ -78,7 +77,6 @@ namespace SolarPower.Controllers "UpdatedBy", "Kwh", "Money", - "PowerstationId", "StartAt" }; await electricitySoldRecordRepository.Update(record, properties); @@ -99,21 +97,30 @@ namespace SolarPower.Controllers return apiResult; } + [HttpPost] public async Task RecordTable(ElectricitySoldRecordTablePost info) { List electricitySoldRecordTable = new List(); ApiResult> apiResult = new ApiResult>(); try { - electricitySoldRecordTable = await electricitySoldRecordRepository.RecordTable(info); - foreach (ElectricitySoldRecordTable a in electricitySoldRecordTable) + if(info.StationId == null || info.Time == null) { - a.Function = @" + apiResult.Code = "0000"; + } + else + { + electricitySoldRecordTable = await electricitySoldRecordRepository.RecordTable(info); + foreach (ElectricitySoldRecordTable a in electricitySoldRecordTable) + { + a.Function = @" "; + a.CreatedDay = Convert.ToDateTime(a.CreatedAt).ToString("yyyy-MM-dd"); + } + apiResult.Code = "0000"; + apiResult.Data = electricitySoldRecordTable; } - apiResult.Code = "0000"; - apiResult.Data = electricitySoldRecordTable; } catch (Exception exception) { @@ -129,5 +136,50 @@ namespace SolarPower.Controllers }); return result; } + + public async Task> GetOnePowerStation(int id) + { + ApiResult apiResult = new ApiResult(); + ElectricitySoldRecord record = new ElectricitySoldRecord(); + try + { + record = await electricitySoldRecordRepository.GetOneAsync(id); + apiResult.Code = "0000"; + apiResult.Data = record; + + } + catch (Exception exception) + { + apiResult.Code = "9999"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + + } + + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } + + public async Task> DeleteRecord(int id) + { + ApiResult apiResult = new ApiResult(); + try + { + await electricitySoldRecordRepository.DeleteOne(id); + apiResult.Code = "0000"; + apiResult.Msg = "刪除成功"; + + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = errorCode.GetString(apiResult.Code); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + id); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + + } } } diff --git a/SolarPower/Controllers/StationReportController.cs b/SolarPower/Controllers/StationReportController.cs index 2fb27a3..acd4e08 100644 --- a/SolarPower/Controllers/StationReportController.cs +++ b/SolarPower/Controllers/StationReportController.cs @@ -99,10 +99,14 @@ namespace SolarPower.Controllers apiResult.Msg = "需加入查詢電站"; return apiResult; } - inverter.Inv = await stationReportRepository.GetInverterId(powerStation.SiteDB,post); - for (int i = 0;i>> GetMaxForm (Select_table2 post) + //{ + + // return; + //} + } } diff --git a/SolarPower/Models/StationReport.cs b/SolarPower/Models/StationReport.cs index 1796f27..92d2d15 100644 --- a/SolarPower/Models/StationReport.cs +++ b/SolarPower/Models/StationReport.cs @@ -32,6 +32,14 @@ namespace SolarPower.Models public int FormType { get; set; } public int Userid { get; set; } } + public class Select_table2 + { + public int SearchType { get; set; } + public string Time { get; set; } + public List PowerStation { get; set; } + public int FormType { get; set; } + public int Userid { get; set; } + } public class Excel { public int SearchType { get; set; } @@ -71,5 +79,19 @@ namespace SolarPower.Models public string Landowner { get; set; } } + public class MaxFormbody + { + public string CityName { get; set; } + public string AreaName { get; set; } + public string PowerstationName { get; set; } + public int PowerstationId { get; set; } + public double Kwp { get; set; } + public string PowerstationDB { get; set; } + public double SolarHour { get; set; } + public double AvgIrradiance { get; set; } + public double AvgPR { get; set; } + + } + } diff --git a/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs b/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs index cf69909..d6b6c7f 100644 --- a/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs +++ b/SolarPower/Repository/Implement/ElectricitySoldRecordRepository.cs @@ -1,8 +1,10 @@ -using SolarPower.Helper; +using Dapper; +using SolarPower.Helper; using SolarPower.Models; using SolarPower.Repository.Interface; using System; using System.Collections.Generic; +using System.Data; using System.Linq; using System.Threading.Tasks; @@ -16,26 +18,61 @@ namespace SolarPower.Repository.Implement } public async Task> RecordTable (ElectricitySoldRecordTablePost post) { - List a = new List(); + string sql = ""; + List ids = new List(); + foreach(var id in post.StationId) + { + ids.Add(Convert.ToInt32(id.Value)); + } + + switch (post.SearchType) { - //case 0: - // post.Time.Replace("-","~").Replace("") - // sql = ""; - // break; - //case 1: - // sql = ""; - // break; - //case 2: - // sql = ""; - // break; - //case 3: - // sql = ""; - // break; + case 0: + post.Time = post.Time.Replace(" ", ""); + post.Time = post.Time.Replace("-", "~"); + post.Time = post.Time.Replace("/", "-"); + var time = post.Time.Split("~"); + sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es + LEFT JOIN power_station ps ON es.PowerstationId = ps.Id + WHERE es.StartAt BETWEEN '{time[0]}' AND '{time[1]}' AND es.PowerstationId IN @ids AND es.Deleted = 0"; + break; + case 1: + post.Time = post.Time.Replace(" ", ""); + post.Time = post.Time.Replace("-", "~"); + post.Time = post.Time.Replace("/", "-"); + var time1 = post.Time.Split("~"); + sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es + LEFT JOIN power_station ps ON es.PowerstationId = ps.Id + WHERE es.StartAt BETWEEN '{time1[0]}' AND '{time1[1]}' AND es.PowerstationId IN @ids AND es.Deleted = 0"; + sql = ""; + break; + case 2: + sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es + LEFT JOIN power_station ps ON es.PowerstationId = ps.Id + WHERE DATE_FORMAT(es.StartAt , '%Y-%m') = '{post.Time}' AND es.PowerstationId IN @ids AND es.Deleted = 0"; + break; + case 3: + sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es + LEFT JOIN power_station ps ON es.PowerstationId = ps.Id + WHERE DATE_FORMAT(es.StartAt , '%Y') = '{post.Time}' AND es.PowerstationId IN @ids AND es.Deleted = 0"; + break; + } + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + List a = new List(); + try + { + a = (await conn.QueryAsync(sql,new { ids = ids})).ToList(); + } + catch (Exception exception) + { + throw exception; + } + return a; } - return a; } } } diff --git a/SolarPower/Views/ElectricitySoldRecord/Index.cshtml b/SolarPower/Views/ElectricitySoldRecord/Index.cshtml index a854a67..32788f1 100644 --- a/SolarPower/Views/ElectricitySoldRecord/Index.cshtml +++ b/SolarPower/Views/ElectricitySoldRecord/Index.cshtml @@ -243,9 +243,10 @@ } \ No newline at end of file diff --git a/SolarPower/Views/StationReport/Index.cshtml b/SolarPower/Views/StationReport/Index.cshtml index 9b180b2..fa84ed5 100644 --- a/SolarPower/Views/StationReport/Index.cshtml +++ b/SolarPower/Views/StationReport/Index.cshtml @@ -254,6 +254,23 @@ +
+
+
+ + + + + + + + + + +
縣市平均發電量(kWp)發電時間(小時)
+
+
+
@@ -267,6 +284,7 @@
+
@@ -641,14 +659,16 @@ } $('#TableHead').empty(); var str = ""; - str += "Date"; - $.each(rel.data.inv, function (index, inverter) { - haveinvertName.push(inverter); - str += "" + inverter + ""; - }) + if (form != 2) { + $.each(rel.data.inv, function (index, inverter) { + haveinvertName.push(inverter); + str += "" + inverter + ""; + }) + } switch (form) { case 0: + str += "Date"; str += "小時
發電量
(kWh)"; str += "小時
發電量
百分比
(%)"; str += "小時
平均
日照度
(W/㎡)"; @@ -658,6 +678,7 @@ } break; case 1: + str += "Date"; str += "日
發電量
(kWh)"; str += "日
發電量
百分比
(%)"; str += "日照小時(hr)"; @@ -669,11 +690,28 @@ str += "日
售電金額
(NTD)"; } break; + case 2: + str += "區域"; + str += "電站名稱"; + str += "發電量"; + str += "發電小時"; + str += "平均日照"; + str += "PR"; + if (rel.data.showMoney == 1) { + str += "發電金額"; + str += "租金收入"; + str += "省電費用"; + } + break; } str += ""; $('#TableHead').append(str); - - tablebody(form, rel.data.showMoney); + if (form != 2) { + tablebody(form, rel.data.showMoney); + } else { + maxtableinfobody(rel.data.showMoney); + } + }, 'json'); @@ -681,6 +719,7 @@ function Dateform(form) { $('#hiretable').hide(); + tablehand(form); } @@ -893,7 +932,6 @@ }, 'json'); } - function ExportExcel() { var send_data = { @@ -909,5 +947,19 @@ } } + function maxtableinfobody(showmoney) + { + var send_data = + { + SearchType: searchType, + Time: timerange, + FormType: form, + PowerStation: selecterd_invert + } + var url = "/StationReport/GetMaxForm"; + $.post(url, send_data, function (rel) { + + }) + } } \ No newline at end of file