Compare commits
10 Commits
26da763cbb
...
b4c7bac548
| Author | SHA1 | Date | |
|---|---|---|---|
| b4c7bac548 | |||
| a07d080198 | |||
| df2654fb57 | |||
| c41d079396 | |||
| f507a0d1b1 | |||
| 3718f3d182 | |||
| 37f769d4f5 | |||
| c0a7a2a7dc | |||
| 02e0245c92 | |||
| 9475fff227 |
@ -472,7 +472,7 @@ namespace SolarPower.Controllers
|
||||
|
||||
#region 顯示body //RowPosition = 1
|
||||
RowPosition++;
|
||||
var avghour = "0"; var avgKWHKWP = "0"; var avgdayKWH = "0"; var monthKWH = "0"; var monthmoney = "0"; var monthmoneyone = "0";
|
||||
var avghour = "0"; var avgKWHKWP = "0"; var avgdayKWH = "0"; double avgdayKWH_value = 0; var monthKWH = "0"; var monthmoney = "0"; var monthmoneyone = "0";
|
||||
var monthGeneratingCapacity = "";
|
||||
var check_hire = false;
|
||||
var sitedb = "";
|
||||
@ -484,9 +484,37 @@ namespace SolarPower.Controllers
|
||||
if (vForDataCount < (Formbody.Result.Data.Count - 1))//最後一筆(總計),不須取值
|
||||
{
|
||||
vForDataCount++;
|
||||
avghour = (Convert.ToDouble(dbody["tothour"].ToString()) + Convert.ToDouble(avghour)).ToString();
|
||||
avgKWHKWP = (Convert.ToDouble(dbody["KWHKWP"].ToString()) + Convert.ToDouble(avgKWHKWP)).ToString();
|
||||
avgdayKWH = (Convert.ToDouble(dbody["dayKWH"].ToString()) + Convert.ToDouble(avgdayKWH)).ToString();
|
||||
object vv = "";
|
||||
|
||||
avghour = (dbody["tothour"] == null) ? "NaN" : dbody["tothour"].ToString();
|
||||
avgKWHKWP = (dbody["KWHKWP"] == null) ? "NaN" : dbody["KWHKWP"].ToString();
|
||||
avgdayKWH = (dbody["dayKWH"] == null) ? "NaN" : dbody["dayKWH"].ToString();
|
||||
|
||||
//if (dbody.TryGetValue("tothour", out vv))
|
||||
// avghour = (Convert.ToDouble(dbody["tothour"].ToString()) + Convert.ToDouble(avghour)).ToString();
|
||||
//else
|
||||
// avghour = "NaN";
|
||||
|
||||
//if (dbody.TryGetValue("KWHKWP", out vv))
|
||||
// avgKWHKWP = (Convert.ToDouble(dbody["KWHKWP"].ToString()) + Convert.ToDouble(avgKWHKWP)).ToString();
|
||||
//else
|
||||
// avgKWHKWP = "NaN";
|
||||
|
||||
//if (dbody.TryGetValue("dayKWH", out vv))
|
||||
// avgKWHKWP = (Convert.ToDouble(dbody["dayKWH"].ToString()) + Convert.ToDouble(avgdayKWH)).ToString();
|
||||
//else
|
||||
// avgKWHKWP = "NaN";
|
||||
|
||||
//avghour = (Convert.ToDouble(dbody["tothour"].ToString()) + Convert.ToDouble(avghour)).ToString();
|
||||
//avgKWHKWP = (Convert.ToDouble(dbody["KWHKWP"].ToString()) + Convert.ToDouble(avgKWHKWP)).ToString();
|
||||
|
||||
//累加 平均發電量(日)
|
||||
if (avgdayKWH != "NaN")
|
||||
avgdayKWH_value += Convert.ToDouble(avgdayKWH);
|
||||
|
||||
|
||||
// avgdayKWH = (Convert.ToDouble(dbody["dayKWH"].ToString()) + Convert.ToDouble(avgdayKWH)).ToString();
|
||||
|
||||
monthKWH = dbody["monthKWH"] == null ? "0" : dbody["monthKWH"].ToString();
|
||||
monthmoney = dbody["monthmoney"] == null ? "0" : dbody["monthmoney"].ToString();
|
||||
monthmoneyone = dbody["monthmoneyone"] == null ? "0" : dbody["monthmoneyone"].ToString();
|
||||
@ -614,7 +642,7 @@ namespace SolarPower.Controllers
|
||||
cell.CellStyle = styleLine12;
|
||||
index++;
|
||||
cell = row.CreateCell(index);
|
||||
cell.SetCellValue(Math.Round(Convert.ToDouble(avgdayKWH) / Useday,2));
|
||||
cell.SetCellValue(Math.Round(avgdayKWH_value / Useday, 2));
|
||||
cell.CellStyle = styleLine12;
|
||||
index++;
|
||||
cell = row.CreateCell(index);
|
||||
|
||||
@ -162,7 +162,8 @@
|
||||
<script>
|
||||
var localurl = this.location.href;
|
||||
var powerids = new Array(0);//當前選擇電站
|
||||
var Type = 2; // //工作項目, 0:清洗 1:巡檢 2:維修
|
||||
var Type = 0; // //程式中 會自動-1, 工作項目, 0:清洗 1:巡檢 2:維修
|
||||
var OperationStatus = 0; //運維 - 完成狀態
|
||||
var stationId;
|
||||
var errortoID;
|
||||
var powerStationData;
|
||||
@ -1031,6 +1032,7 @@
|
||||
"data": function (d) {
|
||||
d.PowerStationIds = powerids;
|
||||
d.WorkType = Type;
|
||||
d.Status = OperationStatus;
|
||||
d.Range = $('#date-range').val();
|
||||
},
|
||||
"dataSrc": function (rel) {
|
||||
@ -2031,6 +2033,24 @@
|
||||
$('#date-range-record').on('change', function () {
|
||||
operationRecordTable.ajax.reload();
|
||||
});
|
||||
//#endregion
|
||||
|
||||
//#region 改狀態
|
||||
function CheckStatus(type, e) {
|
||||
$('#operation_record_table_wrapper').hide();
|
||||
OperationStatus = type;
|
||||
if ($(".status-type").hasClass("btn-success")) {
|
||||
$(".status-type").removeClass("btn-success").addClass("btn-secondary");
|
||||
}
|
||||
$(e).removeClass("btn-secondary").addClass("btn-success");
|
||||
//if (OperationStatus == 2) {
|
||||
// operationRecordTable.column(10).visible(true);
|
||||
//}
|
||||
//else {
|
||||
// operationRecordTable.column(10).visible(false);
|
||||
//}
|
||||
operationRecordTable.ajax.reload();
|
||||
}
|
||||
//#endregion
|
||||
|
||||
//#region 改變項目(運維)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
<div class="row mb-5 d-flex justify-content-start">
|
||||
<div class="row mb-5 d-flex justify-content-start">
|
||||
<div class="pr-3">
|
||||
<div class="btn-group btn-group-md">
|
||||
<button type="button" class="btn btn-success waves-effect waves-themed" onclick="ChangeType(0)" id="button0">全部</button>
|
||||
@ -7,6 +7,13 @@
|
||||
<button type="button" class="btn btn-secondary waves-effect waves-themed" onclick="ChangeType(1)" id="button1">清洗</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pr-3">
|
||||
<div class="btn-group btn-group-md">
|
||||
<button type="button" class="btn btn-success waves-effect waves-themed status-type" onclick="CheckStatus(0,this)">未完成</button>
|
||||
<button type="button" class="btn btn-secondary waves-effect waves-themed status-type" onclick="CheckStatus(1,this)">完成</button>
|
||||
<button type="button" class="btn btn-secondary waves-effect waves-themed status-type" onclick="CheckStatus(2,this)">刪除區</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pr-3">
|
||||
<button type="button" class="btn btn-secondary waves-effect waves-themed" onclick="ChangeDate30()">近30天</button>
|
||||
</div>
|
||||
|
||||
@ -64,14 +64,20 @@ namespace solarApp
|
||||
// Console.WriteLine("Error Occured");
|
||||
// }
|
||||
// }
|
||||
// ref: https://www.ruyut.com/2021/10/serilog.html
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.MinimumLevel.Verbose() // 設定最低顯示層級 預設: Information
|
||||
.WriteTo.File("Logs/solarApp/log-.log",
|
||||
.WriteTo.File("Logs/log-.log",
|
||||
rollingInterval: RollingInterval.Day, // 每天一個檔案
|
||||
outputTemplate: "{Timestamp:HH:mm:ss} [{Level:u5}] {Message:lj}{NewLine}{Exception}"
|
||||
) // 輸出到檔案 檔名範例: log-20211005.log
|
||||
.CreateLogger();
|
||||
|
||||
//Log.Information("Init log");
|
||||
|
||||
// Log.Debug("debug");
|
||||
|
||||
|
||||
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
||||
@ -5,15 +5,16 @@ using MySql.Data.MySqlClient;
|
||||
using solarApp.Model;
|
||||
using System.Configuration;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
//using Microsoft.Extensions.Logging;
|
||||
using System.Windows.Forms;
|
||||
using Serilog;
|
||||
|
||||
namespace solarApp.Service
|
||||
{
|
||||
class archiveLowData
|
||||
{
|
||||
string Connection1 = string.Empty;
|
||||
|
||||
private ILogger logger = Log.ForContext<archiveLowData>();
|
||||
public archiveLowData(string Connection_parame = null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Connection_parame))
|
||||
@ -42,17 +43,16 @@ namespace solarApp.Service
|
||||
// string yyyymm = System.DateTime.Now.AddMonths(-2).ToString("yyyy-MM");
|
||||
_siteID = siteID;
|
||||
//搬移的月份
|
||||
move_month = System.DateTime.Now.AddMonths(-1).ToString("yyyy-MM");
|
||||
//move_month = System.DateTime.Now.ToString("yyyy-MM"); //這個月
|
||||
move_month = System.DateTime.Now.AddMonths(-1).ToString("yyyy-MM")+ "-01";
|
||||
// move_month = System.DateTime.Now.ToString("yyyy-MM") + "-01"; //這個月
|
||||
|
||||
//_date1 = date1;
|
||||
get_siteInfo();
|
||||
checkTable();
|
||||
|
||||
moveData_station();
|
||||
moveData_inv();
|
||||
moveData_sensor();
|
||||
|
||||
|
||||
moveData_sensor();
|
||||
result = true;
|
||||
|
||||
return result;
|
||||
@ -301,7 +301,7 @@ namespace solarApp.Service
|
||||
//System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】開始執行[{_siteDB}.s{_siteID}_station]的資料表向[{_siteDB}_history.s{_siteID}_station]搬移");
|
||||
string for_insert_station = $@"INSERT {_siteDB}_history.s{_siteID01}_station(`ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `KWH`, `TODAYKWH`, `TOTALKWH`, `KWHKWP`, `PR`, `MP`, `SOLARHOUR`, `insertTime`)
|
||||
SELECT `ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `KWH`, `TODAYKWH`, `TOTALKWH`, `KWHKWP`, `PR`, `MP`, `SOLARHOUR`, `insertTime` FROM {_siteDB}.s{_siteID01}_station
|
||||
WHERE FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') < '{move_month}'";
|
||||
WHERE FROM_UNIXTIME(`TIMESTAMP`/1000, '%Y-%m-%d') < '{move_month}'";
|
||||
int rowCT = conn.Execute(for_insert_station, commandTimeout : 600);
|
||||
// System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】{_siteDB}.s{_siteID}_station的七月前資料寫入至{_siteDB}_history.s{_siteID}_station【寫入成功】於{dateTime}");
|
||||
|
||||
@ -315,7 +315,9 @@ namespace solarApp.Service
|
||||
//刪除原本的資料
|
||||
string for_delete_station = $@"DELETE FROM {_siteDB}.s{_siteID01}_station
|
||||
WHERE FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') < '{move_month}'";
|
||||
rowCT = conn.Execute(for_delete_station, commandTimeout: 600);
|
||||
//string for_delete_station = $@"DELETE FROM {_siteDB}.s{_siteID01}_station
|
||||
// WHERE date(CrdTime) < '{move_month}'";
|
||||
rowCT = conn.Execute(for_delete_station, commandTimeout: 600);
|
||||
//System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】{_siteDB}.s{_siteID}_sensoravg搬移至{_siteDB}_history.s{_siteID}_sensoravg【搬移資料成功】於{dateTime} 共 {delete_station.ToString()} 筆");
|
||||
duration = DateTime.Now - dt_start1;
|
||||
|
||||
@ -331,7 +333,7 @@ namespace solarApp.Service
|
||||
{
|
||||
//System.Diagnostics.Debug.WriteLine("【ArchiveRowData】[搬移資料失敗】");
|
||||
TimeSpan duration = DateTime.Now - dt_start1;
|
||||
arclog.insert_log(_powerStationID, "move raw s1", duration.TotalSeconds, $"{_siteDB}.s{_siteID}_station", $"{_siteDB}_history.s{_siteID}_station", "1", ex.Message, "0", conn, null);
|
||||
arclog.insert_log(_powerStationID, @$"move raw s1-{move_month}", duration.TotalSeconds, $"{_siteDB}.s{_siteID}_station", $"{_siteDB}_history.s{_siteID}_station", "1", ex.Message, "0", conn, null);
|
||||
|
||||
throw ex;
|
||||
}
|
||||
@ -358,29 +360,31 @@ namespace solarApp.Service
|
||||
{
|
||||
//MessageBox.Show("here");
|
||||
}
|
||||
// System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】開始執行[{_siteDB}.s{_siteID}_inv]的資料表向[{_siteDB}_history.s{_siteID}_inv]搬移");
|
||||
string for_insert_inv = $@"INSERT {_siteDB}_history.s{_siteID01}_inv(`ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `INVERTERID`, `SN`, `AC1V`, `AC1A`, `AC1W`, `AC1F`, `AC1WH`, `AC2V`, `AC2A`, `AC2W`, `AC2F`, `AC2WH`, `AC3V`, `AC3A`, `AC3W`, `AC3F`, `AC3WH`, `ACRUNTIME`, `DC1V`, `DC1A`, `DC1W`, `DC1WH`, `DC2V`, `DC2A`, `DC2W`, `DC2WH`, `DC3V`, `DC3A`, `DC3W`, `DC3WH`, `DC4V`, `DC4A`, `DC4W`, `DC4WH`, `DC5V`, `DC5A`, `DC5W`, `DC5WH`, `DCRUNTIME`, `WH`, `TODAYKWH`, `TOTALKWH`, `PR`, `RA1`, `RA2`, `RA3`, `RA4`, `RA5`, `CrdTime`)
|
||||
// System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】開始執行[{_siteDB}.s{_siteID}_inv]的資料表向[{_siteDB}_history.s{_siteID}_inv]搬移");
|
||||
string for_insert_inv = $@"INSERT {_siteDB}_history.s{_siteID01}_inv(`ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `INVERTERID`, `SN`, `AC1V`, `AC1A`, `AC1W`, `AC1F`, `AC1WH`, `AC2V`, `AC2A`, `AC2W`, `AC2F`, `AC2WH`, `AC3V`, `AC3A`, `AC3W`, `AC3F`, `AC3WH`, `ACRUNTIME`, `DC1V`, `DC1A`, `DC1W`, `DC1WH`, `DC2V`, `DC2A`, `DC2W`, `DC2WH`, `DC3V`, `DC3A`, `DC3W`, `DC3WH`, `DC4V`, `DC4A`, `DC4W`, `DC4WH`, `DC5V`, `DC5A`, `DC5W`, `DC5WH`, `DCRUNTIME`, `WH`, `TODAYKWH`, `TOTALKWH`, `PR`, `RA1`, `RA2`, `RA3`, `RA4`, `RA5`, `CrdTime`)
|
||||
SELECT `ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `INVERTERID`, `SN`, `AC1V`, `AC1A`, `AC1W`, `AC1F`, `AC1WH`, `AC2V`, `AC2A`, `AC2W`, `AC2F`, `AC2WH`, `AC3V`, `AC3A`, `AC3W`, `AC3F`, `AC3WH`, `ACRUNTIME`, `DC1V`, `DC1A`, `DC1W`, `DC1WH`, `DC2V`, `DC2A`, `DC2W`, `DC2WH`, `DC3V`, `DC3A`, `DC3W`, `DC3WH`, `DC4V`, `DC4A`, `DC4W`, `DC4WH`, `DC5V`, `DC5A`, `DC5W`, `DC5WH`, `DCRUNTIME`, `WH`, `TODAYKWH`, `TOTALKWH`, `PR`, `RA1`, `RA2`, `RA3`, `RA4`, `RA5`, `CrdTime` FROM {_siteDB}.s{_siteID01}_inv
|
||||
WHERE LEFT(crdTime, 7) < '{move_month}'";
|
||||
WHERE FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') < '{move_month}'";
|
||||
//WHERE LEFT(crdTime, 7) < '{move_month}'";
|
||||
int rowCT = conn.Execute(for_insert_inv, commandTimeout: 6000);
|
||||
//System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】{_siteDB}.s{_siteID}_inv的七月前資料寫入至{_siteDB}_history.s{_siteID}_inv【寫入成功】於{dateTime}");
|
||||
// log
|
||||
TimeSpan duration = DateTime.Now - dt_start1;
|
||||
arclog.insert_log(_powerStationID, "move raw s1", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_inv", $"{_siteDB}_history.s{_siteID01}_inv", "0", "", rowCT.ToString(), conn, null);
|
||||
arclog.insert_log(_powerStationID, @$"move raw s1 - {move_month}", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_inv", $"{_siteDB}_history.s{_siteID01}_inv", "0", "", rowCT.ToString(), conn, null);
|
||||
//arclog.insert_log(_powerStationID, "sensor step1", duration.TotalSeconds, "sensor_history_hour", "insert sensor hour", "0", "", rowCT.ToString(), conn, cmd);
|
||||
dt_start1 = DateTime.Now;
|
||||
|
||||
string for_delete_inv = $@"DELETE FROM {_siteDB}.s{_siteID01}_inv
|
||||
WHERE LEFT(crdTime, 7) < '{move_month}'";
|
||||
WHERE FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') < '{move_month}'";
|
||||
//WHERE LEFT(crdTime, 7) < '{move_month}'";
|
||||
rowCT = conn.Execute(for_delete_inv, commandTimeout: 6000);
|
||||
//System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】{_siteDB}.s{_siteID}_sensoravg搬移至{_siteDB}_history.s{_siteID}_sensoravg【搬移資料成功】於{dateTime} 共 {delete_inv.ToString()} 筆");
|
||||
duration = DateTime.Now - dt_start1;
|
||||
arclog.insert_log(_powerStationID, "delete raw s2", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_inv", "", "0", "", rowCT.ToString(), conn, null);
|
||||
arclog.insert_log(_powerStationID, @$"delete raw s2 - {move_month}", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_inv", "", "0", "", rowCT.ToString(), conn, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TimeSpan duration = DateTime.Now - dt_start1;
|
||||
arclog.insert_log(_powerStationID, "move raw s1", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_station", $"{_siteDB}_history.s{_siteID01}_station", "1", ex.Message, "0", conn, null);
|
||||
arclog.insert_log(_powerStationID, @$"move raw s1 - {move_month}", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_station", $"{_siteDB}_history.s{_siteID01}_station", "1", ex.Message, "err", conn, null);
|
||||
//arclog.insert_log(_powerStationID, "sensor step1", duration.TotalSeconds, "sensor_history_hour", "insert sensor hour", "0", "", rowCT.ToString(), conn, cmd);
|
||||
throw ex;
|
||||
}
|
||||
@ -407,24 +411,27 @@ namespace solarApp.Service
|
||||
string for_insert_sensoravg = $@"INSERT {_siteDB}_history.s{_siteID01}_sensoravg(`ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `SENSORAVG01`, `SENSORAVG02`, `SENSORAVG03`, `SENSORAVG04`, `SENSORAVG05`, `SENSORAVG06`, `SENSORAVG07`, `SENSORAVG08`, `SENSORAVG09`, `SENSORAVG10`, `SENSORAVG11`, `SENSORAVG12`, `SENSORAVG13`, `SENSORAVG14`, `SENSORAVG15`, `SENSORAVG16`, `SENSORAVG17`, `SENSORAVG18`, `SENSORAVG19`, `SENSORAVG20`, `SENSORAVG21`, `SENSORAVG22`, `SENSORAVG23`, `SENSORAVG24`, `SENSORAVG25`, `SENSORAVG26`, `SENSORAVG27`, `SENSORAVG28`, `SENSORAVG29`, `SENSORAVG30`, `SENSORAVG31`, `SENSORAVG32`, `SENSORAVG33`, `SENSORAVG34`, `SENSORAVG35`, `SENSORAVG36`, `SENSORAVG37`, `SENSORAVG38`, `SENSORAVG39`, `SENSORAVG40`, `SENSORAVG41`, `SENSORAVG42`, `SENSORAVG43`, `SENSORAVG44`, `SENSORAVG45`, `SENSORAVG46`, `SENSORAVG47`, `SENSORAVG48`, `SENSORAVG49`, `SENSORAVG50`, `CrdTime`)
|
||||
SELECT `ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `SENSORAVG01`, `SENSORAVG02`, `SENSORAVG03`, `SENSORAVG04`, `SENSORAVG05`, `SENSORAVG06`, `SENSORAVG07`, `SENSORAVG08`, `SENSORAVG09`, `SENSORAVG10`, `SENSORAVG11`, `SENSORAVG12`, `SENSORAVG13`, `SENSORAVG14`, `SENSORAVG15`, `SENSORAVG16`, `SENSORAVG17`, `SENSORAVG18`, `SENSORAVG19`, `SENSORAVG20`, `SENSORAVG21`, `SENSORAVG22`, `SENSORAVG23`, `SENSORAVG24`, `SENSORAVG25`, `SENSORAVG26`, `SENSORAVG27`, `SENSORAVG28`, `SENSORAVG29`, `SENSORAVG30`, `SENSORAVG31`, `SENSORAVG32`, `SENSORAVG33`, `SENSORAVG34`, `SENSORAVG35`, `SENSORAVG36`, `SENSORAVG37`, `SENSORAVG38`, `SENSORAVG39`, `SENSORAVG40`, `SENSORAVG41`, `SENSORAVG42`, `SENSORAVG43`, `SENSORAVG44`, `SENSORAVG45`, `SENSORAVG46`, `SENSORAVG47`, `SENSORAVG48`, `SENSORAVG49`, `SENSORAVG50`, `CrdTime`
|
||||
FROM {_siteDB}.s{_siteID01}_sensoravg
|
||||
WHERE LEFT(crdTime, 7) < '{move_month}'";
|
||||
WHERE FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') < '{move_month}'";
|
||||
// WHERE LEFT(crdTime, 7) < '{move_month}'";
|
||||
int rowCT = conn.Execute(for_insert_sensoravg, commandTimeout: 600);
|
||||
// log
|
||||
TimeSpan duration = DateTime.Now - dt_start1;
|
||||
arclog.insert_log(_powerStationID, "move raw s1", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_sensoravg", $"{_siteDB}_history.s{_siteID01}_sensoravg", "0", "", rowCT.ToString(), conn, null);
|
||||
arclog.insert_log(_powerStationID, @$"move raw s1 - {move_month}", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_sensoravg", $"{_siteDB}_history.s{_siteID01}_sensoravg", "0", "", rowCT.ToString(), conn, null);
|
||||
dt_start1 = DateTime.Now;
|
||||
|
||||
string for_delete_sensoravg = $@"DELETE FROM {_siteDB}.s{_siteID01}_sensoravg WHERE LEFT(crdTime, 7) < '{move_month}'";
|
||||
string for_delete_sensoravg = $@"DELETE FROM {_siteDB}.s{_siteID01}_sensoravg
|
||||
WHERE FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') < '{move_month}'";
|
||||
// WHERE LEFT(crdTime, 7) < '{move_month}'";
|
||||
rowCT = conn.Execute(for_delete_sensoravg, commandTimeout: 600);
|
||||
|
||||
duration = DateTime.Now - dt_start1;
|
||||
arclog.insert_log(_powerStationID, "delete raw s2", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_sensoravg", "", "0", "", rowCT.ToString(), conn, null);
|
||||
arclog.insert_log(_powerStationID, @$"delete raw s2 - {move_month}", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_sensoravg", "", "0", "", rowCT.ToString(), conn, null);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TimeSpan duration = DateTime.Now - dt_start1;
|
||||
arclog.insert_log(_powerStationID, "move raw s1", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_sensoravg", $"{_siteDB}_history.s{_siteID01}_sensoravg", "1", ex.Message, "0", conn, null);
|
||||
arclog.insert_log(_powerStationID, @$"move raw s1 - {move_month}", duration.TotalSeconds, $"{_siteDB}.s{_siteID01}_sensoravg", $"{_siteDB}_history.s{_siteID01}_sensoravg", "1", ex.Message, "0", conn, null);
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ using MySql.Data.MySqlClient;
|
||||
using Dapper;
|
||||
using solarApp.Model;
|
||||
using System.Configuration;
|
||||
using Serilog;
|
||||
|
||||
namespace solarApp.Service
|
||||
{
|
||||
@ -14,6 +15,9 @@ namespace solarApp.Service
|
||||
public class getStationSvc
|
||||
{
|
||||
public string Connection1 { get; set; }
|
||||
|
||||
private ILogger logger = Log.ForContext<getSensorSvc>();
|
||||
|
||||
public getStationSvc(string Connection_parame = null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Connection_parame))
|
||||
@ -37,7 +41,7 @@ namespace solarApp.Service
|
||||
/// <returns></returns>
|
||||
public List<raw_statino> get_station_raw(string reportDate, string siteDB, string siteID)
|
||||
{
|
||||
List<raw_statino> ds;
|
||||
List<raw_statino> ds = null;
|
||||
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
||||
{
|
||||
conn.Open();
|
||||
@ -52,7 +56,7 @@ namespace solarApp.Service
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
logger.Error(@$"【get_station_raw】執行失敗 {siteDB}.s{siteID} _station 在{reportDate} - [Exception]:" + ex.ToString());
|
||||
}
|
||||
return ds;
|
||||
}
|
||||
@ -83,7 +87,7 @@ namespace solarApp.Service
|
||||
/// <returns></returns>
|
||||
public List<raw_station_day> get_station_rawAvg(string date1, string date2, string siteDB, string siteID)
|
||||
{
|
||||
List<raw_station_day> ds;
|
||||
List<raw_station_day> ds = null;
|
||||
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
||||
{
|
||||
conn.Open();
|
||||
@ -104,7 +108,7 @@ namespace solarApp.Service
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
logger.Error(@$"【get_station_rawAvg】執行失敗 {siteDB}.s{siteID} _station 在{date1} - {date2} - [Exception]:" + ex.ToString());
|
||||
}
|
||||
|
||||
return ds;
|
||||
@ -193,13 +197,37 @@ namespace solarApp.Service
|
||||
conn.Open(); // 01 控制器編號
|
||||
string sql = @" select id, CompanyId, `code` , SerialNumber, CONCAT(`code` ,'01') SiteID, SiteDB, `name` SiteName
|
||||
from power_station
|
||||
where deleted = 0 and `status`= 1 ";
|
||||
where deleted = 0 and `status`= 1
|
||||
ORDER BY id ";
|
||||
// id <> 14";and id > 24
|
||||
List<station_list> ds = conn.Query<station_list>(sql).AsList<station_list>();
|
||||
conn.Close();
|
||||
return ds;
|
||||
}
|
||||
}
|
||||
|
||||
public List<station_list> get_station_list32(bool include32)
|
||||
{
|
||||
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
||||
{
|
||||
conn.Open(); // 01 控制器編號
|
||||
string sql = @" select id, CompanyId, `code` , SerialNumber, CONCAT(`code` ,'01') SiteID, SiteDB, `name` SiteName
|
||||
from power_station
|
||||
where deleted = 0 and `status`= 1 and id <> 32 ";
|
||||
if (include32)
|
||||
{
|
||||
sql = @" select id, CompanyId, `code` , SerialNumber, CONCAT(`code` ,'01') SiteID, SiteDB, `name` SiteName
|
||||
from power_station
|
||||
where deleted = 0 and `status`= 1 and id = 32";
|
||||
}
|
||||
|
||||
// id <> 14";and id > 24
|
||||
List<station_list> ds = conn.Query<station_list>(sql).AsList<station_list>();
|
||||
conn.Close();
|
||||
return ds;
|
||||
}
|
||||
}
|
||||
|
||||
public List<PowerStation> get_powerStation()
|
||||
{
|
||||
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
||||
|
||||
@ -6,7 +6,8 @@ using Dapper;
|
||||
using solarApp.Model;
|
||||
using System.Configuration;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
//using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
|
||||
namespace solarApp.Service
|
||||
{
|
||||
@ -14,6 +15,18 @@ namespace solarApp.Service
|
||||
{
|
||||
string Connection1 = string.Empty;
|
||||
ILogger _logger;
|
||||
public ILogger MyLoger
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_logger == null)
|
||||
{
|
||||
//需要添加使用的当前类名空间名称,不加的话,不显示
|
||||
_logger = Log.ForContext<procArchiveHourly>();
|
||||
}
|
||||
return _logger;
|
||||
}
|
||||
}
|
||||
public string _siteID { get; set; }
|
||||
public string _siteDB { get; set; }
|
||||
public string _siteID01 { get; set; }
|
||||
@ -44,7 +57,7 @@ namespace solarApp.Service
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcArchiveSensorHourly】開始執行[{0}]在{1}取得電站編號", _siteID, _date1);
|
||||
_logger.Information("【ProcArchiveSensorHourly】開始執行[{0}]在{1}取得電站編號", _siteID, _date1);
|
||||
}
|
||||
|
||||
#region 取得 PowerStationID
|
||||
@ -60,7 +73,7 @@ namespace solarApp.Service
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcArchiveSensorHourly】執行完成[{0}]在{1}取得電站編號 - {2}", _siteID, _date1, _powerStationID);
|
||||
_logger.Information("【ProcArchiveSensorHourly】執行完成[{0}]在{1}取得電站編號 - {2}", _siteID, _date1, _powerStationID);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -72,8 +85,8 @@ namespace solarApp.Service
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogError("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}取得電站編號", _siteID, _date1);
|
||||
_logger.LogError("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}取得電站編號 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
_logger.Error("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}取得電站編號", _siteID, _date1);
|
||||
_logger.Error("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}取得電站編號 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
|
||||
throw ex;
|
||||
@ -95,7 +108,7 @@ namespace solarApp.Service
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcArchiveSensorHourly】開始執行[{0}]在{1}設備寫入資料表的資料", _siteID, _date1);
|
||||
_logger.Information("【ProcArchiveSensorHourly】開始執行[{0}]在{1}設備寫入資料表的資料", _siteID, _date1);
|
||||
}
|
||||
string sql = $@"
|
||||
select x.*, z.itemname, z.HourType, z.DayType, z.MonthType,z.SetWhat
|
||||
@ -161,7 +174,7 @@ namespace solarApp.Service
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcArchiveSensorHourly】執行完成[{0}]在{1}設備寫入資料表的資料", _siteID, _date1);
|
||||
_logger.Information("【ProcArchiveSensorHourly】執行完成[{0}]在{1}設備寫入資料表的資料", _siteID, _date1);
|
||||
}
|
||||
|
||||
conn.Close();
|
||||
@ -172,8 +185,8 @@ namespace solarApp.Service
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogError("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}設備寫入資料表的資料", _siteID, _date1);
|
||||
_logger.LogError("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}設備寫入資料表的資料 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
_logger.Error("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}設備寫入資料表的資料", _siteID, _date1);
|
||||
_logger.Error("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}設備寫入資料表的資料 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
@ -209,8 +222,8 @@ namespace solarApp.Service
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogError("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}日照計更新至資料表的資料", _siteID, _date1);
|
||||
_logger.LogError("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}日照計更新至資料表的資料 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
_logger.Error("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}日照計更新至資料表的資料", _siteID, _date1);
|
||||
_logger.Error("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}日照計更新至資料表的資料 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
@ -233,7 +246,7 @@ namespace solarApp.Service
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcArchiveSensorHourly】開始執行[{0}]在{1}累積日照差更新至資料表的資料", _siteID, _date1);
|
||||
_logger.Information("【ProcArchiveSensorHourly】開始執行[{0}]在{1}累積日照差更新至資料表的資料", _siteID, _date1);
|
||||
}
|
||||
//取前累積日照
|
||||
string sql = $@" select IrrDay
|
||||
@ -281,7 +294,7 @@ namespace solarApp.Service
|
||||
conn.Execute(ss, commandTimeout: 600);
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcArchiveSensorHourly】執行完成[{0}]在{1}累積日照差更新至資料表的資料", _siteID, _date1);
|
||||
_logger.Information("【ProcArchiveSensorHourly】執行完成[{0}]在{1}累積日照差更新至資料表的資料", _siteID, _date1);
|
||||
}
|
||||
conn.Close();
|
||||
}
|
||||
@ -290,8 +303,8 @@ namespace solarApp.Service
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogError("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}累積日照差更新資料表的資料", _siteID, _date1);
|
||||
_logger.LogError("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}累積日照差更新資料表的資料 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
_logger.Error("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}累積日照差更新資料表的資料", _siteID, _date1);
|
||||
_logger.Error("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}累積日照差更新資料表的資料 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
@ -309,7 +322,7 @@ namespace solarApp.Service
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcArchiveSensorHourly】開始執行[{0}]在{1}設備清除資料表的資料", _siteID, _date1);
|
||||
_logger.Information("【ProcArchiveSensorHourly】開始執行[{0}]在{1}設備清除資料表的資料", _siteID, _date1);
|
||||
}
|
||||
string d1 = _date1 + ":00:00";
|
||||
string clearTime = Convert.ToDateTime(d1).ToString("yyyy-MM-dd");
|
||||
@ -325,7 +338,7 @@ namespace solarApp.Service
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcArchiveSensorHourly】執行完成[{0}]在{1}設備清除資料表的資料", _siteID, _date1);
|
||||
_logger.Information("【ProcArchiveSensorHourly】執行完成[{0}]在{1}設備清除資料表的資料", _siteID, _date1);
|
||||
}
|
||||
|
||||
conn.Close();
|
||||
@ -336,8 +349,8 @@ namespace solarApp.Service
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogError("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}設備清除資料表的資料", _siteID, _date1);
|
||||
_logger.LogError("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}設備清除資料表的資料 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
_logger.Error("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}設備清除資料表的資料", _siteID, _date1);
|
||||
_logger.Error("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}設備清除資料表的資料 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
|
||||
@ -6,7 +6,9 @@ using Dapper;
|
||||
using solarApp.Model;
|
||||
using System.Configuration;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
//using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
//using solarApp.Service.proArchiveLog;
|
||||
|
||||
namespace solarApp.Service
|
||||
@ -14,10 +16,10 @@ namespace solarApp.Service
|
||||
public class procInvSvc
|
||||
{
|
||||
string Connection1 = string.Empty;
|
||||
ILogger _logger;
|
||||
private ILogger logger = Log.ForContext<procInvSvc>();
|
||||
|
||||
|
||||
|
||||
public procInvSvc(string Connection_parame = null, ILogger logger = null)
|
||||
public procInvSvc(string Connection_parame = null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Connection_parame))
|
||||
{
|
||||
@ -28,10 +30,10 @@ namespace solarApp.Service
|
||||
Connection1 = ConfigurationManager.ConnectionStrings["mySql"].ConnectionString;
|
||||
}
|
||||
|
||||
if (logger != null)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
//if (logger != null)
|
||||
//{
|
||||
// _logger = logger;
|
||||
//}
|
||||
}
|
||||
|
||||
public string _siteID { get; set; }
|
||||
@ -41,58 +43,55 @@ namespace solarApp.Service
|
||||
//public string _date2 { get; set; }
|
||||
public string _powerStationID { get; set; }
|
||||
|
||||
procArchiveLog arclog = new procArchiveLog();
|
||||
|
||||
public bool clearData()
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
||||
{
|
||||
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
||||
{
|
||||
conn.Open();
|
||||
conn.Open();
|
||||
try
|
||||
{
|
||||
//if (_logger != null)
|
||||
//{
|
||||
// logger.Information("【ProcInvSvc】開始執行[{0}]在{1}逆變器清除資料表的資料", _siteID, _date1);
|
||||
//}
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcInvSvc】開始執行[{0}]在{1}逆變器清除資料表的資料", _siteID, _date1);
|
||||
}
|
||||
|
||||
//string sql = @"
|
||||
// delete from inverter_history_15min where powerstationID = @powerStationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1;
|
||||
// delete from inverter_history_hour where powerstationID = @powerStationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1;
|
||||
// delete from inverter_history_day where powerstationID = @powerStationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1;
|
||||
// delete from inverter_history_month where powerstationID = @powerStationID and left(`TIMESTAMP`, 7) = left(@date1, 7) ;";
|
||||
string sql = @"
|
||||
delete from inverter_history_15min where powerstationID = @powerStationID and CrdDate = @date1;
|
||||
delete from inverter_history_hour where powerstationID = @powerStationID and CrdDate = @date1;
|
||||
delete from inverter_history_day where powerstationID = @powerStationID and CrdDate = @date1;
|
||||
delete from inverter_history_month where powerstationID = @powerStationID and left(`TIMESTAMP`, 7) = left(@date1, 7) ;";
|
||||
//var ds = conn.Execute(sql, new { date1 = _date1, PowerStationID = _powerStationID });
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandTimeout = 360;
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
cmd.Parameters.AddWithValue("@PowerStationID", _powerStationID);
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器清除資料表的資料", _siteID, _date1);
|
||||
}
|
||||
|
||||
conn.Close();
|
||||
//string sql = @"
|
||||
// delete from inverter_history_15min where powerstationID = @powerStationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1;
|
||||
// delete from inverter_history_hour where powerstationID = @powerStationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1;
|
||||
// delete from inverter_history_day where powerstationID = @powerStationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1;
|
||||
// delete from inverter_history_month where powerstationID = @powerStationID and left(`TIMESTAMP`, 7) = left(@date1, 7) ;";
|
||||
string sql = @"
|
||||
delete from inverter_history_15min where powerstationID = @powerStationID and CrdDate = @date1;
|
||||
delete from inverter_history_hour where powerstationID = @powerStationID and CrdDate = @date1;
|
||||
delete from inverter_history_day where powerstationID = @powerStationID and CrdDate = @date1;
|
||||
delete from inverter_history_month where powerstationID = @powerStationID and left(`TIMESTAMP`, 7) = left(@date1, 7) ;";
|
||||
//var ds = conn.Execute(sql, new { date1 = _date1, PowerStationID = _powerStationID });
|
||||
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandTimeout = 360;
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
cmd.Parameters.AddWithValue("@PowerStationID", _powerStationID);
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
|
||||
logger.Information(@$"【ProcInvSvc】執行完成[{_siteID}]在 {_date1} 逆變器清除資料表的資料");
|
||||
result = true;
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_logger != null)
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器清除資料表的資料", _siteID, _date1);
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器清除資料表的資料 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器清除資料表的資料", _siteID, _date1);
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器清除資料表的資料 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
//throw ex;
|
||||
arclog.insert_log(_powerStationID, "step0 del inv ", 0, "inv", "del inv error", "0", "", "", conn, cmd);
|
||||
|
||||
}
|
||||
throw ex;
|
||||
conn.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -130,78 +129,69 @@ namespace solarApp.Service
|
||||
public bool get_siteInfo()
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
||||
{
|
||||
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
||||
conn.Open();
|
||||
try
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcInvSvc】開始執行[{0}]在{1}逆變器取得電站編號", _siteID, _date1);
|
||||
}
|
||||
logger.Information("【ProcInvSvc】開始執行[{0}]在{1}逆變器取得電站編號", _siteID, _date1);
|
||||
|
||||
#region 取得 PowerStationID
|
||||
string sql = @" select id , `code` siteID, siteDB, `name` siteName
|
||||
from solar_master.power_station where `code` = @siteID";
|
||||
var ds = conn.Query<station_list>(sql, new { siteID = _siteID }).AsList<station_list>();
|
||||
foreach (var item in ds)
|
||||
{
|
||||
_powerStationID = item.id;
|
||||
_siteDB = item.SiteDB;
|
||||
_siteID01 = item.SiteID + "01";
|
||||
}
|
||||
#region 取得 PowerStationID
|
||||
string sql = @" select id , `code` siteID, siteDB, `name` siteName
|
||||
from solar_master.power_station where `code` = @siteID";
|
||||
var ds = conn.Query<station_list>(sql, new { siteID = _siteID }).AsList<station_list>();
|
||||
foreach (var item in ds)
|
||||
{
|
||||
_powerStationID = item.id;
|
||||
_siteDB = item.SiteDB;
|
||||
_siteID01 = item.SiteID + "01";
|
||||
}
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器取得電站編號 - {2}", _siteID, _date1, _powerStationID);
|
||||
}
|
||||
|
||||
#endregion
|
||||
conn.Close();
|
||||
logger.Information("【ProcInvSvc】執行完成[{0}]在{1}逆變器取得電站編號 - {2}", _siteID, _date1, _powerStationID);
|
||||
|
||||
#endregion
|
||||
|
||||
result = true;
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_logger != null)
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器取得電站編號", _siteID, _date1);
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器取得電站編號 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
|
||||
throw ex;
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器取得電站編號", _siteID, _date1);
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器取得電站編號 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
|
||||
arclog.insert_log(_powerStationID, "step0 select stationID ", 0, "stationID", "select stationID", "0", "", "", conn, null);
|
||||
}
|
||||
conn.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
bool insert_inv()
|
||||
{
|
||||
bool result = false;
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
//try
|
||||
//{
|
||||
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
||||
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
||||
{
|
||||
conn.Open();
|
||||
string ss = @"SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY,',''));";
|
||||
conn.Execute(ss);
|
||||
|
||||
string sql = string.Empty;
|
||||
#region 15 min
|
||||
try
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcInvSvc】開始執行[{0}]在{1}逆變器15min補償", _siteID, _date1);
|
||||
}
|
||||
#region 15 min
|
||||
try
|
||||
{
|
||||
logger.Information("【ProcInvSvc】開始執行[{0}]在{1}逆變器15min補償", _siteID, _date1);
|
||||
|
||||
sql = @$"DROP TABLE IF EXISTS del_Inv_day_" + _powerStationID + @"_s1;
|
||||
CREATE TABLE del_Inv_day_" + _powerStationID + @"_s1
|
||||
select * from " + _siteDB + ".s" + _siteID01 + @"_inv a
|
||||
WHERE left(crdTime, 10) = @date1;
|
||||
# 2. add index
|
||||
ALTER TABLE del_Inv_day_" + _powerStationID + @"_s1 ADD INDEX `temp_index` (crdTime, inverterid);";
|
||||
//int ct = conn.Execute(sql, new { date1 = _date1 });
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
CREATE TABLE del_Inv_day_" + _powerStationID + @"_s1
|
||||
select * from " + _siteDB + ".s" + _siteID01 + @"_inv a
|
||||
WHERE left(crdTime, 10) = @date1;
|
||||
# 2. add index
|
||||
ALTER TABLE del_Inv_day_" + _powerStationID + @"_s1 ADD INDEX `temp_index` (crdTime, inverterid);";
|
||||
//int ct = conn.Execute(sql, new { date1 = _date1 });
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandTimeout = 360;
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
@ -209,65 +199,34 @@ namespace solarApp.Service
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
|
||||
|
||||
sql = @"
|
||||
INSERT INTO solar_master.inverter_history_15min( PowerStationId, TIMESTAMP, INVERTERID, KWH, TODAYKWH, KWHKWP)
|
||||
select PowerStationId, reportdate, a.inverterid, KWH, TODAYKWH, (kwh/(capacity/4)) kwpkwp from
|
||||
(
|
||||
select @PowerStationId PowerStationId, CONCAT(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':00:00')reportdate, inverterid,
|
||||
(sum(WH)/1000) KWH, max(TODAYKWH) TODAYKWH
|
||||
from del_Inv_day_" + _powerStationID + @"_s1
|
||||
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 and right(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') , 2) between '00' and '10'
|
||||
group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') , inverterid
|
||||
union
|
||||
select @PowerStationId PowerStationId, CONCAT(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':15:00')reportdate, inverterid,
|
||||
(sum(WH)/1000) KWH, max(TODAYKWH) TODAYKWH
|
||||
from del_Inv_day_" + _powerStationID + @"_s1
|
||||
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 and right(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') , 2) between '15' and '25'
|
||||
group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') , inverterid
|
||||
union
|
||||
select @PowerStationId PowerStationId, CONCAT(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':30:00')reportdate, inverterid,
|
||||
(sum(WH)/1000) KWH, max(TODAYKWH) TODAYKWH
|
||||
from del_Inv_day_" + _powerStationID + @"_s1
|
||||
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 and right(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') , 2) between '30' and '40'
|
||||
group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') , inverterid
|
||||
union
|
||||
select @PowerStationId PowerStationId, CONCAT(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':45:00')reportdate, inverterid,
|
||||
(sum(WH)/1000) KWH, max(TODAYKWH) TODAYKWH
|
||||
from del_Inv_day_" + _powerStationID + @"_s1
|
||||
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 and right(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') , 2) between '45' and '55'
|
||||
group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') , inverterid
|
||||
) a join " + _siteDB + @".inverter b on a.inverterid = b.inverterid";
|
||||
|
||||
//sql = @"
|
||||
// INSERT INTO solar_master.inverter_history_15min( PowerStationId, TIMESTAMP, INVERTERID, KWH, TODAYKWH, KWHKWP)
|
||||
// select PowerStationId, reportdate, a.inverterid, KWH, TODAYKWH, (kwh/(capacity/4)) kwpkwp from
|
||||
// (
|
||||
// select @PowerStationId PowerStationId, CONCAT(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':00:00')reportdate, inverterid,
|
||||
// (sum(WH)/1000) KWH, max(TODAYKWH) TODAYKWH
|
||||
// from " + _siteDB + ".s" + _siteID01 + @"_inv
|
||||
// where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 and right(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') , 2) between '00' and '10'
|
||||
// group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') , inverterid
|
||||
// union
|
||||
// select @PowerStationId PowerStationId, CONCAT(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':15:00')reportdate, inverterid,
|
||||
// (sum(WH)/1000) KWH, max(TODAYKWH) TODAYKWH
|
||||
// from " + _siteDB + ".s" + _siteID01 + @"_inv
|
||||
// where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 and right(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') , 2) between '15' and '25'
|
||||
// group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') , inverterid
|
||||
// union
|
||||
// select @PowerStationId PowerStationId, CONCAT(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':30:00')reportdate, inverterid,
|
||||
// (sum(WH)/1000) KWH, max(TODAYKWH) TODAYKWH
|
||||
// from " + _siteDB + ".s" + _siteID01 + @"_inv
|
||||
// where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 and right(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') , 2) between '30' and '40'
|
||||
// group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') , inverterid
|
||||
// union
|
||||
// select @PowerStationId PowerStationId, CONCAT(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':45:00')reportdate, inverterid,
|
||||
// (sum(WH)/1000) KWH, max(TODAYKWH) TODAYKWH
|
||||
// from " + _siteDB + ".s" + _siteID01 + @"_inv
|
||||
// where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 and right(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') , 2) between '45' and '55'
|
||||
// group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') , inverterid
|
||||
// ) a join " + _siteDB + @".inverter b on a.inverterid = b.inverterid";
|
||||
|
||||
INSERT INTO solar_master.inverter_history_15min( PowerStationId, TIMESTAMP, INVERTERID, KWH, TODAYKWH, KWHKWP)
|
||||
select PowerStationId, reportdate, a.inverterid, KWH, TODAYKWH, (kwh/(capacity/4)) kwpkwp from
|
||||
(
|
||||
select @PowerStationId PowerStationId, CONCAT(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':00:00')reportdate, inverterid,
|
||||
(sum(WH)/1000) KWH, max(TODAYKWH) TODAYKWH
|
||||
from del_Inv_day_" + _powerStationID + @"_s1
|
||||
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 and right(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') , 2) between '00' and '10'
|
||||
group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') , inverterid
|
||||
union
|
||||
select @PowerStationId PowerStationId, CONCAT(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':15:00')reportdate, inverterid,
|
||||
(sum(WH)/1000) KWH, max(TODAYKWH) TODAYKWH
|
||||
from del_Inv_day_" + _powerStationID + @"_s1
|
||||
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 and right(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') , 2) between '15' and '25'
|
||||
group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') , inverterid
|
||||
union
|
||||
select @PowerStationId PowerStationId, CONCAT(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':30:00')reportdate, inverterid,
|
||||
(sum(WH)/1000) KWH, max(TODAYKWH) TODAYKWH
|
||||
from del_Inv_day_" + _powerStationID + @"_s1
|
||||
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 and right(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') , 2) between '30' and '40'
|
||||
group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') , inverterid
|
||||
union
|
||||
select @PowerStationId PowerStationId, CONCAT(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H'), ':45:00')reportdate, inverterid,
|
||||
(sum(WH)/1000) KWH, max(TODAYKWH) TODAYKWH
|
||||
from del_Inv_day_" + _powerStationID + @"_s1
|
||||
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 and right(FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H:%i') , 2) between '45' and '55'
|
||||
group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') , inverterid
|
||||
) a join " + _siteDB + @".inverter b on a.inverterid = b.inverterid";
|
||||
|
||||
|
||||
//var ds = conn.Execute(sql, new { date1 = _date1, PowerStationID = _powerStationID });
|
||||
@ -278,70 +237,21 @@ namespace solarApp.Service
|
||||
cmd.Parameters.Clear();
|
||||
cmd.Dispose();
|
||||
|
||||
if (_logger != null)
|
||||
_logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器15min補償", _siteID, _date1);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器15min補償", _siteID, _date1);
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器15min補償 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
logger.Information("【ProcInvSvc】執行完成[{0}]在{1}逆變器15min補償", _siteID, _date1);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器15min補償", _siteID, _date1);
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器15min補償 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
arclog.insert_log(_powerStationID, "step1 insert inverter_15min history " + _date1, 0, "inverter_history_15min", "insert inverter_15min history", "1", "", "", conn, cmd);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region hour
|
||||
try
|
||||
{
|
||||
if (_logger != null)
|
||||
_logger.LogInformation("【ProcInvSvc】開始執行[{0}]在{1}逆變器hour補償", _siteID, _date1);
|
||||
|
||||
//sql = @"
|
||||
// insert into solar_master.inverter_history_hour (PowerStationId, INVERTERID, TIMESTAMP, Irradiance, AC1V, AC1A, AC1W, AC1F, AC1WH, AC2V, AC2A, AC2W, AC2F, AC2WH,
|
||||
// AC3V, AC3A, AC3W, AC3F, AC3WH, DC1V, DC1A, DC1W, DC1WH, DC2V, DC2A, DC2W, DC2WH, DC3V, DC3A, DC3W, DC3WH, DC4V, DC4A, DC4W, DC4WH, DC5V, DC5A, DC5W, DC5WH,
|
||||
// PR, RA1, RA2, RA3, RA4, RA5, DCKW, ACKW, KWH, TODAYKWH, TOTALKWH, KWHKWP)
|
||||
|
||||
// SELECT @powerstationID powerStationID, a.INVERTERID, a.reportDate, IFNULL(Irradiance, 0), a.AC1V, a.AC1A, a.AC1W, a.AC1F, a.AC1WH, a.AC2V, a.AC2A, a.AC2W, a.AC2F, a.AC2WH,
|
||||
// a.AC3V, a.AC3A, a.AC3W, a.AC3F, a.AC3WH, a.DC1V, a.DC1A, a.DC1W, a.DC1WH, a.DC2V, a.DC2A, a.DC2W, a.DC2WH, a.DC3V, a.DC3A, a.DC3W,
|
||||
// a.DC3WH, a.DC4V, a.DC4A, a.DC4W, a.DC4WH, a.DC5V, a.DC5A, a.DC5W, a.DC5WH,
|
||||
// inv_pr.PR, a.RA1, a.RA2, a.RA3, a.RA4, a.RA5, ((DC1W + DC2W + DC3W + DC4W+ DC5W) / 1000) DCKW,
|
||||
// ((AC1W + AC2W + AC3W) / 1000) ACKW, a.KWH, a.TODAYKWH, a.TOTALKWH, (a.KWH / i.Capacity) AS KWHKWP
|
||||
// from
|
||||
// ( -- 取得該時間區間的KWH
|
||||
// SELECT concat(FROM_UNIXTIME(a.TIMESTAMP/1000,'%Y-%m-%d %H'), ':00:00') reportDate, a.INVERTERID,
|
||||
// AVG(a.AC1V) AS AC1V, AVG(a.AC1A) AS AC1A, round(SUM(a.AC1W), 5) AS AC1W, AVG(a.AC1F) AS AC1F, SUM(a.AC1WH) AS AC1WH, AVG(a.AC2V) AS AC2V,
|
||||
// AVG(a.AC2A) AS AC2A, round(SUM(a.AC2W), 5) AS AC2W, AVG(a.AC2F) AS AC2F, SUM(a.AC2WH) AS AC2WH,AVG(a.AC3V) AS AC3V, AVG(a.AC3A) AS AC3A,
|
||||
// round(SUM(a.AC3W),5) AS AC3W, AVG(a.AC3F) AS AC3F, SUM(a.AC3WH) AS AC3WH, AVG(a.DC1V) AS DC1V, AVG(a.DC1A) AS DC1A, SUM(a.DC1W) AS DC1W,
|
||||
// SUM(a.DC1WH) AS DC1WH, AVG(a.DC2V) AS DC2V, AVG(a.DC2A) AS DC2A, SUM(a.DC2W) AS DC2W, SUM(a.DC2WH) AS DC2WH, AVG(a.DC3V) AS DC3V,
|
||||
// AVG(a.DC3A) AS DC3A, AVG(a.DC3W) AS DC3W, AVG(a.DC3WH) AS DC3WH, AVG(a.DC4V) AS DC4V, AVG(a.DC4A) AS DC4A, SUM(a.DC4W) AS DC4W,
|
||||
// SUM(a.DC4WH) AS DC4WH,AVG(a.DC5V) AS DC5V, AVG(a.DC5A) AS DC5A, SUM(a.DC5W) AS DC5W, SUM(a.DC5WH) AS DC5WH,
|
||||
// AVG(a.RA1) AS RA1, AVG(a.RA2) AS RA2, AVG(a.RA3) AS RA3,
|
||||
// AVG(a.RA4) AS RA4, AVG(a.RA5) AS RA5, MAX(a.TODAYKWH) AS TODAYKWH, MAX(a.TOTALKWH) AS TOTALKWH, (SUM(a.WH)/1000) AS KWH
|
||||
// FROM " + _siteDB + ".s" + _siteID01 + @"_inv a
|
||||
// WHERE left(FROM_UNIXTIME(a.TIMESTAMP / 1000, '%Y-%m-%d'), 10) = @date1
|
||||
// GROUP BY left(FROM_UNIXTIME(a.TIMESTAMP/ 1000, '%Y-%m-%d %H'), 13), a.INVERTERID
|
||||
// ) a
|
||||
// LEFT JOIN( -- 取得整點值PR
|
||||
// SELECT concat(FROM_UNIXTIME(inv.TIMESTAMP/1000,'%Y-%m-%d %H'), ':00:00') AS reportDate, inv.INVERTERID, inv.PR
|
||||
// FROM " + _siteDB + ".s" + _siteID01 + @"_inv inv
|
||||
// WHERE left(DATE_FORMAT(FROM_UNIXTIME(inv.TIMESTAMP / 1000), '%Y-%m-%d %H:%i'), 10) = @date1
|
||||
// and right(DATE_FORMAT(FROM_UNIXTIME(inv.TIMESTAMP / 1000), '%Y-%m-%d %H:%i'), 2) = '55'
|
||||
// GROUP BY FROM_UNIXTIME(inv.TIMESTAMP/ 1000, '%Y-%m-%d %H'), inv.INVERTERID
|
||||
// ) inv_pr
|
||||
// ON a.reportDate = inv_pr.reportDate AND a.INVERTERID = inv_pr.INVERTERID
|
||||
// -- 取得逆變器容量
|
||||
// LEFT JOIN " + _siteDB + @".inverter i ON a.INVERTERID = i.InverterId
|
||||
// -- 取日照度 ---------------------
|
||||
// left join (
|
||||
// select concat(DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d %H'), ':00:00') AS reportDate, Irradiance
|
||||
// from sensor_history_hour a
|
||||
// where powerstationID = @powerstationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1
|
||||
// )irr on a.reportDate = irr.reportDate
|
||||
// order by a.INVERTERID, a.reportDate;";
|
||||
//int ct = conn.Execute(sql, new { date1 = _date1, PowerStationID = _powerStationID });
|
||||
{
|
||||
logger.Information("【ProcInvSvc】開始執行[{0}]在{1}逆變器hour補償", _siteID, _date1);
|
||||
|
||||
sql = @$"DROP TEMPORARY TABLE IF EXISTS Inv_day_" + _powerStationID + @"_s2;
|
||||
CREATE TEMPORARY TABLE Inv_day_" + _powerStationID + @"_s2
|
||||
@ -373,8 +283,7 @@ namespace solarApp.Service
|
||||
where powerstationID = " + _powerStationID + @" and DATE_FORMAT(`TIMESTAMP`, '%Y-%m-%d') = @date1
|
||||
)irr on a.reportDate = irr.reportDate
|
||||
where i.enabled = 1;";
|
||||
//int ct = conn.Execute(sql, new { date1 = _date1 });
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
//int ct = conn.Execute(sql, new { date1 = _date1 });
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandTimeout = 720;
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
@ -396,25 +305,22 @@ namespace solarApp.Service
|
||||
) inv_pr
|
||||
ON a.reportDate = inv_pr.reportDate AND a.INVERTERID = inv_pr.INVERTERID;";
|
||||
//ct = conn.Execute(sql, new { date1 = _date1 });
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
logger.Information("【ProcInvSvc】執行完成[{0}]在{1}逆變器hour補償", _siteID, _date1);
|
||||
|
||||
sql = @$"DROP TABLE IF EXISTS del_Inv_day_" + _powerStationID + @"_s1; ";
|
||||
//conn.Execute(ss);
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
if (_logger != null)
|
||||
_logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器hour補償", _siteID, _date1);
|
||||
|
||||
sql = @$"DROP TABLE IF EXISTS del_Inv_day_" + _powerStationID + @"_s1; ";
|
||||
//conn.Execute(ss);
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器hour補償", _siteID, _date1);
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器hour補償 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
throw ex;
|
||||
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器hour補償", _siteID, _date1);
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器hour補償 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
// arclog.insert_log(_powerStationID, "inverter_history_hour step1 " + _date1, 0, "inverter_history_hour", "insert inverter_history_hour error", "0", "", "", conn, cmd);
|
||||
// throw ex;
|
||||
}
|
||||
|
||||
#endregion hour
|
||||
@ -422,10 +328,8 @@ namespace solarApp.Service
|
||||
#region day
|
||||
try
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcInvSvc】開始執行[{0}]在{1}逆變器day補償", _siteID, _date1);
|
||||
}
|
||||
|
||||
logger.Information("【ProcInvSvc】開始執行[{0}]在{1}逆變器day補償", _siteID, _date1);
|
||||
|
||||
sql = @"
|
||||
INSERT INTO solar_master.inverter_history_day(PowerStationId, INVERTERID, TIMESTAMP, Irradiance, IrrDay, AC1V, AC1A, AC1W, AC1F, AC1WH, AC2V, AC2A, AC2W, AC2F, AC2WH,
|
||||
@ -459,8 +363,7 @@ namespace solarApp.Service
|
||||
where powerstationID = @powerstationID and DATE_FORMAT(a.TIMESTAMP, '%Y-%m-%d') = @date1 and Irradiance <> 0 limit 1
|
||||
)irr on a.reportDate = irr.reportDate
|
||||
where i.enabled = 1;";
|
||||
// conn.Execute(sql, new { date1 = _date1, PowerStationID = _powerStationID });
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
// conn.Execute(sql, new { date1 = _date1, PowerStationID = _powerStationID });
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandTimeout = 360;
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
@ -469,26 +372,24 @@ namespace solarApp.Service
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
cmd.Dispose();
|
||||
|
||||
if (_logger != null)
|
||||
_logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器day補償", _siteID, _date1);
|
||||
|
||||
logger.Information("【ProcInvSvc】執行完成[{0}]在{1}逆變器day補償", _siteID, _date1);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器day補償", _siteID, _date1);
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器day補償 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器day補償", _siteID, _date1);
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器day補償 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
//throw ex;
|
||||
//arclog.insert_log(_powerStationID, "inverter_history_day step1 ", 0, "inverter_history_day", "insert inverter_history_day error", "0", "", ex.Message, conn, cmd);
|
||||
}
|
||||
#endregion day
|
||||
|
||||
#region month
|
||||
try
|
||||
{
|
||||
if (_logger != null)
|
||||
_logger.LogInformation("【ProcInvSvc】開始執行[{0}]在{1}逆變器month補償", _siteID, _date1);
|
||||
|
||||
logger.Information("【ProcInvSvc】開始執行[{0}]在{1}逆變器month補償", _siteID, _date1);
|
||||
|
||||
sql = @"
|
||||
delete from inverter_history_month where powerstationID = @powerStationID and left(`TIMESTAMP`, 7) = left(@date1, 7) ;
|
||||
@ -524,8 +425,7 @@ namespace solarApp.Service
|
||||
where powerstationID = @powerstationID and DATE_FORMAT(a.TIMESTAMP, '%Y-%m') = @date1 and Irradiance <> 0
|
||||
)irr on a.reportDate = irr.reportDate
|
||||
where i.enabled = 1;";
|
||||
//conn.Execute(sql, new { date1 = _date1.Substring(0, 7), PowerStationID = _powerStationID });
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
//conn.Execute(sql, new { date1 = _date1.Substring(0, 7), PowerStationID = _powerStationID });
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandTimeout = 360;
|
||||
cmd.Parameters.AddWithValue("@date1", _date1.Substring(0, 7));
|
||||
@ -534,20 +434,17 @@ namespace solarApp.Service
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器month補償", _siteID, _date1);
|
||||
}
|
||||
|
||||
logger.Information("【ProcInvSvc】執行完成[{0}]在{1}逆變器month補償", _siteID, _date1);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器month補償", _siteID, _date1);
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器month補償 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器month補償", _siteID, _date1);
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器month補償 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
// arclog.insert_log(_powerStationID, "inverter_history_month step1 ", 0, "inverter_history_month", "insert inverter_history_month error", "0", "", ex.Message, conn, cmd);
|
||||
// throw ex;
|
||||
}
|
||||
|
||||
#endregion month
|
||||
|
||||
@ -583,46 +480,44 @@ namespace solarApp.Service
|
||||
arclog.insert_log(_powerStationID, "report_day step > 開始執行", (DateTime.Now - dt_start).TotalSeconds, "inverter_history_hour", "temp_invDay", "0", "", "日報 開始執行", conn, cmd);
|
||||
string sql = @$"delete from report_invday where powerstationid = {_powerStationID} and left(report_date, 10) = '{_date1}'";
|
||||
conn.Execute(sql);
|
||||
arclog.insert_log(_powerStationID, "report_day step > 刪除 report_invday", (DateTime.Now - dt_start).TotalSeconds, "inverter_history_hour", "temp_invDay", "0", "", "日報 刪除 report_invday", conn, cmd);
|
||||
arclog.insert_log(_powerStationID, "report_day step > 刪除 report_invday", (DateTime.Now - dt_start).TotalSeconds, "inverter_history_hour", "temp_invDay", "1", "", "日報 刪除 report_invday", conn, cmd);
|
||||
|
||||
#region get SQL
|
||||
//try
|
||||
//{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【Proc_inv_日報 】開始執行[{0}]在{1}inv_get_SQLStatement", _siteID, _date1);
|
||||
}
|
||||
arclog.insert_log(_powerStationID, "report_day step > table 開始建立", (DateTime.Now - dt_start).TotalSeconds, "inverter_history_hour", "temp_invDay", "0", "", "日報 開始建立table", conn, cmd);
|
||||
#region 建立 temp table
|
||||
sql = @$"DROP TABLE IF EXISTS temp_invDay{_powerStationID}_s1;
|
||||
CREATE TABLE temp_invDay{_powerStationID}_s1
|
||||
select a.`TIMESTAMP` report_date, a.powerstationId, a.INVERTERID, a.kwh ,
|
||||
round(TODAYKWH, 6) TODAYKWH, round(KWHKWP, 6) KWHKWP, round(PR, 6) PR
|
||||
from solar_master.inverter_history_hour a
|
||||
WHERE powerstationid = {_powerStationID} and crdDate = '{_date1}';
|
||||
# 2. add index
|
||||
ALTER TABLE `temp_invDay{_powerStationID}_s1` ADD INDEX `temp_indexs1` (report_date, inverterid);";
|
||||
|
||||
logger.Information("【Proc_inv_日報 】開始執行[{0}]在{1}inv_get_SQLStatement", _siteID, _date1);
|
||||
arclog.insert_log(_powerStationID, "report_day step > table 開始建立", (DateTime.Now - dt_start).TotalSeconds, "inverter_history_hour", "temp_invDay", "0", "", "日報 開始建立table", conn, cmd);
|
||||
#region 建立 temp table
|
||||
sql = @$"DROP TABLE IF EXISTS temp_invDay{_powerStationID}_s1;
|
||||
CREATE TABLE temp_invDay{_powerStationID}_s1
|
||||
select a.`TIMESTAMP` report_date, a.powerstationId, a.INVERTERID, a.kwh ,
|
||||
round(TODAYKWH, 6) TODAYKWH, round(KWHKWP, 6) KWHKWP, round(PR, 6) PR
|
||||
from solar_master.inverter_history_hour a
|
||||
WHERE powerstationid = {_powerStationID} and crdDate = '{_date1}';
|
||||
# 2. add index
|
||||
ALTER TABLE `temp_invDay{_powerStationID}_s1` ADD INDEX `temp_indexs1` (report_date, inverterid);";
|
||||
//conn.Execute(ss);
|
||||
|
||||
arclog.insert_log(_powerStationID, "report_day step > table 建立完成", (DateTime.Now - dt_start).TotalSeconds, "inverter_history_hour", "temp_invDay", "0", "", "日報 建立table完成", conn, cmd);
|
||||
arclog.insert_log(_powerStationID, "report_day step > table 建立完成 " + _date1, (DateTime.Now - dt_start).TotalSeconds, "inverter_history_hour", "temp_invDay", "1", "", "日報 建立table完成", conn, cmd);
|
||||
|
||||
try
|
||||
{
|
||||
arclog.insert_log(_powerStationID, "report_day step try", (DateTime.Now - dt_start).TotalSeconds, "inverter_history_hour", "temp_invDay", "0", "", "start 日報 try", conn, cmd);
|
||||
cmd.CommandText = sql;
|
||||
arclog.insert_log(_powerStationID, "report_day step try", (DateTime.Now - dt_start).TotalSeconds, "inverter_history_hour", "temp_invDay", "1", "", "start 日報 try", conn, cmd);
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
cmd.CommandText = @$"select count(*) ct from temp_invDay{_powerStationID}_s1";
|
||||
var rowCT = cmd.ExecuteScalar();
|
||||
//select LAST_INSERT_ID()
|
||||
TimeSpan duration = DateTime.Now - dt_start;
|
||||
arclog.insert_log(_powerStationID, "report_day step1", duration.TotalSeconds, "inverter_history_hour", "temp_invDay", "0", "", rowCT.ToString(), conn, cmd);
|
||||
arclog.insert_log(_powerStationID, "report_day step1 " + _date1, duration.TotalSeconds, "inverter_history_hour", "temp_invDay", "1", "", rowCT.ToString(), conn, cmd);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TimeSpan duration = DateTime.Now - dt_start;
|
||||
arclog.insert_log(_powerStationID, "report_day step1", duration.TotalSeconds, "inverter_history_hour", "temp_invDay", "1", "", ex.Message, conn, cmd);
|
||||
arclog.insert_log(_powerStationID, "report_day step1", duration.TotalSeconds, "inverter_history_hour", "temp_invDay", "0", "", ex.Message, conn, cmd);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -661,12 +556,12 @@ from temp_invDay{_powerStationID}_s1 a join
|
||||
//cmd.CommandText = @$"select count(*) ct from report_invday where powerStationID = {_powerStationID} and left(`TIMESTAMP`,10) = '{_date1}'";
|
||||
//var rowCT = cmd.ExecuteScalar();
|
||||
TimeSpan duration = DateTime.Now - dt_start2 ;
|
||||
arclog.insert_log(_powerStationID, "report_day step2 inv_no01", duration.TotalSeconds, "inverter_history_hour", "report_invday", "0", "", rowCT.ToString(), conn, cmd);
|
||||
arclog.insert_log(_powerStationID, "report_day step2 inv_no01", duration.TotalSeconds, "inverter_history_hour", "report_invday", "1", "", rowCT.ToString(), conn, cmd);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TimeSpan duration = DateTime.Now - dt_start2 ;
|
||||
arclog.insert_log(_powerStationID, "report_day step2 inv_no01", duration.TotalSeconds, "inverter_history_hour", "report_invday", "1", "", ex.Message, conn, cmd);
|
||||
arclog.insert_log(_powerStationID, "report_day step2 inv_no01", duration.TotalSeconds, "inverter_history_hour", "report_invday", "0", "", ex.Message, conn, cmd);
|
||||
}
|
||||
|
||||
// conn.Execute(sql);
|
||||
@ -740,25 +635,21 @@ set a.inv_02 = b.inv_02 ");
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
|
||||
if (_logger != null)
|
||||
_logger.LogInformation("【Proc_inv_日報 table 】執行完成[{0}]在{1} inv_get_SQLStatement", _siteID, _date1);
|
||||
|
||||
logger.Information("【Proc_inv_日報 table 】執行完成[{0}]在{1} inv_get_SQLStatement", _siteID, _date1);
|
||||
|
||||
TimeSpan duration = DateTime.Now - dt_start3;
|
||||
arclog.insert_log(_powerStationID, "report_day step3 update inv02", duration.TotalSeconds, "inverter_history_hour", "report_invday", "0", "", rowCT.ToString(), conn, cmd);
|
||||
arclog.insert_log(_powerStationID, "report_day step3 update inv02", duration.TotalSeconds, "inverter_history_hour", "report_invday", "1", "", rowCT.ToString(), conn, cmd);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TimeSpan duration = DateTime.Now - dt_start3 ;
|
||||
arclog.insert_log(_powerStationID, "report_day step3 update inv02", duration.TotalSeconds, "inverter_history_hour", "report_invday", "1", "", ex.Message, conn, cmd);
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogError("【Proc_inv_日報 table】執行失敗[{0}]在{1}inv_get_SQLStatement", _siteID, _date1);
|
||||
_logger.LogError("【Proc_inv_日報 table】執行失敗[{0}]在{1}inv_get_SQLStatement - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
arclog.insert_log(_powerStationID, "report_day step3 update inv02", duration.TotalSeconds, "inverter_history_hour", "report_invday", "0", "", ex.Message, conn, cmd);
|
||||
|
||||
logger.Error("【Proc_inv_日報 table】執行失敗[{0}]在{1}inv_get_SQLStatement", _siteID, _date1);
|
||||
logger.Error("【Proc_inv_日報 table】執行失敗[{0}]在{1}inv_get_SQLStatement - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -6,6 +6,11 @@ using Dapper;
|
||||
using solarApp.Model;
|
||||
using System.Configuration;
|
||||
using System.Threading.Tasks;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using MySqlX.XDevAPI.Relational;
|
||||
using static solarApp.Model.weather_model;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace solarApp.Service
|
||||
{
|
||||
@ -13,6 +18,8 @@ namespace solarApp.Service
|
||||
{
|
||||
string Connection1 = string.Empty;
|
||||
|
||||
private ILogger logger = Log.ForContext<procSensorSvc>();
|
||||
|
||||
public procSensorSvc(string Connection_parame = null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Connection_parame))
|
||||
@ -133,12 +140,14 @@ namespace solarApp.Service
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
conn.Close();
|
||||
logger.Information("sensor_history clearData OK");
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
{
|
||||
//throw ex;
|
||||
logger.Error("sensor_history error: " + ex.Message);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -207,6 +216,9 @@ namespace solarApp.Service
|
||||
sql = @"SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY,',''));";
|
||||
conn.Execute(sql);
|
||||
|
||||
//全域使用
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
|
||||
#region 獲取 Sensor 類別
|
||||
//沒有被刪除、啟用中、狀態正常的 才可列入計算
|
||||
//sql = @"select a.id, CONCAT( left(UID, 9) ,'01') SiteID, a.`name` sensorName, type, DBName, TableName, colname
|
||||
@ -266,7 +278,22 @@ namespace solarApp.Service
|
||||
foreach (var item in ds_sensor)
|
||||
{
|
||||
tableName = item.TableName;
|
||||
break;
|
||||
sql = @"select count(*) ct from " + _siteDB + "." + tableName + @"
|
||||
where FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') = @date1 ";
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandTimeout = 720;
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
cmd.CommandText = sql;
|
||||
string CT = cmd.ExecuteScalar().ToString();
|
||||
cmd.Parameters.Clear();
|
||||
if (!string.IsNullOrEmpty(CT))
|
||||
{
|
||||
if (int.Parse(CT) >0)
|
||||
{
|
||||
tableName = item.TableName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sql = @"insert into sensor_history_hour( `PowerStationId`, `TIMESTAMP`, Irradiance, Temperature, EnvTemperature, Humidity, Vane, Dust, WingDirection, irrDay, irrDayHour)
|
||||
@ -288,7 +315,8 @@ namespace solarApp.Service
|
||||
//cmd.Parameters()
|
||||
//cmd.ExecuteNonQuery();
|
||||
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
DateTime dt_start2 = DateTime.Now;
|
||||
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandTimeout = 720;
|
||||
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||
@ -296,9 +324,9 @@ namespace solarApp.Service
|
||||
cmd.CommandText = sql;
|
||||
int rowCT = cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
DateTime dt_start2 = DateTime.Now;
|
||||
TimeSpan duration = DateTime.Now - dt_start2;
|
||||
arclog.insert_log(_powerStationID, "sensor step1", duration.TotalSeconds, "sensor_history_hour", "insert sensor hour", "0", "", rowCT.ToString(), conn, cmd);
|
||||
logger.Information($@"sensor step1 insert sensor_history_hour OK duration={duration.TotalSeconds} ");
|
||||
arclog.insert_log(_powerStationID, "sensor step1", duration.TotalSeconds, "sensor_history_hour", "insert sensor hour", "1", "", rowCT.ToString(), conn, cmd);
|
||||
|
||||
// irrDayHour計算
|
||||
//sql = $@"update sensor_history_hour a join (
|
||||
@ -374,11 +402,17 @@ namespace solarApp.Service
|
||||
group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d')
|
||||
)b on a.reportdate = b.reportdate";
|
||||
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||
dt_start2 = DateTime.Now;
|
||||
|
||||
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
duration = DateTime.Now - dt_start2;
|
||||
arclog.insert_log(_powerStationID, "sensor step1", duration.TotalSeconds, "sensor_history_day", "insert sensor_day", "1", "", rowCT.ToString(), conn, cmd);
|
||||
|
||||
logger.Information($@"sensor step1 insert sensor day OK duration={duration.TotalSeconds} ");
|
||||
#endregion day
|
||||
|
||||
#region month 如果跨月 會有2筆資料
|
||||
@ -430,9 +464,14 @@ namespace solarApp.Service
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
arclog.insert_log(_powerStationID, "sensor step1", duration.TotalSeconds, "sensor_history_hour", "insert sensor_hour", "1", "", rowCT.ToString(), conn, cmd);
|
||||
|
||||
logger.Information($@"sensor step1 insert sensoravg_history_hour OK duration={duration.TotalSeconds} ");
|
||||
|
||||
//日照計 update
|
||||
sql = string.Empty;
|
||||
dt_start2 = DateTime.Now;
|
||||
|
||||
foreach (var item in irrlst)
|
||||
{
|
||||
sql += @" update sensoravg_history_hour a join
|
||||
@ -451,6 +490,9 @@ namespace solarApp.Service
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
|
||||
duration = DateTime.Now - dt_start2;
|
||||
logger.Information($@"sensor step1 update sensoravg_history_hour irrAvg OK duration={duration.TotalSeconds} ");
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -470,11 +512,17 @@ namespace solarApp.Service
|
||||
where powerStationID = @powerStationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1
|
||||
group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d');";
|
||||
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||
// dt_start2 = DateTime.Now;
|
||||
// duration = DateTime.Now - dt_start2;
|
||||
dt_start2 = DateTime.Now;
|
||||
|
||||
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
cmd.Parameters.Clear();
|
||||
duration = DateTime.Now - dt_start2;
|
||||
logger.Information($@"sensor step1 INSERT sensoravg_history_day OK duration={duration.TotalSeconds} ");
|
||||
|
||||
//日照計 update
|
||||
sql = string.Empty;
|
||||
@ -548,13 +596,16 @@ namespace solarApp.Service
|
||||
}
|
||||
#endregion
|
||||
|
||||
conn.Close();
|
||||
|
||||
result = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
arclog.insert_log(_powerStationID, "sensor step1 ", 0, "sensor_history_", "insert sensor error", "err", "", ex.Message, conn, cmd);
|
||||
|
||||
//throw ex;
|
||||
}
|
||||
conn.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -570,13 +621,14 @@ namespace solarApp.Service
|
||||
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
||||
{
|
||||
conn.Open();
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
string sql;
|
||||
//電表
|
||||
DateTime dt_start = DateTime.Now;
|
||||
try
|
||||
{
|
||||
#region hour
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandTimeout = 720;
|
||||
|
||||
@ -609,15 +661,16 @@ namespace solarApp.Service
|
||||
cmd.Parameters.Clear();
|
||||
duration = DateTime.Now - dt_start2;
|
||||
arclog.insert_log(_powerStationID, "sensor step1 for irrDayHour", duration.TotalSeconds, "sensor_history_hour", "update sensor hour", "0", "", rowCT2.ToString(), conn, cmd);
|
||||
#endregion hour
|
||||
|
||||
conn.Close();
|
||||
#endregion hour
|
||||
|
||||
result = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
arclog.insert_log(_powerStationID, "sensor step1 irrDayHour", 0, "sensor_history_", "sensor_history_hour error", "err", "", ex.Message, conn, cmd);
|
||||
//throw ex;
|
||||
}
|
||||
conn.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -644,6 +697,7 @@ namespace solarApp.Service
|
||||
|
||||
bool insert_meter() {
|
||||
bool result = false;
|
||||
procArchiveLog arclog = new procArchiveLog();
|
||||
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
||||
{
|
||||
conn.Open();
|
||||
@ -700,7 +754,8 @@ namespace solarApp.Service
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
//throw ex;
|
||||
arclog.insert_log(_powerStationID, "sensor step1 meter_hour", 0, "meter_history_hour", "meter_history_hour error", "err", "", ex.Message, conn, null);
|
||||
}
|
||||
conn.Close();
|
||||
}
|
||||
@ -714,36 +769,41 @@ namespace solarApp.Service
|
||||
bool update_invdayhour()
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
procArchiveLog arclog = new procArchiveLog();
|
||||
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
procArchiveLog arclog = new procArchiveLog();
|
||||
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
||||
conn.Open();
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
try
|
||||
{
|
||||
conn.Open();
|
||||
string sql = $@"update sensor_history_hour a join
|
||||
(
|
||||
select powerstationID, `TIMESTAMP`, irrday -
|
||||
(select irrday from sensor_history_hour where powerstationID = {_powerStationID} and LEFT(`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(_date1).AddHours(-1).ToString("yyyy-MM-dd HH")}' limit 1) irrdayhour
|
||||
from sensor_history_hour z
|
||||
where powerstationID = {_powerStationID} and LEFT(z.`TIMESTAMP`, 13 ) = '{(Convert.ToDateTime(_date1)).ToString("yyyy-MM-dd HH")}'
|
||||
) b on a.powerstationID = b.powerstationID and a.`TIMESTAMP` = b.`TIMESTAMP`
|
||||
Set a.irrdayhour = case when b.irrdayhour < 0 then 0 else b.irrdayhour end
|
||||
where a.powerstationID = {_powerStationID}";
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandTimeout = 720;
|
||||
DateTime dt_start2 = DateTime.Now;
|
||||
cmd.CommandText = sql;
|
||||
int rowCT2 = cmd.ExecuteNonQuery();
|
||||
dt_start2 = DateTime.Now;
|
||||
TimeSpan duration = DateTime.Now - dt_start2;
|
||||
arclog.insert_log(_powerStationID, "sensor step1 for irrDayHour", duration.TotalSeconds, "sensor_history_hour", "update sensor hour", "0", "", rowCT2.ToString(), conn, cmd);
|
||||
|
||||
|
||||
string sql = $@"update sensor_history_hour a join
|
||||
(
|
||||
select powerstationID, `TIMESTAMP`, irrday -
|
||||
(select irrday from sensor_history_hour where powerstationID = {_powerStationID} and LEFT(`TIMESTAMP`, 13 ) = '{Convert.ToDateTime(_date1).AddHours(-1).ToString("yyyy-MM-dd HH")}' limit 1) irrdayhour
|
||||
from sensor_history_hour z
|
||||
where powerstationID = {_powerStationID} and LEFT(z.`TIMESTAMP`, 13 ) = '{(Convert.ToDateTime(_date1)).ToString("yyyy-MM-dd HH")}'
|
||||
) b on a.powerstationID = b.powerstationID and a.`TIMESTAMP` = b.`TIMESTAMP`
|
||||
Set a.irrdayhour = case when b.irrdayhour < 0 then 0 else b.irrdayhour end
|
||||
where a.powerstationID = {_powerStationID}";
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandTimeout = 720;
|
||||
DateTime dt_start2 = DateTime.Now;
|
||||
cmd.CommandText = sql;
|
||||
int rowCT2 = cmd.ExecuteNonQuery();
|
||||
dt_start2 = DateTime.Now;
|
||||
TimeSpan duration = DateTime.Now - dt_start2;
|
||||
arclog.insert_log(_powerStationID, "sensor step1 for irrDayHour", duration.TotalSeconds, "sensor_history_hour", "update sensor hour", "0", "", rowCT2.ToString(), conn, cmd);
|
||||
|
||||
result = true;
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
catch (Exception ex)
|
||||
{
|
||||
//throw ex;
|
||||
arclog.insert_log(_powerStationID, "sensor step1 meter_hour", 0, "meter_history_hour", "meter_history_hour error", "0", "", ex.Message, conn, null);
|
||||
}
|
||||
conn.Close();
|
||||
}
|
||||
return result;
|
||||
|
||||
@ -754,6 +814,9 @@ namespace solarApp.Service
|
||||
procArchiveLog arclog = new procArchiveLog();
|
||||
bool result = false;
|
||||
bool isFirst = true;
|
||||
int rowCT = 0;
|
||||
TimeSpan duration = DateTime.Now - DateTime.Now;
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
||||
{
|
||||
conn.Open();
|
||||
@ -843,16 +906,16 @@ namespace solarApp.Service
|
||||
//cmd.Parameters()
|
||||
//cmd.ExecuteNonQuery();
|
||||
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandTimeout = 720;
|
||||
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
cmd.CommandText = sql;
|
||||
int rowCT = cmd.ExecuteNonQuery();
|
||||
rowCT = cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
DateTime dt_start2 = DateTime.Now;
|
||||
TimeSpan duration = DateTime.Now - dt_start2;
|
||||
duration = DateTime.Now - dt_start2;
|
||||
arclog.insert_log(_powerStationID, "sensor step1", duration.TotalSeconds, "sensor_history_hour", "insert sensor hour", "0", "", rowCT.ToString(), conn, cmd);
|
||||
|
||||
// irrDayHour計算
|
||||
@ -888,10 +951,10 @@ namespace solarApp.Service
|
||||
and a.powerstationID = {_powerStationID} ";
|
||||
dt_start2 = DateTime.Now;
|
||||
cmd.CommandText = sql;
|
||||
int rowCT2 = cmd.ExecuteNonQuery();
|
||||
rowCT = cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
duration = DateTime.Now - dt_start2;
|
||||
arclog.insert_log(_powerStationID, "sensor step1 for irrDayHour", duration.TotalSeconds, "sensor_history_hour", "update sensor hour", "0", "", rowCT2.ToString(), conn, cmd);
|
||||
arclog.insert_log(_powerStationID, "sensor step1 for irrDayHour", duration.TotalSeconds, "sensor_history_hour", "update sensor hour", "0", "", rowCT.ToString(), conn, cmd);
|
||||
|
||||
|
||||
//sql = $@"update sensor_history_hour a join
|
||||
@ -1057,14 +1120,18 @@ namespace solarApp.Service
|
||||
|
||||
#endregion
|
||||
|
||||
conn.Close();
|
||||
|
||||
result = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
arclog.insert_log(_powerStationID, "sensor step1 for irrDayHour", duration.TotalSeconds, "sensor_history_hour", "update sensor hour", "0", "", ex.Message, conn, cmd);
|
||||
|
||||
//throw ex;
|
||||
}
|
||||
conn.Close();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ using MySql.Data.MySqlClient;
|
||||
using Dapper;
|
||||
using solarApp.Model;
|
||||
using System.Configuration;
|
||||
//using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
namespace solarApp.Service
|
||||
{
|
||||
@ -31,6 +32,7 @@ namespace solarApp.Service
|
||||
//public string _date2 { get; set; }
|
||||
public string _powerStationID { get; set; }
|
||||
|
||||
procArchiveLog arclog = new procArchiveLog();
|
||||
|
||||
public bool clearData()
|
||||
{
|
||||
@ -71,7 +73,8 @@ namespace solarApp.Service
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
arclog.insert_log(_powerStationID, "clearData procStation", 0, "sensor_history_hour", "update sensor hour", "0", "", ex.Message, null, null);
|
||||
// throw ex;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -365,7 +368,8 @@ namespace solarApp.Service
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
//throw ex;
|
||||
arclog.insert_log(_powerStationID, "insert_station ", 0, "insert_station", "insert_station", "0", "", ex.Message, null, null);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -388,8 +392,9 @@ namespace solarApp.Service
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
arclog.insert_log(_powerStationID, "update_powerStationPerHour ", 0, table_name, "update_powerStationPerHour", "0", "", ex.Message, null, null);
|
||||
|
||||
}
|
||||
//result = await conn.QueryFirstOrDefaultAsync<PowerStationHistory>(sql, new { DateTime = dateTime });
|
||||
|
||||
//string col = $@"select Id, kwh, Today_kwh, Total_kwh, today_kwhkwp, today_money, total_money, today_PR, today_carbon, total_carbon, today_irradiance, SolarHour";
|
||||
|
||||
28
solarApp/Service/testLog.cs
Normal file
28
solarApp/Service/testLog.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Serilog;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
|
||||
namespace solarApp.Service
|
||||
{
|
||||
internal class testLog
|
||||
{
|
||||
private ILogger logger = Log.ForContext<testLog>();
|
||||
//private ILogger logger;
|
||||
//public ILogger MyLoger
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// if (logger == null)
|
||||
// {
|
||||
// logger = Log.ForContext<testLog>();
|
||||
// }
|
||||
// return logger;
|
||||
// }
|
||||
//}
|
||||
public void procOne() {
|
||||
logger.Information("call procOne OK");
|
||||
}
|
||||
}
|
||||
}
|
||||
1146
solarApp/fmArchive.Designer.cs
generated
1146
solarApp/fmArchive.Designer.cs
generated
File diff suppressed because it is too large
Load Diff
@ -9,6 +9,8 @@ using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using solarApp.Service;
|
||||
using solarApp.Model;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
//using System.Text.RegularExpressions;
|
||||
|
||||
namespace solarApp
|
||||
@ -26,6 +28,9 @@ namespace solarApp
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private ILogger logger = Log.ForContext<fmArchive>();
|
||||
|
||||
|
||||
private void bt_inv_proc_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
@ -64,7 +69,7 @@ namespace solarApp
|
||||
|
||||
private void fmArchive_Load(object sender, EventArgs e)
|
||||
{
|
||||
// MessageBox.Show(" loading ");
|
||||
// MessageBox.Show(" loading ");
|
||||
#region 電站清單
|
||||
int i = 0;
|
||||
var site_list = stationSvc.get_station_list();
|
||||
@ -103,6 +108,7 @@ namespace solarApp
|
||||
f2.Dock = DockStyle.Fill;
|
||||
f2.Show();
|
||||
#endregion
|
||||
logger.Information("start winform process @" + System.DateTime.Now.ToString());
|
||||
}
|
||||
|
||||
private void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||
@ -194,7 +200,7 @@ namespace solarApp
|
||||
if (System.DateTime.Now.Day == 20 && System.DateTime.Now.Hour == 20 && DateTime.Now.Minute == 00
|
||||
&& (DateTime.Now.Second >= 0 && DateTime.Now.Second <= 20)
|
||||
&& autoTask == false)
|
||||
{
|
||||
{
|
||||
autoTask = true;
|
||||
bt_MoveRawData.PerformClick();
|
||||
autoTask = false;
|
||||
@ -202,16 +208,16 @@ namespace solarApp
|
||||
//var site_list = stationSvc.get_station_list();
|
||||
|
||||
//archiveLowData archiveData = new archiveLowData();
|
||||
|
||||
|
||||
//bt_MoveRawData_Click
|
||||
|
||||
|
||||
//foreach (var item in site_list)
|
||||
//{
|
||||
// archiveData.archiveData(item.SiteID.Substring(0, 9));
|
||||
|
||||
// i++;
|
||||
//}
|
||||
|
||||
|
||||
lbMsgTitle.Text = System.DateTime.Now.ToString() + " 水位管理 - 資料搬移完成!";
|
||||
}
|
||||
}
|
||||
@ -220,7 +226,7 @@ namespace solarApp
|
||||
{
|
||||
RadioButton rb = sender as RadioButton;
|
||||
if (rb.Checked)
|
||||
{
|
||||
{
|
||||
lbSiteName_sensor.Text = rb.Text;
|
||||
lbSiteDB_sensor.Text = rb.Tag.ToString();
|
||||
lbSiteID_sensor.Text = rb.Name;
|
||||
@ -338,23 +344,33 @@ namespace solarApp
|
||||
|
||||
private void bt_archive_Click(object sender, EventArgs e)
|
||||
{
|
||||
var site_list = stationSvc.get_station_list();
|
||||
|
||||
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd");
|
||||
string date2 = dtSelect2.Value.ToString("yyyy-MM-dd");
|
||||
var site_list = stationSvc.get_station_list32(false); // 不含 32
|
||||
//var site_list = stationSvc.get_station_list32(true); // 不含 32
|
||||
|
||||
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd");
|
||||
string date2 = dtSelect2.Value.ToString("yyyy-MM-dd");
|
||||
procSensorSvc sensorSvc = new procSensorSvc();
|
||||
procInvSvc invSvc = new procInvSvc();
|
||||
procStationSvc siteSvc = new procStationSvc();
|
||||
|
||||
procStationSvc siteSvc = new procStationSvc();
|
||||
archiveRawData(site_list, date1, date2, sensorSvc, invSvc, siteSvc);
|
||||
|
||||
//單獨製作 32
|
||||
site_list = stationSvc.get_station_list32(true); // 不含 32
|
||||
archiveRawData(site_list, date1, date2, sensorSvc, invSvc, siteSvc);
|
||||
|
||||
lbMsgTitle.Text = System.DateTime.Now.ToString() + " 完成!";
|
||||
}
|
||||
|
||||
private void archiveRawData(List<station_list> site_list, string date1, string date2, procSensorSvc sensorSvc, procInvSvc invSvc, procStationSvc siteSvc)
|
||||
{
|
||||
foreach (var item in site_list)
|
||||
{
|
||||
//RadioButton rb = new RadioButton();
|
||||
//rb.Name = item.SiteID;
|
||||
//rb.Text = item.SiteName;
|
||||
//rb.Tag = item.SiteDB;
|
||||
RadioButton rb = new RadioButton();
|
||||
rb.Name = item.SiteID;
|
||||
rb.Text = item.SiteName;
|
||||
rb.Tag = item.SiteDB;
|
||||
foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2)))
|
||||
{
|
||||
{
|
||||
sensorSvc.archiveData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
|
||||
invSvc.archiveData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
|
||||
siteSvc.archiveData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
|
||||
@ -371,8 +387,6 @@ namespace solarApp
|
||||
invSvc.report_invDay(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
|
||||
}
|
||||
}
|
||||
|
||||
lbMsgTitle.Text = System.DateTime.Now.ToString() + " 完成!";
|
||||
}
|
||||
|
||||
private void bt_clear_sensor_Click(object sender, EventArgs e)
|
||||
@ -416,11 +430,11 @@ namespace solarApp
|
||||
private void bt_rpt_invDay_Click(object sender, EventArgs e)
|
||||
{
|
||||
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd");
|
||||
string date2 = dtSelect2.Value.ToString("yyyy-MM-dd");
|
||||
string date2 = dtSelect2.Value.ToString("yyyy-MM-dd");
|
||||
procInvSvc invSvc = new procInvSvc();
|
||||
|
||||
|
||||
foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2)))
|
||||
{
|
||||
{
|
||||
invSvc.report_invDay(lbSiteID_sensor.Text.Substring(0, 9), day.ToString("yyyy-MM-dd"));
|
||||
}
|
||||
|
||||
@ -433,9 +447,9 @@ namespace solarApp
|
||||
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd");
|
||||
string date2 = dtSelect2.Value.ToString("yyyy-MM-dd");
|
||||
get_inv_svc invSvc = new get_inv_svc();
|
||||
var ds = invSvc.get_ck_invDay_list(date1, date2);
|
||||
var ds = invSvc.get_ck_invDay_list(date1, date2);
|
||||
gv_rpt_invDay.DataSource = ds;
|
||||
gv_rpt_invDay.Columns[0].Width = 60;
|
||||
gv_rpt_invDay.Columns[0].Width = 60;
|
||||
gv_rpt_invDay.Columns[1].Width = 80;
|
||||
gv_rpt_invDay.Columns[2].Width = 100;
|
||||
gv_rpt_invDay.Columns[3].Width = 90;
|
||||
@ -474,16 +488,17 @@ namespace solarApp
|
||||
string date2 = dtSelect2.Value.ToString("yyyy-MM-dd");
|
||||
get_inv_svc invSvc = new get_inv_svc();
|
||||
if (e.ColumnIndex != 8)
|
||||
{
|
||||
{
|
||||
var ds = invSvc.get_ck_invDay_detail1(powerStationID, date1, date2);
|
||||
gv_inv_detail.DataSource = ds;
|
||||
gv_inv_detail.Columns[0].Width = 60;
|
||||
gv_inv_detail.Columns[1].Width = 160; //invID
|
||||
gv_inv_detail.Columns[2].Width = 80;
|
||||
gv_inv_detail.Columns[3].Width = 90;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{ // 日報
|
||||
var ds = invSvc.get_reportDay(powerStationID, date1, date2);
|
||||
var ds = invSvc.get_reportDay(powerStationID, date1, date2);
|
||||
gv_inv_detail.DataSource = ds;
|
||||
gv_inv_detail.Columns[0].Width = 60;
|
||||
gv_inv_detail.Columns[1].Width = 80; //report_date
|
||||
@ -492,7 +507,7 @@ namespace solarApp
|
||||
gv_inv_detail.Columns[4].Width = 70;
|
||||
gv_inv_detail.Columns[5].Width = 70;
|
||||
gv_inv_detail.Columns[6].Width = 70;
|
||||
}
|
||||
}
|
||||
}
|
||||
//switch (e.ColumnIndex)
|
||||
//{
|
||||
@ -506,7 +521,7 @@ namespace solarApp
|
||||
|
||||
private void gv_inv_detail_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
if (gv_inv_detail.Columns.Count == 5 || e.RowIndex == -1) return;
|
||||
if (gv_inv_detail.Columns.Count == 5 || e.RowIndex == -1) return;
|
||||
|
||||
string inverterID = gv_inv_detail.Rows[e.RowIndex].Cells[1].Value.ToString();
|
||||
//MessageBox.Show(inverterID);
|
||||
@ -522,7 +537,7 @@ namespace solarApp
|
||||
gv_inv_detail.Columns[3].Width = 100;
|
||||
gv_inv_detail.Columns[4].Width = 80;
|
||||
gv_inv_detail.Columns[5].Width = 80;
|
||||
}
|
||||
}
|
||||
|
||||
private void bt_sensor_lackData_Click(object sender, EventArgs e)
|
||||
{
|
||||
@ -577,7 +592,7 @@ namespace solarApp
|
||||
getStationSvc GetStation = new getStationSvc();
|
||||
var ds = GetStation.get_lack_stationData(dtSelect1.Value.ToString("yyyy-MM-dd"));
|
||||
|
||||
procInvSvc invSvc = new procInvSvc();
|
||||
procInvSvc invSvc = new procInvSvc();
|
||||
//foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2)))
|
||||
foreach (var item in ds)
|
||||
{
|
||||
@ -589,7 +604,11 @@ namespace solarApp
|
||||
lbMsgTitle.Text = DateTime.Now.ToString() + " lackStation OK";
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// bt_archive 每日歸檔
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void bt_archive_One_Click(object sender, EventArgs e)
|
||||
{
|
||||
int i = 0;
|
||||
@ -636,7 +655,7 @@ namespace solarApp
|
||||
if (result.CompareTo("成功") == 0)
|
||||
{
|
||||
MessageBox.Show("【SendEmailJob】 寄送成功! ");
|
||||
}
|
||||
}
|
||||
}
|
||||
private string Send(List<string> recipientEmails, string subject, string content, List<string> attachments)
|
||||
{
|
||||
@ -674,7 +693,7 @@ namespace solarApp
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//讀取 SMTP Config
|
||||
if (CanDoSend)
|
||||
{
|
||||
@ -717,7 +736,7 @@ namespace solarApp
|
||||
catch (Exception ex)
|
||||
{
|
||||
string json = System.Text.Json.JsonSerializer.Serialize(recipientEmails);
|
||||
|
||||
|
||||
//MessageBox.Show("【SendEmailJob】 " + "寄送信件失敗" + json + " Exception:" + ex.Message);
|
||||
|
||||
return "失敗 - " + ex.Message;
|
||||
@ -726,7 +745,7 @@ namespace solarApp
|
||||
else
|
||||
{
|
||||
return reason;
|
||||
}
|
||||
}
|
||||
}
|
||||
public class SMTPConfig
|
||||
{
|
||||
@ -757,15 +776,16 @@ namespace solarApp
|
||||
if (result.CompareTo("成功") == 0)
|
||||
{
|
||||
// MessageBox.Show("【SendEmailJob】 寄送成功! ");
|
||||
richTextBox1.AppendText(Environment.NewLine + System.DateTime.Now.ToString() + " " + result.ToString());
|
||||
richTextBox1.AppendText(Environment.NewLine + System.DateTime.Now.ToString() + " " + result.ToString());
|
||||
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
richTextBox1.AppendText(Environment.NewLine + System.DateTime.Now.ToShortTimeString() + " " + result.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void button2_Click(object sender, EventArgs e)
|
||||
{
|
||||
// string date1 = dtSelect1.Value.ToString("yyyy-MM-dd") + " "+System.DateTime.Now.AddHours(-2) + ":00:00";
|
||||
@ -774,9 +794,9 @@ namespace solarApp
|
||||
{
|
||||
date1 = dtSelect1.Value.ToString("yyyy-MM-dd ") + textBox1.Text + ":00:00";
|
||||
}
|
||||
|
||||
|
||||
var site_list = stationSvc.get_station_list();
|
||||
|
||||
|
||||
procSensorSvc procSensor = new procSensorSvc();
|
||||
foreach (var item in site_list)
|
||||
{
|
||||
@ -836,6 +856,45 @@ namespace solarApp
|
||||
lbMsgTitle.Text = System.DateTime.Now.ToString() + " 水位管理 - 資料搬移完成!";
|
||||
}
|
||||
|
||||
private void bt_procStep2_Click(object sender, EventArgs e)
|
||||
{
|
||||
var site_list = stationSvc.get_station_list32(false); // 不含 32
|
||||
//var site_list = stationSvc.get_station_list32(true); // 不含 32
|
||||
|
||||
string date1 = dtSelect1.Value.ToString("yyyy-MM-dd");
|
||||
string date2 = dtSelect2.Value.ToString("yyyy-MM-dd");
|
||||
procSensorSvc sensorSvc = new procSensorSvc();
|
||||
procInvSvc invSvc = new procInvSvc();
|
||||
procStationSvc siteSvc = new procStationSvc();
|
||||
sensorSvc.isFirst = true;
|
||||
foreach (var item in site_list)
|
||||
{
|
||||
//for sensor_history_hour
|
||||
foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2)))
|
||||
{
|
||||
sensorSvc.archiveSensorHistoryHourData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
|
||||
sensorSvc.isFirst = false;
|
||||
invSvc.report_invDay(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
|
||||
}
|
||||
}
|
||||
|
||||
//單獨製作 32
|
||||
site_list = stationSvc.get_station_list32(true); // 不含 32
|
||||
sensorSvc.isFirst = true;
|
||||
foreach (var item in site_list)
|
||||
{
|
||||
//for sensor_history_hour
|
||||
foreach (DateTime day in EachDay(DateTime.Parse(date1), DateTime.Parse(date2)))
|
||||
{
|
||||
sensorSvc.archiveSensorHistoryHourData(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
|
||||
sensorSvc.isFirst = false;
|
||||
invSvc.report_invDay(item.SiteID.Substring(0, 9), day.ToString("yyyy-MM-dd"));
|
||||
}
|
||||
}
|
||||
|
||||
lbMsgTitle.Text = System.DateTime.Now.ToString() + " 完成!";
|
||||
}
|
||||
|
||||
//test for email format
|
||||
//private void button3_Click(object sender, EventArgs e)
|
||||
//{
|
||||
|
||||
@ -1,4 +1,64 @@
|
||||
<root>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
|
||||
2393
solarApp/fmMain.Designer.cs
generated
2393
solarApp/fmMain.Designer.cs
generated
File diff suppressed because it is too large
Load Diff
@ -19,7 +19,7 @@ namespace solarApp
|
||||
public fmMain()
|
||||
{
|
||||
InitializeComponent();
|
||||
// init_GridView();
|
||||
// init_GridView();
|
||||
}
|
||||
|
||||
private async void button1_Click(object sender, EventArgs e)
|
||||
@ -38,15 +38,15 @@ namespace solarApp
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
|
||||
gv_web_inv_hour.DataSource = inv_svc.get_web_Inv_hour(date2, lbInverterID.Text);
|
||||
|
||||
gv_web_inv_day.DataSource = inv_svc.get_web_Inv_day(date1, date2, lbInverterID.Text);
|
||||
|
||||
gv_web_inv_month.DataSource = inv_svc.get_web_Inv_month( date1.Substring(0, 7), date2.Substring(0, 7), lbInverterID.Text);
|
||||
|
||||
gv_web_inv_month.DataSource = inv_svc.get_web_Inv_month(date1.Substring(0, 7), date2.Substring(0, 7), lbInverterID.Text);
|
||||
|
||||
lbMsg_inv.Text = " done " + System.DateTime.Now.ToShortTimeString();
|
||||
}
|
||||
|
||||
@ -57,12 +57,12 @@ namespace solarApp
|
||||
//string date2 = dtSelect_sensor2.Value.ToString("yyyy-MM-dd");
|
||||
string date1 = dtselect_inv.Value.AddDays(-7).ToString("yyyy-MM-dd");
|
||||
|
||||
gv_web_inv_hour.DataSource = inv_svc.get_web_Inv_15min(date2, lbInverterID.Text , lbSiteID_inv.Text.Substring(0, 9));
|
||||
gv_web_inv_hour.DataSource = inv_svc.get_web_Inv_15min(date2, lbInverterID.Text, lbSiteID_inv.Text.Substring(0, 9));
|
||||
}
|
||||
|
||||
private void fmMain_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
|
||||
|
||||
dtselect_station1.Value = DateTime.Today.AddDays(-1);
|
||||
|
||||
@ -92,7 +92,7 @@ namespace solarApp
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region 顯示逆變器list
|
||||
//add_inv_list();
|
||||
#endregion
|
||||
@ -112,12 +112,12 @@ namespace solarApp
|
||||
lbSiteID_sensor.Text = lbSiteID_inv.Text;
|
||||
|
||||
//顯示 table name on label
|
||||
lbSiteRaw.Text = lbSiteName_inv.Text + " "+ lbSiteDB_inv.Text + ".s" + lbSiteID_inv.Text + "_Station";
|
||||
lbSiteRaw.Text = lbSiteName_inv.Text + " " + lbSiteDB_inv.Text + ".s" + lbSiteID_inv.Text + "_Station";
|
||||
lbInvRaw.Text = lbSiteName_inv.Text + " " + lbSiteDB_inv.Text + ".s" + lbSiteID_inv.Text + "_Inv";
|
||||
lbSensorRaw.Text = lbSiteName_inv.Text + " " + lbSiteDB_inv.Text + ".s" + lbSiteID_inv.Text + "_SensorAVG";
|
||||
|
||||
add_inv_list(lbSiteDB_inv.Text, lbSiteID_inv.Text.Substring(0, 9));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -125,9 +125,10 @@ namespace solarApp
|
||||
/// </summary>
|
||||
/// <param name="siteDB"></param>
|
||||
/// <param name="siteID"></param>
|
||||
void add_inv_list(string siteDB, string siteID) {
|
||||
void add_inv_list(string siteDB, string siteID)
|
||||
{
|
||||
fp_inv.Controls.Clear();
|
||||
var inv_list = inv_svc.get_Inv_list(siteDB, siteID);
|
||||
var inv_list = inv_svc.get_Inv_list(siteDB, siteID);
|
||||
int i = 0;
|
||||
foreach (var item in inv_list)
|
||||
{
|
||||
@ -147,8 +148,8 @@ namespace solarApp
|
||||
private void radio_inv_click(object sender, EventArgs e)
|
||||
{
|
||||
RadioButton rb = sender as RadioButton;
|
||||
if (rb.Checked)
|
||||
{
|
||||
if (rb.Checked)
|
||||
{
|
||||
lbInverterID.Text = rb.Text;
|
||||
lbMsg_inv.Text = "...";
|
||||
}
|
||||
@ -194,11 +195,11 @@ namespace solarApp
|
||||
try
|
||||
{
|
||||
gv_fic_station_raw.DataSource = stationSvc.get_station_raw(date2, lbSiteDB_inv.Text, lbSiteID_inv.Text);
|
||||
gv_fic_station_day.DataSource = stationSvc.get_station_rawAvg(date1, date2, lbSiteDB_inv.Text, lbSiteID_inv.Text);
|
||||
gv_fic_station_day.DataSource = stationSvc.get_station_rawAvg(date1, date2, lbSiteDB_inv.Text, lbSiteID_inv.Text);
|
||||
}
|
||||
catch (Exception ex )
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show( ex.Message);
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
gv_web_station_hour.DataSource = stationSvc.get_web_station_hour(date2, lbSiteID_inv.Text);
|
||||
|
||||
@ -223,8 +224,8 @@ namespace solarApp
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
gv_web_sensor_hour.DataSource = sensorSvc.get_web_sensor_hour(date2, lbSiteID_inv.Text.Substring(0, 09));
|
||||
|
||||
gv_web_sensor_day.DataSource = sensorSvc.get_web_sensor_day(date1, date2, lbSiteID_inv.Text.Substring(0, 09));
|
||||
@ -329,7 +330,7 @@ namespace solarApp
|
||||
|
||||
private void button1_Click_2(object sender, EventArgs e)
|
||||
{
|
||||
if(label13.Text == "solar_master.notice_schedule資料表")
|
||||
if (label13.Text == "solar_master.notice_schedule資料表")
|
||||
{
|
||||
gv_notice_data.DataSource = errorSvc.QueryAlarmorion_orionalarmrecordData();
|
||||
label13.Text = "solar_master.alarmorion_orionalarmrecord資料表";
|
||||
|
||||
@ -1,4 +1,64 @@
|
||||
<root>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user