AX2012 查询用户在线操作记录

 

 1 static void ExportSysClientAccessLog(Args _args)
 2 {
 3     SysClientAccessLog          sysClientAccessLog;
 4 
 5     SysExcelApplication         xlsApplication;
 6     SysExcelWorkBooks           xlsWorkBookCollection;
 7     SysExcelWorkBook            xlsWorkBook;
 8     SysExcelWorkSheets          xlsWorkSheetCollection;
 9     SysExcelWorkSheet           xlsWorkSheet;
10     SysExcelRange               xlsRange;
11 
12     int                         row = 1, idx;
13     str                         fileName, formName;
14     container                   con, conSel;
15     ;
16 
17     fileName = @"C:\Users\currentUserFileName\Desktop\log\userAccessLog.csv";    
18 
19     xlsApplication           = SysExcelApplication::construct();
20     xlsWorkBookCollection    = xlsApplication.workbooks();
21     xlsWorkBook              = xlsWorkBookCollection.add();
22     xlsWorkSheetCollection   = xlsWorkBook.worksheets();
23     xlsWorkSheet             = xlsWorkSheetCollection.itemFromNum(1);
24 
25     xlsWorkSheet.cells().item(row, 1).value("User Id");
26     xlsWorkSheet.cells().item(row, 2).value("Form Name");
27     xlsWorkSheet.cells().item(row, 3).value("Operation");
28     xlsWorkSheet.cells().item(row, 4).value("DateTime");
29 
30     row++;
31     
32     while select sysClientAccessLog
33         where sysClientAccessLog.createdDateTime > 2023-02-14T03:00:00
34            && sysClientAccessLog.createdDateTime < 2023-02-15T00:00:00
35            && sysClientAccessLog.createdBy == 'admin' // UserName
36     {
37         con = sysClientAccessLog.EventsContainer;
38 
39         for(idx = 1; idx <= conLen(con); idx++)
40         {
41             conSel = conpeek(con, idx);
42             formName = formName2Pname(conPeek(conSel, 1));
43             //Information to Excel
44             xlsWorkSheet.cells().item(row, 1).value(strFmt("%1", sysClientAccessLog.createdBy));
45             xlsWorkSheet.cells().item(row, 2).value(strFmt("%1", formName ? formName : conPeek(conSel, 1)));
46             xlsWorkSheet.cells().item(row, 3).value(strFmt("%1", conPeek(conSel, 2)));  
47             xlsWorkSheet.cells().item(row, 4).value(strFmt("%1", DateTimeUtil::applyTimeZoneOffset(sysClientAccessLog.createdDateTime, DateTimeUtil::getUserPreferredTimeZone())));
48 
49             row++;
50         }
51     }
52 
53 
54     if(WinApi::fileExists(fileName))
55         WinApi::deleteFile(fileName);
56 
57     xlsWorkbook.saveAs(fileName);
58     xlsApplication.visible(true);
59 
60     info(strFmt("File has been exported"));
61 }

 

posted @ 2023-02-15 16:31  一口一个小馒头  阅读(29)  评论(0编辑  收藏  举报