This commit is contained in:
2025-05-26 13:27:34 +04:00
parent 0d9bb677c1
commit 83f1edcd9c
6 changed files with 89 additions and 55 deletions

View File

@@ -1,13 +1,15 @@
using Oracle.ManagedDataAccess.Client;
using Microsoft.Data.SqlClient;
using Oracle.ManagedDataAccess.Client;
using SendNotify;
using System.Net;
using System.Net.Http.Json;
using System.Text;
using System.Data.SqlClient;
internal class Program
{
private static DateTime lastDate = DateTime.MinValue;
[Obsolete]
private static void Main(string[] args)
{
while (true)
@@ -17,6 +19,8 @@ internal class Program
string? proxyUrl = null;
string? proxyUsername = null;
string? proxyPassword = null;
string? checkNow = null;
var config = File.ReadAllLines("config.txt");
foreach (var line in config)
@@ -31,26 +35,45 @@ internal class Program
proxyUsername = line.Substring("proxy_username=".Length);
else if (line.StartsWith("proxy_password="))
proxyPassword = line.Substring("proxy_password=".Length);
else if (line.StartsWith("check_now="))
checkNow = line.Substring("check_now=".Length);
}
if (gotifyUrl == null || appToken_izhstal == null || proxyUrl == null || proxyUsername == null || proxyPassword == null)
if (gotifyUrl == null || appToken_izhstal == null || proxyUrl == null || proxyUsername == null || proxyPassword == null || checkNow == null)
{
Console.WriteLine("Ошибка: не все параметры указаны в config.txt");
Log.Logger("Ошибка: не все параметры указаны в config.txt");
}
else
NotifyPollingAsync(gotifyUrl, appToken_izhstal, proxyUrl, proxyUsername, proxyPassword);
{
NotifyPollingAsync(gotifyUrl, appToken_izhstal, proxyUrl, proxyUsername, proxyPassword, checkNow);
}
Thread.Sleep(60000);
}
}
[Obsolete]
private static async void NotifyPollingAsync(string url, string token, string proxyUrl, string proxyUsername, string proxyPassword)
private static async void NotifyPollingAsync(string url, string token, string proxyUrl, string proxyUsername, string proxyPassword, string checkNow)
{
#region check furnace 250
#region test msg to check
DateTime now = DateTime.Now;
if ((now.Hour == 8 && now.Date != lastDate.Date) || checkNow.ToLower() == "yes")
{
var notification = new
{
title = "Test notify",
message = "IS OK",
priority = 3
};
await SendNotify(url, token, notification, proxyUrl, proxyUsername, proxyPassword);
if (checkNow.ToLower() != "yes")
lastDate = now;
}
#endregion
#region check furnace 250
var result = CheckFurnace250().Result;
if (!result.status)
{
@@ -64,20 +87,6 @@ internal class Program
}
#endregion
#region test msg to check
if (now.Hour == 8 && now.Date != lastDate.Date)
{
var notification = new
{
title = "Test notify",
message = "IS OK",
priority = 3
};
await SendNotify(url, token, notification, proxyUrl, proxyUsername, proxyPassword);
lastDate = now;
}
#endregion
#region check billets 250
result = CheckRoughToFinishedBilletCount().Result;
if (!result.status)
@@ -109,9 +118,9 @@ internal class Program
}
}
}
catch
catch (Exception ex)
{
return (false, "Ошибка подключения к БД Oracle ст.250!");
return (false, ex.Message);
}
if (cntBillets > 15)
{
@@ -119,46 +128,57 @@ internal class Program
}
return (true, "OK");
}
[Obsolete]
private static async Task<(bool status, string msg)> CheckFurnace250()
{
int cntEmptyPOID = 0;
DateTime lastDT = DateTime.Now;
const string sqlConn = @"Password=WonderUser;User ID=WonderUser;Initial Catalog=Furnace_l2;Data Source=10.14.18.38\IZHSTALSQLSRVER;TrustServerCertificate=true;Encrypt=true;";
try
{
using (var conn = new SqlConnection(sqlConn))
{
await conn.OpenAsync();
string sqlQuery = @"SELECT COUNT(PO_ID) cnt_empty_poid, (SELECT top(1)
CHARGING_TIME
FROM [Furnace_l2].[dbo].[HIST_PIECES]
where [IS_DISCHARGED] ='N' and
datediff(day,CHARGING_TIME, Getdate()) < 1 AND
RTRIM(LTRIM(PO_ID)) != ''
order by CHARGING_TIME desc) last_dt
FROM [Furnace_l2].[dbo].[HIST_PIECES]
where [IS_DISCHARGED] ='N' and
datediff(day,CHARGING_TIME, Getdate()) < 1 AND
RTRIM(LTRIM(PO_ID)) = '';";
string sqlQuery = @"SELECT
COUNT(PO_ID) cnt_empty_poid,
(
SELECT
top(1) CHARGING_TIME
FROM
[Furnace_l2].[dbo].[HIST_PIECES]
WHERE
[IS_DISCHARGED] = 'N'
AND datediff(DAY, CHARGING_TIME, Getdate()) < 1
AND RTRIM(LTRIM(PO_ID)) != ''
ORDER BY
CHARGING_TIME DESC
) last_dt
FROM
[Furnace_l2].[dbo].[HIST_PIECES]
WHERE
[IS_DISCHARGED] = 'N'
AND datediff(DAY, CHARGING_TIME, Getdate()) < 1
AND RTRIM(LTRIM(PO_ID)) = '';";
using (var command = new SqlCommand(sqlQuery, conn))
using (var dbReader = await command.ExecuteReaderAsync())
{
while (await dbReader.ReadAsync())
{
cntEmptyPOID = Convert.ToInt32(dbReader.GetValue(0));
lastDT = Convert.ToDateTime(dbReader.GetValue(1));
if (dbReader.GetValue(0) != DBNull.Value && dbReader.GetValue(1) != DBNull.Value)
{
cntEmptyPOID = Convert.ToInt32(dbReader.GetValue(0));
lastDT = Convert.ToDateTime(dbReader.GetValue(1));
}
}
}
}
}
catch
catch (Exception ex)
{
return (false, "Ошибка подключения к БД sql server печи ПШП!");
return (false, ex.Message);
}
if (cntEmptyPOID > 15 && DateTime.Now - lastDT > new TimeSpan(0, 5, 0))
@@ -218,4 +238,5 @@ internal class Program
}
}
}
}
}