applicant_list

This commit is contained in:
Алексей Заблоцкий 2023-10-19 19:14:38 +03:00
parent ddba6c7a3a
commit 42b89fe6e9
6 changed files with 196 additions and 8 deletions

View File

@ -5,7 +5,7 @@ unit cgiReport;
interface
uses
Classes, SysUtils, baseconnection, extTypes;
Classes, SysUtils, baseconnection, extTypes, xpMemParamManagerUnit;
type
{ TReportCommand }
@ -25,6 +25,7 @@ type
procedure Prepare; virtual;
procedure PrepareVars; virtual;
procedure FillVars;
procedure OnFillVariables(AVariables: TxpMemParamManager); virtual;
function Run: boolean; override;
function ParseArguments(Args: TStrings; out Errors: TStrings): boolean; override;
function ProcessOptionValues(ParamName: string; out Answer: string; out RetValue: QWORD; out OptionValues: TStrings): boolean; override;
@ -160,6 +161,11 @@ begin
connect.Processor.ExecuteSQL(script);
end;
procedure TReportCommand.OnFillVariables(AVariables: TxpMemParamManager);
begin
end;
function TReportCommand.Run: boolean;
var
i: integer;
@ -203,7 +209,7 @@ begin
end;
fcurrentStage := 'исполняется ()';
try
connect.ReportProcessor.ExportReport(ftPDF,fileData,@SetStage);
connect.ReportProcessor.ExportReport(ftPDF,fileData,@SetStage,@OnFillVariables);
except on e: Exception do
begin
connect.Processor.LogError(self,e,'ExportReport');

View File

@ -76,7 +76,6 @@
<PathDelim Value="\"/>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="U:\Apache\Apache24\cgi-bin"/>
</SearchPaths>
<Other>
<CustomOptions Value="-dDEBUG

View File

@ -119,6 +119,10 @@
<HasResources Value="True"/>
<UnitName Value="reportDMUnit"/>
</Unit>
<Unit>
<Filename Value="reports\applicantlist.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
@ -129,6 +133,7 @@
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<OtherUnitFiles Value="reports"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>

View File

@ -11,7 +11,7 @@ Uses
sysutils,
DaemonApp, lazdaemonapp, cgi_mapper, cgi_daemon, tcpthreadhelper,
ConnectionsDmUnit, baseconnection, tcpserver, cgiReport, cgiDM, extTypes,
reportDMUnit, abbrevia, lnetbase
reportDMUnit, abbrevia, lnetbase, applicantlist
{ add your units here };
begin

View File

@ -13,7 +13,7 @@ type
{ TReportDM }
TReportQuery=class;
{ TReportQuery }
TVariableFillProc=procedure(AVariables: TxpMemParamManager) of object;
TReportQuery=class
private
@ -54,6 +54,8 @@ type
DetailDataSets: TStringList; // Список Detail-датасетов. В Objects - TStringList (id query + Detail-датасет(TfrxDBDataset))
ReportVariables: TxpMemParamManager;
ReportQueries: TReportQuery;
fOnVars: TVariableFillProc;
procedure CreateDBDataSet(Query:TReportQuery; EditReport: Boolean = False);
procedure CreateSignaturesDataSet(EditReport: Boolean = False);
procedure CreateLogosDataSet(EditReport: Boolean = False);
@ -82,7 +84,8 @@ type
public
RecordID: integer;
NidbData: TNIDBDM;
procedure ExportReport( ExportType: TExportFileType; Data: TStream; OnStage: TLogger);
procedure ExportReport( ExportType: TExportFileType; Data: TStream; OnStage: TLogger; OnVars: TVariableFillProc);
end;
var
@ -407,6 +410,8 @@ var
SQL: string;
l: TStrings;
i: integer;
OptionName,
OptionValue: String;
begin
NidbData.log(mtDebug,self,'LoadDefaultVariables');
@ -421,7 +426,20 @@ begin
finally
free;
end;
for i := 1 to 5 do
AVariables['GOU_Name'+inttostr(i)] := AVariables['GOU_Name'];
with NidbData.GetData('SELECT name,value from options WHERE name like ''GOU_Name%'' ') do
try
while not eof do
begin
OptionName := fieldByName('name').AsString;
OptionValue := AnsiString(FieldByName('Value').AsString);
AVariables[OptionName] := trim(OptionValue);
Next;
end;
finally
Free;
end;
end;
procedure TReportDM.LoadLogos(AVariables: TxpMemParamManager);
@ -605,13 +623,14 @@ end;
procedure TReportDM.ExportReport(ExportType: TExportFileType; Data: TStream;
OnStage: TLogger);
OnStage: TLogger; OnVars: TVariableFillProc);
var
I : Integer;
flt : TfrxCustomExportFilter;
v : Variant;
AVariables, AParam: TxpMemParamManager;
begin
fOnVars:=OnVars;
frxReport.EngineOptions.EnableThreadSafe:=true;
NidbData.log(mtDebug,self,'ExportReport');
ReportQueries := TReportQuery.Create;
@ -624,6 +643,7 @@ begin
LoadDefaultVariables(AVariables);
LoadLogos(AVariables);
LoadVariables(AVariables,AParam);
if assigned(fOnVars) then fOnVars(AVariables);
frxReport.EngineOptions.DestroyForms := False;
// Создаём источники данных
if assigned(OnStage) then

158
reports/applicantlist.pas Normal file
View File

@ -0,0 +1,158 @@
unit applicantlist;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, cgiReport,xpMemParamManagerUnit;
type
{ TRepApplicantList }
TRepApplicantList=class(TReportCommand)
private
edtMode: integer;
cbStream: integer;
idYear: integer;
public
class function CommandSubClass: string; override;
procedure Prepare; override;
procedure OnFillVariables(AVariables: TxpMemParamManager); override;
end;
implementation
uses
cgiDM,dateutils,baseconnection;
{ TRepApplicantList }
class function TRepApplicantList.CommandSubClass: string;
begin
Result:='applicant_list';
end;
procedure TRepApplicantList.Prepare;
var
SQL: string;
filter: string;
DateFilter: string;
begin
inherited prepare;
edtMode := strtointdef(self.Arguments.Keys.Values['mode'],0);
cbStream := strtointdef(self.Arguments.Keys.Values['stream'],0);
idyear := strtointdef(self.Arguments.Keys.Values['year'],0);
case edtMode of
0: filter := ' AND a1.testready<>0 ';
1: filter := ' AND (a1.testready=0) ';
end;
if cbStream = 1 then //Донабор
begin
DateFilter := Format(' AND cast(date as DATE) BETWEEN %0:s AND %1:s ',
[TNIDBDM.StringAsSQL(Arguments.Keys.Values['fromdate']), TNIDBDM.StringAsSQL(Arguments.Keys.Values['todate'])]);
end;
SQL := format(
'DROP TABLE IF EXISTS tmp_applicant; '+
'CREATE TEMPORARY TABLE tmp_applicant AS '+
'SELECT '+
' a.xp_key, '+
' subj.Subject, '+
' CONCAT_WS('' '',UPPER(a.Child_LastName),a.Child_FirstName,a.Child_MidName) AS FIO, '+
' a.Child_Birth, '+
' a.Child_Class, '+
' CASE WHEN a.testready<>0 THEN ''годен'' ELSE ''не годен'' END AS isready, '+
' COALESCE(a.coeff,1) as coeff, '+
' a.sex, '+
' a.child_mark, '+
' a.Child_Mark_Russ, '+
' a.Child_Mark_Math, '+
' a.Child_Mark_Lang, '+
' a.Child_Mark_Phys, '+
' a.Child_Mark_Info, '+
' COALESCE(NULLIF(a2.Privilege,''''),''нет'') as Privilege, '+
' (SELECT GROUP_CONCAT(l.course_name SEPARATOR '', '') FROM xp_applicant_file_lang l WHERE l.mid=a.xp_key ) as languages, '+
// ' %1:s as status, ' +
' a.CauseFailure '+
'FROM ( '+
' SELECT a1.xp_key, '+
' GROUP_CONCAT(distinct ' +
' CASE WHEN np.code = ''Л'' THEN ''Указ Президента РФ от 09.05.2022 г. №268 п.3/ч.1.'' '+
' WHEN np.code = ''Л1'' THEN ''Указ Президента РФ от 09.05.2022 г. №268 п.3/ч.2.'' '+
' WHEN np.code = ''М'' THEN ''Федеральный закон от 29 декабря 2022 года «641-ФЗ, статья 86, часть 6.1»'' '+
' WHEN np.code IS NOT NULL THEN priv.PrivilegeCode ' +
' ELSE priv.PrivilegeName END order by priv.PrivilegeCode SEPARATOR '', '') AS Privilege '+
' FROM xp_applicant a1 '+
' LEFT JOIN xp_applicant_file_privilege priv ON priv.mid=a1.xp_key AND priv.PrivilegeCode <> ''-'' '+
' LEFT JOIN c_privilege np ON np.code=priv.PrivilegeCode ' +
' WHERE a1.s_year_id=%0:d AND applicant_status_id <> 4'+
' AND (%1:d=COALESCE(a1.stream,0)) '+
filter+
DateFilter+
' GROUP BY a1.xp_key '+
') a2 '+
' JOIN xp_applicant a ON a.xp_key = a2.xp_key '+
' LEFT JOIN xp_subjects subj ON subj.Subject = a.Subject; ',
[idyear,cbStream]);
Connect.Processor.ExecuteSQL(SQL);
SQL :=
'DROP TABLE IF EXISTS tmp_app_sex; '+
'CREATE TEMPORARY TABLE tmp_app_sex AS '+
'SELECT child_class, count(*) as sex_count FROM '+
'(SELECT child_class,sex FROM tmp_applicant WHERE sex IS NOT NULL GROUP BY child_class,sex) t '+
'GROUP BY Child_class; ';
Connect.Processor.ExecuteSQL(SQL);
SQL := format(
'DROP TABLE IF EXISTS tmp_members; '+
'CREATE TEMPORARY TABLE tmp_members AS '+
' SELECT xp_f_get_mid_fio(m.mid,0) as member FROM enroll_comitet c '+
' JOIN enroll_comitet_members m ON m.enroll_comitet = c.id '+
'WHERE c.school_year=%0:d AND coalesce(c.stream,0)=%1:d ORDER BY 1' ,
[idYear,cbStream]);
Connect.Processor.ExecuteSQL(SQL);
end;
procedure TRepApplicantList.OnFillVariables(AVariables: TxpMemParamManager);
var
SQL: string;
Z2: string;
begin
case edtMode of
0: AVariables['mode'] := '';
1: AVariables['mode'] := '';
end;
AVariables['mode_id'] := edtMode;
AVariables['Year'] := YearOf(Date);
SQL := format(
'SELECT xp_f_get_mid_fio(c.chairman,0) as chairman , xp_f_get_mid_fio(c.deputy,0) as deputy, xp_f_get_mid_fio(c.deputy2,0) as deputy2, xp_f_get_mid_fio(c.secretary,0) as secretary '+
'FROM enroll_comitet c WHERE c.school_year = %0:d AND coalesce(c.stream,0)=%1:d; ',
[idYear,cbStream]);
with connect.Processor.getData(SQL) do
try
if Not eof then
begin
AVariables['Председатель'] := (FieldByName('Chairman').AsString);
AVariables['Заместитель'] := (FieldByName('Deputy').AsString);
Z2 := (FieldByName('Deputy2').AsString);
AVariables['Секретарь'] := (FieldByName('Secretary').AsString);
end
else
begin
AVariables['Председатель'] := ('');
AVariables['Заместитель'] := ('');
AVariables['Секретарь'] := ('');
Z2 := '';
end;
AVariables['Заместитель2'] := (Z2);
if Z2<>'' then AVariables['zam2'] := 1 else AVariables['zam2'] := 0;
finally
Free;
end;
end;
Initialization
TCommandCollection.Register(TRepApplicantList);
end.