[前端] 修改年月份顯示

[後端] 修改搜尋變數錯誤
This commit is contained in:
dev02 2024-01-02 14:17:22 +08:00
parent 35118e8115
commit 99fabe689e
2 changed files with 13 additions and 9 deletions

View File

@ -880,7 +880,11 @@
const ElecEachTotal =
$("li.active [name=reportTypeRadio]").data("type") === "compare";
if (ElecEachTotal) {
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 = [
{
label: "選擇月份 <br>" + `${year}${month}` + "(A)",
@ -889,15 +893,14 @@
{
label:
"前一月份 <br>" +
`${year}${month - 1 > 10 ? month - 1 : `0${month - 1}`}` +
`${preYear}${preMonth}` +
"(B)",
value: `${year}-${month - 1 > 10 ? month - 1 : `0${month - 1}`}`,
value: `${preYear}-${preMonth}`,
},
{
label:
"差異比較 <br>" +
`${year}${month}(A)-${year}${month - 1 > 10 ? month - 1 : `0${month - 1}`
}(B)`,
`${year}${month}(A)-${preYear}${preMonth}(B)`,
value: "last month different",
},
{

View File

@ -1299,6 +1299,7 @@ namespace FrontendWebApi.ApiControllers
var start_month = date.ToString("MM"); // 查詢月
var last_year = previousYear.ToString("yyyy"); // 上個查詢年
var last_month = previousMonth.ToString("MM"); // 上個查詢月
var pre_year = previousMonth.ToString("yyyy"); // 上個查詢月(年份)
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");
@ -1329,14 +1330,14 @@ namespace FrontendWebApi.ApiControllers
}
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;
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
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) = {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
join building e on a.device_building_tag = e.building_tag
where {sqlWhere}