DocumentUsageReportQueries.xml
4.98 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
<?xml version="1.0" encoding="utf-8"?>
<queries>
<query key="CreateEmployeeTable">
<mssql><![CDATA[CREATE TABLE {0}
(ReportSessionId varchar(256) NOT NULL,
EmployeeId int NOT NULL,
Employee nvarchar(max) NOT NULL,
JobTitle nvarchar(max) NULL,
Department nvarchar(max) NOT NULL)]]></mssql>
<postgres><![CDATA[CREATE TABLE {0}
(ReportSessionId varchar NOT NULL,
EmployeeId int NOT NULL,
Employee varchar NOT NULL,
JobTitle varchar NULL,
Department varchar NOT NULL)]]></postgres>
</query>
<query key="InsertIntoEmployeeTable">
<default><![CDATA[INSERT INTO {0} (ReportSessionId, EmployeeId, Employee, JobTitle, Department)
select
'{1}',
emp.Id,
emp.Name,
pos.Name,
dep.Name
from
Sungero_Core_Recipient emp
join Sungero_Core_Recipient dep on
emp.Department_Company_Sungero = dep.Id
left join Sungero_Company_JobTitle pos on
emp.JobTitle_Company_Sungero = pos.Id
where
emp.Discriminator = 'b7905516-2be5-4931-961c-cb38d5677565'
and emp.Status = 'Active'
and emp.Login is not null
and ({2} = 0 or emp.Department_Company_Sungero = {2})]]></default>
</query>
<query key="CreateHistoryTable">
<mssql><![CDATA[CREATE TABLE {0}
(ReportSessionId varchar(256) NOT NULL,
EmployeeId int NOT NULL,
EntityId int NOT NULL,
ActionType nvarchar(6) NULL)]]></mssql>
<postgres><![CDATA[CREATE TABLE {0}
(ReportSessionId varchar NOT NULL,
EmployeeId int NOT NULL,
EntityId int NOT NULL,
ActionType varchar NULL)]]></postgres>
</query>
<query key="InsertIntoHistoryTable">
<mssql><![CDATA[SET DATEFORMAT DMY
INSERT INTO {0} (ReportSessionId, EmployeeId, EntityId, ActionType)
select
distinct '{1}',
-- если писать User и Action без [] то будет падать.
h.[User],
EntityId,
case
when [Action] = 'Create'
then 'Create'
when [Action] = 'Update' and (Operation = 'UpdateVerBody' or Operation = 'CreateVersion')
then 'Update'
when [Action] = 'Read' and Operation = 'ReadVerBody'
then 'Read'
end
from
Sungero_Content_DocHistory h
where
EntityId <> 0
and [Action] in ('Create', 'Update', 'Read')
and HistoryDate between '{2}' and '{3}']]></mssql>
<postgres><![CDATA[INSERT INTO {0} (ReportSessionId, EmployeeId, EntityId, ActionType)
select
distinct '{1}',
-- если писать user без "" или без алиаса таблицы, то запрос будет падать так как написание user(или User) в postgre выводит в результат имя текущего пользователя, работающего с БД
h.user,
EntityId,
case
when Action = 'Create'
then 'Create'
when Action = 'Update' and (Operation = 'UpdateVerBody' or Operation = 'CreateVersion')
then 'Update'
when Action = 'Read' and Operation = 'ReadVerBody'
then 'Read'
end
from
Sungero_Content_DocHistory h
where
EntityId <> 0
and Action in ('Create', 'Update', 'Read')
and HistoryDate between '{2}' and '{3}']]></postgres>
</query>
<query key="ResultQuery">
<mssql><![CDATA[select
emp.Employee,
emp.JobTitle,
emp.Department,
ISNULL(SUM(case when his.ActionType = 'Create' then 1 else 0 end), 0) as Created,
ISNULL(SUM(case when his.ActionType = 'Update' then 1 else 0 end), 0) as Updated,
ISNULL(SUM(case when his.ActionType = 'Read' then 1 else 0 end), 0) as Readed
from dbo.Sungero_Reports_DocumentUsageReport_Employees emp
left join dbo.Sungero_Reports_DocumentUsageReport_History his on
emp.EmployeeId = his.EmployeeId and
emp.ReportSessionId = his.ReportSessionId and
his.ActionType is not null
where emp.ReportSessionId = @ReportSessionId
group by
emp.Employee, emp.JobTitle, emp.Department
order by
ISNULL(SUM(case when his.ActionType = 'Create' then 1 else 0 end), 0) +
ISNULL(SUM(case when his.ActionType = 'Update' then 1 else 0 end), 0) +
ISNULL(SUM(case when his.ActionType = 'Read' then 1 else 0 end), 0),
emp.Department, emp.Employee]]></mssql>
<postgres><![CDATA[select
emp.Employee,
emp.JobTitle,
emp.Department,
COALESCE(SUM(case when his.ActionType = 'Create' then 1 else 0 end), 0) as Created,
COALESCE(SUM(case when his.ActionType = 'Update' then 1 else 0 end), 0) as Updated,
COALESCE(SUM(case when his.ActionType = 'Read' then 1 else 0 end), 0) as Readed
from Sungero_Reports_DocumentUsageReport_Employees emp
left join Sungero_Reports_DocumentUsageReport_History his on
emp.EmployeeId = his.EmployeeId and
emp.ReportSessionId = his.ReportSessionId and
his.ActionType is not null
where emp.ReportSessionId = @ReportSessionId
group by
emp.Employee, emp.JobTitle, emp.Department
order by
COALESCE(SUM(case when his.ActionType = 'Create' then 1 else 0 end), 0) +
COALESCE(SUM(case when his.ActionType = 'Update' then 1 else 0 end), 0) +
COALESCE(SUM(case when his.ActionType = 'Read' then 1 else 0 end), 0),
emp.Department, emp.Employee]]></postgres>
</query>
</queries>