Skip to content

Instantly share code, notes, and snippets.

@best-tech
Forked from dmpas/cgi-example.os
Created February 17, 2017 09:40
Show Gist options
  • Save best-tech/6851380d59324fc468ef770c83a06566 to your computer and use it in GitHub Desktop.
Save best-tech/6851380d59324fc468ef770c83a06566 to your computer and use it in GitHub Desktop.
#!C:/opt/oscript/bin/oscript.exe -cgi
ВывестиЗаголовок("Content-type", "text/html");
ВывестиЗаголовок("Content-Encoding", "utf-8");
ВывестиЗаголовок("Cache-control", "no-cache");
ПараметрыЗапроса = Новый Соответствие;
Для Каждого мКЗ Из ВебЗапрос.GET Цикл
ПараметрыЗапроса.Вставить(мКЗ.Ключ, мКЗ.Значение);
КонецЦикла;
Бренд = ПараметрыЗапроса.Получить("marka");
Если Не ЗначениеЗаполнено(Бренд) Тогда
Сообщить(НСтр("en='Please set up MARKA';"));
Exit(1);
КонецЕсли;
ПодключитьВнешнююКомпоненту("C:\opt\oscgi\sql.dll");
Соединение = Новый Соединение;
Соединение.ТипСУБД = Соединение.ТипыСУБД.MSSQLServer;
Соединение.Сервер = "";
Соединение.ИмяПользователя = "";
Соединение.Пароль = "";
Соединение.ИмяБазы = "";
Соединение.Открыть();
Q = Новый Запрос;
Q.УстановитьСоединение(Соединение);
Q.Текст = "
|select
| SUM(_Fld2448) as [total],
| SUM(case when DATEPART(HOUR, _Period) < @hour then _Fld2448 else 0 end) as [before],
| SUM(case when DATEPART(HOUR, _Period) = @hour then _Fld2448 else 0 end) as [this],
| SUM(case when _Period >= @this_day then _Fld2448 else 0 end) as [today]
|from _AccumRg2441 as reg with (nolock)
| join _Reference55 as skl with (nolock)
| join _Reference41 as mag with (nolock)
| join _Reference2545 as br with (nolock)
| on mag._Fld2754RRef = br._IDRRef
| on skl._Fld726RRef = mag._IDRRef
| on reg._Fld2442RRef = skl._IDRRef
|where _Period >= '4014-11-01' and _Active = 0x01 and _RecorderTRef in (89,107)
| and _Fld2448 > 0
| and case when DATEPART(WEEKDAY, reg._Period) in (1, 7) then 1 else 0 end = @holyflag
| and br._Fld2565 = @p_marka
|";
Дата = ДобавитьМесяц(НачалоДня(ТекущаяДата()), 2000 *12);
Час = Час(ТекущаяДата());
Минута = Минута(ТекущаяДата());
Q.УстановитьПараметр("this_day", Дата);
Q.УстановитьПараметр("holyflag", 0);
Q.УстановитьПараметр("p_marka", Бренд);
Q.УстановитьПараметр("hour", Час);
Result = Q.Execute();
Таблица = Result.Unload();
Для Каждого RS Из Таблица Цикл
Total = RS["total"];
Before = RS["before"];
This = RS["this"];
Today = RS["today"];
ДоляЭтотЧас = This/Total * Минута / 60;
ДоляЭтотДень = Before / Total + ДоляЭтотЧас;
Прогноз = 0;
Если ДоляЭтотДень > 0 Тогда
Прогноз = Окр(Today / ДоляЭтотДень, 2);
КонецЕсли;
Сообщить(Прогноз);
Прервать;
КонецЦикла;
@best-tech
Copy link
Author

Кусок настройки апача
Alias "/oscgi/" "C:/opt/oscgi"
<Directory "C:/opt/oscgi">
Options +ExecCGI
AddHandler cgi-script .os

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment