WorkAkkaunt

Gett taxi

Jul 1st, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 10.31 KB | None | 0 0
  1. /*declare @DateStart datetime
  2. declare @DateEnd datetime;
  3. declare @TimeStart datetime;
  4. declare @TimeEnd datetime;
  5.  
  6. set @DateStart = '20180821 00:00:00.000'
  7. set @DateEnd = '20180821 23:59:00.000'
  8. set @TimeStart = '19000101 00:00:00.000'
  9. set @TimeEnd = '19000101 23:59:00.000'
  10. declare @tasks table (id uniqueidentifier)
  11. declare @opers table ( id uniqueidentifier)
  12. insert into @opers
  13. select distinct id from oktell.dbo.A_Users
  14. insert into @tasks
  15. select id from oktell.dbo.A_TaskManager_Tasks --where name ='B2D Premium'
  16. declare @type int = 0*/
  17.  
  18.     declare @olp_dialog table (idchain uniqueidentifier, datewrite datetime ,callerid nvarchar(50),idtask uniqueidentifier,operator nvarchar(100),casy_type nvarchar(max),sub_type nvarchar(max),sub_3 nvarchar(max))
  19.    
  20.     --insert into @olp_dialog
  21.     select od.IdChain,datewrite, callerID,od.idtask,Operator,Casy_type,Sub_type,Sub_3
  22.     into #dialogtabletemp
  23.     from oktell..Olp_dialog od
  24.     --left join oktell.dbo.A_Users au on au.name=od.Operator Старый джойн, возможно пригодится, заменен на eff
  25.     left join oktell_cc_temp.dbo.A_Cube_CC_EffortConnections eff with (nolock) on eff.IdChain=od.IdChain
  26.     where od.DateWrite between @DateStart and @DateEnd
  27. and
  28.     CAST(cast(od.DateWrite as time)AS datetime) between @TimeStart and @TimeEnd
  29.     and od.idtask in (select id from @tasks)
  30.     --and au.ID in (select id from @opers)
  31.     and eff.IdOperator in (select id from @opers)
  32.     and CallResult !=6 -- строка добавлена по AI-11600 14.11.2018, раньше было без нее
  33.  
  34.     --insert into @olp_dialog
  35.     select distinct IdChain
  36.     ,(select top 1 DateWrite from #dialogtabletemp dd2 where dd2.IdChain=dd1.IdChain order by DateWrite) DateWrite
  37.     ,CallerID
  38.     ,(select top 1 idtask from #dialogtabletemp dd2 where dd2.IdChain=dd1.IdChain order by DateWrite desc) idtask
  39.     ,Operator
  40.     ,Casy_type
  41.     ,Sub_type
  42.     ,Sub_3
  43.     into #olp_dialog_report
  44.     from #dialogtabletemp dd1
  45.  
  46.     drop table #dialogtabletemp
  47.  
  48.     declare @final table (idchain uniqueidentifier,datewrite datetime ,callerid nvarchar(50),idtask uniqueidentifier,operator nvarchar(100),casy_type nvarchar(max),sub_type nvarchar(max),sub_3 nvarchar(max),mark int,post int)
  49.     insert into @final
  50.     select distinct od.idchain
  51.     ,isnull((select top 1  datewrite from #olp_dialog_report where IdChain=od.IdChain order by datewrite asc),(select top 1  datewrite from #olp_dialog_report where IdChain=od.IdChain order by datewrite desc))
  52.     ,isnull((select top 1  CallerID from #olp_dialog_report where IdChain=od.IdChain order by datewrite asc),(select top 1  CallerID from #olp_dialog_report where IdChain=od.IdChain order by datewrite desc))
  53.     ,isnull((select top 1  idtask from #olp_dialog_report where IdChain=od.IdChain order by datewrite asc),(select top 1  idtask from #olp_dialog_report where IdChain=od.IdChain order by datewrite desc))
  54.     ,isnull((select top 1  Operator from #olp_dialog_report where IdChain=od.IdChain order by datewrite asc ),(select top 1  Operator from #olp_dialog_report where IdChain=od.IdChain order by datewrite desc ))
  55.     ,isnull((select top 1  Casy_type from #olp_dialog_report where IdChain=od.IdChain order by datewrite asc),(select top 1  Casy_type from #olp_dialog_report where IdChain=od.IdChain order by datewrite desc))
  56.     ,isnull((select top 1  Sub_type from #olp_dialog_report where IdChain=od.IdChain order by datewrite asc),(select top 1  Sub_type from #olp_dialog_report where IdChain=od.IdChain order by datewrite desc))
  57.     ,isnull((select top 1  Sub_3 from #olp_dialog_report where IdChain=od.IdChain order by datewrite asc),(select top 1  Sub_3 from #olp_dialog_report where IdChain=od.IdChain order by datewrite desc))
  58.     ,(select  top 1 mark from oktell.dbo.tbl_MARK where idhcain=od.IdChain)[Mark]
  59.     ,null
  60.         --case
  61.         --  when
  62.         --  (
  63.         --  select sum(lentime) from oktell_cc_temp.[dbo].[A_Cube_CC_OperatorStates] where state=7 and idoperator=eff.IdOperator and ideffort in(select distinct ideffort from oktell_cc_temp.dbo.A_Cube_CC_EffortConnections where idchain=od.IdChain)
  64.         --  )>41
  65.         --then
  66.         --  (select datediff(SECOND,(select top 1 datetimestop from oktell_cc_temp.dbo.A_Cube_CC_EffortConnections with (nolock) where IdOperator = eff.IdOperator and idchain=od.IdChain order by datetimestop desc),(select max(DateTimeStop) from oktell_cc_temp.[dbo].[A_Cube_CC_OperatorStates] where state=7 and idoperator=eff.IdOperator and ideffort in(select distinct ideffort from oktell_cc_temp.dbo.A_Cube_CC_EffortConnections where idchain=od.IdChain))))
  67.         --else
  68.         --  (
  69.         --  select sum(lentime) from oktell_cc_temp.[dbo].[A_Cube_CC_OperatorStates] where state=7 and idoperator=eff.IdOperator and ideffort in(select distinct ideffort from oktell_cc_temp.dbo.A_Cube_CC_EffortConnections where idchain=od.IdChain)
  70.         --  )
  71.         --end
  72.    
  73. from #olp_dialog_report od
  74.     left join oktell.dbo.A_Users au on au.name=od.Operator
  75.     --left join oktell_cc_temp.dbo.A_Cube_CC_EffortConnections eff with (nolock) on eff.IdChain=od.IdChain 
  76.     where od.DateWrite between @DateStart and @DateEnd
  77. and
  78.     CAST(cast(od.DateWrite as time)AS datetime) between @TimeStart and @TimeEnd
  79.     and od.idtask in (select id from @tasks)
  80.     --and eff.IdOperator in (select id from @opers)
  81.     and au.ID in (select id from @opers)
  82.  
  83. drop table #olp_dialog_report
  84.  
  85.  
  86. update @final
  87. set post = (
  88. case
  89.             when
  90.             (
  91.             select sum(lentime) from oktell_cc_temp.[dbo].[A_Cube_CC_OperatorStates] where state=7 and idoperator=au.ID and ideffort in(select distinct ideffort from oktell_cc_temp.dbo.A_Cube_CC_EffortConnections where idchain=t.idchain)
  92.             )>41
  93.         then
  94.             (select datediff(SECOND,(select top 1 datetimestop from oktell_cc_temp.dbo.A_Cube_CC_EffortConnections with (nolock) where IdOperator = au.ID and idchain=t.idchain order by datetimestop desc),(select max(DateTimeStop) from oktell_cc_temp.[dbo].[A_Cube_CC_OperatorStates] where state=7 and idoperator=au.ID and ideffort in(select distinct ideffort from oktell_cc_temp.dbo.A_Cube_CC_EffortConnections where idchain=t.idchain))))
  95.         else
  96.             (
  97.             select sum(lentime) from oktell_cc_temp.[dbo].[A_Cube_CC_OperatorStates] where state=7 and idoperator=au.ID and ideffort in(select distinct ideffort from oktell_cc_temp.dbo.A_Cube_CC_EffortConnections where idchain=t.idchain)
  98.             )
  99.         end
  100. )
  101. from @final t
  102. left join oktell.dbo.a_users au on au.Name = t.operator
  103.  
  104.  
  105.  
  106.     if(@type=1 and (@AbonentNumber='' or @AbonentNumber is null))
  107.     begin
  108.     select datewrite [Дата, Время],callerid[Номер абонента],tsk.Name[Задача],operator[Оператор],casy_type,sub_type,sub_3,mark[Оценка],cast(dateadd(ss,post,'00:00')  as time(0)) post
  109. ,'http://gett.oktell.olp.site:4055/download/byscript?name=Test_voice&startparam1='+cast(idchain as nvarchar(50))+'&async=0&timeout=10' [Ссылка на запись]
  110.  from @final od
  111.     left join oktell.dbo.A_TaskManager_Tasks tsk on tsk.id=od.idtask
  112.     order by Оператор
  113.     end
  114. if((@type=0 or @type is null) and ( @AbonentNumber='' or @AbonentNumber is null))
  115.     begin
  116.     select datewrite [Дата, Время],callerid[Номер абонента],tsk.Name[Задача],operator[Оператор],casy_type,sub_type,sub_3,mark[Оценка],cast(dateadd(ss,post,'00:00') as time(0)) post
  117. ,'http://gett.oktell.olp.site:4055/download/byscript?name=Test_voice&startparam1='+cast(idchain as nvarchar(50))+'&async=0&timeout=10' [Ссылка на запись]
  118.  from @final  od
  119.     left join oktell.dbo.A_TaskManager_Tasks tsk on tsk.id=od.idtask
  120.  
  121.      where casy_type is null or casy_type=''
  122. order by datewrite
  123.     end
  124. if((@type=0 or @type is null) and ( @AbonentNumber<>'' or @AbonentNumber is not null))
  125. begin
  126. select datewrite [Дата, Время],callerid[Номер абонента],tsk.Name[Задача],operator[Оператор],casy_type,sub_type,sub_3,mark[Оценка],cast(dateadd(ss,post,'00:00') as time(0)) post
  127. ,'http://gett.oktell.olp.site:4055/download/byscript?name=Test_voice&startparam1='+cast(idchain as nvarchar(50))+'&async=0&timeout=10' [Ссылка на запись]
  128.  from @final  od
  129.     left join oktell.dbo.A_TaskManager_Tasks tsk on tsk.id=od.idtask
  130.  
  131.      where (casy_type is null or casy_type='' ) and callerid like '%'+@AbonentNumber+'%'
  132. order by datewrite
  133. end
  134. if(@type=1 and ( @AbonentNumber<>'' or @AbonentNumber is not null))
  135. begin
  136.     select datewrite [Дата, Время],callerid[Номер абонента],tsk.Name[Задача],operator[Оператор],casy_type,sub_type,sub_3,mark[Оценка],cast(dateadd(ss,post,'00:00')  as time(0)) post
  137. ,'http://gett.oktell.olp.site:4055/download/byscript?name=Test_voice&startparam1='+cast(idchain as nvarchar(50))+'&async=0&timeout=10' [Ссылка на запись]
  138.  from @final od
  139.     left join oktell.dbo.A_TaskManager_Tasks tsk on tsk.id=od.idtask
  140. where callerid like '%'+@AbonentNumber+'%'
  141. end
  142. /*select
  143. datewrite as [Дата/Время],
  144. mark as [Оценка],
  145. operator as [Оператор],
  146. sub_3 as [Комментарий],
  147. case when (post is null) then 'Нет' else 'Да' end as [Есть запись],
  148. tasks.name as [Задача],
  149. post as [Ссылка на запись]
  150. from @final as f
  151. join oktell..A_TaskManager_Tasks as tasks
  152. on f.idtask=tasks.id*/
  153. /*
  154.  
  155. declare @DateStart datetime;
  156. declare @DateEnd datetime;
  157. declare @TimeStart datetime;
  158. declare @TimeEnd datetime;
  159.  
  160. set @DateStart = '20180821 00:00:00.000'
  161. set @DateEnd = '20180821 23:59:00.000'
  162. set @TimeStart = '19000101 00:00:00.000'
  163. set @TimeEnd = '19000101 23:59:00.000'
  164. declare @tasks table (id uniqueidentifier)
  165. declare @opers table ( id uniqueidentifier)
  166. insert into @opers
  167. select distinct id from oktell.dbo.A_Users
  168. insert into @tasks
  169. select id from oktell.dbo.A_TaskManager_Tasks where name ='B2D Premium'
  170.  
  171. --- не очень хорошее решение в отношении выпадающего списка. Будет тормозить.
  172. declare @TypeClient table(id nvarchar(250), name nvarchar(250));
  173. insert into @TypeClient
  174. select distinct TypeClient, TypeClient from oktell..Olp_dialog
  175.  
  176. declare @Status table(id nvarchar(250), name nvarchar(250))
  177. insert into @Status
  178. select distinct Status, Status from oktell..Olp_dialog
  179.  
  180. declare @Solution table(id nvarchar(250), name nvarchar(250))
  181. insert into @Solution
  182. select distinct Solution, Solution from oktell..Olp_dialog
  183.  
  184. declare @subjct2 int =1
  185.  
  186. declare @Other nvarchar(250);
  187. set @Other = ''
  188.  
  189. declare @AbonentNumber nvarchar(250);
  190. set @AbonentNumber = ''
  191.  
  192.  
  193. */
Add Comment
Please, Sign In to add comment