From edeb83b59a14d7c3897c384f0d431d17590f2aa8 Mon Sep 17 00:00:00 2001 From: cesar liu Date: Wed, 13 Apr 2022 11:49:36 +0800 Subject: [PATCH] =?UTF-8?q?debug:=20=E8=A3=9C=E8=B6=B3=20email=20=E5=85=A7?= =?UTF-8?q?=E5=AE=B9=E4=B8=AD=E7=9A=84=E7=95=B0=E5=B8=B8=E8=A8=8A=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implement/OverviewRepository.cs | 92 +++++++++++++------ 1 file changed, 62 insertions(+), 30 deletions(-) diff --git a/SolarPower/Repository/Implement/OverviewRepository.cs b/SolarPower/Repository/Implement/OverviewRepository.cs index a3f3b11..8d779fe 100644 --- a/SolarPower/Repository/Implement/OverviewRepository.cs +++ b/SolarPower/Repository/Implement/OverviewRepository.cs @@ -694,36 +694,68 @@ namespace SolarPower.Repository.Implement { try { - 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 , - 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, - 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 errMsgT - 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 - ) 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 a.id, site_id, `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 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, + // 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 errMsgT + // 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 + // ) 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, a.id, site_id, `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 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 + ) a LEFT JOIN notice_schedule ns ON ns.ExceptionId = a.id + WHERE ns.Id IS NULL "; exceptionEmailInfos = (await conn.QueryAsync(sql)).ToList(); } catch (Exception exception)