-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUDBProcess.pas
More file actions
2195 lines (2084 loc) · 90.6 KB
/
Copy pathUDBProcess.pas
File metadata and controls
2195 lines (2084 loc) · 90.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit UDBProcess;
interface
uses
SysUtils, Classes, DB, MemDS, DBAccess, Uni, UniProvider, OracleUniProvider, Dialogs,
XMLIntf, XMLDoc, ImgList, Controls, CoolTrayIcon, Menus, TmriOutAccess, HTTPApp, DateUtils;
type
TXMLType = (xt_inXml, xt_outXml);
TDM = class(TDataModule)
OracleUniProvider: TOracleUniProvider;
DBConnect: TUniConnection;
pubQuery: TUniQuery;
spSql: TUniStoredProc;
private
{ Private declarations }
function ExecSql(var Query: TUniQuery; SqlStr: String; isGetRecord: Boolean = True): Boolean;
function GetCurrXmlNode(parentNode: IXMLNode; subNode: String; xmlType: TXMLType=xt_inXml): IXMLNode;
function UpdateResult(var parentNode: IXMLNode; resFlag: String; resMemo: string) : Integer;
procedure HashArithmetic(StrTableName: string; StrWhere: string);
function BuildInterfaceXML(exam_id: string; process_id: string; var jkid: string): string;
function WebServicesInterface(exam_id: string; process_id: string): Boolean;
//下载系统参数交易
function _0_XMLEvent(inXmldoc : IXMLDocument; var outXMLDoc : IXMLDocument) : Integer;
//车载子系统交易
function _1001_XMLEvent(inXmldoc : IXMLDocument; var outXMLDoc : IXMLDocument) : Integer;
function _1002_XMLEvent(inXmldoc : IXMLDocument; var outXMLDoc : IXMLDocument) : Integer;
function _1003_XMLEvent(inXmldoc : IXMLDocument; var outXMLDoc : IXMLDocument) : Integer;
function _1004_XMLEvent(inXmldoc : IXMLDocument; var outXMLDoc : IXMLDocument) : Integer;
function _1005_XMLEvent(inXmldoc : IXMLDocument; var outXMLDoc : IXMLDocument) : Integer;
function _1006_XMLEvent(inXmldoc : IXMLDocument; var outXMLDoc : IXMLDocument) : Integer;
function _1007_XMLEvent(inXmldoc : IXMLDocument; var outXMLDoc : IXMLDocument) : Integer;
function _1008_XMLEvent(inXmldoc : IXMLDocument; var outXMLDoc : IXMLDocument) : Integer;
function _1009_XMLEvent(inXmldoc : IXMLDocument; var outXMLDoc : IXMLDocument) : Integer;
//现场支付相关
function _2001_XMLEvent(inXmldoc : IXMLDocument; var outXMLDoc : IXMLDocument) : Integer;
function _2002_XMLEvent(inXmldoc : IXMLDocument; var outXMLDoc : IXMLDocument) : Integer;
//音视频子系统交易
function _3001_XMLEvent(inXmldoc : IXMLDocument; var outXMLDoc : IXMLDocument) : Integer;
//测绘子系统交易
function _4001_XMLEvent(inXmldoc : IXMLDocument; var outXMLDoc : IXMLDocument) : Integer;
function _4002_XMLEvent(inXmldoc : IXMLDocument; var outXMLDoc : IXMLDocument) : Integer;
function _4003_XMLEvent(inXmldoc : IXMLDocument; var outXMLDoc : IXMLDocument) : Integer;
function _4004_XMLEvent(inXmldoc : IXMLDocument; var outXMLDoc : IXMLDocument) : Integer;
//排队叫号子系统交易
function _5001_XMLEvent(inXmldoc : IXMLDocument; var outXMLDoc : IXMLDocument) : Integer;
//闸机服务子系统交易
function _6001_XMLEvent(inXmldoc : IXMLDocument; var outXMLDoc : IXMLDocument) : Integer;
function Str2Time(timStr: string): Extended;
public
{ Public declarations }
constructor Create();reintroduce;
destructor Destroy; override;
procedure SetDBConnect(inDBConnect: TUniConnection);
function XMLDocExecute(inXmldoc : IXMLDocument; var outXMLDoc : IXMLDocument) : Boolean;
end;
var
DM: TDM;
implementation
uses
UPublic, Base64, EncdDecd, UMyHash, UMain;
{$R *.dfm}
{ TDM }
function TDM.UpdateResult(var parentNode: IXMLNode; resFlag,
resMemo: string): Integer;
begin
parentNode.ChildNodes.FindNode('res_flag').Text := resFlag;
parentNode.ChildNodes.FindNode('res_memo').Text := resMemo;
Result := 0;
end;
function TDM.WebServicesInterface(exam_id, process_id: string): Boolean;
var
resXML, returnXML: string;
debugPath, jkid, strSQL: string;
inXMLDoc, outXMLDoc: IXMLDocument;
rootNode, codeNode, mesgNode: IXMLNode;
statusQuery:TmriOutAccess.TmriJaxRpcOutAccess;
timestr: string;
begin
Result := False;
if claPublic.IsExamMode = '0' then
begin
Result := True;
Exit;
end else
begin
resXML := BuildInterfaceXML(exam_id,process_id,jkid);
inXMLDoc := TXMLDocument.Create(nil);
outXMLDoc := TXMLDocument.Create(nil);
try
if resXML = '' then
begin
// strRtn := '$E##无接口上报的数据记录';
claPublic.WriteLog('WS','无接口上报的数据记录');
frmMain.MemoLog.Lines.Add('$E##无接口上报的数据记录');
Exit;
end else
begin
// if claPublic.IsDebug = '1' then //comment by zj
begin
inXMLDoc.LoadFromXML(AnsiString(resXML));
debugPath := claPublic.GetFileDir('wsxml\send');
DateTimeToString(timestr, 'yyyy-mm-dd-hh-nn-ss', now);
inXMLDoc.SaveToFile(Format('%s%s-%s_send.xml',[debugPath,timestr,jkid]));
end;
try
statusQuery:=GetTmriJaxRpcOutAccess;
returnXML := statusQuery.writeObjectOut(claPublic.WEB_SYSCLASS,claPublic.WEB_SERIALNUMBER,claPublic.WEB_SYSCLASS+jkid,resXML);
outXMLDoc.LoadFromXML(AnsiString(UTF8Decode(HTTPDecode(AnsiString(returnXML)))));
// if claPublic.IsDebug = '1' then //comment by zj
begin
debugPath := claPublic.GetFileDir('wsxml\receive');
outXMLDoc.SaveToFile(Format('%s%s-%s_receive.xml',[debugPath,timestr,jkid]));
end;
rootNode := outXMLDoc.DocumentElement;
codeNode := rootNode.ChildNodes['head'].ChildNodes['code']; //回应状态
mesgNode := rootNode.ChildNodes['head'].ChildNodes['message']; //回应信息
if (Trim(codeNode.Text) = '1') or (Trim(codeNode.Text)='-90') then
begin
Result := True;
end else
Result := False;
// strRtn := NNode.text+'##'+cNode.Text;
//更新接口返回结果
strSQL := Format('update buz_exam_process set process_status=%s where id=%s and exam_id=%s',
[QuotedStr(Trim(codeNode.Text)),
QuotedStr(process_id),
QuotedStr(exam_id)]);
ExecSql(pubQuery,strSQL,False);
except
on E:Exception do
begin
// strRtn := '$E##远程接口调用失败';
claPublic.WriteLog('WS',Format('远程接口调用失败!异常信息:%s',[E.Message]));
frmMain.MemoLog.Lines.Add(Format('远程接口调用失败!异常信息:%s',[E.Message]));
Exit;
end;
end;
end;
finally
inXMLDoc := nil;
outXMLDoc := nil;
end;
end;
end;
function TDM.BuildInterfaceXML(exam_id, process_id: string; var jkid: string): string;
var
strSQL, strXML, strPhoto: string;
PhotoBuf: TMemoryStream;
begin
strXML := '';
jkid := '';
strSQL := Format('select bei.id, bep.id,'+
'(select param_value from cfg_param where param_name = ''SYSTEM_SERIAL_NUMBER'') as ksxtbh,'+
'bb.sequencenumber as lsh, bei.subject as kskm,bs.idnumber as sfzmhm,'+
'to_char(to_date(bep.process_time, ''yyyy-MM-ddhh24:mi:ss''),''yyyy-MM-ddhh24:mi:ss'') as sj,'+
'bep.process_flag as pflag,bep.process_type as jkid,'+
'bep.exam_item as ksxm,bep.deduct_item as kfxm,'+
'bep.process_photo as zp,bd.sequencenumber as sbxh, '+
'bc.license_plate as kchp,bep.speed as cs,'+
'bei.current_exam_score as kscj,be1.idnumber as ksysfzmhm,'+
'be2.idnumber as ksy2sfzmhm,bep.record_type as czlx '+
'from buz_exam_info bei '+
'left join buz_exam_process bep on bep.exam_id = bei.id '+
'left join bas_booking bb on bb.student_id = bei.student_id '+
'left join bas_student bs on bs.id = bei.student_id '+
'left join bas_car bc on bc.id = bei.car_id '+
'left join bas_examiner be1 on be1.id = bei.examiner1_id '+
'left join bas_examiner be2 on be2.id = bei.examiner2_id '+
'left join bas_device bd on bd.id = bep.device_id '+
'where bei.id = %s and bep.id = %s '+
'order by bep.id asc',[QuotedStr(exam_id),QuotedStr(process_id)]);
ExecSql(pubQuery,strSQL);
if pubQuery.RecordCount <> 1 then
begin
Exit;
end else
begin
PhotoBuf := TMemoryStream.Create;
try
PhotoBuf.Clear;
strPhoto := '';
jkid := UpperCase(Trim(pubQuery.FieldByName('jkid').AsString));
if jkid = 'C51' then
begin
TBlobField(pubQuery.FieldByName('zp')).SaveToStream(PhotoBuf);
Base64Enc(PhotoBuf, strPhoto, PhotoBuf.Size);
strXML := Format('<?xml version="1.0" encoding="GBK" ?><root><drvexam> '+
'<lsh>%s</lsh><kskm>%s</kskm><ksxtbh>%s</ksxtbh><sfzmhm>%s</sfzmhm>'+
'<ksysfzmhm>%s</ksysfzmhm><zp>%s</zp><kssj>%s</kssj><Ksy2sfzmhm>%s</Ksy2sfzmhm>'+
'</drvexam></root>',
[Trim(pubQuery.FieldByName('lsh').AsString),
Trim(pubQuery.FieldByName('kskm').AsString),
Trim(pubQuery.FieldByName('ksxtbh').AsString),
Trim(pubQuery.FieldByName('sfzmhm').AsString),
Trim(pubQuery.FieldByName('ksysfzmhm').AsString),
Trim(strPhoto),
Trim(pubQuery.FieldByName('sj').AsString),
Trim(pubQuery.FieldByName('Ksy2sfzmhm').AsString)
]);
claPublic.WriteLog('WS',Format('%s 身份信息比对',[jkid]));
end
else if jkid = 'C52' then
begin
strXML := Format('<?xml version="1.0" encoding="GBK" ?><root><drvexam> '+
'<lsh>%s</lsh><kskm>%s</kskm><sfzmhm>%s</sfzmhm>'+
'<ksxm>%s</ksxm><sbxh>%s</sbxh><kchp>%s</kchp><kssj>%s</kssj>'+
'</drvexam></root>',
[Trim(pubQuery.FieldByName('lsh').AsString),
Trim(pubQuery.FieldByName('kskm').AsString),
Trim(pubQuery.FieldByName('sfzmhm').AsString),
Trim(pubQuery.FieldByName('ksxm').AsString),
Trim(pubQuery.FieldByName('sbxh').AsString),
Trim(pubQuery.FieldByName('kchp').AsString),
Trim(pubQuery.FieldByName('sj').AsString)
]);
claPublic.WriteLog('WS',Format('%s 考试项目开始',[jkid]));
end
else if jkid = 'C53' then
begin
strXML := Format('<?xml version="1.0" encoding="GBK" ?><root><drvexam> '+
'<lsh>%s</lsh><kskm>%s</kskm><ksxm>%s</ksxm>'+
'<kfxm>%s</kfxm><sfzmhm>%s</sfzmhm><kfsj>%s</kfsj>'+
'</drvexam></root>',
[Trim(pubQuery.FieldByName('lsh').AsString),
Trim(pubQuery.FieldByName('kskm').AsString),
Trim(pubQuery.FieldByName('ksxm').AsString),
Trim(pubQuery.FieldByName('kfxm').AsString),
Trim(pubQuery.FieldByName('sfzmhm').AsString),
Trim(pubQuery.FieldByName('sj').AsString)
]);
claPublic.WriteLog('WS',Format('%s 考试扣分',[jkid]));
end
else if jkid = 'C54' then
begin
TBlobField(pubQuery.FieldByName('zp')).SaveToStream(PhotoBuf);
Base64Enc(PhotoBuf, strPhoto, PhotoBuf.Size);
strXML := Format('<?xml version="1.0" encoding="GBK" ?><root><drvexam> '+
'<lsh>%s</lsh><kskm>%s</kskm><ksxm>%s</ksxm>'+
'<sfzmhm>%s</sfzmhm><zpsj>%s</zpsj><zp>%s</zp><cs>%s</cs>'+
'</drvexam></root>',
[Trim(pubQuery.FieldByName('lsh').AsString),
Trim(pubQuery.FieldByName('kskm').AsString),
Trim(pubQuery.FieldByName('ksxm').AsString),
Trim(pubQuery.FieldByName('sfzmhm').AsString),
Trim(pubQuery.FieldByName('sj').AsString),
Trim(strPhoto),
Trim(pubQuery.FieldByName('cs').AsString)
]);
claPublic.WriteLog('WS',Format('%s 考试过程拍照',[jkid]));
end
else if jkid = 'C55' then
begin
strXML := Format('<?xml version="1.0" encoding="GBK" ?><root><drvexam> '+
'<lsh>%s</lsh><kskm>%s</kskm><sfzmhm>%s</sfzmhm>'+
'<ksxm>%s</ksxm><sbxh>%s</sbxh><jssj>%s</jssj><czlx>%s</czlx>'+
'</drvexam></root>',
[Trim(pubQuery.FieldByName('lsh').AsString),
Trim(pubQuery.FieldByName('kskm').AsString),
Trim(pubQuery.FieldByName('sfzmhm').AsString),
Trim(pubQuery.FieldByName('ksxm').AsString),
Trim(pubQuery.FieldByName('sbxh').AsString),
Trim(pubQuery.FieldByName('sj').AsString),
Trim(pubQuery.FieldByName('czlx').AsString)
]);
claPublic.WriteLog('WS',Format('%s 考试项目结束',[jkid]));
end
else if jkid = 'C56' then
begin
TBlobField(pubQuery.FieldByName('zp')).SaveToStream(PhotoBuf);
Base64Enc(PhotoBuf, strPhoto, PhotoBuf.Size);
strXML := Format('<?xml version="1.0" encoding="GBK" ?><root><drvexam> '+
'<lsh>%s</lsh><kskm>%s</kskm><sfzmhm>%s</sfzmhm>'+
'<zp>%s</zp><jssj>%s</jssj><kscj>%s</kscj>'+
'</drvexam></root>',
[Trim(pubQuery.FieldByName('lsh').AsString),
Trim(pubQuery.FieldByName('kskm').AsString),
Trim(pubQuery.FieldByName('sfzmhm').AsString),
Trim(strPhoto),
Trim(pubQuery.FieldByName('sj').AsString),
Trim(pubQuery.FieldByName('kscj').AsString)
]);
claPublic.WriteLog('WS',Format('%s 考试科目结束',[jkid]));
end;
finally
PhotoBuf.Free;
end;
end;
Result := strXML;
end;
constructor TDM.Create;
begin
inherited Create(nil);
end;
destructor TDM.Destroy;
begin
pubQuery.Close;
DBConnect.Disconnect;
DBConnect.Close;
inherited;
end;
function TDM.ExecSql(var Query: TUniQuery; SqlStr: String;
isGetRecord: Boolean): Boolean;
begin
//SQL语句执行增、删、改、查等操作
if Query.Active then Query.Close;
Query.SQL.Clear;
Query.SQL.Text := SqlStr;
// PasPublic.WriteLog('DB',Format('Execute "%s"',[SqlStr]));
try
if isGetRecord then
Query.Open
else
Query.ExecSQL;
result := true;
except
on E: Exception do
begin
claPublic.WriteLog('DB',Format('Exception message: %s',[E.Message]));
result := false;
end;
end;
end;
function TDM.GetCurrXmlNode(parentNode: IXMLNode; subNode: String;
xmlType: TXMLType): IXMLNode;
begin
Result := nil;
Result := parentNode.ChildNodes[subNode];
case xmlType of
xt_outXml:
begin
if Result = nil then
Result := parentNode.AddChild(subNode);
end;
end;
end;
procedure TDM.HashArithmetic(StrTableName, StrWhere: string);
var
i: Integer;
strSQL, hashStr, colNameStr: string;
begin
if StrTableName = 'BUZ_PAYMENT_DETAIL' then
strSQL := Format('select TRADE_NO,TRADE_TYPE,FEE_TIMES,FINAL_AMOUNT,PAY_TIME from %s %s',[StrTableName,StrWhere])
else
strSQL := Format('select * from %s %s',[StrTableName,StrWhere]);
ExecSql(pubQuery,strSQL);
hashStr := '';
for I := 0 to pubQuery.FieldCount - 1 do
begin
colNameStr := LowerCase(pubQuery.Fields[i].FieldName);
if colNameStr <> LowerCase('hash') then
hashStr := hashStr+Trim(pubQuery.Fields[i].AsString);
end;
hashStr := MyHash.SHA1(hashStr);
strSQL := Format('update %s set hash=%s %s',[StrTableName,QuotedStr(hashStr),StrWhere]);
ExecSql(pubQuery,strSQL,False);
end;
procedure TDM.SetDBConnect(inDBConnect: TUniConnection);
begin
DBConnect := inDBConnect;
DBConnect.SpecificOptions.Values['Direct'] := 'True';
DBConnect.LoginPrompt := False;
pubQuery.Connection := DBConnect;
end;
function TDM.XMLDocExecute(inXmldoc: IXMLDocument;
var outXMLDoc: IXMLDocument): Boolean;
var
root: IXMLNode;
xmlflag: Integer;
begin
Result := False;
root := inXMLDoc.ChildNodes.FindNode('root');
if root <> nil then
begin
if root.ChildNodes.FindNode('xmlflag') = nil then
Exit;
try
xmlflag := StrToInt(Trim(root.ChildNodes['xmlflag'].Text));
case xmlflag of
0: _0_XMLEvent(inXMLDoc,outXMLDoc);
//车载子系统交易类型
1001: _1001_XMLEvent(inXMLDoc,outXMLDoc);
1002: _1002_XMLEvent(inXMLDoc,outXMLDoc);
1003: _1003_XMLEvent(inXMLDoc,outXMLDoc);
1004: _1004_XMLEvent(inXMLDoc,outXMLDoc);
1005: _1005_XMLEvent(inXMLDoc,outXMLDoc);
1006: _1006_XMLEvent(inXMLDoc,outXMLDoc);
1007: _1007_XMLEvent(inXMLDoc,outXMLDoc);
1008: _1008_XMLEvent(inXMLDoc,outXMLDoc);
1009: _1009_XMLEvent(inXMLDoc,outXMLDoc);
//现场预约
2001: _2001_XMLEvent(inXmldoc, outXMLDoc);
2002: _2002_XMLEvent(inXmldoc, outXMLDoc);
//音视频子系统交易类型
3001: _3001_XMLEvent(inXMLDoc,outXMLDoc);
//测绘子系统交易类型
4001: _4001_XMLEvent(inXMLDoc,outXMLDoc);
4002: _4002_XMLEvent(inXMLDoc,outXMLDoc);
4003: _4003_XMLEvent(inXMLDoc,outXMLDoc);
4004: _4004_XMLEvent(inXMLDoc,outXMLDoc);
//排队叫号子系统交易类型
5001: _5001_XMLEvent(inXMLDoc,outXMLDoc);
//闸机服务子系统交易类型
6001: _6001_XMLEvent(inXMLDoc,outXMLDoc);
else
Exit;
end;
except
Exit;
end;
result := True;
end;
end;
function TDM._0_XMLEvent(inXmldoc: IXMLDocument;
var outXMLDoc: IXMLDocument): Integer;
var
inRoot, inChild, inSubChild: IXMLNode;
outRoot, outChild, outChildResult, outChildList: IXMLNode;
optype: Integer;
sub_code, subject, param_info, dict_info, items_info, coach_info, strSQL: string;
function BuildParam(var NodeList : IXMLNode; var tmpQuery: TUniQuery; sqlStr : String) : Integer;
var
Child: IXMLNode;
colNameStr: String;
i: Integer;
begin
try
ExecSql(tmpQuery,sqlStr);
tmpQuery.First;
while not tmpQuery.Eof do
begin
Child := NodeList.AddChild('param_item');
for I := 0 to tmpQuery.FieldCount - 1 do
begin
colNameStr := LowerCase(tmpQuery.Fields[i].FieldName);
Child.AddChild(colNameStr);
Child.ChildValues[colNameStr] := Trim(tmpQuery.Fields[i].AsString);
end;
tmpQuery.Next;
end;
Result := 0;
except
Result := -1;
end;
end;
function BuildDict(var NodeList : IXMLNode; var tmpQuery: TUniQuery; sqlStr : String) : Integer;
var
Child, subChild: IXMLNode;
colNameStr, Previous_type: String;
i: Integer;
begin
try
Previous_type := '';
ExecSql(tmpQuery,sqlStr);
tmpQuery.First;
while not tmpQuery.Eof do
begin
if Previous_type <> Trim(tmpQuery.Fields[0].AsString) then
begin
Previous_type := Trim(tmpQuery.Fields[0].AsString);
Child := NodeList.AddChild('dict_item');
for I := 0 to 1 do
begin
colNameStr := LowerCase(tmpQuery.Fields[i].FieldName);
Child.AddChild(colNameStr);
Child.ChildValues[colNameStr] := Trim(tmpQuery.Fields[i].AsString);
end;
end;
subChild := Child.AddChild('sub_item');
for i := 2 to tmpQuery.FieldCount - 1 do
begin
colNameStr := LowerCase(tmpQuery.Fields[i].FieldName);
subChild.AddChild(colNameStr);
subChild.ChildValues[colNameStr] := Trim(tmpQuery.Fields[i].AsString);
end;
tmpQuery.Next;
end;
Result := 0;
except
Result := -1;
end;
end;
function BuildItems(var NodeList : IXMLNode; var tmpQuery: TUniQuery; sqlStr : String) : Integer;
var
Child, subChild: IXMLNode;
colNameStr, Previous_ExamCode: String;
i: Integer;
begin
try
Previous_ExamCode := '';
ExecSql(tmpQuery,sqlStr);
tmpQuery.First;
while not tmpQuery.Eof do
begin
if Previous_ExamCode <> Trim(tmpQuery.Fields[0].AsString) then
begin
Child := NodeList.AddChild('exam_item');
Previous_ExamCode := Trim(tmpQuery.Fields[0].AsString);
for I := 0 to 1 do
begin
colNameStr := LowerCase(tmpQuery.Fields[i].FieldName);
Child.AddChild(colNameStr);
Child.ChildValues[colNameStr] := Trim(tmpQuery.Fields[i].AsString);
end;
end;
subChild := Child.AddChild('deduct_item');
for i := 2 to tmpQuery.FieldCount - 1 do
begin
colNameStr := LowerCase(tmpQuery.Fields[i].FieldName);
subChild.AddChild(colNameStr);
subChild.ChildValues[colNameStr] := Trim(tmpQuery.Fields[i].AsString);
end;
tmpQuery.Next;
end;
Result := 0;
except
Result := -1;
end;
end;
function BuildCoach(var NodeList : IXMLNode; var tmpQuery: TUniQuery; sqlStr : String) : Integer;
var
Child: IXMLNode;
coachFinger: string;
begin
try
ExecSql(tmpQuery,sqlStr);
tmpQuery.First;
while not tmpQuery.Eof do
begin
Child := NodeList.AddChild('coach_msg');
Child.AddChild('coach_idnumber');
Child.ChildValues['coach_idnumber'] := Trim(tmpQuery.Fields[0].AsString);
Child.AddChild('coach_name');
Child.ChildValues['coach_name'] := Trim(tmpQuery.Fields[1].AsString);
Child.AddChild('finger');
Child.ChildValues['finger'] := tmpQuery.Fields[2].AsString;
tmpQuery.Next;
end;
Result := 0;
except
Result := -1;
end;
end;
begin
Result := 0;
outRoot := outXMLDoc.ChildNodes.FindNode('root');
outChildResult := GetCurrXmlNode(outRoot,'result',xt_outXml);
outChild := GetCurrXmlNode(outRoot,'info',xt_outXml);
inRoot := inXMLDoc.ChildNodes.FindNode('root');
try
optype := StrToInt(Trim(inRoot.ChildNodes['optype'].Text));
except
UpdateResult(outChildResult,'1','操作类型异常');
Exit;
end;
inChild := GetCurrXmlNode(inRoot,'info');
if inChild <> nil then
begin
if inChild.ChildNodes.FindNode('sub_code') <> nil then
sub_code := Trim(inChild.ChildNodes.FindNode('sub_code').Text);
if inChild.ChildNodes.FindNode('subject') <> nil then
subject := Trim(inChild.ChildNodes.FindNode('subject').Text);
inSubChild := GetCurrXmlNode(inChild,'task_list');
if inSubChild.ChildNodes.FindNode('param_info') <> nil then
param_info := Trim(inSubChild.ChildNodes.FindNode('param_info').Text);
if inSubChild.ChildNodes.FindNode('dict_info') <> nil then
dict_info := Trim(inSubChild.ChildNodes.FindNode('dict_info').Text);
if inSubChild.ChildNodes.FindNode('items_info') <> nil then
items_info := Trim(inSubChild.ChildNodes.FindNode('items_info').Text);
if inSubChild.ChildNodes.FindNode('coach_info') <> nil then //添加教练信息获取过程
coach_info := Trim(inSubChild.ChildNodes.FindNode('coach_info').Text);
case optype of
1:
begin
if param_info = '1' then
begin
outChildList := GetCurrXmlNode(outChild,'param_list',xt_outXml);
strSQL := Format('select param_name,param_type,param_value,display_name,'+
'param_grade from cfg_param '+
'where (subsys_id=%s or subsys_id=0) and IS_ADMIN_PARAM=0 '+
'order by param_name',[QuotedStr(sub_code)]);
BuildParam(outChildList,pubQuery,strSQL);
end;
if dict_info = '1' then
begin
outChildList := GetCurrXmlNode(outChild,'dict_list',xt_outXml);
strSQL := 'select cdd.dict_type,cd.dict_name as type_name,cdd.dict_code,cdd.dict_name,cdd.view_index '+
'from cfg_dict cd '+
'left join cfg_dict cdd on cd.dict_code = cdd.dict_type '+
'where cd.dict_type=-1 and cdd.dict_type<>0 and cdd.dict_type<3000 '+
'order by cdd.dict_type, cdd.view_index asc';
BuildDict(outChildList,pubQuery,strSQL);
end;
if items_info = '1' then
begin
outChildList := GetCurrXmlNode(outChild,'items_list',xt_outXml);
strSQL := Format('select (case ci.parent_code when ''10000'' then ci.parent_code '+
'when ''30000'' then ci.parent_code else ci.item_code end) as exam_code,'+
'(case ci.parent_code when ''10000'' then ''科二通用评判'' '+
'when ''30000'' then ''科三通用评判'' else ci.item_name end) as exam_name,'+
'cii.item_code as deduct_code,cii.item_name as deduct_name,cii.deduct_score '+
'from cfg_items ci '+
'left join cfg_items cii on ci.item_code=cii.parent_code '+
'where ci.grade=2 and ci.subject=%s '+
'order by cii.parent_code, cii.item_code asc',[QuotedStr(subject)]);
BuildItems(outChildList,pubQuery,strSQL);
end;
//添加获取教练信息处理流程
if coach_info = '1' then
begin
outChildList := GetCurrXmlNode(outChild,'coach_list',xt_outXml);
//获取教练信息
strSQL := 'select idnumber, user_name, fingerprint1 from sys_user where role_id=(select id from sys_role where name=''教练员'')';//教练信息获取的数据库查询语句
BuildCoach(outChildList,pubQuery,strSQL);
end;
end;
else
begin
UpdateResult(outChildResult,'1',Format('操作类型不符:%d',[optype]));
Exit;
end;
end;
UpdateResult(outChildResult,'0','成功');
end else
begin
UpdateResult(outChildResult,'1','请求信息缺失');
Exit;
end;
end;
function TDM._1001_XMLEvent(inXmldoc: IXMLDocument;
var outXMLDoc: IXMLDocument): Integer;
var
inRoot, inChild: IXMLNode;
outRoot, outChild, outChildResult, outChildList, outTmpChild, outSubTmpChild: IXMLNode;
optype, i: Integer;
subject, car_ip, colNameStr, strSQL, Previous_id, mapStr: string;
mapbuf : TMemoryStream;
begin
Result := 0;
outRoot := outXMLDoc.ChildNodes.FindNode('root');
outChildResult := GetCurrXmlNode(outRoot,'result',xt_outXml);
outChild := GetCurrXmlNode(outRoot,'info',xt_outXml);
inRoot := inXMLDoc.ChildNodes.FindNode('root');
try
optype := StrToInt(Trim(inRoot.ChildNodes['optype'].Text));
except
UpdateResult(outChildResult,'1','操作类型异常');
Exit;
end;
inChild := GetCurrXmlNode(inRoot,'info');
if inChild <> nil then
begin
mapbuf := TMemoryStream.Create;
try
if inChild.ChildNodes.FindNode('subject') <> nil then
subject := Trim(inChild.ChildNodes.FindNode('subject').Text);
if inChild.ChildNodes.FindNode('car_ip') <> nil then
car_ip := Trim(inChild.ChildNodes.FindNode('car_ip').Text);
case optype of
1:
begin
outChildList := GetCurrXmlNode(outChild,'map_list',xt_outXml);
Previous_id := '';
strSQL := Format('select cm.id,cm.subject,cm.driver_license_type,cm.exam_item as exam_code,cm.mapnumber,'+
'cm.name as mapname,cm.map,vi.ip as video_ip,vi.port as video_port, '+
'vi.vuser as video_user,vi.password as video_password,vi.device_id '+
'from cfg_maps cm '+
'left join cfg_video vi on trim(vi.item)=to_char(cm.id) and cm.subject=vi.subject and vi.ascription=''M'' '+
'where cm.subject=%s order by cm.id asc', [QuotedStr(subject)]);
ExecSql(pubQuery,strSQL);
pubQuery.First;
while not pubQuery.Eof do
begin
if Previous_id <> Trim(pubQuery.Fields[0].AsString) then
begin
outTmpChild := outChildList.AddChild('map');
Previous_id := Trim(pubQuery.Fields[0].AsString);
for i := 1 to 6 do
begin
colNameStr := LowerCase(pubQuery.Fields[i].FieldName);
outTmpChild.AddChild(colNameStr);
if colNameStr = LowerCase('MAP') then
begin
mapbuf.Clear;
mapStr := '';
TBlobField(pubQuery.FieldByName('MAP')).SaveToStream(mapbuf);
Base64Enc(mapbuf, mapStr, mapbuf.Size);
outTmpChild.ChildValues[colNameStr] := mapStr;
end
else
outTmpChild.ChildValues[colNameStr] := Trim(pubQuery.Fields[i].AsString);
end;
end;
outSubTmpChild := outTmpChild.AddChild('video_list');
for i := 7 to pubQuery.FieldCount - 1 do
begin
colNameStr := LowerCase(pubQuery.Fields[i].FieldName);
outSubTmpChild.AddChild(colNameStr);
outSubTmpChild.ChildValues[colNameStr] := Trim(pubQuery.Fields[i].AsString);
end;
pubQuery.Next;
end;
end;
2:
begin
outTmpChild := GetCurrXmlNode(outChild,'car',xt_outXml);
Previous_id := '';
strSQL := Format('select bc.id as car_id,bc.license_plate,bc.qualified_car_type,bc.car_map,vi.ip as video_ip,'+
'vi.port as video_port,vi.vuser as video_user, vi.password as video_password '+
'from bas_car bc '+
'left join cfg_video vi on Trim(bc.id)=Trim(vi.item) and bc.subject=vi.subject and vi.ascription=''C'' '+
'where bc.car_ip=%s and bc.subject=%s and bc.USE_STATUS=''A'' and bc.CAR_STATUS=''A'' order by bc.id asc',
[QuotedStr(car_ip),QuotedStr(subject)]);
ExecSql(pubQuery,strSQL);
if pubQuery.RecordCount = 0 then
begin
UpdateResult(outChildResult,'1',Format('无[%s]的车辆信息或该车辆已停止使用',[car_ip]));
Exit;
end;
pubQuery.First;
while not pubQuery.Eof do
begin
if Previous_id <> Trim(pubQuery.Fields[0].AsString) then
begin
Previous_id := Trim(pubQuery.Fields[0].AsString);
for i := 0 to 3 do
begin
colNameStr := LowerCase(pubQuery.Fields[i].FieldName);
outTmpChild.AddChild(colNameStr);
if colNameStr = LowerCase('CAR_MAP') then
begin
mapbuf.Clear;
mapStr := '';
TBlobField(pubQuery.FieldByName('CAR_MAP')).SaveToStream(mapbuf);
Base64Enc(mapbuf, mapStr, mapbuf.Size);
outTmpChild.ChildValues[colNameStr] := mapStr;
end
else
outTmpChild.ChildValues[colNameStr] := Trim(pubQuery.Fields[i].AsString);
end;
end;
outSubTmpChild := outTmpChild.AddChild('video_list');
for i := 4 to pubQuery.FieldCount - 1 do
begin
colNameStr := LowerCase(pubQuery.Fields[i].FieldName);
outSubTmpChild.AddChild(colNameStr);
outSubTmpChild.ChildValues[colNameStr] := Trim(pubQuery.Fields[i].AsString);
end;
pubQuery.Next;
end;
end;
else
begin
UpdateResult(outChildResult,'1',Format('操作类型不符:%d',[optype]));
Exit;
end;
end;
UpdateResult(outChildResult,'0','成功');
finally
mapbuf.Free;
end;
end else
begin
UpdateResult(outChildResult,'1','请求信息缺失');
Exit;
end;
end;
function TDM._1002_XMLEvent(inXmldoc: IXMLDocument;
var outXMLDoc: IXMLDocument): Integer;
var
inRoot, inChild: IXMLNode;
outRoot, outChild, outChildResult: IXMLNode;
optype, i: Integer;
license_plate, colNameStr, strSQL: string;
begin
Result := 0;
outRoot := outXMLDoc.ChildNodes.FindNode('root');
outChildResult := GetCurrXmlNode(outRoot,'result',xt_outXml);
outChild := GetCurrXmlNode(outRoot,'info',xt_outXml);
inRoot := inXMLDoc.ChildNodes.FindNode('root');
try
optype := StrToInt(Trim(inRoot.ChildNodes['optype'].Text));
except
UpdateResult(outChildResult,'1','操作类型异常');
Exit;
end;
inChild := GetCurrXmlNode(inRoot,'info');
if inChild <> nil then
begin
if inChild.ChildNodes.FindNode('license_plate') <> nil then
license_plate := Trim(inChild.ChildNodes.FindNode('license_plate').Text);
case optype of
1:
begin
strSQL := Format('select bs.id as student_id, bs.idnumber as student_idnumber, bgd.grouping_id '+
'from bas_grouping bg '+
'left join bas_grouping_detail bgd on bgd.grouping_id=bg.id '+
'left join BAS_BOOKING bb on bb.student_id=bgd.student_id and bb.booking_exam_date=to_char(sysdate,''YYYYMMDD'') '+
'left join bas_student bs on bs.id=bgd.student_id '+
'left join bas_car bc on bc.id=bg.car_id '+
'where bc.license_plate=%s and bgd.queue_status=''1'' '+
'and bb.sign_status=''1'' and bb.EXAM_STATUS = ''0'' and rownum=1 '+
'order by bgd.queue_order asc',
[QuotedStr(license_plate)]);
ExecSql(pubQuery,strSQL);
if pubQuery.RecordCount = 1 then
begin
for I := 0 to pubQuery.FieldCount - 1 do
begin
colNameStr := LowerCase(pubQuery.Fields[i].FieldName);
outChild.AddChild(colNameStr);
outChild.ChildValues[colNameStr] := Trim(pubQuery.Fields[i].AsString);
end;
end
else
begin
UpdateResult(outChildResult,'1',Format('无备考学员信息',[optype]));
Exit;
end;
end;
else
begin
UpdateResult(outChildResult,'1',Format('操作类型不符:%d',[optype]));
Exit;
end;
end;
UpdateResult(outChildResult,'0','成功');
end else
begin
UpdateResult(outChildResult,'1','请求信息缺失');
Exit;
end;
end;
function TDM._1003_XMLEvent(inXmldoc: IXMLDocument;
var outXMLDoc: IXMLDocument): Integer;
var
inRoot, inChild: IXMLNode;
outRoot, outChild, outChildResult, outChildList: IXMLNode;
optype, i: Integer;
student_idnumber, license_plate, is_grouping, grouping_id: string;
password, colNameStr, strSQL, driver_license_type: string;
begin
Result := 0;
outRoot := outXMLDoc.ChildNodes.FindNode('root');
outChildResult := GetCurrXmlNode(outRoot,'result',xt_outXml);
outChild := GetCurrXmlNode(outRoot,'info',xt_outXml);
inRoot := inXMLDoc.ChildNodes.FindNode('root');
try
optype := StrToInt(Trim(inRoot.ChildNodes['optype'].Text));
except
UpdateResult(outChildResult,'1','操作类型异常');
Exit;
end;
inChild := GetCurrXmlNode(inRoot,'info');
if inChild <> nil then
begin
if inChild.ChildNodes.FindNode('student_idnumber') <> nil then
student_idnumber := Trim(inChild.ChildNodes.FindNode('student_idnumber').Text);
if inChild.ChildNodes.FindNode('driver_license_type') <> nil then
driver_license_type := Trim(inChild.ChildNodes.FindNode('driver_license_type').Text);
if inChild.ChildNodes.FindNode('is_grouping') <> nil then
is_grouping := Trim(inChild.ChildNodes.FindNode('is_grouping').Text);
if inChild.ChildNodes.FindNode('grouping_id') <> nil then
grouping_id := Trim(inChild.ChildNodes.FindNode('grouping_id').Text);
if inChild.ChildNodes.FindNode('license_plate') <> nil then
license_plate := Trim(inChild.ChildNodes.FindNode('license_plate').Text);
if inChild.ChildNodes.FindNode('password') <> nil then
password := Trim(inChild.ChildNodes.FindNode('password').Text);
case optype of
1:
begin
outChildList := GetCurrXmlNode(outChild,'finger_list',xt_outXml);
if is_grouping = '0' then
//无考试安排
strSQL := Format('select bs.DRIVER_LICENSE_TYPE,bs.id as student_id, bs.fingerprint1, bs.fingerprint2,'+
'bs.fingerprint3, bs.fingerprint4 '+
'from bas_student bs '+
'where bs.idnumber = %s ',[QuotedStr(student_idnumber)])
else if is_grouping = '1' then
//有考试安排
strSQL := Format('select bs.id as student_id, bs.fingerprint1, bs.fingerprint2,'+
'bs.fingerprint3, bs.fingerprint4 '+
'from bas_booking bb '+
'left join bas_student bs on bs.id=bb.student_id '+
'left join bas_grouping_detail bgd on bgd.student_id=bs.id '+
'left join bas_grouping bg on bg.id=bgd.grouping_id '+
'left join bas_car bc on bc.id=bg.car_id '+
'where bb.booking_exam_date=to_char(sysdate,''yyyymmdd'') '+
'and bs.idnumber=%s and bc.license_plate=%s and bg.id=%s ',
[QuotedStr(student_idnumber),QuotedStr(license_plate),QuotedStr(grouping_id)])
else
begin
UpdateResult(outChildResult,'1',Format('备考学员是否分组情况不明',[optype]));
Exit;
end;
ExecSql(pubQuery,strSQL);
if pubQuery.RecordCount = 1 then
begin
if driver_license_type <> Trim(pubQuery.Fields[0].AsString) then
begin
UpdateResult(outChildResult,'1',Format('该学员准驾车型[%s]与当前车辆[%s]不符',
[Trim(pubQuery.Fields[0].AsString),driver_license_type]));
Exit;
end;
for I := 1 to pubQuery.FieldCount - 1 do
begin
colNameStr := LowerCase(pubQuery.Fields[i].FieldName);
if colNameStr = LowerCase('student_id') then
begin
outChild.AddChild(colNameStr);
outChild.ChildNodes[colNameStr].Text := Trim(pubQuery.Fields[i].AsString);
end else
begin
outChildList.AddChild('finger');
outChildList.ChildValues['finger'] := Trim(pubQuery.Fields[i].AsString);
end;
end;
end
else
begin
UpdateResult(outChildResult,'1',Format('学员信息不存在',[optype]));
Exit;
end;
end;
2:
begin
if password = '' then
begin
UpdateResult(outChildResult,'1',Format('密码为空',[optype]));
Exit;
end;
strSQL := Format('select bs.id as student_id, bs.idnumber, bs.password '+
'from bas_student bs '+
'where bs.idnumber=%s',[QuotedStr(student_idnumber)]);
ExecSql(pubQuery,strSQL);
if pubQuery.RecordCount > 0 then
begin
if Trim(pubQuery.FieldByName('password').AsString) <> password then //todo:这里需要进行加解密操作
begin
UpdateResult(outChildResult,'1',Format('密码错误',[optype]));
Exit;
end;
outChild.AddChild('student_id');
outChild.ChildValues['student_id'] := Trim(pubQuery.FieldByName('student_id').AsString);
end else
begin
UpdateResult(outChildResult,'1',Format('学员信息不存在',[optype]));
Exit;
end;
end;
else
begin
UpdateResult(outChildResult,'1',Format('操作类型不符:%d',[optype]));
Exit;
end;
end;
UpdateResult(outChildResult,'0','成功');
end else
begin
UpdateResult(outChildResult,'1','请求信息缺失');
Exit;
end;
end;