檢查項目

This commit is contained in:
b110212000 2021-09-07 17:59:59 +08:00
parent ee5e10dace
commit e1326493b8
7 changed files with 410 additions and 7 deletions

View File

@ -3161,5 +3161,53 @@ namespace SolarPower.Controllers
return apiResult;
}
public async Task<ApiResult<List<string>>> CheckStationStatus (int Id)
{
ApiResult<List<string>> apiResult = new ApiResult<List<string>>();
List<string> status = new List<string>();
try
{
var powerStation = await powerStationRepository.GetOneAsync(Id);
status = await powerStationRepository.CheckStationStatus(powerStation.Code, powerStation.SiteDB);
if(status.Count > 0)
{
apiResult.Code = "0099";
apiResult.Data = status;
}
else
{
await powerStationRepository.StationStatus(Id,1);
apiResult.Msg = "電站啟用成功";
apiResult.Code = "0000";
}
}
catch (Exception exception)
{
apiResult.Code = "9999";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
public async Task<ApiResult<string>> StationUnStatus(int Id)
{
ApiResult<string> apiResult = new ApiResult<string>();
try
{
await powerStationRepository.StationStatus(Id, 0);
apiResult.Msg = "電站停用成功";
apiResult.Code = "0000";
}
catch (Exception exception)
{
apiResult.Code = "9999";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
}
}

View File

@ -2191,7 +2191,8 @@ ALTER TABLE `power_station`
CHANGE COLUMN `today_irradiance` `today_irradiance` DECIMAL(5,2) UNSIGNED NOT NULL DEFAULT '0.00' COMMENT '今日日照度' AFTER `total_carbon`,
CHANGE COLUMN `avg_irradiance` `avg_irradiance` DECIMAL(5,2) UNSIGNED NOT NULL DEFAULT '0.00' COMMENT '平均日照度' AFTER `today_irradiance`;
ALTER TABLE `power_station`
ADD COLUMN `Status` TINYINT(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '是否啟用, 0:否 1:是' AFTER `AreaId`;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;

View File

@ -30,6 +30,7 @@ namespace SolarPower.Models.PowerStation
public int Id { get; set; }
public byte HealthStatus { get; set; } //狀態
public int Status { get; set; }//停用啟用
public int CompanyId { get; set; }
public int CityId { get; set; } //縣市
public string CityName { get; set; } //縣市名稱

View File

@ -13,6 +13,7 @@ using System.Text.Json;
using SolarPower.Models;
using SolarPower.Models.Role;
using SolarPower.Models.Company;
using MySql.Data.MySqlClient;
namespace SolarPower.Repository.Implement
{
@ -5426,5 +5427,286 @@ namespace SolarPower.Repository.Implement
}
}
}
public async Task<List<string>> CheckStationStatus (string code , string DBname)
{
List<string> result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
List<PowerstationOption> devices = new List<PowerstationOption>
{
new PowerstationOption{Text="日照計",Value="PYR"},
new PowerstationOption{Text="模組溫度計",Value="MTR"}
};
// devices.Add(new PowerstationOption { Text = "電表", Value = "PWR" });
var sql2 = "";
foreach (var device in devices)
{
sql2 += @$"#檢查是否存在設備({device.Text})#
set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason)
select ', siteID ,', ''device'', ''device_Type_{device.Value}'',
case when count(*) > 0 then 0 else 1 end isError,
now(),
case when count(*) > 0 then Null else ''{device.Text}'' end error_reason
from {DBname}.device b
join power_station a on a.Id = b.PowerStationId
where b.Deleted = 0 and b.Enabled = 1 and b.Status = 1 and b.Type = ''{device.Value}'' and a.`Code` = ', siteID );
prepare stmt from @qry1 ;
execute stmt ;";
}
List<string> tables = new List<string>
{
"inv",
"station",
"sensor",
"sensoravg",
};
// tables.Add("meter");
var sql3 = "";
foreach (var table in tables)
{
sql3 += @$"# 檢查資料表_{table}是否存在#
set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason)
select ', siteID ,', ''{table}'', ''{table}_Table'',
case when count(*) > 0 then 0 else 1 end isError,
now(),
case when count(*) > 0 then Null else ''_{table}'' end error_reason
from information_schema.SCHEMATA,information_schema.TABLES
where SCHEMA_NAME = ''{DBname}'' AND Table_schema = ''{DBname}'' AND TABLE_NAME = ''s{code}01_{table}''');
prepare stmt from @qry1;
execute stmt;";
}
var sql = $@"DROP PROCEDURE IF EXISTS `sp_power_station_enable_check` ;
CREATE PROCEDURE `sp_power_station_enable_check`( siteID varchar(20) )
BEGIN
declare _siteDB varchar(20);
declare _siteNo int(2);
SELECT SiteDB into _siteDB
from power_station where `code` = siteID;
#clear check result
set @qry1:= concat('delete from power_station_enable_check where `siteID` = ', siteID );
prepare stmt from @qry1 ;
execute stmt ;
#()#
SET @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason)
select ', siteID ,', ''station'', ''address_isnull'', case when ISNULL(a.Address) = 0 then 0 else 1 end isError, now() ,case when ISNULL(a.Address) = 0 then Null else '''' end error_reason
from power_station a
where a.`Code` = ', siteID );
prepare stmt from @qry1 ;
execute stmt ;
#()#
set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason)
select ', siteID ,', ''station'', ''name_isnull'', case when ISNULL(a.Name) = 0 then 0 else 1 end isError, now(),case when ISNULL(a.Name) = 0 then Null else '''' end error_reason
from power_station a
where a.`Code` = ', siteID );
prepare stmt from @qry1 ;
execute stmt ;
#()#
set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason)
select ', siteID ,', ''station'', ''code_isnull'', case when ISNULL(a.Code) = 0 then 0 else 1 end isError, now(),case when ISNULL(a.Code) = 0 then Null else '''' end error_reason
from power_station a
where a.`Code` = ', siteID );
prepare stmt from @qry1 ;
execute stmt ;
#(- 0)#
set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason)
select ', siteID ,', ''station'', ''generatingCapacity_isnullorempty'', case when a.GeneratingCapacity > 0 and ISNULL(a.GeneratingCapacity) = 0 then 0 else 1 end isError, now(),case when a.GeneratingCapacity > 0 and ISNULL(a.GeneratingCapacity) = 0 then Null else '' 0 '' end error_reason
from power_station a
where a.`Code` = ', siteID );
prepare stmt from @qry1 ;
execute stmt ;
-- ##
-- set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason)
-- select ', siteID ,', ''station'', ''subStation_isnull'', case when count(*) > 0 then 0 else 1 end isError, now(),case when count(*) > 0 then Null else '''' end error_reason
-- from {DBname}.power_station a
-- where a.`Code` = ', siteID );
-- prepare stmt from @qry1 ;
-- execute stmt ;
#()#
set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason)
select ', siteID ,', ''station'', ''coordinate_isnull'', case when ISNULL(a.Coordinate) = 0 then 0 else 1 end isError, now(),case when ISNULL(a.Coordinate) = 0 then Null else '''' end error_reason
from power_station a
where a.`Code` = ', siteID );
prepare stmt from @qry1 ;
execute stmt ;
#()#
set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason)
select ', siteID ,', ''company'', ''company_deleted'',
case when b.Deleted = 0 then 0 else 1 end isError,
now(),
case when b.Deleted = 0 then Null else '''' end error_reason
from power_station a
join company b on a.CompanyId = b.Id
where a.`Code` = ', siteID );
prepare stmt from @qry1 ;
execute stmt ;
#()#
set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason)
select ', siteID ,', ''company'', ''company_status'',
case when b.Status = 1 then 0 else 1 end isError,
now(),
case when b.Status = 1 then Null else '''' end error_reason
from power_station a
join company b on a.CompanyId = b.Id
where a.`Code` = ', siteID );
prepare stmt from @qry1 ;
execute stmt ;
#()#
set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason)
select ', siteID ,', ''company'', ''company_isnull'',
case when count(*) > 0 then 0 else 1 end isError,
now(),
case when count(*) > 0 then Null else '''' end error_reason
from power_station a
join company b on a.CompanyId = b.Id
where a.`Code` = ', siteID );
prepare stmt from @qry1 ;
execute stmt ;
##
set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason)
select ', siteID ,', ''station'', ''operation_personnel_count'',
case when count(*) > 0 then 0 else 1 end isError,
now(),
case when count(*) > 0 then Null else '''' end error_reason
from power_station_operation_personnel b
join power_station a on a.Id = b.PowerStationId
where b.Deleted = 0 and a.`Code` = ', siteID );
prepare stmt from @qry1 ;
execute stmt ;
" + sql2 + $@"
#DBName是否填寫#
set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason)
select ', siteID ,', ''device'', ''device_DBName'',
case when count(*) > 0 then 1 else 0 end isError,
now(),
case when count(*) > 0 then ''DBName欄位未填寫'' else Null end error_reason
from {DBname}.device b
join power_station a on a.Id = b.PowerStationId
where b.Deleted = 0 and b.Enabled = 1 and b.Status = 1 and b.DBName Is Null and a.`Code` = ', siteID );
prepare stmt from @qry1 ;
execute stmt ;
#TableName是否填寫#
set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason)
select ', siteID ,', ''device'', ''device_TableName'',
case when count(*) > 0 then 1 else 0 end isError,
now(),
case when count(*) > 0 then ''TableName欄位未填寫'' else Null end error_reason
from {DBname}.device b
join power_station a on a.Id = b.PowerStationId
where b.Deleted = 0 and b.Enabled = 1 and b.Status = 1 and b.TableName Is Null and a.`Code` = ', siteID );
prepare stmt from @qry1 ;
execute stmt ;
#ColName是否填寫#
set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason)
select ', siteID ,', ''device'', ''device_ColName'',
case when count(*) > 0 then 1 else 0 end isError,
now(),
case when count(*) > 0 then ''ColName欄位未填寫'' else Null end error_reason
from {DBname}.device b
join power_station a on a.Id = b.PowerStationId
where b.Deleted = 0 and b.Enabled = 1 and b.Status = 1 and b.ColName Is Null and a.`Code` = ', siteID );
prepare stmt from @qry1 ;
execute stmt ;
" + sql3 + @$"
# #
set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason)
select ', siteID ,', ''controller'', ''controller_isnull'',
case when count(*) > 0 then 0 else 1 end isError,
now(),
case when count(*) > 0 then Null else '''' end error_reason
from {DBname}.power_station a
join {DBname}.controller b on a.id = b.PowerStationId
where a.`Code` = ', siteID, ' and b.Deleted = 0' );
prepare stmt from @qry1;
execute stmt;
# #
set @qry1:= concat('insert power_station_enable_check(siteID, check_type, check_item, isError, check_Date, error_reason)
select ', siteID ,', ''inverter'', ''inverter_isnull'',
case when count(*) > 0 then 0 else 1 end isError,
now(),
case when count(*) > 0 then Null else '''' end error_reason
from {DBname}.power_station a
join {DBname}.controller b on a.id = b.PowerStationId
join {DBname}.inverter c on b.id = c.ControllerId
where a.`Code` = ', siteID, ' and c.Deleted = 0 and c.Enabled = 1 and c.Status = 1' );
prepare stmt from @qry1;
execute stmt;
#
set @qry1:= concat('select error_reason from power_station_enable_check
where siteID = ', siteID ,' and isError = 1');
prepare stmt from @qry1 ;
execute stmt;
END ;
call sp_power_station_enable_check('{code}'); ";
result = (await conn.QueryAsync<string>(sql)).ToList();
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
public async Task StationStatus(int stationId , int status)
{
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
conn.Open();
using (var trans = conn.BeginTransaction())
{
try
{
var sql = @$"UPDATE power_station
SET Status = {status}
WHERE Id = {stationId} ";
await conn.ExecuteAsync(sql, trans);
trans.Commit();
}
catch (Exception exception)
{
trans.Rollback();
throw exception;
}
finally
{
conn.Close();
}
}
}
}
}
}

View File

@ -603,5 +603,7 @@ namespace SolarPower.Repository.Interface
Task<List<string>> GetShareDevicePowerstationName(int Id, string DBname);
Task DropShareDevice(int powerstationId, string DBname);
Task DeleteALLPowerStationOperationPersonnel(int stationId);
Task<List<string>> CheckStationStatus(string code, string DBname);
Task StationStatus(int stationId, int status);
}
}

View File

@ -140,6 +140,7 @@
<th>裝置容量(kWp)</th>
<th>逆變器數量</th>
<th>台電掛表日</th>
<th>狀態</th>
<th>功能</th>
</tr>
</thead>
@ -219,6 +220,7 @@
var tablocation = "";
var ids = new Array(0);
var localurl = this.location.href;
var index = 0;
$(function () {
$('#collapse').trigger("click");
Cityes();
@ -255,7 +257,7 @@
sidebar += "<div class='card'>";
sidebar += "<div class='card-header'>";
sidebar += "<a id='tab-" + index +"-collapse' href='#tab-" + val.cityId + "' class='card-title collapsed' data-toggle='collapse' data-target='#js_list_accordion-" + val.cityId + "' aria-expanded='false' data-filter-tags='backup' onclick=changecity(" + val.cityId +")> ";
sidebar += "<a id='tab-" + index + "-collapse' href='#tab-" + val.cityId + "' class='card-title collapsed' data-toggle='collapse' data-target='#js_list_accordion-" + val.cityId + "' aria-expanded='false' data-filter-tags='backup' onclick=changecity(" + val.cityId + "," + index + ")> ";
sidebar += "<i class='fal fa-globe width-2 fs-xl'></i>";
sidebar += val.cityName;
sidebar += "<span class='ml-auto'>";
@ -290,15 +292,16 @@
addPowerStationCard(ids);
$("#areaTab").find(".nav-item > a").first().click();
$('#tab-0-collapse').trigger("click");
$('#tab-' + index + '-collapse').trigger("click");
return;
}
}, 'json');
}
function changecity(a)
function changecity(a,i)
{
$('#AreaTab' + a).find('a').trigger("click");
index = i;
}
@ -340,14 +343,24 @@
del_str = '<button type = "button" class= "btn btn-danger btn-pills waves-effect waves-themed del-btnto" > 刪除</button >';
</text>
}
$('#solarTable' + val.cityId).find('tbody').append('<tr data-id="' + val.id + '" datacity-id="' + val.cityId+'"">' +
var status_str = "";
if (val.status == 0) {
status_str = '<button type = "button" class= "btn btn-info btn-pills waves-effect waves-themed status-btnto" > 啟用</button >';
}
else {
status_str = '<button type = "button" class= "btn btn-danger btn-pills waves-effect waves-themed unstatus-btnto" > 停用</button >';
}
$('#solarTable' + val.cityId).find('tbody').append('<tr data-id="' + val.id + '" datacity-id="' + val.cityId + '"">' +
'<td>' + val.id + '</td>' +
'<td>' + val.name + '</td>' +
'<td>' + val.generatingCapacity.toFixed(2) + '</td>' +
'<td>' + val.inverterAmount + '</td>' +
'<td>' + val.electricityMeterAt + '</td>' +
'<td> <button type="button" class="btn btn-primary btn-pills waves-effect waves-themed" onclick="location.href=\'' + localurl + '/edit?stationId=' + val.id + '\'">選擇</button> ' +
'<td>' + ((val.status == 0) ? "停用" : "啟用") + '</td>' +
'<td>' + status_str + ' <button type="button" class="btn btn-primary btn-pills waves-effect waves-themed" onclick="location.href=\'' + localurl + '/edit?stationId=' + val.id + '\'">選擇</button> ' +
del_str +
'</td > ' +
@ -360,9 +373,65 @@
}, 'json');
}
$(document).on("click", "button.status-btnto", function () {
var selected_id = $(this).parents('tr').attr('data-id');
var url = "/PowerStation/CheckStationStatus";
var send_data = {
Id: selected_id
}
$.post(url, send_data, function (rel) {
if (rel.code == "9999") {
toast_error(rel.msg);
return;
}
else
{
if (rel.code == "0000") {
toast_ok(rel.msg);
Cityes();
}
else if (rel.code == "0099") {
var text = "";
$.each(rel.data, function (index, val) {
text += index+1 + "." + val + "<br\>";
});
text += "電站尚有以上問題至無法啟用電站<br\>";
Swal.fire(
{
title: "啟用失敗",
icon: 'warning',
html: text,
});
}
}
}, 'json');
});
$(document).on("click", "button.unstatus-btnto", function () {
var selected_id = $(this).parents('tr').attr('data-id');
var url = "/PowerStation/StationUnStatus";
var send_data = {
Id: selected_id
}
$.post(url, send_data, function (rel) {
if (rel.code == "9999") {
toast_error(rel.msg);
return;
}
else {
if (rel.code == "0000") {
toast_ok(rel.msg);
}
Cityes();
}
}, 'json');
});
function CardDisplay() {

View File

@ -25,7 +25,7 @@
//},
"BackgroundServiceCron": {
"CalcPowerStationJob": "0 5 * * * ?",
"CalcAvgPowerStationJob": "0/10 * * * * ?",
"CalcAvgPowerStationJob": "0 0 2 * * ?",
"OperationScheduleJob": "0 0 2 * * ?",
"CalcInverter15minJob": "0 2/15 * * * ?",
"SendEmailJob": "0 0/5 * * * ?",