[前端] 修改年月份顯示
[後端] 修改搜尋變數錯誤
This commit is contained in:
parent
35118e8115
commit
99fabe689e
@ -879,8 +879,12 @@
|
|||||||
|
|
||||||
const ElecEachTotal =
|
const ElecEachTotal =
|
||||||
$("li.active [name=reportTypeRadio]").data("type") === "compare";
|
$("li.active [name=reportTypeRadio]").data("type") === "compare";
|
||||||
if (ElecEachTotal) {
|
if (ElecEachTotal) {
|
||||||
const [year, month] = $("#elecMonthDate").val().split("-");
|
let preDate = new Date($("#elecMonthDate").val().split("-") + "-01");
|
||||||
|
preDate.setMonth(preDate.getMonth() - 1);
|
||||||
|
const [year, month] = $("#elecMonthDate").val().split("-");
|
||||||
|
const preYear = preDate.getFullYear();
|
||||||
|
const preMonth = (preDate.getMonth() + 1).toString().padStart(2, '0');
|
||||||
datesColumns = [
|
datesColumns = [
|
||||||
{
|
{
|
||||||
label: "選擇月份 <br>" + `${year}${month}` + "(A)",
|
label: "選擇月份 <br>" + `${year}${month}` + "(A)",
|
||||||
@ -888,16 +892,15 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label:
|
label:
|
||||||
"前一月份 <br>" +
|
"前一月份 <br>" +
|
||||||
`${year}${month - 1 > 10 ? month - 1 : `0${month - 1}`}` +
|
`${preYear}${preMonth}` +
|
||||||
"(B)",
|
"(B)",
|
||||||
value: `${year}-${month - 1 > 10 ? month - 1 : `0${month - 1}`}`,
|
value: `${preYear}-${preMonth}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label:
|
label:
|
||||||
"差異比較 <br>" +
|
"差異比較 <br>" +
|
||||||
`${year}${month}(A)-${year}${month - 1 > 10 ? month - 1 : `0${month - 1}`
|
`${year}${month}(A)-${preYear}${preMonth}(B)`,
|
||||||
}(B)`,
|
|
||||||
value: "last month different",
|
value: "last month different",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1299,6 +1299,7 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
var start_month = date.ToString("MM"); // 查詢月
|
var start_month = date.ToString("MM"); // 查詢月
|
||||||
var last_year = previousYear.ToString("yyyy"); // 上個查詢年
|
var last_year = previousYear.ToString("yyyy"); // 上個查詢年
|
||||||
var last_month = previousMonth.ToString("MM"); // 上個查詢月
|
var last_month = previousMonth.ToString("MM"); // 上個查詢月
|
||||||
|
var pre_year = previousMonth.ToString("yyyy"); // 上個查詢月(年份)
|
||||||
|
|
||||||
string sqlWhere = "";
|
string sqlWhere = "";
|
||||||
string tag_quantity = await backendRepository.GetOneAsync<string>("select system_value from variable where system_type = 'obixConfig' and system_key = 'tag_quantity' and deleted = 0");
|
string tag_quantity = await backendRepository.GetOneAsync<string>("select system_value from variable where system_type = 'obixConfig' and system_key = 'tag_quantity' and deleted = 0");
|
||||||
@ -1329,14 +1330,14 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
string header_now = start_year + "-" + start_month;
|
string header_now = start_year + "-" + start_month;
|
||||||
string header_lastM = start_year + "-" + last_month;
|
string header_lastM = pre_year + "-" + last_month;
|
||||||
string header_lastY = last_year + "-" + start_month;
|
string header_lastY = last_year + "-" + start_month;
|
||||||
|
|
||||||
var sql = $@"
|
var sql = $@"
|
||||||
select e.full_name building_name, a.device_number, '{header_now}' searchMT, ifnull(b.kwh_sum, 0) searchM, '{header_lastM}' lastMT, ifnull(c.kwh_sum, 0) lastM, '{header_lastY}' lastYT, ifnull(d.kwh_sum, 0) lastY
|
select e.full_name building_name, a.device_number, '{header_now}' searchMT, ifnull(b.kwh_sum, 0) searchM, '{header_lastM}' lastMT, ifnull(c.kwh_sum, 0) lastM, '{header_lastY}' lastYT, ifnull(d.kwh_sum, 0) lastY
|
||||||
from device a
|
from device a
|
||||||
left join (select device_number, sum(kwh_result) kwh_sum from archive_electric_meter_month where year(start_timestamp) = {start_year} and month(start_timestamp) = {start_month} group by device_number) b on a.device_number COLLATE utf8mb4_0900_ai_ci = b.device_number -- month1
|
left join (select device_number, sum(kwh_result) kwh_sum from archive_electric_meter_month where year(start_timestamp) = {start_year} and month(start_timestamp) = {start_month} group by device_number) b on a.device_number COLLATE utf8mb4_0900_ai_ci = b.device_number -- month1
|
||||||
left join (select device_number, sum(kwh_result) kwh_sum from archive_electric_meter_month where year(start_timestamp) = {start_year} and month(start_timestamp) = {last_month} group by device_number) c on a.device_number COLLATE utf8mb4_0900_ai_ci = c.device_number -- month2
|
left join (select device_number, sum(kwh_result) kwh_sum from archive_electric_meter_month where year(start_timestamp) = {pre_year} and month(start_timestamp) = {last_month} group by device_number) c on a.device_number COLLATE utf8mb4_0900_ai_ci = c.device_number -- month2
|
||||||
left join (select device_number, sum(kwh_result) kwh_sum from archive_electric_meter_month where year(start_timestamp) = {last_year} and month(start_timestamp) = {start_month} group by device_number) d on a.device_number COLLATE utf8mb4_0900_ai_ci = d.device_number -- last Month
|
left join (select device_number, sum(kwh_result) kwh_sum from archive_electric_meter_month where year(start_timestamp) = {last_year} and month(start_timestamp) = {start_month} group by device_number) d on a.device_number COLLATE utf8mb4_0900_ai_ci = d.device_number -- last Month
|
||||||
join building e on a.device_building_tag = e.building_tag
|
join building e on a.device_building_tag = e.building_tag
|
||||||
where {sqlWhere}
|
where {sqlWhere}
|
||||||
|
Loading…
Reference in New Issue
Block a user