解決衝突

This commit is contained in:
b110212000 2021-07-06 20:25:51 +08:00
commit 987c4b7dfd
15 changed files with 1444 additions and 125 deletions

View File

@ -1,19 +1,92 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SolarPower.Models;
using SolarPower.Models.PowerStation;
using SolarPower.Repository.Interface;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace SolarPower.Controllers
{
public class MapOverviewController : Controller
public class MapOverviewController : MyBaseController<MapOverviewController>
{
private readonly IOverviewRepository overviewRepository;
private readonly IPowerStationRepository powerStationRepository;
public MapOverviewController(
IOverviewRepository overviewRepository,
IPowerStationRepository powerStationRepository) : base()
{
this.overviewRepository = overviewRepository;
this.powerStationRepository = powerStationRepository;
}
public IActionResult Index()
{
return View();
}
[HttpPost]
public async Task<ApiResult<MapOverview>> GetMapOverview()
{
ApiResult<MapOverview> apiResult = new ApiResult<MapOverview>();
MapOverview mapOverview = new MapOverview();
try
{
List<int> powerStationIds = new List<int>() { 1, 2, 3};
var overview = await overviewRepository.GetOverviewByPowerStationIds(powerStationIds);
mapOverview.Today_kwh = overview.Today_kwh;
mapOverview.Total_kwh = overview.Total_kwh;
mapOverview.Today_irradiance = overview.Today_irradiance;
mapOverview.Avg_irradiance = overview.Avg_irradiance;
mapOverview.Today_PR = overview.Today_PR;
mapOverview.Avg_PR = overview.Avg_PR;
mapOverview.Today_kwhkwp = overview.Today_kwhkwp;
mapOverview.Avg_kwhkwp = overview.Avg_kwhkwp;
mapOverview.Today_carbon = overview.Today_carbon;
mapOverview.Total_carbon = overview.Total_carbon;
mapOverview.CapacityDataTables = await overviewRepository.GetCapacityDataTableByPowerStationIds(powerStationIds);
var totalPowerStationCount = 0;
var totalCapacity = 0.0;
foreach(var capacity in mapOverview.CapacityDataTables)
{
totalPowerStationCount += capacity.SubPowerStationCount;
totalCapacity += capacity.SubTotalCapacity;
}
mapOverview.TotalPowerStationCount = totalPowerStationCount;
mapOverview.TotalCapacity = totalCapacity;
mapOverview.PowerStations = await overviewRepository.GetListPowerStationByPowerStationIds(powerStationIds);
mapOverview.UpdatedAt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
apiResult.Code = "0000";
apiResult.Data = mapOverview;
}
catch (Exception exception)
{
apiResult.Code = "9999";
Logger.LogError("【" + controllerName + "/" + actionName + "】");
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
apiResult.Msg = errorCode.GetString(apiResult.Code);
return apiResult;
}
//public async Task<ApiResult<MapOverview>> GetAllDate()
//{
// ApiResult<MapOverview> apiResult = new ApiResult<MapOverview>();

View File

@ -894,6 +894,88 @@ COMMENT='運維紀錄 檔案 or 圖片'
COLLATE='utf8_general_ci'
ENGINE=InnoDB;
-- 創建 電站每小時歷史資料 20210702
CREATE TABLE `power_station_history_hour` (
`Id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`PowerStationId` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '電站編號',
`TIMESTAMP` BIGINT(20) NULL DEFAULT NULL,
`SITEID` VARCHAR(500) NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_ci',
`SITETYPE` INT(11) NULL DEFAULT NULL,
`KWH` DOUBLE NULL DEFAULT NULL,
`TODAYKWH` DOUBLE NULL DEFAULT NULL,
`TOTALKWH` DOUBLE NULL DEFAULT NULL,
`KWHKWP` DOUBLE NULL DEFAULT NULL,
`PR` DOUBLE NULL DEFAULT NULL,
`MP` DOUBLE NULL DEFAULT NULL,
`SOLARHOUR` DOUBLE NULL DEFAULT NULL,
PRIMARY KEY (`Id`) USING BTREE,
INDEX `IDX_01` (`PowerStationId`) USING BTREE
)
COMMENT='各電站每小時的歷史記錄'
COLLATE='utf8mb4_unicode_ci'
ENGINE=InnoDB
;
-- 修改 power_station 欄位 20210702
ALTER TABLE `power_station`
ADD COLUMN `today_kwhkwp` DECIMAL(10,3) NULL DEFAULT NULL COMMENT '今日kwhkwp' AFTER `Total_kwh`,
ADD COLUMN `avg_kwhkwp` DECIMAL(10,3) NULL DEFAULT NULL COMMENT '30天平均kwhkwp' AFTER `today_kwhkwp`,
ADD COLUMN `today_monery` DECIMAL(10,2) NULL DEFAULT NULL COMMENT '今日金額' AFTER `avg_kwhkwp`,
ADD COLUMN `total_monery` DECIMAL(10,2) NULL DEFAULT NULL COMMENT '總金額' AFTER `today_monery`,
ADD COLUMN `today_PR` DECIMAL(5,2) NULL DEFAULT NULL COMMENT '電站Pr值' AFTER `total_monery`,
ADD COLUMN `avg_PR` DECIMAL(5,2) NULL DEFAULT NULL COMMENT '平均Pr值' AFTER `today_PR`,
ADD COLUMN `today_carbon` DECIMAL(10,2) NULL DEFAULT NULL COMMENT '今日減碳量' AFTER `avg_PR`,
ADD COLUMN `total_carbon` DECIMAL(10,2) NULL DEFAULT NULL COMMENT '總減碳量' AFTER `today_carbon`,
ADD COLUMN `today_irradiance` DECIMAL(5,2) NULL DEFAULT NULL COMMENT '今日日照度' AFTER `total_carbon`,
ADD COLUMN `avg_irradiance` DECIMAL(5,2) NULL DEFAULT NULL COMMENT '平均日照度' AFTER `today_irradiance`,
DROP COLUMN `kwhkwp`,
DROP COLUMN `PR`,
DROP COLUMN `MP`;
-- 創建 電站每天歷史資料 20210706
CREATE TABLE `power_station_history_day` (
`Id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`PowerStationId` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '電站編號',
`TIMESTAMP` TIMESTAMP NULL DEFAULT NULL,
`SITEID` VARCHAR(500) NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_ci',
`SITETYPE` INT(11) NULL DEFAULT NULL,
`TODAYKWH` DOUBLE NULL DEFAULT NULL,
`TOTALKWH` DOUBLE NULL DEFAULT NULL,
`KWHKWP` DOUBLE NULL DEFAULT NULL,
`PR` DOUBLE NULL DEFAULT NULL,
`MP` DOUBLE NULL DEFAULT NULL,
`SOLARHOUR` DOUBLE NULL DEFAULT NULL,
PRIMARY KEY (`Id`) USING BTREE,
INDEX `IDX_01` (`PowerStationId`) USING BTREE
)
COMMENT='各電站每天的歷史記錄'
COLLATE='utf8mb4_unicode_ci'
ENGINE=InnoDB
;
-- 創建 電站每月歷史資料 20210706
CREATE TABLE `power_station_history_month` (
`Id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`PowerStationId` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '電站編號',
`TIMESTAMP` TIMESTAMP NULL DEFAULT NULL,
`SITEID` VARCHAR(500) NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_ci',
`SITETYPE` INT(11) NULL DEFAULT NULL,
`MONTHKWH` DOUBLE NULL DEFAULT NULL,
`TOTALKWH` DOUBLE NULL DEFAULT NULL,
`KWHKWP` DOUBLE NULL DEFAULT NULL,
`PR` DOUBLE NULL DEFAULT NULL,
`MP` DOUBLE NULL DEFAULT NULL,
`SOLARHOUR` DOUBLE NULL DEFAULT NULL,
PRIMARY KEY (`Id`) USING BTREE,
INDEX `IDX_01` (`PowerStationId`) USING BTREE
)
COMMENT='各電站每月的歷史記錄'
COLLATE='utf8mb4_unicode_ci'
ENGINE=InnoDB
;
-- 修改 電站資料 更新時間預設值
ALTER TABLE `power_station`
CHANGE COLUMN `UpdatedAt` `UpdatedAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP() ON UPDATE CURRENT_TIMESTAMP COMMENT '修改時間' AFTER `UpdatedBy`;

View File

@ -1,11 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace SolarPower.Models
{
public class MapOverview
{
}
}

View File

@ -2,12 +2,38 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SolarPower.Models.PowerStation;
namespace SolarPower.Models
{
public class Overview
{
public int PR;
public double Today_kwh { get; set; } //今日總發電量
public double Total_kwh { get; set; } //累計總發電量
public double Today_irradiance { get; set; } //即時平均日照度
public double Avg_irradiance { get; set; } //平均日照度(30天)
public double Today_PR { get; set; } //即時平均 PR 值
public double Avg_PR { get; set; } //平均 PR 值(30天)
public double Today_kwhkwp { get; set; } //即時平均 kWh / kWp
public double Avg_kwhkwp { get; set; } //平均 kWh / kWp (30天)
public double Today_carbon { get; set; } //今日減碳量
public double Total_carbon { get; set; } //累積減碳量
}
public class MapOverview : Overview
{
public List<CapacityDataTable> CapacityDataTables { get; set; }
public List<PowerStation.PowerStation> PowerStations { get; set; }
public int TotalPowerStationCount { get; set; }
public double TotalCapacity { get; set; }
public string UpdatedAt { get; set; } //畫面資料更新時間
}
public class CapacityDataTable
{
public string CityName { get; set; } //城市名稱
public int SubPowerStationCount { get; set; } //電站數量
public double SubTotalCapacity { get; set; } //總裝置容量
}
public class UseStatusCityGetPowerStation
@ -15,4 +41,5 @@ namespace SolarPower.Models
public List<int> CityId; //都市
public List<int> Status; //狀態
}
}

View File

@ -6,6 +6,12 @@ using System.Threading.Tasks;
namespace SolarPower.Models.PowerStation
{
public enum SolarTypeEnum : byte
{
SelfSold = 0, //自建躉售
HireSold = 1, //租建躉售
SelfUse = 2 //自建自用
}
public class PowerStation : Created
{
private string electricityMeterAt = "", tpcContractAt = "", tpcPurchaseElectricityAt = "", tpcSellElectricityAt = "";
@ -16,6 +22,7 @@ namespace SolarPower.Models.PowerStation
public int CityId { get; set; } //縣市
public string CityName { get; set; } //縣市名稱
public int AreaId { get; set; } //地區
public string AreaName { get; set; } //地區
public string Address { get; set; } //地址
public string Name { get; set; } //名稱
public string MainDisplay { get; set; } //主要顯示圖片
@ -106,11 +113,16 @@ namespace SolarPower.Models.PowerStation
public List<LandBuilding> LandBuildings { get; set; } //土地房屋資料
public byte SolarType { get; set; } //電站類型
public double kwh { get; set; } //
public double Today_kwh { get; set; } //今日發電量
public double Total_kwh { get; set; } //總發電量
public double kwhkwp { get; set; }
public double PR { get; set; }
public double MP { get; set; }
public double Today_kWh { get; set; } //今日發電量
public double Total_kWh { get; set; } //總發電量
public double Today_Monery { get; set; } //今日發電金額
public double Total_Monery { get; set; } //總發電金額
public double Today_kwhkwp { get; set; }
public double Avg_kwhkwp { get; set; }
public double Today_PR { get; set; }
public double Avg_PR { get; set; }
public double Today_Carbon { get; set; } //今日減碳量
public double Total_Carbon { get; set; } //總減碳量
public double SolarHour { get; set; } //總運轉小時
public string SiteDB { get; set; } //電站 DB name: solar_com
public string TodayWeather { get; set; } //今日天氣
@ -553,4 +565,58 @@ namespace SolarPower.Models.PowerStation
public int PowerStationId { get; set; }
public int DeviceId { get; set; }
}
public class PowerStationHistory
{
public int PowerStationId { get; set; }
public Int64 Timestamp { get; set; }
public string SITEID { get; set; }
public string SiteType { get; set; }
public double KWH { get; set; }
public double TodayKWh { get; set; }
public double TotalKWH { get; set; }
public double KWHKWP { get; set; }
public double PR { get; set; }
public double MP { get; set; }
public double SolarHour { get; set; }
}
public class AvgPowerStationHistory
{
public int PowerStationId { get; set; }
public double AvgKWHKWP { get; set; }
public double AvgPR { get; set; }
}
public class PowerStationHistoryDay
{
public int PowerStationId { get; set; }
public string Timestamp { get; set; }
public string SITEID { get; set; }
public string SiteType { get; set; }
public double TodayKWh { get; set; }
public double TotalKWH { get; set; }
public double KWHKWP { get; set; }
public double PR { get; set; }
public double MP { get; set; }
public double SolarHour { get; set; }
}
public class PowerStationHistoryMonth
{
public int PowerStationId { get; set; }
public string Timestamp { get; set; }
public string SITEID { get; set; }
public string SiteType { get; set; }
public double MONTHKWH { get; set; }
public double TotalKWH { get; set; }
public double KWHKWP { get; set; }
public double PR { get; set; }
public double MP { get; set; }
public double SolarHour { get; set; }
}
}

View File

@ -0,0 +1,175 @@
using Microsoft.Extensions.Logging;
using Quartz;
using SolarPower.Models.PowerStation;
using SolarPower.Repository.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace SolarPower.Quartz.Jobs
{
[DisallowConcurrentExecution]
public class CalcAvgPowerStationJob : IJob
{
private readonly ILogger<CalcAvgPowerStationJob> logger;
private readonly IPowerStationRepository powerStationRepository;
public CalcAvgPowerStationJob(ILogger<CalcAvgPowerStationJob> logger, IPowerStationRepository powerStationRepository)
{
this.logger = logger;
this.powerStationRepository = powerStationRepository;
}
public async Task Execute(IJobExecutionContext context)
{
try
{
#region step1.
var powerStations = await powerStationRepository.GetAllAsync();
#endregion
List<PowerStationHistoryDay> powerStationHistoryDays = new List<PowerStationHistoryDay>();
List<PowerStation> calcAvgPowerStations = new List<PowerStation>();
List<PowerStationHistoryMonth> insertPowerStationHistoryMonths = new List<PowerStationHistoryMonth>();
List<PowerStationHistoryMonth> updatePowerStationHistoryMonths = new List<PowerStationHistoryMonth>();
var DateTimeNow = DateTime.Now;
#region step2. DB及電站編號找出該電站的控制器
foreach (var powerStation in powerStations)
{
#region step2-1. 30
var table_name = String.Format("`{0}`.`{1}01_ficstationhistory`", powerStation.SiteDB, powerStation.Code);
var dateNowDay = DateTimeNow.AddDays(-1).ToString("yyyy-MM-dd");
dateNowDay = "2021-06-24";
var history = await powerStationRepository.GetAvgPowerStationHistory30day(dateNowDay, table_name);
if (history != null)
{
history.PowerStationId = powerStation.Id;
#region 30 kWh/kWp PR
var calcPowerStation = new PowerStation();
calcPowerStation.Id = powerStation.Id;
#region kWh/kWp
//直接填寫
calcPowerStation.Avg_kwhkwp = history.AvgKWHKWP;
#endregion
#region PR
//直接填寫
calcPowerStation.Avg_PR = history.AvgPR;
#endregion
#endregion
calcAvgPowerStations.Add(calcPowerStation);
}
#endregion
#region step2-2.
var historyDay = await powerStationRepository.GetLastOnePowerStationHistoryByDay(dateNowDay, table_name);
if(historyDay != null)
{
historyDay.PowerStationId = powerStation.Id;
powerStationHistoryDays.Add(historyDay);
}
#endregion
#region step2-3.
//判斷這個月是否已存在
var dateNowMonth = DateTimeNow.ToString("yyyy-MM");
dateNowMonth = "2021-06";
var exist = await powerStationRepository.GetOnePowerStationHistoryByPowerStationIdAndMonth(powerStation.Id, dateNowMonth);
if (exist == null)
{ //新增
var historyMonth = await powerStationRepository.GetPowerStationHistoryMonthDataByPowerStationId(powerStation.Id, dateNowMonth);
if(historyMonth != null)
{
historyMonth.Timestamp = Convert.ToDateTime(historyMonth.Timestamp).ToString("yyyy-MM-dd");
insertPowerStationHistoryMonths.Add(historyMonth);
}
}
else
{ //修改
var historyMonth = await powerStationRepository.GetPowerStationHistoryMonthDataByPowerStationId(powerStation.Id, dateNowMonth);
if (historyMonth != null)
{
updatePowerStationHistoryMonths.Add(historyMonth);
}
}
#endregion
}
#endregion
//TODO 日照
#region step3. calcPowerStations UPDATE power_station
List<string> power_station_properties = new List<string>()
{
"Id",
"avg_kwhkwp",
"avg_PR",
};
await powerStationRepository.UpdateList(calcAvgPowerStations, power_station_properties);
#endregion
#region step4. insert or update
//每日
List<string> history_properties_day = new List<string>()
{
"PowerStationId",
"TIMESTAMP",
"SITEID",
"SITETYPE",
"TODAYKWH",
"TOTALKWH",
"KWHKWP",
"PR",
"MP",
"SolarHour"
};
await powerStationRepository.AddPowerStationHistoryDayList(powerStationHistoryDays, history_properties_day);
List<string> history_properties_month = new List<string>()
{
"PowerStationId",
"TIMESTAMP",
"SITEID",
"SITETYPE",
"MonthKWh",
"TOTALKWH",
"KWHKWP",
"PR",
"MP",
"SolarHour"
};
if(insertPowerStationHistoryMonths.Count > 0)
{
await powerStationRepository.AddPowerStationHistoryMonthList(insertPowerStationHistoryMonths, history_properties_month);
}
if (updatePowerStationHistoryMonths.Count > 0)
{
await powerStationRepository.UpdatePowerStationHistoryMonthList(updatePowerStationHistoryMonths);
}
#endregion
}
catch (Exception exception)
{
logger.LogError("【{0}】{1}", "CalcAvgPowerStationJob", exception.Message);
}
}
}
}

View File

@ -0,0 +1,192 @@
using Microsoft.Extensions.Logging;
using Quartz;
using SolarPower.Models.PowerStation;
using SolarPower.Repository.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace SolarPower.Quartz.Jobs
{
[DisallowConcurrentExecution]
public class CalcPowerStationJob : IJob
{
private readonly ILogger<CalcPowerStationJob> logger;
private readonly IPowerStationRepository powerStationRepository;
private double carbonRate;
public CalcPowerStationJob(ILogger<CalcPowerStationJob> logger, IPowerStationRepository powerStationRepository)
{
this.logger = logger;
this.powerStationRepository = powerStationRepository;
}
public async Task Execute(IJobExecutionContext context)
{
try
{
#region step1.
var powerStations = await powerStationRepository.GetAllAsync();
#endregion
List<PowerStationHistory> powerStationHistoriesHour = new List<PowerStationHistory>();
List<PowerStation> calcPowerStations = new List<PowerStation>();
var DateTimeNow = DateTime.Now;
#region step2. DB及電站編號找出該電站的控制器
var count = 0;
foreach (var powerStation in powerStations)
{
if(count > 0)
{
break;
}
#region step2-1.
var table_name = String.Format("`{0}`.{1}01_ficstationhistory", powerStation.SiteDB, powerStation.Code);
var dateTime = DateTimeNow.AddHours(-1).ToString("yyyy-MM-dd HH");
dateTime = "2021-06-24 18";
var history = await powerStationRepository.GetPowerStationHistoryPerHour(dateTime, table_name);
if (history != null)
{
history.PowerStationId = powerStation.Id;
#region
var calcPowerStation = new PowerStation();
calcPowerStation.Id = powerStation.Id;
calcPowerStation.kwh = history.KWH;
#region
//今日發電量(直接填寫
calcPowerStation.Today_kWh = history.TodayKWh;
//總發電量(直接填寫
calcPowerStation.Total_kWh = history.TotalKWH;
#endregion
//TODO
#region
//1. 找出該電站所有日照計設備(包還共享
//2. 透過該DB、col取得到是哪一個sensor
#endregion
#region
//發電金額
switch (powerStation.SolarType)
{
case (int)SolarTypeEnum.SelfSold: //自建躉售
//今日發電金額 計算方式todaykWh * 授電費率
calcPowerStation.Today_Monery = history.TodayKWh * powerStation.PowerRate;
//總發電金額 計算方式totalkWh * 授電費率
calcPowerStation.Total_Monery = history.TotalKWH * powerStation.PowerRate;
break;
case (int)SolarTypeEnum.HireSold: //租建躉售
//找出該電站的所有土地房屋資訊
var landBuildings = await powerStationRepository.GetAllLandBuildingInfoByPowerStationId(powerStation.Id, powerStation.SiteDB);
var sumLeaseRate = 0.00;
var avgLeaseRate = 0.00;
foreach (var landBuilding in landBuildings)
{
sumLeaseRate += landBuilding.LeaseRate;
}
avgLeaseRate = sumLeaseRate / landBuildings.Count();
//今日發電金額計算方式todaykWh * 出借費率(各個土地房屋租借比率平均)
calcPowerStation.Today_Monery = history.TodayKWh * avgLeaseRate;
//總發電金額 計算方式totalkWh * 授電費率
calcPowerStation.Total_Monery = history.TotalKWH * avgLeaseRate;
break;
case (int)SolarTypeEnum.SelfUse: //自建自用
//今日發電金額 計算方式todaykWh * 授電費率
calcPowerStation.Today_Monery = history.TodayKWh * powerStation.PowerRate;
//總發電金額 計算方式totalkWh * 授電費率
calcPowerStation.Total_Monery = history.TotalKWH * powerStation.PowerRate;
break;
}
#endregion
#region kWh/kWp
//直接填寫
calcPowerStation.Today_kwhkwp = history.KWHKWP;
#endregion
#region PR
//直接填寫
calcPowerStation.Today_PR = history.PR;
#endregion
#region
carbonRate = Convert.ToDouble(await powerStationRepository.GetOneVariableByName("CarbonRate"));
//今日減碳量( 今日發電量 * (0.554/1000)[抓資料庫值]
calcPowerStation.Today_Carbon = history.TodayKWh * carbonRate;
//總減碳量(總發電量 * (0.554/1000)[抓資料庫值]
calcPowerStation.Total_Carbon = history.TotalKWH * carbonRate;
#endregion
#endregion
powerStationHistoriesHour.Add(history);
calcPowerStations.Add(calcPowerStation);
}
#endregion
count++;
}
#endregion
#region step3. historiers INSERT power_station_history_hour
List<string> history_properties = new List<string>()
{
"PowerStationId",
"TIMESTAMP",
"SITEID",
"SITETYPE",
"KWH",
"TODAYKWH",
"TOTALKWH",
"KWHKWP",
"PR",
"MP",
"SolarHour"
};
await powerStationRepository.AddPowerStationHistory(powerStationHistoriesHour, history_properties);
#endregion
//TODO 日照
#region step4. calcPowerStations UPDATE power_station
List<string> power_station_properties = new List<string>()
{
"Id",
"kwh",
"Today_kwh",
"Total_kwh",
"today_kwhkwp",
"today_monery",
"total_monery",
"today_PR",
"today_carbon",
"total_carbon",
};
await powerStationRepository.UpdateList(calcPowerStations, power_station_properties);
#endregion
}
catch (Exception exception)
{
logger.LogError("【{0}】{1}", "CalcPowerStationJob", exception.Message);
}
}
}
}

View File

@ -18,6 +18,106 @@ namespace SolarPower.Repository.Implement
tableName = "power_station";
}
public async Task<List<int>> GetAllCityIdAsync()
{
List<int> result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = $"SELECT Id FROM city";
result = (await conn.QueryAsync<int>(sql)).ToList();
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
public async Task<Overview> GetOverviewByPowerStationIds(List<int> powerStationIds)
{
Overview result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = @$"SELECT
SUM(ps.Today_kwh) AS Today_kwh,
SUM(ps.Total_kwh) AS Total_kwh,
AVG(ps.Today_irradiance) AS today_irradiance,
AVG(ps.avg_irradiance) AS avg_irradiance,
AVG(ps.today_PR) AS today_PR,
AVG(ps.avg_PR) AS avg_PR,
AVG(ps.today_kwhkwp) AS today_kwhkwp,
AVG(ps.avg_kwhkwp) AS avg_kwhkwp,
SUM(ps.today_carbon) AS today_carbon,
SUM(ps.total_carbon) AS total_carbon
FROM power_station ps
WHERE ps.Id IN @PowerStationIds
";
result = await conn.QueryFirstOrDefaultAsync<Overview>(sql, new { PowerStationIds = powerStationIds });
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
public async Task<List<CapacityDataTable>> GetCapacityDataTableByPowerStationIds(List<int> powerStationIds)
{
List<CapacityDataTable> result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = @$"SELECT
ps.CityId,
c.Name AS CityName,
COUNT(*) AS SubPowerStationCount,
SUM(ps.GeneratingCapacity) AS SubTotalCapacity
FROM power_station ps
LEFT JOIN city c ON ps.CityId = c.Id
WHERE ps.Id IN @PowerStationIds
GROUP BY ps.CityId
";
result = (await conn.QueryAsync<CapacityDataTable>(sql, new { PowerStationIds = powerStationIds })).ToList();
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
public async Task<List<PowerStation>> GetListPowerStationByPowerStationIds(List<int> powerStationIds)
{
List<PowerStation> result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = @$"SELECT * FROM power_station ps WHERE ps.Id IN @PowerStationIds
";
result = (await conn.QueryAsync<PowerStation>(sql, new { PowerStationIds = powerStationIds })).ToList();
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
public async Task<List<PowerStation>> GetSolarByCity(MyUser User, UseStatusCityGetPowerStation post)
{
using IDbConnection conn = _databaseHelper.GetConnection();

View File

@ -168,6 +168,25 @@ namespace SolarPower.Repository.Implement
}
}
public override async Task<List<PowerStation>> GetAllAsync()
{
List<PowerStation> result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = $"SELECT * FROM {tableName} WHERE Deleted = 0";
result = (await conn.QueryAsync<PowerStation>(sql)).ToList();
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
/// <summary>
/// 透過電站編號,取得單一電站資訊(覆寫)
/// </summary>
@ -342,6 +361,33 @@ namespace SolarPower.Repository.Implement
}
}
/// <summary>
/// 透過電站編號,取得所有土地房屋資訊
/// </summary>
/// <param name="id"></param>
/// <param name="db_name"></param>
/// <returns></returns>
public async Task<List<LandBuilding>> GetAllLandBuildingInfoByPowerStationId(int id, string db_name)
{
List<LandBuilding> result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = @$"SELECT lb.*, u.Name AS CreatorName FROM {db_name}.land_building lb
LEFT JOIN user u ON lb.CreatedBy = u.Id
WHERE lb.Deleted = 0 AND PowerStationId = @PowerStationId";
result = (await conn.QueryAsync<LandBuilding>(sql, new { PowerStationId = id })).ToList();
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
/// <summary>
/// 取得 土地房屋資訊
/// </summary>
@ -1361,19 +1407,33 @@ namespace SolarPower.Repository.Implement
}
if (User.Role.Layer == 0 || User.Role.Layer == 1)
{
var sql = "SELECT * FROM power_station WHERE CityId IN @IDs";
var sql = @"SELECT ps.* , c.Name AS CityName, a.Name AS AreaName
FROM power_station ps
LEFT JOIN city c ON ps.CityId = c.Id
LEFT JOIN area a ON ps.AreaId = a.Id
WHERE ps.CityId IN @IDs";
powerstation = (await conn.QueryAsync<PowerStation>(sql, new { IDs = CityId })).ToList();
trans.Commit();
}
else if (User.Role.Layer == 2)
{
var sql = "SELECT * FROM power_station WHERE CityId IN @IDs AND CompanyId=@CompanyId";
var sql = @"SELECT ps.* , c.Name AS CityName, a.Name AS AreaName
FROM power_station ps
LEFT JOIN city c ON ps.CityId = c.Id
LEFT JOIN area a ON ps.AreaId = a.Id
WHERE ps.CityId IN @IDs
AND ps.CompanyId=@CompanyId";
powerstation = (await conn.QueryAsync<PowerStation>(sql, new { IDs = CityId, CompanyId = User.CompanyId })).ToList();
trans.Commit();
}
else
{
var sql = "SELECT power_station.* FROM power_station LEFT JOIN power_station_operation_personnel ON power_station.Id = power_station_operation_personnel.PowerStationId WHERE CityId IN @IDs AND Userid = @UserId";
var sql = @"SELECT ps.* , c.Name AS CityName, a.Name AS AreaName
FROM power_station ps
LEFT JOIN city c ON ps.CityId = c.Id
LEFT JOIN area a ON ps.AreaId = a.Id
LEFT JOIN power_station_operation_personnel psop ON ps.Id = psop.PowerStationId
WHERE ps.CityId IN @IDs AND psop.Userid = @UserId";
powerstation = (await conn.QueryAsync<PowerStation>(sql, new { IDs = CityId, UserId = User.Id })).ToList();
trans.Commit();
}
@ -1532,6 +1592,36 @@ namespace SolarPower.Repository.Implement
return count;
}
}
/// <summary>
/// 透過電站Id取得所有控制器編碼
/// </summary>
/// <param name="stationId"></param>
/// <param name="db_name"></param>
/// <returns></returns>
public async Task<List<string>> GetAllDeviceControllerByPowerStationId(int stationId, string db_name)
{
using (IDbConnection conn = _databaseHelper.GetConnection())
{
List<string> result;
conn.Open();
try
{
string sql = $"SELECT ControllerId FROM {db_name}.controller WHERE PowerStationId = {stationId}";
result = (await conn.QueryAsync<string>(sql)).ToList();
}
catch (Exception exception)
{
throw exception;
}
finally
{
conn.Close();
}
return result;
}
}
/// <summary>
/// 逆變器DataTable
/// </summary>
@ -1721,5 +1811,325 @@ namespace SolarPower.Repository.Implement
return result;
}
}
public async Task<PowerStationHistory> GetPowerStationHistoryPerHour(string dateTime, string table_name)
{
PowerStationHistory result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = $@"
SELECT * FROM {table_name} WHERE DATE_FORMAT(FROM_UNIXTIME(timestamp / 1000), '%Y-%m-%d %H') = @DateTime
";
result = await conn.QueryFirstOrDefaultAsync<PowerStationHistory>(sql, new { DateTime = dateTime });
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
public async Task<AvgPowerStationHistory> GetAvgPowerStationHistory30day(string nowDay, string table_name)
{
AvgPowerStationHistory result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var startDay = Convert.ToDateTime(nowDay).AddDays(-30).ToString("yyyy-MM-dd");
var sql = $@"SELECT AVG(s.KWHKWP) AS AvgKWHKWP, AVG(s.PR) AS AvgPR
FROM {table_name} s
WHERE DATE_FORMAT(FROM_UNIXTIME(s.TIMESTAMP/1000), '%Y-%m-%d %H') IN (
SELECT MAX(DATE_FORMAT(FROM_UNIXTIME(s.TIMESTAMP/1000), '%Y-%m-%d %H')) FROM {table_name} s
WHERE DATE_FORMAT(FROM_UNIXTIME(s.TIMESTAMP/1000), '%Y-%m-%d') BETWEEN @StartDay AND @EndDay
GROUP BY DATE_FORMAT(FROM_UNIXTIME(s.TIMESTAMP/1000), '%Y-%m-%d'))
";
result = await conn.QueryFirstOrDefaultAsync<AvgPowerStationHistory>(sql, new { StartDay = startDay, EndDay = nowDay });
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
public async Task<int> AddPowerStationHistory(List<PowerStationHistory> entity, List<string> properties)
{
int count;
using (IDbConnection conn = _databaseHelper.GetConnection())
{
conn.Open();
using (var trans = conn.BeginTransaction())
{
try
{
string sql = GenerateInsertQueryWithCustomTable(properties, "power_station_history_hour");
count = await conn.ExecuteAsync(sql, entity, trans);
trans.Commit();
}
catch (Exception exception)
{
trans.Rollback();
throw exception;
}
finally
{
conn.Close();
}
}
return count;
}
}
public async Task<int> UpdateList(List<PowerStation> entity, List<string> properties)
{
int count;
using (IDbConnection conn = _databaseHelper.GetConnection())
{
conn.Open();
using (var trans = conn.BeginTransaction())
{
try
{
string sql = GenerateUpdateQuery(properties);
count = await conn.ExecuteAsync(sql, entity, trans);
trans.Commit();
}
catch (Exception exception)
{
trans.Rollback();
throw exception;
}
finally
{
conn.Close();
}
}
return count;
}
}
/// <summary>
/// 透過日期,取得最後一筆資料
/// </summary>
/// <param name="day"></param>
/// <param name="table_name"></param>
/// <returns></returns>
public async Task<PowerStationHistoryDay> GetLastOnePowerStationHistoryByDay(string day, string table_name)
{
PowerStationHistoryDay result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = $@"SELECT
DATE_FORMAT(FROM_UNIXTIME(s.TIMESTAMP/1000), '%Y-%m-%d %H') AS TIMESTAMP,
s.SITEID,
s.SITETYPE,
s.TodayKWh,
s.TotalKWH,
s.KWHKWP,
s.PR,
s.MP,
s.SolarHour
FROM {table_name} s
WHERE DATE_FORMAT(FROM_UNIXTIME(s.TIMESTAMP/1000), '%Y-%m-%d') = @Day
ORDER BY TIMESTAMP DESC
LIMIT 1
";
result = await conn.QueryFirstOrDefaultAsync<PowerStationHistoryDay>(sql, new { Day = day });
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
/// <summary>
/// 新增資料,至每日的電站歷史記錄
/// </summary>
/// <param name="entity"></param>
/// <param name="properties"></param>
/// <returns></returns>
public async Task<int> AddPowerStationHistoryDayList(List<PowerStationHistoryDay> entity, List<string> properties)
{
int count;
using (IDbConnection conn = _databaseHelper.GetConnection())
{
conn.Open();
using (var trans = conn.BeginTransaction())
{
try
{
string sql = GenerateInsertQueryWithCustomTable(properties, "power_station_history_day");
count = await conn.ExecuteAsync(sql, entity, trans);
trans.Commit();
}
catch (Exception exception)
{
trans.Rollback();
throw exception;
}
finally
{
conn.Close();
}
}
return count;
}
}
public async Task<PowerStationHistoryMonth> GetOnePowerStationHistoryByPowerStationIdAndMonth(int powerStationId, string month)
{
PowerStationHistoryMonth result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = $@"SELECT *
FROM power_station_history_month s
WHERE PowerStationId = @PowerStationId
AND DATE_FORMAT(s.TIMESTAMP, '%Y-%m')= @Month
";
result = await conn.QueryFirstOrDefaultAsync<PowerStationHistoryMonth>(sql, new { PowerStationId = powerStationId, Month = month });
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
public async Task<PowerStationHistoryMonth> GetPowerStationHistoryMonthDataByPowerStationId(int powerStationId, string month)
{
PowerStationHistoryMonth result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = $@"SELECT
PowerStationId,
DATE_FORMAT(s.TIMESTAMP, '%Y-%m') AS TIMESTAMP,
s.SITEID,
s.SITETYPE,
SUM(s.TODAYKWH) AS MONTHKWH,
MAX(s.TOTALKWH) AS TOTALKWH,
AVG(s.KWHKWP) AS KWHKWP,
AVG(s.PR) AS PR,
AVG(s.MP) AS MP,
SUM(s.SOLARHOUR) AS SOLARHOUR
FROM power_station_history_day s
WHERE DATE_FORMAT(s.TIMESTAMP, '%Y-%m') = @Month
AND PowerStationId = @PowerStationId
GROUP BY PowerStationId,DATE_FORMAT(s.TIMESTAMP, '%Y-%m')
";
result = await conn.QueryFirstOrDefaultAsync<PowerStationHistoryMonth>(sql, new { PowerStationId = powerStationId, Month = month });
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
/// <summary>
/// 新增資料,至每月的電站歷史記錄
/// </summary>
/// <param name="entity"></param>
/// <param name="properties"></param>
/// <returns></returns>
public async Task<int> AddPowerStationHistoryMonthList(List<PowerStationHistoryMonth> entity, List<string> properties)
{
int count;
using (IDbConnection conn = _databaseHelper.GetConnection())
{
conn.Open();
using (var trans = conn.BeginTransaction())
{
try
{
string sql = GenerateInsertQueryWithCustomTable(properties, "power_station_history_month");
count = await conn.ExecuteAsync(sql, entity, trans);
trans.Commit();
}
catch (Exception exception)
{
trans.Rollback();
throw exception;
}
finally
{
conn.Close();
}
}
return count;
}
}
public async Task<int> UpdatePowerStationHistoryMonthList(List<PowerStationHistoryMonth> entity)
{
int count;
using (IDbConnection conn = _databaseHelper.GetConnection())
{
conn.Open();
using (var trans = conn.BeginTransaction())
{
try
{
string sql = @"UPDATE power_station_history_month SET
MonthKWh=@MonthKWh,
TOTALKWH=@TOTALKWH,
KWHKWP=@KWHKWP,
PR=@PR,
MP=@MP,
SolarHour=@SolarHour
WHERE PowerStationId = @PowerStationId
AND TIMESTAMP LIKE CONCAT(@TIMESTAMP, '%')
";
count = await conn.ExecuteAsync(sql, entity, trans);
trans.Commit();
}
catch (Exception exception)
{
trans.Rollback();
throw exception;
}
finally
{
conn.Close();
}
}
return count;
}
}
}
}

View File

@ -417,7 +417,7 @@ namespace SolarPower.Repository.Implement
{
try
{
var sql = $"SELECT * FROM variable WHERE Name = @Name";
var sql = $"SELECT Value FROM variable WHERE Name = @Name";
result = await conn.QueryFirstOrDefaultAsync<string>(sql, new { Name = name });
}

View File

@ -10,6 +10,11 @@ namespace SolarPower.Repository.Interface
{
public interface IOverviewRepository : IRepositoryBase<Overview>
{
Task<List<int>> GetAllCityIdAsync();
Task<Overview> GetOverviewByPowerStationIds(List<int> powerStationIds);
Task<List<CapacityDataTable>> GetCapacityDataTableByPowerStationIds(List<int> powerStationIds);
Task<List<PowerStation>> GetListPowerStationByPowerStationIds(List<int> powerStationIds);
Task<List<PowerStation>> GetSolarByCity(MyUser User, UseStatusCityGetPowerStation post);
}
}

View File

@ -85,6 +85,14 @@ namespace SolarPower.Repository.Interface
/// <returns></returns>
Task UpdateBoETPCInfo(UpdateBoETPCInfo entity, List<string> properties, string db_name);
/// <summary>
/// 透過電站編號,取得所有土地房屋資訊
/// </summary>
/// <param name="id"></param>
/// <param name="db_name"></param>
/// <returns></returns>
Task<List<LandBuilding>> GetAllLandBuildingInfoByPowerStationId(int id, string db_name);
/// <summary>
/// 取得 土地房屋資訊
/// </summary>
@ -416,6 +424,69 @@ namespace SolarPower.Repository.Interface
/// <param name="table_name"></param>
/// <returns></returns>
Task<A> GetoneData<A>(string where, string db_name, string table_name);
/// <summary>
/// 透過電站Id取得所有控制器編碼
/// </summary>
/// <param name="stationId"></param>
/// <param name="db_name"></param>
/// <returns></returns>
Task<List<string>> GetAllDeviceControllerByPowerStationId(int stationId, string db_name);
/// <summary>
/// 透過當前時間,取得電站歷史資料
/// </summary>
/// <param name="dateTime"></param>
/// <param name="table_name"></param>
/// <returns></returns>
Task<PowerStationHistory> GetPowerStationHistoryPerHour(string dateTime, string table_name);
/// <summary>
/// 透過當前日期取得往前推算30天的平均值
/// </summary>
/// <param name="nowDay"></param>
/// <param name="table_name"></param>
/// <returns></returns>
Task<AvgPowerStationHistory> GetAvgPowerStationHistory30day(string nowDay, string table_name);
Task<int> AddPowerStationHistory(List<PowerStationHistory> entity, List<string> properties);
Task<int> UpdateList(List<PowerStation> entity, List<string> properties);
/// <summary>
/// 透過日期,取得最後一筆資料
/// </summary>
/// <param name="day"></param>
/// <param name="table_name"></param>
/// <returns></returns>
Task<PowerStationHistoryDay> GetLastOnePowerStationHistoryByDay(string day, string table_name);
/// <summary>
/// 新增資料,至每日的電站歷史記錄
/// </summary>
/// <param name="entity"></param>
/// <param name="properties"></param>
/// <returns></returns>
Task<int> AddPowerStationHistoryDayList(List<PowerStationHistoryDay> entity, List<string> properties);
/// <summary>
/// 透過月份,取得單一筆資料
/// </summary>
/// <param name="day"></param>
/// <param name="table_name"></param>
/// <returns></returns>
Task<PowerStationHistoryMonth> GetOnePowerStationHistoryByPowerStationIdAndMonth(int powerStationId, string month);
/// <summary>
/// 透過電站編號、月份,取得該月份資訊
/// </summary>
/// <param name="day"></param>
/// <param name="table_name"></param>
/// <returns></returns>
Task<PowerStationHistoryMonth> GetPowerStationHistoryMonthDataByPowerStationId(int powerStationId, string month);
Task<int> AddPowerStationHistoryMonthList(List<PowerStationHistoryMonth> entity, List<string> properties);
Task<int> UpdatePowerStationHistoryMonthList(List<PowerStationHistoryMonth> entity);
/// <summary>
/// 電站日照計列表
/// </summary>

View File

@ -90,11 +90,27 @@ namespace SolarPower
//²K¥[QuartzªA°È
services.AddSingleton<IJobFactory, SingletonJobFactory>();
services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>();
//添加我們的Job
services.AddSingleton<OperationScheduleJob>();
//添加Job
#region
//services.AddSingleton<OperationScheduleJob>();
//services.AddSingleton(
// new JobSchedule(jobType: typeof(OperationScheduleJob), cronExpression: "0/5 * * * * ?")
//);
#endregion
#region (5)
services.AddSingleton<CalcPowerStationJob>();
services.AddSingleton(
new JobSchedule(jobType: typeof(OperationScheduleJob), cronExpression: "0/5 * * * * ?")
new JobSchedule(jobType: typeof(CalcPowerStationJob), cronExpression: "0 5 * * * ?")
);
#endregion
#region PRkWP 30(2)
services.AddSingleton<CalcAvgPowerStationJob>();
services.AddSingleton(
new JobSchedule(jobType: typeof(CalcAvgPowerStationJob), cronExpression: "0 0 2 * * ?")
);
#endregion
services.AddHostedService<QuartzHostedService>();
#endregion
}

View File

@ -129,7 +129,7 @@
</div>
<div class="form-group col-lg-6">
<label class="form-label" for="company_logo_modal">Logo</label>
<label class="form-label" for="company_logo_modal">公司Logo(建議尺寸 200 * 40px)</label>
<input type="file" id="company_logo_modal" name="company_logo_modal" class="form-control" accept="image/*">
</div>
</div>

View File

@ -5,13 +5,161 @@
}
<ol class="breadcrumb page-breadcrumb">
<li class="breadcrumb-item"><a href="javascript:void(0);">總覽</a></li>
<li class="breadcrumb-item active">@ViewData["Title"]</li>
<li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li>
<li class="breadcrumb-item active">地圖總覽</li>
<li class="position-absolute pos-top pos-right d-none d-sm-block">最後更新時間 <span id="update_at"></span></li>
</ol>
<!-- Your main content goes below here: -->
<div class="row mb-5">
<div class="card-columns col-xl-12">
<div class="card">
<div class="card-header bg-fusion-25 py-2 pr-3 d-flex align-items-center flex-wrap">
<h4 class="mb-0 font-weight-bold"><span class="fal fa-bolt mr-1"></span> 發電量</h4>
</div>
<div class="card-body">
<div class="d-flex justify-content-between">
<p>總發電量</p>
<p><span class="color-info-700 fs-xl font-weight-bold" id="today_kwh">126,161.72</span> kWh</p>
</div>
<div class="d-flex justify-content-between">
<p>平均發電量</p>
<p><span class="color-info-700 fs-xl font-weight-bold" id="total_kwh">4,069.73</span> kWh</p>
</div>
</div>
</div>
<div class="card">
<div class="card-header bg-fusion-25 py-2 pr-3 d-flex align-items-center flex-wrap">
<h4 class="mb-0 font-weight-bold"><span class="fal fa-dollar-sign mr-1"></span> 日照度</h4>
</div>
<div class="card-body">
<div class="d-flex justify-content-between">
<p>即時平均日照度</p>
<p><span class="color-info-700 fs-xl font-weight-bold" id="today_irradiance">126,161.72</span> kW/m<sup>2</sup></p>
</div>
<div class="d-flex justify-content-between">
<p>平均日照度(30天)</p>
<p><span class="color-info-700 fs-xl font-weight-bold" id="avg_irradiance">4,069.73</span> kW/m<sup>2</sup></p>
</div>
</div>
</div>
<div class="card">
<div class="card-header bg-fusion-25 py-2 pr-3 d-flex align-items-center flex-wrap">
<h4 class="mb-0 font-weight-bold"><span class="fal fa-bolt mr-1"></span> PR值</h4>
</div>
<div class="card-body">
<div class="d-flex justify-content-between">
<p>即時平均 PR 值</p>
<p><span class="color-info-700 fs-xl font-weight-bold" id="today_PR">119.04</span> hr</p>
</div>
<div class="d-flex justify-content-between">
<p>平均 PR 值(30天)</p>
<p><span class="color-info-700 fs-xl font-weight-bold" id="avg_PR">3.84</span> hr</p>
</div>
</div>
</div>
<div class="card">
<div class="card-header bg-fusion-25 py-2 pr-3 d-flex align-items-center flex-wrap">
<h4 class="mb-0 font-weight-bold"><span class="fal fa-sun mr-1"></span> kWh / kWp</h4>
</div>
<div class="card-body">
<div class="d-flex justify-content-between">
<p>即時平均 kWh / kWp</p>
<p><span class="color-info-700 fs-xl font-weight-bold" id="today_kwhkwp">140.39</span> kW/m2</p>
</div>
<div class="d-flex justify-content-between">
<p>平均 kWh / kWp (30天)</p>
<p><span class="color-info-700 fs-xl font-weight-bold" id="avg_kwhkwp">4.53</span> kW/m2</p>
</div>
</div>
</div>
<div class="card">
<div class="card-header bg-fusion-25 py-2 pr-3 d-flex align-items-center flex-wrap">
<h4 class="mb-0 font-weight-bold"><span class="fal fa-cow mr-1"></span> 減碳量</h4>
</div>
<div class="card-body">
<div class="d-flex justify-content-between">
<p>總減碳量</p>
<p><span class="color-info-700 fs-xl font-weight-bold" id="today_carbon">6,091.78</span> KG</p>
</div>
<div class="d-flex justify-content-between">
<p>今日減碳量</p>
<p><span class="color-info-700 fs-xl font-weight-bold" id="total_carbon">985.98</span> KG</p>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-auto" style="width: 60%;">
<div id="panel-1" class="panel">
<div class="panel-hdr">
<h2>電站分佈圖</h2>
</div>
<div class="panel-container show">
<div class="panel-content">
<div class="map-respondive">
<div id="map" style="width: 100%; height:450px"></div>
</div>
</div>
</div>
</div>
</div>
<div class="col-auto" style="width: 40%;">
<div class="row">
<div class="col-xl-6">
<div class="card">
<div class="card-header bg-fusion-25 py-2 pr-3 d-flex align-items-center flex-wrap">
<h4 class="mb-0 font-weight-bold"><span class="fal fa-bolt mr-1"></span> 電站總數</h4>
</div>
<div class="card-body" style="min-height: 148px;">
<p class="text-center display-3"><span class="color-info-700 font-weight-bold" id="total_power_station_count">52</span></p>
<p class="text-right mb-0">廠</p>
</div>
</div>
</div>
<div class="col-xl-6">
<div class="card">
<div class="card-header bg-fusion-25 py-2 pr-3 d-flex align-items-center flex-wrap">
<h4 class="mb-0 font-weight-bold"><span class="fal fa-bolt mr-1"></span> 總裝置容量</h4>
</div>
<div class="card-body" style="min-height: 148px;">
<p class="text-center display-3"><span class="color-info-700 font-weight-bold" id="total_capacity">1288.63</span></p>
<p class="text-right mb-0">MWp</p>
</div>
</div>
</div>
<div class="col-xl-12 mt-4">
<div id="panel-1" class="panel">
<div class="panel-hdr">
<h2>電站分佈小計</h2>
</div>
<div class="panel-container show">
<div class="panel-content">
<table id="capacity-Table" class="table text-center m-0">
<thead class="thead-themed">
<tr>
<th>縣市</th>
<th>電站數量</th>
<th>裝置容量 MWp</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xl-12">
<div id="map"></div>
<div id="map" style="width: 100%; height:60vh"></div>
</div>
</div>
@ -22,48 +170,27 @@
<script src="https://unpkg.com/@@googlemaps/markerclustererplus/dist/index.min.js"></script>
<script>
var companyTable; var companyAuthTable;
var capacityTable;
var mapOverview;
var locations = [];
$(function () {
//#region 公司管理列表 DataTable
companyTable = $("#company_table").DataTable({
capacityTable = $("#capacity-Table").DataTable({
"paging": true,
"lengthChange": false,
"searching": false,
"ordering": true,
"ordering": false,
"info": true,
"autoWidth": false,
"responsive": true,
"order": [[8, "desc"]],
"columns": [{
"data": "id"
"data": "cityName"
}, {
"data": "logo"
"data": "subPowerStationCount"
}, {
"data": "name"
}, {
"data": "taxIDNumber"
}, {
"data": "phone"
}, {
"data": "address"
}, {
"data": "registerRatio"
}, {
"data": "spStationAmount"
}, {
"data": "createdAt"
}, {
"data": "function",
}],
"columnDefs": [{
'targets': 1,
'searchable': false,
'orderable': false,
'className': 'dt-body-center',
'render': function (data, type, full, meta) {
return '<img src="' + data + '?v=' + Date.now() + '" class="img-fluid">';
}
"data": "subTotalCapacity"
}],
"language": {
"emptyTable": "無資料...",
@ -87,42 +214,55 @@
"sortDescending": ": 降冪排列"
}
},
'createdRow': function (row, data, dataIndex) {
$(row).attr('data-id', data.id);
},
"ajax": {
"url": "/Company/CompanyList",
"type": "POST",
"data": function (d) {
d.SelectedCompanyId = $('#system_admin_account').val();
d.Name = $('#company_name').val();
d.Phone = $('#company_phone').val();
d.TaxIDNumber = $('#company_taxIDNumber').val();
},
"dataSrc": function (rel) {
if (rel.data.code == "9999") {
toast_error(rel.data.msg);
"data": []
});
//#endregion
var url = "/MapOverview/GetMapOverview";
$.post(url, null, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
data = rel.data.data;
mapOverview = rel.data;
if (data == null || data.length == 0) {
this.data = [];
}
$("#today_kwh").html(mapOverview.today_kwh);
$("#total_kwh").html(mapOverview.total_kwh);
$("#today_irradiance").html(mapOverview.today_irradiance);
$("#avg_irradiance").html(mapOverview.avg_irradiance);
$("#today_PR").html(mapOverview.today_PR);
$("#avg_PR").html(mapOverview.avg_PR);
$("#today_kwhkwp").html(mapOverview.today_kwhkwp);
$("#avg_kwhkwp").html(mapOverview.avg_kwhkwp);
$("#today_carbon").html(mapOverview.today_carbon);
$("#total_power_station_count").html(mapOverview.totalPowerStationCount);
$("#total_capacity").html(mapOverview.totalCapacity);
$("#update_at").html(mapOverview.updatedAt);
return data;
}
}
});
//#endregion
capacityTable.clear().rows.add(mapOverview.capacityDataTables).draw();
//#region google map
initMap();
//#endregion
});
});
function initMap() {
mapOverview.powerStations.forEach(function (item, index) {
if (item.coordinate != null) {
var split = item.coordinate.split(',');
if (split[0] == undefined || split[0] == null) {
split[0] = 23
}
if (split[1] == undefined || split[1] == null) {
split[1] = 122
}
locations.push({ lat: parseFloat(split[0]), lng: parseFloat(split[1]) })
}
});
const map = new google.maps.Map(document.getElementById("map"), {
zoom: 7,
center: { lat: 23.5, lng: 123 },
@ -146,32 +286,5 @@
"https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m",
});
}
const locations = [
{ lat: -31.56391, lng: 147.154312 },
{ lat: -33.718234, lng: 150.363181 },
{ lat: -33.727111, lng: 150.371124 },
{ lat: -33.848588, lng: 151.209834 },
{ lat: -33.851702, lng: 151.216968 },
{ lat: -34.671264, lng: 150.863657 },
{ lat: -35.304724, lng: 148.662905 },
{ lat: -36.817685, lng: 175.699196 },
{ lat: -36.828611, lng: 175.790222 },
{ lat: -37.75, lng: 145.116667 },
{ lat: -37.759859, lng: 145.128708 },
{ lat: -37.765015, lng: 145.133858 },
{ lat: -37.770104, lng: 145.143299 },
{ lat: -37.7737, lng: 145.145187 },
{ lat: -37.774785, lng: 145.137978 },
{ lat: -37.819616, lng: 144.968119 },
{ lat: -38.330766, lng: 144.695692 },
{ lat: -39.927193, lng: 175.053218 },
{ lat: -41.330162, lng: 174.865694 },
{ lat: -42.734358, lng: 147.439506 },
{ lat: -42.734358, lng: 147.501315 },
{ lat: -42.735258, lng: 147.438 },
{ lat: -43.999792, lng: 170.463352 },
];
}
</script>
}