Последний статус оператора — различия между версиями
Материал из Oktell
Строка 27: | Строка 27: | ||
<pre> | <pre> | ||
if exists ( select * from tempdb..sysobjects where id=OBJECT_ID ( 'tempdb..#u_cur_state' )) | if exists ( select * from tempdb..sysobjects where id=OBJECT_ID ( 'tempdb..#u_cur_state' )) | ||
− | Drop table #u_cur_state | + | Drop table #u_cur_state |
+ | |||
SELECT UserId, max(TimeChange) TimeChange | SELECT UserId, max(TimeChange) TimeChange | ||
into #u_cur_state | into #u_cur_state | ||
FROM oktell.dbo.A_UserStateHistory | FROM oktell.dbo.A_UserStateHistory | ||
− | + | GROUP BY UserId | |
+ | |||
select a.name as "Имя", | select a.name as "Имя", | ||
− | + | a.state as "Код состояния", | |
− | + | CASE WHEN a.state = 1 THEN 'Готов' | |
− | + | WHEN a.state = 2 THEN 'Перерыв' | |
− | + | WHEN a.state in (5,6) THEN 'Занят' | |
− | + | WHEN a.state = 0 THEN 'Отключен' | |
− | + | WHEN a.state = 3 THEN 'Нет на месте' | |
− | + | WHEN a.state = 7 THEN 'Без телефона' | |
− | + | end as "Состояние" , | |
− | + | a.grname as "Отдел" | |
from( | from( | ||
− | + | select au.name as "name", | |
− | + | (select top 1 h.state | |
− | + | from oktell.dbo.A_UserStateHistory as h | |
− | + | where h.UserId = ucs1.UserId AND h.TimeChange = ucs1.TimeChange | |
− | + | ) as "state", | |
− | + | ag.name as "grname" | |
− | + | from #u_cur_state as ucs1 | |
− | + | join oktell.dbo.a_users as au on ucs1.userid=au.id | |
− | + | left join oktell_settings.dbo.a_groups ag on au.parentgroupid=ag.id | |
− | + | /*where ucs1.userid in (select * from @users) | |
− | + | and au.parentgroupid in (select * from @groups)*/ | |
− | )a | + | )a |
order by a.grname | order by a.grname | ||
</pre> | </pre> |
Текущая версия на 09:13, 18 июня 2015
1)Запрос возвращает текущие статусы операторов и время, когда этот статус был назначен. В запросе имеется закомментированная строка для фильтрации данных по конкретной задаче.
SELECT u.id ,u.NAME ,h.state ,h.TimeChange FROM A_Users u LEFT JOIN (SELECT h.* FROM ( SELECT UserId, max(TimeChange) TimeChange FROM A_UserStateHistory GROUP BY UserId ) t JOIN A_UserStateHistory h ON t.UserId = h.UserId AND h.TimeChange = t.TimeChange ) h ON h.UserId = u.Id WHERE u.id IN ( SELECT OperatorId FROM [oktell_settings].[dbo].[A_TaskManager_Operators] -- where TaskId='25130D79-8766-4EAD-9C22-596CF2B465F9' )
2)Вторая версия запроса, с фильтром по отделам и пользователям (данные фильтры закомментированы)
if exists ( select * from tempdb..sysobjects where id=OBJECT_ID ( 'tempdb..#u_cur_state' )) Drop table #u_cur_state SELECT UserId, max(TimeChange) TimeChange into #u_cur_state FROM oktell.dbo.A_UserStateHistory GROUP BY UserId select a.name as "Имя", a.state as "Код состояния", CASE WHEN a.state = 1 THEN 'Готов' WHEN a.state = 2 THEN 'Перерыв' WHEN a.state in (5,6) THEN 'Занят' WHEN a.state = 0 THEN 'Отключен' WHEN a.state = 3 THEN 'Нет на месте' WHEN a.state = 7 THEN 'Без телефона' end as "Состояние" , a.grname as "Отдел" from( select au.name as "name", (select top 1 h.state from oktell.dbo.A_UserStateHistory as h where h.UserId = ucs1.UserId AND h.TimeChange = ucs1.TimeChange ) as "state", ag.name as "grname" from #u_cur_state as ucs1 join oktell.dbo.a_users as au on ucs1.userid=au.id left join oktell_settings.dbo.a_groups ag on au.parentgroupid=ag.id /*where ucs1.userid in (select * from @users) and au.parentgroupid in (select * from @groups)*/ )a order by a.grname