From c6ea225956e0071cad90407d96e9c2d524cffecc Mon Sep 17 00:00:00 2001 From: Kai Date: Tue, 16 Nov 2021 13:53:29 +0800 Subject: [PATCH 1/3] =?UTF-8?q?1.=20inv=E3=80=81sensor=5Favg=20=E8=87=AA?= =?UTF-8?q?=E5=8B=95=E5=8A=A0=E5=85=A5=E6=AC=84=E4=BD=8D=202.=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E9=80=86=E8=AE=8A=E5=99=A8=E6=AD=B8=E6=AA=94sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/PowerStationController.cs | 14 ++ .../Implement/PowerStationRepository.cs | 159 ++++++++++++++++-- .../Interface/IPowerStationRepository.cs | 4 + 3 files changed, 160 insertions(+), 17 deletions(-) diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index 5482d63..0fdab4a 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -3289,6 +3289,20 @@ namespace SolarPower.Controllers } else { + //檢查資料表是否有該欄位 + var check_inv_col = await powerStationRepository.CheckInvTableColumn(powerStation.SiteDB, powerStation.Code); + var check_sensor_avg_col = await powerStationRepository.CheckSensorAvgTableColumn(powerStation.SiteDB, powerStation.Code); + + if (check_inv_col != 1) + { + await powerStationRepository.AlertColInvTableColumn(powerStation.SiteDB, powerStation.Code); + } + + if (check_sensor_avg_col != 1) + { + await powerStationRepository.AlertColSensoravgTableColumn(powerStation.SiteDB, powerStation.Code); + } + await powerStationRepository.StationStatus(Id, 1); await powerStationRepository.StationStatus(Id, 1, powerStation.SiteDB + "."); apiResult.Msg = "電站啟用成功"; diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index bfd4377..f748416 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -2890,19 +2890,20 @@ namespace SolarPower.Repository.Implement var sql = $@"SELECT s.TIMESTAMP, s.INVERTERID, - a.KWH, + s.KWH, s.TODAYKWH, i.Capacity, - a.KWH/(i.Capacity/4) AS KWHKWP + s.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, + SUM(sub_inv.WH)/1000 AS KWH, MAX(sub_inv.TODAYKWH) AS TODAYKWH 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 GROUP BY sub_inv.INVERTERID) s - LEFT JOIN ( + /*LEFT JOIN ( SELECT MAX(FROM_UNIXTIME(sub_inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i')) AS TIMESTAMP, sub_inv.INVERTERID, SUM(sub_inv.WH)/1000 AS KWH @@ -2910,10 +2911,10 @@ namespace SolarPower.Repository.Implement WHERE FROM_UNIXTIME(sub_inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i') BETWEEN @StartDateTime AND @EndDateTime AND sub_inv.INVERTERID IN @InverterIds GROUP BY sub_inv.INVERTERID) a - ON s.TIMESTAMP = a.TIMESTAMP AND s.INVERTERID = a. INVERTERID + ON s.TIMESTAMP = a.TIMESTAMP AND s.INVERTERID = a. INVERTERID*/ LEFT JOIN {db_name}.inverter i ON s.INVERTERID = REPLACE(i.InverterId, 's', '');"; - result = (await conn.QueryAsync(sql, new { StartDateTime = stratDateTime, EndDateTime = dateTime, InverterIds = inverterIds })).ToList(); + result = (await conn.QueryAsync(sql, new { StartDateTime = stratDateTime, EndDateTime = dateTime, InverterIds = inverterIds }, commandTimeout: 300)).ToList(); } catch (Exception exception) { @@ -3008,14 +3009,14 @@ namespace SolarPower.Repository.Implement AVG(s.RA3) AS RA3, AVG(s.RA4) AS RA4, AVG(s.RA5) AS RA5, - a.KWH, + SUM(s.WH)/1000 AS KWH, MAX(s.TODAYKWH) AS TODAYKWH, MAX(s.TOTALKWH) AS TOTALKWH, i.Capacity, - (a.KWH/i.Capacity) AS KWHKWP + ((SUM(s.WH)/1000) / i.Capacity) AS KWHKWP FROM {table_name} s -- 取得該時間區間的KWH - LEFT JOIN ( + /*LEFT JOIN ( SELECT FROM_UNIXTIME(inv.TIMESTAMP/1000, '%Y-%m-%d %H') AS TIMESTAMP, inv.INVERTERID, @@ -3024,26 +3025,26 @@ namespace SolarPower.Repository.Implement WHERE DATE_FORMAT(FROM_UNIXTIME(inv.TIMESTAMP/1000), '%Y-%m-%d %H') = @DateTime AND inv.INVERTERID IN @InverterIds GROUP BY FROM_UNIXTIME(inv.TIMESTAMP/1000, '%Y-%m-%d %H'), inv.INVERTERID) a - ON FROM_UNIXTIME(s.TIMESTAMP/1000, '%Y-%m-%d %H') = a.TIMESTAMP AND s.INVERTERID = a. INVERTERID + ON FROM_UNIXTIME(s.TIMESTAMP/1000, '%Y-%m-%d %H') = a.TIMESTAMP AND s.INVERTERID = a. INVERTERID*/ -- 取得整點值PR LEFT JOIN ( SELECT - FROM_UNIXTIME(inv.TIMESTAMP/1000, '%Y-%m-%d %H') AS TIMESTAMP, + inv.CrdTime AS TIMESTAMP, inv.INVERTERID, inv.PR FROM {table_name} inv - WHERE DATE_FORMAT(FROM_UNIXTIME(inv.TIMESTAMP/1000), '%Y-%m-%d %H:%i') = CONCAT(@DateTime, ':55') + WHERE left(inv.CrdTime, 16) = CONCAT(@DateTime, ':55') AND inv.INVERTERID IN @InverterIds - GROUP BY FROM_UNIXTIME(inv.TIMESTAMP/1000, '%Y-%m-%d %H'), inv.INVERTERID) inv_pr - ON FROM_UNIXTIME(s.TIMESTAMP/1000, '%Y-%m-%d %H') = inv_pr.TIMESTAMP AND s.INVERTERID = inv_pr. INVERTERID + GROUP BY left(inv.CrdTime, 13), inv.INVERTERID) inv_pr + ON left(s.CrdTime, 13) = inv_pr.TIMESTAMP AND s.INVERTERID = inv_pr. INVERTERID -- 取得逆變器容量 LEFT JOIN {db_name}.inverter i ON s.INVERTERID = i.InverterId - WHERE FROM_UNIXTIME(s.TIMESTAMP/1000, '%Y-%m-%d %H') = @DateTime + WHERE left(s.CrdTime, 13) = @DateTime AND s.INVERTERID IN @InverterIds - GROUP BY DATE_FORMAT(FROM_UNIXTIME(s.TIMESTAMP/1000), '%Y-%m-%d %H'), s.INVERTERID + GROUP BY left(s.CrdTime, 13), s.INVERTERID "; - result = (await conn.QueryAsync(sql, new { DateTime = dateTime, InverterIds = inverterIds })).ToList(); + result = (await conn.QueryAsync(sql, new { DateTime = dateTime, InverterIds = inverterIds }, commandTimeout: 300)).ToList(); } catch (Exception exception) { @@ -4467,7 +4468,7 @@ namespace SolarPower.Repository.Implement inv.RA5 FROM {table_name} inv LEFT JOIN (select * from {sensor_table_name} where TIMESTAMP between @start_timestamp and @end_timestamp)sen - ON FROM_UNIXTIME(inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i') = FROM_UNIXTIME(sen.TIMESTAMP/1000, '%Y-%m-%d %H:%i') + ON inv.CrdTime = sen.CrdTime -- LEFT JOIN {sensor_table_name} sen ON FROM_UNIXTIME(inv.TIMESTAMP/1000, '%Y-%m-%d %H:%i') = FROM_UNIXTIME(sen.TIMESTAMP/1000, '%Y-%m-%d %H:%i') LEFT JOIN {entity.SiteDB}.inverter i ON inv.INVERTERID = i.InverterId WHERE inv.`TIMESTAMP` between @start_timestamp and @end_timestamp @@ -5837,5 +5838,129 @@ namespace SolarPower.Repository.Implement return resule; } } + + public async Task CheckInvTableColumn (string dbname, string code) + { + + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + conn.Open(); + + var resule = 0; + try + { + var sql = $@"SELECT count(*) FROM information_schema.columns WHERE table_schema='{dbname}' AND table_name = 's{code}01_inv' AND column_name = 'CrdTime'"; + resule = await conn.QueryFirstOrDefaultAsync(sql); + + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + + return resule; + } + } + + public async Task CheckSensorAvgTableColumn(string dbname, string code) + { + + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + conn.Open(); + + var resule = 0; + try + { + var sql = $@"SELECT count(*) FROM information_schema.columns WHERE table_schema='{dbname}' AND table_name = 's{code}01_sensoravg' AND column_name = 'CrdTime'"; + resule = await conn.QueryFirstOrDefaultAsync(sql); + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + + return resule; + } + } + + public async Task AlertColInvTableColumn(string dbname, string code) + { + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + conn.Open(); + + try + { + var sql = $@"ALTER TABLE {dbname}.s{code}01_inv ADD COLUMN CrdTime datetime; + use {dbname}; + create trigger trg01_s{code}01_inv + before insert on {dbname}.s{code}01_inv + FOR EACH ROW + begin + set new.CrdTime = FROM_UNIXTIME(new.`TIMESTAMP`/1000,'%Y-%m-%d %H:%i'); + end; + use solar_master; + + update {dbname}.s{code}01_inv set crdtime = FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i'); + + CREATE INDEX IDX02_s{code}01 ON {dbname}.s{code}01_inv(Inverterid, CrdTime);"; + + await conn.ExecuteAsync(sql); + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + + } + } + + public async Task AlertColSensoravgTableColumn(string dbname, string code) + { + using (IDbConnection conn = this._databaseHelper.GetConnection()) + { + conn.Open(); + + try + { + var sql = $@"ALTER TABLE {dbname}.s{code}01_sensoravg ADD COLUMN CrdTime datetime; + use {dbname}; + create trigger trg01_s{code}01_sensoravg + before insert on {dbname}.s{code}01_sensoravg + FOR EACH ROW + begin + set new.CrdTime = FROM_UNIXTIME(new.`TIMESTAMP`/1000,'%Y-%m-%d %H:%i'); + end; + use solar_master; + + update {dbname}.s{code}01_sensoravg set crdtime = FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i'); + + CREATE INDEX IDX{code}01_sensoravg ON {dbname}.s{code}01_sensoravg(CrdTime);"; + await conn.ExecuteAsync(sql); + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + + } + } } } diff --git a/SolarPower/Repository/Interface/IPowerStationRepository.cs b/SolarPower/Repository/Interface/IPowerStationRepository.cs index 2672704..5aed3fe 100644 --- a/SolarPower/Repository/Interface/IPowerStationRepository.cs +++ b/SolarPower/Repository/Interface/IPowerStationRepository.cs @@ -608,5 +608,9 @@ namespace SolarPower.Repository.Interface Task UpdateInvStatus(string siteDB, List codes, List inverterIds = null, byte status = 0); Task> GetInvStatusErr(List codes); Task Check4table(string code, string dbname); + Task CheckInvTableColumn(string dbname, string code); + Task CheckSensorAvgTableColumn(string dbname, string code); + Task AlertColInvTableColumn(string dbname, string code); + Task AlertColSensoravgTableColumn(string dbname, string code); } } From acd8812ec32ce479a78cde0a72400896da8d1b53 Mon Sep 17 00:00:00 2001 From: b110212000 Date: Mon, 22 Nov 2021 10:47:10 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=9C=88=E5=A0=B1=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository/Implement/StationReportRepository.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/SolarPower/Repository/Implement/StationReportRepository.cs b/SolarPower/Repository/Implement/StationReportRepository.cs index 00adb1f..ebabe0a 100644 --- a/SolarPower/Repository/Implement/StationReportRepository.cs +++ b/SolarPower/Repository/Implement/StationReportRepository.cs @@ -106,7 +106,7 @@ namespace SolarPower.Repository.Implement GROUP_CONCAT(DISTINCT CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then round(a.KWH, 2) end) ''inv_', right(INVERTERID, 2), '''') ) INTO @sql - FROM inverter_history_hour where powerstationId = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y-%m') = '{post.Time}'; + FROM inverter_history_day where powerstationId = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y-%m') = '{post.Time}'; SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%m/%d'') report_date, ', @sql, ',b.TODAYKWH ''dayKWH'', round((b.TODAYKWH / c.monthKWH)*100,2) ''dayKWHp'', b.SOLARHOUR ''tothour'', b.KWHKWP ''KWHKWP'', b.PR, d.irradiance ''irradiance'', d.Temperature ''temperature'', b.money ''soldmoney'', @@ -153,7 +153,7 @@ namespace SolarPower.Repository.Implement GROUP_CONCAT(DISTINCT CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then round(a.KWH, 2) end) ''inv_', right(INVERTERID, 2), '''') ) INTO @sql - FROM inverter_history_hour where powerstationId = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') BETWEEN '{times[0]}' AND '{times[1]}'; + FROM inverter_history_day where powerstationId = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') BETWEEN '{times[0]}' AND '{times[1]}'; SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%m/%d'') report_date, ', @sql, ',b.TODAYKWH ''dayKWH'', round((b.TODAYKWH / c.monthKWH)*100,2) ''dayKWHp'', b.SOLARHOUR ''tothour'', b.KWHKWP ''KWHKWP'', b.PR, d.irradiance ''irradiance'', d.Temperature ''temperature'', b.money ''soldmoney'', @@ -202,7 +202,7 @@ namespace SolarPower.Repository.Implement GROUP_CONCAT(DISTINCT CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then round(a.KWH, 2) end) ''inv_', right(INVERTERID, 2), '''') ) INTO @sql - FROM inverter_history_hour where powerstationId = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y') = '{post.Time}'; + FROM inverter_history_month where powerstationId = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y') = '{post.Time}'; SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%Y/%m'') report_date, ', @sql, ',b.todayKWH ''dayKWH'', round((b.todayKWH / c.monthKWH)*100,2) ''dayKWHp'', b.SOLARHOUR ''tothour'', b.KWHKWP ''KWHKWP'', c.PR, d.irradiance ''irradiance'', d.Temperature ''temperature'', b.money ''soldmoney'', @@ -482,7 +482,7 @@ namespace SolarPower.Repository.Implement GROUP_CONCAT(DISTINCT CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then round(a.KWH, 2) end) ''inv_', right(INVERTERID, 2), '''') ) INTO @sql - FROM inverter_history_hour where powerstationId = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y-%m') = '{post.Time}'; + FROM inverter_history_day where powerstationId = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y-%m') = '{post.Time}'; SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%m/%d'') report_date, ', @sql, ',b.TODAYKWH ''dayKWH'', round((b.TODAYKWH / c.monthKWH)*100,2) ''dayKWHp'', b.SOLARHOUR ''tothour'', b.KWHKWP ''KWHKWP'', b.PR, d.irradiance ''irradiance'', d.Temperature ''temperature'', b.money ''soldmoney'', @@ -529,7 +529,7 @@ namespace SolarPower.Repository.Implement GROUP_CONCAT(DISTINCT CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then round(a.KWH, 2) end) ''inv_', right(INVERTERID, 2), '''') ) INTO @sql - FROM inverter_history_hour where powerstationId = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') BETWEEN '{times[0]}' AND '{times[1]}'; + FROM inverter_history_day where powerstationId = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') BETWEEN '{times[0]}' AND '{times[1]}'; SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%m/%d'') report_date, ', @sql, ',b.TODAYKWH ''dayKWH'', round((b.TODAYKWH / c.monthKWH)*100,2) ''dayKWHp'', b.SOLARHOUR ''tothour'', b.KWHKWP ''KWHKWP'', b.PR, d.irradiance ''irradiance'', d.Temperature ''temperature'', b.money ''soldmoney'', @@ -577,7 +577,7 @@ namespace SolarPower.Repository.Implement GROUP_CONCAT(DISTINCT CONCAT('max(case when INVERTERID = ''', INVERTERID, ''' then round(a.KWH, 2) end) ''inv_', right(INVERTERID, 2), '''') ) INTO @sql - FROM inverter_history_hour where powerstationId = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y') = '{post.Time}'; + FROM inverter_history_month where powerstationId = {post.PowerStation} and DATE_FORMAT(`TIMESTAMP`,'%Y') = '{post.Time}'; SET @sql = CONCAT('SELECT DATE_FORMAT(a.TIMESTAMP,''%Y/%m'') report_date, ', @sql, ',b.todayKWH ''dayKWH'', round((b.todayKWH / c.monthKWH)*100,2) ''dayKWHp'', b.SOLARHOUR ''tothour'', b.KWHKWP ''KWHKWP'', c.PR, d.irradiance ''irradiance'', d.Temperature ''temperature'', b.money ''soldmoney'', From 9e9fbeb921750834bc0870c38a158f285a4e2adc Mon Sep 17 00:00:00 2001 From: b110212000 Date: Tue, 30 Nov 2021 18:26:02 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=95=B0=E5=B8=B8sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implement/OverviewRepository.cs | 54 +++++++++++++++---- .../StationOverviewInfo.cshtml | 2 +- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/SolarPower/Repository/Implement/OverviewRepository.cs b/SolarPower/Repository/Implement/OverviewRepository.cs index 7e13d05..0de6831 100644 --- a/SolarPower/Repository/Implement/OverviewRepository.cs +++ b/SolarPower/Repository/Implement/OverviewRepository.cs @@ -360,10 +360,35 @@ namespace SolarPower.Repository.Implement { DateTime start; DateTime end; - var sql = @$"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, - errDevice, err_valueKind, errValue, FROM_UNIXTIME( (a.lastUpdate / 1000), '%Y-%m-%d %H:%i:%s') lastUpdate, - case when c.errMsg_tw is null then d.errMsg_tw else c.errMsg_tw end errMsg + //var sql = @$"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, + // errDevice, err_valueKind, errValue, FROM_UNIXTIME( (a.lastUpdate / 1000), '%Y-%m-%d %H:%i:%s') lastUpdate, + // case when c.errMsg_tw is null then d.errMsg_tw else c.errMsg_tw end 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 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 = @PowerStationId "; + var sql = @$"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, 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 left join alarmorion_orionalarmclass b on a.alarmclass = b.id left join ref_err_device c on trim(b.alarmClass) = c.deviceType @@ -374,7 +399,6 @@ namespace SolarPower.Repository.Implement left join operation_record pr on pr.ErrorCode = a.id WHERE a.sourceState = @Status AND ps.Id = @PowerStationId "; - if (!string.IsNullOrEmpty(post.Range)) { post.StartTime = post.Range.Split('-')[0] + " 00:00:00"; @@ -415,10 +439,22 @@ namespace SolarPower.Repository.Implement { DateTime start; DateTime end; - var sql = @$"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, - case when c.errMsg_tw is null then d.errMsg_tw else c.errMsg_tw end errMsg + var sql = @$"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, 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 diff --git a/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml b/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml index a8000df..5adf90d 100644 --- a/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml +++ b/SolarPower/Views/StationOverview/StationOverviewInfo.cshtml @@ -2812,7 +2812,7 @@ return; } $("#Invertercard-Name").html(rel.data.name); - $("#Invertercard-kwh").html(rel.data.kwh.toFixed(2)); + $("#Invertercard-kwh").html(rel.data.today_kWh.toFixed(2)); @if (ViewBag.myUser.Role.Auths.Contains("ShowMoney")) {