This commit is contained in:
b110212000 2021-08-04 10:29:11 +08:00
parent d2b386cc18
commit 196b00595a
3 changed files with 128 additions and 25 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,21 +97,30 @@ 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
{ {
electricitySoldRecordTable = await electricitySoldRecordRepository.RecordTable(info); if(info.StationId == null || info.Time == null)
foreach (ElectricitySoldRecordTable a in electricitySoldRecordTable)
{ {
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-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.Data = electricitySoldRecordTable;
} }
apiResult.Code = "0000";
apiResult.Data = electricitySoldRecordTable;
} }
catch (Exception exception) catch (Exception exception)
{ {
@ -129,5 +136,27 @@ 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;
}
} }
} }

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 = "";
List<int> ids = new List<int>();
foreach(var id in post.StationId)
{
ids.Add(Convert.ToInt32(id.Value));
}
switch (post.SearchType) switch (post.SearchType)
{ {
//case 0: case 0:
// post.Time.Replace("-","~").Replace("") post.Time = post.Time.Replace(" ", "");
// sql = ""; post.Time = post.Time.Replace("-", "~");
// break; post.Time = post.Time.Replace("/", "-");
//case 1: var time = post.Time.Split("~");
// sql = ""; sql = @$"SELECT es.`*`,ps.Name AS PowerStationName FROM electricity_sold_record es
// break; LEFT JOIN power_station ps ON es.PowerstationId = ps.Id
//case 2: WHERE es.StartAt BETWEEN '{time[0]}' AND '{time[1]}' AND es.PowerstationId IN @ids";
// sql = ""; break;
// break; case 1:
//case 3: post.Time = post.Time.Replace(" ", "");
// sql = ""; post.Time = post.Time.Replace("-", "~");
// break; 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";
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";
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";
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 左邊的搜索欄位
@ -562,6 +564,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 +593,47 @@
} }
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 () {
$("#Operation-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');
});
</script> </script>
} }