This commit is contained in:
Kai 2021-08-04 16:03:09 +08:00
commit e5dd87a6cb
6 changed files with 294 additions and 38 deletions

View File

@ -68,7 +68,6 @@ namespace SolarPower.Controllers
UpdatedBy = myUser.Id, UpdatedBy = myUser.Id,
Kwh = post.Kwh, Kwh = post.Kwh,
Money = post.Money, Money = post.Money,
PowerstationId = post.PowerstationId,
StartAt = post.StartAt StartAt = post.StartAt
}; };
List<string> properties = new List<string>() List<string> properties = new List<string>()
@ -78,7 +77,6 @@ namespace SolarPower.Controllers
"UpdatedBy", "UpdatedBy",
"Kwh", "Kwh",
"Money", "Money",
"PowerstationId",
"StartAt" "StartAt"
}; };
await electricitySoldRecordRepository.Update(record, properties); await electricitySoldRecordRepository.Update(record, properties);
@ -99,11 +97,18 @@ namespace SolarPower.Controllers
return apiResult; return apiResult;
} }
[HttpPost]
public async Task<ActionResult> RecordTable(ElectricitySoldRecordTablePost info) public async Task<ActionResult> RecordTable(ElectricitySoldRecordTablePost info)
{ {
List<ElectricitySoldRecordTable> electricitySoldRecordTable = new List<ElectricitySoldRecordTable>(); List<ElectricitySoldRecordTable> electricitySoldRecordTable = new List<ElectricitySoldRecordTable>();
ApiResult<List<ElectricitySoldRecordTable>> apiResult = new ApiResult<List<ElectricitySoldRecordTable>>(); ApiResult<List<ElectricitySoldRecordTable>> apiResult = new ApiResult<List<ElectricitySoldRecordTable>>();
try try
{
if(info.StationId == null || info.Time == null)
{
apiResult.Code = "0000";
}
else
{ {
electricitySoldRecordTable = await electricitySoldRecordRepository.RecordTable(info); electricitySoldRecordTable = await electricitySoldRecordRepository.RecordTable(info);
foreach (ElectricitySoldRecordTable a in electricitySoldRecordTable) foreach (ElectricitySoldRecordTable a in electricitySoldRecordTable)
@ -111,10 +116,12 @@ namespace SolarPower.Controllers
a.Function = @" a.Function = @"
<button type='button' class='btn btn-primary btn-pills waves-effect waves-themed edit-btn'></button> <button type='button' class='btn btn-primary btn-pills waves-effect waves-themed edit-btn'></button>
<button type='button' class='btn btn-danger btn-pills waves-effect waves-themed del-btn'></button>"; <button type='button' class='btn btn-danger btn-pills waves-effect waves-themed del-btn'></button>";
a.CreatedDay = Convert.ToDateTime(a.CreatedAt).ToString("yyyy-MM-dd");
} }
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Data = electricitySoldRecordTable; apiResult.Data = electricitySoldRecordTable;
} }
}
catch (Exception exception) catch (Exception exception)
{ {
apiResult.Code = "9999"; apiResult.Code = "9999";
@ -129,5 +136,50 @@ namespace SolarPower.Controllers
}); });
return result; return result;
} }
public async Task<ApiResult<ElectricitySoldRecord>> GetOnePowerStation(int id)
{
ApiResult<ElectricitySoldRecord> apiResult = new ApiResult<ElectricitySoldRecord>();
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<ApiResult<string>> DeleteRecord(int id)
{
ApiResult<string> apiResult = new ApiResult<string>();
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;
}
} }
} }

View File

@ -99,11 +99,15 @@ namespace SolarPower.Controllers
apiResult.Msg = "需加入查詢電站"; apiResult.Msg = "需加入查詢電站";
return apiResult; return apiResult;
} }
inverter.Inv = await stationReportRepository.GetInverterId(powerStation.SiteDB,post);
for (int i = 0;i<inverter.Inv.Count;i++) if(post.FormType != 2)
{
inverter.Inv = await stationReportRepository.GetInverterId(powerStation.SiteDB, post);
for (int i = 0; i < inverter.Inv.Count; i++)
{ {
inverter.Inv[i] = "inv_" + inverter.Inv[i].Substring(inverter.Inv[i].Length - 4, 4); inverter.Inv[i] = "inv_" + inverter.Inv[i].Substring(inverter.Inv[i].Length - 4, 4);
} }
}
if (Showmoney) if (Showmoney)
{ {
inverter.ShowMoney = 1; inverter.ShowMoney = 1;
@ -1188,5 +1192,11 @@ namespace SolarPower.Controllers
return Path.Combine("\\" + "upload" ,"report", Datename, "FIC太陽能監控平台" + "_" + name + "報表" + "_" + postObject.Userid+ Datename + ".xlsx"); return Path.Combine("\\" + "upload" ,"report", Datename, "FIC太陽能監控平台" + "_" + name + "報表" + "_" + postObject.Userid+ Datename + ".xlsx");
} }
//public async Task<ApiResult<List<MaxFormbody>>> GetMaxForm (Select_table2 post)
//{
// return;
//}
} }
} }

View File

@ -32,6 +32,14 @@ namespace SolarPower.Models
public int FormType { get; set; } public int FormType { get; set; }
public int Userid { get; set; } public int Userid { get; set; }
} }
public class Select_table2
{
public int SearchType { get; set; }
public string Time { get; set; }
public List<Excelpowerstation> PowerStation { get; set; }
public int FormType { get; set; }
public int Userid { get; set; }
}
public class Excel public class Excel
{ {
public int SearchType { get; set; } public int SearchType { get; set; }
@ -71,5 +79,19 @@ namespace SolarPower.Models
public string Landowner { get; set; } 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; }
}
} }

View File

@ -1,8 +1,10 @@
using SolarPower.Helper; using Dapper;
using SolarPower.Helper;
using SolarPower.Models; using SolarPower.Models;
using SolarPower.Repository.Interface; using SolarPower.Repository.Interface;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -16,26 +18,61 @@ namespace SolarPower.Repository.Implement
} }
public async Task<List<ElectricitySoldRecordTable>> RecordTable (ElectricitySoldRecordTablePost post) public async Task<List<ElectricitySoldRecordTable>> RecordTable (ElectricitySoldRecordTablePost post)
{ {
List<ElectricitySoldRecordTable> a = new List<ElectricitySoldRecordTable>();
string sql = ""; string sql = "";
switch (post.SearchType) List<int> ids = new List<int>();
foreach(var id in post.StationId)
{ {
//case 0: ids.Add(Convert.ToInt32(id.Value));
// post.Time.Replace("-","~").Replace("")
// sql = "";
// break;
//case 1:
// sql = "";
// break;
//case 2:
// sql = "";
// break;
//case 3:
// sql = "";
// break;
} }
switch (post.SearchType)
{
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<ElectricitySoldRecordTable> a = new List<ElectricitySoldRecordTable>();
try
{
a = (await conn.QueryAsync<ElectricitySoldRecordTable>(sql,new { ids = ids})).ToList();
}
catch (Exception exception)
{
throw exception;
}
return a; return a;
} }
}
} }
} }

View File

@ -243,9 +243,10 @@
<script> <script>
var searchType = 0;//搜尋條件(日,日區間,月,年) var searchType = 0;//搜尋條件(日,日區間,月,年)
var datepicker; var datepicker;
var timerange;//選取時間 var timerange = "";//選取時間
var selecterd_powerstationId = []; var selecterd_powerstationId = [];
var selected_id; var selected_id;
var RecordTable;
//#region Date-Picker //#region Date-Picker
datepicker = $('#DateGettext').daterangepicker({ datepicker = $('#DateGettext').daterangepicker({
autoUpdateInput: false, autoUpdateInput: false,
@ -287,6 +288,7 @@
$('#DateGettext').val(dateLimit_format + ' - ' + today_format); $('#DateGettext').val(dateLimit_format + ' - ' + today_format);
$("#PowerStationId_modal").append($("<option />").val(0).text("請先選擇電站")); $("#PowerStationId_modal").append($("<option />").val(0).text("請先選擇電站"));
$("#PowerStationId_modal").attr("disabled", true); $("#PowerStationId_modal").attr("disabled", true);
DataTable();
}) })
//#region 左邊的搜索欄位 //#region 左邊的搜索欄位
@ -489,6 +491,7 @@
if ($("#Record-form").valid()) { if ($("#Record-form").valid()) {
var url = "/ElectricitySoldRecord/SaveSoldMoney"; var url = "/ElectricitySoldRecord/SaveSoldMoney";
var send_data = { var send_data = {
Id: selected_id,
StartAt: $("#StartTime_modal").val(), StartAt: $("#StartTime_modal").val(),
EndAt: $("#EndTime_modal").val(), EndAt: $("#EndTime_modal").val(),
Kwh: $("#BuyKwh_modal").val(), Kwh: $("#BuyKwh_modal").val(),
@ -503,8 +506,8 @@
} }
else { else {
toast_ok(rel.msg); toast_ok(rel.msg);
//$('#ShareDevice-modal').modal('hide'); $('#Record-modal').modal('hide');
//ShareDeviceTable.ajax.reload(); RecordTable.ajax.reload();
return; return;
} }
@ -562,6 +565,7 @@
}, },
'createdRow': function (row, data, dataIndex) { 'createdRow': function (row, data, dataIndex) {
$(row).attr('data-id', data.id); $(row).attr('data-id', data.id);
$(row).attr('powerstation-Name', data.powerStationName);
}, },
"ajax": { "ajax": {
"url": "/ElectricitySoldRecord/RecordTable", "url": "/ElectricitySoldRecord/RecordTable",
@ -590,13 +594,92 @@
} }
function Searchform() { function Searchform() {
console.log(selecterd_powerstationId);
if (searchType == 0 || searchType == 1) { if (searchType == 0 || searchType == 1) {
timerange = $('#DateGettext').val(); timerange = $('#DateGettext').val();
} }
else { else {
timerange = $('#DateGet').val(); timerange = $('#DateGet').val();
} }
DataTable(); RecordTable.ajax.reload();
} }
$('#RecordTable').on("click", "button.edit-btn", function () {
$("#Record-modal .modal-title").html("台電售電紀錄 - 編輯");
selected_id = $(this).parents('tr').attr('data-id');
var powerstationName = $(this).parents('tr').attr('powerstation-Name');
//取得單一運維基本資料
var url = "/ElectricitySoldRecord/GetOnePowerStation/";
var send_data = {
Id: selected_id
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
$('#PowerStationId_modal').empty();
$("#PowerStationId_modal").attr("disabled", true);
$("#PowerStationId_modal").append($("<option />").val(999).text(powerstationName));
$("#StartTime_modal").val(rel.data.startAt);
$("#BuyKwh_modal").val(rel.data.kwh);
$("#EndTime_modal").val(rel.data.endAt);
$("#Money_modal").val(rel.data.money);
$("#Record-modal").modal();
}, 'json');
});
$('#RecordTable').on("click", "button.del-btn", function () {
selected_id = $(this).parents('tr').attr('data-id');
Swal.fire(
{
title: "刪除",
text: "你確定是否刪除此筆資料?",
type: "warning",
icon: 'warning',
showCancelButton: true,
confirmButtonText: "是",
cancelButtonText: "否"
}).then(function (result) {
if (result.value) {
var url = "/ElectricitySoldRecord/DeleteRecord/";
var send_data = {
Id: selected_id
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
toast_ok(rel.msg);
RecordTable.ajax.reload();
}, 'json');
}
});
});
$("#Record-form").validate({
rules: {
PowerStationId_modal: {
required: true,
},
StartTime_modal: {
required: true
},
EndTime_modal: {
required: true,
},
BuyKwh_modal: {
required: true,
},
Money_modal: {
required: true,
},
},
});
</script> </script>
} }

View File

@ -254,6 +254,23 @@
</div> </div>
</div> </div>
</div> </div>
<div class="row mb-5">
<div class="col-xl-12">
<div class="card p-3 w-100 " id="maxtable">
<table class="table m-0">
<thead>
<tr>
<th>縣市</th>
<th>平均發電量(kWp)</th>
<th>發電時間(小時)</th>
</tr>
</thead>
<tbody id="maxtableBody">
</tbody>
</table>
</div>
</div>
</div>
<div class="row mb-5"> <div class="row mb-5">
<div class="col-xl-12"> <div class="col-xl-12">
<div class="card p-3 w-100 overflow-auto"> <div class="card p-3 w-100 overflow-auto">
@ -267,6 +284,7 @@
</div> </div>
</div> </div>
</main> </main>
</div> </div>
</div> </div>
@ -641,14 +659,16 @@
} }
$('#TableHead').empty(); $('#TableHead').empty();
var str = "<tr>"; var str = "<tr>";
str += "<th>Date</th>"; if (form != 2) {
$.each(rel.data.inv, function (index, inverter) { $.each(rel.data.inv, function (index, inverter) {
haveinvertName.push(inverter); haveinvertName.push(inverter);
str += "<th>" + inverter + "</th>"; str += "<th>" + inverter + "</th>";
}) })
}
switch (form) switch (form)
{ {
case 0: case 0:
str += "<th>Date</th>";
str += "<th>小時<br />發電量<br />(kWh)</th>"; str += "<th>小時<br />發電量<br />(kWh)</th>";
str += "<th>小時<br />發電量<br />百分比<br />(%)</th>"; str += "<th>小時<br />發電量<br />百分比<br />(%)</th>";
str += "<th>小時<br />平均<br />日照度<br />(W/㎡)</th>"; str += "<th>小時<br />平均<br />日照度<br />(W/㎡)</th>";
@ -658,6 +678,7 @@
} }
break; break;
case 1: case 1:
str += "<th>Date</th>";
str += "<th>日<br />發電量<br />(kWh)</th>"; str += "<th>日<br />發電量<br />(kWh)</th>";
str += "<th>日<br />發電量<br />百分比<br />(%)</th>"; str += "<th>日<br />發電量<br />百分比<br />(%)</th>";
str += "<th>日照小時(hr)</th>"; str += "<th>日照小時(hr)</th>";
@ -669,11 +690,28 @@
str += "<th>日<br />售電金額<br />(NTD)</th>"; str += "<th>日<br />售電金額<br />(NTD)</th>";
} }
break; break;
case 2:
str += "<th>區域</th>";
str += "<th>電站名稱</th>";
str += "<th>發電量</th>";
str += "<th>發電小時</th>";
str += "<th>平均日照</th>";
str += "<th>PR</th>";
if (rel.data.showMoney == 1) {
str += "<th>發電金額</th>";
str += "<th>租金收入</th>";
str += "<th>省電費用</th>";
}
break;
} }
str += "</tr>"; str += "</tr>";
$('#TableHead').append(str); $('#TableHead').append(str);
if (form != 2) {
tablebody(form, rel.data.showMoney); tablebody(form, rel.data.showMoney);
} else {
maxtableinfobody(rel.data.showMoney);
}
}, 'json'); }, 'json');
@ -681,6 +719,7 @@
function Dateform(form) { function Dateform(form) {
$('#hiretable').hide(); $('#hiretable').hide();
tablehand(form); tablehand(form);
} }
@ -893,7 +932,6 @@
}, 'json'); }, 'json');
} }
function ExportExcel() { function ExportExcel() {
var send_data = 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) {
})
}
</script> </script>
} }