Merge branch 'Willy'
This commit is contained in:
commit
ffd4e47981
@ -68,7 +68,6 @@ namespace SolarPower.Controllers
|
||||
UpdatedBy = myUser.Id,
|
||||
Kwh = post.Kwh,
|
||||
Money = post.Money,
|
||||
PowerstationId = post.PowerstationId,
|
||||
StartAt = post.StartAt
|
||||
};
|
||||
List<string> properties = new List<string>()
|
||||
@ -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<ActionResult> RecordTable(ElectricitySoldRecordTablePost info)
|
||||
{
|
||||
List<ElectricitySoldRecordTable> electricitySoldRecordTable = new List<ElectricitySoldRecordTable>();
|
||||
ApiResult<List<ElectricitySoldRecordTable>> apiResult = new ApiResult<List<ElectricitySoldRecordTable>>();
|
||||
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 = @"
|
||||
<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>";
|
||||
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<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;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,10 +99,14 @@ namespace SolarPower.Controllers
|
||||
apiResult.Msg = "需加入查詢電站";
|
||||
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[i] = "inv_" + inverter.Inv[i].Substring(inverter.Inv[i].Length - 4, 4);
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (Showmoney)
|
||||
{
|
||||
@ -1181,12 +1185,18 @@ namespace SolarPower.Controllers
|
||||
{
|
||||
Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report", Datename));
|
||||
}
|
||||
var n = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report", "FIC太陽能監控平台" + "_" + name + "報表" + "_" + postObject.Userid + Datename + ".xlsx");
|
||||
var n = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "report", Datename, "FIC太陽能監控平台" + "_" + name + "報表" + "_" + postObject.Userid + Datename + ".xlsx");
|
||||
FileStream FS = new FileStream(n, FileMode.Create, FileAccess.Write);
|
||||
workbook.Write(FS);
|
||||
FS.Close();
|
||||
return Path.Combine("\\" + "upload" ,"report", Datename, "FIC太陽能監控平台" + "_" + name + "報表" + "_" + postObject.Userid+ Datename + ".xlsx");
|
||||
}
|
||||
|
||||
//public async Task<ApiResult<List<MaxFormbody>>> GetMaxForm (Select_table2 post)
|
||||
//{
|
||||
|
||||
// return;
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<Excelpowerstation> 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; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -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<List<ElectricitySoldRecordTable>> RecordTable (ElectricitySoldRecordTablePost post)
|
||||
{
|
||||
List<ElectricitySoldRecordTable> a = new List<ElectricitySoldRecordTable>();
|
||||
|
||||
string sql = "";
|
||||
switch (post.SearchType)
|
||||
List<int> ids = new List<int>();
|
||||
foreach(var id in post.StationId)
|
||||
{
|
||||
//case 0:
|
||||
// post.Time.Replace("-","~").Replace("")
|
||||
// sql = "";
|
||||
// break;
|
||||
//case 1:
|
||||
// sql = "";
|
||||
// break;
|
||||
//case 2:
|
||||
// sql = "";
|
||||
// break;
|
||||
//case 3:
|
||||
// sql = "";
|
||||
// break;
|
||||
ids.Add(Convert.ToInt32(id.Value));
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,9 +243,10 @@
|
||||
<script>
|
||||
var searchType = 0;//搜尋條件(日,日區間,月,年)
|
||||
var datepicker;
|
||||
var timerange;//選取時間
|
||||
var timerange = "";//選取時間
|
||||
var selecterd_powerstationId = [];
|
||||
var selected_id;
|
||||
var RecordTable;
|
||||
//#region Date-Picker
|
||||
datepicker = $('#DateGettext').daterangepicker({
|
||||
autoUpdateInput: false,
|
||||
@ -287,6 +288,7 @@
|
||||
$('#DateGettext').val(dateLimit_format + ' - ' + today_format);
|
||||
$("#PowerStationId_modal").append($("<option />").val(0).text("請先選擇電站"));
|
||||
$("#PowerStationId_modal").attr("disabled", true);
|
||||
DataTable();
|
||||
})
|
||||
|
||||
//#region 左邊的搜索欄位
|
||||
@ -489,6 +491,7 @@
|
||||
if ($("#Record-form").valid()) {
|
||||
var url = "/ElectricitySoldRecord/SaveSoldMoney";
|
||||
var send_data = {
|
||||
Id: selected_id,
|
||||
StartAt: $("#StartTime_modal").val(),
|
||||
EndAt: $("#EndTime_modal").val(),
|
||||
Kwh: $("#BuyKwh_modal").val(),
|
||||
@ -503,8 +506,8 @@
|
||||
}
|
||||
else {
|
||||
toast_ok(rel.msg);
|
||||
//$('#ShareDevice-modal').modal('hide');
|
||||
//ShareDeviceTable.ajax.reload();
|
||||
$('#Record-modal').modal('hide');
|
||||
RecordTable.ajax.reload();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -562,6 +565,7 @@
|
||||
},
|
||||
'createdRow': function (row, data, dataIndex) {
|
||||
$(row).attr('data-id', data.id);
|
||||
$(row).attr('powerstation-Name', data.powerStationName);
|
||||
},
|
||||
"ajax": {
|
||||
"url": "/ElectricitySoldRecord/RecordTable",
|
||||
@ -590,13 +594,92 @@
|
||||
}
|
||||
|
||||
function Searchform() {
|
||||
console.log(selecterd_powerstationId);
|
||||
if (searchType == 0 || searchType == 1) {
|
||||
timerange = $('#DateGettext').val();
|
||||
}
|
||||
else {
|
||||
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>
|
||||
}
|
||||
@ -254,6 +254,23 @@
|
||||
</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="col-xl-12">
|
||||
<div class="card p-3 w-100 overflow-auto">
|
||||
@ -267,6 +284,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
@ -641,14 +659,16 @@
|
||||
}
|
||||
$('#TableHead').empty();
|
||||
var str = "<tr>";
|
||||
str += "<th>Date</th>";
|
||||
$.each(rel.data.inv, function (index, inverter) {
|
||||
haveinvertName.push(inverter);
|
||||
str += "<th>" + inverter + "</th>";
|
||||
})
|
||||
if (form != 2) {
|
||||
$.each(rel.data.inv, function (index, inverter) {
|
||||
haveinvertName.push(inverter);
|
||||
str += "<th>" + inverter + "</th>";
|
||||
})
|
||||
}
|
||||
switch (form)
|
||||
{
|
||||
case 0:
|
||||
str += "<th>Date</th>";
|
||||
str += "<th>小時<br />發電量<br />(kWh)</th>";
|
||||
str += "<th>小時<br />發電量<br />百分比<br />(%)</th>";
|
||||
str += "<th>小時<br />平均<br />日照度<br />(W/㎡)</th>";
|
||||
@ -658,6 +678,7 @@
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
str += "<th>Date</th>";
|
||||
str += "<th>日<br />發電量<br />(kWh)</th>";
|
||||
str += "<th>日<br />發電量<br />百分比<br />(%)</th>";
|
||||
str += "<th>日照小時(hr)</th>";
|
||||
@ -669,11 +690,28 @@
|
||||
str += "<th>日<br />售電金額<br />(NTD)</th>";
|
||||
}
|
||||
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>";
|
||||
$('#TableHead').append(str);
|
||||
if (form != 2) {
|
||||
tablebody(form, rel.data.showMoney);
|
||||
} else {
|
||||
maxtableinfobody(rel.data.showMoney);
|
||||
}
|
||||
|
||||
tablebody(form, 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) {
|
||||
|
||||
})
|
||||
}
|
||||
</script>
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user