1. 逆變器選單列表

2. 修改 逆變器 抓KWH 計算方式
This commit is contained in:
Kai 2021-07-22 19:28:43 +08:00
parent c2d0e04962
commit e42fbc7f76
13 changed files with 343 additions and 118 deletions

View File

@ -1,5 +1,7 @@
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;
@ -23,6 +25,64 @@ namespace SolarPower.Controllers
return View();
}
[HttpPost]
public async Task<ApiResult<Dictionary<string, Dictionary<string, List<PowerStationInverter>>>>> GetInverterCollapse(string filter)
{
ApiResult<Dictionary<string, Dictionary<string, List<PowerStationInverter>>>> apiResult = new ApiResult<Dictionary<string, Dictionary<string, List<PowerStationInverter>>>>();
try
{
var powerStations = new List<PowerStation>();
if (IsPlatformLayer(myUser.Role.Layer))
{
powerStations = await powerStationRepository.GetAllAsync();
}
else
{
powerStations = await powerStationRepository.GetPowerStationsByCompanyId(myUser.CompanyId);
}
var siteDBNamePowerStationId = new Dictionary<string, List<int>>();
var powerStation_Group = powerStations.GroupBy(x => x.SiteDB).ToList();
foreach(var stations in powerStation_Group)
{
var powerStationIds = stations.Select(x => x.Id).ToList();
siteDBNamePowerStationId.Add(stations.Key, powerStationIds);
}
var powerStationInverters = await powerStationRepository.GetPowerStationInverter(siteDBNamePowerStationId, filter);
powerStationInverters = powerStationInverters.Where(x => x.InverterId != null).ToList();
var powerStationInverter_Group = powerStationInverters.GroupBy(x => x.CityName).ToList();
var inverterCollapse = new Dictionary<string, Dictionary<string, List<PowerStationInverter>>>();
foreach (var powerStationInverter in powerStationInverter_Group)
{
var inverter_Group = powerStationInverter.GroupBy(x => x.PowerStationName).ToList();
var inverterDic = new Dictionary<string, List<PowerStationInverter>>();
foreach (var inverter in inverter_Group)
{
inverterDic.Add(inverter.Key, inverter.ToList());
}
inverterCollapse.Add(powerStationInverter.Key, inverterDic);
}
apiResult.Code = "0000";
apiResult.Data = inverterCollapse;
}
catch (Exception exception)
{
apiResult.Code = "9999";
Logger.LogError("【" + controllerName + "/" + actionName + "】");
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
apiResult.Msg = errorCode.GetString(apiResult.Code);
return apiResult;
}
}
}

View File

@ -1963,9 +1963,14 @@ CREATE TABLE `sensoravg_history_month` (
COMMENT='各電站每月的sensor avg 歷史資料'
COLLATE='utf8mb4_unicode_ci'
ENGINE=InnoDB
AUTO_INCREMENT=2
;
-- 新增電站欄位 20210721
ALTER TABLE `power_station`
ADD COLUMN `line_token` VARCHAR(255) NULL AFTER `RateOfRain`,
ADD COLUMN `Estimate_kwh` DECIMAL(10,2) NULL DEFAULT '0.00' COMMENT '預估發電度數' AFTER `line_token`,
ADD COLUMN `EstimateEfficacy` DECIMAL(10,2) NULL DEFAULT '0.00' COMMENT '預估發電效能' AFTER `Estimate_kwh`;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;

View File

@ -5,7 +5,14 @@ using System.Threading.Tasks;
namespace SolarPower.Models
{
public class PowerStationInverter
{
public int PowerStationId { get; set; }
public string CityName { get; set; }
public string PowerStationName { get; set; }
public string InverterName { get; set; }
public string InverterId { get; set; }
}
public class AnalysisInverter
{

View File

@ -26,7 +26,7 @@ namespace SolarPower.Quartz.Jobs
try
{
//var day_array = new string[] { "15", "16", "17", "18", "19" };
////var day_array = new string[] { "15" };
//var day_array = new string[] { "22" };
//var time_array = new string[] { "00:02", "00:17", "00:32", "00:47",
// "01:02", "01:17", "01:32", "01:47",
// "02:02", "02:17", "02:32", "02:47",
@ -73,12 +73,11 @@ namespace SolarPower.Quartz.Jobs
// {
//var dateNowTime = string.Format("2021-07-{0} {1}", day_array[i], time_array[j]);
#region step2. DB及電站編號找出該電站的控制器
foreach (var powerStation in powerStations)
{
//取得所有該電站的逆變器
logger.LogInformation("【CalcInverter15minJob】【開始取得電站[{0}]在{1}的逆變器設備資訊】", powerStation.Code, dateNowTime);
var controllers = await powerStationRepository.GetAllDeviceControllerId(powerStation.Id, powerStation.SiteDB);
@ -98,6 +97,7 @@ namespace SolarPower.Quartz.Jobs
logger.LogInformation("【CalcInverter15minJob】【開始計算電站[{0}]在{1}的每15分鐘逆變器資訊】", powerStation.Code, dateNowTime);
calcInverter15mins = await powerStationRepository.CalcInverterHisyort15minData(dateNowTime, powerStation.SiteDB, full_table_name, inverterIds);
logger.LogInformation("【CalcInverter15minJob】【計算完成電站[{0}]在{1}的每15分鐘逆變器資訊】", powerStation.Code, dateNowTime);
logger.LogInformation("【CalcInverter15minJob】【計算結果】 - {0}", System.Text.Json.JsonSerializer.Serialize(calcInverter15mins));
if (calcInverter15mins.Count() > 0)
{
foreach (var inverterHistory in calcInverter15mins)
@ -130,9 +130,6 @@ namespace SolarPower.Quartz.Jobs
#endregion
// }
//}
}
catch (Exception exception)
{

View File

@ -429,7 +429,7 @@ namespace SolarPower.Repository.Implement
{
var sql = @$"
--
CREATE DATABASE IF NOT EXISTS `{db_name}`;
CREATE DATABASE IF NOT EXISTS `{db_name}` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */;
USE `{db_name}`;
-- controller
@ -437,8 +437,8 @@ namespace SolarPower.Repository.Implement
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`Deleted` tinyint(4) NOT NULL DEFAULT '0' COMMENT ' 0: 1:',
`PowerStationId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '',
`ControllerId` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '',
`SerialNumber` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '',
`ControllerId` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '',
`SerialNumber` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`CreatedBy` int(10) unsigned NOT NULL,
`CreatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`UpdatedBy` int(10) unsigned DEFAULT NULL,
@ -481,7 +481,7 @@ namespace SolarPower.Repository.Implement
`Enabled` tinyint(4) DEFAULT '0' COMMENT '0: 1:',
`Status` tinyint(4) DEFAULT '0' COMMENT '0: 1: 2:',
`InstallDate` timestamp NULL DEFAULT NULL COMMENT '',
`SerialNumber` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '()',
`SerialNumber` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '()',
`InverterName` varchar(50) DEFAULT NULL COMMENT '',
`InverterId` varchar(50) DEFAULT NULL COMMENT 'UID',
`ControllerId` int(10) DEFAULT NULL COMMENT '',
@ -536,70 +536,76 @@ namespace SolarPower.Repository.Implement
-- power_station
CREATE TABLE IF NOT EXISTS `power_station` (
`Id` int(10) unsigned NOT NULL DEFAULT '0',
`Deleted` TINYINT(4) NOT NULL DEFAULT '0' COMMENT ' 0: 1:',
`CompanyId` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '',
`CityId` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '',
`AreaId` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '',
`HealthStatus` TINYINT(4) UNSIGNED NOT NULL DEFAULT '1' COMMENT '1: 2: 3:',
`Address` VARCHAR(100) NULL DEFAULT NULL COMMENT '' COLLATE 'utf8mb4_unicode_ci',
`Name` VARCHAR(50) NULL DEFAULT NULL COMMENT '' COLLATE 'utf8mb4_unicode_ci',
`MainDisplay` VARCHAR(50) NULL DEFAULT NULL COMMENT '' COLLATE 'utf8mb4_unicode_ci',
`Code` VARCHAR(50) NULL DEFAULT NULL COMMENT '++' COLLATE 'utf8mb4_unicode_ci',
`SerialNumber` VARCHAR(4) NULL DEFAULT NULL COMMENT '' COLLATE 'utf8mb4_unicode_ci',
`IsEscrow` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '0: 1:',
`EscrowName` VARCHAR(50) NULL DEFAULT NULL COMMENT '' COLLATE 'utf8mb4_unicode_ci',
`ElectricityMeterAt` TIMESTAMP NULL DEFAULT NULL COMMENT '',
`EstimatedRecoveryTime` VARCHAR(10) NULL DEFAULT NULL COMMENT '' COLLATE 'utf8mb4_unicode_ci',
`GeneratingCapacity` DECIMAL(10,1) NOT NULL DEFAULT '0.0' COMMENT '()',
`PowerRate` DECIMAL(10,3) NOT NULL DEFAULT '0.000' COMMENT '',
`Coordinate` VARCHAR(50) NULL DEFAULT NULL COMMENT '' COLLATE 'utf8mb4_unicode_ci',
`InverterBrand` VARCHAR(50) NULL DEFAULT NULL COMMENT '' COLLATE 'utf8mb4_unicode_ci',
`InverterProductModel` VARCHAR(50) NULL DEFAULT NULL COMMENT '' COLLATE 'utf8mb4_unicode_ci',
`InverterAmount` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '',
`PhotovoltaicPanelBrand` VARCHAR(50) NULL DEFAULT NULL COMMENT '' COLLATE 'utf8mb4_unicode_ci',
`PhotovoltaicPanelProductModel` VARCHAR(50) NULL DEFAULT NULL COMMENT '' COLLATE 'utf8mb4_unicode_ci',
`PhotovoltaicPanelSpecification` VARCHAR(100) NULL DEFAULT NULL COMMENT '' COLLATE 'utf8mb4_unicode_ci',
`PhotovoltaicPanelAmount` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '',
`BoEFileName` VARCHAR(255) NULL DEFAULT NULL COMMENT '' COLLATE 'utf8mb4_unicode_ci',
`BoEFile` VARCHAR(255) NULL DEFAULT NULL COMMENT '' COLLATE 'utf8mb4_unicode_ci',
`BoEDiscountRate` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '',
`BoEDeviceRegisterNumber` VARCHAR(50) NULL DEFAULT NULL COMMENT '' COLLATE 'utf8mb4_unicode_ci',
`BoERentRatio` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '(%)',
`TPCContractNumber` VARCHAR(50) NULL DEFAULT NULL COMMENT '' COLLATE 'utf8mb4_unicode_ci',
`TPCContractAt` TIMESTAMP NULL DEFAULT NULL COMMENT '',
`TPCSellDeadline` INT(10) UNSIGNED NULL DEFAULT '0' COMMENT '()',
`TPCMeterReading` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '',
`TPCPurchaseElectricityAt` TIMESTAMP NULL DEFAULT NULL COMMENT '',
`TPCSellElectricityAt` TIMESTAMP NULL DEFAULT NULL COMMENT '',
`SolarType` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '',
`kwh` DECIMAL(10,3) UNSIGNED NOT NULL DEFAULT '0.000',
`Today_kwh` DECIMAL(10,3) UNSIGNED NOT NULL DEFAULT '0.000' COMMENT '',
`Total_kwh` DECIMAL(10,3) UNSIGNED NOT NULL DEFAULT '0.000' COMMENT '',
`today_kwhkwp` DECIMAL(10,3) NULL DEFAULT NULL COMMENT 'kwhkwp',
`avg_kwhkwp` DECIMAL(10,3) NULL DEFAULT NULL COMMENT '30kwhkwp',
`today_money` DECIMAL(10,2) NULL DEFAULT NULL COMMENT '',
`total_money` DECIMAL(10,2) NULL DEFAULT NULL COMMENT '',
`today_PR` DECIMAL(5,2) NULL DEFAULT NULL COMMENT 'Pr值',
`avg_PR` DECIMAL(5,2) NULL DEFAULT NULL COMMENT 'Pr值',
`today_carbon` DECIMAL(10,2) NULL DEFAULT NULL COMMENT '',
`total_carbon` DECIMAL(10,2) NULL DEFAULT NULL COMMENT '',
`today_irradiance` DECIMAL(5,2) NULL DEFAULT NULL COMMENT '',
`avg_irradiance` DECIMAL(5,2) NULL DEFAULT NULL COMMENT '',
`SolarHour` DECIMAL(5,2) UNSIGNED NOT NULL DEFAULT '0.00' COMMENT '',
`SiteDB` VARCHAR(20) NULL DEFAULT NULL COMMENT ' DB name: solar_com' COLLATE 'utf8mb4_unicode_ci',
`TodayWeather` VARCHAR(20) NULL DEFAULT NULL COMMENT '' COLLATE 'utf8mb4_unicode_ci',
`TodayWeatherTemp` DECIMAL(5,2) UNSIGNED NOT NULL DEFAULT '0.00' COMMENT '',
`CreatedBy` INT(10) UNSIGNED NOT NULL COMMENT '',
`CreatedAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '',
`UpdatedBy` INT(10) UNSIGNED NULL DEFAULT NULL COMMENT '',
`UpdatedAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '',
PRIMARY KEY (`Id`),
KEY `IDX_01` (`Deleted`),
KEY `IDX_02` (`CompanyId`),
KEY `IDX_03` (`CityId`,`AreaId`)
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`Deleted` tinyint(4) NOT NULL DEFAULT '0' COMMENT ' 0: 1:',
`CompanyId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '',
`CityId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '',
`AreaId` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '',
`HealthStatus` tinyint(4) unsigned NOT NULL DEFAULT '1' COMMENT '1: 2: 3:',
`Address` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`Name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`MainDisplay` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`Code` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '++',
`SerialNumber` varchar(4) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`IsEscrow` tinyint(4) NOT NULL DEFAULT '0' COMMENT '0: 1:',
`EscrowName` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`ElectricityMeterAt` timestamp NULL DEFAULT NULL COMMENT '',
`EstimatedRecoveryTime` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`GeneratingCapacity` decimal(10,1) NOT NULL DEFAULT '0.0' COMMENT '()',
`PowerRate` decimal(10,3) NOT NULL DEFAULT '0.000' COMMENT '',
`Coordinate` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`InverterBrand` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`InverterProductModel` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`InverterAmount` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '',
`PhotovoltaicPanelBrand` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`PhotovoltaicPanelProductModel` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`PhotovoltaicPanelSpecification` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`PhotovoltaicPanelAmount` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '',
`BoEFileName` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`BoEFile` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`BoEDiscountRate` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '',
`BoEDeviceRegisterNumber` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`BoERentRatio` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '(%)',
`TPCContractNumber` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`TPCContractAt` timestamp NULL DEFAULT NULL COMMENT '',
`TPCSellDeadline` int(10) unsigned DEFAULT '0' COMMENT '()',
`TPCMeterReading` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '',
`TPCPurchaseElectricityAt` timestamp NULL DEFAULT NULL COMMENT '',
`TPCSellElectricityAt` timestamp NULL DEFAULT NULL COMMENT '',
`SolarType` tinyint(4) NOT NULL DEFAULT '0' COMMENT '',
`kwh` decimal(10,3) unsigned NOT NULL DEFAULT '0.000',
`Today_kwh` decimal(10,3) unsigned NOT NULL DEFAULT '0.000' COMMENT '',
`Total_kwh` decimal(10,3) unsigned NOT NULL DEFAULT '0.000' COMMENT '',
`today_kwhkwp` decimal(10,3) DEFAULT NULL COMMENT 'kwhkwp',
`avg_kwhkwp` decimal(10,3) DEFAULT NULL COMMENT '30kwhkwp',
`today_money` decimal(10,2) DEFAULT NULL COMMENT '',
`total_money` decimal(10,2) DEFAULT NULL COMMENT '',
`today_PR` decimal(5,2) DEFAULT NULL COMMENT 'Pr值',
`avg_PR` decimal(5,2) DEFAULT NULL COMMENT 'Pr值',
`today_carbon` decimal(10,2) DEFAULT NULL COMMENT '',
`total_carbon` decimal(10,2) DEFAULT NULL COMMENT '',
`today_irradiance` decimal(5,2) DEFAULT NULL COMMENT '',
`avg_irradiance` decimal(5,2) DEFAULT NULL COMMENT '',
`SolarHour` decimal(5,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '',
`SiteDB` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT ' DB name: solar_com',
`TodayWeather` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`TodayWeatherTemp` decimal(5,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '',
`WeathersStationId` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`RateOfRain` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
`line_token` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`Estimate_kwh` decimal(10,2) DEFAULT '0.00' COMMENT '',
`EstimateEfficacy` decimal(10,2) DEFAULT '0.00' COMMENT '',
`CreatedBy` int(10) unsigned NOT NULL COMMENT '',
`CreatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '',
`UpdatedBy` int(10) unsigned DEFAULT NULL COMMENT '',
`UpdatedAt` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '',
PRIMARY KEY (`Id`) USING BTREE,
KEY `IDX_01` (`Deleted`) USING BTREE,
KEY `IDX_02` (`CompanyId`) USING BTREE,
KEY `IDX_03` (`CityId`,`AreaId`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='';
-- power_station_exception
CREATE TABLE IF NOT EXISTS `power_station_exception` (
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT,

View File

@ -202,7 +202,7 @@ namespace SolarPower.Repository.Implement
FROM power_station_history_hour ps
LEFT JOIN sensor_history_hour pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d %H') = DATE_FORMAT(pyr.timestamp, '%Y-%m-%d %H')
WHERE ps.PowerStationId = @PowerStationId
AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = @NowDay";
AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = @NowDay ORDER BY ps.timestamp";
result = (await conn.QueryAsync<PowerIrradiance>(sql_power, new { PowerStationId = powerStationId, NowDay = nowDay })).ToList();
}
@ -226,7 +226,7 @@ namespace SolarPower.Repository.Implement
FROM power_station_history_day ps
LEFT JOIN sensor_history_day pyr ON ps.PowerStationId = pyr.PowerStationId AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') = DATE_FORMAT(pyr.timestamp, '%Y-%m-%d')
WHERE ps.PowerStationId = @PowerStationId
AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') BETWEEN @StartDay AND @NowDay";
AND DATE_FORMAT(ps.timestamp, '%Y-%m-%d') BETWEEN @StartDay AND @NowDay ORDER BY ps.timestamp";
result = (await conn.QueryAsync<PowerIrradiance>(sql_power, new { PowerStationId = powerStationId, StartDay = startDay, NowDay = nowDay })).ToList();
}
@ -319,7 +319,7 @@ namespace SolarPower.Repository.Implement
//var endDataTime = dateTime + " 19:00";
//var sql = @$"SELECT * FROM inverter_history_15min WHERE PowerStationId = @PowerStationId AND DATE_FORMAT(TIMESTAMP, '%Y-%m-%d %H:%i') BETWEEN @StartDateTime AND @EndDateTime";
var sql = @$"SELECT * FROM inverter_history_15min WHERE PowerStationId = @PowerStationId AND DATE_FORMAT(TIMESTAMP, '%Y-%m-%d') = @DateTime";
var sql = @$"SELECT * FROM inverter_history_15min WHERE PowerStationId = @PowerStationId AND DATE_FORMAT(TIMESTAMP, '%Y-%m-%d') = @DateTime ORDER BY TIMESTAMP";
result = (await conn.QueryAsync<InverterHistory>(sql, new { PowerStationId = powerStationId, DateTime = dateTime })).ToList();
}

View File

@ -2618,7 +2618,7 @@ namespace SolarPower.Repository.Implement
a.KWH,
s.TODAYKWH,
i.Capacity,
(a.KWH/i.Capacity) AS KWHKWP
a.KWH/(i.Capacity/4) AS KWHKWP
FROM (SELECT
MAX(FROM_UNIXTIME(sub_inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i')) AS TIMESTAMP,
sub_inv.INVERTERID,
@ -2630,7 +2630,7 @@ namespace SolarPower.Repository.Implement
LEFT JOIN (
SELECT MAX(FROM_UNIXTIME(sub_inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i')) AS TIMESTAMP,
sub_inv.INVERTERID,
AVG(sub_inv.WH)/1000 AS KWH
SUM(sub_inv.WH)/1000 AS KWH
FROM {table_name} sub_inv
WHERE FROM_UNIXTIME(sub_inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i') BETWEEN @StartDateTime AND @EndDateTime
AND sub_inv.INVERTERID IN @InverterIds
@ -2738,7 +2738,7 @@ namespace SolarPower.Repository.Implement
SELECT
FROM_UNIXTIME(inv.TIMESTAMP/1000, '%Y-%m-%d %H') AS TIMESTAMP,
inv.INVERTERID,
AVG(inv.WH)/1000 AS KWH
SUM(inv.WH)/1000 AS KWH
FROM {table_name} inv
WHERE DATE_FORMAT(FROM_UNIXTIME(inv.TIMESTAMP/1000), '%Y-%m-%d %H') = @DateTime
AND inv.INVERTERID IN @InverterIds
@ -2860,7 +2860,7 @@ namespace SolarPower.Repository.Implement
AVG(inv.RA3) AS RA3,
AVG(inv.RA4) AS RA4,
AVG(inv.RA5) AS RA5,
AVG(inv.KWH) AS KWH,
SUM(inv.KWH) AS KWH,
MAX(inv.TODAYKWH) AS TODAYKWH,
MAX(inv.TODAYKWH) / i.Capacity AS KWHKWP
FROM inverter_history_hour inv
@ -2981,7 +2981,7 @@ namespace SolarPower.Repository.Implement
AVG(inv.RA3) AS RA3,
AVG(inv.RA4) AS RA4,
AVG(inv.RA5) AS RA5,
AVG(inv.KWH) AS KWH,
SUM(inv.KWH) AS KWH,
SUM(inv.TODAYKWH) AS TODAYKWH,
SUM(inv.TODAYKWH) / i.Capacity AS KWHKWP
FROM inverter_history_day inv
@ -3608,5 +3608,69 @@ namespace SolarPower.Repository.Implement
return count;
}
}
public async Task<List<PowerStation>> GetPowerStationsByCompanyId(int companyId)
{
List<PowerStation> result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = $"SELECT * FROM {tableName} WHERE Deleted = 0 AND CompanyId = @CompanyId";
result = (await conn.QueryAsync<PowerStation>(sql, new { CompanyId = companyId })).ToList();
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
public async Task<List<PowerStationInverter>> GetPowerStationInverter(Dictionary<string, List<int>> dic, string filter)
{
List<PowerStationInverter> result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
List<string> sql_perSiteDB = new List<string>();
var sql = "";
foreach(var powerStationDic in dic)
{
var powerStationIds = string.Join(",", powerStationDic.Value);
var temp_sql = @$"SELECT ps.Id AS PowerStationId,
c.Name AS CityName,
ps.Name AS PowerStationName,
inv.InverterName AS InverterName,
inv.InverterId AS InverterId
FROM power_station ps
LEFT JOIN `city` c ON ps.CityId = c.Id
LEFT JOIN {powerStationDic.Key}.controller con ON ps.Id = con.PowerStationId
LEFT JOIN {powerStationDic.Key}.inverter inv ON con.Id = inv.ControllerId
WHERE ps.Deleted = 0
AND ps.Id IN ({powerStationIds})";
if (!string.IsNullOrEmpty(filter))
{
temp_sql += " AND inv.InverterName LIKE CONCAT('%', @Filter, '%')";
}
sql_perSiteDB.Add(temp_sql);
}
sql = string.Join(" UNION ", sql_perSiteDB);
result = (await conn.QueryAsync<PowerStationInverter>(sql, new { Filter = filter})).ToList();
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
}
}

View File

@ -546,5 +546,7 @@ namespace SolarPower.Repository.Interface
Task<SensorAvgHistory> CalcSensorAvgHistoryMonthDataByPowerStationId(string month, int powerStationId);
Task<int> AddSensorAvgHistoryMonthList(List<SensorAvgHistory> entity, List<string> properties);
Task<int> UpdateSensorAvgHistoryMonthList(List<SensorAvgHistory> entity);
Task<List<PowerStation>> GetPowerStationsByCompanyId(int companyId);
Task<List<PowerStationInverter>> GetPowerStationInverter(Dictionary<string, List<int>> dic, string filter);
}
}

View File

@ -212,35 +212,6 @@
<div class="pr-3">
<button type="button" class="btn btn-secondary waves-effect waves-themed">查詢</button>
</div>
</div>
<div class="mb-5">
<div class="card p-3 w-100">
<h5 class="font-weight-bold mb-3 pl-5 pb-3">總結</h5>
<table class="table m-0">
<thead>
<tr>
<th>時間</th>
<th>發電量(kWh)</th>
<th>發電小時</th>
<th>日射量(kWh/m2)</th>
<th>PR(%)</th>
<th>溫度修正PR(%)</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">2021-05</th>
<td>126,121.7</td>
<td>119.04</td>
<td>140.39</td>
<td>84.8</td>
<td>91.9</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="mb-5">
@ -290,6 +261,7 @@
var searchType = 0;//搜尋條件(日,日區間,月,年)
var datepicker;
var timerange;//選取時間
var selecterd_invert = [];
$(function () {
//#region 預設初始值
@ -300,6 +272,9 @@
timerange = $('#DateGet').val();
//#endregion
//#region 載入左邊選單列表
GetPowerStationCollapse("");
//#endregion
})
function myfunc(div) {
@ -454,5 +429,116 @@
timerange = $('#DateGettext').val();
});
//#endregion
$("#js_list_accordion_filter").change(function (e) {
GetPowerStationCollapse($(this).val());
});
$('#js_list_accordion').on("change", 'input[name="selectedInverterId[]"]', function (event) {
if (this.checked) {
if ($.inArray(this.value, selecterd_invert) < 0) {
selecterd_invert.push(this.value);
}
} else {
if ($.inArray(this.value, selecterd_invert) > -1) {
selecterd_invert.slice($.inArray(this.value, selecterd_invert), 1);
}
}
console.log(selecterd_invert);
});
$('#js_list_accordion').on("change", 'input[name="selectedInverterLayer2[]"]', function (event) {
if (this.checked) {
$(this).parents(".list-group-item").find('input[name="selectedInverterId[]"]').prop("checked", true).trigger("change");
} else {
$(this).parents(".list-group-item").find('input[name="selectedInverterId[]"]').prop("checked", false).trigger("change");
}
});
function GetPowerStationCollapse(filter) {
var url = "/AnalysisInverter/GetInverterCollapse"
var send_data = {
Filter: filter
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.data.msg);
return;
}
var inverterCollapse = rel.data;
$('#js_list_accordion').empty();
if (inverterCollapse.length <= 0) {
$('#js_list_accordion').append("<div>查無結果</div>");
}
var str = "";
Object.keys(inverterCollapse).map(function (key, index) {
str += '<div class="card border-top-left-radius-0 border-top-right-radius-0" id="templateCard">' +
'<div class="card-header">' +
'<a href="javascript:void(0);" class="card-title collapsed" data-toggle="collapse" data-target="#js_list_accordion-' + index + '" aria-expanded="false" data-filter-tags="settings">' +
'<i class="fal fa-globe width-2 fs-xl"></i>' +
'<span class="city-name">' + key + '</span>' +
'<span class="ml-auto">' +
'<span class="collapsed-reveal"><i class="fal fa-chevron-up fs-xl"></i></span>' +
'<span class="collapsed-hidden"><i class="fal fa-chevron-down fs-xl"></i></span>' +
'</span>' +
'</a>' +
'</div>' +
'<div id="js_list_accordion-' + index + '" class="collapse" data-parent="#js_list_accordion" style="">' +
'<div class="card-body">' +
'<ul class="list-group list-group-flush">';
Object.keys(inverterCollapse[key]).map(function (powerStationkey, index) {
str += '<li class="list-group-item">' +
'<div class="d-flex justify-content-between">' +
'<h4 class="font-weight-bold"><i class="fal fa-charging-station"></i> ' + powerStationkey + '</h4>' +
'<div class="">' +
'<input type="checkbox" class="" name="selectedInverterLayer2[]" >' +
'</div>' +
'</div>' +
'<ul class="list-group list-group-flush">';
$.each(inverterCollapse[key][powerStationkey], function (index, inverter) {
str += '<li class="list-group-item pr-0 d-flex justify-content-between">' +
'<a href="#"><i class="fal fa-server"></i>&nbsp;' + inverter.inverterName + '</a>' +
'<div class=""><input type="checkbox" class="" name="selectedInverterId[]" value="' + inverter.inverterId + '">' + '</div>'
'</li>';
});
str += '</ul>' +
'</li>';
});
str += '</ul>';
str += '</div>';
str += '</div>';
});
$('#js_list_accordion').append(str);
$('#js_list_accordion').find('.card').first().addClass(" border-top-left-radius-0 border-top-right-radius-0");
if (selecterd_invert.length <= 0) {
var first_val = Object.values(inverterCollapse)[0];
var child_val = Object.values(Object.values(inverterCollapse)[0])[0];
selecterd_invert.push(Object.values(Object.values(inverterCollapse)[0])[0][0].inverterId)
}
$('input[name="selectedInverterId[]"]').each(function () {
if ($.inArray(this.value, selecterd_invert) > -1) {
$(this).prop('checked', true);
}
});
}, 'json');
}
</script>
}

View File

@ -108,7 +108,7 @@
<!-- BEGIN Left Aside -->
<aside class="page-sidebar">
<div class="page-logo">
<a href="#" class="page-logo-link press-scale-down" data-toggle="modal" data-target="#modal-shortcut">
<a href="#" class="page-logo-link press-scale-down">
<img src="~/img/logo.png" alt="SmartAdmin WebApp" aria-roledescription="logo"> <span class="page-logo-text mr-1"></span> <span class="position-absolute text-white opacity-50 small pos-top pos-right mr-2 mt-n2"></span>
<!--<i class="fal fa-angle-down d-inline-block ml-1 fs-lg color-primary-300"></i>-->
</a>

View File

@ -1736,7 +1736,7 @@
function CreatePowerStationImagecarousel(dom, value, index) {
var indicators = '<li data-target="#carouselExampleIndicators" data-slide-to="' + index + '"></li>'
var carousel_item = '<div class="carousel-item">' +
'<img class="d-block w-100" width="250px" height="150" src="' + value.image + '">' +
'<img class="d-block w-100" src="' + value.image + '">' +
'</div>'
dom.find(".carousel-indicators").append(indicators);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long