發佈版本 0907

This commit is contained in:
cesar liu 2022-09-07 15:07:42 +08:00
parent e1777eca17
commit f614fd07f0
5 changed files with 157 additions and 152 deletions

View File

@ -21,7 +21,7 @@
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Product",
"ASPNETCORE_ENVIRONMENT": "Production",
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"

View File

@ -46,8 +46,7 @@ namespace SolarPower.Quartz.Jobs
if(ExceptionList.Count > 0 )
{
// 立刻發報
var ExceptionListex = ExceptionList.Where(x => x.sourceState == 1 &&
x.priority == 1 ).ToList();
var ExceptionListex = ExceptionList.Where(x => x.priority == 1 ).ToList();
// 12小時後發報
var ExceptionListex2 = ExceptionList.Where(x => x.sourceState == 1 &&
x.priority == 2 &&
@ -78,10 +77,10 @@ namespace SolarPower.Quartz.Jobs
$"異常訊息:{Exception.errMsg}" + "<br>" +
$"設備編號:{Exception.errDevice}" + "<br>" +
$"異常編號:{Exception.id}" + "<br>";
if (Exception.errMsgT == "d")
{
Content += $"當前數值:{Exception.errValue}" + "<br>";
}
//if (Exception.errMsgT == "d")
//{
// Content += $"當前數值:{Exception.errValue}" + "<br>";
//}
foreach (var user in UserListWithPowerstation)
{
@ -98,19 +97,18 @@ namespace SolarPower.Quartz.Jobs
Type = 1,
ExceptionId = Exception.id
};
//List<string> properties = new List<string>()
//{
// "UserId",
// "EmailType",
// "RecipientEmail",
// "Subject",
// "Content",
// "RecipientName",
// "Type",
// "ExceptionId"
//};
//await noticeScheduleRepository.AddOneAsync(DaySchedule, properties);
List<string> properties = new List<string>()
{
"UserId",
"EmailType",
"RecipientEmail",
"Subject",
"Content",
"RecipientName",
"Type",
"ExceptionId"
};
await noticeScheduleRepository.AddOneAsync(DaySchedule, properties);
}
var powerstation = await powerStationRepository.GetOneAsync(Exception.PowerStationId);

View File

@ -406,7 +406,7 @@ namespace SolarPower.Repository.Implement
}
sql += " order by errvalue ";
sql += " order by pr.Id ";
result = (await conn.QueryAsync<ExceptionDataTable>(sql,
new
@ -434,31 +434,40 @@ namespace SolarPower.Repository.Implement
{
DateTime start;
DateTime end;
var sql = @$"select pr.FormId as FormId, pr.Id as ErrorID, a.id, site_id, ps.Id PowerStationId, `timestamp`, FROM_UNIXTIME((`timestamp` / 1000), '%Y-%m-%d %H:%i:%s') dev_time ,
string sql = $@"
select pr.FormId as FormId, pr.Id as ErrorID, a.id, site_id, ps.Id PowerStationId, `timestamp`, FROM_UNIXTIME((`timestamp` / 1000), '%Y-%m-%d %H:%i:%s') dev_time ,
a.sourceState err_status, FROM_UNIXTIME( (a.normalTime / 1000), '%Y-%m-%d %H:%i:%s') normalTime,
a.alarmClass, b.alarmClass_zh as alarmClassName,ps.Name as PowerStationName, errDevice, err_valueKind, errValue, FROM_UNIXTIME( (a.lastUpdate / 1000), '%Y-%m-%d %H:%i:%s') lastUpdate, c.errMsg_tw cerrMsg_tw, d.errMsg_tw derrMsg_tw,
case when c.errMsg_tw is null then
case when err_valueKind = 'b' then d.errMsg_tw
when err_valueKind = 'd' then CONCAT(d.errMsg_tw, ': ', round(a.errValue, 2))
when d.errMsg_tw is null then a.errValue
when a.errValue is null then d.errMsg_tw
else CONCAT(a.errValue, ', ' , ifNull(d.errMsg_tw, '')) end
else
case when err_valueKind = 'b' then c.errMsg_tw
when err_valueKind = 'd' then CONCAT(c.errMsg_tw, ': ', round(a.errValue, 2))
when c.errMsg_tw is null then a.errValue
when a.errValue is null then c.errMsg_tw
else CONCAT(a.errValue, ', ' , ifNull(c.errMsg_tw, '')) end
end errMsg
a.alarmClass, b.alarmClass_zh as alarmClassName,ps.Name as PowerStationName, errDevice, err_valueKind, errValue, FROM_UNIXTIME( (a.lastUpdate / 1000), '%Y-%m-%d %H:%i:%s') lastUpdate, a.errMsg
from err_main a
join alarmorion_orionalarmclass b on a.alarmclass = b.id
left join ref_err_device c on trim(b.alarmClass) = c.deviceType
left join ref_err_inv d on lower(b.alarmClass) = d.deviceType
# and case when lower(b.alarmClass) = 'inverter' and err_valuekind = 'e' then errvalue else '' end = d.errCode
and a.errDeviceBrand = d.brend and a.errDeviceModel = d.model and a.errValue = d.errCode
left join power_station ps on ps.Code = site_id
left join operation_record pr on pr.ErrorCode = a.id
WHERE a.sourceState = @Status AND ps.Id IN @PowerStationId";
//var sql = @$"select pr.FormId as FormId, pr.Id as ErrorID, a.id, site_id, ps.Id PowerStationId, `timestamp`, FROM_UNIXTIME((`timestamp` / 1000), '%Y-%m-%d %H:%i:%s') dev_time ,
// a.sourceState err_status, FROM_UNIXTIME( (a.normalTime / 1000), '%Y-%m-%d %H:%i:%s') normalTime,
// a.alarmClass, b.alarmClass_zh as alarmClassName,ps.Name as PowerStationName, errDevice, err_valueKind, errValue, FROM_UNIXTIME( (a.lastUpdate / 1000), '%Y-%m-%d %H:%i:%s') lastUpdate, c.errMsg_tw cerrMsg_tw, d.errMsg_tw derrMsg_tw,
// case when c.errMsg_tw is null then
// case when err_valueKind = 'b' then d.errMsg_tw
// when err_valueKind = 'd' then CONCAT(d.errMsg_tw, ': ', round(a.errValue, 2))
// when d.errMsg_tw is null then a.errValue
// when a.errValue is null then d.errMsg_tw
// else CONCAT(a.errValue, ', ' , ifNull(d.errMsg_tw, '')) end
// else
// case when err_valueKind = 'b' then c.errMsg_tw
// when err_valueKind = 'd' then CONCAT(c.errMsg_tw, ': ', round(a.errValue, 2))
// when c.errMsg_tw is null then a.errValue
// when a.errValue is null then c.errMsg_tw
// else CONCAT(a.errValue, ', ' , ifNull(c.errMsg_tw, '')) end
// end errMsg
// from err_main a
// join alarmorion_orionalarmclass b on a.alarmclass = b.id
// left join ref_err_device c on trim(b.alarmClass) = c.deviceType
// left join ref_err_inv d on lower(b.alarmClass) = d.deviceType
// # and case when lower(b.alarmClass) = 'inverter' and err_valuekind = 'e' then errvalue else '' end = d.errCode
// and a.errDeviceBrand = d.brend and a.errDeviceModel = d.model and a.errValue = d.errCode
// left join power_station ps on ps.Code = site_id
// left join operation_record pr on pr.ErrorCode = a.id
// WHERE a.sourceState = @Status AND ps.Id IN @PowerStationId";
if (!string.IsNullOrEmpty(post.Range))
@ -472,7 +481,7 @@ namespace SolarPower.Repository.Implement
sql += @$" AND `timestamp` BETWEEN {startime * 1000} AND {endtime * 1000}";
}
sql += " order by errvalue ";
sql += " order by pr.Id ";
result = (await conn.QueryAsync<ExceptionDataTable>(sql,
new
@ -796,11 +805,29 @@ namespace SolarPower.Repository.Implement
{
try
{
//var sql = @$"SELECT a.`*`,ns.Id FROM
string sql = $@"SELECT a.`*`,ns.Id FROM
(
select pr.FormId as FormId, pr.Id as ErrorID, priority, a.id, site_id, `timestamp`, a.sourceState,
FROM_UNIXTIME((`timestamp` / 1000), '%Y-%m-%d %H:%i:%s') dev_time ,
a.sourceState err_status, FROM_UNIXTIME( (a.normalTime / 1000), '%Y-%m-%d %H:%i:%s') normalTime,
a.alarmClass, b.alarmClass_zh as alarmClassName,ps.Name as PowerStationName, ps.Id as PowerStationId,errDevice, err_valueKind, errValue,
FROM_UNIXTIME( (a.lastUpdate / 1000), '%Y-%m-%d %H:%i:%s') lastUpdate, -- c.errMsg_tw cerrMsg_tw, d.errMsg_tw derrMsg_tw,
a.errMsg
from err_main a
left join alarmorion_orionalarmclass b on a.alarmclass = b.id
left join power_station ps on ps.`Code` = site_id
left join operation_record pr on pr.ErrorCode = a.id
where datestamp = '{DateTime.Now.ToString("yyyy-MM-dd")}' and ps.`Code` is not null and priority < 20
) a LEFT JOIN notice_schedule ns ON ns.ExceptionId = a.id
WHERE ns.Id IS NULL ";
// var sql = $@"
// SELECT a.`*`,ns.Id FROM
// (
// select a.id, site_id, `timestamp`, FROM_UNIXTIME((`timestamp` / 1000), '%Y-%m-%d %H:%i:%s') dev_time ,
//select pr.FormId as FormId, pr.Id as ErrorID, priority, a.id, site_id, `timestamp`, a.sourceState,
//FROM_UNIXTIME((`timestamp` / 1000), '%Y-%m-%d %H:%i:%s') dev_time ,
// a.sourceState err_status, FROM_UNIXTIME( (a.normalTime / 1000), '%Y-%m-%d %H:%i:%s') normalTime,
// a.alarmClass, b.alarmClass as alarmClassName,ps.Name as PowerStationName,ps.Id as PowerStationId, errDevice, err_valueKind, errValue, FROM_UNIXTIME( (a.lastUpdate / 1000), '%Y-%m-%d %H:%i:%s') lastUpdate, d.errMsg_tw errMsg,
// a.alarmClass, b.alarmClass_zh as alarmClassName,ps.Name as PowerStationName, ps.Id as PowerStationId,errDevice, err_valueKind, errValue,
// FROM_UNIXTIME( (a.lastUpdate / 1000), '%Y-%m-%d %H:%i:%s') lastUpdate, c.errMsg_tw cerrMsg_tw, d.errMsg_tw derrMsg_tw,
// case when c.errMsg_tw is null then
// case when err_valueKind = 'b' then d.errMsg_tw
// when err_valueKind = 'd' then CONCAT(d.errMsg_tw, ': ', round(a.errValue, 2))
@ -813,51 +840,18 @@ namespace SolarPower.Repository.Implement
// when c.errMsg_tw is null then a.errValue
// when a.errValue is null then c.errMsg_tw
// else CONCAT(a.errValue, ', ' , ifNull(c.errMsg_tw, '')) end
// end errMsgT
// end errMsg
// #, a.errDeviceBrand , d.brend , a.errDeviceModel, d.model , a.errValue , d.errCode
//from err_main a
// join alarmorion_orionalarmclass b on a.alarmclass = b.id
// left join alarmorion_orionalarmclass b on a.alarmclass = b.id
// left join ref_err_device c on trim(b.alarmClass) = c.deviceType
// left join ref_err_inv d on lower(b.alarmClass) = d.deviceType
// # and case when lower(b.alarmClass) = 'inverter' and err_valuekind = 'e' then errvalue else '' end = d.errCode
// and a.errDeviceBrand = d.brend and a.errDeviceModel = d.model and a.errValue = d.errCode
// left join power_station ps on ps.Code = site_id
// left join power_station ps on ps.`Code` = site_id
// left join operation_record pr on pr.ErrorCode = a.id
// ) a
// LEFT JOIN
// notice_schedule ns ON ns.ExceptionId = a.id
// WHERE ns.Id IS NULL AND a.err_status = 1 AND a.PowerStationId IS NOT null";
var sql = $@"
SELECT a.`*`,ns.Id FROM
(
select pr.FormId as FormId, pr.Id as ErrorID, priority, a.id, site_id, `timestamp`, a.sourceState,
FROM_UNIXTIME((`timestamp` / 1000), '%Y-%m-%d %H:%i:%s') dev_time ,
a.sourceState err_status, FROM_UNIXTIME( (a.normalTime / 1000), '%Y-%m-%d %H:%i:%s') normalTime,
a.alarmClass, b.alarmClass_zh as alarmClassName,ps.Name as PowerStationName, ps.Id as PowerStationId,errDevice, err_valueKind, errValue,
FROM_UNIXTIME( (a.lastUpdate / 1000), '%Y-%m-%d %H:%i:%s') lastUpdate, c.errMsg_tw cerrMsg_tw, d.errMsg_tw derrMsg_tw,
case when c.errMsg_tw is null then
case when err_valueKind = 'b' then d.errMsg_tw
when err_valueKind = 'd' then CONCAT(d.errMsg_tw, ': ', round(a.errValue, 2))
when d.errMsg_tw is null then a.errValue
when a.errValue is null then d.errMsg_tw
else CONCAT(a.errValue, ', ' , ifNull(d.errMsg_tw, '')) end
else
case when err_valueKind = 'b' then c.errMsg_tw
when err_valueKind = 'd' then CONCAT(c.errMsg_tw, ': ', round(a.errValue, 2))
when c.errMsg_tw is null then a.errValue
when a.errValue is null then c.errMsg_tw
else CONCAT(a.errValue, ', ' , ifNull(c.errMsg_tw, '')) end
end errMsg
#, a.errDeviceBrand , d.brend , a.errDeviceModel, d.model , a.errValue , d.errCode
from err_main a
left join alarmorion_orionalarmclass b on a.alarmclass = b.id
left join ref_err_device c on trim(b.alarmClass) = c.deviceType
left join ref_err_inv d on lower(b.alarmClass) = d.deviceType
and a.errDeviceBrand = d.brend and a.errDeviceModel = d.model and a.errValue = d.errCode
left join power_station ps on ps.`Code` = site_id
left join operation_record pr on pr.ErrorCode = a.id
where sourceState = 1 and ps.`Code` is not null and priority < 20
) a LEFT JOIN notice_schedule ns ON ns.ExceptionId = a.id
WHERE ns.Id IS NULL ";
//where sourceState = 1 and ps.`Code` is not null and priority < 20
// ) a LEFT JOIN notice_schedule ns ON ns.ExceptionId = a.id
// WHERE ns.Id IS NULL ";
exceptionEmailInfos = (await conn.QueryAsync<ExceptionEmailInfo>(sql)).ToList();
}
catch (Exception exception)

View File

@ -122,13 +122,6 @@ namespace SolarPower
);
//#endregion
////#region 計算電站發電量等資訊(每整點5分執行)
//services.AddSingleton<CalcPowerStationJob>();
//services.AddSingleton(
//new JobSchedule(jobType: typeof(CalcPowerStationJob), cronExpression: Configuration.GetValue<string>("BackgroundServiceCron:CalcPowerStationJob"))
////new JobSchedule(jobType: typeof(CalcPowerStationJob), cronExpression: "0/10 * * * * ?")
//);
////#endregion
//#region 計算電站發電量等資訊(每整點5分執行)
services.AddSingleton<CalcPowerStationJobV2>();

View File

@ -220,8 +220,9 @@ namespace solarApp.Service
{
conn.Open();
string sql = $@"SELECT a.`*`,
case priority when 1 then DATE_ADD(dev_time, INTERVAL 24 HOUR)
case priority when 1 then dev_time
when 2 then DATE_ADD(dev_time, INTERVAL 12 HOUR)
when 3 then DATE_ADD(dev_time, INTERVAL 24 HOUR)
else dev_time end emailTime
FROM
(
@ -229,31 +230,50 @@ namespace solarApp.Service
FROM_UNIXTIME((`timestamp` / 1000), '%Y-%m-%d %H:%i:%s') dev_time ,
a.sourceState err_status, FROM_UNIXTIME( (a.normalTime / 1000), '%Y-%m-%d %H:%i:%s') normalTime,
a.alarmClass, b.alarmClass_zh as alarmClassName,ps.Name as PowerStationName, ps.Id as PowerStationId,errDevice, err_valueKind, errValue,
FROM_UNIXTIME( (a.lastUpdate / 1000), '%Y-%m-%d %H:%i:%s') lastUpdate, c.errMsg_tw cerrMsg_tw, d.errMsg_tw derrMsg_tw,
case when c.errMsg_tw is null then
case when err_valueKind = 'b' then d.errMsg_tw
when err_valueKind = 'd' then CONCAT(d.errMsg_tw, ': ', round(a.errValue, 2))
when d.errMsg_tw is null then a.errValue
when a.errValue is null then d.errMsg_tw
else CONCAT(a.errValue, ', ' , ifNull(d.errMsg_tw, '')) end
else
case when err_valueKind = 'b' then c.errMsg_tw
when err_valueKind = 'd' then CONCAT(c.errMsg_tw, ': ', round(a.errValue, 2))
when c.errMsg_tw is null then a.errValue
when a.errValue is null then c.errMsg_tw
else CONCAT(a.errValue, ', ' , ifNull(c.errMsg_tw, '')) end
end errMsg
#, a.errDeviceBrand , d.brend , a.errDeviceModel, d.model , a.errValue , d.errCode
FROM_UNIXTIME( (a.lastUpdate / 1000), '%Y-%m-%d %H:%i:%s') lastUpdate,
a.errMsg
from err_main a
left join alarmorion_orionalarmclass b on a.alarmclass = b.id
left join ref_err_device c on trim(b.alarmClass) = c.deviceType
left join ref_err_inv d on lower(b.alarmClass) = d.deviceType
and a.errDeviceBrand = d.brend and a.errDeviceModel = d.model and a.errValue = d.errCode
left join power_station ps on ps.`Code` = site_id
left join operation_record pr on pr.ErrorCode = a.id
where sourceState = 1 and datestamp > '{System.DateTime.Now.AddDays(-60).ToString("yyyy-MM-dd")}' and ps.`Code` is not null
where sourceState = 1 and datestamp > '{System.DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd")}' and ps.`Code` is not null
) a
order by a.id desc limit 1000";
// string sql = $@"SELECT a.`*`,
// case priority when 1 then DATE_ADD(dev_time, INTERVAL 24 HOUR)
// when 2 then DATE_ADD(dev_time, INTERVAL 12 HOUR)
// else dev_time end emailTime
// FROM
// (
//select pr.FormId as FormId, pr.Id as ErrorID, priority, a.id, site_id, `timestamp`, a.sourceState,
//FROM_UNIXTIME((`timestamp` / 1000), '%Y-%m-%d %H:%i:%s') dev_time ,
// a.sourceState err_status, FROM_UNIXTIME( (a.normalTime / 1000), '%Y-%m-%d %H:%i:%s') normalTime,
// a.alarmClass, b.alarmClass_zh as alarmClassName,ps.Name as PowerStationName, ps.Id as PowerStationId,errDevice, err_valueKind, errValue,
// FROM_UNIXTIME( (a.lastUpdate / 1000), '%Y-%m-%d %H:%i:%s') lastUpdate, c.errMsg_tw cerrMsg_tw, d.errMsg_tw derrMsg_tw,
// case when c.errMsg_tw is null then
// case when err_valueKind = 'b' then d.errMsg_tw
// when err_valueKind = 'd' then CONCAT(d.errMsg_tw, ': ', round(a.errValue, 2))
// when d.errMsg_tw is null then a.errValue
// when a.errValue is null then d.errMsg_tw
// else CONCAT(a.errValue, ', ' , ifNull(d.errMsg_tw, '')) end
// else
// case when err_valueKind = 'b' then c.errMsg_tw
// when err_valueKind = 'd' then CONCAT(c.errMsg_tw, ': ', round(a.errValue, 2))
// when c.errMsg_tw is null then a.errValue
// when a.errValue is null then c.errMsg_tw
// else CONCAT(a.errValue, ', ' , ifNull(c.errMsg_tw, '')) end
// end errMsg
// #, a.errDeviceBrand , d.brend , a.errDeviceModel, d.model , a.errValue , d.errCode
//from err_main a
// left join alarmorion_orionalarmclass b on a.alarmclass = b.id
// left join ref_err_device c on trim(b.alarmClass) = c.deviceType
// left join ref_err_inv d on lower(b.alarmClass) = d.deviceType
// and a.errDeviceBrand = d.brend and a.errDeviceModel = d.model and a.errValue = d.errCode
// left join power_station ps on ps.`Code` = site_id
// left join operation_record pr on pr.ErrorCode = a.id
//where sourceState = 1 and datestamp > '{System.DateTime.Now.AddDays(-60).ToString("yyyy-MM-dd")}' and ps.`Code` is not null
// ) a
// order by a.id desc limit 1000";
List<ExceptionEmailInfo> ds = conn.Query<ExceptionEmailInfo>(sql, commandTimeout: 600).AsList<ExceptionEmailInfo>();
conn.Close();
return ds;