中间件底层,websocket

proc_DataAnalysis_SQLServer.txt 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. create procedure [dbo].[proc_DataAnalysis]
  2. @nAgentID int,
  3. @nLogInID int,
  4. @BeginTime datetime,
  5. @EndTime datetime
  6. as
  7. declare @answer_ext bigint --内线应答次数
  8. declare @answer_trunk bigint --外线应答次数
  9. declare @call_in_ext bigint --内线呼入次数
  10. declare @call_in_trunk bigint --外线呼入次数
  11. declare @call_in_totalTime_ext bigint --内线呼入总时长
  12. declare @call_in_totalTime_trunk bigint --外线呼入总时长
  13. declare @call_out_ext bigint --呼出内线次数
  14. declare @call_out_trunk bigint --呼出外线次数
  15. declare @call_out_totalTime_ext bigint --呼出内线总时长
  16. declare @call_out_totalTime_trunk bigint --呼出外线总时长
  17. declare @call_out_success_ext bigint --呼出内线成功次数
  18. declare @call_out_success_trunk bigint --呼出外线成功次数
  19. declare @over_work_totalTime bigint --话后处理总时长
  20. declare @alerting_totalTime bigint --振铃总时长
  21. declare @transfer_count bigint --转移次数
  22. declare @be_transfer_count bigint --被转移次数
  23. declare @conference_count bigint --三方会议次数
  24. declare @be_conference_count bigint --被三方会议次数
  25. declare @over_alerting_count bigint --久振未接数
  26. declare @TalkTimesCount bigint --通话时长临时变量
  27. --内线应答次数,内线呼入总时长
  28. select @answer_ext=count(1),@call_in_totalTime_ext=isnull(sum(periodtalking),0) from dbo.rep_ext_call_in where calltype <> 1 and isanswer = 1 and CalleeAgentID = @nAgentID and TimeHangUp between @BeginTime and @EndTime
  29. --外线应答次数,外线呼入总时长
  30. select @answer_trunk=count(1),@call_in_totalTime_trunk=isnull(sum(periodtalking),0) from dbo.rep_ext_call_in where calltype = 1 and isanswer = 1 and CalleeAgentID = @nAgentID and TimeHangUp between @BeginTime and @EndTime
  31. --内线呼入次数
  32. select @call_in_ext=count(1) from dbo.rep_ext_call_in where calltype <> 1 and CalleeAgentID = @nAgentID and TimeHangUp between @BeginTime and @EndTime
  33. --外线呼入次数
  34. select @call_in_trunk=count(1) from dbo.rep_ext_call_in where calltype = 1 and CalleeAgentID = @nAgentID and TimeHangUp between @BeginTime and @EndTime
  35. --呼出内线总次数
  36. select @call_out_ext=count(1) from dbo.rep_ext_call_out where peerlinetype = 0 and CallerAgentID = @nAgentID and TimeHangUp between @BeginTime and @EndTime
  37. --呼出外线总次数
  38. select @call_out_trunk=count(1) from dbo.rep_ext_call_out where peerlinetype = 1 and CallerAgentID = @nAgentID and TimeHangUp between @BeginTime and @EndTime
  39. --呼出内线总时长
  40. select @call_out_totalTime_ext=isnull(sum(periodtalking),0) from dbo.rep_ext_call_out where peerlinetype = 0 and CallerAgentID = @nAgentID and TimeHangUp between @BeginTime and @EndTime
  41. --呼出外线总时长
  42. select @call_out_totalTime_trunk=isnull(sum(periodtalking),0) from dbo.rep_ext_call_out where peerlinetype = 1 and CallerAgentID = @nAgentID and TimeHangUp between @BeginTime and @EndTime
  43. --呼出内线成功次数
  44. select @call_out_success_ext=count(1) from dbo.rep_ext_call_out where peerlinetype = 0 and iscalloutsucceed = 1 and CallerAgentID = @nAgentID and TimeHangUp between @BeginTime and @EndTime
  45. --呼出外线成功次数
  46. select @call_out_success_trunk=count(1) from dbo.rep_ext_call_out where peerlinetype = 1 and iscalloutsucceed = 1 and CallerAgentID = @nAgentID and TimeHangUp between @BeginTime and @EndTime
  47. --话后处理总时长
  48. select @over_work_totalTime=isnull(sum(Duration),0) from dbo.rep_agent_state where State = 4 and AgentId = @nAgentID and LoginId = @nLogInID
  49. --振铃总时长
  50. select @alerting_totalTime=isnull(sum(PeriodAlerting),0) from dbo.rep_ext_call_in where CalleeAgentID = @nAgentID and TimeHangUp between @BeginTime and @EndTime
  51. --转移次数
  52. select @transfer_count=Count(1) from dbo.rep_transfer where CallerAgentID = @nAgentID and TimeBeginTransfer between @BeginTime and @EndTime
  53. --被转移次数
  54. select @be_transfer_count=Count(1) from dbo.rep_transfer where CalleeAgentID = @nAgentID and TimeBeginTransfer between @BeginTime and @EndTime
  55. --三方会议次数
  56. select @conference_count=Count(1) from dbo.rep_conference where CallerAgentID = @nAgentID and TimeConference between @BeginTime and @EndTime
  57. --被三方会议次数
  58. select @be_conference_count=Count(1) from dbo.rep_conference where CalleeAgentID = @nAgentID and TimeConference between @BeginTime and @EndTime
  59. --久振未接数 默认值为大于10秒
  60. select @over_alerting_count=Count(1) from dbo.rep_ext_call_in where PeriodAlerting > 10 and CalleeAgentID = @nAgentID and TimeAlerting between @BeginTime and @EndTime
  61. set @TalkTimesCount = @call_in_totalTime_ext + @call_in_totalTime_trunk + @call_out_totalTime_ext + @call_out_totalTime_trunk
  62. --空闲时长=签入时长-通话时长-置忙时长-话后处理时长
  63. update dbo.rep_agent_detail
  64. set FreeTimes = LoginTimes - @TalkTimesCount - ReposeTimes - @over_work_totalTime,
  65. TalkTimes = @TalkTimesCount,
  66. AnswerNumExt = @answer_ext,
  67. AnswerNumTrunk = @answer_trunk,
  68. CallInNumExt = @call_in_ext,
  69. CallInNumTrunk = @call_in_trunk,
  70. CallInTimesTotalExt = @call_in_totalTime_ext,
  71. CallInTimesTotalTrunk = @call_in_totalTime_trunk,
  72. CallOutNumExt = @call_out_ext,
  73. CallOutNumTrunk = @call_out_trunk,
  74. CallOutTimesTotalExt = @call_out_totalTime_ext,
  75. CallOutTimesTotalTrunk = @call_out_totalTime_trunk,
  76. CallOutOkNumExt = @call_out_success_ext,
  77. CallOutOkNumTrunk = @call_out_success_trunk,
  78. OverWorkTimesTotal = @over_work_totalTime,
  79. TimeAlertingTotal = @alerting_totalTime,
  80. TransferNum = @transfer_count,
  81. BeTransferNum = @be_transfer_count,
  82. ConferenceNum = @conference_count,
  83. BeConferenceNum = @be_conference_count,
  84. OverAlertingNum = @over_alerting_count
  85. where AgentId = @nAgentID and LoginId = @nLogInID
  86. update dbo.rep_agent_detail
  87. set FreeTimes = 0
  88. where AgentId = @nAgentID and LoginId = @nLogInID and FreeTimes<0